diff options
Diffstat (limited to 'kernel/interrupts.c')
| -rw-r--r-- | kernel/interrupts.c | 129 |
1 files changed, 13 insertions, 116 deletions
diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 897c312..3ab0dd3 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -41,23 +41,12 @@ static void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr) idt[irq].sel=sel; } -/** Installs the interrupt table */ -void interrupts_install() -{ - idtd.size=sizeof(struct int_desc)*INT_MAX; - uint32_t addr=(uint32_t)&idt[0]; - idtd.baseHi=addr>>16; - idtd.baseLo=0xffff&addr; - __asm__("lidt %0"::"m" (idtd)); -} - /* * Interrupt dispatcher * * Remeber that we are inside an interrupt here! * */ - uint32_t interrupt_handler(uint32_t esp, uint32_t irq) { // DO NOT WRITE INSIDE INTERRUPTS!! COZ IT ACQUIRES LOCK AND WE WILL DEADLOCK @@ -101,111 +90,9 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) return esp; } -// log helpers // -void errlog(uint32_t error_code) -{ - klog("error_code: 0x%08X",error_code); -} - -void defklog(uint32_t esp) -{ - klog("EXCEPTION: eip: 0x%08X",*(uint32_t *)esp); - esp+=4; - klog("EXCEPTION: segment: 0x%08X",*(uint16_t *)esp); - esp+=4; - klog("EXCPETION: eflags: 0x%08X",*(uint32_t *)esp); -} - -void show_selector_error(uint32_t err) -{ - klog("Selector Error Details:"); - klog("External Event: %x",err&0b1); - klog("Location: 0x%x (0-GDT/1-IDT/2-LDT/3-IDT)",err&0b110); - klog("Selector: 0x%x",err&0b1111111111111000); -} - -void show_page_fault_error(uint32_t error_code) -{ - klog("Page Fault Error Details:"); - klog("error_code_P (Present): %d",error_code&1?1:0); - klog("error_code_W/R (Write): %d",error_code&2?1:0); - klog("error_code_U/S (User): %d",error_code&4?1:0); - klog("error_code_RSVD (Reserved Write) : %d",error_code&8?1:0); - klog("error_code_I/D (Instruction Fetch): %d",error_code&16?1:0); - klog("at addr: 0x%08X",x86_get_cr(2)); -} - -void exception_handle(uint32_t esp, uint32_t irq) -{ - uint32_t error_code=0; - - klog("EXCEPTION: apicID: 0x%08X",apicID()); - klog("EXCEPTION: vector nr.: %d",irq); - - switch(irq){ //this interrupts push also an error_code - case 8: - case 10: - case 11: - case 12: - case 13: - case 14: - case 17: - case 30: - error_code = *(uint32_t *)esp; - esp+=4; - } - klog("EXCEPTION: error_code: %d",irq); - defklog(esp); - - switch(irq){ - case 0: - kpanic("Divide by 0"); - case 1: - kpanic("Single step (debugger)"); - case 2: - kpanic("Non Maskable Interrupt"); - case 3: - kpanic("Breakpoint (debugger)"); - case 4: - kpanic("Overflow"); - case 5: - kpanic("Bounds check"); - case 6: - kpanic("Undefined OP Code"); - case 7: - kpanic("No coprocessor"); - case 8: - kpanic("Double Fault"); - case 9: - kpanic("Coprocessor Segment Overrun"); - case 10: - show_selector_error(error_code); - kpanic("Invalid TSS"); - case 11: - show_selector_error(error_code); - kpanic("Segment Not Present"); - case 12: - show_selector_error(error_code); - kpanic("Stack Segment Overrun"); - case 13: - show_selector_error(error_code); - kpanic("Exception: Fault: General Protection Fault"); - case 14: - show_page_fault_error(error_code); - kpanic("Exception: Fault: Page Fault"); - case 15: - kpanic("RESERVED"); - case 16: - kpanic("Coprocessor error"); - case 17: - kpanic("Alignment Check"); - case 18: - kpanic("Machine Check"); - } -} - - -// set default handler for all interrupts for a start +/** + * init interrupt descriptor table + */ void interrupts_init(uint16_t sel) { klog("initializing. IDT: 0x%08x, IDTD: 0x%08X",&idt,&idtd); @@ -256,3 +143,13 @@ void interrupts_init(uint16_t sel) int_install_ir(0x81, 0b10001110, 0x08,&int129); } + +/** Installs the interrupt table */ +void interrupts_install() +{ + idtd.size=sizeof(struct int_desc)*INT_MAX; + uint32_t addr=(uint32_t)&idt[0]; + idtd.baseHi=addr>>16; + idtd.baseLo=0xffff&addr; + __asm__("lidt %0"::"m" (idtd)); +} |
