VirtualBox

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

Last change on this file since 60539 was 60539, checked in by vboxsync, 9 years ago

bs3kit: Updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.7 KB
Line 
1/* $Id: bs3-mode-TestDoModes.c 60539 2016-04-18 14:09:39Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3TestDoModeTests
4 */
5
6/*
7 * Copyright (C) 2007-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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#include "bs3kit-template-header.h"
32#include "bs3-cmn-test.h"
33
34
35/*********************************************************************************************************************************
36* Defined Constants And Macros *
37*********************************************************************************************************************************/
38/** @def CONV_TO_FLAT
39 * Get flat address. In 16-bit the parameter is a real mode far address, while
40 * in 32-bit and 64-bit modes it is already flat.
41 */
42/** @def CONV_TO_PROT_FAR16
43 * Get a 32-bit value that makes a protected mode far 16:16 address.
44 */
45/** @def CONV_TO_RM_FAR16
46 * Get a 32-bit value that makes a real mode far 16:16 address. In 16-bit mode
47 * this is already what we've got, except must be converted to uint32_t.
48 */
49#if ARCH_BITS == 16
50# define CONV_TO_FLAT(a_fpfn) (((uint32_t)BS3_FP_SEG(a_fpfn) << 4) + BS3_FP_OFF(a_fpfn))
51# define CONV_TO_PROT_FAR16(a_fpfn) RT_MAKE_U32(BS3_FP_OFF(a_fpfn), Bs3SelRealModeCodeToProtMode(BS3_FP_SEG(a_fpfn)))
52# define CONV_TO_RM_FAR16(a_fpfn) RT_MAKE_U32(BS3_FP_OFF(a_fpfn), BS3_FP_SEG(a_fpfn))
53#else
54# define CONV_TO_FLAT(a_fpfn) ((uint32_t)(uintptr_t)(a_fpfn))
55# define CONV_TO_PROT_FAR16(a_fpfn) Bs3SelFlatCodeToProtFar16((uint32_t)(uintptr_t)(a_fpfn))
56# define CONV_TO_RM_FAR16(a_fpfn) Bs3SelFlatCodeToRealMode( (uint32_t)(uintptr_t)(a_fpfn))
57#endif
58
59
60/*********************************************************************************************************************************
61* Assembly Symbols *
62*********************************************************************************************************************************/
63BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInRM)(uint32_t uCallbackFarPtr);
64BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE16)(uint32_t uCallbackFarPtr);
65BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE16_32)(uint32_t uFlatAddrCallback);
66BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE16_V86)(uint32_t uCallbackFarPtr);
67BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE32)(uint32_t uFlatAddrCallback);
68BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE32_16)(uint32_t uCallbackFarPtr);
69BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPEV86)(uint32_t uCallbackFarPtr);
70BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP16)(uint32_t uCallbackFarPtr);
71BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP16_32)(uint32_t uFlatAddrCallback);
72BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP16_V86)(uint32_t uCallbackFarPtr);
73BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP32)(uint32_t uFlatAddrCallback);
74BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP32_16)(uint32_t uCallbackFarPtr);
75BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPPV86)(uint32_t uCallbackFarPtr);
76BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE16)(uint32_t uCallbackFarPtr);
77BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE16_32)(uint32_t uFlatAddrCallback);
78BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE16_V86)(uint32_t uCallbackFarPtr);
79BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE32)(uint32_t uFlatAddrCallback);
80BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE32_16)(uint32_t uCallbackFarPtr);
81BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAEV86)(uint32_t uCallbackFarPtr);
82BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInLM16)(uint32_t uCallbackFarPtr);
83BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInLM32)(uint32_t uFlatAddrCallback);
84BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInLM64)(uint32_t uFlatAddrCallback);
85
86
87
88/**
89 * Warns about CPU modes that must be skipped.
90 *
91 * It will try not warn about modes for which there are no tests.
92 *
93 * @param paEntries The mode test entries.
94 * @param cEntries The number of tests.
95 * @param bCpuType The CPU type byte (see #BS3CPU_TYPE_MASK).
96 * @param fHavePae Whether the CPU has PAE.
97 * @param fHaveLongMode Whether the CPU does long mode.
98 */
99static void bs3TestWarnAboutSkippedModes(PCBS3TESTMODEENTRY paEntries, unsigned cEntries,
100 uint8_t bCpuType, bool fHavePae, bool fHaveLongMode)
101{
102 bool fComplained286 = false;
103 bool fComplained386 = false;
104 bool fComplainedPAE = false;
105 bool fComplainedAMD64 = false;
106 unsigned i;
107
108 /*
109 * Complaint run.
110 */
111 for (i = 0; i < cEntries; i++)
112 {
113 if ( !fComplained286
114 && paEntries[i].pfnDoPE16)
115 {
116 if (bCpuType < BS3CPU_80286)
117 {
118 Bs3Printf("Only executing real-mode tests as no 80286+ CPU was detected.\n");
119 break;
120 }
121 fComplained286 = true;
122 }
123
124 if ( !fComplained386
125 && ( paEntries[i].pfnDoPE16_32
126 || paEntries[i].pfnDoPE16_V86
127 || paEntries[i].pfnDoPE32
128 || paEntries[i].pfnDoPE32_16
129 || paEntries[i].pfnDoPEV86
130 || paEntries[i].pfnDoPP16
131 || paEntries[i].pfnDoPP16_32
132 || paEntries[i].pfnDoPP16_V86
133 || paEntries[i].pfnDoPP32
134 || paEntries[i].pfnDoPP32_16
135 || paEntries[i].pfnDoPPV86) )
136 {
137 if (bCpuType < BS3CPU_80386)
138 {
139 Bs3Printf("80286 CPU: Only executing 16-bit protected and real mode tests.\n");
140 break;
141 }
142 fComplained386 = true;
143 }
144
145 if ( !fComplainedPAE
146 && ( paEntries[i].pfnDoPAE16
147 || paEntries[i].pfnDoPAE16_32
148 || paEntries[i].pfnDoPAE16_V86
149 || paEntries[i].pfnDoPAE32
150 || paEntries[i].pfnDoPAE32_16
151 || paEntries[i].pfnDoPAEV86) )
152 {
153 if (!fHavePae)
154 {
155 Bs3Printf("PAE and long mode tests will be skipped.\n");
156 break;
157 }
158 fComplainedPAE = true;
159 }
160
161 if ( !fComplainedAMD64
162 && ( paEntries[i].pfnDoLM16
163 || paEntries[i].pfnDoLM32
164 || paEntries[i].pfnDoLM64) )
165 {
166 if (!fHaveLongMode)
167 {
168 Bs3Printf("Long mode tests will be skipped.\n");
169 break;
170 }
171 fComplainedAMD64 = true;
172 }
173 }
174}
175
176BS3_DECL(void) TMPL_NM(Bs3TestDoModes)(PCBS3TESTMODEENTRY paEntries, size_t cEntries)
177{
178 bool const fVerbose = true;
179 bool const fDoV86Modes = true;
180 bool const fDoWeirdV86Modes = true;
181 uint16_t const uCpuDetected = g_uBs3CpuDetected;
182 uint8_t const bCpuType = uCpuDetected & BS3CPU_TYPE_MASK;
183 bool const fHavePae = RT_BOOL(uCpuDetected & BS3CPU_F_PAE);
184 bool const fHaveLongMode = RT_BOOL(uCpuDetected & BS3CPU_F_LONG_MODE);
185 unsigned i;
186
187#if 1 /* debug. */
188 Bs3Printf("Bs3TestDoModes: uCpuDetected=%#x fHavePae=%d fHaveLongMode=%d\n", uCpuDetected, fHavePae, fHaveLongMode);
189#endif
190 bs3TestWarnAboutSkippedModes(paEntries, cEntries, bCpuType, fHavePae, fHaveLongMode);
191
192 /*
193 * The real run.
194 */
195 for (i = 0; i < cEntries; i++)
196 {
197 const char *pszFmtStr = "Error #%u (%#x) in %s!\n";
198 bool fSkipped = true;
199 uint8_t bErrNo;
200 Bs3TestSub(paEntries[i].pszSubTest);
201
202#define PRE_DO_CALL(a_szModeName) do { if (fVerbose) Bs3TestPrintf("...%s\n", a_szModeName); } while (0)
203#define CHECK_RESULT(a_szModeName) \
204 do { \
205 if (bErrNo != BS3TESTDOMODE_SKIPPED) \
206 { \
207 /*Bs3Printf("bErrNo=%#x %s\n", bErrNo, a_szModeName);*/ \
208 fSkipped = false; \
209 if (bErrNo != 0) \
210 Bs3TestFailedF(pszFmtStr, bErrNo, bErrNo, a_szModeName); \
211 } \
212 } while (0)
213
214 if (paEntries[i].pfnDoRM)
215 {
216 PRE_DO_CALL(g_szBs3ModeName_rm);
217 bErrNo = TMPL_NM(Bs3TestCallDoerInRM)(CONV_TO_RM_FAR16(paEntries[i].pfnDoRM));
218 CHECK_RESULT(g_szBs3ModeName_rm);
219 }
220
221 if (bCpuType < BS3CPU_80286)
222 {
223 if (fSkipped)
224 Bs3TestSkipped(NULL);
225 continue;
226 }
227
228 /*
229 * Unpaged prot mode.
230 */
231 if (paEntries[i].pfnDoPE16)
232 {
233 PRE_DO_CALL(g_szBs3ModeName_pe16);
234 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPE16));
235 CHECK_RESULT(g_szBs3ModeName_pe16);
236 }
237 if (bCpuType < BS3CPU_80386)
238 {
239 if (fSkipped)
240 Bs3TestSkipped(NULL);
241 continue;
242 }
243
244 if (paEntries[i].pfnDoPE16_32)
245 {
246 PRE_DO_CALL(g_szBs3ModeName_pe16_32);
247 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPE16_32));
248 CHECK_RESULT(g_szBs3ModeName_pe16_32);
249 }
250
251 if (paEntries[i].pfnDoPE16_V86 && fDoWeirdV86Modes)
252 {
253 PRE_DO_CALL(g_szBs3ModeName_pe16_v86);
254 bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPE16_V86));
255 CHECK_RESULT(g_szBs3ModeName_pe16_v86);
256 }
257
258 if (paEntries[i].pfnDoPE32)
259 {
260 PRE_DO_CALL(g_szBs3ModeName_pe32);
261 bErrNo = TMPL_NM(Bs3TestCallDoerInPE32)(CONV_TO_FLAT(paEntries[i].pfnDoPE32));
262 CHECK_RESULT(g_szBs3ModeName_pe32);
263 }
264
265 if (paEntries[i].pfnDoPE32_16)
266 {
267 PRE_DO_CALL(g_szBs3ModeName_pe32_16);
268 bErrNo = TMPL_NM(Bs3TestCallDoerInPE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPE32_16));
269 CHECK_RESULT(g_szBs3ModeName_pe32_16);
270 }
271
272 if (paEntries[i].pfnDoPEV86 && fDoV86Modes)
273 {
274 PRE_DO_CALL(g_szBs3ModeName_pev86);
275 bErrNo = TMPL_NM(Bs3TestCallDoerInPEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPEV86));
276 CHECK_RESULT(g_szBs3ModeName_pev86);
277 }
278
279 /*
280 * Paged protected mode.
281 */
282 if (paEntries[i].pfnDoPP16)
283 {
284 PRE_DO_CALL(g_szBs3ModeName_pp16);
285 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPP16));
286 CHECK_RESULT(g_szBs3ModeName_pp16);
287 }
288
289 if (paEntries[i].pfnDoPP16_32)
290 {
291 PRE_DO_CALL(g_szBs3ModeName_pp16_32);
292 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPP16_32));
293 CHECK_RESULT(g_szBs3ModeName_pp16_32);
294 }
295
296 if (paEntries[i].pfnDoPP16_V86 && fDoWeirdV86Modes)
297 {
298 PRE_DO_CALL(g_szBs3ModeName_pp16_v86);
299 bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPP16_V86));
300 CHECK_RESULT(g_szBs3ModeName_pp16_v86);
301 }
302
303 if (paEntries[i].pfnDoPP32)
304 {
305 PRE_DO_CALL(g_szBs3ModeName_pp32);
306 bErrNo = TMPL_NM(Bs3TestCallDoerInPP32)(CONV_TO_FLAT(paEntries[i].pfnDoPP32));
307 CHECK_RESULT(g_szBs3ModeName_pp32);
308 }
309
310 if (paEntries[i].pfnDoPP32_16)
311 {
312 PRE_DO_CALL(g_szBs3ModeName_pp32_16);
313 bErrNo = TMPL_NM(Bs3TestCallDoerInPP32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPP32_16));
314 CHECK_RESULT(g_szBs3ModeName_pp32_16);
315 }
316
317 if (paEntries[i].pfnDoPPV86 && fDoV86Modes)
318 {
319 PRE_DO_CALL(g_szBs3ModeName_ppv86);
320 bErrNo = TMPL_NM(Bs3TestCallDoerInPPV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPPV86));
321 CHECK_RESULT(g_szBs3ModeName_ppv86);
322 }
323
324 /*
325 * Protected mode with PAE paging.
326 */
327 if (!fHavePae)
328 {
329 if (fSkipped)
330 Bs3TestSkipped(NULL);
331 continue;
332 }
333
334 if (paEntries[i].pfnDoPAE16)
335 {
336 PRE_DO_CALL(g_szBs3ModeName_pae16);
337 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPAE16));
338 CHECK_RESULT(g_szBs3ModeName_pae16);
339 }
340
341 if (paEntries[i].pfnDoPAE16_32)
342 {
343 PRE_DO_CALL(g_szBs3ModeName_pae16_32);
344 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPAE16_32));
345 CHECK_RESULT(g_szBs3ModeName_pae16_32);
346 }
347
348 if (paEntries[i].pfnDoPAE16_V86 && fDoWeirdV86Modes)
349 {
350 PRE_DO_CALL(g_szBs3ModeName_pae16_v86);
351 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPAE16_V86));
352 CHECK_RESULT(g_szBs3ModeName_pae16_v86);
353 }
354
355 if (paEntries[i].pfnDoPAE32)
356 {
357 PRE_DO_CALL(g_szBs3ModeName_pae32);
358 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32)(CONV_TO_FLAT(paEntries[i].pfnDoPAE32));
359 CHECK_RESULT(g_szBs3ModeName_pae32);
360 }
361
362 if (paEntries[i].pfnDoPAE32_16)
363 {
364 PRE_DO_CALL(g_szBs3ModeName_pae32_16);
365 bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPAE32_16));
366 CHECK_RESULT(g_szBs3ModeName_pae32_16);
367 }
368
369 if (paEntries[i].pfnDoPAEV86 && fDoV86Modes)
370 {
371 PRE_DO_CALL(g_szBs3ModeName_paev86);
372 bErrNo = TMPL_NM(Bs3TestCallDoerInPAEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPAEV86));
373 CHECK_RESULT(g_szBs3ModeName_paev86);
374 }
375
376 /*
377 * Long mode.
378 */
379 if (!fHaveLongMode)
380 {
381 if (fSkipped)
382 Bs3TestSkipped(NULL);
383 continue;
384 }
385
386 if (paEntries[i].pfnDoLM16)
387 {
388 PRE_DO_CALL(g_szBs3ModeName_lm16);
389 bErrNo = TMPL_NM(Bs3TestCallDoerInLM16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoLM16));
390 CHECK_RESULT(g_szBs3ModeName_lm16);
391 }
392
393 if (paEntries[i].pfnDoLM32)
394 {
395 PRE_DO_CALL(g_szBs3ModeName_lm32);
396 bErrNo = TMPL_NM(Bs3TestCallDoerInLM32)(CONV_TO_FLAT(paEntries[i].pfnDoLM32));
397 CHECK_RESULT(g_szBs3ModeName_lm32);
398 }
399
400 if (paEntries[i].pfnDoLM64)
401 {
402 PRE_DO_CALL(g_szBs3ModeName_lm64);
403 bErrNo = TMPL_NM(Bs3TestCallDoerInLM64)(CONV_TO_FLAT(paEntries[i].pfnDoLM64));
404 CHECK_RESULT(g_szBs3ModeName_lm64);
405 }
406
407 if (fSkipped)
408 Bs3TestSkipped("skipped\n");
409 }
410 Bs3TestSubDone();
411}
412
Note: See TracBrowser for help on using the repository browser.

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