diff options
author | trimill <trimill@trimillxyz.org> | 2024-01-29 21:10:29 -0500 |
---|---|---|
committer | trimill <trimill@trimillxyz.org> | 2024-01-29 21:10:29 -0500 |
commit | 417d5b17b8054a73c2a41ae4aabefb4654e05fad (patch) | |
tree | 3dbd424270d1dd56843d3a11dbf34854e62bd2d6 /src/arch/amd64 | |
parent | pic done (diff) | |
download | corn-417d5b17b8054a73c2a41ae4aabefb4654e05fad.tar.gz corn-417d5b17b8054a73c2a41ae4aabefb4654e05fad.tar.bz2 corn-417d5b17b8054a73c2a41ae4aabefb4654e05fad.zip |
refactor, improve exception message
Diffstat (limited to '')
-rw-r--r-- | src/arch/amd64/idt.S | 8 | ||||
-rw-r--r-- | src/arch/amd64/idt.c | 119 | ||||
-rw-r--r-- | src/arch/amd64/panic.c | 5 |
3 files changed, 75 insertions, 57 deletions
diff --git a/src/arch/amd64/idt.S b/src/arch/amd64/idt.S index 1098057..32670c8 100644 --- a/src/arch/amd64/idt.S +++ b/src/arch/amd64/idt.S @@ -7,11 +7,13 @@ extern idt_pic_mouse extern idt_pic_eoi %macro PUSHALL 0 + push rax push rbx push rcx push rdx - push rsi + push rbp push rdi + push rsi push r8 push r9 push r10 @@ -31,11 +33,13 @@ extern idt_pic_eoi pop r10 pop r9 pop r8 - pop rdi pop rsi + pop rdi + pop rbp pop rdx pop rcx pop rbx + pop rax %endmacro ; call the exception handler with the interrupt number diff --git a/src/arch/amd64/idt.c b/src/arch/amd64/idt.c index 5c6261c..83b792c 100644 --- a/src/arch/amd64/idt.c +++ b/src/arch/amd64/idt.c @@ -73,68 +73,81 @@ void idt_init(void) { // Intel manual vol 3 ch 6.3.1 char *EXCEPTIONS[] = { - "Exception 0x00 Divide Error", - "Exception 0x01 Debug Exception", - "Exception 0x02 NMI Interrupt", - "Exception 0x03 Breakpoint", - "Exception 0x04 Overflow", - "Exception 0x05 BOUND Range Exceeded", - "Exception 0x06 Invalid Opcode", - "Exception 0x07 Device Not Available", - "Exception 0x08 Double Fault", - "Exception 0x09 Coprocessor Segment Overrun", - "Exception 0x0A Invalid TSS", - "Exception 0x0B Segment Not Present", - "Exception 0x0C Stack-Segment Fault", - "Exception 0x0D General Protection", - "Exception 0x0E Page Fault", - "Exception 0x0F Reserved", - "Exception 0x10 x87 FPU Floating-Point Error", - "Exception 0x11 Alignment Check", - "Exception 0x12 Machine Check", - "Exception 0x13 SIMD Floaing-Point Exception", - "Exception 0x14 Virtualization Exception", - "Exception 0x15 Control Protection Exception", - "Exception 0x16 Reserved", - "Exception 0x17 Reserved", - "Exception 0x18 Reserved", - "Exception 0x19 Reserved", - "Exception 0x1A Reserved", - "Exception 0x1B Reserved", - "Exception 0x1C Reserved", - "Exception 0x1D Reserved", - "Exception 0x1E Reserved", - "Exception 0x1F Reserved", + "0x00 Division Error", + "0x01 Debug", + "0x02 NMI", + "0x03 Breakpoint", + "0x04 Overflow", + "0x05 BOUND Range Exceeded", + "0x06 Invalid Opcode", + "0x07 Device Not Available", + "0x08 Double Fault", + "0x09 Coprocessor Segment Overrun", + "0x0A Invalid TSS", + "0x0B Segment Not Present", + "0x0C Stack-Segment Fault", + "0x0D General Protection Fault", + "0x0E Page Fault", + "0x0F Reserved", + "0x10 x87 Floating-Point Error", + "0x11 Alignment Check", + "0x12 Machine Check", + "0x13 SIMD Floaing-Point Exception", + "0x14 Virtualization Exception", + "0x15 Control Protection Exception", + "0x16 Reserved", + "0x17 Reserved", + "0x18 Reserved", + "0x19 Reserved", + "0x1A Reserved", + "0x1B Reserved", + "0x1C Hypervisor Injection Exception", + "0x1D VMM Communication Exception", + "0x1E Security Exception", + "0x1F Reserved", }; +void idt_exception_handler(uint64_t exception, uint64_t code) { + // TODO don't just panic + char buf[24]; + char msg[256] = "Exception "; + + strcat(msg, EXCEPTIONS[exception]); + + strcat(msg, "\nError code 0x"); + ultoa(code, buf, 16); + strcat(msg, buf); + + // page faults store the offending address in cr2 + if(exception == 0x0E) { + strcat(msg, "\nPage fault address: 0x"); + void *addr; + __asm__ volatile ("mov %%cr2, %0" : "=r"(addr)); + ultoa((size_t)addr, buf, 16); + strcat(msg, buf); + } + + panic(msg); +} + void idt_pic_eoi(uint8_t exception) { pic_eoi(exception - PIC_REMAP_OFFSET); } -static size_t timer = 0; +int counter = 0; void idt_pic_timer(void) { - timer += 1; - char buf[20]; - ltoa(timer, buf, 10); - serial_out_str(buf); - serial_out_str("\n"); -} - -void idt_pic_keyboard(void) { - serial_out_str("ps2 kbd"); + // print a message once we know the timer works + // but avoid spamming the logs + if (counter == 3) { + serial_out_str("pic timer!\n"); + } + if (counter <= 3) { + counter++; + } } -void idt_pic_mouse(void) { - serial_out_str("ps2 mouse"); -} +void idt_pic_keyboard(void) {} -void idt_exception_handler(uint64_t exception, uint64_t code) { - // TODO don't just panic - char buf[80]; - char *end = strcpy(buf, EXCEPTIONS[exception]); - end = strcpy(end, "\nError code 0x"); - ltoa(code, end, 16); - panic(buf); -} +void idt_pic_mouse(void) {} diff --git a/src/arch/amd64/panic.c b/src/arch/amd64/panic.c index 227ecce..c034b90 100644 --- a/src/arch/amd64/panic.c +++ b/src/arch/amd64/panic.c @@ -6,11 +6,12 @@ _Noreturn void _panic_impl(char *line, char *file, char *msg) { cli(); serial_out_str("\n\n!!! PANIC !!!\n"); - serial_out_str(msg); - serial_out_str("\nin file "); + serial_out_str("In file "); serial_out_str(file); serial_out_str(" at line "); serial_out_str(line); + serial_out_str(":\n"); + serial_out_str(msg); serial_out('\n'); while (1) { halt(); |