summaryrefslogtreecommitdiff
path: root/src/kernel/core
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-08-13 20:34:04 +0200
committerAlexis211 <alexis211@gmail.com>2010-08-13 20:34:04 +0200
commitbea638adc3da8a10f77358542a9a6889d833fb33 (patch)
treea88241280f4175ecbcca7446b6a0156f48ae66b6 /src/kernel/core
parenta75acb568a301903f00d3230467de2a097cce0db (diff)
downloadTCE-bea638adc3da8a10f77358542a9a6889d833fb33.tar.gz
TCE-bea638adc3da8a10f77358542a9a6889d833fb33.zip
Some changes to stack tracing.
Diffstat (limited to 'src/kernel/core')
-rw-r--r--src/kernel/core/sys.c27
-rw-r--r--src/kernel/core/sys.h2
2 files changed, 23 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. */
diff --git a/src/kernel/core/sys.h b/src/kernel/core/sys.h
index f147922..f429b44 100644
--- a/src/kernel/core/sys.h
+++ b/src/kernel/core/sys.h
@@ -8,6 +8,8 @@ void outw(uint16_t port, uint16_t value);
uint8_t inb(uint16_t port);
uint16_t inw(uint16_t port);
+void stack_trace(size_t bp);
+
#define PANIC(s) panic(s, __FILE__, __LINE__);
#define ASSERT(s) { if (!(s)) panic_assert(#s, __FILE__, __LINE__); }
void panic(char* message, char* file, int line);