fetch und decode kompilierbar, generelle tb, änderung in pkgs, eigene decoder entity
[calu.git] / cpu / src / common_pkg.vhd
1 library IEEE;
2
3 use IEEE.std_logic_1164.all;
4 use IEEE.numeric_std.all;
5
6 package common_pkg is
7
8
9         
10         constant WORD_WIDTH   : INTEGER := 32;
11         constant HWORD_WIDTH  : INTEGER := 16;
12         constant BYTE_WIDTH   : INTEGER :=  8;
13         constant OPCODE_WIDTH : INTEGER :=  5;
14         constant DISPL_WIDTH  : INTEGER := 15;
15
16         subtype byte_t is std_logic_vector(BYTE_WIDTH-1 downto 0);
17         subtype hword_t is std_logic_vector(HWORD_WIDTH-1 downto 0);
18         subtype word_t  is std_logic_vector(WORD_WIDTH-1 downto 0);
19
20         subtype gp_register_t is word_t;
21
22         
23         constant REG_ZERO : gp_register_t := (others => '0');
24
25         constant INSTR_ADDR_WIDTH       : INTEGER := 32;
26         constant PHYS_INSTR_ADDR_WIDTH  : INTEGER := 11;
27         constant REG_ADDR_WIDTH         : INTEGER := 4;
28         constant DATA_ADDR_WIDTH        : INTEGER := 32;
29         constant PHYS_DATA_ADDR_WIDTH   : INTEGER := 32;
30         
31         constant NUM_OP_OPT_WIDTH       : INTEGER := 5;
32         constant COND_WIDTH : INTEGER := 4;
33
34         
35         subtype instruction_word_t is std_logic_vector(WORD_WIDTH-1 downto 0);
36         subtype instruction_addr_t is std_logic_vector(INSTR_ADDR_WIDTH-1 downto 0);
37         
38         subtype gp_addr_t       is unsigned(REG_ADDR_WIDTH-1 downto 0);
39         subtype data_ram_word_t is std_logic_vector(WORD_WIDTH-1 downto 0);
40         subtype data_ram_addr_t is std_logic_vector(DATA_ADDR_WIDTH-1 downto 0);
41
42         subtype opcode_t is std_logic_vector(OPCODE_WIDTH-1 downto 0);
43         subtype condition_t is std_logic_vector(COND_WIDTH-1 downto 0);
44         
45         --Opcode consits of decoded group information type and option bits
46         --currently not complete, might need option increase too.
47         --IMMEDIATE always in right_operand (src2)
48         
49         constant IMM_OPT : integer := 0;
50         
51         constant SUB_OPT : integer := 1;
52         constant LOG_SHIFT : integer := 1;
53         
54         constant CARRY_OPT : integer := 2;
55         
56         constant LEFT_SHIFT : integer := 3;
57         
58         constant PSW_DISABLE : integer := 4;
59         
60         type op_info_t is (ADDSUB_OP,AND_OP,OR_OP, XOR_OP,SHIFT_OP);
61         subtype op_opt_rec is std_logic_vector(NUM_OP_OPT_WIDTH-1 downto 0);
62         
63         
64         type instruction_rec is record
65
66                 predicates : std_logic_vector(3 downto 0);
67
68                 opcode : opcode_t;
69
70                 reg_dest_addr : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
71                 reg_src1_addr : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
72                 reg_src2_addr : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
73
74                 immediate : std_logic_vector(WORD_WIDTH-1 downto 0);
75                 displacement : std_logic_vector(DISPL_WIDTH-1 downto 0);
76
77                 jmptype : std_logic_vector(1 downto 0);
78
79                 carry, sreg_update, high_low, fill, signext, bp, arith, left_right : std_logic;
80
81         end record;
82
83
84         type read_through_write_rec is record
85
86                 rtw_reg : gp_register_t;
87                 rtw_reg1 : std_logic;
88                 rtw_reg2 : std_logic;
89
90         end record;
91
92         type dec_op is record
93                 condition : condition_t;
94                 op_group : op_info_t;
95                 op_detail : op_opt_rec;
96                 brpr : std_logic;
97                 
98                 src1 : gp_register_t;
99                 src2 : gp_register_t;
100                 
101                 saddr1 : gp_addr_t;
102                 saddr2 : gp_addr_t;
103                 
104                 daddr   : gp_addr_t;
105                 
106         end record;
107
108         
109         
110         
111         function inc(value : in std_logic_vector; constant by : in integer := 1) return std_logic_vector;
112         function log2c(constant value : in integer range 0 to integer'high) return integer;
113 end package common_pkg;
114
115 package body common_pkg is
116
117         function inc(value : in std_logic_vector; constant by : in integer := 1) return std_logic_vector is
118         begin
119                 return std_logic_vector(UNSIGNED(value)+by);
120         end function inc;
121         
122         function log2c(constant value : in integer range 0 to integer'high) return integer is
123                 variable ret_value : integer;
124                 variable cur_value : integer;
125         begin
126                 ret_value := 0;
127                 cur_value := 1;
128                 
129                 while cur_value < value loop
130                         ret_value := ret_value + 1;
131                         cur_value := cur_value * 2;
132                 end loop;
133                 return ret_value;
134         end function log2c;
135         
136 end package body common_pkg;