feat: capability list to enable greater flexibility of devices
[lunaix-os.git] / lunaix-os / kernel / debug / gdbstub.c
index 38d35adf0b13e75a56aa771725a0abdb3ce3840d..963e5ff7dafeafd49e185dd9cafb5dd4f5f43ef6 100644 (file)
  * SOFTWARE.
  */
 
-#include <hal/io.h>
+#include <hal/serial.h>
 #include <klibc/string.h>
-#include <lunaix/peripheral/serial.h>
 #include <sdbg/gdbstub.h>
+#include <sys/port_io.h>
 
 /*****************************************************************************
  * Types
@@ -74,6 +74,7 @@ enum GDB_REGISTER
 struct gdb_state
 {
     int signum;
+    struct serial_dev* sdev;
     reg registers[GDB_CPU_NUM_REGISTERS];
 };
 
@@ -884,13 +885,9 @@ gdb_send_error_packet(struct gdb_state* state,
 static int
 gdb_write(struct gdb_state* state, const char* buf, unsigned int len)
 {
-    while (len--) {
-        if (gdb_sys_putchar(state, *buf++) == GDB_EOF) {
-            return GDB_EOF;
-        }
-    }
+    int err = serial_rwbuf_sync(state->sdev, buf, len, SERIAL_RW_TX);
 
-    return 0;
+    return err < 0 ? GDB_EOF : 0;
 }
 
 /*
@@ -913,14 +910,9 @@ gdb_read(struct gdb_state* state,
         return GDB_EOF;
     }
 
-    while (len--) {
-        if ((c = gdb_sys_getc(state)) == GDB_EOF) {
-            return GDB_EOF;
-        }
-        *buf++ = c;
-    }
+    int err = serial_rwbuf_sync(state->sdev, buf, buf_len, SERIAL_RW_RX);
 
-    return 0;
+    return err < 0 ? GDB_EOF : 0;
 }
 
 /*****************************************************************************
@@ -1191,8 +1183,8 @@ struct gdb_idt_gate
 /*****************************************************************************
  * Prototypes
  ****************************************************************************/
-#define gdb_x86_io_write_8(port, val) io_outb(port, val)
-#define gdb_x86_io_read_8(port) io_inb(port)
+#define gdb_x86_io_write_8(port, val) port_wrbyte(port, val)
+#define gdb_x86_io_read_8(port) port_rdbyte(port)
 
 #define gdb_x86_serial_getc() serial_rx_byte(COM_PORT)
 #define gdb_x86_serial_putchar(ch) serial_tx_byte(COM_PORT, ch)
@@ -1271,7 +1263,7 @@ gdbstub_loop(isr_param* param)
 int
 gdb_sys_putchar(struct gdb_state* state, int ch)
 {
-    gdb_x86_serial_putchar(ch);
+    serial_rwbuf_sync(state->sdev, &ch, 1, SERIAL_RW_TX);
     return ch;
 }
 
@@ -1281,7 +1273,9 @@ gdb_sys_putchar(struct gdb_state* state, int ch)
 int
 gdb_sys_getc(struct gdb_state* state)
 {
-    return gdb_x86_serial_getc() & 0xff;
+    char ch;
+    serial_rwbuf_sync(state->sdev, &ch, 1, SERIAL_RW_RX);
+    return ch & 0xff;
 }
 
 /*