Changeset 60292 in vbox for trunk/src/VBox/ValidationKit/bootsectors
- Timestamp:
- Apr 1, 2016 11:50:07 PM (9 years ago)
- Location:
- trunk/src/VBox/ValidationKit/bootsectors
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c
r60291 r60292 125 125 126 126 /** 127 * Compares trap stuff.127 * Compares \#GP trap. 128 128 */ 129 129 #define bs3CpuBasic2_CompareGpCtx BS3_CMN_NM(bs3CpuBasic2_CompareGpCtx) … … 146 146 147 147 /** 148 * Compares trap stuff.148 * Compares \#NP trap. 149 149 */ 150 150 #define bs3CpuBasic2_CompareNpCtx BS3_CMN_NM(bs3CpuBasic2_CompareNpCtx) … … 167 167 168 168 /** 169 * Compares trap stuff. 169 * Compares \#SS trap. 170 */ 171 #define bs3CpuBasic2_CompareSsCtx BS3_CMN_NM(bs3CpuBasic2_CompareSsCtx) 172 void bs3CpuBasic2_CompareSsCtx(PCBS3TRAPFRAME pTrapCtx, PCBS3REGCTX pStartCtx, uint16_t uErrCd, bool f16BitHandler, 173 const char *pszMode, unsigned uLine) 174 { 175 uint16_t const cErrorsBefore = Bs3TestSubErrorCount(); 176 CHECK_MEMBER("bXcpt", "%#04x", pTrapCtx->bXcpt, X86_XCPT_SS); 177 CHECK_MEMBER("bErrCd", "%#06RX64", pTrapCtx->uErrCd, (uint64_t)uErrCd); 178 Bs3TestCheckRegCtxEx(&pTrapCtx->Ctx, pStartCtx, 0 /*cbIpAdjust*/, 0 /*cbSpAdjust*/, 179 f16BitHandler ? 0 : X86_EFL_RF, 180 pszMode, uLine); 181 if (Bs3TestSubErrorCount() != cErrorsBefore) 182 { 183 //Bs3TestPrintf("%s\n", __FUNCTION__); 184 Bs3TrapPrintFrame(pTrapCtx); 185 ASMHalt(); 186 } 187 } 188 189 /** 190 * Compares \#TS trap. 191 */ 192 #define bs3CpuBasic2_CompareTsCtx BS3_CMN_NM(bs3CpuBasic2_CompareTsCtx) 193 void bs3CpuBasic2_CompareTsCtx(PCBS3TRAPFRAME pTrapCtx, PCBS3REGCTX pStartCtx, uint16_t uErrCd, bool f16BitHandler, 194 const char *pszMode, unsigned uLine) 195 { 196 uint16_t const cErrorsBefore = Bs3TestSubErrorCount(); 197 CHECK_MEMBER("bXcpt", "%#04x", pTrapCtx->bXcpt, X86_XCPT_TS); 198 CHECK_MEMBER("bErrCd", "%#06RX64", pTrapCtx->uErrCd, (uint64_t)uErrCd); 199 Bs3TestCheckRegCtxEx(&pTrapCtx->Ctx, pStartCtx, 0 /*cbIpAdjust*/, 0 /*cbSpAdjust*/, 200 f16BitHandler ? 0 : X86_EFL_RF, 201 pszMode, uLine); 202 if (Bs3TestSubErrorCount() != cErrorsBefore) 203 { 204 //Bs3TestPrintf("%s\n", __FUNCTION__); 205 Bs3TrapPrintFrame(pTrapCtx); 206 ASMHalt(); 207 } 208 } 209 210 /** 211 * Compares \#PF trap. 170 212 */ 171 213 #define bs3CpuBasic2_ComparePfCtx BS3_CMN_NM(bs3CpuBasic2_ComparePfCtx) … … 192 234 #define bs3CpuBasic2_RaiseXcpt1Common BS3_CMN_NM(bs3CpuBasic2_RaiseXcpt1Common) 193 235 static void bs3CpuBasic2_RaiseXcpt1Common(uint8_t const bMode, const char * const pszMode, bool const f16BitSys, 194 uint16_t const uSysR0Cs, uint16_t const uSysR0CsConf, 236 uint16_t const uSysR0Cs, uint16_t const uSysR0CsConf, uint16_t const uSysR0Ss, 195 237 PX86DESC const paIdt, unsigned const cIdteShift) 196 238 { … … 204 246 unsigned iCtx; 205 247 unsigned iRing; 248 unsigned iDpl; 249 unsigned iRpl; 206 250 unsigned i, j, k; 207 251 unsigned uLine; 208 # if TMPL_BITS != 16 252 uint32_t uExpected; 253 # if TMPL_BITS == 16 254 bool const f386Plus = (BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_TYPE_MASK) >= BS3CPU_80386; 255 # else 256 bool const f386Plus = true; 209 257 int rc; 210 258 uint8_t *pbIdtCopyAlloc; … … 356 404 } 357 405 } 358 BS3_ASSERT(uLine < 2000); 406 BS3_ASSERT(uLine < 2800); 407 408 409 /* 410 * Various CS and SS related faults 411 * We temporarily reconfigure gate 80 and 83 with new CS selectors, the 412 * latter have a CS.DPL of 2 for testing ring transisions and SS loading 413 * without making it impossible to handle faults. 414 * 415 * Check #NP(CS). Pit #NP(CS) against #GP(CS) due to DPL. 416 * Ditto for stack. 417 * Pit SS trouble against CS trouble. 418 * Pit both against gate DPL trouble. 419 */ 420 uLine = 2800; 421 BS3_DATA_NM(Bs3GdteTestPage00) = BS3_DATA_NM(Bs3Gdt)[uSysR0Cs >> X86_SEL_SHIFT]; 422 BS3_DATA_NM(Bs3GdteTestPage00).Gen.u1Present = 0; 423 paIdt[0x80 << cIdteShift].Gate.u16Sel = BS3_SEL_TEST_PAGE_00; 424 425 /* CS.PRESENT = 0 */ 426 Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx); 427 bs3CpuBasic2_CompareNpCtx(&TrapCtx, &Ctx80, BS3_SEL_TEST_PAGE_00, f16BitSys, pszMode, uLine); 428 uLine++; 429 430 /* Check that GATE.DPL is checked before CS.PRESENT. */ 431 for (iRing = 1; iRing < 4; iRing++) 432 { 433 Bs3MemCpy(&CtxTmp, &Ctx80, sizeof(CtxTmp)); 434 Bs3RegCtxConvertToRingX(&CtxTmp, iRing); 435 Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx); 436 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxTmp, (0x80 << X86_TRAP_ERR_SEL_SHIFT) | X86_TRAP_ERR_IDT, 437 f16BitSys, pszMode, uLine); 438 uLine++; 439 } 440 441 /* CS.DPL mismatch takes precedence over CS.PRESENT = 0. */ 442 Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx); 443 bs3CpuBasic2_CompareNpCtx(&TrapCtx, &Ctx80, BS3_SEL_TEST_PAGE_00, f16BitSys, pszMode, uLine); 444 uLine++; 445 for (iDpl = 1; iDpl < 4; iDpl++) 446 { 447 BS3_DATA_NM(Bs3GdteTestPage00).Gen.u2Dpl = iDpl; 448 Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx); 449 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx80, BS3_SEL_TEST_PAGE_00, f16BitSys, pszMode, uLine); 450 uLine++; 451 } 452 453 /* Test SS. */ 454 if (!BS3_MODE_IS_64BIT_SYS(bMode)) 455 { 456 uint16_t BS3_FAR *puTssSs2 = BS3_MODE_IS_16BIT_SYS(bMode) ? &BS3_DATA_NM(Bs3Tss16).ss2 : &BS3_DATA_NM(Bs3Tss32).ss2; 457 uint16_t const uSavedSs2 = *puTssSs2; 458 459 /* Make the handler execute in ring-2. */ 460 BS3_DATA_NM(Bs3GdteTestPage02) = BS3_DATA_NM(Bs3Gdt)[(uSysR0Cs + (2 << BS3_SEL_RING_SHIFT)) >> X86_SEL_SHIFT]; 461 paIdt[0x83 << cIdteShift].Gate.u16Sel = BS3_SEL_TEST_PAGE_02 | 2; 462 463 Bs3MemCpy(&CtxTmp, &Ctx83, sizeof(CtxTmp)); 464 Bs3RegCtxConvertToRingX(&CtxTmp, 3); /* yeah, from 3 so SS:xSP is reloaded. */ 465 Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx); 466 bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &CtxTmp, 0x83, pszMode, uLine); 467 uLine++; 468 469 /* Create a SS.DPL=2 stack segment and check that SS2.RPL matters and 470 that we get #SS if the selector isn't present. */ 471 BS3_DATA_NM(Bs3GdteTestPage03) = BS3_DATA_NM(Bs3Gdt)[(uSysR0Ss + (2 << BS3_SEL_RING_SHIFT)) >> X86_SEL_SHIFT]; 472 for (iDpl = 0; iDpl < 4; iDpl++) 473 { 474 BS3_DATA_NM(Bs3GdteTestPage03).Gen.u2Dpl = iDpl; 475 for (k = 0; k < 2; k++) 476 { 477 BS3_DATA_NM(Bs3GdteTestPage03).Gen.u1Present = k == 0; 478 for (iRpl = 0; iRpl < 4; iRpl++) 479 { 480 *puTssSs2 = BS3_SEL_TEST_PAGE_03 | iRpl; 481 Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx); 482 if (iRpl != 2 || iRpl != iDpl) 483 bs3CpuBasic2_CompareTsCtx(&TrapCtx, &CtxTmp, BS3_SEL_TEST_PAGE_03, f16BitSys, pszMode, uLine); 484 else if (k != 0) 485 bs3CpuBasic2_CompareSsCtx(&TrapCtx, &CtxTmp, BS3_SEL_TEST_PAGE_03, f16BitSys, pszMode, uLine); 486 else 487 { 488 bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &CtxTmp, 0x83, pszMode, uLine); 489 if (TrapCtx.uHandlerSs != (BS3_SEL_TEST_PAGE_03 | 2)) 490 Bs3TestFailedF("%u - %s: uHandlerSs=%#x expected %#x\n", uLine, pszMode, 491 TrapCtx.uHandlerSs, BS3_SEL_TEST_PAGE_03 | 2); 492 } 493 uLine++; 494 495 /* Modify the gate DPL to check that this is checked before SS.DPL and SS.PRESENT. */ 496 paIdt[0x83 << cIdteShift].Gate.u2Dpl = 2; 497 Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx); 498 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxTmp, (0x83 << X86_TRAP_ERR_SEL_SHIFT) | X86_TRAP_ERR_IDT, 499 f16BitSys, pszMode, uLine); 500 paIdt[0x83 << cIdteShift].Gate.u2Dpl = 3; 501 uLine++; 502 503 /* Check the the CS.DPL check is done before the SS ones. Restoring the ring-0 INT 83 504 context triggers the CS.DPL < CPL check. */ 505 Bs3TrapSetJmpAndRestore(&Ctx83, &TrapCtx); 506 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx83, BS3_SEL_TEST_PAGE_02, f16BitSys, pszMode, uLine); 507 uLine++; 508 509 /* Now mark the CS selector not present and check that that also triggers before SS stuff. */ 510 BS3_DATA_NM(Bs3GdteTestPage02).Gen.u1Present = 0; 511 Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx); 512 bs3CpuBasic2_CompareNpCtx(&TrapCtx, &CtxTmp, BS3_SEL_TEST_PAGE_02, f16BitSys, pszMode, uLine); 513 BS3_DATA_NM(Bs3GdteTestPage02).Gen.u1Present = 1; 514 uLine++; 515 } 516 } 517 } 518 519 *puTssSs2 = uSavedSs2; 520 paIdt[0x83 << cIdteShift].Gate.u16Sel = uSysR0Cs; 521 } 522 paIdt[0x80 << cIdteShift].Gate.u16Sel = uSysR0Cs; 359 523 360 524 /* … … 574 738 if (!(BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type & X86_SEL_TYPE_ACCESSED)) 575 739 Bs3TestFailedF("%u - %s: u4Type=%#x, not accessed!\n", uLine, pszMode, BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type); 740 if (TrapCtx.uHandlerCs != (BS3_SEL_TEST_PAGE_03 | 3)) 741 Bs3TestFailedF("%u - %s: uHandlerCs=%#x, expected %#x\n", uLine, pszMode, TrapCtx.uHandlerCs, (BS3_SEL_TEST_PAGE_03 | 3)); 576 742 uLine++; 577 743 … … 660 826 /* restore */ 661 827 paIdt[0x80 << cIdteShift].Gate.u16Sel = uSysR0Cs; 662 paIdt[0x83 << cIdteShift].Gate.u16Sel = uSysR0Cs + (3 << BS3_SEL_RING_SHIFT) + 3;828 paIdt[0x83 << cIdteShift].Gate.u16Sel = uSysR0Cs;// + (3 << BS3_SEL_RING_SHIFT) + 3; 663 829 } 664 830 665 831 # endif /* 32 || 64*/ 832 833 /* 834 * Check broad EFLAGS effects. 835 */ 836 uLine = 5600; 837 for (iCtx = 0; iCtx < RT_ELEMENTS(apCtx8x); iCtx++) 838 { 839 for (iRing = 0; iRing < 4; iRing++) 840 { 841 Bs3MemCpy(&CtxTmp, apCtx8x[iCtx], sizeof(CtxTmp)); 842 Bs3RegCtxConvertToRingX(&CtxTmp, iRing); 843 844 /* all set */ 845 CtxTmp.rflags.u32 &= X86_EFL_VM | X86_EFL_1; 846 CtxTmp.rflags.u32 |= X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF /* | X86_EFL_TF */ /*| X86_EFL_IF*/ 847 | X86_EFL_DF | X86_EFL_OF | X86_EFL_IOPL /* | X86_EFL_NT*/; 848 if (f386Plus) 849 CtxTmp.rflags.u32 |= /*X86_EFL_VM |*/ X86_EFL_AC | X86_EFL_VIF | X86_EFL_VIP; 850 if (f386Plus && !f16BitSys) 851 CtxTmp.rflags.u32 |= X86_EFL_RF; 852 if (BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_F_CPUID) 853 CtxTmp.rflags.u32 |= X86_EFL_ID; 854 Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx); 855 CtxTmp.rflags.u32 &= ~X86_EFL_RF; 856 857 if (iCtx >= iRing) 858 bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &CtxTmp, 0x80 + iCtx /*bXcpt*/, pszMode, uLine); 859 else 860 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxTmp, ((0x80 + iCtx) << X86_TRAP_ERR_SEL_SHIFT) | X86_TRAP_ERR_IDT, 861 f16BitSys, pszMode, uLine); 862 uExpected = CtxTmp.rflags.u32 863 & ( X86_EFL_1 | X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_DF 864 | X86_EFL_OF | X86_EFL_IOPL | X86_EFL_NT | X86_EFL_VM | X86_EFL_AC | X86_EFL_VIF | X86_EFL_VIP 865 | X86_EFL_ID /*| X86_EFL_TF*/ /*| X86_EFL_IF*/ /*| X86_EFL_RF*/ ); 866 if (TrapCtx.fHandlerRfl != uExpected) 867 Bs3TestFailedF("%u - %s: unexpected handler rflags value: %RX64 expected %RX32; CtxTmp.rflags=%RX64 Ctx.rflags=%RX64\n", 868 uLine, pszMode, TrapCtx.fHandlerRfl, uExpected, CtxTmp.rflags.u, TrapCtx.Ctx.rflags.u); 869 uLine++; 870 871 /* all cleared */ 872 if ((BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_TYPE_MASK) < BS3CPU_80286) 873 CtxTmp.rflags.u32 = apCtx8x[iCtx]->rflags.u32 & (X86_EFL_RA1_MASK | UINT16_C(0xf000)); 874 else 875 CtxTmp.rflags.u32 = apCtx8x[iCtx]->rflags.u32 & (X86_EFL_VM | X86_EFL_RA1_MASK); 876 Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx); 877 if (iCtx >= iRing) 878 bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &CtxTmp, 0x80 + iCtx /*bXcpt*/, pszMode, uLine); 879 else 880 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxTmp, ((0x80 + iCtx) << X86_TRAP_ERR_SEL_SHIFT) | X86_TRAP_ERR_IDT, 881 f16BitSys, pszMode, uLine); 882 uExpected = CtxTmp.rflags.u32; 883 if (TrapCtx.fHandlerRfl != uExpected) 884 Bs3TestFailedF("%u - %s: unexpected handler rflags value: %RX64 expected %RX32; CtxTmp.rflags=%RX64 Ctx.rflags=%RX64\n", 885 uLine, pszMode, TrapCtx.fHandlerRfl, uExpected, CtxTmp.rflags.u, TrapCtx.Ctx.rflags.u); 886 uLine++; 887 } 888 } 666 889 667 890 /* … … 682 905 uint16_t const * const pauInvTypes = cIdteShift != 0 ? s_auInvlTypes64 : s_auInvlTypes32; 683 906 uint16_t const cInvTypes = cIdteShift != 0 ? RT_ELEMENTS(s_auInvlTypes64) 684 : (BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_TYPE_MASK) < BS3CPU_80386 685 ? RT_ELEMENTS(s_auInvlTypes32) : RT_ELEMENTS(s_auInvlTypes32) - 3; 907 : f386Plus ? RT_ELEMENTS(s_auInvlTypes32) - 3 : RT_ELEMENTS(s_auInvlTypes32); 686 908 687 909 … … 738 960 * - Run \#PF and \#GP (and others?) at CPLs other than zero. 739 961 * - Quickly generate all faults. 740 * - Check CS.u1Access = 1 \#PF against \#NP(CS), CS.u2DPL, \#NP(SS),741 * SS.u2DPL, and SS.u1Access=1 \#PF.742 * - Check that IOPL doesn't influence anything for non-v8086.743 * - EFLAGS effects (AC seen gonne missing in real-mode).744 962 * - All the peculiarities v8086. 745 963 */ … … 749 967 # endif 750 968 } 751 752 969 753 970 #endif /* once for each bitcount */ … … 944 1161 BS3_DECL(uint8_t) TMPL_NM(bs3CpuBasic2_RaiseXcpt1)(uint8_t bMode) 945 1162 { 1163 #if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE) 946 1164 uint8_t bRet = 0; 947 1165 … … 949 1167 * Pass to common worker which is only compiled once per mode. 950 1168 */ 951 #if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)952 1169 bs3CpuBasic2_RaiseXcpt1Common(bMode, 953 1170 BS3_DATA_NM(TMPL_NM(g_szBs3ModeName)), … … 955 1172 MY_SYS_SEL_R0_CS, 956 1173 MY_SYS_SEL_R0_CS_CNF, 1174 MY_SYS_SEL_R0_SS, 957 1175 (PX86DESC)MyBs3Idt, 958 1176 BS3_MODE_IS_64BIT_SYS(TMPL_MODE) ? 1 : 0); 959 #else960 bRet = BS3TESTDOMODE_SKIPPED;961 #endif962 1177 963 1178 /* … … 966 1181 TMPL_NM(Bs3TrapInit)(); 967 1182 return bRet; 1183 #elif !BS3_MODE_IS_RM(TMPL_MODE) 1184 1185 /* 1186 * Check 1187 */ 1188 /** @todo check */ 1189 return BS3TESTDOMODE_SKIPPED; 1190 1191 #else 1192 return BS3TESTDOMODE_SKIPPED; 1193 #endif 968 1194 } 969 1195 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesHlp.asm
r60019 r60292 666 666 STRICT_CHECK_REGS 667 667 668 push BS3_MODE_PAE 16_32668 push BS3_MODE_PAE32 669 669 call eax 670 670
Note:
See TracChangeset
for help on using the changeset viewer.