Our first instruction

A computer executes programs by following instructions. The instructions belong to an an instruction set. As mentioned in Chapter Welcome, we will use a subset of the OR1K instruction set as the instruction set for our computer.

As a first step, we will try to build a computer with only one instruction. Although somewhat restricted, this computer will be able to

  • Read instructions stored in a memory
  • Decode each instruction
  • Take action, based on the instruction read - in this case, it means that the computer will store a value in a register

We will start with deciding on a program to run our our computer. The program will be stored in a memory, and its instructions will be read, one by one, and actions will be taken.

A program

Our computer needs a program in order to run. Before creating the program, we select an instruction to use.

From the OpenRisc Architecture page we can find the OpenRISC 100 Architecture Manual.

We look in the OpenRISC 100 Architecture Manual, and we find the instruction l.movhi rD, K on page 81. This instruction takes a 16-bit value K, and shifts it left by 16-bits, and then places the resulting value in the register rD.

Read more

Addressing a memory

We need to put our instructions in memory.

Design a memory where the program can be stored. We can implement a memory in SystemC by using TLM (TBD URL). We use TLM as a means to model communication over a memory-mapped bus.

A memory implementation in SystemC/TLM is shown in Figure 11.

#ifndef MEMORY_H
#define MEMORY_H

#include "tlm.h"
#include "tlm_utils/simple_target_socket.h"

class Memory : sc_core::sc_module
{
public: 
    tlm_utils::simple_target_socket<Memory> socket; 
    Memory(sc_core::sc_module_name name, int size); 
private: 
    void read_contents_from_file(const char *file_name, int *mem, int max_values);
    void b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time& delay); 
    unsigned int size;
    int *mem;
}; 

#endif

Figure 11. A memory in SystemC/TLM.

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

Describe the code in Figure 11, and give examples of the implementation, as verb_code_figure listings.

Create a pc that reads addresses expressed in bytes. Meaning that it increments itself with four for each instruction read. We can implement a program counter SystemC by using TLM (TBD URL). We use TLM as a means to model communication over a memory-mapped bus.

Read more

Decoding the instruction

We must interpret the instruction. We must take actions, in the form of writing parts of the instruction - the K value - into a register. We make a register bank with a destination register selection, and a data input, and a write enable (feels good to have that).

Read more

Running the program

Here we wire the pieces together, and create a functioning computer, albeit with only one instruction! More to come, continue reading!

Read more