Specifications.
[pintos-anon] / specs / kbd / scancodes-10.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4  <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
5  <TITLE>Keyboard scancodes: The AT keyboard controller</TITLE>
6  <LINK HREF="scancodes-11.html" REL=next>
7  <LINK HREF="scancodes-9.html" REL=previous>
8  <LINK HREF="scancodes.html#toc10" REL=contents>
9 </HEAD>
10 <BODY>
11 <A HREF="scancodes-11.html">Next</A>
12 <A HREF="scancodes-9.html">Previous</A>
13 <A HREF="scancodes.html#toc10">Contents</A>
14 <HR>
15 <H2><A NAME="s10">10. The AT keyboard controller</A></H2>
16
17 <P>A user program can talk to the keyboard controller on the motherboard.
18 The keyboard controller can again talk to the keyboard.
19 <P>When a key is pressed the keyboard sends the corresponding
20 keyboard scancode to the keyboard controller, and the keyboard controller
21 translates that and interrupts the CPU, allowing the CPU to read the result.
22 <P>More detailed: when a key is pressed, the keyboard sends
23 a start bit (low), followed by 8 data bits for the keyboard scancode
24 of the key (least significant first), followed by an odd parity bit,
25 followed by a stop bit (high).
26 The keyboard controller reads the data and checks the parity.
27 If incorrect, retransmission is requested. If incorrect again
28 a parity error is reported.
29 If the time between request to send and start of transmission is greater
30 than 15 ms, or if the eleven bits are not received within 2ms,
31 a timeout is reported.
32 In both cases (parity error or timeout), the data byte is set to 0xff.
33 <P>The keyboard controller has three 8-bit registers involved in
34 communication with the CPU: its input buffer, that can be written
35 by the CPU by writing port 0x60 or port 0x64; its output buffer,
36 that can be read by the CPU by reading from port 0x60; and the
37 status register, that can be read by the CPU by reading from port 0x64.
38 <P>If the CPU writes to port 0x64, the byte is interpreted as a command byte.
39 If the CPU writes to port 0x60, the byte is interpreted as a data byte.
40 <P>The keyboard controller has two 8-bit I/O ports involved in
41 communication with the keyboard: the
42 <A HREF="#inputport">input port</A> P1 (receiving input from the keyboard)
43 and the 
44 <A HREF="#outputport">output port</A> P2 (for sending output
45 to the keyboard).
46 <P>
47 <H2><A NAME="ss10.1">10.1 The keyboard controller status register</A>
48 </H2>
49
50 <P>The keyboard controller has an 8-bit status register.
51 It can be inspected by the CPU by reading port 0x64.
52 <P>(Typically, it has the value 0x14: keyboard not locked, self-test completed.)
53 <P>
54 <CENTER><TABLE BORDER><TR><TD>
55 <A HREF="#kcPARE">PARE</A> </TD><TD>
56 <A HREF="#kcTIM">TIM</A> </TD><TD>
57 <A HREF="#kcAUXB">AUXB</A> </TD><TD>
58 <A HREF="#kcKEYL">KEYL</A> </TD><TD>
59 <A HREF="#kcCD">C/D</A> </TD><TD>
60 <A HREF="#kcSYSF">SYSF</A> </TD><TD>
61 <A HREF="#kcINPB">INPB</A> </TD><TD>
62 <A HREF="#kcOUTB">OUTB</A> </TD></TR><TR><TD>
63
64 </TD></TR></TABLE></CENTER>
65 <P><I>Bit 7: 
66 <A NAME="kcPARE"></A> Parity error</I>
67 <P>
68 <BLOCKQUOTE>
69 0: OK.
70 1: Parity error with last byte. 
71 </BLOCKQUOTE>
72 <P><I>Bit 6: 
73 <A NAME="kcTIM"></A> Timeout</I>
74 <P>
75 <BLOCKQUOTE>
76 0: OK.
77 1: Timeout.
78 On PS/2 systems: General timeout.
79 On AT systems: Timeout on transmission from keyboard to keyboard controller.
80 Possibly parity error (in which case both bits 6 and 7 are set).
81 </BLOCKQUOTE>
82 <P><I>Bit 5: 
83 <A NAME="kcAUXB"></A> Auxiliary output buffer full</I>
84 <P>
85 <BLOCKQUOTE>
86 On PS/2 systems:
87 Bit 0 tells whether a read from port 0x60 will be valid.
88 If it is valid, this bit 5 tells what data will be read from port 0x60.
89 0: Keyboard data. 1: Mouse data.
90 <P>On AT systems:
91 0: OK.
92 1: Timeout on transmission from keyboard controller to keyboard.
93 This may indicate that no keyboard is present.
94 </BLOCKQUOTE>
95 <P><I>Bit 4: 
96 <A NAME="kcKEYL"></A> Keyboard lock</I>
97 <P>
98 <BLOCKQUOTE>
99 0: Locked.
100 1: Not locked.
101 </BLOCKQUOTE>
102 <P><I>Bit 3: 
103 <A NAME="kcCD"></A> Command/Data</I>
104 <P>
105 <BLOCKQUOTE>
106 0: Last write to input buffer was data (written via port 0x60).
107 1: Last write to input buffer was a command (written via port 0x64).
108 (This bit is also referred to as Address Line A2.)
109 </BLOCKQUOTE>
110 <P><I>Bit 2: 
111 <A NAME="kcSYSF"></A> System flag</I>
112 <P>
113 <BLOCKQUOTE>
114 Set to 0 after power on reset.
115 Set to 1 after successful completion of the keyboard controller self-test
116 (Basic Assurance Test, BAT).
117 Can also be set by command (see 
118 <A HREF="#kccb2">below</A>).
119 </BLOCKQUOTE>
120 <P><I>Bit 1: 
121 <A NAME="kcINPB"></A> Input buffer status</I>
122 <P>
123 <BLOCKQUOTE>
124 0: Input buffer empty, can be written.
125 1: Input buffer full, don't write yet.
126 </BLOCKQUOTE>
127 <P><I>Bit 0: 
128 <A NAME="kcOUTB"></A> Output buffer status</I>
129 <P>
130 <BLOCKQUOTE>
131 0: Output buffer empty, don't read yet.
132 1: Output buffer full, can be read.
133 (In the PS/2 situation bit 5 tells whether the available data is
134 from keyboard or mouse.)
135 This bit is cleared when port 0x60 is read.
136 </BLOCKQUOTE>
137 <P>
138 <H2><A NAME="commandbyte"></A> <A NAME="ss10.2">10.2 The keyboard controller command byte</A>
139 </H2>
140
141 <P>The keyboard controller is provided with some RAM, for example 32 bytes,
142 that can be accessed by the CPU. The most important part of this RAM is
143 byte 0, the Controller Command Byte (CCB). It can be read/written by
144 writing 0x20/0x60 to port 0x64 and then reading/writing a data byte
145 from/to port 0x60.
146 <P>This byte has the following layout.
147 <P>
148 <CENTER><TABLE BORDER><TR><TD>
149 <A HREF="#kccb7">0</A> </TD><TD>
150 <A HREF="#kccb6">XLATE</A> </TD><TD>
151 <A HREF="#kccb5">ME</A> </TD><TD>
152 <A HREF="#kccb4">KE</A> </TD><TD>
153 <A HREF="#kccb3">IGNLK</A> </TD><TD>
154 <A HREF="#kccb2">SYSF</A> </TD><TD>
155 <A HREF="#kccb1">MIE</A> </TD><TD>
156 <A HREF="#kccb0">KIE</A> </TD></TR><TR><TD>
157
158 </TD></TR></TABLE></CENTER>
159 <P><I>Bit 7: 
160 <A NAME="kccb7"></A> Unused</I>
161 <P>
162 <BLOCKQUOTE>
163 Always 0.
164 </BLOCKQUOTE>
165 <P><I>Bit 6: 
166 <A NAME="kccb6"></A> Translate</I>
167 <P>
168 <BLOCKQUOTE>
169 0: No translation.
170 1: Translate keyboard scancodes, using the
171 <A HREF="scancodes-9.html#translationtable">translation table</A> given above.
172 MCA type 2 controllers cannot set this bit to 1. In this case
173 scan code conversion is set using keyboard command 0xf0 to port 0x60.
174 </BLOCKQUOTE>
175 <P><I>Bit 5: 
176 <A NAME="kccb5"></A> Mouse enable</I>
177 <P>
178 <BLOCKQUOTE>
179 On an EISA or PS/2 system: 0: Enable mouse. 1: Disable mouse
180 by driving the clock line low.
181 On an ISA system: "PC Mode": 0: use 11-bit codes, check parity and do
182 scan conversion.
183 1: use 8086 codes, don't check parity and don't do scan conversion.
184 </BLOCKQUOTE>
185 <P><I>Bit 4: 
186 <A NAME="kccb4"></A> Keyboard enable</I>
187 <P>
188 <BLOCKQUOTE>
189 0: Enable keyboard. 1: Disable keyboard
190 by driving the clock line low.
191 </BLOCKQUOTE>
192 <P><I>Bit 3: 
193 <A NAME="kccb3"></A> Ignore keyboard lock</I>
194 <P>
195 <BLOCKQUOTE>
196 For PS/2: Unused, always 0.
197 For AT:
198 0: No action. 1: Force 
199 <A HREF="#kcKEYL">bit 4</A> of the status register
200 to 1, "not locked". This is used for keyboard testing after power on.
201 Maybe only on older motherboards.
202 </BLOCKQUOTE>
203 <P><I>Bit 2: 
204 <A NAME="kccb2"></A> System flag</I>
205 <P>
206 <BLOCKQUOTE>
207 This bit is shown in 
208 <A HREF="#kcSYSF">bit 2</A> of the status register.
209 A "cold reboot" is one with this bit set to zero.
210 A "warm reboot" is one with this bit set to one (BAT already completed).
211 This will influence the tests and initializations done by the POST.
212 </BLOCKQUOTE>
213 <P><I>Bit 1: 
214 <A NAME="kccb1"></A> Mouse interrupt enable</I>
215 <P>
216 <BLOCKQUOTE>
217 On an ISA system: unused, always 0. On an EISA or PS/2 system:
218 0: Do not use mouse interrupts.
219 1: Send interrupt request IRQ12 when the mouse output buffer is full.
220 </BLOCKQUOTE>
221 <P><I>Bit 0: 
222 <A NAME="kccb0"></A> Keyboard interrupt enable</I>
223 <P>
224 <BLOCKQUOTE>
225 0: Do not use keyboard interrupts.
226 1: Send interrupt request IRQ1 when the keyboard output buffer is full.
227 <P>When no interrupts are used, the CPU has to poll bits 0 (and 5)
228 of the status register.
229 </BLOCKQUOTE>
230 <P>
231 <H2><A NAME="ss10.3">10.3 Keyboard controller commands</A>
232 </H2>
233
234 <P>The CPU can command the keyboard controller by writing port 0x64.
235 Useful, generally available, keyboard commands are:
236 <P>
237 <P>
238 <CENTER><TABLE BORDER><TR><TD>
239 <B>
240 <A HREF="#kcc20">20</A></B> </TD><TD> Read keyboard controller command byte </TD></TR><TR><TD>
241 <B>
242 <A HREF="#kcc60">60</A></B> </TD><TD> Write keyboard controller command byte </TD></TR><TR><TD>
243 <B>
244 <A HREF="#kccaa">aa</A></B> </TD><TD> Self test </TD></TR><TR><TD>
245 <B>
246 <A HREF="#kccab">ab</A></B> </TD><TD> Interface test </TD></TR><TR><TD>
247 <B>
248 <A HREF="#kccad">ad</A></B> </TD><TD> Disable keyboard </TD></TR><TR><TD>
249 <B>
250 <A HREF="#kccae">ae</A></B> </TD><TD> Enable keyboard </TD></TR><TR><TD>
251 <B>
252 <A HREF="#kccc0">c0</A></B> </TD><TD> Read input port </TD></TR><TR><TD>
253 <B>
254 <A HREF="#kccd0">d0</A></B> </TD><TD> Read output port </TD></TR><TR><TD>
255 <B>
256 <A HREF="#kccd1">d1</A></B> </TD><TD> Write output port </TD></TR><TR><TD>
257 <B>
258 <A HREF="#kcce0">e0</A></B> </TD><TD> Read test inputs </TD></TR><TR><TD>
259 <B>
260 <A HREF="#kccfe">fe</A></B> </TD><TD> System reset </TD></TR><TR><TD>
261
262 </TD></TR></TABLE></CENTER>
263 <P>Useful, generally available, mouse commands are:
264 <P>
265 <P>
266 <CENTER><TABLE BORDER><TR><TD>
267 <B>
268 <A HREF="#kcca7">a7</A></B> </TD><TD> Disable mouse port </TD></TR><TR><TD>
269 <B>
270 <A HREF="#kcca8">a8</A></B> </TD><TD> Enable mouse port </TD></TR><TR><TD>
271 <B>
272 <A HREF="#kcca9">a9</A></B> </TD><TD> Test mouse port </TD></TR><TR><TD>
273 <B>
274 <A HREF="#kccd4">d4</A></B> </TD><TD> Write to mouse </TD></TR><TR><TD>
275
276 </TD></TR></TABLE></CENTER>
277 <P>Obscure, probably obsolete, commands:
278 <P>
279 <P>
280 <CENTER><TABLE BORDER><TR><TD>
281 <B>
282 <A HREF="#kcc00">00-1f</A></B> </TD><TD> Read keyboard controller RAM </TD></TR><TR><TD>
283 <B>
284 <A HREF="#kcc20">20-3f</A></B> </TD><TD> Read keyboard controller RAM </TD></TR><TR><TD>
285 <B>
286 <A HREF="#kcc40">40-5f</A></B> </TD><TD> Write keyboard controller RAM </TD></TR><TR><TD>
287 <B>
288 <A HREF="#kcc60">60-7f</A></B> </TD><TD> Write keyboard controller RAM </TD></TR><TR><TD>
289 <B>
290 <A HREF="#kcc90">90-93</A></B> </TD><TD> Synaptics multiplexer prefix </TD></TR><TR><TD>
291 <B>
292 <A HREF="#kcc90via">90-9f</A></B> </TD><TD> Write Port13-Port10 </TD></TR><TR><TD>
293 <B>
294 <A HREF="#kcca0">a0</A></B> </TD><TD> Read copyright </TD></TR><TR><TD>
295 <B>
296 <A HREF="#kcca1">a1</A></B> </TD><TD> Read firmware version </TD></TR><TR><TD>
297 <B>
298 <A HREF="#kcca2">a2</A></B> </TD><TD> Switch speed </TD></TR><TR><TD>
299 <B>
300 <A HREF="#kcca3">a3</A></B> </TD><TD> Switch speed </TD></TR><TR><TD>
301 <B>
302 <A HREF="#kcca4">a4</A></B> </TD><TD> Check if password installed </TD></TR><TR><TD>
303 <B>
304 <A HREF="#kcca5">a5</A></B> </TD><TD> Load password </TD></TR><TR><TD>
305 <B>
306 <A HREF="#kcca6">a6</A></B> </TD><TD> Check password </TD></TR><TR><TD>
307 <B>
308 <A HREF="#kccac">ac</A></B> </TD><TD> Diagnostic dump </TD></TR><TR><TD>
309 <B>
310 <A HREF="#kccaf">af</A></B> </TD><TD> Read keyboard version </TD></TR><TR><TD>
311 <B>
312 <A HREF="#kccb0">b0-b5</A></B> </TD><TD> Reset keyboard controller line </TD></TR><TR><TD>
313 <B>
314 <A HREF="#kccb8">b8-bd</A></B> </TD><TD> Set keyboard controller line </TD></TR><TR><TD>
315 <B>
316 <A HREF="#kccc1">c1</A></B> </TD><TD> Continuous input port poll, low </TD></TR><TR><TD>
317 <B>
318 <A HREF="#kccc2">c2</A></B> </TD><TD> Continuous input port poll, high </TD></TR><TR><TD>
319 <B>
320 <A HREF="#kccc8">c8</A></B> </TD><TD> Unblock lines P22 and P23 </TD></TR><TR><TD>
321 <B>
322 <A HREF="#kccc9">c9</A></B> </TD><TD> Block lines P22 and P23 </TD></TR><TR><TD>
323 <B>
324 <A HREF="#kccca">ca</A></B> </TD><TD> Read keyboard controller mode </TD></TR><TR><TD>
325 <B>
326 <A HREF="#kcccb">cb</A></B> </TD><TD> Write keyboard controller mode </TD></TR><TR><TD>
327 <B>
328 <A HREF="#kccd2">d2</A></B> </TD><TD> Write keyboard output buffer </TD></TR><TR><TD>
329 <B>
330 <A HREF="#kccd3">d3</A></B> </TD><TD> Write mouse output buffer </TD></TR><TR><TD>
331 <B>
332 <A HREF="#kccdd">dd</A></B> </TD><TD> Disable A20 address line </TD></TR><TR><TD>
333 <B>
334 <A HREF="#kccdf">df</A></B> </TD><TD> Enable A20 address line </TD></TR><TR><TD>
335 <B>
336 <A HREF="#kccf0">f0-ff</A></B> </TD><TD> Pulse output bit </TD></TR><TR><TD>
337
338 </TD></TR></TABLE></CENTER>
339 <P><I>Command 0x00-0x1f: 
340 <A NAME="kcc00"></A> Read keyboard controller RAM</I>
341 <P>
342 <BLOCKQUOTE>
343 (AMIBIOS only) Aliases for 0x20-0x3f.
344 </BLOCKQUOTE>
345 <P><I>Command 0x20-0x3f: 
346 <A NAME="kcc20"></A> Read keyboard controller RAM</I>
347 <P>
348 <BLOCKQUOTE>
349 The last six bits of the command specify the RAM address to read.
350 The read data is placed into the output buffer, and can be read
351 by reading port 0x60.
352 On MCA systems, type 1 controllers can access all 32 locations;
353 type 2 controllers can only access locations 0, 0x13-0x17, 0x1d, 0x1f.
354 <P>Location 0 is the 
355 <A HREF="#commandbyte">Command byte</A>, see above.
356 <P>Location 0x13 (on MCA) is nonzero when a password is enabled.
357 <P>Location 0x14 (on MCA) is nonzero when the password was matched.
358 <P>Locations 0x16-0x17 (on MCA) give two make codes to be discarded
359 during password matching.
360 </BLOCKQUOTE>
361 <P><I>Command 0x40-0x5f: 
362 <A NAME="kcc40"></A> Write keyboard controller RAM</I>
363 <P>
364 <BLOCKQUOTE>
365 (AMIBIOS only) Aliases for 0x40-0x5f.
366 </BLOCKQUOTE>
367 <P><I>Command 0x60-0x7f: 
368 <A NAME="kcc60"></A> Write keyboard controller RAM</I>
369 <P>
370 <P><I>Command 0x90-0x93: 
371 <A NAME="kcc90"></A> Synaptics routing prefixes</I>
372 <P>
373 <BLOCKQUOTE>
374 Prefix a PS/2 mouse command with one of these to talk to one of at most four
375 multiplexed devices. See also the
376 <A HREF="#multiplexing">multiplexing handshake</A> below.
377 <P>Unfortunately, VIA also uses this command:
378 </BLOCKQUOTE>
379 <P><I>Command 0x90-0x9f: 
380 <A NAME="kcc90via"></A> Write Port13-Port10</I>
381 <BLOCKQUOTE>
382 (VIA VT82C42) Write low nibble to Port13-Port10.
383 </BLOCKQUOTE>
384 <P><I>Command 0xa0: 
385 <A NAME="kcca0"></A> Read copyright</I>
386 <P>
387 <BLOCKQUOTE>
388 On some keyboard controllers: an ASCIZ copyright string
389 (possibly just NUL) is made available for reading via port 0x60.
390 On other systems: no effect, the command is ignored.
391 </BLOCKQUOTE>
392 <P><I>Command 0xa1: 
393 <A NAME="kcca1"></A> Read controller firmware version</I>
394 <P>
395 <BLOCKQUOTE>
396 On some keyboard controllers: a single ASCII byte is made available
397 for reading via port 0x60.
398 On other systems: no effect, the command is ignored.
399 </BLOCKQUOTE>
400 <P><I>Command 0xa2: 
401 <A NAME="kcca2"></A> Switch speed</I>
402 <P>
403 <BLOCKQUOTE>
404 (On ISA/EISA systems with AMI BIOS)
405 Reset keyboard controller lines P22 and P23 low.
406 These lines can be used for speed switching via the keyboard controller.
407 When done, the keyboard controller sends one garbage byte to the system.
408 </BLOCKQUOTE>
409 <P><I>Command 0xa3: 
410 <A NAME="kcca3"></A> Switch speed</I>
411 <P>
412 <BLOCKQUOTE>
413 (On ISA/EISA systems with AMI BIOS)
414 Set keyboard controller lines P22 and P23 high.
415 These lines can be used for speed switching via the keyboard controller.
416 When done, the keyboard controller sends one garbage byte to the system.
417 <P>(Compaq BIOS: Enable system speed control.)
418 </BLOCKQUOTE>
419 <P><I>Command 0xa4: 
420 <A NAME="kcca4"></A> Check if password installed</I>
421 <P>
422 <BLOCKQUOTE>
423 On MCA systems:
424 Return 0xf1 (via port 0x60) when no password is installed,
425 return 0xfa when a password has been installed.
426 Some systems without password facility always return 0xf1.
427 <P>(On ISA/EISA systems with AMI BIOS)
428 Write Clock = Low.
429 <P>(Compaq BIOS: toggle speed.)
430 </BLOCKQUOTE>
431 <P><I>Command 0xa5: 
432 <A NAME="kcca5"></A> Load password</I>
433 <P>
434 <BLOCKQUOTE>
435 On MCA systems:
436 Load a password by writing a NUL-terminated string to port 0x60.
437 The string is in scancode format.
438 <P>(On ISA/EISA systems with AMI BIOS)
439 Write Clock = High.
440 <P>(Compaq BIOS: special read of P2, with bits 4 and 5 replaced:
441 Bit 5: 0: 9-bit keyboard, 1: 11-bit keyboard.
442 Bit 4: 0: outp-buff-full interrupt disabled, 1: enabled.)
443 </BLOCKQUOTE>
444 <P><I>Command 0xa6: 
445 <A NAME="kcca6"></A> Check password</I>
446 <P>
447 <BLOCKQUOTE>
448 On MCA systems:
449 When a password is installed:
450 Check password by matching keystrokes with the stored password.
451 Enable keyboard upon successful match.
452 <P>(On ISA/EISA systems with AMI BIOS)
453 Read Clock. 0: Low. 1: High.
454 </BLOCKQUOTE>
455 <P><I>Command 0xa7: 
456 <A NAME="kcca7"></A> Disable mouse port</I>
457 <P>
458 <BLOCKQUOTE>
459 On MCA systems: disable the mouse (auxiliary device)
460 by setting its clock line low, and set 
461 <A HREF="#kccb5">bit 5</A>
462 of the 
463 <A HREF="#commandbyte">Command byte</A>. Now P23 = 1.
464 <P>(On ISA/EISA systems with AMI BIOS)
465 Write Cache Bad.
466 </BLOCKQUOTE>
467 <P><I>Command 0xa8: 
468 <A NAME="kcca8"></A> Enable mouse port</I>
469 <P>
470 <BLOCKQUOTE>
471 On MCA systems: enable the mouse (auxiliary device),
472 clear 
473 <A HREF="#kccb5">bit 5</A> of the
474 <A HREF="#commandbyte">Command byte</A>. Now P23 = 0.
475 <P>(On ISA/EISA systems with AMI BIOS)
476 Write Cache Good.
477 </BLOCKQUOTE>
478 <P><I>Command 0xa9: 
479 <A NAME="kcca9"></A> Test mouse port</I>
480 <P>
481 <BLOCKQUOTE>
482 On MCA and other systems: test the serial link between
483 keyboard controller and mouse. The result can be read from port 0x60.
484 0: OK.
485 1: Mouse clock line stuck low.
486 2: Mouse clock line stuck high.
487 3: Mouse data line stuck low.
488 4: Mouse data line stuck high.
489 0xff: No mouse.
490 <P>(On ISA/EISA systems with AMI BIOS)
491 Read Cache Bad or Good. 0: Bad. 1: Good.
492 </BLOCKQUOTE>
493 <P><I>Command 0xaa: 
494 <A NAME="kccaa"></A> Self test</I>
495 <P>
496 <BLOCKQUOTE>
497 Perform self-test. Return 0x55 if OK, 0xfc if NOK.
498 </BLOCKQUOTE>
499 <P><I>Command 0xab: 
500 <A NAME="kccab"></A> Interface test</I>
501 <P>
502 <BLOCKQUOTE>
503 Test the serial link between keyboard controller and keyboard.
504 The result can be read from port 0x60.
505 0: OK.
506 1: Keyboard clock line stuck low.
507 2: Keyboard clock line stuck high.
508 3: Keyboard data line stuck low.
509 4: Keyboard data line stuck high.
510 0xff: General error.
511 </BLOCKQUOTE>
512 <P><I>Command 0xac: 
513 <A NAME="kccac"></A> Diagnostic dump</I>
514 <P>
515 <BLOCKQUOTE>
516 (On some systems)
517 Read from port 0x60 sixteen bytes of keyboard controller RAM,
518 and the output and input ports and the controller's program status word.
519 </BLOCKQUOTE>
520 <P><I>Command 0xad: 
521 <A NAME="kccad"></A> Disable keyboard</I>
522 <P>
523 <BLOCKQUOTE>
524 Disable the keyboard clock line and set 
525 <A HREF="#kccb5">bit 4</A>
526 of the 
527 <A HREF="#commandbyte">Command byte</A>.
528 Any keyboard command enables the keyboard again.
529 </BLOCKQUOTE>
530 <P><I>Command 0xae: 
531 <A NAME="kccae"></A> Enable keyboard</I>
532 <P>
533 <BLOCKQUOTE>
534 Enable the keyboard clock line and clear 
535 <A HREF="#kccb5">bit 4</A>
536 of the 
537 <A HREF="#commandbyte">Command byte</A>.
538 </BLOCKQUOTE>
539 <P><I>Command 0xaf: 
540 <A NAME="kccaf"></A> Read keyboard version</I>
541 <P>
542 <BLOCKQUOTE>
543 (Award BIOS, VIA)
544 </BLOCKQUOTE>
545 <P><I>Command 0xb0-0xb5,0xb8-0xbd:
546 <A NAME="kccb0"></A> <A NAME="kccb8"></A> Reset/set keyboard controller line</I>
547 <P>
548 <BLOCKQUOTE>
549 AMI BIOS:
550 Commands 0xb0-0xb5 reset a keyboard controller line low.
551 Commands 0xb8-0xbd set the corresponding keyboard controller line high.
552 The lines are P10, P11, P12, P13, P22 and P23, respectively.
553 (In the case of the lines P10, P11, P22, P23 this is on ISA/EISA systems only.)
554 When done, the keyboard controller sends one garbage byte to the system.
555 <P>VIA BIOS:
556 Commands 0xb0-0xb7 write 0 to lines P10, P11, P12, P13, P22, P23, P14, P15.
557 Commands 0xb8-0xbf write 1 to lines P10, P11, P12, P13, P22, P23, P14, P15.
558 </BLOCKQUOTE>
559 <P><I>Command 0xc0: 
560 <A NAME="kccc0"></A> Read input port</I>
561 <P>
562 <BLOCKQUOTE>
563 Read the 
564 <A HREF="#inputport">input port</A> (P1),
565 and make the resulting byte available to be read from port 0x60.
566 </BLOCKQUOTE>
567 <P><I>Command 0xc1: 
568 <A NAME="kccc1"></A> Continuous input port poll, low</I>
569 <P>
570 <BLOCKQUOTE>
571 (MCA systems with type 1 controller only)
572 Continuously copy bits 3-0 of the input port to be read from bits 7-4
573 of port 0x64, until another keyboard controller command is received.
574 </BLOCKQUOTE>
575 <P><I>Command 0xc2: 
576 <A NAME="kccc2"></A> Continuous input port poll, high</I>
577 <P>
578 <BLOCKQUOTE>
579 (MCA systems with type 1 controller only)
580 Continuously copy bits 7-4 of the input port to be read from bits 7-4
581 of port 0x64, until another keyboard controller command is received.
582 </BLOCKQUOTE>
583 <P><I>Command 0xc8:
584 <A NAME="kccc8"></A> Unblock keyboard controller lines P22 and P23</I>
585 <P>
586 <BLOCKQUOTE>
587 (On ISA/EISA systems with AMI BIOS)
588 After this command, the system can make lines P22 and P23 low/high
589 using 
590 <A HREF="#kccd1">command 0xd1</A>.
591 </BLOCKQUOTE>
592 <P><I>Command 0xc9:
593 <A NAME="kccc9"></A> Block keyboard controller lines P22 and P23</I>
594 <P>
595 <BLOCKQUOTE>
596 (On ISA/EISA systems with AMI BIOS)
597 After this command, the system cannot make lines P22 and P23 low/high
598 using 
599 <A HREF="#kccd1">command 0xd1</A>.
600 </BLOCKQUOTE>
601 <P><I>Command 0xca: 
602 <A NAME="kccca"></A> Read keyboard controller mode</I>
603 <P>
604 <BLOCKQUOTE>
605 (AMI BIOS, VIA)
606 Read keyboard controller mode to bit 0 of port 0x60.
607 0: ISA (AT) interface.
608 1: PS/2 (MCA)interface.
609 </BLOCKQUOTE>
610 <P><I>Command 0xcb: 
611 <A NAME="kcccb"></A> Write keyboard controller mode</I>
612 <P>
613 <BLOCKQUOTE>
614 (AMI BIOS)
615 Write keyboard controller mode to bit 0 of port 0x60.
616 0: ISA (AT) interface.
617 1: PS/2 (MCA)interface.
618 (First read the mode using command 0xca, then modify only
619 the last bit, then write the mode using this command.)
620 </BLOCKQUOTE>
621 <P><I>Command 0xd0: 
622 <A NAME="kccd0"></A> Read output port</I>
623 <P>
624 <BLOCKQUOTE>
625 Read the 
626 <A HREF="#outputport">output port</A> (P2)
627 and place the result in the output buffer.
628 Use only when output buffer is empty.
629 </BLOCKQUOTE>
630 <P><I>Command 0xd1: 
631 <A NAME="kccd1"></A> Write output port</I>
632 <P>
633 <BLOCKQUOTE>
634 Write the 
635 <A HREF="#outputport">output port</A> (P2).
636 Note that writing a 0 in bit 0 will cause a hardware reset.
637 <P>(Compaq: the system speed bits are not set. Use commands 0xa1-0xa6 for that.)
638 </BLOCKQUOTE>
639 <P><I>Command 0xd2: 
640 <A NAME="kccd2"></A> Write keyboard output buffer</I>
641 <P>
642 <BLOCKQUOTE>
643 (MCA)
644 Write the keyboard controllers output buffer with the byte
645 next written to port 0x60, and act as if this was keyboard data.
646 (In particular, raise IRQ1 when 
647 <A HREF="#kccb0">bit 0</A>
648 of the 
649 <A HREF="#commandbyte">Command byte</A> says so.)
650 </BLOCKQUOTE>
651 <P><I>Command 0xd3: 
652 <A NAME="kccd3"></A> Write mouse output buffer</I>
653 <P>
654 <BLOCKQUOTE>
655 (MCA)
656 Write the keyboard controllers output buffer with the byte
657 next written to port 0x60, and act as if this was mouse data.
658 (In particular, raise IRQ12 when 
659 <A HREF="#kccb1">bit 1</A>
660 of the 
661 <A HREF="#commandbyte">Command byte</A> says so.)
662 <P>Not all systems support this.
663 <P><B>
664 <A NAME="multiplexing"></A> Synaptics multiplexing</B>
665 On the other hand, Synaptics (see 
666 <A HREF="http://www.synaptics-uk.com/decaf/utilities/ps2-mux.PDF">ps2-mux.PDF</A>)
667 uses this command as a handshake between driver and controller:
668 if the driver gives this command three times, with data bytes
669 0xf0, 0x56, 0xa4 respectively, and reads 0xf0, 0x56, but not 0xa4
670 back from the mouse output buffer, then the driver knows that the
671 controller supports Synaptics AUX port multiplexing, and the controller
672 knows that it does not have to do the usual data faking and goes
673 into multiplexed mode. The third byte read is the version of the
674 Synaptics standard.
675 <P>There is a corresponding deactivation sequence, namely
676 0xf0, 0x56, 0xa5. (And again the last byte is changed to the
677 version number of the standard supported.)
678 This latter sequence works both in multiplexed mode and in legacy mode
679 and can thus be used to determine whether this feature is present
680 without activating it.
681 <P>See also the multiplexer commands 
682 <A HREF="#kcc90">0x90-0x93</A>.
683 <P>For some laptops it has been reported that bit 3 of every third
684 mouse byte is forced to 1 (as it would be with the standard
685 3-byte mouse packets). This may turn 0xf0, 0x56, 0xa4 into
686 0xf0, 0x56, 0xac and cause misdetection of Synaptics multiplexing
687 (for version 10.12).
688 </BLOCKQUOTE>
689 <P><I>Command 0xd4: 
690 <A NAME="kccd4"></A> Write to mouse</I>
691 <P>
692 <BLOCKQUOTE>
693 (MCA)
694 The byte next written to port 0x60 is transmitted to the mouse.
695 </BLOCKQUOTE>
696 <P><I>Command 0xdd: 
697 <A NAME="kccdd"></A> Disable A20 address line</I>
698 <P>
699 <BLOCKQUOTE>
700 (HP Vectra)
701 </BLOCKQUOTE>
702 <P><I>Command 0xdf: 
703 <A NAME="kccdf"></A> Enable A20 address line</I>
704 <P>
705 <BLOCKQUOTE>
706 (HP Vectra)
707 </BLOCKQUOTE>
708 <P><I>Command 0xe0: 
709 <A NAME="kcce0"></A> Read test inputs</I>
710 <P>
711 <BLOCKQUOTE>
712 This command makes the status of the
713 <A HREF="#testinputs">Test inputs</A> T0 and T1 available
714 to be read via port 0x60 in bits 0 and 1, respectively.
715 Use only when the output port is empty.
716 </BLOCKQUOTE>
717 <P>
718 <P><I>Command 0xf0-0xff: 
719 <A NAME="kccf0"></A> Pulse output bit</I>
720 <P>
721 <BLOCKQUOTE>
722 Bits 3-0 of the 
723 <A HREF="#outputport">output port</A> P2
724 of the keyboard controller may be pulsed low for approximately 6 µseconds.
725 Bits 3-0 of this command specify the output port bits to be pulsed.
726 0: Bit should be pulsed.
727 1: Bit should not be modified. 
728 The only useful version of this command is Command 0xfe.
729 (For MCA, replace 3-0 by 1-0 in the above.)
730 </BLOCKQUOTE>
731 <P><I>Command 0xfe: 
732 <A NAME="kccfe"></A> System reset</I>
733 <P>
734 <BLOCKQUOTE>
735 Pulse bit 0 of the 
736 <A HREF="#outputport">output port</A> P2
737 of the keyboard controller. This will reset the CPU.
738 </BLOCKQUOTE>
739 <P>
740 <H2><A NAME="inputport"></A> <A NAME="ss10.4">10.4 The input port P1</A>
741 </H2>
742
743 <P>This has the following layout.
744 <P>
745 <CENTER><TABLE BORDER><TR><TD>
746 bit 7 </TD><TD> Keyboard lock </TD><TD> 0: locked, 1: not locked </TD></TR><TR><TD>
747 bit 6 </TD><TD> Display </TD><TD> 0: CGA, 1: MDA </TD></TR><TR><TD>
748 bit 5 </TD><TD> Manufacturing jumper </TD><TD> 0: installed, 1: not installed </TD></TR><TR><TD>
749 </TD><TD> </TD><TD> with jumper the BIOS runs an infinite diagnostic loop </TD></TR><TR><TD>
750 bit 4 </TD><TD> RAM on motherboard </TD><TD> 0: 512 KB, 1: 256 KB </TD></TR><TR><TD>
751 bit 3 </TD><TD> &nbsp; </TD><TD> Unused in ISA, EISA, PS/2 systems </TD></TR><TR><TD>
752 </TD><TD> &nbsp; </TD><TD> Can be configured for clock switching </TD></TR><TR><TD>
753 bit 2 </TD><TD> &nbsp; </TD><TD> Unused in ISA, EISA, PS/2 systems </TD></TR><TR><TD>
754 </TD><TD> &nbsp; </TD><TD> Can be configured for clock switching </TD></TR><TR><TD>
755 </TD><TD> Keyboard power </TD><TD> PS/2 MCA: 0: keyboard power normal, 1: no power </TD></TR><TR><TD>
756 bit 1 </TD><TD> Mouse data in </TD><TD> Unused in ISA </TD></TR><TR><TD>
757 bit 0 </TD><TD> Keyboard data in </TD><TD> Unused in ISA </TD></TR><TR><TD>
758
759 </TD></TR></TABLE></CENTER>
760 <P>Clearly only bits 1-0 are input bits.
761 Of the above, the original IBM AT used bits 7-4, while PS/2 MCA systems
762 use only bits 2-0.
763 <P>Where in the above lines P10, P11, etc are used, these refer to the pins
764 corresponding to bit 0, bit 1, etc of port P1.
765 <P>
766 <H2><A NAME="outputport"></A> <A NAME="ss10.5">10.5 The output port P2</A>
767 </H2>
768
769 <P>This has the following layout.
770 <P>
771 <CENTER><TABLE BORDER><TR><TD>
772 bit 7 </TD><TD> Keyboard data </TD><TD> data to keyboard </TD></TR><TR><TD>
773 bit 6 </TD><TD> Keyboard clock </TD></TR><TR><TD>
774 bit 5 </TD><TD> IRQ12 </TD><TD> 0: IRQ12 not active, 1: active </TD></TR><TR><TD>
775 bit 4 </TD><TD> IRQ1 </TD><TD> 0: IRQ1 not active, 1: active </TD></TR><TR><TD>
776 bit 3 </TD><TD> Mouse clock </TD><TD> Unused in ISA </TD></TR><TR><TD>
777 bit 2 </TD><TD> Mouse data </TD><TD> Unused in ISA. Data to mouse </TD></TR><TR><TD>
778 bit 1 </TD><TD> A20 </TD><TD> 0: A20 line is forced 0, 1: A20 enabled </TD></TR><TR><TD>
779 bit 0 </TD><TD> Reset </TD><TD> 0: reset CPU, 1: normal </TD></TR><TR><TD>
780
781 </TD></TR></TABLE></CENTER>
782 <P>Where in the above lines P20, P21, etc are used, these refer to the pins
783 corresponding to bit 0, bit 1, etc of port P2.
784 <P>
785 <H2><A NAME="testinputs"></A> <A NAME="ss10.6">10.6 The test port T</A>
786 </H2>
787
788 <P><I>bit 0</I>
789 <P>
790 <BLOCKQUOTE>
791 Keyboard clock (input).
792 </BLOCKQUOTE>
793 <P><I>bit 1</I>
794 <P>
795 <BLOCKQUOTE>
796 (AT) Keyboard data (input).
797 (PS/2) Mouse clock (input).
798 </BLOCKQUOTE>
799 <P>
800 <HR>
801 <A HREF="scancodes-11.html">Next</A>
802 <A HREF="scancodes-9.html">Previous</A>
803 <A HREF="scancodes.html#toc10">Contents</A>
804 </BODY>
805 </HTML>