Chapter 11: The Palm OS Debugging Field Guide: From Bus Errors to Hard Resets
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. The Anatomy of a Palm OS Crash
Because classic Palm devices operate without a memory management unit (MMU) or virtual memory isolation, an application crash is not simply a logged exception—it frequently brings down the entire operating system, freezing the display or forcing an immediate reboot.
Understanding how the hardware and kernel react to errors is essential to becoming an effective Palm developer.
2. The Hierarchy of Resets
When a Palm OS device encounters a critical fault, it enters one of three reset states:
┌──────────────────────────────┐
│ Application Bug │
└──────────────┬───────────────┘
│
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
[ Soft Reset ] [ Warm Reset ] [ Hard Reset ]
Pin into rear hole. Hold 'Scroll Up' key Hold 'Power' button
Clears Dynamic Heap. while pressing reset. while pressing reset.
Reboots OS. Skips system extensions Clears Storage Heap!
Preserves Databases. and boot hacks. Wipes ALL user data!
2.1. 1. Soft Reset
- Trigger: Pushing a straightened paperclip into the small reset hole on the rear case.
- What Happens: The hardware asserts CPU reset. The Dynamic Heap (system RAM, stack, globals) is completely cleared and reinitialized.
- Data Safety: Safe. All databases, memos, contacts, and installed PRCs in the Storage Heap are preserved.
2.2. 2. Warm Reset (Safe Mode)
- Trigger: Hold the hardware Scroll-Up button down continuously while pressing and releasing the reset button with a paperclip.
- What Happens: Palm OS boots without launching system extensions, HackMaster/DA hacks, notification handlers, or startup apps.
- When to Use: If an app crashes inside
sysAppLaunchCmdSystemResetor registers a broken notification hook that prevents the device from ever reaching the Application Launcher during a soft reset.
2.3. 3. Hard Reset (Factory Wipe)
- Trigger: Hold down the green Power button while pressing the rear reset button. When the Palm logo appears, release the reset button, then release the Power button when the screen displays:
"Erase all data?". Press Scroll-Up to confirm. - What Happens: The system re-formats both the Dynamic Heap AND the Storage Heap.
- Data Safety: TOTAL WIPE. All databases and third-party software are permanently deleted, restoring the handheld to factory state.
- Developer Safeguard: Always back up your test database before testing low-level code!
3. Common Fatal Exceptions and Their Root Causes
| Error Name | CPU Exception Vector | Typical Root Cause in C++ Code |
|---|---|---|
| Bus Error | Vector 2 | Attempting to write directly to the Storage Heap without DmWrite, or dereferencing a pointer outside 24-bit physical RAM ($00000000 - $00FFFFFF). |
| Address Error | Vector 3 | Reading or writing a 16-bit word or 32-bit long-word from an odd (unaligned) memory address! The 68000 hardware strictly forbids unaligned multi-byte bus cycles. |
| Illegal Instruction | Vector 4 | Jumping to an uninitialized function pointer, executing garbage data, or calling an unsupported 68020/68030 instruction on a 68EC000 DragonBall CPU. |
| Zero Divide | Vector 5 | Integer division by zero (x / 0 or x % 0). |
| Line 1111 (A-Trap) Error | Vector 10 ($Axxx) | Dispatched an invalid, corrupted, or unsupported system trap number via trap #15. |
| Memory Leak / Out of Memory | Kernel Alert | Exhausted the 96–256 KB Dynamic Heap by failing to call MemPtrFree or MemHandleFree. |
| UI Form Stack Overflow | Kernel Alert | Calling FrmGotoForm recursively without returning to the event loop, overflowing the form window stack. |
4. The Address Error Trap: Odd-Address Alignment
This is the most common bug that bites developers transitioning from x86 or ARM:
// DANGEROUS CRASH TRAP on 68000 DragonBall! char buffer[10]; // buffer[1] is an ODD address! UInt32* badPtr = reinterpret_cast<UInt32*>(&buffer[1]); *badPtr = 0x12345678; // IMMEDIATE HARDWARE ADDRESS ERROR (BUS CRASH)!
The Fix: Ensure all structs are aligned or use packed byte access routines:
// Safe big-endian word serializer void WriteUInt16BigEndian(char* dest, UInt16 val) { dest[0] = static_cast<char>((val >> 8) & 0xFF); dest[1] = static_cast<char>(val & 0xFF); }
5. Debugging Strategies
ErrFatalDisplayFileLineMsg: Palm OS provides an assertion API. In debug builds, verify assumptions:
#define PALM_ASSERT(cond) \ if (!(cond)) ErrDisplayFileLineMsg(__FILE__, __LINE__, #cond)
When triggered, Palm OS freezes execution and pops up a system alert with the exact file, line number, and expression!
- POSE & CloudpilotEmu Gremlins: The Palm OS Emulator (POSE) and modern CloudpilotEmu feature Gremlins: automated stress-testing monkeys that generate thousands of random pen taps, Graffiti strokes, and hardware button presses per minute to detect memory corruption and event leaks.
6. Further Reading & Reference Resources
- Debugging & Error Handling Guides:
- PalmSource Palm OS Companion: Error Handling and Debugging: https://palm.wiki/development/docs/601/PalmOSCompanion/ErrorHandling_Chapter.html
- Dave Mark & Neil Rhodes: Palm OS Programming: The Developer's Guide (Appendix A: Palm OS Error Codes).
- Motorola 68000 Hardware Exceptions:
- Motorola 68000 Exception Processing (Vectors 2-15): http://www.easy68k.com/paul/exceptions.htm
- Bus Error vs. Address Error Architecture Notes: https://retrocomputing.stackexchange.com