diff options
author | Alexis211 <alexis211@gmail.com> | 2010-08-13 20:34:04 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2010-08-13 20:34:04 +0200 |
commit | bea638adc3da8a10f77358542a9a6889d833fb33 (patch) | |
tree | a88241280f4175ecbcca7446b6a0156f48ae66b6 /src/kernel/core/sys.c | |
parent | a75acb568a301903f00d3230467de2a097cce0db (diff) | |
download | TCE-bea638adc3da8a10f77358542a9a6889d833fb33.tar.gz TCE-bea638adc3da8a10f77358542a9a6889d833fb33.zip |
Some changes to stack tracing.
Diffstat (limited to 'src/kernel/core/sys.c')
-rw-r--r-- | src/kernel/core/sys.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/kernel/core/sys.c b/src/kernel/core/sys.c index 96d4908..56de038 100644 --- a/src/kernel/core/sys.c +++ b/src/kernel/core/sys.c @@ -24,20 +24,35 @@ uint16_t inw(uint16_t port) { return ret; } -/* These two functions stop the system, reporting an error message, because something bad happenned. */ +////// +void stack_trace(size_t bp) { + uint32_t *stack = (uint32_t*)bp, i; + for (i = 0; i < 5 && stack > 0xE0000000 && stack < (bp + 0x8000); i++) { + monitor_write(" "); monitor_writeHex(stack); + monitor_write("\tnext:"); monitor_writeHex(stack[0]); monitor_write("\t\tret:"); monitor_writeHex(stack[1]); + monitor_write("\n"); + stack = (uint32_t*)stack[0]; + } +} -void panic(char* message, char* file, int line) { - monitor_write("\n\nPANIC:\t\t"); monitor_write(message); +/* For internal use only. Used by panic and panic_assert. */ +static void panic_do(char* file, int line) { monitor_write("\n File:\t\t"); monitor_write(file); monitor_put(':'); monitor_writeDec(line); + monitor_write("\nTrace:\n"); + size_t bp; asm volatile("mov %%ebp,%0" : "=r"(bp)); stack_trace(bp); monitor_write("\n\t\tSystem halted -_-'\n"); asm volatile("cli; hlt"); } +/* These functions stop the system, reporting an error message, because something bad happenned. */ +void panic(char* message, char* file, int line) { + monitor_write("\n\nPANIC:\t\t"); monitor_write(message); + panic_do(file, line); +} + void panic_assert(char* assertion, char* file, int line) { monitor_write("\n\nASSERT FAILED:\t"); monitor_write(assertion); - monitor_write("\n File:\t\t"); monitor_write(file); monitor_put(':'); monitor_writeDec(line); - monitor_write("\n\t\tSystem halted -_-'\n"); - asm volatile("cli; hlt"); + panic_do(file, line); } /* Global system mutex. See comments in sys.h. */ |