]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/km.c
3078987366c5ad513b858e367d215294e9bfcde6
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
27 * km.m - kernel keyboard/monitor module, procedural interface.
32 #include <sys/param.h>
35 #include <dev/i386/cons.h>
37 #include <sys/systm.h>
39 #include <sys/fcntl.h> /* for kmopen */
40 #include <sys/errno.h>
41 #include <sys/proc.h> /* for kmopen */
42 #include <sys/msgbuf.h>
44 #include <dev/kmreg_com.h>
45 #include <pexpert/pexpert.h>
48 * 'Global' variables, shared only by this file and conf.c.
50 extern struct tty cons
;
51 struct tty
*km_tty
[1] = { &cons
};
54 * this works early on, after initialize_screen() but before autoconf (and thus
55 * before we have a kmDevice).
57 int disableConsoleOutput
;
60 * 'Global' variables, shared only by this file and kmDevice.m.
64 static int kmoutput(struct tty
*tp
);
65 static void kmstart(struct tty
*tp
);
67 extern void KeyboardOpen(void);
71 cons
.t_dev
= makedev(12, 0);
75 * cdevsw interface to km driver.
94 tp
= (struct tty
*)&cons
;
95 tp
->t_oproc
= kmstart
;
99 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
100 tp
->t_iflag
= TTYDEF_IFLAG
;
101 tp
->t_oflag
= TTYDEF_OFLAG
;
102 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
103 tp
->t_lflag
= TTYDEF_LFLAG
;
104 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
105 termioschars(&tp
->t_termios
);
107 } else if ((tp
->t_state
& TS_XCLUDE
) && pp
->p_ucred
->cr_uid
!= 0)
110 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
111 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
115 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
116 * from pexpert/i386/video_console.c
122 PE_initialize_console(0, kPETextScreen
);
124 bzero(&video
, sizeof(video
));
125 PE_current_console(&video
);
126 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
127 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
128 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
148 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
159 register struct tty
*tp
;
162 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
171 register struct tty
*tp
;
174 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
186 struct tty
*tp
= &cons
;
194 wp
= (struct winsize
*)data
;
199 /* Prevent changing of console size --
200 * this ensures that login doesn't revert to the
201 * termcap-defined size
205 /* Bodge in the CLOCAL flag as the km device is always local */
209 register struct termios
*t
= (struct termios
*)data
;
210 t
->c_cflag
|= CLOCAL
;
214 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
218 error
= ttioctl (tp
, cmd
, data
, flag
, p
);
233 if( disableConsoleOutput
)
276 * Callouts from linesw.
279 #define KM_LOWAT_DELAY ((ns_time_t)1000)
286 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
288 if (tp
->t_outq
.c_cc
== 0)
290 tp
->t_state
|= TS_BUSY
;
291 if (tp
->t_outq
.c_cc
> tp
->t_lowat
) {
303 timeout(kmtimeout
, tp
, hz
);
315 boolean_t funnel_state
;
316 struct tty
*tp
= (struct tty
*) arg
;
318 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
320 (void) thread_funnel_set(kernel_flock
, funnel_state
);
329 * 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
;
357 struct tty
*tp
= &cons
;
358 boolean_t funnel_state
;
361 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);