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

Subversion Repositories opencpu32

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

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

powered by: WebSVN 2.1.0

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