Difference between revisions of "CPUProject"

From ATI public wiki
Jump to: navigation, search
(Created page with "CPU project is one of the projects designed in department of computer engineering at TTU as a lab project. The main aims of this project are: * Developing a generic CPU witho...")
 
Line 4: Line 4:
 
* Compiling GCC for this architecture
 
* Compiling GCC for this architecture
 
* Booting a light linux on it
 
* Booting a light linux on it
 +
 
= CPU Design=
 
= CPU Design=
 +
 
== Functionality Requirements ==
 
== Functionality Requirements ==
 
The CPU is supposed to be able to perform the following operations:
 
The CPU is supposed to be able to perform the following operations:
Line 19: Line 21:
 
* NOP/HALT  
 
* NOP/HALT  
  
== Instruction Set Architecture (ISA)==
+
== Architecture ==
 +
===Instruction Format===
 +
Our CPU's instuction has 8 bit of upcode and one operand that can be as long as 32 bit.
 +
First 3 bits of OPcode are at the moment reserved.
 +
 
 +
== Instruction Set (IS)==
 
The following instrcutions designed for the CPU:  
 
The following instrcutions designed for the CPU:  
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! Instruction !! Description !! OpCode !! DPU Command !! Data To DPU !! MemAddress !!  Next PC
+
! Instruction !! Register Transfer Language !! OpCode !! DPU Command !! Data To DPU !! MemAddress !!  Next PC
 
|-
 
|-
| Add_A_B || A <-- A + B || Example || Example || Example || Example || Example  
+
| Add_A_B || A <-- A + B                   || Example || 00 000 0000 10 || ----    || ---- || PC_out+1  
 
|-
 
|-
| Add_A_Mem || Example || Example || Example || Example || Example || Example  
+
| Add_A_Mem || A <-- A + Mem[Operand]      || Example || 00 000 0000 00 || ----    || Operand || PC_out+1  
 
|-
 
|-
| Add_A_Dir || Example || Example || Example || Example || Example || Example  
+
| Add_A_Dir || A <-- A + Operand            || Example || 00 000 0000 01 || Operand || ---- || PC_out+1  
 
|-
 
|-
| Sub_A_B || Example || Example || Example || Example || Example || Example   
+
| Sub_A_B || A <-- A - B                    || Example || 00 000 0001 10 || ----    || ---- || Example   
 
|-
 
|-
| Sub_A_Mem || Example || Example || Example || Example || Example || Example  
+
| Sub_A_Mem || A <-- A - Mem[Operand]      || Example || 00 000 0001 00 || ----    || Operand || PC_out+1  
 
|-
 
|-
| Sub_A_Dir || Example || Example || Example || Example || Example || Example  
+
| Sub_A_Dir || A <-- A - Operand            || Example || 00 000 0001 01 || Operand || ---- || PC_out+1  
 
|-
 
|-
| IncA || Example || Example || Example || Example || Example || Example  
+
| IncA || A <-- A + 1                      || Example || 00 000 0000 11 || ----    || ---- || PC_out+1  
 
|-
 
|-
| DecA || Example || Example || Example || Example || Example || Example
+
| DecA || A <-- A - 1                      || Example || 00 000 0001 11 || ----    || ---- || PC_out+1
 
|-
 
|-
| And_A_B || Example || Example || Example || Example || Example || Example  
+
| And_A_B || A <-- A and B                  || Example || 00 000 0100 10 || ----    || ---- || PC_out+1  
 
|-
 
|-
| OR_A_B || Example || Example || Example || Example || Example || Example  
+
| OR_A_B || A <-- A or B                    || Example || 00 000 0101 10 || ----    || ---- || PC_out+1  
 
|-
 
|-
| XOR_A_B || Example || Example || Example || Example || Example || Example  
+
| XOR_A_B || A <-- A xor B                  || Example || 00 000 0110 10 || ----    || ---- || PC_out+1  
 
|-
 
|-
| FlipA || Example || Example || Example || Example || Example || Example  
+
| FlipA || A <-- not (A)                    || Example || 00 000 1100 00 || ----    || ---- || PC_out+1  
 
|-
 
|-
| NegA || Example || Example || Example || Example || Example || Example  
+
| NegA || A <-- not(A) + 1                  || Example || Example || ---- || ---- || PC_out+1  
 
|-
 
|-
| Jmp || Example || Example || Example || Example || Example || Example  
+
| Jmp || PC <-- Operand                    || Example || Example || ---- || ---- || Depends  
 
|-
 
|-
| JmpZ || Example || Example || Example || Example || Example || Example  
+
| JmpZ || if Z = 1: PC <-- Operand || Example || Example || ---- || ---- || Depends  
 
|-
 
|-
| JmpOV || Example || Example || Example || Example || Example || Example  
+
| JmpOV || if OV = 1: PC <-- Operand || Example || Example || ---- || ---- || Depends  
 
|-
 
|-
| Jmp_rel || Example || Example || Example || Example || Example || Example  
+
| Jmp_rel || PC <-- PC + Operand  || Example || Example || ---- || ---- || Depends  
 
|-
 
|-
| JMPEQ || Example || Example || Example || Example || Example || Example  
+
| JMPEQ || if EQ = 1: PC <-- Operand || Example || Example || ---- || ---- || Depends  
 
|-
 
|-
| ClearZ || Example || Example || Example || Example || Example || Example  
+
| ClearZ || Z <--- 0 || Example || Example || ---- || ---- ||   PC_out+1  
 
|-
 
|-
| ClearOV || Example || Example || Example || Example || Example || Example 
+
| ClearOV || OV <--- 0 || Example || Example || ---- || ---- || PC_out+1   
 
|-
 
|-
| LoadPC  || Example || Example || Example || Example || Example || Example  
+
| LoadPC  || PC <---- A || Example || Example || ---- || ---- || A  
 
|-
 
|-
| SavePC || Example || Example || Example || Example || Example || Example 
+
| SavePC || A <---- PC || Example || Example || PC || ---- || PC_out+1   
 
|-
 
|-
| ShiftArithR || Example || Example || Example || Example || Example || Example 
+
| ShiftArithR || A <-- A(7) & A(7 downto 1)  || Example || Example || ---- || ---- || PC_out+1   
 
|-
 
|-
| ShiftArithL || Example || Example || Example || Example || Example || Example 
+
| ShiftArithL || A <-- A(7) & A(5 downto 0)& '0' || Example || Example || ---- || ---- || PC_out+1   
 
|-
 
|-
| ShiftA_R || Example || Example || Example || Example || Example || Example 
+
| ShiftA_R || A <-- A(6 downto 0)& '0' || Example || Example || ---- || ---- || PC_out+1   
 
|-
 
|-
| ShiftA_L || Example || Example || Example || Example || Example || Example 
+
| ShiftA_L || A <-- '0' & A(7 downto 1)  || Example || Example || ---- || ---- || PC_out+1   
 
|-
 
|-
| Load_A_Mem || Example || Example || Example || Example || Example || Example 
+
| Load_A_Mem || A <-- Mem[Operand] || Example || Example || ---- || Operand || PC_out+1   
 
|-
 
|-
| Store_A_Mem || Example || Example || Example || Example || Example || Example 
+
| Store_A_Mem || Mem[Operand] <-- A || Example || 00 000 0010 -- || ---- || Operand || PC_out+1   
 
|-
 
|-
| Load_B_Dir || Example || Example || Example || Example || Example || Example 
+
| Load_B_Dir || B <-- Operand || Example || 00 000 0010 -- || Operand || ---- || PC_out+1   
 
|-
 
|-
| Load_B_Mem || Example || Example || Example || Example || Example || Example 
+
| Load_B_Mem || B <-- Mem[Operand] || Example || 00 000 0010 -- || ---- || Operand || PC_out+1   
 
|-
 
|-
| JmpC || Example || Example || Example || Example || Example || Example  
+
| JmpC || if C = 1: PC <-- Operand || Example || 00 000 0010 -- || ---- || ---- || Depends  
 
|-
 
|-
| ClearC || Example || Example || Example || Example || Example || Example 
+
| ClearC || C <--- 0 || Example || 00 000 0010 -- || ---- || ---- || PC_out+1   
 
|-
 
|-
| ClearACC || Example || Example || Example || Example || Example || Example 
+
| ClearACC || ACC <-- 0 || Example || Example || ---- || ---- || PC_out+1   
 
|-
 
|-
| RRC || Example || Example || Example || Example || Example || Example 
+
| RRC || A <-- C & A(7 downto 1) ,C<--  A(0)  || Example || Example || ---- || ---- || PC_out+1   
 
|-
 
|-
| PUSH || Example || Example || Example || Example || Example || Example 
+
| RLC || A <-- A(6 downto 0) & C ,C<--  A(7) || Example || Example || ---- || ---- || PC_out+1 
 
|-
 
|-
| POP || Example || Example || Example || Example || Example || Example  
+
| PUSH || Mem [0 + SP] <--- A,SP <--- SP + 1 || Example || 00 000 0010 -- || ---- || SP || PC_out+1  
 
|-
 
|-
| RLC || Example || Example || Example || Example || Example || Example  
+
| POP || A <--- Mem [0 + SP - 1],SP <--- SP - 1 || Example || Example || ---- || SP - 1 || PC_out+1  
 
|-
 
|-
| NOP || Example || Example || Example || Example || Example || Example  
+
| NOP || NOP || Example || 00 000 0010 -- || ---- || ---- || PC_out+1  
 
|-
 
|-
| HALT || Example || Example || Example || Example || Example || Example  
+
| HALT || HALT || Example || 00 000 0010 -- || ---- || ---- || PC  
 
|}
 
|}
 
===Other instructions implementation===
 
===Other instructions implementation===
Line 115: Line 122:
 
  Add_A_Dir 4
 
  Add_A_Dir 4
 
  LoadPC
 
  LoadPC
 +
 +
== DataPath unit==
 +
===Flags===
 +
== Control unit==
 +
== Instruction Memory (ROM) ==
 +
== Data Memory ==
  
 
== Functional Testing ==
 
== Functional Testing ==

Revision as of 19:28, 4 December 2014

CPU project is one of the projects designed in department of computer engineering at TTU as a lab project. The main aims of this project are:

  • Developing a generic CPU without any fancy feature
  • Writing a compiler for it
  • Compiling GCC for this architecture
  • Booting a light linux on it

CPU Design

Functionality Requirements

The CPU is supposed to be able to perform the following operations:

  • Addition/Subtraction
  • Increment/Decrement
  • Arithmetic and Logical Shift
  • Bitwise AND, OR, XOR and NOT
  • Negation
  • Load/Store
  • Unconditional Branch (jump)
  • Branch if zero / Branch if Overflow / Branch if Carry
  • Clear Registers/Flags
  • PUSH / POP
  • NOP/HALT

Architecture

Instruction Format

Our CPU's instuction has 8 bit of upcode and one operand that can be as long as 32 bit. First 3 bits of OPcode are at the moment reserved.

Instruction Set (IS)

The following instrcutions designed for the CPU:

Instruction Register Transfer Language OpCode DPU Command Data To DPU MemAddress Next PC
Add_A_B A <-- A + B Example 00 000 0000 10 ---- ---- PC_out+1
Add_A_Mem A <-- A + Mem[Operand] Example 00 000 0000 00 ---- Operand PC_out+1
Add_A_Dir A <-- A + Operand Example 00 000 0000 01 Operand ---- PC_out+1
Sub_A_B A <-- A - B Example 00 000 0001 10 ---- ---- Example
Sub_A_Mem A <-- A - Mem[Operand] Example 00 000 0001 00 ---- Operand PC_out+1
Sub_A_Dir A <-- A - Operand Example 00 000 0001 01 Operand ---- PC_out+1
IncA A <-- A + 1 Example 00 000 0000 11 ---- ---- PC_out+1
DecA A <-- A - 1 Example 00 000 0001 11 ---- ---- PC_out+1
And_A_B A <-- A and B Example 00 000 0100 10 ---- ---- PC_out+1
OR_A_B A <-- A or B Example 00 000 0101 10 ---- ---- PC_out+1
XOR_A_B A <-- A xor B Example 00 000 0110 10 ---- ---- PC_out+1
FlipA A <-- not (A) Example 00 000 1100 00 ---- ---- PC_out+1
NegA A <-- not(A) + 1 Example Example ---- ---- PC_out+1
Jmp PC <-- Operand Example Example ---- ---- Depends
JmpZ if Z = 1: PC <-- Operand Example Example ---- ---- Depends
JmpOV if OV = 1: PC <-- Operand Example Example ---- ---- Depends
Jmp_rel PC <-- PC + Operand Example Example ---- ---- Depends
JMPEQ if EQ = 1: PC <-- Operand Example Example ---- ---- Depends
ClearZ Z <--- 0 Example Example ---- ---- PC_out+1
ClearOV OV <--- 0 Example Example ---- ---- PC_out+1
LoadPC PC <---- A Example Example ---- ---- A
SavePC A <---- PC Example Example PC ---- PC_out+1
ShiftArithR A <-- A(7) & A(7 downto 1) Example Example ---- ---- PC_out+1
ShiftArithL A <-- A(7) & A(5 downto 0)& '0' Example Example ---- ---- PC_out+1
ShiftA_R A <-- A(6 downto 0)& '0' Example Example ---- ---- PC_out+1
ShiftA_L A <-- '0' & A(7 downto 1) Example Example ---- ---- PC_out+1
Load_A_Mem A <-- Mem[Operand] Example Example ---- Operand PC_out+1
Store_A_Mem Mem[Operand] <-- A Example 00 000 0010 -- ---- Operand PC_out+1
Load_B_Dir B <-- Operand Example 00 000 0010 -- Operand ---- PC_out+1
Load_B_Mem B <-- Mem[Operand] Example 00 000 0010 -- ---- Operand PC_out+1
JmpC if C = 1: PC <-- Operand Example 00 000 0010 -- ---- ---- Depends
ClearC C <--- 0 Example 00 000 0010 -- ---- ---- PC_out+1
ClearACC ACC <-- 0 Example Example ---- ---- PC_out+1
RRC A <-- C & A(7 downto 1) ,C<-- A(0) Example Example ---- ---- PC_out+1
RLC A <-- A(6 downto 0) & C ,C<-- A(7) Example Example ---- ---- PC_out+1
PUSH Mem [0 + SP] <--- A,SP <--- SP + 1 Example 00 000 0010 -- ---- SP PC_out+1
POP A <--- Mem [0 + SP - 1],SP <--- SP - 1 Example Example ---- SP - 1 PC_out+1
NOP NOP Example 00 000 0010 -- ---- ---- PC_out+1
HALT HALT Example 00 000 0010 -- ---- ---- PC

Other instructions implementation

the follwoing instructions can be also implemented with the ones in IS:

  • Call "function_name":
PUSH
SavePC
Push
Jmp "function address"
POP  
  • Return:
POP
Add_A_Dir 4
LoadPC

DataPath unit

Flags

Control unit

Instruction Memory (ROM)

Data Memory

Functional Testing

Assembler

Compiler