diff --git a/drivers/term/fbcon.c b/drivers/term/fbcon.c index 225f64d..9489027 100644 --- a/drivers/term/fbcon.c +++ b/drivers/term/fbcon.c @@ -31,17 +31,17 @@ static struct tty_serial_ops fbcon_serial_ops = { .serial_getchar = fbcon_getchar, }; -void fbcon_init(void) +struct tty *fbcon_init(void) { if (!fb_res || !fb_res->framebuffer_count) - return; + return NULL; struct limine_framebuffer *fb = fb_res->framebuffers[0]; size_t fb_size = fb->pitch * fb->height; void *fb_virt = map_mmio_dev((paddr_t)TO_PHYS(fb->address), fb_size); if (!fb_virt) - return; + return NULL; ft_ctx = flanterm_fb_init( NULL, NULL, fb_virt, fb->width, fb->height, fb->pitch, fb->red_mask_size, fb->red_mask_shift, fb->green_mask_size, @@ -49,7 +49,7 @@ void fbcon_init(void) 0, 0, 0, 0, FLANTERM_FB_ROTATE_0); if (!ft_ctx) - return; + return NULL; struct tty *fbtty = tty_create("tty1", NULL); @@ -57,4 +57,6 @@ void fbcon_init(void) tty_printf = fbtty; kinfo("fbcon: framebuffer console initialized (%lux%lu)\n", fb->width, fb->height); + + return fbtty; } diff --git a/include/kernel/tty.h b/include/kernel/tty.h index 33f74c4..c9986f4 100644 --- a/include/kernel/tty.h +++ b/include/kernel/tty.h @@ -32,5 +32,8 @@ 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); +struct tty *tty_tee_create(const char *name); +void tty_tee_add(struct tty *tee, struct tty *child); +void tty_tee_remove(struct tty *tee, struct tty *child); #endif /* _TTY_H_ */ diff --git a/init/main.c b/init/main.c index 83ed8c1..4119256 100644 --- a/init/main.c +++ b/init/main.c @@ -36,8 +36,10 @@ typedef void (*initcall_t)(void); +struct tty *fbcon_init(); +void arch_ap_startup(); + extern initcall_t __initcall_start, __initcall_end; -extern void fbcon_init(void); struct tty *tty_printf = NULL; bool kernel_init_ready = false; @@ -74,16 +76,19 @@ static void kmain() tty_layer_init(); /* init main fallback tty */ - struct tty *main_tty = NULL; - serial_port_tty_init(&main_tty); + struct tty *serial_tty = NULL; + serial_port_tty_init(&serial_tty); - tty_printf = main_tty; + struct tty *visual_tty = fbcon_init(); - fbcon_init(); + struct tty *tee = tty_tee_create("broadcast"); + tty_tee_add(tee, serial_tty); + tty_tee_add(tee, visual_tty); + + tty_printf = tee; do_initcalls(); - void arch_ap_startup(); arch_ap_startup(); /* do nothing, for now :) */ diff --git a/kernel/tty/Makefile b/kernel/tty/Makefile index 7b44b69..1106f7d 100644 --- a/kernel/tty/Makefile +++ b/kernel/tty/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-y += tee.o obj-y += tty.o obj-y += vt100.o diff --git a/kernel/tty/tee.c b/kernel/tty/tee.c new file mode 100644 index 0000000..703d890 --- /dev/null +++ b/kernel/tty/tee.c @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include +#include +#include + +static void serial_putchar(struct tty *tty, char c) +{ + list_t *list = tty->priv; + if (!list) + return; + list_item_t *item = list->head; + while (item) { + struct tty *next = item->ptr; + next->serial_ops.serial_putchar(next, c); + item = item->next; + } +} + +static char serial_getchar(struct tty *tty) +{ + /* can't read from a tee, duh */ + return 0; +} + +struct tty *tty_tee_create(const char *name) +{ + static struct tty_serial_ops ops = {.serial_putchar = serial_putchar, .serial_getchar = serial_getchar}; + + list_t *list = kzalloc(sizeof(list_t), ALLOC_KERN); + if (!list) + return NULL; + list_create(list); + struct tty *ret = tty_create(name, list); + + if (!ret) { + list_destroy(list); + kfree(list); + return NULL; + } + + ret->serial_ops = ops; + + return ret; +} + +void tty_tee_add(struct tty *tee, struct tty *child) +{ + list_t *list = tee->priv; + list_insert(list, child); +} + +void tty_tee_remove(struct tty *tee, struct tty *child) +{ + list_t *list = tee->priv; + if (!list) + return; + + list_item_t *item = list->head; + while (item) { + if (item->ptr == child) { + list_remove(item); + return; + } + + item = item->next; + } +} diff --git a/limine.conf b/limine.conf index 2b16ac7..de07032 100644 --- a/limine.conf +++ b/limine.conf @@ -1,5 +1,5 @@ +serial: yes timeout: 1 -resolution: 1920x1080 # The entry name that will be displayed in the boot menu. /vbos diff --git a/scripts/Makefile.limine b/scripts/Makefile.limine index 1a6a18e..c679083 100644 --- a/scripts/Makefile.limine +++ b/scripts/Makefile.limine @@ -47,6 +47,7 @@ run: edk2-ovmf $(INITRAMFS) $(IMG) -accel kvm \ -hda $(IMG) \ -hdb test_drive.hdd \ + -serial stdio \ $(QEMUFLAGS) .PHONY += debug @@ -57,6 +58,7 @@ debug: edk2-ovmf $(IMG) -drive if=pflash,unit=0,format=raw,file=edk2-ovmf/ovmf-code-$(ARCH).fd,readonly=on \ -hda $(IMG) \ -hdb test_drive.hdd \ + -serial stdio \ $(QEMUFLAGS) edk2-ovmf: