loadstore1: Decide on load formatting controls a cycle earlier
[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 FPR_CONV, -- converting double to float for store
49 SECOND_REQ, -- send 2nd request of unaligned xfer
50 ACK_WAIT, -- waiting for ack from dcache
51 MMU_LOOKUP, -- waiting for MMU to look up translation
52 TLBIE_WAIT, -- waiting for MMU to finish doing a tlbie
53 FINISH_LFS, -- write back converted SP data for lfs*
54 COMPLETE -- extra cycle to complete an operation
55 );
56
57 type byte_index_t is array(0 to 7) of unsigned(2 downto 0);
58 subtype byte_trim_t is std_ulogic_vector(1 downto 0);
59 type trim_ctl_t is array(0 to 7) of byte_trim_t;
60
61 type reg_stage_t is record
62 -- latch most of the input request
63 load : std_ulogic;
64 tlbie : std_ulogic;
65 dcbz : std_ulogic;
66 mfspr : std_ulogic;
67 addr : std_ulogic_vector(63 downto 0);
68 store_data : std_ulogic_vector(63 downto 0);
69 load_data : std_ulogic_vector(63 downto 0);
70 write_reg : gspr_index_t;
71 length : std_ulogic_vector(3 downto 0);
72 byte_reverse : std_ulogic;
73 sign_extend : std_ulogic;
74 update : std_ulogic;
75 update_reg : gpr_index_t;
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 st_sp_data : std_ulogic_vector(31 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 data_in : std_ulogic_vector(63 downto 0);
303 variable byte_rev : std_ulogic;
304 variable length : std_ulogic_vector(3 downto 0);
305 variable negative : std_ulogic;
306 variable sprn : std_ulogic_vector(9 downto 0);
307 variable exception : std_ulogic;
308 variable next_addr : std_ulogic_vector(63 downto 0);
309 variable mmureq : std_ulogic;
310 variable dsisr : std_ulogic_vector(31 downto 0);
311 variable mmu_mtspr : std_ulogic;
312 variable itlb_fault : std_ulogic;
313 variable misaligned : std_ulogic;
314 variable fp_reg_conv : std_ulogic;
315 variable lfs_done : std_ulogic;
316 begin
317 v := r;
318 req := '0';
319 v.mfspr := '0';
320 mmu_mtspr := '0';
321 itlb_fault := '0';
322 sprn := std_ulogic_vector(to_unsigned(decode_spr_num(l_in.insn), 10));
323 dsisr := (others => '0');
324 mmureq := '0';
325 fp_reg_conv := '0';
326
327 write_enable := '0';
328 lfs_done := '0';
329
330 do_update := r.do_update;
331 v.do_update := '0';
332
333 -- load data formatting
334 -- shift and byte-reverse data bytes
335 for i in 0 to 7 loop
336 j := to_integer(r.byte_index(i)) * 8;
337 data_permuted(i * 8 + 7 downto i * 8) := d_in.data(j + 7 downto j);
338 end loop;
339
340 -- Work out the sign bit for sign extension.
341 -- For unaligned loads crossing two dwords, the sign bit is in the
342 -- first dword for big-endian (byte_reverse = 1), or the second dword
343 -- for little-endian.
344 if r.dwords_done = '1' and r.byte_reverse = '1' then
345 negative := (r.length(3) and r.load_data(63)) or
346 (r.length(2) and r.load_data(31)) or
347 (r.length(1) and r.load_data(15)) or
348 (r.length(0) and r.load_data(7));
349 else
350 negative := (r.length(3) and data_permuted(63)) or
351 (r.length(2) and data_permuted(31)) or
352 (r.length(1) and data_permuted(15)) or
353 (r.length(0) and data_permuted(7));
354 end if;
355
356 -- trim and sign-extend
357 for i in 0 to 7 loop
358 case r.trim_ctl(i) is
359 when "11" =>
360 data_trimmed(i * 8 + 7 downto i * 8) := r.load_data(i * 8 + 7 downto i * 8);
361 when "10" =>
362 data_trimmed(i * 8 + 7 downto i * 8) := data_permuted(i * 8 + 7 downto i * 8);
363 when "01" =>
364 data_trimmed(i * 8 + 7 downto i * 8) := (others => negative);
365 when others =>
366 data_trimmed(i * 8 + 7 downto i * 8) := x"00";
367 end case;
368 end loop;
369
370 if HAS_FPU then
371 -- Single-precision FP conversion
372 v.st_sp_data := store_sp_data;
373 v.ld_sp_data := data_trimmed(31 downto 0);
374 v.ld_sp_nz := or (data_trimmed(22 downto 0));
375 v.ld_sp_lz := count_left_zeroes(data_trimmed(22 downto 0));
376 end if;
377
378 -- Byte reversing and rotating for stores.
379 -- Done in the first cycle (when l_in.valid = 1) for integer stores
380 -- and DP float stores, and in the second cycle for SP float stores.
381 store_data := r.store_data;
382 if l_in.valid = '1' or (HAS_FPU and r.state = FPR_CONV) then
383 if HAS_FPU and r.state = FPR_CONV then
384 data_in := x"00000000" & r.st_sp_data;
385 byte_offset := unsigned(r.addr(2 downto 0));
386 byte_rev := r.byte_reverse;
387 length := r.length;
388 else
389 data_in := l_in.data;
390 byte_offset := unsigned(lsu_sum(2 downto 0));
391 byte_rev := l_in.byte_reverse;
392 length := l_in.length;
393 end if;
394 brev_lenm1 := "000";
395 if byte_rev = '1' then
396 brev_lenm1 := unsigned(length(2 downto 0)) - 1;
397 end if;
398 for i in 0 to 7 loop
399 k := (to_unsigned(i, 3) - byte_offset) xor brev_lenm1;
400 j := to_integer(k) * 8;
401 store_data(i * 8 + 7 downto i * 8) := data_in(j + 7 downto j);
402 end loop;
403 end if;
404 v.store_data := store_data;
405
406 -- compute (addr + 8) & ~7 for the second doubleword when unaligned
407 next_addr := std_ulogic_vector(unsigned(r.addr(63 downto 3)) + 1) & "000";
408
409 -- Busy calculation.
410 -- We need to minimize the delay from clock to busy valid because it
411 -- gates the start of execution of the next instruction.
412 busy := r.busy and not ((r.wait_dcache and d_in.valid) or (r.wait_mmu and m_in.done));
413 v.busy := busy;
414
415 done := '0';
416 if r.state /= IDLE and busy = '0' then
417 done := '1';
418 end if;
419 exception := '0';
420
421 if r.dwords_done = '1' or r.state = SECOND_REQ then
422 addr := next_addr;
423 byte_sel := r.second_bytes;
424 else
425 addr := r.addr;
426 byte_sel := r.first_bytes;
427 end if;
428 if r.mode_32bit = '1' then
429 addr(63 downto 32) := (others => '0');
430 end if;
431 maddr := addr;
432
433 case r.state is
434 when IDLE =>
435
436 when FPR_CONV =>
437 req := '1';
438 if r.second_bytes /= "00000000" then
439 v.state := SECOND_REQ;
440 else
441 v.state := ACK_WAIT;
442 end if;
443
444 when SECOND_REQ =>
445 req := '1';
446 v.state := ACK_WAIT;
447 v.last_dword := '0';
448
449 when ACK_WAIT =>
450 if d_in.error = '1' then
451 -- dcache will discard the second request if it
452 -- gets an error on the 1st of two requests
453 if d_in.cache_paradox = '1' then
454 -- signal an interrupt straight away
455 exception := '1';
456 dsisr(63 - 38) := not r.load;
457 -- XXX there is no architected bit for this
458 dsisr(63 - 35) := d_in.cache_paradox;
459 else
460 -- Look up the translation for TLB miss
461 -- and also for permission error and RC error
462 -- in case the PTE has been updated.
463 mmureq := '1';
464 v.state := MMU_LOOKUP;
465 end if;
466 end if;
467 if d_in.valid = '1' then
468 if r.last_dword = '0' then
469 v.dwords_done := '1';
470 v.last_dword := '1';
471 if r.load = '1' then
472 v.load_data := data_permuted;
473 end if;
474 else
475 write_enable := r.load and not r.load_sp;
476 if HAS_FPU and r.load_sp = '1' then
477 -- SP to DP conversion takes a cycle
478 -- Write back rA update in this cycle if needed
479 do_update := r.update;
480 v.state := FINISH_LFS;
481 elsif r.extra_cycle = '1' then
482 -- loads with rA update need an extra cycle
483 v.state := COMPLETE;
484 v.do_update := r.update;
485 else
486 -- stores write back rA update in this cycle
487 do_update := r.update;
488 end if;
489 v.busy := '0';
490 end if;
491 end if;
492 -- r.wait_dcache gets set one cycle after we come into ACK_WAIT state,
493 -- which is OK because the dcache always takes at least two cycles.
494 v.wait_dcache := r.last_dword and not r.extra_cycle;
495
496 when MMU_LOOKUP =>
497 if m_in.done = '1' then
498 if r.instr_fault = '0' then
499 -- retry the request now that the MMU has installed a TLB entry
500 req := '1';
501 if r.last_dword = '0' then
502 v.state := SECOND_REQ;
503 else
504 v.state := ACK_WAIT;
505 end if;
506 end if;
507 end if;
508 if m_in.err = '1' then
509 exception := '1';
510 dsisr(63 - 33) := m_in.invalid;
511 dsisr(63 - 36) := m_in.perm_error;
512 dsisr(63 - 38) := not r.load;
513 dsisr(63 - 44) := m_in.badtree;
514 dsisr(63 - 45) := m_in.rc_error;
515 end if;
516
517 when TLBIE_WAIT =>
518
519 when FINISH_LFS =>
520 lfs_done := '1';
521
522 when COMPLETE =>
523 exception := r.align_intr;
524
525 end case;
526
527 if done = '1' or exception = '1' then
528 v.state := IDLE;
529 v.busy := '0';
530 end if;
531
532 -- Note that l_in.valid is gated with busy inside execute1
533 if l_in.valid = '1' then
534 v.mode_32bit := l_in.mode_32bit;
535 v.load := '0';
536 v.dcbz := '0';
537 v.tlbie := '0';
538 v.instr_fault := '0';
539 v.align_intr := '0';
540 v.dwords_done := '0';
541 v.last_dword := '1';
542 v.write_reg := l_in.write_reg;
543 v.length := l_in.length;
544 v.byte_reverse := l_in.byte_reverse;
545 v.sign_extend := l_in.sign_extend;
546 v.update := l_in.update;
547 v.update_reg := l_in.update_reg;
548 v.xerc := l_in.xerc;
549 v.reserve := l_in.reserve;
550 v.rc := l_in.rc;
551 v.nc := l_in.ci;
552 v.virt_mode := l_in.virt_mode;
553 v.priv_mode := l_in.priv_mode;
554 v.load_sp := '0';
555 v.wait_dcache := '0';
556 v.wait_mmu := '0';
557 v.do_update := '0';
558 v.extra_cycle := '0';
559
560 addr := lsu_sum;
561 if l_in.second = '1' then
562 -- for the second half of a 16-byte transfer, use next_addr
563 addr := next_addr;
564 end if;
565 if l_in.mode_32bit = '1' then
566 addr(63 downto 32) := (others => '0');
567 end if;
568 v.addr := addr;
569 maddr := l_in.addr2; -- address from RB for tlbie
570
571 -- XXX Temporary hack. Mark the op as non-cachable if the address
572 -- is the form 0xc------- for a real-mode access.
573 if addr(31 downto 28) = "1100" and l_in.virt_mode = '0' then
574 v.nc := '1';
575 end if;
576
577 if l_in.second = '0' then
578 -- Do length_to_sel and work out if we are doing 2 dwords
579 long_sel := xfer_data_sel(l_in.length, lsu_sum(2 downto 0));
580 byte_sel := long_sel(7 downto 0);
581 v.first_bytes := byte_sel;
582 v.second_bytes := long_sel(15 downto 8);
583 else
584 byte_sel := r.first_bytes;
585 long_sel := r.second_bytes & r.first_bytes;
586 end if;
587
588 -- check alignment for larx/stcx
589 misaligned := or (std_ulogic_vector(unsigned(l_in.length(2 downto 0)) - 1) and addr(2 downto 0));
590 v.align_intr := l_in.reserve and misaligned;
591 if l_in.repeat = '1' and l_in.second = '0' and addr(3) = '1' then
592 -- length is really 16 not 8
593 -- Make misaligned lq cause an alignment interrupt in LE mode,
594 -- in order to avoid the case with RA = RT + 1 where the second half
595 -- faults but the first doesn't (and updates RT+1, destroying RA).
596 -- The equivalent BE case doesn't occur because RA = RT is illegal.
597 misaligned := '1';
598 if l_in.reserve = '1' or (l_in.op = OP_LOAD and l_in.byte_reverse = '0') then
599 v.align_intr := '1';
600 end if;
601 end if;
602
603 v.atomic := not misaligned;
604 v.atomic_last := not misaligned and (l_in.second or not l_in.repeat);
605
606 case l_in.op is
607 when OP_STORE =>
608 if HAS_FPU and l_in.is_32bit = '1' then
609 v.state := FPR_CONV;
610 fp_reg_conv := '1';
611 else
612 req := '1';
613 end if;
614 when OP_LOAD =>
615 req := '1';
616 v.load := '1';
617 -- Allow an extra cycle for RA update on loads
618 v.extra_cycle := l_in.update;
619 if HAS_FPU and l_in.is_32bit = '1' then
620 -- Allow an extra cycle for SP->DP precision conversion
621 v.load_sp := '1';
622 v.extra_cycle := '1';
623 end if;
624 when OP_DCBZ =>
625 v.align_intr := v.nc;
626 req := '1';
627 v.dcbz := '1';
628 when OP_TLBIE =>
629 mmureq := '1';
630 v.tlbie := '1';
631 v.state := TLBIE_WAIT;
632 v.wait_mmu := '1';
633 when OP_MFSPR =>
634 v.mfspr := '1';
635 -- partial decode on SPR number should be adequate given
636 -- the restricted set that get sent down this path
637 if sprn(9) = '0' and sprn(5) = '0' then
638 if sprn(0) = '0' then
639 v.sprval := x"00000000" & r.dsisr;
640 else
641 v.sprval := r.dar;
642 end if;
643 else
644 -- reading one of the SPRs in the MMU
645 v.sprval := m_in.sprval;
646 end if;
647 v.state := COMPLETE;
648 when OP_MTSPR =>
649 if sprn(9) = '0' and sprn(5) = '0' then
650 if sprn(0) = '0' then
651 v.dsisr := l_in.data(31 downto 0);
652 else
653 v.dar := l_in.data;
654 end if;
655 v.state := COMPLETE;
656 else
657 -- writing one of the SPRs in the MMU
658 mmu_mtspr := '1';
659 v.state := TLBIE_WAIT;
660 v.wait_mmu := '1';
661 end if;
662 when OP_FETCH_FAILED =>
663 -- send it to the MMU to do the radix walk
664 maddr := l_in.nia;
665 v.instr_fault := '1';
666 mmureq := '1';
667 v.state := MMU_LOOKUP;
668 v.wait_mmu := '1';
669 when others =>
670 assert false report "unknown op sent to loadstore1";
671 end case;
672
673 if req = '1' then
674 if v.align_intr = '1' then
675 v.state := COMPLETE;
676 elsif long_sel(15 downto 8) = "00000000" then
677 v.state := ACK_WAIT;
678 else
679 v.state := SECOND_REQ;
680 end if;
681 end if;
682
683 v.busy := req or mmureq or mmu_mtspr or fp_reg_conv;
684 end if;
685
686 -- Work out load formatter controls for next cycle
687 byte_offset := unsigned(v.addr(2 downto 0));
688 brev_lenm1 := "000";
689 if v.byte_reverse = '1' then
690 brev_lenm1 := unsigned(v.length(2 downto 0)) - 1;
691 end if;
692
693 for i in 0 to 7 loop
694 kk := ('0' & (to_unsigned(i, 3) xor brev_lenm1)) + ('0' & byte_offset);
695 v.use_second(i) := kk(3);
696 v.byte_index(i) := kk(2 downto 0);
697 end loop;
698
699 for i in 0 to 7 loop
700 if i < to_integer(unsigned(v.length)) then
701 if v.dwords_done = '1' then
702 v.trim_ctl(i) := '1' & not v.use_second(i);
703 else
704 v.trim_ctl(i) := "10";
705 end if;
706 else
707 v.trim_ctl(i) := '0' & v.sign_extend;
708 end if;
709 end loop;
710
711 -- Update outputs to dcache
712 d_out.valid <= req and not v.align_intr;
713 d_out.load <= v.load;
714 d_out.dcbz <= v.dcbz;
715 d_out.nc <= v.nc;
716 d_out.reserve <= v.reserve;
717 d_out.atomic <= v.atomic;
718 d_out.atomic_last <= v.atomic_last;
719 d_out.addr <= addr;
720 d_out.data <= store_data;
721 d_out.byte_sel <= byte_sel;
722 d_out.virt_mode <= v.virt_mode;
723 d_out.priv_mode <= v.priv_mode;
724
725 -- Update outputs to MMU
726 m_out.valid <= mmureq;
727 m_out.iside <= v.instr_fault;
728 m_out.load <= r.load;
729 m_out.priv <= r.priv_mode;
730 m_out.tlbie <= v.tlbie;
731 m_out.mtspr <= mmu_mtspr;
732 m_out.sprn <= sprn;
733 m_out.addr <= maddr;
734 m_out.slbia <= l_in.insn(7);
735 m_out.rs <= l_in.data;
736
737 -- Update outputs to writeback
738 -- Multiplex either cache data to the destination GPR or
739 -- the address for the rA update.
740 l_out.valid <= done;
741 if r.mfspr = '1' then
742 l_out.write_enable <= '1';
743 l_out.write_reg <= r.write_reg;
744 l_out.write_data <= r.sprval;
745 elsif do_update = '1' then
746 l_out.write_enable <= '1';
747 l_out.write_reg <= gpr_to_gspr(r.update_reg);
748 l_out.write_data <= r.addr;
749 elsif lfs_done = '1' then
750 l_out.write_enable <= '1';
751 l_out.write_reg <= r.write_reg;
752 l_out.write_data <= load_dp_data;
753 else
754 l_out.write_enable <= write_enable;
755 l_out.write_reg <= r.write_reg;
756 l_out.write_data <= data_trimmed;
757 end if;
758 l_out.xerc <= r.xerc;
759 l_out.rc <= r.rc and done;
760 l_out.store_done <= d_in.store_done;
761
762 -- update exception info back to execute1
763 e_out.busy <= busy;
764 e_out.exception <= exception;
765 e_out.alignment <= r.align_intr;
766 e_out.instr_fault <= r.instr_fault;
767 e_out.invalid <= m_in.invalid;
768 e_out.badtree <= m_in.badtree;
769 e_out.perm_error <= m_in.perm_error;
770 e_out.rc_error <= m_in.rc_error;
771 e_out.segment_fault <= m_in.segerr;
772 if exception = '1' and r.instr_fault = '0' then
773 v.dar := addr;
774 if m_in.segerr = '0' and r.align_intr = '0' then
775 v.dsisr := dsisr;
776 end if;
777 end if;
778
779 -- Update registers
780 rin <= v;
781
782 end process;
783
784 l1_log: if LOG_LENGTH > 0 generate
785 signal log_data : std_ulogic_vector(9 downto 0);
786 begin
787 ls1_log: process(clk)
788 begin
789 if rising_edge(clk) then
790 log_data <= e_out.busy &
791 e_out.exception &
792 l_out.valid &
793 m_out.valid &
794 d_out.valid &
795 m_in.done &
796 r.dwords_done &
797 std_ulogic_vector(to_unsigned(state_t'pos(r.state), 3));
798 end if;
799 end process;
800 log_out <= log_data;
801 end generate;
802
803 end;