Here is an interesting project that I have finished this summer. I would like to share it with you so I can hear your opinions and suggestions The project is FREE. Source code and all resources can be downloaded through this link.
The mission of the project is to create a functional FPGA computer system consisting of a 6502-like processor, a display controller, a PS/2 controller for keyboard, a ROM to store the firmware, and a RAM. The computer was written in VHDL and installed on a Nexys-2 FPGA board.
NOTE: Click on any image to see it in full size.
1- The processor:
The processor is actually a 6502 clone, but with a totally new microarchitecture. The reasons why I used an ISA that already exists (and didn't design my own ISA) are:
- I already designed a customized ISA before, so it is time to study the ISAs of others (more specifically, the ISAs of the golden era of computing)
- 6502 is pretty interesting!
- I could use my 6502 implementation later to make a NES clone, for example.
No pipelining! No cache! I didn't study the academical comp. arch. course till now so maybe that's the reason why my designs are always so primitive xD However, it is planned to implement my own pipeline and cache system when I have enough time
ALU has 8 operations (ADD, SUB, SHL, SHR, BIT, AND, ORA, and EOR); These ops are actually all the required operations to implement 6502 ISA. The control unit here is microprogrammed. I wrote the micro-program using my preferred text editor, wrote a micro-assembler to compile the microcode into binary, and used the micro-assembler along with GNU M4 to generate the microprogram ROM. The microprogram ROM is then converted into VHDL code as a block ram array. The combination of the VHDL logic + the microprogram ROM is an FSM that typically implements the 6502 instruction set.
2- Display controller:
Here I decided to replicate the design of the IBM VGA adaptor on a very small scale so that I could learn how the IBM VGA itself worked. I finally came up with this design:
After a lot of debugging on the real FGPA, it worked and the CRT screen showed something! I first implemented the CRT controller module, tested it until it worked, then the RAM blocks, then tests, then another module and so on. I am also grateful to this greate article on the wiki!
3- PS/2 controller:
This is a simple finite state machine that fetches signals on the PS/2 bus. The controller is connected to the NMI input of the CPU.
4- Memory controller:
This controller works as an interface between system bus and Nexys-2 on-board ROM and RAM chips. Whenever a CPU read/write cycle takes place, the controller generates signals that control the on-board ROM/RAM. The controller supports read/write operations from/to RAM, and read operation from ROM (no ROM programming).
5- The big picture:
Here is the design of the whole computer that shows how components interface each other:
Looking at the decoder, we can deduce that RAM appears at (0x0000-0x3FFF) memory region, the keyboard controller appears at (0x4000-0x5FFF), VGA at (0x6000-0x7FFF), and ROM at (0x8000-0xFFFF).
6- Software:
It was pretty interesting to design some hardware and then write some software to run on it To save time, I wrote the OS in C (and some assembly). I used cc65 and modified its libraries to support my architecture. The operating system basically initializes the system, then executes a simple shell that supports some simple commands. When an NMI signal arrives, the keyboard driver takes control, reads the scancode register of the keyboard controller hardware module, then converts it into either ASCII character or some action.
7- Emulator:
To test the operating system before uploading to the FPGA chip, I wrote a simple emulator in C. The real machine and the emulator use the same microcode binaries, so I could use the emulator to debug both the microcode and the OS.
8- Compiling and Uploading:
In order to synthesize the VHDL code and implement the design, one needs to have Xilinx ISE installed on a computer machine. I wrote a Makefile to automate the process, so I didn't have to use the messy GUI of ISE. Text editors win! cc65 also needs to be installed on the system to compile the OS. GCC is necessary to compile the emulator, the microassembler, and utilities. SDL is required by the emulator. GNU M4 is required by the microassembler. I wrote a C program called "upload" which was used to upload the firmware onto the on-board ROM. So, Digilent Adept must be installed so the program can interface the on-board ROM. Digilent Adept is also necessary to upload the bit file (generated by Xilinix tools) onto the FPGA chip and/or the flash ROM.
9- The final result:
Suggestions/questions are more than welcome
Project website, explains the whole story in more details.