1 #include <hal/acpi/acpi.h>
2 #include <hal/ioapic.h>
3 #include <klibc/stdio.h>
4 #include <lunaix/lxconsole.h>
5 #include <lunaix/peripheral/serial.h>
6 #include <lunaix/syslog.h>
7 #include <sdbg/gdbstub.h>
8 #include <sdbg/lsdbg.h>
9 #include <sdbg/protocol.h>
11 // #define USE_LSDBG_BACKEND
15 volatile int debug_mode = 0;
18 sdbg_loop(const isr_param* param)
20 // This is importnat, because we will handle any subsequent RX/TX in a
21 // synchronized way. And we don't want these irq queue up at our APIC and
22 // confuse the CPU after ACK with APIC.
23 serial_disable_irq(SERIAL_COM1);
24 if (param->vector == 1 || param->vector == 3) {
29 // Oh... C.M.C. is about to help the debugging!
30 if (serial_rx_byte(SERIAL_COM1) != '@') {
33 if (serial_rx_byte(SERIAL_COM1) != 'c') {
36 if (serial_rx_byte(SERIAL_COM1) != 'm') {
39 if (serial_rx_byte(SERIAL_COM1) != 'c') {
44 if (serial_rx_byte(SERIAL_COM1) != '@') {
47 if (serial_rx_byte(SERIAL_COM1) != 'y') {
50 if (serial_rx_byte(SERIAL_COM1) != 'a') {
53 if (serial_rx_byte(SERIAL_COM1) != 'y') {
62 #ifdef USE_LSDBG_BACKEND
63 lunaix_sdbg_loop(param);
70 serial_enable_irq(SERIAL_COM1);
74 sdbg_imm(const isr_param* param)
76 kprintf(KDEBUG "Quick debug mode\n");
77 kprintf(KDEBUG "cs=%p eip=%p eax=%p ebx=%p\n",
81 param->registers.ebx);
82 kprintf(KDEBUG "ecx=%p edx=%p edi=%p esi=%p\n",
86 param->registers.esi);
87 kprintf(KDEBUG "u.esp=%p k.esp=%p ebp=%p ps=%p\n",
92 kprintf(KDEBUG "ss=%p ds=%p es=%p fs=%p gs=%p\n",
104 ioapic_get_irq(acpi_context* acpi_ctx, uint8_t old_irq);
109 intr_subscribe(UART_COM1, sdbg_loop);
110 intr_subscribe(INSTR_DEBUG, sdbg_loop); // #DB
111 intr_subscribe(INSTR_BREAK, sdbg_loop); // #BRK
113 acpi_context* acpi_ctx = acpi_get_context();
114 uint8_t irq = ioapic_get_irq(acpi_ctx, COM1_IRQ);
115 ioapic_redirect(irq, UART_COM1, 0, IOAPIC_DELMOD_FIXED);