From 9281d621065f16bb68138071e945cfaee94d4e3f Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Tue, 24 Mar 2015 08:25:58 -0700 Subject: [PATCH] Moving cpu/runtime/ to cpu/. --- src/xenia/apu/audio_driver.cc | 3 +- src/xenia/apu/audio_system.cc | 4 +- src/xenia/apu/audio_system.h | 2 +- src/xenia/cpu/backend/assembler.h | 17 +++-- src/xenia/cpu/backend/backend.cc | 2 +- src/xenia/cpu/backend/backend.h | 8 +-- src/xenia/cpu/backend/x64/x64_assembler.cc | 7 +-- src/xenia/cpu/backend/x64/x64_assembler.h | 9 ++- src/xenia/cpu/backend/x64/x64_backend.cc | 2 +- src/xenia/cpu/backend/x64/x64_backend.h | 2 +- src/xenia/cpu/backend/x64/x64_emitter.cc | 19 +++--- src/xenia/cpu/backend/x64/x64_emitter.h | 23 +++---- src/xenia/cpu/backend/x64/x64_function.cc | 9 +-- src/xenia/cpu/backend/x64/x64_function.h | 16 ++--- src/xenia/cpu/backend/x64/x64_sequences.cc | 4 +- src/xenia/cpu/backend/x64/x64_tracers.cc | 6 +- src/xenia/cpu/compiler/compiler.cc | 2 +- src/xenia/cpu/compiler/compiler.h | 8 +-- src/xenia/cpu/compiler/compiler_pass.h | 4 +- .../passes/constant_propagation_pass.cc | 6 +- .../compiler/passes/context_promotion_pass.cc | 2 +- .../passes/control_flow_analysis_pass.cc | 2 +- .../control_flow_simplification_pass.cc | 2 +- .../passes/data_flow_analysis_pass.cc | 2 +- .../cpu/compiler/passes/finalization_pass.cc | 2 +- .../cpu/compiler/passes/validation_pass.cc | 2 +- .../compiler/passes/value_reduction_pass.cc | 2 +- src/xenia/cpu/cpu.h | 12 ++-- src/xenia/cpu/{runtime => }/debug_info.cc | 4 +- src/xenia/cpu/{runtime => }/debug_info.h | 8 +-- src/xenia/cpu/{runtime => }/debugger.cc | 7 +-- src/xenia/cpu/{runtime => }/debugger.h | 10 ++- src/xenia/cpu/{runtime => }/entry_table.cc | 4 +- src/xenia/cpu/{runtime => }/entry_table.h | 8 +-- src/xenia/cpu/frontend/frontend.cc | 4 +- src/xenia/cpu/frontend/frontend.h | 18 +++--- src/xenia/cpu/frontend/ppc/ppc_context.h | 6 +- src/xenia/cpu/frontend/ppc/ppc_frontend.cc | 6 +- src/xenia/cpu/frontend/ppc/ppc_frontend.h | 13 ++-- src/xenia/cpu/frontend/ppc/ppc_hir_builder.cc | 4 +- src/xenia/cpu/frontend/ppc/ppc_hir_builder.h | 12 ++-- src/xenia/cpu/frontend/ppc/ppc_scanner.cc | 4 +- src/xenia/cpu/frontend/ppc/ppc_scanner.h | 6 +- src/xenia/cpu/frontend/ppc/ppc_translator.cc | 8 +-- src/xenia/cpu/frontend/ppc/ppc_translator.h | 9 ++- .../cpu/frontend/ppc/test/xe-cpu-ppc-test.cc | 63 ++----------------- src/xenia/cpu/{runtime => }/function.cc | 10 ++- src/xenia/cpu/{runtime => }/function.h | 12 ++-- src/xenia/cpu/hir/hir_builder.cc | 4 +- src/xenia/cpu/hir/hir_builder.h | 6 +- src/xenia/cpu/hir/instr.h | 4 +- src/xenia/cpu/{runtime => }/instrument.cc | 8 +-- src/xenia/cpu/{runtime => }/instrument.h | 10 ++- src/xenia/cpu/{runtime => }/module.cc | 6 +- src/xenia/cpu/{runtime => }/module.h | 10 ++- src/xenia/cpu/processor.cc | 17 ++--- src/xenia/cpu/processor.h | 16 ++--- src/xenia/cpu/{runtime => }/raw_module.cc | 4 +- src/xenia/cpu/{runtime => }/raw_module.h | 10 ++- src/xenia/cpu/{runtime => }/runtime.cc | 23 ++++--- src/xenia/cpu/{runtime => }/runtime.h | 36 +++++------ src/xenia/cpu/runtime/sources.gypi | 30 --------- src/xenia/cpu/runtime/thread_state.cc | 56 ----------------- src/xenia/cpu/sources.gypi | 27 ++++++-- src/xenia/cpu/{runtime => }/symbol_info.cc | 4 +- src/xenia/cpu/{runtime => }/symbol_info.h | 8 +-- src/xenia/cpu/test/test_add.cc | 2 +- src/xenia/cpu/test/test_byte_swap.cc | 2 +- src/xenia/cpu/test/test_extract.cc | 2 +- src/xenia/cpu/test/test_insert.cc | 2 +- .../cpu/test/test_load_vector_shl_shr.cc | 2 +- src/xenia/cpu/test/test_pack.cc | 2 +- src/xenia/cpu/test/test_permute.cc | 2 +- src/xenia/cpu/test/test_sha.cc | 2 +- src/xenia/cpu/test/test_shl.cc | 2 +- src/xenia/cpu/test/test_shr.cc | 2 +- src/xenia/cpu/test/test_swizzle.cc | 2 +- src/xenia/cpu/test/test_unpack.cc | 2 +- src/xenia/cpu/test/test_vector_add.cc | 2 +- src/xenia/cpu/test/test_vector_max.cc | 2 +- src/xenia/cpu/test/test_vector_min.cc | 2 +- src/xenia/cpu/test/test_vector_rotate_left.cc | 2 +- src/xenia/cpu/test/test_vector_sha.cc | 2 +- src/xenia/cpu/test/test_vector_shl.cc | 2 +- src/xenia/cpu/test/test_vector_shr.cc | 2 +- src/xenia/cpu/test/util.h | 63 ++----------------- src/xenia/cpu/test/xe-cpu-hir-test.cc | 2 +- src/xenia/cpu/test/xe-cpu-sandbox.cc | 56 ++--------------- src/xenia/cpu/{runtime => }/test_module.cc | 8 +-- src/xenia/cpu/{runtime => }/test_module.h | 10 ++- ...{xenon_thread_state.cc => thread_state.cc} | 62 ++++++++++++++---- src/xenia/cpu/{runtime => }/thread_state.h | 43 +++++++++---- src/xenia/cpu/xenon_runtime.cc | 39 ------------ src/xenia/cpu/xenon_runtime.h | 42 ------------- src/xenia/cpu/xenon_thread_state.h | 57 ----------------- src/xenia/cpu/xex_module.cc | 8 ++- src/xenia/cpu/xex_module.h | 10 +-- src/xenia/emulator.h | 2 +- src/xenia/kernel/objects/xthread.cc | 4 +- src/xenia/kernel/objects/xthread.h | 4 +- src/xenia/kernel/objects/xuser_module.cc | 2 +- src/xenia/memory.cc | 41 ++++++------ 102 files changed, 394 insertions(+), 771 deletions(-) rename src/xenia/cpu/{runtime => }/debug_info.cc (96%) rename src/xenia/cpu/{runtime => }/debug_info.h (93%) rename src/xenia/cpu/{runtime => }/debugger.cc (97%) rename src/xenia/cpu/{runtime => }/debugger.h (94%) rename src/xenia/cpu/{runtime => }/entry_table.cc (96%) rename src/xenia/cpu/{runtime => }/entry_table.h (88%) rename src/xenia/cpu/{runtime => }/function.cc (94%) rename src/xenia/cpu/{runtime => }/function.h (88%) rename src/xenia/cpu/{runtime => }/instrument.cc (93%) rename src/xenia/cpu/{runtime => }/instrument.h (95%) rename src/xenia/cpu/{runtime => }/module.cc (98%) rename src/xenia/cpu/{runtime => }/module.h (91%) rename src/xenia/cpu/{runtime => }/raw_module.cc (95%) rename src/xenia/cpu/{runtime => }/raw_module.h (83%) rename src/xenia/cpu/{runtime => }/runtime.cc (92%) rename src/xenia/cpu/{runtime => }/runtime.h (76%) delete mode 100644 src/xenia/cpu/runtime/sources.gypi delete mode 100644 src/xenia/cpu/runtime/thread_state.cc rename src/xenia/cpu/{runtime => }/symbol_info.cc (94%) rename src/xenia/cpu/{runtime => }/symbol_info.h (94%) rename src/xenia/cpu/{runtime => }/test_module.cc (95%) rename src/xenia/cpu/{runtime => }/test_module.h (88%) rename src/xenia/cpu/{xenon_thread_state.cc => thread_state.cc} (61%) rename src/xenia/cpu/{runtime => }/thread_state.h (53%) delete mode 100644 src/xenia/cpu/xenon_runtime.cc delete mode 100644 src/xenia/cpu/xenon_runtime.h delete mode 100644 src/xenia/cpu/xenon_thread_state.h diff --git a/src/xenia/apu/audio_driver.cc b/src/xenia/apu/audio_driver.cc index b896f4373..91b24df44 100644 --- a/src/xenia/apu/audio_driver.cc +++ b/src/xenia/apu/audio_driver.cc @@ -11,8 +11,7 @@ #include "xenia/emulator.h" #include "xenia/cpu/processor.h" -#include "xenia/cpu/xenon_thread_state.h" - +#include "xenia/cpu/thread_state.h" using namespace xe; using namespace xe::apu; diff --git a/src/xenia/apu/audio_system.cc b/src/xenia/apu/audio_system.cc index 52b86be40..b331be21a 100644 --- a/src/xenia/apu/audio_system.cc +++ b/src/xenia/apu/audio_system.cc @@ -13,7 +13,7 @@ #include "xenia/apu/audio_driver.h" #include "xenia/emulator.h" #include "xenia/cpu/processor.h" -#include "xenia/cpu/xenon_thread_state.h" +#include "xenia/cpu/thread_state.h" // As with normal Microsoft, there are like twelve different ways to access // the audio APIs. Early games use XMA*() methods almost exclusively to touch @@ -90,7 +90,7 @@ X_STATUS AudioSystem::Setup() { // Setup worker thread state. This lets us make calls into guest code. thread_state_ = - new XenonThreadState(emulator_->processor()->runtime(), 0, 16 * 1024, 0); + new ThreadState(emulator_->processor()->runtime(), 0, 0, 16 * 1024, 0); thread_state_->set_name("Audio Worker"); thread_block_ = (uint32_t)memory()->HeapAlloc(0, 2048, MEMORY_FLAG_ZERO); thread_state_->context()->r[13] = thread_block_; diff --git a/src/xenia/apu/audio_system.h b/src/xenia/apu/audio_system.h index b76e2b42f..4e96244e3 100644 --- a/src/xenia/apu/audio_system.h +++ b/src/xenia/apu/audio_system.h @@ -75,7 +75,7 @@ class AudioSystem { cpu::Processor* processor_; std::thread thread_; - cpu::XenonThreadState* thread_state_; + cpu::ThreadState* thread_state_; uint32_t thread_block_; std::atomic running_; diff --git a/src/xenia/cpu/backend/assembler.h b/src/xenia/cpu/backend/assembler.h index 2655ef3ee..2a1814fa2 100644 --- a/src/xenia/cpu/backend/assembler.h +++ b/src/xenia/cpu/backend/assembler.h @@ -14,15 +14,13 @@ namespace xe { namespace cpu { -namespace hir { -class HIRBuilder; -} // namespace hir -namespace runtime { class DebugInfo; class Function; class FunctionInfo; class Runtime; -} // namespace runtime +namespace hir { +class HIRBuilder; +} // namespace hir } // namespace cpu } // namespace xe @@ -41,11 +39,10 @@ class Assembler { virtual void Reset(); - virtual int Assemble(runtime::FunctionInfo* symbol_info, - hir::HIRBuilder* builder, uint32_t debug_info_flags, - std::unique_ptr debug_info, - uint32_t trace_flags, - runtime::Function** out_function) = 0; + virtual int Assemble(FunctionInfo* symbol_info, hir::HIRBuilder* builder, + uint32_t debug_info_flags, + std::unique_ptr debug_info, + uint32_t trace_flags, Function** out_function) = 0; protected: Backend* backend_; diff --git a/src/xenia/cpu/backend/backend.cc b/src/xenia/cpu/backend/backend.cc index 041321b73..4d6072bcb 100644 --- a/src/xenia/cpu/backend/backend.cc +++ b/src/xenia/cpu/backend/backend.cc @@ -13,7 +13,7 @@ namespace xe { namespace cpu { namespace backend { -using xe::cpu::runtime::Runtime; +using xe::cpu::Runtime; Backend::Backend(Runtime* runtime) : runtime_(runtime) { memset(&machine_info_, 0, sizeof(machine_info_)); diff --git a/src/xenia/cpu/backend/backend.h b/src/xenia/cpu/backend/backend.h index 268f48dfe..2f8b98e95 100644 --- a/src/xenia/cpu/backend/backend.h +++ b/src/xenia/cpu/backend/backend.h @@ -16,9 +16,7 @@ namespace xe { namespace cpu { -namespace runtime { class Runtime; -} // namespace runtime } // namespace cpu } // namespace xe @@ -30,10 +28,10 @@ class Assembler; class Backend { public: - Backend(runtime::Runtime* runtime); + Backend(Runtime* runtime); virtual ~Backend(); - runtime::Runtime* runtime() const { return runtime_; } + Runtime* runtime() const { return runtime_; } const MachineInfo* machine_info() const { return &machine_info_; } virtual int Initialize(); @@ -44,7 +42,7 @@ class Backend { virtual std::unique_ptr CreateAssembler() = 0; protected: - runtime::Runtime* runtime_; + Runtime* runtime_; MachineInfo machine_info_; }; diff --git a/src/xenia/cpu/backend/x64/x64_assembler.cc b/src/xenia/cpu/backend/x64/x64_assembler.cc index 252c4682d..60cafd87d 100644 --- a/src/xenia/cpu/backend/x64/x64_assembler.cc +++ b/src/xenia/cpu/backend/x64/x64_assembler.cc @@ -14,7 +14,7 @@ #include "xenia/cpu/backend/x64/x64_function.h" #include "xenia/cpu/hir/hir_builder.h" #include "xenia/cpu/hir/label.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "poly/reset_scope.h" #include "xenia/profiling.h" @@ -28,12 +28,9 @@ namespace backend { namespace x64 { // TODO(benvanik): remove when enums redefined. -using namespace xe::cpu::runtime; +using namespace xe::cpu; using xe::cpu::hir::HIRBuilder; -using xe::cpu::runtime::DebugInfo; -using xe::cpu::runtime::Function; -using xe::cpu::runtime::FunctionInfo; X64Assembler::X64Assembler(X64Backend* backend) : Assembler(backend), x64_backend_(backend) {} diff --git a/src/xenia/cpu/backend/x64/x64_assembler.h b/src/xenia/cpu/backend/x64/x64_assembler.h index a3362e84e..f805ad248 100644 --- a/src/xenia/cpu/backend/x64/x64_assembler.h +++ b/src/xenia/cpu/backend/x64/x64_assembler.h @@ -33,13 +33,12 @@ class X64Assembler : public Assembler { void Reset() override; - int Assemble(runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder, - uint32_t debug_info_flags, - std::unique_ptr debug_info, - uint32_t trace_flags, runtime::Function** out_function) override; + int Assemble(FunctionInfo* symbol_info, hir::HIRBuilder* builder, + uint32_t debug_info_flags, std::unique_ptr debug_info, + uint32_t trace_flags, Function** out_function) override; private: - void DumpMachineCode(runtime::DebugInfo* debug_info, void* machine_code, + void DumpMachineCode(DebugInfo* debug_info, void* machine_code, size_t code_size, poly::StringBuffer* str); private: diff --git a/src/xenia/cpu/backend/x64/x64_backend.cc b/src/xenia/cpu/backend/x64/x64_backend.cc index 4c0b2217b..a66a1b75e 100644 --- a/src/xenia/cpu/backend/x64/x64_backend.cc +++ b/src/xenia/cpu/backend/x64/x64_backend.cc @@ -19,7 +19,7 @@ namespace cpu { namespace backend { namespace x64 { -using xe::cpu::runtime::Runtime; +using xe::cpu::Runtime; X64Backend::X64Backend(Runtime* runtime) : Backend(runtime), code_cache_(0) {} diff --git a/src/xenia/cpu/backend/x64/x64_backend.h b/src/xenia/cpu/backend/x64/x64_backend.h index 6eb0973d3..2c3104921 100644 --- a/src/xenia/cpu/backend/x64/x64_backend.h +++ b/src/xenia/cpu/backend/x64/x64_backend.h @@ -26,7 +26,7 @@ typedef void* (*GuestToHostThunk)(void* target, void* arg0, void* arg1); class X64Backend : public Backend { public: - X64Backend(runtime::Runtime* runtime); + X64Backend(Runtime* runtime); ~X64Backend() override; X64CodeCache* code_cache() const { return code_cache_; } diff --git a/src/xenia/cpu/backend/x64/x64_emitter.cc b/src/xenia/cpu/backend/x64/x64_emitter.cc index 3aa47aa2e..55320dd24 100644 --- a/src/xenia/cpu/backend/x64/x64_emitter.cc +++ b/src/xenia/cpu/backend/x64/x64_emitter.cc @@ -16,10 +16,10 @@ #include "xenia/cpu/backend/x64/x64_thunk_emitter.h" #include "xenia/cpu/cpu-private.h" #include "xenia/cpu/hir/hir_builder.h" -#include "xenia/cpu/runtime/debug_info.h" -#include "xenia/cpu/runtime/runtime.h" -#include "xenia/cpu/runtime/symbol_info.h" -#include "xenia/cpu/runtime/thread_state.h" +#include "xenia/cpu/debug_info.h" +#include "xenia/cpu/runtime.h" +#include "xenia/cpu/symbol_info.h" +#include "xenia/cpu/thread_state.h" #include "poly/vec128.h" #include "xdb/protocol.h" #include "xenia/profiling.h" @@ -31,7 +31,7 @@ namespace x64 { // TODO(benvanik): remove when enums redefined. using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using poly::vec128b; using poly::vec128f; @@ -40,10 +40,6 @@ using poly::vec128i; using namespace Xbyak; using xe::cpu::hir::HIRBuilder; using xe::cpu::hir::Instr; -using xe::cpu::runtime::Function; -using xe::cpu::runtime::FunctionInfo; -using xe::cpu::runtime::SourceMapEntry; -using xe::cpu::runtime::ThreadState; static const size_t MAX_CODE_SIZE = 1 * 1024 * 1024; @@ -76,7 +72,7 @@ X64Emitter::~X64Emitter() {} int X64Emitter::Initialize() { return 0; } int X64Emitter::Emit(HIRBuilder* builder, uint32_t debug_info_flags, - runtime::DebugInfo* debug_info, uint32_t trace_flags, + DebugInfo* debug_info, uint32_t trace_flags, void*& out_code_address, size_t& out_code_size) { SCOPE_profile_cpu_f("cpu"); @@ -439,8 +435,7 @@ uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) { return addr; } -void X64Emitter::Call(const hir::Instr* instr, - runtime::FunctionInfo* symbol_info) { +void X64Emitter::Call(const hir::Instr* instr, FunctionInfo* symbol_info) { auto fn = reinterpret_cast(symbol_info->function()); // Resolve address to the function to call and store in rax. if (fn) { diff --git a/src/xenia/cpu/backend/x64/x64_emitter.h b/src/xenia/cpu/backend/x64/x64_emitter.h index 6d3d5dd9a..ac47f934a 100644 --- a/src/xenia/cpu/backend/x64/x64_emitter.h +++ b/src/xenia/cpu/backend/x64/x64_emitter.h @@ -16,16 +16,14 @@ namespace xe { namespace cpu { -namespace hir { -class HIRBuilder; -class Instr; -} // namespace hir -namespace runtime { class DebugInfo; class FunctionInfo; class Runtime; class SymbolInfo; -} // namespace runtime +namespace hir { +class HIRBuilder; +class Instr; +} // namespace hir } // namespace cpu } // namespace xe @@ -103,14 +101,14 @@ class X64Emitter : public Xbyak::CodeGenerator { X64Emitter(X64Backend* backend, XbyakAllocator* allocator); virtual ~X64Emitter(); - runtime::Runtime* runtime() const { return runtime_; } + Runtime* runtime() const { return runtime_; } X64Backend* backend() const { return backend_; } int Initialize(); int Emit(hir::HIRBuilder* builder, uint32_t debug_info_flags, - runtime::DebugInfo* debug_info, uint32_t trace_flags, - void*& out_code_address, size_t& out_code_size); + DebugInfo* debug_info, uint32_t trace_flags, void*& out_code_address, + size_t& out_code_size); public: // Reserved: rsp @@ -149,10 +147,9 @@ class X64Emitter : public Xbyak::CodeGenerator { void UnimplementedInstr(const hir::Instr* i); void UnimplementedExtern(const hir::Instr* i); - void Call(const hir::Instr* instr, runtime::FunctionInfo* symbol_info); + void Call(const hir::Instr* instr, FunctionInfo* symbol_info); void CallIndirect(const hir::Instr* instr, const Xbyak::Reg64& reg); - void CallExtern(const hir::Instr* instr, - const runtime::FunctionInfo* symbol_info); + void CallExtern(const hir::Instr* instr, const FunctionInfo* symbol_info); void CallNative(void* fn); void CallNative(uint64_t (*fn)(void* raw_context)); void CallNative(uint64_t (*fn)(void* raw_context, uint64_t arg0)); @@ -191,7 +188,7 @@ class X64Emitter : public Xbyak::CodeGenerator { void EmitTraceUserCallReturn(); protected: - runtime::Runtime* runtime_; + Runtime* runtime_; X64Backend* backend_; X64CodeCache* code_cache_; XbyakAllocator* allocator_; diff --git a/src/xenia/cpu/backend/x64/x64_function.cc b/src/xenia/cpu/backend/x64/x64_function.cc index 689dd8a40..dba992640 100644 --- a/src/xenia/cpu/backend/x64/x64_function.cc +++ b/src/xenia/cpu/backend/x64/x64_function.cc @@ -10,19 +10,14 @@ #include "xenia/cpu/backend/x64/x64_function.h" #include "xenia/cpu/backend/x64/x64_backend.h" -#include "xenia/cpu/runtime/runtime.h" -#include "xenia/cpu/runtime/thread_state.h" +#include "xenia/cpu/runtime.h" +#include "xenia/cpu/thread_state.h" namespace xe { namespace cpu { namespace backend { namespace x64 { -using xe::cpu::runtime::Breakpoint; -using xe::cpu::runtime::Function; -using xe::cpu::runtime::FunctionInfo; -using xe::cpu::runtime::ThreadState; - X64Function::X64Function(FunctionInfo* symbol_info) : Function(symbol_info), machine_code_(nullptr), code_size_(0) {} diff --git a/src/xenia/cpu/backend/x64/x64_function.h b/src/xenia/cpu/backend/x64/x64_function.h index d6692fc75..f697dc447 100644 --- a/src/xenia/cpu/backend/x64/x64_function.h +++ b/src/xenia/cpu/backend/x64/x64_function.h @@ -10,17 +10,18 @@ #ifndef XENIA_BACKEND_X64_X64_FUNCTION_H_ #define XENIA_BACKEND_X64_X64_FUNCTION_H_ -#include "xenia/cpu/runtime/function.h" -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/symbol_info.h" +#include "xenia/cpu/thread_state.h" namespace xe { namespace cpu { namespace backend { namespace x64 { -class X64Function : public runtime::Function { +class X64Function : public Function { public: - X64Function(runtime::FunctionInfo* symbol_info); + X64Function(FunctionInfo* symbol_info); virtual ~X64Function(); void* machine_code() const { return machine_code_; } @@ -29,10 +30,9 @@ class X64Function : public runtime::Function { void Setup(void* machine_code, size_t code_size); protected: - virtual int AddBreakpointImpl(runtime::Breakpoint* breakpoint); - virtual int RemoveBreakpointImpl(runtime::Breakpoint* breakpoint); - virtual int CallImpl(runtime::ThreadState* thread_state, - uint64_t return_address); + virtual int AddBreakpointImpl(Breakpoint* breakpoint); + virtual int RemoveBreakpointImpl(Breakpoint* breakpoint); + virtual int CallImpl(ThreadState* thread_state, uint64_t return_address); private: void* machine_code_; diff --git a/src/xenia/cpu/backend/x64/x64_sequences.cc b/src/xenia/cpu/backend/x64/x64_sequences.cc index e5297b910..305396f94 100644 --- a/src/xenia/cpu/backend/x64/x64_sequences.cc +++ b/src/xenia/cpu/backend/x64/x64_sequences.cc @@ -27,7 +27,7 @@ #include "xenia/cpu/backend/x64/x64_emitter.h" #include "xenia/cpu/backend/x64/x64_tracers.h" #include "xenia/cpu/hir/hir_builder.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" namespace xe { namespace cpu { @@ -38,7 +38,7 @@ using namespace Xbyak; // TODO(benvanik): direct usings. using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using poly::vec128b; diff --git a/src/xenia/cpu/backend/x64/x64_tracers.cc b/src/xenia/cpu/backend/x64/x64_tracers.cc index 059d5d65f..7d059e135 100644 --- a/src/xenia/cpu/backend/x64/x64_tracers.cc +++ b/src/xenia/cpu/backend/x64/x64_tracers.cc @@ -10,12 +10,12 @@ #include "xenia/cpu/backend/x64/x64_tracers.h" #include "xenia/cpu/backend/x64/x64_emitter.h" -#include "xenia/cpu/runtime/runtime.h" -#include "xenia/cpu/runtime/thread_state.h" +#include "xenia/cpu/runtime.h" +#include "xenia/cpu/thread_state.h" using namespace xe; using namespace xe::cpu::backend::x64; -using namespace xe::cpu::runtime; +using namespace xe::cpu; namespace xe { namespace cpu { diff --git a/src/xenia/cpu/compiler/compiler.cc b/src/xenia/cpu/compiler/compiler.cc index 2308de4a8..803880f5f 100644 --- a/src/xenia/cpu/compiler/compiler.cc +++ b/src/xenia/cpu/compiler/compiler.cc @@ -17,7 +17,7 @@ namespace cpu { namespace compiler { using xe::cpu::hir::HIRBuilder; -using xe::cpu::runtime::Runtime; +using xe::cpu::Runtime; Compiler::Compiler(Runtime* runtime) : runtime_(runtime) {} diff --git a/src/xenia/cpu/compiler/compiler.h b/src/xenia/cpu/compiler/compiler.h index e7973a00f..1c84d999f 100644 --- a/src/xenia/cpu/compiler/compiler.h +++ b/src/xenia/cpu/compiler/compiler.h @@ -18,9 +18,7 @@ namespace xe { namespace cpu { -namespace runtime { class Runtime; -} // namespace runtime } // namespace cpu } // namespace xe @@ -32,10 +30,10 @@ class CompilerPass; class Compiler { public: - Compiler(runtime::Runtime* runtime); + Compiler(Runtime* runtime); ~Compiler(); - runtime::Runtime* runtime() const { return runtime_; } + Runtime* runtime() const { return runtime_; } poly::Arena* scratch_arena() { return &scratch_arena_; } void AddPass(std::unique_ptr pass); @@ -45,7 +43,7 @@ class Compiler { int Compile(hir::HIRBuilder* builder); private: - runtime::Runtime* runtime_; + Runtime* runtime_; poly::Arena scratch_arena_; std::vector> passes_; diff --git a/src/xenia/cpu/compiler/compiler_pass.h b/src/xenia/cpu/compiler/compiler_pass.h index 975cc9595..884001433 100644 --- a/src/xenia/cpu/compiler/compiler_pass.h +++ b/src/xenia/cpu/compiler/compiler_pass.h @@ -15,9 +15,7 @@ namespace xe { namespace cpu { -namespace runtime { class Runtime; -} // namespace runtime } // namespace cpu } // namespace xe @@ -40,7 +38,7 @@ class CompilerPass { poly::Arena* scratch_arena() const; protected: - runtime::Runtime* runtime_; + Runtime* runtime_; Compiler* compiler_; }; diff --git a/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc b/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc index 16f4e3b85..7c9ff52e1 100644 --- a/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc +++ b/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc @@ -9,8 +9,8 @@ #include "xenia/cpu/compiler/passes/constant_propagation_pass.h" -#include "xenia/cpu/runtime/function.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" namespace xe { @@ -96,7 +96,7 @@ int ConstantPropagationPass::Run(HIRBuilder* builder) { break; case OPCODE_CALL_INDIRECT: if (i->src1.value->IsConstant()) { - runtime::FunctionInfo* symbol_info; + FunctionInfo* symbol_info; if (runtime_->LookupFunctionInfo( (uint32_t)i->src1.value->constant.i32, &symbol_info)) { break; diff --git a/src/xenia/cpu/compiler/passes/context_promotion_pass.cc b/src/xenia/cpu/compiler/passes/context_promotion_pass.cc index a675da8d7..35561e597 100644 --- a/src/xenia/cpu/compiler/passes/context_promotion_pass.cc +++ b/src/xenia/cpu/compiler/passes/context_promotion_pass.cc @@ -12,7 +12,7 @@ #include #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" DEFINE_bool(store_all_context_values, false, diff --git a/src/xenia/cpu/compiler/passes/control_flow_analysis_pass.cc b/src/xenia/cpu/compiler/passes/control_flow_analysis_pass.cc index 335498883..8f07c9fef 100644 --- a/src/xenia/cpu/compiler/passes/control_flow_analysis_pass.cc +++ b/src/xenia/cpu/compiler/passes/control_flow_analysis_pass.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/backend.h" #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" namespace xe { diff --git a/src/xenia/cpu/compiler/passes/control_flow_simplification_pass.cc b/src/xenia/cpu/compiler/passes/control_flow_simplification_pass.cc index 2a4520dd4..c6b9b7233 100644 --- a/src/xenia/cpu/compiler/passes/control_flow_simplification_pass.cc +++ b/src/xenia/cpu/compiler/passes/control_flow_simplification_pass.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/backend.h" #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" namespace xe { diff --git a/src/xenia/cpu/compiler/passes/data_flow_analysis_pass.cc b/src/xenia/cpu/compiler/passes/data_flow_analysis_pass.cc index 63f5d7f6d..15b8fa4a8 100644 --- a/src/xenia/cpu/compiler/passes/data_flow_analysis_pass.cc +++ b/src/xenia/cpu/compiler/passes/data_flow_analysis_pass.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/backend.h" #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" #if XE_COMPILER_MSVC diff --git a/src/xenia/cpu/compiler/passes/finalization_pass.cc b/src/xenia/cpu/compiler/passes/finalization_pass.cc index e585089bb..1d1ea73d7 100644 --- a/src/xenia/cpu/compiler/passes/finalization_pass.cc +++ b/src/xenia/cpu/compiler/passes/finalization_pass.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/backend.h" #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" namespace xe { diff --git a/src/xenia/cpu/compiler/passes/validation_pass.cc b/src/xenia/cpu/compiler/passes/validation_pass.cc index a3d1cd7b0..5c05c98b8 100644 --- a/src/xenia/cpu/compiler/passes/validation_pass.cc +++ b/src/xenia/cpu/compiler/passes/validation_pass.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/backend.h" #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" namespace xe { diff --git a/src/xenia/cpu/compiler/passes/value_reduction_pass.cc b/src/xenia/cpu/compiler/passes/value_reduction_pass.cc index 9f4e479e7..95c0cc5e0 100644 --- a/src/xenia/cpu/compiler/passes/value_reduction_pass.cc +++ b/src/xenia/cpu/compiler/passes/value_reduction_pass.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/backend.h" #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" #if XE_COMPILER_MSVC diff --git a/src/xenia/cpu/cpu.h b/src/xenia/cpu/cpu.h index 19b7fc983..3314abb9b 100644 --- a/src/xenia/cpu/cpu.h +++ b/src/xenia/cpu/cpu.h @@ -11,12 +11,12 @@ #define XENIA_CPU_CPU_H_ #include "xenia/cpu/processor.h" -#include "xenia/cpu/runtime/function.h" -#include "xenia/cpu/runtime/module.h" -#include "xenia/cpu/runtime/runtime.h" -#include "xenia/cpu/runtime/thread_state.h" -#include "xenia/cpu/xenon_runtime.h" -#include "xenia/cpu/xenon_thread_state.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/module.h" +#include "xenia/cpu/runtime.h" +#include "xenia/cpu/thread_state.h" +#include "xenia/cpu/runtime.h" +#include "xenia/cpu/thread_state.h" #include "xenia/cpu/xex_module.h" #endif // XENIA_CPU_CPU_H_ diff --git a/src/xenia/cpu/runtime/debug_info.cc b/src/xenia/cpu/debug_info.cc similarity index 96% rename from src/xenia/cpu/runtime/debug_info.cc rename to src/xenia/cpu/debug_info.cc index ef5355e8e..416b48e76 100644 --- a/src/xenia/cpu/runtime/debug_info.cc +++ b/src/xenia/cpu/debug_info.cc @@ -7,13 +7,12 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/debug_info.h" +#include "xenia/cpu/debug_info.h" #include namespace xe { namespace cpu { -namespace runtime { DebugInfo::DebugInfo() : source_disasm_(nullptr), @@ -72,6 +71,5 @@ SourceMapEntry* DebugInfo::LookupCodeOffset(uint64_t offset) { return nullptr; } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/debug_info.h b/src/xenia/cpu/debug_info.h similarity index 93% rename from src/xenia/cpu/runtime/debug_info.h rename to src/xenia/cpu/debug_info.h index 207559fce..9625d831a 100644 --- a/src/xenia/cpu/runtime/debug_info.h +++ b/src/xenia/cpu/debug_info.h @@ -7,15 +7,14 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_DEBUG_INFO_H_ -#define XENIA_RUNTIME_DEBUG_INFO_H_ +#ifndef XENIA_CPU_DEBUG_INFO_H_ +#define XENIA_CPU_DEBUG_INFO_H_ #include #include namespace xe { namespace cpu { -namespace runtime { enum DebugInfoFlags { DEBUG_INFO_NONE = 0, @@ -72,8 +71,7 @@ class DebugInfo { SourceMapEntry* source_map_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_DEBUG_INFO_H_ +#endif // XENIA_CPU_DEBUG_INFO_H_ diff --git a/src/xenia/cpu/runtime/debugger.cc b/src/xenia/cpu/debugger.cc similarity index 97% rename from src/xenia/cpu/runtime/debugger.cc rename to src/xenia/cpu/debugger.cc index b465fd9dc..02f7d3b58 100644 --- a/src/xenia/cpu/runtime/debugger.cc +++ b/src/xenia/cpu/debugger.cc @@ -7,15 +7,15 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/debugger.h" +#include "xenia/cpu/debugger.h" #include -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/runtime.h" namespace xe { namespace cpu { -namespace runtime { Breakpoint::Breakpoint(Type type, uint64_t address) : type_(type), address_(address) {} @@ -195,6 +195,5 @@ void Debugger::OnBreakpointHit(ThreadState* thread_state, // Note that we stay suspended. } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/debugger.h b/src/xenia/cpu/debugger.h similarity index 94% rename from src/xenia/cpu/runtime/debugger.h rename to src/xenia/cpu/debugger.h index fe76eaccd..efa7974da 100644 --- a/src/xenia/cpu/runtime/debugger.h +++ b/src/xenia/cpu/debugger.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_DEBUGGER_H_ -#define XENIA_RUNTIME_DEBUGGER_H_ +#ifndef XENIA_CPU_DEBUGGER_H_ +#define XENIA_CPU_DEBUGGER_H_ #include #include @@ -16,16 +16,15 @@ #include #include "poly/delegate.h" +#include "xenia/cpu/thread_state.h" namespace xe { namespace cpu { -namespace runtime { class Debugger; class Function; class FunctionInfo; class Runtime; -class ThreadState; class Breakpoint { public: @@ -117,8 +116,7 @@ class Debugger { std::multimap breakpoints_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_DEBUGGER_H_ +#endif // XENIA_CPU_DEBUGGER_H_ diff --git a/src/xenia/cpu/runtime/entry_table.cc b/src/xenia/cpu/entry_table.cc similarity index 96% rename from src/xenia/cpu/runtime/entry_table.cc rename to src/xenia/cpu/entry_table.cc index d23c277fa..efc3ff67c 100644 --- a/src/xenia/cpu/runtime/entry_table.cc +++ b/src/xenia/cpu/entry_table.cc @@ -7,14 +7,13 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/entry_table.h" +#include "xenia/cpu/entry_table.h" #include "poly/poly.h" #include "xenia/profiling.h" namespace xe { namespace cpu { -namespace runtime { EntryTable::EntryTable() = default; @@ -88,6 +87,5 @@ std::vector EntryTable::FindWithAddress(uint64_t address) { return fns; } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/entry_table.h b/src/xenia/cpu/entry_table.h similarity index 88% rename from src/xenia/cpu/runtime/entry_table.h rename to src/xenia/cpu/entry_table.h index f371ffb00..b44bf77d8 100644 --- a/src/xenia/cpu/runtime/entry_table.h +++ b/src/xenia/cpu/entry_table.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_ENTRY_TABLE_H_ -#define XENIA_RUNTIME_ENTRY_TABLE_H_ +#ifndef XENIA_CPU_ENTRY_TABLE_H_ +#define XENIA_CPU_ENTRY_TABLE_H_ #include #include @@ -16,7 +16,6 @@ namespace xe { namespace cpu { -namespace runtime { class Function; @@ -50,8 +49,7 @@ class EntryTable { std::unordered_map map_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_ENTRY_TABLE_H_ +#endif // XENIA_CPU_ENTRY_TABLE_H_ diff --git a/src/xenia/cpu/frontend/frontend.cc b/src/xenia/cpu/frontend/frontend.cc index c5a46e7b2..3c1c2c563 100644 --- a/src/xenia/cpu/frontend/frontend.cc +++ b/src/xenia/cpu/frontend/frontend.cc @@ -9,13 +9,13 @@ #include "xenia/cpu/frontend/frontend.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" namespace xe { namespace cpu { namespace frontend { -Frontend::Frontend(runtime::Runtime* runtime) : runtime_(runtime) {} +Frontend::Frontend(Runtime* runtime) : runtime_(runtime) {} Frontend::~Frontend() = default; diff --git a/src/xenia/cpu/frontend/frontend.h b/src/xenia/cpu/frontend/frontend.h index efa398951..1e15653cf 100644 --- a/src/xenia/cpu/frontend/frontend.h +++ b/src/xenia/cpu/frontend/frontend.h @@ -14,14 +14,12 @@ #include "xenia/cpu/frontend/context_info.h" #include "xenia/memory.h" -#include "xenia/cpu/runtime/function.h" -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/symbol_info.h" namespace xe { namespace cpu { -namespace runtime { class Runtime; -} // namespace runtime } // namespace cpu } // namespace xe @@ -31,22 +29,22 @@ namespace frontend { class Frontend { public: - Frontend(runtime::Runtime* runtime); + Frontend(Runtime* runtime); virtual ~Frontend(); - runtime::Runtime* runtime() const { return runtime_; } + Runtime* runtime() const { return runtime_; } Memory* memory() const; ContextInfo* context_info() const { return context_info_.get(); } virtual int Initialize(); - virtual int DeclareFunction(runtime::FunctionInfo* symbol_info) = 0; - virtual int DefineFunction(runtime::FunctionInfo* symbol_info, + virtual int DeclareFunction(FunctionInfo* symbol_info) = 0; + virtual int DefineFunction(FunctionInfo* symbol_info, uint32_t debug_info_flags, uint32_t trace_flags, - runtime::Function** out_function) = 0; + Function** out_function) = 0; protected: - runtime::Runtime* runtime_; + Runtime* runtime_; std::unique_ptr context_info_; }; diff --git a/src/xenia/cpu/frontend/ppc/ppc_context.h b/src/xenia/cpu/frontend/ppc/ppc_context.h index ea9beccb8..73a7259e4 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_context.h +++ b/src/xenia/cpu/frontend/ppc/ppc_context.h @@ -15,10 +15,8 @@ namespace xe { namespace cpu { -namespace runtime { class Runtime; class ThreadState; -} // namespace runtime } // namespace cpu } // namespace xe @@ -45,7 +43,7 @@ using vec128_t = poly::vec128_t; typedef struct alignas(64) PPCContext_s { // Must be stored at 0x0 for now. // TODO(benvanik): find a nice way to describe this to the JIT. - runtime::ThreadState* thread_state; + ThreadState* thread_state; // TODO(benvanik): this is getting nasty. Must be here. uint8_t* membase; @@ -211,7 +209,7 @@ typedef struct alignas(64) PPCContext_s { // Runtime-specific data pointer. Used on callbacks to get access to the // current runtime and its data. - runtime::Runtime* runtime; + Runtime* runtime; void SetRegFromString(const char* name, const char* value); bool CompareRegWithString(const char* name, const char* value, diff --git a/src/xenia/cpu/frontend/ppc/ppc_frontend.cc b/src/xenia/cpu/frontend/ppc/ppc_frontend.cc index 9a5436c63..17bc144a0 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_frontend.cc +++ b/src/xenia/cpu/frontend/ppc/ppc_frontend.cc @@ -13,16 +13,14 @@ #include "xenia/cpu/frontend/ppc/ppc_disasm.h" #include "xenia/cpu/frontend/ppc/ppc_emit.h" #include "xenia/cpu/frontend/ppc/ppc_translator.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" namespace xe { namespace cpu { namespace frontend { namespace ppc { -using xe::cpu::runtime::Function; -using xe::cpu::runtime::FunctionInfo; -using xe::cpu::runtime::Runtime; +using xe::cpu::Runtime; void InitializeIfNeeded(); void CleanupOnShutdown(); diff --git a/src/xenia/cpu/frontend/ppc/ppc_frontend.h b/src/xenia/cpu/frontend/ppc/ppc_frontend.h index 876c03920..55546e392 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_frontend.h +++ b/src/xenia/cpu/frontend/ppc/ppc_frontend.h @@ -25,23 +25,22 @@ class PPCTranslator; struct PPCBuiltins { std::mutex global_lock; bool global_lock_taken; - runtime::FunctionInfo* check_global_lock; - runtime::FunctionInfo* handle_global_lock; + FunctionInfo* check_global_lock; + FunctionInfo* handle_global_lock; }; class PPCFrontend : public Frontend { public: - PPCFrontend(runtime::Runtime* runtime); + PPCFrontend(Runtime* runtime); ~PPCFrontend() override; int Initialize() override; PPCBuiltins* builtins() { return &builtins_; } - int DeclareFunction(runtime::FunctionInfo* symbol_info) override; - int DefineFunction(runtime::FunctionInfo* symbol_info, - uint32_t debug_info_flags, uint32_t trace_flags, - runtime::Function** out_function) override; + int DeclareFunction(FunctionInfo* symbol_info) override; + int DefineFunction(FunctionInfo* symbol_info, uint32_t debug_info_flags, + uint32_t trace_flags, Function** out_function) override; private: poly::TypePool translator_pool_; diff --git a/src/xenia/cpu/frontend/ppc/ppc_hir_builder.cc b/src/xenia/cpu/frontend/ppc/ppc_hir_builder.cc index d9f5cdab9..eaa074e21 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_hir_builder.cc +++ b/src/xenia/cpu/frontend/ppc/ppc_hir_builder.cc @@ -15,7 +15,7 @@ #include "xenia/cpu/frontend/ppc/ppc_frontend.h" #include "xenia/cpu/frontend/ppc/ppc_instr.h" #include "xenia/cpu/hir/label.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/profiling.h" namespace xe { @@ -29,8 +29,6 @@ using namespace xe::cpu::hir; using xe::cpu::hir::Label; using xe::cpu::hir::TypeName; using xe::cpu::hir::Value; -using xe::cpu::runtime::Runtime; -using xe::cpu::runtime::FunctionInfo; PPCHIRBuilder::PPCHIRBuilder(PPCFrontend* frontend) : HIRBuilder(), frontend_(frontend), comment_buffer_(4096) {} diff --git a/src/xenia/cpu/frontend/ppc/ppc_hir_builder.h b/src/xenia/cpu/frontend/ppc/ppc_hir_builder.h index 86587e394..a877f3848 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_hir_builder.h +++ b/src/xenia/cpu/frontend/ppc/ppc_hir_builder.h @@ -11,8 +11,8 @@ #define XENIA_FRONTEND_PPC_PPC_HIR_BUILDER_H_ #include "xenia/cpu/hir/hir_builder.h" -#include "xenia/cpu/runtime/function.h" -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/symbol_info.h" #include "poly/string_buffer.h" namespace xe { @@ -41,10 +41,10 @@ class PPCHIRBuilder : public hir::HIRBuilder { // Emit TraceSource nodes with the resulting values of the operations. EMIT_TRACE_SOURCE_VALUES = EMIT_TRACE_SOURCE | (1 << 2), }; - int Emit(runtime::FunctionInfo* symbol_info, uint32_t flags); + int Emit(FunctionInfo* symbol_info, uint32_t flags); - runtime::FunctionInfo* symbol_info() const { return symbol_info_; } - runtime::FunctionInfo* LookupFunction(uint64_t address); + FunctionInfo* symbol_info() const { return symbol_info_; } + FunctionInfo* LookupFunction(uint64_t address); Label* LookupLabel(uint64_t address); Value* LoadLR(); @@ -96,7 +96,7 @@ class PPCHIRBuilder : public hir::HIRBuilder { // Reset each Emit: bool with_debug_info_; - runtime::FunctionInfo* symbol_info_; + FunctionInfo* symbol_info_; uint64_t start_address_; uint64_t instr_count_; Instr** instr_offset_list_; diff --git a/src/xenia/cpu/frontend/ppc/ppc_scanner.cc b/src/xenia/cpu/frontend/ppc/ppc_scanner.cc index 07488a317..ff60711f9 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_scanner.cc +++ b/src/xenia/cpu/frontend/ppc/ppc_scanner.cc @@ -14,7 +14,7 @@ #include "xenia/cpu/frontend/ppc/ppc_frontend.h" #include "xenia/cpu/frontend/ppc/ppc_instr.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "poly/logging.h" #include "poly/memory.h" #include "xenia/profiling.h" @@ -30,8 +30,6 @@ namespace cpu { namespace frontend { namespace ppc { -using xe::cpu::runtime::FunctionInfo; - PPCScanner::PPCScanner(PPCFrontend* frontend) : frontend_(frontend) {} PPCScanner::~PPCScanner() {} diff --git a/src/xenia/cpu/frontend/ppc/ppc_scanner.h b/src/xenia/cpu/frontend/ppc/ppc_scanner.h index a64a014ad..5ee8170cf 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_scanner.h +++ b/src/xenia/cpu/frontend/ppc/ppc_scanner.h @@ -12,7 +12,7 @@ #include -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/symbol_info.h" namespace xe { namespace cpu { @@ -31,9 +31,9 @@ class PPCScanner { PPCScanner(PPCFrontend* frontend); ~PPCScanner(); - int FindExtents(runtime::FunctionInfo* symbol_info); + int FindExtents(FunctionInfo* symbol_info); - std::vector FindBlocks(runtime::FunctionInfo* symbol_info); + std::vector FindBlocks(FunctionInfo* symbol_info); private: bool IsRestGprLr(uint64_t address); diff --git a/src/xenia/cpu/frontend/ppc/ppc_translator.cc b/src/xenia/cpu/frontend/ppc/ppc_translator.cc index 345f35555..2c055c7fc 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_translator.cc +++ b/src/xenia/cpu/frontend/ppc/ppc_translator.cc @@ -16,7 +16,7 @@ #include "xenia/cpu/frontend/ppc/ppc_hir_builder.h" #include "xenia/cpu/frontend/ppc/ppc_instr.h" #include "xenia/cpu/frontend/ppc/ppc_scanner.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "poly/reset_scope.h" #include "xenia/profiling.h" @@ -26,12 +26,10 @@ namespace frontend { namespace ppc { // TODO(benvanik): remove when enums redefined. -using namespace xe::cpu::runtime; +using namespace xe::cpu; using xe::cpu::backend::Backend; using xe::cpu::compiler::Compiler; -using xe::cpu::runtime::Function; -using xe::cpu::runtime::FunctionInfo; namespace passes = xe::cpu::compiler::passes; PPCTranslator::PPCTranslator(PPCFrontend* frontend) : frontend_(frontend) { @@ -175,7 +173,7 @@ int PPCTranslator::Translate(FunctionInfo* symbol_info, return 0; }; -void PPCTranslator::DumpSource(runtime::FunctionInfo* symbol_info, +void PPCTranslator::DumpSource(FunctionInfo* symbol_info, poly::StringBuffer* string_buffer) { Memory* memory = frontend_->memory(); const uint8_t* p = memory->membase(); diff --git a/src/xenia/cpu/frontend/ppc/ppc_translator.h b/src/xenia/cpu/frontend/ppc/ppc_translator.h index e8bfa8218..852d80655 100644 --- a/src/xenia/cpu/frontend/ppc/ppc_translator.h +++ b/src/xenia/cpu/frontend/ppc/ppc_translator.h @@ -14,7 +14,7 @@ #include "xenia/cpu/backend/assembler.h" #include "xenia/cpu/compiler/compiler.h" -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/symbol_info.h" #include "poly/string_buffer.h" namespace xe { @@ -31,12 +31,11 @@ class PPCTranslator { PPCTranslator(PPCFrontend* frontend); ~PPCTranslator(); - int Translate(runtime::FunctionInfo* symbol_info, uint32_t debug_info_flags, - uint32_t trace_flags, runtime::Function** out_function); + int Translate(FunctionInfo* symbol_info, uint32_t debug_info_flags, + uint32_t trace_flags, Function** out_function); private: - void DumpSource(runtime::FunctionInfo* symbol_info, - poly::StringBuffer* string_buffer); + void DumpSource(FunctionInfo* symbol_info, poly::StringBuffer* string_buffer); private: PPCFrontend* frontend_; diff --git a/src/xenia/cpu/frontend/ppc/test/xe-cpu-ppc-test.cc b/src/xenia/cpu/frontend/ppc/test/xe-cpu-ppc-test.cc index 4a3b50f31..12cde143a 100644 --- a/src/xenia/cpu/frontend/ppc/test/xe-cpu-ppc-test.cc +++ b/src/xenia/cpu/frontend/ppc/test/xe-cpu-ppc-test.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/x64/x64_backend.h" #include "xenia/cpu/frontend/ppc/ppc_context.h" #include "xenia/cpu/frontend/ppc/ppc_frontend.h" -#include "xenia/cpu/runtime/raw_module.h" +#include "xenia/cpu/raw_module.h" #include "poly/main.h" #include "poly/poly.h" @@ -30,61 +30,12 @@ namespace cpu { namespace test { using xe::cpu::frontend::ppc::PPCContext; -using xe::cpu::runtime::Runtime; +using xe::cpu::Runtime; typedef std::vector> AnnotationList; const uint32_t START_ADDRESS = 0x100000; -class ThreadState : public xe::cpu::runtime::ThreadState { - public: - ThreadState(Runtime* runtime, uint32_t thread_id, uint64_t stack_address, - size_t stack_size, uint64_t thread_state_address) - : xe::cpu::runtime::ThreadState(runtime, thread_id), - stack_address_(stack_address), - stack_size_(stack_size), - thread_state_address_(thread_state_address) { - memset(memory_->Translate(stack_address_), 0, stack_size_); - - // Allocate with 64b alignment. - context_ = (PPCContext*)calloc(1, sizeof(PPCContext)); - assert_true((reinterpret_cast(context_) & 0xF) == 0); - - // Stash pointers to common structures that callbacks may need. - context_->reserve_address = memory_->reserve_address(); - context_->reserve_value = memory_->reserve_value(); - context_->membase = memory_->membase(); - context_->runtime = runtime; - context_->thread_state = this; - - // Set initial registers. - context_->r[1] = stack_address_ + stack_size; - context_->r[13] = thread_state_address_; - - // Pad out stack a bit, as some games seem to overwrite the caller by about - // 16 to 32b. - context_->r[1] -= 64; - - raw_context_ = context_; - - runtime_->debugger()->OnThreadCreated(this); - } - ~ThreadState() override { - runtime_->debugger()->OnThreadDestroyed(this); - free(context_); - } - - PPCContext* context() const { return context_; } - - private: - uint64_t stack_address_; - size_t stack_size_; - uint64_t thread_state_address_; - - // NOTE: must be 64b aligned for SSE ops. - PPCContext* context_; -}; - struct TestCase { TestCase(uint64_t address, std::string& name) : address(address), name(name) {} @@ -224,10 +175,8 @@ class TestRunner { memory.reset(new Memory()); memory->Initialize(); - runtime.reset(new Runtime(memory.get())); - auto frontend = - std::make_unique(runtime.get()); - runtime->Initialize(std::move(frontend), nullptr); + runtime.reset(new Runtime(memory.get(), nullptr, 0, 0)); + runtime->Initialize(nullptr); } ~TestRunner() { @@ -238,7 +187,7 @@ class TestRunner { bool Setup(TestSuite& suite) { // Load the binary module. - auto module = std::make_unique(runtime.get()); + auto module = std::make_unique(runtime.get()); if (module->LoadFile(START_ADDRESS, suite.bin_file_path)) { PLOGE("Unable to load test binary %ls", suite.bin_file_path.c_str()); return false; @@ -263,7 +212,7 @@ class TestRunner { } // Execute test. - xe::cpu::runtime::Function* fn; + xe::cpu::Function* fn; runtime->ResolveFunction(test_case.address, &fn); if (!fn) { PLOGE("Entry function not found"); diff --git a/src/xenia/cpu/runtime/function.cc b/src/xenia/cpu/function.cc similarity index 94% rename from src/xenia/cpu/runtime/function.cc rename to src/xenia/cpu/function.cc index 9eb64f34f..e58ea397d 100644 --- a/src/xenia/cpu/runtime/function.cc +++ b/src/xenia/cpu/function.cc @@ -7,17 +7,16 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/function.h" +#include "xenia/cpu/function.h" -#include "xenia/cpu/runtime/debugger.h" -#include "xenia/cpu/runtime/symbol_info.h" -#include "xenia/cpu/runtime/thread_state.h" +#include "xenia/cpu/debugger.h" +#include "xenia/cpu/symbol_info.h" +#include "xenia/cpu/thread_state.h" #include "poly/logging.h" #include "xdb/protocol.h" namespace xe { namespace cpu { -namespace runtime { Function::Function(FunctionInfo* symbol_info) : address_(symbol_info->address()), symbol_info_(symbol_info) {} @@ -126,6 +125,5 @@ int Function::Call(ThreadState* thread_state, uint64_t return_address) { return result; } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/function.h b/src/xenia/cpu/function.h similarity index 88% rename from src/xenia/cpu/runtime/function.h rename to src/xenia/cpu/function.h index 37090c69c..8f7a46148 100644 --- a/src/xenia/cpu/runtime/function.h +++ b/src/xenia/cpu/function.h @@ -7,22 +7,21 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_FUNCTION_H_ -#define XENIA_RUNTIME_FUNCTION_H_ +#ifndef XENIA_CPU_FUNCTION_H_ +#define XENIA_CPU_FUNCTION_H_ #include #include #include -#include "xenia/cpu/runtime/debug_info.h" +#include "xenia/cpu/debug_info.h" +#include "xenia/cpu/thread_state.h" namespace xe { namespace cpu { -namespace runtime { class Breakpoint; class FunctionInfo; -class ThreadState; class Function { public: @@ -58,8 +57,7 @@ class Function { std::vector breakpoints_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_FUNCTION_H_ +#endif // XENIA_CPU_FUNCTION_H_ diff --git a/src/xenia/cpu/hir/hir_builder.cc b/src/xenia/cpu/hir/hir_builder.cc index 2ef6f3279..f55d11bab 100644 --- a/src/xenia/cpu/hir/hir_builder.cc +++ b/src/xenia/cpu/hir/hir_builder.cc @@ -12,15 +12,13 @@ #include "xenia/cpu/hir/block.h" #include "xenia/cpu/hir/instr.h" #include "xenia/cpu/hir/label.h" -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/symbol_info.h" #include "xenia/profiling.h" namespace xe { namespace cpu { namespace hir { -using xe::cpu::runtime::FunctionInfo; - #define ASSERT_ADDRESS_TYPE(value) #define ASSERT_INTEGER_TYPE(value) #define ASSERT_FLOAT_TYPE(value) diff --git a/src/xenia/cpu/hir/hir_builder.h b/src/xenia/cpu/hir/hir_builder.h index d30adcedf..e9e0ed3ae 100644 --- a/src/xenia/cpu/hir/hir_builder.h +++ b/src/xenia/cpu/hir/hir_builder.h @@ -81,12 +81,12 @@ class HIRBuilder { void Trap(uint16_t trap_code = 0); void TrapTrue(Value* cond, uint16_t trap_code = 0); - void Call(runtime::FunctionInfo* symbol_info, uint32_t call_flags = 0); - void CallTrue(Value* cond, runtime::FunctionInfo* symbol_info, + void Call(FunctionInfo* symbol_info, uint32_t call_flags = 0); + void CallTrue(Value* cond, FunctionInfo* symbol_info, uint32_t call_flags = 0); void CallIndirect(Value* value, uint32_t call_flags = 0); void CallIndirectTrue(Value* cond, Value* value, uint32_t call_flags = 0); - void CallExtern(runtime::FunctionInfo* symbol_info); + void CallExtern(FunctionInfo* symbol_info); void Return(); void ReturnTrue(Value* cond); void SetReturnAddress(Value* value); diff --git a/src/xenia/cpu/hir/instr.h b/src/xenia/cpu/hir/instr.h index bee06ebe5..2406781dc 100644 --- a/src/xenia/cpu/hir/instr.h +++ b/src/xenia/cpu/hir/instr.h @@ -15,9 +15,7 @@ namespace xe { namespace cpu { -namespace runtime { class FunctionInfo; -} // namespace runtime } // namespace cpu } // namespace xe @@ -39,7 +37,7 @@ class Instr { uint32_t ordinal; typedef union { - runtime::FunctionInfo* symbol_info; + FunctionInfo* symbol_info; Label* label; Value* value; uint64_t offset; diff --git a/src/xenia/cpu/runtime/instrument.cc b/src/xenia/cpu/instrument.cc similarity index 93% rename from src/xenia/cpu/runtime/instrument.cc rename to src/xenia/cpu/instrument.cc index eaeddac34..d94b22671 100644 --- a/src/xenia/cpu/runtime/instrument.cc +++ b/src/xenia/cpu/instrument.cc @@ -7,15 +7,14 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/instrument.h" +#include "xenia/cpu/instrument.h" #include "xenia/memory.h" -#include "xenia/cpu/runtime/function.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/runtime.h" namespace xe { namespace cpu { -namespace runtime { Instrument::Instrument(Runtime* runtime) : runtime_(runtime), memory_(runtime->memory()), is_attached_(false) {} @@ -109,6 +108,5 @@ void MemoryInstrument::Access(ThreadState* thread_state, uint64_t address, // TODO(benvanik): get thread local instance } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/instrument.h b/src/xenia/cpu/instrument.h similarity index 95% rename from src/xenia/cpu/runtime/instrument.h rename to src/xenia/cpu/instrument.h index e400c7e35..90c7d8955 100644 --- a/src/xenia/cpu/runtime/instrument.h +++ b/src/xenia/cpu/instrument.h @@ -7,24 +7,23 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_INSTRUMENT_H_ -#define XENIA_RUNTIME_INSTRUMENT_H_ +#ifndef XENIA_CPU_INSTRUMENT_H_ +#define XENIA_CPU_INSTRUMENT_H_ #include namespace xe { namespace cpu { class Memory; +class ThreadState; } // namespace cpu } // namespace xe namespace xe { namespace cpu { -namespace runtime { class Function; class Runtime; -class ThreadState; class Instrument { public: @@ -141,8 +140,7 @@ class MemoryInstrument : public Instrument { // v OnUnload(context) // // get proc address? -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_INSTRUMENT_H_ +#endif // XENIA_CPU_INSTRUMENT_H_ diff --git a/src/xenia/cpu/runtime/module.cc b/src/xenia/cpu/module.cc similarity index 98% rename from src/xenia/cpu/runtime/module.cc rename to src/xenia/cpu/module.cc index 8ff6f6124..9027a296b 100644 --- a/src/xenia/cpu/runtime/module.cc +++ b/src/xenia/cpu/module.cc @@ -7,18 +7,17 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/module.h" +#include "xenia/cpu/module.h" #include #include -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "poly/poly.h" #include "xenia/profiling.h" namespace xe { namespace cpu { -namespace runtime { Module::Module(Runtime* runtime) : runtime_(runtime), memory_(runtime->memory()) {} @@ -247,6 +246,5 @@ int Module::ReadMap(const char* file_name) { return 0; } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/module.h b/src/xenia/cpu/module.h similarity index 91% rename from src/xenia/cpu/runtime/module.h rename to src/xenia/cpu/module.h index 8ecefc988..57cec2612 100644 --- a/src/xenia/cpu/runtime/module.h +++ b/src/xenia/cpu/module.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_MODULE_H_ -#define XENIA_RUNTIME_MODULE_H_ +#ifndef XENIA_CPU_MODULE_H_ +#define XENIA_CPU_MODULE_H_ #include #include @@ -17,11 +17,10 @@ #include #include "xenia/memory.h" -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/symbol_info.h" namespace xe { namespace cpu { -namespace runtime { class Function; class Runtime; @@ -68,8 +67,7 @@ class Module { std::vector> list_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_MODULE_H_ +#endif // XENIA_CPU_MODULE_H_ diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index 8c29701c6..32e81a067 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -10,15 +10,18 @@ #include "xenia/cpu/processor.h" #include "xenia/cpu/cpu-private.h" -#include "xenia/cpu/xenon_runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/cpu/xex_module.h" #include "xenia/export_resolver.h" namespace xe { namespace cpu { +// TODO(benvanik): remove when enums converted. +using namespace xe::cpu; using namespace xe::cpu::backend; -using namespace xe::cpu::runtime; + +using PPCContext = xe::cpu::frontend::ppc::PPCContext; void InitializeIfNeeded(); void CleanupOnShutdown(); @@ -80,8 +83,8 @@ int Processor::Setup() { trace_flags |= TRACE_SOURCE_VALUES; } - runtime_ = new XenonRuntime(memory_, export_resolver_, debug_info_flags, - trace_flags); + runtime_ = + new Runtime(memory_, export_resolver_, debug_info_flags, trace_flags); if (!runtime_) { return 1; } @@ -93,7 +96,7 @@ int Processor::Setup() { return result; } - interrupt_thread_state_ = new XenonThreadState(runtime_, 0, 16 * 1024, 0); + interrupt_thread_state_ = new ThreadState(runtime_, 0, 0, 16 * 1024, 0); interrupt_thread_state_->set_name("Interrupt"); interrupt_thread_block_ = memory_->HeapAlloc(0, 2048, MEMORY_FLAG_ZERO); interrupt_thread_state_->context()->r[13] = interrupt_thread_block_; @@ -101,7 +104,7 @@ int Processor::Setup() { return 0; } -int Processor::Execute(XenonThreadState* thread_state, uint64_t address) { +int Processor::Execute(ThreadState* thread_state, uint64_t address) { SCOPE_profile_cpu_f("cpu"); // Attempt to get the function. @@ -126,7 +129,7 @@ int Processor::Execute(XenonThreadState* thread_state, uint64_t address) { return 0; } -uint64_t Processor::Execute(XenonThreadState* thread_state, uint64_t address, +uint64_t Processor::Execute(ThreadState* thread_state, uint64_t address, uint64_t args[], size_t arg_count) { SCOPE_profile_cpu_f("cpu"); diff --git a/src/xenia/cpu/processor.h b/src/xenia/cpu/processor.h index 84d76c1c0..9b3aa45bd 100644 --- a/src/xenia/cpu/processor.h +++ b/src/xenia/cpu/processor.h @@ -20,8 +20,8 @@ namespace xe { namespace cpu { -class XenonRuntime; -class XenonThreadState; +class Runtime; +class ThreadState; class XexModule; enum class Irql : uint32_t { @@ -37,14 +37,14 @@ class Processor { ~Processor(); ExportResolver* export_resolver() const { return export_resolver_; } - XenonRuntime* runtime() const { return runtime_; } + Runtime* runtime() const { return runtime_; } Memory* memory() const { return memory_; } int Setup(); - int Execute(XenonThreadState* thread_state, uint64_t address); - uint64_t Execute(XenonThreadState* thread_state, uint64_t address, - uint64_t args[], size_t arg_count); + int Execute(ThreadState* thread_state, uint64_t address); + uint64_t Execute(ThreadState* thread_state, uint64_t address, uint64_t args[], + size_t arg_count); Irql RaiseIrql(Irql new_value); void LowerIrql(Irql old_value); @@ -55,12 +55,12 @@ class Processor { private: ExportResolver* export_resolver_; - XenonRuntime* runtime_; + Runtime* runtime_; Memory* memory_; Irql irql_; std::mutex interrupt_thread_lock_; - XenonThreadState* interrupt_thread_state_; + ThreadState* interrupt_thread_state_; uint64_t interrupt_thread_block_; }; diff --git a/src/xenia/cpu/runtime/raw_module.cc b/src/xenia/cpu/raw_module.cc similarity index 95% rename from src/xenia/cpu/runtime/raw_module.cc rename to src/xenia/cpu/raw_module.cc index 02fbc1d9a..93e6b6970 100644 --- a/src/xenia/cpu/runtime/raw_module.cc +++ b/src/xenia/cpu/raw_module.cc @@ -7,14 +7,13 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/raw_module.h" +#include "xenia/cpu/raw_module.h" #include "poly/platform.h" #include "poly/string.h" namespace xe { namespace cpu { -namespace runtime { RawModule::RawModule(Runtime* runtime) : Module(runtime), base_address_(0), low_address_(0), high_address_(0) {} @@ -57,6 +56,5 @@ bool RawModule::ContainsAddress(uint64_t address) { return address >= low_address_ && address < high_address_; } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/raw_module.h b/src/xenia/cpu/raw_module.h similarity index 83% rename from src/xenia/cpu/runtime/raw_module.h rename to src/xenia/cpu/raw_module.h index 9cc402872..523f03470 100644 --- a/src/xenia/cpu/runtime/raw_module.h +++ b/src/xenia/cpu/raw_module.h @@ -7,16 +7,15 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_RAW_MODULE_H_ -#define XENIA_RUNTIME_RAW_MODULE_H_ +#ifndef XENIA_CPU_RAW_MODULE_H_ +#define XENIA_CPU_RAW_MODULE_H_ #include -#include "xenia/cpu/runtime/module.h" +#include "xenia/cpu/module.h" namespace xe { namespace cpu { -namespace runtime { class RawModule : public Module { public: @@ -36,8 +35,7 @@ class RawModule : public Module { uint64_t high_address_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_RAW_MODULE_H_ +#endif // XENIA_CPU_RAW_MODULE_H_ diff --git a/src/xenia/cpu/runtime/runtime.cc b/src/xenia/cpu/runtime.cc similarity index 92% rename from src/xenia/cpu/runtime/runtime.cc rename to src/xenia/cpu/runtime.cc index 3d6ec62f3..4cb787e05 100644 --- a/src/xenia/cpu/runtime/runtime.cc +++ b/src/xenia/cpu/runtime.cc @@ -7,13 +7,15 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include -#include "xenia/cpu/runtime/module.h" #include "poly/poly.h" #include "xdb/protocol.h" +#include "xenia/cpu/frontend/ppc/ppc_frontend.h" +#include "xenia/cpu/module.h" +#include "xenia/cpu/thread_state.h" // TODO(benvanik): based on compiler support #include "xenia/cpu/backend/x64/x64_backend.h" @@ -22,7 +24,6 @@ DEFINE_string(runtime_backend, "any", "Runtime backend [any, x64]."); namespace xe { namespace cpu { -namespace runtime { using xe::cpu::backend::Backend; using xe::cpu::frontend::Frontend; @@ -39,13 +40,14 @@ class BuiltinModule : public Module { std::string name_; }; -Runtime::Runtime(Memory* memory, uint32_t debug_info_flags, - uint32_t trace_flags) +Runtime::Runtime(Memory* memory, ExportResolver* export_resolver, + uint32_t debug_info_flags, uint32_t trace_flags) : memory_(memory), debug_info_flags_(debug_info_flags), trace_flags_(trace_flags), builtin_module_(nullptr), - next_builtin_address_(0x100000000ull) {} + next_builtin_address_(0x100000000ull), + export_resolver_(export_resolver) {} Runtime::~Runtime() { { @@ -58,8 +60,10 @@ Runtime::~Runtime() { backend_.reset(); } -int Runtime::Initialize(std::unique_ptr frontend, - std::unique_ptr backend) { +int Runtime::Initialize(std::unique_ptr backend) { + auto frontend = std::make_unique(this); + // TODO(benvanik): set options/etc. + // Must be initialized by subclass before calling into this. assert_not_null(memory_); @@ -145,7 +149,7 @@ FunctionInfo* Runtime::DefineBuiltin(const std::string& name, fn_info->set_end_address(address + 4); fn_info->set_name(name); fn_info->SetupExtern(handler, arg0, arg1); - fn_info->set_status(runtime::SymbolInfo::STATUS_DECLARED); + fn_info->set_status(SymbolInfo::STATUS_DECLARED); return fn_info; } @@ -280,6 +284,5 @@ int Runtime::DemandFunction(FunctionInfo* symbol_info, return 0; } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/runtime.h b/src/xenia/cpu/runtime.h similarity index 76% rename from src/xenia/cpu/runtime/runtime.h rename to src/xenia/cpu/runtime.h index 7a33e8c90..50e984843 100644 --- a/src/xenia/cpu/runtime/runtime.h +++ b/src/xenia/cpu/runtime.h @@ -7,39 +7,36 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_RUNTIME_H_ -#define XENIA_RUNTIME_RUNTIME_H_ - -#include -#include -#include +#ifndef XENIA_CPU_RUNTIME_H_ +#define XENIA_CPU_RUNTIME_H_ +#include "xenia/common.h" #include "xenia/cpu/backend/backend.h" +#include "xenia/cpu/debugger.h" +#include "xenia/cpu/entry_table.h" #include "xenia/cpu/frontend/frontend.h" +#include "xenia/cpu/function.h" +#include "xenia/cpu/module.h" +#include "xenia/cpu/thread_state.h" +#include "xenia/export_resolver.h" #include "xenia/memory.h" -#include "xenia/cpu/runtime/debugger.h" -#include "xenia/cpu/runtime/entry_table.h" -#include "xenia/cpu/runtime/module.h" -#include "xenia/cpu/runtime/symbol_info.h" -#include "xenia/cpu/runtime/thread_state.h" namespace xe { namespace cpu { -namespace runtime { class Runtime { public: - explicit Runtime(Memory* memory, uint32_t debug_info_flags = 0, - uint32_t trace_flags = 0); - virtual ~Runtime(); + Runtime(Memory* memory, ExportResolver* export_resolver, + uint32_t debug_info_flags, uint32_t trace_flags); + ~Runtime(); Memory* memory() const { return memory_; } Debugger* debugger() const { return debugger_.get(); } frontend::Frontend* frontend() const { return frontend_.get(); } backend::Backend* backend() const { return backend_.get(); } + ExportResolver* export_resolver() const { return export_resolver_; } - int Initialize(std::unique_ptr frontend, - std::unique_ptr backend = 0); + int Initialize(std::unique_ptr backend = 0); int AddModule(std::unique_ptr module); Module* GetModule(const char* name); @@ -63,7 +60,6 @@ class Runtime { private: int DemandFunction(FunctionInfo* symbol_info, Function** out_function); - protected: Memory* memory_; uint32_t debug_info_flags_; @@ -73,6 +69,7 @@ class Runtime { std::unique_ptr frontend_; std::unique_ptr backend_; + ExportResolver* export_resolver_; EntryTable entry_table_; std::mutex modules_lock_; @@ -81,8 +78,7 @@ class Runtime { uint64_t next_builtin_address_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_RUNTIME_H_ +#endif // XENIA_CPU_RUNTIME_H_ diff --git a/src/xenia/cpu/runtime/sources.gypi b/src/xenia/cpu/runtime/sources.gypi deleted file mode 100644 index 283b16c79..000000000 --- a/src/xenia/cpu/runtime/sources.gypi +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2013 Ben Vanik. All Rights Reserved. -{ - 'sources': [ - 'debug_info.cc', - 'debug_info.h', - 'debugger.cc', - 'debugger.h', - 'entry_table.cc', - 'entry_table.h', - 'function.cc', - 'function.h', - 'instrument.cc', - 'instrument.h', - 'module.cc', - 'module.h', - 'raw_module.cc', - 'raw_module.h', - 'runtime.cc', - 'runtime.h', - 'symbol_info.cc', - 'symbol_info.h', - 'test_module.cc', - 'test_module.h', - 'thread_state.cc', - 'thread_state.h', - ], - - 'includes': [ - ], -} diff --git a/src/xenia/cpu/runtime/thread_state.cc b/src/xenia/cpu/runtime/thread_state.cc deleted file mode 100644 index 0e515c28f..000000000 --- a/src/xenia/cpu/runtime/thread_state.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - ****************************************************************************** - * 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/runtime/thread_state.h" - -#include "xenia/cpu/runtime/runtime.h" -#include "poly/poly.h" - -namespace xe { -namespace cpu { -namespace runtime { - -thread_local ThreadState* thread_state_ = nullptr; - -ThreadState::ThreadState(Runtime* runtime, uint32_t thread_id) - : runtime_(runtime), - memory_(runtime->memory()), - thread_id_(thread_id), - name_(""), - backend_data_(0), - raw_context_(0) { - if (thread_id_ == UINT_MAX) { - // System thread. Assign the system thread ID with a high bit - // set so people know what's up. - uint32_t system_thread_handle = poly::threading::current_thread_id(); - thread_id_ = 0x80000000 | system_thread_handle; - } - backend_data_ = runtime->backend()->AllocThreadData(); -} - -ThreadState::~ThreadState() { - if (backend_data_) { - runtime_->backend()->FreeThreadData(backend_data_); - } - if (thread_state_ == this) { - thread_state_ = nullptr; - } -} - -void ThreadState::Bind(ThreadState* thread_state) { - thread_state_ = thread_state; -} - -ThreadState* ThreadState::Get() { return thread_state_; } - -uint32_t ThreadState::GetThreadID() { return thread_state_->thread_id_; } - -} // namespace runtime -} // namespace cpu -} // namespace xe diff --git a/src/xenia/cpu/sources.gypi b/src/xenia/cpu/sources.gypi index 9d9daa4f5..c4e996ed2 100644 --- a/src/xenia/cpu/sources.gypi +++ b/src/xenia/cpu/sources.gypi @@ -4,14 +4,32 @@ 'cpu-private.h', 'cpu.cc', 'cpu.h', + 'debug_info.cc', + 'debug_info.h', + 'debugger.cc', + 'debugger.h', + 'entry_table.cc', + 'entry_table.h', + 'function.cc', + 'function.h', + 'instrument.cc', + 'instrument.h', 'mmio_handler.cc', 'mmio_handler.h', + 'module.cc', + 'module.h', 'processor.cc', 'processor.h', - 'xenon_runtime.cc', - 'xenon_runtime.h', - 'xenon_thread_state.cc', - 'xenon_thread_state.h', + 'raw_module.cc', + 'raw_module.h', + 'runtime.cc', + 'runtime.h', + 'symbol_info.cc', + 'symbol_info.h', + 'test_module.cc', + 'test_module.h', + 'thread_state.cc', + 'thread_state.h', 'xex_module.cc', 'xex_module.h', ], @@ -42,6 +60,5 @@ 'compiler/sources.gypi', 'frontend/sources.gypi', 'hir/sources.gypi', - 'runtime/sources.gypi', ], } diff --git a/src/xenia/cpu/runtime/symbol_info.cc b/src/xenia/cpu/symbol_info.cc similarity index 94% rename from src/xenia/cpu/runtime/symbol_info.cc rename to src/xenia/cpu/symbol_info.cc index 33e9e566b..f822f8209 100644 --- a/src/xenia/cpu/runtime/symbol_info.cc +++ b/src/xenia/cpu/symbol_info.cc @@ -7,11 +7,10 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/symbol_info.h" +#include "xenia/cpu/symbol_info.h" namespace xe { namespace cpu { -namespace runtime { SymbolInfo::SymbolInfo(Type type, Module* module, uint64_t address) : type_(type), @@ -44,6 +43,5 @@ VariableInfo::VariableInfo(Module* module, uint64_t address) VariableInfo::~VariableInfo() = default; -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/symbol_info.h b/src/xenia/cpu/symbol_info.h similarity index 94% rename from src/xenia/cpu/runtime/symbol_info.h rename to src/xenia/cpu/symbol_info.h index fdb96192e..f176f2ad6 100644 --- a/src/xenia/cpu/runtime/symbol_info.h +++ b/src/xenia/cpu/symbol_info.h @@ -7,15 +7,14 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_SYMBOL_INFO_H_ -#define XENIA_RUNTIME_SYMBOL_INFO_H_ +#ifndef XENIA_CPU_SYMBOL_INFO_H_ +#define XENIA_CPU_SYMBOL_INFO_H_ #include #include namespace xe { namespace cpu { -namespace runtime { class Function; class Module; @@ -104,8 +103,7 @@ class VariableInfo : public SymbolInfo { ~VariableInfo() override; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_SYMBOL_INFO_H_ +#endif // XENIA_CPU_SYMBOL_INFO_H_ diff --git a/src/xenia/cpu/test/test_add.cc b/src/xenia/cpu/test/test_add.cc index ff7b86be9..e3a95157c 100644 --- a/src/xenia/cpu/test/test_add.cc +++ b/src/xenia/cpu/test/test_add.cc @@ -12,7 +12,7 @@ #include using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; diff --git a/src/xenia/cpu/test/test_byte_swap.cc b/src/xenia/cpu/test/test_byte_swap.cc index 44db4eae0..927d8f772 100644 --- a/src/xenia/cpu/test/test_byte_swap.cc +++ b/src/xenia/cpu/test/test_byte_swap.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_extract.cc b/src/xenia/cpu/test/test_extract.cc index f40e030b3..03c97e568 100644 --- a/src/xenia/cpu/test/test_extract.cc +++ b/src/xenia/cpu/test/test_extract.cc @@ -12,7 +12,7 @@ #include using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_insert.cc b/src/xenia/cpu/test/test_insert.cc index 0372db977..d18692236 100644 --- a/src/xenia/cpu/test/test_insert.cc +++ b/src/xenia/cpu/test/test_insert.cc @@ -12,7 +12,7 @@ #include using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_load_vector_shl_shr.cc b/src/xenia/cpu/test/test_load_vector_shl_shr.cc index cfcd1e62b..5082030bd 100644 --- a/src/xenia/cpu/test/test_load_vector_shl_shr.cc +++ b/src/xenia/cpu/test/test_load_vector_shl_shr.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_pack.cc b/src/xenia/cpu/test/test_pack.cc index 5f93447c2..bf9746d2e 100644 --- a/src/xenia/cpu/test/test_pack.cc +++ b/src/xenia/cpu/test/test_pack.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_permute.cc b/src/xenia/cpu/test/test_permute.cc index 1d82cc457..e2c674773 100644 --- a/src/xenia/cpu/test/test_permute.cc +++ b/src/xenia/cpu/test/test_permute.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_sha.cc b/src/xenia/cpu/test/test_sha.cc index a9368b2f8..ecbd415b5 100644 --- a/src/xenia/cpu/test/test_sha.cc +++ b/src/xenia/cpu/test/test_sha.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; diff --git a/src/xenia/cpu/test/test_shl.cc b/src/xenia/cpu/test/test_shl.cc index d12d054b3..f491c66fc 100644 --- a/src/xenia/cpu/test/test_shl.cc +++ b/src/xenia/cpu/test/test_shl.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; diff --git a/src/xenia/cpu/test/test_shr.cc b/src/xenia/cpu/test/test_shr.cc index 703ee9b73..243df51a4 100644 --- a/src/xenia/cpu/test/test_shr.cc +++ b/src/xenia/cpu/test/test_shr.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_swizzle.cc b/src/xenia/cpu/test/test_swizzle.cc index 0c17e0177..14a688dfd 100644 --- a/src/xenia/cpu/test/test_swizzle.cc +++ b/src/xenia/cpu/test/test_swizzle.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_unpack.cc b/src/xenia/cpu/test/test_unpack.cc index 3794063d3..bdc36dddc 100644 --- a/src/xenia/cpu/test/test_unpack.cc +++ b/src/xenia/cpu/test/test_unpack.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_vector_add.cc b/src/xenia/cpu/test/test_vector_add.cc index 4c89d774b..ac595e1c4 100644 --- a/src/xenia/cpu/test/test_vector_add.cc +++ b/src/xenia/cpu/test/test_vector_add.cc @@ -12,7 +12,7 @@ #include using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_vector_max.cc b/src/xenia/cpu/test/test_vector_max.cc index fa1dbcc28..998b7c931 100644 --- a/src/xenia/cpu/test/test_vector_max.cc +++ b/src/xenia/cpu/test/test_vector_max.cc @@ -12,7 +12,7 @@ #include using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_vector_min.cc b/src/xenia/cpu/test/test_vector_min.cc index caab12d6b..c53f21b7a 100644 --- a/src/xenia/cpu/test/test_vector_min.cc +++ b/src/xenia/cpu/test/test_vector_min.cc @@ -12,7 +12,7 @@ #include using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_vector_rotate_left.cc b/src/xenia/cpu/test/test_vector_rotate_left.cc index 96a71997f..9782b1fb6 100644 --- a/src/xenia/cpu/test/test_vector_rotate_left.cc +++ b/src/xenia/cpu/test/test_vector_rotate_left.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_vector_sha.cc b/src/xenia/cpu/test/test_vector_sha.cc index 5506ee775..ecb4fbbdb 100644 --- a/src/xenia/cpu/test/test_vector_sha.cc +++ b/src/xenia/cpu/test/test_vector_sha.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_vector_shl.cc b/src/xenia/cpu/test/test_vector_shl.cc index 9c80023cf..53e48a801 100644 --- a/src/xenia/cpu/test/test_vector_shl.cc +++ b/src/xenia/cpu/test/test_vector_shl.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/test_vector_shr.cc b/src/xenia/cpu/test/test_vector_shr.cc index 6a5cb0223..be2b90ff7 100644 --- a/src/xenia/cpu/test/test_vector_shr.cc +++ b/src/xenia/cpu/test/test_vector_shr.cc @@ -10,7 +10,7 @@ #include "xenia/cpu/test/util.h" using namespace xe::cpu::hir; -using namespace xe::cpu::runtime; +using namespace xe::cpu; using namespace xe::cpu::test; using xe::cpu::frontend::ppc::PPCContext; using namespace poly; diff --git a/src/xenia/cpu/test/util.h b/src/xenia/cpu/test/util.h index 0ba9f83ed..b0309a4ee 100644 --- a/src/xenia/cpu/test/util.h +++ b/src/xenia/cpu/test/util.h @@ -15,7 +15,7 @@ #include "xenia/cpu/frontend/ppc/ppc_context.h" #include "xenia/cpu/frontend/ppc/ppc_frontend.h" #include "xenia/cpu/hir/hir_builder.h" -#include "xenia/cpu/runtime/test_module.h" +#include "xenia/cpu/test_module.h" #include "poly/main.h" #include "poly/poly.h" @@ -28,56 +28,7 @@ namespace cpu { namespace test { using xe::cpu::frontend::ppc::PPCContext; -using xe::cpu::runtime::Runtime; - -class ThreadState : public xe::cpu::runtime::ThreadState { - public: - ThreadState(Runtime* runtime, uint32_t thread_id, uint64_t stack_address, - size_t stack_size, uint64_t thread_state_address) - : xe::cpu::runtime::ThreadState(runtime, thread_id), - stack_address_(stack_address), - stack_size_(stack_size), - thread_state_address_(thread_state_address) { - memset(memory_->Translate(stack_address_), 0, stack_size_); - - // Allocate with 64b alignment. - context_ = (PPCContext*)calloc(1, sizeof(PPCContext)); - assert_true((reinterpret_cast(context_) & 0xF) == 0); - - // Stash pointers to common structures that callbacks may need. - context_->reserve_address = memory_->reserve_address(); - context_->reserve_value = memory_->reserve_value(); - context_->membase = memory_->membase(); - context_->runtime = runtime; - context_->thread_state = this; - - // Set initial registers. - context_->r[1] = stack_address_ + stack_size; - context_->r[13] = thread_state_address_; - - // Pad out stack a bit, as some games seem to overwrite the caller by about - // 16 to 32b. - context_->r[1] -= 64; - - raw_context_ = context_; - - runtime_->debugger()->OnThreadCreated(this); - } - ~ThreadState() override { - runtime_->debugger()->OnThreadDestroyed(this); - free(context_); - } - - PPCContext* context() const { return context_; } - - private: - uint64_t stack_address_; - size_t stack_size_; - uint64_t thread_state_address_; - - // NOTE: must be 64b aligned for SSE ops. - PPCContext* context_; -}; +using xe::cpu::Runtime; class TestFunction { public: @@ -88,18 +39,16 @@ class TestFunction { #if XENIA_TEST_X64 { - auto runtime = std::make_unique(memory.get()); - auto frontend = - std::make_unique(runtime.get()); + auto runtime = std::make_unique(memory.get(), nullptr, 0, 0); auto backend = std::make_unique(runtime.get()); - runtime->Initialize(std::move(frontend), std::move(backend)); + runtime->Initialize(std::move(backend)); runtimes.emplace_back(std::move(runtime)); } #endif // XENIA_TEST_X64 for (auto& runtime : runtimes) { - auto module = std::make_unique( + auto module = std::make_unique( runtime.get(), "Test", [](uint64_t address) { return address == 0x1000; }, [generator](hir::HIRBuilder& b) { @@ -120,7 +69,7 @@ class TestFunction { for (auto& runtime : runtimes) { memory->Zero(0, memory_size); - xe::cpu::runtime::Function* fn; + xe::cpu::Function* fn; runtime->ResolveFunction(0x1000, &fn); uint64_t stack_size = 64 * 1024; diff --git a/src/xenia/cpu/test/xe-cpu-hir-test.cc b/src/xenia/cpu/test/xe-cpu-hir-test.cc index 4695ba64e..451a7c2da 100644 --- a/src/xenia/cpu/test/xe-cpu-hir-test.cc +++ b/src/xenia/cpu/test/xe-cpu-hir-test.cc @@ -17,7 +17,7 @@ namespace cpu { namespace test { using xe::cpu::frontend::ppc::PPCContext; -using xe::cpu::runtime::Runtime; +using xe::cpu::Runtime; int main(std::vector& args) { std::vector narrow_args; diff --git a/src/xenia/cpu/test/xe-cpu-sandbox.cc b/src/xenia/cpu/test/xe-cpu-sandbox.cc index d1640e967..27adc34d3 100644 --- a/src/xenia/cpu/test/xe-cpu-sandbox.cc +++ b/src/xenia/cpu/test/xe-cpu-sandbox.cc @@ -11,7 +11,7 @@ #include "xenia/cpu/backend/x64/x64_backend.h" #include "xenia/cpu/frontend/ppc/ppc_context.h" #include "xenia/cpu/frontend/ppc/ppc_frontend.h" -#include "xenia/cpu/runtime/raw_module.h" +#include "xenia/cpu/raw_module.h" #include "poly/main.h" #include "poly/poly.h" @@ -22,55 +22,7 @@ namespace cpu { namespace sandbox { using xe::cpu::frontend::ppc::PPCContext; -using xe::cpu::runtime::Runtime; - -class ThreadState : public xe::cpu::runtime::ThreadState { - public: - ThreadState(Runtime* runtime, uint32_t thread_id, uint64_t stack_address, - size_t stack_size, uint64_t thread_state_address) - : xe::cpu::runtime::ThreadState(runtime, thread_id), - stack_address_(stack_address), - stack_size_(stack_size), - thread_state_address_(thread_state_address) { - memset(memory_->Translate(stack_address_), 0, stack_size_); - - // Allocate with 64b alignment. - context_ = (PPCContext*)calloc(1, sizeof(PPCContext)); - assert_true((reinterpret_cast(context_) & 0xF) == 0); - - // Stash pointers to common structures that callbacks may need. - context_->reserve_address = memory_->reserve_address(); - context_->membase = memory_->membase(); - context_->runtime = runtime; - context_->thread_state = this; - - // Set initial registers. - context_->r[1] = stack_address_ + stack_size; - context_->r[13] = thread_state_address_; - - // Pad out stack a bit, as some games seem to overwrite the caller by about - // 16 to 32b. - context_->r[1] -= 64; - - raw_context_ = context_; - - runtime_->debugger()->OnThreadCreated(this); - } - ~ThreadState() override { - runtime_->debugger()->OnThreadDestroyed(this); - free(context_); - } - - PPCContext* context() const { return context_; } - - private: - uint64_t stack_address_; - size_t stack_size_; - uint64_t thread_state_address_; - - // NOTE: must be 64b aligned for SSE ops. - PPCContext* context_; -}; +using xe::cpu::Runtime; // TODO(benvanik): simple memory? move more into core? @@ -93,7 +45,7 @@ int main(std::vector& args) { // std::make_unique(runtime.get()); runtime->Initialize(std::move(frontend), std::move(backend)); - auto module = std::make_unique(runtime.get()); + auto module = std::make_unique(runtime.get()); module->LoadFile(0x00001000, L"test\\codegen\\instr_add.bin"); runtime->AddModule(std::move(module)); @@ -104,7 +56,7 @@ int main(std::vector& args) { auto thread_state = std::make_unique( runtime.get(), 100, stack_address, stack_size, thread_state_address); - xe::cpu::runtime::Function* fn; + xe::cpu::Function* fn; runtime->ResolveFunction(0x1000, &fn); auto ctx = thread_state->context(); ctx->lr = 0xBEBEBEBE; diff --git a/src/xenia/cpu/runtime/test_module.cc b/src/xenia/cpu/test_module.cc similarity index 95% rename from src/xenia/cpu/runtime/test_module.cc rename to src/xenia/cpu/test_module.cc index 40835ecdb..061b52867 100644 --- a/src/xenia/cpu/runtime/test_module.cc +++ b/src/xenia/cpu/test_module.cc @@ -7,23 +7,20 @@ ****************************************************************************** */ -#include "xenia/cpu/runtime/test_module.h" +#include "xenia/cpu/test_module.h" #include "xenia/cpu/compiler/compiler_passes.h" -#include "xenia/cpu/runtime/runtime.h" +#include "xenia/cpu/runtime.h" #include "poly/platform.h" #include "poly/reset_scope.h" #include "poly/string.h" namespace xe { namespace cpu { -namespace runtime { using xe::cpu::backend::Backend; using xe::cpu::compiler::Compiler; using xe::cpu::hir::HIRBuilder; -using xe::cpu::runtime::Function; -using xe::cpu::runtime::FunctionInfo; namespace passes = xe::cpu::compiler::passes; TestModule::TestModule(Runtime* runtime, const std::string& name, @@ -100,6 +97,5 @@ SymbolInfo::Status TestModule::DeclareFunction(uint64_t address, return status; } -} // namespace runtime } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/runtime/test_module.h b/src/xenia/cpu/test_module.h similarity index 88% rename from src/xenia/cpu/runtime/test_module.h rename to src/xenia/cpu/test_module.h index 65669df85..74c6c9a2a 100644 --- a/src/xenia/cpu/runtime/test_module.h +++ b/src/xenia/cpu/test_module.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_TEST_MODULE_H_ -#define XENIA_RUNTIME_TEST_MODULE_H_ +#ifndef XENIA_CPU_TEST_MODULE_H_ +#define XENIA_CPU_TEST_MODULE_H_ #include #include @@ -17,11 +17,10 @@ #include "xenia/cpu/backend/assembler.h" #include "xenia/cpu/compiler/compiler.h" #include "xenia/cpu/hir/hir_builder.h" -#include "xenia/cpu/runtime/module.h" +#include "xenia/cpu/module.h" namespace xe { namespace cpu { -namespace runtime { class TestModule : public Module { public: @@ -47,8 +46,7 @@ class TestModule : public Module { std::unique_ptr assembler_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_TEST_MODULE_H_ +#endif // XENIA_CPU_TEST_MODULE_H_ diff --git a/src/xenia/cpu/xenon_thread_state.cc b/src/xenia/cpu/thread_state.cc similarity index 61% rename from src/xenia/cpu/xenon_thread_state.cc rename to src/xenia/cpu/thread_state.cc index 636418c48..fc2de8fca 100644 --- a/src/xenia/cpu/xenon_thread_state.cc +++ b/src/xenia/cpu/thread_state.cc @@ -7,24 +7,47 @@ ****************************************************************************** */ -#include "xenia/cpu/xenon_thread_state.h" +#include "xenia/cpu/thread_state.h" #include "xdb/protocol.h" -#include "xenia/cpu/xenon_runtime.h" +#include "xenia/cpu/runtime.h" namespace xe { namespace cpu { using namespace xe::cpu::frontend; -using namespace xe::cpu::runtime; +using namespace xe::cpu; -XenonThreadState::XenonThreadState(XenonRuntime* runtime, uint32_t thread_id, - size_t stack_size, - uint64_t thread_state_address) - : ThreadState(runtime, thread_id), +using PPCContext = xe::cpu::frontend::ppc::PPCContext; + +thread_local ThreadState* thread_state_ = nullptr; + +ThreadState::ThreadState(Runtime* runtime, uint32_t thread_id, + uint64_t stack_address, size_t stack_size, + uint64_t thread_state_address) + : runtime_(runtime), + memory_(runtime->memory()), + thread_id_(thread_id), + name_(""), + backend_data_(0), + raw_context_(0), stack_size_(stack_size), thread_state_address_(thread_state_address) { - stack_address_ = xenon_memory()->HeapAlloc(0, stack_size, MEMORY_FLAG_ZERO); + if (thread_id_ == UINT_MAX) { + // System thread. Assign the system thread ID with a high bit + // set so people know what's up. + uint32_t system_thread_handle = poly::threading::current_thread_id(); + thread_id_ = 0x80000000 | system_thread_handle; + } + backend_data_ = runtime->backend()->AllocThreadData(); + + if (!stack_address) { + stack_address_ = memory()->HeapAlloc(0, stack_size, MEMORY_FLAG_ZERO); + stack_allocated_ = true; + } else { + stack_address_ = stack_address; + stack_allocated_ = false; + } assert_not_zero(stack_address_); // Allocate with 64b alignment. @@ -52,14 +75,31 @@ XenonThreadState::XenonThreadState(XenonRuntime* runtime, uint32_t thread_id, runtime_->debugger()->OnThreadCreated(this); } -XenonThreadState::~XenonThreadState() { +ThreadState::~ThreadState() { runtime_->debugger()->OnThreadDestroyed(this); + if (backend_data_) { + runtime_->backend()->FreeThreadData(backend_data_); + } + if (thread_state_ == this) { + thread_state_ = nullptr; + } + free(context_); - xenon_memory()->HeapFree(stack_address_, stack_size_); + if (stack_allocated_) { + memory()->HeapFree(stack_address_, stack_size_); + } } -void XenonThreadState::WriteRegisters(xdb::protocol::Registers* registers) { +void ThreadState::Bind(ThreadState* thread_state) { + thread_state_ = thread_state; +} + +ThreadState* ThreadState::Get() { return thread_state_; } + +uint32_t ThreadState::GetThreadID() { return thread_state_->thread_id_; } + +void ThreadState::WriteRegisters(xdb::protocol::Registers* registers) { registers->lr = context_->lr; registers->ctr = context_->ctr; registers->xer = 0xFEFEFEFE; diff --git a/src/xenia/cpu/runtime/thread_state.h b/src/xenia/cpu/thread_state.h similarity index 53% rename from src/xenia/cpu/runtime/thread_state.h rename to src/xenia/cpu/thread_state.h index cd8e9b6f7..d80c31b8e 100644 --- a/src/xenia/cpu/runtime/thread_state.h +++ b/src/xenia/cpu/thread_state.h @@ -7,23 +7,30 @@ ****************************************************************************** */ -#ifndef XENIA_RUNTIME_THREAD_STATE_H_ -#define XENIA_RUNTIME_THREAD_STATE_H_ - -#include +#ifndef XENIA_CPU_thread_state_H_ +#define XENIA_CPU_thread_state_H_ +#include "xenia/cpu/frontend/ppc/ppc_context.h" +#include "xenia/cpu/thread_state.h" +#include "xenia/common.h" #include "xenia/memory.h" +namespace xdb { +namespace protocol { +struct Registers; +} // namespace protocol +} // namespace xdb + namespace xe { namespace cpu { -namespace runtime { class Runtime; class ThreadState { public: - ThreadState(Runtime* runtime, uint32_t thread_id); - virtual ~ThreadState(); + ThreadState(Runtime* runtime, uint32_t thread_id, uint64_t stack_address, + size_t stack_size, uint64_t thread_state_address); + ~ThreadState(); Runtime* runtime() const { return runtime_; } Memory* memory() const { return memory_; } @@ -32,26 +39,38 @@ class ThreadState { void set_name(const std::string& value) { name_ = value; } void* backend_data() const { return backend_data_; } void* raw_context() const { return raw_context_; } + uint64_t stack_address() const { return stack_address_; } + size_t stack_size() const { return stack_size_; } + uint64_t thread_state_address() const { return thread_state_address_; } + xe::cpu::frontend::ppc::PPCContext* context() const { return context_; } int Suspend() { return Suspend(~0); } - virtual int Suspend(uint32_t timeout_ms) { return 1; } - virtual int Resume(bool force = false) { return 1; } + int Suspend(uint32_t timeout_ms) { return 1; } + int Resume(bool force = false) { return 1; } static void Bind(ThreadState* thread_state); static ThreadState* Get(); static uint32_t GetThreadID(); - protected: + void WriteRegisters(xdb::protocol::Registers* registers); + + private: Runtime* runtime_; Memory* memory_; uint32_t thread_id_; std::string name_; void* backend_data_; void* raw_context_; + uint64_t stack_address_; + bool stack_allocated_; + size_t stack_size_; + uint64_t thread_state_address_; + + // NOTE: must be 64b aligned for SSE ops. + xe::cpu::frontend::ppc::PPCContext* context_; }; -} // namespace runtime } // namespace cpu } // namespace xe -#endif // XENIA_RUNTIME_THREAD_STATE_H_ +#endif // XENIA_CPU_thread_state_H_ diff --git a/src/xenia/cpu/xenon_runtime.cc b/src/xenia/cpu/xenon_runtime.cc deleted file mode 100644 index 566198f1c..000000000 --- a/src/xenia/cpu/xenon_runtime.cc +++ /dev/null @@ -1,39 +0,0 @@ -/** - ****************************************************************************** - * 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/xenon_runtime.h" - -#include "xenia/cpu/frontend/ppc/ppc_frontend.h" -#include "xenia/cpu/xenon_thread_state.h" - -namespace xe { -namespace cpu { - -XenonRuntime::XenonRuntime(Memory* memory, ExportResolver* export_resolver, - uint32_t debug_info_flags, uint32_t trace_flags) - : Runtime(memory, debug_info_flags, trace_flags), - export_resolver_(export_resolver) {} - -XenonRuntime::~XenonRuntime() = default; - -int XenonRuntime::Initialize( - std::unique_ptr backend) { - auto frontend = std::make_unique(this); - // TODO(benvanik): set options/etc. - - int result = Runtime::Initialize(std::move(frontend), std::move(backend)); - if (result) { - return result; - } - - return result; -} - -} // namespace cpu -} // namespace xe diff --git a/src/xenia/cpu/xenon_runtime.h b/src/xenia/cpu/xenon_runtime.h deleted file mode 100644 index b8b279e6b..000000000 --- a/src/xenia/cpu/xenon_runtime.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - ****************************************************************************** - * 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. * - ****************************************************************************** - */ - -#ifndef XENIA_CPU_XENON_RUNTIME_H_ -#define XENIA_CPU_XENON_RUNTIME_H_ - -#include "xenia/cpu/runtime/runtime.h" -#include "xenia/common.h" -#include "xenia/cpu/xenon_thread_state.h" -#include "xenia/export_resolver.h" -#include "xenia/memory.h" - -namespace xe { -namespace cpu { - -class XenonThreadState; - -class XenonRuntime : public xe::cpu::runtime::Runtime { - public: - XenonRuntime(Memory* memory, ExportResolver* export_resolver, - uint32_t debug_info_flags, uint32_t trace_flags); - virtual ~XenonRuntime(); - - ExportResolver* export_resolver() const { return export_resolver_; } - - virtual int Initialize( - std::unique_ptr backend = 0); - - private: - ExportResolver* export_resolver_; -}; - -} // namespace cpu -} // namespace xe - -#endif // XENIA_CPU_XENON_RUNTIME_H_ diff --git a/src/xenia/cpu/xenon_thread_state.h b/src/xenia/cpu/xenon_thread_state.h deleted file mode 100644 index 693143577..000000000 --- a/src/xenia/cpu/xenon_thread_state.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - ****************************************************************************** - * 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. * - ****************************************************************************** - */ - -#ifndef XENIA_CPU_XENON_THREAD_STATE_H_ -#define XENIA_CPU_XENON_THREAD_STATE_H_ - -#include "xenia/cpu/frontend/ppc/ppc_context.h" -#include "xenia/cpu/runtime/thread_state.h" -#include "xenia/common.h" -#include "xenia/memory.h" - -namespace xdb { -namespace protocol { -struct Registers; -} // namespace protocol -} // namespace xdb - -namespace xe { -namespace cpu { - -class XenonRuntime; - -using PPCContext = xe::cpu::frontend::ppc::PPCContext; - -class XenonThreadState : public xe::cpu::runtime::ThreadState { - public: - XenonThreadState(XenonRuntime* runtime, uint32_t thread_id, size_t stack_size, - uint64_t thread_state_address); - virtual ~XenonThreadState(); - - Memory* xenon_memory() { return static_cast(memory_); } - uint64_t stack_address() const { return stack_address_; } - size_t stack_size() const { return stack_size_; } - uint64_t thread_state_address() const { return thread_state_address_; } - PPCContext* context() const { return context_; } - - void WriteRegisters(xdb::protocol::Registers* registers); - - private: - uint64_t stack_address_; - size_t stack_size_; - uint64_t thread_state_address_; - - // NOTE: must be 64b aligned for SSE ops. - PPCContext* context_; -}; - -} // namespace cpu -} // namespace xe - -#endif // XENIA_CPU_XENON_THREAD_STATE_H_ diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index f65a68af1..61c47581c 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -13,19 +13,21 @@ #include "poly/math.h" #include "xenia/cpu/cpu-private.h" -#include "xenia/cpu/xenon_runtime.h" +#include "xenia/cpu/runtime.h" #include "xenia/export_resolver.h" namespace xe { namespace cpu { -using namespace xe::cpu::runtime; +using namespace xe::cpu; + +using PPCContext = xe::cpu::frontend::ppc::PPCContext; void UndefinedImport(PPCContext* ppc_state, void* arg0, void* arg1) { XELOGE("call to undefined kernel import"); } -XexModule::XexModule(XenonRuntime* runtime) +XexModule::XexModule(Runtime* runtime) : Module(runtime), runtime_(runtime), xex_(nullptr), diff --git a/src/xenia/cpu/xex_module.h b/src/xenia/cpu/xex_module.h index 7d9ddb6ca..522f4be9d 100644 --- a/src/xenia/cpu/xex_module.h +++ b/src/xenia/cpu/xex_module.h @@ -12,18 +12,18 @@ #include -#include "xenia/cpu/runtime/module.h" +#include "xenia/cpu/module.h" #include "xenia/common.h" #include "xenia/kernel/util/xex2.h" namespace xe { namespace cpu { -class XenonRuntime; +class Runtime; -class XexModule : public xe::cpu::runtime::Module { +class XexModule : public xe::cpu::Module { public: - XexModule(XenonRuntime* runtime); + XexModule(Runtime* runtime); virtual ~XexModule(); xe_xex2_ref xex() const { return xex_; } @@ -40,7 +40,7 @@ private: int FindSaveRest(); private: - XenonRuntime* runtime_; + Runtime* runtime_; std::string name_; std::string path_; xe_xex2_ref xex_; diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h index 5a70e1efc..a55d24616 100644 --- a/src/xenia/emulator.h +++ b/src/xenia/emulator.h @@ -25,7 +25,7 @@ class AudioSystem; } // namespace apu namespace cpu { class Processor; -class XenonThreadState; +class ThreadState; } // namespace cpu namespace gpu { class GraphicsSystem; diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index 7be0363a8..d73a69d74 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -194,8 +194,8 @@ X_STATUS XThread::Create() { // Allocate processor thread state. // This is thread safe. thread_state_ = - new XenonThreadState(kernel_state()->processor()->runtime(), thread_id_, - creation_params_.stack_size, thread_state_address_); + new ThreadState(kernel_state()->processor()->runtime(), thread_id_, 0, + creation_params_.stack_size, thread_state_address_); X_STATUS return_code = PlatformCreate(); if (XFAILED(return_code)) { diff --git a/src/xenia/kernel/objects/xthread.h b/src/xenia/kernel/objects/xthread.h index 4a4fad19d..e400efe25 100644 --- a/src/xenia/kernel/objects/xthread.h +++ b/src/xenia/kernel/objects/xthread.h @@ -14,7 +14,7 @@ #include #include -#include "xenia/cpu/xenon_thread_state.h" +#include "xenia/cpu/thread_state.h" #include "xenia/kernel/xobject.h" #include "xenia/xbox.h" @@ -89,7 +89,7 @@ class XThread : public XObject { uint32_t scratch_size_; uint32_t tls_address_; uint32_t thread_state_address_; - cpu::XenonThreadState* thread_state_; + cpu::ThreadState* thread_state_; std::string name_; diff --git a/src/xenia/kernel/objects/xuser_module.cc b/src/xenia/kernel/objects/xuser_module.cc index 0c110fae9..366b3a987 100644 --- a/src/xenia/kernel/objects/xuser_module.cc +++ b/src/xenia/kernel/objects/xuser_module.cc @@ -105,7 +105,7 @@ X_STATUS XUserModule::LoadFromFile(const char* path) { X_STATUS XUserModule::LoadFromMemory(const void* addr, const size_t length) { Processor* processor = kernel_state()->processor(); - XenonRuntime* runtime = processor->runtime(); + Runtime* runtime = processor->runtime(); // Load the XEX into memory and decrypt. xe_xex2_options_t xex_options = {0}; diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index 8ebe37e70..d2d94b815 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -64,7 +64,7 @@ DEFINE_bool(scribble_heap, false, * sizes or use madvice to let the OS know what to expect. * * We create our own heap of committed memory that lives at - * XENON_MEMORY_HEAP_LOW to XENON_MEMORY_HEAP_HIGH - all normal user allocations + * memory_HEAP_LOW to memory_HEAP_HIGH - all normal user allocations * come from there. Since the Xbox has no paging, we know that the size of this * heap will never need to be larger than ~512MB (realistically, smaller than * that). We place it far away from the XEX data and keep the memory around it @@ -80,10 +80,10 @@ DEFINE_bool(scribble_heap, false, * this. */ -#define XENON_MEMORY_PHYSICAL_HEAP_LOW 0x00010000 -#define XENON_MEMORY_PHYSICAL_HEAP_HIGH 0x20000000 -#define XENON_MEMORY_VIRTUAL_HEAP_LOW 0x20000000 -#define XENON_MEMORY_VIRTUAL_HEAP_HIGH 0x40000000 +#define MEMORY_PHYSICAL_HEAP_LOW 0x00010000 +#define MEMORY_PHYSICAL_HEAP_HIGH 0x20000000 +#define MEMORY_VIRTUAL_HEAP_LOW 0x20000000 +#define MEMORY_VIRTUAL_HEAP_HIGH 0x40000000 class xe::MemoryHeap { public: @@ -187,10 +187,9 @@ int Memory::Initialize() { membase_ = mapping_base_; // Prepare heaps. - virtual_heap_->Initialize(XENON_MEMORY_VIRTUAL_HEAP_LOW, - XENON_MEMORY_VIRTUAL_HEAP_HIGH); - physical_heap_->Initialize(XENON_MEMORY_PHYSICAL_HEAP_LOW, - XENON_MEMORY_PHYSICAL_HEAP_HIGH - 0x1000); + virtual_heap_->Initialize(MEMORY_VIRTUAL_HEAP_LOW, MEMORY_VIRTUAL_HEAP_HIGH); + physical_heap_->Initialize(MEMORY_PHYSICAL_HEAP_LOW, + MEMORY_PHYSICAL_HEAP_HIGH - 0x1000); // GPU writeback. // 0xC... is physical, 0x7F... is virtual. We may need to overlay these. @@ -348,14 +347,14 @@ uint64_t Memory::HeapAlloc(uint64_t base_address, size_t size, uint32_t flags, } return result; } else { - if (base_address >= XENON_MEMORY_VIRTUAL_HEAP_LOW && - base_address < XENON_MEMORY_VIRTUAL_HEAP_HIGH) { + if (base_address >= MEMORY_VIRTUAL_HEAP_LOW && + base_address < MEMORY_VIRTUAL_HEAP_HIGH) { // Overlapping managed heap. assert_always(); return 0; } - if (base_address >= XENON_MEMORY_PHYSICAL_HEAP_LOW && - base_address < XENON_MEMORY_PHYSICAL_HEAP_HIGH) { + if (base_address >= MEMORY_PHYSICAL_HEAP_LOW && + base_address < MEMORY_PHYSICAL_HEAP_HIGH) { // Overlapping managed heap. assert_always(); return 0; @@ -380,11 +379,11 @@ uint64_t Memory::HeapAlloc(uint64_t base_address, size_t size, uint32_t flags, } int Memory::HeapFree(uint64_t address, size_t size) { - if (address >= XENON_MEMORY_VIRTUAL_HEAP_LOW && - address < XENON_MEMORY_VIRTUAL_HEAP_HIGH) { + if (address >= MEMORY_VIRTUAL_HEAP_LOW && + address < MEMORY_VIRTUAL_HEAP_HIGH) { return virtual_heap_->Free(address, size) ? 0 : 1; - } else if (address >= XENON_MEMORY_PHYSICAL_HEAP_LOW && - address < XENON_MEMORY_PHYSICAL_HEAP_HIGH) { + } else if (address >= MEMORY_PHYSICAL_HEAP_LOW && + address < MEMORY_PHYSICAL_HEAP_HIGH) { return physical_heap_->Free(address, size) ? 0 : 1; } else { // A placed address. Decommit. @@ -411,11 +410,11 @@ bool Memory::QueryInformation(uint64_t base_address, AllocationInfo* mem_info) { } size_t Memory::QuerySize(uint64_t base_address) { - if (base_address >= XENON_MEMORY_VIRTUAL_HEAP_LOW && - base_address < XENON_MEMORY_VIRTUAL_HEAP_HIGH) { + if (base_address >= MEMORY_VIRTUAL_HEAP_LOW && + base_address < MEMORY_VIRTUAL_HEAP_HIGH) { return virtual_heap_->QuerySize(base_address); - } else if (base_address >= XENON_MEMORY_PHYSICAL_HEAP_LOW && - base_address < XENON_MEMORY_PHYSICAL_HEAP_HIGH) { + } else if (base_address >= MEMORY_PHYSICAL_HEAP_LOW && + base_address < MEMORY_PHYSICAL_HEAP_HIGH) { return physical_heap_->QuerySize(base_address); } else { // A placed address.