summaryrefslogtreecommitdiff
path: root/arch/i386/serial.c
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.xyz>2021-01-20 21:31:23 -0600
committerDanny Holman <dholman@gymli.xyz>2021-01-20 21:31:23 -0600
commit7a6cf86e4dd3094ed5aa41bf76d93c28c89e85e7 (patch)
treedd076e1a2307b8f2d5ee26b8df118ba45604ad1d /arch/i386/serial.c
parentec075eefe8733bb788627f5e5b5bf467de7a4c05 (diff)
i386: add serial port support
Add support for serial communication in the i386 architecture. Signed-off-by: Danny Holman <dholman@gymli.xyz>
Diffstat (limited to 'arch/i386/serial.c')
-rw-r--r--arch/i386/serial.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/arch/i386/serial.c b/arch/i386/serial.c
new file mode 100644
index 0000000..b172e82
--- /dev/null
+++ b/arch/i386/serial.c
@@ -0,0 +1,40 @@
+#include <kernel/serial.h>
+#include "pic.h"
+
+#define PORT 0x3f8
+
+static int serial_init(void) {
+ outb(PORT + 1, 0x00);
+ outb(PORT + 3, 0x80);
+ outb(PORT + 0, 0x03);
+ outb(PORT + 1, 0x00);
+ outb(PORT + 3, 0x03);
+ outb(PORT + 2, 0xC7);
+ outb(PORT + 4, 0x0B);
+ outb(PORT + 4, 0x1E);
+ outb(PORT + 0, 0xAE);
+
+ if (inb(PORT + 0) != 0xAE)
+ return -1;
+
+ outb(PORT + 4, 0x0F);
+ return 0;
+}
+
+int serial_recieved(void) {
+ return inb(PORT + 5) & 1;
+}
+
+char read_serial(void) {
+ while (serial_recieved() == 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);
+}