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