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 __FBSDID("$FreeBSD$"); 2938a227beSBruce Evans 3038a227beSBruce Evans #include "opt_syscons.h" 3138a227beSBruce Evans 3238a227beSBruce Evans #include <sys/param.h> 3338a227beSBruce Evans #include <sys/systm.h> 3419dcee25SBruce Evans #include <sys/kernel.h> 3519dcee25SBruce Evans #include <sys/module.h> 3638a227beSBruce Evans #include <sys/consio.h> 3738a227beSBruce Evans 38*76a0183eSMateusz Guzik #if defined(__arm__) || defined(__powerpc__) 3938a227beSBruce Evans #include <machine/sc_machdep.h> 4038a227beSBruce Evans #else 4138a227beSBruce Evans #include <machine/pc/display.h> 4238a227beSBruce Evans #endif 4338a227beSBruce Evans 4438a227beSBruce Evans #include <dev/syscons/syscons.h> 4538a227beSBruce Evans #include <dev/syscons/sctermvar.h> 4638a227beSBruce Evans 4738a227beSBruce Evans /* dumb terminal emulator */ 4838a227beSBruce Evans 4938a227beSBruce Evans static sc_term_init_t dumb_init; 5038a227beSBruce Evans static sc_term_term_t dumb_term; 5138a227beSBruce Evans static sc_term_puts_t dumb_puts; 5238a227beSBruce Evans static sc_term_ioctl_t dumb_ioctl; 5338a227beSBruce Evans static sc_term_clear_t dumb_clear; 5438a227beSBruce Evans static sc_term_input_t dumb_input; 5538a227beSBruce Evans static void dumb_nop(void); 5619dcee25SBruce Evans static sc_term_fkeystr_t dumb_fkeystr; 5719dcee25SBruce Evans static sc_term_sync_t dumb_sync; 5838a227beSBruce Evans 5938a227beSBruce Evans static sc_term_sw_t sc_term_dumb = { 6038a227beSBruce Evans { NULL, NULL }, 6138a227beSBruce Evans "dumb", /* emulator name */ 6238a227beSBruce Evans "dumb terminal", /* description */ 6338a227beSBruce Evans "*", /* matching renderer */ 6438a227beSBruce Evans 0, /* softc size */ 6538a227beSBruce Evans 0, 6638a227beSBruce Evans dumb_init, 6738a227beSBruce Evans dumb_term, 6838a227beSBruce Evans dumb_puts, 6938a227beSBruce Evans dumb_ioctl, 7038a227beSBruce Evans (sc_term_reset_t *)dumb_nop, 7138a227beSBruce Evans (sc_term_default_attr_t *)dumb_nop, 7238a227beSBruce Evans dumb_clear, 7338a227beSBruce Evans (sc_term_notify_t *)dumb_nop, 7438a227beSBruce Evans dumb_input, 7519dcee25SBruce Evans dumb_fkeystr, 7619dcee25SBruce Evans dumb_sync, 7738a227beSBruce Evans }; 7838a227beSBruce Evans 7938a227beSBruce Evans SCTERM_MODULE(dumb, sc_term_dumb); 8038a227beSBruce Evans 8138a227beSBruce Evans static int 8238a227beSBruce Evans dumb_init(scr_stat *scp, void **softc, int code) 8338a227beSBruce Evans { 8438a227beSBruce Evans switch (code) { 8538a227beSBruce Evans case SC_TE_COLD_INIT: 8638a227beSBruce Evans ++sc_term_dumb.te_refcount; 8738a227beSBruce Evans break; 8838a227beSBruce Evans case SC_TE_WARM_INIT: 8938a227beSBruce Evans break; 9038a227beSBruce Evans } 9138a227beSBruce Evans return 0; 9238a227beSBruce Evans } 9338a227beSBruce Evans 9438a227beSBruce Evans static int 9538a227beSBruce Evans dumb_term(scr_stat *scp, void **softc) 9638a227beSBruce Evans { 9738a227beSBruce Evans --sc_term_dumb.te_refcount; 9838a227beSBruce Evans return 0; 9938a227beSBruce Evans } 10038a227beSBruce Evans 10138a227beSBruce Evans static void 10238a227beSBruce Evans dumb_puts(scr_stat *scp, u_char *buf, int len) 10338a227beSBruce Evans { 10438a227beSBruce Evans while (len > 0) { 10538a227beSBruce Evans ++scp->sc->write_in_progress; 10638a227beSBruce Evans sc_term_gen_print(scp, &buf, &len, SC_NORM_ATTR << 8); 10738a227beSBruce Evans sc_term_gen_scroll(scp, scp->sc->scr_map[0x20], 10838a227beSBruce Evans SC_NORM_ATTR << 8); 10938a227beSBruce Evans --scp->sc->write_in_progress; 11038a227beSBruce Evans } 11138a227beSBruce Evans } 11238a227beSBruce Evans 11338a227beSBruce Evans static int 11438a227beSBruce Evans dumb_ioctl(scr_stat *scp, struct tty *tp, u_long cmd, caddr_t data, 11519dcee25SBruce Evans struct thread *td) 11638a227beSBruce Evans { 11738a227beSBruce Evans vid_info_t *vi; 11838a227beSBruce Evans 11938a227beSBruce Evans switch (cmd) { 12038a227beSBruce Evans case GIO_ATTR: /* get current attributes */ 12138a227beSBruce Evans *(int*)data = SC_NORM_ATTR; 12238a227beSBruce Evans return 0; 12338a227beSBruce Evans case CONS_GETINFO: /* get current (virtual) console info */ 12438a227beSBruce Evans vi = (vid_info_t *)data; 12538a227beSBruce Evans if (vi->size != sizeof(struct vid_info)) 12638a227beSBruce Evans return EINVAL; 12738a227beSBruce Evans vi->mv_norm.fore = SC_NORM_ATTR & 0x0f; 12838a227beSBruce Evans vi->mv_norm.back = (SC_NORM_ATTR >> 4) & 0x0f; 12938a227beSBruce Evans vi->mv_rev.fore = SC_NORM_ATTR & 0x0f; 13038a227beSBruce Evans vi->mv_rev.back = (SC_NORM_ATTR >> 4) & 0x0f; 13138a227beSBruce Evans /* 13238a227beSBruce Evans * The other fields are filled by the upper routine. XXX 13338a227beSBruce Evans */ 13438a227beSBruce Evans return ENOIOCTL; 13538a227beSBruce Evans } 13638a227beSBruce Evans return ENOIOCTL; 13738a227beSBruce Evans } 13838a227beSBruce Evans 13938a227beSBruce Evans static void 14038a227beSBruce Evans dumb_clear(scr_stat *scp) 14138a227beSBruce Evans { 14238a227beSBruce Evans sc_move_cursor(scp, 0, 0); 14338a227beSBruce Evans sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8); 14438a227beSBruce Evans mark_all(scp); 14538a227beSBruce Evans } 14638a227beSBruce Evans 14738a227beSBruce Evans static int 14838a227beSBruce Evans dumb_input(scr_stat *scp, int c, struct tty *tp) 14938a227beSBruce Evans { 15038a227beSBruce Evans return FALSE; 15138a227beSBruce Evans } 15238a227beSBruce Evans 15319dcee25SBruce Evans static const char * 15419dcee25SBruce Evans dumb_fkeystr(scr_stat *scp, int c) 15519dcee25SBruce Evans { 15619dcee25SBruce Evans return (NULL); 15719dcee25SBruce Evans } 15819dcee25SBruce Evans 15919dcee25SBruce Evans static void 16019dcee25SBruce Evans dumb_sync(scr_stat *scp) 16119dcee25SBruce Evans { 16219dcee25SBruce Evans } 16319dcee25SBruce Evans 16438a227beSBruce Evans static void 16538a227beSBruce Evans dumb_nop(void) 16638a227beSBruce Evans { 16738a227beSBruce Evans /* nothing */ 16838a227beSBruce Evans } 169