Disasm.cpp revision 99cd1ce586a12bf6b8c6084cbcdebe8fe3553cc2
/** @file
*
* VBox disassembler:
* Main
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef USING_VISUAL_STUDIO
# include <stdafx.h>
#endif
#include <VBox/disopcode.h>
#include "DisasmInternal.h"
#include "DisasmTables.h"
/**
* Disassembles one instruction
*
* @returns VBox error code
* @param pCpu Pointer to cpu structure which have DISCPUSTATE::mode
* set correctly.
* @param uInstrAddr Pointer to the structure to disassemble.
* @param pcbSize Where to store the size of the instruction.
* NULL is allowed.
* @param pszOutput Storage for disassembled instruction
*
* @todo Define output callback.
*/
DISDECL(int) DISInstr(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PDISCPUSTATE pCpu, uint32_t *pcbSize, char *pszOutput)
{
}
/**
* Disassembles one instruction
*
* @returns VBox error code
* @param pCpu Pointer to cpu structure which have DISCPUSTATE::mode
* set correctly.
* @param uInstrAddr Pointer to the structure to disassemble.
* @param offRealAddr Offset to add to instruction address to get the real
* virtual address.
* @param pcbSize Where to store the size of the instruction.
* NULL is allowed.
* @param pszOutput Storage for disassembled instruction
*
* @todo Define output callback.
*/
{
return DISInstrEx(uInstrAddr, offRealAddr, pCpu->mode, pCpu->pfnReadBytes, pCpu->apvUserData[0], OPTYPE_ALL,
}
/**
* Disassembles one instruction with a byte fetcher caller.
*
* @returns VBox error code
* @param uInstrAddr Pointer to the structure to disassemble.
* @param enmCpuMode The CPU mode.
* @param pfnCallback The byte fetcher callback.
* @param pvUser The user argument (found in
* DISCPUSTATE::apvUserData[0]).
* @param pCpu Where to return the disassembled instruction.
* @param pcbSize Where to store the size of the instruction.
* NULL is allowed.
* @param pszOutput Storage for disassembled instruction
*
* @todo Define output callback.
*/
DISDECL(int) DISInstrWithReader(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PFNDISREADBYTES pfnReadBytes, void *pvUser,
{
}
/**
* Disassembles one instruction; only fully disassembly an instruction if it matches the filter criteria
*
* @returns VBox error code
* @param pCpu Pointer to cpu structure which have DISCPUSTATE::mode
* set correctly.
* @param uInstrAddr Pointer to the structure to disassemble.
* @param u32EipOffset Offset to add to instruction address to get the real virtual address
* @param pcbSize Where to store the size of the instruction.
* NULL is allowed.
* @param pszOutput Storage for disassembled instruction
* @param uFilter Instruction type filter
*
* @todo Define output callback.
*/
{
const OPCODE *paOneByteMap;
/*
* Initialize the CPU state.
* Note! The RT_BZERO make ASSUMPTIONS about the placement of apvUserData.
*/
if (enmCpuMode == CPUMODE_64BIT)
{
}
else
{
}
/*
* Parse the instruction byte by byte.
*/
unsigned i = 0;
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... */
for (;;)
{
/* Hardcoded assumption about OP_* values!! */
if (opcode <= OP_LAST_PREFIX)
{
/* The REX prefix must precede the opcode byte(s). Any other placement is ignored. */
{
}
switch (opcode)
{
case OP_INVALID:
if (pcbSize)
// segment override prefix byte
case OP_SEG:
/* Segment prefixes for CS, DS, ES and SS are ignored in long mode. */
i += sizeof(uint8_t);
cbPrefix++;
continue; //fetch the next byte
// lock prefix byte
case OP_LOCK:
i += sizeof(uint8_t);
cbPrefix++;
continue; //fetch the next byte
// address size override prefix byte
case OP_ADDRSIZE:
else
else
i += sizeof(uint8_t);
cbPrefix++;
continue; //fetch the next byte
// operand size override prefix byte
case OP_OPSIZE:
else
pCpu->opmode = CPUMODE_16BIT; /* for 32 and 64 bits mode (there is no 32 bits operand size override prefix) */
i += sizeof(uint8_t);
cbPrefix++;
continue; //fetch the next byte
// rep and repne are not really prefixes, but we'll treat them as such
case OP_REPE:
i += sizeof(uint8_t);
continue; //fetch the next byte
case OP_REPNE:
i += sizeof(uint8_t);
continue; //fetch the next byte
case OP_REX:
/* REX prefix byte */
i += sizeof(uint8_t);
continue; //fetch the next byte
}
}
unsigned idx = i;
i += sizeof(uint8_t); //first opcode byte
if (pszOutput)
disasmSprintf(pszOutput, uInstrAddr+i-1-cbPrefix, pCpu, &pCpu->param1, &pCpu->param2, &pCpu->param3);
i += cbInc;
cbPrefix = 0;
break;
}
if (pcbSize)
*pcbSize = i;
}
//*****************************************************************************
//*****************************************************************************
{
while (off < 40)
}
//*****************************************************************************
//*****************************************************************************
{
int param = 1;
{
off += RTStrPrintf(&pszOutput[off], 64, "Invalid Opcode [%02X][%02X]", pCpu->abInstr[0], pCpu->abInstr[1]);
else
}
else
while (*pszFormat)
{
switch (*pszFormat)
{
case '%':
switch (pszFormat[1])
{
case 'J': //Relative jump offset
{
/** @todo: is this correct? */
else
{
AssertMsgFailed(("Oops!\n"));
return;
}
}
//no break;
case 'A': //direct address
case 'C': //control register
case 'D': //debug register
case 'E': //ModRM specifies parameter
case 'F': //Eflags register
case 'G': //ModRM selects general register
case 'I': //Immediate data
case 'M': //ModRM may only refer to memory
case 'O': //No ModRM byte
case 'P': //ModRM byte selects MMX register
case 'Q': //ModRM byte selects MMX register or memory address
case 'R': //ModRM byte may only refer to a general register
case 'S': //ModRM byte selects a segment register
case 'T': //ModRM byte selects a test register
case 'X': //DS:SI
case 'Y': //ES:DI
switch(param)
{
case 1:
break;
case 2:
break;
case 3:
break;
}
break;
case 'e': //register based on operand size (e.g. %eAX)
break;
default:
AssertMsgFailed(("Oops!\n"));
break;
}
//Go to the next parameter in the format string
pszFormat++;
if (*pszFormat == ',')
pszFormat--;
break;
case ',':
param++;
//no break
default:
break;
}
if (*pszFormat)
pszFormat++;
}
}
//*****************************************************************************
//*****************************************************************************