From dd0e90c84db6743141eeaabacb51bc8539d4eaf0 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Sun, 13 Jul 2014 13:07:19 -0700 Subject: [PATCH] Starting Kernel Debugger --- sys/amd64/debug.c | 29 +++++++++++++++++++++++++++++ sys/amd64/machine.c | 2 ++ sys/amd64/trap.c | 8 ++++++++ sys/kern/debug.c | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 sys/amd64/debug.c diff --git a/sys/amd64/debug.c b/sys/amd64/debug.c new file mode 100644 index 0000000..bbba551 --- /dev/null +++ b/sys/amd64/debug.c @@ -0,0 +1,29 @@ + +#include + +#include +#include +//#include +#include + +#include "trap.h" + +TrapFrame *frames[MAX_CPUS]; + +void +Debug_Breakpoint(TrapFrame *tf) +{ + frames[CPU()] = tf; + + // Stop all processors + + Debug_Prompt(); + + // Resume all processors +} + +void +Debug_Registers(int argc, const char *argv[]) +{ +} + diff --git a/sys/amd64/machine.c b/sys/amd64/machine.c index e1e125e..caf77f8 100644 --- a/sys/amd64/machine.c +++ b/sys/amd64/machine.c @@ -101,5 +101,7 @@ void Machine_Init() PCI_Init(); IDE_Init(); + + breakpoint(); } diff --git a/sys/amd64/trap.c b/sys/amd64/trap.c index daa54bc..94e32a9 100644 --- a/sys/amd64/trap.c +++ b/sys/amd64/trap.c @@ -87,11 +87,19 @@ Trap_Dump(TrapFrame *tf) void trap_entry(TrapFrame *tf) { + // Kernel Debugger + if (tf->vector == T_BP && tf->cs == SEL_KCS) + { + Debug_Breakpoint(tf); + return; + } + // Halt on kernel errors if (tf->vector <= T_CPU_LAST && tf->cs == SEL_KCS) { kprintf("Kernel Fault!\n"); Trap_Dump(tf); + Debug_Breakpoint(tf); while (1) hlt(); } diff --git a/sys/kern/debug.c b/sys/kern/debug.c index fadd76e..d1f32c6 100644 --- a/sys/kern/debug.c +++ b/sys/kern/debug.c @@ -70,3 +70,21 @@ Debug_PrintHex(const char *data, size_t length, off_t off, size_t limit) } } +void +Debug_Dump(int argc, const char *argv[]) +{ +} + +void +Debug_Prompt() +{ + kprintf("Entered Debugger!\n"); + + kprintf("> "); + // read input + + // parse input + + // execute command +} +