diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/init/main.c | 4 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/serial.c | 5 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/serial.h | 1 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/tty.c | 5 | ||||
-rw-r--r-- | src/kernel/arch/io.h | 1 | ||||
-rw-r--r-- | src/kernel/vfs/root.c | 16 |
6 files changed, 31 insertions, 1 deletions
diff --git a/src/init/main.c b/src/init/main.c index 1a6162a..5c798d2 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -28,6 +28,10 @@ int main(void) { fs_test(); test_await(); + char c; + while (_syscall_read(tty_fd, &c, 1, 0)) + _syscall_write(tty_fd, &c, 1, 0); + _syscall_exit(argify("my job here is done.")); } 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) { diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c index dca81d2..7e957ef 100644 --- a/src/kernel/vfs/root.c +++ b/src/kernel/vfs/root.c @@ -13,12 +13,26 @@ int vfs_root_handler(struct vfs_request *req) { return 0; } return -1; - case VFSOP_WRITE: + + case VFSOP_READ: switch (req->id) { // every id corresponds to a special file type // this is a shit way to do this but :shrug: case 0: { // tty struct virt_iter iter; + virt_iter_new(&iter, req->output.buf, req->output.len, + req->caller->pages, true, false); + while (virt_iter_next(&iter)) + tty_read(iter.frag, iter.frag_len); + return iter.prior; + } + default: panic_invalid_state(); + } + + case VFSOP_WRITE: + switch (req->id) { + case 0: { // tty + struct virt_iter iter; virt_iter_new(&iter, req->input.buf, req->input.len, req->caller->pages, true, false); while (virt_iter_next(&iter)) |