cr_file.vhdl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. library work;
  5. use work.common.all;
  6. entity cr_file is
  7. generic (
  8. SIM : boolean := false;
  9. -- Non-zero to enable log data collection
  10. LOG_LENGTH : natural := 0
  11. );
  12. port(
  13. clk : in std_logic;
  14. d_in : in Decode2ToCrFileType;
  15. d_out : out CrFileToDecode2Type;
  16. w_in : in WritebackToCrFileType;
  17. -- debug
  18. sim_dump : in std_ulogic;
  19. log_out : out std_ulogic_vector(12 downto 0)
  20. );
  21. end entity cr_file;
  22. architecture behaviour of cr_file is
  23. signal crs : std_ulogic_vector(31 downto 0) := (others => '0');
  24. signal crs_updated : std_ulogic_vector(31 downto 0);
  25. signal xerc : xer_common_t := xerc_init;
  26. signal xerc_updated : xer_common_t;
  27. begin
  28. cr_create_0: process(all)
  29. variable hi, lo : integer := 0;
  30. variable cr_tmp : std_ulogic_vector(31 downto 0) := (others => '0');
  31. begin
  32. cr_tmp := crs;
  33. for i in 0 to 7 loop
  34. if w_in.write_cr_mask(i) = '1' then
  35. lo := i*4;
  36. hi := lo + 3;
  37. cr_tmp(hi downto lo) := w_in.write_cr_data(hi downto lo);
  38. end if;
  39. end loop;
  40. crs_updated <= cr_tmp;
  41. if w_in.write_xerc_enable = '1' then
  42. xerc_updated <= w_in.write_xerc_data;
  43. else
  44. xerc_updated <= xerc;
  45. end if;
  46. end process;
  47. -- synchronous writes
  48. cr_write_0: process(clk)
  49. begin
  50. if rising_edge(clk) then
  51. if w_in.write_cr_enable = '1' then
  52. report "Writing " & to_hstring(w_in.write_cr_data) & " to CR mask " & to_hstring(w_in.write_cr_mask);
  53. crs <= crs_updated;
  54. end if;
  55. if w_in.write_xerc_enable = '1' then
  56. report "Writing XERC";
  57. xerc <= xerc_updated;
  58. end if;
  59. end if;
  60. end process;
  61. -- asynchronous reads
  62. cr_read_0: process(all)
  63. begin
  64. -- just return the entire CR to make mfcrf easier for now
  65. if d_in.read = '1' then
  66. report "Reading CR " & to_hstring(crs_updated);
  67. end if;
  68. d_out.read_cr_data <= crs_updated;
  69. d_out.read_xerc_data <= xerc_updated;
  70. end process;
  71. sim_dump_test: if SIM generate
  72. dump_cr: process(all)
  73. begin
  74. if sim_dump = '1' then
  75. report "CR 00000000" & to_hstring(crs);
  76. assert false report "end of test" severity failure;
  77. end if;
  78. end process;
  79. end generate;
  80. cf_log: if LOG_LENGTH > 0 generate
  81. signal log_data : std_ulogic_vector(12 downto 0);
  82. begin
  83. cr_log: process(clk)
  84. begin
  85. if rising_edge(clk) then
  86. log_data <= w_in.write_cr_enable &
  87. w_in.write_cr_data(31 downto 28) &
  88. w_in.write_cr_mask;
  89. end if;
  90. end process;
  91. log_out <= log_data;
  92. end generate;
  93. end architecture behaviour;