copyleft: gplv3 added and set repo to public
[calu.git] / cpu / src / core_top_c4de2_115.vhd
1 --   `Deep Thought', a softcore CPU implemented on a FPGA
2 --
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>
8 --
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.
13 --
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.
18 --
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/>.
21
22 library IEEE;
23 use IEEE.std_logic_1164.all;
24 use IEEE.numeric_std.all;
25
26 use work.common_pkg.all;
27 use work.core_pkg.all;
28 use work.extension_pkg.all;
29
30 entity core_top_c4de2_115 is
31
32         port(
33                 --System input pins
34                 CLOCK_50        : in std_logic;
35                 --Reset buttons
36                 KEY : in std_logic_vector(0 to 3);
37
38                 -- uart
39                 UART_TXD : out std_logic;
40                 UART_RXD : in std_logic;
41                 -- bootrom led
42                 LEDR : out std_logic_vector(0 to 17);
43                 LEDG : out std_logic_vector(0 to 8);
44
45                 HEX0 : out std_logic_vector(0 to 6);
46                 HEX1 : out std_logic_vector(0 to 6);
47                 HEX2 : out std_logic_vector(0 to 6);
48                 HEX3 : out std_logic_vector(0 to 6);
49
50
51                 LCD_DATA_8 : out std_logic_vector(7 downto 0);
52                 LCD_BLON : out std_logic;
53                 LCD_RW : out std_logic;
54                 LCD_EN : out std_logic;
55                 LCD_RS : out std_logic;
56                 LCD_ON : out std_logic
57
58
59         );
60
61 end core_top_c4de2_115;
62
63 architecture behav of core_top_c4de2_115 is
64
65                 constant SYNC_STAGES : integer := 2;
66                 constant RESET_VALUE : std_logic := '0';
67
68                 signal sys_clk, sys_res, soft_res : std_logic;
69                 signal bus_tx, bus_rx : std_logic;
70                 signal led2 : std_logic;
71                 signal sseg0, sseg1, sseg2, sseg3 : std_logic_vector(0 to 6);
72
73                 signal jump_result : instruction_addr_t;
74                 signal jump_result_pin : instruction_addr_t;
75                 signal prediction_result_pin : instruction_addr_t;
76                 signal branch_prediction_bit_pin : std_logic;
77                 signal alu_jump_bit_pin : std_logic;
78                 signal instruction_pin : instruction_word_t;
79                 signal prog_cnt_pin : instruction_addr_t;
80
81                 signal reg_w_addr_pin : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
82                 signal reg_wr_data_pin : gp_register_t;
83                 signal reg_we_pin : std_logic;
84                 signal to_next_stage : dec_op;
85
86                 signal result_pin : gp_register_t;--reg
87                 signal result_addr_pin : gp_addr_t;--reg
88                 signal addr_pin : word_t; --memaddr
89                 signal data_pin : gp_register_t; --mem data --ureg
90                 signal alu_jump_pin : std_logic;--reg
91                 signal brpr_pin  : std_logic;  --reg
92                 signal wr_en_pin : std_logic;--regop --reg
93                 signal dmem_pin  : std_logic;--memop
94                 signal dmem_wr_en_pin : std_logic;
95                 signal hword_pin  : std_logic;
96                 signal byte_s_pin : std_logic;
97
98                 signal gpm_in_pin : extmod_rec;
99                 signal gpm_out_pin : gp_register_t;
100                 signal nop_pin : std_logic;
101
102                 signal sync : std_logic_vector(1 to SYNC_STAGES);
103                 signal sync2 : std_logic_vector(1 to SYNC_STAGES);
104                 signal sys_res_n, soft_res_n : std_logic;
105
106                 signal int_req : interrupt_t;
107
108                 signal new_im_data : std_logic;
109                 signal im_addr, im_data : gp_register_t;
110 --              signal led2 : std_logic;
111
112                 signal vers, vers_nxt : exec2wb_rec;
113 begin
114         sys_clk <= CLOCK_50;
115         sys_res <= KEY(0);
116         soft_res <= KEY(1);
117
118         UART_TXD <= bus_tx;
119         bus_rx <= UART_RXD;
120
121         --bootrom status
122         LEDR(0) <= led2;
123         LEDR(1 to 17) <= (others => '0');
124         LEDG <= (others => '0');
125
126         HEX0 <= sseg0;
127         HEX1 <= sseg1;
128         HEX2 <= sseg2;
129         HEX3 <= sseg3;
130
131         fetch_st : fetch_stage
132                 generic map (
133
134                         RESET_VALUE,
135                         '1'
136                 )
137
138                 port map (
139                 --System inputs
140                         clk => sys_clk, --: in std_logic;
141                         reset => sys_res_n, --: in std_logic;
142                         s_reset => soft_res_n,
143
144                 --Data inputs
145                         jump_result => jump_result_pin, --: in instruction_addr_t;
146                         prediction_result => prediction_result_pin, --: in instruction_addr_t;
147                         branch_prediction_bit => branch_prediction_bit_pin,  --: in std_logic;
148                         alu_jump_bit => alu_jump_bit_pin, --: in std_logic;
149                         int_req => int_req,
150                 -- instruction memory program port :D
151                         new_im_data_in => new_im_data,
152                         im_addr => im_addr,
153                         im_data => im_data,
154                 --Data outputs
155                         instruction => instruction_pin, --: out instruction_word_t
156                         prog_cnt => prog_cnt_pin,
157                         led2 => led2
158                 );
159
160         decode_st : decode_stage
161                 generic map (
162                         -- active reset value
163                         RESET_VALUE,
164                         -- active logic value
165                         '1'
166                         )
167                 port map (
168                 --System inputs
169                         clk => sys_clk, --: in std_logic;
170                         reset => sys_res_n and soft_res_n, -- : in std_logic;
171
172                 --Data inputs
173                         instruction => instruction_pin, --: in instruction_word_t;
174                         prog_cnt => prog_cnt_pin,
175                         reg_w_addr => reg_w_addr_pin, --: in std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
176                         reg_wr_data => reg_wr_data_pin, --: in gp_register_t;
177                         reg_we => reg_we_pin, --: in std_logic;
178                         nop => nop_pin,
179
180                 --Data outputs
181                         branch_prediction_res => prediction_result_pin, --: instruction_word_t;
182                         branch_prediction_bit => branch_prediction_bit_pin, --: std_logic
183                         to_next_stage => to_next_stage
184                 );
185
186                 exec_st : execute_stage
187                         generic map(RESET_VALUE)
188                         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,
189                                  data_pin, alu_jump_pin,brpr_pin, wr_en_pin, dmem_pin,dmem_wr_en_pin,hword_pin,byte_s_pin, gpm_out_pin);
190
191                 writeback_st : writeback_stage
192                         generic map(RESET_VALUE, '1', "altera", 434)
193                         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, 
194                                  wr_en_pin, dmem_pin, dmem_wr_en_pin, hword_pin, byte_s_pin,
195                                  reg_wr_data_pin, reg_we_pin, reg_w_addr_pin, jump_result_pin, alu_jump_bit_pin,bus_tx, bus_rx, 
196                                  new_im_data, im_addr, im_data, sseg0, sseg1, sseg2, sseg3, int_req);
197
198
199
200 syn: process(sys_clk, sys_res)
201
202 begin
203
204         if sys_res = RESET_VALUE then
205
206                 sync <= (others => RESET_VALUE);
207
208         elsif rising_edge(sys_clk) then
209                         sync(1) <= sys_res;
210                         for i in 2 to SYNC_STAGES loop
211                                 sync(i) <= sync(i - 1);
212                         end loop;
213
214                         sync2(1) <= soft_res;
215                         for i in 2 to SYNC_STAGES loop
216                                 sync2(i) <= sync2(i - 1);
217                         end loop;
218
219         end if;
220
221 end process;
222
223 sys_res_n <= sync(SYNC_STAGES);
224 soft_res_n <= sync2(SYNC_STAGES);
225 nop_pin <= (alu_jump_bit_pin); -- xor brpr_pin);
226 jump_result <= prog_cnt_pin; --jump_result_pin;
227
228 end behav;