VirtualBox

Changeset 66342 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
Mar 29, 2017 4:22:31 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114278
Message:

IEM: Converted grp 9 to tables and fixed cmpxchg16b/8b prefix handling.

Location:
trunk/src/VBox/ValidationKit/bootsectors
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-decoding-1.c32

    r66341 r66342  
    406406CPUDECODE1UDTST const g_aUdTest2Byte_0f[] =
    407407{
    408 #if 1
     408#if 0
    409409    {  UD_T_EXACT, 2, { 0x0f, 0x04 }, UD_F_ANY_PFX },
    410410    {  UD_T_EXACT, 2, { 0x0f, 0x0a }, UD_F_ANY_PFX },
     
    536536    {  UD_T_MODRM_MR0, 2, { 0x0f, 0xc7 }, UD_F_ANY_PFX },
    537537    {  UD_T_MODRM_RR0, 2, { 0x0f, 0xc7 }, UD_F_ANY_PFX },
    538     //{  UD_T_MODRM_MR1, 2, { 0x0f, 0xc7 }, xxxx }, - cmpxchg8b/16b is weird, needs special testcase.
     538    //{  UD_T_MODRM_MR1, 2, { 0x0f, 0xc7 }, UD_F_NOT_NO_PFX | UD_F_NOT_OZ_PFX | UD_F_NOT_RN_PFX | UD_F_NOT_RZ_PFX | UD_F_NOT_LK_PFX }, - cmpxchg8b ignores everything. @
    539539    {  UD_T_MODRM_RR1, 2, { 0x0f, 0xc7 }, UD_F_ANY_PFX },
    540540    {  UD_T_MODRM_MR2, 2, { 0x0f, 0xc7 }, UD_F_ANY_PFX },
     
    546546    {  UD_T_MODRM_MR5, 2, { 0x0f, 0xc7 }, UD_F_ANY_PFX },
    547547    {  UD_T_MODRM_RR5, 2, { 0x0f, 0xc7 }, UD_F_ANY_PFX },
    548     //{  UD_T_MODRM_MR0, 2, { 0x0f, 0xc7 }, UD_F_NOT_OZ_PFX | UD_F_NOT_RN_PFX |  },
    549     {  UD_T_MODRM_RR0, 2, { 0x0f, 0xc7 }, UD_F_ANY_PFX },
    550 #if 1
     548    {  UD_T_MODRM_MR6, 2, { 0x0f, 0xc7 }, UD_F_NOT_NO_PFX | UD_F_NOT_OZ_PFX | UD_F_NOT_RZ_PFX }, /* f2? */
     549    {  UD_T_MODRM_RR6, 2, { 0x0f, 0xc7 }, UD_F_NOT_NO_PFX | UD_F_NOT_OZ_PFX }, /* (rdrand Rv) */
     550    {  UD_T_MODRM_MR7, 2, { 0x0f, 0xc7 }, UD_F_NOT_NO_PFX }, /* vmptrst Mq (f2?); */
     551    {  UD_T_MODRM_RR7, 2, { 0x0f, 0xc7 }, UD_F_NOT_NO_PFX | UD_F_NOT_OZ_PFX | UD_F_NOT_RZ_PFX }, /* rdrand Rv; rdpid Rd/q (f2,66??); */
     552#if 0
    551553    {  UD_T_MODRM, 2, { 0x0f, 0xd0 }, UD_F_NOT_OZ_PFX | UD_F_NOT_RN_PFX },
    552554    {  UD_T_MODRM, 2, { 0x0f, 0xd1 }, UD_F_NOT_NO_PFX | UD_F_NOT_OZ_PFX },
     
    12901292
    12911293
     1294#if 0
     1295/**
     1296 * Checks how prefixes affects cmpxchg8b and cmpxchg16b
     1297 *
     1298 * The thing here is that the intel opcode tables indicates that the 66 and f3
     1299 * prefixes encodings are reserved and causes \#UD, where AMD doesn't.  Seems
     1300 * though that the f2, f3 and 66 prefixes are ignored on skylake intel.  Need to
     1301 * make sure this is the case, also in 64-bit mode and for the 16b version.
     1302 */
     1303static void DecodeCmpXchg8bVs16b(void)
     1304{
     1305    uint8_t BS3_FAR *pbPages;
     1306
     1307    /* Check that the instructions are supported. */
     1308    if (   !(g_uBs3CpuDetected & BS3CPU_F_CPUID)
     1309        || !(ASMCpuId_EDX(1) & X86_CPUID_FEATURE_EDX_CX8))
     1310    {
     1311        Bs3TestSkipped("not supported");
     1312        return;
     1313    }
     1314
     1315    /* Setup a guarded page. */
     1316    pbPages = Bs3MemGuardedTestPageAlloc(BS3MEMKIND_FLAT32);
     1317    if (pbPages)
     1318    {
     1319
     1320        Bs3MemGuardedTestPageFree(pbPages);
     1321    }
     1322    else
     1323        Bs3TestFailed("Failed to allocate two pages!\n");
     1324}
     1325#endif
     1326
     1327
    12921328/**
    12931329 * Checks various prefix encodings with the MOVBE and CRC32 instructions to try
     
    16611697    Bs3TestPrintf("g_uBs3CpuDetected=%#x\n", g_uBs3CpuDetected);
    16621698
    1663 #if 1
     1699#if 0
    16641700    Bs3TestSub("CMPPS, CMPPD, CMPSS, CMPSD");
    16651701    DecodeCmppsCmppdCmpssCmpsd();
     
    16681704    DecodeMovbeVsCrc32();
    16691705#endif
     1706
     1707    //Bs3TestSub("CMPXCHG8B/16B");
     1708    //DecodeCmpXchg8bVs16b();
    16701709
    16711710#if 1
     
    16731712    DecodeUdEdgeTest(g_aUdTest2Byte_0f, RT_ELEMENTS(g_aUdTest2Byte_0f));
    16741713#endif
    1675 #if 1
     1714#if 0
    16761715    Bs3TestSub("3 byte undefined opcodes 0f 38");
    16771716    DecodeUdEdgeTest(g_aUdTest3Byte_0f_38, RT_ELEMENTS(g_aUdTest3Byte_0f_38));
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-instr-2-template.c

    r65507 r66342  
    5454extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_cmpxchg16b_rdi_ud2);
    5555extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_lock_cmpxchg16b_rdi_ud2);
     56extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_o16_cmpxchg16b_rdi_ud2);
     57extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_lock_o16_cmpxchg16b_rdi_ud2);
     58extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_repz_cmpxchg16b_rdi_ud2);
     59extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_lock_repz_cmpxchg16b_rdi_ud2);
     60extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_repnz_cmpxchg16b_rdi_ud2);
     61extern FNBS3FAR     BS3_CMN_NM(bs3CpuInstr2_lock_repnz_cmpxchg16b_rdi_ud2);
    5662# endif
    5763#endif
     
    550556    PRTUINT128U     pau128       = RT_ALIGN_PT(&au128[0], sizeof(RTUINT128U), PRTUINT128U);
    551557    bool const      fSupportCX16 = RT_BOOL(ASMCpuId_ECX(1) & X86_CPUID_FEATURE_ECX_CX16);
    552     unsigned        iLocked;
    553558    unsigned        iFlags;
    554559    unsigned        offBuf;
    555560    unsigned        iMatch;
     561    unsigned        iWorker;
     562    static struct
     563    {
     564        bool        fLocked;
     565        uint8_t     offUd2;
     566        FNBS3FAR   *pfnWorker;
     567    } const s_aWorkers[] =
     568    {
     569        {   false,  4,  BS3_CMN_NM(bs3CpuInstr2_cmpxchg16b_rdi_ud2) },
     570        {   false,  5,  BS3_CMN_NM(bs3CpuInstr2_o16_cmpxchg16b_rdi_ud2) },
     571        {   false,  5,  BS3_CMN_NM(bs3CpuInstr2_repz_cmpxchg16b_rdi_ud2) },
     572        {   false,  5,  BS3_CMN_NM(bs3CpuInstr2_repnz_cmpxchg16b_rdi_ud2) },
     573        {   true, 1+4,  BS3_CMN_NM(bs3CpuInstr2_lock_cmpxchg16b_rdi_ud2) },
     574        {   true, 1+5,  BS3_CMN_NM(bs3CpuInstr2_lock_o16_cmpxchg16b_rdi_ud2) },
     575        {   true, 1+5,  BS3_CMN_NM(bs3CpuInstr2_lock_repz_cmpxchg16b_rdi_ud2) },
     576        {   true, 1+5,  BS3_CMN_NM(bs3CpuInstr2_lock_repnz_cmpxchg16b_rdi_ud2) },
     577    };
    556578
    557579    /* Ensure the structures are allocated before we sample the stack pointer. */
     
    572594     */
    573595    g_usBs3TestStep = 0;
    574     Bs3RegCtxSetRipCsFromCurPtr(&Ctx, BS3_CMN_NM(bs3CpuInstr2_cmpxchg16b_rdi_ud2));
    575     for (iLocked = 0; iLocked < 2; iLocked++)
    576     {
     596    for (iWorker = 0; iWorker < RT_ELEMENTS(s_aWorkers); iWorker++)
     597    {
     598        Bs3RegCtxSetRipCsFromCurPtr(&Ctx, s_aWorkers[iWorker].pfnWorker);
     599
    577600        /*
    578601         * One loop with all status flags set, and one with them clear.
     
    604627                    Bs3TrapSetJmpAndRestore(&Ctx, &TrapFrame);
    605628                    g_usBs3TestStep++;
    606                     //Bs3TestPrintf("Test: iFlags=%d offBuf=%d iMatch=%u\n", iFlags, offBuf, iMatch);
     629                    //Bs3TestPrintf("Test: iFlags=%d offBuf=%d iMatch=%u iWorker=%u\n", iFlags, offBuf, iMatch, iWorker);
    607630                    bExpectXcpt = X86_XCPT_UD;
    608631                    if (fSupportCX16)
     
    622645                            else
    623646                                ExpectCtx.rflags.u32 = Ctx.rflags.u32 & ~X86_EFL_ZF;
    624                             ExpectCtx.rip.u = Ctx.rip.u + 4 + (iLocked & 1);
     647                            ExpectCtx.rip.u = Ctx.rip.u + s_aWorkers[iWorker].offUd2;
    625648                        }
    626649                        ExpectCtx.rflags.u32 |= X86_EFL_RF;
     
    632655                        if (TrapFrame.bXcpt != bExpectXcpt)
    633656                            Bs3TestFailedF("Expected bXcpt=#%x, got %#x (%#x)", bExpectXcpt, TrapFrame.bXcpt, TrapFrame.uErrCd);
    634                         Bs3TestFailedF("^^^ iLocked=%d iFlags=%d offBuf=%d iMatch=%u\n", iLocked, iFlags, offBuf, iMatch);
     657                        Bs3TestFailedF("^^^ iWorker=%d iFlags=%d offBuf=%d iMatch=%u\n", iWorker, iFlags, offBuf, iMatch);
    635658                        ASMHalt();
    636659                    }
     
    642665            Ctx.rflags.u16 &= ~X86_EFL_STATUS_BITS;
    643666        }
    644         Bs3RegCtxSetRipCsFromCurPtr(&Ctx, BS3_CMN_NM(bs3CpuInstr2_lock_cmpxchg16b_rdi_ud2));
    645667    }
    646668
    647669    return 0;
    648 
    649670}
    650671# endif /* ARCH_BITS == 64 */
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-instr-2-template.mac

    r65507 r66342  
    101101AssertCompile(.again - BS3_LAST_LABEL == 5)
    102102BS3_PROC_END_CMN   bs3CpuInstr2_lock_cmpxchg16b_rdi_ud2
     103
     104
     105BS3_PROC_BEGIN_CMN bs3CpuInstr2_o16_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
     106        o16 cmpxchg16b [rdi]
     107.again:
     108        ud2
     109        jmp     .again
     110AssertCompile(.again - BS3_LAST_LABEL == 5)
     111BS3_PROC_END_CMN   bs3CpuInstr2_o16_cmpxchg16b_rdi_ud2
     112
     113
     114BS3_PROC_BEGIN_CMN bs3CpuInstr2_lock_o16_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
     115        db 0f0h, 066h
     116        cmpxchg16b [rdi]
     117.again:
     118        ud2
     119        jmp     .again
     120AssertCompile(.again - BS3_LAST_LABEL == 6)
     121BS3_PROC_END_CMN   bs3CpuInstr2_lock_o16_cmpxchg16b_rdi_ud2
     122
     123
     124BS3_PROC_BEGIN_CMN bs3CpuInstr2_repz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
     125        repz cmpxchg16b [rdi]
     126.again:
     127        ud2
     128        jmp     .again
     129AssertCompile(.again - BS3_LAST_LABEL == 5)
     130BS3_PROC_END_CMN   bs3CpuInstr2_repz_cmpxchg16b_rdi_ud2
     131
     132
     133BS3_PROC_BEGIN_CMN bs3CpuInstr2_lock_repz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
     134        db 0f0h, 0f3h
     135        cmpxchg16b [rdi]
     136.again:
     137        ud2
     138        jmp     .again
     139AssertCompile(.again - BS3_LAST_LABEL == 6)
     140BS3_PROC_END_CMN   bs3CpuInstr2_lock_repz_cmpxchg16b_rdi_ud2
     141
     142BS3_PROC_BEGIN_CMN bs3CpuInstr2_repnz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
     143        repnz cmpxchg16b [rdi]
     144.again:
     145        ud2
     146        jmp     .again
     147AssertCompile(.again - BS3_LAST_LABEL == 5)
     148BS3_PROC_END_CMN   bs3CpuInstr2_repnz_cmpxchg16b_rdi_ud2
     149
     150
     151BS3_PROC_BEGIN_CMN bs3CpuInstr2_lock_repnz_cmpxchg16b_rdi_ud2, BS3_PBC_NEAR
     152        db 0f0h, 0f2h
     153        cmpxchg16b [rdi]
     154.again:
     155        ud2
     156        jmp     .again
     157AssertCompile(.again - BS3_LAST_LABEL == 6)
     158BS3_PROC_END_CMN   bs3CpuInstr2_lock_repnz_cmpxchg16b_rdi_ud2
     159
     160;; @todo figure out this fudge. sigh.
     161times (348) db 0cch ; fudge to avoid 'rderr' during boot.
     162
    103163 %endif ; TMPL_BITS == 64
    104164
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette