summaryrefslogtreecommitdiff
path: root/src/kernel/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/arch')
-rw-r--r--src/kernel/arch/i386/tty/serial.c5
-rw-r--r--src/kernel/arch/i386/tty/serial.h1
-rw-r--r--src/kernel/arch/i386/tty/tty.c5
-rw-r--r--src/kernel/arch/io.h1
4 files changed, 12 insertions, 0 deletions
diff --git a/src/kernel/arch/i386/tty/serial.c b/src/kernel/arch/i386/tty/serial.c
index 6ddc05b..2b89ecf 100644
--- a/src/kernel/arch/i386/tty/serial.c
+++ b/src/kernel/arch/i386/tty/serial.c
@@ -35,6 +35,11 @@ static void serial_putchar(char c) {
port_outb(COM1, c);
}
+char serial_read(void) {
+ while ((port_inb(COM1 + 5) & 0x01) == 0); // wait for DR
+ return port_inb(COM1);
+}
+
void serial_write(const char *buf, size_t len) {
for (size_t i = 0; i < len; i++)
serial_putchar(buf[i]);
diff --git a/src/kernel/arch/i386/tty/serial.h b/src/kernel/arch/i386/tty/serial.h
index 2332113..751e528 100644
--- a/src/kernel/arch/i386/tty/serial.h
+++ b/src/kernel/arch/i386/tty/serial.h
@@ -1,5 +1,6 @@
#pragma once
#include <stddef.h>
+char serial_read(void);
void serial_write(const char *buf, size_t len);
void serial_init(void);
diff --git a/src/kernel/arch/i386/tty/tty.c b/src/kernel/arch/i386/tty/tty.c
index bae65c5..5a65221 100644
--- a/src/kernel/arch/i386/tty/tty.c
+++ b/src/kernel/arch/i386/tty/tty.c
@@ -11,6 +11,11 @@ void tty_init(void) {
serial_write("<3 ", 3);
}
+void tty_read(char *buf, size_t len) {
+ for (size_t i = 0; i < len; i++)
+ buf[i] = serial_read();
+}
+
void tty_write(const char *buf, size_t len) {
vga_write(buf, len);
serial_write(buf, len);
diff --git a/src/kernel/arch/io.h b/src/kernel/arch/io.h
index ef8cb17..acba67a 100644
--- a/src/kernel/arch/io.h
+++ b/src/kernel/arch/io.h
@@ -2,6 +2,7 @@
#include <stddef.h>
void tty_init(void);
+void tty_read(char *buf, size_t len);
void tty_write(const char *buf, size_t len);
static inline void _tty_hex(const char *buf, size_t len) {