Changeset 66422 in vbox for trunk/src/VBox/ValidationKit/bootsectors
- Timestamp:
- Apr 4, 2017 6:18:07 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 114383
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-generated-1-template.c
r66419 r66422 229 229 * UINT8_MAX if no special exception expected. */ 230 230 uint8_t bAlignmentXcpt; 231 /** Set by the encoding method to indicating invalid encoding. */ 232 bool fInvalidEncoding; 231 233 232 234 /** The context we're working on. */ … … 1261 1263 1262 1264 1263 unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr)1265 static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(PBS3CG1STATE pThis, unsigned iEncoding) 1264 1266 { 1265 1267 unsigned off; … … 1292 1294 1293 1295 1294 unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr)1296 static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(PBS3CG1STATE pThis, unsigned iEncoding) 1295 1297 { 1296 1298 unsigned off; … … 1323 1325 1324 1326 1325 unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ev__OR__BS3CG1ENC_MODRM_Ev_Gv(PBS3CG1STATE pThis, 1326 unsigned iEncoding, bool *pfInvalidInstr) 1327 static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gv_Ev__OR__BS3CG1ENC_MODRM_Ev_Gv(PBS3CG1STATE pThis, unsigned iEncoding) 1327 1328 { 1328 1329 unsigned off; … … 1403 1404 1404 1405 1405 1406 static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr) 1406 static 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 1435 static 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 1464 static 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 1495 static 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 1524 static 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 1548 static 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 1570 static 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 1601 static 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 1644 static 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 1661 static 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 1678 static 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 1695 static unsigned Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(PBS3CG1STATE pThis, unsigned iEncoding) 1407 1696 { 1408 1697 unsigned off; … … 1431 1720 (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT, 1432 1721 4, 0, BS3CG1OPLOC_MEM_RW); 1433 *pfInvalidInstr= true;1722 pThis->fInvalidEncoding = true; 1434 1723 } 1435 1724 else if (iEncoding == 3) … … 1440 1729 (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT, 1441 1730 4, 0, BS3CG1OPLOC_MEM_RW); 1442 *pfInvalidInstr= true;1731 pThis->fInvalidEncoding = true; 1443 1732 } 1444 1733 else if (iEncoding == 4) … … 1450 1739 (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT, 1451 1740 4, 0, BS3CG1OPLOC_MEM_RW); 1452 *pfInvalidInstr= true;1741 pThis->fInvalidEncoding = true; 1453 1742 } 1454 1743 else if (iEncoding == 5) … … 1460 1749 (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT, 1461 1750 4, 0, BS3CG1OPLOC_MEM_RW); 1462 *pfInvalidInstr= true;1751 pThis->fInvalidEncoding = true; 1463 1752 } 1464 1753 else if (iEncoding == 6) … … 1470 1759 (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT, 1471 1760 4, 0, BS3CG1OPLOC_MEM_RW); 1472 *pfInvalidInstr= true;1761 pThis->fInvalidEncoding = true; 1473 1762 } 1474 1763 else if (iEncoding == 7) … … 1479 1768 (pThis->abCurInstr[off] & X86_MODRM_REG_MASK) >> X86_MODRM_REG_SHIFT, 1480 1769 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 1795 static 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 1810 static 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 1826 static 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 1891 static 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 1914 static 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 } 1481 1933 } 1482 1934 else … … 1496 1948 * each BS3CG1ENC_XXX value and should be considered 1497 1949 * internal. 1498 * @param pfInvalidInstr Pointer to variable to set when generating an1499 * invalid encoding. (Never clear this.)1500 1950 */ 1501 unsigned Bs3Cg1EncodeNext(PBS3CG1STATE pThis, unsigned iEncoding, bool *pfInvalidInstr) 1502 { 1503 unsigned off; 1504 unsigned cbOp; 1505 1951 static unsigned Bs3Cg1EncodeNext(PBS3CG1STATE pThis, unsigned iEncoding) 1952 { 1506 1953 pThis->bAlignmentXcpt = UINT8_MAX; 1507 1954 … … 1509 1956 { 1510 1957 case BS3CG1ENC_MODRM_Eb_Gb: 1511 return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(pThis, iEncoding , pfInvalidInstr);1958 return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Eb_Gb(pThis, iEncoding); 1512 1959 case BS3CG1ENC_MODRM_Gb_Eb: 1513 return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(pThis, iEncoding , pfInvalidInstr);1960 return Bs3Cg1EncodeNext_BS3CG1ENC_MODRM_Gb_Eb(pThis, iEncoding); 1514 1961 case BS3CG1ENC_MODRM_Gv_Ev: 1515 1962 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); 1517 1964 1518 1965 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); 1544 1967 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); 1570 1969 case BS3CG1ENC_MODRM_Wps_Vps: 1571 1970 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); 1599 1972 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); 1624 1974 1625 1975 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); 1646 1977 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); 1665 1979 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); 1692 1981 1693 1982 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); 1732 1984 1733 1985 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); 1747 1987 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); 1761 1989 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); 1775 1991 case BS3CG1ENC_VEX_MODRM_MdWO: 1776 return Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(pThis, iEncoding , pfInvalidInstr);1992 return Bs3Cg1EncodeNext_BS3CG1ENC_VEX_MODRM_MdWO(pThis, iEncoding); 1777 1993 1778 1994 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); 1787 1996 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); 1798 1998 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); 1859 2000 1860 2001 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); 1879 2003 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); 1902 2005 1903 2006 default: … … 2151 2254 * input to avoid unnecessary CPUID work. 2152 2255 */ 2153 static bool Bs3Cg1CpuSetupNext(PBS3CG1STATE pThis, unsigned iCpuSetup, bool *pfInvalidInstr)2256 static bool Bs3Cg1CpuSetupNext(PBS3CG1STATE pThis, unsigned iCpuSetup, bool BS3_FAR *pfInvalidInstr) 2154 2257 { 2155 2258 if ( (pThis->fFlags & BS3CG1INSTR_F_INVALID_64BIT) … … 2791 2894 * @returns true if successful, false if not. 2792 2895 * @param pThis The state. 2793 * @param fInvalidInstr Whether this is an invalid instruction.2794 2896 * @param bTestXcptExpected The exception causing the test code to stop 2795 2897 * executing. 2796 2898 * @param iEncoding For error reporting. 2797 2899 */ 2798 static bool Bs3Cg1CheckResult(PBS3CG1STATE pThis, bool fInvalidInstr,uint8_t bTestXcptExpected, unsigned iEncoding)2900 static bool Bs3Cg1CheckResult(PBS3CG1STATE pThis, uint8_t bTestXcptExpected, unsigned iEncoding) 2799 2901 { 2800 2902 unsigned iOperand; … … 2805 2907 uint8_t bExpectedXcpt; 2806 2908 uint8_t cbAdjustPc; 2807 if (! fInvalidInstr)2909 if (!pThis->fInvalidEncoding) 2808 2910 { 2809 2911 bExpectedXcpt = pThis->bAlignmentXcpt; … … 2838 2940 * Check memory output operands. 2839 2941 */ 2840 if (! fInvalidInstr)2942 if (!pThis->fInvalidEncoding) 2841 2943 { 2842 2944 iOperand = pThis->cOperands; … … 3319 3421 pThis->pabOpcodes += pThis->cbOpcodes) 3320 3422 { 3321 bool fOuterInvalidInstr = false;3322 unsigned iCpuSetup;3323 u int8_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; 3324 3426 3325 3427 /* … … 3383 3485 * Encode the next instruction variation. 3384 3486 */ 3385 bool fInnerInvalidInstr= fOuterInvalidInstr;3386 iEncodingNext = Bs3Cg1EncodeNext(pThis, iEncoding , &fInnerInvalidInstr);3487 pThis->fInvalidEncoding = fOuterInvalidInstr; 3488 iEncodingNext = Bs3Cg1EncodeNext(pThis, iEncoding); 3387 3489 if (iEncodingNext <= iEncoding) 3388 3490 break; 3389 BS3CG1_DPRINTF(("\ndbg: Encoding #%u: cbCurInst=%u: %.*Rhxs fIn nerInvalidInstr=%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)); 3391 3493 3392 3494 /* … … 3450 3552 pThis->Ctx.rflags.u32 |= pThis->TrapFrame.Ctx.rflags.u32 & X86_EFL_RF; 3451 3553 pThis->bValueXcpt = UINT8_MAX; 3452 if ( fInnerInvalidInstr3554 if ( pThis->fInvalidEncoding 3453 3555 || pThis->bAlignmentXcpt != UINT8_MAX 3454 3556 || pThis->bValueXcpt != UINT8_MAX … … 3457 3559 &pThis->TrapFrame.Ctx, NULL /*pbCode*/)) 3458 3560 { 3459 Bs3Cg1CheckResult(pThis, fInnerInvalidInstr,bTestXcptExpected, iEncoding);3561 Bs3Cg1CheckResult(pThis, bTestXcptExpected, iEncoding); 3460 3562 } 3461 3563 } … … 3495 3597 BS3CG1STATE This; 3496 3598 3497 #if 13599 #if 0 3498 3600 /* (for debugging) */ 3499 if (bMode < BS3_MODE_P P16_32)3601 if (bMode < BS3_MODE_PE32) 3500 3602 return BS3TESTDOMODE_SKIPPED; 3501 3603 #endif … … 3510 3612 #if 0 3511 3613 /* (for debugging) */ 3512 if (bMode >= BS3_MODE_ RM)3614 if (bMode >= BS3_MODE_LM64) 3513 3615 { 3514 3616 Bs3TestTerm();
Note:
See TracChangeset
for help on using the changeset viewer.