xref: /freebsd/sys/dev/syscons/scterm-dumb.c (revision 38a227be7ac75cc2b55f0afe804c7c2a9975eaa8)
1*38a227beSBruce Evans /*-
2*38a227beSBruce Evans  * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3*38a227beSBruce Evans  * All rights reserved.
4*38a227beSBruce Evans  *
5*38a227beSBruce Evans  * Redistribution and use in source and binary forms, with or without
6*38a227beSBruce Evans  * modification, are permitted provided that the following conditions
7*38a227beSBruce Evans  * are met:
8*38a227beSBruce Evans  * 1. Redistributions of source code must retain the above copyright
9*38a227beSBruce Evans  *    notice, this list of conditions and the following disclaimer as
10*38a227beSBruce Evans  *    the first lines of this file unmodified.
11*38a227beSBruce Evans  * 2. Redistributions in binary form must reproduce the above copyright
12*38a227beSBruce Evans  *    notice, this list of conditions and the following disclaimer in the
13*38a227beSBruce Evans  *    documentation and/or other materials provided with the distribution.
14*38a227beSBruce Evans  *
15*38a227beSBruce Evans  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16*38a227beSBruce Evans  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*38a227beSBruce Evans  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*38a227beSBruce Evans  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19*38a227beSBruce Evans  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*38a227beSBruce Evans  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*38a227beSBruce Evans  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*38a227beSBruce Evans  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*38a227beSBruce Evans  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*38a227beSBruce Evans  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*38a227beSBruce Evans  */
26*38a227beSBruce Evans 
27*38a227beSBruce Evans #include <sys/cdefs.h>
28*38a227beSBruce Evans __FBSDID("$FreeBSD$");
29*38a227beSBruce Evans 
30*38a227beSBruce Evans #include "opt_syscons.h"
31*38a227beSBruce Evans 
32*38a227beSBruce Evans #include <sys/param.h>
33*38a227beSBruce Evans #include <sys/systm.h>
34*38a227beSBruce Evans #include <sys/consio.h>
35*38a227beSBruce Evans 
36*38a227beSBruce Evans #if defined(__sparc64__) || defined(__powerpc__)
37*38a227beSBruce Evans #include <machine/sc_machdep.h>
38*38a227beSBruce Evans #else
39*38a227beSBruce Evans #include <machine/pc/display.h>
40*38a227beSBruce Evans #endif
41*38a227beSBruce Evans 
42*38a227beSBruce Evans #include <dev/syscons/syscons.h>
43*38a227beSBruce Evans #include <dev/syscons/sctermvar.h>
44*38a227beSBruce Evans 
45*38a227beSBruce Evans #ifdef SC_DUMB_TERMINAL
46*38a227beSBruce Evans 
47*38a227beSBruce Evans /* dumb terminal emulator */
48*38a227beSBruce Evans 
49*38a227beSBruce Evans static sc_term_init_t	dumb_init;
50*38a227beSBruce Evans static sc_term_term_t	dumb_term;
51*38a227beSBruce Evans static sc_term_puts_t	dumb_puts;
52*38a227beSBruce Evans static sc_term_ioctl_t	dumb_ioctl;
53*38a227beSBruce Evans static sc_term_clear_t	dumb_clear;
54*38a227beSBruce Evans static sc_term_input_t	dumb_input;
55*38a227beSBruce Evans static void		dumb_nop(void);
56*38a227beSBruce Evans 
57*38a227beSBruce Evans static sc_term_sw_t sc_term_dumb = {
58*38a227beSBruce Evans 	{ NULL, NULL },
59*38a227beSBruce Evans 	"dumb",				/* emulator name */
60*38a227beSBruce Evans 	"dumb terminal",		/* description */
61*38a227beSBruce Evans 	"*",				/* matching renderer */
62*38a227beSBruce Evans 	0,				/* softc size */
63*38a227beSBruce Evans 	0,
64*38a227beSBruce Evans 	dumb_init,
65*38a227beSBruce Evans 	dumb_term,
66*38a227beSBruce Evans 	dumb_puts,
67*38a227beSBruce Evans 	dumb_ioctl,
68*38a227beSBruce Evans 	(sc_term_reset_t *)dumb_nop,
69*38a227beSBruce Evans 	(sc_term_default_attr_t *)dumb_nop,
70*38a227beSBruce Evans 	dumb_clear,
71*38a227beSBruce Evans 	(sc_term_notify_t *)dumb_nop,
72*38a227beSBruce Evans 	dumb_input,
73*38a227beSBruce Evans };
74*38a227beSBruce Evans 
75*38a227beSBruce Evans SCTERM_MODULE(dumb, sc_term_dumb);
76*38a227beSBruce Evans 
77*38a227beSBruce Evans static int
78*38a227beSBruce Evans dumb_init(scr_stat *scp, void **softc, int code)
79*38a227beSBruce Evans {
80*38a227beSBruce Evans 	switch (code) {
81*38a227beSBruce Evans 	case SC_TE_COLD_INIT:
82*38a227beSBruce Evans 		++sc_term_dumb.te_refcount;
83*38a227beSBruce Evans 		break;
84*38a227beSBruce Evans 	case SC_TE_WARM_INIT:
85*38a227beSBruce Evans 		break;
86*38a227beSBruce Evans 	}
87*38a227beSBruce Evans 	return 0;
88*38a227beSBruce Evans }
89*38a227beSBruce Evans 
90*38a227beSBruce Evans static int
91*38a227beSBruce Evans dumb_term(scr_stat *scp, void **softc)
92*38a227beSBruce Evans {
93*38a227beSBruce Evans 	--sc_term_dumb.te_refcount;
94*38a227beSBruce Evans 	return 0;
95*38a227beSBruce Evans }
96*38a227beSBruce Evans 
97*38a227beSBruce Evans static void
98*38a227beSBruce Evans dumb_puts(scr_stat *scp, u_char *buf, int len)
99*38a227beSBruce Evans {
100*38a227beSBruce Evans 	while (len > 0) {
101*38a227beSBruce Evans 		++scp->sc->write_in_progress;
102*38a227beSBruce Evans 		sc_term_gen_print(scp, &buf, &len, SC_NORM_ATTR << 8);
103*38a227beSBruce Evans     		sc_term_gen_scroll(scp, scp->sc->scr_map[0x20],
104*38a227beSBruce Evans 				   SC_NORM_ATTR << 8);
105*38a227beSBruce Evans 		--scp->sc->write_in_progress;
106*38a227beSBruce Evans 	}
107*38a227beSBruce Evans }
108*38a227beSBruce Evans 
109*38a227beSBruce Evans static int
110*38a227beSBruce Evans dumb_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
111*38a227beSBruce Evans 	   int flag, struct proc *p)
112*38a227beSBruce Evans {
113*38a227beSBruce Evans 	vid_info_t *vi;
114*38a227beSBruce Evans 
115*38a227beSBruce Evans 	switch (cmd) {
116*38a227beSBruce Evans 	case GIO_ATTR:      	/* get current attributes */
117*38a227beSBruce Evans 		*(int*)data = SC_NORM_ATTR;
118*38a227beSBruce Evans 		return 0;
119*38a227beSBruce Evans 	case CONS_GETINFO:  	/* get current (virtual) console info */
120*38a227beSBruce Evans 		vi = (vid_info_t *)data;
121*38a227beSBruce Evans 		if (vi->size != sizeof(struct vid_info))
122*38a227beSBruce Evans 			return EINVAL;
123*38a227beSBruce Evans 		vi->mv_norm.fore = SC_NORM_ATTR & 0x0f;
124*38a227beSBruce Evans 		vi->mv_norm.back = (SC_NORM_ATTR >> 4) & 0x0f;
125*38a227beSBruce Evans 		vi->mv_rev.fore = SC_NORM_ATTR & 0x0f;
126*38a227beSBruce Evans 		vi->mv_rev.back = (SC_NORM_ATTR >> 4) & 0x0f;
127*38a227beSBruce Evans 		/*
128*38a227beSBruce Evans 		 * The other fields are filled by the upper routine. XXX
129*38a227beSBruce Evans 		 */
130*38a227beSBruce Evans 		return ENOIOCTL;
131*38a227beSBruce Evans 	}
132*38a227beSBruce Evans 	return ENOIOCTL;
133*38a227beSBruce Evans }
134*38a227beSBruce Evans 
135*38a227beSBruce Evans static void
136*38a227beSBruce Evans dumb_clear(scr_stat *scp)
137*38a227beSBruce Evans {
138*38a227beSBruce Evans 	sc_move_cursor(scp, 0, 0);
139*38a227beSBruce Evans 	sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
140*38a227beSBruce Evans 	mark_all(scp);
141*38a227beSBruce Evans }
142*38a227beSBruce Evans 
143*38a227beSBruce Evans static int
144*38a227beSBruce Evans dumb_input(scr_stat *scp, int c, struct tty *tp)
145*38a227beSBruce Evans {
146*38a227beSBruce Evans 	return FALSE;
147*38a227beSBruce Evans }
148*38a227beSBruce Evans 
149*38a227beSBruce Evans static void
150*38a227beSBruce Evans dumb_nop(void)
151*38a227beSBruce Evans {
152*38a227beSBruce Evans 	/* nothing */
153*38a227beSBruce Evans }
154*38a227beSBruce Evans 
155*38a227beSBruce Evans #endif /* SC_DUMB_TERMINAL */
156