| 1 |
2 |
skordal |
-- The Potato Processor - A simple processor for FPGAs
|
| 2 |
|
|
-- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
|
| 3 |
3 |
skordal |
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
|
| 4 |
2 |
skordal |
|
| 5 |
|
|
library ieee;
|
| 6 |
|
|
use ieee.std_logic_1164.all;
|
| 7 |
|
|
use ieee.numeric_std.all;
|
| 8 |
|
|
|
| 9 |
|
|
use work.pp_types.all;
|
| 10 |
|
|
use work.pp_constants.all;
|
| 11 |
|
|
use work.pp_csr.all;
|
| 12 |
|
|
|
| 13 |
|
|
--! @brief Instruction decode unit.
|
| 14 |
|
|
entity pp_decode is
|
| 15 |
|
|
generic(
|
| 16 |
|
|
RESET_ADDRESS : std_logic_vector(31 downto 0);
|
| 17 |
|
|
PROCESSOR_ID : std_logic_vector(31 downto 0)
|
| 18 |
|
|
);
|
| 19 |
|
|
port(
|
| 20 |
|
|
clk : in std_logic;
|
| 21 |
|
|
reset : in std_logic;
|
| 22 |
|
|
|
| 23 |
|
|
flush : in std_logic;
|
| 24 |
|
|
stall : in std_logic;
|
| 25 |
|
|
|
| 26 |
|
|
-- Instruction input:
|
| 27 |
|
|
instruction_data : in std_logic_vector(31 downto 0);
|
| 28 |
|
|
instruction_address : in std_logic_vector(31 downto 0);
|
| 29 |
|
|
instruction_ready : in std_logic;
|
| 30 |
|
|
instruction_count : in std_logic;
|
| 31 |
|
|
|
| 32 |
|
|
-- Register addresses:
|
| 33 |
|
|
rs1_addr, rs2_addr, rd_addr : out register_address;
|
| 34 |
|
|
csr_addr : out csr_address;
|
| 35 |
|
|
|
| 36 |
|
|
-- Shamt value for shift operations:
|
| 37 |
|
|
shamt : out std_logic_vector(4 downto 0);
|
| 38 |
|
|
funct3 : out std_logic_vector(2 downto 0);
|
| 39 |
|
|
|
| 40 |
|
|
-- Immediate value for immediate instructions:
|
| 41 |
|
|
immediate : out std_logic_vector(31 downto 0);
|
| 42 |
|
|
|
| 43 |
|
|
-- Control signals:
|
| 44 |
|
|
rd_write : out std_logic;
|
| 45 |
|
|
branch : out branch_type;
|
| 46 |
|
|
alu_x_src : out alu_operand_source;
|
| 47 |
|
|
alu_y_src : out alu_operand_source;
|
| 48 |
|
|
alu_op : out alu_operation;
|
| 49 |
|
|
mem_op : out memory_operation_type;
|
| 50 |
|
|
mem_size : out memory_operation_size;
|
| 51 |
|
|
count_instruction : out std_logic;
|
| 52 |
|
|
|
| 53 |
|
|
-- Instruction address:
|
| 54 |
|
|
pc : out std_logic_vector(31 downto 0);
|
| 55 |
|
|
|
| 56 |
|
|
-- CSR control signals:
|
| 57 |
|
|
csr_write : out csr_write_mode;
|
| 58 |
|
|
csr_use_imm : out std_logic;
|
| 59 |
|
|
|
| 60 |
|
|
-- Exception output signals:
|
| 61 |
|
|
decode_exception : out std_logic;
|
| 62 |
|
|
decode_exception_cause : out csr_exception_cause
|
| 63 |
|
|
);
|
| 64 |
|
|
|
| 65 |
|
|
end entity pp_decode;
|
| 66 |
|
|
|
| 67 |
|
|
architecture behaviour of pp_decode is
|
| 68 |
|
|
signal instruction : std_logic_vector(31 downto 0);
|
| 69 |
|
|
signal immediate_value : std_logic_vector(31 downto 0);
|
| 70 |
|
|
begin
|
| 71 |
|
|
|
| 72 |
|
|
immediate <= immediate_value;
|
| 73 |
|
|
|
| 74 |
|
|
get_instruction: process(clk)
|
| 75 |
|
|
begin
|
| 76 |
|
|
if rising_edge(clk) then
|
| 77 |
|
|
if reset = '1' then
|
| 78 |
|
|
instruction <= RISCV_NOP;
|
| 79 |
|
|
pc <= RESET_ADDRESS;
|
| 80 |
|
|
count_instruction <= '0';
|
| 81 |
|
|
elsif stall = '1' then
|
| 82 |
|
|
count_instruction <= '0';
|
| 83 |
|
|
elsif flush = '1' or instruction_ready = '0' then
|
| 84 |
|
|
instruction <= RISCV_NOP;
|
| 85 |
|
|
count_instruction <= '0';
|
| 86 |
|
|
else
|
| 87 |
|
|
instruction <= instruction_data;
|
| 88 |
|
|
count_instruction <= instruction_count;
|
| 89 |
|
|
pc <= instruction_address;
|
| 90 |
|
|
end if;
|
| 91 |
|
|
end if;
|
| 92 |
|
|
end process get_instruction;
|
| 93 |
|
|
|
| 94 |
|
|
-- -- Extract register addresses from the instruction word:
|
| 95 |
|
|
rs1_addr <= instruction(19 downto 15);
|
| 96 |
|
|
rs2_addr <= instruction(24 downto 20);
|
| 97 |
|
|
rd_addr <= instruction(11 downto 7);
|
| 98 |
|
|
|
| 99 |
|
|
-- Extract the shamt value from the instruction word:
|
| 100 |
|
|
shamt <= instruction(24 downto 20);
|
| 101 |
|
|
|
| 102 |
|
|
-- Extract the value specifying which comparison to do in branch instructions:
|
| 103 |
|
|
funct3 <= instruction(14 downto 12);
|
| 104 |
|
|
|
| 105 |
|
|
-- Extract the immediate value from the instruction word:
|
| 106 |
|
|
immediate_decoder: entity work.pp_imm_decoder
|
| 107 |
|
|
port map(
|
| 108 |
|
|
instruction => instruction(31 downto 2),
|
| 109 |
|
|
immediate => immediate_value
|
| 110 |
|
|
);
|
| 111 |
|
|
|
| 112 |
|
|
decode_csr_addr: process(immediate_value)
|
| 113 |
|
|
begin
|
| 114 |
58 |
skordal |
if immediate_value(11 downto 0) = CSR_EPC_ERET then
|
| 115 |
|
|
csr_addr <= CSR_MEPC;
|
| 116 |
2 |
skordal |
else
|
| 117 |
|
|
csr_addr <= immediate_value(11 downto 0);
|
| 118 |
|
|
end if;
|
| 119 |
|
|
end process decode_csr_addr;
|
| 120 |
|
|
|
| 121 |
|
|
control_unit: entity work.pp_control_unit
|
| 122 |
|
|
port map(
|
| 123 |
|
|
opcode => instruction(6 downto 2),
|
| 124 |
|
|
funct3 => instruction(14 downto 12),
|
| 125 |
|
|
funct7 => instruction(31 downto 25),
|
| 126 |
|
|
funct12 => instruction(31 downto 20),
|
| 127 |
|
|
rd_write => rd_write,
|
| 128 |
|
|
branch => branch,
|
| 129 |
|
|
alu_x_src => alu_x_src,
|
| 130 |
|
|
alu_y_src => alu_y_src,
|
| 131 |
|
|
alu_op => alu_op,
|
| 132 |
|
|
mem_op => mem_op,
|
| 133 |
|
|
mem_size => mem_size,
|
| 134 |
|
|
decode_exception => decode_exception,
|
| 135 |
|
|
decode_exception_cause => decode_exception_cause,
|
| 136 |
|
|
csr_write => csr_write,
|
| 137 |
|
|
csr_imm => csr_use_imm
|
| 138 |
|
|
);
|
| 139 |
|
|
|
| 140 |
|
|
end architecture behaviour;
|