1 -- `Deep Thought', a softcore CPU implemented on a FPGA
3 -- Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
4 -- Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
5 -- Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
6 -- Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
7 -- Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
9 -- This program is free software: you can redistribute it and/or modify
10 -- it under the terms of the GNU General Public License as published by
11 -- the Free Software Foundation, either version 3 of the License, or
12 -- (at your option) any later version.
14 -- This program is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 -- GNU General Public License for more details.
19 -- You should have received a copy of the GNU General Public License
20 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
23 use IEEE.std_logic_1164.all;
24 use IEEE.numeric_std.all;
26 use work.common_pkg.all;
27 use work.core_pkg.all;
28 use work.extension_pkg.all;
34 sys_res : in std_logic;
35 soft_res : in std_logic;
36 sys_clk_in : in std_logic;
37 -- result : out gp_register_t;
38 -- reg_wr_data : out gp_register_t
40 bus_tx : out std_logic;
41 bus_rx : in std_logic;
44 --sseg0 : out std_logic_vector(0 to 6);
45 --sseg1 : out std_logic_vector(0 to 6);
46 --sseg2 : out std_logic_vector(0 to 6);
47 --sseg3 : out std_logic_vector(0 to 6)
52 architecture behav of core_top is
54 constant SYNC_STAGES : integer := 2;
55 constant RESET_VALUE : std_logic := '0';
57 signal sys_clk : std_logic;
59 signal jump_result : instruction_addr_t;
60 signal jump_result_pin : instruction_addr_t;
61 signal prediction_result_pin : instruction_addr_t;
62 signal branch_prediction_bit_pin : std_logic;
63 signal alu_jump_bit_pin : std_logic;
64 signal instruction_pin : instruction_word_t;
65 signal prog_cnt_pin : instruction_addr_t;
67 signal reg_w_addr_pin : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
68 signal reg_wr_data_pin : gp_register_t;
69 signal reg_we_pin : std_logic;
70 signal to_next_stage : dec_op;
72 -- signal reg1_rd_data_pin : gp_register_t;
73 -- signal reg2_rd_data_pin : gp_register_t;
75 signal result_pin : gp_register_t;--reg
76 signal result_addr_pin : gp_addr_t;--reg
77 signal addr_pin : word_t; --memaddr
78 signal data_pin : gp_register_t; --mem data --ureg
79 signal alu_jump_pin : std_logic;--reg
80 signal brpr_pin : std_logic; --reg
81 signal wr_en_pin : std_logic;--regop --reg
82 signal dmem_pin : std_logic;--memop
83 signal dmem_wr_en_pin : std_logic;
84 signal hword_pin : std_logic;
85 signal byte_s_pin : std_logic;
87 signal gpm_in_pin : extmod_rec;
88 signal gpm_out_pin : gp_register_t;
89 signal nop_pin : std_logic;
91 signal sync, sync2 : std_logic_vector(1 to SYNC_STAGES);
92 signal sys_res_n, soft_res_n : std_logic;
94 signal int_req : interrupt_t;
96 signal new_im_data : std_logic;
97 signal im_addr, im_data : gp_register_t;
99 signal vers, vers_nxt : exec2wb_rec;
105 inclk0 : IN STD_LOGIC := '0';
111 pll_inst : pll PORT MAP (
112 inclk0 => sys_clk_in,
117 fetch_st : fetch_stage
126 clk => sys_clk, --: in std_logic;
127 reset => sys_res_n, --: in std_logic;
128 s_reset => soft_res_n,
130 jump_result => jump_result_pin, --: in instruction_addr_t;
131 prediction_result => prediction_result_pin, --: in instruction_addr_t;
132 branch_prediction_bit => branch_prediction_bit_pin, --: in std_logic;
133 alu_jump_bit => alu_jump_bit_pin, --: in std_logic;
135 -- instruction memory program port :D
136 new_im_data_in => new_im_data,
140 instruction => instruction_pin, --: out instruction_word_t
141 prog_cnt => prog_cnt_pin,
145 decode_st : decode_stage
147 -- active reset value
149 -- active logic value
155 clk => sys_clk, --: in std_logic;
156 reset => sys_res_n and soft_res_n, -- : in std_logic;
159 instruction => instruction_pin, --: in instruction_word_t;
160 prog_cnt => prog_cnt_pin,
161 reg_w_addr => reg_w_addr_pin, --: in std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
162 reg_wr_data => reg_wr_data_pin, --: in gp_register_t;
163 reg_we => reg_we_pin, --: in std_logic;
167 branch_prediction_res => prediction_result_pin, --: instruction_word_t;
168 branch_prediction_bit => branch_prediction_bit_pin, --: std_logic
169 to_next_stage => to_next_stage
172 exec_st : execute_stage
174 port map(sys_clk, sys_res_n and soft_res_n, to_next_stage, reg_wr_data_pin, reg_we_pin, reg_w_addr_pin, gpm_in_pin, result_pin, result_addr_pin,addr_pin,
175 data_pin, alu_jump_pin,brpr_pin, wr_en_pin, dmem_pin,dmem_wr_en_pin,hword_pin,byte_s_pin, gpm_out_pin);
178 vers_nxt.result <= result_pin;
179 vers_nxt.result_addr <= result_addr_pin;
180 vers_nxt.address <= addr_pin;
181 vers_nxt.ram_data <= data_pin;
182 vers_nxt.alu_jmp <= alu_jump_pin;
183 vers_nxt.br_pred <= brpr_pin;
184 vers_nxt.write_en <= wr_en_pin;
185 vers_nxt.dmem_en <= dmem_pin;
186 vers_nxt.dmem_write_en <= dmem_wr_en_pin;
187 vers_nxt.hword <= hword_pin;
188 vers_nxt.byte_s <= byte_s_pin;
190 -- writeback_st : writeback_stage
191 -- generic map('0', '1')
192 -- port map(sys_clk, sys_res, result_pin, result_addr_pin, addr_pin, data_pin, alu_jump_pin, brpr_pin,
193 -- wr_en_pin, dmem_pin, dmem_wr_en_pin, hword_pin, byte_s_pin,
194 -- reg_wr_data_pin, reg_we_pin, reg_w_addr_pin, jump_result_pin, alu_jump_bit_pin,bus_tx, sseg0, sseg1, sseg2, sseg3);
197 writeback_st : writeback_stage
198 generic map('0', '1', "altera", 5208)
199 port map(sys_clk, sys_res_n and soft_res_n, vers_nxt.result, vers_nxt.result_addr, vers_nxt.address, vers_nxt.ram_data, vers_nxt.alu_jmp, vers_nxt.br_pred,
200 vers_nxt.write_en, vers_nxt.dmem_en, vers_nxt.dmem_write_en, vers_nxt.hword, vers_nxt.byte_s,
201 reg_wr_data_pin, reg_we_pin, reg_w_addr_pin, jump_result_pin, alu_jump_bit_pin,bus_tx, bus_rx,
202 -- instruction memory program port :D
203 new_im_data, im_addr, im_data,
204 --sseg0, sseg1, sseg2, sseg3,
208 syn: process(sys_clk, sys_res, soft_res)
212 if sys_res = '1' then
213 -- vers.result <= (others => '0');
214 -- vers.result_addr <= (others => '0');
215 -- vers.address <= (others => '0');
216 -- vers.ram_data <= (others => '0');
217 -- vers.alu_jmp <= '0';
218 -- vers.br_pred <= '0';
219 -- vers.write_en <= '0';
220 -- vers.dmem_en <= '0';
221 -- vers.dmem_write_en <= '0';
222 -- vers.hword <= '0';
223 -- vers.byte_s <= '0';
225 sync <= (others => '0');
226 sync2 <= (others => '0');
228 elsif rising_edge(sys_clk) then
230 sync(1) <= not sys_res;
231 for i in 2 to SYNC_STAGES loop
232 sync(i) <= sync(i - 1);
234 sync2(1) <= not soft_res;
235 for i in 2 to SYNC_STAGES loop
236 sync2(i) <= sync2(i - 1);
243 sys_res_n <= sync(SYNC_STAGES);
244 soft_res_n <= sync2(SYNC_STAGES);
246 --init : process(all)
249 -- jump_result_pin <= (others => '0');
250 -- alu_jump_bit_pin <= '0';
251 -- reg_w_addr_pin <= (others => '0');
252 -- reg_wr_data_pin <= (others => '0');
253 -- reg_we_pin <= '0';
257 -- result <= result_pin;
258 nop_pin <= (alu_jump_bit_pin); -- xor brpr_pin);
260 jump_result <= prog_cnt_pin; --jump_result_pin;
263 -- reg_wr_data <= reg_wr_data_pin;