Welcome

Do you want to create a computer? All by yourself?

Do you want to do it step-by-step, starting with a single bit and ending with a design that can run real programs, written in C?

Do you also want to see how the design can be done using different languages, such as VHDL and Verilog?

Then this might be a book for you. The book will show you, in a step-by-step manner, how a simple computer can be created. While doing so, it will also provide an introduction to how computers work, and how their main parts can be constructed, and put together into a functioning design.

We start with a simple building block that can store one bit, and we end with a computer that can run software that is compiled and linked using gcc.

We choose to implement a subset of a real computer architecture - the OR1K architecture. In this way, we can convey the experience of building a real system, while at the same time - since we choose a suitable small subset - making the task small enough to be completed without a large implementation effort.

Using an already available architecture also allows us to use available tools, such as the OpenRISC GNU tool chain.

The book is designed as a Book with Views. This means that there are common parts, covering the general aspects of computer design, but also specific parts, treating view-specific material. We have chosen the views as languages. This gives us a possibility to treat the topic of computer design using different languages, but still keeping the material contained in one book.

The book has the following views.

  • SystemC/TLM
  • VHDL
  • Verilog

The view you are reading now is VHDL. The purpose of this view is to show how VHDL can be used to construct a computer that implements a specific architecture.

Choosing a language

We choose to describe our computer using a language. In this way, we can have a textual representation of the computer, and we can use the textual representation as input to software tools, that will help us to simulate the behavior of our computer.

VHDL is a hardware description language. We use VHDL to describe our computer, and to simulate its functionality. It is also possible to use VHDL to actually synthesize a computer, in real hardware, for example in an FPGA.

Read more

Hello world

A simple example will get us started. We use a classical "Hello, world'' example, which will do nothing meaningful except printing a text string. The code for the example is shown in Figure 1. The code for the example is from the GHDL guide. We will start using GHDL in Section Getting some tools.

use std.textio.all;

entity hello_world is
end hello_world;

architecture behavior of hello_world is
begin
  process
    variable the_line: line;
  begin
    write(the_line, String'("Hello, world"));
    writeline(output, the_line);
    wait;
  end process;
end behavior;

Figure 1. A hello world example in VHDL.

This the VHDL view - other views are Verilog - SystemC-TLM

The code in Figure 1 starts with a use clause. The purpose of this clause is to indicate which VHDL libraries that will be used. In this case we use one library, with functionality for printing text.

The code in Figure 1 contains an entity. The entity is empty, since we do not have any input ports or output ports.

Then comes the architecture part, where a process is defined.

Read more

Getting some tools

We need some tools, in the form of software. We search for software that can be obtained without cost.

We use a Linux computer with Ubuntu 16.04, and a Mac computer with OS X El Capitan.

We decide to use GHDL.

Read more

Make it run

The code in Figure 1 can be compiled and run.

Assuming that the program is stored in a file hello.vhdl, compiling can be done as

ghdl -a hello.vhdl

The above command generates the file hello.o, which can be elaborated, using the command

ghdl -e hello_world

where the string hello_world refers to the name of the entity in Figure 1.

Read more

Building a computer

We have chosen a language, to describe our computer. We have taken a first, tiny step, and we have seen how we can get hold of some tools.

Before we take our next steps towards building our computer, let's spend some time talking a bit of what we want to build.

Our goal is to create a computer. A computer reads instructions from a memory. Each instruction is represented as a sequence of bits. The values of the bits determine the type of instruction, and sometimes also arguments that the instruction shall use. The allowed instructions, for a given computer, belong to the computer's instruction set.

Most computers have instructions for loading data from a memory, and storing data to a memory. Other common instructions are instructions for doing mathematical operations, such as addition and subtraction, and instructions for making decisions. The decisions can be based on evaluations of certain conditions, such as checking if a number is zero, or if a certain bit is set in a piece of data.

Read more