1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
; $Id: bootsector2-cpu-a20-1.asm $
;; @file
; Bootsector that checks the A20 emulation.
;
;
; Copyright (C) 2007-2019 Oracle Corporation
;
; This file is part of VirtualBox Open Source Edition (OSE), as
; available from http://www.virtualbox.org. This file is free software;
; you can redistribute it and/or modify it under the terms of the GNU
; General Public License (GPL) as published by the Free Software
; Foundation, in version 2 as it comes in the "COPYING" file of the
; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
;
; The contents of this file may alternatively be used under the terms
; of the Common Development and Distribution License Version 1.0
; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
; VirtualBox OSE distribution, in which case the provisions of the
; CDDL are applicable instead of those of the GPL.
;
; You may elect to license modified versions of this file under the
; terms and conditions of either the GPL or the CDDL or both.
;
%include "iprt/asmdefs.mac"
%include "iprt/x86.mac"
%include "VBox/VMMDevTesting.mac"
;
; Include and execute the init code.
;
%define BS2_WITH_TRAPS
%define BS2_INIT_RM
%define BS2_INC_PE16
%define BS2_INC_PE32
%define BS2_INC_PP32
%define BS2_INC_PAE32
%define BS2_INC_LM64
%include "bootsector2-common-init-code.mac"
;
; The benchmark driver
;
BEGINPROC main
;
; Test prologue.
;
mov ax, .s_szTstName
call TestInit_r86
;
; The actual tests.
;
call TestA20_1 ; must come first
call TestA20_rm_rm
;call TestA20_rm_pe16
call TestA20_rm_pe32
call TestA20_rm_pp32
;call TestA20_rm_pp16
call TestA20_rm_pae32
call TestA20_rm_lm64
;
; We're done.
;
call TestTerm_r86
call Bs2Panic
.s_szTstName:
db 'tstA20-1', 0
.s_szInitialA20Status:
db 'Initial A20 state', 0
ENDPROC main
;
; Do some initial tests.
;
BEGINPROC TestA20_1
push eax
push edx
push ecx
push ebx
push edi
;
; Check that the A20 gate is disabled when we come from the BIOS.
;
mov ax, .s_szInitialA20Status
call TestSub_r86
call IsA20GateEnabled_rm
mov di, ax ; save A20 state in AX for bios test.
cmp al, 0
je .initial_state_done
mov ax, .s_szBadInitialA20Status
call TestFailed_r86
jmp .initial_state_done
.s_szInitialA20Status:
db 'Initial A20 state', 0
.s_szBadInitialA20Status:
db 'Initial A20 state is enabled, expected disabled', 10, 13, 0
.initial_state_done:
call TestSubDone_r86
;
; Disable it via the BIOS interface and check.
;
mov ax, .s_szBios
call TestSub_r86
; query support
mov ax, 2403h
int 15h
jnc .bios_2403_ok
movzx edx, ax
mov ax, .s_szBios2403Error
mov cl, VMMDEV_TESTING_UNIT_NONE
call TestValueU32_r86
jmp .bios_2403_done
.bios_2403_ok:
movzx edx, al
mov ax, .s_szBios2403Mask
mov cl, VMMDEV_TESTING_UNIT_NONE
call TestValueU32_r86
.bios_2403_done:
; Check what the bios thinks the state is.
call BiosIsA20GateEnabled_rm
cmp ax, di
je .bios_2402_done
push di
push ax
push word ds
push word .s_szBios2402Error
call TestFailedF_r86
add sp, 8
.bios_2402_done:
; Loop to make sure we get all transitions and ends up with A20 disabled.
mov cx, 10h
.bios_loop:
; enable it
mov ax, 2401h
push cx ; paranoia that seems necessary for at least one AMI bios.
int 15h
pop cx
jnc .bios_continue1
mov ax, .s_szBiosFailed2401
jmp .bios_failed
.bios_continue1:
call IsA20GateEnabled_rm
cmp al, 1
je .bios_continue2
mov ax, .s_szBiosEnableFailed
jmp .bios_failed
.bios_continue2:
; disable
mov ax, 2400h
push cx ; paranoia that seems necessary for at least one AMI bios.
int 15h
pop cx
jnc .bios_continue3
mov ax, .s_szBiosFailed2400
jmp .bios_failed
.bios_continue3:
call IsA20GateEnabled_rm
cmp al, 0
je .bios_continue4
mov ax, .s_szBiosDisableFailed
jmp .bios_failed
.bios_continue4:
loop .bios_loop
jmp .bios_done
.s_szBios:
db 'INT 15h AH=24 A20 Gate interface', 0
.s_szBios2403Mask:
db 'AX=2403 return (AL)', 0
.s_szBios2403Error:
db 'AX=2403 error (AX)', 10, 13, 0
.s_szBios2402Error:
db '2402h -> AX=%RX16 expected %RX16', 10, 13, 0
.s_szBiosFailed2400:
db '2400h interface failed', 10, 13, 0
.s_szBiosFailed2401:
db '2401h interface failed', 10, 13, 0
.s_szBiosDisableFailed:
db 'BIOS failed to disable A20 (or bad CPU)', 10, 13, 0
.s_szBiosEnableFailed:
db 'BIOS failed to enable A20', 10, 13, 0
.bios_failed:
call TestFailed_r86
.bios_done:
call TestSubDone_r86
call Bs2DisableA20ViaPortA_r86
call Bs2DisableA20ViaKbd_r86
;
; Test the fast A20 gate interface.
;
mov ax, .s_szFastA20
call TestSub_r86
mov cx, 10h
.fast_loop:
call Bs2EnableA20ViaPortA_r86
call IsA20GateEnabled_rm
cmp al, 1
mov ax, .s_szFastEnableFailed
jne .fast_failed
call Bs2DisableA20ViaPortA_r86
call IsA20GateEnabled_rm
cmp al, 0
mov ax, .s_szFastDisableFailed
jne .fast_failed
loop .fast_loop
jmp .fast_done
.s_szFastA20:
db 'Fast A20 Gate Interface', 0
.s_szFastDisableFailed:
db 'Fast A20 gate disabling failed', 10, 13, 0
.s_szFastEnableFailed:
db 'Fast A20 gate enabling failed', 10, 13, 0
.fast_failed:
call TestFailed_r86
.fast_done:
call TestSubDone_r86
call Bs2DisableA20ViaPortA_r86
call Bs2DisableA20ViaKbd_r86
;
; Test the keyboard interface.
;
mov ax, .s_szKeyboardA20
call TestSub_r86
mov cx, 10h
.kbd_loop:
call Bs2EnableA20ViaKbd_r86
call IsA20GateEnabled_rm
cmp al, 1
mov ax, .s_szKbdEnableFailed
jne .kbd_failed
call Bs2DisableA20ViaKbd_r86
call IsA20GateEnabled_rm
cmp al, 0
mov ax, .s_szKbdDisableFailed
jne .kbd_failed
loop .kbd_loop
jmp .kbd_done
.s_szKeyboardA20:
db 'Keyboard A20 Gate Interface', 0
.s_szKbdDisableFailed:
db 'Disabling the A20 gate via the keyboard controller failed', 10, 13, 0
.s_szKbdEnableFailed:
db 'Enabling the A20 gate via the keyboard controller failed', 10, 13, 0
.kbd_failed:
call TestFailed_r86
.kbd_done:
call TestSubDone_r86
call Bs2DisableA20ViaPortA_r86
call Bs2DisableA20ViaKbd_r86
pop edi
pop ebx
pop ecx
pop edx
pop eax
ret
ENDPROC TestA20_1
;;
; Checks if the A20 gate is enabled.
;
; This is do by temporarily changing a word at address 0000000h and see if this
; is reflected at address 0100000h (1 MB). The word written is
; ~*(word *)0x100000h to make sure it won't accidentally match.
;
; @returns ax 1 if enabled, 0 if disabled.
;
BEGINPROC IsA20GateEnabled_rm
push ds
push es
push dx
pushf
cli
.once_again:
xor ax, ax
mov ds, ax
dec ax
mov es, ax
mov ax, [es:0010h] ; 0ffff:0010 => 0100000h (1 MB)
mov dx, [ds:0000h] ; 00000:0000 => 0000000h - save it
not ax
mov [ds:0000h], ax ; 0000000h - write ~[0100000h]
cmp [es:0010h], ax ; 0100000h - same as 0000000h if A20 is disabled.
mov [ds:0000h], dx ; 0000000h - restore original value
setne al
movzx ax, al
popf
pop dx
pop es
pop ds
ret
ENDPROC IsA20GateEnabled_rm
;;
; Checks if the BIOS thinks the A20 gate is enabled.
;
; @returns ax 1 if enabled, 0 if disabled.
;
BEGINPROC BiosIsA20GateEnabled_rm
push ecx
push eax
mov ax, 2402h
int 15h
jnc .ok
mov al, 080h
.ok:
mov cx, ax
pop eax
mov ax, cx
pop ecx
ret
ENDPROC BiosIsA20GateEnabled_rm
;
; Instantiate the template code.
;
%include "bootsector2-template-footer.mac" ; reset the initial environemnt.
%define TMPL_RM
%include "bootsector2-cpu-a20-1-template.mac"
;%define TMPL_CMN_V86
;%include "bootsector2-cpu-a20-1-template.mac"
%define TMPL_PE16
%include "bootsector2-cpu-a20-1-template.mac"
%define TMPL_PE32
%include "bootsector2-cpu-a20-1-template.mac"
;%define TMPL_PP16
;%include "bootsector2-cpu-a20-1-template.mac"
%define TMPL_PP32
%include "bootsector2-cpu-a20-1-template.mac"
;%define TMPL_PAE16
;%include "bootsector2-cpu-a20-1-template.mac"
%define TMPL_PAE32
%include "bootsector2-cpu-a20-1-template.mac"
;%define TMPL_LM16
;%include "bootsector2-cpu-a20-1-template.mac"
;%define TMPL_LM32
;%include "bootsector2-cpu-a20-1-template.mac"
%define TMPL_LM64
%include "bootsector2-cpu-a20-1-template.mac"
;
; End sections and image.
;
%include "bootsector2-common-end.mac"
|