#+TITLE: Chapter 1: The Palm OS Mental Model and Architecture #+AUTHOR: Hermes & Claude #+DATE: 2026-10-07 #+PARENT: [[file:index.org][Index]] #+INCLUDE: goback.org * The Machine in Your Hand To write reliable software for Palm OS, you must abandon modern operating system assumptions: there is no virtual memory, no memory protection unit (MPU/MMU), no multi-threaded preemptive scheduler, no files in a POSIX filesystem tree, and no gigabytes of swap space. Instead, a classic Palm device is a lean, battery-conserving appliance designed around instant-on operation and 160x160 pixel resistive touchscreen interaction. ** Motorola 68000 & DragonBall Architecture Classic Palm devices run on the Freescale/Motorola *DragonBall* family of microcontrollers, built around a Motorola 68EC000 core: | Device Family | Processor | Clock Speed | Architecture | RAM / Flash | Typical OS | |---------------+-----------+-------------+--------------+-------------+------------| | PalmPilot Pro | MC68328 | 16 MHz | 68EC000 | 1 MB / 512K | 2.0 | | Palm III / V | MC68328 | 16 MHz | 68EC000 | 2-8 MB | 3.0 - 3.5 | | Palm m100 | MC68VZ328 | 20 MHz | 68EC000 | 2 MB | 3.5 | | Palm IIIc | MC68VZ328 | 33 MHz | 68EC000 | 8 MB (Color)| 3.5 | | Palm m515 | MC68VZ328 | 33 MHz | 68EC000 | 16 MB (Color)| 4.1 | | Tungsten T | OMAP 1510 | 144 MHz | ARM925T | 16 MB | 5.0 (PACE) | The 68EC000 CPU features: - 32-bit internal registers (8 data registers ~d0-d7~, 8 address registers ~a0-a7~). - 24-bit external address bus (addressing up to 16 MB of physical memory). - Big-endian byte order: the high byte is stored at the lowest memory address. Word and long-word access *must be aligned to even addresses*, or an Address Error (bus exception) crashes the system! ** The Palm OS Memory Architecture: Dynamic Heap vs. Storage Heap RAM on a Palm OS device is partitioned into two distinct physical cards or heaps: 1. *Dynamic Heap* (~RAM~ in the Unix sense): - Used for the operating system state, active application stack, global variables, and dynamic allocations (~MemPtrNew~). - Extremely constrained! On Palm OS 1.0-2.0, it was only 32 KB. On Palm OS 3.0-4.x, it ranges between 96 KB and 256 KB (rarely up to 512 KB on OS 4.1 devices like the m515). - Any allocation from the Dynamic Heap is cleared on soft reset. 2. *Storage Heap* (~Filesystem / Disk~ in the Unix sense): - All databases, application files, memo records, and calendar entries live here. - Non-volatile: battery-backed static RAM preserves the Storage Heap continuously even when the screen is powered down. - You do *not* read or write files using byte-stream file descriptors (~open/read/write~). Instead, you access records directly in RAM via the *Data Manager*. ** The A5 World and Small-Data Model The 68000 architecture uses address register ~a5~ as a base pointer to locate an application's global variables and jump tables. This is known as the *A5 World*: - Offsets from ~a5~ use 16-bit signed displacements, restricting total global data (and single code sections) to ±32 KB. - When an application launches in normal mode (~sysAppLaunchCmdNormalLaunch~), the OS sets up ~a5~. - If your application is invoked by an action code (like a system alarm or search query) without a full launch, ~a5~ is *not initialized*! Accessing global variables in that state crashes immediately. - Modern C++ programming on Palm OS eliminates global variables in favor of stack allocations or explicit context pointers. ** The PRC Container File Format A Palm executable is not an ELF or PE binary. It is a Palm Resource Database file with the extension ~.prc~: - *Database Header*: Contains the 32-character application database name, flags, version, creation/modification dates, type (~'appl'~ for applications, ~'libr'~ for shared libraries), and a 4-character *Creator ID* (e.g., ~'GP14'~). - *Resource List*: A directory of resource entries. Each entry specifies a 4-byte *Resource Type* (e.g., ~'code'~, ~'data'~, ~'tFRM'~, ~'tAbt'~), a 2-byte *Resource ID*, and an offset into the file. - ~code #1~: The primary executable code resource containing ~PilotMain~. - ~data #0~: Initialized global data. - ~rloc #0~: Relocation fixups generated by the linker. ** System Call Dispatch: Trap #15 How does application code invoke the hundreds of operating system APIs without a dynamic linker like ~ld.so~? Palm OS uses the 68000's hardware software-interrupt instruction: *~trap #15~*. Each system function has a unique 16-bit trap vector number (e.g., ~sysTrapMemPtrNew = 0xA013~, ~sysTrapFrmAlert = 0xA188~, ~sysTrapEvtGetEvent = 0xA006~). To call a function: 1. Arguments are pushed onto the 68000 stack in Pascal/C calling order. 2. The trap number (or inline trap word) is dispatched via ~trap #15~. 3. The Palm OS trap dispatcher intercepts the exception, locates the API in ROM via a system jump table, executes it, and returns results in register ~d0~. #+LF * Further Reading & Reference Resources - **Books:** - Rhodes, Neil & McKeehan, Julie. /Palm OS Programming: The Developer's Guide/. O'Reilly & Associates, 2nd Edition (2001). Available on Internet Archive: https://archive.org/details/palmosprogrammin00rhod - Foster, Lonnon R. /Palm OS Programming Bible/. IDG Books Worldwide (2000). Comprehensive reference covering memory managers, DragonBall registers, and event systems. - **Official Documentation (Archived):** - PalmSource Palm OS 4.0 Developer Documentation Suite on PalmDB: https://palmdb.net - /Palm OS Programmer's Companion/ (Volume 1 & 2): https://palm.wiki/development/docs/601/PalmOSCompanion/ - /Palm OS System Reference/: http://apitechwriter.com/Samples/Palm/PalmOS_Developer_Guide.pdf - **Community Archives & Hardware Registries:** - PalmDB Preservation Repository: https://palmdb.net - RetroComputing Palm OS Architecture Discussions: https://retrocomputing.stackexchange.com/questions/tagged/palm-os - Freescale/Motorola MC68328 (DragonBall) User's Manual (Document MC68328UM/AD).