1 |
2 |
jeunes2 |
-- This file is part of the marca processor.
|
2 |
|
|
-- Copyright (C) 2007 Wolfgang Puffitsch
|
3 |
|
|
|
4 |
|
|
-- This program is free software; you can redistribute it and/or modify it
|
5 |
|
|
-- under the terms of the GNU Library General Public License as published
|
6 |
|
|
-- by the Free Software Foundation; either version 2, or (at your option)
|
7 |
|
|
-- any later version.
|
8 |
|
|
|
9 |
|
|
-- This program is distributed in the hope that it will be useful,
|
10 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12 |
|
|
-- Library General Public License for more details.
|
13 |
|
|
|
14 |
|
|
-- You should have received a copy of the GNU Library General Public
|
15 |
|
|
-- License along with this program; if not, write to the Free Software
|
16 |
|
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
17 |
|
|
|
18 |
|
|
-------------------------------------------------------------------------------
|
19 |
|
|
-- Package MARCA
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
-- global definitions for MARCA processor
|
22 |
|
|
-------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
-------------------------------------------------------------------------------
|
25 |
|
|
-- Wolfgang Puffitsch
|
26 |
|
|
-- Computer Architecture Lab, Group 3
|
27 |
|
|
-------------------------------------------------------------------------------
|
28 |
|
|
|
29 |
|
|
library IEEE;
|
30 |
|
|
use IEEE.std_logic_1164.all;
|
31 |
|
|
use IEEE.numeric_std.all;
|
32 |
|
|
|
33 |
|
|
package marca_pkg is
|
34 |
|
|
|
35 |
|
|
-----------------------------------------------------------------------------
|
36 |
|
|
-- running at a whopping 20MHz
|
37 |
|
|
-----------------------------------------------------------------------------
|
38 |
|
|
constant CLOCK_FREQ : integer := 20000000;
|
39 |
|
|
|
40 |
|
|
-----------------------------------------------------------------------------
|
41 |
|
|
-- the reset-button is high when pressed
|
42 |
|
|
-----------------------------------------------------------------------------
|
43 |
|
|
constant RESET_ACTIVE : std_logic := '1';
|
44 |
|
|
|
45 |
|
|
-----------------------------------------------------------------------------
|
46 |
|
|
-- general constants
|
47 |
|
|
-----------------------------------------------------------------------------
|
48 |
|
|
constant REG_WIDTH : integer := 16;
|
49 |
|
|
constant REG_WIDTH_LOG : integer := 4;
|
50 |
|
|
|
51 |
|
|
constant REG_COUNT : integer := 16;
|
52 |
|
|
constant REG_COUNT_LOG : integer := 4;
|
53 |
|
|
|
54 |
|
|
constant VEC_COUNT : integer := 16;
|
55 |
|
|
|
56 |
|
|
constant ADDR_WIDTH : integer := 13;
|
57 |
|
|
constant DATA_WIDTH : integer := 8;
|
58 |
|
|
|
59 |
|
|
constant RADDR_WIDTH : integer := 8;
|
60 |
|
|
constant RDATA_WIDTH : integer := 8;
|
61 |
|
|
|
62 |
|
|
constant PADDR_WIDTH : integer := 13;
|
63 |
|
|
constant PDATA_WIDTH : integer := 16;
|
64 |
|
|
|
65 |
|
|
constant OUT_BITS : integer := 2;
|
66 |
|
|
constant IN_BITS : integer := 2;
|
67 |
|
|
|
68 |
|
|
-----------------------------------------------------------------------------
|
69 |
|
|
-- where to access which memory
|
70 |
|
|
-----------------------------------------------------------------------------
|
71 |
|
|
constant MEM_MIN_ADDR : std_logic_vector := "0000000000000000";
|
72 |
|
|
constant MEM_MAX_ADDR : std_logic_vector := "0001111111111111";
|
73 |
|
|
|
74 |
|
|
constant ROM_MIN_ADDR : std_logic_vector := "0010000000000000";
|
75 |
|
|
constant ROM_MAX_ADDR : std_logic_vector := "0010000011111111";
|
76 |
|
|
|
77 |
|
|
-----------------------------------------------------------------------------
|
78 |
|
|
-- opcodes
|
79 |
|
|
-----------------------------------------------------------------------------
|
80 |
|
|
constant OPC_ADD : std_logic_vector(3 downto 0) := "0000";
|
81 |
|
|
constant OPC_SUB : std_logic_vector(3 downto 0) := "0001";
|
82 |
|
|
constant OPC_ADDC : std_logic_vector(3 downto 0) := "0010";
|
83 |
|
|
constant OPC_SUBC : std_logic_vector(3 downto 0) := "0011";
|
84 |
|
|
constant OPC_AND : std_logic_vector(3 downto 0) := "0100";
|
85 |
|
|
constant OPC_OR : std_logic_vector(3 downto 0) := "0101";
|
86 |
|
|
constant OPC_XOR : std_logic_vector(3 downto 0) := "0110";
|
87 |
|
|
constant OPC_MUL : std_logic_vector(3 downto 0) := "0111";
|
88 |
|
|
constant OPC_DIV : std_logic_vector(3 downto 0) := "1000";
|
89 |
|
|
constant OPC_UDIV : std_logic_vector(3 downto 0) := "1001";
|
90 |
|
|
constant OPC_LDIL : std_logic_vector(3 downto 0) := "1010";
|
91 |
|
|
constant OPC_LDIH : std_logic_vector(3 downto 0) := "1011";
|
92 |
|
|
constant OPC_LDIB : std_logic_vector(3 downto 0) := "1100";
|
93 |
|
|
|
94 |
|
|
-- the following opcodes have this prefix
|
95 |
|
|
constant OPC_PFX_A : std_logic_vector(3 downto 0) := "1101";
|
96 |
|
|
|
97 |
|
|
constant OPC_MOV : std_logic_vector(3 downto 0) := "0000";
|
98 |
|
|
constant OPC_MOD : std_logic_vector(3 downto 0) := "0001";
|
99 |
|
|
constant OPC_UMOD : std_logic_vector(3 downto 0) := "0010";
|
100 |
|
|
constant OPC_NOT : std_logic_vector(3 downto 0) := "0011";
|
101 |
|
|
constant OPC_NEG : std_logic_vector(3 downto 0) := "0100";
|
102 |
|
|
constant OPC_CMP : std_logic_vector(3 downto 0) := "0101";
|
103 |
|
|
constant OPC_ADDI : std_logic_vector(3 downto 0) := "0110";
|
104 |
|
|
constant OPC_CMPI : std_logic_vector(3 downto 0) := "0111";
|
105 |
|
|
constant OPC_SHL : std_logic_vector(3 downto 0) := "1000";
|
106 |
|
|
constant OPC_SHR : std_logic_vector(3 downto 0) := "1001";
|
107 |
|
|
constant OPC_SAR : std_logic_vector(3 downto 0) := "1010";
|
108 |
|
|
constant OPC_ROLC : std_logic_vector(3 downto 0) := "1011";
|
109 |
|
|
constant OPC_RORC : std_logic_vector(3 downto 0) := "1100";
|
110 |
|
|
constant OPC_BSET : std_logic_vector(3 downto 0) := "1101";
|
111 |
|
|
constant OPC_BCLR : std_logic_vector(3 downto 0) := "1110";
|
112 |
|
|
constant OPC_BTEST : std_logic_vector(3 downto 0) := "1111";
|
113 |
|
|
|
114 |
|
|
-- the following opcodes have this prefix
|
115 |
|
|
constant OPC_PFX_B : std_logic_vector(3 downto 0) := "1110";
|
116 |
|
|
|
117 |
|
|
constant OPC_LOAD : std_logic_vector(3 downto 0) := "0000";
|
118 |
|
|
constant OPC_STORE : std_logic_vector(3 downto 0) := "0001";
|
119 |
|
|
constant OPC_LOADL : std_logic_vector(3 downto 0) := "0010";
|
120 |
|
|
constant OPC_LOADH : std_logic_vector(3 downto 0) := "0011";
|
121 |
|
|
constant OPC_LOADB : std_logic_vector(3 downto 0) := "0100";
|
122 |
|
|
constant OPC_STOREL: std_logic_vector(3 downto 0) := "0101";
|
123 |
|
|
constant OPC_STOREH: std_logic_vector(3 downto 0) := "0110";
|
124 |
|
|
constant OPC_CALL : std_logic_vector(3 downto 0) := "1000";
|
125 |
|
|
|
126 |
|
|
-- the following opcodes have this prefix
|
127 |
|
|
constant OPC_PFX_C : std_logic_vector(3 downto 0) := "1111";
|
128 |
|
|
|
129 |
|
|
constant OPC_BR : std_logic_vector(3 downto 0) := "0000";
|
130 |
|
|
constant OPC_BRZ : std_logic_vector(3 downto 0) := "0001";
|
131 |
|
|
constant OPC_BRNZ : std_logic_vector(3 downto 0) := "0010";
|
132 |
|
|
constant OPC_BRLE : std_logic_vector(3 downto 0) := "0011";
|
133 |
|
|
constant OPC_BRLT : std_logic_vector(3 downto 0) := "0100";
|
134 |
|
|
constant OPC_BRGE : std_logic_vector(3 downto 0) := "0101";
|
135 |
|
|
constant OPC_BRGT : std_logic_vector(3 downto 0) := "0110";
|
136 |
|
|
constant OPC_BRULE : std_logic_vector(3 downto 0) := "0111";
|
137 |
|
|
constant OPC_BRULT : std_logic_vector(3 downto 0) := "1000";
|
138 |
|
|
constant OPC_BRUGE : std_logic_vector(3 downto 0) := "1001";
|
139 |
|
|
constant OPC_BRUGT : std_logic_vector(3 downto 0) := "1010";
|
140 |
|
|
constant OPC_SEXT : std_logic_vector(3 downto 0) := "1011";
|
141 |
|
|
constant OPC_LDVEC : std_logic_vector(3 downto 0) := "1100";
|
142 |
|
|
constant OPC_STVEC : std_logic_vector(3 downto 0) := "1101";
|
143 |
|
|
|
144 |
|
|
-- the following opcodes have this prefix additionally to OPC_PFX_C
|
145 |
|
|
constant OPC_PFX_C1 : std_logic_vector(3 downto 0) := "1110";
|
146 |
|
|
|
147 |
|
|
constant OPC_JMP : std_logic_vector(3 downto 0):= "0000";
|
148 |
|
|
constant OPC_JMPZ : std_logic_vector(3 downto 0):= "0001";
|
149 |
|
|
constant OPC_JMPNZ : std_logic_vector(3 downto 0):= "0010";
|
150 |
|
|
constant OPC_JMPLE : std_logic_vector(3 downto 0):= "0011";
|
151 |
|
|
constant OPC_JMPLT : std_logic_vector(3 downto 0):= "0100";
|
152 |
|
|
constant OPC_JMPGE : std_logic_vector(3 downto 0):= "0101";
|
153 |
|
|
constant OPC_JMPGT : std_logic_vector(3 downto 0):= "0110";
|
154 |
|
|
constant OPC_JMPULE: std_logic_vector(3 downto 0):= "0111";
|
155 |
|
|
constant OPC_JMPULT: std_logic_vector(3 downto 0):= "1000";
|
156 |
|
|
constant OPC_JMPUGE: std_logic_vector(3 downto 0):= "1001";
|
157 |
|
|
constant OPC_JMPUGT: std_logic_vector(3 downto 0):= "1010";
|
158 |
|
|
constant OPC_INTR : std_logic_vector(3 downto 0):= "1011";
|
159 |
|
|
constant OPC_GETIRA: std_logic_vector(3 downto 0):= "1100";
|
160 |
|
|
constant OPC_SETIRA: std_logic_vector(3 downto 0):= "1101";
|
161 |
|
|
constant OPC_GETFL : std_logic_vector(3 downto 0):= "1110";
|
162 |
|
|
constant OPC_SETFL : std_logic_vector(3 downto 0):= "1111";
|
163 |
|
|
|
164 |
|
|
-- the following opcodes have this prefix additionally to OPC_PFX_C
|
165 |
|
|
constant OPC_PFX_C2 : std_logic_vector(3 downto 0) := "1111";
|
166 |
|
|
|
167 |
|
|
constant OPC_GETSHFL:std_logic_vector(3 downto 0):= "0000";
|
168 |
|
|
constant OPC_SETSHFL:std_logic_vector(3 downto 0):= "0001";
|
169 |
|
|
|
170 |
|
|
-- the following opcodes have this prefix additionally to OPC_PFX_C2
|
171 |
|
|
constant OPC_PFX_C2a : std_logic_vector(3 downto 0) := "1111";
|
172 |
|
|
|
173 |
|
|
constant OPC_RETI : std_logic_vector(3 downto 0):= "0000";
|
174 |
|
|
constant OPC_NOP : std_logic_vector(3 downto 0):= "0001";
|
175 |
|
|
constant OPC_SEI : std_logic_vector(3 downto 0):= "0010";
|
176 |
|
|
constant OPC_CLI : std_logic_vector(3 downto 0):= "0011";
|
177 |
|
|
constant OPC_ERROR : std_logic_vector(3 downto 0):= "1111";
|
178 |
|
|
|
179 |
|
|
-----------------------------------------------------------------------------
|
180 |
|
|
-- definitions for the flags register
|
181 |
|
|
-----------------------------------------------------------------------------
|
182 |
|
|
constant FLAG_Z : integer := 0;
|
183 |
|
|
constant FLAG_C : integer := 1;
|
184 |
|
|
constant FLAG_V : integer := 2;
|
185 |
|
|
constant FLAG_N : integer := 3;
|
186 |
|
|
constant FLAG_I : integer := 4;
|
187 |
|
|
constant FLAG_P : integer := 5;
|
188 |
|
|
|
189 |
|
|
-----------------------------------------------------------------------------
|
190 |
|
|
-- definitions for the exception vectors
|
191 |
|
|
-----------------------------------------------------------------------------
|
192 |
|
|
constant EXC_ERR : integer := 0;
|
193 |
|
|
constant EXC_ALU : integer := 1;
|
194 |
|
|
constant EXC_MEM : integer := 2;
|
195 |
|
|
|
196 |
|
|
-----------------------------------------------------------------------------
|
197 |
|
|
-- which unit to be on duty
|
198 |
|
|
-----------------------------------------------------------------------------
|
199 |
|
|
type UNIT_SELECTOR is (UNIT_ALU, UNIT_MEM, UNIT_INTR, UNIT_CALL);
|
200 |
|
|
|
201 |
|
|
-----------------------------------------------------------------------------
|
202 |
|
|
-- where to write a result
|
203 |
|
|
-----------------------------------------------------------------------------
|
204 |
|
|
type TARGET_SELECTOR is (TARGET_NONE, TARGET_REGISTER, TARGET_PC, TARGET_BOTH);
|
205 |
|
|
|
206 |
|
|
-----------------------------------------------------------------------------
|
207 |
|
|
-- the operations of the ALU
|
208 |
|
|
-----------------------------------------------------------------------------
|
209 |
|
|
type ALU_OP is (ALU_ADD,
|
210 |
|
|
ALU_SUB,
|
211 |
|
|
ALU_ADDC,
|
212 |
|
|
ALU_SUBC,
|
213 |
|
|
ALU_NEG,
|
214 |
|
|
ALU_ADDI,
|
215 |
|
|
ALU_CMPI,
|
216 |
|
|
ALU_BRZ,
|
217 |
|
|
ALU_BRNZ,
|
218 |
|
|
ALU_BRLE,
|
219 |
|
|
ALU_BRLT,
|
220 |
|
|
ALU_BRGE,
|
221 |
|
|
ALU_BRGT,
|
222 |
|
|
ALU_BRULE,
|
223 |
|
|
ALU_BRULT,
|
224 |
|
|
ALU_BRUGE,
|
225 |
|
|
ALU_BRUGT,
|
226 |
|
|
|
227 |
|
|
ALU_MUL,
|
228 |
|
|
ALU_DIV,
|
229 |
|
|
ALU_UDIV,
|
230 |
|
|
ALU_MOD,
|
231 |
|
|
ALU_UMOD,
|
232 |
|
|
|
233 |
|
|
ALU_AND,
|
234 |
|
|
ALU_OR,
|
235 |
|
|
ALU_XOR,
|
236 |
|
|
ALU_LDIL,
|
237 |
|
|
ALU_LDIH,
|
238 |
|
|
ALU_LDIB,
|
239 |
|
|
ALU_MOV,
|
240 |
|
|
ALU_NOT,
|
241 |
|
|
ALU_SHL,
|
242 |
|
|
ALU_SHR,
|
243 |
|
|
ALU_SAR,
|
244 |
|
|
ALU_ROLC,
|
245 |
|
|
ALU_RORC,
|
246 |
|
|
ALU_BSET,
|
247 |
|
|
ALU_BCLR,
|
248 |
|
|
ALU_BTEST,
|
249 |
|
|
ALU_SEXT,
|
250 |
|
|
ALU_JMP,
|
251 |
|
|
ALU_JMPZ,
|
252 |
|
|
ALU_JMPNZ,
|
253 |
|
|
ALU_JMPLE,
|
254 |
|
|
ALU_JMPLT,
|
255 |
|
|
ALU_JMPGE,
|
256 |
|
|
ALU_JMPGT,
|
257 |
|
|
ALU_JMPULE,
|
258 |
|
|
ALU_JMPULT,
|
259 |
|
|
ALU_JMPUGE,
|
260 |
|
|
ALU_JMPUGT,
|
261 |
|
|
ALU_GETFL,
|
262 |
|
|
ALU_SETFL,
|
263 |
|
|
ALU_GETSHFL,
|
264 |
|
|
ALU_SETSHFL,
|
265 |
|
|
ALU_INTR,
|
266 |
|
|
ALU_RETI,
|
267 |
|
|
ALU_SEI,
|
268 |
|
|
ALU_CLI,
|
269 |
|
|
ALU_NOP);
|
270 |
|
|
|
271 |
|
|
-----------------------------------------------------------------------------
|
272 |
|
|
-- the operations of the memory unit
|
273 |
|
|
-----------------------------------------------------------------------------
|
274 |
|
|
type MEM_OP is (MEM_LOAD,
|
275 |
|
|
MEM_LOADL,
|
276 |
|
|
MEM_LOADH,
|
277 |
|
|
MEM_LOADB,
|
278 |
|
|
MEM_STORE,
|
279 |
|
|
MEM_STOREL,
|
280 |
|
|
MEM_STOREH,
|
281 |
|
|
MEM_NOP);
|
282 |
|
|
|
283 |
|
|
-----------------------------------------------------------------------------
|
284 |
|
|
-- the operations of the interrupt unit
|
285 |
|
|
-----------------------------------------------------------------------------
|
286 |
|
|
type INTR_OP is (INTR_INTR,
|
287 |
|
|
INTR_RETI,
|
288 |
|
|
INTR_SETIRA,
|
289 |
|
|
INTR_GETIRA,
|
290 |
|
|
INTR_STVEC,
|
291 |
|
|
INTR_LDVEC,
|
292 |
|
|
INTR_NOP);
|
293 |
|
|
|
294 |
|
|
-----------------------------------------------------------------------------
|
295 |
|
|
-- more of a hack to reduce checks against zero to a large NOR
|
296 |
|
|
-----------------------------------------------------------------------------
|
297 |
|
|
function zero(a : std_logic_vector) return std_logic;
|
298 |
|
|
|
299 |
|
|
end marca_pkg;
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
package body marca_pkg is
|
303 |
|
|
|
304 |
|
|
function zero(a : std_logic_vector)
|
305 |
|
|
return std_logic is
|
306 |
|
|
variable result : std_logic;
|
307 |
|
|
variable i : integer;
|
308 |
|
|
begin
|
309 |
|
|
result := '0';
|
310 |
|
|
for i in a'low to a'high loop
|
311 |
|
|
result := result or a(i);
|
312 |
|
|
end loop;
|
313 |
|
|
return not result;
|
314 |
|
|
end;
|
315 |
|
|
|
316 |
|
|
end marca_pkg;
|