diff --git a/src/xenia/gpu/xenos/ucode.cc b/src/xenia/apu/apu-private.h similarity index 76% rename from src/xenia/gpu/xenos/ucode.cc rename to src/xenia/apu/apu-private.h index 90a46ef50..181dd9f9b 100644 --- a/src/xenia/gpu/xenos/ucode.cc +++ b/src/xenia/apu/apu-private.h @@ -1,15 +1,19 @@ -/** - ****************************************************************************** - * 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 - - -using namespace xe; -using namespace xe::gpu; -using namespace xe::gpu::xenos; +/** + ****************************************************************************** + * 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_APU_APU_PRIVATE_H_ +#define XENIA_APU_APU_PRIVATE_H_ + +#include + + +DECLARE_string(apu); + + +#endif // XENIA_APU_APU_PRIVATE_H_ diff --git a/src/xenia/apu/apu.cc b/src/xenia/apu/apu.cc new file mode 100644 index 000000000..b9f6fea5e --- /dev/null +++ b/src/xenia/apu/apu.cc @@ -0,0 +1,39 @@ +/** + ****************************************************************************** + * 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 +#include + + + +using namespace xe; +using namespace xe::apu; + + +DEFINE_string(apu, "any", + "Audio system. Use: [any, nop]"); + + +#include +AudioSystem* xe::apu::CreateNop(Emulator* emulator) { + return xe::apu::nop::Create(emulator); +} + + +AudioSystem* xe::apu::Create(Emulator* emulator) { + if (FLAGS_apu.compare("nop") == 0) { + return CreateNop(emulator); + } else { + // Create best available. + AudioSystem* best = NULL; + + // Fallback to nop. + return CreateNop(emulator); + } +} diff --git a/src/xenia/apu/apu.h b/src/xenia/apu/apu.h new file mode 100644 index 000000000..de63f0756 --- /dev/null +++ b/src/xenia/apu/apu.h @@ -0,0 +1,32 @@ +/** + ****************************************************************************** + * 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_APU_APU_H_ +#define XENIA_APU_APU_H_ + +#include + + +XEDECLARECLASS1(xe, Emulator); + + +namespace xe { +namespace apu { + + +AudioSystem* Create(Emulator* emulator); + +AudioSystem* CreateNop(Emulator* emulator); + + +} // namespace apu +} // namespace xe + + +#endif // XENIA_APU_APU_H_ diff --git a/src/xenia/apu/audio_driver.cc b/src/xenia/apu/audio_driver.cc new file mode 100644 index 000000000..0affc2c3a --- /dev/null +++ b/src/xenia/apu/audio_driver.cc @@ -0,0 +1,23 @@ +/** + ****************************************************************************** + * 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 + + +using namespace xe; +using namespace xe::apu; + + +AudioDriver::AudioDriver(xe_memory_ref memory) { + memory_ = xe_memory_retain(memory); +} + +AudioDriver::~AudioDriver() { + xe_memory_release(memory_); +} diff --git a/src/xenia/apu/audio_driver.h b/src/xenia/apu/audio_driver.h new file mode 100644 index 000000000..eb0a9d1b8 --- /dev/null +++ b/src/xenia/apu/audio_driver.h @@ -0,0 +1,39 @@ +/** + ****************************************************************************** + * 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_APU_AUDIO_DRIVER_H_ +#define XENIA_APU_AUDIO_DRIVER_H_ + +#include + + +namespace xe { +namespace apu { + + +class AudioDriver { +public: + virtual ~AudioDriver(); + + xe_memory_ref memory() const { return memory_; } + + virtual void Initialize() = 0; + +protected: + AudioDriver(xe_memory_ref memory); + + xe_memory_ref memory_; +}; + + +} // namespace apu +} // namespace xe + + +#endif // XENIA_APU_AUDIO_DRIVER_H_ diff --git a/src/xenia/apu/audio_system.cc b/src/xenia/apu/audio_system.cc new file mode 100644 index 000000000..f19be8b5c --- /dev/null +++ b/src/xenia/apu/audio_system.cc @@ -0,0 +1,116 @@ +/** + ****************************************************************************** + * 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 + +#include +#include +#include + + +using namespace xe; +using namespace xe::apu; +using namespace xe::cpu::ppc; + + +AudioSystem::AudioSystem(Emulator* emulator) : + emulator_(emulator), + thread_(0), running_(false), driver_(0) { + memory_ = xe_memory_retain(emulator->memory()); + + // Create the run loop used for any windows/etc. + // This must be done on the thread we create the driver. + run_loop_ = xe_run_loop_create(); +} + +AudioSystem::~AudioSystem() { + // TODO(benvanik): thread join. + running_ = false; + xe_thread_release(thread_); + + xe_run_loop_release(run_loop_); + xe_memory_release(memory_); +} + +X_STATUS AudioSystem::Setup() { + processor_ = emulator_->processor(); + + // Let the processor know we want register access callbacks. + RegisterAccessCallbacks callbacks; + callbacks.context = this; + callbacks.handles = (RegisterHandlesCallback)HandlesRegisterThunk; + callbacks.read = (RegisterReadCallback)ReadRegisterThunk; + callbacks.write = (RegisterWriteCallback)WriteRegisterThunk; + emulator_->processor()->AddRegisterAccessCallbacks(callbacks); + + // Create worker thread. + // This will initialize the audio system. + // Init needs to happen there so that any thread-local stuff + // is created on the right thread. + running_ = true; + thread_ = xe_thread_create( + "AudioSystem", + (xe_thread_callback)ThreadStartThunk, this); + xe_thread_start(thread_); + + return X_STATUS_SUCCESS; +} + +void AudioSystem::ThreadStart() { + xe_run_loop_ref run_loop = xe_run_loop_retain(run_loop_); + + // Initialize driver and ringbuffer. + Initialize(); + XEASSERTNOTNULL(driver_); + + // Main run loop. + while (running_) { + // Peek main run loop. + if (xe_run_loop_pump(run_loop)) { + break; + } + if (!running_) { + break; + } + + // Pump worker. + //worker_->Pump(); + + // Pump audio system. + Pump(); + } + running_ = false; + + Shutdown(); + + xe_run_loop_release(run_loop); + + // TODO(benvanik): call module API to kill? +} + +void AudioSystem::Initialize() { +} + +void AudioSystem::Shutdown() { +} + +bool AudioSystem::HandlesRegister(uint32_t addr) { + return (addr & 0xFFFF0000) == 0x7FEA0000; +} + +uint64_t AudioSystem::ReadRegister(uint32_t addr) { + uint32_t r = addr & 0xFFFF; + XELOGAPU("ReadRegister(%.4X)", r); + return 0; +} + +void AudioSystem::WriteRegister(uint32_t addr, uint64_t value) { + uint32_t r = addr & 0xFFFF; + XELOGAPU("WriteRegister(%.4X, %.8X)", r, value); +} \ No newline at end of file diff --git a/src/xenia/apu/audio_system.h b/src/xenia/apu/audio_system.h new file mode 100644 index 000000000..4b953bad6 --- /dev/null +++ b/src/xenia/apu/audio_system.h @@ -0,0 +1,82 @@ +/** + ****************************************************************************** + * 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_APU_AUDIO_SYSTEM_H_ +#define XENIA_APU_AUDIO_SYSTEM_H_ + +#include +#include + + +XEDECLARECLASS1(xe, Emulator); +XEDECLARECLASS2(xe, cpu, Processor); + + +namespace xe { +namespace apu { + +class AudioDriver; + + +class AudioSystem { +public: + virtual ~AudioSystem(); + + Emulator* emulator() const { return emulator_; } + xe_memory_ref memory() const { return memory_; } + cpu::Processor* processor() const { return processor_; } + + virtual X_STATUS Setup(); + + bool HandlesRegister(uint32_t addr); + virtual uint64_t ReadRegister(uint32_t addr); + virtual void WriteRegister(uint32_t addr, uint64_t value); + +protected: + virtual void Initialize(); + virtual void Pump() = 0; + virtual void Shutdown(); + +private: + static void ThreadStartThunk(AudioSystem* this_ptr) { + this_ptr->ThreadStart(); + } + void ThreadStart(); + + static bool HandlesRegisterThunk(AudioSystem* as, uint32_t addr) { + return as->HandlesRegister(addr); + } + static uint64_t ReadRegisterThunk(AudioSystem* as, uint32_t addr) { + return as->ReadRegister(addr); + } + static void WriteRegisterThunk(AudioSystem* as, uint32_t addr, + uint64_t value) { + as->WriteRegister(addr, value); + } + +protected: + AudioSystem(Emulator* emulator); + + Emulator* emulator_; + xe_memory_ref memory_; + cpu::Processor* processor_; + + xe_run_loop_ref run_loop_; + xe_thread_ref thread_; + bool running_; + + AudioDriver* driver_; +}; + + +} // namespace apu +} // namespace xe + + +#endif // XENIA_APU_AUDIO_SYSTEM_H_ diff --git a/src/xenia/apu/nop/nop_apu-private.h b/src/xenia/apu/nop/nop_apu-private.h new file mode 100644 index 000000000..23da172dd --- /dev/null +++ b/src/xenia/apu/nop/nop_apu-private.h @@ -0,0 +1,31 @@ +/** + ****************************************************************************** + * 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_APU_NOP_NOP_APU_PRIVATE_H_ +#define XENIA_APU_NOP_NOP_APU_PRIVATE_H_ + +#include + +#include + + +namespace xe { +namespace apu { +namespace nop { + + + + + +} // namespace nop +} // namespace apu +} // namespace xe + + +#endif // XENIA_APU_NOP_NOP_APU_PRIVATE_H_ diff --git a/src/xenia/apu/nop/nop_apu.cc b/src/xenia/apu/nop/nop_apu.cc new file mode 100644 index 000000000..ecd2b4a67 --- /dev/null +++ b/src/xenia/apu/nop/nop_apu.cc @@ -0,0 +1,44 @@ +/** + ****************************************************************************** + * 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 + +#include + + +using namespace xe; +using namespace xe::apu; +using namespace xe::apu::nop; + + +namespace { + void InitializeIfNeeded(); + void CleanupOnShutdown(); + + void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; + } + has_initialized = true; + + // + + atexit(CleanupOnShutdown); + } + + void CleanupOnShutdown() { + } +} + + +AudioSystem* xe::apu::nop::Create(Emulator* emulator) { + InitializeIfNeeded(); + return new NopAudioSystem(emulator); +} diff --git a/src/xenia/gpu/nop/nop.h b/src/xenia/apu/nop/nop_apu.h similarity index 80% rename from src/xenia/gpu/nop/nop.h rename to src/xenia/apu/nop/nop_apu.h index 896a9822f..e6e49f2fe 100644 --- a/src/xenia/gpu/nop/nop.h +++ b/src/xenia/apu/nop/nop_apu.h @@ -1,33 +1,33 @@ -/** - ****************************************************************************** - * 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_GPU_NOP_NOP_H_ -#define XENIA_GPU_NOP_NOP_H_ - -#include - - -namespace xe { -namespace gpu { - -class CreationParams; -class GraphicsSystem; - -namespace nop { - - -GraphicsSystem* Create(const CreationParams* params); - - -} // namespace nop -} // namespace gpu -} // namespace xe - - -#endif // XENIA_GPU_NOP_NOP_H_ +/** + ****************************************************************************** + * 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_GPU_NOP_NOP_H_ +#define XENIA_GPU_NOP_NOP_H_ + +#include + + +XEDECLARECLASS1(xe, Emulator); +XEDECLARECLASS2(xe, apu, AudioSystem); + + +namespace xe { +namespace apu { +namespace nop { + + +AudioSystem* Create(Emulator* emulator); + + +} // namespace nop +} // namespace apu +} // namespace xe + + +#endif // XENIA_GPU_NOP_NOP_H_ diff --git a/src/xenia/apu/nop/nop_audio_driver.cc b/src/xenia/apu/nop/nop_audio_driver.cc new file mode 100644 index 000000000..86ee77199 --- /dev/null +++ b/src/xenia/apu/nop/nop_audio_driver.cc @@ -0,0 +1,28 @@ +/** + ****************************************************************************** + * 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 + +#include + + +using namespace xe; +using namespace xe::apu; +using namespace xe::apu::nop; + + +NopAudioDriver::NopAudioDriver(xe_memory_ref memory) : + AudioDriver(memory) { +} + +NopAudioDriver::~NopAudioDriver() { +} + +void NopAudioDriver::Initialize() { +} diff --git a/src/xenia/apu/nop/nop_audio_driver.h b/src/xenia/apu/nop/nop_audio_driver.h new file mode 100644 index 000000000..c04bb7f79 --- /dev/null +++ b/src/xenia/apu/nop/nop_audio_driver.h @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * 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_APU_NOP_NOP_AUDIO_DRIVER_H_ +#define XENIA_APU_NOP_NOP_AUDIO_DRIVER_H_ + +#include + +#include +#include + + +namespace xe { +namespace apu { +namespace nop { + + +class NopAudioDriver : public AudioDriver { +public: + NopAudioDriver(xe_memory_ref memory); + virtual ~NopAudioDriver(); + + virtual void Initialize(); + +protected: +}; + + +} // namespace nop +} // namespace apu +} // namespace xe + + +#endif // XENIA_APU_NOP_NOP_AUDIO_DRIVER_H_ diff --git a/src/xenia/apu/nop/nop_audio_system.cc b/src/xenia/apu/nop/nop_audio_system.cc new file mode 100644 index 000000000..f6fc92edd --- /dev/null +++ b/src/xenia/apu/nop/nop_audio_system.cc @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * 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 + +#include +#include + + +using namespace xe; +using namespace xe::apu; +using namespace xe::apu::nop; + + +NopAudioSystem::NopAudioSystem(Emulator* emulator) : + AudioSystem(emulator) { +} + +NopAudioSystem::~NopAudioSystem() { +} + +void NopAudioSystem::Initialize() { + AudioSystem::Initialize(); + + XEASSERTNULL(driver_); + driver_ = new NopAudioDriver(memory_); +} + +void NopAudioSystem::Pump() { +} + +void NopAudioSystem::Shutdown() { + AudioSystem::Shutdown(); +} diff --git a/src/xenia/apu/nop/nop_audio_system.h b/src/xenia/apu/nop/nop_audio_system.h new file mode 100644 index 000000000..db5fe329a --- /dev/null +++ b/src/xenia/apu/nop/nop_audio_system.h @@ -0,0 +1,43 @@ +/** + ****************************************************************************** + * 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_APU_NOP_NOP_AUDIO_SYSTEM_H_ +#define XENIA_APU_NOP_NOP_AUDIO_SYSTEM_H_ + +#include + +#include +#include + + +namespace xe { +namespace apu { +namespace nop { + + +class NopAudioSystem : public AudioSystem { +public: + NopAudioSystem(Emulator* emulator); + virtual ~NopAudioSystem(); + +protected: + virtual void Initialize(); + virtual void Pump(); + virtual void Shutdown(); + +private: +}; + + +} // namespace nop +} // namespace apu +} // namespace xe + + +#endif // XENIA_APU_NOP_NOP_AUDIO_SYSTEM_H_ diff --git a/src/xenia/apu/nop/sources.gypi b/src/xenia/apu/nop/sources.gypi new file mode 100644 index 000000000..902e9530d --- /dev/null +++ b/src/xenia/apu/nop/sources.gypi @@ -0,0 +1,12 @@ +# Copyright 2013 Ben Vanik. All Rights Reserved. +{ + 'sources': [ + 'nop_apu-private.h', + 'nop_apu.cc', + 'nop_apu.h', + 'nop_audio_driver.cc', + 'nop_audio_driver.h', + 'nop_audio_system.cc', + 'nop_audio_system.h', + ], +} diff --git a/src/xenia/apu/sources.gypi b/src/xenia/apu/sources.gypi new file mode 100644 index 000000000..3e6b4c244 --- /dev/null +++ b/src/xenia/apu/sources.gypi @@ -0,0 +1,23 @@ +# Copyright 2013 Ben Vanik. All Rights Reserved. +{ + 'sources': [ + 'apu-private.h', + 'apu.cc', + 'apu.h', + 'audio_driver.cc', + 'audio_driver.h', + 'audio_system.cc', + 'audio_system.h', + ], + + 'includes': [ + 'nop/sources.gypi', + ], + + 'conditions': [ + ['OS == "win"', { + 'includes': [ + ], + }], + ], +} diff --git a/src/xenia/config.h b/src/xenia/config.h index 413275232..2d11d03f9 100644 --- a/src/xenia/config.h +++ b/src/xenia/config.h @@ -24,6 +24,7 @@ #define XE_OPTION_LOG_DEBUG 1 #define XE_OPTION_LOG_CPU 1 #define XE_OPTION_LOG_SDB 0 +#define XE_OPTION_LOG_APU 1 #define XE_OPTION_LOG_GPU 1 #define XE_OPTION_LOG_KERNEL 1 #define XE_OPTION_LOG_FS 1 diff --git a/src/xenia/core.h b/src/xenia/core.h index 5bd0640a6..a4202cfd7 100644 --- a/src/xenia/core.h +++ b/src/xenia/core.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/xenia/core/sources.gypi b/src/xenia/core/sources.gypi index 062ac31cf..b7248305b 100644 --- a/src/xenia/core/sources.gypi +++ b/src/xenia/core/sources.gypi @@ -7,8 +7,6 @@ 'file.h', 'hash.cc', 'hash.h', - 'memory.cc', - 'memory.h', 'mmap.h', 'mutex.h', 'pal.h', diff --git a/src/xenia/cpu/backend.h b/src/xenia/cpu/backend.h index 6182cf4de..0761c9850 100644 --- a/src/xenia/cpu/backend.h +++ b/src/xenia/cpu/backend.h @@ -12,7 +12,7 @@ #include -#include +#include namespace xe { diff --git a/src/xenia/cpu/exec_module.cc b/src/xenia/cpu/exec_module.cc index 4adee8886..0451f1343 100644 --- a/src/xenia/cpu/exec_module.cc +++ b/src/xenia/cpu/exec_module.cc @@ -16,11 +16,10 @@ using namespace xe; using namespace xe::cpu; using namespace xe::cpu::sdb; -using namespace xe::kernel; ExecModule::ExecModule( - xe_memory_ref memory, shared_ptr export_resolver, + xe_memory_ref memory, ExportResolver* export_resolver, SymbolTable* sym_table, const char* module_name, const char* module_path) { memory_ = xe_memory_retain(memory); @@ -42,7 +41,7 @@ SymbolDatabase* ExecModule::sdb() { int ExecModule::PrepareRawBinary(uint32_t start_address, uint32_t end_address) { sdb_ = shared_ptr( - new sdb::RawSymbolDatabase(memory_, export_resolver_.get(), + new sdb::RawSymbolDatabase(memory_, export_resolver_, sym_table_, start_address, end_address)); code_addr_low_ = start_address; @@ -53,7 +52,7 @@ int ExecModule::PrepareRawBinary(uint32_t start_address, uint32_t end_address) { int ExecModule::PrepareXexModule(xe_xex2_ref xex) { sdb_ = shared_ptr( - new sdb::XexSymbolDatabase(memory_, export_resolver_.get(), + new sdb::XexSymbolDatabase(memory_, export_resolver_, sym_table_, xex)); code_addr_low_ = UINT_MAX; diff --git a/src/xenia/cpu/exec_module.h b/src/xenia/cpu/exec_module.h index 18f01a122..1a5924bc7 100644 --- a/src/xenia/cpu/exec_module.h +++ b/src/xenia/cpu/exec_module.h @@ -13,8 +13,8 @@ #include #include +#include #include -#include #include @@ -25,7 +25,7 @@ namespace cpu { class ExecModule { public: ExecModule( - xe_memory_ref memory, shared_ptr export_resolver, + xe_memory_ref memory, ExportResolver* export_resolver, sdb::SymbolTable* sym_table, const char* module_name, const char* module_path); ~ExecModule(); @@ -43,11 +43,11 @@ private: int Prepare(); int Init(); - xe_memory_ref memory_; - shared_ptr export_resolver_; - sdb::SymbolTable* sym_table_; - char* module_name_; - char* module_path_; + xe_memory_ref memory_; + ExportResolver* export_resolver_; + sdb::SymbolTable* sym_table_; + char* module_name_; + char* module_path_; shared_ptr sdb_; uint32_t code_addr_low_; diff --git a/src/xenia/cpu/global_exports.cc b/src/xenia/cpu/global_exports.cc index eb9d83c5c..3114bbc02 100644 --- a/src/xenia/cpu/global_exports.cc +++ b/src/xenia/cpu/global_exports.cc @@ -15,13 +15,12 @@ #include #include #include -#include +#include using namespace xe; using namespace xe::cpu; using namespace xe::cpu::sdb; -using namespace xe::kernel; namespace { diff --git a/src/xenia/cpu/global_exports.h b/src/xenia/cpu/global_exports.h index 8349ad688..9364f0e9e 100644 --- a/src/xenia/cpu/global_exports.h +++ b/src/xenia/cpu/global_exports.h @@ -13,9 +13,9 @@ #include #include +#include #include #include -#include namespace xe { @@ -33,7 +33,7 @@ typedef struct { xe_ppc_state_t* state, uint64_t cia, uint64_t ea); void (_cdecl *XeTraceKernelCall)( xe_ppc_state_t* state, uint64_t cia, uint64_t call_ia, - kernel::KernelExport* kernel_export); + KernelExport* kernel_export); void (_cdecl *XeTraceUserCall)( xe_ppc_state_t* state, uint64_t cia, uint64_t call_ia, sdb::FunctionSymbol* fn); diff --git a/src/xenia/cpu/jit.h b/src/xenia/cpu/jit.h index 7f64532ae..61ae48a8b 100644 --- a/src/xenia/cpu/jit.h +++ b/src/xenia/cpu/jit.h @@ -30,8 +30,8 @@ public: } virtual int Setup() = 0; - virtual void SetupGpuPointers(void* gpu_this, - void* gpu_read, void* gpu_write) = 0; + virtual void AddRegisterAccessCallbacks( + ppc::RegisterAccessCallbacks callbacks) = 0; virtual int InitModule(ExecModule* module) = 0; virtual int UninitModule(ExecModule* module) = 0; diff --git a/src/xenia/cpu/ppc.h b/src/xenia/cpu/ppc.h index 618bccddc..b8ae0d21a 100644 --- a/src/xenia/cpu/ppc.h +++ b/src/xenia/cpu/ppc.h @@ -13,6 +13,7 @@ #include #include +#include #include #endif // XENIA_CPU_PPC_H_ diff --git a/src/xenia/cpu/ppc/registers.h b/src/xenia/cpu/ppc/registers.h new file mode 100644 index 000000000..6b74d9787 --- /dev/null +++ b/src/xenia/cpu/ppc/registers.h @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * 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_PPC_REGISTERS_H_ +#define XENIA_CPU_PPC_REGISTERS_H_ + +#include + + +namespace xe { +namespace cpu { +namespace ppc { + + +typedef bool (*RegisterHandlesCallback)(void* context, uint32_t addr); +typedef uint64_t (*RegisterReadCallback)(void* context, uint32_t addr); +typedef void (*RegisterWriteCallback)(void* context, uint32_t addr, + uint64_t value); + + +typedef struct { + void* context; + RegisterHandlesCallback handles; + RegisterReadCallback read; + RegisterWriteCallback write; +} RegisterAccessCallbacks; + + +} // namespace ppc +} // namespace cpu +} // namespace xe + + +#endif // XENIA_CPU_PPC_REGISTERS_H_ diff --git a/src/xenia/cpu/ppc/sources.gypi b/src/xenia/cpu/ppc/sources.gypi index 1a346ec32..ac23d0a45 100644 --- a/src/xenia/cpu/ppc/sources.gypi +++ b/src/xenia/cpu/ppc/sources.gypi @@ -10,6 +10,7 @@ 'instr.cc', 'instr.h', 'instr_tables.h', + 'registers.h', 'state.cc', 'state.h', ], diff --git a/src/xenia/cpu/ppc/state.h b/src/xenia/cpu/ppc/state.h index f6a0619b2..ba8619282 100644 --- a/src/xenia/cpu/ppc/state.h +++ b/src/xenia/cpu/ppc/state.h @@ -13,12 +13,8 @@ #include -namespace xe { -namespace cpu { -class Processor; -class ThreadState; -} // namespace cpu -} // namespace xe +XEDECLARECLASS2(xe, cpu, Processor); +XEDECLARECLASS2(xe, cpu, ThreadState); // namespace FPRF { diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index 92c07b181..def594602 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -9,16 +9,15 @@ #include +#include #include #include #include -#include using namespace xe; using namespace xe::cpu; using namespace xe::cpu::sdb; -using namespace xe::kernel; namespace { @@ -46,11 +45,14 @@ namespace { } -Processor::Processor(xe_memory_ref memory, shared_ptr backend) : +Processor::Processor(Emulator* emulator, Backend* backend) : sym_table_(NULL), jit_(NULL), interrupt_thread_lock_(NULL), interrupt_thread_state_(NULL) { - memory_ = xe_memory_retain(memory); + emulator_ = emulator; backend_ = backend; + memory_ = xe_memory_retain(emulator->memory()); + export_resolver_ = emulator->export_resolver(); + sym_lock_ = xe_mutex_alloc(10000); InitializeIfNeeded(); @@ -76,34 +78,9 @@ Processor::~Processor() { delete sym_table_; xe_mutex_free(sym_lock_); - graphics_system_.reset(); - export_resolver_.reset(); - backend_.reset(); xe_memory_release(memory_); } -xe_memory_ref Processor::memory() { - return xe_memory_retain(memory_); -} - -shared_ptr Processor::graphics_system() { - return graphics_system_; -} - -void Processor::set_graphics_system( - shared_ptr graphics_system) { - graphics_system_ = graphics_system; -} - -shared_ptr Processor::export_resolver() { - return export_resolver_; -} - -void Processor::set_export_resolver( - shared_ptr export_resolver) { - export_resolver_ = export_resolver; -} - int Processor::Setup() { XEASSERTNULL(jit_); @@ -121,15 +98,15 @@ int Processor::Setup() { return 1; } - XEASSERTNOTNULL(graphics_system_.get()); - jit_->SetupGpuPointers( - graphics_system_.get(), - (void*)&xe::gpu::GraphicsSystem::ReadRegisterThunk, - (void*)&xe::gpu::GraphicsSystem::WriteRegisterThunk); - return 0; } +void Processor::AddRegisterAccessCallbacks( + ppc::RegisterAccessCallbacks callbacks) { + XEASSERTNOTNULL(jit_); + jit_->AddRegisterAccessCallbacks(callbacks); +} + int Processor::LoadRawBinary(const xechar_t* path, uint32_t start_address) { ExecModule* exec_module = NULL; const xechar_t* name = xestrrchr(path, XE_PATH_SEPARATOR) + 1; diff --git a/src/xenia/cpu/processor.h b/src/xenia/cpu/processor.h index fda16a509..925fb1b25 100644 --- a/src/xenia/cpu/processor.h +++ b/src/xenia/cpu/processor.h @@ -18,15 +18,10 @@ #include #include #include -#include -#include -namespace xe { -namespace gpu { -class GraphicsSystem; -} // namespace gpu -} // namespace xe +XEDECLARECLASS1(xe, Emulator); +XEDECLARECLASS1(xe, ExportResolver); namespace xe { @@ -37,17 +32,16 @@ class JIT; class Processor { public: - Processor(xe_memory_ref memory, shared_ptr backend); + Processor(Emulator* emulator, Backend* backend); ~Processor(); - xe_memory_ref memory(); - shared_ptr graphics_system(); - void set_graphics_system(shared_ptr graphics_system); - shared_ptr export_resolver(); - void set_export_resolver(shared_ptr export_resolver); + xe_memory_ref memory() const { return memory_; } + ExportResolver* export_resolver() const { return export_resolver_; } int Setup(); + void AddRegisterAccessCallbacks(ppc::RegisterAccessCallbacks callbacks); + int LoadRawBinary(const xechar_t* path, uint32_t start_address); int LoadXexModule(const char* name, const char* path, xe_xex2_ref xex); @@ -69,19 +63,19 @@ public: void* GetFunctionPointer(uint32_t address); private: - xe_memory_ref memory_; - shared_ptr backend_; - shared_ptr graphics_system_; - shared_ptr export_resolver_; + Emulator* emulator_; + Backend* backend_; + xe_memory_ref memory_; + ExportResolver* export_resolver_; - sdb::SymbolTable* sym_table_; - JIT* jit_; + sdb::SymbolTable* sym_table_; + JIT* jit_; std::vector modules_; - xe_mutex_t* sym_lock_; + xe_mutex_t* sym_lock_; - xe_mutex_t* interrupt_thread_lock_; - ThreadState* interrupt_thread_state_; - uint32_t interrupt_thread_block_; + xe_mutex_t* interrupt_thread_lock_; + ThreadState* interrupt_thread_state_; + uint32_t interrupt_thread_block_; }; diff --git a/src/xenia/cpu/sdb/raw_symbol_database.cc b/src/xenia/cpu/sdb/raw_symbol_database.cc index 9b4b1356d..9d0c4796a 100644 --- a/src/xenia/cpu/sdb/raw_symbol_database.cc +++ b/src/xenia/cpu/sdb/raw_symbol_database.cc @@ -17,7 +17,6 @@ using namespace xe; using namespace xe::cpu; using namespace xe::cpu::ppc; using namespace xe::cpu::sdb; -using namespace xe::kernel; RawSymbolDatabase::RawSymbolDatabase( diff --git a/src/xenia/cpu/sdb/raw_symbol_database.h b/src/xenia/cpu/sdb/raw_symbol_database.h index c6329aea6..560b8258f 100644 --- a/src/xenia/cpu/sdb/raw_symbol_database.h +++ b/src/xenia/cpu/sdb/raw_symbol_database.h @@ -21,7 +21,7 @@ namespace sdb { class RawSymbolDatabase : public SymbolDatabase { public: RawSymbolDatabase(xe_memory_ref memory, - kernel::ExportResolver* export_resolver, + ExportResolver* export_resolver, SymbolTable* sym_table, uint32_t start_address, uint32_t end_address); virtual ~RawSymbolDatabase(); diff --git a/src/xenia/cpu/sdb/symbol.cc b/src/xenia/cpu/sdb/symbol.cc index 9a3db0a12..8c200a0c7 100644 --- a/src/xenia/cpu/sdb/symbol.cc +++ b/src/xenia/cpu/sdb/symbol.cc @@ -17,7 +17,6 @@ using namespace xe; using namespace xe::cpu; using namespace xe::cpu::ppc; using namespace xe::cpu::sdb; -using namespace xe::kernel; Symbol::Symbol(SymbolType type) : diff --git a/src/xenia/cpu/sdb/symbol.h b/src/xenia/cpu/sdb/symbol.h index e699186b7..334966d86 100644 --- a/src/xenia/cpu/sdb/symbol.h +++ b/src/xenia/cpu/sdb/symbol.h @@ -15,7 +15,7 @@ #include #include -#include +#include namespace xe { @@ -125,7 +125,7 @@ public: FunctionType type; uint32_t flags; - kernel::KernelExport* kernel_export; + KernelExport* kernel_export; ExceptionEntrySymbol* ee; // Implementation-specific value. This could be a JIT'ed function ref @@ -147,9 +147,9 @@ public: VariableSymbol(); virtual ~VariableSymbol(); - uint32_t address; + uint32_t address; - kernel::KernelExport* kernel_export; + KernelExport* kernel_export; }; class ExceptionEntrySymbol : public Symbol { diff --git a/src/xenia/cpu/sdb/symbol_database.cc b/src/xenia/cpu/sdb/symbol_database.cc index e0ac8cda3..023214e83 100644 --- a/src/xenia/cpu/sdb/symbol_database.cc +++ b/src/xenia/cpu/sdb/symbol_database.cc @@ -20,12 +20,12 @@ using namespace xe; using namespace xe::cpu; using namespace xe::cpu::ppc; using namespace xe::cpu::sdb; -using namespace xe::kernel; SymbolDatabase::SymbolDatabase(xe_memory_ref memory, ExportResolver* export_resolver, - SymbolTable* sym_table) { + SymbolTable* sym_table) : + function_count_(0), variable_count_(0) { memory_ = xe_memory_retain(memory); export_resolver_ = export_resolver; sym_table_ = sym_table; diff --git a/src/xenia/cpu/sdb/symbol_database.h b/src/xenia/cpu/sdb/symbol_database.h index ec7233da9..f5f5ab4fd 100644 --- a/src/xenia/cpu/sdb/symbol_database.h +++ b/src/xenia/cpu/sdb/symbol_database.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -28,7 +28,7 @@ namespace sdb { class SymbolDatabase { public: - SymbolDatabase(xe_memory_ref memory, kernel::ExportResolver* export_resolver, + SymbolDatabase(xe_memory_ref memory, ExportResolver* export_resolver, SymbolTable* sym_table); virtual ~SymbolDatabase(); @@ -64,7 +64,7 @@ protected: virtual bool IsValueInTextRange(uint32_t value) = 0; xe_memory_ref memory_; - kernel::ExportResolver* export_resolver_; + ExportResolver* export_resolver_; SymbolTable* sym_table_; size_t function_count_; size_t variable_count_; diff --git a/src/xenia/cpu/sdb/xex_symbol_database.cc b/src/xenia/cpu/sdb/xex_symbol_database.cc index dd9835754..28fec1910 100644 --- a/src/xenia/cpu/sdb/xex_symbol_database.cc +++ b/src/xenia/cpu/sdb/xex_symbol_database.cc @@ -17,7 +17,6 @@ using namespace xe; using namespace xe::cpu; using namespace xe::cpu::ppc; using namespace xe::cpu::sdb; -using namespace xe::kernel; namespace { diff --git a/src/xenia/cpu/sdb/xex_symbol_database.h b/src/xenia/cpu/sdb/xex_symbol_database.h index 4c1795100..d98af1cbc 100644 --- a/src/xenia/cpu/sdb/xex_symbol_database.h +++ b/src/xenia/cpu/sdb/xex_symbol_database.h @@ -23,7 +23,7 @@ namespace sdb { class XexSymbolDatabase : public SymbolDatabase { public: XexSymbolDatabase(xe_memory_ref memory, - kernel::ExportResolver* export_resolver, + ExportResolver* export_resolver, SymbolTable* sym_table, xe_xex2_ref xex); virtual ~XexSymbolDatabase(); diff --git a/src/xenia/cpu/thread_state.cc b/src/xenia/cpu/thread_state.cc index 923c49da1..d861ab381 100644 --- a/src/xenia/cpu/thread_state.cc +++ b/src/xenia/cpu/thread_state.cc @@ -9,7 +9,7 @@ #include -#include +#include #include diff --git a/src/xenia/cpu/x64/x64_emit_memory.cc b/src/xenia/cpu/x64/x64_emit_memory.cc index 985757c9f..6ad096ccb 100644 --- a/src/xenia/cpu/x64/x64_emit_memory.cc +++ b/src/xenia/cpu/x64/x64_emit_memory.cc @@ -454,8 +454,8 @@ XEEMITTER(lwz, 0x80000000, D )(X64Emitter& e, X86Compiler& c, InstrDat uint64_t constant_ea; if (i.D.RA && e.get_constant_gpr_value(i.D.RA, &constant_ea)) { constant_ea += XEEXTS16(i.D.DS); - if ((constant_ea & 0xFFFF0000) == 0x7FC80000) { - GpVar reg(e.read_gpu_register((uint32_t)constant_ea)); + GpVar reg; + if (e.check_constant_gpr_read((uint32_t)constant_ea, ®)) { e.update_gpr_value(i.D.RT, reg); e.clear_constant_gpr_value(i.D.RT); return 0; @@ -824,8 +824,7 @@ XEEMITTER(stw, 0x90000000, D )(X64Emitter& e, X86Compiler& c, InstrDat uint64_t constant_ea; if (i.D.RA && e.get_constant_gpr_value(i.D.RA, &constant_ea)) { constant_ea += XEEXTS16(i.D.DS); - if ((constant_ea & 0xFFFF0000) == 0x7FC80000) { - e.write_gpu_register((uint32_t)constant_ea, e.gpr_value(i.D.RT)); + if (e.check_constant_gpr_write((uint32_t)constant_ea, e.gpr_value(i.D.RT))) { return 0; } } diff --git a/src/xenia/cpu/x64/x64_emitter.cc b/src/xenia/cpu/x64/x64_emitter.cc index 54d0f6510..3c651a42d 100644 --- a/src/xenia/cpu/x64/x64_emitter.cc +++ b/src/xenia/cpu/x64/x64_emitter.cc @@ -94,11 +94,9 @@ X64Emitter::~X64Emitter() { lock_ = NULL; } -void X64Emitter::SetupGpuPointers(void* gpu_this, - void* gpu_read, void* gpu_write) { - gpu_this_ = gpu_this; - gpu_read_ = gpu_read; - gpu_write_ = gpu_write; +void X64Emitter::AddRegisterAccessCallbacks( + RegisterAccessCallbacks callbacks) { + access_callbacks_.push_back(callbacks); } void X64Emitter::Lock() { @@ -1155,44 +1153,6 @@ int X64Emitter::GenerateIndirectionBranch(uint32_t cia, GpVar& target, return 0; } -GpVar X64Emitter::read_gpu_register(uint32_t r) { - X86Compiler& c = compiler_; - - GpVar this_imm(c.newGpVar()); - c.mov(this_imm, imm((uint64_t)gpu_this_)); - GpVar reg_imm(c.newGpVar()); - c.mov(reg_imm, imm(r & 0xFFFF)); - - X86CompilerFuncCall* call = c.call(gpu_read_); - call->setPrototype(kX86FuncConvDefault, - FuncBuilder2()); - call->setArgument(0, this_imm); - call->setArgument(1, reg_imm); - GpVar res(c.newGpVar()); - call->setReturn(res); - - return res; -} - -void X64Emitter::write_gpu_register(uint32_t r, GpVar& v) { - X86Compiler& c = compiler_; - - GpVar this_imm(c.newGpVar()); - c.alloc(this_imm, rcx); - c.mov(this_imm, imm((uint64_t)gpu_this_)); - GpVar reg_imm(c.newGpVar()); - c.alloc(reg_imm, rdx); - c.mov(reg_imm, imm(r & 0xFFFF)); - c.alloc(v, r8); - - X86CompilerFuncCall* call = c.call(gpu_write_); - call->setPrototype(kX86FuncConvDefault, - FuncBuilder3()); - call->setArgument(0, this_imm); - call->setArgument(1, reg_imm); - call->setArgument(2, v); -} - void X64Emitter::SetupLocals() { X86Compiler& c = compiler_; @@ -1505,6 +1465,69 @@ void X64Emitter::clear_all_constant_gpr_values() { } } +bool X64Emitter::check_constant_gpr_read(uint32_t addr, GpVar* reg) { + X86Compiler& c = compiler_; + + for (std::vector::const_iterator it = + access_callbacks_.begin(); it != access_callbacks_.end(); ++it) { + if (!it->handles(it->context, addr)) { + continue; + } + + GpVar this_imm(c.newGpVar()); + c.mov(this_imm, imm((uint64_t)it->context)); + GpVar reg_imm(c.newGpVar()); + c.mov(reg_imm, imm(addr)); + + X86CompilerFuncCall* call = c.call(it->read); + call->setPrototype( + kX86FuncConvDefault, + FuncBuilder2()); + call->setArgument(0, this_imm); + call->setArgument(1, reg_imm); + GpVar res(c.newGpVar()); + call->setReturn(res); + *reg = res; + + // Don't let the caller handle the write. + return true; + } + + return false; +} + +bool X64Emitter::check_constant_gpr_write(uint32_t addr, GpVar& reg) { + X86Compiler& c = compiler_; + + for (std::vector::const_iterator it = + access_callbacks_.begin(); it != access_callbacks_.end(); ++it) { + if (!it->handles(it->context, addr)) { + continue; + } + + GpVar this_imm(c.newGpVar()); + c.alloc(this_imm, rcx); + c.mov(this_imm, imm((uint64_t)it->context)); + GpVar reg_imm(c.newGpVar()); + c.alloc(reg_imm, rdx); + c.mov(reg_imm, imm(addr)); + c.alloc(reg, r8); + + X86CompilerFuncCall* call = c.call(it->write); + call->setPrototype( + kX86FuncConvDefault, + FuncBuilder3()); + call->setArgument(0, this_imm); + call->setArgument(1, reg_imm); + call->setArgument(2, reg); + + // Don't let the caller handle the write. + return true; + } + + return false; +} + GpVar X64Emitter::xer_value() { X86Compiler& c = compiler_; if (FLAGS_cache_registers) { diff --git a/src/xenia/cpu/x64/x64_emitter.h b/src/xenia/cpu/x64/x64_emitter.h index a2f7cf662..072142c9a 100644 --- a/src/xenia/cpu/x64/x64_emitter.h +++ b/src/xenia/cpu/x64/x64_emitter.h @@ -11,8 +11,8 @@ #define XENIA_CPU_X64_X64_EMITTER_H_ #include +#include #include -#include #include @@ -31,7 +31,7 @@ public: X64Emitter(xe_memory_ref memory); ~X64Emitter(); - void SetupGpuPointers(void* gpu_this, void* gpu_read, void* gpu_write); + void AddRegisterAccessCallbacks(ppc::RegisterAccessCallbacks callbacks); void Lock(); void Unlock(); @@ -75,6 +75,9 @@ public: void clear_constant_gpr_value(uint32_t n); void clear_all_constant_gpr_values(); + bool check_constant_gpr_read(uint32_t addr, AsmJit::GpVar* reg); + bool check_constant_gpr_write(uint32_t addr, AsmJit::GpVar& reg); + AsmJit::GpVar xer_value(); void update_xer_value(AsmJit::GpVar& value); void update_xer_with_overflow(AsmJit::GpVar& value); @@ -139,9 +142,7 @@ private: xe_mutex_t* lock_; uint32_t cpu_feature_mask_; - void* gpu_this_; - void* gpu_read_; - void* gpu_write_; + std::vector access_callbacks_; static uint64_t reserved_addr_; diff --git a/src/xenia/cpu/x64/x64_jit.cc b/src/xenia/cpu/x64/x64_jit.cc index 6a53d7a02..c91288718 100644 --- a/src/xenia/cpu/x64/x64_jit.cc +++ b/src/xenia/cpu/x64/x64_jit.cc @@ -18,6 +18,7 @@ using namespace xe; using namespace xe::cpu; +using namespace xe::cpu::ppc; using namespace xe::cpu::sdb; using namespace xe::cpu::x64; @@ -53,9 +54,8 @@ XECLEANUP: return result_code; } -void X64JIT::SetupGpuPointers(void* gpu_this, - void* gpu_read, void* gpu_write) { - emitter_->SetupGpuPointers(gpu_this, gpu_read, gpu_write); +void X64JIT::AddRegisterAccessCallbacks(RegisterAccessCallbacks callbacks) { + emitter_->AddRegisterAccessCallbacks(callbacks); } namespace { diff --git a/src/xenia/cpu/x64/x64_jit.h b/src/xenia/cpu/x64/x64_jit.h index 739f36e20..b1ba20bba 100644 --- a/src/xenia/cpu/x64/x64_jit.h +++ b/src/xenia/cpu/x64/x64_jit.h @@ -29,8 +29,8 @@ public: virtual ~X64JIT(); virtual int Setup(); - virtual void SetupGpuPointers(void* gpu_this, - void* gpu_read, void* gpu_write); + virtual void AddRegisterAccessCallbacks( + ppc::RegisterAccessCallbacks callbacks); virtual int InitModule(ExecModule* module); virtual int UninitModule(ExecModule* module); diff --git a/src/xenia/dbg/debugger.cc b/src/xenia/dbg/debugger.cc index 07ce09f8a..164c25f74 100644 --- a/src/xenia/dbg/debugger.cc +++ b/src/xenia/dbg/debugger.cc @@ -11,6 +11,7 @@ #include +#include #include #include @@ -25,7 +26,8 @@ DEFINE_int32(remote_debug_port, 6200, "Websocket port to listen for debugger connections on."); -Debugger::Debugger() { +Debugger::Debugger(Emulator* emulator) : + emulator_(emulator) { //listener_ = auto_ptr(new WsListener(this, FLAGS_remote_debug_port)); } diff --git a/src/xenia/dbg/debugger.h b/src/xenia/dbg/debugger.h index 3d331b128..aad92c9dc 100644 --- a/src/xenia/dbg/debugger.h +++ b/src/xenia/dbg/debugger.h @@ -17,6 +17,9 @@ #include +XEDECLARECLASS1(xe, Emulator); + + namespace xe { namespace dbg { @@ -28,7 +31,7 @@ class Listener; class Debugger { public: - Debugger(); + Debugger(Emulator* emulator); virtual ~Debugger(); void RegisterContentSource(ContentSource* content_source); @@ -45,6 +48,7 @@ private: friend class Client; private: + Emulator* emulator_; auto_ptr listener_; std::vector clients_; std::map content_sources_; diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc new file mode 100644 index 000000000..54686d4cf --- /dev/null +++ b/src/xenia/emulator.cc @@ -0,0 +1,196 @@ +/** + ****************************************************************************** + * 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 + +#include +#include +#include +#include +#include +#include +#include + + +using namespace xe; +using namespace xe::apu; +using namespace xe::cpu; +using namespace xe::dbg; +using namespace xe::gpu; +using namespace xe::kernel; +using namespace xe::kernel::xam; +using namespace xe::kernel::xboxkrnl; +using namespace xe::kernel::xboxkrnl::fs; + + +Emulator::Emulator(const xechar_t* command_line) : + memory_(0), + debugger_(0), + cpu_backend_(0), processor_(0), audio_system_(0), graphics_system_(0), + export_resolver_(0), file_system_(0), + xboxkrnl_(0), xam_(0) { + XEIGNORE(xestrcpy(command_line_, XECOUNT(command_line_), command_line)); +} + +Emulator::~Emulator() { + // Note that we delete things in the reverse order they were initialized. + + delete xam_; + delete xboxkrnl_; + + delete file_system_; + + delete graphics_system_; + delete audio_system_; + delete processor_; + delete cpu_backend_; + + delete debugger_; + + delete export_resolver_; + + xe_memory_release(memory_); +} + +X_STATUS Emulator::Setup() { + X_STATUS result = X_STATUS_UNSUCCESSFUL; + + // Create memory system first, as it is required for other systems. + xe_memory_options_t memory_options; + xe_zero_struct(&memory_options, sizeof(memory_options)); + memory_ = xe_memory_create(memory_options); + XEEXPECTNOTNULL(memory_); + + // Shared export resolver used to attach and query for HLE exports. + export_resolver_ = new ExportResolver(); + XEEXPECTNOTNULL(export_resolver_); + + // Create the debugger. + debugger_ = new Debugger(this); + XEEXPECTNOTNULL(debugger_); + + // Initialize the CPU. + cpu_backend_ = new xe::cpu::x64::X64Backend(); + XEEXPECTNOTNULL(cpu_backend_); + processor_ = new Processor(this, cpu_backend_); + XEEXPECTNOTNULL(processor_); + + // Initialize the APU. + audio_system_ = xe::apu::Create(this); + XEEXPECTNOTNULL(audio_system_); + + // Initialize the GPU. + graphics_system_ = xe::gpu::Create(this); + XEEXPECTNOTNULL(graphics_system_); + + // Setup the core components. + result = processor_->Setup(); + XEEXPECTZERO(result); + result = audio_system_->Setup(); + XEEXPECTZERO(result); + result = graphics_system_->Setup(); + XEEXPECTZERO(result); + + // Bring up the virtual filesystem used by the kernel. + file_system_ = new FileSystem(); + XEEXPECTNOTNULL(file_system_); + + // HLE kernel modules. + xboxkrnl_ = new XboxkrnlModule(this); + XEEXPECTNOTNULL(xboxkrnl_); + xam_ = new XamModule(this); + XEEXPECTNOTNULL(xam_); + + // Prepare the debugger. + // This may pause waiting for connections. + result = debugger_->Startup(); + XEEXPECTZERO(result); + + return result; + +XECLEANUP: + return result; +} + +X_STATUS Emulator::LaunchXexFile(const xechar_t* path) { + // We create a virtual filesystem pointing to its directory and symlink + // that to the game filesystem. + // e.g., /my/files/foo.xex will get a local fs at: + // \\Device\\Harddisk0\\Partition1 + // and then get that symlinked to game:\, so + // -> game:\foo.xex + + int result_code = 0; + + // Get just the filename (foo.xex). + const xechar_t* file_name = xestrrchr(path, XE_PATH_SEPARATOR); + if (file_name) { + // Skip slash. + file_name++; + } else { + // No slash found, whole thing is a file. + file_name = path; + } + + // Get the parent path of the file. + xechar_t parent_path[XE_MAX_PATH]; + XEIGNORE(xestrcpy(parent_path, XECOUNT(parent_path), path)); + parent_path[file_name - path] = 0; + + // Register the local directory in the virtual filesystem. + result_code = file_system_->RegisterHostPathDevice( + "\\Device\\Harddisk1\\Partition0", parent_path); + if (result_code) { + XELOGE("Unable to mount local directory"); + return result_code; + } + + // Create symlinks to the device. + file_system_->CreateSymbolicLink( + "game:", "\\Device\\Harddisk1\\Partition0"); + file_system_->CreateSymbolicLink( + "d:", "\\Device\\Harddisk1\\Partition0"); + + // Get the file name of the module to load from the filesystem. + char fs_path[XE_MAX_PATH]; + XEIGNORE(xestrcpya(fs_path, XECOUNT(fs_path), "game:\\")); + char* fs_path_ptr = fs_path + xestrlena(fs_path); + *fs_path_ptr = 0; +#if XE_WCHAR + XEIGNORE(xestrnarrow(fs_path_ptr, XECOUNT(fs_path), file_name)); +#else + XEIGNORE(xestrcpya(fs_path_ptr, XECOUNT(fs_path), file_name)); +#endif + + // Launch the game. + return xboxkrnl_->LaunchModule(fs_path); +} + +X_STATUS Emulator::LaunchDiscImage(const xechar_t* path) { + int result_code = 0; + + // Register the disc image in the virtual filesystem. + result_code = file_system_->RegisterDiscImageDevice( + "\\Device\\Cdrom0", path); + if (result_code) { + XELOGE("Unable to mount disc image"); + return result_code; + } + + // Create symlinks to the device. + file_system_->CreateSymbolicLink( + "game:", + "\\Device\\Cdrom0"); + file_system_->CreateSymbolicLink( + "d:", + "\\Device\\Cdrom0"); + + // Launch the game. + return xboxkrnl_->LaunchModule("game:\\default.xex"); +} diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h new file mode 100644 index 000000000..6573a82bb --- /dev/null +++ b/src/xenia/emulator.h @@ -0,0 +1,77 @@ +/** + ****************************************************************************** + * 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_EMULATOR_H_ +#define XENIA_EMULATOR_H_ + +#include +#include +#include + + +XEDECLARECLASS1(xe, ExportResolver); +XEDECLARECLASS2(xe, apu, AudioSystem); +XEDECLARECLASS2(xe, cpu, Backend); +XEDECLARECLASS2(xe, cpu, Processor); +XEDECLARECLASS2(xe, dbg, Debugger); +XEDECLARECLASS2(xe, gpu, GraphicsSystem); +XEDECLARECLASS3(xe, kernel, xam, XamModule); +XEDECLARECLASS3(xe, kernel, xboxkrnl, XboxkrnlModule); +XEDECLARECLASS4(xe, kernel, xboxkrnl, fs, FileSystem); + + +namespace xe { + + +class Emulator { +public: + Emulator(const xechar_t* command_line); + ~Emulator(); + + const xechar_t* command_line() const { return command_line_; } + xe_memory_ref memory() const { return memory_; } + + dbg::Debugger* debugger() const { return debugger_; } + + cpu::Processor* processor() const { return processor_; } + apu::AudioSystem* audio_system() const { return audio_system_; } + gpu::GraphicsSystem* graphics_system() const { return graphics_system_; } + + ExportResolver* export_resolver() const { return export_resolver_; } + kernel::xboxkrnl::fs::FileSystem* file_system() const { return file_system_; } + + X_STATUS Setup(); + + // TODO(benvanik): raw binary. + X_STATUS LaunchXexFile(const xechar_t* path); + X_STATUS LaunchDiscImage(const xechar_t* path); + +private: + xechar_t command_line_[XE_MAX_PATH]; + xe_memory_ref memory_; + + dbg::Debugger* debugger_; + + cpu::Backend* cpu_backend_; + cpu::Processor* processor_; + apu::AudioSystem* audio_system_; + gpu::GraphicsSystem* graphics_system_; + + ExportResolver* export_resolver_; + kernel::xboxkrnl::fs::FileSystem* file_system_; + + kernel::xboxkrnl::XboxkrnlModule* xboxkrnl_; + kernel::xam::XamModule* xam_; +}; + + +} // namespace xe + + +#endif // XENIA_EMULATOR_H_ diff --git a/src/xenia/kernel/export.cc b/src/xenia/export_resolver.cc similarity index 97% rename from src/xenia/kernel/export.cc rename to src/xenia/export_resolver.cc index e3245e0ad..f630a3c48 100644 --- a/src/xenia/kernel/export.cc +++ b/src/xenia/export_resolver.cc @@ -7,11 +7,10 @@ ****************************************************************************** */ -#include +#include using namespace xe; -using namespace xe::kernel; ExportResolver::ExportResolver() { diff --git a/src/xenia/kernel/export.h b/src/xenia/export_resolver.h similarity index 94% rename from src/xenia/kernel/export.h rename to src/xenia/export_resolver.h index ac73f61c5..fa0ca1bf0 100644 --- a/src/xenia/kernel/export.h +++ b/src/xenia/export_resolver.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_EXPORT_H_ -#define XENIA_KERNEL_EXPORT_H_ +#ifndef XENIA_EXPORT_RESOLVER_H_ +#define XENIA_EXPORT_RESOLVER_H_ #include @@ -19,7 +19,6 @@ typedef struct xe_ppc_state xe_ppc_state_t; namespace xe { -namespace kernel { typedef void (*xe_kernel_export_impl_fn)(); @@ -92,8 +91,7 @@ private: }; -} // namespace kernel } // namespace xe -#endif // XENIA_KERNEL_EXPORT_H_ +#endif // XENIA_EXPORT_RESOLVER_H_ diff --git a/src/xenia/gpu/d3d11/d3d11-private.h b/src/xenia/gpu/d3d11/d3d11_gpu-private.h similarity index 76% rename from src/xenia/gpu/d3d11/d3d11-private.h rename to src/xenia/gpu/d3d11/d3d11_gpu-private.h index 561b15f85..7032de896 100644 --- a/src/xenia/gpu/d3d11/d3d11-private.h +++ b/src/xenia/gpu/d3d11/d3d11_gpu-private.h @@ -1,31 +1,31 @@ -/** - ****************************************************************************** - * 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_GPU_D3D11_D3D11_PRIVATE_H_ -#define XENIA_GPU_D3D11_D3D11_PRIVATE_H_ - -#include - -#include - - -namespace xe { -namespace gpu { -namespace d3d11 { - - - - - -} // namespace d3d11 -} // namespace gpu -} // namespace xe - - -#endif // XENIA_GPU_D3D11_D3D11_PRIVATE_H_ +/** + ****************************************************************************** + * 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_GPU_D3D11_D3D11_GPU_PRIVATE_H_ +#define XENIA_GPU_D3D11_D3D11_GPU_PRIVATE_H_ + +#include + +#include + + +namespace xe { +namespace gpu { +namespace d3d11 { + + + + + +} // namespace d3d11 +} // namespace gpu +} // namespace xe + + +#endif // XENIA_GPU_D3D11_D3D11_GPU_PRIVATE_H_ diff --git a/src/xenia/gpu/d3d11/d3d11.cc b/src/xenia/gpu/d3d11/d3d11_gpu.cc similarity index 83% rename from src/xenia/gpu/d3d11/d3d11.cc rename to src/xenia/gpu/d3d11/d3d11_gpu.cc index d9b11a3d9..52dd9a7b6 100644 --- a/src/xenia/gpu/d3d11/d3d11.cc +++ b/src/xenia/gpu/d3d11/d3d11_gpu.cc @@ -1,44 +1,44 @@ -/** - ****************************************************************************** - * 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 - -#include - - -using namespace xe; -using namespace xe::gpu; -using namespace xe::gpu::d3d11; - - -namespace { - void InitializeIfNeeded(); - void CleanupOnShutdown(); - - void InitializeIfNeeded() { - static bool has_initialized = false; - if (has_initialized) { - return; - } - has_initialized = true; - - // - - atexit(CleanupOnShutdown); - } - - void CleanupOnShutdown() { - } -} - - -GraphicsSystem* xe::gpu::d3d11::Create(const CreationParams* params) { - InitializeIfNeeded(); - return new D3D11GraphicsSystem(params); -} +/** + ****************************************************************************** + * 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 + +#include + + +using namespace xe; +using namespace xe::gpu; +using namespace xe::gpu::d3d11; + + +namespace { + void InitializeIfNeeded(); + void CleanupOnShutdown(); + + void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; + } + has_initialized = true; + + // + + atexit(CleanupOnShutdown); + } + + void CleanupOnShutdown() { + } +} + + +GraphicsSystem* xe::gpu::d3d11::Create(Emulator* emulator) { + InitializeIfNeeded(); + return new D3D11GraphicsSystem(emulator); +} diff --git a/src/xenia/gpu/d3d11/d3d11.h b/src/xenia/gpu/d3d11/d3d11_gpu.h similarity index 73% rename from src/xenia/gpu/d3d11/d3d11.h rename to src/xenia/gpu/d3d11/d3d11_gpu.h index d215f60db..5003c7afd 100644 --- a/src/xenia/gpu/d3d11/d3d11.h +++ b/src/xenia/gpu/d3d11/d3d11_gpu.h @@ -1,33 +1,33 @@ -/** - ****************************************************************************** - * 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_GPU_D3D11_D3D11_H_ -#define XENIA_GPU_D3D11_D3D11_H_ - -#include - - -namespace xe { -namespace gpu { - -class CreationParams; -class GraphicsSystem; - -namespace d3d11 { - - -GraphicsSystem* Create(const CreationParams* params); - - -} // namespace d3d11 -} // namespace gpu -} // namespace xe - - -#endif // XENIA_GPU_D3D11_D3D11_H_ +/** + ****************************************************************************** + * 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_GPU_D3D11_D3D11_GPU_H_ +#define XENIA_GPU_D3D11_D3D11_GPU_H_ + +#include + + +XEDECLARECLASS1(xe, Emulator); +XEDECLARECLASS2(xe, gpu, GraphicsSystem); + + +namespace xe { +namespace gpu { +namespace d3d11 { + + +GraphicsSystem* Create(Emulator* emulator); + + +} // namespace d3d11 +} // namespace gpu +} // namespace xe + + +#endif // XENIA_GPU_D3D11_D3D11_GPU_H_ diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_driver.h b/src/xenia/gpu/d3d11/d3d11_graphics_driver.h index d660220f2..fb2e7b4d6 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_driver.h +++ b/src/xenia/gpu/d3d11/d3d11_graphics_driver.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc index 648067976..2dde94eda 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc +++ b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc @@ -21,7 +21,8 @@ using namespace xe::gpu::d3d11; namespace { -void __stdcall D3D11GraphicsSystemVsyncCallback(D3D11GraphicsSystem* gs, BOOLEAN) { +void __stdcall D3D11GraphicsSystemVsyncCallback( + D3D11GraphicsSystem* gs, BOOLEAN) { gs->MarkVblank(); gs->DispatchInterruptCallback(0); } @@ -29,10 +30,10 @@ void __stdcall D3D11GraphicsSystemVsyncCallback(D3D11GraphicsSystem* gs, BOOLEAN } -D3D11GraphicsSystem::D3D11GraphicsSystem(const CreationParams* params) : +D3D11GraphicsSystem::D3D11GraphicsSystem(Emulator* emulator) : window_(0), dxgi_factory_(0), device_(0), timer_queue_(NULL), vsync_timer_(NULL), - GraphicsSystem(params) { + GraphicsSystem(emulator) { } D3D11GraphicsSystem::~D3D11GraphicsSystem() { @@ -78,7 +79,7 @@ void D3D11GraphicsSystem::Initialize() { } // Just go with the default for now. adapter = 0; - + D3D_DRIVER_TYPE driver_type = adapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE; diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_system.h b/src/xenia/gpu/d3d11/d3d11_graphics_system.h index 7b0d0bd82..8b3420a37 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_system.h +++ b/src/xenia/gpu/d3d11/d3d11_graphics_system.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include @@ -25,12 +25,12 @@ namespace d3d11 { class D3D11Window; -GraphicsSystem* Create(const CreationParams* params); +GraphicsSystem* Create(Emulator* emulator); class D3D11GraphicsSystem : public GraphicsSystem { public: - D3D11GraphicsSystem(const CreationParams* params); + D3D11GraphicsSystem(Emulator* emulator); virtual ~D3D11GraphicsSystem(); protected: diff --git a/src/xenia/gpu/d3d11/sources.gypi b/src/xenia/gpu/d3d11/sources.gypi index b6a9052b7..3e3afa8e9 100644 --- a/src/xenia/gpu/d3d11/sources.gypi +++ b/src/xenia/gpu/d3d11/sources.gypi @@ -1,9 +1,9 @@ # Copyright 2013 Ben Vanik. All Rights Reserved. { 'sources': [ - 'd3d11-private.h', - 'd3d11.cc', - 'd3d11.h', + 'd3d11_gpu-private.h', + 'd3d11_gpu.cc', + 'd3d11_gpu.h', 'd3d11_graphics_driver.cc', 'd3d11_graphics_driver.h', 'd3d11_graphics_system.cc', diff --git a/src/xenia/gpu/gpu.cc b/src/xenia/gpu/gpu.cc index 0c8b4fb20..ebb448a87 100644 --- a/src/xenia/gpu/gpu.cc +++ b/src/xenia/gpu/gpu.cc @@ -20,39 +20,39 @@ DEFINE_string(gpu, "any", "Graphics system. Use: [any, nop, d3d11]"); -#include -GraphicsSystem* xe::gpu::CreateNop(const CreationParams* params) { - return xe::gpu::nop::Create(params); +#include +GraphicsSystem* xe::gpu::CreateNop(Emulator* emulator) { + return xe::gpu::nop::Create(emulator); } #if XE_PLATFORM(WIN32) -#include -GraphicsSystem* xe::gpu::CreateD3D11(const CreationParams* params) { - return xe::gpu::d3d11::Create(params); +#include +GraphicsSystem* xe::gpu::CreateD3D11(Emulator* emulator) { + return xe::gpu::d3d11::Create(emulator); } #endif // WIN32 -GraphicsSystem* xe::gpu::Create(const CreationParams* params) { +GraphicsSystem* xe::gpu::Create(Emulator* emulator) { if (FLAGS_gpu.compare("nop") == 0) { - return CreateNop(params); + return CreateNop(emulator); #if XE_PLATFORM(WIN32) } else if (FLAGS_gpu.compare("d3d11") == 0) { - return CreateD3D11(params); + return CreateD3D11(emulator); #endif // WIN32 } else { // Create best available. GraphicsSystem* best = NULL; #if XE_PLATFORM(WIN32) - best = CreateD3D11(params); + best = CreateD3D11(emulator); if (best) { return best; } #endif // WIN32 // Fallback to nop. - return CreateNop(params); + return CreateNop(emulator); } } diff --git a/src/xenia/gpu/gpu.h b/src/xenia/gpu/gpu.h index 1b5342846..70fc72376 100644 --- a/src/xenia/gpu/gpu.h +++ b/src/xenia/gpu/gpu.h @@ -13,16 +13,19 @@ #include +XEDECLARECLASS1(xe, Emulator); + + namespace xe { namespace gpu { -GraphicsSystem* Create(const CreationParams* params); +GraphicsSystem* Create(Emulator* emulator); -GraphicsSystem* CreateNop(const CreationParams* params); +GraphicsSystem* CreateNop(Emulator* emulator); #if XE_PLATFORM(WIN32) -GraphicsSystem* CreateD3D11(const CreationParams* params); +GraphicsSystem* CreateD3D11(Emulator* emulator); #endif // WIN32 diff --git a/src/xenia/gpu/graphics_driver.cc b/src/xenia/gpu/graphics_driver.cc index 662b4f0ef..3f081823d 100644 --- a/src/xenia/gpu/graphics_driver.cc +++ b/src/xenia/gpu/graphics_driver.cc @@ -24,7 +24,3 @@ GraphicsDriver::GraphicsDriver(xe_memory_ref memory) : GraphicsDriver::~GraphicsDriver() { xe_memory_release(memory_); } - -xe_memory_ref GraphicsDriver::memory() { - return xe_memory_retain(memory_); -} diff --git a/src/xenia/gpu/graphics_driver.h b/src/xenia/gpu/graphics_driver.h index 45c76fb1c..ef746d8d4 100644 --- a/src/xenia/gpu/graphics_driver.h +++ b/src/xenia/gpu/graphics_driver.h @@ -23,7 +23,7 @@ class GraphicsDriver { public: virtual ~GraphicsDriver(); - xe_memory_ref memory(); + xe_memory_ref memory() const { return memory_; } xenos::RegisterFile* register_file() { return ®ister_file_; }; void set_address_translation(uint32_t value) { address_translation_ = value; diff --git a/src/xenia/gpu/graphics_system.cc b/src/xenia/gpu/graphics_system.cc index d5e5eb42e..45ef056fd 100644 --- a/src/xenia/gpu/graphics_system.cc +++ b/src/xenia/gpu/graphics_system.cc @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -16,33 +17,21 @@ using namespace xe; +using namespace xe::cpu::ppc; using namespace xe::gpu; using namespace xe::gpu::xenos; -GraphicsSystem::GraphicsSystem(const CreationParams* params) : +GraphicsSystem::GraphicsSystem(Emulator* emulator) : + emulator_(emulator), + thread_(0), running_(false), driver_(0), worker_(0), interrupt_callback_(0), interrupt_callback_data_(0), last_interrupt_time_(0), swap_pending_(false) { - memory_ = xe_memory_retain(params->memory); - - worker_ = new RingBufferWorker(this, memory_); - - // Set during Initialize(); - driver_ = 0; + memory_ = xe_memory_retain(emulator->memory()); // Create the run loop used for any windows/etc. // This must be done on the thread we create the driver. run_loop_ = xe_run_loop_create(); - - // Create worker thread. - // This will initialize the graphics system. - // Init needs to happen there so that any thread-local stuff - // is created on the right thread. - running_ = true; - thread_ = xe_thread_create( - "GraphicsSystem", - (xe_thread_callback)ThreadStartThunk, this); - xe_thread_start(thread_); } GraphicsSystem::~GraphicsSystem() { @@ -57,16 +46,31 @@ GraphicsSystem::~GraphicsSystem() { xe_memory_release(memory_); } -xe_memory_ref GraphicsSystem::memory() { - return xe_memory_retain(memory_); -} +X_STATUS GraphicsSystem::Setup() { + processor_ = emulator_->processor(); -shared_ptr GraphicsSystem::processor() { - return processor_; -} + // Create worker. + worker_ = new RingBufferWorker(this, memory_); -void GraphicsSystem::set_processor(shared_ptr processor) { - processor_ = processor; + // Let the processor know we want register access callbacks. + RegisterAccessCallbacks callbacks; + callbacks.context = this; + callbacks.handles = (RegisterHandlesCallback)HandlesRegisterThunk; + callbacks.read = (RegisterReadCallback)ReadRegisterThunk; + callbacks.write = (RegisterWriteCallback)WriteRegisterThunk; + emulator_->processor()->AddRegisterAccessCallbacks(callbacks); + + // Create worker thread. + // This will initialize the graphics system. + // Init needs to happen there so that any thread-local stuff + // is created on the right thread. + running_ = true; + thread_ = xe_thread_create( + "GraphicsSystem", + (xe_thread_callback)ThreadStartThunk, this); + xe_thread_start(thread_); + + return X_STATUS_SUCCESS; } void GraphicsSystem::ThreadStart() { @@ -128,7 +132,12 @@ void GraphicsSystem::EnableReadPointerWriteBack(uint32_t ptr, worker_->EnableReadPointerWriteBack(ptr, block_size); } -uint64_t GraphicsSystem::ReadRegister(uint32_t r) { +bool GraphicsSystem::HandlesRegister(uint32_t addr) { + return (addr & 0xFFFF0000) == 0x7FC80000; +} + +uint64_t GraphicsSystem::ReadRegister(uint32_t addr) { + uint32_t r = addr & 0xFFFF; XELOGGPU("ReadRegister(%.4X)", r); RegisterFile* regs = driver_->register_file(); @@ -142,7 +151,8 @@ uint64_t GraphicsSystem::ReadRegister(uint32_t r) { return regs->values[r].u32; } -void GraphicsSystem::WriteRegister(uint32_t r, uint64_t value) { +void GraphicsSystem::WriteRegister(uint32_t addr, uint64_t value) { + uint32_t r = addr & 0xFFFF; XELOGGPU("WriteRegister(%.4X, %.8X)", r, value); RegisterFile* regs = driver_->register_file(); diff --git a/src/xenia/gpu/graphics_system.h b/src/xenia/gpu/graphics_system.h index ae6e6e88d..b0a42d5d6 100644 --- a/src/xenia/gpu/graphics_system.h +++ b/src/xenia/gpu/graphics_system.h @@ -11,13 +11,11 @@ #define XENIA_GPU_GRAPHICS_SYSTEM_H_ #include +#include -namespace xe { -namespace cpu { -class Processor; -} // namespace cpu -} // namespace xe +XEDECLARECLASS1(xe, Emulator); +XEDECLARECLASS2(xe, cpu, Processor); namespace xe { @@ -27,47 +25,29 @@ class GraphicsDriver; class RingBufferWorker; -class CreationParams { -public: - xe_memory_ref memory; - - CreationParams() : - memory(0) { - } -}; - - class GraphicsSystem { public: virtual ~GraphicsSystem(); - xe_memory_ref memory(); - shared_ptr processor(); - void set_processor(shared_ptr processor); + Emulator* emulator() const { return emulator_; } + xe_memory_ref memory() const { return memory_; } + cpu::Processor* processor() const { return processor_; } + + virtual X_STATUS Setup(); void SetInterruptCallback(uint32_t callback, uint32_t user_data); void InitializeRingBuffer(uint32_t ptr, uint32_t page_count); void EnableReadPointerWriteBack(uint32_t ptr, uint32_t block_size); - virtual uint64_t ReadRegister(uint32_t r); - virtual void WriteRegister(uint32_t r, uint64_t value); + bool HandlesRegister(uint32_t addr); + virtual uint64_t ReadRegister(uint32_t addr); + virtual void WriteRegister(uint32_t addr, uint64_t value); void MarkVblank(); void DispatchInterruptCallback(uint32_t source, uint32_t cpu = 0xFFFFFFFF); bool swap_pending() const { return swap_pending_; } void set_swap_pending(bool value) { swap_pending_ = value; } -public: - // TODO(benvanik): have an HasRegisterHandler() so that the JIT can - // just poke the register file directly. - static uint64_t ReadRegisterThunk(GraphicsSystem* this_ptr, uint32_t r) { - return this_ptr->ReadRegister(r); - } - static void WriteRegisterThunk(GraphicsSystem* this_ptr, uint32_t r, - uint64_t value) { - this_ptr->WriteRegister(r, value); - } - protected: virtual void Initialize(); virtual void Pump() = 0; @@ -79,12 +59,24 @@ private: } void ThreadStart(); -protected: - GraphicsSystem(const CreationParams* params); + static bool HandlesRegisterThunk(GraphicsSystem* gs, uint32_t addr) { + return gs->HandlesRegister(addr); + } + static uint64_t ReadRegisterThunk(GraphicsSystem* gs, uint32_t addr) { + return gs->ReadRegister(addr); + } + static void WriteRegisterThunk(GraphicsSystem* gs, uint32_t addr, + uint64_t value) { + gs->WriteRegister(addr, value); + } +protected: + GraphicsSystem(Emulator* emulator); + + Emulator* emulator_; xe_memory_ref memory_; - shared_ptr processor_; - + cpu::Processor* processor_; + xe_run_loop_ref run_loop_; xe_thread_ref thread_; bool running_; diff --git a/src/xenia/gpu/nop/nop-private.h b/src/xenia/gpu/nop/nop_gpu-private.h similarity index 83% rename from src/xenia/gpu/nop/nop-private.h rename to src/xenia/gpu/nop/nop_gpu-private.h index 47c17ca63..2aaa2d459 100644 --- a/src/xenia/gpu/nop/nop-private.h +++ b/src/xenia/gpu/nop/nop_gpu-private.h @@ -1,31 +1,31 @@ -/** - ****************************************************************************** - * 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_GPU_NOP_NOP_PRIVATE_H_ -#define XENIA_GPU_NOP_NOP_PRIVATE_H_ - -#include - -#include - - -namespace xe { -namespace gpu { -namespace nop { - - - - - -} // namespace nop -} // namespace gpu -} // namespace xe - - -#endif // XENIA_GPU_NOP_NOP_PRIVATE_H_ +/** + ****************************************************************************** + * 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_GPU_NOP_NOP_GPU_PRIVATE_H_ +#define XENIA_GPU_NOP_NOP_GPU_PRIVATE_H_ + +#include + +#include + + +namespace xe { +namespace gpu { +namespace nop { + + + + + +} // namespace nop +} // namespace gpu +} // namespace xe + + +#endif // XENIA_GPU_NOP_NOP_PRIVATE_H_ diff --git a/src/xenia/gpu/nop/nop.cc b/src/xenia/gpu/nop/nop_gpu.cc similarity index 83% rename from src/xenia/gpu/nop/nop.cc rename to src/xenia/gpu/nop/nop_gpu.cc index 4f416befe..d976f5fa4 100644 --- a/src/xenia/gpu/nop/nop.cc +++ b/src/xenia/gpu/nop/nop_gpu.cc @@ -1,44 +1,44 @@ -/** - ****************************************************************************** - * 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 - -#include - - -using namespace xe; -using namespace xe::gpu; -using namespace xe::gpu::nop; - - -namespace { - void InitializeIfNeeded(); - void CleanupOnShutdown(); - - void InitializeIfNeeded() { - static bool has_initialized = false; - if (has_initialized) { - return; - } - has_initialized = true; - - // - - atexit(CleanupOnShutdown); - } - - void CleanupOnShutdown() { - } -} - - -GraphicsSystem* xe::gpu::nop::Create(const CreationParams* params) { - InitializeIfNeeded(); - return new NopGraphicsSystem(params); -} +/** + ****************************************************************************** + * 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 + +#include + + +using namespace xe; +using namespace xe::gpu; +using namespace xe::gpu::nop; + + +namespace { + void InitializeIfNeeded(); + void CleanupOnShutdown(); + + void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; + } + has_initialized = true; + + // + + atexit(CleanupOnShutdown); + } + + void CleanupOnShutdown() { + } +} + + +GraphicsSystem* xe::gpu::nop::Create(Emulator* emulator) { + InitializeIfNeeded(); + return new NopGraphicsSystem(emulator); +} diff --git a/src/xenia/gpu/nop/nop_gpu.h b/src/xenia/gpu/nop/nop_gpu.h new file mode 100644 index 000000000..7d3e03a34 --- /dev/null +++ b/src/xenia/gpu/nop/nop_gpu.h @@ -0,0 +1,33 @@ +/** + ****************************************************************************** + * 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_GPU_NOP_NOP_GPU_H_ +#define XENIA_GPU_NOP_NOP_GPU_H_ + +#include + + +XEDECLARECLASS1(xe, Emulator); +XEDECLARECLASS2(xe, gpu, GraphicsSystem); + + +namespace xe { +namespace gpu { +namespace nop { + + +GraphicsSystem* Create(Emulator* emulator); + + +} // namespace nop +} // namespace gpu +} // namespace xe + + +#endif // XENIA_GPU_NOP_NOP_GPU_H_ diff --git a/src/xenia/gpu/nop/nop_graphics_driver.h b/src/xenia/gpu/nop/nop_graphics_driver.h index 66c5d3329..881822b45 100644 --- a/src/xenia/gpu/nop/nop_graphics_driver.h +++ b/src/xenia/gpu/nop/nop_graphics_driver.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include diff --git a/src/xenia/gpu/nop/nop_graphics_system.cc b/src/xenia/gpu/nop/nop_graphics_system.cc index ed04bd346..9ae31bb3a 100644 --- a/src/xenia/gpu/nop/nop_graphics_system.cc +++ b/src/xenia/gpu/nop/nop_graphics_system.cc @@ -28,8 +28,8 @@ void __stdcall NopGraphicsSystemVsyncCallback(NopGraphicsSystem* gs, BOOLEAN) { } -NopGraphicsSystem::NopGraphicsSystem(const CreationParams* params) : - GraphicsSystem(params), +NopGraphicsSystem::NopGraphicsSystem(Emulator* emulator) : + GraphicsSystem(emulator), timer_queue_(NULL), vsync_timer_(NULL) { } diff --git a/src/xenia/gpu/nop/nop_graphics_system.h b/src/xenia/gpu/nop/nop_graphics_system.h index c0f6ac614..4ff0579d5 100644 --- a/src/xenia/gpu/nop/nop_graphics_system.h +++ b/src/xenia/gpu/nop/nop_graphics_system.h @@ -13,7 +13,7 @@ #include #include -#include +#include namespace xe { @@ -23,7 +23,7 @@ namespace nop { class NopGraphicsSystem : public GraphicsSystem { public: - NopGraphicsSystem(const CreationParams* params); + NopGraphicsSystem(Emulator* emulator); virtual ~NopGraphicsSystem(); protected: diff --git a/src/xenia/gpu/nop/sources.gypi b/src/xenia/gpu/nop/sources.gypi index 1d167f9a4..28892e9b3 100644 --- a/src/xenia/gpu/nop/sources.gypi +++ b/src/xenia/gpu/nop/sources.gypi @@ -1,9 +1,9 @@ # Copyright 2013 Ben Vanik. All Rights Reserved. { 'sources': [ - 'nop-private.h', - 'nop.cc', - 'nop.h', + 'nop_gpu-private.h', + 'nop_gpu.cc', + 'nop_gpu.h', 'nop_graphics_driver.cc', 'nop_graphics_driver.h', 'nop_graphics_system.cc', diff --git a/src/xenia/gpu/ring_buffer_worker.cc b/src/xenia/gpu/ring_buffer_worker.cc index dde1c208b..96e29096f 100644 --- a/src/xenia/gpu/ring_buffer_worker.cc +++ b/src/xenia/gpu/ring_buffer_worker.cc @@ -570,7 +570,7 @@ uint32_t RingBufferWorker::ExecutePacket(PacketArgs& args) { switch (type) { case 0x4: // REGISTER index += 0x2000; - for (int n = 0; n < count - 1; n++, index++) { + for (uint32_t n = 0; n < count - 1; n++, index++) { uint32_t data = READ_PTR(); const char* reg_name = xenos::GetRegisterName(index); XELOGGPU("[%.8X] %.8X -> %.4X %s", diff --git a/src/xenia/gpu/xenos/sources.gypi b/src/xenia/gpu/xenos/sources.gypi index 4b8b2b296..c1f677682 100644 --- a/src/xenia/gpu/xenos/sources.gypi +++ b/src/xenia/gpu/xenos/sources.gypi @@ -5,7 +5,6 @@ 'register_table.inc', 'registers.cc', 'registers.h', - 'ucode.cc', 'ucode.h', 'ucode_disassembler.cc', 'ucode_disassembler.h', diff --git a/src/xenia/kernel/kernel.h b/src/xenia/kernel/kernel.h index 5fe073206..21c3a5cc2 100644 --- a/src/xenia/kernel/kernel.h +++ b/src/xenia/kernel/kernel.h @@ -10,7 +10,6 @@ #ifndef XENIA_KERNEL_KERNEL_H_ #define XENIA_KERNEL_KERNEL_H_ -#include -#include +#include #endif // XENIA_KERNEL_KERNEL_H_ diff --git a/src/xenia/kernel/kernel_module.cc b/src/xenia/kernel/kernel_module.cc index 2cc1c18d7..9252f1096 100644 --- a/src/xenia/kernel/kernel_module.cc +++ b/src/xenia/kernel/kernel_module.cc @@ -9,21 +9,20 @@ #include -#include -#include +#include +#include using namespace xe; using namespace xe::kernel; -KernelModule::KernelModule(Runtime* runtime) { - runtime_ = runtime; - memory_ = runtime->memory(); - export_resolver_ = runtime->export_resolver(); +KernelModule::KernelModule(Emulator* emulator) : + emulator_(emulator) { + memory_ = xe_memory_retain(emulator_->memory()); + export_resolver_ = emulator->export_resolver(); } KernelModule::~KernelModule() { - export_resolver_.reset(); xe_memory_release(memory_); } diff --git a/src/xenia/kernel/kernel_module.h b/src/xenia/kernel/kernel_module.h index 1d1876f85..229c9c42d 100644 --- a/src/xenia/kernel/kernel_module.h +++ b/src/xenia/kernel/kernel_module.h @@ -14,23 +14,23 @@ #include +XEDECLARECLASS1(xe, Emulator); +XEDECLARECLASS1(xe, ExportResolver); + + namespace xe { namespace kernel { -class ExportResolver; -class Runtime; - - class KernelModule { public: - KernelModule(Runtime* runtime); + KernelModule(Emulator* emulator); virtual ~KernelModule(); protected: - Runtime* runtime_; + Emulator* emulator_; xe_memory_ref memory_; - shared_ptr export_resolver_; + ExportResolver* export_resolver_; }; diff --git a/src/xenia/kernel/modules/modules.h b/src/xenia/kernel/modules.h similarity index 85% rename from src/xenia/kernel/modules/modules.h rename to src/xenia/kernel/modules.h index 735091394..439134680 100644 --- a/src/xenia/kernel/modules/modules.h +++ b/src/xenia/kernel/modules.h @@ -10,7 +10,7 @@ #ifndef XENIA_KERNEL_MODULES_H_ #define XENIA_KERNEL_MODULES_H_ -#include -#include +#include +#include #endif // XENIA_KERNEL_MODULES_H_ diff --git a/src/xenia/kernel/modules/sources.gypi b/src/xenia/kernel/modules/sources.gypi deleted file mode 100644 index 46f9a5946..000000000 --- a/src/xenia/kernel/modules/sources.gypi +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright 2013 Ben Vanik. All Rights Reserved. -{ - 'sources': [ - 'modules.h', - ], - - 'includes': [ - 'xam/sources.gypi', - 'xboxkrnl/sources.gypi', - ], -} diff --git a/src/xenia/kernel/modules/xboxkrnl/kernel_state.h b/src/xenia/kernel/modules/xboxkrnl/kernel_state.h deleted file mode 100644 index 442d758db..000000000 --- a/src/xenia/kernel/modules/xboxkrnl/kernel_state.h +++ /dev/null @@ -1,78 +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_KERNEL_MODULES_XBOXKRNL_KERNEL_STATE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_KERNEL_STATE_H_ - -#include -#include - -#include -#include -#include -#include -#include - - -namespace xe { -namespace cpu { -class Processor; -} -} - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - -class XModule; -namespace fs { -class FileSystem; -} - - -class KernelState { -public: - KernelState(Runtime* runtime); - ~KernelState(); - - static KernelState* shared(); - - Runtime* runtime(); - xe_memory_ref memory(); - cpu::Processor* processor(); - fs::FileSystem* filesystem(); - - ObjectTable* object_table() const; - - XModule* GetModule(const char* name); - XModule* GetExecutableModule(); - void SetExecutableModule(XModule* module); - -private: - Runtime* runtime_; - xe_memory_ref memory_; - shared_ptr processor_; - shared_ptr filesystem_; - - ObjectTable* object_table_; - xe_mutex_t* object_mutex_; - - XModule* executable_module_; - - friend class XObject; -}; - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_KERNEL_STATE_H_ diff --git a/src/xenia/kernel/runtime.cc b/src/xenia/kernel/runtime.cc deleted file mode 100644 index e89869dbe..000000000 --- a/src/xenia/kernel/runtime.cc +++ /dev/null @@ -1,136 +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 - -#include -#include - - -using namespace xe; -using namespace xe::cpu; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl::fs; - - -Runtime::Runtime(shared_ptr processor, - const xechar_t* command_line) { - memory_ = processor->memory(); - processor_ = processor; - XEIGNORE(xestrcpy(command_line_, XECOUNT(command_line_), command_line)); - export_resolver_ = shared_ptr(new ExportResolver()); - - filesystem_ = shared_ptr(new FileSystem()); - - xboxkrnl_ = auto_ptr( - new xboxkrnl::XboxkrnlModule(this)); - xam_ = auto_ptr( - new xam::XamModule(this)); -} - -Runtime::~Runtime() { - xe_memory_release(memory_); -} - -const xechar_t* Runtime::command_line() { - return command_line_; -} - -xe_memory_ref Runtime::memory() { - return xe_memory_retain(memory_); -} - -shared_ptr Runtime::processor() { - return processor_; -} - -shared_ptr Runtime::export_resolver() { - return export_resolver_; -} - -shared_ptr Runtime::filesystem() { - return filesystem_; -} - -int Runtime::LaunchXexFile(const xechar_t* path) { - // We create a virtual filesystem pointing to its directory and symlink - // that to the game filesystem. - // e.g., /my/files/foo.xex will get a local fs at: - // \\Device\\Harddisk0\\Partition1 - // and then get that symlinked to game:\, so - // -> game:\foo.xex - - int result_code = 0; - - // Get just the filename (foo.xex). - const xechar_t* file_name = xestrrchr(path, XE_PATH_SEPARATOR); - if (file_name) { - // Skip slash. - file_name++; - } else { - // No slash found, whole thing is a file. - file_name = path; - } - - // Get the parent path of the file. - xechar_t parent_path[XE_MAX_PATH]; - XEIGNORE(xestrcpy(parent_path, XECOUNT(parent_path), path)); - parent_path[file_name - path] = 0; - - // Register the local directory in the virtual filesystem. - result_code = filesystem_->RegisterHostPathDevice( - "\\Device\\Harddisk1\\Partition0", parent_path); - if (result_code) { - XELOGE("Unable to mount local directory"); - return result_code; - } - - // Create symlinks to the device. - filesystem_->CreateSymbolicLink( - "game:", "\\Device\\Harddisk1\\Partition0"); - filesystem_->CreateSymbolicLink( - "d:", "\\Device\\Harddisk1\\Partition0"); - - // Get the file name of the module to load from the filesystem. - char fs_path[XE_MAX_PATH]; - XEIGNORE(xestrcpya(fs_path, XECOUNT(fs_path), "game:\\")); - char* fs_path_ptr = fs_path + xestrlena(fs_path); - *fs_path_ptr = 0; -#if XE_WCHAR - XEIGNORE(xestrnarrow(fs_path_ptr, XECOUNT(fs_path), file_name)); -#else - XEIGNORE(xestrcpya(fs_path_ptr, XECOUNT(fs_path), file_name)); -#endif - - // Launch the game. - return xboxkrnl_->LaunchModule(fs_path); -} - -int Runtime::LaunchDiscImage(const xechar_t* path) { - int result_code = 0; - - // Register the disc image in the virtual filesystem. - result_code = filesystem_->RegisterDiscImageDevice( - "\\Device\\Cdrom0", path); - if (result_code) { - XELOGE("Unable to mount disc image"); - return result_code; - } - - // Create symlinks to the device. - filesystem_->CreateSymbolicLink( - "game:", - "\\Device\\Cdrom0"); - filesystem_->CreateSymbolicLink( - "d:", - "\\Device\\Cdrom0"); - - // Launch the game. - return xboxkrnl_->LaunchModule("game:\\default.xex"); -} diff --git a/src/xenia/kernel/runtime.h b/src/xenia/kernel/runtime.h deleted file mode 100644 index 7553e548b..000000000 --- a/src/xenia/kernel/runtime.h +++ /dev/null @@ -1,77 +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_KERNEL_RUNTIME_H_ -#define XENIA_KERNEL_RUNTIME_H_ - -#include -#include -#include - -#include -#include - - -namespace xe { -namespace cpu { - class Processor; -} -namespace kernel { -namespace xboxkrnl { - class XboxkrnlModule; -namespace fs { - class FileSystem; -} -} -namespace xam { - class XamModule; -} -} -} - - -namespace xe { -namespace kernel { - -class KernelModule; - - -class Runtime { -public: - Runtime(shared_ptr processor, const xechar_t* command_line); - ~Runtime(); - - const xechar_t* command_line(); - - xe_memory_ref memory(); - shared_ptr processor(); - shared_ptr export_resolver(); - shared_ptr filesystem(); - - int LaunchXexFile(const xechar_t* path); - int LaunchDiscImage(const xechar_t* path); - -private: - xechar_t command_line_[XE_MAX_PATH]; - - xe_memory_ref memory_; - shared_ptr processor_; - shared_ptr export_resolver_; - shared_ptr filesystem_; - - auto_ptr xboxkrnl_; - auto_ptr xam_; -}; - - -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_RUNTIME_H_ diff --git a/src/xenia/kernel/shim_utils.h b/src/xenia/kernel/shim_utils.h index 16120245b..71e8c64d0 100644 --- a/src/xenia/kernel/shim_utils.h +++ b/src/xenia/kernel/shim_utils.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include diff --git a/src/xenia/kernel/sources.gypi b/src/xenia/kernel/sources.gypi index 1d205ae61..9bd4b8283 100644 --- a/src/xenia/kernel/sources.gypi +++ b/src/xenia/kernel/sources.gypi @@ -1,22 +1,19 @@ # Copyright 2013 Ben Vanik. All Rights Reserved. { 'sources': [ - 'export.cc', - 'export.h', 'kernel.h', 'kernel_module.cc', 'kernel_module.h', - 'runtime.cc', - 'runtime.h', + 'modules.h', 'shim_utils.h', - 'xbox.h', 'xex2.cc', 'xex2.h', 'xex2_info.h', ], 'includes': [ - 'modules/sources.gypi', + 'xam/sources.gypi', + 'xboxkrnl/sources.gypi', 'util/sources.gypi', ], } diff --git a/src/xenia/kernel/util/export_table_pre.inc b/src/xenia/kernel/util/export_table_pre.inc index f3f30ab55..c71f93ea8 100644 --- a/src/xenia/kernel/util/export_table_pre.inc +++ b/src/xenia/kernel/util/export_table_pre.inc @@ -14,7 +14,7 @@ * // Build the export table used for resolution. * #include * static KernelExport my_module_export_table[] = { - * #include + * #include * }; * #include * export_resolver_->RegisterTable( diff --git a/src/xenia/kernel/util/ordinal_table_pre.inc b/src/xenia/kernel/util/ordinal_table_pre.inc index a5f93aaaf..fd0407a19 100644 --- a/src/xenia/kernel/util/ordinal_table_pre.inc +++ b/src/xenia/kernel/util/ordinal_table_pre.inc @@ -15,7 +15,7 @@ * #include * namespace ordinals { * enum { - * #include + * #include * }; * } // namespace ordinals * #include diff --git a/src/xenia/kernel/modules/xam/sources.gypi b/src/xenia/kernel/xam/sources.gypi similarity index 100% rename from src/xenia/kernel/modules/xam/sources.gypi rename to src/xenia/kernel/xam/sources.gypi diff --git a/src/xenia/kernel/modules/xam/xam_content.cc b/src/xenia/kernel/xam/xam_content.cc similarity index 89% rename from src/xenia/kernel/modules/xam/xam_content.cc rename to src/xenia/kernel/xam/xam_content.cc index 266388ac1..a660b1dd5 100644 --- a/src/xenia/kernel/modules/xam/xam_content.cc +++ b/src/xenia/kernel/xam/xam_content.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include #include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xam/xam_content.h b/src/xenia/kernel/xam/xam_content.h similarity index 79% rename from src/xenia/kernel/modules/xam/xam_content.h rename to src/xenia/kernel/xam/xam_content.h index c5d0d4f05..42aad6660 100644 --- a/src/xenia/kernel/modules/xam/xam_content.h +++ b/src/xenia/kernel/xam/xam_content.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_CONTENT_H_ -#define XENIA_KERNEL_MODULES_XAM_CONTENT_H_ +#ifndef XENIA_KERNEL_XAM_CONTENT_H_ +#define XENIA_KERNEL_XAM_CONTENT_H_ #include #include -#include +#include namespace xe { @@ -28,4 +28,4 @@ namespace xam { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_CONTENT_H_ +#endif // XENIA_KERNEL_XAM_CONTENT_H_ diff --git a/src/xenia/kernel/modules/xam/xam_info.cc b/src/xenia/kernel/xam/xam_info.cc similarity index 93% rename from src/xenia/kernel/modules/xam/xam_info.cc rename to src/xenia/kernel/xam/xam_info.cc index 74b4da33f..bca7136d2 100644 --- a/src/xenia/kernel/modules/xam/xam_info.cc +++ b/src/xenia/kernel/xam/xam_info.cc @@ -7,12 +7,12 @@ ****************************************************************************** */ -#include +#include #include #include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xam/xam_info.h b/src/xenia/kernel/xam/xam_info.h similarity index 80% rename from src/xenia/kernel/modules/xam/xam_info.h rename to src/xenia/kernel/xam/xam_info.h index a8ed93d96..e786c71d2 100644 --- a/src/xenia/kernel/modules/xam/xam_info.h +++ b/src/xenia/kernel/xam/xam_info.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_INFO_H_ -#define XENIA_KERNEL_MODULES_XAM_INFO_H_ +#ifndef XENIA_KERNEL_XAM_INFO_H_ +#define XENIA_KERNEL_XAM_INFO_H_ #include #include -#include +#include namespace xe { @@ -28,4 +28,4 @@ namespace xam { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_INFO_H_ +#endif // XENIA_KERNEL_XAM_INFO_H_ diff --git a/src/xenia/kernel/modules/xam/xam_input.cc b/src/xenia/kernel/xam/xam_input.cc similarity index 89% rename from src/xenia/kernel/modules/xam/xam_input.cc rename to src/xenia/kernel/xam/xam_input.cc index 908b93f88..60927a62b 100644 --- a/src/xenia/kernel/modules/xam/xam_input.cc +++ b/src/xenia/kernel/xam/xam_input.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include #include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xam/xam_input.h b/src/xenia/kernel/xam/xam_input.h similarity index 80% rename from src/xenia/kernel/modules/xam/xam_input.h rename to src/xenia/kernel/xam/xam_input.h index 8dd6a011e..cfd0d771f 100644 --- a/src/xenia/kernel/modules/xam/xam_input.h +++ b/src/xenia/kernel/xam/xam_input.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_INPUT_H_ -#define XENIA_KERNEL_MODULES_XAM_INPUT_H_ +#ifndef XENIA_KERNEL_XAM_INPUT_H_ +#define XENIA_KERNEL_XAM_INPUT_H_ #include #include -#include +#include namespace xe { @@ -28,4 +28,4 @@ namespace xam { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_INPUT_H_ +#endif // XENIA_KERNEL_XAM_INPUT_H_ diff --git a/src/xenia/kernel/modules/xam/xam_module.cc b/src/xenia/kernel/xam/xam_module.cc similarity index 59% rename from src/xenia/kernel/modules/xam/xam_module.cc rename to src/xenia/kernel/xam/xam_module.cc index f25331020..de6ea1a78 100644 --- a/src/xenia/kernel/modules/xam/xam_module.cc +++ b/src/xenia/kernel/xam/xam_module.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include -#include -#include -#include +#include +#include +#include using namespace xe; @@ -22,31 +22,31 @@ using namespace xe::kernel::xam; XamState* xe::kernel::xam::shared_xam_state_ = NULL; -XamModule::XamModule(Runtime* runtime) : - KernelModule(runtime) { +XamModule::XamModule(Emulator* emulator) : + KernelModule(emulator) { // Build the export table used for resolution. #include static KernelExport xam_export_table[] = { - #include + #include }; #include export_resolver_->RegisterTable( "xam.xex", xam_export_table, XECOUNT(xam_export_table)); // Setup the xam state instance. - xam_state = auto_ptr(new XamState(memory_, export_resolver_)); + xam_state_ = new XamState(emulator); // Setup the shared global state object. XEASSERTNULL(shared_xam_state_); - shared_xam_state_ = xam_state.get(); + shared_xam_state_ = xam_state_; // Register all exported functions. - RegisterContentExports(export_resolver_.get(), xam_state.get()); - RegisterInfoExports(export_resolver_.get(), xam_state.get()); - RegisterInputExports(export_resolver_.get(), xam_state.get()); - RegisterNetExports(export_resolver_.get(), xam_state.get()); - RegisterUserExports(export_resolver_.get(), xam_state.get()); - RegisterVideoExports(export_resolver_.get(), xam_state.get()); + RegisterContentExports(export_resolver_, xam_state_); + RegisterInfoExports(export_resolver_, xam_state_); + RegisterInputExports(export_resolver_, xam_state_); + RegisterNetExports(export_resolver_, xam_state_); + RegisterUserExports(export_resolver_, xam_state_); + RegisterVideoExports(export_resolver_, xam_state_); } XamModule::~XamModule() { diff --git a/src/xenia/kernel/modules/xam/xam_module.h b/src/xenia/kernel/xam/xam_module.h similarity index 73% rename from src/xenia/kernel/modules/xam/xam_module.h rename to src/xenia/kernel/xam/xam_module.h index 33c068188..cb91bf9c6 100644 --- a/src/xenia/kernel/modules/xam/xam_module.h +++ b/src/xenia/kernel/xam/xam_module.h @@ -7,18 +7,18 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_H_ -#define XENIA_KERNEL_MODULES_XAM_H_ +#ifndef XENIA_KERNEL_XAM_H_ +#define XENIA_KERNEL_XAM_H_ #include #include -#include +#include #include -#include +#include // All of the exported functions: -#include +#include namespace xe { @@ -30,11 +30,11 @@ class XamState; class XamModule : public KernelModule { public: - XamModule(Runtime* runtime); + XamModule(Emulator* emulator); virtual ~XamModule(); private: - auto_ptr xam_state; + XamState* xam_state_; }; @@ -43,4 +43,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_H_ +#endif // XENIA_KERNEL_XAM_H_ diff --git a/src/xenia/kernel/modules/xam/xam_net.cc b/src/xenia/kernel/xam/xam_net.cc similarity index 92% rename from src/xenia/kernel/modules/xam/xam_net.cc rename to src/xenia/kernel/xam/xam_net.cc index 4f946b259..aab7ee9de 100644 --- a/src/xenia/kernel/modules/xam/xam_net.cc +++ b/src/xenia/kernel/xam/xam_net.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include #include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xam/xam_net.h b/src/xenia/kernel/xam/xam_net.h similarity index 81% rename from src/xenia/kernel/modules/xam/xam_net.h rename to src/xenia/kernel/xam/xam_net.h index 24a31fa47..fffadf725 100644 --- a/src/xenia/kernel/modules/xam/xam_net.h +++ b/src/xenia/kernel/xam/xam_net.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_NET_H_ -#define XENIA_KERNEL_MODULES_XAM_NET_H_ +#ifndef XENIA_KERNEL_XAM_NET_H_ +#define XENIA_KERNEL_XAM_NET_H_ #include #include -#include +#include namespace xe { @@ -28,4 +28,4 @@ namespace xam { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_NET_H_ +#endif // XENIA_KERNEL_XAM_NET_H_ diff --git a/src/xenia/kernel/modules/xam/xam_ordinals.h b/src/xenia/kernel/xam/xam_ordinals.h similarity index 75% rename from src/xenia/kernel/modules/xam/xam_ordinals.h rename to src/xenia/kernel/xam/xam_ordinals.h index d32102581..6941106ab 100644 --- a/src/xenia/kernel/modules/xam/xam_ordinals.h +++ b/src/xenia/kernel/xam/xam_ordinals.h @@ -1,29 +1,29 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XAM_ORDINALS_H_ -#define XENIA_KERNEL_MODULES_XAM_ORDINALS_H_ - -#include -#include - -#include - - -// Build an ordinal enum to make it easy to lookup ordinals. -#include -namespace ordinals { -enum { - #include -}; -} // namespace ordinals -#include - - -#endif // XENIA_KERNEL_MODULES_XAM_ORDINALS_H_ +/** + ****************************************************************************** + * 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_KERNEL_XAM_ORDINALS_H_ +#define XENIA_KERNEL_XAM_ORDINALS_H_ + +#include +#include + +#include + + +// Build an ordinal enum to make it easy to lookup ordinals. +#include +namespace ordinals { +enum { + #include +}; +} // namespace ordinals +#include + + +#endif // XENIA_KERNEL_XAM_ORDINALS_H_ diff --git a/src/xenia/kernel/modules/xam/xam_private.h b/src/xenia/kernel/xam/xam_private.h similarity index 85% rename from src/xenia/kernel/modules/xam/xam_private.h rename to src/xenia/kernel/xam/xam_private.h index 32375d540..8336c9b7a 100644 --- a/src/xenia/kernel/modules/xam/xam_private.h +++ b/src/xenia/kernel/xam/xam_private.h @@ -1,46 +1,46 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XAM_PRIVATE_H_ -#define XENIA_KERNEL_MODULES_XAM_PRIVATE_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xam { - -class XamState; - - -// This is a global object initialized with the XamModule. -// It references the current xam state object that all xam methods should -// be using to stash their variables. -extern XamState* shared_xam_state_; - - -// Registration functions, one per file. -void RegisterContentExports(ExportResolver* export_resolver, XamState* state); -void RegisterInfoExports(ExportResolver* export_resolver, XamState* state); -void RegisterInputExports(ExportResolver* export_resolver, XamState* state); -void RegisterNetExports(ExportResolver* export_resolver, XamState* state); -void RegisterUserExports(ExportResolver* export_resolver, XamState* state); -void RegisterVideoExports(ExportResolver* export_resolver, XamState* state); - - -} // namespace xam -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XAM_PRIVATE_H_ +/** + ****************************************************************************** + * 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_KERNEL_XAM_PRIVATE_H_ +#define XENIA_KERNEL_XAM_PRIVATE_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xam { + +class XamState; + + +// This is a global object initialized with the XamModule. +// It references the current xam state object that all xam methods should +// be using to stash their variables. +extern XamState* shared_xam_state_; + + +// Registration functions, one per file. +void RegisterContentExports(ExportResolver* export_resolver, XamState* state); +void RegisterInfoExports(ExportResolver* export_resolver, XamState* state); +void RegisterInputExports(ExportResolver* export_resolver, XamState* state); +void RegisterNetExports(ExportResolver* export_resolver, XamState* state); +void RegisterUserExports(ExportResolver* export_resolver, XamState* state); +void RegisterVideoExports(ExportResolver* export_resolver, XamState* state); + + +} // namespace xam +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XAM_PRIVATE_H_ diff --git a/src/xenia/kernel/modules/xam/xam_state.cc b/src/xenia/kernel/xam/xam_state.cc similarity index 70% rename from src/xenia/kernel/modules/xam/xam_state.cc rename to src/xenia/kernel/xam/xam_state.cc index 98a0fb6e0..b27ea1de5 100644 --- a/src/xenia/kernel/modules/xam/xam_state.cc +++ b/src/xenia/kernel/xam/xam_state.cc @@ -7,7 +7,9 @@ ****************************************************************************** */ -#include +#include + +#include using namespace xe; @@ -20,12 +22,12 @@ namespace { } -XamState::XamState(xe_memory_ref memory, - shared_ptr export_resolver) { - this->memory = xe_memory_retain(memory); - export_resolver_ = export_resolver; +XamState::XamState(Emulator* emulator) : + emulator_(emulator) { + memory_ = xe_memory_retain(emulator->memory()); + export_resolver_ = emulator->export_resolver(); } XamState::~XamState() { - xe_memory_release(memory); + xe_memory_release(memory_); } diff --git a/src/xenia/kernel/modules/xam/xam_state.h b/src/xenia/kernel/xam/xam_state.h similarity index 69% rename from src/xenia/kernel/modules/xam/xam_state.h rename to src/xenia/kernel/xam/xam_state.h index 83e95e219..e5dc4cb7e 100644 --- a/src/xenia/kernel/modules/xam/xam_state.h +++ b/src/xenia/kernel/xam/xam_state.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_XAM_STATE_H_ -#define XENIA_KERNEL_MODULES_XAM_XAM_STATE_H_ +#ifndef XENIA_KERNEL_XAM_XAM_STATE_H_ +#define XENIA_KERNEL_XAM_XAM_STATE_H_ #include #include -#include +#include #include @@ -24,13 +24,15 @@ namespace xam { class XamState { public: - XamState(xe_memory_ref memory, shared_ptr export_resolver); + XamState(Emulator* emulator); ~XamState(); - xe_memory_ref memory; + xe_memory_ref memory() const { return memory_; } private: - shared_ptr export_resolver_; + Emulator* emulator_; + xe_memory_ref memory_; + ExportResolver* export_resolver_; }; @@ -39,4 +41,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_XAM_STATE_H_ +#endif // XENIA_KERNEL_XAM_XAM_STATE_H_ diff --git a/src/xenia/kernel/modules/xam/xam_table.inc b/src/xenia/kernel/xam/xam_table.inc similarity index 100% rename from src/xenia/kernel/modules/xam/xam_table.inc rename to src/xenia/kernel/xam/xam_table.inc diff --git a/src/xenia/kernel/modules/xam/xam_user.cc b/src/xenia/kernel/xam/xam_user.cc similarity index 91% rename from src/xenia/kernel/modules/xam/xam_user.cc rename to src/xenia/kernel/xam/xam_user.cc index ef2a0730e..619a2aea1 100644 --- a/src/xenia/kernel/modules/xam/xam_user.cc +++ b/src/xenia/kernel/xam/xam_user.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include #include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xam/xam_user.h b/src/xenia/kernel/xam/xam_user.h similarity index 80% rename from src/xenia/kernel/modules/xam/xam_user.h rename to src/xenia/kernel/xam/xam_user.h index a6382e5c0..802d78b94 100644 --- a/src/xenia/kernel/modules/xam/xam_user.h +++ b/src/xenia/kernel/xam/xam_user.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_USER_H_ -#define XENIA_KERNEL_MODULES_XAM_USER_H_ +#ifndef XENIA_KERNEL_XAM_USER_H_ +#define XENIA_KERNEL_XAM_USER_H_ #include #include -#include +#include namespace xe { @@ -28,4 +28,4 @@ namespace xam { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_USER_H_ +#endif // XENIA_KERNEL_XAM_USER_H_ diff --git a/src/xenia/kernel/modules/xam/xam_video.cc b/src/xenia/kernel/xam/xam_video.cc similarity index 83% rename from src/xenia/kernel/modules/xam/xam_video.cc rename to src/xenia/kernel/xam/xam_video.cc index 40f7b165a..97e6e760a 100644 --- a/src/xenia/kernel/modules/xam/xam_video.cc +++ b/src/xenia/kernel/xam/xam_video.cc @@ -1,44 +1,44 @@ -/** - ****************************************************************************** - * 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 : 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 + #include -#include -#include - -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xam; - - +#include +#include + +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xam; + + namespace xe { namespace kernel { -namespace xam { - - -SHIM_CALL XGetVideoMode_shim( - xe_ppc_state_t* ppc_state, XamState* state) { - xe::kernel::xboxkrnl::X_VIDEO_MODE *video_mode = (xe::kernel::xboxkrnl::X_VIDEO_MODE*)SHIM_MEM_ADDR(SHIM_GET_ARG_32(0)); - xeVdQueryVideoMode(video_mode, true); -} - - -} // namespace xam -} // namespace kernel -} // namespace xe - - -void xe::kernel::xam::RegisterVideoExports( - ExportResolver* export_resolver, XamState* state) { - SHIM_SET_MAPPING("xam.xex", XGetVideoMode, state); -} +namespace xam { + + +SHIM_CALL XGetVideoMode_shim( + xe_ppc_state_t* ppc_state, XamState* state) { + xe::kernel::xboxkrnl::X_VIDEO_MODE *video_mode = (xe::kernel::xboxkrnl::X_VIDEO_MODE*)SHIM_MEM_ADDR(SHIM_GET_ARG_32(0)); + xeVdQueryVideoMode(video_mode, true); +} + + +} // namespace xam +} // namespace kernel +} // namespace xe + + +void xe::kernel::xam::RegisterVideoExports( + ExportResolver* export_resolver, XamState* state) { + SHIM_SET_MAPPING("xam.xex", XGetVideoMode, state); +} diff --git a/src/xenia/kernel/modules/xam/xam_video.h b/src/xenia/kernel/xam/xam_video.h similarity index 80% rename from src/xenia/kernel/modules/xam/xam_video.h rename to src/xenia/kernel/xam/xam_video.h index eaa300d53..a70acfb0e 100644 --- a/src/xenia/kernel/modules/xam/xam_video.h +++ b/src/xenia/kernel/xam/xam_video.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XAM_VIDEO_H_ -#define XENIA_KERNEL_MODULES_XAM_VIDEO_H_ +#ifndef XENIA_KERNEL_XAM_VIDEO_H_ +#define XENIA_KERNEL_XAM_VIDEO_H_ #include #include -#include +#include namespace xe { @@ -28,4 +28,4 @@ namespace xam { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XAM_VIDEO_H_ +#endif // XENIA_KERNEL_XAM_VIDEO_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/async_request.cc b/src/xenia/kernel/xboxkrnl/async_request.cc similarity index 85% rename from src/xenia/kernel/modules/xboxkrnl/async_request.cc rename to src/xenia/kernel/xboxkrnl/async_request.cc index 06778e364..06db3f9d0 100644 --- a/src/xenia/kernel/modules/xboxkrnl/async_request.cc +++ b/src/xenia/kernel/xboxkrnl/async_request.cc @@ -1,42 +1,42 @@ -/** - ****************************************************************************** - * 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 - -#include -#include - - -using namespace std; -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; - - -XAsyncRequest::XAsyncRequest( - KernelState* kernel_state, XObject* object, - CompletionCallback callback, void* callback_context) : - kernel_state_(kernel_state), object_(object), - callback_(callback), callback_context_(callback_context), - apc_routine_(0), apc_context_(0) { - object_->Retain(); -} - -XAsyncRequest::~XAsyncRequest() { - for (vector::iterator it = wait_events_.begin(); - it != wait_events_.end(); ++it) { - (*it)->Release(); - } - object_->Release(); -} - -void XAsyncRequest::AddWaitEvent(XEvent* ev) { - ev->Retain(); - wait_events_.push_back(ev); -} +/** + ****************************************************************************** + * 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 + +#include +#include + + +using namespace std; +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; + + +XAsyncRequest::XAsyncRequest( + KernelState* kernel_state, XObject* object, + CompletionCallback callback, void* callback_context) : + kernel_state_(kernel_state), object_(object), + callback_(callback), callback_context_(callback_context), + apc_routine_(0), apc_context_(0) { + object_->Retain(); +} + +XAsyncRequest::~XAsyncRequest() { + for (vector::iterator it = wait_events_.begin(); + it != wait_events_.end(); ++it) { + (*it)->Release(); + } + object_->Release(); +} + +void XAsyncRequest::AddWaitEvent(XEvent* ev) { + ev->Retain(); + wait_events_.push_back(ev); +} diff --git a/src/xenia/kernel/modules/xboxkrnl/async_request.h b/src/xenia/kernel/xboxkrnl/async_request.h similarity index 84% rename from src/xenia/kernel/modules/xboxkrnl/async_request.h rename to src/xenia/kernel/xboxkrnl/async_request.h index fb17306c1..23f3fea9b 100644 --- a/src/xenia/kernel/modules/xboxkrnl/async_request.h +++ b/src/xenia/kernel/xboxkrnl/async_request.h @@ -1,61 +1,61 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_ASYNC_REQUEST_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_ASYNC_REQUEST_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - -class KernelState; -class XEvent; -class XObject; - - -class XAsyncRequest { -public: - typedef void (*CompletionCallback)(XAsyncRequest* request, void* context); - - XAsyncRequest( - KernelState* kernel_state, XObject* object, - CompletionCallback callback, void* callback_context); - virtual ~XAsyncRequest(); - - KernelState* kernel_state() const { return kernel_state_; } - XObject* object() const { return object_; } - - void AddWaitEvent(XEvent* ev); - - // Complete(result) - -protected: - KernelState* kernel_state_; - XObject* object_; - CompletionCallback callback_; - void* callback_context_; - - std::vector wait_events_; - uint32_t apc_routine_; - uint32_t apc_context_; -}; - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_ASYNC_REQUEST_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_ASYNC_REQUEST_H_ +#define XENIA_KERNEL_XBOXKRNL_ASYNC_REQUEST_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + +class KernelState; +class XEvent; +class XObject; + + +class XAsyncRequest { +public: + typedef void (*CompletionCallback)(XAsyncRequest* request, void* context); + + XAsyncRequest( + KernelState* kernel_state, XObject* object, + CompletionCallback callback, void* callback_context); + virtual ~XAsyncRequest(); + + KernelState* kernel_state() const { return kernel_state_; } + XObject* object() const { return object_; } + + void AddWaitEvent(XEvent* ev); + + // Complete(result) + +protected: + KernelState* kernel_state_; + XObject* object_; + CompletionCallback callback_; + void* callback_context_; + + std::vector wait_events_; + uint32_t apc_routine_; + uint32_t apc_context_; +}; + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_ASYNC_REQUEST_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/device.cc b/src/xenia/kernel/xboxkrnl/fs/device.cc similarity index 93% rename from src/xenia/kernel/modules/xboxkrnl/fs/device.cc rename to src/xenia/kernel/xboxkrnl/fs/device.cc index e436a442e..3c6bd2cc2 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/device.cc +++ b/src/xenia/kernel/xboxkrnl/fs/device.cc @@ -7,7 +7,7 @@ ****************************************************************************** */ -#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/device.h b/src/xenia/kernel/xboxkrnl/fs/device.h similarity index 81% rename from src/xenia/kernel/modules/xboxkrnl/fs/device.h rename to src/xenia/kernel/xboxkrnl/fs/device.h index 3b13e1c96..b73f0f699 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/device.h +++ b/src/xenia/kernel/xboxkrnl/fs/device.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_DEVICE_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_DEVICE_H_ #include #include -#include +#include namespace xe { @@ -42,4 +42,4 @@ protected: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_DEVICE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_device.cc b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_device.cc similarity index 92% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_device.cc rename to src/xenia/kernel/xboxkrnl/fs/devices/disc_image_device.cc index 234e35e4b..4f4b6263c 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_device.cc +++ b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_device.cc @@ -7,10 +7,10 @@ ****************************************************************************** */ -#include +#include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_device.h b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_device.h similarity index 79% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_device.h rename to src/xenia/kernel/xboxkrnl/fs/devices/disc_image_device.h index 93e505ecd..8ac834192 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_device.h +++ b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_device.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ #include #include -#include +#include namespace xe { @@ -47,4 +47,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_DEVICE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_entry.cc b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_entry.cc similarity index 89% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_entry.cc rename to src/xenia/kernel/xboxkrnl/fs/devices/disc_image_entry.cc index 2af71c8f0..3c217daa7 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_entry.cc +++ b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_entry.cc @@ -1,89 +1,89 @@ -/** - ****************************************************************************** - * 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 - -#include -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; -using namespace xe::kernel::xboxkrnl::fs; - - -namespace { - - -class DiscImageMemoryMapping : public MemoryMapping { -public: - DiscImageMemoryMapping(uint8_t* address, size_t length, xe_mmap_ref mmap) : - MemoryMapping(address, length) { - mmap_ = xe_mmap_retain(mmap); - } - - virtual ~DiscImageMemoryMapping() { - xe_mmap_release(mmap_); - } - -private: - xe_mmap_ref mmap_; -}; - - -} - - -DiscImageEntry::DiscImageEntry(Type type, Device* device, const char* path, - xe_mmap_ref mmap, GDFXEntry* gdfx_entry) : - gdfx_entry_(gdfx_entry), - Entry(type, device, path) { - mmap_ = xe_mmap_retain(mmap); -} - -DiscImageEntry::~DiscImageEntry() { - xe_mmap_release(mmap_); -} - -X_STATUS DiscImageEntry::QueryInfo(XFileInfo* out_info) { - XEASSERTNOTNULL(out_info); - out_info->creation_time = 0; - out_info->last_access_time = 0; - out_info->last_write_time = 0; - out_info->change_time = 0; - out_info->allocation_size = 2048; - out_info->file_length = gdfx_entry_->size; - out_info->attributes = gdfx_entry_->attributes; - return X_STATUS_SUCCESS; -} - -MemoryMapping* DiscImageEntry::CreateMemoryMapping( - xe_file_mode file_mode, const size_t offset, const size_t length) { - if (file_mode & kXEFileModeWrite) { - // Only allow reads. - return NULL; - } - - size_t real_offset = gdfx_entry_->offset + offset; - size_t real_length = length ? - MIN(length, gdfx_entry_->size) : gdfx_entry_->size; - return new DiscImageMemoryMapping( - xe_mmap_get_addr(mmap_) + real_offset, - real_length, - mmap_); -} - -X_STATUS DiscImageEntry::Open( - KernelState* kernel_state, - uint32_t desired_access, bool async, - XFile** out_file) { - *out_file = new DiscImageFile(kernel_state, desired_access, this); - return X_STATUS_SUCCESS; -} +/** + ****************************************************************************** + * 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 + +#include +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; +using namespace xe::kernel::xboxkrnl::fs; + + +namespace { + + +class DiscImageMemoryMapping : public MemoryMapping { +public: + DiscImageMemoryMapping(uint8_t* address, size_t length, xe_mmap_ref mmap) : + MemoryMapping(address, length) { + mmap_ = xe_mmap_retain(mmap); + } + + virtual ~DiscImageMemoryMapping() { + xe_mmap_release(mmap_); + } + +private: + xe_mmap_ref mmap_; +}; + + +} + + +DiscImageEntry::DiscImageEntry(Type type, Device* device, const char* path, + xe_mmap_ref mmap, GDFXEntry* gdfx_entry) : + gdfx_entry_(gdfx_entry), + Entry(type, device, path) { + mmap_ = xe_mmap_retain(mmap); +} + +DiscImageEntry::~DiscImageEntry() { + xe_mmap_release(mmap_); +} + +X_STATUS DiscImageEntry::QueryInfo(XFileInfo* out_info) { + XEASSERTNOTNULL(out_info); + out_info->creation_time = 0; + out_info->last_access_time = 0; + out_info->last_write_time = 0; + out_info->change_time = 0; + out_info->allocation_size = 2048; + out_info->file_length = gdfx_entry_->size; + out_info->attributes = gdfx_entry_->attributes; + return X_STATUS_SUCCESS; +} + +MemoryMapping* DiscImageEntry::CreateMemoryMapping( + xe_file_mode file_mode, const size_t offset, const size_t length) { + if (file_mode & kXEFileModeWrite) { + // Only allow reads. + return NULL; + } + + size_t real_offset = gdfx_entry_->offset + offset; + size_t real_length = length ? + MIN(length, gdfx_entry_->size) : gdfx_entry_->size; + return new DiscImageMemoryMapping( + xe_mmap_get_addr(mmap_) + real_offset, + real_length, + mmap_); +} + +X_STATUS DiscImageEntry::Open( + KernelState* kernel_state, + uint32_t desired_access, bool async, + XFile** out_file) { + *out_file = new DiscImageFile(kernel_state, desired_access, this); + return X_STATUS_SUCCESS; +} diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_entry.h b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_entry.h similarity index 81% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_entry.h rename to src/xenia/kernel/xboxkrnl/fs/devices/disc_image_entry.h index 95ad83faf..299a33a8b 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_entry.h +++ b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_entry.h @@ -1,58 +1,58 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_ENTRY_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_ENTRY_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { -namespace fs { - -class GDFXEntry; - - -class DiscImageEntry : public Entry { -public: - DiscImageEntry(Type type, Device* device, const char* path, - xe_mmap_ref mmap, GDFXEntry* gdfx_entry); - virtual ~DiscImageEntry(); - - xe_mmap_ref mmap() const { return mmap_; } - GDFXEntry* gdfx_entry() const { return gdfx_entry_; } - - virtual X_STATUS QueryInfo(XFileInfo* out_info); - - virtual MemoryMapping* CreateMemoryMapping( - xe_file_mode file_mode, const size_t offset, const size_t length); - - virtual X_STATUS Open( - KernelState* kernel_state, - uint32_t desired_access, bool async, - XFile** out_file); - -private: - xe_mmap_ref mmap_; - GDFXEntry* gdfx_entry_; -}; - - -} // namespace fs -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_ENTRY_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_ENTRY_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_ENTRY_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { +namespace fs { + +class GDFXEntry; + + +class DiscImageEntry : public Entry { +public: + DiscImageEntry(Type type, Device* device, const char* path, + xe_mmap_ref mmap, GDFXEntry* gdfx_entry); + virtual ~DiscImageEntry(); + + xe_mmap_ref mmap() const { return mmap_; } + GDFXEntry* gdfx_entry() const { return gdfx_entry_; } + + virtual X_STATUS QueryInfo(XFileInfo* out_info); + + virtual MemoryMapping* CreateMemoryMapping( + xe_file_mode file_mode, const size_t offset, const size_t length); + + virtual X_STATUS Open( + KernelState* kernel_state, + uint32_t desired_access, bool async, + XFile** out_file); + +private: + xe_mmap_ref mmap_; + GDFXEntry* gdfx_entry_; +}; + + +} // namespace fs +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_ENTRY_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_file.cc b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_file.cc similarity index 86% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_file.cc rename to src/xenia/kernel/xboxkrnl/fs/devices/disc_image_file.cc index ccd48a6ad..1575e67a2 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_file.cc +++ b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_file.cc @@ -1,48 +1,48 @@ -/** - ****************************************************************************** - * 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 - -#include -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; -using namespace xe::kernel::xboxkrnl::fs; - - -DiscImageFile::DiscImageFile( - KernelState* kernel_state, uint32_t desired_access, - DiscImageEntry* entry) : - entry_(entry), - XFile(kernel_state, desired_access) { -} - -DiscImageFile::~DiscImageFile() { -} - -X_STATUS DiscImageFile::QueryInfo(XFileInfo* out_info) { - return entry_->QueryInfo(out_info); -} - +/** + ****************************************************************************** + * 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 + +#include +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; +using namespace xe::kernel::xboxkrnl::fs; + + +DiscImageFile::DiscImageFile( + KernelState* kernel_state, uint32_t desired_access, + DiscImageEntry* entry) : + entry_(entry), + XFile(kernel_state, desired_access) { +} + +DiscImageFile::~DiscImageFile() { +} + +X_STATUS DiscImageFile::QueryInfo(XFileInfo* out_info) { + return entry_->QueryInfo(out_info); +} + X_STATUS DiscImageFile::ReadSync( void* buffer, size_t buffer_length, size_t byte_offset, size_t* out_bytes_read) { GDFXEntry* gdfx_entry = entry_->gdfx_entry(); xe_mmap_ref mmap = entry_->mmap(); - size_t real_offset = gdfx_entry->offset + byte_offset; - size_t real_length = MIN(buffer_length, gdfx_entry->size - byte_offset); - xe_copy_memory( - buffer, buffer_length, - xe_mmap_get_addr(mmap) + real_offset, real_length); - *out_bytes_read = real_length; + size_t real_offset = gdfx_entry->offset + byte_offset; + size_t real_length = MIN(buffer_length, gdfx_entry->size - byte_offset); + xe_copy_memory( + buffer, buffer_length, + xe_mmap_get_addr(mmap) + real_offset, real_length); + *out_bytes_read = real_length; return X_STATUS_SUCCESS; } diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_file.h b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_file.h similarity index 81% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_file.h rename to src/xenia/kernel/xboxkrnl/fs/devices/disc_image_file.h index e8f6f3e19..5b77e1c3c 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/disc_image_file.h +++ b/src/xenia/kernel/xboxkrnl/fs/devices/disc_image_file.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_FILE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_FILE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_FILE_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_FILE_H_ #include #include -#include +#include namespace xe { @@ -48,4 +48,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_DISC_IMAGE_FILE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_DEVICES_DISC_IMAGE_FILE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_device.cc b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_device.cc similarity index 92% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_device.cc rename to src/xenia/kernel/xboxkrnl/fs/devices/host_path_device.cc index 769ea330d..1b334afc2 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_device.cc +++ b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_device.cc @@ -7,9 +7,9 @@ ****************************************************************************** */ -#include +#include -#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_device.h b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_device.h similarity index 78% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_device.h rename to src/xenia/kernel/xboxkrnl/fs/devices/host_path_device.h index ca2e0ea1a..20319f2f4 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_device.h +++ b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_device.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_DEVICE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_DEVICE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_DEVICE_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_DEVICE_H_ #include #include -#include +#include namespace xe { @@ -40,4 +40,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_DEVICE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_DEVICE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_entry.cc b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_entry.cc similarity index 92% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_entry.cc rename to src/xenia/kernel/xboxkrnl/fs/devices/host_path_entry.cc index 2c2320235..b0fd1c5ad 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_entry.cc +++ b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_entry.cc @@ -1,108 +1,108 @@ -/** - ****************************************************************************** - * 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 - -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; -using namespace xe::kernel::xboxkrnl::fs; - - -namespace { - - -class HostPathMemoryMapping : public MemoryMapping { -public: - HostPathMemoryMapping(uint8_t* address, size_t length, xe_mmap_ref mmap) : - MemoryMapping(address, length) { - mmap_ = xe_mmap_retain(mmap); - } - virtual ~HostPathMemoryMapping() { - xe_mmap_release(mmap_); - } -private: - xe_mmap_ref mmap_; -}; - - -} - - -HostPathEntry::HostPathEntry(Type type, Device* device, const char* path, - const xechar_t* local_path) : - Entry(type, device, path) { - local_path_ = xestrdup(local_path); -} - -HostPathEntry::~HostPathEntry() { - xe_free(local_path_); -} - -X_STATUS HostPathEntry::QueryInfo(XFileInfo* out_info) { - XEASSERTNOTNULL(out_info); - - WIN32_FILE_ATTRIBUTE_DATA data; - if (!GetFileAttributesEx( - local_path_, GetFileExInfoStandard, &data)) { - return X_STATUS_ACCESS_DENIED; - } - -#define COMBINE_TIME(t) (((uint64_t)t.dwHighDateTime << 32) | t.dwLowDateTime) - out_info->creation_time = COMBINE_TIME(data.ftCreationTime); - out_info->last_access_time = COMBINE_TIME(data.ftLastAccessTime); - out_info->last_write_time = COMBINE_TIME(data.ftLastWriteTime); - out_info->change_time = COMBINE_TIME(data.ftLastWriteTime); - out_info->allocation_size = 4096; - out_info->file_length = ((uint64_t)data.nFileSizeHigh << 32) | data.nFileSizeLow; - out_info->attributes = (X_FILE_ATTRIBUTES)data.dwFileAttributes; - return X_STATUS_SUCCESS; -} - -MemoryMapping* HostPathEntry::CreateMemoryMapping( - xe_file_mode file_mode, const size_t offset, const size_t length) { - xe_mmap_ref mmap = xe_mmap_open(file_mode, local_path_, offset, length); - if (!mmap) { - return NULL; - } - - HostPathMemoryMapping* lfmm = new HostPathMemoryMapping( - (uint8_t*)xe_mmap_get_addr(mmap), xe_mmap_get_length(mmap), - mmap); - xe_mmap_release(mmap); - - return lfmm; -} - -X_STATUS HostPathEntry::Open( - KernelState* kernel_state, - uint32_t desired_access, bool async, - XFile** out_file) { - DWORD share_mode = FILE_SHARE_READ; - DWORD creation_disposition = OPEN_EXISTING; - DWORD flags_and_attributes = async ? FILE_FLAG_OVERLAPPED : 0; - HANDLE file = CreateFile( - local_path_, - desired_access, - share_mode, - NULL, - creation_disposition, - flags_and_attributes, - NULL); - if (!file) { - // TODO(benvanik): pick correct response. - return X_STATUS_ACCESS_DENIED; - } - - *out_file = new HostPathFile(kernel_state, desired_access, this, file); - return X_STATUS_SUCCESS; -} +/** + ****************************************************************************** + * 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 + +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; +using namespace xe::kernel::xboxkrnl::fs; + + +namespace { + + +class HostPathMemoryMapping : public MemoryMapping { +public: + HostPathMemoryMapping(uint8_t* address, size_t length, xe_mmap_ref mmap) : + MemoryMapping(address, length) { + mmap_ = xe_mmap_retain(mmap); + } + virtual ~HostPathMemoryMapping() { + xe_mmap_release(mmap_); + } +private: + xe_mmap_ref mmap_; +}; + + +} + + +HostPathEntry::HostPathEntry(Type type, Device* device, const char* path, + const xechar_t* local_path) : + Entry(type, device, path) { + local_path_ = xestrdup(local_path); +} + +HostPathEntry::~HostPathEntry() { + xe_free(local_path_); +} + +X_STATUS HostPathEntry::QueryInfo(XFileInfo* out_info) { + XEASSERTNOTNULL(out_info); + + WIN32_FILE_ATTRIBUTE_DATA data; + if (!GetFileAttributesEx( + local_path_, GetFileExInfoStandard, &data)) { + return X_STATUS_ACCESS_DENIED; + } + +#define COMBINE_TIME(t) (((uint64_t)t.dwHighDateTime << 32) | t.dwLowDateTime) + out_info->creation_time = COMBINE_TIME(data.ftCreationTime); + out_info->last_access_time = COMBINE_TIME(data.ftLastAccessTime); + out_info->last_write_time = COMBINE_TIME(data.ftLastWriteTime); + out_info->change_time = COMBINE_TIME(data.ftLastWriteTime); + out_info->allocation_size = 4096; + out_info->file_length = ((uint64_t)data.nFileSizeHigh << 32) | data.nFileSizeLow; + out_info->attributes = (X_FILE_ATTRIBUTES)data.dwFileAttributes; + return X_STATUS_SUCCESS; +} + +MemoryMapping* HostPathEntry::CreateMemoryMapping( + xe_file_mode file_mode, const size_t offset, const size_t length) { + xe_mmap_ref mmap = xe_mmap_open(file_mode, local_path_, offset, length); + if (!mmap) { + return NULL; + } + + HostPathMemoryMapping* lfmm = new HostPathMemoryMapping( + (uint8_t*)xe_mmap_get_addr(mmap), xe_mmap_get_length(mmap), + mmap); + xe_mmap_release(mmap); + + return lfmm; +} + +X_STATUS HostPathEntry::Open( + KernelState* kernel_state, + uint32_t desired_access, bool async, + XFile** out_file) { + DWORD share_mode = FILE_SHARE_READ; + DWORD creation_disposition = OPEN_EXISTING; + DWORD flags_and_attributes = async ? FILE_FLAG_OVERLAPPED : 0; + HANDLE file = CreateFile( + local_path_, + desired_access, + share_mode, + NULL, + creation_disposition, + flags_and_attributes, + NULL); + if (!file) { + // TODO(benvanik): pick correct response. + return X_STATUS_ACCESS_DENIED; + } + + *out_file = new HostPathFile(kernel_state, desired_access, this, file); + return X_STATUS_SUCCESS; +} diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_entry.h b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_entry.h similarity index 80% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_entry.h rename to src/xenia/kernel/xboxkrnl/fs/devices/host_path_entry.h index ab77a4ccc..2cdc5aec0 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_entry.h +++ b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_entry.h @@ -1,54 +1,54 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_ENTRY_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_ENTRY_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { -namespace fs { - - -class HostPathEntry : public Entry { -public: - HostPathEntry(Type type, Device* device, const char* path, - const xechar_t* local_path); - virtual ~HostPathEntry(); - - const xechar_t* local_path() { return local_path_; } - - virtual X_STATUS QueryInfo(XFileInfo* out_info); - - virtual MemoryMapping* CreateMemoryMapping( - xe_file_mode file_mode, const size_t offset, const size_t length); - - virtual X_STATUS Open( - KernelState* kernel_state, - uint32_t desired_access, bool async, - XFile** out_file); - -private: - xechar_t* local_path_; -}; - - -} // namespace fs -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_ENTRY_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_ENTRY_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_ENTRY_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { +namespace fs { + + +class HostPathEntry : public Entry { +public: + HostPathEntry(Type type, Device* device, const char* path, + const xechar_t* local_path); + virtual ~HostPathEntry(); + + const xechar_t* local_path() { return local_path_; } + + virtual X_STATUS QueryInfo(XFileInfo* out_info); + + virtual MemoryMapping* CreateMemoryMapping( + xe_file_mode file_mode, const size_t offset, const size_t length); + + virtual X_STATUS Open( + KernelState* kernel_state, + uint32_t desired_access, bool async, + XFile** out_file); + +private: + xechar_t* local_path_; +}; + + +} // namespace fs +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_ENTRY_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_file.cc b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_file.cc similarity index 89% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_file.cc rename to src/xenia/kernel/xboxkrnl/fs/devices/host_path_file.cc index d0e391f9f..850b73103 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_file.cc +++ b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_file.cc @@ -1,38 +1,38 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#include - -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; -using namespace xe::kernel::xboxkrnl::fs; - - -HostPathFile::HostPathFile( - KernelState* kernel_state, uint32_t desired_access, - HostPathEntry* entry, HANDLE file_handle) : - entry_(entry), file_handle_(file_handle), - XFile(kernel_state, desired_access) { -} - -HostPathFile::~HostPathFile() { - CloseHandle(file_handle_); -} - -X_STATUS HostPathFile::QueryInfo(XFileInfo* out_info) { - return entry_->QueryInfo(out_info); -} - +/** + ****************************************************************************** + * 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 + +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; +using namespace xe::kernel::xboxkrnl::fs; + + +HostPathFile::HostPathFile( + KernelState* kernel_state, uint32_t desired_access, + HostPathEntry* entry, HANDLE file_handle) : + entry_(entry), file_handle_(file_handle), + XFile(kernel_state, desired_access) { +} + +HostPathFile::~HostPathFile() { + CloseHandle(file_handle_); +} + +X_STATUS HostPathFile::QueryInfo(XFileInfo* out_info) { + return entry_->QueryInfo(out_info); +} + X_STATUS HostPathFile::ReadSync( void* buffer, size_t buffer_length, size_t byte_offset, size_t* out_bytes_read) { diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_file.h b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_file.h similarity index 81% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_file.h rename to src/xenia/kernel/xboxkrnl/fs/devices/host_path_file.h index 70193bee1..8de3e7786 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/devices/host_path_file.h +++ b/src/xenia/kernel/xboxkrnl/fs/devices/host_path_file.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_FILE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_FILE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_FILE_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_FILE_H_ #include #include -#include +#include namespace xe { @@ -49,4 +49,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_DEVICES_HOST_PATH_FILE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_DEVICES_HOST_PATH_FILE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/devices/sources.gypi b/src/xenia/kernel/xboxkrnl/fs/devices/sources.gypi similarity index 100% rename from src/xenia/kernel/modules/xboxkrnl/fs/devices/sources.gypi rename to src/xenia/kernel/xboxkrnl/fs/devices/sources.gypi diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/entry.cc b/src/xenia/kernel/xboxkrnl/fs/entry.cc similarity index 95% rename from src/xenia/kernel/modules/xboxkrnl/fs/entry.cc rename to src/xenia/kernel/xboxkrnl/fs/entry.cc index 48610c2fc..e5341eed9 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/entry.cc +++ b/src/xenia/kernel/xboxkrnl/fs/entry.cc @@ -7,7 +7,7 @@ ****************************************************************************** */ -#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/entry.h b/src/xenia/kernel/xboxkrnl/fs/entry.h similarity index 84% rename from src/xenia/kernel/modules/xboxkrnl/fs/entry.h rename to src/xenia/kernel/xboxkrnl/fs/entry.h index 6602fac38..50d1869ce 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/entry.h +++ b/src/xenia/kernel/xboxkrnl/fs/entry.h @@ -7,21 +7,23 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_ENTRY_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_ENTRY_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_ENTRY_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_ENTRY_H_ #include #include -#include +#include + + +XEDECLARECLASS3(xe, kernel, xboxkrnl, KernelState); +XEDECLARECLASS3(xe, kernel, xboxkrnl, XFile); +XEDECLARECLASS3(xe, kernel, xboxkrnl, XFileInfo); namespace xe { namespace kernel { namespace xboxkrnl { -class KernelState; -class XFile; -class XFileInfo; namespace fs { class Device; @@ -62,7 +64,7 @@ public: xe_file_mode file_mode, const size_t offset, const size_t length) = 0; virtual X_STATUS Open( - KernelState* kernel_state, + KernelState* kernel_state, uint32_t desired_access, bool async, XFile** out_file) = 0; @@ -80,4 +82,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_ENTRY_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_ENTRY_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/filesystem.cc b/src/xenia/kernel/xboxkrnl/fs/filesystem.cc similarity index 94% rename from src/xenia/kernel/modules/xboxkrnl/fs/filesystem.cc rename to src/xenia/kernel/xboxkrnl/fs/filesystem.cc index 53e2d7a85..72e5bd08b 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/filesystem.cc +++ b/src/xenia/kernel/xboxkrnl/fs/filesystem.cc @@ -7,10 +7,10 @@ ****************************************************************************** */ -#include +#include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/filesystem.h b/src/xenia/kernel/xboxkrnl/fs/filesystem.h similarity index 85% rename from src/xenia/kernel/modules/xboxkrnl/fs/filesystem.h rename to src/xenia/kernel/xboxkrnl/fs/filesystem.h index 7c37db1b2..98f96c6ba 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/filesystem.h +++ b/src/xenia/kernel/xboxkrnl/fs/filesystem.h @@ -7,15 +7,15 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_FILESYSTEM_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_FILESYSTEM_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_FILESYSTEM_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_FILESYSTEM_H_ #include #include #include -#include +#include namespace xe { @@ -53,4 +53,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_FILESYSTEM_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_FILESYSTEM_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/gdfx.cc b/src/xenia/kernel/xboxkrnl/fs/gdfx.cc similarity index 99% rename from src/xenia/kernel/modules/xboxkrnl/fs/gdfx.cc rename to src/xenia/kernel/xboxkrnl/fs/gdfx.cc index 1572ef382..b19e349cf 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/gdfx.cc +++ b/src/xenia/kernel/xboxkrnl/fs/gdfx.cc @@ -9,7 +9,7 @@ * - abgx360 */ -#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/gdfx.h b/src/xenia/kernel/xboxkrnl/fs/gdfx.h similarity index 89% rename from src/xenia/kernel/modules/xboxkrnl/fs/gdfx.h rename to src/xenia/kernel/xboxkrnl/fs/gdfx.h index beb76ef86..227e978c7 100644 --- a/src/xenia/kernel/modules/xboxkrnl/fs/gdfx.h +++ b/src/xenia/kernel/xboxkrnl/fs/gdfx.h @@ -7,16 +7,16 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_FS_GDFX_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_FS_GDFX_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_FS_GDFX_H_ +#define XENIA_KERNEL_XBOXKRNL_FS_GDFX_H_ #include #include #include -#include -#include +#include +#include namespace xe { @@ -95,4 +95,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_FS_GDFX_H_ +#endif // XENIA_KERNEL_XBOXKRNL_FS_GDFX_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/fs/sources.gypi b/src/xenia/kernel/xboxkrnl/fs/sources.gypi similarity index 100% rename from src/xenia/kernel/modules/xboxkrnl/fs/sources.gypi rename to src/xenia/kernel/xboxkrnl/fs/sources.gypi diff --git a/src/xenia/kernel/modules/xboxkrnl/kernel_state.cc b/src/xenia/kernel/xboxkrnl/kernel_state.cc similarity index 63% rename from src/xenia/kernel/modules/xboxkrnl/kernel_state.cc rename to src/xenia/kernel/xboxkrnl/kernel_state.cc index 2a7fd5361..b1b5de572 100644 --- a/src/xenia/kernel/modules/xboxkrnl/kernel_state.cc +++ b/src/xenia/kernel/xboxkrnl/kernel_state.cc @@ -7,13 +7,13 @@ ****************************************************************************** */ -#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace xe; @@ -21,17 +21,12 @@ using namespace xe::kernel; using namespace xe::kernel::xboxkrnl; -namespace { - -} - - -KernelState::KernelState(Runtime* runtime) : - runtime_(runtime), +KernelState::KernelState(Emulator* emulator) : + emulator_(emulator), executable_module_(NULL) { - memory_ = runtime->memory(); - processor_ = runtime->processor(); - filesystem_ = runtime->filesystem(); + memory_ = xe_memory_retain(emulator->memory()); + processor_ = emulator->processor(); + file_system_ = emulator->file_system(); object_table_ = new ObjectTable(); object_mutex_ = xe_mutex_alloc(10000); @@ -44,8 +39,6 @@ KernelState::~KernelState() { xe_mutex_free(object_mutex_); delete object_table_; - filesystem_.reset(); - processor_.reset(); xe_memory_release(memory_); } @@ -53,26 +46,6 @@ KernelState* KernelState::shared() { return shared_kernel_state_; } -Runtime* KernelState::runtime() { - return runtime_; -} - -xe_memory_ref KernelState::memory() { - return memory_; -} - -cpu::Processor* KernelState::processor() { - return processor_.get(); -} - -fs::FileSystem* KernelState::filesystem() { - return filesystem_.get(); -} - -ObjectTable* KernelState::object_table() const { - return object_table_; -} - XModule* KernelState::GetModule(const char* name) { // TODO(benvanik): implement lookup. Most games seem to look for xam.xex/etc. XEASSERTALWAYS(); diff --git a/src/xenia/kernel/xboxkrnl/kernel_state.h b/src/xenia/kernel/xboxkrnl/kernel_state.h new file mode 100644 index 000000000..5b0a01f08 --- /dev/null +++ b/src/xenia/kernel/xboxkrnl/kernel_state.h @@ -0,0 +1,71 @@ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_KERNEL_STATE_H_ +#define XENIA_KERNEL_XBOXKRNL_KERNEL_STATE_H_ + +#include +#include + +#include +#include +#include +#include +#include + + +XEDECLARECLASS2(xe, cpu, Processor); +XEDECLARECLASS3(xe, kernel, fs, FileSystem); +XEDECLARECLASS3(xe, kernel, xboxkrnl, XModule); + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +class KernelState { +public: + KernelState(Emulator* emulator); + ~KernelState(); + + static KernelState* shared(); + + Emulator* emulator() const { return emulator_; } + xe_memory_ref memory() const { return memory_; } + cpu::Processor* processor() const { return processor_; } + fs::FileSystem* file_system() const { return file_system_; } + + ObjectTable* object_table() const { return object_table_; } + + XModule* GetModule(const char* name); + XModule* GetExecutableModule(); + void SetExecutableModule(XModule* module); + +private: + Emulator* emulator_; + xe_memory_ref memory_; + cpu::Processor* processor_; + fs::FileSystem* file_system_; + + ObjectTable* object_table_; + xe_mutex_t* object_mutex_; + + XModule* executable_module_; + + friend class XObject; +}; + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_KERNEL_STATE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/object_table.cc b/src/xenia/kernel/xboxkrnl/object_table.cc similarity index 92% rename from src/xenia/kernel/modules/xboxkrnl/object_table.cc rename to src/xenia/kernel/xboxkrnl/object_table.cc index ebb8ac9ac..9df618e7d 100644 --- a/src/xenia/kernel/modules/xboxkrnl/object_table.cc +++ b/src/xenia/kernel/xboxkrnl/object_table.cc @@ -1,194 +1,194 @@ -/** - ****************************************************************************** - * 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 - -#include -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; - - -ObjectTable::ObjectTable() : - table_capacity_(0), - table_(NULL), - last_free_entry_(0) { - table_mutex_ = xe_mutex_alloc(0); - XEASSERTNOTNULL(table_mutex_); -} - -ObjectTable::~ObjectTable() { - xe_mutex_lock(table_mutex_); - - // Release all objects. - for (uint32_t n = 0; n < table_capacity_; n++) { - ObjectTableEntry& entry = table_[n]; - if (entry.object) { - entry.object->ReleaseHandle(); - entry.object->Release(); - } - } - - table_capacity_ = 0; - last_free_entry_ = 0; - xe_free(table_); - table_ = NULL; - - xe_mutex_unlock(table_mutex_); - - xe_mutex_free(table_mutex_); - table_mutex_ = NULL; -} - -X_STATUS ObjectTable::FindFreeSlot(uint32_t* out_slot) { - // Find a free slot. - uint32_t slot = last_free_entry_; - uint32_t scan_count = 0; - while (scan_count < table_capacity_) { - ObjectTableEntry& entry = table_[slot]; - if (!entry.object) { - *out_slot = slot; - return X_STATUS_SUCCESS; - } - scan_count++; - slot = (slot + 1) % table_capacity_; - if (slot == 0) { - // Never allow 0 handles. - scan_count++; - slot++; - } - } - - // Table out of slots, expand. - uint32_t new_table_capacity = MAX(16 * 1024, table_capacity_ * 2); - ObjectTableEntry* new_table = (ObjectTableEntry*)xe_recalloc( - table_, - table_capacity_ * sizeof(ObjectTableEntry), - new_table_capacity * sizeof(ObjectTableEntry)); - if (!new_table) { - return X_STATUS_NO_MEMORY; - } - last_free_entry_ = table_capacity_; - table_capacity_ = new_table_capacity; - table_ = new_table; - - // Never allow 0 handles. - slot = ++last_free_entry_; - *out_slot = slot; - - return X_STATUS_SUCCESS; -} - -X_STATUS ObjectTable::AddHandle(XObject* object, X_HANDLE* out_handle) { - XEASSERTNOTNULL(out_handle); - - X_STATUS result = X_STATUS_SUCCESS; - - xe_mutex_lock(table_mutex_); - - // Find a free slot. - uint32_t slot = 0; - result = FindFreeSlot(&slot); - - // Stash. - if (XSUCCEEDED(result)) { - ObjectTableEntry& entry = table_[slot]; - entry.object = object; - - // Retain so long as the object is in the table. - object->RetainHandle(); - object->Retain(); - } - - xe_mutex_unlock(table_mutex_); - - if (XSUCCEEDED(result)) { - *out_handle = slot << 2; - } - - return result; -} - -X_STATUS ObjectTable::RemoveHandle(X_HANDLE handle) { - X_STATUS result = X_STATUS_SUCCESS; - - xe_mutex_lock(table_mutex_); - - // Lower 2 bits are ignored. - uint32_t slot = handle >> 2; - - // Verify slot. - XObject* object = NULL; - if (slot > table_capacity_) { - result = X_STATUS_INVALID_HANDLE; - } else { - ObjectTableEntry& entry = table_[slot]; - if (entry.object) { - // Release after we lose the lock. - object = entry.object; - } else { - result = X_STATUS_INVALID_HANDLE; - } - } - - xe_mutex_unlock(table_mutex_); - - if (object) { - // Release the object handle now that it is out of the table. - object->ReleaseHandle(); - object->Release(); - } - - return result; -} - -X_STATUS ObjectTable::GetObject(X_HANDLE handle, XObject** out_object) { - XEASSERTNOTNULL(out_object); - - X_STATUS result = X_STATUS_SUCCESS; - - if (handle == 0xFFFFFFFF) { - // CurrentProcess - XEASSERTALWAYS(); - } else if (handle == 0xFFFFFFFE) { - // CurrentThread - handle = XThread::GetCurrentThreadHandle(); - } - - xe_mutex_lock(table_mutex_); - - // Lower 2 bits are ignored. - uint32_t slot = handle >> 2; - - // Verify slot. - XObject* object = NULL; - if (slot > table_capacity_) { - result = X_STATUS_INVALID_HANDLE; - } else { - ObjectTableEntry& entry = table_[slot]; - if (entry.object) { - object = entry.object; - } else { - result = X_STATUS_INVALID_HANDLE; - } - } - - // Retain the object pointer. - if (object) { - object->Retain(); - } - - xe_mutex_unlock(table_mutex_); - - *out_object = object; - return result; -} +/** + ****************************************************************************** + * 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 + +#include +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; + + +ObjectTable::ObjectTable() : + table_capacity_(0), + table_(NULL), + last_free_entry_(0) { + table_mutex_ = xe_mutex_alloc(0); + XEASSERTNOTNULL(table_mutex_); +} + +ObjectTable::~ObjectTable() { + xe_mutex_lock(table_mutex_); + + // Release all objects. + for (uint32_t n = 0; n < table_capacity_; n++) { + ObjectTableEntry& entry = table_[n]; + if (entry.object) { + entry.object->ReleaseHandle(); + entry.object->Release(); + } + } + + table_capacity_ = 0; + last_free_entry_ = 0; + xe_free(table_); + table_ = NULL; + + xe_mutex_unlock(table_mutex_); + + xe_mutex_free(table_mutex_); + table_mutex_ = NULL; +} + +X_STATUS ObjectTable::FindFreeSlot(uint32_t* out_slot) { + // Find a free slot. + uint32_t slot = last_free_entry_; + uint32_t scan_count = 0; + while (scan_count < table_capacity_) { + ObjectTableEntry& entry = table_[slot]; + if (!entry.object) { + *out_slot = slot; + return X_STATUS_SUCCESS; + } + scan_count++; + slot = (slot + 1) % table_capacity_; + if (slot == 0) { + // Never allow 0 handles. + scan_count++; + slot++; + } + } + + // Table out of slots, expand. + uint32_t new_table_capacity = MAX(16 * 1024, table_capacity_ * 2); + ObjectTableEntry* new_table = (ObjectTableEntry*)xe_recalloc( + table_, + table_capacity_ * sizeof(ObjectTableEntry), + new_table_capacity * sizeof(ObjectTableEntry)); + if (!new_table) { + return X_STATUS_NO_MEMORY; + } + last_free_entry_ = table_capacity_; + table_capacity_ = new_table_capacity; + table_ = new_table; + + // Never allow 0 handles. + slot = ++last_free_entry_; + *out_slot = slot; + + return X_STATUS_SUCCESS; +} + +X_STATUS ObjectTable::AddHandle(XObject* object, X_HANDLE* out_handle) { + XEASSERTNOTNULL(out_handle); + + X_STATUS result = X_STATUS_SUCCESS; + + xe_mutex_lock(table_mutex_); + + // Find a free slot. + uint32_t slot = 0; + result = FindFreeSlot(&slot); + + // Stash. + if (XSUCCEEDED(result)) { + ObjectTableEntry& entry = table_[slot]; + entry.object = object; + + // Retain so long as the object is in the table. + object->RetainHandle(); + object->Retain(); + } + + xe_mutex_unlock(table_mutex_); + + if (XSUCCEEDED(result)) { + *out_handle = slot << 2; + } + + return result; +} + +X_STATUS ObjectTable::RemoveHandle(X_HANDLE handle) { + X_STATUS result = X_STATUS_SUCCESS; + + xe_mutex_lock(table_mutex_); + + // Lower 2 bits are ignored. + uint32_t slot = handle >> 2; + + // Verify slot. + XObject* object = NULL; + if (slot > table_capacity_) { + result = X_STATUS_INVALID_HANDLE; + } else { + ObjectTableEntry& entry = table_[slot]; + if (entry.object) { + // Release after we lose the lock. + object = entry.object; + } else { + result = X_STATUS_INVALID_HANDLE; + } + } + + xe_mutex_unlock(table_mutex_); + + if (object) { + // Release the object handle now that it is out of the table. + object->ReleaseHandle(); + object->Release(); + } + + return result; +} + +X_STATUS ObjectTable::GetObject(X_HANDLE handle, XObject** out_object) { + XEASSERTNOTNULL(out_object); + + X_STATUS result = X_STATUS_SUCCESS; + + if (handle == 0xFFFFFFFF) { + // CurrentProcess + XEASSERTALWAYS(); + } else if (handle == 0xFFFFFFFE) { + // CurrentThread + handle = XThread::GetCurrentThreadHandle(); + } + + xe_mutex_lock(table_mutex_); + + // Lower 2 bits are ignored. + uint32_t slot = handle >> 2; + + // Verify slot. + XObject* object = NULL; + if (slot > table_capacity_) { + result = X_STATUS_INVALID_HANDLE; + } else { + ObjectTableEntry& entry = table_[slot]; + if (entry.object) { + object = entry.object; + } else { + result = X_STATUS_INVALID_HANDLE; + } + } + + // Retain the object pointer. + if (object) { + object->Retain(); + } + + xe_mutex_unlock(table_mutex_); + + *out_object = object; + return result; +} diff --git a/src/xenia/kernel/modules/xboxkrnl/object_table.h b/src/xenia/kernel/xboxkrnl/object_table.h similarity index 82% rename from src/xenia/kernel/modules/xboxkrnl/object_table.h rename to src/xenia/kernel/xboxkrnl/object_table.h index e34e52631..7082c754e 100644 --- a/src/xenia/kernel/modules/xboxkrnl/object_table.h +++ b/src/xenia/kernel/xboxkrnl/object_table.h @@ -1,55 +1,55 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_OBJECT_TABLE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_OBJECT_TABLE_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - - -class XObject; - - -class ObjectTable { -public: - ObjectTable(); - ~ObjectTable(); - - X_STATUS AddHandle(XObject* object, X_HANDLE* out_handle); - X_STATUS RemoveHandle(X_HANDLE handle); - X_STATUS GetObject(X_HANDLE handle, XObject** out_object); - -private: - X_STATUS FindFreeSlot(uint32_t* out_slot); - - typedef struct { - XObject* object; - } ObjectTableEntry; - - xe_mutex_t* table_mutex_; - uint32_t table_capacity_; - ObjectTableEntry* table_; - uint32_t last_free_entry_; -}; - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_OBJECT_TABLE_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_OBJECT_TABLE_H_ +#define XENIA_KERNEL_XBOXKRNL_OBJECT_TABLE_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +class XObject; + + +class ObjectTable { +public: + ObjectTable(); + ~ObjectTable(); + + X_STATUS AddHandle(XObject* object, X_HANDLE* out_handle); + X_STATUS RemoveHandle(X_HANDLE handle); + X_STATUS GetObject(X_HANDLE handle, XObject** out_object); + +private: + X_STATUS FindFreeSlot(uint32_t* out_slot); + + typedef struct { + XObject* object; + } ObjectTableEntry; + + xe_mutex_t* table_mutex_; + uint32_t table_capacity_; + ObjectTableEntry* table_; + uint32_t last_free_entry_; +}; + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_OBJECT_TABLE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/sources.gypi b/src/xenia/kernel/xboxkrnl/objects/sources.gypi similarity index 100% rename from src/xenia/kernel/modules/xboxkrnl/objects/sources.gypi rename to src/xenia/kernel/xboxkrnl/objects/sources.gypi diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xevent.cc b/src/xenia/kernel/xboxkrnl/objects/xevent.cc similarity index 95% rename from src/xenia/kernel/modules/xboxkrnl/objects/xevent.cc rename to src/xenia/kernel/xboxkrnl/objects/xevent.cc index 17ba5cfd0..e099da7ab 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xevent.cc +++ b/src/xenia/kernel/xboxkrnl/objects/xevent.cc @@ -1,67 +1,67 @@ -/** - ****************************************************************************** - * 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 - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; - - -XEvent::XEvent(KernelState* kernel_state) : - XObject(kernel_state, kTypeEvent), - handle_(NULL) { -} - -XEvent::~XEvent() { -} - -void XEvent::Initialize(bool manual_reset, bool initial_state) { - XEASSERTNULL(handle_); - - handle_ = CreateEvent(NULL, manual_reset, initial_state, NULL); -} - -void XEvent::InitializeNative(void* native_ptr, DISPATCH_HEADER& header) { - XEASSERTNULL(handle_); - - bool manual_reset; - switch (header.type_flags >> 24) { - case 0x00: // EventNotificationObject (manual reset) - manual_reset = true; - break; - case 0x01: // EventSynchronizationObject (auto reset) - manual_reset = false; - break; - default: - XEASSERTALWAYS(); - return; - } - - bool initial_state = header.signal_state ? true : false; - - handle_ = CreateEvent(NULL, manual_reset, initial_state, NULL); -} - -int32_t XEvent::Set(uint32_t priority_increment, bool wait) { - return SetEvent(handle_) ? 1 : 0; -} - -int32_t XEvent::Reset() { - return ResetEvent(handle_) ? 1 : 0; -} - -void XEvent::Clear() { - ResetEvent(handle_); -} - +/** + ****************************************************************************** + * 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 + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; + + +XEvent::XEvent(KernelState* kernel_state) : + XObject(kernel_state, kTypeEvent), + handle_(NULL) { +} + +XEvent::~XEvent() { +} + +void XEvent::Initialize(bool manual_reset, bool initial_state) { + XEASSERTNULL(handle_); + + handle_ = CreateEvent(NULL, manual_reset, initial_state, NULL); +} + +void XEvent::InitializeNative(void* native_ptr, DISPATCH_HEADER& header) { + XEASSERTNULL(handle_); + + bool manual_reset; + switch (header.type_flags >> 24) { + case 0x00: // EventNotificationObject (manual reset) + manual_reset = true; + break; + case 0x01: // EventSynchronizationObject (auto reset) + manual_reset = false; + break; + default: + XEASSERTALWAYS(); + return; + } + + bool initial_state = header.signal_state ? true : false; + + handle_ = CreateEvent(NULL, manual_reset, initial_state, NULL); +} + +int32_t XEvent::Set(uint32_t priority_increment, bool wait) { + return SetEvent(handle_) ? 1 : 0; +} + +int32_t XEvent::Reset() { + return ResetEvent(handle_) ? 1 : 0; +} + +void XEvent::Clear() { + ResetEvent(handle_); +} + X_STATUS XEvent::Wait(uint32_t wait_reason, uint32_t processor_mode, uint32_t alertable, uint64_t* opt_timeout) { DWORD timeout_ms; @@ -96,4 +96,4 @@ X_STATUS XEvent::Wait(uint32_t wait_reason, uint32_t processor_mode, case WAIT_ABANDONED: return X_STATUS_ABANDONED_WAIT_0; } -} \ No newline at end of file +} diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xevent.h b/src/xenia/kernel/xboxkrnl/objects/xevent.h similarity index 80% rename from src/xenia/kernel/modules/xboxkrnl/objects/xevent.h rename to src/xenia/kernel/xboxkrnl/objects/xevent.h index 1e2e112d8..ec45d2352 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xevent.h +++ b/src/xenia/kernel/xboxkrnl/objects/xevent.h @@ -1,48 +1,48 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_XEVENT_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_XEVENT_H_ - -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - - -class XEvent : public XObject { -public: - XEvent(KernelState* kernel_state); - virtual ~XEvent(); - - void Initialize(bool manual_reset, bool initial_state); - void InitializeNative(void* native_ptr, DISPATCH_HEADER& header); - - int32_t Set(uint32_t priority_increment, bool wait); - int32_t Reset(); - void Clear(); - +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_XEVENT_H_ +#define XENIA_KERNEL_XBOXKRNL_XEVENT_H_ + +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +class XEvent : public XObject { +public: + XEvent(KernelState* kernel_state); + virtual ~XEvent(); + + void Initialize(bool manual_reset, bool initial_state); + void InitializeNative(void* native_ptr, DISPATCH_HEADER& header); + + int32_t Set(uint32_t priority_increment, bool wait); + int32_t Reset(); + void Clear(); + virtual X_STATUS Wait(uint32_t wait_reason, uint32_t processor_mode, - uint32_t alertable, uint64_t* opt_timeout); - -private: - HANDLE handle_; -}; - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_XEVENT_H_ + uint32_t alertable, uint64_t* opt_timeout); + +private: + HANDLE handle_; +}; + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_XEVENT_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xfile.cc b/src/xenia/kernel/xboxkrnl/objects/xfile.cc similarity index 92% rename from src/xenia/kernel/modules/xboxkrnl/objects/xfile.cc rename to src/xenia/kernel/xboxkrnl/objects/xfile.cc index ee4484994..f508273f4 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xfile.cc +++ b/src/xenia/kernel/xboxkrnl/objects/xfile.cc @@ -7,10 +7,10 @@ ****************************************************************************** */ -#include +#include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xfile.h b/src/xenia/kernel/xboxkrnl/objects/xfile.h similarity index 91% rename from src/xenia/kernel/modules/xboxkrnl/objects/xfile.h rename to src/xenia/kernel/xboxkrnl/objects/xfile.h index 55bb806d4..3dfd4ad93 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xfile.h +++ b/src/xenia/kernel/xboxkrnl/objects/xfile.h @@ -7,12 +7,12 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_XFILE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_XFILE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_XFILE_H_ +#define XENIA_KERNEL_XBOXKRNL_XFILE_H_ -#include +#include -#include +#include namespace xe { @@ -84,4 +84,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_XFILE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_XFILE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.cc b/src/xenia/kernel/xboxkrnl/objects/xmodule.cc similarity index 97% rename from src/xenia/kernel/modules/xboxkrnl/objects/xmodule.cc rename to src/xenia/kernel/xboxkrnl/objects/xmodule.cc index c7c4100e1..818f733f6 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.cc +++ b/src/xenia/kernel/xboxkrnl/objects/xmodule.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include +#include #include -#include -#include +#include using namespace xe; @@ -59,7 +59,7 @@ const xe_xex2_header_t* XModule::xex_header() { X_STATUS XModule::LoadFromFile(const char* path) { // Resolve the file to open. // TODO(benvanik): make this code shared? - fs::Entry* fs_entry = kernel_state()->filesystem()->ResolvePath(path); + fs::Entry* fs_entry = kernel_state()->file_system()->ResolvePath(path); if (!fs_entry) { XELOGE("File not found: %s", path); return X_STATUS_NO_SUCH_FILE; @@ -152,7 +152,8 @@ X_STATUS XModule::Launch(uint32_t flags) { } void XModule::Dump() { - ExportResolver* export_resolver = runtime()->export_resolver().get(); + ExportResolver* export_resolver = + kernel_state_->emulator()->export_resolver(); const xe_xex2_header_t* header = xe_xex2_get_header(xex_); // XEX info. diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.h b/src/xenia/kernel/xboxkrnl/objects/xmodule.h similarity index 83% rename from src/xenia/kernel/modules/xboxkrnl/objects/xmodule.h rename to src/xenia/kernel/xboxkrnl/objects/xmodule.h index 197a98a95..505304d50 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xmodule.h +++ b/src/xenia/kernel/xboxkrnl/objects/xmodule.h @@ -7,15 +7,15 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_XMODULE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_XMODULE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_XMODULE_H_ +#define XENIA_KERNEL_XBOXKRNL_XMODULE_H_ -#include +#include #include -#include -#include +#include +#include #include @@ -59,4 +59,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_XMODULE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_XMODULE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc b/src/xenia/kernel/xboxkrnl/objects/xthread.cc similarity index 97% rename from src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc rename to src/xenia/kernel/xboxkrnl/objects/xthread.cc index 2a772a8de..56595b7af 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.cc +++ b/src/xenia/kernel/xboxkrnl/objects/xthread.cc @@ -7,12 +7,12 @@ ****************************************************************************** */ -#include +#include #include -#include -#include -#include +#include +#include +#include using namespace xe; @@ -192,7 +192,7 @@ X_STATUS XThread::Create() { X_STATUS XThread::Exit(int exit_code) { // TODO(benvanik): set exit code in thread state block - + // TODO(benvanik); dispatch events? waiters? etc? event_->Set(0, false); diff --git a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.h b/src/xenia/kernel/xboxkrnl/objects/xthread.h similarity index 90% rename from src/xenia/kernel/modules/xboxkrnl/objects/xthread.h rename to src/xenia/kernel/xboxkrnl/objects/xthread.h index 17359a966..8d856458b 100644 --- a/src/xenia/kernel/modules/xboxkrnl/objects/xthread.h +++ b/src/xenia/kernel/xboxkrnl/objects/xthread.h @@ -7,12 +7,12 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_XTHREAD_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_XTHREAD_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_XTHREAD_H_ +#define XENIA_KERNEL_XBOXKRNL_XTHREAD_H_ -#include +#include -#include +#include namespace xe { @@ -94,4 +94,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_XTHREAD_H_ +#endif // XENIA_KERNEL_XBOXKRNL_XTHREAD_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/sources.gypi b/src/xenia/kernel/xboxkrnl/sources.gypi similarity index 94% rename from src/xenia/kernel/modules/xboxkrnl/sources.gypi rename to src/xenia/kernel/xboxkrnl/sources.gypi index 8af61490f..0482574bf 100644 --- a/src/xenia/kernel/modules/xboxkrnl/sources.gypi +++ b/src/xenia/kernel/xboxkrnl/sources.gypi @@ -5,8 +5,6 @@ 'async_request.h', 'kernel_state.cc', 'kernel_state.h', - 'module.cc', - 'module.h', 'object_table.cc', 'object_table.h', 'xboxkrnl_debug.cc', @@ -21,6 +19,8 @@ 'xboxkrnl_misc.h', 'xboxkrnl_module.cc', 'xboxkrnl_module.h', + 'xboxkrnl_modules.cc', + 'xboxkrnl_modules.h', 'xboxkrnl_nt.cc', 'xboxkrnl_nt.h', 'xboxkrnl_ob.cc', diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_debug.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_debug.cc similarity index 91% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_debug.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_debug.cc index 90951e4e9..3db81076d 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_debug.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_debug.cc @@ -1,242 +1,242 @@ -/** - ****************************************************************************** - * 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 - -#include -#include -#include -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - - -// TODO: clean me up! -SHIM_CALL DbgPrint_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - - uint32_t format_ptr = SHIM_GET_ARG_32(0); - if (format_ptr == 0) { - SHIM_SET_RETURN(-1); - return; - } - - const char *format = (const char *)SHIM_MEM_ADDR(format_ptr); - - int arg_index = 0; - - char buffer[512]; // TODO: ensure it never writes past the end of the buffer... - char *b = buffer; - for (; *format != '\0'; ++format) { - const char *start = format; - - if (*format != '%') { - *b++ = *format; - continue; - } - - ++format; - if (*format == '\0') { - break; - } - - if (*format == '%') { - *b++ = *format; - continue; - } - - const char *end; - end = format; - - // skip flags - while (*end == '-' || - *end == '+' || - *end == ' ' || - *end == '#' || - *end == '0') { - ++end; - } - - if (*end == '\0') { - break; - } - - int arg_extras = 0; - - // skip width - if (*end == '*') { - ++end; - arg_extras++; - } - else { - while (*end >= '0' && *end <= '9') { - ++end; - } - } - - if (*end == '\0') { - break; - } - - // skip precision - if (*end == '.') { - ++end; - - if (*end == '*') { - ++end; - ++arg_extras; - } - else { - while (*end >= '0' && *end <= '9') { - ++end; - } - } - } - - if (*end == '\0') { - break; - } - - // get length - int arg_size = 4; - - if (*end == 'h') { - ++end; - arg_size = 4; - if (*end == 'h') { - ++end; - } - } - else if (*end == 'l') { - ++end; - arg_size = 4; - if (*end == 'l') { - ++end; - arg_size = 8; - } - } - else if (*end == 'j') { - arg_size = 8; - ++end; - } - else if (*end == 'z') { - arg_size = 4; - ++end; - } - else if (*end == 't') { - arg_size = 8; - ++end; - } - else if (*end == 'L') { - arg_size = 8; - ++end; - } - - if (*end == '\0') { - break; - } - - if (*end == 'd' || - *end == 'i' || - *end == 'u' || - *end == 'o' || - *end == 'x' || - *end == 'X' || - *end == 'f' || - *end == 'F' || - *end == 'e' || - *end == 'E' || - *end == 'g' || - *end == 'G' || - *end == 'a' || - *end == 'A' || - *end == 'c') { - char local[512]; - local[0] = '\0'; - strncat(local, start, end + 1 - start); - - XEASSERT(arg_size == 8 || arg_size == 4); - if (arg_size == 8) { - if (arg_extras == 0) { - uint64_t value = arg_index < 7 - ? SHIM_GET_ARG_64(1 + arg_index) - : SHIM_MEM_32(SHIM_GPR_32(1) + 16 + ((1 + arg_index) * 8)); - int result = sprintf(b, local, value); - b += result; - arg_index++; - } - else { - XEASSERT(false); - } - } - else if (arg_size == 4) { - if (arg_extras == 0) { - uint64_t value = arg_index < 7 - ? SHIM_GET_ARG_64(1 + arg_index) - : SHIM_MEM_32(SHIM_GPR_32(1) + 16 + ((1 + arg_index) * 8)); - int result = sprintf(b, local, (uint32_t)value); - b += result; - arg_index++; - } - else { - XEASSERT(false); - } - } - } - else if (*end == 's' || - *end == 'p' || - *end == 'n') { - char local[512]; - local[0] = '\0'; - strncat(local, start, end + 1 - start); - - XEASSERT(arg_size == 4); - if (arg_extras == 0) { - uint32_t value = arg_index < 7 - ? SHIM_GET_ARG_32(1 + arg_index) - : (uint32_t)SHIM_MEM_64(SHIM_GPR_32(1) + 16 + ((1 + arg_index) * 8)); - const char *pointer = (const char *)SHIM_MEM_ADDR(value); - int result = sprintf(b, local, pointer); - b += result; - arg_index++; - } - else { - XEASSERT(false); - } - } - else { - XEASSERT(false); - break; - } - - format = end; - } - *b++ = '\0'; - - XELOGD("(DbgPrint) %s", buffer); -} - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -void xe::kernel::xboxkrnl::RegisterDebugExports( - ExportResolver* export_resolver, KernelState* state) { - SHIM_SET_MAPPING("xboxkrnl.exe", DbgPrint, state); -} +/** + ****************************************************************************** + * 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 + +#include +#include +#include +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +// TODO: clean me up! +SHIM_CALL DbgPrint_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + + uint32_t format_ptr = SHIM_GET_ARG_32(0); + if (format_ptr == 0) { + SHIM_SET_RETURN(-1); + return; + } + + const char *format = (const char *)SHIM_MEM_ADDR(format_ptr); + + int arg_index = 0; + + char buffer[512]; // TODO: ensure it never writes past the end of the buffer... + char *b = buffer; + for (; *format != '\0'; ++format) { + const char *start = format; + + if (*format != '%') { + *b++ = *format; + continue; + } + + ++format; + if (*format == '\0') { + break; + } + + if (*format == '%') { + *b++ = *format; + continue; + } + + const char *end; + end = format; + + // skip flags + while (*end == '-' || + *end == '+' || + *end == ' ' || + *end == '#' || + *end == '0') { + ++end; + } + + if (*end == '\0') { + break; + } + + int arg_extras = 0; + + // skip width + if (*end == '*') { + ++end; + arg_extras++; + } + else { + while (*end >= '0' && *end <= '9') { + ++end; + } + } + + if (*end == '\0') { + break; + } + + // skip precision + if (*end == '.') { + ++end; + + if (*end == '*') { + ++end; + ++arg_extras; + } + else { + while (*end >= '0' && *end <= '9') { + ++end; + } + } + } + + if (*end == '\0') { + break; + } + + // get length + int arg_size = 4; + + if (*end == 'h') { + ++end; + arg_size = 4; + if (*end == 'h') { + ++end; + } + } + else if (*end == 'l') { + ++end; + arg_size = 4; + if (*end == 'l') { + ++end; + arg_size = 8; + } + } + else if (*end == 'j') { + arg_size = 8; + ++end; + } + else if (*end == 'z') { + arg_size = 4; + ++end; + } + else if (*end == 't') { + arg_size = 8; + ++end; + } + else if (*end == 'L') { + arg_size = 8; + ++end; + } + + if (*end == '\0') { + break; + } + + if (*end == 'd' || + *end == 'i' || + *end == 'u' || + *end == 'o' || + *end == 'x' || + *end == 'X' || + *end == 'f' || + *end == 'F' || + *end == 'e' || + *end == 'E' || + *end == 'g' || + *end == 'G' || + *end == 'a' || + *end == 'A' || + *end == 'c') { + char local[512]; + local[0] = '\0'; + strncat(local, start, end + 1 - start); + + XEASSERT(arg_size == 8 || arg_size == 4); + if (arg_size == 8) { + if (arg_extras == 0) { + uint64_t value = arg_index < 7 + ? SHIM_GET_ARG_64(1 + arg_index) + : SHIM_MEM_32(SHIM_GPR_32(1) + 16 + ((1 + arg_index) * 8)); + int result = sprintf(b, local, value); + b += result; + arg_index++; + } + else { + XEASSERT(false); + } + } + else if (arg_size == 4) { + if (arg_extras == 0) { + uint64_t value = arg_index < 7 + ? SHIM_GET_ARG_64(1 + arg_index) + : SHIM_MEM_32(SHIM_GPR_32(1) + 16 + ((1 + arg_index) * 8)); + int result = sprintf(b, local, (uint32_t)value); + b += result; + arg_index++; + } + else { + XEASSERT(false); + } + } + } + else if (*end == 's' || + *end == 'p' || + *end == 'n') { + char local[512]; + local[0] = '\0'; + strncat(local, start, end + 1 - start); + + XEASSERT(arg_size == 4); + if (arg_extras == 0) { + uint32_t value = arg_index < 7 + ? SHIM_GET_ARG_32(1 + arg_index) + : (uint32_t)SHIM_MEM_64(SHIM_GPR_32(1) + 16 + ((1 + arg_index) * 8)); + const char *pointer = (const char *)SHIM_MEM_ADDR(value); + int result = sprintf(b, local, pointer); + b += result; + arg_index++; + } + else { + XEASSERT(false); + } + } + else { + XEASSERT(false); + break; + } + + format = end; + } + *b++ = '\0'; + + XELOGD("(DbgPrint) %s", buffer); +} + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +void xe::kernel::xboxkrnl::RegisterDebugExports( + ExportResolver* export_resolver, KernelState* state) { + SHIM_SET_MAPPING("xboxkrnl.exe", DbgPrint, state); +} diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_debug.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_debug.h similarity index 79% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_debug.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_debug.h index 851e19240..88baa6f77 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_debug.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_debug.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_DEBUG_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_DEBUG_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_DEBUG_H_ +#define XENIA_KERNEL_XBOXKRNL_DEBUG_H_ #include #include -#include +#include namespace xe { @@ -26,4 +26,4 @@ namespace xboxkrnl { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_DEBUG_H_ +#endif // XENIA_KERNEL_XBOXKRNL_DEBUG_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_hal.cc similarity index 90% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_hal.cc index b19a4e645..53415501c 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_hal.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include #include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_hal.h similarity index 80% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_hal.h index 3ae93d971..8596ec64d 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_hal.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_HAL_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_HAL_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_HAL_H_ +#define XENIA_KERNEL_XBOXKRNL_HAL_H_ #include #include -#include +#include namespace xe { @@ -29,4 +29,4 @@ void xeHalReturnToFirmware(uint32_t routine); } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_HAL_H_ +#endif // XENIA_KERNEL_XBOXKRNL_HAL_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc similarity index 96% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_io.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc index 410993377..3b8a9a912 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc @@ -7,14 +7,14 @@ ****************************************************************************** */ -#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace xe; @@ -63,7 +63,7 @@ SHIM_CALL NtCreateFile_shim( uint32_t handle; // Resolve the file using the virtual file system. - FileSystem* fs = state->filesystem(); + FileSystem* fs = state->file_system(); Entry* entry = fs->ResolvePath(attrs.object_name.buffer); XFile* file = NULL; if (entry && entry->type() == Entry::kTypeFile) { @@ -312,15 +312,15 @@ SHIM_CALL NtQueryInformationFile_shim( SHIM_SET_MEM_64(file_info_ptr, file->position()); break; case XFileNetworkOpenInformation: - // struct FILE_NETWORK_OPEN_INFORMATION { - // LARGE_INTEGER CreationTime; - // LARGE_INTEGER LastAccessTime; - // LARGE_INTEGER LastWriteTime; - // LARGE_INTEGER ChangeTime; - // LARGE_INTEGER AllocationSize; - // LARGE_INTEGER EndOfFile; - // ULONG FileAttributes; - // ULONG Unknown; + // struct FILE_NETWORK_OPEN_INFORMATION { + // LARGE_INTEGER CreationTime; + // LARGE_INTEGER LastAccessTime; + // LARGE_INTEGER LastWriteTime; + // LARGE_INTEGER ChangeTime; + // LARGE_INTEGER AllocationSize; + // LARGE_INTEGER EndOfFile; + // ULONG FileAttributes; + // ULONG Unknown; // }; XEASSERT(length == 56); XFileInfo file_info; @@ -369,7 +369,7 @@ SHIM_CALL NtQueryFullAttributesFile_shim( X_STATUS result = X_STATUS_NO_SUCH_FILE; // Resolve the file using the virtual file system. - FileSystem* fs = state->filesystem(); + FileSystem* fs = state->file_system(); Entry* entry = fs->ResolvePath(attrs.object_name.buffer); if (entry && entry->type() == Entry::kTypeFile) { // Found. diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_io.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.h similarity index 80% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_io.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_io.h index 6182ce295..48a394947 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_io.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_io.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_IO_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_IO_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_IO_H_ +#define XENIA_KERNEL_XBOXKRNL_IO_H_ #include #include -#include +#include namespace xe { @@ -26,4 +26,4 @@ namespace xboxkrnl { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_IO_H_ +#endif // XENIA_KERNEL_XBOXKRNL_IO_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc similarity index 98% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc index e0d96b046..a8c1e612d 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.cc @@ -7,11 +7,11 @@ ****************************************************************************** */ -#include +#include #include -#include -#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.h similarity index 88% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_memory.h index a00bf6240..b5ac87cb9 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_memory.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_MEMORY_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_MEMORY_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_MEMORY_H_ +#define XENIA_KERNEL_XBOXKRNL_MEMORY_H_ #include #include -#include +#include namespace xe { @@ -42,4 +42,4 @@ uint32_t xeMmGetPhysicalAddress(uint32_t base_address); } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_MEMORY_H_ +#endif // XENIA_KERNEL_XBOXKRNL_MEMORY_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_misc.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_misc.cc similarity index 87% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_misc.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_misc.cc index adb93107a..07882fed7 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_misc.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_misc.cc @@ -7,12 +7,12 @@ ****************************************************************************** */ -#include +#include #include -#include -#include -#include +#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_misc.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_misc.h similarity index 79% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_misc.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_misc.h index c1e896a63..b8399c61b 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_misc.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_misc.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_MISC_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_MISC_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_MISC_H_ +#define XENIA_KERNEL_XBOXKRNL_MISC_H_ #include #include -#include +#include namespace xe { @@ -26,4 +26,4 @@ namespace xboxkrnl { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_MISC_H_ +#endif // XENIA_KERNEL_XBOXKRNL_MISC_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/module.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc similarity index 79% rename from src/xenia/kernel/modules/xboxkrnl/module.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc index 23cd46d77..7796fc9f7 100644 --- a/src/xenia/kernel/modules/xboxkrnl/module.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc @@ -7,14 +7,14 @@ ****************************************************************************** */ -#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace xe; @@ -29,39 +29,37 @@ DEFINE_bool(abort_before_entry, false, KernelState* xe::kernel::xboxkrnl::shared_kernel_state_ = NULL; -XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : - KernelModule(runtime) { - ExportResolver* resolver = export_resolver_.get(); - +XboxkrnlModule::XboxkrnlModule(Emulator* emulator) : + KernelModule(emulator) { // Build the export table used for resolution. #include static KernelExport xboxkrnl_export_table[] = { - #include + #include }; #include - resolver->RegisterTable( + export_resolver_->RegisterTable( "xboxkrnl.exe", xboxkrnl_export_table, XECOUNT(xboxkrnl_export_table)); // Setup the kernel state instance. // This is where all kernel objects are kept while running. - kernel_state_ = auto_ptr(new KernelState(runtime)); + kernel_state_ = new KernelState(emulator); // Setup the shared global state object. XEASSERTNULL(shared_kernel_state_); - shared_kernel_state_ = kernel_state_.get(); + shared_kernel_state_ = kernel_state_; // Register all exported functions. - RegisterDebugExports(resolver, kernel_state_.get()); - RegisterHalExports(resolver, kernel_state_.get()); - RegisterIoExports(resolver, kernel_state_.get()); - RegisterMemoryExports(resolver, kernel_state_.get()); - RegisterMiscExports(resolver, kernel_state_.get()); - RegisterModuleExports(resolver, kernel_state_.get()); - RegisterNtExports(resolver, kernel_state_.get()); - RegisterObExports(resolver, kernel_state_.get()); - RegisterRtlExports(resolver, kernel_state_.get()); - RegisterThreadingExports(resolver, kernel_state_.get()); - RegisterVideoExports(resolver, kernel_state_.get()); + RegisterDebugExports(export_resolver_, kernel_state_); + RegisterHalExports(export_resolver_, kernel_state_); + RegisterIoExports(export_resolver_, kernel_state_); + RegisterMemoryExports(export_resolver_, kernel_state_); + RegisterMiscExports(export_resolver_, kernel_state_); + RegisterModuleExports(export_resolver_, kernel_state_); + RegisterNtExports(export_resolver_, kernel_state_); + RegisterObExports(export_resolver_, kernel_state_); + RegisterRtlExports(export_resolver_, kernel_state_); + RegisterThreadingExports(export_resolver_, kernel_state_); + RegisterVideoExports(export_resolver_, kernel_state_); uint8_t* mem = xe_memory_addr(memory_); @@ -70,7 +68,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // Offset 0x18 is a 4b pointer to a handler function that seems to take two // arguments. If we wanted to see what would happen we could fake that. uint32_t pKeDebugMonitorData = xe_memory_heap_alloc(memory_, 0, 256, 0); - resolver->SetVariableMapping( + export_resolver_->SetVariableMapping( "xboxkrnl.exe", ordinals::KeDebugMonitorData, pKeDebugMonitorData); XESETUINT32BE(mem + pKeDebugMonitorData, 0); @@ -78,7 +76,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // KeCertMonitorData (?*) // Always set to zero, ignored. uint32_t pKeCertMonitorData = xe_memory_heap_alloc(memory_, 0, 4, 0); - resolver->SetVariableMapping( + export_resolver_->SetVariableMapping( "xboxkrnl.exe", ordinals::KeCertMonitorData, pKeCertMonitorData); XESETUINT32BE(mem + pKeCertMonitorData, 0); @@ -89,7 +87,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // Games seem to check if bit 26 (0x20) is set, which at least for xbox1 // was whether an HDD was present. Not sure what the other flags are. uint32_t pXboxHardwareInfo = xe_memory_heap_alloc(memory_, 0, 16, 0); - resolver->SetVariableMapping( + export_resolver_->SetVariableMapping( "xboxkrnl.exe", ordinals::XboxHardwareInfo, pXboxHardwareInfo); XESETUINT32BE(mem + pXboxHardwareInfo + 0, 0x00000000); // flags @@ -107,7 +105,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // 0x80101100 <- xex header base uint32_t ppXexExecutableModuleHandle = xe_memory_heap_alloc(memory_, 0, 4, 0); - resolver->SetVariableMapping( + export_resolver_->SetVariableMapping( "xboxkrnl.exe", ordinals::XexExecutableModuleHandle, ppXexExecutableModuleHandle); uint32_t pXexExecutableModuleHandle = @@ -120,7 +118,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // Perhaps it's how swap disc/etc data is sent? // Always set to "default.xex" (with quotes) for now. uint32_t pExLoadedCommandLine = xe_memory_heap_alloc(memory_, 0, 1024, 0); - resolver->SetVariableMapping( + export_resolver_->SetVariableMapping( "xboxkrnl.exe", ordinals::ExLoadedCommandLine, pExLoadedCommandLine); char command_line[] = "\"default.xex\""; @@ -131,7 +129,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // Kernel version, looks like 2b.2b.2b.2b. // I've only seen games check >=, so we just fake something here. uint32_t pXboxKrnlVersion = xe_memory_heap_alloc(memory_, 0, 8, 0); - resolver->SetVariableMapping( + export_resolver_->SetVariableMapping( "xboxkrnl.exe", ordinals::XboxKrnlVersion, pXboxKrnlVersion); XESETUINT16BE(mem + pXboxKrnlVersion + 0, 2); @@ -141,7 +139,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // KeTimeStampBundle (ad) uint32_t pKeTimeStampBundle = xe_memory_heap_alloc(memory_, 0, 24, 0); - resolver->SetVariableMapping( + export_resolver_->SetVariableMapping( "xboxkrnl.exe", ordinals::KeTimeStampBundle, pKeTimeStampBundle); XESETUINT64BE(mem + pKeTimeStampBundle + 0, 0); @@ -150,6 +148,8 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : } XboxkrnlModule::~XboxkrnlModule() { + delete kernel_state_; + // Clear the shared kernel state. shared_kernel_state_ = NULL; } @@ -157,7 +157,7 @@ XboxkrnlModule::~XboxkrnlModule() { int XboxkrnlModule::LaunchModule(const char* path) { // Create and register the module. We keep it local to this function and // dispose it on exit. - XModule* module = new XModule(kernel_state_.get(), path); + XModule* module = new XModule(kernel_state_, path); // Load the module into memory from the filesystem. X_STATUS result_code = module->LoadFromFile(path); diff --git a/src/xenia/kernel/modules/xboxkrnl/module.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.h similarity index 55% rename from src/xenia/kernel/modules/xboxkrnl/module.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_module.h index 7ac8ddc5f..d93c6a125 100644 --- a/src/xenia/kernel/modules/xboxkrnl/module.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.h @@ -7,24 +7,24 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_MODULE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_MODULE_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_MODULE_H_ +#define XENIA_KERNEL_XBOXKRNL_MODULE_H_ #include #include -#include +#include #include -#include +#include // All of the exported functions: -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace xe { @@ -36,13 +36,13 @@ class KernelState; class XboxkrnlModule : public KernelModule { public: - XboxkrnlModule(Runtime* runtime); + XboxkrnlModule(Emulator* emulator); virtual ~XboxkrnlModule(); int LaunchModule(const char* path); private: - auto_ptr kernel_state_; + KernelState* kernel_state_; }; @@ -51,4 +51,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_MODULE_H_ +#endif // XENIA_KERNEL_XBOXKRNL_MODULE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc similarity index 96% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc index d134e9f97..f901eb0c7 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc @@ -7,13 +7,13 @@ ****************************************************************************** */ -#include +#include #include #include -#include -#include -#include +#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.h similarity index 83% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_modules.h index 8e561fcec..a76e12ce8 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_MODULE_IMPL_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_MODULE_IMPL_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_MODULES_IMPL_H_ +#define XENIA_KERNEL_XBOXKRNL_MODULES_IMPL_H_ #include #include -#include +#include namespace xe { @@ -35,4 +35,4 @@ int xeXexGetModuleHandle(const char* module_name, } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_MODULE_IMPL_H_ +#endif // XENIA_KERNEL_XBOXKRNL_MODULES_IMPL_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_nt.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_nt.cc similarity index 84% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_nt.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_nt.cc index 195a1c58a..7ce9f4cdb 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_nt.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_nt.cc @@ -7,12 +7,12 @@ ****************************************************************************** */ -#include +#include #include -#include -#include -#include +#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_nt.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_nt.h similarity index 80% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_nt.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_nt.h index 713878de6..0a42cef31 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_nt.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_nt.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_NT_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_NT_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_NT_H_ +#define XENIA_KERNEL_XBOXKRNL_NT_H_ #include #include -#include +#include namespace xe { @@ -26,4 +26,4 @@ namespace xboxkrnl { } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_NT_H_ +#endif // XENIA_KERNEL_XBOXKRNL_NT_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ob.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc similarity index 86% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ob.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc index fcf8f18cc..32ff43be5 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ob.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc @@ -1,101 +1,101 @@ -/** - ****************************************************************************** - * 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 - -#include -#include -#include -#include -#include - - -using namespace xe; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - - -SHIM_CALL ObReferenceObjectByHandle_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t handle = SHIM_GET_ARG_32(0); - uint32_t object_type_ptr = SHIM_GET_ARG_32(1); - uint32_t out_object_ptr = SHIM_GET_ARG_32(2); - - XELOGD( - "ObReferenceObjectByHandle(%.8X, %.8X, %.8X)", - handle, - object_type_ptr, - out_object_ptr); - - X_STATUS result = X_STATUS_INVALID_HANDLE; - - XObject* object = NULL; - result = state->object_table()->GetObject(handle, &object); - if (XSUCCEEDED(result)) { - // TODO(benvanik): verify type with object_type_ptr - - // TODO(benvanik): get native value, if supported. - uint32_t native_ptr = 0xDEADF00D; - switch (object_type_ptr) { - case 0xD01BBEEF: // ExThreadObjectType - { - XThread* thread = (XThread*)object; - native_ptr = thread->thread_state(); - } - break; - } - - if (out_object_ptr) { - SHIM_SET_MEM_32(out_object_ptr, native_ptr); - } - } - - SHIM_SET_RETURN(result); -} - - -SHIM_CALL ObDereferenceObject_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t native_ptr = SHIM_GET_ARG_32(0); - - XELOGD( - "ObDereferenceObject(%.8X)", - native_ptr); - - // Check if a dummy value from ObReferenceObjectByHandle. - if (native_ptr == 0xDEADF00D) { - SHIM_SET_RETURN(0); - return; - } - - void* object_ptr = SHIM_MEM_ADDR(native_ptr); - XObject* object = XObject::GetObject(state, object_ptr); - if (object) { - object->Release(); - } - - SHIM_SET_RETURN(0); -} - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -void xe::kernel::xboxkrnl::RegisterObExports( - ExportResolver* export_resolver, KernelState* state) { - SHIM_SET_MAPPING("xboxkrnl.exe", ObReferenceObjectByHandle, state); - SHIM_SET_MAPPING("xboxkrnl.exe", ObDereferenceObject, state); -} +/** + ****************************************************************************** + * 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 + +#include +#include +#include +#include +#include + + +using namespace xe; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +SHIM_CALL ObReferenceObjectByHandle_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t handle = SHIM_GET_ARG_32(0); + uint32_t object_type_ptr = SHIM_GET_ARG_32(1); + uint32_t out_object_ptr = SHIM_GET_ARG_32(2); + + XELOGD( + "ObReferenceObjectByHandle(%.8X, %.8X, %.8X)", + handle, + object_type_ptr, + out_object_ptr); + + X_STATUS result = X_STATUS_INVALID_HANDLE; + + XObject* object = NULL; + result = state->object_table()->GetObject(handle, &object); + if (XSUCCEEDED(result)) { + // TODO(benvanik): verify type with object_type_ptr + + // TODO(benvanik): get native value, if supported. + uint32_t native_ptr = 0xDEADF00D; + switch (object_type_ptr) { + case 0xD01BBEEF: // ExThreadObjectType + { + XThread* thread = (XThread*)object; + native_ptr = thread->thread_state(); + } + break; + } + + if (out_object_ptr) { + SHIM_SET_MEM_32(out_object_ptr, native_ptr); + } + } + + SHIM_SET_RETURN(result); +} + + +SHIM_CALL ObDereferenceObject_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t native_ptr = SHIM_GET_ARG_32(0); + + XELOGD( + "ObDereferenceObject(%.8X)", + native_ptr); + + // Check if a dummy value from ObReferenceObjectByHandle. + if (native_ptr == 0xDEADF00D) { + SHIM_SET_RETURN(0); + return; + } + + void* object_ptr = SHIM_MEM_ADDR(native_ptr); + XObject* object = XObject::GetObject(state, object_ptr); + if (object) { + object->Release(); + } + + SHIM_SET_RETURN(0); +} + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +void xe::kernel::xboxkrnl::RegisterObExports( + ExportResolver* export_resolver, KernelState* state) { + SHIM_SET_MAPPING("xboxkrnl.exe", ObReferenceObjectByHandle, state); + SHIM_SET_MAPPING("xboxkrnl.exe", ObDereferenceObject, state); +} diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ob.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.h similarity index 77% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ob.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_ob.h index 04fa70a40..c56eef13f 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ob.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_ob.h @@ -1,29 +1,29 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_OB_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_OB_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_OB_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_OB_H_ +#define XENIA_KERNEL_XBOXKRNL_OB_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_OB_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ordinals.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_ordinals.h similarity index 73% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ordinals.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_ordinals.h index def54bcff..7ec22c811 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_ordinals.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_ordinals.h @@ -1,29 +1,29 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_ORDINALS_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_ORDINALS_H_ - -#include -#include - -#include - - -// Build an ordinal enum to make it easy to lookup ordinals. -#include -namespace ordinals { -enum { - #include -}; -} // namespace ordinals -#include - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_ORDINALS_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_ORDINALS_H_ +#define XENIA_KERNEL_XBOXKRNL_ORDINALS_H_ + +#include +#include + +#include + + +// Build an ordinal enum to make it easy to lookup ordinals. +#include +namespace ordinals { +enum { + #include +}; +} // namespace ordinals +#include + + +#endif // XENIA_KERNEL_XBOXKRNL_ORDINALS_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_private.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_private.h similarity index 87% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_private.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_private.h index b730c05d5..02fb79521 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_private.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_private.h @@ -1,51 +1,51 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_PRIVATE_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_PRIVATE_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - -class KernelState; - - -// This is a global object initialized with the XboxkrnlModule. -// It references the current kernel state object that all kernel methods should -// be using to stash their variables. -extern KernelState* shared_kernel_state_; - -// Registration functions, one per file. -void RegisterDebugExports(ExportResolver* export_resolver, KernelState* state); -void RegisterHalExports(ExportResolver* export_resolver, KernelState* state); -void RegisterIoExports(ExportResolver* export_resolver, KernelState* state); -void RegisterMemoryExports(ExportResolver* export_resolver, KernelState* state); -void RegisterMiscExports(ExportResolver* export_resolver, KernelState* state); -void RegisterModuleExports(ExportResolver* export_resolver, KernelState* state); -void RegisterNtExports(ExportResolver* export_resolver, KernelState* state); -void RegisterObExports(ExportResolver* export_resolver, KernelState* state); -void RegisterRtlExports(ExportResolver* export_resolver, KernelState* state); -void RegisterThreadingExports(ExportResolver* export_resolver, - KernelState* state); -void RegisterVideoExports(ExportResolver* export_resolver, KernelState* state); - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_PRIVATE_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_PRIVATE_H_ +#define XENIA_KERNEL_XBOXKRNL_PRIVATE_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + +class KernelState; + + +// This is a global object initialized with the XboxkrnlModule. +// It references the current kernel state object that all kernel methods should +// be using to stash their variables. +extern KernelState* shared_kernel_state_; + +// Registration functions, one per file. +void RegisterDebugExports(ExportResolver* export_resolver, KernelState* state); +void RegisterHalExports(ExportResolver* export_resolver, KernelState* state); +void RegisterIoExports(ExportResolver* export_resolver, KernelState* state); +void RegisterMemoryExports(ExportResolver* export_resolver, KernelState* state); +void RegisterMiscExports(ExportResolver* export_resolver, KernelState* state); +void RegisterModuleExports(ExportResolver* export_resolver, KernelState* state); +void RegisterNtExports(ExportResolver* export_resolver, KernelState* state); +void RegisterObExports(ExportResolver* export_resolver, KernelState* state); +void RegisterRtlExports(ExportResolver* export_resolver, KernelState* state); +void RegisterThreadingExports(ExportResolver* export_resolver, + KernelState* state); +void RegisterVideoExports(ExportResolver* export_resolver, KernelState* state); + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_PRIVATE_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc similarity index 98% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc index 4a508a217..dafcf0bd1 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc @@ -7,14 +7,14 @@ ****************************************************************************** */ -#include +#include #include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.h similarity index 91% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.h index fc4f59222..bb7228dac 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_RTL_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_RTL_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_RTL_H_ +#define XENIA_KERNEL_XBOXKRNL_RTL_H_ #include #include -#include +#include namespace xe { @@ -54,4 +54,4 @@ void xeRtlLeaveCriticalSection(uint32_t cs_ptr); } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_RTL_H_ +#endif // XENIA_KERNEL_XBOXKRNL_RTL_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_table.inc b/src/xenia/kernel/xboxkrnl/xboxkrnl_table.inc similarity index 100% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_table.inc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_table.inc diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc similarity index 98% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc index ed724a1cb..f224e0bba 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc @@ -7,13 +7,13 @@ ****************************************************************************** */ -#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace xe; diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.h similarity index 91% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_threading.h index 68e22f628..45c908942 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.h @@ -7,13 +7,13 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_THREADING_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_THREADING_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_THREADING_H_ +#define XENIA_KERNEL_XBOXKRNL_THREADING_H_ #include #include -#include +#include namespace xe { @@ -62,4 +62,4 @@ void xeKeLeaveCriticalRegion(); } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_THREADING_H_ +#endif // XENIA_KERNEL_XBOXKRNL_THREADING_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_video.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc similarity index 92% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_video.cc rename to src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc index 448c56c8a..965e1f781 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_video.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.cc @@ -1,443 +1,444 @@ -/** - ****************************************************************************** - * 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 - -#include -#include -#include -#include -#include -#include - - -using namespace xe; -using namespace xe::gpu; -using namespace xe::kernel; -using namespace xe::kernel::xboxkrnl; - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - - -// http://www.tweakoz.com/orkid/ -// http://www.tweakoz.com/orkid/dox/d3/d52/xb360init_8cpp_source.html -// https://github.com/Free60Project/xenosfb/ -// https://github.com/Free60Project/xenosfb/blob/master/src/xe.h -// https://github.com/gligli/libxemit -// http://web.archive.org/web/20090428095215/http://msdn.microsoft.com/en-us/library/bb313877.aspx -// http://web.archive.org/web/20100423054747/http://msdn.microsoft.com/en-us/library/bb313961.aspx -// http://web.archive.org/web/20100423054747/http://msdn.microsoft.com/en-us/library/bb313878.aspx -// http://web.archive.org/web/20090510235238/http://msdn.microsoft.com/en-us/library/bb313942.aspx -// http://svn.dd-wrt.com/browser/src/linux/universal/linux-3.8/drivers/gpu/drm/radeon/radeon_ring.c -// http://www.microsoft.com/en-za/download/details.aspx?id=5313 -- "Stripped Down Direct3D: Xbox 360 Command Buffer and Resource Management" - - -void xeVdGetCurrentDisplayGamma(uint32_t* arg0, float* arg1) { - *arg0 = 2; - *arg1 = 2.22222233f; -} - - -SHIM_CALL VdGetCurrentDisplayGamma_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t arg0_ptr = SHIM_GET_ARG_32(0); - uint32_t arg1_ptr = SHIM_GET_ARG_32(1); - - XELOGD( - "VdGetCurrentDisplayGamma(%.8X, %.8X)", - arg0_ptr, arg1_ptr); - - uint32_t arg0 = 0; - union { - float float_value; - uint32_t uint_value; - } arg1; - xeVdGetCurrentDisplayGamma(&arg0, &arg1.float_value); - SHIM_SET_MEM_32(arg0_ptr, arg0); - SHIM_SET_MEM_32(arg1_ptr, arg1.uint_value); -} - - -SHIM_CALL VdGetCurrentDisplayInformation_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t ptr = SHIM_GET_ARG_32(0); - - XELOGD( - "VdGetCurrentDisplayInformation(%.8X)", - ptr); - - // Expecting a length 0x58 struct of stuff. - SHIM_SET_MEM_32(ptr + 0x10, 1280); - SHIM_SET_MEM_32(ptr + 0x14, 720); - SHIM_SET_MEM_16(ptr + 0x48, 1280); - SHIM_SET_MEM_16(ptr + 0x4A, 720); - SHIM_SET_MEM_16(ptr + 0x56, 1280); -} - - -uint32_t xeVdQueryVideoFlags() { - // ? - return 0x00000007; -} - - -SHIM_CALL VdQueryVideoFlags_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - XELOGD( - "VdQueryVideoFlags()"); - - SHIM_SET_RETURN(xeVdQueryVideoFlags()); -} - - -void xeVdQueryVideoMode(X_VIDEO_MODE *video_mode, bool swap) { - if (video_mode == NULL) { - return; - } - - // TODO: get info from actual display - video_mode->display_width = 1280; - video_mode->display_height = 720; - video_mode->is_interlaced = 0; - video_mode->is_widescreen = 1; - video_mode->is_hi_def = 1; - video_mode->refresh_rate = 60.0f; - video_mode->video_standard = 1; // NTSC - video_mode->unknown_0x8a = 0x8A; - video_mode->unknown_0x01 = 0x01; - - if (swap) { - video_mode->display_width = XESWAP32BE(video_mode->display_width); - video_mode->display_height = XESWAP32BE(video_mode->display_height); - video_mode->is_interlaced = XESWAP32BE(video_mode->is_interlaced); - video_mode->is_widescreen = XESWAP32BE(video_mode->is_widescreen); - video_mode->is_hi_def = XESWAP32BE(video_mode->is_hi_def); - video_mode->refresh_rate = XESWAPF32BE(video_mode->refresh_rate); - video_mode->video_standard = XESWAP32BE(video_mode->video_standard); - video_mode->unknown_0x8a = XESWAP32BE(video_mode->unknown_0x8a); - video_mode->unknown_0x01 = XESWAP32BE(video_mode->unknown_0x01); - } -} - - -SHIM_CALL VdQueryVideoMode_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t video_mode_ptr = SHIM_GET_ARG_32(0); - X_VIDEO_MODE *video_mode = (X_VIDEO_MODE*)SHIM_MEM_ADDR(video_mode_ptr); - - XELOGD( - "VdQueryVideoMode(%.8X)", - video_mode_ptr); - - xeVdQueryVideoMode(video_mode, true); -} - - -void xeVdInitializeEngines(uint32_t unk0, uint32_t callback, uint32_t unk1, - uint32_t unk2_ptr, uint32_t unk3_ptr) { +/** + ****************************************************************************** + * 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 + +#include +#include +#include +#include +#include +#include +#include + + +using namespace xe; +using namespace xe::gpu; +using namespace xe::kernel; +using namespace xe::kernel::xboxkrnl; + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +// http://www.tweakoz.com/orkid/ +// http://www.tweakoz.com/orkid/dox/d3/d52/xb360init_8cpp_source.html +// https://github.com/Free60Project/xenosfb/ +// https://github.com/Free60Project/xenosfb/blob/master/src/xe.h +// https://github.com/gligli/libxemit +// http://web.archive.org/web/20090428095215/http://msdn.microsoft.com/en-us/library/bb313877.aspx +// http://web.archive.org/web/20100423054747/http://msdn.microsoft.com/en-us/library/bb313961.aspx +// http://web.archive.org/web/20100423054747/http://msdn.microsoft.com/en-us/library/bb313878.aspx +// http://web.archive.org/web/20090510235238/http://msdn.microsoft.com/en-us/library/bb313942.aspx +// http://svn.dd-wrt.com/browser/src/linux/universal/linux-3.8/drivers/gpu/drm/radeon/radeon_ring.c +// http://www.microsoft.com/en-za/download/details.aspx?id=5313 -- "Stripped Down Direct3D: Xbox 360 Command Buffer and Resource Management" + + +void xeVdGetCurrentDisplayGamma(uint32_t* arg0, float* arg1) { + *arg0 = 2; + *arg1 = 2.22222233f; +} + + +SHIM_CALL VdGetCurrentDisplayGamma_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t arg0_ptr = SHIM_GET_ARG_32(0); + uint32_t arg1_ptr = SHIM_GET_ARG_32(1); + + XELOGD( + "VdGetCurrentDisplayGamma(%.8X, %.8X)", + arg0_ptr, arg1_ptr); + + uint32_t arg0 = 0; + union { + float float_value; + uint32_t uint_value; + } arg1; + xeVdGetCurrentDisplayGamma(&arg0, &arg1.float_value); + SHIM_SET_MEM_32(arg0_ptr, arg0); + SHIM_SET_MEM_32(arg1_ptr, arg1.uint_value); +} + + +SHIM_CALL VdGetCurrentDisplayInformation_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t ptr = SHIM_GET_ARG_32(0); + + XELOGD( + "VdGetCurrentDisplayInformation(%.8X)", + ptr); + + // Expecting a length 0x58 struct of stuff. + SHIM_SET_MEM_32(ptr + 0x10, 1280); + SHIM_SET_MEM_32(ptr + 0x14, 720); + SHIM_SET_MEM_16(ptr + 0x48, 1280); + SHIM_SET_MEM_16(ptr + 0x4A, 720); + SHIM_SET_MEM_16(ptr + 0x56, 1280); +} + + +uint32_t xeVdQueryVideoFlags() { + // ? + return 0x00000007; +} + + +SHIM_CALL VdQueryVideoFlags_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + XELOGD( + "VdQueryVideoFlags()"); + + SHIM_SET_RETURN(xeVdQueryVideoFlags()); +} + + +void xeVdQueryVideoMode(X_VIDEO_MODE *video_mode, bool swap) { + if (video_mode == NULL) { + return; + } + + // TODO: get info from actual display + video_mode->display_width = 1280; + video_mode->display_height = 720; + video_mode->is_interlaced = 0; + video_mode->is_widescreen = 1; + video_mode->is_hi_def = 1; + video_mode->refresh_rate = 60.0f; + video_mode->video_standard = 1; // NTSC + video_mode->unknown_0x8a = 0x8A; + video_mode->unknown_0x01 = 0x01; + + if (swap) { + video_mode->display_width = XESWAP32BE(video_mode->display_width); + video_mode->display_height = XESWAP32BE(video_mode->display_height); + video_mode->is_interlaced = XESWAP32BE(video_mode->is_interlaced); + video_mode->is_widescreen = XESWAP32BE(video_mode->is_widescreen); + video_mode->is_hi_def = XESWAP32BE(video_mode->is_hi_def); + video_mode->refresh_rate = XESWAPF32BE(video_mode->refresh_rate); + video_mode->video_standard = XESWAP32BE(video_mode->video_standard); + video_mode->unknown_0x8a = XESWAP32BE(video_mode->unknown_0x8a); + video_mode->unknown_0x01 = XESWAP32BE(video_mode->unknown_0x01); + } +} + + +SHIM_CALL VdQueryVideoMode_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t video_mode_ptr = SHIM_GET_ARG_32(0); + X_VIDEO_MODE *video_mode = (X_VIDEO_MODE*)SHIM_MEM_ADDR(video_mode_ptr); + + XELOGD( + "VdQueryVideoMode(%.8X)", + video_mode_ptr); + + xeVdQueryVideoMode(video_mode, true); +} + + +void xeVdInitializeEngines(uint32_t unk0, uint32_t callback, uint32_t unk1, + uint32_t unk2_ptr, uint32_t unk3_ptr) { KernelState* state = shared_kernel_state_; - XEASSERTNOTNULL(state); - GraphicsSystem* gs = state->processor()->graphics_system().get(); - if (!gs) { - return; - } - - // r3 = 0x4F810000 - // r4 = function ptr (cleanup callback?) - // r5 = 0 - // r6/r7 = some binary data in .data -} - - -SHIM_CALL VdInitializeEngines_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t unk0 = SHIM_GET_ARG_32(0); - uint32_t callback = SHIM_GET_ARG_32(1); - uint32_t unk1 = SHIM_GET_ARG_32(2); - uint32_t unk2_ptr = SHIM_GET_ARG_32(3); - uint32_t unk3_ptr = SHIM_GET_ARG_32(4); - - XELOGD( - "VdInitializeEngines(%.8X, %.8X, %.8X, %.8X, %.8X)", - unk0, callback, unk1, unk2_ptr, unk3_ptr); - - xeVdInitializeEngines(unk0, callback, unk1, unk2_ptr, unk3_ptr); -} - - -void xeVdSetGraphicsInterruptCallback(uint32_t callback, uint32_t user_data) { + XEASSERTNOTNULL(state); + GraphicsSystem* gs = state->emulator()->graphics_system(); + if (!gs) { + return; + } + + // r3 = 0x4F810000 + // r4 = function ptr (cleanup callback?) + // r5 = 0 + // r6/r7 = some binary data in .data +} + + +SHIM_CALL VdInitializeEngines_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t unk0 = SHIM_GET_ARG_32(0); + uint32_t callback = SHIM_GET_ARG_32(1); + uint32_t unk1 = SHIM_GET_ARG_32(2); + uint32_t unk2_ptr = SHIM_GET_ARG_32(3); + uint32_t unk3_ptr = SHIM_GET_ARG_32(4); + + XELOGD( + "VdInitializeEngines(%.8X, %.8X, %.8X, %.8X, %.8X)", + unk0, callback, unk1, unk2_ptr, unk3_ptr); + + xeVdInitializeEngines(unk0, callback, unk1, unk2_ptr, unk3_ptr); +} + + +void xeVdSetGraphicsInterruptCallback(uint32_t callback, uint32_t user_data) { KernelState* state = shared_kernel_state_; - XEASSERTNOTNULL(state); - GraphicsSystem* gs = state->processor()->graphics_system().get(); - if (!gs) { - return; - } - - // callback takes 2 params - // r3 = bool 0/1 - 0 is normal interrupt, 1 is some acquire/lock mumble - // r4 = user_data (r4 of VdSetGraphicsInterruptCallback) - - gs->SetInterruptCallback(callback, user_data); -} - - -SHIM_CALL VdSetGraphicsInterruptCallback_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t callback = SHIM_GET_ARG_32(0); - uint32_t user_data = SHIM_GET_ARG_32(1); - - XELOGD( - "VdSetGraphicsInterruptCallback(%.8X, %.8X)", - callback, user_data); - - xeVdSetGraphicsInterruptCallback(callback, user_data); -} - - -void xeVdInitializeRingBuffer(uint32_t ptr, uint32_t page_count) { + XEASSERTNOTNULL(state); + GraphicsSystem* gs = state->emulator()->graphics_system(); + if (!gs) { + return; + } + + // callback takes 2 params + // r3 = bool 0/1 - 0 is normal interrupt, 1 is some acquire/lock mumble + // r4 = user_data (r4 of VdSetGraphicsInterruptCallback) + + gs->SetInterruptCallback(callback, user_data); +} + + +SHIM_CALL VdSetGraphicsInterruptCallback_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t callback = SHIM_GET_ARG_32(0); + uint32_t user_data = SHIM_GET_ARG_32(1); + + XELOGD( + "VdSetGraphicsInterruptCallback(%.8X, %.8X)", + callback, user_data); + + xeVdSetGraphicsInterruptCallback(callback, user_data); +} + + +void xeVdInitializeRingBuffer(uint32_t ptr, uint32_t page_count) { KernelState* state = shared_kernel_state_; - XEASSERTNOTNULL(state); - GraphicsSystem* gs = state->processor()->graphics_system().get(); - if (!gs) { - return; - } - - // r3 = result of MmGetPhysicalAddress - // r4 = number of pages? page size? - // 0x8000 -> cntlzw=16 -> 0x1C - 16 = 12 - // Buffer pointers are from MmAllocatePhysicalMemory with WRITE_COMBINE. - // Sizes could be zero? XBLA games seem to do this. Default sizes? - // D3D does size / region_count - must be > 1024 - - gs->InitializeRingBuffer(ptr, page_count); -} - - -SHIM_CALL VdInitializeRingBuffer_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t ptr = SHIM_GET_ARG_32(0); - uint32_t page_count = SHIM_GET_ARG_32(1); - - XELOGD( - "VdInitializeRingBuffer(%.8X, %.8X)", - ptr, page_count); - - xeVdInitializeRingBuffer(ptr, page_count); -} - - -void xeVdEnableRingBufferRPtrWriteBack(uint32_t ptr, uint32_t block_size) { + XEASSERTNOTNULL(state); + GraphicsSystem* gs = state->emulator()->graphics_system(); + if (!gs) { + return; + } + + // r3 = result of MmGetPhysicalAddress + // r4 = number of pages? page size? + // 0x8000 -> cntlzw=16 -> 0x1C - 16 = 12 + // Buffer pointers are from MmAllocatePhysicalMemory with WRITE_COMBINE. + // Sizes could be zero? XBLA games seem to do this. Default sizes? + // D3D does size / region_count - must be > 1024 + + gs->InitializeRingBuffer(ptr, page_count); +} + + +SHIM_CALL VdInitializeRingBuffer_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t ptr = SHIM_GET_ARG_32(0); + uint32_t page_count = SHIM_GET_ARG_32(1); + + XELOGD( + "VdInitializeRingBuffer(%.8X, %.8X)", + ptr, page_count); + + xeVdInitializeRingBuffer(ptr, page_count); +} + + +void xeVdEnableRingBufferRPtrWriteBack(uint32_t ptr, uint32_t block_size) { KernelState* state = shared_kernel_state_; - XEASSERTNOTNULL(state); - GraphicsSystem* gs = state->processor()->graphics_system().get(); - if (!gs) { - return; - } - - // r4 = 6, usually --- <=19 - gs->EnableReadPointerWriteBack(ptr, block_size); - - ptr += 0x20000000; - printf("%.8X", ptr); - // 0x0110343c - - // r3 = 0x2B10(d3d?) + 0x3C - - //((p + 0x3C) & 0x1FFFFFFF) + ((((p + 0x3C) >> 20) + 0x200) & 0x1000) - //also 0x3C offset into WriteBacks is PrimaryRingBufferReadIndex -//(1:17:38 AM) Rick: .text:8201B348 lwz r11, 0x2B10(r31) -//(1:17:38 AM) Rick: .text:8201B34C addi r11, r11, 0x3C -//(1:17:38 AM) Rick: .text:8201B350 srwi r10, r11, 20 # r10 = r11 >> 20 -//(1:17:38 AM) Rick: .text:8201B354 clrlwi r11, r11, 3 # r11 = r11 & 0x1FFFFFFF -//(1:17:38 AM) Rick: .text:8201B358 addi r10, r10, 0x200 -//(1:17:39 AM) Rick: .text:8201B35C rlwinm r10, r10, 0,19,19 # r10 = r10 & 0x1000 -//(1:17:39 AM) Rick: .text:8201B360 add r3, r10, r11 -//(1:17:39 AM) Rick: .text:8201B364 bl VdEnableRingBufferRPtrWriteBack - // TODO(benvanik): something? -} - - -SHIM_CALL VdEnableRingBufferRPtrWriteBack_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t ptr = SHIM_GET_ARG_32(0); - uint32_t block_size = SHIM_GET_ARG_32(1); - - XELOGD( - "VdEnableRingBufferRPtrWriteBack(%.8X, %.8X)", - ptr, block_size); - - xeVdEnableRingBufferRPtrWriteBack(ptr, block_size); -} - - -void xeVdGetSystemCommandBuffer(uint32_t* p0, uint32_t* p1) { - *p0 = 0xBEEF0000; - *p1 = 0xBEEF0001; -} - - -SHIM_CALL VdGetSystemCommandBuffer_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t p0_ptr = SHIM_GET_ARG_32(0); - uint32_t p1_ptr = SHIM_GET_ARG_32(1); - - XELOGD( - "VdGetSystemCommandBuffer(%.8X, %.8X)", - p0_ptr, - p1_ptr); - - uint32_t p0 = 0; - uint32_t p1 = 0; - xeVdGetSystemCommandBuffer(&p0, &p1); - SHIM_SET_MEM_32(p0_ptr, p0); - SHIM_SET_MEM_32(p1_ptr, p1); -} - - -void xeVdSetSystemCommandBufferGpuIdentifierAddress(uint32_t unk) { + XEASSERTNOTNULL(state); + GraphicsSystem* gs = state->emulator()->graphics_system(); + if (!gs) { + return; + } + + // r4 = 6, usually --- <=19 + gs->EnableReadPointerWriteBack(ptr, block_size); + + ptr += 0x20000000; + printf("%.8X", ptr); + // 0x0110343c + + // r3 = 0x2B10(d3d?) + 0x3C + + //((p + 0x3C) & 0x1FFFFFFF) + ((((p + 0x3C) >> 20) + 0x200) & 0x1000) + //also 0x3C offset into WriteBacks is PrimaryRingBufferReadIndex +//(1:17:38 AM) Rick: .text:8201B348 lwz r11, 0x2B10(r31) +//(1:17:38 AM) Rick: .text:8201B34C addi r11, r11, 0x3C +//(1:17:38 AM) Rick: .text:8201B350 srwi r10, r11, 20 # r10 = r11 >> 20 +//(1:17:38 AM) Rick: .text:8201B354 clrlwi r11, r11, 3 # r11 = r11 & 0x1FFFFFFF +//(1:17:38 AM) Rick: .text:8201B358 addi r10, r10, 0x200 +//(1:17:39 AM) Rick: .text:8201B35C rlwinm r10, r10, 0,19,19 # r10 = r10 & 0x1000 +//(1:17:39 AM) Rick: .text:8201B360 add r3, r10, r11 +//(1:17:39 AM) Rick: .text:8201B364 bl VdEnableRingBufferRPtrWriteBack + // TODO(benvanik): something? +} + + +SHIM_CALL VdEnableRingBufferRPtrWriteBack_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t ptr = SHIM_GET_ARG_32(0); + uint32_t block_size = SHIM_GET_ARG_32(1); + + XELOGD( + "VdEnableRingBufferRPtrWriteBack(%.8X, %.8X)", + ptr, block_size); + + xeVdEnableRingBufferRPtrWriteBack(ptr, block_size); +} + + +void xeVdGetSystemCommandBuffer(uint32_t* p0, uint32_t* p1) { + *p0 = 0xBEEF0000; + *p1 = 0xBEEF0001; +} + + +SHIM_CALL VdGetSystemCommandBuffer_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t p0_ptr = SHIM_GET_ARG_32(0); + uint32_t p1_ptr = SHIM_GET_ARG_32(1); + + XELOGD( + "VdGetSystemCommandBuffer(%.8X, %.8X)", + p0_ptr, + p1_ptr); + + uint32_t p0 = 0; + uint32_t p1 = 0; + xeVdGetSystemCommandBuffer(&p0, &p1); + SHIM_SET_MEM_32(p0_ptr, p0); + SHIM_SET_MEM_32(p1_ptr, p1); +} + + +void xeVdSetSystemCommandBufferGpuIdentifierAddress(uint32_t unk) { KernelState* state = shared_kernel_state_; - XEASSERTNOTNULL(state); - GraphicsSystem* gs = state->processor()->graphics_system().get(); - if (!gs) { - return; - } - - // r3 = 0x2B10(d3d?) + 8 -} - - -SHIM_CALL VdSetSystemCommandBufferGpuIdentifierAddress_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t unk = SHIM_GET_ARG_32(0); - - XELOGD( - "VdSetSystemCommandBufferGpuIdentifierAddress(%.8X)", - unk); - - xeVdSetSystemCommandBufferGpuIdentifierAddress(unk); -} - - -// VdVerifyMEInitCommand -// r3 -// r4 = 19 -// no op? - - -// VdCallGraphicsNotificationRoutines -// r3 = 1 -// r4 = ? -// callbacks get 0, r3, r4 - - -SHIM_CALL VdIsHSIOTrainingSucceeded_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - XELOGD( - "VdIsHSIOTrainingSucceeded()"); - - // Not really sure what this should be - code does weird stuff here: - // (cntlzw r11, r3 / extrwi r11, r11, 1, 26) - SHIM_SET_RETURN(1); -} - - -SHIM_CALL VdPersistDisplay_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - XELOGD( - "VdPersistDisplay(?)"); - - // ? - SHIM_SET_RETURN(1); -} - - -SHIM_CALL VdRetrainEDRAMWorker_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t unk0 = SHIM_GET_ARG_32(0); - - XELOGD( - "VdRetrainEDRAMWorker(%.8X)", - unk0); - - SHIM_SET_RETURN(0); -} - - -SHIM_CALL VdRetrainEDRAM_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t unk0 = SHIM_GET_ARG_32(0); - uint32_t unk1 = SHIM_GET_ARG_32(1); - uint32_t unk2 = SHIM_GET_ARG_32(2); - uint32_t unk3 = SHIM_GET_ARG_32(3); - uint32_t unk4 = SHIM_GET_ARG_32(4); - uint32_t unk5 = SHIM_GET_ARG_32(5); - - XELOGD( - "VdRetrainEDRAM(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X)", - unk0, unk1, unk2, unk3, unk4, unk5); - - SHIM_SET_RETURN(0); -} - - -SHIM_CALL VdSwap_shim( - xe_ppc_state_t* ppc_state, KernelState* state) { - uint32_t unk0 = SHIM_GET_ARG_32(0); - uint32_t unk1 = SHIM_GET_ARG_32(1); - uint32_t unk2 = SHIM_GET_ARG_32(2); - uint32_t unk3 = SHIM_GET_ARG_32(3); - uint32_t unk4 = SHIM_GET_ARG_32(4); - uint32_t unk5 = SHIM_GET_ARG_32(5); - uint32_t unk6 = SHIM_GET_ARG_32(6); - uint32_t unk7 = SHIM_GET_ARG_32(7); - - XELOGD( - "VdSwap(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %.8X)", - unk0, - unk1, - unk2, - unk3, - unk4, - unk5, - unk6, - unk7); - + XEASSERTNOTNULL(state); + GraphicsSystem* gs = state->emulator()->graphics_system(); + if (!gs) { + return; + } + + // r3 = 0x2B10(d3d?) + 8 +} + + +SHIM_CALL VdSetSystemCommandBufferGpuIdentifierAddress_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t unk = SHIM_GET_ARG_32(0); + + XELOGD( + "VdSetSystemCommandBufferGpuIdentifierAddress(%.8X)", + unk); + + xeVdSetSystemCommandBufferGpuIdentifierAddress(unk); +} + + +// VdVerifyMEInitCommand +// r3 +// r4 = 19 +// no op? + + +// VdCallGraphicsNotificationRoutines +// r3 = 1 +// r4 = ? +// callbacks get 0, r3, r4 + + +SHIM_CALL VdIsHSIOTrainingSucceeded_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + XELOGD( + "VdIsHSIOTrainingSucceeded()"); + + // Not really sure what this should be - code does weird stuff here: + // (cntlzw r11, r3 / extrwi r11, r11, 1, 26) + SHIM_SET_RETURN(1); +} + + +SHIM_CALL VdPersistDisplay_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + XELOGD( + "VdPersistDisplay(?)"); + + // ? + SHIM_SET_RETURN(1); +} + + +SHIM_CALL VdRetrainEDRAMWorker_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t unk0 = SHIM_GET_ARG_32(0); + + XELOGD( + "VdRetrainEDRAMWorker(%.8X)", + unk0); + + SHIM_SET_RETURN(0); +} + + +SHIM_CALL VdRetrainEDRAM_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t unk0 = SHIM_GET_ARG_32(0); + uint32_t unk1 = SHIM_GET_ARG_32(1); + uint32_t unk2 = SHIM_GET_ARG_32(2); + uint32_t unk3 = SHIM_GET_ARG_32(3); + uint32_t unk4 = SHIM_GET_ARG_32(4); + uint32_t unk5 = SHIM_GET_ARG_32(5); + + XELOGD( + "VdRetrainEDRAM(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X)", + unk0, unk1, unk2, unk3, unk4, unk5); + + SHIM_SET_RETURN(0); +} + + +SHIM_CALL VdSwap_shim( + xe_ppc_state_t* ppc_state, KernelState* state) { + uint32_t unk0 = SHIM_GET_ARG_32(0); + uint32_t unk1 = SHIM_GET_ARG_32(1); + uint32_t unk2 = SHIM_GET_ARG_32(2); + uint32_t unk3 = SHIM_GET_ARG_32(3); + uint32_t unk4 = SHIM_GET_ARG_32(4); + uint32_t unk5 = SHIM_GET_ARG_32(5); + uint32_t unk6 = SHIM_GET_ARG_32(6); + uint32_t unk7 = SHIM_GET_ARG_32(7); + + XELOGD( + "VdSwap(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %.8X)", + unk0, + unk1, + unk2, + unk3, + unk4, + unk5, + unk6, + unk7); + KernelState* kernel_state = shared_kernel_state_; - XEASSERTNOTNULL(kernel_state); - GraphicsSystem* gs = kernel_state->processor()->graphics_system().get(); - if (!gs) { - return; - } - - gs->set_swap_pending(true); - - SHIM_SET_RETURN(0); -} - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -void xe::kernel::xboxkrnl::RegisterVideoExports( - ExportResolver* export_resolver, KernelState* state) { - SHIM_SET_MAPPING("xboxkrnl.exe", VdGetCurrentDisplayGamma, state); - SHIM_SET_MAPPING("xboxkrnl.exe", VdGetCurrentDisplayInformation, state); - SHIM_SET_MAPPING("xboxkrnl.exe", VdQueryVideoFlags, state); - SHIM_SET_MAPPING("xboxkrnl.exe", VdQueryVideoMode, state); - SHIM_SET_MAPPING("xboxkrnl.exe", VdInitializeEngines, state); - SHIM_SET_MAPPING("xboxkrnl.exe", VdSetGraphicsInterruptCallback, state); - SHIM_SET_MAPPING("xboxkrnl.exe", VdInitializeRingBuffer, state); + XEASSERTNOTNULL(kernel_state); + GraphicsSystem* gs = kernel_state->emulator()->graphics_system(); + if (!gs) { + return; + } + + gs->set_swap_pending(true); + + SHIM_SET_RETURN(0); +} + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +void xe::kernel::xboxkrnl::RegisterVideoExports( + ExportResolver* export_resolver, KernelState* state) { + SHIM_SET_MAPPING("xboxkrnl.exe", VdGetCurrentDisplayGamma, state); + SHIM_SET_MAPPING("xboxkrnl.exe", VdGetCurrentDisplayInformation, state); + SHIM_SET_MAPPING("xboxkrnl.exe", VdQueryVideoFlags, state); + SHIM_SET_MAPPING("xboxkrnl.exe", VdQueryVideoMode, state); + SHIM_SET_MAPPING("xboxkrnl.exe", VdInitializeEngines, state); + SHIM_SET_MAPPING("xboxkrnl.exe", VdSetGraphicsInterruptCallback, state); + SHIM_SET_MAPPING("xboxkrnl.exe", VdInitializeRingBuffer, state); SHIM_SET_MAPPING("xboxkrnl.exe", VdEnableRingBufferRPtrWriteBack, state); SHIM_SET_MAPPING("xboxkrnl.exe", VdGetSystemCommandBuffer, state); SHIM_SET_MAPPING("xboxkrnl.exe", @@ -447,40 +448,40 @@ void xe::kernel::xboxkrnl::RegisterVideoExports( SHIM_SET_MAPPING("xboxkrnl.exe", VdRetrainEDRAMWorker, state); SHIM_SET_MAPPING("xboxkrnl.exe", VdRetrainEDRAM, state); SHIM_SET_MAPPING("xboxkrnl.exe", VdSwap, state); - - xe_memory_ref memory = state->memory(); - uint8_t* mem = xe_memory_addr(memory); - - // VdGlobalDevice (4b) - // Pointer to a global D3D device. Games only seem to set this, so we don't - // have to do anything. We may want to read it back later, though. - uint32_t pVdGlobalDevice = xe_memory_heap_alloc(memory, 0, 4, 0); - export_resolver->SetVariableMapping( - "xboxkrnl.exe", ordinals::VdGlobalDevice, - pVdGlobalDevice); - XESETUINT32BE(mem + pVdGlobalDevice, 0); - - // VdGlobalXamDevice (4b) - // Pointer to the XAM D3D device, which we don't have. - uint32_t pVdGlobalXamDevice = xe_memory_heap_alloc(memory, 0, 4, 0); - export_resolver->SetVariableMapping( - "xboxkrnl.exe", ordinals::VdGlobalXamDevice, - pVdGlobalXamDevice); - XESETUINT32BE(mem + pVdGlobalXamDevice, 0); - - // VdGpuClockInMHz (4b) - // GPU clock. Xenos is 500MHz. Hope nothing is relying on this timing... - uint32_t pVdGpuClockInMHz = xe_memory_heap_alloc(memory, 0, 4, 0); - export_resolver->SetVariableMapping( - "xboxkrnl.exe", ordinals::VdGpuClockInMHz, - pVdGpuClockInMHz); - XESETUINT32BE(mem + pVdGpuClockInMHz, 500); - - // VdHSIOCalibrationLock (28b) - // CriticalSection. - uint32_t pVdHSIOCalibrationLock = xe_memory_heap_alloc(memory, 0, 28, 0); - export_resolver->SetVariableMapping( - "xboxkrnl.exe", ordinals::VdHSIOCalibrationLock, - pVdHSIOCalibrationLock); - xeRtlInitializeCriticalSectionAndSpinCount(pVdHSIOCalibrationLock, 10000); -} + + xe_memory_ref memory = state->memory(); + uint8_t* mem = xe_memory_addr(memory); + + // VdGlobalDevice (4b) + // Pointer to a global D3D device. Games only seem to set this, so we don't + // have to do anything. We may want to read it back later, though. + uint32_t pVdGlobalDevice = xe_memory_heap_alloc(memory, 0, 4, 0); + export_resolver->SetVariableMapping( + "xboxkrnl.exe", ordinals::VdGlobalDevice, + pVdGlobalDevice); + XESETUINT32BE(mem + pVdGlobalDevice, 0); + + // VdGlobalXamDevice (4b) + // Pointer to the XAM D3D device, which we don't have. + uint32_t pVdGlobalXamDevice = xe_memory_heap_alloc(memory, 0, 4, 0); + export_resolver->SetVariableMapping( + "xboxkrnl.exe", ordinals::VdGlobalXamDevice, + pVdGlobalXamDevice); + XESETUINT32BE(mem + pVdGlobalXamDevice, 0); + + // VdGpuClockInMHz (4b) + // GPU clock. Xenos is 500MHz. Hope nothing is relying on this timing... + uint32_t pVdGpuClockInMHz = xe_memory_heap_alloc(memory, 0, 4, 0); + export_resolver->SetVariableMapping( + "xboxkrnl.exe", ordinals::VdGpuClockInMHz, + pVdGpuClockInMHz); + XESETUINT32BE(mem + pVdGpuClockInMHz, 500); + + // VdHSIOCalibrationLock (28b) + // CriticalSection. + uint32_t pVdHSIOCalibrationLock = xe_memory_heap_alloc(memory, 0, 28, 0); + export_resolver->SetVariableMapping( + "xboxkrnl.exe", ordinals::VdHSIOCalibrationLock, + pVdHSIOCalibrationLock); + xeRtlInitializeCriticalSectionAndSpinCount(pVdHSIOCalibrationLock, 10000); +} diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_video.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.h similarity index 87% rename from src/xenia/kernel/modules/xboxkrnl/xboxkrnl_video.h rename to src/xenia/kernel/xboxkrnl/xboxkrnl_video.h index d6bdfe7c5..701b89d08 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_video.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_video.h @@ -1,57 +1,57 @@ -/** - ****************************************************************************** - * 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_KERNEL_MODULES_XBOXKRNL_VIDEO_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_VIDEO_H_ - -#include -#include - -#include - - -namespace xe { -namespace kernel { -namespace xboxkrnl { - - -// http://ffplay360.googlecode.com/svn/trunk/Common/XTLOnPC.h -#pragma pack(push, 1) -typedef struct { - uint32_t display_width; - uint32_t display_height; - uint32_t is_interlaced; - uint32_t is_widescreen; - uint32_t is_hi_def; - float refresh_rate; - uint32_t video_standard; - uint32_t unknown_0x8a; - uint32_t unknown_0x01; - uint32_t reserved[3]; -} -X_VIDEO_MODE; -#pragma pack(pop) -XEASSERTSTRUCTSIZE(X_VIDEO_MODE, 48); - -void xeVdGetCurrentDisplayGamma(uint32_t* arg0, float* arg1); -uint32_t xeVdQueryVideoFlags(); -void xeVdQueryVideoMode(X_VIDEO_MODE *video_mode, bool swap); - -void xeVdInitializeEngines(uint32_t unk0, uint32_t callback, uint32_t unk1, - uint32_t unk2_ptr, uint32_t unk3_ptr); -void xeVdSetGraphicsInterruptCallback(uint32_t callback, uint32_t user_data); -void xeVdEnableRingBufferRPtrWriteBack(uint32_t ptr, uint32_t block_size); - - -} // namespace xboxkrnl -} // namespace kernel -} // namespace xe - - -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_VIDEO_H_ +/** + ****************************************************************************** + * 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_KERNEL_XBOXKRNL_VIDEO_H_ +#define XENIA_KERNEL_XBOXKRNL_VIDEO_H_ + +#include +#include + +#include + + +namespace xe { +namespace kernel { +namespace xboxkrnl { + + +// http://ffplay360.googlecode.com/svn/trunk/Common/XTLOnPC.h +#pragma pack(push, 1) +typedef struct { + uint32_t display_width; + uint32_t display_height; + uint32_t is_interlaced; + uint32_t is_widescreen; + uint32_t is_hi_def; + float refresh_rate; + uint32_t video_standard; + uint32_t unknown_0x8a; + uint32_t unknown_0x01; + uint32_t reserved[3]; +} +X_VIDEO_MODE; +#pragma pack(pop) +XEASSERTSTRUCTSIZE(X_VIDEO_MODE, 48); + +void xeVdGetCurrentDisplayGamma(uint32_t* arg0, float* arg1); +uint32_t xeVdQueryVideoFlags(); +void xeVdQueryVideoMode(X_VIDEO_MODE *video_mode, bool swap); + +void xeVdInitializeEngines(uint32_t unk0, uint32_t callback, uint32_t unk1, + uint32_t unk2_ptr, uint32_t unk3_ptr); +void xeVdSetGraphicsInterruptCallback(uint32_t callback, uint32_t user_data); +void xeVdEnableRingBufferRPtrWriteBack(uint32_t ptr, uint32_t block_size); + + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe + + +#endif // XENIA_KERNEL_XBOXKRNL_VIDEO_H_ diff --git a/src/xenia/kernel/modules/xboxkrnl/xobject.cc b/src/xenia/kernel/xboxkrnl/xobject.cc similarity index 94% rename from src/xenia/kernel/modules/xboxkrnl/xobject.cc rename to src/xenia/kernel/xboxkrnl/xobject.cc index dc1cfc75e..6a4c6867a 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xobject.cc +++ b/src/xenia/kernel/xboxkrnl/xobject.cc @@ -7,10 +7,10 @@ ****************************************************************************** */ -#include +#include -#include -#include +#include +#include using namespace xe; @@ -31,14 +31,6 @@ XObject::~XObject() { XEASSERTZERO(pointer_ref_count_); } -Runtime* XObject::runtime() { - return kernel_state_->runtime_; -} - -KernelState* XObject::kernel_state() { - return kernel_state_; -} - xe_memory_ref XObject::memory() { return kernel_state_->memory(); } @@ -183,4 +175,4 @@ XObject* XObject::GetObject(KernelState* kernel_state, void* native_ptr) { XObject::UnlockType(); return object; } -} \ No newline at end of file +} diff --git a/src/xenia/kernel/modules/xboxkrnl/xobject.h b/src/xenia/kernel/xboxkrnl/xobject.h similarity index 83% rename from src/xenia/kernel/modules/xboxkrnl/xobject.h rename to src/xenia/kernel/xboxkrnl/xobject.h index 41b981715..852ec0bca 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xobject.h +++ b/src/xenia/kernel/xboxkrnl/xobject.h @@ -7,19 +7,12 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_MODULES_XBOXKRNL_XOBJECT_H_ -#define XENIA_KERNEL_MODULES_XBOXKRNL_XOBJECT_H_ +#ifndef XENIA_KERNEL_XBOXKRNL_XOBJECT_H_ +#define XENIA_KERNEL_XBOXKRNL_XOBJECT_H_ -#include +#include -#include - - -namespace xe { -namespace kernel { - class Runtime; -} -} +#include namespace xe { @@ -48,7 +41,8 @@ public: XObject(KernelState* kernel_state, Type type); virtual ~XObject(); - KernelState* kernel_state(); + Emulator* emulator() const { return kernel_state_->emulator_; } + KernelState* kernel_state() const { return kernel_state_; } Type type(); X_HANDLE handle() const; @@ -70,13 +64,12 @@ public: static XObject* GetObject(KernelState* kernel_state, void* native_ptr); protected: - Runtime* runtime(); xe_memory_ref memory(); // unretained void SetNativePointer(uint32_t native_ptr); -private: KernelState* kernel_state_; +private: volatile int32_t handle_ref_count_; volatile int32_t pointer_ref_count_; @@ -90,4 +83,4 @@ private: } // namespace xe -#endif // XENIA_KERNEL_MODULES_XBOXKRNL_XOBJECT_H_ +#endif // XENIA_KERNEL_XBOXKRNL_XOBJECT_H_ diff --git a/src/xenia/logging.h b/src/xenia/logging.h index 0856e2959..7c1fe00ec 100644 --- a/src/xenia/logging.h +++ b/src/xenia/logging.h @@ -64,6 +64,11 @@ void xe_log_line(const char* file_path, const uint32_t line_number, #else #define XELOGSDB(fmt, ...) XE_EMPTY_MACRO #endif +#if XE_OPTION(LOG_APU) +#define XELOGAPU(fmt, ...) XELOGCORE('A', fmt, ##__VA_ARGS__) +#else +#define XELOGAPU(fmt, ...) XE_EMPTY_MACRO +#endif #if XE_OPTION(LOG_GPU) #define XELOGGPU(fmt, ...) XELOGCORE('G', fmt, ##__VA_ARGS__) #else diff --git a/src/xenia/core/memory.cc b/src/xenia/memory.cc similarity index 99% rename from src/xenia/core/memory.cc rename to src/xenia/memory.cc index 37f476e38..b7127af34 100644 --- a/src/xenia/core/memory.cc +++ b/src/xenia/memory.cc @@ -7,13 +7,13 @@ ****************************************************************************** */ -#include +#include #include #include // TODO(benvanik): move xbox.h out -#include +#include #if !XE_PLATFORM(WIN32) #include diff --git a/src/xenia/core/memory.h b/src/xenia/memory.h similarity index 100% rename from src/xenia/core/memory.h rename to src/xenia/memory.h diff --git a/src/xenia/sources.gypi b/src/xenia/sources.gypi index 82fbe4627..4977a09f6 100644 --- a/src/xenia/sources.gypi +++ b/src/xenia/sources.gypi @@ -7,20 +7,28 @@ 'common.h', 'config.h', 'core.h', + 'emulator.cc', + 'emulator.h', + 'export_resolver.cc', + 'export_resolver.h', 'logging.cc', 'logging.h', 'malloc.cc', 'malloc.h', + 'memory.cc', + 'memory.h', 'platform.cc', 'platform.h', 'platform_includes.h', 'string.cc', 'string.h', 'types.h', + 'xbox.h', 'xenia.h', ], 'includes': [ + 'apu/sources.gypi', 'core/sources.gypi', 'cpu/sources.gypi', 'dbg/sources.gypi', diff --git a/src/xenia/types.h b/src/xenia/types.h index a213dc205..d375857ef 100644 --- a/src/xenia/types.h +++ b/src/xenia/types.h @@ -24,6 +24,21 @@ using std::tr1::shared_ptr; #define XEUNREFERENCED(expr) (void)(expr) +#define XEDECLARECLASS1(ns1, name) \ + namespace ns1 { class name; } +#define XEDECLARECLASS2(ns1, ns2, name) \ + namespace ns1 { namespace ns2 { \ + class name; \ + } } +#define XEDECLARECLASS3(ns1, ns2, ns3, name) \ + namespace ns1 { namespace ns2 { namespace ns3 { \ + class name; \ + } } } +#define XEDECLARECLASS4(ns1, ns2, ns3, ns4, name) \ + namespace ns1 { namespace ns2 { namespace ns3 { namespace ns4 { \ + class name; \ + } } } } + #if XE_COMPILER(MSVC) #define XEASSUME(expr) __analysis_assume(expr) #else diff --git a/src/xenia/kernel/xbox.h b/src/xenia/xbox.h similarity index 97% rename from src/xenia/kernel/xbox.h rename to src/xenia/xbox.h index 3baa5e538..2321c46d8 100644 --- a/src/xenia/kernel/xbox.h +++ b/src/xenia/xbox.h @@ -7,15 +7,14 @@ ****************************************************************************** */ -#ifndef XENIA_KERNEL_XBOX_H_ -#define XENIA_KERNEL_XBOX_H_ +#ifndef XENIA_XBOX_H_ +#define XENIA_XBOX_H_ #include #include namespace xe { -namespace kernel { typedef uint32_t X_HANDLE; @@ -122,64 +121,64 @@ typedef enum _X_FILE_ATTRIBUTES { } X_FILE_ATTRIBUTES; -typedef enum _X_FILE_INFORMATION_CLASS { - XFileDirectoryInformation = 1, - XFileFullDirectoryInformation, - XFileBothDirectoryInformation, - XFileBasicInformation, - XFileStandardInformation, - XFileInternalInformation, - XFileEaInformation, - XFileAccessInformation, - XFileNameInformation, - XFileRenameInformation, - XFileLinkInformation, - XFileNamesInformation, - XFileDispositionInformation, - XFilePositionInformation, - XFileFullEaInformation, - XFileModeInformation, - XFileAlignmentInformation, - XFileAllInformation, - XFileAllocationInformation, - XFileEndOfFileInformation, - XFileAlternateNameInformation, - XFileStreamInformation, - XFilePipeInformation, - XFilePipeLocalInformation, - XFilePipeRemoteInformation, - XFileMailslotQueryInformation, - XFileMailslotSetInformation, - XFileCompressionInformation, - XFileObjectIdInformation, - XFileCompletionInformation, - XFileMoveClusterInformation, - XFileQuotaInformation, - XFileReparsePointInformation, - XFileNetworkOpenInformation, - XFileAttributeTagInformation, - XFileTrackingInformation, - XFileIdBothDirectoryInformation, - XFileIdFullDirectoryInformation, - XFileValidDataLengthInformation, - XFileShortNameInformation, - XFileIoCompletionNotificationInformation, - XFileIoStatusBlockRangeInformation, - XFileIoPriorityHintInformation, - XFileSfioReserveInformation, - XFileSfioVolumeInformation, - XFileHardLinkInformation, - XFileProcessIdsUsingFileInformation, - XFileNormalizedNameInformation, - XFileNetworkPhysicalNameInformation, - XFileIdGlobalTxDirectoryInformation, - XFileIsRemoteDeviceInformation, - XFileAttributeCacheInformation, - XFileNumaNodeInformation, - XFileStandardLinkInformation, - XFileRemoteProtocolInformation, - XFileReplaceCompletionInformation, - XFileMaximumInformation +typedef enum _X_FILE_INFORMATION_CLASS { + XFileDirectoryInformation = 1, + XFileFullDirectoryInformation, + XFileBothDirectoryInformation, + XFileBasicInformation, + XFileStandardInformation, + XFileInternalInformation, + XFileEaInformation, + XFileAccessInformation, + XFileNameInformation, + XFileRenameInformation, + XFileLinkInformation, + XFileNamesInformation, + XFileDispositionInformation, + XFilePositionInformation, + XFileFullEaInformation, + XFileModeInformation, + XFileAlignmentInformation, + XFileAllInformation, + XFileAllocationInformation, + XFileEndOfFileInformation, + XFileAlternateNameInformation, + XFileStreamInformation, + XFilePipeInformation, + XFilePipeLocalInformation, + XFilePipeRemoteInformation, + XFileMailslotQueryInformation, + XFileMailslotSetInformation, + XFileCompressionInformation, + XFileObjectIdInformation, + XFileCompletionInformation, + XFileMoveClusterInformation, + XFileQuotaInformation, + XFileReparsePointInformation, + XFileNetworkOpenInformation, + XFileAttributeTagInformation, + XFileTrackingInformation, + XFileIdBothDirectoryInformation, + XFileIdFullDirectoryInformation, + XFileValidDataLengthInformation, + XFileShortNameInformation, + XFileIoCompletionNotificationInformation, + XFileIoStatusBlockRangeInformation, + XFileIoPriorityHintInformation, + XFileSfioReserveInformation, + XFileSfioVolumeInformation, + XFileHardLinkInformation, + XFileProcessIdsUsingFileInformation, + XFileNormalizedNameInformation, + XFileNetworkPhysicalNameInformation, + XFileIdGlobalTxDirectoryInformation, + XFileIsRemoteDeviceInformation, + XFileAttributeCacheInformation, + XFileNumaNodeInformation, + XFileStandardLinkInformation, + XFileRemoteProtocolInformation, + XFileReplaceCompletionInformation, + XFileMaximumInformation } X_FILE_INFORMATION_CLASS; @@ -243,8 +242,7 @@ public: }; -} // namespace kernel } // namespace xe -#endif // XENIA_KERNEL_XBOX_H_ +#endif // XENIA_XBOX_H_ diff --git a/src/xenia/xenia.h b/src/xenia/xenia.h index bca9f567e..853d6e335 100644 --- a/src/xenia/xenia.h +++ b/src/xenia/xenia.h @@ -12,9 +12,14 @@ #include #include +#include +#include + +#include #include #include #include #include + #endif // XENIA_H_ diff --git a/tools/tools.gypi b/tools/tools.gypi index 4abe34578..d33b4e16c 100644 --- a/tools/tools.gypi +++ b/tools/tools.gypi @@ -2,6 +2,6 @@ { 'includes': [ 'xenia-run/xenia-run.gypi', - 'xenia-test/xenia-test.gypi', + #'xenia-test/xenia-test.gypi', ], } diff --git a/tools/xenia-run/xenia-run.cc b/tools/xenia-run/xenia-run.cc index 8bd7dcb9a..c78454ffe 100644 --- a/tools/xenia-run/xenia-run.cc +++ b/tools/xenia-run/xenia-run.cc @@ -13,111 +13,17 @@ using namespace xe; -using namespace xe::cpu; -using namespace xe::gpu; -using namespace xe::dbg; -using namespace xe::kernel; DEFINE_string(target, "", "Specifies the target .xex or .iso to execute."); -class Run { -public: - Run(); - ~Run(); - - int Setup(); - int Launch(const xechar_t* path); - -private: - xe_memory_ref memory_; - xe_run_loop_ref run_loop_; - shared_ptr backend_; - shared_ptr graphics_system_; - shared_ptr processor_; - shared_ptr runtime_; - shared_ptr debugger_; -}; - -Run::Run() : - memory_(0), run_loop_(0) { -} - -Run::~Run() { - xe_run_loop_release(run_loop_); - xe_memory_release(memory_); -} - -int Run::Setup() { - CreationParams params; - - xe_pal_options_t pal_options; - xe_zero_struct(&pal_options, sizeof(pal_options)); - XEEXPECTZERO(xe_pal_init(pal_options)); - - xe_memory_options_t memory_options; - xe_zero_struct(&memory_options, sizeof(memory_options)); - memory_ = xe_memory_create(memory_options); - XEEXPECTNOTNULL(memory_); - - backend_ = shared_ptr(new xe::cpu::x64::X64Backend()); - - params.memory = memory_; - graphics_system_ = shared_ptr(xe::gpu::Create(¶ms)); - - debugger_ = shared_ptr(new Debugger()); - - processor_ = shared_ptr(new Processor(memory_, backend_)); - processor_->set_graphics_system(graphics_system_); - graphics_system_->set_processor(processor_); - - XEEXPECTZERO(processor_->Setup()); - - runtime_ = shared_ptr(new Runtime(processor_, XT(""))); - processor_->set_export_resolver(runtime_->export_resolver()); - - return 0; -XECLEANUP: - return 1; -} - -int Run::Launch(const xechar_t* path) { - // Normalize the path and make absolute. - // TODO(benvanik): move this someplace common. - xechar_t abs_path[XE_MAX_PATH]; - xe_path_get_absolute(path, abs_path, XECOUNT(abs_path)); - - // Grab file extension. - const xechar_t* dot = xestrrchr(abs_path, '.'); - if (!dot) { - XELOGE("Invalid input path; no extension found"); - return 1; - } - - // Run the debugger. - // This may pause waiting for connections. - if (debugger_->Startup()) { - XELOGE("Debugger failed to start up"); - return 1; - } - - // Launch based on file type. - // This is a silly guess based on file extension. - // NOTE: the runtime launch routine will wait until the module exits. - if (xestrcmp(dot, XT(".xex")) == 0) { - // Treat as a naked xex file. - return runtime_->LaunchXexFile(abs_path); - } else { - // Assume a disc image. - return runtime_->LaunchDiscImage(abs_path); - } -} - int xenia_run(int argc, xechar_t** argv) { int result_code = 1; + Emulator* emulator = NULL; + // Grab path from the flag or unnamed argument. if (!FLAGS_target.size() && argc < 2) { google::ShowUsageWithFlags("xenia-run"); @@ -135,15 +41,50 @@ int xenia_run(int argc, xechar_t** argv) { path = argv[1]; } - auto_ptr run = auto_ptr(new Run()); + // Create platform abstraction layer. + xe_pal_options_t pal_options; + xe_zero_struct(&pal_options, sizeof(pal_options)); + XEEXPECTZERO(xe_pal_init(pal_options)); - result_code = run->Setup(); - XEEXPECTZERO(result_code); + // Normalize the path and make absolute. + // TODO(benvanik): move this someplace common. + xechar_t abs_path[XE_MAX_PATH]; + xe_path_get_absolute(path, abs_path, XECOUNT(abs_path)); - run->Launch(path); + // Grab file extension. + const xechar_t* dot = xestrrchr(abs_path, '.'); + if (!dot) { + XELOGE("Invalid input path; no extension found"); + return 1; + } + + // Create the emulator. + emulator = new Emulator(XT("")); + XEEXPECTNOTNULL(emulator); + X_STATUS result = emulator->Setup(); + if (XFAILED(result)) { + XELOGE("Failed to setup emulator: %.8X", result); + XEFAIL(); + } + + // Launch based on file type. + // This is a silly guess based on file extension. + // NOTE: the runtime launch routine will wait until the module exits. + if (xestrcmp(dot, XT(".xex")) == 0) { + // Treat as a naked xex file. + result = emulator->LaunchXexFile(abs_path); + } else { + // Assume a disc image. + result = emulator->LaunchDiscImage(abs_path); + } + if (XFAILED(result)) { + XELOGE("Failed to launch target: %.8X", result); + XEFAIL(); + } result_code = 0; XECLEANUP: + delete emulator; return result_code; } XE_MAIN_THUNK(xenia_run, "xenia-run some.xex"); diff --git a/xenia.gyp b/xenia.gyp index aa4702fda..0c344ce56 100644 --- a/xenia.gyp +++ b/xenia.gyp @@ -70,7 +70,6 @@ { 'files': [ # Depending on which SDK you have... - '<(windows_sdk_dir)/redist/d3d/x64/d3dcompiler_46.dll', '<(windows_sdk_dir)/redist/d3d/x64/d3dcompiler_47.dll', ], 'destination': '<(PRODUCT_DIR)',