VirtualBox

Changeset 66161 in vbox


Ignore:
Timestamp:
Mar 18, 2017 4:47:35 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114070
Message:

bs3-cpu-generated-1: Test more encodings.

File:
1 edited

Legend:

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

    r66159 r66161  
    9494    BS3CG1OPLOC_IMM,
    9595    BS3CG1OPLOC_MEM,
     96    BS3CG1OPLOC_MEM_RW,
    9697    BS3CG1OPLOC_END
    9798} BS3CG1OPLOC;
     
    178179        uint8_t             idxField;
    179180        /** Depends on enmLocation.
    180          * - BS3CG1OPLOC_IMM: offset relative to start of the instruction.
    181          * - BS3CG1OPLOC_MEM: offset should be subtracted from &pbDataPg[_4K].
    182          * - BS3CG1OPLOC_CTX: not used (use idxField instead).
     181         * - BS3CG1OPLOC_IMM:       offset relative to start of the instruction.
     182         * - BS3CG1OPLOC_MEM:       offset should be subtracted from &pbDataPg[_4K].
     183         * - BS3CG1OPLOC_MEM_RW:    offset should be subtracted from &pbDataPg[_4K].
     184         * - BS3CG1OPLOC_CTX:       not used (use idxField instead).
    183185         */
    184186        uint8_t             off;
     
    682684                off = Bs3Cg1InsertOpcodes(pThis, 0);
    683685                pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, X86_GREG_xAX, X86_GREG_xCX);
    684                 pThis->cbCurInstr = off;
    685686                pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_AL;
    686687                pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_CL;
    687                 iEncoding++;
    688             }
     688            }
     689            else if (iEncoding == 1 || iEncoding == 2)
     690            {
     691                /** @todo need to figure out a more flexible way to do all this crap. */
     692                off = 0;
     693                if (iEncoding == 2)
     694                    pThis->abCurInstr[off++] = 0x67;
     695                off = Bs3Cg1InsertOpcodes(pThis, off);
     696                if (BS3_MODE_IS_16BIT_CODE(pThis->bMode))
     697                {
     698#if ARCH_BITS == 16 /** @todo fixme */
     699                    unsigned iRing = 4;
     700                    if (BS3_MODE_IS_RM_OR_V86(pThis->bMode))
     701                        while (iRing-- > 0)
     702                            pThis->aInitialCtxs[iRing].ds = BS3_FP_SEG(pThis->pbDataPg);
     703                    else
     704                        while (iRing-- > 0)
     705                            pThis->aInitialCtxs[iRing].ds = BS3_FP_SEG(pThis->pbDataPg) | iRing;
     706#endif
     707                    if (iEncoding == 1)
     708                    {
     709                        pThis->abCurInstr[off++] = X86_MODRM_MAKE(0, X86_GREG_xBP, 6 /*disp16*/);
     710                        *(uint16_t *)&pThis->abCurInstr[off] = BS3_FP_OFF(pThis->pbDataPg) + X86_PAGE_SIZE - 1;
     711                        off += 2;
     712                    }
     713                    else
     714                    {
     715                        pThis->abCurInstr[off++] = X86_MODRM_MAKE(0, X86_GREG_xBP, 5 /*disp32*/);
     716                        *(uint32_t *)&pThis->abCurInstr[off] = BS3_FP_OFF(pThis->pbDataPg) + X86_PAGE_SIZE - 1;
     717                        off += 4;
     718                    }
     719                }
     720                else
     721                {
     722                    pThis->abCurInstr[off++] = X86_MODRM_MAKE(0, X86_GREG_xBP, 5 /*disp32*/);
     723                    *(uint32_t *)&pThis->abCurInstr[off] = BS3_FP_OFF(pThis->pbDataPg) + X86_PAGE_SIZE - 1;
     724                    if (BS3_MODE_IS_64BIT_CODE(pThis->bMode))
     725                        *(uint32_t *)&pThis->abCurInstr[off] -= BS3_FP_OFF(&pThis->pbCodePg[X86_PAGE_SIZE]);
     726                    off += 4;
     727                }
     728                pThis->aOperands[pThis->iRegOp].idxField    = BS3CG1DST_CH;
     729                pThis->aOperands[pThis->iRmOp ].idxField    = BS3CG1DST_INVALID;
     730                pThis->aOperands[pThis->iRmOp ].enmLocation = BS3CG1OPLOC_MEM_RW;
     731                pThis->aOperands[pThis->iRmOp ].off         = 1;
     732
     733                if (BS3_MODE_IS_32BIT_CODE(pThis->bMode)) /* skip address size override */
     734                    iEncoding++;
     735            }
     736            else
     737                break;
     738            pThis->cbCurInstr = off;
     739            iEncoding++;
    689740            break;
    690741
     
    695746                off = Bs3Cg1InsertOpcodes(pThis, 0);
    696747                pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, X86_GREG_xAX, X86_GREG_xCX);
    697                 pThis->cbCurInstr = off;
    698748                pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_AL;
    699749                pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_CL;
    700                 iEncoding++;
    701             }
     750            }
     751            else if (iEncoding == 1 || iEncoding == 2)
     752            {
     753                /** @todo need to figure out a more flexible way to do all this crap. */
     754                off = 0;
     755                if (iEncoding == 2)
     756                    pThis->abCurInstr[off++] = 0x67;
     757                off = Bs3Cg1InsertOpcodes(pThis, off);
     758                if (BS3_MODE_IS_16BIT_CODE(pThis->bMode))
     759                {
     760#if ARCH_BITS == 16 /** @todo fixme */
     761                    unsigned iRing = 4;
     762                    if (BS3_MODE_IS_RM_OR_V86(pThis->bMode))
     763                        while (iRing-- > 0)
     764                            pThis->aInitialCtxs[iRing].ds = BS3_FP_SEG(pThis->pbDataPg);
     765                    else
     766                        while (iRing-- > 0)
     767                            pThis->aInitialCtxs[iRing].ds = BS3_FP_SEG(pThis->pbDataPg) | iRing;
     768#endif
     769                    if (iEncoding == 1)
     770                    {
     771                        pThis->abCurInstr[off++] = X86_MODRM_MAKE(0, X86_GREG_xBP, 6 /*disp16*/);
     772                        *(uint16_t *)&pThis->abCurInstr[off] = BS3_FP_OFF(pThis->pbDataPg) + X86_PAGE_SIZE - 1;
     773                        off += 2;
     774                    }
     775                    else
     776                    {
     777                        pThis->abCurInstr[off++] = X86_MODRM_MAKE(0, X86_GREG_xBP, 5 /*disp32*/);
     778                        *(uint32_t *)&pThis->abCurInstr[off] = BS3_FP_OFF(pThis->pbDataPg) + X86_PAGE_SIZE - 1;
     779                        off += 4;
     780                    }
     781                }
     782                else
     783                {
     784                    pThis->abCurInstr[off++] = X86_MODRM_MAKE(0, X86_GREG_xBP, 5 /*disp32*/);
     785                    *(uint32_t *)&pThis->abCurInstr[off] = BS3_FP_OFF(pThis->pbDataPg) + X86_PAGE_SIZE - 1;
     786                    if (BS3_MODE_IS_64BIT_CODE(pThis->bMode))
     787                        *(uint32_t *)&pThis->abCurInstr[off] -= BS3_FP_OFF(&pThis->pbCodePg[X86_PAGE_SIZE]);
     788                    off += 4;
     789                }
     790                pThis->aOperands[pThis->iRegOp].idxField    = BS3CG1DST_CH;
     791                pThis->aOperands[pThis->iRmOp ].idxField    = BS3CG1DST_INVALID;
     792                pThis->aOperands[pThis->iRmOp ].enmLocation = BS3CG1OPLOC_MEM;
     793                pThis->aOperands[pThis->iRmOp ].off         = 1;
     794
     795                if (BS3_MODE_IS_32BIT_CODE(pThis->bMode)) /* skip address size override */
     796                    iEncoding++;
     797            }
     798            else
     799                break;
     800            pThis->cbCurInstr = off;
     801            iEncoding++;
    702802            break;
    703803
     
    12041304
    12051305                    case BS3CG1OPLOC_MEM:
     1306                        if (!pbInstr)
     1307                            return Bs3TestFailedF("Read only operand specified in output!");
     1308                        PtrField.pu8 = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[idxOp].off];
     1309                        break;
     1310
     1311                    case BS3CG1OPLOC_MEM_RW:
    12061312                        if (pbInstr)
    12071313                            PtrField.pu8 = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[idxOp].off];
    12081314                        else
    1209                             return Bs3TestFailedF("TODO: Implement output memory operands!");
     1315                            PtrField.pu8 = pThis->MemOp.ab[1];
    12101316                        break;
    12111317
     
    13881494                                           cbAdjustPc, 0 /*cbSpAdjust*/, 0 /*fExtraEfl*/,
    13891495                                           pThis->pszMode, iEncoding)))
    1390             return true;
     1496        {
     1497            bool fOkay = true;
     1498            iOperand = pThis->cOperands;
     1499            while (iOperand-- > 0)
     1500                if (pThis->aOperands[iOperand].enmLocation == BS3CG1OPLOC_MEM_RW)
     1501                {
     1502                    BS3PTRUNION PtrUnion;
     1503                    PtrUnion.pb = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[iOperand].off];
     1504                    switch (pThis->aOperands[iOperand].cbOp)
     1505                    {
     1506                        case 1:
     1507                            if (*PtrUnion.pu8 == pThis->MemOp.ab[0])
     1508                                continue;
     1509                            Bs3TestFailedF("op%u: Wrote %#04RX8, expected %#04RX8", iOperand, *PtrUnion.pu8, pThis->MemOp.ab[0]);
     1510                            break;
     1511                        case 2:
     1512                            if (*PtrUnion.pu16 == pThis->MemOp.au16[0])
     1513                                continue;
     1514                            Bs3TestFailedF("op%u: Wrote %#06RX16, expected %#06RX16",
     1515                                           iOperand, *PtrUnion.pu16, pThis->MemOp.au16[0]);
     1516                            break;
     1517                        case 4:
     1518                            if (*PtrUnion.pu32 == pThis->MemOp.au32[0])
     1519                                continue;
     1520                            Bs3TestFailedF("op%u: Wrote %#010RX32, expected %#010RX32",
     1521                                           iOperand, *PtrUnion.pu32, pThis->MemOp.au32[0]);
     1522                            break;
     1523                        case 8:
     1524                            if (*PtrUnion.pu64 == pThis->MemOp.au64[0])
     1525                                continue;
     1526                            Bs3TestFailedF("op%u: Wrote %#018RX64, expected %#018RX64",
     1527                                           iOperand, *PtrUnion.pu64, pThis->MemOp.au64[0]);
     1528                            break;
     1529                        default:
     1530                            if (Bs3MemCmp(PtrUnion.pb, pThis->MemOp.ab, pThis->aOperands[iOperand].cbOp) == 0)
     1531                                continue;
     1532                            Bs3TestFailedF("op%u: Wrote %.*Rhxs, expected %.*Rhxs",
     1533                                           iOperand,
     1534                                           pThis->aOperands[iOperand].cbOp, PtrUnion.pb,
     1535                                           pThis->aOperands[iOperand].cbOp, pThis->MemOp.ab);
     1536                            break;
     1537                    }
     1538                    fOkay = false;
     1539                }
     1540            if (fOkay)
     1541                return true;
     1542        }
    13911543
    13921544        /*
     
    14521604
    14531605            case BS3CG1OPLOC_MEM:
     1606            case BS3CG1OPLOC_MEM_RW:
    14541607                PtrUnion.pb = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[iOperand].off];
    14551608                switch (pThis->aOperands[iOperand].cbOp)
     
    14631616                                      pThis->aOperands[iOperand].cbOp, *PtrUnion.pu64);
    14641617                        break;
     1618                }
     1619                if (pThis->aOperands[iOperand].enmLocation == BS3CG1OPLOC_MEM_RW)
     1620                {
     1621                    PtrUnion.pb = pThis->MemOp.ab;
     1622                    switch (pThis->aOperands[iOperand].cbOp)
     1623                    {
     1624                        case 1: Bs3TestPrintf("op%u: expect mem08: %#04RX8\n", iOperand, *PtrUnion.pu8); break;
     1625                        case 2: Bs3TestPrintf("op%u: expect mem16: %#06RX16\n", iOperand, *PtrUnion.pu16); break;
     1626                        case 4: Bs3TestPrintf("op%u: expect mem32: %#010RX32\n", iOperand, *PtrUnion.pu32); break;
     1627                        case 8: Bs3TestPrintf("op%u: expect mem64: %#018RX64\n", iOperand, *PtrUnion.pu64); break;
     1628                        default:
     1629                            Bs3TestPrintf("op%u: expect mem%u: %.*Rhxs\n", iOperand, pThis->aOperands[iOperand].cbOp * 8,
     1630                                          pThis->aOperands[iOperand].cbOp, *PtrUnion.pu64);
     1631                            break;
     1632                    }
    14651633                }
    14661634                break;
     
    15161684            Bs3MemGuardedTestPageFree(This.pbCodePg);
    15171685            return Bs3TestFailedF("Second Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind);
     1686        }
     1687        if (   BS3_MODE_IS_64BIT_CODE(bMode)
     1688            && (uintptr_t)This.pbDataPg >= _2G)
     1689        {
     1690            Bs3TestFailedF("pbDataPg=%p is above 2GB and not simple to address from 64-bit code", This.pbDataPg);
     1691            Bs3MemGuardedTestPageFree(This.pbDataPg);
     1692            Bs3MemGuardedTestPageFree(This.pbCodePg);
     1693            return 0;
    15181694        }
    15191695    }
     
    16531829                    {
    16541830                        /* Okay, set up the execution context. */
    1655                         uint8_t BS3_FAR *pbCode = &This.pbCodePg[BS3_MODE_IS_PAGED(bMode) ? This.cbCurInstr : 0];
     1831                        uint8_t BS3_FAR *pbCode;
    16561832
    16571833                        Bs3MemCpy(&This.Ctx, &This.aInitialCtxs[iRing], sizeof(This.Ctx));
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