📄 cons.c
字号:
#ifndef lintstatic char *sccsid = "@(#)cons.c 4.5 ULTRIX 10/9/90";#endif lint/************************************************************************ * * * Copyright (c) 1984-1988 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* * Modification History * * 31-Aug-90 paradis * Code cleanups for VAX9000 support. * * 03-Aug-90 rafiey (Ali Rafieymehr) * Added VAX9000 (Aquarius) support (its very similar to 8600). Also * cleaned up the logical console command check code for 8600 in * cnstart. Eliminated the "goto" from cnputc. Fixed a couple of 8600 * bugs in cnputc routine: * 1. if "c == 0", return BEFORE messing with TXCS register. * 2. when restoring TXCS, also set write mask bit. * * 15-Aug-89 - Randall Brown * * Changed all references of TCSADFLUSH to TCSAFLUSH * * 30-May-89 darrell * Added include of ../../machine/common/cpuconf.h -- cpu types * were moved there. * * 07-Jun-88 darrell * Added VAX60 (Firefox) support. * * 26-Apr-88 jaw * Add VAX8820 support. * * 7-Mar-88 lp * Fixed typo in ioctl routine (cant believe its been wrong this long). * * 12-Feb-88 - Fred Canter * Changes for VAX420 (CVAXstar/PVAX) support. * * 3-Feb-88 - Tim Burke * Only examine O_NONBLOCK for POSIX mode. * A valid character of 0377 is returned as 0377,0377 in TERMIODISC only. * Initialize termio flag extensions to be zero on first open. * * 1-Dec-87 - Tim Burke * * Added support for both System V termio(7) and POSIX termios(7). These * changes also include support for 8-bit canonical processing. Changes * involve: * * - Default settings on first open depend on mode of open. For termio * opens the defaults are "RAW" style, while non-termio opens default * to the traditional "cooked" style. * - The driver now represents its terminal attributes and special * characters in the POSIX termios data structure. This contrasts the * original approach of storing attributes and special chars in the * t_flags, ltchars and tchars. * - New termio ioctls: TCSANOW, TCSADRAIN, TCSADFLUSH, TCSETA, TESETAW, * TCSETAF. * - Addition of LPASS8 to local mode word for 8-bit canonical support. * * * 20-Apr-87 - afd * Changed name CVAXQ to VAX3600 for Mayfair. * * 13-Mar-87 - Tim Burke * Added full TERMIO functionality to terminal subsystem. * Formerly the terminal settings were specified by the t_flags and * t_ispeed. Now they are specified by termio parameters in the cflag. * * 06-Mar-87 -- afd * Added CVAXQ to MVAX ifdef's in v_consputc for QDSS. * * * 06-Aug-86 -- jaw fixes to 8800 console support. * * 2-Jul-86 -- fred (Fred Canter) * Moved sscons_init(), ssputc(), & ssgetc() to ss.c. * No longer any VAXstar specific code in cons.c. * * 18-Jun-86 -- fred (Fred Canter) * Changes for VAXstar kernel support. * * 29-Apr-86 -- jaw fixes to 8800 console. * * 15-Apr-86 -- afd * v_console() was changed to v_consputc(). * * 09-Apr-86 -- jaw only VAX8800 now toggles TXCS_IE. * * 03-Apr-86 -- jaw left out some ifdefs. * * 02-Apr-86 -- jaw add support for nautilus console and memory adapter * * 05-Mar-86 -- jaw VAXBI device and controller config code added. * todr code put in cpusw. * * 07 Nov 85 -- lp * Disable use of EMM. Only snap file commands allowed on * logical_cons. * 10 Oct 85 -- lp * Added 8600 remote line support. Also moved 780 floppy output * to be routed through chrqueue (so we dont get confused * about who a character is intended for). Prevent non-8600 * 8200 machines from using extra lines code (they can't). * Make sure interrupts are off in 8600 cnputc. * * 19 Aug 85 -- lp * Changed cnstart routine to only call cnoutput if not aready * outputting characters. * * 13 Aug 85 -- rjl * Changed virtual console put call to be through a function pointer * instead of directly to allow dynamic configuring of the system * console. * * 16 Jul 85 -- lp * Cleanup for 1.2 ft. Added ioctl setspeed for Scorpio. * * 15 Mar 85 -- lp * Added support for Scorpio slu's (serial line units). * Added notion of interrupt queue so we can get characters * in at elevated IPL the reschedule tty action at a lower IPL. * * 20 Nov 84 -- rjl * Changed qvss support to virtual console support with the idea that * a virtual console could be added at a later time. * * 11 Aug 84 -- rjl * Added MVAX support for system console *//* * VAX console driver (and floppy interface) */#include "../h/param.h"#include "../h/conf.h"#include "../h/dir.h"#include "../h/user.h"#include "../h/proc.h"#include "../h/ioctl.h"#include "../h/tty.h"#include "../h/termio.h"#include "../h/file.h"#include "../h/systm.h"#include "../h/uio.h"#include "../h/exec.h"#include "../machine/cpu.h"#include "../../machine/common/cpuconf.h"#include "../machine/cons.h"#include "../machine/mtpr.h"#if defined(VAX8200) || defined(VAX8600) || defined (VAX9000)#define NCONS 4#else#define NCONS 1#endif#define DEFAULTSPEED B4800/* * ULTRIX settings for first open. */#define IFLAGS (EVENP|ECHO|XTABS|CRMOD)/* termio flags will be set to these default values in non-termio mode to * provide a backward compatible ULTRIX environment. */#define IFLAG (BRKINT|IGNPAR|ISTRIP|IXON|IXANY|ICRNL)#define OFLAG (OPOST|TAB3|ONLCR)#define LFLAG (ISIG|ICANON|ECHO)#ifdef VAX8200#define CFLAG (PARENB|CREAD|CS7|CLOCAL)#else VAX8200#define CFLAG (PARENB|CREAD|CS7|CLOCAL)#endif VAX8200struct tty cons[NCONS];int tty8800rec[3] = { 0, 0, 0};int txcs8800ie;int rx8800ie;int cnstart();int ttrstrt();char partab[];int cold;#ifdef VAX8200static int rxcs[] = { RXCS, RXCS1, RXCS2, RXCS3 };static int rxdb[] = { RXDB, RXDB1, RXDB2, RXDB3 };static int txcs[] = { TXCS, TXCS1, TXCS2, TXCS3 };static int txdb[] = { TXDB, TXDB1, TXDB2, TXDB3 };#else VAX8200static int rxcs[] = { RXCS };static int rxdb[] = { RXDB };static int txcs[] = { TXCS };static int txdb[] = { TXDB };#endif VAX8200/* * Note: Aquarius doesn't have the EMM port but this define should be ok.*/#if defined(VAX8600) || defined(VAX9000)static int conson[] = { LOCAL_CONS, REMOTE_PORT, EMM_PORT, LOGICAL_CONS };static int consid[] = { LOCAL_CONS_ID, REMOTE_PORT_ID, EMM_ID, LOGIC_CONS_ID };int mask_update_needed = 0;int new_mask = 0;#endif#ifdef VAX8800static int consid8800[] = {N_LCL_CONS,N_LCL_NOLOG,N_RMT_CONS};#endif /*ARGSUSED*/cnopen(dev, flag) dev_t dev;{ register int whichcons = minor(dev); register int which = minor(dev); register struct tty *tp; register int s, timo; switch (cpu) {#if defined(VAX8200) || defined(VAX8600) || defined(VAX9000) case VAX_9000: /* VAX 9000 only supports 0 (local console) and * 1 (remote console). */ if(which > 1) return(ENODEV); /* Fall thru to... */ case VAX_8600: whichcons=0; case VAX_8200: if (which > 3 ) return(ENODEV); break;#endif #ifdef VAX8800 case VAX_8820: case VAX_8800: if (which > 2 ) return(ENODEV); tty8800rec[which] = 0; whichcons=0; break;#endif default: if (which) return(ENODEV); break; } tp = &cons[which]; tp->t_oproc = cnstart; /* * Look at the compatibility mode to specify correct default parameters * and to insure only standard specified functionality. */ if ((u.u_procp->p_progenv == A_SYSV) || (u.u_procp->p_progenv == A_POSIX)) { flag |= O_TERMIO; tp->t_line = TERMIODISC; } /* * Set state bit to tell tty.c not to assign this line as the * controlling terminal for the process which opens this line. */ if (flag & O_NOCTTY) tp->t_state |= TS_ONOCTTY; if ((tp->t_state&TS_ISOPEN) == 0) { ttychars(tp); tp->t_state = TS_ISOPEN|TS_CARR_ON; tp->t_cflag = tp->t_cflag_ext = DEFAULTSPEED; tp->t_iflag_ext = 0; tp->t_oflag_ext = 0; tp->t_lflag_ext = 0; /* * Ultrix defaults to a "COOKED" mode on the first * open, while termio defaults to a "RAW" style. * Base this decision by a flag set in the termio * emulation routine for open, or set by an explicit * ioctl call. */ if ( flag & O_TERMIO ) { /* Provide a termio style environment. * "RAW" style by default. */ tp->t_flags = RAW; tp->t_iflag = 0; tp->t_oflag = 0; tp->t_cflag |= CS8|CREAD|HUPCL; tp->t_lflag = 0; /* * Change to System V line discipline. */ tp->t_line = TERMIODISC; /* * The following three control chars have * different default values than ULTRIX. */ tp->t_cc[VERASE] = '#'; tp->t_cc[VKILL] = '@'; tp->t_cc[VINTR] = 0177; tp->t_cc[VMIN] = 6; tp->t_cc[VTIME] = 1; } else { /* Provide a backward compatible ULTRIX * environment. "COOKED" style. */ tp->t_flags = IFLAGS; tp->t_iflag = IFLAG; tp->t_oflag = OFLAG; tp->t_lflag = LFLAG; tp->t_cflag |= CFLAG; } } if (tp->t_state&TS_XCLUDE && u.u_uid != 0) return (EBUSY);#if defined(VAX8600) || defined(VAX9000) if(cpu == VAX_8600 || cpu == VAX_9000) { if(consid[which] == EMM_ID) /* No EMM allowed */ return(ENODEV); /* enable that console based on dev */ mtpr(rxcs[0], (mfpr(rxcs[0])|conson[which]|RXCS_IE)); cnenable_8600_9000(conson[which], TXCS_IE); }#endif s = spl5(); if (((cpu != VAX_9000) && (cpu != VAX_8800) && (cpu != VAX_8820)) || txcs8800ie == 0) { txcs8800ie=1; mtpr(txcs[whichcons], (mfpr(txcs[whichcons])|TXCS_IE)); } splx(s); if((cpu != VAX_8600) && (cpu != VAX_9000)) { mtpr(rxcs[whichcons], (mfpr(rxcs[whichcons])|RXCS_IE)); } return ((*linesw[tp->t_line].l_open)(dev, tp));}/*ARGSUSED*/cnclose(dev) dev_t dev;{ register int which = minor(dev); register struct tty *tp = &cons[which]; register timo; (*linesw[tp->t_line].l_close)(tp); switch (cpu) {#if defined(VAX8800) || defined(VAX780) case VAX_8820: case VAX_8800: case VAX_780: ttyclose(tp); break;#endif#if defined(VAX8600) || defined(VAX9000) case VAX_8600: case VAX_9000: ttyclose(tp); /* Mask the line out */ cndisable_8600_9000(conson[which], 0); if(cpu == VAX_8600) { mtpr(rxcs[0], (mfpr(rxcs[0])&~conson[which]) | RXCS_IE); } break;#endif default: mtpr(rxcs[which], mfpr(rxcs[which])&~RXCS_IE); ttyclose(tp);#ifdef VAX8200 if(cpu == VAX_8200) { tp->t_cflag = tp->t_cflag_ext = DEFAULTSPEED; cnparam(which); }#endif /* disable interrupts till line is opened */ mtpr(txcs[which], mfpr(txcs[which])&~TXCS_IE); break; } /* * Clear input speed so that the next open will have propper defaults. */ tp->t_cflag &= ~CBAUD; tp->t_cflag_ext &= ~CBAUD; /* Remove termio flags that do not map */ tp->t_iflag &= ~TERMIO_ONLY_IFLAG; tp->t_oflag &= ~TERMIO_ONLY_OFLAG; tp->t_cflag &= ~TERMIO_ONLY_CFLAG; tp->t_lflag &= ~TERMIO_ONLY_LFLAG;}/*ARGSUSED*/cnread(dev, uio) dev_t dev; struct uio *uio;{ register struct tty *tp = &cons[minor(dev)]; return ((*linesw[tp->t_line].l_read)(tp, uio));}/*ARGSUSED*/cnwrite(dev, uio) dev_t dev; struct uio *uio;{ register struct tty *tp = &cons[minor(dev)]; return ((*linesw[tp->t_line].l_write)(tp, uio));}/* * Got a level-20 receive interrupt - * the LSI wants to give us a character. * Catch the character, and see who it goes to. *//*ARGSUSED*/cnrint(dev) dev_t dev;{ int chrqueue(); register int c; register int which = minor(dev); register struct tty *tp = &cons[which]; switch (cpu) {#ifdef VAX8800 case VAX_8820: case VAX_8800: c = mfpr(rxdb[0]); ka8800requeue(c); return;#endif#if defined(VAX8600) case VAX_8600: c = mfpr(rxdb[0]); /* Based on Id field, setup who the interrupt goes to */ /* Valid values are Venus: 0,1,2,3; Aquarius: 0,1,3 */ if((c&RXDB_ID) == RXDB_ID) /* could be handled better */ return; tp = &cons[(c>>8)&0x3]; break;#endif#ifdef VAX9000 case VAX_9000: /* On the VAX9000 the "dev" argument will always be * zero; the actual device has to be decoded from * the RXDB register. In fact, this may not be a * character interrupt at all; the console may have * rebooted or carrier may have been detected on the * remote line. */ c = mfpr(rxdb[0]); if((c & RXDB_ID) == RXDB_ID_CARIER) { if (c & RXDB_CONRTN) { /* SPU has rebooted! */ ka9000_reinit_spu(); } if((c & RXDB_RTYCD) == RXDB_RTYCD) { /* Carrier detect on remote. Record * this fact and set DTR on for the * remote TTY. */ cons[1].t_state |= TS_CARR_ON; mtpr(rxcs[0], mfpr(rxcs[0])|RXCS_RDTR|RXCS_IE); } if((c & RXDB_RTYCD) == 0) { if(cons[1].t_state & TS_CARR_ON) { /* If remote carrier * transitioned from high * to low, then drop the * connection. */ cons9000_tty_drop(&cons[1]); } } /* If a CARRIER function occurred, then * we do nothing else. */ return; } else { tp = &cons[(c>>8)&0x3]; which = tp - &cons[0]; } break;#endif VAX9000#ifdef VAX780 case VAX_780: c = mfpr(rxdb[which]); if (c&RXDB_ID) { int cnrfl(); chrqueue(cnrfl, c, 0); return; } break;#endif VAX780 default: c = mfpr(rxdb[which]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -