source: vendor/emx/current/src/dos/a20.asm

Last change on this file was 18, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 10.5 KB
Line 
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
35SV_DATA SEGMENT
36
37;
38; Enable/disable A20: address of functions
39;
40A20_ON_JMP DW ?
41A20_OFF_JMP DW ?
42
43A20_FLAG DB FALSE
44USE_A20_PATCH DB FALSE
45USE_FAST_A20 DB FALSE
46
47SV_DATA ENDS
48
49
50INIT_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
59INIT_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;
103INIT_A20_1: LEA BX, AT_A20_ON
104 LEA DX, AT_A20_OFF
105
106INIT_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
110INIT_A20_SET_1: MOV A20_ON_JMP, BX
111 MOV A20_OFF_JMP, DX
112 POP ES
113 RET
114INIT_A20 ENDP
115
116
117DATA_8042 = 60H ; Keyboard processor
118STATUS_8042 = 64H ; Keyboard processor
119
120;
121; Enable address line A20
122;
123; Note: disables interrupts
124;
125 ASSUME DS:SV_DATA
126A20_ON PROC NEAR
127 PUSH AX
128 CLI
129 CALL A20_ON_JMP
130 MOV A20_FLAG, NOT FALSE
131 POP AX
132 RET
133A20_ON ENDP
134
135;
136; Disable address line A20
137;
138; Note: disables interrupts
139;
140 ASSUME DS:SV_DATA
141A20_OFF PROC NEAR
142 PUSH AX
143 CLI
144 CALL A20_OFF_JMP
145 MOV A20_FLAG, FALSE
146 POP AX
147 RET
148A20_OFF ENDP
149
150;
151; Don't enable address line A20
152;
153NO_A20_ON PROC NEAR
154 RET
155NO_A20_ON ENDP
156
157;
158; Don't disable address line A20
159;
160NO_A20_OFF PROC NEAR
161 RET
162NO_A20_OFF ENDP
163
164;
165; Enable address line A20 (AT compatible)
166;
167AT_A20_ON PROC NEAR
168 MOV AH, 0DFH
169 CALL AT_SET_A20
170 RET
171AT_A20_ON ENDP
172
173;
174; Disable address line A20 (AT compatible)
175;
176AT_A20_OFF PROC NEAR
177 MOV AH, 0DDH
178 CALL AT_SET_A20
179 RET
180AT_A20_OFF ENDP
181
182
183;
184; Enable address line A20 (PS/2)
185;
186PS2_A20_ON PROC NEAR
187 IN AL, 92H
188 OR AL, 02H
189 OUT 92H, AL
190 RET
191PS2_A20_ON ENDP
192
193
194;
195; Disable address line A20 (PS/2)
196;
197PS2_A20_OFF PROC NEAR
198 IN AL, 92H
199 AND AL, NOT 02H
200 OUT 92H, AL
201 RET
202PS2_A20_OFF ENDP
203
204
205;
206; Enable address line A20 (Inboard 386/PC)
207;
208INBOARD_A20_ON PROC NEAR
209 MOV AL, 0DFH
210 OUT 60H, AL
211 RET
212INBOARD_A20_ON ENDP
213
214
215;
216; Disable address line A20 (Inboard 386/PC)
217;
218INBOARD_A20_OFF PROC NEAR
219 MOV AL, 0DDH
220 OUT 60H, AL
221 RET
222INBOARD_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;
231AT_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
245AT_SET_A20_END: POP CX
246 RET
247AT_SET_A20 ENDP
248
249
250;
251; Wait until we can send a command to the keyboard controller
252;
253READY_8042 PROC NEAR
254 XOR CX, CX
255 TALIGN 4 ; Avoid surprises
256READY_1: IN AL, STATUS_8042
257 TEST AL, 02H ; Input buffer full?
258 LOOPNZ READY_1 ; Yes -> wait
259 RET
260READY_8042 ENDP
261
262
263FAST_IO_DELAY MACRO
264 LOCAL L1, L2
265 JMP SHORT L1
266L1: JMP SHORT L2
267L2:
268 ENDM
269
270;
271; Enable address line A20 (fast)
272;
273FAST_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
280FAST_A20_ON ENDP
281
282;
283; Disable address line A20 (fast)
284;
285FAST_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
292FAST_A20_OFF ENDP
293
294
295;
296; Enable address line A20 (Fujitsu FMR70)
297;
298FMR70_A20_ON proc near
299 MOV AL, 00110000B
300 OUT 20H, AL
301 RET
302FMR70_A20_ON ENDP
303
304;
305; Disable address line A20 (Fujitsu FMR70)
306;
307FMR70_A20_OFF PROC NEAR
308 MOV AL, 0
309 OUT 20H, AL
310 RET
311FMR70_A20_OFF ENDP
312
313
314;
315; Enable address line A20 (NEC PC-98)
316;
317PC98_A20_ON PROC NEAR
318 MOV AL, 0
319 OUT 0F2H, AL
320 RET
321PC98_A20_ON ENDP
322
323;
324; Disable address line A20 (NEC PC-98)
325;
326PC98_A20_OFF PROC NEAR
327 MOV AL, 0FFH
328 OUT 0F2H, AL
329 RET
330PC98_A20_OFF ENDP
331
332
333;
334; Enable address line A20 (patched)
335;
336PATCH_A20_ON PROC NEAR
337 RET
338 DB "PATCH_A20_ON "
339 RET
340PATCH_A20_ON ENDP
341
342
343;
344; Disable address line A20 (patched)
345;
346PATCH_A20_OFF PROC NEAR
347 RET
348 DB "PATCH_A20_OFF"
349 RET
350PATCH_A20_OFF ENDP
351
352
353;
354;
355;
356 ASSUME DS:SV_DATA
357CLEANUP_A20 PROC NEAR
358 CMP A20_FLAG, FALSE
359 JE SHORT CA20_RET
360 CALL A20_OFF
361CA20_RET: RET
362CLEANUP_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
374CHECK_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
393CKA20_RET: POP ES
394 POP DS
395 RET
396CHECK_A20 ENDP
397
398INIT_CODE ENDS
399
400 END
Note: See TracBrowser for help on using the repository browser.