1 #include <hal/acpi/acpi.h>
2 #include <hal/ioapic.h>
3 #include <klibc/stdio.h>
4 #include <lunaix/isrm.h>
5 #include <lunaix/lxconsole.h>
6 #include <lunaix/peripheral/serial.h>
7 #include <lunaix/syslog.h>
8 #include <sdbg/gdbstub.h>
9 #include <sdbg/lsdbg.h>
10 #include <sdbg/protocol.h>
12 // #define USE_LSDBG_BACKEND
16 volatile int debug_mode = 0;
19 sdbg_loop(const isr_param* param)
21 // This is importnat, because we will handle any subsequent RX/TX in a
22 // synchronized way. And we don't want these irq queue up at our APIC and
23 // confuse the CPU after ACK with APIC.
24 serial_disable_irq(SERIAL_COM1);
25 struct exec_param* execp = param->execp;
26 if (execp->vector == 1 || execp->vector == 3) {
31 // Oh... C.M.C. is about to help the debugging!
32 if (serial_rx_byte(SERIAL_COM1) != '@') {
35 if (serial_rx_byte(SERIAL_COM1) != 'c') {
38 if (serial_rx_byte(SERIAL_COM1) != 'm') {
41 if (serial_rx_byte(SERIAL_COM1) != 'c') {
46 if (serial_rx_byte(SERIAL_COM1) != '@') {
49 if (serial_rx_byte(SERIAL_COM1) != 'y') {
52 if (serial_rx_byte(SERIAL_COM1) != 'a') {
55 if (serial_rx_byte(SERIAL_COM1) != 'y') {
64 #ifdef USE_LSDBG_BACKEND
65 lunaix_sdbg_loop(param);
72 serial_enable_irq(SERIAL_COM1);
76 sdbg_imm(const isr_param* param)
78 struct exec_param* execp = param->execp;
79 kprintf(KDEBUG "Quick debug mode\n");
80 kprintf(KDEBUG "cs=%p eip=%p eax=%p ebx=%p\n",
84 param->registers.ebx);
85 kprintf(KDEBUG "ecx=%p edx=%p edi=%p esi=%p\n",
89 param->registers.esi);
90 kprintf(KDEBUG "u.esp=%p k.esp=%p ebp=%p ps=%p\n",
95 kprintf(KDEBUG "ss=%p ds=%p es=%p fs=%p gs=%p\n",
100 param->registers.gs);
108 isrm_bindiv(INSTR_DEBUG, sdbg_loop); // #DB
109 isrm_bindiv(INSTR_BREAK, sdbg_loop); // #BRK
111 isrm_bindirq(COM1_IRQ, sdbg_loop);