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

Subversion Repositories minimips_superscalar

[/] [minimips_superscalar/] [tags/] [P1/] [sources/] [syscop.vhd] - Blame information for rev 33

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 mcafruni
------------------------------------------------------------------------------------
2
--                                                                                --
3
--    Copyright (c) 2004, Hangouet Samuel                                         --
4
--                  , Jan Sebastien                                               --
5
--                  , Mouton Louis-Marie                                          --
6
--                  , Schneider Olivier     all rights reserved                   --
7
--                                                                                --
8
--    This file is part of miniMIPS.                                              --
9
--                                                                                --
10
--    miniMIPS is free software; you can redistribute it and/or modify            --
11
--    it under the terms of the GNU General Public License as published by        --
12
--    the Free Software Foundation; either version 2 of the License, or           --
13
--    (at your option) any later version.                                         --
14
--                                                                                --
15
--    miniMIPS is distributed in the hope that it will be useful,                 --
16
--    but WITHOUT ANY WARRANTY; without even the implied warranty of              --
17
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               --
18
--    GNU General Public License for more details.                                --
19
--                                                                                --
20
--    You should have received a copy of the GNU General Public License           --
21
--    along with miniMIPS; if not, write to the Free Software                     --
22
--    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   --
23
--                                                                                --
24
------------------------------------------------------------------------------------
25
 
26
 
27
-- If you encountered any problem, please contact :
28
--
29
--   lmouton@enserg.fr
30
--   oschneid@enserg.fr
31
--   shangoue@enserg.fr
32
--
33
 
34
 
35
 
36
--------------------------------------------------------------------------
37
--                                                                      --
38
--                                                                      --
39
--        miniMIPS Processor : Coprocessor system (cop0)                --
40
--                                                                      --
41
--                                                                      --
42
--                                                                      --
43
-- Authors : Hangouet  Samuel                                           --
44
--           Jan       Sébastien                                        --
45
--           Mouton    Louis-Marie                                      --
46
--           Schneider Olivier                                          --
47
--                                                                      --
48
--                                                          june 2003   --
49
--------------------------------------------------------------------------
50
 
51
 
52
library ieee;
53
use ieee.std_logic_1164.all;
54
use IEEE.numeric_std.all;
55
 
56
library work;
57
use work.pack_mips.all;
58
 
59
-- By convention in the commentary, the term interruption means hardware interruptions and software exceptions
60
 
61
entity syscop is
62
port
63
(
64
    clock         : in std_logic;
65
    clock2        : in std_logic;
66
    reset         : in std_logic;
67
 
68
    -- Datas from the pipeline
69
    MEM_adr       : in bus32;       -- Address (PC) of the current instruction in the pipeline end -> responsible of the exception
70
    MEM_exc_cause : in bus32;       -- Potential cause exception of that instruction
71
    MEM_it_ok     : in std_logic;   -- Allow hardware interruptions
72
 
73
    -- Hardware interruption
74
    it_mat        : in std_logic;   -- Hardware interruption detected
75
 
76
    -- Interruption controls
77
    interrupt     : out std_logic;  -- Interruption to take into account
78
    vecteur_it    : out bus32;      -- Interruption vector
79
 
80
    -- Writing request in register bank
81
    write_data    : in bus32;       -- Data to write
82
    write_adr     : in bus5;        -- Address of the register to write
83
    write_SCP     : in std_logic;   -- Writing request
84
 
85
    -- Reading request in register bank
86
    read_adr1     : in bus5;        -- Address of the first register
87
    read_adr2     : in bus5;        -- Address of the second register
88
    read_data1    : out bus32;      -- Value of register 1
89
    read_data2    : out bus32;       -- Value of register 2
90
 
91
--mod
92
    -- Datas from the pipeline
93
    MEM_adr2       : in bus32;       -- Address of the current instruction in the pipeline end -> responsible of the exception
94
    MEM_exc_cause2 : in bus32;       -- Potential cause exception of that instruction
95
    MEM_it_ok2     : in std_logic;   -- Allow hardware interruptions
96
 
97
    -- Hardware interruption
98
    it_mat2        : in std_logic;   -- Hardware interruption detected
99
 
100
    -- Interruption controls
101
    interrupt2     : out std_logic;  -- Interruption to take into account
102
    vecteur_it2    : out bus32;      -- Interruption vector
103
 
104
    -- Writing request in register bank
105
    write_data2    : in bus32;       -- Data to write 
106
    write_adr2     : in bus5;        -- Address of the register to write
107
    write_SCP2     : in std_logic;   -- Writing request
108
 
109
    -- Reading request in register bank
110
    read_adr3     : in bus5;        -- Address of the 3th register
111
    read_adr4     : in bus5;        -- Address of the 4th register
112
    read_data3    : out bus32;      -- Value of register 3
113
    read_data4    : out bus32       -- Value of register 4
114
);
115
end syscop;
116
 
117
architecture rtl of syscop is
118
 
119
    subtype adr_scp_reg is integer range 12 to 15;
120
 
121
    type scp_reg_type is array (integer range adr_scp_reg'low to adr_scp_reg'high) of bus32;
122
 
123
    -- Constants to define the coprocessor registers
124
    constant COMMAND   : integer      := 0;   -- False register to command the coprocessor system
125
    constant STATUS    : adr_scp_reg  := 12;  -- Registre 12 of the coprocessor system
126
    constant CAUSE     : adr_scp_reg  := 13;  -- Registre 13 of the coprocessor system
127
    constant ADRESSE   : adr_scp_reg  := 14;  -- Registre 14 of the coprocessor system
128
    constant VECTIT    : adr_scp_reg  := 15;  -- Registre 15 of the coprocessor system
129
 
130
    signal scp_reg : scp_reg_type;          -- Internal register bank
131
    signal pre_reg : scp_reg_type;          -- Register bank preparation
132
        signal scp_reg2 : scp_reg_type;          -- Internal register bank
133
    signal pre_reg2 : scp_reg_type;          -- Register bank preparation
134
 
135
    signal adr_src1 : integer range 0 to 31;
136
    signal adr_src2 : integer range 0 to 31;
137
    signal adr_dest : integer range 0 to 31;
138
--mod
139
    signal adr_src3 : integer range 0 to 31;
140
    signal adr_src4 : integer range 0 to 31;
141
    signal adr_dest2 : integer range 0 to 31;
142
--fim mod        
143
    signal exception, exception2 : std_logic;           -- Set to '1' when exception detected *** quando MEM_exc_cause for diferente de IT_NOEXC
144
    signal interruption, interruption2 : std_logic;        -- Set to '1' when interruption detected
145
    signal cmd_itret, cmd_itret2    : std_logic;        -- Set to '1' when interruption return command is detected
146
 
147
    signal save_msk, save_msk2  : std_logic;           -- Save the mask state when an interruption occurs
148
 
149
begin
150
 
151
    -- Detection of the interruptions
152
    exception <= '1' when MEM_exc_cause/=IT_NOEXC else '0'; -- *** chegou uma instrucao ilegal ou break ou syscall ***
153
    interruption <= '1' when it_mat='1' and scp_reg(STATUS)(0)='1' and MEM_it_ok='1' else '0';
154
    exception2 <= '1' when MEM_exc_cause2/=IT_NOEXC else '0'; -- *** chegou uma instrucao ilegal ou break ou syscall ***
155
    interruption2 <= '1' when it_mat2='1' and scp_reg2(STATUS)(0)='1' and MEM_it_ok2='1' else '0';
156
    -- Update asynchronous outputs
157
    interrupt <= exception or interruption; -- Detection of interruptions
158
    vecteur_it <= scp_reg(ADRESSE) when cmd_itret = '1' else -- Send the return adress when a return instruction appears -- *** retorno de uma instrucao ilegal ou break ou syscall ***
159
                  scp_reg(VECTIT);                           -- Send the interruption vector in other cases
160
    interrupt2 <= exception2 or interruption2; -- Detection of interruptions
161
    vecteur_it2 <= scp_reg2(ADRESSE) when cmd_itret2 = '1' else -- Send the return adress when a return instruction appears -- *** retorno de uma instrucao ilegal ou break ou syscall ***
162
                  scp_reg2(VECTIT);                           -- Send the interruption vector in other cases
163
 
164
    -- Decode the address of the registers
165
    adr_src1 <= to_integer(unsigned(read_adr1));
166
    adr_src2 <= to_integer(unsigned(read_adr2));
167
    adr_dest <= to_integer(unsigned(write_adr));
168
--mod
169
    adr_src3 <= to_integer(unsigned(read_adr3));
170
    adr_src4 <= to_integer(unsigned(read_adr4));
171
    adr_dest2 <= to_integer(unsigned(write_adr2));
172
--fim mod        
173
    -- Read the two registers
174
    read_data1 <= (others => '0') when (adr_src1<scp_reg'low or adr_src1>scp_reg'high) else
175
                  scp_reg(adr_src1);
176
    read_data2 <= (others => '0') when (adr_src2<scp_reg'low or adr_src2>scp_reg'high) else
177
                  scp_reg(adr_src2);
178
--mod    
179
    -- Read the two registers
180
    read_data3 <= (others => '0') when (adr_src3<scp_reg'low or adr_src3>scp_reg'high) else
181
                  scp_reg(adr_src3);
182
    read_data4 <= (others => '0') when (adr_src4<scp_reg'low or adr_src4>scp_reg'high) else -- erro de copia e cola
183
                  scp_reg(adr_src4);                                                                                                                                              -- arrumado em 04\12\17 
184
--fim mod       
185
 
186
    -- Define the pre_reg signal, next value for the registers
187
    process (scp_reg, scp_reg2, adr_dest, write_SCP, write_data, interruption, exception, interruption2, exception2, MEM_exc_cause, MEM_adr, reset, adr_dest2, write_SCP2, write_data2, MEM_exc_cause2, MEM_adr2)
188
    begin    -- *** exception eh um sinal interno e tambem pode ser tratado em um processo *** --
189
        pre_reg <= scp_reg;
190
        cmd_itret <= '0'; -- No IT return in most cases
191
        pre_reg2 <= scp_reg2;
192
        cmd_itret2 <= '0'; -- No IT return in most cases
193
        -- Potential writing in a register
194
        if (write_SCP='1' and adr_dest>=pre_reg'low and adr_dest<=pre_reg'high) then
195
            pre_reg(adr_dest) <= write_data;
196
        end if;
197
--mod
198
        -- Potential writing in a register from 2nd pipe
199
        if (write_SCP2='1' and adr_dest2>=pre_reg2'low and adr_dest2<=pre_reg2'high) then
200
            pre_reg2(adr_dest2) <= write_data2;
201
        end if;
202
--fim mod
203
 
204
        -- Command from the core P1
205
        if write_SCP='1' and adr_dest=COMMAND then
206
            case write_data is -- Different operations
207
                when SYS_UNMASK => pre_reg(STATUS)(0) <= '1'; -- Unamsk command
208
                when SYS_MASK   => pre_reg(STATUS)(0) <= '0'; -- Mask command
209
                when SYS_ITRET  => -- Interruption return command
210
                                   pre_reg(STATUS)(0) <= save_msk; -- Restore the mask before the interruption
211
                                   cmd_itret          <= '1';      -- False interruption request (to clear the pipeline)
212
                when others     => null;
213
            end case;
214
        end if;
215
 
216
        -- Modifications from the interruptions
217
        if interruption='1' then
218
            pre_reg(STATUS)(0) <= '0';       -- Mask the interruptions
219
            pre_reg(CAUSE) <= IT_ITMAT;      -- Save the interruption cause
220
            pre_reg(ADRESSE) <= MEM_adr;     -- Save the return address
221
        end if;
222
 
223
        -- Modifications from the exceptions
224
        if exception='1' then  -- *** chegou uma instrucao ilegal ou break ou syscall ***
225
            pre_reg(STATUS)(0) <= '0';       -- Mask the interruptions
226
            pre_reg(CAUSE) <= MEM_exc_cause; -- Save the exception cause
227
            pre_reg(ADRESSE) <= MEM_adr;     -- Save the return address
228
        end if;
229
 
230
        -- Command from the core P2
231
        if write_SCP2='1' and adr_dest2=COMMAND then
232
            case write_data2 is -- Different operations
233
                when SYS_UNMASK => pre_reg2(STATUS)(0) <= '1'; -- Unamsk command
234
                when SYS_MASK   => pre_reg2(STATUS)(0) <= '0'; -- Mask command
235
                when SYS_ITRET  => -- Interruption return command
236
                                   pre_reg2(STATUS)(0) <= save_msk2; -- Restore the mask before the interruption
237
                                   cmd_itret2          <= '1';      -- False interruption request (to clear the pipeline)
238
                when others     => null;
239
            end case;
240
        end if;
241
 
242
        -- Modifications from the interruptions
243
        if interruption2='1' then
244
            pre_reg2(STATUS)(0) <= '0';       -- Mask the interruptions
245
            pre_reg2(CAUSE) <= IT_ITMAT;      -- Save the interruption cause
246
            pre_reg2(ADRESSE) <= MEM_adr2;     -- Save the return address
247
        end if;
248
 
249
        -- Modifications from the exceptions
250
        if exception2='1' then  -- *** chegou uma instrucao ilegal ou break ou syscall ***
251
            pre_reg2(STATUS)(0) <= '0';       -- Mask the interruptions
252
            pre_reg2(CAUSE) <= MEM_exc_cause2; -- Save the exception cause
253
            pre_reg2(ADRESSE) <= MEM_adr2;     -- Save the return address
254
        end if;
255
 
256
        -- The reset has the priority on the other cuases
257
        if reset='1' then
258
            pre_reg  <= (others => (others => '0'));
259
            pre_reg2 <= (others => (others => '0'));
260
            -- NB : The processor is masked after a reset
261
            --      The exception handler is set at address 0
262
        end if;
263
    end process;
264
 
265
    -- Memorisation of the modifications in the register bank
266
    process(clock)
267
    begin
268
        if clock='1' and clock'event then
269
            -- Save the mask when an interruption appears
270
            if (exception='1') or (interruption='1') then
271
                save_msk <= scp_reg(STATUS)(0);
272
            end if;
273
            scp_reg <= pre_reg;
274
        end if;
275
    end process;
276
 
277
    process(clock2)
278
    begin
279
        if clock2='1' and clock2'event then
280
            -- Save the mask when an interruption appears
281
            if (exception2='1') or (interruption2='1') then
282
                save_msk2 <= scp_reg2(STATUS)(0);
283
            end if;
284
            scp_reg2 <= pre_reg2;
285
        end if;
286
    end process;
287
 
288
end rtl;

powered by: WebSVN 2.1.0

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