Changeset 54688 in vbox for trunk/src/VBox
- Timestamp:
- Mar 8, 2015 11:08:04 PM (10 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/PATMA.asm
r54687 r54688 4 4 ; 5 5 6 ; Copyright (C) 2006-201 2Oracle Corporation6 ; Copyright (C) 2006-2015 Oracle Corporation 7 7 ; 8 8 ; This file is part of VirtualBox Open Source Edition (OSE), as … … 35 35 %include "PATMA.mac" 36 36 37 ;******************************************************************************* 38 ;* Defined Constants And Macros * 39 ;******************************************************************************* 37 40 %ifdef DEBUG 38 41 ; Noisy, but useful for debugging certain problems … … 41 44 %endif 42 45 43 BEGINCONST 44 46 ;; 47 ; Simple PATCHASMRECORD initializer 48 ; @param %1 The patch function name. 49 ; @param %2 The number of fixups. 50 ; 51 %macro PATCHASMRECORD_INIT 2 52 istruc PATCHASMRECORD 53 at PATCHASMRECORD.pbFunction, RTCCPTR_DEF NAME(%1) 54 at PATCHASMRECORD.offJump, DD 0 55 at PATCHASMRECORD.offRelJump, DD 0 56 at PATCHASMRECORD.offSizeOverride,DD 0 57 at PATCHASMRECORD.cbFunction, DD NAME(%1 %+ _EndProc) - NAME(%1) 58 at PATCHASMRECORD.cRelocs, DD %2 59 iend 60 %endmacro 61 62 ;; 63 ; Simple PATCHASMRECORD initializer 64 ; @param %1 The patch function name. 65 ; @param %2 Jump lable. 66 ; @param %3 The number of fixups. 67 ; 68 %macro PATCHASMRECORD_INIT_JUMP 3 69 istruc PATCHASMRECORD 70 at PATCHASMRECORD.pbFunction, RTCCPTR_DEF NAME(%1) 71 at PATCHASMRECORD.offJump, DD %2 - NAME(%1) 72 at PATCHASMRECORD.offRelJump, DD 0 73 at PATCHASMRECORD.offSizeOverride,DD 0 74 at PATCHASMRECORD.cbFunction, DD NAME(%1 %+ _EndProc) - NAME(%1) 75 at PATCHASMRECORD.cRelocs, DD %3 76 iend 77 %endmacro 78 79 ;; 80 ; Switches to the code section and aligns the function. 81 %macro BEGIN_PATCH_CODE_SECTION 0 82 BEGINCODE 83 align 32 84 %endmacro 85 86 ;; 87 ; Switches to the data section for the read-only patch descriptor data and 88 ; aligns it appropriately. 89 %macro BEGIN_PATCH_RODATA_SECTION 0 90 BEGINDATA 91 align 16 92 %endmacro 93 94 95 ; 96 ; Switch to 32-bit mode (x86). 97 ; 45 98 %ifdef RT_ARCH_AMD64 46 BITS 32 ; switch to 32-bit mode (x86). 47 %endif 99 BITS 32 100 %endif 101 48 102 49 103 %ifdef VBOX_WITH_STATISTICS … … 51 105 ; Patch call statistics 52 106 ; 107 BEGIN_PATCH_CODE_SECTION 53 108 BEGINPROC PATMStats 54 PATMStats_Start:55 109 mov dword [ss:PATM_INTERRUPTFLAG], 0 56 110 pushf … … 59 113 popf 60 114 mov dword [ss:PATM_INTERRUPTFLAG], 1 61 PATMStats_End:62 115 ENDPROC PATMStats 63 64 116 65 117 ; Patch record for statistics 66 118 GLOBALNAME g_patmStatsRecord 67 RTCCPTR_DEF PATMStats_Start 68 DD 0 69 DD 0 70 DD 0 71 DD PATMStats_End - PATMStats_Start 72 DD 4 73 DD PATM_INTERRUPTFLAG 74 DD 0 75 DD PATM_ALLPATCHCALLS 76 DD 0 77 DD PATM_PERPATCHCALLS 78 DD 0 79 DD PATM_INTERRUPTFLAG 80 DD 0 81 DD 0ffffffffh 82 %endif 119 PATCHASMRECORD_INIT PATMStats, 4 120 DD PATM_INTERRUPTFLAG, 0 121 DD PATM_ALLPATCHCALLS, 0 122 DD PATM_PERPATCHCALLS, 0 123 DD PATM_INTERRUPTFLAG, 0 124 DD 0ffffffffh, 0ffffffffh 125 %endif ; VBOX_WITH_STATISTICS 126 83 127 84 128 ; 85 129 ; Set PATM_INTERRUPTFLAG 86 130 ; 131 BEGIN_PATCH_CODE_SECTION 87 132 BEGINPROC PATMSetPIF 88 PATMSetPIF_Start: 89 mov dword [ss:PATM_INTERRUPTFLAG], 1 90 PATMSetPIF_End: 133 mov dword [ss:PATM_INTERRUPTFLAG], 1 91 134 ENDPROC PATMSetPIF 92 135 93 94 SECTION .data95 136 ; Patch record for setting PATM_INTERRUPTFLAG 137 BEGIN_PATCH_RODATA_SECTION 96 138 GLOBALNAME g_patmSetPIFRecord 97 RTCCPTR_DEF PATMSetPIF_Start 98 DD 0 99 DD 0 100 DD 0 101 DD PATMSetPIF_End - PATMSetPIF_Start 102 DD 1 103 DD PATM_INTERRUPTFLAG 104 DD 0 105 DD 0ffffffffh 106 SECTION .text 139 PATCHASMRECORD_INIT PATMSetPIF, 1 140 DD PATM_INTERRUPTFLAG, 0 141 DD 0ffffffffh, 0ffffffffh 107 142 108 143 ; 109 144 ; Clear PATM_INTERRUPTFLAG 110 145 ; 146 BEGIN_PATCH_CODE_SECTION 111 147 BEGINPROC PATMClearPIF 112 PATMClearPIF_Start:113 148 ; probe stack here as we can't recover from page faults later on 114 149 not dword [esp-64] 115 150 not dword [esp-64] 116 151 mov dword [ss:PATM_INTERRUPTFLAG], 0 117 PATMClearPIF_End:118 152 ENDPROC PATMClearPIF 119 153 120 121 SECTION .data122 154 ; Patch record for clearing PATM_INTERRUPTFLAG 155 BEGIN_PATCH_RODATA_SECTION 123 156 GLOBALNAME g_patmClearPIFRecord 124 RTCCPTR_DEF PATMClearPIF_Start 125 DD 0 126 DD 0 127 DD 0 128 DD PATMClearPIF_End - PATMClearPIF_Start 129 DD 1 130 DD PATM_INTERRUPTFLAG 131 DD 0 132 DD 0ffffffffh 133 SECTION .text 157 PATCHASMRECORD_INIT PATMClearPIF, 1 158 DD PATM_INTERRUPTFLAG, 0 159 DD 0ffffffffh, 0ffffffffh 134 160 135 161 ; 136 162 ; Clear PATM_INHIBITIRQADDR and fault if IF=0 137 163 ; 164 BEGIN_PATCH_CODE_SECTION 138 165 BEGINPROC PATMClearInhibitIRQFaultIF0 139 PATMClearInhibitIRQFaultIF0_Start:140 166 mov dword [ss:PATM_INTERRUPTFLAG], 0 141 167 mov dword [ss:PATM_INHIBITIRQADDR], 0 … … 170 196 popf 171 197 mov dword [ss:PATM_INTERRUPTFLAG], 1 172 PATMClearInhibitIRQFaultIF0_End:173 198 ENDPROC PATMClearInhibitIRQFaultIF0 174 199 175 176 SECTION .data177 200 ; Patch record for clearing PATM_INHIBITIRQADDR 201 BEGIN_PATCH_RODATA_SECTION 178 202 GLOBALNAME g_patmClearInhibitIRQFaultIF0Record 179 RTCCPTR_DEF PATMClearInhibitIRQFaultIF0_Start 180 DD 0 181 DD 0 182 DD 0 183 DD PATMClearInhibitIRQFaultIF0_End - PATMClearInhibitIRQFaultIF0_Start 184 DD 12 185 DD PATM_INTERRUPTFLAG 186 DD 0 187 DD PATM_INHIBITIRQADDR 188 DD 0 189 DD PATM_VMFLAGS 190 DD 0 191 DD PATM_VM_FORCEDACTIONS 192 DD 0 193 DD PATM_TEMP_EAX 194 DD 0 195 DD PATM_TEMP_ECX 196 DD 0 197 DD PATM_TEMP_EDI 198 DD 0 199 DD PATM_TEMP_RESTORE_FLAGS 200 DD 0 201 DD PATM_PENDINGACTION 202 DD 0 203 DD PATM_NEXTINSTRADDR 204 DD 0 205 DD PATM_INTERRUPTFLAG 206 DD 0 207 DD PATM_INTERRUPTFLAG 208 DD 0 209 DD 0ffffffffh 210 SECTION .text 203 PATCHASMRECORD_INIT PATMClearInhibitIRQFaultIF0, 12 204 DD PATM_INTERRUPTFLAG, 0 205 DD PATM_INHIBITIRQADDR, 0 206 DD PATM_VMFLAGS, 0 207 DD PATM_VM_FORCEDACTIONS, 0 208 DD PATM_TEMP_EAX, 0 209 DD PATM_TEMP_ECX, 0 210 DD PATM_TEMP_EDI, 0 211 DD PATM_TEMP_RESTORE_FLAGS, 0 212 DD PATM_PENDINGACTION, 0 213 DD PATM_NEXTINSTRADDR, 0 214 DD PATM_INTERRUPTFLAG, 0 215 DD PATM_INTERRUPTFLAG, 0 216 DD 0ffffffffh, 0ffffffffh 217 211 218 212 219 ; 213 220 ; Clear PATM_INHIBITIRQADDR and continue if IF=0 (duplicated function only; never jump back to guest code afterwards!!) 214 221 ; 222 BEGIN_PATCH_CODE_SECTION 215 223 BEGINPROC PATMClearInhibitIRQContIF0 216 PATMClearInhibitIRQContIF0_Start:217 224 mov dword [ss:PATM_INTERRUPTFLAG], 0 218 225 mov dword [ss:PATM_INHIBITIRQADDR], 0 … … 242 249 popf 243 250 mov dword [ss:PATM_INTERRUPTFLAG], 1 244 PATMClearInhibitIRQContIF0_End:245 251 ENDPROC PATMClearInhibitIRQContIF0 246 252 247 248 SECTION .data249 253 ; Patch record for clearing PATM_INHIBITIRQADDR 254 BEGIN_PATCH_RODATA_SECTION 250 255 GLOBALNAME g_patmClearInhibitIRQContIF0Record 251 RTCCPTR_DEF PATMClearInhibitIRQContIF0_Start 252 DD 0 253 DD 0 254 DD 0 255 DD PATMClearInhibitIRQContIF0_End - PATMClearInhibitIRQContIF0_Start 256 DD 11 257 DD PATM_INTERRUPTFLAG 258 DD 0 259 DD PATM_INHIBITIRQADDR 260 DD 0 261 DD PATM_VMFLAGS 262 DD 0 263 DD PATM_VM_FORCEDACTIONS 264 DD 0 265 DD PATM_TEMP_EAX 266 DD 0 267 DD PATM_TEMP_ECX 268 DD 0 269 DD PATM_TEMP_EDI 270 DD 0 271 DD PATM_TEMP_RESTORE_FLAGS 272 DD 0 273 DD PATM_PENDINGACTION 274 DD 0 275 DD PATM_NEXTINSTRADDR 276 DD 0 277 DD PATM_INTERRUPTFLAG 278 DD 0 279 DD 0ffffffffh 280 SECTION .text 281 282 256 PATCHASMRECORD_INIT PATMClearInhibitIRQContIF0, 11 257 DD PATM_INTERRUPTFLAG, 0 258 DD PATM_INHIBITIRQADDR, 0 259 DD PATM_VMFLAGS, 0 260 DD PATM_VM_FORCEDACTIONS, 0 261 DD PATM_TEMP_EAX, 0 262 DD PATM_TEMP_ECX, 0 263 DD PATM_TEMP_EDI, 0 264 DD PATM_TEMP_RESTORE_FLAGS, 0 265 DD PATM_PENDINGACTION, 0 266 DD PATM_NEXTINSTRADDR, 0 267 DD PATM_INTERRUPTFLAG, 0 268 DD 0ffffffffh, 0ffffffffh 269 270 271 ; 272 ; 273 ; 274 BEGIN_PATCH_CODE_SECTION 283 275 BEGINPROC PATMCliReplacement 284 PATMCliStart:285 276 mov dword [ss:PATM_INTERRUPTFLAG], 0 286 277 pushf … … 303 294 PATMCliJump: 304 295 DD PATM_JUMPDELTA 305 PATMCliEnd:306 296 ENDPROC PATMCliReplacement 307 297 308 309 SECTION .data310 298 ; Patch record for 'cli' 299 BEGIN_PATCH_RODATA_SECTION 311 300 GLOBALNAME g_patmCliRecord 312 RTCCPTR_DEF PATMCliStart313 DD PATMCliJump - PATMCliStart314 DD 0315 DD 0316 DD PATMCliEnd - PATMCliStart317 301 %ifdef PATM_LOG_PATCHINSTR 318 DD4302 PATCHASMRECORD_INIT_JUMP PATMCliReplacement, PATMCliJump, 4 319 303 %else 320 DD 3 321 %endif 322 DD PATM_INTERRUPTFLAG 323 DD 0 304 PATCHASMRECORD_INIT_JUMP PATMCliReplacement, PATMCliJump, 3 305 %endif 306 DD PATM_INTERRUPTFLAG, 0 324 307 %ifdef PATM_LOG_PATCHINSTR 325 DD PATM_PENDINGACTION 326 DD 0 327 %endif 328 DD PATM_ VMFLAGS329 DD 0 330 DD PATM_INTERRUPTFLAG 331 DD 0 332 DD 0ffffffffh 333 SECTION .text 334 335 308 DD PATM_PENDINGACTION, 0 309 %endif 310 DD PATM_VMFLAGS, 0 311 DD PATM_INTERRUPTFLAG, 0 312 DD 0ffffffffh, 0ffffffffh 313 314 315 ; 316 ; 317 ; 318 BEGIN_PATCH_CODE_SECTION 336 319 BEGINPROC PATMStiReplacement 337 320 PATMStiStart: … … 355 338 ENDPROC PATMStiReplacement 356 339 357 SECTION .data358 340 ; Patch record for 'sti' 341 BEGIN_PATCH_RODATA_SECTION 359 342 GLOBALNAME g_patmStiRecord 360 343 RTCCPTR_DEF PATMStiStart … … 383 366 DD 0 384 367 DD 0ffffffffh 385 SECTION .text 368 386 369 387 370 ; … … 398 381 ; esp - EIP 399 382 ; 383 BEGIN_PATCH_CODE_SECTION 400 384 BEGINPROC PATMTrapEntry 401 385 PATMTrapEntryStart: … … 444 428 ENDPROC PATMTrapEntry 445 429 446 447 SECTION .data448 430 ; Patch record for trap gate entrypoint 431 BEGIN_PATCH_RODATA_SECTION 449 432 GLOBALNAME g_patmTrapEntryRecord 450 433 RTCCPTR_DEF PATMTrapEntryStart … … 469 452 DD 0 470 453 DD 0ffffffffh 471 SECTION .text 454 472 455 473 456 ; … … 485 468 ; esp - error code 486 469 ; 470 BEGIN_PATCH_CODE_SECTION 487 471 BEGINPROC PATMTrapEntryErrorCode 488 472 PATMTrapErrorCodeEntryStart: … … 531 515 ENDPROC PATMTrapEntryErrorCode 532 516 533 534 SECTION .data535 517 ; Patch record for trap gate entrypoint 518 BEGIN_PATCH_RODATA_SECTION 536 519 GLOBALNAME g_patmTrapEntryRecordErrorCode 537 520 RTCCPTR_DEF PATMTrapErrorCodeEntryStart … … 556 539 DD 0 557 540 DD 0ffffffffh 558 SECTION .text559 541 560 542 … … 572 554 ; esp - EIP 573 555 ; 556 BEGIN_PATCH_CODE_SECTION 574 557 BEGINPROC PATMIntEntry 575 558 PATMIntEntryStart: … … 615 598 ENDPROC PATMIntEntry 616 599 617 618 SECTION .data619 600 ; Patch record for interrupt gate entrypoint 601 BEGIN_PATCH_RODATA_SECTION 620 602 GLOBALNAME g_patmIntEntryRecord 621 603 RTCCPTR_DEF PATMIntEntryStart … … 640 622 DD 0 641 623 DD 0ffffffffh 642 SECTION .text 624 643 625 644 626 ; … … 656 638 ; esp - error code 657 639 ; 640 BEGIN_PATCH_CODE_SECTION 658 641 BEGINPROC PATMIntEntryErrorCode 659 642 PATMIntEntryErrorCodeStart: … … 699 682 ENDPROC PATMIntEntryErrorCode 700 683 701 702 SECTION .data703 684 ; Patch record for interrupt gate entrypoint 685 BEGIN_PATCH_RODATA_SECTION 704 686 GLOBALNAME g_patmIntEntryRecordErrorCode 705 687 RTCCPTR_DEF PATMIntEntryErrorCodeStart … … 724 706 DD 0 725 707 DD 0ffffffffh 726 SECTION .text 708 727 709 728 710 ; 729 711 ; 32 bits Popf replacement that faults when IF remains 0 730 712 ; 713 BEGIN_PATCH_CODE_SECTION 731 714 BEGINPROC PATMPopf32Replacement 732 715 PATMPopf32Start: … … 786 769 ENDPROC PATMPopf32Replacement 787 770 788 789 SECTION .data790 771 ; Patch record for 'popfd' 772 BEGIN_PATCH_RODATA_SECTION 791 773 GLOBALNAME g_patmPopf32Record 792 774 RTCCPTR_DEF PATMPopf32Start … … 827 809 DD 0 828 810 DD 0ffffffffh 829 SECTION .text 830 811 812 813 ; 831 814 ; no need to check the IF flag when popf isn't an exit point of a patch (e.g. function duplication) 815 ; 816 BEGIN_PATCH_CODE_SECTION 832 817 BEGINPROC PATMPopf32Replacement_NoExit 833 818 PATMPopf32_NoExitStart: … … 880 865 ENDPROC PATMPopf32Replacement_NoExit 881 866 882 883 SECTION .data884 867 ; Patch record for 'popfd' 868 BEGIN_PATCH_RODATA_SECTION 885 869 GLOBALNAME g_patmPopf32Record_NoExit 886 870 RTCCPTR_DEF PATMPopf32_NoExitStart … … 925 909 DD 0 926 910 DD 0ffffffffh 927 SECTION .text928 911 929 912 … … 931 914 ; 16 bits Popf replacement that faults when IF remains 0 932 915 ; 916 BEGIN_PATCH_CODE_SECTION 933 917 BEGINPROC PATMPopf16Replacement 934 918 PATMPopf16Start: … … 964 948 ENDPROC PATMPopf16Replacement 965 949 966 967 SECTION .data968 950 ; Patch record for 'popf' 951 BEGIN_PATCH_RODATA_SECTION 969 952 GLOBALNAME g_patmPopf16Record 970 953 RTCCPTR_DEF PATMPopf16Start … … 993 976 DD 0 994 977 DD 0ffffffffh 995 SECTION .text 978 996 979 997 980 ; 998 981 ; 16 bits Popf replacement that faults when IF remains 0 999 982 ; @todo not necessary to fault in that case (see 32 bits version) 983 ; 984 BEGIN_PATCH_CODE_SECTION 1000 985 BEGINPROC PATMPopf16Replacement_NoExit 1001 986 PATMPopf16Start_NoExit: … … 1027 1012 ENDPROC PATMPopf16Replacement_NoExit 1028 1013 1029 1030 SECTION .data1031 1014 ; Patch record for 'popf' 1015 BEGIN_PATCH_RODATA_SECTION 1032 1016 GLOBALNAME g_patmPopf16Record_NoExit 1033 1017 RTCCPTR_DEF PATMPopf16Start_NoExit … … 1056 1040 DD 0 1057 1041 DD 0ffffffffh 1058 SECTION .text 1059 1060 1042 1043 1044 ; 1045 ; 1046 ; 1047 BEGIN_PATCH_CODE_SECTION 1061 1048 BEGINPROC PATMPushf32Replacement 1062 1049 PATMPushf32Start: … … 1086 1073 ENDPROC PATMPushf32Replacement 1087 1074 1088 1089 SECTION .data1090 1075 ; Patch record for 'pushfd' 1076 BEGIN_PATCH_RODATA_SECTION 1091 1077 GLOBALNAME g_patmPushf32Record 1092 1078 RTCCPTR_DEF PATMPushf32Start … … 1111 1097 DD 0 1112 1098 DD 0ffffffffh 1113 SECTION .text 1114 1115 1099 1100 1101 ; 1102 ; 1103 ; 1104 BEGIN_PATCH_CODE_SECTION 1116 1105 BEGINPROC PATMPushf16Replacement 1117 1106 PATMPushf16Start: … … 1135 1124 ENDPROC PATMPushf16Replacement 1136 1125 1137 1138 SECTION .data1139 1126 ; Patch record for 'pushf' 1127 BEGIN_PATCH_RODATA_SECTION 1140 1128 GLOBALNAME g_patmPushf16Record 1141 1129 RTCCPTR_DEF PATMPushf16Start … … 1152 1140 DD 0 1153 1141 DD 0ffffffffh 1154 SECTION .text 1155 1156 1142 1143 1144 ; 1145 ; 1146 ; 1147 BEGIN_PATCH_CODE_SECTION 1157 1148 BEGINPROC PATMPushCSReplacement 1158 1149 PATMPushCSStart: … … 1177 1168 ENDPROC PATMPushCSReplacement 1178 1169 1179 1180 SECTION .data1181 1170 ; Patch record for 'push cs' 1171 BEGIN_PATCH_RODATA_SECTION 1182 1172 GLOBALNAME g_patmPushCSRecord 1183 1173 RTCCPTR_DEF PATMPushCSStart … … 1192 1182 DD 0 1193 1183 DD 0ffffffffh 1194 SECTION .text 1184 1195 1185 1196 1186 ;;**************************************************** … … 1225 1215 ; esp - EIP 1226 1216 ;; 1217 BEGIN_PATCH_CODE_SECTION 1227 1218 BEGINPROC PATMIretReplacement 1228 1219 PATMIretStart: … … 1392 1383 ENDPROC PATMIretReplacement 1393 1384 1394 SECTION .data1395 1385 ; Patch record for 'iretd' 1386 BEGIN_PATCH_RODATA_SECTION 1396 1387 GLOBALNAME g_patmIretRecord 1397 1388 RTCCPTR_DEF PATMIretStart … … 1460 1451 DD 0 1461 1452 DD 0ffffffffh 1462 SECTION .text 1453 1463 1454 1464 1455 ;;**************************************************** … … 1493 1484 ; esp - EIP 1494 1485 ;; 1486 BEGIN_PATCH_CODE_SECTION 1495 1487 BEGINPROC PATMIretRing1Replacement 1496 1488 PATMIretRing1Start: … … 1690 1682 ENDPROC PATMIretRing1Replacement 1691 1683 1692 SECTION .data1693 1684 ; Patch record for 'iretd' 1685 BEGIN_PATCH_RODATA_SECTION 1694 1686 GLOBALNAME g_patmIretRing1Record 1695 1687 RTCCPTR_DEF PATMIretRing1Start … … 1758 1750 DD 0 1759 1751 DD 0ffffffffh 1760 SECTION .text1761 1752 1762 1753 … … 1778 1769 ; 1779 1770 ; @note NEVER change this without bumping the SSM version 1780 align 32 1771 BEGIN_PATCH_CODE_SECTION 1781 1772 BEGINPROC PATMIretFunction 1782 1773 PATMIretFunction_Start: … … 1842 1833 ENDPROC PATMIretFunction 1843 1834 1844 SECTION .data 1835 BEGIN_PATCH_RODATA_SECTION 1845 1836 GLOBALNAME g_patmIretFunctionRecord 1846 1837 RTCCPTR_DEF PATMIretFunction_Start … … 1855 1846 DD 0 1856 1847 DD 0ffffffffh 1857 SECTION .text 1858 1859 1860 align 32 ; yasm / nasm diff - remove me! 1848 1849 1850 ; 1851 ; PATMCpuidReplacement 1852 ; 1853 BEGIN_PATCH_CODE_SECTION 1861 1854 BEGINPROC PATMCpuidReplacement 1862 1855 PATMCpuidStart: … … 1910 1903 ENDPROC PATMCpuidReplacement 1911 1904 1912 SECTION .data1913 1905 ; Patch record for 'cpuid' 1906 BEGIN_PATCH_RODATA_SECTION 1914 1907 GLOBALNAME g_patmCpuidRecord 1915 1908 istruc PATCHASMRECORD … … 1931 1924 DD PATM_INTERRUPTFLAG, 0 ; 8 1932 1925 DD 0ffffffffh, 0ffffffffh ; 9 - for sanity checks 1933 SECTION .text 1934 1935 1926 1927 1928 ; 1929 ; 1930 ; 1931 BEGIN_PATCH_CODE_SECTION 1936 1932 BEGINPROC PATMJEcxReplacement 1937 1933 PATMJEcxStart: … … 1955 1951 ENDPROC PATMJEcxReplacement 1956 1952 1957 SECTION .data1958 1953 ; Patch record for 'JEcx' 1954 BEGIN_PATCH_RODATA_SECTION 1959 1955 GLOBALNAME g_patmJEcxRecord 1960 1956 RTCCPTR_DEF PATMJEcxStart … … 1970 1966 DD PATM_INTERRUPTFLAG 1971 1967 DD 0 1972 DD 0ffffffffh 1973 SECTION .text 1974 1975 align 32; yasm / nasm diffing. remove me! 1968 DD 0ffffffffh, 0ffffffffh 1969 1970 1971 ; 1972 ; 1973 ; 1974 BEGIN_PATCH_CODE_SECTION 1976 1975 BEGINPROC PATMLoopReplacement 1977 1976 PATMLoopStart: … … 1995 1994 ENDPROC PATMLoopReplacement 1996 1995 1997 SECTION .data1998 1996 ; Patch record for 'Loop' 1997 BEGIN_PATCH_RODATA_SECTION 1999 1998 GLOBALNAME g_patmLoopRecord 2000 1999 RTCCPTR_DEF PATMLoopStart … … 2010 2009 DD PATM_INTERRUPTFLAG 2011 2010 DD 0 2012 DD 0ffffffffh 2013 SECTION .text 2014 2011 DD 0ffffffffh, 0ffffffffh 2012 2013 2014 ; 2015 ; 2016 ; 2017 BEGIN_PATCH_CODE_SECTION 2015 2018 BEGINPROC PATMLoopZReplacement 2016 2019 PATMLoopZStart: … … 2037 2040 ENDPROC PATMLoopZReplacement 2038 2041 2039 SECTION .data2040 2042 ; Patch record for 'Loopz' 2043 BEGIN_PATCH_RODATA_SECTION 2041 2044 GLOBALNAME g_patmLoopZRecord 2042 2045 RTCCPTR_DEF PATMLoopZStart … … 2052 2055 DD PATM_INTERRUPTFLAG 2053 2056 DD 0 2054 DD 0ffffffffh 2055 SECTION .text 2056 2057 2057 DD 0ffffffffh, 0ffffffffh 2058 2059 2060 ; 2061 ; 2062 ; 2063 BEGIN_PATCH_CODE_SECTION 2058 2064 BEGINPROC PATMLoopNZReplacement 2059 2065 PATMLoopNZStart: … … 2080 2086 ENDPROC PATMLoopNZReplacement 2081 2087 2082 SECTION .data2083 2088 ; Patch record for 'LoopNZ' 2089 BEGIN_PATCH_RODATA_SECTION 2084 2090 GLOBALNAME g_patmLoopNZRecord 2085 2091 RTCCPTR_DEF PATMLoopNZStart … … 2095 2101 DD PATM_INTERRUPTFLAG 2096 2102 DD 0 2097 DD 0ffffffffh 2098 SECTION .text 2099 2100 align 32 2103 DD 0ffffffffh, 0ffffffffh 2104 2105 2106 ; 2101 2107 ; Global patch function for indirect calls 2102 2108 ; Caller is responsible for clearing PATM_INTERRUPTFLAG and doing: … … 2109 2115 ; 2110 2116 ; @note NEVER change this without bumping the SSM version 2117 BEGIN_PATCH_CODE_SECTION 2111 2118 BEGINPROC PATMLookupAndCall 2112 2119 PATMLookupAndCallStart: … … 2215 2222 ENDPROC PATMLookupAndCall 2216 2223 2217 SECTION .data2218 2224 ; Patch record for indirect calls and jumps 2225 BEGIN_PATCH_RODATA_SECTION 2219 2226 GLOBALNAME g_patmLookupAndCallRecord 2220 2227 RTCCPTR_DEF PATMLookupAndCallStart … … 2250 2257 DD PATM_CALL_PATCH_TARGET_ADDR 2251 2258 DD 0 2252 DD 0ffffffffh 2253 SECTION .text 2254 2255 2256 align 32 2259 DD 0ffffffffh, 0ffffffffh 2260 2261 2262 ; 2257 2263 ; Global patch function for indirect jumps 2258 2264 ; Caller is responsible for clearing PATM_INTERRUPTFLAG and doing: … … 2263 2269 ; 2264 2270 ; @note NEVER change this without bumping the SSM version 2271 BEGIN_PATCH_CODE_SECTION 2265 2272 BEGINPROC PATMLookupAndJump 2266 2273 PATMLookupAndJumpStart: … … 2334 2341 ENDPROC PATMLookupAndJump 2335 2342 2336 SECTION .data2337 2343 ; Patch record for indirect calls and jumps 2344 BEGIN_PATCH_RODATA_SECTION 2338 2345 GLOBALNAME g_patmLookupAndJumpRecord 2339 2346 RTCCPTR_DEF PATMLookupAndJumpStart … … 2353 2360 DD PATM_TEMP_EAX 2354 2361 DD 0 2355 DD 0ffffffffh 2356 SECTION .text 2357 2358 2359 2360 2361 align 32 2362 DD 0ffffffffh, 0ffffffffh 2363 2364 2362 2365 ; Patch function for static calls 2363 2366 ; @note static calls have only one lookup slot! … … 2365 2368 ; push [pTargetGC] 2366 2369 ; 2370 BEGIN_PATCH_CODE_SECTION 2367 2371 BEGINPROC PATMCall 2368 2372 PATMCallStart: … … 2395 2399 ENDPROC PATMCall 2396 2400 2397 SECTION .data2398 2401 ; Patch record for direct calls 2402 BEGIN_PATCH_RODATA_SECTION 2399 2403 GLOBALNAME g_patmCallRecord 2400 2404 RTCCPTR_DEF PATMCallStart … … 2414 2418 DD PATM_INTERRUPTFLAG 2415 2419 DD 0 2416 DD 0ffffffffh 2417 SECTION .text 2418 2419 2420 align 32 2420 DD 0ffffffffh, 0ffffffffh 2421 2422 2421 2423 ; Patch function for indirect calls 2422 2424 ; Caller is responsible for clearing PATM_INTERRUPTFLAG and adding: 2423 2425 ; push [pTargetGC] 2424 2426 ; 2427 BEGIN_PATCH_CODE_SECTION 2425 2428 BEGINPROC PATMCallIndirect 2426 2429 PATMCallIndirectStart: … … 2453 2456 ENDPROC PATMCallIndirect 2454 2457 2455 SECTION .data2456 2458 ; Patch record for indirect calls 2459 BEGIN_PATCH_RODATA_SECTION 2457 2460 GLOBALNAME g_patmCallIndirectRecord 2458 2461 RTCCPTR_DEF PATMCallIndirectStart … … 2472 2475 DD PATM_INTERRUPTFLAG 2473 2476 DD 0 2474 DD 0ffffffffh 2475 SECTION .text 2476 2477 2478 align 32 2477 DD 0ffffffffh, 0ffffffffh 2478 2479 2480 ; 2479 2481 ; Patch function for indirect jumps 2480 2482 ; Caller is responsible for clearing PATM_INTERRUPTFLAG and adding: 2481 2483 ; push [pTargetGC] 2482 2484 ; 2485 BEGIN_PATCH_CODE_SECTION 2483 2486 BEGINPROC PATMJumpIndirect 2484 2487 PATMJumpIndirectStart: … … 2516 2519 ENDPROC PATMJumpIndirect 2517 2520 2518 SECTION .data2519 2521 ; Patch record for indirect jumps 2522 BEGIN_PATCH_RODATA_SECTION 2520 2523 GLOBALNAME g_patmJumpIndirectRecord 2521 2524 RTCCPTR_DEF PATMJumpIndirectStart … … 2535 2538 DD PATM_INTERRUPTFLAG 2536 2539 DD 0 2537 DD 0ffffffffh 2538 SECTION .text 2540 DD 0ffffffffh, 0ffffffffh 2541 2539 2542 2540 2543 ; 2541 2544 ; return from duplicated function 2542 2545 ; 2543 align 32 2546 BEGIN_PATCH_CODE_SECTION 2544 2547 BEGINPROC PATMRet 2545 2548 PATMRet_Start: … … 2583 2586 ENDPROC PATMRet 2584 2587 2585 SECTION .data 2588 BEGIN_PATCH_RODATA_SECTION 2586 2589 GLOBALNAME g_patmRetRecord 2587 2590 RTCCPTR_DEF PATMRet_Start … … 2599 2602 DD PATM_INTERRUPTFLAG 2600 2603 DD 0 2601 DD 0ffffffffh 2602 SECTION .text 2604 DD 0ffffffffh, 0ffffffffh 2605 2603 2606 2604 2607 ; … … 2619 2622 ; 2620 2623 ; @note NEVER change this without bumping the SSM version 2621 align 32 2624 BEGIN_PATCH_CODE_SECTION 2622 2625 BEGINPROC PATMRetFunction 2623 2626 PATMRetFunction_Start: … … 2750 2753 ENDPROC PATMRetFunction 2751 2754 2752 SECTION .data 2755 BEGIN_PATCH_RODATA_SECTION 2753 2756 GLOBALNAME g_patmRetFunctionRecord 2754 2757 RTCCPTR_DEF PATMRetFunction_Start … … 2784 2787 DD 0 2785 2788 %endif 2786 DD 0ffffffffh 2787 SECTION .text 2789 DD 0ffffffffh, 0ffffffffh 2788 2790 2789 2791 … … 2791 2793 ; Jump to original instruction if IF=1 2792 2794 ; 2795 BEGIN_PATCH_CODE_SECTION 2793 2796 BEGINPROC PATMCheckIF 2794 2797 PATMCheckIF_Start: … … 2827 2830 ENDPROC PATMCheckIF 2828 2831 2829 SECTION .data2830 2832 ; Patch record for call instructions 2833 BEGIN_PATCH_RODATA_SECTION 2831 2834 GLOBALNAME g_patmCheckIFRecord 2832 2835 RTCCPTR_DEF PATMCheckIF_Start … … 2854 2857 DD PATM_INTERRUPTFLAG 2855 2858 DD 0 2856 DD 0ffffffffh 2857 SECTION .text 2859 DD 0ffffffffh, 0ffffffffh 2860 2858 2861 2859 2862 ; 2860 2863 ; Jump back to guest if IF=1, else fault 2861 2864 ; 2865 BEGIN_PATCH_CODE_SECTION 2862 2866 BEGINPROC PATMJumpToGuest_IF1 2863 2867 PATMJumpToGuest_IF1_Start: … … 2883 2887 ENDPROC PATMJumpToGuest_IF1 2884 2888 2885 SECTION .data2886 2889 ; Patch record for call instructions 2890 BEGIN_PATCH_RODATA_SECTION 2887 2891 GLOBALNAME PATMJumpToGuest_IF1Record 2888 2892 RTCCPTR_DEF PATMJumpToGuest_IF1_Start … … 2900 2904 DD PATM_INTERRUPTFLAG 2901 2905 DD 0 2902 DD 0ffffffffh 2903 SECTION .text 2904 2905 2906 ; check and correct RPL of pushed ss 2906 DD 0ffffffffh, 0ffffffffh 2907 2908 2909 ; 2910 ; Check and correct RPL of pushed ss. 2911 ; 2912 BEGIN_PATCH_CODE_SECTION 2907 2913 BEGINPROC PATMMovFromSS 2908 2914 PATMMovFromSS_Start: … … 2921 2927 ENDPROC PATMMovFromSS 2922 2928 2923 SECTION .data 2929 BEGIN_PATCH_RODATA_SECTION 2924 2930 GLOBALNAME g_patmMovFromSSRecord 2925 2931 RTCCPTR_DEF PATMMovFromSS_Start … … 2929 2935 DD PATMMovFromSS_Start_End - PATMMovFromSS_Start 2930 2936 DD 0 2931 DD 0ffffffffh 2937 DD 0ffffffffh, 0ffffffffh 2932 2938 2933 2939 -
trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp
r54687 r54688 45 45 #include "PATMPatch.h" 46 46 47 /* internal structure for passing more information about call fixups to patmPatchGenCode */ 47 48 /******************************************************************************* 49 * Structures and Typedefs * 50 *******************************************************************************/ 51 /** 52 * Internal structure for passing more information about call fixups to 53 * patmPatchGenCode. 54 */ 48 55 typedef struct 49 56 { … … 54 61 } PATMCALLINFO, *PPATMCALLINFO; 55 62 56 int patmPatchAddReloc32(PVM pVM, PPATCHINFO pPatch, uint8_t *pRelocHC, uint32_t uType, RTRCPTR pSource, RTRCPTR pDest) 63 64 /******************************************************************************* 65 * Defined Constants And Macros * 66 *******************************************************************************/ 67 #define PATCHGEN_PROLOG_NODEF(pVM, pPatch) \ 68 do { \ 69 pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \ 70 if (pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem) \ 71 { \ 72 pVM->patm.s.fOutOfMemory = true; \ 73 Assert(pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem); \ 74 return VERR_NO_MEMORY; \ 75 } \ 76 } while (0) 77 78 #define PATCHGEN_PROLOG(pVM, pPatch) \ 79 uint8_t *pPB; \ 80 PATCHGEN_PROLOG_NODEF(pVM, pPatch) 81 82 #define PATCHGEN_EPILOG(pPatch, size) \ 83 do { \ 84 Assert(size <= 640); \ 85 pPatch->uCurPatchOffset += size; \ 86 } while (0) 87 88 89 90 91 int patmPatchAddReloc32(PVM pVM, PPATCHINFO pPatch, uint8_t *pRelocHC, uint32_t uType, 92 RTRCPTR pSource /*= 0*/, RTRCPTR pDest /*= 0*/) 57 93 { 58 94 PRELOCREC pRec; … … 96 132 return VINF_SUCCESS; 97 133 } 98 99 #define PATCHGEN_PROLOG_NODEF(pVM, pPatch) \100 pPB = PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset; \101 \102 if (pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem) \103 { \104 pVM->patm.s.fOutOfMemory = true; \105 Assert(pPB + 256 >= pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem); \106 return VERR_NO_MEMORY; \107 }108 109 #define PATCHGEN_PROLOG(pVM, pPatch) \110 uint8_t *pPB; \111 PATCHGEN_PROLOG_NODEF(pVM, pPatch);112 113 114 #define PATCHGEN_EPILOG(pPatch, size) \115 Assert(size <= 640); \116 pPatch->uCurPatchOffset += size;117 118 134 119 135 static uint32_t patmPatchGenCode(PVM pVM, PPATCHINFO pPatch, uint8_t *pPB, PCPATCHASMRECORD pAsmRecord, … … 226 242 227 243 case PATM_CPUID_STD_PTR: 228 /** @todo dirty hack when correcting this fixup (state restore) */229 244 dest = CPUMR3GetGuestCpuIdPatmStdRCPtr(pVM); 230 245 break; 231 246 232 247 case PATM_CPUID_EXT_PTR: 233 /** @todo dirty hack when correcting this fixup (state restore) */234 248 dest = CPUMR3GetGuestCpuIdPatmExtRCPtr(pVM); 235 249 break; 236 250 237 251 case PATM_CPUID_CENTAUR_PTR: 238 /** @todo dirty hack when correcting this fixup (state restore) */239 252 dest = CPUMR3GetGuestCpuIdPatmCentaurRCPtr(pVM); 240 253 break; 241 254 242 255 case PATM_CPUID_DEF_PTR: 243 /** @todo dirty hack when correcting this fixup (state restore) */244 256 dest = CPUMR3GetGuestCpuIdPatmDefRCPtr(pVM); 245 257 break; … … 377 389 *(uint32_t *)&pPB[pAsmRecord->offJump] = displ; 378 390 patmPatchAddReloc32(pVM, pPatch, &pPB[pAsmRecord->offJump], FIXUP_REL_JMPTOGUEST, 379 PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset + pAsmRecord->offJump - 1 + SIZEOF_NEARJUMP32,380 pReturnAddrGC);391 PATCHCODE_PTR_GC(pPatch) + pPatch->uCurPatchOffset + pAsmRecord->offJump - 1 + SIZEOF_NEARJUMP32, 392 pReturnAddrGC); 381 393 } 382 394 -
trunk/src/VBox/VMM/VMMR3/PATMSSM.cpp
r54674 r54688 1102 1102 * @returns VBox status code. 1103 1103 * @param pVM Pointer to the VM. 1104 * @param u lSSMVersion SSM version1104 * @param uVersion Saved state version. 1105 1105 * @param patmInfo Saved PATM structure 1106 1106 * @param pPatch Patch record … … 1109 1109 * @param pFixup Fixup address 1110 1110 */ 1111 static void patmCorrectFixup(PVM pVM, unsigned ulSSMVersion, PATM &patmInfo, PPATCHINFO pPatch, PRELOCREC pRec, int32_t offset, RTRCPTR *pFixup) 1111 static void patmCorrectFixup(PVM pVM, unsigned uVersion, PATM &patmInfo, PPATCHINFO pPatch, PRELOCREC pRec, 1112 int32_t offset, RTRCPTR *pFixup) 1112 1113 { 1113 1114 int32_t delta = pVM->patm.s.pPatchMemGC - patmInfo.pPatchMemGC; … … 1120 1121 break; 1121 1122 1122 if ( *pFixup >= patmInfo.pGCStateGC1123 && *pFixup < patmInfo.pGCStateGC + sizeof(PATMGCSTATE))1124 {1125 LogFlow(("Changing absolute GCState at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC));1126 *pFixup = (*pFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC;1127 }1128 else1129 if ( *pFixup >= patmInfo.pCPUMCtxGC1130 && *pFixup < patmInfo.pCPUMCtxGC + sizeof(CPUMCTX))1131 { 1132 LogFlow(("Changing absolute CPUMCTX at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC));1123 RTRCPTR const uFixup = *pFixup; 1124 if ( uFixup >= patmInfo.pGCStateGC 1125 && uFixup < patmInfo.pGCStateGC + sizeof(PATMGCSTATE)) 1126 { 1127 LogFlow(("Changing absolute GCState at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC)); 1128 *pFixup = (uFixup - patmInfo.pGCStateGC) + pVM->patm.s.pGCStateGC; 1129 } 1130 else if ( uFixup >= patmInfo.pCPUMCtxGC 1131 && uFixup < patmInfo.pCPUMCtxGC + sizeof(CPUMCTX)) 1132 { 1133 LogFlow(("Changing absolute CPUMCTX at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC)); 1133 1134 1134 1135 /* The CPUMCTX structure has completely changed, so correct the offsets too. */ 1135 if (u lSSMVersion == PATM_SAVED_STATE_VERSION_VER16)1136 if (uVersion == PATM_SAVED_STATE_VERSION_VER16) 1136 1137 { 1137 unsigned uCPUMOffset = *pFixup - patmInfo.pCPUMCtxGC;1138 unsigned offCpumCtx = uFixup - patmInfo.pCPUMCtxGC; 1138 1139 1139 1140 /* ''case RT_OFFSETOF()'' does not work as gcc refuses to use & as a constant expression. 1140 1141 * Defining RT_OFFSETOF as __builtin_offsetof for gcc would make this possible. But this 1141 1142 * function is not available in older gcc versions, at least not in gcc-3.3 */ 1142 if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr0))1143 { 1144 LogFlow(("Changing dr[0] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[0])));1143 if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr0)) 1144 { 1145 LogFlow(("Changing dr[0] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[0]))); 1145 1146 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[0]); 1146 1147 } 1147 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr1))1148 { 1149 LogFlow(("Changing dr[1] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[1])));1148 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr1)) 1149 { 1150 LogFlow(("Changing dr[1] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[1]))); 1150 1151 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[1]); 1151 1152 } 1152 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr2))1153 { 1154 LogFlow(("Changing dr[2] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[2])));1153 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr2)) 1154 { 1155 LogFlow(("Changing dr[2] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[2]))); 1155 1156 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[2]); 1156 1157 } 1157 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr3))1158 { 1159 LogFlow(("Changing dr[3] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[3])));1158 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr3)) 1159 { 1160 LogFlow(("Changing dr[3] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[3]))); 1160 1161 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[3]); 1161 1162 } 1162 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr4))1163 { 1164 LogFlow(("Changing dr[4] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[4])));1163 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr4)) 1164 { 1165 LogFlow(("Changing dr[4] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[4]))); 1165 1166 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[4]); 1166 1167 } 1167 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr5))1168 { 1169 LogFlow(("Changing dr[5] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[5])));1168 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr5)) 1169 { 1170 LogFlow(("Changing dr[5] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[5]))); 1170 1171 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[5]); 1171 1172 } 1172 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr6))1173 { 1174 LogFlow(("Changing dr[6] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[6])));1173 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr6)) 1174 { 1175 LogFlow(("Changing dr[6] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[6]))); 1175 1176 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[6]); 1176 1177 } 1177 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr7))1178 { 1179 LogFlow(("Changing dr[7] offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, dr[7])));1178 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, dr7)) 1179 { 1180 LogFlow(("Changing dr[7] offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, dr[7]))); 1180 1181 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, dr[7]); 1181 1182 } 1182 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr0))1183 { 1184 LogFlow(("Changing cr0 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr0)));1183 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr0)) 1184 { 1185 LogFlow(("Changing cr0 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr0))); 1185 1186 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr0); 1186 1187 } 1187 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr2))1188 { 1189 LogFlow(("Changing cr2 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr2)));1188 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr2)) 1189 { 1190 LogFlow(("Changing cr2 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr2))); 1190 1191 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr2); 1191 1192 } 1192 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr3))1193 { 1194 LogFlow(("Changing cr3 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr3)));1193 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr3)) 1194 { 1195 LogFlow(("Changing cr3 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr3))); 1195 1196 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr3); 1196 1197 } 1197 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr4))1198 { 1199 LogFlow(("Changing cr4 offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, cr4)));1198 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, cr4)) 1199 { 1200 LogFlow(("Changing cr4 offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, cr4))); 1200 1201 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, cr4); 1201 1202 } 1202 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, tr))1203 { 1204 LogFlow(("Changing tr offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, tr)));1203 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, tr)) 1204 { 1205 LogFlow(("Changing tr offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, tr))); 1205 1206 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, tr); 1206 1207 } 1207 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, ldtr))1208 { 1209 LogFlow(("Changing ldtr offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, ldtr)));1208 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, ldtr)) 1209 { 1210 LogFlow(("Changing ldtr offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, ldtr))); 1210 1211 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, ldtr); 1211 1212 } 1212 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.pGdt))1213 { 1214 LogFlow(("Changing pGdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, gdtr.pGdt)));1213 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.pGdt)) 1214 { 1215 LogFlow(("Changing pGdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, gdtr.pGdt))); 1215 1216 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, gdtr.pGdt); 1216 1217 } 1217 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.cbGdt))1218 { 1219 LogFlow(("Changing cbGdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, gdtr.cbGdt)));1218 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, gdtr.cbGdt)) 1219 { 1220 LogFlow(("Changing cbGdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, gdtr.cbGdt))); 1220 1221 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, gdtr.cbGdt); 1221 1222 } 1222 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.pIdt))1223 { 1224 LogFlow(("Changing pIdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, idtr.pIdt)));1223 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.pIdt)) 1224 { 1225 LogFlow(("Changing pIdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, idtr.pIdt))); 1225 1226 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, idtr.pIdt); 1226 1227 } 1227 else if ( uCPUMOffset== (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.cbIdt))1228 { 1229 LogFlow(("Changing cbIdt offset from %x to %x\n", uCPUMOffset, RT_OFFSETOF(CPUMCTX, idtr.cbIdt)));1228 else if (offCpumCtx == (unsigned)RT_OFFSETOF(CPUMCTX_VER1_6, idtr.cbIdt)) 1229 { 1230 LogFlow(("Changing cbIdt offset from %x to %x\n", offCpumCtx, RT_OFFSETOF(CPUMCTX, idtr.cbIdt))); 1230 1231 *pFixup = pVM->patm.s.pCPUMCtxGC + RT_OFFSETOF(CPUMCTX, idtr.cbIdt); 1231 1232 } 1232 1233 else 1233 AssertMsgFailed(("Unexpected CPUMCTX offset %x\n", uCPUMOffset));1234 AssertMsgFailed(("Unexpected CPUMCTX offset %x\n", offCpumCtx)); 1234 1235 } 1235 1236 else 1236 *pFixup = (*pFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC; 1237 } 1238 else 1239 if ( *pFixup >= patmInfo.pStatsGC 1240 && *pFixup < patmInfo.pStatsGC + PATM_STAT_MEMSIZE) 1241 { 1242 LogFlow(("Changing absolute Stats at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC)); 1243 *pFixup = (*pFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC; 1244 } 1245 else 1246 if ( *pFixup >= patmInfo.pGCStackGC 1247 && *pFixup < patmInfo.pGCStackGC + PATM_STACK_TOTAL_SIZE) 1248 { 1249 LogFlow(("Changing absolute Stack at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC)); 1250 *pFixup = (*pFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC; 1251 } 1252 else 1253 if ( *pFixup >= patmInfo.pPatchMemGC 1254 && *pFixup < patmInfo.pPatchMemGC + patmInfo.cbPatchMem) 1255 { 1256 LogFlow(("Changing absolute PatchMem at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, *pFixup, (*pFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC)); 1257 *pFixup = (*pFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC; 1258 } 1259 else 1237 *pFixup = (uFixup - patmInfo.pCPUMCtxGC) + pVM->patm.s.pCPUMCtxGC; 1238 } 1239 else if ( uFixup >= patmInfo.pStatsGC 1240 && uFixup < patmInfo.pStatsGC + PATM_STAT_MEMSIZE) 1241 { 1242 LogFlow(("Changing absolute Stats at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC)); 1243 *pFixup = (uFixup - patmInfo.pStatsGC) + pVM->patm.s.pStatsGC; 1244 } 1245 else if ( uFixup >= patmInfo.pGCStackGC 1246 && uFixup < patmInfo.pGCStackGC + PATM_STACK_TOTAL_SIZE) 1247 { 1248 LogFlow(("Changing absolute Stack at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC)); 1249 *pFixup = (uFixup - patmInfo.pGCStackGC) + pVM->patm.s.pGCStackGC; 1250 } 1251 else if ( uFixup >= patmInfo.pPatchMemGC 1252 && uFixup < patmInfo.pPatchMemGC + patmInfo.cbPatchMem) 1253 { 1254 LogFlow(("Changing absolute PatchMem at %RRv from %RRv to %RRv\n", patmInfo.pPatchMemGC + offset, uFixup, (uFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC)); 1255 *pFixup = (uFixup - patmInfo.pPatchMemGC) + pVM->patm.s.pPatchMemGC; 1256 } 1260 1257 /* Boldly ASSUMES: 1261 1258 * 1. That pCPUMCtxGC is in the VM structure and that its location is … … 1264 1261 * structure. 1265 1262 * 3. That the CPUM leafs are less than 8KB into the structure. */ 1266 if ( ulSSMVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK1267 && *pFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(32))1268 { 1269 LogFlow(("Changing fLocalForcedActions fixup from %RRv to %RRv\n", *pFixup, pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions)));1263 else if ( uVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK 1264 && uFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(32)) 1265 { 1266 LogFlow(("Changing fLocalForcedActions fixup from %RRv to %RRv\n", uFixup, pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions))); 1270 1267 *pFixup = pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions); 1271 1268 } 1272 else 1273 if ( ulSSMVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK 1274 && *pFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(8192)) 1269 else if ( uVersion <= PATM_SAVED_STATE_VERSION_FIXUP_HACK 1270 && uFixup - (patmInfo.pCPUMCtxGC & UINT32_C(0xffc00000)) < UINT32_C(8192)) 1275 1271 { 1276 1272 static int cCpuidFixup = 0; 1277 #ifdef LOG_ENABLED 1278 RTRCPTR oldFixup = *pFixup; 1279 #endif 1273 1280 1274 /* very dirty assumptions about the cpuid patch and cpuid ordering. */ 1281 switch (cCpuidFixup & 3)1275 switch (cCpuidFixup & 3) 1282 1276 { 1283 1277 case 0: … … 1294 1288 break; 1295 1289 } 1296 LogFlow(("Changing cpuid fixup %d from %RRv to %RRv\n", cCpuidFixup, oldFixup, *pFixup));1290 LogFlow(("Changing cpuid fixup %d from %RRv to %RRv\n", cCpuidFixup, uFixup, *pFixup)); 1297 1291 cCpuidFixup++; 1298 1292 } 1299 else 1300 if (ulSSMVersion >= PATM_SAVED_STATE_VERSION_MEM) 1301 { 1302 #ifdef LOG_ENABLED 1303 RTRCPTR oldFixup = *pFixup; 1304 #endif 1305 /* Core.Key abused to store the type of fixup */ 1293 else if (uVersion >= PATM_SAVED_STATE_VERSION_MEM) 1294 { 1295 /* Core.Key abused to store the type of fixup. */ 1306 1296 switch ((uintptr_t)pRec->Core.Key) 1307 1297 { 1308 1298 case PATM_FIXUP_CPU_FF_ACTION: 1309 1299 *pFixup = pVM->pVMRC + RT_OFFSETOF(VM, aCpus[0].fLocalForcedActions); 1310 LogFlow(("Changing cpu ff action fixup from %x to %x\n", oldFixup, *pFixup));1300 LogFlow(("Changing cpu ff action fixup from %x to %x\n", uFixup, *pFixup)); 1311 1301 break; 1312 1302 case PATM_FIXUP_CPUID_DEFAULT: 1313 1303 *pFixup = CPUMR3GetGuestCpuIdPatmDefRCPtr(pVM); 1314 LogFlow(("Changing cpuid def fixup from %x to %x\n", oldFixup, *pFixup));1304 LogFlow(("Changing cpuid def fixup from %x to %x\n", uFixup, *pFixup)); 1315 1305 break; 1316 1306 case PATM_FIXUP_CPUID_STANDARD: 1317 1307 *pFixup = CPUMR3GetGuestCpuIdPatmStdRCPtr(pVM); 1318 LogFlow(("Changing cpuid std fixup from %x to %x\n", oldFixup, *pFixup));1308 LogFlow(("Changing cpuid std fixup from %x to %x\n", uFixup, *pFixup)); 1319 1309 break; 1320 1310 case PATM_FIXUP_CPUID_EXTENDED: 1321 1311 *pFixup = CPUMR3GetGuestCpuIdPatmExtRCPtr(pVM); 1322 LogFlow(("Changing cpuid ext fixup from %x to %x\n", oldFixup, *pFixup));1312 LogFlow(("Changing cpuid ext fixup from %x to %x\n", uFixup, *pFixup)); 1323 1313 break; 1324 1314 case PATM_FIXUP_CPUID_CENTAUR: 1325 1315 *pFixup = CPUMR3GetGuestCpuIdPatmCentaurRCPtr(pVM); 1326 LogFlow(("Changing cpuid centaur fixup from %x to %x\n", oldFixup, *pFixup));1316 LogFlow(("Changing cpuid centaur fixup from %x to %x\n", uFixup, *pFixup)); 1327 1317 break; 1328 1318 default: 1329 AssertMsgFailed(("Unexpected fixup value % x\n", *pFixup));1319 AssertMsgFailed(("Unexpected fixup value %p\n", (uintptr_t)pRec->Core.Key)); 1330 1320 break; 1331 1321 } -
trunk/src/VBox/VMM/include/PATMInternal.h
r52771 r54688 153 153 } RELOCREC, *PRELOCREC; 154 154 155 /* forward decl */156 struct _PATCHINFO;157 158 155 /* Cache record for guest to host pointer conversions. */ 159 156 typedef struct … … 258 255 * Patch information. 259 256 */ 260 typedef struct _PATCHINFO257 typedef struct PATCHINFO 261 258 { 262 259 /** Current patch state (enabled, disabled, etc.). */
Note:
See TracChangeset
for help on using the changeset viewer.