Line 21... |
Line 21... |
Port ( reset : in STD_LOGIC;
|
Port ( reset : in STD_LOGIC;
|
clk : in STD_LOGIC;
|
clk : in STD_LOGIC;
|
FlagsDp : in STD_LOGIC_VECTOR (n downto 0);
|
FlagsDp : in STD_LOGIC_VECTOR (n downto 0);
|
DataDp : in STD_LOGIC_VECTOR (n downto 0);
|
DataDp : in STD_LOGIC_VECTOR (n downto 0);
|
MuxDp : out STD_LOGIC_VECTOR (2 downto 0);
|
MuxDp : out STD_LOGIC_VECTOR (2 downto 0);
|
|
MuxRegDp : out STD_LOGIC_VECTOR(1 downto 0); --! Select Alu InputA (Memory,Imediate,RegFileA)
|
ImmDp : out STD_LOGIC_VECTOR (n downto 0);
|
ImmDp : out STD_LOGIC_VECTOR (n downto 0);
|
DpRegFileWriteAddr : out STD_LOGIC;
|
DpAluOp : out aluOps; --! Alu operations
|
|
DpRegFileWriteAddr : out generalRegisters;
|
DpRegFileWriteEn : out STD_LOGIC;
|
DpRegFileWriteEn : out STD_LOGIC;
|
DpRegFileReadAddrA : out STD_LOGIC;
|
DpRegFileReadAddrA : out generalRegisters;
|
DpRegFileReadAddrB : out STD_LOGIC;
|
DpRegFileReadAddrB : out generalRegisters;
|
DpRegFileReadEnA : out STD_LOGIC;
|
DpRegFileReadEnA : out STD_LOGIC;
|
DpRegFileReadEnB : out STD_LOGIC;
|
DpRegFileReadEnB : out STD_LOGIC;
|
MemoryDataRead : out std_logic;
|
MemoryDataRead : out std_logic;
|
MemoryDataWrite : out std_logic;
|
MemoryDataWrite : out std_logic;
|
MemoryDataInput : in STD_LOGIC_VECTOR (n downto 0);
|
MemoryDataInput : in STD_LOGIC_VECTOR (n downto 0);
|
Line 64... |
Line 66... |
end process;
|
end process;
|
|
|
-- Next state logic (Execution states)
|
-- Next state logic (Execution states)
|
process (clk, currentCpuState)
|
process (clk, currentCpuState)
|
begin
|
begin
|
if (currentCpuState /= execute) and (currentCpuState /= executing) then
|
if ( (currentCpuState /= execute) and (currentCpuState /= executing) ) then
|
currentExState <= s0;
|
currentExState <= initInstructionExecution;
|
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|
currentExState <= nextExState;
|
currentExState <= nextExState;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
Line 105... |
Line 107... |
MemoryDataRead <= '0';
|
MemoryDataRead <= '0';
|
MemoryDataWrite <= '0';
|
MemoryDataWrite <= '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 =>
|
when mov_reg | mov_val | add_reg | sub_reg | and_reg | or_reg | xor_reg =>
|
nextCpuState <= execute;
|
nextCpuState <= execute;
|
cyclesExecute := 2;
|
cyclesExecute := 3; -- Wait 3 cycles for mov operation
|
currInstruction <= IR;
|
currInstruction <= IR;
|
-- Invalid instruction (Now will be ignored, but latter should raise a trap
|
-- Invalid instruction (Now will be ignored, but latter should raise a trap
|
when others =>
|
when others =>
|
end case;
|
end case;
|
|
|
Line 136... |
Line 138... |
|
|
-- Process that handles the execution of each instruction
|
-- Process that handles the execution of each instruction
|
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_reg2 : std_logic_vector(3 downto 0);
|
|
variable operand_imm : std_logic_vector(21 downto 0);
|
begin
|
begin
|
opcodeIR := IR((IR'HIGH) downto (IR'HIGH - 5));
|
-- Parse the common operands
|
|
opcodeIR := IR((IR'HIGH) downto (IR'HIGH - 5)); -- 6 Bits opcode (Max 64 instructions)
|
|
operand_reg1 := IR((IR'HIGH - 6) downto (IR'HIGH - 9)); -- 4 bits register operand1 (Max 16 registers)
|
|
operand_reg2 := IR((IR'HIGH - 10) downto (IR'HIGH - 13)); -- 4 bits register operand2 (Max 16 registers
|
|
operand_imm := IR((IR'HIGH - 10) downto (IR'LOW)); -- 22 bits imediate value (Max value 4194304)
|
|
|
|
-- Select the instruction and init it's execution
|
case currentExState is
|
case currentExState is
|
when s0 =>
|
when initInstructionExecution =>
|
case opcodeIR is
|
case opcodeIR is
|
|
-- MOV r2,r1 (See the testDatapath to see how to drive the datapath for this function)
|
when mov_reg =>
|
when mov_reg =>
|
null;
|
MuxDp <= muxPos(fromRegFileB);
|
|
DpRegFileReadAddrB <= Num2reg(conv_integer(UNSIGNED(operand_reg2)));
|
|
DpRegFileWriteAddr <= Num2reg(conv_integer(UNSIGNED(operand_reg1)));
|
|
DpRegFileReadEnB <= '1';
|
|
nextExState <= writeRegister;
|
|
|
|
-- 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 =>
|
|
MuxDp <= muxPos(fromAlu);
|
|
MuxRegDp <= muxRegPos(fromRegFileA);
|
|
DpRegFileReadAddrA <= Num2reg(conv_integer(UNSIGNED(operand_reg1))); -- Read first operand
|
|
DpRegFileReadAddrB <= Num2reg(conv_integer(UNSIGNED(operand_reg2))); -- Read second operand
|
|
DpRegFileReadEnA <= '1';
|
|
DpRegFileReadEnB <= '1';
|
|
DpRegFileWriteAddr <= Num2reg(conv_integer(UNSIGNED(operand_reg1))); -- Point to write in first operand (pointing to register)
|
|
DpAluOp <= opcode2AluOp(opcodeIR); -- Select the alu operation from the operand
|
|
nextExState <= writeRegister;
|
|
|
|
-- MOV r0,10d (See the testDatapath to see how to drive the datapath for this function)
|
|
when mov_val =>
|
|
MuxDp <= muxPos(fromImediate);
|
|
DpRegFileWriteAddr <= Num2reg(conv_integer(UNSIGNED(operand_reg1)));
|
|
ImmDp <= "0000000000" & operand_imm; -- & is used to concatenate signals
|
|
nextExState <= writeRegister;
|
|
|
|
-- ADD r3,2 (r2 <= r2+2) (See the testDatapath to see how to drive the datapath for this function)
|
|
when add_val | sub_val | and_val | or_val | xor_val =>
|
|
MuxDp <= muxPos(fromAlu);
|
|
MuxRegDp <= muxRegPos(fromImediate);
|
|
DpRegFileWriteAddr <= Num2reg(conv_integer(UNSIGNED(operand_reg1)));
|
|
DpRegFileReadAddrB <= Num2reg(conv_integer(UNSIGNED(operand_reg1))); -- Read first operand
|
|
DpRegFileReadEnB <= '1';
|
|
ImmDp <= "0000000000" & operand_imm; -- & is used to concatenate signals
|
|
DpAluOp <= opcode2AluOp(opcodeIR); -- Select the alu operation from the operand
|
|
nextExState <= writeRegister;
|
|
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
|
|
|
-- Write something on the register files
|
|
when writeRegister =>
|
|
DpRegFileWriteEn <= '1';
|
|
nextExState <= releaseWriteRead;
|
|
|
|
-- Release lines (Reset Datapath lines to something that does nothing...)
|
|
when releaseWriteRead =>
|
|
DpRegFileReadEnB <= '0';
|
|
DpRegFileReadEnA <= '0';
|
|
DpRegFileWriteEn <= '0';
|
|
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
end process;
|
end process;
|
|
|