]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/km.c
a5a6c3f6c80e01d2d1503de4819aa17fe7fd3bb5
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
32 * km.m - kernel keyboard/monitor module, procedural interface.
37 #include <sys/param.h>
40 #include <dev/i386/cons.h>
42 #include <sys/systm.h>
44 #include <sys/fcntl.h> /* for kmopen */
45 #include <sys/errno.h>
46 #include <sys/proc.h> /* for kmopen */
47 #include <sys/msgbuf.h>
49 #include <dev/kmreg_com.h>
50 #include <pexpert/pexpert.h>
54 extern void cnputcusr(char);
55 extern int cngetc(void);
58 int kmopen(dev_t dev
, int flag
, int devtype
, struct proc
*pp
);
59 int kmclose(dev_t dev
, int flag
, int mode
, struct proc
*p
);
60 int kmread(dev_t dev
, struct uio
*uio
, int ioflag
);
61 int kmwrite(dev_t dev
, struct uio
*uio
, int ioflag
);
62 int kmioctl(dev_t dev
, int cmd
, caddr_t data
, int flag
, struct proc
*p
);
64 int kmgetc(dev_t dev
);
65 int kmgetc_silent(dev_t dev
);
66 void cons_cinput(char ch
);
69 * 'Global' variables, shared only by this file and conf.c.
71 struct tty
*km_tty
[1] = { &cons
};
74 * this works early on, after initialize_screen() but before autoconf (and thus
75 * before we have a kmDevice).
77 int disableConsoleOutput
;
80 * 'Global' variables, shared only by this file and kmDevice.m.
84 static int kmoutput(struct tty
*tp
);
85 static void kmstart(struct tty
*tp
);
87 extern void KeyboardOpen(void);
92 cons
.t_dev
= makedev(12, 0);
96 * cdevsw interface to km driver.
102 __unused
int devtype
,
114 tp
= (struct tty
*)&cons
;
115 tp
->t_oproc
= kmstart
;
119 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
120 tp
->t_iflag
= TTYDEF_IFLAG
;
121 tp
->t_oflag
= TTYDEF_OFLAG
;
122 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
123 tp
->t_lflag
= TTYDEF_LFLAG
;
124 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
125 termioschars(&tp
->t_termios
);
127 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
))
130 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
131 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
135 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
136 * from pexpert/i386/video_console.c
142 PE_initialize_console(0, kPETextScreen
);
144 bzero(&video
, sizeof(video
));
145 PE_current_console(&video
);
146 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
147 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
148 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
162 __unused
struct proc
*p
)
168 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
179 register struct tty
*tp
;
182 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
191 register struct tty
*tp
;
194 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
206 struct tty
*tp
= &cons
;
214 wp
= (struct winsize
*)data
;
219 /* Prevent changing of console size --
220 * this ensures that login doesn't revert to the
221 * termcap-defined size
225 /* Bodge in the CLOCAL flag as the km device is always local */
229 register struct termios
*t
= (struct termios
*)data
;
230 t
->c_cflag
|= CLOCAL
;
234 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
237 return ttioctl (tp
, cmd
, data
, flag
, p
);
246 if( disableConsoleOutput
)
289 * Callouts from linesw.
292 #define KM_LOWAT_DELAY ((ns_time_t)1000)
298 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
300 if (tp
->t_outq
.c_cc
== 0)
302 tp
->t_state
|= TS_BUSY
;
307 (*linesw
[tp
->t_line
].l_start
)(tp
);
314 boolean_t funnel_state
;
315 struct tty
*tp
= (struct tty
*) arg
;
317 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
319 (void) thread_funnel_set(kernel_flock
, funnel_state
);
328 * FIXME - to be grokked...copied from m68k km.c.
335 while (tp
->t_outq
.c_cc
> 0) {
336 cc
= ndqb(&tp
->t_outq
, 0);
339 cc
= min(cc
, sizeof buf
);
340 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
341 for (cp
= buf
; cp
< &buf
[cc
]; cp
++) {
345 if (tp
->t_outq
.c_cc
> 0) {
346 timeout(kmtimeout
, tp
, hz
);
348 tp
->t_state
&= ~TS_BUSY
;
349 (*linesw
[tp
->t_line
].l_start
)(tp
);
357 struct tty
*tp
= &cons
;
359 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);