#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cons_machdep.c,v 1.8 2015/06/15 16:53:17 matt Exp $");
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/cpu.h>
#include <sys/systm.h>
#include <dev/cons.h>
#include <machine/sbdvar.h>
#include <ews4800mips/ews4800mips/cons_machdep.h>
cons_decl(rom_);
struct cons cons;
struct consdev consdev_rom = {
rom_cnprobe,
rom_cninit,
rom_cngetc,
rom_cnputc,
rom_cnpollc,
NULL,
NULL,
NULL,
NODEV,
CN_DEAD
};
void
consinit(void)
{
static int initted;
if (initted)
return;
if (platform.consinit) {
(*platform.consinit)();
initted = 1;
} else
rom_cons_init();
}
void
rom_cons_init(void)
{
cons.type = CONS_ROM;
cn_tab = &consdev_rom;
(*cn_tab->cn_init)(cn_tab);
}
void
rom_cnprobe(struct consdev *cn)
{
cn->cn_pri = CN_INTERNAL;
}
void
rom_cninit(struct consdev *cn)
{
static int initted;
if (initted)
return;
cons.x = X_INIT;
#if 0
cons.y = Y_INIT;
#else
cons.y = 20;
#endif
initted = 1;
}
void
rom_cnputc(dev_t dev, int c)
{
int i;
struct lwp *curlwp_save;
curlwp_save = curlwp;
switch (c) {
default:
ROM_PUTC(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
if (++cons.x == CONS_WIDTH) {
cons.x = X_INIT;
cons.y++;
}
break;
case '\b':
ROM_PUTC(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
cons.x = cons.x == X_INIT ? X_INIT : cons.x - 1;
break;
case '\t':
for (i = cons.x % 8; i < 8; i++) {
ROM_PUTC(cons.x * ROM_FONT_WIDTH,
cons.y * ROM_FONT_HEIGHT, ' ');
if (++cons.x == CONS_WIDTH) {
cons.x = X_INIT;
if (++cons.y == CONS_HEIGHT)
cons.y = Y_INIT;
}
}
break;
case '\r':
ROM_PUTC(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
cons.x = X_INIT;
break;
case '\n':
ROM_PUTC(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT,
'\r');
ROM_PUTC(cons.x * ROM_FONT_WIDTH, cons.y * ROM_FONT_HEIGHT, c);
cons.x = X_INIT;
cons.y++;
break;
}
curlwp = curlwp_save;
if (cons.y == CONS_HEIGHT)
cons.y = Y_INIT;
}
int
rom_cngetc(dev_t dev)
{
int rval;
struct lwp *curlwp_save;
curlwp_save = curlwp;
rval = ROM_GETC();
curlwp = curlwp_save;
return rval;
}
void
rom_cnpollc(dev_t dev, int on)
{
static bool __polling = false;
static int s;
if (on && !__polling) {
s = splhigh();
__polling = true;
} else if (!on && __polling) {
__polling = false;
splx(s);
}
}