kern
changeset 13:6c9138a87e02
added register dump in panic()
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 23 Feb 2011 00:12:36 +0200 |
parents | eaec918de072 |
children | a5176aa334c3 |
files | src/main.c src/panic.c src/regs.S |
diffstat | 3 files changed, 87 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/src/main.c Tue Feb 22 18:51:44 2011 +0200 1.2 +++ b/src/main.c Wed Feb 23 00:12:36 2011 +0200 1.3 @@ -4,6 +4,7 @@ 1.4 #include <asmops.h> 1.5 #include "segm.h" 1.6 #include "intr.h" 1.7 +#include "panic.h" 1.8 1.9 /* special keys */ 1.10 enum { 1.11 @@ -48,6 +49,8 @@ 1.12 1.13 asm volatile("int $0x80"); 1.14 1.15 + panic("foo\n"); 1.16 + 1.17 for(;;) { 1.18 char c, keypress; 1.19 do {
2.1 --- a/src/panic.c Tue Feb 22 18:51:44 2011 +0200 2.2 +++ b/src/panic.c Wed Feb 23 00:12:36 2011 +0200 2.3 @@ -1,16 +1,45 @@ 2.4 #include <stdio.h> 2.5 +#include <string.h> 2.6 #include <stdarg.h> 2.7 #include "asmops.h" 2.8 2.9 +struct registers { 2.10 + uint32_t eax, ebx, ecx, edx; 2.11 + uint32_t esp, ebp, esi, edi; 2.12 + uint32_t eflags; 2.13 + uint32_t cs, ss, ds, es, fs, gs; 2.14 + uint32_t cr0, cr1, cr2, cr3; 2.15 +}; 2.16 + 2.17 +/* defined in regs.S */ 2.18 +void get_regs(struct registers *regs); 2.19 + 2.20 void panic(const char *fmt, ...) 2.21 { 2.22 va_list ap; 2.23 + struct registers regs; 2.24 + 2.25 + disable_intr(); 2.26 + 2.27 + memset(®s, 0, sizeof regs); 2.28 + get_regs(®s); 2.29 2.30 printf("~~~~~ kernel panic ~~~~~\n"); 2.31 va_start(ap, fmt); 2.32 vprintf(fmt, ap); 2.33 va_end(ap); 2.34 2.35 - disable_intr(); 2.36 + printf("\nRegisters:\n"); 2.37 + printf("eax: %x, ebx: %x, ecx: %x, edx: %x\n", regs.eax, regs.ebx, regs.ecx, regs.edx); 2.38 + printf("esp: %x, ebp: %x, esi: %x, edi: %x\n", regs.esp, regs.ebp, regs.esi, regs.edi); 2.39 + printf("eflags: %x\n", regs.eflags); 2.40 + printf("cr0: %x, cr1: %x, cr2: %x, cr3: %x\n", regs.cr0, regs.cr1, regs.cr2, regs.cr3); 2.41 + printf("cs: %x (%d|%d)\n", regs.cs, regs.cs >> 3, regs.cs & 3); 2.42 + printf("ss: %x (%d|%d)\n", regs.ss, regs.ss >> 3, regs.ss & 3); 2.43 + printf("ds: %x (%d|%d)\n", regs.ds, regs.ds >> 3, regs.ds & 3); 2.44 + printf("es: %x (%d|%d)\n", regs.es, regs.es >> 3, regs.es & 3); 2.45 + printf("fs: %x (%d|%d)\n", regs.fs, regs.fs >> 3, regs.fs & 3); 2.46 + printf("gs: %x (%d|%d)\n", regs.gs, regs.gs >> 3, regs.gs & 3); 2.47 + 2.48 halt_cpu(); 2.49 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/regs.S Wed Feb 23 00:12:36 2011 +0200 3.3 @@ -0,0 +1,54 @@ 3.4 + .text 3.5 + .align 4 3.6 + 3.7 + .globl get_regs 3.8 +get_regs: 3.9 + pushl %ebp 3.10 + movl %esp, %ebp 3.11 + 3.12 + pushl %edx 3.13 + movl 8(%ebp), %edx 3.14 + 3.15 + movl %eax, (%edx) 3.16 + movl %ebx, 4(%edx) 3.17 + movl %ecx, 8(%edx) 3.18 + 3.19 + /* juggle edx */ 3.20 + movl %edx, %eax 3.21 + popl %edx 3.22 + movl %edx, 12(%eax) 3.23 + pushl %edx 3.24 + movl %eax, %edx 3.25 + 3.26 + /* those two are pointless in a function */ 3.27 + movl %esp, 16(%edx) 3.28 + movl %ebp, 20(%edx) 3.29 + 3.30 + movl %esi, 24(%edx) 3.31 + movl %edi, 28(%edx) 3.32 + 3.33 + pushf 3.34 + popl %eax 3.35 + movl %eax, 32(%edx) 3.36 + 3.37 + movw %cs, 36(%edx) 3.38 + movw %ss, 40(%edx) 3.39 + movw %ds, 44(%edx) 3.40 + movw %es, 48(%edx) 3.41 + movw %fs, 52(%edx) 3.42 + movw %gs, 56(%edx) 3.43 + 3.44 + pushl %ebx 3.45 + movl %cr0, %ebx 3.46 + movl %ebx, 60(%edx) 3.47 + /*movl %cr1, %ebx 3.48 + movl %ebx, 64(%edx)*/ 3.49 + movl %cr3, %ebx 3.50 + movl %ebx, 68(%edx) 3.51 + movl %cr4, %ebx 3.52 + movl %ebx, 72(%edx) 3.53 + popl %ebx 3.54 + 3.55 + popl %edx 3.56 + popl %ebp 3.57 + ret