Linux on the Sega 32X. Who needs hardware synchronization primitives anyway?
147 points
• 4 days ago
• Article
Link
Sega 32X 是这一系列复古计算项目的最新目标,旨在把 Linux kernel 带到九十年代中期的硬件上。和之前将 Linux 移植到 Atari Jaguar 的工作类似,这次的目标是通过应对遗留硅片、有限资源和非标准架构的各种复杂性,来打磨板级启动(bringup)能力。对于 32X 来说,这意味着要面对一种特殊的双处理器结构:两颗 23 MHz 的 Hitachi SH2,作为 16-bit Genesis 与 32-bit Saturn 之间的过渡设计。
要在 32X 上成功引导 Linux,必须突破严重的内存限制。附加卡上只有 256KB RAM,因此项目依赖现代基于 FPGA 的 flash carts,特别是带有 Extended SSFv2 Mapper 的型号。通过把 cartridge ROM 当作可写的 RAM 使用,扩展了总可用内存,从而能为 Linux kernel 和一个小型 initramfs 留出足够空间。在调整 SDK 示例以支持 ROM-to-RAM 映射之后,工作重心转向用自定义的 sh2eb-elf toolchain 交叉编译内核,并修复各种内部编译器错误与寄存器被破坏的问题。
在实现 Symmetric Multiprocessing (SMP) 支持时遇到了重大挑战。由于 32X 硬件本身缺乏原生同步原语和缓存一致性,要实现真正的并行处理只能靠巧妙的软件方案。开发者采用 Peterson's algorithm 来做 CPU 间的同步,并利用原始的 Genesis 68000 处理器作为仲裁器负责中断路由,这样系统才能引导两个 SH2 核心。为保证稳定性,他们通过禁用共享变量的缓存并为每个处理器分配唯一标识,规避了缓存相关的问题。
整个过程充满反复试验:为解决调度错误和 kernel panics 进行了大量调试,并对代码进行了激进优化,才把 Linux 和 Busybox 装进有限的存储空间。实现了一个基本的控制台显示驱动并利用 ELF FDPIC 支持后,该移植达到了能运行最小用户空间的可用状态。尽管最终系统存在严重的总线争用且性能有限,但能够在 32X 硬件上成功运行 Linux kernel,本身就是一项技术成就,证明只要有足够的毅力和创造性的工程设计,再受限的复古架构也能支持现代软件。
The Sega 32X serves as the latest target in a series of ambitious retro-computing projects aimed at bringing the Linux kernel to hardware from the mid-nineties. Much like the previous effort to port Linux to the Atari Jaguar, the goal here is to refine board bringup skills by navigating the complexities of legacy silicon, limited resources, and non-standard architectures. For the 32X, this meant working with a unique dual-processor setup featuring two 23 MHz Hitachi SH2s, which were intended to act as an intermediary step between the 16-bit Genesis and the 32-bit Saturn.
Successfully booting Linux on the 32X required overcoming significant memory constraints. With only 256KB of RAM available on the addon, the project relied on modern FPGA-based flash carts, specifically those featuring an Extended SSFv2 Mapper. By treating the cartridge ROM as writeable RAM, the total usable memory was expanded, allowing for a configuration that leaves enough room for both the kernel and a modest initramfs. After adjusting the SDK examples to handle ROM-to-RAM mappings, the focus shifted to cross-compiling the kernel using a custom `sh2eb-elf` toolchain and addressing various internal compiler errors and register clobbering issues.
A major challenge arose during the development of Symmetric Multiprocessing (SMP) support. Because the 32X hardware lacks native synchronization primitives and cache coherency, implementing true parallel processing required a clever software-based approach. By leveraging Peterson's algorithm to handle inter-CPU synchronization and utilizing the original Genesis 68000 processor as an arbiter to route interrupts, the system was able to boot both SH2 cores. To ensure stability, the developers bypassed cache-related issues by disabling caching for shared variables and assigning unique identifiers to each processor.
Ultimately, the process involved extensive trial and error to resolve scheduling bugs and kernel panics, as well as aggressive optimization to fit Linux and Busybox into the limited footprint. By implementing a basic console display driver and utilizing ELF FDPIC support, the port reached a functional state capable of running a minimal user space. While the resulting system experiences significant bus contention and modest performance, the ability to successfully execute the Linux kernel across the 32X hardware stands as a technical achievement that proves even the most restrictive retro architectures can support modern software if provided with enough perseverance and creative engineering.
32 comments • Comments Link
• 成功把支持 SMP 的 Linux 移植到 Sega 32X,证明了即使没有原生硬件同步原语,多核也能工作。
• 不同处理器间 BogoMIPS 值的差异,很可能是因为从属 SH2 的定时器线路配置错误——内核正是通过这些定时器来校准 BogoMIPS 。
• 相比之下,Sega Saturn 被认为是更实际的目标,因为它有更快的时钟、更宽的 32 位内存总线、现成的 RAM 扩展以及现成的硬件键盘支持。
• 虽然 Hitachi SuperH 架构和 ARM 的 THUMB 在某些设计上有相似之处(例如 16 位指令和双操作数的限制),但 SuperH 本身是独立的架构,保留了像分支延迟槽(branch delay slots)这样的 RISC 时代特性。
• 这一工作属于"在任何设备上运行 Linux"的爱好者传统,与社区力求在各种小众或非传统设备上运行 Doom 的行为类似。
• 当前的 I/O 通过将 UART 数据转发给 M68K 处理器,由其充当 SH2 的调度器来实现。尽管硬件把带宽上限限定在 4800 bps,这仍是主要的终端访问方式。
• 在 Sega CD 和 Genesis 上实现 SMP 实际上不可行,因为 sub-68K 和主 68K 并非以允许同时访问的方式共享内存,这限制了多核扩展的可能性。
• 针对硬件访问的限制(例如 SH-2 无法写入 cartridge 区域)需要创造性的权宜之计,例如利用 32X 的 SDRAM 来维持 Linux 内核的运行环境。
• 在视频输出信号中编码数据(类似 Lumacode)作为替代的 UART 数据流传输方式在技术上可行但非常消耗资源,考虑到当前串行方案的简单性,这种做法可能并无必要。
• 持续的开发工作还包括向 GCC 提交上游错误报告,以确保 SuperH 后端在当前和未来的硬件移植中保持兼容与稳定。
该项目处在复古计算热情与底层系统工程的交汇点上,反映出将现代操作系统移植到受限老旧硬件上的长期兴趣。讨论突出了这些移植工作中的固有技术难题,比如内存总线限制、架构特性,以及为 I/O 和同步设计的各种创造性权宜之计。尽管 Sega 32X 在实现 SMP 上带来了独特挑战,但普遍认为对于想推动这些经典平台性能的人来说,Saturn 更强大的硬件提供了一条更可行的路径。归根结底,这些实验更多展示的是技术创意和对平台的掌控能力,而非实用的计算解决方案。 • A successful port of SMP-ready Linux to the Sega 32X has been achieved, demonstrating that multi-core processing can function even without native hardware synchronization primitives.
• Discrepancies in BogoMIPS values between processors likely stem from misconfigured timer wiring on the secondary SH2, as these values are derived from kernel calibration against a timer.
• The Sega Saturn is considered a more practical target for such projects due to its faster clock speed, 32-bit memory bus, off-the-shelf RAM expansions, and existing hardware keyboard support.
• While the Hitachi SuperH architecture shares some design characteristics with ARM's THUMB, such as 16-bit instructions and two-operand limitations, it is a distinct architecture that includes RISC-era design quirks like branch delay slots.
• The effort is part of a broader hobbyist tradition of "running Linux on everything," akin to the community pursuit of running Doom on increasingly obscure or non-computational devices.
• Current I/O relies on forwarding UART data to the M68K processor, which acts as a dispatcher for the SH2s; though hardware limitations cap this at 4800 bps, it serves as the primary terminal access method.
• SMP on the Sega CD and Genesis is rendered practically impossible because the sub-68K and main 68K do not share memory in a way that allows simultaneous access, limiting potential for multi-core scaling.
• Technical constraints regarding hardware access, such as the SH-2's inability to write to the cartridge area, require creative workarounds like utilizing the 32X's SDRAM to maintain the Linux kernel environment.
• Encoding data within video output signals, similar to Lumacode, is a technically feasible but resource-intensive alternative to UART for data streaming, though potentially unnecessary given the simplicity of current serial implementations.
• Ongoing development includes submitting upstream bug reports to GCC to ensure the SuperH backend remains compatible and stable for this and future hardware porting efforts.
This project sits at the intersection of retro-computing enthusiasm and low-level systems engineering, reflecting a long-standing fascination with porting modern operating systems to constrained, legacy hardware. The discussion highlights the technical hurdles inherent in these ports, such as memory bus limitations, architectural quirks, and the necessity of creative workarounds for I/O and synchronization. While the Sega 32X provides a unique challenge for SMP implementation, the consensus suggests that the Saturn's more robust architecture offers a more viable path for those seeking to push these classic platforms further. Ultimately, these experiments serve more as impressive displays of technical ingenuity and platform mastery than as practical computing solutions.