tty: add tee
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
e78aeb66fb
commit
4909482a2e
5 changed files with 88 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
17
init/main.c
17
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 :) */
|
||||
|
|
|
|||
|
|
@ -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
67
kernel/tty/tee.c
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue