* Copyright (c) 1990 The Regents of the University of California.
* Copyright (c) 1992 by Holger Veit
* This code is derived from software contributed to Berkeley by
* William Jolitz and Don Ahn.
* Significant parts are added and rewritten by Holger Veit.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
* @(#)co_cons.c $Revision: 1.11 $ (Contributed to 386bsd) $Date: 93/01/23 23:14:33 $
static char *rcsid
= "$Header: /usr/src/sys.386bsd/i386/isa/codrv/RCS/co_cons.c,v 1.11 93/01/23 23:14:33 root Exp Locker: root $";
* History: See CO_HISTORY
* code to work keyboard & display for PC-style console
unsigned __debug
= 0; /* 0xffe, exported to elsewhere */
struct tty
*dev2tty(dev_t dev
)
/* also checks valid minor # */
static int tty2vty(struct tty
*tp
)
if (vtys
[i
].ttyp
==tp
) return i
;
* open a vty device. Name 'pcopen' is historical
int pcopen(dev_t dev
, int flag
, int mode
, struct proc
*p
)
register struct tty
*tp
= dev2tty(dev
);
/* increment ref count */
vtys
[minor(dev
)].ttycnt
++;
consoftc
.cs_flags
|= CO_OPEN
|CO_INITTTY
;
if ((tp
->t_state
& TS_ISOPEN
) == 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
;
pcparam(tp
, &tp
->t_termios
);
} else if (tp
->t_state
&TS_XCLUDE
&& p
->p_ucred
->cr_uid
!= 0)
tp
->t_state
|= TS_CARR_ON
;
return ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
int pcclose(dev_t dev
, int flag
, int mode
, struct proc
*p
)
register struct tty
*tp
= dev2tty(dev
);
struct vty
*vp
= &vtys
[minor(dev
)];
/* decrement vty reference count */
if (vp
->ttycnt
> 0) vp
->ttycnt
--;
if (consoftc
.cs_opencnt
==0) {
consoftc
.cs_flags
&= ~CO_OPEN
;
/* reset the keyboard state */
(*linesw
[tp
->t_line
].l_close
)(tp
, flag
);
int pcread(dev_t dev
, struct uio
*uio
, int flag
)
register struct tty
*tp
= dev2tty(dev
);
/* this does not belong to here, but anybody always wants to
strip the 8th bit, very likely the shell */
return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, flag
));
int pcwrite(dev_t dev
, struct uio
*uio
, int flag
)
register struct tty
*tp
= dev2tty(dev
);
/* we allow writing, but we don't know where it goes to */
/*if (consoftc.cs_flags & CO_OPENRAW) return EBUSY; */
return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, flag
));
* This does no longer accept keyboard and vga oriented ioctls
int pcioctl(dev_t dev
, int cmd
, caddr_t data
, int flag
)
/* call the ioctl handler */
return consioctl(dev
, cmd
, data
, flag
);
* Got a console transmission interrupt -
* the console processor wants another character.
* -hv- is this really used?
register struct tty
*tp
= dev2tty(dev
);
(*linesw
[tp
->t_line
].l_start
)(tp
);
int pcstart(register struct tty
*tp
)
if (tp
->t_state
& (TS_TIMEOUT
|TS_BUSY
|TS_TTSTOP
))
if (RB_LEN(&tp
->t_out
) <= tp
->t_lowat
) {
if (tp
->t_state
&TS_ASLEEP
) {
tp
->t_state
&= ~TS_ASLEEP
;
wakeup((caddr_t
)&tp
->t_out
);
selwakeup(tp
->t_wsel
, tp
->t_state
& TS_WCOLL
);
tp
->t_state
&= ~TS_WCOLL
;
if (RB_LEN(&tp
->t_out
) == 0)
if (vp
< 0) panic("pcstart: unknown vty");
/* interface for console device */
void pccnprobe(struct consdev
*cp
)
/* locate the major number */
for (maj
= 0; maj
< nchrdev
; maj
++)
if (cdevsw
[maj
].d_open
== pcopen
)
/* initialize required fields */
cp
->cn_dev
= makedev(maj
, 0);
cp
->cn_pri
= CN_INTERNAL
;
/* interface for console device */
void pccninit(struct consdev
*cp
)
* For now, don't screw with it.
/* interface for console device */
void pccnputc(dev_t dev
, int c
)
if (!dev2tty(dev
)) return; /* ignore if invalid */
sput(minor(dev
), '\r', clr
);
sput(minor(dev
), c
, clr
);
* Print a character on console.
/* interface for console device */
s
= spltty(); /* block cointr while we poll */
while ((cp
= kbd_sgetc(0))==NULL
);
if (*cp
== '\r') return('\n');
cp
= kbd_sgetc(0); /* this is surely ASCII */
int pcparam(struct tty
*tp
, struct termios
*t
)
register int cflag
= t
->c_cflag
;
tp
->t_ispeed
= t
->c_ispeed
;
tp
->t_ospeed
= t
->c_ospeed
;
* Turn input polling on/off (used by debugger).
int pg(char *p
,int q
,int r
,int s
,int t
,int u
,int v
,int w
,int x
,int y
,int z
)
printf(p
,q
,r
,s
,t
,u
,v
,w
,x
,y
,z
);
consoftc
.cs_flags
|= CO_POLLING
;
while ((c
=kbd_sgetc(0))==NULL
);
consoftc
.cs_flags
&= ~CO_POLLING
;
default: if (thechar
>= ' ')
case lf
: sput(0, '\r', 1);
sput(0, '^', 1) ; sput(0, 'C', 1) ; sput(0, '\r', 1) ; sput(0, '\n', 1) ;
sput(0, '^', 1) ; sput(0, 'D', 1) ; sput(0, '\r', 1) ; sput(0, '\n', 1) ;
#include "machine/stdarg.h"
dprintf(unsigned flgs
, const char *fmt
, ...)
dprintf(flgs
, fmt
/*, va_alist */)
{ extern unsigned __debug
;
if((flgs
&__debug
) > DPAUSE
) {
__color
= ffs(flgs
&__debug
)+1;
kprintf(fmt
, 1, (struct tty
*)0, ap
);
if (flgs
&DPAUSE
|| nrow
%24 == 23) {
if (nrow
%24 == 23) nrow
= 0;