core: Restore bypass path from execute1
[microwatt.git] / loadstore1.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.insn_helpers.all;
9 use work.helpers.all;
10
11 -- 2 cycle LSU
12 -- We calculate the address in the first cycle
13
14 entity loadstore1 is
15 generic (
16 HAS_FPU : boolean := true;
17 -- Non-zero to enable log data collection
18 LOG_LENGTH : natural := 0
19 );
20 port (
21 clk : in std_ulogic;
22 rst : in std_ulogic;
23
24 l_in : in Execute1ToLoadstore1Type;
25 e_out : out Loadstore1ToExecute1Type;
26 l_out : out Loadstore1ToWritebackType;
27
28 d_out : out Loadstore1ToDcacheType;
29 d_in : in DcacheToLoadstore1Type;
30
31 m_out : out Loadstore1ToMmuType;
32 m_in : in MmuToLoadstore1Type;
33
34 dc_stall : in std_ulogic;
35
36 log_out : out std_ulogic_vector(9 downto 0)
37 );
38 end loadstore1;
39
40 -- Note, we don't currently use the stall output from the dcache because
41 -- we know it can take two requests without stalling when idle, we are
42 -- its only user, and we know it never stalls when idle.
43
44 architecture behave of loadstore1 is
45
46 -- State machine for unaligned loads/stores
47 type state_t is (IDLE, -- ready for instruction
48 SECOND_REQ, -- send 2nd request of unaligned xfer
49 ACK_WAIT, -- waiting for ack from dcache
50 MMU_LOOKUP, -- waiting for MMU to look up translation
51 TLBIE_WAIT, -- waiting for MMU to finish doing a tlbie
52 FINISH_LFS, -- write back converted SP data for lfs*
53 COMPLETE -- extra cycle to complete an operation
54 );
55
56 type byte_index_t is array(0 to 7) of unsigned(2 downto 0);
57 subtype byte_trim_t is std_ulogic_vector(1 downto 0);
58 type trim_ctl_t is array(0 to 7) of byte_trim_t;
59
60 type reg_stage_t is record
61 -- latch most of the input request
62 load : std_ulogic;
63 tlbie : std_ulogic;
64 dcbz : std_ulogic;
65 addr : std_ulogic_vector(63 downto 0);
66 store_data : std_ulogic_vector(63 downto 0);
67 load_data : std_ulogic_vector(63 downto 0);
68 instr_tag : instr_tag_t;
69 write_reg : gspr_index_t;
70 length : std_ulogic_vector(3 downto 0);
71 byte_reverse : std_ulogic;
72 byte_offset : unsigned(2 downto 0);
73 brev_mask : unsigned(2 downto 0);
74 sign_extend : std_ulogic;
75 update : std_ulogic;
76 xerc : xer_common_t;
77 reserve : std_ulogic;
78 atomic : std_ulogic;
79 atomic_last : std_ulogic;
80 rc : std_ulogic;
81 nc : std_ulogic; -- non-cacheable access
82 virt_mode : std_ulogic;
83 priv_mode : std_ulogic;
84 state : state_t;
85 dwords_done : std_ulogic;
86 last_dword : std_ulogic;
87 first_bytes : std_ulogic_vector(7 downto 0);
88 second_bytes : std_ulogic_vector(7 downto 0);
89 dar : std_ulogic_vector(63 downto 0);
90 dsisr : std_ulogic_vector(31 downto 0);
91 instr_fault : std_ulogic;
92 align_intr : std_ulogic;
93 sprval : std_ulogic_vector(63 downto 0);
94 busy : std_ulogic;
95 wait_dcache : std_ulogic;
96 wait_mmu : std_ulogic;
97 do_update : std_ulogic;
98 extra_cycle : std_ulogic;
99 mode_32bit : std_ulogic;
100 byte_index : byte_index_t;
101 use_second : std_ulogic_vector(7 downto 0);
102 trim_ctl : trim_ctl_t;
103 load_sp : std_ulogic;
104 ld_sp_data : std_ulogic_vector(31 downto 0);
105 ld_sp_nz : std_ulogic;
106 ld_sp_lz : std_ulogic_vector(5 downto 0);
107 wr_sel : std_ulogic_vector(1 downto 0);
108 end record;
109
110 signal r, rin : reg_stage_t;
111 signal lsu_sum : std_ulogic_vector(63 downto 0);
112
113 signal store_sp_data : std_ulogic_vector(31 downto 0);
114 signal load_dp_data : std_ulogic_vector(63 downto 0);
115
116 -- Generate byte enables from sizes
117 function length_to_sel(length : in std_logic_vector(3 downto 0)) return std_ulogic_vector is
118 begin
119 case length is
120 when "0001" =>
121 return "00000001";
122 when "0010" =>
123 return "00000011";
124 when "0100" =>
125 return "00001111";
126 when "1000" =>
127 return "11111111";
128 when others =>
129 return "00000000";
130 end case;
131 end function length_to_sel;
132
133 -- Calculate byte enables
134 -- This returns 16 bits, giving the select signals for two transfers,
135 -- to account for unaligned loads or stores
136 function xfer_data_sel(size : in std_logic_vector(3 downto 0);
137 address : in std_logic_vector(2 downto 0))
138 return std_ulogic_vector is
139 variable longsel : std_ulogic_vector(15 downto 0);
140 begin
141 longsel := "00000000" & length_to_sel(size);
142 return std_ulogic_vector(shift_left(unsigned(longsel),
143 to_integer(unsigned(address))));
144 end function xfer_data_sel;
145
146 -- 23-bit right shifter for DP -> SP float conversions
147 function shifter_23r(frac: std_ulogic_vector(22 downto 0); shift: unsigned(4 downto 0))
148 return std_ulogic_vector is
149 variable fs1 : std_ulogic_vector(22 downto 0);
150 variable fs2 : std_ulogic_vector(22 downto 0);
151 begin
152 case shift(1 downto 0) is
153 when "00" =>
154 fs1 := frac;
155 when "01" =>
156 fs1 := '0' & frac(22 downto 1);
157 when "10" =>
158 fs1 := "00" & frac(22 downto 2);
159 when others =>
160 fs1 := "000" & frac(22 downto 3);
161 end case;
162 case shift(4 downto 2) is
163 when "000" =>
164 fs2 := fs1;
165 when "001" =>
166 fs2 := x"0" & fs1(22 downto 4);
167 when "010" =>
168 fs2 := x"00" & fs1(22 downto 8);
169 when "011" =>
170 fs2 := x"000" & fs1(22 downto 12);
171 when "100" =>
172 fs2 := x"0000" & fs1(22 downto 16);
173 when others =>
174 fs2 := x"00000" & fs1(22 downto 20);
175 end case;
176 return fs2;
177 end;
178
179 -- 23-bit left shifter for SP -> DP float conversions
180 function shifter_23l(frac: std_ulogic_vector(22 downto 0); shift: unsigned(4 downto 0))
181 return std_ulogic_vector is
182 variable fs1 : std_ulogic_vector(22 downto 0);
183 variable fs2 : std_ulogic_vector(22 downto 0);
184 begin
185 case shift(1 downto 0) is
186 when "00" =>
187 fs1 := frac;
188 when "01" =>
189 fs1 := frac(21 downto 0) & '0';
190 when "10" =>
191 fs1 := frac(20 downto 0) & "00";
192 when others =>
193 fs1 := frac(19 downto 0) & "000";
194 end case;
195 case shift(4 downto 2) is
196 when "000" =>
197 fs2 := fs1;
198 when "001" =>
199 fs2 := fs1(18 downto 0) & x"0" ;
200 when "010" =>
201 fs2 := fs1(14 downto 0) & x"00";
202 when "011" =>
203 fs2 := fs1(10 downto 0) & x"000";
204 when "100" =>
205 fs2 := fs1(6 downto 0) & x"0000";
206 when others =>
207 fs2 := fs1(2 downto 0) & x"00000";
208 end case;
209 return fs2;
210 end;
211
212 begin
213 -- Calculate the address in the first cycle
214 lsu_sum <= std_ulogic_vector(unsigned(l_in.addr1) + unsigned(l_in.addr2)) when l_in.valid = '1' else (others => '0');
215
216 loadstore1_0: process(clk)
217 begin
218 if rising_edge(clk) then
219 if rst = '1' then
220 r.state <= IDLE;
221 r.busy <= '0';
222 r.do_update <= '0';
223 else
224 r <= rin;
225 end if;
226 end if;
227 end process;
228
229 ls_fp_conv: if HAS_FPU generate
230 -- Convert DP data to SP for stfs
231 dp_to_sp: process(all)
232 variable exp : unsigned(10 downto 0);
233 variable frac : std_ulogic_vector(22 downto 0);
234 variable shift : unsigned(4 downto 0);
235 begin
236 store_sp_data(31) <= l_in.data(63);
237 store_sp_data(30 downto 0) <= (others => '0');
238 exp := unsigned(l_in.data(62 downto 52));
239 if exp > 896 then
240 store_sp_data(30) <= l_in.data(62);
241 store_sp_data(29 downto 0) <= l_in.data(58 downto 29);
242 elsif exp >= 874 then
243 -- denormalization required
244 frac := '1' & l_in.data(51 downto 30);
245 shift := 0 - exp(4 downto 0);
246 store_sp_data(22 downto 0) <= shifter_23r(frac, shift);
247 end if;
248 end process;
249
250 -- Convert SP data to DP for lfs
251 sp_to_dp: process(all)
252 variable exp : unsigned(7 downto 0);
253 variable exp_dp : unsigned(10 downto 0);
254 variable exp_nz : std_ulogic;
255 variable exp_ao : std_ulogic;
256 variable frac : std_ulogic_vector(22 downto 0);
257 variable frac_shift : unsigned(4 downto 0);
258 begin
259 frac := r.ld_sp_data(22 downto 0);
260 exp := unsigned(r.ld_sp_data(30 downto 23));
261 exp_nz := or (r.ld_sp_data(30 downto 23));
262 exp_ao := and (r.ld_sp_data(30 downto 23));
263 frac_shift := (others => '0');
264 if exp_ao = '1' then
265 exp_dp := to_unsigned(2047, 11); -- infinity or NaN
266 elsif exp_nz = '1' then
267 exp_dp := 896 + resize(exp, 11); -- finite normalized value
268 elsif r.ld_sp_nz = '0' then
269 exp_dp := to_unsigned(0, 11); -- zero
270 else
271 -- denormalized SP operand, need to normalize
272 exp_dp := 896 - resize(unsigned(r.ld_sp_lz), 11);
273 frac_shift := unsigned(r.ld_sp_lz(4 downto 0)) + 1;
274 end if;
275 load_dp_data(63) <= r.ld_sp_data(31);
276 load_dp_data(62 downto 52) <= std_ulogic_vector(exp_dp);
277 load_dp_data(51 downto 29) <= shifter_23l(frac, frac_shift);
278 load_dp_data(28 downto 0) <= (others => '0');
279 end process;
280 end generate;
281
282 loadstore1_1: process(all)
283 variable v : reg_stage_t;
284 variable brev_lenm1 : unsigned(2 downto 0);
285 variable byte_offset : unsigned(2 downto 0);
286 variable j : integer;
287 variable k : unsigned(2 downto 0);
288 variable kk : unsigned(3 downto 0);
289 variable long_sel : std_ulogic_vector(15 downto 0);
290 variable byte_sel : std_ulogic_vector(7 downto 0);
291 variable req : std_ulogic;
292 variable busy : std_ulogic;
293 variable addr : std_ulogic_vector(63 downto 0);
294 variable maddr : std_ulogic_vector(63 downto 0);
295 variable wdata : std_ulogic_vector(63 downto 0);
296 variable write_enable : std_ulogic;
297 variable do_update : std_ulogic;
298 variable done : std_ulogic;
299 variable data_permuted : std_ulogic_vector(63 downto 0);
300 variable data_trimmed : std_ulogic_vector(63 downto 0);
301 variable store_data : std_ulogic_vector(63 downto 0);
302 variable byte_rev : std_ulogic;
303 variable length : std_ulogic_vector(3 downto 0);
304 variable negative : std_ulogic;
305 variable sprn : std_ulogic_vector(9 downto 0);
306 variable exception : std_ulogic;
307 variable next_addr : std_ulogic_vector(63 downto 0);
308 variable mmureq : std_ulogic;
309 variable dsisr : std_ulogic_vector(31 downto 0);
310 variable mmu_mtspr : std_ulogic;
311 variable itlb_fault : std_ulogic;
312 variable misaligned : std_ulogic;
313 begin
314 v := r;
315 req := '0';
316 mmu_mtspr := '0';
317 itlb_fault := '0';
318 sprn := std_ulogic_vector(to_unsigned(decode_spr_num(l_in.insn), 10));
319 dsisr := (others => '0');
320 mmureq := '0';
321 v.wr_sel := "11";
322
323 write_enable := '0';
324
325 do_update := r.do_update;
326 v.do_update := '0';
327
328 -- load data formatting
329 -- shift and byte-reverse data bytes
330 for i in 0 to 7 loop
331 j := to_integer(r.byte_index(i)) * 8;
332 data_permuted(i * 8 + 7 downto i * 8) := d_in.data(j + 7 downto j);
333 end loop;
334
335 -- Work out the sign bit for sign extension.
336 -- For unaligned loads crossing two dwords, the sign bit is in the
337 -- first dword for big-endian (byte_reverse = 1), or the second dword
338 -- for little-endian.
339 if r.dwords_done = '1' and r.byte_reverse = '1' then
340 negative := (r.length(3) and r.load_data(63)) or
341 (r.length(2) and r.load_data(31)) or
342 (r.length(1) and r.load_data(15)) or
343 (r.length(0) and r.load_data(7));
344 else
345 negative := (r.length(3) and data_permuted(63)) or
346 (r.length(2) and data_permuted(31)) or
347 (r.length(1) and data_permuted(15)) or
348 (r.length(0) and data_permuted(7));
349 end if;
350
351 -- trim and sign-extend
352 for i in 0 to 7 loop
353 case r.trim_ctl(i) is
354 when "11" =>
355 data_trimmed(i * 8 + 7 downto i * 8) := r.load_data(i * 8 + 7 downto i * 8);
356 when "10" =>
357 data_trimmed(i * 8 + 7 downto i * 8) := data_permuted(i * 8 + 7 downto i * 8);
358 when "01" =>
359 data_trimmed(i * 8 + 7 downto i * 8) := (others => negative);
360 when others =>
361 data_trimmed(i * 8 + 7 downto i * 8) := x"00";
362 end case;
363 end loop;
364
365 if HAS_FPU then
366 -- Single-precision FP conversion for loads
367 v.ld_sp_data := data_trimmed(31 downto 0);
368 v.ld_sp_nz := or (data_trimmed(22 downto 0));
369 v.ld_sp_lz := count_left_zeroes(data_trimmed(22 downto 0));
370 end if;
371
372 -- Byte reversing and rotating for stores.
373 -- Done in the second cycle (the cycle after l_in.valid = 1).
374 for i in 0 to 7 loop
375 k := (to_unsigned(i, 3) - r.byte_offset) xor r.brev_mask;
376 j := to_integer(k) * 8;
377 store_data(i * 8 + 7 downto i * 8) := r.store_data(j + 7 downto j);
378 end loop;
379
380 -- compute (addr + 8) & ~7 for the second doubleword when unaligned
381 next_addr := std_ulogic_vector(unsigned(r.addr(63 downto 3)) + 1) & "000";
382
383 -- Busy calculation.
384 -- We need to minimize the delay from clock to busy valid because it
385 -- gates the start of execution of the next instruction.
386 busy := r.busy and not ((r.wait_dcache and d_in.valid) or (r.wait_mmu and m_in.done));
387 v.busy := busy;
388
389 done := '0';
390 if r.state /= IDLE and busy = '0' then
391 done := '1';
392 end if;
393 exception := '0';
394
395 if r.dwords_done = '1' or r.state = SECOND_REQ then
396 addr := next_addr;
397 byte_sel := r.second_bytes;
398 else
399 addr := r.addr;
400 byte_sel := r.first_bytes;
401 end if;
402 if r.mode_32bit = '1' then
403 addr(63 downto 32) := (others => '0');
404 end if;
405 maddr := addr;
406
407 case r.state is
408 when IDLE =>
409
410 when SECOND_REQ =>
411 req := '1';
412 v.state := ACK_WAIT;
413 v.last_dword := '0';
414
415 when ACK_WAIT =>
416 -- r.wr_sel gets set one cycle after we come into ACK_WAIT state,
417 -- which is OK because the dcache always takes at least two cycles.
418 if r.update = '1' and r.load = '0' then
419 v.wr_sel := "01";
420 end if;
421 if d_in.error = '1' then
422 -- dcache will discard the second request if it
423 -- gets an error on the 1st of two requests
424 if d_in.cache_paradox = '1' then
425 -- signal an interrupt straight away
426 exception := '1';
427 dsisr(63 - 38) := not r.load;
428 -- XXX there is no architected bit for this
429 dsisr(63 - 35) := d_in.cache_paradox;
430 else
431 -- Look up the translation for TLB miss
432 -- and also for permission error and RC error
433 -- in case the PTE has been updated.
434 mmureq := '1';
435 v.state := MMU_LOOKUP;
436 end if;
437 end if;
438 if d_in.valid = '1' then
439 if r.last_dword = '0' then
440 v.dwords_done := '1';
441 v.last_dword := '1';
442 if r.load = '1' then
443 v.load_data := data_permuted;
444 end if;
445 else
446 write_enable := r.load and not r.load_sp;
447 if HAS_FPU and r.load_sp = '1' then
448 -- SP to DP conversion takes a cycle
449 v.wr_sel := "10";
450 v.state := FINISH_LFS;
451 elsif r.load = '0' then
452 -- stores write back rA update in this cycle
453 do_update := r.update;
454 end if;
455 v.busy := '0';
456 end if;
457 end if;
458 -- r.wait_dcache gets set one cycle after we come into ACK_WAIT state,
459 -- which is OK because the dcache always takes at least two cycles.
460 v.wait_dcache := r.last_dword and not r.extra_cycle;
461
462 when MMU_LOOKUP =>
463 if m_in.done = '1' then
464 if r.instr_fault = '0' then
465 -- retry the request now that the MMU has installed a TLB entry
466 req := '1';
467 if r.last_dword = '0' then
468 v.state := SECOND_REQ;
469 else
470 v.state := ACK_WAIT;
471 end if;
472 end if;
473 end if;
474 if m_in.err = '1' then
475 exception := '1';
476 dsisr(63 - 33) := m_in.invalid;
477 dsisr(63 - 36) := m_in.perm_error;
478 dsisr(63 - 38) := not r.load;
479 dsisr(63 - 44) := m_in.badtree;
480 dsisr(63 - 45) := m_in.rc_error;
481 end if;
482
483 when TLBIE_WAIT =>
484
485 when FINISH_LFS =>
486
487 when COMPLETE =>
488 exception := r.align_intr;
489
490 end case;
491
492 if done = '1' or exception = '1' then
493 v.state := IDLE;
494 v.busy := '0';
495 end if;
496
497 -- Note that l_in.valid is gated with busy inside execute1
498 if l_in.valid = '1' then
499 v.mode_32bit := l_in.mode_32bit;
500 v.load := '0';
501 v.dcbz := '0';
502 v.tlbie := '0';
503 v.instr_fault := '0';
504 v.align_intr := '0';
505 v.dwords_done := '0';
506 v.last_dword := '1';
507 v.instr_tag := l_in.instr_tag;
508 v.write_reg := l_in.write_reg;
509 v.length := l_in.length;
510 v.byte_reverse := l_in.byte_reverse;
511 v.sign_extend := l_in.sign_extend;
512 v.update := l_in.update;
513 v.xerc := l_in.xerc;
514 v.reserve := l_in.reserve;
515 v.rc := l_in.rc;
516 v.nc := l_in.ci;
517 v.virt_mode := l_in.virt_mode;
518 v.priv_mode := l_in.priv_mode;
519 v.load_sp := '0';
520 v.wait_dcache := '0';
521 v.wait_mmu := '0';
522 v.extra_cycle := '0';
523
524 if HAS_FPU and l_in.is_32bit = '1' then
525 v.store_data := x"00000000" & store_sp_data;
526 else
527 v.store_data := l_in.data;
528 end if;
529
530 addr := lsu_sum;
531 if l_in.second = '1' then
532 -- second half of load with update does the update
533 if l_in.op = OP_LOAD and l_in.update = '1' then
534 v.do_update := '1';
535 else
536 -- for the second half of a 16-byte transfer, use next_addr
537 addr := next_addr;
538 end if;
539 end if;
540 if l_in.mode_32bit = '1' then
541 addr(63 downto 32) := (others => '0');
542 end if;
543 if v.do_update = '0' then
544 -- preserve previous r.addr for load with update
545 v.addr := addr;
546 end if;
547 maddr := l_in.addr2; -- address from RB for tlbie
548
549 -- XXX Temporary hack. Mark the op as non-cachable if the address
550 -- is the form 0xc------- for a real-mode access.
551 if addr(31 downto 28) = "1100" and l_in.virt_mode = '0' then
552 v.nc := '1';
553 end if;
554
555 if l_in.second = '0' then
556 -- Do length_to_sel and work out if we are doing 2 dwords
557 long_sel := xfer_data_sel(l_in.length, lsu_sum(2 downto 0));
558 byte_sel := long_sel(7 downto 0);
559 v.first_bytes := byte_sel;
560 v.second_bytes := long_sel(15 downto 8);
561 else
562 byte_sel := r.first_bytes;
563 long_sel := r.second_bytes & r.first_bytes;
564 end if;
565
566 -- check alignment for larx/stcx
567 misaligned := or (std_ulogic_vector(unsigned(l_in.length(2 downto 0)) - 1) and addr(2 downto 0));
568 v.align_intr := l_in.reserve and misaligned;
569 if l_in.repeat = '1' and l_in.second = '0' and l_in.update = '0' and addr(3) = '1' then
570 -- length is really 16 not 8
571 -- Make misaligned lq cause an alignment interrupt in LE mode,
572 -- in order to avoid the case with RA = RT + 1 where the second half
573 -- faults but the first doesn't (and updates RT+1, destroying RA).
574 -- The equivalent BE case doesn't occur because RA = RT is illegal.
575 misaligned := '1';
576 if l_in.reserve = '1' or (l_in.op = OP_LOAD and l_in.byte_reverse = '0') then
577 v.align_intr := '1';
578 end if;
579 end if;
580
581 v.atomic := not misaligned;
582 v.atomic_last := not misaligned and (l_in.second or not l_in.repeat);
583
584 case l_in.op is
585 when OP_STORE =>
586 req := '1';
587 when OP_LOAD =>
588 v.load := '1';
589 if l_in.second = '1' and l_in.update = '1' then
590 v.wr_sel := "01";
591 v.state := COMPLETE;
592 else
593 req := '1';
594 if HAS_FPU and l_in.is_32bit = '1' then
595 -- Allow an extra cycle for SP->DP precision conversion
596 v.load_sp := '1';
597 v.extra_cycle := '1';
598 end if;
599 end if;
600 when OP_DCBZ =>
601 v.align_intr := v.nc;
602 req := '1';
603 v.dcbz := '1';
604 when OP_TLBIE =>
605 mmureq := '1';
606 v.tlbie := '1';
607 v.state := TLBIE_WAIT;
608 v.wait_mmu := '1';
609 when OP_MFSPR =>
610 v.wr_sel := "00";
611 -- partial decode on SPR number should be adequate given
612 -- the restricted set that get sent down this path
613 if sprn(9) = '0' and sprn(5) = '0' then
614 if sprn(0) = '0' then
615 v.sprval := x"00000000" & r.dsisr;
616 else
617 v.sprval := r.dar;
618 end if;
619 else
620 -- reading one of the SPRs in the MMU
621 v.sprval := m_in.sprval;
622 end if;
623 v.state := COMPLETE;
624 when OP_MTSPR =>
625 if sprn(9) = '0' and sprn(5) = '0' then
626 if sprn(0) = '0' then
627 v.dsisr := l_in.data(31 downto 0);
628 else
629 v.dar := l_in.data;
630 end if;
631 v.state := COMPLETE;
632 else
633 -- writing one of the SPRs in the MMU
634 mmu_mtspr := '1';
635 v.state := TLBIE_WAIT;
636 v.wait_mmu := '1';
637 end if;
638 when OP_FETCH_FAILED =>
639 -- send it to the MMU to do the radix walk
640 maddr := l_in.nia;
641 v.instr_fault := '1';
642 mmureq := '1';
643 v.state := MMU_LOOKUP;
644 v.wait_mmu := '1';
645 when others =>
646 assert false report "unknown op sent to loadstore1";
647 end case;
648
649 if req = '1' then
650 if v.align_intr = '1' then
651 v.state := COMPLETE;
652 elsif long_sel(15 downto 8) = "00000000" then
653 v.state := ACK_WAIT;
654 else
655 v.state := SECOND_REQ;
656 end if;
657 end if;
658
659 v.busy := req or mmureq or mmu_mtspr;
660 end if;
661
662 -- Work out controls for store formatting
663 if l_in.valid = '1' then
664 byte_offset := unsigned(lsu_sum(2 downto 0));
665 byte_rev := l_in.byte_reverse;
666 length := l_in.length;
667 brev_lenm1 := "000";
668 if byte_rev = '1' then
669 brev_lenm1 := unsigned(length(2 downto 0)) - 1;
670 end if;
671 v.byte_offset := byte_offset;
672 v.brev_mask := brev_lenm1;
673 end if;
674
675 -- Work out load formatter controls for next cycle
676 byte_offset := unsigned(v.addr(2 downto 0));
677 brev_lenm1 := "000";
678 if v.byte_reverse = '1' then
679 brev_lenm1 := unsigned(v.length(2 downto 0)) - 1;
680 end if;
681
682 for i in 0 to 7 loop
683 kk := ('0' & (to_unsigned(i, 3) xor brev_lenm1)) + ('0' & byte_offset);
684 v.use_second(i) := kk(3);
685 v.byte_index(i) := kk(2 downto 0);
686 end loop;
687
688 for i in 0 to 7 loop
689 if i < to_integer(unsigned(v.length)) then
690 if v.dwords_done = '1' then
691 v.trim_ctl(i) := '1' & not v.use_second(i);
692 else
693 v.trim_ctl(i) := "10";
694 end if;
695 else
696 v.trim_ctl(i) := '0' & v.sign_extend;
697 end if;
698 end loop;
699
700 -- Update outputs to dcache
701 d_out.valid <= req and not v.align_intr;
702 d_out.load <= v.load;
703 d_out.dcbz <= v.dcbz;
704 d_out.nc <= v.nc;
705 d_out.reserve <= v.reserve;
706 d_out.atomic <= v.atomic;
707 d_out.atomic_last <= v.atomic_last;
708 d_out.addr <= addr;
709 d_out.data <= store_data;
710 d_out.byte_sel <= byte_sel;
711 d_out.virt_mode <= v.virt_mode;
712 d_out.priv_mode <= v.priv_mode;
713
714 -- Update outputs to MMU
715 m_out.valid <= mmureq;
716 m_out.iside <= v.instr_fault;
717 m_out.load <= r.load;
718 m_out.priv <= r.priv_mode;
719 m_out.tlbie <= v.tlbie;
720 m_out.mtspr <= mmu_mtspr;
721 m_out.sprn <= sprn;
722 m_out.addr <= maddr;
723 m_out.slbia <= l_in.insn(7);
724 m_out.rs <= l_in.data;
725
726 -- Update outputs to writeback
727 -- Multiplex either cache data to the destination GPR or
728 -- the address for the rA update.
729 l_out.valid <= done;
730 l_out.instr_tag <= r.instr_tag;
731 l_out.write_reg <= r.write_reg;
732 case r.wr_sel is
733 when "00" =>
734 l_out.write_enable <= '1';
735 l_out.write_data <= r.sprval;
736 when "01" =>
737 l_out.write_enable <= do_update;
738 l_out.write_data <= r.addr;
739 when "10" =>
740 l_out.write_enable <= '1';
741 l_out.write_data <= load_dp_data;
742 when others =>
743 l_out.write_enable <= write_enable;
744 l_out.write_data <= data_trimmed;
745 end case;
746 l_out.xerc <= r.xerc;
747 l_out.rc <= r.rc and done;
748 l_out.store_done <= d_in.store_done;
749
750 -- update exception info back to execute1
751 e_out.busy <= busy;
752 e_out.exception <= exception;
753 e_out.alignment <= r.align_intr;
754 e_out.instr_fault <= r.instr_fault;
755 e_out.invalid <= m_in.invalid;
756 e_out.badtree <= m_in.badtree;
757 e_out.perm_error <= m_in.perm_error;
758 e_out.rc_error <= m_in.rc_error;
759 e_out.segment_fault <= m_in.segerr;
760 if exception = '1' and r.instr_fault = '0' then
761 v.dar := addr;
762 if m_in.segerr = '0' and r.align_intr = '0' then
763 v.dsisr := dsisr;
764 end if;
765 end if;
766
767 -- Update registers
768 rin <= v;
769
770 end process;
771
772 l1_log: if LOG_LENGTH > 0 generate
773 signal log_data : std_ulogic_vector(9 downto 0);
774 begin
775 ls1_log: process(clk)
776 begin
777 if rising_edge(clk) then
778 log_data <= e_out.busy &
779 e_out.exception &
780 l_out.valid &
781 m_out.valid &
782 d_out.valid &
783 m_in.done &
784 r.dwords_done &
785 std_ulogic_vector(to_unsigned(state_t'pos(r.state), 3));
786 end if;
787 end process;
788 log_out <= log_data;
789 end generate;
790
791 end;