kernel: add definitions for a TTY device interface.

This commit is contained in:
2023-02-09 09:17:04 +00:00
parent 943e9dc517
commit 5b9bdd4848
3 changed files with 116 additions and 0 deletions

View File

@@ -1,11 +1,27 @@
#ifndef SOCKS_CONSOLE_H_
#define SOCKS_CONSOLE_H_
/* The console system
Consoles are like simplified TTYs. Their purpose is to serve as an output
sink for messages printed using printk.
a console_t could be used to represent a serial port, UART port, or even
a text-based framebuffer display. Anything where the job of displaying
or sending text can be abstracted to a simple write() call.
A secondary purpose of consoles is to allow input. For example, a console
representing a serial port may allow both sending AND receiving over the
port.
*/
#include <socks/queue.h>
#include <socks/locks.h>
#include <socks/status.h>
typedef enum console_flags {
/* console is only used during the boot process. the console
will be automatically de-registered when the first
non-boot console is registered */
CON_BOOT = 0x01u,
} console_flags_t;

87
include/socks/tty.h Normal file
View File

@@ -0,0 +1,87 @@
#ifndef SOCKS_TTY_H_
#define SOCKS_TTY_H_
#include <socks/status.h>
#include <socks/queue.h>
#include <stdint.h>
/* The TTY system.
TTYs are an enhanced version of the console object. Rather than a simple output
device for log messages, TTYs are intended to support fully-featured interactive
user sessions, including advanced display manipulation (if applicable) and
buffered user input.
A TTY object is split into 2 parts:
- tty_t: This represents the terminal session, and tracks things like the cursor
position, input buffer, flags, etc.
- tty_driver_t: This is a set of function callbacks that the TTY can use to
manipulate the output device. This could represent a char-based framebuffer
device, a serial port, etc.
*/
/* opaque context pointer for use by the tty driver */
typedef void *tty_driver_ctx_t;
typedef enum tty_driver_type {
/* For TTYs operating on simple IO devices like serial ports.
Allows writing characters, receiving characters, and not much else. */
TTY_DRIVER_SIMPLE,
/* For TTYs operating on more capable display interfaces.
Allows putting characters at arbitrary locations, scrolling, etc */
TTY_DRIVER_FULL,
} tty_driver_type_t;
/* TTY cursor status. The extra cursor styles are just for completeness,
the important one to support (if possible), is TTY_CURSOR_NONE.
The others can be interpreted as "just turn on a cursor of any style". */
typedef enum tty_cursor {
TTY_CURSOR_ULINE,
TTY_CURSOR_BLOCK,
TTY_CURSOR_NONE,
} tty_cursor_t;
/* direction to use for scrolling. The important one to support is
TTY_SCROLL_DOWN for when output overflows the display */
typedef enum tty_scroll_dir {
TTY_SCROLL_DOWN,
TTY_SCROLL_UP,
} tty_scroll_dir_t;
/* character attribute. this could be as simple as VGA's 16-colour palette
plus an extra bit for bright, or a full 24-bit RGB value with bold and underline
support, depending on what the driver supports. */
typedef uint64_t tty_attrib_t;
typedef struct tty_driver {
char tty_name[16];
tty_driver_type_t tty_type;
queue_entry_t tty_list;
void (*tty_init)(tty_driver_ctx_t *ctx);
void (*tty_deinit)(tty_driver_ctx_t ctx);
void (*tty_clear)(tty_driver_ctx_t ctx, int x, int y, int width, int height);
void (*tty_putc)(tty_driver_ctx_t ctx, int c, int xpos, int ypos, tty_attrib_t attrib);
void (*tty_set_cursor)(tty_driver_ctx_t ctx, tty_cursor_t cur);
void (*tty_move_cursor)(tty_driver_ctx_t ctx, int x, int y);
void (*tty_scroll)(tty_driver_ctx_t ctx, tty_scroll_dir_t dir, int lines);
} tty_driver_t;
typedef struct tty {
int tty_xcur, tty_ycur;
unsigned int tty_iflag, tty_oflag, tty_lflag;
tty_driver_ctx_t tty_dctx;
const tty_driver_t *tty_driver;
} tty_t;
extern kern_status_t tty_driver_register(tty_driver_t *drv);
extern kern_status_t tty_driver_unregister(tty_driver_t *drv);
extern tty_t *tty_create(void);
extern void tty_destroy(tty_t *tty);
extern int tty_read(tty_t *tty, char *s, unsigned long len);
extern int tty_write(tty_t *tty, const char *s, unsigned long len);
#endif

13
kernel/tty.c Normal file
View File

@@ -0,0 +1,13 @@
#include <socks/tty.h>
#include <socks/locks.h>
#include <socks/queue.h>
int tty_read(tty_t *tty, char *s, unsigned long len)
{
return 0;
}
int tty_write(tty_t *tty, const char *s, unsigned long len)
{
return 0;
}