parent
d2da38cad1
commit
b82072e2ed
@ -0,0 +1,20 @@
|
||||
#include <vm_lifters.hpp>
|
||||
|
||||
namespace vm
|
||||
{
|
||||
lifters_t::lifter_callback_t lifters_t::idivdw =
|
||||
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||
llvm::IRBuilder<> *ir_builder ) {
|
||||
auto t1 = rtn->pop( 4 );
|
||||
auto t2 = rtn->pop( 4 );
|
||||
|
||||
// TODO: this is wrong...
|
||||
ir_builder->CreateUDiv( t1, t2 );
|
||||
rtn->push( 4, t1 );
|
||||
rtn->push( 4, t2 );
|
||||
|
||||
auto &vmp_rtn = rtn->vmp_rtns.back();
|
||||
// TODO: compute flags...
|
||||
rtn->push( 8, rtn->load_value( 8, vmp_rtn->flags ) );
|
||||
};
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#include <vm_lifters.hpp>
|
||||
|
||||
namespace vm
|
||||
{
|
||||
lifters_t::lifter_callback_t lifters_t::readcr3 =
|
||||
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||
llvm::IRBuilder<> *ir_builder ) {
|
||||
llvm::Function *readcr3_intrin = nullptr;
|
||||
if ( !( readcr3_intrin = rtn->llvm_module->getFunction( "readcr3" ) ) )
|
||||
{
|
||||
readcr3_intrin = llvm::Function::Create( llvm::FunctionType::get( ir_builder->getInt64Ty(), false ),
|
||||
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "readcr3",
|
||||
*rtn->llvm_module );
|
||||
|
||||
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", readcr3_intrin );
|
||||
auto ib = ir_builder->GetInsertBlock();
|
||||
ir_builder->SetInsertPoint( entry_block );
|
||||
|
||||
std::string asm_str( "mov rax, cr3; ret" );
|
||||
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->CreateRet( llvm::ConstantInt::get( *rtn->llvm_ctx, llvm::APInt( 64, 0 ) ) );
|
||||
ir_builder->SetInsertPoint( ib );
|
||||
}
|
||||
auto t1 = ir_builder->CreateCall( readcr3_intrin );
|
||||
rtn->push( 8, t1 );
|
||||
};
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#include <vm_lifters.hpp>
|
||||
|
||||
namespace vm
|
||||
{
|
||||
lifters_t::lifter_callback_t lifters_t::writecr3 =
|
||||
[ & ]( vm::devirt_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
|
||||
llvm::IRBuilder<> *ir_builder ) {
|
||||
llvm::Function *writecr3_intrin = nullptr;
|
||||
if ( !( writecr3_intrin = rtn->llvm_module->getFunction( "writecr3" ) ) )
|
||||
{
|
||||
writecr3_intrin = llvm::Function::Create(
|
||||
llvm::FunctionType::get( ir_builder->getVoidTy(), { ir_builder->getInt64Ty() }, false ),
|
||||
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "writecr3", *rtn->llvm_module );
|
||||
|
||||
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", writecr3_intrin );
|
||||
auto ib = ir_builder->GetInsertBlock();
|
||||
ir_builder->SetInsertPoint( entry_block );
|
||||
|
||||
std::string asm_str( "mov cr3, rcx; ret" );
|
||||
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->SetInsertPoint( ib );
|
||||
}
|
||||
auto t1 = rtn->pop( 8 );
|
||||
ir_builder->CreateCall( writecr3_intrin, { t1 } );
|
||||
};
|
||||
}
|
Loading…
Reference in new issue