VirtualBox

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

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

bs3kit: far updates.

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