138a227beSBruce Evans /*-
238a227beSBruce Evans * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
338a227beSBruce Evans * All rights reserved.
438a227beSBruce Evans *
538a227beSBruce Evans * Redistribution and use in source and binary forms, with or without
638a227beSBruce Evans * modification, are permitted provided that the following conditions
738a227beSBruce Evans * are met:
838a227beSBruce Evans * 1. Redistributions of source code must retain the above copyright
938a227beSBruce Evans * notice, this list of conditions and the following disclaimer as
1038a227beSBruce Evans * the first lines of this file unmodified.
1138a227beSBruce Evans * 2. Redistributions in binary form must reproduce the above copyright
1238a227beSBruce Evans * notice, this list of conditions and the following disclaimer in the
1338a227beSBruce Evans * documentation and/or other materials provided with the distribution.
1438a227beSBruce Evans *
1538a227beSBruce Evans * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1638a227beSBruce Evans * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1738a227beSBruce Evans * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1838a227beSBruce Evans * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1938a227beSBruce Evans * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2038a227beSBruce Evans * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2138a227beSBruce Evans * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2238a227beSBruce Evans * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2338a227beSBruce Evans * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2438a227beSBruce Evans * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2538a227beSBruce Evans */
2638a227beSBruce Evans
2738a227beSBruce Evans #include <sys/cdefs.h>
2838a227beSBruce Evans #include "opt_syscons.h"
2938a227beSBruce Evans
3038a227beSBruce Evans #include <sys/param.h>
3138a227beSBruce Evans #include <sys/systm.h>
3219dcee25SBruce Evans #include <sys/kernel.h>
3319dcee25SBruce Evans #include <sys/module.h>
3438a227beSBruce Evans #include <sys/consio.h>
3538a227beSBruce Evans
36*76a0183eSMateusz Guzik #if defined(__arm__) || defined(__powerpc__)
3738a227beSBruce Evans #include <machine/sc_machdep.h>
3838a227beSBruce Evans #else
3938a227beSBruce Evans #include <machine/pc/display.h>
4038a227beSBruce Evans #endif
4138a227beSBruce Evans
4238a227beSBruce Evans #include <dev/syscons/syscons.h>
4338a227beSBruce Evans #include <dev/syscons/sctermvar.h>
4438a227beSBruce Evans
4538a227beSBruce Evans /* dumb terminal emulator */
4638a227beSBruce Evans
4738a227beSBruce Evans static sc_term_init_t dumb_init;
4838a227beSBruce Evans static sc_term_term_t dumb_term;
4938a227beSBruce Evans static sc_term_puts_t dumb_puts;
5038a227beSBruce Evans static sc_term_ioctl_t dumb_ioctl;
5138a227beSBruce Evans static sc_term_clear_t dumb_clear;
5238a227beSBruce Evans static sc_term_input_t dumb_input;
5338a227beSBruce Evans static void dumb_nop(void);
5419dcee25SBruce Evans static sc_term_fkeystr_t dumb_fkeystr;
5519dcee25SBruce Evans static sc_term_sync_t dumb_sync;
5638a227beSBruce Evans
5738a227beSBruce Evans static sc_term_sw_t sc_term_dumb = {
5838a227beSBruce Evans { NULL, NULL },
5938a227beSBruce Evans "dumb", /* emulator name */
6038a227beSBruce Evans "dumb terminal", /* description */
6138a227beSBruce Evans "*", /* matching renderer */
6238a227beSBruce Evans 0, /* softc size */
6338a227beSBruce Evans 0,
6438a227beSBruce Evans dumb_init,
6538a227beSBruce Evans dumb_term,
6638a227beSBruce Evans dumb_puts,
6738a227beSBruce Evans dumb_ioctl,
6838a227beSBruce Evans (sc_term_reset_t *)dumb_nop,
6938a227beSBruce Evans (sc_term_default_attr_t *)dumb_nop,
7038a227beSBruce Evans dumb_clear,
7138a227beSBruce Evans (sc_term_notify_t *)dumb_nop,
7238a227beSBruce Evans dumb_input,
7319dcee25SBruce Evans dumb_fkeystr,
7419dcee25SBruce Evans dumb_sync,
7538a227beSBruce Evans };
7638a227beSBruce Evans
7738a227beSBruce Evans SCTERM_MODULE(dumb, sc_term_dumb);
7838a227beSBruce Evans
7938a227beSBruce Evans static int
dumb_init(scr_stat * scp,void ** softc,int code)8038a227beSBruce Evans dumb_init(scr_stat *scp, void **softc, int code)
8138a227beSBruce Evans {
8238a227beSBruce Evans switch (code) {
8338a227beSBruce Evans case SC_TE_COLD_INIT:
8438a227beSBruce Evans ++sc_term_dumb.te_refcount;
8538a227beSBruce Evans break;
8638a227beSBruce Evans case SC_TE_WARM_INIT:
8738a227beSBruce Evans break;
8838a227beSBruce Evans }
8938a227beSBruce Evans return 0;
9038a227beSBruce Evans }
9138a227beSBruce Evans
9238a227beSBruce Evans static int
dumb_term(scr_stat * scp,void ** softc)9338a227beSBruce Evans dumb_term(scr_stat *scp, void **softc)
9438a227beSBruce Evans {
9538a227beSBruce Evans --sc_term_dumb.te_refcount;
9638a227beSBruce Evans return 0;
9738a227beSBruce Evans }
9838a227beSBruce Evans
9938a227beSBruce Evans static void
dumb_puts(scr_stat * scp,u_char * buf,int len)10038a227beSBruce Evans dumb_puts(scr_stat *scp, u_char *buf, int len)
10138a227beSBruce Evans {
10238a227beSBruce Evans while (len > 0) {
10338a227beSBruce Evans ++scp->sc->write_in_progress;
10438a227beSBruce Evans sc_term_gen_print(scp, &buf, &len, SC_NORM_ATTR << 8);
10538a227beSBruce Evans sc_term_gen_scroll(scp, scp->sc->scr_map[0x20],
10638a227beSBruce Evans SC_NORM_ATTR << 8);
10738a227beSBruce Evans --scp->sc->write_in_progress;
10838a227beSBruce Evans }
10938a227beSBruce Evans }
11038a227beSBruce Evans
11138a227beSBruce Evans static int
dumb_ioctl(scr_stat * scp,struct tty * tp,u_long cmd,caddr_t data,struct thread * td)11238a227beSBruce Evans dumb_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data,
11319dcee25SBruce Evans struct thread *td)
11438a227beSBruce Evans {
11538a227beSBruce Evans vid_info_t *vi;
11638a227beSBruce Evans
11738a227beSBruce Evans switch (cmd) {
11838a227beSBruce Evans case GIO_ATTR: /* get current attributes */
11938a227beSBruce Evans *(int*)data = SC_NORM_ATTR;
12038a227beSBruce Evans return 0;
12138a227beSBruce Evans case CONS_GETINFO: /* get current (virtual) console info */
12238a227beSBruce Evans vi = (vid_info_t *)data;
12338a227beSBruce Evans if (vi->size != sizeof(struct vid_info))
12438a227beSBruce Evans return EINVAL;
12538a227beSBruce Evans vi->mv_norm.fore = SC_NORM_ATTR & 0x0f;
12638a227beSBruce Evans vi->mv_norm.back = (SC_NORM_ATTR >> 4) & 0x0f;
12738a227beSBruce Evans vi->mv_rev.fore = SC_NORM_ATTR & 0x0f;
12838a227beSBruce Evans vi->mv_rev.back = (SC_NORM_ATTR >> 4) & 0x0f;
12938a227beSBruce Evans /*
13038a227beSBruce Evans * The other fields are filled by the upper routine. XXX
13138a227beSBruce Evans */
13238a227beSBruce Evans return ENOIOCTL;
13338a227beSBruce Evans }
13438a227beSBruce Evans return ENOIOCTL;
13538a227beSBruce Evans }
13638a227beSBruce Evans
13738a227beSBruce Evans static void
dumb_clear(scr_stat * scp)13838a227beSBruce Evans dumb_clear(scr_stat *scp)
13938a227beSBruce Evans {
14038a227beSBruce Evans sc_move_cursor(scp, 0, 0);
14138a227beSBruce Evans sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
14238a227beSBruce Evans mark_all(scp);
14338a227beSBruce Evans }
14438a227beSBruce Evans
14538a227beSBruce Evans static int
dumb_input(scr_stat * scp,int c,struct tty * tp)14638a227beSBruce Evans dumb_input(scr_stat *scp, int c, struct tty *tp)
14738a227beSBruce Evans {
14838a227beSBruce Evans return FALSE;
14938a227beSBruce Evans }
15038a227beSBruce Evans
15119dcee25SBruce Evans static const char *
dumb_fkeystr(scr_stat * scp,int c)15219dcee25SBruce Evans dumb_fkeystr(scr_stat *scp, int c)
15319dcee25SBruce Evans {
15419dcee25SBruce Evans return (NULL);
15519dcee25SBruce Evans }
15619dcee25SBruce Evans
15719dcee25SBruce Evans static void
dumb_sync(scr_stat * scp)15819dcee25SBruce Evans dumb_sync(scr_stat *scp)
15919dcee25SBruce Evans {
16019dcee25SBruce Evans }
16119dcee25SBruce Evans
16238a227beSBruce Evans static void
dumb_nop(void)16338a227beSBruce Evans dumb_nop(void)
16438a227beSBruce Evans {
16538a227beSBruce Evans /* nothing */
16638a227beSBruce Evans }
167