1 /* -----------------------------------------------------------------------
3 * Copyright 2008 rPath, Inc. - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * ----------------------------------------------------------------------- */
29 * Code to enable A20. Based on code in SYSLINUX.
32 .section ".text16","ax"
34 .type enable_a20, @function
39 /* Are we enabled already? */
52 /* Try the keyboard controller */
55 jnz 1f /* A20 live, no need for KBC */
58 movb $0xd1, %al /* Command write */
62 movb $0xdf, %al /* Enable A20 */
66 movb $0xff, %al /* Null command, required by UHCI spec */
70 /* Loop until A20 is enabled, or for 2^16 loops */
76 /* Urk. Try the "fast A20 gate" (config port A) */
78 orb $0x02, %al /* Enable A20 */
79 andb $0xfe, %al /* Do not reset */
82 /* Loop until A20 is enabled, or for 2^16 loops */
88 /* If we get here, we're in trouble. Try again;
89 loop forever if need be. */
95 .size enable_a20, .-enable_a20
98 * Test to see if A20 already is enabled.
100 .type a20_test, @function
112 movw $32, %cx /* Loop count */
113 movw %fs:0,%ax /* Divide by zero vector, hope it's safe */
121 popw %fs:0 /* Restore previous value */
127 .size a20_test, .-a20_test
131 * Routine to empty the 8042 KBC controller. If %cx != 0 then we will
132 * test A20 in the loop and exit if A20 becomes enabled.
134 .type empty_8042, @function
138 jcxz 1f /* If %cx == 0 continue regardless */
142 inb $0x64, %al /* Status port */
146 inb $0x60, %al /* Read input */
154 .size empty_8042, .-empty_8042
159 #define DELAY_PORT 0x80
161 .type io_delay, @function
165 outb %al, $DELAY_PORT
166 outb %al, $DELAY_PORT
169 .size io_delay, .-io_delay