ctrl.vhd 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 ctrl is
  7. port (
  8. clk : in std_logic;
  9. res_n : in std_logic;
  10. stall : in std_logic;
  11. stall_fetch : out std_logic;
  12. stall_dec : out std_logic;
  13. stall_exec : out std_logic;
  14. stall_mem : out std_logic;
  15. stall_wb : out std_logic;
  16. flush_fetch : out std_logic;
  17. flush_dec : out std_logic;
  18. flush_exec : out std_logic;
  19. flush_mem : out std_logic;
  20. flush_wb : out std_logic;
  21. -- from FWD
  22. wb_op_exec : in wb_op_type;
  23. exec_op_dec : in exec_op_type;
  24. -- from MEM
  25. pcsrc_in : in std_logic;
  26. pcsrc_out : out std_logic
  27. );
  28. end entity;
  29. architecture rtl of ctrl is
  30. signal flush_branch_ctrl : std_logic;
  31. signal stall_fwd_ctrl : std_logic;
  32. begin
  33. -- concurrent
  34. stall_fwd_ctrl <= '1' when wb_op_exec.src = WBS_MEM and (exec_op_dec.rs1 = wb_op_exec.rd or exec_op_dec.rs2 = wb_op_exec.rd) else '0';
  35. pcsrc_out <= '0';
  36. flush_branch_ctrl <= pcsrc_in;
  37. flush_fetch <= flush_branch_ctrl;
  38. flush_dec <= flush_branch_ctrl;
  39. flush_exec <= flush_branch_ctrl;
  40. flush_mem <= '0';
  41. flush_wb <= '0';
  42. -- sequential
  43. sync : process(clk, res_n, stall)
  44. begin
  45. if res_n = '0' then
  46. stall_fetch <= '0';
  47. stall_dec <= '0';
  48. stall_exec <= '0';
  49. stall_mem <= '0';
  50. stall_wb <= '0';
  51. elsif rising_edge(clk) and stall = '0' then
  52. stall_fetch <= stall_fwd_ctrl;
  53. stall_dec <= stall_fwd_ctrl;
  54. stall_exec <= stall_fwd_ctrl;
  55. stall_mem <= stall_fwd_ctrl;
  56. stall_wb <= stall_fwd_ctrl;
  57. end if;
  58. end process;
  59. end architecture;