Beruflich Dokumente
Kultur Dokumente
Vittorio Giovara
149374
16/06/2008 http://gle-mips.googlecode.com
Contents
1 Introduction 3
1.1 Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Expansions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Architectural Behaviour 5
2.1 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.1 Control Unit . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.2 Instruction Fetch . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.3 Instruction Decode . . . . . . . . . . . . . . . . . . . . . . 6
2.2.4 Execution Stage . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.5 Memory Stage . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.6 Write-Back . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Modular View 7
3.1 Control Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1.1 Input and Outputs . . . . . . . . . . . . . . . . . . . . . . 7
3.1.2 Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.1.3 Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Instruction Fetch . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.1 Input and Outputs . . . . . . . . . . . . . . . . . . . . . . 8
3.2.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.3 Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Instruction Decode . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3.1 Input and Outputs . . . . . . . . . . . . . . . . . . . . . . 9
3.3.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3.3 Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 Execution Stage . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.4.1 Input and Outputs . . . . . . . . . . . . . . . . . . . . . . 10
3.4.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.4.3 Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.5 Arithmetic Logic Unit . . . . . . . . . . . . . . . . . . . . . . . . 11
3.5.1 Input and Outputs . . . . . . . . . . . . . . . . . . . . . . 11
3.5.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.5.3 Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.6 Memory Stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.6.1 Input and Outputs . . . . . . . . . . . . . . . . . . . . . . 12
1
3.6.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.6.3 Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.7 Write-Back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.7.1 Input and Outputs . . . . . . . . . . . . . . . . . . . . . . 13
3.7.2 Components . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.7.3 Behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2
Chapter 1
Introduction
The aim of this report is to provide complete and detailed documentation about
the design and implementation of a MIPS-like processor in VHDL language.
1.1 Specifications
The custom processor must produce a result in 5 clock cycles, using a non
pipelined architecture. A complete instruction set has been built, with working
• Arithmetic operations
• Logical operations
• Shift operations
• Memory operations
• Branch operations
In order to load the encoded instructions, a special ROM file is used and is
accessed using the Program Counter as index.
1.2 Expansions
In addition to the requested functionality, several optional features have been
included:
Division and Modulo: working code for division or modulo operations;
Greater/Less than or Equal: complete evaluation case module;
Rotate: arithmetical or logical, right or left rotation module;
MOV instruction: for rapidly storing values in the register file;
Inverse logical fuctions: for NAND, NOR and XNOR computation;
RAM file: a functional volatile memory with read and write support;
64 bit support: integer and memory size expansion.
3
1.2.1 Notes
The RAM file and the 64 bits support have only limited implementation due to
VHDL intrinsic boundaries.
Synthesis for a complete RAM module take excessive computational effort
and for this reason its size has been limited to 26 words; however this parameter
can be increased, since all the modules are built using generics.
The 64 bits support is available only at synthesis time, selecting the correct
generics flags; the main advantage for using this extension is to be able to
manipulate and compute operations with 32 bits integer numbers (instead of
16) and have the result on 64 bits. However enabling this feature will cause
more warnings during synthesis as the base architecture was thought in 32 bits;
furthermore the ROM file can be only accessed in 32 bits fashion, because the
available integer conversion functions only support 32 bits numbers.
Warning: Xilinx behaves weirdly when simulatining a module with two dif-
ferent configurations; for this reason the configuration sections have been com-
mented out and in order to test the 64 bits extension using the provided ROM
file, it is necessary to manually change the architecture used by ROM. This bug
is not present in other simulation/synthesis tool like Modelsim or Synopsis.
4
Chapter 2
Architectural Behaviour
2.1 Structure
The processor is organized in 5 separated blocks, corresponding to the five RISC
stages; each stage corresponds to a single module written in VHDL; each module
includes all the smaller devices needed for correct functionality
• Instruction Fetch
• Instruction Decode
• Execution Stage
• Memory Stage
• Write-Back
The control logic is implemented by a Control Unit that enables only one
stage at each clock cycle, activating control signals according to the istruction
in execution. Even though the last stage doesn’t actually need a clock cycle, it
has been preferred to force an additional clock period in order to fully adhere
to the project speficiations.
2.2 Modules
2.2.1 Control Unit
This module implements two finite state machine, one for enabling the stages
in sequence, the other for setting up the correct path for data to enter or exit
in the Exectution and Memory Stage.
5
2.2.3 Instruction Decode
In this phase there is the Register File in which the registers are written and
read, provinding data to the execution stage.
2.2.6 Write-Back
This is a multiplexer that selects the source to be written in the Register File.
6
Chapter 3
Modular View
In this chapter the main modules are presented, listing all the signals, compo-
nents and processes involved.
7
3.1.2 Processes
3.1.3 Behaviour
In the ENBL process there is a finite state machine which, at every clock cycle,
sets one single enable signal for the next phase in this order: IF, ID, EX, MM
plus one pseudo enable (that is, when they are all 0) for the WB that has not
enable inputs.
In the other process, DECODE all the control signals (listed above) are
actived accordingly to the operation that must be executed. Since not every
operation always activates every control signal (with the exception of left mux,
right mux and alu mux ) at the beginning of the process, a default value is
assigned.
3.2.2 Components
8
3.2.3 Behaviour
First of all a new istruction is extracted from the instruction memory (MEM ),
a read-only array of blocks of 8 bits, using the program counter value as vector
index; then this value is stored inside a special register (IR) which splits the
various part of an instruction (opcode, registers etc).
Finally the content of the program counter (PC ) is increased of 4 through
Adder4 and stored in NPC.
3.3.2 Components
Component Name Component description
REG FILE The Register File
SIGN Sign extension for the Immediate number
A The register for the first operand
B The register for the second operand
Imm The register for the extended immediate number
3.3.3 Behaviour
The two source registers are extracted from the Register File according to the
addresses r s and r t, and stored in a register (respectively A out and B out).
As for the destination register, there’s a condition on opcode in:
9
As for the immediate number, it must be first extended to complete the
register size; so in SIGN the Most Significant Bit of Imm in is repeated to
cover the whole size of Imm out, the register in which this value is stored.
3.4.2 Components
3.4.3 Behaviour
The Control Unit chooses the inputs that are going to be processed by the ALU
with the two multiplexers MUX L (NPC or register A) and MUX R (register B
or immediate). The ALU performs the operation selected with the omonimous
signal (always commanded by the Contro Unit) and stores the result in the
ALU out register.
In the meantime the CHK controls the branch output. It can be forced to
produce always 0 (000, no branch taken) and always 1 (111 always jump); the
intemediate value correspond to the desired comparison operation (=, 6=, >, <,
10
≥, ≤) between 0 and the input operand, and they determine whether a branch
is taken or not.
3.5.2 Components
3.5.3 Behaviour
This is the central operating unit which provides the actual output of the oper-
ation, located inside the execution stage.
The input operands from left and right are connected to all the modules
above and each one of them provides a result; only the selected result is sent to
output, using a behavioral muxer controlled by alu mux. The various modules
options (like for signed and unsigned numbers) are carefully activated with the
signals info, types and extra.
11
3.6 Memory Stage
3.6.1 Input and Outputs
Signal Name Type Signal description
clk IN Clock synchronization signal
rst IN Reset control signal
enb IN Register and memory enable
cond IN Control signal for mux 0
sel IN Control signal for mux 1
mem wr IN Enable Write on the RAM
mem cnt IN Word size selection
B in IN Data to be saved in memory
ALU in IN Address for the memory array
NewPC IN Corresponds to Program Counter + 4
mux out OUT Output from mux 1
result OUT Output from the memory array
NPC final OUT Correct Next Program Counter
3.6.2 Components
3.6.3 Behaviour
According to condition evaluation of the Execution Stage, the correct Program
Counter is selected via MUX 0 (either PC+4 or the value computed by the
ALU) and stored in PCreg.
In case of Jump and Link or Jump and Link Register operations, the ouput
value must be the New Program Counter while in the Instruction Decode the
correct destination register has already been selected. To do so, MUX 1 selects
the NPC, instead of the ALU ouput, and sends it Write Back stage.
The input and output of the memory is first filtered with SPLIT in and
SPLIT out to obtain just the desired word size (the control signal mem cnt is
directly sent from the Control Unit). Then the least significant bits (only due
to design limitation) of the ALU output is used to access the RAM (which is
simply an array of registers) and the result in sent directly to the Write Back.
12
3.7 Write-Back
3.7.1 Input and Outputs
Signal Name Type Signal description
LOAD in IN Clock synchronization signal
ALU in IN Reset control signal
sel IN Register enable
output OUT Control signal for mux 0
3.7.2 Components
Component Name Component description
MUX Multiplexer between the output of the memory and
of the ALU towards the Register File
3.7.3 Behaviour
This module selects the final data to be stored in the Register File; depending
on the operation, it selects either the memory output, or the result of the ALU.
13