xref: /dragonfly/sys/dev/misc/syscons/scterm-dumb.c (revision c69bf40f)
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  * $FreeBSD: src/sys/dev/syscons/scterm-dumb.c,v 1.2 2000/01/29 15:08:45 peter Exp $
27  * $DragonFly: src/sys/dev/misc/syscons/scterm-dumb.c,v 1.5 2006/07/28 02:17:36 dillon Exp $
28  */
29 
30 #include "opt_syscons.h"
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/consio.h>
36 
37 #include <machine/pc/display.h>
38 
39 #include "syscons.h"
40 #include "sctermvar.h"
41 
42 #ifdef SC_DUMB_TERMINAL
43 
44 /* dumb terminal emulator */
45 
46 static sc_term_init_t	dumb_init;
47 static sc_term_term_t	dumb_term;
48 static sc_term_puts_t	dumb_puts;
49 static sc_term_ioctl_t	dumb_ioctl;
50 static sc_term_clear_t	dumb_clear;
51 static sc_term_input_t	dumb_input;
52 static void		dumb_nop(void);
53 
54 static sc_term_sw_t sc_term_dumb = {
55 	{ NULL, NULL },
56 	"dumb",				/* emulator name */
57 	"dumb terminal",		/* description */
58 	"*",				/* matching renderer */
59 	0,				/* softc size */
60 	0,
61 	dumb_init,
62 	dumb_term,
63 	dumb_puts,
64 	dumb_ioctl,
65 	(sc_term_reset_t *)dumb_nop,
66 	(sc_term_default_attr_t *)dumb_nop,
67 	dumb_clear,
68 	(sc_term_notify_t *)dumb_nop,
69 	dumb_input,
70 };
71 
72 SCTERM_MODULE(dumb, sc_term_dumb);
73 
74 static int
75 dumb_init(scr_stat *scp, void **softc, int code)
76 {
77 	switch (code) {
78 	case SC_TE_COLD_INIT:
79 		++sc_term_dumb.te_refcount;
80 		break;
81 	case SC_TE_WARM_INIT:
82 		break;
83 	}
84 	return 0;
85 }
86 
87 static int
88 dumb_term(scr_stat *scp, void **softc)
89 {
90 	--sc_term_dumb.te_refcount;
91 	return 0;
92 }
93 
94 static void
95 dumb_puts(scr_stat *scp, u_char *buf, int len)
96 {
97 	while (len > 0) {
98 		atomic_add_char(&scp->sc->write_in_progress, 1);
99 		sc_term_gen_print(scp, &buf, &len, SC_NORM_ATTR << 8);
100     		sc_term_gen_scroll(scp, scp->sc->scr_map[0x20],
101 				   SC_NORM_ATTR << 8);
102 		atomic_add_char(&scp->sc->write_in_progress, -1);
103 	}
104 }
105 
106 static int
107 dumb_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
108 	   int flag)
109 {
110 	vid_info_t *vi;
111 
112 	switch (cmd) {
113 	case GIO_ATTR:      	/* get current attributes */
114 		*(int*)data = SC_NORM_ATTR;
115 		return 0;
116 	case CONS_GETINFO:  	/* get current (virtual) console info */
117 		vi = (vid_info_t *)data;
118 		if (vi->size != sizeof(struct vid_info))
119 			return EINVAL;
120 		vi->mv_norm.fore = SC_NORM_ATTR & 0x0f;
121 		vi->mv_norm.back = (SC_NORM_ATTR >> 4) & 0x0f;
122 		vi->mv_rev.fore = SC_NORM_ATTR & 0x0f;
123 		vi->mv_rev.back = (SC_NORM_ATTR >> 4) & 0x0f;
124 		/*
125 		 * The other fields are filled by the upper routine. XXX
126 		 */
127 		return ENOIOCTL;
128 	}
129 	return ENOIOCTL;
130 }
131 
132 static void
133 dumb_clear(scr_stat *scp)
134 {
135 	sc_move_cursor(scp, 0, 0);
136 	sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
137 	mark_all(scp);
138 }
139 
140 static int
141 dumb_input(scr_stat *scp, int c, struct tty *tp)
142 {
143 	return FALSE;
144 }
145 
146 static void
147 dumb_nop(void)
148 {
149 	/* nothing */
150 }
151 
152 #endif /* SC_DUMB_TERMINAL */
153