示例#1
0
/*
 * ScrollAsmDisplay - move asm display in response to a scroll request
 */
void ScrollAsmDisplay( HWND hwnd, WORD wparam, ADDRESS *paddr,
                       ADDRESS *flagaddr, int idlo, int idhi, int sbid )
{
    int         i;
    char        buff[256];

    switch( wparam ) {
    case SB_PAGEDOWN:
        for( i=0;i<8;i++ ) {
            paddr->offset += Disassemble( paddr, buff, FALSE );
        }
        break;
    case SB_PAGEUP:
        for( i=0;i<8;i++ ) {
            InstructionBackup( 1, paddr );
        }
        break;
    case SB_LINEDOWN:
        paddr->offset += Disassemble( paddr, buff, FALSE );
        break;
    case SB_LINEUP:
        InstructionBackup( 1, paddr );
        break;
    default:
        return;
    }
    DisplayAsmLines( hwnd, paddr, flagaddr, idlo, idhi, sbid );

} /* ScrollAsmDisplay */
示例#2
0
文件: svalue.cpp 项目: ufasoft/lisp
CP CLispEng::FromFunctionDesignator(CP p) {
	CSPtr q;
	switch (Type(p)) {
	case TS_INTFUNC:
	case TS_SUBR:
	case TS_CCLOSURE:
		return p;
	case TS_SYMBOL:
		q =  ToSymbol(p)->GetFun();
		break;
	case TS_CONS:
		if (FunnameP(p)) {
			q = ToSymbol(GetSymProp(Car(Cdr(p)), S(L_SETF_FUNCTION)))->GetFun();
			break;
		}
	default:
		E_TypeErr(p, 0, IDS_E_IsNotAFunctionName, GetSubrName(m_subrSelf), p);
	}
	switch (Type(q)) {
	case TS_INTFUNC:
	case TS_SUBR:
	case TS_CCLOSURE:
		return q;
	default:
#ifdef X_TEST //!!!D
		Print(p);
		Disassemble(cerr, CurClosure);
#endif
		E_UndefinedFunction(p);
	}
}
示例#3
0
BOOL	RXGetLine(char *args) {
ULONG addr, line = 0;
long	info[2];    //	info[0] == lineBeg, info[1] == lineNo
WORD type, i;
short undef = TRUE;


    if(*args) {
        addr = ParseExp(args, &undef, strlen(args));
    }
    if(undef)addr = programPC;
    type = CurrentMixedLine(&addr, &line, info);
    if(type == MIXTYPE_SOURCE) {
	char *lineStr = (char *)info[0];
	for (i = 0; lineStr[i] && lineStr[i] != '\n'; ++i)
   	 ;
        sprintf(RexxReplyString,"%6d. ", info[1]); 
	strncat(RexxReplyString, lineStr, i);
    }
    else {
	sprintf(RexxReplyString,"%08X",addr);
	strcat(RexxReplyString," ");
	i=strlen(RexxReplyString);
	Disassemble(addr, addr, &RexxReplyString[i]);
    }
    return TRUE;
}
示例#4
0
/*
================
idProgram::CompileFile
================
*/
void idProgram::CompileFile( const char *filename ) {
	char *src;
	bool result;

	if ( fileSystem->ReadFile( filename, ( void ** )&src, NULL ) < 0 ) {
		gameLocal.Error( "Couldn't load %s\n", filename );
	}

#ifdef _HH_GLOBAL_COUNTER //HUMANHEAD rww
	if (globalOutputFile) {
		globalOutputFile->Printf("========================\r\nScript %s\r\n========================\r\n", filename);
		globalOutputUnique = 0;
		globalOutputRunningSize = 0;
	}
#endif //HUMANHEAD END

	result = CompileText( filename, src, false );

	fileSystem->FreeFile( src );

	if ( g_disasm.GetBool() ) {
		Disassemble();
	}

	if ( !result ) {
		gameLocal.Error( "Compile failed in file %s.", filename );
	}

#ifdef _HH_GLOBAL_COUNTER //HUMANHEAD rww
	if (globalOutputFile) {
		globalOutputFile->Printf("========================\r\n%s\r\nUnique variables: %i\r\nVariable size: %i\r\n========================\r\n", filename, globalOutputUnique, globalOutputRunningSize);
	}
#endif //HUMANHEAD END
}
示例#5
0
// This test goes from text ASM to binary to text ASM and once again back to binary.
// Very convenient for testing. Then the two binaries are compared.
bool SuperTrip(const char *asm_code)
{
	std::vector<u16> code1, code2;
	std::string text;
	if (!Assemble(asm_code, code1))
	{
		printf("SuperTrip: First assembly failed\n");
		return false;
	}
	printf("First assembly: %i words\n", (int)code1.size());
	if (!Disassemble(code1, false, text))
	{
		printf("SuperTrip: Disassembly failed\n");
		return false;
	}
	else
	{
		printf("Disass:\n");
		printf("%s", text.c_str());
	}
	if (!Assemble(text.c_str(), code2))
	{
		printf("SuperTrip: Second assembly failed\n");
		return false;
	}
	/*
	std::string text2;
	Disassemble(code1, true, &text1);
	Disassemble(code2, true, &text2);
	File::WriteStringToFile(text1, "code1.txt");
	File::WriteStringToFile(text2, "code2.txt");
	*/
	return true;
}
示例#6
0
void CDead6800::Step()
{
u8 Opcode;										//current opcode
u8 tmp,ntmp,otmp;								//temp variables used by opcodes
u32 tmp2,tmp3;

CHECK_INTERRUPTS;
if(WaitInterrupt)
	{
	AddCycles(1);
	return;
	}
SavePC = PC;
Opcode = OpRead(PC++);
switch(Opcode)
	{
	#include "Dead6800switch.cpp"
	}
AddCycles(c6800Cycles[Opcode]);
//debug crap
if(Debug == 3)
	{
	char dis[128];

	Disassemble(dis,SavePC);
	message("$%04X: %s D=$%04X X=$%04X S=$%04X CC=$%02X\n",SavePC,dis,D,X,S,CC);
	}
}
示例#7
0
/**
* Shows the code at the bookmark address in the disassembly window
*
* @param hwnd HWND of the debugger window
**/
void GoToDebuggerBookmark(HWND hwnd)
{
	int selectedItem = SendDlgItemMessage(hwnd, LIST_DEBUGGER_BOOKMARKS, LB_GETCURSEL, 0, 0);
	// If no bookmark is selected just return
	if (selectedItem == LB_ERR) return;
	unsigned int n = getBookmarkAddress(selectedItem);
	Disassemble(hwnd, IDC_DEBUGGER_DISASSEMBLY, IDC_DEBUGGER_DISASSEMBLY_VSCR, n);
}
static void AddressError( char *ErrorString )
{
    char buffer[80];

    Disassemble( Pmem+PC, buffer );
    DisplayError( !FATAL, "Error: %s, PC = %d, SP = %d, FP = %d\n", 
                  ErrorString, PC, SP, FP );
    DisplayError( !FATAL, "       Instruction \"%s\"\n", buffer );
}
示例#9
0
int main(int argc, const char *argv[])
{
	for (int i = 1; i < argc; ++i)
	{
		Disassemble(argv[i]);
	}

	return 0;
}
示例#10
0
//---------------------------------------------------------------------------
void tTJSInterCodeContext::Disassemble(
	void (*output_func)(const tjs_char *msg,void *data), void *data, tjs_int start,
		tjs_int end)

{
	// dis-assemble
	of_data dat;
	dat.func =  output_func;
	dat.funcdata = data;
	Disassemble(_output_func, _output_func_src, (void*)&dat, start, end);
}
示例#11
0
// This test goes from text ASM to binary to text ASM and once again back to binary.
// Then the two binaries are compared.
bool RoundTrip(const std::vector<u16> &code1)
{
	std::vector<u16> code2;
	std::string text;
	if (!Disassemble(code1, false, text))
	{
		printf("RoundTrip: Disassembly failed.\n");
		return false;
	}
	if (!Assemble(text.c_str(), code2))
	{
		printf("RoundTrip: Assembly failed.\n");
		return false;
	}
	if (!Compare(code1, code2))
	{
		Disassemble(code1, true, text);
		printf("%s", text.c_str());
	}
	return true;
}
示例#12
0
/*
================
idProgram::CompileFunction
================
*/
const function_t *idProgram::CompileFunction( const char *functionName, const char *text ) {
	bool result;

	result = CompileText( functionName, text, false );

	if ( g_disasm.GetBool() ) {
		Disassemble();
	}

	if ( !result ) {
		gameLocal.Error( "Compile failed." );
	}

	return FindFunction( functionName );
}
示例#13
0
BOOL	RXGetDismLine(char *args) {
ULONG addr;
short undef = TRUE, i;


    if(*args) {
        addr = ParseExp(args, &undef, strlen(args));
    }
    if(undef)addr = programPC;
	sprintf(RexxReplyString,"%08X",addr);
	strcat(RexxReplyString," ");
	i=strlen(RexxReplyString);
	Disassemble(addr, addr, &RexxReplyString[i]);
    return TRUE;
}
示例#14
0
/*
 * DisplayAsmLines - display all assembler lines
 *      hwnd     - dialog handle
 *      paddr    - address to start dissassembly
 *      flagaddr - address of instruction to mark
 *      idlo     - id of first text field
 *      idhi     - id of last text field (text field id's must be contiguous)
 *      sbid     - scroll bar id
 */
void DisplayAsmLines( HWND hwnd, ADDRESS *paddr, ADDRESS *flagaddr, int idlo,
                        int idhi, int sbid )
{
    int         i;
    ADDRESS     addr;
    char        buff[256];
    HWND        hscrl;
    BOOL        markit;
    DWORD       max;
    int         curr;

    addr = *paddr;
    for( i=idlo;i<=idhi;i++ ) {
        markit = FALSE;
        if( (addr.seg == flagaddr->seg ) &&
            (addr.offset == flagaddr->offset )) markit = TRUE;
        addr.offset += Disassemble( &addr, buff+1, FALSE );
        if( markit ) {
            buff[0] = '*';
        } else {
            buff[0] = ' ';
        }
        SetDlgItemText( hwnd, i, buff );
    }

#ifdef __NT__
    max = max;
    curr = curr;
    hscrl = GetDlgItem( hwnd, sbid );
    SetScrollRange( hscrl, SB_CTL, 0, 2, FALSE);
    SetScrollPos( hscrl, SB_CTL, 1, TRUE );
#else
    max = GetASelectorLimit( paddr->seg );
    if( max > MAXRANGE ) {
        curr = (MAXRANGE*paddr->offset)/max;
        max = MAXRANGE;
    } else {
        curr = paddr->offset;
    }
    hscrl = GetDlgItem( hwnd, sbid );
    SetScrollRange( hscrl, SB_CTL, 0, max, FALSE);
    SetScrollPos( hscrl, SB_CTL, curr, TRUE );
#endif
} /* DisplayAsmLines */
示例#15
0
/*
 *	xpt_linker	-	main entry-point for linker plugin
 *
 */
pascal short xpt_linker(CWPluginContext context)
{
	long request;
	if (CWGetPluginRequest(context, &request) != cwNoErr)
		return cwErrRequestFailed;
	
	gPluginContext = context;
	short result = cwNoErr;
		
	/* dispatch on linker request */
	switch (request) {
	case reqInitLinker:
		/* linker has just been loaded into memory */
		break;
		
	case reqTermLinker:
		/* linker is about to be unloaded from memory */
		break;
		
	case reqLink:
		/* build the final executable */
		result = Link(context);
		break;
		
	case reqDisassemble:
		/* disassemble object code for a given project file */
		result = Disassemble(context);
		break;
	
	case reqTargetInfo:
		/* return info describing target characteristics */
		result = GetTargetInfo(context);
		break;
		
	default:
		result = cwErrRequestFailed;
		break;
	}
	
	result = CWDonePluginRequest(context, result);
	
	/* return result code */
	return result;
}
示例#16
0
/*
 * DisplayAsmLines - display all assembler lines
 *      hwnd     - dialog handle
 *      paddr    - address to start dissassembly
 */
static void DisplayAsmLines( HWND hwnd, address *paddr )
{
    int         i;
    address     addr;
    address     flagaddr;
    char        buff[256];
    HWND        hscrl;
    DWORD       max;
    int         curr;
    mad_registers   *regs;

    addr = *paddr;
    regs = StatGetMadRegisters( hwnd );
    GetCurrAddr( &flagaddr, regs );

    for( i = STAT_DISASM_1;i <= STAT_DISASM_8; i++ ) {
        buff[0] = ' ';
        if( MADAddrComp( &addr, &flagaddr, MAF_FULL ) == 0 ) {
            buff[0] = '*';
        }

        Disassemble( &addr, buff+1, FALSE, 255 );
        SetDlgItemText( hwnd, i, buff );
    }

#ifdef __NT__
    max = max;
    curr = curr;
    hscrl = GetDlgItem( hwnd, STAT_SCROLL );
    SetScrollRange( hscrl, SB_CTL, 0, 2, FALSE );
    SetScrollPos( hscrl, SB_CTL, 1, TRUE );
#else
    max = GetASelectorLimit( paddr->mach.segment );
    if( max > MAXRANGE ) {
        curr = ( MAXRANGE * paddr->mach.offset ) / max;
        max = MAXRANGE;
    } else {
        curr = paddr->mach.offset;
    }
    hscrl = GetDlgItem( hwnd, STAT_SCROLL );
    SetScrollRange( hscrl, SB_CTL, 0, max, FALSE);
    SetScrollPos( hscrl, SB_CTL, curr, TRUE );
#endif
} /* DisplayAsmLines */
示例#17
0
/*
================
idProgram::CompileFile
================
*/
void idProgram::CompileFile( const char *filename ) {
	char *src;
	bool result;

	if ( fileSystem->ReadFile( filename, ( void ** )&src, NULL ) < 0 ) {
		gameLocal.Error( "Couldn't load %s\n", filename );
	}

	result = CompileText( filename, src, false );

	fileSystem->FreeFile( src );

	if ( g_disasm.GetBool() ) {
		Disassemble();
	}

	if ( !result ) {
		gameLocal.Error( "Compile failed in file %s.", filename );
	}
}
示例#18
0
文件: nid_table.c 项目: 173210/VHL
int nid_table_analyzeStub(const void *stub, SceNID nid, nidTable_entry *entry)
{
        entry->nid = nid;
        entry->value.i = 0;

        ARM_INSTRUCTION instr;

        while(1)
        {
                if(Disassemble(stub, &instr) < 0)
                        return ANALYZE_STUB_INVAL;

                switch(instr.instruction)
                {
                        case ARM_INST_MOVW:
                                entry->value.i = instr.value[1];
                                break;
                        case ARM_INST_MOVT:
                                entry->value.i |= instr.value[1] << 16;
                                break;

                        case ARM_INST_BX:
                        case ARM_INST_BLX:
                                entry->type = ENTRY_TYPES_FUNCTION;
                                return ANALYZE_STUB_OK;

                        case ARM_INST_SVC:
                                entry->type = ENTRY_TYPES_SYSCALL;
                                return ANALYZE_STUB_OK;

                        case ARM_INST_MVN:
                                return ANALYZE_STUB_UNRESOLVED;

                        default:
                                DEBUG_LOG_("ERROR");
                                return ANALYZE_STUB_INVAL;
                }
                stub = (char*)stub + sizeof(SceUInt);
        }
}
示例#19
0
pascal short xpidl_compiler(CWPluginContext context)
{
	long request;
	if (CWGetPluginRequest(context, &request) != cwNoErr)
		return cwErrRequestFailed;
	
	gPluginContext = context;
	short result = cwNoErr;
	
	/* dispatch on compiler request */
	switch (request) {
	case reqInitCompiler:
		/* compiler has just been loaded into memory */
		break;
		
	case reqTermCompiler:
		/* compiler is about to be unloaded from memory */
		break;
		
	case reqCompile:
		/* compile a source file */
		result = Compile(context);
		break;
	
	case reqCompDisassemble:
		/* disassemble a source file */
		result = Disassemble(context);
		break;
	
	default:
		result = cwErrRequestFailed;
		break;
	}
	
	/* is this necessary? */
	CWDonePluginRequest(context, result);
	
	/* return result code */
	return (result);
}
DisassembleResult Disassemble(OutputFile &pOutput, const char *pTriple,
                              const char *pFuncName, const uint8_t *pFunc,
                              size_t FuncSize) {
  // Check the state of the specified output file.
  if (pOutput.hasError()) {
    return kDisassembleInvalidOutput;
  }

  // Open the output file decorated in llvm::raw_ostream.
  llvm::raw_ostream *output = pOutput.dup();
  if (output == NULL) {
    return kDisassembleFailedPrepareOutput;
  }

  // Delegate the request.
  DisassembleResult result =
      Disassemble(*output, pTriple, pFuncName, pFunc, FuncSize);

  // Close the output before return.
  delete output;

  return result;
}
示例#21
0
/*
 * logDisasm - log some disassembly
 */
static void logDisasm( ExceptDlgInfo *info ) {
    int         i;
    address     addr;
    address     flagaddr;
    char        str[256];

    SetDisasmInfo( info->procinfo->prochdl, info->module );

    GetCurrAddr( &flagaddr, info->regs );
    addr = flagaddr;
    InstructionBackward( LogData.asm_bkup, &addr );

    for( i = 0; i <= LogData.asm_cnt; i++ ) {
        if( MADAddrComp( &addr, &flagaddr, MAF_FULL ) == 0 ) {
            logStrPrintf( "--->" );
        } else {
            logStrPrintf( "    " );
        }

        Disassemble( &addr, str, TRUE, 255 );
        logStrPrintf( "%s\n", str );
    }

} /* logDisasm */
示例#22
0
Cell::SPtr const Document::GetCell(Address const& rAddr) const
{
  boost::mutex::scoped_lock Lock(m_CellMutex);

  CellData CurCellData;
  if (!m_spDatabase->GetCellData(rAddr, CurCellData))
    return nullptr;
  auto spCellData = std::make_shared<CellData>(CurCellData); // TODO: we can avoid this

  switch (CurCellData.GetType())
  {
  case Cell::ValueType:     return std::make_shared<Value>(spCellData);
  case Cell::CharacterType: return std::make_shared<Character>(spCellData);
  case Cell::StringType:    return std::make_shared<String>(spCellData);
  case Cell::InstructionType:
    {
      auto spInsn = std::make_shared<Instruction>();
      spInsn->GetData()->ArchitectureTag() = CurCellData.GetArchitectureTag();
      spInsn->Mode() = CurCellData.GetMode();
      auto spArch = ModuleManager::Instance().GetArchitecture(CurCellData.GetArchitectureTag());
      if (spArch == nullptr)
      {
        Log::Write("core") << "unable to get architecture for " << rAddr << LogEnd;
        return nullptr;
      }
      TOffset Offset;
      ConvertAddressToFileOffset(rAddr, Offset);
      spArch->Disassemble(GetBinaryStream(), Offset, *spInsn, CurCellData.GetMode());
      return spInsn;
    }
  default:
    break;
  }

  return Cell::SPtr();
}
int Compiler::compile(bool compileOnly) {
  llvm::Target const *Target = NULL;
  llvm::TargetData *TD = NULL;
  llvm::TargetMachine *TM = NULL;

  std::string FeaturesStr;

  llvm::NamedMDNode const *PragmaMetadata;
  llvm::NamedMDNode const *ExportVarMetadata;
  llvm::NamedMDNode const *ExportFuncMetadata;
  llvm::NamedMDNode const *ObjectSlotMetadata;

  if (mModule == NULL)  // No module was loaded
    return 0;

  // Create TargetMachine
  Target = llvm::TargetRegistry::lookupTarget(Triple, mError);
  if (hasError())
    goto on_bcc_compile_error;

  if (!CPU.empty() || !Features.empty()) {
    llvm::SubtargetFeatures F;

    for (std::vector<std::string>::const_iterator
         I = Features.begin(), E = Features.end(); I != E; I++) {
      F.AddFeature(*I);
    }

    FeaturesStr = F.getString();
  }

#if defined(DEFAULT_X86_64_CODEGEN)
  // Data address in X86_64 architecture may reside in a far-away place
  TM = Target->createTargetMachine(Triple, CPU, FeaturesStr,
                                   llvm::Reloc::Static,
                                   llvm::CodeModel::Medium);
#else
  // This is set for the linker (specify how large of the virtual addresses
  // we can access for all unknown symbols.)
  TM = Target->createTargetMachine(Triple, CPU, FeaturesStr,
                                   llvm::Reloc::Static,
                                   llvm::CodeModel::Small);
#endif
  if (TM == NULL) {
    setError("Failed to create target machine implementation for the"
             " specified triple '" + Triple + "'");
    goto on_bcc_compile_error;
  }

  // Get target data from Module
  TD = new llvm::TargetData(mModule);

  // Load named metadata
  ExportVarMetadata = mModule->getNamedMetadata(ExportVarMetadataName);
  ExportFuncMetadata = mModule->getNamedMetadata(ExportFuncMetadataName);
  PragmaMetadata = mModule->getNamedMetadata(PragmaMetadataName);
  ObjectSlotMetadata = mModule->getNamedMetadata(ObjectSlotMetadataName);

  // Perform link-time optimization if we have multiple modules
  if (mHasLinked) {
    runLTO(new llvm::TargetData(*TD), ExportVarMetadata, ExportFuncMetadata);
  }

  // Perform code generation
#if USE_OLD_JIT
  if (runCodeGen(new llvm::TargetData(*TD), TM,
                 ExportVarMetadata, ExportFuncMetadata) != 0) {
    goto on_bcc_compile_error;
  }
#endif

#if USE_MCJIT
  if (runMCCodeGen(new llvm::TargetData(*TD), TM) != 0) {
    goto on_bcc_compile_error;
  }

  if (compileOnly)
    return 0;

  // Load the ELF Object
  mRSExecutable =
    rsloaderCreateExec((unsigned char *)&*mEmittedELFExecutable.begin(),
                       mEmittedELFExecutable.size(),
                       &resolveSymbolAdapter, this);

  if (!mRSExecutable) {
    setError("Fail to load emitted ELF relocatable file");
    goto on_bcc_compile_error;
  }

  if (ExportVarMetadata) {
    ScriptCompiled::ExportVarList &varList = mpResult->mExportVars;
    std::vector<std::string> &varNameList = mpResult->mExportVarsName;

    for (int i = 0, e = ExportVarMetadata->getNumOperands(); i != e; i++) {
      llvm::MDNode *ExportVar = ExportVarMetadata->getOperand(i);
      if (ExportVar != NULL && ExportVar->getNumOperands() > 1) {
        llvm::Value *ExportVarNameMDS = ExportVar->getOperand(0);
        if (ExportVarNameMDS->getValueID() == llvm::Value::MDStringVal) {
          llvm::StringRef ExportVarName =
            static_cast<llvm::MDString*>(ExportVarNameMDS)->getString();

          varList.push_back(
            rsloaderGetSymbolAddress(mRSExecutable,
                                     ExportVarName.str().c_str()));
          varNameList.push_back(ExportVarName.str());
#if DEBUG_MCJIT_REFLECT
          LOGD("runMCCodeGen(): Exported Var: %s @ %p\n", ExportVarName.str().c_str(),
               varList.back());
#endif
          continue;
        }
      }

      varList.push_back(NULL);
    }
  }

  if (ExportFuncMetadata) {
    ScriptCompiled::ExportFuncList &funcList = mpResult->mExportFuncs;
    std::vector<std::string> &funcNameList = mpResult->mExportFuncsName;

    for (int i = 0, e = ExportFuncMetadata->getNumOperands(); i != e; i++) {
      llvm::MDNode *ExportFunc = ExportFuncMetadata->getOperand(i);
      if (ExportFunc != NULL && ExportFunc->getNumOperands() > 0) {
        llvm::Value *ExportFuncNameMDS = ExportFunc->getOperand(0);
        if (ExportFuncNameMDS->getValueID() == llvm::Value::MDStringVal) {
          llvm::StringRef ExportFuncName =
            static_cast<llvm::MDString*>(ExportFuncNameMDS)->getString();

          funcList.push_back(
            rsloaderGetSymbolAddress(mRSExecutable,
                                     ExportFuncName.str().c_str()));
          funcNameList.push_back(ExportFuncName.str());
#if DEBUG_MCJIT_RELECT
          LOGD("runMCCodeGen(): Exported Func: %s @ %p\n", ExportFuncName.str().c_str(),
               funcList.back());
#endif
        }
      }
    }
  }

#if DEBUG_MCJIT_DISASSEMBLER
  {
    // Get MC codegen emitted function name list
    size_t func_list_size = rsloaderGetFuncCount(mRSExecutable);
    std::vector<char const *> func_list(func_list_size, NULL);
    rsloaderGetFuncNameList(mRSExecutable, func_list_size, &*func_list.begin());

    // Disassemble each function
    for (size_t i = 0; i < func_list_size; ++i) {
      void *func = rsloaderGetSymbolAddress(mRSExecutable, func_list[i]);
      if (func) {
        size_t size = rsloaderGetSymbolSize(mRSExecutable, func_list[i]);
        Disassemble(DEBUG_MCJIT_DISASSEMBLER_FILE,
                    Target, TM, func_list[i], (unsigned char const *)func, size);
      }
    }
  }
#endif
#endif

  // Read pragma information from the metadata node of the module.
  if (PragmaMetadata) {
    ScriptCompiled::PragmaList &pragmaList = mpResult->mPragmas;

    for (int i = 0, e = PragmaMetadata->getNumOperands(); i != e; i++) {
      llvm::MDNode *Pragma = PragmaMetadata->getOperand(i);
      if (Pragma != NULL &&
          Pragma->getNumOperands() == 2 /* should have exactly 2 operands */) {
        llvm::Value *PragmaNameMDS = Pragma->getOperand(0);
        llvm::Value *PragmaValueMDS = Pragma->getOperand(1);

        if ((PragmaNameMDS->getValueID() == llvm::Value::MDStringVal) &&
            (PragmaValueMDS->getValueID() == llvm::Value::MDStringVal)) {
          llvm::StringRef PragmaName =
            static_cast<llvm::MDString*>(PragmaNameMDS)->getString();
          llvm::StringRef PragmaValue =
            static_cast<llvm::MDString*>(PragmaValueMDS)->getString();

          pragmaList.push_back(
            std::make_pair(std::string(PragmaName.data(),
                                       PragmaName.size()),
                           std::string(PragmaValue.data(),
                                       PragmaValue.size())));
#if DEBUG_BCC_REFLECT
          LOGD("compile(): Pragma: %s -> %s\n",
               pragmaList.back().first.c_str(),
               pragmaList.back().second.c_str());
#endif
        }
      }
    }
  }

  if (ObjectSlotMetadata) {
    ScriptCompiled::ObjectSlotList &objectSlotList = mpResult->mObjectSlots;

    for (int i = 0, e = ObjectSlotMetadata->getNumOperands(); i != e; i++) {
      llvm::MDNode *ObjectSlot = ObjectSlotMetadata->getOperand(i);
      if (ObjectSlot != NULL &&
          ObjectSlot->getNumOperands() == 1) {
        llvm::Value *SlotMDS = ObjectSlot->getOperand(0);
        if (SlotMDS->getValueID() == llvm::Value::MDStringVal) {
          llvm::StringRef Slot =
              static_cast<llvm::MDString*>(SlotMDS)->getString();
          uint32_t USlot = 0;
          if (Slot.getAsInteger(10, USlot)) {
            setError("Non-integer object slot value '" + Slot.str() + "'");
            goto on_bcc_compile_error;
          }
          objectSlotList.push_back(USlot);
#if DEBUG_BCC_REFLECT
          LOGD("compile(): RefCount Slot: %s @ %u\n", Slot.str().c_str(), USlot);
#endif
        }
      }
    }
  }

on_bcc_compile_error:
  // LOGE("on_bcc_compiler_error");
  if (TD) {
    delete TD;
  }

  if (TM) {
    delete TM;
  }

  if (mError.empty()) {
    return 0;
  }

  // LOGE(getErrorMessage());
  return 1;
}
示例#24
0
文件: invaders.c 项目: Godzil/EDL
int MEM_Handler()
{
	int keepGoing=g_traceStep^1;
	static unsigned char SYNC_LATCH;
	static int SYNC_A_LATCH;
	static int outOfRange=0;
	static int NewInstructionBegun=-1;

	// Watch for SYNC pulse and TYPE and latch them

	if (PinGetPIN_SYNC())
	{
		SYNC_LATCH=PinGetPIN_D();
		if (SYNC_LATCH==SYNC_FETCH)
		{
			SYNC_A_LATCH=PinGetPIN_A();
			NewInstructionBegun=2;
			if (dumpInstruction>0)
			{
				dumpInstruction--;
				outOfRange=1;
			}
			else
			{
				outOfRange=0;
			}
		}
	}

	if (NewInstructionBegun>-1)
	{
		if (NewInstructionBegun==0)
		{
			if (outOfRange)
				Disassemble(SYNC_A_LATCH);
			if (isBreakpoint(SYNC_A_LATCH))
				g_instructionStep=1;
			if (g_instructionStep)
				keepGoing=0;
		}
		NewInstructionBegun--;
	}

	// CPU INPUT expects data to be available on T2 state so we can do that work on the PIN_SYNC itself
	// Assume memory has no latency
	if (PinGetPIN_SYNC())
	{
		if (SYNC_LATCH==SYNC_FETCH || SYNC_LATCH==SYNC_STACK_READ || SYNC_LATCH==SYNC_MEM_READ)
		{
			if (PinGetPIN_A()>0x3FFF)
			{
				printf("Out of bounds read : %04X | masterClock : %d\n",PinGetPIN_A(),masterClock);
			}
			if ((PinGetPIN_A()&0x2000) == 0x2000)
			{
				PinSetPIN_D(Ram[PinGetPIN_A()&0x1FFF]);
			}
			else
			{
				PinSetPIN_D(Rom[PinGetPIN_A()&0x1FFF]);
			}
			if (dumpInstruction>0)
			{
				printf("Reading : %04X - %02X\n",PinGetPIN_A(),PinGetPIN_D());
			}
			PinSetPIN_READY(1);
			PIN_BUFFER_READY=1;
		}
		else if (SYNC_LATCH==SYNC_STACK_WRITE || SYNC_LATCH==SYNC_MEM_WRITE || SYNC_LATCH==SYNC_OUTPUT)
		{
			PinSetPIN_READY(1);
			PIN_BUFFER_READY=1;
		}
		else if (SYNC_LATCH==SYNC_INPUT)
		{
			PinSetPIN_D(HandleIOPortRead(PinGetPIN_A()&0xFF));
			PinSetPIN_READY(1);
			PIN_BUFFER_READY=1;
		}
		else if (SYNC_LATCH==SYNC_INT_ACK)
		{
			PinSetPIN_D(NEXTINT);
		}
		else
		{
			printf("Error unknown sync state!!! PIN_D = %02X\n",PinGetPIN_D());
			exit(12);
		}
	}
	
	// CPU OUTPUT expects device to have signalled readyness to capture at state T2, but capture occurs at T3 (when _WR is low)
	if (PinGetPIN__WR() == 0)
	{
		if (SYNC_LATCH==SYNC_STACK_WRITE || SYNC_LATCH==SYNC_MEM_WRITE)
		{
			if ((PinGetPIN_A()&0x2000)==0x2000)
			{
				Ram[PinGetPIN_A()&0x1FFF]=PinGetPIN_D();
			}
		}
		else if (SYNC_LATCH==SYNC_OUTPUT)
		{
			HandleIOPortWrite(PinGetPIN_A()&0xFF,PinGetPIN_D());
		}
	}

	return keepGoing;
}
示例#25
0
//---------------------------------------------------------------------------
void tTJSInterCodeContext::Disassemble(tjs_int start, tjs_int end)
{
	Disassemble(tTJSScriptBlock::GetConsoleOutput(), Block, start, end);
}
示例#26
0
//---------------------------------------------------------------------------
void tTJSInterCodeContext::DisassenbleSrcLine(tjs_int codepos)
{
	tjs_int start = FindSrcLineStartCodePos(codepos);
	Disassemble(start, codepos + 1);
}
示例#27
0
bool Capstone::Disassemble(uint addr, const unsigned char data[MAX_DISASM_BUFFER])
{
    return Disassemble(addr, data, MAX_DISASM_BUFFER);
}
示例#28
0
void CCodeWin::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CFont* pOldFont;
	C6502_REGS	regs;
	bool foundpc=false;

	// Select in our font

	pOldFont=dc.SelectObject(mpCodeFont);

	// Find out the PC for highlighting

	mSystem.GetRegs(regs);

	if(mMemorySize>1)
	{
		CString	line;
		int	current_address,address,loop;

		// If in follow mode then check PC will be draw else adjust mAddress
		// we don't follow if the CPU is not running

		if(mFollowPC)
		{
			bool test=false;
			address=mAddress;
			for(loop=0;loop<mLineCount;loop++)
			{
				if(address==regs.PC) test=true;
				address=NextAddress(address);
			}
			if(!test) mAddress=regs.PC;
		}

		// Now repaint

		address=mAddress;

		for(loop=0;loop<mLineCount;loop++)
		{
			line="";
			current_address=address;
			address=Disassemble(line,address);

			
			for(int bps=0;bps<MAX_CPU_BREAKPOINTS;bps++)
			{		
				if(current_address==regs.cpuBreakpoints[bps])
				{
					line.SetAt(0,'*');
				}
			}

			if(current_address!=regs.PC)
			{
				dc.TabbedTextOut(0,loop*mCharHeight,line,7,mTabstops,0);
			}
			else
			{
				COLORREF back,front;
				front=dc.GetTextColor();
				back=dc.GetBkColor();
				dc.SetTextColor(back);
				dc.SetBkColor(front);
				dc.TabbedTextOut(0,loop*mCharHeight,line,7,mTabstops,0);
				dc.SetTextColor(front);
				dc.SetBkColor(back);
			}
		}
	}
	else
	{
		// We have selected an invalid memory range

		dc.TextOut(mCharWidth*12,(mLineCount/2-1)*mCharHeight,"CARTRIDGE BANK IS EMPTY");
	}

	// Select the old font back in

	dc.SelectObject(pOldFont);
}
示例#29
0
void Disassembler::Disassemble(const void *byteCode, size_t length, OutputStream &outputStream)
{
	MemoryInputStream cboStream(byteCode, Stream::pos_t(length));
	Disassemble(cboStream, outputStream);
}