Line 3... |
Line 3... |
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
|
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
|
use work.pp_types.all;
|
|
use work.pp_constants.all;
|
use work.pp_constants.all;
|
use work.pp_csr.all;
|
use work.pp_csr.all;
|
|
use work.pp_types.all;
|
|
use work.pp_utilities.all;
|
|
|
--! @brief Unit decoding instructions and setting control signals apropriately.
|
--! @brief Unit decoding instructions and setting control signals apropriately.
|
entity pp_control_unit is
|
entity pp_control_unit is
|
port(
|
port(
|
-- Inputs, indices correspond to instruction word indices:
|
-- Inputs, indices correspond to instruction word indices:
|
Line 41... |
Line 42... |
mem_size : out memory_operation_size
|
mem_size : out memory_operation_size
|
);
|
);
|
end entity pp_control_unit;
|
end entity pp_control_unit;
|
|
|
architecture behaviour of pp_control_unit is
|
architecture behaviour of pp_control_unit is
|
|
signal exception : std_logic;
|
|
signal exception_cause : std_logic_vector(4 downto 0);
|
|
signal alu_op_temp : alu_operation;
|
begin
|
begin
|
|
|
csr_imm <= funct3(2);
|
csr_imm <= funct3(2);
|
|
alu_op <= alu_op_temp;
|
|
|
|
decode_exception <= exception or to_std_logic(alu_op_temp = ALU_INVALID);
|
|
decode_exception_cause <= exception_cause when alu_op_temp /= ALU_INVALID
|
|
else CSR_CAUSE_INVALID_INSTR;
|
|
|
alu_control: entity work.pp_alu_control_unit
|
alu_control: entity work.pp_alu_control_unit
|
port map(
|
port map(
|
opcode => opcode,
|
opcode => opcode,
|
funct3 => funct3,
|
funct3 => funct3,
|
funct7 => funct7,
|
funct7 => funct7,
|
alu_x_src => alu_x_src,
|
alu_x_src => alu_x_src,
|
alu_y_src => alu_y_src,
|
alu_y_src => alu_y_src,
|
alu_op => alu_op
|
alu_op => alu_op_temp
|
);
|
);
|
|
|
decode_ctrl: process(opcode, funct3, funct12)
|
decode_ctrl: process(opcode, funct3, funct12)
|
begin
|
begin
|
case opcode is
|
case opcode is
|
when b"01101" => -- Load upper immediate
|
when b"01101" => -- Load upper immediate
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
when b"00101" => -- Add upper immediate to PC
|
when b"00101" => -- Add upper immediate to PC
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
when b"11011" => -- Jump and link
|
when b"11011" => -- Jump and link
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_JUMP;
|
branch <= BRANCH_JUMP;
|
when b"11001" => -- Jump and link register
|
when b"11001" => -- Jump and link register
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_JUMP_INDIRECT;
|
branch <= BRANCH_JUMP_INDIRECT;
|
when b"11000" => -- Branch operations
|
when b"11000" => -- Branch operations
|
rd_write <= '0';
|
rd_write <= '0';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_CONDITIONAL;
|
branch <= BRANCH_CONDITIONAL;
|
when b"00000" => -- Load instructions
|
when b"00000" => -- Load instructions
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
when b"01000" => -- Store instructions
|
when b"01000" => -- Store instructions
|
rd_write <= '0';
|
rd_write <= '0';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
when b"00100" => -- Register-immediate operations
|
when b"00100" => -- Register-immediate operations
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
when b"01100" => -- Register-register operations
|
when b"01100" => -- Register-register operations
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
when b"00011" => -- Fence instructions, ignored
|
when b"00011" => -- Fence instructions, ignored
|
rd_write <= '0';
|
rd_write <= '0';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
when b"11100" => -- System instructions
|
when b"11100" => -- System instructions
|
if funct3 = b"000" then
|
if funct3 = b"000" then
|
rd_write <= '0';
|
rd_write <= '0';
|
|
|
if funct12 = x"000" then
|
if funct12 = x"000" then
|
decode_exception <= '1';
|
exception <= '1';
|
decode_exception_cause <= CSR_CAUSE_SYSCALL;
|
exception_cause <= CSR_CAUSE_SYSCALL;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
elsif funct12 = x"001" then
|
elsif funct12 = x"001" then
|
decode_exception <= '1';
|
exception <= '1';
|
decode_exception_cause <= CSR_CAUSE_BREAKPOINT;
|
exception_cause <= CSR_CAUSE_BREAKPOINT;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
elsif funct12 = x"800" then
|
elsif funct12 = x"800" then
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_SRET;
|
branch <= BRANCH_SRET;
|
else
|
else
|
decode_exception <= '1';
|
exception <= '1';
|
decode_exception_cause <= CSR_CAUSE_INVALID_INSTR;
|
exception_cause <= CSR_CAUSE_INVALID_INSTR;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
end if;
|
end if;
|
else
|
else
|
rd_write <= '1';
|
rd_write <= '1';
|
decode_exception <= '0';
|
exception <= '0';
|
decode_exception_cause <= CSR_CAUSE_NONE;
|
exception_cause <= CSR_CAUSE_NONE;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
end if;
|
end if;
|
when others =>
|
when others =>
|
rd_write <= '0';
|
rd_write <= '0';
|
decode_exception <= '1';
|
exception <= '1';
|
decode_exception_cause <= CSR_CAUSE_INVALID_INSTR;
|
exception_cause <= CSR_CAUSE_INVALID_INSTR;
|
branch <= BRANCH_NONE;
|
branch <= BRANCH_NONE;
|
end case;
|
end case;
|
end process decode_ctrl;
|
end process decode_ctrl;
|
|
|
decode_csr: process(opcode, funct3)
|
decode_csr: process(opcode, funct3)
|