]>
Commit | Line | Data |
---|---|---|
14c7c974 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights | |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.1 (the "License"). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the | |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License. | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* | |
25 | * Mach Operating System | |
26 | * Copyright (c) 1990 Carnegie-Mellon University | |
27 | * Copyright (c) 1989 Carnegie-Mellon University | |
28 | * All rights reserved. The CMU software License Agreement specifies | |
29 | * the terms and conditions for use and redistribution. | |
30 | */ | |
31 | ||
32 | /* | |
33 | * INTEL CORPORATION PROPRIETARY INFORMATION | |
34 | * | |
35 | * This software is supplied under the terms of a license agreement or | |
36 | * nondisclosure agreement with Intel Corporation and may not be copied | |
37 | * nor disclosed except in accordance with the terms of that agreement. | |
38 | * | |
39 | * Copyright 1988, 1989 Intel Corporation | |
40 | */ | |
41 | ||
42 | /* | |
43 | * Copyright 1993 NeXT, Inc. | |
44 | * All rights reserved. | |
45 | */ | |
46 | ||
14c7c974 A |
47 | #include "libsaio.h" |
48 | ||
49 | /* | |
50 | * keyboard controller (8042) I/O port addresses | |
51 | */ | |
52 | #define PORT_A 0x60 /* port A */ | |
53 | #define PORT_B 0x64 /* port B */ | |
54 | ||
55 | /* | |
56 | * keyboard controller command | |
57 | */ | |
58 | #define CMD_WOUT 0xd1 /* write controller's output port */ | |
59 | ||
60 | /* | |
61 | * keyboard controller status flags | |
62 | */ | |
63 | #define KB_INFULL 0x2 /* input buffer full */ | |
64 | #define KB_OUTFULL 0x1 /* output buffer full */ | |
65 | ||
66 | #define KB_A20 0x9f /* enable A20, | |
67 | enable output buffer full interrupt | |
68 | enable data line | |
69 | disable clock line */ | |
70 | ||
71 | //========================================================================== | |
72 | // Enable A20 gate to be able to access memory above 1MB | |
73 | ||
74 | void enableA20() | |
75 | { | |
75b89a82 A |
76 | /* make sure that the input buffer is empty */ |
77 | while (inb(PORT_B) & KB_INFULL); | |
14c7c974 | 78 | |
75b89a82 A |
79 | /* make sure that the output buffer is empty */ |
80 | if (inb(PORT_B) & KB_OUTFULL) | |
81 | (void)inb(PORT_A); | |
14c7c974 | 82 | |
75b89a82 A |
83 | /* make sure that the input buffer is empty */ |
84 | while (inb(PORT_B) & KB_INFULL); | |
14c7c974 | 85 | |
75b89a82 A |
86 | /* write output port */ |
87 | outb(PORT_B, CMD_WOUT); | |
14c7c974 | 88 | |
75b89a82 A |
89 | /* wait until command is accepted */ |
90 | while (inb(PORT_B) & KB_INFULL); | |
14c7c974 | 91 | |
75b89a82 | 92 | outb(PORT_A, KB_A20); |
14c7c974 | 93 | |
75b89a82 | 94 | while (inb(PORT_B) & KB_INFULL); /* wait until done */ |
14c7c974 A |
95 | } |
96 | ||
97 | void sleep(int n) | |
98 | { | |
75b89a82 A |
99 | int endtime = (time18() + 18*n); |
100 | while (time18() < endtime); | |
14c7c974 A |
101 | } |
102 | ||
103 | void turnOffFloppy(void) | |
104 | { | |
75b89a82 A |
105 | /* |
106 | * Disable floppy: | |
107 | * Hold controller in reset, | |
108 | * disable DMA and IRQ, | |
109 | * turn off floppy motors. | |
110 | */ | |
111 | outb(0x3F2, 0x00); | |
14c7c974 A |
112 | } |
113 | ||
75b89a82 | 114 | char * newString(const char * oldString) |
14c7c974 A |
115 | { |
116 | if ( oldString ) | |
117 | return strcpy(malloc(strlen(oldString)+1), oldString); | |
118 | else | |
119 | return NULL; | |
120 | } | |
75b89a82 A |
121 | |
122 | void stop(const char * msg) | |
123 | { | |
124 | error("\n%s\n", msg); | |
125 | halt(); | |
126 | } |