Compare commits

...
Author SHA1 Message Date
4909482a2e tty: add tee
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-17 02:38:00 -04:00
e78aeb66fb limine: use serial and graphical modes
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-17 02:17:51 -04:00
7 changed files with 91 additions and 11 deletions

View file

@ -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;
}

View file

@ -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_ */

View file

@ -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 :) */

View file

@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += tee.o
obj-y += tty.o
obj-y += vt100.o

67
kernel/tty/tee.c Normal file
View file

@ -0,0 +1,67 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/tty.h>
#include <kernel/slab.h>
#include <lib/list.h>
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;
}
}

View file

@ -1,5 +1,5 @@
serial: yes
timeout: 1
resolution: 1920x1080
# The entry name that will be displayed in the boot menu.
/vbos

View file

@ -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: