feat: a better boot command line parser
[lunaix-os.git] / lunaix-os / includes / hal / term.h
1 #ifndef __LUNAIX_TERM_H
2 #define __LUNAIX_TERM_H
3
4 #include <lunaix/device.h>
5 #include <lunaix/ds/rbuffer.h>
6 #include <lunaix/signal_defs.h>
7
8 #include <usr/lunaix/term.h>
9
10 struct term;
11
12 struct linebuffer
13 {
14     struct rbuffer* next;
15     struct rbuffer* current;
16     short sflags;
17     short sz_hlf;
18 };
19 #define LSTATE_EOL (1)
20 #define LSTATE_EOF (1 << 1)
21 #define LSTATE_SIGRAISE (1 << 2)
22
23 typedef struct rbuffer** lbuf_ref_t;
24 #define ref_current(lbuf) (&(lbuf)->current)
25 #define ref_next(lbuf) (&(lbuf)->next)
26 #define deref(bref) (*(bref))
27
28 struct term_lcntl
29 {
30     struct term* term;
31     int (*process_and_put)(struct term*, struct linebuffer*, char);
32 };
33
34 struct term
35 {
36     struct device* dev;
37     struct device* chdev;
38     struct term_lcntl* lcntl;
39     struct linebuffer line_out;
40     struct linebuffer line_in;
41     pid_t fggrp;
42
43     struct
44     {
45         int (*set_speed)(struct device*, speed_t);
46     } chdev_ops;
47
48     /* -- POSIX.1-2008 compliant fields -- */
49     tcflag_t iflags;
50     tcflag_t oflags;
51     tcflag_t lflags;
52     cc_t cc[_NCCS];
53     speed_t iospeed;
54 };
55
56 struct term*
57 term_create(struct device* chardev, char* suffix);
58
59 int
60 term_bind(struct term* tdev, struct device* chdev);
61
62 int
63 term_push_lcntl(struct term* tdev, struct term_lcntl* lcntl);
64
65 int
66 term_pop_lcntl(struct term* tdev);
67
68 struct term_lcntl*
69 term_get_lcntl(u32_t lcntl_index);
70
71 static inline void
72 line_flip(struct linebuffer* lbf)
73 {
74     struct rbuffer* tmp = lbf->current;
75     lbf->current = lbf->next;
76     lbf->next = tmp;
77 }
78
79 void
80 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
81
82 void
83 line_free(struct linebuffer* lbf, size_t sz_hlf);
84
85 void
86 term_sendsig(struct term* tdev, int signal);
87
88 int
89 term_flush(struct term* tdev);
90
91 int
92 term_read(struct term* tdev);
93
94 int
95 lcntl_transform_inseq(struct term* tdev);
96
97 int
98 lcntl_transform_outseq(struct term* tdev);
99
100 #endif /* __LUNAIX_TERM_H */