Hardware: Context

Wouldn't it be nice to be able to ship a run-anywhere stack-based VM like Java?

Well, yes and no. When Inferno migrated the Plan 9 codebase to a stack-based VM, it lost most of its community, who stayed behind on the C-based version. In the modern world, intermediate VMs are more often regarded as necessary evils and shortcuts than something desirable. (See also: the steady migration of llvm away from its namesake.)

Loper OS, the archetypal hobbyist daydream project that never gets anywhere concrete, proposed a return to the high-level architectures used by Lisp machines. The last time Stanislav posted about that project, he was working on learning how to implement his vision in FPGA, without even furnishing his audience with a specification for a CPU architecture. It's hard not to see such a drastic change of plans as an excuse to avoid actually producing any code. There are several excellent papers that describe very elegant and compact Lisp machines, including one literally called SIMPLE, and the detailed manuals necessary to emulate the Symbolics machines are available. Perhaps this way lies madness?

What about real-world CPU architectures? We're currently waking up to an ARM-dominated world, and the next revolution after that will probably RISC-V... but the majority of desktop machines are still very much rooted in x86-64. There is an obvious 'out' here—maybe it's better to hedge our bets for now and just develop a userland that compiles to C until the project can invest in serious assembly generation backends.

Still, there is an inescapable desire to truly pry up the floorboards and make something self-hosting. I've spent some time working through OSDev tutorials for Intel CPUs lately, and my main takeaway was that many of the recommended resources for development are horribly organized, outdated, or—worse—closed. So increasingly I've become interested in building an emulator for an idealized, clean architecture, on the premise that it could reasonably be ported to other machines later. Staring at Previous for many hours may have contributed to this.

The CHASM Workstation Architecture

The current design for a target platform for LETHE is called CHASM. The exact meaning of the acronym changes on a regular basis, but one might parse it as a 'container for a hybrid-architecture simulated microkernel.'

The mostly-complete spec, covering the emulation-relevant portions of CPU and hardware functionality, can be found here. Enough of it is documented already to support a basic networked workstation.

Basic attributes:

CHASM is a RISC-adjacent CPU. It violates the principle of minimality by providing several domain-specific datatypes, including floating-point and string support. Note that the trailing literal paradigm (typical of most CPUs) utilizes the same number of clock cycles per word as using LUI and LW to load a 32-bit value in MIPS. It's also easier to optimize—the current emulator loads these trailers and advances the program counter immediately instead of waiting for the instruction bus window to advance, as would real hardware.

Unusual features:

As with other LETHE support projects, the CHASM emulator is being written in C and C++, targeting MinGW64. It uses SDL3 for graphics and input. A source code release is not yet available.

The CHAS Assembler

The CHASM spec includes a complete description of the assembly language used for the CHASM CPU, called CHAS (CHasm ASsembler). The source code for a rudimentary implementation of CHAS can be obtained at https://github.com/rhetorica/chas.

Background: Register machines, stack machines, and high-level architectures

There are three major paradigms for how a CPU operates:

On the whole, HLAs have failed because of the enduring popularity of C, and there has never really been a 'general-purpose' HLA, excepting perhaps workstations like the Xerox and Symbolics machines, which supported certain degrees of reprogramming CPU macrocode for domain-specific tasks. CPUs have been forced to work around the minimalist and chaotic nature of C, which considers type punning to be a feature, not a bug, compromising the architect's ability to make assumptions about the workload being processed. For a hot minute in 1982 it looked like the iAPX 432 might change this trajectory, but its reach exceeded its grasp, and the product that shipped was intolerably slow and buggy. (Intel would later repeat some of these mistakes with the i860 and Itanium architectures, which had some of the same designers involved.)