summaryrefslogtreecommitdiffstats
path: root/include/device
diff options
context:
space:
mode:
Diffstat (limited to 'include/device')
-rw-r--r--include/device/serial.h48
-rw-r--r--include/device/uart.h19
2 files changed, 67 insertions, 0 deletions
diff --git a/include/device/serial.h b/include/device/serial.h
new file mode 100644
index 0000000..d59b00f
--- /dev/null
+++ b/include/device/serial.h
@@ -0,0 +1,48 @@
+#ifndef _JOVE_DEVICE_SERIAL_H
+#define _JOVE_DEVICE_SERIAL_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stddef.h>
+#include "klib/spinlock.h"
+
+#define SERIAL_UART_COM1 0x3F8
+#define SERIAL_UART_COM2 0x2F8
+
+#define SERIAL_UART_COM_THR(COM) COM
+#define SERIAL_UART_COM_RBR(COM) COM
+#define SERIAL_UART_COM_DLAB_DLL(COM) COM
+#define SERIAL_UART_COM_IER(COM) (COM + 1)
+#define SERIAL_UART_COM_DLAB_DLH(COM) (COM + 1)
+#define SERIAL_UART_COM_IIR(COM) (COM + 2)
+#define SERIAL_UART_COM_FCR(COM) (COM + 2)
+#define SERIAL_UART_COM_LCR(COM) (COM + 3)
+#define SERIAL_UART_COM_MCR(COM) (COM + 4)
+#define SERIAL_UART_COM_LSR(COM) (COM + 5)
+#define SERIAL_UART_COM_MSR(COM) (COM + 6)
+#define SERIAL_UART_COM_SR(COM) (COM + 7)
+
+typedef struct serial_device
+{
+ uint16_t com;
+ spinlock_t lock;
+} serial_dev_t;
+
+extern serial_dev_t COM1;
+
+void serial_setup(void);
+serial_dev_t serial_new(uint16_t com);
+
+void serial_set_int(serial_dev_t *dev, bool enable);
+void serial_set_baud(serial_dev_t *dev, uint16_t baud);
+
+void serial_set_fcr(serial_dev_t *dev, uint16_t flg);
+void serial_set_lcr(serial_dev_t *dev, uint16_t flg);
+void serial_set_mcr(serial_dev_t *dev, uint16_t flg);
+void serial_set_lsr(serial_dev_t *dev, uint16_t flg);
+void serial_set_msr(serial_dev_t *dev, uint16_t flg);
+
+uint8_t serial_line_status(serial_dev_t *dev);
+void serial_write(serial_dev_t *dev, const char *s, size_t len);
+
+#endif
diff --git a/include/device/uart.h b/include/device/uart.h
new file mode 100644
index 0000000..1724eb5
--- /dev/null
+++ b/include/device/uart.h
@@ -0,0 +1,19 @@
+#ifndef JOVE_KERNEL_ARCH_x86_64_UART_H
+#define JOVE_KERNEL_ARCH_x86_64_UART_H 1
+
+#include "jove.h"
+#include <stdint.h>
+
+ALWAYS_INLINE uint8_t pinb(uint16_t port)
+{
+ uint8_t v;
+ __asm__ volatile("inb %1, %0": "=a"(v): "Nd"(port));
+ return v;
+}
+
+ALWAYS_INLINE void poutb(uint16_t port, uint8_t b)
+{
+ __asm__ volatile("outb %0, %1":: "a"(b), "Nd"(port));
+}
+
+#endif