Add simple stack trace to exception handler

This commit is contained in:
Justin C. Miller
2018-05-05 17:12:02 -07:00
parent 569bc243f1
commit 34156c55ae
5 changed files with 39 additions and 3 deletions

View File

@@ -19,6 +19,9 @@ _start:
cli cli
mov rsp, stack_end mov rsp, stack_end
push 0 ; signal end of stack with 0 return address
mov rbp, rsp
extern kernel_main extern kernel_main
call kernel_main call kernel_main
@@ -40,6 +43,7 @@ interrupts_disable:
ret ret
section .bss section .bss
align 0x100
stack_begin: stack_begin:
resb 0x4000 ; 16KiB stack space resb 0x4000 ; 16KiB stack space
stack_end: stack_end:

View File

@@ -10,3 +10,20 @@ global _halt
_halt: _halt:
hlt hlt
jmp _halt jmp _halt
global get_frame
get_frame:
mov rcx, rbp
.loop:
mov rax, [rcx + 8]
mov rcx, [rcx]
cmp rdi, 0
je .done
sub rdi, 1
jmp .loop
.done:
ret

View File

@@ -208,6 +208,8 @@ struct registers
#define print_reg(name, value) cons->printf(" %s: %lx\n", name, (value)); #define print_reg(name, value) cons->printf(" %s: %lx\n", name, (value));
extern "C" uint64_t get_frame(int frame);
void void
isr_handler(registers regs) isr_handler(registers regs)
{ {
@@ -277,6 +279,15 @@ isr_handler(registers regs)
print_reg(" ef", regs.eflags); print_reg(" ef", regs.eflags);
print_reg("esp", regs.user_esp); print_reg("esp", regs.user_esp);
print_reg(" ss", regs.ss); print_reg(" ss", regs.ss);
cons->puts("\n");
int frame = 0;
uint64_t bp = get_frame(0);
while (bp) {
cons->printf(" frame %2d: %lx\n", frame, bp);
bp = get_frame(++frame);
}
while(1) asm("hlt"); while(1) asm("hlt");
} }

View File

@@ -50,6 +50,10 @@ init_console(const popcorn_data *header)
log::enable(logs::devices, log::level::debug); log::enable(logs::devices, log::level::debug);
} }
void do_error_3() { int x = 1 / 0; }
void do_error_2() { do_error_3(); }
void do_error_1() { do_error_2(); }
void void
kernel_main(popcorn_data *header) kernel_main(popcorn_data *header)
{ {
@@ -80,7 +84,7 @@ kernel_main(popcorn_data *header)
log::info(logs::boot, "CPU Family %x Model %x Stepping %x", log::info(logs::boot, "CPU Family %x Model %x Stepping %x",
cpu.family(), cpu.model(), cpu.stepping()); cpu.family(), cpu.model(), cpu.stepping());
// int x = 1 / 0; // do_error_1();
// __asm__ __volatile__("int $15"); // __asm__ __volatile__("int $15");
g_console.puts("boogity!"); g_console.puts("boogity!");

View File

@@ -58,7 +58,7 @@ def configure(ctx):
'-ffreestanding', '-ffreestanding',
'-nodefaultlibs', '-nodefaultlibs',
'-fno-builtin', '-fno-builtin',
'-fomit-frame-pointer', '-fno-omit-frame-pointer',
'-mno-red-zone', '-mno-red-zone',
] ]
@@ -103,7 +103,7 @@ def configure(ctx):
ctx.env.append_value('CXXFLAGS', baseflags) ctx.env.append_value('CXXFLAGS', baseflags)
ctx.env.append_value('CXXFLAGS', warnflags) ctx.env.append_value('CXXFLAGS', warnflags)
ctx.env.append_value('CXXFLAGS', [ ctx.env.append_value('CXXFLAGS', [
'-ggdb', '-g',
'-std=c++14', '-std=c++14',
'-fno-exceptions', '-fno-exceptions',
'-fno-rtti', '-fno-rtti',