Core Components
The emulator is organized into four major subsystems that work together to replicate Xbox 360 functionality:CPU Subsystem
The CPU subsystem provides PowerPC emulation through a sophisticated JIT compiler:- Processor - Main entry point for code execution (
src/xenia/cpu/processor.h) - JIT Translator - Converts PowerPC instructions to HIR (High-level Intermediate Representation)
- Compiler - Optimizes HIR through multiple compilation passes
- x64 Backend - Generates native x64 machine code from HIR
GPU Subsystem
The GPU subsystem emulates the custom AMD Xenos graphics chip:- Graphics System - Top-level GPU management
- Command Processor - Processes GPU command buffers from the ringbuffer (
src/xenia/gpu/command_processor.cc) - Shader Translator - Converts Xenos shader microcode to SPIR-V/DXBC
- Vulkan/D3D12 Backend - Renders using modern graphics APIs
- EDRAM Emulation - Emulates on-die embedded DRAM for framebuffers
Memory Subsystem
The memory subsystem manages both virtual and physical memory spaces:- Memory Manager - Maps guest memory to host address space (
src/xenia/memory.h) - Heaps - Page-based allocation for virtual and physical regions
- MMU - Handles memory protection and address translation
Kernel Subsystem
The kernel subsystem implements Xbox 360 system software:- Kernel State - Tracks all kernel objects and system state (
src/xenia/kernel/kernel_state.h) - Export Resolver - Links game imports to kernel exports
- xboxkrnl.exe - NT kernel implementation with Xbox modifications
- xam.xex - Xbox Application Manager for system services
- Object Manager - Manages kernel objects (threads, events, mutexes, etc.)
Component Interaction
The emulator’s components are orchestrated by the mainEmulator class (src/xenia/emulator.h):
Execution Flow
-
Initialization (
Emulator::Setup)- Creates memory manager with virtual/physical address spaces
- Initializes CPU processor with JIT backend
- Sets up graphics system with chosen backend (Vulkan/D3D12)
- Creates kernel state and export resolver
- Mounts file systems for game content
-
Game Loading (
Emulator::LaunchPath)- Parses XEX (Xbox Executable) format
- Maps executable sections into memory
- Resolves kernel imports and exports
- Creates initial thread in kernel
-
Runtime Execution
- CPU executes translated code, calling kernel exports via syscalls
- Games submit command buffers to GPU via ringbuffer in system memory
- GPU command processor fetches and executes commands
- Memory is shared between CPU and GPU, similar to real hardware
-
System Calls
- JIT-compiled code encounters syscall instruction
- Transitions from guest context to host
- Kernel export function executes (native C++ code)
- Returns to guest code with results
Design Philosophy
High-Level Emulation (HLE)
Xenia uses HLE for the kernel, implementing Xbox 360 system calls as native functions rather than emulating the actual kernel code. This approach:- Provides better performance than low-level emulation
- Simplifies implementation of complex OS features
- Allows focusing optimization on game code translation
- Requires careful reverse engineering of system call behavior
JIT Compilation
The CPU uses Just-In-Time compilation rather than interpretation:- Translates PowerPC blocks to HIR on first execution
- Applies optimization passes to HIR
- Generates optimized x64 code
- Caches compiled code for subsequent execution
- Dramatically faster than interpretation
Accuracy vs Performance
Xenia balances accuracy and performance:- CPU timing is not cycle-accurate (games rarely depend on exact timing)
- GPU command processing is asynchronous like real hardware
- Memory protection and page tables are emulated
- Most system behavior is functionally accurate without perfect timing
Next Steps
Explore each subsystem in detail:- CPU Architecture - JIT translation, HIR, and code generation
- GPU Architecture - Command processing, shaders, and rendering
- Memory Architecture - Virtual memory, heaps, and memory mapping
- Kernel Architecture - System calls, modules, and kernel objects
