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