wb.vhd 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use work.core_pkg.all;
  5. use work.op_pkg.all;
  6. entity wb is
  7. port (
  8. clk : in std_logic;
  9. res_n : in std_logic;
  10. stall : in std_logic;
  11. flush : in std_logic;
  12. -- from MEM
  13. op : in wb_op_type;
  14. aluresult : in data_type;
  15. memresult : in data_type;
  16. pc_old_in : in pc_type;
  17. -- to FWD and DEC
  18. reg_write : out reg_write_type
  19. );
  20. end entity;
  21. architecture rtl of wb is
  22. type internal_t is record
  23. op : wb_op_type;
  24. aluresult : data_type;
  25. memresult : data_type;
  26. pc_old : pc_type;
  27. end record;
  28. signal internal : internal_t;
  29. constant INITIAL_INTERNAL : internal_t := (
  30. WB_NOP,
  31. (others => '0'),
  32. (others => '0'),
  33. (others => '0')
  34. );
  35. begin
  36. --syncronous
  37. sync : process(clk, res_n, flush, stall)
  38. begin
  39. if res_n = '0' then
  40. internal <= INITIAL_INTERNAL;
  41. elsif stall = '0' and rising_edge(clk) then
  42. internal.op <= op;
  43. internal.aluresult <= aluresult;
  44. internal.memresult <= memresult;
  45. internal.pc_old <= pc_old_in;
  46. end if;
  47. end process;
  48. --concurrent
  49. reg_write.reg <= internal.op.rd;
  50. reg_write.write <= internal.op.write when flush = '0' else '0';
  51. with internal.op.src select reg_write.data <=
  52. internal.aluresult when WBS_ALU,
  53. internal.memresult when WBS_MEM,
  54. std_logic_vector(x"00000000" + unsigned(internal.pc_old) + x"4") when WBS_OPC;
  55. end architecture;