#+TITLE: Appendix A: The Walkthrough: A Human-Centered Reconstruction #+AUTHOR: Hermes & Claude #+DATE: 2026-10-07 #+PARENT: [[file:index.org][Index]] #+DESCRIPTION: A step-by-step, literate walkthrough designed to be read in print, understood conceptually, and executed by hand. #+INCLUDE: goback.org * Preface: Why a Literate Walkthrough? Most installation scripts are written for machines: defensive guards (~set -euo pipefail~), variable indirection (~${WORKSPACE:-...}~), silent flags (~-q~, ~> /dev/null~), and loops designed to save keystrokes. When printed in a book, such scripts make terrible reading. They obscure the /intent/ of each operation behind shell plumbing. This appendix is written for a *human reader sitting with a printed volume*, terminal open, following along step by step. Every command is presented in isolation, preceded by an explanation of *why* it is necessary, *what* the system does in response, and *how* to verify that it worked before moving forward. No magic loops. No nested variable expansions. Just clean, readable Unix commands. * Act I: Laying the Foundations We assume you are running a standard modern 64-bit Linux distribution (such as Debian 12 Bookworm, Ubuntu 22.04/24.04, or similar). We will keep our work organized inside a single workspace folder. ** Step 1: Create Your Workshop Create and enter the directory where your build experiments will take place: #+BEGIN_SRC bash mkdir -p ~/palm-dev cd ~/palm-dev #+END_SRC ** Step 2: Install Basic Host Tools We need tools to fetch files (~curl~), extract packages (~dpkg-deb~), and run Python helpers. #+BEGIN_SRC bash sudo apt-get update sudo apt-get install -y curl build-essential binutils-multiarch python3 #+END_SRC * Act II: Acquiring the Modern GCC 14 Cross-Compiler Palm OS runs on Motorola 68000 microprocessors (~m68k~). Debian maintains modern cross-compilers targeting ~m68k-linux-gnu~ in its "Sid" (unstable) ports archive. Because Sid packages are built against GLIBC 2.38+, and current stable distributions often ship GLIBC 2.36, installing them directly would normally fail with a dependency error. We solve this elegantly: we download the necessary ~.deb~ files and force-install them. ** Step 3: Fetch the Compiler Packages Download the six essential Debian Sid packages into a temporary directory: #+BEGIN_SRC bash mkdir -p /tmp/debs cd /tmp/debs BASE="http://ftp.us.debian.org/debian/pool/main/g/gcc-14-cross-ports" curl -sLO "$BASE/gcc-14-m68k-linux-gnu-base_14.4.0-1cross2_amd64.deb" curl -sLO "$BASE/cpp-14-m68k-linux-gnu_14.4.0-1cross2_amd64.deb" curl -sLO "$BASE/gcc-14-m68k-linux-gnu_14.4.0-1cross2_amd64.deb" curl -sLO "$BASE/g++-14-m68k-linux-gnu_14.4.0-1cross2_amd64.deb" curl -sLO "$BASE/libgcc-14-dev-m68k-cross_14.4.0-1cross2_all.deb" curl -sLO "$BASE/libstdc++-14-dev-m68k-cross_14.4.0-1cross2_all.deb" #+END_SRC ** Step 4: Unpack Packages onto Your Host We tell ~dpkg~ to install these files despite the version mismatch. The binary files will land in ~/usr/bin~ and ~/usr/libexec~: #+BEGIN_SRC bash sudo dpkg --force-depends -i /tmp/debs/*.deb #+END_SRC * Act III: Taming the GLIBC Mismatch Without Patching If you run ~/usr/bin/m68k-linux-gnu-g++-14~ right now on Debian 12, it will halt complaining that ~GLIBC_2.38~ is missing. /The Pitfall/: Do *not* run ~patchelf~ on the compiler! Patching GCC's internal binary headers corrupts symbol version tables and causes unpredictable crashes during code generation. /The Solution/: We download a copy of Sid's ~libc6~, extract it to ~/tmp/sid-libc~, and tell Linux's dynamic linker (~ld-linux-x86-64.so.2~) to load that library specifically when running GCC. ** Step 5: Extract the Sid Dynamic Linker Fetch the Sid ~libc6~ package and extract its contents into ~/tmp/sid-libc~: #+BEGIN_SRC bash cd /tmp curl -sLO "http://ftp.us.debian.org/debian/pool/main/g/glibc/libc6_2.42-17_amd64.deb" dpkg-deb -x libc6_2.42-17_amd64.deb /tmp/sid-libc/ #+END_SRC ** Step 6: Construct the Internal Sub-Tool Trampolines GCC is not a single executable; the driver calls sub-programs: - ~cc1~ (the C compiler) - ~cc1plus~ (the C++ compiler) - ~collect2~ (the link manager) When GCC runs, the ~-B~ flag instructs it where to find these sub-tools. We create a small directory tree containing one-line shell trampolines that launch each sub-tool through the Sid dynamic linker: #+BEGIN_SRC bash mkdir -p /tmp/gcc14-root/m68k-linux-gnu/14 #+END_SRC Now, create the trampoline for ~cc1~: #+BEGIN_SRC bash cat > /tmp/gcc14-root/m68k-linux-gnu/14/cc1 << 'EOF' #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \ /usr/libexec/gcc-cross/m68k-linux-gnu/14/cc1 "$@" EOF #+END_SRC Create the trampoline for ~cc1plus~ (our C++ compiler): #+BEGIN_SRC bash cat > /tmp/gcc14-root/m68k-linux-gnu/14/cc1plus << 'EOF' #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \ /usr/libexec/gcc-cross/m68k-linux-gnu/14/cc1plus "$@" EOF #+END_SRC Create the trampoline for ~collect2~: #+BEGIN_SRC bash cat > /tmp/gcc14-root/m68k-linux-gnu/14/collect2 << 'EOF' #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \ /usr/libexec/gcc-cross/m68k-linux-gnu/14/collect2 "$@" EOF #+END_SRC Mark these trampolines executable: #+BEGIN_SRC bash chmod +x /tmp/gcc14-root/m68k-linux-gnu/14/* #+END_SRC ** Step 7: Create the Main Driver Wrapper Finally, create your daily C++ compiler command: ~/tmp/g++14-palmos~. It launches the Sid ~g++-14~ driver with our library path and directs its ~-B~ search path to the sub-tools: #+BEGIN_SRC bash cat > /tmp/g++14-palmos << 'EOF' #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \ /usr/bin/m68k-linux-gnu-g++-14 "-B/tmp/gcc14-root/m68k-linux-gnu/14" "$@" EOF chmod +x /tmp/g++14-palmos #+END_SRC ** Verification Checkpoint 1 Test your new cross-compiler: #+BEGIN_SRC bash /tmp/g++14-palmos --version #+END_SRC /Expected output/: #+BEGIN_EXAMPLE m68k-linux-gnu-g++-14 (Debian 14.4.0-1cross2) 14.4.0 Copyright (C) 2024 Free Software Foundation, Inc. #+END_EXAMPLE If you see this banner, your modern C++ cross-compiler is fully operational on your machine! * Act IV: The Linker Script (~palmres.ld~) Return to your workspace directory: #+BEGIN_SRC bash cd ~/palm-dev #+END_SRC Modern GNU Binutils emits ELF binaries, but Palm OS requires Motorola 68000 COFF format with code placed in a designated 32 KB resource segment. We write a minimal 6-line linker script to enforce this: #+BEGIN_SRC bash cat > palmres.ld << 'EOF' OUTPUT_FORMAT("coff-m68k") MEMORY { coderes : ORIGIN = 0x0, LENGTH = 32770 } SECTIONS { .text : { *(.text) } > coderes /DISCARD/ : { *(.note.GN) *(.comment) *(.ident) } } EOF #+END_SRC *Notice what this script does:* 1. ~OUTPUT_FORMAT("coff-m68k")~: Enforces the vintage COFF format. 2. ~MEMORY { coderes ... }~: Establishes a 32 KB window at offset 0. 3. ~/DISCARD/~: Discards modern Linux metadata sections (~.note~, ~.comment~, ~.ident~) that would confuse the vintage Palm OS resource builder. * Act V: Writing and Compiling Modern C++ Let us write a tiny Palm OS program in C++20 demonstrating compile-time evaluation (~constexpr~) and templates. ** Step 8: Write ~test_app.cpp~ #+BEGIN_SRC cpp // test_app.cpp — Modern C++20 on DragonBall m68k using UInt16 = unsigned short; using UInt32 = unsigned long; template class MathBox { T val_; public: constexpr explicit MathBox(T v) : val_(v) {} constexpr T square() const { return val_ * val_; } }; extern "C" { UInt32 PilotMain(UInt16 cmd, void* cmdPBP, UInt16 launchFlags) { (void)cmdPBP; (void)launchFlags; // Normal interactive launch code is 0 if (cmd != 0) return 0; // Compile-time template calculation constexpr MathBox box(6); static_assert(box.square() == 36, "Square computation failed!"); return 0; } } #+END_SRC ** Step 9: Compile to Clean m68k Assembly We invoke our compiler with flags tailored for embedded freestanding code: #+BEGIN_SRC bash /tmp/g++14-palmos -S -m68000 -fno-pic -nostdlib -ffreestanding \ -std=c++20 -O2 -fno-ident -fno-exceptions -fno-rtti \ -o test_app.s test_app.cpp #+END_SRC - *-S*: Stops after emitting assembly language (no binary ELF yet). - *-m68000*: Restricts instructions to the pure 68000 instruction set. - *-fno-exceptions & -fno-rtti*: Strips heavy runtime machinery that doesn't exist on Palm OS. - *-O2*: Inlines our template and folds the calculation at compile-time. ** Step 10: Filter Modern Directives The Palm OS assembler (~m68k-palmos-as~) comes from Binutils 2.14 and does not understand modern ELF annotations like ~.type~ or ~.size~. We strip them with a single ~grep~: #+BEGIN_SRC bash grep -vE '\.ident|\.type|\.size|\.section' test_app.s > test_app.clean.s #+END_SRC ** Step 11: Assemble into COFF Object Code We run the vintage assembler: #+BEGIN_SRC bash m68k-palmos-as -m68000 -o test_app.o test_app.clean.s #+END_SRC ** Step 12: Link with Embedded Relocations We link using our ~palmres.ld~ script: #+BEGIN_SRC bash m68k-palmos-ld --embedded-relocs --no-check-sections -N \ -T palmres.ld -o test_app.elf test_app.o #+END_SRC - *--embedded-relocs*: Generates Palm OS relocation tables so the operating system can load the code anywhere in RAM. * Act VI: Packaging and The Crucial Header Fix Now we turn our linked binary into a Palm Resource Database (~.prc~). ** Step 13: Package with ~build-prc~ #+BEGIN_SRC bash /usr/bin/build-prc -t appl -c GP14 -n "Gpp14Modern" -o Gpp14Modern.prc test_app.elf #+END_SRC - *-t appl*: Application database. - *-c GP14*: 4-character Creator ID (~'GP14'~). - *-n "Gpp14Modern"*: The internal database name displayed in the Palm Launcher. ** Step 14: Patch the Database Header Flags (Pitfall #30b) If you try to install this file into an emulator right now, the emulator will reject it with: #+BEGIN_EXAMPLE "failed to install database" #+END_EXAMPLE *Why?* ~build-prc~ sets the database attribute flags at byte offset ~0x20~ to ~0x0001~ (~dmHdrAttrBackup~ only). Palm OS strictly demands bit 3: ~dmHdrAttrLaunchableData~ (~0x0008~). Without bit 3 set, the Palm OS launcher ignores the file! We use a tiny 4-line Python script to inspect and set this bit to ~0x0009~: #+BEGIN_SRC bash python3 -c " with open('Gpp14Modern.prc', 'r+b') as f: f.seek(0x20) flags = int.from_bytes(f.read(2), 'big') f.seek(0x20) f.write(bytes([0x00, flags | 0x08])) print(f'Flags successfully updated to: 0x{flags | 0x08:04x}') " #+END_SRC * Act VII: Final Inspection and Verification Now inspect your creation: #+BEGIN_SRC bash ls -lh Gpp14Modern.prc #+END_SRC /Expected result/: #+BEGIN_EXAMPLE -rw-r--r-- 1 user user 201B Oct 7 16:00 Gpp14Modern.prc #+END_EXAMPLE Check the database header strings: #+BEGIN_SRC bash strings Gpp14Modern.prc | head -n 2 #+END_SRC /Expected output/: #+BEGIN_EXAMPLE Gpp14Modern applGP14 #+END_EXAMPLE * You Have Succeeded! You have successfully compiled, filtered, assembled, linked, packaged, and patched a modern C++20 program targeting a 1996–2003 vintage Motorola 68000 Palm OS appliance. The resulting 201-byte file runs directly in CloudpilotEmu, Mu, and on original DragonBall hardware. #+LF