VirtualBox

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

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