diff options
Diffstat (limited to 'src/arch/amd64/idt.c')
-rw-r--r-- | src/arch/amd64/idt.c | 119 |
1 files changed, 66 insertions, 53 deletions
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) {} |