Embedded Projects
Paver
This project is based on an original 16-bit CPU, implemented in Verilog on a DE1/SoC FPGA development board made by Terasic.
The download package (see towards end of article) includes the Altera II files that allow you to write a working image to the board, if you happen to have one.
The Verilog implementation includes modules for PS/2 input and custom VGA output coupled to the virtual âPaverâ micro-controller using a dual-ported RAM. So essentially, it turns the DE1/SOC into a home-computer.
On startup, a small native IDE with an editor runs. I wrote a little, mostly working Forth interpreter experimenting with the system. There is even a native assembler and IO routines for saving/restoring from SD-card!
Developing for a new CPU of your own invention gets you to jump through some interesting âhoopsâ, because no-one is going to do it for you:
Step 1: I started out writing a simulator in C for the CPU, then added an assembler (âcyfâ) in C that generated machine code for the simulator. This meant that I could write assembly programs for the new CPU and experiment.
Step 2: Then I wrote one particularly interesting program for the CPU, which was a port of my C assembler. After a bit of fiddling around both with the C assembler and the native Assembler I had just written, both programs accepted the same source files, and produced identical machine code output. This meant that I could assemble the assembler natively, and could ditch the C assembler.
Step 3: So now I had a âhenâ (the assembly command was literally called that), that took my assembler source, assembled it and from it produced an â.eggâ object file with a new version of the assembler, which I could then run again as the new âhenâ with the simulator and so on.
The trick (and this often got me!) is to be very careful about making only gradual, compatible changes to the format that the assembler could accept and to its internal datastructures. It has to slowly evolve, in the true sense of the term!
Otherwise your egg would become âitâs own speciesâ, turn into an incompatible hen, and you potentially locked yourself out badly, in the worst case losing all your modifications right back to the first native run. So you had to keep copies of your eggs, because some bugs only manifested themselves two generations down etc.
Step 4: Since the .egg files are literally native binary images, we can simply load them into a RAM component of the DE1/SOC machine and attach them to your âCPUâ. But first, you need to describe your CPU (the behaviour of the C simulator) in a hardware description language called Verilog and program the FPGA (a Cyclone 5) with it, so that it can execute the program you put in its RAM.
So I would write my firmware (see download package) in assembler on the computer, deploy it to the board and then test it out. Eventually I wouldnât need a computer even, since I had my own assembler, monitor screen, keyboard and SD storage.
If you havenât had the experience, writing a system from zero like this takes a bit of will-power. There are so many interconnected parts that you really have to take your time with, itâs unholy.
But eventually you will get there. The layout of the character bitmap finally matches your Verilog rasterization logic, and there is this quiet, properly synched monitor signal, showing some terminal output with text, generated by a CPU you designed⊠Itâs cool somehow, like if you had climbed up some mountain for a few months or something.
GUI Simulators
Further, the package includes simulators (âPhosâ) of the DE1/SoC system with native GUIs for macOS (OpenGL, Objective-C), Windows (OpenGL, C), Android (C) and iOS (Objective-C). The mobile versions are super silly - I have no idea who would ever use them, including me. But I still learned something I guess.
This is the only time Iâve worked with Objective-C. The fact that Objective-C can handle ANSI C, and that C++ can handle ANSI C, and that both Windows and Apple had/have? excellent support for OpenGL made porting the simulators pretty easy. This was just before Swift came out and Apple deprecated OpenGL.
Downloads
The dowload package has lots of stuff in it. I havenât looked at it for years, but it should still all be reproducible on current systems.