Changeset 41668 in vbox for trunk/src/VBox/Disassembler
- Timestamp:
- Jun 12, 2012 1:15:51 PM (12 years ago)
- Location:
- trunk/src/VBox/Disassembler
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Disassembler/Disasm.cpp
r41658 r41668 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBox disassembler: 4 * Main 3 * VBox disassembler - Disassemble and optionally format. 5 4 */ 6 5 7 6 /* 8 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 9 8 * 10 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 20 * Header Files * 22 21 *******************************************************************************/ 23 #ifdef USING_VISUAL_STUDIO 24 # include <stdafx.h> 25 #endif 22 #define LOG_GROUP LOG_GROUP_DIS 26 23 #include <VBox/dis.h> 27 24 #include <VBox/disopcode.h> … … 40 37 * set correctly. 41 38 * @param uInstrAddr Pointer to the structure to disassemble. 42 * @param pcb Size Where to store the size of the instruction.43 * NULL isallowed.39 * @param pcbInstr Where to store the size of the instruction. NULL is 40 * allowed. 44 41 * @param pszOutput Storage for disassembled instruction 45 42 * 46 43 * @todo Define output callback. 47 44 */ 48 DISDECL(int) DISInstr(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PDISCPUSTATE pCpu, uint32_t *pcb Size, char *pszOutput)45 DISDECL(int) DISInstr(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PDISCPUSTATE pCpu, uint32_t *pcbInstr, char *pszOutput) 49 46 { 50 47 return DISInstrEx(uInstrAddr, 0, enmCpuMode, NULL, NULL, OPTYPE_ALL, 51 pCpu, pcb Size, pszOutput);48 pCpu, pcbInstr, pszOutput); 52 49 } 53 50 … … 61 58 * @param offRealAddr Offset to add to instruction address to get the real 62 59 * virtual address. 63 * @param pcb Size Where to store the size of the instruction.64 * NULL isallowed.60 * @param pcbInstr Where to store the size of the instruction. NULL is 61 * allowed. 65 62 * @param pszOutput Storage for disassembled instruction 66 63 * … … 68 65 */ 69 66 DISDECL(int) DISInstrWithOff(PDISCPUSTATE pCpu, RTUINTPTR uInstrAddr, RTUINTPTR offRealAddr, 70 u nsigned *pcbSize, char *pszOutput)67 uint32_t *pcbInstr, char *pszOutput) 71 68 { 72 69 return DISInstrEx(uInstrAddr, offRealAddr, pCpu->mode, pCpu->pfnReadBytes, pCpu->apvUserData[0], OPTYPE_ALL, 73 pCpu, pcb Size, pszOutput);70 pCpu, pcbInstr, pszOutput); 74 71 } 75 72 … … 84 81 * DISCPUSTATE::apvUserData[0]). 85 82 * @param pCpu Where to return the disassembled instruction. 86 * @param pcb Size Where to store the size of the instruction.87 * NULL isallowed.83 * @param pcbInstr Where to store the size of the instruction. NULL is 84 * allowed. 88 85 * @param pszOutput Storage for disassembled instruction 89 86 * … … 91 88 */ 92 89 DISDECL(int) DISInstrWithReader(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PFNDISREADBYTES pfnReadBytes, void *pvUser, 93 PDISCPUSTATE pCpu, uint32_t *pcb Size, char *pszOutput)90 PDISCPUSTATE pCpu, uint32_t *pcbInstr, char *pszOutput) 94 91 95 92 { 96 93 return DISInstrEx(uInstrAddr, 0, enmCpuMode, pfnReadBytes, pvUser, OPTYPE_ALL, 97 pCpu, pcb Size, pszOutput);94 pCpu, pcbInstr, pszOutput); 98 95 } 99 96 … … 106 103 * @param uInstrAddr Pointer to the structure to disassemble. 107 104 * @param u32EipOffset Offset to add to instruction address to get the real virtual address 108 * @param pcb Size Where to store the size of the instruction.109 * NULL isallowed.105 * @param pcbInstr Where to store the size of the instruction. NULL is 106 * allowed. 110 107 * @param pszOutput Storage for disassembled instruction 111 * @param uFilter Instruction type filter 108 * @param uFilter Instruction type filter. 112 109 * 113 110 * @todo Define output callback. … … 115 112 DISDECL(int) DISInstrEx(RTUINTPTR uInstrAddr, RTUINTPTR offRealAddr, DISCPUMODE enmCpuMode, 116 113 PFNDISREADBYTES pfnReadBytes, void *pvUser, uint32_t uFilter, 117 PDISCPUSTATE pCpu, uint32_t *pcb Size, char *pszOutput)114 PDISCPUSTATE pCpu, uint32_t *pcbInstr, char *pszOutput) 118 115 { 119 const OPCODE *paOneByteMap; 116 int rc = DISCoreOneExEx(uInstrAddr, enmCpuMode, uFilter, pfnReadBytes, pvUser, pCpu, pcbInstr); 117 if (RT_SUCCESS(rc) && pszOutput) 118 { 119 size_t cbOutput = 128; 120 size_t cch; 121 #if 0 122 RTUINTPTR uRealAddr = uInstrAddr + offRealAddr; 123 if (pCpu->mode == CPUMODE_64BIT || uRealAddr > UINT32_MAX) 124 cch = RTStrPrintf(pszOutput, cbOutput, "%016RTptr: ", uRealAddr); 125 else 126 cch = RTStrPrintf(pszOutput, cbOutput, "%08RX32: ", (uint32_t)uRealAddr); 127 rc = DISFormatYasmEx(pCpu, pszOutput + cch, cbOutput - cch, 128 DIS_FMT_FLAGS_BYTES_LEFT | DIS_FMT_FLAGS_BYTES_BRACKETS | DIS_FMT_FLAGS_BYTES_SPACED 129 | DIS_FMT_FLAGS_RELATIVE_BRANCH, 130 NULL /*pfnGetSymbol*/, NULL /*pvUser*/); 131 #else 132 pCpu->uInstrAddr += offRealAddr; 133 rc = DISFormatYasmEx(pCpu, pszOutput, cbOutput, 134 DIS_FMT_FLAGS_BYTES_LEFT | DIS_FMT_FLAGS_BYTES_BRACKETS | DIS_FMT_FLAGS_BYTES_SPACED 135 | DIS_FMT_FLAGS_RELATIVE_BRANCH | DIS_FMT_FLAGS_ADDR_LEFT, 136 NULL /*pfnGetSymbol*/, NULL /*pvUser*/); 137 pCpu->uInstrAddr = uInstrAddr; 138 #endif 139 cch = strlen(pszOutput); 140 if (cch < cbOutput) 141 { 142 pszOutput[cch++] = '\n'; 143 pszOutput[cch] = '\0'; 144 } 145 } 146 return rc; 147 } 120 148 121 /*122 * Initialize the CPU state.123 * Note! The RT_BZERO make ASSUMPTIONS about the placement of apvUserData.124 */125 RT_BZERO(pCpu, RT_OFFSETOF(DISCPUSTATE, apvUserData));126 127 pCpu->mode = enmCpuMode;128 if (enmCpuMode == CPUMODE_64BIT)129 {130 paOneByteMap = g_aOneByteMapX64;131 pCpu->addrmode = CPUMODE_64BIT;132 pCpu->opmode = CPUMODE_32BIT;133 }134 else135 {136 paOneByteMap = g_aOneByteMapX86;137 pCpu->addrmode = enmCpuMode;138 pCpu->opmode = enmCpuMode;139 }140 pCpu->prefix = PREFIX_NONE;141 pCpu->enmPrefixSeg = DIS_SELREG_DS;142 pCpu->uInstrAddr = uInstrAddr;143 pCpu->opaddr = uInstrAddr + offRealAddr;144 pCpu->pfnDisasmFnTable = pfnFullDisasm;145 pCpu->uFilter = uFilter;146 pCpu->rc = VINF_SUCCESS;147 pCpu->pfnReadBytes = pfnReadBytes ? pfnReadBytes : disReadBytesDefault;148 pCpu->apvUserData[0] = pvUser;149 150 /*151 * Parse the instruction byte by byte.152 */153 unsigned i = 0;154 unsigned cbPrefix = 0; /** @todo this isn't really needed, is it? Seems to be a bit too many variables tracking the same stuff here. cbInc, i, cbPrefix, idx... */155 for (;;)156 {157 uint8_t codebyte = DISReadByte(pCpu, uInstrAddr+i);158 uint8_t opcode = paOneByteMap[codebyte].opcode;159 160 /* Hardcoded assumption about OP_* values!! */161 if (opcode <= OP_LAST_PREFIX)162 {163 /* The REX prefix must precede the opcode byte(s). Any other placement is ignored. */164 if (opcode != OP_REX)165 {166 pCpu->lastprefix = opcode;167 pCpu->prefix &= ~PREFIX_REX;168 }169 170 switch (opcode)171 {172 case OP_INVALID:173 if (pcbSize)174 *pcbSize = pCpu->opsize;175 return pCpu->rc = VERR_DIS_INVALID_OPCODE;176 177 // segment override prefix byte178 case OP_SEG:179 pCpu->enmPrefixSeg = (DIS_SELREG)(paOneByteMap[codebyte].param1 - OP_PARM_REG_SEG_START);180 /* Segment prefixes for CS, DS, ES and SS are ignored in long mode. */181 if ( pCpu->mode != CPUMODE_64BIT182 || pCpu->enmPrefixSeg >= DIS_SELREG_FS)183 pCpu->prefix |= PREFIX_SEG;184 i += sizeof(uint8_t);185 cbPrefix++;186 continue; //fetch the next byte187 188 // lock prefix byte189 case OP_LOCK:190 pCpu->prefix |= PREFIX_LOCK;191 i += sizeof(uint8_t);192 cbPrefix++;193 continue; //fetch the next byte194 195 // address size override prefix byte196 case OP_ADDRSIZE:197 pCpu->prefix |= PREFIX_ADDRSIZE;198 if (pCpu->mode == CPUMODE_16BIT)199 pCpu->addrmode = CPUMODE_32BIT;200 else201 if (pCpu->mode == CPUMODE_32BIT)202 pCpu->addrmode = CPUMODE_16BIT;203 else204 pCpu->addrmode = CPUMODE_32BIT; /* 64 bits */205 206 i += sizeof(uint8_t);207 cbPrefix++;208 continue; //fetch the next byte209 210 // operand size override prefix byte211 case OP_OPSIZE:212 pCpu->prefix |= PREFIX_OPSIZE;213 if (pCpu->mode == CPUMODE_16BIT)214 pCpu->opmode = CPUMODE_32BIT;215 else216 pCpu->opmode = CPUMODE_16BIT; /* for 32 and 64 bits mode (there is no 32 bits operand size override prefix) */217 218 i += sizeof(uint8_t);219 cbPrefix++;220 continue; //fetch the next byte221 222 // rep and repne are not really prefixes, but we'll treat them as such223 case OP_REPE:224 pCpu->prefix |= PREFIX_REP;225 i += sizeof(uint8_t);226 cbPrefix += sizeof(uint8_t);227 continue; //fetch the next byte228 229 case OP_REPNE:230 pCpu->prefix |= PREFIX_REPNE;231 i += sizeof(uint8_t);232 cbPrefix += sizeof(uint8_t);233 continue; //fetch the next byte234 235 case OP_REX:236 Assert(pCpu->mode == CPUMODE_64BIT);237 /* REX prefix byte */238 pCpu->prefix |= PREFIX_REX;239 pCpu->prefix_rex = PREFIX_REX_OP_2_FLAGS(paOneByteMap[codebyte].param1);240 i += sizeof(uint8_t);241 cbPrefix += sizeof(uint8_t);242 243 if (pCpu->prefix_rex & PREFIX_REX_FLAGS_W)244 pCpu->opmode = CPUMODE_64BIT; /* overrides size prefix byte */245 continue; //fetch the next byte246 }247 }248 249 pCpu->cbPrefix = i; Assert(cbPrefix == i);250 pCpu->opcode = codebyte;251 252 unsigned idx = i;253 i += sizeof(uint8_t); //first opcode byte254 255 unsigned cbInc = ParseInstruction(uInstrAddr + i, &paOneByteMap[pCpu->opcode], pCpu);256 257 AssertMsg(pCpu->opsize == cbPrefix + cbInc + sizeof(uint8_t),258 ("%u %u\n", pCpu->opsize, cbPrefix + cbInc + sizeof(uint8_t)));259 pCpu->opsize = cbPrefix + cbInc + sizeof(uint8_t);260 261 if (pszOutput)262 disasmSprintf(pszOutput, uInstrAddr+i-1-cbPrefix, pCpu, &pCpu->param1, &pCpu->param2, &pCpu->param3);263 264 i += cbInc;265 cbPrefix = 0;266 break;267 }268 269 if (pcbSize)270 *pcbSize = i;271 272 if (pCpu->prefix & PREFIX_LOCK)273 disValidateLockSequence(pCpu);274 275 return pCpu->rc;276 }277 //*****************************************************************************278 //*****************************************************************************279 static size_t DbgBytesToString(PDISCPUSTATE pCpu, char *pszOutput, size_t offStart)280 {281 unsigned off = offStart;282 283 while (off < 40)284 pszOutput[off++] = ' ';285 pszOutput[off++] = ' ';286 pszOutput[off++] = '[';287 288 for (unsigned i = 0; i < pCpu->opsize; i++)289 off += RTStrPrintf(&pszOutput[off], 64, "%02X ", pCpu->abInstr[i]);290 291 pszOutput[off - 1] = ']'; // replaces space292 return off - offStart;293 }294 //*****************************************************************************295 //*****************************************************************************296 void disasmSprintf(char *pszOutput, RTUINTPTR uInstrAddr, PDISCPUSTATE pCpu,297 OP_PARAMETER *pParam1, OP_PARAMETER *pParam2, OP_PARAMETER *pParam3)298 {299 const char *pszFormat = pCpu->pszOpcode;300 int param = 1;301 302 303 size_t off = RTStrPrintf(pszOutput, 64, "%08RTptr: ", pCpu->opaddr);304 if (pCpu->prefix & PREFIX_LOCK)305 off += RTStrPrintf(&pszOutput[off], 64, "lock ");306 if (pCpu->prefix & PREFIX_REP)307 off += RTStrPrintf(&pszOutput[off], 64, "rep(e) ");308 else if(pCpu->prefix & PREFIX_REPNE)309 off += RTStrPrintf(&pszOutput[off], 64, "repne ");310 311 if (!strcmp("Invalid Opcode", pszFormat))312 {313 if (pCpu->opsize >= 2)314 off += RTStrPrintf(&pszOutput[off], 64, "Invalid Opcode [%02X][%02X]", pCpu->abInstr[0], pCpu->abInstr[1]);315 else316 off += RTStrPrintf(&pszOutput[off], 64, "Invalid Opcode [%02X]", pCpu->abInstr[0]);317 }318 else319 while (*pszFormat)320 {321 switch (*pszFormat)322 {323 case '%':324 switch (pszFormat[1])325 {326 case 'J': //Relative jump offset327 {328 int32_t disp;329 330 AssertMsg(param == 1, ("Invalid branch parameter nr"));331 if (pParam1->flags & USE_IMMEDIATE8_REL)332 disp = (int32_t)(char)pParam1->parval;333 else if (pParam1->flags & USE_IMMEDIATE16_REL)334 disp = (int32_t)(uint16_t)pParam1->parval;335 else if (pParam1->flags & USE_IMMEDIATE32_REL)336 disp = (int32_t)pParam1->parval;337 else if(pParam1->flags & USE_IMMEDIATE64_REL)338 /** @todo: is this correct? */339 disp = (int32_t)pParam1->parval;340 else341 {342 AssertMsgFailed(("Oops!\n"));343 return;344 }345 uint32_t addr = (uint32_t)(pCpu->opaddr + pCpu->opsize) + disp;346 off += RTStrPrintf(&pszOutput[off], 64, "[%08X]", addr);347 }348 349 //no break;350 351 case 'A': //direct address352 case 'C': //control register353 case 'D': //debug register354 case 'E': //ModRM specifies parameter355 case 'F': //Eflags register356 case 'G': //ModRM selects general register357 case 'I': //Immediate data358 case 'M': //ModRM may only refer to memory359 case 'O': //No ModRM byte360 case 'P': //ModRM byte selects MMX register361 case 'Q': //ModRM byte selects MMX register or memory address362 case 'R': //ModRM byte may only refer to a general register363 case 'S': //ModRM byte selects a segment register364 case 'T': //ModRM byte selects a test register365 case 'V': //ModRM byte selects an XMM/SSE register366 case 'W': //ModRM byte selects an XMM/SSE register or a memory address367 case 'X': //DS:SI368 case 'Y': //ES:DI369 switch(param)370 {371 case 1:372 off += RTStrPrintf(&pszOutput[off], 64, pParam1->szParam);373 break;374 case 2:375 off += RTStrPrintf(&pszOutput[off], 64, pParam2->szParam);376 break;377 case 3:378 off += RTStrPrintf(&pszOutput[off], 64, pParam3->szParam);379 break;380 }381 break;382 383 case 'e': //register based on operand size (e.g. %eAX)384 if(pCpu->opmode == CPUMODE_32BIT)385 off += RTStrPrintf(&pszOutput[off], 64, "E");386 if(pCpu->opmode == CPUMODE_64BIT)387 off += RTStrPrintf(&pszOutput[off], 64, "R");388 389 off += RTStrPrintf(&pszOutput[off], 64, "%c%c", pszFormat[2], pszFormat[3]);390 break;391 392 default:393 AssertMsgFailed(("Oops!\n"));394 break;395 }396 397 //Go to the next parameter in the format string398 while (*pszFormat && *pszFormat != ',')399 pszFormat++;400 if (*pszFormat == ',')401 pszFormat--;402 403 break;404 405 case ',':406 param++;407 //no break408 409 default:410 off += RTStrPrintf(&pszOutput[off], 64, "%c", *pszFormat);411 break;412 }413 414 if (*pszFormat)415 pszFormat++;416 }417 418 off += DbgBytesToString(pCpu, pszOutput, off);419 off += RTStrPrintf(&pszOutput[off], 64, "\n");420 }421 //*****************************************************************************422 //***************************************************************************** -
trunk/src/VBox/Disassembler/DisasmCore.cpp
r41663 r41668 21 21 *******************************************************************************/ 22 22 #define LOG_GROUP LOG_GROUP_DIS 23 #ifdef USING_VISUAL_STUDIO24 # include <stdafx.h>25 #endif26 27 23 #include <VBox/dis.h> 28 24 #include <VBox/disopcode.h> … … 35 31 #include "DisasmTables.h" 36 32 37 #if !defined(DIS_CORE_ONLY) && defined(LOG_ENABLED)38 # include <stdlib.h>39 # include <stdio.h>40 #endif41 42 33 43 34 /******************************************************************************* 44 35 * Internal Functions * 45 36 *******************************************************************************/ 46 static int disCoreParseInstr(PDISCPUSTATE pCpu, RTUINTPTR uInstrAddr, const OPCODE *paOneByteMap, 47 unsigned *pcbInstruction); 48 #if !defined(DIS_CORE_ONLY) && defined(LOG_ENABLED) 49 static void disasmAddString(char *psz, const char *pszString); 50 static void disasmAddStringF(char *psz, const char *pszFormat, ...); 51 static void disasmAddChar(char *psz, char ch); 52 # define disasmAddStringF1(psz, pszFmt, a1) disasmAddStringF(psz, pszFmt, a1) 53 # define disasmAddStringF2(psz, pszFmt, a1, a2) disasmAddStringF(psz, pszFmt, a1, a2) 54 # define disasmAddStringF3(psz, pszFmt, a1, a2, a3) disasmAddStringF(psz, pszFmt, a1, a2, a3) 55 #else 56 # define disasmAddString(psz, pszString) do {} while (0) 57 # define disasmAddStringF1(psz, pszFmt, a1) do {} while (0) 58 # define disasmAddStringF2(psz, pszFmt, a1, a2) do {} while (0) 59 # define disasmAddStringF3(psz, pszFmt, a1, a2, a3) do {} while (0) 60 # define disasmAddChar(psz, ch) do {} while (0) 61 #endif 62 63 static unsigned QueryModRM(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc = NULL); 64 static unsigned QueryModRM_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc = NULL); 65 static void UseSIB(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu); 66 static unsigned ParseSIB_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu); 37 static int disCoreParseInstr(PDISCPUSTATE pCpu, RTUINTPTR uInstrAddr, const OPCODE *paOneByteMap, uint32_t *pcbInstr); 38 39 static unsigned QueryModRM(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc = NULL); 40 static unsigned QueryModRM_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc = NULL); 41 static void UseSIB(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu); 42 static unsigned ParseSIB_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu); 43 44 static void disasmModRMReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam, int fRegAddr); 45 static void disasmModRMReg16(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam); 46 static void disasmModRMSReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam); 47 48 49 /** @name Parsers 50 * @{ */ 51 static FNDISPARSE ParseIllegal; 52 static FNDISPARSE ParseModRM; 53 static FNDISPARSE ParseModRM_SizeOnly; 54 static FNDISPARSE UseModRM; 55 static FNDISPARSE ParseImmByte; 56 static FNDISPARSE ParseImmByte_SizeOnly; 57 static FNDISPARSE ParseImmByteSX; 58 static FNDISPARSE ParseImmByteSX_SizeOnly; 59 static FNDISPARSE ParseImmBRel; 60 static FNDISPARSE ParseImmBRel_SizeOnly; 61 static FNDISPARSE ParseImmUshort; 62 static FNDISPARSE ParseImmUshort_SizeOnly; 63 static FNDISPARSE ParseImmV; 64 static FNDISPARSE ParseImmV_SizeOnly; 65 static FNDISPARSE ParseImmVRel; 66 static FNDISPARSE ParseImmVRel_SizeOnly; 67 static FNDISPARSE ParseImmZ; 68 static FNDISPARSE ParseImmZ_SizeOnly; 69 70 static FNDISPARSE ParseImmAddr; 71 static FNDISPARSE ParseImmAddr_SizeOnly; 72 static FNDISPARSE ParseImmAddrF; 73 static FNDISPARSE ParseImmAddrF_SizeOnly; 74 static FNDISPARSE ParseFixedReg; 75 static FNDISPARSE ParseImmUlong; 76 static FNDISPARSE ParseImmUlong_SizeOnly; 77 static FNDISPARSE ParseImmQword; 78 static FNDISPARSE ParseImmQword_SizeOnly; 79 80 static FNDISPARSE ParseTwoByteEsc; 81 static FNDISPARSE ParseThreeByteEsc4; 82 static FNDISPARSE ParseThreeByteEsc5; 83 static FNDISPARSE ParseImmGrpl; 84 static FNDISPARSE ParseShiftGrp2; 85 static FNDISPARSE ParseGrp3; 86 static FNDISPARSE ParseGrp4; 87 static FNDISPARSE ParseGrp5; 88 static FNDISPARSE Parse3DNow; 89 static FNDISPARSE ParseGrp6; 90 static FNDISPARSE ParseGrp7; 91 static FNDISPARSE ParseGrp8; 92 static FNDISPARSE ParseGrp9; 93 static FNDISPARSE ParseGrp10; 94 static FNDISPARSE ParseGrp12; 95 static FNDISPARSE ParseGrp13; 96 static FNDISPARSE ParseGrp14; 97 static FNDISPARSE ParseGrp15; 98 static FNDISPARSE ParseGrp16; 99 static FNDISPARSE ParseModFence; 100 static FNDISPARSE ParseNopPause; 101 102 static FNDISPARSE ParseYv; 103 static FNDISPARSE ParseYb; 104 static FNDISPARSE ParseXv; 105 static FNDISPARSE ParseXb; 106 107 /* Floating point parsing */ 108 static FNDISPARSE ParseEscFP; 109 /** @} */ 110 67 111 68 112 /******************************************************************************* 69 113 * Global Variables * 70 114 *******************************************************************************/ 71 72 PFNDISPARSE pfnFullDisasm[IDX_ParseMax] =115 /** Parser opcode table for full disassembly. */ 116 PFNDISPARSE g_apfnFullDisasm[IDX_ParseMax] = 73 117 { 74 118 ParseIllegal, … … 115 159 }; 116 160 117 PFNDISPARSE pfnCalcSize[IDX_ParseMax] = 161 /** Parser opcode table for only calculating instruction size. */ 162 PFNDISPARSE g_apfnCalcSize[IDX_ParseMax] = 118 163 { 119 164 ParseIllegal, … … 163 208 /** 164 209 * Parses one guest instruction. 165 * The result is found in pCpu and pcbInstruction. 210 * 211 * The result is found in pCpu and pcbInstr. 212 * 213 * @returns VBox status code. 214 * @param uInstrAddr Address of the instruction to decode. This is a 215 * real address in the current context that can be 216 * derefferenced. (Consider DISCoreOneWithReader if 217 * this isn't the case.) 218 * @param enmCpuMode The CPU mode. CPUMODE_32BIT, CPUMODE_16BIT, or CPUMODE_64BIT. 219 * @param pfnReadBytes Callback for reading instruction bytes. 220 * @param pvUser User argument for the instruction reader. (Ends up in apvUserData[0].) 221 * @param pCpu Pointer to cpu structure. Will be initialized. 222 * @param pcbInstr Where to store the size of the instruction. 223 * NULL is allowed. This is also stored in 224 * PDISCPUSTATE::opsize. 225 */ 226 DISDECL(int) DISCoreOne(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PDISCPUSTATE pCpu, uint32_t *pcbInstr) 227 { 228 return DISCoreOneExEx(uInstrAddr, enmCpuMode, OPTYPE_ALL, NULL /*pfnReadBytes*/, NULL /*pvUser*/, pCpu, pcbInstr); 229 } 230 231 232 /** 233 * Parses one guest instruction. 234 * 235 * The result is found in pCpu and pcbInstr. 166 236 * 167 237 * @returns VBox status code. … … 172 242 * @param pvUser User argument for the instruction reader. (Ends up in apvUserData[0].) 173 243 * @param pCpu Pointer to cpu structure. Will be initialized. 174 * @param pcbInstruction Where to store the size of the instruction. 175 * NULL is allowed. 244 * @param pcbInstr Where to store the size of the instruction. 245 * NULL is allowed. This is also stored in 246 * PDISCPUSTATE::opsize. 176 247 */ 177 DISDECL(int) DISCoreOneEx(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PFNDISREADBYTES pfnReadBytes, void *pvUser, 178 PDISCPUSTATE pCpu, unsigned *pcbInstruction) 248 DISDECL(int) DISCoreOneWithReader(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PFNDISREADBYTES pfnReadBytes, void *pvUser, 249 PDISCPUSTATE pCpu, uint32_t *pcbInstr) 250 { 251 return DISCoreOneExEx(uInstrAddr, enmCpuMode, OPTYPE_ALL, pfnReadBytes, pvUser, pCpu, pcbInstr); 252 } 253 254 255 /** 256 * Parses one guest instruction. 257 * 258 * The result is found in pCpu and pcbInstr. 259 * 260 * @returns VBox status code. 261 * @param uInstrAddr Address of the instruction to decode. What this means 262 * is left to the pfnReadBytes function. 263 * @param enmCpuMode The CPU mode. CPUMODE_32BIT, CPUMODE_16BIT, or CPUMODE_64BIT. 264 * @param pfnReadBytes Callback for reading instruction bytes. 265 * @param uFilter Instruction type filter. 266 * @param pvUser User argument for the instruction reader. (Ends up in apvUserData[0].) 267 * @param pCpu Pointer to cpu structure. Will be initialized. 268 * @param pcbInstr Where to store the size of the instruction. 269 * NULL is allowed. This is also stored in 270 * PDISCPUSTATE::opsize. 271 */ 272 DISDECL(int) DISCoreOneExEx(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, uint32_t uFilter, 273 PFNDISREADBYTES pfnReadBytes, void *pvUser, 274 PDISCPUSTATE pCpu, uint32_t *pcbInstr) 179 275 { 180 276 const OPCODE *paOneByteMap; … … 202 298 pCpu->enmPrefixSeg = DIS_SELREG_DS; 203 299 pCpu->uInstrAddr = uInstrAddr; 204 pCpu->pfnDisasmFnTable = pfnFullDisasm;205 pCpu->uFilter = OPTYPE_ALL;300 pCpu->pfnDisasmFnTable = g_apfnFullDisasm; 301 pCpu->uFilter = uFilter; 206 302 pCpu->rc = VINF_SUCCESS; 207 303 pCpu->pfnReadBytes = pfnReadBytes ? pfnReadBytes : disReadBytesDefault; 208 304 pCpu->apvUserData[0] = pvUser; 209 305 210 return disCoreParseInstr(pCpu, uInstrAddr, paOneByteMap, pcbInstruction); 211 } 306 return disCoreParseInstr(pCpu, uInstrAddr, paOneByteMap, pcbInstr); 307 } 308 212 309 213 310 /** … … 218 315 * @param paOneByteMap The one byte opcode map to use. 219 316 * @param uInstrAddr Instruction address. 220 * @param pcbInstr uctionWhere to store the instruction size. Can be NULL.317 * @param pcbInstr Where to store the instruction size. Can be NULL. 221 318 */ 222 static int disCoreParseInstr(PDISCPUSTATE pCpu, RTUINTPTR uInstrAddr, const OPCODE *paOneByteMap, u nsigned *pcbInstruction)319 static int disCoreParseInstr(PDISCPUSTATE pCpu, RTUINTPTR uInstrAddr, const OPCODE *paOneByteMap, uint32_t *pcbInstr) 223 320 { 224 321 /* … … 246 343 { 247 344 case OP_INVALID: 248 if (pcbInstr uction)249 *pcbInstr uction= iByte + 1;345 if (pcbInstr) 346 *pcbInstr = iByte + 1; 250 347 return pCpu->rc = VERR_DIS_INVALID_OPCODE; 251 348 … … 320 417 iByte += sizeof(uint8_t); //first opcode byte 321 418 322 pCpu->opaddr = uInstrAddr;323 419 pCpu->opcode = codebyte; 324 420 … … 330 426 AssertMsg(pCpu->opsize == iByte || RT_FAILURE_NP(pCpu->rc), ("%u %u\n", pCpu->opsize, iByte)); 331 427 pCpu->opsize = iByte; 332 if (pcbInstr uction)333 *pcbInstr uction= iByte;428 if (pcbInstr) 429 *pcbInstr = iByte; 334 430 335 431 if (pCpu->prefix & PREFIX_LOCK) … … 340 436 //***************************************************************************** 341 437 //***************************************************************************** 342 unsigned ParseInstruction(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, PDISCPUSTATE pCpu)438 unsigned ParseInstruction(RTUINTPTR uCodePtr, PCOPCODE pOp, PDISCPUSTATE pCpu) 343 439 { 344 440 int size = 0; 345 441 bool fFiltered = false; 346 442 347 Assert( lpszCodeBlock&& pOp && pCpu);443 Assert(uCodePtr && pOp && pCpu); 348 444 349 445 // Store the opcode format string for disasmPrintf … … 360 456 { 361 457 fFiltered = true; 362 pCpu->pfnDisasmFnTable = pfnCalcSize;458 pCpu->pfnDisasmFnTable = g_apfnCalcSize; 363 459 } 364 460 else 365 461 { 366 462 /* Not filtered out -> full disassembly */ 367 pCpu->pfnDisasmFnTable = pfnFullDisasm;463 pCpu->pfnDisasmFnTable = g_apfnFullDisasm; 368 464 } 369 465 … … 393 489 if (pOp->idxParse1 != IDX_ParseNop) 394 490 { 395 size += pCpu->pfnDisasmFnTable[pOp->idxParse1]( lpszCodeBlock, pOp, &pCpu->param1, pCpu);491 size += pCpu->pfnDisasmFnTable[pOp->idxParse1](uCodePtr, pOp, &pCpu->param1, pCpu); 396 492 if (fFiltered == false) pCpu->param1.cb = DISGetParamSize(pCpu, &pCpu->param1); 397 493 } … … 399 495 if (pOp->idxParse2 != IDX_ParseNop) 400 496 { 401 size += pCpu->pfnDisasmFnTable[pOp->idxParse2]( lpszCodeBlock+size, pOp, &pCpu->param2, pCpu);497 size += pCpu->pfnDisasmFnTable[pOp->idxParse2](uCodePtr+size, pOp, &pCpu->param2, pCpu); 402 498 if (fFiltered == false) pCpu->param2.cb = DISGetParamSize(pCpu, &pCpu->param2); 403 499 } … … 405 501 if (pOp->idxParse3 != IDX_ParseNop) 406 502 { 407 size += pCpu->pfnDisasmFnTable[pOp->idxParse3]( lpszCodeBlock+size, pOp, &pCpu->param3, pCpu);503 size += pCpu->pfnDisasmFnTable[pOp->idxParse3](uCodePtr+size, pOp, &pCpu->param3, pCpu); 408 504 if (fFiltered == false) pCpu->param3.cb = DISGetParamSize(pCpu, &pCpu->param3); 409 505 } … … 415 511 /* Floating point opcode parsing */ 416 512 //***************************************************************************** 417 unsigned ParseEscFP(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)513 unsigned ParseEscFP(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 418 514 { 419 515 int index; … … 423 519 NOREF(pOp); 424 520 425 ModRM = DISReadByte(pCpu, lpszCodeBlock);521 ModRM = DISReadByte(pCpu, uCodePtr); 426 522 427 523 index = pCpu->opcode - 0xD8; … … 446 542 */ 447 543 if ((fpop->optype & pCpu->uFilter) == 0) 448 { 449 pCpu->pfnDisasmFnTable = pfnCalcSize; 450 } 451 else 452 { 544 pCpu->pfnDisasmFnTable = g_apfnCalcSize; 545 else 453 546 /* Not filtered out -> full disassembly */ 454 pCpu->pfnDisasmFnTable = pfnFullDisasm; 455 } 547 pCpu->pfnDisasmFnTable = g_apfnFullDisasm; 456 548 457 549 /* Correct the operand size if the instruction is marked as forced or default 64 bits */ … … 472 564 473 565 if (fpop->idxParse1 != IDX_ParseNop) 474 size += pCpu->pfnDisasmFnTable[fpop->idxParse1]( lpszCodeBlock+size, (PCOPCODE)fpop, pParam, pCpu);566 size += pCpu->pfnDisasmFnTable[fpop->idxParse1](uCodePtr+size, (PCOPCODE)fpop, pParam, pCpu); 475 567 476 568 if (fpop->idxParse2 != IDX_ParseNop) 477 size += pCpu->pfnDisasmFnTable[fpop->idxParse2]( lpszCodeBlock+size, (PCOPCODE)fpop, pParam, pCpu);569 size += pCpu->pfnDisasmFnTable[fpop->idxParse2](uCodePtr+size, (PCOPCODE)fpop, pParam, pCpu); 478 570 479 571 // Store the opcode format string for disasmPrintf … … 497 589 #endif 498 590 //***************************************************************************** 499 void UseSIB(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)591 void UseSIB(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 500 592 { 501 593 unsigned scale, base, index, regtype; 502 594 const char **ppszSIBIndexReg; 503 595 const char **ppszSIBBaseReg; 504 NOREF( lpszCodeBlock); NOREF(pOp);596 NOREF(uCodePtr); NOREF(pOp); 505 597 506 598 scale = pCpu->SIB.Bits.Scale; … … 531 623 pParam->scale = (1<<scale); 532 624 } 533 534 if (base == 5 && pCpu->ModRM.Bits.Mod == 0)535 disasmAddStringF2(pParam->szParam, "%s%s", ppszSIBIndexReg[index], szSIBScale[scale]);536 else537 disasmAddStringF3(pParam->szParam, "%s+%s%s", ppszSIBBaseReg[base], ppszSIBIndexReg[index], szSIBScale[scale]);538 }539 else540 {541 if (base != 5 || pCpu->ModRM.Bits.Mod != 0)542 disasmAddStringF1(pParam->szParam, "%s", ppszSIBBaseReg[base]);543 625 } 544 626 … … 550 632 pParam->flags |= USE_DISPLACEMENT32; 551 633 pParam->uDisp.i32 = pCpu->i32SibDisp; 552 disasmAddChar(pParam->szParam, '+');553 disasmPrintDisp32(pParam);554 634 } 555 635 else … … 557 637 pParam->flags |= USE_DISPLACEMENT64; 558 638 pParam->uDisp.i64 = pCpu->i32SibDisp; 559 disasmAddChar(pParam->szParam, '+');560 disasmPrintDisp64(pParam);561 639 } 562 640 } … … 570 648 //***************************************************************************** 571 649 //***************************************************************************** 572 unsigned ParseSIB(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)650 unsigned ParseSIB(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 573 651 { 574 652 unsigned size = sizeof(uint8_t); … … 576 654 NOREF(pOp); NOREF(pParam); 577 655 578 SIB = DISReadByte(pCpu, lpszCodeBlock);579 lpszCodeBlock+= size;656 SIB = DISReadByte(pCpu, uCodePtr); 657 uCodePtr += size; 580 658 581 659 pCpu->SIB.Bits.Base = SIB_BASE(SIB); … … 596 674 { 597 675 /* Additional 32 bits displacement. No change in long mode. */ 598 pCpu->i32SibDisp = DISReadDWord(pCpu, lpszCodeBlock);676 pCpu->i32SibDisp = DISReadDWord(pCpu, uCodePtr); 599 677 size += sizeof(int32_t); 600 678 } … … 603 681 //***************************************************************************** 604 682 //***************************************************************************** 605 unsigned ParseSIB_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)683 unsigned ParseSIB_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 606 684 { 607 685 unsigned size = sizeof(uint8_t); … … 609 687 NOREF(pOp); NOREF(pParam); 610 688 611 SIB = DISReadByte(pCpu, lpszCodeBlock);612 lpszCodeBlock+= size;689 SIB = DISReadByte(pCpu, uCodePtr); 690 uCodePtr += size; 613 691 614 692 pCpu->SIB.Bits.Base = SIB_BASE(SIB); … … 637 715 // Mod Reg/Opcode R/M 638 716 //***************************************************************************** 639 unsigned UseModRM(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)717 unsigned UseModRM(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 640 718 { 641 719 int vtype = OP_PARM_VTYPE(pParam->param); … … 667 745 else 668 746 pParam->base.reg_ctrl = reg; 669 670 disasmAddStringF1(pParam->szParam, "CR%d", pParam->base.reg_ctrl);671 747 return 0; 672 748 673 749 case OP_PARM_D: //debug register 674 disasmAddStringF1(pParam->szParam, "DR%d", reg);675 750 pParam->flags |= USE_REG_DBG; 676 751 pParam->base.reg_dbg = reg; … … 679 754 case OP_PARM_P: //MMX register 680 755 reg &= 7; /* REX.R has no effect here */ 681 disasmAddStringF1(pParam->szParam, "MM%d", reg);682 756 pParam->flags |= USE_REG_MMX; 683 757 pParam->base.reg_mmx = reg; … … 692 766 case OP_PARM_T: //test register 693 767 reg &= 7; /* REX.R has no effect here */ 694 disasmAddStringF1(pParam->szParam, "TR%d", reg);695 768 pParam->flags |= USE_REG_TEST; 696 769 pParam->base.reg_test = reg; … … 704 777 705 778 case OP_PARM_V: //XMM register 706 disasmAddStringF1(pParam->szParam, "XMM%d", reg);707 779 pParam->flags |= USE_REG_XMM; 708 780 pParam->base.reg_xmm = reg; … … 724 796 { 725 797 case 0: //effective address 726 disasmGetPtrString(pCpu, pOp, pParam);727 disasmAddChar(pParam->szParam, '[');728 798 if (rm == 4) 729 799 { /* SIB byte follows ModRM */ 730 UseSIB( lpszCodeBlock, pOp, pParam, pCpu);800 UseSIB(uCodePtr, pOp, pParam, pCpu); 731 801 } 732 802 else … … 738 808 pParam->flags |= USE_DISPLACEMENT32; 739 809 pParam->uDisp.i32 = pCpu->i32SibDisp; 740 disasmPrintDisp32(pParam);741 810 } 742 811 else … … 744 813 pParam->flags |= USE_RIPDISPLACEMENT32; 745 814 pParam->uDisp.i32 = pCpu->i32SibDisp; 746 disasmAddString(pParam->szParam, "RIP+");747 disasmPrintDisp32(pParam);748 815 } 749 816 } … … 753 820 disasmModRMReg(pCpu, pOp, rm, pParam, 1); 754 821 } 755 disasmAddChar(pParam->szParam, ']');756 822 break; 757 823 758 824 case 1: //effective address + 8 bits displacement 759 disasmGetPtrString(pCpu, pOp, pParam);760 disasmAddChar(pParam->szParam, '[');761 825 if (rm == 4) {//SIB byte follows ModRM 762 UseSIB( lpszCodeBlock, pOp, pParam, pCpu);826 UseSIB(uCodePtr, pOp, pParam, pCpu); 763 827 } 764 828 else … … 769 833 pParam->uDisp.i8 = pCpu->i32SibDisp; 770 834 pParam->flags |= USE_DISPLACEMENT8; 771 772 if (pParam->uDisp.i8 != 0)773 {774 if (pParam->uDisp.i8 > 0)775 disasmAddChar(pParam->szParam, '+');776 disasmPrintDisp8(pParam);777 }778 disasmAddChar(pParam->szParam, ']');779 835 break; 780 836 781 837 case 2: //effective address + 32 bits displacement 782 disasmGetPtrString(pCpu, pOp, pParam);783 disasmAddChar(pParam->szParam, '[');784 838 if (rm == 4) {//SIB byte follows ModRM 785 UseSIB( lpszCodeBlock, pOp, pParam, pCpu);839 UseSIB(uCodePtr, pOp, pParam, pCpu); 786 840 } 787 841 else … … 792 846 pParam->uDisp.i32 = pCpu->i32SibDisp; 793 847 pParam->flags |= USE_DISPLACEMENT32; 794 795 if (pParam->uDisp.i32 != 0)796 {797 disasmAddChar(pParam->szParam, '+');798 disasmPrintDisp32(pParam);799 }800 disasmAddChar(pParam->szParam, ']');801 848 break; 802 849 … … 811 858 { 812 859 case 0: //effective address 813 disasmGetPtrString(pCpu, pOp, pParam);814 disasmAddChar(pParam->szParam, '[');815 860 if (rm == 6) 816 861 {//16 bits displacement 817 862 pParam->uDisp.i16 = pCpu->i32SibDisp; 818 863 pParam->flags |= USE_DISPLACEMENT16; 819 disasmPrintDisp16(pParam);820 864 } 821 865 else … … 824 868 disasmModRMReg16(pCpu, pOp, rm, pParam); 825 869 } 826 disasmAddChar(pParam->szParam, ']');827 870 break; 828 871 829 872 case 1: //effective address + 8 bits displacement 830 disasmGetPtrString(pCpu, pOp, pParam);831 disasmAddChar(pParam->szParam, '[');832 873 disasmModRMReg16(pCpu, pOp, rm, pParam); 833 874 pParam->uDisp.i8 = pCpu->i32SibDisp; 834 875 pParam->flags |= USE_BASE | USE_DISPLACEMENT8; 835 836 if (pParam->uDisp.i8 != 0)837 {838 if (pParam->uDisp.i8 > 0)839 disasmAddChar(pParam->szParam, '+');840 disasmPrintDisp8(pParam);841 }842 disasmAddChar(pParam->szParam, ']');843 876 break; 844 877 845 878 case 2: //effective address + 16 bits displacement 846 disasmGetPtrString(pCpu, pOp, pParam);847 disasmAddChar(pParam->szParam, '[');848 879 disasmModRMReg16(pCpu, pOp, rm, pParam); 849 880 pParam->uDisp.i16 = pCpu->i32SibDisp; 850 881 pParam->flags |= USE_BASE | USE_DISPLACEMENT16; 851 852 if (pParam->uDisp.i16 != 0)853 {854 disasmAddChar(pParam->szParam, '+');855 disasmPrintDisp16(pParam);856 }857 disasmAddChar(pParam->szParam, ']');858 882 break; 859 883 … … 868 892 // Query the size of the ModRM parameters and fetch the immediate data (if any) 869 893 //***************************************************************************** 870 unsigned QueryModRM(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc)894 unsigned QueryModRM(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc) 871 895 { 872 896 unsigned sibinc; … … 890 914 if (mod != 3 && rm == 4) 891 915 { /* SIB byte follows ModRM */ 892 *pSibInc = ParseSIB( lpszCodeBlock, pOp, pParam, pCpu);893 lpszCodeBlock+= *pSibInc;916 *pSibInc = ParseSIB(uCodePtr, pOp, pParam, pCpu); 917 uCodePtr += *pSibInc; 894 918 size += *pSibInc; 895 919 } … … 899 923 case 0: /* Effective address */ 900 924 if (rm == 5) { /* 32 bits displacement */ 901 pCpu->i32SibDisp = DISReadDWord(pCpu, lpszCodeBlock);925 pCpu->i32SibDisp = DISReadDWord(pCpu, uCodePtr); 902 926 size += sizeof(int32_t); 903 927 } … … 906 930 907 931 case 1: /* Effective address + 8 bits displacement */ 908 pCpu->i32SibDisp = (int8_t)DISReadByte(pCpu, lpszCodeBlock);932 pCpu->i32SibDisp = (int8_t)DISReadByte(pCpu, uCodePtr); 909 933 size += sizeof(char); 910 934 break; 911 935 912 936 case 2: /* Effective address + 32 bits displacement */ 913 pCpu->i32SibDisp = DISReadDWord(pCpu, lpszCodeBlock);937 pCpu->i32SibDisp = DISReadDWord(pCpu, uCodePtr); 914 938 size += sizeof(int32_t); 915 939 break; … … 926 950 case 0: /* Effective address */ 927 951 if (rm == 6) { 928 pCpu->i32SibDisp = DISReadWord(pCpu, lpszCodeBlock);952 pCpu->i32SibDisp = DISReadWord(pCpu, uCodePtr); 929 953 size += sizeof(uint16_t); 930 954 } … … 933 957 934 958 case 1: /* Effective address + 8 bits displacement */ 935 pCpu->i32SibDisp = (int8_t)DISReadByte(pCpu, lpszCodeBlock);959 pCpu->i32SibDisp = (int8_t)DISReadByte(pCpu, uCodePtr); 936 960 size += sizeof(char); 937 961 break; 938 962 939 963 case 2: /* Effective address + 32 bits displacement */ 940 pCpu->i32SibDisp = (int16_t)DISReadWord(pCpu, lpszCodeBlock);964 pCpu->i32SibDisp = (int16_t)DISReadWord(pCpu, uCodePtr); 941 965 size += sizeof(uint16_t); 942 966 break; … … 951 975 // Query the size of the ModRM parameters and fetch the immediate data (if any) 952 976 //***************************************************************************** 953 unsigned QueryModRM_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc)977 unsigned QueryModRM_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu, unsigned *pSibInc) 954 978 { 955 979 unsigned sibinc; … … 972 996 if (mod != 3 && rm == 4) 973 997 { /* SIB byte follows ModRM */ 974 *pSibInc = ParseSIB_SizeOnly( lpszCodeBlock, pOp, pParam, pCpu);975 lpszCodeBlock+= *pSibInc;998 *pSibInc = ParseSIB_SizeOnly(uCodePtr, pOp, pParam, pCpu); 999 uCodePtr += *pSibInc; 976 1000 size += *pSibInc; 977 1001 } … … 1026 1050 //***************************************************************************** 1027 1051 //***************************************************************************** 1028 unsigned ParseIllegal(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1029 { 1030 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1052 unsigned ParseIllegal(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1053 { 1054 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1031 1055 AssertFailed(); 1032 1056 return 0; … … 1034 1058 //***************************************************************************** 1035 1059 //***************************************************************************** 1036 unsigned ParseModRM(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1060 unsigned ParseModRM(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1037 1061 { 1038 1062 unsigned size = sizeof(uint8_t); //ModRM byte 1039 1063 unsigned sibinc, ModRM; 1040 1064 1041 ModRM = DISReadByte(pCpu, lpszCodeBlock);1042 lpszCodeBlock+= sizeof(uint8_t);1065 ModRM = DISReadByte(pCpu, uCodePtr); 1066 uCodePtr += sizeof(uint8_t); 1043 1067 1044 1068 pCpu->ModRM.Bits.Rm = MODRM_RM(ModRM); … … 1072 1096 } 1073 1097 } 1074 size += QueryModRM( lpszCodeBlock, pOp, pParam, pCpu, &sibinc);1075 lpszCodeBlock+= sibinc;1076 1077 UseModRM( lpszCodeBlock, pOp, pParam, pCpu);1078 return size; 1079 } 1080 //***************************************************************************** 1081 //***************************************************************************** 1082 unsigned ParseModRM_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1098 size += QueryModRM(uCodePtr, pOp, pParam, pCpu, &sibinc); 1099 uCodePtr += sibinc; 1100 1101 UseModRM(uCodePtr, pOp, pParam, pCpu); 1102 return size; 1103 } 1104 //***************************************************************************** 1105 //***************************************************************************** 1106 unsigned ParseModRM_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1083 1107 { 1084 1108 unsigned size = sizeof(uint8_t); //ModRM byte 1085 1109 unsigned sibinc, ModRM; 1086 1110 1087 ModRM = DISReadByte(pCpu, lpszCodeBlock);1088 lpszCodeBlock+= sizeof(uint8_t);1111 ModRM = DISReadByte(pCpu, uCodePtr); 1112 uCodePtr += sizeof(uint8_t); 1089 1113 1090 1114 pCpu->ModRM.Bits.Rm = MODRM_RM(ModRM); … … 1119 1143 } 1120 1144 1121 size += QueryModRM_SizeOnly( lpszCodeBlock, pOp, pParam, pCpu, &sibinc);1122 lpszCodeBlock+= sibinc;1145 size += QueryModRM_SizeOnly(uCodePtr, pOp, pParam, pCpu, &sibinc); 1146 uCodePtr += sibinc; 1123 1147 1124 1148 /* UseModRM is not necessary here; we're only interested in the opcode size */ … … 1127 1151 //***************************************************************************** 1128 1152 //***************************************************************************** 1129 unsigned ParseModFence(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1153 unsigned ParseModFence(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1130 1154 { 1131 1155 ////AssertMsgFailed(("??\n")); 1132 1156 //nothing to do apparently 1133 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1157 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1134 1158 return 0; 1135 1159 } 1136 1160 //***************************************************************************** 1137 1161 //***************************************************************************** 1138 unsigned ParseImmByte(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1162 unsigned ParseImmByte(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1139 1163 { 1140 1164 NOREF(pOp); 1141 pParam->parval = DISReadByte(pCpu, lpszCodeBlock);1165 pParam->parval = DISReadByte(pCpu, uCodePtr); 1142 1166 pParam->flags |= USE_IMMEDIATE8; 1143 1167 pParam->cb = sizeof(uint8_t); 1144 1145 disasmAddStringF1(pParam->szParam, "0%02Xh", (uint32_t)pParam->parval);1146 1168 return sizeof(uint8_t); 1147 1169 } 1148 1170 //***************************************************************************** 1149 1171 //***************************************************************************** 1150 unsigned ParseImmByte_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1151 { 1152 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1172 unsigned ParseImmByte_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1173 { 1174 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1153 1175 return sizeof(uint8_t); 1154 1176 } 1155 1177 //***************************************************************************** 1156 1178 //***************************************************************************** 1157 unsigned ParseImmByteSX(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1179 unsigned ParseImmByteSX(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1158 1180 { 1159 1181 NOREF(pOp); 1160 1182 if (pCpu->opmode == CPUMODE_32BIT) 1161 1183 { 1162 pParam->parval = (uint32_t)(int8_t)DISReadByte(pCpu, lpszCodeBlock);1184 pParam->parval = (uint32_t)(int8_t)DISReadByte(pCpu, uCodePtr); 1163 1185 pParam->flags |= USE_IMMEDIATE32_SX8; 1164 1186 pParam->cb = sizeof(uint32_t); 1165 disasmAddStringF1(pParam->szParam, "0%08Xh", (uint32_t)pParam->parval);1166 1187 } 1167 1188 else 1168 1189 if (pCpu->opmode == CPUMODE_64BIT) 1169 1190 { 1170 pParam->parval = (uint64_t)(int8_t)DISReadByte(pCpu, lpszCodeBlock);1191 pParam->parval = (uint64_t)(int8_t)DISReadByte(pCpu, uCodePtr); 1171 1192 pParam->flags |= USE_IMMEDIATE64_SX8; 1172 1193 pParam->cb = sizeof(uint64_t); 1173 disasmAddStringF1(pParam->szParam, "0%016RX64h", pParam->parval); 1174 } 1175 else 1176 { 1177 pParam->parval = (uint16_t)(int8_t)DISReadByte(pCpu, lpszCodeBlock); 1194 } 1195 else 1196 { 1197 pParam->parval = (uint16_t)(int8_t)DISReadByte(pCpu, uCodePtr); 1178 1198 pParam->flags |= USE_IMMEDIATE16_SX8; 1179 1199 pParam->cb = sizeof(uint16_t); 1180 disasmAddStringF1(pParam->szParam, "0%04Xh", (uint16_t)pParam->parval);1181 1200 } 1182 1201 return sizeof(uint8_t); … … 1184 1203 //***************************************************************************** 1185 1204 //***************************************************************************** 1186 unsigned ParseImmByteSX_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1187 { 1188 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1205 unsigned ParseImmByteSX_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1206 { 1207 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1189 1208 return sizeof(uint8_t); 1190 1209 } 1191 1210 //***************************************************************************** 1192 1211 //***************************************************************************** 1193 unsigned ParseImmUshort(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1212 unsigned ParseImmUshort(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1194 1213 { 1195 1214 NOREF(pOp); 1196 pParam->parval = DISReadWord(pCpu, lpszCodeBlock);1215 pParam->parval = DISReadWord(pCpu, uCodePtr); 1197 1216 pParam->flags |= USE_IMMEDIATE16; 1198 1217 pParam->cb = sizeof(uint16_t); 1199 1200 disasmAddStringF1(pParam->szParam, "0%04Xh", (uint16_t)pParam->parval);1201 1218 return sizeof(uint16_t); 1202 1219 } 1203 1220 //***************************************************************************** 1204 1221 //***************************************************************************** 1205 unsigned ParseImmUshort_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1206 { 1207 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1222 unsigned ParseImmUshort_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1223 { 1224 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1208 1225 return sizeof(uint16_t); 1209 1226 } 1210 1227 //***************************************************************************** 1211 1228 //***************************************************************************** 1212 unsigned ParseImmUlong(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1229 unsigned ParseImmUlong(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1213 1230 { 1214 1231 NOREF(pOp); 1215 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock);1232 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1216 1233 pParam->flags |= USE_IMMEDIATE32; 1217 1234 pParam->cb = sizeof(uint32_t); 1218 1219 disasmAddStringF1(pParam->szParam, "0%08Xh", (uint32_t)pParam->parval);1220 1235 return sizeof(uint32_t); 1221 1236 } 1222 1237 //***************************************************************************** 1223 1238 //***************************************************************************** 1224 unsigned ParseImmUlong_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1225 { 1226 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1239 unsigned ParseImmUlong_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1240 { 1241 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1227 1242 return sizeof(uint32_t); 1228 1243 } 1229 1244 //***************************************************************************** 1230 1245 //***************************************************************************** 1231 unsigned ParseImmQword(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1246 unsigned ParseImmQword(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1232 1247 { 1233 1248 NOREF(pOp); 1234 pParam->parval = DISReadQWord(pCpu, lpszCodeBlock);1249 pParam->parval = DISReadQWord(pCpu, uCodePtr); 1235 1250 pParam->flags |= USE_IMMEDIATE64; 1236 1251 pParam->cb = sizeof(uint64_t); 1237 1238 disasmAddStringF2(pParam->szParam, "0%08X%08Xh",1239 (uint32_t)pParam->parval, (uint32_t)(pParam->parval >> 32));1240 1252 return sizeof(uint64_t); 1241 1253 } 1242 1254 //***************************************************************************** 1243 1255 //***************************************************************************** 1244 unsigned ParseImmQword_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1245 { 1246 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1256 unsigned ParseImmQword_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1257 { 1258 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1247 1259 return sizeof(uint64_t); 1248 1260 } 1249 1261 //***************************************************************************** 1250 1262 //***************************************************************************** 1251 unsigned ParseImmV(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1263 unsigned ParseImmV(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1252 1264 { 1253 1265 NOREF(pOp); 1254 1266 if (pCpu->opmode == CPUMODE_32BIT) 1255 1267 { 1256 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock);1268 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1257 1269 pParam->flags |= USE_IMMEDIATE32; 1258 1270 pParam->cb = sizeof(uint32_t); 1259 1260 disasmAddStringF1(pParam->szParam, "0%08Xh", (uint32_t)pParam->parval);1261 1271 return sizeof(uint32_t); 1262 1272 } 1263 else 1273 1264 1274 if (pCpu->opmode == CPUMODE_64BIT) 1265 1275 { 1266 pParam->parval = DISReadQWord(pCpu, lpszCodeBlock);1276 pParam->parval = DISReadQWord(pCpu, uCodePtr); 1267 1277 pParam->flags |= USE_IMMEDIATE64; 1268 1278 pParam->cb = sizeof(uint64_t); 1269 1270 disasmAddStringF1(pParam->szParam, "0%RX64h", pParam->parval);1271 1279 return sizeof(uint64_t); 1272 1280 } 1273 else 1274 { 1275 pParam->parval = DISReadWord(pCpu, lpszCodeBlock); 1276 pParam->flags |= USE_IMMEDIATE16; 1277 pParam->cb = sizeof(uint16_t); 1278 1279 disasmAddStringF1(pParam->szParam, "0%04Xh", (uint32_t)pParam->parval); 1280 return sizeof(uint16_t); 1281 } 1282 } 1283 //***************************************************************************** 1284 //***************************************************************************** 1285 unsigned ParseImmV_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1286 { 1287 NOREF(lpszCodeBlock); NOREF(pOp); NOREF(pParam); 1281 1282 pParam->parval = DISReadWord(pCpu, uCodePtr); 1283 pParam->flags |= USE_IMMEDIATE16; 1284 pParam->cb = sizeof(uint16_t); 1285 return sizeof(uint16_t); 1286 } 1287 //***************************************************************************** 1288 //***************************************************************************** 1289 unsigned ParseImmV_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1290 { 1291 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); 1288 1292 if (pCpu->opmode == CPUMODE_32BIT) 1289 1293 return sizeof(uint32_t); … … 1294 1298 //***************************************************************************** 1295 1299 //***************************************************************************** 1296 unsigned ParseImmZ(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1300 unsigned ParseImmZ(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1297 1301 { 1298 1302 NOREF(pOp); … … 1300 1304 if (pCpu->opmode == CPUMODE_16BIT) 1301 1305 { 1302 pParam->parval = DISReadWord(pCpu, lpszCodeBlock);1306 pParam->parval = DISReadWord(pCpu, uCodePtr); 1303 1307 pParam->flags |= USE_IMMEDIATE16; 1304 1308 pParam->cb = sizeof(uint16_t); 1305 1306 disasmAddStringF1(pParam->szParam, "0%04Xh", (uint32_t)pParam->parval);1307 1309 return sizeof(uint16_t); 1308 1310 } 1309 else 1310 { 1311 /* 64 bits op mode means *sign* extend to 64 bits. */ 1312 if (pCpu->opmode == CPUMODE_64BIT) 1313 { 1314 pParam->parval = (uint64_t)(int32_t)DISReadDWord(pCpu, lpszCodeBlock); 1315 pParam->flags |= USE_IMMEDIATE64; 1316 pParam->cb = sizeof(uint64_t); 1317 disasmAddStringF1(pParam->szParam, "0%RX64h", pParam->parval); 1318 } 1319 else 1320 { 1321 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock); 1322 pParam->flags |= USE_IMMEDIATE32; 1323 pParam->cb = sizeof(uint32_t); 1324 disasmAddStringF1(pParam->szParam, "0%08Xh", (uint32_t)pParam->parval); 1325 } 1326 return sizeof(uint32_t); 1327 } 1328 } 1329 //***************************************************************************** 1330 //***************************************************************************** 1331 unsigned ParseImmZ_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1332 { 1333 NOREF(lpszCodeBlock); NOREF(pOp); NOREF(pParam); 1311 1312 /* 64 bits op mode means *sign* extend to 64 bits. */ 1313 if (pCpu->opmode == CPUMODE_64BIT) 1314 { 1315 pParam->parval = (uint64_t)(int32_t)DISReadDWord(pCpu, uCodePtr); 1316 pParam->flags |= USE_IMMEDIATE64; 1317 pParam->cb = sizeof(uint64_t); 1318 } 1319 else 1320 { 1321 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1322 pParam->flags |= USE_IMMEDIATE32; 1323 pParam->cb = sizeof(uint32_t); 1324 } 1325 return sizeof(uint32_t); 1326 } 1327 //***************************************************************************** 1328 //***************************************************************************** 1329 unsigned ParseImmZ_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1330 { 1331 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); 1334 1332 /* Word for 16-bit operand-size or doubleword for 32 or 64-bit operand-size. */ 1335 1333 if (pCpu->opmode == CPUMODE_16BIT) … … 1341 1339 // Relative displacement for branches (rel. to next instruction) 1342 1340 //***************************************************************************** 1343 unsigned ParseImmBRel(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1341 unsigned ParseImmBRel(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1344 1342 { 1345 1343 NOREF(pOp); 1346 pParam->parval = DISReadByte(pCpu, lpszCodeBlock);1344 pParam->parval = DISReadByte(pCpu, uCodePtr); 1347 1345 pParam->flags |= USE_IMMEDIATE8_REL; 1348 1346 pParam->cb = sizeof(uint8_t); 1349 1350 disasmAddStringF1(pParam->szParam, " (0%02Xh)", (uint32_t)pParam->parval);1351 1347 return sizeof(char); 1352 1348 } … … 1354 1350 // Relative displacement for branches (rel. to next instruction) 1355 1351 //***************************************************************************** 1356 unsigned ParseImmBRel_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1357 { 1358 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam); NOREF(pCpu);1352 unsigned ParseImmBRel_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1353 { 1354 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); NOREF(pCpu); 1359 1355 return sizeof(char); 1360 1356 } … … 1362 1358 // Relative displacement for branches (rel. to next instruction) 1363 1359 //***************************************************************************** 1364 unsigned ParseImmVRel(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1360 unsigned ParseImmVRel(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1365 1361 { 1366 1362 NOREF(pOp); 1367 1363 if (pCpu->opmode == CPUMODE_32BIT) 1368 1364 { 1369 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock);1365 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1370 1366 pParam->flags |= USE_IMMEDIATE32_REL; 1371 1367 pParam->cb = sizeof(int32_t); 1372 1373 disasmAddStringF1(pParam->szParam, " (0%08Xh)", (uint32_t)pParam->parval);1374 1368 return sizeof(int32_t); 1375 1369 } 1376 else 1370 1377 1371 if (pCpu->opmode == CPUMODE_64BIT) 1378 1372 { 1379 1373 /* 32 bits relative immediate sign extended to 64 bits. */ 1380 pParam->parval = (uint64_t)(int32_t)DISReadDWord(pCpu, lpszCodeBlock);1374 pParam->parval = (uint64_t)(int32_t)DISReadDWord(pCpu, uCodePtr); 1381 1375 pParam->flags |= USE_IMMEDIATE64_REL; 1382 1376 pParam->cb = sizeof(int64_t); 1383 1384 disasmAddStringF1(pParam->szParam, " (0%RX64h)", pParam->parval);1385 1377 return sizeof(int32_t); 1386 1378 } 1387 else 1388 { 1389 pParam->parval = DISReadWord(pCpu, lpszCodeBlock); 1390 pParam->flags |= USE_IMMEDIATE16_REL; 1391 pParam->cb = sizeof(int16_t); 1392 1393 disasmAddStringF1(pParam->szParam, " (0%04Xh)", (uint32_t)pParam->parval); 1394 return sizeof(int16_t); 1395 } 1379 1380 pParam->parval = DISReadWord(pCpu, uCodePtr); 1381 pParam->flags |= USE_IMMEDIATE16_REL; 1382 pParam->cb = sizeof(int16_t); 1383 return sizeof(int16_t); 1396 1384 } 1397 1385 //***************************************************************************** 1398 1386 // Relative displacement for branches (rel. to next instruction) 1399 1387 //***************************************************************************** 1400 unsigned ParseImmVRel_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1401 { 1402 NOREF( lpszCodeBlock); NOREF(pOp); NOREF(pParam);1388 unsigned ParseImmVRel_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1389 { 1390 NOREF(uCodePtr); NOREF(pOp); NOREF(pParam); 1403 1391 if (pCpu->opmode == CPUMODE_16BIT) 1404 1392 return sizeof(int16_t); … … 1408 1396 //***************************************************************************** 1409 1397 //***************************************************************************** 1410 unsigned ParseImmAddr(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1411 { 1412 disasmGetPtrString(pCpu, pOp, pParam); 1398 unsigned ParseImmAddr(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1399 { 1413 1400 if (pCpu->addrmode == CPUMODE_32BIT) 1414 1401 { 1415 1402 if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_p) 1416 {// far 16:32 pointer 1417 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock); 1418 *((uint32_t*)&pParam->parval+1) = DISReadWord(pCpu, lpszCodeBlock+sizeof(uint32_t)); 1403 { 1404 /* far 16:32 pointer */ 1405 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1406 *((uint32_t*)&pParam->parval+1) = DISReadWord(pCpu, uCodePtr+sizeof(uint32_t)); 1419 1407 pParam->flags |= USE_IMMEDIATE_ADDR_16_32; 1420 1408 pParam->cb = sizeof(uint16_t) + sizeof(uint32_t); 1421 1422 disasmAddStringF2(pParam->szParam, "0%04X:0%08Xh", (uint32_t)(pParam->parval>>32), (uint32_t)pParam->parval);1423 1409 return sizeof(uint32_t) + sizeof(uint16_t); 1424 1410 } 1425 else 1426 {// near 32 bits pointer 1427 /* 1428 * Note: used only in "mov al|ax|eax, [Addr]" and "mov [Addr], al|ax|eax" 1429 * so we treat it like displacement. 1430 */ 1431 pParam->uDisp.i32 = DISReadDWord(pCpu, lpszCodeBlock); 1432 pParam->flags |= USE_DISPLACEMENT32; 1433 pParam->cb = sizeof(uint32_t); 1434 1435 disasmAddStringF1(pParam->szParam, "[0%08Xh]", pParam->uDisp.i32); 1436 return sizeof(uint32_t); 1437 } 1438 } 1439 else 1440 if (pCpu->addrmode == CPUMODE_64BIT) 1441 { 1442 Assert(OP_PARM_VSUBTYPE(pParam->param) != OP_PARM_p); 1443 /* near 64 bits pointer */ 1411 1444 1412 /* 1413 * near 32 bits pointer 1414 * 1445 1415 * Note: used only in "mov al|ax|eax, [Addr]" and "mov [Addr], al|ax|eax" 1446 1416 * so we treat it like displacement. 1447 1417 */ 1448 pParam->uDisp.i64 = DISReadQWord(pCpu, lpszCodeBlock); 1418 pParam->uDisp.i32 = DISReadDWord(pCpu, uCodePtr); 1419 pParam->flags |= USE_DISPLACEMENT32; 1420 pParam->cb = sizeof(uint32_t); 1421 return sizeof(uint32_t); 1422 } 1423 1424 if (pCpu->addrmode == CPUMODE_64BIT) 1425 { 1426 Assert(OP_PARM_VSUBTYPE(pParam->param) != OP_PARM_p); 1427 /* 1428 * near 64 bits pointer 1429 * 1430 * Note: used only in "mov al|ax|eax, [Addr]" and "mov [Addr], al|ax|eax" 1431 * so we treat it like displacement. 1432 */ 1433 pParam->uDisp.i64 = DISReadQWord(pCpu, uCodePtr); 1449 1434 pParam->flags |= USE_DISPLACEMENT64; 1450 1435 pParam->cb = sizeof(uint64_t); 1451 1452 disasmAddStringF2(pParam->szParam, "[0%08X%08Xh]", (uint32_t)(pParam->uDisp.i64 >> 32), (uint32_t)pParam->uDisp.i64);1453 1436 return sizeof(uint64_t); 1454 1437 } 1455 else 1456 { 1457 if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_p) 1458 {// far 16:16 pointer 1459 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock); 1460 pParam->flags |= USE_IMMEDIATE_ADDR_16_16; 1461 pParam->cb = 2*sizeof(uint16_t); 1462 1463 disasmAddStringF2(pParam->szParam, "0%04X:0%04Xh", (uint32_t)(pParam->parval>>16), (uint16_t)pParam->parval ); 1464 return sizeof(uint32_t); 1465 } 1466 else 1467 {// near 16 bits pointer 1468 /* 1469 * Note: used only in "mov al|ax|eax, [Addr]" and "mov [Addr], al|ax|eax" 1470 * so we treat it like displacement. 1471 */ 1472 pParam->uDisp.i16 = DISReadWord(pCpu, lpszCodeBlock); 1473 pParam->flags |= USE_DISPLACEMENT16; 1474 pParam->cb = sizeof(uint16_t); 1475 1476 disasmAddStringF1(pParam->szParam, "[0%04Xh]", (uint32_t)pParam->uDisp.i16); 1477 return sizeof(uint16_t); 1478 } 1479 } 1480 } 1481 //***************************************************************************** 1482 //***************************************************************************** 1483 unsigned ParseImmAddr_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1484 { 1485 NOREF(lpszCodeBlock); NOREF(pOp); 1438 if (OP_PARM_VSUBTYPE(pParam->param) == OP_PARM_p) 1439 { 1440 /* far 16:16 pointer */ 1441 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1442 pParam->flags |= USE_IMMEDIATE_ADDR_16_16; 1443 pParam->cb = 2*sizeof(uint16_t); 1444 return sizeof(uint32_t); 1445 } 1446 1447 /* 1448 * near 16 bits pointer 1449 * 1450 * Note: used only in "mov al|ax|eax, [Addr]" and "mov [Addr], al|ax|eax" 1451 * so we treat it like displacement. 1452 */ 1453 pParam->uDisp.i16 = DISReadWord(pCpu, uCodePtr); 1454 pParam->flags |= USE_DISPLACEMENT16; 1455 pParam->cb = sizeof(uint16_t); 1456 return sizeof(uint16_t); 1457 } 1458 //***************************************************************************** 1459 //***************************************************************************** 1460 unsigned ParseImmAddr_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1461 { 1462 NOREF(uCodePtr); NOREF(pOp); 1486 1463 if (pCpu->addrmode == CPUMODE_32BIT) 1487 1464 { … … 1514 1491 //***************************************************************************** 1515 1492 //***************************************************************************** 1516 unsigned ParseImmAddrF(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1517 { 1518 disasmGetPtrString(pCpu, pOp, pParam); 1493 unsigned ParseImmAddrF(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1494 { 1519 1495 // immediate far pointers - only 16:16 or 16:32; determined by operand, *not* address size! 1520 1496 Assert(pCpu->opmode == CPUMODE_16BIT || pCpu->opmode == CPUMODE_32BIT); … … 1523 1499 { 1524 1500 // far 16:32 pointer 1525 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock);1526 *((uint32_t*)&pParam->parval+1) = DISReadWord(pCpu, lpszCodeBlock+sizeof(uint32_t));1501 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1502 *((uint32_t*)&pParam->parval+1) = DISReadWord(pCpu, uCodePtr+sizeof(uint32_t)); 1527 1503 pParam->flags |= USE_IMMEDIATE_ADDR_16_32; 1528 1504 pParam->cb = sizeof(uint16_t) + sizeof(uint32_t); 1529 1530 disasmAddStringF2(pParam->szParam, "0%04X:0%08Xh", (uint32_t)(pParam->parval>>32), (uint32_t)pParam->parval);1531 1505 return sizeof(uint32_t) + sizeof(uint16_t); 1532 1506 } 1533 else 1534 { 1535 // far 16:16 pointer 1536 pParam->parval = DISReadDWord(pCpu, lpszCodeBlock); 1537 pParam->flags |= USE_IMMEDIATE_ADDR_16_16; 1538 pParam->cb = 2*sizeof(uint16_t); 1539 1540 disasmAddStringF2(pParam->szParam, "0%04X:0%04Xh", (uint32_t)(pParam->parval>>16), (uint16_t)pParam->parval ); 1541 return sizeof(uint32_t); 1542 } 1543 } 1544 //***************************************************************************** 1545 //***************************************************************************** 1546 unsigned ParseImmAddrF_SizeOnly(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1547 { 1548 NOREF(lpszCodeBlock); NOREF(pOp); 1507 1508 // far 16:16 pointer 1509 pParam->parval = DISReadDWord(pCpu, uCodePtr); 1510 pParam->flags |= USE_IMMEDIATE_ADDR_16_16; 1511 pParam->cb = 2*sizeof(uint16_t); 1512 return sizeof(uint32_t); 1513 } 1514 //***************************************************************************** 1515 //***************************************************************************** 1516 unsigned ParseImmAddrF_SizeOnly(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1517 { 1518 NOREF(uCodePtr); NOREF(pOp); 1549 1519 // immediate far pointers - only 16:16 or 16:32 1550 1520 Assert(pCpu->opmode == CPUMODE_16BIT || pCpu->opmode == CPUMODE_32BIT); … … 1563 1533 //***************************************************************************** 1564 1534 //***************************************************************************** 1565 unsigned ParseFixedReg(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1566 { 1567 NOREF( lpszCodeBlock);1535 unsigned ParseFixedReg(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1536 { 1537 NOREF(uCodePtr); 1568 1538 1569 1539 /* … … 1664 1634 //***************************************************************************** 1665 1635 //***************************************************************************** 1666 unsigned ParseXv(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1667 { 1668 NOREF(pu8CodeBlock); 1669 disasmGetPtrString(pCpu, pOp, pParam); 1670 disasmAddString(pParam->szParam, (pCpu->addrmode == CPUMODE_32BIT) ? "DS:ESI" : "DS:SI"); 1636 unsigned ParseXv(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1637 { 1638 NOREF(uCodePtr); 1671 1639 1672 1640 pParam->flags |= USE_POINTER_DS_BASED; … … 1691 1659 //***************************************************************************** 1692 1660 //***************************************************************************** 1693 unsigned ParseXb(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1694 { 1695 NOREF(pu8CodeBlock); NOREF(pOp); 1696 disasmAddString(pParam->szParam, (pCpu->addrmode == CPUMODE_32BIT) ? "DS:ESI" : "DS:SI"); 1661 unsigned ParseXb(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1662 { 1663 NOREF(uCodePtr); NOREF(pOp); 1697 1664 1698 1665 pParam->flags |= USE_POINTER_DS_BASED; … … 1717 1684 //***************************************************************************** 1718 1685 //***************************************************************************** 1719 unsigned ParseYv(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1720 { 1721 NOREF(pu8CodeBlock); 1722 disasmGetPtrString(pCpu, pOp, pParam); 1723 disasmAddString(pParam->szParam, (pCpu->addrmode == CPUMODE_32BIT) ? "ES:EDI" : "ES:DI"); 1686 unsigned ParseYv(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1687 { 1688 NOREF(uCodePtr); 1724 1689 1725 1690 pParam->flags |= USE_POINTER_ES_BASED; … … 1744 1709 //***************************************************************************** 1745 1710 //***************************************************************************** 1746 unsigned ParseYb(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1747 { 1748 NOREF(pu8CodeBlock); NOREF(pOp); 1749 disasmAddString(pParam->szParam, (pCpu->addrmode == CPUMODE_32BIT) ? "ES:EDI" : "ES:DI"); 1711 unsigned ParseYb(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1712 { 1713 NOREF(uCodePtr); NOREF(pOp); 1750 1714 1751 1715 pParam->flags |= USE_POINTER_ES_BASED; … … 1770 1734 //***************************************************************************** 1771 1735 //***************************************************************************** 1772 unsigned ParseTwoByteEsc(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1736 unsigned ParseTwoByteEsc(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1773 1737 { 1774 1738 const OPCODE *pOpcode; … … 1777 1741 1778 1742 /* 2nd byte */ 1779 pCpu->opcode = DISReadByte(pCpu, lpszCodeBlock);1743 pCpu->opcode = DISReadByte(pCpu, uCodePtr); 1780 1744 1781 1745 /* default to the non-prefixed table. */ … … 1824 1788 } 1825 1789 1826 size += ParseInstruction( lpszCodeBlock+size, pOpcode, pCpu);1827 return size; 1828 } 1829 //***************************************************************************** 1830 //***************************************************************************** 1831 unsigned ParseThreeByteEsc4(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1790 size += ParseInstruction(uCodePtr+size, pOpcode, pCpu); 1791 return size; 1792 } 1793 //***************************************************************************** 1794 //***************************************************************************** 1795 unsigned ParseThreeByteEsc4(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1832 1796 { 1833 1797 const OPCODE *pOpcode; … … 1836 1800 1837 1801 /* 3rd byte */ 1838 pCpu->opcode = DISReadByte(pCpu, lpszCodeBlock);1802 pCpu->opcode = DISReadByte(pCpu, uCodePtr); 1839 1803 1840 1804 /* default to the non-prefixed table. */ … … 1885 1849 } 1886 1850 1887 size += ParseInstruction( lpszCodeBlock+size, pOpcode, pCpu);1888 return size; 1889 } 1890 //***************************************************************************** 1891 //***************************************************************************** 1892 unsigned ParseThreeByteEsc5(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1851 size += ParseInstruction(uCodePtr+size, pOpcode, pCpu); 1852 return size; 1853 } 1854 //***************************************************************************** 1855 //***************************************************************************** 1856 unsigned ParseThreeByteEsc5(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1893 1857 { 1894 1858 const OPCODE *pOpcode; … … 1897 1861 1898 1862 /* 3rd byte */ 1899 pCpu->opcode = DISReadByte(pCpu, lpszCodeBlock);1863 pCpu->opcode = DISReadByte(pCpu, uCodePtr); 1900 1864 1901 1865 /** @todo Should we take the first or last prefix byte in case of multiple prefix bytes??? */ … … 1920 1884 pOpcode = &g_InvalidOpcode[0]; 1921 1885 1922 size += ParseInstruction( lpszCodeBlock+size, pOpcode, pCpu);1923 return size; 1924 } 1925 //***************************************************************************** 1926 //***************************************************************************** 1927 unsigned ParseNopPause(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1886 size += ParseInstruction(uCodePtr+size, pOpcode, pCpu); 1887 return size; 1888 } 1889 //***************************************************************************** 1890 //***************************************************************************** 1891 unsigned ParseNopPause(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1928 1892 { 1929 1893 unsigned size = 0; … … 1938 1902 pOp = &g_aMapX86_NopPause[0]; /* NOP */ 1939 1903 1940 size += ParseInstruction( pu8CodeBlock, pOp, pCpu);1941 return size; 1942 } 1943 //***************************************************************************** 1944 //***************************************************************************** 1945 unsigned ParseImmGrpl(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1904 size += ParseInstruction(uCodePtr, pOp, pCpu); 1905 return size; 1906 } 1907 //***************************************************************************** 1908 //***************************************************************************** 1909 unsigned ParseImmGrpl(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1946 1910 { 1947 1911 int idx = (pCpu->opcode - 0x80) * 8; … … 1949 1913 NOREF(pParam); 1950 1914 1951 modrm = DISReadByte(pCpu, lpszCodeBlock);1915 modrm = DISReadByte(pCpu, uCodePtr); 1952 1916 reg = MODRM_REG(modrm); 1953 1917 … … 1957 1921 size = sizeof(uint8_t); //ModRM byte 1958 1922 1959 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);1960 1961 return size; 1962 } 1963 //***************************************************************************** 1964 //***************************************************************************** 1965 unsigned ParseShiftGrp2(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1923 size += ParseInstruction(uCodePtr, pOp, pCpu); 1924 1925 return size; 1926 } 1927 //***************************************************************************** 1928 //***************************************************************************** 1929 unsigned ParseShiftGrp2(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 1966 1930 { 1967 1931 int idx; … … 1988 1952 } 1989 1953 1990 modrm = DISReadByte(pCpu, lpszCodeBlock);1954 modrm = DISReadByte(pCpu, uCodePtr); 1991 1955 reg = MODRM_REG(modrm); 1992 1956 … … 1997 1961 size = sizeof(uint8_t); //ModRM byte 1998 1962 1999 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2000 2001 return size; 2002 } 2003 //***************************************************************************** 2004 //***************************************************************************** 2005 unsigned ParseGrp3(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1963 size += ParseInstruction(uCodePtr, pOp, pCpu); 1964 1965 return size; 1966 } 1967 //***************************************************************************** 1968 //***************************************************************************** 1969 unsigned ParseGrp3(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2006 1970 { 2007 1971 int idx = (pCpu->opcode - 0xF6) * 8; … … 2009 1973 NOREF(pParam); 2010 1974 2011 modrm = DISReadByte(pCpu, lpszCodeBlock);1975 modrm = DISReadByte(pCpu, uCodePtr); 2012 1976 reg = MODRM_REG(modrm); 2013 1977 … … 2018 1982 size = sizeof(uint8_t); //ModRM byte 2019 1983 2020 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2021 2022 return size; 2023 } 2024 //***************************************************************************** 2025 //***************************************************************************** 2026 unsigned ParseGrp4(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)1984 size += ParseInstruction(uCodePtr, pOp, pCpu); 1985 1986 return size; 1987 } 1988 //***************************************************************************** 1989 //***************************************************************************** 1990 unsigned ParseGrp4(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2027 1991 { 2028 1992 unsigned size = 0, modrm, reg; 2029 1993 NOREF(pParam); 2030 1994 2031 modrm = DISReadByte(pCpu, lpszCodeBlock);1995 modrm = DISReadByte(pCpu, uCodePtr); 2032 1996 reg = MODRM_REG(modrm); 2033 1997 … … 2038 2002 size = sizeof(uint8_t); //ModRM byte 2039 2003 2040 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2041 2042 return size; 2043 } 2044 //***************************************************************************** 2045 //***************************************************************************** 2046 unsigned ParseGrp5(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2004 size += ParseInstruction(uCodePtr, pOp, pCpu); 2005 2006 return size; 2007 } 2008 //***************************************************************************** 2009 //***************************************************************************** 2010 unsigned ParseGrp5(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2047 2011 { 2048 2012 unsigned size = 0, modrm, reg; 2049 2013 NOREF(pParam); 2050 2014 2051 modrm = DISReadByte(pCpu, lpszCodeBlock);2015 modrm = DISReadByte(pCpu, uCodePtr); 2052 2016 reg = MODRM_REG(modrm); 2053 2017 … … 2058 2022 size = sizeof(uint8_t); //ModRM byte 2059 2023 2060 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2024 size += ParseInstruction(uCodePtr, pOp, pCpu); 2061 2025 2062 2026 return size; … … 2068 2032 // 2069 2033 //***************************************************************************** 2070 unsigned Parse3DNow(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2034 unsigned Parse3DNow(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2071 2035 { 2072 2036 unsigned size = 0, modrmsize; … … 2077 2041 #endif 2078 2042 2079 unsigned ModRM = DISReadByte(pCpu, lpszCodeBlock);2043 unsigned ModRM = DISReadByte(pCpu, uCodePtr); 2080 2044 pCpu->ModRM.Bits.Rm = MODRM_RM(ModRM); 2081 2045 pCpu->ModRM.Bits.Mod = MODRM_MOD(ModRM); 2082 2046 pCpu->ModRM.Bits.Reg = MODRM_REG(ModRM); 2083 2047 2084 modrmsize = QueryModRM( lpszCodeBlock+sizeof(uint8_t), pOp, pParam, pCpu);2085 2086 uint8_t opcode = DISReadByte(pCpu, lpszCodeBlock+sizeof(uint8_t)+modrmsize);2048 modrmsize = QueryModRM(uCodePtr+sizeof(uint8_t), pOp, pParam, pCpu); 2049 2050 uint8_t opcode = DISReadByte(pCpu, uCodePtr+sizeof(uint8_t)+modrmsize); 2087 2051 2088 2052 pOp = (PCOPCODE)&g_aTwoByteMapX86_3DNow[opcode]; … … 2097 2061 } 2098 2062 2099 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2063 size += ParseInstruction(uCodePtr, pOp, pCpu); 2100 2064 size += sizeof(uint8_t); //imm8_opcode uint8_t 2101 2065 … … 2104 2068 //***************************************************************************** 2105 2069 //***************************************************************************** 2106 unsigned ParseGrp6(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2070 unsigned ParseGrp6(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2107 2071 { 2108 2072 unsigned size = 0, modrm, reg; 2109 2073 NOREF(pParam); 2110 2074 2111 modrm = DISReadByte(pCpu, lpszCodeBlock);2075 modrm = DISReadByte(pCpu, uCodePtr); 2112 2076 reg = MODRM_REG(modrm); 2113 2077 … … 2118 2082 size = sizeof(uint8_t); //ModRM byte 2119 2083 2120 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2121 2122 return size; 2123 } 2124 //***************************************************************************** 2125 //***************************************************************************** 2126 unsigned ParseGrp7(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2084 size += ParseInstruction(uCodePtr, pOp, pCpu); 2085 2086 return size; 2087 } 2088 //***************************************************************************** 2089 //***************************************************************************** 2090 unsigned ParseGrp7(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2127 2091 { 2128 2092 unsigned size = 0, modrm, reg, rm, mod; 2129 2093 NOREF(pParam); 2130 2094 2131 modrm = DISReadByte(pCpu, lpszCodeBlock);2095 modrm = DISReadByte(pCpu, uCodePtr); 2132 2096 mod = MODRM_MOD(modrm); 2133 2097 reg = MODRM_REG(modrm); … … 2146 2110 size = sizeof(uint8_t); //ModRM byte 2147 2111 2148 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2149 2150 return size; 2151 } 2152 //***************************************************************************** 2153 //***************************************************************************** 2154 unsigned ParseGrp8(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2112 size += ParseInstruction(uCodePtr, pOp, pCpu); 2113 2114 return size; 2115 } 2116 //***************************************************************************** 2117 //***************************************************************************** 2118 unsigned ParseGrp8(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2155 2119 { 2156 2120 unsigned size = 0, modrm, reg; 2157 2121 NOREF(pParam); 2158 2122 2159 modrm = DISReadByte(pCpu, lpszCodeBlock);2123 modrm = DISReadByte(pCpu, uCodePtr); 2160 2124 reg = MODRM_REG(modrm); 2161 2125 … … 2166 2130 size = sizeof(uint8_t); //ModRM byte 2167 2131 2168 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2169 2170 return size; 2171 } 2172 //***************************************************************************** 2173 //***************************************************************************** 2174 unsigned ParseGrp9(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2132 size += ParseInstruction(uCodePtr, pOp, pCpu); 2133 2134 return size; 2135 } 2136 //***************************************************************************** 2137 //***************************************************************************** 2138 unsigned ParseGrp9(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2175 2139 { 2176 2140 unsigned size = 0, modrm, reg; 2177 2141 NOREF(pParam); 2178 2142 2179 modrm = DISReadByte(pCpu, lpszCodeBlock);2143 modrm = DISReadByte(pCpu, uCodePtr); 2180 2144 reg = MODRM_REG(modrm); 2181 2145 … … 2186 2150 size = sizeof(uint8_t); //ModRM byte 2187 2151 2188 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2189 2190 return size; 2191 } 2192 //***************************************************************************** 2193 //***************************************************************************** 2194 unsigned ParseGrp10(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2152 size += ParseInstruction(uCodePtr, pOp, pCpu); 2153 2154 return size; 2155 } 2156 //***************************************************************************** 2157 //***************************************************************************** 2158 unsigned ParseGrp10(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2195 2159 { 2196 2160 unsigned size = 0, modrm, reg; 2197 2161 NOREF(pParam); 2198 2162 2199 modrm = DISReadByte(pCpu, lpszCodeBlock);2163 modrm = DISReadByte(pCpu, uCodePtr); 2200 2164 reg = MODRM_REG(modrm); 2201 2165 … … 2206 2170 size = sizeof(uint8_t); //ModRM byte 2207 2171 2208 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2209 2210 return size; 2211 } 2212 //***************************************************************************** 2213 //***************************************************************************** 2214 unsigned ParseGrp12(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2172 size += ParseInstruction(uCodePtr, pOp, pCpu); 2173 2174 return size; 2175 } 2176 //***************************************************************************** 2177 //***************************************************************************** 2178 unsigned ParseGrp12(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2215 2179 { 2216 2180 unsigned size = 0, modrm, reg; 2217 2181 NOREF(pParam); 2218 2182 2219 modrm = DISReadByte(pCpu, lpszCodeBlock);2183 modrm = DISReadByte(pCpu, uCodePtr); 2220 2184 reg = MODRM_REG(modrm); 2221 2185 … … 2229 2193 size = sizeof(uint8_t); //ModRM byte 2230 2194 2231 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2232 return size; 2233 } 2234 //***************************************************************************** 2235 //***************************************************************************** 2236 unsigned ParseGrp13(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2195 size += ParseInstruction(uCodePtr, pOp, pCpu); 2196 return size; 2197 } 2198 //***************************************************************************** 2199 //***************************************************************************** 2200 unsigned ParseGrp13(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2237 2201 { 2238 2202 unsigned size = 0, modrm, reg; 2239 2203 NOREF(pParam); 2240 2204 2241 modrm = DISReadByte(pCpu, lpszCodeBlock);2205 modrm = DISReadByte(pCpu, uCodePtr); 2242 2206 reg = MODRM_REG(modrm); 2243 2207 if (pCpu->prefix & PREFIX_OPSIZE) … … 2250 2214 size = sizeof(uint8_t); //ModRM byte 2251 2215 2252 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2253 2254 return size; 2255 } 2256 //***************************************************************************** 2257 //***************************************************************************** 2258 unsigned ParseGrp14(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2216 size += ParseInstruction(uCodePtr, pOp, pCpu); 2217 2218 return size; 2219 } 2220 //***************************************************************************** 2221 //***************************************************************************** 2222 unsigned ParseGrp14(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2259 2223 { 2260 2224 unsigned size = 0, modrm, reg; 2261 2225 NOREF(pParam); 2262 2226 2263 modrm = DISReadByte(pCpu, lpszCodeBlock);2227 modrm = DISReadByte(pCpu, uCodePtr); 2264 2228 reg = MODRM_REG(modrm); 2265 2229 if (pCpu->prefix & PREFIX_OPSIZE) … … 2272 2236 size = sizeof(uint8_t); //ModRM byte 2273 2237 2274 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2275 2276 return size; 2277 } 2278 //***************************************************************************** 2279 //***************************************************************************** 2280 unsigned ParseGrp15(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2238 size += ParseInstruction(uCodePtr, pOp, pCpu); 2239 2240 return size; 2241 } 2242 //***************************************************************************** 2243 //***************************************************************************** 2244 unsigned ParseGrp15(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2281 2245 { 2282 2246 unsigned size = 0, modrm, reg, mod, rm; 2283 2247 NOREF(pParam); 2284 2248 2285 modrm = DISReadByte(pCpu, lpszCodeBlock);2249 modrm = DISReadByte(pCpu, uCodePtr); 2286 2250 mod = MODRM_MOD(modrm); 2287 2251 reg = MODRM_REG(modrm); … … 2297 2261 size = sizeof(uint8_t); //ModRM byte 2298 2262 2299 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2300 return size; 2301 } 2302 //***************************************************************************** 2303 //***************************************************************************** 2304 unsigned ParseGrp16(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu)2263 size += ParseInstruction(uCodePtr, pOp, pCpu); 2264 return size; 2265 } 2266 //***************************************************************************** 2267 //***************************************************************************** 2268 unsigned ParseGrp16(RTUINTPTR uCodePtr, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu) 2305 2269 { 2306 2270 unsigned size = 0, modrm, reg; 2307 2271 NOREF(pParam); 2308 2272 2309 modrm = DISReadByte(pCpu, lpszCodeBlock);2273 modrm = DISReadByte(pCpu, uCodePtr); 2310 2274 reg = MODRM_REG(modrm); 2311 2275 … … 2316 2280 size = sizeof(uint8_t); //ModRM byte 2317 2281 2318 size += ParseInstruction( lpszCodeBlock, pOp, pCpu);2282 size += ParseInstruction(uCodePtr, pOp, pCpu); 2319 2283 return size; 2320 2284 } … … 2331 2295 static const int IndexModRMReg16[4] = { USE_REG_SI, USE_REG_DI, USE_REG_SI, USE_REG_DI}; 2332 2296 //***************************************************************************** 2333 void disasmModRMReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam, int fRegAddr)2297 static void disasmModRMReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam, int fRegAddr) 2334 2298 { 2335 2299 int subtype, type, mod; … … 2375 2339 idx += (USE_REG_SPL - USE_REG_AH); 2376 2340 } 2377 disasmAddString(pParam->szParam, szModRMReg8[idx]);2378 2341 2379 2342 pParam->flags |= USE_REG_GEN8; … … 2382 2345 2383 2346 case OP_PARM_w: 2384 disasmAddString(pParam->szParam, szModRMReg16[idx]);2385 2347 Assert(idx < (pCpu->prefix & PREFIX_REX) ? 16 : 8); 2386 2348 … … 2390 2352 2391 2353 case OP_PARM_d: 2392 disasmAddString(pParam->szParam, szModRMReg32[idx]);2393 2354 Assert(idx < (pCpu->prefix & PREFIX_REX) ? 16 : 8); 2394 2355 … … 2398 2359 2399 2360 case OP_PARM_q: 2400 disasmAddString(pParam->szParam, szModRMReg64[idx]);2401 2361 pParam->flags |= USE_REG_GEN64; 2402 2362 pParam->base.reg_gen = idx; … … 2411 2371 //***************************************************************************** 2412 2372 //***************************************************************************** 2413 void disasmModRMReg16(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam)2373 static void disasmModRMReg16(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam) 2414 2374 { 2415 2375 NOREF(pCpu); NOREF(pOp); 2416 disasmAddString(pParam->szParam, szModRMReg1616[idx]);2417 2376 pParam->flags |= USE_REG_GEN16; 2418 2377 pParam->base.reg_gen = BaseModRMReg16[idx]; … … 2425 2384 //***************************************************************************** 2426 2385 //***************************************************************************** 2427 void disasmModRMSReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam)2386 static void disasmModRMSReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam) 2428 2387 { 2429 2388 NOREF(pOp); … … 2435 2394 } 2436 2395 2437 disasmAddString(pParam->szParam, szModRMSegReg[idx]);2438 2396 pParam->flags |= USE_REG_SEG; 2439 2397 pParam->base.reg_seg = (DIS_SELREG)idx; 2440 }2441 //*****************************************************************************2442 //*****************************************************************************2443 void disasmPrintAbs32(POP_PARAMETER pParam)2444 {2445 disasmAddStringF1(pParam->szParam, "%08Xh", pParam->uDisp.i32); NOREF(pParam);2446 }2447 //*****************************************************************************2448 //*****************************************************************************2449 void disasmPrintDisp32(POP_PARAMETER pParam)2450 {2451 disasmAddStringF1(pParam->szParam, "%08Xh", pParam->uDisp.i32); NOREF(pParam);2452 }2453 //*****************************************************************************2454 //*****************************************************************************2455 void disasmPrintDisp64(POP_PARAMETER pParam)2456 {2457 disasmAddStringF1(pParam->szParam, "%16RX64h", pParam->uDisp.i64); NOREF(pParam);2458 }2459 //*****************************************************************************2460 //*****************************************************************************2461 void disasmPrintDisp8(POP_PARAMETER pParam)2462 {2463 disasmAddStringF1(pParam->szParam, "%d", pParam->uDisp.i8); NOREF(pParam);2464 }2465 //*****************************************************************************2466 //*****************************************************************************2467 void disasmPrintDisp16(POP_PARAMETER pParam)2468 {2469 disasmAddStringF1(pParam->szParam, "%04Xh", pParam->uDisp.i16); NOREF(pParam);2470 }2471 //*****************************************************************************2472 //*****************************************************************************2473 void disasmGetPtrString(PDISCPUSTATE pCpu, PCOPCODE pOp, POP_PARAMETER pParam)2474 {2475 int subtype = OP_PARM_VSUBTYPE(pParam->param);2476 NOREF(pOp);2477 2478 if (subtype == OP_PARM_v)2479 {2480 switch(pCpu->opmode)2481 {2482 case CPUMODE_32BIT:2483 subtype = OP_PARM_d;2484 break;2485 case CPUMODE_64BIT:2486 subtype = OP_PARM_q;2487 break;2488 case CPUMODE_16BIT:2489 subtype = OP_PARM_w;2490 break;2491 default:2492 /* make gcc happy */2493 break;2494 }2495 }2496 2497 switch (subtype)2498 {2499 case OP_PARM_a: //two words or dwords depending on operand size (bound only)2500 break;2501 2502 case OP_PARM_b:2503 disasmAddString(pParam->szParam, "byte ptr ");2504 break;2505 2506 case OP_PARM_w:2507 disasmAddString(pParam->szParam, "word ptr ");2508 break;2509 2510 case OP_PARM_d:2511 disasmAddString(pParam->szParam, "dword ptr ");2512 break;2513 2514 case OP_PARM_q:2515 case OP_PARM_dq:2516 disasmAddString(pParam->szParam, "qword ptr ");2517 break;2518 2519 case OP_PARM_p:2520 disasmAddString(pParam->szParam, "far ptr ");2521 break;2522 2523 case OP_PARM_s:2524 break; //??2525 2526 case OP_PARM_z:2527 break;2528 default:2529 break; //no pointer type specified/necessary2530 }2531 if (pCpu->prefix & PREFIX_SEG)2532 disasmAddStringF1(pParam->szParam, "%s:", szModRMSegReg[pCpu->enmPrefixSeg]);2533 2398 } 2534 2399 … … 2722 2587 return uTemp.u; 2723 2588 } 2724 2725 #if !defined(DIS_CORE_ONLY) && defined(LOG_ENABLED)2726 //*****************************************************************************2727 //*****************************************************************************2728 void disasmAddString(char *psz, const char *pszAdd)2729 {2730 strcat(psz, pszAdd);2731 }2732 //*****************************************************************************2733 //*****************************************************************************2734 void disasmAddStringF(char *psz, const char *pszFormat, ...)2735 {2736 va_list args;2737 va_start(args, pszFormat);2738 size_t cchCur = strlen(psz);2739 Assert(cchCur < RT_SIZEOFMEMB(OP_PARAMETER, szParam));2740 RTStrPrintfV(psz + cchCur, RT_SIZEOFMEMB(OP_PARAMETER, szParam) - cchCur,2741 pszFormat, args);2742 va_end(args);2743 }2744 2745 //*****************************************************************************2746 //*****************************************************************************2747 void disasmAddChar(char *psz, char ch)2748 {2749 char sz[2];2750 2751 sz[0] = ch;2752 sz[1] = '\0';2753 strcat(psz, sz);2754 }2755 #endif /* !DIS_CORE_ONLY */2756 2589 2757 2590 -
trunk/src/VBox/Disassembler/DisasmFormatYasm.cpp
r41666 r41668 348 348 { 349 349 #if HC_ARCH_BITS == 64 || GC_ARCH_BITS == 64 350 if (pCpu-> opaddr >= _4G)351 PUT_NUM(9, "%08x`", (uint32_t)(pCpu-> opaddr >> 32));350 if (pCpu->uInstrAddr >= _4G) 351 PUT_NUM(9, "%08x`", (uint32_t)(pCpu->uInstrAddr >> 32)); 352 352 #endif 353 PUT_NUM(8, "%08x", (uint32_t)pCpu-> opaddr);353 PUT_NUM(8, "%08x", (uint32_t)pCpu->uInstrAddr); 354 354 PUT_C(' '); 355 355 } … … 896 896 PUT_SZ(" ("); 897 897 898 RTUINTPTR uTrgAddr = pCpu-> opaddr + pCpu->opsize + offDisplacement;898 RTUINTPTR uTrgAddr = pCpu->uInstrAddr + pCpu->opsize + offDisplacement; 899 899 if (pCpu->mode == CPUMODE_16BIT) 900 900 PUT_NUM_16(uTrgAddr); … … 1132 1132 PUT_C(' '); 1133 1133 #if HC_ARCH_BITS == 64 || GC_ARCH_BITS == 64 1134 if (pCpu-> opaddr >= _4G)1135 PUT_NUM(9, "%08x`", (uint32_t)(pCpu-> opaddr >> 32));1134 if (pCpu->uInstrAddr >= _4G) 1135 PUT_NUM(9, "%08x`", (uint32_t)(pCpu->uInstrAddr >> 32)); 1136 1136 #endif 1137 PUT_NUM(8, "%08x", (uint32_t)pCpu-> opaddr);1137 PUT_NUM(8, "%08x", (uint32_t)pCpu->uInstrAddr); 1138 1138 } 1139 1139 -
trunk/src/VBox/Disassembler/DisasmInternal.h
r41658 r41668 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBox disassembler: 4 * Internal header 3 * VBox disassembler - Internal header. 5 4 */ 6 5 7 6 /* 8 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 9 8 * 10 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 19 #define ___DisasmInternal_h___ 21 20 22 #include <VBox/cdefs.h>23 21 #include <VBox/types.h> 24 22 #include <VBox/dis.h> … … 72 70 73 71 74 extern PFNDISPARSE pfnFullDisasm[IDX_ParseMax]; 75 extern PFNDISPARSE pfnCalcSize[IDX_ParseMax]; 76 72 extern PFNDISPARSE g_apfnFullDisasm[IDX_ParseMax]; 73 extern PFNDISPARSE g_apfnCalcSize[IDX_ParseMax]; 77 74 78 75 unsigned ParseInstruction(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, PDISCPUSTATE pCpu); 79 80 unsigned ParseIllegal(RTUINTPTR lpszCodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);81 unsigned ParseModRM(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);82 unsigned ParseModRM_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);83 unsigned UseModRM(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);84 unsigned ParseImmByte(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);85 unsigned ParseImmByte_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);86 unsigned ParseImmByteSX(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);87 unsigned ParseImmByteSX_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);88 unsigned ParseImmBRel(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);89 unsigned ParseImmBRel_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);90 unsigned ParseImmUshort(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);91 unsigned ParseImmUshort_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);92 unsigned ParseImmV(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);93 unsigned ParseImmV_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);94 unsigned ParseImmVRel(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);95 unsigned ParseImmVRel_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);96 unsigned ParseImmZ(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);97 unsigned ParseImmZ_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);98 99 unsigned ParseImmAddr(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);100 unsigned ParseImmAddr_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);101 unsigned ParseImmAddrF(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);102 unsigned ParseImmAddrF_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);103 unsigned ParseFixedReg(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);104 unsigned ParseImmUlong(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);105 unsigned ParseImmUlong_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);106 unsigned ParseImmQword(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);107 unsigned ParseImmQword_SizeOnly(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);108 109 unsigned ParseTwoByteEsc(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);110 unsigned ParseThreeByteEsc4(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);111 unsigned ParseThreeByteEsc5(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);112 unsigned ParseImmGrpl(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);113 unsigned ParseShiftGrp2(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);114 unsigned ParseGrp3(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);115 unsigned ParseGrp4(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);116 unsigned ParseGrp5(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);117 unsigned Parse3DNow(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);118 unsigned ParseGrp6(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);119 unsigned ParseGrp7(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);120 unsigned ParseGrp8(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);121 unsigned ParseGrp9(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);122 unsigned ParseGrp10(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);123 unsigned ParseGrp12(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);124 unsigned ParseGrp13(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);125 unsigned ParseGrp14(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);126 unsigned ParseGrp15(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);127 unsigned ParseGrp16(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);128 unsigned ParseModFence(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);129 unsigned ParseNopPause(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);130 131 unsigned ParseYv(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);132 unsigned ParseYb(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);133 unsigned ParseXv(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);134 unsigned ParseXb(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);135 136 /* Floating point parsing */137 unsigned ParseEscFP(RTUINTPTR pu8CodeBlock, PCOPCODE pOp, POP_PARAMETER pParam, PDISCPUSTATE pCpu);138 139 76 void disValidateLockSequence(PDISCPUSTATE pCpu); 140 141 /* Disassembler printf */142 void disasmSprintf(char *pszOutput, RTUINTPTR pu8Instruction, PDISCPUSTATE pCpu, POP_PARAMETER pParam1, POP_PARAMETER pParam2, POP_PARAMETER pParam3 = NULL);143 void disasmGetPtrString(PDISCPUSTATE pCpu, PCOPCODE pOp, POP_PARAMETER pParam);144 void disasmModRMReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam, int fRegAddr);145 void disasmModRMReg16(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam);146 void disasmModRMSReg(PDISCPUSTATE pCpu, PCOPCODE pOp, unsigned idx, POP_PARAMETER pParam);147 void disasmPrintAbs32(POP_PARAMETER pParam);148 void disasmPrintDisp32(POP_PARAMETER pParam);149 void disasmPrintDisp64(POP_PARAMETER pParam);150 void disasmPrintDisp8(POP_PARAMETER pParam);151 void disasmPrintDisp16(POP_PARAMETER pParam);152 153 77 154 78 /* Read functions */ … … 161 85 size_t disFormatBytes(PCDISCPUSTATE pCpu, char *pszDst, size_t cchDst, uint32_t fFlags); 162 86 163 #endif /* !___DisasmInternal_h___ */87 #endif 164 88 -
trunk/src/VBox/Disassembler/DisasmReg.cpp
r41663 r41668 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBox disassembler: 4 * Core components 3 * VBox disassembler- Register Info Helpers. 5 4 */ 6 5 7 6 /* 8 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 9 8 * 10 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 22 21 *******************************************************************************/ 23 22 #define LOG_GROUP LOG_GROUP_DIS 24 #ifdef USING_VISUAL_STUDIO25 # include <stdafx.h>26 #endif27 28 23 #include <VBox/dis.h> 29 24 #include <VBox/disopcode.h> … … 36 31 #include "DisasmInternal.h" 37 32 #include "DisasmTables.h" 38 39 #if !defined(DIS_CORE_ONLY) && defined(LOG_ENABLED)40 # include <stdlib.h>41 # include <stdio.h>42 #endif43 33 44 34 … … 825 815 return VERR_INVALID_PARAMETER; 826 816 } 827 //***************************************************************************** 828 //***************************************************************************** 817 -
trunk/src/VBox/Disassembler/DisasmTables.cpp
r40577 r41668 1 /* $Id$ */ 1 2 /** @file 2 * VBox disassembler - Tables .3 * VBox disassembler - Tables for X86 (32-bit and 16-bit modes). 3 4 */ 4 5 5 6 /* 6 * Copyright (C) 2006-201 1Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 7 8 * 8 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 19 20 * Header Files * 20 21 *******************************************************************************/ 21 #ifdef USING_VISUAL_STUDIO22 # include <stdafx.h>23 #endif24 22 #include <VBox/dis.h> 25 23 #include <VBox/disopcode.h> … … 27 25 #include "DisasmInternal.h" 28 26 29 30 /** @def O31 * Wrapper which initializes an OPCODE.32 * We must use this so that we can exclude unused fields in order33 * to save precious bytes in the GC version.34 *35 * @internal36 */37 #ifndef DIS_CORE_ONLY38 # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \39 { pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype }40 #else41 # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \42 { idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype }43 #endif44 27 45 28 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -
trunk/src/VBox/Disassembler/DisasmTables.h
r28800 r41668 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBox disassembler: 4 * Tables.header 3 * VBox disassembler - Tables Header. 5 4 */ 6 5 7 6 /* 8 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 9 8 * 10 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 16 */ 18 17 19 #ifndef __ disasmtable_h__20 #define __ disasmtable_h__18 #ifndef ___disasmtable_h___ 19 #define ___disasmtable_h___ 21 20 22 21 #include <VBox/dis.h> … … 99 98 /** @} */ 100 99 101 #endif /* !__disasmtable_h__ */ 100 /** @def OP 101 * Wrapper which initializes an OPCODE. 102 * We must use this so that we can exclude unused fields in order 103 * to save precious bytes in the GC version. 104 * 105 * @internal 106 */ 107 #ifndef DIS_CORE_ONLY 108 # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \ 109 { pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype } 110 #else 111 # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \ 112 { idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype } 113 #endif 102 114 115 #endif 116 -
trunk/src/VBox/Disassembler/DisasmTablesX64.cpp
r38733 r41668 1 /* $Id$ */ 1 2 /** @file 2 * VBox disassembler - Tables for AMD64 ( longmode).3 * VBox disassembler - Tables for AMD64 (64-bit mode). 3 4 */ 4 5 5 6 /* 6 * Copyright (C) 2006-201 1Oracle Corporation7 * Copyright (C) 2006-2012 Oracle Corporation 7 8 * 8 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 19 20 * Header Files * 20 21 *******************************************************************************/ 21 #ifdef USING_VISUAL_STUDIO22 # include <stdafx.h>23 #endif24 22 #include <VBox/dis.h> 25 23 #include <VBox/disopcode.h> … … 27 25 #include "DisasmInternal.h" 28 26 29 30 /** @def O31 * Wrapper which initializes an OPCODE.32 * We must use this so that we can exclude unused fields in order33 * to save precious bytes in the GC version.34 *35 * @internal36 */37 #ifndef DIS_CORE_ONLY38 # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \39 { pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype }40 #else41 # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \42 { idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype }43 #endif44 27 45 28 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -
trunk/src/VBox/Disassembler/DisasmTestCore.cpp
r41658 r41668 39 39 unsigned cb; 40 40 DISCPUSTATE cpu; 41 if (DISCoreOne Ex((uintptr_t)&DISCoreOneEx, CPUMODE_32BIT, NULL /*pfnReadBytes*/, NULL /*pvUser*/, &cpu, &cb))41 if (DISCoreOne((uintptr_t)&DISCoreOne, CPUMODE_32BIT, &cpu, &cb)) 42 42 printf("ok %d\n", cpu.addrmode); 43 43 else -
trunk/src/VBox/Disassembler/testcase/tstDisasm-2.cpp
r41658 r41668 103 103 #endif 104 104 105 RTPrintf(" %s ; % 08llu %s", szTmp, pState->uAddress, pState->szLine);105 RTPrintf(" %s ; %s", szTmp, pState->szLine); 106 106 } 107 107
Note:
See TracChangeset
for help on using the changeset viewer.