Open-Source z386 Brings Intel 80386 Microcode Back to Life

z386 is an open-source 80386-class FPGA CPU core that uses recovered Intel 386 microcode to run DOS and protected-mode software.

z386, an open-source FPGA CPU core that recreates a once-legendary Intel 80386-class processor (i386) using recovered original microcode, has reached the point where it can boot DOS, run protected-mode software, and play classic games such as Doom and Cannon Fodder.

For our younger readers, let me clarify that the Intel 80386, or i386, was introduced in 1985 as Intel’s first 32-bit x86 processor. It laid the foundation for modern 32-bit PC operating systems by introducing protected mode, paging, virtual memory support, and a larger address space than earlier 16-bit CPUs.

And to make it even clearer, the 80386 is mainly associated with late DOS systems, early Windows 3.x, DOS extenders, 386BSD, early Linux, and the transition from 16-bit to 32-bit computing. Now, back to the topic.

z386 is written in SystemVerilog and does not emulate instructions individually at the RTL level. Instead, it reconstructs enough of the original 386 hardware for the recovered Intel 80386 control ROM to manage execution.

The core features a 37-bit-wide, 2,560-entry microcode ROM and retains key 80386 structures, including instruction prefetch, decoding, a microcode sequencer, segmentation, paging, protection checks, TLB, ALU, shifter, and memory/cache path. FPGA-friendly optimizations, such as DSP blocks for multiplication and a compact unified L1 cache, are also used.

The current implementation is able to boot DOS 6 and DOS 7, run protected-mode programs with DOS extenders like DOS/4GW and DOS/32A, and supports some legendary titles and software such as Doom, Doom II, Cannon Fodder, FreeDOS, HIMEM, EMM386, SeaBIOS, and other compatibility and integration tests.

Doom II running on z386.
Doom II running on z386.

According to the project author, current z386 builds perform similarly to a fast cached 386-class machine at about 70 MHz or a low-end 486. On a DE10-Nano board, z386 runs at 85 MHz and achieves 16.5 FPS in Doom at maximum detail. For comparison, ao486 runs at 90 MHz and reaches 21 FPS in the same test.

Beyond performance, z386 is more compact, with about 8,000 lines of code compared to ao486’s 17,600, and uses fewer FPGA resources according to the author.

The project is based on recent reverse-engineering of the Intel 80386 microcode ROM. The microcode was recovered from high-resolution die images, then extracted and disassembled using image processing, neural networks, and manual analysis. This process produced a usable disassembly, now used as z386’s main control program.

Moreover, the project implements 386-specific protected-mode features, including segmentation, paging, selector validation, descriptor-cache state, TLB handling, page walks, accessed and dirty bit updates, and page faults.

Additionally, while the original 80386 lacked an on-chip L1 cache, z386 adds a 16 KB unified L1 cache to make the FPGA memory system resemble fast cached 386 systems of the era. The cache is 4-way set associative, uses 16-byte lines, and reduces contention between instruction prefetch and data reads.

Finally, the author notes that Windows is not yet supported and protected-mode coverage remains incomplete.

For additional details, visit the project’s GitHub page or check out this post.

Image credits: nand2mario

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

One comment

  1. WILLIAM B PECKHAM

    Perfect for DOS applications under FreeDOS for certain groups. I wonder if we will have to resurrect ancient Linux or BSD distributions to run Linux on one. I still have copied of Turbo Pascal for DOS that might make it a decent development platform.
    Exciting!

Leave a Reply

Your email address will not be published. Required fields are marked *