A Tiny RISC-V Emulator Runs Linux With No MMU. And Yes, It Runs DOOM!

It’s something of an article of faith, that to run Linux your computer must include a hardware memory management unit, or MMU. To an extent it’s true, in that for a Linux-based system to shine it must have that hardware, but in fact there has been support for MMU-less Linux for many years now. Prolific hacker [cnlohr] has created an emulated simple RISCV processor without an MMU, and not only does it run Linux, it also runs DOOM.

The videos below the break go into significant depth on writing and debugging an emulator not to mention the inner workings of DOOM, but fear not if it’s not your thing. Everything can be found in a GitHub repository, and there are straightforward instructions should you wish to try it yourself.

All this is entertaining stuff, but it becomes of much more interest when viewed as part of an ongoing chain of projects working on no-MMU Linux for low-end RISC-V microcontrollers. Imagine the prospect of running Linux on a CPU costing relative pennies, and you can see why that’s an interesting prospect. Even if it’s not the most unexpected way to run Linux without an MMU.

 

28 thoughts on “A Tiny RISC-V Emulator Runs Linux With No MMU. And Yes, It Runs DOOM!

    1. I wasn’t at all familiar with the RISC-V architecture when I read this article, but was extremely suspicious of the claim that there was no MMU. I found architecture diagrams for the RISC-V that clearly show an MMU, and it only took about a 30 seconds of searching on Google. 🤦

      1. Okay, the thing is most riscv32 processors only have a very basic MMU (not enough for the Linux kernel). So in order to run Linux on it you run, guess what, MMU-less Linux with uClibc (a standard library intended for systems without MMUs)!

    2. Wow! If the author here did the smallest bit of research, they would have realized that RISC-V has an MMU. I knew nothing of the architecture, but was very suspicious of the claim of no MMU. I was able to find an architecture diagram in less than 2 minutes of searching. It most definitely has an MMU.

        1. Of course there is a massive difference between tiny MCU cores that only support some Thumb subset and no priviledged modes whatsoever, not to mention the absence of MMU, and fully functional high-end cores with a full ISA support, with priviledged modes, with MMU, with instruction and data caches, with an ability to use an external DRAM.

          There is very little in common between, say ARM Cortex-R5 and ARM Cortex-A15.

    1. The only STM32’s I’m aware of it supporting (outside the completely different MP1 series) are ones with external memory interfaces. Unless there’s a really big ‘F411, I don’t think it has that. Even the couple hundred KB just isn’t enough and you **need** at least a couple MB of external SDRAM or SRAM to get a linux kernel booting (even with XIP flash).

    2. The stm32f413 can and the EVK does have 1MB of PSRAM via QSPI as well as 16MB of Flash QSPI+1.5MB of internal Flash. So you should adapt Linux to this SoC and run in MMU-less mode(ucLinux) but the speed won’t be that much even if yes, it should work.
      The point is that you can find SoCs that cost less and are more powerful than it.
      But done as an ex recise is a great way to learn. I’ve added basic support to Linux for i.MXRT1050 that has parallel sdram and sd-card and it works.
      Of course using QSPI PSRAM will slow things down and you need to use a bigger PSRAM.
      To run Doom over it at least 8MB and then shrinking down busybox, sdl and its dependencies. Take a look to Buildroot pending patches for i.MXRT so you can try to build and see the needed resources. But it takes a lot of time and effort.

  1. There’s also ReGIS for vectorial output to a terminal: https://en.wikipedia.org/wiki/ReGIS — I remember I had a VT220 connected to my Linux machine in the late 90s so that I would always know where my text console was. I knew of a VT340 stashed in one of the lab’s cupboards however (colour output, but too big for my desk). But when I read the language I was using at the time (IDL) could output ReGIS, of course I swapped my VT220 for the VT340, and to my amazement, the graphical output just worked! All I remember is that painting shapes pixel by pixel was very slow. Way slower than LOGO on my Amstrad CP6128, but maybe my Baudrate was set too low, I don’t know. Probably not fast enough for Doom, but if I ever did see a “vector doom” running on a VT340, I think I would really grin ear to ear… So *this* is how it’s done, huh? ;-)

  2. I guess that’s easier than porting Linux to 80286 and 16-Bit segmented protected-mode.
    There’s an 8028 version, but still no native, specific port for the 80286.
    The 80286 had a full-fledged MMU and supported virtual memory, it merely lacked a paging unit.
    This didn’t stop OS/2 1.3 from fully supporting virtual memory, though.

      1. The 286 has a very sophisticated MMU, but lacks paging. And the first run on i286 chips and the BIOS that IBM shipped with the AT made getting out of protected mode difficult and made using BIOS and option ROM from pmode almost impossible.

        Many years ago, my friend wrote a nice article on one of the undocumented tricks for 286 pmode (the undocumented 286 LOADALL instruction) as well as some history and detail and comparison to the better know 386+ LOADALL. http://rcollins.org/articles/loadall/

  3. always a trip to see text-mode doom again! gonna toot my own horn because i’m old enough to want to tell stories

    when the quake source was leaked, i got ahold of it and noticed an incomplete svgalib port, so i completed that and sent a patch file to John Carmack, who hired David Kirsch (Zoid) to support that port. and a few months after that, i stumbled onto aalib (ascii art). and just on a lark, i spent an evening making the thinnest shim so that a program linked against svgalib could render to aalib. so i was playing doom and quake in ascii. i called it aavga and uploaded it to sunsite in 1997. then Bob Zimbinski (bobz) cleaned it up and packaged it better and called it ttyquake. it had enough wow factor that slashdot rediscovered it at least 3 times. seemed like they were running an annual article on it for the first half of the aughts. and now, everyone has seen it and even though i think my tiny contribution isn’t being used anymore, the idea has become a part of the “but will it run doom” movement.

    really the story just goes to show how easy it was 25 years ago to be the first one to do something unique on a computer

Leave a Reply to JRDCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.