File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 44
55extern interrupt_handler_0x00_0x1F_exception
66
7+ global at_stack
78global _interrupt_handler_0x00_exception
89global _interrupt_handler_0x01_exception
910global _interrupt_handler_0x02_exception
@@ -69,6 +70,22 @@ global _interrupt_handler_0x1F_exception
6970 iret
7071%endmacro
7172
73+ at_stack:
74+ push ebp
75+ mov ebp , esp
76+
77+ push ds
78+ mov eax , ss
79+ mov ds , eax
80+
81+ mov esi , [ ebp + 8 ] ; stack pointer
82+ mov eax , [ esi ]
83+
84+ pop ds
85+
86+ pop ebp
87+ ret
88+
7289 create_low__interrupt_handler_xy_exception_nohup 0x00 ; divide-by-zero
7390 create_low__interrupt_handler_xy_exception 0x01
7491 create_low__interrupt_handler_xy_exception 0x02
Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ struct exceptionContext {
5050 int ip , cs , eflag ;
5151};
5252
53+ int at_stack (int esp );
54+
5355void interrupt_handler_0x00_0x1F_exception (struct exceptionContext context ) {
5456 // written for handler with error code otherwise ip, cs and eflag will skew.
5557 const int gdte_size = sizeof (struct GDTEntry );
@@ -74,13 +76,14 @@ void interrupt_handler_0x00_0x1F_exception(struct exceptionContext context) {
7476 // stack trace
7577 {
7678 const int stack_trace_max_depth = 5 ;
77- int last_ebp = context .ebp ;
79+ int ebp = context .ebp ;
7880 // stack[ebp] => previous_ebp, if previous_ebp == 0 then break;
79- for (int i = 0 ; i < stack_trace_max_depth ; i ++ ) {
80- // to be implemented
81- break ;
81+ print_log ("stack trace: \n - %x" , context .ip );
82+ for (int i = 0 ; ebp > 0 && i < stack_trace_max_depth ; i ++ ) {
83+ int return_address = at_stack (ebp + 4 );
84+ print_log (" - %x (ni)" , return_address );
85+ ebp = at_stack (ebp );
8286 }
83-
8487 }
8588
8689
You can’t perform that action at this time.
0 commit comments