VirtualBox

Ignore:
Timestamp:
Apr 4, 2017 6:18:07 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114383
Message:

bs3-cpu-generated-1: fixes

File:
1 edited

Legend:

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

    r66419 r66422  
    229229     * UINT8_MAX if no special exception expected. */
    230230    uint8_t                 bAlignmentXcpt;
     231    /** Set by the encoding method to indicating invalid encoding. */
     232    bool                    fInvalidEncoding;
    231233
    232234    /** The context we're working on. */
     
    12611263
    12621264
    1263 unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr)
     1265static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(PBS3CG1STATE pThis, unsigned iEncoding)
    12641266{
    12651267    unsigned off;
     
    12921294
    12931295
    1294 unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr)
     1296static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(PBS3CG1STATE pThis, unsigned iEncoding)
    12951297{
    12961298    unsigned off;
     
    13231325
    13241326
    1325 unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ev__OR__BS3CG1ENC_MODRM_Ev_Gv(PBS3CG1STATE pThis,
    1326                                                                            unsigned iEncoding, bool *pfInvalidInstr)
     1327static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ev__OR__BS3CG1ENC_MODRM_Ev_Gv(PBS3CG1STATE pThis, unsigned iEncoding)
    13271328{
    13281329    unsigned off;
     
    14031404
    14041405
    1405 
    1406 static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr)
     1406static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Wss_Vss(PBS3CG1STATE pThis, unsigned iEncoding)
     1407{
     1408    unsigned off;
     1409    if (iEncoding == 0)
     1410    {
     1411        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1412        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
     1413        pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_DW0;
     1414        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_DW0;
     1415    }
     1416    else if (iEncoding == 1)
     1417    {
     1418        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_DW0;
     1419        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1420        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 4, 0, BS3CG1OPLOC_MEM_RW);
     1421    }
     1422    else if (iEncoding == 2)
     1423    {
     1424        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_DW0;
     1425        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1426        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 4, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
     1427    }
     1428    else
     1429        return 0;
     1430    pThis->cbCurInstr = off;
     1431    return iEncoding + 1;
     1432}
     1433
     1434
     1435static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Wsd_Vsd(PBS3CG1STATE pThis, unsigned iEncoding)
     1436{
     1437    unsigned off;
     1438    if (iEncoding == 0)
     1439    {
     1440        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1441        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
     1442        pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_LO;
     1443        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_LO;
     1444    }
     1445    else if (iEncoding == 1)
     1446    {
     1447        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
     1448        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1449        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 8, 0, BS3CG1OPLOC_MEM_RW);
     1450    }
     1451    else if (iEncoding == 2)
     1452    {
     1453        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_LO;
     1454        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1455        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 8, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
     1456    }
     1457    else
     1458        return 0;
     1459    pThis->cbCurInstr = off;
     1460    return iEncoding + 1;
     1461}
     1462
     1463
     1464static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Wps_Vps__OR__BS3CG1ENC_MODRM_Wpd_Vpd(PBS3CG1STATE pThis, unsigned iEncoding)
     1465{
     1466    unsigned off;
     1467    if (iEncoding == 0)
     1468    {
     1469        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1470        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
     1471        pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0;
     1472        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1;
     1473    }
     1474    else if (iEncoding == 1)
     1475    {
     1476        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2;
     1477        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1478        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 16, 0, BS3CG1OPLOC_MEM_RW);
     1479    }
     1480    else if (iEncoding == 2)
     1481    {
     1482        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3;
     1483        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1484        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 16, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
     1485        if (!Bs3Cg1XcptTypeIsUnaligned(pThis->enmXcptType))
     1486            pThis->bAlignmentXcpt = X86_XCPT_GP;
     1487    }
     1488    else
     1489        return 0;
     1490    pThis->cbCurInstr = off;
     1491    return iEncoding + 1;
     1492}
     1493
     1494
     1495static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_WqZxReg_Vq(PBS3CG1STATE pThis, unsigned iEncoding)
     1496{
     1497    unsigned off;
     1498    if (iEncoding == 0)
     1499    {
     1500        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1501        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
     1502        pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_LO_ZX;
     1503        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_LO;
     1504    }
     1505    else if (iEncoding == 1)
     1506    {
     1507        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
     1508        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1509        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 8, 0, BS3CG1OPLOC_MEM_RW);
     1510    }
     1511    else if (iEncoding == 2)
     1512    {
     1513        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_LO;
     1514        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1515        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 8, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
     1516    }
     1517    else
     1518        return 0;
     1519    pThis->cbCurInstr = off;
     1520    return iEncoding + 1;
     1521}
     1522
     1523
     1524static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Vq_UqHi(PBS3CG1STATE pThis, unsigned iEncoding)
     1525{
     1526    unsigned off;
     1527    if (iEncoding == 0)
     1528    {
     1529        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1530        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
     1531        pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_HI;
     1532        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_LO;
     1533    }
     1534    else if (iEncoding == 1)
     1535    {
     1536        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1537        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 2, 2);
     1538        pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM2_HI;
     1539        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
     1540    }
     1541    else
     1542        return 0;
     1543    pThis->cbCurInstr = off;
     1544    return iEncoding + 1;
     1545}
     1546
     1547
     1548static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Vq_Mq(PBS3CG1STATE pThis, unsigned iEncoding)
     1549{
     1550    unsigned off;
     1551    if (iEncoding == 0)
     1552    {
     1553        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
     1554        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1555        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 8, 0, BS3CG1OPLOC_MEM);
     1556    }
     1557    else if (iEncoding == 1)
     1558    {
     1559        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_LO;
     1560        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1561        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 8, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM);
     1562    }
     1563    else
     1564        return 0;
     1565    pThis->cbCurInstr = off;
     1566    return iEncoding + 1;
     1567}
     1568
     1569
     1570static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Vdq_Wdq(PBS3CG1STATE pThis, unsigned iEncoding)
     1571{
     1572    unsigned off;
     1573    if (iEncoding == 0)
     1574    {
     1575        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1576        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
     1577        pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0;
     1578        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1;
     1579    }
     1580    else if (iEncoding == 1)
     1581    {
     1582        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2;
     1583        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1584        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 16, 0, BS3CG1OPLOC_MEM);
     1585    }
     1586    else if (iEncoding == 2)
     1587    {
     1588        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3;
     1589        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1590        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 16, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM);
     1591        if (!Bs3Cg1XcptTypeIsUnaligned(pThis->enmXcptType))
     1592            pThis->bAlignmentXcpt = X86_XCPT_GP;
     1593    }
     1594    else
     1595        return 0;
     1596    pThis->cbCurInstr = off;
     1597    return iEncoding + 1;
     1598}
     1599
     1600
     1601static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ma(PBS3CG1STATE pThis, unsigned iEncoding)
     1602{
     1603    unsigned off;
     1604    unsigned cbOp = BS3_MODE_IS_16BIT_CODE(pThis->bMode) ? 2 : 4;
     1605    if (iEncoding == 0)
     1606    {
     1607        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
     1608        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1609        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
     1610    }
     1611    else if (iEncoding == 1 && (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
     1612    {
     1613        cbOp = cbOp == 2 ? 4 : 2;
     1614        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
     1615        pThis->abCurInstr[0] = P_OZ;
     1616        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 1));
     1617        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
     1618    }
     1619    else if (iEncoding == 2)
     1620    {
     1621        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
     1622        pThis->abCurInstr[0] = P_AZ;
     1623        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 1));
     1624        off = Bs3Cfg1EncodeMemMod0Disp(pThis, true, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
     1625    }
     1626    else if (iEncoding == 3)
     1627    {
     1628        cbOp = cbOp == 2 ? 4 : 2;
     1629        pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
     1630        pThis->abCurInstr[0] = P_AZ;
     1631        pThis->abCurInstr[1] = P_OZ;
     1632        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 2));
     1633        off = Bs3Cfg1EncodeMemMod0Disp(pThis, true, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
     1634    }
     1635    else
     1636        return 0;
     1637    pThis->aOperands[pThis->iRegOp].cbOp = cbOp;
     1638    pThis->cbOperand  = cbOp;
     1639    pThis->cbCurInstr = off;
     1640    return iEncoding + 1;
     1641}
     1642
     1643
     1644static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MbRO(PBS3CG1STATE pThis, unsigned iEncoding)
     1645{
     1646    unsigned off;
     1647    if (iEncoding == 0)
     1648    {
     1649        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0)) - 1;
     1650        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off,
     1651                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
     1652                                       1, 0, BS3CG1OPLOC_MEM);
     1653    }
     1654    else
     1655        return 0;
     1656    pThis->cbCurInstr = off;
     1657    return iEncoding + 1;
     1658}
     1659
     1660
     1661static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MdRO(PBS3CG1STATE pThis, unsigned iEncoding)
     1662{
     1663    unsigned off;
     1664    if (iEncoding == 0)
     1665    {
     1666        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0)) - 1;
     1667        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off,
     1668                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
     1669                                       4, 0, BS3CG1OPLOC_MEM);
     1670    }
     1671    else
     1672        return 0;
     1673    pThis->cbCurInstr = off;
     1674    return iEncoding + 1;
     1675}
     1676
     1677
     1678static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MdWO(PBS3CG1STATE pThis, unsigned iEncoding)
     1679{
     1680    unsigned off;
     1681    if (iEncoding == 0)
     1682    {
     1683        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0)) - 1;
     1684        off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off,
     1685                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
     1686                                       4, 0, BS3CG1OPLOC_MEM_RW);
     1687    }
     1688    else
     1689        return 0;
     1690    pThis->cbCurInstr = off;
     1691    return iEncoding + 1;
     1692}
     1693
     1694
     1695static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(PBS3CG1STATE pThis, unsigned iEncoding)
    14071696{
    14081697    unsigned off;
     
    14311720                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    14321721                                       4, 0, BS3CG1OPLOC_MEM_RW);
    1433         *pfInvalidInstr = true;
     1722        pThis->fInvalidEncoding = true;
    14341723    }
    14351724    else if (iEncoding == 3)
     
    14401729                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    14411730                                       4, 0, BS3CG1OPLOC_MEM_RW);
    1442         *pfInvalidInstr = true;
     1731        pThis->fInvalidEncoding = true;
    14431732    }
    14441733    else if (iEncoding == 4)
     
    14501739                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    14511740                                       4, 0, BS3CG1OPLOC_MEM_RW);
    1452         *pfInvalidInstr = true;
     1741        pThis->fInvalidEncoding = true;
    14531742    }
    14541743    else if (iEncoding == 5)
     
    14601749                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    14611750                                       4, 0, BS3CG1OPLOC_MEM_RW);
    1462         *pfInvalidInstr = true;
     1751        pThis->fInvalidEncoding = true;
    14631752    }
    14641753    else if (iEncoding == 6)
     
    14701759                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    14711760                                       4, 0, BS3CG1OPLOC_MEM_RW);
    1472         *pfInvalidInstr = true;
     1761        pThis->fInvalidEncoding = true;
    14731762    }
    14741763    else if (iEncoding == 7)
     
    14791768                                       (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    14801769                                       4, 0, BS3CG1OPLOC_MEM_RW);
     1770    }
     1771#if ARCH_BITS == 64
     1772    else if (BS3_MODE_IS_64BIT_CODE(pThis->bMode))
     1773    {
     1774        if (iEncoding == 8)
     1775        {
     1776            pThis->abCurInstr[0] = REX_____;
     1777            off = Bs3Cg1InsertVex3bPrefix(pThis, 1 /*offDst*/, 0xf /*~V*/, 0 /*L*/, 1 /*~R*/, 1 /*~X*/, 1 /*~B*/, 0 /*W*/);
     1778            off = Bs3Cg1InsertOpcodes(pThis, off) - 1;
     1779            off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off,
     1780                                           (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
     1781                                           4, 0, BS3CG1OPLOC_MEM_RW);
     1782            pThis->fInvalidEncoding = true;
     1783        }
     1784        else
     1785            return 0;
     1786    }
     1787#endif
     1788    else
     1789        return 0;
     1790    pThis->cbCurInstr = off;
     1791    return iEncoding + 1;
     1792}
     1793
     1794
     1795static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_FIXED(PBS3CG1STATE pThis, unsigned iEncoding)
     1796{
     1797    unsigned off;
     1798    if (iEncoding == 0)
     1799    {
     1800        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1801        pThis->cbCurInstr = off;
     1802        iEncoding++;
     1803    }
     1804    else
     1805        return 0;
     1806    return iEncoding + 1;
     1807}
     1808
     1809
     1810static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_FIXED_AL_Ib(PBS3CG1STATE pThis, unsigned iEncoding)
     1811{
     1812    unsigned off;
     1813    if (iEncoding == 0)
     1814    {
     1815        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1816        pThis->aOperands[1].off = (uint8_t)off;
     1817        pThis->abCurInstr[off++] = 0xff;
     1818        pThis->cbCurInstr = off;
     1819    }
     1820    else
     1821        return 0;
     1822    return iEncoding + 1;
     1823}
     1824
     1825
     1826static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_FIXED_rAX_Iz(PBS3CG1STATE pThis, unsigned iEncoding)
     1827{
     1828    unsigned off;
     1829    if (iEncoding == 0)
     1830    {
     1831        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
     1832        pThis->aOperands[1].off = (uint8_t)off;
     1833        if (BS3_MODE_IS_16BIT_CODE(pThis->bMode))
     1834        {
     1835            *(uint16_t *)&pThis->abCurInstr[off] = UINT16_MAX;
     1836            off += 2;
     1837            pThis->aOperands[0].cbOp = 2;
     1838            pThis->aOperands[1].cbOp = 2;
     1839            pThis->cbOperand         = 2;
     1840        }
     1841        else
     1842        {
     1843            *(uint32_t *)&pThis->abCurInstr[off] = UINT32_MAX;
     1844            off += 4;
     1845            pThis->aOperands[0].cbOp = 4;
     1846            pThis->aOperands[1].cbOp = 4;
     1847            pThis->cbOperand         = 4;
     1848        }
     1849    }
     1850    else if (iEncoding == 1 && (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
     1851    {
     1852        pThis->abCurInstr[0] = P_OZ;
     1853        off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 1));
     1854        pThis->aOperands[1].off = (uint8_t)off;
     1855        if (!BS3_MODE_IS_16BIT_CODE(pThis->bMode))
     1856        {
     1857            *(uint16_t *)&pThis->abCurInstr[off] = UINT16_MAX;
     1858            off += 2;
     1859            pThis->aOperands[0].cbOp = 2;
     1860            pThis->aOperands[1].cbOp = 2;
     1861            pThis->cbOperand         = 2;
     1862        }
     1863        else
     1864        {
     1865            *(uint32_t *)&pThis->abCurInstr[off] = UINT32_MAX;
     1866            off += 4;
     1867            pThis->aOperands[0].cbOp = 4;
     1868            pThis->aOperands[1].cbOp = 4;
     1869            pThis->cbOperand         = 4;
     1870        }
     1871    }
     1872    else if (iEncoding == 2 && BS3_MODE_IS_64BIT_CODE(pThis->bMode))
     1873    {
     1874        off = Bs3Cg1InsertReqPrefix(pThis, 0);
     1875        pThis->abCurInstr[off++] = REX_W___;
     1876        off = Bs3Cg1InsertOpcodes(pThis, off);
     1877        pThis->aOperands[1].off = (uint8_t)off;
     1878        *(uint32_t *)&pThis->abCurInstr[off] = UINT32_MAX;
     1879        off += 4;
     1880        pThis->aOperands[0].cbOp = 8;
     1881        pThis->aOperands[1].cbOp = 4;
     1882        pThis->cbOperand         = 8;
     1883    }
     1884    else
     1885        return 0;
     1886    pThis->cbCurInstr = off;
     1887    return iEncoding + 1;
     1888}
     1889
     1890
     1891static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MOD_EQ_3(PBS3CG1STATE pThis, unsigned iEncoding)
     1892{
     1893    unsigned off;
     1894    if (iEncoding < 8)
     1895    {
     1896        off = Bs3Cg1InsertReqPrefix(pThis, 0);
     1897        off = Bs3Cg1InsertOpcodes(pThis, off);
     1898        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, iEncoding, 1);
     1899    }
     1900    else if (iEncoding < 16)
     1901    {
     1902        off = Bs3Cg1InsertReqPrefix(pThis, 0);
     1903        off = Bs3Cg1InsertOpcodes(pThis, off);
     1904        pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 0, iEncoding);
     1905    }
     1906    else
     1907        return 0;
     1908    pThis->cbCurInstr = off;
     1909
     1910    return iEncoding + 1;
     1911}
     1912
     1913
     1914static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MOD_NE_3(PBS3CG1STATE pThis, unsigned iEncoding)
     1915{
     1916    unsigned off;
     1917    if (iEncoding < 3)
     1918    {
     1919        off = Bs3Cg1InsertReqPrefix(pThis, 0);
     1920        off = Bs3Cg1InsertOpcodes(pThis, off);
     1921        pThis->abCurInstr[off++] = X86_MODRM_MAKE(iEncoding, 0, 1);
     1922        if (iEncoding >= 1)
     1923            pThis->abCurInstr[off++] = 0x7f;
     1924        if (iEncoding == 2)
     1925        {
     1926            pThis->abCurInstr[off++] = 0x5f;
     1927            if (!BS3_MODE_IS_16BIT_CODE(pThis->bMode))
     1928            {
     1929                pThis->abCurInstr[off++] = 0x3f;
     1930                pThis->abCurInstr[off++] = 0x1f;
     1931            }
     1932        }
    14811933    }
    14821934    else
     
    14961948 *                          each BS3CG1ENC_XXX value and should be considered
    14971949 *                          internal.
    1498  * @param   pfInvalidInstr  Pointer to variable to set when generating an
    1499  *                          invalid encoding.  (Never clear this.)
    15001950 */
    1501 unsigned Bs3Cg1EncodeNext(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr)
    1502 {
    1503     unsigned off;
    1504     unsigned cbOp;
    1505 
     1951static unsigned Bs3Cg1EncodeNext(PBS3CG1STATE pThis, unsigned iEncoding)
     1952{
    15061953    pThis->bAlignmentXcpt = UINT8_MAX;
    15071954
     
    15091956    {
    15101957        case BS3CG1ENC_MODRM_Eb_Gb:
    1511             return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(pThis, iEncoding, pfInvalidInstr);
     1958            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(pThis, iEncoding);
    15121959        case BS3CG1ENC_MODRM_Gb_Eb:
    1513             return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(pThis, iEncoding, pfInvalidInstr);
     1960            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(pThis, iEncoding);
    15141961        case BS3CG1ENC_MODRM_Gv_Ev:
    15151962        case BS3CG1ENC_MODRM_Ev_Gv:
    1516             return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ev__OR__BS3CG1ENC_MODRM_Ev_Gv(pThis, iEncoding, pfInvalidInstr);
     1963            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ev__OR__BS3CG1ENC_MODRM_Ev_Gv(pThis, iEncoding);
    15171964
    15181965        case BS3CG1ENC_MODRM_Wss_Vss:
    1519             if (iEncoding == 0)
    1520             {
    1521                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1522                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
    1523                 pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_DW0;
    1524                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_DW0;
    1525             }
    1526             else if (iEncoding == 1)
    1527             {
    1528                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_DW0;
    1529                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1530                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 4, 0, BS3CG1OPLOC_MEM_RW);
    1531             }
    1532             else if (iEncoding == 2)
    1533             {
    1534                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_DW0;
    1535                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1536                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 4, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
    1537             }
    1538             else
    1539                 break;
    1540             pThis->cbCurInstr = off;
    1541             iEncoding++;
    1542             break;
    1543 
     1966            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Wss_Vss(pThis, iEncoding);
    15441967        case BS3CG1ENC_MODRM_Wsd_Vsd:
    1545             if (iEncoding == 0)
    1546             {
    1547                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1548                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
    1549                 pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_LO;
    1550                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_LO;
    1551             }
    1552             else if (iEncoding == 1)
    1553             {
    1554                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
    1555                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1556                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 8, 0, BS3CG1OPLOC_MEM_RW);
    1557             }
    1558             else if (iEncoding == 2)
    1559             {
    1560                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_LO;
    1561                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1562                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 8, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
    1563             }
    1564             else
    1565                 break;
    1566             pThis->cbCurInstr = off;
    1567             iEncoding++;
    1568             break;
    1569 
     1968            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Wsd_Vsd(pThis, iEncoding);
    15701969        case BS3CG1ENC_MODRM_Wps_Vps:
    15711970        case BS3CG1ENC_MODRM_Wpd_Vpd:
    1572             if (iEncoding == 0)
    1573             {
    1574                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1575                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
    1576                 pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0;
    1577                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1;
    1578             }
    1579             else if (iEncoding == 1)
    1580             {
    1581                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2;
    1582                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1583                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 16, 0, BS3CG1OPLOC_MEM_RW);
    1584             }
    1585             else if (iEncoding == 2)
    1586             {
    1587                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3;
    1588                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1589                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 16, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
    1590                 if (!Bs3Cg1XcptTypeIsUnaligned(pThis->enmXcptType))
    1591                     pThis->bAlignmentXcpt = X86_XCPT_GP;
    1592             }
    1593             else
    1594                 break;
    1595             pThis->cbCurInstr = off;
    1596             iEncoding++;
    1597             break;
    1598 
     1971            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Wps_Vps__OR__BS3CG1ENC_MODRM_Wpd_Vpd(pThis, iEncoding);
    15991972        case BS3CG1ENC_MODRM_WqZxReg_Vq:
    1600             if (iEncoding == 0)
    1601             {
    1602                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1603                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
    1604                 pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_LO_ZX;
    1605                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_LO;
    1606             }
    1607             else if (iEncoding == 1)
    1608             {
    1609                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
    1610                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1611                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 8, 0, BS3CG1OPLOC_MEM_RW);
    1612             }
    1613             else if (iEncoding == 2)
    1614             {
    1615                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_LO;
    1616                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1617                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 8, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM_RW);
    1618             }
    1619             else
    1620                 break;
    1621             pThis->cbCurInstr = off;
    1622             iEncoding++;
    1623             break;
     1973            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_WqZxReg_Vq(pThis, iEncoding);
    16241974
    16251975        case BS3CG1ENC_MODRM_Vq_UqHi:
    1626             if (iEncoding == 0)
    1627             {
    1628                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1629                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
    1630                 pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0_HI;
    1631                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1_LO;
    1632             }
    1633             else if (iEncoding == 1)
    1634             {
    1635                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1636                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 2, 2);
    1637                 pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM2_HI;
    1638                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
    1639             }
    1640             else
    1641                 break;
    1642             pThis->cbCurInstr = off;
    1643             iEncoding++;
    1644             break;
    1645 
     1976            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Vq_UqHi(pThis, iEncoding);
    16461977        case BS3CG1ENC_MODRM_Vq_Mq:
    1647             if (iEncoding == 0)
    1648             {
    1649                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2_LO;
    1650                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1651                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 8, 0, BS3CG1OPLOC_MEM);
    1652             }
    1653             else if (iEncoding == 1)
    1654             {
    1655                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3_LO;
    1656                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1657                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 8, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM);
    1658             }
    1659             else
    1660                 break;
    1661             pThis->cbCurInstr = off;
    1662             iEncoding++;
    1663             break;
    1664 
     1978            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Vq_Mq(pThis, iEncoding);
    16651979        case BS3CG1ENC_MODRM_Vdq_Wdq:
    1666             if (iEncoding == 0)
    1667             {
    1668                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1669                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 1, 0);
    1670                 pThis->aOperands[pThis->iRmOp ].idxField = BS3CG1DST_XMM0;
    1671                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM1;
    1672             }
    1673             else if (iEncoding == 1)
    1674             {
    1675                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM2;
    1676                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1677                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 2 /*iReg*/, 16, 0, BS3CG1OPLOC_MEM);
    1678             }
    1679             else if (iEncoding == 2)
    1680             {
    1681                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_XMM3;
    1682                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1683                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, 3 /*iReg*/, 16, 1 /*cbMissalign*/, BS3CG1OPLOC_MEM);
    1684                 if (!Bs3Cg1XcptTypeIsUnaligned(pThis->enmXcptType))
    1685                     pThis->bAlignmentXcpt = X86_XCPT_GP;
    1686             }
    1687             else
    1688                 break;
    1689             pThis->cbCurInstr = off;
    1690             iEncoding++;
    1691             break;
     1980            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Vdq_Wdq(pThis, iEncoding);
    16921981
    16931982        case BS3CG1ENC_MODRM_Gv_Ma:
    1694             cbOp = BS3_MODE_IS_16BIT_CODE(pThis->bMode) ? 2 : 4;
    1695             if (iEncoding == 0)
    1696             {
    1697                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
    1698                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1699                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
    1700             }
    1701             else if (iEncoding == 1 && (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
    1702             {
    1703                 cbOp = cbOp == 2 ? 4 : 2;
    1704                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
    1705                 pThis->abCurInstr[0] = P_OZ;
    1706                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 1));
    1707                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
    1708             }
    1709             else if (iEncoding == 2)
    1710             {
    1711                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
    1712                 pThis->abCurInstr[0] = P_AZ;
    1713                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 1));
    1714                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, true, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
    1715             }
    1716             else if (iEncoding == 3)
    1717             {
    1718                 cbOp = cbOp == 2 ? 4 : 2;
    1719                 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_OZ_RBP;
    1720                 pThis->abCurInstr[0] = P_AZ;
    1721                 pThis->abCurInstr[1] = P_OZ;
    1722                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 2));
    1723                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, true, off, X86_GREG_xBP, cbOp * 2, 0, BS3CG1OPLOC_MEM);
    1724             }
    1725             else
    1726                 break;
    1727             pThis->aOperands[pThis->iRegOp].cbOp = cbOp;
    1728             pThis->cbOperand  = cbOp;
    1729             pThis->cbCurInstr = off;
    1730             iEncoding++;
    1731             break;
     1983            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ma(pThis, iEncoding);
    17321984
    17331985        case BS3CG1ENC_MODRM_MbRO:
    1734             if (iEncoding == 0)
    1735             {
    1736                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0)) - 1;
    1737                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off,
    1738                                                (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    1739                                                1, 0, BS3CG1OPLOC_MEM);
    1740             }
    1741             else
    1742                 break;
    1743             pThis->cbCurInstr = off;
    1744             iEncoding++;
    1745             break;
    1746 
     1986            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MbRO(pThis, iEncoding);
    17471987        case BS3CG1ENC_MODRM_MdRO:
    1748             if (iEncoding == 0)
    1749             {
    1750                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0)) - 1;
    1751                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off,
    1752                                                (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    1753                                                4, 0, BS3CG1OPLOC_MEM);
    1754             }
    1755             else
    1756                 break;
    1757             pThis->cbCurInstr = off;
    1758             iEncoding++;
    1759             break;
    1760 
     1988            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MdRO(pThis, iEncoding);
    17611989        case BS3CG1ENC_MODRM_MdWO:
    1762             if (iEncoding == 0)
    1763             {
    1764                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0)) - 1;
    1765                 off = Bs3Cfg1EncodeMemMod0Disp(pThis, false, off,
    1766                                                (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT,
    1767                                                4, 0, BS3CG1OPLOC_MEM_RW);
    1768             }
    1769             else
    1770                 break;
    1771             pThis->cbCurInstr = off;
    1772             iEncoding++;
    1773             break;
    1774 
     1990            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MdWO(pThis, iEncoding);
    17751991        case BS3CG1ENC_VEX_MODRM_MdWO:
    1776             return Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(pThis, iEncoding, pfInvalidInstr);
     1992            return Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(pThis, iEncoding);
    17771993
    17781994        case BS3CG1ENC_FIXED:
    1779             if (iEncoding == 0)
    1780             {
    1781                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1782                 pThis->cbCurInstr = off;
    1783                 iEncoding++;
    1784             }
    1785             break;
    1786 
     1995            return Bs3Cg1EncodeNext_BS3CG1ENC_FIXED(pThis, iEncoding);
    17871996        case BS3CG1ENC_FIXED_AL_Ib:
    1788             if (iEncoding == 0)
    1789             {
    1790                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1791                 pThis->aOperands[1].off = (uint8_t)off;
    1792                 pThis->abCurInstr[off++] = 0xff;
    1793                 pThis->cbCurInstr = off;
    1794                 iEncoding++;
    1795             }
    1796             break;
    1797 
     1997            return Bs3Cg1EncodeNext_BS3CG1ENC_FIXED_AL_Ib(pThis, iEncoding);
    17981998        case BS3CG1ENC_FIXED_rAX_Iz:
    1799             if (iEncoding == 0)
    1800             {
    1801                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 0));
    1802                 pThis->aOperands[1].off = (uint8_t)off;
    1803                 if (BS3_MODE_IS_16BIT_CODE(pThis->bMode))
    1804                 {
    1805                     *(uint16_t *)&pThis->abCurInstr[off] = UINT16_MAX;
    1806                     off += 2;
    1807                     pThis->aOperands[0].cbOp = 2;
    1808                     pThis->aOperands[1].cbOp = 2;
    1809                     pThis->cbOperand         = 2;
    1810                 }
    1811                 else
    1812                 {
    1813                     *(uint32_t *)&pThis->abCurInstr[off] = UINT32_MAX;
    1814                     off += 4;
    1815                     pThis->aOperands[0].cbOp = 4;
    1816                     pThis->aOperands[1].cbOp = 4;
    1817                     pThis->cbOperand         = 4;
    1818                 }
    1819             }
    1820             else if (iEncoding == 1 && (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
    1821             {
    1822                 pThis->abCurInstr[0] = P_OZ;
    1823                 off = Bs3Cg1InsertOpcodes(pThis, Bs3Cg1InsertReqPrefix(pThis, 1));
    1824                 pThis->aOperands[1].off = (uint8_t)off;
    1825                 if (!BS3_MODE_IS_16BIT_CODE(pThis->bMode))
    1826                 {
    1827                     *(uint16_t *)&pThis->abCurInstr[off] = UINT16_MAX;
    1828                     off += 2;
    1829                     pThis->aOperands[0].cbOp = 2;
    1830                     pThis->aOperands[1].cbOp = 2;
    1831                     pThis->cbOperand         = 2;
    1832                 }
    1833                 else
    1834                 {
    1835                     *(uint32_t *)&pThis->abCurInstr[off] = UINT32_MAX;
    1836                     off += 4;
    1837                     pThis->aOperands[0].cbOp = 4;
    1838                     pThis->aOperands[1].cbOp = 4;
    1839                     pThis->cbOperand         = 4;
    1840                 }
    1841             }
    1842             else if (iEncoding == 2 && BS3_MODE_IS_64BIT_CODE(pThis->bMode))
    1843             {
    1844                 off = Bs3Cg1InsertReqPrefix(pThis, 0);
    1845                 pThis->abCurInstr[off++] = REX_W___;
    1846                 off = Bs3Cg1InsertOpcodes(pThis, off);
    1847                 pThis->aOperands[1].off = (uint8_t)off;
    1848                 *(uint32_t *)&pThis->abCurInstr[off] = UINT32_MAX;
    1849                 off += 4;
    1850                 pThis->aOperands[0].cbOp = 8;
    1851                 pThis->aOperands[1].cbOp = 4;
    1852                 pThis->cbOperand         = 8;
    1853             }
    1854             else
    1855                 break;
    1856             pThis->cbCurInstr = off;
    1857             iEncoding++;
    1858             break;
     1999            return Bs3Cg1EncodeNext_BS3CG1ENC_FIXED_rAX_Iz(pThis, iEncoding);
    18592000
    18602001        case BS3CG1ENC_MODRM_MOD_EQ_3:
    1861             if (iEncoding < 8)
    1862             {
    1863                 off = Bs3Cg1InsertReqPrefix(pThis, 0);
    1864                 off = Bs3Cg1InsertOpcodes(pThis, off);
    1865                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, iEncoding, 1);
    1866             }
    1867             else if (iEncoding < 16)
    1868             {
    1869                 off = Bs3Cg1InsertReqPrefix(pThis, 0);
    1870                 off = Bs3Cg1InsertOpcodes(pThis, off);
    1871                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, 0, iEncoding);
    1872             }
    1873             else
    1874                 break;
    1875             pThis->cbCurInstr = off;
    1876             iEncoding++;
    1877             break;
    1878 
     2002            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MOD_EQ_3(pThis, iEncoding);
    18792003        case BS3CG1ENC_MODRM_MOD_NE_3:
    1880             if (iEncoding < 3)
    1881             {
    1882                 off = Bs3Cg1InsertReqPrefix(pThis, 0);
    1883                 off = Bs3Cg1InsertOpcodes(pThis, off);
    1884                 pThis->abCurInstr[off++] = X86_MODRM_MAKE(iEncoding, 0, 1);
    1885                 if (iEncoding >= 1)
    1886                     pThis->abCurInstr[off++] = 0x7f;
    1887                 if (iEncoding == 2)
    1888                 {
    1889                     pThis->abCurInstr[off++] = 0x5f;
    1890                     if (!BS3_MODE_IS_16BIT_CODE(pThis->bMode))
    1891                     {
    1892                         pThis->abCurInstr[off++] = 0x3f;
    1893                         pThis->abCurInstr[off++] = 0x1f;
    1894                     }
    1895                 }
    1896             }
    1897             else
    1898                 break;
    1899             pThis->cbCurInstr = off;
    1900             iEncoding++;
    1901             break;
     2004            return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_MOD_NE_3(pThis, iEncoding);
    19022005
    19032006        default:
     
    21512254 *                          input to avoid unnecessary CPUID work.
    21522255 */
    2153 static bool Bs3Cg1CpuSetupNext(PBS3CG1STATE pThis, unsigned iCpuSetup, bool *pfInvalidInstr)
     2256static bool Bs3Cg1CpuSetupNext(PBS3CG1STATE pThis, unsigned iCpuSetup, bool BS3_FAR *pfInvalidInstr)
    21542257{
    21552258    if (   (pThis->fFlags & BS3CG1INSTR_F_INVALID_64BIT)
     
    27912894 * @returns true if successful, false if not.
    27922895 * @param   pThis               The state.
    2793  * @param   fInvalidInstr       Whether this is an invalid instruction.
    27942896 * @param   bTestXcptExpected   The exception causing the test code to stop
    27952897 *                              executing.
    27962898 * @param   iEncoding           For error reporting.
    27972899 */
    2798 static bool Bs3Cg1CheckResult(PBS3CG1STATE pThis, bool fInvalidInstr, uint8_t bTestXcptExpected, unsigned iEncoding)
     2900static bool Bs3Cg1CheckResult(PBS3CG1STATE pThis, uint8_t bTestXcptExpected, unsigned iEncoding)
    27992901{
    28002902    unsigned iOperand;
     
    28052907    uint8_t bExpectedXcpt;
    28062908    uint8_t cbAdjustPc;
    2807     if (!fInvalidInstr)
     2909    if (!pThis->fInvalidEncoding)
    28082910    {
    28092911        bExpectedXcpt = pThis->bAlignmentXcpt;
     
    28382940         * Check memory output operands.
    28392941         */
    2840         if (!fInvalidInstr)
     2942        if (!pThis->fInvalidEncoding)
    28412943        {
    28422944            iOperand = pThis->cOperands;
     
    33193421         pThis->pabOpcodes  += pThis->cbOpcodes)
    33203422    {
    3321         bool     fOuterInvalidInstr = false;
    3322         unsigned iCpuSetup;
    3323         uint8_t  bTestXcptExpected = BS3_MODE_IS_PAGED(pThis->bMode) ? X86_XCPT_PF : X86_XCPT_UD;
     3423        uint8_t const   bTestXcptExpected  = BS3_MODE_IS_PAGED(pThis->bMode) ? X86_XCPT_PF : X86_XCPT_UD;
     3424        bool            fOuterInvalidInstr = false;
     3425        unsigned        iCpuSetup;
    33243426
    33253427        /*
     
    33833485                 * Encode the next instruction variation.
    33843486                 */
    3385                 bool fInnerInvalidInstr = fOuterInvalidInstr;
    3386                 iEncodingNext = Bs3Cg1EncodeNext(pThis, iEncoding, &fInnerInvalidInstr);
     3487                pThis->fInvalidEncoding = fOuterInvalidInstr;
     3488                iEncodingNext = Bs3Cg1EncodeNext(pThis, iEncoding);
    33873489                if (iEncodingNext <= iEncoding)
    33883490                    break;
    3389                 BS3CG1_DPRINTF(("\ndbg: Encoding #%u: cbCurInst=%u: %.*Rhxs  fInnerInvalidInstr=%d\n",
    3390                                 iEncoding, pThis->cbCurInstr, pThis->cbCurInstr, pThis->abCurInstr, fInnerInvalidInstr));
     3491                BS3CG1_DPRINTF(("\ndbg: Encoding #%u: cbCurInst=%u: %.*Rhxs  fInvalidEncoding=%d\n",
     3492                                iEncoding, pThis->cbCurInstr, pThis->cbCurInstr, pThis->abCurInstr, pThis->fInvalidEncoding));
    33913493
    33923494                /*
     
    34503552                                pThis->Ctx.rflags.u32 |= pThis->TrapFrame.Ctx.rflags.u32 & X86_EFL_RF;
    34513553                                pThis->bValueXcpt      = UINT8_MAX;
    3452                                 if (   fInnerInvalidInstr
     3554                                if (   pThis->fInvalidEncoding
    34533555                                    || pThis->bAlignmentXcpt != UINT8_MAX
    34543556                                    || pThis->bValueXcpt     != UINT8_MAX
     
    34573559                                                                &pThis->TrapFrame.Ctx, NULL /*pbCode*/))
    34583560                                {
    3459                                     Bs3Cg1CheckResult(pThis, fInnerInvalidInstr, bTestXcptExpected, iEncoding);
     3561                                    Bs3Cg1CheckResult(pThis, bTestXcptExpected, iEncoding);
    34603562                                }
    34613563                            }
     
    34953597    BS3CG1STATE This;
    34963598
    3497 #if 1
     3599#if 0
    34983600    /* (for debugging) */
    3499     if (bMode < BS3_MODE_PP16_32)
     3601    if (bMode < BS3_MODE_PE32)
    35003602        return BS3TESTDOMODE_SKIPPED;
    35013603#endif
     
    35103612#if 0
    35113613    /* (for debugging) */
    3512     if (bMode >= BS3_MODE_RM)
     3614    if (bMode >= BS3_MODE_LM64)
    35133615    {
    35143616        Bs3TestTerm();
Note: See TracChangeset for help on using the changeset viewer.

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