����14-28 linux/include/linux/tty.h
1 /*
2 * 'tty.h' defines some structures used by tty_io.c and some defines.
3 *
4 * NOTE! Don't touch this without checking that nothing in rs_io.s or
5 * con_io.s breaks. Some constants are hardwired into the system (mainly
6 * offsets into 'tty_queue'
7 */
/*
* 'tty.h'�ж�����tty_io.c����ʹ�õ�ijЩ�ṹ������һЩ���塣
*
* ע�⣡��������Ķ���ʱ��һ��Ҫ���rs_io.s��con_io.s�����в���������⡣
* ��ϵͳ����Щ������ֱ��д�ڳ����еģ���Ҫ��һЩtty_queue�е�ƫ��ֵ����
*/
8
9 #ifndef _TTY_H
10 #define _TTY_H
11
12 #define MAX_CONSOLES 8 // ����������̨������
13 #define NR_SERIALS 2 // �����ն�������
14 #define NR_PTYS 4 // α�ն�������
15
16 extern int NR_CONSOLES; // �������̨������
17
18 #include <termios.h> // �ն������������ͷ�ļ�����Ҫ��������첽ͨ�ſڵ��ն˽ӿڡ�
19
20 #define TTY_BUF_SIZE 1024 // tty�������������������
21
// tty�ַ�����������ݽṹ������tty_struc�ṹ�еĶ���д�������淶��������С�
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
// ���¶�����tty�ȴ������л����������꺯������tail��ǰ��head�ںμ�tty_io.c��ͼ����
// a������ָ��ǰ��1�ֽڣ����ѳ����������Ҳ࣬��ָ��ѭ����
37 #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
// a������ָ�����1�ֽڣ���ѭ����
38 #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
// ���ָ�����еĻ�������
39 #define EMPTY(a) ((a)->head == (a)->tail)
// ���������ɴ���ַ��ij��ȣ����������ȣ���
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)])
// �������������Ϊ1�Ļ�����
42 #define FULL(a) (!LEFT(a))
// ���������Ѵ���ַ��ij��ȣ��ַ�������
43 #define CHARS(a) (((a)->head-(a)->tail)&(TTY_BUF_SIZE-1))
// ��queue�����������ȡһ�ַ�(��tail��������tail+=1)��
44 #define GETCH(queue,c) \
45 (void)({c=(queue)->buf[(queue)->tail];INC((queue)->tail);})
// ��queue����������з���һ�ַ�����head��������head+=1����
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]) // �жϷ������ж��ź�SIGINT��
50 #define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT]) // �˳��������˳��ź�SIGQUIT��
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]) // ��������������ź�SIGTSTP��
57
// tty���ݽṹ��
58 struct tty_struct {
59 struct termios termios; // �ն�io���ԺͿ����ַ����ݽṹ��
60 int pgrp; // ���������顣
61 int session; // �Ự�š�
62 int stopped; // ֹͣ��־��
63 void (*write)(struct tty_struct * tty); // ttyд����ָ�롣
64 struct tty_queue *read_q; // tty������
65 struct tty_queue *write_q; // tty���
66 struct tty_queue *secondary; // tty��������(��Ź淶ģʽ�ַ�����)��
67 }; // �ɳ�Ϊ�淶(��)ģʽ���С�
68
69 extern struct tty_struct tty_table[]; // tty�ṹ���顣
70 extern int fg_console; // ǰ̨����̨�š�
71
// �����ն�������tty_table[] ��ȡ��Ӧ�ն˺�nr��tty �ṹָ�롣��73�к�벿������
// �������豸��dev��tty_table[]����ѡ���Ӧ��tty�ṹ�����dev = 0����ʾ����ʹ��
// ǰ̨�նˣ����ֱ��ʹ���ն˺�fg_console ��Ϊ tty_table[] ������ȡ tty�ṹ�����
// dev����0����ô��Ҫ������������ǣ��� dev �������ն˺ţ��� dev �Ǵ����ն˺Ż���
// α�ն˺š����������ն���tty�ṹ�� tty_table[]���������� dev-1��0 -- 63��������
// ���������նˣ������ǵ� tty�ṹ��������� dev�����磬���dev = 64����ʾ��һ����
// ���ն�1������tty �ṹ���� ttb_table[dev]�� ���dev = 1�����Ӧ�ն˵�tty�ṹ��
// tty_table[0]���μ�tty_io.c�����70 -- 73�С�
72 #define TTY_TABLE(nr) \
73 (tty_table + ((nr) ? (((nr) < 64)? (nr)-1:(nr)) : fg_console))
74
// ����������ն�termios�ṹ�пɸ��ĵ������ַ�����c_cc[]�ij�ʼֵ����termios�ṹ
// ������include/termios.h�С�POSIX.1������11�������ַ�������Linuxϵͳ�����ⶨ
// ����SVR4ʹ�õ�6�������ַ������������_POSIX_VDISABLE��\0������ô��ijһ��ֵ��
// ��_POSIX_VDISABLE��ֵʱ����ʾ��ֹʹ����Ӧ�������ַ���[8����ֵ]
75 /* intr=^C quit=^| erase=del kill=^U
76 eof=^D vtime=\0 vmin=\1 sxtc=\0
77 start=^Q stop=^S susp=^Z eol=\0
78 reprint=^R discard=^U werase=^W lnext=^V
79 eol2=\0
80 */
/* �ж�intr=^C �˳�quit=^| ɾ��erase=del ��ֹkill=^U
* �����eof=^D vtime=\0 vmin=\1 sxtc=\0
* ��ʼstart=^Q ֹͣstop=^S ����susp=^Z �н���eol=\0
* ����reprint=^R ����discard=^U werase=^W lnext=^V
* ���eol2=\0
*/
81 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
82
83 void rs_init(void); // �첽����ͨ�ų�ʼ����(kernel/chr_drv/serial.c)
84 void con_init(void); // �����ն˳�ʼ���� (kernel/chr_drv/console.c)
85 void tty_init(void); // tty��ʼ���� (kernel/chr_drv/tty_io.c)
86
87 int tty_read(unsigned c, char * buf, int n); // (kernel/chr_drv/tty_io.c)
88 int tty_write(unsigned c, char * buf, int n); // (kernel/chr_drv/tty_io.c)
89
90 void con_write(struct tty_struct * tty); // (kernel/chr_drv/console.c)
91 void rs_write(struct tty_struct * tty); // (kernel/chr_drv/serial.c)
92 void mpty_write(struct tty_struct * tty); // (kernel/chr_drv/pty.c)
93 void spty_write(struct tty_struct * tty); // (kernel/chr_drv/pty.c)
94
95 void copy_to_cooked(struct tty_struct * tty); // (kernel/chr_drv/tty_io.c)
96
97 void update_screen(void); // (kernel/chr_drv/console.c)
98
99 #endif
100