OpenCores
URL https://opencores.org/ocsvn/leros/leros/trunk

Subversion Repositories leros

[/] [leros/] [trunk/] [vhdl/] [core/] [leros_fedec.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 martin
--
2
--  Copyright 2011 Martin Schoeberl <masca@imm.dtu.dk>,
3
--                 Technical University of Denmark, DTU Informatics. 
4
--  All rights reserved.
5
--
6
-- Redistribution and use in source and binary forms, with or without
7
-- modification, are permitted provided that the following conditions are met:
8
-- 
9
--    1. Redistributions of source code must retain the above copyright notice,
10
--       this list of conditions and the following disclaimer.
11
-- 
12
--    2. Redistributions in binary form must reproduce the above copyright
13
--       notice, this list of conditions and the following disclaimer in the
14
--       documentation and/or other materials provided with the distribution.
15
-- 
16
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS
17
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
-- OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19
-- NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-- 
27
-- The views and conclusions contained in the software and documentation are
28
-- those of the authors and should not be interpreted as representing official
29
-- policies, either expressed or implied, of the copyright holder.
30
-- 
31
 
32
library ieee;
33
use ieee.std_logic_1164.all;
34
use ieee.numeric_std.all;
35
 
36
use work.leros_types.all;
37
 
38
-- fetch and decode stage
39
 
40
entity leros_fedec is
41
        port  (
42
                clk : in std_logic;
43
                reset : in std_logic;
44
                din : in fedec_in_type;
45
                dout : out fedec_out_type
46
        );
47
end leros_fedec;
48
 
49
architecture rtl of leros_fedec is
50
 
51
        signal imin : im_in_type;
52
        signal imout : im_out_type;
53
 
54
        signal zf, do_branch : std_logic;
55
 
56
        signal pc, pc_next, pc_op, pc_add : unsigned(IM_BITS-1 downto 0);
57
        signal decode : decode_type;
58
 
59
begin
60
 
61
        dout.pc <= std_logic_vector(pc_add);
62
 
63
        imin.rdaddr <= std_logic_vector(pc_next);
64
 
65
        im: entity work.leros_im port map(
66
                clk, reset, imin, imout
67
        );
68
 
69
        dec: entity work.leros_decode port map(
70
                imout.data(15 downto 8), decode
71
        );
72
 
73
-- DM address selection
74
process(decode, din, imout)
75
        variable addr : std_logic_vector(15 downto 0);
76
begin
77
        addr := std_logic_vector(unsigned(din.dm_data) + unsigned(imout.data(7 downto 0)));
78
        -- MUX for indirect load/store (from unregistered decode)
79
        if decode.indls='1' then
80
                dout.dm_addr <= addr(DM_BITS-1 downto 0);
81
        else
82
                -- If DM > 256 zero extend the varidx
83
                dout.dm_addr <= imout.data(DM_BITS-1 downto 0);
84
        end if;
85
 
86
end process;
87
 
88
-- branch 
89
process(decode, din, do_branch, imout, pc, pc_add, pc_op, zf)
90
begin
91
        -- should be checked in ModelSim
92
        if unsigned(din.accu)=0 then
93
                zf <= '1';
94
        else
95
                zf <= '0';
96
        end if;
97
        do_branch <= '0'; -- is setting and reading a signal in on process ok style?
98
 
99
        -- check branch condition
100
        if decode.br_op='1' then
101
                case imout.data(10 downto 8) is
102
                        when "000" =>           -- branch
103
                                do_branch <= '1';
104
                        when "001" =>           -- brz
105
                                if zf='1' then
106
                                        do_branch <= '1';
107
                                end if;
108
                        when "010" =>           -- brnz
109
                                if zf='0' then
110
                                        do_branch <= '1';
111
                                end if;
112
                        when "011" =>           -- brp
113
                                if din.accu(15)='0' then
114
                                        do_branch <= '1';
115
                                end if;
116
                        when "100" =>           -- brn
117
                                if din.accu(15)='1' then
118
                                        do_branch <= '1';
119
                                end if;
120
                        when others =>
121
                                null;
122
                end case;
123
        end if;
124
 
125
        -- shall we do the branch in the ex stage so
126
        -- we will have a real branch delay slot?
127
        -- branch
128
        if do_branch='1' then
129
                pc_op <= unsigned(resize(signed(imout.data(7 downto 0)), IM_BITS));
130
        else
131
                pc_op <= to_unsigned(1, IM_BITS);
132
        end if;
133
        pc_add <= pc + pc_op;
134
        -- jump and link
135
        if decode.jal='1' then
136
                pc_next <= unsigned(din.accu(IM_BITS-1 downto 0));
137
        else
138
                pc_next <= pc_add;
139
        end if;
140
 
141
end process;
142
 
143
-- pc register
144
process(clk, reset)
145
begin
146
        if reset='1' then
147
                pc <= (others => '0');
148
        elsif rising_edge(clk) then
149
                pc <= pc_next;
150
                dout.dec <= decode;
151
--              if decode.add_sub='1' then
152
                -- sign extension depends on loadh?????
153
                if decode.loadh='1' then
154
                        dout.imm(7 downto 0) <= (others => '0');
155
                        dout.imm(15 downto 8) <= imout.data(7 downto 0);
156
                else
157
                        dout.imm <= std_logic_vector(resize(signed(imout.data(7 downto 0)), 16));
158
                end if;
159
--              else
160
--                      immr(7 downto 0) <= imout.data(7 downto 0);
161
--                      immr(15 downto 0) <= (others => '0');
162
--              end if;
163
        end if;
164
end process;
165
 
166
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.