c2b040193a777c09bdc595c95492b57a2521db87
Stefan Schuermans added file headers

Stefan Schuermans authored 12 years ago

1) -- MIPS I system
2) -- Copyright 2011-2012 Stefan Schuermans <stefan@schuermans.info>
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_alu IS
12)     PORT (
13)         i_alu: IN  t_alu;
14)         i_op1: IN  std_logic_vector(31 DOWNTO 0);
15)         i_op2: IN  std_logic_vector(31 DOWNTO 0);
16)         o_res: OUT std_logic_vector(31 DOWNTO 0)
17)     );
18) END ENTITY e_mips_alu;
19) 
20) ARCHITECTURE a_mips_alu OF e_mips_alu IS
21) 
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

22)     SIGNAL s_shift_arith: std_logic;
23)     SIGNAL s_shift_left:  std_logic;
24)     SIGNAL s_shift_out:   std_logic_vector(31 DOWNTO 0);
25) 
26)     COMPONENT e_mips_shifter IS
27)         PORT (
28)             i_arith: IN  std_logic;
29)             i_left:  IN  std_logic;
30)             i_val:   IN  std_logic_vector(31 DOWNTO 0);
31)             i_num:   IN  std_logic_vector(31 DOWNTO 0);
32)             o_val:   OUT std_logic_vector(31 DOWNTO 0)
33)         );
34)     END COMPONENT e_mips_shifter;
35) 
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

36) BEGIN
37) 
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

38)     shifter: e_mips_shifter
39)         PORT MAP (
40)             i_arith => s_shift_arith,
41)             i_left  => s_shift_left,
Stefan Schuermans s operand is number of bits

Stefan Schuermans authored 12 years ago

42)             i_val   => i_op2,
43)             i_num   => i_op1,
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

44)             o_val   => s_shift_out
45)         );
46) 
47)     p_alu: PROCESS(i_alu, i_op1, i_op2, s_shift_out)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

48)         VARIABLE v_op1_s: signed(31 DOWNTO 0);
49)         VARIABLE v_op2_s: signed(31 DOWNTO 0);
50)         VARIABLE v_op1_u: unsigned(31 DOWNTO 0);
51)         VARIABLE v_op2_u: unsigned(31 DOWNTO 0);
52)     BEGIN
53)         v_op1_s := signed(i_op1);
54)         v_op2_s := signed(i_op2);
55)         v_op1_u := unsigned(i_op1);
56)         v_op2_u := unsigned(i_op2);
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

57)         s_shift_arith <= '0';
58)         s_shift_left <= '0';
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

59)         CASE i_alu IS
60)             WHEN alu_add => o_res <= std_logic_vector(v_op1_s + v_op2_s);
61)             WHEN alu_and => o_res <= i_op1 AND i_op2;
62)             WHEN alu_nor => o_res <= i_op1 NOR i_op2;
63)             WHEN alu_or  => o_res <= i_op1 OR i_op2;
64)             WHEN alu_sub => o_res <= std_logic_vector(v_op1_s - v_op2_s);
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

65)             WHEN alu_sll => s_shift_arith <= '0'; s_shift_left <= '1'; o_res <= s_shift_out;
66)             WHEN alu_sra => s_shift_arith <= '1'; s_shift_left <= '0'; o_res <= s_shift_out;
Stefan Schuermans fixed srl instruction (no s...

Stefan Schuermans authored 12 years ago

67)             WHEN alu_srl => s_shift_arith <= '0'; s_shift_left <= '0'; o_res <= s_shift_out;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

68)             WHEN alu_slt => IF v_op1_s < v_op2_s THEN
69)                                 o_res <= X"00000001";
70)                             ELSE
71)                                 o_res <= X"00000000";
72)                             END IF;
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

73)             WHEN alu_sltu => IF v_op1_u < v_op2_u THEN
74)                                  o_res <= X"00000001";
75)                              ELSE
76)                                  o_res <= X"00000000";
77)                              END IF;
Stefan Schuermans added decoding of simple lo...

Stefan Schuermans authored 12 years ago

78)             WHEN alu_up => o_res <= i_op2(15 DOWNTO 0) & X"0000";