Advertisement
madegoff

Untitled

Jan 15th, 2023
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.12 KB | None | 0 0
  1. #richtiger Code
  2.  
  3. library ieee;
  4. use ieee.std_logic_1164.all;
  5. use ieee.numeric_std.all;
  6.  
  7. library work;
  8. use work.proc_config.all;
  9.  
  10. entity mipsCpu is
  11. generic(PROG_FILE_NAME : string;
  12. DATA_FILE_NAME : string
  13. );
  14. port(clk : in std_logic;
  15. rst : in std_logic;
  16.  
  17. -- instruction insertion ports
  18. testMode_debug : in std_logic;
  19. testInstruction_debug : in std_logic_vector(31 downto 0);
  20.  
  21. -- ram access ports
  22. ramInsertMode_debug : in std_logic; -- wenn das Signal = 1 , werden alle drei unteren weitergegeben; wenn 0 - drei MUX (um zu entscheiden ob unsere oder debug Signale genutyt werden sollen)
  23. ramWriteEn_debug : in std_logic;
  24. ramWriteAddr_debug : in std_logic_vector(LOG2_NUM_RAM_ELEMENTS - 1 downto 0);
  25. ramWriteData_debug : in std_logic_vector(RAM_ELEMENT_WIDTH - 1 downto 0);
  26. ramElements_debug : out ram_elements_type;
  27.  
  28. -- register file access port
  29. registers_debug : out reg_vector_type;
  30.  
  31. -- intermediate result ports
  32. pc_next_debug : out std_logic_vector(PC_WIDTH - 1 downto 0);
  33. pc7SegDigits_debug : out pc_7seg_digits_type
  34. );
  35. end mipsCpu;
  36.  
  37. architecture structural of mipsCpu is
  38.  
  39. --Signale Instruction Mux
  40. signal instruction_rom : std_logic_vector(31 downto 0);
  41. signal instruction : std_logic_vector(31 downto 0);
  42.  
  43. --Signale Instruction Memory
  44. signal addr_pc : std_logic_vector(31 downto 0);
  45.  
  46. --Signale Control
  47. signal regDst : std_logic;
  48. signal branch : std_logic;
  49. signal memRead : std_logic;
  50. signal memToReg : std_logic;
  51. signal aluOp : std_logic_vector(1 downto 0);
  52. signal memWrite : std_logic;
  53. signal aluSrc : std_logic;
  54. signal regWrite : std_logic; --in bei RegisterFile
  55.  
  56. --Signale Registers (mittig)
  57. signal writeReg : std_logic_vector(4 downto 0);
  58. signal writeData : std_logic_vector(31 downto 0);
  59.  
  60. signal readData1 : std_logic_vector(31 downto 0);
  61. signal readData2 : std_logic_vector(31 downto 0);
  62.  
  63. --Signale RAM
  64. signal ramWriteEn : std_logic;
  65. signal ramWriteAddr : std_logic_vector(9 downto 0);
  66. signal ramWriteData : std_logic_vector(31 downto 0);
  67. signal ramReadData : std_logic_vector(31 downto 0);
  68.  
  69. --Signale Sign Extend
  70. signal signExtendNumber : std_logic_vector(31 downto 0);
  71.  
  72. --Signale Shift Left 2
  73. signal shiftedNumber : std_logic_vector(31 downto 0);
  74.  
  75. --Signale ALU Control
  76. signal operation : std_logic_vector(3 downto 0);
  77.  
  78. --Signale ALU
  79. signal aluResult : std_logic_vector(31 downto 0);
  80. signal zero : std_logic;
  81. --zusaetzliche Signale
  82. signal muxalu : std_logic_vector(31 downto 0); -- auch der 4. MUX
  83. signal mux3 : std_logic_vector(31 downto 0);
  84. signal muxRamOut : std_logic_vector(31 downto 0); -- auch der 2. Mux
  85. signal muxRamIn : std_logic_vector(31 downto 0);
  86.  
  87. signal invClk : std_logic; -- invert clk
  88.  
  89. signal and_out : std_logic;
  90.  
  91.  
  92. --Signale Addierer
  93. signal add2 : std_logic_vector(31 downto 0);
  94. signal add1: std_logic_vector(31 downto 0);
  95.  
  96.  
  97. begin
  98.  
  99. invClk <= not clk;
  100.  
  101.  
  102. with testMode_debug select
  103. instruction <= testInstruction_debug when '1',
  104. instruction_rom when others;
  105.  
  106. -- Beschreibung der MIPS-CPU ergänzen
  107.  
  108.  
  109. control: entity work.mipsCtrl(structural) --Beschreibung des Control MIPS
  110. port map( op(5 downto 0) => instruction(31 downto 26),
  111. regDst => regDst,
  112. branch => branch,
  113. memRead => memRead,
  114. memToReg => memToReg,
  115. aluOp(1 downto 0) => aluOp(1 downto 0),
  116. memWrite => memWrite,
  117. aluSrc => aluSrc,
  118. regWrite => regWrite);
  119.  
  120. and_out <= branch and zero;
  121.  
  122.  
  123. --ramInsertMode_debug : in std_logic; -- wenn das Signal = 1 , werden alle drei unteren weitergegeben; wenn 0 - drei MUX (um zuentscheiden ob unsere oder debug Signale genutyt werden sollen)
  124. --ramWriteEn_debug : in std_logic;
  125. --ramWriteAddr_debug : in std_logic_vector(LOG2_NUM_RAM_ELEMENTS - 1 downto 0);
  126. --ramWriteData_debug : in std_logic_vector(RAM_ELEMENT_WIDTH - 1 downto 0);
  127.  
  128. with ramInsertMode_debug select -- Beschreibung des MUX vor dem RAM (Kommentar oben)
  129. ramWriteEn <= ramWriteEn_debug when '1',
  130. memWrite when others;
  131. with ramInsertMode_debug select
  132. ramWriteAddr <= ramWriteAddr_debug when '1',
  133. aluResult(11 downto 2) when others;
  134. with ramInsertMode_debug select
  135. ramWriteData <= ramWriteData_debug when '1',
  136. readData2 when others;
  137.  
  138.  
  139.  
  140. with regDst select --Beschreibung des ersten MUXs
  141. writeReg <= instruction(20 downto 16) when '0',
  142. instruction(15 downto 11) when others;
  143.  
  144. with memToReg select -- Beschreibung zweites MUXs
  145. muxRamOut <= ramReadData when '1',
  146. aluResult when others;
  147.  
  148. with and_out select -- Beschreibung des dritten MUXs
  149. mux3 <= add1 when '0',
  150. add2 when others;
  151.  
  152. with aluSrc select -- Beschreibung des vierten MUXs
  153. muxalu <= readData2 when '0',
  154. signExtendNumber when others;
  155.  
  156.  
  157. signextend : entity work.signExtend(behavioral) --Beschreibung des SignExtend
  158. generic map(INPUT_WIDTH => 16,
  159. OUTPUT_WIDTH => 32)
  160. port map(number => signed(instruction(15 downto 0)),
  161. std_logic_vector(signExtNumber) => signExtendNumber(31 downto 0)); --(31 downto 0) rechts - noetig?
  162.  
  163.  
  164. shiftleft2 : entity work.leftShifter --Beschreibung ShiftLeft
  165. generic map(WIDTH => 32,
  166. SHIFT_AMOUNT => 2)
  167. port map(number => signExtendNumber,
  168. shiftedNumber => shiftedNumber);
  169.  
  170. alucontrol : entity work.aluCtrl --Beschreibung ALU Control
  171. port map(f(5 downto 0) => instruction(5 downto 0),
  172. aluOp(1 downto 0) => aluOp(1 downto 0),
  173. operation(3 downto 0) => operation(3 downto 0));
  174.  
  175. alu : entity work.mipsAlu -- Beschreibung ALU
  176. generic map(WIDTH => 32)
  177. port map(ctrl(3 downto 0) => operation(3 downto 0),
  178. a => readData1,
  179. b => muxalu,
  180. result => aluResult,
  181. zero => zero);
  182.  
  183.  
  184. -- Beschreibung Addierers
  185.  
  186. add1 <= std_logic_vector(4 + unsigned(addr_pc));
  187. add2 <= std_logic_vector(unsigned(add1) + unsigned(shiftedNumber));
  188.  
  189. --Beschreibung BinToChars
  190. binToChar1 : entity work.bin2Char
  191. port map(bin => addr_pc(3 downto 0),
  192. bitmask => pc7SegDigits_debug(0));
  193.  
  194. binToChar2 : entity work.bin2Char
  195. port map(bin => addr_pc(7 downto 4),
  196. bitmask => pc7SegDigits_debug(1));
  197.  
  198. binToChar3 : entity work.bin2Char
  199. port map(bin => addr_pc(11 downto 8),
  200. bitmask => pc7SegDigits_debug(2));
  201.  
  202. binToChar4 : entity work.bin2Char
  203. port map(bin => addr_pc(15 downto 12),
  204. bitmask => pc7SegDigits_debug(3));
  205.  
  206.  
  207. --Beschreibung von RegFile
  208. regFile : entity work.regFile
  209. generic map(NUM_REGS => 32,
  210. LOG2_NUM_REGS => 5,
  211. REG_WIDTH => 32)
  212. port map(clk => clk,
  213. rst => rst,
  214. readAddr1 => instruction(25 downto 21),-- in
  215. readData1 => readData1, --out
  216. readAddr2 => instruction(20 downto 16), --in
  217. readData2 => readData2, --out
  218. writeEn => regWrite, -- Eingang hier, Ausgang von MIPS Control
  219. writeAddr => writeReg, -- eingang WriteRegister, Ausgang des ersten MUXs
  220. writeData => muxRamOut, -- eingang WriteData = Ausgang des zweiten MUXs
  221. reg_vect_debug => registers_debug);
  222.  
  223.  
  224. -- Instruction Memory
  225. INSTR_ROM: entity work.flashROM(behavioral) -- nutzen Worte (4 Bits) -- PC auf 4 teilen
  226. generic map(NUM_ELEMENTS => 1024,
  227. LOG2_NUM_ELEMENTS => 10,
  228. ELEMENT_WIDTH => 32,
  229. INIT_FILE_NAME => PROG_FILE_NAME)
  230. port map(address => addr_pc(11 downto 2), -- pc_next_debug?
  231. readData => instruction_rom);
  232.  
  233. -- Data Memory
  234. DATA_RAM: entity work.flashRAM(behavioral)
  235. generic map(NUM_ELEMENTS => 1024 ,
  236. LOG2_NUM_ELEMENTS => 10,
  237. ELEMENT_WIDTH => 32,
  238. INIT_FILE_NAME => DATA_FILE_NAME)
  239. port map(clk => invClk,
  240. address => ramWriteAddr,
  241. writeEn => ramWriteEn,
  242. writeData => ramWriteData,
  243. readEn => memRead,
  244. readData => ramReadData,
  245. ramElements_debug => ramElements_debug);
  246.  
  247. PC: entity work.reg --Beschreibung PC
  248. generic map(
  249. WIDTH => 32)
  250. port map(
  251. clk => clk,
  252. rst => rst,
  253. en => not testMode_debug, -- kA obs richtig is
  254. D => mux3,-- in, Ausgang 3 MUXs
  255. Q => addr_pc); -- out
  256.  
  257. pc_next_debug <= mux3;
  258.  
  259. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement