At last, it’s working!

After writing the last blog post, I was able to find a test suite for the Motorola 68000, allowing me to verify the accuracy of my 68000 emulator. After addressing a number of inaccuracies, Linux could finally finish booting! The issue that was breaking kmalloc
was the CMPA.W
, ADDA.W
, and SUBA.W
instructions not setting their condition codes properly due to quirks related to sign-extension, which presumably broke a branch or two somewhere.
Upon booting Linux, I noticed that it wasn’t recognising serial input. This turned out to be because Linux expects a level 2 interrupt to occur when there is pending data in the serial port’s FIFO. Curiously, code in 68 Katy’s Linux port suggests that it should also support a level 7 interrupt, which combines the serial input update with a 100Hz timer update, however it does not appear to work. That aside, adding the level 2 interrupt was simple enough, and, with input now working, I could try out the various executables that were bundled with Linux.
The 68 Katy’s Linux port is very barebones, only sporting vi
, expand
, ledblink
, and sash
. It also includes Colossal Cave Adventure, which is an old-school text-based adventure game. Sash is neat, because, despite being a shell, it has some BusyBox-like functionality that allows it to perform commands such as mount
, mkdir
, touch
, and ls
, which is enough to do some basic file-management. The inclusion of a fun little terminal-friendly game is nice too, even if its executable does take up a lot of space (86KiB, out of the 512KiB ROM).
Running dusty old executables is fun and all, but I had something else in mind: I wanted to see if I could port my Mega Drive emulator – clownmdemu. You see, my Mega Drive emulator and my 68 Katy emulator use the exact same 68000 emulator, meaning that if I can get the former to run on the latter, then my 68000 emulator would be emulating itself!
Being restricted to a terminal means that my emulator can’t create any graphical output, but I can at least run the emulator as a benchmark and get an idea of its performance. Compiling my Mega Drive emulator to target the 68 Katy was simple enough, since it doesn’t have any dependencies beyond the C standard library, though I did have to increase the 68 Katy’s ROM and RAM to fit the files and give the emulator the memory it needs.
So, how fast is it?

This benchmark is running the game Knuckles the Echidna in Sonic the Hedgehog 2 for a single frame, which takes 0.5 seconds. That’s right: it’s running at 2 frames per second. Note that the 68 Katy’s emulated CPU is running as fast as the host platform will let it, which in my case is around 350MHz.
I would have gotten the entire 68 Katy emulator running in itself, but the awkward timer interrupt and terminal input logic meant that it has to rely on POSIX threads, which doesn’t appear to be compatible with the 68 Katy’s ancient toolchain.
I tried to port a newer version of Linux to the 68 Katy, but it seems that only the Linux 2.0.X build of uClinux supports the vanilla Motorola 68000: the closest thing that later versions of Linux support is the Motorola 68328 – a souped-up 68000 with additional features such as built-in timers and an improved interrupt mechanism. While I was able to eliminate the dependencies on these extra features from Linux 4.4 and get it to partially boot in my emulator, it would still crash before completing its boot process.
Despite that setback, I was still successful in running Linux on my 68000 emulator, even if it was just Linux 2.0.X. I think that this is a good place to leave the project for now, so I’ve cleaned-up the codebase and made it available on GitHub. In contrast to my usual naming scheme, I’ve named this project ‘Virtual 68 Katy’ just because I think it sounds cool. You can find its Git repository here.
One thought on “Virtual 68 Katy”