1 |
2 |
idiolatrie |
--------------------------------------------------------------------------------
|
2 |
|
|
-- MIPS™ I CPU - Type Definitions --
|
3 |
|
|
--------------------------------------------------------------------------------
|
4 |
|
|
-- Copyright (C)2011 Mathias Hörtnagl <mathias.hoertnagl@gmail.comt> --
|
5 |
|
|
-- --
|
6 |
|
|
-- This program is free software: you can redistribute it and/or modify --
|
7 |
|
|
-- it under the terms of the GNU General Public License as published by --
|
8 |
|
|
-- the Free Software Foundation, either version 3 of the License, or --
|
9 |
|
|
-- (at your option) any later version. --
|
10 |
|
|
-- --
|
11 |
|
|
-- This program is distributed in the hope that it will be useful, --
|
12 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
13 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
14 |
|
|
-- GNU General Public License for more details. --
|
15 |
|
|
-- --
|
16 |
|
|
-- You should have received a copy of the GNU General Public License --
|
17 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
|
18 |
|
|
--------------------------------------------------------------------------------
|
19 |
|
|
library ieee;
|
20 |
|
|
use ieee.std_logic_1164.all;
|
21 |
|
|
use ieee.numeric_std.all;
|
22 |
|
|
|
23 |
|
|
library work;
|
24 |
|
|
use work.mips1.all;
|
25 |
|
|
|
26 |
|
|
package tcpu is
|
27 |
|
|
|
28 |
|
|
component gpr is
|
29 |
|
|
port(
|
30 |
|
|
clk_i : in std_logic;
|
31 |
|
|
hld_i : in std_logic;
|
32 |
|
|
rs_a : in std_logic_vector(4 downto 0);
|
33 |
|
|
rt_a : in std_logic_vector(4 downto 0);
|
34 |
|
|
rd_a : in std_logic_vector(4 downto 0);
|
35 |
|
|
rd_we : in std_logic;
|
36 |
|
|
rd_i : in std_logic_vector(31 downto 0);
|
37 |
|
|
rs_o : out std_logic_vector(31 downto 0);
|
38 |
|
|
rt_o : out std_logic_vector(31 downto 0)
|
39 |
|
|
);
|
40 |
|
|
end component;
|
41 |
|
|
|
42 |
|
|
-----------------------------------------------------------------------------
|
43 |
|
|
-- MEMORY STAGE --
|
44 |
|
|
-----------------------------------------------------------------------------
|
45 |
|
|
type wc_t is record
|
46 |
|
|
we : std_logic; -- Write back enable.
|
47 |
|
|
end record;
|
48 |
|
|
|
49 |
|
|
type me_t is record
|
50 |
|
|
wc : wc_t; -- Write Back Stage control.
|
51 |
|
|
rd : std_logic_vector(4 downto 0); -- Write back register address.
|
52 |
|
|
res : std_logic_vector(31 downto 0); -- Write back data (ALU or Memory).
|
53 |
|
|
end record;
|
54 |
|
|
|
55 |
|
|
-----------------------------------------------------------------------------
|
56 |
|
|
-- EXECUTION STAGE --
|
57 |
|
|
-----------------------------------------------------------------------------
|
58 |
|
|
type mem_ext_t is (ZERO, SIGN);
|
59 |
|
|
type mem_byt_t is (NONE, BYTE, HALF, WORD);
|
60 |
|
|
|
61 |
|
|
type jadr_t is record
|
62 |
|
|
j : unsigned(31 downto 2); -- Jump/Branch address.
|
63 |
|
|
jmp : std_logic; -- Jump or don't jump. That's ...
|
64 |
|
|
end record;
|
65 |
|
|
|
66 |
|
|
type mem_t is record
|
67 |
|
|
we : std_logic; -- Stored data write enable.
|
68 |
|
|
ext : mem_ext_t; -- Loaded Data extension.
|
69 |
|
|
byt : mem_byt_t; -- Data width.
|
70 |
|
|
end record;
|
71 |
|
|
|
72 |
|
|
type ret_t is (ALU, MEM);
|
73 |
|
|
|
74 |
|
|
type mc_t is record
|
75 |
|
|
src : ret_t; -- Either ALU or Memory result.
|
76 |
|
|
mem : mem_t; -- Load/Store control signals.
|
77 |
|
|
end record;
|
78 |
|
|
|
79 |
|
|
type ex_t is record
|
80 |
|
|
mc : mc_t; -- Memory Stage control.
|
81 |
|
|
wc : wc_t; -- Write Back Stage control.
|
82 |
|
|
rd : std_logic_vector(4 downto 0); -- Write back register address.
|
83 |
|
|
f : jadr_t; -- Jump/Branch information for IF.
|
84 |
|
|
str : std_logic_vector(31 downto 0); -- ALU source B saved to memory.
|
85 |
|
|
res : std_logic_vector(31 downto 0); -- ALU result.
|
86 |
|
|
end record;
|
87 |
|
|
|
88 |
|
|
-----------------------------------------------------------------------------
|
89 |
|
|
-- DECODE STAGE --
|
90 |
|
|
-----------------------------------------------------------------------------
|
91 |
|
|
type jmp_op_t is (NOP, JMP, EQ, NEQ, GTZ, LTZ, GEZ, LEZ);
|
92 |
|
|
type jmp_src_t is (REG, JMP, BRA);
|
93 |
|
|
|
94 |
|
|
type jmp_t is record
|
95 |
|
|
op : jmp_op_t; -- Possible branching conditions.
|
96 |
|
|
src : jmp_src_t; -- Possile jump/branch sources.
|
97 |
|
|
end record;
|
98 |
|
|
|
99 |
|
|
type alu_src_a_t is (SH_CONST, SH_16, ADD_4, REG);
|
100 |
|
|
type alu_src_b_t is (ZERO, SIGN, PC, REG);
|
101 |
|
|
|
102 |
|
|
type alu_src_t is record
|
103 |
|
|
a : alu_src_a_t; -- Sources for input A.
|
104 |
|
|
b : alu_src_b_t; -- Sources for input B.
|
105 |
|
|
end record;
|
106 |
|
|
|
107 |
|
|
type alu_t is record
|
108 |
|
|
op : alu_op_t; -- ALU Ops [Mips1.vhd]
|
109 |
|
|
src : alu_src_t; -- ALU sources.
|
110 |
|
|
end record;
|
111 |
|
|
|
112 |
|
|
type wbr_t is (RD, RT, RA); -- Possible write back addresses.
|
113 |
|
|
|
114 |
|
|
type ec_t is record
|
115 |
|
|
wbr : wbr_t; -- Write back register type.
|
116 |
|
|
alu : alu_t; -- ALU control signals.
|
117 |
|
|
jmp : jmp_t; -- Jump/Branch control signals.
|
118 |
|
|
end record;
|
119 |
|
|
|
120 |
|
|
type cc_t is record
|
121 |
|
|
mtsr : boolean; -- CP0 move to SR enable.
|
122 |
|
|
rfe : boolean; -- Restore from exception.
|
123 |
|
|
end record;
|
124 |
|
|
|
125 |
|
|
type dc_t is record
|
126 |
|
|
we : std_logic; -- WB forward write enable.
|
127 |
|
|
end record;
|
128 |
|
|
|
129 |
|
|
type de_t is record
|
130 |
|
|
cc : cc_t; -- CP0 control.
|
131 |
|
|
dc : dc_t; -- Decode Stage control.
|
132 |
|
|
ec : ec_t; -- Execution Stage control.
|
133 |
|
|
mc : mc_t; -- Memory Stage control.
|
134 |
|
|
wc : wc_t; -- Write Back Stage control.
|
135 |
|
|
--f : jadr_t; -- J, JAL control signals.
|
136 |
|
|
rd : std_logic_vector(4 downto 0); -- WB forward destination address.
|
137 |
|
|
res : std_logic_vector(31 downto 0); -- WB forward data.
|
138 |
|
|
i : std_logic_vector(25 downto 0); -- Instruction (without OP code).
|
139 |
|
|
end record;
|
140 |
|
|
|
141 |
|
|
-----------------------------------------------------------------------------
|
142 |
|
|
-- FETCH STAGE --
|
143 |
|
|
-----------------------------------------------------------------------------
|
144 |
|
|
type fe_t is record
|
145 |
|
|
pc : unsigned(31 downto 2); -- Program counter.
|
146 |
|
|
end record;
|
147 |
|
|
|
148 |
|
|
-----------------------------------------------------------------------------
|
149 |
|
|
-- CO-PROCESSOR 0 --
|
150 |
|
|
-----------------------------------------------------------------------------
|
151 |
|
|
type sr_t is record
|
152 |
|
|
im : std_logic_vector(7 downto 0); -- Interrupt mask.
|
153 |
|
|
iec : std_logic; -- IEc: Interrupt enable current.
|
154 |
|
|
iep : std_logic; -- IEp: Interrupt enable previous.
|
155 |
|
|
ieo : std_logic; -- IEo: Interrupt enable old.
|
156 |
|
|
end record;
|
157 |
|
|
|
158 |
|
|
type cp0_t is record
|
159 |
|
|
sr : sr_t; -- Status register.
|
160 |
|
|
epc : unsigned(29 downto 0); -- Exception program counter.
|
161 |
|
|
end record;
|
162 |
|
|
|
163 |
|
|
end tcpu;
|