Appendix A: The Walkthrough: A Human-Centered Reconstruction
This is an LLM ass-isted document, as are all in the ass/ subdirectory.
Of these, here in the dump/ subdirectory I keep the sloppy & doubtful ones.
I keep these as learning materials for myself, yet to be went thru.
1. 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.
2. 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.
2.1. Step 1: Create Your Workshop
Create and enter the directory where your build experiments will take place:
mkdir -p ~/palm-dev
cd ~/palm-dev
2.2. Step 2: Install Basic Host Tools
We need tools to fetch files (curl), extract packages (dpkg-deb), and run Python helpers.
sudo apt-get update sudo apt-get install -y curl build-essential binutils-multiarch python3
3. 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.
3.1. Step 3: Fetch the Compiler Packages
Download the six essential Debian Sid packages into a temporary directory:
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"
3.2. 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:
sudo dpkg --force-depends -i /tmp/debs/*.deb
4. 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.
4.1. Step 5: Extract the Sid Dynamic Linker
Fetch the Sid libc6 package and extract its contents into /tmp/sid-libc:
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/
4.2. 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:
mkdir -p /tmp/gcc14-root/m68k-linux-gnu/14
Now, create the trampoline for cc1:
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
Create the trampoline for cc1plus (our C++ compiler):
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
Create the trampoline for collect2:
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
Mark these trampolines executable:
chmod +x /tmp/gcc14-root/m68k-linux-gnu/14/*
4.3. 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:
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
4.4. Verification Checkpoint 1
Test your new cross-compiler:
/tmp/g++14-palmos --version
Expected output:
m68k-linux-gnu-g++-14 (Debian 14.4.0-1cross2) 14.4.0 Copyright (C) 2024 Free Software Foundation, Inc.
If you see this banner, your modern C++ cross-compiler is fully operational on your machine!
5. Act IV: The Linker Script (palmres.ld)
Return to your workspace directory:
cd ~/palm-dev
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:
cat > palmres.ld << 'EOF' OUTPUT_FORMAT("coff-m68k") MEMORY { coderes : ORIGIN = 0x0, LENGTH = 32770 } SECTIONS { .text : { *(.text) } > coderes /DISCARD/ : { *(.note.GN) *(.comment) *(.ident) } } EOF
Notice what this script does:
OUTPUT_FORMAT("coff-m68k"): Enforces the vintage COFF format.MEMORY { coderes ... }: Establishes a 32 KB window at offset 0./DISCARD/: Discards modern Linux metadata sections (.note,.comment,.ident) that would confuse the vintage Palm OS resource builder.
6. 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.
6.1. Step 8: Write test_app.cpp
// test_app.cpp — Modern C++20 on DragonBall m68k using UInt16 = unsigned short; using UInt32 = unsigned long; template <typename T> 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<int> box(6); static_assert(box.square() == 36, "Square computation failed!"); return 0; } }
6.2. Step 9: Compile to Clean m68k Assembly
We invoke our compiler with flags tailored for embedded freestanding code:
/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
- -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.
6.3. 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:
grep -vE '\.ident|\.type|\.size|\.section' test_app.s > test_app.clean.s
6.4. Step 11: Assemble into COFF Object Code
We run the vintage assembler:
m68k-palmos-as -m68000 -o test_app.o test_app.clean.s
6.5. Step 12: Link with Embedded Relocations
We link using our palmres.ld script:
m68k-palmos-ld --embedded-relocs --no-check-sections -N \
-T palmres.ld -o test_app.elf test_app.o
- –embedded-relocs: Generates Palm OS relocation tables so the operating system can load the code anywhere in RAM.
7. Act VI: Packaging and The Crucial Header Fix
Now we turn our linked binary into a Palm Resource Database (.prc).
7.1. Step 13: Package with build-prc
/usr/bin/build-prc -t appl -c GP14 -n "Gpp14Modern" -o Gpp14Modern.prc test_app.elf
- -t appl: Application database.
- -c GP14: 4-character Creator ID (
'GP14'). - -n "Gpp14Modern": The internal database name displayed in the Palm Launcher.
7.2. 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:
"failed to install database"
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:
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}')
"
8. Act VII: Final Inspection and Verification
Now inspect your creation:
ls -lh Gpp14Modern.prc
Expected result:
-rw-r--r-- 1 user user 201B Oct 7 16:00 Gpp14Modern.prc
Check the database header strings:
strings Gpp14Modern.prc | head -n 2
Expected output:
Gpp14Modern applGP14
9. 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.