kernel: tty: support printing output from printk()
This commit is contained in:
@@ -93,6 +93,8 @@ extern kern_status_t tty_bootstrap(void);
|
|||||||
extern struct device *tty_device_create(void);
|
extern struct device *tty_device_create(void);
|
||||||
extern kern_status_t tty_device_register(struct device *dev, struct tty_driver *owner, struct device *parent);
|
extern kern_status_t tty_device_register(struct device *dev, struct tty_driver *owner, struct device *parent);
|
||||||
|
|
||||||
|
extern void tty_set_printk_output(struct device *tty);
|
||||||
|
|
||||||
extern struct tty_driver *tty_driver_create(struct kext *self, const char *name);
|
extern struct tty_driver *tty_driver_create(struct kext *self, const char *name);
|
||||||
extern kern_status_t tty_driver_destroy(struct tty_driver *drv);
|
extern kern_status_t tty_driver_destroy(struct tty_driver *drv);
|
||||||
extern kern_status_t tty_driver_register(struct tty_driver *drv);
|
extern kern_status_t tty_driver_register(struct tty_driver *drv);
|
||||||
|
|||||||
26
init/main.c
26
init/main.c
@@ -6,6 +6,7 @@
|
|||||||
#include <socks/test.h>
|
#include <socks/test.h>
|
||||||
#include <socks/printk.h>
|
#include <socks/printk.h>
|
||||||
#include <socks/device.h>
|
#include <socks/device.h>
|
||||||
|
#include <socks/tty.h>
|
||||||
#include <socks/kext.h>
|
#include <socks/kext.h>
|
||||||
#include <socks/object.h>
|
#include <socks/object.h>
|
||||||
#include <socks/sched.h>
|
#include <socks/sched.h>
|
||||||
@@ -192,9 +193,25 @@ void kernel_init(uintptr_t arg)
|
|||||||
struct object *fb;
|
struct object *fb;
|
||||||
status = object_get("/dev/video/fb0", &fb);
|
status = object_get("/dev/video/fb0", &fb);
|
||||||
if (status == KERN_OK) {
|
if (status == KERN_OK) {
|
||||||
|
#if 0
|
||||||
|
struct framebuffer_varinfo fb_mode;
|
||||||
|
struct device *fbdev = cast_to_device(fb);
|
||||||
|
framebuffer_get_varinfo(fbdev, &fb_mode);
|
||||||
|
fb_mode.fb_xres = 1024;
|
||||||
|
fb_mode.fb_yres = 768;
|
||||||
|
fb_mode.fb_bpp = 24;
|
||||||
|
fb_mode.fb_flags = FB_MODE_RGB;
|
||||||
|
framebuffer_set_varinfo(fbdev, &fb_mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
start_console_on_framebuffer(cast_to_device(fb));
|
start_console_on_framebuffer(cast_to_device(fb));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
struct object *tty0;
|
||||||
|
status = object_get("/dev/tty/tty0", &tty0);
|
||||||
|
if (status == KERN_OK) {
|
||||||
|
tty_set_printk_output(cast_to_device(tty0));
|
||||||
|
}
|
||||||
|
|
||||||
create_kernel_thread(background_thread);
|
create_kernel_thread(background_thread);
|
||||||
|
|
||||||
@@ -202,15 +219,6 @@ void kernel_init(uintptr_t arg)
|
|||||||
|
|
||||||
run_all_tests();
|
run_all_tests();
|
||||||
|
|
||||||
struct object *tty0;
|
|
||||||
status = object_get("/dev/tty/tty0", &tty0);
|
|
||||||
if (status == KERN_OK) {
|
|
||||||
size_t q;
|
|
||||||
object_write(tty0, "hello", 5, &q, 0);
|
|
||||||
} else {
|
|
||||||
printk("tty: unavailable");
|
|
||||||
}
|
|
||||||
|
|
||||||
status = object_get("/dev/input/input0", &kbd);
|
status = object_get("/dev/input/input0", &kbd);
|
||||||
if (status != KERN_OK) {
|
if (status != KERN_OK) {
|
||||||
printk("no keyboard available");
|
printk("no keyboard available");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <socks/tty.h>
|
#include <socks/tty.h>
|
||||||
#include <socks/device.h>
|
#include <socks/device.h>
|
||||||
|
#include <socks/console.h>
|
||||||
#include <socks/libc/stdio.h>
|
#include <socks/libc/stdio.h>
|
||||||
|
|
||||||
static struct char_device_ops tty_ops = {
|
static struct char_device_ops tty_ops = {
|
||||||
@@ -7,6 +8,19 @@ static struct char_device_ops tty_ops = {
|
|||||||
.write = tty_write,
|
.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 device *tty_device_create(void)
|
||||||
{
|
{
|
||||||
struct char_device *cdev = char_device_create();
|
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);
|
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