98 lines
2.2 KiB
C
98 lines
2.2 KiB
C
#include <socks/printk.h>
|
|
#include <socks/device.h>
|
|
#include <socks/kext.h>
|
|
#include <socks/tty.h>
|
|
#include <socks/libc/stdio.h>
|
|
#include "fbcon.h"
|
|
|
|
static struct tty_driver *fbcon_driver = NULL;
|
|
|
|
static void tty_clear(struct device *dev, int x, int y, int width, int height)
|
|
{
|
|
struct fbcon_priv *priv = dev->dev_priv;
|
|
priv->tty_ops->tty_clear(dev, x, y, width, height);
|
|
}
|
|
|
|
static void tty_putc(struct device *dev, int c, int xpos, int ypos, tty_attrib_t attrib)
|
|
{
|
|
struct fbcon_priv *priv = dev->dev_priv;
|
|
priv->tty_ops->tty_putc(dev, c, xpos, ypos, attrib);
|
|
}
|
|
|
|
static void tty_set_cursor(struct device *dev, enum tty_cursor cur)
|
|
{
|
|
struct fbcon_priv *priv = dev->dev_priv;
|
|
priv->tty_ops->tty_set_cursor(dev, cur);
|
|
}
|
|
|
|
static void tty_move_cursor(struct device *dev, int x, int y)
|
|
{
|
|
struct fbcon_priv *priv = dev->dev_priv;
|
|
priv->tty_ops->tty_move_cursor(dev, x, y);
|
|
}
|
|
|
|
static void tty_scroll(struct device *dev, enum tty_scroll_dir dir, int lines)
|
|
{
|
|
struct fbcon_priv *priv = dev->dev_priv;
|
|
priv->tty_ops->tty_scroll(dev, dir, lines);
|
|
}
|
|
|
|
static struct tty_driver_ops tty_ops = {
|
|
.tty_clear = tty_clear,
|
|
.tty_putc = tty_putc,
|
|
.tty_set_cursor = tty_set_cursor,
|
|
.tty_move_cursor = tty_move_cursor,
|
|
.tty_scroll = tty_scroll,
|
|
};
|
|
|
|
static kern_status_t online(struct kext *self)
|
|
{
|
|
fbcon_driver = tty_driver_create(self, "tty");
|
|
if (!fbcon_driver) {
|
|
return KERN_NO_MEMORY;
|
|
}
|
|
|
|
fbcon_driver->tty_ops = &tty_ops;
|
|
fbcon_driver->tty_type = TTY_DRIVER_FULL;
|
|
|
|
tty_driver_register(fbcon_driver);
|
|
|
|
return KERN_OK;
|
|
}
|
|
|
|
kern_status_t start_console_on_framebuffer(struct device *fb)
|
|
{
|
|
struct framebuffer_varinfo fb_mode;
|
|
framebuffer_get_varinfo(fb, &fb_mode);
|
|
|
|
struct device *tty = tty_device_create();
|
|
|
|
/* TODO actual IDs for FB tty devices */
|
|
snprintf(tty->dev_name, sizeof tty->dev_name, "ttyFB0");
|
|
|
|
kern_status_t status;
|
|
if (fb_mode.fb_flags & FB_MODE_VGATEXT) {
|
|
status = init_vgacon_console(tty, fb);
|
|
} else {
|
|
status = init_fbcon_console(tty, fb);
|
|
}
|
|
|
|
if (status != KERN_OK) {
|
|
/* TODO destroy tty device */
|
|
return status;
|
|
}
|
|
|
|
status = tty_device_register(tty, fbcon_driver, misc_device());
|
|
|
|
if (status != KERN_OK) {
|
|
/* TODO destroy tty device */
|
|
return status;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
DEFINE_KEXT("net.doorstuck.socks.fbcon",
|
|
online, NULL,
|
|
KEXT_NO_DEPENDENCIES);
|