--- Gnu-Mach/device/cons.c 2020/09/02 04:36:57 1.1 +++ Gnu-Mach/device/cons.c 2020/09/02 04:47:50 1.1.1.4 @@ -20,28 +20,20 @@ * Utah $Hdr: cons.c 1.14 94/12/14$ */ -#ifdef MACH_KERNEL +#include +#include #include #include #include -#include -#else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif +#include + +#ifdef MACH_KMSG +#include +#include +#endif /* MACH_KMSG */ -static int cn_inited = 0; +static boolean_t cn_inited = FALSE; static struct consdev *cn_tab = 0; /* physical console device info */ -#ifndef MACH_KERNEL -static struct tty *constty = 0; /* virtual console output device */ -#endif /* * ROM getc/putc primitives. @@ -50,8 +42,8 @@ static struct tty *constty = 0; /* virtu * is enabled. This can be useful to debug (or catch panics from) code early * in the bootstrap procedure. */ -int (*romgetc)() = 0; -void (*romputc)() = 0; +int (*romgetc)(char c) = 0; +void (*romputc)(char c) = 0; #if CONSBUFSIZE > 0 /* @@ -62,16 +54,15 @@ void (*romputc)() = 0; */ static char consbuf[CONSBUFSIZE] = { 0 }; static char *consbp = consbuf; -static int consbufused = 0; -#endif +static boolean_t consbufused = FALSE; +#endif /* CONSBUFSIZE > 0 */ -cninit() +void +cninit(void) { struct consdev *cp; -#ifdef MACH_KERNEL dev_ops_t cn_ops; int x; -#endif if (cn_inited) return; @@ -86,15 +77,15 @@ cninit() (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri)) cn_tab = cp; } + /* * Found a console, initialize it. */ - if (cp = cn_tab) { + if ((cp = cn_tab)) { /* * Initialize as console */ (*cp->cn_init)(cp); -#ifdef MACH_KERNEL /* * Look up its dev_ops pointer in the device table and * place it in the device indirection table. @@ -102,7 +93,6 @@ cninit() if (dev_name_lookup(cp->cn_name, &cn_ops, &x) == FALSE) panic("cninit: dev_name_lookup failed"); dev_set_indirection("console", cn_ops, minor(cp->cn_dev)); -#endif #if CONSBUFSIZE > 0 /* * Now that the console is initialized, dump any chars in @@ -116,108 +106,21 @@ cninit() if (++cbp == &consbuf[CONSBUFSIZE]) cbp = consbuf; } while (cbp != consbp); - consbufused = 0; + consbufused = FALSE; } -#endif - cn_inited = 1; +#endif /* CONSBUFSIZE > 0 */ + cn_inited = TRUE; return; } /* * No console device found, not a problem for BSD, fatal for Mach */ -#ifdef MACH_KERNEL panic("can't find a console device"); -#endif -} - -#ifndef MACH_KERNEL -cnopen(dev, flag) - dev_t dev; -{ - if (cn_tab == NULL) - return(0); - dev = cn_tab->cn_dev; - return ((*cdevsw[major(dev)].d_open)(dev, flag)); -} - -cnclose(dev, flag) - dev_t dev; -{ - if (cn_tab == NULL) - return(0); - dev = cn_tab->cn_dev; - return ((*cdevsw[major(dev)].d_close)(dev, flag)); -} - -cnread(dev, uio) - dev_t dev; - struct uio *uio; -{ - if (cn_tab == NULL) - return(0); - dev = cn_tab->cn_dev; - return ((*cdevsw[major(dev)].d_read)(dev, uio)); -} - -cnwrite(dev, uio) - dev_t dev; - struct uio *uio; -{ - if (cn_tab == NULL) - return(0); - dev = cn_tab->cn_dev; - return ((*cdevsw[major(dev)].d_write)(dev, uio)); -} - -cnioctl(dev, cmd, data, flag) - dev_t dev; - caddr_t data; -{ - if (cn_tab == NULL) - return(0); - /* - * Superuser can always use this to wrest control of console - * output from the "virtual" console. - */ - if (cmd == TIOCCONS && constty) { - if (!suser()) - return(EPERM); - constty = NULL; - return(0); - } - dev = cn_tab->cn_dev; - return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag)); } -cnselect(dev, rw) - dev_t dev; - int rw; -{ - if (cn_tab == NULL) - return(1); - return(ttselect(cn_tab->cn_dev, rw)); -} -#ifndef hp300 -/* - * XXX Should go away when the new CIO MUX driver is in place - */ -#define d_control d_mmap -cncontrol(dev, cmd, data) - dev_t dev; - int cmd; - int data; -{ - if (cn_tab == NULL) - return(0); - dev = cn_tab->cn_dev; - return((*cdevsw[major(dev)].d_control)(dev, cmd, data)); -} -#undef d_control -#endif -#endif - -cngetc() +int +cngetc(void) { if (cn_tab) return ((*cn_tab->cn_getc)(cn_tab->cn_dev, 1)); @@ -226,8 +129,8 @@ cngetc() return (0); } -#ifdef MACH_KERNEL -cnmaygetc() +int +cnmaygetc(void) { if (cn_tab) return((*cn_tab->cn_getc)(cn_tab->cn_dev, 0)); @@ -235,14 +138,28 @@ cnmaygetc() return ((*romgetc)(0)); return (0); } -#endif +void cnputc(c) - int c; + char c; { if (c == 0) return; +#ifdef MACH_KMSG + /* XXX: Assume that All output routines always use cnputc. */ + kmsg_putchar (c); +#endif + +#if defined(MACH_HYP) && 0 + { + /* Also output on hypervisor's emergency console, for + * debugging */ + unsigned char d = c; + hyp_console_write(&d, 1); + } +#endif /* MACH_HYP */ + if (cn_tab) { (*cn_tab->cn_putc)(cn_tab->cn_dev, c); if (c == '\n') @@ -254,14 +171,14 @@ cnputc(c) } #if CONSBUFSIZE > 0 else { - if (consbufused == 0) { + if (consbufused == FALSE) { consbp = consbuf; - consbufused = 1; - bzero(consbuf, CONSBUFSIZE); + consbufused = TRUE; + memset(consbuf, 0, CONSBUFSIZE); } *consbp++ = c; if (consbp >= &consbuf[CONSBUFSIZE]) consbp = consbuf; } -#endif +#endif /* CONSBUFSIZE > 0 */ }