kernel: implement tty driver system
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
#define SOCKS_TTY_H_
|
||||
|
||||
#include <socks/status.h>
|
||||
#include <socks/device.h>
|
||||
#include <socks/queue.h>
|
||||
#include <socks/object.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct kext;
|
||||
|
||||
/* The TTY system.
|
||||
|
||||
TTYs are an enhanced version of the console object. Rather than a simple output
|
||||
@@ -25,9 +28,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* opaque context pointer for use by the tty driver */
|
||||
typedef void *tty_driver_ctx_t;
|
||||
|
||||
enum tty_driver_type {
|
||||
/* For TTYs operating on simple IO devices like serial ports.
|
||||
Allows writing characters, receiving characters, and not much else. */
|
||||
@@ -58,38 +58,45 @@ enum tty_scroll_dir {
|
||||
support, depending on what the driver supports. */
|
||||
typedef uint64_t tty_attrib_t;
|
||||
|
||||
struct tty_driver_ops {
|
||||
void (*tty_init)(struct device *dev);
|
||||
void (*tty_deinit)(struct device *dev);
|
||||
void (*tty_clear)(struct device *dev, int x, int y, int width, int height);
|
||||
void (*tty_putc)(struct device *dev, int c, int xpos, int ypos, tty_attrib_t attrib);
|
||||
void (*tty_set_cursor)(struct device *dev, enum tty_cursor cur);
|
||||
void (*tty_move_cursor)(struct device *dev, int x, int y);
|
||||
void (*tty_scroll)(struct device *dev, enum tty_scroll_dir dir, int lines);
|
||||
};
|
||||
|
||||
struct tty_driver {
|
||||
struct object tty_base;
|
||||
struct driver tty_base;
|
||||
|
||||
char tty_name[16];
|
||||
enum tty_driver_type tty_type;
|
||||
struct queue_entry tty_list;
|
||||
struct queue_entry tty_head;
|
||||
|
||||
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, enum tty_cursor cur);
|
||||
void (*tty_move_cursor)(tty_driver_ctx_t ctx, int x, int y);
|
||||
void (*tty_scroll)(tty_driver_ctx_t ctx, enum tty_scroll_dir dir, int lines);
|
||||
struct tty_driver_ops *tty_ops;
|
||||
};
|
||||
|
||||
struct tty {
|
||||
int tty_xcur, tty_ycur;
|
||||
struct tty_device {
|
||||
unsigned int tty_xcells, tty_ycells;
|
||||
unsigned int tty_xcur, tty_ycur;
|
||||
unsigned int tty_iflag, tty_oflag, tty_lflag;
|
||||
|
||||
tty_driver_ctx_t tty_dctx;
|
||||
const struct tty_driver *tty_driver;
|
||||
};
|
||||
|
||||
extern kern_status_t tty_init(void);
|
||||
|
||||
extern struct device *tty_device_create(void);
|
||||
extern kern_status_t tty_device_register(struct device *dev, struct tty_driver *owner, struct device *parent);
|
||||
|
||||
extern struct tty_driver *tty_driver_create(struct kext *self, const char *name);
|
||||
extern kern_status_t tty_driver_destroy(struct tty_driver *drv);
|
||||
extern kern_status_t tty_driver_register(struct tty_driver *drv);
|
||||
extern kern_status_t tty_driver_unregister(struct tty_driver *drv);
|
||||
|
||||
extern struct tty *tty_create(void);
|
||||
extern void tty_destroy(struct tty *tty);
|
||||
|
||||
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);
|
||||
static inline struct driver *tty_driver_base(struct tty_driver *drv)
|
||||
{
|
||||
return &drv->tty_base;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user