llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8
Native app: Qwen 3.8 27B on the PS5 GPU through RADV
Abhirama41ac3b61618
diff --git a/.gitignore b/.gitignoreindex 742a88b..1920350 100644--- a/.gitignore+++ b/.gitignore@@ -13,3 +13,6 @@ models/.DS_Store.wrangler/++# the app's home screen backgrounds, made from ps5/app/sce_sys/source by scripts/build-app.sh+ps5/app/sce_sys/*.ddsdiff --git a/README.md b/README.mdindex 1b5cf81..24e49c2 100644--- a/README.md+++ b/README.md@@ -11,6 +11,8 @@The first target is **Qwen 3.8** (27B, hybrid Gated DeltaNet attention), the newest open Qwen. No one has run it on a PS5 yet.> **Status:** v0.1 is out. One payload, `ps5lm.elf`, opens a model library in the PS5's browser: download a model on the console, run it, chat. Small models for now (up to 1.6 GB, Qwen3.5 0.8B and 2B). See [docs/ROADMAP.md](docs/ROADMAP.md) and [docs/CONSOLE.md](docs/CONSOLE.md).+>+> **New: Qwen 3.8 27B on the GPU.** A native app (`ps5/app`) runs llama.cpp's Vulkan backend on Mihawk-99's RADV port with the console's 12 GiB of direct memory: Qwen3.8-27B UD-IQ2_XXS answers at 9 to 21 tok/s, chat at `http://<console IP>:8081`. Built from source for now (below).## Install@@ -40,6 +42,7 @@ Earlier PS5 LLM work hand-writes GPU kernels for one model at a time. PS5LM port|---|---|| `third_party/llama.cpp` | upstream llama.cpp, pinned as a submodule || `ps5/compat` | the few libc functions the console lacks |+| `ps5/app` | the native app: llama-server on the GPU through RADV, its icon and `param.json` || `patches/` | PS5 changes to llama.cpp's source, kept small || `probes/` | `memprobe` and `threadprobe`: what a payload gets on the console || `scripts/` | SDK setup, the llama.cpp cross build, sending payloads |@@ -85,6 +88,17 @@ scripts/run.sh llama-cli -m /data/PS5LM/models/model.gguf -p "Hello from a PS5"scripts/run.sh llama-server -m /data/PS5LM/models/model.gguf --host 0.0.0.0 --port 8081```+## The GPU app++The app links llama.cpp with ggml-vulkan against [PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan)'s RADV build. Set up PS5_Vulkan and its forks in `.deps/src` (`PS5_Vulkan`, `PS5_Mesa` and `PS5_PayloadSDK` at the revisions PS5_Vulkan pins), then:++```sh+(cd .deps/src/PS5_Vulkan && tools/setup-native-dependencies.sh && tools/build-radv.sh release && make app)+scripts/build-app.sh # build/app-ps5/title/PPSA99581+```++Copy `build/app-ps5/title/PPSA99581` to `/data/homebrew/PPSA99581` and the model to `/data/PS5LM/models`, then start **PS5LM** from the home screen. The screen stays black; after about 90 s the chat is at `http://<console IP>:8081`. Its arguments come from `/data/PS5LM/app-args.txt` (one per line) and its log goes to `/data/PS5LM/app.log` and `llama.log`.+## Credits- [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp), which does the actual work.diff --git a/docs/CONSOLE.md b/docs/CONSOLE.mdindex 9ee5f75..3f3bbb6 100644--- a/docs/CONSOLE.md+++ b/docs/CONSOLE.md@@ -75,3 +75,23 @@ At exit, Sony's libc prints `[SceLibc] A heap error is detected` (SceLibcInterna- Programs need an absolute path; a relative one, and very long command lines, end with exit code 3 ("command not found").- `kill` takes no `-9`; Payload Manager's `/process_kill?pid=N` works.- `browse <URL>` opens the PS5's web browser.++## The native app on the GPU++PS5LM's app (`ps5/app`, PPSA99581) is a title, not a payload: it gets the console's direct memory and the GPU, through ggml-vulkan on PS5_Vulkan's RADV.++| What | Value |+|---|---|+| Direct memory for the title | 12 GiB; RADV reports one 11.44 GiB device heap with `radv_enable_unified_heap_on_apu` (8 GiB without) |+| Device | PlayStation 5 GPU (RADV NAVI21), Vulkan 1.4 |+| Qwen3.8-27B UD-IQ2_XXS, `-ngl 999 -lm none -c 4096 -ub 64` | loads in 82 s |+| Prompt | 35 to 50 tok/s |+| Generation | 21 tok/s on a short prompt, 9 tok/s after the web UI's 371-token prompt |++What a title has to do differently from a payload, each found by a crash:++- **Never exit.** `exit()` and `_Exit` end in SIGSYS; the title waits for the shell to close it, as ps5-native-app-boilerplate's examples do. It hides the splash screen itself and posts notifications to show its state.+- **Imports that resolve to nothing.** Functions only `libScePosixForWebKit` or `libkernel_sys` define in the SDK's stubs are null in a title: `isatty` (llama.cpp's log setup jumped to address 0), `getnameinfo`, `mkstemp`, `readlink`, `link`, `symlink`, `pathconf`, `fork`. `ps5/app/compat_app.c` defines them, in an archive so the title exports nothing.+- **The SDK fork's `getaddrinfo` always fails**, and cpp-httplib resolves even the address it binds; `compat_app.c` has a numeric one. Its `accept4` is the title's own too, and logs `errno` when `accept` fails: with the payload's version the listener stopped 20 s into the first run.+- **No `HOME`**: llama.cpp throws looking for its cache directory without one.+- C++ exceptions and RTTI are off by default for the PS5 target and must be turned on for llama.cpp.diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 9fe787a..89c8173 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -45,7 +45,8 @@ Decoding is bound by memory bandwidth: tokens per second ≈ effective bandwidth- [x] Safe CPU defaults for the PS5 (`patches/0001`): threads = allowed CPUs minus two, no busy-waiting- [x] `llama-server` on the console with a chat page in the PS5's own browser (`scripts/ps5-chat.sh`, `ps5/webui`); phones and laptops use the same page on port 8081- [ ] `llama-bench` numbers for the small model-- [ ] **First light: Qwen3.8-27B generates text on the PS5.** UD-Q2_K_XL if Phase 0 says it fits, UD-IQ2_XXS if not. A video of it, posted with the repo.+- [x] **First light: Qwen3.8-27B generates text on the PS5** (2026-10-09). UD-IQ1_S (5.77 GiB) in a payload, mapped from `/data` and paged in from the SSD, so about one token a minute (`-fit off`: llama.cpp's fit step asks for one 525 MB block a payload cannot get). The GPU app below is the real result.+- [ ] A video of it, posted with the repo.Expect 1 to 3 tok/s here. Slow, but it is Qwen 3.8 running on a PS5, and the claim we want first.@@ -77,13 +78,14 @@ An Ollama-like way to get models and chat, without a PC in the loop. One payloadThe route: ggml's Vulkan backend on [Mihawk-99's PS5_Vulkan](https://github.com/mihawk-99/PS5_Vulkan), whose RADV driver (Mesa 26.2 from [PS5_Mesa](https://github.com/mihawk-99/PS5_Mesa), on a PS5 winsys over the console's AGC functions) reports Vulkan 1.4 and compiles shaders with ACO on the console. llama.cpp keeps its own kernels, so every model and quant comes along. RADV has everything ggml-vulkan requires but no cooperative matrix and no accelerated integer dot product, so matrix products take the fp16 shaders ([RESEARCH.md](RESEARCH.md)).-- [ ] Build RADV: `tools/setup-native-dependencies.sh`, then `tools/build-radv.sh release` in PS5_Vulkan (CachyOS or Arch is the tested host; an Arch machine in OrbStack avoids an untested Ubuntu). Output: `libvulkan_radeon.ps5.a`-- [ ] App shell: `eboot.bin` with `sce_sys/param.json`, from [ps5-native-app-boilerplate](https://github.com/blackbearreloaded/ps5-native-app-boilerplate), mounted by ShadowMountPlus, jailbroken at start through the HEN request PS5SX2 uses (the title ID must be on etaHEN's allowlist)-- [ ] ggml-vulkan cross-compiled, its shaders compiled to SPIR-V on the host, linked as `tools/radv-link.sh` does (`--whole-archive`, `--defsym` for the `vk*` entry points ggml calls directly)+- [x] Build RADV: `tools/setup-native-dependencies.sh`, then `tools/build-radv.sh release` in PS5_Vulkan. Built on Fedora 44 (needs `spirv-tools-devel` and the LLVM, Clang, libclc and SPIR-V translator development packages). Output: `libvulkan_radeon.ps5.a`; its smoke title passed 101 of 102 checks on the console (the miss is a display mode)+- [x] App shell: `eboot.bin` with `sce_sys/param.json` (PPSA99581), linked as PS5_Vulkan's titles are, mounted by ShadowMountPlus from `/data/homebrew`. No jailbreak request needed: the title reads `/data/PS5LM` and serves on the network as it is (`scripts/build-app.sh`, `ps5/app`)+- [x] ggml-vulkan cross-compiled, its shaders compiled to SPIR-V on the host, linked as `tools/radv-link.sh` does. No Vulkan loader: `vkGetInstanceProcAddr` forwards to RADV's ICD entry point, and the three commands ggml calls by name go to Mesa's `vk_common_*`- [ ] `test-backend-ops` on the console: every op the `qwen35` graph uses matches the CPU- [ ] Prompt processing in small batches: a submit that makes no progress for 10 s loses the device, and Gated DeltaNet loops over every token of a batch in one dispatch-- [ ] Weights in device memory. RADV's heaps come out of one direct memory pool of about 12 GiB, shared with the CPU side, so UD-IQ2_XXS (6.77 GiB) before UD-Q2_K_XL-- [ ] Qwen3.8-27B decoding on the GPU, target 15 tok/s or more+- [x] Weights in device memory: with `radv_enable_unified_heap_on_apu` RADV reports one 11.44 GiB device heap over the title's 12 GiB direct memory (2/3 of it by default). UD-IQ2_XXS (6.77 GiB) loads in 82 s+- [ ] UD-Q2_K_XL (9.15 GiB) on the GPU+- [x] Qwen3.8-27B decoding on the GPU (2026-10-09): 21 tok/s on a short prompt, 9 tok/s in the web UI, prompts at 35 to 50 tok/s, through llama-server on port 8081**Done when** the GPU decodes at least five times faster than the CPU.diff --git a/ps5/app/compat_app.c b/ps5/app/compat_app.cnew file mode 100644index 0000000..0ecd779--- /dev/null+++ b/ps5/app/compat_app.c@@ -0,0 +1,261 @@+/* libc functions llama.cpp's common code references that no system module+ * gives a title. None of them is on the inference path: they back spawning+ * tools, the home directory lookup, cookie dates and mmap hints.+ *+ * SPDX-License-Identifier: GPL-3.0-or-later+ */+#include <errno.h>+#include <fcntl.h>+#include <pwd.h>+#include <stddef.h>+#include <time.h>+#include <unistd.h>++int execlp(const char *file, const char *arg, ...) {+ (void)file;+ (void)arg;+ errno = ENOSYS;+ return -1;+}++int pipe2(int fds[2], int flags) {+ if (pipe(fds) != 0)+ return -1;+ for (int i = 0; i < 2; i++) {+ if ((flags & O_CLOEXEC) && fcntl(fds[i], F_SETFD, FD_CLOEXEC) == -1)+ goto fail;+ if ((flags & O_NONBLOCK) && fcntl(fds[i], F_SETFL, fcntl(fds[i], F_GETFL) | O_NONBLOCK) == -1)+ goto fail;+ }+ return 0;+fail:+ close(fds[0]);+ close(fds[1]);+ return -1;+}++struct passwd *getpwuid(uid_t uid) {+ (void)uid;+ return NULL;+}++/* Days from 1970-01-01 to the given civil date (Howard Hinnant's algorithm). */+static long long days_from_civil(long long y, unsigned m, unsigned d) {+ y -= m <= 2;+ const long long era = (y >= 0 ? y : y - 399) / 400;+ const unsigned yoe = (unsigned)(y - era * 400);+ const unsigned doy = (153 * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1;+ const unsigned doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;+ return era * 146097 + (long long)doe - 719468;+}++time_t timegm(struct tm *tm) {+ long long y = tm->tm_year + 1900LL;+ long long mon = tm->tm_mon;+ y += mon / 12;+ mon %= 12;+ if (mon < 0) {+ mon += 12;+ y--;+ }+ const long long days = days_from_civil(y, (unsigned)mon + 1, 1) + tm->tm_mday - 1;+ return (time_t)(days * 86400 + tm->tm_hour * 3600LL + tm->tm_min * 60LL + tm->tm_sec);+}++int posix_madvise(void *addr, size_t len, int advice) {+ (void)addr;+ (void)len;+ (void)advice;+ return 0;+}++/* Imports only libScePosixForWebKit or libkernel_sys define in the SDK's+ * stubs. Those modules give a title nothing, so each import would be a call+ * through NULL (isatty, from llama.cpp's log setup, was the first). Defined+ * here, the link binds them locally. */+#include <arpa/inet.h>+#include <netdb.h>+#include <netinet/in.h>+#include <stdio.h>+#include <string.h>+#include <sys/socket.h>+#include <sys/types.h>++int isatty(int fd) {+ (void)fd;+ errno = ENOTTY;+ return 0;+}++pid_t fork(void) {+ errno = ENOSYS;+ return -1;+}++long pathconf(const char *path, int name) {+ (void)path;+ (void)name;+ errno = EINVAL;+ return -1;+}++ssize_t readlink(const char *restrict path, char *restrict buf, size_t size) {+ (void)path;+ (void)buf;+ (void)size;+ errno = EINVAL; /* not a symbolic link */+ return -1;+}++int link(const char *from, const char *to) {+ (void)from;+ (void)to;+ errno = ENOSYS;+ return -1;+}++int symlink(const char *from, const char *to) {+ (void)from;+ (void)to;+ errno = ENOSYS;+ return -1;+}++int mkstemp(char *path) {+ const size_t n = strlen(path);+ if (n < 6 || strcmp(path + n - 6, "XXXXXX") != 0) {+ errno = EINVAL;+ return -1;+ }+ static const char chars[] = "abcdefghijklmnopqrstuvwxyz0123456789";+ static unsigned counter;+ for (int attempt = 0; attempt < 100; attempt++) {+ unsigned v = (unsigned)time(NULL) * 2654435761u + (++counter) * 40503u + (unsigned)attempt;+ for (int i = 0; i < 6; i++) {+ path[n - 6 + i] = chars[v % 36];+ v = v / 36 + 7919u * (unsigned)i;+ }+ const int fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0600);+ if (fd >= 0 || errno != EEXIST)+ return fd;+ }+ errno = EEXIST;+ return -1;+}++/* Numeric only: the console has no reverse lookup, and the HTTP server asks+ * for numeric host and port. */+int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict host, size_t hostlen,+ char *restrict serv, size_t servlen, int flags) {+ (void)salen;+ (void)flags;+ const void *addr;+ unsigned port;+ if (sa->sa_family == AF_INET) {+ const struct sockaddr_in *in = (const struct sockaddr_in *)sa;+ addr = &in->sin_addr;+ port = ntohs(in->sin_port);+ } else if (sa->sa_family == AF_INET6) {+ const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *)sa;+ addr = &in6->sin6_addr;+ port = ntohs(in6->sin6_port);+ } else {+ return EAI_FAMILY;+ }+ if (host != NULL && hostlen > 0 && inet_ntop(sa->sa_family, addr, host, (socklen_t)hostlen) == NULL)+ return EAI_OVERFLOW;+ if (serv != NULL && servlen > 0 && snprintf(serv, servlen, "%u", port) >= (int)servlen)+ return EAI_OVERFLOW;+ return 0;+}++/* The SDK fork's platform getaddrinfo always fails (EAI_FAIL), and+ * cpp-httplib resolves even the address it binds to through getaddrinfo:+ * llama-server could not bind 0.0.0.0. Numeric addresses and the passive+ * wildcard are all a server needs; names are refused. */+#include <stdlib.h>++static struct addrinfo *make_ai(int family, int socktype, int protocol, const void *addr, unsigned port) {+ const size_t addrlen = family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);+ struct addrinfo *ai = calloc(1, sizeof(*ai) + addrlen);+ if (ai == NULL)+ return NULL;+ ai->ai_family = family;+ ai->ai_socktype = socktype;+ ai->ai_protocol = protocol;+ ai->ai_addrlen = (socklen_t)addrlen;+ ai->ai_addr = (struct sockaddr *)(ai + 1);+ if (family == AF_INET) {+ struct sockaddr_in *in = (struct sockaddr_in *)ai->ai_addr;+ in->sin_len = sizeof(*in);+ in->sin_family = AF_INET;+ in->sin_port = htons((unsigned short)port);+ memcpy(&in->sin_addr, addr, sizeof(in->sin_addr));+ } else {+ struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)ai->ai_addr;+ in6->sin6_len = sizeof(*in6);+ in6->sin6_family = AF_INET6;+ in6->sin6_port = htons((unsigned short)port);+ memcpy(&in6->sin6_addr, addr, sizeof(in6->sin6_addr));+ }+ return ai;+}++int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {+ const int family = hints ? hints->ai_family : AF_UNSPEC;+ const int socktype = hints ? hints->ai_socktype : 0;+ const int protocol = hints ? hints->ai_protocol : 0;+ const int passive = hints && (hints->ai_flags & AI_PASSIVE);+ unsigned port = 0;+ if (service != NULL && *service != '\0') {+ char *end;+ const unsigned long v = strtoul(service, &end, 10);+ if (*end != '\0' || v > 65535)+ return EAI_SERVICE;+ port = (unsigned)v;+ }+ struct in_addr v4;+ struct in6_addr v6;+ if (node == NULL || strcmp(node, "localhost") == 0) {+ if (family == AF_INET6) {+ v6 = node == NULL && passive ? in6addr_any : in6addr_loopback;+ *res = make_ai(AF_INET6, socktype, protocol, &v6, port);+ } else {+ v4.s_addr = htonl(node == NULL && passive ? INADDR_ANY : INADDR_LOOPBACK);+ *res = make_ai(AF_INET, socktype, protocol, &v4, port);+ }+ } else if (family != AF_INET6 && inet_pton(AF_INET, node, &v4) == 1) {+ *res = make_ai(AF_INET, socktype, protocol, &v4, port);+ } else if (family != AF_INET && inet_pton(AF_INET6, node, &v6) == 1) {+ *res = make_ai(AF_INET6, socktype, protocol, &v6, port);+ } else {+ return EAI_NONAME;+ }+ return *res != NULL ? 0 : EAI_MEMORY;+}++void freeaddrinfo(struct addrinfo *ai) {+ while (ai != NULL) {+ struct addrinfo *next = ai->ai_next;+ free(ai);+ ai = next;+ }+}++/* accept4 for the title, with the reason logged when accept fails: the HTTP+ * listener stops on any error it does not know to be transient. */+int accept4(int s, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) {+ const int fd = accept(s, addr, addrlen);+ if (fd < 0) {+ const int saved = errno;+ fprintf(stderr, "ps5lm-app: accept failed, errno %d\n", saved);+ errno = saved;+ return fd;+ }+ if (flags & SOCK_NONBLOCK) {+ const int fl = fcntl(fd, F_GETFL);+ if (fl != -1)+ (void)fcntl(fd, F_SETFL, fl | O_NONBLOCK);+ }+ return fd;+}diff --git a/ps5/app/main.cpp b/ps5/app/main.cppnew file mode 100644index 0000000..2cd2eae--- /dev/null+++ b/ps5/app/main.cpp@@ -0,0 +1,149 @@+// PS5LM native app: llama-server on the PS5's GPU through RADV (ggml-vulkan).+//+// A title gets the console's direct memory (12 GiB) where a payload gets none,+// and RADV turns it into Vulkan device memory, so the whole model sits on the+// GPU. The app runs llama-server on port 8081, logs to /data/PS5LM/app.log and+// takes its arguments from /data/PS5LM/app-args.txt, one per line (FTP lets+// them change without a rebuild).+//+// SPDX-License-Identifier: GPL-3.0-or-later++#include <cstdint>+#include <cstdio>+#include <cstdlib>+#include <exception>+#include <fstream>+#include <string>+#include <vector>++#include <vulkan/vulkan_core.h>++#include "ggml-backend.h"++int llama_server(int argc, char ** argv);++// No Vulkan loader on the console: RADV is linked in whole, and ggml-vulkan's+// dispatcher starts from vkGetInstanceProcAddr, which the ICD entry point+// answers for every command.+extern "C" PFN_vkVoidFunction vk_icdGetInstanceProcAddr(VkInstance instance, const char * name);+extern "C" PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const char * name) {+ return vk_icdGetInstanceProcAddr(instance, name);+}++// The few commands ggml-vulkan calls by name rather than through its+// dispatcher go to Mesa's common implementations, which dispatch through the+// object's own table.+extern "C" PFN_vkVoidFunction vk_common_GetDeviceProcAddr(VkDevice device, const char * name);+extern "C" void vk_common_GetPhysicalDeviceFeatures2(VkPhysicalDevice dev, VkPhysicalDeviceFeatures2 * features);+extern "C" void vk_common_CmdCopyBuffer(VkCommandBuffer cmd, VkBuffer src, VkBuffer dst, uint32_t n,+ const VkBufferCopy * regions);+extern "C" PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char * name) {+ return vk_common_GetDeviceProcAddr(device, name);+}+extern "C" void vkGetPhysicalDeviceFeatures2(VkPhysicalDevice dev, VkPhysicalDeviceFeatures2 * features) {+ vk_common_GetPhysicalDeviceFeatures2(dev, features);+}+extern "C" void vkCmdCopyBuffer(VkCommandBuffer cmd, VkBuffer src, VkBuffer dst, uint32_t n,+ const VkBufferCopy * regions) {+ vk_common_CmdCopyBuffer(cmd, src, dst, n, regions);+}++extern "C" {+int sceSystemServiceHideSplashScreen(void);+int sceKernelSendNotificationRequest(uint32_t device, void * request, size_t size, int blocking);+int sceKernelUsleep(uint32_t microseconds);+}++// A system notification on the TV: the app draws nothing itself.+static void notify(const char * text) {+ struct {+ uint8_t reserved[45];+ char message[3075];+ } request = {};+ std::snprintf(request.message, sizeof(request.message), "%s", text);+ sceKernelSendNotificationRequest(0, &request, sizeof(request), 0);+}++static const char * k_log = "/data/PS5LM/app.log";+static const char * k_args = "/data/PS5LM/app-args.txt";++static std::vector<std::string> read_args() {+ std::vector<std::string> args;+ std::ifstream in(k_args);+ for (std::string line; std::getline(in, line);) {+ while (!line.empty() && (line.back() == '\r' || line.back() == ' ')) {+ line.pop_back();+ }+ if (!line.empty() && line[0] != '#') {+ args.push_back(line);+ }+ }+ if (args.empty()) {+ args = { "-m", "/data/PS5LM/models/Qwen3.8-27B-UD-IQ2_XXS.gguf", "-ngl", "999", "-fit", "off",+ "-lm", "none", "-c", "4096", "-b", "256", "-ub", "64", "-np", "1",+ "--host", "0.0.0.0", "--port", "8081" };+ }+ return args;+}++int main(int, char **) {+ // The splash stays up until a title hides it; this one draws nothing, so+ // it hides it at once (as the boilerplate's headless examples do).+ (void)sceSystemServiceHideSplashScreen();++ // stdout and stderr to a file the PC can fetch over FTP.+ if (std::freopen(k_log, "w", stdout) != nullptr) {+ setvbuf(stdout, nullptr, _IOLBF, 0);+ }+ if (std::freopen(k_log, "a", stderr) != nullptr) {+ setvbuf(stderr, nullptr, _IONBF, 0);+ }++ // RADV splits an APU's memory into 2/3 device-local and 1/3 host heaps;+ // one device-local heap over the whole pool lets the model take nearly all+ // of the 12 GiB.+ setenv("radv_enable_unified_heap_on_apu", "true", 1);+ // A title has no HOME, and llama.cpp throws when it looks for its cache+ // directory without one.+ setenv("HOME", "/data/PS5LM", 0);+ setenv("LLAMA_CACHE", "/data/PS5LM/cache", 0);++ std::printf("ps5lm-app: start\n");+ for (size_t i = 0; i < ggml_backend_dev_count(); i++) {+ ggml_backend_dev_t dev = ggml_backend_dev_get(i);+ size_t free = 0, total = 0;+ ggml_backend_dev_memory(dev, &free, &total);+ std::printf("ps5lm-app: device %zu %s (%s): %.2f / %.2f GiB free\n", i, ggml_backend_dev_name(dev),+ ggml_backend_dev_description(dev), free / 1073741824.0, total / 1073741824.0);+ }++ std::vector<std::string> args = read_args();+ // llama.cpp's own log, written as it goes: it survives a crash, where+ // its log thread's buffer would not.+ args.insert(args.begin(), { "--log-file", "/data/PS5LM/llama.log" });+ std::vector<char *> argv;+ argv.push_back(const_cast<char *>("llama-server"));+ for (auto & a : args) {+ std::printf("ps5lm-app: arg %s\n", a.c_str());+ argv.push_back(a.data());+ }+ argv.push_back(nullptr);++ notify("PS5LM: loading the model onto the GPU, chat on port 8081 when ready");+ int rc = 1;+ try {+ rc = llama_server((int) argv.size() - 1, argv.data());+ } catch (const std::exception & e) {+ std::printf("ps5lm-app: exception: %s\n", e.what());+ } catch (...) {+ std::printf("ps5lm-app: unknown exception\n");+ }+ std::printf("ps5lm-app: llama_server returned %d\n", rc);+ std::fflush(nullptr);+ notify(rc == 0 ? "PS5LM: server stopped" : "PS5LM: server failed, see /data/PS5LM/llama.log");+ // A title must not exit on its own (exit() and _Exit end in SIGSYS); it+ // waits for the shell to close it.+ for (;;) {+ sceKernelUsleep(2000000);+ }+}diff --git a/ps5/app/ps5cc b/ps5/app/ps5ccnew file mode 100755index 0000000..308d779--- /dev/null+++ b/ps5/app/ps5cc@@ -0,0 +1,3 @@+#!/bin/sh+# C compiler for the native app build (ps5/app/toolchain.cmake).+PS5_CLANG=${PS5_CLANG_C:-clang} exec sh "$PS5_VULKAN_ROOT/tooling/prospero-clang18" "$@"diff --git a/ps5/app/ps5cxx b/ps5/app/ps5cxxnew file mode 100755index 0000000..7f3bfef--- /dev/null+++ b/ps5/app/ps5cxx@@ -0,0 +1,3 @@+#!/bin/sh+# C++ compiler for the native app build (ps5/app/toolchain.cmake).+PS5_CLANG=${PS5_CLANG_CXX:-clang++} exec sh "$PS5_VULKAN_ROOT/tooling/prospero-clang18" "$@"diff --git a/ps5/app/sce_sys/icon0.png b/ps5/app/sce_sys/icon0.pngnew file mode 100644index 0000000..9ff369bBinary files /dev/null and b/ps5/app/sce_sys/icon0.png differdiff --git a/ps5/app/sce_sys/param.json b/ps5/app/sce_sys/param.jsonnew file mode 100644index 0000000..5f06b72--- /dev/null+++ b/ps5/app/sce_sys/param.json@@ -0,0 +1,47 @@+{+ "ageLevel": {+ "default": 0+ },+ "amm": {+ "multimapVaRangeInGib": 512,+ "pagetableMemorySizeInMib": 256,+ "vaRangeInGib": 512+ },+ "applicationCategoryType": 0,+ "applicationDrmType": "free",+ "attribute": 0,+ "attribute2": 0,+ "attribute3": 0,+ "conceptId": "99581",+ "contentBadgeType": 1,+ "contentId": "UP9000-PPSA99581_00-PS5LMVULKAN00001",+ "contentVersion": "01.000.000",+ "downloadDataSize": 256,+ "gameIntent": {+ "permittedIntents": [+ {+ "intentType": "launchActivity"+ }+ ]+ },+ "kernel": {+ "cpuPageTableSize": 268435456,+ "gpuPageTableSize": 268435456+ },+ "localizedParameters": {+ "defaultLanguage": "en-US",+ "en-US": {+ "titleName": "PS5LM"+ }+ },+ "masterVersion": "01.00",+ "pubtools": {+ "creationDate": "2026-08-31 00:00:00",+ "loudnessSnd0": "-28.00",+ "toolVersion": "2.00"+ },+ "requiredSystemSoftwareVersion": "0x0000000000000000",+ "sdkVersion": "0x0000000000000000",+ "titleId": "PPSA99581",+ "versionFileUri": ""+}\ No newline at end of filediff --git a/ps5/app/sce_sys/source/background.svg b/ps5/app/sce_sys/source/background.svgnew file mode 100644index 0000000..299e9e5--- /dev/null+++ b/ps5/app/sce_sys/source/background.svg@@ -0,0 +1,175 @@+<svg xmlns="http://www.w3.org/2000/svg" width="3840" height="2160" viewBox="0 0 3840 2160">+<!-- PS5LM home screen background, generated by background.py from icon.svg. -->+<defs>+ <radialGradient id="glow" cx="50%" cy="46%" r="62%">+ <stop offset="0" stop-color="#2a2b52"/>+ <stop offset="0.55" stop-color="#15151f"/>+ <stop offset="1" stop-color="#0b0b10"/>+ </radialGradient>+ <linearGradient id="bubble" x1="0" y1="0" x2="1" y2="1">+ <stop offset="0" stop-color="#a9adff"/>+ <stop offset="1" stop-color="#6b71e6"/>+ </linearGradient>+ <linearGradient id="die" x1="0" y1="0" x2="0" y2="1">+ <stop offset="0" stop-color="#1d1e2c"/>+ <stop offset="1" stop-color="#14141d"/>+ </linearGradient>+ </defs>+<radialGradient id="bgglow" cx="0.703" cy="0.5" r="0.75">+ <stop offset="0" stop-color="#25264a"/><stop offset="0.45" stop-color="#121219"/><stop offset="1" stop-color="#0b0b10"/>+</radialGradient>+<rect width="3840" height="2160" fill="url(#bgglow)"/>+<g stroke="#8288f0" stroke-opacity="0.16" stroke-width="7" fill="none" stroke-linecap="round"><path d="M2922 690 V558 H3439 V427"/>+<path d="M2362 1374 H1858 V1895 H1353"/>+<path d="M3038 853 H3303 V431 H3568"/>+<path d="M2617 1470 V1704 H2424 V1939"/>+<path d="M2362 1183 H1636 V1265 H910"/>+<path d="M2638 1470 V1603 H2492 V1736"/>+<path d="M2564 1470 V1546 H2246 V1623"/>+<path d="M3038 1215 H3340 V1465 H3643"/>+<path d="M3038 866 H3114 V470 H3189"/>+<path d="M2362 922 H2173 V544 H1984"/>+<path d="M3038 979 H3274 V792 H3509"/>+<path d="M3038 1158 H3218 V1304 H3397"/>+<path d="M3038 1267 H3214 V1614 H3389"/>+<path d="M2649 1470 V1521 H2531 V1572"/>+<path d="M2721 690 V460 H2769 V229"/>+<path d="M3038 961 H3146 V740 H3254"/>+<path d="M2651 690 V376 H2537 V63"/>+<path d="M2506 690 V534 H2055 V377"/>+<path d="M2654 690 V621 H2546 V552"/>+<path d="M2579 690 V621 H2298 V552"/>+<path d="M2899 1470 V1600 H3363 V1730"/>+<path d="M2362 955 H1404 V930 H446"/>+<path d="M2362 1165 H2188 V1511 H2013"/>+<path d="M2821 1470 V1514 H3104 V1559"/>+<path d="M2494 1470 V1602 H2015 V1735"/>+<path d="M3038 857 H3238 V443 H3439"/>+<path d="M2678 1470 V1772 H2625 V2074"/>+<path d="M2788 690 V503 H2994 V316"/>+<path d="M2532 1470 V1698 H2141 V1926"/>+<path d="M2488 690 V596 H1995 V503"/>+<path d="M2362 921 H1730 V701 H1097"/>+<path d="M2635 690 V422 H2484 V154"/>+<path d="M2887 690 V537 H3324 V384"/>+<path d="M2575 690 V415 H2283 V140"/>+<path d="M3038 1289 H3271 V1676 H3504"/>+<path d="M2565 1470 V1534 H2250 V1599"/>+<path d="M2362 1202 H1927 V1446 H1492"/>+<path d="M3038 1303 H3417 V1716 H3796"/>+<path d="M2620 690 V608 H2432 V526"/>+<path d="M2555 1470 V1538 H2218 V1607"/>+<path d="M2362 1346 H1886 V1947 H1410"/>+<path d="M3038 1296 H3402 V1698 H3765"/>+<path d="M3038 1224 H3324 V1491 H3611"/>+<path d="M2362 893 H1826 V621 H1289"/>+<path d="M2362 1378 H1812 V2002 H1261"/>+<path d="M2847 1470 V1596 H3190 V1723"/>+<path d="M2766 1470 V1672 H2919 V1875"/>+<path d="M2634 1470 V1659 H2481 V1848"/>+<path d="M2714 1470 V1585 H2746 V1700"/>+<path d="M2362 1042 H2222 V717 H2083"/>+<path d="M2576 690 V420 H2288 V151"/>+<path d="M2633 1470 V1774 H2477 V2077"/>+<path d="M2505 690 V557 H2049 V424"/>+<path d="M2362 1316 H1694 V1898 H1026"/>+<path d="M2629 1470 V1660 H2462 V1850"/>+<path d="M2865 690 V466 H3250 V242"/>+<path d="M2362 1112 H1941 V1337 H1520"/>+<path d="M2750 690 V522 H2868 V355"/>+<path d="M2680 690 V515 H2632 V340"/>+<path d="M2919 690 V584 H3431 V478"/>+<path d="M2572 690 V605 H2273 V520"/>+<path d="M2671 690 V640 H2604 V590"/>+<path d="M3038 1151 H3198 V1284 H3358"/>+<path d="M3038 1372 H3298 V1913 H3558"/>+<path d="M2640 1470 V1550 H2499 V1630"/>+<path d="M2571 1470 V1774 H2271 V2078"/>+<path d="M2652 1470 V1648 H2539 V1827"/>+<path d="M2362 912 H1544 V692 H727"/>+<path d="M3038 1316 H3205 V1754 H3372"/>+<path d="M2362 1110 H1612 V1138 H863"/></g>+<g fill="#8288f0" fill-opacity="0.30"><circle cx="3439" cy="427" r="11"/>+<circle cx="1353" cy="1895" r="11"/>+<circle cx="3568" cy="431" r="11"/>+<circle cx="2424" cy="1939" r="11"/>+<circle cx="910" cy="1265" r="11"/>+<circle cx="2492" cy="1736" r="11"/>+<circle cx="2246" cy="1623" r="11"/>+<circle cx="3643" cy="1465" r="11"/>+<circle cx="3189" cy="470" r="11"/>+<circle cx="1984" cy="544" r="11"/>+<circle cx="3509" cy="792" r="11"/>+<circle cx="3397" cy="1304" r="11"/>+<circle cx="3389" cy="1614" r="11"/>+<circle cx="2531" cy="1572" r="11"/>+<circle cx="2769" cy="229" r="11"/>+<circle cx="3254" cy="740" r="11"/>+<circle cx="2537" cy="63" r="11"/>+<circle cx="2055" cy="377" r="11"/>+<circle cx="2546" cy="552" r="11"/>+<circle cx="2298" cy="552" r="11"/>+<circle cx="3363" cy="1730" r="11"/>+<circle cx="446" cy="930" r="11"/>+<circle cx="2013" cy="1511" r="11"/>+<circle cx="3104" cy="1559" r="11"/>+<circle cx="2015" cy="1735" r="11"/>+<circle cx="3439" cy="443" r="11"/>+<circle cx="2625" cy="2074" r="11"/>+<circle cx="2994" cy="316" r="11"/>+<circle cx="2141" cy="1926" r="11"/>+<circle cx="1995" cy="503" r="11"/>+<circle cx="1097" cy="701" r="11"/>+<circle cx="2484" cy="154" r="11"/>+<circle cx="3324" cy="384" r="11"/>+<circle cx="2283" cy="140" r="11"/>+<circle cx="3504" cy="1676" r="11"/>+<circle cx="2250" cy="1599" r="11"/>+<circle cx="1492" cy="1446" r="11"/>+<circle cx="3796" cy="1716" r="11"/>+<circle cx="2432" cy="526" r="11"/>+<circle cx="2218" cy="1607" r="11"/>+<circle cx="1410" cy="1947" r="11"/>+<circle cx="3765" cy="1698" r="11"/>+<circle cx="3611" cy="1491" r="11"/>+<circle cx="1289" cy="621" r="11"/>+<circle cx="1261" cy="2002" r="11"/>+<circle cx="3190" cy="1723" r="11"/>+<circle cx="2919" cy="1875" r="11"/>+<circle cx="2481" cy="1848" r="11"/>+<circle cx="2746" cy="1700" r="11"/>+<circle cx="2083" cy="717" r="11"/>+<circle cx="2288" cy="151" r="11"/>+<circle cx="2477" cy="2077" r="11"/>+<circle cx="2049" cy="424" r="11"/>+<circle cx="1026" cy="1898" r="11"/>+<circle cx="2462" cy="1850" r="11"/>+<circle cx="3250" cy="242" r="11"/>+<circle cx="1520" cy="1337" r="11"/>+<circle cx="2868" cy="355" r="11"/>+<circle cx="2632" cy="340" r="11"/>+<circle cx="3431" cy="478" r="11"/>+<circle cx="2273" cy="520" r="11"/>+<circle cx="2604" cy="590" r="11"/>+<circle cx="3358" cy="1284" r="11"/>+<circle cx="3558" cy="1913" r="11"/>+<circle cx="2499" cy="1630" r="11"/>+<circle cx="2271" cy="2078" r="11"/>+<circle cx="2539" cy="1827" r="11"/>+<circle cx="727" cy="692" r="11"/>+<circle cx="3372" cy="1754" r="11"/>+<circle cx="863" cy="1138" r="11"/></g>+<g transform="translate(2034 414) scale(2.6)"><!-- the die -->+ <rect x="136" y="116" width="240" height="280" rx="30" fill="url(#die)" stroke="#8288f0" stroke-opacity="0.55" stroke-width="4"/>+ <!-- the chat bubble -->+ <path d="M182 168 h148 a34 34 0 0 1 34 34 v84 a34 34 0 0 1 -34 34 h-72 l-46 40 v-40 h-30 a34 34 0 0 1 -34 -34 v-84 a34 34 0 0 1 34 -34 z"+ fill="url(#bubble)"/>+ <!-- tokens being generated -->+ <g fill="#0e0e14">+ <rect x="190" y="208" width="132" height="16" rx="8"/>+ <rect x="190" y="240" width="96" height="16" rx="8"/>+ <rect x="190" y="272" width="56" height="16" rx="8"/>+ <rect x="254" y="270" width="7" height="20" rx="2" fill="#f2f2f7"/>+ </g>+</g>+</svg>\ No newline at end of filediff --git a/ps5/app/sce_sys/source/icon.svg b/ps5/app/sce_sys/source/icon.svgnew file mode 100644index 0000000..95fc99f--- /dev/null+++ b/ps5/app/sce_sys/source/icon.svg@@ -0,0 +1,48 @@+<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">+ <!-- PS5LM launcher icon: a chat bubble on a GPU die, in the project site's+ colours (bg #0e0e14, accent #8288f0). Rendered by scripts/build-assets.sh. -->+ <defs>+ <radialGradient id="glow" cx="50%" cy="46%" r="62%">+ <stop offset="0" stop-color="#2a2b52"/>+ <stop offset="0.55" stop-color="#15151f"/>+ <stop offset="1" stop-color="#0b0b10"/>+ </radialGradient>+ <linearGradient id="bubble" x1="0" y1="0" x2="1" y2="1">+ <stop offset="0" stop-color="#a9adff"/>+ <stop offset="1" stop-color="#6b71e6"/>+ </linearGradient>+ <linearGradient id="die" x1="0" y1="0" x2="0" y2="1">+ <stop offset="0" stop-color="#1d1e2c"/>+ <stop offset="1" stop-color="#14141d"/>+ </linearGradient>+ </defs>+ <rect width="512" height="512" fill="url(#glow)"/>+ <!-- traces leaving the die -->+ <g stroke="#8288f0" stroke-opacity="0.28" stroke-width="5" fill="none" stroke-linecap="round">+ <path d="M136 176 H70 V120"/> <path d="M136 226 H40"/>+ <path d="M136 286 H60 V350"/> <path d="M136 336 H96 V420"/>+ <path d="M376 176 H446 V96"/> <path d="M376 236 H472"/>+ <path d="M376 296 H430 V372"/> <path d="M376 346 H410 V440"/>+ <path d="M196 116 V48 H150"/> <path d="M256 116 V36"/> <path d="M316 116 V60 H372"/>+ <path d="M216 396 V470"/> <path d="M296 396 V452 H350"/>+ </g>+ <g fill="#8288f0" fill-opacity="0.45">+ <circle cx="70" cy="120" r="8"/> <circle cx="40" cy="226" r="8"/> <circle cx="60" cy="350" r="8"/>+ <circle cx="96" cy="420" r="8"/> <circle cx="446" cy="96" r="8"/> <circle cx="472" cy="236" r="8"/>+ <circle cx="430" cy="372" r="8"/> <circle cx="410" cy="440" r="8"/> <circle cx="150" cy="48" r="8"/>+ <circle cx="256" cy="36" r="8"/> <circle cx="372" cy="60" r="8"/> <circle cx="216" cy="470" r="8"/>+ <circle cx="350" cy="452" r="8"/>+ </g>+ <!-- the die -->+ <rect x="136" y="116" width="240" height="280" rx="30" fill="url(#die)" stroke="#8288f0" stroke-opacity="0.55" stroke-width="4"/>+ <!-- the chat bubble -->+ <path d="M182 168 h148 a34 34 0 0 1 34 34 v84 a34 34 0 0 1 -34 34 h-72 l-46 40 v-40 h-30 a34 34 0 0 1 -34 -34 v-84 a34 34 0 0 1 34 -34 z"+ fill="url(#bubble)"/>+ <!-- tokens being generated -->+ <g fill="#0e0e14">+ <rect x="190" y="208" width="132" height="16" rx="8"/>+ <rect x="190" y="240" width="96" height="16" rx="8"/>+ <rect x="190" y="272" width="56" height="16" rx="8"/>+ <rect x="254" y="270" width="7" height="20" rx="2" fill="#f2f2f7"/>+ </g>+</svg>diff --git a/ps5/app/toolchain.cmake b/ps5/app/toolchain.cmakenew file mode 100644index 0000000..2e87515--- /dev/null+++ b/ps5/app/toolchain.cmake@@ -0,0 +1,21 @@+# CMake toolchain for PS5LM's native app: llama.cpp and ggml-vulkan as static+# libraries for a title that links RADV (scripts/build-app.sh does the link).+# The compilers are PS5_Vulkan's title wrapper (tooling/prospero-clang18) over+# the PS5_PayloadSDK fork; PS5_PAYLOAD_SDK must name that SDK.++set(CMAKE_SYSTEM_NAME FreeBSD)+set(CMAKE_SYSTEM_PROCESSOR x86_64)++set(CMAKE_C_COMPILER "${CMAKE_CURRENT_LIST_DIR}/ps5cc")+set(CMAKE_CXX_COMPILER "${CMAKE_CURRENT_LIST_DIR}/ps5cxx")+set(CMAKE_AR "$ENV{PS5_PAYLOAD_SDK}/bin/llvm-ar" CACHE FILEPATH "")+set(CMAKE_RANLIB "$ENV{PS5_PAYLOAD_SDK}/bin/llvm-ranlib" CACHE FILEPATH "")++# Only static libraries come out of this build; nothing is linked by CMake.+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)++set(CMAKE_FIND_ROOT_PATH "$ENV{PS5_PAYLOAD_SDK}/target")+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)diff --git a/scripts/build-app.sh b/scripts/build-app.shnew file mode 100755index 0000000..2d83ef4--- /dev/null+++ b/scripts/build-app.sh@@ -0,0 +1,143 @@+#!/usr/bin/env bash+# Builds PS5LM's native app: llama-server with ggml-vulkan on RADV, as a title+# folder (eboot.bin, sce_sys/param.json, sce_module/libc.prx) for+# ShadowMountPlus, in build/app-ps5/title/<TITLE_ID>. The icon and the+# backgrounds come from ps5/app/sce_sys (sources in its source/ folder).+#+# Needs PS5_Vulkan next to its forks (.deps/src: PS5_Vulkan, PS5_Mesa,+# PS5_PayloadSDK), set up with its tools/setup-native-dependencies.sh,+# tools/build-radv.sh release and `make app` (for the host tool and libc.prx).+#+# scripts/build-app.sh configure, build and package+set -euo pipefail++root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"+vk=${PS5_VULKAN_ROOT:-$root/.deps/src/PS5_Vulkan}+sdk="$vk/.deps/native/ps5-payload-sdk"+radv="$vk/.deps/native/radv-release"+archive="$radv/lib/libvulkan_radeon.ps5.a"+tool="$vk/build/host/ps5-native-tool"+llama="$root/third_party/llama.cpp"+out="$root/build/app-ps5"+headers="$root/.deps/ps5-vk-headers"+sce_sys="$root/ps5/app/sce_sys"+param="$sce_sys/param.json"++for f in "$archive" "$tool" "$vk/runtime/libc.prx" "$sdk/bin/prospero-lld"; do+ [ -e "$f" ] || { echo "build-app: missing $f" >&2; exit 2; }+done+export PS5_PAYLOAD_SDK="$sdk" PS5_VULKAN_ROOT="$vk"++# radv-link.sh takes Clang's builtins from <resource dir>/lib/linux/, where+# Debian and Arch put them; Fedora keeps them under the target triple. A clang+# that reports a resource dir with that layout covers both.+builtins=$(clang --print-file-name=libclang_rt.builtins.a)+[ -f "$builtins" ] || builtins="$(clang --print-resource-dir)/lib/linux/libclang_rt.builtins-x86_64.a"+shim="$root/.deps/clang-shim"+mkdir -p "$shim/resource/lib/linux"+ln -sf "$builtins" "$shim/resource/lib/linux/libclang_rt.builtins-x86_64.a"+printf '#!/bin/sh\n[ "$1" = --print-resource-dir ] && { echo "%s"; exit 0; }\nexec clang "$@"\n' \+ "$shim/resource" > "$shim/clang"+chmod +x "$shim/clang"++# The Vulkan and SPIR-V headers, copied out of the host's /usr/include so the+# cross build never sees the host's libc headers next to them.+if [ ! -f "$headers/include/vulkan/vulkan.hpp" ]; then+ mkdir -p "$headers/include" "$headers/cmake"+ cp -r /usr/include/vulkan /usr/include/vk_video /usr/include/spirv "$headers/include/"+ cat > "$headers/cmake/SPIRV-HeadersConfig.cmake" <<EOF+add_library(SPIRV-Headers::SPIRV-Headers INTERFACE IMPORTED)+set_target_properties(SPIRV-Headers::SPIRV-Headers PROPERTIES+ INTERFACE_INCLUDE_DIRECTORIES "$headers/include")+set(SPIRV-Headers_FOUND TRUE)+EOF+fi++# The PS5 changes to llama.cpp (patches/), as scripts/build-llama.sh applies them.+for p in "$root"/patches/*.patch; do+ git -C "$llama" apply --reverse --check "$p" 2>/dev/null || git -C "$llama" apply "$p"+done++flags="-DSUBPROCESS_HAVE_CWD=0 -I$headers/include"+# llama.cpp throws, catches and uses dynamic_cast; the PS5 target turns+# exceptions and RTTI off by default.+cxxflags="$flags -fexceptions -fcxx-exceptions -frtti"+cmake -S "$llama" -B "$out/llama" -G Ninja \+ -DCMAKE_TOOLCHAIN_FILE="$root/ps5/app/toolchain.cmake" \+ -DCMAKE_BUILD_TYPE=Release \+ -DCMAKE_C_FLAGS="$flags" -DCMAKE_CXX_FLAGS="$cxxflags" \+ -DBUILD_SHARED_LIBS=OFF -DGGML_BACKEND_DL=OFF -DGGML_NATIVE=OFF -DGGML_CPU_ALL_VARIANTS=OFF \+ -DGGML_AVX=ON -DGGML_AVX2=ON -DGGML_FMA=ON -DGGML_F16C=ON -DGGML_BMI2=ON -DGGML_AVX512=OFF \+ -DGGML_OPENMP=OFF -DGGML_CCACHE=OFF -DGGML_VULKAN=ON \+ -DVulkan_INCLUDE_DIR="$headers/include" -DVulkan_LIBRARY="$archive" \+ -DVulkan_GLSLC_EXECUTABLE="$(command -v glslc)" -DSPIRV-Headers_DIR="$headers/cmake" \+ -DMATH_LIBRARY=SceLibcInternal \+ -DLLAMA_OPENSSL=OFF -DLLAMA_BUILD_COMMON=ON -DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_EXAMPLES=OFF \+ -DLLAMA_BUILD_TOOLS=ON -DLLAMA_BUILD_SERVER=ON > "$out.configure.log" 2>&1 ||+ { tail -30 "$out.configure.log" >&2; exit 1; }+cmake --build "$out/llama" --target llama-server-impl++# The app's own objects, and the title's start code from PS5_Vulkan.+obj="$out/obj"+mkdir -p "$obj" "$out/stubs"+cxx() { "$root/ps5/app/ps5cxx" -std=c++17 -O2 -ffunction-sections -fdata-sections "$@"; }+cxx -fexceptions -fcxx-exceptions -frtti -I "$headers/include" -I "$llama/ggml/include" -c "$root/ps5/app/main.cpp" -o "$obj/main.o"+"$root/ps5/app/ps5cc" -O2 -c "$root/ps5/app/compat_app.c" -o "$obj/compat_app.o"+# In an archive, so --exclude-libs keeps them local: a stub module defines some+# of the same names, and lld would otherwise export ours to interpose them,+# which the title converter refuses.+rm -f "$obj/libps5app_compat.a"+"$sdk/bin/llvm-ar" rcs "$obj/libps5app_compat.a" "$obj/compat_app.o"+cxx -std=c++20 -fno-exceptions -fno-rtti -c "$vk/tooling/native/app_crt.cpp" -o "$obj/app_crt.o"+cxx -std=c++20 -fno-exceptions -fno-rtti -c "$vk/tooling/native/app_cpp_runtime.cpp" -o "$obj/app_cpp_runtime.o"++# AGC comes from system modules; these stubs only name the imports.+for pair in libSceAgc:agc_canary_link_stub.c libSceAgcDriver:agc_driver_canary_link_stub.c; do+ lib=${pair%%:*}+ "$root/ps5/app/ps5cc" -O2 -fPIC -c "$vk/vendor/ps5/sdk/stubs/${pair#*:}" -o "$obj/${lib}_stub.o"+ "$sdk/bin/prospero-lld" --shared -soname "$lib.prx" -o "$out/stubs/$lib.so" "$obj/${lib}_stub.o"+done++# shellcheck source=/dev/null+source "$vk/tools/radv-link.sh"+PS5_CLANG="$shim/clang" radv_link_recipe "$vk" "$sdk" "$archive" || exit 2+# The platform's getaddrinfo always fails; ps5/app/compat_app.c has a numeric one.+flags=()+for f in "${radv_link_flags[@]}"; do+ case $f in --defsym=getaddrinfo=*|--defsym=freeaddrinfo=*) ;; *) flags+=("$f") ;; esac+done+radv_link_flags=("${flags[@]}")+mapfile -t libs < <(find "$out/llama" -name '*.a' | sort)+"$sdk/bin/prospero-lld" "${radv_linker_script[@]}" --eh-frame-hdr "${radv_link_flags[@]}" \+ --version-script "$vk/tooling/native/app-symbols.map" --exclude-libs=ALL \+ -e _start -o "$out/llvm-pie.elf" \+ "$obj/app_crt.o" "$obj/app_cpp_runtime.o" "$obj/main.o" \+ --start-group "${libs[@]}" "$obj/libps5app_compat.a" --end-group \+ "$out/stubs/libSceAgc.so" "$out/stubs/libSceAgcDriver.so" \+ "${radv_link_inputs[@]}" \+ --as-needed "$sdk"/target/lib/*.so+"$tool" link --in "$out/llvm-pie.elf" --out "$out/eboot.elf" \+ --stub-dir "$sdk/target/lib" --stub "$out/stubs/libSceAgc.so" \+ --stub "$out/stubs/libSceAgcDriver.so" --module-sdk 0x02000009 \+ --companion-sdk 0x08050001 --file-name eboot.elf++title_id=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["titleId"])' "$param")+app="$out/title/$title_id"+rm -rf -- "$app"+mkdir -p "$app/sce_sys" "$app/sce_module"+"$tool" self --sign --in "$out/eboot.elf" --out "$app/eboot.bin" --magic 0x1D3D154F+cp "$param" "$app/sce_sys/param.json"+# The home screen backgrounds (3840x2160 BC7 DDS) are made from the SVG in+# ps5/app/sce_sys/source by PS5_Vulkan's asset tools, and only when it changes.+if [ ! -f "$sce_sys/pic0.dds" ] || [ "$sce_sys/source/background.svg" -nt "$sce_sys/pic0.dds" ]; then+ mkdir -p "$out/assets"+ magick "$sce_sys/source/background.svg" "$out/assets/background.png"+ (cd "$vk" && bash tools/setup-asset-dependencies.sh > /dev/null &&+ bash tools/prepare-assets.sh --icon "$sce_sys/icon0.png" --background "$out/assets/background.png" \+ --output-directory "$out/assets" > /dev/null)+ cp "$out/assets/pic0.dds" "$out/assets/pic1.dds" "$sce_sys/"+fi+cp "$sce_sys/icon0.png" "$sce_sys/pic0.dds" "$sce_sys/pic1.dds" "$app/sce_sys/"+cp "$vk/runtime/libc.prx" "$app/sce_module/libc.prx"+"$tool" self --inspect --file "$app/eboot.bin" > /dev/null+echo "build-app: $app ($(stat -c %s "$app/eboot.bin") bytes)"