# HG changeset patch # User John Tsiombikas # Date 1298412756 -7200 # Node ID 6c9138a87e02d39a821c9480ef039f6f10ac61ca # Parent eaec918de07266a57a60a1945bc8e89f933dad04 added register dump in panic() diff -r eaec918de072 -r 6c9138a87e02 src/main.c --- a/src/main.c Tue Feb 22 18:51:44 2011 +0200 +++ b/src/main.c Wed Feb 23 00:12:36 2011 +0200 @@ -4,6 +4,7 @@ #include #include "segm.h" #include "intr.h" +#include "panic.h" /* special keys */ enum { @@ -48,6 +49,8 @@ asm volatile("int $0x80"); + panic("foo\n"); + for(;;) { char c, keypress; do { diff -r eaec918de072 -r 6c9138a87e02 src/panic.c --- a/src/panic.c Tue Feb 22 18:51:44 2011 +0200 +++ b/src/panic.c Wed Feb 23 00:12:36 2011 +0200 @@ -1,16 +1,45 @@ #include +#include #include #include "asmops.h" +struct registers { + uint32_t eax, ebx, ecx, edx; + uint32_t esp, ebp, esi, edi; + uint32_t eflags; + uint32_t cs, ss, ds, es, fs, gs; + uint32_t cr0, cr1, cr2, cr3; +}; + +/* defined in regs.S */ +void get_regs(struct registers *regs); + void panic(const char *fmt, ...) { va_list ap; + struct registers regs; + + disable_intr(); + + memset(®s, 0, sizeof regs); + get_regs(®s); printf("~~~~~ kernel panic ~~~~~\n"); va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); - disable_intr(); + printf("\nRegisters:\n"); + printf("eax: %x, ebx: %x, ecx: %x, edx: %x\n", regs.eax, regs.ebx, regs.ecx, regs.edx); + printf("esp: %x, ebp: %x, esi: %x, edi: %x\n", regs.esp, regs.ebp, regs.esi, regs.edi); + printf("eflags: %x\n", regs.eflags); + printf("cr0: %x, cr1: %x, cr2: %x, cr3: %x\n", regs.cr0, regs.cr1, regs.cr2, regs.cr3); + printf("cs: %x (%d|%d)\n", regs.cs, regs.cs >> 3, regs.cs & 3); + printf("ss: %x (%d|%d)\n", regs.ss, regs.ss >> 3, regs.ss & 3); + printf("ds: %x (%d|%d)\n", regs.ds, regs.ds >> 3, regs.ds & 3); + printf("es: %x (%d|%d)\n", regs.es, regs.es >> 3, regs.es & 3); + printf("fs: %x (%d|%d)\n", regs.fs, regs.fs >> 3, regs.fs & 3); + printf("gs: %x (%d|%d)\n", regs.gs, regs.gs >> 3, regs.gs & 3); + halt_cpu(); } diff -r eaec918de072 -r 6c9138a87e02 src/regs.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/regs.S Wed Feb 23 00:12:36 2011 +0200 @@ -0,0 +1,54 @@ + .text + .align 4 + + .globl get_regs +get_regs: + pushl %ebp + movl %esp, %ebp + + pushl %edx + movl 8(%ebp), %edx + + movl %eax, (%edx) + movl %ebx, 4(%edx) + movl %ecx, 8(%edx) + + /* juggle edx */ + movl %edx, %eax + popl %edx + movl %edx, 12(%eax) + pushl %edx + movl %eax, %edx + + /* those two are pointless in a function */ + movl %esp, 16(%edx) + movl %ebp, 20(%edx) + + movl %esi, 24(%edx) + movl %edi, 28(%edx) + + pushf + popl %eax + movl %eax, 32(%edx) + + movw %cs, 36(%edx) + movw %ss, 40(%edx) + movw %ds, 44(%edx) + movw %es, 48(%edx) + movw %fs, 52(%edx) + movw %gs, 56(%edx) + + pushl %ebx + movl %cr0, %ebx + movl %ebx, 60(%edx) + /*movl %cr1, %ebx + movl %ebx, 64(%edx)*/ + movl %cr3, %ebx + movl %ebx, 68(%edx) + movl %cr4, %ebx + movl %ebx, 72(%edx) + popl %ebx + + popl %edx + popl %ebp + ret