1 |
2 |
tarookumic |
----------------------------------------------------------------------------
|
2 |
|
|
-- This file is a part of the LEON VHDL model
|
3 |
|
|
-- Copyright (C) 2003 Gaisler Research, all rights reserved
|
4 |
|
|
--
|
5 |
|
|
-- This library is free software; you can redistribute it and/or
|
6 |
|
|
-- modify it under the terms of the GNU Lesser General Public
|
7 |
|
|
-- License as published by the Free Software Foundation; either
|
8 |
|
|
-- version 2 of the License, or (at your option) any later version.
|
9 |
|
|
--
|
10 |
|
|
-- See the file COPYING.LGPL for the full details of the license.
|
11 |
|
|
----------------------------------------------------------------------------
|
12 |
|
|
|
13 |
|
|
-- Konrad Eisele<eiselekd@web.de> ,2002
|
14 |
|
|
|
15 |
|
|
library ieee;
|
16 |
|
|
use ieee.std_logic_1164.all;
|
17 |
|
|
use work.leon_target.all;
|
18 |
|
|
use work.leon_device.all;
|
19 |
|
|
use work.leon_config.all;
|
20 |
|
|
|
21 |
|
|
package mmuconfig is
|
22 |
|
|
|
23 |
|
|
constant M_CTX_SZ : integer := 8;
|
24 |
|
|
constant MMUCTX_BITS : integer := M_CTX_SZ * mmu_config.enable;
|
25 |
|
|
|
26 |
|
|
constant M_EN : boolean := (mmu_config.enable = 1); -- enable mmu
|
27 |
|
|
constant M_EN_DIAG : boolean := mmu_config.tlb_diag; --enable ASI diagnostic access
|
28 |
|
|
constant M_TLB_TYPE : mmu_tlb_type := mmu_config.tlb_type; -- eather split or combined
|
29 |
|
|
constant TLB_REP : mmu_tlb_rep := mmu_config.tlb_rep;
|
30 |
|
|
|
31 |
|
|
constant M_ENT_I : integer range 2 to 64 := mmu_config.itlbnum; -- icache tlb entries: number
|
32 |
|
|
constant M_ENT_ILOG : integer := log2(M_ENT_I); -- icache tlb entries: address bits
|
33 |
|
|
|
34 |
|
|
constant M_ENT_D : integer range 2 to 64 := mmu_config.dtlbnum; -- dcache tlb entries: number
|
35 |
|
|
constant M_ENT_DLOG : integer := log2(M_ENT_D); -- dcache tlb entries: address bits
|
36 |
|
|
|
37 |
|
|
constant M_ENT_C : integer range 2 to 64 := M_ENT_I; -- i/dcache tlb entries: number
|
38 |
|
|
constant M_ENT_CLOG : integer := M_ENT_ILOG; -- i/dcache tlb entries: address bits
|
39 |
|
|
|
40 |
|
|
constant M_ENT_MAX : integer := 64;
|
41 |
|
|
constant XM_ENT_MAX_LOG : integer := log2(M_ENT_MAX);
|
42 |
|
|
constant M_ENT_MAX_LOG : integer := XM_ENT_MAX_LOG;
|
43 |
|
|
|
44 |
|
|
type mmu_idcache is (id_icache, id_dcache);
|
45 |
|
|
|
46 |
|
|
-- ##############################################################
|
47 |
|
|
-- 1.0 virtual address [sparc V8: p.243,Appx.H,Figure H-4]
|
48 |
|
|
-- +--------+--------+--------+---------------+
|
49 |
|
|
-- a) | INDEX1 | INDEX2 | INDEX3 | OFFSET |
|
50 |
|
|
-- +--------+--------+--------+---------------+
|
51 |
|
|
-- 31 24 23 18 17 12 11 0
|
52 |
|
|
|
53 |
|
|
constant VA_I1_SZ : integer := 8;
|
54 |
|
|
constant VA_I2_SZ : integer := 6;
|
55 |
|
|
constant VA_I3_SZ : integer := 6;
|
56 |
|
|
constant VA_I_SZ : integer := VA_I1_SZ+VA_I2_SZ+VA_I3_SZ;
|
57 |
|
|
constant VA_I_MAX : integer := 8;
|
58 |
|
|
|
59 |
|
|
constant VA_I1_U : integer := 31;
|
60 |
|
|
constant VA_I1_D : integer := 32-VA_I1_SZ;
|
61 |
|
|
constant VA_I2_U : integer := 31-VA_I1_SZ;
|
62 |
|
|
constant VA_I2_D : integer := 32-VA_I1_SZ-VA_I2_SZ;
|
63 |
|
|
constant VA_I3_U : integer := 31-VA_I1_SZ-VA_I2_SZ;
|
64 |
|
|
constant VA_I3_D : integer := 32-VA_I_SZ;
|
65 |
|
|
constant VA_I_U : integer := 31;
|
66 |
|
|
constant VA_I_D : integer := 32-VA_I_SZ;
|
67 |
|
|
constant VA_OFF_U : integer := 31-VA_I_SZ;
|
68 |
|
|
constant VA_OFF_D : integer := 0;
|
69 |
|
|
|
70 |
|
|
constant VA_OFFCTX_U : integer := 31;
|
71 |
|
|
constant VA_OFFCTX_D : integer := 0;
|
72 |
|
|
constant VA_OFFREG_U : integer := 31-VA_I1_SZ;
|
73 |
|
|
constant VA_OFFREG_D : integer := 0;
|
74 |
|
|
constant VA_OFFSEG_U : integer := 31-VA_I1_SZ-VA_I2_SZ;
|
75 |
|
|
constant VA_OFFSEG_D : integer := 0;
|
76 |
|
|
constant VA_OFFPAG_U : integer := 31-VA_I_SZ;
|
77 |
|
|
constant VA_OFFPAG_D : integer := 0;
|
78 |
|
|
|
79 |
|
|
-- ##############################################################
|
80 |
|
|
-- 2.0 PAGE TABE DESCRIPTOR (PTD) [sparc V8: p.247,Appx.H,Figure H-7]
|
81 |
|
|
--
|
82 |
|
|
-- +-------------------------------------------------+---+---+
|
83 |
|
|
-- | Page Table Pointer (PTP) | 0 | 0 |
|
84 |
|
|
-- +-------------------------------------------------+---+---+
|
85 |
|
|
-- 31 2 1 0
|
86 |
|
|
--
|
87 |
|
|
-- 2.1 PAGE TABE ENTRY (PTE) [sparc V8: p.247,Appx.H,Figure H-8]
|
88 |
|
|
--
|
89 |
|
|
-- +-----------------------------+---+---+---+-----------+---+
|
90 |
|
|
-- |Physical Page Number (PPN) | C | M | R | ACC | ET¦
|
91 |
|
|
-- +-----------------------------+---+---+---+-----------+---+
|
92 |
|
|
-- 31 8 7 6 5 4 2 1 0
|
93 |
|
|
--
|
94 |
|
|
constant PTD_PTP_U : integer := 31; -- PTD: page table pointer
|
95 |
|
|
constant PTD_PTP_D : integer := 2;
|
96 |
|
|
constant PTD_PTP32_U : integer := 27; -- PTD: page table pointer 32 bit
|
97 |
|
|
constant PTD_PTP32_D : integer := 2;
|
98 |
|
|
constant PTE_PPN_U : integer := 31; -- PTE: physical page number
|
99 |
|
|
constant PTE_PPN_D : integer := 8;
|
100 |
|
|
constant PTE_PPN_S : integer := (PTE_PPN_U+1)-PTE_PPN_D; -- PTE: pysical page number size
|
101 |
|
|
constant PTE_PPN32_U : integer := 27; -- PTE: physical page number 32 bit addr
|
102 |
|
|
constant PTE_PPN32_D : integer := 8;
|
103 |
|
|
constant PTE_PPN32_S : integer := (PTE_PPN32_U+1)-PTE_PPN32_D; -- PTE: pysical page number 32 bit size
|
104 |
|
|
constant PTE_PPN32REG_U : integer := PTE_PPN32_U; -- PTE: pte part of merged result address
|
105 |
|
|
constant PTE_PPN32REG_D : integer := PTE_PPN32_U+1-VA_I1_SZ;
|
106 |
|
|
constant PTE_PPN32SEG_U : integer := PTE_PPN32_U;
|
107 |
|
|
constant PTE_PPN32SEG_D : integer := PTE_PPN32_U+1-VA_I1_SZ-VA_I2_SZ;
|
108 |
|
|
constant PTE_PPN32PAG_U : integer := PTE_PPN32_U;
|
109 |
|
|
constant PTE_PPN32PAG_D : integer := PTE_PPN32_U+1-VA_I_SZ;
|
110 |
|
|
|
111 |
|
|
constant PTE_C : integer := 7; -- PTE: Cacheable bit
|
112 |
|
|
constant PTE_M : integer := 6; -- PTE: Modified bit
|
113 |
|
|
constant PTE_R : integer := 5; -- PTE: Reference Bit - a "1" indicates an PTE
|
114 |
|
|
|
115 |
|
|
constant PTE_ACC_U : integer := 4; -- PTE: Access field
|
116 |
|
|
constant PTE_ACC_D : integer := 2;
|
117 |
|
|
constant ACC_W : integer := 2; -- PTE::ACC : write permission
|
118 |
|
|
constant ACC_E : integer := 3; -- PTE::ACC : exec permission
|
119 |
|
|
constant ACC_SU : integer := 4; -- PTE::ACC : privileged
|
120 |
|
|
|
121 |
|
|
constant PT_ET_U : integer := 1; -- PTD/PTE: PTE Type
|
122 |
|
|
constant PT_ET_D : integer := 0;
|
123 |
|
|
constant ET_INV : std_logic_vector(1 downto 0) := "00";
|
124 |
|
|
constant ET_PTD : std_logic_vector(1 downto 0) := "01";
|
125 |
|
|
constant ET_PTE : std_logic_vector(1 downto 0) := "10";
|
126 |
|
|
constant ET_RVD : std_logic_vector(1 downto 0) := "11";
|
127 |
|
|
|
128 |
|
|
constant PADDR_PTD_U : integer := 31;
|
129 |
|
|
constant PADDR_PTD_D : integer := 6;
|
130 |
|
|
|
131 |
|
|
-- ##############################################################
|
132 |
|
|
-- 3.0 TLBCAM TAG hardware representation (TTG)
|
133 |
|
|
--
|
134 |
|
|
type tlbcam_reg is record
|
135 |
|
|
ET : std_logic_vector(1 downto 0); -- et field
|
136 |
|
|
ACC : std_logic_vector(2 downto 0); -- on flush/probe this will become FPTY
|
137 |
|
|
M : std_logic; -- modified
|
138 |
|
|
R : std_logic; -- referenced
|
139 |
|
|
SU : std_logic; -- equal ACC >= 6
|
140 |
|
|
VALID : std_logic;
|
141 |
|
|
LVL : std_logic_vector(1 downto 0); -- level in pth
|
142 |
|
|
I1 : std_logic_vector(7 downto 0); -- vaddr
|
143 |
|
|
I2 : std_logic_vector(5 downto 0);
|
144 |
|
|
I3 : std_logic_vector(5 downto 0);
|
145 |
|
|
CTX : std_logic_vector(M_CTX_SZ-1 downto 0); -- ctx number
|
146 |
|
|
PPN : std_logic_vector(PTE_PPN_S-1 downto 0); -- physical page number
|
147 |
|
|
C : std_logic; -- cachable
|
148 |
|
|
end record;
|
149 |
|
|
|
150 |
|
|
-- tlbcam_reg::LVL
|
151 |
|
|
constant LVL_PAGE : std_logic_vector(1 downto 0) := "00"; -- equal tlbcam_tfp::TYP FPTY_PAGE
|
152 |
|
|
constant LVL_SEGMENT : std_logic_vector(1 downto 0) := "01"; -- equal tlbcam_tfp::TYP FPTY_SEGMENT
|
153 |
|
|
constant LVL_REGION : std_logic_vector(1 downto 0) := "10"; -- equal tlbcam_tfp::TYP FPTY_REGION
|
154 |
|
|
constant LVL_CTX : std_logic_vector(1 downto 0) := "11"; -- equal tlbcam_tfp::TYP FPTY_CTX
|
155 |
|
|
|
156 |
|
|
-- ##############################################################
|
157 |
|
|
-- 4.0 TLBCAM tag i/o for translation/flush/(probe)
|
158 |
|
|
--
|
159 |
|
|
type tlbcam_tfp is record
|
160 |
|
|
TYP : std_logic_vector(2 downto 0); -- f/(p) type
|
161 |
|
|
I1 : std_logic_vector(7 downto 0); -- vaddr
|
162 |
|
|
I2 : std_logic_vector(5 downto 0);
|
163 |
|
|
I3 : std_logic_vector(5 downto 0);
|
164 |
|
|
CTX : std_logic_vector(M_CTX_SZ-1 downto 0); -- ctx number
|
165 |
|
|
M : std_logic;
|
166 |
|
|
end record;
|
167 |
|
|
|
168 |
|
|
--tlbcam_tfp::TYP
|
169 |
|
|
constant FPTY_PAGE : std_logic_vector(2 downto 0) := "000"; -- level 3 PTE match I1+I2+I3
|
170 |
|
|
constant FPTY_SEGMENT : std_logic_vector(2 downto 0) := "001"; -- level 2/3 PTE/PTD match I1+I2
|
171 |
|
|
constant FPTY_REGION : std_logic_vector(2 downto 0) := "010"; -- level 1/2/3 PTE/PTD match I1
|
172 |
|
|
constant FPTY_CTX : std_logic_vector(2 downto 0) := "011"; -- level 0/1/2/3 PTE/PTD ctx
|
173 |
|
|
constant FPTY_N : std_logic_vector(2 downto 0) := "100"; -- entire tlb
|
174 |
|
|
|
175 |
|
|
-- ##############################################################
|
176 |
|
|
-- 5.0 MMU Control Register [sparc V8: p.253,Appx.H,Figure H-10]
|
177 |
|
|
--
|
178 |
|
|
-- +-------+-----+------------------+-----+-------+--+--+
|
179 |
|
|
-- | IMPL | VER | SC | PSO | resvd |NF|E |
|
180 |
|
|
-- +-------+-----+------------------+-----+-------+--+--+
|
181 |
|
|
-- 31 28 27 24 23 8 7 6 2 1 0
|
182 |
|
|
--
|
183 |
|
|
-- MMU Context Pointer [sparc V8: p.254,Appx.H,Figure H-11]
|
184 |
|
|
-- +-------------------------------------------+--------+
|
185 |
|
|
-- | Context Table Pointer | resvd |
|
186 |
|
|
-- +-------------------------------------------+--------+
|
187 |
|
|
-- 31 2 1 0
|
188 |
|
|
--
|
189 |
|
|
-- MMU Context Number [sparc V8: p.255,Appx.H,Figure H-12]
|
190 |
|
|
-- +----------------------------------------------------+
|
191 |
|
|
-- | Context Table Pointer |
|
192 |
|
|
-- +----------------------------------------------------+
|
193 |
|
|
-- 31 0
|
194 |
|
|
--
|
195 |
|
|
-- fault status/address register [sparc V8: p.256,Appx.H,Table H-13/14]
|
196 |
|
|
-- +------------+-----+---+----+----+-----+----+
|
197 |
|
|
-- | reserved | EBE | L | AT | FT | FAV | OW |
|
198 |
|
|
-- +------------+-----+---+----+----+-----+----+
|
199 |
|
|
-- 31 18 17 10 9 8 7 5 4 2 1 0
|
200 |
|
|
--
|
201 |
|
|
-- +----------------------------------------------------+
|
202 |
|
|
-- | fault address register |
|
203 |
|
|
-- +----------------------------------------------------+
|
204 |
|
|
-- 31 0
|
205 |
|
|
|
206 |
|
|
constant MMCTRL_CTXP_SZ : integer := 30;
|
207 |
|
|
constant MMCTRL_PTP32_U : integer := 25;
|
208 |
|
|
constant MMCTRL_PTP32_D : integer := 0;
|
209 |
|
|
|
210 |
|
|
constant MMCTRL_E : integer := 0;
|
211 |
|
|
constant MMCTRL_NF : integer := 1;
|
212 |
|
|
constant MMCTRL_PSO : integer := 7;
|
213 |
|
|
constant MMCTRL_SC_U : integer := 23;
|
214 |
|
|
constant MMCTRL_SC_D : integer := 8;
|
215 |
|
|
constant MMCTRL_VER_U : integer := 27;
|
216 |
|
|
constant MMCTRL_VER_D : integer := 24;
|
217 |
|
|
constant MMCTRL_IMPL_U : integer := 31;
|
218 |
|
|
constant MMCTRL_IMPL_D : integer := 28;
|
219 |
|
|
constant MMCTRL_TLBDIS : integer := 31;
|
220 |
|
|
|
221 |
|
|
constant MMCTXP_U : integer := 31;
|
222 |
|
|
constant MMCTXP_D : integer := 2;
|
223 |
|
|
|
224 |
|
|
constant MMCTXNR_U : integer := M_CTX_SZ-1;
|
225 |
|
|
constant MMCTXNR_D : integer := 0;
|
226 |
|
|
|
227 |
|
|
constant FS_SZ : integer := 18; -- fault status size
|
228 |
|
|
|
229 |
|
|
constant FS_EBE_U : integer := 17;
|
230 |
|
|
constant FS_EBE_D : integer := 10;
|
231 |
|
|
|
232 |
|
|
constant FS_L_U : integer := 9;
|
233 |
|
|
constant FS_L_D : integer := 8;
|
234 |
|
|
constant FS_L_CTX : std_logic_vector(1 downto 0) := "00";
|
235 |
|
|
constant FS_L_L1 : std_logic_vector(1 downto 0) := "01";
|
236 |
|
|
constant FS_L_L2 : std_logic_vector(1 downto 0) := "10";
|
237 |
|
|
constant FS_L_L3 : std_logic_vector(1 downto 0) := "11";
|
238 |
|
|
|
239 |
|
|
constant FS_AT_U : integer := 7;
|
240 |
|
|
constant FS_AT_D : integer := 5;
|
241 |
|
|
constant FS_AT_LS : natural := 7; --L=0 S=1
|
242 |
|
|
constant FS_AT_ID : natural := 6; --D=0 I=1
|
243 |
|
|
constant FS_AT_SU : natural := 5; --U=0 SU=1
|
244 |
|
|
constant FS_AT_LUDS : std_logic_vector(2 downto 0) := "000";
|
245 |
|
|
constant FS_AT_LSDS : std_logic_vector(2 downto 0) := "001";
|
246 |
|
|
constant FS_AT_LUIS : std_logic_vector(2 downto 0) := "010";
|
247 |
|
|
constant FS_AT_LSIS : std_logic_vector(2 downto 0) := "011";
|
248 |
|
|
constant FS_AT_SUDS : std_logic_vector(2 downto 0) := "100";
|
249 |
|
|
constant FS_AT_SSDS : std_logic_vector(2 downto 0) := "101";
|
250 |
|
|
constant FS_AT_SUIS : std_logic_vector(2 downto 0) := "110";
|
251 |
|
|
constant FS_AT_SSIS : std_logic_vector(2 downto 0) := "111";
|
252 |
|
|
|
253 |
|
|
constant FS_FT_U : integer := 4;
|
254 |
|
|
constant FS_FT_D : integer := 2;
|
255 |
|
|
constant FS_FT_NONE : std_logic_vector(2 downto 0) := "000";
|
256 |
|
|
constant FS_FT_INV : std_logic_vector(2 downto 0) := "001";
|
257 |
|
|
constant FS_FT_PRO : std_logic_vector(2 downto 0) := "010";
|
258 |
|
|
constant FS_FT_PRI : std_logic_vector(2 downto 0) := "011";
|
259 |
|
|
constant FS_FT_TRANS : std_logic_vector(2 downto 0):= "110";
|
260 |
|
|
constant FS_FT_BUS : std_logic_vector(2 downto 0) := "101";
|
261 |
|
|
constant FS_FT_INT : std_logic_vector(2 downto 0) := "110";
|
262 |
|
|
constant FS_FT_RVD : std_logic_vector(2 downto 0) := "111";
|
263 |
|
|
|
264 |
|
|
constant FS_FAV : natural := 1;
|
265 |
|
|
constant FS_OW : natural := 0;
|
266 |
|
|
|
267 |
|
|
--# mmu ctrl reg
|
268 |
|
|
type mmctrl_type1 is record
|
269 |
|
|
e : std_logic; -- enable
|
270 |
|
|
nf : std_logic; -- no fault
|
271 |
|
|
pso : std_logic; -- partial store order
|
272 |
|
|
-- pre : std_logic; -- pretranslation source
|
273 |
|
|
-- pri : std_logic; -- i/d priority
|
274 |
|
|
ctx : std_logic_vector(M_CTX_SZ-1 downto 0);-- context nr
|
275 |
|
|
ctxp : std_logic_vector(MMCTRL_CTXP_SZ-1 downto 0); -- context table pointer
|
276 |
|
|
tlbdis : std_logic; -- tlb disabled
|
277 |
|
|
bar : std_logic_vector(1 downto 0); -- preplace barrier
|
278 |
|
|
end record;
|
279 |
|
|
|
280 |
|
|
--# fault status reg
|
281 |
|
|
type mmctrl_fs_type is record
|
282 |
|
|
ow : std_logic;
|
283 |
|
|
fav : std_logic;
|
284 |
|
|
ft : std_logic_vector(2 downto 0); -- fault type
|
285 |
|
|
at_ls : std_logic; -- access type, load/store
|
286 |
|
|
at_id : std_logic; -- access type, i/dcache
|
287 |
|
|
at_su : std_logic; -- access type, su/user
|
288 |
|
|
l : std_logic_vector(1 downto 0); -- level
|
289 |
|
|
ebe : std_logic_vector(7 downto 0);
|
290 |
|
|
end record;
|
291 |
|
|
|
292 |
|
|
type mmctrl_type2 is record
|
293 |
|
|
fs : mmctrl_fs_type;
|
294 |
|
|
valid : std_logic;
|
295 |
|
|
fa : std_logic_vector(VA_I_SZ-1 downto 0); -- fault address register
|
296 |
|
|
end record;
|
297 |
|
|
|
298 |
|
|
-- ##############################################################
|
299 |
|
|
-- 6. Virtual Flush/Probe address [sparc V8: p.249,Appx.H,Figure H-9]
|
300 |
|
|
-- +---------------------------------------+--------+-------+
|
301 |
|
|
-- | VIRTUAL FLUSH&Probe Address (VFPA) | type | rvd |
|
302 |
|
|
-- +---------------------------------------+--------+-------+
|
303 |
|
|
-- 31 12 11 8 7 0
|
304 |
|
|
--
|
305 |
|
|
--
|
306 |
|
|
subtype FPA is natural range 31 downto 12;
|
307 |
|
|
constant FPA_I1_U : integer := 31;
|
308 |
|
|
constant FPA_I1_D : integer := 24;
|
309 |
|
|
constant FPA_I2_U : integer := 23;
|
310 |
|
|
constant FPA_I2_D : integer := 18;
|
311 |
|
|
constant FPA_I3_U : integer := 17;
|
312 |
|
|
constant FPA_I3_D : integer := 12;
|
313 |
|
|
constant FPTY_U : integer := 10; -- only 3 bits
|
314 |
|
|
constant FPTY_D : integer := 8;
|
315 |
|
|
|
316 |
|
|
-- ##############################################################
|
317 |
|
|
-- 7. control register virtual address [sparc V8: p.253,Appx.H,Table H-5]
|
318 |
|
|
-- +---------------------------------+-----+--------+
|
319 |
|
|
-- | | CNR | rsvd |
|
320 |
|
|
-- +---------------------------------+-----+--------+
|
321 |
|
|
-- 31 10 8 7 0
|
322 |
|
|
|
323 |
|
|
constant CNR_U : integer := 10;
|
324 |
|
|
constant CNR_D : integer := 8;
|
325 |
|
|
constant CNR_CTRL : std_logic_vector(2 downto 0) := "000";
|
326 |
|
|
constant CNR_CTXP : std_logic_vector(2 downto 0) := "001";
|
327 |
|
|
constant CNR_CTX : std_logic_vector(2 downto 0) := "010";
|
328 |
|
|
constant CNR_F : std_logic_vector(2 downto 0) := "011";
|
329 |
|
|
constant CNR_FADDR : std_logic_vector(2 downto 0) := "100";
|
330 |
|
|
|
331 |
|
|
-- ##############################################################
|
332 |
|
|
-- 8. Precise flush (ASI 0x10-14) [sparc V8: p.266,Appx.I]
|
333 |
|
|
-- supported: ASI_FLUSH_PAGE
|
334 |
|
|
-- ASI_FLUSH_CTX
|
335 |
|
|
|
336 |
|
|
constant PFLUSH_PAGE : std_logic := '0';
|
337 |
|
|
constant PFLUSH_CTX : std_logic := '1';
|
338 |
|
|
|
339 |
|
|
-- ##############################################################
|
340 |
|
|
-- 9. Diagnostic access
|
341 |
|
|
--
|
342 |
|
|
constant DIAGF_LVL_U : integer := 1;
|
343 |
|
|
constant DIAGF_LVL_D : integer := 0;
|
344 |
|
|
constant DIAGF_WR : integer := 3;
|
345 |
|
|
constant DIAGF_HIT : integer := 4;
|
346 |
|
|
constant DIAGF_CTX_U : integer := 12;
|
347 |
|
|
constant DIAGF_CTX_D : integer := 5;
|
348 |
|
|
constant DIAGF_VALID : integer := 13;
|
349 |
|
|
end mmuconfig;
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
-- Konrad Eisele<eiselekd@web.de> ,2002
|
354 |
|
|
|
355 |
|
|
library ieee;
|
356 |
|
|
use ieee.std_logic_1164.all;
|
357 |
|
|
use IEEE.std_logic_arith.all;
|
358 |
|
|
use work.mmuconfig.all;
|
359 |
|
|
|
360 |
|
|
package mmulib is
|
361 |
|
|
|
362 |
|
|
function TLB_CreateCamWrite( two_data : std_logic_vector(31 downto 0);
|
363 |
|
|
read : std_logic;
|
364 |
|
|
lvl : std_logic_vector(1 downto 0);
|
365 |
|
|
ctx : std_logic_vector(M_CTX_SZ-1 downto 0);
|
366 |
|
|
vaddr : std_logic_vector(31 downto 0)
|
367 |
|
|
) return tlbcam_reg;
|
368 |
|
|
|
369 |
|
|
procedure TLB_CheckFault( ACC : in std_logic_vector(2 downto 0);
|
370 |
|
|
isid : in mmu_idcache;
|
371 |
|
|
su : in std_logic;
|
372 |
|
|
read : in std_logic;
|
373 |
|
|
fault_pro : out std_logic;
|
374 |
|
|
fault_pri : out std_logic );
|
375 |
|
|
|
376 |
|
|
procedure TLB_MergeData( LVL : in std_logic_vector(1 downto 0);
|
377 |
|
|
PTE : in std_logic_vector(31 downto 0);
|
378 |
|
|
data : in std_logic_vector(31 downto 0);
|
379 |
|
|
transdata : out std_logic_vector(31 downto 0));
|
380 |
|
|
|
381 |
|
|
function TLB_CreateCamTrans( vaddr : std_logic_vector(31 downto 0);
|
382 |
|
|
read : std_logic;
|
383 |
|
|
ctx : std_logic_vector(M_CTX_SZ-1 downto 0)
|
384 |
|
|
) return tlbcam_tfp;
|
385 |
|
|
|
386 |
|
|
function TLB_CreateCamFlush( data : std_logic_vector(31 downto 0);
|
387 |
|
|
ctx : std_logic_vector(M_CTX_SZ-1 downto 0)
|
388 |
|
|
) return tlbcam_tfp;
|
389 |
|
|
|
390 |
|
|
end;
|
391 |
|
|
|
392 |
|
|
package body mmulib is
|
393 |
|
|
|
394 |
|
|
procedure TLB_CheckFault( ACC : in std_logic_vector(2 downto 0);
|
395 |
|
|
isid : in mmu_idcache;
|
396 |
|
|
su : in std_logic;
|
397 |
|
|
read : in std_logic;
|
398 |
|
|
fault_pro : out std_logic;
|
399 |
|
|
fault_pri : out std_logic ) is
|
400 |
|
|
variable c_isd : std_logic;
|
401 |
|
|
begin
|
402 |
|
|
fault_pro := '0';
|
403 |
|
|
fault_pri := '0';
|
404 |
|
|
|
405 |
|
|
-- use '0' == icache '1' == dcache
|
406 |
|
|
if isid = id_icache then
|
407 |
|
|
c_isd := '0';
|
408 |
|
|
else
|
409 |
|
|
c_isd := '1';
|
410 |
|
|
end if;
|
411 |
|
|
--# fault, todo: should we flush on a fault?
|
412 |
|
|
case ACC is
|
413 |
|
|
when "000" => fault_pro := (not c_isd) or (not read);
|
414 |
|
|
when "001" => fault_pro := (not c_isd);
|
415 |
|
|
when "010" => fault_pro := (not read);
|
416 |
|
|
when "011" => null;
|
417 |
|
|
when "100" => fault_pro := (c_isd);
|
418 |
|
|
when "101" => fault_pro := (not c_isd) or ((not read) and (not su));
|
419 |
|
|
when "110" => fault_pri := (not su);
|
420 |
|
|
fault_pro := (not read);
|
421 |
|
|
when "111" => fault_pri := (not su);
|
422 |
|
|
when others => null;
|
423 |
|
|
end case;
|
424 |
|
|
end;
|
425 |
|
|
|
426 |
|
|
procedure TLB_MergeData( LVL : in std_logic_vector(1 downto 0);
|
427 |
|
|
PTE : in std_logic_vector(31 downto 0);
|
428 |
|
|
data : in std_logic_vector(31 downto 0);
|
429 |
|
|
transdata : out std_logic_vector(31 downto 0) ) is
|
430 |
|
|
begin
|
431 |
|
|
|
432 |
|
|
--# merge data
|
433 |
|
|
transdata := (others => '0');
|
434 |
|
|
case LVL is
|
435 |
|
|
when LVL_PAGE => transdata := PTE(PTE_PPN32PAG_U downto PTE_PPN32PAG_D) & data(VA_OFFPAG_U downto VA_OFFPAG_D);
|
436 |
|
|
when LVL_SEGMENT => transdata := PTE(PTE_PPN32SEG_U downto PTE_PPN32SEG_D) & data(VA_OFFSEG_U downto VA_OFFSEG_D);
|
437 |
|
|
when LVL_REGION => transdata := PTE(PTE_PPN32REG_U downto PTE_PPN32REG_D) & data(VA_OFFREG_U downto VA_OFFREG_D);
|
438 |
|
|
when LVL_CTX => transdata := data(VA_OFFCTX_U downto VA_OFFCTX_D);
|
439 |
|
|
when others => transdata := (others => 'X');
|
440 |
|
|
end case;
|
441 |
|
|
end;
|
442 |
|
|
|
443 |
|
|
function TLB_CreateCamWrite( two_data : std_logic_vector(31 downto 0);
|
444 |
|
|
read : std_logic;
|
445 |
|
|
lvl : std_logic_vector(1 downto 0);
|
446 |
|
|
ctx : std_logic_vector(M_CTX_SZ-1 downto 0);
|
447 |
|
|
vaddr : std_logic_vector(31 downto 0)
|
448 |
|
|
) return tlbcam_reg is
|
449 |
|
|
variable tlbcam_tagwrite : tlbcam_reg;
|
450 |
|
|
begin
|
451 |
|
|
|
452 |
|
|
tlbcam_tagwrite.ET := two_data(PT_ET_U downto PT_ET_D);
|
453 |
|
|
tlbcam_tagwrite.ACC := two_data(PTE_ACC_U downto PTE_ACC_D);
|
454 |
|
|
tlbcam_tagwrite.M := two_data(PTE_M) or (not read); -- tw : p-update modified
|
455 |
|
|
tlbcam_tagwrite.R := '1';
|
456 |
|
|
case tlbcam_tagwrite.ACC is -- tw : p-su ACC >= 6
|
457 |
|
|
when "110" | "111" => tlbcam_tagwrite.SU := '1';
|
458 |
|
|
when others => tlbcam_tagwrite.SU := '0';
|
459 |
|
|
end case;
|
460 |
|
|
tlbcam_tagwrite.VALID := '1';
|
461 |
|
|
tlbcam_tagwrite.LVL := lvl;
|
462 |
|
|
tlbcam_tagwrite.I1 := vaddr(VA_I1_U downto VA_I1_D);
|
463 |
|
|
tlbcam_tagwrite.I2 := vaddr(VA_I2_U downto VA_I2_D);
|
464 |
|
|
tlbcam_tagwrite.I3 := vaddr(VA_I3_U downto VA_I3_D);
|
465 |
|
|
tlbcam_tagwrite.CTX := ctx;
|
466 |
|
|
tlbcam_tagwrite.PPN := two_data(PTE_PPN_U downto PTE_PPN_D);
|
467 |
|
|
tlbcam_tagwrite.C := two_data(PTE_C);
|
468 |
|
|
return tlbcam_tagwrite;
|
469 |
|
|
end;
|
470 |
|
|
|
471 |
|
|
function TLB_CreateCamTrans( vaddr : std_logic_vector(31 downto 0);
|
472 |
|
|
read : std_logic;
|
473 |
|
|
ctx : std_logic_vector(M_CTX_SZ-1 downto 0)
|
474 |
|
|
) return tlbcam_tfp is
|
475 |
|
|
variable mtag : tlbcam_tfp;
|
476 |
|
|
begin
|
477 |
|
|
mtag.TYP := (others => '0');
|
478 |
|
|
mtag.I1 := vaddr(VA_I1_U downto VA_I1_D);
|
479 |
|
|
mtag.I2 := vaddr(VA_I2_U downto VA_I2_D);
|
480 |
|
|
mtag.I3 := vaddr(VA_I3_U downto VA_I3_D);
|
481 |
|
|
mtag.CTX := ctx;
|
482 |
|
|
mtag.M := not (read);
|
483 |
|
|
return mtag;
|
484 |
|
|
end;
|
485 |
|
|
|
486 |
|
|
function TLB_CreateCamFlush( data : std_logic_vector(31 downto 0);
|
487 |
|
|
ctx : std_logic_vector(M_CTX_SZ-1 downto 0)
|
488 |
|
|
) return tlbcam_tfp is
|
489 |
|
|
variable ftag : tlbcam_tfp;
|
490 |
|
|
begin
|
491 |
|
|
ftag.TYP := data(FPTY_U downto FPTY_D);
|
492 |
|
|
ftag.I1 := data(FPA_I1_U downto FPA_I1_D);
|
493 |
|
|
ftag.I2 := data(FPA_I2_U downto FPA_I2_D);
|
494 |
|
|
ftag.I3 := data(FPA_I3_U downto FPA_I3_D);
|
495 |
|
|
ftag.CTX := ctx;
|
496 |
|
|
ftag.M := '0';
|
497 |
|
|
return ftag;
|
498 |
|
|
end;
|
499 |
|
|
|
500 |
|
|
end;
|
501 |
|
|
|