1 /* tty.h - Terminals */ 2 3 #include <minix/chardriver.h> 4 #include <minix/timers.h> 5 6 /* First minor numbers for the various classes of TTY devices. */ 7 #define PTMX_MINOR 0 /* minor of the Unix98 clone device */ 8 #define TTYPX_MINOR 128 9 #define PTYPX_MINOR 192 10 /* UNIX98_MINOR is defined in minix/dmap.h */ 11 12 #define TTY_IN_BYTES 256 /* tty input queue size */ 13 #define TTY_OUT_BYTES 2048 /* tty output queue size */ 14 #define TAB_SIZE 8 /* distance between tab stops */ 15 #define TAB_MASK 7 /* mask to compute a tab stop position */ 16 17 #define ESC '\33' /* escape */ 18 19 struct tty; 20 typedef int (*devfun_t)(struct tty *tp, int try_only); 21 typedef void (*devfunarg_t)(struct tty *tp, int c); 22 typedef int (*devfunline_t)(struct tty *tp, devminor_t line); 23 24 typedef struct tty { 25 int tty_events; /* set when TTY should inspect this line */ 26 int tty_index; /* index into TTY table */ 27 28 /* Input queue. Typed characters are stored here until read by a program. */ 29 u16_t *tty_inhead; /* pointer to place where next char goes */ 30 u16_t *tty_intail; /* pointer to next char to be given to prog */ 31 int tty_incount; /* # chars in the input queue */ 32 int tty_eotct; /* number of "line breaks" in input queue */ 33 devfun_t tty_devread; /* routine to read from low level buffers */ 34 devfun_t tty_icancel; /* cancel any device input */ 35 int tty_min; /* minimum requested #chars in input queue */ 36 minix_timer_t tty_tmr; /* the timer for this tty */ 37 38 /* Output section. */ 39 devfun_t tty_devwrite; /* routine to start actual device output */ 40 devfunarg_t tty_echo; /* routine to echo characters input */ 41 devfun_t tty_ocancel; /* cancel any ongoing device output */ 42 devfun_t tty_break_on; /* let the device assert a break */ 43 devfun_t tty_break_off; /* let the device de-assert a break */ 44 45 /* Terminal parameters and status. */ 46 int tty_position; /* current position on the screen for echoing */ 47 char tty_reprint; /* 1 when echoed input messed up, else 0 */ 48 char tty_escaped; /* 1 when LNEXT (^V) just seen, else 0 */ 49 char tty_inhibited; /* 1 when STOP (^S) just seen (stops output) */ 50 endpoint_t tty_pgrp; /* endpoint of controlling process */ 51 char tty_openct; /* count of number of opens of this tty */ 52 53 /* Information about incomplete I/O requests is stored here. */ 54 endpoint_t tty_incaller; /* process that made the call, or NONE */ 55 cdev_id_t tty_inid; /* ID of suspended read request */ 56 cp_grant_id_t tty_ingrant; /* grant where data is to go */ 57 size_t tty_inleft; /* how many chars are still needed */ 58 size_t tty_incum; /* # chars input so far */ 59 endpoint_t tty_outcaller; /* process that made the call, or NONE */ 60 cdev_id_t tty_outid; /* ID of suspended write request */ 61 cp_grant_id_t tty_outgrant; /* grant where data comes from */ 62 size_t tty_outleft; /* # chars yet to be output */ 63 size_t tty_outcum; /* # chars output so far */ 64 endpoint_t tty_iocaller; /* process that made the call, or NONE */ 65 cdev_id_t tty_ioid; /* ID of suspended ioctl request */ 66 unsigned int tty_ioreq; /* ioctl request code */ 67 cp_grant_id_t tty_iogrant; /* virtual address of ioctl buffer or grant */ 68 69 /* select() data */ 70 unsigned int tty_select_ops; /* which operations are interesting */ 71 endpoint_t tty_select_proc; /* which process wants notification */ 72 devminor_t tty_select_minor; /* minor used to start select query */ 73 74 /* Miscellaneous. */ 75 devfunline_t tty_mayopen; /* check whether this tty may be opened */ 76 devfun_t tty_open; /* tell the device that the tty is opened */ 77 devfun_t tty_close; /* tell the device that the tty is closed */ 78 void *tty_priv; /* pointer to per device private data */ 79 struct termios tty_termios; /* terminal attributes */ 80 struct winsize tty_winsize; /* window size (#lines and #columns) */ 81 82 u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */ 83 84 } tty_t; 85 86 /* Memory allocated in tty.c, so extern here. */ 87 extern tty_t tty_table[NR_PTYS]; 88 extern u32_t system_hz; /* system clock frequency */ 89 extern int tty_gid; /* group ID of the "tty" group */ 90 91 /* Values for the fields. */ 92 #define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */ 93 #define ESCAPED 1 /* previous character was LNEXT (^V) */ 94 #define RUNNING 0 /* no STOP (^S) has been typed to stop output */ 95 #define STOPPED 1 /* STOP (^S) has been typed to stop output */ 96 97 /* Fields and flags on characters in the input queue. */ 98 #define IN_CHAR 0x00FF /* low 8 bits are the character itself */ 99 #define IN_LEN 0x0F00 /* length of char if it has been echoed */ 100 #define IN_LSHIFT 8 /* length = (c & IN_LEN) >> IN_LSHIFT */ 101 #define IN_EOT 0x1000 /* char is a line break (^D, LF) */ 102 #define IN_EOF 0x2000 /* char is EOF (^D), do not return to user */ 103 #define IN_ESC 0x4000 /* escaped by LNEXT (^V), no interpretation */ 104 105 /* Number of elements and limit of a buffer. */ 106 #define buflen(buf) (sizeof(buf) / sizeof((buf)[0])) 107 #define bufend(buf) ((buf) + buflen(buf)) 108 109 /* Function prototypes for TTY driver. */ 110 /* tty.c */ 111 void handle_events(struct tty *tp); 112 void sigchar(struct tty *tp, int sig, int mayflush); 113 void tty_task(void); 114 tty_t *line2tty(devminor_t minor); 115 int in_process(struct tty *tp, char *buf, int count); 116 void out_process(struct tty *tp, char *bstart, char *bpos, char *bend, 117 int *icount, int *ocount); 118 void tty_wakeup(clock_t now); 119 int select_try(struct tty *tp, int ops); 120 int select_retry(struct tty *tp); 121 int tty_ioctl(devminor_t minor, unsigned long request, endpoint_t endpt, 122 cp_grant_id_t grant, int flags, endpoint_t user_endpt, cdev_id_t id); 123 124 /* pty.c */ 125 void do_pty(message *m_ptr, int ipc_status); 126 void pty_init(struct tty *tp); 127 void select_retry_pty(struct tty *tp); 128