From 4f4b83b421b75de3840fa203230e836ab1d932ca Mon Sep 17 00:00:00 2001 From: gibbed Date: Wed, 4 Sep 2019 20:12:43 -0500 Subject: [PATCH] [Kernel] Move ExGetXConfigSetting to its own file. - [Kernel] Clean up xboxkrnl registration function declarations. - [Kernel] Move ExGetXConfigSetting to its own file. --- src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc | 3 +- src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc | 104 +------------- src/xenia/kernel/xboxkrnl/xboxkrnl_private.h | 56 +++----- src/xenia/kernel/xboxkrnl/xboxkrnl_xconfig.cc | 129 ++++++++++++++++++ 4 files changed, 154 insertions(+), 138 deletions(-) create mode 100644 src/xenia/kernel/xboxkrnl/xboxkrnl_xconfig.cc diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc index 008bb0fe3..21676c425 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_module.cc @@ -2,7 +2,7 @@ ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * + * Copyright 2019 Ben Vanik. All rights reserved. * * Released under the BSD license - see LICENSE in the root for more details. * ****************************************************************************** */ @@ -96,6 +96,7 @@ XboxkrnlModule::XboxkrnlModule(Emulator* emulator, KernelState* kernel_state) RegisterThreadingExports(export_resolver_, kernel_state_); RegisterUsbcamExports(export_resolver_, kernel_state_); RegisterVideoExports(export_resolver_, kernel_state_); + RegisterXConfigExports(export_resolver_, kernel_state_); // KeDebugMonitorData (?*) // Set to a valid value when a remote debugger is attached. diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc index 44483bcf3..81a44c553 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc @@ -2,7 +2,7 @@ ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * + * Copyright 2019 Ben Vanik. All rights reserved. * * Released under the BSD license - see LICENSE in the root for more details. * ****************************************************************************** */ @@ -15,112 +15,10 @@ #include "xenia/kernel/xboxkrnl/xboxkrnl_private.h" #include "xenia/xbox.h" -DEFINE_int32(game_language, 1, - "The language for the game to run in. 1=EN / 2=JP / 3=DE / 4=FR / " - "5=ES / 6=IT / 7=KR / 8=CN", - "General"); - namespace xe { namespace kernel { namespace xboxkrnl { -X_STATUS xeExGetXConfigSetting(uint16_t category, uint16_t setting, - void* buffer, uint16_t buffer_size, - uint16_t* required_size) { - uint16_t setting_size = 0; - alignas(uint32_t) uint8_t value[4]; - - // TODO(benvanik): have real structs here that just get copied from. - // https://free60project.github.io/wiki/XConfig.html - // https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/Generic/ExConfig.h - switch (category) { - case 0x0002: - // XCONFIG_SECURED_CATEGORY - switch (setting) { - case 0x0002: // XCONFIG_SECURED_AV_REGION - setting_size = 4; - xe::store_and_swap(value, 0x00001000); // USA/Canada - break; - default: - assert_unhandled_case(setting); - return X_STATUS_INVALID_PARAMETER_2; - } - break; - case 0x0003: - // XCONFIG_USER_CATEGORY - switch (setting) { - case 0x0001: // XCONFIG_USER_TIME_ZONE_BIAS - case 0x0002: // XCONFIG_USER_TIME_ZONE_STD_NAME - case 0x0003: // XCONFIG_USER_TIME_ZONE_DLT_NAME - case 0x0004: // XCONFIG_USER_TIME_ZONE_STD_DATE - case 0x0005: // XCONFIG_USER_TIME_ZONE_DLT_DATE - case 0x0006: // XCONFIG_USER_TIME_ZONE_STD_BIAS - case 0x0007: // XCONFIG_USER_TIME_ZONE_DLT_BIAS - setting_size = 4; - // TODO(benvanik): get this value. - xe::store_and_swap(value, 0); - break; - case 0x0009: // XCONFIG_USER_LANGUAGE - setting_size = 4; - xe::store_and_swap(value, cvars::game_language); // English - break; - case 0x000A: // XCONFIG_USER_VIDEO_FLAGS - setting_size = 4; - xe::store_and_swap(value, 0x00040000); - break; - case 0x000C: // XCONFIG_USER_RETAIL_FLAGS - setting_size = 4; - // TODO(benvanik): get this value. - xe::store_and_swap(value, 0); - break; - case 0x000E: // XCONFIG_USER_COUNTRY - // Halo: Reach sub_82804888 - min 0x5, max 0x6E. - setting_size = 1; - // TODO(benvanik): get this value. - value[0] = 5; - break; - default: - assert_unhandled_case(setting); - return X_STATUS_INVALID_PARAMETER_2; - } - break; - default: - assert_unhandled_case(category); - return X_STATUS_INVALID_PARAMETER_1; - } - - if (buffer) { - if (buffer_size < setting_size) { - return X_STATUS_BUFFER_TOO_SMALL; - } - std::memcpy(buffer, value, setting_size); - } else { - if (buffer_size) { - return X_STATUS_INVALID_PARAMETER_3; - } - } - if (required_size) { - *required_size = setting_size; - } - - return X_STATUS_SUCCESS; -} - -dword_result_t ExGetXConfigSetting(word_t category, word_t setting, - lpdword_t buffer_ptr, word_t buffer_size, - lpword_t required_size_ptr) { - uint16_t required_size = 0; - X_STATUS result = xeExGetXConfigSetting(category, setting, buffer_ptr, - buffer_size, &required_size); - - if (required_size_ptr) { - *required_size_ptr = required_size; - } - - return result; -} -DECLARE_XBOXKRNL_EXPORT1(ExGetXConfigSetting, kModules, kImplemented); - dword_result_t XexCheckExecutablePrivilege(dword_t privilege) { // BOOL // DWORD Privilege diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_private.h b/src/xenia/kernel/xboxkrnl/xboxkrnl_private.h index b198892e0..71fb12223 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_private.h +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_private.h @@ -21,40 +21,28 @@ namespace xboxkrnl { xe::cpu::Export* RegisterExport_xboxkrnl(xe::cpu::Export* export_entry); // Registration functions, one per file. -void RegisterAudioExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterAudioXmaExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterCryptExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterDebugExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterErrorExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterHalExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterHidExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterIoExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterMemoryExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterMiscExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterModuleExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterObExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterRtlExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterStringExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterThreadingExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterUsbcamExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); -void RegisterVideoExports(xe::cpu::ExportResolver* export_resolver, - KernelState* kernel_state); +#define DECLARE_REGISTER_EXPORTS(n) \ + void Register##n##Exports(xe::cpu::ExportResolver* export_resolver, \ + KernelState* kernel_state) +DECLARE_REGISTER_EXPORTS(Audio); +DECLARE_REGISTER_EXPORTS(AudioXma); +DECLARE_REGISTER_EXPORTS(Crypt); +DECLARE_REGISTER_EXPORTS(Debug); +DECLARE_REGISTER_EXPORTS(Error); +DECLARE_REGISTER_EXPORTS(Hal); +DECLARE_REGISTER_EXPORTS(Hid); +DECLARE_REGISTER_EXPORTS(Io); +DECLARE_REGISTER_EXPORTS(Memory); +DECLARE_REGISTER_EXPORTS(Misc); +DECLARE_REGISTER_EXPORTS(Module); +DECLARE_REGISTER_EXPORTS(Ob); +DECLARE_REGISTER_EXPORTS(Rtl); +DECLARE_REGISTER_EXPORTS(String); +DECLARE_REGISTER_EXPORTS(Threading); +DECLARE_REGISTER_EXPORTS(Usbcam); +DECLARE_REGISTER_EXPORTS(Video); +DECLARE_REGISTER_EXPORTS(XConfig); +#undef DECLARE_REGISTER_EXPORTS } // namespace xboxkrnl } // namespace kernel diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_xconfig.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_xconfig.cc new file mode 100644 index 000000000..9449df067 --- /dev/null +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_xconfig.cc @@ -0,0 +1,129 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2019 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "xenia/base/logging.h" +#include "xenia/cpu/processor.h" +#include "xenia/kernel/kernel_state.h" +#include "xenia/kernel/user_module.h" +#include "xenia/kernel/util/shim_utils.h" +#include "xenia/kernel/xboxkrnl/xboxkrnl_private.h" +#include "xenia/xbox.h" + +DEFINE_int32(game_language, 1, + "The language for the game to run in. 1=EN / 2=JP / 3=DE / 4=FR / " + "5=ES / 6=IT / 7=KR / 8=CN", + "General"); + +namespace xe { +namespace kernel { +namespace xboxkrnl { + +X_STATUS xeExGetXConfigSetting(uint16_t category, uint16_t setting, + void* buffer, uint16_t buffer_size, + uint16_t* required_size) { + uint16_t setting_size = 0; + alignas(uint32_t) uint8_t value[4]; + + // TODO(benvanik): have real structs here that just get copied from. + // https://free60project.github.io/wiki/XConfig.html + // https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/Generic/ExConfig.h + switch (category) { + case 0x0002: + // XCONFIG_SECURED_CATEGORY + switch (setting) { + case 0x0002: // XCONFIG_SECURED_AV_REGION + setting_size = 4; + xe::store_and_swap(value, 0x00001000); // USA/Canada + break; + default: + assert_unhandled_case(setting); + return X_STATUS_INVALID_PARAMETER_2; + } + break; + case 0x0003: + // XCONFIG_USER_CATEGORY + switch (setting) { + case 0x0001: // XCONFIG_USER_TIME_ZONE_BIAS + case 0x0002: // XCONFIG_USER_TIME_ZONE_STD_NAME + case 0x0003: // XCONFIG_USER_TIME_ZONE_DLT_NAME + case 0x0004: // XCONFIG_USER_TIME_ZONE_STD_DATE + case 0x0005: // XCONFIG_USER_TIME_ZONE_DLT_DATE + case 0x0006: // XCONFIG_USER_TIME_ZONE_STD_BIAS + case 0x0007: // XCONFIG_USER_TIME_ZONE_DLT_BIAS + setting_size = 4; + // TODO(benvanik): get this value. + xe::store_and_swap(value, 0); + break; + case 0x0009: // XCONFIG_USER_LANGUAGE + setting_size = 4; + xe::store_and_swap(value, cvars::game_language); // English + break; + case 0x000A: // XCONFIG_USER_VIDEO_FLAGS + setting_size = 4; + xe::store_and_swap(value, 0x00040000); + break; + case 0x000C: // XCONFIG_USER_RETAIL_FLAGS + setting_size = 4; + // TODO(benvanik): get this value. + xe::store_and_swap(value, 0); + break; + case 0x000E: // XCONFIG_USER_COUNTRY + // Halo: Reach sub_82804888 - min 0x5, max 0x6E. + setting_size = 1; + // TODO(benvanik): get this value. + value[0] = 5; + break; + default: + assert_unhandled_case(setting); + return X_STATUS_INVALID_PARAMETER_2; + } + break; + default: + assert_unhandled_case(category); + return X_STATUS_INVALID_PARAMETER_1; + } + + if (buffer) { + if (buffer_size < setting_size) { + return X_STATUS_BUFFER_TOO_SMALL; + } + std::memcpy(buffer, value, setting_size); + } else { + if (buffer_size) { + return X_STATUS_INVALID_PARAMETER_3; + } + } + if (required_size) { + *required_size = setting_size; + } + + return X_STATUS_SUCCESS; +} + +dword_result_t ExGetXConfigSetting(word_t category, word_t setting, + lpdword_t buffer_ptr, word_t buffer_size, + lpword_t required_size_ptr) { + uint16_t required_size = 0; + X_STATUS result = xeExGetXConfigSetting(category, setting, buffer_ptr, + buffer_size, &required_size); + + if (required_size_ptr) { + *required_size_ptr = required_size; + } + + return result; +} +DECLARE_XBOXKRNL_EXPORT1(ExGetXConfigSetting, kModules, kImplemented); + +void RegisterXConfigExports(xe::cpu::ExportResolver* export_resolver, + KernelState* kernel_state) {} + +} // namespace xboxkrnl +} // namespace kernel +} // namespace xe