]> git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/kd.c
270bf1c61d92b4413c4bad4b2d0dbdbd769000f5
[apple/xnu.git] / pexpert / i386 / kd.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 */
35
36 /*
37 * Olivetti Mach Console driver v0.0
38 * Copyright Ing. C. Olivetti & C. S.p.A. 1988, 1989
39 * All rights reserved.
40 *
41 */
42 /*
43 * Copyright 1988, 1989 by Olivetti Advanced Technology Center, Inc.,
44 * Cupertino, California.
45 *
46 * All Rights Reserved
47 *
48 * Permission to use, copy, modify, and distribute this software and
49 * its documentation for any purpose and without fee is hereby
50 * granted, provided that the above copyright notice appears in all
51 * copies and that both the copyright notice and this permission notice
52 * appear in supporting documentation, and that the name of Olivetti
53 * not be used in advertising or publicity pertaining to distribution
54 * of the software without specific, written prior permission.
55 *
56 * OLIVETTI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
57 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
58 * IN NO EVENT SHALL OLIVETTI BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
59 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
60 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
61 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION
62 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
63 *
64 *
65 * Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
66 *
67 * All Rights Reserved
68 *
69 * Permission to use, copy, modify, and distribute this software and
70 * its documentation for any purpose and without fee is hereby
71 * granted, provided that the above copyright notice appears in all
72 * copies and that both the copyright notice and this permission notice
73 * appear in supporting documentation, and that the name of Intel
74 * not be used in advertising or publicity pertaining to distribution
75 * of the software without specific, written prior permission.
76 *
77 * INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
78 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
79 * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
80 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
81 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
82 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
83 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
84 */
85
86 /* $ Header: $ */
87
88 #include <pexpert/pexpert.h>
89
90 extern void cpu_shutdown(void);
91
92 int cngetc(void);
93 int cnmaygetc(void);
94 void kdreboot(void);
95
96 /*
97 * Common I/O ports.
98 */
99 #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
100 #define K_STATUS 0x64 /* keybd status (read-only) */
101 #define K_CMD 0x64 /* keybd ctlr command (write-only) */
102
103 /*
104 * Bit definitions for K_STATUS port.
105 */
106 #define K_OBUF_FUL 0x01 /* output (from keybd) buffer full */
107 #define K_IBUF_FUL 0x02 /* input (to keybd) buffer full */
108 #define K_SYSFLAG 0x04 /* "System Flag" */
109 #define K_CMD_DATA 0x08 /* 1 = input buf has cmd, 0 = data */
110 #define K_KBD_INHBT 0x10 /* 0 if keyboard inhibited */
111 #define K_XMT_TIMEOUT 0x20 /* Transmit time out */
112 #define K_RCV_TIMEOUT 0x40 /* Receive time out */
113
114 /*
115 * Keyboard controller commands (sent to K_CMD port).
116 */
117 #define K_CMD_READ 0x20 /* read controller command byte */
118 #define K_CMD_WRITE 0x60 /* write controller command byte */
119 #define K_CMD_TEST 0xab /* test interface */
120 #define K_CMD_DUMP 0xac /* diagnostic dump */
121 #define K_CMD_DISBLE 0xad /* disable keyboard */
122 #define K_CMD_ENBLE 0xae /* enable keyboard */
123 #define K_CMD_RDKBD 0xc4 /* read keyboard ID */
124 #define K_CMD_ECHO 0xee /* used for diagnostic testing */
125 #define K_CMD_RESET 0xfe /* issue a system reset */
126
127 /*
128 * cngetc / cnmaygetc
129 *
130 * Get one character using polling, rather than interrupts.
131 * Used by the kernel debugger.
132 */
133
134 int
135 cngetc(void)
136 {
137 char c;
138
139 if ( 0 == (*PE_poll_input)(0, &c) )
140 return ( c );
141 else
142 return ( 0 );
143 }
144
145 int
146 cnmaygetc(void)
147 {
148 char c;
149
150 if ( 0 == (*PE_poll_input)(0, &c) )
151 return ( c );
152 else
153 return ( 0 );
154 }
155
156 /*
157 * kd_sendcmd
158 *
159 * This function sends a command byte to the keyboard command
160 * port, but first waits until the input/output data buffer is
161 * clear before sending the data.
162 *
163 */
164
165 static void
166 kd_sendcmd(unsigned char ch)
167 {
168 while (inb(K_STATUS) & K_IBUF_FUL);
169 outb(K_CMD, ch);
170 }
171
172 /*
173 * kdreboot
174 *
175 * Send a command to the motherboard keyboard controller to
176 * issue a hardware reset.
177 */
178
179 void
180 kdreboot(void)
181 {
182 kd_sendcmd( K_CMD_RESET );
183
184 /*
185 * DRAT. We're still here. Let's try a "CPU shutdown", which consists
186 * of clearing the IDTR and causing an exception. It's in locore.s
187 */
188 cpu_shutdown();
189 /*NOTREACHED*/
190 }