Changeset 66161 in vbox
- Timestamp:
- Mar 18, 2017 4:47:35 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 114070
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-generated-1-template.c
r66159 r66161 94 94 BS3CG1OPLOC_IMM, 95 95 BS3CG1OPLOC_MEM, 96 BS3CG1OPLOC_MEM_RW, 96 97 BS3CG1OPLOC_END 97 98 } BS3CG1OPLOC; … … 178 179 uint8_t idxField; 179 180 /** 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). 183 185 */ 184 186 uint8_t off; … … 682 684 off = Bs3Cg1InsertOpcodes(pThis, 0); 683 685 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, X86_GREG_xAX, X86_GREG_xCX); 684 pThis->cbCurInstr = off;685 686 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_AL; 686 687 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++; 689 740 break; 690 741 … … 695 746 off = Bs3Cg1InsertOpcodes(pThis, 0); 696 747 pThis->abCurInstr[off++] = X86_MODRM_MAKE(3, X86_GREG_xAX, X86_GREG_xCX); 697 pThis->cbCurInstr = off;698 748 pThis->aOperands[pThis->iRegOp].idxField = BS3CG1DST_AL; 699 749 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++; 702 802 break; 703 803 … … 1204 1304 1205 1305 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: 1206 1312 if (pbInstr) 1207 1313 PtrField.pu8 = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[idxOp].off]; 1208 1314 else 1209 return Bs3TestFailedF("TODO: Implement output memory operands!");1315 PtrField.pu8 = pThis->MemOp.ab[1]; 1210 1316 break; 1211 1317 … … 1388 1494 cbAdjustPc, 0 /*cbSpAdjust*/, 0 /*fExtraEfl*/, 1389 1495 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 } 1391 1543 1392 1544 /* … … 1452 1604 1453 1605 case BS3CG1OPLOC_MEM: 1606 case BS3CG1OPLOC_MEM_RW: 1454 1607 PtrUnion.pb = &pThis->pbDataPg[X86_PAGE_SIZE - pThis->aOperands[iOperand].off]; 1455 1608 switch (pThis->aOperands[iOperand].cbOp) … … 1463 1616 pThis->aOperands[iOperand].cbOp, *PtrUnion.pu64); 1464 1617 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 } 1465 1633 } 1466 1634 break; … … 1516 1684 Bs3MemGuardedTestPageFree(This.pbCodePg); 1517 1685 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; 1518 1694 } 1519 1695 } … … 1653 1829 { 1654 1830 /* 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; 1656 1832 1657 1833 Bs3MemCpy(&This.Ctx, &This.aInitialCtxs[iRing], sizeof(This.Ctx));
Note:
See TracChangeset
for help on using the changeset viewer.