1 /* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1992 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department and Ralph Campbell. 9 * 10 * %sccs.include.redist.c% 11 * 12 * from: Utah $Hdr: cons.c 1.1 90/07/09$ 13 * 14 * @(#)cons.c 7.5 (Berkeley) 11/15/92 15 */ 16 17 #include <sys/param.h> 18 #include <sys/proc.h> 19 #include <sys/systm.h> 20 #include <sys/buf.h> 21 #include <sys/ioctl.h> 22 #include <sys/tty.h> 23 #include <sys/file.h> 24 #include <sys/conf.h> 25 26 #include <pmax/stand/dec_prom.h> 27 28 /* 29 * Console I/O is redirected to the appropriate device, either a screen and 30 * keyboard or a serial port. 31 */ 32 #include <pmax/pmax/cons.h> 33 34 struct consdev cn_tab = { 35 1, 36 1, 37 NODEV, 38 (struct pmax_fb *)0, 39 (int (*)())0, 40 (int (*)())0, 41 (void (*)())0, 42 (struct tty *)0, 43 }; 44 45 cnopen(dev, flag, mode, p) 46 dev_t dev; 47 int flag, mode; 48 struct proc *p; 49 { 50 if (cn_tab.cn_dev == NODEV) 51 return (0); 52 dev = cn_tab.cn_dev; 53 return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p)); 54 } 55 56 cnclose(dev, flag, mode, p) 57 dev_t dev; 58 int flag, mode; 59 struct proc *p; 60 { 61 if (cn_tab.cn_dev == NODEV) 62 return (0); 63 dev = cn_tab.cn_dev; 64 return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p)); 65 } 66 67 cnread(dev, uio, flag) 68 dev_t dev; 69 struct uio *uio; 70 { 71 if (cn_tab.cn_dev == NODEV) 72 return (0); 73 dev = cn_tab.cn_dev; 74 return ((*cdevsw[major(dev)].d_read)(dev, uio, flag)); 75 } 76 77 cnwrite(dev, uio, flag) 78 dev_t dev; 79 struct uio *uio; 80 { 81 if (cn_tab.cn_dev == NODEV) 82 return (0); 83 dev = cn_tab.cn_dev; 84 return ((*cdevsw[major(dev)].d_write)(dev, uio, flag)); 85 } 86 87 cnioctl(dev, cmd, data, flag, p) 88 dev_t dev; 89 caddr_t data; 90 struct proc *p; 91 { 92 int error; 93 94 if (cn_tab.cn_dev == NODEV) 95 return (0); 96 dev = cn_tab.cn_dev; 97 return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p)); 98 } 99 100 /*ARGSUSED*/ 101 cnselect(dev, rw, p) 102 dev_t dev; 103 int rw; 104 struct proc *p; 105 { 106 if (cn_tab.cn_dev == NODEV) 107 return (1); 108 return (ttselect(cn_tab.cn_dev, rw, p)); 109 } 110 111 /* 112 * Get character from console. 113 */ 114 cngetc() 115 { 116 117 /* check to be sure device has been initialized */ 118 if (cn_tab.cn_dev == NODEV || cn_tab.cn_disabled) 119 return ((*callv->getchar)()); 120 return ((*cn_tab.cn_getc)(cn_tab.cn_dev)); 121 } 122 123 /* 124 * Print a character on console. 125 */ 126 cnputc(c) 127 register int c; 128 { 129 int s; 130 131 if (cn_tab.cn_dev == NODEV || cn_tab.cn_disabled) { 132 s = splhigh(); 133 (*callv->printf)("%c", c); 134 splx(s); 135 } else if (c) { 136 if (c == '\n') 137 (*cn_tab.cn_putc)(cn_tab.cn_dev, '\r'); 138 (*cn_tab.cn_putc)(cn_tab.cn_dev, c); 139 } 140 } 141