]>
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>
46 extern void cnputcusr(char);
47 extern int cngetc(void);
50 int kmopen(dev_t dev
, int flag
, int devtype
, struct proc
*pp
);
51 int kmclose(dev_t dev
, int flag
, int mode
, struct proc
*p
);
52 int kmread(dev_t dev
, struct uio
*uio
, int ioflag
);
53 int kmwrite(dev_t dev
, struct uio
*uio
, int ioflag
);
54 int kmioctl(dev_t dev
, int cmd
, caddr_t data
, int flag
, struct proc
*p
);
56 int kmgetc(dev_t dev
);
57 int kmgetc_silent(dev_t dev
);
58 void cons_cinput(char ch
);
61 * 'Global' variables, shared only by this file and conf.c.
63 struct tty
*km_tty
[1] = { &cons
};
66 * this works early on, after initialize_screen() but before autoconf (and thus
67 * before we have a kmDevice).
69 int disableConsoleOutput
;
72 * 'Global' variables, shared only by this file and kmDevice.m.
76 static int kmoutput(struct tty
*tp
);
77 static void kmstart(struct tty
*tp
);
79 extern void KeyboardOpen(void);
84 cons
.t_dev
= makedev(12, 0);
88 * cdevsw interface to km driver.
106 tp
= (struct tty
*)&cons
;
107 tp
->t_oproc
= kmstart
;
111 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
112 tp
->t_iflag
= TTYDEF_IFLAG
;
113 tp
->t_oflag
= TTYDEF_OFLAG
;
114 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
115 tp
->t_lflag
= TTYDEF_LFLAG
;
116 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
117 termioschars(&tp
->t_termios
);
119 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
))
122 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
123 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
127 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
128 * from pexpert/i386/video_console.c
134 PE_initialize_console(0, kPETextScreen
);
136 bzero(&video
, sizeof(video
));
137 PE_current_console(&video
);
138 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
139 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
140 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
154 __unused
struct proc
*p
)
160 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
171 register struct tty
*tp
;
174 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
183 register struct tty
*tp
;
186 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
198 struct tty
*tp
= &cons
;
206 wp
= (struct winsize
*)data
;
211 /* Prevent changing of console size --
212 * this ensures that login doesn't revert to the
213 * termcap-defined size
217 /* Bodge in the CLOCAL flag as the km device is always local */
221 register struct termios
*t
= (struct termios
*)data
;
222 t
->c_cflag
|= CLOCAL
;
226 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
229 return ttioctl (tp
, cmd
, data
, flag
, p
);
238 if( disableConsoleOutput
)
281 * Callouts from linesw.
284 #define KM_LOWAT_DELAY ((ns_time_t)1000)
290 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
292 if (tp
->t_outq
.c_cc
== 0)
294 tp
->t_state
|= TS_BUSY
;
299 (*linesw
[tp
->t_line
].l_start
)(tp
);
306 boolean_t funnel_state
;
307 struct tty
*tp
= (struct tty
*) arg
;
309 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
311 (void) thread_funnel_set(kernel_flock
, funnel_state
);
320 * FIXME - to be grokked...copied from m68k km.c.
327 while (tp
->t_outq
.c_cc
> 0) {
328 cc
= ndqb(&tp
->t_outq
, 0);
331 cc
= min(cc
, sizeof buf
);
332 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
333 for (cp
= buf
; cp
< &buf
[cc
]; cp
++) {
337 if (tp
->t_outq
.c_cc
> 0) {
338 timeout(kmtimeout
, tp
, hz
);
340 tp
->t_state
&= ~TS_BUSY
;
341 (*linesw
[tp
->t_line
].l_start
)(tp
);
349 struct tty
*tp
= &cons
;
351 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);