ee62a05adf3edc311f79d818936a384d27476006
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

1) LIBRARY ieee;
2) USE ieee.std_logic_1164.all;
3) USE ieee.numeric_std.all;
4) USE work.mips_types.all;
5) 
6) ENTITY e_mips_core IS
7)     PORT (
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

8)         rst:          IN  std_logic;
9)         clk:          IN  std_logic;
10)         o_instr_addr: OUT std_logic_vector(31 DOWNTO 0);
11)         i_instr_data: IN  std_logic_vector(31 DOWNTO 0)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

12)     );
13) END ENTITY e_mips_core;
14) 
15) ARCHITECTURE a_mips_core OF e_mips_core IS
16) 
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

17)     SIGNAL r_pc: std_logic_vector(31 DOWNTO 0);
18)     SIGNAL n_pc: std_logic_vector(31 DOWNTO 0);
19) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

20)     SIGNAL s_instr: std_logic_vector(31 DOWNTO 0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

21) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

22)     SIGNAL n_reg_s:  std_logic_vector( 4 DOWNTO 0);
23)     SIGNAL n_reg_t:  std_logic_vector( 4 DOWNTO 0);
24)     SIGNAL n_reg_d:  std_logic_vector( 4 DOWNTO 0);
25)     SIGNAL n_imm_a:  std_logic_vector( 4 DOWNTO 0);
26)     SIGNAL n_imm_16: std_logic_vector(15 DOWNTO 0);
27)     SIGNAL n_imm_26: std_logic_vector(25 DOWNTO 0);
28)     SIGNAL n_op:     t_op;
29)     SIGNAL n_link:   t_link;
30)     SIGNAL n_cmp:    t_cmp;
31)     SIGNAL n_alu:    t_alu;
32)     SIGNAL n_imm:    t_imm;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

33)     SIGNAL n_ldst:   t_ldst;
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

34) 
35)     SIGNAL r_reg_s:  std_logic_vector( 4 DOWNTO 0);
36)     SIGNAL r_reg_t:  std_logic_vector( 4 DOWNTO 0);
37)     SIGNAL r_reg_d:  std_logic_vector( 4 DOWNTO 0);
38)     SIGNAL r_imm_a:  std_logic_vector( 4 DOWNTO 0);
39)     SIGNAL r_imm_16: std_logic_vector(15 DOWNTO 0);
40)     SIGNAL r_imm_26: std_logic_vector(25 DOWNTO 0);
41)     SIGNAL r_op:     t_op;
42)     SIGNAL r_link:   t_link;
43)     SIGNAL r_cmp:    t_cmp;
44)     SIGNAL r_alu:    t_alu;
45)     SIGNAL r_imm:    t_imm;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

46)     SIGNAL r_ldst:   t_ldst;
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

47) 
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

48)     SIGNAL s_val_s: std_logic_vector(31 DOWNTO 0);
49)     SIGNAL s_val_t: std_logic_vector(31 DOWNTO 0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

50) 
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

51)     SIGNAL s_alu_op1: std_logic_vector(31 DOWNTO 0);
52)     SIGNAL s_alu_op2: std_logic_vector(31 DOWNTO 0);
53)     SIGNAL s_alu_res: std_logic_vector(31 DOWNTO 0);
54) 
55)     SIGNAL s_cmp_op1: std_logic_vector(31 DOWNTO 0);
56)     SIGNAL s_cmp_op2: std_logic_vector(31 DOWNTO 0);
57)     SIGNAL s_cmp_res: std_logic;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

58) 
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

59)     SIGNAL s_reg_wr_no:   std_logic_vector( 4 DOWNTO 0);
60)     SIGNAL s_reg_wr_data: std_logic_vector(31 DOWNTO 0);
61)     SIGNAL s_reg_wr_en:   std_logic;
62) 
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

63)     COMPONENT e_mips_decoder IS
64)         PORT (
65)             i_instr:  IN  std_logic_vector(31 DOWNTO 0);
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

66)             o_reg_s:  OUT std_logic_vector( 4 DOWNTO 0);
67)             o_reg_t:  OUT std_logic_vector( 4 DOWNTO 0);
68)             o_reg_d:  OUT std_logic_vector( 4 DOWNTO 0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

69)             o_imm_a:  OUT std_logic_vector( 4 DOWNTO 0);
70)             o_imm_16: OUT std_logic_vector(15 DOWNTO 0);
71)             o_imm_26: OUT std_logic_vector(25 DOWNTO 0);
72)             o_op:     OUT t_op;
73)             o_link:   OUT t_link;
74)             o_cmp:    OUT t_cmp;
75)             o_alu:    OUT t_alu;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

76)             o_imm:    OUT t_imm;
77)             o_ldst:   OUT t_ldst
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

78)         );
79)     END COMPONENT e_mips_decoder;
80) 
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

81)     COMPONENT e_mips_regs IS
82)         PORT (
83)             rst:         IN  std_logic;
84)             clk:         IN  std_logic;
85)             i_rd_a_no:   IN  std_logic_vector( 4 DOWNTO 0);
86)             o_rd_a_data: OUT std_logic_vector(31 DOWNTO 0);
87)             i_rd_b_no:   IN  std_logic_vector( 4 DOWNTO 0);
88)             o_rd_b_data: OUT std_logic_vector(31 DOWNTO 0);
89)             i_wr_no:     IN  std_logic_vector( 4 DOWNTO 0);
90)             i_wr_data:   IN  std_logic_vector(31 DOWNTO 0);
91)             i_wr_en:     IN  std_logic
92)         );
93)     END COMPONENT e_mips_regs;
94) 
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

95)     COMPONENT e_mips_alu IS
96)         PORT (
97)             i_alu: IN  t_alu;
98)             i_op1: IN  std_logic_vector(31 DOWNTO 0);
99)             i_op2: IN  std_logic_vector(31 DOWNTO 0);
100)             o_res: OUT std_logic_vector(31 DOWNTO 0)
101)         );
102)     END COMPONENT e_mips_alu;
103) 
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

104)     COMPONENT e_mips_cmp IS
105)         PORT (
106)             i_cmp: IN  t_cmp;
107)             i_op1: IN  std_logic_vector(31 DOWNTO 0);
108)             i_op2: IN  std_logic_vector(31 DOWNTO 0);
109)             o_res: OUT std_logic
110)         );
111)     END COMPONENT e_mips_cmp;
112) 
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

113) BEGIN
114) 
115)     decoder: e_mips_decoder
116)         PORT MAP (
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

117)             i_instr  => s_instr,
118)             o_reg_s  => n_reg_s,
119)             o_reg_t  => n_reg_t,
120)             o_reg_d  => n_reg_d,
121)             o_imm_a  => n_imm_a,
122)             o_imm_16 => n_imm_16,
123)             o_imm_26 => n_imm_26,
124)             o_op     => n_op,
125)             o_link   => n_link,
126)             o_cmp    => n_cmp,
127)             o_alu    => n_alu,
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

128)             o_imm    => n_imm,
129)             o_ldst   => n_ldst
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

130)         );
131) 
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

132)     regs: e_mips_regs
133)         PORT MAP (
134)             rst         => rst,
135)             clk         => clk,
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

136)             i_rd_a_no   => r_reg_s,
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

137)             o_rd_a_data => s_val_s,
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

138)             i_rd_b_no   => r_reg_t,
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

139)             o_rd_b_data => s_val_t,
140)             i_wr_no     => s_reg_wr_no,
141)             i_wr_data   => s_reg_wr_data,
142)             i_wr_en     => s_reg_wr_en
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

143)         );
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

144) 
145)     alu: e_mips_alu
146)         PORT MAP (
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

147)             i_alu => r_alu,
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

148)             i_op1 => s_alu_op1,
149)             i_op2 => s_alu_op2,
150)             o_res => s_alu_res
151)         );
152) 
153)     cmp: e_mips_cmp
154)         PORT MAP (
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

155)             i_cmp => r_cmp,
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

156)             i_op1 => s_cmp_op1,
157)             i_op2 => s_cmp_op2,
158)             o_res => s_cmp_res
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

159)         );
160) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

161)     p_sync_pc: PROCESS(rst, clk)
162)     BEGIN
163)         IF rst = '1' THEN
164)             r_pc <= (OTHERS => '0');
165)         ELSIF rising_edge(clk) THEN
166)             r_pc <= n_pc;
167)         END IF;
168)     END PROCESS p_sync_pc;
169) 
170)     p_fetch: PROCESS(n_pc, i_instr_data)
171)     BEGIN
172)         o_instr_addr <= n_pc;
173)         s_instr      <= i_instr_data;
174)     END PROCESS p_fetch;
175) 
176)     p_dec2ex: PROCESS(rst, clk)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

177)     BEGIN
178)         IF rst = '1' THEN
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

179)             r_reg_s  <= (OTHERS => '0');
180)             r_reg_t  <= (OTHERS => '0');
181)             r_reg_d  <= (OTHERS => '0');
182)             r_imm_a  <= (OTHERS => '0');
183)             r_imm_16 <= (OTHERS => '0');
184)             r_imm_26 <= (OTHERS => '0');
185)             r_op     <= op_none;
186)             r_link   <= link_none;
187)             r_cmp    <= cmp_none;
188)             r_alu    <= alu_none;
189)             r_imm    <= imm_none;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

190)             r_ldst   <= ldst_none;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

191)         ELSIF rising_edge(clk) THEN
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

192)             r_reg_s  <= n_reg_s;
193)             r_reg_t  <= n_reg_t;
194)             r_reg_d  <= n_reg_d;
195)             r_imm_a  <= n_imm_a;
196)             r_imm_16 <= n_imm_16;
197)             r_imm_26 <= n_imm_26;
198)             r_op     <= n_op;
199)             r_link   <= n_link;
200)             r_cmp    <= n_cmp;
201)             r_alu    <= n_alu;
202)             r_imm    <= n_imm;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

203)             r_ldst   <= n_ldst;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

204)         END IF;
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

205)     END PROCESS p_dec2ex;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

206) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

207)     p_alu_in: PROCESS(r_op, r_imm, s_val_s, s_val_t, r_imm_a, r_imm_16)
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

208)     BEGIN
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

209)         s_alu_op1 <= (OTHERS => '0');
210)         s_alu_op2 <= (OTHERS => '0');
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

211)         IF r_op = op_alu THEN
212)             CASE r_imm IS
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

213)                 WHEN imm_none =>
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

214)                     s_alu_op1 <= s_val_s;
215)                     s_alu_op2 <= s_val_t;
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

216)                 WHEN imm_a =>
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

217)                     s_alu_op1(4 DOWNTO 0) <= r_imm_a;
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

218)                     s_alu_op2 <= s_val_t;
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

219)                 WHEN imm_16se =>
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

220)                     s_alu_op1 <= s_val_s;
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

221)                     s_alu_op2(15 DOWNTO 0) <= r_imm_16;
222)                     IF (r_imm_16(15) = '1') THEN
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

223)                         s_alu_op2(31 DOWNTO 16) <= (OTHERS => '1');
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

224)                     END IF;
225)                 WHEN imm_16ze =>
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

226)                     s_alu_op1 <= s_val_s;
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

227)                     s_alu_op2(15 DOWNTO 0) <= r_imm_16;
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

228)                 WHEN OTHERS => NULL;
229)             END CASE;
230)         END IF;
231)     END PROCESS p_alu_in;
232) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

233)     p_cmp_in: PROCESS(r_op, s_val_s, s_val_t)
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

234)     BEGIN
235)         s_cmp_op1 <= (OTHERS => '0');
236)         s_cmp_op2 <= (OTHERS => '0');
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

237)         IF r_op = op_j THEN
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

238)             s_cmp_op1 <= s_val_s;
239)             s_cmp_op2 <= s_val_t;
240)         END IF;
241)     END PROCESS p_cmp_in;
242) 
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

243)     p_reg_wr: PROCESS(r_op, r_imm, r_reg_t, r_reg_d, s_alu_res)
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

244)     BEGIN
245)         s_reg_wr_no   <= (OTHERS => '0');
246)         s_reg_wr_data <= (OTHERS => '0');
247)         s_reg_wr_en   <= '0';
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

248)         IF r_op = op_alu THEN
249)             CASE r_imm IS
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

250)                 WHEN imm_none | imm_a =>
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

251)                     s_reg_wr_no   <= r_reg_d;
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

252)                     s_reg_wr_data <= s_alu_res;
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

253)                     s_reg_wr_en   <= '1';
254)                 WHEN imm_16se | imm_16ze =>
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

255)                     s_reg_wr_no   <= r_reg_t;
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

256)                     s_reg_wr_data <= s_alu_res;
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

257)                     s_reg_wr_en   <= '1';
258)                 WHEN OTHERS => NULL;
259)             END CASE;
260)         END IF;
261)     END PROCESS p_reg_wr;
262) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

263)     p_next_pc: PROCESS(r_pc, r_op, r_imm, s_cmp_res, r_imm_16, r_imm_26)
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

264)         VARIABLE v_pc:  signed(31 DOWNTO 0);
265)         VARIABLE v_rel: signed(17 DOWNTO 0);
266)     BEGIN
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

267)         IF r_op = op_j AND s_cmp_res = '1' THEN
268)             IF r_imm = imm_26 THEN
269)                 n_pc <= r_pc(31 DOWNTO 28) & r_imm_26 & "00";
270)             ELSE
271)                 n_pc <= std_logic_vector(signed(r_pc) +
272)                                          signed(r_imm_16 & "00"));
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

273)             END IF;
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

274)         ELSE
275)             n_pc <= std_logic_vector(signed(r_pc) + to_signed(4, 32));
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

276)         END IF;
277)     END PROCESS p_next_pc;
278)