Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / boot / pc32 / libi386 / gatea20.c
1 /*
2  * $FreeBSD: src/sys/boot/i386/libi386/gatea20.c,v 1.2.2.1 2000/12/28 13:12:40 ps Exp $
3  * From: $NetBSD: gatea20.c,v 1.2 1997/10/29 00:32:49 fvdl Exp $
4  */
5
6 /* extracted from freebsd:sys/i386/boot/biosboot/io.c */
7
8 #include <stand.h>
9 #include <machine/cpufunc.h>
10
11 #include <bootstrap.h>
12
13 #include "libi386.h"
14
15 #define K_RDWR          0x60            /* keyboard data & cmds (read/write) */
16 #define K_STATUS        0x64            /* keyboard status */
17 #define K_CMD           0x64            /* keybd ctlr command (write-only) */
18
19 #define K_OBUF_FUL      0x01            /* output buffer full */
20 #define K_IBUF_FUL      0x02            /* input buffer full */
21
22 #define KC_CMD_WIN      0xd0            /* read  output port */
23 #define KC_CMD_WOUT     0xd1            /* write output port */
24 #define KB_A20          0x9f            /* enable A20,
25                                            reset (!),
26                                            enable output buffer full interrupt
27                                            enable data line
28                                            disable clock line */
29
30 /*
31  * Gate A20 for high memory
32  */
33 static unsigned char    x_20 = KB_A20;
34 void gateA20()
35 {
36         __asm("pushfl ; cli");
37 #ifdef  IBM_L40
38         outb(0x92, 0x2);
39 #else   /* !IBM_L40 */
40         while (inb(K_STATUS) & K_IBUF_FUL);
41         while (inb(K_STATUS) & K_OBUF_FUL)
42                 (void)inb(K_RDWR);
43
44         outb(K_CMD, KC_CMD_WOUT);
45         delay(100);
46         while (inb(K_STATUS) & K_IBUF_FUL);
47         outb(K_RDWR, x_20);
48         delay(100);
49         while (inb(K_STATUS) & K_IBUF_FUL);
50 #endif  /* IBM_L40 */
51         __asm("popfl");
52 }