Changeset 66118 in vbox
- Timestamp:
- Mar 15, 2017 7:04:42 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-generated-1-template.c
r66116 r66118 75 75 * Debug print macro. 76 76 */ 77 #if 077 #if 1 78 78 # define BS3CG1_DPRINTF(a_ArgList) Bs3TestPrintf a_ArgList 79 # define BS3CG1_DEBUG_CTX_MOD79 //# define BS3CG1_DEBUG_CTX_MOD 80 80 #else 81 81 # define BS3CG1_DPRINTF(a_ArgList) do { } while (0) … … 87 87 * Structures and Typedefs * 88 88 *********************************************************************************************************************************/ 89 /** Operand value location. */ 90 typedef enum BS3CG1OPLOC 91 { 92 BS3CG1OPLOC_INVALID = 0, 93 BS3CG1OPLOC_CTX, 94 BS3CG1OPLOC_IMM, 95 BS3CG1OPLOC_MEM, 96 BS3CG1OPLOC_END 97 } BS3CG1OPLOC; 98 89 99 /** 90 100 * The state. … … 162 172 { 163 173 uint8_t cbOp; 164 bool fMem; 174 /** BS3CG1OPLOC_XXX. */ 175 uint8_t enmLocation; 165 176 /** The BS3CG1DST value for this field. 166 177 * Set to BS3CG1DST_INVALID if memory. */ 167 178 uint8_t idxField; 179 /** Depends on enmLocation. 180 * - BS3CG1OPLOC_IMM: offset relative to start of the instruction. 181 */ 182 uint8_t off; 168 183 } aOperands[4]; 169 184 /** @} */ … … 631 646 break; 632 647 648 case BS3CG1ENC_FIXED_AL_Ib: 649 if (iEncoding == 0) 650 { 651 off = Bs3Cg1InsertOpcodes(pThis, 0); 652 pThis->aOperands[1].off = (uint8_t)off; 653 pThis->abCurInstr[off++] = 0xff; 654 pThis->cbCurInstr = off; 655 iEncoding++; 656 } 657 break; 658 633 659 case BS3CG1ENC_MODRM_Ev_Gv: 634 660 case BS3CG1ENC_MODRM_Gv_Ev: 635 case BS3CG1ENC_FIXED_AL_Ib:636 661 case BS3CG1ENC_FIXED_rAX_Iz: 637 662 break; … … 671 696 pThis->aOperands[0].cbOp = 1; 672 697 pThis->aOperands[1].cbOp = 1; 673 pThis->aOperands[0]. fMem = false;674 pThis->aOperands[1]. fMem = false;698 pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX; 699 pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX; 675 700 break; 676 701 … … 680 705 pThis->aOperands[0].cbOp = 2; 681 706 pThis->aOperands[1].cbOp = 2; 682 pThis->aOperands[0]. fMem = false;683 pThis->aOperands[1]. fMem = false;707 pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX; 708 pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX; 684 709 break; 685 710 … … 689 714 pThis->aOperands[0].cbOp = 1; 690 715 pThis->aOperands[1].cbOp = 1; 691 pThis->aOperands[0]. fMem = false;692 pThis->aOperands[1]. fMem = false;716 pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX; 717 pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX; 693 718 break; 694 719 … … 698 723 pThis->aOperands[0].cbOp = 2; 699 724 pThis->aOperands[1].cbOp = 2; 700 pThis->aOperands[0]. fMem = false;701 pThis->aOperands[1]. fMem = false;725 pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX; 726 pThis->aOperands[1].enmLocation = BS3CG1OPLOC_CTX; 702 727 break; 703 728 704 729 case BS3CG1ENC_FIXED_AL_Ib: 730 pThis->aOperands[0].cbOp = 1; 731 pThis->aOperands[1].cbOp = 1; 732 pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX; 733 pThis->aOperands[1].enmLocation = BS3CG1OPLOC_IMM; 734 pThis->aOperands[0].idxField = BS3CG1DST_AL; 735 pThis->aOperands[1].idxField = BS3CG1DST_INVALID; 705 736 break; 737 706 738 case BS3CG1ENC_FIXED_rAX_Iz: 739 pThis->aOperands[0].cbOp = 2; 740 pThis->aOperands[1].cbOp = 2; 741 pThis->aOperands[0].enmLocation = BS3CG1OPLOC_CTX; 742 pThis->aOperands[1].enmLocation = BS3CG1OPLOC_IMM; 743 pThis->aOperands[0].idxField = BS3CG1DST_OZ_RAX; 744 pThis->aOperands[1].idxField = BS3CG1DST_INVALID; 707 745 break; 708 746 709 747 default: 710 Bs3TestFailedF("Invalid enmEncoding for instruction #%u (%.*s): %d", 711 pThis->iInstr, pThis->cchMnemonic, pThis->pchMnemonic, pThis->enmEncoding); 712 return false; 748 return Bs3TestFailedF("Invalid enmEncoding for instruction #%u (%.*s): %d", 749 pThis->iInstr, pThis->cchMnemonic, pThis->pchMnemonic, pThis->enmEncoding); 713 750 } 714 751 return true; … … 762 799 #undef CASE_PRED 763 800 default: 764 Bs3TestFailedF("Invalid selector opcode %#x!", pbCode[-1]); 765 return false; 801 return Bs3TestFailedF("Invalid selector opcode %#x!", pbCode[-1]); 766 802 } 767 803 } … … 782 818 * @param pEflCtx The context to take undefined EFLAGS from. (This is NULL 783 819 * if we're processing a input context modifier program.) 820 * @param pbInstr Points to the first instruction byte. For storing 821 * immediate operands during input context modification. 822 * NULL for output contexts. 784 823 */ 785 824 static bool Bs3Cg1RunContextModifier(PBS3CG1STATE pThis, PBS3REGCTX pCtx, PCBS3CG1TESTHDR pHdr, unsigned off, unsigned cb, 786 PCBS3REGCTX pEflCtx )825 PCBS3REGCTX pEflCtx, uint8_t BS3_FAR *pbInstr) 787 826 { 788 827 uint8_t const BS3_FAR *pbCode = (uint8_t const BS3_FAR *)(pHdr + 1) + off; … … 833 872 else if (idxField < BS3CG1DST_END) 834 873 break; 835 Bs3TestFailedF("Malformed context instruction: idxField=%d", idxField); 836 return false; 874 return Bs3TestFailedF("Malformed context instruction: idxField=%d", idxField); 837 875 } 838 876 /* fall thru */ 839 877 default: 840 Bs3TestFailed("Malformed context instruction: Destination"); 841 return false; 878 return Bs3TestFailed("Malformed context instruction: Destination"); 842 879 } 843 880 … … 862 899 /* fall thru */ 863 900 default: 864 Bs3TestFailed("Malformed context instruction: size"); 865 return false; 901 return Bs3TestFailed("Malformed context instruction: size"); 866 902 } 867 903 … … 870 906 { /* likely */ } 871 907 else 872 { 873 Bs3TestFailedF("Malformed context instruction: %u bytes value, %u bytes left", cbValue, cbLeft); 874 return false; 875 } 908 return Bs3TestFailedF("Malformed context instruction: %u bytes value, %u bytes left", cbValue, cbLeft); 876 909 877 910 /* … … 905 938 break; 906 939 } 907 Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst); 908 return false; 940 return Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst); 909 941 } 910 942 else … … 920 952 break; 921 953 } 922 Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst); 923 return false; 954 return Bs3TestFailedF("Malformed context instruction: %u bytes value (%u dst)", cbValue, cbDst); 924 955 } 925 956 … … 927 958 if (offField < sizeof(BS3REGCTX)) 928 959 PtrField.pu8 = (uint8_t BS3_FAR *)pCtx + offField; 960 /* Non-register operands: */ 961 else if ((unsigned)(idxField - BS3CG1DST_OP1) < 4U) 962 { 963 unsigned const idxOp = idxField - BS3CG1DST_OP1; 964 965 switch (pThis->aOperands[idxOp].enmLocation) 966 { 967 case BS3CG1OPLOC_IMM: 968 if (pbInstr) 969 PtrField.pu8 = &pbInstr[pThis->aOperands[idxOp].off]; 970 else 971 return Bs3TestFailedF("Immediate operand referenced in output context!"); 972 break; 973 974 default: 975 return Bs3TestFailedF("Internal error: cbDst=%u idxField=%d (%d) offField=%#x: enmLocation=%u off=%#x idxField=%u", 976 cbDst, idxField, idxOp, offField, pThis->aOperands[idxOp].enmLocation, 977 pThis->aOperands[idxOp].off, pThis->aOperands[idxOp].idxField); 978 } 979 } 929 980 /* Special field: Copying in undefined EFLAGS from the result context. */ 930 981 else if (idxField == BS3CG1DST_EFL_UNDEF) 931 982 { 932 983 if (!pEflCtx || (bOpcode & BS3CG1_CTXOP_OPERATOR_MASK) != BS3CG1_CTXOP_ASSIGN) 933 { 934 Bs3TestFailed("Invalid BS3CG1DST_EFL_UNDEF usage"); 935 return false; 936 } 984 return Bs3TestFailed("Invalid BS3CG1DST_EFL_UNDEF usage"); 937 985 PtrField.pu32 = &pCtx->rflags.u32; 938 986 uValue = (*PtrField.pu32 & ~(uint32_t)uValue) | (pEflCtx->rflags.u32 & (uint32_t)uValue); … … 943 991 //@todo } 944 992 else 945 { 946 Bs3TestFailedF("Todo implement me: cbDst=%u idxField=%d offField=%#x", cbDst, idxField, offField); 947 return false; 948 } 993 return Bs3TestFailedF("Todo implement me: cbDst=%u idxField=%d offField=%#x", cbDst, idxField, offField); 949 994 950 995 #ifdef BS3CG1_DEBUG_CTX_MOD … … 1024 1069 1025 1070 default: 1026 Bs3TestFailedF("Malformed context instruction: cbDst=%u, expected 1, 2, 4, or 8", cbDst); 1027 return false; 1071 return Bs3TestFailedF("Malformed context instruction: cbDst=%u, expected 1, 2, 4, or 8", cbDst); 1028 1072 } 1029 1073 … … 1043 1087 */ 1044 1088 else 1045 { 1046 Bs3TestFailedF("TODO: Implement me: cbDst=%u idxField=%d", cbDst, idxField); 1047 return false; 1048 } 1089 return Bs3TestFailedF("TODO: Implement me: cbDst=%u idxField=%d", cbDst, idxField); 1049 1090 1050 1091 /* … … 1087 1128 This.pbCodePg = Bs3MemGuardedTestPageAlloc(enmMemKind); 1088 1129 if (!This.pbCodePg) 1089 { 1090 Bs3TestFailedF("First Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind); 1091 return 0; 1092 } 1130 return Bs3TestFailedF("First Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind); 1093 1131 This.pbDataPg = Bs3MemGuardedTestPageAlloc(enmMemKind); 1094 1132 if (!This.pbDataPg) 1095 1133 { 1096 1134 Bs3MemGuardedTestPageFree(This.pbCodePg); 1097 Bs3TestFailedF("Second Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind); 1098 return 0; 1135 return Bs3TestFailedF("Second Bs3MemGuardedTestPageAlloc(%d) failed", enmMemKind); 1099 1136 } 1100 1137 } … … 1103 1140 This.pbCodePg = Bs3MemAlloc(enmMemKind, X86_PAGE_SIZE); 1104 1141 if (!This.pbCodePg) 1105 { 1106 Bs3TestFailedF("First Bs3MemAlloc(%d,Pg) failed", enmMemKind); 1107 return 0; 1108 } 1142 return Bs3TestFailedF("First Bs3MemAlloc(%d,Pg) failed", enmMemKind); 1109 1143 This.pbDataPg = Bs3MemAlloc(enmMemKind, X86_PAGE_SIZE); 1110 1144 if (!This.pbDataPg) 1111 1145 { 1112 1146 Bs3MemFree(This.pbCodePg, X86_PAGE_SIZE); 1113 Bs3TestFailedF("Second Bs3MemAlloc(%d,Pg) failed", enmMemKind); 1114 return 0; 1147 return Bs3TestFailedF("Second Bs3MemAlloc(%d,Pg) failed", enmMemKind); 1115 1148 } 1116 1149 } … … 1244 1277 This.Ctx.rip.u = BS3_FP_OFF(pbCode); 1245 1278 1246 if (Bs3Cg1RunContextModifier(&This, &This.Ctx, pHdr, pHdr->cbSelector, pHdr->cbInput, NULL ))1279 if (Bs3Cg1RunContextModifier(&This, &This.Ctx, pHdr, pHdr->cbSelector, pHdr->cbInput, NULL, pbCode)) 1247 1280 { 1248 1281 /* Run the instruction. */ … … 1263 1296 if (Bs3Cg1RunContextModifier(&This, &This.Ctx, pHdr, 1264 1297 pHdr->cbSelector + pHdr->cbInput, pHdr->cbOutput, 1265 &This.TrapFrame.Ctx ))1298 &This.TrapFrame.Ctx, NULL /*pbCode*/)) 1266 1299 { 1267 1300 Bs3TestCheckRegCtxEx(&This.TrapFrame.Ctx, &This.Ctx, This.cbCurInstr, 0 /*cbSpAdjust*/,
Note:
See TracChangeset
for help on using the changeset viewer.

