]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/syscons/scterm-dumb.c
MFV r346563:
[FreeBSD/FreeBSD.git] / sys / dev / syscons / scterm-dumb.c
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/kernel.h>
35 #include <sys/module.h>
36 #include <sys/consio.h>
37
38 #if defined(__arm__) || defined(__mips__) || \
39         defined(__powerpc__) || defined(__sparc64__)
40 #include <machine/sc_machdep.h>
41 #else
42 #include <machine/pc/display.h>
43 #endif
44
45 #include <dev/syscons/syscons.h>
46 #include <dev/syscons/sctermvar.h>
47
48 /* dumb terminal emulator */
49
50 static sc_term_init_t   dumb_init;
51 static sc_term_term_t   dumb_term;
52 static sc_term_puts_t   dumb_puts;
53 static sc_term_ioctl_t  dumb_ioctl;
54 static sc_term_clear_t  dumb_clear;
55 static sc_term_input_t  dumb_input;
56 static void             dumb_nop(void);
57 static sc_term_fkeystr_t        dumb_fkeystr;
58 static sc_term_sync_t   dumb_sync;
59
60 static sc_term_sw_t sc_term_dumb = {
61         { NULL, NULL },
62         "dumb",                         /* emulator name */
63         "dumb terminal",                /* description */
64         "*",                            /* matching renderer */
65         0,                              /* softc size */
66         0,
67         dumb_init,
68         dumb_term,
69         dumb_puts,
70         dumb_ioctl,
71         (sc_term_reset_t *)dumb_nop,
72         (sc_term_default_attr_t *)dumb_nop,
73         dumb_clear,
74         (sc_term_notify_t *)dumb_nop,
75         dumb_input,
76         dumb_fkeystr,
77         dumb_sync,
78 };
79
80 SCTERM_MODULE(dumb, sc_term_dumb);
81
82 static int
83 dumb_init(scr_stat *scp, void **softc, int code)
84 {
85         switch (code) {
86         case SC_TE_COLD_INIT:
87                 ++sc_term_dumb.te_refcount;
88                 break;
89         case SC_TE_WARM_INIT:
90                 break;
91         }
92         return 0;
93 }
94
95 static int
96 dumb_term(scr_stat *scp, void **softc)
97 {
98         --sc_term_dumb.te_refcount;
99         return 0;
100 }
101
102 static void
103 dumb_puts(scr_stat *scp, u_char *buf, int len)
104 {
105         while (len > 0) {
106                 ++scp->sc->write_in_progress;
107                 sc_term_gen_print(scp, &buf, &len, SC_NORM_ATTR << 8);
108                 sc_term_gen_scroll(scp, scp->sc->scr_map[0x20],
109                                    SC_NORM_ATTR << 8);
110                 --scp->sc->write_in_progress;
111         }
112 }
113
114 static int
115 dumb_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
116            struct thread *td)
117 {
118         vid_info_t *vi;
119
120         switch (cmd) {
121         case GIO_ATTR:          /* get current attributes */
122                 *(int*)data = SC_NORM_ATTR;
123                 return 0;
124         case CONS_GETINFO:      /* get current (virtual) console info */
125                 vi = (vid_info_t *)data;
126                 if (vi->size != sizeof(struct vid_info))
127                         return EINVAL;
128                 vi->mv_norm.fore = SC_NORM_ATTR & 0x0f;
129                 vi->mv_norm.back = (SC_NORM_ATTR >> 4) & 0x0f;
130                 vi->mv_rev.fore = SC_NORM_ATTR & 0x0f;
131                 vi->mv_rev.back = (SC_NORM_ATTR >> 4) & 0x0f;
132                 /*
133                  * The other fields are filled by the upper routine. XXX
134                  */
135                 return ENOIOCTL;
136         }
137         return ENOIOCTL;
138 }
139
140 static void
141 dumb_clear(scr_stat *scp)
142 {
143         sc_move_cursor(scp, 0, 0);
144         sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
145         mark_all(scp);
146 }
147
148 static int
149 dumb_input(scr_stat *scp, int c, struct tty *tp)
150 {
151         return FALSE;
152 }
153
154 static const char *
155 dumb_fkeystr(scr_stat *scp, int c)
156 {
157         return (NULL);
158 }
159
160 static void
161 dumb_sync(scr_stat *scp)
162 {
163 }
164
165 static void
166 dumb_nop(void)
167 {
168         /* nothing */
169 }