VirtualBox

Changeset 66118 in vbox


Ignore:
Timestamp:
Mar 15, 2017 7:04:42 PM (8 years ago)
Author:
vboxsync
Message:

bs3-cpu-generated-1: Implemented testing instruction taking AL,Ib as operands.

File:
1 edited

Legend:

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

    r66116 r66118  
    7575 * Debug print macro.
    7676 */
    77 #if 0
     77#if 1
    7878# define BS3CG1_DPRINTF(a_ArgList) Bs3TestPrintf a_ArgList
    79 # define BS3CG1_DEBUG_CTX_MOD
     79//# define BS3CG1_DEBUG_CTX_MOD
    8080#else
    8181# define BS3CG1_DPRINTF(a_ArgList) do { } while (0)
     
    8787*   Structures and Typedefs                                                                                                      *
    8888*********************************************************************************************************************************/
     89/** Operand value location. */
     90typedef enum BS3CG1OPLOC
     91{
     92    BS3CG1OPLOC_INVALID = 0,
     93    BS3CG1OPLOC_CTX,
     94    BS3CG1OPLOC_IMM,
     95    BS3CG1OPLOC_MEM,
     96    BS3CG1OPLOC_END
     97} BS3CG1OPLOC;
     98
    8999/**
    90100 * The state.
     
    162172    {
    163173        uint8_t             cbOp;
    164         bool                fMem;
     174        /** BS3CG1OPLOC_XXX. */
     175        uint8_t             enmLocation;
    165176        /** The BS3CG1DST value for this field.
    166177         * Set to BS3CG1DST_INVALID if memory.  */
    167178        uint8_t             idxField;
     179        /** Depends on enmLocation.
     180         * - BS3CG1OPLOC_IMM: offset relative to start of the instruction.
     181         */
     182        uint8_t             off;
    168183    } aOperands[4];
    169184    /** @} */
     
    631646            break;
    632647
     648        case BS3CG1ENC_FIXED_AL_Ib:
     649            if (iEncoding == 0)
     650            {
     651                off = Bs3Cg1InsertOpcodes(pThis, 0);
     652                pThis->aOperands[1].off = (uint8_t)off;
     653                pThis->abCurInstr[off++] = 0xff;
     654                pThis->cbCurInstr = off;
     655                iEncoding++;
     656            }
     657            break;
     658
    633659        case BS3CG1ENC_MODRM_Ev_Gv:
    634660        case BS3CG1ENC_MODRM_Gv_Ev:
    635         case BS3CG1ENC_FIXED_AL_Ib:
    636661        case BS3CG1ENC_FIXED_rAX_Iz:
    637662            break;
     
    671696            pThis->aOperands[0].cbOp = 1;
    672697            pThis->aOperands[1].cbOp = 1;
    673             pThis->aOperands[0].fMem = false;
    674             pThis->aOperands[1].fMem = false;
     698            pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX;
     699            pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX;
    675700            break;
    676701
     
    680705            pThis->aOperands[0].cbOp = 2;
    681706            pThis->aOperands[1].cbOp = 2;
    682             pThis->aOperands[0].fMem = false;
    683             pThis->aOperands[1].fMem = false;
     707            pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX;
     708            pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX;
    684709            break;
    685710
     
    689714            pThis->aOperands[0].cbOp = 1;
    690715            pThis->aOperands[1].cbOp = 1;
    691             pThis->aOperands[0].fMem = false;
    692             pThis->aOperands[1].fMem = false;
     716            pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX;
     717            pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX;
    693718            break;
    694719
     
    698723            pThis->aOperands[0].cbOp = 2;
    699724            pThis->aOperands[1].cbOp = 2;
    700             pThis->aOperands[0].fMem = false;
    701             pThis->aOperands[1].fMem = false;
     725            pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX;
     726            pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX;
    702727            break;
    703728
    704729        case BS3CG1ENC_FIXED_AL_Ib:
     730            pThis->aOperands[0].cbOp = 1;
     731            pThis->aOperands[1].cbOp = 1;
     732            pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX;
     733            pThis->aOperands[1].enmLocation = BS3CG1OPLOC_IMM;
     734            pThis->aOperands[0].idxField    = BS3CG1DST_AL;
     735            pThis->aOperands[1].idxField    = BS3CG1DST_INVALID;
    705736            break;
     737
    706738        case BS3CG1ENC_FIXED_rAX_Iz:
     739            pThis->aOperands[0].cbOp = 2;
     740            pThis->aOperands[1].cbOp = 2;
     741            pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX;
     742            pThis->aOperands[1].enmLocation = BS3CG1OPLOC_IMM;
     743            pThis->aOperands[0].idxField    = BS3CG1DST_OZ_RAX;
     744            pThis->aOperands[1].idxField    = BS3CG1DST_INVALID;
    707745            break;
    708746
    709747        default:
    710             Bs3TestFailedF("Invalid enmEncoding for instruction #%u (%.*s): %d",
    711                            pThis->iInstr, pThis->cchMnemonic, pThis->pchMnemonic, pThis->enmEncoding);
    712             return false;
     748            return Bs3TestFailedF("Invalid enmEncoding for instruction #%u (%.*s): %d",
     749                                  pThis->iInstr, pThis->cchMnemonic, pThis->pchMnemonic, pThis->enmEncoding);
    713750    }
    714751    return true;
     
    762799#undef CASE_PRED
    763800            default:
    764                 Bs3TestFailedF("Invalid selector opcode %#x!", pbCode[-1]);
    765                 return false;
     801                return Bs3TestFailedF("Invalid selector opcode %#x!", pbCode[-1]);
    766802        }
    767803    }
     
    782818 * @param   pEflCtx     The context to take undefined EFLAGS from.  (This is NULL
    783819 *                      if we're processing a input context modifier program.)
     820 * @param   pbInstr     Points to the first instruction byte.  For storing
     821 *                      immediate operands during input context modification.
     822 *                      NULL for output contexts.
    784823 */
    785824static bool Bs3Cg1RunContextModifier(PBS3CG1STATE pThis, PBS3REGCTX pCtx, PCBS3CG1TESTHDR pHdr, unsigned off, unsigned cb,
    786                                      PCBS3REGCTX pEflCtx)
     825                                     PCBS3REGCTX pEflCtx, uint8_t BS3_FAR *pbInstr)
    787826{
    788827    uint8_t const BS3_FAR *pbCode = (uint8_t const BS3_FAR *)(pHdr + 1) + off;
     
    833872                    else if (idxField < BS3CG1DST_END)
    834873                        break;
    835                     Bs3TestFailedF("Malformed context instruction: idxField=%d", idxField);
    836                     return false;
     874                    return Bs3TestFailedF("Malformed context instruction: idxField=%d", idxField);
    837875                }
    838876                /* fall thru */
    839877            default:
    840                 Bs3TestFailed("Malformed context instruction: Destination");
    841                 return false;
     878                return Bs3TestFailed("Malformed context instruction: Destination");
    842879        }
    843880
     
    862899                /* fall thru */
    863900            default:
    864                 Bs3TestFailed("Malformed context instruction: size");
    865                 return false;
     901                return Bs3TestFailed("Malformed context instruction: size");
    866902        }
    867903
     
    870906        { /* likely */ }
    871907        else
    872         {
    873             Bs3TestFailedF("Malformed context instruction: %u bytes value, %u bytes left", cbValue, cbLeft);
    874             return false;
    875         }
     908            return Bs3TestFailedF("Malformed context instruction: %u bytes value, %u bytes left", cbValue, cbLeft);
    876909
    877910        /*
     
    905938                            break;
    906939                        }
    907                         Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst);
    908                         return false;
     940                        return Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst);
    909941                }
    910942            else
     
    920952                            break;
    921953                        }
    922                         Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst);
    923                         return false;
     954                        return Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst);
    924955                }
    925956
     
    927958            if (offField < sizeof(BS3REGCTX))
    928959                PtrField.pu8 = (uint8_t BS3_FAR *)pCtx + offField;
     960            /* Non-register operands: */
     961            else if ((unsigned)(idxField - BS3CG1DST_OP1) < 4U)
     962            {
     963                unsigned const idxOp = idxField - BS3CG1DST_OP1;
     964
     965                switch (pThis->aOperands[idxOp].enmLocation)
     966                {
     967                    case BS3CG1OPLOC_IMM:
     968                        if (pbInstr)
     969                            PtrField.pu8 = &pbInstr[pThis->aOperands[idxOp].off];
     970                        else
     971                            return Bs3TestFailedF("Immediate operand referenced in output context!");
     972                        break;
     973
     974                    default:
     975                        return Bs3TestFailedF("Internal error: cbDst=%u idxField=%d (%d) offField=%#x: enmLocation=%u off=%#x idxField=%u",
     976                                              cbDst, idxField, idxOp, offField, pThis->aOperands[idxOp].enmLocation,
     977                                              pThis->aOperands[idxOp].off, pThis->aOperands[idxOp].idxField);
     978                }
     979            }
    929980            /* Special field: Copying in undefined EFLAGS from the result context. */
    930981            else if (idxField == BS3CG1DST_EFL_UNDEF)
    931982            {
    932983                if (!pEflCtx || (bOpcode & BS3CG1_CTXOP_OPERATOR_MASK) != BS3CG1_CTXOP_ASSIGN)
    933                 {
    934                     Bs3TestFailed("Invalid BS3CG1DST_EFL_UNDEF usage");
    935                     return false;
    936                 }
     984                    return Bs3TestFailed("Invalid BS3CG1DST_EFL_UNDEF usage");
    937985                PtrField.pu32 = &pCtx->rflags.u32;
    938986                uValue = (*PtrField.pu32 & ~(uint32_t)uValue) | (pEflCtx->rflags.u32 & (uint32_t)uValue);
     
    943991            //@todo }
    944992            else
    945             {
    946                 Bs3TestFailedF("Todo implement me: cbDst=%u idxField=%d offField=%#x", cbDst, idxField, offField);
    947                 return false;
    948             }
     993                return Bs3TestFailedF("Todo implement me: cbDst=%u idxField=%d offField=%#x", cbDst, idxField, offField);
    949994
    950995#ifdef BS3CG1_DEBUG_CTX_MOD
     
    10241069
    10251070                default:
    1026                     Bs3TestFailedF("Malformed context instruction: cbDst=%u, expected 1, 2, 4, or 8", cbDst);
    1027                     return false;
     1071                    return Bs3TestFailedF("Malformed context instruction: cbDst=%u, expected 1, 2, 4, or 8", cbDst);
    10281072            }
    10291073
     
    10431087         */
    10441088        else
    1045         {
    1046             Bs3TestFailedF("TODO: Implement me: cbDst=%u idxField=%d", cbDst, idxField);
    1047             return false;
    1048         }
     1089            return Bs3TestFailedF("TODO: Implement me: cbDst=%u idxField=%d", cbDst, idxField);
    10491090
    10501091        /*
     
    10871128        This.pbCodePg = Bs3MemGuardedTestPageAlloc(enmMemKind);
    10881129        if (!This.pbCodePg)
    1089         {
    1090             Bs3TestFailedF("First Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind);
    1091             return 0;
    1092         }
     1130            return Bs3TestFailedF("First Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind);
    10931131        This.pbDataPg = Bs3MemGuardedTestPageAlloc(enmMemKind);
    10941132        if (!This.pbDataPg)
    10951133        {
    10961134            Bs3MemGuardedTestPageFree(This.pbCodePg);
    1097             Bs3TestFailedF("Second Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind);
    1098             return 0;
     1135            return Bs3TestFailedF("Second Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind);
    10991136        }
    11001137    }
     
    11031140        This.pbCodePg = Bs3MemAlloc(enmMemKind, X86_PAGE_SIZE);
    11041141        if (!This.pbCodePg)
    1105         {
    1106             Bs3TestFailedF("First Bs3MemAlloc(%d,Pg) failed", enmMemKind);
    1107             return 0;
    1108         }
     1142            return Bs3TestFailedF("First Bs3MemAlloc(%d,Pg) failed", enmMemKind);
    11091143        This.pbDataPg = Bs3MemAlloc(enmMemKind, X86_PAGE_SIZE);
    11101144        if (!This.pbDataPg)
    11111145        {
    11121146            Bs3MemFree(This.pbCodePg, X86_PAGE_SIZE);
    1113             Bs3TestFailedF("Second Bs3MemAlloc(%d,Pg) failed", enmMemKind);
    1114             return 0;
     1147            return Bs3TestFailedF("Second Bs3MemAlloc(%d,Pg) failed", enmMemKind);
    11151148        }
    11161149    }
     
    12441277                        This.Ctx.rip.u = BS3_FP_OFF(pbCode);
    12451278
    1246                         if (Bs3Cg1RunContextModifier(&This, &This.Ctx, pHdr, pHdr->cbSelector, pHdr->cbInput, NULL))
     1279                        if (Bs3Cg1RunContextModifier(&This, &This.Ctx, pHdr, pHdr->cbSelector, pHdr->cbInput, NULL, pbCode))
    12471280                        {
    12481281                            /* Run the instruction. */
     
    12631296                                if (Bs3Cg1RunContextModifier(&This, &This.Ctx, pHdr,
    12641297                                                             pHdr->cbSelector + pHdr->cbInput, pHdr->cbOutput,
    1265                                                              &This.TrapFrame.Ctx))
     1298                                                             &This.TrapFrame.Ctx, NULL /*pbCode*/))
    12661299                                {
    12671300                                    Bs3TestCheckRegCtxEx(&This.TrapFrame.Ctx, &This.Ctx, This.cbCurInstr,  0 /*cbSpAdjust*/,
Note: See TracChangeset for help on using the changeset viewer.

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