1 | ; $Id: bootsector2-triple-fault-1.asm 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; Bootsector for testing triple faults.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2022 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 |
|
---|
38 | %include "iprt/asmdefs.mac"
|
---|
39 | %include "iprt/x86.mac"
|
---|
40 | %include "VBox/VMMDevTesting.mac"
|
---|
41 |
|
---|
42 | ;; The number of instructions to test.
|
---|
43 | %define TEST_INSTRUCTION_COUNT_IO 2000000
|
---|
44 |
|
---|
45 | ;; The number of instructions to test.
|
---|
46 | %define TEST_INSTRUCTION_COUNT_MMIO 750000
|
---|
47 |
|
---|
48 | ;; Define this to drop unnecessary test variations.
|
---|
49 | %define QUICK_TEST
|
---|
50 |
|
---|
51 | ;
|
---|
52 | ; Include and execute the init code.
|
---|
53 | ;
|
---|
54 | %define BS2_INIT_RM
|
---|
55 | %define BS2_INC_PE16
|
---|
56 | %define BS2_INC_PE32
|
---|
57 | %define BS2_INC_PP32
|
---|
58 | %define BS2_INC_PAE32
|
---|
59 | %define BS2_INC_LM64
|
---|
60 | %include "bootsector2-common-init-code.mac"
|
---|
61 |
|
---|
62 |
|
---|
63 | ;
|
---|
64 | ; The test driver
|
---|
65 | ;
|
---|
66 | BEGINPROC main
|
---|
67 | ;
|
---|
68 | ; Test prologue.
|
---|
69 | ;
|
---|
70 | mov ax, .s_szTstName
|
---|
71 | call TestInit_r86
|
---|
72 | call Bs2EnableA20_r86
|
---|
73 |
|
---|
74 | ;
|
---|
75 | ; Did we get here from a reboot triggered below?
|
---|
76 | ;
|
---|
77 | push ds
|
---|
78 | mov ax, 2000h ; 128 KB is enough for the test program
|
---|
79 | .boot_check_loop:
|
---|
80 | mov ds, ax
|
---|
81 | cmp dword [0], 064726962h
|
---|
82 | jne .boot_check_next
|
---|
83 | cmp dword [4], 062697264h
|
---|
84 | je .warm_reset_broken
|
---|
85 |
|
---|
86 | .boot_check_next:
|
---|
87 | mov dword [0], 064726962h
|
---|
88 | mov dword [4], 062697264h
|
---|
89 | add ax, 1000h
|
---|
90 | cmp ax, 8000h
|
---|
91 | jbe .boot_check_loop
|
---|
92 | pop ds
|
---|
93 | jmp .fine
|
---|
94 |
|
---|
95 | .warm_reset_broken:
|
---|
96 | pop ds
|
---|
97 | mov ax, .s_szWarmResetBroken
|
---|
98 | call NAME(TestFailed_r86)
|
---|
99 | jmp .done
|
---|
100 | .s_szWarmResetBroken:
|
---|
101 | db 'Warm reset vector support is broken', 0dh, 0ah, 0
|
---|
102 | .fine:
|
---|
103 |
|
---|
104 | ;
|
---|
105 | ; Test that the warm reset interface works.
|
---|
106 | ;
|
---|
107 | mov ax, .s_szPrecondTest5
|
---|
108 | call NAME(TestSub_r86)
|
---|
109 | mov al, 05h
|
---|
110 | call NAME(SetWarmResetJmp)
|
---|
111 | cmp ax, 0
|
---|
112 | jne .precond_test_A
|
---|
113 | call NAME(TestReboot_r86)
|
---|
114 |
|
---|
115 | .precond_test_A:
|
---|
116 | mov ax, .s_szPrecondTestA
|
---|
117 | call NAME(TestSub_r86)
|
---|
118 | mov al, 0Ah
|
---|
119 | call NAME(SetWarmResetJmp)
|
---|
120 | cmp ax, 0
|
---|
121 | jne .precond_test_A_passed
|
---|
122 | call NAME(TestReboot_r86)
|
---|
123 | .precond_test_A_passed:
|
---|
124 | call NAME(TestSubDone_r86)
|
---|
125 |
|
---|
126 | ;
|
---|
127 | ; The real tests.
|
---|
128 | ;
|
---|
129 |
|
---|
130 |
|
---|
131 | ;
|
---|
132 | ; We're done.
|
---|
133 | ;
|
---|
134 | .done:
|
---|
135 | call NAME(TestTerm_r86)
|
---|
136 | call Bs2Panic
|
---|
137 |
|
---|
138 | .s_szTstName:
|
---|
139 | db 'tstTriple', 0
|
---|
140 | .s_szPrecondTest5:
|
---|
141 | db 'Shutdown Action 5', 0
|
---|
142 | .s_szPrecondTestA:
|
---|
143 | db 'Shutdown Action A', 0
|
---|
144 | ENDPROC main
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 | ;;
|
---|
149 | ; Sets up the warm reset vector.
|
---|
150 | ;
|
---|
151 | ; @param ax Where to resume exeuction.
|
---|
152 | ; @param dl Shutdown action command to use, 5h or Fh.
|
---|
153 | ;
|
---|
154 | ; @uses nothing
|
---|
155 | ;
|
---|
156 | BEGINPROC SetUpWarmReset
|
---|
157 | push bp
|
---|
158 | mov bp, sp
|
---|
159 | push eax
|
---|
160 | push ebx
|
---|
161 | push ecx
|
---|
162 | push edx
|
---|
163 | push edi
|
---|
164 | push esi
|
---|
165 | push es
|
---|
166 |
|
---|
167 | ;
|
---|
168 | ; Set up the warm reboot vector.
|
---|
169 | ;
|
---|
170 | mov bx, 40h
|
---|
171 | mov es, bx
|
---|
172 |
|
---|
173 | mov ecx, [es:67h] ; debug
|
---|
174 | mov word [es:67h], ax
|
---|
175 | mov bx, cs
|
---|
176 | mov word [es:67h+2], bx
|
---|
177 |
|
---|
178 | mov bx, [es:72h] ; debug
|
---|
179 | mov word [es:72h], 1234h ; warm reboot
|
---|
180 |
|
---|
181 | wbinvd
|
---|
182 |
|
---|
183 | mov al, 0fh
|
---|
184 | out 70h, al ; set register index
|
---|
185 | in al, 71h
|
---|
186 | mov ah, al ; debug
|
---|
187 | mov al, dl ; shutdown action command
|
---|
188 | out 71h, al ; set cmos[f] = a - invoke testResume as early as possible.
|
---|
189 | in al, 71h ; debug / paranoia
|
---|
190 | movzx si, al
|
---|
191 |
|
---|
192 | ; Debug print.
|
---|
193 | %if 1
|
---|
194 | mov di, sp ; save sp (lazy bird)
|
---|
195 | in al, 64h
|
---|
196 | push ax ; kbd status
|
---|
197 | push si ; cmos[f] after
|
---|
198 | mov al, ah ; cmos[f] before
|
---|
199 | push ax
|
---|
200 | push word [0472h] ; 40:72 word after
|
---|
201 | push bx ; 40:72 word before
|
---|
202 | push word [0467h] ; 40:67 far addr after
|
---|
203 | push word [0469h]
|
---|
204 | push cx ; 40:67 far addr before
|
---|
205 | shr ecx, 16
|
---|
206 | push dx
|
---|
207 | push ds
|
---|
208 | push .s_szDebugFmt
|
---|
209 | call NAME(PrintF_r86)
|
---|
210 | mov sp, di ; restore sp.
|
---|
211 | ;.forever:
|
---|
212 | ; cli
|
---|
213 | ; hlt
|
---|
214 | ; jmp .forever
|
---|
215 | %endif
|
---|
216 |
|
---|
217 | pop es
|
---|
218 | pop esi
|
---|
219 | pop edi
|
---|
220 | pop edx
|
---|
221 | pop ecx
|
---|
222 | pop ebx
|
---|
223 | pop eax
|
---|
224 | leave
|
---|
225 | ret
|
---|
226 |
|
---|
227 | .s_szDebugFmt:
|
---|
228 | db 'dbg: 40:67=%RX16:%RX16 (%RX16:%RX16) 40:72=%RX16 (%RX16) cmos[f]=%RX8 (%RX8) kbdsts=%RX8', 0dh, 0ah, 0
|
---|
229 | ENDPROC SetUpWarmReset
|
---|
230 |
|
---|
231 |
|
---|
232 | ;;
|
---|
233 | ; Sets up the warm reset vector.
|
---|
234 | ;
|
---|
235 | ; @returns ax = 0 on setup call, ax = 1 on resume return.
|
---|
236 | ; @param al Shutdown action command to use, 5h or Fh.
|
---|
237 | ; @uses ax
|
---|
238 | ;
|
---|
239 | BEGINPROC SetWarmResetJmp
|
---|
240 | push bp
|
---|
241 | mov bp, sp
|
---|
242 | push dx
|
---|
243 |
|
---|
244 | mov dl, al
|
---|
245 | mov ax, .resume
|
---|
246 | call NAME(SetUpWarmReset)
|
---|
247 |
|
---|
248 | %ifdef DEBUG
|
---|
249 | push cs
|
---|
250 | push .s_szDbg1
|
---|
251 | call NAME(PrintF_r86)
|
---|
252 | add sp, 4
|
---|
253 | %endif
|
---|
254 |
|
---|
255 | mov ax, .s_ResumeRegs
|
---|
256 | call NAME(TestSaveRegisters_r86)
|
---|
257 |
|
---|
258 | %ifdef DEBUG
|
---|
259 | push cs
|
---|
260 | push .s_szDbg2
|
---|
261 | call NAME(PrintF_r86)
|
---|
262 | add sp, 4
|
---|
263 | %endif
|
---|
264 |
|
---|
265 | mov dx, [bp - 2]
|
---|
266 | mov [.s_ResumeRegs + BS2REGS.rdx], dx
|
---|
267 | mov ax, bp
|
---|
268 | add ax, 4
|
---|
269 | mov [.s_ResumeRegs + BS2REGS.rsp], ax
|
---|
270 | mov ax, [bp]
|
---|
271 | mov [.s_ResumeRegs + BS2REGS.rbp], ax
|
---|
272 | mov ax, [bp + 2]
|
---|
273 | mov [.s_ResumeRegs + BS2REGS.rip], ax
|
---|
274 | mov word [.s_ResumeRegs + BS2REGS.rax], 1
|
---|
275 |
|
---|
276 | %ifdef DEBUG
|
---|
277 | push cs
|
---|
278 | push .s_szDbg3
|
---|
279 | call NAME(PrintF_r86)
|
---|
280 | add sp, 4
|
---|
281 | %endif
|
---|
282 |
|
---|
283 | xor ax, ax
|
---|
284 | .done:
|
---|
285 | pop dx
|
---|
286 | leave
|
---|
287 | ret
|
---|
288 |
|
---|
289 | .resume:
|
---|
290 | cli
|
---|
291 | xor ax, ax
|
---|
292 | mov ds, ax
|
---|
293 | mov es, ax
|
---|
294 | mov ax, [.s_ResumeRegs + BS2REGS.ss]
|
---|
295 | mov ss, ax
|
---|
296 | mov esp, [.s_ResumeRegs + BS2REGS.rsp]
|
---|
297 | mov ebp, [.s_ResumeRegs + BS2REGS.rbp]
|
---|
298 |
|
---|
299 | %ifdef DEBUG
|
---|
300 | push ds
|
---|
301 | push .s_szDbg4
|
---|
302 | call NAME(PrintF_r86)
|
---|
303 | add sp, 4
|
---|
304 | %endif
|
---|
305 |
|
---|
306 | mov ax, .s_ResumeRegs
|
---|
307 | call NAME(TestRestoreRegisters_r86)
|
---|
308 | mov ax, [.s_ResumeRegs + BS2REGS.rip]
|
---|
309 | push ax
|
---|
310 | mov ax, 1
|
---|
311 | ret
|
---|
312 | ;jmp word [.s_ResumeRegs + BS2REGS.rip]
|
---|
313 |
|
---|
314 | .s_ResumeRegs:
|
---|
315 | times (BS2REGS_size) db 0
|
---|
316 | %ifdef DEBUG
|
---|
317 | .s_szDbg1:
|
---|
318 | db 'dbg 1', 0dh, 0ah, 0
|
---|
319 | .s_szDbg2:
|
---|
320 | db 'dbg 2', 0dh, 0ah, 0
|
---|
321 | .s_szDbg3:
|
---|
322 | db 'dbg 3', 0dh, 0ah, 0
|
---|
323 | .s_szDbg4:
|
---|
324 | db 'dbg 4', 0dh, 0ah, 0
|
---|
325 | %endif
|
---|
326 | ENDPROC SetWarmResetJmp
|
---|
327 |
|
---|
328 |
|
---|
329 | ;;
|
---|
330 | ; Reboot the machine. Will not return.
|
---|
331 | ;
|
---|
332 | BEGINPROC TestReboot_r86
|
---|
333 | %ifdef DEBUG
|
---|
334 | ; Debug
|
---|
335 | push ds
|
---|
336 | push .s_szDbg
|
---|
337 | call NAME(PrintF_r86)
|
---|
338 | %endif
|
---|
339 | ; Via port A
|
---|
340 | in al, 92h
|
---|
341 | and al, ~1
|
---|
342 | out 92h, al
|
---|
343 | or al, 1
|
---|
344 | out 92h, al
|
---|
345 | in al, 92h
|
---|
346 | .forever:
|
---|
347 | cli
|
---|
348 | hlt
|
---|
349 | jmp .forever
|
---|
350 | %ifdef DEBUG
|
---|
351 | .s_szDbg:
|
---|
352 | db 'Rebooting...', 0dh, 0ah, 0
|
---|
353 | %endif
|
---|
354 | ENDPROC TestReboot_r86
|
---|
355 |
|
---|
356 |
|
---|
357 | ;
|
---|
358 | ; Instantiate the template code.
|
---|
359 | ;
|
---|
360 | %include "bootsector2-template-footer.mac" ; reset the initial environemnt.
|
---|
361 |
|
---|
362 | ;%define TMPL_RM
|
---|
363 | ;%include "bootsector2-test1-template.mac"
|
---|
364 | ;%define TMPL_CMN_V86
|
---|
365 | ;%include "bootsector2-test1-template.mac"
|
---|
366 | ;%define TMPL_PE16
|
---|
367 | ;%include "bootsector2-test1-template.mac"
|
---|
368 | ;%define TMPL_PE32
|
---|
369 | ;%include "bootsector2-test1-template.mac"
|
---|
370 | ;%define TMPL_PP16
|
---|
371 | ;%include "bootsector2-test1-template.mac"
|
---|
372 | ;%define TMPL_PP32
|
---|
373 | ;%include "bootsector2-test1-template.mac"
|
---|
374 | ;%define TMPL_PAE16
|
---|
375 | ;%include "bootsector2-test1-template.mac"
|
---|
376 | ;%define TMPL_PAE32
|
---|
377 | ;%include "bootsector2-test1-template.mac"
|
---|
378 | ;%define TMPL_LM16
|
---|
379 | ;%include "bootsector2-test1-template.mac"
|
---|
380 | ;%define TMPL_LM32
|
---|
381 | ;%include "bootsector2-test1-template.mac"
|
---|
382 | ;%define TMPL_LM64
|
---|
383 | ;%include "bootsector2-test1-template.mac"
|
---|
384 |
|
---|
385 |
|
---|
386 | ;
|
---|
387 | ; End sections and image.
|
---|
388 | ;
|
---|
389 | %include "bootsector2-common-end.mac"
|
---|
390 |
|
---|