tty: implement read/write support
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
#include <socks/device.h>
|
||||
#include <socks/libc/stdio.h>
|
||||
|
||||
static struct char_device_ops tty_ops = {
|
||||
.read = tty_read,
|
||||
.write = tty_write,
|
||||
};
|
||||
|
||||
struct device *tty_device_create(void)
|
||||
{
|
||||
struct char_device *cdev = char_device_create();
|
||||
@@ -15,7 +20,9 @@ struct device *tty_device_create(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cdev->c_ops = &tty_ops;
|
||||
cdev->c_tty = tty_dev;
|
||||
|
||||
return char_device_base(cdev);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ static struct vm_cache tty_driver_cache = {
|
||||
static struct queue tty_drivers;
|
||||
static spin_lock_t tty_drivers_lock;
|
||||
|
||||
kern_status_t tty_init(void)
|
||||
kern_status_t tty_bootstrap(void)
|
||||
{
|
||||
vm_cache_init(&tty_driver_cache);
|
||||
tty_drivers = QUEUE_INIT;
|
||||
|
||||
56
kernel/tty/tty.c
Normal file
56
kernel/tty/tty.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <socks/tty.h>
|
||||
#include <socks/printk.h>
|
||||
|
||||
static void putchar(struct device *tty, int c)
|
||||
{
|
||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
||||
struct tty_driver *tty_driver = TTY_DRIVER(tty->dev_owner);
|
||||
struct tty_driver_ops *ops = tty_driver->tty_ops;
|
||||
|
||||
if (!ops->tty_putc) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tty_driver->tty_type == TTY_DRIVER_SIMPLE) {
|
||||
ops->tty_putc(tty, c, -1, -1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
ops->tty_putc(tty, c, ttydev->tty_xcur, ttydev->tty_ycur, ttydev->tty_curattrib);
|
||||
ttydev->tty_xcur++;
|
||||
|
||||
if (ttydev->tty_xcur >= ttydev->tty_xcells) {
|
||||
ttydev->tty_xcur = 0;
|
||||
ttydev->tty_ycur++;
|
||||
}
|
||||
|
||||
if (ttydev->tty_ycur >= ttydev->tty_ycells) {
|
||||
if (ops->tty_scroll) {
|
||||
ops->tty_scroll(tty, TTY_SCROLL_DOWN, 1);
|
||||
} else {
|
||||
ttydev->tty_xcur = 0;
|
||||
ttydev->tty_ycur = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ops->tty_move_cursor(tty, ttydev->tty_xcur, ttydev->tty_ycur);
|
||||
}
|
||||
|
||||
kern_status_t tty_read(struct device *tty, void *buf, size_t max, size_t *nr_read, socks_flags_t flags)
|
||||
{
|
||||
printk("tty_read");
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t tty_write(struct device *tty, const void *buf, size_t len, size_t *nr_written, socks_flags_t flags)
|
||||
{
|
||||
size_t r = 0;
|
||||
const char *s = buf;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
putchar(tty, s[i]);
|
||||
r++;
|
||||
}
|
||||
|
||||
*nr_written = r;
|
||||
return KERN_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user