1 /* tty.h - Terminals */
8 #define TTY_REVIVE 6767
10 /* First minor numbers for the various classes of TTY devices. */
13 #define RS232_MINOR 16
15 #define KBDAUX_MINOR 126
16 #define VIDEO_MINOR 125
17 #define TTYPX_MINOR 128
18 #define PTYPX_MINOR 192
20 #define LINEWRAP 1 /* console.c - wrap lines at column 80 */
22 #define TTY_IN_BYTES 256 /* tty input queue size */
23 #define TAB_SIZE 8 /* distance between tab stops */
24 #define TAB_MASK 7 /* mask to compute a tab stop position */
26 #define ESC '\33' /* escape */
28 #define O_NOCTTY 00400 /* from <fcntl.h>, or cc will choke */
29 #define O_NONBLOCK 04000
32 typedef _PROTOTYPE( int (*devfun_t
), (struct tty
*tp
, int try_only
) );
33 typedef _PROTOTYPE( void (*devfunarg_t
), (struct tty
*tp
, int c
) );
36 int tty_events
; /* set when TTY should inspect this line */
37 int tty_index
; /* index into TTY table */
38 int tty_minor
; /* device minor number */
40 /* Input queue. Typed characters are stored here until read by a program. */
41 u16_t
*tty_inhead
; /* pointer to place where next char goes */
42 u16_t
*tty_intail
; /* pointer to next char to be given to prog */
43 int tty_incount
; /* # chars in the input queue */
44 int tty_eotct
; /* number of "line breaks" in input queue */
45 devfun_t tty_devread
; /* routine to read from low level buffers */
46 devfun_t tty_icancel
; /* cancel any device input */
47 int tty_min
; /* minimum requested #chars in input queue */
48 timer_t tty_tmr
; /* the timer for this tty */
51 devfun_t tty_devwrite
; /* routine to start actual device output */
52 devfunarg_t tty_echo
; /* routine to echo characters input */
53 devfun_t tty_ocancel
; /* cancel any ongoing device output */
54 devfun_t tty_break
; /* let the device send a break */
56 /* Terminal parameters and status. */
57 int tty_position
; /* current position on the screen for echoing */
58 char tty_reprint
; /* 1 when echoed input messed up, else 0 */
59 char tty_escaped
; /* 1 when LNEXT (^V) just seen, else 0 */
60 char tty_inhibited
; /* 1 when STOP (^S) just seen (stops output) */
61 int tty_pgrp
; /* slot number of controlling process */
62 char tty_openct
; /* count of number of opens of this tty */
64 /* Information about incomplete I/O requests is stored here. */
65 int tty_inrepcode
; /* reply code, TASK_REPLY or REVIVE */
66 char tty_inrevived
; /* set to 1 if revive callback is pending */
67 int tty_incaller
; /* process that made the call (usually FS) */
68 int tty_inproc
; /* process that wants to read from tty */
69 vir_bytes tty_in_vir_g
; /* address or grant where data is to go */
70 vir_bytes tty_in_vir_offset
; /* offset into grant */
71 int tty_in_safe
; /* nonzero: safecopies (in_vir is grantid) */
72 int tty_inleft
; /* how many chars are still needed */
73 int tty_incum
; /* # chars input so far */
74 int tty_outrepcode
; /* reply code, TASK_REPLY or REVIVE */
75 int tty_outrevived
; /* set to 1 if revive callback is pending */
76 int tty_outcaller
; /* process that made the call (usually FS) */
77 int tty_outproc
; /* process that wants to write to tty */
78 vir_bytes tty_out_vir_g
; /* address or grant where data comes from */
79 vir_bytes tty_out_vir_offset
; /* offset into grant */
80 int tty_out_safe
; /* nonzero: safecopies (out_vir is grantid) */
81 int tty_outleft
; /* # chars yet to be output */
82 int tty_outcum
; /* # chars output so far */
83 int tty_iocaller
; /* process that made the call (usually FS) */
84 int tty_iorevived
; /* set to 1 if revive callback is pending */
85 int tty_ioproc
; /* process that wants to do an ioctl */
86 int tty_iostatus
; /* result */
87 int tty_ioreq
; /* ioctl request code */
88 int tty_io_safe
; /* safe copy mode? (iovir is grant id) */
89 vir_bytes tty_iovir_g
; /* virtual address of ioctl buffer or grant */
92 int tty_select_ops
; /* which operations are interesting */
93 int tty_select_proc
; /* which process wants notification */
96 devfun_t tty_ioctl
; /* set line speed, etc. at the device level */
97 devfun_t tty_close
; /* tell the device that the tty is closed */
98 void *tty_priv
; /* pointer to per device private data */
99 struct termios tty_termios
; /* terminal attributes */
100 struct winsize tty_winsize
; /* window size (#lines and #columns) */
102 u16_t tty_inbuf
[TTY_IN_BYTES
];/* tty input buffer */
106 /* Memory allocated in tty.c, so extern here. */
107 extern tty_t tty_table
[NR_CONS
+NR_RS_LINES
+NR_PTYS
];
108 extern int ccurrent
; /* currently visible console */
109 extern u32_t system_hz
; /* system clock frequency */
111 extern unsigned long kbd_irq_set
;
112 extern unsigned long rs_irq_set
;
114 /* Values for the fields. */
115 #define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */
116 #define ESCAPED 1 /* previous character was LNEXT (^V) */
117 #define RUNNING 0 /* no STOP (^S) has been typed to stop output */
118 #define STOPPED 1 /* STOP (^S) has been typed to stop output */
120 /* Fields and flags on characters in the input queue. */
121 #define IN_CHAR 0x00FF /* low 8 bits are the character itself */
122 #define IN_LEN 0x0F00 /* length of char if it has been echoed */
123 #define IN_LSHIFT 8 /* length = (c & IN_LEN) >> IN_LSHIFT */
124 #define IN_EOT 0x1000 /* char is a line break (^D, LF) */
125 #define IN_EOF 0x2000 /* char is EOF (^D), do not return to user */
126 #define IN_ESC 0x4000 /* escaped by LNEXT (^V), no interpretation */
128 /* Times and timeouts. */
129 #define force_timeout() ((void) (0))
131 /* Memory allocated in tty.c, so extern here. */
132 extern timer_t
*tty_timers
; /* queue of TTY timers */
133 extern clock_t tty_next_timeout
; /* next TTY timeout */
135 /* Number of elements and limit of a buffer. */
136 #define buflen(buf) (sizeof(buf) / sizeof((buf)[0]))
137 #define bufend(buf) ((buf) + buflen(buf))
139 /* Memory allocated in tty.c, so extern here. */
140 extern struct machine machine
; /* machine information (a.o.: pc_at, ega) */
142 /* The tty outputs diagnostic messages in a circular buffer. */
143 extern struct kmessages kmess
;
145 /* Function prototypes for TTY driver. */
147 _PROTOTYPE( void handle_events
, (struct tty
*tp
) );
148 _PROTOTYPE( void sigchar
, (struct tty
*tp
, int sig
, int mayflush
) );
149 _PROTOTYPE( void tty_task
, (void) );
150 _PROTOTYPE( int in_process
, (struct tty
*tp
, char *buf
, int count
) );
151 _PROTOTYPE( void out_process
, (struct tty
*tp
, char *bstart
, char *bpos
,
152 char *bend
, int *icount
, int *ocount
) );
153 _PROTOTYPE( void tty_wakeup
, (clock_t now
) );
154 #define tty_reply(c, r, p, s) tty_reply_f(__FILE__, __LINE__, (c), (r), (p), (s))
155 _PROTOTYPE( void tty_reply_f
, (char *f
, int l
, int code
, int replyee
, int proc_nr
,
157 _PROTOTYPE( int select_try
, (struct tty
*tp
, int ops
) );
158 _PROTOTYPE( int select_retry
, (struct tty
*tp
) );
161 _PROTOTYPE( void rs_init
, (struct tty
*tp
) );
162 _PROTOTYPE( void rs_interrupt
, (message
*m
) );
166 _PROTOTYPE( void kputc
, (int c
) );
167 _PROTOTYPE( void cons_stop
, (void) );
168 _PROTOTYPE( void do_new_kmess
, (message
*m
) );
169 _PROTOTYPE( void do_diagnostics
, (message
*m
, int safe
) );
170 _PROTOTYPE( void do_get_kmess
, (message
*m
) );
171 _PROTOTYPE( void do_get_kmess_s
, (message
*m
) );
172 _PROTOTYPE( void scr_init
, (struct tty
*tp
) );
173 _PROTOTYPE( void toggle_scroll
, (void) );
174 _PROTOTYPE( int con_loadfont
, (message
*m
) );
175 _PROTOTYPE( void select_console
, (int cons_line
) );
176 _PROTOTYPE( void beep_x
, ( unsigned freq
, clock_t dur
) );
177 _PROTOTYPE( void do_video
, (message
*m
) );
180 _PROTOTYPE( void kb_init
, (struct tty
*tp
) );
181 _PROTOTYPE( void kb_init_once
, (void) );
182 _PROTOTYPE( int kbd_loadmap
, (message
*m
, int safe
) );
183 _PROTOTYPE( void do_fkey_ctl
, (message
*m
) );
184 _PROTOTYPE( void kbd_interrupt
, (message
*m
) );
185 _PROTOTYPE( void do_kbd
, (message
*m
) );
186 _PROTOTYPE( void do_kbdaux
, (message
*m
) );
187 _PROTOTYPE( int kbd_status
, (message
*m_ptr
) );
190 _PROTOTYPE( void do_pty
, (struct tty
*tp
, message
*m_ptr
) );
191 _PROTOTYPE( void pty_init
, (struct tty
*tp
) );
192 _PROTOTYPE( void select_retry_pty
, (struct tty
*tp
) );
193 _PROTOTYPE( int pty_status
, (message
*m_ptr
) );
195 #endif /* (CHIP == INTEL) */