1 | ; $Id: bootsector2-cpu-a20-1-template.mac 82968 2020-02-04 10:35:17Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; bootsector2 A20 - multi mode template.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2020 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 |
|
---|
28 | %include "bootsector2-template-header.mac"
|
---|
29 |
|
---|
30 |
|
---|
31 | ;;
|
---|
32 | ; Inner loop dealing with one 64KB segment.
|
---|
33 | ;
|
---|
34 | BEGINPROC TMPL_NM(TestA20_EnabledInner)
|
---|
35 | .inner_loop:
|
---|
36 | mov ah, [es:xDI]
|
---|
37 | mov al, [ds:xSI]
|
---|
38 | cmp al, ah
|
---|
39 | jne .inner_next
|
---|
40 |
|
---|
41 | not al
|
---|
42 | mov [es:xDI], al
|
---|
43 | cmp al, [ds:xSI]
|
---|
44 | mov [es:xDI], ah
|
---|
45 | je .failed
|
---|
46 |
|
---|
47 | .inner_next:
|
---|
48 | inc xDI
|
---|
49 | inc xSI
|
---|
50 | dec ecx
|
---|
51 | jnz .inner_loop
|
---|
52 |
|
---|
53 | clc
|
---|
54 | ret
|
---|
55 |
|
---|
56 | .failed:
|
---|
57 | push sBX
|
---|
58 | push sAX
|
---|
59 | push sSI
|
---|
60 | push sDI
|
---|
61 | %ifdef TMPL_16BIT
|
---|
62 | push cs
|
---|
63 | %endif
|
---|
64 | push .s_szModifiyError
|
---|
65 | call TMPL_NM_CMN(TestFailedF)
|
---|
66 | add xSP, sCB * 5
|
---|
67 | stc
|
---|
68 | ret
|
---|
69 | .s_szModifiyError:
|
---|
70 | db TMPL_MODE_STR, '- Same memory; EDI=%RX32 ESI=%RX32 EAX=%RX32 EBX=%RX32', 13, 10, 0
|
---|
71 | ENDPROC TMPL_NM(TestA20_EnabledInner)
|
---|
72 |
|
---|
73 |
|
---|
74 | ;;
|
---|
75 | ; Inner loop dealing with one 64KB segment.
|
---|
76 | ;
|
---|
77 | BEGINPROC TMPL_NM(TestA20_DisabledInner)
|
---|
78 | .inner_loop:
|
---|
79 | mov ah, [es:xDI]
|
---|
80 | mov al, [ds:xSI]
|
---|
81 | cmp al, ah
|
---|
82 | jne .failed1
|
---|
83 |
|
---|
84 | not al
|
---|
85 | mov [es:xDI], al
|
---|
86 | cmp al, [ds:xSI]
|
---|
87 | mov [es:xDI], ah
|
---|
88 | jne .failed2
|
---|
89 |
|
---|
90 | inc xDI
|
---|
91 | inc xSI
|
---|
92 | dec ecx
|
---|
93 | jnz .inner_loop
|
---|
94 |
|
---|
95 | clc
|
---|
96 | ret
|
---|
97 |
|
---|
98 | .failed1:
|
---|
99 | push sCX
|
---|
100 | push sBX
|
---|
101 | push sAX
|
---|
102 | push sSI
|
---|
103 | push sDI
|
---|
104 | %ifdef TMPL_16BIT
|
---|
105 | push cs
|
---|
106 | %endif
|
---|
107 | push .s_szNotEqual
|
---|
108 | call TMPL_NM_CMN(TestFailedF)
|
---|
109 | add xSP, sCB * 6
|
---|
110 | stc
|
---|
111 | ret
|
---|
112 | .s_szNotEqual:
|
---|
113 | db TMPL_MODE_STR, ' - Not equal; EDI=%RX32 ESI=%RX32 EAX=%RX32 EBX=%RX32 ECX=%RX32', 13, 10, 0
|
---|
114 |
|
---|
115 | .failed2:
|
---|
116 | push sCX
|
---|
117 | push sBX
|
---|
118 | push sAX
|
---|
119 | push sSI
|
---|
120 | push sDI
|
---|
121 | %ifdef TMPL_16BIT
|
---|
122 | push cs
|
---|
123 | %endif
|
---|
124 | push .s_szModifiyError
|
---|
125 | call TMPL_NM_CMN(TestFailedF)
|
---|
126 | add xSP, sCB * 6
|
---|
127 | stc
|
---|
128 | ret
|
---|
129 |
|
---|
130 | .s_szModifiyError:
|
---|
131 | db TMPL_MODE_STR, ' - Modify error; EDI=%RX32 ESI=%RX32 EAX=%RX32 EBX=%RX32 ECX=%RX32', 13, 10, 0
|
---|
132 | ENDPROC TMPL_NM(TestA20_DisabledInner)
|
---|
133 |
|
---|
134 |
|
---|
135 | ;;
|
---|
136 | ; Scans memory calling sDX for each segment.
|
---|
137 | ;
|
---|
138 | BEGINPROC TMPL_NM(TestA20_ScanMemory)
|
---|
139 | push sAX
|
---|
140 | push sBX
|
---|
141 | push sCX
|
---|
142 | push sDX
|
---|
143 | push sSI
|
---|
144 | push sDI
|
---|
145 | pushf
|
---|
146 | cli
|
---|
147 | %ifdef TMPL_16BIT
|
---|
148 | push es
|
---|
149 | push ds
|
---|
150 | %endif
|
---|
151 |
|
---|
152 | ;
|
---|
153 | ; The outer loop walks a segment (64 KB) at a time.
|
---|
154 | ;
|
---|
155 | mov ebx, _1M
|
---|
156 | .outer_loop:
|
---|
157 |
|
---|
158 | ; Set up the registers.
|
---|
159 | %ifdef TMPL_CMN_R86
|
---|
160 | mov ax, 0ffffh
|
---|
161 | mov edi, 00010h
|
---|
162 | mov es, ax
|
---|
163 | mov ax, 00000h
|
---|
164 | mov esi, 00000h
|
---|
165 | mov ds, ax
|
---|
166 | mov ecx, 01000h ; at 101000 there is a VMMDevTesting MMIO page.
|
---|
167 | %elifdef TMPL_16BIT
|
---|
168 | ;; @todo need a selector we can modify.
|
---|
169 | jmp .done
|
---|
170 |
|
---|
171 | %else
|
---|
172 | mov edi, ebx
|
---|
173 | mov esi, ebx
|
---|
174 | and esi, ~_1M
|
---|
175 | mov ecx, _64K
|
---|
176 | %endif
|
---|
177 | %ifndef TMPL_CMN_R86
|
---|
178 | ; Should we skip this segment or only check parts of it?
|
---|
179 | cmp esi, edi ; affected by A20?
|
---|
180 | je .outer_next
|
---|
181 |
|
---|
182 | %if BS2_PXX_LAST != 09ffffh
|
---|
183 | %error BS2_PXX_LAST does not have the expected value.
|
---|
184 | %endif
|
---|
185 | cmp ebx, BS2_PXX_BASE + _1M ; don't mess with page tables, stacks, MMIO or ROMs.
|
---|
186 | jb .not_low_rom_mmio_region
|
---|
187 | cmp ebx, _1M + _1M
|
---|
188 | jb .outer_next
|
---|
189 | .not_low_rom_mmio_region:
|
---|
190 |
|
---|
191 | cmp ebx, BS2_ADDR + _1M
|
---|
192 | ja .not_bs2
|
---|
193 | mov ecx, BS2_ADDR ; don't overwrite our own code.
|
---|
194 | .not_bs2:
|
---|
195 | cmp ebx, _1M
|
---|
196 | jne .not_VMMDevTestingMMIO
|
---|
197 | mov ecx, 1000h ; don't bother with the MMIO
|
---|
198 | .not_VMMDevTestingMMIO:
|
---|
199 | %endif ; TMPL_CMN_R86
|
---|
200 |
|
---|
201 | ; Invoke the callback.
|
---|
202 | call xDX
|
---|
203 | jc .failure
|
---|
204 |
|
---|
205 | %ifndef TMPL_CMN_R86
|
---|
206 | .outer_next:
|
---|
207 | add ebx, _64K
|
---|
208 | cmp ebx, 32*_1M
|
---|
209 | jbe .outer_loop
|
---|
210 | %endif
|
---|
211 |
|
---|
212 | .done:
|
---|
213 | %ifdef TMPL_16BIT
|
---|
214 | pop ds
|
---|
215 | pop es
|
---|
216 | %endif
|
---|
217 | popf
|
---|
218 | pop sDI
|
---|
219 | pop sSI
|
---|
220 | pop sDX
|
---|
221 | pop sCX
|
---|
222 | pop sBX
|
---|
223 | pop sAX
|
---|
224 | ret
|
---|
225 |
|
---|
226 | .failure:
|
---|
227 | %if 1
|
---|
228 | cmp ebx, _1M
|
---|
229 | je .contine_at_next_MB
|
---|
230 | cmp ebx, _2M
|
---|
231 | je .contine_at_next_MB
|
---|
232 | cmp ebx, _1M + _2M
|
---|
233 | je .contine_at_next_MB
|
---|
234 | cmp ebx, _4M
|
---|
235 | je .contine_at_next_MB
|
---|
236 | %endif
|
---|
237 | jmp .done
|
---|
238 |
|
---|
239 | .contine_at_next_MB:
|
---|
240 | add ebx, _1M
|
---|
241 | jmp .outer_loop
|
---|
242 | ENDPROC TMPL_NM(TestA20_ScanMemory)
|
---|
243 |
|
---|
244 |
|
---|
245 | BEGINPROC TMPL_NM(TestA20_Enabled)
|
---|
246 | push sDX
|
---|
247 | mov xDX, TMPL_NM(TestA20_EnabledInner)
|
---|
248 | call TMPL_NM(TestA20_ScanMemory)
|
---|
249 | pop sDX
|
---|
250 | ret
|
---|
251 | ENDPROC TMPL_NM(TestA20_Enabled)
|
---|
252 |
|
---|
253 |
|
---|
254 | ;;
|
---|
255 | ; Checks that the first 64KB at 1MB wraps is the same physical memory as at
|
---|
256 | ; address 0.
|
---|
257 | ;
|
---|
258 | BEGINPROC TMPL_NM(TestA20_Disabled)
|
---|
259 | push sDX
|
---|
260 | mov xDX, TMPL_NM(TestA20_DisabledInner)
|
---|
261 | call TMPL_NM(TestA20_ScanMemory)
|
---|
262 | pop sDX
|
---|
263 | ret
|
---|
264 | ENDPROC TMPL_NM(TestA20_Disabled)
|
---|
265 |
|
---|
266 |
|
---|
267 | BEGINPROC TMPL_NM(TestA20_FlushAll)
|
---|
268 | push sAX
|
---|
269 | wbinvd
|
---|
270 | mov sAX, cr3
|
---|
271 | mov cr3, sAX
|
---|
272 | wbinvd
|
---|
273 | pop sAX
|
---|
274 | ret
|
---|
275 | ENDPROC TMPL_NM(TestA20_FlushAll)
|
---|
276 |
|
---|
277 |
|
---|
278 |
|
---|
279 | ;;
|
---|
280 | ; Do the A20 tests for this mode.
|
---|
281 | ;
|
---|
282 | ; @uses nothing
|
---|
283 | ;
|
---|
284 | BEGINCODELOW
|
---|
285 | BITS 16
|
---|
286 | BEGINPROC TMPL_NM(TestA20_rm)
|
---|
287 | push eax
|
---|
288 |
|
---|
289 | mov ax, .s_szTestName
|
---|
290 | call TestSub_r86
|
---|
291 |
|
---|
292 | call TMPL_NM(Bs2IsModeSupported_rm)
|
---|
293 | jz .skip_not_supported
|
---|
294 |
|
---|
295 | ;
|
---|
296 | ; Do tests with A20 enabled.
|
---|
297 | ;
|
---|
298 | call Bs2EnableA20_r86
|
---|
299 | call TMPL_NM(Bs2EnterMode_rm)
|
---|
300 | BITS TMPL_BITS
|
---|
301 | call TMPL_NM(TestA20_FlushAll)
|
---|
302 | call TMPL_NM(TestA20_Enabled)
|
---|
303 | call TMPL_NM(Bs2ExitMode)
|
---|
304 | BITS 16
|
---|
305 | call TestSubErrorCount_r86
|
---|
306 | cmp ax, 0
|
---|
307 | jne .done
|
---|
308 |
|
---|
309 | ;
|
---|
310 | ; Do tests with A20 disabled.
|
---|
311 | ;
|
---|
312 | call Bs2DisableA20_r86
|
---|
313 | call TMPL_NM(Bs2EnterMode_rm)
|
---|
314 | BITS TMPL_BITS
|
---|
315 | call TMPL_NM(TestA20_FlushAll)
|
---|
316 | call TMPL_NM(TestA20_Disabled)
|
---|
317 | call TMPL_NM(Bs2ExitMode)
|
---|
318 | BITS 16
|
---|
319 | call TestSubErrorCount_r86
|
---|
320 | cmp ax, 0
|
---|
321 | jne .done
|
---|
322 |
|
---|
323 | %ifndef TMPL_CMN_V86
|
---|
324 | ;
|
---|
325 | ; Change A20 state without leaving and entering the CPU mode.
|
---|
326 | ;
|
---|
327 | call Bs2EnableA20_r86
|
---|
328 | call TMPL_NM(Bs2EnterMode_rm)
|
---|
329 | BITS TMPL_BITS
|
---|
330 | call TMPL_NM(TestA20_Enabled)
|
---|
331 |
|
---|
332 | call TMPL_NM_CMN(Bs2DisableA20)
|
---|
333 | call TMPL_NM(TestA20_FlushAll)
|
---|
334 | call TMPL_NM(TestA20_Disabled)
|
---|
335 |
|
---|
336 | call TMPL_NM_CMN(Bs2EnableA20)
|
---|
337 | call TMPL_NM(TestA20_FlushAll)
|
---|
338 | call TMPL_NM(TestA20_Enabled)
|
---|
339 |
|
---|
340 | call TMPL_NM_CMN(Bs2DisableA20)
|
---|
341 | call TMPL_NM(TestA20_FlushAll)
|
---|
342 | call TMPL_NM(TestA20_Disabled)
|
---|
343 |
|
---|
344 | call TMPL_NM_CMN(Bs2EnableA20)
|
---|
345 | call TMPL_NM(TestA20_FlushAll)
|
---|
346 | call TMPL_NM(TestA20_Enabled)
|
---|
347 |
|
---|
348 | call TMPL_NM(Bs2ExitMode)
|
---|
349 | BITS 16
|
---|
350 | %endif ; !TMPL_CMN_V86
|
---|
351 |
|
---|
352 | .done:
|
---|
353 | call Bs2DisableA20_r86
|
---|
354 | .done1:
|
---|
355 | call TestSubDone_r86
|
---|
356 |
|
---|
357 | pop eax
|
---|
358 | ret
|
---|
359 |
|
---|
360 | .skip_not_supported:
|
---|
361 | mov eax, .s_szSkipNotSupported
|
---|
362 | call TestSkipped_r86
|
---|
363 | jmp .done1
|
---|
364 |
|
---|
365 | .s_szTestName:
|
---|
366 | db TMPL_MODE_STR, 0
|
---|
367 | .s_szSkipNotSupported:
|
---|
368 | db TMPL_MODE_STR, ' is not supported by the CPU', 10, 13, 0
|
---|
369 | ENDPROC TMPL_NM(TestA20_rm)
|
---|
370 | TMPL_BEGINCODE
|
---|
371 | BITS TMPL_BITS
|
---|
372 |
|
---|
373 |
|
---|
374 | %include "bootsector2-template-footer.mac"
|
---|
375 |
|
---|