ignore /abc.history
[microwatt.git] / execute1.vhdl
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5 library work;
6 use work.decode_types.all;
7 use work.common.all;
8 use work.helpers.all;
9 use work.crhelpers.all;
10 use work.insn_helpers.all;
11 use work.ppc_fx_insns.all;
12
13 entity execute1 is
14 generic (
15 SIM : boolean := false;
16 EX1_BYPASS : boolean := true;
17 HAS_FPU : boolean := true;
18 -- Non-zero to enable log data collection
19 LOG_LENGTH : natural := 0
20 );
21 port (
22 clk : in std_ulogic;
23 rst : in std_ulogic;
24
25 -- asynchronous
26 flush_in : in std_ulogic;
27 busy_out : out std_ulogic;
28
29 e_in : in Decode2ToExecute1Type;
30 l_in : in Loadstore1ToExecute1Type;
31 fp_in : in FPUToExecute1Type;
32
33 ext_irq_in : std_ulogic;
34 interrupt_in : WritebackToExecute1Type;
35
36 -- asynchronous
37 l_out : out Execute1ToLoadstore1Type;
38 fp_out : out Execute1ToFPUType;
39
40 e_out : out Execute1ToWritebackType;
41 bypass_data : out bypass_data_t;
42 bypass_cr_data : out cr_bypass_data_t;
43 bypass2_data : out bypass_data_t;
44 bypass2_cr_data : out cr_bypass_data_t;
45
46 dbg_ctrl_out : out ctrl_t;
47
48 icache_inval : out std_ulogic;
49 terminate_out : out std_ulogic;
50
51 -- PMU event buses
52 wb_events : in WritebackEventType;
53 ls_events : in Loadstore1EventType;
54 dc_events : in DcacheEventType;
55 ic_events : in IcacheEventType;
56
57 -- Access to SPRs from core_debug module
58 dbg_spr_req : in std_ulogic;
59 dbg_spr_ack : out std_ulogic;
60 dbg_spr_addr : in std_ulogic_vector(7 downto 0);
61 dbg_spr_data : out std_ulogic_vector(63 downto 0);
62
63 -- debug
64 sim_dump : in std_ulogic;
65 sim_dump_done : out std_ulogic;
66
67 log_out : out std_ulogic_vector(11 downto 0);
68 log_rd_addr : out std_ulogic_vector(31 downto 0);
69 log_rd_data : in std_ulogic_vector(63 downto 0);
70 log_wr_addr : in std_ulogic_vector(31 downto 0)
71 );
72 end entity execute1;
73
74 architecture behaviour of execute1 is
75 type side_effect_type is record
76 terminate : std_ulogic;
77 icache_inval : std_ulogic;
78 write_msr : std_ulogic;
79 write_xerlow : std_ulogic;
80 write_dec : std_ulogic;
81 write_cfar : std_ulogic;
82 write_loga : std_ulogic;
83 inc_loga : std_ulogic;
84 write_pmuspr : std_ulogic;
85 ramspr_write_even : std_ulogic;
86 ramspr_write_odd : std_ulogic;
87 mult_32s : std_ulogic;
88 end record;
89 constant side_effect_init : side_effect_type := (others => '0');
90
91 type actions_type is record
92 e : Execute1ToWritebackType;
93 se : side_effect_type;
94 complete : std_ulogic;
95 exception : std_ulogic;
96 trap : std_ulogic;
97 advance_nia : std_ulogic;
98 new_msr : std_ulogic_vector(63 downto 0);
99 take_branch : std_ulogic;
100 direct_branch : std_ulogic;
101 start_mul : std_ulogic;
102 start_div : std_ulogic;
103 do_trace : std_ulogic;
104 fp_intr : std_ulogic;
105 res2_sel : std_ulogic_vector(1 downto 0);
106 bypass_valid : std_ulogic;
107 ramspr_odd_data : std_ulogic_vector(63 downto 0);
108 end record;
109 constant actions_type_init : actions_type :=
110 (e => Execute1ToWritebackInit, se => side_effect_init,
111 new_msr => (others => '0'), res2_sel => "00",
112 ramspr_odd_data => 64x"0", others => '0');
113
114 type reg_stage1_type is record
115 e : Execute1ToWritebackType;
116 se : side_effect_type;
117 busy: std_ulogic;
118 fp_exception_next : std_ulogic;
119 trace_next : std_ulogic;
120 prev_op : insn_type_t;
121 prev_prefixed : std_ulogic;
122 oe : std_ulogic;
123 mul_select : std_ulogic_vector(1 downto 0);
124 res2_sel : std_ulogic_vector(1 downto 0);
125 spr_select : spr_id;
126 pmu_spr_num : std_ulogic_vector(4 downto 0);
127 mul_in_progress : std_ulogic;
128 mul_finish : std_ulogic;
129 div_in_progress : std_ulogic;
130 no_instr_avail : std_ulogic;
131 instr_dispatch : std_ulogic;
132 ext_interrupt : std_ulogic;
133 taken_branch_event : std_ulogic;
134 br_mispredict : std_ulogic;
135 msr : std_ulogic_vector(63 downto 0);
136 xerc : xer_common_t;
137 xerc_valid : std_ulogic;
138 ramspr_wraddr : ramspr_index;
139 ramspr_odd_data : std_ulogic_vector(63 downto 0);
140 end record;
141 constant reg_stage1_type_init : reg_stage1_type :=
142 (e => Execute1ToWritebackInit, se => side_effect_init,
143 busy => '0',
144 fp_exception_next => '0', trace_next => '0', prev_op => OP_ILLEGAL,
145 prev_prefixed => '0',
146 oe => '0', mul_select => "00", res2_sel => "00",
147 spr_select => spr_id_init, pmu_spr_num => 5x"0",
148 mul_in_progress => '0', mul_finish => '0', div_in_progress => '0',
149 no_instr_avail => '0', instr_dispatch => '0', ext_interrupt => '0',
150 taken_branch_event => '0', br_mispredict => '0',
151 msr => 64x"0",
152 xerc => xerc_init, xerc_valid => '0',
153 ramspr_wraddr => (others => '0'), ramspr_odd_data => 64x"0");
154
155 type reg_stage2_type is record
156 e : Execute1ToWritebackType;
157 se : side_effect_type;
158 ext_interrupt : std_ulogic;
159 taken_branch_event : std_ulogic;
160 br_mispredict : std_ulogic;
161 log_addr_spr : std_ulogic_vector(31 downto 0);
162 end record;
163 constant reg_stage2_type_init : reg_stage2_type :=
164 (e => Execute1ToWritebackInit, se => side_effect_init,
165 log_addr_spr => 32x"0", others => '0');
166
167 signal ex1, ex1in : reg_stage1_type;
168 signal ex2, ex2in : reg_stage2_type;
169 signal actions : actions_type;
170
171 signal a_in, b_in, c_in : std_ulogic_vector(63 downto 0);
172 signal cr_in : std_ulogic_vector(31 downto 0);
173 signal xerc_in : xer_common_t;
174 signal mshort_p : std_ulogic_vector(31 downto 0) := (others => '0');
175
176 signal valid_in : std_ulogic;
177 signal ctrl: ctrl_t := ctrl_t_init;
178 signal ctrl_tmp: ctrl_t := ctrl_t_init;
179 signal right_shift, rot_clear_left, rot_clear_right: std_ulogic;
180 signal rot_sign_ext: std_ulogic;
181 signal rotator_result: std_ulogic_vector(63 downto 0);
182 signal rotator_carry: std_ulogic;
183 signal logical_result: std_ulogic_vector(63 downto 0);
184 signal do_popcnt: std_ulogic;
185 signal countbits_result: std_ulogic_vector(63 downto 0);
186 signal alu_result: std_ulogic_vector(63 downto 0);
187 signal adder_result: std_ulogic_vector(63 downto 0);
188 signal misc_result: std_ulogic_vector(63 downto 0);
189 signal muldiv_result: std_ulogic_vector(63 downto 0);
190 signal shortmul_result: std_ulogic_vector(63 downto 0);
191 signal spr_result: std_ulogic_vector(63 downto 0);
192 signal next_nia : std_ulogic_vector(63 downto 0);
193 signal s1_sel : std_ulogic_vector(2 downto 0);
194
195 signal carry_32 : std_ulogic;
196 signal carry_64 : std_ulogic;
197 signal overflow_32 : std_ulogic;
198 signal overflow_64 : std_ulogic;
199
200 signal trapval : std_ulogic_vector(4 downto 0);
201
202 signal write_cr_mask : std_ulogic_vector(7 downto 0);
203 signal write_cr_data : std_ulogic_vector(31 downto 0);
204
205 -- multiply signals
206 signal x_to_multiply: MultiplyInputType;
207 signal multiply_to_x: MultiplyOutputType;
208 signal x_to_mult_32s: MultiplyInputType;
209 signal mult_32s_to_x: MultiplyOutputType;
210
211 -- divider signals
212 signal x_to_divider: Execute1ToDividerType;
213 signal divider_to_x: DividerToExecute1Type := DividerToExecute1Init;
214
215 -- random number generator signals
216 signal random_raw : std_ulogic_vector(63 downto 0);
217 signal random_cond : std_ulogic_vector(63 downto 0);
218 signal random_err : std_ulogic;
219
220 -- PMU signals
221 signal x_to_pmu : Execute1ToPMUType;
222 signal pmu_to_x : PMUToExecute1Type;
223
224 -- signals for logging
225 signal exception_log : std_ulogic;
226 signal irq_valid_log : std_ulogic;
227
228 -- SPR-related signals
229 type ramspr_half_t is array(ramspr_index_range) of std_ulogic_vector(63 downto 0);
230 signal even_sprs : ramspr_half_t := (others => (others => '0'));
231 signal odd_sprs : ramspr_half_t := (others => (others => '0'));
232 signal ramspr_even : std_ulogic_vector(63 downto 0);
233 signal ramspr_odd : std_ulogic_vector(63 downto 0);
234 signal ramspr_result : std_ulogic_vector(63 downto 0);
235 signal ramspr_rd_odd : std_ulogic;
236 signal ramspr_wr_addr : ramspr_index;
237 signal ramspr_even_wr_data : std_ulogic_vector(63 downto 0);
238 signal ramspr_even_wr_enab : std_ulogic;
239 signal ramspr_odd_wr_data : std_ulogic_vector(63 downto 0);
240 signal ramspr_odd_wr_enab : std_ulogic;
241
242 signal stage2_stall : std_ulogic;
243
244 type privilege_level is (USER, SUPER);
245 type op_privilege_array is array(insn_type_t) of privilege_level;
246 constant op_privilege: op_privilege_array := (
247 OP_ATTN => SUPER,
248 OP_MFMSR => SUPER,
249 OP_MTMSRD => SUPER,
250 OP_RFID => SUPER,
251 OP_TLBIE => SUPER,
252 others => USER
253 );
254
255 function instr_is_privileged(op: insn_type_t; insn: std_ulogic_vector(31 downto 0))
256 return boolean is
257 begin
258 if op_privilege(op) = SUPER then
259 return true;
260 elsif op = OP_MFSPR or op = OP_MTSPR then
261 return insn(20) = '1';
262 else
263 return false;
264 end if;
265 end;
266
267 procedure set_carry(e: inout Execute1ToWritebackType;
268 carry32 : in std_ulogic;
269 carry : in std_ulogic) is
270 begin
271 e.xerc.ca32 := carry32;
272 e.xerc.ca := carry;
273 end;
274
275 procedure set_ov(e: inout Execute1ToWritebackType;
276 ov : in std_ulogic;
277 ov32 : in std_ulogic) is
278 begin
279 e.xerc.ov32 := ov32;
280 e.xerc.ov := ov;
281 if ov = '1' then
282 e.xerc.so := '1';
283 end if;
284 end;
285
286 function calc_ov(msb_a : std_ulogic; msb_b: std_ulogic;
287 ca: std_ulogic; msb_r: std_ulogic) return std_ulogic is
288 begin
289 return (ca xor msb_r) and not (msb_a xor msb_b);
290 end;
291
292 function decode_input_carry(ic : carry_in_t;
293 xerc : xer_common_t) return std_ulogic is
294 begin
295 case ic is
296 when ZERO =>
297 return '0';
298 when CA =>
299 return xerc.ca;
300 when OV =>
301 return xerc.ov;
302 when ONE =>
303 return '1';
304 end case;
305 end;
306
307 function msr_copy(msr: std_ulogic_vector(63 downto 0))
308 return std_ulogic_vector is
309 variable msr_out: std_ulogic_vector(63 downto 0);
310 begin
311 -- ISA says this:
312 -- Defined MSR bits are classified as either full func-
313 -- tion or partial function. Full function MSR bits are
314 -- saved in SRR1 or HSRR1 when an interrupt other
315 -- than a System Call Vectored interrupt occurs and
316 -- restored by rfscv, rfid, or hrfid, while partial func-
317 -- tion MSR bits are not saved or restored.
318 -- Full function MSR bits lie in the range 0:32, 37:41, and
319 -- 48:63, and partial function MSR bits lie in the range
320 -- 33:36 and 42:47. (Note this is IBM bit numbering).
321 msr_out := (others => '0');
322 msr_out(63 downto 31) := msr(63 downto 31);
323 msr_out(26 downto 22) := msr(26 downto 22);
324 msr_out(15 downto 0) := msr(15 downto 0);
325 return msr_out;
326 end;
327
328 function intr_srr1(msr: std_ulogic_vector; flags: std_ulogic_vector)
329 return std_ulogic_vector is
330 variable srr1: std_ulogic_vector(63 downto 0);
331 begin
332 srr1(63 downto 31) := msr(63 downto 31);
333 srr1(30 downto 27) := flags(14 downto 11);
334 srr1(26 downto 22) := msr(26 downto 22);
335 srr1(21 downto 16) := flags(5 downto 0);
336 srr1(15 downto 0) := msr(15 downto 0);
337 return srr1;
338 end;
339
340 -- Work out whether a signed value fits into n bits,
341 -- that is, see if it is in the range -2^(n-1) .. 2^(n-1) - 1
342 function fits_in_n_bits(val: std_ulogic_vector; n: integer) return boolean is
343 variable x, xp1: std_ulogic_vector(val'left downto val'right);
344 begin
345 x := val;
346 if val(val'left) = '0' then
347 x := not val;
348 end if;
349 xp1 := bit_reverse(std_ulogic_vector(unsigned(bit_reverse(x)) + 1));
350 x := x and not xp1;
351 -- For positive inputs, x has ones at the positions
352 -- to the left of the leftmost 1 bit in val.
353 -- For negative inputs, x has ones to the left of
354 -- the leftmost 0 bit in val.
355 return x(n - 1) = '1';
356 end;
357
358 function assemble_xer(xerc: xer_common_t; xer_low: std_ulogic_vector)
359 return std_ulogic_vector is
360 begin
361 return 32x"0" & xerc.so & xerc.ov & xerc.ca & "000000000" &
362 xerc.ov32 & xerc.ca32 & xer_low(17 downto 0);
363 end;
364
365 -- Tell vivado to keep the hierarchy for the random module so that the
366 -- net names in the xdc file match.
367 attribute keep_hierarchy : string;
368 attribute keep_hierarchy of random_0 : label is "yes";
369
370 begin
371
372 rotator_0: entity work.rotator
373 port map (
374 rs => c_in,
375 ra => a_in,
376 shift => b_in(6 downto 0),
377 insn => e_in.insn,
378 is_32bit => e_in.is_32bit,
379 right_shift => right_shift,
380 arith => e_in.is_signed,
381 clear_left => rot_clear_left,
382 clear_right => rot_clear_right,
383 sign_ext_rs => rot_sign_ext,
384 result => rotator_result,
385 carry_out => rotator_carry
386 );
387
388 logical_0: entity work.logical
389 port map (
390 rs => c_in,
391 rb => b_in,
392 op => e_in.insn_type,
393 invert_in => e_in.invert_a,
394 invert_out => e_in.invert_out,
395 is_signed => e_in.is_signed,
396 result => logical_result,
397 datalen => e_in.data_len
398 );
399
400 countbits_0: entity work.bit_counter
401 port map (
402 clk => clk,
403 rs => c_in,
404 stall => stage2_stall,
405 count_right => e_in.insn(10),
406 is_32bit => e_in.is_32bit,
407 do_popcnt => do_popcnt,
408 datalen => e_in.data_len,
409 result => countbits_result
410 );
411
412 multiply_0: entity work.multiply
413 port map (
414 clk => clk,
415 m_in => x_to_multiply,
416 m_out => multiply_to_x
417 );
418
419 mult_32s_0: entity work.multiply_32s
420 port map (
421 clk => clk,
422 stall => stage2_stall,
423 m_in => x_to_mult_32s,
424 m_out => mult_32s_to_x
425 );
426
427 divider_0: if not HAS_FPU generate
428 div_0: entity work.divider
429 port map (
430 clk => clk,
431 rst => rst,
432 d_in => x_to_divider,
433 d_out => divider_to_x
434 );
435 end generate;
436
437 random_0: entity work.random
438 port map (
439 clk => clk,
440 data => random_cond,
441 raw => random_raw,
442 err => random_err
443 );
444
445 pmu_0: entity work.pmu
446 port map (
447 clk => clk,
448 rst => rst,
449 p_in => x_to_pmu,
450 p_out => pmu_to_x
451 );
452
453 dbg_ctrl_out <= ctrl;
454 log_rd_addr <= ex2.log_addr_spr;
455
456 a_in <= e_in.read_data1;
457 b_in <= e_in.read_data2;
458 c_in <= e_in.read_data3;
459 cr_in <= e_in.cr;
460
461 x_to_pmu.occur <= (instr_complete => wb_events.instr_complete,
462 fp_complete => wb_events.fp_complete,
463 ld_complete => ls_events.load_complete,
464 st_complete => ls_events.store_complete,
465 itlb_miss => ls_events.itlb_miss,
466 dc_load_miss => dc_events.load_miss,
467 dc_ld_miss_resolved => dc_events.dcache_refill,
468 dc_store_miss => dc_events.store_miss,
469 dtlb_miss => dc_events.dtlb_miss,
470 dtlb_miss_resolved => dc_events.dtlb_miss_resolved,
471 icache_miss => ic_events.icache_miss,
472 itlb_miss_resolved => ic_events.itlb_miss_resolved,
473 no_instr_avail => ex1.no_instr_avail,
474 dispatch => ex1.instr_dispatch,
475 ext_interrupt => ex2.ext_interrupt,
476 br_taken_complete => ex2.taken_branch_event,
477 br_mispredict => ex2.br_mispredict,
478 others => '0');
479 x_to_pmu.nia <= e_in.nia;
480 x_to_pmu.addr <= (others => '0');
481 x_to_pmu.addr_v <= '0';
482 x_to_pmu.spr_num <= ex1.pmu_spr_num;
483 x_to_pmu.spr_val <= ex1.e.write_data;
484 x_to_pmu.run <= '1';
485
486 -- XER forwarding. The CA and CA32 bits are only modified by instructions
487 -- that are handled here, so for them we can just use the result most
488 -- recently sent to writeback, unless a pipeline flush has happened in the
489 -- meantime.
490 -- Hazards for SO/OV/OV32 are handled by control.vhdl as there may be other
491 -- units writing to them. No forwarding is done because performance of
492 -- instructions that alter them is not considered significant.
493 xerc_in.so <= e_in.xerc.so;
494 xerc_in.ov <= e_in.xerc.ov;
495 xerc_in.ov32 <= e_in.xerc.ov32;
496 xerc_in.ca <= ex1.xerc.ca when ex1.xerc_valid = '1' else e_in.xerc.ca;
497 xerc_in.ca32 <= ex1.xerc.ca32 when ex1.xerc_valid = '1' else e_in.xerc.ca32;
498
499 -- N.B. the busy signal from each source includes the
500 -- stage2 stall from that source in it.
501 busy_out <= l_in.busy or ex1.busy or fp_in.busy;
502
503 valid_in <= e_in.valid and not (busy_out or flush_in or ex1.e.redirect or ex1.e.interrupt);
504
505 -- SPRs stored in two small RAM arrays (two so that we can read and write
506 -- two SPRs in each cycle).
507
508 ramspr_read: process(all)
509 variable even_rd_data, odd_rd_data : std_ulogic_vector(63 downto 0);
510 variable wr_addr : ramspr_index;
511 variable even_wr_enab, odd_wr_enab : std_ulogic;
512 variable even_wr_data, odd_wr_data : std_ulogic_vector(63 downto 0);
513 variable doit : std_ulogic;
514 begin
515 -- Read address mux and async RAM reading
516 if is_X(e_in.ramspr_even_rdaddr) then
517 even_rd_data := (others => 'X');
518 else
519 even_rd_data := even_sprs(to_integer(e_in.ramspr_even_rdaddr));
520 end if;
521 if is_X(e_in.ramspr_even_rdaddr) then
522 odd_rd_data := (others => 'X');
523 else
524 odd_rd_data := odd_sprs(to_integer(e_in.ramspr_odd_rdaddr));
525 end if;
526
527 -- Write address and data muxes
528 doit := ex1.e.valid and not stage2_stall and not flush_in;
529 even_wr_enab := (ex1.se.ramspr_write_even and doit) or interrupt_in.intr;
530 odd_wr_enab := (ex1.se.ramspr_write_odd and doit) or interrupt_in.intr;
531 if interrupt_in.intr = '1' then
532 wr_addr := RAMSPR_SRR0;
533 else
534 wr_addr := ex1.ramspr_wraddr;
535 end if;
536 if interrupt_in.intr = '1' then
537 even_wr_data := ex2.e.last_nia;
538 odd_wr_data := intr_srr1(ctrl.msr, interrupt_in.srr1);
539 else
540 even_wr_data := ex1.e.write_data;
541 odd_wr_data := ex1.ramspr_odd_data;
542 end if;
543 ramspr_wr_addr <= wr_addr;
544 ramspr_even_wr_data <= even_wr_data;
545 ramspr_even_wr_enab <= even_wr_enab;
546 ramspr_odd_wr_data <= odd_wr_data;
547 ramspr_odd_wr_enab <= odd_wr_enab;
548
549 -- SPR RAM read with write data bypass
550 -- We assume no instruction executes in the cycle immediately following
551 -- an interrupt, so we don't need to bypass interrupt data
552 if ex1.se.ramspr_write_even = '1' and e_in.ramspr_even_rdaddr = ex1.ramspr_wraddr then
553 ramspr_even <= ex1.e.write_data;
554 else
555 ramspr_even <= even_rd_data;
556 end if;
557 if ex1.se.ramspr_write_odd = '1' and e_in.ramspr_odd_rdaddr = ex1.ramspr_wraddr then
558 ramspr_odd <= ex1.ramspr_odd_data;
559 else
560 ramspr_odd <= odd_rd_data;
561 end if;
562 if e_in.ramspr_rd_odd = '0' then
563 ramspr_result <= ramspr_even;
564 else
565 ramspr_result <= ramspr_odd;
566 end if;
567 end process;
568
569 ramspr_write: process(clk)
570 begin
571 if rising_edge(clk) then
572 if ramspr_even_wr_enab = '1' then
573 assert not is_X(ramspr_wr_addr) report "Writing to unknown address" severity FAILURE;
574 even_sprs(to_integer(ramspr_wr_addr)) <= ramspr_even_wr_data;
575 report "writing even spr " & integer'image(to_integer(ramspr_wr_addr)) & " data=" &
576 to_hstring(ramspr_even_wr_data);
577 end if;
578 if ramspr_odd_wr_enab = '1' then
579 assert not is_X(ramspr_wr_addr) report "Writing to unknown address" severity FAILURE;
580 odd_sprs(to_integer(ramspr_wr_addr)) <= ramspr_odd_wr_data;
581 report "writing odd spr " & integer'image(to_integer(ramspr_wr_addr)) & " data=" &
582 to_hstring(ramspr_odd_wr_data);
583 end if;
584 end if;
585 end process;
586
587 -- First stage result mux
588 s1_sel <= e_in.result_sel when ex1.busy = '0' else "100";
589 with s1_sel select alu_result <=
590 adder_result when "000",
591 logical_result when "001",
592 rotator_result when "010",
593 shortmul_result when "011",
594 muldiv_result when "100",
595 ramspr_result when "101",
596 next_nia when "110",
597 misc_result when others;
598
599 execute1_0: process(clk)
600 begin
601 if rising_edge(clk) then
602 if rst = '1' then
603 ex1 <= reg_stage1_type_init;
604 ex2 <= reg_stage2_type_init;
605 ctrl <= ctrl_t_init;
606 ctrl.msr <= (MSR_SF => '1', MSR_LE => '1', others => '0');
607 ex1.msr <= (MSR_SF => '1', MSR_LE => '1', others => '0');
608 else
609 ex1 <= ex1in;
610 ex2 <= ex2in;
611 ctrl <= ctrl_tmp;
612 if valid_in = '1' then
613 report "execute " & to_hstring(e_in.nia) & " op=" & insn_type_t'image(e_in.insn_type) &
614 " wr=" & to_hstring(ex1in.e.write_reg) & " we=" & std_ulogic'image(ex1in.e.write_enable) &
615 " tag=" & integer'image(ex1in.e.instr_tag.tag) & std_ulogic'image(ex1in.e.instr_tag.valid);
616 end if;
617 -- We mustn't get stalled on a cycle where execute2 is
618 -- completing an instruction or generating an interrupt
619 if ex2.e.valid = '1' or ex2.e.interrupt = '1' then
620 assert stage2_stall = '0' severity failure;
621 end if;
622 end if;
623 end if;
624 end process;
625
626 ex_dbg_spr: process(clk)
627 begin
628 if rising_edge(clk) then
629 if rst = '0' and dbg_spr_req = '1' then
630 if e_in.dbg_spr_access = '1' and dbg_spr_ack = '0' then
631 if dbg_spr_addr(7) = '1' then
632 dbg_spr_data <= ramspr_result;
633 else
634 dbg_spr_data <= assemble_xer(xerc_in, ctrl.xer_low);
635 end if;
636 dbg_spr_ack <= '1';
637 end if;
638 else
639 dbg_spr_ack <= '0';
640 end if;
641 end if;
642 end process;
643
644 -- Data path for integer instructions (first execute stage)
645 execute1_dp: process(all)
646 variable a_inv : std_ulogic_vector(63 downto 0);
647 variable sum_with_carry : std_ulogic_vector(64 downto 0);
648 variable sign1, sign2 : std_ulogic;
649 variable abs1, abs2 : signed(63 downto 0);
650 variable addend : std_ulogic_vector(127 downto 0);
651 variable addg6s : std_ulogic_vector(63 downto 0);
652 variable crbit : integer range 0 to 31;
653 variable isel_result : std_ulogic_vector(63 downto 0);
654 variable darn : std_ulogic_vector(63 downto 0);
655 variable setb_result : std_ulogic_vector(63 downto 0);
656 variable mfcr_result : std_ulogic_vector(63 downto 0);
657 variable lo, hi : integer;
658 variable l : std_ulogic;
659 variable zerohi, zerolo : std_ulogic;
660 variable msb_a, msb_b : std_ulogic;
661 variable a_lt : std_ulogic;
662 variable a_lt_lo : std_ulogic;
663 variable a_lt_hi : std_ulogic;
664 variable newcrf : std_ulogic_vector(3 downto 0);
665 variable bf, bfa : std_ulogic_vector(2 downto 0);
666 variable crnum : crnum_t;
667 variable scrnum : crnum_t;
668 variable cr_operands : std_ulogic_vector(1 downto 0);
669 variable crresult : std_ulogic;
670 variable bt, ba, bb : std_ulogic_vector(4 downto 0);
671 variable btnum : integer range 0 to 3;
672 variable banum, bbnum : integer range 0 to 31;
673 variable j : integer;
674 begin
675 -- Main adder
676 if e_in.invert_a = '0' then
677 a_inv := a_in;
678 else
679 a_inv := not a_in;
680 end if;
681 sum_with_carry := ppc_adde(a_inv, b_in,
682 decode_input_carry(e_in.input_carry, xerc_in));
683 adder_result <= sum_with_carry(63 downto 0);
684 carry_32 <= sum_with_carry(32) xor a_inv(32) xor b_in(32);
685 carry_64 <= sum_with_carry(64);
686 overflow_32 <= calc_ov(a_inv(31), b_in(31), carry_32, sum_with_carry(31));
687 overflow_64 <= calc_ov(a_inv(63), b_in(63), carry_64, sum_with_carry(63));
688
689 -- signals to multiplier
690 addend := (others => '0');
691 if e_in.reg_valid3 = '1' then
692 -- integer multiply-add, major op 4 (if it is a multiply)
693 addend(63 downto 0) := c_in;
694 if e_in.is_signed = '1' then
695 addend(127 downto 64) := (others => c_in(63));
696 end if;
697 end if;
698 x_to_multiply.data1 <= std_ulogic_vector(a_in);
699 x_to_multiply.data2 <= std_ulogic_vector(b_in);
700 x_to_multiply.is_signed <= e_in.is_signed;
701 x_to_multiply.subtract <= '0';
702 x_to_multiply.addend <= addend;
703
704 -- Interface to divide unit
705 if not HAS_FPU then
706 sign1 := '0';
707 sign2 := '0';
708 if e_in.is_signed = '1' then
709 if e_in.is_32bit = '1' then
710 sign1 := a_in(31);
711 sign2 := b_in(31);
712 else
713 sign1 := a_in(63);
714 sign2 := b_in(63);
715 end if;
716 end if;
717 -- take absolute values
718 if sign1 = '0' then
719 abs1 := signed(a_in);
720 else
721 abs1 := - signed(a_in);
722 end if;
723 if sign2 = '0' then
724 abs2 := signed(b_in);
725 else
726 abs2 := - signed(b_in);
727 end if;
728
729 x_to_divider.is_signed <= e_in.is_signed;
730 x_to_divider.is_32bit <= e_in.is_32bit;
731 x_to_divider.is_extended <= '0';
732 x_to_divider.is_modulus <= '0';
733 if e_in.insn_type = OP_MOD then
734 x_to_divider.is_modulus <= '1';
735 end if;
736 x_to_divider.flush <= flush_in;
737 x_to_divider.neg_result <= sign1 xor (sign2 and not x_to_divider.is_modulus);
738 if e_in.is_32bit = '0' then
739 -- 64-bit forms
740 if e_in.insn_type = OP_DIVE then
741 x_to_divider.is_extended <= '1';
742 end if;
743 x_to_divider.dividend <= std_ulogic_vector(abs1);
744 x_to_divider.divisor <= std_ulogic_vector(abs2);
745 else
746 -- 32-bit forms
747 x_to_divider.is_extended <= '0';
748 if e_in.insn_type = OP_DIVE then -- extended forms
749 x_to_divider.dividend <= std_ulogic_vector(abs1(31 downto 0)) & x"00000000";
750 else
751 x_to_divider.dividend <= x"00000000" & std_ulogic_vector(abs1(31 downto 0));
752 end if;
753 x_to_divider.divisor <= x"00000000" & std_ulogic_vector(abs2(31 downto 0));
754 end if;
755 end if;
756
757 -- signals to 32-bit multiplier
758 x_to_mult_32s.data1 <= 32x"0" & a_in(31 downto 0);
759 x_to_mult_32s.data2 <= 32x"0" & b_in(31 downto 0);
760 x_to_mult_32s.is_signed <= e_in.is_signed;
761 -- The following are unused, but set here to avoid X states
762 x_to_mult_32s.subtract <= '0';
763 x_to_mult_32s.addend <= (others => '0');
764
765 shortmul_result <= std_ulogic_vector(resize(signed(mshort_p), 64));
766 case ex1.mul_select is
767 when "00" =>
768 muldiv_result <= multiply_to_x.result(63 downto 0);
769 when "01" =>
770 muldiv_result <= multiply_to_x.result(127 downto 64);
771 when "10" =>
772 muldiv_result <= multiply_to_x.result(63 downto 32) &
773 multiply_to_x.result(63 downto 32);
774 when others =>
775 muldiv_result <= divider_to_x.write_reg_data;
776 end case;
777
778 -- Compute misc_result
779 case e_in.sub_select is
780 when "000" =>
781 misc_result <= (others => '0');
782 when "001" =>
783 -- addg6s
784 addg6s := (others => '0');
785 for i in 0 to 14 loop
786 lo := i * 4;
787 hi := (i + 1) * 4;
788 if (a_in(hi) xor b_in(hi) xor sum_with_carry(hi)) = '0' then
789 addg6s(lo + 3 downto lo) := "0110";
790 end if;
791 end loop;
792 if sum_with_carry(64) = '0' then
793 addg6s(63 downto 60) := "0110";
794 end if;
795 misc_result <= addg6s;
796 when "010" =>
797 -- isel
798 crbit := to_integer(unsigned(insn_bc(e_in.insn)));
799 if cr_in(31-crbit) = '1' then
800 isel_result := a_in;
801 else
802 isel_result := b_in;
803 end if;
804 misc_result <= isel_result;
805 when "011" =>
806 -- darn
807 darn := (others => '1');
808 if random_err = '0' then
809 case e_in.insn(17 downto 16) is
810 when "00" =>
811 darn := x"00000000" & random_cond(31 downto 0);
812 when "10" =>
813 darn := random_raw;
814 when others =>
815 darn := random_cond;
816 end case;
817 end if;
818 misc_result <= darn;
819 when "100" =>
820 -- mfmsr
821 misc_result <= ex1.msr;
822 when "101" =>
823 if e_in.insn(20) = '0' then
824 -- mfcr
825 mfcr_result := x"00000000" & cr_in;
826 else
827 -- mfocrf
828 crnum := fxm_to_num(insn_fxm(e_in.insn));
829 mfcr_result := (others => '0');
830 for i in 0 to 7 loop
831 lo := (7-i)*4;
832 hi := lo + 3;
833 if crnum = i then
834 mfcr_result(hi downto lo) := cr_in(hi downto lo);
835 end if;
836 end loop;
837 end if;
838 misc_result <= mfcr_result;
839 when "110" =>
840 -- setb and set[n]bc[r]
841 setb_result := (others => '0');
842 if e_in.insn(9) = '0' then
843 -- setb
844 bfa := insn_bfa(e_in.insn);
845 crbit := to_integer(unsigned(bfa)) * 4;
846 if cr_in(31 - crbit) = '1' then
847 setb_result := (others => '1');
848 elsif cr_in(30 - crbit) = '1' then
849 setb_result(0) := '1';
850 end if;
851 else
852 -- set[n]bc[r]
853 crbit := to_integer(unsigned(insn_bi(e_in.insn)));
854 if (cr_in(31 - crbit) xor e_in.insn(6)) = '1' then
855 if e_in.insn(7) = '0' then
856 setb_result(0) := '1';
857 else
858 setb_result := (others => '1');
859 end if;
860 end if;
861 end if;
862 misc_result <= setb_result;
863 when others =>
864 misc_result <= (others => '0');
865 end case;
866
867 -- compute comparison results
868 -- Note, we have done RB - RA, not RA - RB
869 if e_in.insn_type = OP_CMP then
870 l := insn_l(e_in.insn);
871 else
872 l := not e_in.is_32bit;
873 end if;
874 zerolo := not (or (a_in(31 downto 0) xor b_in(31 downto 0)));
875 zerohi := not (or (a_in(63 downto 32) xor b_in(63 downto 32)));
876 if zerolo = '1' and (l = '0' or zerohi = '1') then
877 -- values are equal
878 trapval <= "00100";
879 else
880 a_lt_lo := '0';
881 a_lt_hi := '0';
882 if is_X(a_in) or is_X(b_in) then
883 a_lt_lo := 'X';
884 a_lt_hi := 'X';
885 else
886 if unsigned(a_in(30 downto 0)) < unsigned(b_in(30 downto 0)) then
887 a_lt_lo := '1';
888 end if;
889 if unsigned(a_in(62 downto 31)) < unsigned(b_in(62 downto 31)) then
890 a_lt_hi := '1';
891 end if;
892 end if;
893 if l = '1' then
894 -- 64-bit comparison
895 msb_a := a_in(63);
896 msb_b := b_in(63);
897 a_lt := a_lt_hi or (zerohi and (a_in(31) xnor b_in(31)) and a_lt_lo);
898 else
899 -- 32-bit comparison
900 msb_a := a_in(31);
901 msb_b := b_in(31);
902 a_lt := a_lt_lo;
903 end if;
904 if msb_a /= msb_b then
905 -- Comparison is clear from MSB difference.
906 -- for signed, 0 is greater; for unsigned, 1 is greater
907 trapval <= msb_a & msb_b & '0' & msb_b & msb_a;
908 else
909 -- MSBs are equal, so signed and unsigned comparisons give the
910 -- same answer.
911 trapval <= a_lt & not a_lt & '0' & a_lt & not a_lt;
912 end if;
913 end if;
914
915 -- CR result mux
916 bf := insn_bf(e_in.insn);
917 newcrf := (others => '0');
918 case e_in.sub_select is
919 when "000" =>
920 -- CMP and CMPL instructions
921 if e_in.is_signed = '1' then
922 newcrf := trapval(4 downto 2) & xerc_in.so;
923 else
924 newcrf := trapval(1 downto 0) & trapval(2) & xerc_in.so;
925 end if;
926 when "001" =>
927 newcrf := ppc_cmprb(a_in, b_in, insn_l(e_in.insn));
928 when "010" =>
929 newcrf := ppc_cmpeqb(a_in, b_in);
930 when "011" =>
931 if is_X(e_in.insn) then
932 newcrf := (others => 'X');
933 elsif e_in.insn(1) = '1' then
934 -- CR logical instructions
935 crnum := to_integer(unsigned(bf));
936 j := (7 - crnum) * 4;
937 newcrf := cr_in(j + 3 downto j);
938 bt := insn_bt(e_in.insn);
939 ba := insn_ba(e_in.insn);
940 bb := insn_bb(e_in.insn);
941 btnum := 3 - to_integer(unsigned(bt(1 downto 0)));
942 banum := 31 - to_integer(unsigned(ba));
943 bbnum := 31 - to_integer(unsigned(bb));
944 -- Bits 6-9 of the instruction word give the truth table
945 -- of the requested logical operation
946 cr_operands := cr_in(banum) & cr_in(bbnum);
947 crresult := e_in.insn(6 + to_integer(unsigned(cr_operands)));
948 for i in 0 to 3 loop
949 if i = btnum then
950 newcrf(i) := crresult;
951 end if;
952 end loop;
953 else
954 -- MCRF
955 bfa := insn_bfa(e_in.insn);
956 scrnum := to_integer(unsigned(bfa));
957 j := (7 - scrnum) * 4;
958 newcrf := cr_in(j + 3 downto j);
959 end if;
960 when "100" =>
961 -- MCRXRX
962 newcrf := xerc_in.ov & xerc_in.ov32 & xerc_in.ca & xerc_in.ca32;
963 when others =>
964 end case;
965 if e_in.insn_type = OP_MTCRF then
966 if e_in.insn(20) = '0' then
967 -- mtcrf
968 write_cr_mask <= insn_fxm(e_in.insn);
969 else
970 -- mtocrf: We require one hot priority encoding here
971 crnum := fxm_to_num(insn_fxm(e_in.insn));
972 write_cr_mask <= num_to_fxm(crnum);
973 end if;
974 elsif e_in.output_cr = '1' and not is_X(bf) then
975 crnum := to_integer(unsigned(bf));
976 write_cr_mask <= num_to_fxm(crnum);
977 else
978 write_cr_mask <= (others => '0');
979 end if;
980 for i in 0 to 7 loop
981 if write_cr_mask(i) = '0' then
982 write_cr_data(i*4 + 3 downto i*4) <= cr_in(i*4 + 3 downto i*4);
983 elsif e_in.insn_type = OP_MTCRF then
984 write_cr_data(i*4 + 3 downto i*4) <= c_in(i*4 + 3 downto i*4);
985 else
986 write_cr_data(i*4 + 3 downto i*4) <= newcrf;
987 end if;
988 end loop;
989
990 end process;
991
992 execute1_actions: process(all)
993 variable v: actions_type;
994 variable bo, bi : std_ulogic_vector(4 downto 0);
995 variable illegal : std_ulogic;
996 variable privileged : std_ulogic;
997 variable misaligned : std_ulogic;
998 variable slow_op : std_ulogic;
999 variable owait : std_ulogic;
1000 variable srr1 : std_ulogic_vector(63 downto 0);
1001 begin
1002 v := actions_type_init;
1003 v.e.write_data := alu_result;
1004 v.e.write_reg := e_in.write_reg;
1005 v.e.write_enable := e_in.write_reg_enable;
1006 v.e.rc := e_in.rc;
1007 v.e.write_cr_data := write_cr_data;
1008 v.e.write_cr_mask := write_cr_mask;
1009 v.e.write_cr_enable := e_in.output_cr;
1010 v.e.write_xerc_enable := e_in.output_xer;
1011 v.e.xerc := xerc_in;
1012 v.new_msr := ex1.msr;
1013 v.e.redir_mode := ex1.msr(MSR_IR) & not ex1.msr(MSR_PR) &
1014 not ex1.msr(MSR_LE) & not ex1.msr(MSR_SF);
1015 v.e.intr_vec := 16#700#;
1016 v.e.mode_32bit := not ex1.msr(MSR_SF);
1017 v.e.instr_tag := e_in.instr_tag;
1018 v.e.last_nia := e_in.nia;
1019 v.e.br_offset := 64x"4";
1020
1021 v.se.ramspr_write_even := e_in.ramspr_write_even;
1022 v.se.ramspr_write_odd := e_in.ramspr_write_odd;
1023 v.ramspr_odd_data := c_in;
1024 if e_in.dec_ctr = '1' then
1025 v.ramspr_odd_data := std_ulogic_vector(unsigned(ramspr_odd) - 1);
1026 end if;
1027
1028 -- Note the difference between v.exception and v.trap:
1029 -- v.exception signals a condition that prevents execution of the
1030 -- instruction, and hence shouldn't depend on operand data, so as to
1031 -- avoid timing chains through both data and control paths.
1032 -- v.trap also means we want to generate an interrupt, but doesn't
1033 -- cancel instruction execution (hence we need to avoid setting any
1034 -- side-effect flags or write enables when generating a trap).
1035 -- With v.trap = 1 we will assert both ex1.e.valid and ex1.e.interrupt
1036 -- to writeback, and it will complete the instruction and take
1037 -- and interrupt. It is OK for v.trap to depend on operand data.
1038
1039 illegal := '0';
1040 privileged := '0';
1041 misaligned := e_in.misaligned_prefix;
1042 slow_op := '0';
1043 owait := '0';
1044
1045 if e_in.illegal_suffix = '1' then
1046 illegal := '1';
1047 elsif ex1.msr(MSR_PR) = '1' and instr_is_privileged(e_in.insn_type, e_in.insn) then
1048 privileged := '1';
1049 end if;
1050
1051 v.do_trace := ex1.msr(MSR_SE);
1052 case_0: case e_in.insn_type is
1053 when OP_ILLEGAL =>
1054 illegal := '1';
1055 when OP_SC =>
1056 -- check bit 1 of the instruction is 1 so we know this is sc;
1057 -- 0 would mean scv, so generate an illegal instruction interrupt
1058 if e_in.insn(1) = '1' then
1059 v.trap := '1';
1060 v.advance_nia := '1';
1061 v.e.intr_vec := 16#C00#;
1062 if e_in.valid = '1' then
1063 report "sc";
1064 end if;
1065 else
1066 illegal := '1';
1067 end if;
1068 when OP_ATTN =>
1069 -- check bits 1-10 of the instruction to make sure it's attn
1070 -- if not then it is illegal
1071 if e_in.insn(10 downto 1) = "0100000000" then
1072 v.se.terminate := '1';
1073 if e_in.valid = '1' then
1074 report "ATTN";
1075 end if;
1076 else
1077 illegal := '1';
1078 end if;
1079 when OP_NOP | OP_DCBF | OP_DCBST | OP_DCBT | OP_DCBTST | OP_ICBT =>
1080 -- Do nothing
1081 when OP_ADD =>
1082 if e_in.output_carry = '1' then
1083 if e_in.input_carry /= OV then
1084 set_carry(v.e, carry_32, carry_64);
1085 else
1086 v.e.xerc.ov := carry_64;
1087 v.e.xerc.ov32 := carry_32;
1088 end if;
1089 end if;
1090 if e_in.oe = '1' then
1091 set_ov(v.e, overflow_64, overflow_32);
1092 end if;
1093 when OP_CMP =>
1094 when OP_TRAP =>
1095 -- trap instructions (tw, twi, td, tdi)
1096 v.e.intr_vec := 16#700#;
1097 -- set bit 46 to say trap occurred
1098 v.e.srr1(47 - 46) := '1';
1099 if or (trapval and insn_to(e_in.insn)) = '1' then
1100 -- generate trap-type program interrupt
1101 v.trap := '1';
1102 if e_in.valid = '1' then
1103 report "trap";
1104 end if;
1105 end if;
1106 when OP_ADDG6S =>
1107 when OP_CMPRB =>
1108 when OP_CMPEQB =>
1109 when OP_LOGIC | OP_XOR | OP_PRTY | OP_CMPB | OP_EXTS |
1110 OP_BPERM | OP_BREV | OP_BCD =>
1111
1112 when OP_B =>
1113 v.take_branch := '1';
1114 v.direct_branch := '1';
1115 v.e.br_last := '1';
1116 v.e.br_taken := '1';
1117 v.e.br_offset := b_in;
1118 v.e.abs_br := insn_aa(e_in.insn);
1119 if e_in.br_pred = '0' then
1120 -- should never happen
1121 v.e.redirect := '1';
1122 end if;
1123 if ex1.msr(MSR_BE) = '1' then
1124 v.do_trace := '1';
1125 end if;
1126 v.se.write_cfar := '1';
1127 when OP_BC =>
1128 -- If CTR is being decremented, it is in ramspr_odd.
1129 bo := insn_bo(e_in.insn);
1130 bi := insn_bi(e_in.insn);
1131 v.take_branch := ppc_bc_taken(bo, bi, cr_in, ramspr_odd);
1132 if v.take_branch = '1' then
1133 v.e.br_offset := b_in;
1134 v.e.abs_br := insn_aa(e_in.insn);
1135 end if;
1136 -- Mispredicted branches cause a redirect
1137 if v.take_branch /= e_in.br_pred then
1138 v.e.redirect := '1';
1139 end if;
1140 v.direct_branch := '1';
1141 v.e.br_last := '1';
1142 v.e.br_taken := v.take_branch;
1143 if ex1.msr(MSR_BE) = '1' then
1144 v.do_trace := '1';
1145 end if;
1146 v.se.write_cfar := v.take_branch;
1147 when OP_BCREG =>
1148 -- If CTR is being decremented, it is in ramspr_odd.
1149 -- The target address is in ramspr_result (LR, CTR or TAR).
1150 bo := insn_bo(e_in.insn);
1151 bi := insn_bi(e_in.insn);
1152 v.take_branch := ppc_bc_taken(bo, bi, cr_in, ramspr_odd);
1153 if v.take_branch = '1' then
1154 v.e.br_offset := ramspr_result;
1155 v.e.abs_br := '1';
1156 end if;
1157 -- Indirect branches are never predicted taken
1158 v.e.redirect := v.take_branch;
1159 v.e.br_taken := v.take_branch;
1160 if ex1.msr(MSR_BE) = '1' then
1161 v.do_trace := '1';
1162 end if;
1163 v.se.write_cfar := v.take_branch;
1164
1165 when OP_RFID =>
1166 srr1 := ramspr_odd;
1167 v.e.redir_mode := (srr1(MSR_IR) or srr1(MSR_PR)) & not srr1(MSR_PR) &
1168 not srr1(MSR_LE) & not srr1(MSR_SF);
1169 -- Can't use msr_copy here because the partial function MSR
1170 -- bits should be left unchanged, not zeroed.
1171 v.new_msr(63 downto 31) := srr1(63 downto 31);
1172 v.new_msr(26 downto 22) := srr1(26 downto 22);
1173 v.new_msr(15 downto 0) := srr1(15 downto 0);
1174 if srr1(MSR_PR) = '1' then
1175 v.new_msr(MSR_EE) := '1';
1176 v.new_msr(MSR_IR) := '1';
1177 v.new_msr(MSR_DR) := '1';
1178 end if;
1179 v.se.write_msr := '1';
1180 v.e.br_offset := ramspr_result;
1181 v.e.abs_br := '1';
1182 v.e.redirect := '1';
1183 v.se.write_cfar := '1';
1184 if HAS_FPU then
1185 v.fp_intr := fp_in.exception and
1186 (srr1(MSR_FE0) or srr1(MSR_FE1));
1187 end if;
1188 v.do_trace := '0';
1189
1190 when OP_CNTZ | OP_POPCNT =>
1191 v.res2_sel := "01";
1192 slow_op := '1';
1193 when OP_ISEL =>
1194 when OP_CROP =>
1195 when OP_MCRXRX =>
1196 when OP_DARN =>
1197 when OP_MFMSR =>
1198 when OP_MFSPR =>
1199 if e_in.spr_is_ram = '1' then
1200 if e_in.valid = '1' and not is_X(e_in.insn) then
1201 report "MFSPR to SPR " & integer'image(decode_spr_num(e_in.insn)) &
1202 "=" & to_hstring(alu_result);
1203 end if;
1204 elsif e_in.spr_select.valid = '1' then
1205 if e_in.valid = '1' and not is_X(e_in.insn) then
1206 report "MFSPR to slow SPR " & integer'image(decode_spr_num(e_in.insn));
1207 end if;
1208 slow_op := '1';
1209 if e_in.spr_select.ispmu = '0' then
1210 case e_in.spr_select.sel is
1211 when SPRSEL_LOGD =>
1212 v.se.inc_loga := '1';
1213 when others =>
1214 end case;
1215 v.res2_sel := "10";
1216 else
1217 v.res2_sel := "11";
1218 end if;
1219 else
1220 -- mfspr from unimplemented SPRs should be a nop in
1221 -- supervisor mode and a program interrupt for user mode
1222 if e_in.valid = '1' and not is_X(e_in.insn) then
1223 report "MFSPR to SPR " & integer'image(decode_spr_num(e_in.insn)) &
1224 " invalid";
1225 end if;
1226 if ex1.msr(MSR_PR) = '1' then
1227 illegal := '1';
1228 end if;
1229 end if;
1230
1231 when OP_MFCR =>
1232 when OP_MTCRF =>
1233 when OP_MTMSRD =>
1234 v.se.write_msr := '1';
1235 if e_in.insn(16) = '1' then
1236 -- just update EE and RI
1237 v.new_msr(MSR_EE) := c_in(MSR_EE);
1238 v.new_msr(MSR_RI) := c_in(MSR_RI);
1239 else
1240 -- Architecture says to leave out bits 3 (HV), 51 (ME)
1241 -- and 63 (LE) (IBM bit numbering)
1242 if e_in.is_32bit = '0' then
1243 v.new_msr(63 downto 61) := c_in(63 downto 61);
1244 v.new_msr(59 downto 32) := c_in(59 downto 32);
1245 end if;
1246 v.new_msr(31 downto 13) := c_in(31 downto 13);
1247 v.new_msr(11 downto 1) := c_in(11 downto 1);
1248 if c_in(MSR_PR) = '1' then
1249 v.new_msr(MSR_EE) := '1';
1250 v.new_msr(MSR_IR) := '1';
1251 v.new_msr(MSR_DR) := '1';
1252 end if;
1253 if HAS_FPU then
1254 v.fp_intr := fp_in.exception and
1255 (c_in(MSR_FE0) or c_in(MSR_FE1));
1256 end if;
1257 end if;
1258 when OP_MTSPR =>
1259 if e_in.valid = '1' and not is_X(e_in.insn) then
1260 report "MTSPR to SPR " & integer'image(decode_spr_num(e_in.insn)) &
1261 "=" & to_hstring(c_in);
1262 end if;
1263 v.se.write_pmuspr := e_in.spr_select.ispmu;
1264 if e_in.spr_select.valid = '1' and e_in.spr_select.ispmu = '0' then
1265 case e_in.spr_select.sel is
1266 when SPRSEL_XER =>
1267 v.e.xerc.so := c_in(63-32);
1268 v.e.xerc.ov := c_in(63-33);
1269 v.e.xerc.ca := c_in(63-34);
1270 v.e.xerc.ov32 := c_in(63-44);
1271 v.e.xerc.ca32 := c_in(63-45);
1272 v.se.write_xerlow := '1';
1273 when SPRSEL_DEC =>
1274 v.se.write_dec := '1';
1275 when SPRSEL_LOGA =>
1276 v.se.write_loga := '1';
1277 when others =>
1278 end case;
1279 end if;
1280 if e_in.spr_select.valid = '0' and e_in.spr_is_ram = '0' then
1281 -- mtspr to unimplemented SPRs should be a nop in
1282 -- supervisor mode and a program interrupt for user mode
1283 if ex1.msr(MSR_PR) = '1' then
1284 illegal := '1';
1285 end if;
1286 end if;
1287 when OP_RLC | OP_RLCL | OP_RLCR | OP_SHL | OP_SHR | OP_EXTSWSLI =>
1288 if e_in.output_carry = '1' then
1289 set_carry(v.e, rotator_carry, rotator_carry);
1290 end if;
1291 when OP_SETB =>
1292
1293 when OP_ISYNC =>
1294 v.e.redirect := '1';
1295
1296 when OP_ICBI =>
1297 v.se.icache_inval := '1';
1298
1299 when OP_MUL_L64 =>
1300 if e_in.is_32bit = '1' then
1301 v.se.mult_32s := '1';
1302 v.res2_sel := "00";
1303 slow_op := '1';
1304 else
1305 -- Use standard multiplier
1306 v.start_mul := '1';
1307 slow_op := '1';
1308 owait := '1';
1309 end if;
1310
1311 when OP_MUL_H64 =>
1312 v.start_mul := '1';
1313 slow_op := '1';
1314 owait := '1';
1315
1316 when OP_MUL_H32 =>
1317 v.se.mult_32s := '1';
1318 v.res2_sel := "01";
1319 slow_op := '1';
1320
1321 when OP_DIV | OP_DIVE | OP_MOD =>
1322 if not HAS_FPU then
1323 v.start_div := '1';
1324 slow_op := '1';
1325 owait := '1';
1326 end if;
1327
1328 when OP_FETCH_FAILED =>
1329 -- Handling an ITLB miss doesn't count as having executed an instruction
1330 v.do_trace := '0';
1331
1332 when others =>
1333 if e_in.valid = '1' and e_in.unit = ALU then
1334 report "unhandled insn_type " & insn_type_t'image(e_in.insn_type);
1335 end if;
1336 end case;
1337
1338 if misaligned = '1' then
1339 -- generate an alignment interrupt
1340 -- This is higher priority than illegal because a misaligned
1341 -- prefix will come down as an OP_ILLEGAL instruction.
1342 v.exception := '1';
1343 v.e.intr_vec := 16#600#;
1344 v.e.srr1(47 - 35) := '1';
1345 v.e.srr1(47 - 34) := '1';
1346 if e_in.valid = '1' then
1347 report "misaligned prefixed instruction interrupt";
1348 end if;
1349
1350 elsif privileged = '1' then
1351 -- generate a program interrupt
1352 v.exception := '1';
1353 v.e.srr1(47 - 34) := e_in.prefixed;
1354 -- set bit 45 to indicate privileged instruction type interrupt
1355 v.e.srr1(47 - 45) := '1';
1356 if e_in.valid = '1' then
1357 report "privileged instruction";
1358 end if;
1359
1360 elsif illegal = '1' then
1361 v.exception := '1';
1362 v.e.srr1(47 - 34) := e_in.prefixed;
1363 -- Since we aren't doing Hypervisor emulation assist (0xe40) we
1364 -- set bit 44 to indicate we have an illegal
1365 v.e.srr1(47 - 44) := '1';
1366 if e_in.valid = '1' then
1367 report "illegal instruction";
1368 end if;
1369
1370 elsif HAS_FPU and ex1.msr(MSR_FP) = '0' and e_in.fac = FPU then
1371 -- generate a floating-point unavailable interrupt
1372 v.exception := '1';
1373 v.e.srr1(47 - 34) := e_in.prefixed;
1374 v.e.intr_vec := 16#800#;
1375 if e_in.valid = '1' then
1376 report "FP unavailable interrupt";
1377 end if;
1378 end if;
1379
1380 if e_in.unit = ALU then
1381 v.complete := e_in.valid and not v.exception and not owait;
1382 v.bypass_valid := e_in.valid and not v.exception and not slow_op;
1383 end if;
1384
1385 actions <= v;
1386 end process;
1387
1388 -- First execute stage
1389 execute1_1: process(all)
1390 variable v : reg_stage1_type;
1391 variable overflow : std_ulogic;
1392 variable lv : Execute1ToLoadstore1Type;
1393 variable irq_valid : std_ulogic;
1394 variable exception : std_ulogic;
1395 variable fv : Execute1ToFPUType;
1396 variable go : std_ulogic;
1397 variable bypass_valid : std_ulogic;
1398 begin
1399 v := ex1;
1400 if (ex1.busy or l_in.busy or fp_in.busy) = '0' then
1401 v.e := actions.e;
1402 v.e.valid := '0';
1403 v.oe := e_in.oe;
1404 v.spr_select := e_in.spr_select;
1405 v.pmu_spr_num := e_in.insn(20 downto 16);
1406 v.mul_select := e_in.sub_select(1 downto 0);
1407 v.se := side_effect_init;
1408 v.ramspr_wraddr := e_in.ramspr_wraddr;
1409 v.ramspr_odd_data := actions.ramspr_odd_data;
1410 end if;
1411
1412 lv := Execute1ToLoadstore1Init;
1413 fv := Execute1ToFPUInit;
1414
1415 x_to_multiply.valid <= '0';
1416 x_to_mult_32s.valid <= '0';
1417 x_to_divider.valid <= '0';
1418 v.ext_interrupt := '0';
1419 v.taken_branch_event := '0';
1420 v.br_mispredict := '0';
1421 v.busy := '0';
1422 bypass_valid := '0';
1423
1424 irq_valid := ex1.msr(MSR_EE) and (pmu_to_x.intr or ctrl.dec(63) or ext_irq_in);
1425
1426 -- Next insn adder used in a couple of places
1427 next_nia <= std_ulogic_vector(unsigned(e_in.nia) + 4);
1428
1429 -- rotator control signals
1430 right_shift <= '1' when e_in.insn_type = OP_SHR else '0';
1431 rot_clear_left <= '1' when e_in.insn_type = OP_RLC or e_in.insn_type = OP_RLCL else '0';
1432 rot_clear_right <= '1' when e_in.insn_type = OP_RLC or e_in.insn_type = OP_RLCR else '0';
1433 rot_sign_ext <= '1' when e_in.insn_type = OP_EXTSWSLI else '0';
1434
1435 do_popcnt <= '1' when e_in.insn_type = OP_POPCNT else '0';
1436
1437 if valid_in = '1' then
1438 v.prev_op := e_in.insn_type;
1439 v.prev_prefixed := e_in.prefixed;
1440 end if;
1441
1442 -- Determine if there is any interrupt to be taken
1443 -- before/instead of executing this instruction
1444 exception := valid_in and actions.exception;
1445 if valid_in = '1' and e_in.second = '0' then
1446 if HAS_FPU and ex1.fp_exception_next = '1' then
1447 -- This is used for FP-type program interrupts that
1448 -- become pending due to MSR[FE0,FE1] changing from 00 to non-zero.
1449 exception := '1';
1450 v.e.intr_vec := 16#700#;
1451 v.e.srr1 := (others => '0');
1452 v.e.srr1(47 - 43) := '1';
1453 v.e.srr1(47 - 47) := '1';
1454 elsif ex1.trace_next = '1' then
1455 -- Generate a trace interrupt rather than executing the next instruction
1456 -- or taking any asynchronous interrupt
1457 exception := '1';
1458 v.e.intr_vec := 16#d00#;
1459 v.e.srr1 := (others => '0');
1460 v.e.srr1(47 - 33) := '1';
1461 v.e.srr1(47 - 34) := ex1.prev_prefixed;
1462 if ex1.prev_op = OP_LOAD or ex1.prev_op = OP_ICBI or ex1.prev_op = OP_ICBT or
1463 ex1.prev_op = OP_DCBT or ex1.prev_op = OP_DCBST or ex1.prev_op = OP_DCBF then
1464 v.e.srr1(47 - 35) := '1';
1465 elsif ex1.prev_op = OP_STORE or ex1.prev_op = OP_DCBZ or
1466 ex1.prev_op = OP_DCBTST then
1467 v.e.srr1(47 - 36) := '1';
1468 end if;
1469
1470 elsif irq_valid = '1' then
1471 -- Don't deliver the interrupt until we have a valid instruction
1472 -- coming in, so we have a valid NIA to put in SRR0.
1473 if pmu_to_x.intr = '1' then
1474 v.e.intr_vec := 16#f00#;
1475 report "IRQ valid: PMU";
1476 elsif ctrl.dec(63) = '1' then
1477 v.e.intr_vec := 16#900#;
1478 report "IRQ valid: DEC";
1479 elsif ext_irq_in = '1' then
1480 v.e.intr_vec := 16#500#;
1481 report "IRQ valid: External";
1482 v.ext_interrupt := '1';
1483 end if;
1484 v.e.srr1 := (others => '0');
1485 exception := '1';
1486
1487 end if;
1488 end if;
1489
1490 v.no_instr_avail := not (e_in.valid or l_in.busy or ex1.busy or fp_in.busy);
1491
1492 go := valid_in and not exception;
1493 v.instr_dispatch := go;
1494
1495 if go = '1' then
1496 v.se := actions.se;
1497 v.e.valid := actions.complete;
1498 bypass_valid := actions.bypass_valid;
1499 v.taken_branch_event := actions.take_branch;
1500 v.trace_next := actions.do_trace;
1501 v.fp_exception_next := actions.fp_intr;
1502 v.res2_sel := actions.res2_sel;
1503 v.msr := actions.new_msr;
1504 x_to_multiply.valid <= actions.start_mul;
1505 x_to_mult_32s.valid <= actions.se.mult_32s;
1506 v.mul_in_progress := actions.start_mul;
1507 x_to_divider.valid <= actions.start_div;
1508 v.div_in_progress := actions.start_div;
1509 v.br_mispredict := v.e.redirect and actions.direct_branch;
1510 exception := actions.trap;
1511 if actions.advance_nia = '1' then
1512 v.e.last_nia := next_nia;
1513 end if;
1514
1515 -- Go busy while division is happening because the
1516 -- divider is not pipelined. Also go busy while a
1517 -- multiply is happening in order to stop following
1518 -- instructions from using the wrong XER value
1519 -- (and for simplicity in the OE=0 case).
1520 v.busy := actions.start_div or actions.start_mul;
1521
1522 -- instruction for other units, i.e. LDST
1523 if e_in.unit = LDST then
1524 lv.valid := '1';
1525 end if;
1526 if HAS_FPU and e_in.unit = FPU then
1527 fv.valid := '1';
1528 end if;
1529 end if;
1530
1531 if not HAS_FPU and ex1.div_in_progress = '1' then
1532 v.div_in_progress := not divider_to_x.valid;
1533 v.busy := not divider_to_x.valid;
1534 if divider_to_x.valid = '1' and ex1.oe = '1' then
1535 v.e.xerc.ov := divider_to_x.overflow;
1536 v.e.xerc.ov32 := divider_to_x.overflow;
1537 if divider_to_x.overflow = '1' then
1538 v.e.xerc.so := '1';
1539 end if;
1540 end if;
1541 v.e.valid := divider_to_x.valid;
1542 v.e.write_data := alu_result;
1543 bypass_valid := v.e.valid;
1544 end if;
1545 if ex1.mul_in_progress = '1' then
1546 v.mul_in_progress := not multiply_to_x.valid;
1547 v.mul_finish := multiply_to_x.valid and ex1.oe;
1548 v.e.valid := multiply_to_x.valid and not ex1.oe;
1549 v.busy := not v.e.valid;
1550 v.e.write_data := alu_result;
1551 bypass_valid := v.e.valid;
1552 end if;
1553 if ex1.mul_finish = '1' then
1554 v.mul_finish := '0';
1555 v.e.xerc.ov := multiply_to_x.overflow;
1556 v.e.xerc.ov32 := multiply_to_x.overflow;
1557 if multiply_to_x.overflow = '1' then
1558 v.e.xerc.so := '1';
1559 end if;
1560 v.e.valid := '1';
1561 end if;
1562
1563 if v.e.write_xerc_enable = '1' and v.e.valid = '1' then
1564 v.xerc := v.e.xerc;
1565 v.xerc_valid := '1';
1566 end if;
1567
1568 if (ex1.busy or l_in.busy or fp_in.busy) = '0' then
1569 v.e.interrupt := exception;
1570 end if;
1571 if v.e.valid = '0' then
1572 v.e.redirect := '0';
1573 v.e.br_last := '0';
1574 end if;
1575 if flush_in = '1' then
1576 v.e.valid := '0';
1577 v.e.interrupt := '0';
1578 v.e.redirect := '0';
1579 v.e.br_last := '0';
1580 v.busy := '0';
1581 v.div_in_progress := '0';
1582 v.mul_in_progress := '0';
1583 v.mul_finish := '0';
1584 v.xerc_valid := '0';
1585 end if;
1586 if flush_in = '1' or interrupt_in.intr = '1' then
1587 v.msr := ctrl_tmp.msr;
1588 end if;
1589 if interrupt_in.intr = '1' then
1590 v.trace_next := '0';
1591 v.fp_exception_next := '0';
1592 end if;
1593
1594 bypass_data.tag.valid <= v.e.write_enable and bypass_valid;
1595 bypass_data.tag.tag <= v.e.instr_tag.tag;
1596 bypass_data.data <= alu_result;
1597
1598 bypass_cr_data.tag.valid <= v.e.write_cr_enable and bypass_valid;
1599 bypass_cr_data.tag.tag <= v.e.instr_tag.tag;
1600 bypass_cr_data.data <= v.e.write_cr_data;
1601
1602 -- Outputs to loadstore1 (async)
1603 lv.op := e_in.insn_type;
1604 lv.instr_tag := e_in.instr_tag;
1605 lv.addr1 := a_in;
1606 lv.addr2 := b_in;
1607 lv.data := c_in;
1608 lv.write_reg := e_in.write_reg;
1609 lv.length := e_in.data_len;
1610 lv.byte_reverse := e_in.byte_reverse xnor ex1.msr(MSR_LE);
1611 lv.sign_extend := e_in.sign_extend;
1612 lv.update := e_in.update;
1613 lv.xerc := xerc_in;
1614 lv.reserve := e_in.reserve;
1615 lv.rc := e_in.rc;
1616 lv.insn := e_in.insn;
1617 -- invert_a field is overloaded for load/store instructions
1618 -- to mark l*cix and st*cix
1619 lv.ci := e_in.invert_a;
1620 lv.virt_mode := ex1.msr(MSR_DR);
1621 lv.priv_mode := not ex1.msr(MSR_PR);
1622 lv.mode_32bit := not ex1.msr(MSR_SF);
1623 lv.is_32bit := e_in.is_32bit;
1624 lv.prefixed := e_in.prefixed;
1625 lv.repeat := e_in.repeat;
1626 lv.second := e_in.second;
1627 lv.e2stall := fp_in.f2stall;
1628
1629 -- Outputs to FPU
1630 fv.op := e_in.insn_type;
1631 fv.insn := e_in.insn;
1632 fv.itag := e_in.instr_tag;
1633 fv.single := e_in.is_32bit;
1634 fv.is_signed := e_in.is_signed;
1635 fv.fe_mode := ex1.msr(MSR_FE0) & ex1.msr(MSR_FE1);
1636 fv.fra := a_in;
1637 fv.frb := b_in;
1638 fv.frc := c_in;
1639 fv.valid_a := e_in.reg_valid1;
1640 fv.valid_b := e_in.reg_valid2;
1641 fv.valid_c := e_in.reg_valid3;
1642 fv.frt := e_in.write_reg;
1643 fv.rc := e_in.rc;
1644 fv.out_cr := e_in.output_cr;
1645 fv.m32b := not ex1.msr(MSR_SF);
1646 fv.oe := e_in.oe;
1647 fv.xerc := xerc_in;
1648 fv.stall := l_in.l2stall;
1649
1650 -- Update registers
1651 ex1in <= v;
1652
1653 -- update outputs
1654 l_out <= lv;
1655 fp_out <= fv;
1656 irq_valid_log <= irq_valid;
1657 end process;
1658
1659 -- Slow SPR read mux
1660 with ex1.spr_select.sel select spr_result <=
1661 ctrl.tb when SPRSEL_TB,
1662 32x"0" & ctrl.tb(63 downto 32) when SPRSEL_TBU,
1663 ctrl.dec when SPRSEL_DEC,
1664 32x"0" & PVR_MICROWATT when SPRSEL_PVR,
1665 log_wr_addr & ex2.log_addr_spr when SPRSEL_LOGA,
1666 log_rd_data when SPRSEL_LOGD,
1667 ctrl.cfar when SPRSEL_CFAR,
1668 assemble_xer(ex1.e.xerc, ctrl.xer_low) when others;
1669
1670 stage2_stall <= l_in.l2stall or fp_in.f2stall;
1671
1672 -- Second execute stage control
1673 execute2_1: process(all)
1674 variable v : reg_stage2_type;
1675 variable bypass_valid : std_ulogic;
1676 variable rcresult : std_ulogic_vector(63 downto 0);
1677 variable sprres : std_ulogic_vector(63 downto 0);
1678 variable ex_result : std_ulogic_vector(63 downto 0);
1679 variable cr_res : std_ulogic_vector(31 downto 0);
1680 variable cr_mask : std_ulogic_vector(7 downto 0);
1681 variable sign, zero : std_ulogic;
1682 variable rcnz_hi, rcnz_lo : std_ulogic;
1683 begin
1684 v := ex2;
1685 if stage2_stall = '0' then
1686 v.e := ex1.e;
1687 v.se := ex1.se;
1688 v.ext_interrupt := ex1.ext_interrupt;
1689 v.taken_branch_event := ex1.taken_branch_event;
1690 v.br_mispredict := ex1.br_mispredict;
1691 end if;
1692
1693 if ex1.se.mult_32s = '1' and ex1.oe = '1' then
1694 v.e.xerc.ov := mult_32s_to_x.overflow;
1695 v.e.xerc.ov32 := mult_32s_to_x.overflow;
1696 if mult_32s_to_x.overflow = '1' then
1697 v.e.xerc.so := '1';
1698 end if;
1699 end if;
1700
1701 ctrl_tmp <= ctrl;
1702 -- FIXME: run at 512MHz not core freq
1703 ctrl_tmp.tb <= std_ulogic_vector(unsigned(ctrl.tb) + 1);
1704 ctrl_tmp.dec <= std_ulogic_vector(unsigned(ctrl.dec) - 1);
1705
1706 x_to_pmu.mfspr <= '0';
1707 x_to_pmu.mtspr <= '0';
1708 x_to_pmu.tbbits(3) <= ctrl.tb(63 - 47);
1709 x_to_pmu.tbbits(2) <= ctrl.tb(63 - 51);
1710 x_to_pmu.tbbits(1) <= ctrl.tb(63 - 55);
1711 x_to_pmu.tbbits(0) <= ctrl.tb(63 - 63);
1712 x_to_pmu.pmm_msr <= ctrl.msr(MSR_PMM);
1713 x_to_pmu.pr_msr <= ctrl.msr(MSR_PR);
1714
1715 if v.e.valid = '0' or flush_in = '1' then
1716 v.e.write_enable := '0';
1717 v.e.write_cr_enable := '0';
1718 v.e.write_xerc_enable := '0';
1719 v.e.redirect := '0';
1720 v.e.br_last := '0';
1721 v.taken_branch_event := '0';
1722 v.br_mispredict := '0';
1723 end if;
1724 if flush_in = '1' then
1725 v.e.valid := '0';
1726 v.e.interrupt := '0';
1727 v.se := side_effect_init;
1728 v.ext_interrupt := '0';
1729 end if;
1730
1731 -- This is split like this because mfspr doesn't have an Rc bit,
1732 -- and we don't want the zero-detect logic to be after the
1733 -- SPR mux for timing reasons.
1734 if ex1.se.mult_32s = '1' then
1735 if ex1.res2_sel(0) = '0' then
1736 rcresult := mult_32s_to_x.result(63 downto 0);
1737 else
1738 rcresult := mult_32s_to_x.result(63 downto 32) &
1739 mult_32s_to_x.result(63 downto 32);
1740 end if;
1741 elsif ex1.res2_sel(0) = '0' then
1742 rcresult := ex1.e.write_data;
1743 else
1744 rcresult := countbits_result;
1745 end if;
1746 if ex1.res2_sel(0) = '0' then
1747 sprres := spr_result;
1748 else
1749 sprres := pmu_to_x.spr_val;
1750 end if;
1751 if ex1.res2_sel(1) = '0' then
1752 ex_result := rcresult;
1753 else
1754 ex_result := sprres;
1755 end if;
1756
1757 cr_res := ex1.e.write_cr_data;
1758 cr_mask := ex1.e.write_cr_mask;
1759 if ex1.e.rc = '1' and ex1.e.write_enable = '1' then
1760 rcnz_lo := or (rcresult(31 downto 0));
1761 if ex1.e.mode_32bit = '0' then
1762 rcnz_hi := or (rcresult(63 downto 32));
1763 zero := not (rcnz_hi or rcnz_lo);
1764 sign := ex_result(63);
1765 else
1766 zero := not rcnz_lo;
1767 sign := ex_result(31);
1768 end if;
1769 cr_res(31) := sign;
1770 cr_res(30) := not (sign or zero);
1771 cr_res(29) := zero;
1772 cr_res(28) := v.e.xerc.so;
1773 cr_mask(7) := '1';
1774 end if;
1775
1776 if stage2_stall = '0' then
1777 v.e.write_data := ex_result;
1778 v.e.write_cr_data := cr_res;
1779 v.e.write_cr_mask := cr_mask;
1780 if ex1.e.rc = '1' and ex1.e.write_enable = '1' and v.e.valid = '1' then
1781 v.e.write_cr_enable := '1';
1782 end if;
1783
1784 if ex1.se.write_msr = '1' then
1785 ctrl_tmp.msr <= ex1.msr;
1786 end if;
1787 if ex1.se.write_xerlow = '1' then
1788 ctrl_tmp.xer_low <= ex1.e.write_data(17 downto 0);
1789 end if;
1790 if ex1.se.write_dec = '1' then
1791 ctrl_tmp.dec <= ex1.e.write_data;
1792 end if;
1793 if ex1.se.write_cfar = '1' then
1794 ctrl_tmp.cfar <= ex1.e.last_nia;
1795 end if;
1796 if ex1.se.write_loga = '1' then
1797 v.log_addr_spr := ex1.e.write_data(31 downto 0);
1798 elsif ex1.se.inc_loga = '1' then
1799 v.log_addr_spr := std_ulogic_vector(unsigned(ex2.log_addr_spr) + 1);
1800 end if;
1801 x_to_pmu.mtspr <= ex1.se.write_pmuspr;
1802 end if;
1803
1804 if interrupt_in.intr = '1' then
1805 ctrl_tmp.msr(MSR_SF) <= '1';
1806 ctrl_tmp.msr(MSR_EE) <= '0';
1807 ctrl_tmp.msr(MSR_PR) <= '0';
1808 ctrl_tmp.msr(MSR_SE) <= '0';
1809 ctrl_tmp.msr(MSR_BE) <= '0';
1810 ctrl_tmp.msr(MSR_FP) <= '0';
1811 ctrl_tmp.msr(MSR_FE0) <= '0';
1812 ctrl_tmp.msr(MSR_FE1) <= '0';
1813 ctrl_tmp.msr(MSR_IR) <= '0';
1814 ctrl_tmp.msr(MSR_DR) <= '0';
1815 ctrl_tmp.msr(MSR_RI) <= '0';
1816 ctrl_tmp.msr(MSR_LE) <= '1';
1817 end if;
1818
1819 bypass_valid := ex1.e.valid;
1820 if stage2_stall = '1' and ex1.res2_sel(1) = '1' then
1821 bypass_valid := '0';
1822 end if;
1823
1824 bypass2_data.tag.valid <= ex1.e.write_enable and bypass_valid;
1825 bypass2_data.tag.tag <= ex1.e.instr_tag.tag;
1826 bypass2_data.data <= ex_result;
1827
1828 bypass2_cr_data.tag.valid <= (ex1.e.write_cr_enable or (ex1.e.rc and ex1.e.write_enable))
1829 and bypass_valid;
1830 bypass2_cr_data.tag.tag <= ex1.e.instr_tag.tag;
1831 bypass2_cr_data.data <= cr_res;
1832
1833 -- Update registers
1834 ex2in <= v;
1835
1836 -- update outputs
1837 e_out <= ex2.e;
1838 e_out.msr <= msr_copy(ctrl.msr);
1839
1840 terminate_out <= ex2.se.terminate;
1841 icache_inval <= ex2.se.icache_inval;
1842
1843 exception_log <= v.e.interrupt;
1844 end process;
1845
1846 sim_dump_test: if SIM generate
1847 dump_exregs: process(all)
1848 variable xer : std_ulogic_vector(63 downto 0);
1849 begin
1850 if sim_dump = '1' then
1851 report "LR " & to_hstring(even_sprs(to_integer(RAMSPR_LR)));
1852 report "CTR " & to_hstring(odd_sprs(to_integer(RAMSPR_CTR)));
1853 sim_dump_done <= '1';
1854 else
1855 sim_dump_done <= '0';
1856 end if;
1857 end process;
1858 end generate;
1859
1860 -- Keep GHDL synthesis happy
1861 sim_dump_test_synth: if not SIM generate
1862 sim_dump_done <= '0';
1863 end generate;
1864
1865 e1_log: if LOG_LENGTH > 0 generate
1866 signal log_data : std_ulogic_vector(11 downto 0);
1867 begin
1868 ex1_log : process(clk)
1869 begin
1870 if rising_edge(clk) then
1871 log_data <= ctrl.msr(MSR_EE) & ctrl.msr(MSR_PR) &
1872 ctrl.msr(MSR_IR) & ctrl.msr(MSR_DR) &
1873 exception_log &
1874 irq_valid_log &
1875 interrupt_in.intr &
1876 ex2.e.write_enable &
1877 ex2.e.valid &
1878 (ex2.e.redirect or ex2.e.interrupt) &
1879 ex1.busy &
1880 flush_in;
1881 end if;
1882 end process;
1883 log_out <= log_data;
1884 end generate;
1885 end architecture behaviour;