1 |
2 |
mcafruni |
--------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- --
|
4 |
|
|
-- miniMIPS Superscalar Processor : Memory access stage --
|
5 |
|
|
-- based on miniMIPS Processor --
|
6 |
|
|
-- --
|
7 |
|
|
-- --
|
8 |
|
|
-- Author : Miguel Cafruni --
|
9 |
|
|
-- miguel_cafruni@hotmail.com --
|
10 |
|
|
-- December 2018 --
|
11 |
|
|
--------------------------------------------------------------------------
|
12 |
|
|
|
13 |
|
|
library IEEE;
|
14 |
|
|
use IEEE.std_logic_1164.all;
|
15 |
|
|
|
16 |
|
|
library work;
|
17 |
|
|
use work.pack_mips.all;
|
18 |
|
|
|
19 |
|
|
entity pps_mem is
|
20 |
|
|
port
|
21 |
|
|
(
|
22 |
|
|
clock : in std_logic;
|
23 |
|
|
clock2 : in std_logic;
|
24 |
|
|
reset : in std_logic;
|
25 |
|
|
stop_all : in std_logic; -- Unconditionnal locking of the outputs
|
26 |
|
|
stop_all2 : in std_logic;
|
27 |
|
|
clear : in std_logic; -- Clear the pipeline stage
|
28 |
|
|
|
29 |
|
|
-- Interface with the control bus
|
30 |
|
|
MTC_data : out bus32; -- Data to write in memory
|
31 |
|
|
MTC_adr : out bus32; -- Address for memory
|
32 |
|
|
MTC_r_w : out std_logic; -- Read/Write in memory
|
33 |
|
|
MTC_req : out std_logic; -- Request access to memory
|
34 |
|
|
CTM_data : in bus32; -- Data from memory
|
35 |
|
|
|
36 |
|
|
-- Datas from Execution stage
|
37 |
|
|
EX_adr : in bus32; -- Instruction address
|
38 |
|
|
EX_data_ual : in bus32; -- Result of alu operation
|
39 |
|
|
EX_adresse : in bus32; -- Result of the calculation of the address
|
40 |
|
|
EX_adresse_p1p2 : in bus32; -- resultado do calculo do endereco do desvio + 4 para pipe 2
|
41 |
|
|
-- *** nao tinha essa entrada no original, so tinha a saida no EX ***
|
42 |
|
|
EX_bra_confirm : in bus1; -- Confirmacao do branch no pipe 1 (26-07-18)
|
43 |
|
|
-- ******************
|
44 |
|
|
EX_adr_reg_dest : in adr_reg_type; -- Destination register address for the result
|
45 |
|
|
EX_ecr_reg : in std_logic; -- Effective writing of the result
|
46 |
|
|
EX_op_mem : in std_logic; -- Memory operation needed
|
47 |
|
|
EX_r_w : in std_logic; -- Type of memory operation (read or write)
|
48 |
|
|
EX_exc_cause : in bus32; -- Potential exception cause
|
49 |
|
|
EX_level : in level_type; -- Availability stage for the result for bypassing (Estágio de disponibilidade para o resultado de bypassing)
|
50 |
|
|
EX_it_ok : in std_logic; -- Allow hardware interruptions
|
51 |
|
|
|
52 |
|
|
-- Synchronous outputs for bypass unit
|
53 |
|
|
MEM_adr : out bus32; -- Instruction address
|
54 |
|
|
MEM_adr_reg_dest : out adr_reg_type; -- Destination register address
|
55 |
|
|
MEM_ecr_reg : out std_logic; -- Writing of the destination register
|
56 |
|
|
MEM_data_ecr : out bus32; -- Data to write (from alu or memory)
|
57 |
|
|
MEM_exc_cause : out bus32; -- Potential exception cause
|
58 |
|
|
MEM_level : out level_type; -- Availability stage for the result for bypassing (Estágio de disponibilidade para o resultado de bypassing)
|
59 |
|
|
MEM_it_ok : out std_logic; -- Allow hardware interruptions
|
60 |
|
|
|
61 |
|
|
--modificação
|
62 |
|
|
-- Interface with the control bus
|
63 |
|
|
MTC_data2 : out bus32; -- Data to write in memory
|
64 |
|
|
MTC_adr2 : out bus32; -- Address for memory
|
65 |
|
|
MTC_r_w2 : out std_logic; -- Read/Write in memory
|
66 |
|
|
MTC_req2 : out std_logic; -- Request access to memory
|
67 |
|
|
CTM_data2 : in bus32; -- Data from memory
|
68 |
|
|
|
69 |
|
|
-- Datas from Execution 2 stage
|
70 |
|
|
EX_adr2 : in bus32; -- Instruction address
|
71 |
|
|
EX_data_ual2 : in bus32; -- Result of alu operation
|
72 |
|
|
EX_adresse2 : in bus32; -- Result of the calculation of the address
|
73 |
|
|
EX_adresse_p2p1 : in bus32; -- resultado do calculo do endereco do desvio + 4 para pipe 1
|
74 |
|
|
-- *** nao tinha essa entrada no original, so tinha a saida no EX2 ***
|
75 |
|
|
EX_bra_confirm2 : in bus1; -- Confirmacao do branch no pipe 2 (26-07-18)
|
76 |
|
|
-- ******************
|
77 |
|
|
EX_adr_reg_dest2 : in adr_reg_type; -- Destination register address for the result
|
78 |
|
|
EX_ecr_reg2 : in std_logic; -- Effective writing of the result
|
79 |
|
|
EX_op_mem2 : in std_logic; -- Memory operation needed
|
80 |
|
|
EX_r_w2 : in std_logic; -- Type of memory operation (read or write)
|
81 |
|
|
EX_exc_cause2 : in bus32; -- Potential exception cause
|
82 |
|
|
EX_level2 : in level_type; -- Availability stage for the result for bypassing (Estágio de disponibilidade para o resultado de bypassing)
|
83 |
|
|
EX_it_ok2 : in std_logic; -- Allow hardware interruptions
|
84 |
|
|
|
85 |
|
|
-- Synchronous outputs for bypass unit
|
86 |
|
|
MEM_adr2 : out bus32; -- Instruction address
|
87 |
|
|
MEM_adr_reg_dest2 : out adr_reg_type; -- Destination register address
|
88 |
|
|
MEM_ecr_reg2 : out std_logic; -- Writing of the destination register
|
89 |
|
|
MEM_data_ecr2 : out bus32; -- Data to write (from alu or memory)
|
90 |
|
|
MEM_exc_cause2 : out bus32; -- Potential exception cause
|
91 |
|
|
MEM_level2 : out level_type; -- Availability stage for the result for bypassing(Estágio de disponibilidade para o resultado de bypassing)
|
92 |
|
|
MEM_it_ok2 : out std_logic -- Allow hardware interruptions
|
93 |
|
|
);
|
94 |
|
|
end pps_mem;
|
95 |
|
|
|
96 |
|
|
architecture rtl of pps_mem is
|
97 |
|
|
|
98 |
|
|
signal tmp_data_ecr : bus32; -- Selection of the data source (memory or alu)
|
99 |
|
|
signal tmp_data_ecr2 : bus32; -- Selection of the data source (memory or alu)
|
100 |
|
|
signal sel_MTC : bus2;
|
101 |
|
|
|
102 |
|
|
begin
|
103 |
|
|
sel_MTC <= EX_bra_confirm & EX_bra_confirm2;
|
104 |
|
|
|
105 |
|
|
with sel_MTC select
|
106 |
|
|
MTC_adr <= EX_adresse_p2p1 when "01",
|
107 |
|
|
EX_adresse when others;
|
108 |
|
|
|
109 |
|
|
with sel_MTC select
|
110 |
|
|
MTC_adr2 <= EX_adresse_p1p2 when "10",
|
111 |
|
|
EX_adresse2 when others;
|
112 |
|
|
|
113 |
|
|
-- Bus controler connexions
|
114 |
|
|
MTC_r_w <= EX_r_w; -- Connexion of R/W
|
115 |
|
|
MTC_data <= EX_data_ual; -- Connexion of the data bus
|
116 |
|
|
MTC_req <= EX_op_mem and not clear; -- Connexion of the request (if there is no clearing of the pipeline)
|
117 |
|
|
-- Bus controler connexions 2nd pipe
|
118 |
|
|
MTC_r_w2 <= EX_r_w2; -- Connexion of R/W
|
119 |
|
|
MTC_data2 <= EX_data_ual2; -- Connexion of the data bus
|
120 |
|
|
MTC_req2 <= EX_op_mem2 and not clear; -- Connexion of the request (if there is no clearing of the pipeline)
|
121 |
|
|
-- Preselection of the data source for the outputs
|
122 |
|
|
tmp_data_ecr <= CTM_data when EX_op_mem = '1' else EX_data_ual;
|
123 |
|
|
tmp_data_ecr2 <= CTM_data2 when EX_op_mem2 = '1' else EX_data_ual2; --(modificação) para EX2
|
124 |
|
|
-- Set the synchronous outputs
|
125 |
|
|
process (clock)
|
126 |
|
|
begin
|
127 |
|
|
if rising_edge(clock) then
|
128 |
|
|
if reset = '1' then
|
129 |
|
|
MEM_adr <= (others => '0');
|
130 |
|
|
MEM_adr_reg_dest <= (others => '0');
|
131 |
|
|
MEM_ecr_reg <= '0';
|
132 |
|
|
MEM_data_ecr <= (others => '0');
|
133 |
|
|
MEM_exc_cause <= IT_NOEXC;
|
134 |
|
|
MEM_level <= LVL_DI;
|
135 |
|
|
MEM_it_ok <= '0';
|
136 |
|
|
elsif stop_all = '0' then
|
137 |
|
|
if clear = '1' then -- Clear the stage
|
138 |
|
|
MEM_adr <= EX_adr;
|
139 |
|
|
MEM_adr_reg_dest <= (others => '0');
|
140 |
|
|
MEM_ecr_reg <= '0';
|
141 |
|
|
MEM_data_ecr <= (others => '0');
|
142 |
|
|
MEM_exc_cause <= IT_NOEXC;
|
143 |
|
|
MEM_level <= LVL_DI;
|
144 |
|
|
MEM_it_ok <= '0';
|
145 |
|
|
else -- Normal evolution
|
146 |
|
|
MEM_adr <= EX_adr;
|
147 |
|
|
MEM_adr_reg_dest <= EX_adr_reg_dest;
|
148 |
|
|
MEM_ecr_reg <= EX_ecr_reg;
|
149 |
|
|
MEM_data_ecr <= tmp_data_ecr;
|
150 |
|
|
MEM_exc_cause <= EX_exc_cause;
|
151 |
|
|
MEM_level <= EX_level;
|
152 |
|
|
MEM_it_ok <= EX_it_ok;
|
153 |
|
|
end if;
|
154 |
|
|
end if;
|
155 |
|
|
end if;
|
156 |
|
|
end process;
|
157 |
|
|
|
158 |
|
|
process (clock2)
|
159 |
|
|
begin
|
160 |
|
|
if falling_edge(clock2) then
|
161 |
|
|
if reset = '1' then
|
162 |
|
|
MEM_adr2 <= (others => '0');
|
163 |
|
|
MEM_adr_reg_dest2 <= (others => '0');
|
164 |
|
|
MEM_ecr_reg2 <= '0';
|
165 |
|
|
MEM_data_ecr2 <= (others => '0');
|
166 |
|
|
MEM_exc_cause2 <= IT_NOEXC;
|
167 |
|
|
MEM_level2 <= LVL_DI;
|
168 |
|
|
MEM_it_ok2 <= '0';
|
169 |
|
|
elsif stop_all2 = '0' then
|
170 |
|
|
if clear = '1' then -- Clear the stage
|
171 |
|
|
MEM_adr2 <= EX_adr2;
|
172 |
|
|
MEM_adr_reg_dest2 <= (others => '0');
|
173 |
|
|
MEM_ecr_reg2 <= '0';
|
174 |
|
|
MEM_data_ecr2 <= (others => '0');
|
175 |
|
|
MEM_exc_cause2 <= IT_NOEXC;
|
176 |
|
|
MEM_level2 <= LVL_DI;
|
177 |
|
|
MEM_it_ok2 <= '0';
|
178 |
|
|
else -- Normal evolution
|
179 |
|
|
MEM_adr2 <= EX_adr2;
|
180 |
|
|
MEM_adr_reg_dest2 <= EX_adr_reg_dest2;
|
181 |
|
|
MEM_ecr_reg2 <= EX_ecr_reg2;
|
182 |
|
|
MEM_data_ecr2 <= tmp_data_ecr2;
|
183 |
|
|
MEM_exc_cause2 <= EX_exc_cause2;
|
184 |
|
|
MEM_level2 <= EX_level2;
|
185 |
|
|
MEM_it_ok2 <= EX_it_ok2;
|
186 |
|
|
end if;
|
187 |
|
|
end if;
|
188 |
|
|
end if;
|
189 |
|
|
end process;
|
190 |
|
|
|
191 |
|
|
end rtl;
|