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 SystemC-TLM. The purpose of this view is to show how SystemC and TLM can be used to construct a simulator for 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.

SystemC is a C++ library that makes it possible to create event-based simulations. TLM is an additional library that makes it possible to do transaction level simulation. We use SystemC and TLM to describe our computer, and to simulate its functionality.

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.

#include "systemc"
#include "tlm.h"

#include <iostream>

int sc_main(int argc, char* argv[])
    std::cout << "Hello, world" << std::endl; 
    return 0;

Figure 1. A hello world example in SystemC.

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

The code in Figure 1 starts with three include directives. The first and the second include directive include functionality for SystemC and TLM, respectively. The third include directive includes the iostream header, which contains functionality for printing text.

The code in Figure 1 contains a function named sc_main. The function starts with a statement that prints a string. The simulation is then started, by calling the function sc_core::sc_start, and after that the value zero is returned.

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 can download SystemC and TLM from Accellera. We have to accept a license agreement, and then we can download the file systemc-2.3.1a.tar.gz by using the link named Core SystemC Language and Examples.

Read more

Make it run

The program in Figure 1 can be compiled, linked, and run.

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

g++ -c -I /usr/local/systemc-2.3.1a/include hello.cpp

The above command generates the object file hello.o, which can be linked into an executable program named hello.

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