summaryrefslogtreecommitdiffstats
path: root/sys/dev/syscons/scterm-dumb.c
blob: 19e421d594a1086a38506d93caa23a73db8ed4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*-
 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer as
 *    the first lines of this file unmodified.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#include "sc.h"
#include "opt_syscons.h"

#if NSC > 0

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/consio.h>

#include <machine/pc/display.h>

#include <dev/syscons/syscons.h>
#include <dev/syscons/sctermvar.h>

#ifdef SC_DUMB_TERMINAL

/* dumb terminal emulator */

static sc_term_init_t	dumb_init;
static sc_term_term_t	dumb_term;
static sc_term_puts_t	dumb_puts;
static sc_term_ioctl_t	dumb_ioctl;
static sc_term_clear_t	dumb_clear;
static sc_term_input_t	dumb_input;
static void		dumb_nop(void);

static sc_term_sw_t sc_term_dumb = {
	{ NULL, NULL },
	"dumb",				/* emulator name */
	"dumb terminal",		/* description */
	"*",				/* matching renderer */
	0,				/* softc size */
	0,
	dumb_init,
	dumb_term,
	dumb_puts,
	dumb_ioctl,
	(sc_term_reset_t *)dumb_nop,
	(sc_term_default_attr_t *)dumb_nop,
	dumb_clear,
	(sc_term_notify_t *)dumb_nop,
	dumb_input,
};

SCTERM_MODULE(dumb, sc_term_dumb);

static int
dumb_init(scr_stat *scp, void **softc, int code)
{
	switch (code) {
	case SC_TE_COLD_INIT:
		++sc_term_dumb.te_refcount;
		break;
	case SC_TE_WARM_INIT:
		break;
	}
	return 0;
}

static int
dumb_term(scr_stat *scp, void **softc)
{
	--sc_term_dumb.te_refcount;
	return 0;
}

static void
dumb_puts(scr_stat *scp, u_char *buf, int len)
{
	while (len > 0) {
		++scp->sc->write_in_progress;
		sc_term_gen_print(scp, &buf, &len, SC_NORM_ATTR << 8);
    		sc_term_gen_scroll(scp, scp->sc->scr_map[0x20],
				   SC_NORM_ATTR << 8);
		--scp->sc->write_in_progress;
	}
}

static int
dumb_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
	   int flag, struct proc *p)
{
	vid_info_t *vi;

	switch (cmd) {
	case GIO_ATTR:      	/* get current attributes */
		*(int*)data = SC_NORM_ATTR;
		return 0;
	case CONS_GETINFO:  	/* get current (virtual) console info */
		vi = (vid_info_t *)data;
		if (vi->size != sizeof(struct vid_info))
			return EINVAL;
		vi->mv_norm.fore = SC_NORM_ATTR & 0x0f;
		vi->mv_norm.back = (SC_NORM_ATTR >> 4) & 0x0f;
		vi->mv_rev.fore = SC_NORM_ATTR & 0x0f;
		vi->mv_rev.back = (SC_NORM_ATTR >> 4) & 0x0f;
		/*
		 * The other fields are filled by the upper routine. XXX
		 */
		return ENOIOCTL;
	}
	return ENOIOCTL;
}

static void
dumb_clear(scr_stat *scp)
{
	sc_move_cursor(scp, 0, 0);
	sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
	mark_all(scp);
}

static int
dumb_input(scr_stat *scp, int c, struct tty *tp)
{
	return FALSE;
}

static void
dumb_nop(void)
{
	/* nothing */
}

#endif /* SC_DUMB_TERMINAL */

#endif /* NSC > 1 */
OpenPOWER on IntegriCloud