]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/km.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
30 * km.m - kernel keyboard/monitor module, procedural interface.
35 #include <sys/param.h>
38 #include <dev/i386/cons.h>
40 #include <sys/systm.h>
42 #include <sys/fcntl.h> /* for kmopen */
43 #include <sys/errno.h>
44 #include <sys/proc.h> /* for kmopen */
45 #include <sys/msgbuf.h>
47 #include <dev/kmreg_com.h>
48 #include <pexpert/pexpert.h>
49 #include <pexpert/i386/boot.h>
53 extern void cnputcusr(char);
54 extern int cngetc(void);
57 int kmopen(dev_t dev
, int flag
, int devtype
, struct proc
*pp
);
58 int kmclose(dev_t dev
, int flag
, int mode
, struct proc
*p
);
59 int kmread(dev_t dev
, struct uio
*uio
, int ioflag
);
60 int kmwrite(dev_t dev
, struct uio
*uio
, int ioflag
);
61 int kmioctl(dev_t dev
, int cmd
, caddr_t data
, int flag
, struct proc
*p
);
63 int kmgetc(dev_t dev
);
64 int kmgetc_silent(dev_t dev
);
65 void cons_cinput(char ch
);
68 * 'Global' variables, shared only by this file and conf.c.
70 struct tty
*km_tty
[1] = { &cons
};
73 * this works early on, after initialize_screen() but before autoconf (and thus
74 * before we have a kmDevice).
76 int disableConsoleOutput
;
79 * 'Global' variables, shared only by this file and kmDevice.m.
83 static int kmoutput(struct tty
*tp
);
84 static void kmstart(struct tty
*tp
);
86 extern void KeyboardOpen(void);
91 cons
.t_dev
= makedev(12, 0);
95 * cdevsw interface to km driver.
101 __unused
int devtype
,
113 tp
= (struct tty
*)&cons
;
114 tp
->t_oproc
= kmstart
;
118 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
119 tp
->t_iflag
= TTYDEF_IFLAG
;
120 tp
->t_oflag
= TTYDEF_OFLAG
;
121 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
122 tp
->t_lflag
= TTYDEF_LFLAG
;
123 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
124 termioschars(&tp
->t_termios
);
126 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
))
129 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
130 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
134 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
135 * from pexpert/i386/video_console.c
141 PE_initialize_console(0, kPETextScreen
);
143 bzero(&video
, sizeof(video
));
144 PE_current_console(&video
);
145 if( video
.v_display
== VGA_TEXT_MODE
) {
146 wp
->ws_col
= video
.v_width
;
147 wp
->ws_row
= video
.v_height
;
148 } else if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
149 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
150 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
164 __unused
struct proc
*p
)
170 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
181 register struct tty
*tp
;
184 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
193 register struct tty
*tp
;
196 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
208 struct tty
*tp
= &cons
;
216 wp
= (struct winsize
*)data
;
221 /* Prevent changing of console size --
222 * this ensures that login doesn't revert to the
223 * termcap-defined size
227 /* Bodge in the CLOCAL flag as the km device is always local */
231 register struct termios
*t
= (struct termios
*)data
;
232 t
->c_cflag
|= CLOCAL
;
236 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
239 return ttioctl (tp
, cmd
, data
, flag
, p
);
248 if( disableConsoleOutput
)
291 * Callouts from linesw.
294 #define KM_LOWAT_DELAY ((ns_time_t)1000)
300 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
302 if (tp
->t_outq
.c_cc
== 0)
304 tp
->t_state
|= TS_BUSY
;
309 (*linesw
[tp
->t_line
].l_start
)(tp
);
316 boolean_t funnel_state
;
317 struct tty
*tp
= (struct tty
*) arg
;
319 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
321 (void) thread_funnel_set(kernel_flock
, funnel_state
);
330 * FIXME - to be grokked...copied from m68k km.c.
337 while (tp
->t_outq
.c_cc
> 0) {
338 cc
= ndqb(&tp
->t_outq
, 0);
341 cc
= min(cc
, sizeof buf
);
342 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
343 for (cp
= buf
; cp
< &buf
[cc
]; cp
++) {
347 if (tp
->t_outq
.c_cc
> 0) {
348 timeout(kmtimeout
, tp
, hz
);
350 tp
->t_state
&= ~TS_BUSY
;
351 (*linesw
[tp
->t_line
].l_start
)(tp
);
359 struct tty
*tp
= &cons
;
361 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);