xref: /csrg-svn/sys/luna68k/stand/cons.c (revision 57082)
1*57082Sakito /*
2*57082Sakito  * Copyright (c) 1992 OMRON Corporation.
3*57082Sakito  * Copyright (c) 1992 The Regents of the University of California.
4*57082Sakito  * All rights reserved.
5*57082Sakito  *
6*57082Sakito  * This code is derived from software contributed to Berkeley by
7*57082Sakito  * OMRON Corporation.
8*57082Sakito  *
9*57082Sakito  * %sccs.include.redist.c%
10*57082Sakito  *
11*57082Sakito  *	@(#)cons.c	7.1 (Berkeley) 12/13/92
12*57082Sakito  */
13*57082Sakito 
14*57082Sakito #include <sys/param.h>
15*57082Sakito #include <sys/systm.h>
16*57082Sakito #include <sys/buf.h>
17*57082Sakito #include <sys/ioctl.h>
18*57082Sakito #include <sys/tty.h>
19*57082Sakito #include <sys/file.h>
20*57082Sakito #include <sys/conf.h>
21*57082Sakito #include <luna68k/luna68k/cons.h>
22*57082Sakito 
23*57082Sakito #define NBMC	1
24*57082Sakito #define	NSIO	1
25*57082Sakito #define	NROM	1
26*57082Sakito 
27*57082Sakito /* XXX - all this could be autoconfig()ed */
28*57082Sakito #include "romvec.h"
29*57082Sakito #if NBMC > 0
30*57082Sakito int bmccnprobe(), bmccninit(), bmccngetc(), bmccnputc();
31*57082Sakito #endif
32*57082Sakito #if NSIO > 0
33*57082Sakito int siocnprobe(), siocninit(), siocngetc(), siocnputc();
34*57082Sakito #endif
35*57082Sakito #if NROM > 0
36*57082Sakito int romcnprobe(), romcninit(), romcngetc(), romcnputc();
37*57082Sakito #endif
38*57082Sakito 
39*57082Sakito struct	consdev constab[] = {
40*57082Sakito #if NBMC > 0
41*57082Sakito 	{ bmccnprobe,	bmccninit,	bmccngetc,	bmccnputc },
42*57082Sakito #endif
43*57082Sakito #if NSIO > 0
44*57082Sakito 	{ siocnprobe,	siocninit,	siocngetc,	siocnputc },
45*57082Sakito #endif
46*57082Sakito #if NROM > 0
47*57082Sakito 	{ romcnprobe,	romcninit,	romcngetc,	romcnputc },
48*57082Sakito #endif
49*57082Sakito 	{ 0 },
50*57082Sakito };
51*57082Sakito /* end XXX */
52*57082Sakito 
53*57082Sakito struct	tty *constty = 0;	/* virtual console output device */
54*57082Sakito struct	consdev *cn_tab;	/* physical console device info */
55*57082Sakito struct	tty *cn_tty;		/* XXX: console tty struct for tprintf */
56*57082Sakito 
57*57082Sakito cninit()
58*57082Sakito {
59*57082Sakito 	register struct consdev *cp;
60*57082Sakito 
61*57082Sakito 	/*
62*57082Sakito 	 * Collect information about all possible consoles
63*57082Sakito 	 * and find the one with highest priority
64*57082Sakito 	 */
65*57082Sakito 	for (cp = constab; cp->cn_probe; cp++) {
66*57082Sakito 		(*cp->cn_probe)(cp);
67*57082Sakito 		if (cp->cn_pri > CN_DEAD &&
68*57082Sakito 		    (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
69*57082Sakito 			cn_tab = cp;
70*57082Sakito 	}
71*57082Sakito 	/*
72*57082Sakito 	 * No console, we can handle it
73*57082Sakito 	 */
74*57082Sakito 	if ((cp = cn_tab) == NULL)
75*57082Sakito 		return;
76*57082Sakito 	/*
77*57082Sakito 	 * Turn on console
78*57082Sakito 	 */
79*57082Sakito 	cn_tty = cp->cn_tp;
80*57082Sakito 	(*cp->cn_init)(cp);
81*57082Sakito }
82*57082Sakito 
83*57082Sakito cngetc()
84*57082Sakito {
85*57082Sakito 	if (cn_tab == NULL)
86*57082Sakito 		return(0);
87*57082Sakito 	return((*cn_tab->cn_getc)(cn_tab->cn_dev));
88*57082Sakito }
89*57082Sakito 
90*57082Sakito cnputc(c)
91*57082Sakito 	register int c;
92*57082Sakito {
93*57082Sakito 	if (cn_tab == NULL)
94*57082Sakito 		return;
95*57082Sakito 	if (c) {
96*57082Sakito 		(*cn_tab->cn_putc)(cn_tab->cn_dev, c);
97*57082Sakito 		if (c == '\n')
98*57082Sakito 			(*cn_tab->cn_putc)(cn_tab->cn_dev, '\r');
99*57082Sakito 	}
100*57082Sakito }
101