diff --git a/amd64/amd64_init.c b/amd64/amd64_init.c index fd8a3e6..c709233 100644 --- a/amd64/amd64_init.c +++ b/amd64/amd64_init.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include -#include +#include #include #include #include "arch/reg.h" diff --git a/amd64/drivers/serial.c b/amd64/drivers/serial.c index 38dd216..9c761a3 100644 --- a/amd64/drivers/serial.c +++ b/amd64/drivers/serial.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include diff --git a/drivers/Makefile b/drivers/Makefile index 92e45d1..e76e034 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -1,5 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += acpi/ obj-y += pci/ -obj-y += tty/ #obj-y += ahci.o diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile deleted file mode 100644 index 7b44b69..0000000 --- a/drivers/tty/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -obj-y += tty.o -obj-y += vt100.o - diff --git a/drivers/tty/tty.c b/drivers/tty/tty.c deleted file mode 100644 index 1c3d21e..0000000 --- a/drivers/tty/tty.c +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#include -#include -#include -#include -#include - -static mem_cache_t *tty_slab; - -static struct tty_serial_ops arch_serial_ops = {.serial_getchar = arch_serial_read, .serial_putchar = arch_serial_write}; - -struct tty *tty_create(const char *name, void *priv) -{ - struct tty *tty = slab_alloc(tty_slab); - - dev_t tty_device = device_create(tty, DEV_CLASS_TTY, name); - - tty->dev = tty_device; - tty->priv = priv; - tty->serial_ops = arch_serial_ops; - - return tty; -} - -void tty_putchar(struct tty *tty, char c) -{ - tty->serial_ops.serial_putchar(tty, c); -} - -char tty_getchar(struct tty *tty) -{ - return tty->serial_ops.serial_getchar(tty); -} - -void tty_write(struct tty *tty, const char *s) -{ - char c; - while ((c = *s++)) - tty_putchar(tty, c); -} - -void tty_layer_init() -{ - tty_slab = slab_create("tty_layer", sizeof(struct tty), 256 * KB, 8); - - if (!tty_slab) { - panic("tty_slab alloc failed\n"); - } -} diff --git a/drivers/tty/vt100.c b/drivers/tty/vt100.c deleted file mode 100644 index 8598a41..0000000 --- a/drivers/tty/vt100.c +++ /dev/null @@ -1,87 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#include -#include -#include - -void tty_send_dsr(struct tty *tty) -{ - tty_write(tty, "\033[6n"); -} - -void tty_set_origin_mode(struct tty *tty) -{ - tty_write(tty, "\033[?6h"); -} - -void tty_clear_screen(struct tty *tty) -{ - tty_write(tty, "\033[2J"); -} - -void tty_set_cursor_pos(struct tty *tty, int r, int c) -{ - if (r > 999) - r = 999; - if (c > 999) - c = 999; - - char str[12] = { 0 }; - snprintf(str, 11, "\033[%d;%dH", r, c); - tty_write(tty, str); -} - -void tty_get_cursor_pos(struct tty *tty, int *row, int *col) -{ - tty_send_dsr(tty); - - char c; - int n = 0; - - char ro[128] = { 0 }; - char co[128] = { 0 }; - - bool sem = false; - bool begin = false; - - while ((c = tty_getchar(tty))) { - if (c == '\033') - continue; - - if (c == ';') { - sem = true; - n = 0; - } - - if (!begin) { - if (c == '[') - begin = true; - continue; - } - - if (c >= '0' && c <= '9') { - if (!sem) - ro[n] = c; - else - co[n] = c; - - n++; - } - - if (c == 'R') - break; - } - - *row = atoi(ro); - *col = atoi(co); -} - -void tty_get_size(struct tty *tty, int *rows, int *cols) -{ - tty_set_cursor_pos(tty, 999, 999); - tty_get_cursor_pos(tty, rows, cols); -} - -void tty_setlf(struct tty *tty) -{ - tty_write(tty, "\033[20l"); -} diff --git a/fs/vfs/devfs.c b/fs/vfs/devfs.c index 50f61d5..961b297 100644 --- a/fs/vfs/devfs.c +++ b/fs/vfs/devfs.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include #include -#include +#include #include #include diff --git a/include/drivers/tty.h b/include/drivers/tty.h deleted file mode 100644 index 33f74c4..0000000 --- a/include/drivers/tty.h +++ /dev/null @@ -1,36 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _TTY_H_ -#define _TTY_H_ - -#include - -struct tty_serial_ops { - void (*serial_putchar)(struct tty *tty, char c); - char (*serial_getchar)(struct tty *tty); -}; - -struct tty { - dev_t dev; - void *priv; - struct tty_serial_ops serial_ops; -}; - -void tty_layer_init(); - -struct tty *tty_create(const char *name, void *priv); -void tty_putchar(struct tty *tty, char c); -char tty_getchar(struct tty *tty); -void tty_write(struct tty *tty, const char *s); - -void arch_serial_write(struct tty *tty, char c); -char arch_serial_read(struct tty *tty); - -void tty_send_dsr(struct tty *tty); -void tty_set_origin_mode(struct tty *tty); -void tty_clear_screen(struct tty *tty); -void tty_set_cursor_pos(struct tty *tty, int x, int y); -void tty_get_cursor_pos(struct tty *tty, int *row, int *col); -void tty_get_size(struct tty *tty, int *rows, int *cols); -void tty_setlf(struct tty *tty); - -#endif /* _TTY_H_ */ diff --git a/include/fs/devfs.h b/include/fs/devfs.h index 7b18283..1e60201 100644 --- a/include/fs/devfs.h +++ b/include/fs/devfs.h @@ -4,7 +4,7 @@ #include -#include +#include #include diff --git a/init/main.c b/init/main.c index 80c855a..030188d 100644 --- a/init/main.c +++ b/init/main.c @@ -15,7 +15,7 @@ #include -#include +#include #include #include #include diff --git a/kernel/Makefile b/kernel/Makefile index af3538b..5dafe9b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += device.o obj-y += block.o +obj-y += tty/ diff --git a/kernel/device.c b/kernel/device.c index b3fc145..868e41a 100644 --- a/kernel/device.c +++ b/kernel/device.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include +#include #include #include #include diff --git a/lib/printf.c b/lib/printf.c index e4c5950..f7150e8 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -39,7 +39,7 @@ #include #include -#include +#include // define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the // printf_config.h header file