refactor: Optimize the context switch overhead
[lunaix-os.git] / lunaix-os / debug / sdbg.c
index 2309ece105496d9e09416f9a7f4e468ee49f0592..60a89f360a40cffc3b4e1fe91fd790ff802a16e7 100644 (file)
@@ -1,6 +1,7 @@
 #include <hal/acpi/acpi.h>
 #include <hal/ioapic.h>
 #include <klibc/stdio.h>
+#include <lunaix/isrm.h>
 #include <lunaix/lxconsole.h>
 #include <lunaix/peripheral/serial.h>
 #include <lunaix/syslog.h>
@@ -21,7 +22,8 @@ sdbg_loop(const isr_param* param)
     // synchronized way. And we don't want these irq queue up at our APIC and
     // confuse the CPU after ACK with APIC.
     serial_disable_irq(SERIAL_COM1);
-    if (param->vector == 1 || param->vector == 3) {
+    struct exec_param* execp = param->execp;
+    if (execp->vector == 1 || execp->vector == 3) {
         goto cont;
     }
 
@@ -73,10 +75,11 @@ done:
 void
 sdbg_imm(const isr_param* param)
 {
+    struct exec_param* execp = param->execp;
     kprintf(KDEBUG "Quick debug mode\n");
     kprintf(KDEBUG "cs=%p eip=%p eax=%p ebx=%p\n",
-            param->cs,
-            param->eip,
+            execp->cs,
+            execp->eip,
             param->registers.eax,
             param->registers.ebx);
     kprintf(KDEBUG "ecx=%p edx=%p edi=%p esi=%p\n",
@@ -85,12 +88,12 @@ sdbg_imm(const isr_param* param)
             param->registers.edi,
             param->registers.esi);
     kprintf(KDEBUG "u.esp=%p k.esp=%p ebp=%p ps=%p\n",
-            param->registers.esp,
             param->esp,
+            execp->esp,
             param->registers.ebp,
-            param->eflags);
+            execp->eflags);
     kprintf(KDEBUG "ss=%p ds=%p es=%p fs=%p gs=%p\n",
-            param->ss,
+            execp->ss,
             param->registers.ds,
             param->registers.es,
             param->registers.fs,
@@ -99,18 +102,11 @@ sdbg_imm(const isr_param* param)
     while (1)
         ;
 }
-
-extern uint8_t
-ioapic_get_irq(acpi_context* acpi_ctx, uint8_t old_irq);
-
 void
 sdbg_init()
 {
-    intr_subscribe(UART_COM1, sdbg_loop);
-    intr_subscribe(INSTR_DEBUG, sdbg_loop); // #DB
-    intr_subscribe(INSTR_BREAK, sdbg_loop); // #BRK
+    isrm_bindiv(INSTR_DEBUG, sdbg_loop); // #DB
+    isrm_bindiv(INSTR_BREAK, sdbg_loop); // #BRK
 
-    acpi_context* acpi_ctx = acpi_get_context();
-    uint8_t irq = ioapic_get_irq(acpi_ctx, COM1_IRQ);
-    ioapic_redirect(irq, UART_COM1, 0, IOAPIC_DELMOD_FIXED);
+    isrm_bindirq(COM1_IRQ, sdbg_loop);
 }
\ No newline at end of file