Decoupling Architectural-specific Code (#35)
[lunaix-os.git] / lunaix-os / arch / i386 / exceptions / intr_routines.c
index 6571f9a63219b9b4ee2b91fae10f1a380891890c..ddd06a8b3010cd990459ebc304734741a58ae5fc 100644 (file)
@@ -1,97 +1,79 @@
-#include <sys/interrupts.h>
+#include <sys/hart.h>
 
-#include <lunaix/isrm.h>
-#include <lunaix/lxconsole.h>
+#include <lunaix/generic/isrm.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
-#include <lunaix/tty/tty.h>
+#include <lunaix/trace.h>
+#include <lunaix/failsafe.h>
 
-#include <klibc/stdio.h>
+#include <klibc/strfmt.h>
 
-#include <sys/apic.h>
+#include "sys/apic.h"
 #include <sys/i386_intr.h>
 
 LOG_MODULE("INTR")
 
 extern void
-intr_routine_page_fault(const isr_param* param);
+intr_routine_page_fault(const struct hart_state* state);
 
 extern u32_t debug_resv;
 
 void
-__print_panic_msg(const char* msg, const isr_param* param)
+__print_panic_msg(const char* msg, const struct hart_state* state)
 {
-    volatile struct exec_param* execp = param->execp;
-
-    kprint_panic("  INT %u: (%x) [%p: %p] %s",
-                 execp->vector,
-                 execp->err_code,
-                 execp->cs,
-                 execp->eip,
-                 msg);
+    ERROR("panic: %s", msg);
+    failsafe_diagnostic();
 }
 
 void
-intr_routine_divide_zero(const isr_param* param)
+intr_routine_divide_zero(const struct hart_state* state)
 {
-    console_flush();
-    __print_panic_msg("Divide by zero!", param);
-    spin();
+    __print_panic_msg("div zero", state);
 }
 
 void
-intr_routine_general_protection(const isr_param* param)
+intr_routine_general_protection(const struct hart_state* state)
 {
-    kprintf(KERROR "Pid: %d\n", __current->pid);
-    kprintf(KERROR "Addr: %p\n", (&debug_resv)[0]);
-    kprintf(KERROR "Expected: %p\n", (&debug_resv)[1]);
-    console_flush();
-    __print_panic_msg("General Protection", param);
-    spin();
+    __print_panic_msg("general protection", state);
 }
 
 void
-intr_routine_sys_panic(const isr_param* param)
+intr_routine_sys_panic(const struct hart_state* state)
 {
-    console_flush();
-    __print_panic_msg((char*)(param->registers.edi), param);
-    spin();
+    __print_panic_msg((char*)(state->registers.edi), state);
 }
 
 void
-intr_routine_fallback(const isr_param* param)
+intr_routine_fallback(const struct hart_state* state)
 {
-    __print_panic_msg("Unknown Interrupt", param);
-    console_flush();
-    spin();
+    __print_panic_msg("unknown interrupt", state);
 }
 
 /**
  * @brief ISR for Spurious interrupt
  *
- * @param isr_param passed by CPU
+ * @param struct hart_state passed by CPU
  */
 void
-intr_routine_apic_spi(const isr_param* param)
+intr_routine_apic_spi(const struct hart_state* state)
 {
     // FUTURE: do nothing for now
 }
 
 void
-intr_routine_apic_error(const isr_param* param)
+intr_routine_apic_error(const struct hart_state* state)
 {
     u32_t error_reg = apic_read_reg(APIC_ESR);
     char buf[32];
     ksprintf(buf, "APIC error, ESR=0x%x", error_reg);
-    console_flush();
-    __print_panic_msg(buf, param);
-    spin();
+
+    failsafe_diagnostic();
 }
 
 void
-intr_routine_sched(const isr_param* param)
+intr_routine_sched(const struct hart_state* state)
 {
     schedule();
 }