VirtualBox

Changeset 97695 in vbox


Ignore:
Timestamp:
Nov 29, 2022 12:58:11 AM (2 years ago)
Author:
vboxsync
Message:

ValKit/bs3-cpu-basic-2: Simple instruction length test. bugref:9898

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

Legend:

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

    r97692 r97695  
    62316231}
    62326232
     6233
     6234
     6235/*********************************************************************************************************************************
     6236*   Instruction Length                                                                                                           *
     6237*********************************************************************************************************************************/
     6238
     6239
     6240static uint8_t bs3CpuBasic2_instr_len_Worker(uint8_t bMode, uint8_t BS3_FAR *pbCodeBuf)
     6241{
     6242    BS3TRAPFRAME    TrapCtx;
     6243    BS3REGCTX       Ctx;
     6244    BS3REGCTX       CtxExpected;
     6245    uint32_t        uEipBase;
     6246    unsigned        cbInstr;
     6247    unsigned        off;
     6248
     6249    /* Make sure they're allocated and all zeroed. */
     6250    Bs3MemZero(&Ctx, sizeof(Ctx));
     6251    Bs3MemZero(&CtxExpected, sizeof(Ctx));
     6252    Bs3MemZero(&TrapCtx, sizeof(TrapCtx));
     6253
     6254    /*
     6255     * Create a context.
     6256     *
     6257     * ASSUMES we're in on the ring-0 stack in ring-0 and using less than 16KB.
     6258     */
     6259    Bs3RegCtxSaveEx(&Ctx, bMode, 768);
     6260    Bs3RegCtxSetRipCsFromCurPtr(&Ctx, (FPFNBS3FAR)pbCodeBuf);
     6261    uEipBase = Ctx.rip.u32;
     6262
     6263    Bs3MemCpy(&CtxExpected, &Ctx, sizeof(CtxExpected));
     6264
     6265    /*
     6266     * Simple stuff crossing the page.
     6267     */
     6268    for (off = X86_PAGE_SIZE - 32; off <= X86_PAGE_SIZE + 16; off++)
     6269    {
     6270        Ctx.rip.u32 = uEipBase + off;
     6271        for (cbInstr = 0; cbInstr < 24; cbInstr++)
     6272        {
     6273            /*
     6274             * Generate the instructions:
     6275             *      [es] nop
     6276             *      ud2
     6277             */
     6278            if (cbInstr > 0)
     6279            {
     6280                Bs3MemSet(&pbCodeBuf[off], 0x26 /* es */, cbInstr);
     6281                pbCodeBuf[off + cbInstr - 1] = 0x90; /* nop */
     6282            }
     6283            pbCodeBuf[off + cbInstr + 0] = 0x0f; /* ud2 */
     6284            pbCodeBuf[off + cbInstr + 1] = 0x0b;
     6285
     6286            /*
     6287             * Test it.
     6288             */
     6289            if (cbInstr < 16)
     6290                CtxExpected.rip.u32 = Ctx.rip.u32 + cbInstr;
     6291            else
     6292                CtxExpected.rip.u32 = Ctx.rip.u32;
     6293            g_uBs3TrapEipHint = CtxExpected.rip.u32;
     6294            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     6295            if (cbInstr < 16)
     6296                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxExpected);
     6297            else
     6298                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &CtxExpected, 0);
     6299        }
     6300        pbCodeBuf[off] = 0xf1; /* icebp */
     6301    }
     6302
     6303    /*
     6304     * Pit instruction length violations against the segment limit (#GP).
     6305     */
     6306    if (!BS3_MODE_IS_RM_OR_V86(bMode) && bMode != BS3_MODE_LM64)
     6307    {
     6308        /** @todo */
     6309    }
     6310
     6311    /*
     6312     * Pit instruction length violations against an invalid page (#PF).
     6313     */
     6314    if (BS3_MODE_IS_PAGED(bMode))
     6315    {
     6316        /** @todo */
     6317    }
     6318
     6319    return 0;
     6320}
     6321
     6322
     6323/**
     6324 * Entrypoint for FAR RET tests.
     6325 *
     6326 * @returns 0 or BS3TESTDOMODE_SKIPPED.
     6327 * @param   bMode       The CPU mode we're testing.
     6328 */
     6329BS3_DECL_FAR(uint8_t) BS3_CMN_FAR_NM(bs3CpuBasic2_instr_len)(uint8_t bMode)
     6330{
     6331    /*
     6332     * Allocate three pages so we can straddle an instruction across the
     6333     * boundrary for testing special IEM cases, with the last page being
     6334     * made in accessible and useful for pitting #PF against #GP.
     6335     */
     6336    uint8_t BS3_FAR * const pbCodeBuf = (uint8_t BS3_FAR *)Bs3MemAlloc(BS3MEMKIND_REAL, X86_PAGE_SIZE * 3);
     6337    //Bs3TestPrintf("pbCodeBuf=%p\n", pbCodeBuf);
     6338    if (pbCodeBuf)
     6339    {
     6340        Bs3MemSet(pbCodeBuf, 0xf1, X86_PAGE_SIZE * 3);
     6341        bs3CpuBasic2_SetGlobals(bMode);
     6342
     6343        if (!BS3_MODE_IS_PAGED(bMode))
     6344            bs3CpuBasic2_instr_len_Worker(bMode, pbCodeBuf);
     6345        else
     6346        {
     6347            uint32_t const uFlatLastPg = Bs3SelPtrToFlat(pbCodeBuf) + X86_PAGE_SIZE * 2;
     6348            int rc = Bs3PagingProtect(uFlatLastPg, X86_PAGE_SIZE, 0, X86_PTE_P);
     6349            if (RT_SUCCESS(rc))
     6350            {
     6351                bs3CpuBasic2_instr_len_Worker(bMode, pbCodeBuf);
     6352                Bs3PagingProtect(uFlatLastPg, X86_PAGE_SIZE, X86_PTE_P, 0);
     6353            }
     6354            else
     6355                Bs3TestFailed("Failed to allocate 3 code pages");
     6356        }
     6357
     6358        Bs3MemFree(pbCodeBuf, X86_PAGE_SIZE * 3);
     6359    }
     6360    else
     6361        Bs3TestFailed("Failed to allocate 3 code pages");
     6362    return 0;
     6363}
     6364
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2.c

    r97643 r97695  
    5959FNBS3TESTDOMODE             bs3CpuBasic2_near_ret_f16;
    6060FNBS3TESTDOMODE             bs3CpuBasic2_far_ret_f16;
     61FNBS3TESTDOMODE             bs3CpuBasic2_instr_len_f16;
    6162
    6263BS3_DECL_CALLBACK(void)     bs3CpuBasic2_Do32BitTests_pe32();
     
    9293    { "lgdt", bs3CpuBasic2_lgdt_f16, 0 },
    9394#endif
     95#if 1
     96    { "instr length", bs3CpuBasic2_instr_len_f16, 0 },
     97#endif
    9498};
    9599
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