Index: head/sys/pc98/cbus/sio.c =================================================================== --- head/sys/pc98/cbus/sio.c (revision 42404) +++ head/sys/pc98/cbus/sio.c (revision 42405) @@ -1,4720 +1,4732 @@ /*- * Copyright (c) 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: @(#)com.c 7.5 (Berkeley) 5/16/91 - * $Id: sio.c,v 1.72 1999/01/03 05:03:47 kato Exp $ + * $Id: sio.c,v 1.73 1999/01/03 15:57:02 kato Exp $ */ #include "opt_comconsole.h" #include "opt_compat.h" #include "opt_ddb.h" #include "opt_devfs.h" #include "opt_sio.h" #include "sio.h" #include "pnp.h" /* * Serial driver, based on 386BSD-0.1 com driver. * Mostly rewritten to use pseudo-DMA. * Works for National Semiconductor NS8250-NS16550AF UARTs. * COM driver, based on HP dca driver. * * Changes for PC-Card integration: * - Added PC-Card driver table and handlers */ /*=============================================================== * 386BSD(98),FreeBSD-1.1x(98) com driver. * ----- * modified for PC9801 by M.Ishii * Kyoto University Microcomputer Club (KMC) * Chou "TEFUTEFU" Hirotomi * Kyoto Univ. the faculty of medicine *=============================================================== * FreeBSD-2.0.1(98) sio driver. * ----- * modified for pc98 Internal i8251 and MICRO CORE MC16550II * T.Koike(hfc01340@niftyserve.or.jp) * implement kernel device configuration * aizu@orient.center.nitech.ac.jp * * Notes. * ----- * PC98 localization based on 386BSD(98) com driver. Using its PC98 local * functions. * This driver is under debugging,has bugs. * * 1) config * options COM_MULTIPORT #if using MC16550II * device sio0 at nec? port 0x30 tty irq 4 #internal * device sio1 at nec? port 0xd2 tty irq 5 flags 0x101 #mc1 * device sio2 at nec? port 0x8d2 tty flags 0x101 #mc2 * # ~~~~~iobase ~~multi port flag * # ~ master device is sio1 * 2) device * cd /dev; MAKEDEV ttyd0 ttyd1 .. * 3) /etc/rc.serial * 57600bps is too fast for sio0(internal8251) * my ex. * #set default speed 9600 * modem() * : * stty last update: 15 Sep.1995 * * How to configure... * # options COM_MULTIPORT # support for MICROCORE MC16550II * ... comment-out this line, which will conflict with B98_01. * options "B98_01" # support for AIWA B98-01 * device sio1 at nec? port 0x00d1 tty irq ? * device sio2 at nec? port 0x00d5 tty irq ? * ... you can leave these lines `irq ?', irq will be autodetected. */ /* * Modified by Y.Takahashi of Kogakuin University. */ #ifdef PC98 #define COM_IF_INTERNAL 0x00 #define COM_IF_PC9861K_1 0x01 #define COM_IF_PC9861K_2 0x02 #define COM_IF_IND_SS_1 0x03 #define COM_IF_IND_SS_2 0x04 #define COM_IF_PIO9032B_1 0x05 #define COM_IF_PIO9032B_2 0x06 #define COM_IF_B98_01_1 0x07 #define COM_IF_B98_01_2 0x08 #define COM_IF_END1 COM_IF_B98_01_2 #define COM_IF_RSA98 0x10 /* same as COM_IF_NS16550 */ #define COM_IF_NS16550 0x11 #define COM_IF_SECOND_CCU 0x12 /* same as COM_IF_NS16550 */ #define COM_IF_MC16550II 0x13 #define COM_IF_MCRS98 0x14 /* same as COM_IF_MC16550II */ #define COM_IF_RSB3000 0x15 #define COM_IF_RSB384 0x16 #define COM_IF_MODEM_CARD 0x17 /* same as COM_IF_NS16550 */ #define COM_IF_RSA98III 0x18 #define COM_IF_ESP98 0x19 #define COM_IF_END2 COM_IF_ESP98 #endif /* PC98 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEVFS #include #endif #include #include #ifdef PC98 #include #include #include #include #else #include #endif #include #include #include #ifdef COM_ESP #include #endif #include #ifdef PC98 #include #endif #include "card.h" #if NCARD > 0 #include #include #endif #if NPNP > 0 #include #endif #ifdef SMP #define disable_intr() COM_DISABLE_INTR() #define enable_intr() COM_ENABLE_INTR() #endif /* SMP */ #ifndef EXTRA_SIO #if NPNP > 0 #define EXTRA_SIO MAX_PNP_CARDS #else #define EXTRA_SIO 0 #endif #endif #define NSIOTOT (NSIO + EXTRA_SIO) #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */ #define RS_IBUFSIZE 256 #define CALLOUT_MASK 0x80 #define CONTROL_MASK 0x60 #define CONTROL_INIT_STATE 0x20 #define CONTROL_LOCK_STATE 0x40 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev))) #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK) #define MINOR_TO_UNIT(mynor) ((mynor) & ~MINOR_MAGIC_MASK) #ifdef COM_MULTIPORT /* checks in flags for multiport and which is multiport "master chip" * for a given card */ #define COM_ISMULTIPORT(dev) ((dev)->id_flags & 0x01) #define COM_MPMASTER(dev) (((dev)->id_flags >> 8) & 0x0ff) #define COM_NOTAST4(dev) ((dev)->id_flags & 0x04) #endif /* COM_MULTIPORT */ #define COM_CONSOLE(dev) ((dev)->id_flags & 0x10) #define COM_FORCECONSOLE(dev) ((dev)->id_flags & 0x20) #define COM_LLCONSOLE(dev) ((dev)->id_flags & 0x40) #define COM_LOSESOUTINTS(dev) ((dev)->id_flags & 0x08) #define COM_NOFIFO(dev) ((dev)->id_flags & 0x02) #define COM_ST16650A(dev) ((dev)->id_flags & 0x20000) #define COM_C_NOPROBE (0x40000) #define COM_NOPROBE(dev) ((dev)->id_flags & COM_C_NOPROBE) #define COM_C_IIR_TXRDYBUG (0x80000) #define COM_IIR_TXRDYBUG(dev) ((dev)->id_flags & COM_C_IIR_TXRDYBUG) #define COM_FIFOSIZE(dev) (((dev)->id_flags & 0xff000000) >> 24) #ifdef PC98 #define com_emr com_msr /* Extension mode register for RSB-2000/3000 */ #else #define com_scr 7 /* scratch register for 16450-16550 (R/W) */ #endif /* * Input buffer watermarks. * The external device is asked to stop sending when the buffer exactly reaches * high water, or when the high level requests it. * The high level is notified immediately (rather than at a later clock tick) * when this watermark is reached. * The buffer size is chosen so the watermark should almost never be reached. * The low watermark is invisibly 0 since the buffer is always emptied all at * once. */ #define RS_IHIGHWATER (3 * RS_IBUFSIZE / 4) /* * com state bits. * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher * than the other bits so that they can be tested as a group without masking * off the low bits. * * The following com and tty flags correspond closely: * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and * siostop()) * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart()) * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam()) * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam()) * TS_FLUSH is not used. * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON. * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state). */ #define CS_BUSY 0x80 /* output in progress */ #define CS_TTGO 0x40 /* output not stopped by XOFF */ #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */ #define CS_CHECKMSR 1 /* check of MSR scheduled */ #define CS_CTS_OFLOW 2 /* use CTS output flow control */ #define CS_DTR_OFF 0x10 /* DTR held off */ #define CS_ODONE 4 /* output completed */ #define CS_RTS_IFLOW 8 /* use RTS input flow control */ #define CSE_BUSYCHECK 1 /* siobusycheck() scheduled */ static char const * const error_desc[] = { #define CE_OVERRUN 0 "silo overflow", #define CE_INTERRUPT_BUF_OVERFLOW 1 "interrupt-level buffer overflow", #define CE_TTY_BUF_OVERFLOW 2 "tty-level buffer overflow", }; #define CE_NTYPES 3 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum]) /* types. XXX - should be elsewhere */ typedef u_int Port_t; /* hardware port */ typedef u_char bool_t; /* boolean */ /* queue of linear buffers */ struct lbq { u_char *l_head; /* next char to process */ u_char *l_tail; /* one past the last char to process */ struct lbq *l_next; /* next in queue */ bool_t l_queued; /* nonzero if queued */ }; /* com device structure */ struct com_s { u_int id_flags; /* Copy isa device falgas */ u_char state; /* miscellaneous flag bits */ bool_t active_out; /* nonzero if the callout device is open */ u_char cfcr_image; /* copy of value written to CFCR */ #ifdef COM_ESP bool_t esp; /* is this unit a hayes esp board? */ #endif u_char extra_state; /* more flag bits, separate for order trick */ u_char fifo_image; /* copy of value written to FIFO */ bool_t hasfifo; /* nonzero for 16550 UARTs */ bool_t st16650a; /* Is a Startech 16650A or RTS/CTS compat */ bool_t loses_outints; /* nonzero if device loses output interrupts */ u_char mcr_image; /* copy of value written to MCR */ #ifdef COM_MULTIPORT bool_t multiport; /* is this unit part of a multiport device? */ #endif /* COM_MULTIPORT */ bool_t no_irq; /* nonzero if irq is not attached */ bool_t gone; /* hardware disappeared */ bool_t poll; /* nonzero if polling is required */ bool_t poll_output; /* nonzero if polling for output is required */ int unit; /* unit number */ int dtr_wait; /* time to hold DTR down on close (* 1/hz) */ u_int tx_fifo_size; u_int wopeners; /* # processes waiting for DCD in open() */ /* * The high level of the driver never reads status registers directly * because there would be too many side effects to handle conveniently. * Instead, it reads copies of the registers stored here by the * interrupt handler. */ u_char last_modem_status; /* last MSR read by intr handler */ u_char prev_modem_status; /* last MSR handled by high level */ u_char hotchar; /* ldisc-specific char to be handled ASAP */ u_char *ibuf; /* start of input buffer */ u_char *ibufend; /* end of input buffer */ u_char *ihighwater; /* threshold in input buffer */ u_char *iptr; /* next free spot in input buffer */ struct lbq obufq; /* head of queue of output buffers */ struct lbq obufs[2]; /* output buffers */ #ifdef PC98 Port_t cmd_port; Port_t sts_port; Port_t in_modem_port; Port_t intr_ctrl_port; int intr_enable; int pc98_prev_modem_status; int pc98_modem_delta; int modem_car_chg_timer; int pc98_prev_siocmd; int pc98_prev_siomod; int modem_checking; int pc98_if_type; #endif /* PC98 */ Port_t data_port; /* i/o ports */ #ifdef COM_ESP Port_t esp_port; #endif Port_t int_id_port; Port_t iobase; #ifdef PC98 Port_t rsabase; /* iobase address of a I/O-DATA RSA board */ #endif Port_t modem_ctl_port; Port_t line_status_port; Port_t modem_status_port; Port_t intr_ctl_port; /* Ports of IIR register */ struct tty *tp; /* cross reference */ /* Initial state. */ struct termios it_in; /* should be in struct tty */ struct termios it_out; /* Lock state. */ struct termios lt_in; /* should be in struct tty */ struct termios lt_out; bool_t do_timestamp; bool_t do_dcd_timestamp; struct timeval timestamp; struct timeval dcd_timestamp; u_long bytes_in; /* statistics */ u_long bytes_out; u_int delta_error_counts[CE_NTYPES]; u_long error_counts[CE_NTYPES]; /* * Ping-pong input buffers. The extra factor of 2 in the sizes is * to allow for an error byte for each input byte. */ #ifdef PC98 u_long CE_INPUT_OFFSET; u_char *ibuf1; u_char *ibuf2; /* * Data area for output buffers. Someday we should build the output * buffer queue without copying data. */ u_char *obuf1; u_char *obuf2; #else #define CE_INPUT_OFFSET RS_IBUFSIZE u_char ibuf1[2 * RS_IBUFSIZE]; u_char ibuf2[2 * RS_IBUFSIZE]; /* * Data area for output buffers. Someday we should build the output * buffer queue without copying data. */ u_char obuf1[256]; u_char obuf2[256]; #endif #ifdef DEVFS void *devfs_token_ttyd; void *devfs_token_ttyl; void *devfs_token_ttyi; void *devfs_token_cuaa; void *devfs_token_cual; void *devfs_token_cuai; #endif }; #ifdef COM_ESP static int espattach __P((struct isa_device *isdp, struct com_s *com, Port_t esp_port)); #endif static int sioattach __P((struct isa_device *dev)); static timeout_t siobusycheck; static timeout_t siodtrwakeup; static void comhardclose __P((struct com_s *com)); static ointhand2_t siointr; static void siointr1 __P((struct com_s *com)); static int commctl __P((struct com_s *com, int bits, int how)); static int comparam __P((struct tty *tp, struct termios *t)); static swihand_t siopoll; static int sioprobe __P((struct isa_device *dev)); static void siosettimeout __P((void)); static void comstart __P((struct tty *tp)); static timeout_t comwakeup; static void disc_optim __P((struct tty *tp, struct termios *t, struct com_s *com)); static char driver_name[] = "sio"; /* table and macro for fast conversion from a unit number to its com struct */ static struct com_s *p_com_addr[NSIOTOT]; #define com_addr(unit) (p_com_addr[unit]) struct isa_driver siodriver = { sioprobe, sioattach, driver_name }; static d_open_t sioopen; static d_close_t sioclose; static d_read_t sioread; static d_write_t siowrite; static d_ioctl_t sioioctl; static d_stop_t siostop; static d_devtotty_t siodevtotty; #define CDEV_MAJOR 28 static struct cdevsw sio_cdevsw = { sioopen, sioclose, sioread, siowrite, sioioctl, siostop, noreset, siodevtotty, ttpoll, nommap, NULL, driver_name, NULL, -1, nodump, nopsize, D_TTY, }; static int comconsole = -1; static volatile speed_t comdefaultrate = CONSPEED; static u_int com_events; /* input chars + weighted output completions */ static Port_t siocniobase; static bool_t sio_registered; static int sio_timeout; static int sio_timeouts_until_log; static struct callout_handle sio_timeout_handle = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle); #if 0 /* XXX */ static struct tty *sio_tty[NSIOTOT]; #else static struct tty sio_tty[NSIOTOT]; #endif static const int nsio_tty = NSIOTOT; #ifdef PC98 struct siodev { short if_type; short irq; Port_t cmd, sts, ctrl, mod; }; static int sysclock; #define COM_INT_DISABLE {int previpri; previpri=spltty(); #define COM_INT_ENABLE splx(previpri);} #define IEN_TxFLAG IEN_Tx #define COM_CARRIER_DETECT_EMULATE 0 #define PC98_CHECK_MODEM_INTERVAL (hz/10) #define DCD_OFF_TOLERANCE 2 #define DCD_ON_RECOGNITION 2 #define IS_8251(if_type) (!(if_type & 0x10)) #define COM1_EXT_CLOCK 0x40000 static void commint __P((dev_t dev)); static void com_tiocm_set __P((struct com_s *com, int msr)); static void com_tiocm_bis __P((struct com_s *com, int msr)); static void com_tiocm_bic __P((struct com_s *com, int msr)); static int com_tiocm_get __P((struct com_s *com)); static int com_tiocm_get_delta __P((struct com_s *com)); static void pc98_msrint_start __P((dev_t dev)); static void com_cflag_and_speed_set __P((struct com_s *com, int cflag, int speed)); static int pc98_ttspeedtab __P((struct com_s *com, int speed)); static int pc98_get_modem_status __P((struct com_s *com)); static timeout_t pc98_check_msr; static void pc98_set_baud_rate __P((struct com_s *com, int count)); static void pc98_i8251_reset __P((struct com_s *com, int mode, int command)); static void pc98_disable_i8251_interrupt __P((struct com_s *com, int mod)); static void pc98_enable_i8251_interrupt __P((struct com_s *com, int mod)); static int pc98_check_i8251_interrupt __P((struct com_s *com)); static int pc98_i8251_get_cmd __P((struct com_s *com)); static int pc98_i8251_get_mod __P((struct com_s *com)); static void pc98_i8251_set_cmd __P((struct com_s *com, int x)); static void pc98_i8251_or_cmd __P((struct com_s *com, int x)); static void pc98_i8251_clear_cmd __P((struct com_s *com, int x)); static void pc98_i8251_clear_or_cmd __P((struct com_s *com, int clr, int x)); static int pc98_check_if_type __P((struct isa_device *dev, struct siodev *iod)); static void pc98_check_sysclock __P((void)); static int pc98_set_ioport __P((struct com_s *com, int id_flags)); #define com_int_Tx_disable(com) \ pc98_disable_i8251_interrupt(com,IEN_Tx|IEN_TxEMP) #define com_int_Tx_enable(com) \ pc98_enable_i8251_interrupt(com,IEN_TxFLAG) #define com_int_Rx_disable(com) \ pc98_disable_i8251_interrupt(com,IEN_Rx) #define com_int_Rx_enable(com) \ pc98_enable_i8251_interrupt(com,IEN_Rx) #define com_int_TxRx_disable(com) \ pc98_disable_i8251_interrupt(com,IEN_Tx|IEN_TxEMP|IEN_Rx) #define com_int_TxRx_enable(com) \ pc98_enable_i8251_interrupt(com,IEN_TxFLAG|IEN_Rx) #define com_send_break_on(com) \ pc98_i8251_or_cmd(com,CMD8251_SBRK) #define com_send_break_off(com) \ pc98_i8251_clear_cmd(com,CMD8251_SBRK) static struct speedtab pc98speedtab[] = { /* internal RS232C interface */ 0, 0, 50, 50, 75, 75, 150, 150, 200, 200, 300, 300, 600, 600, 1200, 1200, 2400, 2400, 4800, 4800, 9600, 9600, 19200, 19200, 38400, 38400, 51200, 51200, 76800, 76800, 20800, 20800, 31200, 31200, 41600, 41600, 62400, 62400, -1, -1 }; static struct speedtab pc98fast_speedtab[] = { 9600, 0x80 | COMBRD(9600), 19200, 0x80 | COMBRD(19200), 38400, 0x80 | COMBRD(38400), 57600, 0x80 | COMBRD(57600), 115200, 0x80 | COMBRD(115200), -1, -1 }; static struct speedtab comspeedtab_pio9032b[] = { 300, 6, 600, 5, 1200, 4, 2400, 3, 4800, 2, 9600, 1, 19200, 0, 38400, 7, -1, -1 }; static struct speedtab comspeedtab_b98_01[] = { 75, 11, 150, 10, 300, 9, 600, 8, 1200, 7, 2400, 6, 4800, 5, 9600, 4, 19200, 3, 38400, 2, 76800, 1, 153600, 0, -1, -1 }; static struct speedtab comspeedtab_mc16550[] = { 300, 1536, 600, 768, 1200, 384, 2400, 192, 4800, 96, 9600, 48, 19200, 24, 38400, 12, 57600, 8, 115200, 4, 153600, 3, 230400, 2, 460800, 1, -1, -1 }; static struct speedtab comspeedtab_rsb384[] = { 300, 3840, 600, 1920, 1200, 960, 2400, 480, 4800, 240, 9600, 120, 19200, 60, 38400, 30, 57600, 20, 115200, 10, 128000, 9, 144000, 8, 192000, 6, 230400, 5, 288000, 4, 384000, 3, 576000, 2, 1152000, 1, -1, -1 }; static struct speedtab comspeedtab_rsa[] = { { 0, 0 }, { 50, COMBRD_RSA(50) }, { 75, COMBRD_RSA(75) }, { 110, COMBRD_RSA(110) }, { 134, COMBRD_RSA(134) }, { 150, COMBRD_RSA(150) }, { 200, COMBRD_RSA(200) }, { 300, COMBRD_RSA(300) }, { 600, COMBRD_RSA(600) }, { 1200, COMBRD_RSA(1200) }, { 1800, COMBRD_RSA(1800) }, { 2400, COMBRD_RSA(2400) }, { 4800, COMBRD_RSA(4800) }, { 9600, COMBRD_RSA(9600) }, { 19200, COMBRD_RSA(19200) }, { 38400, COMBRD_RSA(38400) }, { 57600, COMBRD_RSA(57600) }, { 115200, COMBRD_RSA(115200) }, { 230400, COMBRD_RSA(230400) }, { 460800, COMBRD_RSA(460800) }, { 921600, COMBRD_RSA(921600) }, { -1, -1 } }; #endif /* PC98 */ static struct speedtab comspeedtab[] = { { 0, 0 }, { 50, COMBRD(50) }, { 75, COMBRD(75) }, { 110, COMBRD(110) }, { 134, COMBRD(134) }, { 150, COMBRD(150) }, { 200, COMBRD(200) }, { 300, COMBRD(300) }, { 600, COMBRD(600) }, { 1200, COMBRD(1200) }, { 1800, COMBRD(1800) }, { 2400, COMBRD(2400) }, { 4800, COMBRD(4800) }, { 9600, COMBRD(9600) }, { 19200, COMBRD(19200) }, { 38400, COMBRD(38400) }, { 57600, COMBRD(57600) }, { 115200, COMBRD(115200) }, { -1, -1 } }; #ifdef PC98 struct { char *name; short port_table[7]; short irr_mask; struct speedtab *speedtab; short check_irq; } if_8251_type[] = { /* COM_IF_INTERNAL */ { " (internal)", {0x30, 0x32, 0x32, 0x33, 0x35, -1, -1}, -1, pc98speedtab, 1 }, /* COM_IF_PC9861K_1 */ { " (PC9861K)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, -1, -1}, 3, NULL, 1 }, /* COM_IF_PC9861K_2 */ { " (PC9861K)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, -1, -1}, 3, NULL, 1 }, /* COM_IF_IND_SS_1 */ { " (IND-SS)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xb3, -1}, 3, comspeedtab_mc16550, 1 }, /* COM_IF_IND_SS_2 */ { " (IND-SS)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xbb, -1}, 3, comspeedtab_mc16550, 1 }, /* COM_IF_PIO9032B_1 */ { " (PIO9032B)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xb8, -1}, 7, comspeedtab_pio9032b, 1 }, /* COM_IF_PIO9032B_2 */ { " (PIO9032B)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xba, -1}, 7, comspeedtab_pio9032b, 1 }, /* COM_IF_B98_01_1 */ { " (B98-01)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xd1, 0xd3}, 7, comspeedtab_b98_01, 0 }, /* COM_IF_B98_01_2 */ { " (B98-01)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xd5, 0xd7}, 7, comspeedtab_b98_01, 0 }, }; #define PC98SIO_data_port(type) (if_8251_type[type].port_table[0]) #define PC98SIO_cmd_port(type) (if_8251_type[type].port_table[1]) #define PC98SIO_sts_port(type) (if_8251_type[type].port_table[2]) #define PC98SIO_in_modem_port(type) (if_8251_type[type].port_table[3]) #define PC98SIO_intr_ctrl_port(type) (if_8251_type[type].port_table[4]) #define PC98SIO_baud_rate_port(type) (if_8251_type[type].port_table[5]) #define PC98SIO_func_port(type) (if_8251_type[type].port_table[6]) struct { char *name; short irr_read; short irr_write; short port_shift; short io_size; struct speedtab *speedtab; } if_16550a_type[] = { /* COM_IF_RSA98 */ { " (RSA-98)", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_NS16550 */ { "", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_SECOND_CCU */ { "", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_MC16550II */ { " (MC16550II)", -1, 0x1000, 8, 1, comspeedtab_mc16550 }, /* COM_IF_MCRS98 */ { " (MC-RS98)", -1, 0x1000, 8, 1, comspeedtab_mc16550 }, /* COM_IF_RSB3000 */ { " (RSB-3000)", 0xbf, -1, 1, 1, comspeedtab_rsb384 }, /* COM_IF_RSB384 */ { " (RSB-384)", 0xbf, -1, 1, 1, comspeedtab_rsb384 }, /* COM_IF_MODEM_CARD */ { "", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_RSA98III */ { " (RSA-98III)", -1, -1, 0, 16, comspeedtab_rsa }, /* COM_IF_ESP98 */ { " (ESP98)", -1, -1, 1, 1, comspeedtab_mc16550 }, }; #endif /* PC98 */ #ifdef COM_ESP #ifdef PC98 /* XXX configure this properly. */ static Port_t likely_com_ports[] = { 0, 0xb0, 0xb1, 0 }; static Port_t likely_esp_ports[] = { 0xc0d0, 0 }; #define ESP98_CMD1 (ESP_CMD1 * 0x100) #define ESP98_CMD2 (ESP_CMD2 * 0x100) #define ESP98_STATUS1 (ESP_STATUS1 * 0x100) #define ESP98_STATUS2 (ESP_STATUS2 * 0x100) #else /* PC98 */ /* XXX configure this properly. */ static Port_t likely_com_ports[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, }; static Port_t likely_esp_ports[] = { 0x140, 0x180, 0x280, 0 }; #endif /* PC98 */ #endif /* * handle sysctl read/write requests for console speed * * In addition to setting comdefaultrate for I/O through /dev/console, * also set the initial and lock values for the /dev/ttyXX device * if there is one associated with the console. Finally, if the /dev/tty * device has already been open, change the speed on the open running port * itself. */ static int sysctl_machdep_comdefaultrate SYSCTL_HANDLER_ARGS { int error, s; speed_t newspeed; struct com_s *com; struct tty *tp; newspeed = comdefaultrate; error = sysctl_handle_opaque(oidp, &newspeed, sizeof newspeed, req); if (error || !req->newptr) return (error); comdefaultrate = newspeed; if (comconsole < 0) /* serial console not selected? */ return (0); com = com_addr(comconsole); if (!com) return (ENXIO); /* * set the initial and lock rates for /dev/ttydXX and /dev/cuaXX * (note, the lock rates really are boolean -- if non-zero, disallow * speed changes) */ com->it_in.c_ispeed = com->it_in.c_ospeed = com->lt_in.c_ispeed = com->lt_in.c_ospeed = com->it_out.c_ispeed = com->it_out.c_ospeed = com->lt_out.c_ispeed = com->lt_out.c_ospeed = comdefaultrate; /* * if we're open, change the running rate too */ tp = com->tp; if (tp && (tp->t_state & TS_ISOPEN)) { tp->t_termios.c_ispeed = tp->t_termios.c_ospeed = comdefaultrate; s = spltty(); error = comparam(tp, &tp->t_termios); splx(s); } return error; } SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW, 0, 0, sysctl_machdep_comdefaultrate, "I", ""); #if NCARD > 0 /* * PC-Card (PCMCIA) specific code. */ static int sioinit __P((struct pccard_devinfo *)); static void siounload __P((struct pccard_devinfo *)); static int card_intr __P((struct pccard_devinfo *)); static struct pccard_device sio_info = { driver_name, sioinit, siounload, card_intr, 0, /* Attributes - presently unused */ &tty_imask /* Interrupt mask for device */ /* XXX - Should this also include net_imask? */ }; DATA_SET(pccarddrv_set, sio_info); /* * Initialize the device - called from Slot manager. */ int sioinit(struct pccard_devinfo *devi) { /* validate unit number. */ if (devi->isahd.id_unit >= (NSIOTOT)) return(ENODEV); /* Make sure it isn't already probed. */ if (com_addr(devi->isahd.id_unit)) return(EBUSY); /* It's already probed as serial by Upper */ devi->isahd.id_flags |= COM_C_NOPROBE; /* * Probe the device. If a value is returned, the * device was found at the location. */ if (sioprobe(&devi->isahd) == 0) return(ENXIO); if (sioattach(&devi->isahd) == 0) return(ENXIO); return(0); } /* * siounload - unload the driver and clear the table. * XXX TODO: * This is usually called when the card is ejected, but * can be caused by a modunload of a controller driver. * The idea is to reset the driver's view of the device * and ensure that any driver entry points such as * read and write do not hang. */ static void siounload(struct pccard_devinfo *devi) { struct com_s *com; if (!devi) { printf("NULL devi in siounload\n"); return; } com = com_addr(devi->isahd.id_unit); if (!com) { printf("NULL com in siounload\n"); return; } if (!com->iobase) { printf("sio%d already unloaded!\n",devi->isahd.id_unit); return; } if (com->tp && (com->tp->t_state & TS_ISOPEN)) { com->gone = 1; printf("sio%d: unload\n", devi->isahd.id_unit); com->tp->t_gen++; ttyclose(com->tp); ttwakeup(com->tp); ttwwakeup(com->tp); } else { com_addr(com->unit) = NULL; #ifdef PC98 bzero(com->ibuf1, com->CE_INPUT_OFFSET * 6); #endif bzero(com, sizeof *com); free(com,M_TTYS); printf("sio%d: unload,gone\n", devi->isahd.id_unit); } } /* * card_intr - Shared interrupt called from * front end of PC-Card handler. */ static int card_intr(struct pccard_devinfo *devi) { struct com_s *com; COM_LOCK(); com = com_addr(devi->isahd.id_unit); if (com && !com->gone) siointr1(com_addr(devi->isahd.id_unit)); COM_UNLOCK(); return(1); } #endif /* NCARD > 0 */ static int sioprobe(dev) struct isa_device *dev; { static bool_t already_init; bool_t failures[10]; int fn; struct isa_device *idev; Port_t iobase; intrmask_t irqmap[4]; intrmask_t irqs; u_char mcr_image; int result; struct isa_device *xdev; #ifdef PC98 int irqout=0; int ret = 0; int tmp; int port_shift = 0; struct siodev iod; Port_t rsabase = NULL; #endif if (!already_init) { /* * Turn off MCR_IENABLE for all likely serial ports. An unused * port with its MCR_IENABLE gate open will inhibit interrupts * from any used port that shares the interrupt vector. * XXX the gate enable is elsewhere for some multiports. */ for (xdev = isa_devtab_tty; xdev->id_driver != NULL; xdev++) #ifdef PC98 if (xdev->id_driver == &siodriver && xdev->id_enabled) { tmp = (xdev->id_flags >> 24) & 0xff; if (IS_8251(tmp)) outb((xdev->id_iobase & 0xff00) | PC98SIO_cmd_port(tmp & 0x0f), 0xf2); else if (tmp == COM_IF_RSA98III) { rsabase = xdev->id_iobase & 0xfff0; #if 0 if (rsabase != xdev->id_iobase) return(0); #endif outb(xdev->id_iobase + 8 + (com_mcr << if_16550a_type[tmp & 0x0f].port_shift), 0); } else outb(xdev->id_iobase + (com_mcr << if_16550a_type[tmp & 0x0f].port_shift), 0); } #else if (xdev->id_driver == &siodriver && xdev->id_enabled) outb(xdev->id_iobase + com_mcr, 0); #endif already_init = TRUE; } if (COM_LLCONSOLE(dev)) { printf("sio%d: reserved for low-level i/o\n", dev->id_unit); return (0); } #ifdef PC98 DELAY(10); /* * If the port is i8251 UART (internal, B98_01) */ if (pc98_check_if_type(dev, &iod) == -1) return 0; if (iod.irq > 0) dev->id_irq = 1 << iod.irq; if (IS_8251(iod.if_type)) { outb(iod.cmd, 0); DELAY(10); outb(iod.cmd, 0); DELAY(10); outb(iod.cmd, 0); DELAY(10); outb(iod.cmd, CMD8251_RESET); DELAY(1000); /* for a while...*/ outb(iod.cmd, 0xf2); /* MODE (dummy) */ DELAY(10); outb(iod.cmd, 0x01); /* CMD (dummy) */ DELAY(1000); /* for a while...*/ if (( inb(iod.sts) & STS8251_TxEMP ) == 0 ) { ret = 0; } if (if_8251_type[iod.if_type & 0x0f].check_irq) { COM_INT_DISABLE tmp = ( inb( iod.ctrl ) & ~(IEN_Rx|IEN_TxEMP|IEN_Tx)); outb( iod.ctrl, tmp|IEN_TxEMP ); DELAY(10); ret = isa_irq_pending() ? 4 : 0; outb( iod.ctrl, tmp ); COM_INT_ENABLE } else { /* * B98_01 doesn't activate TxEMP interrupt line * when being reset, so we can't check irq pending. */ ret = 4; } if (epson_machine_id==0x20) { /* XXX */ ret = 4; } return ret; } #endif /* PC98 */ /* * If the device is on a multiport card and has an AST/4 * compatible interrupt control register, initialize this * register and prepare to leave MCR_IENABLE clear in the mcr. * Otherwise, prepare to set MCR_IENABLE in the mcr. * Point idev to the device struct giving the correct id_irq. * This is the struct for the master device if there is one. */ idev = dev; mcr_image = MCR_IENABLE; #ifdef PC98 if (iod.if_type == COM_IF_RSA98III) { mcr_image = 0; rsabase = idev->id_iobase & 0xfff0; if (rsabase != idev->id_iobase) return(0); outb(rsabase + rsa_msr, 0x04); outb(rsabase + rsa_frr, 0x00); if ((inb(rsabase + rsa_srr) & 0x36) != 0x36) return (0); outb(rsabase + rsa_ier, 0x00); outb(rsabase + rsa_frr, 0x00); outb(rsabase + rsa_tivsr, 0x00); outb(rsabase + rsa_tcr, 0x00); } #endif /* PC98 */ #ifdef COM_MULTIPORT if (COM_ISMULTIPORT(dev)) { idev = find_isadev(isa_devtab_tty, &siodriver, COM_MPMASTER(dev)); if (idev == NULL) { printf("sio%d: master device %d not configured\n", dev->id_unit, COM_MPMASTER(dev)); dev->id_irq = 0; idev = dev; } #ifndef PC98 if (!COM_NOTAST4(dev)) { outb(idev->id_iobase + com_scr, idev->id_irq ? 0x80 : 0); mcr_image = 0; } #endif /* !PC98 */ } #endif /* COM_MULTIPORT */ if (idev->id_irq == 0) mcr_image = 0; #ifdef PC98 tmp = if_16550a_type[iod.if_type & 0x0f].irr_write; if (tmp != -1) { /* MC16550II */ switch (idev->id_irq) { case IRQ3: irqout = 4; break; case IRQ5: irqout = 5; break; case IRQ6: irqout = 6; break; case IRQ12: irqout = 7; break; default: printf("sio%d: irq configuration error\n", dev->id_unit); return (0); } outb((dev->id_iobase & 0x00ff) | tmp, irqout); } port_shift = if_16550a_type[iod.if_type & 0x0f].port_shift; #endif bzero(failures, sizeof failures); #ifdef PC98 if (iod.if_type == COM_IF_RSA98III) iobase = dev->id_iobase + 8; else #endif iobase = dev->id_iobase; /* * We don't want to get actual interrupts, just masked ones. * Interrupts from this line should already be masked in the ICU, * but mask them in the processor as well in case there are some * (misconfigured) shared interrupts. */ disable_intr(); /* EXTRA DELAY? */ /* * Initialize the speed and the word size and wait long enough to * drain the maximum of 16 bytes of junk in device output queues. * The speed is undefined after a master reset and must be set * before relying on anything related to output. There may be * junk after a (very fast) soft reboot and (apparently) after * master reset. * XXX what about the UART bug avoided by waiting in comparam()? * We don't want to to wait long enough to drain at 2 bps. */ if (iobase == siocniobase) DELAY((16 + 1) * 1000000 / (comdefaultrate / 10)); else { #ifdef PC98 tmp = ttspeedtab(SIO_TEST_SPEED, if_16550a_type[iod.if_type & 0x0f].speedtab); outb(iobase + (com_cfcr << port_shift), CFCR_DLAB|CFCR_8BITS); outb(iobase + (com_dlbl << port_shift), tmp & 0xff); outb(iobase + (com_dlbh << port_shift), (tmp >> 8) & 0xff); outb(iobase + (com_cfcr << port_shift), CFCR_8BITS); #else outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS); outb(iobase + com_dlbl, COMBRD(SIO_TEST_SPEED) & 0xff); outb(iobase + com_dlbh, (u_int) COMBRD(SIO_TEST_SPEED) >> 8); outb(iobase + com_cfcr, CFCR_8BITS); #endif DELAY((16 + 1) * 1000000 / (SIO_TEST_SPEED / 10)); } /* * Enable the interrupt gate and disable device interupts. This * should leave the device driving the interrupt line low and * guarantee an edge trigger if an interrupt can be generated. */ /* EXTRA DELAY? */ #ifdef PC98 outb(iobase + (com_mcr << port_shift), mcr_image); outb(iobase + (com_ier << port_shift), 0); #else outb(iobase + com_mcr, mcr_image); outb(iobase + com_ier, 0); #endif DELAY(1000); /* XXX */ irqmap[0] = isa_irq_pending(); /* * Attempt to set loopback mode so that we can send a null byte * without annoying any external device. */ /* EXTRA DELAY? */ #ifdef PC98 outb(iobase + (com_mcr << port_shift), mcr_image | MCR_LOOPBACK); #else outb(iobase + com_mcr, mcr_image | MCR_LOOPBACK); #endif /* * Attempt to generate an output interrupt. On 8250's, setting * IER_ETXRDY generates an interrupt independent of the current * setting and independent of whether the THR is empty. On 16450's, * setting IER_ETXRDY generates an interrupt independent of the * current setting. On 16550A's, setting IER_ETXRDY only * generates an interrupt when IER_ETXRDY is not already set. */ #ifdef PC98 outb(iobase + (com_ier << port_shift), IER_ETXRDY); if (iod.if_type == COM_IF_RSA98III) { outb(rsabase + rsa_ier, 0x04); } #else outb(iobase + com_ier, IER_ETXRDY); #endif /* PC98 */ /* * On some 16x50 incompatibles, setting IER_ETXRDY doesn't generate * an interrupt. They'd better generate one for actually doing * output. Loopback may be broken on the same incompatibles but * it's unlikely to do more than allow the null byte out. */ #ifdef PC98 outb(iobase + (com_data << port_shift), 0); #else outb(iobase + com_data, 0); #endif DELAY((1 + 2) * 1000000 / (SIO_TEST_SPEED / 10)); /* * Turn off loopback mode so that the interrupt gate works again * (MCR_IENABLE was hidden). This should leave the device driving * an interrupt line high. It doesn't matter if the interrupt * line oscillates while we are not looking at it, since interrupts * are disabled. */ /* EXTRA DELAY? */ #ifdef PC98 outb(iobase + (com_mcr << port_shift), mcr_image); #else outb(iobase + com_mcr, mcr_image); #endif /* PC98 */ /* * It's a definitly Serial PCMCIA(16550A), but still be required * for IIR_TXRDY implementation ( Palido 321s, DC-1S... ) */ if ( COM_NOPROBE(dev) ) { /* Reading IIR register twice */ for ( fn = 0; fn < 2; fn ++ ) { DELAY(10000); #ifdef PC98 failures[6] = inb(iobase + (com_iir << port_shift)); #else failures[6] = inb(iobase + com_iir); #endif } /* Check IIR_TXRDY clear ? */ #ifdef PC98 result = if_16550a_type[iod.if_type & 0x0f].io_size; #else result = IO_COMSIZE; #endif if ( failures[6] & IIR_TXRDY ) { /* Nop, Double check with clearing IER */ #ifdef PC98 outb(iobase + (com_ier << port_shift), 0); if (inb(iobase + (com_iir << port_shift)) & IIR_NOPEND) { #else outb(iobase + com_ier, 0); if ( inb(iobase + com_iir) & IIR_NOPEND ) { #endif /* Ok. we're familia this gang */ dev->id_flags |= COM_C_IIR_TXRDYBUG; /* Set IIR_TXRDYBUG */ } else { /* Unknow, Just omit this chip.. XXX*/ result = 0; } } else { /* OK. this is well-known guys */ dev->id_flags &= ~COM_C_IIR_TXRDYBUG; /*Clear IIR_TXRDYBUG*/ } #ifdef PC98 outb(iobase + (com_cfcr << port_shift), CFCR_8BITS); #else outb(iobase + com_cfcr, CFCR_8BITS); #endif enable_intr(); return (iobase == siocniobase ? IO_COMSIZE : result); } /* * Check that * o the CFCR, IER and MCR in UART hold the values written to them * (the values happen to be all distinct - this is good for * avoiding false positive tests from bus echoes). * o an output interrupt is generated and its vector is correct. * o the interrupt goes away when the IIR in the UART is read. */ /* EXTRA DELAY? */ #ifdef PC98 failures[0] = inb(iobase + (com_cfcr << port_shift)) - CFCR_8BITS; failures[1] = inb(iobase + (com_ier << port_shift)) - IER_ETXRDY; failures[2] = inb(iobase + (com_mcr << port_shift)) - mcr_image; #else failures[0] = inb(iobase + com_cfcr) - CFCR_8BITS; failures[1] = inb(iobase + com_ier) - IER_ETXRDY; failures[2] = inb(iobase + com_mcr) - mcr_image; #endif DELAY(10000); /* Some internal modems need this time */ irqmap[1] = isa_irq_pending(); #ifdef PC98 failures[4] = (inb(iobase + (com_iir << port_shift)) & IIR_IMASK) - IIR_TXRDY; if (iod.if_type == COM_IF_RSA98III) { inb(rsabase + rsa_srr); } #else failures[4] = (inb(iobase + com_iir) & IIR_IMASK) - IIR_TXRDY; #endif DELAY(1000); /* XXX */ irqmap[2] = isa_irq_pending(); #ifdef PC98 failures[6] = (inb(iobase + (com_iir << port_shift)) & IIR_IMASK) - IIR_NOPEND; if (iod.if_type == COM_IF_RSA98III) { inb(rsabase + rsa_srr); } #else failures[6] = (inb(iobase + com_iir) & IIR_IMASK) - IIR_NOPEND; #endif /* * Turn off all device interrupts and check that they go off properly. * Leave MCR_IENABLE alone. For ports without a master port, it gates * the OUT2 output of the UART to * the ICU input. Closing the gate would give a floating ICU input * (unless there is another device driving at) and spurious interrupts. * (On the system that this was first tested on, the input floats high * and gives a (masked) interrupt as soon as the gate is closed.) */ #ifdef PC98 outb(iobase + (com_ier << port_shift), 0); outb(iobase + (com_cfcr << port_shift), CFCR_8BITS); failures[7] = inb(iobase + (com_ier << port_shift)); if (iod.if_type == COM_IF_RSA98III) { outb(rsabase + rsa_ier, 0x00); } #else outb(iobase + com_ier, 0); outb(iobase + com_cfcr, CFCR_8BITS); /* dummy to avoid bus echo */ failures[7] = inb(iobase + com_ier); #endif DELAY(1000); /* XXX */ irqmap[3] = isa_irq_pending(); #ifdef PC98 failures[9] = (inb(iobase + (com_iir << port_shift)) & IIR_IMASK) - IIR_NOPEND; if (iod.if_type == COM_IF_RSA98III) { inb(rsabase + rsa_srr); outb(rsabase + rsa_frr, 0x00); } #else failures[9] = (inb(iobase + com_iir) & IIR_IMASK) - IIR_NOPEND; #endif enable_intr(); irqs = irqmap[1] & ~irqmap[0]; if (idev->id_irq != 0 && (idev->id_irq & irqs) == 0) printf( "sio%d: configured irq %d not in bitmap of probed irqs %#x\n", dev->id_unit, ffs(idev->id_irq) - 1, irqs); if (bootverbose) printf("sio%d: irq maps: %#x %#x %#x %#x\n", dev->id_unit, irqmap[0], irqmap[1], irqmap[2], irqmap[3]); #ifdef PC98 result = if_16550a_type[iod.if_type & 0x0f].io_size; #else result = IO_COMSIZE; #endif for (fn = 0; fn < sizeof failures; ++fn) if (failures[fn]) { #ifdef PC98 outb(iobase + (com_mcr << port_shift), 0); #else outb(iobase + com_mcr, 0); #endif result = 0; if (bootverbose) { printf("sio%d: probe failed test(s):", dev->id_unit); for (fn = 0; fn < sizeof failures; ++fn) if (failures[fn]) printf(" %d", fn); printf("\n"); } break; } return (iobase == siocniobase ? IO_COMSIZE : result); } #ifdef COM_ESP static int espattach(isdp, com, esp_port) struct isa_device *isdp; struct com_s *com; Port_t esp_port; { u_char dips; u_char val; /* * Check the ESP-specific I/O port to see if we're an ESP * card. If not, return failure immediately. */ if ((inb(esp_port) & 0xf3) == 0) { printf(" port 0x%x is not an ESP board?\n", esp_port); return (0); } /* * We've got something that claims to be a Hayes ESP card. * Let's hope so. */ /* Get the dip-switch configuration */ #ifdef PC98 outb(esp_port + ESP98_CMD1, ESP_GETDIPS); dips = inb(esp_port + ESP98_STATUS1); #else outb(esp_port + ESP_CMD1, ESP_GETDIPS); dips = inb(esp_port + ESP_STATUS1); #endif /* * Bits 0,1 of dips say which COM port we are. */ #ifdef PC98 if ((com->iobase & 0xff) == likely_com_ports[dips & 0x03]) #else if (com->iobase == likely_com_ports[dips & 0x03]) #endif printf(" : ESP"); else { printf(" esp_port has com %d\n", dips & 0x03); return (0); } /* * Check for ESP version 2.0 or later: bits 4,5,6 = 010. */ #ifdef PC98 outb(esp_port + ESP98_CMD1, ESP_GETTEST); val = inb(esp_port + ESP98_STATUS1); /* clear reg 1 */ val = inb(esp_port + ESP98_STATUS2); #else outb(esp_port + ESP_CMD1, ESP_GETTEST); val = inb(esp_port + ESP_STATUS1); /* clear reg 1 */ val = inb(esp_port + ESP_STATUS2); #endif if ((val & 0x70) < 0x20) { printf("-old (%o)", val & 0x70); return (0); } /* * Check for ability to emulate 16550: bit 7 == 1 */ if ((dips & 0x80) == 0) { printf(" slave"); return (0); } /* * Okay, we seem to be a Hayes ESP card. Whee. */ com->esp = TRUE; com->esp_port = esp_port; return (1); } #endif /* COM_ESP */ static int sioattach(isdp) struct isa_device *isdp; { struct com_s *com; dev_t dev; #ifdef COM_ESP Port_t *espp; #endif Port_t iobase; int s; int unit; #ifdef PC98 int port_shift = 0; u_long ibufsize; #endif isdp->id_ointr = siointr; isdp->id_ri_flags |= RI_FAST; #ifdef PC98 if (((isdp->id_flags >> 24) & 0xff) == COM_IF_RSA98III) iobase = isdp->id_iobase + 8; else #endif iobase = isdp->id_iobase; unit = isdp->id_unit; #ifndef PC98 com = malloc(sizeof *com, M_TTYS, M_NOWAIT); #else ibufsize = RS_IBUFSIZE; if (((isdp->id_flags >> 24) & 0xff) == COM_IF_RSA98III) ibufsize = 2048; com = malloc((sizeof *com) + ibufsize * 6, M_TTYS, M_NOWAIT); #endif if (com == NULL) return (0); /* * sioprobe() has initialized the device registers as follows: * o cfcr = CFCR_8BITS. * It is most important that CFCR_DLAB is off, so that the * data port is not hidden when we enable interrupts. * o ier = 0. * Interrupts are only enabled when the line is open. * o mcr = MCR_IENABLE, or 0 if the port has AST/4 compatible * interrupt control register or the config specifies no irq. * Keeping MCR_DTR and MCR_RTS off might stop the external * device from sending before we are ready. */ bzero(com, sizeof *com); #ifdef PC98 com->CE_INPUT_OFFSET = ibufsize; com->ibuf1 = (u_char *)com + (sizeof *com); com->ibuf2 = com->ibuf1 + (ibufsize * 2); com->obuf1 = com->ibuf2 + (ibufsize * 2); com->obuf2 = com->obuf1 + ibufsize; bzero(com->ibuf1, ibufsize * 6); #endif com->unit = unit; com->cfcr_image = CFCR_8BITS; com->dtr_wait = 3 * hz; com->loses_outints = COM_LOSESOUTINTS(isdp) != 0; com->no_irq = isdp->id_irq == 0; com->tx_fifo_size = 1; com->iptr = com->ibuf = com->ibuf1; #ifndef PC98 com->ibufend = com->ibuf1 + RS_IBUFSIZE; com->ihighwater = com->ibuf1 + RS_IHIGHWATER; #else com->ibufend = com->ibuf1 + com->CE_INPUT_OFFSET; com->ihighwater = com->ibuf1 + (3 * com->CE_INPUT_OFFSET / 4); #endif com->obufs[0].l_head = com->obuf1; com->obufs[1].l_head = com->obuf2; com->iobase = iobase; #ifdef PC98 if (pc98_set_ioport(com, isdp->id_flags) == -1) { com->pc98_if_type = (isdp->id_flags >> 24) & 0xff; port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; com->data_port = iobase + (com_data << port_shift); com->int_id_port = iobase + (com_iir << port_shift); com->modem_ctl_port = iobase + (com_mcr << port_shift); com->mcr_image = inb(com->modem_ctl_port); com->line_status_port = iobase + (com_lsr << port_shift); com->modem_status_port = iobase + (com_msr << port_shift); com->intr_ctl_port = iobase + (com_ier << port_shift); } #else /* not PC98 */ com->data_port = iobase + com_data; com->int_id_port = iobase + com_iir; com->modem_ctl_port = iobase + com_mcr; com->mcr_image = inb(com->modem_ctl_port); com->line_status_port = iobase + com_lsr; com->modem_status_port = iobase + com_msr; com->intr_ctl_port = iobase + com_ier; #endif /* * We don't use all the flags from since they * are only relevant for logins. It's important to have echo off * initially so that the line doesn't start blathering before the * echo flag can be turned off. */ com->it_in.c_iflag = 0; com->it_in.c_oflag = 0; com->it_in.c_cflag = TTYDEF_CFLAG; com->it_in.c_lflag = 0; if (unit == comconsole) { #ifdef PC98 if (IS_8251(com->pc98_if_type)) DELAY(100000); #endif com->it_in.c_iflag = TTYDEF_IFLAG; com->it_in.c_oflag = TTYDEF_OFLAG; com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL; com->it_in.c_lflag = TTYDEF_LFLAG; com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL; com->lt_out.c_ispeed = com->lt_out.c_ospeed = com->lt_in.c_ispeed = com->lt_in.c_ospeed = com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate; } else com->it_in.c_ispeed = com->it_in.c_ospeed = TTYDEF_SPEED; termioschars(&com->it_in); com->it_out = com->it_in; /* attempt to determine UART type */ printf("sio%d: type", unit); #ifndef PC98 #ifdef COM_MULTIPORT if (!COM_ISMULTIPORT(isdp) && !COM_IIR_TXRDYBUG(isdp)) #else if (!COM_IIR_TXRDYBUG(isdp)) #endif { u_char scr; u_char scr1; u_char scr2; scr = inb(iobase + com_scr); outb(iobase + com_scr, 0xa5); scr1 = inb(iobase + com_scr); outb(iobase + com_scr, 0x5a); scr2 = inb(iobase + com_scr); outb(iobase + com_scr, scr); if (scr1 != 0xa5 || scr2 != 0x5a) { printf(" 8250"); goto determined_type; } } #endif /* !PC98 */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) { com_int_TxRx_disable( com ); com_cflag_and_speed_set( com, com->it_in.c_cflag, comdefaultrate ); com_tiocm_bic( com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE ); com_send_break_off( com ); printf(" 8251%s", if_8251_type[com->pc98_if_type & 0x0f].name); } else { outb(iobase + (com_fifo << port_shift), FIFO_ENABLE | FIFO_RX_HIGH); #else outb(iobase + com_fifo, FIFO_ENABLE | FIFO_RX_HIGH); #endif /* PC98 */ DELAY(100); com->st16650a = 0; switch (inb(com->int_id_port) & IIR_FIFO_MASK) { case FIFO_RX_LOW: printf(" 16450"); break; case FIFO_RX_MEDL: printf(" 16450?"); break; case FIFO_RX_MEDH: printf(" 16550?"); break; case FIFO_RX_HIGH: if (COM_NOFIFO(isdp)) { printf(" 16550A fifo disabled"); } else { com->hasfifo = TRUE; #ifdef PC98 com->tx_fifo_size = 0; /* XXX flag conflicts. */ printf(" 16550A"); #else if (COM_ST16650A(isdp)) { com->st16650a = 1; com->tx_fifo_size = 32; printf(" ST16650A"); } else { com->tx_fifo_size = COM_FIFOSIZE(isdp); printf(" 16550A"); } #endif } #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { com->tx_fifo_size = 2048; com->rsabase = isdp->id_iobase; outb(com->rsabase + rsa_ier, 0x00); outb(com->rsabase + rsa_frr, 0x00); } #endif #ifdef COM_ESP #ifdef PC98 if (com->pc98_if_type == COM_IF_ESP98) #endif for (espp = likely_esp_ports; *espp != 0; espp++) if (espattach(isdp, com, *espp)) { com->tx_fifo_size = 1024; break; } #endif if (!com->st16650a) { if (!com->tx_fifo_size) com->tx_fifo_size = 16; else printf(" lookalike with %d bytes FIFO", com->tx_fifo_size); } break; } #ifdef PC98 if (com->pc98_if_type == COM_IF_RSB3000) { /* Set RSB-2000/3000 Extended Buffer mode. */ u_char lcr; lcr = inb(iobase + (com_cfcr << port_shift)); outb(iobase + (com_cfcr << port_shift), lcr | CFCR_DLAB); outb(iobase + (com_emr << port_shift), EMR_EXBUFF | EMR_EFMODE); outb(iobase + (com_cfcr << port_shift), lcr); } #endif #ifdef COM_ESP if (com->esp) { /* * Set 16550 compatibility mode. * We don't use the ESP_MODE_SCALE bit to increase the * fifo trigger levels because we can't handle large * bursts of input. * XXX flow control should be set in comparam(), not here. */ #ifdef PC98 outb(com->esp_port + ESP98_CMD1, ESP_SETMODE); outb(com->esp_port + ESP98_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO); #else outb(com->esp_port + ESP_CMD1, ESP_SETMODE); outb(com->esp_port + ESP_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO); #endif /* Set RTS/CTS flow control. */ #ifdef PC98 outb(com->esp_port + ESP98_CMD1, ESP_SETFLOWTYPE); outb(com->esp_port + ESP98_CMD2, ESP_FLOW_RTS); outb(com->esp_port + ESP98_CMD2, ESP_FLOW_CTS); #else outb(com->esp_port + ESP_CMD1, ESP_SETFLOWTYPE); outb(com->esp_port + ESP_CMD2, ESP_FLOW_RTS); outb(com->esp_port + ESP_CMD2, ESP_FLOW_CTS); #endif /* Set flow-control levels. */ #ifdef PC98 outb(com->esp_port + ESP98_CMD1, ESP_SETRXFLOW); outb(com->esp_port + ESP98_CMD2, HIBYTE(768)); outb(com->esp_port + ESP98_CMD2, LOBYTE(768)); outb(com->esp_port + ESP98_CMD2, HIBYTE(512)); outb(com->esp_port + ESP98_CMD2, LOBYTE(512)); #else outb(com->esp_port + ESP_CMD1, ESP_SETRXFLOW); outb(com->esp_port + ESP_CMD2, HIBYTE(768)); outb(com->esp_port + ESP_CMD2, LOBYTE(768)); outb(com->esp_port + ESP_CMD2, HIBYTE(512)); outb(com->esp_port + ESP_CMD2, LOBYTE(512)); #endif #ifdef PC98 /* Set UART clock prescaler. */ outb(com->esp_port + ESP98_CMD1, ESP_SETCLOCK); outb(com->esp_port + ESP98_CMD2, 2); /* 4 times */ #endif } #endif /* COM_ESP */ #ifdef PC98 printf("%s", if_16550a_type[com->pc98_if_type & 0x0f].name); outb(iobase + (com_fifo << port_shift), 0); #else outb(iobase + com_fifo, 0); #endif determined_type: ; #ifdef COM_MULTIPORT if (COM_ISMULTIPORT(isdp)) { com->multiport = TRUE; printf(" (multiport"); if (unit == COM_MPMASTER(isdp)) printf(" master"); printf(")"); com->no_irq = find_isadev(isa_devtab_tty, &siodriver, COM_MPMASTER(isdp))->id_irq == 0; } #endif /* COM_MULTIPORT */ #ifdef PC98 } #endif if (unit == comconsole) printf(", console"); if ( COM_IIR_TXRDYBUG(isdp) ) printf(" with a bogus IIR_TXRDY register"); printf("\n"); s = spltty(); com_addr(unit) = com; splx(s); if (!sio_registered) { dev = makedev(CDEV_MAJOR, 0); cdevsw_add(&dev, &sio_cdevsw, NULL); register_swi(SWI_TTY, siopoll); sio_registered = TRUE; } #ifdef DEVFS com->devfs_token_ttyd = devfs_add_devswf(&sio_cdevsw, unit, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit); com->devfs_token_ttyi = devfs_add_devswf(&sio_cdevsw, unit | CONTROL_INIT_STATE, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit); com->devfs_token_ttyl = devfs_add_devswf(&sio_cdevsw, unit | CONTROL_LOCK_STATE, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit); com->devfs_token_cuaa = devfs_add_devswf(&sio_cdevsw, unit | CALLOUT_MASK, DV_CHR, UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit); com->devfs_token_cuai = devfs_add_devswf(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_INIT_STATE, DV_CHR, UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit); com->devfs_token_cual = devfs_add_devswf(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_LOCK_STATE, DV_CHR, UID_UUCP, GID_DIALER, 0660, "cuala%r", unit); #endif com->id_flags = isdp->id_flags; /* Heritate id_flags for later */ return (1); } static int sioopen(dev, flag, mode, p) dev_t dev; int flag; int mode; struct proc *p; { struct com_s *com; int error; Port_t iobase; int mynor; int s; struct tty *tp; int unit; #ifdef PC98 int port_shift = 0; #endif mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); if ((u_int) unit >= NSIOTOT || (com = com_addr(unit)) == NULL) return (ENXIO); if (com->gone) return (ENXIO); if (mynor & CONTROL_MASK) return (0); #if 0 /* XXX */ tp = com->tp = sio_tty[unit] = ttymalloc(sio_tty[unit]); #else tp = com->tp = &sio_tty[unit]; #endif s = spltty(); #ifdef PC98 if (!IS_8251(com->pc98_if_type)) port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; #endif /* * We jump to this label after all non-interrupted sleeps to pick * up any changes of the device state. */ open_top: while (com->state & CS_DTR_OFF) { error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "siodtr", 0); if (com_addr(unit) == NULL) return (ENXIO); if (error != 0 || com->gone) goto out; } if (tp->t_state & TS_ISOPEN) { /* * The device is open, so everything has been initialized. * Handle conflicts. */ if (mynor & CALLOUT_MASK) { if (!com->active_out) { error = EBUSY; goto out; } } else { if (com->active_out) { if (flag & O_NONBLOCK) { error = EBUSY; goto out; } error = tsleep(&com->active_out, TTIPRI | PCATCH, "siobi", 0); if (com_addr(unit) == NULL) return (ENXIO); if (error != 0 || com->gone) goto out; goto open_top; } } if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) { error = EBUSY; goto out; } } else { /* * The device isn't open, so there are no conflicts. * Initialize it. Initialization is done twice in many * cases: to preempt sleeping callin opens if we are * callout, and to complete a callin open after DCD rises. */ tp->t_oproc = comstart; tp->t_param = comparam; tp->t_dev = dev; tp->t_termios = mynor & CALLOUT_MASK ? com->it_out : com->it_in; #ifndef PC98 tp->t_ififosize = 2 * RS_IBUFSIZE; #else tp->t_ififosize = 2 * com->CE_INPUT_OFFSET; #endif tp->t_ispeedwat = (speed_t)-1; tp->t_ospeedwat = (speed_t)-1; #ifdef PC98 if (!IS_8251(com->pc98_if_type)) #endif (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET); com->poll = com->no_irq; com->poll_output = com->loses_outints; ++com->wopeners; error = comparam(tp, &tp->t_termios); --com->wopeners; if (error != 0) goto out; #ifdef PC98 if (IS_8251(com->pc98_if_type)) { com_tiocm_bis(com, TIOCM_DTR|TIOCM_RTS); pc98_msrint_start(dev); } #endif /* * XXX we should goto open_top if comparam() slept. */ iobase = com->iobase; if (com->hasfifo) { /* * (Re)enable and drain fifos. * * Certain SMC chips cause problems if the fifos * are enabled while input is ready. Turn off the * fifo if necessary to clear the input. We test * the input ready bit after enabling the fifos * since we've already enabled them in comparam() * and to handle races between enabling and fresh * input. */ while (TRUE) { #ifdef PC98 outb(iobase + (com_fifo << port_shift), FIFO_RCV_RST | FIFO_XMT_RST | com->fifo_image); if (com->pc98_if_type == COM_IF_RSA98III) outb(com->rsabase + rsa_frr , 0x00); #else outb(iobase + com_fifo, FIFO_RCV_RST | FIFO_XMT_RST | com->fifo_image); #endif /* * XXX the delays are for superstitious * historical reasons. It must be less than * the character time at the maximum * supported speed (87 usec at 115200 bps * 8N1). Otherwise we might loop endlessly * if data is streaming in. We used to use * delays of 100. That usually worked * because DELAY(100) used to usually delay * for about 85 usec instead of 100. */ DELAY(50); #ifndef PC98 if (!(inb(com->line_status_port) & LSR_RXRDY)) #else if (com->pc98_if_type == COM_IF_RSA98III ? !(inb(com->rsabase + rsa_srr) & 0x08) : !(inb(com->line_status_port) & LSR_RXRDY)) #endif break; #ifdef PC98 outb(iobase + (com_fifo << port_shift), 0); #else outb(iobase + com_fifo, 0); #endif DELAY(50); (void) inb(com->data_port); } } disable_intr(); #ifdef PC98 if (IS_8251(com->pc98_if_type)) { com_tiocm_bis(com, TIOCM_LE); com->pc98_prev_modem_status = pc98_get_modem_status(com); com_int_Rx_enable(com); } else { #endif (void) inb(com->line_status_port); (void) inb(com->data_port); com->prev_modem_status = com->last_modem_status = inb(com->modem_status_port); if (COM_IIR_TXRDYBUG(com)) { outb(com->intr_ctl_port, IER_ERXRDY | IER_ERLS | IER_EMSC); } else { outb(com->intr_ctl_port, IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); } #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { outb(com->rsabase + rsa_ier, 0x1d); outb(com->intr_ctl_port, IER_ERLS | IER_EMSC); } #endif #ifdef PC98 } #endif enable_intr(); /* * Handle initial DCD. Callout devices get a fake initial * DCD (trapdoor DCD). If we are callout, then any sleeping * callin opens get woken up and resume sleeping on "siobi" * instead of "siodcd". */ /* * XXX `mynor & CALLOUT_MASK' should be * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where * TRAPDOOR_CARRIER is the default initial state for callout * devices and SOFT_CARRIER is like CLOCAL except it hides * the true carrier. */ #ifdef PC98 if ((IS_8251(com->pc98_if_type) && (pc98_get_modem_status(com) & TIOCM_CAR)) || (!IS_8251(com->pc98_if_type) && (com->prev_modem_status & MSR_DCD)) || mynor & CALLOUT_MASK) #else if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK) #endif (*linesw[tp->t_line].l_modem)(tp, 1); } /* * Wait for DCD if necessary. */ if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) { ++com->wopeners; error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "siodcd", 0); if (com_addr(unit) == NULL) return (ENXIO); --com->wopeners; if (error != 0 || com->gone) goto out; goto open_top; } error = (*linesw[tp->t_line].l_open)(dev, tp); disc_optim(tp, &tp->t_termios, com); if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK) com->active_out = TRUE; siosettimeout(); out: splx(s); if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0) comhardclose(com); return (error); } static int sioclose(dev, flag, mode, p) dev_t dev; int flag; int mode; struct proc *p; { struct com_s *com; int mynor; int s; struct tty *tp; mynor = minor(dev); if (mynor & CONTROL_MASK) return (0); com = com_addr(MINOR_TO_UNIT(mynor)); tp = com->tp; s = spltty(); (*linesw[tp->t_line].l_close)(tp, flag); #ifdef PC98 com->modem_checking = 0; #endif disc_optim(tp, &tp->t_termios, com); siostop(tp, FREAD | FWRITE); comhardclose(com); ttyclose(tp); siosettimeout(); splx(s); if (com->gone) { printf("sio%d: gone\n", com->unit); s = spltty(); com_addr(com->unit) = 0; bzero(tp,sizeof *tp); bzero(com,sizeof *com); free(com,M_TTYS); splx(s); } return (0); } static void comhardclose(com) struct com_s *com; { Port_t iobase; int s; struct tty *tp; int unit; #ifdef PC98 int port_shift = 0; #endif unit = com->unit; iobase = com->iobase; s = spltty(); com->poll = FALSE; com->poll_output = FALSE; com->do_timestamp = FALSE; com->do_dcd_timestamp = FALSE; #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_send_break_off(com); else { port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; outb(iobase + (com_cfcr << port_shift), com->cfcr_image &= ~CFCR_SBREAK); } #else outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); #endif { #ifdef PC98 int tmp; if (IS_8251(com->pc98_if_type)) com_int_TxRx_disable(com); else outb(iobase + (com_ier << port_shift), 0); if (com->pc98_if_type == COM_IF_RSA98III) { outb(com->rsabase + rsa_ier, 0x00); } #else outb(iobase + com_ier, 0); #endif tp = com->tp; #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = pc98_get_modem_status(com) & TIOCM_CAR; else tmp = com->prev_modem_status & MSR_DCD; #endif if (tp->t_cflag & HUPCL /* * XXX we will miss any carrier drop between here and the * next open. Perhaps we should watch DCD even when the * port is closed; it is not sufficient to check it at * the next open because it might go up and down while * we're not watching. */ || !com->active_out #ifdef PC98 && !(tmp) #else && !(com->prev_modem_status & MSR_DCD) #endif && !(com->it_in.c_cflag & CLOCAL) || !(tp->t_state & TS_ISOPEN)) { #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE); else #endif (void)commctl(com, TIOCM_DTR, DMBIC); if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) { timeout(siodtrwakeup, com, com->dtr_wait); com->state |= CS_DTR_OFF; } } #ifdef PC98 else { if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_LE ); } #endif } if (com->hasfifo) { /* * Disable fifos so that they are off after controlled * reboots. Some BIOSes fail to detect 16550s when the * fifos are enabled. */ #ifdef PC98 outb(iobase + (com_fifo << port_shift), 0); #else outb(iobase + com_fifo, 0); #endif } com->active_out = FALSE; wakeup(&com->active_out); wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */ splx(s); } static int sioread(dev, uio, flag) dev_t dev; struct uio *uio; int flag; { int mynor; int unit; struct tty *tp; mynor = minor(dev); if (mynor & CONTROL_MASK) return (ENODEV); unit = MINOR_TO_UNIT(mynor); if (com_addr(unit)->gone) return (ENODEV); tp = com_addr(unit)->tp; return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); } static int siowrite(dev, uio, flag) dev_t dev; struct uio *uio; int flag; { int mynor; struct tty *tp; int unit; mynor = minor(dev); if (mynor & CONTROL_MASK) return (ENODEV); unit = MINOR_TO_UNIT(mynor); if (com_addr(unit)->gone) return (ENODEV); tp = com_addr(unit)->tp; /* * (XXX) We disallow virtual consoles if the physical console is * a serial port. This is in case there is a display attached that * is not the console. In that situation we don't need/want the X * server taking over the console. */ if (constty != NULL && unit == comconsole) constty = NULL; return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); } static void siobusycheck(chan) void *chan; { struct com_s *com; int s; com = (struct com_s *)chan; /* * Clear TS_BUSY if low-level output is complete. * spl locking is sufficient because siointr1() does not set CS_BUSY. * If siointr1() clears CS_BUSY after we look at it, then we'll get * called again. Reading the line status port outside of siointr1() * is safe because CS_BUSY is clear so there are no output interrupts * to lose. */ s = spltty(); if (com->state & CS_BUSY) com->extra_state &= ~CSE_BUSYCHECK; /* False alarm. */ #ifdef PC98 else if (IS_8251(com->pc98_if_type) && (inb(com->sts_port) & (STS8251_TxRDY | STS8251_TxEMP)) == (STS8251_TxRDY | STS8251_TxEMP) || (inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY)) == (LSR_TSRE | LSR_TXRDY)) { #else else if ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY)) == (LSR_TSRE | LSR_TXRDY)) { #endif com->tp->t_state &= ~TS_BUSY; ttwwakeup(com->tp); com->extra_state &= ~CSE_BUSYCHECK; } else timeout(siobusycheck, com, hz / 100); splx(s); } static void siodtrwakeup(chan) void *chan; { struct com_s *com; com = (struct com_s *)chan; com->state &= ~CS_DTR_OFF; wakeup(&com->dtr_wait); } static void siointr(unit) int unit; { #ifndef COM_MULTIPORT COM_LOCK(); siointr1(com_addr(unit)); COM_UNLOCK(); #else /* COM_MULTIPORT */ struct com_s *com; bool_t possibly_more_intrs; #ifdef PC98 u_char rsa_buf_status; #endif /* * Loop until there is no activity on any port. This is necessary * to get an interrupt edge more than to avoid another interrupt. * If the IRQ signal is just an OR of the IRQ signals from several * devices, then the edge from one may be lost because another is * on. */ COM_LOCK(); do { possibly_more_intrs = FALSE; for (unit = 0; unit < NSIOTOT; ++unit) { com = com_addr(unit); /* * XXX COM_LOCK(); * would it work here, or be counter-productive? */ #ifdef PC98 if (com != NULL && !com->gone && IS_8251(com->pc98_if_type)){ siointr1(com); } else #endif /* PC98 */ #ifdef PC98 if (com != NULL && !com->gone && com->pc98_if_type == COM_IF_RSA98III) { rsa_buf_status = inb(com->rsabase + rsa_srr) & 0xc9; if ((rsa_buf_status & 0xc8) || !(rsa_buf_status & 0x01)) { siointr1(com); if(rsa_buf_status != (inb(com->rsabase + rsa_srr) & 0xc9)) possibly_more_intrs = TRUE; } } else #endif if (com != NULL && !com->gone && (inb(com->int_id_port) & IIR_IMASK) != IIR_NOPEND) { siointr1(com); possibly_more_intrs = TRUE; } /* XXX COM_UNLOCK(); */ } } while (possibly_more_intrs); COM_UNLOCK(); #endif /* COM_MULTIPORT */ } static void siointr1(com) struct com_s *com; { u_char line_status; u_char modem_status; u_char *ioptr; u_char recv_data; u_char int_ctl; u_char int_ctl_new; #ifdef PC98 u_char tmp=0; u_char rsa_buf_status = 0; int rsa_tx_fifo_size=0; recv_data=0; #endif /* PC98 */ int_ctl = inb(com->intr_ctl_port); int_ctl_new = int_ctl; while (!com->gone) { #ifdef PC98 status_read:; if (IS_8251(com->pc98_if_type)) { tmp = inb(com->sts_port); more_intr: line_status = 0; if (tmp & STS8251_TxRDY) line_status |= LSR_TXRDY; if (tmp & STS8251_RxRDY) line_status |= LSR_RXRDY; if (tmp & STS8251_TxEMP) line_status |= LSR_TSRE; if (tmp & STS8251_PE) line_status |= LSR_PE; if (tmp & STS8251_OE) line_status |= LSR_OE; if (tmp & STS8251_FE) line_status |= LSR_FE; if (tmp & STS8251_BD_SD) line_status |= LSR_BI; } else #endif /* PC98 */ line_status = inb(com->line_status_port); #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) rsa_buf_status = inb(com->rsabase + rsa_srr); #endif /* PC98 */ /* input event? (check first to help avoid overruns) */ #ifndef PC98 while (line_status & LSR_RCV_MASK) { #else while ((line_status & LSR_RCV_MASK) || (com->pc98_if_type == COM_IF_RSA98III && (rsa_buf_status & 0x08))) { #endif /* PC98 */ /* break/unnattached error bits or real input? */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) { recv_data = inb(com->data_port); if (tmp & 0x78) { pc98_i8251_or_cmd(com,CMD8251_ER); recv_data = 0; } } else { #endif /* PC98 */ #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { if (!(rsa_buf_status & 0x08)) recv_data = 0; else { recv_data = inb(com->data_port); } } else #endif if (!(line_status & LSR_RXRDY)) recv_data = 0; else recv_data = inb(com->data_port); #ifdef PC98 } #endif if (line_status & (LSR_BI | LSR_FE | LSR_PE)) { /* * Don't store BI if IGNBRK or FE/PE if IGNPAR. * Otherwise, push the work to a higher level * (to handle PARMRK) if we're bypassing. * Otherwise, convert BI/FE and PE+INPCK to 0. * * This makes bypassing work right in the * usual "raw" case (IGNBRK set, and IGNPAR * and INPCK clear). * * Note: BI together with FE/PE means just BI. */ if (line_status & LSR_BI) { #if defined(DDB) && defined(BREAK_TO_DEBUGGER) if (com->unit == comconsole) { breakpoint(); goto cont; } #endif if (com->tp == NULL || com->tp->t_iflag & IGNBRK) goto cont; } else { if (com->tp == NULL || com->tp->t_iflag & IGNPAR) goto cont; } if (com->tp->t_state & TS_CAN_BYPASS_L_RINT && (line_status & (LSR_BI | LSR_FE) || com->tp->t_iflag & INPCK)) recv_data = 0; } ++com->bytes_in; if (com->hotchar != 0 && recv_data == com->hotchar) setsofttty(); ioptr = com->iptr; if (ioptr >= com->ibufend) CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW); else { if (com->do_timestamp) microtime(&com->timestamp); ++com_events; schedsofttty(); #if 0 /* for testing input latency vs efficiency */ if (com->iptr - com->ibuf == 8) setsofttty(); #endif ioptr[0] = recv_data; #ifdef PC98 ioptr[com->CE_INPUT_OFFSET] = line_status; #else ioptr[CE_INPUT_OFFSET] = line_status; #endif com->iptr = ++ioptr; if (ioptr == com->ihighwater && com->state & CS_RTS_IFLOW) #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS); if (line_status & LSR_OE) CE_RECORD(com, CE_OVERRUN); } cont: /* * "& 0x7F" is to avoid the gcc-1.40 generating a slow * jump from the top of the loop to here */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) goto status_read; else #endif line_status = inb(com->line_status_port) & 0x7F; #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) rsa_buf_status = inb(com->rsabase + rsa_srr); #endif /* PC98 */ } /* modem status change? (always check before doing output) */ #ifdef PC98 if (!IS_8251(com->pc98_if_type)) { #endif modem_status = inb(com->modem_status_port); if (modem_status != com->last_modem_status) { if (com->do_dcd_timestamp && !(com->last_modem_status & MSR_DCD) && modem_status & MSR_DCD) microtime(&com->dcd_timestamp); /* * Schedule high level to handle DCD changes. Note * that we don't use the delta bits anywhere. Some * UARTs mess them up, and it's easy to remember the * previous bits and calculate the delta. */ com->last_modem_status = modem_status; if (!(com->state & CS_CHECKMSR)) { com_events += LOTS_OF_EVENTS; com->state |= CS_CHECKMSR; setsofttty(); } /* handle CTS change immediately for crisp flow ctl */ if (com->state & CS_CTS_OFLOW) { if (modem_status & MSR_CTS) com->state |= CS_ODEVREADY; else com->state &= ~CS_ODEVREADY; } } #ifdef PC98 } #endif /* output queued and everything ready? */ #ifndef PC98 if (line_status & LSR_TXRDY && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) { #else if (((com->pc98_if_type == COM_IF_RSA98III) ? (rsa_buf_status & 0x02) : (line_status & LSR_TXRDY)) && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) { #endif ioptr = com->obufq.l_head; if (com->tx_fifo_size > 1) { u_int ocount; ocount = com->obufq.l_tail - ioptr; #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { rsa_buf_status = inb(com->rsabase + rsa_srr); rsa_tx_fifo_size = 1024; if (!(rsa_buf_status & 0x01)) rsa_tx_fifo_size = 2048; if (ocount > rsa_tx_fifo_size) ocount = rsa_tx_fifo_size; } else #endif if (ocount > com->tx_fifo_size) ocount = com->tx_fifo_size; com->bytes_out += ocount; do outb(com->data_port, *ioptr++); while (--ocount != 0); } else { outb(com->data_port, *ioptr++); ++com->bytes_out; } #ifdef PC98 if (IS_8251(com->pc98_if_type)) if (!(pc98_check_i8251_interrupt(com) & IEN_TxFLAG)) com_int_Tx_enable(com); #endif com->obufq.l_head = ioptr; if (COM_IIR_TXRDYBUG(com)) { int_ctl_new = int_ctl | IER_ETXRDY; } if (ioptr >= com->obufq.l_tail) { struct lbq *qp; qp = com->obufq.l_next; qp->l_queued = FALSE; qp = qp->l_next; if (qp != NULL) { com->obufq.l_head = qp->l_head; com->obufq.l_tail = qp->l_tail; com->obufq.l_next = qp; } else { /* output just completed */ if ( COM_IIR_TXRDYBUG(com) ) { int_ctl_new = int_ctl & ~IER_ETXRDY; } com->state &= ~CS_BUSY; #if defined(PC98) if (IS_8251(com->pc98_if_type)) if ( pc98_check_i8251_interrupt(com) & IEN_TxFLAG ) com_int_Tx_disable(com); #endif } if (!(com->state & CS_ODONE)) { com_events += LOTS_OF_EVENTS; com->state |= CS_ODONE; setsofttty(); /* handle at high level ASAP */ } } if ( COM_IIR_TXRDYBUG(com) && (int_ctl != int_ctl_new)) { if (com->pc98_if_type == COM_IF_RSA98III) { int_ctl_new &= ~(IER_ETXRDY | IER_ERXRDY); outb(com->intr_ctl_port, int_ctl_new); outb(com->rsabase + rsa_ier, 0x1d); } else outb(com->intr_ctl_port, int_ctl_new); } } #ifdef PC98 else if (line_status & LSR_TXRDY) { if (IS_8251(com->pc98_if_type)) if ( pc98_check_i8251_interrupt(com) & IEN_TxFLAG ) com_int_Tx_disable(com); } if (IS_8251(com->pc98_if_type)) if ((tmp = inb(com->sts_port)) & STS8251_RxRDY) goto more_intr; #endif /* finished? */ #ifndef COM_MULTIPORT #ifdef PC98 if (IS_8251(com->pc98_if_type)) return; #endif if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND) #endif /* COM_MULTIPORT */ return; } } static int sioioctl(dev, cmd, data, flag, p) dev_t dev; u_long cmd; caddr_t data; int flag; struct proc *p; { struct com_s *com; int error; Port_t iobase; int mynor; int s; struct tty *tp; #if defined(COMPAT_43) || defined(COMPAT_SUNOS) int oldcmd; struct termios term; #endif mynor = minor(dev); com = com_addr(MINOR_TO_UNIT(mynor)); if (com->gone) return (ENODEV); iobase = com->iobase; if (mynor & CONTROL_MASK) { struct termios *ct; switch (mynor & CONTROL_MASK) { case CONTROL_INIT_STATE: ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in; break; case CONTROL_LOCK_STATE: ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in; break; default: return (ENODEV); /* /dev/nodev */ } switch (cmd) { case TIOCSETA: error = suser(p->p_ucred, &p->p_acflag); if (error != 0) return (error); *ct = *(struct termios *)data; return (0); case TIOCGETA: *(struct termios *)data = *ct; return (0); case TIOCGETD: *(int *)data = TTYDISC; return (0); case TIOCGWINSZ: bzero(data, sizeof(struct winsize)); return (0); default: return (ENOTTY); } } tp = com->tp; #if defined(COMPAT_43) || defined(COMPAT_SUNOS) term = tp->t_termios; oldcmd = cmd; error = ttsetcompat(tp, &cmd, data, &term); if (error != 0) return (error); if (cmd != oldcmd) data = (caddr_t)&term; #endif if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) { int cc; struct termios *dt = (struct termios *)data; struct termios *lt = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in; dt->c_iflag = (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag); dt->c_oflag = (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag); dt->c_cflag = (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag); dt->c_lflag = (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag); for (cc = 0; cc < NCCS; ++cc) if (lt->c_cc[cc] != 0) dt->c_cc[cc] = tp->t_cc[cc]; if (lt->c_ispeed != 0) dt->c_ispeed = tp->t_ispeed; if (lt->c_ospeed != 0) dt->c_ospeed = tp->t_ospeed; } error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); if (error != ENOIOCTL) return (error); s = spltty(); error = ttioctl(tp, cmd, data, flag); disc_optim(tp, &tp->t_termios, com); if (error != ENOIOCTL) { splx(s); return (error); } #ifdef PC98 if (IS_8251(com->pc98_if_type)) { switch (cmd) { case TIOCSBRK: com_send_break_on( com ); break; case TIOCCBRK: com_send_break_off( com ); break; case TIOCSDTR: com_tiocm_bis(com, TIOCM_DTR | TIOCM_RTS ); break; case TIOCCDTR: com_tiocm_bic(com, TIOCM_DTR); break; /* * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The * changes get undone on the next call to comparam(). */ case TIOCMSET: com_tiocm_set( com, *(int *)data ); break; case TIOCMBIS: com_tiocm_bis( com, *(int *)data ); break; case TIOCMBIC: com_tiocm_bic( com, *(int *)data ); break; case TIOCMGET: *(int *)data = com_tiocm_get(com); break; case TIOCMSDTRWAIT: /* must be root since the wait applies to following logins */ error = suser(p->p_ucred, &p->p_acflag); if (error != 0) { splx(s); return (error); } com->dtr_wait = *(int *)data * hz / 100; break; case TIOCMGDTRWAIT: *(int *)data = com->dtr_wait * 100 / hz; break; case TIOCTIMESTAMP: com->do_timestamp = TRUE; *(struct timeval *)data = com->timestamp; break; case TIOCDCDTIMESTAMP: com->do_dcd_timestamp = TRUE; *(struct timeval *)data = com->dcd_timestamp; break; default: splx(s); return (ENOTTY); } } else { int port_shift; port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; #endif switch (cmd) { case TIOCSBRK: #ifdef PC98 outb(iobase + (com_cfcr << port_shift), com->cfcr_image |= CFCR_SBREAK); #else outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK); #endif break; case TIOCCBRK: #ifdef PC98 outb(iobase + (com_cfcr << port_shift), com->cfcr_image &= ~CFCR_SBREAK); #else outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); #endif break; case TIOCSDTR: (void)commctl(com, TIOCM_DTR, DMBIS); break; case TIOCCDTR: (void)commctl(com, TIOCM_DTR, DMBIC); break; /* * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The * changes get undone on the next call to comparam(). */ case TIOCMSET: (void)commctl(com, *(int *)data, DMSET); break; case TIOCMBIS: (void)commctl(com, *(int *)data, DMBIS); break; case TIOCMBIC: (void)commctl(com, *(int *)data, DMBIC); break; case TIOCMGET: *(int *)data = commctl(com, 0, DMGET); break; case TIOCMSDTRWAIT: /* must be root since the wait applies to following logins */ error = suser(p->p_ucred, &p->p_acflag); if (error != 0) { splx(s); return (error); } com->dtr_wait = *(int *)data * hz / 100; break; case TIOCMGDTRWAIT: *(int *)data = com->dtr_wait * 100 / hz; break; case TIOCTIMESTAMP: com->do_timestamp = TRUE; *(struct timeval *)data = com->timestamp; break; case TIOCDCDTIMESTAMP: com->do_dcd_timestamp = TRUE; *(struct timeval *)data = com->dcd_timestamp; break; default: splx(s); return (ENOTTY); } #ifdef PC98 } #endif splx(s); return (0); } static void siopoll() { int unit; if (com_events == 0) return; repeat: for (unit = 0; unit < NSIOTOT; ++unit) { u_char *buf; struct com_s *com; u_char *ibuf; int incc; struct tty *tp; #ifdef PC98 int tmp; #endif com = com_addr(unit); if (com == NULL) continue; tp = com->tp; if (tp == NULL || com->gone) { /* * Discard any events related to never-opened or * going-away devices. */ disable_intr(); incc = com->iptr - com->ibuf; com->iptr = com->ibuf; if (com->state & CS_CHECKMSR) { incc += LOTS_OF_EVENTS; com->state &= ~CS_CHECKMSR; } com_events -= incc; enable_intr(); continue; } /* switch the role of the low-level input buffers */ if (com->iptr == (ibuf = com->ibuf)) { buf = NULL; /* not used, but compiler can't tell */ incc = 0; } else { buf = ibuf; disable_intr(); incc = com->iptr - buf; com_events -= incc; if (ibuf == com->ibuf1) ibuf = com->ibuf2; else ibuf = com->ibuf1; #ifndef PC98 com->ibufend = ibuf + RS_IBUFSIZE; com->ihighwater = ibuf + RS_IHIGHWATER; #else com->ibufend = ibuf + com->CE_INPUT_OFFSET; com->ihighwater = ibuf + (3 * com->CE_INPUT_OFFSET / 4); #endif com->iptr = ibuf; /* * There is now room for another low-level buffer full * of input, so enable RTS if it is now disabled and * there is room in the high-level buffer. */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = com_tiocm_get(com) & TIOCM_RTS; else tmp = com->mcr_image & MCR_RTS; #endif if ((com->state & CS_RTS_IFLOW) #ifdef PC98 && !(tmp) #else && !(com->mcr_image & MCR_RTS) #endif && !(tp->t_state & TS_TBLOCK)) #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bis(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS); enable_intr(); com->ibuf = ibuf; } if (com->state & CS_CHECKMSR) { u_char delta_modem_status; #ifdef PC98 if (!IS_8251(com->pc98_if_type)) { #endif disable_intr(); delta_modem_status = com->last_modem_status ^ com->prev_modem_status; com->prev_modem_status = com->last_modem_status; com_events -= LOTS_OF_EVENTS; com->state &= ~CS_CHECKMSR; enable_intr(); if (delta_modem_status & MSR_DCD) (*linesw[tp->t_line].l_modem) (tp, com->prev_modem_status & MSR_DCD); #ifdef PC98 } #endif } if (com->state & CS_ODONE) { disable_intr(); com_events -= LOTS_OF_EVENTS; com->state &= ~CS_ODONE; enable_intr(); if (!(com->state & CS_BUSY) && !(com->extra_state & CSE_BUSYCHECK)) { timeout(siobusycheck, com, hz / 100); com->extra_state |= CSE_BUSYCHECK; } (*linesw[tp->t_line].l_start)(tp); } if (incc <= 0 || !(tp->t_state & TS_ISOPEN) || !(tp->t_cflag & CREAD)) continue; /* * Avoid the grotesquely inefficient lineswitch routine * (ttyinput) in "raw" mode. It usually takes about 450 * instructions (that's without canonical processing or echo!). * slinput is reasonably fast (usually 40 instructions plus * call overhead). */ if (tp->t_state & TS_CAN_BYPASS_L_RINT) { if (tp->t_rawq.c_cc + incc > tp->t_ihiwat && (com->state & CS_RTS_IFLOW || tp->t_iflag & IXOFF) && !(tp->t_state & TS_TBLOCK)) ttyblock(tp); tk_nin += incc; tk_rawcc += incc; tp->t_rawcc += incc; com->delta_error_counts[CE_TTY_BUF_OVERFLOW] += b_to_q((char *)buf, incc, &tp->t_rawq); ttwakeup(tp); if (tp->t_state & TS_TTSTOP && (tp->t_iflag & IXANY || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) { tp->t_state &= ~TS_TTSTOP; tp->t_lflag &= ~FLUSHO; comstart(tp); } } else { do { u_char line_status; int recv_data; #ifndef PC98 line_status = (u_char) buf[CE_INPUT_OFFSET]; #else line_status = (u_char) buf[com->CE_INPUT_OFFSET]; #endif recv_data = (u_char) *buf++; if (line_status & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) { if (line_status & LSR_BI) recv_data |= TTY_BI; if (line_status & LSR_FE) recv_data |= TTY_FE; if (line_status & LSR_OE) recv_data |= TTY_OE; if (line_status & LSR_PE) recv_data |= TTY_PE; } (*linesw[tp->t_line].l_rint)(recv_data, tp); } while (--incc > 0); } if (com_events == 0) break; } if (com_events >= LOTS_OF_EVENTS) goto repeat; } static int comparam(tp, t) struct tty *tp; struct termios *t; { u_int cfcr; int cflag; struct com_s *com; int divisor; u_char dlbh; u_char dlbl; Port_t iobase; int s; int unit; #ifdef PC98 Port_t tmp_port; int tmp_flg; int port_shift = 0; u_char param = 0; #endif #ifdef PC98 cfcr = 0; unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); iobase = com->iobase; if (IS_8251(com->pc98_if_type)) { divisor = pc98_ttspeedtab(com, t->c_ospeed); } else { port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; /* do historical conversions */ if (t->c_ispeed == 0) t->c_ispeed = t->c_ospeed; /* check requested parameters */ divisor = ttspeedtab(t->c_ospeed, if_16550a_type[com->pc98_if_type & 0x0f].speedtab); } #else /* do historical conversions */ if (t->c_ispeed == 0) t->c_ispeed = t->c_ospeed; /* check requested parameters */ divisor = ttspeedtab(t->c_ospeed, comspeedtab); #endif if (divisor < 0 || divisor > 0 && t->c_ispeed != t->c_ospeed) return (EINVAL); /* parameters are OK, convert them to the com struct and the device */ #ifndef PC98 unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); iobase = com->iobase; #endif s = spltty(); #ifdef PC98 if (IS_8251(com->pc98_if_type)) { if (divisor == 0) com_tiocm_bic( com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE ); else com_tiocm_bis( com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE ); } else { #endif if (divisor == 0) (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */ else (void)commctl(com, TIOCM_DTR, DMBIS); #ifdef PC98 } #endif cflag = t->c_cflag; #ifdef PC98 if (!IS_8251(com->pc98_if_type)) { #endif switch (cflag & CSIZE) { case CS5: cfcr = CFCR_5BITS; break; case CS6: cfcr = CFCR_6BITS; break; case CS7: cfcr = CFCR_7BITS; break; default: cfcr = CFCR_8BITS; break; } if (cflag & PARENB) { cfcr |= CFCR_PENAB; if (!(cflag & PARODD)) cfcr |= CFCR_PEVEN; } if (cflag & CSTOPB) cfcr |= CFCR_STOPB; if (com->hasfifo && divisor != 0) { /* * Use a fifo trigger level low enough so that the input * latency from the fifo is less than about 16 msec and * the total latency is less than about 30 msec. These * latencies are reasonable for humans. Serial comms * protocols shouldn't expect anything better since modem * latencies are larger. */ com->fifo_image = t->c_ospeed <= 4800 ? FIFO_ENABLE : FIFO_ENABLE | FIFO_RX_HIGH; #ifdef COM_ESP /* * The Hayes ESP card needs the fifo DMA mode bit set * in compatibility mode. If not, it will interrupt * for each character received. */ if (com->esp) com->fifo_image |= FIFO_DMA_MODE; #endif #ifdef PC98 outb(iobase + (com_fifo << port_shift), com->fifo_image); #else outb(iobase + com_fifo, com->fifo_image); #endif } #ifdef PC98 } #endif disable_intr(); /* very important while com_data is hidden */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_cflag_and_speed_set(com, cflag, t->c_ospeed); else { #endif if (divisor != 0) { #ifdef PC98 outb(iobase + (com_cfcr << port_shift), cfcr | CFCR_DLAB); #else outb(iobase + com_cfcr, cfcr | CFCR_DLAB); #endif /* * Only set the divisor registers if they would change, * since on some 16550 incompatibles (UMC8669F), setting * them while input is arriving them loses sync until * data stops arriving. */ dlbl = divisor & 0xFF; #ifdef PC98 if (inb(iobase + (com_dlbl << port_shift)) != dlbl) outb(iobase + (com_dlbl << port_shift), dlbl); dlbh = (u_int) divisor >> 8; if (inb(iobase + (com_dlbh << port_shift)) != dlbh) outb(iobase + (com_dlbh << port_shift), dlbh); #else if (inb(iobase + com_dlbl) != dlbl) outb(iobase + com_dlbl, dlbl); dlbh = (u_int) divisor >> 8; if (inb(iobase + com_dlbh) != dlbh) outb(iobase + com_dlbh, dlbh); #endif } #ifdef PC98 } outb(iobase + (com_cfcr << port_shift), com->cfcr_image = cfcr); #else outb(iobase + com_cfcr, com->cfcr_image = cfcr); #endif if (!(tp->t_state & TS_TTSTOP)) com->state |= CS_TTGO; if (cflag & CRTS_IFLOW) { if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) | 0x40); } com->state |= CS_RTS_IFLOW; /* * If CS_RTS_IFLOW just changed from off to on, the change * needs to be propagated to MCR_RTS. This isn't urgent, * so do it later by calling comstart() instead of repeating * a lot of code from comstart() here. */ } else if (com->state & CS_RTS_IFLOW) { com->state &= ~CS_RTS_IFLOW; /* * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS * on here, since comstart() won't do it later. */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bis(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS); if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) & ~0x40); } } /* * Set up state to handle output flow control. * XXX - worth handling MDMBUF (DCD) flow control at the lowest level? * Now has 10+ msec latency, while CTS flow has 50- usec latency. */ com->state |= CS_ODEVREADY; com->state &= ~CS_CTS_OFLOW; #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { param = inb(com->rsabase + rsa_msr); outb(com->rsabase + rsa_msr, param & 0x14); } #endif if (cflag & CCTS_OFLOW) { com->state |= CS_CTS_OFLOW; #ifdef PC98 if (IS_8251(com->pc98_if_type)) { if (!(pc98_get_modem_status(com) & TIOCM_CTS)) com->state &= ~CS_ODEVREADY; } else { #endif #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { /* Set automatic flow control mode */ outb(com->rsabase + rsa_msr, param | 0x08); } else #endif if (!(com->last_modem_status & MSR_CTS)) com->state &= ~CS_ODEVREADY; if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) | 0x80); } #ifdef PC98 } #endif } else { if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) & ~0x80); } } #ifdef PC98 outb(iobase + (com_cfcr << port_shift), com->cfcr_image); #else outb(iobase + com_cfcr, com->cfcr_image); #endif /* XXX shouldn't call functions while intrs are disabled. */ disc_optim(tp, t, com); /* * Recover from fiddling with CS_TTGO. We used to call siointr1() * unconditionally, but that defeated the careful discarding of * stale input in sioopen(). */ if (com->state >= (CS_BUSY | CS_TTGO)) siointr1(com); enable_intr(); splx(s); comstart(tp); return (0); } static void comstart(tp) struct tty *tp; { struct com_s *com; int s; int unit; #ifdef PC98 int tmp; #endif unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); s = spltty(); disable_intr(); if (tp->t_state & TS_TTSTOP) com->state &= ~CS_TTGO; else com->state |= CS_TTGO; if (tp->t_state & TS_TBLOCK) { #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = com_tiocm_get(com) & TIOCM_RTS; else tmp = com->mcr_image & MCR_RTS; if (tmp && (com->state & CS_RTS_IFLOW)) #else if (com->mcr_image & MCR_RTS && com->state & CS_RTS_IFLOW) #endif #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS); } else { #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = com_tiocm_get(com) & TIOCM_RTS; else tmp = com->mcr_image & MCR_RTS; if (!(tmp) && com->iptr < com->ihighwater && com->state & CS_RTS_IFLOW) #else if (!(com->mcr_image & MCR_RTS) && com->iptr < com->ihighwater && com->state & CS_RTS_IFLOW) #endif #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bis(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS); } enable_intr(); if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) { ttwwakeup(tp); #ifdef PC98 /* if(IS_8251(com->pc98_if_type)) com_int_Tx_enable(com); */ #endif splx(s); return; } if (tp->t_outq.c_cc != 0) { struct lbq *qp; struct lbq *next; if (!com->obufs[0].l_queued) { com->obufs[0].l_tail = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1, #ifndef PC98 sizeof com->obuf1); #else com->CE_INPUT_OFFSET); #endif com->obufs[0].l_next = NULL; com->obufs[0].l_queued = TRUE; disable_intr(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; while ((next = qp->l_next) != NULL) qp = next; qp->l_next = &com->obufs[0]; } else { com->obufq.l_head = com->obufs[0].l_head; com->obufq.l_tail = com->obufs[0].l_tail; com->obufq.l_next = &com->obufs[0]; com->state |= CS_BUSY; } enable_intr(); } if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) { com->obufs[1].l_tail = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2, #ifndef PC98 sizeof com->obuf2); #else com->CE_INPUT_OFFSET); #endif com->obufs[1].l_next = NULL; com->obufs[1].l_queued = TRUE; disable_intr(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; while ((next = qp->l_next) != NULL) qp = next; qp->l_next = &com->obufs[1]; } else { com->obufq.l_head = com->obufs[1].l_head; com->obufq.l_tail = com->obufs[1].l_tail; com->obufq.l_next = &com->obufs[1]; com->state |= CS_BUSY; } enable_intr(); } tp->t_state |= TS_BUSY; } disable_intr(); if (com->state >= (CS_BUSY | CS_TTGO)) siointr1(com); /* fake interrupt to start output */ enable_intr(); #ifdef PC98 /* if(IS_8251(com->pc98_if_type)) com_int_Tx_enable(com); */ #endif ttwwakeup(tp); splx(s); } static void siostop(tp, rw) struct tty *tp; int rw; { struct com_s *com; #ifdef PC98 int port_shift = 0; int rsa98_tmp = 0; #endif com = com_addr(DEV_TO_UNIT(tp->t_dev)); if (com->gone) return; #ifdef PC98 if (IS_8251(com->pc98_if_type)) port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; #endif disable_intr(); if (rw & FWRITE) { if (com->hasfifo) #ifdef COM_ESP /* XXX avoid h/w bug. */ if (!com->esp) #endif #ifdef PC98 outb(com->iobase + (com_fifo << port_shift), FIFO_XMT_RST | com->fifo_image); if (com->pc98_if_type == COM_IF_RSA98III) for(rsa98_tmp = 0; rsa98_tmp < 2048; rsa98_tmp++) outb(com->iobase + (com_fifo << port_shift), FIFO_XMT_RST | com->fifo_image); #else outb(com->iobase + com_fifo, FIFO_XMT_RST | com->fifo_image); #endif com->obufs[0].l_queued = FALSE; com->obufs[1].l_queued = FALSE; if (com->state & CS_ODONE) com_events -= LOTS_OF_EVENTS; com->state &= ~(CS_ODONE | CS_BUSY); com->tp->t_state &= ~TS_BUSY; } if (rw & FREAD) { if (com->hasfifo) #ifdef COM_ESP /* XXX avoid h/w bug. */ if (!com->esp) #endif #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { for(rsa98_tmp = 0; rsa98_tmp < 2048; rsa98_tmp++) inb(com->data_port); } outb(com->iobase + (com_fifo << port_shift), FIFO_RCV_RST | com->fifo_image); #else outb(com->iobase + com_fifo, FIFO_RCV_RST | com->fifo_image); #endif com_events -= (com->iptr - com->ibuf); com->iptr = com->ibuf; } enable_intr(); comstart(tp); } static struct tty * siodevtotty(dev) dev_t dev; { int mynor; int unit; mynor = minor(dev); if (mynor & CONTROL_MASK) return (NULL); unit = MINOR_TO_UNIT(mynor); if ((u_int) unit >= NSIOTOT) return (NULL); return (&sio_tty[unit]); } static int commctl(com, bits, how) struct com_s *com; int bits; int how; { int mcr; int msr; if (how == DMGET) { bits = TIOCM_LE; /* XXX - always enabled while open */ mcr = com->mcr_image; if (mcr & MCR_DTR) bits |= TIOCM_DTR; if (mcr & MCR_RTS) bits |= TIOCM_RTS; msr = com->prev_modem_status; if (msr & MSR_CTS) bits |= TIOCM_CTS; if (msr & MSR_DCD) bits |= TIOCM_CD; if (msr & MSR_DSR) bits |= TIOCM_DSR; /* * XXX - MSR_RI is naturally volatile, and we make MSR_TERI * more volatile by reading the modem status a lot. Perhaps * we should latch both bits until the status is read here. */ if (msr & (MSR_RI | MSR_TERI)) bits |= TIOCM_RI; return (bits); } mcr = 0; if (bits & TIOCM_DTR) mcr |= MCR_DTR; if (bits & TIOCM_RTS) mcr |= MCR_RTS; if (com->gone) return(0); disable_intr(); switch (how) { case DMSET: outb(com->modem_ctl_port, com->mcr_image = mcr | (com->mcr_image & MCR_IENABLE)); break; case DMBIS: outb(com->modem_ctl_port, com->mcr_image |= mcr); break; case DMBIC: outb(com->modem_ctl_port, com->mcr_image &= ~mcr); break; } enable_intr(); return (0); } static void siosettimeout() { struct com_s *com; bool_t someopen; int unit; /* * Set our timeout period to 1 second if no polled devices are open. * Otherwise set it to max(1/200, 1/hz). * Enable timeouts iff some device is open. */ untimeout(comwakeup, (void *)NULL, sio_timeout_handle); sio_timeout = hz; someopen = FALSE; for (unit = 0; unit < NSIOTOT; ++unit) { com = com_addr(unit); if (com != NULL && com->tp != NULL && com->tp->t_state & TS_ISOPEN && !com->gone) { someopen = TRUE; if (com->poll || com->poll_output) { sio_timeout = hz > 200 ? hz / 200 : 1; break; } } } if (someopen) { sio_timeouts_until_log = hz / sio_timeout; sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout); } else { /* Flush error messages, if any. */ sio_timeouts_until_log = 1; comwakeup((void *)NULL); untimeout(comwakeup, (void *)NULL, sio_timeout_handle); } } static void comwakeup(chan) void *chan; { struct com_s *com; int unit; sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout); /* * Recover from lost output interrupts. * Poll any lines that don't use interrupts. */ for (unit = 0; unit < NSIOTOT; ++unit) { com = com_addr(unit); if (com != NULL && !com->gone && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) { disable_intr(); siointr1(com); enable_intr(); } } /* * Check for and log errors, but not too often. */ if (--sio_timeouts_until_log > 0) return; sio_timeouts_until_log = hz / sio_timeout; for (unit = 0; unit < NSIOTOT; ++unit) { int errnum; com = com_addr(unit); if (com == NULL) continue; if (com->gone) continue; for (errnum = 0; errnum < CE_NTYPES; ++errnum) { u_int delta; u_long total; disable_intr(); delta = com->delta_error_counts[errnum]; com->delta_error_counts[errnum] = 0; enable_intr(); if (delta == 0) continue; total = com->error_counts[errnum] += delta; log(LOG_ERR, "sio%d: %u more %s%s (total %lu)\n", unit, delta, error_desc[errnum], delta == 1 ? "" : "s", total); } } } #ifdef PC98 /* commint is called when modem control line changes */ static void commint(dev_t dev) { register struct tty *tp; int stat,delta; struct com_s *com; int mynor,unit; mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); com = com_addr(unit); tp = com->tp; stat = com_tiocm_get(com); delta = com_tiocm_get_delta(com); if (com->state & CS_CTS_OFLOW) { if (stat & TIOCM_CTS) com->state |= CS_ODEVREADY; else com->state &= ~CS_ODEVREADY; } if ((delta & TIOCM_CAR) && (mynor & CALLOUT_MASK) == 0) { if (stat & TIOCM_CAR ) (void)(*linesw[tp->t_line].l_modem)(tp, 1); else if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0) { /* negate DTR, RTS */ com_tiocm_bic(com, (tp->t_cflag & HUPCL) ? TIOCM_DTR|TIOCM_RTS|TIOCM_LE : TIOCM_LE ); /* disable IENABLE */ com_int_TxRx_disable( com ); } } } #endif static void disc_optim(tp, t, com) struct tty *tp; struct termios *t; struct com_s *com; { if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON)) && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) && (!(t->c_iflag & PARMRK) || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) && linesw[tp->t_line].l_rint == ttyinput) tp->t_state |= TS_CAN_BYPASS_L_RINT; else tp->t_state &= ~TS_CAN_BYPASS_L_RINT; com->hotchar = linesw[tp->t_line].l_hotchar; } /* * Following are all routines needed for SIO to act as console */ #include struct siocnstate { u_char dlbl; u_char dlbh; u_char ier; u_char cfcr; u_char mcr; }; static speed_t siocngetspeed __P((Port_t, struct speedtab *)); static void siocnclose __P((struct siocnstate *sp)); static void siocnopen __P((struct siocnstate *sp)); static void siocntxwait __P((void)); +/* + * XXX: sciocnget() and sciocnputc() are not declared static, as they are + * referred to from i386/i386/i386-gdbstub.c. + */ +static cn_probe_t siocnprobe; +static cn_init_t siocninit; +static cn_checkc_t siocncheckc; + cn_getc_t siocngetc; + cn_putc_t siocnputc; + +CONS_DRIVER(sio, siocnprobe, siocninit, siocngetc, siocncheckc, siocnputc); + static void siocntxwait() { int timo; /* * Wait for any pending transmission to finish. Required to avoid * the UART lockup bug when the speed is changed, and for normal * transmits. */ timo = 100000; while ((inb(siocniobase + com_lsr) & (LSR_TSRE | LSR_TXRDY)) != (LSR_TSRE | LSR_TXRDY) && --timo != 0) ; } /* * Read the serial port specified and try to figure out what speed * it's currently running at. We're assuming the serial port has * been initialized and is basicly idle. This routine is only intended * to be run at system startup. * * If the value read from the serial port doesn't make sense, return 0. */ static speed_t siocngetspeed(iobase, table) Port_t iobase; struct speedtab *table; { int code; u_char dlbh; u_char dlbl; u_char cfcr; cfcr = inb(iobase + com_cfcr); outb(iobase + com_cfcr, CFCR_DLAB | cfcr); dlbl = inb(iobase + com_dlbl); dlbh = inb(iobase + com_dlbh); outb(iobase + com_cfcr, cfcr); code = dlbh << 8 | dlbl; for ( ; table->sp_speed != -1; table++) if (table->sp_code == code) return (table->sp_speed); return 0; /* didn't match anything sane */ } static void siocnopen(sp) struct siocnstate *sp; { int divisor; u_char dlbh; u_char dlbl; Port_t iobase; /* * Save all the device control registers except the fifo register * and set our default ones (cs8 -parenb speed=comdefaultrate). * We can't save the fifo register since it is read-only. */ iobase = siocniobase; sp->ier = inb(iobase + com_ier); outb(iobase + com_ier, 0); /* spltty() doesn't stop siointr() */ siocntxwait(); sp->cfcr = inb(iobase + com_cfcr); outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS); sp->dlbl = inb(iobase + com_dlbl); sp->dlbh = inb(iobase + com_dlbh); /* * Only set the divisor registers if they would change, since on * some 16550 incompatibles (Startech), setting them clears the * data input register. This also reduces the effects of the * UMC8669F bug. */ divisor = ttspeedtab(comdefaultrate, comspeedtab); dlbl = divisor & 0xFF; if (sp->dlbl != dlbl) outb(iobase + com_dlbl, dlbl); dlbh = (u_int) divisor >> 8; if (sp->dlbh != dlbh) outb(iobase + com_dlbh, dlbh); outb(iobase + com_cfcr, CFCR_8BITS); sp->mcr = inb(iobase + com_mcr); /* * We don't want interrupts, but must be careful not to "disable" * them by clearing the MCR_IENABLE bit, since that might cause * an interrupt by floating the IRQ line. */ outb(iobase + com_mcr, (sp->mcr & MCR_IENABLE) | MCR_DTR | MCR_RTS); } static void siocnclose(sp) struct siocnstate *sp; { Port_t iobase; /* * Restore the device control registers. */ siocntxwait(); iobase = siocniobase; outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS); if (sp->dlbl != inb(iobase + com_dlbl)) outb(iobase + com_dlbl, sp->dlbl); if (sp->dlbh != inb(iobase + com_dlbh)) outb(iobase + com_dlbh, sp->dlbh); outb(iobase + com_cfcr, sp->cfcr); /* * XXX damp oscillations of MCR_DTR and MCR_RTS by not restoring them. */ outb(iobase + com_mcr, sp->mcr | MCR_DTR | MCR_RTS); outb(iobase + com_ier, sp->ier); } -void +static void siocnprobe(cp) struct consdev *cp; { speed_t boot_speed; u_char cfcr; struct isa_device *dvp; int s; struct siocnstate sp; /* * Find our first enabled console, if any. If it is a high-level * console device, then initialize it and return successfully. * If it is a low-level console device, then initialize it and * return unsuccessfully. It must be initialized in both cases * for early use by console drivers and debuggers. Initializing * the hardware is not necessary in all cases, since the i/o * routines initialize it on the fly, but it is necessary if * input might arrive while the hardware is switched back to an * uninitialized state. We can't handle multiple console devices * yet because our low-level routines don't take a device arg. * We trust the user to set the console flags properly so that we * don't need to probe. */ cp->cn_pri = CN_DEAD; for (dvp = isa_devtab_tty; dvp->id_driver != NULL; dvp++) if (dvp->id_driver == &siodriver && dvp->id_enabled && COM_CONSOLE(dvp)) { siocniobase = dvp->id_iobase; s = spltty(); if (boothowto & RB_SERIAL) { boot_speed = siocngetspeed(siocniobase, comspeedtab); if (boot_speed) comdefaultrate = boot_speed; } /* * Initialize the divisor latch. We can't rely on * siocnopen() to do this the first time, since it * avoids writing to the latch if the latch appears * to have the correct value. Also, if we didn't * just read the speed from the hardware, then we * need to set the speed in hardware so that * switching it later is null. */ cfcr = inb(siocniobase + com_cfcr); outb(siocniobase + com_cfcr, CFCR_DLAB | cfcr); outb(siocniobase + com_dlbl, COMBRD(comdefaultrate) & 0xff); outb(siocniobase + com_dlbh, (u_int) COMBRD(comdefaultrate) >> 8); outb(siocniobase + com_cfcr, cfcr); siocnopen(&sp); splx(s); if (!COM_LLCONSOLE(dvp)) { cp->cn_dev = makedev(CDEV_MAJOR, dvp->id_unit); cp->cn_pri = COM_FORCECONSOLE(dvp) || boothowto & RB_SERIAL ? CN_REMOTE : CN_NORMAL; } break; } } -void +static void siocninit(cp) struct consdev *cp; { comconsole = DEV_TO_UNIT(cp->cn_dev); } -int +static int siocncheckc(dev) dev_t dev; { int c; Port_t iobase; int s; struct siocnstate sp; iobase = siocniobase; s = spltty(); siocnopen(&sp); if (inb(iobase + com_lsr) & LSR_RXRDY) c = inb(iobase + com_data); else c = -1; siocnclose(&sp); splx(s); return (c); } int siocngetc(dev) dev_t dev; { int c; Port_t iobase; int s; struct siocnstate sp; iobase = siocniobase; s = spltty(); siocnopen(&sp); while (!(inb(iobase + com_lsr) & LSR_RXRDY)) ; c = inb(iobase + com_data); siocnclose(&sp); splx(s); return (c); } void siocnputc(dev, c) dev_t dev; int c; { int s; struct siocnstate sp; s = spltty(); siocnopen(&sp); siocntxwait(); outb(siocniobase + com_data, c); siocnclose(&sp); splx(s); } /* * support PnP cards if we are using 'em */ #if NPNP > 0 static pnpid_t siopnp_ids[] = { { 0x5015f435, "MOT1550"}, { 0x8113b04e, "Supra1381"}, { 0x9012b04e, "Supra1290"}, { 0x7121b04e, "SupraExpress 56i Sp"}, { 0x11007256, "USR0011"}, { 0x30207256, "USR2030"}, { 0 } }; static char *siopnp_probe(u_long csn, u_long vend_id); static void siopnp_attach(u_long csn, u_long vend_id, char *name, struct isa_device *dev); static u_long nsiopnp = NSIO; static struct pnp_device siopnp = { "siopnp", siopnp_probe, siopnp_attach, &nsiopnp, &tty_imask }; DATA_SET (pnpdevice_set, siopnp); static char * siopnp_probe(u_long csn, u_long vend_id) { pnpid_t *id; char *s = NULL; for(id = siopnp_ids; id->vend_id != 0; id++) { if (vend_id == id->vend_id) { s = id->id_str; break; } } if (s) { struct pnp_cinfo d; read_pnp_parms(&d, 0); if (d.enable == 0 || d.flags & 1) { printf("CSN %lu is disabled.\n", csn); return (NULL); } } return (s); } static void siopnp_attach(u_long csn, u_long vend_id, char *name, struct isa_device *dev) { struct pnp_cinfo d; struct isa_device *dvp; if (dev->id_unit >= NSIOTOT) return; if (read_pnp_parms(&d, 0) == 0) { printf("failed to read pnp parms\n"); return; } write_pnp_parms(&d, 0); enable_pnp_card(); dev->id_iobase = d.port[0]; dev->id_irq = (1 << d.irq[0]); dev->id_intr = siointr; dev->id_ri_flags = RI_FAST; dev->id_drq = -1; if (dev->id_driver == NULL) { dev->id_driver = &siodriver; dvp = find_isadev(isa_devtab_tty, &siodriver, 0); if (dvp != NULL) dev->id_id = dvp->id_id; } if ((dev->id_alive = sioprobe(dev)) != 0) sioattach(dev); else printf("sio%d: probe failed\n", dev->id_unit); } #endif #ifdef PC98 /* * pc98 local function */ static void com_tiocm_set(struct com_s *com, int msr) { int s; int tmp = 0; int mask = CMD8251_TxEN|CMD8251_RxEN|CMD8251_DTR|CMD8251_RTS; s=spltty(); com->pc98_prev_modem_status = ( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ) | ( com->pc98_prev_modem_status & ~(TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ); tmp |= (CMD8251_TxEN|CMD8251_RxEN); if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR; if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS; pc98_i8251_clear_or_cmd( com, mask, tmp ); splx(s); } static void com_tiocm_bis(struct com_s *com, int msr) { int s; int tmp = 0; s=spltty(); com->pc98_prev_modem_status |= ( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ); tmp |= CMD8251_TxEN|CMD8251_RxEN; if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR; if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS; pc98_i8251_or_cmd( com, tmp ); splx(s); } static void com_tiocm_bic(struct com_s *com, int msr) { int s; int tmp = msr; s=spltty(); com->pc98_prev_modem_status &= ~( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ); if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR; if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS; pc98_i8251_clear_cmd( com, tmp ); splx(s); } static int com_tiocm_get(struct com_s *com) { return( com->pc98_prev_modem_status ); } static int com_tiocm_get_delta(struct com_s *com) { int tmp; tmp = com->pc98_modem_delta; com->pc98_modem_delta = 0; return( tmp ); } /* convert to TIOCM_?? ( ioctl.h ) */ static int pc98_get_modem_status(struct com_s *com) { int stat, stat2; register int msr; stat = inb(com->sts_port); stat2 = inb(com->in_modem_port); msr = com->pc98_prev_modem_status & ~(TIOCM_CAR|TIOCM_RI|TIOCM_DSR|TIOCM_CTS); if ( !(stat2 & CICSCD_CD) ) msr |= TIOCM_CAR; if ( !(stat2 & CICSCD_CI) ) msr |= TIOCM_RI; if ( stat & STS8251_DSR ) msr |= TIOCM_DSR; if ( !(stat2 & CICSCD_CS) ) msr |= TIOCM_CTS; #if COM_CARRIER_DETECT_EMULATE if ( msr & (TIOCM_DSR|TIOCM_CTS) ) { msr |= TIOCM_CAR; } #endif return(msr); } static void pc98_check_msr(void* chan) { int msr, delta; int s; register struct tty *tp; struct com_s *com; int mynor; int unit; dev_t dev; dev=(dev_t)chan; mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); com = com_addr(unit); tp = com->tp; s = spltty(); msr = pc98_get_modem_status(com); /* make change flag */ delta = msr ^ com->pc98_prev_modem_status; if ( delta & TIOCM_CAR ) { if ( com->modem_car_chg_timer ) { if ( -- com->modem_car_chg_timer ) msr ^= TIOCM_CAR; } else { if ( com->modem_car_chg_timer = ( msr & TIOCM_CAR ) ? DCD_ON_RECOGNITION : DCD_OFF_TOLERANCE ) msr ^= TIOCM_CAR; } } else com->modem_car_chg_timer = 0; delta = ( msr ^ com->pc98_prev_modem_status ) & (TIOCM_CAR|TIOCM_RI|TIOCM_DSR|TIOCM_CTS); com->pc98_prev_modem_status = msr; delta = ( com->pc98_modem_delta |= delta ); splx(s); if ( com->modem_checking || (tp->t_state & (TS_ISOPEN)) ) { if ( delta ) { commint(dev); } timeout(pc98_check_msr, (caddr_t)dev, PC98_CHECK_MODEM_INTERVAL); } else { com->modem_checking = 0; } } static void pc98_msrint_start(dev_t dev) { struct com_s *com; int mynor; int unit; int s = spltty(); mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); com = com_addr(unit); /* modem control line check routine envoke interval is 1/10 sec */ if ( com->modem_checking == 0 ) { com->pc98_prev_modem_status = pc98_get_modem_status(com); com->pc98_modem_delta = 0; timeout(pc98_check_msr, (caddr_t)dev, PC98_CHECK_MODEM_INTERVAL); com->modem_checking = 1; } splx(s); } static void pc98_disable_i8251_interrupt(struct com_s *com, int mod) { /* disable interrupt */ register int tmp; mod |= ~(IEN_Tx|IEN_TxEMP|IEN_Rx); COM_INT_DISABLE tmp = inb( com->intr_ctrl_port ) & ~(IEN_Tx|IEN_TxEMP|IEN_Rx); outb( com->intr_ctrl_port, (com->intr_enable&=~mod) | tmp ); COM_INT_ENABLE } static void pc98_enable_i8251_interrupt(struct com_s *com, int mod) { register int tmp; COM_INT_DISABLE tmp = inb( com->intr_ctrl_port ) & ~(IEN_Tx|IEN_TxEMP|IEN_Rx); outb( com->intr_ctrl_port, (com->intr_enable|=mod) | tmp ); COM_INT_ENABLE } static int pc98_check_i8251_interrupt(struct com_s *com) { return ( com->intr_enable & 0x07 ); } static void pc98_i8251_clear_cmd(struct com_s *com, int x) { int tmp; COM_INT_DISABLE tmp = com->pc98_prev_siocmd & ~(x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static void pc98_i8251_or_cmd(struct com_s *com, int x) { int tmp; COM_INT_DISABLE tmp = com->pc98_prev_siocmd | (x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static void pc98_i8251_set_cmd(struct com_s *com, int x) { int tmp; COM_INT_DISABLE tmp = (x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static void pc98_i8251_clear_or_cmd(struct com_s *com, int clr, int x) { int tmp; COM_INT_DISABLE tmp = com->pc98_prev_siocmd & ~(clr); tmp |= (x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static int pc98_i8251_get_cmd(struct com_s *com) { return com->pc98_prev_siocmd; } static int pc98_i8251_get_mod(struct com_s *com) { return com->pc98_prev_siomod; } static void pc98_i8251_reset(struct com_s *com, int mode, int command) { outb(com->cmd_port, 0); /* dummy */ DELAY(2); outb(com->cmd_port, 0); /* dummy */ DELAY(2); outb(com->cmd_port, 0); /* dummy */ DELAY(2); outb(com->cmd_port, CMD8251_RESET); /* internal reset */ DELAY(2); outb(com->cmd_port, mode ); /* mode register */ com->pc98_prev_siomod = mode; DELAY(2); pc98_i8251_set_cmd( com, (command|CMD8251_ER) ); } static void pc98_check_sysclock(void) { /* get system clock from port */ if ( pc98_machine_type & M_8M ) { /* 8 MHz system & H98 */ sysclock = 8; } else { /* 5 MHz system */ sysclock = 5; } } static void com_cflag_and_speed_set( struct com_s *com, int cflag, int speed) { int cfcr=0, count; int previnterrupt; count = pc98_ttspeedtab( com, speed ); if ( count < 0 ) return; previnterrupt = pc98_check_i8251_interrupt(com); pc98_disable_i8251_interrupt( com, IEN_Tx|IEN_TxEMP|IEN_Rx ); switch ( cflag&CSIZE ) { case CS5: cfcr = MOD8251_5BITS; break; case CS6: cfcr = MOD8251_6BITS; break; case CS7: cfcr = MOD8251_7BITS; break; case CS8: cfcr = MOD8251_8BITS; break; } if ( cflag&PARENB ) { if ( cflag&PARODD ) cfcr |= MOD8251_PODD; else cfcr |= MOD8251_PEVEN; } else cfcr |= MOD8251_PDISAB; if ( cflag&CSTOPB ) cfcr |= MOD8251_STOP2; else cfcr |= MOD8251_STOP1; if ( count & 0x10000 ) cfcr |= MOD8251_CLKX1; else cfcr |= MOD8251_CLKX16; if (epson_machine_id != 0x20) { /* XXX */ int tmp; while (!((tmp = inb(com->sts_port)) & STS8251_TxEMP)) ; } /* set baud rate from ospeed */ pc98_set_baud_rate( com, count ); if ( cfcr != pc98_i8251_get_mod(com) ) pc98_i8251_reset(com, cfcr, pc98_i8251_get_cmd(com) ); pc98_enable_i8251_interrupt( com, previnterrupt ); } static int pc98_ttspeedtab(struct com_s *com, int speed) { int if_type, effect_sp, count = -1, mod; if_type = com->pc98_if_type & 0x0f; switch (com->pc98_if_type) { case COM_IF_INTERNAL: if (PC98SIO_baud_rate_port(if_type) != -1) { count = ttspeedtab(speed, if_8251_type[if_type].speedtab); if (count > 0) { count |= COM1_EXT_CLOCK; break; } } /* for *1CLK asynchronous! mode, TEFUTEFU */ mod = (sysclock == 5) ? 2457600 : 1996800; effect_sp = ttspeedtab( speed, pc98speedtab ); if ( effect_sp < 0 ) /* XXX */ effect_sp = ttspeedtab( (speed - 1), pc98speedtab ); if ( effect_sp <= 0 ) return effect_sp; if ( effect_sp == speed ) mod /= 16; if ( mod % effect_sp ) return(-1); count = mod / effect_sp; if ( count > 65535 ) return(-1); if ( effect_sp != speed ) count |= 0x10000; break; case COM_IF_PC9861K_1: case COM_IF_PC9861K_2: count = 1; break; case COM_IF_IND_SS_1: case COM_IF_IND_SS_2: case COM_IF_PIO9032B_1: case COM_IF_PIO9032B_2: if ( speed == 0 ) return 0; count = ttspeedtab( speed, if_8251_type[if_type].speedtab ); break; case COM_IF_B98_01_1: case COM_IF_B98_01_2: if ( speed == 0 ) return 0; count = ttspeedtab( speed, if_8251_type[if_type].speedtab ); #ifdef B98_01_OLD if (count == 0 || count == 1) { count += 4; count |= 0x20000; /* x1 mode for 76800 and 153600 */ } #endif break; } return count; } static void pc98_set_baud_rate( struct com_s *com, int count ) { int if_type, io, s; if_type = com->pc98_if_type & 0x0f; io = com->iobase & 0xff00; switch (com->pc98_if_type) { case COM_IF_INTERNAL: if (PC98SIO_baud_rate_port(if_type) != -1) { if (count & COM1_EXT_CLOCK) { outb((Port_t)PC98SIO_baud_rate_port(if_type), count & 0xff); break; } else { outb((Port_t)PC98SIO_baud_rate_port(if_type), 0x09); } } if ( count < 0 ) { printf( "[ Illegal count : %d ]", count ); return; } else if ( count == 0 ) return; /* set i8253 */ s = splclock(); if (count != 3) outb( 0x77, 0xb6 ); else outb( 0x77, 0xb4 ); outb( 0x5f, 0); outb( 0x75, count & 0xff ); outb( 0x5f, 0); outb( 0x75, (count >> 8) & 0xff ); splx(s); break; case COM_IF_IND_SS_1: case COM_IF_IND_SS_2: outb(io | PC98SIO_intr_ctrl_port(if_type), 0); outb(io | PC98SIO_baud_rate_port(if_type), 0); outb(io | PC98SIO_baud_rate_port(if_type), 0xc0); outb(io | PC98SIO_baud_rate_port(if_type), (count >> 8) | 0x80); outb(io | PC98SIO_baud_rate_port(if_type), count & 0xff); break; case COM_IF_PIO9032B_1: case COM_IF_PIO9032B_2: outb(io | PC98SIO_baud_rate_port(if_type), count); break; case COM_IF_B98_01_1: case COM_IF_B98_01_2: outb(io | PC98SIO_baud_rate_port(if_type), count & 0x0f); #ifdef B98_01_OLD /* * Some old B98_01 board should be controlled * in different way, but this hasn't been tested yet. */ outb(io | PC98SIO_func_port(if_type), (count & 0x20000) ? 0xf0 : 0xf2); #endif break; } } static int pc98_check_if_type(struct isa_device *dev, struct siodev *iod) { int irr, io, if_type, tmp; static short irq_tab[2][8] = { { 3, 5, 6, 9, 10, 12, 13, -1}, { 3, 10, 12, 13, 5, 6, 9, -1} }; iod->if_type = if_type = (dev->id_flags >> 24) & 0xff; if ((if_type < 0 || if_type > COM_IF_END1) && (if_type < 0x10 || if_type > COM_IF_END2)) return(-1); if_type &= 0x0f; iod->irq = 0; io = dev->id_iobase & 0xff00; if (IS_8251(iod->if_type)) { if (PC98SIO_func_port(if_type) != -1) { outb(io | PC98SIO_func_port(if_type), 0xf2); tmp = ttspeedtab(9600, if_8251_type[if_type].speedtab); if (tmp != -1 && PC98SIO_baud_rate_port(if_type) != -1) outb(io | PC98SIO_baud_rate_port(if_type), tmp); } iod->cmd = io | PC98SIO_cmd_port(if_type); iod->sts = io | PC98SIO_sts_port(if_type); iod->mod = io | PC98SIO_in_modem_port(if_type); iod->ctrl = io | PC98SIO_intr_ctrl_port(if_type); if (iod->if_type == COM_IF_INTERNAL) { iod->irq = 4; /* XXX check new internal port. */ outb(0x138, 0); DELAY(10); for (tmp = 0; tmp < 100; tmp++) { if ((inb(0x138) & 1) == 0) { PC98SIO_baud_rate_port(if_type) = 0x13a; if_8251_type[if_type].name = " (internal fast)"; if_8251_type[if_type].speedtab = pc98fast_speedtab; break; } DELAY(1); } } else { tmp = inb( iod->mod ) & if_8251_type[if_type].irr_mask; if ((dev->id_iobase & 0xff) == IO_COM2) iod->irq = irq_tab[0][tmp]; else iod->irq = irq_tab[1][tmp]; } } else { irr = if_16550a_type[if_type].irr_read; #ifdef COM_MULTIPORT if (!COM_ISMULTIPORT(dev) || dev->id_unit == COM_MPMASTER(dev)) #endif if (irr != -1) { tmp = inb(io | irr); if (dev->id_iobase & 0x01) /* XXX depend on RSB-384 */ iod->irq = irq_tab[1][tmp >> 3]; else iod->irq = irq_tab[0][tmp & 0x07]; } } if ( iod->irq == -1 ) return -1; return 0; } static int pc98_set_ioport( struct com_s *com, int id_flags ) { int io, if_type; if_type = (id_flags >> 24) & 0xff; if (IS_8251(if_type)) { pc98_check_sysclock(); io = com->iobase & 0xff00; com->pc98_if_type = if_type; if_type &= 0x0f; com->data_port = io | PC98SIO_data_port(if_type); com->cmd_port = io | PC98SIO_cmd_port(if_type); com->sts_port = io | PC98SIO_sts_port(if_type); com->in_modem_port = io | PC98SIO_in_modem_port(if_type); com->intr_ctrl_port = io | PC98SIO_intr_ctrl_port(if_type); return 0; } return -1; } #endif /* PC98 defined */ Index: head/sys/pc98/pc98/sio.c =================================================================== --- head/sys/pc98/pc98/sio.c (revision 42404) +++ head/sys/pc98/pc98/sio.c (revision 42405) @@ -1,4720 +1,4732 @@ /*- * Copyright (c) 1991 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: @(#)com.c 7.5 (Berkeley) 5/16/91 - * $Id: sio.c,v 1.72 1999/01/03 05:03:47 kato Exp $ + * $Id: sio.c,v 1.73 1999/01/03 15:57:02 kato Exp $ */ #include "opt_comconsole.h" #include "opt_compat.h" #include "opt_ddb.h" #include "opt_devfs.h" #include "opt_sio.h" #include "sio.h" #include "pnp.h" /* * Serial driver, based on 386BSD-0.1 com driver. * Mostly rewritten to use pseudo-DMA. * Works for National Semiconductor NS8250-NS16550AF UARTs. * COM driver, based on HP dca driver. * * Changes for PC-Card integration: * - Added PC-Card driver table and handlers */ /*=============================================================== * 386BSD(98),FreeBSD-1.1x(98) com driver. * ----- * modified for PC9801 by M.Ishii * Kyoto University Microcomputer Club (KMC) * Chou "TEFUTEFU" Hirotomi * Kyoto Univ. the faculty of medicine *=============================================================== * FreeBSD-2.0.1(98) sio driver. * ----- * modified for pc98 Internal i8251 and MICRO CORE MC16550II * T.Koike(hfc01340@niftyserve.or.jp) * implement kernel device configuration * aizu@orient.center.nitech.ac.jp * * Notes. * ----- * PC98 localization based on 386BSD(98) com driver. Using its PC98 local * functions. * This driver is under debugging,has bugs. * * 1) config * options COM_MULTIPORT #if using MC16550II * device sio0 at nec? port 0x30 tty irq 4 #internal * device sio1 at nec? port 0xd2 tty irq 5 flags 0x101 #mc1 * device sio2 at nec? port 0x8d2 tty flags 0x101 #mc2 * # ~~~~~iobase ~~multi port flag * # ~ master device is sio1 * 2) device * cd /dev; MAKEDEV ttyd0 ttyd1 .. * 3) /etc/rc.serial * 57600bps is too fast for sio0(internal8251) * my ex. * #set default speed 9600 * modem() * : * stty last update: 15 Sep.1995 * * How to configure... * # options COM_MULTIPORT # support for MICROCORE MC16550II * ... comment-out this line, which will conflict with B98_01. * options "B98_01" # support for AIWA B98-01 * device sio1 at nec? port 0x00d1 tty irq ? * device sio2 at nec? port 0x00d5 tty irq ? * ... you can leave these lines `irq ?', irq will be autodetected. */ /* * Modified by Y.Takahashi of Kogakuin University. */ #ifdef PC98 #define COM_IF_INTERNAL 0x00 #define COM_IF_PC9861K_1 0x01 #define COM_IF_PC9861K_2 0x02 #define COM_IF_IND_SS_1 0x03 #define COM_IF_IND_SS_2 0x04 #define COM_IF_PIO9032B_1 0x05 #define COM_IF_PIO9032B_2 0x06 #define COM_IF_B98_01_1 0x07 #define COM_IF_B98_01_2 0x08 #define COM_IF_END1 COM_IF_B98_01_2 #define COM_IF_RSA98 0x10 /* same as COM_IF_NS16550 */ #define COM_IF_NS16550 0x11 #define COM_IF_SECOND_CCU 0x12 /* same as COM_IF_NS16550 */ #define COM_IF_MC16550II 0x13 #define COM_IF_MCRS98 0x14 /* same as COM_IF_MC16550II */ #define COM_IF_RSB3000 0x15 #define COM_IF_RSB384 0x16 #define COM_IF_MODEM_CARD 0x17 /* same as COM_IF_NS16550 */ #define COM_IF_RSA98III 0x18 #define COM_IF_ESP98 0x19 #define COM_IF_END2 COM_IF_ESP98 #endif /* PC98 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEVFS #include #endif #include #include #ifdef PC98 #include #include #include #include #else #include #endif #include #include #include #ifdef COM_ESP #include #endif #include #ifdef PC98 #include #endif #include "card.h" #if NCARD > 0 #include #include #endif #if NPNP > 0 #include #endif #ifdef SMP #define disable_intr() COM_DISABLE_INTR() #define enable_intr() COM_ENABLE_INTR() #endif /* SMP */ #ifndef EXTRA_SIO #if NPNP > 0 #define EXTRA_SIO MAX_PNP_CARDS #else #define EXTRA_SIO 0 #endif #endif #define NSIOTOT (NSIO + EXTRA_SIO) #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */ #define RS_IBUFSIZE 256 #define CALLOUT_MASK 0x80 #define CONTROL_MASK 0x60 #define CONTROL_INIT_STATE 0x20 #define CONTROL_LOCK_STATE 0x40 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev))) #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK) #define MINOR_TO_UNIT(mynor) ((mynor) & ~MINOR_MAGIC_MASK) #ifdef COM_MULTIPORT /* checks in flags for multiport and which is multiport "master chip" * for a given card */ #define COM_ISMULTIPORT(dev) ((dev)->id_flags & 0x01) #define COM_MPMASTER(dev) (((dev)->id_flags >> 8) & 0x0ff) #define COM_NOTAST4(dev) ((dev)->id_flags & 0x04) #endif /* COM_MULTIPORT */ #define COM_CONSOLE(dev) ((dev)->id_flags & 0x10) #define COM_FORCECONSOLE(dev) ((dev)->id_flags & 0x20) #define COM_LLCONSOLE(dev) ((dev)->id_flags & 0x40) #define COM_LOSESOUTINTS(dev) ((dev)->id_flags & 0x08) #define COM_NOFIFO(dev) ((dev)->id_flags & 0x02) #define COM_ST16650A(dev) ((dev)->id_flags & 0x20000) #define COM_C_NOPROBE (0x40000) #define COM_NOPROBE(dev) ((dev)->id_flags & COM_C_NOPROBE) #define COM_C_IIR_TXRDYBUG (0x80000) #define COM_IIR_TXRDYBUG(dev) ((dev)->id_flags & COM_C_IIR_TXRDYBUG) #define COM_FIFOSIZE(dev) (((dev)->id_flags & 0xff000000) >> 24) #ifdef PC98 #define com_emr com_msr /* Extension mode register for RSB-2000/3000 */ #else #define com_scr 7 /* scratch register for 16450-16550 (R/W) */ #endif /* * Input buffer watermarks. * The external device is asked to stop sending when the buffer exactly reaches * high water, or when the high level requests it. * The high level is notified immediately (rather than at a later clock tick) * when this watermark is reached. * The buffer size is chosen so the watermark should almost never be reached. * The low watermark is invisibly 0 since the buffer is always emptied all at * once. */ #define RS_IHIGHWATER (3 * RS_IBUFSIZE / 4) /* * com state bits. * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher * than the other bits so that they can be tested as a group without masking * off the low bits. * * The following com and tty flags correspond closely: * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and * siostop()) * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart()) * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam()) * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam()) * TS_FLUSH is not used. * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON. * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state). */ #define CS_BUSY 0x80 /* output in progress */ #define CS_TTGO 0x40 /* output not stopped by XOFF */ #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */ #define CS_CHECKMSR 1 /* check of MSR scheduled */ #define CS_CTS_OFLOW 2 /* use CTS output flow control */ #define CS_DTR_OFF 0x10 /* DTR held off */ #define CS_ODONE 4 /* output completed */ #define CS_RTS_IFLOW 8 /* use RTS input flow control */ #define CSE_BUSYCHECK 1 /* siobusycheck() scheduled */ static char const * const error_desc[] = { #define CE_OVERRUN 0 "silo overflow", #define CE_INTERRUPT_BUF_OVERFLOW 1 "interrupt-level buffer overflow", #define CE_TTY_BUF_OVERFLOW 2 "tty-level buffer overflow", }; #define CE_NTYPES 3 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum]) /* types. XXX - should be elsewhere */ typedef u_int Port_t; /* hardware port */ typedef u_char bool_t; /* boolean */ /* queue of linear buffers */ struct lbq { u_char *l_head; /* next char to process */ u_char *l_tail; /* one past the last char to process */ struct lbq *l_next; /* next in queue */ bool_t l_queued; /* nonzero if queued */ }; /* com device structure */ struct com_s { u_int id_flags; /* Copy isa device falgas */ u_char state; /* miscellaneous flag bits */ bool_t active_out; /* nonzero if the callout device is open */ u_char cfcr_image; /* copy of value written to CFCR */ #ifdef COM_ESP bool_t esp; /* is this unit a hayes esp board? */ #endif u_char extra_state; /* more flag bits, separate for order trick */ u_char fifo_image; /* copy of value written to FIFO */ bool_t hasfifo; /* nonzero for 16550 UARTs */ bool_t st16650a; /* Is a Startech 16650A or RTS/CTS compat */ bool_t loses_outints; /* nonzero if device loses output interrupts */ u_char mcr_image; /* copy of value written to MCR */ #ifdef COM_MULTIPORT bool_t multiport; /* is this unit part of a multiport device? */ #endif /* COM_MULTIPORT */ bool_t no_irq; /* nonzero if irq is not attached */ bool_t gone; /* hardware disappeared */ bool_t poll; /* nonzero if polling is required */ bool_t poll_output; /* nonzero if polling for output is required */ int unit; /* unit number */ int dtr_wait; /* time to hold DTR down on close (* 1/hz) */ u_int tx_fifo_size; u_int wopeners; /* # processes waiting for DCD in open() */ /* * The high level of the driver never reads status registers directly * because there would be too many side effects to handle conveniently. * Instead, it reads copies of the registers stored here by the * interrupt handler. */ u_char last_modem_status; /* last MSR read by intr handler */ u_char prev_modem_status; /* last MSR handled by high level */ u_char hotchar; /* ldisc-specific char to be handled ASAP */ u_char *ibuf; /* start of input buffer */ u_char *ibufend; /* end of input buffer */ u_char *ihighwater; /* threshold in input buffer */ u_char *iptr; /* next free spot in input buffer */ struct lbq obufq; /* head of queue of output buffers */ struct lbq obufs[2]; /* output buffers */ #ifdef PC98 Port_t cmd_port; Port_t sts_port; Port_t in_modem_port; Port_t intr_ctrl_port; int intr_enable; int pc98_prev_modem_status; int pc98_modem_delta; int modem_car_chg_timer; int pc98_prev_siocmd; int pc98_prev_siomod; int modem_checking; int pc98_if_type; #endif /* PC98 */ Port_t data_port; /* i/o ports */ #ifdef COM_ESP Port_t esp_port; #endif Port_t int_id_port; Port_t iobase; #ifdef PC98 Port_t rsabase; /* iobase address of a I/O-DATA RSA board */ #endif Port_t modem_ctl_port; Port_t line_status_port; Port_t modem_status_port; Port_t intr_ctl_port; /* Ports of IIR register */ struct tty *tp; /* cross reference */ /* Initial state. */ struct termios it_in; /* should be in struct tty */ struct termios it_out; /* Lock state. */ struct termios lt_in; /* should be in struct tty */ struct termios lt_out; bool_t do_timestamp; bool_t do_dcd_timestamp; struct timeval timestamp; struct timeval dcd_timestamp; u_long bytes_in; /* statistics */ u_long bytes_out; u_int delta_error_counts[CE_NTYPES]; u_long error_counts[CE_NTYPES]; /* * Ping-pong input buffers. The extra factor of 2 in the sizes is * to allow for an error byte for each input byte. */ #ifdef PC98 u_long CE_INPUT_OFFSET; u_char *ibuf1; u_char *ibuf2; /* * Data area for output buffers. Someday we should build the output * buffer queue without copying data. */ u_char *obuf1; u_char *obuf2; #else #define CE_INPUT_OFFSET RS_IBUFSIZE u_char ibuf1[2 * RS_IBUFSIZE]; u_char ibuf2[2 * RS_IBUFSIZE]; /* * Data area for output buffers. Someday we should build the output * buffer queue without copying data. */ u_char obuf1[256]; u_char obuf2[256]; #endif #ifdef DEVFS void *devfs_token_ttyd; void *devfs_token_ttyl; void *devfs_token_ttyi; void *devfs_token_cuaa; void *devfs_token_cual; void *devfs_token_cuai; #endif }; #ifdef COM_ESP static int espattach __P((struct isa_device *isdp, struct com_s *com, Port_t esp_port)); #endif static int sioattach __P((struct isa_device *dev)); static timeout_t siobusycheck; static timeout_t siodtrwakeup; static void comhardclose __P((struct com_s *com)); static ointhand2_t siointr; static void siointr1 __P((struct com_s *com)); static int commctl __P((struct com_s *com, int bits, int how)); static int comparam __P((struct tty *tp, struct termios *t)); static swihand_t siopoll; static int sioprobe __P((struct isa_device *dev)); static void siosettimeout __P((void)); static void comstart __P((struct tty *tp)); static timeout_t comwakeup; static void disc_optim __P((struct tty *tp, struct termios *t, struct com_s *com)); static char driver_name[] = "sio"; /* table and macro for fast conversion from a unit number to its com struct */ static struct com_s *p_com_addr[NSIOTOT]; #define com_addr(unit) (p_com_addr[unit]) struct isa_driver siodriver = { sioprobe, sioattach, driver_name }; static d_open_t sioopen; static d_close_t sioclose; static d_read_t sioread; static d_write_t siowrite; static d_ioctl_t sioioctl; static d_stop_t siostop; static d_devtotty_t siodevtotty; #define CDEV_MAJOR 28 static struct cdevsw sio_cdevsw = { sioopen, sioclose, sioread, siowrite, sioioctl, siostop, noreset, siodevtotty, ttpoll, nommap, NULL, driver_name, NULL, -1, nodump, nopsize, D_TTY, }; static int comconsole = -1; static volatile speed_t comdefaultrate = CONSPEED; static u_int com_events; /* input chars + weighted output completions */ static Port_t siocniobase; static bool_t sio_registered; static int sio_timeout; static int sio_timeouts_until_log; static struct callout_handle sio_timeout_handle = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle); #if 0 /* XXX */ static struct tty *sio_tty[NSIOTOT]; #else static struct tty sio_tty[NSIOTOT]; #endif static const int nsio_tty = NSIOTOT; #ifdef PC98 struct siodev { short if_type; short irq; Port_t cmd, sts, ctrl, mod; }; static int sysclock; #define COM_INT_DISABLE {int previpri; previpri=spltty(); #define COM_INT_ENABLE splx(previpri);} #define IEN_TxFLAG IEN_Tx #define COM_CARRIER_DETECT_EMULATE 0 #define PC98_CHECK_MODEM_INTERVAL (hz/10) #define DCD_OFF_TOLERANCE 2 #define DCD_ON_RECOGNITION 2 #define IS_8251(if_type) (!(if_type & 0x10)) #define COM1_EXT_CLOCK 0x40000 static void commint __P((dev_t dev)); static void com_tiocm_set __P((struct com_s *com, int msr)); static void com_tiocm_bis __P((struct com_s *com, int msr)); static void com_tiocm_bic __P((struct com_s *com, int msr)); static int com_tiocm_get __P((struct com_s *com)); static int com_tiocm_get_delta __P((struct com_s *com)); static void pc98_msrint_start __P((dev_t dev)); static void com_cflag_and_speed_set __P((struct com_s *com, int cflag, int speed)); static int pc98_ttspeedtab __P((struct com_s *com, int speed)); static int pc98_get_modem_status __P((struct com_s *com)); static timeout_t pc98_check_msr; static void pc98_set_baud_rate __P((struct com_s *com, int count)); static void pc98_i8251_reset __P((struct com_s *com, int mode, int command)); static void pc98_disable_i8251_interrupt __P((struct com_s *com, int mod)); static void pc98_enable_i8251_interrupt __P((struct com_s *com, int mod)); static int pc98_check_i8251_interrupt __P((struct com_s *com)); static int pc98_i8251_get_cmd __P((struct com_s *com)); static int pc98_i8251_get_mod __P((struct com_s *com)); static void pc98_i8251_set_cmd __P((struct com_s *com, int x)); static void pc98_i8251_or_cmd __P((struct com_s *com, int x)); static void pc98_i8251_clear_cmd __P((struct com_s *com, int x)); static void pc98_i8251_clear_or_cmd __P((struct com_s *com, int clr, int x)); static int pc98_check_if_type __P((struct isa_device *dev, struct siodev *iod)); static void pc98_check_sysclock __P((void)); static int pc98_set_ioport __P((struct com_s *com, int id_flags)); #define com_int_Tx_disable(com) \ pc98_disable_i8251_interrupt(com,IEN_Tx|IEN_TxEMP) #define com_int_Tx_enable(com) \ pc98_enable_i8251_interrupt(com,IEN_TxFLAG) #define com_int_Rx_disable(com) \ pc98_disable_i8251_interrupt(com,IEN_Rx) #define com_int_Rx_enable(com) \ pc98_enable_i8251_interrupt(com,IEN_Rx) #define com_int_TxRx_disable(com) \ pc98_disable_i8251_interrupt(com,IEN_Tx|IEN_TxEMP|IEN_Rx) #define com_int_TxRx_enable(com) \ pc98_enable_i8251_interrupt(com,IEN_TxFLAG|IEN_Rx) #define com_send_break_on(com) \ pc98_i8251_or_cmd(com,CMD8251_SBRK) #define com_send_break_off(com) \ pc98_i8251_clear_cmd(com,CMD8251_SBRK) static struct speedtab pc98speedtab[] = { /* internal RS232C interface */ 0, 0, 50, 50, 75, 75, 150, 150, 200, 200, 300, 300, 600, 600, 1200, 1200, 2400, 2400, 4800, 4800, 9600, 9600, 19200, 19200, 38400, 38400, 51200, 51200, 76800, 76800, 20800, 20800, 31200, 31200, 41600, 41600, 62400, 62400, -1, -1 }; static struct speedtab pc98fast_speedtab[] = { 9600, 0x80 | COMBRD(9600), 19200, 0x80 | COMBRD(19200), 38400, 0x80 | COMBRD(38400), 57600, 0x80 | COMBRD(57600), 115200, 0x80 | COMBRD(115200), -1, -1 }; static struct speedtab comspeedtab_pio9032b[] = { 300, 6, 600, 5, 1200, 4, 2400, 3, 4800, 2, 9600, 1, 19200, 0, 38400, 7, -1, -1 }; static struct speedtab comspeedtab_b98_01[] = { 75, 11, 150, 10, 300, 9, 600, 8, 1200, 7, 2400, 6, 4800, 5, 9600, 4, 19200, 3, 38400, 2, 76800, 1, 153600, 0, -1, -1 }; static struct speedtab comspeedtab_mc16550[] = { 300, 1536, 600, 768, 1200, 384, 2400, 192, 4800, 96, 9600, 48, 19200, 24, 38400, 12, 57600, 8, 115200, 4, 153600, 3, 230400, 2, 460800, 1, -1, -1 }; static struct speedtab comspeedtab_rsb384[] = { 300, 3840, 600, 1920, 1200, 960, 2400, 480, 4800, 240, 9600, 120, 19200, 60, 38400, 30, 57600, 20, 115200, 10, 128000, 9, 144000, 8, 192000, 6, 230400, 5, 288000, 4, 384000, 3, 576000, 2, 1152000, 1, -1, -1 }; static struct speedtab comspeedtab_rsa[] = { { 0, 0 }, { 50, COMBRD_RSA(50) }, { 75, COMBRD_RSA(75) }, { 110, COMBRD_RSA(110) }, { 134, COMBRD_RSA(134) }, { 150, COMBRD_RSA(150) }, { 200, COMBRD_RSA(200) }, { 300, COMBRD_RSA(300) }, { 600, COMBRD_RSA(600) }, { 1200, COMBRD_RSA(1200) }, { 1800, COMBRD_RSA(1800) }, { 2400, COMBRD_RSA(2400) }, { 4800, COMBRD_RSA(4800) }, { 9600, COMBRD_RSA(9600) }, { 19200, COMBRD_RSA(19200) }, { 38400, COMBRD_RSA(38400) }, { 57600, COMBRD_RSA(57600) }, { 115200, COMBRD_RSA(115200) }, { 230400, COMBRD_RSA(230400) }, { 460800, COMBRD_RSA(460800) }, { 921600, COMBRD_RSA(921600) }, { -1, -1 } }; #endif /* PC98 */ static struct speedtab comspeedtab[] = { { 0, 0 }, { 50, COMBRD(50) }, { 75, COMBRD(75) }, { 110, COMBRD(110) }, { 134, COMBRD(134) }, { 150, COMBRD(150) }, { 200, COMBRD(200) }, { 300, COMBRD(300) }, { 600, COMBRD(600) }, { 1200, COMBRD(1200) }, { 1800, COMBRD(1800) }, { 2400, COMBRD(2400) }, { 4800, COMBRD(4800) }, { 9600, COMBRD(9600) }, { 19200, COMBRD(19200) }, { 38400, COMBRD(38400) }, { 57600, COMBRD(57600) }, { 115200, COMBRD(115200) }, { -1, -1 } }; #ifdef PC98 struct { char *name; short port_table[7]; short irr_mask; struct speedtab *speedtab; short check_irq; } if_8251_type[] = { /* COM_IF_INTERNAL */ { " (internal)", {0x30, 0x32, 0x32, 0x33, 0x35, -1, -1}, -1, pc98speedtab, 1 }, /* COM_IF_PC9861K_1 */ { " (PC9861K)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, -1, -1}, 3, NULL, 1 }, /* COM_IF_PC9861K_2 */ { " (PC9861K)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, -1, -1}, 3, NULL, 1 }, /* COM_IF_IND_SS_1 */ { " (IND-SS)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xb3, -1}, 3, comspeedtab_mc16550, 1 }, /* COM_IF_IND_SS_2 */ { " (IND-SS)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xbb, -1}, 3, comspeedtab_mc16550, 1 }, /* COM_IF_PIO9032B_1 */ { " (PIO9032B)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xb8, -1}, 7, comspeedtab_pio9032b, 1 }, /* COM_IF_PIO9032B_2 */ { " (PIO9032B)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xba, -1}, 7, comspeedtab_pio9032b, 1 }, /* COM_IF_B98_01_1 */ { " (B98-01)", {0xb1, 0xb3, 0xb3, 0xb0, 0xb0, 0xd1, 0xd3}, 7, comspeedtab_b98_01, 0 }, /* COM_IF_B98_01_2 */ { " (B98-01)", {0xb9, 0xbb, 0xbb, 0xb2, 0xb2, 0xd5, 0xd7}, 7, comspeedtab_b98_01, 0 }, }; #define PC98SIO_data_port(type) (if_8251_type[type].port_table[0]) #define PC98SIO_cmd_port(type) (if_8251_type[type].port_table[1]) #define PC98SIO_sts_port(type) (if_8251_type[type].port_table[2]) #define PC98SIO_in_modem_port(type) (if_8251_type[type].port_table[3]) #define PC98SIO_intr_ctrl_port(type) (if_8251_type[type].port_table[4]) #define PC98SIO_baud_rate_port(type) (if_8251_type[type].port_table[5]) #define PC98SIO_func_port(type) (if_8251_type[type].port_table[6]) struct { char *name; short irr_read; short irr_write; short port_shift; short io_size; struct speedtab *speedtab; } if_16550a_type[] = { /* COM_IF_RSA98 */ { " (RSA-98)", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_NS16550 */ { "", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_SECOND_CCU */ { "", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_MC16550II */ { " (MC16550II)", -1, 0x1000, 8, 1, comspeedtab_mc16550 }, /* COM_IF_MCRS98 */ { " (MC-RS98)", -1, 0x1000, 8, 1, comspeedtab_mc16550 }, /* COM_IF_RSB3000 */ { " (RSB-3000)", 0xbf, -1, 1, 1, comspeedtab_rsb384 }, /* COM_IF_RSB384 */ { " (RSB-384)", 0xbf, -1, 1, 1, comspeedtab_rsb384 }, /* COM_IF_MODEM_CARD */ { "", -1, -1, 0, IO_COMSIZE, comspeedtab }, /* COM_IF_RSA98III */ { " (RSA-98III)", -1, -1, 0, 16, comspeedtab_rsa }, /* COM_IF_ESP98 */ { " (ESP98)", -1, -1, 1, 1, comspeedtab_mc16550 }, }; #endif /* PC98 */ #ifdef COM_ESP #ifdef PC98 /* XXX configure this properly. */ static Port_t likely_com_ports[] = { 0, 0xb0, 0xb1, 0 }; static Port_t likely_esp_ports[] = { 0xc0d0, 0 }; #define ESP98_CMD1 (ESP_CMD1 * 0x100) #define ESP98_CMD2 (ESP_CMD2 * 0x100) #define ESP98_STATUS1 (ESP_STATUS1 * 0x100) #define ESP98_STATUS2 (ESP_STATUS2 * 0x100) #else /* PC98 */ /* XXX configure this properly. */ static Port_t likely_com_ports[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, }; static Port_t likely_esp_ports[] = { 0x140, 0x180, 0x280, 0 }; #endif /* PC98 */ #endif /* * handle sysctl read/write requests for console speed * * In addition to setting comdefaultrate for I/O through /dev/console, * also set the initial and lock values for the /dev/ttyXX device * if there is one associated with the console. Finally, if the /dev/tty * device has already been open, change the speed on the open running port * itself. */ static int sysctl_machdep_comdefaultrate SYSCTL_HANDLER_ARGS { int error, s; speed_t newspeed; struct com_s *com; struct tty *tp; newspeed = comdefaultrate; error = sysctl_handle_opaque(oidp, &newspeed, sizeof newspeed, req); if (error || !req->newptr) return (error); comdefaultrate = newspeed; if (comconsole < 0) /* serial console not selected? */ return (0); com = com_addr(comconsole); if (!com) return (ENXIO); /* * set the initial and lock rates for /dev/ttydXX and /dev/cuaXX * (note, the lock rates really are boolean -- if non-zero, disallow * speed changes) */ com->it_in.c_ispeed = com->it_in.c_ospeed = com->lt_in.c_ispeed = com->lt_in.c_ospeed = com->it_out.c_ispeed = com->it_out.c_ospeed = com->lt_out.c_ispeed = com->lt_out.c_ospeed = comdefaultrate; /* * if we're open, change the running rate too */ tp = com->tp; if (tp && (tp->t_state & TS_ISOPEN)) { tp->t_termios.c_ispeed = tp->t_termios.c_ospeed = comdefaultrate; s = spltty(); error = comparam(tp, &tp->t_termios); splx(s); } return error; } SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW, 0, 0, sysctl_machdep_comdefaultrate, "I", ""); #if NCARD > 0 /* * PC-Card (PCMCIA) specific code. */ static int sioinit __P((struct pccard_devinfo *)); static void siounload __P((struct pccard_devinfo *)); static int card_intr __P((struct pccard_devinfo *)); static struct pccard_device sio_info = { driver_name, sioinit, siounload, card_intr, 0, /* Attributes - presently unused */ &tty_imask /* Interrupt mask for device */ /* XXX - Should this also include net_imask? */ }; DATA_SET(pccarddrv_set, sio_info); /* * Initialize the device - called from Slot manager. */ int sioinit(struct pccard_devinfo *devi) { /* validate unit number. */ if (devi->isahd.id_unit >= (NSIOTOT)) return(ENODEV); /* Make sure it isn't already probed. */ if (com_addr(devi->isahd.id_unit)) return(EBUSY); /* It's already probed as serial by Upper */ devi->isahd.id_flags |= COM_C_NOPROBE; /* * Probe the device. If a value is returned, the * device was found at the location. */ if (sioprobe(&devi->isahd) == 0) return(ENXIO); if (sioattach(&devi->isahd) == 0) return(ENXIO); return(0); } /* * siounload - unload the driver and clear the table. * XXX TODO: * This is usually called when the card is ejected, but * can be caused by a modunload of a controller driver. * The idea is to reset the driver's view of the device * and ensure that any driver entry points such as * read and write do not hang. */ static void siounload(struct pccard_devinfo *devi) { struct com_s *com; if (!devi) { printf("NULL devi in siounload\n"); return; } com = com_addr(devi->isahd.id_unit); if (!com) { printf("NULL com in siounload\n"); return; } if (!com->iobase) { printf("sio%d already unloaded!\n",devi->isahd.id_unit); return; } if (com->tp && (com->tp->t_state & TS_ISOPEN)) { com->gone = 1; printf("sio%d: unload\n", devi->isahd.id_unit); com->tp->t_gen++; ttyclose(com->tp); ttwakeup(com->tp); ttwwakeup(com->tp); } else { com_addr(com->unit) = NULL; #ifdef PC98 bzero(com->ibuf1, com->CE_INPUT_OFFSET * 6); #endif bzero(com, sizeof *com); free(com,M_TTYS); printf("sio%d: unload,gone\n", devi->isahd.id_unit); } } /* * card_intr - Shared interrupt called from * front end of PC-Card handler. */ static int card_intr(struct pccard_devinfo *devi) { struct com_s *com; COM_LOCK(); com = com_addr(devi->isahd.id_unit); if (com && !com->gone) siointr1(com_addr(devi->isahd.id_unit)); COM_UNLOCK(); return(1); } #endif /* NCARD > 0 */ static int sioprobe(dev) struct isa_device *dev; { static bool_t already_init; bool_t failures[10]; int fn; struct isa_device *idev; Port_t iobase; intrmask_t irqmap[4]; intrmask_t irqs; u_char mcr_image; int result; struct isa_device *xdev; #ifdef PC98 int irqout=0; int ret = 0; int tmp; int port_shift = 0; struct siodev iod; Port_t rsabase = NULL; #endif if (!already_init) { /* * Turn off MCR_IENABLE for all likely serial ports. An unused * port with its MCR_IENABLE gate open will inhibit interrupts * from any used port that shares the interrupt vector. * XXX the gate enable is elsewhere for some multiports. */ for (xdev = isa_devtab_tty; xdev->id_driver != NULL; xdev++) #ifdef PC98 if (xdev->id_driver == &siodriver && xdev->id_enabled) { tmp = (xdev->id_flags >> 24) & 0xff; if (IS_8251(tmp)) outb((xdev->id_iobase & 0xff00) | PC98SIO_cmd_port(tmp & 0x0f), 0xf2); else if (tmp == COM_IF_RSA98III) { rsabase = xdev->id_iobase & 0xfff0; #if 0 if (rsabase != xdev->id_iobase) return(0); #endif outb(xdev->id_iobase + 8 + (com_mcr << if_16550a_type[tmp & 0x0f].port_shift), 0); } else outb(xdev->id_iobase + (com_mcr << if_16550a_type[tmp & 0x0f].port_shift), 0); } #else if (xdev->id_driver == &siodriver && xdev->id_enabled) outb(xdev->id_iobase + com_mcr, 0); #endif already_init = TRUE; } if (COM_LLCONSOLE(dev)) { printf("sio%d: reserved for low-level i/o\n", dev->id_unit); return (0); } #ifdef PC98 DELAY(10); /* * If the port is i8251 UART (internal, B98_01) */ if (pc98_check_if_type(dev, &iod) == -1) return 0; if (iod.irq > 0) dev->id_irq = 1 << iod.irq; if (IS_8251(iod.if_type)) { outb(iod.cmd, 0); DELAY(10); outb(iod.cmd, 0); DELAY(10); outb(iod.cmd, 0); DELAY(10); outb(iod.cmd, CMD8251_RESET); DELAY(1000); /* for a while...*/ outb(iod.cmd, 0xf2); /* MODE (dummy) */ DELAY(10); outb(iod.cmd, 0x01); /* CMD (dummy) */ DELAY(1000); /* for a while...*/ if (( inb(iod.sts) & STS8251_TxEMP ) == 0 ) { ret = 0; } if (if_8251_type[iod.if_type & 0x0f].check_irq) { COM_INT_DISABLE tmp = ( inb( iod.ctrl ) & ~(IEN_Rx|IEN_TxEMP|IEN_Tx)); outb( iod.ctrl, tmp|IEN_TxEMP ); DELAY(10); ret = isa_irq_pending() ? 4 : 0; outb( iod.ctrl, tmp ); COM_INT_ENABLE } else { /* * B98_01 doesn't activate TxEMP interrupt line * when being reset, so we can't check irq pending. */ ret = 4; } if (epson_machine_id==0x20) { /* XXX */ ret = 4; } return ret; } #endif /* PC98 */ /* * If the device is on a multiport card and has an AST/4 * compatible interrupt control register, initialize this * register and prepare to leave MCR_IENABLE clear in the mcr. * Otherwise, prepare to set MCR_IENABLE in the mcr. * Point idev to the device struct giving the correct id_irq. * This is the struct for the master device if there is one. */ idev = dev; mcr_image = MCR_IENABLE; #ifdef PC98 if (iod.if_type == COM_IF_RSA98III) { mcr_image = 0; rsabase = idev->id_iobase & 0xfff0; if (rsabase != idev->id_iobase) return(0); outb(rsabase + rsa_msr, 0x04); outb(rsabase + rsa_frr, 0x00); if ((inb(rsabase + rsa_srr) & 0x36) != 0x36) return (0); outb(rsabase + rsa_ier, 0x00); outb(rsabase + rsa_frr, 0x00); outb(rsabase + rsa_tivsr, 0x00); outb(rsabase + rsa_tcr, 0x00); } #endif /* PC98 */ #ifdef COM_MULTIPORT if (COM_ISMULTIPORT(dev)) { idev = find_isadev(isa_devtab_tty, &siodriver, COM_MPMASTER(dev)); if (idev == NULL) { printf("sio%d: master device %d not configured\n", dev->id_unit, COM_MPMASTER(dev)); dev->id_irq = 0; idev = dev; } #ifndef PC98 if (!COM_NOTAST4(dev)) { outb(idev->id_iobase + com_scr, idev->id_irq ? 0x80 : 0); mcr_image = 0; } #endif /* !PC98 */ } #endif /* COM_MULTIPORT */ if (idev->id_irq == 0) mcr_image = 0; #ifdef PC98 tmp = if_16550a_type[iod.if_type & 0x0f].irr_write; if (tmp != -1) { /* MC16550II */ switch (idev->id_irq) { case IRQ3: irqout = 4; break; case IRQ5: irqout = 5; break; case IRQ6: irqout = 6; break; case IRQ12: irqout = 7; break; default: printf("sio%d: irq configuration error\n", dev->id_unit); return (0); } outb((dev->id_iobase & 0x00ff) | tmp, irqout); } port_shift = if_16550a_type[iod.if_type & 0x0f].port_shift; #endif bzero(failures, sizeof failures); #ifdef PC98 if (iod.if_type == COM_IF_RSA98III) iobase = dev->id_iobase + 8; else #endif iobase = dev->id_iobase; /* * We don't want to get actual interrupts, just masked ones. * Interrupts from this line should already be masked in the ICU, * but mask them in the processor as well in case there are some * (misconfigured) shared interrupts. */ disable_intr(); /* EXTRA DELAY? */ /* * Initialize the speed and the word size and wait long enough to * drain the maximum of 16 bytes of junk in device output queues. * The speed is undefined after a master reset and must be set * before relying on anything related to output. There may be * junk after a (very fast) soft reboot and (apparently) after * master reset. * XXX what about the UART bug avoided by waiting in comparam()? * We don't want to to wait long enough to drain at 2 bps. */ if (iobase == siocniobase) DELAY((16 + 1) * 1000000 / (comdefaultrate / 10)); else { #ifdef PC98 tmp = ttspeedtab(SIO_TEST_SPEED, if_16550a_type[iod.if_type & 0x0f].speedtab); outb(iobase + (com_cfcr << port_shift), CFCR_DLAB|CFCR_8BITS); outb(iobase + (com_dlbl << port_shift), tmp & 0xff); outb(iobase + (com_dlbh << port_shift), (tmp >> 8) & 0xff); outb(iobase + (com_cfcr << port_shift), CFCR_8BITS); #else outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS); outb(iobase + com_dlbl, COMBRD(SIO_TEST_SPEED) & 0xff); outb(iobase + com_dlbh, (u_int) COMBRD(SIO_TEST_SPEED) >> 8); outb(iobase + com_cfcr, CFCR_8BITS); #endif DELAY((16 + 1) * 1000000 / (SIO_TEST_SPEED / 10)); } /* * Enable the interrupt gate and disable device interupts. This * should leave the device driving the interrupt line low and * guarantee an edge trigger if an interrupt can be generated. */ /* EXTRA DELAY? */ #ifdef PC98 outb(iobase + (com_mcr << port_shift), mcr_image); outb(iobase + (com_ier << port_shift), 0); #else outb(iobase + com_mcr, mcr_image); outb(iobase + com_ier, 0); #endif DELAY(1000); /* XXX */ irqmap[0] = isa_irq_pending(); /* * Attempt to set loopback mode so that we can send a null byte * without annoying any external device. */ /* EXTRA DELAY? */ #ifdef PC98 outb(iobase + (com_mcr << port_shift), mcr_image | MCR_LOOPBACK); #else outb(iobase + com_mcr, mcr_image | MCR_LOOPBACK); #endif /* * Attempt to generate an output interrupt. On 8250's, setting * IER_ETXRDY generates an interrupt independent of the current * setting and independent of whether the THR is empty. On 16450's, * setting IER_ETXRDY generates an interrupt independent of the * current setting. On 16550A's, setting IER_ETXRDY only * generates an interrupt when IER_ETXRDY is not already set. */ #ifdef PC98 outb(iobase + (com_ier << port_shift), IER_ETXRDY); if (iod.if_type == COM_IF_RSA98III) { outb(rsabase + rsa_ier, 0x04); } #else outb(iobase + com_ier, IER_ETXRDY); #endif /* PC98 */ /* * On some 16x50 incompatibles, setting IER_ETXRDY doesn't generate * an interrupt. They'd better generate one for actually doing * output. Loopback may be broken on the same incompatibles but * it's unlikely to do more than allow the null byte out. */ #ifdef PC98 outb(iobase + (com_data << port_shift), 0); #else outb(iobase + com_data, 0); #endif DELAY((1 + 2) * 1000000 / (SIO_TEST_SPEED / 10)); /* * Turn off loopback mode so that the interrupt gate works again * (MCR_IENABLE was hidden). This should leave the device driving * an interrupt line high. It doesn't matter if the interrupt * line oscillates while we are not looking at it, since interrupts * are disabled. */ /* EXTRA DELAY? */ #ifdef PC98 outb(iobase + (com_mcr << port_shift), mcr_image); #else outb(iobase + com_mcr, mcr_image); #endif /* PC98 */ /* * It's a definitly Serial PCMCIA(16550A), but still be required * for IIR_TXRDY implementation ( Palido 321s, DC-1S... ) */ if ( COM_NOPROBE(dev) ) { /* Reading IIR register twice */ for ( fn = 0; fn < 2; fn ++ ) { DELAY(10000); #ifdef PC98 failures[6] = inb(iobase + (com_iir << port_shift)); #else failures[6] = inb(iobase + com_iir); #endif } /* Check IIR_TXRDY clear ? */ #ifdef PC98 result = if_16550a_type[iod.if_type & 0x0f].io_size; #else result = IO_COMSIZE; #endif if ( failures[6] & IIR_TXRDY ) { /* Nop, Double check with clearing IER */ #ifdef PC98 outb(iobase + (com_ier << port_shift), 0); if (inb(iobase + (com_iir << port_shift)) & IIR_NOPEND) { #else outb(iobase + com_ier, 0); if ( inb(iobase + com_iir) & IIR_NOPEND ) { #endif /* Ok. we're familia this gang */ dev->id_flags |= COM_C_IIR_TXRDYBUG; /* Set IIR_TXRDYBUG */ } else { /* Unknow, Just omit this chip.. XXX*/ result = 0; } } else { /* OK. this is well-known guys */ dev->id_flags &= ~COM_C_IIR_TXRDYBUG; /*Clear IIR_TXRDYBUG*/ } #ifdef PC98 outb(iobase + (com_cfcr << port_shift), CFCR_8BITS); #else outb(iobase + com_cfcr, CFCR_8BITS); #endif enable_intr(); return (iobase == siocniobase ? IO_COMSIZE : result); } /* * Check that * o the CFCR, IER and MCR in UART hold the values written to them * (the values happen to be all distinct - this is good for * avoiding false positive tests from bus echoes). * o an output interrupt is generated and its vector is correct. * o the interrupt goes away when the IIR in the UART is read. */ /* EXTRA DELAY? */ #ifdef PC98 failures[0] = inb(iobase + (com_cfcr << port_shift)) - CFCR_8BITS; failures[1] = inb(iobase + (com_ier << port_shift)) - IER_ETXRDY; failures[2] = inb(iobase + (com_mcr << port_shift)) - mcr_image; #else failures[0] = inb(iobase + com_cfcr) - CFCR_8BITS; failures[1] = inb(iobase + com_ier) - IER_ETXRDY; failures[2] = inb(iobase + com_mcr) - mcr_image; #endif DELAY(10000); /* Some internal modems need this time */ irqmap[1] = isa_irq_pending(); #ifdef PC98 failures[4] = (inb(iobase + (com_iir << port_shift)) & IIR_IMASK) - IIR_TXRDY; if (iod.if_type == COM_IF_RSA98III) { inb(rsabase + rsa_srr); } #else failures[4] = (inb(iobase + com_iir) & IIR_IMASK) - IIR_TXRDY; #endif DELAY(1000); /* XXX */ irqmap[2] = isa_irq_pending(); #ifdef PC98 failures[6] = (inb(iobase + (com_iir << port_shift)) & IIR_IMASK) - IIR_NOPEND; if (iod.if_type == COM_IF_RSA98III) { inb(rsabase + rsa_srr); } #else failures[6] = (inb(iobase + com_iir) & IIR_IMASK) - IIR_NOPEND; #endif /* * Turn off all device interrupts and check that they go off properly. * Leave MCR_IENABLE alone. For ports without a master port, it gates * the OUT2 output of the UART to * the ICU input. Closing the gate would give a floating ICU input * (unless there is another device driving at) and spurious interrupts. * (On the system that this was first tested on, the input floats high * and gives a (masked) interrupt as soon as the gate is closed.) */ #ifdef PC98 outb(iobase + (com_ier << port_shift), 0); outb(iobase + (com_cfcr << port_shift), CFCR_8BITS); failures[7] = inb(iobase + (com_ier << port_shift)); if (iod.if_type == COM_IF_RSA98III) { outb(rsabase + rsa_ier, 0x00); } #else outb(iobase + com_ier, 0); outb(iobase + com_cfcr, CFCR_8BITS); /* dummy to avoid bus echo */ failures[7] = inb(iobase + com_ier); #endif DELAY(1000); /* XXX */ irqmap[3] = isa_irq_pending(); #ifdef PC98 failures[9] = (inb(iobase + (com_iir << port_shift)) & IIR_IMASK) - IIR_NOPEND; if (iod.if_type == COM_IF_RSA98III) { inb(rsabase + rsa_srr); outb(rsabase + rsa_frr, 0x00); } #else failures[9] = (inb(iobase + com_iir) & IIR_IMASK) - IIR_NOPEND; #endif enable_intr(); irqs = irqmap[1] & ~irqmap[0]; if (idev->id_irq != 0 && (idev->id_irq & irqs) == 0) printf( "sio%d: configured irq %d not in bitmap of probed irqs %#x\n", dev->id_unit, ffs(idev->id_irq) - 1, irqs); if (bootverbose) printf("sio%d: irq maps: %#x %#x %#x %#x\n", dev->id_unit, irqmap[0], irqmap[1], irqmap[2], irqmap[3]); #ifdef PC98 result = if_16550a_type[iod.if_type & 0x0f].io_size; #else result = IO_COMSIZE; #endif for (fn = 0; fn < sizeof failures; ++fn) if (failures[fn]) { #ifdef PC98 outb(iobase + (com_mcr << port_shift), 0); #else outb(iobase + com_mcr, 0); #endif result = 0; if (bootverbose) { printf("sio%d: probe failed test(s):", dev->id_unit); for (fn = 0; fn < sizeof failures; ++fn) if (failures[fn]) printf(" %d", fn); printf("\n"); } break; } return (iobase == siocniobase ? IO_COMSIZE : result); } #ifdef COM_ESP static int espattach(isdp, com, esp_port) struct isa_device *isdp; struct com_s *com; Port_t esp_port; { u_char dips; u_char val; /* * Check the ESP-specific I/O port to see if we're an ESP * card. If not, return failure immediately. */ if ((inb(esp_port) & 0xf3) == 0) { printf(" port 0x%x is not an ESP board?\n", esp_port); return (0); } /* * We've got something that claims to be a Hayes ESP card. * Let's hope so. */ /* Get the dip-switch configuration */ #ifdef PC98 outb(esp_port + ESP98_CMD1, ESP_GETDIPS); dips = inb(esp_port + ESP98_STATUS1); #else outb(esp_port + ESP_CMD1, ESP_GETDIPS); dips = inb(esp_port + ESP_STATUS1); #endif /* * Bits 0,1 of dips say which COM port we are. */ #ifdef PC98 if ((com->iobase & 0xff) == likely_com_ports[dips & 0x03]) #else if (com->iobase == likely_com_ports[dips & 0x03]) #endif printf(" : ESP"); else { printf(" esp_port has com %d\n", dips & 0x03); return (0); } /* * Check for ESP version 2.0 or later: bits 4,5,6 = 010. */ #ifdef PC98 outb(esp_port + ESP98_CMD1, ESP_GETTEST); val = inb(esp_port + ESP98_STATUS1); /* clear reg 1 */ val = inb(esp_port + ESP98_STATUS2); #else outb(esp_port + ESP_CMD1, ESP_GETTEST); val = inb(esp_port + ESP_STATUS1); /* clear reg 1 */ val = inb(esp_port + ESP_STATUS2); #endif if ((val & 0x70) < 0x20) { printf("-old (%o)", val & 0x70); return (0); } /* * Check for ability to emulate 16550: bit 7 == 1 */ if ((dips & 0x80) == 0) { printf(" slave"); return (0); } /* * Okay, we seem to be a Hayes ESP card. Whee. */ com->esp = TRUE; com->esp_port = esp_port; return (1); } #endif /* COM_ESP */ static int sioattach(isdp) struct isa_device *isdp; { struct com_s *com; dev_t dev; #ifdef COM_ESP Port_t *espp; #endif Port_t iobase; int s; int unit; #ifdef PC98 int port_shift = 0; u_long ibufsize; #endif isdp->id_ointr = siointr; isdp->id_ri_flags |= RI_FAST; #ifdef PC98 if (((isdp->id_flags >> 24) & 0xff) == COM_IF_RSA98III) iobase = isdp->id_iobase + 8; else #endif iobase = isdp->id_iobase; unit = isdp->id_unit; #ifndef PC98 com = malloc(sizeof *com, M_TTYS, M_NOWAIT); #else ibufsize = RS_IBUFSIZE; if (((isdp->id_flags >> 24) & 0xff) == COM_IF_RSA98III) ibufsize = 2048; com = malloc((sizeof *com) + ibufsize * 6, M_TTYS, M_NOWAIT); #endif if (com == NULL) return (0); /* * sioprobe() has initialized the device registers as follows: * o cfcr = CFCR_8BITS. * It is most important that CFCR_DLAB is off, so that the * data port is not hidden when we enable interrupts. * o ier = 0. * Interrupts are only enabled when the line is open. * o mcr = MCR_IENABLE, or 0 if the port has AST/4 compatible * interrupt control register or the config specifies no irq. * Keeping MCR_DTR and MCR_RTS off might stop the external * device from sending before we are ready. */ bzero(com, sizeof *com); #ifdef PC98 com->CE_INPUT_OFFSET = ibufsize; com->ibuf1 = (u_char *)com + (sizeof *com); com->ibuf2 = com->ibuf1 + (ibufsize * 2); com->obuf1 = com->ibuf2 + (ibufsize * 2); com->obuf2 = com->obuf1 + ibufsize; bzero(com->ibuf1, ibufsize * 6); #endif com->unit = unit; com->cfcr_image = CFCR_8BITS; com->dtr_wait = 3 * hz; com->loses_outints = COM_LOSESOUTINTS(isdp) != 0; com->no_irq = isdp->id_irq == 0; com->tx_fifo_size = 1; com->iptr = com->ibuf = com->ibuf1; #ifndef PC98 com->ibufend = com->ibuf1 + RS_IBUFSIZE; com->ihighwater = com->ibuf1 + RS_IHIGHWATER; #else com->ibufend = com->ibuf1 + com->CE_INPUT_OFFSET; com->ihighwater = com->ibuf1 + (3 * com->CE_INPUT_OFFSET / 4); #endif com->obufs[0].l_head = com->obuf1; com->obufs[1].l_head = com->obuf2; com->iobase = iobase; #ifdef PC98 if (pc98_set_ioport(com, isdp->id_flags) == -1) { com->pc98_if_type = (isdp->id_flags >> 24) & 0xff; port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; com->data_port = iobase + (com_data << port_shift); com->int_id_port = iobase + (com_iir << port_shift); com->modem_ctl_port = iobase + (com_mcr << port_shift); com->mcr_image = inb(com->modem_ctl_port); com->line_status_port = iobase + (com_lsr << port_shift); com->modem_status_port = iobase + (com_msr << port_shift); com->intr_ctl_port = iobase + (com_ier << port_shift); } #else /* not PC98 */ com->data_port = iobase + com_data; com->int_id_port = iobase + com_iir; com->modem_ctl_port = iobase + com_mcr; com->mcr_image = inb(com->modem_ctl_port); com->line_status_port = iobase + com_lsr; com->modem_status_port = iobase + com_msr; com->intr_ctl_port = iobase + com_ier; #endif /* * We don't use all the flags from since they * are only relevant for logins. It's important to have echo off * initially so that the line doesn't start blathering before the * echo flag can be turned off. */ com->it_in.c_iflag = 0; com->it_in.c_oflag = 0; com->it_in.c_cflag = TTYDEF_CFLAG; com->it_in.c_lflag = 0; if (unit == comconsole) { #ifdef PC98 if (IS_8251(com->pc98_if_type)) DELAY(100000); #endif com->it_in.c_iflag = TTYDEF_IFLAG; com->it_in.c_oflag = TTYDEF_OFLAG; com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL; com->it_in.c_lflag = TTYDEF_LFLAG; com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL; com->lt_out.c_ispeed = com->lt_out.c_ospeed = com->lt_in.c_ispeed = com->lt_in.c_ospeed = com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate; } else com->it_in.c_ispeed = com->it_in.c_ospeed = TTYDEF_SPEED; termioschars(&com->it_in); com->it_out = com->it_in; /* attempt to determine UART type */ printf("sio%d: type", unit); #ifndef PC98 #ifdef COM_MULTIPORT if (!COM_ISMULTIPORT(isdp) && !COM_IIR_TXRDYBUG(isdp)) #else if (!COM_IIR_TXRDYBUG(isdp)) #endif { u_char scr; u_char scr1; u_char scr2; scr = inb(iobase + com_scr); outb(iobase + com_scr, 0xa5); scr1 = inb(iobase + com_scr); outb(iobase + com_scr, 0x5a); scr2 = inb(iobase + com_scr); outb(iobase + com_scr, scr); if (scr1 != 0xa5 || scr2 != 0x5a) { printf(" 8250"); goto determined_type; } } #endif /* !PC98 */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) { com_int_TxRx_disable( com ); com_cflag_and_speed_set( com, com->it_in.c_cflag, comdefaultrate ); com_tiocm_bic( com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE ); com_send_break_off( com ); printf(" 8251%s", if_8251_type[com->pc98_if_type & 0x0f].name); } else { outb(iobase + (com_fifo << port_shift), FIFO_ENABLE | FIFO_RX_HIGH); #else outb(iobase + com_fifo, FIFO_ENABLE | FIFO_RX_HIGH); #endif /* PC98 */ DELAY(100); com->st16650a = 0; switch (inb(com->int_id_port) & IIR_FIFO_MASK) { case FIFO_RX_LOW: printf(" 16450"); break; case FIFO_RX_MEDL: printf(" 16450?"); break; case FIFO_RX_MEDH: printf(" 16550?"); break; case FIFO_RX_HIGH: if (COM_NOFIFO(isdp)) { printf(" 16550A fifo disabled"); } else { com->hasfifo = TRUE; #ifdef PC98 com->tx_fifo_size = 0; /* XXX flag conflicts. */ printf(" 16550A"); #else if (COM_ST16650A(isdp)) { com->st16650a = 1; com->tx_fifo_size = 32; printf(" ST16650A"); } else { com->tx_fifo_size = COM_FIFOSIZE(isdp); printf(" 16550A"); } #endif } #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { com->tx_fifo_size = 2048; com->rsabase = isdp->id_iobase; outb(com->rsabase + rsa_ier, 0x00); outb(com->rsabase + rsa_frr, 0x00); } #endif #ifdef COM_ESP #ifdef PC98 if (com->pc98_if_type == COM_IF_ESP98) #endif for (espp = likely_esp_ports; *espp != 0; espp++) if (espattach(isdp, com, *espp)) { com->tx_fifo_size = 1024; break; } #endif if (!com->st16650a) { if (!com->tx_fifo_size) com->tx_fifo_size = 16; else printf(" lookalike with %d bytes FIFO", com->tx_fifo_size); } break; } #ifdef PC98 if (com->pc98_if_type == COM_IF_RSB3000) { /* Set RSB-2000/3000 Extended Buffer mode. */ u_char lcr; lcr = inb(iobase + (com_cfcr << port_shift)); outb(iobase + (com_cfcr << port_shift), lcr | CFCR_DLAB); outb(iobase + (com_emr << port_shift), EMR_EXBUFF | EMR_EFMODE); outb(iobase + (com_cfcr << port_shift), lcr); } #endif #ifdef COM_ESP if (com->esp) { /* * Set 16550 compatibility mode. * We don't use the ESP_MODE_SCALE bit to increase the * fifo trigger levels because we can't handle large * bursts of input. * XXX flow control should be set in comparam(), not here. */ #ifdef PC98 outb(com->esp_port + ESP98_CMD1, ESP_SETMODE); outb(com->esp_port + ESP98_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO); #else outb(com->esp_port + ESP_CMD1, ESP_SETMODE); outb(com->esp_port + ESP_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO); #endif /* Set RTS/CTS flow control. */ #ifdef PC98 outb(com->esp_port + ESP98_CMD1, ESP_SETFLOWTYPE); outb(com->esp_port + ESP98_CMD2, ESP_FLOW_RTS); outb(com->esp_port + ESP98_CMD2, ESP_FLOW_CTS); #else outb(com->esp_port + ESP_CMD1, ESP_SETFLOWTYPE); outb(com->esp_port + ESP_CMD2, ESP_FLOW_RTS); outb(com->esp_port + ESP_CMD2, ESP_FLOW_CTS); #endif /* Set flow-control levels. */ #ifdef PC98 outb(com->esp_port + ESP98_CMD1, ESP_SETRXFLOW); outb(com->esp_port + ESP98_CMD2, HIBYTE(768)); outb(com->esp_port + ESP98_CMD2, LOBYTE(768)); outb(com->esp_port + ESP98_CMD2, HIBYTE(512)); outb(com->esp_port + ESP98_CMD2, LOBYTE(512)); #else outb(com->esp_port + ESP_CMD1, ESP_SETRXFLOW); outb(com->esp_port + ESP_CMD2, HIBYTE(768)); outb(com->esp_port + ESP_CMD2, LOBYTE(768)); outb(com->esp_port + ESP_CMD2, HIBYTE(512)); outb(com->esp_port + ESP_CMD2, LOBYTE(512)); #endif #ifdef PC98 /* Set UART clock prescaler. */ outb(com->esp_port + ESP98_CMD1, ESP_SETCLOCK); outb(com->esp_port + ESP98_CMD2, 2); /* 4 times */ #endif } #endif /* COM_ESP */ #ifdef PC98 printf("%s", if_16550a_type[com->pc98_if_type & 0x0f].name); outb(iobase + (com_fifo << port_shift), 0); #else outb(iobase + com_fifo, 0); #endif determined_type: ; #ifdef COM_MULTIPORT if (COM_ISMULTIPORT(isdp)) { com->multiport = TRUE; printf(" (multiport"); if (unit == COM_MPMASTER(isdp)) printf(" master"); printf(")"); com->no_irq = find_isadev(isa_devtab_tty, &siodriver, COM_MPMASTER(isdp))->id_irq == 0; } #endif /* COM_MULTIPORT */ #ifdef PC98 } #endif if (unit == comconsole) printf(", console"); if ( COM_IIR_TXRDYBUG(isdp) ) printf(" with a bogus IIR_TXRDY register"); printf("\n"); s = spltty(); com_addr(unit) = com; splx(s); if (!sio_registered) { dev = makedev(CDEV_MAJOR, 0); cdevsw_add(&dev, &sio_cdevsw, NULL); register_swi(SWI_TTY, siopoll); sio_registered = TRUE; } #ifdef DEVFS com->devfs_token_ttyd = devfs_add_devswf(&sio_cdevsw, unit, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit); com->devfs_token_ttyi = devfs_add_devswf(&sio_cdevsw, unit | CONTROL_INIT_STATE, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit); com->devfs_token_ttyl = devfs_add_devswf(&sio_cdevsw, unit | CONTROL_LOCK_STATE, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit); com->devfs_token_cuaa = devfs_add_devswf(&sio_cdevsw, unit | CALLOUT_MASK, DV_CHR, UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit); com->devfs_token_cuai = devfs_add_devswf(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_INIT_STATE, DV_CHR, UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit); com->devfs_token_cual = devfs_add_devswf(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_LOCK_STATE, DV_CHR, UID_UUCP, GID_DIALER, 0660, "cuala%r", unit); #endif com->id_flags = isdp->id_flags; /* Heritate id_flags for later */ return (1); } static int sioopen(dev, flag, mode, p) dev_t dev; int flag; int mode; struct proc *p; { struct com_s *com; int error; Port_t iobase; int mynor; int s; struct tty *tp; int unit; #ifdef PC98 int port_shift = 0; #endif mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); if ((u_int) unit >= NSIOTOT || (com = com_addr(unit)) == NULL) return (ENXIO); if (com->gone) return (ENXIO); if (mynor & CONTROL_MASK) return (0); #if 0 /* XXX */ tp = com->tp = sio_tty[unit] = ttymalloc(sio_tty[unit]); #else tp = com->tp = &sio_tty[unit]; #endif s = spltty(); #ifdef PC98 if (!IS_8251(com->pc98_if_type)) port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; #endif /* * We jump to this label after all non-interrupted sleeps to pick * up any changes of the device state. */ open_top: while (com->state & CS_DTR_OFF) { error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "siodtr", 0); if (com_addr(unit) == NULL) return (ENXIO); if (error != 0 || com->gone) goto out; } if (tp->t_state & TS_ISOPEN) { /* * The device is open, so everything has been initialized. * Handle conflicts. */ if (mynor & CALLOUT_MASK) { if (!com->active_out) { error = EBUSY; goto out; } } else { if (com->active_out) { if (flag & O_NONBLOCK) { error = EBUSY; goto out; } error = tsleep(&com->active_out, TTIPRI | PCATCH, "siobi", 0); if (com_addr(unit) == NULL) return (ENXIO); if (error != 0 || com->gone) goto out; goto open_top; } } if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) { error = EBUSY; goto out; } } else { /* * The device isn't open, so there are no conflicts. * Initialize it. Initialization is done twice in many * cases: to preempt sleeping callin opens if we are * callout, and to complete a callin open after DCD rises. */ tp->t_oproc = comstart; tp->t_param = comparam; tp->t_dev = dev; tp->t_termios = mynor & CALLOUT_MASK ? com->it_out : com->it_in; #ifndef PC98 tp->t_ififosize = 2 * RS_IBUFSIZE; #else tp->t_ififosize = 2 * com->CE_INPUT_OFFSET; #endif tp->t_ispeedwat = (speed_t)-1; tp->t_ospeedwat = (speed_t)-1; #ifdef PC98 if (!IS_8251(com->pc98_if_type)) #endif (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET); com->poll = com->no_irq; com->poll_output = com->loses_outints; ++com->wopeners; error = comparam(tp, &tp->t_termios); --com->wopeners; if (error != 0) goto out; #ifdef PC98 if (IS_8251(com->pc98_if_type)) { com_tiocm_bis(com, TIOCM_DTR|TIOCM_RTS); pc98_msrint_start(dev); } #endif /* * XXX we should goto open_top if comparam() slept. */ iobase = com->iobase; if (com->hasfifo) { /* * (Re)enable and drain fifos. * * Certain SMC chips cause problems if the fifos * are enabled while input is ready. Turn off the * fifo if necessary to clear the input. We test * the input ready bit after enabling the fifos * since we've already enabled them in comparam() * and to handle races between enabling and fresh * input. */ while (TRUE) { #ifdef PC98 outb(iobase + (com_fifo << port_shift), FIFO_RCV_RST | FIFO_XMT_RST | com->fifo_image); if (com->pc98_if_type == COM_IF_RSA98III) outb(com->rsabase + rsa_frr , 0x00); #else outb(iobase + com_fifo, FIFO_RCV_RST | FIFO_XMT_RST | com->fifo_image); #endif /* * XXX the delays are for superstitious * historical reasons. It must be less than * the character time at the maximum * supported speed (87 usec at 115200 bps * 8N1). Otherwise we might loop endlessly * if data is streaming in. We used to use * delays of 100. That usually worked * because DELAY(100) used to usually delay * for about 85 usec instead of 100. */ DELAY(50); #ifndef PC98 if (!(inb(com->line_status_port) & LSR_RXRDY)) #else if (com->pc98_if_type == COM_IF_RSA98III ? !(inb(com->rsabase + rsa_srr) & 0x08) : !(inb(com->line_status_port) & LSR_RXRDY)) #endif break; #ifdef PC98 outb(iobase + (com_fifo << port_shift), 0); #else outb(iobase + com_fifo, 0); #endif DELAY(50); (void) inb(com->data_port); } } disable_intr(); #ifdef PC98 if (IS_8251(com->pc98_if_type)) { com_tiocm_bis(com, TIOCM_LE); com->pc98_prev_modem_status = pc98_get_modem_status(com); com_int_Rx_enable(com); } else { #endif (void) inb(com->line_status_port); (void) inb(com->data_port); com->prev_modem_status = com->last_modem_status = inb(com->modem_status_port); if (COM_IIR_TXRDYBUG(com)) { outb(com->intr_ctl_port, IER_ERXRDY | IER_ERLS | IER_EMSC); } else { outb(com->intr_ctl_port, IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC); } #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { outb(com->rsabase + rsa_ier, 0x1d); outb(com->intr_ctl_port, IER_ERLS | IER_EMSC); } #endif #ifdef PC98 } #endif enable_intr(); /* * Handle initial DCD. Callout devices get a fake initial * DCD (trapdoor DCD). If we are callout, then any sleeping * callin opens get woken up and resume sleeping on "siobi" * instead of "siodcd". */ /* * XXX `mynor & CALLOUT_MASK' should be * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where * TRAPDOOR_CARRIER is the default initial state for callout * devices and SOFT_CARRIER is like CLOCAL except it hides * the true carrier. */ #ifdef PC98 if ((IS_8251(com->pc98_if_type) && (pc98_get_modem_status(com) & TIOCM_CAR)) || (!IS_8251(com->pc98_if_type) && (com->prev_modem_status & MSR_DCD)) || mynor & CALLOUT_MASK) #else if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK) #endif (*linesw[tp->t_line].l_modem)(tp, 1); } /* * Wait for DCD if necessary. */ if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) { ++com->wopeners; error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "siodcd", 0); if (com_addr(unit) == NULL) return (ENXIO); --com->wopeners; if (error != 0 || com->gone) goto out; goto open_top; } error = (*linesw[tp->t_line].l_open)(dev, tp); disc_optim(tp, &tp->t_termios, com); if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK) com->active_out = TRUE; siosettimeout(); out: splx(s); if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0) comhardclose(com); return (error); } static int sioclose(dev, flag, mode, p) dev_t dev; int flag; int mode; struct proc *p; { struct com_s *com; int mynor; int s; struct tty *tp; mynor = minor(dev); if (mynor & CONTROL_MASK) return (0); com = com_addr(MINOR_TO_UNIT(mynor)); tp = com->tp; s = spltty(); (*linesw[tp->t_line].l_close)(tp, flag); #ifdef PC98 com->modem_checking = 0; #endif disc_optim(tp, &tp->t_termios, com); siostop(tp, FREAD | FWRITE); comhardclose(com); ttyclose(tp); siosettimeout(); splx(s); if (com->gone) { printf("sio%d: gone\n", com->unit); s = spltty(); com_addr(com->unit) = 0; bzero(tp,sizeof *tp); bzero(com,sizeof *com); free(com,M_TTYS); splx(s); } return (0); } static void comhardclose(com) struct com_s *com; { Port_t iobase; int s; struct tty *tp; int unit; #ifdef PC98 int port_shift = 0; #endif unit = com->unit; iobase = com->iobase; s = spltty(); com->poll = FALSE; com->poll_output = FALSE; com->do_timestamp = FALSE; com->do_dcd_timestamp = FALSE; #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_send_break_off(com); else { port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; outb(iobase + (com_cfcr << port_shift), com->cfcr_image &= ~CFCR_SBREAK); } #else outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); #endif { #ifdef PC98 int tmp; if (IS_8251(com->pc98_if_type)) com_int_TxRx_disable(com); else outb(iobase + (com_ier << port_shift), 0); if (com->pc98_if_type == COM_IF_RSA98III) { outb(com->rsabase + rsa_ier, 0x00); } #else outb(iobase + com_ier, 0); #endif tp = com->tp; #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = pc98_get_modem_status(com) & TIOCM_CAR; else tmp = com->prev_modem_status & MSR_DCD; #endif if (tp->t_cflag & HUPCL /* * XXX we will miss any carrier drop between here and the * next open. Perhaps we should watch DCD even when the * port is closed; it is not sufficient to check it at * the next open because it might go up and down while * we're not watching. */ || !com->active_out #ifdef PC98 && !(tmp) #else && !(com->prev_modem_status & MSR_DCD) #endif && !(com->it_in.c_cflag & CLOCAL) || !(tp->t_state & TS_ISOPEN)) { #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE); else #endif (void)commctl(com, TIOCM_DTR, DMBIC); if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) { timeout(siodtrwakeup, com, com->dtr_wait); com->state |= CS_DTR_OFF; } } #ifdef PC98 else { if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_LE ); } #endif } if (com->hasfifo) { /* * Disable fifos so that they are off after controlled * reboots. Some BIOSes fail to detect 16550s when the * fifos are enabled. */ #ifdef PC98 outb(iobase + (com_fifo << port_shift), 0); #else outb(iobase + com_fifo, 0); #endif } com->active_out = FALSE; wakeup(&com->active_out); wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */ splx(s); } static int sioread(dev, uio, flag) dev_t dev; struct uio *uio; int flag; { int mynor; int unit; struct tty *tp; mynor = minor(dev); if (mynor & CONTROL_MASK) return (ENODEV); unit = MINOR_TO_UNIT(mynor); if (com_addr(unit)->gone) return (ENODEV); tp = com_addr(unit)->tp; return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); } static int siowrite(dev, uio, flag) dev_t dev; struct uio *uio; int flag; { int mynor; struct tty *tp; int unit; mynor = minor(dev); if (mynor & CONTROL_MASK) return (ENODEV); unit = MINOR_TO_UNIT(mynor); if (com_addr(unit)->gone) return (ENODEV); tp = com_addr(unit)->tp; /* * (XXX) We disallow virtual consoles if the physical console is * a serial port. This is in case there is a display attached that * is not the console. In that situation we don't need/want the X * server taking over the console. */ if (constty != NULL && unit == comconsole) constty = NULL; return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); } static void siobusycheck(chan) void *chan; { struct com_s *com; int s; com = (struct com_s *)chan; /* * Clear TS_BUSY if low-level output is complete. * spl locking is sufficient because siointr1() does not set CS_BUSY. * If siointr1() clears CS_BUSY after we look at it, then we'll get * called again. Reading the line status port outside of siointr1() * is safe because CS_BUSY is clear so there are no output interrupts * to lose. */ s = spltty(); if (com->state & CS_BUSY) com->extra_state &= ~CSE_BUSYCHECK; /* False alarm. */ #ifdef PC98 else if (IS_8251(com->pc98_if_type) && (inb(com->sts_port) & (STS8251_TxRDY | STS8251_TxEMP)) == (STS8251_TxRDY | STS8251_TxEMP) || (inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY)) == (LSR_TSRE | LSR_TXRDY)) { #else else if ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY)) == (LSR_TSRE | LSR_TXRDY)) { #endif com->tp->t_state &= ~TS_BUSY; ttwwakeup(com->tp); com->extra_state &= ~CSE_BUSYCHECK; } else timeout(siobusycheck, com, hz / 100); splx(s); } static void siodtrwakeup(chan) void *chan; { struct com_s *com; com = (struct com_s *)chan; com->state &= ~CS_DTR_OFF; wakeup(&com->dtr_wait); } static void siointr(unit) int unit; { #ifndef COM_MULTIPORT COM_LOCK(); siointr1(com_addr(unit)); COM_UNLOCK(); #else /* COM_MULTIPORT */ struct com_s *com; bool_t possibly_more_intrs; #ifdef PC98 u_char rsa_buf_status; #endif /* * Loop until there is no activity on any port. This is necessary * to get an interrupt edge more than to avoid another interrupt. * If the IRQ signal is just an OR of the IRQ signals from several * devices, then the edge from one may be lost because another is * on. */ COM_LOCK(); do { possibly_more_intrs = FALSE; for (unit = 0; unit < NSIOTOT; ++unit) { com = com_addr(unit); /* * XXX COM_LOCK(); * would it work here, or be counter-productive? */ #ifdef PC98 if (com != NULL && !com->gone && IS_8251(com->pc98_if_type)){ siointr1(com); } else #endif /* PC98 */ #ifdef PC98 if (com != NULL && !com->gone && com->pc98_if_type == COM_IF_RSA98III) { rsa_buf_status = inb(com->rsabase + rsa_srr) & 0xc9; if ((rsa_buf_status & 0xc8) || !(rsa_buf_status & 0x01)) { siointr1(com); if(rsa_buf_status != (inb(com->rsabase + rsa_srr) & 0xc9)) possibly_more_intrs = TRUE; } } else #endif if (com != NULL && !com->gone && (inb(com->int_id_port) & IIR_IMASK) != IIR_NOPEND) { siointr1(com); possibly_more_intrs = TRUE; } /* XXX COM_UNLOCK(); */ } } while (possibly_more_intrs); COM_UNLOCK(); #endif /* COM_MULTIPORT */ } static void siointr1(com) struct com_s *com; { u_char line_status; u_char modem_status; u_char *ioptr; u_char recv_data; u_char int_ctl; u_char int_ctl_new; #ifdef PC98 u_char tmp=0; u_char rsa_buf_status = 0; int rsa_tx_fifo_size=0; recv_data=0; #endif /* PC98 */ int_ctl = inb(com->intr_ctl_port); int_ctl_new = int_ctl; while (!com->gone) { #ifdef PC98 status_read:; if (IS_8251(com->pc98_if_type)) { tmp = inb(com->sts_port); more_intr: line_status = 0; if (tmp & STS8251_TxRDY) line_status |= LSR_TXRDY; if (tmp & STS8251_RxRDY) line_status |= LSR_RXRDY; if (tmp & STS8251_TxEMP) line_status |= LSR_TSRE; if (tmp & STS8251_PE) line_status |= LSR_PE; if (tmp & STS8251_OE) line_status |= LSR_OE; if (tmp & STS8251_FE) line_status |= LSR_FE; if (tmp & STS8251_BD_SD) line_status |= LSR_BI; } else #endif /* PC98 */ line_status = inb(com->line_status_port); #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) rsa_buf_status = inb(com->rsabase + rsa_srr); #endif /* PC98 */ /* input event? (check first to help avoid overruns) */ #ifndef PC98 while (line_status & LSR_RCV_MASK) { #else while ((line_status & LSR_RCV_MASK) || (com->pc98_if_type == COM_IF_RSA98III && (rsa_buf_status & 0x08))) { #endif /* PC98 */ /* break/unnattached error bits or real input? */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) { recv_data = inb(com->data_port); if (tmp & 0x78) { pc98_i8251_or_cmd(com,CMD8251_ER); recv_data = 0; } } else { #endif /* PC98 */ #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { if (!(rsa_buf_status & 0x08)) recv_data = 0; else { recv_data = inb(com->data_port); } } else #endif if (!(line_status & LSR_RXRDY)) recv_data = 0; else recv_data = inb(com->data_port); #ifdef PC98 } #endif if (line_status & (LSR_BI | LSR_FE | LSR_PE)) { /* * Don't store BI if IGNBRK or FE/PE if IGNPAR. * Otherwise, push the work to a higher level * (to handle PARMRK) if we're bypassing. * Otherwise, convert BI/FE and PE+INPCK to 0. * * This makes bypassing work right in the * usual "raw" case (IGNBRK set, and IGNPAR * and INPCK clear). * * Note: BI together with FE/PE means just BI. */ if (line_status & LSR_BI) { #if defined(DDB) && defined(BREAK_TO_DEBUGGER) if (com->unit == comconsole) { breakpoint(); goto cont; } #endif if (com->tp == NULL || com->tp->t_iflag & IGNBRK) goto cont; } else { if (com->tp == NULL || com->tp->t_iflag & IGNPAR) goto cont; } if (com->tp->t_state & TS_CAN_BYPASS_L_RINT && (line_status & (LSR_BI | LSR_FE) || com->tp->t_iflag & INPCK)) recv_data = 0; } ++com->bytes_in; if (com->hotchar != 0 && recv_data == com->hotchar) setsofttty(); ioptr = com->iptr; if (ioptr >= com->ibufend) CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW); else { if (com->do_timestamp) microtime(&com->timestamp); ++com_events; schedsofttty(); #if 0 /* for testing input latency vs efficiency */ if (com->iptr - com->ibuf == 8) setsofttty(); #endif ioptr[0] = recv_data; #ifdef PC98 ioptr[com->CE_INPUT_OFFSET] = line_status; #else ioptr[CE_INPUT_OFFSET] = line_status; #endif com->iptr = ++ioptr; if (ioptr == com->ihighwater && com->state & CS_RTS_IFLOW) #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS); if (line_status & LSR_OE) CE_RECORD(com, CE_OVERRUN); } cont: /* * "& 0x7F" is to avoid the gcc-1.40 generating a slow * jump from the top of the loop to here */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) goto status_read; else #endif line_status = inb(com->line_status_port) & 0x7F; #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) rsa_buf_status = inb(com->rsabase + rsa_srr); #endif /* PC98 */ } /* modem status change? (always check before doing output) */ #ifdef PC98 if (!IS_8251(com->pc98_if_type)) { #endif modem_status = inb(com->modem_status_port); if (modem_status != com->last_modem_status) { if (com->do_dcd_timestamp && !(com->last_modem_status & MSR_DCD) && modem_status & MSR_DCD) microtime(&com->dcd_timestamp); /* * Schedule high level to handle DCD changes. Note * that we don't use the delta bits anywhere. Some * UARTs mess them up, and it's easy to remember the * previous bits and calculate the delta. */ com->last_modem_status = modem_status; if (!(com->state & CS_CHECKMSR)) { com_events += LOTS_OF_EVENTS; com->state |= CS_CHECKMSR; setsofttty(); } /* handle CTS change immediately for crisp flow ctl */ if (com->state & CS_CTS_OFLOW) { if (modem_status & MSR_CTS) com->state |= CS_ODEVREADY; else com->state &= ~CS_ODEVREADY; } } #ifdef PC98 } #endif /* output queued and everything ready? */ #ifndef PC98 if (line_status & LSR_TXRDY && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) { #else if (((com->pc98_if_type == COM_IF_RSA98III) ? (rsa_buf_status & 0x02) : (line_status & LSR_TXRDY)) && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) { #endif ioptr = com->obufq.l_head; if (com->tx_fifo_size > 1) { u_int ocount; ocount = com->obufq.l_tail - ioptr; #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { rsa_buf_status = inb(com->rsabase + rsa_srr); rsa_tx_fifo_size = 1024; if (!(rsa_buf_status & 0x01)) rsa_tx_fifo_size = 2048; if (ocount > rsa_tx_fifo_size) ocount = rsa_tx_fifo_size; } else #endif if (ocount > com->tx_fifo_size) ocount = com->tx_fifo_size; com->bytes_out += ocount; do outb(com->data_port, *ioptr++); while (--ocount != 0); } else { outb(com->data_port, *ioptr++); ++com->bytes_out; } #ifdef PC98 if (IS_8251(com->pc98_if_type)) if (!(pc98_check_i8251_interrupt(com) & IEN_TxFLAG)) com_int_Tx_enable(com); #endif com->obufq.l_head = ioptr; if (COM_IIR_TXRDYBUG(com)) { int_ctl_new = int_ctl | IER_ETXRDY; } if (ioptr >= com->obufq.l_tail) { struct lbq *qp; qp = com->obufq.l_next; qp->l_queued = FALSE; qp = qp->l_next; if (qp != NULL) { com->obufq.l_head = qp->l_head; com->obufq.l_tail = qp->l_tail; com->obufq.l_next = qp; } else { /* output just completed */ if ( COM_IIR_TXRDYBUG(com) ) { int_ctl_new = int_ctl & ~IER_ETXRDY; } com->state &= ~CS_BUSY; #if defined(PC98) if (IS_8251(com->pc98_if_type)) if ( pc98_check_i8251_interrupt(com) & IEN_TxFLAG ) com_int_Tx_disable(com); #endif } if (!(com->state & CS_ODONE)) { com_events += LOTS_OF_EVENTS; com->state |= CS_ODONE; setsofttty(); /* handle at high level ASAP */ } } if ( COM_IIR_TXRDYBUG(com) && (int_ctl != int_ctl_new)) { if (com->pc98_if_type == COM_IF_RSA98III) { int_ctl_new &= ~(IER_ETXRDY | IER_ERXRDY); outb(com->intr_ctl_port, int_ctl_new); outb(com->rsabase + rsa_ier, 0x1d); } else outb(com->intr_ctl_port, int_ctl_new); } } #ifdef PC98 else if (line_status & LSR_TXRDY) { if (IS_8251(com->pc98_if_type)) if ( pc98_check_i8251_interrupt(com) & IEN_TxFLAG ) com_int_Tx_disable(com); } if (IS_8251(com->pc98_if_type)) if ((tmp = inb(com->sts_port)) & STS8251_RxRDY) goto more_intr; #endif /* finished? */ #ifndef COM_MULTIPORT #ifdef PC98 if (IS_8251(com->pc98_if_type)) return; #endif if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND) #endif /* COM_MULTIPORT */ return; } } static int sioioctl(dev, cmd, data, flag, p) dev_t dev; u_long cmd; caddr_t data; int flag; struct proc *p; { struct com_s *com; int error; Port_t iobase; int mynor; int s; struct tty *tp; #if defined(COMPAT_43) || defined(COMPAT_SUNOS) int oldcmd; struct termios term; #endif mynor = minor(dev); com = com_addr(MINOR_TO_UNIT(mynor)); if (com->gone) return (ENODEV); iobase = com->iobase; if (mynor & CONTROL_MASK) { struct termios *ct; switch (mynor & CONTROL_MASK) { case CONTROL_INIT_STATE: ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in; break; case CONTROL_LOCK_STATE: ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in; break; default: return (ENODEV); /* /dev/nodev */ } switch (cmd) { case TIOCSETA: error = suser(p->p_ucred, &p->p_acflag); if (error != 0) return (error); *ct = *(struct termios *)data; return (0); case TIOCGETA: *(struct termios *)data = *ct; return (0); case TIOCGETD: *(int *)data = TTYDISC; return (0); case TIOCGWINSZ: bzero(data, sizeof(struct winsize)); return (0); default: return (ENOTTY); } } tp = com->tp; #if defined(COMPAT_43) || defined(COMPAT_SUNOS) term = tp->t_termios; oldcmd = cmd; error = ttsetcompat(tp, &cmd, data, &term); if (error != 0) return (error); if (cmd != oldcmd) data = (caddr_t)&term; #endif if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) { int cc; struct termios *dt = (struct termios *)data; struct termios *lt = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in; dt->c_iflag = (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag); dt->c_oflag = (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag); dt->c_cflag = (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag); dt->c_lflag = (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag); for (cc = 0; cc < NCCS; ++cc) if (lt->c_cc[cc] != 0) dt->c_cc[cc] = tp->t_cc[cc]; if (lt->c_ispeed != 0) dt->c_ispeed = tp->t_ispeed; if (lt->c_ospeed != 0) dt->c_ospeed = tp->t_ospeed; } error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); if (error != ENOIOCTL) return (error); s = spltty(); error = ttioctl(tp, cmd, data, flag); disc_optim(tp, &tp->t_termios, com); if (error != ENOIOCTL) { splx(s); return (error); } #ifdef PC98 if (IS_8251(com->pc98_if_type)) { switch (cmd) { case TIOCSBRK: com_send_break_on( com ); break; case TIOCCBRK: com_send_break_off( com ); break; case TIOCSDTR: com_tiocm_bis(com, TIOCM_DTR | TIOCM_RTS ); break; case TIOCCDTR: com_tiocm_bic(com, TIOCM_DTR); break; /* * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The * changes get undone on the next call to comparam(). */ case TIOCMSET: com_tiocm_set( com, *(int *)data ); break; case TIOCMBIS: com_tiocm_bis( com, *(int *)data ); break; case TIOCMBIC: com_tiocm_bic( com, *(int *)data ); break; case TIOCMGET: *(int *)data = com_tiocm_get(com); break; case TIOCMSDTRWAIT: /* must be root since the wait applies to following logins */ error = suser(p->p_ucred, &p->p_acflag); if (error != 0) { splx(s); return (error); } com->dtr_wait = *(int *)data * hz / 100; break; case TIOCMGDTRWAIT: *(int *)data = com->dtr_wait * 100 / hz; break; case TIOCTIMESTAMP: com->do_timestamp = TRUE; *(struct timeval *)data = com->timestamp; break; case TIOCDCDTIMESTAMP: com->do_dcd_timestamp = TRUE; *(struct timeval *)data = com->dcd_timestamp; break; default: splx(s); return (ENOTTY); } } else { int port_shift; port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; #endif switch (cmd) { case TIOCSBRK: #ifdef PC98 outb(iobase + (com_cfcr << port_shift), com->cfcr_image |= CFCR_SBREAK); #else outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK); #endif break; case TIOCCBRK: #ifdef PC98 outb(iobase + (com_cfcr << port_shift), com->cfcr_image &= ~CFCR_SBREAK); #else outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK); #endif break; case TIOCSDTR: (void)commctl(com, TIOCM_DTR, DMBIS); break; case TIOCCDTR: (void)commctl(com, TIOCM_DTR, DMBIC); break; /* * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The * changes get undone on the next call to comparam(). */ case TIOCMSET: (void)commctl(com, *(int *)data, DMSET); break; case TIOCMBIS: (void)commctl(com, *(int *)data, DMBIS); break; case TIOCMBIC: (void)commctl(com, *(int *)data, DMBIC); break; case TIOCMGET: *(int *)data = commctl(com, 0, DMGET); break; case TIOCMSDTRWAIT: /* must be root since the wait applies to following logins */ error = suser(p->p_ucred, &p->p_acflag); if (error != 0) { splx(s); return (error); } com->dtr_wait = *(int *)data * hz / 100; break; case TIOCMGDTRWAIT: *(int *)data = com->dtr_wait * 100 / hz; break; case TIOCTIMESTAMP: com->do_timestamp = TRUE; *(struct timeval *)data = com->timestamp; break; case TIOCDCDTIMESTAMP: com->do_dcd_timestamp = TRUE; *(struct timeval *)data = com->dcd_timestamp; break; default: splx(s); return (ENOTTY); } #ifdef PC98 } #endif splx(s); return (0); } static void siopoll() { int unit; if (com_events == 0) return; repeat: for (unit = 0; unit < NSIOTOT; ++unit) { u_char *buf; struct com_s *com; u_char *ibuf; int incc; struct tty *tp; #ifdef PC98 int tmp; #endif com = com_addr(unit); if (com == NULL) continue; tp = com->tp; if (tp == NULL || com->gone) { /* * Discard any events related to never-opened or * going-away devices. */ disable_intr(); incc = com->iptr - com->ibuf; com->iptr = com->ibuf; if (com->state & CS_CHECKMSR) { incc += LOTS_OF_EVENTS; com->state &= ~CS_CHECKMSR; } com_events -= incc; enable_intr(); continue; } /* switch the role of the low-level input buffers */ if (com->iptr == (ibuf = com->ibuf)) { buf = NULL; /* not used, but compiler can't tell */ incc = 0; } else { buf = ibuf; disable_intr(); incc = com->iptr - buf; com_events -= incc; if (ibuf == com->ibuf1) ibuf = com->ibuf2; else ibuf = com->ibuf1; #ifndef PC98 com->ibufend = ibuf + RS_IBUFSIZE; com->ihighwater = ibuf + RS_IHIGHWATER; #else com->ibufend = ibuf + com->CE_INPUT_OFFSET; com->ihighwater = ibuf + (3 * com->CE_INPUT_OFFSET / 4); #endif com->iptr = ibuf; /* * There is now room for another low-level buffer full * of input, so enable RTS if it is now disabled and * there is room in the high-level buffer. */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = com_tiocm_get(com) & TIOCM_RTS; else tmp = com->mcr_image & MCR_RTS; #endif if ((com->state & CS_RTS_IFLOW) #ifdef PC98 && !(tmp) #else && !(com->mcr_image & MCR_RTS) #endif && !(tp->t_state & TS_TBLOCK)) #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bis(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS); enable_intr(); com->ibuf = ibuf; } if (com->state & CS_CHECKMSR) { u_char delta_modem_status; #ifdef PC98 if (!IS_8251(com->pc98_if_type)) { #endif disable_intr(); delta_modem_status = com->last_modem_status ^ com->prev_modem_status; com->prev_modem_status = com->last_modem_status; com_events -= LOTS_OF_EVENTS; com->state &= ~CS_CHECKMSR; enable_intr(); if (delta_modem_status & MSR_DCD) (*linesw[tp->t_line].l_modem) (tp, com->prev_modem_status & MSR_DCD); #ifdef PC98 } #endif } if (com->state & CS_ODONE) { disable_intr(); com_events -= LOTS_OF_EVENTS; com->state &= ~CS_ODONE; enable_intr(); if (!(com->state & CS_BUSY) && !(com->extra_state & CSE_BUSYCHECK)) { timeout(siobusycheck, com, hz / 100); com->extra_state |= CSE_BUSYCHECK; } (*linesw[tp->t_line].l_start)(tp); } if (incc <= 0 || !(tp->t_state & TS_ISOPEN) || !(tp->t_cflag & CREAD)) continue; /* * Avoid the grotesquely inefficient lineswitch routine * (ttyinput) in "raw" mode. It usually takes about 450 * instructions (that's without canonical processing or echo!). * slinput is reasonably fast (usually 40 instructions plus * call overhead). */ if (tp->t_state & TS_CAN_BYPASS_L_RINT) { if (tp->t_rawq.c_cc + incc > tp->t_ihiwat && (com->state & CS_RTS_IFLOW || tp->t_iflag & IXOFF) && !(tp->t_state & TS_TBLOCK)) ttyblock(tp); tk_nin += incc; tk_rawcc += incc; tp->t_rawcc += incc; com->delta_error_counts[CE_TTY_BUF_OVERFLOW] += b_to_q((char *)buf, incc, &tp->t_rawq); ttwakeup(tp); if (tp->t_state & TS_TTSTOP && (tp->t_iflag & IXANY || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) { tp->t_state &= ~TS_TTSTOP; tp->t_lflag &= ~FLUSHO; comstart(tp); } } else { do { u_char line_status; int recv_data; #ifndef PC98 line_status = (u_char) buf[CE_INPUT_OFFSET]; #else line_status = (u_char) buf[com->CE_INPUT_OFFSET]; #endif recv_data = (u_char) *buf++; if (line_status & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) { if (line_status & LSR_BI) recv_data |= TTY_BI; if (line_status & LSR_FE) recv_data |= TTY_FE; if (line_status & LSR_OE) recv_data |= TTY_OE; if (line_status & LSR_PE) recv_data |= TTY_PE; } (*linesw[tp->t_line].l_rint)(recv_data, tp); } while (--incc > 0); } if (com_events == 0) break; } if (com_events >= LOTS_OF_EVENTS) goto repeat; } static int comparam(tp, t) struct tty *tp; struct termios *t; { u_int cfcr; int cflag; struct com_s *com; int divisor; u_char dlbh; u_char dlbl; Port_t iobase; int s; int unit; #ifdef PC98 Port_t tmp_port; int tmp_flg; int port_shift = 0; u_char param = 0; #endif #ifdef PC98 cfcr = 0; unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); iobase = com->iobase; if (IS_8251(com->pc98_if_type)) { divisor = pc98_ttspeedtab(com, t->c_ospeed); } else { port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; /* do historical conversions */ if (t->c_ispeed == 0) t->c_ispeed = t->c_ospeed; /* check requested parameters */ divisor = ttspeedtab(t->c_ospeed, if_16550a_type[com->pc98_if_type & 0x0f].speedtab); } #else /* do historical conversions */ if (t->c_ispeed == 0) t->c_ispeed = t->c_ospeed; /* check requested parameters */ divisor = ttspeedtab(t->c_ospeed, comspeedtab); #endif if (divisor < 0 || divisor > 0 && t->c_ispeed != t->c_ospeed) return (EINVAL); /* parameters are OK, convert them to the com struct and the device */ #ifndef PC98 unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); iobase = com->iobase; #endif s = spltty(); #ifdef PC98 if (IS_8251(com->pc98_if_type)) { if (divisor == 0) com_tiocm_bic( com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE ); else com_tiocm_bis( com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE ); } else { #endif if (divisor == 0) (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */ else (void)commctl(com, TIOCM_DTR, DMBIS); #ifdef PC98 } #endif cflag = t->c_cflag; #ifdef PC98 if (!IS_8251(com->pc98_if_type)) { #endif switch (cflag & CSIZE) { case CS5: cfcr = CFCR_5BITS; break; case CS6: cfcr = CFCR_6BITS; break; case CS7: cfcr = CFCR_7BITS; break; default: cfcr = CFCR_8BITS; break; } if (cflag & PARENB) { cfcr |= CFCR_PENAB; if (!(cflag & PARODD)) cfcr |= CFCR_PEVEN; } if (cflag & CSTOPB) cfcr |= CFCR_STOPB; if (com->hasfifo && divisor != 0) { /* * Use a fifo trigger level low enough so that the input * latency from the fifo is less than about 16 msec and * the total latency is less than about 30 msec. These * latencies are reasonable for humans. Serial comms * protocols shouldn't expect anything better since modem * latencies are larger. */ com->fifo_image = t->c_ospeed <= 4800 ? FIFO_ENABLE : FIFO_ENABLE | FIFO_RX_HIGH; #ifdef COM_ESP /* * The Hayes ESP card needs the fifo DMA mode bit set * in compatibility mode. If not, it will interrupt * for each character received. */ if (com->esp) com->fifo_image |= FIFO_DMA_MODE; #endif #ifdef PC98 outb(iobase + (com_fifo << port_shift), com->fifo_image); #else outb(iobase + com_fifo, com->fifo_image); #endif } #ifdef PC98 } #endif disable_intr(); /* very important while com_data is hidden */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_cflag_and_speed_set(com, cflag, t->c_ospeed); else { #endif if (divisor != 0) { #ifdef PC98 outb(iobase + (com_cfcr << port_shift), cfcr | CFCR_DLAB); #else outb(iobase + com_cfcr, cfcr | CFCR_DLAB); #endif /* * Only set the divisor registers if they would change, * since on some 16550 incompatibles (UMC8669F), setting * them while input is arriving them loses sync until * data stops arriving. */ dlbl = divisor & 0xFF; #ifdef PC98 if (inb(iobase + (com_dlbl << port_shift)) != dlbl) outb(iobase + (com_dlbl << port_shift), dlbl); dlbh = (u_int) divisor >> 8; if (inb(iobase + (com_dlbh << port_shift)) != dlbh) outb(iobase + (com_dlbh << port_shift), dlbh); #else if (inb(iobase + com_dlbl) != dlbl) outb(iobase + com_dlbl, dlbl); dlbh = (u_int) divisor >> 8; if (inb(iobase + com_dlbh) != dlbh) outb(iobase + com_dlbh, dlbh); #endif } #ifdef PC98 } outb(iobase + (com_cfcr << port_shift), com->cfcr_image = cfcr); #else outb(iobase + com_cfcr, com->cfcr_image = cfcr); #endif if (!(tp->t_state & TS_TTSTOP)) com->state |= CS_TTGO; if (cflag & CRTS_IFLOW) { if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) | 0x40); } com->state |= CS_RTS_IFLOW; /* * If CS_RTS_IFLOW just changed from off to on, the change * needs to be propagated to MCR_RTS. This isn't urgent, * so do it later by calling comstart() instead of repeating * a lot of code from comstart() here. */ } else if (com->state & CS_RTS_IFLOW) { com->state &= ~CS_RTS_IFLOW; /* * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS * on here, since comstart() won't do it later. */ #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bis(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS); if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) & ~0x40); } } /* * Set up state to handle output flow control. * XXX - worth handling MDMBUF (DCD) flow control at the lowest level? * Now has 10+ msec latency, while CTS flow has 50- usec latency. */ com->state |= CS_ODEVREADY; com->state &= ~CS_CTS_OFLOW; #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { param = inb(com->rsabase + rsa_msr); outb(com->rsabase + rsa_msr, param & 0x14); } #endif if (cflag & CCTS_OFLOW) { com->state |= CS_CTS_OFLOW; #ifdef PC98 if (IS_8251(com->pc98_if_type)) { if (!(pc98_get_modem_status(com) & TIOCM_CTS)) com->state &= ~CS_ODEVREADY; } else { #endif #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { /* Set automatic flow control mode */ outb(com->rsabase + rsa_msr, param | 0x08); } else #endif if (!(com->last_modem_status & MSR_CTS)) com->state &= ~CS_ODEVREADY; if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) | 0x80); } #ifdef PC98 } #endif } else { if (com->st16650a) { outb(iobase + com_cfcr, 0xbf); outb(iobase + com_fifo, inb(iobase + com_fifo) & ~0x80); } } #ifdef PC98 outb(iobase + (com_cfcr << port_shift), com->cfcr_image); #else outb(iobase + com_cfcr, com->cfcr_image); #endif /* XXX shouldn't call functions while intrs are disabled. */ disc_optim(tp, t, com); /* * Recover from fiddling with CS_TTGO. We used to call siointr1() * unconditionally, but that defeated the careful discarding of * stale input in sioopen(). */ if (com->state >= (CS_BUSY | CS_TTGO)) siointr1(com); enable_intr(); splx(s); comstart(tp); return (0); } static void comstart(tp) struct tty *tp; { struct com_s *com; int s; int unit; #ifdef PC98 int tmp; #endif unit = DEV_TO_UNIT(tp->t_dev); com = com_addr(unit); s = spltty(); disable_intr(); if (tp->t_state & TS_TTSTOP) com->state &= ~CS_TTGO; else com->state |= CS_TTGO; if (tp->t_state & TS_TBLOCK) { #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = com_tiocm_get(com) & TIOCM_RTS; else tmp = com->mcr_image & MCR_RTS; if (tmp && (com->state & CS_RTS_IFLOW)) #else if (com->mcr_image & MCR_RTS && com->state & CS_RTS_IFLOW) #endif #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bic(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS); } else { #ifdef PC98 if (IS_8251(com->pc98_if_type)) tmp = com_tiocm_get(com) & TIOCM_RTS; else tmp = com->mcr_image & MCR_RTS; if (!(tmp) && com->iptr < com->ihighwater && com->state & CS_RTS_IFLOW) #else if (!(com->mcr_image & MCR_RTS) && com->iptr < com->ihighwater && com->state & CS_RTS_IFLOW) #endif #ifdef PC98 if (IS_8251(com->pc98_if_type)) com_tiocm_bis(com, TIOCM_RTS); else #endif outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS); } enable_intr(); if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) { ttwwakeup(tp); #ifdef PC98 /* if(IS_8251(com->pc98_if_type)) com_int_Tx_enable(com); */ #endif splx(s); return; } if (tp->t_outq.c_cc != 0) { struct lbq *qp; struct lbq *next; if (!com->obufs[0].l_queued) { com->obufs[0].l_tail = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1, #ifndef PC98 sizeof com->obuf1); #else com->CE_INPUT_OFFSET); #endif com->obufs[0].l_next = NULL; com->obufs[0].l_queued = TRUE; disable_intr(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; while ((next = qp->l_next) != NULL) qp = next; qp->l_next = &com->obufs[0]; } else { com->obufq.l_head = com->obufs[0].l_head; com->obufq.l_tail = com->obufs[0].l_tail; com->obufq.l_next = &com->obufs[0]; com->state |= CS_BUSY; } enable_intr(); } if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) { com->obufs[1].l_tail = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2, #ifndef PC98 sizeof com->obuf2); #else com->CE_INPUT_OFFSET); #endif com->obufs[1].l_next = NULL; com->obufs[1].l_queued = TRUE; disable_intr(); if (com->state & CS_BUSY) { qp = com->obufq.l_next; while ((next = qp->l_next) != NULL) qp = next; qp->l_next = &com->obufs[1]; } else { com->obufq.l_head = com->obufs[1].l_head; com->obufq.l_tail = com->obufs[1].l_tail; com->obufq.l_next = &com->obufs[1]; com->state |= CS_BUSY; } enable_intr(); } tp->t_state |= TS_BUSY; } disable_intr(); if (com->state >= (CS_BUSY | CS_TTGO)) siointr1(com); /* fake interrupt to start output */ enable_intr(); #ifdef PC98 /* if(IS_8251(com->pc98_if_type)) com_int_Tx_enable(com); */ #endif ttwwakeup(tp); splx(s); } static void siostop(tp, rw) struct tty *tp; int rw; { struct com_s *com; #ifdef PC98 int port_shift = 0; int rsa98_tmp = 0; #endif com = com_addr(DEV_TO_UNIT(tp->t_dev)); if (com->gone) return; #ifdef PC98 if (IS_8251(com->pc98_if_type)) port_shift = if_16550a_type[com->pc98_if_type & 0x0f].port_shift; #endif disable_intr(); if (rw & FWRITE) { if (com->hasfifo) #ifdef COM_ESP /* XXX avoid h/w bug. */ if (!com->esp) #endif #ifdef PC98 outb(com->iobase + (com_fifo << port_shift), FIFO_XMT_RST | com->fifo_image); if (com->pc98_if_type == COM_IF_RSA98III) for(rsa98_tmp = 0; rsa98_tmp < 2048; rsa98_tmp++) outb(com->iobase + (com_fifo << port_shift), FIFO_XMT_RST | com->fifo_image); #else outb(com->iobase + com_fifo, FIFO_XMT_RST | com->fifo_image); #endif com->obufs[0].l_queued = FALSE; com->obufs[1].l_queued = FALSE; if (com->state & CS_ODONE) com_events -= LOTS_OF_EVENTS; com->state &= ~(CS_ODONE | CS_BUSY); com->tp->t_state &= ~TS_BUSY; } if (rw & FREAD) { if (com->hasfifo) #ifdef COM_ESP /* XXX avoid h/w bug. */ if (!com->esp) #endif #ifdef PC98 if (com->pc98_if_type == COM_IF_RSA98III) { for(rsa98_tmp = 0; rsa98_tmp < 2048; rsa98_tmp++) inb(com->data_port); } outb(com->iobase + (com_fifo << port_shift), FIFO_RCV_RST | com->fifo_image); #else outb(com->iobase + com_fifo, FIFO_RCV_RST | com->fifo_image); #endif com_events -= (com->iptr - com->ibuf); com->iptr = com->ibuf; } enable_intr(); comstart(tp); } static struct tty * siodevtotty(dev) dev_t dev; { int mynor; int unit; mynor = minor(dev); if (mynor & CONTROL_MASK) return (NULL); unit = MINOR_TO_UNIT(mynor); if ((u_int) unit >= NSIOTOT) return (NULL); return (&sio_tty[unit]); } static int commctl(com, bits, how) struct com_s *com; int bits; int how; { int mcr; int msr; if (how == DMGET) { bits = TIOCM_LE; /* XXX - always enabled while open */ mcr = com->mcr_image; if (mcr & MCR_DTR) bits |= TIOCM_DTR; if (mcr & MCR_RTS) bits |= TIOCM_RTS; msr = com->prev_modem_status; if (msr & MSR_CTS) bits |= TIOCM_CTS; if (msr & MSR_DCD) bits |= TIOCM_CD; if (msr & MSR_DSR) bits |= TIOCM_DSR; /* * XXX - MSR_RI is naturally volatile, and we make MSR_TERI * more volatile by reading the modem status a lot. Perhaps * we should latch both bits until the status is read here. */ if (msr & (MSR_RI | MSR_TERI)) bits |= TIOCM_RI; return (bits); } mcr = 0; if (bits & TIOCM_DTR) mcr |= MCR_DTR; if (bits & TIOCM_RTS) mcr |= MCR_RTS; if (com->gone) return(0); disable_intr(); switch (how) { case DMSET: outb(com->modem_ctl_port, com->mcr_image = mcr | (com->mcr_image & MCR_IENABLE)); break; case DMBIS: outb(com->modem_ctl_port, com->mcr_image |= mcr); break; case DMBIC: outb(com->modem_ctl_port, com->mcr_image &= ~mcr); break; } enable_intr(); return (0); } static void siosettimeout() { struct com_s *com; bool_t someopen; int unit; /* * Set our timeout period to 1 second if no polled devices are open. * Otherwise set it to max(1/200, 1/hz). * Enable timeouts iff some device is open. */ untimeout(comwakeup, (void *)NULL, sio_timeout_handle); sio_timeout = hz; someopen = FALSE; for (unit = 0; unit < NSIOTOT; ++unit) { com = com_addr(unit); if (com != NULL && com->tp != NULL && com->tp->t_state & TS_ISOPEN && !com->gone) { someopen = TRUE; if (com->poll || com->poll_output) { sio_timeout = hz > 200 ? hz / 200 : 1; break; } } } if (someopen) { sio_timeouts_until_log = hz / sio_timeout; sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout); } else { /* Flush error messages, if any. */ sio_timeouts_until_log = 1; comwakeup((void *)NULL); untimeout(comwakeup, (void *)NULL, sio_timeout_handle); } } static void comwakeup(chan) void *chan; { struct com_s *com; int unit; sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout); /* * Recover from lost output interrupts. * Poll any lines that don't use interrupts. */ for (unit = 0; unit < NSIOTOT; ++unit) { com = com_addr(unit); if (com != NULL && !com->gone && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) { disable_intr(); siointr1(com); enable_intr(); } } /* * Check for and log errors, but not too often. */ if (--sio_timeouts_until_log > 0) return; sio_timeouts_until_log = hz / sio_timeout; for (unit = 0; unit < NSIOTOT; ++unit) { int errnum; com = com_addr(unit); if (com == NULL) continue; if (com->gone) continue; for (errnum = 0; errnum < CE_NTYPES; ++errnum) { u_int delta; u_long total; disable_intr(); delta = com->delta_error_counts[errnum]; com->delta_error_counts[errnum] = 0; enable_intr(); if (delta == 0) continue; total = com->error_counts[errnum] += delta; log(LOG_ERR, "sio%d: %u more %s%s (total %lu)\n", unit, delta, error_desc[errnum], delta == 1 ? "" : "s", total); } } } #ifdef PC98 /* commint is called when modem control line changes */ static void commint(dev_t dev) { register struct tty *tp; int stat,delta; struct com_s *com; int mynor,unit; mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); com = com_addr(unit); tp = com->tp; stat = com_tiocm_get(com); delta = com_tiocm_get_delta(com); if (com->state & CS_CTS_OFLOW) { if (stat & TIOCM_CTS) com->state |= CS_ODEVREADY; else com->state &= ~CS_ODEVREADY; } if ((delta & TIOCM_CAR) && (mynor & CALLOUT_MASK) == 0) { if (stat & TIOCM_CAR ) (void)(*linesw[tp->t_line].l_modem)(tp, 1); else if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0) { /* negate DTR, RTS */ com_tiocm_bic(com, (tp->t_cflag & HUPCL) ? TIOCM_DTR|TIOCM_RTS|TIOCM_LE : TIOCM_LE ); /* disable IENABLE */ com_int_TxRx_disable( com ); } } } #endif static void disc_optim(tp, t, com) struct tty *tp; struct termios *t; struct com_s *com; { if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON)) && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) && (!(t->c_iflag & PARMRK) || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) && linesw[tp->t_line].l_rint == ttyinput) tp->t_state |= TS_CAN_BYPASS_L_RINT; else tp->t_state &= ~TS_CAN_BYPASS_L_RINT; com->hotchar = linesw[tp->t_line].l_hotchar; } /* * Following are all routines needed for SIO to act as console */ #include struct siocnstate { u_char dlbl; u_char dlbh; u_char ier; u_char cfcr; u_char mcr; }; static speed_t siocngetspeed __P((Port_t, struct speedtab *)); static void siocnclose __P((struct siocnstate *sp)); static void siocnopen __P((struct siocnstate *sp)); static void siocntxwait __P((void)); +/* + * XXX: sciocnget() and sciocnputc() are not declared static, as they are + * referred to from i386/i386/i386-gdbstub.c. + */ +static cn_probe_t siocnprobe; +static cn_init_t siocninit; +static cn_checkc_t siocncheckc; + cn_getc_t siocngetc; + cn_putc_t siocnputc; + +CONS_DRIVER(sio, siocnprobe, siocninit, siocngetc, siocncheckc, siocnputc); + static void siocntxwait() { int timo; /* * Wait for any pending transmission to finish. Required to avoid * the UART lockup bug when the speed is changed, and for normal * transmits. */ timo = 100000; while ((inb(siocniobase + com_lsr) & (LSR_TSRE | LSR_TXRDY)) != (LSR_TSRE | LSR_TXRDY) && --timo != 0) ; } /* * Read the serial port specified and try to figure out what speed * it's currently running at. We're assuming the serial port has * been initialized and is basicly idle. This routine is only intended * to be run at system startup. * * If the value read from the serial port doesn't make sense, return 0. */ static speed_t siocngetspeed(iobase, table) Port_t iobase; struct speedtab *table; { int code; u_char dlbh; u_char dlbl; u_char cfcr; cfcr = inb(iobase + com_cfcr); outb(iobase + com_cfcr, CFCR_DLAB | cfcr); dlbl = inb(iobase + com_dlbl); dlbh = inb(iobase + com_dlbh); outb(iobase + com_cfcr, cfcr); code = dlbh << 8 | dlbl; for ( ; table->sp_speed != -1; table++) if (table->sp_code == code) return (table->sp_speed); return 0; /* didn't match anything sane */ } static void siocnopen(sp) struct siocnstate *sp; { int divisor; u_char dlbh; u_char dlbl; Port_t iobase; /* * Save all the device control registers except the fifo register * and set our default ones (cs8 -parenb speed=comdefaultrate). * We can't save the fifo register since it is read-only. */ iobase = siocniobase; sp->ier = inb(iobase + com_ier); outb(iobase + com_ier, 0); /* spltty() doesn't stop siointr() */ siocntxwait(); sp->cfcr = inb(iobase + com_cfcr); outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS); sp->dlbl = inb(iobase + com_dlbl); sp->dlbh = inb(iobase + com_dlbh); /* * Only set the divisor registers if they would change, since on * some 16550 incompatibles (Startech), setting them clears the * data input register. This also reduces the effects of the * UMC8669F bug. */ divisor = ttspeedtab(comdefaultrate, comspeedtab); dlbl = divisor & 0xFF; if (sp->dlbl != dlbl) outb(iobase + com_dlbl, dlbl); dlbh = (u_int) divisor >> 8; if (sp->dlbh != dlbh) outb(iobase + com_dlbh, dlbh); outb(iobase + com_cfcr, CFCR_8BITS); sp->mcr = inb(iobase + com_mcr); /* * We don't want interrupts, but must be careful not to "disable" * them by clearing the MCR_IENABLE bit, since that might cause * an interrupt by floating the IRQ line. */ outb(iobase + com_mcr, (sp->mcr & MCR_IENABLE) | MCR_DTR | MCR_RTS); } static void siocnclose(sp) struct siocnstate *sp; { Port_t iobase; /* * Restore the device control registers. */ siocntxwait(); iobase = siocniobase; outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS); if (sp->dlbl != inb(iobase + com_dlbl)) outb(iobase + com_dlbl, sp->dlbl); if (sp->dlbh != inb(iobase + com_dlbh)) outb(iobase + com_dlbh, sp->dlbh); outb(iobase + com_cfcr, sp->cfcr); /* * XXX damp oscillations of MCR_DTR and MCR_RTS by not restoring them. */ outb(iobase + com_mcr, sp->mcr | MCR_DTR | MCR_RTS); outb(iobase + com_ier, sp->ier); } -void +static void siocnprobe(cp) struct consdev *cp; { speed_t boot_speed; u_char cfcr; struct isa_device *dvp; int s; struct siocnstate sp; /* * Find our first enabled console, if any. If it is a high-level * console device, then initialize it and return successfully. * If it is a low-level console device, then initialize it and * return unsuccessfully. It must be initialized in both cases * for early use by console drivers and debuggers. Initializing * the hardware is not necessary in all cases, since the i/o * routines initialize it on the fly, but it is necessary if * input might arrive while the hardware is switched back to an * uninitialized state. We can't handle multiple console devices * yet because our low-level routines don't take a device arg. * We trust the user to set the console flags properly so that we * don't need to probe. */ cp->cn_pri = CN_DEAD; for (dvp = isa_devtab_tty; dvp->id_driver != NULL; dvp++) if (dvp->id_driver == &siodriver && dvp->id_enabled && COM_CONSOLE(dvp)) { siocniobase = dvp->id_iobase; s = spltty(); if (boothowto & RB_SERIAL) { boot_speed = siocngetspeed(siocniobase, comspeedtab); if (boot_speed) comdefaultrate = boot_speed; } /* * Initialize the divisor latch. We can't rely on * siocnopen() to do this the first time, since it * avoids writing to the latch if the latch appears * to have the correct value. Also, if we didn't * just read the speed from the hardware, then we * need to set the speed in hardware so that * switching it later is null. */ cfcr = inb(siocniobase + com_cfcr); outb(siocniobase + com_cfcr, CFCR_DLAB | cfcr); outb(siocniobase + com_dlbl, COMBRD(comdefaultrate) & 0xff); outb(siocniobase + com_dlbh, (u_int) COMBRD(comdefaultrate) >> 8); outb(siocniobase + com_cfcr, cfcr); siocnopen(&sp); splx(s); if (!COM_LLCONSOLE(dvp)) { cp->cn_dev = makedev(CDEV_MAJOR, dvp->id_unit); cp->cn_pri = COM_FORCECONSOLE(dvp) || boothowto & RB_SERIAL ? CN_REMOTE : CN_NORMAL; } break; } } -void +static void siocninit(cp) struct consdev *cp; { comconsole = DEV_TO_UNIT(cp->cn_dev); } -int +static int siocncheckc(dev) dev_t dev; { int c; Port_t iobase; int s; struct siocnstate sp; iobase = siocniobase; s = spltty(); siocnopen(&sp); if (inb(iobase + com_lsr) & LSR_RXRDY) c = inb(iobase + com_data); else c = -1; siocnclose(&sp); splx(s); return (c); } int siocngetc(dev) dev_t dev; { int c; Port_t iobase; int s; struct siocnstate sp; iobase = siocniobase; s = spltty(); siocnopen(&sp); while (!(inb(iobase + com_lsr) & LSR_RXRDY)) ; c = inb(iobase + com_data); siocnclose(&sp); splx(s); return (c); } void siocnputc(dev, c) dev_t dev; int c; { int s; struct siocnstate sp; s = spltty(); siocnopen(&sp); siocntxwait(); outb(siocniobase + com_data, c); siocnclose(&sp); splx(s); } /* * support PnP cards if we are using 'em */ #if NPNP > 0 static pnpid_t siopnp_ids[] = { { 0x5015f435, "MOT1550"}, { 0x8113b04e, "Supra1381"}, { 0x9012b04e, "Supra1290"}, { 0x7121b04e, "SupraExpress 56i Sp"}, { 0x11007256, "USR0011"}, { 0x30207256, "USR2030"}, { 0 } }; static char *siopnp_probe(u_long csn, u_long vend_id); static void siopnp_attach(u_long csn, u_long vend_id, char *name, struct isa_device *dev); static u_long nsiopnp = NSIO; static struct pnp_device siopnp = { "siopnp", siopnp_probe, siopnp_attach, &nsiopnp, &tty_imask }; DATA_SET (pnpdevice_set, siopnp); static char * siopnp_probe(u_long csn, u_long vend_id) { pnpid_t *id; char *s = NULL; for(id = siopnp_ids; id->vend_id != 0; id++) { if (vend_id == id->vend_id) { s = id->id_str; break; } } if (s) { struct pnp_cinfo d; read_pnp_parms(&d, 0); if (d.enable == 0 || d.flags & 1) { printf("CSN %lu is disabled.\n", csn); return (NULL); } } return (s); } static void siopnp_attach(u_long csn, u_long vend_id, char *name, struct isa_device *dev) { struct pnp_cinfo d; struct isa_device *dvp; if (dev->id_unit >= NSIOTOT) return; if (read_pnp_parms(&d, 0) == 0) { printf("failed to read pnp parms\n"); return; } write_pnp_parms(&d, 0); enable_pnp_card(); dev->id_iobase = d.port[0]; dev->id_irq = (1 << d.irq[0]); dev->id_intr = siointr; dev->id_ri_flags = RI_FAST; dev->id_drq = -1; if (dev->id_driver == NULL) { dev->id_driver = &siodriver; dvp = find_isadev(isa_devtab_tty, &siodriver, 0); if (dvp != NULL) dev->id_id = dvp->id_id; } if ((dev->id_alive = sioprobe(dev)) != 0) sioattach(dev); else printf("sio%d: probe failed\n", dev->id_unit); } #endif #ifdef PC98 /* * pc98 local function */ static void com_tiocm_set(struct com_s *com, int msr) { int s; int tmp = 0; int mask = CMD8251_TxEN|CMD8251_RxEN|CMD8251_DTR|CMD8251_RTS; s=spltty(); com->pc98_prev_modem_status = ( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ) | ( com->pc98_prev_modem_status & ~(TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ); tmp |= (CMD8251_TxEN|CMD8251_RxEN); if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR; if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS; pc98_i8251_clear_or_cmd( com, mask, tmp ); splx(s); } static void com_tiocm_bis(struct com_s *com, int msr) { int s; int tmp = 0; s=spltty(); com->pc98_prev_modem_status |= ( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ); tmp |= CMD8251_TxEN|CMD8251_RxEN; if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR; if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS; pc98_i8251_or_cmd( com, tmp ); splx(s); } static void com_tiocm_bic(struct com_s *com, int msr) { int s; int tmp = msr; s=spltty(); com->pc98_prev_modem_status &= ~( msr & (TIOCM_LE|TIOCM_DTR|TIOCM_RTS) ); if ( msr & TIOCM_DTR ) tmp |= CMD8251_DTR; if ( msr & TIOCM_RTS ) tmp |= CMD8251_RTS; pc98_i8251_clear_cmd( com, tmp ); splx(s); } static int com_tiocm_get(struct com_s *com) { return( com->pc98_prev_modem_status ); } static int com_tiocm_get_delta(struct com_s *com) { int tmp; tmp = com->pc98_modem_delta; com->pc98_modem_delta = 0; return( tmp ); } /* convert to TIOCM_?? ( ioctl.h ) */ static int pc98_get_modem_status(struct com_s *com) { int stat, stat2; register int msr; stat = inb(com->sts_port); stat2 = inb(com->in_modem_port); msr = com->pc98_prev_modem_status & ~(TIOCM_CAR|TIOCM_RI|TIOCM_DSR|TIOCM_CTS); if ( !(stat2 & CICSCD_CD) ) msr |= TIOCM_CAR; if ( !(stat2 & CICSCD_CI) ) msr |= TIOCM_RI; if ( stat & STS8251_DSR ) msr |= TIOCM_DSR; if ( !(stat2 & CICSCD_CS) ) msr |= TIOCM_CTS; #if COM_CARRIER_DETECT_EMULATE if ( msr & (TIOCM_DSR|TIOCM_CTS) ) { msr |= TIOCM_CAR; } #endif return(msr); } static void pc98_check_msr(void* chan) { int msr, delta; int s; register struct tty *tp; struct com_s *com; int mynor; int unit; dev_t dev; dev=(dev_t)chan; mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); com = com_addr(unit); tp = com->tp; s = spltty(); msr = pc98_get_modem_status(com); /* make change flag */ delta = msr ^ com->pc98_prev_modem_status; if ( delta & TIOCM_CAR ) { if ( com->modem_car_chg_timer ) { if ( -- com->modem_car_chg_timer ) msr ^= TIOCM_CAR; } else { if ( com->modem_car_chg_timer = ( msr & TIOCM_CAR ) ? DCD_ON_RECOGNITION : DCD_OFF_TOLERANCE ) msr ^= TIOCM_CAR; } } else com->modem_car_chg_timer = 0; delta = ( msr ^ com->pc98_prev_modem_status ) & (TIOCM_CAR|TIOCM_RI|TIOCM_DSR|TIOCM_CTS); com->pc98_prev_modem_status = msr; delta = ( com->pc98_modem_delta |= delta ); splx(s); if ( com->modem_checking || (tp->t_state & (TS_ISOPEN)) ) { if ( delta ) { commint(dev); } timeout(pc98_check_msr, (caddr_t)dev, PC98_CHECK_MODEM_INTERVAL); } else { com->modem_checking = 0; } } static void pc98_msrint_start(dev_t dev) { struct com_s *com; int mynor; int unit; int s = spltty(); mynor = minor(dev); unit = MINOR_TO_UNIT(mynor); com = com_addr(unit); /* modem control line check routine envoke interval is 1/10 sec */ if ( com->modem_checking == 0 ) { com->pc98_prev_modem_status = pc98_get_modem_status(com); com->pc98_modem_delta = 0; timeout(pc98_check_msr, (caddr_t)dev, PC98_CHECK_MODEM_INTERVAL); com->modem_checking = 1; } splx(s); } static void pc98_disable_i8251_interrupt(struct com_s *com, int mod) { /* disable interrupt */ register int tmp; mod |= ~(IEN_Tx|IEN_TxEMP|IEN_Rx); COM_INT_DISABLE tmp = inb( com->intr_ctrl_port ) & ~(IEN_Tx|IEN_TxEMP|IEN_Rx); outb( com->intr_ctrl_port, (com->intr_enable&=~mod) | tmp ); COM_INT_ENABLE } static void pc98_enable_i8251_interrupt(struct com_s *com, int mod) { register int tmp; COM_INT_DISABLE tmp = inb( com->intr_ctrl_port ) & ~(IEN_Tx|IEN_TxEMP|IEN_Rx); outb( com->intr_ctrl_port, (com->intr_enable|=mod) | tmp ); COM_INT_ENABLE } static int pc98_check_i8251_interrupt(struct com_s *com) { return ( com->intr_enable & 0x07 ); } static void pc98_i8251_clear_cmd(struct com_s *com, int x) { int tmp; COM_INT_DISABLE tmp = com->pc98_prev_siocmd & ~(x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static void pc98_i8251_or_cmd(struct com_s *com, int x) { int tmp; COM_INT_DISABLE tmp = com->pc98_prev_siocmd | (x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static void pc98_i8251_set_cmd(struct com_s *com, int x) { int tmp; COM_INT_DISABLE tmp = (x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static void pc98_i8251_clear_or_cmd(struct com_s *com, int clr, int x) { int tmp; COM_INT_DISABLE tmp = com->pc98_prev_siocmd & ~(clr); tmp |= (x); outb(com->cmd_port, tmp); com->pc98_prev_siocmd = tmp & ~(CMD8251_ER|CMD8251_RESET|CMD8251_EH); COM_INT_ENABLE } static int pc98_i8251_get_cmd(struct com_s *com) { return com->pc98_prev_siocmd; } static int pc98_i8251_get_mod(struct com_s *com) { return com->pc98_prev_siomod; } static void pc98_i8251_reset(struct com_s *com, int mode, int command) { outb(com->cmd_port, 0); /* dummy */ DELAY(2); outb(com->cmd_port, 0); /* dummy */ DELAY(2); outb(com->cmd_port, 0); /* dummy */ DELAY(2); outb(com->cmd_port, CMD8251_RESET); /* internal reset */ DELAY(2); outb(com->cmd_port, mode ); /* mode register */ com->pc98_prev_siomod = mode; DELAY(2); pc98_i8251_set_cmd( com, (command|CMD8251_ER) ); } static void pc98_check_sysclock(void) { /* get system clock from port */ if ( pc98_machine_type & M_8M ) { /* 8 MHz system & H98 */ sysclock = 8; } else { /* 5 MHz system */ sysclock = 5; } } static void com_cflag_and_speed_set( struct com_s *com, int cflag, int speed) { int cfcr=0, count; int previnterrupt; count = pc98_ttspeedtab( com, speed ); if ( count < 0 ) return; previnterrupt = pc98_check_i8251_interrupt(com); pc98_disable_i8251_interrupt( com, IEN_Tx|IEN_TxEMP|IEN_Rx ); switch ( cflag&CSIZE ) { case CS5: cfcr = MOD8251_5BITS; break; case CS6: cfcr = MOD8251_6BITS; break; case CS7: cfcr = MOD8251_7BITS; break; case CS8: cfcr = MOD8251_8BITS; break; } if ( cflag&PARENB ) { if ( cflag&PARODD ) cfcr |= MOD8251_PODD; else cfcr |= MOD8251_PEVEN; } else cfcr |= MOD8251_PDISAB; if ( cflag&CSTOPB ) cfcr |= MOD8251_STOP2; else cfcr |= MOD8251_STOP1; if ( count & 0x10000 ) cfcr |= MOD8251_CLKX1; else cfcr |= MOD8251_CLKX16; if (epson_machine_id != 0x20) { /* XXX */ int tmp; while (!((tmp = inb(com->sts_port)) & STS8251_TxEMP)) ; } /* set baud rate from ospeed */ pc98_set_baud_rate( com, count ); if ( cfcr != pc98_i8251_get_mod(com) ) pc98_i8251_reset(com, cfcr, pc98_i8251_get_cmd(com) ); pc98_enable_i8251_interrupt( com, previnterrupt ); } static int pc98_ttspeedtab(struct com_s *com, int speed) { int if_type, effect_sp, count = -1, mod; if_type = com->pc98_if_type & 0x0f; switch (com->pc98_if_type) { case COM_IF_INTERNAL: if (PC98SIO_baud_rate_port(if_type) != -1) { count = ttspeedtab(speed, if_8251_type[if_type].speedtab); if (count > 0) { count |= COM1_EXT_CLOCK; break; } } /* for *1CLK asynchronous! mode, TEFUTEFU */ mod = (sysclock == 5) ? 2457600 : 1996800; effect_sp = ttspeedtab( speed, pc98speedtab ); if ( effect_sp < 0 ) /* XXX */ effect_sp = ttspeedtab( (speed - 1), pc98speedtab ); if ( effect_sp <= 0 ) return effect_sp; if ( effect_sp == speed ) mod /= 16; if ( mod % effect_sp ) return(-1); count = mod / effect_sp; if ( count > 65535 ) return(-1); if ( effect_sp != speed ) count |= 0x10000; break; case COM_IF_PC9861K_1: case COM_IF_PC9861K_2: count = 1; break; case COM_IF_IND_SS_1: case COM_IF_IND_SS_2: case COM_IF_PIO9032B_1: case COM_IF_PIO9032B_2: if ( speed == 0 ) return 0; count = ttspeedtab( speed, if_8251_type[if_type].speedtab ); break; case COM_IF_B98_01_1: case COM_IF_B98_01_2: if ( speed == 0 ) return 0; count = ttspeedtab( speed, if_8251_type[if_type].speedtab ); #ifdef B98_01_OLD if (count == 0 || count == 1) { count += 4; count |= 0x20000; /* x1 mode for 76800 and 153600 */ } #endif break; } return count; } static void pc98_set_baud_rate( struct com_s *com, int count ) { int if_type, io, s; if_type = com->pc98_if_type & 0x0f; io = com->iobase & 0xff00; switch (com->pc98_if_type) { case COM_IF_INTERNAL: if (PC98SIO_baud_rate_port(if_type) != -1) { if (count & COM1_EXT_CLOCK) { outb((Port_t)PC98SIO_baud_rate_port(if_type), count & 0xff); break; } else { outb((Port_t)PC98SIO_baud_rate_port(if_type), 0x09); } } if ( count < 0 ) { printf( "[ Illegal count : %d ]", count ); return; } else if ( count == 0 ) return; /* set i8253 */ s = splclock(); if (count != 3) outb( 0x77, 0xb6 ); else outb( 0x77, 0xb4 ); outb( 0x5f, 0); outb( 0x75, count & 0xff ); outb( 0x5f, 0); outb( 0x75, (count >> 8) & 0xff ); splx(s); break; case COM_IF_IND_SS_1: case COM_IF_IND_SS_2: outb(io | PC98SIO_intr_ctrl_port(if_type), 0); outb(io | PC98SIO_baud_rate_port(if_type), 0); outb(io | PC98SIO_baud_rate_port(if_type), 0xc0); outb(io | PC98SIO_baud_rate_port(if_type), (count >> 8) | 0x80); outb(io | PC98SIO_baud_rate_port(if_type), count & 0xff); break; case COM_IF_PIO9032B_1: case COM_IF_PIO9032B_2: outb(io | PC98SIO_baud_rate_port(if_type), count); break; case COM_IF_B98_01_1: case COM_IF_B98_01_2: outb(io | PC98SIO_baud_rate_port(if_type), count & 0x0f); #ifdef B98_01_OLD /* * Some old B98_01 board should be controlled * in different way, but this hasn't been tested yet. */ outb(io | PC98SIO_func_port(if_type), (count & 0x20000) ? 0xf0 : 0xf2); #endif break; } } static int pc98_check_if_type(struct isa_device *dev, struct siodev *iod) { int irr, io, if_type, tmp; static short irq_tab[2][8] = { { 3, 5, 6, 9, 10, 12, 13, -1}, { 3, 10, 12, 13, 5, 6, 9, -1} }; iod->if_type = if_type = (dev->id_flags >> 24) & 0xff; if ((if_type < 0 || if_type > COM_IF_END1) && (if_type < 0x10 || if_type > COM_IF_END2)) return(-1); if_type &= 0x0f; iod->irq = 0; io = dev->id_iobase & 0xff00; if (IS_8251(iod->if_type)) { if (PC98SIO_func_port(if_type) != -1) { outb(io | PC98SIO_func_port(if_type), 0xf2); tmp = ttspeedtab(9600, if_8251_type[if_type].speedtab); if (tmp != -1 && PC98SIO_baud_rate_port(if_type) != -1) outb(io | PC98SIO_baud_rate_port(if_type), tmp); } iod->cmd = io | PC98SIO_cmd_port(if_type); iod->sts = io | PC98SIO_sts_port(if_type); iod->mod = io | PC98SIO_in_modem_port(if_type); iod->ctrl = io | PC98SIO_intr_ctrl_port(if_type); if (iod->if_type == COM_IF_INTERNAL) { iod->irq = 4; /* XXX check new internal port. */ outb(0x138, 0); DELAY(10); for (tmp = 0; tmp < 100; tmp++) { if ((inb(0x138) & 1) == 0) { PC98SIO_baud_rate_port(if_type) = 0x13a; if_8251_type[if_type].name = " (internal fast)"; if_8251_type[if_type].speedtab = pc98fast_speedtab; break; } DELAY(1); } } else { tmp = inb( iod->mod ) & if_8251_type[if_type].irr_mask; if ((dev->id_iobase & 0xff) == IO_COM2) iod->irq = irq_tab[0][tmp]; else iod->irq = irq_tab[1][tmp]; } } else { irr = if_16550a_type[if_type].irr_read; #ifdef COM_MULTIPORT if (!COM_ISMULTIPORT(dev) || dev->id_unit == COM_MPMASTER(dev)) #endif if (irr != -1) { tmp = inb(io | irr); if (dev->id_iobase & 0x01) /* XXX depend on RSB-384 */ iod->irq = irq_tab[1][tmp >> 3]; else iod->irq = irq_tab[0][tmp & 0x07]; } } if ( iod->irq == -1 ) return -1; return 0; } static int pc98_set_ioport( struct com_s *com, int id_flags ) { int io, if_type; if_type = (id_flags >> 24) & 0xff; if (IS_8251(if_type)) { pc98_check_sysclock(); io = com->iobase & 0xff00; com->pc98_if_type = if_type; if_type &= 0x0f; com->data_port = io | PC98SIO_data_port(if_type); com->cmd_port = io | PC98SIO_cmd_port(if_type); com->sts_port = io | PC98SIO_sts_port(if_type); com->in_modem_port = io | PC98SIO_in_modem_port(if_type); com->intr_ctrl_port = io | PC98SIO_intr_ctrl_port(if_type); return 0; } return -1; } #endif /* PC98 defined */ Index: head/sys/pc98/pc98/syscons.c =================================================================== --- head/sys/pc98/pc98/syscons.c (revision 42404) +++ head/sys/pc98/pc98/syscons.c (revision 42405) @@ -1,5950 +1,5958 @@ /*- * Copyright (c) 1992-1998 Sen Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: syscons.c,v 1.103 1998/11/08 12:39:05 dfr Exp $ + * $Id: syscons.c,v 1.104 1998/12/16 14:57:37 kato Exp $ */ #include "sc.h" #include "apm.h" #include "opt_ddb.h" #include "opt_devfs.h" #include "opt_vesa.h" #include "opt_vm86.h" #include "opt_syscons.h" #if NSC > 0 #include #include #include #include #include #include #include #include #include #ifdef DEVFS #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef PC98 #define KANJI #include #include #include #include #include #include #include #include #else #include #include #include #include #include #include #include #endif /* PC98 */ #if defined(PC98) && defined(LINE30) #include #endif #if !defined(MAXCONS) #define MAXCONS 16 #endif #if !defined(SC_MAX_HISTORY_SIZE) #define SC_MAX_HISTORY_SIZE (1000 * MAXCONS) #endif #if !defined(SC_HISTORY_SIZE) #define SC_HISTORY_SIZE (ROW * 4) #endif #if (SC_HISTORY_SIZE * MAXCONS) > SC_MAX_HISTORY_SIZE #undef SC_MAX_HISTORY_SIZE #define SC_MAX_HISTORY_SIZE (SC_HISTORY_SIZE * MAXCONS) #endif #if !defined(SC_MOUSE_CHAR) #define SC_MOUSE_CHAR (0xd0) #endif #define COLD 0 #define WARM 1 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */ #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */ /* for backward compatibility */ #define OLD_CONS_MOUSECTL _IOWR('c', 10, old_mouse_info_t) typedef struct old_mouse_data { int x; int y; int buttons; } old_mouse_data_t; typedef struct old_mouse_info { int operation; union { struct old_mouse_data data; struct mouse_mode mode; } u; } old_mouse_info_t; /* XXX use sc_bcopy where video memory is concerned */ extern void generic_bcopy(const void *, void *, size_t); extern void generic_bzero(void *, size_t); static default_attr user_default = { (FG_LIGHTGREY | BG_BLACK) << 8, (FG_BLACK | BG_LIGHTGREY) << 8 }; #ifdef PC98 static default_attr kernel_default = { (FG_LIGHTGREY | BG_BLACK) << 8, (FG_BLACK | BG_LIGHTGREY) << 8 }; #else static default_attr kernel_default = { (FG_WHITE | BG_BLACK) << 8, (FG_BLACK | BG_LIGHTGREY) << 8 }; #endif /* PC98 */ static scr_stat main_console; static scr_stat *console[MAXCONS]; #ifdef DEVFS static void *sc_devfs_token[MAXCONS]; static void *sc_mouse_devfs_token; static void *sc_console_devfs_token; #endif scr_stat *cur_console; static scr_stat *new_scp, *old_scp; static term_stat kernel_console; static default_attr *current_default; static int sc_flags; static int sc_port = IO_KBD; static KBDC sc_kbdc = NULL; static char init_done = COLD; static u_short sc_buffer[ROW*COL]; static char shutdown_in_progress = FALSE; static char font_loading_in_progress = FALSE; static char switch_in_progress = FALSE; static char write_in_progress = FALSE; static char blink_in_progress = FALSE; static int blinkrate = 0; #ifndef PC98 u_int crtc_addr = MONO_BASE; #endif char crtc_type = KD_MONO; static char crtc_vga = FALSE; static int adp_flags; static u_char shfts = 0, ctls = 0, alts = 0, agrs = 0, metas = 0; static u_char accents = 0; #ifdef PC98 static u_char nlkcnt = 0, slkcnt = 0, alkcnt = 0; #else static u_char nlkcnt = 0, clkcnt = 0, slkcnt = 0, alkcnt = 0; #endif static const u_int n_fkey_tab = sizeof(fkey_tab) / sizeof(*fkey_tab); static int delayed_next_scr = FALSE; static long scrn_blank_time = 0; /* screen saver timeout value */ int scrn_blanked = 0; /* screen saver active flag */ static long scrn_time_stamp; static int saver_mode = CONS_LKM_SAVER; /* LKM/user saver */ static int run_scrn_saver = FALSE; /* should run the saver? */ static int scrn_idle = FALSE; /* about to run the saver */ u_char scr_map[256]; u_char scr_rmap[256]; #ifndef PC98 static int initial_video_mode; /* initial video mode # */ static int bios_video_mode; /* video mode # set by BIOS */ #endif int fonts_loaded = 0 #ifdef STD8X16FONT | FONT_16 #endif ; u_char font_8[256*8]; u_char font_14[256*14]; #ifdef STD8X16FONT extern #endif u_char font_16[256*16]; u_char palette[256*3]; static u_char *cut_buffer; static int cut_buffer_size; static int mouse_level; /* sysmouse protocol level */ static mousestatus_t mouse_status = { 0, 0, 0, 0, 0, 0 }; #ifndef PC98 static u_short mouse_and_mask[16] = { 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00, 0xff80, 0xfe00, 0x1e00, 0x1f00, 0x0f00, 0x0f00, 0x0000, 0x0000, 0x0000 }; static u_short mouse_or_mask[16] = { 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x6800, 0x0c00, 0x0c00, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, 0x0000 }; #endif int sc_history_size = SC_HISTORY_SIZE; static int extra_history_size = SC_MAX_HISTORY_SIZE - SC_HISTORY_SIZE * MAXCONS; static void none_saver(int blank) { } static void (*current_saver)(int blank) = none_saver; static void (*default_saver)(int blank) = none_saver; d_ioctl_t *sc_user_ioctl; static int sticky_splash = FALSE; /* OS specific stuff */ #ifdef not_yet_done #define VIRTUAL_TTY(x) (sccons[x] = ttymalloc(sccons[x])) struct CONSOLE_TTY (sccons[MAXCONS] = ttymalloc(sccons[MAXCONS])) struct MOUSE_TTY (sccons[MAXCONS+1] = ttymalloc(sccons[MAXCONS+1])) struct tty *sccons[MAXCONS+2]; #else #define VIRTUAL_TTY(x) &sccons[x] #define CONSOLE_TTY &sccons[MAXCONS] #define MOUSE_TTY &sccons[MAXCONS+1] static struct tty sccons[MAXCONS+2]; #endif #define SC_MOUSE 128 #define SC_CONSOLE 255 u_short *Crtat; #ifdef PC98 u_short *Atrat; static u_char default_kanji = UJIS; #endif static const int nsccons = MAXCONS+2; #define WRAPHIST(scp, pointer, offset)\ ((scp)->history + ((((pointer) - (scp)->history) + (scp)->history_size \ + (offset)) % (scp)->history_size)) #ifdef PC98 #define WRAPHIST_A(scp, pointer, offset)\ ((scp->his_atr) + ((((pointer) - (scp->his_atr)) + (scp)->history_size \ + (offset)) % (scp)->history_size)) #endif #define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG) /* prototypes */ static int scattach(struct isa_device *dev); static ointhand2_t scintr; static int scparam(struct tty *tp, struct termios *t); static int scprobe(struct isa_device *dev); static int scvidprobe(int unit, int flags); static int sckbdprobe(int unit, int flags); static void scstart(struct tty *tp); static void scmousestart(struct tty *tp); static void scinit(void); static void scshutdown(int howto, void *arg); static u_int scgetc(u_int flags); #define SCGETC_CN 1 #define SCGETC_NONBLOCK 2 static void sccnupdate(scr_stat *scp); static scr_stat *alloc_scp(void); static void init_scp(scr_stat *scp); static void sc_bcopy(scr_stat *scp, u_short *p, int from, int to, int mark); static int get_scr_num(void); static timeout_t scrn_timer; static void scrn_update(scr_stat *scp, int show_cursor); static void scrn_saver(void (*saver)(int), int blank); static void stop_scrn_saver(void (*saver)(int)); static int wait_scrn_saver_stop(void); static int switch_scr(scr_stat *scp, u_int next_scr); static void exchange_scr(void); static void scan_esc(scr_stat *scp, u_char c); static void ansi_put(scr_stat *scp, u_char *buf, int len); static void draw_cursor_image(scr_stat *scp); static void remove_cursor_image(scr_stat *scp); static void move_crsr(scr_stat *scp, int x, int y); static u_char *get_fstr(u_int c, u_int *len); static void history_to_screen(scr_stat *scp); static int history_up_line(scr_stat *scp); static int history_down_line(scr_stat *scp); static int mask2attr(struct term_stat *term); #ifndef PC98 static void set_keyboard(int command, int data); #endif static void update_leds(int which); static void set_destructive_cursor(scr_stat *scp); static void set_mouse_pos(scr_stat *scp); static int skip_spc_right(scr_stat *scp, u_short *p); static int skip_spc_left(scr_stat *scp, u_short *p); static void mouse_cut(scr_stat *scp); static void mouse_cut_start(scr_stat *scp); static void mouse_cut_end(scr_stat *scp); static void mouse_cut_word(scr_stat *scp); static void mouse_cut_line(scr_stat *scp); static void mouse_cut_extend(scr_stat *scp); static void mouse_paste(scr_stat *scp); static void draw_mouse_image(scr_stat *scp); static void remove_mouse_image(scr_stat *scp); static void draw_cutmarking(scr_stat *scp); static void remove_cutmarking(scr_stat *scp); static void do_bell(scr_stat *scp, int pitch, int duration); static timeout_t blink_screen; #ifdef SC_SPLASH_SCREEN static void scsplash_init(scr_stat *scp); static void scsplash_term(scr_stat *scp); static void scsplash_saver(int show); #define scsplash_stick(stick) (sticky_splash = (stick)) #else #define scsplash_stick(stick) #endif +static cn_probe_t sccnprobe; +static cn_init_t sccninit; +static cn_getc_t sccngetc; +static cn_checkc_t sccncheckc; +static cn_putc_t sccnputc; + +CONS_DRIVER(sc, sccnprobe, sccninit, sccngetc, sccncheckc, sccnputc); + struct isa_driver scdriver = { scprobe, scattach, "sc", 1 }; static d_open_t scopen; static d_close_t scclose; static d_read_t scread; static d_write_t scwrite; static d_ioctl_t scioctl; static d_mmap_t scmmap; #define CDEV_MAJOR 12 static struct cdevsw sc_cdevsw = { scopen, scclose, scread, scwrite, scioctl, nullstop, noreset, scdevtotty, ttpoll, scmmap, nostrategy, "sc", NULL, -1, nodump, nopsize, D_TTY, }; #ifdef PC98 static u_char ibmpc_to_pc98[16] = { 0x01,0x21,0x81,0xa1,0x41,0x61,0xc1,0xe1, 0x09,0x29,0x89,0xa9,0x49,0x69,0xc9,0xe9 }; static u_char ibmpc_to_pc98rev[16] = { 0x05,0x25,0x85,0xa5,0x45,0x65,0xc5,0xe5, 0x0d,0x2d,0x8d,0xad,0x4d,0x6d,0xcd,0xed }; unsigned int at2pc98(unsigned int attr) { unsigned char fg_at, bg_at; unsigned int at; fg_at = ((attr >> 8) & 0x0F); bg_at = ((attr >> 8) & 0xF0); if (bg_at) { if (bg_at & 0x80) { if (bg_at & 0x70) { /* reverse & blink */ at = ibmpc_to_pc98rev[bg_at >> 4] | 0x02; } else { /* normal & blink */ at = ibmpc_to_pc98[fg_at] | 0x02; } } else { /* reverse */ at = ibmpc_to_pc98rev[bg_at >> 4]; } } else { /* normal */ at = ibmpc_to_pc98[fg_at]; } at |= ((fg_at|bg_at) << 8); return (at); } #endif static void draw_cursor_image(scr_stat *scp) { #ifndef PC98 u_short cursor_image; u_short *ptr; u_short prev_image; #endif #ifdef PC98 int pos = scp->cursor_pos - scp->scr_buf; while((inb(TEXT_GDC + 0) & 0x04) == 0) {} outb(TEXT_GDC + 2, 0x49); /* CSRW */ outb(TEXT_GDC + 0, pos & 0xff); /* EADl */ outb(TEXT_GDC + 0, pos >> 8); /* EADh */ #else if (ISPIXELSC(scp)) { sc_bcopy(scp, scp->scr_buf, scp->cursor_pos - scp->scr_buf, scp->cursor_pos - scp->scr_buf, 1); return; } ptr = (u_short *)(get_adapter(scp)->va_window) + (scp->cursor_pos - scp->scr_buf); /* do we have a destructive cursor ? */ if (sc_flags & CHAR_CURSOR) { prev_image = scp->cursor_saveunder; cursor_image = *ptr & 0x00ff; if (cursor_image == DEAD_CHAR) cursor_image = prev_image & 0x00ff; cursor_image |= *(scp->cursor_pos) & 0xff00; scp->cursor_saveunder = cursor_image; /* update the cursor bitmap if the char under the cursor has changed */ if (prev_image != cursor_image) set_destructive_cursor(scp); /* modify cursor_image */ if (!(sc_flags & BLINK_CURSOR)||((sc_flags & BLINK_CURSOR)&&(blinkrate & 4))){ /* * When the mouse pointer is at the same position as the cursor, * the cursor bitmap needs to be updated even if the char under * the cursor hasn't changed, because the mouse pionter may * have moved by a few dots within the cursor cel. */ if ((prev_image == cursor_image) && (cursor_image != *(scp->cursor_pos))) set_destructive_cursor(scp); cursor_image &= 0xff00; cursor_image |= DEAD_CHAR; } } else { cursor_image = (*(ptr) & 0x00ff) | *(scp->cursor_pos) & 0xff00; scp->cursor_saveunder = cursor_image; if (!(sc_flags & BLINK_CURSOR)||((sc_flags & BLINK_CURSOR)&&(blinkrate & 4))){ if ((cursor_image & 0x7000) == 0x7000) { cursor_image &= 0x8fff; if(!(cursor_image & 0x0700)) cursor_image |= 0x0700; } else { cursor_image |= 0x7000; if ((cursor_image & 0x0700) == 0x0700) cursor_image &= 0xf0ff; } } } *ptr = cursor_image; #endif } static void remove_cursor_image(scr_stat *scp) { #ifndef PC98 if (ISPIXELSC(scp)) sc_bcopy(scp, scp->scr_buf, scp->cursor_oldpos - scp->scr_buf, scp->cursor_oldpos - scp->scr_buf, 0); else *((u_short *)(get_adapter(scp)->va_window) + (scp->cursor_oldpos - scp->scr_buf)) = scp->cursor_saveunder; #endif } static void move_crsr(scr_stat *scp, int x, int y) { if (x < 0) x = 0; if (y < 0) y = 0; if (x >= scp->xsize) x = scp->xsize-1; if (y >= scp->ysize) y = scp->ysize-1; scp->xpos = x; scp->ypos = y; scp->cursor_pos = scp->scr_buf + scp->ypos * scp->xsize + scp->xpos; #ifdef PC98 scp->cursor_atr = scp->atr_buf + scp->ypos * scp->xsize + scp->xpos; #endif } static int scprobe(struct isa_device *dev) { if (!scvidprobe(dev->id_unit, dev->id_flags)) { if (bootverbose) printf("sc%d: no video adapter is found.\n", dev->id_unit); return (0); } #ifndef PC98 #if defined(VESA) && defined(VM86) if (vesa_load()) return FALSE; #endif (*biosvidsw.diag)(bootverbose); #endif /* PC98 */ sc_port = dev->id_iobase; if (sckbdprobe(dev->id_unit, dev->id_flags)) return (IO_KBDSIZE); else return ((dev->id_flags & DETECT_KBD) ? 0 : IO_KBDSIZE); } /* probe video adapters, return TRUE if found */ static int scvidprobe(int unit, int flags) { #ifndef PC98 video_adapter_t *adp; #endif /* do this test only once */ if (init_done != COLD) return (crtc_type != -1); #ifdef PC98 Crtat = (u_short *)TEXT_VRAM; Atrat = (u_short *)TEXT_VRAM + ATTR_OFFSET; crtc_type = KD_PC98; #else if ((*biosvidsw.init)() <= 0) return FALSE; if ((adp = (*biosvidsw.adapter)(V_ADP_PRIMARY)) == NULL) return FALSE; crtc_type = adp->va_type; crtc_vga = (crtc_type == KD_VGA); crtc_addr = adp->va_crtc_addr; Crtat = (u_short *)adp->va_window; adp_flags = adp->va_flags; initial_video_mode = adp->va_initial_mode; bios_video_mode = adp->va_initial_bios_mode; #endif /* PC98 */ return TRUE; } /* probe the keyboard, return TRUE if found */ static int sckbdprobe(int unit, int flags) { #ifndef PC98 int codeset; int c = -1; int m; int res, id; #endif sc_kbdc = kbdc_open(sc_port); #ifndef PC98 if (!kbdc_lock(sc_kbdc, TRUE)) { /* driver error? */ printf("sc%d: unable to lock the controller.\n", unit); return ((flags & DETECT_KBD) ? FALSE : TRUE); } /* flush any noise in the buffer */ empty_both_buffers(sc_kbdc, 10); /* save the current keyboard controller command byte */ m = kbdc_get_device_mask(sc_kbdc) & ~KBD_KBD_CONTROL_BITS; c = get_controller_command_byte(sc_kbdc); if (c == -1) { /* CONTROLLER ERROR */ printf("sc%d: unable to get the current command byte value.\n", unit); goto fail; } if (bootverbose) printf("sc%d: the current keyboard controller command byte %04x\n", unit, c); #if 0 /* override the keyboard lock switch */ c |= KBD_OVERRIDE_KBD_LOCK; #endif /* * The keyboard may have been screwed up by the boot block. * We may just be able to recover from error by testing the controller * and the keyboard port. The controller command byte needs to be saved * before this recovery operation, as some controllers seem to set * the command byte to particular values. */ test_controller(sc_kbdc); test_kbd_port(sc_kbdc); /* enable the keyboard port, but disable the keyboard intr. */ if (!set_controller_command_byte(sc_kbdc, KBD_KBD_CONTROL_BITS, KBD_ENABLE_KBD_PORT | KBD_DISABLE_KBD_INT)) { /* CONTROLLER ERROR * there is very little we can do... */ printf("sc%d: unable to set the command byte.\n", unit); goto fail; } /* * Check if we have an XT keyboard before we attempt to reset it. * The procedure assumes that the keyboard and the controller have * been set up properly by BIOS and have not been messed up * during the boot process. */ codeset = -1; if (flags & XT_KEYBD) /* the user says there is a XT keyboard */ codeset = 1; #ifdef DETECT_XT_KEYBOARD else if ((c & KBD_TRANSLATION) == 0) { /* SET_SCANCODE_SET is not always supported; ignore error */ if (send_kbd_command_and_data(sc_kbdc, KBDC_SET_SCANCODE_SET, 0) == KBD_ACK) codeset = read_kbd_data(sc_kbdc); } if (bootverbose) printf("sc%d: keyboard scancode set %d\n", unit, codeset); #endif /* DETECT_XT_KEYBOARD */ if (flags & KBD_NORESET) { write_kbd_command(sc_kbdc, KBDC_ECHO); if (read_kbd_data(sc_kbdc) != KBD_ECHO) { empty_both_buffers(sc_kbdc, 10); test_controller(sc_kbdc); test_kbd_port(sc_kbdc); if (bootverbose) printf("sc%d: failed to get response from the keyboard.\n", unit); goto fail; } } else { /* reset keyboard hardware */ if (!reset_kbd(sc_kbdc)) { /* KEYBOARD ERROR * Keyboard reset may fail either because the keyboard doen't * exist, or because the keyboard doesn't pass the self-test, * or the keyboard controller on the motherboard and the keyboard * somehow fail to shake hands. It is just possible, particularly * in the last case, that the keyoard controller may be left * in a hung state. test_controller() and test_kbd_port() appear * to bring the keyboard controller back (I don't know why and * how, though.) */ empty_both_buffers(sc_kbdc, 10); test_controller(sc_kbdc); test_kbd_port(sc_kbdc); /* We could disable the keyboard port and interrupt... but, * the keyboard may still exist (see above). */ if (bootverbose) printf("sc%d: failed to reset the keyboard.\n", unit); goto fail; } } /* * Allow us to set the XT_KEYBD flag in UserConfig so that keyboards * such as those on the IBM ThinkPad laptop computers can be used * with the standard console driver. */ if (codeset == 1) { if (send_kbd_command_and_data( sc_kbdc, KBDC_SET_SCANCODE_SET, codeset) == KBD_ACK) { /* XT kbd doesn't need scan code translation */ c &= ~KBD_TRANSLATION; } else { /* KEYBOARD ERROR * The XT kbd isn't usable unless the proper scan code set * is selected. */ printf("sc%d: unable to set the XT keyboard mode.\n", unit); goto fail; } } /* enable the keyboard port and intr. */ if (!set_controller_command_byte(sc_kbdc, KBD_KBD_CONTROL_BITS | KBD_TRANSLATION | KBD_OVERRIDE_KBD_LOCK, (c & (KBD_TRANSLATION | KBD_OVERRIDE_KBD_LOCK)) | KBD_ENABLE_KBD_PORT | KBD_ENABLE_KBD_INT)) { /* CONTROLLER ERROR * This is serious; we are left with the disabled keyboard intr. */ printf("sc%d: unable to enable the keyboard port and intr.\n", unit); goto fail; } /* Get the ID of the keyboard, if any */ empty_kbd_buffer(sc_kbdc, 5); res = send_kbd_command(sc_kbdc, KBDC_SEND_DEV_ID); if (res == KBD_ACK) { /* 10ms delay */ DELAY(10000); id = (read_kbd_data(sc_kbdc) << 8) | read_kbd_data(sc_kbdc); if (bootverbose) printf("sc%d: keyboard device ID: %04x\n", unit, id); } kbdc_set_device_mask(sc_kbdc, m | KBD_KBD_CONTROL_BITS), kbdc_lock(sc_kbdc, FALSE); #endif /* !PC98 */ return TRUE; #ifndef PC98 fail: if (c != -1) /* try to restore the command byte as before, if possible */ set_controller_command_byte(sc_kbdc, 0xff, c); kbdc_set_device_mask(sc_kbdc, (flags & DETECT_KBD) ? m : m | KBD_KBD_CONTROL_BITS); kbdc_lock(sc_kbdc, FALSE); return FALSE; #endif /* !PC98 */ } #if NAPM > 0 static int scresume(void *dummy) { shfts = ctls = alts = agrs = metas = accents = 0; return 0; } #endif static int scattach(struct isa_device *dev) { scr_stat *scp; #ifndef PC98 video_info_t info; #endif dev_t cdev = makedev(CDEV_MAJOR, 0); #ifdef DEVFS int vc; #endif dev->id_ointr = scintr; scinit(); sc_flags = dev->id_flags; if (!ISFONTAVAIL(adp_flags)) sc_flags &= ~CHAR_CURSOR; scp = console[0]; /* copy temporary buffer to final buffer */ scp->scr_buf = NULL; #ifdef PC98 scp->atr_buf = NULL; #endif sc_alloc_scr_buffer(scp, FALSE, FALSE); bcopy(sc_buffer, scp->scr_buf, scp->xsize*scp->ysize*sizeof(u_short)); #ifdef PC98 bcopy(Atrat, scp->atr_buf, scp->xsize*scp->ysize*sizeof(u_short)); #endif /* cut buffer is available only when the mouse pointer is used */ if (ISMOUSEAVAIL(adp_flags)) sc_alloc_cut_buffer(scp, FALSE); /* initialize history buffer & pointers */ sc_alloc_history_buffer(scp, sc_history_size, 0, FALSE); #ifndef PC98 #if defined(VESA) && defined(VM86) if ((sc_flags & VESA800X600) && ((*biosvidsw.get_info)(scp->adp, M_VESA_800x600, &info) == 0)) { #ifdef SC_SPLASH_SCREEN scsplash_term(scp); #endif sc_set_graphics_mode(scp, NULL, M_VESA_800x600); sc_set_pixel_mode(scp, NULL, COL, ROW, 16); initial_video_mode = M_VESA_800x600; #ifdef SC_SPLASH_SCREEN scsplash_init(scp); #endif } #endif /* VESA && VM86 */ #endif /* PC98 */ /* initialize cursor stuff */ if (!ISGRAPHSC(scp)) draw_cursor_image(scp); /* get screen update going */ scrn_timer((void *)TRUE); update_leds(scp->status); printf("sc%d: ", dev->id_unit); switch(crtc_type) { #ifdef PC98 case KD_PC98: printf(" "); break; #else case KD_VGA: printf("VGA %s", (adp_flags & V_ADP_COLOR) ? "color" : "mono"); break; case KD_EGA: printf("EGA %s", (adp_flags & V_ADP_COLOR) ? "color" : "mono"); break; case KD_CGA: printf("CGA"); break; case KD_MONO: case KD_HERCULES: default: printf("MDA/Hercules"); break; #endif /* PC98 */ } printf(" <%d virtual consoles, flags=0x%x>\n", MAXCONS, sc_flags); #if NAPM > 0 scp->r_hook.ah_fun = scresume; scp->r_hook.ah_arg = NULL; scp->r_hook.ah_name = "system keyboard"; scp->r_hook.ah_order = APM_MID_ORDER; apm_hook_establish(APM_HOOK_RESUME , &scp->r_hook); #endif at_shutdown(scshutdown, NULL, SHUTDOWN_PRE_SYNC); cdevsw_add(&cdev, &sc_cdevsw, NULL); #ifdef DEVFS for (vc = 0; vc < MAXCONS; vc++) sc_devfs_token[vc] = devfs_add_devswf(&sc_cdevsw, vc, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc); sc_mouse_devfs_token = devfs_add_devswf(&sc_cdevsw, SC_MOUSE, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "sysmouse"); sc_console_devfs_token = devfs_add_devswf(&sc_cdevsw, SC_CONSOLE, DV_CHR, UID_ROOT, GID_WHEEL, 0600, "consolectl"); #endif return 0; } struct tty *scdevtotty(dev_t dev) { int unit = minor(dev); if (init_done == COLD) return(NULL); if (unit == SC_CONSOLE) return CONSOLE_TTY; if (unit == SC_MOUSE) return MOUSE_TTY; if (unit >= MAXCONS || unit < 0) return(NULL); return VIRTUAL_TTY(unit); } int scopen(dev_t dev, int flag, int mode, struct proc *p) { struct tty *tp = scdevtotty(dev); if (!tp) return(ENXIO); tp->t_oproc = (minor(dev) == SC_MOUSE) ? scmousestart : scstart; tp->t_param = scparam; tp->t_dev = dev; if (!(tp->t_state & TS_ISOPEN)) { ttychars(tp); /* Use the current setting of the <-- key as default VERASE. */ /* If the Delete key is preferable, an stty is necessary */ tp->t_cc[VERASE] = key_map.key[0x0e].map[0]; tp->t_iflag = TTYDEF_IFLAG; tp->t_oflag = TTYDEF_OFLAG; tp->t_cflag = TTYDEF_CFLAG; tp->t_lflag = TTYDEF_LFLAG; tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; scparam(tp, &tp->t_termios); (*linesw[tp->t_line].l_modem)(tp, 1); if (minor(dev) == SC_MOUSE) mouse_level = 0; /* XXX */ } else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) return(EBUSY); if (minor(dev) < MAXCONS && !console[minor(dev)]) { console[minor(dev)] = alloc_scp(); #ifndef PC98 if (ISGRAPHSC(console[minor(dev)])) sc_set_pixel_mode(console[minor(dev)], NULL, COL, ROW, 16); #endif /* PC98 */ } if (minor(dev)t_winsize.ws_col && !tp->t_winsize.ws_row) { tp->t_winsize.ws_col = console[minor(dev)]->xsize; tp->t_winsize.ws_row = console[minor(dev)]->ysize; } return ((*linesw[tp->t_line].l_open)(dev, tp)); } int scclose(dev_t dev, int flag, int mode, struct proc *p) { struct tty *tp = scdevtotty(dev); struct scr_stat *scp; if (!tp) return(ENXIO); if (minor(dev) < MAXCONS) { scp = sc_get_scr_stat(tp->t_dev); if (scp->status & SWITCH_WAIT_ACQ) wakeup((caddr_t)&scp->smode); #if not_yet_done if (scp == &main_console) { scp->pid = 0; scp->proc = NULL; scp->smode.mode = VT_AUTO; } else { free(scp->scr_buf, M_DEVBUF); #ifdef PC98 free(scp->atr_buf, M_DEVBUF); if (scp->his_atr != NULL) free(scp->his_atr, M_DEVBUF); #endif if (scp->history != NULL) { free(scp->history, M_DEVBUF); if (scp->history_size / scp->xsize > imax(sc_history_size, scp->ysize)) extra_history_size += scp->history_size / scp->xsize - imax(sc_history_size, scp->ysize); } free(scp, M_DEVBUF); console[minor(dev)] = NULL; } #else scp->pid = 0; scp->proc = NULL; scp->smode.mode = VT_AUTO; #endif } spltty(); (*linesw[tp->t_line].l_close)(tp, flag); ttyclose(tp); spl0(); return(0); } int scread(dev_t dev, struct uio *uio, int flag) { struct tty *tp = scdevtotty(dev); if (!tp) return(ENXIO); return((*linesw[tp->t_line].l_read)(tp, uio, flag)); } int scwrite(dev_t dev, struct uio *uio, int flag) { struct tty *tp = scdevtotty(dev); if (!tp) return(ENXIO); return((*linesw[tp->t_line].l_write)(tp, uio, flag)); } static void scintr(int unit) { static struct tty *cur_tty; int c, len; u_char *cp; /* * Loop while there is still input to get from the keyboard. * I don't think this is nessesary, and it doesn't fix * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX */ while ((c = scgetc(SCGETC_NONBLOCK)) != NOKEY) { cur_tty = VIRTUAL_TTY(get_scr_num()); if (!(cur_tty->t_state & TS_ISOPEN)) if (!((cur_tty = CONSOLE_TTY)->t_state & TS_ISOPEN)) continue; switch (c & 0xff00) { case 0x0000: /* normal key */ (*linesw[cur_tty->t_line].l_rint)(c & 0xFF, cur_tty); break; case FKEY: /* function key, return string */ if (cp = get_fstr((u_int)c, (u_int *)&len)) { while (len-- > 0) (*linesw[cur_tty->t_line].l_rint)(*cp++ & 0xFF, cur_tty); } break; case MKEY: /* meta is active, prepend ESC */ (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty); (*linesw[cur_tty->t_line].l_rint)(c & 0xFF, cur_tty); break; case BKEY: /* backtab fixed sequence (esc [ Z) */ (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty); (*linesw[cur_tty->t_line].l_rint)('[', cur_tty); (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty); break; } } #if 0 if (cur_console->status & MOUSE_ENABLED) { cur_console->status &= ~MOUSE_VISIBLE; remove_mouse_image(cur_console); } #else if (cur_console->status & MOUSE_VISIBLE) { remove_mouse_image(cur_console); cur_console->status &= ~MOUSE_VISIBLE; } #endif } static int scparam(struct tty *tp, struct termios *t) { tp->t_ispeed = t->c_ispeed; tp->t_ospeed = t->c_ospeed; tp->t_cflag = t->c_cflag; return 0; } int scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) { u_int delta_ehs; int error; int i; struct tty *tp; scr_stat *scp; #ifndef PC98 video_adapter_t *adp; #endif int s; tp = scdevtotty(dev); if (!tp) return ENXIO; scp = sc_get_scr_stat(tp->t_dev); /* If there is a user_ioctl function call that first */ if (sc_user_ioctl) { error = (*sc_user_ioctl)(dev, cmd, data, flag, p); if (error != ENOIOCTL) return error; } error = sc_vid_ioctl(tp, cmd, data, flag, p); if (error != ENOIOCTL) return error; switch (cmd) { /* process console hardware related ioctl's */ case GIO_ATTR: /* get current attributes */ *(int*)data = (scp->term.cur_attr >> 8) & 0xFF; return 0; case GIO_COLOR: /* is this a color console ? */ #ifdef PC98 *(int*)data = 0; #else *(int *)data = (adp_flags & V_ADP_COLOR) ? 1 : 0; #endif return 0; case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */ if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) return EINVAL; s = spltty(); scrn_blank_time = *(int *)data; run_scrn_saver = (scrn_blank_time != 0); splx(s); return 0; case CONS_CURSORTYPE: /* set cursor type blink/noblink */ if ((*(int*)data) & 0x01) sc_flags |= BLINK_CURSOR; else sc_flags &= ~BLINK_CURSOR; if ((*(int*)data) & 0x02) { #ifndef PC98 if (!ISFONTAVAIL(get_adapter(scp)->va_flags)) return ENXIO; #endif /* PC98 */ sc_flags |= CHAR_CURSOR; } else sc_flags &= ~CHAR_CURSOR; /* * The cursor shape is global property; all virtual consoles * are affected. Update the cursor in the current console... */ if (!ISGRAPHSC(cur_console)) { remove_cursor_image(cur_console); if (sc_flags & CHAR_CURSOR) set_destructive_cursor(cur_console); draw_cursor_image(cur_console); } return 0; case CONS_BELLTYPE: /* set bell type sound/visual */ if ((*(int *)data) & 0x01) sc_flags |= VISUAL_BELL; else sc_flags &= ~VISUAL_BELL; if ((*(int *)data) & 0x02) sc_flags |= QUIET_BELL; else sc_flags &= ~QUIET_BELL; return 0; case CONS_HISTORY: /* set history size */ if (*(int *)data > 0) { int lines; /* buffer size to allocate */ int lines0; /* current buffer size */ lines = imax(*(int *)data, scp->ysize); lines0 = (scp->history != NULL) ? scp->history_size / scp->xsize : scp->ysize; if (lines0 > imax(sc_history_size, scp->ysize)) delta_ehs = lines0 - imax(sc_history_size, scp->ysize); else delta_ehs = 0; /* * syscons unconditionally allocates buffers upto SC_HISTORY_SIZE * lines or scp->ysize lines, whichever is larger. A value * greater than that is allowed, subject to extra_history_size. */ if (lines > imax(sc_history_size, scp->ysize)) if (lines - imax(sc_history_size, scp->ysize) > extra_history_size + delta_ehs) return EINVAL; if (cur_console->status & BUFFER_SAVED) return EBUSY; sc_alloc_history_buffer(scp, lines, delta_ehs, TRUE); return 0; } else return EINVAL; case CONS_MOUSECTL: /* control mouse arrow */ case OLD_CONS_MOUSECTL: { /* MOUSE_BUTTON?DOWN -> MOUSE_MSC_BUTTON?UP */ static int butmap[8] = { MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP, MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP, MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP, MOUSE_MSC_BUTTON3UP, MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP, MOUSE_MSC_BUTTON2UP, MOUSE_MSC_BUTTON1UP, 0, }; mouse_info_t *mouse = (mouse_info_t*)data; mouse_info_t buf; /* FIXME: */ #ifndef PC98 if (!ISMOUSEAVAIL(get_adapter(scp)->va_flags)) return ENODEV; #endif /* PC98 */ if (cmd == OLD_CONS_MOUSECTL) { static u_char swapb[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; old_mouse_info_t *old_mouse = (old_mouse_info_t *)data; mouse = &buf; mouse->operation = old_mouse->operation; switch (mouse->operation) { case MOUSE_MODE: mouse->u.mode = old_mouse->u.mode; break; case MOUSE_SHOW: case MOUSE_HIDE: break; case MOUSE_MOVEABS: case MOUSE_MOVEREL: case MOUSE_ACTION: mouse->u.data.x = old_mouse->u.data.x; mouse->u.data.y = old_mouse->u.data.y; mouse->u.data.z = 0; mouse->u.data.buttons = swapb[old_mouse->u.data.buttons & 0x7]; break; case MOUSE_GETINFO: old_mouse->u.data.x = scp->mouse_xpos; old_mouse->u.data.y = scp->mouse_ypos; old_mouse->u.data.buttons = swapb[scp->mouse_buttons & 0x7]; break; default: return EINVAL; } } switch (mouse->operation) { case MOUSE_MODE: if (ISSIGVALID(mouse->u.mode.signal)) { scp->mouse_signal = mouse->u.mode.signal; scp->mouse_proc = p; scp->mouse_pid = p->p_pid; } else { scp->mouse_signal = 0; scp->mouse_proc = NULL; scp->mouse_pid = 0; } return 0; case MOUSE_SHOW: if (ISTEXTSC(scp) && !(scp->status & MOUSE_ENABLED)) { scp->status |= (MOUSE_ENABLED | MOUSE_VISIBLE); scp->mouse_oldpos = scp->mouse_pos; mark_all(scp); return 0; } else return EINVAL; break; case MOUSE_HIDE: if (ISTEXTSC(scp) && (scp->status & MOUSE_ENABLED)) { scp->status &= ~(MOUSE_ENABLED | MOUSE_VISIBLE); mark_all(scp); return 0; } else return EINVAL; break; case MOUSE_MOVEABS: scp->mouse_xpos = mouse->u.data.x; scp->mouse_ypos = mouse->u.data.y; set_mouse_pos(scp); break; case MOUSE_MOVEREL: scp->mouse_xpos += mouse->u.data.x; scp->mouse_ypos += mouse->u.data.y; set_mouse_pos(scp); break; case MOUSE_GETINFO: mouse->u.data.x = scp->mouse_xpos; mouse->u.data.y = scp->mouse_ypos; mouse->u.data.z = 0; mouse->u.data.buttons = scp->mouse_buttons; return 0; case MOUSE_ACTION: case MOUSE_MOTION_EVENT: /* this should maybe only be settable from /dev/consolectl SOS */ /* send out mouse event on /dev/sysmouse */ mouse_status.dx += mouse->u.data.x; mouse_status.dy += mouse->u.data.y; mouse_status.dz += mouse->u.data.z; if (mouse->operation == MOUSE_ACTION) mouse_status.button = mouse->u.data.buttons; mouse_status.flags |= ((mouse->u.data.x || mouse->u.data.y || mouse->u.data.z) ? MOUSE_POSCHANGED : 0) | (mouse_status.obutton ^ mouse_status.button); if (mouse_status.flags == 0) return 0; if (ISTEXTSC(cur_console) && (cur_console->status & MOUSE_ENABLED)) cur_console->status |= MOUSE_VISIBLE; if ((MOUSE_TTY)->t_state & TS_ISOPEN) { u_char buf[MOUSE_SYS_PACKETSIZE]; int j; /* the first five bytes are compatible with MouseSystems' */ buf[0] = MOUSE_MSC_SYNC | butmap[mouse_status.button & MOUSE_STDBUTTONS]; j = imax(imin(mouse->u.data.x, 255), -256); buf[1] = j >> 1; buf[3] = j - buf[1]; j = -imax(imin(mouse->u.data.y, 255), -256); buf[2] = j >> 1; buf[4] = j - buf[2]; for (j = 0; j < MOUSE_MSC_PACKETSIZE; j++) (*linesw[(MOUSE_TTY)->t_line].l_rint)(buf[j],MOUSE_TTY); if (mouse_level >= 1) { /* extended part */ j = imax(imin(mouse->u.data.z, 127), -128); buf[5] = (j >> 1) & 0x7f; buf[6] = (j - (j >> 1)) & 0x7f; /* buttons 4-10 */ buf[7] = (~mouse_status.button >> 3) & 0x7f; for (j = MOUSE_MSC_PACKETSIZE; j < MOUSE_SYS_PACKETSIZE; j++) (*linesw[(MOUSE_TTY)->t_line].l_rint)(buf[j],MOUSE_TTY); } } if (cur_console->mouse_signal) { cur_console->mouse_buttons = mouse->u.data.buttons; /* has controlling process died? */ if (cur_console->mouse_proc && (cur_console->mouse_proc != pfind(cur_console->mouse_pid))){ cur_console->mouse_signal = 0; cur_console->mouse_proc = NULL; cur_console->mouse_pid = 0; } else psignal(cur_console->mouse_proc, cur_console->mouse_signal); } else if (mouse->operation == MOUSE_ACTION && cut_buffer != NULL) { /* process button presses */ if ((cur_console->mouse_buttons ^ mouse->u.data.buttons) && ISTEXTSC(cur_console)) { cur_console->mouse_buttons = mouse->u.data.buttons; if (cur_console->mouse_buttons & MOUSE_BUTTON1DOWN) mouse_cut_start(cur_console); else mouse_cut_end(cur_console); if (cur_console->mouse_buttons & MOUSE_BUTTON2DOWN || cur_console->mouse_buttons & MOUSE_BUTTON3DOWN) mouse_paste(cur_console); } } if (mouse->u.data.x != 0 || mouse->u.data.y != 0) { cur_console->mouse_xpos += mouse->u.data.x; cur_console->mouse_ypos += mouse->u.data.y; set_mouse_pos(cur_console); } break; case MOUSE_BUTTON_EVENT: if ((mouse->u.event.id & MOUSE_BUTTONS) == 0) return EINVAL; if (mouse->u.event.value < 0) return EINVAL; if (mouse->u.event.value > 0) { cur_console->mouse_buttons |= mouse->u.event.id; mouse_status.button |= mouse->u.event.id; } else { cur_console->mouse_buttons &= ~mouse->u.event.id; mouse_status.button &= ~mouse->u.event.id; } mouse_status.flags |= mouse_status.obutton ^ mouse_status.button; if (mouse_status.flags == 0) return 0; if (ISTEXTSC(cur_console) && (cur_console->status & MOUSE_ENABLED)) cur_console->status |= MOUSE_VISIBLE; if ((MOUSE_TTY)->t_state & TS_ISOPEN) { u_char buf[8]; int i; buf[0] = MOUSE_MSC_SYNC | butmap[mouse_status.button & MOUSE_STDBUTTONS]; buf[7] = (~mouse_status.button >> 3) & 0x7f; buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0; for (i = 0; i < ((mouse_level >= 1) ? MOUSE_SYS_PACKETSIZE : MOUSE_MSC_PACKETSIZE); i++) (*linesw[(MOUSE_TTY)->t_line].l_rint)(buf[i],MOUSE_TTY); } if (cur_console->mouse_signal) { if (cur_console->mouse_proc && (cur_console->mouse_proc != pfind(cur_console->mouse_pid))){ cur_console->mouse_signal = 0; cur_console->mouse_proc = NULL; cur_console->mouse_pid = 0; } else psignal(cur_console->mouse_proc, cur_console->mouse_signal); break; } if (!ISTEXTSC(cur_console) || (cut_buffer == NULL)) break; switch (mouse->u.event.id) { case MOUSE_BUTTON1DOWN: switch (mouse->u.event.value % 4) { case 0: /* up */ mouse_cut_end(cur_console); break; case 1: mouse_cut_start(cur_console); break; case 2: mouse_cut_word(cur_console); break; case 3: mouse_cut_line(cur_console); break; } break; case MOUSE_BUTTON2DOWN: switch (mouse->u.event.value) { case 0: /* up */ break; default: mouse_paste(cur_console); break; } break; case MOUSE_BUTTON3DOWN: switch (mouse->u.event.value) { case 0: /* up */ if (!(cur_console->mouse_buttons & MOUSE_BUTTON1DOWN)) mouse_cut_end(cur_console); break; default: mouse_cut_extend(cur_console); break; } break; } break; default: return EINVAL; } /* make screensaver happy */ scsplash_stick(FALSE); run_scrn_saver = FALSE; return 0; } /* MOUSE_XXX: /dev/sysmouse ioctls */ case MOUSE_GETHWINFO: /* get device information */ { mousehw_t *hw = (mousehw_t *)data; if (tp != MOUSE_TTY) return ENOTTY; hw->buttons = 10; /* XXX unknown */ hw->iftype = MOUSE_IF_SYSMOUSE; hw->type = MOUSE_MOUSE; hw->model = MOUSE_MODEL_GENERIC; hw->hwid = 0; return 0; } case MOUSE_GETMODE: /* get protocol/mode */ { mousemode_t *mode = (mousemode_t *)data; if (tp != MOUSE_TTY) return ENOTTY; mode->level = mouse_level; switch (mode->level) { case 0: /* at this level, sysmouse emulates MouseSystems protocol */ mode->protocol = MOUSE_PROTO_MSC; mode->rate = -1; /* unknown */ mode->resolution = -1; /* unknown */ mode->accelfactor = 0; /* disabled */ mode->packetsize = MOUSE_MSC_PACKETSIZE; mode->syncmask[0] = MOUSE_MSC_SYNCMASK; mode->syncmask[1] = MOUSE_MSC_SYNC; break; case 1: /* at this level, sysmouse uses its own protocol */ mode->protocol = MOUSE_PROTO_SYSMOUSE; mode->rate = -1; mode->resolution = -1; mode->accelfactor = 0; mode->packetsize = MOUSE_SYS_PACKETSIZE; mode->syncmask[0] = MOUSE_SYS_SYNCMASK; mode->syncmask[1] = MOUSE_SYS_SYNC; break; } return 0; } case MOUSE_SETMODE: /* set protocol/mode */ { mousemode_t *mode = (mousemode_t *)data; if (tp != MOUSE_TTY) return ENOTTY; if ((mode->level < 0) || (mode->level > 1)) return EINVAL; mouse_level = mode->level; return 0; } case MOUSE_GETLEVEL: /* get operation level */ if (tp != MOUSE_TTY) return ENOTTY; *(int *)data = mouse_level; return 0; case MOUSE_SETLEVEL: /* set operation level */ if (tp != MOUSE_TTY) return ENOTTY; if ((*(int *)data < 0) || (*(int *)data > 1)) return EINVAL; mouse_level = *(int *)data; return 0; case MOUSE_GETSTATUS: /* get accumulated mouse events */ if (tp != MOUSE_TTY) return ENOTTY; s = spltty(); *(mousestatus_t *)data = mouse_status; mouse_status.flags = 0; mouse_status.obutton = mouse_status.button; mouse_status.dx = 0; mouse_status.dy = 0; mouse_status.dz = 0; splx(s); return 0; #if notyet case MOUSE_GETVARS: /* get internal mouse variables */ case MOUSE_SETVARS: /* set internal mouse variables */ if (tp != MOUSE_TTY) return ENOTTY; return ENODEV; #endif case MOUSE_READSTATE: /* read status from the device */ case MOUSE_READDATA: /* read data from the device */ if (tp != MOUSE_TTY) return ENOTTY; return ENODEV; case CONS_GETINFO: /* get current (virtual) console info */ { vid_info_t *ptr = (vid_info_t*)data; if (ptr->size == sizeof(struct vid_info)) { ptr->m_num = get_scr_num(); ptr->mv_col = scp->xpos; ptr->mv_row = scp->ypos; ptr->mv_csz = scp->xsize; ptr->mv_rsz = scp->ysize; ptr->mv_norm.fore = (scp->term.std_color & 0x0f00)>>8; ptr->mv_norm.back = (scp->term.std_color & 0xf000)>>12; ptr->mv_rev.fore = (scp->term.rev_color & 0x0f00)>>8; ptr->mv_rev.back = (scp->term.rev_color & 0xf000)>>12; ptr->mv_grfc.fore = 0; /* not supported */ ptr->mv_grfc.back = 0; /* not supported */ ptr->mv_ovscan = scp->border; ptr->mk_keylock = scp->status & LOCK_KEY_MASK; return 0; } return EINVAL; } case CONS_GETVERS: /* get version number */ *(int*)data = 0x200; /* version 2.0 */ return 0; case CONS_IDLE: /* see if the screen has been idle */ /* * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE, * the user process may have been writing something on the * screen and syscons is not aware of it. Declare the screen * is NOT idle if it is in one of these modes. But there is * an exception to it; if a screen saver is running in the * graphics mode in the current screen, we should say that the * screen has been idle. */ *(int *)data = scrn_idle && (!ISGRAPHSC(cur_console) || (cur_console->status & SAVER_RUNNING)); return 0; case CONS_SAVERMODE: /* set saver mode */ switch(*(int *)data) { case CONS_USR_SAVER: /* if a LKM screen saver is running, stop it first. */ scsplash_stick(FALSE); saver_mode = *(int *)data; s = spltty(); if ((error = wait_scrn_saver_stop())) { splx(s); return error; } scp->status |= SAVER_RUNNING; scsplash_stick(TRUE); splx(s); break; case CONS_LKM_SAVER: s = spltty(); if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING)) scp->status &= ~SAVER_RUNNING; saver_mode = *(int *)data; splx(s); break; default: return EINVAL; } return 0; case CONS_SAVERSTART: /* immediately start/stop the screen saver */ /* * Note that this ioctl does not guarantee the screen saver * actually starts or stops. It merely attempts to do so... */ s = spltty(); run_scrn_saver = (*(int *)data != 0); if (run_scrn_saver) scrn_time_stamp -= scrn_blank_time; splx(s); return 0; #ifdef PC98 case SW_PC98_80x25: case SW_PC98_80x30: /* PC98 TEXT MODES */ if (!crtc_vga) return ENXIO; scp->xsize = 80; scp->status &= ~MOUSE_VISIBLE; remove_cutmarking(scp); s = spltty(); if ((error = wait_scrn_saver_stop())) { splx(s); return error; } if (scp->history != NULL) i = imax(scp->history_size / scp->xsize - imax(SC_HISTORY_SIZE, scp->ysize), 0); else i = 0; switch (cmd & 0xff) { case M_PC98_80x25: scp->ysize = 25; break; #ifdef LINE30 case M_PC98_80x30: scp->ysize = LINE30_ROW; break; #endif default: return EINVAL; } #endif case VT_SETMODE: /* set screen switcher mode */ { struct vt_mode *mode; mode = (struct vt_mode *)data; if (ISSIGVALID(mode->relsig) && ISSIGVALID(mode->acqsig) && ISSIGVALID(mode->frsig)) { bcopy(data, &scp->smode, sizeof(struct vt_mode)); if (scp->smode.mode == VT_PROCESS) { scp->proc = p; scp->pid = scp->proc->p_pid; } return 0; } else return EINVAL; } case VT_GETMODE: /* get screen switcher mode */ bcopy(&scp->smode, data, sizeof(struct vt_mode)); return 0; case VT_RELDISP: /* screen switcher ioctl */ switch(*(int *)data) { case VT_FALSE: /* user refuses to release screen, abort */ if (scp == old_scp && (scp->status & SWITCH_WAIT_REL)) { old_scp->status &= ~SWITCH_WAIT_REL; switch_in_progress = FALSE; return 0; } return EINVAL; case VT_TRUE: /* user has released screen, go on */ if (scp == old_scp && (scp->status & SWITCH_WAIT_REL)) { scp->status &= ~SWITCH_WAIT_REL; exchange_scr(); if (new_scp->smode.mode == VT_PROCESS) { new_scp->status |= SWITCH_WAIT_ACQ; psignal(new_scp->proc, new_scp->smode.acqsig); } else switch_in_progress = FALSE; return 0; } return EINVAL; case VT_ACKACQ: /* acquire acknowledged, switch completed */ if (scp == new_scp && (scp->status & SWITCH_WAIT_ACQ)) { scp->status &= ~SWITCH_WAIT_ACQ; switch_in_progress = FALSE; return 0; } return EINVAL; default: return EINVAL; } /* NOT REACHED */ case VT_OPENQRY: /* return free virtual console */ for (i = 0; i < MAXCONS; i++) { tp = VIRTUAL_TTY(i); if (!(tp->t_state & TS_ISOPEN)) { *(int *)data = i + 1; return 0; } } return EINVAL; case VT_ACTIVATE: /* switch to screen *data */ return switch_scr(scp, *(int *)data - 1); case VT_WAITACTIVE: /* wait for switch to occur */ if (*(int *)data > MAXCONS || *(int *)data < 0) return EINVAL; if (minor(dev) == *(int *)data - 1) return 0; if (*(int *)data == 0) { if (scp == cur_console) return 0; } else scp = console[*(int *)data - 1]; while ((error=tsleep((caddr_t)&scp->smode, PZERO|PCATCH, "waitvt", 0)) == ERESTART) ; return error; case VT_GETACTIVE: *(int *)data = get_scr_num()+1; return 0; case KDENABIO: /* allow io operations */ error = suser(p->p_ucred, &p->p_acflag); if (error != 0) return error; if (securelevel > 0) return EPERM; p->p_md.md_regs->tf_eflags |= PSL_IOPL; return 0; case KDDISABIO: /* disallow io operations (default) */ p->p_md.md_regs->tf_eflags &= ~PSL_IOPL; return 0; case KDSKBSTATE: /* set keyboard state (locks) */ if (*(int *)data & ~LOCK_KEY_MASK) return EINVAL; scp->status &= ~LOCK_KEY_MASK; scp->status |= *(int *)data; if (scp == cur_console) update_leds(scp->status); return 0; case KDGKBSTATE: /* get keyboard state (locks) */ *(int *)data = scp->status & LOCK_KEY_MASK; return 0; case KDSETRAD: /* set keyboard repeat & delay rates */ #ifndef PC98 if (*(int *)data & ~0x7f) return EINVAL; if (sc_kbdc != NULL) set_keyboard(KBDC_SET_TYPEMATIC, *(int *)data); #endif return 0; case KDSKBMODE: /* set keyboard mode */ switch (*(int *)data) { case K_RAW: /* switch to RAW scancode mode */ scp->status &= ~KBD_CODE_MODE; scp->status |= KBD_RAW_MODE; return 0; case K_CODE: /* switch to CODE mode */ scp->status &= ~KBD_RAW_MODE; scp->status |= KBD_CODE_MODE; return 0; case K_XLATE: /* switch to XLT ascii mode */ if (scp == cur_console && scp->status & KBD_RAW_MODE) shfts = ctls = alts = agrs = metas = accents = 0; scp->status &= ~(KBD_RAW_MODE | KBD_CODE_MODE); return 0; default: return EINVAL; } /* NOT REACHED */ case KDGKBMODE: /* get keyboard mode */ *(int *)data = (scp->status & KBD_RAW_MODE) ? K_RAW : ((scp->status & KBD_CODE_MODE) ? K_CODE : K_XLATE); return 0; case KDMKTONE: /* sound the bell */ if (*(int*)data) do_bell(scp, (*(int*)data)&0xffff, (((*(int*)data)>>16)&0xffff)*hz/1000); else do_bell(scp, scp->bell_pitch, scp->bell_duration); return 0; case KIOCSOUND: /* make tone (*data) hz */ if (scp == cur_console) { if (*(int*)data) { int pitch = timer_freq / *(int*)data; #ifdef PC98 /* enable counter 1 */ outb(0x35, inb(0x35) & 0xf7); /* set command for counter 1, 2 byte write */ if (acquire_timer1(TIMER_16BIT|TIMER_SQWAVE)) { return EBUSY; } /* set pitch */ outb(TIMER_CNTR1, pitch); outb(TIMER_CNTR1, (pitch>>8)); #else /* set command for counter 2, 2 byte write */ if (acquire_timer2(TIMER_16BIT|TIMER_SQWAVE)) return EBUSY; /* set pitch */ outb(TIMER_CNTR2, pitch); outb(TIMER_CNTR2, (pitch>>8)); /* enable counter 2 output to speaker */ outb(IO_PPI, inb(IO_PPI) | 3); #endif } else { #ifdef PC98 /* disable counter 1 */ outb(0x35, inb(0x35) | 0x08); release_timer1(); #else /* disable counter 2 output to speaker */ outb(IO_PPI, inb(IO_PPI) & 0xFC); release_timer2(); #endif } } return 0; case KDGKBTYPE: /* get keyboard type */ *(int *)data = 0; /* type not known (yet) */ return 0; case KDSETLED: /* set keyboard LED status */ if (*(int *)data & ~LED_MASK) return EINVAL; scp->status &= ~LED_MASK; scp->status |= *(int *)data; if (scp == cur_console) update_leds(scp->status); return 0; case KDGETLED: /* get keyboard LED status */ *(int *)data = scp->status & LED_MASK; return 0; case GETFKEY: /* get functionkey string */ if (*(u_short*)data < n_fkey_tab) { fkeyarg_t *ptr = (fkeyarg_t*)data; bcopy(&fkey_tab[ptr->keynum].str, ptr->keydef, fkey_tab[ptr->keynum].len); ptr->flen = fkey_tab[ptr->keynum].len; return 0; } else return EINVAL; case SETFKEY: /* set functionkey string */ if (*(u_short*)data < n_fkey_tab) { fkeyarg_t *ptr = (fkeyarg_t*)data; bcopy(ptr->keydef, &fkey_tab[ptr->keynum].str, min(ptr->flen, MAXFK)); fkey_tab[ptr->keynum].len = min(ptr->flen, MAXFK); return 0; } else return EINVAL; case GIO_SCRNMAP: /* get output translation table */ bcopy(&scr_map, data, sizeof(scr_map)); return 0; case PIO_SCRNMAP: /* set output translation table */ bcopy(data, &scr_map, sizeof(scr_map)); for (i=0; iva_flags)) return ENXIO; bcopy(data, font_8, 8*256); fonts_loaded |= FONT_8; /* * FONT KLUDGE * Always use the font page #0. XXX * Don't load if the current font size is not 8x8. */ if (ISTEXTSC(cur_console) && (cur_console->font_size < 14)) copy_font(cur_console, LOAD, 8, font_8); return 0; case GIO_FONT8x8: /* get 8x8 dot font */ if (!ISFONTAVAIL(get_adapter(scp)->va_flags)) return ENXIO; if (fonts_loaded & FONT_8) { bcopy(font_8, data, 8*256); return 0; } else return ENXIO; case PIO_FONT8x14: /* set 8x14 dot font */ if (!ISFONTAVAIL(get_adapter(scp)->va_flags)) return ENXIO; bcopy(data, font_14, 14*256); fonts_loaded |= FONT_14; /* * FONT KLUDGE * Always use the font page #0. XXX * Don't load if the current font size is not 8x14. */ if (ISTEXTSC(cur_console) && (cur_console->font_size >= 14) && (cur_console->font_size < 16)) copy_font(cur_console, LOAD, 14, font_14); return 0; case GIO_FONT8x14: /* get 8x14 dot font */ if (!ISFONTAVAIL(get_adapter(scp)->va_flags)) return ENXIO; if (fonts_loaded & FONT_14) { bcopy(font_14, data, 14*256); return 0; } else return ENXIO; case PIO_FONT8x16: /* set 8x16 dot font */ if (!ISFONTAVAIL(get_adapter(scp)->va_flags)) return ENXIO; bcopy(data, font_16, 16*256); fonts_loaded |= FONT_16; /* * FONT KLUDGE * Always use the font page #0. XXX * Don't load if the current font size is not 8x16. */ if (ISTEXTSC(cur_console) && (cur_console->font_size >= 16)) copy_font(cur_console, LOAD, 16, font_16); return 0; case GIO_FONT8x16: /* get 8x16 dot font */ if (!ISFONTAVAIL(get_adapter(scp)->va_flags)) return ENXIO; if (fonts_loaded & FONT_16) { bcopy(font_16, data, 16*256); return 0; } else return ENXIO; #endif /* PC98 */ #ifdef PC98 case ADJUST_CLOCK: /* /dev/rtc for 98note resume */ inittodr(0); return 0; #endif default: break; } error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); if (error != ENOIOCTL) return(error); error = ttioctl(tp, cmd, data, flag); if (error != ENOIOCTL) return(error); return(ENOTTY); } static void scstart(struct tty *tp) { struct clist *rbp; int s, len; u_char buf[PCBURST]; scr_stat *scp = sc_get_scr_stat(tp->t_dev); if (scp->status & SLKED || blink_in_progress) return; /* XXX who repeats the call when the above flags are cleared? */ s = spltty(); if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) { tp->t_state |= TS_BUSY; rbp = &tp->t_outq; while (rbp->c_cc) { len = q_to_b(rbp, buf, PCBURST); splx(s); ansi_put(scp, buf, len); s = spltty(); } tp->t_state &= ~TS_BUSY; ttwwakeup(tp); } splx(s); } static void scmousestart(struct tty *tp) { struct clist *rbp; int s; u_char buf[PCBURST]; s = spltty(); if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) { tp->t_state |= TS_BUSY; rbp = &tp->t_outq; while (rbp->c_cc) { q_to_b(rbp, buf, PCBURST); } tp->t_state &= ~TS_BUSY; ttwwakeup(tp); } splx(s); } -void +static void sccnprobe(struct consdev *cp) { struct isa_device *dvp; /* * Take control if we are the highest priority enabled display device. */ dvp = find_display(); if (dvp == NULL || dvp->id_driver != &scdriver) { cp->cn_pri = CN_DEAD; return; } if (!scvidprobe(dvp->id_unit, dvp->id_flags)) { cp->cn_pri = CN_DEAD; return; } /* initialize required fields */ cp->cn_dev = makedev(CDEV_MAJOR, SC_CONSOLE); cp->cn_pri = CN_INTERNAL; sc_kbdc = kbdc_open(sc_port); } -void +static void sccninit(struct consdev *cp) { scinit(); } -void +static void sccnputc(dev_t dev, int c) { u_char buf[1]; int s; scr_stat *scp = console[0]; term_stat save = scp->term; scp->term = kernel_console; current_default = &kernel_default; if (scp == cur_console && !ISGRAPHSC(scp)) remove_cursor_image(scp); buf[0] = c; ansi_put(scp, buf, 1); kernel_console = scp->term; current_default = &user_default; scp->term = save; s = spltty(); /* block scintr and scrn_timer */ sccnupdate(scp); splx(s); } -int +static int sccngetc(dev_t dev) { int s = spltty(); /* block scintr and scrn_timer while we poll */ int c; /* * Stop the screen saver and update the screen if necessary. * What if we have been running in the screen saver code... XXX */ scsplash_stick(FALSE); run_scrn_saver = FALSE; sccnupdate(cur_console); c = scgetc(SCGETC_CN); splx(s); return(c); } -int +static int sccncheckc(dev_t dev) { int s = spltty(); /* block scintr and scrn_timer while we poll */ int c; scsplash_stick(FALSE); run_scrn_saver = FALSE; sccnupdate(cur_console); c = scgetc(SCGETC_CN | SCGETC_NONBLOCK); splx(s); return(c == NOKEY ? -1 : c); /* c == -1 can't happen */ } static void sccnupdate(scr_stat *scp) { /* this is a cut-down version of scrn_timer()... */ if (font_loading_in_progress) return; if (panicstr || shutdown_in_progress) { scsplash_stick(FALSE); run_scrn_saver = FALSE; } else if (scp != cur_console) { return; } if (!run_scrn_saver) scrn_idle = FALSE; if ((saver_mode != CONS_LKM_SAVER) || !scrn_idle) if (scp->status & SAVER_RUNNING) stop_scrn_saver(current_saver); if (scp != cur_console || blink_in_progress || switch_in_progress) return; if (!ISGRAPHSC(scp) && !(scp->status & SAVER_RUNNING)) scrn_update(scp, TRUE); } scr_stat *sc_get_scr_stat(dev_t dev) { int unit = minor(dev); if (unit == SC_CONSOLE) return console[0]; if (unit >= MAXCONS || unit < 0) return(NULL); return console[unit]; } static int get_scr_num() { int i = 0; while ((i < MAXCONS) && (cur_console != console[i])) i++; return i < MAXCONS ? i : 0; } static void scrn_timer(void *arg) { struct timeval tv; scr_stat *scp; int s; /* don't do anything when we are touching font */ if (font_loading_in_progress) { if (arg) timeout(scrn_timer, (void *)TRUE, hz / 10); return; } s = spltty(); /* * With release 2.1 of the Xaccel server, the keyboard is left * hanging pretty often. Apparently an interrupt from the * keyboard is lost, and I don't know why (yet). * This ugly hack calls scintr if input is ready for the keyboard * and conveniently hides the problem. XXX */ /* Try removing anything stuck in the keyboard controller; whether * it's a keyboard scan code or mouse data. `scintr()' doesn't * read the mouse data directly, but `kbdio' routines will, as a * side effect. */ if (kbdc_lock(sc_kbdc, TRUE)) { /* * We have seen the lock flag is not set. Let's reset the flag early; * otherwise `update_led()' failes which may want the lock * during `scintr()'. */ kbdc_lock(sc_kbdc, FALSE); if (kbdc_data_ready(sc_kbdc)) scintr(0); } scp = cur_console; /* should we stop the screen saver? */ getmicrouptime(&tv); if (panicstr || shutdown_in_progress) { scsplash_stick(FALSE); run_scrn_saver = FALSE; } if (run_scrn_saver) { scrn_idle = (tv.tv_sec > scrn_time_stamp + scrn_blank_time); } else { scrn_time_stamp = tv.tv_sec; scrn_idle = FALSE; if (scrn_blank_time > 0) run_scrn_saver = TRUE; } if ((saver_mode != CONS_LKM_SAVER) || !scrn_idle) if (scp->status & SAVER_RUNNING) stop_scrn_saver(current_saver); /* should we just return ? */ if (blink_in_progress || switch_in_progress) { if (arg) timeout(scrn_timer, (void *)TRUE, hz / 10); splx(s); return; } /* Update the screen */ if (!ISGRAPHSC(scp) && !(scp->status & SAVER_RUNNING)) scrn_update(scp, TRUE); /* should we activate the screen saver? */ if ((saver_mode == CONS_LKM_SAVER) && scrn_idle) if (!ISGRAPHSC(scp) || (scp->status & SAVER_RUNNING)) scrn_saver(current_saver, TRUE); if (arg) timeout(scrn_timer, (void *)TRUE, hz / 25); splx(s); } static void scrn_update(scr_stat *scp, int show_cursor) { /* update screen image */ if (scp->start <= scp->end) { sc_bcopy(scp, scp->scr_buf, scp->start, scp->end, 0); #ifdef PC98 generic_bcopy(scp->atr_buf + scp->start, Atrat + scp->start, (1 + scp->end - scp->start) * sizeof(u_short)); #endif } /* we are not to show the cursor and the mouse pointer... */ if (!show_cursor) { scp->end = 0; scp->start = scp->xsize*scp->ysize - 1; return; } /* update "pseudo" mouse pointer image */ if (scp->status & MOUSE_VISIBLE) { /* did mouse move since last time ? */ if (scp->status & MOUSE_MOVED) { /* do we need to remove old mouse pointer image ? */ if (scp->mouse_cut_start != NULL || (scp->mouse_pos-scp->scr_buf) <= scp->start || (scp->mouse_pos+scp->xsize + 1 - scp->scr_buf) >= scp->end) { remove_mouse_image(scp); } scp->status &= ~MOUSE_MOVED; draw_mouse_image(scp); } else { /* mouse didn't move, has it been overwritten ? */ if ((scp->mouse_pos+scp->xsize + 1 - scp->scr_buf) >= scp->start && (scp->mouse_pos - scp->scr_buf) <= scp->end) { draw_mouse_image(scp); } } } /* update cursor image */ if (scp->status & CURSOR_ENABLED) { /* did cursor move since last time ? */ if (scp->cursor_pos != scp->cursor_oldpos) { /* do we need to remove old cursor image ? */ if ((scp->cursor_oldpos - scp->scr_buf) < scp->start || ((scp->cursor_oldpos - scp->scr_buf) > scp->end)) { remove_cursor_image(scp); } scp->cursor_oldpos = scp->cursor_pos; draw_cursor_image(scp); } else { /* cursor didn't move, has it been overwritten ? */ if (scp->cursor_pos - scp->scr_buf >= scp->start && scp->cursor_pos - scp->scr_buf <= scp->end) { draw_cursor_image(scp); } else { /* if its a blinking cursor, we may have to update it */ if (sc_flags & BLINK_CURSOR) draw_cursor_image(scp); } } blinkrate++; } if (scp->mouse_cut_start != NULL) draw_cutmarking(scp); scp->end = 0; scp->start = scp->xsize*scp->ysize - 1; } int add_scrn_saver(void (*this_saver)(int)) { #ifdef SC_SPLASH_SCREEN if (current_saver == scsplash) { scsplash_stick(FALSE); stop_scrn_saver(scsplash); } #endif if (current_saver != default_saver) return EBUSY; run_scrn_saver = FALSE; saver_mode = CONS_LKM_SAVER; current_saver = this_saver; return 0; } int remove_scrn_saver(void (*this_saver)(int)) { if (current_saver != this_saver) return EINVAL; /* * In order to prevent `current_saver' from being called by * the timeout routine `scrn_timer()' while we manipulate * the saver list, we shall set `current_saver' to `none_saver' * before stopping the current saver, rather than blocking by `splXX()'. */ current_saver = none_saver; if (scrn_blanked > 0) stop_scrn_saver(this_saver); if (scrn_blanked > 0) return EBUSY; /* XXX */ current_saver = default_saver; return 0; } static void scrn_saver(void (*saver)(int), int blank) { static int busy = FALSE; if (busy) return; busy = TRUE; (*saver)(blank); busy = FALSE; } static void stop_scrn_saver(void (*saver)(int)) { scrn_saver(saver, FALSE); run_scrn_saver = FALSE; /* the screen saver may have chosen not to stop after all... */ if (scrn_blanked > 0) return; mark_all(cur_console); if (delayed_next_scr) switch_scr(cur_console, delayed_next_scr - 1); wakeup((caddr_t)&scrn_blanked); } static int wait_scrn_saver_stop(void) { int error = 0; while (scrn_blanked > 0) { run_scrn_saver = FALSE; error = tsleep((caddr_t)&scrn_blanked, PZERO | PCATCH, "scrsav", 0); run_scrn_saver = FALSE; if (error != ERESTART) break; } return error; } void sc_clear_screen(scr_stat *scp) { move_crsr(scp, 0, 0); scp->cursor_oldpos = scp->cursor_pos; #ifdef PC98 fillw(scr_map[0x20], scp->scr_buf, scp->xsize * scp->ysize); fillw(at2pc98(scp->term.cur_color), scp->atr_buf, scp->xsize * scp->ysize); #else fillw(scp->term.cur_color | scr_map[0x20], scp->scr_buf, scp->xsize * scp->ysize); #endif mark_all(scp); remove_cutmarking(scp); } static int switch_scr(scr_stat *scp, u_int next_scr) { /* delay switch if actively updating screen */ if (scrn_blanked > 0 || write_in_progress || blink_in_progress) { scsplash_stick(FALSE); run_scrn_saver = FALSE; delayed_next_scr = next_scr+1; return 0; } if (switch_in_progress && (cur_console->proc != pfind(cur_console->pid))) switch_in_progress = FALSE; if (next_scr >= MAXCONS || switch_in_progress || (cur_console->smode.mode == VT_AUTO && ISGRAPHSC(cur_console))) { do_bell(scp, BELL_PITCH, BELL_DURATION); return EINVAL; } /* is the wanted virtual console open ? */ if (next_scr) { struct tty *tp = VIRTUAL_TTY(next_scr); if (!(tp->t_state & TS_ISOPEN)) { do_bell(scp, BELL_PITCH, BELL_DURATION); return EINVAL; } } switch_in_progress = TRUE; old_scp = cur_console; new_scp = console[next_scr]; wakeup((caddr_t)&new_scp->smode); if (new_scp == old_scp) { switch_in_progress = FALSE; delayed_next_scr = FALSE; return 0; } /* has controlling process died? */ if (old_scp->proc && (old_scp->proc != pfind(old_scp->pid))) old_scp->smode.mode = VT_AUTO; if (new_scp->proc && (new_scp->proc != pfind(new_scp->pid))) new_scp->smode.mode = VT_AUTO; /* check the modes and switch appropriately */ if (old_scp->smode.mode == VT_PROCESS) { old_scp->status |= SWITCH_WAIT_REL; psignal(old_scp->proc, old_scp->smode.relsig); } else { exchange_scr(); if (new_scp->smode.mode == VT_PROCESS) { new_scp->status |= SWITCH_WAIT_ACQ; psignal(new_scp->proc, new_scp->smode.acqsig); } else switch_in_progress = FALSE; } return 0; } static void exchange_scr(void) { move_crsr(old_scp, old_scp->xpos, old_scp->ypos); cur_console = new_scp; #ifdef PC98 if (old_scp->mode != new_scp->mode || ISUNKNOWNSC(old_scp) || ISUNKNOWNSC(new_scp)) #else if (old_scp->mode != new_scp->mode || ISUNKNOWNSC(old_scp)) #endif set_mode(new_scp); move_crsr(new_scp, new_scp->xpos, new_scp->ypos); #ifndef PC98 if (ISTEXTSC(new_scp) && (sc_flags & CHAR_CURSOR)) set_destructive_cursor(new_scp); if (ISGRAPHSC(old_scp)) load_palette(new_scp, palette); #endif if (old_scp->status & KBD_RAW_MODE || new_scp->status & KBD_RAW_MODE || old_scp->status & KBD_CODE_MODE || new_scp->status & KBD_CODE_MODE) shfts = ctls = alts = agrs = metas = accents = 0; set_border(new_scp, new_scp->border); update_leds(new_scp->status); delayed_next_scr = FALSE; mark_all(new_scp); #ifdef PC98 if (new_scp->mode == 0x102) { bzero(Crtat, 800*600/8); } #endif } static void scan_esc(scr_stat *scp, u_char c) { static u_char ansi_col[16] = {0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15}; int i, n; u_short *src, *dst, count; #ifdef PC98 u_short *src_attr, *dst_attr; #endif if (scp->term.esc == 1) { /* seen ESC */ #ifdef KANJI switch (scp->kanji_type) { case KTYPE_KANIN: /* Kanji Invoke sequence */ switch (c) { case 'B': case '@': scp->kanji_type = KTYPE_7JIS; scp->term.esc = 0; scp->kanji_1st_char = 0; return; default: scp->kanji_type = KTYPE_ASCII; scp->term.esc = 0; break; } break; case KTYPE_ASCIN: /* Ascii Invoke sequence */ switch (c) { case 'J': case 'B': case 'H': scp->kanji_type = KTYPE_ASCII; scp->term.esc = 0; scp->kanji_1st_char = 0; return; case 'I': scp->kanji_type = KTYPE_JKANA; scp->term.esc = 0; scp->kanji_1st_char = 0; return; default: scp->kanji_type = KTYPE_ASCII; scp->term.esc = 0; break; } break; default: break; } #endif switch (c) { case '7': /* Save cursor position */ scp->saved_xpos = scp->xpos; scp->saved_ypos = scp->ypos; break; case '8': /* Restore saved cursor position */ if (scp->saved_xpos >= 0 && scp->saved_ypos >= 0) move_crsr(scp, scp->saved_xpos, scp->saved_ypos); break; case '[': /* Start ESC [ sequence */ scp->term.esc = 2; scp->term.last_param = -1; for (i = scp->term.num_param; i < MAX_ESC_PAR; i++) scp->term.param[i] = 1; scp->term.num_param = 0; return; #ifdef KANJI case '$': /* Kanji Invoke sequence */ scp->kanji_type = KTYPE_KANIN; return; #endif case 'M': /* Move cursor up 1 line, scroll if at top */ if (scp->ypos > 0) move_crsr(scp, scp->xpos, scp->ypos - 1); else { #ifdef PC98 bcopy(scp->scr_buf, scp->scr_buf + scp->xsize, (scp->ysize - 1) * scp->xsize * sizeof(u_short)); bcopy(scp->atr_buf, scp->atr_buf + scp->xsize, (scp->ysize - 1) * scp->xsize * sizeof(u_short)); fillw(scr_map[0x20], scp->scr_buf, scp->xsize); fillw(at2pc98(scp->term.cur_color), scp->atr_buf, scp->xsize); #else bcopy(scp->scr_buf, scp->scr_buf + scp->xsize, (scp->ysize - 1) * scp->xsize * sizeof(u_short)); fillw(scp->term.cur_color | scr_map[0x20], scp->scr_buf, scp->xsize); #endif mark_all(scp); } break; #if notyet case 'Q': scp->term.esc = 4; return; #endif case 'c': /* Clear screen & home */ sc_clear_screen(scp); break; case '(': /* iso-2022: designate 94 character set to G0 */ #ifdef KANJI scp->kanji_type = KTYPE_ASCIN; #else scp->term.esc = 5; #endif return; } } else if (scp->term.esc == 2) { /* seen ESC [ */ if (c >= '0' && c <= '9') { if (scp->term.num_param < MAX_ESC_PAR) { if (scp->term.last_param != scp->term.num_param) { scp->term.last_param = scp->term.num_param; scp->term.param[scp->term.num_param] = 0; } else scp->term.param[scp->term.num_param] *= 10; scp->term.param[scp->term.num_param] += c - '0'; return; } } scp->term.num_param = scp->term.last_param + 1; switch (c) { case ';': if (scp->term.num_param < MAX_ESC_PAR) return; break; case '=': scp->term.esc = 3; scp->term.last_param = -1; for (i = scp->term.num_param; i < MAX_ESC_PAR; i++) scp->term.param[i] = 1; scp->term.num_param = 0; return; case 'A': /* up n rows */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, scp->xpos, scp->ypos - n); break; case 'B': /* down n rows */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, scp->xpos, scp->ypos + n); break; case 'C': /* right n columns */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, scp->xpos + n, scp->ypos); break; case 'D': /* left n columns */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, scp->xpos - n, scp->ypos); break; case 'E': /* cursor to start of line n lines down */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, 0, scp->ypos + n); break; case 'F': /* cursor to start of line n lines up */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, 0, scp->ypos - n); break; case 'f': /* Cursor move */ case 'H': if (scp->term.num_param == 0) move_crsr(scp, 0, 0); else if (scp->term.num_param == 2) move_crsr(scp, scp->term.param[1] - 1, scp->term.param[0] - 1); break; case 'J': /* Clear all or part of display */ if (scp->term.num_param == 0) n = 0; else n = scp->term.param[0]; switch (n) { case 0: /* clear form cursor to end of display */ #ifdef PC98 fillw(scr_map[0x20], scp->cursor_pos, scp->scr_buf + scp->xsize * scp->ysize - scp->cursor_pos); fillw(at2pc98(scp->term.cur_color), scp->cursor_atr, scp->atr_buf + scp->xsize * scp->ysize - scp->cursor_atr); #else fillw(scp->term.cur_color | scr_map[0x20], scp->cursor_pos, scp->scr_buf + scp->xsize * scp->ysize - scp->cursor_pos); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif mark_for_update(scp, scp->xsize * scp->ysize - 1); remove_cutmarking(scp); break; case 1: /* clear from beginning of display to cursor */ #ifdef PC98 fillw(scr_map[0x20], scp->scr_buf, scp->cursor_pos - scp->scr_buf); fillw(at2pc98(scp->term.cur_color), scp->atr_buf, scp->cursor_atr - scp->atr_buf); #else fillw(scp->term.cur_color | scr_map[0x20], scp->scr_buf, scp->cursor_pos - scp->scr_buf); #endif mark_for_update(scp, 0); mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif remove_cutmarking(scp); break; case 2: /* clear entire display */ #ifdef PC98 fillw(scr_map[0x20], scp->scr_buf, scp->xsize * scp->ysize); fillw(at2pc98(scp->term.cur_color), scp->atr_buf, scp->xsize * scp->ysize); #else fillw(scp->term.cur_color | scr_map[0x20], scp->scr_buf, scp->xsize * scp->ysize); #endif mark_all(scp); remove_cutmarking(scp); break; } break; case 'K': /* Clear all or part of line */ if (scp->term.num_param == 0) n = 0; else n = scp->term.param[0]; switch (n) { case 0: /* clear form cursor to end of line */ #ifdef PC98 fillw(scr_map[0x20], scp->cursor_pos, scp->xsize - scp->xpos); fillw(at2pc98(scp->term.cur_color), scp->cursor_atr, scp->xsize - scp->xpos); #else fillw(scp->term.cur_color | scr_map[0x20], scp->cursor_pos, scp->xsize - scp->xpos); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf + scp->xsize - 1 - scp->xpos); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf + scp->xsize - 1 - scp->xpos); #endif break; case 1: /* clear from beginning of line to cursor */ #ifdef PC98 fillw(scr_map[0x20], scp->cursor_pos - scp->xpos, scp->xpos + 1); fillw(at2pc98(scp->term.cur_color), scp->cursor_atr - scp->xpos, scp->xpos + 1); #else fillw(scp->term.cur_color | scr_map[0x20], scp->cursor_pos - scp->xpos, scp->xpos + 1); #endif mark_for_update(scp, scp->ypos * scp->xsize); mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif break; case 2: /* clear entire line */ #ifdef PC98 fillw(scr_map[0x20], scp->cursor_pos - scp->xpos, scp->xsize); fillw(at2pc98(scp->term.cur_color), scp->cursor_atr - scp->xpos, scp->xsize); #else fillw(scp->term.cur_color | scr_map[0x20], scp->cursor_pos - scp->xpos, scp->xsize); #endif mark_for_update(scp, scp->ypos * scp->xsize); mark_for_update(scp, (scp->ypos + 1) * scp->xsize - 1); break; } break; case 'L': /* Insert n lines */ n = scp->term.param[0]; if (n < 1) n = 1; if (n > scp->ysize - scp->ypos) n = scp->ysize - scp->ypos; src = scp->scr_buf + scp->ypos * scp->xsize; dst = src + n * scp->xsize; count = scp->ysize - (scp->ypos + n); bcopy(src, dst, count * scp->xsize * sizeof(u_short)); #ifdef PC98 src_attr = scp->atr_buf + scp->ypos * scp->xsize; dst_attr = src_attr + n * scp->xsize; bcopy(src_attr, dst_attr, count * scp->xsize * sizeof(u_short)); fillw(scr_map[0x20], src, n * scp->xsize); fillw(at2pc98(scp->term.cur_color), src_attr, n * scp->xsize); #else fillw(scp->term.cur_color | scr_map[0x20], src, n * scp->xsize); #endif mark_for_update(scp, scp->ypos * scp->xsize); mark_for_update(scp, scp->xsize * scp->ysize - 1); break; case 'M': /* Delete n lines */ n = scp->term.param[0]; if (n < 1) n = 1; if (n > scp->ysize - scp->ypos) n = scp->ysize - scp->ypos; dst = scp->scr_buf + scp->ypos * scp->xsize; src = dst + n * scp->xsize; count = scp->ysize - (scp->ypos + n); bcopy(src, dst, count * scp->xsize * sizeof(u_short)); src = dst + count * scp->xsize; #ifdef PC98 dst_attr = scp->atr_buf + scp->ypos * scp->xsize; src_attr = dst_attr + n * scp->xsize; bcopy(src_attr, dst_attr, count * scp->xsize * sizeof(u_short)); src_attr = dst_attr + count * scp->xsize; fillw(scr_map[0x20], src, n * scp->xsize); fillw(at2pc98(scp->term.cur_color), src_attr, n * scp->xsize); #else fillw(scp->term.cur_color | scr_map[0x20], src, n * scp->xsize); #endif mark_for_update(scp, scp->ypos * scp->xsize); mark_for_update(scp, scp->xsize * scp->ysize - 1); break; case 'P': /* Delete n chars */ n = scp->term.param[0]; if (n < 1) n = 1; if (n > scp->xsize - scp->xpos) n = scp->xsize - scp->xpos; dst = scp->cursor_pos; src = dst + n; count = scp->xsize - (scp->xpos + n); bcopy(src, dst, count * sizeof(u_short)); src = dst + count; #ifdef PC98 dst_attr = scp->cursor_atr; src_attr = dst_attr + n; bcopy(src_attr, dst_attr, count * sizeof(u_short)); src_attr = dst_attr + count; fillw(scr_map[0x20], src, n); fillw(at2pc98(scp->term.cur_color), src_attr, n); #else fillw(scp->term.cur_color | scr_map[0x20], src, n); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf + n + count - 1); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf + n + count - 1); #endif break; case '@': /* Insert n chars */ n = scp->term.param[0]; if (n < 1) n = 1; if (n > scp->xsize - scp->xpos) n = scp->xsize - scp->xpos; src = scp->cursor_pos; dst = src + n; count = scp->xsize - (scp->xpos + n); bcopy(src, dst, count * sizeof(u_short)); #ifdef PC98 src_attr = scp->cursor_atr; dst_attr = src_attr + n; bcopy(src_attr, dst_attr, count * sizeof(u_short)); fillw(scr_map[0x20], src, n); fillw(at2pc98(scp->term.cur_color), src_attr, n); #else fillw(scp->term.cur_color | scr_map[0x20], src, n); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf + n + count - 1); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf + n + count - 1); #endif break; case 'S': /* scroll up n lines */ n = scp->term.param[0]; if (n < 1) n = 1; if (n > scp->ysize) n = scp->ysize; bcopy(scp->scr_buf + (scp->xsize * n), scp->scr_buf, scp->xsize * (scp->ysize - n) * sizeof(u_short)); #ifdef PC98 bcopy(scp->atr_buf + (scp->xsize * n), scp->atr_buf, scp->xsize * (scp->ysize - n) * sizeof(u_short)); fillw(scr_map[0x20], scp->scr_buf + scp->xsize * (scp->ysize - n), scp->xsize * n); fillw(at2pc98(scp->term.cur_color), scp->atr_buf + scp->xsize * (scp->ysize - n), scp->xsize * n); #else fillw(scp->term.cur_color | scr_map[0x20], scp->scr_buf + scp->xsize * (scp->ysize - n), scp->xsize * n); #endif mark_all(scp); break; case 'T': /* scroll down n lines */ n = scp->term.param[0]; if (n < 1) n = 1; if (n > scp->ysize) n = scp->ysize; bcopy(scp->scr_buf, scp->scr_buf + (scp->xsize * n), scp->xsize * (scp->ysize - n) * sizeof(u_short)); #ifdef PC98 bcopy(scp->atr_buf, scp->atr_buf + (scp->xsize * n), scp->xsize * (scp->ysize - n) * sizeof(u_short)); fillw(scr_map[0x20], scp->scr_buf, scp->xsize * n); fillw(at2pc98(scp->term.cur_color), scp->atr_buf, scp->xsize * n); #else fillw(scp->term.cur_color | scr_map[0x20], scp->scr_buf, scp->xsize * n); #endif mark_all(scp); break; case 'X': /* erase n characters in line */ n = scp->term.param[0]; if (n < 1) n = 1; if (n > scp->xsize - scp->xpos) n = scp->xsize - scp->xpos; #ifdef PC98 fillw(scr_map[0x20], scp->cursor_pos, n); fillw(at2pc98(scp->term.cur_color), scp->cursor_atr, n); #else fillw(scp->term.cur_color | scr_map[0x20], scp->cursor_pos, n); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf + n - 1); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf + n - 1); #endif break; case 'Z': /* move n tabs backwards */ n = scp->term.param[0]; if (n < 1) n = 1; if ((i = scp->xpos & 0xf8) == scp->xpos) i -= 8*n; else i -= 8*(n-1); if (i < 0) i = 0; move_crsr(scp, i, scp->ypos); break; case '`': /* move cursor to column n */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, n - 1, scp->ypos); break; case 'a': /* move cursor n columns to the right */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, scp->xpos + n, scp->ypos); break; case 'd': /* move cursor to row n */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, scp->xpos, n - 1); break; case 'e': /* move cursor n rows down */ n = scp->term.param[0]; if (n < 1) n = 1; move_crsr(scp, scp->xpos, scp->ypos + n); break; case 'm': /* change attribute */ if (scp->term.num_param == 0) { scp->term.attr_mask = NORMAL_ATTR; scp->term.cur_attr = scp->term.cur_color = scp->term.std_color; break; } for (i = 0; i < scp->term.num_param; i++) { switch (n = scp->term.param[i]) { case 0: /* back to normal */ scp->term.attr_mask = NORMAL_ATTR; scp->term.cur_attr = scp->term.cur_color = scp->term.std_color; break; case 1: /* bold */ scp->term.attr_mask |= BOLD_ATTR; scp->term.cur_attr = mask2attr(&scp->term); break; case 4: /* underline */ scp->term.attr_mask |= UNDERLINE_ATTR; scp->term.cur_attr = mask2attr(&scp->term); break; case 5: /* blink */ scp->term.attr_mask |= BLINK_ATTR; scp->term.cur_attr = mask2attr(&scp->term); break; case 7: /* reverse video */ scp->term.attr_mask |= REVERSE_ATTR; scp->term.cur_attr = mask2attr(&scp->term); break; case 30: case 31: /* set fg color */ case 32: case 33: case 34: case 35: case 36: case 37: scp->term.attr_mask |= FOREGROUND_CHANGED; scp->term.cur_color = (scp->term.cur_color&0xF000) | (ansi_col[(n-30)&7]<<8); scp->term.cur_attr = mask2attr(&scp->term); break; case 40: case 41: /* set bg color */ case 42: case 43: case 44: case 45: case 46: case 47: scp->term.attr_mask |= BACKGROUND_CHANGED; scp->term.cur_color = (scp->term.cur_color&0x0F00) | (ansi_col[(n-40)&7]<<12); scp->term.cur_attr = mask2attr(&scp->term); break; } } break; case 's': /* Save cursor position */ scp->saved_xpos = scp->xpos; scp->saved_ypos = scp->ypos; break; case 'u': /* Restore saved cursor position */ if (scp->saved_xpos >= 0 && scp->saved_ypos >= 0) move_crsr(scp, scp->saved_xpos, scp->saved_ypos); break; case 'x': if (scp->term.num_param == 0) n = 0; else n = scp->term.param[0]; switch (n) { case 0: /* reset attributes */ scp->term.attr_mask = NORMAL_ATTR; scp->term.cur_attr = scp->term.cur_color = scp->term.std_color = current_default->std_color; scp->term.rev_color = current_default->rev_color; break; case 1: /* set ansi background */ scp->term.attr_mask &= ~BACKGROUND_CHANGED; scp->term.cur_color = scp->term.std_color = (scp->term.std_color & 0x0F00) | (ansi_col[(scp->term.param[1])&0x0F]<<12); scp->term.cur_attr = mask2attr(&scp->term); break; case 2: /* set ansi foreground */ scp->term.attr_mask &= ~FOREGROUND_CHANGED; scp->term.cur_color = scp->term.std_color = (scp->term.std_color & 0xF000) | (ansi_col[(scp->term.param[1])&0x0F]<<8); scp->term.cur_attr = mask2attr(&scp->term); break; case 3: /* set ansi attribute directly */ scp->term.attr_mask &= ~(FOREGROUND_CHANGED|BACKGROUND_CHANGED); scp->term.cur_color = scp->term.std_color = (scp->term.param[1]&0xFF)<<8; scp->term.cur_attr = mask2attr(&scp->term); break; case 5: /* set ansi reverse video background */ scp->term.rev_color = (scp->term.rev_color & 0x0F00) | (ansi_col[(scp->term.param[1])&0x0F]<<12); scp->term.cur_attr = mask2attr(&scp->term); break; case 6: /* set ansi reverse video foreground */ scp->term.rev_color = (scp->term.rev_color & 0xF000) | (ansi_col[(scp->term.param[1])&0x0F]<<8); scp->term.cur_attr = mask2attr(&scp->term); break; case 7: /* set ansi reverse video directly */ scp->term.rev_color = (scp->term.param[1]&0xFF)<<8; scp->term.cur_attr = mask2attr(&scp->term); break; } break; case 'z': /* switch to (virtual) console n */ if (scp->term.num_param == 1) switch_scr(scp, scp->term.param[0]); break; } } else if (scp->term.esc == 3) { /* seen ESC [0-9]+ = */ if (c >= '0' && c <= '9') { if (scp->term.num_param < MAX_ESC_PAR) { if (scp->term.last_param != scp->term.num_param) { scp->term.last_param = scp->term.num_param; scp->term.param[scp->term.num_param] = 0; } else scp->term.param[scp->term.num_param] *= 10; scp->term.param[scp->term.num_param] += c - '0'; return; } } scp->term.num_param = scp->term.last_param + 1; switch (c) { case ';': if (scp->term.num_param < MAX_ESC_PAR) return; break; case 'A': /* set display border color */ if (scp->term.num_param == 1) { scp->border=scp->term.param[0] & 0xff; if (scp == cur_console) set_border(cur_console, scp->border); } break; case 'B': /* set bell pitch and duration */ if (scp->term.num_param == 2) { scp->bell_pitch = scp->term.param[0]; scp->bell_duration = scp->term.param[1]; } break; case 'C': /* set cursor type & shape */ if (scp->term.num_param == 1) { if (scp->term.param[0] & 0x01) sc_flags |= BLINK_CURSOR; else sc_flags &= ~BLINK_CURSOR; #ifdef PC98 if (scp->term.param[0] & 0x02) sc_flags |= CHAR_CURSOR; else sc_flags &= ~CHAR_CURSOR; #else /* PC98 */ if ((scp->term.param[0] & 0x02) && ISFONTAVAIL(get_adapter(scp)->va_flags)) sc_flags |= CHAR_CURSOR; else sc_flags &= ~CHAR_CURSOR; #endif /* PC98 */ } else if (scp->term.num_param == 2) { scp->cursor_start = scp->term.param[0] & 0x1F; scp->cursor_end = scp->term.param[1] & 0x1F; } /* * The cursor shape is global property; all virtual consoles * are affected. Update the cursor in the current console... */ if (!ISGRAPHSC(cur_console)) { remove_cursor_image(cur_console); if (sc_flags & CHAR_CURSOR) set_destructive_cursor(cur_console); draw_cursor_image(cur_console); } break; case 'F': /* set ansi foreground */ if (scp->term.num_param == 1) { scp->term.attr_mask &= ~FOREGROUND_CHANGED; scp->term.cur_color = scp->term.std_color = (scp->term.std_color & 0xF000) | ((scp->term.param[0] & 0x0F) << 8); scp->term.cur_attr = mask2attr(&scp->term); } break; case 'G': /* set ansi background */ if (scp->term.num_param == 1) { scp->term.attr_mask &= ~BACKGROUND_CHANGED; scp->term.cur_color = scp->term.std_color = (scp->term.std_color & 0x0F00) | ((scp->term.param[0] & 0x0F) << 12); scp->term.cur_attr = mask2attr(&scp->term); } break; case 'H': /* set ansi reverse video foreground */ if (scp->term.num_param == 1) { scp->term.rev_color = (scp->term.rev_color & 0xF000) | ((scp->term.param[0] & 0x0F) << 8); scp->term.cur_attr = mask2attr(&scp->term); } break; case 'I': /* set ansi reverse video background */ if (scp->term.num_param == 1) { scp->term.rev_color = (scp->term.rev_color & 0x0F00) | ((scp->term.param[0] & 0x0F) << 12); scp->term.cur_attr = mask2attr(&scp->term); } break; } } #if notyet else if (scp->term.esc == 4) { /* seen ESC Q */ /* to be filled */ } #endif else if (scp->term.esc == 5) { /* seen ESC ( */ switch (c) { case 'B': /* iso-2022: desginate ASCII into G0 */ break; /* other items to be filled */ default: break; } } scp->term.esc = 0; } #ifdef KANJI static u_char iskanji1(u_char mode, u_char c) { if ((mode == KTYPE_7JIS) && (c >= 0x21) && (c <= 0x7e)) { /* JIS */ default_kanji = UJIS; return KTYPE_7JIS; } if ((mode == KTYPE_JKANA) && (c >= 0x21) && (c <= 0x5f)) { /* JIS HANKAKU */ default_kanji = UJIS; return KTYPE_JKANA; } #if 1 if ((c >= 0xa1) && (c <= 0xdf) && (default_kanji == UJIS)) { /* UJIS */ return KTYPE_UJIS; } #endif if ((c >= 0x81) && (c <= 0x9f) && (c != 0x8e)) { /* SJIS */ default_kanji = SJIS; return KTYPE_SJIS; } if ((c >= 0xa1) && (c <= 0xdf) && (default_kanji == SJIS)) { /* SJIS HANKAKU */ return KTYPE_KANA; } #if 0 if ((c >= 0xa1) && (c <= 0xdf) && (default_kanji == UJIS)) { /* UJIS */ return KTYPE_UJIS; } #endif if ((c >= 0xf0) && (c <= 0xfe)) { /* UJIS */ default_kanji = UJIS; return KTYPE_UJIS; } if ((c >= 0xe0) && (c <= 0xef)) { /* SJIS or UJIS */ return KTYPE_SUJIS; } if (c == 0x8e) { /* SJIS or UJIS HANKAKU */ return KTYPE_SUKANA; } return KTYPE_ASCII; } static u_char iskanji2(u_char mode, u_char c) { switch (mode) { case KTYPE_7JIS: if ((c >= 0x21) && (c <= 0x7e)) { /* JIS */ return KTYPE_7JIS; } break; case KTYPE_SJIS: if ((c >= 0x40) && (c <= 0xfc) && (c != 0x7f)) { /* SJIS */ return KTYPE_SJIS; } break; case KTYPE_UJIS: if ((c >= 0xa1) && (c <= 0xfe)) { /* UJIS */ return KTYPE_UJIS; } break; case KTYPE_SUKANA: if ((c >= 0xa1) && (c <= 0xdf) && (default_kanji == UJIS)) { /* UJIS HANKAKU */ return KTYPE_KANA; } if ((c >= 0x40) && (c <= 0xfc) && (c != 0x7f)) { /* SJIS */ default_kanji = SJIS; return KTYPE_SJIS; } break; case KTYPE_SUJIS: if ((c >= 0x40) && (c <= 0xa0) && (c != 0x7f)) { /* SJIS */ default_kanji = SJIS; return KTYPE_SJIS; } if ((c == 0xfd) || (c == 0xfe)) { /* UJIS */ default_kanji = UJIS; return KTYPE_UJIS; } if ((c >= 0xa1) && (c <= 0xfc)) { if (default_kanji == SJIS) return KTYPE_SJIS; if (default_kanji == UJIS) return KTYPE_UJIS; } break; } return KTYPE_ASCII; } /* * JIS X0208-83 keisen conversion table */ static u_short keiConv[32] = { 0x240c, 0x260c, 0x300c, 0x340c, 0x3c0c, 0x380c, 0x400c, 0x500c, 0x480c, 0x580c, 0x600c, 0x250c, 0x270c, 0x330c, 0x370c, 0x3f0c, 0x3b0c, 0x470c, 0x570c, 0x4f0c, 0x5f0c, 0x6f0c, 0x440c, 0x530c, 0x4c0c, 0x5b0c, 0x630c, 0x410c, 0x540c, 0x490c, 0x5c0c, 0x660c }; static u_short kanji_convert(u_char mode, u_char h, u_char l) { u_short tmp, high, low, c; high = (u_short) h; low = (u_short) l; switch (mode) { case KTYPE_SJIS: /* SHIFT JIS */ if (low >= 0xe0) { low -= 0x40; } low = (low - 0x81) * 2 + 0x21; if (high > 0x7f) { high--; } if (high > 0x9d) { low++; high -= 0x9e - 0x21; } else { high -= 0x40 - 0x21; } high &= 0x7F; low &= 0x7F; tmp = ((high << 8) | low) - 0x20; break; case KTYPE_7JIS: /* JIS */ case KTYPE_UJIS: /* UJIS */ high &= 0x7F; low &= 0x7F; tmp = ((high << 8) | low) - 0x20; break; default: tmp = 0; break; } /* keisen */ c = ((tmp & 0xff) << 8) | (tmp >> 8); /* 0x2821 .. 0x2840 */ if (0x0821 <= c && c <= 0x0840) tmp = keiConv[c - 0x0821]; return (tmp); } #endif static void ansi_put(scr_stat *scp, u_char *buf, int len) { u_char *ptr = buf; #ifdef KANJI u_short i, kanji_code; #endif /* make screensaver happy */ if (!sticky_splash && scp == cur_console) run_scrn_saver = FALSE; write_in_progress++; outloop: if (scp->term.esc) { scan_esc(scp, *ptr++); len--; } else if (PRINTABLE(*ptr)) { /* Print only printables */ #ifndef PC98 int cnt = len <= (scp->xsize-scp->xpos) ? len : (scp->xsize-scp->xpos); #endif u_short cur_attr = scp->term.cur_attr; u_short *cursor_pos = scp->cursor_pos; #ifdef PC98 u_char c = *ptr; u_short *cursor_atr = scp->cursor_atr; #ifdef KANJI if (scp->kanji_1st_char == 0) { scp->kanji_type = iskanji1(scp->kanji_type, c); if (!IS_KTYPE_ASCII_or_HANKAKU(scp->kanji_type)) { /* not Ascii & not HANKAKU */ scp->kanji_1st_char = c; ptr++; len--; goto kanji_end; } else { scp->kanji_1st_char = 0; } } else { if ((scp->kanji_type = iskanji2(scp->kanji_type, c)) & 0xee) { /* print kanji on TEXT VRAM */ kanji_code = kanji_convert(scp->kanji_type, c, scp->kanji_1st_char); for (i=0; i<2; i++){ /* *cursor_pos = (kanji_code | (i*0x80)); */ *cursor_pos = kanji_code | ((i==0) ? 0x00 : 0x80); *cursor_atr = (at2pc98(cur_attr)); cursor_pos++; cursor_atr++; if (++scp->xpos >= scp->xsize) { scp->xpos = 0; scp->ypos++; } } KTYPE_MASK_CTRL(scp->kanji_type); scp->kanji_1st_char = 0; ptr++; len--; goto kanji_end; } else { scp->kanji_1st_char = 0; } } if (IS_KTYPE_KANA(scp->kanji_type)) c |= 0x80; KTYPE_MASK_CTRL(scp->kanji_type); #endif /* KANJI */ *cursor_pos++ = (scr_map[c]); *cursor_atr++ = at2pc98(cur_attr); ptr++; #else do { /* * gcc-2.6.3 generates poor (un)sign extension code. Casting the * pointers in the following to volatile should have no effect, * but in fact speeds up this inner loop from 26 to 18 cycles * (+ cache misses) on i486's. */ #define UCVP(ucp) ((u_char volatile *)(ucp)) *cursor_pos++ = UCVP(scr_map)[*UCVP(ptr)] | cur_attr; ptr++; cnt--; } while (cnt && PRINTABLE(*ptr)); #endif /* PC98 */ len -= (cursor_pos - scp->cursor_pos); scp->xpos += (cursor_pos - scp->cursor_pos); #ifdef KANJI kanji_end: #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif mark_for_update(scp, cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, cursor_atr - scp->atr_buf); #endif scp->cursor_pos = cursor_pos; #ifdef PC98 scp->cursor_atr = cursor_atr; #endif if (scp->xpos >= scp->xsize) { scp->xpos = 0; scp->ypos++; } } else { switch(*ptr) { case 0x07: do_bell(scp, scp->bell_pitch, scp->bell_duration); break; case 0x08: /* non-destructive backspace */ if (scp->cursor_pos > scp->scr_buf) { mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif scp->cursor_pos--; #ifdef PC98 scp->cursor_atr--; #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif if (scp->xpos > 0) scp->xpos--; else { scp->xpos += scp->xsize - 1; scp->ypos--; } } break; case 0x09: /* non-destructive tab */ mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif scp->cursor_pos += (8 - scp->xpos % 8u); #ifdef PC98 scp->cursor_atr += (8 - scp->xpos % 8u); #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif if ((scp->xpos += (8 - scp->xpos % 8u)) >= scp->xsize) { scp->xpos = 0; scp->ypos++; } break; case 0x0a: /* newline, same pos */ mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif scp->cursor_pos += scp->xsize; #ifdef PC98 scp->cursor_atr += scp->xsize; #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif scp->ypos++; break; case 0x0c: /* form feed, clears screen */ sc_clear_screen(scp); break; case 0x0d: /* return, return to pos 0 */ mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif scp->cursor_pos -= scp->xpos; #ifdef PC98 scp->cursor_atr -= scp->xpos; #endif mark_for_update(scp, scp->cursor_pos - scp->scr_buf); #ifdef PC98 mark_for_update(scp, scp->cursor_atr - scp->atr_buf); #endif scp->xpos = 0; break; #ifdef PC98 case 0x0e: /* ^N */ scp->kanji_type = KTYPE_JKANA; scp->term.esc = 0; scp->kanji_1st_char = 0; break; case 0x0f: /* ^O */ scp->kanji_type = KTYPE_ASCII; scp->term.esc = 0; scp->kanji_1st_char = 0; break; #endif case 0x1b: /* start escape sequence */ scp->term.esc = 1; scp->term.num_param = 0; break; } ptr++; len--; } /* do we have to scroll ?? */ if (scp->cursor_pos >= scp->scr_buf + scp->ysize * scp->xsize) { remove_cutmarking(scp); if (scp->history != NULL) { bcopy(scp->scr_buf, scp->history_head, scp->xsize * sizeof(u_short)); scp->history_head += scp->xsize; #ifdef PC98 bcopy(scp->atr_buf, scp->his_atr_head, scp->xsize * sizeof(u_short)); scp->his_atr_head += scp->xsize; #endif if (scp->history_head + scp->xsize > scp->history + scp->history_size) #ifdef PC98 { #endif scp->history_head = scp->history; #ifdef PC98 scp->his_atr_head = scp->his_atr; } #endif } bcopy(scp->scr_buf + scp->xsize, scp->scr_buf, scp->xsize * (scp->ysize - 1) * sizeof(u_short)); #ifdef PC98 bcopy(scp->atr_buf + scp->xsize, scp->atr_buf, scp->xsize * (scp->ysize - 1) * sizeof(u_short)); fillw(scr_map[0x20], scp->scr_buf + scp->xsize * (scp->ysize - 1), scp->xsize); fillw(at2pc98(scp->term.cur_color), scp->atr_buf + scp->xsize * (scp->ysize - 1), scp->xsize); #else fillw(scp->term.cur_color | scr_map[0x20], scp->scr_buf + scp->xsize * (scp->ysize - 1), scp->xsize); #endif scp->cursor_pos -= scp->xsize; #ifdef PC98 scp->cursor_atr -= scp->xsize; #endif scp->ypos--; mark_all(scp); } if (len) goto outloop; write_in_progress--; if (delayed_next_scr) switch_scr(scp, delayed_next_scr - 1); } static void scinit(void) { #ifdef PC98 u_int hw_cursor; #else int col; int row; #endif u_int i; if (init_done != COLD) return; init_done = WARM; #ifdef PC98 if (pc98_machine_type & M_8M) { BELL_PITCH = 1339; } else { BELL_PITCH = 1678; } outb(0x62, 0xd); outb(0xA2, 0xd); /* Extract cursor location */ while((inb(TEXT_GDC + 0) & 0x04) == 0) {} /* GDC wait */ outb(TEXT_GDC + 2, 0xe0); /* CSRR */ while((inb(TEXT_GDC + 0) & 0x1) == 0) {} /* GDC wait */ hw_cursor = inb(TEXT_GDC + 2); /* EADl */ hw_cursor |= (inb(TEXT_GDC + 2) << 8); /* EADh */ inb(TEXT_GDC + 2); /* dummy */ inb(TEXT_GDC + 2); /* dummy */ inb(TEXT_GDC + 2); /* dummy */ if (hw_cursor >= ROW*COL) { hw_cursor = 0; } crtc_vga = TRUE; #else /* IBM-PC */ /* extract the hardware cursor location and move it out of the way */ (*biosvidsw.read_hw_cursor)(V_ADP_PRIMARY, &col, &row); (*biosvidsw.set_hw_cursor)(V_ADP_PRIMARY, -1, -1); #endif /* PC98 */ /* set up the first console */ current_default = &user_default; console[0] = &main_console; init_scp(console[0]); cur_console = console[0]; /* copy screen to temporary buffer */ if (ISTEXTSC(console[0])) #ifdef PC98 generic_bcopy(Crtat, sc_buffer, console[0]->xsize * console[0]->ysize * sizeof(u_short)); #else /* PC98 */ generic_bcopy((ushort *)(get_adapter(console[0])->va_window), sc_buffer, console[0]->xsize * console[0]->ysize * sizeof(u_short)); #endif /* PC98 */ console[0]->scr_buf = console[0]->mouse_pos = console[0]->mouse_oldpos = sc_buffer; #ifdef PC98 console[0]->cursor_pos = console[0]->cursor_oldpos = sc_buffer + hw_cursor; console[0]->atr_buf = Atrat; console[0]->cursor_atr = Atrat + hw_cursor; console[0]->xpos = hw_cursor % COL; console[0]->ypos = hw_cursor / COL; #else if (col >= console[0]->xsize) col = 0; if (row >= console[0]->ysize) row = console[0]->ysize - 1; console[0]->xpos = col; console[0]->ypos = row; console[0]->cursor_pos = console[0]->cursor_oldpos = sc_buffer + row*console[0]->xsize + col; console[0]->cursor_saveunder = *console[0]->cursor_pos; #endif for (i=1; iva_flags)) { if (fonts_loaded & FONT_16) { copy_font(cur_console, LOAD, 16, font_16); } else { copy_font(cur_console, SAVE, 16, font_16); fonts_loaded = FONT_16; set_destructive_cursor(cur_console); } /* * FONT KLUDGE * Always use the font page #0. XXX */ (*biosvidsw.show_font)(cur_console->adp, 0); } save_palette(cur_console, palette); #ifdef SC_SPLASH_SCREEN /* put up the splash. */ scsplash_init(cur_console); #endif #endif } static void scshutdown(int howto, void *arg) { scsplash_stick(FALSE); run_scrn_saver = FALSE; if (!cold && cur_console->smode.mode == VT_AUTO && console[0]->smode.mode == VT_AUTO) switch_scr(cur_console, 0); shutdown_in_progress = TRUE; } int sc_clean_up(scr_stat *scp) { int error; if ((error = wait_scrn_saver_stop())) return error; scp->status &= ~MOUSE_VISIBLE; remove_cutmarking(scp); return 0; } void sc_alloc_scr_buffer(scr_stat *scp, int wait, int clear) { if (scp->scr_buf) free(scp->scr_buf, M_DEVBUF); scp->scr_buf = (u_short *)malloc(scp->xsize*scp->ysize*sizeof(u_short), M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT); #ifdef PC98 if (scp->atr_buf) free(scp->atr_buf, M_DEVBUF); scp->atr_buf = (u_short *)malloc(scp->xsize*scp->ysize*sizeof(u_short), M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT); #endif if (clear) { /* clear the screen and move the text cursor to the top-left position */ sc_clear_screen(scp); } else { /* retain the current cursor position, but adjust pointers */ move_crsr(scp, scp->xpos, scp->ypos); scp->cursor_oldpos = scp->cursor_pos; } /* move the mouse cursor at the center of the screen */ sc_move_mouse(scp, scp->xpixel / 2, scp->ypixel / 2); } void sc_alloc_cut_buffer(scr_stat *scp, int wait) { if ((cut_buffer == NULL) || (cut_buffer_size < scp->xsize * scp->ysize + 1)) { if (cut_buffer != NULL) free(cut_buffer, M_DEVBUF); cut_buffer_size = scp->xsize * scp->ysize + 1; cut_buffer = (u_char *)malloc(cut_buffer_size, M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT); if (cut_buffer != NULL) cut_buffer[0] = '\0'; } } void sc_alloc_history_buffer(scr_stat *scp, int lines, int extra, int wait) { u_short *usp; #ifdef PC98 u_short *atr_usp; #endif if (lines < scp->ysize) lines = scp->ysize; usp = scp->history; scp->history = NULL; if (usp != NULL) { free(usp, M_DEVBUF); if (extra > 0) extra_history_size += extra; } #ifdef PC98 atr_usp = scp->his_atr; scp->his_atr = NULL; if (atr_usp != NULL) free(atr_usp, M_DEVBUF); #endif scp->history_size = lines * scp->xsize; if (lines > imax(sc_history_size, scp->ysize)) extra_history_size -= lines - imax(sc_history_size, scp->ysize); usp = (u_short *)malloc(scp->history_size * sizeof(u_short), M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT); if (usp != NULL) bzero(usp, scp->history_size * sizeof(u_short)); scp->history_head = scp->history_pos = usp; scp->history = usp; #ifdef PC98 atr_usp = (u_short *)malloc(scp->history_size * sizeof(u_short), M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT); if (atr_usp != NULL) bzero(atr_usp, scp->history_size * sizeof(u_short)); scp->his_atr_head = scp->his_atr_pos = atr_usp; scp->his_atr = atr_usp; #endif } static scr_stat *alloc_scp() { scr_stat *scp; scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK); init_scp(scp); sc_alloc_scr_buffer(scp, TRUE, TRUE); #ifdef PC98 sc_alloc_cut_buffer(scp, TRUE); #else /* PC98 */ if (ISMOUSEAVAIL(get_adapter(scp)->va_flags)) sc_alloc_cut_buffer(scp, TRUE); #endif /* PC98 */ sc_alloc_history_buffer(scp, sc_history_size, 0, TRUE); /* SOS #ifndef PC98 if (get_adapter(scp)->va_flags & V_ADP_MODECHANGE) #endif set_mode(scp); */ sc_clear_screen(scp); #ifndef PC98 scp->cursor_saveunder = *scp->cursor_pos; #endif return scp; } static void init_scp(scr_stat *scp) { #ifndef PC98 video_info_t info; #endif #ifdef PC98 scp->mode = M_PC98_80x25; scp->scr_buf = NULL; scp->atr_buf = NULL; scp->font_size = 16; scp->xsize = COL; scp->ysize = ROW; scp->xpixel = scp->xsize * 8; scp->ypixel = scp->ysize * scp->font_size; #else scp->adp = V_ADP_PRIMARY; (*biosvidsw.get_info)(scp->adp, initial_video_mode, &info); scp->status = 0; scp->mode = scp->initial_mode = initial_video_mode; scp->scr_buf = NULL; if (info.vi_flags & V_INFO_GRAPHICS) { scp->status |= GRAPHICS_MODE; scp->xpixel = info.vi_width; scp->ypixel = info.vi_height; scp->xsize = info.vi_width/8; scp->ysize = info.vi_height/info.vi_cheight; scp->font_size = FONT_NONE; } else { scp->xsize = info.vi_width; scp->ysize = info.vi_height; scp->xpixel = scp->xsize*8; scp->ypixel = scp->ysize*info.vi_cheight; scp->font_size = info.vi_cheight; } scp->xoff = scp->yoff = 0; #endif scp->xpos = scp->ypos = 0; scp->saved_xpos = scp->saved_ypos = -1; scp->start = scp->xsize * scp->ysize; scp->end = 0; scp->term.esc = 0; scp->term.attr_mask = NORMAL_ATTR; scp->term.cur_attr = scp->term.cur_color = scp->term.std_color = current_default->std_color; scp->term.rev_color = current_default->rev_color; scp->border = BG_BLACK; #ifdef PC98 scp->cursor_start = 0; scp->cursor_end = 0; #else scp->cursor_start = *(u_int8_t *)pa_to_va(0x461); scp->cursor_end = *(u_int8_t *)pa_to_va(0x460); #endif scp->mouse_xpos = scp->xsize*8/2; scp->mouse_ypos = scp->ysize*scp->font_size/2; scp->mouse_cut_start = scp->mouse_cut_end = NULL; scp->mouse_signal = 0; scp->mouse_pid = 0; scp->mouse_proc = NULL; scp->bell_pitch = BELL_PITCH; scp->bell_duration = BELL_DURATION; #ifdef PC98 scp->status = 0; scp->status |= CURSOR_ENABLED; #else scp->status |= (*(u_int8_t *)pa_to_va(0x417) & 0x20) ? NLKED : 0; scp->status |= CURSOR_ENABLED; #endif scp->pid = 0; scp->proc = NULL; scp->smode.mode = VT_AUTO; scp->history_head = scp->history_pos = scp->history = NULL; #ifdef PC98 scp->his_atr_head = scp->his_atr_pos = scp->his_atr = NULL; #endif scp->history_size = imax(sc_history_size, scp->ysize) * scp->xsize; #ifdef KANJI scp->kanji_1st_char = 0; scp->kanji_type = KTYPE_ASCII; #endif } static u_char *get_fstr(u_int c, u_int *len) { u_int i; if (!(c & FKEY)) return(NULL); i = (c & 0xFF) - F_FN; if (i > n_fkey_tab) return(NULL); *len = fkey_tab[i].len; return(fkey_tab[i].str); } static void history_to_screen(scr_stat *scp) { int i; for (i=0; iysize; i++) #ifdef PC98 { #endif bcopy(scp->history + (((scp->history_pos - scp->history) + scp->history_size-((i+1)*scp->xsize))%scp->history_size), scp->scr_buf + (scp->xsize * (scp->ysize-1 - i)), scp->xsize * sizeof(u_short)); #ifdef PC98 bcopy(scp->his_atr + (((scp->his_atr_pos - scp->his_atr) + scp->history_size-((i+1)*scp->xsize))%scp->history_size), scp->atr_buf + (scp->xsize * (scp->ysize-1 - i)), scp->xsize * sizeof(u_short)); } #endif mark_all(scp); } static int history_up_line(scr_stat *scp) { if (WRAPHIST(scp, scp->history_pos, -(scp->xsize*scp->ysize)) != scp->history_head) { scp->history_pos = WRAPHIST(scp, scp->history_pos, -scp->xsize); #ifdef PC98 scp->his_atr_pos = WRAPHIST_A(scp, scp->his_atr_pos, -scp->xsize); #endif history_to_screen(scp); return 0; } else return -1; } static int history_down_line(scr_stat *scp) { if (scp->history_pos != scp->history_head) { scp->history_pos = WRAPHIST(scp, scp->history_pos, scp->xsize); #ifdef PC98 scp->his_atr_pos = WRAPHIST_A(scp, scp->his_atr_pos, scp->xsize); #endif history_to_screen(scp); return 0; } else return -1; } /* * scgetc(flags) - get character from keyboard. * If flags & SCGETC_CN, then avoid harmful side effects. * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else * return NOKEY if there is nothing there. */ static u_int scgetc(u_int flags) { struct key_t *key; u_char scancode, keycode; u_int state, action; int c; static u_char esc_flag = 0, compose = 0; static u_int chr = 0; next_code: /* first see if there is something in the keyboard port */ if (flags & SCGETC_NONBLOCK) { c = read_kbd_data_no_wait(sc_kbdc); if (c == -1) return(NOKEY); } else { do { c = read_kbd_data(sc_kbdc); } while(c == -1); } scancode = (u_char)c; /* make screensaver happy */ if (!(scancode & 0x80)) { scsplash_stick(FALSE); run_scrn_saver = FALSE; } if (!(flags & SCGETC_CN)) { /* do the /dev/random device a favour */ add_keyboard_randomness(scancode); if (cur_console->status & KBD_RAW_MODE) return scancode; } keycode = scancode & 0x7F; switch (esc_flag) { case 0x00: /* normal scancode */ switch(scancode) { case 0xB8: /* left alt (compose key) */ if (compose) { compose = 0; if (chr > 255) { do_bell(cur_console, BELL_PITCH, BELL_DURATION); chr = 0; } } break; case 0x38: if (!compose) { compose = 1; chr = 0; } break; case 0xE0: case 0xE1: esc_flag = scancode; goto next_code; } break; case 0xE0: /* 0xE0 prefix */ esc_flag = 0; switch (keycode) { case 0x1C: /* right enter key */ keycode = 0x59; break; case 0x1D: /* right ctrl key */ keycode = 0x5A; break; case 0x35: /* keypad divide key */ keycode = 0x5B; break; case 0x37: /* print scrn key */ keycode = 0x5C; break; case 0x38: /* right alt key (alt gr) */ keycode = 0x5D; break; case 0x47: /* grey home key */ keycode = 0x5E; break; case 0x48: /* grey up arrow key */ keycode = 0x5F; break; case 0x49: /* grey page up key */ keycode = 0x60; break; case 0x4B: /* grey left arrow key */ keycode = 0x61; break; case 0x4D: /* grey right arrow key */ keycode = 0x62; break; case 0x4F: /* grey end key */ keycode = 0x63; break; case 0x50: /* grey down arrow key */ keycode = 0x64; break; case 0x51: /* grey page down key */ keycode = 0x65; break; case 0x52: /* grey insert key */ keycode = 0x66; break; case 0x53: /* grey delete key */ keycode = 0x67; break; /* the following 3 are only used on the MS "Natural" keyboard */ case 0x5b: /* left Window key */ keycode = 0x69; break; case 0x5c: /* right Window key */ keycode = 0x6a; break; case 0x5d: /* menu key */ keycode = 0x6b; break; default: /* ignore everything else */ goto next_code; } break; case 0xE1: /* 0xE1 prefix */ esc_flag = 0; if (keycode == 0x1D) esc_flag = 0x1D; goto next_code; /* NOT REACHED */ case 0x1D: /* pause / break */ esc_flag = 0; if (keycode != 0x45) goto next_code; keycode = 0x68; break; } if (!(flags & SCGETC_CN) && (cur_console->status & KBD_CODE_MODE)) return (keycode | (scancode & 0x80)); /* if scroll-lock pressed allow history browsing */ if (cur_console->history && cur_console->status & SLKED) { int i; cur_console->status &= ~CURSOR_ENABLED; if (!(cur_console->status & BUFFER_SAVED)) { cur_console->status |= BUFFER_SAVED; cur_console->history_save = cur_console->history_head; #ifdef PC98 cur_console->his_atr_save = cur_console->his_atr_head; #endif /* copy screen into top of history buffer */ for (i=0; iysize; i++) { bcopy(cur_console->scr_buf + (cur_console->xsize * i), cur_console->history_head, cur_console->xsize * sizeof(u_short)); cur_console->history_head += cur_console->xsize; #ifdef PC98 bcopy(cur_console->atr_buf + (cur_console->xsize * i), cur_console->his_atr_head, cur_console->xsize * sizeof(u_short)); cur_console->his_atr_head += cur_console->xsize; #endif if (cur_console->history_head + cur_console->xsize > cur_console->history + cur_console->history_size) #ifdef PC98 { #endif cur_console->history_head=cur_console->history; #ifdef PC98 cur_console->his_atr_head=cur_console->his_atr; } #endif } cur_console->history_pos = cur_console->history_head; #ifdef PC98 cur_console->his_atr_pos = cur_console->his_atr_head; #endif history_to_screen(cur_console); } switch (scancode) { #ifdef PC98 case 0x3E: /* home key */ #else case 0x47: /* home key */ #endif cur_console->history_pos = cur_console->history_head; #ifdef PC98 cur_console->his_atr_pos = cur_console->his_atr_head; #endif history_to_screen(cur_console); goto next_code; #ifdef PC98 case 0x3F: /* help key */ #else case 0x4F: /* end key */ #endif cur_console->history_pos = WRAPHIST(cur_console, cur_console->history_head, cur_console->xsize*cur_console->ysize); #ifdef PC98 cur_console->his_atr_pos = WRAPHIST_A(cur_console, cur_console->his_atr_head, cur_console->xsize*cur_console->ysize); #endif history_to_screen(cur_console); goto next_code; #ifdef PC98 case 0x3A: /* up arrow key */ #else case 0x48: /* up arrow key */ #endif if (history_up_line(cur_console)) do_bell(cur_console, BELL_PITCH, BELL_DURATION); goto next_code; #ifdef PC98 case 0x3D: /* down arrow key */ #else case 0x50: /* down arrow key */ #endif if (history_down_line(cur_console)) do_bell(cur_console, BELL_PITCH, BELL_DURATION); goto next_code; #ifdef PC98 case 0x36: /* roll up key */ #else case 0x49: /* page up key */ #endif for (i=0; iysize; i++) if (history_up_line(cur_console)) { do_bell(cur_console, BELL_PITCH, BELL_DURATION); break; } goto next_code; #ifdef PC98 case 0x37: /* roll down key */ #else case 0x51: /* page down key */ #endif for (i=0; iysize; i++) if (history_down_line(cur_console)) { do_bell(cur_console, BELL_PITCH, BELL_DURATION); break; } goto next_code; } } if (compose) { switch (scancode) { /* key pressed process it */ case 0x47: case 0x48: case 0x49: /* keypad 7,8,9 */ chr = (scancode - 0x40) + chr*10; goto next_code; case 0x4B: case 0x4C: case 0x4D: /* keypad 4,5,6 */ chr = (scancode - 0x47) + chr*10; goto next_code; case 0x4F: case 0x50: case 0x51: /* keypad 1,2,3 */ chr = (scancode - 0x4E) + chr*10; goto next_code; case 0x52: /* keypad 0 */ chr *= 10; goto next_code; /* key release, no interest here */ case 0xC7: case 0xC8: case 0xC9: /* keypad 7,8,9 */ case 0xCB: case 0xCC: case 0xCD: /* keypad 4,5,6 */ case 0xCF: case 0xD0: case 0xD1: /* keypad 1,2,3 */ case 0xD2: /* keypad 0 */ goto next_code; case 0x38: /* left alt key */ break; default: if (chr) { compose = chr = 0; do_bell(cur_console, BELL_PITCH, BELL_DURATION); goto next_code; } break; } } state = (shfts ? 1 : 0 ) | (2 * (ctls ? 1 : 0)) | (4 * (alts ? 1 : 0)); if ((!agrs && (cur_console->status & ALKED)) || (agrs && !(cur_console->status & ALKED))) keycode += ALTGR_OFFSET; key = &key_map.key[keycode]; if ( ((key->flgs & FLAG_LOCK_C) && (cur_console->status & CLKED)) || ((key->flgs & FLAG_LOCK_N) && (cur_console->status & NLKED)) ) state ^= 1; /* Check for make/break */ action = key->map[state]; if (scancode & 0x80) { /* key released */ if (key->spcl & (0x80>>state)) { switch (action) { case LSH: shfts &= ~1; break; case RSH: shfts &= ~2; break; case LCTR: ctls &= ~1; break; case RCTR: ctls &= ~2; break; case LALT: alts &= ~1; break; case RALT: alts &= ~2; break; case NLK: nlkcnt = 0; break; case CLK: #ifdef PC98 cur_console->status &= ~CLKED; update_leds(cur_console->status); #else clkcnt = 0; #endif break; case SLK: slkcnt = 0; break; case ASH: agrs = 0; break; case ALK: alkcnt = 0; break; case META: metas = 0; break; } } if (chr && !compose) { action = chr; chr = 0; return(action); } } else { /* key pressed */ if (key->spcl & (0x80>>state)) { switch (action) { /* LOCKING KEYS */ case NLK: if (!nlkcnt) { nlkcnt++; if (cur_console->status & NLKED) cur_console->status &= ~NLKED; else cur_console->status |= NLKED; update_leds(cur_console->status); } break; case CLK: #ifdef PC98 cur_console->status |= CLKED; update_leds(cur_console->status); #else if (!clkcnt) { clkcnt++; if (cur_console->status & CLKED) cur_console->status &= ~CLKED; else cur_console->status |= CLKED; update_leds(cur_console->status); } #endif break; case SLK: if (!slkcnt) { slkcnt++; if (cur_console->status & SLKED) { cur_console->status &= ~SLKED; if (cur_console->status & BUFFER_SAVED){ int i; u_short *ptr = cur_console->history_save; #ifdef PC98 u_short *ptr_a = cur_console->his_atr_save; #endif for (i=0; iysize; i++) { bcopy(ptr, cur_console->scr_buf + (cur_console->xsize*i), cur_console->xsize * sizeof(u_short)); ptr += cur_console->xsize; #ifdef PC98 bcopy(ptr_a, cur_console->atr_buf + (cur_console->xsize*i), cur_console->xsize * sizeof(u_short)); ptr_a += cur_console->xsize; #endif if (ptr + cur_console->xsize > cur_console->history + cur_console->history_size) #ifdef PC98 { #endif ptr = cur_console->history; #ifdef PC98 ptr_a = cur_console->his_atr; } #endif } cur_console->status &= ~BUFFER_SAVED; cur_console->history_head=cur_console->history_save; #ifdef PC98 cur_console->his_atr_head=cur_console->his_atr_save; #endif cur_console->status |= CURSOR_ENABLED; mark_all(cur_console); } scstart(VIRTUAL_TTY(get_scr_num())); } else cur_console->status |= SLKED; update_leds(cur_console->status); } break; case ALK: if (!alkcnt) { alkcnt++; if (cur_console->status & ALKED) cur_console->status &= ~ALKED; else cur_console->status |= ALKED; update_leds(cur_console->status); } break; /* NON-LOCKING KEYS */ case NOP: break; case SPSC: /* force activatation/deactivation of the screen saver */ accents = 0; if (scrn_blanked <= 0) { run_scrn_saver = TRUE; scrn_time_stamp -= scrn_blank_time; } #ifdef SC_SPLASH_SCREEN if (cold) { /* * While devices are being probed, the screen saver need * to be invoked explictly. XXX */ if (scrn_blanked > 0) { scsplash_stick(FALSE); stop_scrn_saver(current_saver); } else { if (!ISGRAPHSC(cur_console)) { scsplash_stick(TRUE); scrn_saver(current_saver, TRUE); } } } #endif break; case RBT: #ifndef SC_DISABLE_REBOOT accents = 0; shutdown_nice(); #endif break; case SUSP: #if NAPM > 0 accents = 0; apm_suspend(PMST_SUSPEND); #endif break; case STBY: #if NAPM > 0 accents = 0; apm_suspend(PMST_STANDBY); #endif break; case DBG: #ifdef DDB /* try to switch to console 0 */ accents = 0; /* * TRY to make sure the screen saver is stopped, * and the screen is updated before switching to * the vty0. */ scrn_timer((void *)FALSE); if (cur_console->smode.mode == VT_AUTO && console[0]->smode.mode == VT_AUTO) switch_scr(cur_console, 0); Debugger("manual escape to debugger"); #else printf("No debugger in kernel\n"); #endif break; case LSH: shfts |= 1; break; case RSH: shfts |= 2; break; case LCTR: ctls |= 1; break; case RCTR: ctls |= 2; break; case LALT: alts |= 1; break; case RALT: alts |= 2; break; case ASH: agrs = 1; break; case META: metas = 1; break; case NEXT: { int next, this = get_scr_num(); accents = 0; for (next = this+1; next != this; next = (next+1)%MAXCONS) { struct tty *tp = VIRTUAL_TTY(next); if (tp->t_state & TS_ISOPEN) { switch_scr(cur_console, next); break; } } } break; case BTAB: accents = 0; return(BKEY); default: if (action >= F_ACC && action <= L_ACC) { /* turn it into an index */ action -= F_ACC - 1; if ((action > accent_map.n_accs) || (accent_map.acc[action - 1].accchar == 0)) { /* * The index is out of range or pointing to an * empty entry. */ accents = 0; do_bell(cur_console, BELL_PITCH, BELL_DURATION); } /* * If the same accent key has been hit twice, * produce the accent char itself. */ if (action == accents) { action = accent_map.acc[accents - 1].accchar; accents = 0; if (metas) action |= MKEY; return (action); } /* remember the index and wait for the next key stroke */ accents = action; break; } if (accents > 0) { accents = 0; do_bell(cur_console, BELL_PITCH, BELL_DURATION); } if (action >= F_SCR && action <= L_SCR) { switch_scr(cur_console, action - F_SCR); break; } if (action >= F_FN && action <= L_FN) action |= FKEY; return(action); } } else { if (accents) { struct acc_t *acc; int i; acc = &accent_map.acc[accents - 1]; accents = 0; /* * If the accent key is followed by the space key, * produce the accent char itself. */ if (action == ' ') { action = acc->accchar; if (metas) action |= MKEY; return (action); } for (i = 0; i < NUM_ACCENTCHARS; ++i) { if (acc->map[i][0] == 0) /* end of the map entry */ break; if (acc->map[i][0] == action) { action = acc->map[i][1]; if (metas) action |= MKEY; return (action); } } do_bell(cur_console, BELL_PITCH, BELL_DURATION); goto next_code; } if (metas) action |= MKEY; return(action); } } goto next_code; } int scmmap(dev_t dev, vm_offset_t offset, int nprot) { #ifdef PC98 if (offset > 0x48000 - PAGE_SIZE) #else if (offset > 0x20000 - PAGE_SIZE) #endif return -1; return i386_btop((VIDEOMEM + offset)); } /* * Calculate hardware attributes word using logical attributes mask and * hardware colors */ static int mask2attr(struct term_stat *term) { int attr, mask = term->attr_mask; if (mask & REVERSE_ATTR) { attr = ((mask & FOREGROUND_CHANGED) ? ((term->cur_color & 0xF000) >> 4) : (term->rev_color & 0x0F00)) | ((mask & BACKGROUND_CHANGED) ? ((term->cur_color & 0x0F00) << 4) : (term->rev_color & 0xF000)); } else attr = term->cur_color; /* XXX: underline mapping for Hercules adapter can be better */ if (mask & (BOLD_ATTR | UNDERLINE_ATTR)) attr ^= 0x0800; if (mask & BLINK_ATTR) attr ^= 0x8000; return attr; } #ifndef PC98 static void set_keyboard(int command, int data) { int s; if (sc_kbdc == NULL) return; /* prevent the timeout routine from polling the keyboard */ if (!kbdc_lock(sc_kbdc, TRUE)) return; /* disable the keyboard and mouse interrupt */ s = spltty(); #if 0 c = get_controller_command_byte(sc_kbdc); if ((c == -1) || !set_controller_command_byte(sc_kbdc, kbdc_get_device_mask(sc_kbdc), KBD_DISABLE_KBD_PORT | KBD_DISABLE_KBD_INT | KBD_DISABLE_AUX_PORT | KBD_DISABLE_AUX_INT)) { /* CONTROLLER ERROR */ kbdc_lock(sc_kbdc, FALSE); splx(s); return; } /* * Now that the keyboard controller is told not to generate * the keyboard and mouse interrupts, call `splx()' to allow * the other tty interrupts. The clock interrupt may also occur, * but the timeout routine (`scrn_timer()') will be blocked * by the lock flag set via `kbdc_lock()' */ splx(s); #endif if (send_kbd_command_and_data(sc_kbdc, command, data) != KBD_ACK) send_kbd_command(sc_kbdc, KBDC_ENABLE_KBD); #if 0 /* restore the interrupts */ if (!set_controller_command_byte(sc_kbdc, kbdc_get_device_mask(sc_kbdc), c & (KBD_KBD_CONTROL_BITS | KBD_AUX_CONTROL_BITS))) { /* CONTROLLER ERROR */ } #else splx(s); #endif kbdc_lock(sc_kbdc, FALSE); } #endif static void update_leds(int which) { #ifndef PC98 static u_char xlate_leds[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; /* replace CAPS led with ALTGR led for ALTGR keyboards */ if (key_map.n_keys > ALTGR_OFFSET) { if (which & ALKED) which |= CLKED; else which &= ~CLKED; } set_keyboard(KBDC_SET_LEDS, xlate_leds[which & LED_MASK]); #endif } int set_mode(scr_stat *scp) { #ifndef PC98 video_info_t info; video_adapter_t *adp; /* reject unsupported mode */ if ((*biosvidsw.get_info)(scp->adp, scp->mode, &info)) return 1; /* if this vty is not currently showing, do nothing */ if (scp != cur_console) return 0; /* setup video hardware for the given mode */ adp = get_adapter(scp); (*biosvidsw.set_mode)(scp->adp, scp->mode); Crtat = (u_short *)adp->va_window; if (!(scp->status & GRAPHICS_MODE)) { /* load appropriate font */ if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(get_adapter(scp)->va_flags)) { if (scp->font_size < 14) { if (fonts_loaded & FONT_8) copy_font(scp, LOAD, 8, font_8); } else if (scp->font_size >= 16) { if (fonts_loaded & FONT_16) copy_font(scp, LOAD, 16, font_16); } else { if (fonts_loaded & FONT_14) copy_font(scp, LOAD, 14, font_14); } /* * FONT KLUDGE: * This is an interim kludge to display correct font. * Always use the font page #0 on the video plane 2. * Somehow we cannot show the font in other font pages on * some video cards... XXX */ (*biosvidsw.show_font)(scp->adp, 0); } mark_all(scp); } if (scp->status & PIXEL_MODE) generic_bzero((u_char *)(adp->va_window), scp->xpixel*scp->ypixel/8); set_border(scp, scp->border); /* move hardware cursor out of the way */ (*biosvidsw.set_hw_cursor)(scp->adp, -1, -1); return 0; #else /* PC98 */ if (scp != cur_console) return 1; /* setup video hardware for the given mode */ #ifdef LINE30 switch (scp->mode) { case M_PC98_80x25: /* VGA TEXT MODES */ initialize_gdc(T25_G400); break; case M_PC98_80x30: initialize_gdc(T30_G400); break; default: break; } #endif if (scp->status & UNKNOWN_MODE) { while (!(inb(0x60) & 0x20)) {} /* V-SYNC wait */ outb(0x62, 0xc); /* text off */ outb(0xA2, 0xd); /* graphics on */ } else { while (!(inb(0x60) & 0x20)) {} /* V-SYNC wait */ outb(0x62, 0xd); /* text off */ outb(0xA2, 0xc); /* graphics on */ } /* set border color for this (virtual) console */ set_border(scp, scp->border); return 0; #endif /* PC98 */ } void set_border(scr_stat *scp, int color) { #ifndef PC98 u_char *p; int xoff; int yoff; int xlen; int ylen; int i; (*biosvidsw.set_border)(scp->adp, color); if (scp->status & PIXEL_MODE) { outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ outw(GDCIDX, (color << 8) | 0x00); /* set/reset */ p = (u_char *)(get_adapter(scp)->va_window); xoff = scp->xoff; yoff = scp->yoff*scp->font_size; xlen = scp->xpixel/8; ylen = scp->ysize*scp->font_size; if (yoff > 0) { generic_bzero(p, xlen*yoff); generic_bzero(p + xlen*(yoff + ylen), xlen*scp->ypixel - xlen*(yoff + ylen)); } if (xoff > 0) { for (i = 0; i < ylen; ++i) { generic_bzero(p + xlen*(yoff + i), xoff); generic_bzero(p + xlen*(yoff + i) + xoff + scp->xsize, xlen - xoff - scp->xsize); } } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ } #else /* PC98 */ switch (crtc_type) { case KD_PC98: outb(0x6c, color << 4); break; default: break; } #endif /* PC98 */ } void copy_font(scr_stat *scp, int operation, int font_size, u_char *buf) { #ifndef PC98 /* * FONT KLUDGE: * This is an interim kludge to display correct font. * Always use the font page #0 on the video plane 2. * Somehow we cannot show the font in other font pages on * some video cards... XXX */ font_loading_in_progress = TRUE; if (operation == LOAD) { (*biosvidsw.load_font)(scp->adp, 0, font_size, buf, 0, 256); if (sc_flags & CHAR_CURSOR) set_destructive_cursor(scp); } else if (operation == SAVE) { (*biosvidsw.save_font)(scp->adp, 0, font_size, buf, 0, 256); } font_loading_in_progress = FALSE; #endif } static void set_destructive_cursor(scr_stat *scp) { #ifndef PC98 u_char cursor[32]; u_char *font_buffer; int font_size; int i; if (!ISFONTAVAIL(get_adapter(scp)->va_flags) || (scp->status & (GRAPHICS_MODE | PIXEL_MODE))) return; if (scp->font_size < 14) { font_buffer = font_8; font_size = 8; } else if (scp->font_size >= 16) { font_buffer = font_16; font_size = 16; } else { font_buffer = font_14; font_size = 14; } if (scp->status & MOUSE_VISIBLE) { if ((scp->cursor_saveunder & 0xff) == SC_MOUSE_CHAR) bcopy(&scp->mouse_cursor[0], cursor, scp->font_size); else if ((scp->cursor_saveunder & 0xff) == SC_MOUSE_CHAR + 1) bcopy(&scp->mouse_cursor[32], cursor, scp->font_size); else if ((scp->cursor_saveunder & 0xff) == SC_MOUSE_CHAR + 2) bcopy(&scp->mouse_cursor[64], cursor, scp->font_size); else if ((scp->cursor_saveunder & 0xff) == SC_MOUSE_CHAR + 3) bcopy(&scp->mouse_cursor[96], cursor, scp->font_size); else bcopy(font_buffer+((scp->cursor_saveunder & 0xff)*scp->font_size), cursor, scp->font_size); } else bcopy(font_buffer + ((scp->cursor_saveunder & 0xff) * scp->font_size), cursor, scp->font_size); for (i=0; i<32; i++) if ((i >= scp->cursor_start && i <= scp->cursor_end) || (scp->cursor_start >= scp->font_size && i == scp->font_size - 1)) cursor[i] |= 0xff; #if 1 while (!(inb(crtc_addr+6) & 0x08)) /* wait for vertical retrace */ ; #endif font_loading_in_progress = TRUE; (*biosvidsw.load_font)(scp->adp, 0, font_size, cursor, DEAD_CHAR, 1); font_loading_in_progress = FALSE; #endif } void sc_move_mouse(scr_stat *scp, int x, int y) { scp->mouse_xpos = x; scp->mouse_ypos = y; scp->mouse_pos = scp->mouse_oldpos = scp->scr_buf + (y / scp->font_size) * scp->xsize + x / 8; } static void set_mouse_pos(scr_stat *scp) { static int last_xpos = -1, last_ypos = -1; if (scp->mouse_xpos < 0) scp->mouse_xpos = 0; if (scp->mouse_ypos < 0) scp->mouse_ypos = 0; if (!ISTEXTSC(scp)) { if (scp->mouse_xpos > scp->xpixel-1) scp->mouse_xpos = scp->xpixel-1; if (scp->mouse_ypos > scp->ypixel-1) scp->mouse_ypos = scp->ypixel-1; return; } if (scp->mouse_xpos > (scp->xsize*8)-1) scp->mouse_xpos = (scp->xsize*8)-1; if (scp->mouse_ypos > (scp->ysize*scp->font_size)-1) scp->mouse_ypos = (scp->ysize*scp->font_size)-1; if (scp->mouse_xpos != last_xpos || scp->mouse_ypos != last_ypos) { scp->status |= MOUSE_MOVED; scp->mouse_pos = scp->scr_buf + ((scp->mouse_ypos/scp->font_size)*scp->xsize + scp->mouse_xpos/8); if ((scp->status & MOUSE_VISIBLE) && (scp->status & MOUSE_CUTTING)) mouse_cut(scp); } } #define isspace(c) (((c) & 0xff) == ' ') static int skip_spc_right(scr_stat *scp, u_short *p) { int i; for (i = (p - scp->scr_buf) % scp->xsize; i < scp->xsize; ++i) { if (!isspace(*p)) break; ++p; } return i; } static int skip_spc_left(scr_stat *scp, u_short *p) { int i; for (i = (p-- - scp->scr_buf) % scp->xsize - 1; i >= 0; --i) { if (!isspace(*p)) break; --p; } return i; } static void mouse_cut(scr_stat *scp) { u_short *end; u_short *p; int i = 0; int j = 0; scp->mouse_cut_end = (scp->mouse_pos >= scp->mouse_cut_start) ? scp->mouse_pos + 1 : scp->mouse_pos; end = (scp->mouse_cut_start > scp->mouse_cut_end) ? scp->mouse_cut_start : scp->mouse_cut_end; for (p = (scp->mouse_cut_start > scp->mouse_cut_end) ? scp->mouse_cut_end : scp->mouse_cut_start; p < end; ++p) { cut_buffer[i] = *p & 0xff; /* remember the position of the last non-space char */ if (!isspace(cut_buffer[i++])) j = i; /* trim trailing blank when crossing lines */ if (((p - scp->scr_buf) % scp->xsize) == (scp->xsize - 1)) { cut_buffer[j++] = '\r'; i = j; } } cut_buffer[i] = '\0'; /* scan towards the end of the last line */ --p; for (i = (p - scp->scr_buf) % scp->xsize; i < scp->xsize; ++i) { if (!isspace(*p)) break; ++p; } /* if there is nothing but blank chars, trim them, but mark towards eol */ if (i >= scp->xsize) { if (scp->mouse_cut_start > scp->mouse_cut_end) scp->mouse_cut_start = p; else scp->mouse_cut_end = p; cut_buffer[j++] = '\r'; cut_buffer[j] = '\0'; } mark_for_update(scp, scp->mouse_cut_start - scp->scr_buf); mark_for_update(scp, scp->mouse_cut_end - scp->scr_buf); } static void mouse_cut_start(scr_stat *scp) { int i; if (scp->status & MOUSE_VISIBLE) { if (scp->mouse_pos == scp->mouse_cut_start && scp->mouse_cut_start == scp->mouse_cut_end - 1) { cut_buffer[0] = '\0'; remove_cutmarking(scp); } else if (skip_spc_right(scp, scp->mouse_pos) >= scp->xsize) { /* if the pointer is on trailing blank chars, mark towards eol */ i = skip_spc_left(scp, scp->mouse_pos) + 1; scp->mouse_cut_start = scp->scr_buf + ((scp->mouse_pos - scp->scr_buf) / scp->xsize) * scp->xsize + i; scp->mouse_cut_end = scp->scr_buf + ((scp->mouse_pos - scp->scr_buf) / scp->xsize + 1) * scp->xsize; cut_buffer[0] = '\r'; cut_buffer[1] = '\0'; scp->status |= MOUSE_CUTTING; } else { scp->mouse_cut_start = scp->mouse_pos; scp->mouse_cut_end = scp->mouse_cut_start + 1; cut_buffer[0] = *scp->mouse_cut_start & 0xff; cut_buffer[1] = '\0'; scp->status |= MOUSE_CUTTING; } mark_all(scp); /* delete all other screens cut markings */ for (i=0; istatus & MOUSE_VISIBLE) { scp->status &= ~MOUSE_CUTTING; } } static void mouse_cut_word(scr_stat *scp) { u_short *p; u_short *sol; u_short *eol; int i; /* * Because we don't have locale information in the kernel, * we only distinguish space char and non-space chars. Punctuation * chars, symbols and other regular chars are all treated alike. */ if (scp->status & MOUSE_VISIBLE) { sol = scp->scr_buf + ((scp->mouse_pos - scp->scr_buf) / scp->xsize) * scp->xsize; eol = sol + scp->xsize; if (isspace(*scp->mouse_pos)) { for (p = scp->mouse_pos; p >= sol; --p) if (!isspace(*p)) break; scp->mouse_cut_start = ++p; for (p = scp->mouse_pos; p < eol; ++p) if (!isspace(*p)) break; scp->mouse_cut_end = p; } else { for (p = scp->mouse_pos; p >= sol; --p) if (isspace(*p)) break; scp->mouse_cut_start = ++p; for (p = scp->mouse_pos; p < eol; ++p) if (isspace(*p)) break; scp->mouse_cut_end = p; } for (i = 0, p = scp->mouse_cut_start; p < scp->mouse_cut_end; ++p) cut_buffer[i++] = *p & 0xff; cut_buffer[i] = '\0'; scp->status |= MOUSE_CUTTING; } } static void mouse_cut_line(scr_stat *scp) { u_short *p; int i; if (scp->status & MOUSE_VISIBLE) { scp->mouse_cut_start = scp->scr_buf + ((scp->mouse_pos - scp->scr_buf) / scp->xsize) * scp->xsize; scp->mouse_cut_end = scp->mouse_cut_start + scp->xsize; for (i = 0, p = scp->mouse_cut_start; p < scp->mouse_cut_end; ++p) cut_buffer[i++] = *p & 0xff; cut_buffer[i++] = '\r'; cut_buffer[i] = '\0'; scp->status |= MOUSE_CUTTING; } } static void mouse_cut_extend(scr_stat *scp) { if ((scp->status & MOUSE_VISIBLE) && !(scp->status & MOUSE_CUTTING) && (scp->mouse_cut_start != NULL)) { mouse_cut(scp); scp->status |= MOUSE_CUTTING; } } static void mouse_paste(scr_stat *scp) { if (scp->status & MOUSE_VISIBLE) { struct tty *tp; u_char *ptr = cut_buffer; tp = VIRTUAL_TTY(get_scr_num()); while (*ptr) (*linesw[tp->t_line].l_rint)(scr_rmap[*ptr++], tp); } } static void draw_mouse_image(scr_stat *scp) { #ifdef PC98 *(Atrat + (scp->mouse_pos - scp->scr_buf)) ^= 0x4; /* reverse bit */ #else u_short buffer[32]; u_short xoffset, yoffset; u_short *crt_pos = (u_short *)(get_adapter(scp)->va_window) + (scp->mouse_pos - scp->scr_buf); u_char *font_buffer; int font_size; int i; if (scp->font_size < 14) { font_buffer = font_8; font_size = 8; } else if (scp->font_size >= 16) { font_buffer = font_16; font_size = 16; } else { font_buffer = font_14; font_size = 14; } xoffset = scp->mouse_xpos % 8; yoffset = scp->mouse_ypos % scp->font_size; /* prepare mousepointer char's bitmaps */ bcopy(font_buffer + ((*(scp->mouse_pos) & 0xff) * font_size), &scp->mouse_cursor[0], font_size); bcopy(font_buffer + ((*(scp->mouse_pos+1) & 0xff) * font_size), &scp->mouse_cursor[32], font_size); bcopy(font_buffer + ((*(scp->mouse_pos+scp->xsize) & 0xff) * font_size), &scp->mouse_cursor[64], font_size); bcopy(font_buffer + ((*(scp->mouse_pos+scp->xsize+1) & 0xff) * font_size), &scp->mouse_cursor[96], font_size); for (i=0; imouse_cursor[i]<<8 | scp->mouse_cursor[i+32]; buffer[i+font_size]=scp->mouse_cursor[i+64]<<8|scp->mouse_cursor[i+96]; } /* now and-or in the mousepointer image */ for (i=0; i<16; i++) { buffer[i+yoffset] = ( buffer[i+yoffset] & ~(mouse_and_mask[i] >> xoffset)) | (mouse_or_mask[i] >> xoffset); } for (i=0; imouse_cursor[i] = (buffer[i] & 0xff00) >> 8; scp->mouse_cursor[i+32] = buffer[i] & 0xff; scp->mouse_cursor[i+64] = (buffer[i+font_size] & 0xff00) >> 8; scp->mouse_cursor[i+96] = buffer[i+font_size] & 0xff; } #endif scp->mouse_oldpos = scp->mouse_pos; #ifndef PC98 #if 1 /* wait for vertical retrace to avoid jitter on some videocards */ while (!(inb(crtc_addr+6) & 0x08)) /* idle */ ; #endif font_loading_in_progress = TRUE; (*biosvidsw.load_font)(scp->adp, 0, 32, scp->mouse_cursor, SC_MOUSE_CHAR, 4); font_loading_in_progress = FALSE; *(crt_pos) = (*(scp->mouse_pos) & 0xff00) | SC_MOUSE_CHAR; *(crt_pos+scp->xsize) = (*(scp->mouse_pos + scp->xsize) & 0xff00) | (SC_MOUSE_CHAR + 2); if (scp->mouse_xpos < (scp->xsize-1)*8) { *(crt_pos + 1) = (*(scp->mouse_pos + 1) & 0xff00) | (SC_MOUSE_CHAR + 1); *(crt_pos+scp->xsize + 1) = (*(scp->mouse_pos + scp->xsize + 1) & 0xff00) | (SC_MOUSE_CHAR + 3); } #endif mark_for_update(scp, scp->mouse_pos - scp->scr_buf); #ifndef PC98 mark_for_update(scp, scp->mouse_pos + scp->xsize + 1 - scp->scr_buf); #endif } static void remove_mouse_image(scr_stat *scp) { u_short *crt_pos; if (!ISTEXTSC(scp)) return; #ifdef PC98 crt_pos = Atrat + (scp->mouse_oldpos - scp->scr_buf); #else crt_pos = (u_short *)(get_adapter(scp)->va_window) + (scp->mouse_oldpos - scp->scr_buf); #endif #ifdef PC98 *(crt_pos) = *(scp->atr_buf + (scp->mouse_oldpos - scp->scr_buf)); #else *(crt_pos) = *(scp->mouse_oldpos); *(crt_pos+1) = *(scp->mouse_oldpos+1); *(crt_pos+scp->xsize) = *(scp->mouse_oldpos+scp->xsize); *(crt_pos+scp->xsize+1) = *(scp->mouse_oldpos+scp->xsize+1); #endif mark_for_update(scp, scp->mouse_oldpos - scp->scr_buf); #ifndef PC98 mark_for_update(scp, scp->mouse_oldpos + scp->xsize + 1 - scp->scr_buf); #endif } static void draw_cutmarking(scr_stat *scp) { u_short *crt_pos; u_short *ptr; u_short och, nch; #ifdef PC98 crt_pos = Atrat; #else crt_pos = (u_short *)(get_adapter(scp)->va_window); #endif for (ptr=scp->scr_buf; ptr<=(scp->scr_buf+(scp->xsize*scp->ysize)); ptr++) { nch = och = *(crt_pos + (ptr - scp->scr_buf)); /* are we outside the selected area ? */ if ( ptr < (scp->mouse_cut_start > scp->mouse_cut_end ? scp->mouse_cut_end : scp->mouse_cut_start) || ptr >= (scp->mouse_cut_start > scp->mouse_cut_end ? scp->mouse_cut_start : scp->mouse_cut_end)) { #ifdef PC98 if (ptr != scp->mouse_pos) nch = *(scp->atr_buf + (ptr - scp->scr_buf)); else nch = *(scp->atr_buf + (ptr - scp->scr_buf)) ^ 0x4; #else if (ptr != scp->cursor_pos) nch = (och & 0xff) | (*ptr & 0xff00); #endif } else { #ifdef PC98 if (ptr != scp->mouse_pos) nch = *(scp->atr_buf + (ptr - scp->scr_buf)) ^ 0x4; /* reverse bit */ #else /* are we clear of the cursor image ? */ if (ptr != scp->cursor_pos) nch = (och & 0x88ff) | (*ptr & 0x7000)>>4 | (*ptr & 0x0700)<<4; else { if (sc_flags & CHAR_CURSOR) nch = (och & 0x88ff)|(*ptr & 0x7000)>>4|(*ptr & 0x0700)<<4; else if (!(sc_flags & BLINK_CURSOR)) nch = (och & 0xff) | (*ptr & 0xff00); } #endif } if (nch != och) *(crt_pos + (ptr - scp->scr_buf)) = nch; } } static void remove_cutmarking(scr_stat *scp) { scp->mouse_cut_start = scp->mouse_cut_end = NULL; scp->status &= ~MOUSE_CUTTING; mark_all(scp); } static void do_bell(scr_stat *scp, int pitch, int duration) { if (cold || shutdown_in_progress) return; if (scp != cur_console && (sc_flags & QUIET_BELL)) return; if (sc_flags & VISUAL_BELL) { if (blink_in_progress) return; blink_in_progress = 4; if (scp != cur_console) blink_in_progress += 2; blink_screen(cur_console); } else { if (scp != cur_console) pitch *= 2; sysbeep(pitch, duration); } } static void blink_screen(void *arg) { scr_stat *scp = arg; if (!ISTEXTSC(scp) || (blink_in_progress <= 1)) { blink_in_progress = FALSE; mark_all(scp); if (delayed_next_scr) switch_scr(scp, delayed_next_scr - 1); } else { #ifdef PC98 if (blink_in_progress & 1){ fillw(scr_map[0x20], Crtat, scp->xsize * scp->ysize); fillw(at2pc98(kernel_default.std_color), Atrat, scp->xsize * scp->ysize); } else { fillw(scr_map[0x20], Crtat, scp->xsize * scp->ysize); fillw(at2pc98(kernel_default.rev_color), Atrat, scp->xsize * scp->ysize); } #else if (blink_in_progress & 1) fillw(kernel_default.std_color | scr_map[0x20], (u_short *)(get_adapter(scp)->va_window), scp->xsize * scp->ysize); else fillw(kernel_default.rev_color | scr_map[0x20], (u_short *)(get_adapter(scp)->va_window), scp->xsize * scp->ysize); #endif blink_in_progress--; timeout(blink_screen, scp, hz / 10); } } void sc_bcopy(scr_stat *scp, u_short *p, int from, int to, int mark) { #ifdef PC98 if (ISTEXTSC(scp)) { generic_bcopy(p + from, Crtat + from, (to - from + 1)*sizeof(u_short)); } else if (scp->mode == 0x102) { u_char *d, *e; int i,j; if (mark) mark = 255; d = (u_char *)Crtat; d += 10 + 6*16*100 + (from%80) + 16*100*(from/80); for (i = from ; i <= to ; i++) { e = d; for (j = 0 ; j < 16; j++) { *e = mark^font_16[(p[i]&0xff)*16+j]; e+=100; } d++; if ((i % 80) == 79) d += 20 + 15*100; } } #else /* PC98 */ u_char *font; u_char volatile *d; u_char *e; u_char *f; int font_size; int line_length; int xsize; u_short bg; int i, j; u_char c; if (ISTEXTSC(scp)) { generic_bcopy(p + from, (u_short *)(get_adapter(scp)->va_window) + from, (to - from + 1)*sizeof(u_short)); } else /* if ISPIXELSC(scp) */ { if (mark) mark = 255; font_size = scp->font_size; if (font_size < 14) font = font_8; else if (font_size >= 16) font = font_16; else font = font_14; line_length = scp->xpixel/8; xsize = scp->xsize; d = (u_char *)(get_adapter(scp)->va_window) + scp->xoff + scp->yoff*font_size*line_length + (from%xsize) + font_size*line_length*(from/xsize); outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ bg = -1; for (i = from ; i <= to ; i++) { /* set background color in EGA/VGA latch */ if (bg != (p[i] & 0xf000)) { bg = (p[i] & 0xf000); outw(GDCIDX, (bg >> 4) | 0x00); /* set/reset */ outw(GDCIDX, 0xff08); /* bit mask */ *d = 0; c = *d; /* set the background color in the latch */ } /* foreground color */ outw(GDCIDX, (p[i] & 0x0f00) | 0x00); /* set/reset */ e = (u_char *)d; f = &font[(p[i] & 0x00ff)*font_size]; for (j = 0 ; j < font_size; j++, f++) { outw(GDCIDX, ((*f^mark) << 8) | 0x08); /* bit mask */ *e = 0; e += line_length; } d++; if ((i % xsize) == xsize - 1) d += scp->xoff*2 + (font_size - 1)*line_length; } outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ #if 0 /* VGA only */ outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */ outw(GDCIDX, 0x0003); /* data rotate/function select */ outw(GDCIDX, 0x0f01); /* set/reset enable */ outw(GDCIDX, 0xff08); /* bit mask */ bg = -1; for (i = from ; i <= to ; i++) { /* set background color in EGA/VGA latch */ if (bg != (p[i] & 0xf000)) { bg = (p[i] & 0xf000); outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, (bg >> 4) | 0x00); /* set/reset */ *d = 0; c = *d; /* set the background color in the latch */ outw(GDCIDX, 0x0305); /* read mode 0, write mode 3 */ } /* foreground color */ outw(GDCIDX, (p[i] & 0x0f00) | 0x00); /* set/reset */ e = (u_char *)d; f = &font[(p[i] & 0x00ff)*font_size]; for (j = 0 ; j < font_size; j++, f++) { *e = *f^mark; e += line_length; } d++; if ((i % xsize) == xsize - 1) d += scp->xoff*2 + (font_size - 1)*line_length; } outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ outw(GDCIDX, 0x0000); /* set/reset */ outw(GDCIDX, 0x0001); /* set/reset enable */ #endif /* 0 */ } #endif /* PC98 */ } #ifdef SC_SPLASH_SCREEN static void scsplash_init(scr_stat *scp) { video_info_t info; if (scsplash_load(scp) == 0 && add_scrn_saver(scsplash_saver) == 0) { default_saver = scsplash_saver; scrn_blank_time = DEFAULT_BLANKTIME; run_scrn_saver = TRUE; if (!(boothowto & (RB_VERBOSE | RB_CONFIG))) { scsplash_stick(TRUE); scsplash_saver(TRUE); } } } static void scsplash_term(scr_stat *scp) { default_saver = none_saver; scsplash_stick(FALSE); remove_scrn_saver(scsplash_saver); scsplash_unload(scp); } static void scsplash_saver(int show) { if (show) scsplash(TRUE); else if (!sticky_splash) scsplash(FALSE); } #endif /* SC_SPLASH_SCREEN */ #if defined(PC98) && defined(LINE30) /* 30line */ static void master_gdc_cmd(unsigned int cmd) { while ( (inb(0x60) & 2) != 0); outb(0x62, cmd); } static void master_gdc_prm(unsigned int pmtr) { while ( (inb(0x60) & 2) != 0); outb(0x60, pmtr); } static void master_gdc_word_prm(unsigned int wpmtr) { master_gdc_prm(wpmtr & 0x00ff); master_gdc_prm((wpmtr >> 8) & 0x00ff); } static void master_gdc_fifo_empty(void) { while ( (inb(0x60) & 4) == 0); } static void master_gdc_wait_vsync(void) { while ( (inb(0x60) & 0x20) != 0); while ( (inb(0x60) & 0x20) == 0); } static void gdc_cmd(unsigned int cmd) { while ( (inb(0xa0) & 2) != 0); outb( 0xa2, cmd); } static void gdc_prm(unsigned int pmtr) { while ( (inb(0xa0) & 2) != 0); outb( 0xa0, pmtr); } static void gdc_word_prm(unsigned int wpmtr) { gdc_prm(wpmtr & 0x00ff); gdc_prm((wpmtr >> 8) & 0x00ff); } static void gdc_fifo_empty(void) { while ( (inb(0xa0) & 0x04) == 0); } static void gdc_wait_vsync(void) { while ( (inb(0xa0) & 0x20) != 0); while ( (inb(0xa0) & 0x20) == 0); } static int check_gdc_clock(void) { if ((inb(0x31) & 0x80) == 0){ return _5MHZ; } else { return _2_5MHZ; } } static void initialize_gdc(unsigned int mode) { /* start 30line initialize */ int m_mode,s_mode,gdc_clock; gdc_clock = check_gdc_clock(); if (mode == T25_G400){ m_mode = _25L; }else{ m_mode = _30L; } s_mode = 2*mode+gdc_clock; gdc_INFO = m_mode; master_gdc_cmd(_GDC_RESET); master_gdc_cmd(_GDC_MASTER); gdc_cmd(_GDC_RESET); gdc_cmd(_GDC_SLAVE); /* GDC Master */ master_gdc_cmd(_GDC_SYNC); master_gdc_prm(0x00); /* flush less */ /* text & graph */ master_gdc_prm(master_param[m_mode][GDC_CR]); master_gdc_word_prm(((master_param[m_mode][GDC_HFP] << 10) + (master_param[m_mode][GDC_VS] << 5) + master_param[m_mode][GDC_HS])); master_gdc_prm(master_param[m_mode][GDC_HBP]); master_gdc_prm(master_param[m_mode][GDC_VFP]); master_gdc_word_prm(((master_param[m_mode][GDC_VBP] << 10) + (master_param[m_mode][GDC_LF]))); master_gdc_fifo_empty(); master_gdc_cmd(_GDC_PITCH); master_gdc_prm(MasterPCH); master_gdc_fifo_empty(); /* GDC slave */ gdc_cmd(_GDC_SYNC); gdc_prm(0x06); gdc_prm(slave_param[s_mode][GDC_CR]); gdc_word_prm((slave_param[s_mode][GDC_HFP] << 10) + (slave_param[s_mode][GDC_VS] << 5) + (slave_param[s_mode][GDC_HS])); gdc_prm(slave_param[s_mode][GDC_HBP]); gdc_prm(slave_param[s_mode][GDC_VFP]); gdc_word_prm((slave_param[s_mode][GDC_VBP] << 10) + (slave_param[s_mode][GDC_LF])); gdc_fifo_empty(); gdc_cmd(_GDC_PITCH); gdc_prm(SlavePCH[gdc_clock]); gdc_fifo_empty(); /* set Master GDC scroll param */ master_gdc_wait_vsync(); master_gdc_wait_vsync(); master_gdc_wait_vsync(); master_gdc_cmd(_GDC_SCROLL); master_gdc_word_prm(0); master_gdc_word_prm((master_param[m_mode][GDC_LF] << 4) | 0x0000); master_gdc_fifo_empty(); /* set Slave GDC scroll param */ gdc_wait_vsync(); gdc_cmd(_GDC_SCROLL); gdc_word_prm(0); if (gdc_clock == _5MHZ){ gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000); }else{ gdc_word_prm(SlaveScrlLF[mode] << 4); } gdc_fifo_empty(); gdc_word_prm(0); if (gdc_clock == _5MHZ){ gdc_word_prm((SlaveScrlLF[mode] << 4) | 0x4000); }else{ gdc_word_prm(SlaveScrlLF[mode] << 4); } gdc_fifo_empty(); /* sync start */ gdc_cmd(_GDC_STOP); gdc_wait_vsync(); gdc_wait_vsync(); gdc_wait_vsync(); master_gdc_cmd(_GDC_START); } #endif /* 30 line */ #endif /* NSC */