commit 3c495e0af49360e83ee5ad9c97bd5d6b35726ed7
Author: mrfox <jens.se@icloud.com>
AuthorDate: Tue Nov 24 22:09:40 2026 +0100
Commit: mrfox <jens.se@icloud.com>
CommitDate: Tue Nov 24 22:09:40 2026 +0100
Add native XEX platform (no XDK): runtime with files, dirs and time
platform/xex builds normal Xbox 360 titles (default.xex, started from
Aurora/FSD) with GCC 16 + newlib + libstdc++ from the free60/libxenon
image, without the Microsoft XDK and without libxenon:
- sdk/: import thunks, title entry and kernel/XAM headers from
xenon-forge (MIT/Apache-2.0); xex-link from xenon-forge converts the
ELF (tools/build-xex-link.sh builds it as a static binary).
- runtime/: start-up (static constructors from .ctors, .eh_frame
registration so C++ exceptions work), link script, newlib system calls
and POSIX wrappers on the kernel Nt* API (open/read/write/lseek/stat/
mkdir/unlink, opendir/readdir), mount points usb0-2:/hdd:, time
(KeQuerySystemTime, time base), heap, guide notifications.
- tests/hello: C++ runtime check (verified on a console and in Xenia).
- tests/fs: files/dirs/time check (verified in Xenia, read-only there).
- `make xex` at the top level.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
Makefile | 8 +-
platform/xex/.gitignore | 3 +
platform/xex/Makefile | 67 ++
platform/xex/README.md | 62 ++
platform/xex/runtime/crt.c | 34 +
platform/xex/runtime/crt0.S | 5 +
platform/xex/runtime/extra_imports.S | 9 +
platform/xex/runtime/fs.c | 538 +++++++++++++
platform/xex/runtime/include/sys/dirent.h | 33 +
platform/xex/runtime/link.ld | 50 ++
platform/xex/runtime/posix.c | 38 +
platform/xex/runtime/sys.c | 144 ++++
platform/xex/runtime/xex_runtime.h | 34 +
platform/xex/sdk/LICENSE-APACHE | 190 +++++
platform/xex/sdk/LICENSE-MIT | 21 +
platform/xex/sdk/README | 3 +
platform/xex/sdk/crt/entry.inc | 32 +
platform/xex/sdk/include/xbox360/base.h | 189 +++++
platform/xex/sdk/include/xbox360/xam.h | 16 +
platform/xex/sdk/include/xbox360/xam/content.h | 220 ++++++
platform/xex/sdk/include/xbox360/xam/input.h | 155 ++++
platform/xex/sdk/include/xbox360/xam/net.h | 550 +++++++++++++
platform/xex/sdk/include/xbox360/xam/notify.h | 80 ++
platform/xex/sdk/include/xbox360/xam/system.h | 368 +++++++++
platform/xex/sdk/include/xbox360/xam/ui.h | 177 +++++
platform/xex/sdk/include/xbox360/xam/user.h | 264 +++++++
platform/xex/sdk/include/xbox360/xam/xamdef.h | 35 +
platform/xex/sdk/include/xbox360/xbox360.h | 9 +
platform/xex/sdk/include/xbox360/xboxkrnl.h | 22 +
platform/xex/sdk/include/xbox360/xboxkrnl/ex.h | 325 ++++++++
platform/xex/sdk/include/xbox360/xboxkrnl/hal.h | 351 +++++++++
platform/xex/sdk/include/xbox360/xboxkrnl/io.h | 815 +++++++++++++++++++
platform/xex/sdk/include/xbox360/xboxkrnl/ke.h | 518 +++++++++++++
platform/xex/sdk/include/xbox360/xboxkrnl/mm.h | 175 +++++
platform/xex/sdk/include/xbox360/xboxkrnl/nic.h | 53 ++
platform/xex/sdk/include/xbox360/xboxkrnl/ntdef.h | 95 +++
platform/xex/sdk/include/xbox360/xboxkrnl/ob.h | 149 ++++
platform/xex/sdk/include/xbox360/xboxkrnl/rtl.h | 284 +++++++
platform/xex/sdk/include/xbox360/xboxkrnl/usb.h | 42 +
platform/xex/sdk/include/xbox360/xboxkrnl/vd.h | 239 ++++++
platform/xex/sdk/include/xbox360/xboxkrnl/xaudio.h | 46 ++
platform/xex/sdk/include/xbox360/xboxkrnl/xe.h | 113 +++
platform/xex/sdk/include/xbox360/xboxkrnl/xex.h | 243 ++++++
platform/xex/sdk/include/xbox360/xboxkrnl/xma.h | 144 ++++
platform/xex/sdk/thunks/macros.inc | 152 ++++
platform/xex/sdk/thunks/ppc32.S | 862 +++++++++++++++++++++
platform/xex/tests/fs/main.cpp | 127 +++
platform/xex/tests/fs/xex.toml | 3 +
platform/xex/tests/hello/main.cpp | 39 +
platform/xex/tests/hello/xex.toml | 3 +
platform/xex/tools/build-xex-link.sh | 25 +
51 files changed, 8158 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index a4861e1..f447bf0 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ export APP_VERSION = v$(V_MAJOR).$(V_MINOR).$(V_PATCH).$(V_BUILD)
export SOURCES = ../../source ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng ../../libs/simpleini ../../libs/miniz
export INCLUDES = ../../include ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng ../../libs/simpleini ../../libs/miniz
-.PHONY: all 3ds switch wiiu vita sdl2 sdl windows clean clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl clean-windows xenon clean-xenon
+.PHONY: all 3ds switch wiiu vita sdl2 sdl windows clean clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl clean-windows xenon clean-xenon xex clean-xex
all: 3ds switch wiiu vita bittboy windows
@@ -75,6 +75,12 @@ wiiu:
xenon:
@$(MAKE) -C platform/xenon
+xex:
+ @$(MAKE) -C platform/xex
+
+clean-xex:
+ @$(MAKE) -C platform/xex clean
+
vita:
@$(MAKE) -C platform/vita
diff --git a/platform/xex/.gitignore b/platform/xex/.gitignore
new file mode 100644
index 0000000..301492e
--- /dev/null
+++ b/platform/xex/.gitignore
@@ -0,0 +1,3 @@
+build/
+tools/bin/
+tools/.xenon-forge-src/
diff --git a/platform/xex/Makefile b/platform/xex/Makefile
new file mode 100644
index 0000000..33354c9
--- /dev/null
+++ b/platform/xex/Makefile
@@ -0,0 +1,67 @@
+#---------------------------------------------------------------------------------
+# FAKE-08 for Xbox 360 as a native XEX (runs under the dashboard, started
+# from Aurora/FSD), built WITHOUT the Microsoft XDK:
+# GCC 16 + newlib + libstdc++ (free60/libxenon image, libxenon itself is
+# not used) -> ELF -> xex-link (from xenon-forge) -> default.xex
+#
+# Run inside the free60/libxenon docker image. xex-link must be built first
+# with tools/build-xex-link.sh (see README.md).
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(DEVKITXENON)),)
+$(error "Please set DEVKITXENON (run inside the free60/libxenon image)")
+endif
+
+XEX_LINK ?= $(CURDIR)/tools/bin/xex-link
+BUILD := build
+
+CC := xenon-gcc
+CXX := xenon-g++
+MACH := -m32 -mpowerpc64 -mhard-float -maltivec -fno-pic -G0 -msdata=none
+INCLUDES := -I$(CURDIR)/runtime/include -I$(CURDIR)/runtime -I$(CURDIR)/sdk/include
+CFLAGS := $(MACH) -O2 -g -Wall -Wno-attributes -ffunction-sections -fdata-sections $(INCLUDES)
+CXXFLAGS := $(CFLAGS) -std=gnu++17
+ASFLAGS := $(MACH) -Wa,-mppc64
+LDFLAGS := $(MACH) -nostartfiles -nostdlib -T $(CURDIR)/runtime/link.ld -Wl,--gc-sections
+LIBS := -L$(DEVKITXENON)/xenon/lib/32 -Wl,--start-group -lstdc++ -lm -lc -lgcc -Wl,--end-group
+
+RUNTIME_SRC := runtime/crt0.S runtime/crt.c runtime/sys.c runtime/fs.c runtime/posix.c \
+ runtime/extra_imports.S sdk/thunks/ppc32.S
+RUNTIME_OBJ := $(patsubst %,$(BUILD)/%.o,$(RUNTIME_SRC))
+
+TESTS := hello fs
+
+.PHONY: all tests runtime clean
+all: tests
+runtime: $(RUNTIME_OBJ)
+tests: $(foreach t,$(TESTS),$(BUILD)/tests/$(t)/default.xex)
+
+$(BUILD)/%.S.o: %.S
+ @mkdir -p $(dir $@)
+ @echo [$(notdir $<)]
+ @$(CC) $(ASFLAGS) -c $< -o $@
+$(BUILD)/%.c.o: %.c
+ @mkdir -p $(dir $@)
+ @echo [$(notdir $<)]
+ @$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
+$(BUILD)/%.cpp.o: %.cpp
+ @mkdir -p $(dir $@)
+ @echo [$(notdir $<)]
+ @$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
+
+# tests/<name>/*.cpp -> build/tests/<name>/default.xex
+.SECONDEXPANSION:
+$(BUILD)/tests/%/app.elf: $$(addprefix $(BUILD)/,$$(addsuffix .o,$$(wildcard tests/$$*/*.cpp))) $(RUNTIME_OBJ) runtime/link.ld
+ @mkdir -p $(dir $@)
+ @echo linking $@
+ @$(CXX) $(LDFLAGS) -Wl,-Map,$(@:.elf=.map) -o $@ $(filter %.o,$^) $(LIBS)
+
+$(BUILD)/tests/%/default.xex: $(BUILD)/tests/%/app.elf tests/%/xex.toml
+ @$(XEX_LINK) $< $@ --manifest tests/$*/xex.toml
+
+clean:
+ rm -r -f $(CURDIR)/$(BUILD)
+
+-include $(shell find $(BUILD) -name '*.d' 2>/dev/null)
+
+# keep the ELFs (symbols for addr2line)
+.SECONDARY:
diff --git a/platform/xex/README.md b/platform/xex/README.md
new file mode 100644
index 0000000..f78f689
--- /dev/null
+++ b/platform/xex/README.md
@@ -0,0 +1,62 @@
+# FAKE-08 as a native Xbox 360 XEX (no XDK)
+
+A second Xbox 360 target next to `platform/xenon` (bare-metal libxenon ELF
+started from XeLL). This one builds a normal `default.xex` that runs under
+the dashboard and is started from Aurora/FSD like any other app, on RGH/JTAG
+consoles. It does not use the Microsoft XDK.
+
+## How it is built
+
+| Piece | From |
+|---|---|
+| Compiler, newlib, libstdc++ | GCC 16 in the `free60/libxenon` docker image (libxenon itself is not linked) |
+| Import thunks, title entry, kernel/XAM headers | [xenon-forge](https://github.com/landaire/xenon-forge) `src/sdk` (MIT/Apache-2.0), copied to `sdk/` |
+| ELF -> XEX | `xex-link` from xenon-forge, built by `tools/build-xex-link.sh` |
+| C/C++ runtime | `runtime/`: start-up (static constructors, `.eh_frame` registration), newlib system calls on the kernel's `Nt*` API, dirent, time, heap |
+
+The code is compiled as 32-bit SysV PowerPC (`-m32 -mpowerpc64`), which is
+what titles run as (32-bit pointers in 64-bit registers). Calls into the
+kernel go through xenon-forge's thunks, which add the 0x50-byte home area
+the console ABI needs and convert 64-bit results; the title entry saves
+r14-r31 in full 64 bits.
+
+## Build
+
+From the repository root:
+
+ # once: build xex-link (static binary in platform/xex/tools/bin)
+ docker run --rm -v $PWD:/build_dir rust:latest \
+ /bin/sh -ex /build_dir/platform/xex/tools/build-xex-link.sh
+
+ # runtime + test programs
+ docker run --rm -v $PWD:/build_dir -w /build_dir free60/libxenon:latest \
+ bash -lc 'make xex'
+
+Output: `platform/xex/build/tests/<name>/default.xex`. The ELF next to it
+(`app.elf`) has the symbols for `xenon-addr2line`.
+
+The test programs also run in Xenia Canary
+(`xenia_canary --log_file=xenia.log --log_level=4 default.xex`); their
+DbgPrint output shows up in the log. Xenia mounts the XEX's folder
+read-only, so file writes only work on a console.
+
+## Runtime
+
+- **Paths:** `game:/...` (folder of the XEX), `usb0:`-`usb2:`
+ (`\Device\Mass0`-`2`), `hdd:` (`\Device\Harddisk0\Partition1`, Aurora's
+ `Hdd1:`). Relative paths are under `game:`. `/` and `\` both work.
+- **Files:** `open/read/write/lseek/close/stat/fstat/unlink/mkdir`,
+ `opendir/readdir/closedir` (stdio and iostreams work on top).
+- **Time:** `gettimeofday` (KeQuerySystemTime), `clock()/times()` (time
+ base), `xex_sleep_ms`, `usleep`.
+- **Heap:** a 96 MB `.bss` arena (`XEX_HEAP_SIZE`).
+- **Exit:** returning from `main`/`exit()` calls `XamLoaderTerminateTitle`,
+ which goes back to the dashboard.
+- `xex_runtime.h`: `xex_notify()` (guide notification), timing helpers.
+
+## Tests
+
+| Test | Checks |
+|---|---|
+| `tests/hello` | static constructors, C++ exceptions, `std::regex`, notifications, exit to dashboard |
+| `tests/fs` | time, `clock()`, directory listing, write/append/read/seek/stat/mkdir/remove on every device; writes `game:/fs-test-report.txt` |
diff --git a/platform/xex/runtime/crt.c b/platform/xex/runtime/crt.c
new file mode 100644
index 0000000..92ff060
--- /dev/null
+++ b/platform/xex/runtime/crt.c
@@ -0,0 +1,34 @@
+/*
+ * C/C++ runtime start for GCC-built Xbox 360 titles (newlib + libstdc++).
+ *
+ * The toolchain uses .ctors (not .init_array) and no crtbegin/crtend, so
+ * the link script provides the bounds and we run the constructors here.
+ * .eh_frame is registered with libgcc's unwinder so C++ exceptions work.
+ */
+#include <stdlib.h>
+
+typedef void (*ctor_fn)(void);
+extern ctor_fn __CTOR_LIST__[];
+extern ctor_fn __CTOR_END__[];
+extern char __eh_frame_start[];
+
+extern void __register_frame(void *);
+extern void xex_mount_devices(void);
+extern int main(int argc, char **argv);
+
+static char *argv_empty[] = { "game:\\default.xex", 0 };
+
+int __xex_crt_main(void)
+{
+ __register_frame(__eh_frame_start);
+ xex_mount_devices();
+
+ /* GCC runs .ctors from the end towards the start */
+ for (ctor_fn *p = __CTOR_END__; p > __CTOR_LIST__; ) {
+ (*--p)();
+ }
+
+ int ret = main(1, argv_empty);
+ exit(ret);
+ return ret;
+}
diff --git a/platform/xex/runtime/crt0.S b/platform/xex/runtime/crt0.S
new file mode 100644
index 0000000..0e9cb44
--- /dev/null
+++ b/platform/xex/runtime/crt0.S
@@ -0,0 +1,5 @@
+/* Title entry: saves r14-r31 in full 64 bits (console ABI) and calls the
+ * C runtime start in crt.c. See sdk/crt/entry.inc. */
+#include "../sdk/crt/entry.inc"
+
+ xbox360_entry _start, __xex_crt_main
diff --git a/platform/xex/runtime/extra_imports.S b/platform/xex/runtime/extra_imports.S
new file mode 100644
index 0000000..b2bf222
--- /dev/null
+++ b/platform/xex/runtime/extra_imports.S
@@ -0,0 +1,9 @@
+/* Imports that the xenon-forge headers do not declare yet.
+ * Record: type (1 = function) << 24 | library (0 xboxkrnl, 1 xam) << 16 | ordinal */
+#include "../sdk/thunks/macros.inc"
+
+/* VOID XNotifyQueueUI(DWORD Type, DWORD UserIndex, ULONGLONG Areas,
+ * PCWSTR Text, PVOID Context) - xam.xex ordinal 656.
+ * Areas is one 64-bit register in the console ABI: callers pass it as a
+ * 32-bit value in r5 (see xex_notify in runtime/xex.h), Text in r6. */
+xbox360_stub XNotifyQueueUI, 0x01010290
diff --git a/platform/xex/runtime/fs.c b/platform/xex/runtime/fs.c
new file mode 100644
index 0000000..33f78bb
--- /dev/null
+++ b/platform/xex/runtime/fs.c
@@ -0,0 +1,538 @@
+/*
+ * newlib file system calls and dirent for GCC-built Xbox 360 titles, on the
+ * kernel's Nt* file API.
+ *
+ * Paths: "dev:/dir/file" or "dev:\dir\file" (dev = game, usb0..usb2, hdd, or
+ * any other symbolic link), relative paths are relative to "game:". They
+ * become the object name "\??\dev:\dir\file". Kernel paths starting with
+ * '\' are passed through unchanged.
+ */
+#include <errno.h>
+#include <fcntl.h>
+#include <reent.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <unistd.h>
+
+#include <xbox360/xboxkrnl.h>
+
+#include "xex_runtime.h"
+
+#define STATUS_END_OF_FILE 0xC0000011
+#define STATUS_NO_MORE_FILES 0x80000006
+#define STATUS_NO_SUCH_FILE 0xC000000F
+#define STATUS_OBJECT_NAME_NOT_FOUND 0xC0000034
+#define STATUS_OBJECT_NAME_COLLISION 0xC0000035
+#define STATUS_OBJECT_PATH_NOT_FOUND 0xC000003A
+#define STATUS_ACCESS_DENIED 0xC0000022
+#define STATUS_FILE_IS_A_DIRECTORY 0xC00000BA
+#define STATUS_NOT_A_DIRECTORY 0xC0000103
+#define STATUS_NO_SUCH_DEVICE 0xC000000E
+#define STATUS_DISK_FULL 0xC000007F
+
+#ifndef FILE_LIST_DIRECTORY
+#define FILE_LIST_DIRECTORY 0x00000001
+#endif
+#ifndef FILE_READ_ATTRIBUTES
+#define FILE_READ_ATTRIBUTES 0x00000080
+#endif
+
+#define XEX_PATH_MAX 512
+#define MAX_FDS 64
+#define FIRST_FD 3
+
+typedef struct {
+ HANDLE handle;
+ long long pos;
+ int append;
+ int used;
+} xex_file;
+
+static xex_file files[MAX_FDS];
+
+/* ------------------------------------------------------------------------ */
+
+static int status_to_errno(NTSTATUS status)
+{
+ switch ((unsigned)status) {
+ case STATUS_NO_SUCH_FILE:
+ case STATUS_OBJECT_NAME_NOT_FOUND:
+ case STATUS_OBJECT_PATH_NOT_FOUND:
+ case STATUS_NO_SUCH_DEVICE:
+ return ENOENT;
+ case STATUS_OBJECT_NAME_COLLISION:
+ return EEXIST;
+ case STATUS_ACCESS_DENIED:
+ return EACCES;
+ case STATUS_FILE_IS_A_DIRECTORY:
+ return EISDIR;
+ case STATUS_NOT_A_DIRECTORY:
+ return ENOTDIR;
+ case STATUS_DISK_FULL:
+ return ENOSPC;
+ default:
+ return EIO;
+ }
+}
+
+static int nt_ok(NTSTATUS status)
+{
+ return (int)status >= 0;
+}
+
+/* "usb0:/a/b" -> "\??\usb0:\a\b"; relative -> "\??\game:\..." */
+int xex_kernel_path(const char *in, char *out, size_t size)
+{
+ size_t o = 0;
+ const char *p = in;
+
+ if (!in || !*in) {
+ return -1;
+ }
+
+ if (in[0] == '\\') { /* already a kernel path */
+ if (strlen(in) + 1 > size) return -1;
+ strcpy(out, in);
+ return 0;
+ }
+
+ const char *colon = strchr(in, ':');
+ const char *prefix = "\\??\\";
+ for (const char *s = prefix; *s; s++) out[o++] = *s;
+ if (!colon) {
+ const char *game = "game:\\";
+ for (const char *s = game; *s; s++) out[o++] = *s;
+ }
+
+ char last = 0;
+ for (; *p && o + 2 < size; p++) {
+ char c = (*p == '/') ? '\\' : *p;
+ if (c == '\\' && last == '\\') continue; /* collapse "//" */
+ out[o++] = c;
+ last = c;
+ }
+ if (*p) return -1;
+
+ /* "dev:" -> "dev:\" (root), strip other trailing separators */
+ if (o > 0 && out[o - 1] == ':') {
+ out[o++] = '\\';
+ } else {
+ while (o > 1 && out[o - 1] == '\\' && out[o - 2] != ':') o--;
+ }
+ out[o] = 0;
+ return 0;
+}
+
+static void init_attributes(OBJECT_ATTRIBUTES *attributes, STRING *name, char *path)
+{
+ size_t len = strlen(path);
+ name->Length = (USHORT)len;
+ name->MaximumLength = (USHORT)(len + 1);
+ name->Buffer = path;
+ attributes->RootDirectory = NULL;
+ attributes->ObjectName = name;
+ attributes->Attributes = OBJ_CASE_INSENSITIVE;
+}
+
+static NTSTATUS open_path(const char *path, HANDLE *handle, ACCESS_MASK access,
+ ULONG disposition, ULONG options)
+{
+ char kpath[XEX_PATH_MAX];
+ STRING name;
+ OBJECT_ATTRIBUTES attributes;
+ IO_STATUS_BLOCK iosb;
+
+ if (xex_kernel_path(path, kpath, sizeof(kpath)) != 0) {
+ return STATUS_OBJECT_PATH_NOT_FOUND;
+ }
+ init_attributes(&attributes, &name, kpath);
+ return NtCreateFile(handle, access | SYNCHRONIZE, &attributes, &iosb, NULL,
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ (CREATE_DISPOSITION)disposition,
+ options | FILE_SYNCHRONOUS_IO_NONALERT);
+}
+
+static xex_file *get_file(int fd)
+{
+ if (fd < FIRST_FD || fd >= MAX_FDS || !files[fd].used) {
+ return NULL;
+ }
+ return &files[fd];
+}
+
+static long long file_size(HANDLE handle)
+{
+ FILE_NETWORK_OPEN_INFORMATION info;
+ IO_STATUS_BLOCK iosb;
+ if (!nt_ok(NtQueryInformationFile(handle, &iosb, &info, sizeof(info), FileNetworkOpenInformation))) {
+ return -1;
+ }
+ return info.EndOfFile.QuadPart;
+}
+
+/* ------------------------------------------------------------------------ */
+/* newlib system calls */
+
+int _open_r(struct _reent *r, const char *path, int flags, int mode)
+{
+ (void)mode;
+ int fd;
+ for (fd = FIRST_FD; fd < MAX_FDS && files[fd].used; fd++) {}
+ if (fd == MAX_FDS) {
+ r->_errno = EMFILE;
+ return -1;
+ }
+
+ ACCESS_MASK access = FILE_READ_ATTRIBUTES;
+ switch (flags & O_ACCMODE) {
+ case O_RDONLY: access |= GENERIC_READ; break;
+ case O_WRONLY: access |= GENERIC_WRITE; break;
+ default: access |= GENERIC_READ | GENERIC_WRITE; break;
+ }
+
+ ULONG disposition;
+ if ((flags & O_CREAT) && (flags & O_EXCL)) disposition = FILE_CREATE;
+ else if ((flags & O_CREAT) && (flags & O_TRUNC)) disposition = FILE_OVERWRITE_IF;
+ else if (flags & O_CREAT) disposition = FILE_OPEN_IF;
+ else if (flags & O_TRUNC) disposition = FILE_OVERWRITE;
+ else disposition = FILE_OPEN;
+
+ HANDLE handle;
+ NTSTATUS status = open_path(path, &handle, access, disposition, FILE_NON_DIRECTORY_FILE);
+ if (!nt_ok(status)) {
+ r->_errno = status_to_errno(status);
+ return -1;
+ }
+
+ files[fd].handle = handle;
+ files[fd].pos = 0;
+ files[fd].append = (flags & O_APPEND) != 0;
+ files[fd].used = 1;
+ return fd;
+}
+
+int _close_r(struct _reent *r, int fd)
+{
+ xex_file *f = get_file(fd);
+ if (!f) {
+ if (fd >= 0 && fd < FIRST_FD) return 0;
+ r->_errno = EBADF;
+ return -1;
+ }
+ NtClose(f->handle);
+ f->used = 0;
+ return 0;
+}
+
+_ssize_t _read_r(struct _reent *r, int fd, void *buf, size_t len)
+{
+ xex_file *f = get_file(fd);
+ if (!f) {
+ r->_errno = EBADF;
+ return -1;
+ }
+ if (len == 0) return 0;
+
+ IO_STATUS_BLOCK iosb;
+ LARGE_INTEGER offset;
+ offset.QuadPart = f->pos;
+ NTSTATUS status = NtReadFile(f->handle, NULL, NULL, NULL, &iosb, buf, (ULONG)len, &offset);
+ if ((unsigned)status == STATUS_END_OF_FILE) {
+ return 0;
+ }
+ if (!nt_ok(status)) {
+ r->_errno = status_to_errno(status);
+ return -1;
+ }
+ f->pos += iosb.Information;
+ return (_ssize_t)iosb.Information;
+}
+
+_ssize_t _write_r(struct _reent *r, int fd, const void *buf, size_t len)
+{
+ if (fd == 1 || fd == 2) {
+ xex_debug_write(buf, len);
+ return (_ssize_t)len;
+ }
+
+ xex_file *f = get_file(fd);
+ if (!f) {
+ r->_errno = EBADF;
+ return -1;
+ }
+ if (len == 0) return 0;
+
+ if (f->append) {
+ long long size = file_size(f->handle);
+ if (size >= 0) f->pos = size;
+ }
+
+ IO_STATUS_BLOCK iosb;
+ LARGE_INTEGER offset;
+ offset.QuadPart = f->pos;
+ NTSTATUS status = NtWriteFile(f->handle, NULL, NULL, NULL, &iosb, (PVOID)buf, (ULONG)len, &offset);
+ if (!nt_ok(status)) {
+ r->_errno = status_to_errno(status);
+ return -1;
+ }
+ f->pos += iosb.Information;
+ return (_ssize_t)iosb.Information;
+}
+
+_off_t _lseek_r(struct _reent *r, int fd, _off_t off, int whence)
+{
+ xex_file *f = get_file(fd);
+ if (!f) {
+ r->_errno = EBADF;
+ return -1;
+ }
+ long long base;
+ switch (whence) {
+ case SEEK_SET: base = 0; break;
+ case SEEK_CUR: base = f->pos; break;
+ case SEEK_END:
+ base = file_size(f->handle);
+ if (base < 0) {
+ r->_errno = EIO;
+ return -1;
+ }
+ break;
+ default:
+ r->_errno = EINVAL;
+ return -1;
+ }
+ if (base + off < 0) {
+ r->_errno = EINVAL;
+ return -1;
+ }
+ f->pos = base + off;
+ return (_off_t)f->pos;
+}
+
+static void fill_stat(struct stat *st, ULONG attributes, long long size)
+{
+ memset(st, 0, sizeof(*st));
+ st->st_mode = (attributes & FILE_ATTRIBUTE_DIRECTORY) ? (S_IFDIR | 0777) : (S_IFREG | 0666);
+ st->st_size = (off_t)size;
+ st->st_nlink = 1;
+ st->st_blksize = 4096;
+}
+
+int _fstat_r(struct _reent *r, int fd, struct stat *st)
+{
+ if (fd >= 0 && fd < FIRST_FD) {
+ memset(st, 0, sizeof(*st));
+ st->st_mode = S_IFCHR;
+ return 0;
+ }
+ xex_file *f = get_file(fd);
+ if (!f) {
+ r->_errno = EBADF;
+ return -1;
+ }
+ FILE_NETWORK_OPEN_INFORMATION info;
+ IO_STATUS_BLOCK iosb;
+ NTSTATUS status = NtQueryInformationFile(f->handle, &iosb, &info, sizeof(info), FileNetworkOpenInformation);
+ if (!nt_ok(status)) {
+ r->_errno = status_to_errno(status);
+ return -1;
+ }
+ fill_stat(st, info.FileAttributes, info.EndOfFile.QuadPart);
+ return 0;
+}
+
+int _stat_r(struct _reent *r, const char *path, struct stat *st)
+{
+ char kpath[XEX_PATH_MAX];
+ STRING name;
+ OBJECT_ATTRIBUTES attributes;
+ FILE_NETWORK_OPEN_INFORMATION info;
+
+ if (xex_kernel_path(path, kpath, sizeof(kpath)) != 0) {
+ r->_errno = ENAMETOOLONG;
+ return -1;
+ }
+ init_attributes(&attributes, &name, kpath);
+ NTSTATUS status = NtQueryFullAttributesFile(&attributes, &info);
+ if (!nt_ok(status)) {
+ /* volume roots ("usb0:\") have no attributes: probe as a directory */
+ HANDLE handle;
+ status = open_path(path, &handle, FILE_LIST_DIRECTORY, FILE_OPEN, FILE_DIRECTORY_FILE);
+ if (!nt_ok(status)) {
+ r->_errno = status_to_errno(status);
+ return -1;
+ }
+ NtClose(handle);
+ fill_stat(st, FILE_ATTRIBUTE_DIRECTORY, 0);
+ return 0;
+ }
+ fill_stat(st, info.FileAttributes, info.EndOfFile.QuadPart);
+ return 0;
+}
+
+int _isatty_r(struct _reent *r, int fd)
+{
+ (void)r;
+ return fd >= 0 && fd < FIRST_FD;
+}
+
+int _unlink_r(struct _reent *r, const char *path)
+{
+ char kpath[XEX_PATH_MAX];
+ STRING name;
+ OBJECT_ATTRIBUTES attributes;
+ if (xex_kernel_path(path, kpath, sizeof(kpath)) != 0) {
+ r->_errno = ENAMETOOLONG;
+ return -1;
+ }
+ init_attributes(&attributes, &name, kpath);
+ NTSTATUS status = NtDeleteFile(&attributes);
+ if (!nt_ok(status)) {
+ r->_errno = status_to_errno(status);
+ return -1;
+ }
+ return 0;
+}
+
+int _link_r(struct _reent *r, const char *existing, const char *new_path)
+{
+ (void)existing; (void)new_path;
+ r->_errno = ENOSYS;
+ return -1;
+}
+
+int _rename_r(struct _reent *r, const char *old_path, const char *new_path)
+{
+ (void)old_path; (void)new_path;
+ r->_errno = ENOSYS;
+ return -1;
+}
+
+int mkdir(const char *path, mode_t mode)
+{
+ (void)mode;
+ HANDLE handle;
+ NTSTATUS status = open_path(path, &handle, FILE_LIST_DIRECTORY, FILE_CREATE, FILE_DIRECTORY_FILE);
+ if (!nt_ok(status)) {
+ errno = status_to_errno(status);
+ return -1;
+ }
+ NtClose(handle);
+ return 0;
+}
+
+int chdir(const char *path)
+{
+ (void)path;
+ errno = ENOSYS;
+ return -1;
+}
+
+/* ------------------------------------------------------------------------ */
+/* dirent */
+
+struct __xex_dir {
+ HANDLE handle;
+ struct dirent entry;
+ ULONG offset; /* offset of the next entry in buffer, or ~0 */
+ int restart;
+ unsigned char buffer[8192] __attribute__((aligned(8)));
+};
+
+DIR *opendir(const char *path)
+{
+ HANDLE handle;
+ NTSTATUS status = open_path(path, &handle, FILE_LIST_DIRECTORY, FILE_OPEN, FILE_DIRECTORY_FILE);
+ if (!nt_ok(status)) {
+ errno = status_to_errno(status);
+ return NULL;
+ }
+ DIR *dir = (DIR *)malloc(sizeof(DIR));
+ if (!dir) {
+ NtClose(handle);
+ errno = ENOMEM;
+ return NULL;
+ }
+ dir->handle = handle;
+ dir->offset = ~0u;
+ dir->restart = 1;
+ return dir;
+}
+
+struct dirent *readdir(DIR *dir)
+{
+ if (!dir) {
+ errno = EBADF;
+ return NULL;
+ }
+ if (dir->offset == ~0u) {
+ IO_STATUS_BLOCK iosb;
+ NTSTATUS status = NtQueryDirectoryFile(dir->handle, NULL, NULL, NULL, &iosb,
+ dir->buffer, sizeof(dir->buffer), NULL,
+ dir->restart ? TRUE : FALSE);
+ dir->restart = 0;
+ if (!nt_ok(status) || (unsigned)status == STATUS_NO_MORE_FILES) {
+ return NULL;
+ }
+ dir->offset = 0;
+ }
+
+ FILE_DIRECTORY_INFORMATION *info = (FILE_DIRECTORY_INFORMATION *)(dir->buffer + dir->offset);
+ ULONG len = info->FileNameLength;
+ if (len > sizeof(dir->entry.d_name) - 1) len = sizeof(dir->entry.d_name) - 1;
+ memcpy(dir->entry.d_name, info->FileName, len);
+ dir->entry.d_name[len] = 0;
+ dir->entry.d_type = (info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
+ dir->entry.d_ino = 0;
+
+ dir->offset = info->NextEntryOffset ? dir->offset + info->NextEntryOffset : ~0u;
+ return &dir->entry;
+}
+
+void rewinddir(DIR *dir)
+{
+ if (dir) {
+ dir->offset = ~0u;
+ dir->restart = 1;
+ }
+}
+
+int closedir(DIR *dir)
+{
+ if (!dir) {
+ errno = EBADF;
+ return -1;
+ }
+ NtClose(dir->handle);
+ free(dir);
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+/* Mount points */
+
+static void link_device(const char *link, const char *device)
+{
+ char link_buf[64], device_buf[96];
+ STRING link_name, device_name;
+ strcpy(link_buf, link);
+ strcpy(device_buf, device);
+ link_name.Length = (USHORT)strlen(link_buf);
+ link_name.MaximumLength = link_name.Length + 1;
+ link_name.Buffer = link_buf;
+ device_name.Length = (USHORT)strlen(device_buf);
+ device_name.MaximumLength = device_name.Length + 1;
+ device_name.Buffer = device_buf;
+ ObCreateSymbolicLink(&link_name, &device_name);
+}
+
+void xex_mount_devices(void)
+{
+ link_device("\\??\\usb0:", "\\Device\\Mass0");
+ link_device("\\??\\usb1:", "\\Device\\Mass1");
+ link_device("\\??\\usb2:", "\\Device\\Mass2");
+ link_device("\\??\\hdd:", "\\Device\\Harddisk0\\Partition1");
+}
diff --git a/platform/xex/runtime/include/sys/dirent.h b/platform/xex/runtime/include/sys/dirent.h
new file mode 100644
index 0000000..a3dc358
--- /dev/null
+++ b/platform/xex/runtime/include/sys/dirent.h
@@ -0,0 +1,33 @@
+/* Directory listing for GCC-built Xbox 360 titles (implemented in fs.c on
+ * NtQueryDirectoryFile). Replaces newlib's "not supported" sys/dirent.h. */
+#ifndef _XEX_SYS_DIRENT_H
+#define _XEX_SYS_DIRENT_H
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DT_UNKNOWN 0
+#define DT_DIR 4
+#define DT_REG 8
+
+struct dirent {
+ ino_t d_ino;
+ unsigned char d_type;
+ char d_name[256];
+};
+
+typedef struct __xex_dir DIR;
+
+DIR *opendir(const char *path);
+struct dirent *readdir(DIR *dir);
+int closedir(DIR *dir);
+void rewinddir(DIR *dir);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/xex/runtime/link.ld b/platform/xex/runtime/link.ld
new file mode 100644
index 0000000..2e267d0
--- /dev/null
+++ b/platform/xex/runtime/link.ld
@@ -0,0 +1,50 @@
+/* Link script for GCC-built titles: code at 0x82010000 (the first 64 KB
+ * page holds the XEX headers), each kind of section on its own 64 KB pages
+ * like xex-link's own script, plus what newlib/libstdc++ need:
+ * .ctors, .eh_frame (kept, zero terminated), .gcc_except_table, .got2. */
+ENTRY(_start)
+
+SECTIONS {
+ . = 0x82010000;
+ .text : {
+ *(.text._start)
+ *(.text .text.* .gnu.linkonce.t.*)
+ }
+ . = ALIGN(4);
+ .xthunks : { *(.xthunks .xthunks.*) }
+
+ . = ALIGN(0x10000);
+ .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) *(.sdata2 .sdata2.*) }
+ . = ALIGN(4);
+ .eh_frame : {
+ PROVIDE(__eh_frame_start = .);
+ KEEP(*(.eh_frame))
+ LONG(0)
+ }
+ .gcc_except_table : { *(.gcc_except_table .gcc_except_table.*) }
+
+ . = ALIGN(0x10000);
+ .ctors : {
+ __CTOR_LIST__ = .;
+ KEEP(*(SORT(.ctors.*)))
+ KEEP(*(.ctors))
+ __CTOR_END__ = .;
+ }
+ .dtors : { KEEP(*(.dtors .dtors.*)) }
+ .init_array : { KEEP(*(.init_array .init_array.*)) }
+ .got2 : { *(.got2) }
+ .got : { *(.got .got.plt) }
+ .data : { *(.data .data.* .gnu.linkonce.d.*) *(.sdata .sdata.*) }
+ .xvars : { *(.xvars .xvars.*) }
+
+ . = ALIGN(0x10000);
+ .bss : {
+ __bss_start = .;
+ *(.bss .bss.*) *(.sbss .sbss.*) *(COMMON)
+ __bss_end = .;
+ }
+ . = ALIGN(8);
+ _end = .;
+
+ /DISCARD/ : { *(.comment) *(.note .note.*) *(.eh_frame_hdr) }
+}
diff --git a/platform/xex/runtime/posix.c b/platform/xex/runtime/posix.c
new file mode 100644
index 0000000..1517dee
--- /dev/null
+++ b/platform/xex/runtime/posix.c
@@ -0,0 +1,38 @@
+/*
+ * POSIX entry points on top of the reentrant newlib system calls. This
+ * newlib build has no "supplied syscalls" layer (libxenon normally provides
+ * it), so libstdc++ and application code calling read(), stat() etc. need
+ * these wrappers.
+ */
+#include <reent.h>
+#include <stdarg.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+/* Normally from crtbegin.o: identifies this module for __cxa_atexit. */
+void *__dso_handle = &__dso_handle;
+
+int open(const char *path, int flags, ...)
+{
+ int mode = 0;
+ if (flags & O_CREAT) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ }
+ return _open_r(_REENT, path, flags, mode);
+}
+
+int close(int fd) { return _close_r(_REENT, fd); }
+ssize_t read(int fd, void *buf, size_t len) { return _read_r(_REENT, fd, buf, len); }
+ssize_t write(int fd, const void *buf, size_t len) { return _write_r(_REENT, fd, buf, len); }
+off_t lseek(int fd, off_t off, int whence) { return _lseek_r(_REENT, fd, off, whence); }
+int fstat(int fd, struct stat *st) { return _fstat_r(_REENT, fd, st); }
+int stat(const char *path, struct stat *st) { return _stat_r(_REENT, path, st); }
+int unlink(const char *path) { return _unlink_r(_REENT, path); }
+int isatty(int fd) { return _isatty_r(_REENT, fd); }
+int gettimeofday(struct timeval *tv, void *tz) { return _gettimeofday_r(_REENT, tv, tz); }
diff --git a/platform/xex/runtime/sys.c b/platform/xex/runtime/sys.c
new file mode 100644
index 0000000..26cbf3a
--- /dev/null
+++ b/platform/xex/runtime/sys.c
@@ -0,0 +1,144 @@
+/*
+ * newlib system calls that are not about files: heap, debug output,
+ * time, process. Files and directories are in fs.c.
+ */
+#include <errno.h>
+#include <reent.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <time.h>
+
+#include <xbox360/xboxkrnl.h>
+/* xam.h is not included: its socket types clash with newlib. */
+extern void XamLoaderTerminateTitle(void) __attribute__((noreturn));
+
+#include "xex_runtime.h"
+
+/* VOID XNotifyQueueUI(DWORD Type, DWORD UserIndex, ULONGLONG Areas,
+ * PCWSTR Text, PVOID Context): Areas is one register in the console ABI,
+ * so it is passed as a 32-bit value (see extra_imports.S). */
+extern void XNotifyQueueUI(uint32_t type, uint32_t user, uint32_t areas,
+ const uint16_t *text, void *context);
+
+/* ------------------------------------------------------------------------ */
+/* Heap: a .bss arena (the loader commits it with the image). */
+
+#ifndef XEX_HEAP_SIZE
+#define XEX_HEAP_SIZE (96 * 1024 * 1024)
+#endif
+static char heap[XEX_HEAP_SIZE] __attribute__((aligned(64)));
+static size_t heap_used;
+
+void *_sbrk_r(struct _reent *r, ptrdiff_t incr)
+{
+ if (incr < 0 || heap_used + (size_t)incr > XEX_HEAP_SIZE) {
+ r->_errno = ENOMEM;
+ return (void *)-1;
+ }
+ void *p = heap + heap_used;
+ heap_used += (size_t)incr;
+ return p;
+}
+
+/* ------------------------------------------------------------------------ */
+/* Debug output and notifications */
+
+void xex_debug_write(const void *buf, size_t len)
+{
+ char tmp[257];
+ size_t done = 0;
+ while (done < len) {
+ size_t n = len - done > 256 ? 256 : len - done;
+ for (size_t i = 0; i < n; i++) tmp[i] = ((const char *)buf)[done + i];
+ tmp[n] = 0;
+ DbgPrint("%s", tmp);
+ done += n;
+ }
+}
+
+void xex_notify(const char *text)
+{
+ uint16_t wide[128];
+ size_t n = 0;
+ for (; text[n] && n < 127; n++) wide[n] = (uint8_t)text[n];
+ wide[n] = 0;
+ XNotifyQueueUI(14 /* XNOTIFYUI_TYPE_PREFERRED_REVIEW */, 0, 2 /* high priority */, wide, NULL);
+}
+
+/* ------------------------------------------------------------------------ */
+/* Time */
+
+uint64_t xex_timebase(void)
+{
+ uint64_t tb;
+ __asm__ volatile("mftb %0" : "=r"(tb)); /* 64-bit register */
+ return tb;
+}
+
+uint64_t xex_timebase_freq(void)
+{
+ static uint64_t freq;
+ if (!freq) freq = KeQueryPerformanceFrequency();
+ return freq ? freq : 49875000ull;
+}
+
+void xex_sleep_ms(unsigned ms)
+{
+ LARGE_INTEGER interval;
+ interval.QuadPart = -(LONGLONG)ms * 10000; /* relative, 100 ns units */
+ KeDelayExecutionThread(1 /* UserMode */, FALSE, &interval);
+}
+
+int _gettimeofday_r(struct _reent *r, struct timeval *tv, void *tz)
+{
+ (void)r; (void)tz;
+ LARGE_INTEGER now;
+ KeQuerySystemTime(&now); /* 100 ns since 1601-01-01 */
+ long long us = (now.QuadPart - 116444736000000000LL) / 10;
+ tv->tv_sec = (time_t)(us / 1000000);
+ tv->tv_usec = (suseconds_t)(us % 1000000);
+ return 0;
+}
+
+clock_t _times_r(struct _reent *r, struct tms *buf)
+{
+ (void)r;
+ clock_t t = (clock_t)(xex_timebase() / (xex_timebase_freq() / CLOCKS_PER_SEC));
+ if (buf) {
+ buf->tms_utime = t;
+ buf->tms_stime = 0;
+ buf->tms_cutime = 0;
+ buf->tms_cstime = 0;
+ }
+ return t;
+}
+
+int usleep(useconds_t us)
+{
+ xex_sleep_ms((unsigned)((us + 999) / 1000));
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+/* Process */
+
+int _kill_r(struct _reent *r, int pid, int sig)
+{
+ (void)pid; (void)sig;
+ r->_errno = EINVAL;
+ return -1;
+}
+
+int _getpid_r(struct _reent *r)
+{
+ (void)r;
+ return 1;
+}
+
+void _exit(int status)
+{
+ (void)status;
+ XamLoaderTerminateTitle();
+}
diff --git a/platform/xex/runtime/xex_runtime.h b/platform/xex/runtime/xex_runtime.h
new file mode 100644
index 0000000..71eea14
--- /dev/null
+++ b/platform/xex/runtime/xex_runtime.h
@@ -0,0 +1,34 @@
+/* Helpers of the GCC Xbox 360 title runtime (runtime/ sources). */
+#ifndef XEX_RUNTIME_H
+#define XEX_RUNTIME_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* DbgPrint without format interpretation. */
+void xex_debug_write(const void *buf, size_t len);
+
+/* Creates usb0:..usb2: (\Device\Mass0..2) and hdd: (Partition1). */
+void xex_mount_devices(void);
+
+/* "usb0:/a/b" -> "\??\usb0:\a\b" (relative paths are under game:). */
+int xex_kernel_path(const char *path, char *out, size_t size);
+
+/* Xbox guide notification with an ASCII text. */
+void xex_notify(const char *text);
+
+void xex_sleep_ms(unsigned ms);
+
+/* Time base (mftb) ticks and frequency (49.875 MHz on retail consoles). */
+uint64_t xex_timebase(void);
+uint64_t xex_timebase_freq(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/platform/xex/sdk/LICENSE-APACHE b/platform/xex/sdk/LICENSE-APACHE
new file mode 100644
index 0000000..8007ffd
--- /dev/null
+++ b/platform/xex/sdk/LICENSE-APACHE
@@ -0,0 +1,190 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to the Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by the Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding any notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+Copyright 2026 Lander Brandt
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/platform/xex/sdk/LICENSE-MIT b/platform/xex/sdk/LICENSE-MIT
new file mode 100644
index 0000000..72e631e
--- /dev/null
+++ b/platform/xex/sdk/LICENSE-MIT
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 Lander Brandt
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/platform/xex/sdk/README b/platform/xex/sdk/README
new file mode 100644
index 0000000..81add22
--- /dev/null
+++ b/platform/xex/sdk/README
@@ -0,0 +1,3 @@
+Files in this directory come from xenon-forge
+(https://github.com/landaire/xenon-forge, commit 2fcc78c),
+dual licensed MIT / Apache-2.0 (see LICENSE-MIT, LICENSE-APACHE).
diff --git a/platform/xex/sdk/crt/entry.inc b/platform/xex/sdk/crt/entry.inc
new file mode 100644
index 0000000..ec31921
--- /dev/null
+++ b/platform/xex/sdk/crt/entry.inc
@@ -0,0 +1,32 @@
+/*
+ * Entries of C and C++ modules.
+ *
+ * The loader calls the entry of a module with the console calling
+ * convention, which expects r14-r31 back in full 64 bits. Code of the
+ * powerpc (SysV) code generation saves only their low words. The entry
+ * saves them in full, reserves the home area that console callees store
+ * their arguments in, and calls `target` with r3-r10 unchanged.
+ */
+
+.macro xbox360_entry name, target
+ .section .text.\name, "ax", @progbits
+ .globl \name
+ .type \name, @function
+ .balign 4
+\name:
+ stwu 1, -0xe0(1)
+ mflr 0
+ stw 0, 0x8(1)
+ .irp reg, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
+ std \reg, 0x50 + 8 * (\reg - 14)(1)
+ .endr
+ bl \target
+ .irp reg, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
+ ld \reg, 0x50 + 8 * (\reg - 14)(1)
+ .endr
+ lwz 0, 0x8(1)
+ mtlr 0
+ addi 1, 1, 0xe0
+ blr
+ .size \name, .-\name
+.endm
diff --git a/platform/xex/sdk/include/xbox360/base.h b/platform/xex/sdk/include/xbox360/base.h
new file mode 100644
index 0000000..8d38c8a
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/base.h
@@ -0,0 +1,189 @@
+/*
+ * Base types and macros of the Xbox 360 headers.
+ *
+ * Titles use 32-bit pointers, int and long on 64-bit registers. Clang's
+ * powerpc-unknown-none-eabi and powerpc64-unknown-xbox360-ilp32 targets both give
+ * this data model. The headers include no system header.
+ *
+ * Every import is declared with XBOX360_IMPORT(library, ordinal). The
+ * annotation names the library and export ordinal. xbox360-bindgen reads it
+ * to generate the import thunks that C and Rust code link with. A module
+ * exports a function with XBOX360_EXPORT(ordinal, function).
+ */
+
+#ifndef XBOX360_BASE_H
+#define XBOX360_BASE_H
+
+#ifdef __cplusplus
+#define XBOX360_EXTERN_C_START extern "C" {
+#define XBOX360_EXTERN_C_END }
+#else
+#define XBOX360_EXTERN_C_START
+#define XBOX360_EXTERN_C_END
+#endif
+
+/*
+ * An import of `library` (xboxkrnl, xam or xbdm) by `ordinal`. The thunk
+ * library defines a function import under its own name. A data import is
+ * declared as its slot, `__imp_<name>`, which holds the address of the
+ * export after the loader resolves it.
+ */
+#define XBOX360_IMPORT(library, ordinal) \
+ __attribute__((annotate("xbox360_import," #library "," #ordinal)))
+
+#define XBOXKRNL_IMPORT(ordinal) XBOX360_IMPORT(xboxkrnl, ordinal)
+#define XAM_IMPORT(ordinal) XBOX360_IMPORT(xam, ordinal)
+#define XBDM_IMPORT(ordinal) XBOX360_IMPORT(xbdm, ordinal)
+
+#define DECLSPEC_NORETURN __attribute__((noreturn))
+#define DECLSPEC_ALIGN(Alignment) __attribute__((aligned(Alignment)))
+#define C_ASSERT(Expression) _Static_assert(Expression, #Expression)
+
+XBOX360_EXTERN_C_START
+
+typedef void VOID, *PVOID;
+typedef const void *PCVOID;
+
+typedef char CHAR, *PCHAR, *PSTR;
+typedef const char *PCSTR, *PCSZ;
+typedef unsigned char UCHAR, *PUCHAR;
+typedef unsigned char BYTE, *PBYTE;
+typedef const unsigned char *PCBYTE;
+
+typedef short SHORT, *PSHORT;
+typedef unsigned short USHORT, *PUSHORT;
+typedef unsigned short WORD, *PWORD;
+/* wchar_t is 32 bits on powerpc-unknown-none-eabi; the console's is 16. */
+typedef unsigned short WCHAR, *PWCHAR, *PWSTR;
+typedef const unsigned short *PCWSTR;
+
+typedef int INT, *PINT;
+typedef unsigned int UINT, *PUINT;
+typedef long LONG, *PLONG;
+typedef unsigned long ULONG, *PULONG;
+typedef unsigned long DWORD, *PDWORD;
+typedef long long LONGLONG, *PLONGLONG;
+typedef unsigned long long ULONGLONG, *PULONGLONG;
+typedef unsigned long long QWORD, *PQWORD;
+typedef float FLOAT, *PFLOAT;
+typedef double DOUBLE, *PDOUBLE;
+
+typedef LONG LONG_PTR, *PLONG_PTR;
+typedef ULONG ULONG_PTR, *PULONG_PTR;
+typedef ULONG SIZE_T, *PSIZE_T;
+typedef ULONG DWORD_PTR, *PDWORD_PTR;
+
+typedef UCHAR BOOLEAN, *PBOOLEAN;
+typedef int BOOL, *PBOOL;
+
+typedef LONG NTSTATUS;
+typedef LONG HRESULT;
+typedef PVOID HANDLE, *PHANDLE;
+typedef ULONG ACCESS_MASK, *PACCESS_MASK;
+
+/* A user's Xbox Live identity. */
+typedef ULONGLONG XUID, *PXUID;
+
+#define TRUE 1
+#define FALSE 0
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
+#endif
+
+#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
+
+/* Doubly linked list entry; a list head is its own entry when empty. */
+typedef struct _LIST_ENTRY {
+ struct _LIST_ENTRY *Flink;
+ struct _LIST_ENTRY *Blink;
+} LIST_ENTRY, *PLIST_ENTRY;
+
+typedef struct _SINGLE_LIST_ENTRY {
+ struct _SINGLE_LIST_ENTRY *Next;
+} SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
+
+/* 64-bit integers also addressed as two halves; the high half comes first. */
+typedef union _LARGE_INTEGER {
+ struct {
+ LONG HighPart;
+ ULONG LowPart;
+ };
+ LONGLONG QuadPart;
+} LARGE_INTEGER, *PLARGE_INTEGER;
+
+typedef union _ULARGE_INTEGER {
+ struct {
+ ULONG HighPart;
+ ULONG LowPart;
+ };
+ ULONGLONG QuadPart;
+} ULARGE_INTEGER, *PULARGE_INTEGER;
+
+C_ASSERT(sizeof(PVOID) == 4);
+C_ASSERT(sizeof(LONG) == 4);
+C_ASSERT(sizeof(LONGLONG) == 8);
+C_ASSERT(sizeof(LIST_ENTRY) == 8);
+C_ASSERT(sizeof(LARGE_INTEGER) == 8);
+
+XBOX360_EXTERN_C_END
+
+/*
+ * Export `function` at `ordinal`, an integer literal from 1 to 0xFFFF, at
+ * file scope. xex-link rejects two exports at one ordinal. Ordinals that
+ * share a function are declared once each.
+ *
+ * Callers use the console calling convention, which expects r14-r31 back in
+ * full 64 bits. Code of the powerpc (SysV) code generation saves only their
+ * low words, so the export is an entry like the `_start` of the C runtime:
+ * it saves r14-r31 in full, reserves the home area that console callees
+ * store their arguments in, and calls `function` with r3-r10 unchanged.
+ * `function` takes at most eight 32-bit integer or pointer arguments and
+ * returns a 32-bit result or none.
+ *
+ * The export is an 8-byte `.xexports` record, as `xbox360_sys::export!`
+ * writes: the big-endian ordinal, then the address of the entry. xex-link
+ * turns the records into the XEX export table.
+ */
+#define XBOX360_EXPORT(ordinal, function) \
+ XBOX360_EXPORT_IMPL(ordinal, function, __xbox360_export_##ordinal)
+
+/* XBOX360_EXPORT with `name`, the symbol of the entry. */
+#define XBOX360_EXPORT_IMPL(ordinal, function, name) \
+ _Static_assert((ordinal) >= 1 && (ordinal) <= 0xFFFF, \
+ "export ordinals are 1 to 0xFFFF"); \
+ __attribute__((used)) static __typeof__(function) *const name##_target \
+ __asm__(#name "_target") = function; \
+ extern VOID name(VOID) __asm__(#name); \
+ __attribute__((used, retain, section(".xexports"))) static const struct { \
+ ULONG Ordinal; \
+ VOID (*Entry)(VOID); \
+ } name##_record = {(ordinal), name}; \
+ __asm__(".pushsection .text." #name ", \"ax\", @progbits\n" \
+ ".globl " #name "\n" \
+ ".type " #name ", @function\n" \
+ ".balign 4\n" #name ":\n" \
+ "stwu 1, -0xe0(1)\n" \
+ "mflr 0\n" \
+ "stw 0, 0x8(1)\n" \
+ ".irp reg, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31\n" \
+ "std \\reg, 0x50 + 8 * (\\reg - 14)(1)\n" \
+ ".endr\n" \
+ "lis 12, " #name "_target@ha\n" \
+ "lwz 12, " #name "_target@l(12)\n" \
+ "mtctr 12\n" \
+ "bctrl\n" \
+ ".irp reg, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31\n" \
+ "ld \\reg, 0x50 + 8 * (\\reg - 14)(1)\n" \
+ ".endr\n" \
+ "lwz 0, 0x8(1)\n" \
+ "mtlr 0\n" \
+ "addi 1, 1, 0xe0\n" \
+ "blr\n" \
+ ".size " #name ", . - " #name "\n" \
+ ".popsection")
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam.h b/platform/xex/sdk/include/xbox360/xam.h
new file mode 100644
index 0000000..4f409d0
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam.h
@@ -0,0 +1,16 @@
+/* xam.xex imports and the types they use. */
+
+#ifndef XBOX360_XAM_H
+#define XBOX360_XAM_H
+
+#include <xbox360/xboxkrnl.h>
+#include <xbox360/xam/xamdef.h>
+#include <xbox360/xam/net.h>
+#include <xbox360/xam/content.h>
+#include <xbox360/xam/user.h>
+#include <xbox360/xam/ui.h>
+#include <xbox360/xam/input.h>
+#include <xbox360/xam/notify.h>
+#include <xbox360/xam/system.h>
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/content.h b/platform/xex/sdk/include/xbox360/xam/content.h
new file mode 100644
index 0000000..acd782d
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/content.h
@@ -0,0 +1,220 @@
+/*
+ * XAM content packages: create, open, enumerate, copy and delete packages
+ * on storage devices.
+ */
+
+#ifndef XBOX360_XAM_CONTENT_H
+#define XBOX360_XAM_CONTENT_H
+
+#include <xbox360/xam/xamdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Kind of a content package, with Xenia's values. */
+typedef enum _XCONTENT_TYPE {
+ XCONTENTTYPE_SAVEDGAME = 0x00000001,
+ XCONTENTTYPE_MARKETPLACE = 0x00000002,
+ XCONTENTTYPE_PUBLISHER = 0x00000003,
+ XCONTENTTYPE_XBOX360TITLE = 0x00001000,
+ XCONTENTTYPE_IPTVPAUSEBUFFER = 0x00002000,
+ XCONTENTTYPE_XNACOMMUNITY = 0x00003000,
+ XCONTENTTYPE_INSTALLEDGAME = 0x00004000,
+ XCONTENTTYPE_XBOXTITLE = 0x00005000,
+ XCONTENTTYPE_SOCIALTITLE = 0x00006000,
+ XCONTENTTYPE_GAMESONDEMAND = 0x00007000,
+ XCONTENTTYPE_STORAGEPACK = 0x00008000,
+ XCONTENTTYPE_AVATARITEM = 0x00009000,
+ XCONTENTTYPE_PROFILE = 0x00010000,
+ XCONTENTTYPE_GAMERPICTURE = 0x00020000,
+ XCONTENTTYPE_THEME = 0x00030000,
+ XCONTENTTYPE_CACHEFILE = 0x00040000,
+ XCONTENTTYPE_STORAGEDOWNLOAD = 0x00050000,
+ XCONTENTTYPE_XBOXSAVEDGAME = 0x00060000,
+ XCONTENTTYPE_XBOXDOWNLOAD = 0x00070000,
+ XCONTENTTYPE_GAMEDEMO = 0x00080000,
+ XCONTENTTYPE_VIDEO = 0x00090000,
+ XCONTENTTYPE_GAMETITLE = 0x000A0000,
+ XCONTENTTYPE_INSTALLER = 0x000B0000,
+ XCONTENTTYPE_GAMETRAILER = 0x000C0000,
+ XCONTENTTYPE_ARCADE = 0x000D0000,
+ XCONTENTTYPE_XNA = 0x000E0000,
+ XCONTENTTYPE_LICENSESTORE = 0x000F0000,
+ XCONTENTTYPE_MOVIE = 0x00100000,
+ XCONTENTTYPE_TV = 0x00200000,
+ XCONTENTTYPE_MUSICVIDEO = 0x00300000,
+ XCONTENTTYPE_GAMEVIDEO = 0x00400000,
+ XCONTENTTYPE_PODCASTVIDEO = 0x00500000,
+ XCONTENTTYPE_VIRALVIDEO = 0x00600000,
+ XCONTENTTYPE_COMMUNITYGAME = 0x02000000,
+} XCONTENT_TYPE;
+
+/* Length of the display name, in UTF-16 units including the NUL. */
+#define XCONTENT_MAX_DISPLAYNAME_LENGTH 128
+/* Length of the file name in bytes. A name of this length has no NUL. */
+#define XCONTENT_MAX_FILENAME_LENGTH 42
+
+/* What XamContentCreate did. */
+#define XCONTENT_CREATED_NEW 1
+#define XCONTENT_OPENED_EXISTING 2
+
+/* The device, kind and names of a package. */
+typedef struct _XCONTENT_DATA {
+ DWORD DeviceID;
+ DWORD dwContentType;
+ WCHAR szDisplayName[XCONTENT_MAX_DISPLAYNAME_LENGTH];
+ CHAR szFileName[XCONTENT_MAX_FILENAME_LENGTH];
+ BYTE Padding[2];
+} XCONTENT_DATA, *PXCONTENT_DATA;
+
+C_ASSERT(sizeof(XCONTENT_DATA) == 0x134);
+C_ASSERT(__builtin_offsetof(XCONTENT_DATA, szFileName) == 0x108);
+
+/**
+ * Creates or opens a content package and maps it to the drive RootName.
+ * Flags holds the creation disposition in its low four bits. The disposition taken
+ * (XCONTENT_CREATED_NEW or XCONTENT_OPENED_EXISTING) is stored at Disposition when not
+ * NULL. Returns a Win32 error code, or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x258) DWORD XamContentCreate(
+ DWORD UserIndex,
+ PCSTR RootName,
+ const XCONTENT_DATA *ContentData,
+ DWORD Flags,
+ PDWORD Disposition,
+ PDWORD LicenseMask,
+ PXOVERLAPPED Overlapped);
+
+/** Closes the content drive RootName. Returns a Win32 error code, or ERROR_IO_PENDING with an Overlapped. */
+XAM_IMPORT(0x25A) DWORD XamContentClose(PCSTR RootName, PXOVERLAPPED Overlapped);
+
+/**
+ * Deletes a content package.
+ * Returns a Win32 error code, or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x25B) DWORD XamContentDelete(DWORD UserIndex, const XCONTENT_DATA *ContentData, PXOVERLAPPED Overlapped);
+
+/**
+ * Creates an enumerator of the storage devices accepting ContentTypes, returning
+ * ItemsPerCall 0x50-byte device records per XamEnumerate. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x25D) DWORD XamContentCreateDeviceEnumerator(
+ DWORD ContentTypes,
+ DWORD Flags,
+ DWORD ItemsPerCall,
+ PDWORD BufferSize,
+ PHANDLE Handle);
+
+/** Fills the 0x50-byte device record of DeviceId. Returns a Win32 error code. */
+XAM_IMPORT(0x25E) DWORD XamContentGetDeviceData(DWORD DeviceId, PBYTE DeviceData);
+
+/**
+ * Commits the writes to the content drive RootName. The 2.0.6717 dashboard flushes
+ * DASHUSER after it writes DashPreferences. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x267) DWORD XamContentFlush(PCSTR RootName, PXOVERLAPPED Overlapped);
+
+/**
+ * Copies the package of the 0x200-byte aggregate record Content to the device DeviceId
+ * points to, owned by the XUID NewOwner points to. The 2.0.6717 dashboard passes NULL
+ * for DeviceId when the destination is the package's device and NULL for NewOwner
+ * when the owner does not change.
+ * XAM calls Progress with a 64-bit byte count in r4, a reason in r8 and Context in
+ * the stack slot at 0x50 of its caller. The dashboard's routine (0x9225BF00) adds the
+ * growth of the count to its total, takes the count to start again at 0 on reason 1, and
+ * returns 0. The dashboard passes 0 for Unknown, whose meaning is not known. Returns a
+ * Win32 error code, or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x26C) DWORD XamContentCopyInternal(
+ const XUID *NewOwner,
+ const DWORD *DeviceId,
+ PCBYTE Content,
+ PCVOID Progress,
+ PVOID Context,
+ DWORD Unknown,
+ PXOVERLAPPED Overlapped);
+
+/** Moves a package; the arguments are those of XamContentCopyInternal. */
+XAM_IMPORT(0x26D) DWORD XamContentMoveInternal(
+ const XUID *NewOwner,
+ const DWORD *DeviceId,
+ PCBYTE Content,
+ PCVOID Progress,
+ PVOID Context,
+ DWORD Unknown,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Reads the header of the package of the 0x200-byte aggregate record Content into
+ * Buffer, 0x93D6 bytes in the 2.0.6717 dashboard. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x26E) DWORD XamContentGetMetaDataInternal(PCBYTE Content, PBYTE Buffer, PXOVERLAPPED Overlapped);
+
+/**
+ * Deletes the package of the 0x200-byte aggregate record Content. Returns a Win32 error
+ * code, or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x270) DWORD XamContentDeleteInternal(PCBYTE Content, PXOVERLAPPED Overlapped);
+
+/**
+ * Opens the package of the 0x200-byte aggregate record Content and maps it to the drive
+ * RootName, as XamContentCreate. The 2.0.6717 dashboard opens existing packages
+ * (Flags 3) and passes 0 for Reserved and Size. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x271) DWORD XamContentCreateInternal(
+ PCSTR RootName,
+ PCBYTE Content,
+ DWORD Flags,
+ PDWORD Disposition,
+ PDWORD LicenseMask,
+ DWORD Reserved,
+ ULONGLONG Size,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Launches the NUL-terminated executable path Image inside the package of the 0x200-byte
+ * aggregate record Content. Returns 0 on success; the system then ends the caller.
+ */
+XAM_IMPORT(0x273) DWORD XamContentLaunchImageInternal(PCBYTE Content, PCSTR Image);
+
+/**
+ * Writes the path of the package of the 0x200-byte aggregate record Content to Path as a
+ * NUL-terminated string of at most Capacity bytes. The 2.0.6717 dashboard passes 0x104
+ * and 0 for the reserved arguments. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x276) DWORD XamContentResolveInternal(
+ PCBYTE Content,
+ PSTR Path,
+ DWORD Capacity,
+ DWORD Reserved1,
+ DWORD Reserved2,
+ DWORD Reserved3);
+
+/**
+ * Writes the 0x24-byte attribute block of the package of the 0x200-byte aggregate record
+ * Content to Attributes; +0x4 holds the creation FILETIME. Returns a Win32 error code,
+ * or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x277) DWORD XamContentGetAttributesInternal(PCBYTE Content, PBYTE Attributes, PXOVERLAPPED Overlapped);
+
+/**
+ * Opens an enumeration of the packages of ContentType and TitleId on DeviceId (0: every
+ * device). The 2.0.6717 dashboard passes 0 as the first argument; its Memory area passes a
+ * device id, other callers 0. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x279) DWORD XamContentAggregateCreateEnumerator(
+ DWORD Reserved,
+ DWORD DeviceId,
+ DWORD ContentType,
+ DWORD TitleId,
+ PHANDLE Handle);
+
+/**
+ * Stores the id of the default content device at DeviceId. Returns a Win32 error code,
+ * ERROR_FUNCTION_FAILED when no device is the default. The 2.0.6717 dashboard passes the
+ * device word of a 0x200-byte content record and does not read the result.
+ */
+XAM_IMPORT(0x284) DWORD XamContentGetDefaultDevice(PDWORD DeviceId);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/input.h b/platform/xex/sdk/include/xbox360/xam/input.h
new file mode 100644
index 0000000..caf87bf
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/input.h
@@ -0,0 +1,155 @@
+/*
+ * XAM controller input: state, capabilities, vibration and keystrokes.
+ */
+
+#ifndef XBOX360_XAM_INPUT_H
+#define XBOX360_XAM_INPUT_H
+
+#include <xbox360/xam/xamdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Devices a controller query covers. */
+#define XINPUT_FLAG_GAMEPAD 0x00000001
+
+/* XamInputGetKeystrokeEx: every device class, and a keystroke of any user. */
+#define XINPUT_FLAG_ANYDEVICE 0x000000FF
+#define XINPUT_FLAG_ANYUSER 0x40000000
+
+/* Device type and subtype. */
+#define XINPUT_DEVTYPE_GAMEPAD 0x01
+#define XINPUT_DEVSUBTYPE_GAMEPAD 0x01
+
+/* Pressed buttons of a gamepad. */
+#define XINPUT_GAMEPAD_DPAD_UP 0x0001
+#define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
+#define XINPUT_GAMEPAD_DPAD_LEFT 0x0004
+#define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008
+#define XINPUT_GAMEPAD_START 0x0010
+#define XINPUT_GAMEPAD_BACK 0x0020
+#define XINPUT_GAMEPAD_LEFT_THUMB 0x0040
+#define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080
+#define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
+#define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
+#define XINPUT_GAMEPAD_GUIDE 0x0400
+#define XINPUT_GAMEPAD_A 0x1000
+#define XINPUT_GAMEPAD_B 0x2000
+#define XINPUT_GAMEPAD_X 0x4000
+#define XINPUT_GAMEPAD_Y 0x8000
+
+/* Capability flags. */
+#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
+#define XINPUT_CAPS_WIRELESS 0x0002
+#define XINPUT_CAPS_VOICE_SUPPORTED 0x0004
+#define XINPUT_CAPS_PMD_SUPPORTED 0x0008
+#define XINPUT_CAPS_NO_NAVIGATION 0x0010
+
+/* Keystroke flags. */
+#define XINPUT_KEYSTROKE_KEYDOWN 0x0001
+#define XINPUT_KEYSTROKE_KEYUP 0x0002
+#define XINPUT_KEYSTROKE_REPEAT 0x0004
+
+typedef struct _XINPUT_GAMEPAD {
+ WORD wButtons;
+ BYTE bLeftTrigger;
+ BYTE bRightTrigger;
+ SHORT sThumbLX;
+ SHORT sThumbLY;
+ SHORT sThumbRX;
+ SHORT sThumbRY;
+} XINPUT_GAMEPAD, *PXINPUT_GAMEPAD;
+
+C_ASSERT(sizeof(XINPUT_GAMEPAD) == 12);
+
+typedef struct _XINPUT_STATE {
+ /* Changes whenever the controller state changes. */
+ DWORD dwPacketNumber;
+ XINPUT_GAMEPAD Gamepad;
+} XINPUT_STATE, *PXINPUT_STATE;
+
+C_ASSERT(sizeof(XINPUT_STATE) == 16);
+
+/* Motor speeds, 0 to 65535. */
+typedef struct _XINPUT_VIBRATION {
+ WORD wLeftMotorSpeed;
+ WORD wRightMotorSpeed;
+} XINPUT_VIBRATION, *PXINPUT_VIBRATION;
+
+C_ASSERT(sizeof(XINPUT_VIBRATION) == 4);
+
+/* The gamepad and vibration fields hold the ranges the device supports. */
+typedef struct _XINPUT_CAPABILITIES {
+ BYTE Type;
+ BYTE SubType;
+ WORD Flags;
+ XINPUT_GAMEPAD Gamepad;
+ XINPUT_VIBRATION Vibration;
+} XINPUT_CAPABILITIES, *PXINPUT_CAPABILITIES;
+
+C_ASSERT(sizeof(XINPUT_CAPABILITIES) == 20);
+C_ASSERT(__builtin_offsetof(XINPUT_CAPABILITIES, Vibration) == 16);
+
+/* One key transition. Controller buttons arrive as virtual keys 0x5800 and up. */
+typedef struct _XINPUT_KEYSTROKE {
+ WORD VirtualKey;
+ WCHAR Unicode;
+ WORD Flags;
+ BYTE UserIndex;
+ BYTE HidCode;
+} XINPUT_KEYSTROKE, *PXINPUT_KEYSTROKE;
+
+C_ASSERT(sizeof(XINPUT_KEYSTROKE) == 8);
+
+/*
+ * Controller keys as XamInputGetKeystrokeEx reports them in VirtualKey.
+ * Keyboard keys use Windows virtual key codes, not listed here.
+ */
+typedef enum _XINPUT_PAD_KEY {
+ VK_PAD_A = 0x5800,
+ VK_PAD_B = 0x5801,
+ VK_PAD_X = 0x5802,
+ VK_PAD_Y = 0x5803,
+ VK_PAD_RSHOULDER = 0x5804,
+ VK_PAD_LSHOULDER = 0x5805,
+ VK_PAD_LTRIGGER = 0x5806,
+ VK_PAD_RTRIGGER = 0x5807,
+ VK_PAD_DPAD_UP = 0x5810,
+ VK_PAD_DPAD_DOWN = 0x5811,
+ VK_PAD_DPAD_LEFT = 0x5812,
+ VK_PAD_DPAD_RIGHT = 0x5813,
+ VK_PAD_START = 0x5814,
+ VK_PAD_BACK = 0x5815,
+ VK_PAD_LTHUMB_UP = 0x5820,
+ VK_PAD_LTHUMB_DOWN = 0x5821,
+ VK_PAD_LTHUMB_RIGHT = 0x5822,
+ VK_PAD_LTHUMB_LEFT = 0x5823,
+} XINPUT_PAD_KEY;
+
+/**
+ * Reads the capabilities of the controller of a user slot.
+ * Returns a Win32 error code: ERROR_DEVICE_NOT_CONNECTED without a controller.
+ */
+XAM_IMPORT(0x190) DWORD XamInputGetCapabilities(DWORD UserIndex, DWORD Flags, PXINPUT_CAPABILITIES Capabilities);
+
+/**
+ * Reads the state of the controller of a user slot.
+ * Returns a Win32 error code: ERROR_DEVICE_NOT_CONNECTED without a controller.
+ */
+XAM_IMPORT(0x191) DWORD XamInputGetState(DWORD UserIndex, DWORD Flags, PXINPUT_STATE State);
+
+/**
+ * Sets the motor speeds of the controller of a user slot. Xenia ignores Flags.
+ * Returns a Win32 error code.
+ */
+XAM_IMPORT(0x192) DWORD XamInputSetState(DWORD UserIndex, DWORD Flags, const XINPUT_VIBRATION *Vibration);
+
+/**
+ * Takes the next queued key transition. UserIndex points to the user slot, or
+ * with XINPUT_FLAG_ANYUSER in Flags receives the slot of the keystroke.
+ * Returns a Win32 error code; nonzero when no keystroke is queued.
+ */
+XAM_IMPORT(0x198) DWORD XamInputGetKeystrokeEx(PDWORD UserIndex, DWORD Flags, PXINPUT_KEYSTROKE Keystroke);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/net.h b/platform/xex/sdk/include/xbox360/xam/net.h
new file mode 100644
index 0000000..2774402
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/net.h
@@ -0,0 +1,550 @@
+/*
+ * Winsock, XNet, HTTP and UPnP exports of xam.xex (NetDll_*) and the Xbox
+ * LIVE logon exports (XNetLogon*).
+ *
+ * Every NetDll_* export takes an XNCALLER first. Multi-byte socket
+ * addresses and ports are in network byte order.
+ */
+
+#ifndef XBOX360_XAM_NET_H
+#define XBOX360_XAM_NET_H
+
+#include <xbox360/xam/xamdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* On whose behalf a network call is made. */
+typedef enum _XNCALLER {
+ XNCALLER_TITLE = 1,
+ XNCALLER_SYSAPP = 2,
+ XNCALLER_XBDM = 3,
+} XNCALLER;
+
+/*
+ * Winsock
+ */
+
+/* A socket, or INVALID_SOCKET from a call that failed. */
+typedef ULONG SOCKET, *PSOCKET;
+
+#define INVALID_SOCKET ((SOCKET)~0)
+/* Result of a call that has no count to return: 0 or this. */
+#define SOCKET_ERROR (-1)
+
+/* Address family. */
+#define AF_INET 2
+
+/* Socket type. */
+#define SOCK_STREAM 1
+#define SOCK_DGRAM 2
+
+/* Protocol, also an option level. */
+#define IPPROTO_TCP 6
+#define IPPROTO_UDP 17
+
+/* Option level of IP options. */
+#define IPPROTO_IP 0
+
+/* What NetDll_shutdown disables. */
+#define SD_RECEIVE 0
+#define SD_SEND 1
+#define SD_BOTH 2
+
+/* NetDll_ioctlsocket commands. */
+/* Sets non-blocking mode from a nonzero argument. */
+#define FIONBIO 0x8004667EUL
+/* Stores the number of bytes ready to read. */
+#define FIONREAD 0x4004667FUL
+
+/* Option level of socket options. */
+#define SOL_SOCKET 0xFFFF
+
+/* Options of level SOL_SOCKET. The console rejects SO_KEEPALIVE and
+ SO_ERROR with WSAENOPROTOOPT. SO_DONTLINGER and SO_EXCLUSIVEADDRUSE can
+ only be set. */
+#define SO_REUSEADDR 0x0004
+#define SO_KEEPALIVE 0x0008
+#define SO_BROADCAST 0x0020
+#define SO_LINGER 0x0080
+#define SO_SNDBUF 0x1001
+#define SO_RCVBUF 0x1002
+#define SO_SNDTIMEO 0x1005
+#define SO_RCVTIMEO 0x1006
+#define SO_ERROR 0x1007
+#define SO_TYPE 0x1008
+#define SO_DONTLINGER (~SO_LINGER)
+#define SO_EXCLUSIVEADDRUSE (~SO_REUSEADDR)
+
+/* Options of the console only. Their names are this SDK's; the official ones
+ are unknown. */
+
+/* Level SOL_SOCKET. */
+/* Marks the socket insecure: its traffic bypasses XNet security. A title
+ needs the XEX_SYSTEM_INSECURE_SOCKETS privilege, or setting it fails with
+ WSAEACCES. */
+#define SO_INSECURE 0x5801
+/* Limits the socket to the local network: connect and sendto fail with
+ WSAEHOSTUNREACH for an address that is not private (10/8, 172.16/12,
+ 192.168/16), on the console's subnet, loopback, broadcast or multicast. */
+#define SO_LAN_ONLY 0x5802
+
+/* Level IPPROTO_TCP. A TCP socket only; the MSS values are 88 to 1460. */
+/* The peer's receive window, scaled. Can only be read. */
+#define TCP_SEND_WINDOW 0x5802
+/* The segment size of sends: 512 until the connection is established, then
+ the peer's MSS, at most TCP_LOCAL_MSS. */
+#define TCP_SEND_MSS 0x5803
+/* The MSS that the socket announces and the most it sends. Unless set, the
+ connection picks 1460 for an address on the console's subnet, 1324 for
+ another, and 1264 for an XNet secure address. */
+#define TCP_LOCAL_MSS 0x5804
+/* Nonzero offers selective acknowledgments (RFC 2018), which the connection
+ uses if the peer permits them. Can only be set. */
+#define TCP_SACK 0x5805
+
+/* Level IPPROTO_IP. The DSCP of sent packets: one byte, 0 to 63. */
+#define IP_DSCP 0x64
+
+/* Option of level IPPROTO_TCP. */
+#define TCP_NODELAY 0x0001
+
+/* Options of level IPPROTO_IP, with their Winsock 1 numbers. IP_TTL takes 1
+ to 255. The membership options take the group address (the start of an
+ ip_mreq) on a bound socket that is not TCP, at most four groups per socket;
+ they can only be set. */
+#define IP_ADD_MEMBERSHIP 5
+#define IP_DROP_MEMBERSHIP 6
+#define IP_TTL 7
+
+/* Flags of sends and receives. */
+#define MSG_OOB 0x1
+#define MSG_PEEK 0x2
+#define MSG_DONTROUTE 0x4
+
+/* Network events of NetDll_WSAEventSelect. */
+#define FD_READ 0x01
+#define FD_WRITE 0x02
+#define FD_OOB 0x04
+#define FD_ACCEPT 0x08
+#define FD_CONNECT 0x10
+#define FD_CLOSE 0x20
+
+/* Sockets per select set. */
+#define FD_SETSIZE 64
+
+/* WSADATA, as NetDll_WSAStartup stores it. */
+typedef struct WSAData {
+ WORD wVersion;
+ WORD wHighVersion;
+ CHAR szDescription[257];
+ CHAR szSystemStatus[129];
+ USHORT iMaxSockets;
+ USHORT iMaxUdpDg;
+ PCHAR lpVendorInfo;
+} WSADATA, *PWSADATA, *LPWSADATA;
+
+C_ASSERT(__builtin_offsetof(WSADATA, iMaxSockets) == 0x186);
+C_ASSERT(sizeof(WSADATA) == 0x190);
+
+/* IPv4 address. */
+typedef struct in_addr {
+ ULONG s_addr;
+} IN_ADDR, *PIN_ADDR;
+
+C_ASSERT(sizeof(IN_ADDR) == 4);
+
+/* Generic socket address. */
+typedef struct sockaddr {
+ USHORT sa_family;
+ CHAR sa_data[14];
+} SOCKADDR, *PSOCKADDR;
+
+C_ASSERT(sizeof(SOCKADDR) == 16);
+
+/* IPv4 socket address. */
+typedef struct sockaddr_in {
+ USHORT sin_family;
+ USHORT sin_port;
+ struct in_addr sin_addr;
+ CHAR sin_zero[8];
+} SOCKADDR_IN, *PSOCKADDR_IN;
+
+C_ASSERT(sizeof(SOCKADDR_IN) == 16);
+
+/* Descriptor set of NetDll_select. */
+typedef struct fd_set {
+ UINT fd_count;
+ SOCKET fd_array[FD_SETSIZE];
+} fd_set, *PFD_SET;
+
+C_ASSERT(sizeof(fd_set) == 0x104);
+
+/* Time interval. */
+typedef struct timeval {
+ LONG tv_sec;
+ LONG tv_usec;
+} TIMEVAL, *PTIMEVAL;
+
+C_ASSERT(sizeof(TIMEVAL) == 8);
+
+/*
+ * XNet
+ */
+
+/* NetDll_XNetGetTitleXnAddr and NetDll_XNetGetDebugXnAddr results. */
+#define XNET_GET_XNADDR_PENDING 0x0000
+#define XNET_GET_XNADDR_NONE 0x0001
+#define XNET_GET_XNADDR_ETHERNET 0x0002
+#define XNET_GET_XNADDR_STATIC 0x0004
+#define XNET_GET_XNADDR_DHCP 0x0008
+#define XNET_GET_XNADDR_PPPOE 0x0010
+#define XNET_GET_XNADDR_GATEWAY 0x0020
+#define XNET_GET_XNADDR_DNS 0x0040
+#define XNET_GET_XNADDR_ONLINE 0x0080
+#define XNET_GET_XNADDR_TROUBLESHOOT 0x8000
+
+/* NetDll_XNetGetEthernetLinkStatus flags. */
+#define XNET_ETHERNET_LINK_ACTIVE 0x01
+#define XNET_ETHERNET_LINK_100MBPS 0x02
+#define XNET_ETHERNET_LINK_10MBPS 0x04
+#define XNET_ETHERNET_LINK_FULL_DUPLEX 0x08
+#define XNET_ETHERNET_LINK_HALF_DUPLEX 0x10
+
+/* XNetStartupParams flags. */
+/* Accept insecure connections, as development kits allow. */
+#define XNET_STARTUP_BYPASS_SECURITY 0x01
+
+/* Options of NetDll_XNetGetOpt and NetDll_XNetSetOpt. */
+/* The XNetStartupParams the stack was started with. */
+#define XNET_OPTID_STARTUP_PARAMS 0x0001
+/* A ULONGLONG that changes with network traffic. */
+#define XNET_OPTID_ACTIVITY_COUNTER 0x0004
+/* Promiscuous receive. */
+#define XNET_OPTID_PROMISCUOUS 0x1390
+/* Link flags of the network interface. */
+#define XNET_OPTID_LINK_FLAGS 0x1395
+/* Reports the secondary network interface. */
+#define XNET_OPTID_SECONDARY_NIC 0x2F00
+/* A ULONG state of the USB wireless adapter; bit 0 is set while attached. */
+#define XNET_OPTID_WIRELESS_ADAPTER_STATE 0x2AF9
+/* The wireless security type and key, in a 0x48-byte record. */
+#define XNET_OPTID_WIRELESS_KEY 0x2AFA
+/* The wireless adapter information record. */
+#define XNET_OPTID_WIRELESS_ADAPTER_INFO 0x2AFC
+/* A count followed by at most ten wireless security capabilities. */
+#define XNET_OPTID_WIRELESS_CAPABILITIES 0x2AFD
+/* A 0x24-byte record with the SSID length and 32 SSID bytes. */
+#define XNET_OPTID_WIRELESS_SSID 0x0D010102
+/* A ULONG BSS type: 0 ad-hoc, 1 infrastructure. */
+#define XNET_OPTID_WIRELESS_BSS_TYPE 0x0D010108
+/* A ULONG radio mode: 1 802.11b, 2 802.11a, 3 802.11g, 4 any. */
+#define XNET_OPTID_WIRELESS_MODE 0x0D010204
+/* A LONG: received signal strength of the wireless adapter in dBm. */
+#define XNET_OPTID_WIRELESS_RSSI 0x0D010206
+/* Variable-length wireless scan records. */
+#define XNET_OPTID_WIRELESS_SCAN_RESULTS 0x0D010217
+/* Starts a wireless network scan. WSAEINPROGRESS means one is active. */
+#define XNET_OPTID_WIRELESS_SCAN_START 0x0D01021A
+
+/*
+ * Network address of a console. Addresses and the port are in network byte
+ * order.
+ */
+typedef struct _XNADDR {
+ /* IP address; zero without a static or DHCP address. */
+ IN_ADDR ina;
+ /* Online IP address; zero when not online. */
+ IN_ADDR inaOnline;
+ WORD wPortOnline;
+ BYTE abEnet[6];
+ BYTE abOnline[20];
+} XNADDR, *PXNADDR;
+
+C_ASSERT(sizeof(XNADDR) == 0x24);
+
+/*
+ * Network stack settings of NetDll_XNetStartup. A zero field selects the
+ * default of the network stack.
+ */
+typedef struct _XNetStartupParams {
+ /* sizeof(XNetStartupParams), 13. */
+ BYTE cfgSizeOfStruct;
+ /* XNET_STARTUP_* flags. */
+ BYTE cfgFlags;
+ BYTE cfgSockMaxDgramSockets;
+ BYTE cfgSockMaxStreamSockets;
+ BYTE cfgSockDefaultRecvBufsizeInK;
+ BYTE cfgSockDefaultSendBufsizeInK;
+ BYTE cfgKeyRegMax;
+ BYTE cfgSecRegMax;
+ BYTE cfgQosDataLimitDiv4;
+ BYTE cfgQosProbeTimeoutInSeconds;
+ BYTE cfgQosProbeRetries;
+ BYTE cfgQosSrvMaxSimultaneousResponses;
+ BYTE cfgQosPairWaitTimeInSeconds;
+} XNetStartupParams, *PXNetStartupParams;
+
+C_ASSERT(__builtin_offsetof(XNetStartupParams, cfgSockDefaultRecvBufsizeInK) == 4);
+C_ASSERT(sizeof(XNetStartupParams) == 13);
+
+/*
+ * Saved network configuration, the 0x1EC-byte record of
+ * NetDll_XnpLoadConfigParams, NetDll_XnpSaveConfigParams and
+ * NetDll_XnpConfig. Fields without a known meaning are reserved; a caller
+ * zeroes them.
+ */
+typedef struct _XNetConfigParams {
+ BYTE Reserved0[0x4C];
+ /* Meaning of each bit unknown; a debug monitor sets 0xC with a static
+ address, subnet and gateway. */
+ USHORT Flags;
+ BYTE Reserved1[6];
+ /* Static IP address, network byte order. */
+ ULONG Address;
+ /* Subnet mask, network byte order. */
+ ULONG Subnet;
+ /* Default gateway, network byte order. */
+ ULONG Gateway;
+ BYTE Reserved2[8];
+ /* DHCP host name, NUL-terminated. */
+ CHAR HostName[0x184];
+} XNetConfigParams, *PXNetConfigParams;
+
+C_ASSERT(__builtin_offsetof(XNetConfigParams, Flags) == 0x4C);
+C_ASSERT(__builtin_offsetof(XNetConfigParams, Address) == 0x54);
+C_ASSERT(__builtin_offsetof(XNetConfigParams, Subnet) == 0x58);
+C_ASSERT(__builtin_offsetof(XNetConfigParams, Gateway) == 0x5C);
+C_ASSERT(__builtin_offsetof(XNetConfigParams, HostName) == 0x68);
+C_ASSERT(sizeof(XNetConfigParams) == 0x1EC);
+
+/*
+ * Winsock exports
+ */
+
+/** Initializes Winsock. VersionRequested is MAKEWORD(major, minor). */
+XAM_IMPORT(0x001) INT NetDll_WSAStartup(XNCALLER Caller, WORD VersionRequested, PWSADATA Data);
+
+/** Creates a socket. Returns the socket or INVALID_SOCKET. */
+XAM_IMPORT(0x003) SOCKET NetDll_socket(XNCALLER Caller, INT AddressFamily, INT Type, INT Protocol);
+
+/** Closes a socket. */
+XAM_IMPORT(0x004) INT NetDll_closesocket(XNCALLER Caller, SOCKET Socket);
+
+/** Disables sends, receives or both (SD_*) on a socket. */
+XAM_IMPORT(0x005) INT NetDll_shutdown(XNCALLER Caller, SOCKET Socket, INT How);
+
+/** Controls a socket mode. */
+XAM_IMPORT(0x006) INT NetDll_ioctlsocket(XNCALLER Caller, SOCKET Socket, ULONG Command, PULONG Argument);
+
+/** Sets a socket option. */
+XAM_IMPORT(0x007) INT NetDll_setsockopt(XNCALLER Caller, SOCKET Socket, INT Level, INT OptionName,
+ PCSTR OptionValue, INT OptionLength);
+
+/** Reads a socket option. */
+XAM_IMPORT(0x008) INT NetDll_getsockopt(XNCALLER Caller, SOCKET Socket, INT Level, INT OptionName,
+ PCHAR OptionValue, PINT OptionLength);
+
+/** Stores the local address of a socket. */
+XAM_IMPORT(0x009) INT NetDll_getsockname(XNCALLER Caller, SOCKET Socket, struct sockaddr *Name,
+ PINT NameLength);
+
+/** Stores the remote address of a connected socket. */
+XAM_IMPORT(0x00A) INT NetDll_getpeername(XNCALLER Caller, SOCKET Socket, struct sockaddr *Name,
+ PINT NameLength);
+
+/** Binds a socket to a local address. */
+XAM_IMPORT(0x00B) INT NetDll_bind(XNCALLER Caller, SOCKET Socket, const struct sockaddr *Name,
+ INT NameLength);
+
+/** Connects a socket to a remote address. */
+XAM_IMPORT(0x00C) INT NetDll_connect(XNCALLER Caller, SOCKET Socket, const struct sockaddr *Name,
+ INT NameLength);
+
+/** Places a socket in the listening state. */
+XAM_IMPORT(0x00D) INT NetDll_listen(XNCALLER Caller, SOCKET Socket, INT Backlog);
+
+/** Accepts a connection. Returns the new socket or INVALID_SOCKET. */
+XAM_IMPORT(0x00E) SOCKET NetDll_accept(XNCALLER Caller, SOCKET Socket, struct sockaddr *Address,
+ PINT AddressLength);
+
+/** Waits until sockets are readable, writable or in error. Returns the number of ready sockets. */
+XAM_IMPORT(0x00F) INT NetDll_select(XNCALLER Caller, INT Count, fd_set *ReadFds, fd_set *WriteFds,
+ fd_set *ExceptFds, const struct timeval *Timeout);
+
+/** Receives from a connected socket. Returns the byte count or SOCKET_ERROR. */
+XAM_IMPORT(0x012) INT NetDll_recv(XNCALLER Caller, SOCKET Socket, PCHAR Buffer, INT Length, INT Flags);
+
+/** Receives a datagram and its source address. */
+XAM_IMPORT(0x014) INT NetDll_recvfrom(XNCALLER Caller, SOCKET Socket, PCHAR Buffer, INT Length, INT Flags,
+ struct sockaddr *From, PINT FromLength);
+
+/** Sends on a connected socket. Returns the byte count or SOCKET_ERROR. */
+XAM_IMPORT(0x016) INT NetDll_send(XNCALLER Caller, SOCKET Socket, PCSTR Buffer, INT Length, INT Flags);
+
+/** Sends a datagram to an address. */
+XAM_IMPORT(0x018) INT NetDll_sendto(XNCALLER Caller, SOCKET Socket, PCSTR Buffer, INT Length, INT Flags,
+ const struct sockaddr *To, INT ToLength);
+
+/** Returns the last Winsock error of the current thread. */
+XAM_IMPORT(0x01B) INT NetDll_WSAGetLastError(XNCALLER Caller);
+
+/**
+ * Associates network events (FD_*) of a socket with an event object. A NULL
+ * EventObject and no events end the association.
+ */
+XAM_IMPORT(0x023) INT NetDll_WSAEventSelect(XNCALLER Caller, SOCKET Socket, HANDLE EventObject,
+ LONG NetworkEvents);
+
+/*
+ * XNet exports
+ */
+
+/** Initializes the network stack. Params may be NULL. */
+XAM_IMPORT(0x033) INT NetDll_XNetStartup(XNCALLER Caller, const XNetStartupParams *Params);
+
+/** Fills a buffer with random bytes. */
+XAM_IMPORT(0x035) INT NetDll_XNetRandom(XNCALLER Caller, PBYTE Buffer, UINT Length);
+
+/** Stores the title XNADDR. Returns XNET_GET_XNADDR_* flags. */
+XAM_IMPORT(0x049) DWORD NetDll_XNetGetTitleXnAddr(XNCALLER Caller, PXNADDR Address);
+
+/** Stores the debug XNADDR. Returns XNET_GET_XNADDR_* flags. */
+XAM_IMPORT(0x04A) DWORD NetDll_XNetGetDebugXnAddr(XNCALLER Caller, PXNADDR Address);
+
+/** Returns the link status (XNET_ETHERNET_LINK_*) of the network interface. */
+XAM_IMPORT(0x04B) DWORD NetDll_XNetGetEthernetLinkStatus(XNCALLER Caller);
+
+/** Reads a network stack option (XNET_OPTID_*). */
+XAM_IMPORT(0x04E) INT NetDll_XNetGetOpt(XNCALLER Caller, DWORD OptionId, PBYTE Value, PINT ValueLength);
+
+/** Writes a network stack option (XNET_OPTID_*). */
+XAM_IMPORT(0x04F) INT NetDll_XNetSetOpt(XNCALLER Caller, DWORD OptionId, PCBYTE Value, DWORD ValueLength);
+
+/**
+ * NetDll_XNetStartup with a third argument. The 2.0.6717 dashboard calls it
+ * in place of NetDll_XNetStartup when XamGetSystemVersion is 0x200A3200 or
+ * more, with Version 0x2017F400, and treats the result as that of
+ * NetDll_XNetStartup.
+ */
+XAM_IMPORT(0x050) INT NetDll_XNetStartupVersion(XNCALLER Caller, const XNetStartupParams *Params,
+ DWORD Version);
+
+/** Reads the saved network configuration, a 0x1EC-byte record, into Params. */
+XAM_IMPORT(0x065) HRESULT NetDll_XnpLoadConfigParams(XNCALLER Caller, PXNetConfigParams Params);
+
+/**
+ * Saves the 0x1EC-byte network configuration record Params. Returns
+ * E_PENDING while the save has not finished; the 2.0.6717 dashboard calls it
+ * again until it does.
+ */
+XAM_IMPORT(0x066) HRESULT NetDll_XnpSaveConfigParams(XNCALLER Caller, const XNetConfigParams *Params);
+
+/** Applies a network configuration. The meaning of Flags is unknown; a debug monitor passes 0. */
+XAM_IMPORT(0x068) INT NetDll_XnpConfig(XNCALLER Caller, const XNetConfigParams *Config, DWORD Flags);
+
+/** Stores the network configuration status. The layout of the record is unknown. */
+XAM_IMPORT(0x069) INT NetDll_XnpGetConfigStatus(XNCALLER Caller, PVOID Status);
+
+/**
+ * Installs or removes Ethernet frame transmit and receive callbacks. The
+ * callback signatures and the meaning of each Flags bit are unknown; a debug
+ * monitor's network simulator sets 0x2 and a frame capture sets none.
+ */
+XAM_IMPORT(0x06D) INT NetDll_XnpEthernetInterceptSetCallbacks(XNCALLER Caller, PVOID Transmit, PVOID Receive,
+ PVOID Context, DWORD Flags);
+
+/** Transmits a raw Ethernet frame. */
+XAM_IMPORT(0x06E) DWORD NetDll_XnpEthernetInterceptXmit(XNCALLER Caller, PBYTE Frame, DWORD Length);
+
+/** Delivers a raw Ethernet frame to the network stack. */
+XAM_IMPORT(0x06F) DWORD NetDll_XnpEthernetInterceptRecv(XNCALLER Caller, PBYTE Frame, DWORD Length);
+
+/** Stores the list of open sockets. Count holds the capacity on entry and the count on return. */
+XAM_IMPORT(0x07A) DWORD NetDll_XnpGetActiveSocketList(XNCALLER Caller, PVOID Buffer, PDWORD Count);
+
+/** Informs the network stack that the system time changed. */
+XAM_IMPORT(0x07B) DWORD NetDll_XnpNoteSystemTime(XNCALLER Caller);
+
+/*
+ * HTTP exports. Session, connection and request handles are DWORD values; 0
+ * means failure.
+ */
+
+/** Initializes the HTTP client. */
+XAM_IMPORT(0x0C9) BOOL NetDll_XHttpStartup(XNCALLER Caller, DWORD Reserved, DWORD Parameters);
+
+/** Shuts down the HTTP client. */
+XAM_IMPORT(0x0CA) BOOL NetDll_XHttpShutdown(XNCALLER Caller);
+
+/** Opens an HTTP session. Returns the session handle or 0. */
+XAM_IMPORT(0x0CB) DWORD NetDll_XHttpOpen(XNCALLER Caller, PCSTR UserAgent, DWORD AccessType, DWORD ProxyName,
+ DWORD ProxyBypass, DWORD Flags);
+
+/** Closes an HTTP handle. */
+XAM_IMPORT(0x0CC) BOOL NetDll_XHttpCloseHandle(XNCALLER Caller, DWORD Handle);
+
+/** Opens an HTTP connection to a server. Returns the connection handle or 0. */
+XAM_IMPORT(0x0CD) DWORD NetDll_XHttpConnect(XNCALLER Caller, DWORD Session, PCSTR ServerName, DWORD ServerPort,
+ DWORD Flags);
+
+/** Installs a status callback on an HTTP handle. The callback signature is unknown. */
+XAM_IMPORT(0x0CE) DWORD NetDll_XHttpSetStatusCallback(XNCALLER Caller, DWORD Handle, DWORD Callback,
+ DWORD NotificationFlags, DWORD Reserved);
+
+/** Opens an HTTP request. Returns the request handle or 0. */
+XAM_IMPORT(0x0CF) DWORD NetDll_XHttpOpenRequest(XNCALLER Caller, DWORD Connection, PCSTR Verb, PCSTR ObjectName,
+ DWORD Version, DWORD Referrer, DWORD AcceptTypes, DWORD Flags);
+
+/** Sends an HTTP request. */
+XAM_IMPORT(0x0D1) BOOL NetDll_XHttpSendRequest(XNCALLER Caller, DWORD Request, DWORD Headers, DWORD HeadersLength,
+ DWORD Optional, DWORD OptionalLength, DWORD TotalLength,
+ DWORD Context);
+
+/** Waits for the response to an HTTP request. */
+XAM_IMPORT(0x0D2) BOOL NetDll_XHttpReceiveResponse(XNCALLER Caller, DWORD Request, DWORD Reserved);
+
+/** Reads response header information. */
+XAM_IMPORT(0x0D3) BOOL NetDll_XHttpQueryHeaders(XNCALLER Caller, DWORD Request, DWORD InfoLevel, DWORD Name,
+ PDWORD Buffer, PDWORD BufferLength, DWORD Index);
+
+/** Reads response body data. The byte count is stored at BytesRead. */
+XAM_IMPORT(0x0D4) BOOL NetDll_XHttpReadData(XNCALLER Caller, DWORD Request, PVOID Buffer, DWORD Length,
+ PDWORD BytesRead);
+
+/** Sets an option on an HTTP handle. */
+XAM_IMPORT(0x0D7) BOOL NetDll_XHttpSetOption(XNCALLER Caller, DWORD Handle, DWORD Option, PDWORD Buffer,
+ DWORD BufferLength);
+
+/** Processes pending HTTP work for a session. */
+XAM_IMPORT(0x0D8) BOOL NetDll_XHttpDoWork(XNCALLER Caller, DWORD Session, DWORD Timeout);
+
+/*
+ * UPnP exports
+ */
+
+/** Starts the UPnP client. */
+XAM_IMPORT(0x0FB) INT NetDll_UpnpStartup(XNCALLER Caller);
+
+/** Stops the UPnP client. */
+XAM_IMPORT(0x0FC) INT NetDll_UpnpCleanup(XNCALLER Caller);
+
+/*
+ * Xbox LIVE logon exports
+ */
+
+/** Stores the Xbox LIVE logon status and extended status. */
+XAM_IMPORT(0x13B) DWORD XNetLogonGetExtendedStatus(PDWORD Status, PDWORD ExtendedStatus);
+
+/**
+ * Discards the cached Xbox LIVE tickets. The 2.0.6717 dashboard passes 0; the
+ * meaning of the argument is unknown.
+ */
+XAM_IMPORT(0x13C) DWORD XNetLogonClearTicketCaches(DWORD Unknown);
+
+/* Ordinal 0x139 from Xenia's export table; 0x1C6 is XamGetWCNConfigFile. */
+/** Stores a NUL-terminated Xbox LIVE service DNS name in Buffer. */
+XAM_IMPORT(0x139) DWORD XNetLogonGetDnsString(DWORD Index, PCHAR Buffer, DWORD Capacity);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/notify.h b/platform/xex/sdk/include/xbox360/xam/notify.h
new file mode 100644
index 0000000..a7957c5
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/notify.h
@@ -0,0 +1,80 @@
+/*
+ * XAM notifications and messages to XAM applications.
+ */
+
+#ifndef XBOX360_XAM_NOTIFY_H
+#define XBOX360_XAM_NOTIFY_H
+
+#include <xbox360/xam/xamdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Notification areas of XamNotifyCreateListenerInternal. */
+#define XNOTIFY_SYSTEM 0x00000001
+
+/**
+ * Takes the next queued notification of Listener and stores its id and parameter.
+ * A nonzero MatchId takes only notifications with that id.
+ * Returns nonzero when a notification was taken.
+ */
+XAM_IMPORT(0x28B) BOOLEAN XNotifyGetNext(HANDLE Listener, DWORD MatchId, PDWORD Id, PDWORD Parameter);
+
+/**
+ * Sends the notification Id with Parameter to every listener. The 2.0.6717 dashboard
+ * sends 0x8000000F with the bit of the user whose background changed and does not read
+ * the result, so none is declared.
+ */
+XAM_IMPORT(0x28E) VOID XNotifyBroadcast(DWORD Id, DWORD Parameter);
+
+/** Creates a notification listener for the notification areas in Mask. Returns the listener handle. */
+XAM_IMPORT(0x291) HANDLE XamNotifyCreateListenerInternal(ULONGLONG Mask, DWORD IsSystem, DWORD MaxVersion);
+
+/**
+ * Calls a XAM application in the calling process. The meaning of the parameters depends
+ * on Message.
+ */
+XAM_IMPORT(0x1F4) HRESULT XMsgInProcessCall(DWORD App, DWORD Message, PDWORD Parameter1, PDWORD Parameter2);
+
+/**
+ * Calls a XAM application synchronously. The dashboard reports a language change with
+ * App 0xFE, Message 0x8000000D and no buffer.
+ */
+XAM_IMPORT(0x1F6) HRESULT XMsgSystemProcessCall(DWORD App, DWORD Message, PVOID Buffer, DWORD BufferLength);
+
+/**
+ * Starts an I/O request to a XAM application. Completes through Overlapped when not NULL.
+ *
+ * With Overlapped, the result is the Win32 code ERROR_IO_PENDING (997) and not an
+ * HRESULT, so it reads as a success with facility 0. The outcome of the request is in
+ * Overlapped.
+ */
+XAM_IMPORT(0x1F7) HRESULT XMsgStartIORequest(
+ DWORD App,
+ DWORD Message,
+ PXOVERLAPPED Overlapped,
+ PVOID Buffer,
+ DWORD BufferLength);
+
+/**
+ * Cancels the request of Overlapped. With Wait, returns after the request completed.
+ * The 2.0.6717 dashboard always waits and does not use the result.
+ */
+XAM_IMPORT(0x1F8) DWORD XMsgCancelIORequest(PXOVERLAPPED Overlapped, BOOL Wait);
+
+/**
+ * Starts an I/O request to a XAM application with an extra parameter block. The 2.0.6717
+ * dashboard queries a video license with App 0xFA, Message 0x7005D, a 16-byte request and
+ * Extended pointing to the words 0x20080002 and 0. Without Overlapped the call completes
+ * before it returns; the dashboard then also takes a nonzero thread error as failure.
+ */
+XAM_IMPORT(0x1FC) HRESULT XMsgStartIORequestEx(
+ DWORD App,
+ DWORD Message,
+ PXOVERLAPPED Overlapped,
+ PVOID Buffer,
+ DWORD BufferLength,
+ PDWORD Extended);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/system.h b/platform/xex/sdk/include/xbox360/xam/system.h
new file mode 100644
index 0000000..a990fc8
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/system.h
@@ -0,0 +1,368 @@
+/*
+ * XAM loader, system, Win32-style, automation, media and play timer imports.
+ */
+
+#ifndef XBOX360_XAM_SYSTEM_H
+#define XBOX360_XAM_SYSTEM_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+#include <xbox360/xam/xamdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Wait time without limit. */
+#define INFINITE 0xFFFFFFFF
+
+/* Results of WaitForSingleObject. */
+#define WAIT_OBJECT_0 0x00000000
+#define WAIT_ABANDONED_0 0x00000080
+#define WAIT_TIMEOUT 0x00000102
+#define WAIT_FAILED 0xFFFFFFFF
+
+/* Flags of RtlAllocateHeap and RtlFreeHeap. */
+#define HEAP_ZERO_MEMORY 0x00000008
+
+/* Options of DuplicateHandle. */
+#define DUPLICATE_CLOSE_SOURCE 0x00000001
+#define DUPLICATE_SAME_ACCESS 0x00000002
+
+/* CreateFileA result of a failed call. */
+#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
+
+/* Creation disposition of CreateFileA. */
+typedef enum _CREATION_DISPOSITION {
+ CREATE_NEW = 1,
+ CREATE_ALWAYS = 2,
+ OPEN_EXISTING = 3,
+ OPEN_ALWAYS = 4,
+ TRUNCATE_EXISTING = 5
+} CREATION_DISPOSITION;
+
+/* Date and time, as GetLocalTime stores it. */
+typedef struct _SYSTEMTIME {
+ WORD wYear;
+ WORD wMonth;
+ WORD wDayOfWeek;
+ WORD wDay;
+ WORD wHour;
+ WORD wMinute;
+ WORD wSecond;
+ WORD wMilliseconds;
+} SYSTEMTIME, *PSYSTEMTIME;
+
+C_ASSERT(sizeof(SYSTEMTIME) == 0x10);
+
+/* Video mode, filled by XGetVideoMode. Layout from Xenia. */
+typedef struct _XVIDEO_MODE {
+ DWORD dwDisplayWidth;
+ DWORD dwDisplayHeight;
+ /* Nonzero for an interlaced mode. */
+ BOOL fIsInterlaced;
+ /* Nonzero for a 16:9 display. */
+ BOOL fIsWideScreen;
+ /* Nonzero for a high definition mode. */
+ BOOL fIsHiDef;
+ FLOAT RefreshRate;
+ DWORD VideoStandard;
+ DWORD Reserved[5];
+} XVIDEO_MODE, *PXVIDEO_MODE;
+
+C_ASSERT(sizeof(XVIDEO_MODE) == 0x30);
+C_ASSERT(__builtin_offsetof(XVIDEO_MODE, RefreshRate) == 0x14);
+
+/* Record of XamPlayTimerGetData and XamPlayTimerSetData. */
+typedef struct _XPLAY_TIMER_DATA {
+ /* Next reset, written by XamPlayTimerGetNextResetDate. */
+ DWORD NextReset[2];
+ /* Period flags: 0 is off, 2 daily, 4 weekly. */
+ DWORD Period;
+ /* Play time allowed per period, in milliseconds. */
+ DWORD Allowance;
+ /* Play time remaining in the period, in milliseconds. */
+ DWORD Remaining;
+} XPLAY_TIMER_DATA, *PXPLAY_TIMER_DATA;
+
+C_ASSERT(sizeof(XPLAY_TIMER_DATA) == 0x14);
+C_ASSERT(__builtin_offsetof(XPLAY_TIMER_DATA, Remaining) == 0x10);
+
+/** Applies the configured inactivity timeout. */
+XAM_IMPORT(0x1A2) DWORD XamSetInactivityTimeFromConfig(DWORD Apply);
+
+/**
+ * Writes the media type of the disc in the console drive to MediaType and its title id to
+ * TitleId. The 2.0.6717 dashboard reads media 1 as an Xbox 360 game and -1 as unknown.
+ */
+XAM_IMPORT(0x1A3) VOID XamLoaderGetMediaInfo(PDWORD MediaType, PDWORD TitleId);
+
+/**
+ * Ends the running title and launches the executable at Path (NULL or a NUL-terminated path)
+ * with Flags. A NULL Path returns to the dashboard.
+ * Call it only from a thread of the title process: XAM then ends the title and the calling
+ * thread with it.
+ */
+XAM_IMPORT(0x1A4) DECLSPEC_NORETURN VOID XamLoaderLaunchTitle(PCSTR Path, DWORD Flags);
+
+/**
+ * Launches the executable at Path with Flags, as XamLoaderLaunchTitle does. The purpose of
+ * Second and Third (NUL-terminated strings or NULL) is not known; the 2.0.6717 dashboard
+ * passes NULL for all three strings to launch the disc.
+ */
+XAM_IMPORT(0x1A5) VOID XamLoaderLaunchTitleEx(PCSTR Path, PCSTR Second, PCSTR Third, DWORD Flags);
+
+/**
+ * Sets the launch data the next title reads with XamLoaderGetLaunchData. Returns a Win32
+ * error code.
+ */
+XAM_IMPORT(0x1A6) DWORD XamLoaderSetLaunchData(PCVOID Data, DWORD Size);
+
+/**
+ * Copies the launch data the previous title set to Buffer, at most Size bytes.
+ * Returns a Win32 error code; nonzero when no launch data is set.
+ */
+XAM_IMPORT(0x1A8) DWORD XamLoaderGetLaunchData(PVOID Buffer, DWORD Size);
+
+/**
+ * Ends the running title.
+ * Call it only from a thread of the title process: XAM then ends the title and the calling
+ * thread with it.
+ */
+XAM_IMPORT(0x1A9) DECLSPEC_NORETURN VOID XamLoaderTerminateTitle(VOID);
+
+/** Returns the optical drive tray state. */
+XAM_IMPORT(0x1AA) DWORD XamLoaderGetDvdTrayState(VOID);
+
+/** Returns 1 when TitleId is a system title id. */
+XAM_IMPORT(0x1BB) BOOLEAN XamIsSystemTitleId(DWORD TitleId);
+
+/** Returns the title id of the title that ran before the current one, or 0. */
+XAM_IMPORT(0x1BE) DWORD XamLoaderGetPriorTitleId(VOID);
+
+/** Returns nonzero when TitleId is an original Xbox title. */
+XAM_IMPORT(0x1BF) BOOLEAN XamIsXbox1TitleId(DWORD TitleId);
+
+/**
+ * Gives the PNG of the default gamer picture: stores its address at Image and its length at
+ * Size. The 2.0.6717 dashboard does not read the result.
+ */
+XAM_IMPORT(0x1C5) DWORD XamGetDefaultSystemImage(PCBYTE *Image, PDWORD Size);
+
+/**
+ * Writes the NUL-terminated path of the Windows Connect Now configuration file found on a
+ * storage device to Path, at most Capacity bytes. Returns ERROR_FILE_NOT_FOUND when no device
+ * holds one, or another Win32 error code.
+ */
+XAM_IMPORT(0x1C6) DWORD XamGetWCNConfigFile(PSTR Path, DWORD Capacity);
+
+/** Mutes (nonzero) or unmutes the sounds of the system UI. */
+XAM_IMPORT(0x1CA) VOID XamMuteSound(DWORD Mute);
+
+/**
+ * Sets the dashboard context XAM reports to the system UI. The 2.0.6717 dashboard passes 3
+ * when initial setup starts and 0 when it completes.
+ */
+XAM_IMPORT(0x1CC) VOID XamSetDashContext(DWORD Context);
+
+/** Returns the title id of the running title, 0 for none. */
+XAM_IMPORT(0x1CF) DWORD XamGetCurrentTitleId(VOID);
+
+/**
+ * Returns the Win32 result of the request of Overlapped, or ERROR_IO_INCOMPLETE while it runs
+ * and Wait is FALSE. Stores the result length at Length when not NULL.
+ */
+XAM_IMPORT(0x1FB) DWORD XamGetOverlappedResult(PXOVERLAPPED Overlapped, PDWORD Length, BOOL Wait);
+
+/**
+ * Unloads the XAM applications stacked above the dashboard. The 2.0.6717 dashboard passes 0
+ * for Flags; the result is not used.
+ */
+XAM_IMPORT(0x246) DWORD XamAppUnloadStack(DWORD Flags);
+
+/**
+ * Creates an enumeration handle served by XAM application App: XamEnumerate on it sends
+ * EnumerateMessage, closing it sends CloseMessage. The handle carries a private block of
+ * PrivateSize bytes for the application. The 2.0.6717 dashboard passes user -1 and Flags
+ * 0x20000001 for its media enumerations. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x24E) DWORD XamCreateEnumeratorHandle(DWORD UserIndex, DWORD App, DWORD EnumerateMessage,
+ DWORD CloseMessage, DWORD PrivateSize, DWORD Count, DWORD Flags, PHANDLE Handle);
+
+/**
+ * Stores the object of the private block of an enumeration Handle at Object, with a reference
+ * the caller releases with ObDereferenceObject. The 2.0.6717 dashboard zeroes PrivateSize bytes
+ * from the object's +0x18, passes that address in its start request and does not read the
+ * result, so none is declared.
+ */
+XAM_IMPORT(0x24F) VOID XamGetPrivateEnumStructureFromHandle(HANDLE Handle, PVOID *Object);
+
+/**
+ * Reads the next records of an enumeration into Buffer. Stores the record count at Items when
+ * not NULL. Returns a Win32 error code: ERROR_NO_MORE_FILES after the last record, or
+ * ERROR_IO_PENDING with an Overlapped, which then holds the count in its length.
+ */
+XAM_IMPORT(0x250) DWORD XamEnumerate(HANDLE Handle, DWORD Flags, PVOID Buffer, DWORD Size, PDWORD Items,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Unloads the system application App. The 2.0.6717 dashboard passes app 0xF6 with Unknown 1
+ * before a format, before it deletes the package named IptvClient, and in the IPTV client
+ * download (0x9228B9A0); the meaning of Unknown is not known and the result is not read.
+ */
+XAM_IMPORT(0x252) DWORD XamUnloadSysApp(DWORD App, DWORD Unknown);
+
+/** Returns the system software version. */
+XAM_IMPORT(0x282) DWORD XamGetSystemVersion(VOID);
+
+/**
+ * Writes the cached name of TitleId as NUL-terminated UTF-16 to Buffer, at most *Length units.
+ * Returns a Win32 error code.
+ */
+XAM_IMPORT(0x2B6) DWORD XamGetCachedTitleName(DWORD TitleId, PWSTR Buffer, PDWORD Length);
+
+/**
+ * Clears XAM's content and title caches. The 2.0.6717 dashboard passes zero during storage
+ * maintenance and ignores the result.
+ */
+XAM_IMPORT(0x2B7) DWORD XamCacheReset(DWORD Flags);
+
+/** Returns nonzero when the running system UI was opened by a title. */
+XAM_IMPORT(0x2EB) DWORD XamIsSysUiInvokedByTitle(VOID);
+
+/** Returns nonzero while a system UI is shown. */
+XAM_IMPORT(0x2EC) BOOLEAN XamIsUIActive(VOID);
+
+/**
+ * Writes the locator of the system resource Name to Locator, at most Capacity UTF-16 units:
+ * `section://<xam.xex module handle>,shrdres#<name>`, or a `memory://` locator for eight legacy
+ * names. In system software 2.0.21256.0 it asserts (`twi 31`) unless the running title is one
+ * of two system titles, which halts other titles under the debug monitor.
+ */
+XAM_IMPORT(0x31C) HRESULT XamBuildLegacySystemResourceLocator(PCWSTR Name, PWSTR Locator, DWORD Capacity);
+
+/** Returns the audio flags (XConfig user setting 0xB). */
+XAM_IMPORT(0x3CA) DWORD XGetAudioFlags(VOID);
+
+/** Returns the AV pack value. */
+XAM_IMPORT(0x3CB) DWORD XGetAVPack(VOID);
+
+/** Returns the game region of the console (XConfig). */
+XAM_IMPORT(0x3CC) DWORD XGetGameRegion(VOID);
+
+/** Stores the current video mode. */
+XAM_IMPORT(0x3D1) VOID XGetVideoMode(PXVIDEO_MODE VideoMode);
+
+/** Returns the console language. */
+XAM_IMPORT(0x3D2) DWORD XamGetLanguage(VOID);
+
+/** Binds an automation controller to a user slot. */
+XAM_IMPORT(0x3D5) DWORD XAutomationpBindController(DWORD UserIndex);
+
+/** Removes the automation controller from a user slot. */
+XAM_IMPORT(0x3D6) DWORD XAutomationpUnbindController(DWORD UserIndex);
+
+/** Sends a Guide button press from the automation controller of a user slot. */
+XAM_IMPORT(0x3D7) DWORD XAutomationpInputXenonButton(DWORD UserIndex);
+
+/** Allocates from a heap. Returns the address or NULL. */
+XAM_IMPORT(0x3FC) PVOID RtlAllocateHeap(HANDLE HeapHandle, DWORD Flags, SIZE_T Size);
+
+/** Frees a heap block. */
+XAM_IMPORT(0x3FF) BOOL RtlFreeHeap(HANDLE HeapHandle, DWORD Flags, PVOID BaseAddress);
+
+/** Returns the ID of the current thread. */
+XAM_IMPORT(0x410) DWORD GetCurrentThreadId(VOID);
+
+/** Waits on a handle for Milliseconds, or without limit for INFINITE. */
+XAM_IMPORT(0x425) DWORD WaitForSingleObject(HANDLE Handle, DWORD Milliseconds);
+
+/** Sets an event to not signaled. */
+XAM_IMPORT(0x42B) BOOL ResetEvent(HANDLE Event);
+
+/** Stores the performance counter. */
+XAM_IMPORT(0x42F) BOOL QueryPerformanceCounter(PLARGE_INTEGER PerformanceCount);
+
+/** Stores the performance counter frequency. */
+XAM_IMPORT(0x430) BOOL QueryPerformanceFrequency(PLARGE_INTEGER Frequency);
+
+/** Decrements the suspend count of a thread. Returns the previous count. */
+XAM_IMPORT(0x43D) DWORD ResumeThread(HANDLE Thread);
+
+/** Stores the local time. */
+XAM_IMPORT(0x444) VOID GetLocalTime(PSYSTEMTIME SystemTime);
+
+/** Creates an event. Returns the handle or NULL. */
+XAM_IMPORT(0x446) HANDLE CreateEventA(PVOID EventAttributes, BOOL ManualReset, BOOL InitialState, PCSTR Name);
+
+/**
+ * Creates or opens a file. FileName is a NUL-terminated path. Returns the handle or
+ * INVALID_HANDLE_VALUE.
+ */
+XAM_IMPORT(0x447) HANDLE CreateFileA(PCSTR FileName, ACCESS_MASK DesiredAccess, DWORD ShareMode,
+ PVOID SecurityAttributes, CREATION_DISPOSITION CreationDisposition, DWORD FlagsAndAttributes,
+ HANDLE TemplateFile);
+
+/** Duplicates a handle. */
+XAM_IMPORT(0x45B) BOOL DuplicateHandle(HANDLE SourceProcessHandle, HANDLE SourceHandle,
+ HANDLE TargetProcessHandle, PHANDLE TargetHandle, ACCESS_MASK DesiredAccess, BOOL InheritHandle,
+ DWORD Options);
+
+/** Removes the IPTV service registration. */
+XAM_IMPORT(0x517) HRESULT XamIptvUninstall(VOID);
+
+/**
+ * Stores the DVR storage in megabytes: the space given to recordings, the space they use, and
+ * the largest allocation the service accepts.
+ */
+XAM_IMPORT(0x518) HRESULT XamGetDvrStorage(PDWORD Allocated, PDWORD Used, PDWORD Maximum);
+
+/**
+ * Sets the space given to recordings, in megabytes. Completes through Overlapped; the 2.0.6717
+ * dashboard treats a negative result as a failure.
+ */
+XAM_IMPORT(0x519) HRESULT XamSetDvrStorage(DWORD Allocated, PXOVERLAPPED Overlapped);
+
+/** Stores a pointer to the NUL-terminated UTF-16 name of the IPTV service at Name. */
+XAM_IMPORT(0x51A) HRESULT XamIptvGetServiceName(PCWSTR *Name);
+
+/** Returns the default heap of the process. */
+XAM_IMPORT(0x7D2) HANDLE GetProcessHeap(VOID);
+
+/**
+ * Copies the background download queue of UserIndex to Items, 0x250-byte records with the
+ * package path at +0x138. Count holds the capacity in records on entry and the number copied
+ * on return. The 2.0.6717 dashboard passes a capacity of 6 and reads only Count.
+ */
+XAM_IMPORT(0x9C7) DWORD XamBackgroundDownloadGetItems(DWORD UserIndex, PVOID Items, PDWORD Count);
+
+/** Copies the play timer record to Data. The 2.0.6717 dashboard does not read the result. */
+XAM_IMPORT(0xA5A) VOID XamPlayTimerGetData(PXPLAY_TIMER_DATA Data);
+
+/**
+ * Replaces the play timer record with Data. The 2.0.6717 dashboard passes 1 for Save and does
+ * not read the result.
+ */
+XAM_IMPORT(0xA5B) VOID XamPlayTimerSetData(const XPLAY_TIMER_DATA *Data, DWORD Save);
+
+/** Resumes the play timer. The 2.0.6717 dashboard passes 1. */
+XAM_IMPORT(0xA5C) VOID XamPlayTimerResume(DWORD Resume);
+
+/** Suspends the play timer. */
+XAM_IMPORT(0xA5D) VOID XamPlayTimerSuspend(VOID);
+
+/** Whether the play timer is counting. */
+XAM_IMPORT(0xA5E) BOOLEAN XamPlayTimerIsRunning(VOID);
+
+/** Whether a play timer period is set. */
+XAM_IMPORT(0xA5F) BOOLEAN XamPlayTimerIsEnabled(VOID);
+
+/** Writes the next reset of Period to Data->NextReset. */
+XAM_IMPORT(0xA60) VOID XamPlayTimerGetNextResetDate(DWORD Period, PXPLAY_TIMER_DATA Data);
+
+/** Posts the play timer notification. */
+XAM_IMPORT(0xA64) VOID XamPlayTimerForceNotification(VOID);
+
+/** The security violations the system has detected, as a 64-bit value. */
+XAM_IMPORT(0xAF3) ULONGLONG XamGetSecurityViolationsDetected(VOID);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/ui.h b/platform/xex/sdk/include/xbox360/xam/ui.h
new file mode 100644
index 0000000..8aaa4ef
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/ui.h
@@ -0,0 +1,177 @@
+/*
+ * XAM system UI: sign-in, keyboard, message box, device selector, gamer
+ * cards, marketplace and other system screens.
+ */
+
+#ifndef XBOX360_XAM_UI_H
+#define XBOX360_XAM_UI_H
+
+#include <xbox360/xam/xamdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Icon of a message box, in the low four bits of the XamShowMessageBoxUI flags. */
+typedef enum _XMB_ICON {
+ XMB_NOICON = 0,
+ XMB_ERRORICON = 1,
+ XMB_WARNINGICON = 2,
+ XMB_ALERTICON = 3,
+} XMB_ICON;
+
+/* The user enters a four-key passcode, returned in MESSAGEBOX_RESULT. The box takes no buttons. */
+#define XMB_PASSCODEMODE 0x00010000
+/* XAM compares the entered passcode with the one the result block holds. */
+#define XMB_VERIFYPASSCODEMODE 0x00020000
+
+/* The index of the chosen button, or the four virtual key codes of a passcode. */
+typedef union _MESSAGEBOX_RESULT {
+ DWORD dwButtonPressed;
+ WORD rgwPasscode[4];
+} MESSAGEBOX_RESULT, *PMESSAGEBOX_RESULT;
+
+C_ASSERT(sizeof(MESSAGEBOX_RESULT) == 8);
+
+/**
+ * Opens the sign-in UI with Panes user panes. Returns a Win32 error code; the UI does
+ * not report when it closes.
+ */
+XAM_IMPORT(0x2BC) DWORD XamShowSigninUI(DWORD Panes, DWORD Flags);
+
+/**
+ * XamShowSigninUI for the controller UserIndex. Returns a Win32 error code; the UI
+ * does not report when it closes.
+ */
+XAM_IMPORT(0x2BE) DWORD XamShowSigninUIp(DWORD UserIndex, DWORD Panes, DWORD Flags);
+
+/**
+ * Shows the virtual keyboard. DefaultText, Title and Description are NUL-terminated
+ * UTF-16 strings. Completes through Overlapped and writes the NUL-terminated text to
+ * Buffer, at most Length units. Returns ERROR_IO_PENDING when the keyboard is shown,
+ * or another Win32 error code.
+ */
+XAM_IMPORT(0x2C1) DWORD XamShowKeyboardUI(
+ DWORD UserIndex,
+ DWORD Flags,
+ PCWSTR DefaultText,
+ PCWSTR Title,
+ PCWSTR Description,
+ PWSTR Buffer,
+ DWORD Length,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Opens the gamer card of the profile signed in on UserIndex. Returns a Win32 error code.
+ * An index above 3 reaches RtlRip.
+ */
+XAM_IMPORT(0x2C4) DWORD XamShowGamerCardUI(DWORD UserIndex);
+
+/**
+ * Opens the achievements of TitleId for UserIndex. Returns a Win32 error code. An index
+ * above 3 reaches RtlRip.
+ */
+XAM_IMPORT(0x2C5) DWORD XamShowAchievementsUI(DWORD UserIndex, DWORD TitleId);
+
+/**
+ * Shows a message box with up to three buttons. Title, Text and each entry of Buttons are
+ * NUL-terminated UTF-16 strings. Completes through Overlapped and stores the result at
+ * Result; dwButtonPressed is the chosen button index. Returns ERROR_IO_PENDING when the
+ * box is shown, or another Win32 error code.
+ */
+XAM_IMPORT(0x2CA) DWORD XamShowMessageBoxUI(
+ DWORD UserIndex,
+ PCWSTR Title,
+ PCWSTR Text,
+ DWORD ButtonCount,
+ const PCWSTR *Buttons,
+ DWORD FocusButton,
+ DWORD Flags,
+ PMESSAGEBOX_RESULT Result,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Shows the storage device selector for content of type ContentType (0 for any) that
+ * needs BytesRequested free bytes (0 for any). DeviceId holds the device selected
+ * first and receives the chosen device id. Completes through Overlapped. Returns
+ * ERROR_IO_PENDING when the selector is shown, or another Win32 error code.
+ */
+XAM_IMPORT(0x2CB) DWORD XamShowDeviceSelectorUI(
+ DWORD UserIndex,
+ DWORD ContentType,
+ DWORD Flags,
+ ULONGLONG BytesRequested,
+ PDWORD DeviceId,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Opens the profile creation UI for UserIndex. In system software 2.0.21256.0 the export
+ * passes Unknown on to XamShowCreateProfileUIEx, which stores it in the request and
+ * selects one of two modes by it (1, 0xB and 0xE against any other value); the 2.0.6717.0
+ * export takes only UserIndex and stores 0 there. Returns a Win32 error code. An index
+ * above 3 reaches RtlRip.
+ */
+XAM_IMPORT(0x2CF) DWORD XamShowCreateProfileUI(DWORD UserIndex, DWORD Unknown);
+
+/**
+ * Opens the played games list of UserIndex. The 2.0.6717 dashboard passes 0 for
+ * Unknown. Returns a Win32 error code. An index above 3 reaches RtlRip.
+ */
+XAM_IMPORT(0x2D0) DWORD XamShowGamesUI(DWORD UserIndex, DWORD Unknown);
+
+/**
+ * Opens the Xbox LIVE signup UI for UserIndex. The 2.0.6717 dashboard passes 1 to
+ * recover an existing account and 0 to join. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x2D1) DWORD XamShowLiveSignupUI(DWORD UserIndex, DWORD Mode);
+
+/**
+ * Opens the gamer card of Xuid for UserIndex. A nonzero Flags sets bit 0x80 of the
+ * request; the 2.0.6717 dashboard passes 0. Returns a Win32 error code. An index above 3
+ * reaches RtlRip.
+ */
+XAM_IMPORT(0x2D5) DWORD XamShowGamerCardUIForXUID(DWORD UserIndex, XUID Xuid, DWORD Flags);
+
+/**
+ * Opens the details of AchievementId of TitleId for UserIndex. Returns a Win32 error
+ * code. An index above 3 reaches RtlRip.
+ */
+XAM_IMPORT(0x2E0) DWORD XamShowAchievementDetailsUI(DWORD UserIndex, DWORD TitleId, DWORD AchievementId);
+
+/**
+ * In system software 2.0.6717.0 opens the theme picker for UserIndex, copying 0x200 bytes
+ * from InitialSelection when it is not NULL. In 2.0.21256.0 it opens no UI: it writes
+ * 0x144 bytes of the selection to <drive>:\ThematicSkin and sends notification
+ * 0x8000000F, and a NULL InitialSelection reaches RtlRip. The purpose of Unknown is
+ * not known.
+ */
+XAM_IMPORT(0x2E1) DWORD XamShowPersonalizationUI(DWORD UserIndex, PCBYTE InitialSelection, DWORD Unknown);
+
+/**
+ * Opens the marketplace at Entry for UserIndex, with the offer OfferId and the title
+ * TitleId. The 2.0.6717 dashboard passes 0xFFFFFFFF, 0xFFFFFFFF, 0 and 0 for the four
+ * unknown arguments. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x2E8) DWORD XamShowMarketplaceUIEx(
+ DWORD UserIndex,
+ DWORD Entry,
+ ULONGLONG OfferId,
+ DWORD Unknown1,
+ DWORD Unknown2,
+ DWORD Unknown3,
+ DWORD Unknown4,
+ DWORD TitleId);
+
+/**
+ * Opens the Xbox LIVE upsell UI for UserIndex. XamShowLiveUpsellUI (0x2D7) takes no
+ * arguments and calls this export with 0. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x300) DWORD XamShowLiveUpsellUIEx(DWORD UserIndex);
+
+/**
+ * Opens the join session in progress UI for the player Xuid for UserIndex. Returns a
+ * Win32 error code. An index above 3 reaches RtlRip.
+ */
+XAM_IMPORT(0x301) DWORD XamShowJoinSessionInProgressUI(DWORD UserIndex, XUID Xuid);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/user.h b/platform/xex/sdk/include/xbox360/xam/user.h
new file mode 100644
index 0000000..a1a8287
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/user.h
@@ -0,0 +1,264 @@
+/*
+ * XAM users and profiles: sign-in, XUIDs, profile settings, profiles on
+ * storage, achievements and tiles.
+ */
+
+#ifndef XBOX360_XAM_USER_H
+#define XBOX360_XAM_USER_H
+
+#include <xbox360/xam/xamdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* A user slot, or a choice the export makes. UserIndex arguments take these values. */
+typedef enum _XUSER_INDEX {
+ XUSER_INDEX_0 = 0,
+ XUSER_INDEX_1 = 1,
+ XUSER_INDEX_2 = 2,
+ XUSER_INDEX_3 = 3,
+ /* No user, for operations on behalf of the title itself. */
+ XUSER_INDEX_NONE = 0xFE,
+ /* Any signed-in user or connected controller, as the export decides. */
+ XUSER_INDEX_ANY = 0xFF,
+} XUSER_INDEX;
+
+/* Sign-in state of a user slot. */
+typedef enum _XUSER_SIGNIN_STATE {
+ eXUserSigninState_NotSignedIn = 0,
+ eXUserSigninState_SignedInLocally = 1,
+ eXUserSigninState_SignedInToLive = 2,
+} XUSER_SIGNIN_STATE;
+
+/* Data type of a NUL-terminated UTF-16 string in XUSER_DATA. */
+#define XUSER_DATA_TYPE_UNICODE 4
+
+/*
+ * A typed setting value. The type byte is at +0 and the value at +8; a
+ * string is its byte length at +8 and its address at +0xC.
+ */
+typedef struct _XUSER_DATA {
+ BYTE type;
+ BYTE Reserved[7];
+ union {
+ LONG nData;
+ struct {
+ DWORD cbData;
+ PWSTR pwszData;
+ } string;
+ DWORD Value[2];
+ };
+} XUSER_DATA, *PXUSER_DATA;
+
+C_ASSERT(sizeof(XUSER_DATA) == 0x10);
+C_ASSERT(__builtin_offsetof(XUSER_DATA, string) == 8);
+
+/*
+ * One profile of XamProfileEnumerate. The first 8 bytes are the offline
+ * XUID; the account data after it is not decoded here.
+ */
+typedef struct _XPROFILE_ENUM_RESULT {
+ XUID xuidOffline;
+ BYTE Account[0x180];
+} XPROFILE_ENUM_RESULT, *PXPROFILE_ENUM_RESULT;
+
+C_ASSERT(sizeof(XPROFILE_ENUM_RESULT) == 0x188);
+
+/**
+ * Stores the XUID of a user slot at Xuid. Flags selects the XUID kinds accepted
+ * (the 2.0.6717 dashboard passes 1, 3, 4 and 7). Fails when the slot has no such XUID.
+ */
+XAM_IMPORT(0x20A) HRESULT XamUserGetXUID(DWORD UserIndex, DWORD Flags, PXUID Xuid);
+
+/**
+ * Signs in the users of the four XUIDs at Xuids, one per user slot; zero XUIDs sign
+ * those slots out. XAM copies the XUIDs during the call. Returns ERROR_IO_PENDING (a
+ * success value as an HRESULT) with an Overlapped.
+ */
+XAM_IMPORT(0x20B) HRESULT XamUserLogon(const XUID *Xuids, DWORD Flags, PXOVERLAPPED Overlapped);
+
+/**
+ * Writes the gamertag of a signed-in user slot to Buffer as NUL-terminated UTF-16,
+ * at most Length units. The 2.0.6717 dashboard passes 16 units.
+ */
+XAM_IMPORT(0x20C) HRESULT XamUserGetGamerTag(DWORD UserIndex, PWSTR Buffer, DWORD Length);
+
+/** Returns the sign-in state of a user slot. */
+XAM_IMPORT(0x210) XUSER_SIGNIN_STATE XamUserGetSigninState(DWORD UserIndex);
+
+/**
+ * Stores at UserIndex the user slot the profile Xuid is signed in on. Flags
+ * selects the XUID kinds compared, as for XamUserGetXUID; the 2.0.6717 dashboard's
+ * Memory area passes 1. Fails when no slot has the profile.
+ */
+XAM_IMPORT(0x211) HRESULT XamUserGetIndexFromXUID(XUID Xuid, DWORD Flags, PDWORD UserIndex);
+
+/**
+ * Reads the profile settings SettingIds (SettingIdCount entries) of TitleId for UserIndex,
+ * or of the XuidCount profiles at Xuids. Without Buffer, stores the size needed at
+ * BufferSize. Returns a Win32 error code, or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x219) DWORD XamUserReadProfileSettings(
+ DWORD TitleId,
+ DWORD UserIndex,
+ DWORD XuidCount,
+ const XUID *Xuids,
+ DWORD SettingIdCount,
+ const DWORD *SettingIds,
+ PDWORD BufferSize,
+ PBYTE Buffer,
+ PXOVERLAPPED Overlapped);
+
+/** Returns the Xbox LIVE membership type of UserIndex in the low byte. */
+XAM_IMPORT(0x21B) DWORD XamUserGetMembershipType(DWORD UserIndex);
+
+/**
+ * Processes the queued Xbox LIVE logons. Returns ERROR_IO_PENDING (a success value as an
+ * HRESULT) with an Overlapped.
+ */
+XAM_IMPORT(0x220) HRESULT XamUserFlushLogonQueue(PXOVERLAPPED Overlapped);
+
+/** Returns nonzero when the profile of a user slot has an Xbox LIVE account. */
+XAM_IMPORT(0x221) BOOLEAN XamUserIsOnlineEnabled(DWORD UserIndex);
+
+/**
+ * Starts the creation of an offline profile on the device DeviceId points to and stores
+ * the creation handle. Account is a zeroed 0x17C-byte XAMACCOUNTINFO with the
+ * big-endian UTF-16 gamertag (16 units) at +8; Block is a zeroed 0x8F0-byte block. The
+ * 2.0.6717 dashboard passes 1 for Flags and 0 for Reserved0, Reserved1 and Reserved2.
+ * XAM uses the buffers until the creation completes.
+ */
+XAM_IMPORT(0x230) HRESULT XamProfileCreate(
+ DWORD Flags,
+ const DWORD *DeviceId,
+ DWORD Reserved0,
+ PBYTE Account,
+ PBYTE Block,
+ DWORD Reserved1,
+ DWORD Reserved2,
+ PHANDLE Handle);
+
+/**
+ * Opens an enumeration of the profiles on DeviceId (0 for all devices) and stores its handle.
+ * Close the handle with NtClose. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x231) DWORD XamProfileCreateEnumerator(DWORD DeviceId, PHANDLE Handle);
+
+/**
+ * Stores the next profile of an enumeration at Result. Returns a Win32 error code;
+ * nonzero once no profile remains.
+ */
+XAM_IMPORT(0x232) DWORD XamProfileEnumerate(HANDLE Handle, DWORD Flags, PXPROFILE_ENUM_RESULT Result, PXOVERLAPPED Overlapped);
+
+/**
+ * Deletes the profile Xuid. The 2.0.6717 dashboard passes 0 for Unknown, whose meaning
+ * is not known, and calls it without an overlapped block. Returns an HRESULT.
+ */
+XAM_IMPORT(0x233) HRESULT XamProfileDelete(DWORD Unknown, XUID Xuid);
+
+/**
+ * Stores the XUID of the profile a XamProfileCreate handle creates. Returns
+ * E_PENDING while the creation runs.
+ */
+XAM_IMPORT(0x234) HRESULT XamProfileGetCreationStatus(HANDLE Handle, PXUID Xuid);
+
+/**
+ * Mounts the dashboard settings of the profile Xuid as the drive MountName
+ * (NUL-terminated ASCII, such as DASHUSER). The 2.0.6717 dashboard passes 0 and NULL
+ * for Flags and ContentData. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x237) DWORD XamProfileOpen(XUID Xuid, PCSTR MountName, DWORD Flags, PBYTE ContentData);
+
+/** Unmounts a drive that XamProfileOpen mounted. Returns a Win32 error code. */
+XAM_IMPORT(0x238) DWORD XamProfileClose(PCSTR MountName);
+
+/**
+ * Reads the 0x17C-byte account record of the profile Xuid from its package on
+ * DeviceId into Account; the gamertag is NUL-terminated UTF-16 at +0x08. Returns an
+ * HRESULT.
+ */
+XAM_IMPORT(0x23A) HRESULT XamProfileLoadAccountInfo(DWORD DeviceId, XUID Xuid, PBYTE Account);
+
+/**
+ * Opens an enumeration of the achievements of TitleId for UserIndex or Xuid (0 for the
+ * user). Stores the buffer size for Count records at BufferSize. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x2EE) DWORD XamUserCreateAchievementEnumerator(
+ DWORD TitleId,
+ DWORD UserIndex,
+ XUID Xuid,
+ DWORD DetailFlags,
+ DWORD StartingIndex,
+ DWORD Count,
+ PDWORD BufferSize,
+ PHANDLE Handle);
+
+/**
+ * Reads a tile PNG into Buffer. Without Buffer, stores the size needed at BufferSize.
+ * Returns a Win32 error code, or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x2EF) DWORD XamReadTile(
+ DWORD TileType,
+ DWORD TitleId,
+ ULONGLONG TileId,
+ DWORD UserIndex,
+ PBYTE Buffer,
+ PDWORD BufferSize,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Writes the gamer picture of TitleId with the key words KeyHigh and KeyLow to the
+ * profile signed in on UserIndex. The 2.0.6717 dashboard passes 0 for Reserved.
+ * Returns a Win32 error code, ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x2F0) DWORD XamWriteGamerTile(
+ DWORD UserIndex,
+ DWORD TitleId,
+ DWORD KeyHigh,
+ DWORD KeyLow,
+ DWORD Reserved,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Opens an enumeration of the titles UserIndex or Xuid (0 for the user) has played.
+ * Stores the buffer size for Count records at BufferSize. Returns a Win32 error code.
+ */
+XAM_IMPORT(0x2F3) DWORD XamUserCreateTitlesPlayedEnumerator(
+ DWORD TitleId,
+ DWORD UserIndex,
+ XUID Xuid,
+ DWORD StartingIndex,
+ DWORD Count,
+ PDWORD BufferSize,
+ PHANDLE Handle);
+
+/**
+ * Reads a tile PNG into Buffer of *BufferSize bytes and stores the length at BufferSize.
+ * Key is the picture key setting for tile type 0xC; the 2.0.6717 dashboard passes
+ * HasKey 0 with it. Returns a Win32 error code, or ERROR_IO_PENDING with an Overlapped.
+ */
+XAM_IMPORT(0x2FC) DWORD XamReadTileEx(
+ DWORD TileType,
+ DWORD TitleId,
+ ULONGLONG TileId,
+ DWORD UserIndex,
+ DWORD HasKey,
+ const XUSER_DATA *Key,
+ PBYTE Buffer,
+ PDWORD BufferSize,
+ PXOVERLAPPED Overlapped);
+
+/**
+ * Writes the time of the local FILETIME Time for UserIndex as NUL-terminated UTF-16,
+ * at most Length units. The 2.0.6717 dashboard does not read the result.
+ */
+XAM_IMPORT(0x1E7) VOID XamFormatTimeString(DWORD UserIndex, ULONGLONG Time, PWSTR Buffer, DWORD Length);
+
+/**
+ * Writes the date of the local FILETIME Time for UserIndex as NUL-terminated UTF-16,
+ * at most Length units. The 2.0.6717 dashboard does not read the result.
+ */
+XAM_IMPORT(0x1E8) VOID XamFormatDateString(DWORD UserIndex, ULONGLONG Time, PWSTR Buffer, DWORD Length);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xam/xamdef.h b/platform/xex/sdk/include/xbox360/xam/xamdef.h
new file mode 100644
index 0000000..5186d43
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xam/xamdef.h
@@ -0,0 +1,35 @@
+/*
+ * XAM types that most imports use.
+ */
+
+#ifndef XBOX360_XAM_XAMDEF_H
+#define XBOX360_XAM_XAMDEF_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+struct _XOVERLAPPED;
+
+typedef VOID (*PXOVERLAPPED_COMPLETION_ROUTINE)(DWORD ErrorCode, DWORD Length, struct _XOVERLAPPED *Overlapped);
+
+/*
+ * State of an asynchronous XAM request. InternalLow holds the Win32 error
+ * code, ERROR_IO_PENDING until the request completes.
+ */
+typedef struct _XOVERLAPPED {
+ ULONG_PTR InternalLow;
+ ULONG_PTR InternalHigh;
+ ULONG_PTR InternalContext;
+ /* Event that XAM signals on completion, or NULL. */
+ HANDLE hEvent;
+ PXOVERLAPPED_COMPLETION_ROUTINE pCompletionRoutine;
+ DWORD_PTR dwCompletionContext;
+ DWORD dwExtendedError;
+} XOVERLAPPED, *PXOVERLAPPED;
+
+C_ASSERT(sizeof(XOVERLAPPED) == 0x1c);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xbox360.h b/platform/xex/sdk/include/xbox360/xbox360.h
new file mode 100644
index 0000000..b5d15a2
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xbox360.h
@@ -0,0 +1,9 @@
+/* Every Xbox 360 header. */
+
+#ifndef XBOX360_H
+#define XBOX360_H
+
+#include <xbox360/xboxkrnl.h>
+#include <xbox360/xam.h>
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl.h b/platform/xex/sdk/include/xbox360/xboxkrnl.h
new file mode 100644
index 0000000..44c010a
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl.h
@@ -0,0 +1,22 @@
+/* xboxkrnl.exe imports and the kernel types they use. */
+
+#ifndef XBOX360_XBOXKRNL_H
+#define XBOX360_XBOXKRNL_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+#include <xbox360/xboxkrnl/ke.h>
+#include <xbox360/xboxkrnl/ob.h>
+#include <xbox360/xboxkrnl/rtl.h>
+#include <xbox360/xboxkrnl/ex.h>
+#include <xbox360/xboxkrnl/mm.h>
+#include <xbox360/xboxkrnl/io.h>
+#include <xbox360/xboxkrnl/hal.h>
+#include <xbox360/xboxkrnl/xex.h>
+#include <xbox360/xboxkrnl/xe.h>
+#include <xbox360/xboxkrnl/vd.h>
+#include <xbox360/xboxkrnl/xma.h>
+#include <xbox360/xboxkrnl/xaudio.h>
+#include <xbox360/xboxkrnl/nic.h>
+#include <xbox360/xboxkrnl/usb.h>
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/ex.h b/platform/xex/sdk/include/xbox360/xboxkrnl/ex.h
new file mode 100644
index 0000000..1ffe646
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/ex.h
@@ -0,0 +1,325 @@
+/*
+ * Executive: pool memory, threads, notifications, configuration settings,
+ * events, semaphores, waits and the loaded image name.
+ */
+
+#ifndef XBOX360_XBOXKRNL_EX_H
+#define XBOX360_XBOXKRNL_EX_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+#include <xbox360/xboxkrnl/ke.h>
+
+XBOX360_EXTERN_C_START
+
+/*
+ * Pool of ExAllocatePoolTypeWithTag. CurrentProcessPool selects the title
+ * pool for a title thread and the system pool otherwise.
+ */
+typedef enum _POOL_TYPE {
+ CurrentProcessPool = 0,
+ TitlePool = 1,
+ SystemPool = 2,
+ TitleDebugPool = 3,
+ SystemDebugPool = 4,
+} POOL_TYPE;
+
+/*
+ * CreationFlags of ExCreateThread. Bits 24 to 29 select the hardware
+ * threads the new thread may run on.
+ */
+#define EX_CREATE_FLAG_SUSPENDED 0x00000001
+#define EX_CREATE_FLAG_SYSTEM 0x00000002
+/* Allocate the TLS data block with the thread and copy the TLS template into it. */
+#define EX_CREATE_FLAG_TLS_DATA 0x00000008
+/* Priority class 13; takes precedence over EX_CREATE_FLAG_PRIORITY_CLASS_LOW. */
+#define EX_CREATE_FLAG_PRIORITY_CLASS_HIGH 0x00000020
+/* Priority class 5. */
+#define EX_CREATE_FLAG_PRIORITY_CLASS_LOW 0x00000040
+/* ThreadHandle receives a referenced thread object instead of a handle. */
+#define EX_CREATE_FLAG_RETURN_KTHREAD 0x00000080
+/* Entry thread of a title. */
+#define EX_CREATE_FLAG_TITLE_ENTRY 0x00000100
+/* A debug monitor does not stop the thread. */
+#define EX_CREATE_FLAG_EXEMPT_FROM_STOPS 0x00000200
+/* A debug monitor does not debug the thread. */
+#define EX_CREATE_FLAG_NOT_DEBUGGABLE 0x00000400
+#define EX_CREATE_FLAG_PROCESSOR0 0x01000000
+#define EX_CREATE_FLAG_PROCESSOR1 0x02000000
+#define EX_CREATE_FLAG_PROCESSOR2 0x04000000
+#define EX_CREATE_FLAG_PROCESSOR3 0x08000000
+#define EX_CREATE_FLAG_PROCESSOR4 0x10000000
+#define EX_CREATE_FLAG_PROCESSOR5 0x20000000
+#define EX_CREATE_AFFINITY_SHIFT 24
+
+/*
+ * Thread notification. The routine gets Creating 1 when the thread starts
+ * and 0 when it ends. Routines of higher Priority run first. The kernel
+ * owns ListEntry while the record is registered.
+ */
+struct _EX_THREAD_REGISTRATION;
+
+typedef VOID (*PEX_THREAD_NOTIFICATION_ROUTINE)(
+ struct _EX_THREAD_REGISTRATION *Registration,
+ PKTHREAD Thread,
+ BOOLEAN Creating
+);
+
+typedef struct _EX_THREAD_REGISTRATION {
+ PEX_THREAD_NOTIFICATION_ROUTINE NotificationRoutine;
+ LONG Priority;
+ LIST_ENTRY ListEntry;
+} EX_THREAD_REGISTRATION, *PEX_THREAD_REGISTRATION;
+
+C_ASSERT(sizeof(EX_THREAD_REGISTRATION) == 16);
+C_ASSERT(__builtin_offsetof(EX_THREAD_REGISTRATION, ListEntry) == 8);
+
+/* Title termination notification, laid out as EX_THREAD_REGISTRATION. */
+struct _EX_TITLE_TERMINATE_REGISTRATION;
+
+typedef VOID (*PEX_TITLE_TERMINATE_ROUTINE)(struct _EX_TITLE_TERMINATE_REGISTRATION *Registration);
+
+typedef struct _EX_TITLE_TERMINATE_REGISTRATION {
+ PEX_TITLE_TERMINATE_ROUTINE NotificationRoutine;
+ LONG Priority;
+ LIST_ENTRY ListEntry;
+} EX_TITLE_TERMINATE_REGISTRATION, *PEX_TITLE_TERMINATE_REGISTRATION;
+
+C_ASSERT(sizeof(EX_TITLE_TERMINATE_REGISTRATION) == 16);
+C_ASSERT(__builtin_offsetof(EX_TITLE_TERMINATE_REGISTRATION, ListEntry) == 8);
+
+/*
+ * Categories of the configuration settings. Setting 0 of a category is the
+ * whole category record.
+ */
+#define XCONFIG_STATIC_CATEGORY 0
+#define XCONFIG_STATISTIC_CATEGORY 1
+#define XCONFIG_SECURED_CATEGORY 2
+#define XCONFIG_USER_CATEGORY 3
+#define XCONFIG_XNET_MACHINE_ACCOUNT_CATEGORY 4
+#define XCONFIG_XNET_PARAMETERS_CATEGORY 5
+#define XCONFIG_MEDIA_CENTER_CATEGORY 6
+#define XCONFIG_CONSOLE_CATEGORY 7
+#define XCONFIG_DVD_CATEGORY 8
+#define XCONFIG_IPTV_CATEGORY 9
+#define XCONFIG_SYSTEM_CATEGORY 10
+
+/* Settings of XCONFIG_SECURED_CATEGORY. */
+#define XCONFIG_SECURED_GAME_REGION 3
+#define XCONFIG_SECURED_SYSTEM_FLAGS 6
+
+/* Settings of XCONFIG_USER_CATEGORY. */
+#define XCONFIG_USER_RETAIL_FLAGS 12
+
+/* Services of ExDebugMonitorService. */
+#define ExDmRegisterDebugMonitor 0
+#define ExDmGetDebugMonitorData 1
+#define ExDmEnableProfiling 2
+#define ExDmGetHvStatistics 3
+#define ExDmGetCdRomEmulationRoutines 4
+#define ExDmGetCdRomSenseData 5
+#define ExDmGetPreDebugRoutine 6
+#define ExDmSetDvdEmulationMode 7
+#define ExDmQueryDevkitStatistics 8
+
+/* Sizes of ExLoadedImageName and ExLoadedCommandLine. */
+#define EX_LOADED_IMAGE_NAME_SIZE 256
+#define EX_LOADED_COMMAND_LINE_SIZE 512
+
+struct _EXCEPTION_RECORD;
+struct _CONTEXT;
+
+/** Writes a crash dump for an exception record and context. */
+XBOXKRNL_IMPORT(0x006) NTSTATUS DumpWriteDump(
+ struct _EXCEPTION_RECORD *ExceptionRecord,
+ struct _CONTEXT *ContextRecord,
+ ULONG Flags
+);
+
+/**
+ * Allocates NumberOfBytes of pool memory with a four-character tag.
+ * Returns the address or NULL.
+ */
+XBOXKRNL_IMPORT(0x00A) PVOID ExAllocatePoolWithTag(SIZE_T NumberOfBytes, ULONG Tag);
+
+/**
+ * Allocates pool memory of type PoolType with a four-character tag.
+ * Returns the address or NULL.
+ */
+XBOXKRNL_IMPORT(0x00B) PVOID ExAllocatePoolTypeWithTag(SIZE_T NumberOfBytes, ULONG Tag, POOL_TYPE PoolType);
+
+/**
+ * Console game region. The dashboard 2.0.6717 compares the first 16 bits
+ * with 0x0101 to select Japanese video mode names.
+ */
+XBOXKRNL_IMPORT(0x00C) extern PUSHORT __imp_ExConsoleGameRegion;
+#define ExConsoleGameRegion (*__imp_ExConsoleGameRegion)
+
+/**
+ * Creates a thread. With SystemRoutine NULL the thread enters StartRoutine
+ * with StartContext. Returning from the start routine ends the thread with
+ * the returned value as its exit code, as ExTerminateThread does. Zero
+ * CreationFlags start it at once. ThreadHandle receives the thread handle,
+ * or the referenced thread object with EX_CREATE_FLAG_RETURN_KTHREAD.
+ */
+XBOXKRNL_IMPORT(0x00D) NTSTATUS ExCreateThread(
+ PHANDLE ThreadHandle,
+ SIZE_T StackSize,
+ PULONG ThreadId,
+ PKSYSTEM_ROUTINE SystemRoutine,
+ PKSTART_ROUTINE StartRoutine,
+ PVOID StartContext,
+ ULONG CreationFlags
+);
+
+/** Frees pool memory. */
+XBOXKRNL_IMPORT(0x00F) VOID ExFreePool(PVOID P);
+
+/**
+ * Reads a configuration setting into Buffer. The setting size is stored at
+ * ResultSize when not null.
+ */
+XBOXKRNL_IMPORT(0x010) NTSTATUS ExGetXConfigSetting(
+ USHORT Category,
+ USHORT Setting,
+ PVOID Buffer,
+ USHORT BufferSize,
+ PUSHORT ResultSize
+);
+
+/**
+ * Registers a thread creation and deletion callback when Register is true
+ * and removes it otherwise. Registration must stay valid while registered.
+ */
+XBOXKRNL_IMPORT(0x014) VOID ExRegisterThreadNotification(PEX_THREAD_REGISTRATION Registration, BOOLEAN Register);
+
+/**
+ * Registers a title termination callback when Register is true and removes
+ * it otherwise. Registration must stay valid while registered.
+ */
+XBOXKRNL_IMPORT(0x015) VOID ExRegisterTitleTerminateNotification(
+ PEX_TITLE_TERMINATE_REGISTRATION Registration,
+ BOOLEAN Register
+);
+
+/** Writes a configuration setting from Buffer. */
+XBOXKRNL_IMPORT(0x018) NTSTATUS ExSetXConfigSetting(USHORT Category, USHORT Setting, PVOID Buffer, USHORT BufferSize);
+
+/** Ends the current thread with ExitStatus without unwinding its stack. */
+XBOXKRNL_IMPORT(0x019) DECLSPEC_NORETURN VOID ExTerminateThread(NTSTATUS ExitStatus);
+
+/** Object type of thread objects. */
+XBOXKRNL_IMPORT(0x01B) extern struct _OBJECT_TYPE *__imp_ExThreadObjectType;
+#define ExThreadObjectType (*__imp_ExThreadObjectType)
+
+/** Calls a debug monitor service (ExDm*) of the kernel. */
+XBOXKRNL_IMPORT(0x1AA) NTSTATUS ExDebugMonitorService(ULONG Service, PVOID Argument1, ULONG Argument2, PVOID Argument3);
+
+/** Command line of the running executable, NUL-terminated. */
+XBOXKRNL_IMPORT(0x1AE) extern CHAR (*__imp_ExLoadedCommandLine)[EX_LOADED_COMMAND_LINE_SIZE];
+#define ExLoadedCommandLine (*__imp_ExLoadedCommandLine)
+
+/** Object path of the running executable, NUL-terminated. */
+XBOXKRNL_IMPORT(0x1AF) extern CHAR (*__imp_ExLoadedImageName)[EX_LOADED_IMAGE_NAME_SIZE];
+#define ExLoadedImageName (*__imp_ExLoadedImageName)
+
+/** Replaces a 4-byte configuration setting with (old & AndMask) | OrMask. */
+XBOXKRNL_IMPORT(0x2BC) NTSTATUS ExReadModifyWriteXConfigSettingUlong(
+ USHORT Category,
+ USHORT Setting,
+ ULONG AndMask,
+ ULONG OrMask
+);
+
+/* Largest image of ExExpansionInstall, and the multiple its size must be. */
+#define EX_EXPANSION_MAX_SIZE 0x10000
+#define EX_EXPANSION_SIZE_ALIGNMENT 128
+
+/**
+ * Hands a signed expansion image to the hypervisor, which verifies and
+ * installs it. Fails with STATUS_INVALID_PARAMETER when ImageSize is above
+ * EX_EXPANSION_MAX_SIZE or not a multiple of EX_EXPANSION_SIZE_ALIGNMENT,
+ * and with STATUS_UNSUCCESSFUL when the hypervisor refuses the image.
+ *
+ * The kernel passes MmGetPhysicalAddress(ImageBase) to the hypervisor
+ * without copying. The image must be physically contiguous, start on a
+ * multiple of 0x80 and stay within one 64 KiB physical block; a physical
+ * address below 0x40000 or above the top of memory halts the console. The
+ * hypervisor moves the buffer into integrity-protected memory and zeroes
+ * it afterwards. A buffer that covers only part of its pages halts the
+ * stock 16547 hypervisor, so pass a whole 64 KiB block with the image at
+ * its start and ImageSize EX_EXPANSION_MAX_SIZE: memory from
+ * MmAllocatePhysicalMemoryEx with MEM_LARGE_PAGES, a lowest address of
+ * 0x40000 and a 64 KiB alignment. The hypervisor reads the image size
+ * from the image header.
+ */
+XBOXKRNL_IMPORT(0x30B) NTSTATUS ExExpansionInstall(PVOID ImageBase, ULONG ImageSize);
+
+/**
+ * Calls the installed kernel expansion ExpansionId with four arguments and
+ * returns its status. Fails with STATUS_NOT_IMPLEMENTED when no expansion
+ * of that id is installed. The meaning of the arguments is the
+ * expansion's.
+ */
+XBOXKRNL_IMPORT(0x30C) NTSTATUS ExExpansionCall(
+ ULONG ExpansionId,
+ ULONG_PTR Argument1,
+ ULONG_PTR Argument2,
+ ULONG_PTR Argument3,
+ ULONG_PTR Argument4
+);
+
+/** Sets an event to not signaled. */
+XBOXKRNL_IMPORT(0x0CE) NTSTATUS NtClearEvent(HANDLE EventHandle);
+
+/** Closes a handle. */
+XBOXKRNL_IMPORT(0x0CF) NTSTATUS NtClose(HANDLE Handle);
+
+/** Creates an event. */
+XBOXKRNL_IMPORT(0x0D1) NTSTATUS NtCreateEvent(
+ PHANDLE EventHandle,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ EVENT_TYPE EventType,
+ BOOLEAN InitialState
+);
+
+/** Creates a semaphore with a count and limit. */
+XBOXKRNL_IMPORT(0x0D5) NTSTATUS NtCreateSemaphore(
+ PHANDLE SemaphoreHandle,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ LONG InitialCount,
+ LONG MaximumCount
+);
+
+/** Releases a semaphore. The previous count is stored at PreviousCount when not null. */
+XBOXKRNL_IMPORT(0x0F3) NTSTATUS NtReleaseSemaphore(HANDLE SemaphoreHandle, LONG ReleaseCount, PLONG PreviousCount);
+
+/** Sets an event to signaled. The previous state is stored at PreviousState when not null. */
+XBOXKRNL_IMPORT(0x0F6) NTSTATUS NtSetEvent(HANDLE EventHandle, PLONG PreviousState);
+
+/** Sets the system time as a FILETIME. The previous time is stored at PreviousTime when not null. */
+XBOXKRNL_IMPORT(0x0F9) NTSTATUS NtSetSystemTime(PLARGE_INTEGER SystemTime, PLARGE_INTEGER PreviousTime);
+
+/** Waits on a handle. A null Timeout waits without limit. */
+XBOXKRNL_IMPORT(0x0FD) NTSTATUS NtWaitForSingleObjectEx(
+ HANDLE Handle,
+ KPROCESSOR_MODE WaitMode,
+ BOOLEAN Alertable,
+ PLARGE_INTEGER Timeout
+);
+
+/** Waits on several handles. */
+XBOXKRNL_IMPORT(0x0FE) NTSTATUS NtWaitForMultipleObjectsEx(
+ ULONG Count,
+ const HANDLE *Handles,
+ WAIT_TYPE WaitType,
+ KPROCESSOR_MODE WaitMode,
+ BOOLEAN Alertable,
+ PLARGE_INTEGER Timeout
+);
+
+/** Yields the remainder of the time slice of the current thread. */
+XBOXKRNL_IMPORT(0x101) NTSTATUS NtYieldExecution(VOID);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/hal.h b/platform/xex/sdk/include/xbox360/xboxkrnl/hal.h
new file mode 100644
index 0000000..74bf50a
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/hal.h
@@ -0,0 +1,351 @@
+/*
+ * Hardware abstraction layer: the system management controller (SMC),
+ * firmware reentry, console hardware information and kernel version.
+ */
+
+#ifndef XBOX360_XBOXKRNL_HAL_H
+#define XBOX360_XBOXKRNL_HAL_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/*
+ * A request to the SMC and its reply are 16 bytes; byte 0 is the command.
+ * Commands below 0x80 are queries: the reply repeats the command in byte 0
+ * and reply byte n + 1 is Data[n]. Commands from 0x80 on get no reply, so
+ * HalSendSMCMessage takes a null Reply for them. The SMC does not answer
+ * a query it does not know, and HalSendSMCMessage with a Reply then waits
+ * for good on a retail kernel.
+ *
+ * The names and layouts follow SMC firmware 510301; the SMC firmware
+ * differs between consoles. Query SMC_COMMAND_QUERY_VERSION for the build.
+ */
+#define SMC_MESSAGE_LENGTH 16
+
+/* SMC commands and message kinds (byte 0 of an SMC_MESSAGE). */
+#define SMC_COMMAND_QUERY_POWER_UP_CAUSE 0x01 /* reply SMC_POWER_UP_CAUSE_REPLY */
+#define SMC_COMMAND_QUERY_TEMPERATURES 0x07 /* reply SMC_TEMPERATURES_REPLY */
+#define SMC_COMMAND_I2C 0x11
+#define SMC_COMMAND_QUERY_VERSION 0x12 /* reply SMC_VERSION_REPLY */
+#define SMC_COMMAND_QUERY_IR_ADDRESS 0x16 /* low nibble of reply byte 1 */
+#define SMC_COMMAND_TRAY_STATE 0x83 /* byte 1 is 0x60 plus the state */
+#define SMC_COMMAND_SET_FAN_ALGORITHM 0x88 /* SMC_FAN_ALGORITHM_REQUEST */
+#define SMC_COMMAND_SET_FAN_SPEED 0x89 /* SMC_FAN_SPEED_REQUEST */
+#define SMC_COMMAND_SET_POWER_LED 0x8C /* SMC_POWER_LED_REQUEST */
+#define SMC_COMMAND_SET_FAN2_SPEED 0x94 /* SMC_FAN_SPEED_REQUEST; some SMC builds only */
+#define SMC_COMMAND_SET_IR_ADDRESS 0x95 /* low nibble of byte 1 */
+#define SMC_COMMAND_SET_RING_OF_LIGHT 0x99 /* SMC_RING_OF_LIGHT_REQUEST */
+
+/* Bus address of the EEPROM that holds the debug monitor settings. */
+#define SMC_I2C_SETTINGS_EEPROM 0xD4
+
+typedef struct _SMC_MESSAGE {
+ UCHAR Command;
+ UCHAR Data[SMC_MESSAGE_LENGTH - 1];
+} SMC_MESSAGE, *PSMC_MESSAGE;
+
+C_ASSERT(sizeof(SMC_MESSAGE) == 16);
+
+/*
+ * Reply of SMC_COMMAND_QUERY_POWER_UP_CAUSE. The values of Cause are not
+ * established.
+ */
+typedef struct _SMC_POWER_UP_CAUSE_REPLY {
+ UCHAR Command;
+ UCHAR Cause;
+ UCHAR Reserved1;
+ UCHAR BootAttempts;
+ UCHAR Status; /* SMC_POWER_UP_STATUS_* */
+ UCHAR Reserved2[11];
+} SMC_POWER_UP_CAUSE_REPLY, *PSMC_POWER_UP_CAUSE_REPLY;
+
+C_ASSERT(sizeof(SMC_POWER_UP_CAUSE_REPLY) == 16);
+
+/* SMC_POWER_UP_CAUSE_REPLY.Status: the SMC configuration block is invalid. */
+#define SMC_POWER_UP_STATUS_CONFIG_INVALID 0x01
+
+/*
+ * A temperature of SMC_TEMPERATURES_REPLY: 8.8 fixed point degrees,
+ * fraction byte first. Degrees Celsius is inferred from the kernel's log.
+ */
+typedef struct _SMC_TEMPERATURE {
+ UCHAR Fraction; /* 1/256 degrees */
+ UCHAR Degrees;
+} SMC_TEMPERATURE, *PSMC_TEMPERATURE;
+
+C_ASSERT(sizeof(SMC_TEMPERATURE) == 2);
+
+/*
+ * Reply of SMC_COMMAND_QUERY_TEMPERATURES. Only EdramTemperature has a
+ * known source; the devices Temperature0, Temperature1 and Temperature3
+ * measure are not established. FanSpeed is the requested speed in
+ * percent, not the measured duty.
+ */
+typedef struct _SMC_TEMPERATURES_REPLY {
+ UCHAR Command;
+ SMC_TEMPERATURE Temperature0;
+ SMC_TEMPERATURE Temperature1;
+ SMC_TEMPERATURE EdramTemperature;
+ SMC_TEMPERATURE Temperature3;
+ UCHAR FanSpeed;
+ UCHAR Reserved[6];
+} SMC_TEMPERATURES_REPLY, *PSMC_TEMPERATURES_REPLY;
+
+C_ASSERT(sizeof(SMC_TEMPERATURES_REPLY) == 16);
+C_ASSERT(__builtin_offsetof(SMC_TEMPERATURES_REPLY, EdramTemperature) == 5);
+C_ASSERT(__builtin_offsetof(SMC_TEMPERATURES_REPLY, FanSpeed) == 9);
+
+/*
+ * Reply of SMC_COMMAND_QUERY_VERSION. Version holds the firmware build as
+ * hex digits: 51 03 01 is build 510301. BootCause0 and BootCause1 are the
+ * bytes the host last set with SMC command 0x9c; the kernel reads the boot
+ * cause from BootCause1 bits 7-4. PowerButtonPresses counts power button
+ * presses. Layout of SMC 510301.
+ */
+typedef struct _SMC_VERSION_REPLY {
+ UCHAR Command;
+ UCHAR Version[3];
+ UCHAR BootCause0;
+ UCHAR BootCause1;
+ UCHAR PowerButtonPresses;
+ UCHAR Reserved[9];
+} SMC_VERSION_REPLY, *PSMC_VERSION_REPLY;
+
+C_ASSERT(sizeof(SMC_VERSION_REPLY) == 16);
+C_ASSERT(__builtin_offsetof(SMC_VERSION_REPLY, BootCause0) == 4);
+C_ASSERT(__builtin_offsetof(SMC_VERSION_REPLY, PowerButtonPresses) == 6);
+
+/*
+ * Request of SMC_COMMAND_SET_FAN_ALGORITHM. SMC_FAN_ALGORITHM_FULL_SPEED
+ * is dangerous: the SMC keeps it until power-down and stops polling the
+ * temperature sensors meanwhile, so it reports a sensor timeout and shuts
+ * the console down.
+ */
+typedef struct _SMC_FAN_ALGORITHM_REQUEST {
+ UCHAR Command;
+ UCHAR Algorithm; /* SMC_FAN_ALGORITHM_* */
+ UCHAR Reserved[14];
+} SMC_FAN_ALGORITHM_REQUEST, *PSMC_FAN_ALGORITHM_REQUEST;
+
+C_ASSERT(sizeof(SMC_FAN_ALGORITHM_REQUEST) == 16);
+
+#define SMC_FAN_ALGORITHM_QUIET 0x01
+#define SMC_FAN_ALGORITHM_FULL_SPEED 0x02
+
+/*
+ * Request of SMC_COMMAND_SET_FAN_SPEED and SMC_COMMAND_SET_FAN2_SPEED.
+ * Speed with SMC_FAN_SPEED_FIXED set selects a fixed duty of
+ * Speed & SMC_FAN_SPEED_PERCENT_MASK percent, at most 100; with it clear,
+ * the SMC controls the fan. SMC_COMMAND_SET_FAN2_SPEED drives a second fan
+ * output and exists only in some SMC builds (21010d has it, 510301
+ * ignores it). The setting lasts until the console restarts.
+ */
+typedef struct _SMC_FAN_SPEED_REQUEST {
+ UCHAR Command;
+ UCHAR Speed;
+ UCHAR Reserved[14];
+} SMC_FAN_SPEED_REQUEST, *PSMC_FAN_SPEED_REQUEST;
+
+C_ASSERT(sizeof(SMC_FAN_SPEED_REQUEST) == 16);
+
+#define SMC_FAN_SPEED_AUTOMATIC 0x00
+#define SMC_FAN_SPEED_FIXED 0x80
+#define SMC_FAN_SPEED_PERCENT_MASK 0x7F
+#define SMC_FAN_SPEED_MAX_PERCENT 100
+
+/*
+ * Request of SMC_COMMAND_SET_POWER_LED. Mode SMC_POWER_LED_AUTOMATIC
+ * returns the LED to the SMC, with Option bit 0 as a one-shot request
+ * whose effect is not established. Modes SMC_POWER_LED_PATTERN_FIRST to
+ * SMC_POWER_LED_PATTERN_LAST select a pattern of the SMC's table, whose
+ * looks are not established. The SMC ignores other modes.
+ */
+typedef struct _SMC_POWER_LED_REQUEST {
+ UCHAR Command;
+ UCHAR Mode;
+ UCHAR Option;
+ UCHAR Reserved[13];
+} SMC_POWER_LED_REQUEST, *PSMC_POWER_LED_REQUEST;
+
+C_ASSERT(sizeof(SMC_POWER_LED_REQUEST) == 16);
+
+#define SMC_POWER_LED_AUTOMATIC 1
+#define SMC_POWER_LED_OPTION_ONE_SHOT 0x01
+#define SMC_POWER_LED_PATTERN_FIRST 2
+#define SMC_POWER_LED_PATTERN_LAST 9
+
+/*
+ * Request of SMC_COMMAND_SET_RING_OF_LIGHT. With SMC_RING_OF_LIGHT_OVERRIDE
+ * in Flags, the high nibble of Quadrants turns the four ring quadrants on
+ * (bit set) or off; which bit lights which physical quadrant is not
+ * established. Without it, control returns to the system. Keep the low
+ * nibble of Quadrants zero: SMC build 21010d also reads it. The ring has
+ * no colour or brightness control, and the setting lasts until the
+ * console restarts.
+ */
+typedef struct _SMC_RING_OF_LIGHT_REQUEST {
+ UCHAR Command;
+ UCHAR Flags;
+ UCHAR Quadrants;
+ UCHAR Reserved[13];
+} SMC_RING_OF_LIGHT_REQUEST, *PSMC_RING_OF_LIGHT_REQUEST;
+
+C_ASSERT(sizeof(SMC_RING_OF_LIGHT_REQUEST) == 16);
+
+#define SMC_RING_OF_LIGHT_OVERRIDE 0x01
+#define SMC_RING_OF_LIGHT_QUADRANT_SHIFT 4
+#define SMC_RING_OF_LIGHT_QUADRANT_MASK 0xF0
+
+struct _HAL_SMC_REGISTRATION;
+
+/* SMC notification routine; it runs at dispatch level. */
+typedef VOID (*PHAL_SMC_NOTIFICATION)(struct _HAL_SMC_REGISTRATION *Registration, PSMC_MESSAGE Message);
+
+/*
+ * Registration of an SMC notification routine. Routines of higher
+ * Priority run first. The kernel owns ListEntry while it is registered.
+ */
+typedef struct _HAL_SMC_REGISTRATION {
+ PHAL_SMC_NOTIFICATION NotificationRoutine;
+ LONG Priority;
+ LIST_ENTRY ListEntry;
+} HAL_SMC_REGISTRATION, *PHAL_SMC_REGISTRATION;
+
+C_ASSERT(sizeof(HAL_SMC_REGISTRATION) == 16);
+C_ASSERT(__builtin_offsetof(HAL_SMC_REGISTRATION, ListEntry) == 8);
+
+/* Routine of HalReturnToFirmware. */
+typedef enum _FIRMWARE_REENTRY {
+ HalHaltRoutine = 0,
+ HalRebootRoutine = 1,
+ HalKdRebootRoutine = 2,
+ HalReserved3Routine = 3,
+ HalFatalErrorRebootRoutine = 4, /* reset through the SMC */
+ HalPowerDownRoutine = 5,
+ HalRebootQuiesceRoutine = 6, /* restarts the system software */
+ HalForcedPowerDownRoutine = 7,
+ HalForcedRebootQuiesceRoutine = 8,
+} FIRMWARE_REENTRY;
+
+/*
+ * XBOX_HARDWARE_INFO.Flags. The top four bits hold the hardware generation.
+ * DEVKIT_KERNEL is set by the static initializer of development kit
+ * kernels (15574, 16547) and clear in retail kernels (17559). No kernel
+ * sets TEST_KIT; XBDM reports a test kit when it is set.
+ */
+#define XBOX_HW_FLAG_GENERATION_DETECTED 0x00000004 /* VdDetectSystemType set the generation */
+#define XBOX_HW_FLAG_HOST_BRIDGE_EBEB 0x00000008
+#define XBOX_HW_FLAG_DEVKIT_KERNEL 0x00000010
+#define XBOX_HW_FLAG_HDD 0x00000020
+#define XBOX_HW_FLAG_KERNEL_DEBUGGER_ENABLED 0x00000080 /* enabled at boot */
+#define XBOX_HW_FLAG_KERNEL_DEBUGGER_ATTACHED 0x00000100
+#define XBOX_HW_FLAG_LARGE_MEMORY 0x00010000 /* 1 GB of memory */
+#define XBOX_HW_FLAG_MMC_FLASH 0x00020000
+#define XBOX_HW_FLAG_TEST_KIT 0x02000000
+
+/*
+ * Hardware generation (motherboard), Flags >> XBOX_HW_GENERATION_SHIFT,
+ * as XBDM names it. Other values have no known name.
+ */
+#define XBOX_HW_GENERATION_SHIFT 28
+#define XBOX_HW_GENERATION_XENON 0
+#define XBOX_HW_GENERATION_ZEPHYR 1
+#define XBOX_HW_GENERATION_FALCON 2
+#define XBOX_HW_GENERATION_JASPER 3
+#define XBOX_HW_GENERATION_TRINITY 4
+#define XBOX_HW_GENERATION_CORONA 5
+#define XBOX_HW_GENERATION_WINCHESTER 6
+#define XBOX_HW_GENERATION_RIDGEWAY 8
+
+/* Platform, Flags & XBOX_HW_PLATFORM_MASK, as XBDM names it. */
+#define XBOX_HW_PLATFORM_MASK 0x00000003
+#define XBOX_HW_PLATFORM_ALPHA 0
+#define XBOX_HW_PLATFORM_MONGREL 1
+#define XBOX_HW_PLATFORM_SHIVA 2
+#define XBOX_HW_PLATFORM_WATERNOOSE 3
+
+/*
+ * XBOX_HARDWARE_INFO.BootFlags, which the boot loaders and the hypervisor
+ * set and pass to the kernel. SB and SD are the second and fourth stage
+ * boot loaders. Bit 0x0800 is tested by SB and has no known meaning.
+ */
+#define XBOX_BOOT_FLAG_UNBOUND_BOOT_LOADER 0x0001 /* SB console binding is zero; SMC check skipped */
+#define XBOX_BOOT_FLAG_LOCK_FUSES_BLOWN 0x0002 /* fuse row 0 bits 0-55 nonzero */
+#define XBOX_BOOT_FLAG_CONSOLE_TYPE_MATCH 0x0004 /* fuse row 1 equals the SB console type */
+#define XBOX_BOOT_FLAG_FUSE_VERSION_MATCH 0x0008 /* fuse row 2 count equals the SB version */
+#define XBOX_BOOT_FLAG_CONSOLE_KEY_VALID 0x0010 /* fuse rows 3-6 hold a valid console key */
+#define XBOX_BOOT_FLAG_DEVKIT_MEMORY 0x0080 /* memory above 512 MB */
+#define XBOX_BOOT_FLAG_KD_LITE_ONLY 0x0100 /* kernel debugger lite only; setter unknown */
+#define XBOX_BOOT_FLAG_SHADOW_BOOTED 0x0200 /* started by a shadow boot */
+#define XBOX_BOOT_FLAG_CDROM_SYSTEM_ROOT 0x0400 /* shadow boot from CD-ROM; \SystemRoot is the CD-ROM */
+#define XBOX_BOOT_FLAG_FLASH_PATCH1 0x1000 /* SD loaded the first flash patch slot */
+#define XBOX_BOOT_FLAG_FLASH_PATCH2 0x2000 /* SD loaded the second flash patch slot */
+#define XBOX_BOOT_FLAG_UPDATE_SEQUENCE_PENDING 0x4000 /* the patch requests the next update sequence */
+#define XBOX_BOOT_FLAG_UPDATE_SEQUENCE_PROGRAMMED 0x8000 /* the update sequence fuses hold it */
+
+/* Console hardware description. The debug monitor changes Flags at run time. */
+typedef struct _XBOX_HARDWARE_INFO {
+ ULONG Flags;
+ UCHAR NumberOfProcessors;
+ UCHAR Revision;
+ UCHAR Reserved1[6];
+ USHORT BootLoaderData;
+ USHORT BootFlags;
+} XBOX_HARDWARE_INFO, *PXBOX_HARDWARE_INFO;
+
+C_ASSERT(sizeof(XBOX_HARDWARE_INFO) == 0x10);
+C_ASSERT(__builtin_offsetof(XBOX_HARDWARE_INFO, BootFlags) == 0xE);
+
+typedef struct _XBOX_KRNL_VERSION {
+ USHORT Major;
+ USHORT Minor;
+ USHORT Build;
+ USHORT Qfe;
+} XBOX_KRNL_VERSION, *PXBOX_KRNL_VERSION;
+
+C_ASSERT(sizeof(XBOX_KRNL_VERSION) == 8);
+
+/** Returns the AV pack value the hardware reports. */
+XBOXKRNL_IMPORT(0x022) ULONG HalGetCurrentAVPack(VOID);
+
+/** Opens or closes the optical drive tray. */
+XBOXKRNL_IMPORT(0x024) VOID HalOpenCloseODDTray(ULONG Open);
+
+/**
+ * Registers a system management controller event callback when Register
+ * is true and removes it otherwise. Registration must stay valid while
+ * registered.
+ */
+XBOXKRNL_IMPORT(0x027) VOID HalRegisterSMCNotification(PHAL_SMC_REGISTRATION Registration, BOOLEAN Register);
+
+/**
+ * Restarts or shuts down the console. Stock XBDM code continues after the
+ * call, so it is not declared to diverge.
+ */
+XBOXKRNL_IMPORT(0x028) VOID HalReturnToFirmware(FIRMWARE_REENTRY Routine);
+
+/**
+ * Sends a 16-byte message to the system management controller and
+ * receives the 16-byte reply.
+ */
+XBOXKRNL_IMPORT(0x029) VOID HalSendSMCMessage(PSMC_MESSAGE Request, PSMC_MESSAGE Reply);
+
+/** True while the power-down deferred procedure call runs. */
+XBOXKRNL_IMPORT(0x267) ULONG HalIsExecutingPowerDownDpc(VOID);
+
+/** Console hardware information. */
+XBOXKRNL_IMPORT(0x156) extern PXBOX_HARDWARE_INFO __imp_XboxHardwareInfo;
+#define XboxHardwareInfo (*__imp_XboxHardwareInfo)
+
+/** Version of the base kernel. */
+XBOXKRNL_IMPORT(0x157) extern PXBOX_KRNL_VERSION __imp_XboxKrnlBaseVersion;
+#define XboxKrnlBaseVersion (*__imp_XboxKrnlBaseVersion)
+
+/** Version of the running kernel. */
+XBOXKRNL_IMPORT(0x158) extern PXBOX_KRNL_VERSION __imp_XboxKrnlVersion;
+#define XboxKrnlVersion (*__imp_XboxKrnlVersion)
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/io.h b/platform/xex/sdk/include/xbox360/xboxkrnl/io.h
new file mode 100644
index 0000000..40bc690
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/io.h
@@ -0,0 +1,815 @@
+#ifndef XBOX360_XBOXKRNL_IO_H
+#define XBOX360_XBOXKRNL_IO_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* ------------------------------------------------------------------------- */
+/* File access, share, attribute and create constants */
+/* ------------------------------------------------------------------------- */
+
+/* FILE_SHARE_*: what other opens of a file may do. */
+#define FILE_SHARE_READ 0x00000001
+#define FILE_SHARE_WRITE 0x00000002
+#define FILE_SHARE_DELETE 0x00000004
+
+/* FILE_ATTRIBUTE_*. */
+#define FILE_ATTRIBUTE_READONLY 0x00000001
+#define FILE_ATTRIBUTE_HIDDEN 0x00000002
+#define FILE_ATTRIBUTE_SYSTEM 0x00000004
+#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
+#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
+#define FILE_ATTRIBUTE_DEVICE 0x00000040
+#define FILE_ATTRIBUTE_NORMAL 0x00000080
+#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
+#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
+#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
+
+/* Create disposition of NtCreateFile: what to do when the file exists or does not. */
+typedef enum _CREATE_DISPOSITION {
+ /* Replace the file if it exists, create it otherwise. */
+ FILE_SUPERSEDE = 0,
+ /* Open the file; fail if it does not exist. */
+ FILE_OPEN = 1,
+ /* Create the file; fail if it exists. */
+ FILE_CREATE = 2,
+ /* Open the file, or create it if it does not exist. */
+ FILE_OPEN_IF = 3,
+ /* Open and truncate the file; fail if it does not exist. */
+ FILE_OVERWRITE = 4,
+ /* Open and truncate the file, or create it if it does not exist. */
+ FILE_OVERWRITE_IF = 5
+} CREATE_DISPOSITION;
+
+/* IoStatusBlock->Information of a successful create. */
+#define FILE_SUPERSEDED 0x00000000
+#define FILE_OPENED 0x00000001
+#define FILE_CREATED 0x00000002
+#define FILE_OVERWRITTEN 0x00000003
+#define FILE_EXISTS 0x00000004
+#define FILE_DOES_NOT_EXIST 0x00000005
+
+/* Create options of NtCreateFile and open options of NtOpenFile. */
+#define FILE_DIRECTORY_FILE 0x00000001
+#define FILE_WRITE_THROUGH 0x00000002
+#define FILE_SEQUENTIAL_ONLY 0x00000004
+#define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
+#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
+#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
+#define FILE_NON_DIRECTORY_FILE 0x00000040
+#define FILE_RANDOM_ACCESS 0x00000800
+#define FILE_DELETE_ON_CLOSE 0x00001000
+#define FILE_OPEN_BY_FILE_ID 0x00002000
+#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
+
+/* ByteOffset values of NtReadFile and NtWriteFile (LowPart, HighPart -1). */
+#define FILE_WRITE_TO_END_OF_FILE 0xffffffff
+#define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
+
+/* File system flags of FILE_FS_ATTRIBUTE_INFORMATION.FileSystemAttributes. */
+#define FILE_CASE_SENSITIVE_SEARCH 0x00000001
+#define FILE_CASE_PRESERVED_NAMES 0x00000002
+#define FILE_UNICODE_ON_DISK 0x00000004
+#define FILE_PERSISTENT_ACLS 0x00000008
+#define FILE_FILE_COMPRESSION 0x00000010
+#define FILE_VOLUME_IS_COMPRESSED 0x00008000
+#define FILE_READ_ONLY_VOLUME 0x00080000
+
+/* ------------------------------------------------------------------------- */
+/* File information */
+/* ------------------------------------------------------------------------- */
+
+/* Classes of NtQueryInformationFile and NtSetInformationFile (Xenia's values). */
+typedef enum _FILE_INFORMATION_CLASS {
+ FileDirectoryInformation = 1,
+ FileFullDirectoryInformation = 2,
+ FileBothDirectoryInformation = 3,
+ FileBasicInformation = 4,
+ FileStandardInformation = 5,
+ FileInternalInformation = 6,
+ FileEaInformation = 7,
+ FileAccessInformation = 8,
+ FileNameInformation = 9,
+ FileRenameInformation = 10,
+ FileLinkInformation = 11,
+ FileNamesInformation = 12,
+ FileDispositionInformation = 13,
+ FilePositionInformation = 14,
+ FileFullEaInformation = 15,
+ FileModeInformation = 16,
+ FileAlignmentInformation = 17,
+ FileAllInformation = 18,
+ FileAllocationInformation = 19,
+ FileEndOfFileInformation = 20,
+ FileAlternateNameInformation = 21,
+ FileStreamInformation = 22,
+ /* Mounts a file of the volume as a partition device. */
+ FileMountPartitionInformation = 23,
+ FileMountPartitionsInformation = 24,
+ FilePipeRemoteInformation = 25,
+ FileSectorInformation = 26,
+ FileXctdCompressionInformation = 27,
+ FileCompressionInformation = 28,
+ FileObjectIdInformation = 29,
+ FileCompletionInformation = 30,
+ FileMoveClusterInformation = 31,
+ FileIoPriorityInformation = 32,
+ FileReparsePointInformation = 33,
+ FileNetworkOpenInformation = 34,
+ FileAttributeTagInformation = 35,
+ FileTrackingInformation = 36,
+ FileMaximumInformation = 37
+} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
+
+/* Classes of NtQueryVolumeInformationFile. */
+typedef enum _FS_INFORMATION_CLASS {
+ FileFsVolumeInformation = 1,
+ FileFsLabelInformation = 2,
+ FileFsSizeInformation = 3,
+ FileFsDeviceInformation = 4,
+ FileFsAttributeInformation = 5,
+ FileFsControlInformation = 6,
+ FileFsFullSizeInformation = 7,
+ FileFsObjectIdInformation = 8,
+ FileFsMaximumInformation = 9
+} FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
+
+/*
+ * Result of NtQueryFullAttributesFile and of NtQueryInformationFile with
+ * FileNetworkOpenInformation. Times are FILETIMEs.
+ */
+typedef struct _FILE_NETWORK_OPEN_INFORMATION {
+ LARGE_INTEGER CreationTime;
+ LARGE_INTEGER LastAccessTime;
+ LARGE_INTEGER LastWriteTime;
+ LARGE_INTEGER ChangeTime;
+ LARGE_INTEGER AllocationSize;
+ /* File size in bytes. */
+ LARGE_INTEGER EndOfFile;
+ ULONG FileAttributes;
+ ULONG Reserved;
+} FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
+
+C_ASSERT(__builtin_offsetof(FILE_NETWORK_OPEN_INFORMATION, EndOfFile) == 0x28);
+C_ASSERT(__builtin_offsetof(FILE_NETWORK_OPEN_INFORMATION, FileAttributes) == 0x30);
+C_ASSERT(sizeof(FILE_NETWORK_OPEN_INFORMATION) == 0x38);
+
+/*
+ * An entry of NtQueryDirectoryFile. The name, FileNameLength bytes, follows
+ * at 0x40. Times are FILETIMEs.
+ */
+typedef struct _FILE_DIRECTORY_INFORMATION {
+ /* Offset of the next entry, or 0 for the last one. */
+ ULONG NextEntryOffset;
+ ULONG FileIndex;
+ LARGE_INTEGER CreationTime;
+ LARGE_INTEGER LastAccessTime;
+ LARGE_INTEGER LastWriteTime;
+ LARGE_INTEGER ChangeTime;
+ /* File size in bytes. */
+ LARGE_INTEGER EndOfFile;
+ LARGE_INTEGER AllocationSize;
+ ULONG FileAttributes;
+ ULONG FileNameLength;
+ CHAR FileName[];
+} FILE_DIRECTORY_INFORMATION, *PFILE_DIRECTORY_INFORMATION;
+
+C_ASSERT(__builtin_offsetof(FILE_DIRECTORY_INFORMATION, CreationTime) == 0x08);
+C_ASSERT(__builtin_offsetof(FILE_DIRECTORY_INFORMATION, EndOfFile) == 0x28);
+C_ASSERT(__builtin_offsetof(FILE_DIRECTORY_INFORMATION, FileAttributes) == 0x38);
+C_ASSERT(__builtin_offsetof(FILE_DIRECTORY_INFORMATION, FileNameLength) == 0x3c);
+C_ASSERT(__builtin_offsetof(FILE_DIRECTORY_INFORMATION, FileName) == 0x40);
+C_ASSERT(sizeof(FILE_DIRECTORY_INFORMATION) == 0x40);
+
+/* Information of FileBasicInformation. Times are FILETIMEs. */
+typedef struct _FILE_BASIC_INFORMATION {
+ LARGE_INTEGER CreationTime;
+ LARGE_INTEGER LastAccessTime;
+ LARGE_INTEGER LastWriteTime;
+ LARGE_INTEGER ChangeTime;
+ ULONG FileAttributes;
+ ULONG Reserved;
+} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
+
+C_ASSERT(__builtin_offsetof(FILE_BASIC_INFORMATION, FileAttributes) == 0x20);
+C_ASSERT(sizeof(FILE_BASIC_INFORMATION) == 0x28);
+
+/* Information of FileDispositionInformation. */
+typedef struct _FILE_DISPOSITION_INFORMATION {
+ /* Delete the file when its last handle is closed. */
+ BOOLEAN DeleteFile;
+} FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
+
+C_ASSERT(sizeof(FILE_DISPOSITION_INFORMATION) == 1);
+
+/* Information of FilePositionInformation. */
+typedef struct _FILE_POSITION_INFORMATION {
+ LARGE_INTEGER CurrentByteOffset;
+} FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
+
+C_ASSERT(sizeof(FILE_POSITION_INFORMATION) == 8);
+
+/* Information of FileEndOfFileInformation. */
+typedef struct _FILE_END_OF_FILE_INFORMATION {
+ LARGE_INTEGER EndOfFile;
+} FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
+
+C_ASSERT(sizeof(FILE_END_OF_FILE_INFORMATION) == 8);
+
+/* Information of FileRenameInformation. */
+typedef struct _FILE_RENAME_INFORMATION {
+ BOOLEAN ReplaceIfExists;
+ /* Directory the name is relative to, or NULL. */
+ HANDLE RootDirectory;
+ OBJECT_STRING FileName;
+} FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;
+
+C_ASSERT(__builtin_offsetof(FILE_RENAME_INFORMATION, RootDirectory) == 0x04);
+C_ASSERT(__builtin_offsetof(FILE_RENAME_INFORMATION, FileName) == 0x08);
+C_ASSERT(sizeof(FILE_RENAME_INFORMATION) == 0x10);
+
+/* Information of FileFsSizeInformation. */
+typedef struct _FILE_FS_SIZE_INFORMATION {
+ LARGE_INTEGER TotalAllocationUnits;
+ LARGE_INTEGER AvailableAllocationUnits;
+ ULONG SectorsPerAllocationUnit;
+ ULONG BytesPerSector;
+} FILE_FS_SIZE_INFORMATION, *PFILE_FS_SIZE_INFORMATION;
+
+C_ASSERT(sizeof(FILE_FS_SIZE_INFORMATION) == 0x18);
+
+/* Information of FileFsDeviceInformation. */
+typedef struct _FILE_FS_DEVICE_INFORMATION {
+ /* A FILE_DEVICE_* value. */
+ ULONG DeviceType;
+ ULONG Characteristics;
+} FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
+
+C_ASSERT(sizeof(FILE_FS_DEVICE_INFORMATION) == 8);
+
+/*
+ * Information of FileFsAttributeInformation. The file system name,
+ * FileSystemNameLength bytes, follows at 0xc.
+ */
+typedef struct _FILE_FS_ATTRIBUTE_INFORMATION {
+ /* FILE_* file system flags. */
+ ULONG FileSystemAttributes;
+ LONG MaximumComponentNameLength;
+ ULONG FileSystemNameLength;
+ CHAR FileSystemName[];
+} FILE_FS_ATTRIBUTE_INFORMATION, *PFILE_FS_ATTRIBUTE_INFORMATION;
+
+C_ASSERT(__builtin_offsetof(FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName) == 0xc);
+C_ASSERT(sizeof(FILE_FS_ATTRIBUTE_INFORMATION) == 0xc);
+
+/* Element of the segment array of NtReadFileScatter and NtWriteFileGather: a page address. */
+typedef PVOID FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
+
+/* ------------------------------------------------------------------------- */
+/* Devices and device control */
+/* ------------------------------------------------------------------------- */
+
+/* FILE_DEVICE_*: the type of a device. */
+#define FILE_DEVICE_CD_ROM 0x02
+#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x03
+#define FILE_DEVICE_CONTROLLER 0x04
+#define FILE_DEVICE_DISK 0x07
+#define FILE_DEVICE_DISK_FILE_SYSTEM 0x08
+#define FILE_DEVICE_FILE_SYSTEM 0x09
+#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x14
+#define FILE_DEVICE_MASS_STORAGE 0x2d
+#define FILE_DEVICE_FLASH 0x3c
+#define FILE_DEVICE_STFS 0x3d
+#define FILE_DEVICE_SVOD 0x40
+#define FILE_DEVICE_MMC_FLASH 0x48
+#define FILE_DEVICE_MMC_FLASH_PARTITION 0x49
+
+/* Device control codes: device type, required access, function and buffering method. */
+#define CTL_CODE(DeviceType, Function, Method, Access) \
+ (((ULONG)(DeviceType) << 16) | ((ULONG)(Access) << 14) | ((ULONG)(Function) << 2) | \
+ (ULONG)(Method))
+
+#define METHOD_BUFFERED 0
+#define METHOD_IN_DIRECT 1
+#define METHOD_OUT_DIRECT 2
+#define METHOD_NEITHER 3
+
+#define FILE_ANY_ACCESS 0
+#define FILE_READ_ACCESS 0x0001
+#define FILE_WRITE_ACCESS 0x0002
+
+/* The sector count and the sector size: a DISK_GEOMETRY. */
+#define IOCTL_DISK_GET_DRIVE_GEOMETRY \
+ CTL_CODE(FILE_DEVICE_DISK, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)
+/* The start offset and the length in bytes: a PARTITION_INFORMATION. */
+#define IOCTL_DISK_GET_PARTITION_INFO \
+ CTL_CODE(FILE_DEVICE_DISK, 1, METHOD_BUFFERED, FILE_READ_ACCESS)
+/* A SCSI command described by a SCSI_PASS_THROUGH_DIRECT input. */
+#define IOCTL_SCSI_PASS_THROUGH_DIRECT 0x0004D014
+/* The 0x14-byte flash geometry; words 0 and 2 multiply to the write unit of the device. */
+#define IOCTL_FLASH_GEOMETRY 0x003C0028
+/* The authentication state of the optical drive. */
+#define IOCTL_ODD_AUTH_STATE 0x000240CC
+
+/* Output of IOCTL_DISK_GET_DRIVE_GEOMETRY. */
+typedef struct _DISK_GEOMETRY {
+ ULONG Sectors;
+ ULONG BytesPerSector;
+} DISK_GEOMETRY, *PDISK_GEOMETRY;
+
+C_ASSERT(sizeof(DISK_GEOMETRY) == 8);
+
+/* Output of IOCTL_DISK_GET_PARTITION_INFO. */
+typedef struct _PARTITION_INFORMATION {
+ /* Byte offset of the partition on the disk. */
+ LARGE_INTEGER StartingOffset;
+ /* Length of the partition in bytes. */
+ LARGE_INTEGER PartitionLength;
+} PARTITION_INFORMATION, *PPARTITION_INFORMATION;
+
+C_ASSERT(sizeof(PARTITION_INFORMATION) == 0x10);
+
+/*
+ * Input of IOCTL_SCSI_PASS_THROUGH_DIRECT. The device transfers data
+ * directly to or from DataBuffer.
+ */
+typedef struct _SCSI_PASS_THROUGH_DIRECT {
+ /* Size of the structure in bytes. */
+ USHORT Length;
+ UCHAR Reserved02[5];
+ /* Meaning unknown. */
+ UCHAR Unknown07;
+ /* Bytes to transfer. */
+ ULONG DataTransferLength;
+ ULONG Reserved0C;
+ /* Address of the transfer buffer. */
+ PVOID DataBuffer;
+ /* Command descriptor block. */
+ UCHAR Cdb[16];
+} SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
+
+C_ASSERT(__builtin_offsetof(SCSI_PASS_THROUGH_DIRECT, Unknown07) == 0x07);
+C_ASSERT(__builtin_offsetof(SCSI_PASS_THROUGH_DIRECT, DataTransferLength) == 0x08);
+C_ASSERT(__builtin_offsetof(SCSI_PASS_THROUGH_DIRECT, DataBuffer) == 0x10);
+C_ASSERT(__builtin_offsetof(SCSI_PASS_THROUGH_DIRECT, Cdb) == 0x14);
+C_ASSERT(sizeof(SCSI_PASS_THROUGH_DIRECT) == 0x24);
+
+/* The standard data of a SCSI INQUIRY command. */
+typedef struct _SCSI_INQUIRY_DATA {
+ /* Peripheral qualifier and device type. */
+ UCHAR DeviceType;
+ /* Bit 7: removable medium. */
+ UCHAR Removable;
+ UCHAR Version;
+ /* Response data format in the low four bits. */
+ UCHAR ResponseFormat;
+ /* Bytes that follow this one. */
+ UCHAR AdditionalLength;
+ UCHAR Flags[3];
+ /* ASCII vendor identification. */
+ CHAR VendorId[8];
+ /* ASCII product identification. */
+ CHAR ProductId[16];
+ /* ASCII product revision level. */
+ CHAR ProductRevision[4];
+} SCSI_INQUIRY_DATA, *PSCSI_INQUIRY_DATA;
+
+C_ASSERT(__builtin_offsetof(SCSI_INQUIRY_DATA, VendorId) == 0x08);
+C_ASSERT(__builtin_offsetof(SCSI_INQUIRY_DATA, ProductId) == 0x10);
+C_ASSERT(__builtin_offsetof(SCSI_INQUIRY_DATA, ProductRevision) == 0x20);
+C_ASSERT(sizeof(SCSI_INQUIRY_DATA) == 0x24);
+
+/* ------------------------------------------------------------------------- */
+/* I/O request packets, devices and drivers */
+/* ------------------------------------------------------------------------- */
+
+/* IRP_MJ_*: the major function of an I/O request. */
+#define IRP_MJ_CREATE 0x00
+#define IRP_MJ_CLOSE 0x01
+#define IRP_MJ_READ 0x02
+#define IRP_MJ_WRITE 0x03
+#define IRP_MJ_QUERY_INFORMATION 0x04
+#define IRP_MJ_SET_INFORMATION 0x05
+#define IRP_MJ_FLUSH_BUFFERS 0x06
+#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x07
+#define IRP_MJ_DIRECTORY_CONTROL 0x08
+#define IRP_MJ_DEVICE_CONTROL 0x09
+#define IRP_MJ_CLEANUP 0x0a
+#define IRP_MJ_MAXIMUM_FUNCTION 0x0a
+
+/* Flags of IO_STACK_LOCATION. */
+/* The buffer of a read or write is the transfer address, not an offset into Irp->UserBuffer. */
+#define SL_FSCACHE_REQUEST 0x01
+
+/* SL_* control bits of IO_STACK_LOCATION. */
+#define SL_PENDING_RETURNED 0x01
+#define SL_INVOKE_ON_CANCEL 0x20
+#define SL_INVOKE_ON_SUCCESS 0x40
+#define SL_INVOKE_ON_ERROR 0x80
+
+/* DO_* flags of DEVICE_OBJECT. */
+#define DO_DIRECT_IO 0x00000004
+#define DO_DEVICE_HAS_NAME 0x00000008
+/* Set at creation. The driver clears it once the device is ready. */
+#define DO_DEVICE_INITIALIZING 0x00000010
+
+/* Priority boosts of IoCompleteRequest. */
+#define IO_NO_INCREMENT 0
+#define IO_CD_ROM_INCREMENT 1
+#define IO_DISK_INCREMENT 1
+
+struct _DEVICE_OBJECT;
+struct _IRP;
+
+typedef NTSTATUS (*PIO_COMPLETION_ROUTINE)(
+ struct _DEVICE_OBJECT *DeviceObject,
+ struct _IRP *Irp,
+ PVOID Context);
+
+/*
+ * The part of a request for one driver. The locations of a request are
+ * contiguous; the next driver's location is the one before the current one.
+ * The parameters are 4-byte aligned: ByteOffset is at offset 12.
+ */
+#pragma pack(push, 4)
+typedef struct _IO_STACK_LOCATION {
+ /* An IRP_MJ_* value. */
+ UCHAR MajorFunction;
+ UCHAR MinorFunction;
+ UCHAR Flags;
+ UCHAR Control;
+ union {
+ struct {
+ ULONG Length;
+ union {
+ /* Offset into Irp->UserBuffer, without SL_FSCACHE_REQUEST. */
+ ULONG BufferOffset;
+ /* With SL_FSCACHE_REQUEST. */
+ PVOID CacheBuffer;
+ };
+ LARGE_INTEGER ByteOffset;
+ } Read;
+ struct {
+ ULONG Length;
+ union {
+ ULONG BufferOffset;
+ PVOID CacheBuffer;
+ };
+ LARGE_INTEGER ByteOffset;
+ } Write;
+ struct {
+ ULONG OutputBufferLength;
+ PVOID InputBuffer;
+ ULONG InputBufferLength;
+ ULONG IoControlCode;
+ } DeviceIoControl;
+ struct {
+ ULONG Length;
+ FILE_INFORMATION_CLASS FileInformationClass;
+ } QueryFile;
+ struct {
+ ULONG Length;
+ FS_INFORMATION_CLASS FsInformationClass;
+ } QueryVolume;
+ struct {
+ PVOID Argument1;
+ PVOID Argument2;
+ PVOID Argument3;
+ PVOID Argument4;
+ } Others;
+ } Parameters;
+ struct _DEVICE_OBJECT *DeviceObject;
+ struct _FILE_OBJECT *FileObject;
+ PIO_COMPLETION_ROUTINE CompletionRoutine;
+ PVOID Context;
+} IO_STACK_LOCATION, *PIO_STACK_LOCATION;
+#pragma pack(pop)
+
+C_ASSERT(__builtin_offsetof(IO_STACK_LOCATION, Control) == 3);
+C_ASSERT(__builtin_offsetof(IO_STACK_LOCATION, Parameters) == 4);
+C_ASSERT(__builtin_offsetof(IO_STACK_LOCATION, Parameters.Read.ByteOffset) == 12);
+C_ASSERT(__builtin_offsetof(IO_STACK_LOCATION, DeviceObject) == 0x14);
+C_ASSERT(__builtin_offsetof(IO_STACK_LOCATION, CompletionRoutine) == 0x1c);
+C_ASSERT(__builtin_offsetof(IO_STACK_LOCATION, Context) == 0x20);
+C_ASSERT(sizeof(IO_STACK_LOCATION) == 0x24);
+
+/* An I/O request packet. The kernel allocates it with its stack locations. */
+typedef struct _IRP {
+ SHORT Type;
+ USHORT Size;
+ ULONG Flags;
+ LIST_ENTRY ThreadListEntry;
+ IO_STATUS_BLOCK IoStatus;
+ CHAR StackCount;
+ /* Index of the current stack location. */
+ CHAR CurrentLocation;
+ BOOLEAN PendingReturned;
+ BOOLEAN Cancel;
+ PVOID UserBuffer;
+ PIO_STATUS_BLOCK UserIosb;
+ PKEVENT UserEvent;
+ union {
+ struct {
+ PIO_APC_ROUTINE UserApcRoutine;
+ PVOID UserApcContext;
+ } AsynchronousParameters;
+ LARGE_INTEGER AllocationSize;
+ } Overlay;
+ union {
+ struct {
+ /* KDEVICE_QUEUE_ENTRY (ke.h), or the key of an I/O completion packet. */
+ ULONG DeviceQueueEntry[4];
+ /* Length of the buffer locked by IoLockUserBuffer. */
+ ULONG LockedBufferLength;
+ struct _ETHREAD *Thread;
+ LIST_ENTRY ListEntry;
+ PIO_STACK_LOCATION CurrentStackLocation;
+ struct _FILE_OBJECT *OriginalFileObject;
+ } Overlay;
+ /* KAPC (ke.h). */
+ ULONG Apc[10];
+ } Tail;
+ /* Called with the cancel spin lock held; it releases the lock. */
+ VOID (*CancelRoutine)(struct _DEVICE_OBJECT *DeviceObject, struct _IRP *Irp);
+ ULONG Reserved1;
+} IRP, *PIRP;
+
+C_ASSERT(__builtin_offsetof(IRP, IoStatus) == 0x10);
+C_ASSERT(__builtin_offsetof(IRP, CurrentLocation) == 0x19);
+C_ASSERT(__builtin_offsetof(IRP, UserBuffer) == 0x1c);
+C_ASSERT(__builtin_offsetof(IRP, UserIosb) == 0x20);
+C_ASSERT(__builtin_offsetof(IRP, Overlay) == 0x28);
+C_ASSERT(__builtin_offsetof(IRP, Tail.Overlay.LockedBufferLength) == 0x40);
+C_ASSERT(__builtin_offsetof(IRP, Tail.Overlay.CurrentStackLocation) == 0x50);
+C_ASSERT(__builtin_offsetof(IRP, Tail.Overlay.OriginalFileObject) == 0x54);
+C_ASSERT(sizeof(IRP) == 0x60);
+
+/* A driver routine for a request. */
+typedef NTSTATUS (*PDRIVER_DISPATCH)(struct _DEVICE_OBJECT *DeviceObject, PIRP Irp);
+/* The start I/O routine of a driver. */
+typedef VOID (*PDRIVER_STARTIO)(struct _DEVICE_OBJECT *DeviceObject, PIRP Irp);
+typedef VOID (*PDRIVER_DELETEDEVICE)(struct _DEVICE_OBJECT *DeviceObject);
+typedef NTSTATUS (*PDRIVER_DISMOUNTVOLUME)(struct _DEVICE_OBJECT *DeviceObject);
+
+/* The routines of a driver. */
+typedef struct _DRIVER_OBJECT {
+ PDRIVER_STARTIO DriverStartIo;
+ PDRIVER_DELETEDEVICE DriverDeleteDevice;
+ PDRIVER_DISMOUNTVOLUME DriverDismountVolume;
+ /* The routine of each IRP_MJ_* function. */
+ PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
+} DRIVER_OBJECT, *PDRIVER_OBJECT;
+
+C_ASSERT(__builtin_offsetof(DRIVER_OBJECT, MajorFunction) == 0xc);
+C_ASSERT(sizeof(DRIVER_OBJECT) == 0x38);
+
+/* A device object. The kernel allocates it and its extension. */
+typedef struct _DEVICE_OBJECT {
+ SHORT Type;
+ USHORT Size;
+ LONG ReferenceCount;
+ PDRIVER_OBJECT DriverObject;
+ /* File system device mounted on this device, or the device itself. */
+ struct _DEVICE_OBJECT *MountedOrSelfDevice;
+ PIRP CurrentIrp;
+ /* DO_* flags. */
+ ULONG Flags;
+ PVOID DeviceExtension;
+ UCHAR DeviceType;
+ UCHAR StartIoFlags;
+ /* Stack locations a request to the device needs. */
+ CHAR StackSize;
+ BOOLEAN DeletePending;
+ ULONG SectorSize;
+ /* Mask of the address bits a transfer buffer must have clear. */
+ ULONG AlignmentRequirement;
+ /* KDEVICE_QUEUE (ke.h). */
+ ULONG DeviceQueue[4];
+ KEVENT DeviceLock;
+ ULONG StartIoCount;
+ ULONG StartIoKey;
+} DEVICE_OBJECT, *PDEVICE_OBJECT;
+
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, DriverObject) == 8);
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, CurrentIrp) == 0x10);
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, Flags) == 0x14);
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, DeviceExtension) == 0x18);
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, StackSize) == 0x1e);
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, AlignmentRequirement) == 0x24);
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, DeviceQueue) == 0x28);
+C_ASSERT(__builtin_offsetof(DEVICE_OBJECT, DeviceLock) == 0x38);
+C_ASSERT(sizeof(DEVICE_OBJECT) == 0x50);
+
+/* ------------------------------------------------------------------------- */
+/* File system cache */
+/* ------------------------------------------------------------------------- */
+
+/** Returns the element count of a file system cache. ProcessType is a KPROCESS_TYPE value. */
+XBOXKRNL_IMPORT(0x020) ULONG FscGetCacheElementCount(ULONG ProcessType);
+
+/** Sets the element count of a file system cache. ProcessType is a KPROCESS_TYPE value. */
+XBOXKRNL_IMPORT(0x021) NTSTATUS FscSetCacheElementCount(ULONG ProcessType, ULONG ElementCount);
+
+/* ------------------------------------------------------------------------- */
+/* I/O manager */
+/* ------------------------------------------------------------------------- */
+
+/** Acquires the device object lock. Returns the IRQL that IoReleaseDeviceObjectLock restores. */
+XBOXKRNL_IMPORT(0x02E) KIRQL IoAcquireDeviceObjectLock(VOID);
+
+/** Allocates an I/O request packet with StackSize stack locations. Returns it or NULL. */
+XBOXKRNL_IMPORT(0x02F) PIRP IoAllocateIrp(CHAR StackSize);
+
+/** Completes an I/O request packet. */
+XBOXKRNL_IMPORT(0x035) VOID IoCompleteRequest(PIRP Irp, CHAR PriorityBoost);
+
+/** Creates a device object for a driver. The device object address is stored at DeviceObject. */
+XBOXKRNL_IMPORT(0x037) NTSTATUS IoCreateDevice(
+ PDRIVER_OBJECT DriverObject,
+ ULONG DeviceExtensionSize,
+ POBJECT_STRING DeviceName,
+ ULONG DeviceType,
+ ULONG Attributes,
+ PDEVICE_OBJECT *DeviceObject);
+
+/** Object type of device objects. */
+XBOXKRNL_IMPORT(0x03A) extern struct _OBJECT_TYPE *__imp_IoDeviceObjectType;
+#define IoDeviceObjectType (*__imp_IoDeviceObjectType)
+
+/** Dismounts the file system volume on a device object. */
+XBOXKRNL_IMPORT(0x03B) NTSTATUS IoDismountVolume(PDEVICE_OBJECT DeviceObject);
+
+/** Dismounts the file system volume that an open file belongs to. */
+XBOXKRNL_IMPORT(0x03C) NTSTATUS IoDismountVolumeByFileHandle(HANDLE FileHandle);
+
+/** Completes an I/O request packet with an invalid device request status. */
+XBOXKRNL_IMPORT(0x041) NTSTATUS IoInvalidDeviceRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+
+/** Releases the device object lock and restores OldIrql. */
+XBOXKRNL_IMPORT(0x044) VOID IoReleaseDeviceObjectLock(KIRQL OldIrql);
+
+/** Starts the next queued I/O request packet of a device. */
+XBOXKRNL_IMPORT(0x048) VOID IoStartNextPacket(PDEVICE_OBJECT DeviceObject);
+
+/** Starts or queues an I/O request packet on a device. */
+XBOXKRNL_IMPORT(0x04A) VOID IoStartPacket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PULONG Key);
+
+/** Sends a device I/O control request to a device object and waits for it. */
+XBOXKRNL_IMPORT(0x04B) NTSTATUS IoSynchronousDeviceIoControlRequest(
+ ULONG IoControlCode,
+ PDEVICE_OBJECT DeviceObject,
+ PVOID InputBuffer,
+ ULONG InputBufferLength,
+ PVOID OutputBuffer,
+ ULONG OutputBufferLength,
+ PULONG ReturnedOutputBufferLength);
+
+/** Sends a read or write request (an IRP_MJ_* value) to a device object and waits for it. */
+XBOXKRNL_IMPORT(0x04C) NTSTATUS IoSynchronousFsdRequest(
+ ULONG MajorFunction,
+ PDEVICE_OBJECT DeviceObject,
+ PVOID Buffer,
+ ULONG Length,
+ PLARGE_INTEGER StartingOffset);
+
+/* ------------------------------------------------------------------------- */
+/* File system calls */
+/* ------------------------------------------------------------------------- */
+
+/** Creates or opens a file. */
+XBOXKRNL_IMPORT(0x0D2) NTSTATUS NtCreateFile(
+ PHANDLE FileHandle,
+ ACCESS_MASK DesiredAccess,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PLARGE_INTEGER AllocationSize,
+ ULONG FileAttributes,
+ ULONG ShareAccess,
+ CREATE_DISPOSITION CreateDisposition,
+ ULONG CreateOptions);
+
+/** Deletes a file. */
+XBOXKRNL_IMPORT(0x0D8) NTSTATUS NtDeleteFile(POBJECT_ATTRIBUTES ObjectAttributes);
+
+/** Sends a device I/O control request through a file handle. */
+XBOXKRNL_IMPORT(0x0D9) NTSTATUS NtDeviceIoControlFile(
+ HANDLE FileHandle,
+ HANDLE Event,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ ULONG IoControlCode,
+ PVOID InputBuffer,
+ ULONG InputBufferLength,
+ PVOID OutputBuffer,
+ ULONG OutputBufferLength);
+
+/** Writes buffered data of a file to the device. */
+XBOXKRNL_IMPORT(0x0DB) NTSTATUS NtFlushBuffersFile(
+ HANDLE FileHandle,
+ PIO_STATUS_BLOCK IoStatusBlock);
+
+/** Opens a file. */
+XBOXKRNL_IMPORT(0x0DF) NTSTATUS NtOpenFile(
+ PHANDLE FileHandle,
+ ACCESS_MASK DesiredAccess,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ ULONG ShareAccess,
+ ULONG OpenOptions);
+
+/** Reads directory entries. FileName is an optional wildcard pattern. */
+XBOXKRNL_IMPORT(0x0E4) NTSTATUS NtQueryDirectoryFile(
+ HANDLE FileHandle,
+ HANDLE Event,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID FileInformation,
+ ULONG Length,
+ POBJECT_STRING FileName,
+ BOOLEAN RestartScan);
+
+/** Reads the network open information of a file by name. */
+XBOXKRNL_IMPORT(0x0E7) NTSTATUS NtQueryFullAttributesFile(
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ PFILE_NETWORK_OPEN_INFORMATION FileInformation);
+
+/** Reads information of class FileInformationClass about an open file. */
+XBOXKRNL_IMPORT(0x0E8) NTSTATUS NtQueryInformationFile(
+ HANDLE FileHandle,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID FileInformation,
+ ULONG Length,
+ FILE_INFORMATION_CLASS FileInformationClass);
+
+/** Reads information of class FsInformationClass about a volume. */
+XBOXKRNL_IMPORT(0x0EF) NTSTATUS NtQueryVolumeInformationFile(
+ HANDLE FileHandle,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID FsInformation,
+ ULONG Length,
+ FS_INFORMATION_CLASS FsInformationClass);
+
+/**
+ * Reads from a file. A NULL ByteOffset reads at the current position. A NULL
+ * Event signals the file handle.
+ */
+XBOXKRNL_IMPORT(0x0F0) NTSTATUS NtReadFile(
+ HANDLE FileHandle,
+ HANDLE Event,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID Buffer,
+ ULONG Length,
+ PLARGE_INTEGER ByteOffset);
+
+/** Reads from a file into a list of page-sized segments. */
+XBOXKRNL_IMPORT(0x0F1) NTSTATUS NtReadFileScatter(
+ HANDLE FileHandle,
+ HANDLE Event,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PFILE_SEGMENT_ELEMENT SegmentArray,
+ ULONG Length,
+ PLARGE_INTEGER ByteOffset);
+
+/** Writes information of class FileInformationClass about an open file. */
+XBOXKRNL_IMPORT(0x0F7) NTSTATUS NtSetInformationFile(
+ HANDLE FileHandle,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID FileInformation,
+ ULONG Length,
+ FILE_INFORMATION_CLASS FileInformationClass);
+
+/**
+ * Writes to a file. A NULL ByteOffset writes at the current position. A NULL
+ * Event signals the file handle.
+ */
+XBOXKRNL_IMPORT(0x0FF) NTSTATUS NtWriteFile(
+ HANDLE FileHandle,
+ HANDLE Event,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID Buffer,
+ ULONG Length,
+ PLARGE_INTEGER ByteOffset);
+
+/** Writes to a file from a list of page-sized segments. */
+XBOXKRNL_IMPORT(0x100) NTSTATUS NtWriteFileGather(
+ HANDLE FileHandle,
+ HANDLE Event,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PFILE_SEGMENT_ELEMENT SegmentArray,
+ ULONG Length,
+ PLARGE_INTEGER ByteOffset);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/ke.h b/platform/xex/sdk/include/xbox360/xboxkrnl/ke.h
new file mode 100644
index 0000000..d7618f0
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/ke.h
@@ -0,0 +1,518 @@
+/*
+ * Kernel executive (Ke): dispatcher objects (semaphores, timers, DPCs),
+ * spin locks, interrupt levels, waits, threads and processor registers.
+ */
+
+#ifndef XBOX360_XBOXKRNL_KE_H
+#define XBOX360_XBOXKRNL_KE_H
+
+#include <xbox360/base.h>
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Interrupt request levels. */
+#define PASSIVE_LEVEL 0
+#define APC_LEVEL 1
+#define DISPATCH_LEVEL 2
+
+/* KeSetEvent priority increment for the waiters an event releases. */
+#define EVENT_INCREMENT 1
+
+/* Bug check codes; codes not named here are module-specific. */
+#define KMODE_EXCEPTION_NOT_HANDLED 0x0000001E
+
+/* KeTlsAlloc result when no index is free. */
+#define TLS_OUT_OF_INDEXES 0xFFFFFFFF
+
+/* A set of hardware threads; bit n is hardware thread n. */
+typedef ULONG KAFFINITY, *PKAFFINITY;
+
+/* Spin lock: one word, 0 when free. */
+typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
+
+/* Process type of a thread, as KeGetCurrentProcessType reports it. */
+typedef enum _KPROCESS_TYPE {
+ PROCESS_TYPE_IDLE = 0,
+ /* The title process. */
+ PROCESS_TYPE_TITLE = 1,
+ PROCESS_TYPE_SYSTEM = 2,
+} KPROCESS_TYPE;
+
+typedef enum _TIMER_TYPE {
+ /* Stays signaled until set again and releases every waiter. */
+ NotificationTimer = 0,
+ /* Releases one waiter and resets itself. */
+ SynchronizationTimer = 1,
+} TIMER_TYPE;
+
+/* How a wait on several objects ends. */
+typedef enum _WAIT_TYPE {
+ /* When every object is signaled. */
+ WaitAll = 0,
+ /* When any object is signaled; the status is STATUS_WAIT_0 plus its index. */
+ WaitAny = 1,
+} WAIT_TYPE;
+
+/* Why a thread waits. */
+typedef enum _KWAIT_REASON {
+ Executive = 0,
+ DelayExecution = 1,
+ Suspended = 2,
+ UserRequest = 3,
+ WrQueue = 4,
+ WrFsCacheIn = 5,
+ WrFsCacheOut = 6,
+ WrExecutive = 7,
+ WrCriticalSection = 8,
+} KWAIT_REASON;
+
+typedef struct _KSEMAPHORE {
+ DISPATCHER_HEADER Header;
+ LONG Limit;
+} KSEMAPHORE, *PKSEMAPHORE;
+
+C_ASSERT(sizeof(KSEMAPHORE) == 0x14);
+
+struct _KDPC;
+
+/* Routine of a deferred procedure call. */
+typedef VOID (*PKDEFERRED_ROUTINE)(
+ struct _KDPC *Dpc,
+ PVOID DeferredContext,
+ PVOID SystemArgument1,
+ PVOID SystemArgument2);
+
+/*
+ * Deferred procedure call. InsertedNumber is the hardware thread whose
+ * queue holds the DPC plus one, 0 when not queued. TargetNumber is the
+ * hardware thread that runs it plus one, 0 for the one that queues it;
+ * KeInitializeDpc clears it, so set it afterwards.
+ */
+typedef struct _KDPC {
+ SHORT Type;
+ UCHAR InsertedNumber;
+ UCHAR TargetNumber;
+ LIST_ENTRY DpcListEntry;
+ PKDEFERRED_ROUTINE DeferredRoutine;
+ PVOID DeferredContext;
+ PVOID SystemArgument1;
+ PVOID SystemArgument2;
+} KDPC, *PKDPC;
+
+C_ASSERT(__builtin_offsetof(KDPC, TargetNumber) == 3);
+C_ASSERT(__builtin_offsetof(KDPC, DeferredRoutine) == 0x0C);
+C_ASSERT(sizeof(KDPC) == 0x1C);
+
+typedef struct _KTIMER {
+ DISPATCHER_HEADER Header;
+ ULARGE_INTEGER DueTime;
+ LIST_ENTRY TimerListEntry;
+ PKDPC Dpc;
+ LONG Period;
+} KTIMER, *PKTIMER;
+
+C_ASSERT(__builtin_offsetof(KTIMER, DueTime) == 0x10);
+C_ASSERT(__builtin_offsetof(KTIMER, TimerListEntry) == 0x18);
+C_ASSERT(__builtin_offsetof(KTIMER, Dpc) == 0x20);
+C_ASSERT(sizeof(KTIMER) == 0x28);
+
+/* Links a waiting thread to one object of its wait. */
+typedef struct _KWAIT_BLOCK {
+ LIST_ENTRY WaitListEntry;
+ struct _KTHREAD *Thread;
+ PVOID Object;
+ struct _KWAIT_BLOCK *NextWaitBlock;
+ USHORT WaitKey;
+ USHORT WaitType;
+} KWAIT_BLOCK, *PKWAIT_BLOCK;
+
+C_ASSERT(__builtin_offsetof(KWAIT_BLOCK, WaitKey) == 0x14);
+C_ASSERT(sizeof(KWAIT_BLOCK) == 0x18);
+
+/* Start routine of a thread. */
+typedef VOID (*PKSTART_ROUTINE)(PVOID StartContext);
+
+/* Routine that a new thread runs first; it calls StartRoutine(StartContext). */
+typedef VOID (*PKSYSTEM_ROUTINE)(PKSTART_ROUTINE StartRoutine, PVOID StartContext);
+
+/* Routine that KeIpiGenericCall runs on every processor. */
+typedef ULONG_PTR (*PKIPI_BROADCAST_WORKER)(ULONG_PTR Argument);
+
+/*
+ * Registers the kernel saves on an interrupt or exception, up to the last
+ * field in use.
+ */
+typedef struct _KTRAP_FRAME {
+ ULONG StackFrameHeader[0x14];
+ ULONGLONG Gpr[32];
+ /* Exception record or interrupt state. */
+ ULONG Reserved1[0x14];
+ ULONGLONG Ctr;
+ ULONG Lr;
+ ULONG Iar;
+ ULONG Cr;
+ /* Low word of the saved MSR. */
+ ULONG Msr;
+ ULONG Xer;
+ ULONG UserModeState;
+} KTRAP_FRAME, *PKTRAP_FRAME;
+
+C_ASSERT(__builtin_offsetof(KTRAP_FRAME, Gpr) == 0x50);
+C_ASSERT(__builtin_offsetof(KTRAP_FRAME, Lr) == 0x1A8);
+C_ASSERT(__builtin_offsetof(KTRAP_FRAME, Iar) == 0x1AC);
+C_ASSERT(__builtin_offsetof(KTRAP_FRAME, Msr) == 0x1B4);
+C_ASSERT(__builtin_offsetof(KTRAP_FRAME, Xer) == 0x1B8);
+C_ASSERT(sizeof(KTRAP_FRAME) == 0x1C0);
+
+/*
+ * Thread object, up to the last field in use. The kernel allocates it and
+ * frees it after the thread ends.
+ */
+typedef struct _KTHREAD {
+ /* SignalState is nonzero once the thread has ended. */
+ DISPATCHER_HEADER Header;
+ UCHAR Reserved1[0x48];
+ /* 1 ms clock ticks that the thread ran. */
+ ULONG RunTime;
+ /* Highest address of the stack. */
+ PVOID StackBase;
+ /* Lowest address of the stack. */
+ PVOID StackLimit;
+ /* Frame the thread saved when it last stopped running. */
+ PVOID SwitchFrame;
+ /* Thread local storage block. */
+ PVOID TlsData;
+ UCHAR Reserved2[4];
+ UCHAR Priority;
+ UCHAR Reserved3;
+ /* KPROCESS_TYPE of the process that owns the thread. */
+ UCHAR ProcessType;
+ /* KPROCESS_TYPE that KeGetCurrentProcessType reports for the thread. */
+ UCHAR CurrentProcessType;
+ UCHAR Reserved4[0x10];
+ /* Process that owns the thread. */
+ struct _KPROCESS *Process;
+ UCHAR Reserved5[0x30];
+ UCHAR PriorityDecrement;
+ UCHAR BasePriority;
+ UCHAR Reserved6;
+ UCHAR Saturation;
+ UCHAR SuspendCount;
+ UCHAR Reserved7[2];
+ /* Hardware thread the thread runs or last ran on. */
+ UCHAR CurrentProcessor;
+ UCHAR Reserved8[9];
+ /* Priority that KeSetBasePriorityThread adds its increment to. */
+ UCHAR ProcessPriority;
+ /* Highest base priority that KeSetBasePriorityThread sets. */
+ UCHAR PriorityLimit;
+ UCHAR Reserved9[0x45];
+ /* Link in the thread list of the process. */
+ LIST_ENTRY ThreadListEntry;
+ UCHAR Reserved10[0x18];
+ /* Creation time as a FILETIME. */
+ ULARGE_INTEGER CreateTime;
+ UCHAR Reserved11[8];
+ NTSTATUS ExitStatus;
+ UCHAR Reserved12[8];
+ ULONG UniqueThread;
+ PVOID StartAddress;
+ UCHAR Reserved13[8];
+ /* Word for the debug monitor's own use. */
+ ULONG DebugMonitorData;
+ /* Win32 last error. */
+ ULONG LastWin32ErrorCode;
+ UCHAR Reserved14[8];
+ /* ExCreateThread creation flags. */
+ ULONG CreateOptions;
+} KTHREAD, *PKTHREAD;
+
+C_ASSERT(__builtin_offsetof(KTHREAD, RunTime) == 0x58);
+C_ASSERT(__builtin_offsetof(KTHREAD, TlsData) == 0x68);
+C_ASSERT(__builtin_offsetof(KTHREAD, Priority) == 0x70);
+C_ASSERT(__builtin_offsetof(KTHREAD, CurrentProcessType) == 0x73);
+C_ASSERT(__builtin_offsetof(KTHREAD, Process) == 0x84);
+C_ASSERT(__builtin_offsetof(KTHREAD, PriorityDecrement) == 0xB8);
+C_ASSERT(__builtin_offsetof(KTHREAD, SuspendCount) == 0xBC);
+C_ASSERT(__builtin_offsetof(KTHREAD, CurrentProcessor) == 0xBF);
+C_ASSERT(__builtin_offsetof(KTHREAD, ProcessPriority) == 0xC9);
+C_ASSERT(__builtin_offsetof(KTHREAD, PriorityLimit) == 0xCA);
+C_ASSERT(__builtin_offsetof(KTHREAD, ThreadListEntry) == 0x110);
+C_ASSERT(__builtin_offsetof(KTHREAD, CreateTime) == 0x130);
+C_ASSERT(__builtin_offsetof(KTHREAD, ExitStatus) == 0x140);
+C_ASSERT(__builtin_offsetof(KTHREAD, UniqueThread) == 0x14C);
+C_ASSERT(__builtin_offsetof(KTHREAD, StartAddress) == 0x150);
+C_ASSERT(__builtin_offsetof(KTHREAD, DebugMonitorData) == 0x15C);
+C_ASSERT(__builtin_offsetof(KTHREAD, LastWin32ErrorCode) == 0x160);
+C_ASSERT(__builtin_offsetof(KTHREAD, CreateOptions) == 0x16C);
+C_ASSERT(sizeof(KTHREAD) == 0x170);
+
+/* Process object, up to the thread list. */
+typedef struct _KPROCESS {
+ /* Guards ThreadListHead. */
+ KSPIN_LOCK ThreadListLock;
+ /* Head of the list of KTHREAD.ThreadListEntry links. */
+ LIST_ENTRY ThreadListHead;
+} KPROCESS, *PKPROCESS;
+
+C_ASSERT(__builtin_offsetof(KPROCESS, ThreadListHead) == 4);
+C_ASSERT(sizeof(KPROCESS) == 12);
+
+/* Times that the kernel updates on each clock tick. */
+typedef struct _KTIME_STAMP_BUNDLE {
+ ULONGLONG InterruptTime;
+ ULONGLONG SystemTime;
+ /* Milliseconds since boot. */
+ ULONG TickCount;
+ ULONG Reserved;
+} KTIME_STAMP_BUNDLE, *PKTIME_STAMP_BUNDLE;
+
+C_ASSERT(__builtin_offsetof(KTIME_STAMP_BUNDLE, TickCount) == 0x10);
+C_ASSERT(sizeof(KTIME_STAMP_BUNDLE) == 0x18);
+
+/* Special purpose registers of KeGetSpecialPurposeRegister and KeSetSpecialPurposeRegister. */
+/* Data address breakpoint register. */
+#define SPR_DABR 0x3F5
+/* Performance monitor control: bit 1 freezes and bit 2 enables the counters. */
+#define SPR_MONITOR_CONTROL 0x3F6
+/* Performance monitor event selection. */
+#define SPR_EVENT_SELECT 0x3FA
+
+/* Performance monitor bus registers of KeGetPMWRegister and KeSetPMWRegister. */
+#define PMW_NCU0 0x480
+#define PMW_NCU1 0x580
+#define PMW_NCU2 0x680
+#define PMW_CIU 0x708
+#define PMW_BIU 0xB50
+#define PMW_L2_GROUP 0x310
+#define PMW_L2 0x318
+#define PMW_L2_ECC 0x860
+
+/* Performance monitor registers of KeSetPRVRegister; values are in the high word. */
+#define PRV_RUN 0x1C0
+#define PRV_INTERVAL_CONTROL 0x1C8
+#define PRV_TRIGGER 0x1D8
+#define PRV_INTERVAL 0x1E0
+#define PRV_INTERVAL_RELOAD 0x1E8
+/* Value and control registers of counter Counter (0 to 15). */
+#define PRV_COUNTER_VALUE(Counter) (0x200 + (Counter) * 8)
+#define PRV_COUNTER_CONTROL(Counter) (0x280 + (Counter) * 8)
+
+/** Acquires a spin lock. The caller is already at DISPATCH_LEVEL. */
+XBOXKRNL_IMPORT(0x04D) VOID KeAcquireSpinLockAtRaisedIrql(PKSPIN_LOCK SpinLock);
+
+/** Halts the system with a bug check code. */
+XBOXKRNL_IMPORT(0x052) DECLSPEC_NORETURN VOID KeBugCheck(ULONG BugCheckCode);
+
+/** Halts the system with a bug check code and four parameters. */
+XBOXKRNL_IMPORT(0x053) DECLSPEC_NORETURN VOID KeBugCheckEx(
+ ULONG BugCheckCode,
+ ULONG_PTR BugCheckParameter1,
+ ULONG_PTR BugCheckParameter2,
+ ULONG_PTR BugCheckParameter3,
+ ULONG_PTR BugCheckParameter4);
+
+/** Cancels a timer. True when the timer was set. */
+XBOXKRNL_IMPORT(0x054) BOOLEAN KeCancelTimer(PKTIMER Timer);
+
+/* CONTEXT is defined in rtl.h; DEBUG_MONITOR_DATA belongs to the debug monitor service. */
+struct _CONTEXT;
+struct _DEBUG_MONITOR_DATA;
+
+/** Builds a thread context from kernel trap frames. */
+XBOXKRNL_IMPORT(0x056) VOID KeContextFromKframes(PKTRAP_FRAME TrapFrame, struct _CONTEXT *ContextRecord);
+
+/**
+ * Address of the debug monitor data block that the kernel reads, or 0.
+ * The debug monitor stores it. While a block is published, the kernel
+ * calls the routines it names, so the block must stay valid and its
+ * routine fields must hold routines of the expected form.
+ */
+XBOXKRNL_IMPORT(0x059) extern struct _DEBUG_MONITOR_DATA **__imp_KeDebugMonitorData;
+#define KeDebugMonitorData (*__imp_KeDebugMonitorData)
+
+/** Suspends the current thread for Interval (100 ns units; negative is relative). */
+XBOXKRNL_IMPORT(0x05A) NTSTATUS KeDelayExecutionThread(
+ KPROCESSOR_MODE WaitMode,
+ BOOLEAN Alertable,
+ PLARGE_INTEGER Interval);
+
+/** Enables the processor performance monitor. */
+XBOXKRNL_IMPORT(0x05E) ULONG KeEnablePPUPerformanceMonitor(VOID);
+
+/** Disables normal kernel APC delivery to the current thread. */
+XBOXKRNL_IMPORT(0x05F) VOID KeEnterCriticalRegion(VOID);
+
+/** Flushes the data cache for an address range. */
+XBOXKRNL_IMPORT(0x061) VOID KeFlushCacheRange(PVOID BaseAddress, ULONG Length);
+
+/** Returns the process type of the current thread. */
+XBOXKRNL_IMPORT(0x066) KPROCESS_TYPE KeGetCurrentProcessType(VOID);
+
+/** Reads a performance monitor register. */
+XBOXKRNL_IMPORT(0x067) ULONGLONG KeGetPMWRegister(ULONG Register);
+
+/** Reads a special purpose register. Only the low word of the result is returned. */
+XBOXKRNL_IMPORT(0x06A) ULONG KeGetSpecialPurposeRegister(ULONG Register);
+
+/** Initializes a deferred procedure call object. */
+XBOXKRNL_IMPORT(0x06F) VOID KeInitializeDpc(
+ PKDPC Dpc,
+ PKDEFERRED_ROUTINE DeferredRoutine,
+ PVOID DeferredContext);
+
+/** Initializes an event object. */
+XBOXKRNL_IMPORT(0x070) VOID KeInitializeEvent(PKEVENT Event, EVENT_TYPE Type, BOOLEAN State);
+
+/** Initializes a semaphore object with a count and limit. */
+XBOXKRNL_IMPORT(0x074) VOID KeInitializeSemaphore(PKSEMAPHORE Semaphore, LONG Count, LONG Limit);
+
+/**
+ * Initializes a timer object for processes of ProcessType. Stock XBDM
+ * passes PROCESS_TYPE_SYSTEM for its capture timer.
+ */
+XBOXKRNL_IMPORT(0x075) VOID KeInitializeTimerEx(PKTIMER Timer, TIMER_TYPE Type, UCHAR ProcessType);
+
+/** Queues a deferred procedure call. True when it was queued. */
+XBOXKRNL_IMPORT(0x07B) BOOLEAN KeInsertQueueDpc(
+ PKDPC Dpc,
+ PVOID SystemArgument1,
+ PVOID SystemArgument2);
+
+/** Runs BroadcastFunction(Context) on every processor at IPI level. */
+XBOXKRNL_IMPORT(0x07C) ULONG_PTR KeIpiGenericCall(
+ PKIPI_BROADCAST_WORKER BroadcastFunction,
+ ULONG_PTR Context);
+
+/** Enables normal kernel APC delivery to the current thread. */
+XBOXKRNL_IMPORT(0x07D) VOID KeLeaveCriticalRegion(VOID);
+
+/** Returns the timebase frequency. */
+XBOXKRNL_IMPORT(0x083) ULONGLONG KeQueryPerformanceFrequency(VOID);
+
+/** Stores the system time as a FILETIME. */
+XBOXKRNL_IMPORT(0x084) VOID KeQuerySystemTime(PLARGE_INTEGER CurrentTime);
+
+/** Raises the IRQL to DISPATCH_LEVEL. Returns the previous IRQL. */
+XBOXKRNL_IMPORT(0x085) KIRQL KeRaiseIrqlToDpcLevel(VOID);
+
+/** Releases a semaphore object. Returns the previous count. */
+XBOXKRNL_IMPORT(0x088) LONG KeReleaseSemaphore(
+ PKSEMAPHORE Semaphore,
+ KPRIORITY Increment,
+ LONG Adjustment,
+ BOOLEAN Wait);
+
+/** Releases a spin lock without changing the IRQL. */
+XBOXKRNL_IMPORT(0x089) VOID KeReleaseSpinLockFromRaisedIrql(PKSPIN_LOCK SpinLock);
+
+/** Removes a deferred procedure call from the queue. True when it was queued. */
+XBOXKRNL_IMPORT(0x08E) BOOLEAN KeRemoveQueueDpc(PKDPC Dpc);
+
+/** Sets an event object to not signaled. Returns the previous state. */
+XBOXKRNL_IMPORT(0x08F) LONG KeResetEvent(PKEVENT Event);
+
+/** Decrements the suspend count of a thread object. Returns the previous count. */
+XBOXKRNL_IMPORT(0x092) ULONG KeResumeThread(PKTHREAD Thread);
+
+/** Sets the processor affinity of a thread. The previous affinity is stored at PreviousAffinity. */
+XBOXKRNL_IMPORT(0x097) NTSTATUS KeSetAffinityThread(
+ PKTHREAD Thread,
+ KAFFINITY Affinity,
+ PKAFFINITY PreviousAffinity);
+
+/** Sets the base priority increment of a thread object. */
+XBOXKRNL_IMPORT(0x099) LONG KeSetBasePriorityThread(PKTHREAD Thread, LONG Increment);
+
+/**
+ * Sets an event object to signaled. Returns the previous state. Increment
+ * is usually EVENT_INCREMENT.
+ */
+XBOXKRNL_IMPORT(0x09D) LONG KeSetEvent(PKEVENT Event, KPRIORITY Increment, BOOLEAN Wait);
+
+/** Writes a performance monitor register. The export takes the 64-bit Value in one register. */
+XBOXKRNL_IMPORT(0x09F) VOID KeSetPMWRegister(ULONG Register, ULONGLONG Value);
+
+/** Writes a performance monitor register. The export takes the 64-bit Value in one register. */
+XBOXKRNL_IMPORT(0x0A1) VOID KeSetPRVRegister(ULONG Register, ULONGLONG Value);
+
+/** Sets the priority of a thread object. Returns the previous priority. */
+XBOXKRNL_IMPORT(0x0A3) KPRIORITY KeSetPriorityThread(PKTHREAD Thread, KPRIORITY Priority);
+
+/** Writes a special purpose register. The export takes the 64-bit Value in one register. */
+XBOXKRNL_IMPORT(0x0A5) ULONG KeSetSpecialPurposeRegister(ULONG Register, ULONGLONG Value);
+
+/**
+ * Sets a timer to expire at DueTime (100 ns units; negative is relative to
+ * now), then every Period milliseconds when Period is not 0. Dpc is queued
+ * at expiry when not NULL. True when the timer was already set.
+ * DueTime is a LARGE_INTEGER passed by value, in one register.
+ */
+XBOXKRNL_IMPORT(0x0A7) BOOLEAN KeSetTimerEx(PKTIMER Timer, LONGLONG DueTime, LONG Period, PKDPC Dpc);
+
+/** Busy-waits for MicroSeconds. */
+XBOXKRNL_IMPORT(0x0A8) VOID KeStallExecutionProcessor(ULONG MicroSeconds);
+
+/** Increments the suspend count of a thread object. Returns the previous count. */
+XBOXKRNL_IMPORT(0x0A9) ULONG KeSuspendThread(PKTHREAD Thread);
+
+/** Invalidates the instruction cache for an address range. */
+XBOXKRNL_IMPORT(0x0AB) VOID KeSweepIcacheRange(PVOID BaseAddress, SIZE_T Length);
+
+/** Kernel time stamp bundle. */
+XBOXKRNL_IMPORT(0x0AD) extern PKTIME_STAMP_BUNDLE __imp_KeTimeStampBundle;
+#define KeTimeStampBundle (*__imp_KeTimeStampBundle)
+
+/** Tries to acquire a spin lock at DISPATCH_LEVEL. True when acquired. */
+XBOXKRNL_IMPORT(0x0AE) BOOLEAN KeTryToAcquireSpinLockAtRaisedIrql(PKSPIN_LOCK SpinLock);
+
+/**
+ * Waits on several dispatcher objects. WaitBlockArray may be NULL for up
+ * to four objects.
+ */
+XBOXKRNL_IMPORT(0x0AF) NTSTATUS KeWaitForMultipleObjects(
+ ULONG Count,
+ PVOID *Object,
+ WAIT_TYPE WaitType,
+ KWAIT_REASON WaitReason,
+ KPROCESSOR_MODE WaitMode,
+ BOOLEAN Alertable,
+ PLARGE_INTEGER Timeout,
+ PKWAIT_BLOCK WaitBlockArray);
+
+/** Waits on a dispatcher object. A NULL Timeout waits without limit. */
+XBOXKRNL_IMPORT(0x0B0) NTSTATUS KeWaitForSingleObject(
+ PVOID Object,
+ KWAIT_REASON WaitReason,
+ KPROCESSOR_MODE WaitMode,
+ BOOLEAN Alertable,
+ PLARGE_INTEGER Timeout);
+
+/** Raises the IRQL to DISPATCH_LEVEL and acquires a spin lock. Returns the previous IRQL. */
+XBOXKRNL_IMPORT(0x0B1) KIRQL KfAcquireSpinLock(PKSPIN_LOCK SpinLock);
+
+/** Raises the IRQL. Returns the previous IRQL. */
+XBOXKRNL_IMPORT(0x0B2) KIRQL KfRaiseIrql(KIRQL NewIrql);
+
+/** Lowers the IRQL. */
+XBOXKRNL_IMPORT(0x0B3) VOID KfLowerIrql(KIRQL NewIrql);
+
+/** Releases a spin lock and restores OldIrql. */
+XBOXKRNL_IMPORT(0x0B4) VOID KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql);
+
+/** Allocates a thread local storage index. Returns TLS_OUT_OF_INDEXES when none is free. */
+XBOXKRNL_IMPORT(0x152) ULONG KeTlsAlloc(VOID);
+
+/** Frees a thread local storage index. True on success. */
+XBOXKRNL_IMPORT(0x153) BOOLEAN KeTlsFree(ULONG Index);
+
+/** Returns the value of a thread local storage index for the current thread. */
+XBOXKRNL_IMPORT(0x154) PVOID KeTlsGetValue(ULONG Index);
+
+/** Sets the value of a thread local storage index for the current thread. True on success. */
+XBOXKRNL_IMPORT(0x155) BOOLEAN KeTlsSetValue(ULONG Index, PVOID Value);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/mm.h b/platform/xex/sdk/include/xbox360/xboxkrnl/mm.h
new file mode 100644
index 0000000..f669850
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/mm.h
@@ -0,0 +1,175 @@
+/*
+ * Memory manager: virtual and physical memory, page protection and memory
+ * statistics.
+ */
+
+#ifndef XBOX360_XBOXKRNL_MM_H
+#define XBOX360_XBOXKRNL_MM_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Allocation and free types of the virtual memory calls. */
+#define MEM_COMMIT 0x00001000
+#define MEM_RESERVE 0x00002000
+#define MEM_DECOMMIT 0x00004000
+#define MEM_RELEASE 0x00008000
+#define MEM_FREE 0x00010000
+#define MEM_PRIVATE 0x00020000
+#define MEM_RESET 0x00080000
+#define MEM_TOP_DOWN 0x00100000
+#define MEM_NOZERO 0x00800000
+#define MEM_LARGE_PAGES 0x20000000 /* 64 KB pages */
+#define MEM_HEAP 0x40000000
+#define MEM_16MB_PAGES 0x80000000 /* 16 MB pages */
+
+/*
+ * Page protection. The physical memory calls take MEM_LARGE_PAGES or
+ * MEM_16MB_PAGES in the same word.
+ */
+#define PAGE_NOACCESS 0x0001
+#define PAGE_READONLY 0x0002
+#define PAGE_READWRITE 0x0004
+#define PAGE_WRITECOPY 0x0008
+#define PAGE_EXECUTE 0x0010
+#define PAGE_EXECUTE_READ 0x0020
+#define PAGE_EXECUTE_READWRITE 0x0040
+#define PAGE_EXECUTE_WRITECOPY 0x0080
+#define PAGE_GUARD 0x0100
+#define PAGE_NOCACHE 0x0200
+#define PAGE_WRITECOMBINE 0x0400
+
+/*
+ * Memory region of the physical and virtual memory calls. The kernel
+ * rejects other values. The debug regions count as the extra memory of a
+ * development kit.
+ */
+#define MM_CURRENT_PROCESS_REGION 0 /* title region for a title thread, else system */
+#define MM_TITLE_REGION 1
+#define MM_SYSTEM_REGION 2
+#define MM_TITLE_DEBUG_REGION 3
+#define MM_SYSTEM_DEBUG_REGION 4
+
+/* Region that contains an address, as NtQueryVirtualMemory fills it. */
+typedef struct _MEMORY_BASIC_INFORMATION {
+ PVOID BaseAddress;
+ PVOID AllocationBase;
+ ULONG AllocationProtect;
+ SIZE_T RegionSize;
+ ULONG State; /* MEM_COMMIT, MEM_RESERVE or MEM_FREE */
+ ULONG Protect;
+ ULONG Type; /* MEM_PRIVATE for an allocated region */
+} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
+
+C_ASSERT(sizeof(MEMORY_BASIC_INFORMATION) == 0x1C);
+C_ASSERT(__builtin_offsetof(MEMORY_BASIC_INFORMATION, RegionSize) == 0xC);
+
+/* Memory statistics of MmQueryStatistics. The caller sets Length. */
+typedef struct _MM_STATISTICS {
+ ULONG Length;
+ ULONG TotalPhysicalPages;
+ ULONG KernelPages;
+ ULONG TitleAvailablePages;
+ ULONG TitleTotalVirtualMemoryBytes;
+ ULONG TitleReservedVirtualMemoryBytes;
+ ULONG TitlePhysicalPages;
+ ULONG TitlePoolPages;
+ ULONG TitleStackPages;
+ ULONG TitleImagePages;
+ ULONG TitleHeapPages;
+ ULONG TitleVirtualPages;
+ ULONG TitlePageTablePages;
+ ULONG TitleCachePages;
+ ULONG SystemAvailablePages;
+ ULONG SystemTotalVirtualMemoryBytes;
+ ULONG SystemReservedVirtualMemoryBytes;
+ ULONG SystemPhysicalPages;
+ ULONG SystemPoolPages;
+ ULONG SystemStackPages;
+ ULONG SystemImagePages;
+ ULONG SystemHeapPages;
+ ULONG SystemVirtualPages;
+ ULONG SystemPageTablePages;
+ ULONG SystemCachePages;
+ ULONG HighestPhysicalPage;
+} MM_STATISTICS, *PMM_STATISTICS;
+
+C_ASSERT(sizeof(MM_STATISTICS) == 0x68);
+C_ASSERT(__builtin_offsetof(MM_STATISTICS, TitleAvailablePages) == 0xC);
+C_ASSERT(__builtin_offsetof(MM_STATISTICS, SystemAvailablePages) == 0x38);
+C_ASSERT(__builtin_offsetof(MM_STATISTICS, HighestPhysicalPage) == 0x64);
+
+/** Allocates physical memory. Returns the address or NULL. */
+XBOXKRNL_IMPORT(0x0B9) PVOID MmAllocatePhysicalMemory(LONG MemoryRegionType, SIZE_T NumberOfBytes, ULONG Protect);
+
+/**
+ * Allocates physical memory within an address range and alignment.
+ * Returns the address or NULL.
+ */
+XBOXKRNL_IMPORT(0x0BA) PVOID MmAllocatePhysicalMemoryEx(
+ LONG MemoryRegionType,
+ SIZE_T NumberOfBytes,
+ ULONG Protect,
+ ULONG_PTR LowestAcceptableAddress,
+ ULONG_PTR HighestAcceptableAddress,
+ ULONG_PTR Alignment
+);
+
+/** Frees physical memory that MmAllocatePhysicalMemoryEx allocated in MemoryRegionType. */
+XBOXKRNL_IMPORT(0x0BD) VOID MmFreePhysicalMemory(LONG MemoryRegionType, PVOID BaseAddress);
+
+/** Translates a mapped virtual address to its physical address. */
+XBOXKRNL_IMPORT(0x0BE) ULONG MmGetPhysicalAddress(PVOID BaseAddress);
+
+/** True when an address is mapped. */
+XBOXKRNL_IMPORT(0x0BF) BOOLEAN MmIsAddressValid(PVOID VirtualAddress);
+
+/** Returns the page protection of an address. */
+XBOXKRNL_IMPORT(0x0C4) ULONG MmQueryAddressProtect(PVOID VirtualAddress);
+
+/** Returns the size of the allocation that contains an address. */
+XBOXKRNL_IMPORT(0x0C5) SIZE_T MmQueryAllocationSize(PVOID BaseAddress);
+
+/** Fills MemoryStatistics, whose Length field the caller sets. */
+XBOXKRNL_IMPORT(0x0C6) NTSTATUS MmQueryStatistics(PMM_STATISTICS MemoryStatistics);
+
+/** Returns the address when the debugger may read it, else NULL. */
+XBOXKRNL_IMPORT(0x1AB) PVOID MmDbgReadCheck(PVOID VirtualAddress);
+
+/** Releases a mapping that MmDbgWriteCheck created. */
+XBOXKRNL_IMPORT(0x1AC) VOID MmDbgReleaseAddress(PVOID VirtualAddress, PULONG Opaque);
+
+/**
+ * Maps VirtualAddress writable for the debugger. Returns the mapped
+ * address, else NULL. Opaque receives the state MmDbgReleaseAddress restores.
+ */
+XBOXKRNL_IMPORT(0x1AD) PVOID MmDbgWriteCheck(PVOID VirtualAddress, PULONG Opaque);
+
+/** Reserves or commits virtual memory. Base and size are updated in place. */
+XBOXKRNL_IMPORT(0x0CC) NTSTATUS NtAllocateVirtualMemory(
+ PVOID *BaseAddress,
+ PSIZE_T RegionSize,
+ ULONG AllocationType,
+ ULONG Protect,
+ LONG MemoryRegionType
+);
+
+/** Decommits or releases virtual memory. Base and size are updated in place. */
+XBOXKRNL_IMPORT(0x0DC) NTSTATUS NtFreeVirtualMemory(
+ PVOID *BaseAddress,
+ PSIZE_T RegionSize,
+ ULONG FreeType,
+ LONG MemoryRegionType
+);
+
+/** Fills a memory basic information structure for an address. */
+XBOXKRNL_IMPORT(0x0EE) NTSTATUS NtQueryVirtualMemory(
+ PVOID BaseAddress,
+ PMEMORY_BASIC_INFORMATION MemoryInformation,
+ LONG MemoryRegionType
+);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/nic.h b/platform/xex/sdk/include/xbox360/xboxkrnl/nic.h
new file mode 100644
index 0000000..9012c3c
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/nic.h
@@ -0,0 +1,53 @@
+/*
+ * Network controller driver statistics.
+ */
+
+#ifndef XBOX360_XBOXKRNL_NIC_H
+#define XBOX360_XBOXKRNL_NIC_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Devices behind the NIC driver, as bits of a device mask. */
+#define NIC_DEVICE_EMAC 0x00000001
+#define NIC_DEVICE_WIRELESS 0x00000002
+#define NIC_DEVICE_KD 0x00000010
+
+/* Classes of a received frame by its destination address. */
+typedef enum _NIC_FRAME_CLASS {
+ NicFrameOther,
+ NicFramePrimaryUnicast,
+ NicFrameSecondaryUnicast,
+ NicFrameMulticast,
+ NicFrameBroadcast,
+ NicFrameClassCount
+} NIC_FRAME_CLASS;
+
+/*
+ * Counters of one device; NicGetStats adds them over the devices of a mask.
+ * The structure is 4-byte packed.
+ */
+#pragma pack(push, 4)
+typedef struct _NIC_STATS {
+ ULONGLONG XmitBytes;
+ ULONGLONG RecvBytes[NicFrameClassCount];
+ ULONG XmitPackets;
+ ULONG RecvPackets[NicFrameClassCount];
+ ULONG XmitUnderrunErrors;
+ ULONG XmitOtherErrors;
+ ULONG RecvOverrunErrors;
+ ULONG RecvFrameErrors;
+ ULONG RecvOtherErrors;
+} NIC_STATS, *PNIC_STATS;
+#pragma pack(pop)
+
+C_ASSERT(__builtin_offsetof(NIC_STATS, XmitPackets) == 0x30);
+C_ASSERT(sizeof(NIC_STATS) == 0x5C);
+
+/** Fills a network interface statistics structure for the NIC_DEVICE_* bits of DeviceMask. */
+XBOXKRNL_IMPORT(0x209) ULONG NicGetStats(ULONG DeviceMask, PNIC_STATS Stats);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/ntdef.h b/platform/xex/sdk/include/xbox360/xboxkrnl/ntdef.h
new file mode 100644
index 0000000..64e5121
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/ntdef.h
@@ -0,0 +1,95 @@
+/*
+ * Kernel types that most imports use: counted strings, object attributes,
+ * I/O status blocks and the dispatcher header of waitable objects.
+ */
+
+#ifndef XBOX360_XBOXKRNL_NTDEF_H
+#define XBOX360_XBOXKRNL_NTDEF_H
+
+#include <xbox360/base.h>
+
+XBOX360_EXTERN_C_START
+
+typedef UCHAR KPROCESSOR_MODE;
+typedef UCHAR KIRQL, *PKIRQL;
+typedef LONG KPRIORITY;
+
+#define KernelMode 0
+#define UserMode 1
+
+/* Counted 8-bit string; lengths are in bytes. */
+typedef struct _STRING {
+ USHORT Length;
+ USHORT MaximumLength;
+ PCHAR Buffer;
+} STRING, *PSTRING;
+
+typedef STRING ANSI_STRING, *PANSI_STRING;
+typedef STRING OBJECT_STRING, *POBJECT_STRING;
+
+/* Counted 16-bit string; lengths are in bytes. */
+typedef struct _UNICODE_STRING {
+ USHORT Length;
+ USHORT MaximumLength;
+ PWSTR Buffer;
+} UNICODE_STRING, *PUNICODE_STRING;
+
+C_ASSERT(sizeof(STRING) == 8);
+C_ASSERT(sizeof(UNICODE_STRING) == 8);
+
+/* Object attributes. The console layout has no length or security fields. */
+typedef struct _OBJECT_ATTRIBUTES {
+ HANDLE RootDirectory;
+ POBJECT_STRING ObjectName;
+ ULONG Attributes;
+} OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
+
+C_ASSERT(sizeof(OBJECT_ATTRIBUTES) == 12);
+
+#define OBJ_INHERIT 0x00000002
+#define OBJ_PERMANENT 0x00000010
+#define OBJ_EXCLUSIVE 0x00000020
+#define OBJ_CASE_INSENSITIVE 0x00000040
+#define OBJ_OPENIF 0x00000080
+#define OBJ_OPENLINK 0x00000100
+#define OBJ_KERNEL_HANDLE 0x00000200
+
+/* Final status and information of an I/O request. */
+typedef struct _IO_STATUS_BLOCK {
+ union {
+ NTSTATUS Status;
+ PVOID Pointer;
+ };
+ ULONG_PTR Information;
+} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
+
+C_ASSERT(sizeof(IO_STATUS_BLOCK) == 8);
+
+typedef VOID (*PIO_APC_ROUTINE)(PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved);
+
+/* Header of every object a thread can wait on. */
+typedef struct _DISPATCHER_HEADER {
+ UCHAR Type;
+ UCHAR Absolute;
+ UCHAR ProcessType;
+ UCHAR Inserted;
+ LONG SignalState;
+ LIST_ENTRY WaitListHead;
+} DISPATCHER_HEADER, *PDISPATCHER_HEADER;
+
+C_ASSERT(sizeof(DISPATCHER_HEADER) == 16);
+
+typedef enum _EVENT_TYPE {
+ NotificationEvent = 0,
+ SynchronizationEvent = 1,
+} EVENT_TYPE;
+
+typedef struct _KEVENT {
+ DISPATCHER_HEADER Header;
+} KEVENT, *PKEVENT;
+
+C_ASSERT(sizeof(KEVENT) == 16);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/ob.h b/platform/xex/sdk/include/xbox360/xboxkrnl/ob.h
new file mode 100644
index 0000000..958da31
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/ob.h
@@ -0,0 +1,149 @@
+/*
+ * Object manager (Ob): object types, access masks, object directories and
+ * symbolic links.
+ */
+
+#ifndef XBOX360_XBOXKRNL_OB_H
+#define XBOX360_XBOXKRNL_OB_H
+
+#include <xbox360/base.h>
+#include <xbox360/xboxkrnl/ntdef.h>
+#include <xbox360/xboxkrnl/ke.h>
+
+XBOX360_EXTERN_C_START
+
+/* Standard and generic rights of an ACCESS_MASK. */
+#define DELETE 0x00010000
+#define READ_CONTROL 0x00020000
+#define WRITE_DAC 0x00040000
+#define WRITE_OWNER 0x00080000
+#define SYNCHRONIZE 0x00100000
+#define MAXIMUM_ALLOWED 0x02000000
+#define GENERIC_ALL 0x10000000
+#define GENERIC_EXECUTE 0x20000000
+#define GENERIC_WRITE 0x40000000
+#define GENERIC_READ 0x80000000
+
+/* Allocate the object from title or system memory regardless of the caller. */
+#define OBJ_TITLE_OBJECT 0x00001000
+#define OBJ_SYSTEM_OBJECT 0x00002000
+
+struct _OBJECT_TYPE;
+
+typedef PVOID (*OB_ALLOCATE_METHOD)(SIZE_T NumberOfBytes, ULONG Tag, ULONG PoolType);
+typedef VOID (*OB_FREE_METHOD)(PVOID Pointer);
+typedef VOID (*OB_CLOSE_METHOD)(PVOID Object, ULONG SystemHandleCount);
+typedef VOID (*OB_DELETE_METHOD)(PVOID Object);
+typedef NTSTATUS (*OB_PARSE_METHOD)(
+ PVOID ParseObject,
+ struct _OBJECT_TYPE *ObjectType,
+ ULONG Attributes,
+ POBJECT_STRING CompleteName,
+ POBJECT_STRING RemainingName,
+ PVOID Context,
+ PVOID *Object);
+
+/* An object type, such as ExThreadObjectType. Object calls take its address. */
+typedef struct _OBJECT_TYPE {
+ OB_ALLOCATE_METHOD AllocateProcedure;
+ OB_FREE_METHOD FreeProcedure;
+ OB_CLOSE_METHOD CloseProcedure;
+ OB_DELETE_METHOD DeleteProcedure;
+ OB_PARSE_METHOD ParseProcedure;
+ PVOID DefaultObject;
+ ULONG PoolTag;
+} OBJECT_TYPE, *POBJECT_TYPE;
+
+C_ASSERT(sizeof(OBJECT_TYPE) == 28);
+
+/* Entry of NtQueryDirectoryObject; the name characters follow it. */
+typedef struct _OBJECT_DIRECTORY_INFORMATION {
+ OBJECT_STRING Name;
+ /* PoolTag of the object's type. */
+ ULONG Type;
+} OBJECT_DIRECTORY_INFORMATION, *POBJECT_DIRECTORY_INFORMATION;
+
+C_ASSERT(sizeof(OBJECT_DIRECTORY_INFORMATION) == 12);
+
+/** Creates an object directory. */
+XBOXKRNL_IMPORT(0x0D0) NTSTATUS NtCreateDirectoryObject(
+ PHANDLE DirectoryHandle,
+ POBJECT_ATTRIBUTES ObjectAttributes);
+
+/** Opens an object directory. */
+XBOXKRNL_IMPORT(0x0DE) NTSTATUS NtOpenDirectoryObject(
+ PHANDLE DirectoryHandle,
+ POBJECT_ATTRIBUTES ObjectAttributes);
+
+/** Reads one entry of an object directory. Context holds the enumeration position. */
+XBOXKRNL_IMPORT(0x0E5) NTSTATUS NtQueryDirectoryObject(
+ HANDLE DirectoryHandle,
+ POBJECT_DIRECTORY_INFORMATION DirectoryInformation,
+ ULONG Length,
+ BOOLEAN RestartScan,
+ PULONG Context,
+ PULONG ReturnLength);
+
+/** Allocates an object of type ObjectType with a body of ObjectBodySize bytes. */
+XBOXKRNL_IMPORT(0x102) NTSTATUS ObCreateObject(
+ POBJECT_TYPE ObjectType,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ ULONG ObjectBodySize,
+ PVOID *Object);
+
+/** Creates a symbolic link object from SymbolicLinkName to DeviceName. */
+XBOXKRNL_IMPORT(0x103) NTSTATUS ObCreateSymbolicLink(
+ POBJECT_STRING SymbolicLinkName,
+ POBJECT_STRING DeviceName);
+
+/** Deletes the symbolic link object SymbolicLinkName. */
+XBOXKRNL_IMPORT(0x104) NTSTATUS ObDeleteSymbolicLink(POBJECT_STRING SymbolicLinkName);
+
+/** Releases a reference to an object. */
+XBOXKRNL_IMPORT(0x105) VOID ObDereferenceObject(PVOID Object);
+
+/**
+ * Inserts an object into the handle table and object directory. The handle
+ * is stored at Handle.
+ */
+XBOXKRNL_IMPORT(0x108) NTSTATUS ObInsertObject(
+ PVOID Object,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ ULONG ObjectPointerBias,
+ PHANDLE Handle);
+
+/** Finds a thread object by thread ID and references it. */
+XBOXKRNL_IMPORT(0x10A) NTSTATUS ObLookupAnyThreadByThreadId(HANDLE ThreadId, PKTHREAD *Thread);
+
+/** Removes the permanent flag of a named object. */
+XBOXKRNL_IMPORT(0x10C) VOID ObMakeTemporaryObject(PVOID Object);
+
+/** Opens a named object and stores a handle. */
+XBOXKRNL_IMPORT(0x10D) NTSTATUS ObOpenObjectByName(
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ POBJECT_TYPE ObjectType,
+ PVOID ParseContext,
+ PHANDLE Handle);
+
+/** References the object of a handle. A NULL ObjectType accepts any type. */
+XBOXKRNL_IMPORT(0x110) NTSTATUS ObReferenceObjectByHandle(
+ HANDLE Handle,
+ POBJECT_TYPE ObjectType,
+ PVOID *ReturnedObject);
+
+/** References a named object. Attributes are OBJ_* flags. */
+XBOXKRNL_IMPORT(0x111) NTSTATUS ObReferenceObjectByName(
+ POBJECT_STRING ObjectName,
+ ULONG Attributes,
+ POBJECT_TYPE ObjectType,
+ PVOID ParseContext,
+ PVOID *Object);
+
+/** Reads the target of a symbolic link object into OutputString. */
+XBOXKRNL_IMPORT(0x113) NTSTATUS ObTranslateSymbolicLink(
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ POBJECT_STRING OutputString);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/rtl.h b/platform/xex/sdk/include/xbox360/xboxkrnl/rtl.h
new file mode 100644
index 0000000..7aaabc8
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/rtl.h
@@ -0,0 +1,284 @@
+/*
+ * Run-time library (Rtl): critical sections, singly linked lists, thread
+ * contexts, image headers, debug output and formatting.
+ */
+
+#ifndef XBOX360_XBOXKRNL_RTL_H
+#define XBOX360_XBOXKRNL_RTL_H
+
+#include <xbox360/base.h>
+#include <xbox360/xboxkrnl/ntdef.h>
+#include <xbox360/xboxkrnl/ke.h>
+
+XBOX360_EXTERN_C_START
+
+/* Register groups of a CONTEXT that hold values (ContextFlags). */
+/* MSR, IAR, LR and CTR. */
+#define CONTEXT_CONTROL 0x00000001
+/* FPR and FPSCR. */
+#define CONTEXT_FLOATING_POINT 0x00000002
+/* GPR, CR and XER. */
+#define CONTEXT_INTEGER 0x00000004
+/* VR and VSCR. */
+#define CONTEXT_VECTOR 0x00000010
+/* Every register group, as RtlCaptureContext requests. */
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_VECTOR)
+
+/* The registers of a thread. The vector registers need 16-byte alignment. */
+typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
+ ULONG ContextFlags;
+ ULONG Msr;
+ ULONG Iar;
+ ULONG Lr;
+ ULONGLONG Ctr;
+ ULONGLONG Gpr[32];
+ ULONG Cr;
+ ULONG Xer;
+ /* Floating point values as IEEE bits. */
+ ULONGLONG Fpscr;
+ ULONGLONG Fpr[32];
+ ULONG UserModeState;
+ ULONG Reserved1;
+ ULONG Vscr[4];
+ ULONG Vr[128][4];
+} CONTEXT, *PCONTEXT;
+
+C_ASSERT(__builtin_offsetof(CONTEXT, Ctr) == 0x10);
+C_ASSERT(__builtin_offsetof(CONTEXT, Gpr) == 0x18);
+C_ASSERT(__builtin_offsetof(CONTEXT, Cr) == 0x118);
+C_ASSERT(__builtin_offsetof(CONTEXT, Fpscr) == 0x120);
+C_ASSERT(__builtin_offsetof(CONTEXT, Fpr) == 0x128);
+C_ASSERT(__builtin_offsetof(CONTEXT, Vscr) == 0x230);
+C_ASSERT(__builtin_offsetof(CONTEXT, Vr) == 0x240);
+C_ASSERT(sizeof(CONTEXT) == 0xA40);
+
+/*
+ * Critical section: a synchronization event that waiters block on, with the
+ * spin count in the second byte of the event header, and the ownership
+ * state. LockCount is -1 when the section is free.
+ */
+typedef struct _RTL_CRITICAL_SECTION {
+ union {
+ KEVENT Event;
+ struct {
+ UCHAR Type;
+ UCHAR SpinCount;
+ } Synchronization;
+ };
+ /* Count of entries minus one. */
+ LONG LockCount;
+ /* Count of recursive entries of the owner. */
+ LONG RecursionCount;
+ /* Thread that owns the section, or NULL. */
+ struct _KTHREAD *OwningThread;
+} RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
+
+C_ASSERT(__builtin_offsetof(RTL_CRITICAL_SECTION, LockCount) == 0x10);
+C_ASSERT(__builtin_offsetof(RTL_CRITICAL_SECTION, RecursionCount) == 0x14);
+C_ASSERT(__builtin_offsetof(RTL_CRITICAL_SECTION, OwningThread) == 0x18);
+C_ASSERT(sizeof(RTL_CRITICAL_SECTION) == 0x1C);
+
+/*
+ * Head of a sequenced singly linked list: Next in the high word, Depth and
+ * Sequence in the low word, updated as one doubleword.
+ */
+typedef union _SLIST_HEADER {
+ ULONGLONG Alignment;
+ struct {
+ SINGLE_LIST_ENTRY Next;
+ USHORT Depth;
+ USHORT Sequence;
+ };
+} SLIST_HEADER, *PSLIST_HEADER;
+
+C_ASSERT(sizeof(SLIST_HEADER) == 8);
+
+/*
+ * PE image headers. Image files are little-endian: multibyte fields hold
+ * the stored bytes and must be byte-swapped on read.
+ */
+
+/* IMAGE_FILE_HEADER.Characteristics */
+#define IMAGE_FILE_DLL 0x2000
+
+typedef struct _IMAGE_FILE_HEADER {
+ USHORT Machine;
+ USHORT NumberOfSections;
+ ULONG TimeDateStamp;
+ ULONG PointerToSymbolTable;
+ ULONG NumberOfSymbols;
+ USHORT SizeOfOptionalHeader;
+ USHORT Characteristics;
+} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
+
+C_ASSERT(sizeof(IMAGE_FILE_HEADER) == 20);
+
+typedef struct _IMAGE_DATA_DIRECTORY {
+ ULONG VirtualAddress;
+ ULONG Size;
+} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
+
+C_ASSERT(sizeof(IMAGE_DATA_DIRECTORY) == 8);
+
+#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
+
+typedef struct _IMAGE_OPTIONAL_HEADER {
+ USHORT Magic;
+ UCHAR MajorLinkerVersion;
+ UCHAR MinorLinkerVersion;
+ ULONG SizeOfCode;
+ ULONG SizeOfInitializedData;
+ ULONG SizeOfUninitializedData;
+ ULONG AddressOfEntryPoint;
+ ULONG BaseOfCode;
+ ULONG BaseOfData;
+ ULONG ImageBase;
+ ULONG SectionAlignment;
+ ULONG FileAlignment;
+ USHORT MajorOperatingSystemVersion;
+ USHORT MinorOperatingSystemVersion;
+ USHORT MajorImageVersion;
+ USHORT MinorImageVersion;
+ USHORT MajorSubsystemVersion;
+ USHORT MinorSubsystemVersion;
+ ULONG Win32VersionValue;
+ ULONG SizeOfImage;
+ ULONG SizeOfHeaders;
+ ULONG CheckSum;
+ USHORT Subsystem;
+ USHORT DllCharacteristics;
+ ULONG SizeOfStackReserve;
+ ULONG SizeOfStackCommit;
+ ULONG SizeOfHeapReserve;
+ ULONG SizeOfHeapCommit;
+ ULONG LoaderFlags;
+ ULONG NumberOfRvaAndSizes;
+ IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
+
+C_ASSERT(__builtin_offsetof(IMAGE_OPTIONAL_HEADER, SizeOfImage) == 56);
+C_ASSERT(__builtin_offsetof(IMAGE_OPTIONAL_HEADER, CheckSum) == 64);
+C_ASSERT(sizeof(IMAGE_OPTIONAL_HEADER) == 224);
+
+/* NT headers, as RtlImageNtHeader returns them. The section table follows the optional header. */
+typedef struct _IMAGE_NT_HEADERS {
+ ULONG Signature;
+ IMAGE_FILE_HEADER FileHeader;
+ IMAGE_OPTIONAL_HEADER OptionalHeader;
+} IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
+
+C_ASSERT(__builtin_offsetof(IMAGE_NT_HEADERS, OptionalHeader) == 24);
+C_ASSERT(sizeof(IMAGE_NT_HEADERS) == 248);
+
+#define IMAGE_SIZEOF_SHORT_NAME 8
+
+typedef struct _IMAGE_SECTION_HEADER {
+ /* The name, padded with NULs. A name of eight bytes has no NUL. */
+ UCHAR Name[IMAGE_SIZEOF_SHORT_NAME];
+ ULONG VirtualSize;
+ /* Offset of the section from the image base. */
+ ULONG VirtualAddress;
+ ULONG SizeOfRawData;
+ ULONG PointerToRawData;
+ ULONG PointerToRelocations;
+ ULONG PointerToLinenumbers;
+ USHORT NumberOfRelocations;
+ USHORT NumberOfLinenumbers;
+ ULONG Characteristics;
+} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
+
+C_ASSERT(sizeof(IMAGE_SECTION_HEADER) == 40);
+
+/* IMAGE_DEBUG_DIRECTORY.Type */
+#define IMAGE_DEBUG_TYPE_CODEVIEW 2
+
+/* One entry of the debug data directory. */
+typedef struct _IMAGE_DEBUG_DIRECTORY {
+ ULONG Characteristics;
+ ULONG TimeDateStamp;
+ USHORT MajorVersion;
+ USHORT MinorVersion;
+ ULONG Type;
+ ULONG SizeOfData;
+ /* Offset of the debug data from the image base. */
+ ULONG AddressOfRawData;
+ ULONG PointerToRawData;
+} IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
+
+C_ASSERT(__builtin_offsetof(IMAGE_DEBUG_DIRECTORY, AddressOfRawData) == 20);
+C_ASSERT(sizeof(IMAGE_DEBUG_DIRECTORY) == 28);
+
+/* Index of a PE data directory. */
+typedef enum _IMAGE_DIRECTORY_ENTRY {
+ /* The function table (.pdata). */
+ IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3,
+ IMAGE_DIRECTORY_ENTRY_DEBUG = 6,
+} IMAGE_DIRECTORY_ENTRY;
+
+/** Raises a breakpoint exception to the attached debugger. */
+XBOXKRNL_IMPORT(0x001) VOID DbgBreakPoint(VOID);
+
+/** Writes a formatted string to the debug output. */
+XBOXKRNL_IMPORT(0x003) ULONG DbgPrint(PCSZ Format, ...);
+
+/** Removes all entries from a singly linked list. Returns the first entry. */
+XBOXKRNL_IMPORT(0x02B) PSINGLE_LIST_ENTRY InterlockedFlushSList(PSLIST_HEADER ListHead);
+
+/** Removes the first entry from a singly linked list. Returns the entry or NULL. */
+XBOXKRNL_IMPORT(0x02C) PSINGLE_LIST_ENTRY InterlockedPopEntrySList(PSLIST_HEADER ListHead);
+
+/** Reports a failed assertion to the debugger. */
+XBOXKRNL_IMPORT(0x118) VOID RtlAssert(
+ PVOID FailedAssertion,
+ PVOID FileName,
+ ULONG LineNumber,
+ PCSZ Message);
+
+/** Stores the context of the current thread. */
+XBOXKRNL_IMPORT(0x119) VOID RtlCaptureContext(PCONTEXT ContextRecord);
+
+/** Enters a critical section. */
+XBOXKRNL_IMPORT(0x125) VOID RtlEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection);
+
+/** Stores the low and high stack limits of the current thread. */
+XBOXKRNL_IMPORT(0x12A) VOID RtlGetStackLimits(PULONG_PTR StackLimit, PULONG_PTR StackBase);
+
+/** Returns the value or address of an optional header field of a XEX header. Key is an XEX_HEADER_* key. */
+XBOXKRNL_IMPORT(0x12B) PVOID RtlImageXexHeaderField(PVOID XexHeaderBase, ULONG Key);
+
+/** Initializes a critical section. */
+XBOXKRNL_IMPORT(0x12E) VOID RtlInitializeCriticalSection(PRTL_CRITICAL_SECTION CriticalSection);
+
+/** Initializes a critical section with a spin count. */
+XBOXKRNL_IMPORT(0x12F) NTSTATUS RtlInitializeCriticalSectionAndSpinCount(
+ PRTL_CRITICAL_SECTION CriticalSection,
+ ULONG SpinCount);
+
+/** Leaves a critical section. */
+XBOXKRNL_IMPORT(0x130) VOID RtlLeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection);
+
+/** Converts an NTSTATUS value to a Win32 error code. */
+XBOXKRNL_IMPORT(0x135) ULONG RtlNtStatusToDosError(NTSTATUS Status);
+
+/** Tries to enter a critical section. True when entered. */
+XBOXKRNL_IMPORT(0x141) BOOLEAN RtlTryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection);
+
+/**
+ * Formats into Buffer from a va_list. ArgList is a console va_list: 8-byte
+ * slots, 32-bit values in the low word.
+ */
+XBOXKRNL_IMPORT(0x14D) INT _vsnprintf(PCHAR Buffer, SIZE_T Count, PCSZ Format, PVOID ArgList);
+
+/** Returns the address of a PE data directory of an image. Its size is stored at Size. */
+XBOXKRNL_IMPORT(0x1A8) PVOID RtlImageDirectoryEntryToData(
+ PVOID Base,
+ BOOLEAN MappedAsImage,
+ IMAGE_DIRECTORY_ENTRY DirectoryEntry,
+ PULONG Size);
+
+/** Returns the PE NT headers of an image, or NULL. */
+XBOXKRNL_IMPORT(0x1A9) PIMAGE_NT_HEADERS RtlImageNtHeader(PVOID Base);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/usb.h b/platform/xex/sdk/include/xbox360/xboxkrnl/usb.h
new file mode 100644
index 0000000..156253b
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/usb.h
@@ -0,0 +1,42 @@
+/*
+ * USB devices: controller radio and USB camera driver.
+ */
+
+#ifndef XBOX360_XBOXKRNL_USB_H
+#define XBOX360_XBOXKRNL_USB_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Completion routine of an asynchronous USB camera request. */
+typedef VOID (*PXUSBCAM_COMPLETION_ROUTINE)(LONG Status, PVOID Context);
+
+/** Turns the controller radio on or off. */
+XBOXKRNL_IMPORT(0x1EF) ULONG XInputdSetRFPowerMode(ULONG Enable);
+
+/** Writes one USB camera configuration value. */
+XBOXKRNL_IMPORT(0x21C) LONG XUsbcamSetConfig(
+ ULONG Camera,
+ ULONG Request,
+ ULONG Selector,
+ const UCHAR *Value,
+ ULONG Length,
+ PXUSBCAM_COMPLETION_ROUTINE CompletionRoutine,
+ PVOID Context);
+
+/** State of the USB camera driver. The dashboard reads 2 as ready. */
+XBOXKRNL_IMPORT(0x21D) ULONG XUsbcamGetState(VOID);
+
+/**
+ * Creates the USB camera driver context in Workspace and stores its camera
+ * handle. Returns zero on success.
+ */
+XBOXKRNL_IMPORT(0x222) ULONG XUsbcamCreate(PVOID Workspace, ULONG WorkspaceSize, PULONG Camera);
+
+/** Destroys a USB camera driver context. */
+XBOXKRNL_IMPORT(0x223) VOID XUsbcamDestroy(ULONG Camera);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/vd.h b/platform/xex/sdk/include/xbox360/xboxkrnl/vd.h
new file mode 100644
index 0000000..25707ef
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/vd.h
@@ -0,0 +1,239 @@
+/*
+ * Video display driver: display modes, the GPU command processor and front
+ * buffer swaps.
+ */
+
+#ifndef XBOX360_XBOXKRNL_VD_H
+#define XBOX360_XBOXKRNL_VD_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Display information block that VdGetCurrentDisplayInformation fills. */
+typedef struct _VD_DISPLAY_INFORMATION {
+ USHORT SurfaceWidth;
+ USHORT SurfaceHeight;
+ UCHAR ColorSpace;
+ UCHAR Reserved005[3];
+ ULONG Left;
+ ULONG Top;
+ ULONG Right;
+ ULONG Bottom;
+ ULONG ScaledWidth;
+ ULONG ScaledHeight;
+ ULONG Reserved020[14];
+} VD_DISPLAY_INFORMATION, *PVD_DISPLAY_INFORMATION;
+
+C_ASSERT(__builtin_offsetof(VD_DISPLAY_INFORMATION, ColorSpace) == 4);
+C_ASSERT(__builtin_offsetof(VD_DISPLAY_INFORMATION, Left) == 8);
+C_ASSERT(__builtin_offsetof(VD_DISPLAY_INFORMATION, ScaledHeight) == 0x1C);
+C_ASSERT(sizeof(VD_DISPLAY_INFORMATION) == 0x58);
+
+/*
+ * System command buffer descriptor that VdGetSystemCommandBuffer fills and
+ * VdSwap reads.
+ */
+typedef struct _VD_SYSTEM_COMMAND_BUFFER {
+ /* GPU address of the buffer, or 0 when the kernel has none. */
+ ULONG Address;
+ ULONG Dwords;
+ /* Nonzero when the following state is valid for the swap outputs. */
+ ULONG State;
+ ULONG Reserved00C[34];
+} VD_SYSTEM_COMMAND_BUFFER, *PVD_SYSTEM_COMMAND_BUFFER;
+
+C_ASSERT(sizeof(VD_SYSTEM_COMMAND_BUFFER) == 0x94);
+
+/* Parameter block of VdSetDisplayModeOverride. */
+typedef struct _VD_DISPLAY_MODE_OVERRIDE_PARAMETERS {
+ /* sizeof(VD_DISPLAY_MODE_OVERRIDE_PARAMETERS). */
+ ULONG Size;
+ ULONG Reserved004[2];
+ /* Retry index of the override. */
+ UCHAR Attempt;
+ UCHAR Reserved00D[3];
+} VD_DISPLAY_MODE_OVERRIDE_PARAMETERS, *PVD_DISPLAY_MODE_OVERRIDE_PARAMETERS;
+
+C_ASSERT(__builtin_offsetof(VD_DISPLAY_MODE_OVERRIDE_PARAMETERS, Attempt) == 0xC);
+C_ASSERT(sizeof(VD_DISPLAY_MODE_OVERRIDE_PARAMETERS) == 0x10);
+
+/*
+ * Block that VdGetDisplayDiscoveryData fills. Only bytes +0, +4 and the
+ * unaligned ULONG at +0x1D are known to be used.
+ */
+typedef struct _VD_DISPLAY_DISCOVERY_DATA {
+ ULONG Reserved000[20];
+} VD_DISPLAY_DISCOVERY_DATA, *PVD_DISPLAY_DISCOVERY_DATA;
+
+C_ASSERT(sizeof(VD_DISPLAY_DISCOVERY_DATA) == 0x50);
+
+/*
+ * Mode reported by VdEnumerateVideoModes. Source and Preference rank the
+ * EDID entry the mode came from; DisplayType is the display type value.
+ */
+#pragma pack(push, 2)
+typedef struct _VD_VIDEO_MODE_INFO {
+ USHORT Size;
+ USHORT Width;
+ USHORT Height;
+ UCHAR Source;
+ UCHAR Preference;
+ FLOAT RefreshRate;
+ ULONG ModeID : 8;
+ ULONG Reserved : 19;
+ ULONG Audio : 1;
+ ULONG YCbCr : 1;
+ ULONG Interlaced : 1;
+ ULONG StandardAspectRatio : 1;
+ ULONG Valid : 1;
+ ULONG PixelRate;
+ UCHAR DisplayType;
+ UCHAR PixelRepetition;
+} VD_VIDEO_MODE_INFO, *PVD_VIDEO_MODE_INFO;
+#pragma pack(pop)
+
+C_ASSERT(__builtin_offsetof(VD_VIDEO_MODE_INFO, RefreshRate) == 8);
+C_ASSERT(sizeof(VD_VIDEO_MODE_INFO) == 0x16);
+
+/* Called for each mode by VdEnumerateVideoModes; returns zero to stop. */
+typedef ULONG (*PVD_ENUMERATE_VIDEO_MODES_ROUTINE)(const VD_VIDEO_MODE_INFO *Mode, PVOID Context);
+
+/* Called by VdShutdownEngines with the context given to VdInitializeEngines. */
+typedef VOID (*PVD_ENGINES_SHUTDOWN_ROUTINE)(PVOID Context);
+
+/* Called by the graphics interrupt handler with (0, Context). */
+typedef VOID (*PVD_GRAPHICS_INTERRUPT_ROUTINE)(ULONG Source, PVOID Context);
+
+/**
+ * Makes the command processor write its ring read pointer, in dwords, to
+ * PhysicalAddress (dword aligned). BlockSizeLog2 is the read pointer block
+ * size field of the ring control register.
+ */
+XBOXKRNL_IMPORT(0x1B6) VOID VdEnableRingBufferRPtrWriteBack(ULONG PhysicalAddress, ULONG BlockSizeLog2);
+
+/** Fills a display information structure. */
+XBOXKRNL_IMPORT(0x1BA) VOID VdGetCurrentDisplayInformation(PVD_DISPLAY_INFORMATION DisplayInformation);
+
+/**
+ * Copies the next of the kernel's three system command buffer descriptors
+ * to Buffer and stores in Identifier the value the GPU writes to the
+ * identifier address once that buffer has run.
+ */
+XBOXKRNL_IMPORT(0x1BD) VOID VdGetSystemCommandBuffer(PVD_SYSTEM_COMMAND_BUFFER Buffer, PULONG Identifier);
+
+/**
+ * Gives the GPU command processor to the calling title: loads the CP
+ * microcode (the kernel's own when both pointers are null), stores
+ * ShutdownRoutine and Context for VdShutdownEngines and resets the engines.
+ * Unused is not read. Returns 1. Traps when the engines are already owned.
+ */
+XBOXKRNL_IMPORT(0x1C2) ULONG VdInitializeEngines(
+ ULONG Unused,
+ PVD_ENGINES_SHUTDOWN_ROUTINE ShutdownRoutine,
+ PVOID Context,
+ const ULONG *PrefetchMicrocode,
+ const ULONG *EngineMicrocode);
+
+/**
+ * Points the command processor ring at PhysicalAddress with
+ * 2^(SizeLog2 + 1) dwords and resets its read and write pointers.
+ */
+XBOXKRNL_IMPORT(0x1C3) VOID VdInitializeRingBuffer(ULONG PhysicalAddress, ULONG SizeLog2);
+
+/** Reads a video encoder register. */
+XBOXKRNL_IMPORT(0x1CB) ULONG VdReadDVERegisterUlong(ULONG Register);
+
+/**
+ * Programs the configured video mode. Flags selects display-off,
+ * forced-output, color-space, and pixel-format options.
+ */
+XBOXKRNL_IMPORT(0x1D3) VOID VdSetDisplayMode(ULONG Flags);
+
+/**
+ * Overrides the display mode; nonzero on success. Scan is 1 for interlaced
+ * and 2 for progressive [INFERENCE]; Parameters may be null. All zero
+ * arguments remove the override. RefreshRate is passed in f1 and the console
+ * ABI also reserves r5 for it, so Scan and Parameters are in r6 and r7.
+ */
+XBOXKRNL_IMPORT(0x1D4) ULONG VdSetDisplayModeOverride(
+ ULONG Width,
+ ULONG Height,
+ DOUBLE RefreshRate,
+ ULONG Scan,
+ const VD_DISPLAY_MODE_OVERRIDE_PARAMETERS *Parameters);
+
+/** Sets the routine the graphics interrupt handler calls with (0, Context), or none when null. */
+XBOXKRNL_IMPORT(0x1D5) VOID VdSetGraphicsInterruptCallback(PVD_GRAPHICS_INTERRUPT_ROUTINE Routine, PVOID Context);
+
+/**
+ * Sets the virtual address of the dword where the GPU writes the identifier
+ * of each finished system command buffer, or none when null.
+ */
+XBOXKRNL_IMPORT(0x1D9) VOID VdSetSystemCommandBufferGpuIdentifierAddress(PULONG Address);
+
+/**
+ * Waits for the GPU to idle, returns the command processor to the kernel's
+ * own ring and calls the shutdown routine of VdInitializeEngines.
+ */
+XBOXKRNL_IMPORT(0x1DC) VOID VdShutdownEngines(VOID);
+
+/** Writes a video encoder register. */
+XBOXKRNL_IMPORT(0x1E0) ULONG VdWriteDVERegisterUlong(ULONG Register, ULONG Value);
+
+/**
+ * Writes a 64-dword front buffer flip into Commands: when SystemBuffer holds
+ * a buffer, fetch constant 15 from the 6-dword FetchConstant (base address
+ * virtual) and an indirect buffer call of it, then an event write of
+ * Identifier to IdentifierAddress (virtual), padded with a NOP. The five
+ * outputs are written only when SystemBuffer carries optional state.
+ */
+XBOXKRNL_IMPORT(0x25B) VOID VdSwap(
+ PULONG Commands,
+ const ULONG *FetchConstant,
+ PULONG IdentifierAddress,
+ const VD_SYSTEM_COMMAND_BUFFER *SystemBuffer,
+ ULONG Identifier,
+ PULONG FrontBuffer,
+ PULONG TextureFormat,
+ PULONG ColorSpace,
+ PULONG Width,
+ PULONG Height);
+
+/**
+ * A step of EDRAM retraining. Returns 0 when nothing is due: VdHSIOTrainCount
+ * (export 0x26B) is nonzero and Flags has bit 1 clear. In state 0 it sets
+ * *State to 1, returns 1 and leaves *Commands alone, so a call with a null
+ * *Commands asks whether retraining is due. D3D then calls it with *Commands
+ * at free ring space until it returns 0, and takes the advanced *Commands as
+ * the end of what was written. Returns 0 without effect when *State is above
+ * 7, Capacity (dwords) below 0x928 or WorkBytes below 0x5C. A null State
+ * traps.
+ */
+XBOXKRNL_IMPORT(0x269) ULONG VdRetrainEDRAM(
+ ULONG Flags,
+ PULONG *Commands,
+ ULONG Capacity,
+ PULONG State,
+ PUCHAR Work,
+ ULONG WorkBytes);
+
+/**
+ * When VdHSIOTrainCount is 0: sends message 7 to the system management
+ * controller and stores byte 6 of the reply as the current EDRAM temperature
+ * of the retraining state. Returns 0.
+ */
+XBOXKRNL_IMPORT(0x26A) ULONG VdRetrainEDRAMWorker(ULONG Reserved);
+
+/**
+ * Calls Routine with each display mode the attached display supports; the
+ * routine returns nonzero to continue.
+ */
+XBOXKRNL_IMPORT(0x270) VOID VdEnumerateVideoModes(PVD_ENUMERATE_VIDEO_MODES_ROUTINE Routine, PVOID Context);
+
+/** Fills Data with the display discovery result; nonzero on success. */
+XBOXKRNL_IMPORT(0x27E) ULONG VdGetDisplayDiscoveryData(PVD_DISPLAY_DISCOVERY_DATA Data);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/xaudio.h b/platform/xex/sdk/include/xbox360/xboxkrnl/xaudio.h
new file mode 100644
index 0000000..e9e39c9
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/xaudio.h
@@ -0,0 +1,46 @@
+/*
+ * Audio render driver.
+ */
+
+#ifndef XBOX360_XBOXKRNL_XAUDIO_H
+#define XBOX360_XBOXKRNL_XAUDIO_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* Argument of a render driver client callback, built for each frame. */
+typedef struct _XAUDIORENDERDRVCALLBACKDATA {
+ PVOID Context;
+} XAUDIORENDERDRVCALLBACKDATA, *PXAUDIORENDERDRVCALLBACKDATA;
+
+C_ASSERT(sizeof(XAUDIORENDERDRVCALLBACKDATA) == 4);
+
+typedef VOID (*PXAUDIORENDERDRVCALLBACK)(PXAUDIORENDERDRVCALLBACKDATA CallbackData);
+
+/* Render driver client: the callback runs once per audio frame. */
+typedef struct _XAUDIORENDERDRVCLIENT {
+ PXAUDIORENDERDRVCALLBACK Callback;
+ PVOID Context;
+} XAUDIORENDERDRVCLIENT, *PXAUDIORENDERDRVCLIENT;
+
+C_ASSERT(sizeof(XAUDIORENDERDRVCLIENT) == 8);
+
+/** Registers an audio render client. The client handle is stored at Client. */
+XBOXKRNL_IMPORT(0x1F3) HRESULT XAudioRegisterRenderDriverClient(const XAUDIORENDERDRVCLIENT *ClientData, PVOID *Client);
+
+/** Removes an audio render client. */
+XBOXKRNL_IMPORT(0x1F4) HRESULT XAudioUnregisterRenderDriverClient(PVOID Client);
+
+/** Submits a frame of samples for an audio render client. */
+XBOXKRNL_IMPORT(0x1F5) HRESULT XAudioSubmitRenderDriverFrame(PVOID Client, const FLOAT *Samples);
+
+/** Returns the audio render driver thread object. */
+XBOXKRNL_IMPORT(0x1FE) struct _KTHREAD *XAudioGetRenderDriverThread(VOID);
+
+/** Sets the speaker configuration (the XConfig audio flags value). */
+XBOXKRNL_IMPORT(0x200) HRESULT XAudioSetSpeakerConfig(ULONG SpeakerConfig, ULONG Reserved);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/xe.h b/platform/xex/sdk/include/xbox360/xboxkrnl/xe.h
new file mode 100644
index 0000000..3e940b6
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/xe.h
@@ -0,0 +1,113 @@
+/*
+ * Kernel cryptography (XeCrypt) and security key (XeKeys) routines.
+ */
+
+#ifndef XBOX360_XBOXKRNL_XE_H
+#define XBOX360_XBOXKRNL_XE_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* DES key schedule of XeCryptDesKey: 16 rounds of two words. */
+typedef struct _XECRYPT_DES_STATE {
+ ULONG KeyTable[32];
+} XECRYPT_DES_STATE, *PXECRYPT_DES_STATE;
+
+C_ASSERT(sizeof(XECRYPT_DES_STATE) == 0x80);
+
+/* Key id of XeKeysGetKey: the 12-digit console serial number. */
+#define XEKEYS_KEY_CONSOLE_SERIAL_NUMBER 0x14
+
+/* Console identifier: 5 bytes. */
+#define XE_CONSOLE_ID_SIZE 5
+
+typedef struct _XE_CONSOLE_ID {
+ UCHAR Bytes[XE_CONSOLE_ID_SIZE];
+} XE_CONSOLE_ID, *PXE_CONSOLE_ID;
+
+C_ASSERT(sizeof(XE_CONSOLE_ID) == 5);
+
+/** Sets the parity bit of each byte of a DES key of InputSize bytes. */
+XBOXKRNL_IMPORT(0x174) VOID XeCryptDesParity(PCBYTE Input, ULONG InputSize, PBYTE Output);
+
+/** Expands an 8-byte DES key into DesState. */
+XBOXKRNL_IMPORT(0x175) VOID XeCryptDesKey(PXECRYPT_DES_STATE DesState, PCBYTE Key);
+
+/** Encrypts (Encrypt nonzero) or decrypts one 8-byte block in ECB mode. */
+XBOXKRNL_IMPORT(0x176) VOID XeCryptDesEcb(const XECRYPT_DES_STATE *DesState, PCBYTE Input, PBYTE Output, BOOL Encrypt);
+
+/**
+ * HMAC-SHA1 of the concatenation of up to three buffers under Key; the
+ * first OutputSize bytes of the digest go to Output. The dashboard passes
+ * null buffers of size 0 for the unused ones.
+ */
+XBOXKRNL_IMPORT(0x182) VOID XeCryptHmacSha(
+ PCBYTE Key,
+ ULONG KeySize,
+ PCBYTE Input1,
+ ULONG Input1Size,
+ PCBYTE Input2,
+ ULONG Input2Size,
+ PCBYTE Input3,
+ ULONG Input3Size,
+ PBYTE Output,
+ ULONG OutputSize
+);
+
+/**
+ * MD5 of the concatenation of up to three buffers; the first OutputSize
+ * bytes of the digest go to Output. The dashboard passes null buffers of
+ * size 0 for the unused ones.
+ */
+XBOXKRNL_IMPORT(0x187) VOID XeCryptMd5(
+ PCBYTE Input1,
+ ULONG Input1Size,
+ PCBYTE Input2,
+ ULONG Input2Size,
+ PCBYTE Input3,
+ ULONG Input3Size,
+ PBYTE Output,
+ ULONG OutputSize
+);
+
+/** Fills a buffer with random bytes. */
+XBOXKRNL_IMPORT(0x18A) VOID XeCryptRandom(PBYTE Buffer, ULONG Length);
+
+/**
+ * Writes a boot loader image to flash. A nonzero StartOffset value on
+ * return also indicates failure.
+ */
+XBOXKRNL_IMPORT(0x23D) NTSTATUS XeKeysSaveBootLoader(PULONG StartOffset, PULONG Length, PVOID Buffer);
+
+/** Stores the security key status flags. */
+XBOXKRNL_IMPORT(0x23F) VOID XeKeysGetStatus(PULONG Status);
+
+/**
+ * Copies the key KeyId into Buffer; Length holds the buffer size on entry
+ * and the key size on return. Key 0x14 is the 12-digit console serial number.
+ */
+XBOXKRNL_IMPORT(0x244) NTSTATUS XeKeysGetKey(ULONG KeyId, PVOID Buffer, PULONG Length);
+
+/**
+ * Stores the 5-byte console ID and, when ConsoleIdString is not null, its
+ * 12-character text form.
+ */
+XBOXKRNL_IMPORT(0x246) NTSTATUS XeKeysGetConsoleID(PXE_CONSOLE_ID ConsoleId, PCHAR ConsoleIdString);
+
+/*
+ * XeKeysGetConsoleType value bit: the console certificate is signed with
+ * public key 0x3A; without it, with key 0x3C.
+ */
+#define XE_CONSOLE_TYPE_KEY_3A 0x80000000
+
+/**
+ * Stores the console type field of the console certificate (key 0x36).
+ * Which values mean a development kit, a test kit or a retail console is
+ * not established.
+ */
+XBOXKRNL_IMPORT(0x247) NTSTATUS XeKeysGetConsoleType(PULONG ConsoleType);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/xex.h b/platform/xex/sdk/include/xbox360/xboxkrnl/xex.h
new file mode 100644
index 0000000..e99d783
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/xex.h
@@ -0,0 +1,243 @@
+/*
+ * XEX loader: loaded module records, XEX headers and the Xex routines.
+ */
+
+#ifndef XBOX360_XBOXKRNL_XEX_H
+#define XBOX360_XBOXKRNL_XEX_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/* XEX_HEADER.ModuleFlags, and the module flags of XexLoadImage. */
+#define XEX_MODULE_FLAG_TITLE 0x00000001
+#define XEX_MODULE_FLAG_EXPORTS_TO_TITLE 0x00000002
+#define XEX_MODULE_FLAG_SYSTEM_DEBUGGER 0x00000004
+#define XEX_MODULE_FLAG_DLL 0x00000008
+#define XEX_MODULE_FLAG_PATCH 0x00000010
+#define XEX_MODULE_FLAG_PATCH_FULL 0x00000020
+#define XEX_MODULE_FLAG_PATCH_DELTA 0x00000040
+#define XEX_MODULE_FLAG_USER_MODE 0x00000080
+
+/* Options of XexLoadImage, beside the module flags. */
+#define XEX_LOAD_FLAG_REQUIRE_DEVICE_ID 0x20000000
+#define XEX_LOAD_FLAG_REQUIRE_BOUND_PATH 0x40000000
+#define XEX_LOAD_FLAG_NO_FAILURE_REPORT 0x80000000
+
+/*
+ * Packed XEX version: 4, 4, 16 and 8 bits of major, minor, build and qfe
+ * from the top. As a minimum version, XEX_VERSION_ANY accepts every image.
+ */
+#define XEX_VERSION(Major, Minor, Build, Qfe) \
+ ((ULONG)(((Major) & 0xF) << 28 | ((Minor) & 0xF) << 24 | ((Build) & 0xFFFF) << 8 | ((Qfe) & 0xFF)))
+#define XEX_VERSION_ANY 0
+
+/* Module handle argument that stands for the module of the caller. */
+#define XEX_MODULE_HANDLE_CALLER ((PLDR_DATA_TABLE_ENTRY)-1)
+
+/* Reason the loader passes to the entry point of a module. */
+#define DLL_PROCESS_DETACH 0
+#define DLL_PROCESS_ATTACH 1
+
+/*
+ * Entry of a C or C++ DLL or system module that links xbox360//src/sdk:crt-dll,
+ * which calls it with C linkage. FALSE on DLL_PROCESS_ATTACH fails the load.
+ */
+BOOL DllMain(HANDLE Module, DWORD Reason, PVOID Reserved);
+
+/*
+ * Optional header entry. The low byte of Key gives the form of the data:
+ * 0, Value is the data; 1, Value holds one ULONG; 0xFF, Value is the offset
+ * of data that starts with its ULONG size; otherwise Value is the offset of
+ * Key & 0xFF ULONGs. XEX headers are big-endian.
+ */
+typedef struct _XEX_OPTIONAL_HEADER {
+ ULONG Key;
+ ULONG Value;
+} XEX_OPTIONAL_HEADER, *PXEX_OPTIONAL_HEADER;
+
+C_ASSERT(sizeof(XEX_OPTIONAL_HEADER) == 8);
+
+#define XEX_HEADER_MAGIC 0x58455832 /* 'XEX2' */
+
+typedef struct _XEX_HEADER {
+ ULONG Magic;
+ ULONG ModuleFlags;
+ ULONG SizeOfHeaders;
+ ULONG SizeOfDiscardableHeaders;
+ ULONG SecurityInfo;
+ ULONG OptionalHeaderCount;
+ XEX_OPTIONAL_HEADER OptionalHeaders[1];
+} XEX_HEADER, *PXEX_HEADER;
+
+C_ASSERT(sizeof(XEX_HEADER) == 0x20);
+C_ASSERT(__builtin_offsetof(XEX_HEADER, OptionalHeaders) == 0x18);
+
+/* Optional header keys. */
+#define XEX_HEADER_RESOURCE_INFO 0x000002FF
+#define XEX_HEADER_FILE_FORMAT_INFO 0x000003FF
+#define XEX_HEADER_DELTA_PATCH_DESCRIPTOR 0x000005FF
+#define XEX_HEADER_CONSOLE_FEATURES 0x00004004
+#define XEX_HEADER_VALIDITY_PERIOD 0x00004104
+#define XEX_HEADER_CONSOLE_ID_LIST 0x000042FF
+#define XEX_HEADER_BOUNDING_PATH 0x000080FF
+#define XEX_HEADER_DEVICE_ID 0x00008105
+#define XEX_HEADER_ORIGINAL_BASE_ADDRESS 0x00010001
+#define XEX_HEADER_ENTRY_POINT 0x00010100
+#define XEX_HEADER_IMAGE_BASE_ADDRESS 0x00010201
+#define XEX_HEADER_IMPORT_LIBRARIES 0x000103FF
+#define XEX_HEADER_CHECKSUM_TIMESTAMP 0x00018002
+#define XEX_HEADER_ENABLED_FOR_CALLCAP 0x00018102
+#define XEX_HEADER_ENABLED_FOR_FASTCAP 0x00018200
+#define XEX_HEADER_ORIGINAL_PE_NAME 0x000183FF
+/* 16-byte entries {Name[8], Major, Minor, Build, Qfe} after the size. */
+#define XEX_HEADER_STATIC_LIBRARIES 0x000200FF
+#define XEX_HEADER_TLS_INFO 0x00020104
+#define XEX_HEADER_DEFAULT_STACK_SIZE 0x00020200
+#define XEX_HEADER_FILESYSTEM_CACHE_SIZE 0x00020301
+#define XEX_HEADER_SYSTEM_FLAGS 0x00030000
+#define XEX_HEADER_EXECUTION_INFO 0x00040006
+#define XEX_HEADER_TITLE_WORKSPACE_SIZE 0x00040201
+#define XEX_HEADER_LAN_KEY 0x00040404
+#define XEX_HEADER_ADDITIONAL_TITLE_MEMORY 0x00040801
+
+/* Data of XEX_HEADER_EXECUTION_INFO. */
+typedef struct _XEX_EXECUTION_INFO {
+ ULONG MediaId;
+ ULONG Version;
+ ULONG BaseVersion;
+ ULONG TitleId;
+ UCHAR Platform;
+ UCHAR ExecutableType;
+ UCHAR DiscNumber;
+ UCHAR DiscCount;
+ ULONG SavegameId;
+} XEX_EXECUTION_INFO, *PXEX_EXECUTION_INFO;
+
+C_ASSERT(sizeof(XEX_EXECUTION_INFO) == 0x18);
+C_ASSERT(__builtin_offsetof(XEX_EXECUTION_INFO, TitleId) == 0xC);
+C_ASSERT(__builtin_offsetof(XEX_EXECUTION_INFO, SavegameId) == 0x14);
+
+/* Imports of a module: Count entries, NULL for an import that is not loaded. */
+typedef struct _LDR_IMPORT_TABLE {
+ ULONG Count;
+ struct _LDR_DATA_TABLE_ENTRY *Entries[1];
+} LDR_IMPORT_TABLE, *PLDR_IMPORT_TABLE;
+
+C_ASSERT(sizeof(LDR_IMPORT_TABLE) == 8);
+
+/*
+ * The loader's record of a loaded module. Its address is the module
+ * handle. The loader changes the links and the flags under its lock.
+ */
+typedef struct _LDR_DATA_TABLE_ENTRY {
+ LIST_ENTRY InLoadOrderLinks;
+ LIST_ENTRY InClosureOrderLinks;
+ LIST_ENTRY InInitializationOrderLinks;
+ PVOID NtHeadersBase; /* address the image is loaded at */
+ PVOID ImageBase;
+ ULONG SizeOfNtImage;
+ UNICODE_STRING FullDllName;
+ UNICODE_STRING BaseDllName;
+ ULONG Flags;
+ ULONG SizeOfFullImage;
+ PVOID EntryPoint;
+ USHORT LoadCount;
+ USHORT ModuleIndex;
+ PVOID OriginalBaseAddress; /* function table in kernel 17559 and later */
+ ULONG CheckSum;
+ ULONG ModuleFlags; /* XEX_HEADER.ModuleFlags */
+ ULONG TimeDateStamp;
+ PLDR_IMPORT_TABLE LoadedImports;
+ PXEX_HEADER XexHeaderBase;
+ union {
+ ANSI_STRING LoadFileName;
+ struct {
+ struct _LDR_DATA_TABLE_ENTRY *ClosureRoot;
+ struct _LDR_DATA_TABLE_ENTRY *TraversalParent;
+ } s;
+ } u;
+} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
+
+C_ASSERT(sizeof(LDR_DATA_TABLE_ENTRY) == 0x64);
+C_ASSERT(__builtin_offsetof(LDR_DATA_TABLE_ENTRY, NtHeadersBase) == 0x18);
+C_ASSERT(__builtin_offsetof(LDR_DATA_TABLE_ENTRY, SizeOfNtImage) == 0x20);
+C_ASSERT(__builtin_offsetof(LDR_DATA_TABLE_ENTRY, FullDllName) == 0x24);
+C_ASSERT(__builtin_offsetof(LDR_DATA_TABLE_ENTRY, BaseDllName) == 0x2C);
+C_ASSERT(__builtin_offsetof(LDR_DATA_TABLE_ENTRY, Flags) == 0x34);
+C_ASSERT(__builtin_offsetof(LDR_DATA_TABLE_ENTRY, TimeDateStamp) == 0x50);
+C_ASSERT(__builtin_offsetof(LDR_DATA_TABLE_ENTRY, XexHeaderBase) == 0x58);
+
+/* LDR_DATA_TABLE_ENTRY.Flags */
+#define LDR_FLAG_LOAD_IN_PROGRESS 0x00001000
+#define LDR_FLAG_UNLOAD_PENDING 0x00002000
+
+/** Module handle of the running executable: the address of its loader entry. */
+XBOXKRNL_IMPORT(0x193) extern PLDR_DATA_TABLE_ENTRY *__imp_XexExecutableModuleHandle;
+#define XexExecutableModuleHandle (*__imp_XexExecutableModuleHandle)
+
+/** Finds a loaded module by name and stores its handle. */
+XBOXKRNL_IMPORT(0x195) NTSTATUS XexGetModuleHandle(PCSZ ModuleName, PLDR_DATA_TABLE_ENTRY *ModuleHandle);
+
+/**
+ * Finds the resource SectionName of a module and stores its address and
+ * size. SectionName must equal the stored name, which is at most 8 bytes,
+ * byte for byte, so case is significant. XEX_MODULE_HANDLE_CALLER as Module
+ * names the caller's module. Fails with STATUS_NOT_FOUND when the module
+ * has no such resource.
+ */
+XBOXKRNL_IMPORT(0x196) NTSTATUS XexGetModuleSection(
+ PLDR_DATA_TABLE_ENTRY Module,
+ PCSZ SectionName,
+ PVOID *SectionData,
+ PULONG SectionSize
+);
+
+/**
+ * Finds an export of a module by ordinal and stores its address. Ordinal
+ * may instead be the address of a NUL-terminated export name.
+ */
+XBOXKRNL_IMPORT(0x197) NTSTATUS XexGetProcedureAddress(
+ PLDR_DATA_TABLE_ENTRY ModuleHandle,
+ ULONG Ordinal,
+ PVOID *ProcedureAddress
+);
+
+/**
+ * Loads a XEX image and stores its module handle. MinimumVersion is the
+ * oldest version accepted (see XEX_VERSION).
+ */
+XBOXKRNL_IMPORT(0x199) NTSTATUS XexLoadImage(
+ PCSZ ImageName,
+ ULONG LoadFlags,
+ ULONG MinimumVersion,
+ PLDR_DATA_TABLE_ENTRY *ModuleHandle
+);
+
+/**
+ * Loads a XEX image from ImageSize bytes at ImageBuffer under the module
+ * name ImageName and stores its module handle. ImageName must be a bare
+ * name without a path (STATUS_OBJECT_PATH_INVALID otherwise), and a
+ * module of that name must not be loaded (STATUS_OBJECT_NAME_COLLISION).
+ * The DLL bit of LoadFlags must equal that of the image's module flags;
+ * without it the image loads as the title. MinimumVersion is the oldest
+ * version accepted (see XEX_VERSION).
+ */
+XBOXKRNL_IMPORT(0x19A) NTSTATUS XexLoadImageFromMemory(
+ PVOID ImageBuffer,
+ ULONG ImageSize,
+ PCSZ ImageName,
+ ULONG LoadFlags,
+ ULONG MinimumVersion,
+ PLDR_DATA_TABLE_ENTRY *ModuleHandle
+);
+
+/** Finds the loader entry of the module that contains an address. Returns the image base. */
+XBOXKRNL_IMPORT(0x19C) PVOID XexPcToFileHeader(PVOID PcValue, PLDR_DATA_TABLE_ENTRY *DataTableEntry);
+
+/** Unloads a XEX image. */
+XBOXKRNL_IMPORT(0x1A1) NTSTATUS XexUnloadImage(PLDR_DATA_TABLE_ENTRY ModuleHandle);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/include/xbox360/xboxkrnl/xma.h b/platform/xex/sdk/include/xbox360/xboxkrnl/xma.h
new file mode 100644
index 0000000..efb5423
--- /dev/null
+++ b/platform/xex/sdk/include/xbox360/xboxkrnl/xma.h
@@ -0,0 +1,144 @@
+/*
+ * Hardware XMA audio decoder contexts.
+ */
+
+#ifndef XBOX360_XBOXKRNL_XMA_H
+#define XBOX360_XBOXKRNL_XMA_H
+
+#include <xbox360/xboxkrnl/ntdef.h>
+
+XBOX360_EXTERN_C_START
+
+/*
+ * Hardware context of the XMA decoder, 64 bytes in an array that the decoder
+ * reads from physical memory. Bitfields are assigned from the most
+ * significant bit. Buffer offsets and counts are in the units of the
+ * decoder: input packets of 2 KB, output blocks of 256 bytes.
+ */
+typedef struct _XMA_CONTEXT_DATA {
+ /* DWORD 0 */
+ DWORD OutputBufferWriteOffset : 5;
+ DWORD OutputBufferBlockCount : 5;
+ DWORD InputBuffer1Valid : 1;
+ DWORD InputBuffer0Valid : 1;
+ DWORD LoopCount : 8;
+ DWORD InputBuffer0PacketCount : 12;
+
+ /* DWORD 1 */
+ DWORD OutputBufferValid : 1;
+ DWORD Reserved1A : 1;
+ DWORD IsStereo : 1;
+ DWORD SampleRate : 2;
+ DWORD Reserved1B : 3;
+ DWORD SubframeDecodeCount : 4;
+ DWORD LoopSubframeSkip : 3;
+ DWORD Reserved1C : 3;
+ DWORD LoopSubframeEnd : 2;
+ DWORD InputBuffer1PacketCount : 12;
+
+ /* DWORD 2 */
+ DWORD Reserved2 : 6;
+ DWORD InputBufferReadOffset : 26;
+
+ /* DWORD 3 */
+ DWORD Reserved3 : 6;
+ DWORD LoopStartOffset : 26;
+
+ /* DWORD 4 */
+ DWORD Reserved4A : 1;
+ DWORD PacketMetadata : 5;
+ DWORD LoopEndOffset : 26;
+
+ /* DWORDs 5 to 8: physical addresses. */
+ DWORD InputBuffer0;
+ DWORD InputBuffer1;
+ DWORD OutputBuffer;
+ DWORD WorkBuffer;
+
+ /* DWORD 9 */
+ DWORD Reserved9 : 27;
+ DWORD OutputBufferReadOffset : 5;
+
+ /* DWORDs 10 to 15. */
+ DWORD Reserved[6];
+} XMA_CONTEXT_DATA, *PXMA_CONTEXT_DATA;
+
+C_ASSERT(__builtin_offsetof(XMA_CONTEXT_DATA, InputBuffer0) == 0x14);
+C_ASSERT(sizeof(XMA_CONTEXT_DATA) == 0x40);
+
+/* Loop region of a context. Offsets are bit offsets in the input stream. */
+typedef struct _XMA_LOOP_DATA {
+ DWORD LoopStartOffset;
+ DWORD LoopEndOffset;
+ UCHAR LoopCount;
+ UCHAR LoopSubframeEnd;
+ UCHAR LoopSubframeSkip;
+ UCHAR Reserved;
+} XMA_LOOP_DATA, *PXMA_LOOP_DATA;
+
+C_ASSERT(sizeof(XMA_LOOP_DATA) == 0xC);
+
+/*
+ * Initial state of a context for XMAInitializeContext. Buffers are virtual
+ * addresses of physically contiguous memory.
+ */
+typedef struct _XMA_CONTEXT_INIT {
+ PVOID InputBuffer0;
+ DWORD InputBuffer0PacketCount;
+ PVOID InputBuffer1;
+ DWORD InputBuffer1PacketCount;
+ DWORD InputBufferReadOffset;
+ PVOID OutputBuffer;
+ DWORD OutputBufferBlockCount;
+ PVOID WorkBuffer;
+ DWORD SubframeDecodeCount;
+ DWORD IsStereo;
+ DWORD SampleRate;
+ XMA_LOOP_DATA LoopData;
+} XMA_CONTEXT_INIT, *PXMA_CONTEXT_INIT;
+
+C_ASSERT(__builtin_offsetof(XMA_CONTEXT_INIT, LoopData) == 0x2C);
+C_ASSERT(sizeof(XMA_CONTEXT_INIT) == 0x38);
+
+/** Allocates one hardware XMA decoder context. */
+XBOXKRNL_IMPORT(0x224) HRESULT XMACreateContext(PXMA_CONTEXT_DATA *Context);
+
+/** Initializes an allocated XMA decoder context. */
+XBOXKRNL_IMPORT(0x225) VOID XMAInitializeContext(PXMA_CONTEXT_DATA Context, const XMA_CONTEXT_INIT *ContextInit);
+
+/** Releases a hardware XMA decoder context. */
+XBOXKRNL_IMPORT(0x226) VOID XMAReleaseContext(PXMA_CONTEXT_DATA Context);
+
+/** Enables a hardware XMA decoder context. */
+XBOXKRNL_IMPORT(0x227) VOID XMAEnableContext(PXMA_CONTEXT_DATA Context);
+
+/** Disables a hardware XMA decoder context. Wait waits for in-flight decoder work. */
+XBOXKRNL_IMPORT(0x228) HRESULT XMADisableContext(PXMA_CONTEXT_DATA Context, BOOL Wait);
+
+/** Returns the decoder's output ring write offset in 256-byte blocks. */
+XBOXKRNL_IMPORT(0x229) DWORD XMAGetOutputBufferWriteOffset(PXMA_CONTEXT_DATA Context);
+
+/** Sets the output ring read offset in 256-byte blocks. */
+XBOXKRNL_IMPORT(0x22A) VOID XMASetOutputBufferReadOffset(PXMA_CONTEXT_DATA Context, DWORD Offset);
+
+/** Returns the output ring read offset in 256-byte blocks. */
+XBOXKRNL_IMPORT(0x22B) DWORD XMAGetOutputBufferReadOffset(PXMA_CONTEXT_DATA Context);
+
+/** Marks the output ring of an XMA decoder context valid. */
+XBOXKRNL_IMPORT(0x22C) VOID XMASetOutputBufferValid(PXMA_CONTEXT_DATA Context);
+
+/** Returns whether the output ring is valid. */
+XBOXKRNL_IMPORT(0x22D) BOOL XMAIsOutputBufferValid(PXMA_CONTEXT_DATA Context);
+
+/** Marks input buffer zero of an XMA decoder context valid. */
+XBOXKRNL_IMPORT(0x22E) VOID XMASetInputBuffer0Valid(PXMA_CONTEXT_DATA Context);
+
+/** Returns whether input buffer zero is valid. */
+XBOXKRNL_IMPORT(0x22F) BOOL XMAIsInputBuffer0Valid(PXMA_CONTEXT_DATA Context);
+
+/** Waits until the decoder is not working on Context. */
+XBOXKRNL_IMPORT(0x235) VOID XMABlockWhileInUse(PXMA_CONTEXT_DATA Context);
+
+XBOX360_EXTERN_C_END
+
+#endif
diff --git a/platform/xex/sdk/thunks/macros.inc b/platform/xex/sdk/thunks/macros.inc
new file mode 100644
index 0000000..506424a
--- /dev/null
+++ b/platform/xex/sdk/thunks/macros.inc
@@ -0,0 +1,152 @@
+/*
+ * Macros of the import thunk library. src/tools/xbox360-bindgen writes one
+ * invocation of them per import into ppc32.S and ppc64.S.
+ *
+ * A thunk is 16 bytes: the import record (type << 24 | library << 16 |
+ * ordinal), then nop; nop; blr, which only runs if the loader never patches
+ * it. The loader rewrites the thunk to call the export.
+ *
+ * Each function, thunk and slot is in its own section, so that
+ * --gc-sections drops the imports nobody uses. Each symbol is weak and
+ * defined once per assembly unit, so separate copies of the library link
+ * together and can share one unit, such as a fat LTO module.
+ */
+
+.ifndef .Lxbox360_thunk_macros
+.set .Lxbox360_thunk_macros, 1
+
+.macro xbox360_thunk_words record
+ .long \record
+ .long 0x60000000
+ .long 0x60000000
+ .long 0x4e800020
+.endm
+
+/* A function import that is its thunk (powerpc64 ILP32 callers). */
+.macro xbox360_thunk name, record
+.ifndef \name
+ .pushsection .xthunks.\name, "ax", @progbits
+ .balign 4
+ .weak \name
+ .type \name, @function
+\name:
+ xbox360_thunk_words \record
+ .size \name, 16
+ .popsection
+.endif
+.endm
+
+/* A data import slot, which the loader sets to the address of the export. */
+.macro xbox360_slot name, record
+.ifndef \name
+ .pushsection .xvars.\name, "aw", @progbits
+ .balign 4
+ .weak \name
+ .type \name, @object
+ .size \name, 4
+\name:
+ .long \record
+ .popsection
+.endif
+.endm
+
+/*
+ * The start of a function \name that calls the thunk of the import. Close
+ * it with xbox360_end.
+ */
+.macro xbox360_function name
+ .pushsection .text.xbox360_import.\name, "ax", @progbits
+ .balign 4
+ .weak \name
+ .type \name, @function
+\name:
+.endm
+
+/*
+ * A frame of \frame bytes with the home area of r3-r10 at 0x10-0x50, which
+ * console callees store their arguments in.
+ */
+.macro xbox360_frame frame
+ stwu 1, -\frame(1)
+ mflr 0
+ stw 0, \frame+4(1)
+.endm
+
+.macro xbox360_call name
+ bl .Lxbox360_thunk_\name
+.endm
+
+/*
+ * Convert the result of the export for a SysV caller: a 64-bit integer goes
+ * to r3 (high) and r4 (low), and the bits above a narrow integer, which the
+ * export leaves undefined, are extended.
+ */
+.macro xbox360_result kind
+.ifc \kind, u64
+ mr 4, 3
+ rldicl 3, 3, 32, 32
+.endif
+.ifc \kind, u8
+ clrlwi 3, 3, 24
+.endif
+.ifc \kind, u16
+ clrlwi 3, 3, 16
+.endif
+.ifc \kind, i8
+ extsb 3, 3
+.endif
+.ifc \kind, i16
+ extsh 3, 3
+.endif
+.endm
+
+.macro xbox360_return frame
+ lwz 0, \frame+4(1)
+ mtlr 0
+ addi 1, 1, \frame
+ blr
+.endm
+
+/* The end of the function \name, and its thunk. */
+.macro xbox360_end name, record
+ .size \name, .-\name
+ .section .xthunks.\name, "ax", @progbits
+ .balign 4
+.Lxbox360_thunk_\name:
+ xbox360_thunk_words \record
+ .popsection
+.endm
+
+/*
+ * A function import for SysV (powerpc) callers whose arguments need no
+ * moves: it adds the home area and converts the result `kind`.
+ */
+.macro xbox360_stub name, record, kind=word
+.ifndef \name
+ xbox360_function \name
+ xbox360_frame 0x50
+ xbox360_call \name
+ xbox360_result \kind
+ xbox360_return 0x50
+ xbox360_end \name, \record
+.endif
+.endm
+
+/*
+ * A function import that does not return. It traps if the export returns
+ * anyway, as Xenia's KeBugCheck does. `frame` is 0 when the caller already
+ * reserves the home area (powerpc64 ILP32).
+ */
+.macro xbox360_noreturn name, record, frame=0x50
+.ifndef \name
+ xbox360_function \name
+.if \frame
+ xbox360_frame \frame
+.endif
+ xbox360_call \name
+ trap
+ xbox360_end \name, \record
+.endif
+.endm
+
+.endif
diff --git a/platform/xex/sdk/thunks/ppc32.S b/platform/xex/sdk/thunks/ppc32.S
new file mode 100644
index 0000000..6777226
--- /dev/null
+++ b/platform/xex/sdk/thunks/ppc32.S
@@ -0,0 +1,862 @@
+/* @generated by src/tools/xbox360-bindgen from src/sdk/include. Do not edit. */
+#include "macros.inc"
+
+xbox360_stub CreateEventA, 0x01010446
+xbox360_stub CreateFileA, 0x01010447
+xbox360_stub DbgBreakPoint, 0x01000001
+xbox360_stub DbgPrint, 0x01000003
+xbox360_stub DumpWriteDump, 0x01000006
+xbox360_stub DuplicateHandle, 0x0101045b
+xbox360_stub ExAllocatePoolTypeWithTag, 0x0100000b
+xbox360_stub ExAllocatePoolWithTag, 0x0100000a
+xbox360_stub ExCreateThread, 0x0100000d
+xbox360_stub ExDebugMonitorService, 0x010001aa
+xbox360_stub ExExpansionCall, 0x0100030c
+xbox360_stub ExExpansionInstall, 0x0100030b
+xbox360_stub ExFreePool, 0x0100000f
+xbox360_stub ExGetXConfigSetting, 0x01000010
+xbox360_stub ExReadModifyWriteXConfigSettingUlong, 0x010002bc
+xbox360_stub ExRegisterThreadNotification, 0x01000014
+xbox360_stub ExRegisterTitleTerminateNotification, 0x01000015
+xbox360_stub ExSetXConfigSetting, 0x01000018
+xbox360_noreturn ExTerminateThread, 0x01000019
+xbox360_stub FscGetCacheElementCount, 0x01000020
+xbox360_stub FscSetCacheElementCount, 0x01000021
+xbox360_stub GetCurrentThreadId, 0x01010410
+xbox360_stub GetLocalTime, 0x01010444
+xbox360_stub GetProcessHeap, 0x010107d2
+xbox360_stub HalGetCurrentAVPack, 0x01000022
+xbox360_stub HalIsExecutingPowerDownDpc, 0x01000267
+xbox360_stub HalOpenCloseODDTray, 0x01000024
+xbox360_stub HalRegisterSMCNotification, 0x01000027
+xbox360_stub HalReturnToFirmware, 0x01000028
+xbox360_stub HalSendSMCMessage, 0x01000029
+xbox360_stub InterlockedFlushSList, 0x0100002b
+xbox360_stub InterlockedPopEntrySList, 0x0100002c
+xbox360_stub IoAcquireDeviceObjectLock, 0x0100002e, u8
+xbox360_stub IoAllocateIrp, 0x0100002f
+xbox360_stub IoCompleteRequest, 0x01000035
+xbox360_stub IoCreateDevice, 0x01000037
+xbox360_stub IoDismountVolume, 0x0100003b
+xbox360_stub IoDismountVolumeByFileHandle, 0x0100003c
+xbox360_stub IoInvalidDeviceRequest, 0x01000041
+xbox360_stub IoReleaseDeviceObjectLock, 0x01000044
+xbox360_stub IoStartNextPacket, 0x01000048
+xbox360_stub IoStartPacket, 0x0100004a
+xbox360_stub IoSynchronousDeviceIoControlRequest, 0x0100004b
+xbox360_stub IoSynchronousFsdRequest, 0x0100004c
+xbox360_stub KeAcquireSpinLockAtRaisedIrql, 0x0100004d
+xbox360_noreturn KeBugCheck, 0x01000052
+xbox360_noreturn KeBugCheckEx, 0x01000053
+xbox360_stub KeCancelTimer, 0x01000054, u8
+xbox360_stub KeContextFromKframes, 0x01000056
+xbox360_stub KeDelayExecutionThread, 0x0100005a
+xbox360_stub KeEnablePPUPerformanceMonitor, 0x0100005e
+xbox360_stub KeEnterCriticalRegion, 0x0100005f
+xbox360_stub KeFlushCacheRange, 0x01000061
+xbox360_stub KeGetCurrentProcessType, 0x01000066
+xbox360_stub KeGetPMWRegister, 0x01000067, u64
+xbox360_stub KeGetSpecialPurposeRegister, 0x0100006a
+xbox360_stub KeInitializeDpc, 0x0100006f
+xbox360_stub KeInitializeEvent, 0x01000070
+xbox360_stub KeInitializeSemaphore, 0x01000074
+xbox360_stub KeInitializeTimerEx, 0x01000075
+xbox360_stub KeInsertQueueDpc, 0x0100007b, u8
+xbox360_stub KeIpiGenericCall, 0x0100007c
+xbox360_stub KeLeaveCriticalRegion, 0x0100007d
+xbox360_stub KeQueryPerformanceFrequency, 0x01000083, u64
+xbox360_stub KeQuerySystemTime, 0x01000084
+xbox360_stub KeRaiseIrqlToDpcLevel, 0x01000085, u8
+xbox360_stub KeReleaseSemaphore, 0x01000088
+xbox360_stub KeReleaseSpinLockFromRaisedIrql, 0x01000089
+xbox360_stub KeRemoveQueueDpc, 0x0100008e, u8
+xbox360_stub KeResetEvent, 0x0100008f
+xbox360_stub KeResumeThread, 0x01000092
+xbox360_stub KeSetAffinityThread, 0x01000097
+xbox360_stub KeSetBasePriorityThread, 0x01000099
+xbox360_stub KeSetEvent, 0x0100009d
+
+.ifndef KeSetPMWRegister
+ xbox360_function KeSetPMWRegister
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ xbox360_call KeSetPMWRegister
+ xbox360_return 0x50
+ xbox360_end KeSetPMWRegister, 0x0100009f
+.endif
+
+
+.ifndef KeSetPRVRegister
+ xbox360_function KeSetPRVRegister
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ xbox360_call KeSetPRVRegister
+ xbox360_return 0x50
+ xbox360_end KeSetPRVRegister, 0x010000a1
+.endif
+
+xbox360_stub KeSetPriorityThread, 0x010000a3
+
+.ifndef KeSetSpecialPurposeRegister
+ xbox360_function KeSetSpecialPurposeRegister
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ xbox360_call KeSetSpecialPurposeRegister
+ xbox360_return 0x50
+ xbox360_end KeSetSpecialPurposeRegister, 0x010000a5
+.endif
+
+
+.ifndef KeSetTimerEx
+ xbox360_function KeSetTimerEx
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ lwz 5, 0x20(1)
+ lwz 6, 0x24(1)
+ xbox360_call KeSetTimerEx
+ xbox360_result u8
+ xbox360_return 0x50
+ xbox360_end KeSetTimerEx, 0x010000a7
+.endif
+
+xbox360_stub KeStallExecutionProcessor, 0x010000a8
+xbox360_stub KeSuspendThread, 0x010000a9
+xbox360_stub KeSweepIcacheRange, 0x010000ab
+xbox360_stub KeTlsAlloc, 0x01000152
+xbox360_stub KeTlsFree, 0x01000153, u8
+xbox360_stub KeTlsGetValue, 0x01000154
+xbox360_stub KeTlsSetValue, 0x01000155, u8
+xbox360_stub KeTryToAcquireSpinLockAtRaisedIrql, 0x010000ae, u8
+xbox360_stub KeWaitForMultipleObjects, 0x010000af
+xbox360_stub KeWaitForSingleObject, 0x010000b0
+xbox360_stub KfAcquireSpinLock, 0x010000b1, u8
+xbox360_stub KfLowerIrql, 0x010000b3
+xbox360_stub KfRaiseIrql, 0x010000b2, u8
+xbox360_stub KfReleaseSpinLock, 0x010000b4
+xbox360_stub MmAllocatePhysicalMemory, 0x010000b9
+xbox360_stub MmAllocatePhysicalMemoryEx, 0x010000ba
+xbox360_stub MmDbgReadCheck, 0x010001ab
+xbox360_stub MmDbgReleaseAddress, 0x010001ac
+xbox360_stub MmDbgWriteCheck, 0x010001ad
+xbox360_stub MmFreePhysicalMemory, 0x010000bd
+xbox360_stub MmGetPhysicalAddress, 0x010000be
+xbox360_stub MmIsAddressValid, 0x010000bf, u8
+xbox360_stub MmQueryAddressProtect, 0x010000c4
+xbox360_stub MmQueryAllocationSize, 0x010000c5
+xbox360_stub MmQueryStatistics, 0x010000c6
+xbox360_stub NetDll_UpnpCleanup, 0x010100fc
+xbox360_stub NetDll_UpnpStartup, 0x010100fb
+xbox360_stub NetDll_WSAEventSelect, 0x01010023
+xbox360_stub NetDll_WSAGetLastError, 0x0101001b
+xbox360_stub NetDll_WSAStartup, 0x01010001
+xbox360_stub NetDll_XHttpCloseHandle, 0x010100cc
+xbox360_stub NetDll_XHttpConnect, 0x010100cd
+xbox360_stub NetDll_XHttpDoWork, 0x010100d8
+xbox360_stub NetDll_XHttpOpen, 0x010100cb
+xbox360_stub NetDll_XHttpOpenRequest, 0x010100cf
+xbox360_stub NetDll_XHttpQueryHeaders, 0x010100d3
+xbox360_stub NetDll_XHttpReadData, 0x010100d4
+xbox360_stub NetDll_XHttpReceiveResponse, 0x010100d2
+xbox360_stub NetDll_XHttpSendRequest, 0x010100d1
+xbox360_stub NetDll_XHttpSetOption, 0x010100d7
+xbox360_stub NetDll_XHttpSetStatusCallback, 0x010100ce
+xbox360_stub NetDll_XHttpShutdown, 0x010100ca
+xbox360_stub NetDll_XHttpStartup, 0x010100c9
+xbox360_stub NetDll_XNetGetDebugXnAddr, 0x0101004a
+xbox360_stub NetDll_XNetGetEthernetLinkStatus, 0x0101004b
+xbox360_stub NetDll_XNetGetOpt, 0x0101004e
+xbox360_stub NetDll_XNetGetTitleXnAddr, 0x01010049
+xbox360_stub NetDll_XNetRandom, 0x01010035
+xbox360_stub NetDll_XNetSetOpt, 0x0101004f
+xbox360_stub NetDll_XNetStartup, 0x01010033
+xbox360_stub NetDll_XNetStartupVersion, 0x01010050
+xbox360_stub NetDll_XnpConfig, 0x01010068
+xbox360_stub NetDll_XnpEthernetInterceptRecv, 0x0101006f
+xbox360_stub NetDll_XnpEthernetInterceptSetCallbacks, 0x0101006d
+xbox360_stub NetDll_XnpEthernetInterceptXmit, 0x0101006e
+xbox360_stub NetDll_XnpGetActiveSocketList, 0x0101007a
+xbox360_stub NetDll_XnpGetConfigStatus, 0x01010069
+xbox360_stub NetDll_XnpLoadConfigParams, 0x01010065
+xbox360_stub NetDll_XnpNoteSystemTime, 0x0101007b
+xbox360_stub NetDll_XnpSaveConfigParams, 0x01010066
+xbox360_stub NetDll_accept, 0x0101000e
+xbox360_stub NetDll_bind, 0x0101000b
+xbox360_stub NetDll_closesocket, 0x01010004
+xbox360_stub NetDll_connect, 0x0101000c
+xbox360_stub NetDll_getpeername, 0x0101000a
+xbox360_stub NetDll_getsockname, 0x01010009
+xbox360_stub NetDll_getsockopt, 0x01010008
+xbox360_stub NetDll_ioctlsocket, 0x01010006
+xbox360_stub NetDll_listen, 0x0101000d
+xbox360_stub NetDll_recv, 0x01010012
+xbox360_stub NetDll_recvfrom, 0x01010014
+xbox360_stub NetDll_select, 0x0101000f
+xbox360_stub NetDll_send, 0x01010016
+xbox360_stub NetDll_sendto, 0x01010018
+xbox360_stub NetDll_setsockopt, 0x01010007
+xbox360_stub NetDll_shutdown, 0x01010005
+xbox360_stub NetDll_socket, 0x01010003
+xbox360_stub NicGetStats, 0x01000209
+xbox360_stub NtAllocateVirtualMemory, 0x010000cc
+xbox360_stub NtClearEvent, 0x010000ce
+xbox360_stub NtClose, 0x010000cf
+xbox360_stub NtCreateDirectoryObject, 0x010000d0
+xbox360_stub NtCreateEvent, 0x010000d1
+
+.ifndef NtCreateFile
+ xbox360_function NtCreateFile
+ xbox360_frame 0x60
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x68(1)
+ stw 11, 0x54(1)
+ xbox360_call NtCreateFile
+ xbox360_return 0x60
+ xbox360_end NtCreateFile, 0x010000d2
+.endif
+
+xbox360_stub NtCreateSemaphore, 0x010000d5
+xbox360_stub NtDeleteFile, 0x010000d8
+
+.ifndef NtDeviceIoControlFile
+ xbox360_function NtDeviceIoControlFile
+ xbox360_frame 0x60
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x68(1)
+ stw 11, 0x54(1)
+ li 12, 0
+ stw 12, 0x58(1)
+ lwz 11, 0x6c(1)
+ stw 11, 0x5c(1)
+ xbox360_call NtDeviceIoControlFile
+ xbox360_return 0x60
+ xbox360_end NtDeviceIoControlFile, 0x010000d9
+.endif
+
+xbox360_stub NtFlushBuffersFile, 0x010000db
+xbox360_stub NtFreeVirtualMemory, 0x010000dc
+xbox360_stub NtOpenDirectoryObject, 0x010000de
+xbox360_stub NtOpenFile, 0x010000df
+
+.ifndef NtQueryDirectoryFile
+ xbox360_function NtQueryDirectoryFile
+ xbox360_frame 0x60
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x68(1)
+ stw 11, 0x54(1)
+ xbox360_call NtQueryDirectoryFile
+ xbox360_return 0x60
+ xbox360_end NtQueryDirectoryFile, 0x010000e4
+.endif
+
+xbox360_stub NtQueryDirectoryObject, 0x010000e5
+xbox360_stub NtQueryFullAttributesFile, 0x010000e7
+xbox360_stub NtQueryInformationFile, 0x010000e8
+xbox360_stub NtQueryVirtualMemory, 0x010000ee
+xbox360_stub NtQueryVolumeInformationFile, 0x010000ef
+xbox360_stub NtReadFile, 0x010000f0
+xbox360_stub NtReadFileScatter, 0x010000f1
+xbox360_stub NtReleaseSemaphore, 0x010000f3
+xbox360_stub NtSetEvent, 0x010000f6
+xbox360_stub NtSetInformationFile, 0x010000f7
+xbox360_stub NtSetSystemTime, 0x010000f9
+xbox360_stub NtWaitForMultipleObjectsEx, 0x010000fe
+xbox360_stub NtWaitForSingleObjectEx, 0x010000fd
+xbox360_stub NtWriteFile, 0x010000ff
+xbox360_stub NtWriteFileGather, 0x01000100
+xbox360_stub NtYieldExecution, 0x01000101
+xbox360_stub ObCreateObject, 0x01000102
+xbox360_stub ObCreateSymbolicLink, 0x01000103
+xbox360_stub ObDeleteSymbolicLink, 0x01000104
+xbox360_stub ObDereferenceObject, 0x01000105
+xbox360_stub ObInsertObject, 0x01000108
+xbox360_stub ObLookupAnyThreadByThreadId, 0x0100010a
+xbox360_stub ObMakeTemporaryObject, 0x0100010c
+xbox360_stub ObOpenObjectByName, 0x0100010d
+xbox360_stub ObReferenceObjectByHandle, 0x01000110
+xbox360_stub ObReferenceObjectByName, 0x01000111
+xbox360_stub ObTranslateSymbolicLink, 0x01000113
+xbox360_stub QueryPerformanceCounter, 0x0101042f
+xbox360_stub QueryPerformanceFrequency, 0x01010430
+xbox360_stub ResetEvent, 0x0101042b
+xbox360_stub ResumeThread, 0x0101043d
+xbox360_stub RtlAllocateHeap, 0x010103fc
+xbox360_stub RtlAssert, 0x01000118
+xbox360_stub RtlCaptureContext, 0x01000119
+xbox360_stub RtlEnterCriticalSection, 0x01000125
+xbox360_stub RtlFreeHeap, 0x010103ff
+xbox360_stub RtlGetStackLimits, 0x0100012a
+xbox360_stub RtlImageDirectoryEntryToData, 0x010001a8
+xbox360_stub RtlImageNtHeader, 0x010001a9
+xbox360_stub RtlImageXexHeaderField, 0x0100012b
+xbox360_stub RtlInitializeCriticalSection, 0x0100012e
+xbox360_stub RtlInitializeCriticalSectionAndSpinCount, 0x0100012f
+xbox360_stub RtlLeaveCriticalSection, 0x01000130
+xbox360_stub RtlNtStatusToDosError, 0x01000135
+xbox360_stub RtlTryEnterCriticalSection, 0x01000141, u8
+xbox360_stub VdEnableRingBufferRPtrWriteBack, 0x010001b6
+xbox360_stub VdEnumerateVideoModes, 0x01000270
+xbox360_stub VdGetCurrentDisplayInformation, 0x010001ba
+xbox360_stub VdGetDisplayDiscoveryData, 0x0100027e
+xbox360_stub VdGetSystemCommandBuffer, 0x010001bd
+xbox360_stub VdInitializeEngines, 0x010001c2
+xbox360_stub VdInitializeRingBuffer, 0x010001c3
+xbox360_stub VdReadDVERegisterUlong, 0x010001cb
+xbox360_stub VdRetrainEDRAM, 0x01000269
+xbox360_stub VdRetrainEDRAMWorker, 0x0100026a
+xbox360_stub VdSetDisplayMode, 0x010001d3
+
+.ifndef VdSetDisplayModeOverride
+ xbox360_function VdSetDisplayModeOverride
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 6, 0x18(1)
+ lwz 7, 0x1c(1)
+ xbox360_call VdSetDisplayModeOverride
+ xbox360_return 0x50
+ xbox360_end VdSetDisplayModeOverride, 0x010001d4
+.endif
+
+xbox360_stub VdSetGraphicsInterruptCallback, 0x010001d5
+xbox360_stub VdSetSystemCommandBufferGpuIdentifierAddress, 0x010001d9
+xbox360_stub VdShutdownEngines, 0x010001dc
+
+.ifndef VdSwap
+ xbox360_function VdSwap
+ xbox360_frame 0x60
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x68(1)
+ stw 11, 0x54(1)
+ li 12, 0
+ stw 12, 0x58(1)
+ lwz 11, 0x6c(1)
+ stw 11, 0x5c(1)
+ xbox360_call VdSwap
+ xbox360_return 0x60
+ xbox360_end VdSwap, 0x0100025b
+.endif
+
+xbox360_stub VdWriteDVERegisterUlong, 0x010001e0
+xbox360_stub WaitForSingleObject, 0x01010425
+xbox360_stub XAudioGetRenderDriverThread, 0x010001fe
+xbox360_stub XAudioRegisterRenderDriverClient, 0x010001f3
+xbox360_stub XAudioSetSpeakerConfig, 0x01000200
+xbox360_stub XAudioSubmitRenderDriverFrame, 0x010001f5
+xbox360_stub XAudioUnregisterRenderDriverClient, 0x010001f4
+xbox360_stub XAutomationpBindController, 0x010103d5
+xbox360_stub XAutomationpInputXenonButton, 0x010103d7
+xbox360_stub XAutomationpUnbindController, 0x010103d6
+xbox360_stub XGetAVPack, 0x010103cb
+xbox360_stub XGetAudioFlags, 0x010103ca
+xbox360_stub XGetGameRegion, 0x010103cc
+xbox360_stub XGetVideoMode, 0x010103d1
+xbox360_stub XInputdSetRFPowerMode, 0x010001ef
+xbox360_stub XMABlockWhileInUse, 0x01000235
+xbox360_stub XMACreateContext, 0x01000224
+xbox360_stub XMADisableContext, 0x01000228
+xbox360_stub XMAEnableContext, 0x01000227
+xbox360_stub XMAGetOutputBufferReadOffset, 0x0100022b
+xbox360_stub XMAGetOutputBufferWriteOffset, 0x01000229
+xbox360_stub XMAInitializeContext, 0x01000225
+xbox360_stub XMAIsInputBuffer0Valid, 0x0100022f
+xbox360_stub XMAIsOutputBufferValid, 0x0100022d
+xbox360_stub XMAReleaseContext, 0x01000226
+xbox360_stub XMASetInputBuffer0Valid, 0x0100022e
+xbox360_stub XMASetOutputBufferReadOffset, 0x0100022a
+xbox360_stub XMASetOutputBufferValid, 0x0100022c
+xbox360_stub XMsgCancelIORequest, 0x010101f8
+xbox360_stub XMsgInProcessCall, 0x010101f4
+xbox360_stub XMsgStartIORequest, 0x010101f7
+xbox360_stub XMsgStartIORequestEx, 0x010101fc
+xbox360_stub XMsgSystemProcessCall, 0x010101f6
+xbox360_stub XNetLogonClearTicketCaches, 0x0101013c
+xbox360_stub XNetLogonGetDnsString, 0x01010139
+xbox360_stub XNetLogonGetExtendedStatus, 0x0101013b
+xbox360_stub XNotifyBroadcast, 0x0101028e
+xbox360_stub XNotifyGetNext, 0x0101028b, u8
+xbox360_stub XUsbcamCreate, 0x01000222
+xbox360_stub XUsbcamDestroy, 0x01000223
+xbox360_stub XUsbcamGetState, 0x0100021d
+xbox360_stub XUsbcamSetConfig, 0x0100021c
+xbox360_stub XamAppUnloadStack, 0x01010246
+xbox360_stub XamBackgroundDownloadGetItems, 0x010109c7
+xbox360_stub XamBuildLegacySystemResourceLocator, 0x0101031c
+xbox360_stub XamCacheReset, 0x010102b7
+xbox360_stub XamContentAggregateCreateEnumerator, 0x01010279
+xbox360_stub XamContentClose, 0x0101025a
+xbox360_stub XamContentCopyInternal, 0x0101026c
+xbox360_stub XamContentCreate, 0x01010258
+xbox360_stub XamContentCreateDeviceEnumerator, 0x0101025d
+
+.ifndef XamContentCreateInternal
+ xbox360_function XamContentCreateInternal
+ xbox360_frame 0x50
+ stw 9, 0x28(1)
+ stw 10, 0x2c(1)
+ lwz 9, 0x2c(1)
+ lwz 11, 0x28(1)
+ rldimi 9, 11, 32, 0
+ lwz 10, 0x58(1)
+ xbox360_call XamContentCreateInternal
+ xbox360_return 0x50
+ xbox360_end XamContentCreateInternal, 0x01010271
+.endif
+
+xbox360_stub XamContentDelete, 0x0101025b
+xbox360_stub XamContentDeleteInternal, 0x01010270
+xbox360_stub XamContentFlush, 0x01010267
+xbox360_stub XamContentGetAttributesInternal, 0x01010277
+xbox360_stub XamContentGetDefaultDevice, 0x01010284
+xbox360_stub XamContentGetDeviceData, 0x0101025e
+xbox360_stub XamContentGetMetaDataInternal, 0x0101026e
+xbox360_stub XamContentLaunchImageInternal, 0x01010273
+xbox360_stub XamContentMoveInternal, 0x0101026d
+xbox360_stub XamContentResolveInternal, 0x01010276
+xbox360_stub XamCreateEnumeratorHandle, 0x0101024e
+xbox360_stub XamEnumerate, 0x01010250
+
+.ifndef XamFormatDateString
+ xbox360_function XamFormatDateString
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ lwz 5, 0x20(1)
+ lwz 6, 0x24(1)
+ xbox360_call XamFormatDateString
+ xbox360_return 0x50
+ xbox360_end XamFormatDateString, 0x010101e8
+.endif
+
+
+.ifndef XamFormatTimeString
+ xbox360_function XamFormatTimeString
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ lwz 5, 0x20(1)
+ lwz 6, 0x24(1)
+ xbox360_call XamFormatTimeString
+ xbox360_return 0x50
+ xbox360_end XamFormatTimeString, 0x010101e7
+.endif
+
+xbox360_stub XamGetCachedTitleName, 0x010102b6
+xbox360_stub XamGetCurrentTitleId, 0x010101cf
+xbox360_stub XamGetDefaultSystemImage, 0x010101c5
+xbox360_stub XamGetDvrStorage, 0x01010518
+xbox360_stub XamGetLanguage, 0x010103d2
+xbox360_stub XamGetOverlappedResult, 0x010101fb
+xbox360_stub XamGetPrivateEnumStructureFromHandle, 0x0101024f
+xbox360_stub XamGetSecurityViolationsDetected, 0x01010af3, u64
+xbox360_stub XamGetSystemVersion, 0x01010282
+xbox360_stub XamGetWCNConfigFile, 0x010101c6
+xbox360_stub XamInputGetCapabilities, 0x01010190
+xbox360_stub XamInputGetKeystrokeEx, 0x01010198
+xbox360_stub XamInputGetState, 0x01010191
+xbox360_stub XamInputSetState, 0x01010192
+xbox360_stub XamIptvGetServiceName, 0x0101051a
+xbox360_stub XamIptvUninstall, 0x01010517
+xbox360_stub XamIsSysUiInvokedByTitle, 0x010102eb
+xbox360_stub XamIsSystemTitleId, 0x010101bb, u8
+xbox360_stub XamIsUIActive, 0x010102ec, u8
+xbox360_stub XamIsXbox1TitleId, 0x010101bf, u8
+xbox360_stub XamLoaderGetDvdTrayState, 0x010101aa
+xbox360_stub XamLoaderGetLaunchData, 0x010101a8
+xbox360_stub XamLoaderGetMediaInfo, 0x010101a3
+xbox360_stub XamLoaderGetPriorTitleId, 0x010101be
+xbox360_noreturn XamLoaderLaunchTitle, 0x010101a4
+xbox360_stub XamLoaderLaunchTitleEx, 0x010101a5
+xbox360_stub XamLoaderSetLaunchData, 0x010101a6
+xbox360_noreturn XamLoaderTerminateTitle, 0x010101a9
+xbox360_stub XamMuteSound, 0x010101ca
+
+.ifndef XamNotifyCreateListenerInternal
+ xbox360_function XamNotifyCreateListenerInternal
+ xbox360_frame 0x50
+ stw 3, 0x10(1)
+ stw 4, 0x14(1)
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 3, 0x14(1)
+ lwz 11, 0x10(1)
+ rldimi 3, 11, 32, 0
+ lwz 4, 0x18(1)
+ lwz 5, 0x1c(1)
+ xbox360_call XamNotifyCreateListenerInternal
+ xbox360_return 0x50
+ xbox360_end XamNotifyCreateListenerInternal, 0x01010291
+.endif
+
+xbox360_stub XamPlayTimerForceNotification, 0x01010a64
+xbox360_stub XamPlayTimerGetData, 0x01010a5a
+xbox360_stub XamPlayTimerGetNextResetDate, 0x01010a60
+xbox360_stub XamPlayTimerIsEnabled, 0x01010a5f, u8
+xbox360_stub XamPlayTimerIsRunning, 0x01010a5e, u8
+xbox360_stub XamPlayTimerResume, 0x01010a5c
+xbox360_stub XamPlayTimerSetData, 0x01010a5b
+xbox360_stub XamPlayTimerSuspend, 0x01010a5d
+xbox360_stub XamProfileClose, 0x01010238
+xbox360_stub XamProfileCreate, 0x01010230
+xbox360_stub XamProfileCreateEnumerator, 0x01010231
+
+.ifndef XamProfileDelete
+ xbox360_function XamProfileDelete
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ xbox360_call XamProfileDelete
+ xbox360_return 0x50
+ xbox360_end XamProfileDelete, 0x01010233
+.endif
+
+xbox360_stub XamProfileEnumerate, 0x01010232
+xbox360_stub XamProfileGetCreationStatus, 0x01010234
+
+.ifndef XamProfileLoadAccountInfo
+ xbox360_function XamProfileLoadAccountInfo
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ lwz 5, 0x20(1)
+ xbox360_call XamProfileLoadAccountInfo
+ xbox360_return 0x50
+ xbox360_end XamProfileLoadAccountInfo, 0x0101023a
+.endif
+
+
+.ifndef XamProfileOpen
+ xbox360_function XamProfileOpen
+ xbox360_frame 0x50
+ stw 3, 0x10(1)
+ stw 4, 0x14(1)
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ lwz 3, 0x14(1)
+ lwz 11, 0x10(1)
+ rldimi 3, 11, 32, 0
+ lwz 4, 0x18(1)
+ lwz 5, 0x1c(1)
+ lwz 6, 0x20(1)
+ xbox360_call XamProfileOpen
+ xbox360_return 0x50
+ xbox360_end XamProfileOpen, 0x01010237
+.endif
+
+
+.ifndef XamReadTile
+ xbox360_function XamReadTile
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ stw 9, 0x28(1)
+ stw 10, 0x2c(1)
+ lwz 5, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 5, 11, 32, 0
+ lwz 6, 0x20(1)
+ lwz 7, 0x24(1)
+ lwz 8, 0x28(1)
+ lwz 9, 0x2c(1)
+ xbox360_call XamReadTile
+ xbox360_return 0x50
+ xbox360_end XamReadTile, 0x010102ef
+.endif
+
+
+.ifndef XamReadTileEx
+ xbox360_function XamReadTileEx
+ xbox360_frame 0x60
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ stw 9, 0x28(1)
+ stw 10, 0x2c(1)
+ lwz 5, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 5, 11, 32, 0
+ lwz 6, 0x20(1)
+ lwz 7, 0x24(1)
+ lwz 8, 0x28(1)
+ lwz 9, 0x2c(1)
+ lwz 10, 0x68(1)
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x6c(1)
+ stw 11, 0x54(1)
+ xbox360_call XamReadTileEx
+ xbox360_return 0x60
+ xbox360_end XamReadTileEx, 0x010102fc
+.endif
+
+xbox360_stub XamSetDashContext, 0x010101cc
+xbox360_stub XamSetDvrStorage, 0x01010519
+xbox360_stub XamSetInactivityTimeFromConfig, 0x010101a2
+xbox360_stub XamShowAchievementDetailsUI, 0x010102e0
+xbox360_stub XamShowAchievementsUI, 0x010102c5
+xbox360_stub XamShowCreateProfileUI, 0x010102cf
+
+.ifndef XamShowDeviceSelectorUI
+ xbox360_function XamShowDeviceSelectorUI
+ xbox360_frame 0x50
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ stw 9, 0x28(1)
+ stw 10, 0x2c(1)
+ lwz 6, 0x24(1)
+ lwz 11, 0x20(1)
+ rldimi 6, 11, 32, 0
+ lwz 7, 0x28(1)
+ lwz 8, 0x2c(1)
+ xbox360_call XamShowDeviceSelectorUI
+ xbox360_return 0x50
+ xbox360_end XamShowDeviceSelectorUI, 0x010102cb
+.endif
+
+xbox360_stub XamShowGamerCardUI, 0x010102c4
+
+.ifndef XamShowGamerCardUIForXUID
+ xbox360_function XamShowGamerCardUIForXUID
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ lwz 5, 0x20(1)
+ xbox360_call XamShowGamerCardUIForXUID
+ xbox360_return 0x50
+ xbox360_end XamShowGamerCardUIForXUID, 0x010102d5
+.endif
+
+xbox360_stub XamShowGamesUI, 0x010102d0
+
+.ifndef XamShowJoinSessionInProgressUI
+ xbox360_function XamShowJoinSessionInProgressUI
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 4, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 4, 11, 32, 0
+ xbox360_call XamShowJoinSessionInProgressUI
+ xbox360_return 0x50
+ xbox360_end XamShowJoinSessionInProgressUI, 0x01010301
+.endif
+
+xbox360_stub XamShowKeyboardUI, 0x010102c1
+xbox360_stub XamShowLiveSignupUI, 0x010102d1
+xbox360_stub XamShowLiveUpsellUIEx, 0x01010300
+
+.ifndef XamShowMarketplaceUIEx
+ xbox360_function XamShowMarketplaceUIEx
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ stw 9, 0x28(1)
+ stw 10, 0x2c(1)
+ lwz 5, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 5, 11, 32, 0
+ lwz 6, 0x20(1)
+ lwz 7, 0x24(1)
+ lwz 8, 0x28(1)
+ lwz 9, 0x2c(1)
+ lwz 10, 0x58(1)
+ xbox360_call XamShowMarketplaceUIEx
+ xbox360_return 0x50
+ xbox360_end XamShowMarketplaceUIEx, 0x010102e8
+.endif
+
+
+.ifndef XamShowMessageBoxUI
+ xbox360_function XamShowMessageBoxUI
+ xbox360_frame 0x60
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x68(1)
+ stw 11, 0x54(1)
+ xbox360_call XamShowMessageBoxUI
+ xbox360_return 0x60
+ xbox360_end XamShowMessageBoxUI, 0x010102ca
+.endif
+
+xbox360_stub XamShowPersonalizationUI, 0x010102e1
+xbox360_stub XamShowSigninUI, 0x010102bc
+xbox360_stub XamShowSigninUIp, 0x010102be
+xbox360_stub XamUnloadSysApp, 0x01010252
+
+.ifndef XamUserCreateAchievementEnumerator
+ xbox360_function XamUserCreateAchievementEnumerator
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ stw 9, 0x28(1)
+ stw 10, 0x2c(1)
+ lwz 5, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 5, 11, 32, 0
+ lwz 6, 0x20(1)
+ lwz 7, 0x24(1)
+ lwz 8, 0x28(1)
+ lwz 9, 0x2c(1)
+ lwz 10, 0x58(1)
+ xbox360_call XamUserCreateAchievementEnumerator
+ xbox360_return 0x50
+ xbox360_end XamUserCreateAchievementEnumerator, 0x010102ee
+.endif
+
+
+.ifndef XamUserCreateTitlesPlayedEnumerator
+ xbox360_function XamUserCreateTitlesPlayedEnumerator
+ xbox360_frame 0x50
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ stw 7, 0x20(1)
+ stw 8, 0x24(1)
+ stw 9, 0x28(1)
+ stw 10, 0x2c(1)
+ lwz 5, 0x1c(1)
+ lwz 11, 0x18(1)
+ rldimi 5, 11, 32, 0
+ lwz 6, 0x20(1)
+ lwz 7, 0x24(1)
+ lwz 8, 0x28(1)
+ lwz 9, 0x2c(1)
+ xbox360_call XamUserCreateTitlesPlayedEnumerator
+ xbox360_return 0x50
+ xbox360_end XamUserCreateTitlesPlayedEnumerator, 0x010102f3
+.endif
+
+xbox360_stub XamUserFlushLogonQueue, 0x01010220
+xbox360_stub XamUserGetGamerTag, 0x0101020c
+
+.ifndef XamUserGetIndexFromXUID
+ xbox360_function XamUserGetIndexFromXUID
+ xbox360_frame 0x50
+ stw 3, 0x10(1)
+ stw 4, 0x14(1)
+ stw 5, 0x18(1)
+ stw 6, 0x1c(1)
+ lwz 3, 0x14(1)
+ lwz 11, 0x10(1)
+ rldimi 3, 11, 32, 0
+ lwz 4, 0x18(1)
+ lwz 5, 0x1c(1)
+ xbox360_call XamUserGetIndexFromXUID
+ xbox360_return 0x50
+ xbox360_end XamUserGetIndexFromXUID, 0x01010211
+.endif
+
+xbox360_stub XamUserGetMembershipType, 0x0101021b
+xbox360_stub XamUserGetSigninState, 0x01010210
+xbox360_stub XamUserGetXUID, 0x0101020a
+xbox360_stub XamUserIsOnlineEnabled, 0x01010221, u8
+xbox360_stub XamUserLogon, 0x0101020b
+
+.ifndef XamUserReadProfileSettings
+ xbox360_function XamUserReadProfileSettings
+ xbox360_frame 0x60
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x68(1)
+ stw 11, 0x54(1)
+ xbox360_call XamUserReadProfileSettings
+ xbox360_return 0x60
+ xbox360_end XamUserReadProfileSettings, 0x01010219
+.endif
+
+xbox360_stub XamWriteGamerTile, 0x010102f0
+xbox360_stub XeCryptDesEcb, 0x01000176
+xbox360_stub XeCryptDesKey, 0x01000175
+xbox360_stub XeCryptDesParity, 0x01000174
+
+.ifndef XeCryptHmacSha
+ xbox360_function XeCryptHmacSha
+ xbox360_frame 0x60
+ li 12, 0
+ stw 12, 0x50(1)
+ lwz 11, 0x68(1)
+ stw 11, 0x54(1)
+ li 12, 0
+ stw 12, 0x58(1)
+ lwz 11, 0x6c(1)
+ stw 11, 0x5c(1)
+ xbox360_call XeCryptHmacSha
+ xbox360_return 0x60
+ xbox360_end XeCryptHmacSha, 0x01000182
+.endif
+
+xbox360_stub XeCryptMd5, 0x01000187
+xbox360_stub XeCryptRandom, 0x0100018a
+xbox360_stub XeKeysGetConsoleID, 0x01000246
+xbox360_stub XeKeysGetConsoleType, 0x01000247
+xbox360_stub XeKeysGetKey, 0x01000244
+xbox360_stub XeKeysGetStatus, 0x0100023f
+xbox360_stub XeKeysSaveBootLoader, 0x0100023d
+xbox360_stub XexGetModuleHandle, 0x01000195
+xbox360_stub XexGetModuleSection, 0x01000196
+xbox360_stub XexGetProcedureAddress, 0x01000197
+xbox360_stub XexLoadImage, 0x01000199
+xbox360_stub XexLoadImageFromMemory, 0x0100019a
+xbox360_stub XexPcToFileHeader, 0x0100019c
+xbox360_stub XexUnloadImage, 0x010001a1
+xbox360_slot __imp_ExConsoleGameRegion, 0x0000000c
+xbox360_slot __imp_ExLoadedCommandLine, 0x000001ae
+xbox360_slot __imp_ExLoadedImageName, 0x000001af
+xbox360_slot __imp_ExThreadObjectType, 0x0000001b
+xbox360_slot __imp_IoDeviceObjectType, 0x0000003a
+xbox360_slot __imp_KeDebugMonitorData, 0x00000059
+xbox360_slot __imp_KeTimeStampBundle, 0x000000ad
+xbox360_slot __imp_XboxHardwareInfo, 0x00000156
+xbox360_slot __imp_XboxKrnlBaseVersion, 0x00000157
+xbox360_slot __imp_XboxKrnlVersion, 0x00000158
+xbox360_slot __imp_XexExecutableModuleHandle, 0x00000193
+xbox360_stub _vsnprintf, 0x0100014d
diff --git a/platform/xex/tests/fs/main.cpp b/platform/xex/tests/fs/main.cpp
new file mode 100644
index 0000000..e328a2a
--- /dev/null
+++ b/platform/xex/tests/fs/main.cpp
@@ -0,0 +1,127 @@
+// Runtime check 2: files, directories and time through newlib on the
+// kernel's Nt* API. Writes a report to every writable device and shows a
+// summary as guide notifications; the full report is also on DbgPrint.
+#include <cstdio>
+#include <cstring>
+#include <string>
+#include <vector>
+#include <fstream>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <ctime>
+
+#include "xex_runtime.h"
+
+static std::string report;
+
+static void log(const std::string &line) {
+ report += line + "\n";
+ printf("fs-test: %s\n", line.c_str());
+}
+
+static int listDir(const std::string &path, int maxShow) {
+ DIR *d = opendir(path.c_str());
+ if (!d) {
+ log("opendir " + path + " FAILED");
+ return -1;
+ }
+ int n = 0;
+ while (struct dirent *e = readdir(d)) {
+ if (n < maxShow) log(std::string(" ") + (e->d_type == DT_DIR ? "[" : "") + e->d_name + (e->d_type == DT_DIR ? "]" : ""));
+ n++;
+ }
+ closedir(d);
+ log("opendir " + path + ": " + std::to_string(n) + " entries");
+ return n;
+}
+
+// write, read back with stdio and iostream, stat, append, seek
+static bool fileRoundTrip(const std::string &dir) {
+ std::string path = dir + "/fake08-xex-test.txt";
+ FILE *f = fopen(path.c_str(), "w");
+ if (!f) { log("fopen(w) " + path + " FAILED"); return false; }
+ fputs("hello xbox\n", f);
+ fclose(f);
+
+ f = fopen(path.c_str(), "a");
+ if (!f) { log("fopen(a) FAILED"); return false; }
+ fputs("line2\n", f);
+ fclose(f);
+
+ struct stat st;
+ if (stat(path.c_str(), &st) != 0 || st.st_size != 17) {
+ log("stat FAILED size=" + std::to_string((long)st.st_size));
+ return false;
+ }
+
+ std::ifstream in(path);
+ std::string a, b;
+ std::getline(in, a);
+ std::getline(in, b);
+ if (a != "hello xbox" || b != "line2") { log("read back FAILED '" + a + "' '" + b + "'"); return false; }
+
+ f = fopen(path.c_str(), "rb");
+ fseek(f, 0, SEEK_END);
+ long size = ftell(f);
+ fseek(f, 6, SEEK_SET);
+ char buf[5] = {0};
+ fread(buf, 1, 4, f);
+ fclose(f);
+ if (size != 17 || strcmp(buf, "xbox") != 0) { log("seek FAILED"); return false; }
+
+ std::string sub = dir + "/fake08-xex-dir";
+ mkdir(sub.c_str(), 0777);
+ struct stat sd;
+ bool dirOk = stat(sub.c_str(), &sd) == 0 && S_ISDIR(sd.st_mode);
+ log(std::string("mkdir/stat dir: ") + (dirOk ? "ok" : "FAILED"));
+
+ remove(path.c_str());
+ bool gone = stat(path.c_str(), &st) != 0;
+ log(std::string("remove: ") + (gone ? "ok" : "FAILED"));
+ return dirOk && gone;
+}
+
+int main(int, char **) {
+ std::vector<std::string> summary;
+
+ struct timeval tv;
+ gettimeofday(&tv, nullptr);
+ time_t t = tv.tv_sec;
+ char date[64];
+ strftime(date, sizeof date, "%Y-%m-%d %H:%M:%S", gmtime(&t));
+ log(std::string("time: ") + date + " UTC");
+
+ clock_t c0 = clock();
+ xex_sleep_ms(500);
+ long ms = (long)((clock() - c0) * 1000 / CLOCKS_PER_SEC);
+ log("clock over sleep(500): " + std::to_string(ms) + " ms");
+ summary.push_back(std::string("time ") + date + " clk " + std::to_string(ms));
+
+ const char *devices[] = {"game:", "usb0:", "usb1:", "hdd:"};
+ for (const char *dev : devices) {
+ struct stat st;
+ if (stat(dev, &st) != 0) {
+ log(std::string(dev) + " not present");
+ continue;
+ }
+ int n = listDir(dev, 8);
+ bool rw = fileRoundTrip(dev);
+ std::string s = std::string(dev) + " " + std::to_string(n) + " files, rw " + (rw ? "ok" : "FAIL");
+ log(s);
+ summary.push_back(s);
+ }
+ listDir("usb0:/p8carts", 5);
+
+ // keep the full report next to the XEX
+ if (FILE *f = fopen("game:/fs-test-report.txt", "w")) {
+ fputs(report.c_str(), f);
+ fclose(f);
+ }
+
+ for (auto &s : summary) {
+ xex_notify(s.c_str());
+ xex_sleep_ms(4000);
+ }
+ return 0;
+}
diff --git a/platform/xex/tests/fs/xex.toml b/platform/xex/tests/fs/xex.toml
new file mode 100644
index 0000000..0854722
--- /dev/null
+++ b/platform/xex/tests/fs/xex.toml
@@ -0,0 +1,3 @@
+title_id = 0x46383038 # "F808"
+load_address = 0x82000000
+module_flags = ["TITLE"]
diff --git a/platform/xex/tests/hello/main.cpp b/platform/xex/tests/hello/main.cpp
new file mode 100644
index 0000000..5b3da3a
--- /dev/null
+++ b/platform/xex/tests/hello/main.cpp
@@ -0,0 +1,39 @@
+// Runtime check 1: C++ runtime in a GCC-built XEX (static constructor,
+// exception, std::regex), reported with guide notifications.
+#include <string>
+#include <regex>
+#include <stdexcept>
+#include <cstdio>
+
+#include "xex_runtime.h"
+
+struct StaticInit {
+ int value;
+ StaticInit() : value(42) {}
+};
+static StaticInit g_static;
+
+int main(int, char **) {
+ std::string result = "GCC XEX ok:";
+ result += g_static.value == 42 ? " ctor" : " CTOR-FAIL";
+
+ try {
+ throw std::runtime_error("x");
+ } catch (const std::exception &) {
+ result += " exc";
+ } catch (...) {
+ result += " EXC-WRONG";
+ }
+
+ std::smatch m;
+ std::string s = "#include foo.lua";
+ bool re = std::regex_search(s, m, std::regex("#include\\s+([a-z.]+)")) && m[1] == "foo.lua";
+ result += re ? " regex" : " REGEX-FAIL";
+
+ printf("hello: %s\n", result.c_str());
+ xex_notify("Hello from FAKE-08 XEX (GCC)");
+ xex_sleep_ms(3000);
+ xex_notify(result.c_str());
+ xex_sleep_ms(5000);
+ return 0;
+}
diff --git a/platform/xex/tests/hello/xex.toml b/platform/xex/tests/hello/xex.toml
new file mode 100644
index 0000000..0854722
--- /dev/null
+++ b/platform/xex/tests/hello/xex.toml
@@ -0,0 +1,3 @@
+title_id = 0x46383038 # "F808"
+load_address = 0x82000000
+module_flags = ["TITLE"]
diff --git a/platform/xex/tools/build-xex-link.sh b/platform/xex/tools/build-xex-link.sh
new file mode 100755
index 0000000..f990063
--- /dev/null
+++ b/platform/xex/tools/build-xex-link.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# Builds xex-link (ELF -> XEX converter of xenon-forge) as a static binary
+# into platform/xex/tools/bin/xex-link. Run from the repository root:
+# docker run --rm -v $PWD:/build_dir rust:latest \
+# /bin/sh -ex /build_dir/platform/xex/tools/build-xex-link.sh
+# The xenon-forge checkout is kept in tools/.xenon-forge-src (git-ignored).
+set -e
+XENON_FORGE_REPO=https://github.com/landaire/xenon-forge.git
+XENON_FORGE_COMMIT=2fcc78c
+HERE=$(cd "$(dirname "$0")" && pwd)
+SRC="$HERE/.xenon-forge-src"
+
+if [ ! -d "$SRC/.git" ]; then
+ git clone -q "$XENON_FORGE_REPO" "$SRC"
+fi
+cd "$SRC"
+git fetch -q origin
+git checkout -q "$XENON_FORGE_COMMIT"
+
+rustup target add x86_64-unknown-linux-musl
+cargo build --release -p xex-link --target x86_64-unknown-linux-musl
+
+mkdir -p "$HERE/bin"
+cp target/x86_64-unknown-linux-musl/release/xex-link "$HERE/bin/xex-link"
+"$HERE/bin/xex-link" --help | head -1