root / target-cris / mmu.c @ ed23fbd9
History | View | Annotate | Download (8.9 kB)
1 | 94cff60a | ths | /*
|
---|---|---|---|
2 | 94cff60a | ths | * CRIS mmu emulation.
|
3 | 94cff60a | ths | *
|
4 | 94cff60a | ths | * Copyright (c) 2007 AXIS Communications AB
|
5 | 94cff60a | ths | * Written by Edgar E. Iglesias.
|
6 | 94cff60a | ths | *
|
7 | 94cff60a | ths | * This library is free software; you can redistribute it and/or
|
8 | 94cff60a | ths | * modify it under the terms of the GNU Lesser General Public
|
9 | 94cff60a | ths | * License as published by the Free Software Foundation; either
|
10 | 94cff60a | ths | * version 2 of the License, or (at your option) any later version.
|
11 | 94cff60a | ths | *
|
12 | 94cff60a | ths | * This library is distributed in the hope that it will be useful,
|
13 | 94cff60a | ths | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | 94cff60a | ths | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | 94cff60a | ths | * Lesser General Public License for more details.
|
16 | 94cff60a | ths | *
|
17 | 94cff60a | ths | * You should have received a copy of the GNU Lesser General Public
|
18 | 94cff60a | ths | * License along with this library; if not, write to the Free Software
|
19 | 94cff60a | ths | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20 | 94cff60a | ths | */
|
21 | 94cff60a | ths | |
22 | 94cff60a | ths | #ifndef CONFIG_USER_ONLY
|
23 | 94cff60a | ths | |
24 | 94cff60a | ths | #include <stdio.h> |
25 | 94cff60a | ths | #include <string.h> |
26 | 94cff60a | ths | #include <stdlib.h> |
27 | 94cff60a | ths | |
28 | 94cff60a | ths | #include "config.h" |
29 | 94cff60a | ths | #include "cpu.h" |
30 | 94cff60a | ths | #include "mmu.h" |
31 | 94cff60a | ths | #include "exec-all.h" |
32 | 94cff60a | ths | |
33 | d297f464 | edgar_igl | #ifdef DEBUG
|
34 | d297f464 | edgar_igl | #define D(x) x
|
35 | d297f464 | edgar_igl | #else
|
36 | 786c02f1 | edgar_igl | #define D(x)
|
37 | d297f464 | edgar_igl | #endif
|
38 | 94cff60a | ths | |
39 | 44cd42ee | edgar_igl | void cris_mmu_init(CPUState *env)
|
40 | 44cd42ee | edgar_igl | { |
41 | 44cd42ee | edgar_igl | env->mmu_rand_lfsr = 0xcccc;
|
42 | 44cd42ee | edgar_igl | } |
43 | 44cd42ee | edgar_igl | |
44 | 44cd42ee | edgar_igl | #define SR_POLYNOM 0x8805 |
45 | 44cd42ee | edgar_igl | static inline unsigned int compute_polynom(unsigned int sr) |
46 | 44cd42ee | edgar_igl | { |
47 | 44cd42ee | edgar_igl | unsigned int i; |
48 | 44cd42ee | edgar_igl | unsigned int f; |
49 | 44cd42ee | edgar_igl | |
50 | 44cd42ee | edgar_igl | f = 0;
|
51 | 44cd42ee | edgar_igl | for (i = 0; i < 16; i++) |
52 | 44cd42ee | edgar_igl | f += ((SR_POLYNOM >> i) & 1) & ((sr >> i) & 1); |
53 | 44cd42ee | edgar_igl | |
54 | 44cd42ee | edgar_igl | return f;
|
55 | 44cd42ee | edgar_igl | } |
56 | 44cd42ee | edgar_igl | |
57 | ef29a70d | edgar_igl | static inline int cris_mmu_enabled(uint32_t rw_gc_cfg) |
58 | 94cff60a | ths | { |
59 | 94cff60a | ths | return (rw_gc_cfg & 12) != 0; |
60 | 94cff60a | ths | } |
61 | 94cff60a | ths | |
62 | ef29a70d | edgar_igl | static inline int cris_mmu_segmented_addr(int seg, uint32_t rw_mm_cfg) |
63 | 94cff60a | ths | { |
64 | 94cff60a | ths | return (1 << seg) & rw_mm_cfg; |
65 | 94cff60a | ths | } |
66 | 94cff60a | ths | |
67 | 94cff60a | ths | static uint32_t cris_mmu_translate_seg(CPUState *env, int seg) |
68 | 94cff60a | ths | { |
69 | 94cff60a | ths | uint32_t base; |
70 | 94cff60a | ths | int i;
|
71 | 94cff60a | ths | |
72 | 94cff60a | ths | if (seg < 8) |
73 | 94cff60a | ths | base = env->sregs[SFR_RW_MM_KBASE_LO]; |
74 | 94cff60a | ths | else
|
75 | 94cff60a | ths | base = env->sregs[SFR_RW_MM_KBASE_HI]; |
76 | 94cff60a | ths | |
77 | 94cff60a | ths | i = seg & 7;
|
78 | 94cff60a | ths | base >>= i * 4;
|
79 | 94cff60a | ths | base &= 15;
|
80 | 94cff60a | ths | |
81 | 94cff60a | ths | base <<= 28;
|
82 | 94cff60a | ths | return base;
|
83 | 94cff60a | ths | } |
84 | 94cff60a | ths | /* Used by the tlb decoder. */
|
85 | 94cff60a | ths | #define EXTRACT_FIELD(src, start, end) \
|
86 | 786c02f1 | edgar_igl | (((src) >> start) & ((1 << (end - start + 1)) - 1)) |
87 | 786c02f1 | edgar_igl | |
88 | 786c02f1 | edgar_igl | static inline void set_field(uint32_t *dst, unsigned int val, |
89 | 786c02f1 | edgar_igl | unsigned int offset, unsigned int width) |
90 | 786c02f1 | edgar_igl | { |
91 | 786c02f1 | edgar_igl | uint32_t mask; |
92 | 786c02f1 | edgar_igl | |
93 | 786c02f1 | edgar_igl | mask = (1 << width) - 1; |
94 | 786c02f1 | edgar_igl | mask <<= offset; |
95 | 786c02f1 | edgar_igl | val <<= offset; |
96 | 786c02f1 | edgar_igl | |
97 | 786c02f1 | edgar_igl | val &= mask; |
98 | 786c02f1 | edgar_igl | *dst &= ~(mask); |
99 | 786c02f1 | edgar_igl | *dst |= val; |
100 | 786c02f1 | edgar_igl | } |
101 | 94cff60a | ths | |
102 | d297f464 | edgar_igl | #ifdef DEBUG
|
103 | b41f7df0 | edgar_igl | static void dump_tlb(CPUState *env, int mmu) |
104 | b41f7df0 | edgar_igl | { |
105 | b41f7df0 | edgar_igl | int set;
|
106 | b41f7df0 | edgar_igl | int idx;
|
107 | b41f7df0 | edgar_igl | uint32_t hi, lo, tlb_vpn, tlb_pfn; |
108 | b41f7df0 | edgar_igl | |
109 | b41f7df0 | edgar_igl | for (set = 0; set < 4; set++) { |
110 | b41f7df0 | edgar_igl | for (idx = 0; idx < 16; idx++) { |
111 | b41f7df0 | edgar_igl | lo = env->tlbsets[mmu][set][idx].lo; |
112 | b41f7df0 | edgar_igl | hi = env->tlbsets[mmu][set][idx].hi; |
113 | b41f7df0 | edgar_igl | tlb_vpn = EXTRACT_FIELD(hi, 13, 31); |
114 | b41f7df0 | edgar_igl | tlb_pfn = EXTRACT_FIELD(lo, 13, 31); |
115 | b41f7df0 | edgar_igl | |
116 | b41f7df0 | edgar_igl | printf ("TLB: [%d][%d] hi=%x lo=%x v=%x p=%x\n",
|
117 | b41f7df0 | edgar_igl | set, idx, hi, lo, tlb_vpn, tlb_pfn); |
118 | b41f7df0 | edgar_igl | } |
119 | b41f7df0 | edgar_igl | } |
120 | b41f7df0 | edgar_igl | } |
121 | d297f464 | edgar_igl | #endif
|
122 | b41f7df0 | edgar_igl | |
123 | b41f7df0 | edgar_igl | /* rw 0 = read, 1 = write, 2 = exec. */
|
124 | 94cff60a | ths | static int cris_mmu_translate_page(struct cris_mmu_result_t *res, |
125 | 94cff60a | ths | CPUState *env, uint32_t vaddr, |
126 | 94cff60a | ths | int rw, int usermode) |
127 | 94cff60a | ths | { |
128 | 94cff60a | ths | unsigned int vpage; |
129 | 94cff60a | ths | unsigned int idx; |
130 | 94cff60a | ths | uint32_t lo, hi; |
131 | 786c02f1 | edgar_igl | uint32_t tlb_vpn, tlb_pfn = 0;
|
132 | 786c02f1 | edgar_igl | int tlb_pid, tlb_g, tlb_v, tlb_k, tlb_w, tlb_x;
|
133 | 786c02f1 | edgar_igl | int cfg_v, cfg_k, cfg_w, cfg_x;
|
134 | b41f7df0 | edgar_igl | int set, match = 0; |
135 | 786c02f1 | edgar_igl | uint32_t r_cause; |
136 | 786c02f1 | edgar_igl | uint32_t r_cfg; |
137 | 786c02f1 | edgar_igl | int rwcause;
|
138 | b41f7df0 | edgar_igl | int mmu = 1; /* Data mmu is default. */ |
139 | b41f7df0 | edgar_igl | int vect_base;
|
140 | 786c02f1 | edgar_igl | |
141 | 786c02f1 | edgar_igl | r_cause = env->sregs[SFR_R_MM_CAUSE]; |
142 | 786c02f1 | edgar_igl | r_cfg = env->sregs[SFR_RW_MM_CFG]; |
143 | b41f7df0 | edgar_igl | |
144 | b41f7df0 | edgar_igl | switch (rw) {
|
145 | b41f7df0 | edgar_igl | case 2: rwcause = CRIS_MMU_ERR_EXEC; mmu = 0; break; |
146 | b41f7df0 | edgar_igl | case 1: rwcause = CRIS_MMU_ERR_WRITE; break; |
147 | b41f7df0 | edgar_igl | default:
|
148 | b41f7df0 | edgar_igl | case 0: rwcause = CRIS_MMU_ERR_READ; break; |
149 | b41f7df0 | edgar_igl | } |
150 | b41f7df0 | edgar_igl | |
151 | b41f7df0 | edgar_igl | /* I exception vectors 4 - 7, D 8 - 11. */
|
152 | b41f7df0 | edgar_igl | vect_base = (mmu + 1) * 4; |
153 | 94cff60a | ths | |
154 | 94cff60a | ths | vpage = vaddr >> 13;
|
155 | 94cff60a | ths | |
156 | 94cff60a | ths | /* We know the index which to check on each set.
|
157 | 94cff60a | ths | Scan both I and D. */
|
158 | 786c02f1 | edgar_igl | #if 0
|
159 | b41f7df0 | edgar_igl | for (set = 0; set < 4; set++) {
|
160 | b41f7df0 | edgar_igl | for (idx = 0; idx < 16; idx++) {
|
161 | b41f7df0 | edgar_igl | lo = env->tlbsets[mmu][set][idx].lo;
|
162 | b41f7df0 | edgar_igl | hi = env->tlbsets[mmu][set][idx].hi;
|
163 | 786c02f1 | edgar_igl | tlb_vpn = EXTRACT_FIELD(hi, 13, 31);
|
164 | 786c02f1 | edgar_igl | tlb_pfn = EXTRACT_FIELD(lo, 13, 31);
|
165 | 786c02f1 | edgar_igl | |
166 | 786c02f1 | edgar_igl | printf ("TLB: [%d][%d] hi=%x lo=%x v=%x p=%x\n",
|
167 | b41f7df0 | edgar_igl | set, idx, hi, lo, tlb_vpn, tlb_pfn);
|
168 | 786c02f1 | edgar_igl | }
|
169 | 786c02f1 | edgar_igl | }
|
170 | 786c02f1 | edgar_igl | #endif
|
171 | b41f7df0 | edgar_igl | |
172 | b41f7df0 | edgar_igl | idx = vpage & 15;
|
173 | b41f7df0 | edgar_igl | for (set = 0; set < 4; set++) |
174 | 94cff60a | ths | { |
175 | b41f7df0 | edgar_igl | lo = env->tlbsets[mmu][set][idx].lo; |
176 | b41f7df0 | edgar_igl | hi = env->tlbsets[mmu][set][idx].hi; |
177 | 94cff60a | ths | |
178 | 786c02f1 | edgar_igl | tlb_vpn = EXTRACT_FIELD(hi, 13, 31); |
179 | 44cd42ee | edgar_igl | tlb_pid = EXTRACT_FIELD(hi, 0, 7); |
180 | 786c02f1 | edgar_igl | tlb_pfn = EXTRACT_FIELD(lo, 13, 31); |
181 | 44cd42ee | edgar_igl | tlb_g = EXTRACT_FIELD(lo, 4, 4); |
182 | 94cff60a | ths | |
183 | cf1d97f0 | edgar_igl | D(fprintf(logfile, |
184 | cf1d97f0 | edgar_igl | "TLB[%d][%d][%d] v=%x vpage=%x->pfn=%x lo=%x hi=%x\n",
|
185 | cf1d97f0 | edgar_igl | mmu, set, idx, tlb_vpn, vpage, tlb_pfn, lo, hi)); |
186 | 44cd42ee | edgar_igl | if ((tlb_g || (tlb_pid == (env->pregs[PR_PID] & 0xff))) |
187 | 44cd42ee | edgar_igl | && tlb_vpn == vpage) { |
188 | 94cff60a | ths | match = 1;
|
189 | 94cff60a | ths | break;
|
190 | 94cff60a | ths | } |
191 | 94cff60a | ths | } |
192 | 94cff60a | ths | |
193 | b41f7df0 | edgar_igl | res->bf_vec = vect_base; |
194 | 94cff60a | ths | if (match) {
|
195 | 786c02f1 | edgar_igl | cfg_w = EXTRACT_FIELD(r_cfg, 19, 19); |
196 | 786c02f1 | edgar_igl | cfg_k = EXTRACT_FIELD(r_cfg, 18, 18); |
197 | 786c02f1 | edgar_igl | cfg_x = EXTRACT_FIELD(r_cfg, 17, 17); |
198 | 786c02f1 | edgar_igl | cfg_v = EXTRACT_FIELD(r_cfg, 16, 16); |
199 | 786c02f1 | edgar_igl | |
200 | 786c02f1 | edgar_igl | tlb_pfn = EXTRACT_FIELD(lo, 13, 31); |
201 | 786c02f1 | edgar_igl | tlb_v = EXTRACT_FIELD(lo, 3, 3); |
202 | 786c02f1 | edgar_igl | tlb_k = EXTRACT_FIELD(lo, 2, 2); |
203 | 786c02f1 | edgar_igl | tlb_w = EXTRACT_FIELD(lo, 1, 1); |
204 | 786c02f1 | edgar_igl | tlb_x = EXTRACT_FIELD(lo, 0, 0); |
205 | 786c02f1 | edgar_igl | |
206 | 786c02f1 | edgar_igl | /*
|
207 | 786c02f1 | edgar_igl | set_exception_vector(0x04, i_mmu_refill);
|
208 | 786c02f1 | edgar_igl | set_exception_vector(0x05, i_mmu_invalid);
|
209 | 786c02f1 | edgar_igl | set_exception_vector(0x06, i_mmu_access);
|
210 | 786c02f1 | edgar_igl | set_exception_vector(0x07, i_mmu_execute);
|
211 | 786c02f1 | edgar_igl | set_exception_vector(0x08, d_mmu_refill);
|
212 | 786c02f1 | edgar_igl | set_exception_vector(0x09, d_mmu_invalid);
|
213 | 786c02f1 | edgar_igl | set_exception_vector(0x0a, d_mmu_access);
|
214 | 786c02f1 | edgar_igl | set_exception_vector(0x0b, d_mmu_write);
|
215 | 786c02f1 | edgar_igl | */
|
216 | 44cd42ee | edgar_igl | if (cfg_k && tlb_k && usermode) {
|
217 | ef29a70d | edgar_igl | D(printf ("tlb: kernel protected %x lo=%x pc=%x\n",
|
218 | ef29a70d | edgar_igl | vaddr, lo, env->pc)); |
219 | ef29a70d | edgar_igl | match = 0;
|
220 | ef29a70d | edgar_igl | res->bf_vec = vect_base + 2;
|
221 | b41f7df0 | edgar_igl | } else if (rw == 1 && cfg_w && !tlb_w) { |
222 | ef29a70d | edgar_igl | D(printf ("tlb: write protected %x lo=%x pc=%x\n",
|
223 | ef29a70d | edgar_igl | vaddr, lo, env->pc)); |
224 | ef29a70d | edgar_igl | match = 0;
|
225 | ef29a70d | edgar_igl | /* write accesses never go through the I mmu. */
|
226 | ef29a70d | edgar_igl | res->bf_vec = vect_base + 3;
|
227 | ef29a70d | edgar_igl | } else if (rw == 2 && cfg_x && !tlb_x) { |
228 | ef29a70d | edgar_igl | D(printf ("tlb: exec protected %x lo=%x pc=%x\n",
|
229 | ef29a70d | edgar_igl | vaddr, lo, env->pc)); |
230 | 786c02f1 | edgar_igl | match = 0;
|
231 | b41f7df0 | edgar_igl | res->bf_vec = vect_base + 3;
|
232 | b41f7df0 | edgar_igl | } else if (cfg_v && !tlb_v) { |
233 | b41f7df0 | edgar_igl | D(printf ("tlb: invalid %x\n", vaddr));
|
234 | 786c02f1 | edgar_igl | match = 0;
|
235 | b41f7df0 | edgar_igl | res->bf_vec = vect_base + 1;
|
236 | 786c02f1 | edgar_igl | } |
237 | 786c02f1 | edgar_igl | |
238 | b41f7df0 | edgar_igl | res->prot = 0;
|
239 | b41f7df0 | edgar_igl | if (match) {
|
240 | b41f7df0 | edgar_igl | res->prot |= PAGE_READ; |
241 | b41f7df0 | edgar_igl | if (tlb_w)
|
242 | b41f7df0 | edgar_igl | res->prot |= PAGE_WRITE; |
243 | b41f7df0 | edgar_igl | if (tlb_x)
|
244 | b41f7df0 | edgar_igl | res->prot |= PAGE_EXEC; |
245 | b41f7df0 | edgar_igl | } |
246 | b41f7df0 | edgar_igl | else
|
247 | b41f7df0 | edgar_igl | D(dump_tlb(env, mmu)); |
248 | b41f7df0 | edgar_igl | |
249 | b41f7df0 | edgar_igl | env->sregs[SFR_RW_MM_TLB_HI] = hi; |
250 | b41f7df0 | edgar_igl | env->sregs[SFR_RW_MM_TLB_LO] = lo; |
251 | 44cd42ee | edgar_igl | } else {
|
252 | 44cd42ee | edgar_igl | /* If refill, provide a randomized set. */
|
253 | 44cd42ee | edgar_igl | set = env->mmu_rand_lfsr & 3;
|
254 | 786c02f1 | edgar_igl | } |
255 | 786c02f1 | edgar_igl | |
256 | 786c02f1 | edgar_igl | if (!match) {
|
257 | 44cd42ee | edgar_igl | unsigned int f; |
258 | 44cd42ee | edgar_igl | |
259 | 44cd42ee | edgar_igl | /* Update lfsr at every fault. */
|
260 | 44cd42ee | edgar_igl | f = compute_polynom(env->mmu_rand_lfsr); |
261 | 44cd42ee | edgar_igl | env->mmu_rand_lfsr >>= 1;
|
262 | 44cd42ee | edgar_igl | env->mmu_rand_lfsr |= (f << 15);
|
263 | 44cd42ee | edgar_igl | env->mmu_rand_lfsr &= 0xffff;
|
264 | 44cd42ee | edgar_igl | |
265 | 44cd42ee | edgar_igl | /* Compute index. */
|
266 | b41f7df0 | edgar_igl | idx = vpage & 15;
|
267 | b41f7df0 | edgar_igl | |
268 | b41f7df0 | edgar_igl | /* Update RW_MM_TLB_SEL. */
|
269 | b41f7df0 | edgar_igl | env->sregs[SFR_RW_MM_TLB_SEL] = 0;
|
270 | b41f7df0 | edgar_igl | set_field(&env->sregs[SFR_RW_MM_TLB_SEL], idx, 0, 4); |
271 | 44cd42ee | edgar_igl | set_field(&env->sregs[SFR_RW_MM_TLB_SEL], set, 4, 2); |
272 | b41f7df0 | edgar_igl | |
273 | b41f7df0 | edgar_igl | /* Update RW_MM_CAUSE. */
|
274 | b41f7df0 | edgar_igl | set_field(&r_cause, rwcause, 8, 2); |
275 | 786c02f1 | edgar_igl | set_field(&r_cause, vpage, 13, 19); |
276 | 786c02f1 | edgar_igl | set_field(&r_cause, env->pregs[PR_PID], 0, 8); |
277 | 786c02f1 | edgar_igl | env->sregs[SFR_R_MM_CAUSE] = r_cause; |
278 | b41f7df0 | edgar_igl | D(printf("refill vaddr=%x pc=%x\n", vaddr, env->pc));
|
279 | 94cff60a | ths | } |
280 | b41f7df0 | edgar_igl | |
281 | b41f7df0 | edgar_igl | |
282 | b41f7df0 | edgar_igl | D(printf ("%s rw=%d mtch=%d pc=%x va=%x vpn=%x tlbvpn=%x pfn=%x pid=%x"
|
283 | b41f7df0 | edgar_igl | " %x cause=%x sel=%x sp=%x %x %x\n",
|
284 | b41f7df0 | edgar_igl | __func__, rw, match, env->pc, |
285 | 786c02f1 | edgar_igl | vaddr, vpage, |
286 | 786c02f1 | edgar_igl | tlb_vpn, tlb_pfn, tlb_pid, |
287 | 786c02f1 | edgar_igl | env->pregs[PR_PID], |
288 | 786c02f1 | edgar_igl | r_cause, |
289 | 786c02f1 | edgar_igl | env->sregs[SFR_RW_MM_TLB_SEL], |
290 | b41f7df0 | edgar_igl | env->regs[R_SP], env->pregs[PR_USP], env->ksp)); |
291 | 786c02f1 | edgar_igl | |
292 | 786c02f1 | edgar_igl | res->pfn = tlb_pfn; |
293 | 94cff60a | ths | return !match;
|
294 | 94cff60a | ths | } |
295 | 94cff60a | ths | |
296 | cf1d97f0 | edgar_igl | void cris_mmu_flush_pid(CPUState *env, uint32_t pid)
|
297 | 786c02f1 | edgar_igl | { |
298 | cf1d97f0 | edgar_igl | target_ulong vaddr; |
299 | cf1d97f0 | edgar_igl | unsigned int idx; |
300 | cf1d97f0 | edgar_igl | uint32_t lo, hi; |
301 | cf1d97f0 | edgar_igl | uint32_t tlb_vpn; |
302 | cf1d97f0 | edgar_igl | int tlb_pid, tlb_g, tlb_v, tlb_k;
|
303 | cf1d97f0 | edgar_igl | unsigned int set; |
304 | cf1d97f0 | edgar_igl | unsigned int mmu; |
305 | cf1d97f0 | edgar_igl | |
306 | cf1d97f0 | edgar_igl | pid &= 0xff;
|
307 | cf1d97f0 | edgar_igl | for (mmu = 0; mmu < 2; mmu++) { |
308 | cf1d97f0 | edgar_igl | for (set = 0; set < 4; set++) |
309 | cf1d97f0 | edgar_igl | { |
310 | cf1d97f0 | edgar_igl | for (idx = 0; idx < 16; idx++) { |
311 | cf1d97f0 | edgar_igl | lo = env->tlbsets[mmu][set][idx].lo; |
312 | cf1d97f0 | edgar_igl | hi = env->tlbsets[mmu][set][idx].hi; |
313 | cf1d97f0 | edgar_igl | |
314 | cf1d97f0 | edgar_igl | tlb_vpn = EXTRACT_FIELD(hi, 13, 31); |
315 | cf1d97f0 | edgar_igl | tlb_pid = EXTRACT_FIELD(hi, 0, 7); |
316 | cf1d97f0 | edgar_igl | tlb_g = EXTRACT_FIELD(lo, 4, 4); |
317 | cf1d97f0 | edgar_igl | tlb_v = EXTRACT_FIELD(lo, 3, 3); |
318 | cf1d97f0 | edgar_igl | tlb_k = EXTRACT_FIELD(lo, 2, 2); |
319 | cf1d97f0 | edgar_igl | |
320 | cf1d97f0 | edgar_igl | /* Kernel protected areas need to be flushed
|
321 | cf1d97f0 | edgar_igl | as well. */
|
322 | cf1d97f0 | edgar_igl | if (tlb_v && !tlb_g) {
|
323 | cf1d97f0 | edgar_igl | vaddr = tlb_vpn << TARGET_PAGE_BITS; |
324 | cf1d97f0 | edgar_igl | D(fprintf(logfile, |
325 | cf1d97f0 | edgar_igl | "flush pid=%x vaddr=%x\n",
|
326 | cf1d97f0 | edgar_igl | pid, vaddr)); |
327 | cf1d97f0 | edgar_igl | tlb_flush_page(env, vaddr); |
328 | cf1d97f0 | edgar_igl | } |
329 | cf1d97f0 | edgar_igl | } |
330 | cf1d97f0 | edgar_igl | } |
331 | cf1d97f0 | edgar_igl | } |
332 | 786c02f1 | edgar_igl | } |
333 | 786c02f1 | edgar_igl | |
334 | 94cff60a | ths | int cris_mmu_translate(struct cris_mmu_result_t *res, |
335 | 94cff60a | ths | CPUState *env, uint32_t vaddr, |
336 | 6ebbf390 | j_mayer | int rw, int mmu_idx) |
337 | 94cff60a | ths | { |
338 | 94cff60a | ths | uint32_t phy = vaddr; |
339 | 94cff60a | ths | int seg;
|
340 | 94cff60a | ths | int miss = 0; |
341 | 786c02f1 | edgar_igl | int is_user = mmu_idx == MMU_USER_IDX;
|
342 | b41f7df0 | edgar_igl | uint32_t old_srs; |
343 | b41f7df0 | edgar_igl | |
344 | b41f7df0 | edgar_igl | old_srs= env->pregs[PR_SRS]; |
345 | b41f7df0 | edgar_igl | |
346 | b41f7df0 | edgar_igl | /* rw == 2 means exec, map the access to the insn mmu. */
|
347 | b41f7df0 | edgar_igl | env->pregs[PR_SRS] = rw == 2 ? 1 : 2; |
348 | 94cff60a | ths | |
349 | 94cff60a | ths | if (!cris_mmu_enabled(env->sregs[SFR_RW_GC_CFG])) {
|
350 | 94cff60a | ths | res->phy = vaddr; |
351 | b41f7df0 | edgar_igl | res->prot = PAGE_BITS; |
352 | b41f7df0 | edgar_igl | goto done;
|
353 | 94cff60a | ths | } |
354 | 94cff60a | ths | |
355 | 94cff60a | ths | seg = vaddr >> 28;
|
356 | 94cff60a | ths | if (cris_mmu_segmented_addr(seg, env->sregs[SFR_RW_MM_CFG]))
|
357 | 94cff60a | ths | { |
358 | 94cff60a | ths | uint32_t base; |
359 | 94cff60a | ths | |
360 | 94cff60a | ths | miss = 0;
|
361 | 94cff60a | ths | base = cris_mmu_translate_seg(env, seg); |
362 | 94cff60a | ths | phy = base | (0x0fffffff & vaddr);
|
363 | 94cff60a | ths | res->phy = phy; |
364 | b41f7df0 | edgar_igl | res->prot = PAGE_BITS; |
365 | 94cff60a | ths | } |
366 | 94cff60a | ths | else
|
367 | 94cff60a | ths | { |
368 | 94cff60a | ths | miss = cris_mmu_translate_page(res, env, vaddr, rw, is_user); |
369 | b41f7df0 | edgar_igl | phy = (res->pfn << 13);
|
370 | b41f7df0 | edgar_igl | res->phy = phy; |
371 | 94cff60a | ths | } |
372 | b41f7df0 | edgar_igl | done:
|
373 | b41f7df0 | edgar_igl | env->pregs[PR_SRS] = old_srs; |
374 | 94cff60a | ths | return miss;
|
375 | 94cff60a | ths | } |
376 | 94cff60a | ths | #endif |