diff --git a/src/xenia/kernel/modules/xam/xam_info.cc b/src/xenia/kernel/modules/xam/xam_info.cc index 256cbc3a6..a65f55f7e 100644 --- a/src/xenia/kernel/modules/xam/xam_info.cc +++ b/src/xenia/kernel/modules/xam/xam_info.cc @@ -70,13 +70,7 @@ SHIM_CALL XGetLanguage_shim( void xe::kernel::xam::RegisterInfoExports( ExportResolver* export_resolver, XamState* state) { - #define SHIM_SET_MAPPING(ordinal, shim, impl) \ - export_resolver->SetFunctionMapping("xam.xex", ordinal, \ - state, (xe_kernel_export_shim_fn)shim, (xe_kernel_export_impl_fn)impl) - - SHIM_SET_MAPPING(0x000003CB, XGetAVPack_shim, NULL); - SHIM_SET_MAPPING(0x000003CC, XGetGameRegion_shim, NULL); - SHIM_SET_MAPPING(0x000003CD, XGetLanguage_shim, NULL); - - #undef SET_MAPPING + SHIM_SET_MAPPING("xam.xex", XGetAVPack, state); + SHIM_SET_MAPPING("xam.xex", XGetGameRegion, state); + SHIM_SET_MAPPING("xam.xex", XGetLanguage, state); } diff --git a/src/xenia/kernel/modules/xam/xam_info.h b/src/xenia/kernel/modules/xam/xam_info.h index bb331957d..e7db6dbd1 100644 --- a/src/xenia/kernel/modules/xam/xam_info.h +++ b/src/xenia/kernel/modules/xam/xam_info.h @@ -11,6 +11,7 @@ #define XENIA_KERNEL_MODULES_XAM_INFO_H_ #include +#include namespace xe { diff --git a/src/xenia/kernel/modules/xboxkrnl/module.cc b/src/xenia/kernel/modules/xboxkrnl/module.cc index d886b1a8e..aa2dfd7da 100644 --- a/src/xenia/kernel/modules/xboxkrnl/module.cc +++ b/src/xenia/kernel/modules/xboxkrnl/module.cc @@ -65,7 +65,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // Offset 0x18 is a 4b pointer to a handler function that seems to take two // arguments. If we wanted to see what would happen we could fake that. resolver->SetVariableMapping( - "xboxkrnl.exe", 0x00000059, + "xboxkrnl.exe", ordinals::KeDebugMonitorData, 0x80102100); XESETUINT32BE(mem + 0x80102100, 0); @@ -75,7 +75,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // Games seem to check if bit 26 (0x20) is set, which at least for xbox1 // was whether an HDD was present. Not sure what the other flags are. resolver->SetVariableMapping( - "xboxkrnl.exe", 0x00000156, + "xboxkrnl.exe", ordinals::XboxHardwareInfo, 0x80100FED); XESETUINT32BE(mem + 0x80100FED, 0x00000000); // flags XESETUINT8BE(mem + 0x80100FEE, 0x06); // cpu count @@ -91,7 +91,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // 0x80101058 <- pointer to xex header // 0x80101100 <- xex header base resolver->SetVariableMapping( - "xboxkrnl.exe", 0x00000193, + "xboxkrnl.exe", ordinals::XexExecutableModuleHandle, 0x80100FFC); XESETUINT32BE(mem + 0x80100FFC, 0x80101000); XESETUINT32BE(mem + 0x80101058, 0x80101100); @@ -101,7 +101,7 @@ XboxkrnlModule::XboxkrnlModule(Runtime* runtime) : // Perhaps it's how swap disc/etc data is sent? // Always set to "default.xex" (with quotes) for now. resolver->SetVariableMapping( - "xboxkrnl.exe", 0x000001AE, + "xboxkrnl.exe", ordinals::ExLoadedCommandLine, 0x80102000); char command_line[] = "\"default.xex\""; xe_copy_memory(mem + 0x80102000, 1024, diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.cc b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.cc index d1d0edcd9..c3f8b9874 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.cc +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.cc @@ -49,11 +49,5 @@ SHIM_CALL HalReturnToFirmware_shim( void xe::kernel::xboxkrnl::RegisterHalExports( ExportResolver* export_resolver, KernelState* state) { - #define SHIM_SET_MAPPING(ordinal, shim, impl) \ - export_resolver->SetFunctionMapping("xboxkrnl.exe", ordinal, \ - state, (xe_kernel_export_shim_fn)shim, (xe_kernel_export_impl_fn)impl) - - SHIM_SET_MAPPING(0x00000028, HalReturnToFirmware_shim, NULL); - - #undef SET_MAPPING + SHIM_SET_MAPPING("xboxkrnl.exe", HalReturnToFirmware, state); } diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.h b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.h index 509bed24a..c69896500 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.h +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_hal.h @@ -11,6 +11,7 @@ #define XENIA_KERNEL_MODULES_XBOXKRNL_HAL_H_ #include +#include namespace xe { diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc index 373de0a5e..9f81b15d6 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc @@ -151,12 +151,6 @@ SHIM_CALL NtFreeVirtualMemory_shim( void xe::kernel::xboxkrnl::RegisterMemoryExports( ExportResolver* export_resolver, KernelState* state) { - #define SHIM_SET_MAPPING(ordinal, shim, impl) \ - export_resolver->SetFunctionMapping("xboxkrnl.exe", ordinal, \ - state, (xe_kernel_export_shim_fn)shim, (xe_kernel_export_impl_fn)impl) - - SHIM_SET_MAPPING(0x000000CC, NtAllocateVirtualMemory_shim, NULL); - SHIM_SET_MAPPING(0x000000DC, NtFreeVirtualMemory_shim, NULL); - - #undef SET_MAPPING + SHIM_SET_MAPPING("xboxkrnl.exe", NtAllocateVirtualMemory, state); + SHIM_SET_MAPPING("xboxkrnl.exe", NtFreeVirtualMemory, state); } diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.h b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.h index e91fe9aad..8126f0b6c 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.h +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.h @@ -11,6 +11,7 @@ #define XENIA_KERNEL_MODULES_XBOXKRNL_MEMORY_H_ #include +#include namespace xe { diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.cc b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.cc index 8604ba17f..09191992a 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.cc +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.cc @@ -109,17 +109,11 @@ SHIM_CALL XexGetModuleHandle_shim( void xe::kernel::xboxkrnl::RegisterModuleExports( ExportResolver* export_resolver, KernelState* state) { - #define SHIM_SET_MAPPING(ordinal, shim, impl) \ - export_resolver->SetFunctionMapping("xboxkrnl.exe", ordinal, \ - state, (xe_kernel_export_shim_fn)shim, (xe_kernel_export_impl_fn)impl) + // SHIM_SET_MAPPING("xboxkrnl.exe", ExGetXConfigSetting, state); - //SHIM_SET_MAPPING(0x00000010, ExGetXConfigSetting_shim, NULL); + SHIM_SET_MAPPING("xboxkrnl.exe", XexCheckExecutablePrivilege, state); - SHIM_SET_MAPPING(0x00000194, XexCheckExecutablePrivilege_shim, NULL); - - SHIM_SET_MAPPING(0x00000195, XexGetModuleHandle_shim, NULL); - // SHIM_SET_MAPPING(0x00000196, XexGetModuleSection_shim, NULL); - // SHIM_SET_MAPPING(0x00000197, XexGetProcedureAddress_shim, NULL); - - #undef SET_MAPPING + SHIM_SET_MAPPING("xboxkrnl.exe", XexGetModuleHandle, state); + // SHIM_SET_MAPPING("xboxkrnl.exe", XexGetModuleSection, state); + // SHIM_SET_MAPPING("xboxkrnl.exe", XexGetProcedureAddress, state); } diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.h b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.h index 588512a91..a4294abfd 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.h +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_module.h @@ -11,6 +11,7 @@ #define XENIA_KERNEL_MODULES_XBOXKRNL_MODULE_IMPL_H_ #include +#include namespace xe { diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.cc b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.cc index 5a53931b6..6ea0d37f7 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.cc @@ -489,27 +489,21 @@ SHIM_CALL RtlLeaveCriticalSection_shim( void xe::kernel::xboxkrnl::RegisterRtlExports( ExportResolver* export_resolver, KernelState* state) { - #define SHIM_SET_MAPPING(ordinal, shim, impl) \ - export_resolver->SetFunctionMapping("xboxkrnl.exe", ordinal, \ - state, (xe_kernel_export_shim_fn)shim, (xe_kernel_export_impl_fn)impl) + SHIM_SET_MAPPING("xboxkrnl.exe", RtlCompareMemory, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlCompareMemoryUlong, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlFillMemoryUlong, state); - SHIM_SET_MAPPING(0x0000011A, RtlCompareMemory_shim, NULL); - SHIM_SET_MAPPING(0x0000011B, RtlCompareMemoryUlong_shim, NULL); - SHIM_SET_MAPPING(0x00000126, RtlFillMemoryUlong_shim, NULL); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlInitAnsiString, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlFreeAnsiString, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlInitUnicodeString, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlFreeUnicodeString, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlUnicodeStringToAnsiString, state); - SHIM_SET_MAPPING(0x0000012C, RtlInitAnsiString_shim, NULL); - SHIM_SET_MAPPING(0x00000127, RtlFreeAnsiString_shim, NULL); - SHIM_SET_MAPPING(0x0000012D, RtlInitUnicodeString_shim, NULL); - SHIM_SET_MAPPING(0x00000128, RtlFreeUnicodeString_shim, NULL); - SHIM_SET_MAPPING(0x00000142, RtlUnicodeStringToAnsiString_shim, NULL); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlImageXexHeaderField, state); - SHIM_SET_MAPPING(0x0000012B, RtlImageXexHeaderField_shim, NULL); - - SHIM_SET_MAPPING(0x0000012E, RtlInitializeCriticalSection_shim, NULL); - SHIM_SET_MAPPING(0x0000012F, RtlInitializeCriticalSectionAndSpinCount_shim, NULL); - SHIM_SET_MAPPING(0x00000125, RtlEnterCriticalSection_shim, NULL); - SHIM_SET_MAPPING(0x00000141, RtlTryEnterCriticalSection_shim, NULL); - SHIM_SET_MAPPING(0x00000130, RtlLeaveCriticalSection_shim, NULL); - - #undef SET_MAPPING + SHIM_SET_MAPPING("xboxkrnl.exe", RtlInitializeCriticalSection, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlInitializeCriticalSectionAndSpinCount, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlEnterCriticalSection, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlTryEnterCriticalSection, state); + SHIM_SET_MAPPING("xboxkrnl.exe", RtlLeaveCriticalSection, state); } diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.h b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.h index db8400865..dbda7b931 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.h +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_rtl.h @@ -11,6 +11,7 @@ #define XENIA_KERNEL_MODULES_XBOXKRNL_RTL_H_ #include +#include namespace xe { diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.cc b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.cc index 0e913a9f9..37a27348b 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.cc +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.cc @@ -242,18 +242,12 @@ SHIM_CALL KeTlsSetValue_shim( void xe::kernel::xboxkrnl::RegisterThreadingExports( ExportResolver* export_resolver, KernelState* state) { - #define SHIM_SET_MAPPING(ordinal, shim, impl) \ - export_resolver->SetFunctionMapping("xboxkrnl.exe", ordinal, \ - state, (xe_kernel_export_shim_fn)shim, (xe_kernel_export_impl_fn)impl) + SHIM_SET_MAPPING("xboxkrnl.exe", ExCreateThread, state); - SHIM_SET_MAPPING(0x0000000D, ExCreateThread_shim, NULL); + SHIM_SET_MAPPING("xboxkrnl.exe", KeGetCurrentProcessType, state); - SHIM_SET_MAPPING(0x00000066, KeGetCurrentProcessType_shim, NULL); - - SHIM_SET_MAPPING(0x00000152, KeTlsAlloc_shim, NULL); - SHIM_SET_MAPPING(0x00000153, KeTlsFree_shim, NULL); - SHIM_SET_MAPPING(0x00000154, KeTlsGetValue_shim, NULL); - SHIM_SET_MAPPING(0x00000155, KeTlsSetValue_shim, NULL); - - #undef SET_MAPPING + SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsAlloc, state); + SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsFree, state); + SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsGetValue, state); + SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsSetValue, state); } diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.h b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.h index 0dbf66eed..9a7b13d9b 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.h +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_threading.h @@ -11,6 +11,7 @@ #define XENIA_KERNEL_MODULES_XBOXKRNL_THREADING_H_ #include +#include namespace xe { diff --git a/src/xenia/kernel/shim_utils.h b/src/xenia/kernel/shim_utils.h index 29e80d9c0..e79c84516 100644 --- a/src/xenia/kernel/shim_utils.h +++ b/src/xenia/kernel/shim_utils.h @@ -23,6 +23,18 @@ namespace kernel { #define SHIM_CALL void _cdecl +#define SHIM_SET_MAPPING(library_name, export_name, shim_data) \ + export_resolver->SetFunctionMapping( \ + library_name, ordinals::##export_name, \ + shim_data, \ + (xe_kernel_export_shim_fn)export_name##_shim, \ + NULL); +#define SHIM_SET_MAPPING_WITH_IMPL(library_name, export_name, shim_data) \ + export_resolver->SetFunctionMapping( \ + library_name, ordinals::##export_name, \ + shim_data, \ + (xe_kernel_export_shim_fn)export_name##_shim, \ + (xe_kernel_export_impl_fn)export_name##_impl); #define SHIM_MEM_ADDR(a) (ppc_state->membase + a)