Lines Matching defs:pPatch

71 #define PATCHGEN_PROLOG_NODEF(pVM, pPatch, a_cbMaxEmit) \
74 if (RT_LIKELY((pPatch)->pPatchBlockOffset + pPatch->uCurPatchOffset + cbGivenPatchSize < pVM->patm.s.cbPatchMem)) \
75 pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \
80 (pPatch)->pPatchBlockOffset, pPatch->uCurPatchOffset, a_cbMaxEmit, \
81 (pPatch)->pPatchBlockOffset + pPatch->uCurPatchOffset + cbGivenPatchSize, pVM->patm.s.cbPatchMem)); \
86 #define PATCHGEN_PROLOG(pVM, pPatch, a_cbMaxEmit) \
89 PATCHGEN_PROLOG_NODEF(pVM, pPatch, a_cbMaxEmit)
91 #define PATCHGEN_EPILOG(pPatch, a_cbActual) \
95 pPatch->uCurPatchOffset += (a_cbActual); \
101 int patmPatchAddReloc32(PVM pVM, PPATCHINFO pPatch, uint8_t *pRelocHC, uint32_t uType,
124 bool ret = RTAvlPVInsert(&pPatch->FixupTree, &pRec->Core);
126 pPatch->nrFixups++;
131 int patmPatchAddJump(PVM pVM, PPATCHINFO pPatch, uint8_t *pJumpHC, uint32_t offset, RTRCPTR pTargetGC, uint32_t opcode)
144 bool ret = RTAvlPVInsert(&pPatch->JumpTree, &pRec->Core);
146 pPatch->nrJumpRecs++;
151 static uint32_t patmPatchGenCode(PVM pVM, PPATCHINFO pPatch, uint8_t *pPB, PCPATCHASMRECORD pAsmRecord,
250 dest = patmPatchQueryStatAddress(pVM, pPatch);
281 patmPatchAddJump(pVM, pPatch, &pPB[j-1], 1, pCallInfo->pTargetGC, OP_CALL);
416 patmPatchAddReloc32(pVM, pPatch, &pPB[j], uRelocType,
429 int32_t displ = pReturnAddrGC - (PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset + pAsmRecord->offJump - 1 + SIZEOF_NEARJUMP32);
433 patmR3AddP2GLookupRecord(pVM, pPatch, &pPB[pAsmRecord->offJump - 1], pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);
436 patmPatchAddReloc32(pVM, pPatch, &pPB[pAsmRecord->offJump], FIXUP_REL_JMPTOGUEST,
437 PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset + pAsmRecord->offJump - 1 + SIZEOF_NEARJUMP32,
471 int patmPatchGenDuplicate(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pCurInstrGC)
474 PATCHGEN_PROLOG(pVM, pPatch, cbInstrShutUpGcc);
478 PATCHGEN_EPILOG(pPatch, cbInstrShutUpGcc);
482 int patmPatchGenIret(PVM pVM, PPATCHINFO pPatch, RTRCPTR pCurInstrGC, bool fSizeOverride)
488 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
493 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo);
495 PATCHGEN_EPILOG(pPatch, size);
499 int patmPatchGenCli(PVM pVM, PPATCHINFO pPatch)
502 PATCHGEN_PROLOG(pVM, pPatch, g_patmCliRecord.cbFunction);
504 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmCliRecord, 0, false);
506 PATCHGEN_EPILOG(pPatch, size);
513 int patmPatchGenSti(PVM pVM, PPATCHINFO pPatch, RTRCPTR pCurInstrGC, RTRCPTR pNextInstrGC)
519 PATCHGEN_PROLOG(pVM, pPatch, g_patmStiRecord.cbFunction);
521 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmStiRecord, 0, false, &callInfo);
522 PATCHGEN_EPILOG(pPatch, size);
528 int patmPatchGenPopf(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t *) pReturnAddrGC, bool fSizeOverride, bool fGenJumpBack)
538 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
547 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, pReturnAddrGC, fGenJumpBack, &callInfo);
549 PATCHGEN_EPILOG(pPatch, size);
554 int patmPatchGenPushf(PVM pVM, PPATCHINFO pPatch, bool fSizeOverride)
558 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
560 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false);
562 PATCHGEN_EPILOG(pPatch, size);
566 int patmPatchGenPushCS(PVM pVM, PPATCHINFO pPatch)
569 PATCHGEN_PROLOG(pVM, pPatch, g_patmPushCSRecord.cbFunction);
570 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmPushCSRecord, 0, false);
571 PATCHGEN_EPILOG(pPatch, size);
575 int patmPatchGenLoop(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t *) pTargetGC, uint32_t opcode, bool fSizeOverride)
599 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
600 Log(("PatchGenLoop %d jump %d to %08x offrel=%d\n", opcode, pPatch->nrJumpRecs, pTargetGC, pPatchAsmRec->offRelJump));
603 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false);
612 patmPatchAddJump(pVM, pPatch, &pPB[pPatchAsmRec->offRelJump - 1], 1, pTargetGC, opcode);
614 PATCHGEN_EPILOG(pPatch, size);
618 int patmPatchGenRelJump(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t *) pTargetGC, uint32_t opcode, bool fSizeOverride)
621 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
681 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pTargetGC, PATM_LOOKUP_PATCH2GUEST);
690 return patmPatchGenLoop(pVM, pPatch, pTargetGC, opcode, fSizeOverride);
705 patmPatchAddJump(pVM, pPatch, pPB, offset, pTargetGC, opcode);
709 PATCHGEN_EPILOG(pPatch, offset);
716 int patmPatchGenCall(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTRCPTR pCurInstrGC, RTRCPTR pTargetGC, bool fIndirect)
727 rc = patmPatchGenClearPIF(pVM, pPatch, pCurInstrGC);
732 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
789 PATCHGEN_EPILOG(pPatch, offset);
793 PATCHGEN_PROLOG_NODEF(pVM, pPatch, pPatchAsmRec->cbFunction);
796 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo);
797 PATCHGEN_EPILOG(pPatch, size);
800 rc = patmPatchGenSetPIF(pVM, pPatch, pCurInstrGC);
814 * @param pPatch Patch record
818 int patmPatchGenJump(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTRCPTR pCurInstrGC)
826 rc = patmPatchGenClearPIF(pVM, pPatch, pCurInstrGC);
831 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
867 PATCHGEN_EPILOG(pPatch, offset);
870 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmJumpIndirectRecord.cbFunction);
873 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmJumpIndirectRecord, 0, false, &callInfo);
874 PATCHGEN_EPILOG(pPatch, size);
885 * @param pPatch Patch structure
890 int patmPatchGenRet(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pCurInstrGC)
895 pPatchRetInstrGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
900 if ( pPatch->pTempInfo->pPatchRetInstrGC
901 && pPatch->pTempInfo->uPatchRetParam1 == (uint32_t)pCpu->Param1.uValue) /* nr of bytes popped off the stack should be identical of course! */
906 return patmPatchGenPatchJump(pVM, pPatch, pCurInstrGC, pPatch->pTempInfo->pPatchRetInstrGC);
911 int rc = patmPatchGenCheckIF(pVM, pPatch, pCurInstrGC);
915 PATCHGEN_PROLOG(pVM, pPatch, 4);
922 PATCHGEN_EPILOG(pPatch, size);
924 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmRetRecord.cbFunction);
925 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmRetRecord, 0, false);
926 PATCHGEN_EPILOG(pPatch, size);
930 rc = patmPatchGenDuplicate(pVM, pPatch, pCpu, pCurInstrGC);
934 pPatch->pTempInfo->pPatchRetInstrGC = pPatchRetInstrGC;
935 pPatch->pTempInfo->uPatchRetParam1 = pCpu->Param1.uValue;
945 * @param pPatch Patch structure
948 int patmPatchGenGlobalFunctions(PVM pVM, PPATCHINFO pPatch)
950 pVM->patm.s.pfnHelperCallGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
951 PATCHGEN_PROLOG(pVM, pPatch, g_patmLookupAndCallRecord.cbFunction);
952 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndCallRecord, 0, false);
953 PATCHGEN_EPILOG(pPatch, size);
956 pPatch->uCurPatchOffset = RT_ALIGN_32(pPatch->uCurPatchOffset, 8);
958 pVM->patm.s.pfnHelperRetGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
959 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmRetFunctionRecord.cbFunction);
960 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmRetFunctionRecord, 0, false);
961 PATCHGEN_EPILOG(pPatch, size);
964 pPatch->uCurPatchOffset = RT_ALIGN_32(pPatch->uCurPatchOffset, 8);
966 pVM->patm.s.pfnHelperJumpGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
967 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmLookupAndJumpRecord.cbFunction);
968 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmLookupAndJumpRecord, 0, false);
969 PATCHGEN_EPILOG(pPatch, size);
972 pPatch->uCurPatchOffset = RT_ALIGN_32(pPatch->uCurPatchOffset, 8);
974 pVM->patm.s.pfnHelperIretGC = PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset;
975 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmIretFunctionRecord.cbFunction);
976 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmIretFunctionRecord, 0, false);
977 PATCHGEN_EPILOG(pPatch, size);
992 * @param pPatch Patch structure
995 int patmPatchGenIllegalInstr(PVM pVM, PPATCHINFO pPatch)
997 PATCHGEN_PROLOG(pVM, pPatch, 1);
1001 PATCHGEN_EPILOG(pPatch, 1);
1010 * @param pPatch Patch structure
1014 int patmPatchGenCheckIF(PVM pVM, PPATCHINFO pPatch, RTRCPTR pCurInstrGC)
1018 PATCHGEN_PROLOG(pVM, pPatch, g_patmCheckIFRecord.cbFunction);
1021 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);
1024 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmCheckIFRecord, pCurInstrGC, true);
1026 PATCHGEN_EPILOG(pPatch, size);
1035 * @param pPatch Patch structure
1039 int patmPatchGenSetPIF(PVM pVM, PPATCHINFO pPatch, RTRCPTR pInstrGC)
1041 PATCHGEN_PROLOG(pVM, pPatch, g_patmSetPIFRecord.cbFunction);
1044 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
1046 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false);
1047 PATCHGEN_EPILOG(pPatch, size);
1056 * @param pPatch Patch structure
1060 int patmPatchGenClearPIF(PVM pVM, PPATCHINFO pPatch, RTRCPTR pInstrGC)
1062 PATCHGEN_PROLOG(pVM, pPatch, g_patmSetPIFRecord.cbFunction);
1065 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
1067 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false);
1068 PATCHGEN_EPILOG(pPatch, size);
1078 * @param pPatch Patch structure
1081 int patmPatchGenClearInhibitIRQ(PVM pVM, PPATCHINFO pPatch, RTRCPTR pNextInstrGC)
1084 PCPATCHASMRECORD pPatchAsmRec = pPatch->flags & PATMFL_DUPLICATE_FUNCTION
1086 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
1088 Assert((pPatch->flags & (PATMFL_GENERATE_JUMPTOGUEST|PATMFL_DUPLICATE_FUNCTION)) != (PATMFL_GENERATE_JUMPTOGUEST|PATMFL_DUPLICATE_FUNCTION));
1091 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pNextInstrGC, PATM_LOOKUP_PATCH2GUEST);
1095 uint32_t size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false, &callInfo);
1097 PATCHGEN_EPILOG(pPatch, size);
1106 * @param pPatch Patch record
1111 int patmPatchGenIntEntry(PVM pVM, PPATCHINFO pPatch, RTRCPTR pIntHandlerGC)
1120 PCPATCHASMRECORD pPatchAsmRec = pPatch->flags & PATMFL_INTHANDLER_WITH_ERRORCODE
1122 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
1125 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pIntHandlerGC, PATM_LOOKUP_PATCH2GUEST);
1128 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, 0, false);
1130 PATCHGEN_EPILOG(pPatch, size);
1134 rc = patmPatchGenCli(pVM, pPatch);
1145 * @param pPatch Patch record
1148 int patmPatchGenTrapEntry(PVM pVM, PPATCHINFO pPatch, RTRCPTR pTrapHandlerGC)
1151 PCPATCHASMRECORD pPatchAsmRec = (pPatch->flags & PATMFL_TRAPHANDLER_WITH_ERRORCODE)
1156 PATCHGEN_PROLOG(pVM, pPatch, pPatchAsmRec->cbFunction);
1159 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pTrapHandlerGC, PATM_LOOKUP_PATCH2GUEST);
1162 size = patmPatchGenCode(pVM, pPatch, pPB, pPatchAsmRec, pTrapHandlerGC, true);
1163 PATCHGEN_EPILOG(pPatch, size);
1169 int patmPatchGenStats(PVM pVM, PPATCHINFO pPatch, RTRCPTR pInstrGC)
1173 PATCHGEN_PROLOG(pVM, pPatch, g_patmStatsRecord.cbFunction);
1176 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
1179 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmStatsRecord, pInstrGC, false);
1180 PATCHGEN_EPILOG(pPatch, size);
1194 int patmPatchGenMovDebug(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu)
1200 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
1233 patmPatchAddReloc32(pVM, pPatch, &pPB[2], FIXUP_ABSOLUTE);
1235 PATCHGEN_EPILOG(pPatch, 2 + sizeof(RTRCPTR));
1244 int patmPatchGenMovControl(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu)
1250 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
1299 patmPatchAddReloc32(pVM, pPatch, &pPB[2], FIXUP_ABSOLUTE);
1301 PATCHGEN_EPILOG(pPatch, 2 + sizeof(RTRCPTR));
1308 int patmPatchGenMovFromSS(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTRCPTR pCurInstrGC)
1314 Assert(pPatch->flags & PATMFL_CODE32);
1316 PATCHGEN_PROLOG(pVM, pPatch, g_patmClearPIFRecord.cbFunction + 2 + g_patmMovFromSSRecord.cbFunction + 2 + g_patmSetPIFRecord.cbFunction);
1317 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmClearPIFRecord, 0, false);
1318 PATCHGEN_EPILOG(pPatch, size);
1321 PATCHGEN_PROLOG_NODEF(pVM, pPatch, 2);
1326 PATCHGEN_EPILOG(pPatch, offset);
1329 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmMovFromSSRecord.cbFunction);
1330 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmMovFromSSRecord, 0, false);
1331 PATCHGEN_EPILOG(pPatch, size);
1334 PATCHGEN_PROLOG_NODEF(pVM, pPatch, 2);
1339 PATCHGEN_EPILOG(pPatch, offset);
1342 PATCHGEN_PROLOG_NODEF(pVM, pPatch, g_patmSetPIFRecord.cbFunction);
1343 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmSetPIFRecord, 0, false);
1344 PATCHGEN_EPILOG(pPatch, size);
1355 * @param pPatch Patch record
1359 int patmPatchGenSldtStr(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTRCPTR pCurInstrGC)
1369 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
1390 patmPatchAddReloc32(pVM, pPatch, &pPB[offset], FIXUP_ABSOLUTE);
1435 patmPatchAddReloc32(pVM, pPatch, &pPB[offset], FIXUP_ABSOLUTE);
1446 PATCHGEN_EPILOG(pPatch, offset);
1456 * @param pPatch Patch record
1460 int patmPatchGenSxDT(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTRCPTR pCurInstrGC)
1498 PATCHGEN_PROLOG(pVM, pPatch, PATCHGEN_DEF_SIZE);
1522 patmPatchAddReloc32(pVM, pPatch, &pPB[offset], FIXUP_ABSOLUTE);
1531 patmPatchAddReloc32(pVM, pPatch, &pPB[offset], FIXUP_ABSOLUTE);
1541 PATCHGEN_EPILOG(pPatch, offset);
1551 * @param pPatch Patch record
1554 int patmPatchGenCpuid(PVM pVM, PPATCHINFO pPatch, RTRCPTR pCurInstrGC)
1557 PATCHGEN_PROLOG(pVM, pPatch, g_patmCpuidRecord.cbFunction);
1559 size = patmPatchGenCode(pVM, pPatch, pPB, &g_patmCpuidRecord, 0, false);
1561 PATCHGEN_EPILOG(pPatch, size);
1571 * @param pPatch Patch record
1575 int patmPatchGenJumpToGuest(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t *) pReturnAddrGC, bool fClearInhibitIRQs)
1582 rc = patmPatchGenClearInhibitIRQ(pVM, pPatch, pReturnAddrGC);
1588 PATCHGEN_PROLOG(pVM, pPatch, PATMJumpToGuest_IF1Record.cbFunction);
1591 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);
1594 size = patmPatchGenCode(pVM, pPatch, pPB, &PATMJumpToGuest_IF1Record, pReturnAddrGC, true);
1595 PATCHGEN_EPILOG(pPatch, size);
1603 int patmPatchGenPatchJump(PVM pVM, PPATCHINFO pPatch, RTRCPTR pCurInstrGC, RCPTRTYPE(uint8_t *) pPatchAddrGC, bool fAddLookupRecord)
1609 PATCHGEN_PROLOG(pVM, pPatch, SIZEOF_NEARJUMP32);
1614 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);
1619 displ = pPatchAddrGC - (PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset + SIZEOF_NEARJUMP32);
1623 PATCHGEN_EPILOG(pPatch, SIZEOF_NEARJUMP32);