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