1 /* tty.h - Terminals */
3 #include <minix/chardriver.h>
4 #include <minix/timers.h>
6 /* First minor numbers for the various classes of TTY devices. */
10 #define VIDEO_MINOR 125
11 #define TTYPX_MINOR 128
12 #define PTYPX_MINOR 192
14 #define CONS_ARG 30 /* console= boot param length (incl. nul) */
15 #define LINEWRAP 1 /* console.c - wrap lines at column 80 */
17 #define TTY_IN_BYTES 256 /* tty input queue size */
18 #define TAB_SIZE 8 /* distance between tab stops */
19 #define TAB_MASK 7 /* mask to compute a tab stop position */
21 #define ESC '\33' /* escape */
24 typedef int(*devfun_t
) (struct tty
*tp
, int try_only
);
25 typedef void(*devfunarg_t
) (struct tty
*tp
, int c
);
28 int tty_events
; /* set when TTY should inspect this line */
29 int tty_index
; /* index into TTY table */
30 devminor_t tty_minor
; /* device minor number */
32 /* Input queue. Typed characters are stored here until read by a program. */
33 u16_t
*tty_inhead
; /* pointer to place where next char goes */
34 u16_t
*tty_intail
; /* pointer to next char to be given to prog */
35 int tty_incount
; /* # chars in the input queue */
36 int tty_eotct
; /* number of "line breaks" in input queue */
37 devfun_t tty_devread
; /* routine to read from low level buffers */
38 devfun_t tty_icancel
; /* cancel any device input */
39 int tty_min
; /* minimum requested #chars in input queue */
40 minix_timer_t tty_tmr
; /* the timer for this tty */
43 devfun_t tty_devwrite
; /* routine to start actual device output */
44 devfunarg_t tty_echo
; /* routine to echo characters input */
45 devfun_t tty_ocancel
; /* cancel any ongoing device output */
46 devfun_t tty_break_on
; /* let the device assert a break */
47 devfun_t tty_break_off
; /* let the device de-assert a break */
49 /* Terminal parameters and status. */
50 int tty_position
; /* current position on the screen for echoing */
51 char tty_reprint
; /* 1 when echoed input messed up, else 0 */
52 char tty_escaped
; /* 1 when LNEXT (^V) just seen, else 0 */
53 char tty_inhibited
; /* 1 when STOP (^S) just seen (stops output) */
54 endpoint_t tty_pgrp
; /* endpoint of controlling process */
55 char tty_openct
; /* count of number of opens of this tty */
57 /* Information about incomplete I/O requests is stored here. */
58 endpoint_t tty_incaller
; /* process that made the call, or NONE */
59 cdev_id_t tty_inid
; /* ID of suspended read request */
60 cp_grant_id_t tty_ingrant
; /* grant where data is to go */
61 size_t tty_inleft
; /* how many chars are still needed */
62 size_t tty_incum
; /* # chars input so far */
63 endpoint_t tty_outcaller
; /* process that made the call, or NONE */
64 cdev_id_t tty_outid
; /* ID of suspended write request */
65 cp_grant_id_t tty_outgrant
; /* grant where data comes from */
66 size_t tty_outleft
; /* # chars yet to be output */
67 size_t tty_outcum
; /* # chars output so far */
68 endpoint_t tty_iocaller
; /* process that made the call, or NONE */
69 cdev_id_t tty_ioid
; /* ID of suspended ioctl request */
70 unsigned int tty_ioreq
; /* ioctl request code */
71 cp_grant_id_t tty_iogrant
; /* virtual address of ioctl buffer or grant */
74 unsigned int tty_select_ops
; /* which operations are interesting */
75 endpoint_t tty_select_proc
; /* which process wants notification */
76 devminor_t tty_select_minor
; /* minor used to start select query */
79 devfun_t tty_ioctl
; /* set line speed, etc. at the device level */
80 devfun_t tty_open
; /* tell the device that the tty is opened */
81 devfun_t tty_close
; /* tell the device that the tty is closed */
82 void *tty_priv
; /* pointer to per device private data */
83 struct termios tty_termios
; /* terminal attributes */
84 struct winsize tty_winsize
; /* window size (#lines and #columns) */
86 u16_t tty_inbuf
[TTY_IN_BYTES
];/* tty input buffer */
90 /* Memory allocated in tty.c, so extern here. */
91 extern tty_t tty_table
[NR_CONS
+NR_RS_LINES
+NR_PTYS
];
92 extern int ccurrent
; /* currently visible console */
93 extern u32_t system_hz
; /* system clock frequency */
95 extern unsigned long kbd_irq_set
;
96 extern unsigned long rs_irq_set
;
98 /* Values for the fields. */
99 #define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */
100 #define ESCAPED 1 /* previous character was LNEXT (^V) */
101 #define RUNNING 0 /* no STOP (^S) has been typed to stop output */
102 #define STOPPED 1 /* STOP (^S) has been typed to stop output */
104 /* Fields and flags on characters in the input queue. */
105 #define IN_CHAR 0x00FF /* low 8 bits are the character itself */
106 #define IN_LEN 0x0F00 /* length of char if it has been echoed */
107 #define IN_LSHIFT 8 /* length = (c & IN_LEN) >> IN_LSHIFT */
108 #define IN_EOT 0x1000 /* char is a line break (^D, LF) */
109 #define IN_EOF 0x2000 /* char is EOF (^D), do not return to user */
110 #define IN_ESC 0x4000 /* escaped by LNEXT (^V), no interpretation */
112 /* Times and timeouts. */
113 #define force_timeout() ((void) (0))
115 /* Number of elements and limit of a buffer. */
116 #define buflen(buf) (sizeof(buf) / sizeof((buf)[0]))
117 #define bufend(buf) ((buf) + buflen(buf))
119 /* Memory allocated in tty.c, so extern here. */
120 extern struct machine machine
; /* machine information (a.o.: pc_at, ega) */
122 /* The tty outputs diagnostic messages in a circular buffer. */
123 extern struct kmessages kmess
;
125 /* Function prototypes for TTY driver. */
127 void handle_events(struct tty
*tp
);
128 void sigchar(struct tty
*tp
, int sig
, int mayflush
);
130 tty_t
*line2tty(devminor_t minor
);
131 int in_process(struct tty
*tp
, char *buf
, int count
);
132 void out_process(struct tty
*tp
, char *bstart
, char *bpos
, char *bend
,
133 int *icount
, int *ocount
);
134 void tty_wakeup(clock_t now
);
135 int select_try(struct tty
*tp
, int ops
);
136 int select_retry(struct tty
*tp
);
139 void rs_init(struct tty
*tp
);
140 void rs_interrupt(message
*m
);
144 void cons_stop(void);
145 void scr_init(struct tty
*tp
);
146 void toggle_scroll(void);
147 int con_loadfont(endpoint_t endpt
, cp_grant_id_t grant
);
148 void select_console(int cons_line
);
149 void beep_x( unsigned freq
, clock_t dur
);
150 void do_video(message
*m
, int ipc_status
);
153 void kb_init(struct tty
*tp
);
154 void kb_init_once(void);
155 int kbd_loadmap(endpoint_t endpt
, cp_grant_id_t grant
);
156 void do_fkey_ctl(message
*m
);
157 void do_input(message
*m
);
160 void do_pty(message
*m_ptr
, int ipc_status
);
161 void pty_init(struct tty
*tp
);
162 void select_retry_pty(struct tty
*tp
);