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