kernel: tty: support printing output from printk()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <socks/tty.h>
|
||||
#include <socks/device.h>
|
||||
#include <socks/console.h>
|
||||
#include <socks/libc/stdio.h>
|
||||
|
||||
static struct char_device_ops tty_ops = {
|
||||
@@ -7,6 +8,19 @@ static struct char_device_ops tty_ops = {
|
||||
.write = tty_write,
|
||||
};
|
||||
|
||||
static struct device *tty_printk_output = NULL;
|
||||
|
||||
static void tty_console_write(struct console *con, const char *s, unsigned int len)
|
||||
{
|
||||
size_t nr_written;
|
||||
tty_write(tty_printk_output, s, len, &nr_written, 0);
|
||||
}
|
||||
|
||||
static struct console tty_console = {
|
||||
.c_name = "tty",
|
||||
.c_write = tty_console_write,
|
||||
};
|
||||
|
||||
struct device *tty_device_create(void)
|
||||
{
|
||||
struct char_device *cdev = char_device_create();
|
||||
@@ -47,3 +61,17 @@ kern_status_t tty_device_register(struct device *dev, struct tty_driver *owner,
|
||||
|
||||
return object_namespace_create_link(global_namespace(), link_path, &dev->dev_base);
|
||||
}
|
||||
|
||||
void tty_set_printk_output(struct device *tty)
|
||||
{
|
||||
bool console_init = false;
|
||||
if (tty_printk_output) {
|
||||
console_init = true;
|
||||
}
|
||||
|
||||
tty_printk_output = tty;
|
||||
|
||||
if (!console_init) {
|
||||
console_register(&tty_console);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user