summaryrefslogtreecommitdiff
path: root/kernel/interrupts.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-06 01:58:10 +0200
committerMiguel <m.i@gmx.at>2018-09-06 01:58:10 +0200
commitef4943053475cd8bf341c42dd0b538bc630b92a3 (patch)
treeb7f59c937797a0ce0603af9ef46a194d4a64ef22 /kernel/interrupts.c
parentf67ad595650954195ef064a8b91038dbd0e16842 (diff)
working on smp
Diffstat (limited to 'kernel/interrupts.c')
-rw-r--r--kernel/interrupts.c130
1 files changed, 82 insertions, 48 deletions
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 501ccd4..4eb2a35 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -94,68 +94,102 @@ void errlog(uint32_t error_code)
klog("error_code: 0x%08X",error_code);
}
-void defklog(uint32_t eip, uint16_t cs, uint32_t flags)
+void defklog(uint32_t esp)
{
- klog("eip: 0x%08X",eip);
- klog("segment: 0x%08X",cs);
- klog("eflags: 0x%08X",flags);
+ 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_error(uint32_t err)
+void show_selector_error(uint32_t err)
{
- klog("interrupt error code: 0x%08x",err);
- klog("External Event: %x",err&0b001);
+ klog("Selector Error Details:");
+ klog("External Event: %x",err&0b1);
klog("Location: %x",err&0b110);
klog("Selector: %x",err&0b1111111111111000);
}
-//
-
-void int_default()
+void show_page_fault_error(uint32_t error_code)
{
- klog("default handler");
- kpanic("unhandled interrupt (is this a panic or should just iognore?)");
-}
-
-void exception_handle_0(){ kpanic("Divide by 0"); }
-void exception_handle_1(){ kpanic("Single step (debugger)"); }
-void exception_handle_2(){ kpanic("Non Maskable Interrupt"); }
-void exception_handle_3(){ kpanic("Breakpoint (debugger)"); }
-void exception_handle_4(){ kpanic("Overflow"); }
-void exception_handle_5(){ kpanic("Bounds check"); }
-void exception_handle_6(){ kpanic("Undefined OP Code"); }
-void exception_handle_7(){ kpanic("No coprocessor"); }
-void exception_handle_8(){ kpanic("Double Fault"); }
-void exception_handle_9(){ kpanic("Coprocessor Segment Overrun"); }
-void exception_handle_10(){ kpanic("Invalid TSS"); }
-void exception_handle_11(){ kpanic("Segment Not Present"); }
-void exception_handle_12(){ kpanic("Stack Segment Overrun"); }
-
-void exception_handle_13(uint32_t error_code,uint32_t eip,uint16_t cs,uint16_t unused, uint32_t flags)
-{
- errlog(error_code);
- defklog(eip,cs,flags);
-
- kpanic("Exception: Fault: General Protection Fault");
+ 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_14(uint32_t error_code,uint32_t eip,uint16_t cs,uint16_t unused, uint32_t flags)
+void exception_handle(uint32_t esp, uint32_t irq)
{
- errlog(error_code);
- klog("error_code_P: %d",error_code&1?1:0);
- klog("error_code_W/R: %d",error_code&2?1:0);
- klog("error_code_U/S: %d",error_code&4?1:0);
- klog("error_code_RSVD: %d",error_code&8?1:0);
- klog("error_code_I/D: %d",error_code&16?1:0);
- klog("at addr: 0x%08X",x86_get_cr(2));
- defklog(eip,cs,flags);
- kpanic("Exception: Fault: Page Fault");
+ uint32_t error_code=0;
+
+ 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");
+ }
}
-void exception_handle_15(){ kpanic("Unassigned"); }
-void exception_handle_16(){ kpanic("Coprocessor error"); }
-void exception_handle_17(){ kpanic("Alignment Check"); }
-void exception_handle_18(){ kpanic("Machine Check"); }
// set default handler for all interrupts for a start
void interrupts_init(uint16_t sel)