diff --git a/src/xenia/cpu/export_resolver.cc b/src/xenia/cpu/export_resolver.cc index 79b7f7e9f..db829ee7d 100644 --- a/src/xenia/cpu/export_resolver.cc +++ b/src/xenia/cpu/export_resolver.cc @@ -22,15 +22,10 @@ ExportResolver::~ExportResolver() {} void ExportResolver::RegisterTable(const std::string& library_name, Export* exports, const size_t count) { tables_.emplace_back(library_name, exports, count); - - for (size_t n = 0; n < count; n++) { - exports[n].variable_ptr = 0; - exports[n].function_data.shim = nullptr; - } } Export* ExportResolver::GetExportByOrdinal(const std::string& library_name, - const uint32_t ordinal) { + uint16_t ordinal) { for (const auto& table : tables_) { if (table.name == library_name || table.simple_name == library_name) { // TODO(benvanik): binary search? @@ -46,8 +41,7 @@ Export* ExportResolver::GetExportByOrdinal(const std::string& library_name, } void ExportResolver::SetVariableMapping(const std::string& library_name, - const uint32_t ordinal, - uint32_t value) { + uint16_t ordinal, uint32_t value) { auto export = GetExportByOrdinal(library_name, ordinal); assert_not_null(export); export->tags |= ExportTag::kImplemented; @@ -55,7 +49,7 @@ void ExportResolver::SetVariableMapping(const std::string& library_name, } void ExportResolver::SetFunctionMapping(const std::string& library_name, - const uint32_t ordinal, + uint16_t ordinal, xe_kernel_export_shim_fn shim) { auto export = GetExportByOrdinal(library_name, ordinal); assert_not_null(export); @@ -63,5 +57,14 @@ void ExportResolver::SetFunctionMapping(const std::string& library_name, export->function_data.shim = shim; } +void ExportResolver::SetFunctionMapping(const std::string& library_name, + uint16_t ordinal, + ExportTrampoline trampoline) { + auto export = GetExportByOrdinal(library_name, ordinal); + assert_not_null(export); + export->tags |= ExportTag::kImplemented; + export->function_data.trampoline = trampoline; +} + } // namespace cpu } // namespace xe diff --git a/src/xenia/cpu/export_resolver.h b/src/xenia/cpu/export_resolver.h index 8b59985c8..19dd4dccd 100644 --- a/src/xenia/cpu/export_resolver.h +++ b/src/xenia/cpu/export_resolver.h @@ -40,6 +40,8 @@ struct ExportTag { // DEPRECATED typedef void (*xe_kernel_export_shim_fn)(void*, void*); +typedef void (*ExportTrampoline)(xe::cpu::frontend::PPCContext* ppc_context); + class Export { public: enum class Type { @@ -47,14 +49,19 @@ class Export { kVariable = 1, }; - uint32_t ordinal; + Export(uint16_t ordinal, Type type, std::string name) + : ordinal(ordinal), + type(type), + name(name), + tags(0), + variable_ptr(0), + function_data({nullptr, nullptr, 0}) {} + + uint16_t ordinal; Type type; std::string name; ExportTag::type tags; - void (*trampoline)(xe::cpu::frontend::PPCContext* ppc_context); - uint64_t call_count; - bool is_implemented() const { return (tags & ExportTag::kImplemented) == ExportTag::kImplemented; } @@ -66,10 +73,13 @@ class Export { uint32_t variable_ptr; struct { - // Shimmed implementation. - // This is called directly from generated code. - // It should parse args, do fixups, and call the impl. + // DEPRECATED xe_kernel_export_shim_fn shim; + + // Trampoline that is called from the guest-to-host thunk. + // Expects only PPC context as first arg. + ExportTrampoline trampoline; + uint64_t call_count; } function_data; }; }; @@ -82,14 +92,14 @@ class ExportResolver { void RegisterTable(const std::string& library_name, Export* exports, const size_t count); - Export* GetExportByOrdinal(const std::string& library_name, - const uint32_t ordinal); + Export* GetExportByOrdinal(const std::string& library_name, uint16_t ordinal); - void SetVariableMapping(const std::string& library_name, - const uint32_t ordinal, uint32_t value); - void SetFunctionMapping(const std::string& library_name, - const uint32_t ordinal, + void SetVariableMapping(const std::string& library_name, uint16_t ordinal, + uint32_t value); + void SetFunctionMapping(const std::string& library_name, uint16_t ordinal, xe_kernel_export_shim_fn shim); + void SetFunctionMapping(const std::string& library_name, uint16_t ordinal, + ExportTrampoline trampoline); private: struct ExportTable { diff --git a/src/xenia/cpu/frontend/ppc_frontend.cc b/src/xenia/cpu/frontend/ppc_frontend.cc index 071fe216a..5dc9148ed 100644 --- a/src/xenia/cpu/frontend/ppc_frontend.cc +++ b/src/xenia/cpu/frontend/ppc_frontend.cc @@ -57,18 +57,18 @@ PPCFrontend::~PPCFrontend() { Memory* PPCFrontend::memory() const { return processor_->memory(); } -void CheckGlobalLock(PPCContext* ppc_state, void* arg0, void* arg1) { - ppc_state->scratch = 0x8000; +void CheckGlobalLock(PPCContext* ppc_context, void* arg0, void* arg1) { + ppc_context->scratch = 0x8000; } -void HandleGlobalLock(PPCContext* ppc_state, void* arg0, void* arg1) { +void HandleGlobalLock(PPCContext* ppc_context, void* arg0, void* arg1) { auto global_lock = reinterpret_cast(arg0); volatile bool* global_lock_taken = reinterpret_cast(arg1); - uint64_t value = ppc_state->scratch; + uint64_t value = ppc_context->scratch; if (value == 0x8000) { global_lock->lock(); *global_lock_taken = false; global_lock->unlock(); - } else if (value == ppc_state->r[13]) { + } else if (value == ppc_context->r[13]) { global_lock->lock(); *global_lock_taken = true; global_lock->unlock(); diff --git a/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.cc b/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.cc index 1e268ab24..e43f199f5 100644 --- a/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.cc +++ b/src/xenia/cpu/frontend/test/xe-cpu-ppc-test.cc @@ -233,13 +233,13 @@ class TestRunner { } bool SetupTestState(TestCase& test_case) { - auto ppc_state = thread_state->context(); + auto ppc_context = thread_state->context(); for (auto& it : test_case.annotations) { if (it.first == "REGISTER_IN") { size_t space_pos = it.second.find(" "); auto reg_name = it.second.substr(0, space_pos); auto reg_value = it.second.substr(space_pos + 1); - ppc_state->SetRegFromString(reg_name.c_str(), reg_value.c_str()); + ppc_context->SetRegFromString(reg_name.c_str(), reg_value.c_str()); } else if (it.first == "MEMORY_IN") { size_t space_pos = it.second.find(" "); auto address_str = it.second.substr(0, space_pos); @@ -264,7 +264,7 @@ class TestRunner { } bool CheckTestResults(TestCase& test_case) { - auto ppc_state = thread_state->context(); + auto ppc_context = thread_state->context(); char actual_value[2048]; @@ -274,9 +274,9 @@ class TestRunner { size_t space_pos = it.second.find(" "); auto reg_name = it.second.substr(0, space_pos); auto reg_value = it.second.substr(space_pos + 1); - if (!ppc_state->CompareRegWithString(reg_name.c_str(), - reg_value.c_str(), actual_value, - xe::countof(actual_value))) { + if (!ppc_context->CompareRegWithString(reg_name.c_str(), + reg_value.c_str(), actual_value, + xe::countof(actual_value))) { any_failed = true; printf("Register %s assert failed:\n", reg_name.c_str()); printf(" Expected: %s == %s\n", reg_name.c_str(), reg_value.c_str()); diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index e874d97bb..7c01f6810 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -34,10 +34,10 @@ void UndefinedImport(PPCContext* ppc_context, XELOGE("call to undefined import"); } -XexModule::XexModule(Processor* processor, KernelState* state) +XexModule::XexModule(Processor* processor, KernelState* kernel_state) : Module(processor), processor_(processor), - kernel_state_(state), + kernel_state_(kernel_state), xex_(nullptr), base_address_(0), low_address_(0), diff --git a/src/xenia/cpu/xex_module.h b/src/xenia/cpu/xex_module.h index 6806b912c..bfedb21d4 100644 --- a/src/xenia/cpu/xex_module.h +++ b/src/xenia/cpu/xex_module.h @@ -26,7 +26,7 @@ class Runtime; class XexModule : public xe::cpu::Module { public: - XexModule(Processor* processor, kernel::KernelState* state); + XexModule(Processor* processor, kernel::KernelState* kernel_state); virtual ~XexModule(); xe_xex2_ref xex() const { return xex_; } diff --git a/src/xenia/kernel/util/export_table_pre.inc b/src/xenia/kernel/util/export_table_pre.inc index 995d8e698..e17068901 100644 --- a/src/xenia/kernel/util/export_table_pre.inc +++ b/src/xenia/kernel/util/export_table_pre.inc @@ -24,10 +24,6 @@ #define XE_EXPORT(module, ordinal, name, type) \ - { \ - ordinal, \ - xe::cpu::Export::Type::type, \ - #name, \ - } + xe::cpu::Export(ordinal, xe::cpu::Export::Type::type, #name) #define FLAG(t) kXEKernelExportFlag##t diff --git a/src/xenia/kernel/util/shim_utils.h b/src/xenia/kernel/util/shim_utils.h index c94374782..e1d347e08 100644 --- a/src/xenia/kernel/util/shim_utils.h +++ b/src/xenia/kernel/util/shim_utils.h @@ -24,8 +24,8 @@ using PPCContext = xe::cpu::frontend::PPCContext; library_name, ordinals::##export_name, \ (xe::cpu::xe_kernel_export_shim_fn)export_name##_shim); -#define SHIM_MEM_BASE ppc_state->virtual_membase -#define SHIM_MEM_ADDR(a) (a ? (ppc_state->virtual_membase + a) : nullptr) +#define SHIM_MEM_BASE ppc_context->virtual_membase +#define SHIM_MEM_ADDR(a) (a ? (ppc_context->virtual_membase + a) : nullptr) #define SHIM_MEM_8(a) xe::load_and_swap(SHIM_MEM_ADDR(a)) #define SHIM_MEM_16(a) xe::load_and_swap(SHIM_MEM_ADDR(a)) @@ -36,11 +36,11 @@ using PPCContext = xe::cpu::frontend::PPCContext; #define SHIM_SET_MEM_32(a, v) xe::store_and_swap(SHIM_MEM_ADDR(a), v) #define SHIM_SET_MEM_64(a, v) xe::store_and_swap(SHIM_MEM_ADDR(a), v) -#define SHIM_GET_ARG_8(n) (uint8_t)(ppc_state->r[3 + n]) -#define SHIM_GET_ARG_16(n) (uint16_t)(ppc_state->r[3 + n]) -#define SHIM_GET_ARG_32(n) (uint32_t)(ppc_state->r[3 + n]) -#define SHIM_GET_ARG_64(n) ppc_state->r[3 + n] -#define SHIM_SET_RETURN_32(v) ppc_state->r[3] = (uint64_t)((int32_t)v) +#define SHIM_GET_ARG_8(n) (uint8_t)(ppc_context->r[3 + n]) +#define SHIM_GET_ARG_16(n) (uint16_t)(ppc_context->r[3 + n]) +#define SHIM_GET_ARG_32(n) (uint32_t)(ppc_context->r[3 + n]) +#define SHIM_GET_ARG_64(n) ppc_context->r[3 + n] +#define SHIM_SET_RETURN_32(v) ppc_context->r[3] = (uint64_t)((int32_t)v) #define SHIM_STRUCT(type, address) \ reinterpret_cast(SHIM_MEM_ADDR(address)) diff --git a/src/xenia/kernel/xam_content.cc b/src/xenia/kernel/xam_content.cc index de173c79e..d29c54ff8 100644 --- a/src/xenia/kernel/xam_content.cc +++ b/src/xenia/kernel/xam_content.cc @@ -28,8 +28,8 @@ static const DeviceInfo dummy_device_info_ = { 0xF00D0000, 1, 1024 * 1024 * 1024, 1024 * 1024 * 1024, L"Dummy HDD", }; -SHIM_CALL XamContentGetLicenseMask_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamContentGetLicenseMask_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t mask_ptr = SHIM_GET_ARG_32(0); uint32_t overlapped_ptr = SHIM_GET_ARG_32(1); @@ -41,15 +41,15 @@ SHIM_CALL XamContentGetLicenseMask_shim(PPCContext* ppc_state, SHIM_SET_MEM_32(mask_ptr, 0xFFFFFFFF); if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } } -SHIM_CALL XamShowDeviceSelectorUI_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamShowDeviceSelectorUI_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t content_type = SHIM_GET_ARG_32(1); uint32_t content_flags = SHIM_GET_ARG_32(2); @@ -75,15 +75,15 @@ SHIM_CALL XamShowDeviceSelectorUI_shim(PPCContext* ppc_state, X_RESULT result = X_ERROR_SUCCESS; if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamContentGetDeviceName_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamContentGetDeviceName_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t device_id = SHIM_GET_ARG_32(0); uint32_t name_ptr = SHIM_GET_ARG_32(1); uint32_t name_capacity = SHIM_GET_ARG_32(2); @@ -107,8 +107,8 @@ SHIM_CALL XamContentGetDeviceName_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamContentGetDeviceState_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamContentGetDeviceState_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t device_id = SHIM_GET_ARG_32(0); uint32_t overlapped_ptr = SHIM_GET_ARG_32(1); @@ -116,9 +116,9 @@ SHIM_CALL XamContentGetDeviceState_shim(PPCContext* ppc_state, if ((device_id & 0xFFFF0000) != dummy_device_info_.device_id) { if (overlapped_ptr) { - state->CompleteOverlappedImmediateEx(overlapped_ptr, - X_ERROR_FUNCTION_FAILED, - X_ERROR_DEVICE_NOT_CONNECTED, 0); + kernel_state->CompleteOverlappedImmediateEx( + overlapped_ptr, X_ERROR_FUNCTION_FAILED, X_ERROR_DEVICE_NOT_CONNECTED, + 0); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_DEVICE_NOT_CONNECTED); @@ -127,15 +127,15 @@ SHIM_CALL XamContentGetDeviceState_shim(PPCContext* ppc_state, } if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } } -SHIM_CALL XamContentGetDeviceData_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamContentGetDeviceData_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t device_id = SHIM_GET_ARG_32(0); uint32_t device_data_ptr = SHIM_GET_ARG_32(1); @@ -158,7 +158,8 @@ SHIM_CALL XamContentGetDeviceData_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamContentResolve_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamContentResolve_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t content_data_ptr = SHIM_GET_ARG_32(1); uint32_t buffer_ptr = SHIM_GET_ARG_32(2); @@ -182,8 +183,8 @@ SHIM_CALL XamContentResolve_shim(PPCContext* ppc_state, KernelState* state) { } // http://gameservice.googlecode.com/svn-history/r14/trunk/ContentManager.cpp -SHIM_CALL XamContentCreateEnumerator_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamContentCreateEnumerator_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t device_id = SHIM_GET_ARG_32(1); uint32_t content_type = SHIM_GET_ARG_32(2); @@ -210,12 +211,13 @@ SHIM_CALL XamContentCreateEnumerator_shim(PPCContext* ppc_state, SHIM_SET_MEM_32(buffer_size_ptr, item_count * XCONTENT_DATA::kSize); } - auto e = new XStaticEnumerator(state, item_count, XCONTENT_DATA::kSize); + auto e = + new XStaticEnumerator(kernel_state, item_count, XCONTENT_DATA::kSize); e->Initialize(); // Get all content data. auto content_datas = - state->content_manager()->ListContent(device_id, content_type); + kernel_state->content_manager()->ListContent(device_id, content_type); for (auto& content_data : content_datas) { auto ptr = e->AppendItem(); if (!ptr) { @@ -230,7 +232,7 @@ SHIM_CALL XamContentCreateEnumerator_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -void XamContentCreateCore(PPCContext* ppc_state, KernelState* state, +void XamContentCreateCore(PPCContext* ppc_context, KernelState* kernel_state, uint32_t user_index, std::string root_name, XCONTENT_DATA content_data, uint32_t flags, uint32_t disposition_ptr, uint32_t license_mask_ptr, @@ -240,7 +242,7 @@ void XamContentCreateCore(PPCContext* ppc_state, KernelState* state, X_RESULT result = X_ERROR_INVALID_PARAMETER; - auto content_manager = state->content_manager(); + auto content_manager = kernel_state->content_manager(); bool create = false; bool open = false; switch (flags & 0xF) { @@ -308,15 +310,16 @@ void XamContentCreateCore(PPCContext* ppc_state, KernelState* state, } if (overlapped_ptr) { - state->CompleteOverlappedImmediateEx(overlapped_ptr, disposition, result, - 0); + kernel_state->CompleteOverlappedImmediateEx(overlapped_ptr, disposition, + result, 0); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamContentCreate_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamContentCreate_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t root_name_ptr = SHIM_GET_ARG_32(1); uint32_t content_data_ptr = SHIM_GET_ARG_32(2); @@ -332,12 +335,13 @@ SHIM_CALL XamContentCreate_shim(PPCContext* ppc_state, KernelState* state) { user_index, root_name_ptr, root_name.c_str(), content_data_ptr, flags, disposition_ptr, license_mask_ptr, overlapped_ptr); - XamContentCreateCore(ppc_state, state, user_index, root_name, content_data, - flags, disposition_ptr, license_mask_ptr, 0, 0, - overlapped_ptr); + XamContentCreateCore(ppc_context, kernel_state, user_index, root_name, + content_data, flags, disposition_ptr, license_mask_ptr, + 0, 0, overlapped_ptr); } -SHIM_CALL XamContentCreateEx_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamContentCreateEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t root_name_ptr = SHIM_GET_ARG_32(1); uint32_t content_data_ptr = SHIM_GET_ARG_32(2); @@ -346,7 +350,7 @@ SHIM_CALL XamContentCreateEx_shim(PPCContext* ppc_state, KernelState* state) { uint32_t license_mask_ptr = SHIM_GET_ARG_32(5); uint32_t cache_size = SHIM_GET_ARG_32(6); uint64_t content_size = SHIM_GET_ARG_64(7); - uint32_t sp = (uint32_t)ppc_state->r[1]; + uint32_t sp = (uint32_t)ppc_context->r[1]; uint32_t overlapped_ptr = SHIM_MEM_32(sp + 0x54); auto root_name = xe::load_and_swap(SHIM_MEM_ADDR(root_name_ptr)); @@ -359,12 +363,13 @@ SHIM_CALL XamContentCreateEx_shim(PPCContext* ppc_state, KernelState* state) { disposition_ptr, license_mask_ptr, cache_size, content_size, overlapped_ptr); - XamContentCreateCore(ppc_state, state, user_index, root_name, content_data, - flags, disposition_ptr, license_mask_ptr, cache_size, - content_size, overlapped_ptr); + XamContentCreateCore(ppc_context, kernel_state, user_index, root_name, + content_data, flags, disposition_ptr, license_mask_ptr, + cache_size, content_size, overlapped_ptr); } -SHIM_CALL XamContentFlush_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamContentFlush_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t root_name_ptr = SHIM_GET_ARG_32(0); uint32_t overlapped_ptr = SHIM_GET_ARG_32(1); @@ -375,14 +380,15 @@ SHIM_CALL XamContentFlush_shim(PPCContext* ppc_state, KernelState* state) { X_RESULT result = X_ERROR_SUCCESS; if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamContentClose_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamContentClose_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t root_name_ptr = SHIM_GET_ARG_32(0); uint32_t overlapped_ptr = SHIM_GET_ARG_32(1); @@ -392,17 +398,18 @@ SHIM_CALL XamContentClose_shim(PPCContext* ppc_state, KernelState* state) { overlapped_ptr); // Closes a previously opened root from XamContentCreate*. - auto result = state->content_manager()->CloseContent(root_name); + auto result = kernel_state->content_manager()->CloseContent(root_name); if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamContentGetCreator_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamContentGetCreator_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t content_data_ptr = SHIM_GET_ARG_32(1); uint32_t is_creator_ptr = SHIM_GET_ARG_32(2); @@ -420,7 +427,7 @@ SHIM_CALL XamContentGetCreator_shim(PPCContext* ppc_state, KernelState* state) { // User always creates saves. SHIM_SET_MEM_32(is_creator_ptr, 1); if (creator_xuid_ptr) { - SHIM_SET_MEM_64(creator_xuid_ptr, state->user_profile()->xuid()); + SHIM_SET_MEM_64(creator_xuid_ptr, kernel_state->user_profile()->xuid()); } } else { SHIM_SET_MEM_32(is_creator_ptr, 0); @@ -430,15 +437,15 @@ SHIM_CALL XamContentGetCreator_shim(PPCContext* ppc_state, KernelState* state) { } if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamContentGetThumbnail_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamContentGetThumbnail_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t content_data_ptr = SHIM_GET_ARG_32(1); uint32_t buffer_ptr = SHIM_GET_ARG_32(2); @@ -455,8 +462,8 @@ SHIM_CALL XamContentGetThumbnail_shim(PPCContext* ppc_state, // Get thumbnail (if it exists). std::vector buffer; - auto result = - state->content_manager()->GetContentThumbnail(content_data, &buffer); + auto result = kernel_state->content_manager()->GetContentThumbnail( + content_data, &buffer); SHIM_SET_MEM_32(buffer_size_ptr, uint32_t(buffer.size())); @@ -475,15 +482,15 @@ SHIM_CALL XamContentGetThumbnail_shim(PPCContext* ppc_state, } if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamContentSetThumbnail_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamContentSetThumbnail_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t content_data_ptr = SHIM_GET_ARG_32(1); uint32_t buffer_ptr = SHIM_GET_ARG_32(2); @@ -498,18 +505,19 @@ SHIM_CALL XamContentSetThumbnail_shim(PPCContext* ppc_state, // Buffer is PNG data. auto buffer = std::vector(SHIM_MEM_ADDR(buffer_ptr), SHIM_MEM_ADDR(buffer_ptr) + buffer_size); - auto result = state->content_manager()->SetContentThumbnail( + auto result = kernel_state->content_manager()->SetContentThumbnail( content_data, std::move(buffer)); if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamContentDelete_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamContentDelete_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t content_data_ptr = SHIM_GET_ARG_32(1); uint32_t overlapped_ptr = SHIM_GET_ARG_32(2); @@ -519,10 +527,10 @@ SHIM_CALL XamContentDelete_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XamContentDelete(%d, %.8X, %.8X)", user_index, content_data_ptr, overlapped_ptr); - auto result = state->content_manager()->DeleteContent(content_data); + auto result = kernel_state->content_manager()->DeleteContent(content_data); if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); @@ -533,7 +541,7 @@ SHIM_CALL XamContentDelete_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xam::RegisterContentExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XamContentGetLicenseMask, state); SHIM_SET_MAPPING("xam.xex", XamShowDeviceSelectorUI, state); SHIM_SET_MAPPING("xam.xex", XamContentGetDeviceName, state); diff --git a/src/xenia/kernel/xam_info.cc b/src/xenia/kernel/xam_info.cc index ab9fc47bf..ccee2b23d 100644 --- a/src/xenia/kernel/xam_info.cc +++ b/src/xenia/kernel/xam_info.cc @@ -19,7 +19,8 @@ namespace xe { namespace kernel { -SHIM_CALL XamGetSystemVersion_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamGetSystemVersion_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XamGetSystemVersion()"); // eh, just picking one. If we go too low we may break new games, but // this value seems to be used for conditionally loading symbols and if @@ -29,7 +30,7 @@ SHIM_CALL XamGetSystemVersion_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XGetAVPack_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XGetAVPack_shim(PPCContext* ppc_context, KernelState* kernel_state) { // DWORD // Not sure what the values are for this, but 6 is VGA. // Other likely values are 3/4/8 for HDMI or something. @@ -38,13 +39,15 @@ SHIM_CALL XGetAVPack_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(6); } -SHIM_CALL XGetGameRegion_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XGetGameRegion_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XGetGameRegion()"); SHIM_SET_RETURN_32(0xFFFF); } -SHIM_CALL XGetLanguage_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XGetLanguage_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XGetLanguage()"); uint32_t desired_language = X_LANGUAGE_ENGLISH; @@ -62,19 +65,20 @@ SHIM_CALL XGetLanguage_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(desired_language); } -SHIM_CALL XamVoiceIsActiveProcess_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamVoiceIsActiveProcess_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XamVoiceIsActiveProcess()"); // Returning 0 here will short-circuit a bunch of voice stuff. SHIM_SET_RETURN_32(0); } -SHIM_CALL XamGetExecutionId_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamGetExecutionId_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t info_ptr = SHIM_GET_ARG_32(0); XELOGD("XamGetExecutionId(%.8X)", info_ptr); - auto module = state->GetExecutableModule(); + auto module = kernel_state->GetExecutableModule(); assert_not_null(module); SHIM_SET_MEM_32(info_ptr, module->execution_info_ptr()); @@ -82,8 +86,8 @@ SHIM_CALL XamGetExecutionId_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XamLoaderSetLaunchData_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamLoaderSetLaunchData_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t data_ptr = SHIM_GET_ARG_32(0); uint32_t data_size = SHIM_GET_ARG_32(1); @@ -93,8 +97,8 @@ SHIM_CALL XamLoaderSetLaunchData_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL XamLoaderGetLaunchDataSize_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamLoaderGetLaunchDataSize_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t size_ptr = SHIM_GET_ARG_32(0); XELOGD("XamLoaderGetLaunchDataSize(%.8X)", size_ptr); @@ -104,8 +108,8 @@ SHIM_CALL XamLoaderGetLaunchDataSize_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(1); } -SHIM_CALL XamLoaderGetLaunchData_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamLoaderGetLaunchData_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t buffer_ptr = SHIM_GET_ARG_32(0); uint32_t buffer_size = SHIM_GET_ARG_32(1); @@ -114,7 +118,8 @@ SHIM_CALL XamLoaderGetLaunchData_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL XamLoaderLaunchTitle_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamLoaderLaunchTitle_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t name_ptr = SHIM_GET_ARG_32(0); const char* name = (const char*)SHIM_MEM_ADDR(name_ptr); uint32_t unk2 = SHIM_GET_ARG_32(1); @@ -123,13 +128,13 @@ SHIM_CALL XamLoaderLaunchTitle_shim(PPCContext* ppc_state, KernelState* state) { assert_always(); } -SHIM_CALL XamLoaderTerminateTitle_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamLoaderTerminateTitle_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XamLoaderTerminateTitle()"); assert_always(); } -SHIM_CALL XamAlloc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamAlloc_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t unk = SHIM_GET_ARG_32(0); uint32_t size = SHIM_GET_ARG_32(1); uint32_t out_ptr = SHIM_GET_ARG_32(2); @@ -140,23 +145,24 @@ SHIM_CALL XamAlloc_shim(PPCContext* ppc_state, KernelState* state) { // Allocate from the heap. Not sure why XAM does this specially, perhaps // it keeps stuff in a separate heap? - uint32_t ptr = state->memory()->SystemHeapAlloc(size); + uint32_t ptr = kernel_state->memory()->SystemHeapAlloc(size); SHIM_SET_MEM_32(out_ptr, ptr); SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamFree_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamFree_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t ptr = SHIM_GET_ARG_32(0); XELOGD("XamFree(%.8X)", ptr); - state->memory()->SystemHeapFree(ptr); + kernel_state->memory()->SystemHeapFree(ptr); SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamEnumerate_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamEnumerate_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t zero = SHIM_GET_ARG_32(1); uint32_t buffer_ptr = SHIM_GET_ARG_32(2); @@ -169,11 +175,11 @@ SHIM_CALL XamEnumerate_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XamEnumerate(%.8X, %d, %.8X, %d, %.8X, %.8X)", handle, zero, buffer_ptr, buffer_length, item_count_ptr, overlapped_ptr); - auto e = state->object_table()->LookupObject(handle); + auto e = kernel_state->object_table()->LookupObject(handle); if (!e) { if (overlapped_ptr) { - state->CompleteOverlappedImmediateEx(overlapped_ptr, 0, - X_ERROR_INVALID_HANDLE, 0); + kernel_state->CompleteOverlappedImmediateEx(overlapped_ptr, 0, + X_ERROR_INVALID_HANDLE, 0); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_INVALID_HANDLE); @@ -190,8 +196,8 @@ SHIM_CALL XamEnumerate_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_MEM_32(item_count_ptr, item_count); } else if (overlapped_ptr) { assert_zero(item_count_ptr); - state->CompleteOverlappedImmediateEx(overlapped_ptr, result, result, - item_count); + kernel_state->CompleteOverlappedImmediateEx(overlapped_ptr, result, result, + item_count); result = X_ERROR_IO_PENDING; } else { assert_always(); @@ -205,7 +211,7 @@ SHIM_CALL XamEnumerate_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xam::RegisterInfoExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XamGetSystemVersion, state); SHIM_SET_MAPPING("xam.xex", XGetAVPack, state); SHIM_SET_MAPPING("xam.xex", XGetGameRegion, state); diff --git a/src/xenia/kernel/xam_input.cc b/src/xenia/kernel/xam_input.cc index 10c446f82..ee0824358 100644 --- a/src/xenia/kernel/xam_input.cc +++ b/src/xenia/kernel/xam_input.cc @@ -20,7 +20,8 @@ namespace kernel { using xe::hid::InputSystem; -SHIM_CALL XamResetInactivity_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamResetInactivity_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk = SHIM_GET_ARG_32(0); XELOGD("XamResetInactivity(%d)", unk); @@ -29,8 +30,8 @@ SHIM_CALL XamResetInactivity_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XamEnableInactivityProcessing_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamEnableInactivityProcessing_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t zero = SHIM_GET_ARG_32(0); uint32_t unk = SHIM_GET_ARG_32(1); @@ -41,8 +42,8 @@ SHIM_CALL XamEnableInactivityProcessing_shim(PPCContext* ppc_state, } // http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetcapabilities(v=vs.85).aspx -SHIM_CALL XamInputGetCapabilities_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamInputGetCapabilities_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t flags = SHIM_GET_ARG_32(1); uint32_t caps_ptr = SHIM_GET_ARG_32(2); @@ -55,15 +56,15 @@ SHIM_CALL XamInputGetCapabilities_shim(PPCContext* ppc_state, return; } - InputSystem* input_system = state->emulator()->input_system(); + InputSystem* input_system = kernel_state->emulator()->input_system(); auto caps = SHIM_STRUCT(X_INPUT_CAPABILITIES, caps_ptr); X_RESULT result = input_system->GetCapabilities(user_index, flags, caps); SHIM_SET_RETURN_32(result); } -SHIM_CALL XamInputGetCapabilitiesEx_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamInputGetCapabilitiesEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk = SHIM_GET_ARG_32(0); uint32_t user_index = SHIM_GET_ARG_32(1); uint32_t flags = SHIM_GET_ARG_32(2); @@ -77,7 +78,7 @@ SHIM_CALL XamInputGetCapabilitiesEx_shim(PPCContext* ppc_state, return; } - InputSystem* input_system = state->emulator()->input_system(); + InputSystem* input_system = kernel_state->emulator()->input_system(); auto caps = SHIM_STRUCT(X_INPUT_CAPABILITIES, caps_ptr); X_RESULT result = input_system->GetCapabilities(user_index, flags, caps); @@ -85,7 +86,8 @@ SHIM_CALL XamInputGetCapabilitiesEx_shim(PPCContext* ppc_state, } // http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetstate(v=vs.85).aspx -SHIM_CALL XamInputGetState_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamInputGetState_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t one = SHIM_GET_ARG_32(1); uint32_t state_ptr = SHIM_GET_ARG_32(2); @@ -94,7 +96,7 @@ SHIM_CALL XamInputGetState_shim(PPCContext* ppc_state, KernelState* state) { // Games call this with a NULL state ptr, probably as a query. - InputSystem* input_system = state->emulator()->input_system(); + InputSystem* input_system = kernel_state->emulator()->input_system(); auto input_state = SHIM_STRUCT(X_INPUT_STATE, state_ptr); X_RESULT result = input_system->GetState(user_index, input_state); @@ -102,7 +104,8 @@ SHIM_CALL XamInputGetState_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputsetstate(v=vs.85).aspx -SHIM_CALL XamInputSetState_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamInputSetState_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t unk = SHIM_GET_ARG_32(1); uint32_t vibration_ptr = SHIM_GET_ARG_32(2); @@ -114,7 +117,7 @@ SHIM_CALL XamInputSetState_shim(PPCContext* ppc_state, KernelState* state) { return; } - InputSystem* input_system = state->emulator()->input_system(); + InputSystem* input_system = kernel_state->emulator()->input_system(); auto vibration = SHIM_STRUCT(X_INPUT_VIBRATION, vibration_ptr); X_RESULT result = input_system->SetState(user_index, vibration); @@ -122,7 +125,8 @@ SHIM_CALL XamInputSetState_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetkeystroke(v=vs.85).aspx -SHIM_CALL XamInputGetKeystroke_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamInputGetKeystroke_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t flags = SHIM_GET_ARG_32(1); uint32_t keystroke_ptr = SHIM_GET_ARG_32(2); @@ -139,7 +143,7 @@ SHIM_CALL XamInputGetKeystroke_shim(PPCContext* ppc_state, KernelState* state) { return; } - InputSystem* input_system = state->emulator()->input_system(); + InputSystem* input_system = kernel_state->emulator()->input_system(); auto keystroke = SHIM_STRUCT(X_INPUT_KEYSTROKE, keystroke_ptr); X_RESULT result = input_system->GetKeystroke(user_index, flags, keystroke); @@ -147,8 +151,8 @@ SHIM_CALL XamInputGetKeystroke_shim(PPCContext* ppc_state, KernelState* state) { } // Same as non-ex, just takes a pointer to user index. -SHIM_CALL XamInputGetKeystrokeEx_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamInputGetKeystrokeEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index_ptr = SHIM_GET_ARG_32(0); uint32_t flags = SHIM_GET_ARG_32(1); uint32_t keystroke_ptr = SHIM_GET_ARG_32(2); @@ -163,7 +167,7 @@ SHIM_CALL XamInputGetKeystrokeEx_shim(PPCContext* ppc_state, return; } - InputSystem* input_system = state->emulator()->input_system(); + InputSystem* input_system = kernel_state->emulator()->input_system(); auto keystroke = SHIM_STRUCT(X_INPUT_KEYSTROKE, keystroke_ptr); X_RESULT result = input_system->GetKeystroke(user_index, flags, keystroke); @@ -173,8 +177,8 @@ SHIM_CALL XamInputGetKeystrokeEx_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XamUserGetDeviceContext_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamUserGetDeviceContext_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t unk = SHIM_GET_ARG_32(1); uint32_t out_ptr = SHIM_GET_ARG_32(2); @@ -196,7 +200,7 @@ SHIM_CALL XamUserGetDeviceContext_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xam::RegisterInputExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XamResetInactivity, state); SHIM_SET_MAPPING("xam.xex", XamEnableInactivityProcessing, state); SHIM_SET_MAPPING("xam.xex", XamInputGetCapabilities, state); diff --git a/src/xenia/kernel/xam_module.h b/src/xenia/kernel/xam_module.h index 370ee472f..bb7f9b290 100644 --- a/src/xenia/kernel/xam_module.h +++ b/src/xenia/kernel/xam_module.h @@ -23,6 +23,7 @@ class XamModule : public XKernelModule { virtual ~XamModule(); static void RegisterExportTable(xe::cpu::ExportResolver* export_resolver); + static void RegisterExport(xe::cpu::Export* export); private: }; diff --git a/src/xenia/kernel/xam_msg.cc b/src/xenia/kernel/xam_msg.cc index 45b16ad86..265e8e803 100644 --- a/src/xenia/kernel/xam_msg.cc +++ b/src/xenia/kernel/xam_msg.cc @@ -17,7 +17,8 @@ namespace xe { namespace kernel { -SHIM_CALL XMsgInProcessCall_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMsgInProcessCall_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t app = SHIM_GET_ARG_32(0); uint32_t message = SHIM_GET_ARG_32(1); uint32_t arg1 = SHIM_GET_ARG_32(2); @@ -25,16 +26,16 @@ SHIM_CALL XMsgInProcessCall_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XMsgInProcessCall(%.8X, %.8X, %.8X, %.8X)", app, message, arg1, arg2); - auto result = - state->app_manager()->DispatchMessageSync(app, message, arg1, arg2); + auto result = kernel_state->app_manager()->DispatchMessageSync(app, message, + arg1, arg2); if (result == X_ERROR_NOT_FOUND) { XELOGE("XMsgInProcessCall: app %.8X undefined", app); } SHIM_SET_RETURN_32(result); } -SHIM_CALL XMsgSystemProcessCall_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMsgSystemProcessCall_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t app = SHIM_GET_ARG_32(0); uint32_t message = SHIM_GET_ARG_32(1); uint32_t buffer = SHIM_GET_ARG_32(2); @@ -43,15 +44,16 @@ SHIM_CALL XMsgSystemProcessCall_shim(PPCContext* ppc_state, XELOGD("XMsgSystemProcessCall(%.8X, %.8X, %.8X, %.8X)", app, message, buffer, buffer_length); - auto result = state->app_manager()->DispatchMessageAsync(app, message, buffer, - buffer_length); + auto result = kernel_state->app_manager()->DispatchMessageAsync( + app, message, buffer, buffer_length); if (result == X_ERROR_NOT_FOUND) { XELOGE("XMsgSystemProcessCall: app %.8X undefined", app); } SHIM_SET_RETURN_32(result); } -SHIM_CALL XMsgStartIORequest_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMsgStartIORequest_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t app = SHIM_GET_ARG_32(0); uint32_t message = SHIM_GET_ARG_32(1); uint32_t overlapped_ptr = SHIM_GET_ARG_32(2); @@ -61,19 +63,20 @@ SHIM_CALL XMsgStartIORequest_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XMsgStartIORequest(%.8X, %.8X, %.8X, %.8X, %d)", app, message, overlapped_ptr, buffer, buffer_length); - auto result = state->app_manager()->DispatchMessageAsync(app, message, buffer, - buffer_length); + auto result = kernel_state->app_manager()->DispatchMessageAsync( + app, message, buffer, buffer_length); if (result == X_ERROR_NOT_FOUND) { XELOGE("XMsgStartIORequest: app %.8X undefined", app); } if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); result = X_ERROR_IO_PENDING; } SHIM_SET_RETURN_32(result); } -SHIM_CALL XMsgStartIORequestEx_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMsgStartIORequestEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t app = SHIM_GET_ARG_32(0); uint32_t message = SHIM_GET_ARG_32(1); uint32_t overlapped_ptr = SHIM_GET_ARG_32(2); @@ -84,19 +87,20 @@ SHIM_CALL XMsgStartIORequestEx_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XMsgStartIORequestEx(%.8X, %.8X, %.8X, %.8X, %d, %.8X)", app, message, overlapped_ptr, buffer, buffer_length, unknown_ptr); - auto result = state->app_manager()->DispatchMessageAsync(app, message, buffer, - buffer_length); + auto result = kernel_state->app_manager()->DispatchMessageAsync( + app, message, buffer, buffer_length); if (result == X_ERROR_NOT_FOUND) { XELOGE("XMsgStartIORequestEx: app %.8X undefined", app); } if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); result = X_ERROR_IO_PENDING; } SHIM_SET_RETURN_32(result); } -SHIM_CALL XMsgCancelIORequest_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMsgCancelIORequest_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t overlapped_ptr = SHIM_GET_ARG_32(0); uint32_t wait = SHIM_GET_ARG_32(1); @@ -104,7 +108,7 @@ SHIM_CALL XMsgCancelIORequest_shim(PPCContext* ppc_state, KernelState* state) { X_HANDLE event_handle = XOverlappedGetEvent(SHIM_MEM_ADDR(overlapped_ptr)); if (event_handle && wait) { - auto ev = state->object_table()->LookupObject(event_handle); + auto ev = kernel_state->object_table()->LookupObject(event_handle); if (ev) { ev->Wait(0, 0, true, nullptr); } @@ -117,7 +121,7 @@ SHIM_CALL XMsgCancelIORequest_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xam::RegisterMsgExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XMsgInProcessCall, state); SHIM_SET_MAPPING("xam.xex", XMsgSystemProcessCall, state); SHIM_SET_MAPPING("xam.xex", XMsgStartIORequest, state); diff --git a/src/xenia/kernel/xam_net.cc b/src/xenia/kernel/xam_net.cc index fd5e63df4..9a81feb53 100644 --- a/src/xenia/kernel/xam_net.cc +++ b/src/xenia/kernel/xam_net.cc @@ -71,7 +71,8 @@ void StoreSockaddr(const sockaddr& addr, uint8_t* ptr) { // BYTE cfgQosPairWaitTimeInSeconds; //} XNetStartupParams; -SHIM_CALL NetDll_XNetStartup_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_XNetStartup_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t params_ptr = SHIM_GET_ARG_32(1); @@ -80,7 +81,8 @@ SHIM_CALL NetDll_XNetStartup_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL NetDll_XNetCleanup_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_XNetCleanup_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t params_ptr = SHIM_GET_ARG_32(1); @@ -89,7 +91,8 @@ SHIM_CALL NetDll_XNetCleanup_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL NetDll_XNetRandom_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_XNetRandom_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t buffer_ptr = SHIM_GET_ARG_32(1); uint32_t length = SHIM_GET_ARG_32(2); @@ -103,7 +106,8 @@ SHIM_CALL NetDll_XNetRandom_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL NetDll_WSAStartup_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_WSAStartup_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); // always 1? uint32_t version = SHIM_GET_ARG_16(1); uint32_t data_ptr = SHIM_GET_ARG_32(2); @@ -115,7 +119,7 @@ SHIM_CALL NetDll_WSAStartup_shim(PPCContext* ppc_state, KernelState* state) { ZeroMemory(&wsaData, sizeof(WSADATA)); int ret = WSAStartup(version, &wsaData); - auto data_out = state->memory()->TranslateVirtual(data_ptr); + auto data_out = kernel_state->memory()->TranslateVirtual(data_ptr); if (data_ptr) { xe::store_and_swap(data_out + 0x000, wsaData.wVersion); @@ -134,7 +138,8 @@ SHIM_CALL NetDll_WSAStartup_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_WSACleanup_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_WSACleanup_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); XELOGD("NetDll_WSACleanup(%d)", arg0); @@ -143,8 +148,8 @@ SHIM_CALL NetDll_WSACleanup_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_WSAGetLastError_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NetDll_WSAGetLastError_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("NetDll_WSAGetLastError()"); int err = WSAGetLastError(); @@ -159,14 +164,14 @@ SHIM_CALL NetDll_WSAGetLastError_shim(PPCContext* ppc_state, // BYTE abOnline[20]; // Online identification // } XNADDR; -SHIM_CALL NetDll_XNetGetTitleXnAddr_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NetDll_XNetGetTitleXnAddr_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); // constant 1? uint32_t addr_ptr = SHIM_GET_ARG_32(1); // XNADDR XELOGD("NetDll_XNetGetTitleXnAddr(%d, %.8X)", arg0, addr_ptr); - auto addr = state->memory()->TranslateVirtual(addr_ptr); + auto addr = kernel_state->memory()->TranslateVirtual(addr_ptr); xe::store(addr + 0x0, htonl(INADDR_LOOPBACK)); xe::store_and_swap(addr + 0x4, 0); @@ -177,8 +182,8 @@ SHIM_CALL NetDll_XNetGetTitleXnAddr_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0x00000004); // XNET_GET_XNADDR_STATIC } -SHIM_CALL NetDll_XNetGetEthernetLinkStatus_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NetDll_XNetGetEthernetLinkStatus_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // Games seem to call this before *Startup. If we return 0, they don't even // try. uint32_t arg0 = SHIM_GET_ARG_32(0); @@ -188,7 +193,8 @@ SHIM_CALL NetDll_XNetGetEthernetLinkStatus_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL NetDll_inet_addr_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_inet_addr_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t cp_ptr = SHIM_GET_ARG_32(0); auto cp = reinterpret_cast(SHIM_MEM_ADDR(cp_ptr)); @@ -198,7 +204,8 @@ SHIM_CALL NetDll_inet_addr_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(addr); } -SHIM_CALL NetDll_socket_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_socket_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t af = SHIM_GET_ARG_32(1); uint32_t type = SHIM_GET_ARG_32(2); @@ -215,7 +222,8 @@ SHIM_CALL NetDll_socket_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(static_cast(socket_handle)); } -SHIM_CALL NetDll_closesocket_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_closesocket_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); @@ -225,7 +233,8 @@ SHIM_CALL NetDll_closesocket_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_setsockopt_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_setsockopt_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t level = SHIM_GET_ARG_32(2); @@ -242,7 +251,8 @@ SHIM_CALL NetDll_setsockopt_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_ioctlsocket_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_ioctlsocket_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t cmd = SHIM_GET_ARG_32(2); @@ -258,7 +268,7 @@ SHIM_CALL NetDll_ioctlsocket_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_bind_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_bind_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t name_ptr = SHIM_GET_ARG_32(2); @@ -274,7 +284,8 @@ SHIM_CALL NetDll_bind_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_connect_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_connect_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t name_ptr = SHIM_GET_ARG_32(2); @@ -290,7 +301,8 @@ SHIM_CALL NetDll_connect_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_listen_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_listen_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); int32_t backlog = SHIM_GET_ARG_32(2); @@ -302,7 +314,8 @@ SHIM_CALL NetDll_listen_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_accept_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_accept_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t addr_ptr = SHIM_GET_ARG_32(2); @@ -346,7 +359,8 @@ void StoreFdset(const fd_set& src, uint8_t* dest) { } } -SHIM_CALL NetDll_select_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_select_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t nfds = SHIM_GET_ARG_32(1); uint32_t readfds_ptr = SHIM_GET_ARG_32(2); @@ -393,7 +407,7 @@ SHIM_CALL NetDll_select_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_recv_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_recv_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t buf_ptr = SHIM_GET_ARG_32(2); @@ -409,7 +423,8 @@ SHIM_CALL NetDll_recv_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_recvfrom_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_recvfrom_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t buf_ptr = SHIM_GET_ARG_32(2); @@ -437,7 +452,7 @@ SHIM_CALL NetDll_recvfrom_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_send_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_send_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t buf_ptr = SHIM_GET_ARG_32(2); @@ -453,7 +468,8 @@ SHIM_CALL NetDll_send_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL NetDll_sendto_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NetDll_sendto_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t socket_handle = SHIM_GET_ARG_32(1); uint32_t buf_ptr = SHIM_GET_ARG_32(2); @@ -478,7 +494,7 @@ SHIM_CALL NetDll_sendto_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xam::RegisterNetExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", NetDll_XNetStartup, state); SHIM_SET_MAPPING("xam.xex", NetDll_XNetCleanup, state); SHIM_SET_MAPPING("xam.xex", NetDll_XNetRandom, state); diff --git a/src/xenia/kernel/xam_notify.cc b/src/xenia/kernel/xam_notify.cc index d38b9e169..7e6b0d3f4 100644 --- a/src/xenia/kernel/xam_notify.cc +++ b/src/xenia/kernel/xam_notify.cc @@ -17,8 +17,8 @@ namespace xe { namespace kernel { -SHIM_CALL XamNotifyCreateListener_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamNotifyCreateListener_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint64_t mask = SHIM_GET_ARG_64(0); uint32_t one = SHIM_GET_ARG_32(1); @@ -26,7 +26,8 @@ SHIM_CALL XamNotifyCreateListener_shim(PPCContext* ppc_state, // r4=1 may indicate user process? - auto listener = object_ref(new XNotifyListener(state)); + auto listener = + object_ref(new XNotifyListener(kernel_state)); listener->Initialize(mask); // Handle ref is incremented, so return that. @@ -36,7 +37,8 @@ SHIM_CALL XamNotifyCreateListener_shim(PPCContext* ppc_state, } // http://ffplay360.googlecode.com/svn/Test/Common/AtgSignIn.cpp -SHIM_CALL XNotifyGetNext_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XNotifyGetNext_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t match_id = SHIM_GET_ARG_32(1); uint32_t id_ptr = SHIM_GET_ARG_32(2); @@ -51,7 +53,8 @@ SHIM_CALL XNotifyGetNext_shim(PPCContext* ppc_state, KernelState* state) { } // Grab listener. - auto listener = state->object_table()->LookupObject(handle); + auto listener = + kernel_state->object_table()->LookupObject(handle); if (!listener) { SHIM_SET_RETURN_32(0); return; @@ -77,7 +80,8 @@ SHIM_CALL XNotifyGetNext_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(dequeued ? 1 : 0); } -SHIM_CALL XNotifyDelayUI_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XNotifyDelayUI_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t delay_ms = SHIM_GET_ARG_32(0); XELOGD("XNotifyDelayUI(%d)", delay_ms); @@ -86,7 +90,8 @@ SHIM_CALL XNotifyDelayUI_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XNotifyPositionUI_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XNotifyPositionUI_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t position = SHIM_GET_ARG_32(0); XELOGD("XNotifyPositionUI(%.8X)", position); @@ -98,7 +103,7 @@ SHIM_CALL XNotifyPositionUI_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xam::RegisterNotifyExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XamNotifyCreateListener, state); SHIM_SET_MAPPING("xam.xex", XNotifyGetNext, state); SHIM_SET_MAPPING("xam.xex", XNotifyDelayUI, state); diff --git a/src/xenia/kernel/xam_private.h b/src/xenia/kernel/xam_private.h index 626ab73ae..2bbfc527e 100644 --- a/src/xenia/kernel/xam_private.h +++ b/src/xenia/kernel/xam_private.h @@ -21,25 +21,25 @@ class KernelState; namespace xam { // Registration functions, one per file. void RegisterContentExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterInfoExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterInputExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterMsgExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterNetExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterNotifyExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterUIExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterUserExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterVideoExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterVoiceExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); } // namespace xam } // namespace kernel diff --git a/src/xenia/kernel/xam_ui.cc b/src/xenia/kernel/xam_ui.cc index 623da9a75..63fd9cf07 100644 --- a/src/xenia/kernel/xam_ui.cc +++ b/src/xenia/kernel/xam_ui.cc @@ -19,13 +19,15 @@ namespace xe { namespace kernel { -SHIM_CALL XamIsUIActive_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamIsUIActive_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XamIsUIActive()"); SHIM_SET_RETURN_32(0); } // http://www.se7ensins.com/forums/threads/working-xshowmessageboxui.844116/?jdfwkey=sb0vm -SHIM_CALL XamShowMessageBoxUI_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamShowMessageBoxUI_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t title_ptr = SHIM_GET_ARG_32(1); uint32_t text_ptr = SHIM_GET_ARG_32(2); @@ -35,7 +37,7 @@ SHIM_CALL XamShowMessageBoxUI_shim(PPCContext* ppc_state, KernelState* state) { uint32_t flags = SHIM_GET_ARG_32(6); uint32_t result_ptr = SHIM_GET_ARG_32(7); // arg8 is in stack! - uint32_t sp = (uint32_t)ppc_state->r[1]; + uint32_t sp = (uint32_t)ppc_context->r[1]; uint32_t overlapped_ptr = SHIM_MEM_32(sp + 0x54); auto title = xe::load_and_swap(SHIM_MEM_ADDR(title_ptr)); @@ -67,7 +69,7 @@ SHIM_CALL XamShowMessageBoxUI_shim(PPCContext* ppc_state, KernelState* state) { TASKDIALOGCONFIG config = {0}; config.cbSize = sizeof(config); config.hInstance = GetModuleHandle(nullptr); - config.hwndParent = state->emulator()->main_window()->hwnd(); + config.hwndParent = kernel_state->emulator()->main_window()->hwnd(); config.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION | // esc to exit TDF_POSITION_RELATIVE_TO_WINDOW; // center in window config.dwCommonButtons = 0; @@ -109,19 +111,19 @@ SHIM_CALL XamShowMessageBoxUI_shim(PPCContext* ppc_state, KernelState* state) { } SHIM_SET_MEM_32(result_ptr, chosen_button); - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } -SHIM_CALL XamShowDirtyDiscErrorUI_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamShowDirtyDiscErrorUI_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); XELOGD("XamShowDirtyDiscErrorUI(%d)", user_index); int button_pressed = 0; - TaskDialog(state->emulator()->main_window()->hwnd(), GetModuleHandle(nullptr), - L"Disc Read Error", + TaskDialog(kernel_state->emulator()->main_window()->hwnd(), + GetModuleHandle(nullptr), L"Disc Read Error", L"Game is claiming to be unable to read game data!", nullptr, TDCBF_CLOSE_BUTTON, TD_ERROR_ICON, &button_pressed); @@ -133,7 +135,7 @@ SHIM_CALL XamShowDirtyDiscErrorUI_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xam::RegisterUIExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XamIsUIActive, state); SHIM_SET_MAPPING("xam.xex", XamShowMessageBoxUI, state); SHIM_SET_MAPPING("xam.xex", XamShowDirtyDiscErrorUI, state); diff --git a/src/xenia/kernel/xam_user.cc b/src/xenia/kernel/xam_user.cc index 276367dd5..bf0d4779c 100644 --- a/src/xenia/kernel/xam_user.cc +++ b/src/xenia/kernel/xam_user.cc @@ -18,7 +18,8 @@ namespace xe { namespace kernel { -SHIM_CALL XamUserGetXUID_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamUserGetXUID_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t unk = SHIM_GET_ARG_32(1); uint32_t xuid_ptr = SHIM_GET_ARG_32(2); @@ -26,7 +27,7 @@ SHIM_CALL XamUserGetXUID_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XamUserGetXUID(%d, %.8X, %.8X)", user_index, unk, xuid_ptr); if (user_index == 0) { - const auto& user_profile = state->user_profile(); + const auto& user_profile = kernel_state->user_profile(); if (xuid_ptr) { SHIM_SET_MEM_64(xuid_ptr, user_profile->xuid()); } @@ -36,8 +37,8 @@ SHIM_CALL XamUserGetXUID_shim(PPCContext* ppc_state, KernelState* state) { } } -SHIM_CALL XamUserGetSigninState_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamUserGetSigninState_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); XELOGD("XamUserGetSigninState(%d)", user_index); @@ -46,7 +47,7 @@ SHIM_CALL XamUserGetSigninState_shim(PPCContext* ppc_state, // This should keep games from asking us to sign in and also keep them // from initializing the network. if (user_index == 0 || (user_index & 0xFF) == 0xFF) { - const auto& user_profile = state->user_profile(); + const auto& user_profile = kernel_state->user_profile(); auto signin_state = user_profile->signin_state(); SHIM_SET_RETURN_32(signin_state); } else { @@ -54,7 +55,8 @@ SHIM_CALL XamUserGetSigninState_shim(PPCContext* ppc_state, } } -SHIM_CALL XamUserGetSigninInfo_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamUserGetSigninInfo_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t flags = SHIM_GET_ARG_32(1); uint32_t info_ptr = SHIM_GET_ARG_32(2); @@ -62,7 +64,7 @@ SHIM_CALL XamUserGetSigninInfo_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XamUserGetSigninInfo(%d, %.8X, %.8X)", user_index, flags, info_ptr); if (user_index == 0) { - const auto& user_profile = state->user_profile(); + const auto& user_profile = kernel_state->user_profile(); SHIM_SET_MEM_64(info_ptr + 0, user_profile->xuid()); SHIM_SET_MEM_32(info_ptr + 8, 0); // maybe zero? SHIM_SET_MEM_32(info_ptr + 12, user_profile->signin_state()); @@ -76,7 +78,8 @@ SHIM_CALL XamUserGetSigninInfo_shim(PPCContext* ppc_state, KernelState* state) { } } -SHIM_CALL XamUserGetName_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamUserGetName_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t buffer_ptr = SHIM_GET_ARG_32(1); uint32_t buffer_len = SHIM_GET_ARG_32(2); @@ -84,7 +87,7 @@ SHIM_CALL XamUserGetName_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("XamUserGetName(%d, %.8X, %d)", user_index, buffer_ptr, buffer_len); if (user_index == 0) { - const auto& user_profile = state->user_profile(); + const auto& user_profile = kernel_state->user_profile(); char* buffer = (char*)SHIM_MEM_ADDR(buffer_ptr); strcpy(buffer, user_profile->name().data()); SHIM_SET_RETURN_32(0); @@ -94,8 +97,8 @@ SHIM_CALL XamUserGetName_shim(PPCContext* ppc_state, KernelState* state) { } // http://freestyledash.googlecode.com/svn/trunk/Freestyle/Tools/Generic/xboxtools.cpp -SHIM_CALL XamUserReadProfileSettings_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamUserReadProfileSettings_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t title_id = SHIM_GET_ARG_32(0); uint32_t user_index = SHIM_GET_ARG_32(1); uint32_t unk_0 = SHIM_GET_ARG_32(2); @@ -105,7 +108,7 @@ SHIM_CALL XamUserReadProfileSettings_shim(PPCContext* ppc_state, uint32_t buffer_size_ptr = SHIM_GET_ARG_32(6); uint32_t buffer_ptr = SHIM_GET_ARG_32(7); // arg8 is in stack! - uint32_t sp = (uint32_t)ppc_state->r[1]; + uint32_t sp = (uint32_t)ppc_context->r[1]; uint32_t overlapped_ptr = SHIM_MEM_32(sp + 0x54); uint32_t buffer_size = SHIM_MEM_32(buffer_size_ptr); @@ -126,14 +129,15 @@ SHIM_CALL XamUserReadProfileSettings_shim(PPCContext* ppc_state, if (user_index) { // Only support user 0. if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_NOT_FOUND); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, + X_ERROR_NOT_FOUND); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_NOT_FOUND); } return; } - const auto& user_profile = state->user_profile(); + const auto& user_profile = kernel_state->user_profile(); // First call asks for size (fill buffer_size_ptr). // Second call asks for buffer contents with that size. @@ -170,8 +174,8 @@ SHIM_CALL XamUserReadProfileSettings_shim(PPCContext* ppc_state, if (any_missing) { // TODO(benvanik): don't fail? most games don't even check! if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, - X_ERROR_INVALID_PARAMETER); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, + X_ERROR_INVALID_PARAMETER); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_INVALID_PARAMETER); @@ -181,8 +185,8 @@ SHIM_CALL XamUserReadProfileSettings_shim(PPCContext* ppc_state, SHIM_SET_MEM_32(buffer_size_ptr, size_needed); if (!buffer_ptr || buffer_size < size_needed) { if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, - X_ERROR_INSUFFICIENT_BUFFER); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, + X_ERROR_INSUFFICIENT_BUFFER); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_INSUFFICIENT_BUFFER); @@ -215,15 +219,15 @@ SHIM_CALL XamUserReadProfileSettings_shim(PPCContext* ppc_state, } if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } } -SHIM_CALL XamUserWriteProfileSettings_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamUserWriteProfileSettings_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t unknown = SHIM_GET_ARG_32(1); uint32_t setting_count = SHIM_GET_ARG_32(2); @@ -237,8 +241,8 @@ SHIM_CALL XamUserWriteProfileSettings_shim(PPCContext* ppc_state, if (!setting_count || !settings_ptr) { if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, - X_ERROR_INVALID_PARAMETER); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, + X_ERROR_INVALID_PARAMETER); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_INVALID_PARAMETER); @@ -256,20 +260,20 @@ SHIM_CALL XamUserWriteProfileSettings_shim(PPCContext* ppc_state, return; } - const auto& user_profile = state->user_profile(); + const auto& user_profile = kernel_state->user_profile(); // TODO: Update and save settings. if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } } -SHIM_CALL XamUserCheckPrivilege_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamUserCheckPrivilege_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t mask = SHIM_GET_ARG_32(1); uint32_t out_value_ptr = SHIM_GET_ARG_32(2); @@ -283,8 +287,8 @@ SHIM_CALL XamUserCheckPrivilege_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamUserAreUsersFriends_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamUserAreUsersFriends_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t user_index = SHIM_GET_ARG_32(0); uint32_t unk1 = SHIM_GET_ARG_32(1); uint32_t unk2 = SHIM_GET_ARG_32(2); @@ -308,7 +312,7 @@ SHIM_CALL XamUserAreUsersFriends_shim(PPCContext* ppc_state, X_RESULT result = X_ERROR_SUCCESS; - const auto& user_profile = state->user_profile(); + const auto& user_profile = kernel_state->user_profile(); if (user_profile->signin_state() == 0) { result = X_ERROR_NOT_LOGGED_ON; } @@ -317,14 +321,15 @@ SHIM_CALL XamUserAreUsersFriends_shim(PPCContext* ppc_state, SHIM_SET_MEM_32(out_value_ptr, 0); if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, result); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(result); } } -SHIM_CALL XamShowSigninUI_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamShowSigninUI_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk_0 = SHIM_GET_ARG_32(0); uint32_t unk_mask = SHIM_GET_ARG_32(1); @@ -332,13 +337,13 @@ SHIM_CALL XamShowSigninUI_shim(PPCContext* ppc_state, KernelState* state) { // Mask values vary. Probably matching user types? Local/remote? // Games seem to sit and loop until we trigger this notification. - state->BroadcastNotification(0x00000009, 0); + kernel_state->BroadcastNotification(0x00000009, 0); SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamUserCreateAchievementEnumerator_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamUserCreateAchievementEnumerator_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t title_id = SHIM_GET_ARG_32(0); uint32_t user_index = SHIM_GET_ARG_32(1); uint32_t xuid = SHIM_GET_ARG_32(2); @@ -359,7 +364,7 @@ SHIM_CALL XamUserCreateAchievementEnumerator_shim(PPCContext* ppc_state, SHIM_SET_MEM_32(buffer_size_ptr, 64 * count); } - auto e = new XStaticEnumerator(state, count, 64); + auto e = new XStaticEnumerator(kernel_state, count, 64); e->Initialize(); SHIM_SET_MEM_32(handle_ptr, e->handle()); @@ -367,7 +372,8 @@ SHIM_CALL XamUserCreateAchievementEnumerator_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamParseGamerTileKey_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamParseGamerTileKey_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t key_ptr = SHIM_GET_ARG_32(0); uint32_t out0_ptr = SHIM_GET_ARG_32(1); uint32_t out1_ptr = SHIM_GET_ARG_32(2); @@ -383,7 +389,8 @@ SHIM_CALL XamParseGamerTileKey_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamReadTileToTexture_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamReadTileToTexture_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk0 = SHIM_GET_ARG_32(0); // const? uint32_t unk1 = SHIM_GET_ARG_32(1); // out0 from XamParseGamerTileKey uint32_t unk2 = SHIM_GET_ARG_32(2); // some variant of out1/out2 @@ -397,14 +404,15 @@ SHIM_CALL XamReadTileToTexture_shim(PPCContext* ppc_state, KernelState* state) { unk2, unk3, buffer_ptr, stride, height, overlapped_ptr); if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } } -SHIM_CALL XamWriteGamerTile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamWriteGamerTile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0 = SHIM_GET_ARG_32(0); uint32_t arg1 = SHIM_GET_ARG_32(1); uint32_t arg2 = SHIM_GET_ARG_32(2); @@ -416,15 +424,15 @@ SHIM_CALL XamWriteGamerTile_shim(PPCContext* ppc_state, KernelState* state) { arg2, arg3, arg4, overlapped_ptr); if (overlapped_ptr) { - state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); + kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS); SHIM_SET_RETURN_32(X_ERROR_IO_PENDING); } else { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } } -SHIM_CALL XamSessionCreateHandle_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamSessionCreateHandle_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); XELOGD("XamSessionCreateHandle(%.8X)", handle_ptr); @@ -434,8 +442,8 @@ SHIM_CALL XamSessionCreateHandle_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XamSessionRefObjByHandle_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamSessionRefObjByHandle_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t obj_ptr = SHIM_GET_ARG_32(1); @@ -452,7 +460,7 @@ SHIM_CALL XamSessionRefObjByHandle_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xam::RegisterUserExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XamUserGetXUID, state); SHIM_SET_MAPPING("xam.xex", XamUserGetSigninState, state); SHIM_SET_MAPPING("xam.xex", XamUserGetSigninInfo, state); diff --git a/src/xenia/kernel/xam_video.cc b/src/xenia/kernel/xam_video.cc index 3054f9b0f..8369d25c4 100644 --- a/src/xenia/kernel/xam_video.cc +++ b/src/xenia/kernel/xam_video.cc @@ -18,7 +18,8 @@ namespace kernel { // TODO(benvanik): actually check to see if these are the same. void xeVdQueryVideoMode(X_VIDEO_MODE* video_mode); -SHIM_CALL XGetVideoMode_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XGetVideoMode_shim(PPCContext* ppc_context, + KernelState* kernel_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); @@ -27,7 +28,8 @@ SHIM_CALL XGetVideoMode_shim(PPCContext* ppc_state, KernelState* state) { xeVdQueryVideoMode(video_mode); } -SHIM_CALL XGetVideoCapabilities_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XGetVideoCapabilities_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XGetVideoCapabilities()"); SHIM_SET_RETURN_32(0); } @@ -36,7 +38,7 @@ SHIM_CALL XGetVideoCapabilities_shim(PPCContext* ppc_state, KernelState* state) } // namespace xe void xe::kernel::xam::RegisterVideoExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XGetVideoCapabilities, state); SHIM_SET_MAPPING("xam.xex", XGetVideoMode, state); } diff --git a/src/xenia/kernel/xam_voice.cc b/src/xenia/kernel/xam_voice.cc index 45f914bfd..3aa4d446c 100644 --- a/src/xenia/kernel/xam_voice.cc +++ b/src/xenia/kernel/xam_voice.cc @@ -17,7 +17,8 @@ namespace xe { namespace kernel { -SHIM_CALL XamVoiceCreate_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamVoiceCreate_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk1 = SHIM_GET_ARG_32(0); // 0 uint32_t unk2 = SHIM_GET_ARG_32(1); // 0xF uint32_t out_voice_ptr = SHIM_GET_ARG_32(2); @@ -30,7 +31,8 @@ SHIM_CALL XamVoiceCreate_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_ERROR_ACCESS_DENIED); } -SHIM_CALL XamVoiceClose_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XamVoiceClose_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t voice_ptr = SHIM_GET_ARG_32(0); XELOGD("XamVoiceClose(%.8X)", voice_ptr); @@ -38,8 +40,8 @@ SHIM_CALL XamVoiceClose_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XamVoiceHeadsetPresent_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XamVoiceHeadsetPresent_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t voice_ptr = SHIM_GET_ARG_32(0); XELOGD("XamVoiceHeadsetPresent(%.8X)", voice_ptr); @@ -51,7 +53,7 @@ SHIM_CALL XamVoiceHeadsetPresent_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xam::RegisterVoiceExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xam.xex", XamVoiceCreate, state); SHIM_SET_MAPPING("xam.xex", XamVoiceClose, state); SHIM_SET_MAPPING("xam.xex", XamVoiceHeadsetPresent, state); diff --git a/src/xenia/kernel/xboxkrnl_audio.cc b/src/xenia/kernel/xboxkrnl_audio.cc index 2bd8b96e8..6d63bbac4 100644 --- a/src/xenia/kernel/xboxkrnl_audio.cc +++ b/src/xenia/kernel/xboxkrnl_audio.cc @@ -18,8 +18,8 @@ namespace xe { namespace kernel { -SHIM_CALL XAudioGetSpeakerConfig_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XAudioGetSpeakerConfig_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t config_ptr = SHIM_GET_ARG_32(0); XELOGD("XAudioGetSpeakerConfig(%.8X)", config_ptr); @@ -29,8 +29,8 @@ SHIM_CALL XAudioGetSpeakerConfig_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XAudioGetVoiceCategoryVolumeChangeMask_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XAudioGetVoiceCategoryVolumeChangeMask_shim( + PPCContext* ppc_context, KernelState* kernel_state) { uint32_t driver_ptr = SHIM_GET_ARG_32(0); uint32_t out_ptr = SHIM_GET_ARG_32(1); @@ -39,7 +39,7 @@ SHIM_CALL XAudioGetVoiceCategoryVolumeChangeMask_shim(PPCContext* ppc_state, assert_true((driver_ptr & 0xFFFF0000) == 0x41550000); - auto audio_system = state->emulator()->audio_system(); + auto audio_system = kernel_state->emulator()->audio_system(); // Checking these bits to see if any voice volume changed. // I think. @@ -48,8 +48,8 @@ SHIM_CALL XAudioGetVoiceCategoryVolumeChangeMask_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XAudioGetVoiceCategoryVolume_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XAudioGetVoiceCategoryVolume_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk = SHIM_GET_ARG_32(0); uint32_t out_ptr = SHIM_GET_ARG_32(1); @@ -61,7 +61,8 @@ SHIM_CALL XAudioGetVoiceCategoryVolume_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XAudioEnableDucker_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XAudioEnableDucker_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk = SHIM_GET_ARG_32(0); XELOGD("XAudioEnableDucker(%.8X)", unk); @@ -69,8 +70,8 @@ SHIM_CALL XAudioEnableDucker_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XAudioRegisterRenderDriverClient_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XAudioRegisterRenderDriverClient_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t callback_ptr = SHIM_GET_ARG_32(0); uint32_t driver_ptr = SHIM_GET_ARG_32(1); @@ -80,7 +81,7 @@ SHIM_CALL XAudioRegisterRenderDriverClient_shim(PPCContext* ppc_state, XELOGD("XAudioRegisterRenderDriverClient(%.8X(%.8X, %.8X), %.8X)", callback_ptr, callback, callback_arg, driver_ptr); - auto audio_system = state->emulator()->audio_system(); + auto audio_system = kernel_state->emulator()->audio_system(); size_t index; auto result = audio_system->RegisterClient(callback, callback_arg, &index); @@ -95,21 +96,21 @@ SHIM_CALL XAudioRegisterRenderDriverClient_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XAudioUnregisterRenderDriverClient_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XAudioUnregisterRenderDriverClient_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t driver_ptr = SHIM_GET_ARG_32(0); XELOGD("XAudioUnregisterRenderDriverClient(%.8X)", driver_ptr); assert_true((driver_ptr & 0xFFFF0000) == 0x41550000); - auto audio_system = state->emulator()->audio_system(); + auto audio_system = kernel_state->emulator()->audio_system(); audio_system->UnregisterClient(driver_ptr & 0x0000FFFF); SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XAudioSubmitRenderDriverFrame_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XAudioSubmitRenderDriverFrame_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t driver_ptr = SHIM_GET_ARG_32(0); uint32_t samples_ptr = SHIM_GET_ARG_32(1); @@ -117,7 +118,7 @@ SHIM_CALL XAudioSubmitRenderDriverFrame_shim(PPCContext* ppc_state, assert_true((driver_ptr & 0xFFFF0000) == 0x41550000); - auto audio_system = state->emulator()->audio_system(); + auto audio_system = kernel_state->emulator()->audio_system(); audio_system->SubmitFrame(driver_ptr & 0x0000FFFF, samples_ptr); SHIM_SET_RETURN_32(X_ERROR_SUCCESS); @@ -127,7 +128,7 @@ SHIM_CALL XAudioSubmitRenderDriverFrame_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xboxkrnl::RegisterAudioExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { // Additional XMA* methods are in xboxkrnl_audio_xma.cc. SHIM_SET_MAPPING("xboxkrnl.exe", XAudioGetSpeakerConfig, state); diff --git a/src/xenia/kernel/xboxkrnl_audio_xma.cc b/src/xenia/kernel/xboxkrnl_audio_xma.cc index 4ec2c182a..f3994d605 100644 --- a/src/xenia/kernel/xboxkrnl_audio_xma.cc +++ b/src/xenia/kernel/xboxkrnl_audio_xma.cc @@ -53,12 +53,13 @@ namespace kernel { // restrictions of frame/subframe/etc: // https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.xaudio2.xaudio2_buffer(v=vs.85).aspx -SHIM_CALL XMACreateContext_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMACreateContext_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_out_ptr = SHIM_GET_ARG_32(0); XELOGD("XMACreateContext(%.8X)", context_out_ptr); - auto audio_system = state->emulator()->audio_system(); + auto audio_system = kernel_state->emulator()->audio_system(); uint32_t context_ptr = audio_system->AllocateXmaContext(); SHIM_SET_MEM_32(context_out_ptr, context_ptr); if (!context_ptr) { @@ -69,20 +70,21 @@ SHIM_CALL XMACreateContext_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_STATUS_SUCCESS); } -SHIM_CALL XMAReleaseContext_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMAReleaseContext_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAReleaseContext(%.8X)", context_ptr); - auto audio_system = state->emulator()->audio_system(); + auto audio_system = kernel_state->emulator()->audio_system(); audio_system->ReleaseXmaContext(context_ptr); SHIM_SET_RETURN_32(0); } -void StoreXmaContextIndexedRegister(KernelState* state, uint32_t base_reg, - uint32_t context_ptr) { - auto audio_system = state->emulator()->audio_system(); +void StoreXmaContextIndexedRegister(KernelState* kernel_state, + uint32_t base_reg, uint32_t context_ptr) { + auto audio_system = kernel_state->emulator()->audio_system(); uint32_t hw_index = (context_ptr - audio_system->xma_context_array_ptr()) / XMAContextData::kSize; uint32_t reg_num = base_reg + (hw_index >> 5) * 4; @@ -90,7 +92,8 @@ void StoreXmaContextIndexedRegister(KernelState* state, uint32_t base_reg, audio_system->WriteRegister(reg_num, xe::byte_swap(reg_value)); } -SHIM_CALL XMAInitializeContext_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMAInitializeContext_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); uint32_t context_init_ptr = SHIM_GET_ARG_32(1); @@ -122,12 +125,13 @@ SHIM_CALL XMAInitializeContext_shim(PPCContext* ppc_state, KernelState* state) { context.Store(SHIM_MEM_ADDR(context_ptr)); - StoreXmaContextIndexedRegister(state, 0x1A80, context_ptr); + StoreXmaContextIndexedRegister(kernel_state, 0x1A80, context_ptr); SHIM_SET_RETURN_32(0); } -SHIM_CALL XMASetLoopData_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMASetLoopData_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); uint32_t loop_data_ptr = SHIM_GET_ARG_32(1); @@ -146,8 +150,8 @@ SHIM_CALL XMASetLoopData_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XMAGetInputBufferReadOffset_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMAGetInputBufferReadOffset_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAGetInputBufferReadOffset(%.8X)", context_ptr); @@ -159,8 +163,8 @@ SHIM_CALL XMAGetInputBufferReadOffset_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XMASetInputBufferReadOffset_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMASetInputBufferReadOffset_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); uint32_t value = SHIM_GET_ARG_32(1); @@ -175,7 +179,8 @@ SHIM_CALL XMASetInputBufferReadOffset_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL XMASetInputBuffer0_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMASetInputBuffer0_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); uint32_t buffer_ptr = SHIM_GET_ARG_32(1); uint32_t block_count = SHIM_GET_ARG_32(2); @@ -195,8 +200,8 @@ SHIM_CALL XMASetInputBuffer0_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XMAIsInputBuffer0Valid_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMAIsInputBuffer0Valid_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAIsInputBuffer0Valid(%.8X)", context_ptr); @@ -208,8 +213,8 @@ SHIM_CALL XMAIsInputBuffer0Valid_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XMASetInputBuffer0Valid_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMASetInputBuffer0Valid_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMASetInputBuffer0Valid(%.8X)", context_ptr); @@ -223,7 +228,8 @@ SHIM_CALL XMASetInputBuffer0Valid_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL XMASetInputBuffer1_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMASetInputBuffer1_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); uint32_t buffer_ptr = SHIM_GET_ARG_32(1); uint32_t block_count = SHIM_GET_ARG_32(2); @@ -243,8 +249,8 @@ SHIM_CALL XMASetInputBuffer1_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL XMAIsInputBuffer1Valid_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMAIsInputBuffer1Valid_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAIsInputBuffer1Valid(%.8X)", context_ptr); @@ -256,8 +262,8 @@ SHIM_CALL XMAIsInputBuffer1Valid_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XMASetInputBuffer1Valid_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMASetInputBuffer1Valid_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMASetInputBuffer1Valid(%.8X)", context_ptr); @@ -271,8 +277,8 @@ SHIM_CALL XMASetInputBuffer1Valid_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL XMAIsOutputBufferValid_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMAIsOutputBufferValid_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAIsOutputBufferValid(%.8X)", context_ptr); @@ -284,8 +290,8 @@ SHIM_CALL XMAIsOutputBufferValid_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XMASetOutputBufferValid_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMASetOutputBufferValid_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMASetOutputBufferValid(%.8X)", context_ptr); @@ -299,8 +305,8 @@ SHIM_CALL XMASetOutputBufferValid_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL XMAGetOutputBufferReadOffset_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMAGetOutputBufferReadOffset_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAGetOutputBufferReadOffset(%.8X)", context_ptr); @@ -312,8 +318,8 @@ SHIM_CALL XMAGetOutputBufferReadOffset_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XMASetOutputBufferReadOffset_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMASetOutputBufferReadOffset_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); uint32_t value = SHIM_GET_ARG_32(1); @@ -328,8 +334,8 @@ SHIM_CALL XMASetOutputBufferReadOffset_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL XMAGetOutputBufferWriteOffset_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XMAGetOutputBufferWriteOffset_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAGetOutputBufferWriteOffset(%.8X)", context_ptr); @@ -341,7 +347,8 @@ SHIM_CALL XMAGetOutputBufferWriteOffset_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XMAGetPacketMetadata_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMAGetPacketMetadata_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAGetPacketMetadata(%.8X)", context_ptr); @@ -353,32 +360,36 @@ SHIM_CALL XMAGetPacketMetadata_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL XMAEnableContext_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMAEnableContext_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMAEnableContext(%.8X)", context_ptr); - StoreXmaContextIndexedRegister(state, 0x1940, context_ptr); + StoreXmaContextIndexedRegister(kernel_state, 0x1940, context_ptr); SHIM_SET_RETURN_32(0); } -SHIM_CALL XMADisableContext_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMADisableContext_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); uint32_t wait = SHIM_GET_ARG_32(1); XELOGD("XMADisableContext(%.8X, %d)", context_ptr, wait); X_HRESULT result = X_E_SUCCESS; - StoreXmaContextIndexedRegister(state, 0x1A40, context_ptr); - if (!state->emulator()->audio_system()->BlockOnXmaContext(context_ptr, !wait)) { + StoreXmaContextIndexedRegister(kernel_state, 0x1A40, context_ptr); + if (!kernel_state->emulator()->audio_system()->BlockOnXmaContext(context_ptr, + !wait)) { result = X_E_FALSE; } SHIM_SET_RETURN_32(result); } -SHIM_CALL XMABlockWhileInUse_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XMABlockWhileInUse_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t context_ptr = SHIM_GET_ARG_32(0); XELOGD("XMABlockWhileInUse(%.8X)", context_ptr); @@ -398,7 +409,7 @@ SHIM_CALL XMABlockWhileInUse_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterAudioXmaExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { // Used for both XMA* methods and direct register access. SHIM_SET_MAPPING("xboxkrnl.exe", XMACreateContext, state); SHIM_SET_MAPPING("xboxkrnl.exe", XMAReleaseContext, state); diff --git a/src/xenia/kernel/xboxkrnl_debug.cc b/src/xenia/kernel/xboxkrnl_debug.cc index 8ee398c3d..9c9cde089 100644 --- a/src/xenia/kernel/xboxkrnl_debug.cc +++ b/src/xenia/kernel/xboxkrnl_debug.cc @@ -17,10 +17,10 @@ namespace xe { namespace kernel { -#define SHIM_GPR_32(n) (uint32_t)(ppc_state->r[n]) +#define SHIM_GPR_32(n) (uint32_t)(ppc_context->r[n]) // TODO: clean me up! -SHIM_CALL DbgPrint_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL DbgPrint_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t format_ptr = SHIM_GET_ARG_32(0); if (format_ptr == 0) { SHIM_SET_RETURN_32(-1); @@ -209,7 +209,8 @@ SHIM_CALL DbgPrint_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("(DbgPrint) %s", buffer); } -SHIM_CALL DbgBreakPoint_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL DbgBreakPoint_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("DbgBreakPoint()"); DebugBreak(); } @@ -234,7 +235,8 @@ typedef struct { } X_EXCEPTION_RECORD; static_assert_size(X_EXCEPTION_RECORD, 0x50); -SHIM_CALL RtlRaiseException_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlRaiseException_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t record_ptr = SHIM_GET_ARG_32(0); auto record = reinterpret_cast(SHIM_MEM_ADDR(record_ptr)); @@ -257,7 +259,7 @@ SHIM_CALL RtlRaiseException_shim(PPCContext* ppc_state, KernelState* state) { thread = retain_object(XThread::GetCurrentThread()); } else { // Lookup thread by ID. - thread = state->GetThreadByID(thread_info->thread_id); + thread = kernel_state->GetThreadByID(thread_info->thread_id); } if (thread) { @@ -290,12 +292,13 @@ void xeKeBugCheckEx(uint32_t code, uint32_t param1, uint32_t param2, assert_always(); } -SHIM_CALL KeBugCheck_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeBugCheck_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t code = SHIM_GET_ARG_32(0); xeKeBugCheckEx(code, 0, 0, 0, 0); } -SHIM_CALL KeBugCheckEx_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeBugCheckEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t code = SHIM_GET_ARG_32(0); uint32_t param1 = SHIM_GET_ARG_32(1); uint32_t param2 = SHIM_GET_ARG_32(2); @@ -308,7 +311,7 @@ SHIM_CALL KeBugCheckEx_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterDebugExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", DbgPrint, state); SHIM_SET_MAPPING("xboxkrnl.exe", DbgBreakPoint, state); SHIM_SET_MAPPING("xboxkrnl.exe", RtlRaiseException, state); diff --git a/src/xenia/kernel/xboxkrnl_error.cc b/src/xenia/kernel/xboxkrnl_error.cc index 96e4a28da..3edddb180 100644 --- a/src/xenia/kernel/xboxkrnl_error.cc +++ b/src/xenia/kernel/xboxkrnl_error.cc @@ -983,8 +983,8 @@ const error_lookup_table error_tables[] = { }; #undef MAKE_ENTRY -SHIM_CALL RtlNtStatusToDosError_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlNtStatusToDosError_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t status = SHIM_GET_ARG_32(0); XELOGD("RtlNtStatusToDosError(%.4X)", status); @@ -1035,6 +1035,6 @@ SHIM_CALL RtlNtStatusToDosError_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xboxkrnl::RegisterErrorExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", RtlNtStatusToDosError, state); } diff --git a/src/xenia/kernel/xboxkrnl_hal.cc b/src/xenia/kernel/xboxkrnl_hal.cc index 9b13f98f0..2655f3b4b 100644 --- a/src/xenia/kernel/xboxkrnl_hal.cc +++ b/src/xenia/kernel/xboxkrnl_hal.cc @@ -16,7 +16,8 @@ namespace xe { namespace kernel { -SHIM_CALL HalReturnToFirmware_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL HalReturnToFirmware_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t routine = SHIM_GET_ARG_32(0); XELOGD("HalReturnToFirmware(%d)", routine); @@ -37,6 +38,6 @@ SHIM_CALL HalReturnToFirmware_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterHalExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", HalReturnToFirmware, state); } diff --git a/src/xenia/kernel/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl_io.cc index 16ad650f8..34da72e1c 100644 --- a/src/xenia/kernel/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl_io.cc @@ -72,7 +72,7 @@ struct FileAccess { static const uint32_t X_FILE_APPEND_DATA = 0x00000004; }; -X_STATUS NtCreateFile(PPCContext* ppc_state, KernelState* state, +X_STATUS NtCreateFile(PPCContext* ppc_context, KernelState* kernel_state, uint32_t handle_ptr, uint32_t desired_access, X_OBJECT_ATTRIBUTES* object_attrs, const char* object_name, uint32_t io_status_block_ptr, @@ -87,13 +87,13 @@ X_STATUS NtCreateFile(PPCContext* ppc_state, KernelState* state, uint32_t info = X_FILE_DOES_NOT_EXIST; uint32_t handle; - FileSystem* fs = state->file_system(); + FileSystem* fs = kernel_state->file_system(); std::unique_ptr entry; object_ref root_file; if (object_attrs->root_directory != 0xFFFFFFFD && // ObDosDevices object_attrs->root_directory != 0) { - root_file = state->object_table()->LookupObject( + root_file = kernel_state->object_table()->LookupObject( object_attrs->root_directory); assert_not_null(root_file); assert_true(root_file->type() == XObject::Type::kTypeFile); @@ -134,7 +134,7 @@ X_STATUS NtCreateFile(PPCContext* ppc_state, KernelState* state, mode = fs::Mode::READ; } XFile* file_ptr = nullptr; - result = fs->Open(std::move(entry), state, mode, + result = fs->Open(std::move(entry), kernel_state, mode, false, // TODO(benvanik): pick async mode, if needed. &file_ptr); file = object_ref(file_ptr); @@ -160,7 +160,8 @@ X_STATUS NtCreateFile(PPCContext* ppc_state, KernelState* state, return result; } -SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtCreateFile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t desired_access = SHIM_GET_ARG_32(1); uint32_t object_attributes_ptr = SHIM_GET_ARG_32(2); @@ -179,16 +180,16 @@ SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) { allocation_size_ptr, file_attributes, share_access, creation_disposition); - auto result = - NtCreateFile(ppc_state, state, handle_ptr, desired_access, &object_attrs, - object_name, io_status_block_ptr, allocation_size_ptr, - file_attributes, share_access, creation_disposition); + auto result = NtCreateFile( + ppc_context, kernel_state, handle_ptr, desired_access, &object_attrs, + object_name, io_status_block_ptr, allocation_size_ptr, file_attributes, + share_access, creation_disposition); free(object_name); SHIM_SET_RETURN_32(result); } -SHIM_CALL NtOpenFile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtOpenFile_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t desired_access = SHIM_GET_ARG_32(1); uint32_t object_attributes_ptr = SHIM_GET_ARG_32(2); @@ -203,9 +204,9 @@ SHIM_CALL NtOpenFile_shim(PPCContext* ppc_state, KernelState* state) { !object_name ? "(null)" : object_name, io_status_block_ptr, open_options); - auto result = NtCreateFile(ppc_state, state, handle_ptr, desired_access, - &object_attrs, object_name, io_status_block_ptr, 0, - 0, 0, FileDisposition::X_FILE_OPEN); + auto result = NtCreateFile( + ppc_context, kernel_state, handle_ptr, desired_access, &object_attrs, + object_name, io_status_block_ptr, 0, 0, 0, FileDisposition::X_FILE_OPEN); free(object_name); SHIM_SET_RETURN_32(result); @@ -221,7 +222,7 @@ void xeNtReadFileCompleted(XAsyncRequest* request, xeNtReadFileState* state) { delete state; } -SHIM_CALL NtReadFile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtReadFile_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t file_handle = SHIM_GET_ARG_32(0); uint32_t event_handle = SHIM_GET_ARG_32(1); uint32_t apc_routine_ptr = SHIM_GET_ARG_32(2); @@ -242,15 +243,16 @@ SHIM_CALL NtReadFile_shim(PPCContext* ppc_state, KernelState* state) { // Grab event to signal. bool signal_event = false; - auto ev = event_handle - ? state->object_table()->LookupObject(event_handle) - : object_ref(); + auto ev = + event_handle + ? kernel_state->object_table()->LookupObject(event_handle) + : object_ref(); if (event_handle && !ev) { result = X_STATUS_INVALID_HANDLE; } // Grab file. - auto file = state->object_table()->LookupObject(file_handle); + auto file = kernel_state->object_table()->LookupObject(file_handle); if (!file) { result = X_STATUS_INVALID_HANDLE; } @@ -316,7 +318,7 @@ SHIM_CALL NtReadFile_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtWriteFile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtWriteFile_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t file_handle = SHIM_GET_ARG_32(0); uint32_t event_handle = SHIM_GET_ARG_32(1); uint32_t apc_routine_ptr = SHIM_GET_ARG_32(2); @@ -340,15 +342,16 @@ SHIM_CALL NtWriteFile_shim(PPCContext* ppc_state, KernelState* state) { // Grab event to signal. bool signal_event = false; - auto ev = event_handle - ? state->object_table()->LookupObject(event_handle) - : object_ref(); + auto ev = + event_handle + ? kernel_state->object_table()->LookupObject(event_handle) + : object_ref(); if (event_handle && !ev) { result = X_STATUS_INVALID_HANDLE; } // Grab file. - auto file = state->object_table()->LookupObject(file_handle); + auto file = kernel_state->object_table()->LookupObject(file_handle); if (!ev) { result = X_STATUS_INVALID_HANDLE; } @@ -398,7 +401,8 @@ SHIM_CALL NtWriteFile_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtSetInformationFile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtSetInformationFile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t file_handle = SHIM_GET_ARG_32(0); uint32_t io_status_block_ptr = SHIM_GET_ARG_32(1); uint32_t file_info_ptr = SHIM_GET_ARG_32(2); @@ -412,7 +416,7 @@ SHIM_CALL NtSetInformationFile_shim(PPCContext* ppc_state, KernelState* state) { uint32_t info = 0; // Grab file. - auto file = state->object_table()->LookupObject(file_handle); + auto file = kernel_state->object_table()->LookupObject(file_handle); if (file) { switch (file_info_class) { case XFileDispositionInformation: { @@ -455,8 +459,8 @@ SHIM_CALL NtSetInformationFile_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t file_handle = SHIM_GET_ARG_32(0); uint32_t io_status_block_ptr = SHIM_GET_ARG_32(1); uint32_t file_info_ptr = SHIM_GET_ARG_32(2); @@ -470,7 +474,7 @@ SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_state, uint32_t info = 0; // Grab file. - auto file = state->object_table()->LookupObject(file_handle); + auto file = kernel_state->object_table()->LookupObject(file_handle); if (file) { switch (file_info_class) { case XFileInternalInformation: @@ -478,8 +482,7 @@ SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_state, assert_true(length == 8); info = 8; // TODO(benvanik): use pointer to fs:: entry? - SHIM_SET_MEM_64(file_info_ptr, - xe::hash_combine(0, file->path())); + SHIM_SET_MEM_64(file_info_ptr, xe::hash_combine(0, file->path())); break; case XFilePositionInformation: // struct FILE_POSITION_INFORMATION { @@ -511,14 +514,16 @@ SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_state, case XFileXctdCompressionInformation: assert_true(length == 4); /* - // This is wrong and puts files into wrong states for games that use XctdDecompression. + // This is wrong and puts files into wrong states for games that use + XctdDecompression. uint32_t magic; size_t bytes_read; result = file->Read(&magic, sizeof(magic), 0, &bytes_read); if (XSUCCEEDED(result)) { if (bytes_read == sizeof(magic)) { info = 4; - SHIM_SET_MEM_32(file_info_ptr, magic == xe::byte_swap(0x0FF512ED) ? 1 : 0); + SHIM_SET_MEM_32(file_info_ptr, magic == xe::byte_swap(0x0FF512ED) ? + 1 : 0); } else { result = X_STATUS_UNSUCCESSFUL; } @@ -544,8 +549,8 @@ SHIM_CALL NtQueryInformationFile_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t object_attributes_ptr = SHIM_GET_ARG_32(0); uint32_t file_info_ptr = SHIM_GET_ARG_32(1); @@ -561,14 +566,14 @@ SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state, object_ref root_file; if (attrs.root_directory != 0xFFFFFFFD) { // ObDosDevices root_file = - state->object_table()->LookupObject(attrs.root_directory); + kernel_state->object_table()->LookupObject(attrs.root_directory); assert_not_null(root_file); assert_true(root_file->type() == XObject::Type::kTypeFile); assert_always(); } // Resolve the file using the virtual file system. - FileSystem* fs = state->file_system(); + FileSystem* fs = kernel_state->file_system(); auto entry = fs->ResolvePath(object_name); if (entry) { // Found. @@ -583,8 +588,8 @@ SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t file_handle = SHIM_GET_ARG_32(0); uint32_t io_status_block_ptr = SHIM_GET_ARG_32(1); uint32_t fs_info_ptr = SHIM_GET_ARG_32(2); @@ -598,7 +603,7 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state, uint32_t info = 0; // Grab file. - auto file = state->object_table()->LookupObject(file_handle); + auto file = kernel_state->object_table()->LookupObject(file_handle); if (file) { switch (fs_info_class) { case 1: { // FileFsVolumeInformation @@ -622,7 +627,8 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state, break; } case 5: { // FileFsAttributeInformation - auto fs_attribute_info = (X_FILE_FS_ATTRIBUTE_INFORMATION*)calloc(length, 1); + auto fs_attribute_info = + (X_FILE_FS_ATTRIBUTE_INFORMATION*)calloc(length, 1); result = file->device()->QueryAttributeInfo(fs_attribute_info, length); if (XSUCCEEDED(result)) { fs_attribute_info->Write(SHIM_MEM_BASE, fs_info_ptr); @@ -657,7 +663,8 @@ SHIM_CALL NtQueryVolumeInformationFile_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t file_handle = SHIM_GET_ARG_32(0); uint32_t event_handle = SHIM_GET_ARG_32(1); uint32_t apc_routine = SHIM_GET_ARG_32(2); @@ -666,7 +673,7 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) { uint32_t file_info_ptr = SHIM_GET_ARG_32(5); uint32_t length = SHIM_GET_ARG_32(6); uint32_t file_name_ptr = SHIM_GET_ARG_32(7); - uint32_t sp = (uint32_t)ppc_state->r[1]; + uint32_t sp = (uint32_t)ppc_context->r[1]; uint32_t restart_scan = SHIM_MEM_32(sp + 0x54); char* file_name = NULL; @@ -691,9 +698,10 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_UNSUCCESSFUL; uint32_t info = 0; - auto file = state->object_table()->LookupObject(file_handle); + auto file = kernel_state->object_table()->LookupObject(file_handle); if (file) { - X_FILE_DIRECTORY_INFORMATION* dir_info = (X_FILE_DIRECTORY_INFORMATION*)calloc(length, 1); + X_FILE_DIRECTORY_INFORMATION* dir_info = + (X_FILE_DIRECTORY_INFORMATION*)calloc(length, 1); result = file->QueryDirectory(dir_info, length, file_name, restart_scan != 0); if (XSUCCEEDED(result)) { @@ -717,7 +725,8 @@ SHIM_CALL NtQueryDirectoryFile_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtFlushBuffersFile_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtFlushBuffersFile_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t file_handle = SHIM_GET_ARG_32(0); uint32_t io_status_block_ptr = SHIM_GET_ARG_32(1); @@ -733,8 +742,8 @@ SHIM_CALL NtFlushBuffersFile_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL FscSetCacheElementCount_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL FscSetCacheElementCount_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk_0 = SHIM_GET_ARG_32(0); uint32_t unk_1 = SHIM_GET_ARG_32(1); // unk_0 = 0 @@ -749,7 +758,7 @@ SHIM_CALL FscSetCacheElementCount_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xboxkrnl::RegisterIoExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", NtCreateFile, state); SHIM_SET_MAPPING("xboxkrnl.exe", NtOpenFile, state); SHIM_SET_MAPPING("xboxkrnl.exe", NtReadFile, state); diff --git a/src/xenia/kernel/xboxkrnl_memory.cc b/src/xenia/kernel/xboxkrnl_memory.cc index 2c909c1e8..2e2f2e198 100644 --- a/src/xenia/kernel/xboxkrnl_memory.cc +++ b/src/xenia/kernel/xboxkrnl_memory.cc @@ -53,8 +53,8 @@ uint32_t FromXdkProtectFlags(uint32_t protect) { return result; } -SHIM_CALL NtAllocateVirtualMemory_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NtAllocateVirtualMemory_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t base_addr_ptr = SHIM_GET_ARG_32(0); uint32_t base_addr_value = SHIM_MEM_32(base_addr_ptr); uint32_t region_size_ptr = SHIM_GET_ARG_32(1); @@ -129,14 +129,14 @@ SHIM_CALL NtAllocateVirtualMemory_shim(PPCContext* ppc_state, uint32_t protect = FromXdkProtectFlags(protect_bits); uint32_t address = 0; if (base_addr_value) { - auto heap = state->memory()->LookupHeap(base_addr_value); + auto heap = kernel_state->memory()->LookupHeap(base_addr_value); if (heap->AllocFixed(base_addr_value, adjusted_size, page_size, allocation_type, protect)) { address = base_addr_value; } } else { bool top_down = !!(alloc_type & X_MEM_TOP_DOWN); - auto heap = state->memory()->LookupHeapByType(false, page_size); + auto heap = kernel_state->memory()->LookupHeapByType(false, page_size); heap->Alloc(adjusted_size, page_size, allocation_type, protect, top_down, &address); } @@ -149,7 +149,7 @@ SHIM_CALL NtAllocateVirtualMemory_shim(PPCContext* ppc_state, // Zero memory, if needed. if (address && !(alloc_type & X_MEM_NOZERO)) { if (alloc_type & X_MEM_COMMIT) { - state->memory()->Zero(address, adjusted_size); + kernel_state->memory()->Zero(address, adjusted_size); } } @@ -162,7 +162,8 @@ SHIM_CALL NtAllocateVirtualMemory_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(X_STATUS_SUCCESS); } -SHIM_CALL NtFreeVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtFreeVirtualMemory_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t base_addr_ptr = SHIM_GET_ARG_32(0); uint32_t base_addr_value = SHIM_MEM_32(base_addr_ptr); uint32_t region_size_ptr = SHIM_GET_ARG_32(1); @@ -189,7 +190,7 @@ SHIM_CALL NtFreeVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) { return; } - auto heap = state->memory()->LookupHeap(base_addr_value); + auto heap = kernel_state->memory()->LookupHeap(base_addr_value); bool result = false; if (free_type == X_MEM_DECOMMIT) { // If zero, we may need to query size (free whole region). @@ -220,7 +221,8 @@ struct X_MEMORY_BASIC_INFORMATION { be type; }; -SHIM_CALL NtQueryVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtQueryVirtualMemory_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t base_address = SHIM_GET_ARG_32(0); uint32_t memory_basic_information_ptr = SHIM_GET_ARG_32(1); auto memory_basic_information = @@ -229,7 +231,7 @@ SHIM_CALL NtQueryVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) { XELOGD("NtQueryVirtualMemory(%.8X, %.8X)", base_address, memory_basic_information_ptr); - auto heap = state->memory()->LookupHeap(base_address); + auto heap = kernel_state->memory()->LookupHeap(base_address); HeapAllocationInfo alloc_info; if (heap == nullptr || !heap->QueryRegionInfo(base_address, &alloc_info)) { SHIM_SET_RETURN_32(X_STATUS_INVALID_PARAMETER); @@ -258,8 +260,8 @@ SHIM_CALL NtQueryVirtualMemory_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_STATUS_SUCCESS); } -SHIM_CALL MmAllocatePhysicalMemoryEx_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL MmAllocatePhysicalMemoryEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t type = SHIM_GET_ARG_32(0); uint32_t region_size = SHIM_GET_ARG_32(1); uint32_t protect_bits = SHIM_GET_ARG_32(2); @@ -310,7 +312,7 @@ SHIM_CALL MmAllocatePhysicalMemoryEx_shim(PPCContext* ppc_state, uint32_t allocation_type = kMemoryAllocationReserve | kMemoryAllocationCommit; uint32_t protect = FromXdkProtectFlags(protect_bits); bool top_down = true; - auto heap = state->memory()->LookupHeapByType(true, page_size); + auto heap = kernel_state->memory()->LookupHeapByType(true, page_size); uint32_t base_address; if (!heap->AllocRange(min_addr_range, max_addr_range, adjusted_size, adjusted_alignment, allocation_type, protect, top_down, @@ -324,7 +326,8 @@ SHIM_CALL MmAllocatePhysicalMemoryEx_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(base_address); } -SHIM_CALL MmFreePhysicalMemory_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL MmFreePhysicalMemory_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t type = SHIM_GET_ARG_32(0); uint32_t base_address = SHIM_GET_ARG_32(1); @@ -334,17 +337,17 @@ SHIM_CALL MmFreePhysicalMemory_shim(PPCContext* ppc_state, KernelState* state) { assert_true((base_address & 0x1F) == 0); - auto heap = state->memory()->LookupHeap(base_address); + auto heap = kernel_state->memory()->LookupHeap(base_address); heap->Release(base_address); } -SHIM_CALL MmQueryAddressProtect_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL MmQueryAddressProtect_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t base_address = SHIM_GET_ARG_32(0); XELOGD("MmQueryAddressProtect(%.8X)", base_address); - auto heap = state->memory()->LookupHeap(base_address); + auto heap = kernel_state->memory()->LookupHeap(base_address); uint32_t access; if (!heap->QueryProtect(base_address, &access)) { access = 0; @@ -354,13 +357,13 @@ SHIM_CALL MmQueryAddressProtect_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(access); } -SHIM_CALL MmQueryAllocationSize_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL MmQueryAllocationSize_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t base_address = SHIM_GET_ARG_32(0); XELOGD("MmQueryAllocationSize(%.8X)", base_address); - auto heap = state->memory()->LookupHeap(base_address); + auto heap = kernel_state->memory()->LookupHeap(base_address); uint32_t size; if (!heap->QuerySize(base_address, &size)) { size = 0; @@ -369,7 +372,8 @@ SHIM_CALL MmQueryAllocationSize_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(size); } -SHIM_CALL MmQueryStatistics_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL MmQueryStatistics_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t stats_ptr = SHIM_GET_ARG_32(0); XELOGD("MmQueryStatistics(%.8X)", stats_ptr); @@ -425,7 +429,8 @@ SHIM_CALL MmQueryStatistics_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/windows/hardware/ff554547(v=vs.85).aspx -SHIM_CALL MmGetPhysicalAddress_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL MmGetPhysicalAddress_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t base_address = SHIM_GET_ARG_32(0); XELOGD("MmGetPhysicalAddress(%.8X)", base_address); @@ -443,7 +448,8 @@ SHIM_CALL MmGetPhysicalAddress_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(physical_address); } -SHIM_CALL MmMapIoSpace_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL MmMapIoSpace_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk0 = SHIM_GET_ARG_32(0); uint32_t src_address = SHIM_GET_ARG_32(1); // from MmGetPhysicalAddress uint32_t size = SHIM_GET_ARG_32(2); @@ -461,8 +467,8 @@ SHIM_CALL MmMapIoSpace_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(src_address); } -SHIM_CALL ExAllocatePoolTypeWithTag_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL ExAllocatePoolTypeWithTag_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t size = SHIM_GET_ARG_32(0); uint32_t tag = SHIM_GET_ARG_32(1); uint32_t zero = SHIM_GET_ARG_32(2); @@ -477,20 +483,21 @@ SHIM_CALL ExAllocatePoolTypeWithTag_shim(PPCContext* ppc_state, alignment = 4 * 1024; } - uint32_t addr = state->memory()->SystemHeapAlloc(adjusted_size, alignment); + uint32_t addr = + kernel_state->memory()->SystemHeapAlloc(adjusted_size, alignment); SHIM_SET_RETURN_32(addr); } -SHIM_CALL ExFreePool_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL ExFreePool_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t base_address = SHIM_GET_ARG_32(0); XELOGD("ExFreePool(%.8X)", base_address); - state->memory()->SystemHeapFree(base_address); + kernel_state->memory()->SystemHeapFree(base_address); } -SHIM_CALL KeLockL2_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeLockL2_shim(PPCContext* ppc_context, KernelState* kernel_state) { // Ignored for now. This is just a perf optimization, I think. // It may be useful as a hint for CPU-GPU transfer. @@ -499,7 +506,7 @@ SHIM_CALL KeLockL2_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL KeUnlockL2_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeUnlockL2_shim(PPCContext* ppc_context, KernelState* kernel_state) { XELOGD("KeUnlockL2(?)"); } @@ -507,7 +514,7 @@ SHIM_CALL KeUnlockL2_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterMemoryExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", NtAllocateVirtualMemory, state); SHIM_SET_MAPPING("xboxkrnl.exe", NtFreeVirtualMemory, state); SHIM_SET_MAPPING("xboxkrnl.exe", NtQueryVirtualMemory, state); diff --git a/src/xenia/kernel/xboxkrnl_misc.cc b/src/xenia/kernel/xboxkrnl_misc.cc index 17ee8f2b7..abe08374b 100644 --- a/src/xenia/kernel/xboxkrnl_misc.cc +++ b/src/xenia/kernel/xboxkrnl_misc.cc @@ -17,8 +17,8 @@ namespace xe { namespace kernel { -SHIM_CALL KeEnableFpuExceptions_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeEnableFpuExceptions_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t enabled = SHIM_GET_ARG_32(0); XELOGD("KeEnableFpuExceptions(%d)", enabled); // TODO(benvanik): can we do anything about exceptions? @@ -28,6 +28,6 @@ SHIM_CALL KeEnableFpuExceptions_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xboxkrnl::RegisterMiscExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", KeEnableFpuExceptions, state); } diff --git a/src/xenia/kernel/xboxkrnl_module.h b/src/xenia/kernel/xboxkrnl_module.h index 5e34e6c70..61870ec02 100644 --- a/src/xenia/kernel/xboxkrnl_module.h +++ b/src/xenia/kernel/xboxkrnl_module.h @@ -28,6 +28,7 @@ class XboxkrnlModule : public XKernelModule { virtual ~XboxkrnlModule(); static void RegisterExportTable(xe::cpu::ExportResolver* export_resolver); + static void RegisterExport(xe::cpu::Export* export); int LaunchModule(const char* path); diff --git a/src/xenia/kernel/xboxkrnl_modules.cc b/src/xenia/kernel/xboxkrnl_modules.cc index 0fd7aea6f..ad9c1786d 100644 --- a/src/xenia/kernel/xboxkrnl_modules.cc +++ b/src/xenia/kernel/xboxkrnl_modules.cc @@ -100,7 +100,8 @@ X_STATUS xeExGetXConfigSetting(uint16_t category, uint16_t setting, return X_STATUS_SUCCESS; } -SHIM_CALL ExGetXConfigSetting_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL ExGetXConfigSetting_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint16_t category = SHIM_GET_ARG_16(0); uint16_t setting = SHIM_GET_ARG_16(1); uint32_t buffer_ptr = SHIM_GET_ARG_32(2); @@ -122,8 +123,8 @@ SHIM_CALL ExGetXConfigSetting_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL XexCheckExecutablePrivilege_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XexCheckExecutablePrivilege_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t privilege = SHIM_GET_ARG_32(0); XELOGD("XexCheckExecutablePrivilege(%.8X)", privilege); @@ -135,7 +136,7 @@ SHIM_CALL XexCheckExecutablePrivilege_shim(PPCContext* ppc_state, // Privilege=6 -> 0x00000040 -> XEX_SYSTEM_INSECURE_SOCKETS uint32_t mask = 1 << privilege; - auto module = state->GetExecutableModule(); + auto module = kernel_state->GetExecutableModule(); if (!module) { SHIM_SET_RETURN_32(0); return; @@ -148,7 +149,8 @@ SHIM_CALL XexCheckExecutablePrivilege_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL XexGetModuleHandle_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XexGetModuleHandle_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t module_name_ptr = SHIM_GET_ARG_32(0); const char* module_name = (const char*)SHIM_MEM_ADDR(module_name_ptr); uint32_t module_handle_ptr = SHIM_GET_ARG_32(1); @@ -157,9 +159,9 @@ SHIM_CALL XexGetModuleHandle_shim(PPCContext* ppc_state, KernelState* state) { object_ref module; if (!module_name) { - module = state->GetExecutableModule(); + module = kernel_state->GetExecutableModule(); } else { - module = state->GetModule(module_name); + module = kernel_state->GetModule(module_name); } if (!module) { SHIM_SET_MEM_32(module_handle_ptr, 0); @@ -173,7 +175,8 @@ SHIM_CALL XexGetModuleHandle_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_ERROR_SUCCESS); } -SHIM_CALL XexGetModuleSection_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XexGetModuleSection_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t name_ptr = SHIM_GET_ARG_32(1); const char* name = (const char*)SHIM_MEM_ADDR(name_ptr); @@ -185,7 +188,7 @@ SHIM_CALL XexGetModuleSection_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; - auto module = state->object_table()->LookupObject(handle); + auto module = kernel_state->object_table()->LookupObject(handle); if (module) { uint32_t section_data = 0; uint32_t section_size = 0; @@ -201,7 +204,8 @@ SHIM_CALL XexGetModuleSection_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL XexLoadImage_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XexLoadImage_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t module_name_ptr = SHIM_GET_ARG_32(0); const char* module_name = (const char*)SHIM_MEM_ADDR(module_name_ptr); uint32_t module_flags = SHIM_GET_ARG_32(1); @@ -214,13 +218,14 @@ SHIM_CALL XexLoadImage_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_NO_SUCH_FILE; X_HANDLE module_handle = X_INVALID_HANDLE_VALUE; - auto module = state->GetModule(module_name); + auto module = kernel_state->GetModule(module_name); if (module) { // Existing module found, just add a reference and obtain a handle. - result = state->object_table()->AddHandle(module.get(), &module_handle); + result = + kernel_state->object_table()->AddHandle(module.get(), &module_handle); } else { // Not found; attempt to load as a user module. - auto user_module = state->LoadUserModule(module_name); + auto user_module = kernel_state->LoadUserModule(module_name); if (user_module) { user_module->RetainHandle(); module_handle = user_module->handle(); @@ -232,20 +237,21 @@ SHIM_CALL XexLoadImage_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL XexUnloadImage_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XexUnloadImage_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t module_handle = SHIM_GET_ARG_32(0); XELOGD("XexUnloadImage(%.8X)", module_handle); X_STATUS result = X_STATUS_INVALID_HANDLE; - result = state->object_table()->RemoveHandle(module_handle); + result = kernel_state->object_table()->RemoveHandle(module_handle); SHIM_SET_RETURN_32(result); } -SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t module_handle = SHIM_GET_ARG_32(0); uint32_t ordinal = SHIM_GET_ARG_32(1); uint32_t out_function_ptr = SHIM_GET_ARG_32(2); @@ -268,9 +274,9 @@ SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_state, object_ref module; if (!module_handle) { - module = state->GetExecutableModule(); + module = kernel_state->GetExecutableModule(); } else { - module = state->object_table()->LookupObject(module_handle); + module = kernel_state->object_table()->LookupObject(module_handle); } if (module) { uint32_t ptr; @@ -292,8 +298,8 @@ SHIM_CALL XexGetProcedureAddress_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL ExRegisterTitleTerminateNotification_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL ExRegisterTitleTerminateNotification_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t registration_ptr = SHIM_GET_ARG_32(0); uint32_t create = SHIM_GET_ARG_32(1); @@ -318,7 +324,7 @@ SHIM_CALL ExRegisterTitleTerminateNotification_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xboxkrnl::RegisterModuleExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", ExGetXConfigSetting, state); SHIM_SET_MAPPING("xboxkrnl.exe", XexCheckExecutablePrivilege, state); diff --git a/src/xenia/kernel/xboxkrnl_ob.cc b/src/xenia/kernel/xboxkrnl_ob.cc index 4893b54a6..e5a131819 100644 --- a/src/xenia/kernel/xboxkrnl_ob.cc +++ b/src/xenia/kernel/xboxkrnl_ob.cc @@ -18,7 +18,8 @@ namespace xe { namespace kernel { -SHIM_CALL ObOpenObjectByName_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL ObOpenObjectByName_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // r3 = ptr to info? // +0 = -4 // +4 = name ptr @@ -39,7 +40,8 @@ SHIM_CALL ObOpenObjectByName_shim(PPCContext* ppc_state, KernelState* state) { obj_attributes_ptr, name.c_str(), object_type_ptr, unk, handle_ptr); X_HANDLE handle = X_INVALID_HANDLE_VALUE; - X_STATUS result = state->object_table()->GetObjectByName(name, &handle); + X_STATUS result = + kernel_state->object_table()->GetObjectByName(name, &handle); if (XSUCCEEDED(result)) { SHIM_SET_MEM_32(handle_ptr, handle); } @@ -47,8 +49,8 @@ SHIM_CALL ObOpenObjectByName_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_context, + KernelState* kernel_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); @@ -58,7 +60,7 @@ SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_state, X_STATUS result = X_STATUS_SUCCESS; - auto object = state->object_table()->LookupObject(handle); + auto object = kernel_state->object_table()->LookupObject(handle); if (object) { // TODO(benvanik): verify type with object_type_ptr @@ -110,7 +112,8 @@ SHIM_CALL ObReferenceObjectByHandle_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL ObDereferenceObject_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL ObDereferenceObject_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t native_ptr = SHIM_GET_ARG_32(0); XELOGD("ObDereferenceObject(%.8X)", native_ptr); @@ -122,7 +125,7 @@ SHIM_CALL ObDereferenceObject_shim(PPCContext* ppc_state, KernelState* state) { } void* object_ptr = SHIM_MEM_ADDR(native_ptr); - auto object = XObject::GetNativeObject(state, object_ptr); + auto object = XObject::GetNativeObject(kernel_state, object_ptr); if (object) { object->Release(); } @@ -130,7 +133,8 @@ SHIM_CALL ObDereferenceObject_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL NtDuplicateObject_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtDuplicateObject_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t new_handle_ptr = SHIM_GET_ARG_32(1); uint32_t options = SHIM_GET_ARG_32(2); @@ -148,7 +152,7 @@ SHIM_CALL NtDuplicateObject_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; - auto object = state->object_table()->LookupObject(handle); + auto object = kernel_state->object_table()->LookupObject(handle); if (object) { object->Retain(); object->RetainHandle(); @@ -158,7 +162,7 @@ SHIM_CALL NtDuplicateObject_shim(PPCContext* ppc_state, KernelState* state) { } if (options == 1 /* DUPLICATE_CLOSE_SOURCE */) { // Always close the source object. - state->object_table()->RemoveHandle(handle); + kernel_state->object_table()->RemoveHandle(handle); } } else { result = X_STATUS_INVALID_HANDLE; @@ -167,14 +171,14 @@ SHIM_CALL NtDuplicateObject_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtClose_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtClose_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); XELOGD("NtClose(%.8X)", handle); X_STATUS result = X_STATUS_INVALID_HANDLE; - result = state->object_table()->RemoveHandle(handle); + result = kernel_state->object_table()->RemoveHandle(handle); SHIM_SET_RETURN_32(result); } @@ -183,7 +187,7 @@ SHIM_CALL NtClose_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterObExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", ObOpenObjectByName, state); SHIM_SET_MAPPING("xboxkrnl.exe", ObReferenceObjectByHandle, state); SHIM_SET_MAPPING("xboxkrnl.exe", ObDereferenceObject, state); diff --git a/src/xenia/kernel/xboxkrnl_private.h b/src/xenia/kernel/xboxkrnl_private.h index 56597f72b..042279cba 100644 --- a/src/xenia/kernel/xboxkrnl_private.h +++ b/src/xenia/kernel/xboxkrnl_private.h @@ -20,35 +20,35 @@ class KernelState; namespace xboxkrnl { // Registration functions, one per file. void RegisterAudioExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterAudioXmaExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterDebugExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterErrorExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterHalExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterIoExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterMemoryExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterMiscExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterModuleExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterObExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterRtlExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterStringExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterThreadingExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterUsbcamExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); void RegisterVideoExports(xe::cpu::ExportResolver* export_resolver, - KernelState* state); + KernelState* kernel_state); } // namespace xboxkrnl } // namespace kernel diff --git a/src/xenia/kernel/xboxkrnl_rtl.cc b/src/xenia/kernel/xboxkrnl_rtl.cc index d8c908810..20d7eeede 100644 --- a/src/xenia/kernel/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/xboxkrnl_rtl.cc @@ -25,7 +25,8 @@ namespace xe { namespace kernel { // http://msdn.microsoft.com/en-us/library/ff561778 -SHIM_CALL RtlCompareMemory_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlCompareMemory_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t source1_ptr = SHIM_GET_ARG_32(0); uint32_t source2_ptr = SHIM_GET_ARG_32(1); uint32_t length = SHIM_GET_ARG_32(2); @@ -55,8 +56,8 @@ SHIM_CALL RtlCompareMemory_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/ff552123 -SHIM_CALL RtlCompareMemoryUlong_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlCompareMemoryUlong_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t source_ptr = SHIM_GET_ARG_32(0); uint32_t length = SHIM_GET_ARG_32(1); uint32_t pattern = SHIM_GET_ARG_32(2); @@ -93,7 +94,8 @@ SHIM_CALL RtlCompareMemoryUlong_shim(PPCContext* ppc_state, } // http://msdn.microsoft.com/en-us/library/ff552263 -SHIM_CALL RtlFillMemoryUlong_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlFillMemoryUlong_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t destination_ptr = SHIM_GET_ARG_32(0); uint32_t length = SHIM_GET_ARG_32(1); uint32_t pattern = SHIM_GET_ARG_32(2); @@ -122,7 +124,8 @@ SHIM_CALL RtlFillMemoryUlong_shim(PPCContext* ppc_state, KernelState* state) { } } -SHIM_CALL RtlCompareString_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlCompareString_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t string_1_ptr = SHIM_GET_ARG_32(0); uint32_t string_2_ptr = SHIM_GET_ARG_32(1); uint32_t case_insensitive = SHIM_GET_ARG_32(2); @@ -138,7 +141,8 @@ SHIM_CALL RtlCompareString_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL RtlCompareStringN_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlCompareStringN_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t string_1_ptr = SHIM_GET_ARG_32(0); uint32_t string_1_len = SHIM_GET_ARG_32(1); uint32_t string_2_ptr = SHIM_GET_ARG_32(2); @@ -172,7 +176,8 @@ SHIM_CALL RtlCompareStringN_shim(PPCContext* ppc_state, KernelState* state) { // } ANSI_STRING, *PANSI_STRING; // http://msdn.microsoft.com/en-us/library/ff561918 -SHIM_CALL RtlInitAnsiString_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlInitAnsiString_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t destination_ptr = SHIM_GET_ARG_32(0); uint32_t source_ptr = SHIM_GET_ARG_32(1); @@ -196,7 +201,8 @@ SHIM_CALL RtlInitAnsiString_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/ff561899 -SHIM_CALL RtlFreeAnsiString_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlFreeAnsiString_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t string_ptr = SHIM_GET_ARG_32(0); XELOGD("RtlFreeAnsiString(%.8X)", string_ptr); @@ -209,7 +215,7 @@ SHIM_CALL RtlFreeAnsiString_shim(PPCContext* ppc_state, KernelState* state) { return; } uint32_t length = SHIM_MEM_16(string_ptr + 2); - state->memory()->SystemHeapFree(buffer); + kernel_state->memory()->SystemHeapFree(buffer); SHIM_SET_MEM_16(string_ptr + 0, 0); SHIM_SET_MEM_16(string_ptr + 2, 0); @@ -223,7 +229,8 @@ SHIM_CALL RtlFreeAnsiString_shim(PPCContext* ppc_state, KernelState* state) { // } UNICODE_STRING, *PUNICODE_STRING; // http://msdn.microsoft.com/en-us/library/ff561934 -SHIM_CALL RtlInitUnicodeString_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlInitUnicodeString_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t destination_ptr = SHIM_GET_ARG_32(0); uint32_t source_ptr = SHIM_GET_ARG_32(1); @@ -251,7 +258,8 @@ SHIM_CALL RtlInitUnicodeString_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/ff561903 -SHIM_CALL RtlFreeUnicodeString_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlFreeUnicodeString_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t string_ptr = SHIM_GET_ARG_32(0); XELOGD("RtlFreeUnicodeString(%.8X)", string_ptr); @@ -264,7 +272,7 @@ SHIM_CALL RtlFreeUnicodeString_shim(PPCContext* ppc_state, KernelState* state) { return; } uint32_t length = SHIM_MEM_16(string_ptr + 2); - state->memory()->SystemHeapFree(buffer); + kernel_state->memory()->SystemHeapFree(buffer); SHIM_SET_MEM_16(string_ptr + 0, 0); SHIM_SET_MEM_16(string_ptr + 2, 0); @@ -272,8 +280,8 @@ SHIM_CALL RtlFreeUnicodeString_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/ff562969 -SHIM_CALL RtlUnicodeStringToAnsiString_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlUnicodeStringToAnsiString_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t destination_ptr = SHIM_GET_ARG_32(0); uint32_t source_ptr = SHIM_GET_ARG_32(1); uint32_t alloc_dest = SHIM_GET_ARG_32(2); @@ -297,7 +305,7 @@ SHIM_CALL RtlUnicodeStringToAnsiString_shim(PPCContext* ppc_state, X_STATUS result = X_STATUS_SUCCESS; if (alloc_dest) { uint32_t buffer_ptr = - state->memory()->SystemHeapAlloc(uint32_t(ansi_str.size() + 1)); + kernel_state->memory()->SystemHeapAlloc(uint32_t(ansi_str.size() + 1)); memcpy(SHIM_MEM_ADDR(buffer_ptr), ansi_str.data(), ansi_str.size() + 1); SHIM_SET_MEM_16(destination_ptr + 0, static_cast(ansi_str.size())); @@ -319,8 +327,8 @@ SHIM_CALL RtlUnicodeStringToAnsiString_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL RtlMultiByteToUnicodeN_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlMultiByteToUnicodeN_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t destination_ptr = SHIM_GET_ARG_32(0); uint32_t destination_len = SHIM_GET_ARG_32(1); uint32_t written_ptr = SHIM_GET_ARG_32(2); @@ -345,8 +353,8 @@ SHIM_CALL RtlMultiByteToUnicodeN_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL RtlUnicodeToMultiByteN_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlUnicodeToMultiByteN_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t destination_ptr = SHIM_GET_ARG_32(0); uint32_t destination_len = SHIM_GET_ARG_32(1); uint32_t written_ptr = SHIM_GET_ARG_32(2); @@ -372,8 +380,8 @@ SHIM_CALL RtlUnicodeToMultiByteN_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL RtlImageXexHeaderField_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlImageXexHeaderField_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t xex_header_base = SHIM_GET_ARG_32(0); uint32_t image_field = SHIM_GET_ARG_32(1); @@ -400,7 +408,7 @@ SHIM_CALL RtlImageXexHeaderField_shim(PPCContext* ppc_state, // TODO(benvanik): use xex_header_base to dereference this. // Right now we are only concerned with games making this call on their main // module, so this hack is fine. - auto module = state->GetExecutableModule(); + auto module = kernel_state->GetExecutableModule(); const xe_xex2_header_t* xex_header = module->xex_header(); for (size_t n = 0; n < xex_header->header_count; n++) { @@ -461,8 +469,8 @@ void xeRtlInitializeCriticalSection(X_RTL_CRITICAL_SECTION* cs, cs->owning_thread_id = 0; } -SHIM_CALL RtlInitializeCriticalSection_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlInitializeCriticalSection_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t cs_ptr = SHIM_GET_ARG_32(0); XELOGD("RtlInitializeCriticalSection(%.8X)", cs_ptr); @@ -496,8 +504,8 @@ X_STATUS xeRtlInitializeCriticalSectionAndSpinCount(X_RTL_CRITICAL_SECTION* cs, return X_STATUS_SUCCESS; } -SHIM_CALL RtlInitializeCriticalSectionAndSpinCount_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlInitializeCriticalSectionAndSpinCount_shim( + PPCContext* ppc_context, KernelState* kernel_state) { uint32_t cs_ptr = SHIM_GET_ARG_32(0); uint32_t spin_count = SHIM_GET_ARG_32(1); @@ -510,15 +518,15 @@ SHIM_CALL RtlInitializeCriticalSectionAndSpinCount_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL RtlEnterCriticalSection_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlEnterCriticalSection_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // VOID // _Inout_ LPCRITICAL_SECTION lpCriticalSection uint32_t cs_ptr = SHIM_GET_ARG_32(0); // XELOGD("RtlEnterCriticalSection(%.8X)", cs_ptr); - const uint8_t* pcr = SHIM_MEM_ADDR(ppc_state->r[13]); + const uint8_t* pcr = SHIM_MEM_ADDR(ppc_context->r[13]); uint32_t thread_id = XThread::GetCurrentThreadId(pcr); auto cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr); @@ -552,15 +560,15 @@ spin: cs->recursion_count = 1; } -SHIM_CALL RtlTryEnterCriticalSection_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlTryEnterCriticalSection_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // DWORD // _Inout_ LPCRITICAL_SECTION lpCriticalSection uint32_t cs_ptr = SHIM_GET_ARG_32(0); // XELOGD("RtlTryEnterCriticalSection(%.8X)", cs_ptr); - const uint8_t* pcr = SHIM_MEM_ADDR(ppc_state->r[13]); + const uint8_t* pcr = SHIM_MEM_ADDR(ppc_context->r[13]); uint32_t thread_id = XThread::GetCurrentThreadId(pcr); auto cs = (X_RTL_CRITICAL_SECTION*)SHIM_MEM_ADDR(cs_ptr); @@ -579,8 +587,8 @@ SHIM_CALL RtlTryEnterCriticalSection_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL RtlLeaveCriticalSection_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL RtlLeaveCriticalSection_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // VOID // _Inout_ LPCRITICAL_SECTION lpCriticalSection uint32_t cs_ptr = SHIM_GET_ARG_32(0); @@ -607,7 +615,8 @@ SHIM_CALL RtlLeaveCriticalSection_shim(PPCContext* ppc_state, XThread::GetCurrentThread()->CheckApcs(); } -SHIM_CALL RtlTimeToTimeFields_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlTimeToTimeFields_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t time_ptr = SHIM_GET_ARG_32(0); uint32_t time_fields_ptr = SHIM_GET_ARG_32(1); @@ -630,7 +639,8 @@ SHIM_CALL RtlTimeToTimeFields_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_MEM_16(time_fields_ptr + 12, st.wMilliseconds); } -SHIM_CALL RtlTimeFieldsToTime_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL RtlTimeFieldsToTime_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t time_fields_ptr = SHIM_GET_ARG_32(0); uint32_t time_ptr = SHIM_GET_ARG_32(1); @@ -661,7 +671,7 @@ SHIM_CALL RtlTimeFieldsToTime_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterRtlExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", RtlCompareMemory, state); SHIM_SET_MAPPING("xboxkrnl.exe", RtlCompareMemoryUlong, state); SHIM_SET_MAPPING("xboxkrnl.exe", RtlFillMemoryUlong, state); diff --git a/src/xenia/kernel/xboxkrnl_strings.cc b/src/xenia/kernel/xboxkrnl_strings.cc index 002393524..c5a5d0e16 100644 --- a/src/xenia/kernel/xboxkrnl_strings.cc +++ b/src/xenia/kernel/xboxkrnl_strings.cc @@ -19,7 +19,7 @@ namespace xe { namespace kernel { -SHIM_CALL sprintf_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL sprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t buffer_ptr = SHIM_GET_ARG_32(0); uint32_t format_ptr = SHIM_GET_ARG_32(1); @@ -34,7 +34,7 @@ SHIM_CALL sprintf_shim(PPCContext* ppc_state, KernelState* state) { const char* format = (const char*)SHIM_MEM_ADDR(format_ptr); int arg_index = 2; - uint32_t sp = (uint32_t)ppc_state->r[1]; + uint32_t sp = (uint32_t)ppc_context->r[1]; #define LOAD_SPRINTF_ARG(ARG) \ (ARG < 8) ? SHIM_GET_ARG_32(ARG) : SHIM_MEM_64(sp + 0x54 + 8) @@ -201,7 +201,7 @@ SHIM_CALL sprintf_shim(PPCContext* ppc_state, KernelState* state) { } // TODO: clean me up! -SHIM_CALL vsprintf_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL vsprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t buffer_ptr = SHIM_GET_ARG_32(0); uint32_t format_ptr = SHIM_GET_ARG_32(1); uint32_t arg_ptr = SHIM_GET_ARG_32(2); @@ -409,7 +409,7 @@ SHIM_CALL vsprintf_shim(PPCContext* ppc_state, KernelState* state) { } // TODO: clean me up! -SHIM_CALL _vsnprintf_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL _vsnprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t buffer_ptr = SHIM_GET_ARG_32(0); uint32_t count = SHIM_GET_ARG_32(1); uint32_t format_ptr = SHIM_GET_ARG_32(2); @@ -812,7 +812,7 @@ uint32_t vswprintf_core(wchar_t* buffer, const wchar_t* format, } // TODO: clean me up! -SHIM_CALL _vswprintf_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL _vswprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t buffer_ptr = SHIM_GET_ARG_32(0); uint32_t format_ptr = SHIM_GET_ARG_32(1); uint32_t arg_ptr = SHIM_GET_ARG_32(2); @@ -834,7 +834,7 @@ SHIM_CALL _vswprintf_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(ret); } -SHIM_CALL _vscwprintf_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL _vscwprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t format_ptr = SHIM_GET_ARG_32(0); uint32_t arg_ptr = SHIM_GET_ARG_32(1); @@ -858,7 +858,7 @@ SHIM_CALL _vscwprintf_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterStringExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", sprintf, state); SHIM_SET_MAPPING("xboxkrnl.exe", vsprintf, state); SHIM_SET_MAPPING("xboxkrnl.exe", _vsnprintf, state); diff --git a/src/xenia/kernel/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl_threading.cc index ad79cbfe1..77b466ead 100644 --- a/src/xenia/kernel/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl_threading.cc @@ -61,7 +61,8 @@ namespace kernel { // stw r3, 0x160(r11) // } -void AssertNoNameCollision(KernelState* state, uint32_t obj_attributes_ptr) { +void AssertNoNameCollision(KernelState* kernel_state, + uint32_t obj_attributes_ptr) { // If the name exists and its type matches, we can return that (ref+1) // with a success of NAME_EXISTS. // If the name exists and its type doesn't match, we do NAME_COLLISION. @@ -70,12 +71,14 @@ void AssertNoNameCollision(KernelState* state, uint32_t obj_attributes_ptr) { return; } uint32_t name_str_ptr = xe::load_and_swap( - state->memory()->TranslateVirtual(obj_attributes_ptr + 4)); + kernel_state->memory()->TranslateVirtual(obj_attributes_ptr + 4)); if (name_str_ptr) { - X_ANSI_STRING name_str(state->memory()->virtual_membase(), name_str_ptr); + X_ANSI_STRING name_str(kernel_state->memory()->virtual_membase(), + name_str_ptr); auto name = name_str.to_string(); X_HANDLE handle = X_INVALID_HANDLE_VALUE; - X_RESULT result = state->object_table()->GetObjectByName(name, &handle); + X_RESULT result = + kernel_state->object_table()->GetObjectByName(name, &handle); if (XSUCCEEDED(result)) { // Found something! assert_always("Existing names not implemented"); @@ -83,7 +86,8 @@ void AssertNoNameCollision(KernelState* state, uint32_t obj_attributes_ptr) { } } -SHIM_CALL ExCreateThread_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL ExCreateThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t stack_size = SHIM_GET_ARG_32(1); uint32_t thread_id_ptr = SHIM_GET_ARG_32(2); @@ -108,14 +112,15 @@ SHIM_CALL ExCreateThread_shim(PPCContext* ppc_state, KernelState* state) { // Inherit default stack size if (stack_size == 0) { - stack_size = state->GetExecutableModule()->xex_header()->exe_stack_size; + stack_size = + kernel_state->GetExecutableModule()->xex_header()->exe_stack_size; } // Stack must be aligned to 16kb pages stack_size = std::max((uint32_t)0x4000, ((stack_size + 0xFFF) & 0xFFFFF000)); auto thread = object_ref( - new XThread(state, stack_size, xapi_thread_startup, start_address, + new XThread(kernel_state, stack_size, xapi_thread_startup, start_address, start_context, creation_flags)); X_STATUS result = thread->Create(); @@ -137,7 +142,8 @@ SHIM_CALL ExCreateThread_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL ExTerminateThread_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL ExTerminateThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t exit_code = SHIM_GET_ARG_32(0); XELOGD("ExTerminateThread(%d)", exit_code); @@ -149,7 +155,8 @@ SHIM_CALL ExTerminateThread_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtResumeThread_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtResumeThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t suspend_count_ptr = SHIM_GET_ARG_32(1); @@ -158,7 +165,7 @@ SHIM_CALL NtResumeThread_shim(PPCContext* ppc_state, KernelState* state) { X_RESULT result = X_STATUS_INVALID_HANDLE; uint32_t suspend_count = 0; - auto thread = state->object_table()->LookupObject(handle); + auto thread = kernel_state->object_table()->LookupObject(handle); if (thread) { result = thread->Resume(&suspend_count); } @@ -169,14 +176,15 @@ SHIM_CALL NtResumeThread_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL KeResumeThread_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeResumeThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t thread_ptr = SHIM_GET_ARG_32(0); XELOGD("KeResumeThread(%.8X)", thread_ptr); X_STATUS result = X_STATUS_SUCCESS; - auto thread = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(thread_ptr)); + auto thread = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(thread_ptr)); if (thread) { result = thread->Resume(); } else { @@ -186,7 +194,8 @@ SHIM_CALL KeResumeThread_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtSuspendThread_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtSuspendThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle = SHIM_GET_ARG_32(0); uint32_t suspend_count_ptr = SHIM_GET_ARG_32(1); @@ -195,7 +204,7 @@ SHIM_CALL NtSuspendThread_shim(PPCContext* ppc_state, KernelState* state) { X_RESULT result = X_STATUS_SUCCESS; uint32_t suspend_count = 0; - auto thread = state->object_table()->LookupObject(handle); + auto thread = kernel_state->object_table()->LookupObject(handle); if (thread) { result = thread->Suspend(&suspend_count); } else { @@ -209,14 +218,15 @@ SHIM_CALL NtSuspendThread_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL KeSetAffinityThread_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeSetAffinityThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t thread_ptr = SHIM_GET_ARG_32(0); uint32_t affinity = SHIM_GET_ARG_32(1); XELOGD("KeSetAffinityThread(%.8X, %.8X)", thread_ptr, affinity); - auto thread = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(thread_ptr)); + auto thread = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(thread_ptr)); if (thread) { thread->SetAffinity(affinity); } @@ -224,16 +234,16 @@ SHIM_CALL KeSetAffinityThread_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(affinity); } -SHIM_CALL KeQueryBasePriorityThread_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeQueryBasePriorityThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t thread_ptr = SHIM_GET_ARG_32(0); XELOGD("KeQueryBasePriorityThread(%.8X)", thread_ptr); int32_t priority = 0; - auto thread = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(thread_ptr)); + auto thread = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(thread_ptr)); if (thread) { priority = thread->QueryPriority(); } @@ -241,8 +251,8 @@ SHIM_CALL KeQueryBasePriorityThread_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(priority); } -SHIM_CALL KeSetBasePriorityThread_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeSetBasePriorityThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t thread_ptr = SHIM_GET_ARG_32(0); uint32_t increment = SHIM_GET_ARG_32(1); @@ -253,13 +263,13 @@ SHIM_CALL KeSetBasePriorityThread_shim(PPCContext* ppc_state, object_ref thread; if (thread_ptr < 0x1000) { // They passed in a handle (for some reason) - thread = state->object_table()->LookupObject(thread_ptr); + thread = kernel_state->object_table()->LookupObject(thread_ptr); // Log it in case this is the source of any problems in the future XELOGD("KeSetBasePriorityThread - Interpreting thread ptr as handle!"); } else { - thread = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(thread_ptr)); + thread = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(thread_ptr)); } if (thread) { @@ -270,15 +280,15 @@ SHIM_CALL KeSetBasePriorityThread_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(prev_priority); } -SHIM_CALL KeSetDisableBoostThread_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeSetDisableBoostThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t thread_ptr = SHIM_GET_ARG_32(0); uint32_t disabled = SHIM_GET_ARG_32(1); XELOGD("KeSetDisableBoostThread(%.8X, %.8X)", thread_ptr, disabled); - auto thread = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(thread_ptr)); + auto thread = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(thread_ptr)); if (thread) { // Uhm? } @@ -286,18 +296,18 @@ SHIM_CALL KeSetDisableBoostThread_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL KeGetCurrentProcessType_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeGetCurrentProcessType_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // XELOGD( // "KeGetCurrentProcessType()"); // DWORD - SHIM_SET_RETURN_32(state->process_type()); + SHIM_SET_RETURN_32(kernel_state->process_type()); } -SHIM_CALL KeSetCurrentProcessType_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeSetCurrentProcessType_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t type = SHIM_GET_ARG_32(0); // One of X_PROCTYPE_? @@ -305,11 +315,11 @@ SHIM_CALL KeSetCurrentProcessType_shim(PPCContext* ppc_state, assert_true(type >= 0 && type <= 2); - state->set_process_type(type); + kernel_state->set_process_type(type); } -SHIM_CALL KeQueryPerformanceFrequency_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeQueryPerformanceFrequency_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // XELOGD( // "KeQueryPerformanceFrequency()"); @@ -317,8 +327,8 @@ SHIM_CALL KeQueryPerformanceFrequency_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL KeDelayExecutionThread_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeDelayExecutionThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t processor_mode = SHIM_GET_ARG_32(0); uint32_t alertable = SHIM_GET_ARG_32(1); uint32_t interval_ptr = SHIM_GET_ARG_32(2); @@ -334,14 +344,16 @@ SHIM_CALL KeDelayExecutionThread_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL NtYieldExecution_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtYieldExecution_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // XELOGD("NtYieldExecution()"); XThread* thread = XThread::GetCurrentThread(); X_STATUS result = thread->Delay(0, 0, 0); SHIM_SET_RETURN_32(0); } -SHIM_CALL KeQuerySystemTime_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeQuerySystemTime_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t time_ptr = SHIM_GET_ARG_32(0); XELOGD("KeQuerySystemTime(%.8X)", time_ptr); @@ -359,7 +371,7 @@ SHIM_CALL KeQuerySystemTime_shim(PPCContext* ppc_state, KernelState* state) { // hoping for the best. // http://msdn.microsoft.com/en-us/library/ms686801 -SHIM_CALL KeTlsAlloc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeTlsAlloc_shim(PPCContext* ppc_context, KernelState* kernel_state) { XELOGD("KeTlsAlloc()"); uint32_t tls_index; @@ -379,7 +391,7 @@ SHIM_CALL KeTlsAlloc_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/ms686804 -SHIM_CALL KeTlsFree_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeTlsFree_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t tls_index = SHIM_GET_ARG_32(0); XELOGD("KeTlsFree(%.8X)", tls_index); @@ -401,7 +413,8 @@ SHIM_CALL KeTlsFree_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/ms686812 -SHIM_CALL KeTlsGetValue_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeTlsGetValue_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t tls_index = SHIM_GET_ARG_32(0); // Logging disabled, as some games spam this. @@ -426,7 +439,8 @@ SHIM_CALL KeTlsGetValue_shim(PPCContext* ppc_state, KernelState* state) { } // http://msdn.microsoft.com/en-us/library/ms686818 -SHIM_CALL KeTlsSetValue_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeTlsSetValue_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t tls_index = SHIM_GET_ARG_32(0); uint32_t tls_value = SHIM_GET_ARG_32(1); @@ -444,7 +458,8 @@ SHIM_CALL KeTlsSetValue_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtCreateEvent_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtCreateEvent_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t obj_attributes_ptr = SHIM_GET_ARG_32(1); uint32_t event_type = SHIM_GET_ARG_32(2); @@ -455,9 +470,9 @@ SHIM_CALL NtCreateEvent_shim(PPCContext* ppc_state, KernelState* state) { // TODO(benvanik): check for name collision. May return existing object if // type matches. - AssertNoNameCollision(state, obj_attributes_ptr); + AssertNoNameCollision(kernel_state, obj_attributes_ptr); - XEvent* ev = new XEvent(state); + XEvent* ev = new XEvent(kernel_state); ev->Initialize(!event_type, !!initial_state); // obj_attributes may have a name inside of it, if != NULL. @@ -471,7 +486,7 @@ SHIM_CALL NtCreateEvent_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_STATUS_SUCCESS); } -SHIM_CALL KeSetEvent_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeSetEvent_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t event_ref = SHIM_GET_ARG_32(0); uint32_t increment = SHIM_GET_ARG_32(1); uint32_t wait = SHIM_GET_ARG_32(2); @@ -480,7 +495,7 @@ SHIM_CALL KeSetEvent_shim(PPCContext* ppc_state, KernelState* state) { void* event_ptr = SHIM_MEM_ADDR(event_ref); - auto ev = XObject::GetNativeObject(state, event_ptr); + auto ev = XObject::GetNativeObject(kernel_state, event_ptr); if (!ev) { SHIM_SET_RETURN_32(0); return; @@ -490,7 +505,7 @@ SHIM_CALL KeSetEvent_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtSetEvent_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtSetEvent_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t event_handle = SHIM_GET_ARG_32(0); uint32_t previous_state_ptr = SHIM_GET_ARG_32(1); @@ -498,7 +513,7 @@ SHIM_CALL NtSetEvent_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; - auto ev = state->object_table()->LookupObject(event_handle); + auto ev = kernel_state->object_table()->LookupObject(event_handle); if (ev) { int32_t was_signalled = ev->Set(0, false); if (previous_state_ptr) { @@ -511,7 +526,8 @@ SHIM_CALL NtSetEvent_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL KePulseEvent_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KePulseEvent_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t event_ref = SHIM_GET_ARG_32(0); uint32_t increment = SHIM_GET_ARG_32(1); uint32_t wait = SHIM_GET_ARG_32(2); @@ -521,7 +537,7 @@ SHIM_CALL KePulseEvent_shim(PPCContext* ppc_state, KernelState* state) { int32_t result = 0; void* event_ptr = SHIM_MEM_ADDR(event_ref); - auto ev = XObject::GetNativeObject(state, event_ptr); + auto ev = XObject::GetNativeObject(kernel_state, event_ptr); if (ev) { result = ev->Pulse(increment, !!wait); } @@ -529,7 +545,8 @@ SHIM_CALL KePulseEvent_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtPulseEvent_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtPulseEvent_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t event_handle = SHIM_GET_ARG_32(0); uint32_t previous_state_ptr = SHIM_GET_ARG_32(1); @@ -537,7 +554,7 @@ SHIM_CALL NtPulseEvent_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; - auto ev = state->object_table()->LookupObject(event_handle); + auto ev = kernel_state->object_table()->LookupObject(event_handle); if (ev) { int32_t was_signalled = ev->Pulse(0, false); if (previous_state_ptr) { @@ -550,13 +567,14 @@ SHIM_CALL NtPulseEvent_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL KeResetEvent_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeResetEvent_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t event_ref = SHIM_GET_ARG_32(0); XELOGD("KeResetEvent(%.8X)", event_ref); void* event_ptr = SHIM_MEM_ADDR(event_ref); - auto ev = XObject::GetNativeObject(state, event_ptr); + auto ev = XObject::GetNativeObject(kernel_state, event_ptr); if (!ev) { SHIM_SET_RETURN_32(0); return; @@ -566,14 +584,15 @@ SHIM_CALL KeResetEvent_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtClearEvent_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtClearEvent_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t event_handle = SHIM_GET_ARG_32(0); XELOGD("NtClearEvent(%.8X)", event_handle); X_STATUS result = X_STATUS_SUCCESS; - auto ev = state->object_table()->LookupObject(event_handle); + auto ev = kernel_state->object_table()->LookupObject(event_handle); if (ev) { ev->Reset(); } else { @@ -583,7 +602,8 @@ SHIM_CALL NtClearEvent_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtCreateSemaphore_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtCreateSemaphore_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t obj_attributes_ptr = SHIM_GET_ARG_32(1); int32_t count = SHIM_GET_ARG_32(2); @@ -595,10 +615,10 @@ SHIM_CALL NtCreateSemaphore_shim(PPCContext* ppc_state, KernelState* state) { // TODO(benvanik): check for name collision. May return existing object if // type matches. if (obj_attributes_ptr) { - AssertNoNameCollision(state, obj_attributes_ptr); + AssertNoNameCollision(kernel_state, obj_attributes_ptr); } - auto sem = object_ref(new XSemaphore(state)); + auto sem = object_ref(new XSemaphore(kernel_state)); sem->Initialize(count, limit); // obj_attributes may have a name inside of it, if != NULL. @@ -613,8 +633,8 @@ SHIM_CALL NtCreateSemaphore_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_STATUS_SUCCESS); } -SHIM_CALL KeInitializeSemaphore_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeInitializeSemaphore_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t semaphore_ref = SHIM_GET_ARG_32(0); int32_t count = SHIM_GET_ARG_32(1); int32_t limit = SHIM_GET_ARG_32(2); @@ -622,7 +642,7 @@ SHIM_CALL KeInitializeSemaphore_shim(PPCContext* ppc_state, XELOGD("KeInitializeSemaphore(%.8X, %d, %d)", semaphore_ref, count, limit); void* semaphore_ptr = SHIM_MEM_ADDR(semaphore_ref); - auto sem = XObject::GetNativeObject(state, semaphore_ptr, + auto sem = XObject::GetNativeObject(kernel_state, semaphore_ptr, 5 /* SemaphoreObject */); if (!sem) { return; @@ -631,7 +651,8 @@ SHIM_CALL KeInitializeSemaphore_shim(PPCContext* ppc_state, sem->Initialize(count, limit); } -SHIM_CALL KeReleaseSemaphore_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeReleaseSemaphore_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t semaphore_ref = SHIM_GET_ARG_32(0); int32_t increment = SHIM_GET_ARG_32(1); int32_t adjustment = SHIM_GET_ARG_32(2); @@ -641,7 +662,7 @@ SHIM_CALL KeReleaseSemaphore_shim(PPCContext* ppc_state, KernelState* state) { adjustment, wait); void* semaphore_ptr = SHIM_MEM_ADDR(semaphore_ref); - auto sem = XObject::GetNativeObject(state, semaphore_ptr); + auto sem = XObject::GetNativeObject(kernel_state, semaphore_ptr); if (!sem) { SHIM_SET_RETURN_32(0); return; @@ -654,7 +675,8 @@ SHIM_CALL KeReleaseSemaphore_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtReleaseSemaphore_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtReleaseSemaphore_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t sem_handle = SHIM_GET_ARG_32(0); int32_t release_count = SHIM_GET_ARG_32(1); int32_t previous_count_ptr = SHIM_GET_ARG_32(2); @@ -665,7 +687,7 @@ SHIM_CALL NtReleaseSemaphore_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; int32_t previous_count = 0; - auto sem = state->object_table()->LookupObject(sem_handle); + auto sem = kernel_state->object_table()->LookupObject(sem_handle); if (sem) { previous_count = sem->ReleaseSemaphore(release_count); } else { @@ -678,7 +700,8 @@ SHIM_CALL NtReleaseSemaphore_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtCreateMutant_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtCreateMutant_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t obj_attributes_ptr = SHIM_GET_ARG_32(1); uint32_t initial_owner = SHIM_GET_ARG_32(2); @@ -689,10 +712,10 @@ SHIM_CALL NtCreateMutant_shim(PPCContext* ppc_state, KernelState* state) { // TODO(benvanik): check for name collision. May return existing object if // type matches. if (obj_attributes_ptr) { - AssertNoNameCollision(state, obj_attributes_ptr); + AssertNoNameCollision(kernel_state, obj_attributes_ptr); } - XMutant* mutant = new XMutant(state); + XMutant* mutant = new XMutant(kernel_state); mutant->Initialize(initial_owner ? true : false); // obj_attributes may have a name inside of it, if != NULL. @@ -707,7 +730,8 @@ SHIM_CALL NtCreateMutant_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_STATUS_SUCCESS); } -SHIM_CALL NtReleaseMutant_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtReleaseMutant_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t mutant_handle = SHIM_GET_ARG_32(0); int32_t unknown = SHIM_GET_ARG_32(1); // This doesn't seem to be supported. @@ -725,7 +749,8 @@ SHIM_CALL NtReleaseMutant_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; - auto mutant = state->object_table()->LookupObject(mutant_handle); + auto mutant = + kernel_state->object_table()->LookupObject(mutant_handle); if (mutant) { result = mutant->ReleaseMutant(priority_increment, abandon, wait); } else { @@ -735,7 +760,8 @@ SHIM_CALL NtReleaseMutant_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtCreateTimer_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtCreateTimer_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t obj_attributes_ptr = SHIM_GET_ARG_32(1); uint32_t timer_type = SHIM_GET_ARG_32(2); @@ -748,10 +774,10 @@ SHIM_CALL NtCreateTimer_shim(PPCContext* ppc_state, KernelState* state) { // TODO(benvanik): check for name collision. May return existing object if // type matches. if (obj_attributes_ptr) { - AssertNoNameCollision(state, obj_attributes_ptr); + AssertNoNameCollision(kernel_state, obj_attributes_ptr); } - XTimer* timer = new XTimer(state); + XTimer* timer = new XTimer(kernel_state); timer->Initialize(timer_type); // obj_attributes may have a name inside of it, if != NULL. @@ -766,7 +792,8 @@ SHIM_CALL NtCreateTimer_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_STATUS_SUCCESS); } -SHIM_CALL NtSetTimerEx_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtSetTimerEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t timer_handle = SHIM_GET_ARG_32(0); uint32_t due_time_ptr = SHIM_GET_ARG_32(1); uint32_t routine = SHIM_GET_ARG_32(2); // PTIMERAPCROUTINE @@ -787,7 +814,7 @@ SHIM_CALL NtSetTimerEx_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; - auto timer = state->object_table()->LookupObject(timer_handle); + auto timer = kernel_state->object_table()->LookupObject(timer_handle); if (timer) { result = timer->SetTimer(due_time, period_ms, routine, routine_arg, resume ? true : false); @@ -798,7 +825,8 @@ SHIM_CALL NtSetTimerEx_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL NtCancelTimer_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtCancelTimer_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t timer_handle = SHIM_GET_ARG_32(0); uint32_t current_state_ptr = SHIM_GET_ARG_32(1); @@ -806,7 +834,7 @@ SHIM_CALL NtCancelTimer_shim(PPCContext* ppc_state, KernelState* state) { X_STATUS result = X_STATUS_SUCCESS; - auto timer = state->object_table()->LookupObject(timer_handle); + auto timer = kernel_state->object_table()->LookupObject(timer_handle); if (timer) { result = timer->Cancel(); } else { @@ -819,8 +847,8 @@ SHIM_CALL NtCancelTimer_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result); } -SHIM_CALL KeWaitForSingleObject_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeWaitForSingleObject_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t object_ptr = SHIM_GET_ARG_32(0); uint32_t wait_reason = SHIM_GET_ARG_32(1); uint32_t processor_mode = SHIM_GET_ARG_32(2); @@ -830,8 +858,8 @@ SHIM_CALL KeWaitForSingleObject_shim(PPCContext* ppc_state, XELOGD("KeWaitForSingleObject(%.8X, %.8X, %.8X, %.1X, %.8X)", object_ptr, wait_reason, processor_mode, alertable, timeout_ptr); - auto object = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(object_ptr)); + auto object = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(object_ptr)); if (!object) { // The only kind-of failure code. SHIM_SET_RETURN_32(X_STATUS_ABANDONED_WAIT_0); @@ -845,8 +873,8 @@ SHIM_CALL KeWaitForSingleObject_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL NtWaitForSingleObjectEx_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NtWaitForSingleObjectEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t object_handle = SHIM_GET_ARG_32(0); uint8_t wait_mode = SHIM_GET_ARG_8(1); uint32_t alertable = SHIM_GET_ARG_32(2); @@ -857,7 +885,8 @@ SHIM_CALL NtWaitForSingleObjectEx_shim(PPCContext* ppc_state, X_STATUS result = X_STATUS_SUCCESS; - auto object = state->object_table()->LookupObject(object_handle); + auto object = + kernel_state->object_table()->LookupObject(object_handle); if (object) { uint64_t timeout = timeout_ptr ? SHIM_MEM_64(timeout_ptr) : 0; result = @@ -869,8 +898,8 @@ SHIM_CALL NtWaitForSingleObjectEx_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL KeWaitForMultipleObjects_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeWaitForMultipleObjects_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t count = SHIM_GET_ARG_32(0); uint32_t objects_ptr = SHIM_GET_ARG_32(1); uint32_t wait_type = SHIM_GET_ARG_32(2); @@ -893,7 +922,8 @@ SHIM_CALL KeWaitForMultipleObjects_shim(PPCContext* ppc_state, for (uint32_t n = 0; n < count; n++) { uint32_t object_ptr_ptr = SHIM_MEM_32(objects_ptr + n * 4); void* object_ptr = SHIM_MEM_ADDR(object_ptr_ptr); - auto object_ref = XObject::GetNativeObject(state, object_ptr); + auto object_ref = + XObject::GetNativeObject(kernel_state, object_ptr); if (!object_ref) { SHIM_SET_RETURN_32(X_STATUS_INVALID_PARAMETER); return; @@ -910,8 +940,8 @@ SHIM_CALL KeWaitForMultipleObjects_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL NtWaitForMultipleObjectsEx_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NtWaitForMultipleObjectsEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t count = SHIM_GET_ARG_32(0); uint32_t handles_ptr = SHIM_GET_ARG_32(1); uint32_t wait_type = SHIM_GET_ARG_32(2); @@ -929,7 +959,8 @@ SHIM_CALL NtWaitForMultipleObjectsEx_shim(PPCContext* ppc_state, std::vector> objects(count); for (uint32_t n = 0; n < count; n++) { uint32_t object_handle = SHIM_MEM_32(handles_ptr + n * 4); - auto object = state->object_table()->LookupObject(object_handle); + auto object = + kernel_state->object_table()->LookupObject(object_handle); if (!object) { SHIM_SET_RETURN_32(X_STATUS_INVALID_PARAMETER); return; @@ -945,8 +976,8 @@ SHIM_CALL NtWaitForMultipleObjectsEx_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL NtSignalAndWaitForSingleObjectEx_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL NtSignalAndWaitForSingleObjectEx_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t signal_handle = SHIM_GET_ARG_32(0); uint32_t wait_handle = SHIM_GET_ARG_32(1); uint32_t alertable = SHIM_GET_ARG_32(2); @@ -959,8 +990,9 @@ SHIM_CALL NtSignalAndWaitForSingleObjectEx_shim(PPCContext* ppc_state, X_STATUS result = X_STATUS_SUCCESS; auto signal_object = - state->object_table()->LookupObject(signal_handle); - auto wait_object = state->object_table()->LookupObject(wait_handle); + kernel_state->object_table()->LookupObject(signal_handle); + auto wait_object = + kernel_state->object_table()->LookupObject(wait_handle); if (signal_object && wait_object) { uint64_t timeout = timeout_ptr ? SHIM_MEM_64(timeout_ptr) : 0; result = @@ -973,7 +1005,8 @@ SHIM_CALL NtSignalAndWaitForSingleObjectEx_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(result); } -SHIM_CALL KfAcquireSpinLock_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KfAcquireSpinLock_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t lock_ptr = SHIM_GET_ARG_32(0); // XELOGD( @@ -995,7 +1028,8 @@ SHIM_CALL KfAcquireSpinLock_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(old_irql); } -SHIM_CALL KfReleaseSpinLock_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KfReleaseSpinLock_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t lock_ptr = SHIM_GET_ARG_32(0); uint32_t old_irql = SHIM_GET_ARG_32(1); @@ -1013,8 +1047,8 @@ SHIM_CALL KfReleaseSpinLock_shim(PPCContext* ppc_state, KernelState* state) { xe::atomic_dec(lock); } -SHIM_CALL KeAcquireSpinLockAtRaisedIrql_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeAcquireSpinLockAtRaisedIrql_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t lock_ptr = SHIM_GET_ARG_32(0); // XELOGD( @@ -1029,8 +1063,8 @@ SHIM_CALL KeAcquireSpinLockAtRaisedIrql_shim(PPCContext* ppc_state, } } -SHIM_CALL KeReleaseSpinLockFromRaisedIrql_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeReleaseSpinLockFromRaisedIrql_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t lock_ptr = SHIM_GET_ARG_32(0); // XELOGD( @@ -1042,15 +1076,15 @@ SHIM_CALL KeReleaseSpinLockFromRaisedIrql_shim(PPCContext* ppc_state, xe::atomic_dec(lock); } -SHIM_CALL KeEnterCriticalRegion_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeEnterCriticalRegion_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // XELOGD( // "KeEnterCriticalRegion()"); XThread::EnterCriticalRegion(); } -SHIM_CALL KeLeaveCriticalRegion_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeLeaveCriticalRegion_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // XELOGD( // "KeLeaveCriticalRegion()"); XThread::LeaveCriticalRegion(); @@ -1058,25 +1092,26 @@ SHIM_CALL KeLeaveCriticalRegion_shim(PPCContext* ppc_state, XThread::GetCurrentThread()->CheckApcs(); } -SHIM_CALL KeRaiseIrqlToDpcLevel_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KeRaiseIrqlToDpcLevel_shim(PPCContext* ppc_context, + KernelState* kernel_state) { // XELOGD( // "KeRaiseIrqlToDpcLevel()"); - auto old_value = state->processor()->RaiseIrql(cpu::Irql::DPC); + auto old_value = kernel_state->processor()->RaiseIrql(cpu::Irql::DPC); SHIM_SET_RETURN_32(old_value); } -SHIM_CALL KfLowerIrql_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KfLowerIrql_shim(PPCContext* ppc_context, KernelState* kernel_state) { uint32_t old_value = SHIM_GET_ARG_32(0); // XELOGD( // "KfLowerIrql(%d)", // old_value); - state->processor()->LowerIrql(static_cast(old_value)); + kernel_state->processor()->LowerIrql(static_cast(old_value)); XThread::GetCurrentThread()->CheckApcs(); } -SHIM_CALL NtQueueApcThread_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL NtQueueApcThread_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t thread_handle = SHIM_GET_ARG_32(0); uint32_t apc_routine = SHIM_GET_ARG_32(1); uint32_t arg1 = SHIM_GET_ARG_32(2); @@ -1090,7 +1125,8 @@ SHIM_CALL NtQueueApcThread_shim(PPCContext* ppc_state, KernelState* state) { assert_always("not implemented"); } -SHIM_CALL KeInitializeApc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeInitializeApc_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t apc_ptr = SHIM_GET_ARG_32(0); uint32_t thread = SHIM_GET_ARG_32(1); uint32_t kernel_routine = SHIM_GET_ARG_32(2); @@ -1113,7 +1149,8 @@ SHIM_CALL KeInitializeApc_shim(PPCContext* ppc_state, KernelState* state) { apc->normal_context = normal_routine ? normal_context : 0; } -SHIM_CALL KeInsertQueueApc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeInsertQueueApc_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t apc_ptr = SHIM_GET_ARG_32(0); uint32_t arg1 = SHIM_GET_ARG_32(1); uint32_t arg2 = SHIM_GET_ARG_32(2); @@ -1124,8 +1161,8 @@ SHIM_CALL KeInsertQueueApc_shim(PPCContext* ppc_state, KernelState* state) { auto apc = SHIM_STRUCT(XAPC, apc_ptr); - auto thread = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(apc->thread_ptr)); + auto thread = XObject::GetNativeObject( + kernel_state, SHIM_MEM_ADDR(apc->thread_ptr)); if (!thread) { SHIM_SET_RETURN_32(0); return; @@ -1157,7 +1194,8 @@ SHIM_CALL KeInsertQueueApc_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(1); } -SHIM_CALL KeRemoveQueueApc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeRemoveQueueApc_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t apc_ptr = SHIM_GET_ARG_32(0); XELOGD("KeRemoveQueueApc(%.8X)", apc_ptr); @@ -1166,8 +1204,8 @@ SHIM_CALL KeRemoveQueueApc_shim(PPCContext* ppc_state, KernelState* state) { auto apc = SHIM_STRUCT(XAPC, apc_ptr); - auto thread = - XObject::GetNativeObject(state, SHIM_MEM_ADDR(apc->thread_ptr)); + auto thread = XObject::GetNativeObject( + kernel_state, SHIM_MEM_ADDR(apc->thread_ptr)); if (!thread) { SHIM_SET_RETURN_32(0); return; @@ -1193,8 +1231,8 @@ SHIM_CALL KeRemoveQueueApc_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(result ? 1 : 0); } -SHIM_CALL KiApcNormalRoutineNop_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL KiApcNormalRoutineNop_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk0 = SHIM_GET_ARG_32(0); // output? uint32_t unk1 = SHIM_GET_ARG_32(1); // 0x13 @@ -1203,7 +1241,8 @@ SHIM_CALL KiApcNormalRoutineNop_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL KeInitializeDpc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeInitializeDpc_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t dpc_ptr = SHIM_GET_ARG_32(0); uint32_t routine = SHIM_GET_ARG_32(1); uint32_t context = SHIM_GET_ARG_32(2); @@ -1223,7 +1262,8 @@ SHIM_CALL KeInitializeDpc_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_MEM_32(dpc_ptr + 24, 0); // arg2 } -SHIM_CALL KeInsertQueueDpc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeInsertQueueDpc_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t dpc_ptr = SHIM_GET_ARG_32(0); uint32_t arg1 = SHIM_GET_ARG_32(1); uint32_t arg2 = SHIM_GET_ARG_32(2); @@ -1235,7 +1275,7 @@ SHIM_CALL KeInsertQueueDpc_shim(PPCContext* ppc_state, KernelState* state) { uint32_t list_entry_ptr = dpc_ptr + 4; // Lock dispatcher. - auto dispatcher = state->dispatcher(); + auto dispatcher = kernel_state->dispatcher(); dispatcher->Lock(); auto dpc_list = dispatcher->dpc_list(); @@ -1258,7 +1298,8 @@ SHIM_CALL KeInsertQueueDpc_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(1); } -SHIM_CALL KeRemoveQueueDpc_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL KeRemoveQueueDpc_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t dpc_ptr = SHIM_GET_ARG_32(0); XELOGD("KeRemoveQueueDpc(%.8X)", dpc_ptr); @@ -1267,7 +1308,7 @@ SHIM_CALL KeRemoveQueueDpc_shim(PPCContext* ppc_state, KernelState* state) { uint32_t list_entry_ptr = dpc_ptr + 4; - auto dispatcher = state->dispatcher(); + auto dispatcher = kernel_state->dispatcher(); dispatcher->Lock(); auto dpc_list = dispatcher->dpc_list(); @@ -1284,15 +1325,15 @@ SHIM_CALL KeRemoveQueueDpc_shim(PPCContext* ppc_state, KernelState* state) { xe::mutex global_list_mutex_; // http://www.nirsoft.net/kernel_struct/vista/SLIST_HEADER.html -SHIM_CALL InterlockedPopEntrySList_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL InterlockedPopEntrySList_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t plist_ptr = SHIM_GET_ARG_32(0); XELOGD("InterlockedPopEntrySList(%.8X)", plist_ptr); std::lock_guard lock(global_list_mutex_); - uint8_t* p = state->memory()->TranslateVirtual(plist_ptr); + uint8_t* p = kernel_state->memory()->TranslateVirtual(plist_ptr); auto first = xe::load_and_swap(p); if (first == 0) { // List empty! @@ -1300,7 +1341,7 @@ SHIM_CALL InterlockedPopEntrySList_shim(PPCContext* ppc_state, return; } - uint8_t* p2 = state->memory()->TranslateVirtual(first); + uint8_t* p2 = kernel_state->memory()->TranslateVirtual(first); auto second = xe::load_and_swap(p2); // Now drop the first element @@ -1314,7 +1355,7 @@ SHIM_CALL InterlockedPopEntrySList_shim(PPCContext* ppc_state, } // namespace xe void xe::kernel::xboxkrnl::RegisterThreadingExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", ExCreateThread, state); SHIM_SET_MAPPING("xboxkrnl.exe", ExTerminateThread, state); SHIM_SET_MAPPING("xboxkrnl.exe", NtResumeThread, state); diff --git a/src/xenia/kernel/xboxkrnl_usbcam.cc b/src/xenia/kernel/xboxkrnl_usbcam.cc index eadc6faf6..976b58bb7 100644 --- a/src/xenia/kernel/xboxkrnl_usbcam.cc +++ b/src/xenia/kernel/xboxkrnl_usbcam.cc @@ -16,7 +16,8 @@ namespace xe { namespace kernel { -SHIM_CALL XUsbcamCreate_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XUsbcamCreate_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk1 = SHIM_GET_ARG_32(0); // E uint32_t unk2 = SHIM_GET_ARG_32(1); // 0x4B000 uint32_t unk3_ptr = SHIM_GET_ARG_32(3); @@ -27,7 +28,8 @@ SHIM_CALL XUsbcamCreate_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(X_ERROR_DEVICE_NOT_CONNECTED); } -SHIM_CALL XUsbcamGetState_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL XUsbcamGetState_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("XUsbcamGetState()"); // 0 = not connected. SHIM_SET_RETURN_32(0); @@ -37,7 +39,7 @@ SHIM_CALL XUsbcamGetState_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterUsbcamExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", XUsbcamCreate, state); SHIM_SET_MAPPING("xboxkrnl.exe", XUsbcamGetState, state); } diff --git a/src/xenia/kernel/xboxkrnl_video.cc b/src/xenia/kernel/xboxkrnl_video.cc index 333e8def1..61139079f 100644 --- a/src/xenia/kernel/xboxkrnl_video.cc +++ b/src/xenia/kernel/xboxkrnl_video.cc @@ -36,8 +36,8 @@ using xe::gpu::GraphicsSystem; // http://www.microsoft.com/en-za/download/details.aspx?id=5313 -- "Stripped // Down Direct3D: Xbox 360 Command Buffer and Resource Management" -SHIM_CALL VdGetCurrentDisplayGamma_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdGetCurrentDisplayGamma_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t arg0_ptr = SHIM_GET_ARG_32(0); uint32_t arg1_ptr = SHIM_GET_ARG_32(1); @@ -47,8 +47,8 @@ SHIM_CALL VdGetCurrentDisplayGamma_shim(PPCContext* ppc_state, xe::store_and_swap(SHIM_MEM_ADDR(arg1_ptr), 2.22222233f); } -SHIM_CALL VdGetCurrentDisplayInformation_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdGetCurrentDisplayInformation_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t ptr = SHIM_GET_ARG_32(0); XELOGD("VdGetCurrentDisplayInformation(%.8X)", ptr); @@ -80,7 +80,8 @@ SHIM_CALL VdGetCurrentDisplayInformation_shim(PPCContext* ppc_state, void xeVdQueryVideoMode(X_VIDEO_MODE* video_mode); -SHIM_CALL VdQueryVideoFlags_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdQueryVideoFlags_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("VdQueryVideoFlags()"); X_VIDEO_MODE mode; @@ -106,14 +107,15 @@ void xeVdQueryVideoMode(X_VIDEO_MODE* video_mode) { 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->video_standard = 1; // NTSC video_mode->unknown_0x8a = 0x4A; video_mode->unknown_0x01 = 0x01; video_mode->reserved[0] = video_mode->reserved[1] = video_mode->reserved[2] = 0; } -SHIM_CALL VdQueryVideoMode_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdQueryVideoMode_shim(PPCContext* ppc_context, + KernelState* kernel_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); @@ -122,7 +124,8 @@ SHIM_CALL VdQueryVideoMode_shim(PPCContext* ppc_state, KernelState* state) { xeVdQueryVideoMode(video_mode); } -SHIM_CALL VdSetDisplayMode_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdSetDisplayMode_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t mode = SHIM_GET_ARG_32(0); // 40000000 @@ -131,11 +134,11 @@ SHIM_CALL VdSetDisplayMode_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL VdSetDisplayModeOverride_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdSetDisplayModeOverride_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk0 = SHIM_GET_ARG_32(0); uint32_t unk1 = SHIM_GET_ARG_32(1); - double refresh_rate = ppc_state->f[1]; // 0, 50, 59.9, etc. + double refresh_rate = ppc_context->f[1]; // 0, 50, 59.9, etc. uint32_t unk3 = SHIM_GET_ARG_32(3); uint32_t unk4 = SHIM_GET_ARG_32(4); @@ -146,7 +149,8 @@ SHIM_CALL VdSetDisplayModeOverride_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL VdInitializeEngines_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdInitializeEngines_shim(PPCContext* ppc_context, + KernelState* kernel_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); @@ -164,7 +168,8 @@ SHIM_CALL VdInitializeEngines_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(1); } -SHIM_CALL VdShutdownEngines_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdShutdownEngines_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("VdShutdownEngines()"); // Ignored for now. @@ -172,7 +177,8 @@ SHIM_CALL VdShutdownEngines_shim(PPCContext* ppc_state, KernelState* state) { // re-initialize. } -SHIM_CALL VdGetGraphicsAsicID_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdGetGraphicsAsicID_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("VdGetGraphicsAsicID()"); // Games compare for < 0x10 and do VdInitializeEDRAM, else other @@ -180,8 +186,8 @@ SHIM_CALL VdGetGraphicsAsicID_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0x11); } -SHIM_CALL VdEnableDisableClockGating_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdEnableDisableClockGating_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t enabled = SHIM_GET_ARG_32(0); XELOGD("VdEnableDisableClockGating(%d)", enabled); @@ -191,14 +197,14 @@ SHIM_CALL VdEnableDisableClockGating_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL VdSetGraphicsInterruptCallback_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdSetGraphicsInterruptCallback_shim(PPCContext* ppc_context, + KernelState* kernel_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); - GraphicsSystem* gs = state->emulator()->graphics_system(); + GraphicsSystem* gs = kernel_state->emulator()->graphics_system(); if (!gs) { return; } @@ -210,14 +216,14 @@ SHIM_CALL VdSetGraphicsInterruptCallback_shim(PPCContext* ppc_state, gs->SetInterruptCallback(callback, user_data); } -SHIM_CALL VdInitializeRingBuffer_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdInitializeRingBuffer_shim(PPCContext* ppc_context, + KernelState* kernel_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); - GraphicsSystem* gs = state->emulator()->graphics_system(); + GraphicsSystem* gs = kernel_state->emulator()->graphics_system(); if (!gs) { return; } @@ -232,14 +238,14 @@ SHIM_CALL VdInitializeRingBuffer_shim(PPCContext* ppc_state, gs->InitializeRingBuffer(ptr, page_count); } -SHIM_CALL VdEnableRingBufferRPtrWriteBack_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdEnableRingBufferRPtrWriteBack_shim(PPCContext* ppc_context, + KernelState* kernel_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); - GraphicsSystem* gs = state->emulator()->graphics_system(); + GraphicsSystem* gs = kernel_state->emulator()->graphics_system(); if (!gs) { return; } @@ -270,8 +276,8 @@ SHIM_CALL VdEnableRingBufferRPtrWriteBack_shim(PPCContext* ppc_state, // TODO(benvanik): something? } -SHIM_CALL VdGetSystemCommandBuffer_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdGetSystemCommandBuffer_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t p0_ptr = SHIM_GET_ARG_32(0); uint32_t p1_ptr = SHIM_GET_ARG_32(1); @@ -283,7 +289,7 @@ SHIM_CALL VdGetSystemCommandBuffer_shim(PPCContext* ppc_state, } SHIM_CALL VdSetSystemCommandBufferGpuIdentifierAddress_shim( - PPCContext* ppc_state, KernelState* state) { + PPCContext* ppc_context, KernelState* kernel_state) { uint32_t unk = SHIM_GET_ARG_32(0); XELOGD("VdSetSystemCommandBufferGpuIdentifierAddress(%.8X)", unk); @@ -296,8 +302,8 @@ SHIM_CALL VdSetSystemCommandBufferGpuIdentifierAddress_shim( // r4 = 19 // no op? -SHIM_CALL VdInitializeScalerCommandBuffer_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdInitializeScalerCommandBuffer_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk0 = SHIM_GET_ARG_32(0); // 0? uint32_t unk1 = SHIM_GET_ARG_32(1); // 0x050002d0 size of ? uint32_t unk2 = SHIM_GET_ARG_32(2); // 0? @@ -307,7 +313,7 @@ SHIM_CALL VdInitializeScalerCommandBuffer_shim(PPCContext* ppc_state, uint32_t unk6 = SHIM_GET_ARG_32(6); // 0x2004909c <-- points to zeros? uint32_t unk7 = SHIM_GET_ARG_32(7); // 7? // arg8 is in stack! - uint32_t sp = (uint32_t)ppc_state->r[1]; + uint32_t sp = (uint32_t)ppc_context->r[1]; // Points to the first 80000000h where the memcpy sources from. uint32_t dest_ptr = SHIM_MEM_32(sp + 0x54); @@ -334,8 +340,8 @@ SHIM_CALL VdInitializeScalerCommandBuffer_shim(PPCContext* ppc_state, static uint32_t last_frontbuffer_width_ = 1280; static uint32_t last_frontbuffer_height_ = 720; -SHIM_CALL VdCallGraphicsNotificationRoutines_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdCallGraphicsNotificationRoutines_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk_1 = SHIM_GET_ARG_32(0); uint32_t args_ptr = SHIM_GET_ARG_32(1); @@ -359,8 +365,8 @@ SHIM_CALL VdCallGraphicsNotificationRoutines_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); } -SHIM_CALL VdIsHSIOTrainingSucceeded_shim(PPCContext* ppc_state, - KernelState* state) { +SHIM_CALL VdIsHSIOTrainingSucceeded_shim(PPCContext* ppc_context, + KernelState* kernel_state) { XELOGD("VdIsHSIOTrainingSucceeded()"); // Not really sure what this should be - code does weird stuff here: @@ -368,7 +374,8 @@ SHIM_CALL VdIsHSIOTrainingSucceeded_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(1); } -SHIM_CALL VdPersistDisplay_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdPersistDisplay_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk0 = SHIM_GET_ARG_32(0); uint32_t unk1_ptr = SHIM_GET_ARG_32(1); @@ -377,7 +384,7 @@ SHIM_CALL VdPersistDisplay_shim(PPCContext* ppc_state, KernelState* state) { // unk1_ptr needs to be populated with a pointer passed to // MmFreePhysicalMemory(1, *unk1_ptr). if (unk1_ptr) { - auto heap = state->memory()->LookupHeapByType(true, 16 * 1024); + auto heap = kernel_state->memory()->LookupHeapByType(true, 16 * 1024); uint32_t unk1_value; heap->Alloc(64, 32, kMemoryAllocationReserve | kMemoryAllocationCommit, kMemoryProtectNoAccess, false, &unk1_value); @@ -388,7 +395,8 @@ SHIM_CALL VdPersistDisplay_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(1); } -SHIM_CALL VdRetrainEDRAMWorker_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdRetrainEDRAMWorker_shim(PPCContext* ppc_context, + KernelState* kernel_state) { uint32_t unk0 = SHIM_GET_ARG_32(0); XELOGD("VdRetrainEDRAMWorker(%.8X)", unk0); @@ -396,7 +404,8 @@ SHIM_CALL VdRetrainEDRAMWorker_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL VdRetrainEDRAM_shim(PPCContext* ppc_state, KernelState* state) { +SHIM_CALL VdRetrainEDRAM_shim(PPCContext* ppc_context, + KernelState* kernel_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); @@ -410,12 +419,13 @@ SHIM_CALL VdRetrainEDRAM_shim(PPCContext* ppc_state, KernelState* state) { SHIM_SET_RETURN_32(0); } -SHIM_CALL VdSwap_shim(PPCContext* ppc_state, KernelState* state) { - uint32_t buffer_ptr = SHIM_GET_ARG_32(0); // ptr into primary ringbuffer - uint32_t fetch_ptr = SHIM_GET_ARG_32(1); // frontbuffer texture fetch +SHIM_CALL VdSwap_shim(PPCContext* ppc_context, KernelState* kernel_state) { + uint32_t buffer_ptr = SHIM_GET_ARG_32(0); // ptr into primary ringbuffer + uint32_t fetch_ptr = SHIM_GET_ARG_32(1); // frontbuffer texture fetch uint32_t unk2 = SHIM_GET_ARG_32(2); - uint32_t unk3 = SHIM_GET_ARG_32(3); // buffer from VdGetSystemCommandBuffer - uint32_t unk4 = SHIM_GET_ARG_32(4); // pointer from VdGetSystemCommandBuffer (0xBEEF0001) + uint32_t unk3 = SHIM_GET_ARG_32(3); // buffer from VdGetSystemCommandBuffer + uint32_t unk4 = + SHIM_GET_ARG_32(4); // pointer from VdGetSystemCommandBuffer (0xBEEF0001) uint32_t frontbuffer_ptr = SHIM_GET_ARG_32(5); // ptr to frontbuffer address uint32_t color_format_ptr = SHIM_GET_ARG_32(6); uint32_t color_space_ptr = SHIM_GET_ARG_32(7); @@ -423,7 +433,8 @@ SHIM_CALL VdSwap_shim(PPCContext* ppc_state, KernelState* state) { uint32_t frontbuffer = SHIM_MEM_32(frontbuffer_ptr); gpu::xenos::xe_gpu_texture_fetch_t fetch; - xe::copy_and_swap_32_unaligned((uint32_t*)&fetch, (uint32_t*)SHIM_MEM_ADDR(fetch_ptr), 6); + xe::copy_and_swap_32_unaligned((uint32_t*)&fetch, + (uint32_t*)SHIM_MEM_ADDR(fetch_ptr), 6); auto color_format = (gpu::xenos::ColorFormat)SHIM_MEM_32(color_format_ptr); auto color_space = SHIM_MEM_32(color_space_ptr); @@ -433,8 +444,9 @@ SHIM_CALL VdSwap_shim(PPCContext* ppc_state, KernelState* state) { assert_true(last_frontbuffer_width_ == 1 + fetch.size_2d.width); assert_true(last_frontbuffer_height_ == 1 + fetch.size_2d.height); - XELOGD("VdSwap(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X(%.8X), %.8X(%u), %.8X(%u))", buffer_ptr, - fetch_ptr, unk2, unk3, unk4, frontbuffer_ptr, frontbuffer, color_format_ptr, color_format, color_space_ptr, color_space); + XELOGD("VdSwap(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X(%.8X), %.8X(%u), %.8X(%u))", + buffer_ptr, fetch_ptr, unk2, unk3, unk4, frontbuffer_ptr, frontbuffer, + color_format_ptr, color_format, color_space_ptr, color_space); // The caller seems to reserve 64 words (256b) in the primary ringbuffer // for this method to do what it needs. We just zero them out and send a @@ -457,7 +469,7 @@ SHIM_CALL VdSwap_shim(PPCContext* ppc_state, KernelState* state) { } // namespace xe void xe::kernel::xboxkrnl::RegisterVideoExports( - xe::cpu::ExportResolver* export_resolver, KernelState* state) { + xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) { SHIM_SET_MAPPING("xboxkrnl.exe", VdGetCurrentDisplayGamma, state); SHIM_SET_MAPPING("xboxkrnl.exe", VdGetCurrentDisplayInformation, state); SHIM_SET_MAPPING("xboxkrnl.exe", VdQueryVideoFlags, state); @@ -482,7 +494,7 @@ void xe::kernel::xboxkrnl::RegisterVideoExports( SHIM_SET_MAPPING("xboxkrnl.exe", VdRetrainEDRAM, state); SHIM_SET_MAPPING("xboxkrnl.exe", VdSwap, state); - Memory* memory = state->memory(); + Memory* memory = kernel_state->memory(); // VdGlobalDevice (4b) // Pointer to a global D3D device. Games only seem to set this, so we don't