diff --git a/runtime/ipc.c b/runtime/ipc.c index c79eaa56..2a4e0dac 100644 --- a/runtime/ipc.c +++ b/runtime/ipc.c @@ -715,13 +715,17 @@ static uint64_t stub(const char *sym) { // mutex look owned by the caller (__cxa_guard_acquire in nn::sm::Initialize aborts); // - sdk's full DT_INIT needs nn::os initialised (its TLS slot constructor reaches ThreadManager), which is the boot // sequence's job (T6). The audio client only needs its two sf heap constructors: 16 KiB ExpHeaps on static buffers, -// stored at sdk+0xd37e90 and sdk+0xd3bec0 (CreateAudioRendererManagerByHipc reads the second). +// stored at sdk+0xd37e90 and sdk+0xd3bec0 (CreateAudioRendererManagerByHipc reads the second). The 1.4.3 SDK creates +// that heap lazily; its OpenAudioRenderer takes nn::audio::detail::g_RendererResourceSemaphore first, which the +// constructor at sdk+0x221fb0 initializes (two renderers). static void sdk_prepare(Cpu *c) { Cpu *again; ST32(LD64(c->tpidrro + 0x1F8) + 0x1B0, kern_main_thread(&again)); const RtLoaded *sdk = ldr_module(2); - static const uint64_t heap_ctors[] = {0x1dcbd0, 0x1de8a0}; - for (unsigned k = 0; !RT_V143 && k < sizeof heap_ctors / sizeof *heap_ctors; k++) { + static const uint64_t ctors_121[] = {0x1dcbd0, 0x1de8a0}, ctors_143[] = {0x221fb0}; + const uint64_t *heap_ctors = RT_V143 ? ctors_143 : ctors_121; + unsigned nctors = RT_V143 ? sizeof ctors_143 / sizeof *ctors_143 : sizeof ctors_121 / sizeof *ctors_121; + for (unsigned k = 0; k < nctors; k++) { int found = 0; for (uint64_t e = 0; e < sdk->init_array_size; e += 8) found |= LD64(sdk->init_array + e) == sdk->base + heap_ctors[k]; @@ -784,7 +788,10 @@ static void probe_sdk_client(Cpu *c) { "lifted client (sm: kept open by the SDK: %ld session)\n", audren_renderers_live(), (unsigned long long)(ipc_sessions_released() - released0), (unsigned long long)requests, ipc_sessions_live()); - CHECK(audren_renderers_live() == 0 && ipc_sessions_released() - released0 >= 3 && ipc_sessions_live() == 1, + // The 1.2.1 SDK closes the renderer, device and manager sessions and keeps sm; the 1.4.3 SDK keeps the + // audren:u manager it created lazily, beside sm. + CHECK(audren_renderers_live() == 0 && ipc_sessions_released() - released0 >= (RT_V143 ? 1u : 3u) && + ipc_sessions_live() == (RT_V143 ? 2 : 1), "SDK CloseAudioRenderer"); rt_trace = trace; } diff --git a/runtime/nvn_api_core.c b/runtime/nvn_api_core.c index 346fd93c..1b33e525 100644 --- a/runtime/nvn_api_core.c +++ b/runtime/nvn_api_core.c @@ -123,8 +123,9 @@ const pool_t *nvn_pool_find(uint64_t addr, uint64_t len) { return p; } -// Physical and virtual pools (MacNativeGames totk_vpool.c:32-52 checks). A CPU-invisible one gets a GPU window range; -// a CPU-visible one would need aliased guest storage, which this port does not support (section 3.3). +// Physical and virtual pools (MacNativeGames totk_vpool.c:32-52 checks). A CPU-invisible one gets a GPU window range. +// A CPU-visible physical pool (1.4.3: flags 0x18c, GPU_NO_ACCESS) keeps the game's storage for the CPU; the back end +// gives it device memory as any physical pool (vk_memory.c vk_pool_init), which the GPU reaches through virtual pools. static int pool_place(pool_t *o) { int phys = (o->flags & NVN_MEMORY_POOL_FLAGS_PHYSICAL) != 0, virt = (o->flags & NVN_MEMORY_POOL_FLAGS_VIRTUAL) != 0; if (!phys && !virt) return 1; @@ -136,9 +137,15 @@ static int pool_place(pool_t *o) { } if (virt && o->mem) { rt_log("nvn: virtual pool given storage %p", (void *)o->mem); return 0; } if (phys && !o->mem) { rt_log("nvn: physical pool without storage"); return 0; } - if (!(o->flags & NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS)) - rt_fatal("nvn: CPU-visible %s pool (flags %#x, size %#llx) needs aliased guest storage", - kind, o->flags, (unsigned long long)o->size); + if (!(o->flags & NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS)) { + if (virt) { + rt_log("nvn: CPU-visible virtual pool (flags %#x, size %#llx) refused", o->flags, (unsigned long long)o->size); + return 0; + } + rt_log("nvn: CPU-visible physical pool %p (flags %#x, size %#llx) keeps the game's storage", (void *)o->mem, + o->flags, (unsigned long long)o->size); + return 1; + } uint64_t a = gva_alloc(o->size); if (!a) { rt_log("nvn: GPU address window full, %s pool of %#llx bytes refused", kind, (unsigned long long)o->size); diff --git a/runtime/ov_probe.c b/runtime/ov_probe.c index 41c7a59a..1cda9e1e 100644 --- a/runtime/ov_probe.c +++ b/runtime/ov_probe.c @@ -75,6 +75,7 @@ static Ov ovs[] = { // SDK-internal (section 5.2) {"nndiagStartup", "nndiagStartup"}, {"aoc.Initialize", "_ZN2nn3aoc10InitializeEv"}, + {"aoc.ListAddOnContent", "_ZN2nn3aoc16ListAddOnContentEPiii"}, {"err.InitializeContextWriterApi", "_ZN2nn3err26InitializeContextWriterApiEv"}, {"pctl.Initialize", "_ZN2nn4pctl10InitializeEv"}, {"diag.InitializeApplicationAbortObserver", "_ZN2nn4diag34InitializeApplicationAbortObserverEv"}, @@ -374,6 +375,7 @@ static void probe_applet(void) { CALL("err.ShowError", 0x2a8); CALL("nndiagStartup", 0); CALL("aoc.Initialize", 0); + CHECK(CALL("aoc.ListAddOnContent", U(out), 0, 8) == 0, "aoc: no add-on content"); CALL("err.InitializeContextWriterApi", 0); CALL("pctl.Initialize", 0); CALL("diag.InitializeApplicationAbortObserver", 0); @@ -966,7 +968,9 @@ int probe_services(void) { for (int k = 0; k < NOBS; k++) if (!strcmp(observers[k], n)) obs_bound++; } - for (int k = 0; k < NOV; k++) CHECK(ovs[k].bound, "override %s matches no relocation", ovs[k].name); + for (int k = 0; k < NOV; k++) // 1.2.1 lists no add-on content + CHECK(ovs[k].bound || (!RT_V143 && !strcmp(ovs[k].key, "aoc.ListAddOnContent")), "override %s matches no relocation", + ovs[k].name); for (int k = 0; k < NOBS; k++) CHECK(hostfn_observer(observers[k]), "observer %s is not linked", observers[k]); CHECK(obs_bound == NOBS, "%d of %d observers match a JUMP_SLOT", obs_bound, NOBS); diff --git a/runtime/ov_system.c b/runtime/ov_system.c index b732dc47..b2a7d893 100644 --- a/runtime/ov_system.c +++ b/runtime/ov_system.c @@ -301,6 +301,13 @@ static void ov_show_error(Cpu *c) { // ==== SDK-internal initialisation (services.c:208-218) static void ov_diag_startup(Cpu *c) { (void)c; rt_log("diag: host diagnostics"); } static void ov_aoc_initialize(Cpu *c) { (void)c; rt_log("aoc: no add-on content"); } +// 1.4.3's main lists add-on content (MNG services.c host_aoc_list): there is none. +// int ListAddOnContent(AddOnContentIndex *out, int offset, int count) +static void ov_aoc_list(Cpu *c) { + int offset = (int)arg_x(c, 1), count = (int)arg_x(c, 2); + if (offset < 0 || count < 0) rt_fatal("aoc: ListAddOnContent range %d+%d", offset, count); + ret_x(c, 0); +} static void ov_err_context(Cpu *c) { (void)c; rt_log("err: error contexts stay local"); } static void ov_pctl_initialize(Cpu *c) { (void)c; rt_log("pctl: no parental controls"); } static void ov_abort_observer(Cpu *c) { (void)c; rt_log("diag: the host crash reporter observes aborts"); } @@ -820,6 +827,7 @@ HOST_OVERRIDE("_ZN2nn3err9ShowErrorENS_6ResultE", ov_show_error); HOST_OVERRIDE("nndiagStartup", ov_diag_startup); HOST_OVERRIDE("_ZN2nn3aoc10InitializeEv", ov_aoc_initialize); +HOST_OVERRIDE("_ZN2nn3aoc16ListAddOnContentEPiii", ov_aoc_list); HOST_OVERRIDE("_ZN2nn3err26InitializeContextWriterApiEv", ov_err_context); HOST_OVERRIDE("_ZN2nn4pctl10InitializeEv", ov_pctl_initialize); HOST_OVERRIDE("_ZN2nn4diag34InitializeApplicationAbortObserverEv", ov_abort_observer); diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index 56a5ad91..c1103b4a 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -242,7 +242,9 @@ static void destroy_rec(VkCtx *c, PoolRec *r) { int vk_pool_init(pool_t *p) { VkCtx *c = vk_ctx(); if (!c) { rt_log("vk: MemoryPoolInitialize before vk_init"); return 0; } - // The GPU never sees a GPU_NO_ACCESS pool, except a physical one (0x189) through the virtual pools that map it. + // The GPU never sees a GPU_NO_ACCESS pool, except a physical one (0x189; 1.4.3 also 0x18c, CPU-visible) through the + // virtual pools that map it. Either gets device-local memory: 1.4.3's CPU never writes its 0x18c pool's storage + // (unchanged over 3600 frames of the intro), so the guest storage and the GPU copy need no sync. if ((p->flags & NVN_MEMORY_POOL_FLAGS_GPU_NO_ACCESS) && !(p->flags & NVN_MEMORY_POOL_FLAGS_PHYSICAL)) return 1; PoolRec *r = calloc(1, sizeof *r); if (!r) rt_fatal("vk: out of memory for a pool record"); diff --git a/tools/package_build.py b/tools/package_build.py index 734ea7ba..302075e0 100644 --- a/tools/package_build.py +++ b/tools/package_build.py @@ -1,16 +1,16 @@ -"""Package a built totk.exe into a folder that runs from anywhere: build/v121-portable by default. +"""Package a built totk.exe into a folder that runs from anywhere: build/-portable by default. The folder holds the exe, its DLLs, the shader translator (NativeAOT: no .NET), the RomFS index and patches, the extracted ExeFS (the game code the exe loads), the shared fonts, the prepared shader and pipeline files. There is no config file: totk.exe finds the exefs, romfs, profile and shared-fonts folders next to itself. Without --with-romfs -the 16 GB RomFS image stays out; copy build/extracted/v121/romfs/romfs.bin to /romfs/ or set TOTK_ROMFS +the 16 GB RomFS image stays out; copy build/extracted//romfs/romfs.bin to /romfs/ or set TOTK_ROMFS (a path, relative ones to the exe's folder). The folder contains game code and data derived from the game: for your own machines only, never publish or share it. Saves go to /profile. - .venv/Scripts/python tools/package_build.py [--build build/v121] [--exe PATH/totk.exe] [--out build/v121-portable] - [--with-romfs] [--no-shader-cache] + .venv/Scripts/python tools/package_build.py [--version v121] [--build build/v121] [--exe PATH/totk.exe] + [--out build/v121-portable] [--with-romfs] [--no-shader-cache] """ import argparse import os @@ -48,14 +48,18 @@ def size_of(path): def main(): ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) - ap.add_argument('--build', type=Path, default=ROOT / 'build' / 'v121', help='build dir with the prepared state') + ap.add_argument('--version', default='v121', help='game version (v121 or v143): the defaults below follow it') + ap.add_argument('--build', type=Path, help='build dir with the prepared state (default build/)') ap.add_argument('--exe', type=Path, help='totk.exe to package (default: /totk.exe); its DLLs are taken from --build') ap.add_argument('--xlate', type=Path, default=ROOT / 'build' / 'xlate' / 'totk_xlate.exe') - ap.add_argument('--extracted', type=Path, default=ROOT / 'build' / 'extracted' / 'v121') - ap.add_argument('--out', type=Path, default=ROOT / 'build' / 'v121-portable') + ap.add_argument('--extracted', type=Path, help='default build/extracted/') + ap.add_argument('--out', type=Path, help='default build/-portable') ap.add_argument('--with-romfs', action='store_true', help='also copy romfs.bin (about 16 GB)') ap.add_argument('--no-shader-cache', action='store_true', help='leave out shader-cache (about 2 GB): translates again') a = ap.parse_args() + a.build = a.build or ROOT / 'build' / a.version + a.extracted = a.extracted or ROOT / 'build' / 'extracted' / a.version + a.out = a.out or ROOT / 'build' / f'{a.version}-portable' build, out = a.build.resolve(), a.out.resolve() exe = (a.exe or build / 'totk.exe').resolve()