This directory contains samples of statically recompiled Xbox 360 games that use Xenia's kernel as a runtime library.
The Xenia Static Recompilation Runtime allows running ahead-of-time (AOT) compiled Xbox 360 games on native hardware. Instead of JIT-compiling PowerPC code at runtime, games are pre-compiled to native x86-64 code by XenonRecomp, then linked against Xenia's kernel implementation.
┌─────────────────────────────────────────────────────────────┐
│ Recompiled Game │
│ (ppc_recomp.*.cpp - native x86-64 code from XenonRecomp) │
└─────────────────────────────────────────────────────────────┘
│
│ calls __imp__* functions
▼
┌─────────────────────────────────────────────────────────────┐
│ Kernel Exports │
│ (kernel_impl.cpp / kernel_exports.cc) │
│ __imp__ExCreateThread, __imp__NtCreateFile, etc. │
└─────────────────────────────────────────────────────────────┘
│
│ bridges to
▼
┌─────────────────────────────────────────────────────────────┐
│ Xenia Kernel │
│ (xboxkrnl.exe, xam.xex implementations) │
│ Threading, Sync, Memory, File I/O, Input, etc. │
└─────────────────────────────────────────────────────────────┘
Each recompiled game directory contains:
ppc_config.h- Memory layout constants (IMAGE_BASE, CODE_BASE, etc.)ppc_context.h- PPCContext structure and helper macrosppc_func_mapping.cpp- Function address to native pointer mappingsppc_recomp.*.cpp- Actual recompiled game codekernel_impl.cpp- Kernel API implementations/stubsmain.cpp- Entry point and initialization
The PPCContext structure holds the emulated PowerPC CPU state:
r0-r31- General purpose registersf0-f31- Floating point registersv0-v127- VMX128 vector registerslr,ctr- Link and count registerscr0-cr7- Condition registers
All recompiled functions use this signature:
void func(PPCContext& ctx, uint8_t* base);Where:
ctx- CPU register statebase- Guest memory base pointer
Arguments are passed in registers r3-r10:
r3- First argument / return valuer4-r10- Additional arguments
Guest memory is accessed via the base pointer:
// Load 32-bit value (big-endian)
uint32_t val = __builtin_bswap32(*(uint32_t*)(base + addr));
// Store 32-bit value (big-endian)
*(uint32_t*)(base + addr) = __builtin_bswap32(val);The PPC_LOOKUP_FUNC macro performs indirect function calls:
PPCFunc* func = PPC_LOOKUP_FUNC(base, target_addr);
if (func) func(ctx, base);This uses a perfect hash lookup table populated during initialization.
cd RAGE_GTA_IV
make
./gta4_recomp- Build Xenia as a static library:
cd /path/to/xenia
# Build xenia_runtime target- Link your game against Xenia:
clang++ -o game main.cpp ppc_*.cpp -lxenia_runtime -lpthread- Threading: ExCreateThread, NtResumeThread, NtSuspendThread
- Sync: NtCreateEvent, KeSetEvent, KeWaitForSingleObject
- Memory: NtAllocateVirtualMemory, MmAllocatePhysicalMemoryEx
- File I/O: NtCreateFile, NtReadFile, NtWriteFile, NtClose
- Time: KeQueryPerformanceFrequency, KeDelayExecutionThread
- Debug: DbgPrint
- Most XAM functions (UI, achievements, multiplayer)
- Networking (NetDll_*)
- Video (Vd*)
- Audio (XAudio*, XMA*)
- GPU rendering (handled externally)
- Audio output (handled externally)
- Add declaration to
kernel_exports.h:
KERNEL_EXPORT(NewFunction);- Implement in
kernel_exports.ccorkernel_exports_xenia.cc:
BRIDGE_FUNC(NewFunction) {
uint32_t arg1 = ARG_u32(3);
// Implementation...
RETURN(result);
}- If using Xenia's kernel, call the actual implementation:
void __imp__NewFunction(PPCContext& ctx, uint8_t* base) {
// Extract args
// Call xenia kernel function
// Set return value
}If you see "Missing function at 0xXXXXXXXX":
- Check if the address is in the recompiled code range
- Verify ppc_func_mapping.cpp contains the address
- May need to rerun XenonRecomp with that function
Run make stubs to see which kernel functions are called:
make stubsThis helps identify which stubs need real implementations.
This project is part of the Xenia Xbox 360 Emulator project. See the main Xenia LICENSE file for details.