2005-04-21 16:53:53 +02:00
|
|
|
/* tty.h - Terminals */
|
|
|
|
|
2013-09-11 12:48:10 +02:00
|
|
|
#include <minix/chardriver.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <timers.h>
|
2005-09-30 15:01:34 +02:00
|
|
|
|
|
|
|
#undef lock
|
|
|
|
#undef unlock
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-08-05 15:50:58 +02:00
|
|
|
/* First minor numbers for the various classes of TTY devices. */
|
2005-09-11 19:09:11 +02:00
|
|
|
#define CONS_MINOR 0
|
|
|
|
#define LOG_MINOR 15
|
|
|
|
#define RS232_MINOR 16
|
2005-11-09 16:45:48 +01:00
|
|
|
#define KBD_MINOR 127
|
|
|
|
#define KBDAUX_MINOR 126
|
|
|
|
#define VIDEO_MINOR 125
|
2005-09-11 19:09:11 +02:00
|
|
|
#define TTYPX_MINOR 128
|
|
|
|
#define PTYPX_MINOR 192
|
2005-08-05 15:50:58 +02:00
|
|
|
|
TTY: seperate hardware dependent parts + add new serial driver
.Split TTY in order to support both x86 and ARM.
.Add support for the TI 16750 UARTs on OMAP35x.
.Various other improvements:
.Kernel messages are printed using generic terminal write
functions. That is, they are no longer directly displayed
on the console.
.The console can now be displayed on any terminal. This
is configured by the "console={tty00,tty01,ttyc2,ttyc3,ttyc4}"
boot variable -- basically any valid /dev/tty* terminal.
.Cutify kernel messages with colors. Configured by
"kernelclr={1,2,3,4,5,6,7}" boot variable.
2012-10-17 16:07:53 +02:00
|
|
|
#define CONS_ARG 30 /* console= boot param length (incl. nul) */
|
2005-08-03 13:53:36 +02:00
|
|
|
#define LINEWRAP 1 /* console.c - wrap lines at column 80 */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
#define TTY_IN_BYTES 256 /* tty input queue size */
|
|
|
|
#define TAB_SIZE 8 /* distance between tab stops */
|
|
|
|
#define TAB_MASK 7 /* mask to compute a tab stop position */
|
|
|
|
|
|
|
|
#define ESC '\33' /* escape */
|
|
|
|
|
|
|
|
#define O_NOCTTY 00400 /* from <fcntl.h>, or cc will choke */
|
|
|
|
#define O_NONBLOCK 04000
|
|
|
|
|
|
|
|
struct tty;
|
2012-03-24 16:16:34 +01:00
|
|
|
typedef int(*devfun_t) (struct tty *tp, int try_only);
|
|
|
|
typedef void(*devfunarg_t) (struct tty *tp, int c);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
typedef struct tty {
|
|
|
|
int tty_events; /* set when TTY should inspect this line */
|
|
|
|
int tty_index; /* index into TTY table */
|
2013-09-11 12:48:10 +02:00
|
|
|
devminor_t tty_minor; /* device minor number */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Input queue. Typed characters are stored here until read by a program. */
|
|
|
|
u16_t *tty_inhead; /* pointer to place where next char goes */
|
|
|
|
u16_t *tty_intail; /* pointer to next char to be given to prog */
|
|
|
|
int tty_incount; /* # chars in the input queue */
|
|
|
|
int tty_eotct; /* number of "line breaks" in input queue */
|
|
|
|
devfun_t tty_devread; /* routine to read from low level buffers */
|
|
|
|
devfun_t tty_icancel; /* cancel any device input */
|
|
|
|
int tty_min; /* minimum requested #chars in input queue */
|
|
|
|
timer_t tty_tmr; /* the timer for this tty */
|
|
|
|
|
|
|
|
/* Output section. */
|
|
|
|
devfun_t tty_devwrite; /* routine to start actual device output */
|
|
|
|
devfunarg_t tty_echo; /* routine to echo characters input */
|
|
|
|
devfun_t tty_ocancel; /* cancel any ongoing device output */
|
|
|
|
devfun_t tty_break; /* let the device send a break */
|
|
|
|
|
|
|
|
/* Terminal parameters and status. */
|
|
|
|
int tty_position; /* current position on the screen for echoing */
|
|
|
|
char tty_reprint; /* 1 when echoed input messed up, else 0 */
|
|
|
|
char tty_escaped; /* 1 when LNEXT (^V) just seen, else 0 */
|
|
|
|
char tty_inhibited; /* 1 when STOP (^S) just seen (stops output) */
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
endpoint_t tty_pgrp; /* endpoint of controlling process */
|
2005-04-21 16:53:53 +02:00
|
|
|
char tty_openct; /* count of number of opens of this tty */
|
|
|
|
|
|
|
|
/* Information about incomplete I/O requests is stored here. */
|
2013-09-11 12:48:10 +02:00
|
|
|
endpoint_t tty_incaller; /* process that made the call, or NONE */
|
|
|
|
cdev_id_t tty_inid; /* ID of suspended read request */
|
2011-03-25 11:43:24 +01:00
|
|
|
cp_grant_id_t tty_ingrant; /* grant where data is to go */
|
2013-09-11 12:48:10 +02:00
|
|
|
size_t tty_inleft; /* how many chars are still needed */
|
|
|
|
size_t tty_incum; /* # chars input so far */
|
|
|
|
endpoint_t tty_outcaller; /* process that made the call, or NONE */
|
|
|
|
cdev_id_t tty_outid; /* ID of suspended write request */
|
2011-03-25 11:43:24 +01:00
|
|
|
cp_grant_id_t tty_outgrant; /* grant where data comes from */
|
2013-09-11 12:48:10 +02:00
|
|
|
size_t tty_outleft; /* # chars yet to be output */
|
|
|
|
size_t tty_outcum; /* # chars output so far */
|
|
|
|
endpoint_t tty_iocaller; /* process that made the call, or NONE */
|
|
|
|
cdev_id_t tty_ioid; /* ID of suspended ioctl request */
|
|
|
|
unsigned int tty_ioreq; /* ioctl request code */
|
2011-03-25 11:43:24 +01:00
|
|
|
cp_grant_id_t tty_iogrant; /* virtual address of ioctl buffer or grant */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-06-17 15:37:41 +02:00
|
|
|
/* select() data */
|
|
|
|
int tty_select_ops; /* which operations are interesting */
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
endpoint_t tty_select_proc; /* which process wants notification */
|
2005-06-17 15:37:41 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Miscellaneous. */
|
|
|
|
devfun_t tty_ioctl; /* set line speed, etc. at the device level */
|
TTY: seperate hardware dependent parts + add new serial driver
.Split TTY in order to support both x86 and ARM.
.Add support for the TI 16750 UARTs on OMAP35x.
.Various other improvements:
.Kernel messages are printed using generic terminal write
functions. That is, they are no longer directly displayed
on the console.
.The console can now be displayed on any terminal. This
is configured by the "console={tty00,tty01,ttyc2,ttyc3,ttyc4}"
boot variable -- basically any valid /dev/tty* terminal.
.Cutify kernel messages with colors. Configured by
"kernelclr={1,2,3,4,5,6,7}" boot variable.
2012-10-17 16:07:53 +02:00
|
|
|
devfun_t tty_open; /* tell the device that the tty is opened */
|
2005-04-21 16:53:53 +02:00
|
|
|
devfun_t tty_close; /* tell the device that the tty is closed */
|
|
|
|
void *tty_priv; /* pointer to per device private data */
|
|
|
|
struct termios tty_termios; /* terminal attributes */
|
|
|
|
struct winsize tty_winsize; /* window size (#lines and #columns) */
|
|
|
|
|
|
|
|
u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */
|
2005-06-17 15:37:41 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
} tty_t;
|
|
|
|
|
|
|
|
/* Memory allocated in tty.c, so extern here. */
|
|
|
|
extern tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
|
|
|
|
extern int ccurrent; /* currently visible console */
|
2008-12-08 17:40:29 +01:00
|
|
|
extern u32_t system_hz; /* system clock frequency */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-07-29 17:22:58 +02:00
|
|
|
extern unsigned long kbd_irq_set;
|
|
|
|
extern unsigned long rs_irq_set;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Values for the fields. */
|
|
|
|
#define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */
|
|
|
|
#define ESCAPED 1 /* previous character was LNEXT (^V) */
|
|
|
|
#define RUNNING 0 /* no STOP (^S) has been typed to stop output */
|
|
|
|
#define STOPPED 1 /* STOP (^S) has been typed to stop output */
|
|
|
|
|
|
|
|
/* Fields and flags on characters in the input queue. */
|
|
|
|
#define IN_CHAR 0x00FF /* low 8 bits are the character itself */
|
|
|
|
#define IN_LEN 0x0F00 /* length of char if it has been echoed */
|
|
|
|
#define IN_LSHIFT 8 /* length = (c & IN_LEN) >> IN_LSHIFT */
|
|
|
|
#define IN_EOT 0x1000 /* char is a line break (^D, LF) */
|
|
|
|
#define IN_EOF 0x2000 /* char is EOF (^D), do not return to user */
|
|
|
|
#define IN_ESC 0x4000 /* escaped by LNEXT (^V), no interpretation */
|
|
|
|
|
|
|
|
/* Times and timeouts. */
|
|
|
|
#define force_timeout() ((void) (0))
|
|
|
|
|
|
|
|
/* Number of elements and limit of a buffer. */
|
|
|
|
#define buflen(buf) (sizeof(buf) / sizeof((buf)[0]))
|
|
|
|
#define bufend(buf) ((buf) + buflen(buf))
|
|
|
|
|
|
|
|
/* Memory allocated in tty.c, so extern here. */
|
2005-04-29 17:36:43 +02:00
|
|
|
extern struct machine machine; /* machine information (a.o.: pc_at, ega) */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-09-30 15:01:34 +02:00
|
|
|
/* The tty outputs diagnostic messages in a circular buffer. */
|
|
|
|
extern struct kmessages kmess;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Function prototypes for TTY driver. */
|
|
|
|
/* tty.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void handle_events(struct tty *tp);
|
|
|
|
void sigchar(struct tty *tp, int sig, int mayflush);
|
|
|
|
void tty_task(void);
|
2013-09-11 12:48:10 +02:00
|
|
|
tty_t *line2tty(devminor_t minor);
|
2012-03-24 16:16:34 +01:00
|
|
|
int in_process(struct tty *tp, char *buf, int count, int scode);
|
|
|
|
void out_process(struct tty *tp, char *bstart, char *bpos, char *bend,
|
|
|
|
int *icount, int *ocount);
|
|
|
|
void tty_wakeup(clock_t now);
|
|
|
|
int select_try(struct tty *tp, int ops);
|
|
|
|
int select_retry(struct tty *tp);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* rs232.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void rs_init(struct tty *tp);
|
|
|
|
void rs_interrupt(message *m);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* console.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void kputc(int c);
|
|
|
|
void cons_stop(void);
|
|
|
|
void scr_init(struct tty *tp);
|
|
|
|
void toggle_scroll(void);
|
2013-09-11 12:48:10 +02:00
|
|
|
int con_loadfont(endpoint_t endpt, cp_grant_id_t grant);
|
2012-03-24 16:16:34 +01:00
|
|
|
void select_console(int cons_line);
|
|
|
|
void beep_x( unsigned freq, clock_t dur);
|
2013-09-11 12:48:10 +02:00
|
|
|
void do_video(message *m, int ipc_status);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* keyboard.c */
|
2012-03-24 16:16:34 +01:00
|
|
|
void kb_init(struct tty *tp);
|
|
|
|
void kb_init_once(void);
|
2013-09-11 12:48:10 +02:00
|
|
|
int kbd_loadmap(endpoint_t endpt, cp_grant_id_t grant);
|
2012-03-24 16:16:34 +01:00
|
|
|
void do_fkey_ctl(message *m);
|
|
|
|
void kbd_interrupt(message *m);
|
2013-09-11 12:48:10 +02:00
|
|
|
void do_kbd(message *m, int ipc_status);
|
2012-03-24 16:16:34 +01:00
|
|
|
void do_kb_inject(message *m);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* pty.c */
|
2013-09-11 12:48:10 +02:00
|
|
|
void do_pty(message *m_ptr, int ipc_status);
|
2012-03-24 16:16:34 +01:00
|
|
|
void pty_init(struct tty *tp);
|
|
|
|
void select_retry_pty(struct tty *tp);
|