]>
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_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>
45 * 'Global' variables, shared only by this file and conf.c.
47 extern struct tty cons
;
48 struct tty
*km_tty
[1] = { &cons
};
51 * this works early on, after initialize_screen() but before autoconf (and thus
52 * before we have a kmDevice).
54 int disableConsoleOutput
;
57 * 'Global' variables, shared only by this file and kmDevice.m.
61 static int kmoutput(struct tty
*tp
);
62 static void kmstart(struct tty
*tp
);
64 extern void KeyboardOpen(void);
68 cons
.t_dev
= makedev(12, 0);
72 * cdevsw interface to km driver.
91 tp
= (struct tty
*)&cons
;
92 tp
->t_oproc
= kmstart
;
96 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
97 tp
->t_iflag
= TTYDEF_IFLAG
;
98 tp
->t_oflag
= TTYDEF_OFLAG
;
99 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
100 tp
->t_lflag
= TTYDEF_LFLAG
;
101 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
102 termioschars(&tp
->t_termios
);
104 } else if ((tp
->t_state
& TS_XCLUDE
) && pp
->p_ucred
->cr_uid
!= 0)
107 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
108 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
112 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
113 * from pexpert/i386/video_console.c
119 PE_initialize_console(0, kPETextScreen
);
121 bzero(&video
, sizeof(video
));
122 PE_current_console(&video
);
123 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
124 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
125 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
145 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
156 register struct tty
*tp
;
159 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
168 register struct tty
*tp
;
171 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
183 struct tty
*tp
= &cons
;
191 wp
= (struct winsize
*)data
;
196 /* Prevent changing of console size --
197 * this ensures that login doesn't revert to the
198 * termcap-defined size
202 /* Bodge in the CLOCAL flag as the km device is always local */
206 register struct termios
*t
= (struct termios
*)data
;
207 t
->c_cflag
|= CLOCAL
;
211 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
215 error
= ttioctl (tp
, cmd
, data
, flag
, p
);
230 if( disableConsoleOutput
)
273 * Callouts from linesw.
276 #define KM_LOWAT_DELAY ((ns_time_t)1000)
283 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
285 if (tp
->t_outq
.c_cc
== 0)
287 tp
->t_state
|= TS_BUSY
;
288 if (tp
->t_outq
.c_cc
> tp
->t_lowat
) {
300 timeout(kmtimeout
, tp
, hz
);
312 boolean_t funnel_state
;
313 struct tty
*tp
= (struct tty
*) arg
;
315 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
317 (void) thread_funnel_set(kernel_flock
, funnel_state
);
326 * FIXME - to be grokked...copied from m68k km.c.
334 while (tp
->t_outq
.c_cc
> 0) {
335 cc
= ndqb(&tp
->t_outq
, 0);
338 cc
= min(cc
, sizeof buf
);
339 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
340 for (cp
= buf
; cp
< &buf
[cc
]; cp
++) {
344 if (tp
->t_outq
.c_cc
> 0) {
345 timeout(kmtimeout
, tp
, hz
);
347 tp
->t_state
&= ~TS_BUSY
;
354 struct tty
*tp
= &cons
;
355 boolean_t funnel_state
;
358 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);