summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-02-16 12:35:04 -0600
committerDanny Holman <dholman@gymli.org>2024-02-16 12:35:04 -0600
commitfa748f3e1c0b0571e2c53514a55794ca16d90b18 (patch)
treee722b4feae40dd020a63710c55b80fab0ea7bb82
parenta267b8c076793cf59c2f6c80a31d7d094a215aab (diff)
arch: i386: kernel: the serial driver should be more POSIX-y
Make the serial driver behave more like a standard POSIX call. It should have write and read functions that call architecture specific functions. Signed-off-by: Danny Holman <dholman@gymli.org>
-rw-r--r--arch/i386/kernel/serial.c26
-rw-r--r--include/kernel/serial.h22
2 files changed, 27 insertions, 21 deletions
diff --git a/arch/i386/kernel/serial.c b/arch/i386/kernel/serial.c
index 5bd4105..25a01fe 100644
--- a/arch/i386/kernel/serial.c
+++ b/arch/i386/kernel/serial.c
@@ -5,6 +5,14 @@
#define PORT 0x3f8
+static inline int _serial_received(void) {
+ return inb(PORT + 5) & 1;
+}
+
+static inline int _is_transmit_empty(void) {
+ return inb(PORT + 5) & 0x20;
+}
+
int serial_init(void) {
outb(PORT + 1, 0x00);
outb(PORT + 3, 0x80);
@@ -23,20 +31,12 @@ int serial_init(void) {
return 0;
}
-int serial_recieved(void) {
- return inb(PORT + 5) & 1;
+void serial_putchar(char c) {
+ while (_is_transmit_empty() == 0);
+ outb(PORT, c);
}
-char read_serial(void) {
- while (serial_recieved() == 0);
+char serial_getchar(void) {
+ while (_serial_received() == 0);
return inb(PORT);
}
-
-int is_transmit_empty(void) {
- return inb(PORT + 5) & 0x20;
-}
-
-void write_serial(char a) {
- while (is_transmit_empty() == 0);
- outb(PORT, a);
-}
diff --git a/include/kernel/serial.h b/include/kernel/serial.h
index 24def78..4767722 100644
--- a/include/kernel/serial.h
+++ b/include/kernel/serial.h
@@ -1,15 +1,21 @@
-#ifndef SERIAL_H
-#define SERIAL_H
+#ifndef KERNEL_SERIAL_H
+#define KERNEL_SERIAL_H
-#include <kernel/string.h>
+#include <stdint.h>
+#include <stddef.h>
int serial_init(void);
-char read_serial(void);
-void write_serial(char a);
+void serial_putchar(char c);
+char serial_getchar(void);
-static inline void serial_writestring(const char *str) {
- for (size_t i = 0; i < strlen(str); i++)
- write_serial(str[i]);
+static inline void serial_write(const char *data, size_t size) {
+ for (size_t i = 0; i < size; i++)
+ serial_putchar(data[i]);
+}
+
+static inline void serial_read(char *data, size_t size) {
+ for (size_t i = 0; i < size; i++)
+ data[i] = serial_getchar();
}
#endif