1 |
2 |
poppy |
------------------------------------------------------------------------------------
|
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 |
5 |
poppy |
-- it under the terms of the GNU Lesser General Public License as published by --
|
12 |
|
|
-- the Free Software Foundation; either version 2.1 of the License, or --
|
13 |
2 |
poppy |
-- (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 |
5 |
poppy |
-- GNU Lesser General Public License for more details. --
|
19 |
2 |
poppy |
-- --
|
20 |
5 |
poppy |
-- You should have received a copy of the GNU Lesser General Public License --
|
21 |
2 |
poppy |
-- 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 |
|
|
reset : in std_logic;
|
66 |
|
|
|
67 |
|
|
-- Datas from the pipeline
|
68 |
|
|
MEM_adr : in bus32; -- Address of the current instruction in the pipeline end -> responsible of the exception
|
69 |
|
|
MEM_exc_cause : in bus32; -- Potential cause exception of that instruction
|
70 |
|
|
MEM_it_ok : in std_logic; -- Allow hardware interruptions
|
71 |
|
|
|
72 |
|
|
-- Hardware interruption
|
73 |
|
|
it_mat : in std_logic; -- Hardware interruption detected
|
74 |
|
|
|
75 |
|
|
-- Interruption controls
|
76 |
|
|
interrupt : out std_logic; -- Interruption to take into account
|
77 |
|
|
vecteur_it : out bus32; -- Interruption vector
|
78 |
|
|
|
79 |
|
|
-- Writing request in register bank
|
80 |
|
|
write_data : in bus32; -- Data to write
|
81 |
|
|
write_adr : in bus5; -- Address of the register to write
|
82 |
|
|
write_SCP : in std_logic; -- Writing request
|
83 |
|
|
|
84 |
|
|
-- Reading request in register bank
|
85 |
|
|
read_adr1 : in bus5; -- Address of the first register
|
86 |
|
|
read_adr2 : in bus5; -- Address of the second register
|
87 |
|
|
read_data1 : out bus32; -- Value of register 1
|
88 |
|
|
read_data2 : out bus32 -- Value of register 2
|
89 |
|
|
);
|
90 |
|
|
end syscop;
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
architecture rtl of syscop is
|
94 |
|
|
|
95 |
|
|
subtype adr_scp_reg is integer range 12 to 15;
|
96 |
|
|
|
97 |
|
|
type scp_reg_type is array (integer range adr_scp_reg'low to adr_scp_reg'high) of bus32;
|
98 |
|
|
|
99 |
|
|
-- Constants to define the coprocessor registers
|
100 |
|
|
constant COMMAND : integer := 0; -- False register to command the coprocessor system
|
101 |
|
|
constant STATUS : adr_scp_reg := 12; -- Registre 12 of the coprocessor system
|
102 |
|
|
constant CAUSE : adr_scp_reg := 13; -- Registre 13 of the coprocessor system
|
103 |
|
|
constant ADRESSE : adr_scp_reg := 14; -- Registre 14 of the coprocessor system
|
104 |
|
|
constant VECTIT : adr_scp_reg := 15; -- Registre 15 of the coprocessor system
|
105 |
|
|
|
106 |
|
|
signal scp_reg : scp_reg_type; -- Internal register bank
|
107 |
|
|
signal pre_reg : scp_reg_type; -- Register bank preparation
|
108 |
|
|
|
109 |
|
|
signal adr_src1 : integer range 0 to 31;
|
110 |
|
|
signal adr_src2 : integer range 0 to 31;
|
111 |
|
|
signal adr_dest : integer range 0 to 31;
|
112 |
|
|
|
113 |
|
|
signal exception : std_logic; -- Set to '1' when exception detected
|
114 |
|
|
signal interruption : std_logic; -- Set to '1' when interruption detected
|
115 |
|
|
signal cmd_itret : std_logic; -- Set to '1' when interruption return command is detected
|
116 |
|
|
|
117 |
|
|
signal save_msk : std_logic; -- Save the mask state when an interruption occurs
|
118 |
|
|
|
119 |
|
|
begin
|
120 |
|
|
|
121 |
|
|
-- Detection of the interruptions
|
122 |
|
|
exception <= '1' when MEM_exc_cause/=IT_NOEXC else '0';
|
123 |
|
|
interruption <= '1' when it_mat='1' and scp_reg(STATUS)(0)='1' and MEM_it_ok='1' else '0';
|
124 |
|
|
|
125 |
|
|
-- Update asynchronous outputs
|
126 |
|
|
interrupt <= exception or interruption; -- Detection of interruptions
|
127 |
|
|
vecteur_it <= scp_reg(ADRESSE) when cmd_itret = '1' else -- Send the return adress when a return instruction appears
|
128 |
|
|
scp_reg(VECTIT); -- Send the interruption vector in other cases
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
-- Decode the address of the registers
|
132 |
|
|
adr_src1 <= to_integer(unsigned(read_adr1));
|
133 |
|
|
adr_src2 <= to_integer(unsigned(read_adr2));
|
134 |
|
|
adr_dest <= to_integer(unsigned(write_adr));
|
135 |
|
|
|
136 |
|
|
-- Read the two registers
|
137 |
|
|
read_data1 <= (others => '0') when (adr_src1<scp_reg'low or adr_src1>scp_reg'high) else
|
138 |
|
|
scp_reg(adr_src1);
|
139 |
|
|
read_data2 <= (others => '0') when adr_src2<scp_reg'low or adr_src2>scp_reg'high else
|
140 |
|
|
scp_reg(adr_src2);
|
141 |
|
|
|
142 |
|
|
-- Define the pre_reg signal, next value for the registers
|
143 |
|
|
process (scp_reg, adr_dest, write_SCP, write_data, interruption,
|
144 |
|
|
exception, MEM_exc_cause, MEM_adr, reset)
|
145 |
|
|
begin
|
146 |
|
|
pre_reg <= scp_reg;
|
147 |
|
|
cmd_itret <= '0'; -- No IT return in most cases
|
148 |
|
|
|
149 |
|
|
-- Potential writing in a register
|
150 |
|
|
if (write_SCP='1' and adr_dest>=pre_reg'low and adr_dest<=pre_reg'high) then
|
151 |
|
|
pre_reg(adr_dest) <= write_data;
|
152 |
|
|
end if;
|
153 |
|
|
|
154 |
|
|
-- Command from the core
|
155 |
|
|
if write_SCP='1' and adr_dest=COMMAND then
|
156 |
|
|
case write_data is -- Different operations
|
157 |
|
|
when SYS_UNMASK => pre_reg(STATUS)(0) <= '1'; -- Unamsk command
|
158 |
|
|
when SYS_MASK => pre_reg(STATUS)(0) <= '0'; -- Mask command
|
159 |
|
|
when SYS_ITRET => -- Interruption return command
|
160 |
|
|
pre_reg(STATUS)(0) <= save_msk; -- Restore the mask before the interruption
|
161 |
|
|
cmd_itret <= '1'; -- False interruption request (to clear the pipeline)
|
162 |
|
|
when others => null;
|
163 |
|
|
end case;
|
164 |
|
|
end if;
|
165 |
|
|
|
166 |
|
|
-- Modifications from the interruptions
|
167 |
|
|
if interruption='1' then
|
168 |
|
|
pre_reg(STATUS)(0) <= '0'; -- Mask the interruptions
|
169 |
|
|
pre_reg(CAUSE) <= IT_ITMAT; -- Save the interruption cause
|
170 |
|
|
pre_reg(ADRESSE) <= MEM_adr; -- Save the return address
|
171 |
|
|
end if;
|
172 |
|
|
|
173 |
|
|
-- Modifications from the exceptions
|
174 |
|
|
if exception='1' then
|
175 |
|
|
pre_reg(STATUS)(0) <= '0'; -- Mask the interruptions
|
176 |
|
|
pre_reg(CAUSE) <= MEM_exc_cause; -- Save the exception cause
|
177 |
|
|
pre_reg(ADRESSE) <= MEM_adr; -- Save the return address
|
178 |
|
|
end if;
|
179 |
|
|
|
180 |
|
|
-- The reset has the priority on the other cuases
|
181 |
|
|
if reset='1' then
|
182 |
|
|
pre_reg <= (others => (others => '0'));
|
183 |
|
|
-- NB : The processor is masked after a reset
|
184 |
|
|
-- The exception handler is set at address 0
|
185 |
|
|
end if;
|
186 |
|
|
end process;
|
187 |
|
|
|
188 |
|
|
-- Memorisation of the modifications in the register bank
|
189 |
|
|
process(clock)
|
190 |
|
|
begin
|
191 |
|
|
if clock='1' and clock'event then
|
192 |
|
|
|
193 |
|
|
-- Save the mask when an interruption appears
|
194 |
|
|
if (exception='1') or (interruption='1') then
|
195 |
|
|
save_msk <= scp_reg(STATUS)(0);
|
196 |
|
|
end if;
|
197 |
|
|
|
198 |
|
|
scp_reg <= pre_reg;
|
199 |
|
|
|
200 |
|
|
end if;
|
201 |
|
|
end process;
|
202 |
|
|
|
203 |
|
|
end rtl;
|