Changeset 97330 in vbox
- Timestamp:
- Oct 28, 2022 8:41:48 AM (2 years ago)
- Location:
- trunk/src/VBox/ValidationKit/bootsectors
- Files:
-
- 2 edited
-
bs3-cpu-weird-1-template.mac (modified) (3 diffs)
-
bs3-cpu-weird-1-x0.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-weird-1-template.mac
r97321 r97330 120 120 ; These will potentially trigger VM exits, except for the benign one. 121 121 ; 122 ; Note! Single instructions as the testcase will shift multibyte variations 123 ; across the wrap-around boundary and that would cause unpredictable 124 ; results for the 16-bit if there is more than one instruction. 125 ; 122 126 123 127 BS3_PROC_BEGIN_CMN bs3CpuWeird1_PcWrapBenign1, BS3_PBC_NEAR … … 130 134 131 135 BS3_PROC_BEGIN_CMN bs3CpuWeird1_PcWrapCpuId, BS3_PBC_NEAR 132 xor eax, eax133 136 cpuid 134 137 BS3_PROC_END_CMN bs3CpuWeird1_PcWrapCpuId … … 155 158 156 159 BS3_PROC_BEGIN_CMN bs3CpuWeird1_PcWrapWrDr0, BS3_PBC_NEAR 157 xor sAX, sAX158 160 mov dr0, sAX 159 161 BS3_PROC_END_CMN bs3CpuWeird1_PcWrapWrDr0 -
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-weird-1-x0.c
r97321 r97330 535 535 * IP / EIP Wrapping * 536 536 *********************************************************************************************************************************/ 537 #define PROTO1632(a_Template) FNBS3FAR a_Template ## _c16, a_Template ## _c16_EndProc, a_Template ## _c32, a_Template ## _c32_EndProc 538 PROTO1632(bs3CpuWeird1_PcWrapBenign1); 539 PROTO1632(bs3CpuWeird1_PcWrapBenign2); 540 PROTO1632(bs3CpuWeird1_PcWrapCpuId); 541 PROTO1632(bs3CpuWeird1_PcWrapIn80); 542 PROTO1632(bs3CpuWeird1_PcWrapOut80); 543 PROTO1632(bs3CpuWeird1_PcWrapSmsw); 544 PROTO1632(bs3CpuWeird1_PcWrapRdCr0); 545 PROTO1632(bs3CpuWeird1_PcWrapRdDr0); 546 PROTO1632(bs3CpuWeird1_PcWrapWrDr0); 547 #undef PROTO1632 548 537 #define PROTO_ALL(a_Template) \ 538 FNBS3FAR a_Template ## _c16, a_Template ## _c16_EndProc, \ 539 a_Template ## _c32, a_Template ## _c32_EndProc, \ 540 a_Template ## _c64, a_Template ## _c64_EndProc 541 PROTO_ALL(bs3CpuWeird1_PcWrapBenign1); 542 PROTO_ALL(bs3CpuWeird1_PcWrapBenign2); 543 PROTO_ALL(bs3CpuWeird1_PcWrapCpuId); 544 PROTO_ALL(bs3CpuWeird1_PcWrapIn80); 545 PROTO_ALL(bs3CpuWeird1_PcWrapOut80); 546 PROTO_ALL(bs3CpuWeird1_PcWrapSmsw); 547 PROTO_ALL(bs3CpuWeird1_PcWrapRdCr0); 548 PROTO_ALL(bs3CpuWeird1_PcWrapRdDr0); 549 PROTO_ALL(bs3CpuWeird1_PcWrapWrDr0); 550 #undef PROTO_ALL 551 552 typedef enum { kPcWrapSetup_None, kPcWrapSetup_ZeroRax } PCWRAPSETUP; 549 553 550 554 /** … … 574 578 575 579 576 static uint8_t bs3CpuWeird1_PcWrapping_Worker16(uint8_t bMode, uint8_t BS3_FAR *pbCode, uint8_t BS3_FAR *pbHead,580 static uint8_t bs3CpuWeird1_PcWrapping_Worker16(uint8_t bMode, RTSEL SelCode, uint8_t BS3_FAR *pbHead, 577 581 uint8_t BS3_FAR *pbTail, uint8_t BS3_FAR *pbAfter, 578 void const BS3_FAR *pvTemplate, size_t cbTemplate )582 void const BS3_FAR *pvTemplate, size_t cbTemplate, PCWRAPSETUP enmSetup) 579 583 { 580 584 BS3TRAPFRAME TrapCtx; … … 610 614 Bs3RegCtxSaveEx(&Ctx, bMode, 1024); 611 615 612 Ctx.cs = BS3_FP_SEG(pbCode);616 Ctx.cs = SelCode; 613 617 Ctx.rip.u = 0; 618 switch (enmSetup) 619 { 620 case kPcWrapSetup_None: 621 break; 622 case kPcWrapSetup_ZeroRax: 623 Ctx.rax.u = 0; 624 break; 625 } 614 626 615 627 /* V8086: Set IOPL to 3. */ … … 629 641 * Adjust the contexts for the real test. 630 642 */ 631 Ctx.cs = BS3_FP_SEG(pbCode);643 Ctx.cs = SelCode; 632 644 Ctx.rip.u = (uint32_t)_64K - cbTemplate; 633 645 … … 660 672 */ 661 673 Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx); 662 return bs3CpuWeird1_ComparePcWrap(&TrapCtx, &TrapExpect); 674 if (!bs3CpuWeird1_ComparePcWrap(&TrapCtx, &TrapExpect)) 675 { 676 #if 0 /* needs more work */ 677 /* 678 * Slide the instruction template across the boundrary byte-by-byte and 679 * check that it triggers #GP on the initial instruction on 386+. 680 */ 681 unsigned cbTail; 682 unsigned cbHead; 683 g_usBs3TestStep++; 684 for (cbTail = cbTemplate - 1, cbHead = 1; cbTail > 0; cbTail--, cbHead++, g_usBs3TestStep++) 685 { 686 pbTail[X86_PAGE_SIZE - cbTail - 1] = 0xcc; 687 Bs3MemCpy(&pbTail[X86_PAGE_SIZE - cbTail], pvTemplate, cbTail); 688 Bs3MemCpy(pbHead, &((uint8_t const *)pvTemplate)[cbTail], cbHead); 689 if (bXcpt == X86_XCPT_BP) 690 pbHead[cbHead] = 0xcc; /* int3 */ 691 else 692 { 693 pbHead[cbHead] = 0x0f; /* ud2 */ 694 pbHead[cbHead + 1] = 0x0b; 695 } 696 697 Ctx.rip.u = (uint32_t)_64K - cbTail; 698 if ((g_uBs3CpuDetected & BS3CPU_TYPE_MASK) <= BS3CPU_80286) 699 TrapExpect.Ctx.rip.u = cbHead + 1; 700 else 701 { 702 TrapExpect.Ctx.rip.u = Ctx.rip.u; 703 } 704 705 Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx); 706 if (bs3CpuWeird1_ComparePcWrap(&TrapCtx, &TrapExpect)) 707 return 1; 708 } 709 #endif 710 } 711 return 0; 663 712 } 664 713 … … 666 715 static uint8_t bs3CpuWeird1_PcWrapping_Worker32(uint8_t bMode, RTSEL SelCode, uint8_t BS3_FAR *pbPage1, 667 716 uint8_t BS3_FAR *pbPage2, uint32_t uFlatPage2, 668 void const BS3_FAR *pvTemplate, size_t cbTemplate )717 void const BS3_FAR *pvTemplate, size_t cbTemplate, PCWRAPSETUP enmSetup) 669 718 { 670 719 BS3TRAPFRAME TrapCtx; 671 720 BS3TRAPFRAME TrapExpect; 672 721 BS3REGCTX Ctx; 722 unsigned cbPage1; 723 unsigned cbPage2; 673 724 674 725 /* make sure they're allocated */ … … 694 745 Ctx.cs = BS3_SEL_R0_CS32; 695 746 Ctx.rip.u = uFlatPage2 - cbTemplate; 747 switch (enmSetup) 748 { 749 case kPcWrapSetup_None: 750 break; 751 case kPcWrapSetup_ZeroRax: 752 Ctx.rax.u = 0; 753 break; 754 } 696 755 697 756 Bs3TrapSetJmpAndRestore(&Ctx, &TrapExpect); … … 705 764 706 765 /* 707 * Adjust the contexts for the real test. 708 */ 709 Ctx.cs = SelCode; 710 Ctx.rip.u = UINT32_MAX - cbTemplate + 1; 711 712 TrapExpect.Ctx.cs = SelCode; 713 TrapExpect.Ctx.rip.u = 0; 714 715 /* 716 * Do a test run. 717 */ 718 Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx); 719 if (bs3CpuWeird1_ComparePcWrap(&TrapCtx, &TrapExpect)) 720 ASMHalt(); 766 * The real test uses the special CS selector. 767 */ 768 Ctx.cs = SelCode; 769 TrapExpect.Ctx.cs = SelCode; 770 771 /* 772 * Unlike 16-bit mode, the instruction may cross the wraparound boundary, 773 * so we test by advancing the template across byte-by-byte. 774 */ 775 for (cbPage1 = cbTemplate, cbPage2 = 0; cbPage1 > 0; cbPage1--, cbPage2++, g_usBs3TestStep++) 776 { 777 pbPage1[X86_PAGE_SIZE - cbPage1 - 1] = 0xcc; 778 Bs3MemCpy(&pbPage1[X86_PAGE_SIZE - cbPage1], pvTemplate, cbPage1); 779 Bs3MemCpy(pbPage2, &((uint8_t const *)pvTemplate)[cbPage1], cbPage2); 780 pbPage2[cbPage2] = 0x0f; /* ud2 */ 781 pbPage2[cbPage2 + 1] = 0x0b; 782 783 Ctx.rip.u = UINT32_MAX - cbPage1 + 1; 784 TrapExpect.Ctx.rip.u = cbPage2; 785 786 Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx); 787 if (bs3CpuWeird1_ComparePcWrap(&TrapCtx, &TrapExpect)) 788 return 1; 789 } 721 790 return 0; 722 791 } 723 792 724 793 794 static uint8_t bs3CpuWeird1_PcWrapping_Worker64(uint8_t bMode, uint8_t BS3_FAR *pbPage1, 795 uint8_t BS3_FAR *pbPage2, uint32_t uFlatPage1, 796 void const BS3_FAR *pvTemplate, size_t cbTemplate, PCWRAPSETUP enmSetup) 797 { 798 BS3TRAPFRAME TrapCtx; 799 BS3TRAPFRAME TrapExpect; 800 BS3REGCTX Ctx; 801 unsigned cbPage1; 802 unsigned cbPage2; 803 804 /* make sure they're allocated */ 805 Bs3MemZero(&Ctx, sizeof(Ctx)); 806 Bs3MemZero(&TrapCtx, sizeof(TrapCtx)); 807 Bs3MemZero(&TrapExpect, sizeof(TrapExpect)); 808 809 /* 810 * Create the expected result by first placing the code template 811 * at the start of the buffer and giving it a quick run. 812 */ 813 Bs3MemCpy(&pbPage1[X86_PAGE_SIZE - cbTemplate], pvTemplate, cbTemplate); 814 pbPage2[0] = 0x0f; /* ud2 */ 815 pbPage2[1] = 0x0b; 816 817 Bs3RegCtxSaveEx(&Ctx, bMode, 1024); 818 819 Ctx.rip.u = uFlatPage1 + X86_PAGE_SIZE - cbTemplate; 820 switch (enmSetup) 821 { 822 case kPcWrapSetup_None: 823 break; 824 case kPcWrapSetup_ZeroRax: 825 Ctx.rax.u = 0; 826 break; 827 } 828 829 Bs3TrapSetJmpAndRestore(&Ctx, &TrapExpect); 830 if (TrapExpect.bXcpt != X86_XCPT_UD) 831 { 832 833 Bs3TestFailedF("%u: Setup: bXcpt is %#x, expected %#x!\n", g_usBs3TestStep, TrapExpect.bXcpt, X86_XCPT_UD); 834 Bs3TrapPrintFrame(&TrapExpect); 835 return 1; 836 } 837 838 /* 839 * Unlike 16-bit mode, the instruction may cross the wraparound boundary, 840 * so we test by advancing the template across byte-by-byte. 841 */ 842 for (cbPage1 = cbTemplate, cbPage2 = 0; cbPage1 > 0; cbPage1--, cbPage2++, g_usBs3TestStep++) 843 { 844 pbPage1[X86_PAGE_SIZE - cbPage1 - 1] = 0xcc; 845 Bs3MemCpy(&pbPage1[X86_PAGE_SIZE - cbPage1], pvTemplate, cbPage1); 846 Bs3MemCpy(pbPage2, &((uint8_t const *)pvTemplate)[cbPage1], cbPage2); 847 pbPage2[cbPage2] = 0x0f; /* ud2 */ 848 pbPage2[cbPage2 + 1] = 0x0b; 849 850 Ctx.rip.u = UINT64_MAX - cbPage1 + 1; 851 TrapExpect.Ctx.rip.u = cbPage2; 852 853 Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx); 854 if (bs3CpuWeird1_ComparePcWrap(&TrapCtx, &TrapExpect)) 855 return 1; 856 } 857 return 0; 858 } 859 860 725 861 726 862 BS3_DECL_FAR(uint8_t) BS3_CMN_FAR_NM(bs3CpuWeird1_PcWrapping)(uint8_t bMode) 727 863 { 728 /*729 * Allocate a 68KB buffer for testing.730 *731 * This is a little annoying to work with from 16-bit bit, so we use732 * separate pointers to each interesting bit of it.733 */734 864 uint8_t bRet = 1; 735 /** @todo add api for doing this, so we don't need to include bs3-cmn-memory.h. */ 736 uint8_t BS3_FAR *pbBuf = (uint8_t BS3_FAR *)Bs3SlabAllocEx(&g_Bs3Mem4KLow.Core, 17 /*cPages*/, 0 /*fFlags*/); 737 if (pbBuf != NULL) 738 { 739 uint32_t const uFlatBuf = Bs3SelPtrToFlat(pbBuf); 740 uint8_t BS3_FAR *pbTail = Bs3XptrFlatToCurrent(uFlatBuf + 0x0f000); 741 uint8_t BS3_FAR *pbAfter = Bs3XptrFlatToCurrent(uFlatBuf + UINT32_C(0x10000)); 742 uint32_t off; 743 size_t i; 744 745 /* Fill the buffer with int1 instructions: */ 746 for (off = 0; off < UINT32_C(0x11000); off += _4K) 865 size_t i; 866 867 bs3CpuWeird1_SetGlobals(bMode); 868 869 if (BS3_MODE_IS_16BIT_CODE(bMode)) 870 { 871 /* 872 * For 16-bit testing, we need a 68 KB buffer. 873 * 874 * This is a little annoying to work with from 16-bit bit, so we use 875 * separate pointers to each interesting bit of it. 876 */ 877 /** @todo add api for doing this, so we don't need to include bs3-cmn-memory.h. */ 878 uint8_t BS3_FAR *pbBuf = (uint8_t BS3_FAR *)Bs3SlabAllocEx(&g_Bs3Mem4KLow.Core, 17 /*cPages*/, 0 /*fFlags*/); 879 if (pbBuf != NULL) 747 880 { 748 uint8_t BS3_FAR *pbPage = Bs3XptrFlatToCurrent(uFlatBuf + off); 749 Bs3MemSet(pbPage, 0xf1, _4K); 750 } 751 752 /* 753 * Now for the testing. 754 */ 755 bs3CpuWeird1_SetGlobals(bMode); 756 #define WITH_LEN(a_Template) a_Template, (uintptr_t)a_Template##_EndProc - (uintptr_t)a_Template 757 758 if (BS3_MODE_IS_16BIT_CODE(bMode)) 759 { 760 static struct { FPFNBS3FAR pfnStart, pfnEnd; unsigned fNoV86 : 1; } const s_aTemplates16[] = 881 uint32_t const uFlatBuf = Bs3SelPtrToFlat(pbBuf); 882 uint8_t BS3_FAR *pbTail = Bs3XptrFlatToCurrent(uFlatBuf + 0x0f000); 883 uint8_t BS3_FAR *pbAfter = Bs3XptrFlatToCurrent(uFlatBuf + UINT32_C(0x10000)); 884 RTSEL SelCode; 885 uint32_t off; 886 static struct { FPFNBS3FAR pfnStart, pfnEnd; PCWRAPSETUP enmSetup; unsigned fNoV86 : 1; } 887 const s_aTemplates16[] = 761 888 { 762 #define ENTRY16(a_Template, a_ fNoV86) { a_Template ## _c16, a_Template##_c16_EndProc, a_fNoV86 }763 ENTRY16(bs3CpuWeird1_PcWrapBenign1, 0),764 ENTRY16(bs3CpuWeird1_PcWrapBenign2, 0),765 ENTRY16(bs3CpuWeird1_PcWrapCpuId, 0),766 ENTRY16(bs3CpuWeird1_PcWrapIn80, 0),767 ENTRY16(bs3CpuWeird1_PcWrapOut80, 0),768 ENTRY16(bs3CpuWeird1_PcWrapSmsw, 0),769 ENTRY16(bs3CpuWeird1_PcWrapRdCr0, 1),770 ENTRY16(bs3CpuWeird1_PcWrapRdDr0, 1),771 ENTRY16(bs3CpuWeird1_PcWrapWrDr0, 1),889 #define ENTRY16(a_Template, a_enmSetup, a_fNoV86) { a_Template ## _c16, a_Template ## _c16_EndProc, a_enmSetup, a_fNoV86 } 890 ENTRY16(bs3CpuWeird1_PcWrapBenign1, kPcWrapSetup_None, 0), 891 ENTRY16(bs3CpuWeird1_PcWrapBenign2, kPcWrapSetup_None, 0), 892 ENTRY16(bs3CpuWeird1_PcWrapCpuId, kPcWrapSetup_ZeroRax, 0), 893 ENTRY16(bs3CpuWeird1_PcWrapIn80, kPcWrapSetup_None, 0), 894 ENTRY16(bs3CpuWeird1_PcWrapOut80, kPcWrapSetup_None, 0), 895 ENTRY16(bs3CpuWeird1_PcWrapSmsw, kPcWrapSetup_None, 0), 896 ENTRY16(bs3CpuWeird1_PcWrapRdCr0, kPcWrapSetup_None, 1), 897 ENTRY16(bs3CpuWeird1_PcWrapRdDr0, kPcWrapSetup_None, 1), 898 ENTRY16(bs3CpuWeird1_PcWrapWrDr0, kPcWrapSetup_ZeroRax, 1), 772 899 #undef ENTRY16 773 900 }; 774 uint8_t BS3_FAR *pbCode = BS3_FP_MAKE((uint16_t)(uFlatBuf >> 4), 0); 901 902 /* Fill the buffer with int1 instructions: */ 903 for (off = 0; off < UINT32_C(0x11000); off += _4K) 904 { 905 uint8_t BS3_FAR *pbPage = Bs3XptrFlatToCurrent(uFlatBuf + off); 906 Bs3MemSet(pbPage, 0xf1, _4K); 907 } 908 909 /* Setup the CS for it. */ 910 SelCode = (uint16_t)(uFlatBuf >> 4); 775 911 if (!BS3_MODE_IS_RM_OR_V86(bMode)) 776 912 { 777 913 Bs3SelSetup16BitCode(&Bs3GdteSpare00, uFlatBuf, 0); 778 pbCode = BS3_FP_MAKE(BS3_SEL_SPARE_00, 0);914 SelCode = BS3_SEL_SPARE_00; 779 915 } 780 916 … … 786 922 } 787 923 788 for (i = 0; i < RT_ELEMENTS(s_aTemplates16); i++ , g_usBs3TestStep++)924 for (i = 0; i < RT_ELEMENTS(s_aTemplates16); i++) 789 925 { 790 if (s_aTemplates16[i].fNoV86 && BS3_MODE_IS_V86(bMode)) 791 continue; 792 bs3CpuWeird1_PcWrapping_Worker16(bMode, pbCode, pbBuf, pbTail, pbAfter, s_aTemplates16[i].pfnStart, 793 (uintptr_t)s_aTemplates16[i].pfnEnd - (uintptr_t)s_aTemplates16[i].pfnStart); 926 if (!s_aTemplates16[i].fNoV86 || !BS3_MODE_IS_V86(bMode)) 927 bs3CpuWeird1_PcWrapping_Worker16(bMode, SelCode, pbBuf, pbTail, pbAfter, s_aTemplates16[i].pfnStart, 928 (uintptr_t)s_aTemplates16[i].pfnEnd - (uintptr_t)s_aTemplates16[i].pfnStart, 929 s_aTemplates16[i].enmSetup); 930 g_usBs3TestStep = (g_usBs3TestStep + 16) & ~16; 794 931 } 795 932 796 933 if (BS3_MODE_IS_V86(bMode)) 797 934 ASMBitSet(Bs3SharedIobp, 0x80); 798 bRet = 0; 799 } 800 else if (BS3_MODE_IS_32BIT_CODE(bMode)) 801 { 802 static struct { FPFNBS3FAR pfnStart, pfnEnd; } const s_aTemplates32[] = 803 { 804 #define ENTRY32(a_Template) { a_Template ## _c32, a_Template##_c32_EndProc } 805 ENTRY32(bs3CpuWeird1_PcWrapBenign1), 806 ENTRY32(bs3CpuWeird1_PcWrapBenign2), 807 ENTRY32(bs3CpuWeird1_PcWrapCpuId), 808 //ENTRY32(bs3CpuWeird1_PcWrapIn80), - causes GURU because of vmxHCAdvanceGuestRipBy. 809 //ENTRY32(bs3CpuWeird1_PcWrapOut80), - ditto. 810 ENTRY32(bs3CpuWeird1_PcWrapSmsw), 811 ENTRY32(bs3CpuWeird1_PcWrapRdCr0), 812 ENTRY32(bs3CpuWeird1_PcWrapRdDr0), 813 ENTRY32(bs3CpuWeird1_PcWrapWrDr0), 814 #undef ENTRY32 815 }; 816 817 Bs3SelSetup32BitCode(&Bs3GdteSpare00, uFlatBuf + UINT32_C(0x10000), UINT32_MAX, 0); 818 819 for (i = 0; i < RT_ELEMENTS(s_aTemplates32); i++, g_usBs3TestStep++) 820 { 821 //Bs3TestPrintf("pfnStart=%p pfnEnd=%p\n", s_aTemplates32[i].pfnStart, s_aTemplates32[i].pfnEnd); 822 bs3CpuWeird1_PcWrapping_Worker32(bMode, BS3_SEL_SPARE_00, pbTail, pbAfter, uFlatBuf + UINT32_C(0x10000), 823 Bs3SelLnkPtrToCurPtr(s_aTemplates32[i].pfnStart), 824 (uintptr_t)s_aTemplates32[i].pfnEnd - (uintptr_t)s_aTemplates32[i].pfnStart); 825 } 935 936 Bs3SlabFree(&g_Bs3Mem4KLow.Core, uFlatBuf, 17); 937 826 938 bRet = 0; 827 939 } 828 940 else 941 Bs3TestFailed("Failed to allocate 17 pages (68KB)"); 942 } 943 else 944 { 945 /* 946 * For both 32-bit and 64-bit mode tests we only need a buffer with 947 * two pages. 948 */ 949 uint8_t BS3_FAR *pbBuf = (uint8_t BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_TILED, X86_PAGE_SIZE * 2); 950 if (pbBuf) 829 951 { 830 BS3_ASSERT(bMode == BS3_MODE_LM64); 831 /** @todo test LM64 wraparound too (doing some page table aliasing perhaps). */ 832 bRet = BS3TESTDOMODE_SKIPPED; 952 uint32_t const uFlatBuf = Bs3SelPtrToFlat(pbBuf); 953 Bs3MemSet(pbBuf, 0xf1, X86_PAGE_SIZE * 2); 954 955 /* 956 * For 32-bit we set up a CS that starts with the 2nd page and 957 * ends with the first. 958 */ 959 if (BS3_MODE_IS_32BIT_CODE(bMode)) 960 { 961 static struct { FPFNBS3FAR pfnStart, pfnEnd; PCWRAPSETUP enmSetup; } const s_aTemplates32[] = 962 { 963 #define ENTRY32(a_Template, a_enmSetup) { a_Template ## _c32, a_Template ## _c32_EndProc, a_enmSetup } 964 ENTRY32(bs3CpuWeird1_PcWrapBenign1, kPcWrapSetup_None), 965 ENTRY32(bs3CpuWeird1_PcWrapBenign2, kPcWrapSetup_None), 966 ENTRY32(bs3CpuWeird1_PcWrapCpuId, kPcWrapSetup_ZeroRax), 967 ENTRY32(bs3CpuWeird1_PcWrapIn80, kPcWrapSetup_None), 968 ENTRY32(bs3CpuWeird1_PcWrapOut80, kPcWrapSetup_None), 969 ENTRY32(bs3CpuWeird1_PcWrapSmsw, kPcWrapSetup_None), 970 ENTRY32(bs3CpuWeird1_PcWrapRdCr0, kPcWrapSetup_None), 971 ENTRY32(bs3CpuWeird1_PcWrapRdDr0, kPcWrapSetup_None), 972 ENTRY32(bs3CpuWeird1_PcWrapWrDr0, kPcWrapSetup_ZeroRax), 973 #undef ENTRY32 974 }; 975 976 Bs3SelSetup32BitCode(&Bs3GdteSpare00, uFlatBuf + X86_PAGE_SIZE, UINT32_MAX, 0); 977 978 for (i = 0; i < RT_ELEMENTS(s_aTemplates32); i++) 979 { 980 //Bs3TestPrintf("pfnStart=%p pfnEnd=%p\n", s_aTemplates32[i].pfnStart, s_aTemplates32[i].pfnEnd); 981 bs3CpuWeird1_PcWrapping_Worker32(bMode, BS3_SEL_SPARE_00, pbBuf, &pbBuf[X86_PAGE_SIZE], 982 uFlatBuf + X86_PAGE_SIZE, Bs3SelLnkPtrToCurPtr(s_aTemplates32[i].pfnStart), 983 (uintptr_t)s_aTemplates32[i].pfnEnd - (uintptr_t)s_aTemplates32[i].pfnStart, 984 s_aTemplates32[i].enmSetup); 985 g_usBs3TestStep = (g_usBs3TestStep + 16) & ~16; 986 } 987 988 bRet = 0; 989 } 990 /* 991 * For 64-bit we have to alias the two pages so they straddle address 0. 992 * This ASSUMES there is nothing important in page 0 when in LM64. 993 */ 994 else 995 { 996 int rc = Bs3PagingAlias(UINT64_MAX - X86_PAGE_SIZE + 1, uFlatBuf, X86_PAGE_SIZE, 997 X86_PTE_P | X86_PTE_A | X86_PTE_D | X86_PTE_RW); 998 BS3_ASSERT(bMode == BS3_MODE_LM64); 999 if (RT_SUCCESS(rc)) 1000 { 1001 rc = Bs3PagingAlias(UINT64_C(0), uFlatBuf + X86_PAGE_SIZE, X86_PAGE_SIZE, 1002 X86_PTE_P | X86_PTE_A | X86_PTE_D | X86_PTE_RW); 1003 if (RT_SUCCESS(rc)) 1004 { 1005 static struct { FPFNBS3FAR pfnStart, pfnEnd; PCWRAPSETUP enmSetup; } const s_aTemplates64[] = 1006 { 1007 #define ENTRY64(a_Template, a_enmSetup) { a_Template ## _c64, a_Template ## _c64_EndProc, a_enmSetup } 1008 ENTRY64(bs3CpuWeird1_PcWrapBenign1, kPcWrapSetup_None), 1009 ENTRY64(bs3CpuWeird1_PcWrapBenign2, kPcWrapSetup_None), 1010 ENTRY64(bs3CpuWeird1_PcWrapCpuId, kPcWrapSetup_ZeroRax), 1011 ENTRY64(bs3CpuWeird1_PcWrapIn80, kPcWrapSetup_None), 1012 ENTRY64(bs3CpuWeird1_PcWrapOut80, kPcWrapSetup_None), 1013 ENTRY64(bs3CpuWeird1_PcWrapSmsw, kPcWrapSetup_None), 1014 ENTRY64(bs3CpuWeird1_PcWrapRdCr0, kPcWrapSetup_None), 1015 ENTRY64(bs3CpuWeird1_PcWrapRdDr0, kPcWrapSetup_None), 1016 ENTRY64(bs3CpuWeird1_PcWrapWrDr0, kPcWrapSetup_ZeroRax), 1017 #undef ENTRY64 1018 }; 1019 1020 for (i = 0; i < RT_ELEMENTS(s_aTemplates64); i++) 1021 { 1022 bs3CpuWeird1_PcWrapping_Worker64(bMode, pbBuf, &pbBuf[X86_PAGE_SIZE], uFlatBuf, 1023 Bs3SelLnkPtrToCurPtr(s_aTemplates64[i].pfnStart), 1024 (uintptr_t)s_aTemplates64[i].pfnEnd 1025 - (uintptr_t)s_aTemplates64[i].pfnStart, 1026 s_aTemplates64[i].enmSetup); 1027 g_usBs3TestStep = (g_usBs3TestStep + 16) & ~16; 1028 } 1029 1030 bRet = 0; 1031 1032 Bs3PagingUnalias(UINT64_C(0), X86_PAGE_SIZE); 1033 } 1034 else 1035 Bs3TestFailedF("Bs3PagingAlias(0...) failed: %d", rc); 1036 Bs3PagingUnalias(UINT64_MAX - X86_PAGE_SIZE + 1, X86_PAGE_SIZE); 1037 } 1038 else 1039 Bs3TestFailedF("Bs3PagingAlias(0xfff...) failed: %d", rc); 1040 } 833 1041 } 834 835 Bs3SlabFree(&g_Bs3Mem4KLow.Core, uFlatBuf, 17); 836 } 837 else 838 Bs3TestFailed("Failed to allocate 17 pages (68KB)"); 1042 else 1043 Bs3TestFailed("Failed to allocate 2 pages for tests."); 1044 Bs3MemFree(pbBuf, X86_PAGE_SIZE * 2); 1045 } 839 1046 840 1047 return bRet;
Note:
See TracChangeset
for help on using the changeset viewer.

