]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/km.c
a75e4ea54cf7ee04ba48d075d0880e0d0645f684
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
24 * km.m - kernel keyboard/monitor module, procedural interface.
29 #include <sys/param.h>
32 #include <dev/i386/cons.h>
34 #include <sys/systm.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>
41 #include <dev/kmreg_com.h>
42 #include <pexpert/pexpert.h>
43 #include <pexpert/i386/boot.h>
47 extern void cnputcusr(char);
48 extern int cngetc(void);
51 int kmopen(dev_t dev
, int flag
, int devtype
, struct proc
*pp
);
52 int kmclose(dev_t dev
, int flag
, int mode
, struct proc
*p
);
53 int kmread(dev_t dev
, struct uio
*uio
, int ioflag
);
54 int kmwrite(dev_t dev
, struct uio
*uio
, int ioflag
);
55 int kmioctl(dev_t dev
, int cmd
, caddr_t data
, int flag
, struct proc
*p
);
57 int kmgetc(dev_t dev
);
58 int kmgetc_silent(dev_t dev
);
59 void cons_cinput(char ch
);
62 * 'Global' variables, shared only by this file and conf.c.
64 struct tty
*km_tty
[1] = { &cons
};
67 * this works early on, after initialize_screen() but before autoconf (and thus
68 * before we have a kmDevice).
70 int disableConsoleOutput
;
73 * 'Global' variables, shared only by this file and kmDevice.m.
77 static int kmoutput(struct tty
*tp
);
78 static void kmstart(struct tty
*tp
);
80 extern void KeyboardOpen(void);
85 cons
.t_dev
= makedev(12, 0);
89 * cdevsw interface to km driver.
107 tp
= (struct tty
*)&cons
;
108 tp
->t_oproc
= kmstart
;
112 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
113 tp
->t_iflag
= TTYDEF_IFLAG
;
114 tp
->t_oflag
= TTYDEF_OFLAG
;
115 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
116 tp
->t_lflag
= TTYDEF_LFLAG
;
117 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
118 termioschars(&tp
->t_termios
);
120 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
))
123 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
124 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
128 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
129 * from pexpert/i386/video_console.c
135 PE_initialize_console(0, kPETextScreen
);
137 bzero(&video
, sizeof(video
));
138 PE_current_console(&video
);
139 if( video
.v_display
== VGA_TEXT_MODE
) {
140 wp
->ws_col
= video
.v_width
;
141 wp
->ws_row
= video
.v_height
;
142 } else if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
143 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
144 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
158 __unused
struct proc
*p
)
164 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
175 register struct tty
*tp
;
178 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
187 register struct tty
*tp
;
190 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
202 struct tty
*tp
= &cons
;
210 wp
= (struct winsize
*)data
;
215 /* Prevent changing of console size --
216 * this ensures that login doesn't revert to the
217 * termcap-defined size
221 /* Bodge in the CLOCAL flag as the km device is always local */
225 register struct termios
*t
= (struct termios
*)data
;
226 t
->c_cflag
|= CLOCAL
;
230 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
233 return ttioctl (tp
, cmd
, data
, flag
, p
);
242 if( disableConsoleOutput
)
285 * Callouts from linesw.
288 #define KM_LOWAT_DELAY ((ns_time_t)1000)
294 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
296 if (tp
->t_outq
.c_cc
== 0)
298 tp
->t_state
|= TS_BUSY
;
303 (*linesw
[tp
->t_line
].l_start
)(tp
);
310 boolean_t funnel_state
;
311 struct tty
*tp
= (struct tty
*) arg
;
313 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
315 (void) thread_funnel_set(kernel_flock
, funnel_state
);
324 * FIXME - to be grokked...copied from m68k km.c.
331 while (tp
->t_outq
.c_cc
> 0) {
332 cc
= ndqb(&tp
->t_outq
, 0);
335 cc
= min(cc
, sizeof buf
);
336 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
337 for (cp
= buf
; cp
< &buf
[cc
]; cp
++) {
341 if (tp
->t_outq
.c_cc
> 0) {
342 timeout(kmtimeout
, tp
, hz
);
344 tp
->t_state
&= ~TS_BUSY
;
345 (*linesw
[tp
->t_line
].l_start
)(tp
);
353 struct tty
*tp
= &cons
;
355 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);