|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
23: *
24: * km.m - kernel keyboard/monitor module, procedural interface.
25: *
26: * HISTORY
27: */
28:
29: #include <sys/param.h>
30: #include <sys/tty.h>
31:
32: #include <dev/i386/cons.h>
33: #include <sys/conf.h>
34: #include <sys/systm.h>
35: #include <sys/uio.h>
36: #include <sys/fcntl.h> /* for kmopen */
37: #include <sys/errno.h>
38: #include <sys/proc.h> /* for kmopen */
39: #include <sys/msgbuf.h>
40: #include <sys/time.h>
41: #include <dev/kmreg_com.h>
42:
43: struct ConsoleSize {
44: unsigned short rows;
45: unsigned short cols;
46: unsigned short pixel_width;
47: unsigned short pixel_height;
48: };
49:
50: /*
51: * 'Global' variables, shared only by this file and conf.c.
52: */
53: extern struct tty cons;
54: struct tty *km_tty[1] = { &cons };
55:
56: /*
57: * 'Global' variables, shared only by this file and kmDevice.m.
58: */
59: int initialized = 0;
60:
61: static int kmoutput(struct tty *tp);
62: static void kmstart(struct tty *tp);
63:
64: extern void KeyboardOpen(void);
65:
66: int kminit()
67: {
68: cons.t_dev = makedev(12, 0);
69: initialized = 1;
70: }
71: /*
72: * cdevsw interface to km driver.
73: */
74: int
75: kmopen(
76: dev_t dev,
77: int flag,
78: int devtype,
79: struct proc *pp)
80: {
81: int rtn;
82: int unit;
83: struct tty *tp;
84: struct winsize *wp;
85: struct ConsoleSize size;
86: int ret;
87:
88: unit = minor(dev);
89: if(unit >= 1)
90: return (ENXIO);
91:
92: tp = (struct tty *)&cons;
93: tp->t_oproc = kmstart;
94: tp->t_param = NULL;
95: tp->t_dev = dev;
96:
97: if ( !(tp->t_state & TS_ISOPEN) ) {
98: tp->t_iflag = TTYDEF_IFLAG;
99: tp->t_oflag = TTYDEF_OFLAG;
100: tp->t_cflag = (CREAD | CS8 | CLOCAL);
101: tp->t_lflag = TTYDEF_LFLAG;
102: tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
103: termioschars(&tp->t_termios);
104: ttsetwater(tp);
105: } else if ((tp->t_state & TS_XCLUDE) && pp->p_ucred->cr_uid != 0)
106: return EBUSY;
107:
108: tp->t_state |= TS_CARR_ON; /* lie and say carrier exists and is on. */
109: ret = ((*linesw[tp->t_line].l_open)(dev, tp));
110: #if FIXME
111: if (ret == 0) {
112: (*basicConsole->GetSize)(basicConsole, &size);
113: wp = &tp->t_winsize;
114: wp->ws_row = size.rows;
115: wp->ws_col = size.cols;
116: wp->ws_xpixel = size.pixel_width;
117: wp->ws_ypixel = size.pixel_height;
118: }
119: KeyboardOpen();
120: #else /* FIXME */
121: wp = &tp->t_winsize;
122: wp->ws_row = 24;
123: wp->ws_col = 80;
124: wp->ws_xpixel = 10;
125: wp->ws_ypixel = 12;
126: #endif /* FIXME */
127:
128: return ret;
129: }
130:
131: int
132: kmclose(
133: dev_t dev,
134: int flag,
135: int mode,
136: struct proc *p)
137: {
138:
139: struct tty *tp;
140:
141: tp = &cons;
142: (*linesw[tp->t_line].l_close)(tp,flag);
143: ttyclose(tp);
144: return (0);
145: }
146:
147: int
148: kmread(
149: dev_t dev,
150: struct uio *uio,
151: int ioflag)
152: {
153: register struct tty *tp;
154:
155: tp = &cons;
156: return ((*linesw[tp->t_line].l_read)(tp, uio, ioflag));
157: }
158:
159: int
160: kmwrite(
161: dev_t dev,
162: struct uio *uio,
163: int ioflag)
164: {
165: register struct tty *tp;
166:
167: tp = &cons;
168: return ((*linesw[tp->t_line].l_write)(tp, uio, ioflag));
169: }
170:
171: int
172: kmioctl(
173: dev_t dev,
174: int cmd,
175: caddr_t data,
176: int flag,
177: struct proc *p)
178: {
179: int error;
180: struct tty *tp = &cons;
181: struct ConsoleSize size;
182: struct winsize *wp;
183:
184: switch (cmd) {
185:
186:
187:
188: case KMIOCSIZE:
189: wp = (struct winsize *)data;
190: wp->ws_row = 24;
191: wp->ws_col = 80;
192: wp->ws_xpixel = 10;
193: wp->ws_ypixel = 12;
194: return 0;
195:
196: case TIOCSWINSZ:
197: /* Prevent changing of console size --
198: * this ensures that login doesn't revert to the
199: * termcap-defined size
200: */
201: return EINVAL;
202:
203: /* Bodge in the CLOCAL flag as the km device is always local */
204: case TIOCSETA:
205: case TIOCSETAW:
206: case TIOCSETAF: {
207: register struct termios *t = (struct termios *)data;
208: t->c_cflag |= CLOCAL;
209: /* No Break */
210: }
211: default:
212: error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
213: if (error >= 0) {
214: return error;
215: }
216: error = ttioctl (tp, cmd, data, flag, p);
217: if (error >= 0) {
218: return error;
219: }
220: else {
221: return ENOTTY;
222: }
223: }
224: }
225:
226: /*
227: * this works early on, after initialize_screen() but before autoconf (and thus
228: * before we have a kmDevice).
229: */
230: int disableConsoleOutput;
231:
232: int
233: kmputc(
234: int c)
235: {
236:
237: if( disableConsoleOutput)
238: return( 0);
239:
240:
241: if(!initialized)
242: return( 0);
243:
244: if(c == '\n') {
245: cnputc('\r');
246: }
247: cnputc(c);
248: return 0;
249: }
250:
251: int
252: kmgetc(
253: dev_t dev)
254: {
255: extern int cnputc(char c);
256: int c;
257:
258: c= cngetc();
259:
260: if (c == '\r') {
261: c = '\n';
262: }
263: cnputc(c);
264: return c;
265: }
266:
267: int
268: kmgetc_silent(
269: dev_t dev)
270: {
271: int c;
272:
273: c= cngetc();
274: if (c == '\r') {
275: c = '\n';
276: }
277: return c;
278: }
279:
280: /*
281: * Callouts from linesw.
282: */
283:
284: #define KM_LOWAT_DELAY ((ns_time_t)1000)
285:
286: static void
287: kmstart(
288: struct tty *tp)
289: {
290: extern int hz;
291: if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
292: goto out;
293: if (tp->t_outq.c_cc == 0)
294: goto out;
295: tp->t_state |= TS_BUSY;
296: if (tp->t_outq.c_cc > tp->t_lowat) {
297: /*
298: * Start immediately.
299: */
300: kmoutput(tp);
301: }
302: else {
303: /*
304: * Wait a bit...
305: */
306: #if 0
307: /* FIXME */
308: timeout(kmoutput, tp, hz);
309: #else
310: kmoutput(tp);
311: #endif
312: }
313: out:
314: ttwwakeup(tp);
315: }
316:
317: static int
318: kmoutput(
319: struct tty *tp)
320: {
321: /*
322: * FIXME - to be grokked...copied from m68k km.c.
323: */
324: char buf[80];
325: char *cp;
326: int cc = -1;
327:
328: extern int hz;
329: while (tp->t_outq.c_cc > 0) {
330: cc = ndqb(&tp->t_outq, 0);
331: if (cc == 0)
332: break;
333: cc = min(cc, sizeof buf);
334: (void) q_to_b(&tp->t_outq, buf, cc);
335: for (cp = buf; cp < &buf[cc]; cp++) {
336: kmputc(*cp & 0x7f);
337: }
338: }
339: if (tp->t_outq.c_cc > 0) {
340: timeout(kmoutput, tp, hz);
341: }
342: tp->t_state &= ~TS_BUSY;
343: ttwwakeup(tp);
344: return 0;
345: }
346: cons_cinput(char ch)
347: {
348: struct tty *tp = &cons;
349:
350: (*linesw[tp->t_line].l_rint) (ch, tp);
351: }
352:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.