2023-02-09 09:17:04 +00:00
|
|
|
#ifndef SOCKS_TTY_H_
|
|
|
|
|
#define SOCKS_TTY_H_
|
|
|
|
|
|
|
|
|
|
#include <socks/status.h>
|
|
|
|
|
#include <socks/queue.h>
|
2023-05-14 21:11:32 +01:00
|
|
|
#include <socks/object.h>
|
2023-02-09 09:17:04 +00:00
|
|
|
#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:
|
2023-04-12 20:17:11 +01:00
|
|
|
- struct tty: This represents the terminal session, and tracks things like the cursor
|
2023-02-09 09:17:04 +00:00
|
|
|
position, input buffer, flags, etc.
|
2023-04-12 20:17:11 +01:00
|
|
|
- struct tty_driver: This is a set of function callbacks that the TTY can use to
|
2023-02-09 09:17:04 +00:00
|
|
|
manipulate the output device. This could represent a char-based framebuffer
|
|
|
|
|
device, a serial port, etc.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-09 09:17:04 +00:00
|
|
|
/* opaque context pointer for use by the tty driver */
|
|
|
|
|
typedef void *tty_driver_ctx_t;
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
enum tty_driver_type {
|
2023-02-09 09:17:04 +00:00
|
|
|
/* 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,
|
2023-04-12 20:17:11 +01:00
|
|
|
};
|
2023-02-09 09:17:04 +00:00
|
|
|
|
|
|
|
|
/* 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". */
|
2023-04-12 20:17:11 +01:00
|
|
|
enum tty_cursor {
|
2023-02-09 09:17:04 +00:00
|
|
|
TTY_CURSOR_ULINE,
|
|
|
|
|
TTY_CURSOR_BLOCK,
|
|
|
|
|
TTY_CURSOR_NONE,
|
2023-04-12 20:17:11 +01:00
|
|
|
};
|
2023-02-09 09:17:04 +00:00
|
|
|
|
|
|
|
|
/* direction to use for scrolling. The important one to support is
|
|
|
|
|
TTY_SCROLL_DOWN for when output overflows the display */
|
2023-04-12 20:17:11 +01:00
|
|
|
enum tty_scroll_dir {
|
2023-02-09 09:17:04 +00:00
|
|
|
TTY_SCROLL_DOWN,
|
|
|
|
|
TTY_SCROLL_UP,
|
2023-04-12 20:17:11 +01:00
|
|
|
};
|
2023-02-09 09:17:04 +00:00
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct tty_driver {
|
2023-05-14 21:11:32 +01:00
|
|
|
struct object tty_base;
|
|
|
|
|
|
2023-02-09 09:17:04 +00:00
|
|
|
char tty_name[16];
|
2023-04-12 20:17:11 +01:00
|
|
|
enum tty_driver_type tty_type;
|
|
|
|
|
struct queue_entry tty_list;
|
2023-02-09 09:17:04 +00:00
|
|
|
|
|
|
|
|
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);
|
2023-04-12 20:17:11 +01:00
|
|
|
void (*tty_set_cursor)(tty_driver_ctx_t ctx, enum tty_cursor cur);
|
2023-02-09 09:17:04 +00:00
|
|
|
void (*tty_move_cursor)(tty_driver_ctx_t ctx, int x, int y);
|
2023-04-12 20:17:11 +01:00
|
|
|
void (*tty_scroll)(tty_driver_ctx_t ctx, enum tty_scroll_dir dir, int lines);
|
|
|
|
|
};
|
2023-02-09 09:17:04 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct tty {
|
2023-02-09 09:17:04 +00:00
|
|
|
int tty_xcur, tty_ycur;
|
|
|
|
|
unsigned int tty_iflag, tty_oflag, tty_lflag;
|
|
|
|
|
|
|
|
|
|
tty_driver_ctx_t tty_dctx;
|
2023-04-12 20:17:11 +01:00
|
|
|
const struct tty_driver *tty_driver;
|
|
|
|
|
};
|
2023-02-09 09:17:04 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
extern kern_status_t tty_driver_register(struct tty_driver *drv);
|
|
|
|
|
extern kern_status_t tty_driver_unregister(struct tty_driver *drv);
|
2023-02-09 09:17:04 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
extern struct tty *tty_create(void);
|
|
|
|
|
extern void tty_destroy(struct tty *tty);
|
2023-02-09 09:17:04 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
extern int tty_read(struct tty *tty, char *s, unsigned long len);
|
|
|
|
|
extern int tty_write(struct tty *tty, const char *s, unsigned long len);
|
2023-02-09 09:17:04 +00:00
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-09 09:17:04 +00:00
|
|
|
#endif
|