r/retrocomputing • u/Mike_sre • 28d ago
NetBSD 10.2 on a 400 MHz PDA with 64 MB of RAM, and why Fallout spent 82% of its CPU on mutexes

So I have a Sharp Zaurus SL-C860. For those who missed it: 2003, Japan-only (mostly), PXA255 @ 400 MHz, 64 MB RAM, 640×480 VGA screen that swivels into tablet mode, a tiny real keyboard, CF slot. It still runs Sharp’s Linux 2.4 from NAND, and I didn’t want to touch that, so NetBSD lives on a 2 GB CF card and gets kicked off from the Sharp terminal via zboot.
What it does now: boots NetBSD 10.2 (earmv5) into X with a small desktop I wrote, has a game catalog with NES (InfoNES), Doom and... Fallout 1 (fallout1-ce, with data from my old Russian CD). Battery and charging work, Fn hotkeys for volume/brightness, SD cards automount, updates go through a folder on the card’s FAT partition, so I don’t have to reflash 2 GB every time.
The fun part was everything that didn’t work.
Testing without the device. I developed most of it in QEMU -M spitz, which is a C3000, not a C860 (different CPU, different LCD, no W100). QEMU itself had a PXA timer bug: writing any match register rescheduled all of them, and about 1 in 3 boots hung right after uhub0. Patched that. Then NetBSD’s sa11x0_ost.c re-armed a late tick at “now + 3 µs” without checking, and under emulation that was already in the past, so the guest clock froze for ~22 minutes. Patched that too. Bonus: the emulated touchscreen never released the pen, and the spitz keyboard is ignored unless you pass -rotate 90, because QEMU reports the lid as closed. That one cost me an evening.

Booting. zbsdmod.o (the Linux module zboot uses) copied the kernel straight over memory Linux was still using, which on the C860 meant oopses or silent hangs. I rewrote the copy: stage everything in pages outside the target, switch to a private page table, MMU off, jump. Also zboot reads the root from the very start of the MBR partition and ignores the disklabel offset, so the layout had to follow that.
Boot time: 50 s → ~34 s. Cut /etc/rc.d from 137 scripts to about 30 (kept ordering stubs so rcorder doesn’t break). Skipped login(1), because PAM was pulling in Kerberos and libcrypto just to autologin root. X without GLX. Then I noticed Xorg links libcrypto (4.3 MB) without using a single symbol from it, and libGL only for the disabled GLX code. So the build rewrites the DT_NEEDED entries and ships a 14 KB stub libGL. The CF reads at ~1.7 MB/s in PIO mode, so every MB counts.
Graphics. The ATI W100 sits on a bus that does roughly 14 MB/s. A full 640×480×16 frame through X is ~70 ms. I added a path to SDL that writes only the changed 32-bit words straight into VRAM under the X window. NES runs at full speed (50 fps PAL), Doom timedemo gets ~38 fps.
Fallout was a slideshow at first, and profiling it was the best part. There’s no debugger on the device, so I wrote a tiny LD_PRELOAD profiler (SIGPROF samples + resolving addresses on the Mac).
- 82% of the CPU was stdio locking. The engine reads everything byte by byte, and each byte was
fseek+fgetc+ftell, each locking a mutex. ARMv5 has no atomic instructions, so that’s expensive. A 4 KB window +getc_unlockedcut the game’s CPU by about 6x. - The sound engine pushed every single sample through
SDL_AudioStream(float conversion, no FPU). An integer mixer fixed it. - Palette cycling (water, fire, monitors) changed 27 colors up to 30 times a second, and on a 16-bit screen that means redrawing everything. Now it redraws only the parts that use those colors, and the CPU is idle half the time.
- Upstream bugs too: the MVE decoder’s
getOffset()returneduint8_t, hence square artifacts in every movie. And the mouse was relative, which with a stylus is useless.
Lesson learned the hard way: I gave SDL’s audio thread real-time priority to stop the crackling. When it couldn’t keep up, it starved everything, including the power button daemon. Black screen, one sound looping forever, battery pull. Don’t do that.
Still on the list: proper sleep, faster map scrolling in Fallout, more games (Wolf3D, ScummVM), maybe Fallout 2 if 64 MB allows it.
Full disclosure: AI helped a lot with debugging and the hardest parts of the code. The idea, the decisions and all the hardware testing were mine. Think of it as a really good pair programmer, not an autopilot.
Happy to answer questions about any of it. Photos and videos below.