VirtualBox

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

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

bs3kit: move real mode version of Bs3TestDoModes out of the default 16-bit code segment.

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