598eb9744a1fc32e3616cdfba0cde169378d4632
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;
33) 
34)     SIGNAL r_reg_s:  std_logic_vector( 4 DOWNTO 0);
35)     SIGNAL r_reg_t:  std_logic_vector( 4 DOWNTO 0);
36)     SIGNAL r_reg_d:  std_logic_vector( 4 DOWNTO 0);
37)     SIGNAL r_imm_a:  std_logic_vector( 4 DOWNTO 0);
38)     SIGNAL r_imm_16: std_logic_vector(15 DOWNTO 0);
39)     SIGNAL r_imm_26: std_logic_vector(25 DOWNTO 0);
40)     SIGNAL r_op:     t_op;
41)     SIGNAL r_link:   t_link;
42)     SIGNAL r_cmp:    t_cmp;
43)     SIGNAL r_alu:    t_alu;
44)     SIGNAL r_imm:    t_imm;
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

45) 
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

48) 
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

56) 
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

67)             o_imm_a:  OUT std_logic_vector( 4 DOWNTO 0);
68)             o_imm_16: OUT std_logic_vector(15 DOWNTO 0);
69)             o_imm_26: OUT std_logic_vector(25 DOWNTO 0);
70)             o_op:     OUT t_op;
71)             o_link:   OUT t_link;
72)             o_cmp:    OUT t_cmp;
73)             o_alu:    OUT t_alu;
74)             o_imm:    OUT t_imm
75)         );
76)     END COMPONENT e_mips_decoder;
77) 
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

110) BEGIN
111) 
112)     decoder: e_mips_decoder
113)         PORT MAP (
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

114)             i_instr  => s_instr,
115)             o_reg_s  => n_reg_s,
116)             o_reg_t  => n_reg_t,
117)             o_reg_d  => n_reg_d,
118)             o_imm_a  => n_imm_a,
119)             o_imm_16 => n_imm_16,
120)             o_imm_26 => n_imm_26,
121)             o_op     => n_op,
122)             o_link   => n_link,
123)             o_cmp    => n_cmp,
124)             o_alu    => n_alu,
125)             o_imm    => n_imm
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

126)         );
127) 
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

128)     regs: e_mips_regs
129)         PORT MAP (
130)             rst         => rst,
131)             clk         => clk,
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

135)             o_rd_b_data => s_val_t,
136)             i_wr_no     => s_reg_wr_no,
137)             i_wr_data   => s_reg_wr_data,
138)             i_wr_en     => s_reg_wr_en
Stefan Schuermans added register file

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

140) 
141)     alu: e_mips_alu
142)         PORT MAP (
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

144)             i_op1 => s_alu_op1,
145)             i_op2 => s_alu_op2,
146)             o_res => s_alu_res
147)         );
148) 
149)     cmp: e_mips_cmp
150)         PORT MAP (
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

152)             i_op1 => s_cmp_op1,
153)             i_op2 => s_cmp_op2,
154)             o_res => s_cmp_res
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

155)         );
156) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

175)             r_reg_s  <= (OTHERS => '0');
176)             r_reg_t  <= (OTHERS => '0');
177)             r_reg_d  <= (OTHERS => '0');
178)             r_imm_a  <= (OTHERS => '0');
179)             r_imm_16 <= (OTHERS => '0');
180)             r_imm_26 <= (OTHERS => '0');
181)             r_op     <= op_none;
182)             r_link   <= link_none;
183)             r_cmp    <= cmp_none;
184)             r_alu    <= alu_none;
185)             r_imm    <= imm_none;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

187)             r_reg_s  <= n_reg_s;
188)             r_reg_t  <= n_reg_t;
189)             r_reg_d  <= n_reg_d;
190)             r_imm_a  <= n_imm_a;
191)             r_imm_16 <= n_imm_16;
192)             r_imm_26 <= n_imm_26;
193)             r_op     <= n_op;
194)             r_link   <= n_link;
195)             r_cmp    <= n_cmp;
196)             r_alu    <= n_alu;
197)             r_imm    <= n_imm;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

201)     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

202)     BEGIN
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

205)         IF r_op = op_alu THEN
206)             CASE r_imm IS
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

208)                     s_alu_op1 <= s_val_s;
209)                     s_alu_op2 <= s_val_t;
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

218)                     END IF;
219)                 WHEN imm_16ze =>
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;
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

222)                 WHEN OTHERS => NULL;
223)             END CASE;
224)         END IF;
225)     END PROCESS p_alu_in;
226) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

227)     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

228)     BEGIN
229)         s_cmp_op1 <= (OTHERS => '0');
230)         s_cmp_op2 <= (OTHERS => '0');
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

232)             s_cmp_op1 <= s_val_s;
233)             s_cmp_op2 <= s_val_t;
234)         END IF;
235)     END PROCESS p_cmp_in;
236) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

238)     BEGIN
239)         s_reg_wr_no   <= (OTHERS => '0');
240)         s_reg_wr_data <= (OTHERS => '0');
241)         s_reg_wr_en   <= '0';
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

242)         IF r_op = op_alu THEN
243)             CASE r_imm IS
Stefan Schuermans implement correctly writing...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

251)                     s_reg_wr_en   <= '1';
252)                 WHEN OTHERS => NULL;
253)             END CASE;
254)         END IF;
255)     END PROCESS p_reg_wr;
256) 
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

257)     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

258)         VARIABLE v_pc:  signed(31 DOWNTO 0);
259)         VARIABLE v_rel: signed(17 DOWNTO 0);
260)     BEGIN
Stefan Schuermans implement jump logic, imple...

Stefan Schuermans authored 12 years ago

261)         IF r_op = op_j AND s_cmp_res = '1' THEN
262)             IF r_imm = imm_26 THEN
263)                 n_pc <= r_pc(31 DOWNTO 28) & r_imm_26 & "00";
264)             ELSE
265)                 n_pc <= std_logic_vector(signed(r_pc) +
266)                                          signed(r_imm_16 & "00"));
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

268)         ELSE
269)             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

270)         END IF;
271)     END PROCESS p_next_pc;
272)