902aa402b3830b9c9aa26758390b6eb93b42a0f5
Stefan Schuermans added file headers

Stefan Schuermans authored 12 years ago

1) -- MIPS I system
Stefan Schuermans replace email address in he...

Stefan Schuermans authored 12 years ago

2) -- Copyright 2011-2012 Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans added file headers

Stefan Schuermans authored 12 years ago

3) -- Copyleft GNU public license V2 or later
4) --          http://www.gnu.org/copyleft/gpl.html
5) 
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

6) LIBRARY ieee;
7) USE ieee.std_logic_1164.all;
8) USE ieee.numeric_std.all;
9) USE work.mips_types.all;
10) 
11) ENTITY e_mips_decoder IS
12)     PORT (
13)         i_instr:  IN  std_logic_vector(31 DOWNTO 0);
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

14)         o_reg_s:  OUT std_logic_vector( 4 DOWNTO 0);
15)         o_reg_t:  OUT std_logic_vector( 4 DOWNTO 0);
16)         o_reg_d:  OUT std_logic_vector( 4 DOWNTO 0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

17)         o_imm_a:  OUT std_logic_vector( 4 DOWNTO 0);
18)         o_imm_16: OUT std_logic_vector(15 DOWNTO 0);
19)         o_imm_26: OUT std_logic_vector(25 DOWNTO 0);
20)         o_op:     OUT t_op;
21)         o_link:   OUT t_link;
22)         o_cmp:    OUT t_cmp;
23)         o_alu:    OUT t_alu;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

26)     );
27) END ENTITY e_mips_decoder;
28) 
29) ARCHITECTURE a_mips_decoder OF e_mips_decoder IS
30) 
31)     TYPE t_enc_type IS (enc_reg, enc_imm, enc_jmp);
32) 
33)     SIGNAL s_opcode:   std_logic_vector(5 DOWNTO 0);
Stefan Schuermans add missing branch instruct...

Stefan Schuermans authored 12 years ago

34)     SIGNAL s_ext_op:   std_logic_vector(4 DOWNTO 0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

35)     SIGNAL s_func:     std_logic_vector(5 DOWNTO 0);
Stefan Schuermans add missing branch instruct...

Stefan Schuermans authored 12 years ago

36)     SIGNAL s_enc_type: t_enc_type;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

37) 
38) BEGIN
39) 
40)     s_opcode <= i_instr(31 DOWNTO 26);
Stefan Schuermans add missing branch instruct...

Stefan Schuermans authored 12 years ago

41)     s_ext_op <= i_instr(20 DOWNTO 16);
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

42)     s_func   <= i_instr( 5 DOWNTO  0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

43) 
44)     p_enc_type: PROCESS(s_opcode)
45)     BEGIN
46)         CASE s_opcode IS
47)             WHEN "000000" => s_enc_type <= enc_reg;
48)             WHEN "000010" => s_enc_type <= enc_jmp;
Stefan Schuermans fixed decoding jump instruc...

Stefan Schuermans authored 12 years ago

49)             WHEN "000011" => s_enc_type <= enc_jmp;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

50)             WHEN OTHERS   => s_enc_type <= enc_imm;
51)         END CASE;
52)     END PROCESS p_enc_type;
53) 
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

54)     p_reg_s: PROCESS(i_instr, s_enc_type)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

55)     BEGIN
56)         CASE s_enc_type IS
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

57)             WHEN enc_reg => o_reg_s <= i_instr(25 DOWNTO 21);
58)             WHEN enc_imm => o_reg_s <= i_instr(25 DOWNTO 21);
59)             WHEN OTHERS  => o_reg_s <= "00000";
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

60)         END CASE;
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

61)     END PROCESS p_reg_s;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

62) 
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

63)     p_reg_t: PROCESS(i_instr, s_enc_type)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

64)     BEGIN
65)         CASE s_enc_type IS
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

66)             WHEN enc_reg => o_reg_t <= i_instr(20 DOWNTO 16);
67)             WHEN enc_imm => o_reg_t <= i_instr(20 DOWNTO 16);
68)             WHEN OTHERS  => o_reg_t <= "00000";
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

69)         END CASE;
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

70)     END PROCESS p_reg_t;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

71) 
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

72)     p_reg_d: PROCESS(i_instr, s_enc_type)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

73)     BEGIN
74)         CASE s_enc_type IS
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

75)             WHEN enc_reg => o_reg_d <= i_instr(15 DOWNTO 11);
76)             WHEN OTHERS  => o_reg_d <= "00000";
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

77)         END CASE;
Stefan Schuermans rename src/dest to more gen...

Stefan Schuermans authored 12 years ago

78)     END PROCESS p_reg_d;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

79) 
80)     p_imm_a: PROCESS(i_instr, s_enc_type)
81)     BEGIN
82)         CASE s_enc_type IS
83)             WHEN enc_reg => o_imm_a <= i_instr(10 DOWNTO 6);
84)             WHEN OTHERS  => o_imm_a <= "00000";
85)         END CASE;
86)     END PROCESS p_imm_a;
87) 
88)     p_imm_16: PROCESS(i_instr, s_enc_type)
89)     BEGIN
90)         CASE s_enc_type IS
Stefan Schuermans fix decoder: immediates

Stefan Schuermans authored 12 years ago

91)             WHEN enc_imm => o_imm_16 <= i_instr(15 DOWNTO 0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

92)             WHEN OTHERS  => o_imm_16 <= X"0000";
93)         END CASE;
94)     END PROCESS p_imm_16;
95) 
96)     p_imm_26: PROCESS(i_instr, s_enc_type)
97)     BEGIN
98)         CASE s_enc_type IS
Stefan Schuermans fix decoder: immediates

Stefan Schuermans authored 12 years ago

99)             WHEN enc_jmp => o_imm_26 <= i_instr(25 DOWNTO 0);
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

100)             WHEN OTHERS  => o_imm_26 <= X"000000" & "00";
101)         END CASE;
102)     END PROCESS p_imm_26;
103) 
Stefan Schuermans add missing branch instruct...

Stefan Schuermans authored 12 years ago

104)     p_op: PROCESS(s_opcode, s_ext_op, s_func)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

105)     BEGIN
106)         o_op   <= op_none;
107)         o_link <= link_none;
108)         o_cmp  <= cmp_none;
109)         o_alu  <= alu_none;
110)         o_imm  <= imm_none;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

111)         o_ldst <= ldst_none;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

112)         CASE s_opcode IS
113)             WHEN "000000" =>
114)                 CASE s_func IS
115)                     WHEN "000000" => o_op <= op_alu; o_alu <= alu_sll; o_imm <= imm_a;
116)                     WHEN "000010" => o_op <= op_alu; o_alu <= alu_srl; o_imm <= imm_a;
117)                     WHEN "000011" => o_op <= op_alu; o_alu <= alu_sra; o_imm <= imm_a;
118)                     WHEN "000100" => o_op <= op_alu; o_alu <= alu_sll;
119)                     WHEN "000110" => o_op <= op_alu; o_alu <= alu_srl;
120)                     WHEN "000111" => o_op <= op_alu; o_alu <= alu_sra;
121)                     WHEN "001000" => o_op <= op_j;
122)                     WHEN "001001" => o_op <= op_j; o_link <= link_link;
Stefan Schuermans decoding MULT(U)/DIV(U) ->...

Stefan Schuermans authored 12 years ago

123)                     WHEN "010000" => o_op <= op_mfhi;
Stefan Schuermans fixed decoding of M[FT]{HI|LO}

Stefan Schuermans authored 12 years ago

124)                     WHEN "010001" => o_op <= op_mthi;
125)                     WHEN "010010" => o_op <= op_mflo;
Stefan Schuermans decoding MULT(U)/DIV(U) ->...

Stefan Schuermans authored 12 years ago

126)                     WHEN "010011" => o_op <= op_mtlo;
127)                     WHEN "011000" => o_op <= op_mult;
128)                     WHEN "011001" => o_op <= op_multu;
129)                     WHEN "011010" => o_op <= op_div;
130)                     WHEN "011011" => o_op <= op_divu;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

131)                     WHEN "100000" => o_op <= op_alu; o_alu <= alu_add;
132)                     WHEN "100001" => o_op <= op_alu; o_alu <= alu_add;
133)                     WHEN "100010" => o_op <= op_alu; o_alu <= alu_sub;
134)                     WHEN "100011" => o_op <= op_alu; o_alu <= alu_sub;
135)                     WHEN "100100" => o_op <= op_alu; o_alu <= alu_and;
136)                     WHEN "100101" => o_op <= op_alu; o_alu <= alu_or;
137)                     WHEN "100110" => o_op <= op_alu; o_alu <= alu_xor;
138)                     WHEN "100111" => o_op <= op_alu; o_alu <= alu_nor;
139)                     WHEN "101010" => o_op <= op_alu; o_alu <= alu_slt;
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

140)                     WHEN "101011" => o_op <= op_alu; o_alu <= alu_sltu;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

141)                     WHEN OTHERS => NULL;
142)                 END CASE;
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

143)             WHEN "000001" => o_op <= op_j; o_imm <= imm_16se;
Stefan Schuermans add missing branch instruct...

Stefan Schuermans authored 12 years ago

144)                              IF s_ext_op(0) = '1' THEN o_cmp <= cmp_gez;
145)                                                   ELSE o_cmp <= cmp_ltz;
146)                                                   END IF;
147)                              IF s_ext_op(4) = '1' THEN o_link <= link_link;
148)                                                   ELSE o_link <= link_none;
149)                                                   END IF;
Stefan Schuermans fix decoding of J

Stefan Schuermans authored 12 years ago

150)             WHEN "000010" => o_op <= op_j; o_imm <= imm_26;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

151)             WHEN "000011" => o_op <= op_j; o_link <= link_link; o_imm <= imm_26;
Stefan Schuermans compare unit, initial PC ideas

Stefan Schuermans authored 12 years ago

152)             WHEN "000100" => o_op <= op_j; o_cmp <= cmp_eq; o_imm <= imm_16se;
153)             WHEN "000101" => o_op <= op_j; o_cmp <= cmp_ne; o_imm <= imm_16se;
154)             WHEN "000110" => o_op <= op_j; o_cmp <= cmp_lez; o_imm <= imm_16se;
155)             WHEN "000111" => o_op <= op_j; o_cmp <= cmp_gtz; o_imm <= imm_16se;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

156)             WHEN "001000" => o_op <= op_alu; o_alu <= alu_add; o_imm <= imm_16se;
157)             WHEN "001001" => o_op <= op_alu; o_alu <= alu_add; o_imm <= imm_16se;
158)             WHEN "001010" => o_op <= op_alu; o_alu <= alu_slt; o_imm <= imm_16se;
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

159)             WHEN "001011" => o_op <= op_alu; o_alu <= alu_sltu; o_imm <= imm_16se;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

160)             WHEN "001100" => o_op <= op_alu; o_alu <= alu_and; o_imm <= imm_16ze;
161)             WHEN "001101" => o_op <= op_alu; o_alu <= alu_or; o_imm <= imm_16ze;
162)             WHEN "001110" => o_op <= op_alu; o_alu <= alu_xor; o_imm <= imm_16ze;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

163)             WHEN "001111" => o_op <= op_alu; o_alu <= alu_up; o_imm <= imm_16ze;
164)             WHEN "100000" => o_op <= op_l; o_imm <= imm_16se; o_ldst <= ldst_b;
165)             WHEN "100001" => o_op <= op_l; o_imm <= imm_16se; o_ldst <= ldst_h;
Stefan Schuermans decoding of LWL, LWR, SWL, SWR

Stefan Schuermans authored 12 years ago

166)             WHEN "100010" => o_op <= op_l; o_imm <= imm_16se; o_ldst <= ldst_wl;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

167)             WHEN "100011" => o_op <= op_l; o_imm <= imm_16se; o_ldst <= ldst_w;
168)             WHEN "100100" => o_op <= op_l; o_imm <= imm_16se; o_ldst <= ldst_bu;
169)             WHEN "100101" => o_op <= op_l; o_imm <= imm_16se; o_ldst <= ldst_hu;
Stefan Schuermans decoding of LWL, LWR, SWL, SWR

Stefan Schuermans authored 12 years ago

170)             WHEN "100110" => o_op <= op_l; o_imm <= imm_16se; o_ldst <= ldst_wr;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

171)             WHEN "101000" => o_op <= op_s; o_imm <= imm_16se; o_ldst <= ldst_b;
172)             WHEN "101001" => o_op <= op_s; o_imm <= imm_16se; o_ldst <= ldst_h;
Stefan Schuermans decoding of LWL, LWR, SWL, SWR

Stefan Schuermans authored 12 years ago

173)             WHEN "101010" => o_op <= op_s; o_imm <= imm_16se; o_ldst <= ldst_wl;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

174)             WHEN "101011" => o_op <= op_s; o_imm <= imm_16se; o_ldst <= ldst_w;
Stefan Schuermans decoding of LWL, LWR, SWL, SWR

Stefan Schuermans authored 12 years ago

175)             WHEN "101110" => o_op <= op_s; o_imm <= imm_16se; o_ldst <= ldst_wr;