| 1 |
4 |
atypic |
library ieee;
|
| 2 |
|
|
use ieee.std_logic_1164.all;
|
| 3 |
|
|
|
| 4 |
|
|
library work;
|
| 5 |
|
|
use work.leval2_constants.all;
|
| 6 |
|
|
use work.all;
|
| 7 |
|
|
|
| 8 |
|
|
entity whisk is
|
| 9 |
|
|
port (
|
| 10 |
|
|
clk : in std_logic;
|
| 11 |
|
|
rst : in std_logic;
|
| 12 |
|
|
data_in : in std_logic_vector (BUS_BITS - 1 downto 0);
|
| 13 |
|
|
data_out : in std_logic_vector (BUS_BITS - 1 downto 0);
|
| 14 |
|
|
addr_bus : in std_logic_vector (ADDR_BITS - 1 downto 0);
|
| 15 |
|
|
iowait : in std_logic;
|
| 16 |
|
|
sync : in std_logic;
|
| 17 |
|
|
read : out std_logic;
|
| 18 |
|
|
write : out std_logic;
|
| 19 |
|
|
led : out std_logic);
|
| 20 |
|
|
end entity;
|
| 21 |
|
|
|
| 22 |
|
|
architecture rtl of whisk is
|
| 23 |
|
|
-- signals from control
|
| 24 |
|
|
signal ctrl_indir_reg1 : std_logic;
|
| 25 |
|
|
signal ctrl_indir_reg2 : std_logic;
|
| 26 |
|
|
signal ctrl_indir_idex_reg1 : std_logic;
|
| 27 |
|
|
signal ctrl_indir_idex_reg2 : std_logic;
|
| 28 |
|
|
signal ctrl_alu_funct : std_logic_vector(ALU_FUNCT_SIZE - 1 downto 0);
|
| 29 |
|
|
signal ctrl_reg_write : std_logic;
|
| 30 |
|
|
|
| 31 |
|
|
-- signals from stage 1 (fetch)
|
| 32 |
|
|
signal ctrl_pc_mux : std_logic_vector(1 downto 0);
|
| 33 |
|
|
signal fetched_instruction : std_logic_vector(MC_INSTR_BITS - 1 downto 0);
|
| 34 |
|
|
signal branch_target : std_logic_vector(MC_ADDR_BITS - 1 downto 0);
|
| 35 |
|
|
|
| 36 |
|
|
-- signals from stage 2 (decode)
|
| 37 |
|
|
signal reg1_out : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 38 |
|
|
signal reg2_out : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 39 |
|
|
|
| 40 |
|
|
-- signal ctrl_regs_we : std_logic;
|
| 41 |
|
|
signal ctrl_regs_addr_src_1 : std_logic;
|
| 42 |
|
|
signal ctrl_regs_addr_src_2 : std_logic;
|
| 43 |
|
|
signal immediate : std_logic_vector(IMM_SIZE - 1 downto 0);
|
| 44 |
|
|
signal decode_reg_write : std_logic;
|
| 45 |
|
|
signal alu_funct : std_logic_vector(ALU_FUNCT_SIZE - 1 downto 0);
|
| 46 |
|
|
|
| 47 |
|
|
-- signals from stage 3 (exec)
|
| 48 |
|
|
signal alu_result : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 49 |
|
|
signal alu_flags : std_logic_vector(STATUS_REG_BITS - 1 downto 0);
|
| 50 |
|
|
signal exec_write_mem : std_logic;
|
| 51 |
|
|
signal exec_read_mem : std_logic;
|
| 52 |
|
|
signal exec_mem_ce : std_logic_vector(1 downto 0);
|
| 53 |
|
|
signal exec_branch_taken : std_logic;
|
| 54 |
|
|
signal exec_reg_write : std_logic; -- fwd to memory stage
|
| 55 |
|
|
signal exec_reg2_out : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 56 |
|
|
|
| 57 |
|
|
-- signals from memory stage
|
| 58 |
|
|
signal mem_mem_to_reg : std_logic;
|
| 59 |
|
|
|
| 60 |
|
|
signal mem_reg_write : std_logic; -- register write control signal fed forward
|
| 61 |
|
|
signal mem_reg_data : std_logic_vector(WORD_BITS - 1 downto 0); -- data from register to store
|
| 62 |
|
|
|
| 63 |
|
|
signal mem_loaded_data : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 64 |
|
|
signal mem_alu_result : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 65 |
|
|
|
| 66 |
|
|
signal mem_write_mem : std_logic; -- signal out of memory stage to external mem
|
| 67 |
|
|
signal mem_read_mem : std_logic; -- signal out of memory to external mem
|
| 68 |
|
|
|
| 69 |
|
|
-- signals from write back
|
| 70 |
|
|
signal wb_reg_write : std_logic; -- register write control signal piped forward
|
| 71 |
|
|
signal wb_reg_data : std_logic_vector(WORD_BITS - 1 downto 0); -- data to write to register
|
| 72 |
|
|
|
| 73 |
|
|
-- signals used from and to the data bus and to off-chip
|
| 74 |
|
|
signal bus_read_data : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 75 |
|
|
signal mem_write_enable : std_logic; -- to external memory
|
| 76 |
|
|
signal mem_write_data : std_logic_vector(WORD_BITS - 1 downto 0);
|
| 77 |
|
|
signal databus : std_logic_vector(WORD_BITS - 1 downto 0); --to outside.
|
| 78 |
|
|
signal mem_address : std_logic_vector(ADDR_BITS - 1 downto 0);
|
| 79 |
|
|
|
| 80 |
|
|
signal memory_wait : std_logic;
|
| 81 |
|
|
signal memory_ce : std_logic_vector(1 downto 0);
|
| 82 |
|
|
signal avr_irq : std_logic;
|
| 83 |
|
|
begin
|
| 84 |
|
|
|
| 85 |
|
|
fetch_stage : entity instr_fetch
|
| 86 |
|
|
port map (
|
| 87 |
|
|
core_clk => clk,
|
| 88 |
|
|
core_rst => rst,
|
| 89 |
|
|
pc_mux => ctrl_pc_mux,
|
| 90 |
|
|
instruction => fetched_instruction,
|
| 91 |
|
|
branch_target => branch_target );
|
| 92 |
|
|
|
| 93 |
|
|
decode_stage : entity instr_decode
|
| 94 |
|
|
port map (
|
| 95 |
|
|
instr => fetched_instruction,
|
| 96 |
|
|
clk => clk,
|
| 97 |
|
|
reg1 => reg1_out,
|
| 98 |
|
|
reg2 => reg2_out,
|
| 99 |
|
|
regs_addr_src_1 => ctrl_regs_addr_src_1,
|
| 100 |
|
|
regs_addr_src_2 => ctrl_regs_addr_src_2,
|
| 101 |
|
|
indir_reg1_sel => ctrl_indir_reg1,
|
| 102 |
|
|
indir_reg2_sel => ctrl_indir_reg2,
|
| 103 |
|
|
regs_data_in => wb_reg_data,
|
| 104 |
|
|
ctrl_regs_we => ctrl_reg_write,
|
| 105 |
|
|
wb_reg_write => mem_reg_write,
|
| 106 |
|
|
ctrl_alu_funct => ctrl_alu_funct,
|
| 107 |
|
|
reg_write => decode_reg_write,
|
| 108 |
|
|
alu_funct => alu_funct);
|
| 109 |
|
|
|
| 110 |
|
|
exec_stage : entity exec
|
| 111 |
|
|
port map (
|
| 112 |
|
|
clk => clk,
|
| 113 |
|
|
operand1 => reg1_out,
|
| 114 |
|
|
operand2 => reg2_out,
|
| 115 |
|
|
imm => immediate,
|
| 116 |
|
|
alu_res => alu_result,
|
| 117 |
|
|
alu_flags => alu_flags,
|
| 118 |
|
|
alu_funct => alu_funct,
|
| 119 |
|
|
reg_write => decode_reg_write,
|
| 120 |
|
|
branch_taken => exec_branch_taken,
|
| 121 |
|
|
branch_target => branch_target,
|
| 122 |
|
|
exec_reg_write => exec_reg_write,
|
| 123 |
|
|
exec_reg2_out => exec_reg2_out);
|
| 124 |
|
|
|
| 125 |
|
|
mem_stage : entity mem
|
| 126 |
|
|
port map (
|
| 127 |
|
|
-- Pipeline control signals
|
| 128 |
|
|
clk => clk,
|
| 129 |
|
|
|
| 130 |
|
|
exec_reg_write => exec_reg_write, -- Register write control (in)
|
| 131 |
|
|
mem_reg_write => mem_reg_write, -- Register write control (out)
|
| 132 |
|
|
|
| 133 |
|
|
mem_mem_to_reg => mem_mem_to_reg, -- Write to register when read
|
| 134 |
|
|
|
| 135 |
|
|
address => alu_result(WORD_BITS - 1 downto 0), -- address to read/write
|
| 136 |
|
|
data => exec_reg2_out, -- Data to write
|
| 137 |
|
|
|
| 138 |
|
|
mem_loaded_data => mem_loaded_data,
|
| 139 |
|
|
mem_alu_result => mem_alu_result,
|
| 140 |
|
|
|
| 141 |
|
|
-- Bus IO
|
| 142 |
|
|
mem_read_data => bus_read_data,
|
| 143 |
|
|
mem_write_data => mem_write_data,
|
| 144 |
|
|
mem_address => mem_address,
|
| 145 |
|
|
|
| 146 |
|
|
write_mem => mem_write_mem,
|
| 147 |
|
|
read_mem => mem_read_mem,
|
| 148 |
|
|
memory_wait => memory_wait -- Stall signal from external memory
|
| 149 |
|
|
);
|
| 150 |
|
|
|
| 151 |
|
|
bus_interface : entity bidirbus
|
| 152 |
|
|
port map (
|
| 153 |
|
|
clk => clk,
|
| 154 |
|
|
bidir => databus,
|
| 155 |
|
|
oe => mem_write_enable,
|
| 156 |
|
|
inp => mem_write_data,
|
| 157 |
|
|
outp => bus_read_data);
|
| 158 |
|
|
-- write back stage
|
| 159 |
|
|
wb_reg_data <= mem_loaded_data when mem_mem_to_reg = '1' else mem_alu_result;
|
| 160 |
|
|
wb_reg_write <= mem_reg_write;
|
| 161 |
|
|
|
| 162 |
|
|
-- ctrl section
|
| 163 |
|
|
control : entity control
|
| 164 |
|
|
port map (
|
| 165 |
|
|
indir_reg1 => ctrl_indir_reg1,
|
| 166 |
|
|
indir_reg2 => ctrl_indir_reg2,
|
| 167 |
|
|
indir_idex_reg1 => ctrl_indir_idex_reg1,
|
| 168 |
|
|
indir_idex_reg2 => ctrl_indir_idex_reg2,
|
| 169 |
|
|
pc_mux => ctrl_pc_mux,
|
| 170 |
|
|
opcode => fetched_instruction(INSTR_OPCODE_START downto INSTR_OPCODE_END),
|
| 171 |
|
|
idex_alu_funct => ctrl_alu_funct,
|
| 172 |
|
|
reg_write => ctrl_reg_write,
|
| 173 |
|
|
memory_wait => memory_wait,
|
| 174 |
|
|
branch => exec_branch_taken);
|
| 175 |
|
|
|
| 176 |
|
|
end architecture;
|