2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
6 use work.decode_types.all;
11 constant MSR_SF : integer := (63 - 0); -- Sixty-Four bit mode
12 constant MSR_EE : integer := (63 - 48); -- External interrupt Enable
13 constant MSR_PR : integer := (63 - 49); -- PRoblem state
14 constant MSR_IR : integer := (63 - 58); -- Instruction Relocation
15 constant MSR_DR : integer := (63 - 59); -- Data Relocation
16 constant MSR_RI : integer := (63 - 62); -- Recoverable Interrupt
17 constant MSR_LE : integer := (63 - 63); -- Little Endian
20 subtype spr_num_t is integer range 0 to 1023;
22 function decode_spr_num(insn: std_ulogic_vector(31 downto 0)) return spr_num_t;
24 constant SPR_XER : spr_num_t := 1;
25 constant SPR_LR : spr_num_t := 8;
26 constant SPR_CTR : spr_num_t := 9;
27 constant SPR_DSISR : spr_num_t := 18;
28 constant SPR_DAR : spr_num_t := 19;
29 constant SPR_TB : spr_num_t := 268;
30 constant SPR_DEC : spr_num_t := 22;
31 constant SPR_SRR0 : spr_num_t := 26;
32 constant SPR_SRR1 : spr_num_t := 27;
33 constant SPR_HSRR0 : spr_num_t := 314;
34 constant SPR_HSRR1 : spr_num_t := 315;
35 constant SPR_SPRG0 : spr_num_t := 272;
36 constant SPR_SPRG1 : spr_num_t := 273;
37 constant SPR_SPRG2 : spr_num_t := 274;
38 constant SPR_SPRG3 : spr_num_t := 275;
39 constant SPR_SPRG3U : spr_num_t := 259;
40 constant SPR_HSPRG0 : spr_num_t := 304;
41 constant SPR_HSPRG1 : spr_num_t := 305;
43 -- GPR indices in the register file (GPR only)
44 subtype gpr_index_t is std_ulogic_vector(4 downto 0);
46 -- Extended GPR indice (can hold an SPR)
47 subtype gspr_index_t is std_ulogic_vector(5 downto 0);
49 -- Some SPRs are stored in the register file, they use the magic
50 -- GPR numbers above 31.
52 -- The function fast_spr_num() returns the corresponding fast
53 -- pseudo-GPR number for a given SPR number. The result MSB
54 -- indicates if this is indeed a fast SPR. If clear, then
55 -- the SPR is not stored in the GPR file.
57 function fast_spr_num(spr: spr_num_t) return gspr_index_t;
59 -- Indices conversion functions
60 function gspr_to_gpr(i: gspr_index_t) return gpr_index_t;
61 function gpr_to_gspr(i: gpr_index_t) return gspr_index_t;
62 function gpr_or_spr_to_gspr(g: gpr_index_t; s: gspr_index_t) return gspr_index_t;
63 function is_fast_spr(s: gspr_index_t) return std_ulogic;
65 -- The XER is split: the common bits (CA, OV, SO, OV32 and CA32) are
66 -- in the CR file as a kind of CR extension (with a separate write
67 -- control). The rest is stored as a fast SPR.
68 type xer_common_t is record
75 constant xerc_init : xer_common_t := (others => '0');
77 type irq_state_t is (WRITE_SRR0, WRITE_SRR1);
79 -- This needs to die...
81 tb: std_ulogic_vector(63 downto 0);
82 dec: std_ulogic_vector(63 downto 0);
83 msr: std_ulogic_vector(63 downto 0);
84 irq_state : irq_state_t;
85 irq_nia: std_ulogic_vector(63 downto 0);
86 srr1: std_ulogic_vector(63 downto 0);
89 type Fetch1ToIcacheType is record
91 stop_mark: std_ulogic;
92 nia: std_ulogic_vector(63 downto 0);
95 type IcacheToFetch2Type is record
97 stop_mark: std_ulogic;
98 nia: std_ulogic_vector(63 downto 0);
99 insn: std_ulogic_vector(31 downto 0);
102 type Fetch2ToDecode1Type is record
104 stop_mark : std_ulogic;
105 nia: std_ulogic_vector(63 downto 0);
106 insn: std_ulogic_vector(31 downto 0);
108 constant Fetch2ToDecode1Init : Fetch2ToDecode1Type := (valid => '0', stop_mark => '0', others => (others => '0'));
110 type Decode1ToDecode2Type is record
112 stop_mark : std_ulogic;
113 nia: std_ulogic_vector(63 downto 0);
114 insn: std_ulogic_vector(31 downto 0);
115 ispr1: gspr_index_t; -- (G)SPR used for branch condition (CTR) or mfspr
116 ispr2: gspr_index_t; -- (G)SPR used for branch target (CTR, LR, TAR)
117 decode: decode_rom_t;
119 constant Decode1ToDecode2Init : Decode1ToDecode2Type := (valid => '0', stop_mark => '0', decode => decode_rom_init, others => (others => '0'));
121 type Decode2ToExecute1Type is record
124 insn_type: insn_type_t;
125 nia: std_ulogic_vector(63 downto 0);
126 write_reg: gspr_index_t;
127 read_reg1: gspr_index_t;
128 read_reg2: gspr_index_t;
129 read_data1: std_ulogic_vector(63 downto 0);
130 read_data2: std_ulogic_vector(63 downto 0);
131 read_data3: std_ulogic_vector(63 downto 0);
132 bypass_data1: std_ulogic;
133 bypass_data2: std_ulogic;
134 bypass_data3: std_ulogic;
135 cr: std_ulogic_vector(31 downto 0);
140 invert_a: std_ulogic;
141 invert_out: std_ulogic;
142 input_carry: carry_in_t;
143 output_carry: std_ulogic;
144 input_cr: std_ulogic;
145 output_cr: std_ulogic;
146 is_32bit: std_ulogic;
147 is_signed: std_ulogic;
148 insn: std_ulogic_vector(31 downto 0);
149 data_len: std_ulogic_vector(3 downto 0);
150 byte_reverse : std_ulogic;
151 sign_extend : std_ulogic; -- do we need to sign extend?
152 update : std_ulogic; -- is this an update instruction?
153 reserve : std_ulogic; -- set for larx/stcx
155 constant Decode2ToExecute1Init : Decode2ToExecute1Type :=
156 (valid => '0', unit => NONE, insn_type => OP_ILLEGAL, bypass_data1 => '0', bypass_data2 => '0', bypass_data3 => '0',
157 lr => '0', rc => '0', oe => '0', invert_a => '0',
158 invert_out => '0', input_carry => ZERO, output_carry => '0', input_cr => '0', output_cr => '0',
159 is_32bit => '0', is_signed => '0', xerc => xerc_init, reserve => '0',
160 byte_reverse => '0', sign_extend => '0', update => '0', others => (others => '0'));
162 type Execute1ToMultiplyType is record
164 insn_type: insn_type_t;
165 data1: std_ulogic_vector(64 downto 0);
166 data2: std_ulogic_vector(64 downto 0);
167 is_32bit: std_ulogic;
169 constant Execute1ToMultiplyInit : Execute1ToMultiplyType := (valid => '0', insn_type => OP_ILLEGAL,
171 others => (others => '0'));
173 type Execute1ToDividerType is record
175 dividend: std_ulogic_vector(63 downto 0);
176 divisor: std_ulogic_vector(63 downto 0);
177 is_signed: std_ulogic;
178 is_32bit: std_ulogic;
179 is_extended: std_ulogic;
180 is_modulus: std_ulogic;
181 neg_result: std_ulogic;
183 constant Execute1ToDividerInit: Execute1ToDividerType := (valid => '0', is_signed => '0', is_32bit => '0',
184 is_extended => '0', is_modulus => '0',
185 neg_result => '0', others => (others => '0'));
187 type Decode2ToRegisterFileType is record
188 read1_enable : std_ulogic;
189 read1_reg : gspr_index_t;
190 read2_enable : std_ulogic;
191 read2_reg : gspr_index_t;
192 read3_enable : std_ulogic;
193 read3_reg : gpr_index_t;
196 type RegisterFileToDecode2Type is record
197 read1_data : std_ulogic_vector(63 downto 0);
198 read2_data : std_ulogic_vector(63 downto 0);
199 read3_data : std_ulogic_vector(63 downto 0);
202 type Decode2ToCrFileType is record
206 type CrFileToDecode2Type is record
207 read_cr_data : std_ulogic_vector(31 downto 0);
208 read_xerc_data : xer_common_t;
211 type Execute1ToFetch1Type is record
212 redirect: std_ulogic;
213 redirect_nia: std_ulogic_vector(63 downto 0);
215 constant Execute1ToFetch1TypeInit : Execute1ToFetch1Type := (redirect => '0', others => (others => '0'));
217 type Execute1ToLoadstore1Type is record
219 op : insn_type_t; -- what ld/st or m[tf]spr or TLB op to do
220 addr1 : std_ulogic_vector(63 downto 0);
221 addr2 : std_ulogic_vector(63 downto 0);
222 data : std_ulogic_vector(63 downto 0); -- data to write, unused for read
223 write_reg : gpr_index_t;
224 length : std_ulogic_vector(3 downto 0);
225 ci : std_ulogic; -- cache-inhibited load/store
226 byte_reverse : std_ulogic;
227 sign_extend : std_ulogic; -- do we need to sign extend?
228 update : std_ulogic; -- is this an update instruction?
229 update_reg : gpr_index_t; -- if so, the register to update
231 reserve : std_ulogic; -- set for larx/stcx.
232 rc : std_ulogic; -- set for stcx.
233 virt_mode : std_ulogic; -- do translation through TLB
234 priv_mode : std_ulogic; -- privileged mode (MSR[PR] = 0)
235 spr_num : spr_num_t; -- SPR number for mfspr/mtspr
237 constant Execute1ToLoadstore1Init : Execute1ToLoadstore1Type := (valid => '0', op => OP_ILLEGAL, ci => '0', byte_reverse => '0',
238 sign_extend => '0', update => '0', xerc => xerc_init,
239 reserve => '0', rc => '0', virt_mode => '0', priv_mode => '0',
240 spr_num => 0, others => (others => '0'));
242 type Loadstore1ToExecute1Type is record
243 exception : std_ulogic;
246 type Loadstore1ToDcacheType is record
248 load : std_ulogic; -- is this a load
249 tlbie : std_ulogic; -- is this a tlbie
252 reserve : std_ulogic;
253 virt_mode : std_ulogic;
254 priv_mode : std_ulogic;
255 addr : std_ulogic_vector(63 downto 0);
256 data : std_ulogic_vector(63 downto 0);
257 byte_sel : std_ulogic_vector(7 downto 0);
260 type DcacheToLoadstore1Type is record
262 data : std_ulogic_vector(63 downto 0);
263 store_done : std_ulogic;
265 tlb_miss : std_ulogic;
266 perm_error : std_ulogic;
267 rc_error : std_ulogic;
270 type Loadstore1ToWritebackType is record
272 write_enable: std_ulogic;
273 write_reg : gpr_index_t;
274 write_data : std_ulogic_vector(63 downto 0);
277 store_done : std_ulogic;
279 constant Loadstore1ToWritebackInit : Loadstore1ToWritebackType := (valid => '0', write_enable => '0', xerc => xerc_init,
280 rc => '0', store_done => '0', others => (others => '0'));
282 type Execute1ToWritebackType is record
285 write_enable : std_ulogic;
286 write_reg: gspr_index_t;
287 write_data: std_ulogic_vector(63 downto 0);
288 write_cr_enable : std_ulogic;
289 write_cr_mask : std_ulogic_vector(7 downto 0);
290 write_cr_data : std_ulogic_vector(31 downto 0);
291 write_xerc_enable : std_ulogic;
293 exc_write_enable : std_ulogic;
294 exc_write_reg : gspr_index_t;
295 exc_write_data : std_ulogic_vector(63 downto 0);
297 constant Execute1ToWritebackInit : Execute1ToWritebackType := (valid => '0', rc => '0', write_enable => '0',
298 write_cr_enable => '0', exc_write_enable => '0',
299 write_xerc_enable => '0', xerc => xerc_init,
300 others => (others => '0'));
302 type MultiplyToExecute1Type is record
304 write_reg_data: std_ulogic_vector(63 downto 0);
305 overflow : std_ulogic;
307 constant MultiplyToExecute1Init : MultiplyToExecute1Type := (valid => '0', overflow => '0',
308 others => (others => '0'));
310 type DividerToExecute1Type is record
312 write_reg_data: std_ulogic_vector(63 downto 0);
313 overflow : std_ulogic;
315 constant DividerToExecute1Init : DividerToExecute1Type := (valid => '0', overflow => '0',
316 others => (others => '0'));
318 type WritebackToRegisterFileType is record
319 write_reg : gspr_index_t;
320 write_data : std_ulogic_vector(63 downto 0);
321 write_enable : std_ulogic;
323 constant WritebackToRegisterFileInit : WritebackToRegisterFileType := (write_enable => '0', others => (others => '0'));
325 type WritebackToCrFileType is record
326 write_cr_enable : std_ulogic;
327 write_cr_mask : std_ulogic_vector(7 downto 0);
328 write_cr_data : std_ulogic_vector(31 downto 0);
329 write_xerc_enable : std_ulogic;
330 write_xerc_data : xer_common_t;
332 constant WritebackToCrFileInit : WritebackToCrFileType := (write_cr_enable => '0', write_xerc_enable => '0',
333 write_xerc_data => xerc_init,
334 others => (others => '0'));
336 type XicsToExecute1Type is record
342 package body common is
343 function decode_spr_num(insn: std_ulogic_vector(31 downto 0)) return spr_num_t is
345 return to_integer(unsigned(insn(15 downto 11) & insn(20 downto 16)));
347 function fast_spr_num(spr: spr_num_t) return gspr_index_t is
348 variable n : integer range 0 to 31;
369 when SPR_SPRG3 | SPR_SPRG3U =>
381 return "1" & std_ulogic_vector(to_unsigned(n, 5));
384 function gspr_to_gpr(i: gspr_index_t) return gpr_index_t is
386 return i(4 downto 0);
389 function gpr_to_gspr(i: gpr_index_t) return gspr_index_t is
394 function gpr_or_spr_to_gspr(g: gpr_index_t; s: gspr_index_t) return gspr_index_t is
399 return gpr_to_gspr(g);
403 function is_fast_spr(s: gspr_index_t) return std_ulogic is