VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesByOne.c@ 95491

Last change on this file since 95491 was 95491, checked in by vboxsync, 2 years ago

ValKit/bs3kit: Added Bs3ExtCtxRestoreEx, Bs3ExtCtxSaveEx, Bs3RegCtxConvertV86ToRm, Bs3TrapSetJmpAndRestoreInRm, and BS3TESTMODEBYONEENTRY_F_REAL_MODE_READY so that it is possible to use a 32-bit test driver to do 64-bit testing as well as real-mode. bugref:9898

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.2 KB
Line 
1/* $Id: bs3-mode-TestDoModesByOne.c 95491 2022-07-03 23:37:29Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3TestDoModesByOne
4 */
5
6/*
7 * Copyright (C) 2007-2022 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/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#if TMPL_MODE == BS3_MODE_RM
32# define BS3_USE_RM_TEXT_SEG 1 /* Real mode version in RMTEXT16 segment to save space. */
33# include "bs3kit-template-header.h"
34# include "bs3-cmn-test.h"
35#else
36# include "bs3kit-template-header.h"
37# include "bs3-cmn-test.h"
38#endif
39#include "bs3-mode-TestDoModes.h"
40
41
42/*********************************************************************************************************************************
43* Assembly Symbols *
44*********************************************************************************************************************************/
45/* Assembly helpers for switching to the work bitcount and calling it. */
46BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo16_f16(uint8_t bMode);
47BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo16_c32(uint8_t bMode);
48BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo16_c64(uint8_t bMode);
49BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo32_f16(uint8_t bMode);
50BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo32_c32(uint8_t bMode);
51BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo32_c64(uint8_t bMode);
52BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo64_f16(uint8_t bMode);
53BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo64_c32(uint8_t bMode);
54BS3_DECL_FAR(uint8_t) Bs3TestCallDoerTo64_c64(uint8_t bMode);
55
56
57/** The current worker function, picked up by our assembly helpers. */
58#ifndef DOXYGEN_RUNNING
59# define g_pfnBs3TestDoModesByOneCurrent BS3_CMN_NM(g_pfnBs3TestDoModesByOneCurrent)
60#endif
61extern PFNBS3TESTDOMODE g_pfnBs3TestDoModesByOneCurrent;
62
63#include <iprt/asm-amd64-x86.h>
64
65
66#undef Bs3TestDoModesByOne
67BS3_MODE_DEF(void, Bs3TestDoModesByOne,(PCBS3TESTMODEBYONEENTRY paEntries, size_t cEntries, uint32_t fFlags))
68{
69 bool const fVerbose = true;
70 bool const fDoV86Modes = true;
71 bool const fDoWeirdV86Modes = true;
72 uint16_t const uCpuDetected = g_uBs3CpuDetected;
73 uint8_t const bCpuType = uCpuDetected & BS3CPU_TYPE_MASK;
74 bool const fHavePae = RT_BOOL(uCpuDetected & BS3CPU_F_PAE);
75 bool const fHaveLongMode = RT_BOOL(uCpuDetected & BS3CPU_F_LONG_MODE);
76 unsigned i;
77
78#if 1 /* debug. */
79 Bs3Printf("Bs3TestDoModesByOne: uCpuDetected=%#x fHavePae=%d fHaveLongMode=%d\n", uCpuDetected, fHavePae, fHaveLongMode);
80#endif
81
82 /*
83 * Inform about modes we won't test (if any).
84 */
85 if (bCpuType < BS3CPU_80286)
86 Bs3Printf("Only executing real-mode tests as no 80286+ CPU was detected.\n");
87 else if (bCpuType < BS3CPU_80386)
88 Bs3Printf("80286 CPU: Only executing 16-bit protected and real mode tests.\n");
89 else if (!fHavePae)
90 Bs3Printf("PAE and long mode tests will be skipped.\n");
91 else if (!fHaveLongMode)
92 Bs3Printf("Long mode tests will be skipped.\n");
93#if ARCH_BITS != 16
94 Bs3Printf("Real-mode tests will be skipped.\n");
95#endif
96
97 /*
98 * The real run.
99 */
100 for (i = 0; i < cEntries; i++)
101 {
102 const char *pszFmtStr = "Error #%u (%#x) in %s!\n";
103 bool fSkipped = true;
104 bool const fOnlyPaging = RT_BOOL((paEntries[i].fFlags | fFlags) & BS3TESTMODEBYONEENTRY_F_ONLY_PAGING);
105 bool const fMinimal = RT_BOOL((paEntries[i].fFlags | fFlags) & BS3TESTMODEBYONEENTRY_F_MINIMAL);
106 bool const fCurDoV86Modes = fDoV86Modes && !fMinimal;
107 bool const fCurDoWeirdV86Modes = fDoWeirdV86Modes && fCurDoV86Modes;
108 uint8_t bErrNo;
109 Bs3TestSub(paEntries[i].pszSubTest);
110
111#define PRE_DO_CALL(a_szModeName) do { if (fVerbose) Bs3TestPrintf("...%s\n", a_szModeName); } while (0)
112#define CHECK_RESULT(a_szModeName) \
113 do { \
114 if (bErrNo != BS3TESTDOMODE_SKIPPED) \
115 { \
116 /*Bs3Printf("bErrNo=%#x %s\n", bErrNo, a_szModeName);*/ \
117 fSkipped = false; \
118 if (bErrNo != 0) \
119 Bs3TestFailedF(pszFmtStr, bErrNo, bErrNo, a_szModeName); \
120 } \
121 } while (0)
122
123 g_pfnBs3TestDoModesByOneCurrent = paEntries[i].pfnWorker;
124
125#if ARCH_BITS != 64
126
127# if ARCH_BITS == 16
128 if (!fOnlyPaging)
129 {
130 PRE_DO_CALL(g_szBs3ModeName_rm);
131 bErrNo = TMPL_NM(Bs3TestCallDoerInRM)(CONV_TO_RM_FAR16(paEntries[i].pfnWorker));
132 CHECK_RESULT(g_szBs3ModeName_rm);
133 }
134# else
135 if (!fOnlyPaging && (paEntries[i].fFlags | fFlags) & BS3TESTMODEBYONEENTRY_F_REAL_MODE_READY)
136 {
137 PRE_DO_CALL(g_szBs3ModeName_rm);
138 bErrNo = TMPL_NM(Bs3TestCallDoerInPE32)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_RM);
139 CHECK_RESULT(g_szBs3ModeName_rm);
140 }
141# endif
142
143 if (bCpuType < BS3CPU_80286)
144 {
145 if (fSkipped)
146 Bs3TestSkipped(NULL);
147 continue;
148 }
149
150 /*
151 * Unpaged prot mode.
152 */
153 if (!fOnlyPaging && (!fMinimal || bCpuType < BS3CPU_80386))
154 {
155 PRE_DO_CALL(g_szBs3ModeName_pe16);
156# if ARCH_BITS == 16
157 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnWorker));
158# else
159 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16)(CONV_TO_PROT_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
160# endif
161 CHECK_RESULT(g_szBs3ModeName_pe16);
162 }
163 if (bCpuType < BS3CPU_80386)
164 {
165 if (fSkipped)
166 Bs3TestSkipped(NULL);
167 continue;
168 }
169
170 if (!fOnlyPaging)
171 {
172 PRE_DO_CALL(g_szBs3ModeName_pe16_32);
173# if ARCH_BITS == 32
174 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_32)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_PE16_32);
175# else
176 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_32)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c32)), BS3_MODE_PE16_32);
177# endif
178 CHECK_RESULT(g_szBs3ModeName_pe16_32);
179 }
180
181 if (fCurDoWeirdV86Modes && !fOnlyPaging)
182 {
183 PRE_DO_CALL(g_szBs3ModeName_pe16_v86);
184# if ARCH_BITS == 16
185 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnWorker));
186# else
187 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_V86)(CONV_TO_RM_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
188# endif
189 CHECK_RESULT(g_szBs3ModeName_pe16_v86);
190 }
191
192 if (!fOnlyPaging)
193 {
194 PRE_DO_CALL(g_szBs3ModeName_pe32);
195# if ARCH_BITS == 32
196 bErrNo = TMPL_NM(Bs3TestCallDoerInPE32)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_PE32);
197# else
198 bErrNo = TMPL_NM(Bs3TestCallDoerInPE32)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c32)), BS3_MODE_PE32);
199# endif
200 CHECK_RESULT(g_szBs3ModeName_pe32);
201 }
202
203 if (!fOnlyPaging && !fMinimal)
204 {
205 PRE_DO_CALL(g_szBs3ModeName_pe32_16);
206# if ARCH_BITS == 16
207 bErrNo = TMPL_NM(Bs3TestCallDoerInPE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnWorker));
208# else
209 bErrNo = TMPL_NM(Bs3TestCallDoerInPE32_16)(CONV_TO_PROT_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
210# endif
211 CHECK_RESULT(g_szBs3ModeName_pe32_16);
212 }
213
214 if (fCurDoV86Modes && !fOnlyPaging)
215 {
216 PRE_DO_CALL(g_szBs3ModeName_pev86);
217# if ARCH_BITS == 16
218 bErrNo = TMPL_NM(Bs3TestCallDoerInPEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnWorker));
219# else
220 bErrNo = TMPL_NM(Bs3TestCallDoerInPEV86)(CONV_TO_RM_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
221# endif
222 CHECK_RESULT(g_szBs3ModeName_pev86);
223 }
224
225 /*
226 * Paged protected mode.
227 */
228 if (!fMinimal)
229 {
230 PRE_DO_CALL(g_szBs3ModeName_pp16);
231# if ARCH_BITS == 16
232 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16)(CONV_TO_PROT_FAR16(paEntries[i].pfnWorker));
233# else
234 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16)(CONV_TO_PROT_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
235# endif
236 CHECK_RESULT(g_szBs3ModeName_pp16);
237 }
238
239 if (!fMinimal)
240 {
241 PRE_DO_CALL(g_szBs3ModeName_pp16_32);
242# if ARCH_BITS == 32
243 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_32)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_PP16_32);
244# else
245 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_32)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c32)), BS3_MODE_PP16_32);
246# endif
247 CHECK_RESULT(g_szBs3ModeName_pp16_32);
248 }
249
250 if (fCurDoWeirdV86Modes)
251 {
252 PRE_DO_CALL(g_szBs3ModeName_pp16_v86);
253# if ARCH_BITS == 16
254 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnWorker));
255# else
256 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_V86)(CONV_TO_RM_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
257# endif
258 CHECK_RESULT(g_szBs3ModeName_pp16_v86);
259 }
260
261 if (true)
262 {
263 PRE_DO_CALL(g_szBs3ModeName_pp32);
264# if ARCH_BITS == 32
265 bErrNo = TMPL_NM(Bs3TestCallDoerInPP32)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_PP32);
266# else
267 bErrNo = TMPL_NM(Bs3TestCallDoerInPP32)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c32)), BS3_MODE_PP32);
268# endif
269 CHECK_RESULT(g_szBs3ModeName_pp32);
270 }
271
272 if (!fMinimal)
273 {
274 PRE_DO_CALL(g_szBs3ModeName_pp32_16);
275# if ARCH_BITS == 16
276 bErrNo = TMPL_NM(Bs3TestCallDoerInPP32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnWorker));
277# else
278 bErrNo = TMPL_NM(Bs3TestCallDoerInPP32_16)(CONV_TO_PROT_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
279# endif
280 CHECK_RESULT(g_szBs3ModeName_pp32_16);
281 }
282
283 if (fCurDoV86Modes)
284 {
285 PRE_DO_CALL(g_szBs3ModeName_ppv86);
286# if ARCH_BITS == 16
287 bErrNo = TMPL_NM(Bs3TestCallDoerInPPV86)(CONV_TO_RM_FAR16(paEntries[i].pfnWorker));
288# else
289 bErrNo = TMPL_NM(Bs3TestCallDoerInPPV86)(CONV_TO_RM_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
290# endif
291 CHECK_RESULT(g_szBs3ModeName_ppv86);
292 }
293
294
295 /*
296 * Protected mode with PAE paging.
297 */
298 if (!fMinimal)
299 {
300 PRE_DO_CALL(g_szBs3ModeName_pae16);
301# if ARCH_BITS == 16
302 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnWorker));
303# else
304 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16)(CONV_TO_PROT_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
305# endif
306 CHECK_RESULT(g_szBs3ModeName_pae16);
307 }
308
309 if (!fMinimal)
310 {
311 PRE_DO_CALL(g_szBs3ModeName_pae16_32);
312# if ARCH_BITS == 32
313 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_32)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_PAE16_32);
314# else
315 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_32)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c32)), BS3_MODE_PAE16_32);
316# endif
317 CHECK_RESULT(g_szBs3ModeName_pae16_32);
318 }
319
320 if (fCurDoWeirdV86Modes)
321 {
322 PRE_DO_CALL(g_szBs3ModeName_pae16_v86);
323# if ARCH_BITS == 16
324 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnWorker));
325# else
326 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_V86)(CONV_TO_RM_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
327# endif
328 CHECK_RESULT(g_szBs3ModeName_pae16_v86);
329 }
330
331 if (true)
332 {
333 PRE_DO_CALL(g_szBs3ModeName_pae32);
334# if ARCH_BITS == 32
335 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_PAE32);
336# else
337 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c32)), BS3_MODE_PAE32);
338# endif
339 CHECK_RESULT(g_szBs3ModeName_pae32);
340 }
341
342 if (!fMinimal)
343 {
344 PRE_DO_CALL(g_szBs3ModeName_pae32_16);
345# if ARCH_BITS == 16
346 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnWorker));
347# else
348 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32_16)(CONV_TO_PROT_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
349# endif
350 CHECK_RESULT(g_szBs3ModeName_pae32_16);
351 }
352
353 if (fCurDoV86Modes)
354 {
355 PRE_DO_CALL(g_szBs3ModeName_paev86);
356# if ARCH_BITS == 16
357 bErrNo = TMPL_NM(Bs3TestCallDoerInPAEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnWorker));
358# else
359 bErrNo = TMPL_NM(Bs3TestCallDoerInPAEV86)(CONV_TO_RM_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
360# endif
361 CHECK_RESULT(g_szBs3ModeName_paev86);
362 }
363
364#endif /* ARCH_BITS != 64 */
365
366 /*
367 * Long mode.
368 */
369 if (!fHaveLongMode)
370 {
371 if (fSkipped)
372 Bs3TestSkipped(NULL);
373 continue;
374 }
375
376 if (!fMinimal)
377 {
378 PRE_DO_CALL(g_szBs3ModeName_lm16);
379#if ARCH_BITS == 16
380 bErrNo = TMPL_NM(Bs3TestCallDoerInLM16)(CONV_TO_PROT_FAR16(paEntries[i].pfnWorker));
381#else
382 bErrNo = TMPL_NM(Bs3TestCallDoerInLM16)(CONV_TO_PROT_FAR16(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_f16)));
383#endif
384 CHECK_RESULT(g_szBs3ModeName_lm16);
385 }
386
387 if (!fMinimal)
388 {
389 PRE_DO_CALL(g_szBs3ModeName_lm32);
390#if ARCH_BITS == 32
391 bErrNo = TMPL_NM(Bs3TestCallDoerInLM32)(CONV_TO_FLAT(paEntries[i].pfnWorker));
392#else
393 bErrNo = TMPL_NM(Bs3TestCallDoerInLM32)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c32)));
394#endif
395 CHECK_RESULT(g_szBs3ModeName_lm32);
396 }
397
398 if (true)
399 {
400 PRE_DO_CALL(g_szBs3ModeName_lm64);
401#if ARCH_BITS == 64
402 bErrNo = TMPL_NM(Bs3TestCallDoerInLM64)(CONV_TO_FLAT(paEntries[i].pfnWorker), BS3_MODE_LM64);
403#else
404 bErrNo = TMPL_NM(Bs3TestCallDoerInLM64)(CONV_TO_FLAT(RT_CONCAT3(Bs3TestCallDoerTo,ARCH_BITS,_c64)), BS3_MODE_LM64);
405#endif
406 CHECK_RESULT(g_szBs3ModeName_lm64);
407 }
408
409 if (fSkipped)
410 Bs3TestSkipped("skipped\n");
411 }
412 Bs3TestSubDone();
413}
414
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette