tty.h

Go to the documentation of this file.
00001 /*      tty.h - Terminals       */
00002 
00003 #include <timers.h>
00004 #include "../../kernel/const.h"
00005 #include "../../kernel/type.h"
00006 
00007 #undef lock
00008 #undef unlock
00009 
00010 /* First minor numbers for the various classes of TTY devices. */
00011 #define CONS_MINOR         0
00012 #define LOG_MINOR         15
00013 #define RS232_MINOR       16
00014 #define KBD_MINOR        127
00015 #define KBDAUX_MINOR     126
00016 #define VIDEO_MINOR      125
00017 #define TTYPX_MINOR      128
00018 #define PTYPX_MINOR      192
00019 
00020 #define LINEWRAP           1    /* console.c - wrap lines at column 80 */
00021 
00022 #define TTY_IN_BYTES     256    /* tty input queue size */
00023 #define TAB_SIZE           8    /* distance between tab stops */
00024 #define TAB_MASK           7    /* mask to compute a tab stop position */
00025 
00026 #define ESC             '\33'   /* escape */
00027 
00028 #define O_NOCTTY       00400    /* from <fcntl.h>, or cc will choke */
00029 #define O_NONBLOCK     04000
00030 
00031 struct tty;
00032 typedef _PROTOTYPE( int (*devfun_t), (struct tty *tp, int try_only) );
00033 typedef _PROTOTYPE( void (*devfunarg_t), (struct tty *tp, int c) );
00034 
00035 typedef struct tty {
00036   int tty_events;               /* set when TTY should inspect this line */
00037   int tty_index;                /* index into TTY table */
00038   int tty_minor;                /* device minor number */
00039 
00040   /* Input queue.  Typed characters are stored here until read by a program. */
00041   u16_t *tty_inhead;            /* pointer to place where next char goes */
00042   u16_t *tty_intail;            /* pointer to next char to be given to prog */
00043   int tty_incount;              /* # chars in the input queue */
00044   int tty_eotct;                /* number of "line breaks" in input queue */
00045   devfun_t tty_devread;         /* routine to read from low level buffers */
00046   devfun_t tty_icancel;         /* cancel any device input */
00047   int tty_min;                  /* minimum requested #chars in input queue */
00048   timer_t tty_tmr;              /* the timer for this tty */
00049 
00050   /* Output section. */
00051   devfun_t tty_devwrite;        /* routine to start actual device output */
00052   devfunarg_t tty_echo;         /* routine to echo characters input */
00053   devfun_t tty_ocancel;         /* cancel any ongoing device output */
00054   devfun_t tty_break;           /* let the device send a break */
00055 
00056   /* Terminal parameters and status. */
00057   int tty_position;             /* current position on the screen for echoing */
00058   char tty_reprint;             /* 1 when echoed input messed up, else 0 */
00059   char tty_escaped;             /* 1 when LNEXT (^V) just seen, else 0 */
00060   char tty_inhibited;           /* 1 when STOP (^S) just seen (stops output) */
00061   int tty_pgrp;                 /* slot number of controlling process */
00062   char tty_openct;              /* count of number of opens of this tty */
00063 
00064   /* Information about incomplete I/O requests is stored here. */
00065   char tty_inrepcode;           /* reply code, TASK_REPLY or REVIVE */
00066   char tty_inrevived;           /* set to 1 if revive callback is pending */
00067   int tty_incaller;             /* process that made the call (usually FS) */
00068   int tty_inproc;               /* process that wants to read from tty */
00069   vir_bytes tty_in_vir;         /* virtual address where data is to go */
00070   int tty_inleft;               /* how many chars are still needed */
00071   int tty_incum;                /* # chars input so far */
00072   int tty_outrepcode;           /* reply code, TASK_REPLY or REVIVE */
00073   int tty_outrevived;           /* set to 1 if revive callback is pending */
00074   int tty_outcaller;            /* process that made the call (usually FS) */
00075   int tty_outproc;              /* process that wants to write to tty */
00076   vir_bytes tty_out_vir;        /* virtual address where data comes from */
00077   int tty_outleft;              /* # chars yet to be output */
00078   int tty_outcum;               /* # chars output so far */
00079   int tty_iocaller;             /* process that made the call (usually FS) */
00080   int tty_ioproc;               /* process that wants to do an ioctl */
00081   int tty_ioreq;                /* ioctl request code */
00082   vir_bytes tty_iovir;          /* virtual address of ioctl buffer */
00083 
00084   /* select() data */
00085   int tty_select_ops;           /* which operations are interesting */
00086   int tty_select_proc;          /* which process wants notification */
00087 
00088   /* Miscellaneous. */
00089   devfun_t tty_ioctl;           /* set line speed, etc. at the device level */
00090   devfun_t tty_close;           /* tell the device that the tty is closed */
00091   void *tty_priv;               /* pointer to per device private data */
00092   struct termios tty_termios;   /* terminal attributes */
00093   struct winsize tty_winsize;   /* window size (#lines and #columns) */
00094 
00095   u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */
00096 
00097 } tty_t;
00098 
00099 /* Memory allocated in tty.c, so extern here. */
00100 extern tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
00101 extern int ccurrent;            /* currently visible console */
00102 extern int irq_hook_id;         /* hook id for keyboard irq */
00103 
00104 extern unsigned long kbd_irq_set;
00105 extern unsigned long rs_irq_set;
00106 
00107 extern int panicing;    /* From panic.c in sysutil */
00108 
00109 /* Values for the fields. */
00110 #define NOT_ESCAPED        0    /* previous character is not LNEXT (^V) */
00111 #define ESCAPED            1    /* previous character was LNEXT (^V) */
00112 #define RUNNING            0    /* no STOP (^S) has been typed to stop output */
00113 #define STOPPED            1    /* STOP (^S) has been typed to stop output */
00114 
00115 /* Fields and flags on characters in the input queue. */
00116 #define IN_CHAR       0x00FF    /* low 8 bits are the character itself */
00117 #define IN_LEN        0x0F00    /* length of char if it has been echoed */
00118 #define IN_LSHIFT          8    /* length = (c & IN_LEN) >> IN_LSHIFT */
00119 #define IN_EOT        0x1000    /* char is a line break (^D, LF) */
00120 #define IN_EOF        0x2000    /* char is EOF (^D), do not return to user */
00121 #define IN_ESC        0x4000    /* escaped by LNEXT (^V), no interpretation */
00122 
00123 /* Times and timeouts. */
00124 #define force_timeout() ((void) (0))
00125 
00126 /* Memory allocated in tty.c, so extern here. */
00127 extern timer_t *tty_timers;             /* queue of TTY timers */
00128 extern clock_t tty_next_timeout;        /* next TTY timeout */
00129 
00130 /* Number of elements and limit of a buffer. */
00131 #define buflen(buf)     (sizeof(buf) / sizeof((buf)[0]))
00132 #define bufend(buf)     ((buf) + buflen(buf))
00133 
00134 /* Memory allocated in tty.c, so extern here. */
00135 extern struct machine machine;  /* machine information (a.o.: pc_at, ega) */
00136 
00137 /* The tty outputs diagnostic messages in a circular buffer. */
00138 extern struct kmessages kmess;
00139 
00140 /* Function prototypes for TTY driver. */
00141 /* tty.c */
00142 _PROTOTYPE( void handle_events, (struct tty *tp)                        );
00143 _PROTOTYPE( void sigchar, (struct tty *tp, int sig)                     );
00144 _PROTOTYPE( void tty_task, (void)                                       );
00145 _PROTOTYPE( int in_process, (struct tty *tp, char *buf, int count)      );
00146 _PROTOTYPE( void out_process, (struct tty *tp, char *bstart, char *bpos,
00147                                 char *bend, int *icount, int *ocount)   );
00148 _PROTOTYPE( void tty_wakeup, (clock_t now)                              );
00149 _PROTOTYPE( void tty_reply, (int code, int replyee, int proc_nr,
00150                                                         int status)     );
00151 _PROTOTYPE( int tty_devnop, (struct tty *tp, int try)                   );
00152 _PROTOTYPE( int select_try, (struct tty *tp, int ops)                   );
00153 _PROTOTYPE( int select_retry, (struct tty *tp)                          );
00154 
00155 /* rs232.c */
00156 _PROTOTYPE( void rs_init, (struct tty *tp)                              );
00157 _PROTOTYPE( void rs_interrupt, (message *m)                             );
00158 
00159 #if (CHIP == INTEL)
00160 /* console.c */
00161 _PROTOTYPE( void kputc, (int c)                                         );
00162 _PROTOTYPE( void cons_stop, (void)                                      );
00163 _PROTOTYPE( void do_new_kmess, (message *m)                             );
00164 _PROTOTYPE( void do_diagnostics, (message *m)                           );
00165 _PROTOTYPE( void do_get_kmess, (message *m)                             );
00166 _PROTOTYPE( void scr_init, (struct tty *tp)                             );
00167 _PROTOTYPE( void toggle_scroll, (void)                                  );
00168 _PROTOTYPE( int con_loadfont, (message *m)                              );
00169 _PROTOTYPE( void select_console, (int cons_line)                        );
00170 _PROTOTYPE( void beep_x, ( unsigned freq, clock_t dur)                  );
00171 _PROTOTYPE( void do_video, (message *m)                                 );
00172 
00173 /* keyboard.c */
00174 _PROTOTYPE( void kb_init, (struct tty *tp)                              );
00175 _PROTOTYPE( void kb_init_once, (void)                                   );
00176 _PROTOTYPE( int kbd_loadmap, (message *m)                               );
00177 _PROTOTYPE( void do_panic_dumps, (message *m)                           );
00178 _PROTOTYPE( void do_fkey_ctl, (message *m)                              );
00179 _PROTOTYPE( void kbd_interrupt, (message *m)                            );
00180 _PROTOTYPE( void do_kbd, (message *m)                                   );
00181 _PROTOTYPE( void do_kbdaux, (message *m)                                );
00182 _PROTOTYPE( int kbd_status, (message *m_ptr)                            );
00183 
00184 /* pty.c */
00185 _PROTOTYPE( void do_pty, (struct tty *tp, message *m_ptr)               );
00186 _PROTOTYPE( void pty_init, (struct tty *tp)                             );
00187 _PROTOTYPE( void select_retry_pty, (struct tty *tp)                     );
00188 _PROTOTYPE( int pty_status, (message *m_ptr)                            );
00189 
00190 /* vidcopy.s */
00191 _PROTOTYPE( void vid_vid_copy, (unsigned src, unsigned dst, unsigned count));
00192 _PROTOTYPE( void mem_vid_copy, (u16_t *src, unsigned dst, unsigned count));
00193 
00194 #endif /* (CHIP == INTEL) */
00195 

Generated on Fri Apr 14 22:57:19 2006 for minix by  doxygen 1.4.6