diff options
author | Ian Moffett <ian@osmora.org> | 2024-05-19 19:10:35 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-05-19 19:14:13 -0400 |
commit | 482a38725d4e1d9b5aee18e2b2d5af3d0b0e54e9 (patch) | |
tree | a7de5975cfc79d652f6328d1f3167986ca9ebe71 | |
parent | ddfedec2f91aa67cfc060ab35398e08ec1b1e37d (diff) |
kernel: tty: Implement tty_ioctl()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/include/sys/tty.h | 4 | ||||
-rw-r--r-- | sys/kern/kern_tty.c | 22 |
2 files changed, 26 insertions, 0 deletions
diff --git a/sys/include/sys/tty.h b/sys/include/sys/tty.h index a4595d5..18583a5 100644 --- a/sys/include/sys/tty.h +++ b/sys/include/sys/tty.h @@ -38,6 +38,10 @@ #include <dev/vcons/vcons.h> #endif +/* TTY ioctl commands */ +#define TCSETS 0x00000000U +#define TCGETS 0x00000001U + #if defined(_KERNEL) #define TTY_RING_SIZE 32 #define TTY_SOURCE_RAW 0x0001U /* Raw text */ diff --git a/sys/kern/kern_tty.c b/sys/kern/kern_tty.c index cb3e30a..5c060a4 100644 --- a/sys/kern/kern_tty.c +++ b/sys/kern/kern_tty.c @@ -28,6 +28,7 @@ */ #include <sys/tty.h> +#include <sys/system.h> #include <sys/cdefs.h> #include <sys/errno.h> #include <sys/syslog.h> @@ -153,6 +154,26 @@ tty_dev_read(struct device *dev, struct sio_txn *sio) return len; } +static int +tty_ioctl(struct device *dev, uint32_t cmd, uintptr_t arg) +{ + /* TODO: Support multiple TTYs */ + struct termios *tp = &g_root_tty.termios; + + switch (cmd) { + case TCGETS: + copyout(tp, arg, sizeof(struct termios)); + break; + case TCSETS: + copyin(arg, tp, sizeof(struct termios)); + break; + default: + return -EINVAL; + } + + return 0; +} + /* * Serialized wrapper over __tty_flush() */ @@ -264,6 +285,7 @@ tty_attach(struct tty *tty) return tmp; dev->read = tty_dev_read; + dev->ioctl = tty_ioctl; dev->blocksize = 1; snprintf(devname, sizeof(devname), "tty%d", tty->id); |