static InstTransResult translate_MOVoa (NativeModulePtr natM, BasicBlock *& block, InstPtr ip, MCInst &inst) { InstTransResult ret; Function *F = block->getParent(); // loading functions only available if its a 32-bit offset if( ip->has_external_ref() && width == 32) { Value *addrInt = getValueForExternal<32>(F->getParent(), ip, block); TASSERT(addrInt != 0, "Could not get external data reference"); R_WRITE<width>(block, X86::EAX, addrInt); return ContinueBlock; //ret = doRMMov<32>(ip, block, addrInt, MCOperand::CreateReg(X86::EAX)) ; } else if( ip->has_call_tgt() && width == 32 ) { Value *callback_fn = makeCallbackForLocalFunction( block->getParent()->getParent(), ip->get_call_tgt(0) ); Value *addrInt = new PtrToIntInst( callback_fn, llvm::Type::getInt32Ty(block->getContext()), "", block); ret = doRMMov<32>(ip, block, addrInt, MCOperand::CreateReg(X86::EAX)) ; } else if( ip->is_data_offset() ) { ret = doRMMov<width>(ip, block, GLOBAL_DATA_OFFSET(block, natM, ip), MCOperand::CreateReg(X86::EAX) ); } else { Value *addrv = CONST_V<width>(block, OP(0).getImm()); ret = doRMMov<width>(ip, block, addrv, MCOperand::CreateReg(X86::EAX)) ; } return ret ; }
static InstTransResult translate_CALL32m( NativeModulePtr natM, BasicBlock *& block, InstPtr ip, MCInst &inst) { InstTransResult ret; // is this an external call? if( ip->has_ext_call_target() ) { std::string s = ip->get_ext_call_target()->getSymbolName(); ret = doCallPCExtern(block, s); // not external call, but some weird way of calling local function? } else if( ip->has_call_tgt() ) { ret = doCallPC(ip, block, ip->get_call_tgt(0)); } // is this referencing global data? else if( ip->is_data_offset() ) { doCallM<32>(block, ip, STD_GLOBAL_OP(0)); ret = ContinueBlock; // is this a simple address computation? } else { doCallM<32>(block, ip, ADDR(0)); ret = ContinueBlock; } return ret; }
static InstTransResult doMOVSrm(NativeModulePtr natM, BasicBlock *& block, InstPtr ip, MCInst &inst) { InstTransResult ret; Function *F = block->getParent(); // MOV from memory to XMM register will set the unused poriton // of the XMM register to 0s. // Just set the whole thing to zero, and let the subsequent // write take care of the rest R_WRITE<128>(block, OP(0).getReg(), CONST_V<128>(block, 0)); if( ip->has_external_ref()) { Value *addrInt = getValueForExternal<width>(F->getParent(), ip, block); TASSERT(addrInt != NULL, "Could not get address for external"); R_WRITE<width>(block, OP(0).getReg(), addrInt); return ContinueBlock; } else if( ip->is_data_offset() ) { ret = doRMMov<width>(ip, block, GLOBAL( block, natM, inst, ip, 1 ), OP(0) ); } else { ret = doRMMov<width>(ip, block, ADDR(1), OP(0)); } return ret ; }
static InstTransResult translate_MOVao (NativeModulePtr natM, BasicBlock *& block, InstPtr ip, MCInst &inst) { InstTransResult ret; Function *F = block->getParent(); if( ip->is_data_offset() ) { ret = doMRMov<width>(ip, block, GLOBAL_DATA_OFFSET(block, natM, ip), MCOperand::CreateReg(X86::EAX) ); } else { Value *addrv = CONST_V<width>(block, OP(0).getImm()); ret = doMRMov<width>(ip, block, addrv, MCOperand::CreateReg(X86::EAX)) ; } return ret ; }
static InstTransResult translate_MOV32mr(NativeModulePtr natM, BasicBlock *& block, InstPtr ip, MCInst &inst) { InstTransResult ret; Function *F = block->getParent(); if( ip->has_external_ref()) { Value *addrInt = getValueForExternal<32>(F->getParent(), ip, block); TASSERT(addrInt != NULL, "Could not get address for external"); return doMRMov<32>(ip, block, addrInt, OP(5) ); } else if( ip->is_data_offset() ) { ret = doMRMov<32>(ip, block, GLOBAL( block, natM, inst, ip, 0), OP(5) ); } else { ret = doMRMov<32>(ip, block, ADDR(0), OP(5)) ; } return ret ; }
static InstTransResult translate_LEA64_32r(NativeModulePtr natM, BasicBlock *&block, InstPtr ip, MCInst &inst) { InstTransResult ret; Function *F = block->getParent(); if( ip->has_call_tgt() ) { Value *callback_fn = archMakeCallbackForLocalFunction( block->getParent()->getParent(), ip->get_call_tgt(0)); Value *addrInt = new PtrToIntInst( callback_fn, llvm::Type::getInt32Ty(block->getContext()), "", block); ret = doLeaV<32>(block, OP(0), addrInt); } else if( ip->is_data_offset() ) { ret = doLea<32>(ip, block, STD_GLOBAL_OP(1), OP(0)); } else { ret = doLea<32>(ip, block, ADDR(1), OP(0)); } return ret; }
static InstTransResult translate_JMP32m(NativeModulePtr natM, BasicBlock *& block, InstPtr ip, MCInst &inst) { InstTransResult ret; // translate JMP mem32 API calls // as a call <api>, ret; if( ip->has_ext_call_target() ) { std::string s = ip->get_ext_call_target()->getSymbolName(); ret = doCallPCExtern(block, s, true); if (ret != EndBlock) { return doRet(block); } else { // noreturn api calls don't need to fix stack return ret; } } else if (ip->has_jump_table() && ip->is_data_offset()) { // this is a jump table that got converted // into a table in the data section doJumpTableViaData(natM, block, ip, inst); // return a "ret", since the jmp is simulated // as a call/ret pair return doRet(block); } else if(ip->has_jump_table()) { // this is a conformant jump table // emit an llvm switch doJumpTableViaSwitch(natM, block, ip, inst); return EndBlock; } else { std::string msg("NIY: JMP32m only supported for external API calls and jump tables: "); msg += to_string<VA>(ip->get_loc(), std::hex); throw TErr(__LINE__, __FILE__, msg.c_str()); return EndBlock; } }
static InstTransResult translate_MOV32ri(NativeModulePtr natM, BasicBlock *& block, InstPtr ip, MCInst &inst) { InstTransResult ret; Function *F = block->getParent(); if( ip->has_call_tgt() ) { Value *callback_fn = makeCallbackForLocalFunction( block->getParent()->getParent(), ip->get_call_tgt(0) ); Value *addrInt = new PtrToIntInst( callback_fn, llvm::Type::getInt32Ty(block->getContext()), "", block); ret = doRIMovV<32>(ip, block, addrInt, OP(0) ); } else if( ip->is_data_offset() ) { ret = doRIMovV<32>(ip, block, GLOBAL_DATA_OFFSET(block, natM, ip), OP(0) ); } else { ret = doRIMov<32>(ip, block, OP(1), OP(0)) ; } return ret ; }
//GENERIC_TRANSLATION_32MI(MOV32mi, // doMIMov<32>(ip, block, ADDR(0), OP(5)), // doMIMov<32>(ip, block, STD_GLOBAL_OP(0), OP(5)), // doMIMovV<32>(ip, block, ADDR_NOREF(0), GLOBAL_DATA_OFFSET(block, natM, ip)) // ) // static InstTransResult translate_MOV32mi(NativeModulePtr natM, BasicBlock *&block, InstPtr ip, MCInst &inst) { InstTransResult ret; Function *F = block->getParent(); if( ip->has_call_tgt() ) { Value *callback_fn = makeCallbackForLocalFunction( block->getParent()->getParent(), ip->get_call_tgt(0) ); Value *addrInt = new PtrToIntInst( callback_fn, llvm::Type::getInt32Ty(block->getContext()), "", block); ret = doMIMovV<32>(ip, block, ADDR(0), addrInt); } else if( ip->is_data_offset() ) { if( ip->get_reloc_offset() < OP(5).getOffset() ) { doMIMov<32>(ip, block, STD_GLOBAL_OP(0), OP(5)); } else { doMIMovV<32>(ip, block, ADDR_NOREF(0), GLOBAL_DATA_OFFSET(block, natM, ip)); } ret = ContinueBlock; } else { ret = doMIMov<32>(ip, block, ADDR(0), OP(5)); } return ret; }