Advertisement
madegoff

Zustandsautomat MipsCtrl

Jan 19th, 2023 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. library work;
  5. use work.proc_config.mips_ctrl_state_type;
  6. use work.mipsISA.all;
  7.  
  8. entity mipsCtrlFsm is
  9. port(clk : in std_logic;
  10. rst : in std_logic;
  11. op : in std_logic_vector(5 downto 0);
  12. jr : in std_logic;
  13. regDst : out std_logic_vector(1 downto 0);
  14. memRead : out std_logic;
  15. memToReg : out std_logic;
  16. aluOp : out std_logic_vector(1 downto 0);
  17. memWrite : out std_logic;
  18. regWrite : out std_logic;
  19. aluSrcA : out std_logic;
  20. aluSrcB : out std_logic_vector(1 downto 0);
  21. pcSrc : out std_logic_vector(1 downto 0);
  22. irWrite : out std_logic;
  23. IorD : out std_logic;
  24. pcWrite : out std_logic;
  25. pcWriteCond : out std_logic;
  26. lui : out std_logic;
  27.  
  28. -- debug port
  29. mipsCtrlState_debug : out mips_ctrl_state_type);
  30. end mipsCtrlFsm;
  31.  
  32. architecture behavioral of mipsCtrlFsm is
  33. signal state_reg : mips_ctrl_state_type;
  34. signal zustand : mips_ctrl_state_type;
  35. signal folge : mips_ctrl_state_type;
  36. begin
  37. z_speicher: process (clk, rst)
  38. begin
  39. if clk = '1' and clk'event then
  40. if rst = '1' then zustand <= INSTR_FETCH;
  41. else
  42. zustand <= folge;
  43. end if;
  44. end if;
  45. end process z_speicher;
  46.  
  47. uebergang: process(op, jr, zustand) -- Folgezustandsberechnung
  48. begin
  49.  
  50.  
  51. case zustand is
  52.  
  53. when INSTR_FETCH => folge <= INSTR_DECODE;
  54.  
  55. when INSTR_DECODE => if (op = "100011" or op = "101011") then folge <= MEM_ADDR_CALC;--Memory address computation, LW/SW
  56. elsif (op = "001000") or (op = "001001") then folge <= ADDI_CALC; -- ADDI Computation, ADDI/ADDIU
  57. elsif (op = "000000") then folge <= EXECUTION; --Execution, R-type
  58. elsif (op = "000011") then folge <= JAL_ADD; --JAL add, JAL
  59. elsif (op = "000010") then folge <= JUMP_COMPL; -- Jump completion, J
  60. elsif (op = "001111") then folge <= LUI_COMPL; -- LUI completion, LUI
  61. elsif (op = "000100") then folge <= BRANCH_COMPL; --Branch completion, BEQ
  62. else folge <= INSTR_FETCH; --Instruction Fetch
  63. end if;
  64.  
  65. when MEM_ADDR_CALC => if (op = "100011") then folge <= MEM_READ; --Memory access, LW
  66. else folge <= MEM_WRITE; --Memory access, SW
  67. end if;
  68.  
  69. when ADDI_CALC => folge <= ITYPE_COMPL; --I-type completion step
  70.  
  71. when EXECUTION => if (jr = '1') then folge <= JR_COMPL; -- JR completion, JR = 1
  72. else folge <= RTYPE_COMPL; -- R-type completion step, others
  73. end if;
  74.  
  75. when JAL_ADD => folge <= LR_WRITE; -- LR write
  76.  
  77. when LR_WRITE => folge <= JUMP_COMPL;
  78.  
  79. when MEM_READ => folge <= MEM_READ_COMPL;
  80.  
  81. --Letzter Uebergang, um die Schaltung zyklisch zu machen
  82. when MEM_READ_COMPL | MEM_WRITE | ITYPE_COMPL | RTYPE_COMPL | JR_COMPL | JUMP_COMPL | LUI_COMPL | BRANCH_COMPL =>
  83. folge <= INSTR_FETCH;
  84.  
  85. end case;
  86. end process uebergang;
  87.  
  88. -- noch ein Prozess fuer Ausgabeberechnung;
  89.  
  90. ausgabe: process(zustand)
  91. begin
  92. --alle Ausgabesignale auf 0 setzen
  93. regDst <= "00";
  94. memRead <= '0';
  95. memToReg <= '0';
  96. aluOp <= "00";
  97. memWrite <= '0';
  98. regWrite <= '0';
  99. aluSrcA <= '0';
  100. aluSrcB <= "00";
  101. pcSrc <= "00";
  102. irWrite <= '0';
  103. IorD <= '0';
  104. pcWrite <= '0';
  105. pcWriteCond <= '0';
  106. lui <= '0';
  107.  
  108. case zustand is
  109.  
  110. when INSTR_FETCH =>
  111. memRead <= '1'; aluSrcA <= '0'; IorD <= '0'; irWrite <= '1'; aluSrcB <= "01"; aluOp <= "00"; pcWrite <= '1';
  112. pcSrc <= "00";
  113. when INSTR_DECODE =>
  114. aluSrcA <= '0'; aluSrcB <= "11"; aluOp <= "00";
  115. when MEM_ADDR_CALC =>
  116. aluSrcA <= '1'; aluSrcB <= "10"; aluOp <= "00";
  117. when ADDI_CALC =>
  118. aluSrcA <= '1'; aluSrcB <= "10"; aluOp <= "00";
  119. when EXECUTION =>
  120. aluSrcA <= '1'; aluSrcB <= "00"; aluOp <= "10";
  121. when JAL_ADD =>
  122. aluSrcA <= '0'; aluSrcB <= "01"; aluOp <= "00";
  123. when LUI_COMPL =>
  124. regDst <= "00"; regWrite <= '1'; memToReg <= '0'; lui <= '1';
  125. when BRANCH_COMPL =>
  126. aluSrcA <= '1'; aluSrcB <= "00"; aluOp <= "01"; pcWriteCond <= '1'; pcSrc <= "01";
  127. when LR_WRITE =>
  128. regDst <= "10"; regWrite <= '1'; memToReg <= '0'; lui <= '0';
  129. when MEM_READ =>
  130. memRead <= '1'; IorD <= '1';
  131. when MEM_WRITE =>
  132. memWrite <= '1'; IorD <= '1';
  133. when ITYPE_COMPL =>
  134. regDst <= "00"; regWrite <= '1'; memToReg <= '0'; lui <= '0';
  135. when RTYPE_COMPL =>
  136. regDst <= "01"; regWrite <= '1'; memToReg <= '0'; lui <= '0';
  137. when JR_COMPL =>
  138. pcWrite <= '1'; pcSrc <= "01";
  139. when JUMP_COMPL =>
  140. pcWrite <= '1'; pcSrc <= "10";
  141. when MEM_READ_COMPL =>
  142. regDst <= "00"; regWrite <= '1'; memToReg <= '1';
  143. end case;
  144. end process ausgabe;
  145. mipsCtrlState_debug <= zustand;
  146.  
  147. end behavioral;
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement