HN
Today

Linux on the Sega 32X. Who needs hardware synchronization primitives anyway?

A dedicated embedded engineer details their triumphant quest to port Linux to the Sega 32X, navigating severe hardware limitations, including minimal RAM and a complete absence of synchronization primitives. The write-up meticulously breaks down the intricate low-level challenges, from cross-compilation quirks to implementing SMP with Peterson's algorithm, all to get a modern OS running on a vintage gaming add-on. This captivating story appeals directly to Hacker News's appreciation for deep technical dives, retro computing, and the sheer audacity of impossible engineering feats.

20
Score
3
Comments
#7
Highest Rank
5h
on Front Page
First Seen
Jul 13, 7:00 PM
Last Seen
Jul 13, 11:00 PM
Rank Over Time
77877

The Lowdown

The author, fresh off porting Linux to the Atari Jaguar, embarks on a new, even more challenging endeavor: bringing Linux to the Sega 32X. This project is framed as an exercise in improving board bringup skills, a vital aspect of embedded systems engineering, and a continuation of a lifelong passion for pushing hardware limits.

  • Motivation & Background: The author's journey began at 12, porting Android to an unsupported MediaTek phone, instilling a deep interest in low-level system hacking and board bringup. This 32X project serves as a practical, fun way to hone those skills.
  • Sega 32X Hardware Overview: Released in 1994, the 32X was an add-on for the Sega Genesis, featuring two Hitachi SuperH SH2 CPUs at 23 MHz and 256KB of video RAM, significantly more powerful than the Genesis but with only 64KB system RAM. Its complex "Tower of Power" setup with multiple power bricks and cables highlights its clunky design.
  • Memory Constraint Solution: The 32X's limited RAM (64KB + 256KB Video RAM) was a major hurdle for Linux. The author leveraged an Extended SSFv2 Mapper feature on a Krikkz flash cart, which allows treating portions of the cart's ROM as 4MB of writeable RAM, creating enough space for Linux and an initramfs.
  • Cross-Compilation and Boot Issues:
    • Creating a sh2eb-elf cross-compiler led to a GCC internal compiler error (ICE) in kernel/nstree.c, which required a workaround.
    • Runtime issues included incorrect register clobbering in ashlsi3, ashrsi3, and lshrsi3 functions, and the shrd instruction being unsupported by the SH2 CPUs, requiring specific patches.
    • An earlycon driver was developed for UART output from the 32X via the Genesis.
    • A driver for the SH2's Free Running Timer (FRT) was implemented for clock calibration.
    • ELF FDPIC support with musl-cross-make simplified rootfs creation.
  • Symmetric Multi-Processing (SMP) Without Primitives: The 32X's SH2s lack hardware synchronization primitives and cache coherency, posing a significant challenge for dual-core Linux.
    • The author implemented Peterson's algorithm entirely in software to provide necessary primitives like cmpxchg, albeit with abysmal performance due to bus contention.
    • The Genesis's 68000 CPU was repurposed as a bus arbiter and interrupt router to deliver Inter-Processor Interrupts (IPIs) between the SH2s.
    • Non-cached memory mappings were used for synchronization variables to bypass cache coherency issues.
    • The SH2's DVSR register was ingeniously used to uniquely identify each CPU.
  • Final Result: Despite constant fine-tuning and overcoming persistent Out-Of-Memory (OOM) issues by slimming down Linux and Busybox, the project successfully boots Linux on the Sega 32X, displaying output on a console screen.

This extraordinary technical feat demonstrates the author's profound understanding of low-level hardware, software, and the enduring passion for retro computing challenges. It serves as a testament to what can be achieved with persistence, ingenuity, and a willingness to delve into the obscure corners of vintage system architectures.