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.core_pkg.all;
27 use work.common_pkg.all;
30 architecture behav of fetch_stage is
32 signal instr_w_addr : instruction_addr_t;
33 signal instr_r_addr : instruction_addr_t;
34 signal instr_r_addr_nxt : instruction_addr_t;
35 signal instr_we : std_logic;
36 signal instr_wr_data : instruction_word_t;
37 signal instr_rd_data_rom, instr_rd_data : instruction_word_t;
38 signal rom_ram, rom_ram_nxt : std_logic;
42 instruction_ram : r_w_ram --rom
44 PHYS_INSTR_ADDR_WIDTH,
50 im_addr(PHYS_INSTR_ADDR_WIDTH-1 downto 0),
51 instr_r_addr_nxt(PHYS_INSTR_ADDR_WIDTH-1 downto 0),
65 instr_r_addr_nxt(ROM_INSTR_ADDR_WIDTH-1 downto 0),
70 syn: process(clk, reset)
74 if (reset = RESET_VALUE) then
75 instr_r_addr <= (others => '0');
78 elsif rising_edge(clk) then
79 instr_r_addr <= instr_r_addr_nxt;
80 rom_ram <= rom_ram_nxt;
81 led2 <= rom_ram; --rom_ram_nxt;
87 asyn: process(reset, s_reset, instr_r_addr, jump_result, prediction_result, branch_prediction_bit, alu_jump_bit, instr_rd_data, rom_ram, instr_rd_data_rom, int_req)
88 variable instr_pc : instruction_addr_t;
90 rom_ram_nxt <= rom_ram;
94 instruction <= instr_rd_data_rom;
96 instruction <= instr_rd_data;
98 instruction <= x"F0000000";
100 instr_pc := std_logic_vector(unsigned(instr_r_addr) + 1);
101 instr_r_addr_nxt <= instr_pc;
103 if (instr_pc = x"0000007f" and rom_ram = ROM_USE) then
104 rom_ram_nxt <= RAM_USE;
105 instr_r_addr_nxt <= (others => '0');
108 if (reset = RESET_VALUE) then
109 instr_r_addr_nxt <= (others => '0');
112 if (alu_jump_bit = LOGIC_ACT and int_req = IDLE) then
113 instr_r_addr_nxt <= jump_result;
114 instruction(31 downto 28) <= "1111";
115 elsif (branch_prediction_bit = LOGIC_ACT) then
116 instr_r_addr_nxt <= prediction_result;
121 instruction(31 downto 0) <= (others => '0');
122 instruction(31 downto 28) <= "1110";
123 instruction(27 downto 23) <= "10110";
124 instruction(PHYS_INSTR_ADDR_WIDTH + 7 - 1 downto 7) <= UART_INT_VECTOR;
125 instruction(6 downto 4) <= "001";
126 instruction(3 downto 2) <= "01";
127 instruction(1 downto 0) <= "10";
129 -- instr_r_addr_nxt <= instr_r_addr;
133 if (s_reset = RESET_VALUE) then
134 rom_ram_nxt <= RAM_USE;
135 instr_r_addr_nxt <= (others => '0');
140 out_logic : process (instr_r_addr, alu_jump_bit, int_req, jump_result)
143 prog_cnt(PHYS_INSTR_ADDR_WIDTH-1 downto 0) <= std_logic_vector(unsigned(instr_r_addr(PHYS_INSTR_ADDR_WIDTH-1 downto 0)));
144 prog_cnt(INSTR_ADDR_WIDTH-1 downto PHYS_INSTR_ADDR_WIDTH) <= (others => '0');
146 if (int_req /= IDLE and alu_jump_bit = LOGIC_ACT ) then
147 prog_cnt(PHYS_INSTR_ADDR_WIDTH-1 downto 0) <= jump_result(PHYS_INSTR_ADDR_WIDTH-1 downto 0);