1 |
30 |
leonardoar |
--! @file
|
2 |
|
|
--! @brief Arithmetic logic unit http://en.wikipedia.org/wiki/Arithmetic_logic_unit
|
3 |
|
|
|
4 |
|
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
5 |
|
|
library IEEE;
|
6 |
|
|
use ieee.std_logic_1164.all;
|
7 |
|
|
use ieee.std_logic_unsigned.all;
|
8 |
|
|
use ieee.std_logic_arith.all;
|
9 |
|
|
|
10 |
|
|
--! Use CPU Definitions package
|
11 |
|
|
use work.pkgOpenCPU32.all;
|
12 |
|
|
|
13 |
|
|
--! Cpu top level file
|
14 |
|
|
|
15 |
|
|
--! Include the Control Unit and datapath
|
16 |
|
|
entity openCpu is
|
17 |
|
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
18 |
|
|
Port ( rst : in STD_LOGIC; --! Reset signal
|
19 |
|
|
clk : in STD_LOGIC; --! Clock signal
|
20 |
|
|
mem_rd : out STD_LOGIC; --! Main memory Read enable
|
21 |
|
|
mem_rd_addr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Read address
|
22 |
|
|
mem_wr : out STD_LOGIC; --! Main memory Write enable
|
23 |
|
|
mem_wr_addr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Write address
|
24 |
|
|
mem_data_in : in STD_LOGIC_VECTOR (n downto 0); --! Data comming from main memory
|
25 |
|
|
mem_data_out : out STD_LOGIC_VECTOR (n downto 0) --! Data to main memory
|
26 |
|
|
);
|
27 |
|
|
end openCpu;
|
28 |
|
|
|
29 |
|
|
--! @brief Cpu http://en.wikipedia.org/wiki/Central_processing_unit
|
30 |
|
|
--! @details This description will instantiate the components ControlUnit and DataPath
|
31 |
|
|
architecture Behavioral of openCpu is
|
32 |
|
|
COMPONENT DataPath is
|
33 |
|
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
34 |
|
|
Port ( inputMm : in STD_LOGIC_VECTOR (n downto 0); --! Input of Datapath from main memory
|
35 |
|
|
inputImm : in STD_LOGIC_VECTOR (n downto 0); --! Input of Datapath from imediate value (instructions...)
|
36 |
|
|
clk : in STD_LOGIC; --! Clock signal
|
37 |
|
|
outEn : in typeEnDis; --! Enable/Disable datapath output
|
38 |
|
|
aluOp : in aluOps; --! Alu operations
|
39 |
|
|
muxSel : in STD_LOGIC_VECTOR (2 downto 0); --! Select inputs from dataPath(Memory,Imediate,RegisterFile,Alu)
|
40 |
|
|
muxRegFile : in STD_LOGIC_VECTOR(1 downto 0); --! Select Alu InputA (Memory,Imediate,RegFileA)
|
41 |
|
|
regFileWriteAddr : in generalRegisters; --! General register write address
|
42 |
|
|
regFileWriteEn : in STD_LOGIC; --! RegisterFile write enable signal
|
43 |
|
|
regFileReadAddrA : in generalRegisters; --! General register read address (PortA)
|
44 |
|
|
regFileReadAddrB : in generalRegisters; --! General register read address (PortB)
|
45 |
|
|
regFileEnA : in STD_LOGIC; --! Enable RegisterFile PortA
|
46 |
|
|
regFileEnB : in STD_LOGIC; --! Enable RegisterFile PortB
|
47 |
|
|
outputDp : out STD_LOGIC_VECTOR (n downto 0); --! DataPath Output
|
48 |
|
|
dpFlags : out STD_LOGIC_VECTOR (2 downto 0)); --! Alu Flags
|
49 |
|
|
end COMPONENT;
|
50 |
|
|
|
51 |
|
|
COMPONENT ControlUnit is
|
52 |
|
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
53 |
|
|
Port ( reset : in STD_LOGIC;
|
54 |
|
|
clk : in STD_LOGIC; --! Main system clock
|
55 |
|
|
FlagsDp : in STD_LOGIC_VECTOR (2 downto 0); --! Flags comming from the Datapath
|
56 |
|
|
DataDp : in STD_LOGIC_VECTOR (n downto 0); --! Data comming from the Datapath
|
57 |
31 |
leonardoar |
outEnDp : out typeEnDis; --! Enable/Disable datapath output
|
58 |
30 |
leonardoar |
MuxDp : out STD_LOGIC_VECTOR (2 downto 0); --! Select on datapath data from (Memory, Imediate, RegFileA, RegFileB, AluOut)
|
59 |
|
|
MuxRegDp : out STD_LOGIC_VECTOR(1 downto 0); --! Select Alu InputA (Memory,Imediate,RegFileA)
|
60 |
|
|
ImmDp : out STD_LOGIC_VECTOR (n downto 0); --! Imediate value passed to the Datapath
|
61 |
|
|
DpAluOp : out aluOps; --! Alu operations
|
62 |
|
|
DpRegFileWriteAddr : out generalRegisters; --! General register address to write
|
63 |
|
|
DpRegFileWriteEn : out STD_LOGIC; --! Enable register write
|
64 |
|
|
DpRegFileReadAddrA : out generalRegisters; --! General register address to read
|
65 |
|
|
DpRegFileReadAddrB : out generalRegisters; --! General register address to read
|
66 |
|
|
DpRegFileReadEnA : out STD_LOGIC; --! Enable register read (PortA)
|
67 |
|
|
DpRegFileReadEnB : out STD_LOGIC; --! Enable register read (PortB)
|
68 |
|
|
MemoryDataReadEn : out std_logic; --! Enable Main memory read
|
69 |
|
|
MemoryDataWriteEn: out std_logic; --! Enable Main memory write
|
70 |
|
|
MemoryDataInput : in STD_LOGIC_VECTOR (n downto 0); --! Incoming data from main memory
|
71 |
|
|
MemoryDataRdAddr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Read address
|
72 |
|
|
MemoryDataWrAddr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Write address
|
73 |
|
|
MemoryDataOut : out STD_LOGIC_VECTOR (n downto 0)); --! Data to write on main memory
|
74 |
|
|
end COMPONENT;
|
75 |
|
|
|
76 |
|
|
signal InputImediate : STD_LOGIC_VECTOR (n downto 0);
|
77 |
|
|
signal enableOutputDp : typeEnDis;
|
78 |
|
|
signal aluOperations : aluOps;
|
79 |
|
|
signal InputDataPathSelector : STD_LOGIC_VECTOR (2 downto 0);
|
80 |
|
|
signal InputDataPathAluASelector : STD_LOGIC_VECTOR (1 downto 0);
|
81 |
|
|
signal registerFileWriteAddress : generalRegisters;
|
82 |
|
|
signal registerFileWriteEnable : STD_LOGIC;
|
83 |
|
|
signal registerFileReadAddressA : generalRegisters;
|
84 |
|
|
signal registerFileReadAddressB : generalRegisters;
|
85 |
|
|
signal registerFileReadEnableA : STD_LOGIC;
|
86 |
|
|
signal registerFileReadEnableB : STD_LOGIC;
|
87 |
|
|
signal dataPathOutput : STD_LOGIC_VECTOR (n downto 0);
|
88 |
|
|
signal dataPathFlags : STD_LOGIC_VECTOR (2 downto 0);
|
89 |
|
|
begin
|
90 |
|
|
--! Instantiate the Datapath
|
91 |
|
|
uDataPath: DataPath PORT MAP (
|
92 |
|
|
inputMm => InputImediate,
|
93 |
|
|
inputImm => mem_data_in,
|
94 |
|
|
clk => clk,
|
95 |
|
|
outEn => enableOutputDp,
|
96 |
|
|
aluOp => aluOperations,
|
97 |
|
|
muxSel => InputDataPathSelector,
|
98 |
|
|
muxRegFile => InputDataPathAluASelector,
|
99 |
|
|
regFileWriteAddr => registerFileWriteAddress,
|
100 |
|
|
regFileWriteEn => registerFileWriteEnable,
|
101 |
|
|
regFileReadAddrA => registerFileReadAddressA,
|
102 |
|
|
regFileReadAddrB => registerFileReadAddressB,
|
103 |
|
|
regFileEnA => registerFileReadEnableA,
|
104 |
|
|
regFileEnB => registerFileReadEnableB,
|
105 |
|
|
outputDp => dataPathOutput,
|
106 |
|
|
dpFlags => dataPathFlags
|
107 |
|
|
);
|
108 |
|
|
|
109 |
|
|
--! Instantiate the control unit
|
110 |
|
|
uControlUnit: ControlUnit PORT MAP (
|
111 |
|
|
reset => rst,
|
112 |
|
|
clk => clk,
|
113 |
|
|
FlagsDp => dataPathFlags,
|
114 |
|
|
DataDp => dataPathOutput,
|
115 |
31 |
leonardoar |
outEnDp => enableOutputDp,
|
116 |
30 |
leonardoar |
MuxDp => InputDataPathSelector,
|
117 |
|
|
MuxRegDp => InputDataPathAluASelector,
|
118 |
|
|
ImmDp => InputImediate,
|
119 |
|
|
DpAluOp => aluOperations,
|
120 |
|
|
DpRegFileWriteAddr => registerFileWriteAddress,
|
121 |
|
|
DpRegFileWriteEn => registerFileWriteEnable,
|
122 |
|
|
DpRegFileReadAddrA => registerFileReadAddressA,
|
123 |
|
|
DpRegFileReadAddrB => registerFileReadAddressB,
|
124 |
|
|
DpRegFileReadEnA => registerFileReadEnableA,
|
125 |
|
|
DpRegFileReadEnB => registerFileReadEnableB,
|
126 |
|
|
MemoryDataReadEn => mem_rd,
|
127 |
|
|
MemoryDataWriteEn => mem_wr,
|
128 |
|
|
MemoryDataInput => mem_data_in,
|
129 |
|
|
MemoryDataRdAddr => mem_rd_addr,
|
130 |
|
|
MemoryDataWrAddr => mem_wr_addr,
|
131 |
|
|
MemoryDataOut => mem_data_out
|
132 |
|
|
);
|
133 |
|
|
|
134 |
|
|
end Behavioral;
|
135 |
|
|
|