- 時間撮記:
- 2016-3-28 下午10:51:25 (9 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c
r60215 r60232 166 166 } 167 167 168 /** 169 * Compares trap stuff. 170 */ 171 #define bs3CpuBasic2_ComparePfCtx BS3_CMN_NM(bs3CpuBasic2_ComparePfCtx) 172 void bs3CpuBasic2_ComparePfCtx(PCBS3TRAPFRAME pTrapCtx, PBS3REGCTX pStartCtx, uint16_t uErrCd, uint64_t uCr2Expected, 173 bool f16BitHandler, const char *pszMode, unsigned uLine) 174 { 175 uint64_t const uCr2Saved = pStartCtx->cr2.u; 176 uint16_t const cErrorsBefore = Bs3TestSubErrorCount(); 177 CHECK_MEMBER("bXcpt", "%#04x", pTrapCtx->bXcpt, X86_XCPT_PF); 178 CHECK_MEMBER("bErrCd", "%#06RX64", pTrapCtx->uErrCd, (uint64_t)uErrCd); 179 pStartCtx->cr2.u = uCr2Expected; 180 Bs3TestCheckRegCtxEx(&pTrapCtx->Ctx, pStartCtx, 0 /*cbIpAdjust*/, 0 /*cbSpAdjust*/, 181 f16BitHandler ? 0 : X86_EFL_RF, 182 pszMode, uLine); 183 pStartCtx->cr2.u = uCr2Saved; 184 if (Bs3TestSubErrorCount() != cErrorsBefore) 185 { 186 //Bs3TestPrintf("%s\n", __FUNCTION__); 187 Bs3TrapPrintFrame(pTrapCtx); 188 ASMHalt(); 189 } 190 } 191 168 192 #define bs3CpuBasic2_RaiseXcpt1Common BS3_CMN_NM(bs3CpuBasic2_RaiseXcpt1Common) 169 193 static void bs3CpuBasic2_RaiseXcpt1Common(uint8_t const bMode, const char * const pszMode, bool const f16BitSys, … … 182 206 unsigned i, j, k; 183 207 unsigned uLine; 184 185 //uLine = 0; NOREF(uLine); NOREF(pszMode); NOREF(f16BitSys); 208 # if TMPL_BITS != 16 209 uint8_t *pbIdtCopyAlloc; 210 PX86DESC pIdtCopy; 211 const unsigned cbIdte = 1 << (3 + cIdteShift); 212 # endif 213 RTIDTR IdtrSaved; 214 RTIDTR Idtr; 215 216 ASMGetIDTR(&IdtrSaved); 186 217 187 218 /* make sure they're allocated */ … … 199 230 apCtx8x[3] = &Ctx83; 200 231 232 # if TMPL_BITS != 16 233 /* Allocate memory for playing around with the IDT. */ 234 pbIdtCopyAlloc = NULL; 235 if (BS3_MODE_IS_PAGED(bMode)) 236 pbIdtCopyAlloc = Bs3MemAlloc(BS3MEMKIND_FLAT32, 12*_1K); 237 # endif 238 201 239 /* 202 240 * IDT entry 80 thru 83 are assigned DPLs according to the number. … … 209 247 210 248 Bs3RegCtxSave(&Ctx80); 211 Ctx80.rsp.u -= 0x 80;249 Ctx80.rsp.u -= 0x300; 212 250 Ctx80.rip.u = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_Int80)); 213 251 # if TMPL_BITS == 32 … … 341 379 if (iCtx < iRing) 342 380 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxTmp, ((0x80 + iCtx) << X86_TRAP_ERR_SEL_SHIFT) | X86_TRAP_ERR_IDT, 343 f16BitSys, pszMode, 1);//uLine);381 f16BitSys, pszMode, uLine); 344 382 else if (i > iRing) 345 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxTmp, uCs & X86_SEL_MASK_OFF_RPL, f16BitSys, pszMode, 2);//uLine);383 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxTmp, uCs & X86_SEL_MASK_OFF_RPL, f16BitSys, pszMode, uLine); 346 384 else 347 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &CtxTmp, 2 /*int 8xh*/, 0x80 + iCtx /*bXcpt*/, pszMode, 3);//uLine);385 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &CtxTmp, 2 /*int 8xh*/, 0x80 + iCtx /*bXcpt*/, pszMode, uLine); 348 386 } 349 387 paIdt[(0x80 + iCtx) << cIdteShift].Gate.u16Sel = uSysR0Cs; … … 354 392 355 393 /* 356 * The gates must be 64-bit in long mode. .394 * The gates must be 64-bit in long mode. 357 395 */ 358 396 if (cIdteShift != 0) … … 387 425 } 388 426 } 389 BS3_ASSERT(uLine < 4000); 390 } 427 BS3_ASSERT(uLine < 4000); 428 } 429 430 /* 431 * IDT limit check. 432 */ 433 uLine = 5000; 434 i = (0x80 << (cIdteShift + 3)) - 1; 435 j = (0x82 << (cIdteShift + 3)) - 1; 436 k = (0x83 << (cIdteShift + 3)) - 1; 437 for (; i <= k; i++, uLine++) 438 { 439 Idtr = IdtrSaved; 440 Idtr.cbIdt = i; 441 ASMSetIDTR(&Idtr); 442 Bs3TrapSetJmpAndRestore(&Ctx81, &TrapCtx); 443 if (i < j) 444 bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx81, (0x81 << X86_TRAP_ERR_SEL_SHIFT) | X86_TRAP_ERR_IDT, 445 f16BitSys, pszMode, uLine); 446 else 447 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx81, 2 /*int 8xh*/, 0x81 /*bXcpt*/, pszMode, uLine); 448 } 449 ASMSetIDTR(&IdtrSaved); 450 BS3_ASSERT(uLine < 5100); 451 452 # if TMPL_BITS != 16 /* Only do the paging related stuff in 32-bit and 64-bit modes. */ 453 454 /* 455 * IDT page not present. Placing the IDT copy such that 0x80 is on the 456 * first page and 0x81 is on the second page. We need proceed to move 457 * it down byte by byte to check that any inaccessible byte means #PF. 458 * 459 * Note! We must reload the alternative IDTR for each run as any kind of 460 * printing to the string (like error reporting) will cause a switch 461 * to real mode and back, reloading the default IDTR. 462 */ 463 uLine = 5200; 464 if (BS3_MODE_IS_PAGED(bMode) && pbIdtCopyAlloc) 465 { 466 uint32_t const uCr2Expected = Bs3SelPtrToFlat(pbIdtCopyAlloc) + _4K; 467 for (j = 0; j < cbIdte; j++) 468 { 469 pIdtCopy = (PX86DESC)&pbIdtCopyAlloc[_4K - cbIdte * 0x81 - j]; 470 Bs3MemCpy(pIdtCopy, paIdt, cbIdte * 256); 471 472 Idtr.cbIdt = IdtrSaved.cbIdt; 473 Idtr.pIdt = Bs3SelPtrToFlat(pIdtCopy); 474 475 ASMSetIDTR(&Idtr); 476 Bs3TrapSetJmpAndRestore(&Ctx81, &TrapCtx); 477 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx81, 2 /*int 8xh*/, 0x81 /*bXcpt*/, pszMode, uLine++); 478 479 ASMSetIDTR(&Idtr); 480 Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx); 481 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx80, 2 /*int 8xh*/, 0x80 /*bXcpt*/, pszMode, uLine++); 482 483 i = Bs3PagingProtect(uCr2Expected, _4K, 0 /*fSet*/, X86_PTE_P /*fClear*/); 484 if (RT_SUCCESS(i)) 485 { 486 ASMSetIDTR(&Idtr); 487 Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx); 488 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx80, 2 /*int 8xh*/, 0x80 /*bXcpt*/, pszMode, uLine++); 489 490 ASMSetIDTR(&Idtr); 491 Bs3TrapSetJmpAndRestore(&Ctx81, &TrapCtx); 492 bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx81, 0 /*uErrCd*/, uCr2Expected, f16BitSys, pszMode, uLine++); 493 494 Bs3PagingProtect(uCr2Expected, _4K, X86_PTE_P /*fSet*/, 0 /*fClear*/); 495 496 /* Check if that the entry type is checked after the whole IDTE has been cleared for #PF. */ 497 pIdtCopy[0x80 << cIdteShift].Gate.u4Type = 0; 498 i = Bs3PagingProtect(uCr2Expected, _4K, 0 /*fSet*/, X86_PTE_P /*fClear*/); 499 if (RT_SUCCESS(i)) 500 { 501 ASMSetIDTR(&Idtr); 502 Bs3TrapSetJmpAndRestore(&Ctx81, &TrapCtx); 503 bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx81, 0 /*uErrCd*/, uCr2Expected, f16BitSys, pszMode, uLine++); 504 505 Bs3PagingProtect(uCr2Expected, _4K, X86_PTE_P /*fSet*/, 0 /*fClear*/); 506 } 507 } 508 else 509 Bs3TestPrintf("Bs3PagingProtectPtr: %d\n", i); 510 511 ASMSetIDTR(&IdtrSaved); 512 } 513 } 514 515 /* 516 * The read/write and user/supervisor bits the IDT PTEs are irrelevant. 517 */ 518 uLine = 5300; 519 if (BS3_MODE_IS_PAGED(bMode) && pbIdtCopyAlloc) 520 { 521 Bs3MemCpy(pbIdtCopyAlloc, paIdt, cbIdte * 256); 522 Idtr.cbIdt = IdtrSaved.cbIdt; 523 Idtr.pIdt = Bs3SelPtrToFlat(pbIdtCopyAlloc); 524 525 ASMSetIDTR(&Idtr); 526 Bs3TrapSetJmpAndRestore(&Ctx81, &TrapCtx); 527 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx81, 2 /*int 8xh*/, 0x81 /*bXcpt*/, pszMode, uLine++); 528 529 i = Bs3PagingProtect(Idtr.pIdt, _4K, 0 /*fSet*/, X86_PTE_RW | X86_PTE_US /*fClear*/); 530 if (RT_SUCCESS(i)) 531 { 532 ASMSetIDTR(&Idtr); 533 Bs3TrapSetJmpAndRestore(&Ctx81, &TrapCtx); 534 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx81, 2 /*int 8xh*/, 0x81 /*bXcpt*/, pszMode, uLine++); 535 536 Bs3PagingProtect(Idtr.pIdt, _4K, X86_PTE_RW | X86_PTE_US /*fSet*/, 0 /*fClear*/); 537 } 538 ASMSetIDTR(&IdtrSaved); 539 } 540 541 # endif /* 32 || 64*/ 391 542 392 543 /* … … 458 609 } 459 610 BS3_ASSERT(uLine < 62000U && uLine > 32000U); 611 612 613 /** @todo 614 * - Run \#PF and \#GP (and others?) at CPLs other than zero. 615 * - Quickly generate all faults. 616 * - Check that CS.u1Accessed is set to 1. 617 * - Check that setting CS.u1Access to 1 triggers page fault. 618 * - Check CS.u1Access = 1 \#PF against \#NP(CS), CS.u2DPL, \#NP(SS), 619 * SS.u2DPL, and SS.u1Access=1 \#PF. 620 * - Check that IOPL doesn't influence anything for non-v8086. 621 * - EFLAGS effects (AC seen gonne missing in real-mode). 622 * - All the peculiarities v8086. 623 */ 624 625 # if TMPL_BITS != 16 626 Bs3MemFree(pbIdtCopyAlloc, 12*_1K); 627 # endif 460 628 } 461 629
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器