VirtualBox

Ignore:
Timestamp:
Nov 25, 2016 9:20:25 AM (8 years ago)
Author:
vboxsync
Message:

bs3-cpu-basic-2: updates

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-asm.asm

    r60774 r64752  
    102102
    103103;
     104; CPU mode agnostic test code snippets.
     105;
     106BS3_BEGIN_TEXT32
     107
     108;;
     109; @param    [xBP + xCB*2]   puDst
     110; @param    [xBP + xCB*3]   uNewValue
     111BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_mov, BS3_PBC_NEAR
     112        push    xBP
     113        mov     xBP, xSP
     114        mov     xCX, [xBP + xCB*2]
     115        mov     xAX, [xBP + xCB*3]
     116        mov     [xCX], xAX
     117        leave
     118        ret
     119BS3_PROC_END_CMN   bs3CpuBasic2_Store_mov
     120
     121;;
     122; @param    [xBP + xCB*2]   puDst
     123; @param    [xBP + xCB*3]   uNewValue
     124BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_xchg, BS3_PBC_NEAR
     125        push    xBP
     126        mov     xBP, xSP
     127        mov     xCX, [xBP + xCB*2]
     128        mov     xAX, [xBP + xCB*3]
     129        xchg    [xCX], xAX
     130        leave
     131        ret
     132BS3_PROC_END_CMN   bs3CpuBasic2_Store_xchg
     133
     134;;
     135; @param    [xBP + xCB*2]   puDst
     136; @param    [xBP + xCB*3]   uNewValue
     137; @param    [xBP + xCB*4]   uOldValue
     138BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_cmpxchg, BS3_PBC_NEAR
     139        push    xBP
     140        mov     xBP, xSP
     141        mov     xCX, [xBP + xCB*2]
     142        mov     xDX, [xBP + xCB*3]
     143        mov     xAX, [xBP + xCB*4]
     144.again:
     145        cmpxchg [xCX], xDX
     146        jnz     .again
     147        leave
     148        ret
     149BS3_PROC_END_CMN   bs3CpuBasic2_Store_cmpxchg
     150
     151
     152BS3_BEGIN_TEXT16
     153
     154;
    104155; Instantiate code templates.
    105156;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-pf.c32

    r64735 r64752  
    3333
    3434/*********************************************************************************************************************************
     35*   Structures and Typedefs                                                                                                      *
     36*********************************************************************************************************************************/
     37typedef void BS3_CALL FNBS3CPUBASIC2PFSNIPPET(void);
     38
     39typedef struct FNBS3CPUBASIC2PFTSTCODE
     40{
     41    FNBS3CPUBASIC2PFSNIPPET    *pfn;
     42    uint8_t                     offUd2;
     43    uint8_t                     cbTmpl;
     44} FNBS3CPUBASIC2PFTSTCODE;
     45
     46typedef struct BS3CPUBASIC2PFTTSTCMNMODE
     47{
     48    uint8_t                 bMode;
     49    FNBS3CPUBASIC2PFTSTCODE ExecTmpl;
     50    FNBS3CPUBASIC2PFTSTCODE MovLoad;
     51    FNBS3CPUBASIC2PFTSTCODE MovStore;
     52    FNBS3CPUBASIC2PFTSTCODE Xchg;
     53    FNBS3CPUBASIC2PFTSTCODE CmpXchg;
     54} BS3CPUBASIC2PFTTSTCMNMODE;
     55typedef BS3CPUBASIC2PFTTSTCMNMODE const *PCBS3CPUBASIC2PFTTSTCMNMODE;
     56
     57
     58typedef struct BS3CPUBASIC2PFSTATE
     59{
     60    /** The mode we're currently testing. */
     61    uint8_t                     bMode;
     62    /** The common mode functions. */
     63    PCBS3CPUBASIC2PFTTSTCMNMODE pCmnMode;
     64    /** Pointer to the test area (alias). */
     65    uint8_t                    *pbTest;
     66    /** Pointer to the orignal test area mapping. */
     67    uint8_t                    *pbOrgTest;
     68    /** The size of the test area (at least two pages). */
     69    uint32_t                    cbTest;
     70    /** 16-bit data selector for pbTest. */
     71    uint16_t                    uSel16TestData;
     72    /** 16-bit code selector for pbTest. */
     73    uint16_t                    uSel16TestCode;
     74    /** Test paging information for pbTest. */
     75    BS3PAGINGINFO4ADDR          PgInfo;
     76
     77    /** Set if we can use the INVLPG instruction. */
     78    bool                        fUseInvlPg;
     79
     80    /** Trap context frame. */
     81    BS3TRAPFRAME                TrapCtx;
     82
     83} BS3CPUBASIC2PFSTATE;
     84/** Pointer to state for the \#PF test. */
     85typedef BS3CPUBASIC2PFSTATE *PBS3CPUBASIC2PFSTATE;
     86
     87
     88/*********************************************************************************************************************************
    3589*   Internal Functions                                                                                                           *
    3690*********************************************************************************************************************************/
    3791FNBS3TESTDOMODE bs3CpuBasic2_RaiseXcpt0e_c32;
    3892
     93/* bs3-cpu-basic-2-asm.asm: */
     94void BS3_CALL bs3CpuBasic2_Store_mov_c32(void *pvDst, uint32_t uValue, uint32_t uOld);
     95void BS3_CALL bs3CpuBasic2_Store_xchg_c32(void *pvDst, uint32_t uValue, uint32_t uOld);
     96void BS3_CALL bs3CpuBasic2_Store_cmpxchg_c32(void *pvDst, uint32_t uValue, uint32_t uOld);
     97
     98
     99/* bs3-cpu-basic-2-template.mac: */
     100FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_RaisePF_ExecTmpl_c16;
     101FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_mov_ax_ds_bx__ud2_c16;
     102FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_mov_ds_bx_ax__ud2_c16;
     103FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_xchg_ds_bx_ax__ud2_c16;
     104FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2_c16;
     105
     106FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_RaisePF_ExecTmpl_c32;
     107FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_mov_ax_ds_bx__ud2_c32;
     108FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_mov_ds_bx_ax__ud2_c32;
     109FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_xchg_ds_bx_ax__ud2_c32;
     110FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2_c32;
     111
     112FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_RaisePF_ExecTmpl_c64;
     113FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_mov_ax_ds_bx__ud2_c64;
     114FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_mov_ds_bx_ax__ud2_c64;
     115FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_xchg_ds_bx_ax__ud2_c64;
     116FNBS3CPUBASIC2PFSNIPPET bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2_c64;
     117
     118
     119/*********************************************************************************************************************************
     120*   Global Variables                                                                                                             *
     121*********************************************************************************************************************************/
     122/** Page table access functions. */
     123static const struct
     124{
     125    const char     *pszStore;
     126    void (BS3_CALL *pfnStore)(void *pvDst, uint32_t uValue, uint32_t uOld);
     127} g_aStoreMethods[] =
     128{
     129    { "mov",        bs3CpuBasic2_Store_mov_c32 },
     130    { "xchg",       bs3CpuBasic2_Store_xchg_c32 },
     131    { "cmpxchg",    bs3CpuBasic2_Store_cmpxchg_c32 },
     132};
     133
     134
     135static const BS3CPUBASIC2PFTTSTCMNMODE g_aCmnModes[] =
     136{
     137    {
     138        BS3_MODE_CODE_16,
     139        {   bs3CpuBasic2_RaisePF_ExecTmpl_c16,      0, 3 },
     140        {   bs3CpuBasic2_mov_ax_ds_bx__ud2_c16,     2 },
     141        {   bs3CpuBasic2_mov_ds_bx_ax__ud2_c16,     2 },
     142        {   bs3CpuBasic2_xchg_ds_bx_ax__ud2_c16,    2 },
     143        {   bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2_c16, 3 },
     144    },
     145    {
     146        BS3_MODE_CODE_32,
     147        {   bs3CpuBasic2_RaisePF_ExecTmpl_c32,      0, 3  },
     148        {   bs3CpuBasic2_mov_ax_ds_bx__ud2_c32,     2 },
     149        {   bs3CpuBasic2_mov_ds_bx_ax__ud2_c32,     2 },
     150        {   bs3CpuBasic2_xchg_ds_bx_ax__ud2_c32,    2 },
     151        {   bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2_c32, 3 },
     152    },
     153    {
     154        BS3_MODE_CODE_64,
     155        {   bs3CpuBasic2_RaisePF_ExecTmpl_c64,      0, 3  },
     156        {   bs3CpuBasic2_mov_ax_ds_bx__ud2_c64,     2 + 1 },
     157        {   bs3CpuBasic2_mov_ds_bx_ax__ud2_c64,     2 + 1 },
     158        {   bs3CpuBasic2_xchg_ds_bx_ax__ud2_c64,    2 + 1 },
     159        {   bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2_c64, 3 + 1 },
     160    },
     161    {
     162        BS3_MODE_CODE_V86,
     163        {   bs3CpuBasic2_RaisePF_ExecTmpl_c16,      0, 3  },
     164        {   bs3CpuBasic2_mov_ax_ds_bx__ud2_c16,     2 },
     165        {   bs3CpuBasic2_mov_ds_bx_ax__ud2_c16,     2 },
     166        {   bs3CpuBasic2_xchg_ds_bx_ax__ud2_c16,    2 },
     167        {   bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2_c16, 3 },
     168    },
     169};
     170
     171
     172static void bs3CpuBasic2Pf_DoExecSubTest(PBS3CPUBASIC2PFSTATE pThis, PBS3REGCTX pCtx, uint8_t uXcpt, uint8_t uPfErrCd,
     173                                         unsigned iRing)
     174{
     175    uint8_t *pbOrgTest = pThis->pbOrgTest;
     176    unsigned off;
     177    for (off = X86_PAGE_SIZE - 2; off < X86_PAGE_SIZE + 2; off++)
     178    {
     179        pbOrgTest[off + 0] = X86_OP_PRF_SIZE_ADDR;
     180        pbOrgTest[off + 1] = X86_OP_PRF_SIZE_OP;
     181        pbOrgTest[off + 2] = 0x90; /* NOP */
     182        pbOrgTest[off + 3] = 0x0f; /* UD2 */
     183        pbOrgTest[off + 4] = 0x0b;
     184        pbOrgTest[off + 5] = 0xeb; /* JMP $-4 */
     185        pbOrgTest[off + 6] = 0xfc;
     186        switch (pThis->bMode & BS3_MODE_CODE_MASK)
     187        {
     188            default:
     189                pCtx->rip.u = (uintptr_t)&pThis->pbTest[off];
     190                break;
     191            case BS3_MODE_CODE_16:
     192                Bs3SelSetup16BitCode(&Bs3GdteSpare01, (uintptr_t)pThis->pbTest, iRing);
     193                pCtx->rip.u = off;
     194                pCtx->cs    = BS3_SEL_SPARE_01;
     195                break;
     196            case BS3_MODE_CODE_V86:
     197                /** @todo fix me.   */
     198                return;
     199        }
     200
     201        Bs3TrapSetJmpAndRestore(pCtx, &pThis->TrapCtx);
     202        //bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     203
     204    }
     205}
     206
    39207
    40208/**
     
    44212 *
    45213 * @returns Error count.
    46  * @param   bMode               The mode to test.
    47  * @param   pbTestOrg           Pointer to the actual memory allocation (low
    48  *                              memory) where it is identity mapped (virtual
    49  *                              address == physical address).  This function
    50  *                              will not touch paging structures here.
    51  * @param   pbTest              Pointer to the aliased allocation in high
    52  *                              memory.  This is aligned on a gigabyte boundrary
    53  *                              so that 1GB pages can be tested (later).
    54  * @param   cbTest              The size of the memory allocated for testing.
    55  * @param   pPgInfo             The paging info for @a pbTest.
     214 * @param   pThis       Test state data.
    56215 */
    57 static uint8_t bs3CpuBasic2_RaiseXcpt0eWorker(uint8_t bMode, uint8_t *pbTestOrg, uint8_t *pbTest, uint32_t cbTest,
    58                                               PBS3PAGINGINFO4ADDR pPgInfo)
    59 {
     216static uint8_t bs3CpuBasic2_RaiseXcpt0eWorker(PBS3CPUBASIC2PFSTATE register pThis)
     217{
     218    unsigned            iRing;
     219    BS3REGCTX           aCtxts[4];
     220
     221    /* paranoia: Touch the various big stack structures to ensure the compiler has allocated stack for them. */
     222    for (iRing = 0; iRing < RT_ELEMENTS(aCtxts); iRing++)
     223        Bs3MemZero(&aCtxts[iRing], sizeof(aCtxts[iRing]));
     224
     225    /*
     226     * Set up a few contexts for testing this stuff.
     227     */
     228    Bs3RegCtxSaveEx(&aCtxts[0], pThis->bMode, 2048);
     229    for (iRing = 1; iRing < 4; iRing++)
     230    {
     231        aCtxts[iRing] = aCtxts[0];
     232        Bs3RegCtxConvertToRingX(&aCtxts[iRing], iRing);
     233    }
     234
     235    if (!BS3_MODE_IS_16BIT_CODE(pThis->bMode))
     236    {
     237        for (iRing = 0; iRing < 4; iRing++)
     238            aCtxts[iRing].rbx.u = (uintptr_t)pThis->pbTest;
     239    }
     240    else
     241    {
     242        for (iRing = 0; iRing < 4; iRing++)
     243        {
     244            aCtxts[iRing].ds    = pThis->uSel16TestData;
     245            aCtxts[iRing].rbx.u = 0;
     246        }
     247    }
     248
     249
     250    /*
     251     * Check basic operation.
     252     */
     253    for (iRing = 0; iRing < 4; iRing++)
     254    {
     255        /* we can execute the test page. */
     256        bs3CpuBasic2Pf_DoExecSubTest(pThis, &aCtxts[iRing], X86_XCPT_UD, UINT8_MAX, iRing);
     257    }
     258
     259
    60260
    61261
     
    66266BS3_DECL_CALLBACK(uint8_t)  bs3CpuBasic2_RaiseXcpt0e_c32(uint8_t bMode)
    67267{
    68     void       *pvTestUnaligned;
    69     uint32_t    cbTestUnaligned = _8M;
    70     uint32_t    cbTest;
    71     uint8_t    *pbTest;
    72     uint8_t    *pbAlias;
    73     uint8_t     bRet = 1;
    74     int         rc;
     268    void               *pvTestUnaligned;
     269    uint32_t            cbTestUnaligned = _8M;
     270    uint8_t             bRet = 1;
     271    int                 rc;
     272    BS3CPUBASIC2PFSTATE State;
     273
     274    /*
     275     * Initalize the state data.
     276     */
     277    Bs3MemZero(&State, sizeof(State));
     278    State.bMode = bMode;
     279    State.pCmnMode = &g_aCmnModes[0];
     280    while (State.pCmnMode->bMode != (bMode & BS3_MODE_CODE_MASK))
     281        State.pCmnMode++;
     282    State.fUseInvlPg = (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80486;
    75283
    76284    /*
     
    91299    if ((uintptr_t)pvTestUnaligned & (cbTestUnaligned - 1))
    92300    {
    93         cbTest = cbTestUnaligned >> 1;
    94         pbTest = (uint8_t *)(((uintptr_t)pvTestUnaligned + cbTest - 1) & ~(cbTest - 1));
     301        State.cbTest    = cbTestUnaligned >> 1;
     302        State.pbOrgTest = (uint8_t *)(((uintptr_t)pvTestUnaligned + State.cbTest - 1) & ~(State.cbTest - 1));
    95303    }
    96304    else
    97305    {
    98         pbTest = pvTestUnaligned;
    99         cbTest = cbTestUnaligned;
     306        State.pbOrgTest = pvTestUnaligned;
     307        State.cbTest    = cbTestUnaligned;
    100308    }
    101309
     
    103311     * Alias this memory far away from where our code and data lives.
    104312     */
    105     pbAlias = (uint8_t *)UINT32_C(0x80000000);
    106     rc = Bs3PagingAlias((uintptr_t)pbAlias, (uintptr_t)pbTest, cbTest, X86_PTE_P | X86_PTE_RW | X86_PTE_US);
     313    State.pbTest = (uint8_t *)UINT32_C(0x80000000);
     314    rc = Bs3PagingAlias((uintptr_t)State.pbTest, (uintptr_t)State.pbOrgTest, State.cbTest, X86_PTE_P | X86_PTE_RW | X86_PTE_US);
    107315    if (RT_SUCCESS(rc))
    108316    {
    109         BS3PAGINGINFO4ADDR PgInfo;
    110         rc = Bs3PagingQueryAddressInfo((uintptr_t)pbTest, &PgInfo);
     317        rc = Bs3PagingQueryAddressInfo((uintptr_t)State.pbTest, &State.PgInfo);
    111318        if (RT_SUCCESS(rc))
    112319        {
     
    114321             * Setup a 16-bit selector for accessing the alias.
    115322             */
    116             // ==> office //
    117 
    118             Bs3TestPrintf("RaiseXcpt0e_c32:  bMode=%#x/%#x cbTest=%#x pbTest=%p pbAlias=%p\n",
    119                           bMode, g_bBs3CurrentMode, cbTest, pbTest, pbAlias);
    120             bRet = bs3CpuBasic2_RaiseXcpt0eWorker(bMode, pbTest, pbAlias, cbTest, &PgInfo);
    121 
     323            Bs3SelSetup16BitData(&Bs3GdteSpare00, (uintptr_t)State.pbTest);
     324            State.uSel16TestData = BS3_SEL_SPARE_00 | 3;
     325
     326            //Bs3TestPrintf("RaiseXcpt0e_c32:  bMode=%#x/%#x cbTest=%#x pbTest=%p pbAlias=%p\n",
     327            //              bMode, g_bBs3CurrentMode, cbTest, pbTest, pbAlias);
     328
     329            bRet = bs3CpuBasic2_RaiseXcpt0eWorker(&State);
    122330        }
    123331        else
    124332            Bs3TestFailedF("Bs3PagingQueryAddressInfo failed: %d\n", rc);
    125         Bs3PagingUnalias((uintptr_t)pbAlias, cbTest);
     333        Bs3PagingUnalias((uintptr_t)State.pbTest, State.cbTest);
    126334    }
    127335    else
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac

    r60728 r64752  
    317317 %endif
    318318
     319;
     320; #PF
     321;
     322
     323; For testing exec access.
     324BS3_PROC_BEGIN_CMN bs3CpuBasic2_RaisePF_ExecTmpl, BS3_PBC_NEAR
     325.again: ud2
     326        jmp     .again
     327BS3_PROC_END_CMN   bs3CpuBasic2_RaisePF_ExecTmpl
     328
     329
     330; For testing read access.
     331BS3_PROC_BEGIN_CMN bs3CpuBasic2_mov_ax_ds_bx__ud2, BS3_PBC_NEAR
     332        mov     xAX, [xBX]
     333.again: ud2
     334        jmp     .again
     335AssertCompile(.again - BS3_LAST_LABEL == 2 + (TMPL_BITS == 64))
     336BS3_PROC_END_CMN   bs3CpuBasic2_mov_ax_ds_bx__ud2
     337
     338
     339; For testing write access.
     340BS3_PROC_BEGIN_CMN bs3CpuBasic2_mov_ds_bx_ax__ud2, BS3_PBC_NEAR
     341        mov     [xBX], xAX
     342.again: ud2
     343        jmp     .again
     344AssertCompile(.again - BS3_LAST_LABEL == 2 + (TMPL_BITS == 64))
     345BS3_PROC_END_CMN   bs3CpuBasic2_mov_ds_bx_ax__ud2
     346
     347
     348; For testing read+write access.
     349BS3_PROC_BEGIN_CMN bs3CpuBasic2_xchg_ds_bx_ax__ud2, BS3_PBC_NEAR
     350        xchg    [xBX], xAX
     351.again: ud2
     352        jmp     .again
     353AssertCompile(.again - BS3_LAST_LABEL == 2 + (TMPL_BITS == 64))
     354BS3_PROC_END_CMN   bs3CpuBasic2_xchg_ds_bx_ax__ud2
     355
     356
     357; Another read+write access test.
     358BS3_PROC_BEGIN_CMN bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2, BS3_PBC_NEAR
     359        cmpxchg  [xBX], xCX
     360.again: ud2
     361        jmp     .again
     362AssertCompile(.again - BS3_LAST_LABEL == 3 + (TMPL_BITS == 64))
     363BS3_PROC_END_CMN   bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2
     364
    319365
    320366%endif ; BS3_INSTANTIATING_CMN
Note: See TracChangeset for help on using the changeset viewer.

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