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;
30 entity core_top_c2de1 is
34 sys_res : in std_logic;
35 soft_res : in std_logic;
36 sys_clk : 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_c2de1 is
54 constant SYNC_STAGES : integer := 2;
55 constant RESET_VALUE : std_logic := '0';
57 signal jump_result : instruction_addr_t;
58 signal jump_result_pin : instruction_addr_t;
59 signal prediction_result_pin : instruction_addr_t;
60 signal branch_prediction_bit_pin : std_logic;
61 signal alu_jump_bit_pin : std_logic;
62 signal instruction_pin : instruction_word_t;
63 signal prog_cnt_pin : instruction_addr_t;
65 signal reg_w_addr_pin : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
66 signal reg_wr_data_pin : gp_register_t;
67 signal reg_we_pin : std_logic;
68 signal to_next_stage : dec_op;
70 signal result_pin : gp_register_t;--reg
71 signal result_addr_pin : gp_addr_t;--reg
72 signal addr_pin : word_t; --memaddr
73 signal data_pin : gp_register_t; --mem data --ureg
74 signal alu_jump_pin : std_logic;--reg
75 signal brpr_pin : std_logic; --reg
76 signal wr_en_pin : std_logic;--regop --reg
77 signal dmem_pin : std_logic;--memop
78 signal dmem_wr_en_pin : std_logic;
79 signal hword_pin : std_logic;
80 signal byte_s_pin : std_logic;
82 signal gpm_in_pin : extmod_rec;
83 signal gpm_out_pin : gp_register_t;
84 signal nop_pin : std_logic;
86 signal sync : std_logic_vector(1 to SYNC_STAGES);
87 signal sync2 : std_logic_vector(1 to SYNC_STAGES);
88 signal sys_res_n, soft_res_n : std_logic;
90 signal int_req : interrupt_t;
92 signal new_im_data : std_logic;
93 signal im_addr, im_data : gp_register_t;
94 -- signal led2 : std_logic;
96 signal vers, vers_nxt : exec2wb_rec;
99 fetch_st : fetch_stage
108 clk => sys_clk, --: in std_logic;
109 reset => sys_res_n, --: in std_logic;
110 s_reset => soft_res_n,
113 jump_result => jump_result_pin, --: in instruction_addr_t;
114 prediction_result => prediction_result_pin, --: in instruction_addr_t;
115 branch_prediction_bit => branch_prediction_bit_pin, --: in std_logic;
116 alu_jump_bit => alu_jump_bit_pin, --: in std_logic;
118 -- instruction memory program port :D
119 new_im_data_in => new_im_data,
123 instruction => instruction_pin, --: out instruction_word_t
124 prog_cnt => prog_cnt_pin,
128 decode_st : decode_stage
130 -- active reset value
132 -- active logic value
138 clk => sys_clk, --: in std_logic;
139 reset => sys_res_n and soft_res_n, -- : in std_logic;
142 instruction => instruction_pin, --: in instruction_word_t;
143 prog_cnt => prog_cnt_pin,
144 reg_w_addr => reg_w_addr_pin, --: in std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
145 reg_wr_data => reg_wr_data_pin, --: in gp_register_t;
146 reg_we => reg_we_pin, --: in std_logic;
150 branch_prediction_res => prediction_result_pin, --: instruction_word_t;
151 branch_prediction_bit => branch_prediction_bit_pin, --: std_logic
152 to_next_stage => to_next_stage
155 exec_st : execute_stage
156 generic map(RESET_VALUE)
157 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,
158 data_pin, alu_jump_pin,brpr_pin, wr_en_pin, dmem_pin,dmem_wr_en_pin,hword_pin,byte_s_pin, gpm_out_pin);
161 writeback_st : writeback_stage
162 generic map(RESET_VALUE, '1', "altera", 434)
163 port map(sys_clk, sys_res_n and soft_res_n, result_pin, result_addr_pin, addr_pin, data_pin, alu_jump_pin, brpr_pin,
164 wr_en_pin, dmem_pin, dmem_wr_en_pin, hword_pin, byte_s_pin,
165 reg_wr_data_pin, reg_we_pin, reg_w_addr_pin, jump_result_pin, alu_jump_bit_pin,bus_tx, bus_rx,
166 new_im_data, im_addr, im_data, sseg0, sseg1, sseg2, sseg3, int_req);
170 syn: process(sys_clk, sys_res)
174 if sys_res = RESET_VALUE then
176 sync <= (others => RESET_VALUE);
178 elsif rising_edge(sys_clk) then
180 for i in 2 to SYNC_STAGES loop
181 sync(i) <= sync(i - 1);
184 sync2(1) <= soft_res;
185 for i in 2 to SYNC_STAGES loop
186 sync2(i) <= sync2(i - 1);
193 sys_res_n <= sync(SYNC_STAGES);
194 soft_res_n <= sync2(SYNC_STAGES);
195 nop_pin <= (alu_jump_bit_pin); -- xor brpr_pin);
196 jump_result <= prog_cnt_pin; --jump_result_pin;