xref: /csrg-svn/sys/pmax/pmax/cons.c (revision 65598)
152118Smckusick /*
252118Smckusick  * Copyright (c) 1988 University of Utah.
363218Sbostic  * Copyright (c) 1992, 1993
463218Sbostic  *	The Regents of the University of California.  All rights reserved.
552118Smckusick  *
652118Smckusick  * This code is derived from software contributed to Berkeley by
752118Smckusick  * the Systems Programming Group of the University of Utah Computer
852118Smckusick  * Science Department and Ralph Campbell.
952118Smckusick  *
1052118Smckusick  * %sccs.include.redist.c%
1152118Smckusick  *
1252118Smckusick  * from: Utah $Hdr: cons.c 1.1 90/07/09$
1352118Smckusick  *
14*65598Smckusick  *	@(#)cons.c	8.2 (Berkeley) 01/11/94
1552118Smckusick  */
1652118Smckusick 
1756524Sbostic #include <sys/param.h>
1856524Sbostic #include <sys/proc.h>
1956524Sbostic #include <sys/systm.h>
2056524Sbostic #include <sys/buf.h>
2156524Sbostic #include <sys/ioctl.h>
2256524Sbostic #include <sys/tty.h>
2356524Sbostic #include <sys/file.h>
2456524Sbostic #include <sys/conf.h>
2552118Smckusick 
2656828Sralph #include <pmax/stand/dec_prom.h>
2752118Smckusick 
2852118Smckusick /*
2956828Sralph  * Console I/O is redirected to the appropriate device, either a screen and
30*65598Smckusick  * keyboard, a serial port, or the "virtual" console.
3152118Smckusick  */
3256828Sralph #include <pmax/pmax/cons.h>
3352118Smckusick 
34*65598Smckusick extern struct tty *constty;	/* virtual console output device */
35*65598Smckusick 
3656828Sralph struct consdev cn_tab = {
3756828Sralph 	1,
3856828Sralph 	1,
3956828Sralph 	NODEV,
4056828Sralph 	(struct pmax_fb *)0,
4156828Sralph 	(int (*)())0,
4256828Sralph 	(int (*)())0,
4356828Sralph 	(void (*)())0,
4456828Sralph 	(struct tty *)0,
4556828Sralph };
4656828Sralph 
cnopen(dev,flag,mode,p)4756828Sralph cnopen(dev, flag, mode, p)
4856828Sralph 	dev_t dev;
4956828Sralph 	int flag, mode;
5056828Sralph 	struct proc *p;
5156828Sralph {
5256828Sralph 	if (cn_tab.cn_dev == NODEV)
5356828Sralph 		return (0);
5456828Sralph 	dev = cn_tab.cn_dev;
5556828Sralph 	return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p));
5656828Sralph }
5756828Sralph 
cnclose(dev,flag,mode,p)5856828Sralph cnclose(dev, flag, mode, p)
5956828Sralph 	dev_t dev;
6056828Sralph 	int flag, mode;
6156828Sralph 	struct proc *p;
6256828Sralph {
6356828Sralph 	if (cn_tab.cn_dev == NODEV)
6456828Sralph 		return (0);
6556828Sralph 	dev = cn_tab.cn_dev;
6656828Sralph 	return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p));
6756828Sralph }
6856828Sralph 
cnread(dev,uio,flag)6956828Sralph cnread(dev, uio, flag)
7056828Sralph 	dev_t dev;
7156828Sralph 	struct uio *uio;
7256828Sralph {
7356828Sralph 	if (cn_tab.cn_dev == NODEV)
7456828Sralph 		return (0);
7556828Sralph 	dev = cn_tab.cn_dev;
7656828Sralph 	return ((*cdevsw[major(dev)].d_read)(dev, uio, flag));
7756828Sralph }
7856828Sralph 
cnwrite(dev,uio,flag)7956828Sralph cnwrite(dev, uio, flag)
8056828Sralph 	dev_t dev;
8156828Sralph 	struct uio *uio;
8256828Sralph {
83*65598Smckusick 	if (constty)
84*65598Smckusick 		return ((*linesw[constty->t_line].l_write)(constty, uio, flag));
8556828Sralph 	if (cn_tab.cn_dev == NODEV)
8656828Sralph 		return (0);
8756828Sralph 	dev = cn_tab.cn_dev;
8856828Sralph 	return ((*cdevsw[major(dev)].d_write)(dev, uio, flag));
8956828Sralph }
9056828Sralph 
cnioctl(dev,cmd,data,flag,p)9156828Sralph cnioctl(dev, cmd, data, flag, p)
9256828Sralph 	dev_t dev;
9356828Sralph 	caddr_t data;
9456828Sralph 	struct proc *p;
9556828Sralph {
9656828Sralph 	int error;
9756828Sralph 
98*65598Smckusick 	/*
99*65598Smckusick 	 * Superuser can always use this to wrest control of console
100*65598Smckusick 	 * output from the "virtual" console.
101*65598Smckusick 	 */
102*65598Smckusick 	if (cmd == TIOCCONS && constty) {
103*65598Smckusick 		error = suser(p->p_ucred, (u_short *) NULL);
104*65598Smckusick 		if (error)
105*65598Smckusick 			return (error);
106*65598Smckusick 		constty = NULL;
107*65598Smckusick 		return (0);
108*65598Smckusick 	}
109*65598Smckusick #if 0
110*65598Smckusick 	if (constty) {
111*65598Smckusick 		error = (*linesw[constty->t_line].l_ioctl)
112*65598Smckusick 			(constty, cmd, data, flag, p);
113*65598Smckusick 		if (error >= 0)
114*65598Smckusick 			return (error);
115*65598Smckusick 	}
116*65598Smckusick #endif
11756828Sralph 	if (cn_tab.cn_dev == NODEV)
11856828Sralph 		return (0);
11956828Sralph 	dev = cn_tab.cn_dev;
12056828Sralph 	return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p));
12156828Sralph }
12256828Sralph 
12356828Sralph /*ARGSUSED*/
cnselect(dev,rw,p)12456828Sralph cnselect(dev, rw, p)
12556828Sralph 	dev_t dev;
12656828Sralph 	int rw;
12756828Sralph 	struct proc *p;
12856828Sralph {
12956828Sralph 	if (cn_tab.cn_dev == NODEV)
13056828Sralph 		return (1);
13156828Sralph 	return (ttselect(cn_tab.cn_dev, rw, p));
13256828Sralph }
13356828Sralph 
13452118Smckusick /*
13552118Smckusick  * Get character from console.
13652118Smckusick  */
cngetc()13752118Smckusick cngetc()
13852118Smckusick {
13952118Smckusick 
14052701Sralph 	/* check to be sure device has been initialized */
14156828Sralph 	if (cn_tab.cn_dev == NODEV || cn_tab.cn_disabled)
14256828Sralph 		return ((*callv->getchar)());
14356828Sralph 	return ((*cn_tab.cn_getc)(cn_tab.cn_dev));
14452118Smckusick }
14552118Smckusick 
14652118Smckusick /*
14752118Smckusick  * Print a character on console.
14852118Smckusick  */
cnputc(c)14952118Smckusick cnputc(c)
15052118Smckusick 	register int c;
15152118Smckusick {
15252118Smckusick 	int s;
15352118Smckusick 
15456828Sralph 	if (cn_tab.cn_dev == NODEV || cn_tab.cn_disabled) {
15556828Sralph 		s = splhigh();
15656828Sralph 		(*callv->printf)("%c", c);
15756828Sralph 		splx(s);
15856828Sralph 	} else if (c) {
15956828Sralph 		if (c == '\n')
16056828Sralph 			(*cn_tab.cn_putc)(cn_tab.cn_dev, '\r');
16156828Sralph 		(*cn_tab.cn_putc)(cn_tab.cn_dev, c);
16256828Sralph 	}
16352118Smckusick }
164