1
2
3
4
5
6
7
8
9 #ifndef _TTY_H
10 #define _TTY_H
11
12 #define MAX_CONSOLES 8
13 #define NR_SERIALS 4
14 #define NR_PTYS 4
15
16 extern int NR_CONSOLES;
17
18 #include <termios.h>
19
20 #define TTY_BUF_SIZE 2048
21
22 struct tty_queue {
23 unsigned long data;
24 unsigned long head;
25 unsigned long tail;
26 struct task_struct * proc_list;
27 char buf[TTY_BUF_SIZE];
28 };
29
30 #define IS_A_CONSOLE(min) (((min) & 0xC0) == 0x00)
31 #define IS_A_SERIAL(min) (((min) & 0xC0) == 0x40)
32 #define IS_A_PTY(min) ((min) & 0x80)
33 #define IS_A_PTY_MASTER(min) (((min) & 0xC0) == 0x80)
34 #define IS_A_PTY_SLAVE(min) (((min) & 0xC0) == 0xC0)
35 #define PTY_OTHER(min) ((min) ^ 0x40)
36
37 #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
38 #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
39 #define EMPTY(a) ((a)->head == (a)->tail)
40 #define LEFT(a) (((a)->tail-(a)->head-1)&(TTY_BUF_SIZE-1))
41 #define LAST(a) ((a)->buf[(TTY_BUF_SIZE-1)&((a)->head-1)])
42 #define FULL(a) (!LEFT(a))
43 #define CHARS(a) (((a)->head-(a)->tail)&(TTY_BUF_SIZE-1))
44 #define GETCH(queue,c) \
45 (void)({c=(queue)->buf[(queue)->tail];INC((queue)->tail);})
46 #define PUTCH(c,queue) \
47 (void)({(queue)->buf[(queue)->head]=(c);INC((queue)->head);})
48
49 #define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR])
50 #define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT])
51 #define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE])
52 #define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL])
53 #define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF])
54 #define START_CHAR(tty) ((tty)->termios.c_cc[VSTART])
55 #define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP])
56 #define SUSPEND_CHAR(tty) ((tty)->termios.c_cc[VSUSP])
57
58 struct tty_struct {
59 struct termios termios;
60 int pgrp;
61 int session;
62 int stopped;
63 int busy;
64 struct winsize winsize;
65 void (*write)(struct tty_struct * tty);
66 struct tty_queue *read_q;
67 struct tty_queue *write_q;
68 struct tty_queue *secondary;
69 };
70
71 #define TTY_WRITE(tty) \
72 do { \
73 cli(); \
74 if (!(tty)->busy) { \
75 (tty)->busy = 1; \
76 sti(); \
77 (tty)->write((tty)); \
78 (tty)->busy = 0; \
79 } else \
80 sti(); \
81 } while (0)
82
83 extern struct tty_struct tty_table[];
84 extern int fg_console;
85 extern unsigned long video_num_columns;
86 extern unsigned long video_num_lines;
87
88
89 #define TTY_TABLE(nr) \
90 (tty_table + ((nr) ? (((nr) < 64)? (nr)-1:(nr)) : fg_console))
91
92
93
94
95
96
97
98 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
99
100 void rs_init(void);
101 void con_init(void);
102 void tty_init(void);
103
104 int tty_read(unsigned c, char * buf, int n, unsigned short flags);
105 int tty_write(unsigned c, char * buf, int n);
106
107 void con_write(struct tty_struct * tty);
108 void rs_write(struct tty_struct * tty);
109 void mpty_write(struct tty_struct * tty);
110 void spty_write(struct tty_struct * tty);
111
112 extern void serial_open(unsigned int line);
113
114 void copy_to_cooked(struct tty_struct * tty);
115
116 void update_screen(int new_console);
117
118 #endif