OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Nov 17, 2017 6:46 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: 6502-like FPGA Computer
PostPosted: Fri Oct 10, 2014 1:59 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 18, 2009 5:47 pm
Posts: 190
Location: Alexandria, Egypt
Hello friends!

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) :D
  • 6502 is pretty interesting!
  • I could use my 6502 implementation later to make a NES clone, for example.

The design of the microarchitecture is so simple:

Image

No pipelining! No cache! :D 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:

Image

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:

Image

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 :D 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.

Image

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! :mrgreen: 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:

Image

Suggestions/questions are more than welcome :)

Project website, explains the whole story in more details.


Top
 Profile  
 
 Post subject: Re: 6502-like FPGA Computer
PostPosted: Fri Oct 10, 2014 3:08 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 808
Nice!

Btw, you could probably also simulate the display in software similarly to how it's done in the Maximite, where a serial port is used to output bits from the RAM to the R/G/B output pin (using DMA).


Top
 Profile  
 
 Post subject: Re: 6502-like FPGA Computer
PostPosted: Fri Oct 10, 2014 3:39 am 
Offline
Member
Member
User avatar

Joined: Mon Mar 05, 2012 11:23 am
Posts: 554
Location: Germany
Wow man, this is really amazing work. You have my respect!

_________________
-maxdev
Ghost OS / https://github.com/maxdev1/ghost


Top
 Profile  
 
 Post subject: Re: 6502-like FPGA Computer
PostPosted: Fri Oct 10, 2014 4:26 am 
I'm feeling unhappy because I have no time to do something like this.

Great work! But I hope that next step will be more practical, like smart home controller or robot's AI :)


Top
  
 
 Post subject: Re: 6502-like FPGA Computer
PostPosted: Fri Oct 10, 2014 5:29 am 
Offline
Member
Member
User avatar

Joined: Wed Jul 23, 2014 8:00 am
Posts: 96
Location: The Netherlands
Dude! This stuff is amazing! Seriously!

I've always wanted to build my own computer from scratch from since I was a kid. I'm jealous.

_________________
My post is up there, not down here.


Top
 Profile  
 
 Post subject: Re: 6502-like FPGA Computer
PostPosted: Fri Oct 10, 2014 7:49 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 18, 2009 5:47 pm
Posts: 190
Location: Alexandria, Egypt
alexfru wrote:
Nice!

Btw, you could probably also simulate the display in software similarly to how it's done in the Maximite, where a serial port is used to output bits from the RAM to the R/G/B output pin (using DMA).

Really Interesting! Thank you alexfru :)

max wrote:
Wow man, this is really amazing work. You have my respect!

Hi max! Thank you very much :)

embryo wrote:
I'm feeling unhappy because I have no time to do something like this.

Great work! But I hope that next step will be more practical, like smart home controller or robot's AI :)

Thank you embryo :) Home automation seems very interesting and useful :twisted:

SoLDMG wrote:
Dude! This stuff is amazing! Seriously!

I've always wanted to build my own computer from scratch from since I was a kid. I'm jealous.

LOL Thanks a lot SoLDMG :D


Top
 Profile  
 
 Post subject: Re: 6502-like FPGA Computer
PostPosted: Fri Oct 10, 2014 2:58 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 26, 2007 1:53 am
Posts: 390
Really awesome work!

_________________
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/


Top
 Profile  
 
 Post subject: Re: 6502-like FPGA Computer
PostPosted: Wed Aug 24, 2016 7:12 am 
Offline
User avatar

Joined: Wed Aug 24, 2016 6:48 am
Posts: 1
You have my respect!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group