|
|
|
@ -8,25 +8,21 @@ namespace vm
|
|
|
|
|
llvm::Function *rdtsc_intrin = nullptr;
|
|
|
|
|
if ( !( rdtsc_intrin = rtn->llvm_module->getFunction( "rdtsc" ) ) )
|
|
|
|
|
{
|
|
|
|
|
rdtsc_intrin = llvm::Function::Create(
|
|
|
|
|
llvm::FunctionType::get( ir_builder->getVoidTy(),
|
|
|
|
|
{ llvm::PointerType::get( ir_builder->getInt8Ty(), 0ull ) }, false ),
|
|
|
|
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "rdtsc", *rtn->llvm_module );
|
|
|
|
|
rdtsc_intrin = llvm::Function::Create( llvm::FunctionType::get( ir_builder->getVoidTy(), false ),
|
|
|
|
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "rdtsc",
|
|
|
|
|
*rtn->llvm_module );
|
|
|
|
|
|
|
|
|
|
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", rdtsc_intrin );
|
|
|
|
|
auto ib = ir_builder->GetInsertBlock();
|
|
|
|
|
ir_builder->SetInsertPoint( entry_block );
|
|
|
|
|
|
|
|
|
|
std::string asm_str( "rdtsc; sub rbp, 0x08; mov [rcx], edx; mov [rcx+0x04], eax; ret" );
|
|
|
|
|
auto intrin = llvm::InlineAsm::get( llvm::FunctionType::get( ir_builder->getVoidTy(), false ), asm_str,
|
|
|
|
|
"", false, false, llvm::InlineAsm::AD_Intel );
|
|
|
|
|
// TODO: put RDTSC code here...
|
|
|
|
|
|
|
|
|
|
ir_builder->CreateCall( intrin );
|
|
|
|
|
ir_builder->CreateRetVoid();
|
|
|
|
|
ir_builder->SetInsertPoint( ib );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto &vmp_rtn = rtn->vmp_rtns.back();
|
|
|
|
|
ir_builder->CreateCall( rdtsc_intrin, { vmp_rtn->stack } );
|
|
|
|
|
ir_builder->CreateCall( rdtsc_intrin );
|
|
|
|
|
};
|
|
|
|
|
}
|