VirtualBox

Changeset 41791 in vbox for trunk/src/VBox/Disassembler


Ignore:
Timestamp:
Jun 16, 2012 11:02:09 PM (12 years ago)
Author:
vboxsync
Message:

DIS,CSAM: Drop pvUser2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Disassembler/DisasmCore.cpp

    r41790 r41791  
    4848*******************************************************************************/
    4949static void     disasmModRMReg(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam, int fRegAddr);
    50 static void     disasmModRMReg16(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam);
    51 static void     disasmModRMSReg(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam);
    5250
    5351
     
    214212
    215213
    216 //*****************************************************************************
    217 /* Read functions for getting the opcode bytes */
    218 //*****************************************************************************
    219 
     214/********************************************************************************************************************************
     215 *
     216 *
     217 * Read functions for getting the opcode bytes
     218 *
     219 *
     220 ********************************************************************************************************************************/
    220221
    221222/**
     
    593594static size_t ParseEscFP(size_t offInstr, PCDISOPCODE pOp, PDISOPPARAM pParam, PDISSTATE pDis)
    594595{
    595     int index;
     596    size_t      size = 0;
    596597    PCDISOPCODE fpop;
    597     size_t size = 0;
    598     unsigned ModRM;
    599598    NOREF(pOp);
    600599
    601     ModRM = disReadByte(pDis, offInstr);
    602 
    603     index = pDis->bOpCode - 0xD8;
     600    unsigned    ModRM = disReadByte(pDis, offInstr);
     601    unsigned    index = pDis->bOpCode - 0xD8;
    604602    if (ModRM <= 0xBF)
    605603    {
    606604        fpop            = &(g_apMapX86_FP_Low[index])[MODRM_REG(ModRM)];
    607         pDis->pCurInstr = (PCDISOPCODE)fpop;
     605        pDis->pCurInstr = fpop;
    608606
    609607        // Should contain the parameter type on input
     
    614612    {
    615613        fpop            = &(g_apMapX86_FP_High[index])[ModRM - 0xC0];
    616         pDis->pCurInstr = (PCDISOPCODE)fpop;
     614        pDis->pCurInstr = fpop;
    617615    }
    618616
     
    644642
    645643    if (fpop->idxParse1 != IDX_ParseNop)
    646         size += pDis->pfnDisasmFnTable[fpop->idxParse1](offInstr+size, (PCDISOPCODE)fpop, pParam, pDis);
     644        size += pDis->pfnDisasmFnTable[fpop->idxParse1](offInstr+size, fpop, pParam, pDis);
    647645
    648646    if (fpop->idxParse2 != IDX_ParseNop)
    649         size += pDis->pfnDisasmFnTable[fpop->idxParse2](offInstr+size, (PCDISOPCODE)fpop, pParam, pDis);
     647        size += pDis->pfnDisasmFnTable[fpop->idxParse2](offInstr+size, fpop, pParam, pDis);
    650648
    651649    return size;
    652650}
    653 //*****************************************************************************
    654 // SIB byte: (not 16-bit mode)
    655 // 7 - 6  5 - 3  2-0
    656 // Scale  Index  Base
    657 //*****************************************************************************
     651
     652
     653/********************************************************************************************************************************
     654 *
     655 *
     656 * SIB byte: (not 16-bit mode)
     657 * 7 - 6  5 - 3  2-0
     658 * Scale  Index  Base
     659 *
     660 *
     661 ********************************************************************************************************************************/
    658662static void UseSIB(size_t offInstr, PCDISOPCODE pOp, PDISOPPARAM pParam, PDISSTATE pDis)
    659663{
     
    703707    return;   /* Already fetched everything in ParseSIB; no size returned */
    704708}
    705 //*****************************************************************************
    706 //*****************************************************************************
     709
     710
    707711static size_t ParseSIB(size_t offInstr, PCDISOPCODE pOp, PDISOPPARAM pParam, PDISSTATE pDis)
    708712{
    709713    unsigned size = sizeof(uint8_t);
    710     unsigned SIB;
    711714    NOREF(pOp); NOREF(pParam);
    712715
    713     SIB = disReadByte(pDis, offInstr);
     716    unsigned SIB = disReadByte(pDis, offInstr);
    714717    offInstr += size;
    715718
     
    722725        /* REX.B extends the Base field if not scaled index + disp32 */
    723726        if (!(pDis->SIB.Bits.Base == 5 && pDis->ModRM.Bits.Mod == 0))
    724             pDis->SIB.Bits.Base  |= ((!!(pDis->fRexPrefix & DISPREFIX_REX_FLAGS_B)) << 3);
    725 
    726         pDis->SIB.Bits.Index |= ((!!(pDis->fRexPrefix & DISPREFIX_REX_FLAGS_X)) << 3);
     727            pDis->SIB.Bits.Base  |= (!!(pDis->fRexPrefix & DISPREFIX_REX_FLAGS_B)) << 3;
     728
     729        pDis->SIB.Bits.Index |= (!!(pDis->fRexPrefix & DISPREFIX_REX_FLAGS_X)) << 3;
    727730    }
    728731
     
    736739    return size;
    737740}
    738 //*****************************************************************************
    739 //*****************************************************************************
     741
     742
    740743static size_t ParseSIB_SizeOnly(size_t offInstr, PCDISOPCODE pOp, PDISOPPARAM pParam, PDISSTATE pDis)
    741744{
    742745    unsigned size = sizeof(uint8_t);
    743     unsigned SIB;
    744746    NOREF(pOp); NOREF(pParam);
    745747
    746     SIB = disReadByte(pDis, offInstr);
     748    unsigned SIB = disReadByte(pDis, offInstr);
    747749
    748750    pDis->SIB.Bits.Base  = SIB_BASE(SIB);
     
    766768    return size;
    767769}
    768 //*****************************************************************************
    769 // ModR/M byte:
    770 // 7 - 6  5 - 3       2-0
    771 // Mod    Reg/Opcode  R/M
    772 //*****************************************************************************
     770
     771
     772
     773/********************************************************************************************************************************
     774 *
     775 *
     776 * ModR/M byte:
     777 * 7 - 6  5 - 3       2-0
     778 * Mod    Reg/Opcode  R/M
     779 *
     780 *
     781 ********************************************************************************************************************************/
     782static void disasmModRMReg(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam, int fRegAddr)
     783{
     784    NOREF(pOp); NOREF(pDis);
     785
     786    unsigned mod     = pDis->ModRM.Bits.Mod;
     787
     788    unsigned type    = OP_PARM_VTYPE(pParam->fParam);
     789    unsigned subtype = OP_PARM_VSUBTYPE(pParam->fParam);
     790    if (fRegAddr)
     791        subtype = (pDis->uAddrMode == DISCPUMODE_64BIT) ? OP_PARM_q : OP_PARM_d;
     792    else
     793    if (subtype == OP_PARM_v || subtype == OP_PARM_NONE)
     794    {
     795        switch (pDis->uOpMode)
     796        {
     797        case DISCPUMODE_32BIT:
     798            subtype = OP_PARM_d;
     799            break;
     800        case DISCPUMODE_64BIT:
     801            subtype = OP_PARM_q;
     802            break;
     803        case DISCPUMODE_16BIT:
     804            subtype = OP_PARM_w;
     805            break;
     806        default:
     807            /* make gcc happy */
     808            break;
     809        }
     810    }
     811
     812    switch (subtype)
     813    {
     814    case OP_PARM_b:
     815        Assert(idx < (pDis->fPrefix & DISPREFIX_REX ? 16U : 8U));
     816
     817        /* AH, BH, CH & DH map to DIL, SIL, EBL & SPL when a rex prefix is present. */
     818        /* Intel® 64 and IA-32 Architectures Software Developer’s Manual: 3.4.1.1 */
     819        if (    (pDis->fPrefix & DISPREFIX_REX)
     820            &&  idx >= DISGREG_AH
     821            &&  idx <= DISGREG_BH)
     822        {
     823            idx += (DISGREG_SPL - DISGREG_AH);
     824        }
     825
     826        pParam->fUse |= DISUSE_REG_GEN8;
     827        pParam->Base.idxGenReg = idx;
     828        break;
     829
     830    case OP_PARM_w:
     831        Assert(idx < (pDis->fPrefix & DISPREFIX_REX ? 16U : 8U));
     832
     833        pParam->fUse |= DISUSE_REG_GEN16;
     834        pParam->Base.idxGenReg = idx;
     835        break;
     836
     837    case OP_PARM_d:
     838        Assert(idx < (pDis->fPrefix & DISPREFIX_REX ? 16U : 8U));
     839
     840        pParam->fUse |= DISUSE_REG_GEN32;
     841        pParam->Base.idxGenReg = idx;
     842        break;
     843
     844    case OP_PARM_q:
     845        pParam->fUse |= DISUSE_REG_GEN64;
     846        pParam->Base.idxGenReg = idx;
     847        break;
     848
     849    default:
     850        Log(("disasmModRMReg %x:%x failed!!\n", type, subtype));
     851        pDis->rc = VERR_DIS_INVALID_MODRM;
     852        break;
     853    }
     854}
     855
     856static void disasmModRMReg16(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam)
     857{
     858    static const uint8_t s_auBaseModRMReg16[8]  =
     859    { DISGREG_BX, DISGREG_BX, DISGREG_BP, DISGREG_BP, DISGREG_SI, DISGREG_DI, DISGREG_BP, DISGREG_BX };
     860
     861    NOREF(pDis); NOREF(pOp);
     862    pParam->fUse |= DISUSE_REG_GEN16;
     863    pParam->Base.idxGenReg = s_auBaseModRMReg16[idx];
     864    if (idx < 4)
     865    {
     866        static const uint8_t s_auIndexModRMReg16[4] = { DISGREG_SI, DISGREG_DI, DISGREG_SI, DISGREG_DI };
     867        pParam->fUse |= DISUSE_INDEX;
     868        pParam->Index.idxGenReg = s_auIndexModRMReg16[idx];
     869    }
     870}
     871//*****************************************************************************
     872//*****************************************************************************
     873static void disasmModRMSReg(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam)
     874{
     875    NOREF(pOp);
     876    if (idx >= DISSELREG_END)
     877    {
     878        Log(("disasmModRMSReg %d failed!!\n", idx));
     879        pDis->rc = VERR_DIS_INVALID_PARAMETER;
     880        return;
     881    }
     882
     883    pParam->fUse |= DISUSE_REG_SEG;
     884    pParam->Base.idxSegReg = (DISSELREG)idx;
     885}
     886
     887
    773888static size_t UseModRM(size_t offInstr, PCDISOPCODE pOp, PDISOPPARAM pParam, PDISSTATE pDis)
    774889{
     
    19722087    unsigned reg   = MODRM_REG(modrm);
    19732088
    1974     pOp = (PCDISOPCODE)&g_aMapX86_Group1[idx+reg];
     2089    pOp = &g_aMapX86_Group1[idx+reg];
    19752090    //little hack to make sure the ModRM byte is included in the returned size
    19762091    if (pOp->idxParse1 != IDX_ParseModRM && pOp->idxParse2 != IDX_ParseModRM)
     
    20322147    unsigned reg   = MODRM_REG(modrm);
    20332148
    2034     pOp = (PCDISOPCODE)&g_aMapX86_Group3[idx+reg];
     2149    pOp = &g_aMapX86_Group3[idx+reg];
    20352150
    20362151    //little hack to make sure the ModRM byte is included in the returned size
     
    20522167    unsigned reg   = MODRM_REG(modrm);
    20532168
    2054     pOp = (PCDISOPCODE)&g_aMapX86_Group4[reg];
     2169    pOp = &g_aMapX86_Group4[reg];
    20552170
    20562171    //little hack to make sure the ModRM byte is included in the returned size
     
    20722187    unsigned reg   = MODRM_REG(modrm);
    20732188
    2074     pOp = (PCDISOPCODE)&g_aMapX86_Group5[reg];
     2189    pOp = &g_aMapX86_Group5[reg];
    20752190
    20762191    //little hack to make sure the ModRM byte is included in the returned size
     
    21062221    uint8_t opcode = disReadByte(pDis, offInstr+sizeof(uint8_t)+modrmsize);
    21072222
    2108     pOp = (PCDISOPCODE)&g_aTwoByteMapX86_3DNow[opcode];
     2223    pOp = &g_aTwoByteMapX86_3DNow[opcode];
    21092224
    21102225    //little hack to make sure the ModRM byte is included in the returned size
     
    21322247    unsigned reg   = MODRM_REG(modrm);
    21332248
    2134     pOp = (PCDISOPCODE)&g_aMapX86_Group6[reg];
     2249    pOp = &g_aMapX86_Group6[reg];
    21352250
    21362251    //little hack to make sure the ModRM byte is included in the returned size
     
    21552270
    21562271    if (mod == 3 && rm == 0)
    2157         pOp = (PCDISOPCODE)&g_aMapX86_Group7_mod11_rm000[reg];
     2272        pOp = &g_aMapX86_Group7_mod11_rm000[reg];
    21582273    else
    21592274    if (mod == 3 && rm == 1)
    2160         pOp = (PCDISOPCODE)&g_aMapX86_Group7_mod11_rm001[reg];
    2161     else
    2162         pOp = (PCDISOPCODE)&g_aMapX86_Group7_mem[reg];
     2275        pOp = &g_aMapX86_Group7_mod11_rm001[reg];
     2276    else
     2277        pOp = &g_aMapX86_Group7_mem[reg];
    21632278
    21642279    //little hack to make sure the ModRM byte is included in the returned size
     
    21802295    unsigned reg   = MODRM_REG(modrm);
    21812296
    2182     pOp = (PCDISOPCODE)&g_aMapX86_Group8[reg];
     2297    pOp = &g_aMapX86_Group8[reg];
    21832298
    21842299    //little hack to make sure the ModRM byte is included in the returned size
     
    22002315    unsigned reg   = MODRM_REG(modrm);
    22012316
    2202     pOp = (PCDISOPCODE)&g_aMapX86_Group9[reg];
     2317    pOp = &g_aMapX86_Group9[reg];
    22032318
    22042319    //little hack to make sure the ModRM byte is included in the returned size
     
    22202335    unsigned reg   = MODRM_REG(modrm);
    22212336
    2222     pOp = (PCDISOPCODE)&g_aMapX86_Group10[reg];
     2337    pOp = &g_aMapX86_Group10[reg];
    22232338
    22242339    //little hack to make sure the ModRM byte is included in the returned size
     
    22432358        reg += 8;   //2nd table
    22442359
    2245     pOp = (PCDISOPCODE)&g_aMapX86_Group12[reg];
     2360    pOp = &g_aMapX86_Group12[reg];
    22462361
    22472362    //little hack to make sure the ModRM byte is included in the returned size
     
    22642379        reg += 8;   //2nd table
    22652380
    2266     pOp = (PCDISOPCODE)&g_aMapX86_Group13[reg];
     2381    pOp = &g_aMapX86_Group13[reg];
    22672382
    22682383    //little hack to make sure the ModRM byte is included in the returned size
     
    22862401        reg += 8;   //2nd table
    22872402
    2288     pOp = (PCDISOPCODE)&g_aMapX86_Group14[reg];
     2403    pOp = &g_aMapX86_Group14[reg];
    22892404
    22902405    //little hack to make sure the ModRM byte is included in the returned size
     
    23092424
    23102425    if (mod == 3 && rm == 0)
    2311         pOp = (PCDISOPCODE)&g_aMapX86_Group15_mod11_rm000[reg];
    2312     else
    2313         pOp = (PCDISOPCODE)&g_aMapX86_Group15_mem[reg];
     2426        pOp = &g_aMapX86_Group15_mod11_rm000[reg];
     2427    else
     2428        pOp = &g_aMapX86_Group15_mem[reg];
    23142429
    23152430    //little hack to make sure the ModRM byte is included in the returned size
     
    23302445    unsigned reg   = MODRM_REG(modrm);
    23312446
    2332     pOp = (PCDISOPCODE)&g_aMapX86_Group16[reg];
     2447    pOp = &g_aMapX86_Group16[reg];
    23332448
    23342449    //little hack to make sure the ModRM byte is included in the returned size
     
    23382453    size += disParseInstruction(offInstr, pOp, pDis);
    23392454    return size;
    2340 }
    2341 //*****************************************************************************
    2342 //*****************************************************************************
    2343 static void disasmModRMReg(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam, int fRegAddr)
    2344 {
    2345     NOREF(pOp); NOREF(pDis);
    2346 
    2347     unsigned mod     = pDis->ModRM.Bits.Mod;
    2348 
    2349     unsigned type    = OP_PARM_VTYPE(pParam->fParam);
    2350     unsigned subtype = OP_PARM_VSUBTYPE(pParam->fParam);
    2351     if (fRegAddr)
    2352         subtype = (pDis->uAddrMode == DISCPUMODE_64BIT) ? OP_PARM_q : OP_PARM_d;
    2353     else
    2354     if (subtype == OP_PARM_v || subtype == OP_PARM_NONE)
    2355     {
    2356         switch (pDis->uOpMode)
    2357         {
    2358         case DISCPUMODE_32BIT:
    2359             subtype = OP_PARM_d;
    2360             break;
    2361         case DISCPUMODE_64BIT:
    2362             subtype = OP_PARM_q;
    2363             break;
    2364         case DISCPUMODE_16BIT:
    2365             subtype = OP_PARM_w;
    2366             break;
    2367         default:
    2368             /* make gcc happy */
    2369             break;
    2370         }
    2371     }
    2372 
    2373     switch (subtype)
    2374     {
    2375     case OP_PARM_b:
    2376         Assert(idx < (pDis->fPrefix & DISPREFIX_REX ? 16U : 8U));
    2377 
    2378         /* AH, BH, CH & DH map to DIL, SIL, EBL & SPL when a rex prefix is present. */
    2379         /* Intel® 64 and IA-32 Architectures Software Developer’s Manual: 3.4.1.1 */
    2380         if (    (pDis->fPrefix & DISPREFIX_REX)
    2381             &&  idx >= DISGREG_AH
    2382             &&  idx <= DISGREG_BH)
    2383         {
    2384             idx += (DISGREG_SPL - DISGREG_AH);
    2385         }
    2386 
    2387         pParam->fUse |= DISUSE_REG_GEN8;
    2388         pParam->Base.idxGenReg = idx;
    2389         break;
    2390 
    2391     case OP_PARM_w:
    2392         Assert(idx < (pDis->fPrefix & DISPREFIX_REX ? 16U : 8U));
    2393 
    2394         pParam->fUse |= DISUSE_REG_GEN16;
    2395         pParam->Base.idxGenReg = idx;
    2396         break;
    2397 
    2398     case OP_PARM_d:
    2399         Assert(idx < (pDis->fPrefix & DISPREFIX_REX ? 16U : 8U));
    2400 
    2401         pParam->fUse |= DISUSE_REG_GEN32;
    2402         pParam->Base.idxGenReg = idx;
    2403         break;
    2404 
    2405     case OP_PARM_q:
    2406         pParam->fUse |= DISUSE_REG_GEN64;
    2407         pParam->Base.idxGenReg = idx;
    2408         break;
    2409 
    2410     default:
    2411         Log(("disasmModRMReg %x:%x failed!!\n", type, subtype));
    2412         pDis->rc = VERR_DIS_INVALID_MODRM;
    2413         break;
    2414     }
    2415 }
    2416 //*****************************************************************************
    2417 static const uint8_t g_auBaseModRMReg16[8]  =
    2418 { DISGREG_BX, DISGREG_BX, DISGREG_BP, DISGREG_BP, DISGREG_SI, DISGREG_DI, DISGREG_BP, DISGREG_BX};
    2419 static const uint8_t g_auIndexModRMReg16[4] = { DISGREG_SI, DISGREG_DI, DISGREG_SI, DISGREG_DI };
    2420 //*****************************************************************************
    2421 static void disasmModRMReg16(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam)
    2422 {
    2423     NOREF(pDis); NOREF(pOp);
    2424     pParam->fUse |= DISUSE_REG_GEN16;
    2425     pParam->Base.idxGenReg = g_auBaseModRMReg16[idx];
    2426     if (idx < 4)
    2427     {
    2428         pParam->fUse |= DISUSE_INDEX;
    2429         pParam->Index.idxGenReg = g_auIndexModRMReg16[idx];
    2430     }
    2431 }
    2432 //*****************************************************************************
    2433 //*****************************************************************************
    2434 static void disasmModRMSReg(PDISSTATE pDis, PCDISOPCODE pOp, unsigned idx, PDISOPPARAM pParam)
    2435 {
    2436     NOREF(pOp);
    2437     if (idx >= DISSELREG_END)
    2438     {
    2439         Log(("disasmModRMSReg %d failed!!\n", idx));
    2440         pDis->rc = VERR_DIS_INVALID_PARAMETER;
    2441         return;
    2442     }
    2443 
    2444     pParam->fUse |= DISUSE_REG_SEG;
    2445     pParam->Base.idxSegReg = (DISSELREG)idx;
    24462455}
    24472456
     
    26572666                   PFNDISREADBYTES pfnReadBytes, void *pvUser)
    26582667{
    2659     /*
    2660      * Note! The RT_BZERO make ASSUMPTIONS about the placement of pvUser2.
    2661      */
    2662     RT_BZERO(pDis, RT_OFFSETOF(DISSTATE, pvUser2));
     2668    RT_ZERO(*pDis);
    26632669
    26642670#ifdef VBOX_STRICT /* poison */
     
    27472753 * @param   fFilter         Instruction type filter.
    27482754 * @param   pvUser          User argument for the instruction reader. (Ends up in pvUser.)
    2749  * @param   pDis            Pointer to CPU structure. With the exception of
    2750  *                          DISSTATE::pvUser2, the structure will be
    2751  *                          completely initialized by this API, i.e. no input is
    2752  *                          taken from it.
     2755 * @param   pDis            Pointer to disassembler state (output).
    27532756 * @param   pcbInstr        Where to store the size of the instruction.  (This
    27542757 *                          is also stored in PDISSTATE::cbInstr.)  Optional.
     
    27792782 * @param   fFilter         Instruction type filter.
    27802783 * @param   pvUser          User argument for the instruction reader. (Ends up in pvUser.)
    2781  * @param   pDis            Pointer to CPU structure. With the exception of
    2782  *                          DISSTATE::pvUser2, the structure will be
    2783  *                          completely initialized by this API, i.e. no input is
    2784  *                          taken from it.
     2784 * @param   pDis            Pointer to disassembler state (output).
    27852785 * @param   pcbInstr        Where to store the size of the instruction.  (This
    27862786 *                          is also stored in PDISSTATE::cbInstr.)  Optional.
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