1 | ;
|
---|
2 | ; A20.ASM -- Control the A20 gate
|
---|
3 | ;
|
---|
4 | ; Copyright (c) 1991-1995 by Eberhard Mattes
|
---|
5 | ;
|
---|
6 | ; This file is part of emx.
|
---|
7 | ;
|
---|
8 | ; emx is free software; you can redistribute it and/or modify it
|
---|
9 | ; under the terms of the GNU General Public License as published by
|
---|
10 | ; the Free Software Foundation; either version 2, or (at your option)
|
---|
11 | ; any later version.
|
---|
12 | ;
|
---|
13 | ; emx is distributed in the hope that it will be useful,
|
---|
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | ; GNU General Public License for more details.
|
---|
17 | ;
|
---|
18 | ; You should have received a copy of the GNU General Public License
|
---|
19 | ; along with emx; see the file COPYING. If not, write to
|
---|
20 | ; the Free Software Foundation, 59 Temple Place - Suite 330,
|
---|
21 | ; Boston, MA 02111-1307, USA.
|
---|
22 | ;
|
---|
23 | ; See emx.asm for a special exception.
|
---|
24 | ;
|
---|
25 |
|
---|
26 | INCLUDE EMX.INC
|
---|
27 | INCLUDE XMS.INC
|
---|
28 | INCLUDE VCPI.INC
|
---|
29 | INCLUDE OPTIONS.INC
|
---|
30 |
|
---|
31 | PUBLIC USE_A20_PATCH, USE_FAST_A20
|
---|
32 | PUBLIC INIT_A20, CLEANUP_A20, CHECK_A20
|
---|
33 | PUBLIC A20_ON, A20_OFF
|
---|
34 |
|
---|
35 | SV_DATA SEGMENT
|
---|
36 |
|
---|
37 | ;
|
---|
38 | ; Enable/disable A20: address of functions
|
---|
39 | ;
|
---|
40 | A20_ON_JMP DW ?
|
---|
41 | A20_OFF_JMP DW ?
|
---|
42 |
|
---|
43 | A20_FLAG DB FALSE
|
---|
44 | USE_A20_PATCH DB FALSE
|
---|
45 | USE_FAST_A20 DB FALSE
|
---|
46 |
|
---|
47 | SV_DATA ENDS
|
---|
48 |
|
---|
49 |
|
---|
50 | INIT_CODE SEGMENT
|
---|
51 |
|
---|
52 | ASSUME CS:INIT_CODE, DS:NOTHING
|
---|
53 |
|
---|
54 | ;
|
---|
55 | ; Find out which machine we're running on
|
---|
56 | ; and set A20 enable/disable function addresses
|
---|
57 | ;
|
---|
58 | ASSUME DS:SV_DATA
|
---|
59 | INIT_A20 PROC NEAR
|
---|
60 | PUSH ES ; Don't clobber ES (ARGS!)
|
---|
61 | LEA BX, PATCH_A20_ON
|
---|
62 | LEA DX, PATCH_A20_OFF
|
---|
63 | CMP USE_A20_PATCH, FALSE
|
---|
64 | JNE SHORT INIT_A20_SET
|
---|
65 | LEA BX, FAST_A20_ON
|
---|
66 | LEA DX, FAST_A20_OFF
|
---|
67 | CMP USE_FAST_A20, FALSE
|
---|
68 | JNE SHORT INIT_A20_SET
|
---|
69 | LEA BX, XMS_A20_ON
|
---|
70 | LEA DX, XMS_A20_OFF
|
---|
71 | CMP XMS_FLAG, FALSE
|
---|
72 | JNE SHORT INIT_A20_SET
|
---|
73 | LEA BX, FMR70_A20_ON
|
---|
74 | LEA DX, FMR70_A20_OFF
|
---|
75 | CMP MACHINE, MACH_FMR70
|
---|
76 | JE SHORT INIT_A20_SET
|
---|
77 | LEA BX, PC98_A20_ON
|
---|
78 | LEA DX, PC98_A20_OFF
|
---|
79 | CMP MACHINE, MACH_PC98
|
---|
80 | JE SHORT INIT_A20_SET
|
---|
81 | LEA BX, INBOARD_A20_ON
|
---|
82 | LEA DX, INBOARD_A20_OFF
|
---|
83 | CMP MACHINE, MACH_INBOARD
|
---|
84 | JE SHORT INIT_A20_SET
|
---|
85 | MOV AH, 0C0H ; Return config. parameters
|
---|
86 | STC ; Don't trust BIOS
|
---|
87 | INT 15H ; `Cassette I/O'
|
---|
88 | JC SHORT INIT_A20_1 ; Cannot happen, assume AT
|
---|
89 | MOV AL, ES:[BX+5] ; Get flags byte
|
---|
90 | TEST AL, 00000010B ; Micro Channel?
|
---|
91 | JZ SHORT INIT_A20_1 ; No -> AT compatible
|
---|
92 | ;
|
---|
93 | ; It's a PS/2
|
---|
94 | ;
|
---|
95 | CALL PS2_A20_OFF ; Turn off A20
|
---|
96 | LEA BX, PS2_A20_ON ; Why? HIMEM.SYS does
|
---|
97 | LEA DX, PS2_A20_OFF
|
---|
98 | JMP SHORT INIT_A20_SET
|
---|
99 |
|
---|
100 | ;
|
---|
101 | ; It's an AT compatible machine
|
---|
102 | ;
|
---|
103 | INIT_A20_1: LEA BX, AT_A20_ON
|
---|
104 | LEA DX, AT_A20_OFF
|
---|
105 |
|
---|
106 | INIT_A20_SET: CMP VCPI_FLAG, FALSE ; VCPI ?
|
---|
107 | JE SHORT INIT_A20_SET_1 ; No -> skip
|
---|
108 | LEA BX, NO_A20_ON ; Don't enable A20
|
---|
109 | LEA DX, NO_A20_OFF ; Don't disable A20
|
---|
110 | INIT_A20_SET_1: MOV A20_ON_JMP, BX
|
---|
111 | MOV A20_OFF_JMP, DX
|
---|
112 | POP ES
|
---|
113 | RET
|
---|
114 | INIT_A20 ENDP
|
---|
115 |
|
---|
116 |
|
---|
117 | DATA_8042 = 60H ; Keyboard processor
|
---|
118 | STATUS_8042 = 64H ; Keyboard processor
|
---|
119 |
|
---|
120 | ;
|
---|
121 | ; Enable address line A20
|
---|
122 | ;
|
---|
123 | ; Note: disables interrupts
|
---|
124 | ;
|
---|
125 | ASSUME DS:SV_DATA
|
---|
126 | A20_ON PROC NEAR
|
---|
127 | PUSH AX
|
---|
128 | CLI
|
---|
129 | CALL A20_ON_JMP
|
---|
130 | MOV A20_FLAG, NOT FALSE
|
---|
131 | POP AX
|
---|
132 | RET
|
---|
133 | A20_ON ENDP
|
---|
134 |
|
---|
135 | ;
|
---|
136 | ; Disable address line A20
|
---|
137 | ;
|
---|
138 | ; Note: disables interrupts
|
---|
139 | ;
|
---|
140 | ASSUME DS:SV_DATA
|
---|
141 | A20_OFF PROC NEAR
|
---|
142 | PUSH AX
|
---|
143 | CLI
|
---|
144 | CALL A20_OFF_JMP
|
---|
145 | MOV A20_FLAG, FALSE
|
---|
146 | POP AX
|
---|
147 | RET
|
---|
148 | A20_OFF ENDP
|
---|
149 |
|
---|
150 | ;
|
---|
151 | ; Don't enable address line A20
|
---|
152 | ;
|
---|
153 | NO_A20_ON PROC NEAR
|
---|
154 | RET
|
---|
155 | NO_A20_ON ENDP
|
---|
156 |
|
---|
157 | ;
|
---|
158 | ; Don't disable address line A20
|
---|
159 | ;
|
---|
160 | NO_A20_OFF PROC NEAR
|
---|
161 | RET
|
---|
162 | NO_A20_OFF ENDP
|
---|
163 |
|
---|
164 | ;
|
---|
165 | ; Enable address line A20 (AT compatible)
|
---|
166 | ;
|
---|
167 | AT_A20_ON PROC NEAR
|
---|
168 | MOV AH, 0DFH
|
---|
169 | CALL AT_SET_A20
|
---|
170 | RET
|
---|
171 | AT_A20_ON ENDP
|
---|
172 |
|
---|
173 | ;
|
---|
174 | ; Disable address line A20 (AT compatible)
|
---|
175 | ;
|
---|
176 | AT_A20_OFF PROC NEAR
|
---|
177 | MOV AH, 0DDH
|
---|
178 | CALL AT_SET_A20
|
---|
179 | RET
|
---|
180 | AT_A20_OFF ENDP
|
---|
181 |
|
---|
182 |
|
---|
183 | ;
|
---|
184 | ; Enable address line A20 (PS/2)
|
---|
185 | ;
|
---|
186 | PS2_A20_ON PROC NEAR
|
---|
187 | IN AL, 92H
|
---|
188 | OR AL, 02H
|
---|
189 | OUT 92H, AL
|
---|
190 | RET
|
---|
191 | PS2_A20_ON ENDP
|
---|
192 |
|
---|
193 |
|
---|
194 | ;
|
---|
195 | ; Disable address line A20 (PS/2)
|
---|
196 | ;
|
---|
197 | PS2_A20_OFF PROC NEAR
|
---|
198 | IN AL, 92H
|
---|
199 | AND AL, NOT 02H
|
---|
200 | OUT 92H, AL
|
---|
201 | RET
|
---|
202 | PS2_A20_OFF ENDP
|
---|
203 |
|
---|
204 |
|
---|
205 | ;
|
---|
206 | ; Enable address line A20 (Inboard 386/PC)
|
---|
207 | ;
|
---|
208 | INBOARD_A20_ON PROC NEAR
|
---|
209 | MOV AL, 0DFH
|
---|
210 | OUT 60H, AL
|
---|
211 | RET
|
---|
212 | INBOARD_A20_ON ENDP
|
---|
213 |
|
---|
214 |
|
---|
215 | ;
|
---|
216 | ; Disable address line A20 (Inboard 386/PC)
|
---|
217 | ;
|
---|
218 | INBOARD_A20_OFF PROC NEAR
|
---|
219 | MOV AL, 0DDH
|
---|
220 | OUT 60H, AL
|
---|
221 | RET
|
---|
222 | INBOARD_A20_OFF ENDP
|
---|
223 |
|
---|
224 |
|
---|
225 | ;
|
---|
226 | ; Enable/disable address line A20 (AT compatible)
|
---|
227 | ;
|
---|
228 | ; In: AL=0DDH Disable
|
---|
229 | ; AL=0DFH Enable
|
---|
230 | ;
|
---|
231 | AT_SET_A20 PROC NEAR
|
---|
232 | PUSH CX
|
---|
233 | CALL READY_8042
|
---|
234 | JNZ SHORT AT_SET_A20_END
|
---|
235 | MOV AL, 0D1H ; Write output port
|
---|
236 | OUT STATUS_8042, AL
|
---|
237 | CALL READY_8042
|
---|
238 | JNZ SHORT AT_SET_A20_END
|
---|
239 | MOV AL, AH ; Data
|
---|
240 | OUT DATA_8042, AL
|
---|
241 | CALL READY_8042
|
---|
242 | MOV AL, 0FFH ; Pulse nothing (just wait)
|
---|
243 | OUT STATUS_8042, AL
|
---|
244 | CALL READY_8042
|
---|
245 | AT_SET_A20_END: POP CX
|
---|
246 | RET
|
---|
247 | AT_SET_A20 ENDP
|
---|
248 |
|
---|
249 |
|
---|
250 | ;
|
---|
251 | ; Wait until we can send a command to the keyboard controller
|
---|
252 | ;
|
---|
253 | READY_8042 PROC NEAR
|
---|
254 | XOR CX, CX
|
---|
255 | TALIGN 4 ; Avoid surprises
|
---|
256 | READY_1: IN AL, STATUS_8042
|
---|
257 | TEST AL, 02H ; Input buffer full?
|
---|
258 | LOOPNZ READY_1 ; Yes -> wait
|
---|
259 | RET
|
---|
260 | READY_8042 ENDP
|
---|
261 |
|
---|
262 |
|
---|
263 | FAST_IO_DELAY MACRO
|
---|
264 | LOCAL L1, L2
|
---|
265 | JMP SHORT L1
|
---|
266 | L1: JMP SHORT L2
|
---|
267 | L2:
|
---|
268 | ENDM
|
---|
269 |
|
---|
270 | ;
|
---|
271 | ; Enable address line A20 (fast)
|
---|
272 | ;
|
---|
273 | FAST_A20_ON PROC NEAR
|
---|
274 | MOV AL, 0D1H
|
---|
275 | OUT STATUS_8042, AL
|
---|
276 | FAST_IO_DELAY
|
---|
277 | MOV AL, 0DFH ; Enable
|
---|
278 | OUT DATA_8042, AL
|
---|
279 | RET
|
---|
280 | FAST_A20_ON ENDP
|
---|
281 |
|
---|
282 | ;
|
---|
283 | ; Disable address line A20 (fast)
|
---|
284 | ;
|
---|
285 | FAST_A20_OFF PROC NEAR
|
---|
286 | MOV AL, 0D1H
|
---|
287 | OUT STATUS_8042, AL
|
---|
288 | FAST_IO_DELAY
|
---|
289 | MOV AL, 0DDH ; Disable
|
---|
290 | OUT DATA_8042, AL
|
---|
291 | RET
|
---|
292 | FAST_A20_OFF ENDP
|
---|
293 |
|
---|
294 |
|
---|
295 | ;
|
---|
296 | ; Enable address line A20 (Fujitsu FMR70)
|
---|
297 | ;
|
---|
298 | FMR70_A20_ON proc near
|
---|
299 | MOV AL, 00110000B
|
---|
300 | OUT 20H, AL
|
---|
301 | RET
|
---|
302 | FMR70_A20_ON ENDP
|
---|
303 |
|
---|
304 | ;
|
---|
305 | ; Disable address line A20 (Fujitsu FMR70)
|
---|
306 | ;
|
---|
307 | FMR70_A20_OFF PROC NEAR
|
---|
308 | MOV AL, 0
|
---|
309 | OUT 20H, AL
|
---|
310 | RET
|
---|
311 | FMR70_A20_OFF ENDP
|
---|
312 |
|
---|
313 |
|
---|
314 | ;
|
---|
315 | ; Enable address line A20 (NEC PC-98)
|
---|
316 | ;
|
---|
317 | PC98_A20_ON PROC NEAR
|
---|
318 | MOV AL, 0
|
---|
319 | OUT 0F2H, AL
|
---|
320 | RET
|
---|
321 | PC98_A20_ON ENDP
|
---|
322 |
|
---|
323 | ;
|
---|
324 | ; Disable address line A20 (NEC PC-98)
|
---|
325 | ;
|
---|
326 | PC98_A20_OFF PROC NEAR
|
---|
327 | MOV AL, 0FFH
|
---|
328 | OUT 0F2H, AL
|
---|
329 | RET
|
---|
330 | PC98_A20_OFF ENDP
|
---|
331 |
|
---|
332 |
|
---|
333 | ;
|
---|
334 | ; Enable address line A20 (patched)
|
---|
335 | ;
|
---|
336 | PATCH_A20_ON PROC NEAR
|
---|
337 | RET
|
---|
338 | DB "PATCH_A20_ON "
|
---|
339 | RET
|
---|
340 | PATCH_A20_ON ENDP
|
---|
341 |
|
---|
342 |
|
---|
343 | ;
|
---|
344 | ; Disable address line A20 (patched)
|
---|
345 | ;
|
---|
346 | PATCH_A20_OFF PROC NEAR
|
---|
347 | RET
|
---|
348 | DB "PATCH_A20_OFF"
|
---|
349 | RET
|
---|
350 | PATCH_A20_OFF ENDP
|
---|
351 |
|
---|
352 |
|
---|
353 | ;
|
---|
354 | ;
|
---|
355 | ;
|
---|
356 | ASSUME DS:SV_DATA
|
---|
357 | CLEANUP_A20 PROC NEAR
|
---|
358 | CMP A20_FLAG, FALSE
|
---|
359 | JE SHORT CA20_RET
|
---|
360 | CALL A20_OFF
|
---|
361 | CA20_RET: RET
|
---|
362 | CLEANUP_A20 ENDP
|
---|
363 |
|
---|
364 |
|
---|
365 | ;
|
---|
366 | ; Check if A20 is enabled
|
---|
367 | ;
|
---|
368 | ; Returns AX=0 iff A20 is disabled
|
---|
369 | ;
|
---|
370 | ; Note: disables interrupts
|
---|
371 | ;
|
---|
372 | ASSUME DS:SV_DATA
|
---|
373 |
|
---|
374 | CHECK_A20 PROC NEAR
|
---|
375 | PUSH DS
|
---|
376 | PUSH ES
|
---|
377 | MOV AX, 1 ; Assume A20 is enabled
|
---|
378 | CMP VCPI_FLAG, FALSE ; VCPI active?
|
---|
379 | JNE SHORT CKA20_RET ; Yes -> done
|
---|
380 | MOV AX, 0000H
|
---|
381 | MOV DS, AX ; We compare data at 0000:0000
|
---|
382 | ASSUME DS:NOTHING
|
---|
383 | MOV AX, 0FFFFH ; to data at FFFF:0010
|
---|
384 | MOV ES, AX
|
---|
385 | CLI ; Avoid unexpected things
|
---|
386 | MOV AX, DS:[00H] ; (Divide exception)
|
---|
387 | XOR AX, ES:[10H] ; Equal contents?
|
---|
388 | JNZ SHORT CKA20_RET ; No -> A20 on (or no mem)
|
---|
389 | NOT WORD PTR DS:[00H] ; Change word at 0000:0000
|
---|
390 | MOV AX, DS:[00H] ; Get new value
|
---|
391 | XOR AX, ES:[10H] ; Still equal contents?
|
---|
392 | NOT WORD PTR DS:[00H] ; Restore word at 0000:0000
|
---|
393 | CKA20_RET: POP ES
|
---|
394 | POP DS
|
---|
395 | RET
|
---|
396 | CHECK_A20 ENDP
|
---|
397 |
|
---|
398 | INIT_CODE ENDS
|
---|
399 |
|
---|
400 | END
|
---|