VirtualBox

Ignore:
Timestamp:
Apr 6, 2017 10:44:30 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114437
Message:

IEM: Limited xsave and xrstor implemention. Implemented vstmxcsr.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-generated-1-template.c

    r66450 r66457  
    9898} BS3CG1OPLOC;
    9999
     100
    100101/**
    101102 * The state.
     
    151152    /** Target mode (g_bBs3CurrentMode).  */
    152153    uint8_t                 bMode;
     154    /** The CPU vendor (BS3CPUVENDOR). */
     155    uint8_t                 bCpuVendor;
    153156    /** First ring being tested. */
    154157    uint8_t                 iFirstRing;
     
    166169    uint8_t                 offCurImm;
    167170    /** Buffer for assembling the current instruction. */
    168     uint8_t                 abCurInstr[24];
     171    uint8_t                 abCurInstr[23];
    169172
    170173    /** Set if the encoding can't be tested in the same ring as this test code.
     
    24672470            CASE_PRED(BS3CG1PRED_PAGING_ON,  BS3_MODE_IS_PAGED(pThis->bMode));
    24682471            CASE_PRED(BS3CG1PRED_PAGING_OFF, !BS3_MODE_IS_PAGED(pThis->bMode));
     2472            CASE_PRED(BS3CG1PRED_VENDOR_AMD,   pThis->bCpuVendor == BS3CPUVENDOR_AMD);
     2473            CASE_PRED(BS3CG1PRED_VENDOR_INTEL, pThis->bCpuVendor == BS3CPUVENDOR_INTEL);
     2474            CASE_PRED(BS3CG1PRED_VENDOR_VIA,   pThis->bCpuVendor == BS3CPUVENDOR_VIA);
    24692475
    24702476#undef CASE_PRED
     
    29052911 *
    29062912 * @returns true if successful, false if not.
    2907  * @param   pThis               The state.
    2908  * @param   bTestXcptExpected   The exception causing the test code to stop
    2909  *                              executing.
    2910  * @param   iEncoding           For error reporting.
     2913 * @param   pThis                   The state.
     2914 * @param   bTestXcptExpected       The exception causing the test code to stop
     2915 *                                  executing.
     2916 * @param   fInvalidEncodingPgFault Set if we've cut the instruction a byte
     2917 *                                  short and is expecting a \#PF on the page
     2918 *                                  boundrary rather than a \#UD.  Only set if
     2919 *                                  fInvalidEncoding is also set.
     2920 * @param   iEncoding               For error reporting.
    29112921 */
    2912 static bool BS3_NEAR_CODE Bs3Cg1CheckResult(PBS3CG1STATE pThis, uint8_t bTestXcptExpected, unsigned iEncoding)
     2922static bool BS3_NEAR_CODE Bs3Cg1CheckResult(PBS3CG1STATE pThis, uint8_t bTestXcptExpected,
     2923                                            bool fInvalidEncodingPgFault,  unsigned iEncoding)
    29132924{
    29142925    unsigned iOperand;
     
    29372948    {
    29382949        cbAdjustPc = 0;
    2939         bExpectedXcpt = X86_XCPT_UD;
     2950        if (!fInvalidEncodingPgFault)
     2951            bExpectedXcpt = X86_XCPT_UD;
     2952        else
     2953        {
     2954            bExpectedXcpt = X86_XCPT_PF;
     2955            pThis->Ctx.cr2.u = pThis->uCodePgFlat + X86_PAGE_SIZE;
     2956        }
    29402957    }
    29412958    if (RT_LIKELY(   pThis->TrapFrame.bXcpt     == bExpectedXcpt
     
    29582975                if (pThis->aOperands[iOperand].enmLocation == BS3CG1OPLOC_MEM_RW)
    29592976                {
    2960                     BS3PTRUNION PtrUnion;
    2961                     PtrUnion.pb = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[iOperand].off];
    2962                     switch (pThis->aOperands[iOperand].cbOp)
     2977                    if (pThis->aOperands[iOperand].off)
    29632978                    {
    2964                         case 1:
    2965                             if (*PtrUnion.pu8 == pThis->MemOp.ab[0])
    2966                                 continue;
    2967                             Bs3TestFailedF("op%u: Wrote %#04RX8, expected %#04RX8", iOperand, *PtrUnion.pu8, pThis->MemOp.ab[0]);
    2968                             break;
    2969                         case 2:
    2970                             if (*PtrUnion.pu16 == pThis->MemOp.au16[0])
    2971                                 continue;
    2972                             Bs3TestFailedF("op%u: Wrote %#06RX16, expected %#06RX16",
    2973                                            iOperand, *PtrUnion.pu16, pThis->MemOp.au16[0]);
    2974                             break;
    2975                         case 4:
    2976                             if (*PtrUnion.pu32 == pThis->MemOp.au32[0])
    2977                                 continue;
    2978                             Bs3TestFailedF("op%u: Wrote %#010RX32, expected %#010RX32",
    2979                                            iOperand, *PtrUnion.pu32, pThis->MemOp.au32[0]);
    2980                             break;
    2981                         case 8:
    2982                             if (*PtrUnion.pu64 == pThis->MemOp.au64[0])
    2983                                 continue;
    2984                             Bs3TestFailedF("op%u: Wrote %#018RX64, expected %#018RX64",
    2985                                            iOperand, *PtrUnion.pu64, pThis->MemOp.au64[0]);
    2986                             break;
    2987                         default:
    2988                             if (Bs3MemCmp(PtrUnion.pb, pThis->MemOp.ab, pThis->aOperands[iOperand].cbOp) == 0)
    2989                                 continue;
    2990                             Bs3TestFailedF("op%u: Wrote %.*Rhxs, expected %.*Rhxs",
    2991                                            iOperand,
    2992                                            pThis->aOperands[iOperand].cbOp, PtrUnion.pb,
    2993                                            pThis->aOperands[iOperand].cbOp, pThis->MemOp.ab);
    2994                             break;
     2979                        BS3PTRUNION PtrUnion;
     2980                        PtrUnion.pb = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[iOperand].off];
     2981                        switch (pThis->aOperands[iOperand].cbOp)
     2982                        {
     2983                            case 1:
     2984                                if (*PtrUnion.pu8 == pThis->MemOp.ab[0])
     2985                                    continue;
     2986                                Bs3TestFailedF("op%u: Wrote %#04RX8, expected %#04RX8",
     2987                                               iOperand, *PtrUnion.pu8, pThis->MemOp.ab[0]);
     2988                                break;
     2989                            case 2:
     2990                                if (*PtrUnion.pu16 == pThis->MemOp.au16[0])
     2991                                    continue;
     2992                                Bs3TestFailedF("op%u: Wrote %#06RX16, expected %#06RX16",
     2993                                               iOperand, *PtrUnion.pu16, pThis->MemOp.au16[0]);
     2994                                break;
     2995                            case 4:
     2996                                if (*PtrUnion.pu32 == pThis->MemOp.au32[0])
     2997                                    continue;
     2998                                Bs3TestFailedF("op%u: Wrote %#010RX32, expected %#010RX32",
     2999                                               iOperand, *PtrUnion.pu32, pThis->MemOp.au32[0]);
     3000                                break;
     3001                            case 8:
     3002                                if (*PtrUnion.pu64 == pThis->MemOp.au64[0])
     3003                                    continue;
     3004                                Bs3TestFailedF("op%u: Wrote %#018RX64, expected %#018RX64",
     3005                                               iOperand, *PtrUnion.pu64, pThis->MemOp.au64[0]);
     3006                                break;
     3007                            default:
     3008                                if (Bs3MemCmp(PtrUnion.pb, pThis->MemOp.ab, pThis->aOperands[iOperand].cbOp) == 0)
     3009                                    continue;
     3010                                Bs3TestFailedF("op%u: Wrote %.*Rhxs, expected %.*Rhxs",
     3011                                               iOperand,
     3012                                               pThis->aOperands[iOperand].cbOp, PtrUnion.pb,
     3013                                               pThis->aOperands[iOperand].cbOp, pThis->MemOp.ab);
     3014                                break;
     3015                        }
    29953016                    }
     3017                    else
     3018                        Bs3TestFailedF("op%u: off is zero\n", iOperand);
    29963019                    fOkay = false;
    29973020                }
     
    30563079         * Report failure.
    30573080         */
    3058         Bs3TestFailedF("%RU32[%u]: encoding#%u: %.*Rhxs",
    3059                        pThis->iInstr, pThis->iTest, iEncoding, pThis->cbCurInstr, pThis->abCurInstr);
     3081        Bs3TestFailedF("ins#%RU32/test#%u: encoding #%u: %.*Rhxs%s",
     3082                       pThis->iInstr, pThis->iTest, iEncoding, pThis->cbCurInstr, pThis->abCurInstr,
     3083                       fInvalidEncodingPgFault ? " (cut short)" : "");
    30603084    }
    30613085    else
    3062         Bs3TestFailedF("%RU32[%u]: bXcpt=%#x expected %#x; rip=%RX64 expected %RX64; encoding#%u: %.*Rhxs",
     3086        Bs3TestFailedF("ins#%RU32/test#%u: bXcpt=%#x expected %#x; rip=%RX64 expected %RX64; encoding#%u: %.*Rhxs%s",
    30633087                       pThis->iInstr, pThis->iTest,
    30643088                       pThis->TrapFrame.bXcpt, bExpectedXcpt,
    30653089                       pThis->TrapFrame.Ctx.rip.u, pThis->Ctx.rip.u + cbAdjustPc,
    3066                        iEncoding, pThis->cbCurInstr, pThis->abCurInstr);
     3090                       iEncoding, pThis->cbCurInstr, pThis->abCurInstr, fInvalidEncodingPgFault ? " (cut short)" : "");
    30673091    Bs3TestPrintf("cpl=%u cbOperands=%u\n", pThis->uCpl, pThis->cbOperand);
    30683092
     
    31173141            case BS3CG1OPLOC_MEM:
    31183142            case BS3CG1OPLOC_MEM_RW:
    3119                 PtrUnion.pb = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[iOperand].off];
    3120                 switch (pThis->aOperands[iOperand].cbOp)
     3143                if (pThis->aOperands[iOperand].off)
    31213144                {
    3122                     case 1: Bs3TestPrintf("op%u: result mem08: %#04RX8\n", iOperand, *PtrUnion.pu8); break;
    3123                     case 2: Bs3TestPrintf("op%u: result mem16: %#06RX16\n", iOperand, *PtrUnion.pu16); break;
    3124                     case 4: Bs3TestPrintf("op%u: result mem32: %#010RX32\n", iOperand, *PtrUnion.pu32); break;
    3125                     case 8: Bs3TestPrintf("op%u: result mem64: %#018RX64\n", iOperand, *PtrUnion.pu64); break;
    3126                     default:
    3127                         Bs3TestPrintf("op%u: result mem%u: %.*Rhxs\n", iOperand, pThis->aOperands[iOperand].cbOp * 8,
    3128                                       pThis->aOperands[iOperand].cbOp, PtrUnion.pb);
    3129                         break;
    3130                 }
    3131                 if (pThis->aOperands[iOperand].enmLocation == BS3CG1OPLOC_MEM_RW)
    3132                 {
    3133                     PtrUnion.pb = pThis->MemOp.ab;
     3145                    PtrUnion.pb = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[iOperand].off];
    31343146                    switch (pThis->aOperands[iOperand].cbOp)
    31353147                    {
    3136                         case 1: Bs3TestPrintf("op%u: expect mem08: %#04RX8\n", iOperand, *PtrUnion.pu8); break;
    3137                         case 2: Bs3TestPrintf("op%u: expect mem16: %#06RX16\n", iOperand, *PtrUnion.pu16); break;
    3138                         case 4: Bs3TestPrintf("op%u: expect mem32: %#010RX32\n", iOperand, *PtrUnion.pu32); break;
    3139                         case 8: Bs3TestPrintf("op%u: expect mem64: %#018RX64\n", iOperand, *PtrUnion.pu64); break;
     3148                        case 1: Bs3TestPrintf("op%u: result mem08: %#04RX8\n", iOperand, *PtrUnion.pu8); break;
     3149                        case 2: Bs3TestPrintf("op%u: result mem16: %#06RX16\n", iOperand, *PtrUnion.pu16); break;
     3150                        case 4: Bs3TestPrintf("op%u: result mem32: %#010RX32\n", iOperand, *PtrUnion.pu32); break;
     3151                        case 8: Bs3TestPrintf("op%u: result mem64: %#018RX64\n", iOperand, *PtrUnion.pu64); break;
    31403152                        default:
    3141                             Bs3TestPrintf("op%u: expect mem%u: %.*Rhxs\n", iOperand, pThis->aOperands[iOperand].cbOp * 8,
     3153                            Bs3TestPrintf("op%u: result mem%u: %.*Rhxs\n", iOperand, pThis->aOperands[iOperand].cbOp * 8,
    31423154                                          pThis->aOperands[iOperand].cbOp, PtrUnion.pb);
    31433155                            break;
    31443156                    }
     3157                    if (pThis->aOperands[iOperand].enmLocation == BS3CG1OPLOC_MEM_RW)
     3158                    {
     3159                        PtrUnion.pb = pThis->MemOp.ab;
     3160                        switch (pThis->aOperands[iOperand].cbOp)
     3161                        {
     3162                            case 1: Bs3TestPrintf("op%u: expect mem08: %#04RX8\n", iOperand, *PtrUnion.pu8); break;
     3163                            case 2: Bs3TestPrintf("op%u: expect mem16: %#06RX16\n", iOperand, *PtrUnion.pu16); break;
     3164                            case 4: Bs3TestPrintf("op%u: expect mem32: %#010RX32\n", iOperand, *PtrUnion.pu32); break;
     3165                            case 8: Bs3TestPrintf("op%u: expect mem64: %#018RX64\n", iOperand, *PtrUnion.pu64); break;
     3166                            default:
     3167                                Bs3TestPrintf("op%u: expect mem%u: %.*Rhxs\n", iOperand, pThis->aOperands[iOperand].cbOp * 8,
     3168                                              pThis->aOperands[iOperand].cbOp, PtrUnion.pb);
     3169                                break;
     3170                        }
     3171                    }
    31453172                }
     3173                else
     3174                    Bs3TestPrintf("op%u: mem%u: zero off value!!\n", iOperand, pThis->aOperands[iOperand].cbOp * 8);
    31463175                break;
    31473176        }
     
    31533182    Bs3TestPrintf("-- Expected context:\n");
    31543183    Bs3RegCtxPrint(&pThis->Ctx);
     3184    if (pThis->fWorkExtCtx)
     3185        Bs3TestPrintf("xcr0=%RX64\n", pThis->pExtCtx->fXcr0Saved);
    31553186    Bs3TestPrintf("-- Actual context:\n");
    31563187    Bs3TrapPrintFrame(&pThis->TrapFrame);
     3188    if (pThis->fWorkExtCtx)
     3189        Bs3TestPrintf("xcr0=%RX64\n", pThis->pResultExtCtx->fXcr0Saved);
    31573190    Bs3TestPrintf("\n");
    31583191    return false;
     
    32153248    pThis->pszMode            = Bs3GetModeName(bMode);
    32163249    pThis->pszModeShort       = Bs3GetModeNameShortLower(bMode);
     3250    pThis->bCpuVendor         = Bs3GetCpuVendor();
    32173251    pThis->pchMnemonic        = g_achBs3Cg1Mnemonics;
    32183252    pThis->pabOperands        = g_abBs3Cg1Operands;
     
    35663600                                pThis->Ctx.rflags.u32 &= ~X86_EFL_RF;
    35673601                                pThis->Ctx.rflags.u32 |= pThis->TrapFrame.Ctx.rflags.u32 & X86_EFL_RF;
    3568                                 pThis->bValueXcpt      = UINT8_MAX;
     3602                                pThis->bValueXcpt      = UINT8_MAX; //???
    35693603                                if (   pThis->fInvalidEncoding
    35703604                                    || pThis->bAlignmentXcpt != UINT8_MAX
     
    35743608                                                                &pThis->TrapFrame.Ctx, NULL /*pbCode*/))
    35753609                                {
    3576                                     Bs3Cg1CheckResult(pThis, bTestXcptExpected, iEncoding);
     3610                                    Bs3Cg1CheckResult(pThis, bTestXcptExpected, false /*fInvalidEncodingPgFault*/, iEncoding);
     3611                                }
     3612
     3613                                /*
     3614                                 * If this is an invalid encoding or instruction, check that we
     3615                                 * get a page fault when shortening it by one byte.
     3616                                 * (Since we didn't execute the output context modifier, we don't
     3617                                 * need to re-initialize the start context.)
     3618                                 */
     3619                                if (   pThis->fInvalidEncoding
     3620                                    && BS3_MODE_IS_PAGED(pThis->bMode)
     3621                                    && pThis->cbCurInstr)
     3622                                {
     3623                                    pbCode  += 1;
     3624                                    offCode += 1;
     3625                                    pThis->Ctx.rip.u = pThis->CodePgRip + offCode;
     3626                                    Bs3MemCpy(pbCode, pThis->abCurInstr, pThis->cbCurInstr - 1);
     3627
     3628                                    /* Run the instruction. */
     3629                                    BS3CG1_DPRINTF(("dbg:  Running test #%u (cut short #PF)\n", pThis->iTest));
     3630                                    //Bs3RegCtxPrint(&pThis->Ctx);
     3631                                    if (pThis->fWorkExtCtx)
     3632                                        Bs3ExtCtxRestore(pThis->pExtCtx);
     3633                                    Bs3TrapSetJmpAndRestore(&pThis->Ctx, &pThis->TrapFrame);
     3634                                    if (pThis->fWorkExtCtx)
     3635                                        Bs3ExtCtxSave(pThis->pResultExtCtx);
     3636                                    BS3CG1_DPRINTF(("dbg:  bXcpt=%#x rip=%RX64 -> %RX64 (cut short #PF)\n",
     3637                                                    pThis->TrapFrame.bXcpt, pThis->Ctx.rip.u, pThis->TrapFrame.Ctx.rip.u));
     3638
     3639                                    /* Check it */
     3640                                    pThis->Ctx.rflags.u32 &= ~X86_EFL_RF;
     3641                                    pThis->Ctx.rflags.u32 |= pThis->TrapFrame.Ctx.rflags.u32 & X86_EFL_RF;
     3642                                    Bs3Cg1CheckResult(pThis, X86_XCPT_PF, true /*fInvalidEncodingPgFault*/, iEncoding);
    35773643                                }
    35783644                            }
     
    36143680#if 0
    36153681    /* (for debugging) */
    3616     if (bMode >= BS3_MODE_PE16)
     3682    if (bMode != BS3_MODE_PPV86)
    36173683        return BS3TESTDOMODE_SKIPPED;
    36183684#endif
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-generated-1.h

    r66450 r66457  
    575575typedef enum BS3CG1PRED
    576576{
    577      BS3CG1PRED_INVALID = 0,
    578 
    579      /* Operand size. */
    580      BS3CG1PRED_SIZE_O16,
    581      BS3CG1PRED_SIZE_O32,
    582      BS3CG1PRED_SIZE_O64,
    583      /* Execution ring. */
    584      BS3CG1PRED_RING_0,
    585      BS3CG1PRED_RING_1,
    586      BS3CG1PRED_RING_2,
    587      BS3CG1PRED_RING_3,
    588      BS3CG1PRED_RING_0_THRU_2,
    589      BS3CG1PRED_RING_1_THRU_3,
    590      /* Basic code mode. */
    591      BS3CG1PRED_CODE_64BIT,
    592      BS3CG1PRED_CODE_32BIT,
    593      BS3CG1PRED_CODE_16BIT,
    594      /* CPU modes. */
    595      BS3CG1PRED_MODE_REAL,
    596      BS3CG1PRED_MODE_PROT,
    597      BS3CG1PRED_MODE_LONG,
    598      BS3CG1PRED_MODE_V86,
    599      BS3CG1PRED_MODE_SMM,
    600      BS3CG1PRED_MODE_VMX,
    601      BS3CG1PRED_MODE_SVM,
    602      /* Paging on/off */
    603      BS3CG1PRED_PAGING_ON,
    604      BS3CG1PRED_PAGING_OFF,
    605 
    606      BS3CG1PRED_END
     577    BS3CG1PRED_INVALID = 0,
     578
     579    /* Operand size. */
     580    BS3CG1PRED_SIZE_O16,
     581    BS3CG1PRED_SIZE_O32,
     582    BS3CG1PRED_SIZE_O64,
     583    /* Execution ring. */
     584    BS3CG1PRED_RING_0,
     585    BS3CG1PRED_RING_1,
     586    BS3CG1PRED_RING_2,
     587    BS3CG1PRED_RING_3,
     588    BS3CG1PRED_RING_0_THRU_2,
     589    BS3CG1PRED_RING_1_THRU_3,
     590    /* Basic code mode. */
     591    BS3CG1PRED_CODE_64BIT,
     592    BS3CG1PRED_CODE_32BIT,
     593    BS3CG1PRED_CODE_16BIT,
     594    /* CPU modes. */
     595    BS3CG1PRED_MODE_REAL,
     596    BS3CG1PRED_MODE_PROT,
     597    BS3CG1PRED_MODE_LONG,
     598    BS3CG1PRED_MODE_V86,
     599    BS3CG1PRED_MODE_SMM,
     600    BS3CG1PRED_MODE_VMX,
     601    BS3CG1PRED_MODE_SVM,
     602    /* Paging on/off */
     603    BS3CG1PRED_PAGING_ON,
     604    BS3CG1PRED_PAGING_OFF,
     605    /* CPU Vendors. */
     606    BS3CG1PRED_VENDOR_AMD,
     607    BS3CG1PRED_VENDOR_INTEL,
     608    BS3CG1PRED_VENDOR_VIA,
     609
     610    BS3CG1PRED_END
    607611} BS3CG1PRED;
    608612
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