Line 20... |
Line 20... |
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
Port ( reset : in STD_LOGIC;
|
Port ( reset : in STD_LOGIC;
|
clk : in STD_LOGIC; --! Main system clock
|
clk : in STD_LOGIC; --! Main system clock
|
FlagsDp : in STD_LOGIC_VECTOR (2 downto 0); --! Flags comming from the Datapath
|
FlagsDp : in STD_LOGIC_VECTOR (2 downto 0); --! Flags comming from the Datapath
|
DataDp : in STD_LOGIC_VECTOR (n downto 0); --! Data comming from the Datapath
|
DataDp : in STD_LOGIC_VECTOR (n downto 0); --! Data comming from the Datapath
|
|
outEnDp : out typeEnDis; --! Enable/Disable datapath output
|
MuxDp : out STD_LOGIC_VECTOR (2 downto 0); --! Select on datapath data from (Memory, Imediate, RegFileA, RegFileB, AluOut)
|
MuxDp : out STD_LOGIC_VECTOR (2 downto 0); --! Select on datapath data from (Memory, Imediate, RegFileA, RegFileB, AluOut)
|
MuxRegDp : out STD_LOGIC_VECTOR(1 downto 0); --! Select Alu InputA (Memory,Imediate,RegFileA)
|
MuxRegDp : out STD_LOGIC_VECTOR(1 downto 0); --! Select Alu InputA (Memory,Imediate,RegFileA)
|
ImmDp : out STD_LOGIC_VECTOR (n downto 0); --! Imediate value passed to the Datapath
|
ImmDp : out STD_LOGIC_VECTOR (n downto 0); --! Imediate value passed to the Datapath
|
DpAluOp : out aluOps; --! Alu operations
|
DpAluOp : out aluOps; --! Alu operations
|
DpRegFileWriteAddr : out generalRegisters; --! General register address to write
|
DpRegFileWriteAddr : out generalRegisters; --! General register address to write
|
Line 111... |
Line 112... |
MemoryDataReadEn <= '0';
|
MemoryDataReadEn <= '0';
|
MemoryDataWriteEn <= '0';
|
MemoryDataWriteEn <= '0';
|
|
|
-- The high attribute points to the highes bit position
|
-- The high attribute points to the highes bit position
|
case opcodeIR is
|
case opcodeIR is
|
when mov_reg | mov_val | add_reg | sub_reg | and_reg | or_reg | xor_reg =>
|
when mov_reg | mov_val | add_reg | sub_reg | and_reg | or_reg | xor_reg | ld_reg | ld_val | stom_reg | stom_val =>
|
nextCpuState <= execute;
|
nextCpuState <= execute;
|
cyclesExecute := 3; -- Wait 3 cycles for mov operation
|
cyclesExecute := 3; -- Wait 3 cycles for mov operation
|
currInstruction <= IR;
|
currInstruction <= IR;
|
|
|
when jmp_val | jmpr_val =>
|
when jmp_val | jmpr_val =>
|
Line 129... |
Line 130... |
|
|
-- Wait while the process that handles the execution works..
|
-- Wait while the process that handles the execution works..
|
when execute =>
|
when execute =>
|
-- On the case of jump instructions, it's execution will be handled on this process
|
-- On the case of jump instructions, it's execution will be handled on this process
|
case opcodeIR is
|
case opcodeIR is
|
|
|
when jmp_val =>
|
when jmp_val =>
|
PC <= "0000000000" & operand_imm;
|
PC <= "0000000000" & operand_imm;
|
|
|
when jmpr_val =>
|
when jmpr_val =>
|
PC <= PC + ("0000000000" & operand_imm);
|
PC <= PC + ("0000000000" & operand_imm);
|
|
|
|
when ld_val =>
|
|
MemoryDataRdAddr <= "0000000000" & operand_imm;
|
|
MemoryDataReadEn <= '1';
|
|
|
|
-- STORE r1,10 (Store the value on r1 in the main memory located at address 10)
|
|
when stom_val =>
|
|
MemoryDataWrAddr <= "0000000000" & operand_imm;
|
|
MemoryDataWriteEn <= '1';
|
|
MemoryDataOut <= DataDp;
|
|
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
|
|
if cyclesExecute = 0 then
|
if cyclesExecute = 0 then
|
Line 154... |
Line 168... |
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
end process;
|
end process;
|
|
|
-- Process that handles the execution of each instruction (Excluding the call and jump instructions)
|
-- Process that handles the execution of each instruction (Excluding the call,jump,load,store instructions)
|
process (currentExState)
|
process (currentExState)
|
--variable operando1_reg : std_logic_vector(generalRegisters'range);
|
--variable operando1_reg : std_logic_vector(generalRegisters'range);
|
variable opcodeIR : std_logic_vector(5 downto 0);
|
variable opcodeIR : std_logic_vector(5 downto 0);
|
variable operand_reg1 : std_logic_vector(3 downto 0);
|
variable operand_reg1 : std_logic_vector(3 downto 0);
|
variable operand_reg2 : std_logic_vector(3 downto 0);
|
variable operand_reg2 : std_logic_vector(3 downto 0);
|
Line 180... |
Line 194... |
DpRegFileReadAddrB <= Num2reg(conv_integer(UNSIGNED(operand_reg2)));
|
DpRegFileReadAddrB <= Num2reg(conv_integer(UNSIGNED(operand_reg2)));
|
DpRegFileWriteAddr <= Num2reg(conv_integer(UNSIGNED(operand_reg1)));
|
DpRegFileWriteAddr <= Num2reg(conv_integer(UNSIGNED(operand_reg1)));
|
DpRegFileReadEnB <= '1';
|
DpRegFileReadEnB <= '1';
|
nextExState <= writeRegister;
|
nextExState <= writeRegister;
|
|
|
|
-- LOAD r1,10 (Load into r1, the value in the main memory located at address 10)
|
|
when ld_val =>
|
|
MuxDp <= muxPos(fromMemory);
|
|
DpRegFileWriteAddr <= Num2reg(conv_integer(UNSIGNED(operand_reg1)));
|
|
-- The part that interface with the memory is located on the first process
|
|
nextExState <= writeRegister;
|
|
|
|
-- STORE r1,10 (Store the value on r1 in the main memory located at address 10)
|
|
when stom_val =>
|
|
MuxDp <= muxPos(fromRegFileB);
|
|
DpRegFileReadAddrB <= Num2reg(conv_integer(UNSIGNED(operand_reg1)));
|
|
DpRegFileReadEnB <= '1';
|
|
nextExState <= readRegisterB;
|
|
-- The part that interface with the memory is located on the first process
|
|
nextExState <= readRegisterB;
|
|
|
-- ADD r2,r0 (See the testDatapath to see how to drive the datapath for this function)
|
-- ADD r2,r0 (See the testDatapath to see how to drive the datapath for this function)
|
when add_reg | sub_reg | and_reg | or_reg | xor_reg =>
|
when add_reg | sub_reg | and_reg | or_reg | xor_reg =>
|
MuxDp <= muxPos(fromAlu);
|
MuxDp <= muxPos(fromAlu);
|
MuxRegDp <= muxRegPos(fromRegFileA);
|
MuxRegDp <= muxRegPos(fromRegFileA);
|
DpRegFileReadAddrA <= Num2reg(conv_integer(UNSIGNED(operand_reg1))); -- Read first operand
|
DpRegFileReadAddrA <= Num2reg(conv_integer(UNSIGNED(operand_reg1))); -- Read first operand
|
Line 219... |
Line 249... |
-- Write something on the register files
|
-- Write something on the register files
|
when writeRegister =>
|
when writeRegister =>
|
DpRegFileWriteEn <= '1';
|
DpRegFileWriteEn <= '1';
|
nextExState <= releaseWriteRead;
|
nextExState <= releaseWriteRead;
|
|
|
|
when readRegisterB =>
|
|
DpRegFileReadEnB <= '1';
|
|
outEnDp <= enable;
|
|
nextExState <= releaseWriteRead;
|
|
|
|
when readRegisterA =>
|
|
DpRegFileReadEnA <= '1';
|
|
outEnDp <= enable;
|
|
nextExState <= releaseWriteRead;
|
|
|
-- Release lines (Reset Datapath lines to something that does nothing...)
|
-- Release lines (Reset Datapath lines to something that does nothing...)
|
when releaseWriteRead =>
|
when releaseWriteRead =>
|
DpRegFileReadEnB <= '0';
|
DpRegFileReadEnB <= '0';
|
DpRegFileReadEnA <= '0';
|
DpRegFileReadEnA <= '0';
|
DpRegFileWriteEn <= '0';
|
DpRegFileWriteEn <= '0';
|
|
outEnDp <= disable;
|
|
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
end process;
|
end process;
|