OpenCores
URL https://opencores.org/ocsvn/opencpu32/opencpu32/trunk

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [pkgOpenCPU32.vhd] - Blame information for rev 26

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 leonardoar
--! @file
2
--! @brief 2:1 CPU global Definitions
3 14 leonardoar
 
4
--! @mainpage
5
--! <H1>Main document of the OpenCPU32 project</H1>\n
6
--! <H2>Features</H2>
7 5 leonardoar
 
8
--! Use standard library
9 24 leonardoar
library ieee;
10
use ieee.STD_LOGIC_1164.all;
11
use ieee.std_logic_unsigned.all;
12
use ieee.std_logic_arith.all;
13 5 leonardoar
 
14
package pkgOpenCPU32 is
15
 
16
--! Declare constants, enums, functions used by the design
17 8 leonardoar
constant nBits          : integer := 32;
18 24 leonardoar
constant instructionSize : integer := nBits;
19 8 leonardoar
 
20 14 leonardoar
--! Number of general registers (r0..r15)
21
constant numGenRegs : integer := 16;
22
 
23 20 leonardoar
type aluOps is (alu_pass, alu_passB, alu_sum, alu_sub, alu_inc, alu_dec, alu_mul, alu_or, alu_and,
24 17 leonardoar
        alu_xor, alu_not, alu_shfLt, alu_shfRt, alu_roLt, alu_roRt);
25 14 leonardoar
type typeEnDis is (enable, disable);
26 20 leonardoar
type generalRegisters is (r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15);
27
type dpMuxInputs is (fromMemory, fromImediate, fromRegFileA, fromRegFileB, fromAlu);
28 24 leonardoar
type controlUnitStates is (initial, fetch, decode, execute, executing);
29 26 leonardoar
type executionStates is (s0, s1, s2, s3, s4);
30 14 leonardoar
 
31
function reg2Num (a: generalRegisters) return integer;
32
function Num2reg (a: integer) return generalRegisters;
33 24 leonardoar
function muxPos( a: dpMuxInputs) return std_logic_vector;
34
 
35
-- Opcodes
36 26 leonardoar
subtype opcodes is std_logic_vector(5 downto 0); -- 6 Bits (64 instructions max)
37 24 leonardoar
 
38
-- Each instruction will take 32 bits
39
-- Tutorial on using records.. (http://vhdlguru.blogspot.com.br/2010/02/arrays-and-records-in-vhdl.html)
40
type instructionType is record
41
        opcode : std_logic_vector(5 downto 0);
42
        reg1   : std_logic_vector(3 downto 0);
43
        reg2   : std_logic_vector(3 downto 0);
44
        imm    : std_logic_vector(15 downto 0); -- Max imediate value (16 bits)
45
end record;
46
 
47
 
48
-- Data movement
49
constant mov_reg  : opcodes := conv_std_logic_vector(0,6);        -- Move data between registers
50
constant mov_val  : opcodes := conv_std_logic_vector(1,6);   -- Move data from imediate value to a register
51
constant stom_reg : opcodes := conv_std_logic_vector(2,6);   -- Store a value in memory coming from a register
52
constant stom_val : opcodes := conv_std_logic_vector(3,6);   -- Store a value in memory coming from imediate
53
constant ld_reg   : opcodes := conv_std_logic_vector(4,6);   -- Load a value from memory into a register
54
constant ld_val   : opcodes := conv_std_logic_vector(5,6);   -- Load a value from memoru into another address in memory
55
 
56
-- Jump instructions
57
constant jmp_val  : opcodes := conv_std_logic_vector(6,6);       -- Jump (PC <= Val)
58
constant jmpr_val : opcodes := conv_std_logic_vector(7,6);   -- Jump relative (PC <= PC + Val)
59
constant jz_val   : opcodes := conv_std_logic_vector(8,6);   -- Jump if zero
60
constant jzr_val  : opcodes := conv_std_logic_vector(9,6);   -- Jump if zero relative
61
constant jnz_val  : opcodes := conv_std_logic_vector(10,6);  -- Jump if not zero
62
constant jnzr_val : opcodes := conv_std_logic_vector(11,6);  -- Jump if not zero relative
63
constant call_reg : opcodes := conv_std_logic_vector(12,6);  -- Jump to address (Save return value on the stack
64
constant ret_reg  : opcodes := conv_std_logic_vector(13,6);  -- Pop return value from the stack and jump to it
65
 
66
-- Logical instructions
67
constant and_reg  : opcodes := conv_std_logic_vector(14,6);  -- And between to registers
68
constant and_val  : opcodes := conv_std_logic_vector(15,6);  -- And between register and imediate
69
constant or_reg   : opcodes := conv_std_logic_vector(16,6);  -- Or between to registers
70
constant or_val   : opcodes := conv_std_logic_vector(17,6);  -- Or between register and imediate
71
constant xor_reg  : opcodes := conv_std_logic_vector(18,6);  -- Xor between to registers
72
constant xor_val  : opcodes := conv_std_logic_vector(19,6);  -- Xor between register and imediate
73
constant not_reg  : opcodes := conv_std_logic_vector(20,6);  -- Not on register
74
constant shl_reg  : opcodes := conv_std_logic_vector(21,6);  -- Shift left register (one shift)
75
constant shr_reg  : opcodes := conv_std_logic_vector(22,6);  -- Shift right register (one shift)
76
constant rol_reg  : opcodes := conv_std_logic_vector(23,6);  -- Rotate left register (one rotation)
77
constant ror_reg  : opcodes := conv_std_logic_vector(24,6);  -- Rotate right register (one rotation)
78
constant sbit_reg : opcodes := conv_std_logic_vector(25,6);  -- Set bit pointed by register
79
constant cbit_reg : opcodes := conv_std_logic_vector(26,6);  -- Clear bit pointed by register
80
 
81
-- Math operations instructions (unsigned)
82
constant add_reg  : opcodes := conv_std_logic_vector(27,6);  -- Add to registers
83
constant add_val  : opcodes := conv_std_logic_vector(28,6);  -- Add register and a imediate value
84
constant sub_reg  : opcodes := conv_std_logic_vector(29,6);  -- Subtract to registers
85
constant sub_val  : opcodes := conv_std_logic_vector(30,6);  -- Subtract register and a imediate value
86
constant inc_reg  : opcodes := conv_std_logic_vector(31,6);  -- Increment register
87
constant dec_reg  : opcodes := conv_std_logic_vector(32,6);  -- Decrement register
88
 
89
-- Control opcodes
90
constant nop      : opcodes := conv_std_logic_vector(31,6);  -- Nop...
91
constant halt     : opcodes := conv_std_logic_vector(32,6);  -- Halt processor
92
 
93 5 leonardoar
end pkgOpenCPU32;
94
 
95
--! Define functions or procedures
96 14 leonardoar
package body pkgOpenCPU32 is
97
 
98 20 leonardoar
function muxPos( a: dpMuxInputs) return std_logic_vector is
99
variable valRet : std_logic_vector(2 downto 0);
100
begin
101
        case a is
102
                when fromMemory => valRet := "000";
103
                when fromImediate => valRet := "001";
104
                when fromRegFileA => valRet := "010";
105
                when fromRegFileB => valRet := "011";
106
                when fromAlu => valRet := "100";
107
        end case;
108
        return valRet;
109
end muxPos;
110
 
111 14 leonardoar
function reg2Num (a: generalRegisters) return integer is
112
  variable valRet : integer;
113
  begin
114
    case a is
115
                when r0 => valRet := 0;
116
                when r1 => valRet := 1;
117
                when r2 => valRet := 2;
118
                when r3 => valRet := 3;
119
                when r4 => valRet := 4;
120
                when r5 => valRet := 5;
121
                when r6 => valRet := 6;
122
                when r7 => valRet := 7;
123
                when r8 => valRet := 8;
124
                when r9 => valRet := 9;
125
                when r10 => valRet := 10;
126
                when r11 => valRet := 11;
127
                when r12 => valRet := 12;
128
                when r13 => valRet := 13;
129
                when r14 => valRet := 14;
130
                when r15 => valRet := 15;
131
         end case;
132
         return valRet;
133
  end reg2Num;
134
 
135
function Num2reg (a: integer) return generalRegisters is
136
  variable valRet : generalRegisters;
137
  begin
138
    case a is
139
                when 0 => valRet := r0;
140
                when 1 => valRet := r1;
141
                when 2 => valRet := r2;
142
                when 3 => valRet := r3;
143
                when 4 => valRet := r4;
144
                when 5 => valRet := r5;
145
                when 6 => valRet := r6;
146
                when 7 => valRet := r7;
147
                when 8 => valRet := r8;
148
                when 9 => valRet := r9;
149
                when 10 => valRet := r10;
150
                when 11 => valRet := r11;
151
                when 12 => valRet := r12;
152
                when 13 => valRet := r13;
153
                when 14 => valRet := r14;
154 16 leonardoar
                when 15 => valRet := r15;
155
                when others => valRet := r0;
156 14 leonardoar
         end case;
157
         return valRet;
158
  end Num2reg;
159 5 leonardoar
 
160
end pkgOpenCPU32;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.