1996-05-19 17:00:43 +04:00
|
|
|
/* $NetBSD: cons.c,v 1.23 1996/05/19 13:00:43 mrg Exp $ */
|
1994-11-20 23:51:32 +03:00
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* 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, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1994-11-20 23:51:32 +03:00
|
|
|
* @(#)cons.c 8.3 (Berkeley) 12/14/93
|
1993-10-02 13:22:00 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Console (indirect) driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/file.h>
|
1996-04-01 21:29:44 +04:00
|
|
|
#include <sys/conf.h>
|
1996-03-14 22:44:30 +03:00
|
|
|
|
|
|
|
#include <dev/cons.h>
|
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
#include <machine/bsd_openprom.h>
|
1996-05-19 17:00:43 +04:00
|
|
|
#include <machine/eeprom.h>
|
1993-10-02 13:22:00 +03:00
|
|
|
#include <machine/psl.h>
|
1996-03-14 22:44:30 +03:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/kbd.h>
|
1996-02-26 00:45:53 +03:00
|
|
|
#if defined(SUN4)
|
1995-07-13 16:02:19 +04:00
|
|
|
#include <machine/oldmon.h>
|
|
|
|
#endif
|
1996-03-14 22:44:30 +03:00
|
|
|
#include <machine/autoconf.h>
|
1996-04-01 21:29:44 +04:00
|
|
|
#include <machine/conf.h>
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
#include "zs.h"
|
|
|
|
|
|
|
|
struct tty *constty = 0; /* virtual console output device */
|
|
|
|
struct tty *fbconstty = 0; /* tty structure for frame buffer console */
|
|
|
|
int rom_console_input; /* when set, hardclock calls cnrom() */
|
|
|
|
|
|
|
|
int cons_ocount; /* output byte count */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The output driver may munge the minor number in cons.t_dev.
|
|
|
|
*/
|
|
|
|
struct tty cons; /* rom console tty device */
|
1996-03-14 22:44:30 +03:00
|
|
|
static int (*fcnstop) __P((struct tty *, int));
|
1993-10-13 05:36:39 +03:00
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
static void cnstart __P((struct tty *));
|
1996-03-14 22:44:30 +03:00
|
|
|
int cnstop __P((struct tty *, int));
|
1993-10-13 05:36:39 +03:00
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
static void cnfbstart __P((struct tty *));
|
1996-03-14 22:44:30 +03:00
|
|
|
static int cnfbstop __P((struct tty *, int));
|
1993-10-02 13:22:00 +03:00
|
|
|
static void cnfbdma __P((void *));
|
1996-03-14 22:44:30 +03:00
|
|
|
static struct tty *xxcntty __P((dev_t));
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1994-05-14 00:09:00 +04:00
|
|
|
extern char char_type[];
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1996-03-14 22:44:30 +03:00
|
|
|
/*XXX*/
|
|
|
|
static struct tty *
|
|
|
|
xxcntty(dev_t dev)
|
1995-04-25 21:52:43 +04:00
|
|
|
{
|
|
|
|
return &cons;
|
|
|
|
}
|
|
|
|
|
1993-10-11 05:36:38 +03:00
|
|
|
void
|
1993-10-02 13:22:00 +03:00
|
|
|
consinit()
|
|
|
|
{
|
|
|
|
register struct tty *tp = &cons;
|
|
|
|
register int in, out;
|
|
|
|
|
1996-03-14 22:44:30 +03:00
|
|
|
/*XXX*/ cdevsw[0].d_tty = xxcntty;
|
1993-10-02 13:22:00 +03:00
|
|
|
tp->t_dev = makedev(0, 0); /* /dev/console */
|
|
|
|
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
|
|
|
|
tp->t_param = (int (*)(struct tty *, struct termios *))nullop;
|
1996-04-01 02:38:29 +04:00
|
|
|
|
1996-02-14 01:49:48 +03:00
|
|
|
if (promvec->pv_romvec_vers > 2) {
|
|
|
|
/* We need to probe the PROM device tree */
|
|
|
|
register int node,fd;
|
|
|
|
char buffer[128];
|
|
|
|
register struct nodeops *no;
|
|
|
|
register struct v2devops *op;
|
|
|
|
register char *cp;
|
|
|
|
extern int fbnode;
|
|
|
|
|
|
|
|
in = out = -1;
|
|
|
|
no = promvec->pv_nodeops;
|
|
|
|
op = &promvec->pv_v2devops;
|
|
|
|
|
|
|
|
node = findroot();
|
|
|
|
if (no->no_proplen(node, "stdin-path") >= sizeof(buffer)) {
|
|
|
|
printf("consinit: increase buffer size and recompile\n");
|
|
|
|
goto setup_output;
|
|
|
|
}
|
|
|
|
/* XXX: fix above */
|
|
|
|
|
|
|
|
no->no_getprop(node, "stdin-path",buffer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open an "instance" of this device.
|
|
|
|
* You'd think it would be appropriate to call v2_close()
|
|
|
|
* on the handle when we're done with it. But that seems
|
|
|
|
* to cause the device to shut down somehow; for the moment,
|
|
|
|
* we simply leave it open...
|
|
|
|
*/
|
|
|
|
if ((fd = op->v2_open(buffer)) == 0 ||
|
|
|
|
(node = op->v2_fd_phandle(fd)) == 0) {
|
|
|
|
printf("consinit: bogus stdin path %s.\n",buffer);
|
|
|
|
goto setup_output;
|
|
|
|
}
|
|
|
|
if (no->no_proplen(node,"keyboard") >= 0) {
|
|
|
|
in = PROMDEV_KBD;
|
|
|
|
goto setup_output;
|
|
|
|
}
|
|
|
|
if (strcmp(getpropstring(node,"device_type"),"serial") != 0) {
|
|
|
|
/* not a serial, not keyboard. what is it?!? */
|
|
|
|
in = -1;
|
|
|
|
goto setup_output;
|
|
|
|
}
|
1996-04-01 02:38:29 +04:00
|
|
|
/*
|
1996-02-14 01:49:48 +03:00
|
|
|
* At this point we assume the device path is in the form
|
|
|
|
* ....device@x,y:a for ttya and ...device@x,y:b for ttyb.
|
|
|
|
* If it isn't, we defer to the ROM
|
|
|
|
*/
|
|
|
|
cp = buffer;
|
|
|
|
while (*cp)
|
|
|
|
cp++;
|
|
|
|
cp -= 2;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (cp < buffer)
|
|
|
|
panic("consinit: bad stdin path %s",buffer);
|
|
|
|
#endif
|
|
|
|
/* XXX: only allows tty's a->z, assumes PROMDEV_TTYx contig */
|
|
|
|
if (cp[0]==':' && cp[1] >= 'a' && cp[1] <= 'z')
|
|
|
|
in = PROMDEV_TTYA + (cp[1] - 'a');
|
|
|
|
/* else use rom */
|
|
|
|
setup_output:
|
|
|
|
node = findroot();
|
|
|
|
if (no->no_proplen(node, "stdout-path") >= sizeof(buffer)) {
|
|
|
|
printf("consinit: increase buffer size and recompile\n");
|
|
|
|
goto setup_console;
|
|
|
|
}
|
|
|
|
/* XXX: fix above */
|
|
|
|
|
|
|
|
no->no_getprop(node, "stdout-path", buffer);
|
1993-10-02 13:22:00 +03:00
|
|
|
|
1996-02-14 01:49:48 +03:00
|
|
|
if ((fd = op->v2_open(buffer)) == 0 ||
|
|
|
|
(node = op->v2_fd_phandle(fd)) == 0) {
|
|
|
|
printf("consinit: bogus stdout path %s.\n",buffer);
|
|
|
|
goto setup_output;
|
|
|
|
}
|
|
|
|
if (strcmp(getpropstring(node,"device_type"),"display") == 0) {
|
|
|
|
/* frame buffer output */
|
|
|
|
out = PROMDEV_SCREEN;
|
|
|
|
fbnode = node;
|
|
|
|
} else if (strcmp(getpropstring(node,"device_type"), "serial")
|
|
|
|
!= 0) {
|
|
|
|
/* not screen, not serial. Whatzit? */
|
|
|
|
out = -1;
|
|
|
|
} else { /* serial console. which? */
|
1996-04-01 02:38:29 +04:00
|
|
|
/*
|
|
|
|
* At this point we assume the device path is in the
|
1996-02-14 01:49:48 +03:00
|
|
|
* form:
|
|
|
|
* ....device@x,y:a for ttya, etc.
|
|
|
|
* If it isn't, we defer to the ROM
|
|
|
|
*/
|
|
|
|
cp = buffer;
|
|
|
|
while (*cp)
|
|
|
|
cp++;
|
|
|
|
cp -= 2;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (cp < buffer)
|
|
|
|
panic("consinit: bad stdout path %s",buffer);
|
|
|
|
#endif
|
|
|
|
/* XXX: only allows tty's a->z, assumes PROMDEV_TTYx contig */
|
|
|
|
if (cp[0]==':' && cp[1] >= 'a' && cp[1] <= 'z')
|
|
|
|
out = PROMDEV_TTYA + (cp[1] - 'a');
|
|
|
|
else out = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
in = *promvec->pv_stdin;
|
|
|
|
out = *promvec->pv_stdout;
|
|
|
|
}
|
|
|
|
setup_console:
|
|
|
|
switch (in) {
|
1993-10-02 13:22:00 +03:00
|
|
|
#if NZS > 0
|
|
|
|
case PROMDEV_TTYA:
|
1993-10-13 05:36:39 +03:00
|
|
|
zsconsole(tp, 0, 0, NULL);
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROMDEV_TTYB:
|
1993-10-13 05:36:39 +03:00
|
|
|
zsconsole(tp, 1, 0, NULL);
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case PROMDEV_KBD:
|
|
|
|
/*
|
|
|
|
* Tell the keyboard driver to direct ASCII input here.
|
|
|
|
*/
|
|
|
|
kbd_ascii(tp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rom_console_input = 1;
|
|
|
|
printf("unknown console input source %d; using rom\n", in);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (out) {
|
|
|
|
|
|
|
|
#if NZS > 0
|
|
|
|
case PROMDEV_TTYA:
|
1993-10-13 05:36:39 +03:00
|
|
|
zsconsole(tp, 0, 1, &fcnstop);
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROMDEV_TTYB:
|
1993-10-13 05:36:39 +03:00
|
|
|
zsconsole(tp, 1, 1, &fcnstop);
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case PROMDEV_SCREEN:
|
|
|
|
fbconstty = tp;
|
|
|
|
tp->t_oproc = cnfbstart;
|
1993-10-13 05:36:39 +03:00
|
|
|
fcnstop = cnfbstop;
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("unknown console output sink %d; using rom\n", out);
|
|
|
|
tp->t_oproc = cnstart;
|
1996-03-14 22:44:30 +03:00
|
|
|
fcnstop = (int (*)(struct tty *, int))nullop;
|
1993-10-02 13:22:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
register struct tty *tp = &cons;
|
1993-10-13 05:36:39 +03:00
|
|
|
static int firstopen = 1;
|
1996-05-19 17:00:43 +04:00
|
|
|
static int rows = 0, cols = 0;
|
1993-10-13 05:36:39 +03:00
|
|
|
|
1996-05-19 17:00:43 +04:00
|
|
|
if (firstopen) {
|
1993-10-13 05:36:39 +03:00
|
|
|
clalloc(&tp->t_rawq, 1024, 1);
|
|
|
|
clalloc(&tp->t_canq, 1024, 1);
|
|
|
|
/* output queue doesn't need quoting */
|
|
|
|
clalloc(&tp->t_outq, 1024, 0);
|
1996-05-19 17:00:43 +04:00
|
|
|
/*
|
|
|
|
* get the console struct winsize.
|
|
|
|
*/
|
|
|
|
if (CPU_ISSUN4COR4M) {
|
|
|
|
int i;
|
|
|
|
char *prop;
|
|
|
|
|
|
|
|
if ((prop = getpropstring(optionsnode, "screen-#rows"))) {
|
|
|
|
i = 0;
|
|
|
|
while (*prop != '\0')
|
|
|
|
i = i * 10 + *prop++ - '0';
|
|
|
|
rows = (unsigned short)i;
|
|
|
|
}
|
|
|
|
if ((prop = getpropstring(optionsnode, "screen-#columns"))) {
|
|
|
|
i = 0;
|
|
|
|
while (*prop != '\0')
|
|
|
|
i = i * 10 + *prop++ - '0';
|
|
|
|
cols = (unsigned short)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CPU_ISSUN4) {
|
|
|
|
struct eeprom *ep = (struct eeprom *)eeprom_va;
|
|
|
|
|
|
|
|
if (ep) {
|
|
|
|
rows = (u_short)ep->eeTtyRows;
|
|
|
|
cols = (u_short)ep->eeTtyCols;
|
|
|
|
}
|
|
|
|
}
|
1993-10-13 05:36:39 +03:00
|
|
|
firstopen = 0;
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
|
|
|
/*
|
|
|
|
* Leave baud rate alone!
|
|
|
|
*/
|
|
|
|
ttychars(tp);
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG;
|
|
|
|
tp->t_state = TS_ISOPEN | TS_CARR_ON;
|
|
|
|
(void)(*tp->t_param)(tp, &tp->t_termios);
|
|
|
|
ttsetwater(tp);
|
1996-05-19 17:00:43 +04:00
|
|
|
tp->t_winsize.ws_row = rows;
|
|
|
|
tp->t_winsize.ws_col = cols;
|
1993-10-02 13:22:00 +03:00
|
|
|
} else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0)
|
|
|
|
return (EBUSY);
|
|
|
|
return ((*linesw[tp->t_line].l_open)(dev, tp));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
register struct tty *tp = &cons;
|
|
|
|
|
|
|
|
(*linesw[tp->t_line].l_close)(tp, flag);
|
|
|
|
ttyclose(tp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
register struct tty *tp = &cons;
|
|
|
|
|
|
|
|
return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnwrite(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
register struct tty *tp;
|
1996-04-01 02:38:29 +04:00
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
if ((tp = constty) == NULL ||
|
|
|
|
(tp->t_state & (TS_CARR_ON|TS_ISOPEN)) != (TS_CARR_ON|TS_ISOPEN))
|
|
|
|
tp = &cons;
|
|
|
|
return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
1994-11-02 07:55:47 +03:00
|
|
|
u_long cmd;
|
1993-10-02 13:22:00 +03:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
register struct tty *tp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Superuser can always use this to wrest control of console
|
|
|
|
* output from the "virtual" console.
|
|
|
|
*/
|
|
|
|
if (cmd == TIOCCONS && constty) {
|
|
|
|
error = suser(p->p_ucred, (u_short *)NULL);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
constty = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
tp = &cons;
|
1994-02-14 12:37:11 +03:00
|
|
|
if ((error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, p)) >= 0)
|
1993-10-02 13:22:00 +03:00
|
|
|
return (error);
|
1994-02-14 12:37:11 +03:00
|
|
|
if ((error = ttioctl(tp, cmd, data, flag, p)) >= 0)
|
1993-10-02 13:22:00 +03:00
|
|
|
return (error);
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnselect(dev, which, p)
|
|
|
|
dev_t dev;
|
|
|
|
int which;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ttselect(makedev(major(dev), 0), which, p));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The rest of this code is run only when we are using the ROM vectors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic output. We just call putchar. (Very bad for performance.)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cnstart(tp)
|
|
|
|
register struct tty *tp;
|
|
|
|
{
|
|
|
|
register int c, s;
|
1996-02-14 01:49:48 +03:00
|
|
|
register union {
|
|
|
|
void (*v1)__P((int));
|
|
|
|
int (*v3)__P((int, void *, int));
|
|
|
|
} putc;
|
1996-03-14 22:44:30 +03:00
|
|
|
register int fd = 0, v;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1995-06-01 18:36:17 +04:00
|
|
|
if ((v = promvec->pv_romvec_vers) > 2) {
|
1996-02-14 01:49:48 +03:00
|
|
|
putc.v3 = promvec->pv_v2devops.v2_write;
|
1995-06-01 18:36:17 +04:00
|
|
|
fd = *promvec->pv_v2bootargs.v2_fd1;
|
|
|
|
} else
|
1996-02-14 01:49:48 +03:00
|
|
|
putc.v1 = promvec->pv_putchar;
|
1993-10-02 13:22:00 +03:00
|
|
|
while (tp->t_outq.c_cc) {
|
|
|
|
c = getc(&tp->t_outq);
|
|
|
|
/*
|
|
|
|
* *%&!*& ROM monitor console putchar is not reentrant!
|
|
|
|
* splhigh/tty around it so as not to run so long with
|
|
|
|
* clock interrupts blocked.
|
|
|
|
*/
|
|
|
|
(void) splhigh();
|
1995-06-01 18:36:17 +04:00
|
|
|
if (v > 2) {
|
|
|
|
unsigned char c0 = c & 0177;
|
1996-02-14 01:49:48 +03:00
|
|
|
(*putc.v3)(fd, &c0, 1);
|
1995-06-01 18:36:17 +04:00
|
|
|
} else
|
1996-02-14 01:49:48 +03:00
|
|
|
(*putc.v1)(c & 0177);
|
1993-10-02 13:22:00 +03:00
|
|
|
(void) spltty();
|
|
|
|
}
|
|
|
|
if (tp->t_state & TS_ASLEEP) { /* can't happen? */
|
|
|
|
tp->t_state &= ~TS_ASLEEP;
|
|
|
|
wakeup((caddr_t)&tp->t_outq);
|
|
|
|
}
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1996-03-14 22:44:30 +03:00
|
|
|
int
|
1993-10-13 05:36:39 +03:00
|
|
|
cnstop(tp, flag)
|
|
|
|
register struct tty *tp;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
(*fcnstop)(tp, flag);
|
1996-03-14 22:44:30 +03:00
|
|
|
return 0;
|
1993-10-13 05:36:39 +03:00
|
|
|
}
|
|
|
|
|
1993-10-02 13:22:00 +03:00
|
|
|
/*
|
|
|
|
* Frame buffer output.
|
|
|
|
* We use pseudo-DMA, via the ROM `write string' function, called from
|
|
|
|
* software clock interrupts.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cnfbstart(tp)
|
|
|
|
register struct tty *tp;
|
|
|
|
{
|
|
|
|
register int s;
|
|
|
|
|
|
|
|
s = spltty(); /* paranoid: splsoftclock should suffice */
|
|
|
|
if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If there are sleepers, and output has drained below low
|
|
|
|
* water mark, awaken.
|
|
|
|
*/
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_lowat) {
|
|
|
|
if (tp->t_state & TS_ASLEEP) {
|
|
|
|
tp->t_state &= ~TS_ASLEEP;
|
|
|
|
wakeup((caddr_t)&tp->t_outq);
|
|
|
|
}
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
}
|
|
|
|
if (tp->t_outq.c_cc) {
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
if (s == 0) {
|
|
|
|
(void) splsoftclock();
|
|
|
|
cnfbdma((void *)tp);
|
|
|
|
} else
|
1994-05-05 13:53:37 +04:00
|
|
|
timeout(cnfbdma, tp, 1);
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop frame buffer output: just assert TS_FLUSH if necessary.
|
|
|
|
*/
|
1996-03-14 22:44:30 +03:00
|
|
|
static int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnfbstop(tp, flag)
|
|
|
|
register struct tty *tp;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
register int s = spltty(); /* paranoid */
|
|
|
|
|
|
|
|
if ((tp->t_state & (TS_BUSY | TS_TTSTOP)) == TS_BUSY)
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
splx(s);
|
1996-03-14 22:44:30 +03:00
|
|
|
return 0;
|
1993-10-02 13:22:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do pseudo-dma (called from software interrupt).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cnfbdma(tpaddr)
|
|
|
|
void *tpaddr;
|
|
|
|
{
|
|
|
|
register struct tty *tp = tpaddr;
|
1996-02-14 01:49:48 +03:00
|
|
|
register unsigned char *p, *q;
|
1993-10-02 13:22:00 +03:00
|
|
|
register int n, c, s;
|
|
|
|
|
|
|
|
s = spltty(); /* paranoid */
|
|
|
|
if (tp->t_state & TS_FLUSH) {
|
|
|
|
tp->t_state &= ~(TS_BUSY | TS_FLUSH);
|
|
|
|
splx(s);
|
|
|
|
} else {
|
|
|
|
tp->t_state &= ~TS_BUSY;
|
|
|
|
splx(s);
|
|
|
|
p = tp->t_outq.c_cf;
|
|
|
|
n = ndqb(&tp->t_outq, 0);
|
|
|
|
for (q = p, c = n; --c >= 0; q++)
|
|
|
|
if (*q & 0200) /* high bits seem to be bad */
|
|
|
|
*q &= ~0200;
|
1995-06-01 18:36:17 +04:00
|
|
|
if (promvec->pv_romvec_vers > 2) {
|
|
|
|
(*promvec->pv_v2devops.v2_write)
|
|
|
|
(*promvec->pv_v2bootargs.v2_fd1, p, n);
|
|
|
|
} else
|
1996-02-14 01:49:48 +03:00
|
|
|
(*promvec->pv_putstr)((char *)p, n);
|
1993-10-02 13:22:00 +03:00
|
|
|
ndflush(&tp->t_outq, n);
|
|
|
|
}
|
|
|
|
if (tp->t_line)
|
|
|
|
(*linesw[tp->t_line].l_start)(tp);
|
|
|
|
else
|
|
|
|
cnfbstart(tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following is for rom console input. The rom will not call
|
|
|
|
* an `interrupt' routine on console input ready, so we must poll.
|
|
|
|
* This is all rather sad.
|
|
|
|
*/
|
1995-06-01 18:36:17 +04:00
|
|
|
volatile int cn_rxc = -1; /* XXX receive `silo' */
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
/* called from hardclock, which is above spltty, so no tty calls! */
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cnrom()
|
|
|
|
{
|
|
|
|
register int c;
|
|
|
|
|
|
|
|
if (cn_rxc >= 0)
|
|
|
|
return (1);
|
1995-06-01 18:36:17 +04:00
|
|
|
if (promvec->pv_romvec_vers > 2) {
|
|
|
|
unsigned char c0;
|
|
|
|
if ((*promvec->pv_v2devops.v2_read)
|
|
|
|
(*promvec->pv_v2bootargs.v2_fd0, &c0, 1) <= 0)
|
|
|
|
return (0);
|
|
|
|
c = c0;
|
|
|
|
} else if ((c = (*promvec->pv_nbgetchar)()) < 0)
|
1993-10-02 13:22:00 +03:00
|
|
|
return (0);
|
|
|
|
cn_rxc = c;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pseudo console software interrupt scheduled when cnrom() returns 1 */
|
1996-02-14 01:49:48 +03:00
|
|
|
void
|
1993-10-02 13:22:00 +03:00
|
|
|
cnrint()
|
|
|
|
{
|
|
|
|
register struct tty *tp;
|
|
|
|
register int c, s;
|
|
|
|
|
|
|
|
s = splclock();
|
|
|
|
c = cn_rxc;
|
|
|
|
cn_rxc = -1;
|
|
|
|
splx(s);
|
|
|
|
if (c < 0)
|
|
|
|
return;
|
|
|
|
tp = &cons;
|
|
|
|
if ((tp->t_cflag & CSIZE) == CS7) {
|
|
|
|
/* XXX this should be done elsewhere, if at all */
|
|
|
|
if (tp->t_cflag & PARENB)
|
|
|
|
if (tp->t_cflag & PARODD ?
|
1994-05-14 00:09:00 +04:00
|
|
|
(char_type[c & 0177] & 0200) == (c & 0200) :
|
|
|
|
(char_type[c & 0177] & 0200) != (c & 0200))
|
1993-10-02 13:22:00 +03:00
|
|
|
c |= TTY_PE;
|
|
|
|
c &= ~0200;
|
|
|
|
}
|
|
|
|
(*linesw[tp->t_line].l_rint)(c, tp);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:49:48 +03:00
|
|
|
int
|
1993-10-02 13:22:00 +03:00
|
|
|
cngetc()
|
|
|
|
{
|
|
|
|
register int s, c;
|
|
|
|
|
1995-06-01 18:36:17 +04:00
|
|
|
if (promvec->pv_romvec_vers > 2) {
|
|
|
|
register int n = 0;
|
|
|
|
unsigned char c0;
|
1996-02-14 01:49:48 +03:00
|
|
|
s = splhigh();
|
1995-06-01 18:36:17 +04:00
|
|
|
while (n <= 0) {
|
|
|
|
n = (*promvec->pv_v2devops.v2_read)
|
|
|
|
(*promvec->pv_v2bootargs.v2_fd0, &c0, 1);
|
|
|
|
}
|
1996-02-14 01:49:48 +03:00
|
|
|
splx(s);
|
1995-06-01 18:36:17 +04:00
|
|
|
c = c0;
|
|
|
|
} else {
|
1996-02-26 00:45:53 +03:00
|
|
|
#if defined(SUN4)
|
1995-07-13 16:02:19 +04:00
|
|
|
/* SUN4 PROM: must turn off echo to avoid double char echo */
|
|
|
|
extern struct om_vector *oldpvec;
|
1996-03-14 22:44:30 +03:00
|
|
|
int saveecho = 0;
|
1995-07-13 16:02:19 +04:00
|
|
|
#endif
|
|
|
|
|
1995-06-01 18:36:17 +04:00
|
|
|
s = splhigh();
|
1996-02-26 00:45:53 +03:00
|
|
|
#if defined(SUN4)
|
|
|
|
if (CPU_ISSUN4) {
|
1995-07-13 16:02:19 +04:00
|
|
|
saveecho = *(oldpvec->echo);
|
|
|
|
*(oldpvec->echo) = 0;
|
|
|
|
}
|
|
|
|
#endif
|
1995-06-01 18:36:17 +04:00
|
|
|
c = (*promvec->pv_getchar)();
|
1996-02-26 00:45:53 +03:00
|
|
|
#if defined(SUN4)
|
1996-04-01 02:38:29 +04:00
|
|
|
if (CPU_ISSUN4)
|
1995-07-13 16:02:19 +04:00
|
|
|
*(oldpvec->echo) = saveecho;
|
|
|
|
#endif
|
1995-06-01 18:36:17 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
1993-10-02 13:22:00 +03:00
|
|
|
if (c == '\r')
|
|
|
|
c = '\n';
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:49:48 +03:00
|
|
|
void
|
1993-10-02 13:22:00 +03:00
|
|
|
cnputc(c)
|
|
|
|
register int c;
|
|
|
|
{
|
1995-06-01 18:36:17 +04:00
|
|
|
register int s;
|
1993-10-02 13:22:00 +03:00
|
|
|
|
|
|
|
if (c == '\n')
|
1995-06-01 18:36:17 +04:00
|
|
|
cnputc('\r');
|
|
|
|
s = splhigh();
|
|
|
|
if (promvec->pv_romvec_vers > 2) {
|
|
|
|
unsigned char c0 = c;
|
|
|
|
(*promvec->pv_v2devops.v2_write)
|
|
|
|
(*promvec->pv_v2bootargs.v2_fd1, &c0, 1);
|
|
|
|
} else
|
|
|
|
(*promvec->pv_putchar)(c);
|
1993-10-02 13:22:00 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
1994-11-26 02:55:53 +03:00
|
|
|
|
1996-02-14 01:49:48 +03:00
|
|
|
void
|
1995-06-01 18:36:17 +04:00
|
|
|
cnpollc(on)
|
1994-11-26 02:55:53 +03:00
|
|
|
int on;
|
|
|
|
{
|
|
|
|
}
|