@@ -413,8 +413,8 @@ Value* FunctionGenerator::LoadStateValue(uint32_t offset, Type* type,
|
||||
IRBuilder<>& b = *builder_;
|
||||
PointerType* pointerTy = PointerType::getUnqual(type);
|
||||
Function::arg_iterator args = gen_fn_->arg_begin();
|
||||
Value* statePtr = args;
|
||||
Value* address = b.CreateConstInBoundsGEP1_64(statePtr, offset);
|
||||
Value* state_ptr = args;
|
||||
Value* address = b.CreateInBoundsGEP(state_ptr, b.getInt32(offset));
|
||||
Value* ptr = b.CreatePointerCast(address, pointerTy);
|
||||
return b.CreateLoad(ptr, name);
|
||||
}
|
||||
@@ -424,8 +424,8 @@ void FunctionGenerator::StoreStateValue(uint32_t offset, Type* type,
|
||||
IRBuilder<>& b = *builder_;
|
||||
PointerType* pointerTy = PointerType::getUnqual(type);
|
||||
Function::arg_iterator args = gen_fn_->arg_begin();
|
||||
Value* statePtr = args;
|
||||
Value* address = b.CreateConstInBoundsGEP1_64(statePtr, offset);
|
||||
Value* state_ptr = args;
|
||||
Value* address = b.CreateInBoundsGEP(state_ptr, b.getInt32(offset));
|
||||
Value* ptr = b.CreatePointerCast(address, pointerTy);
|
||||
b.CreateStore(value, ptr);
|
||||
}
|
||||
@@ -861,7 +861,8 @@ Value* FunctionGenerator::ReadMemory(Value* addr, uint32_t size, bool extend) {
|
||||
}
|
||||
PointerType* pointerTy = PointerType::getUnqual(dataTy);
|
||||
|
||||
Value* address = b.CreateInBoundsGEP(GetMembase(), addr);
|
||||
Value* offset_addr = b.CreateAdd(addr, b.getInt64(size));
|
||||
Value* address = b.CreateInBoundsGEP(GetMembase(), offset_addr);
|
||||
Value* ptr = b.CreatePointerCast(address, pointerTy);
|
||||
return b.CreateLoad(ptr);
|
||||
}
|
||||
@@ -889,7 +890,8 @@ void FunctionGenerator::WriteMemory(Value* addr, uint32_t size, Value* value) {
|
||||
}
|
||||
PointerType* pointerTy = PointerType::getUnqual(dataTy);
|
||||
|
||||
Value* address = b.CreateInBoundsGEP(GetMembase(), addr);
|
||||
Value* offset_addr = b.CreateAdd(addr, b.getInt64(size));
|
||||
Value* address = b.CreateInBoundsGEP(GetMembase(), offset_addr);
|
||||
Value* ptr = b.CreatePointerCast(address, pointerTy);
|
||||
|
||||
// Truncate, if required.
|
||||
|
||||
@@ -126,6 +126,14 @@ int ModuleGenerator::Generate() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModuleGenerator::AddFunctionsToMap(
|
||||
std::tr1::unordered_map<uint32_t, llvm::Function*>& map) {
|
||||
for (std::map<uint32_t, CodegenFunction*>::iterator it = functions_.begin();
|
||||
it != functions_.end(); ++it) {
|
||||
map.insert(std::pair<uint32_t, Function*>(it->first, it->second->function));
|
||||
}
|
||||
}
|
||||
|
||||
ModuleGenerator::CodegenFunction* ModuleGenerator::GetCodegenFunction(
|
||||
uint32_t address) {
|
||||
std::map<uint32_t, CodegenFunction*>::iterator it = functions_.find(address);
|
||||
|
||||
@@ -219,6 +219,10 @@ XECLEANUP:
|
||||
return result_code;
|
||||
}
|
||||
|
||||
void ExecModule::AddFunctionsToMap(FunctionMap& map) {
|
||||
codegen_->AddFunctionsToMap(map);
|
||||
}
|
||||
|
||||
void XeTrap(xe_ppc_state_t* state, uint32_t cia) {
|
||||
printf("TRAP");
|
||||
XEASSERTALWAYS();
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
{
|
||||
'sources': [
|
||||
'instr.cc',
|
||||
'state.cc',
|
||||
],
|
||||
}
|
||||
|
||||
47
src/cpu/ppc/state.cc
Normal file
47
src/cpu/ppc/state.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/core.h>
|
||||
#include <xenia/cpu/ppc/state.h>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
uint64_t ParseInt64(const char* value) {
|
||||
return strtoull(value, NULL, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void xe_ppc_state::SetRegFromString(const char* name, const char* value) {
|
||||
int n;
|
||||
if (sscanf(name, "r%d", &n) == 1) {
|
||||
this->r[n] = ParseInt64(value);
|
||||
} else {
|
||||
printf("Unrecognized register name: %s\n", name);
|
||||
}
|
||||
}
|
||||
|
||||
bool xe_ppc_state::CompareRegWithString(
|
||||
const char* name, const char* value,
|
||||
char* out_value, size_t out_value_size) {
|
||||
int n;
|
||||
if (sscanf(name, "r%d", &n) == 1) {
|
||||
uint64_t expected = ParseInt64(value);
|
||||
if (this->r[n] != expected) {
|
||||
xesnprintfa(out_value, out_value_size, "%016llX", this->r[n]);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
printf("Unrecognized register name: %s\n", name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <xenia/cpu/processor.h>
|
||||
|
||||
#include <llvm/ExecutionEngine/ExecutionEngine.h>
|
||||
#include <llvm/ExecutionEngine/GenericValue.h>
|
||||
#include <llvm/ExecutionEngine/Interpreter.h>
|
||||
#include <llvm/ExecutionEngine/JIT.h>
|
||||
#include <llvm/IR/LLVMContext.h>
|
||||
@@ -97,6 +98,7 @@ int Processor::PrepareModule(
|
||||
return 1;
|
||||
}
|
||||
|
||||
exec_module->AddFunctionsToMap(all_fns_);
|
||||
modules_.push_back(exec_module);
|
||||
|
||||
exec_module->Dump();
|
||||
@@ -115,6 +117,7 @@ int Processor::PrepareModule(UserModule* user_module,
|
||||
return 1;
|
||||
}
|
||||
|
||||
exec_module->AddFunctionsToMap(all_fns_);
|
||||
modules_.push_back(exec_module);
|
||||
|
||||
//user_module->Dump(export_resolver.get());
|
||||
@@ -123,12 +126,58 @@ int Processor::PrepareModule(UserModule* user_module,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Processor::Execute(uint32_t address) {
|
||||
// TODO(benvanik): implement execute.
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Processor::CreateCallback(void (*callback)(void* data), void* data) {
|
||||
// TODO(benvanik): implement callback creation.
|
||||
return 0;
|
||||
}
|
||||
|
||||
ThreadState* Processor::AllocThread(uint32_t stack_address,
|
||||
uint32_t stack_size) {
|
||||
ThreadState* thread_state = new ThreadState(
|
||||
this, stack_address, stack_size);
|
||||
return thread_state;
|
||||
}
|
||||
|
||||
void Processor::DeallocThread(ThreadState* thread_state) {
|
||||
delete thread_state;
|
||||
}
|
||||
|
||||
int Processor::Execute(ThreadState* thread_state, uint32_t address) {
|
||||
// Find the function to execute.
|
||||
Function* f = GetFunction(address);
|
||||
if (!f) {
|
||||
XELOGCPU("Failed to find function %.8X to execute.\n", address);
|
||||
return 1;
|
||||
}
|
||||
|
||||
xe_ppc_state_t* ppc_state = thread_state->ppc_state();
|
||||
|
||||
// This could be set to anything to give us a unique identifier to track
|
||||
// re-entrancy/etc.
|
||||
uint32_t lr = 0xBEBEBEBE;
|
||||
|
||||
// Setup registers.
|
||||
ppc_state->lr = 0xBEBEBEBE;
|
||||
|
||||
// Args:
|
||||
// - i8* state
|
||||
// - i64 lr
|
||||
std::vector<GenericValue> args;
|
||||
args.push_back(PTOGV(ppc_state));
|
||||
GenericValue lr_arg;
|
||||
lr_arg.IntVal = APInt(64, lr);
|
||||
args.push_back(lr_arg);
|
||||
|
||||
GenericValue ret = engine_->runFunction(f, args);
|
||||
|
||||
//return (uint32_t)ret.IntVal.getSExtValue();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Function* Processor::GetFunction(uint32_t address) {
|
||||
FunctionMap::iterator it = all_fns_.find(address);
|
||||
if (it != all_fns_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <xenia/cpu/ppc/instr.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace xe;
|
||||
using namespace xe::cpu;
|
||||
using namespace xe::cpu::ppc;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
'exec_module.cc',
|
||||
'processor.cc',
|
||||
'sdb.cc',
|
||||
'thread_state.cc',
|
||||
],
|
||||
|
||||
'includes': [
|
||||
|
||||
38
src/cpu/thread_state.cc
Normal file
38
src/cpu/thread_state.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <xenia/cpu/thread_state.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::cpu;
|
||||
|
||||
|
||||
ThreadState::ThreadState(
|
||||
Processor* processor,
|
||||
uint32_t stack_address, uint32_t stack_size) {
|
||||
stack_address_ = stack_address;
|
||||
stack_size_ = stack_size;
|
||||
|
||||
xe_zero_struct(&ppc_state_, sizeof(ppc_state_));
|
||||
|
||||
// Stash pointers to common structures that callbacks may need.
|
||||
ppc_state_.processor = processor;
|
||||
ppc_state_.thread_state = this;
|
||||
|
||||
// Set initial registers.
|
||||
ppc_state_.r[1] = stack_address_;
|
||||
}
|
||||
|
||||
ThreadState::~ThreadState() {
|
||||
}
|
||||
|
||||
xe_ppc_state_t* ThreadState::ppc_state() {
|
||||
return &ppc_state_;
|
||||
}
|
||||
Reference in New Issue
Block a user