root / target-sh4 / helper.c @ 442599a3
History | View | Annotate | Download (18.2 kB)
1 | fdf9b3e8 | bellard | /*
|
---|---|---|---|
2 | fdf9b3e8 | bellard | * SH4 emulation
|
3 | 5fafdf24 | ths | *
|
4 | fdf9b3e8 | bellard | * Copyright (c) 2005 Samuel Tardieu
|
5 | fdf9b3e8 | bellard | *
|
6 | fdf9b3e8 | bellard | * This library is free software; you can redistribute it and/or
|
7 | fdf9b3e8 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | fdf9b3e8 | bellard | * License as published by the Free Software Foundation; either
|
9 | fdf9b3e8 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | fdf9b3e8 | bellard | *
|
11 | fdf9b3e8 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | fdf9b3e8 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | fdf9b3e8 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | fdf9b3e8 | bellard | * Lesser General Public License for more details.
|
15 | fdf9b3e8 | bellard | *
|
16 | fdf9b3e8 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 8167ee88 | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | fdf9b3e8 | bellard | */
|
19 | fdf9b3e8 | bellard | #include <stdarg.h> |
20 | fdf9b3e8 | bellard | #include <stdlib.h> |
21 | fdf9b3e8 | bellard | #include <stdio.h> |
22 | fdf9b3e8 | bellard | #include <string.h> |
23 | fdf9b3e8 | bellard | #include <inttypes.h> |
24 | fdf9b3e8 | bellard | #include <signal.h> |
25 | fdf9b3e8 | bellard | |
26 | fdf9b3e8 | bellard | #include "cpu.h" |
27 | fdf9b3e8 | bellard | #include "exec-all.h" |
28 | e96e2044 | ths | #include "hw/sh_intc.h" |
29 | fdf9b3e8 | bellard | |
30 | 355fb23d | pbrook | #if defined(CONFIG_USER_ONLY)
|
31 | 355fb23d | pbrook | |
32 | 355fb23d | pbrook | void do_interrupt (CPUState *env)
|
33 | 355fb23d | pbrook | { |
34 | 355fb23d | pbrook | env->exception_index = -1;
|
35 | 355fb23d | pbrook | } |
36 | 355fb23d | pbrook | |
37 | 355fb23d | pbrook | int cpu_sh4_handle_mmu_fault(CPUState * env, target_ulong address, int rw, |
38 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu) |
39 | 355fb23d | pbrook | { |
40 | 355fb23d | pbrook | env->tea = address; |
41 | ee0dc6d3 | Blue Swirl | env->exception_index = -1;
|
42 | 355fb23d | pbrook | switch (rw) {
|
43 | 355fb23d | pbrook | case 0: |
44 | 355fb23d | pbrook | env->exception_index = 0x0a0;
|
45 | 355fb23d | pbrook | break;
|
46 | 355fb23d | pbrook | case 1: |
47 | 355fb23d | pbrook | env->exception_index = 0x0c0;
|
48 | 355fb23d | pbrook | break;
|
49 | cf7055bd | aurel32 | case 2: |
50 | cf7055bd | aurel32 | env->exception_index = 0x0a0;
|
51 | cf7055bd | aurel32 | break;
|
52 | 355fb23d | pbrook | } |
53 | 355fb23d | pbrook | return 1; |
54 | 355fb23d | pbrook | } |
55 | 355fb23d | pbrook | |
56 | 3c1adf12 | edgar_igl | int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr)
|
57 | 3c1adf12 | edgar_igl | { |
58 | 3c1adf12 | edgar_igl | /* For user mode, only U0 area is cachable. */
|
59 | 679dee3c | edgar_igl | return !(addr & 0x80000000); |
60 | 3c1adf12 | edgar_igl | } |
61 | 3c1adf12 | edgar_igl | |
62 | 355fb23d | pbrook | #else /* !CONFIG_USER_ONLY */ |
63 | 355fb23d | pbrook | |
64 | fdf9b3e8 | bellard | #define MMU_OK 0 |
65 | fdf9b3e8 | bellard | #define MMU_ITLB_MISS (-1) |
66 | fdf9b3e8 | bellard | #define MMU_ITLB_MULTIPLE (-2) |
67 | fdf9b3e8 | bellard | #define MMU_ITLB_VIOLATION (-3) |
68 | fdf9b3e8 | bellard | #define MMU_DTLB_MISS_READ (-4) |
69 | fdf9b3e8 | bellard | #define MMU_DTLB_MISS_WRITE (-5) |
70 | fdf9b3e8 | bellard | #define MMU_DTLB_INITIAL_WRITE (-6) |
71 | fdf9b3e8 | bellard | #define MMU_DTLB_VIOLATION_READ (-7) |
72 | fdf9b3e8 | bellard | #define MMU_DTLB_VIOLATION_WRITE (-8) |
73 | fdf9b3e8 | bellard | #define MMU_DTLB_MULTIPLE (-9) |
74 | fdf9b3e8 | bellard | #define MMU_DTLB_MISS (-10) |
75 | cf7055bd | aurel32 | #define MMU_IADDR_ERROR (-11) |
76 | cf7055bd | aurel32 | #define MMU_DADDR_ERROR_READ (-12) |
77 | cf7055bd | aurel32 | #define MMU_DADDR_ERROR_WRITE (-13) |
78 | fdf9b3e8 | bellard | |
79 | fdf9b3e8 | bellard | void do_interrupt(CPUState * env)
|
80 | fdf9b3e8 | bellard | { |
81 | e96e2044 | ths | int do_irq = env->interrupt_request & CPU_INTERRUPT_HARD;
|
82 | e96e2044 | ths | int do_exp, irq_vector = env->exception_index;
|
83 | e96e2044 | ths | |
84 | e96e2044 | ths | /* prioritize exceptions over interrupts */
|
85 | e96e2044 | ths | |
86 | e96e2044 | ths | do_exp = env->exception_index != -1;
|
87 | e96e2044 | ths | do_irq = do_irq && (env->exception_index == -1);
|
88 | e96e2044 | ths | |
89 | e96e2044 | ths | if (env->sr & SR_BL) {
|
90 | e96e2044 | ths | if (do_exp && env->exception_index != 0x1e0) { |
91 | e96e2044 | ths | env->exception_index = 0x000; /* masked exception -> reset */ |
92 | e96e2044 | ths | } |
93 | 833ed386 | aurel32 | if (do_irq && !env->intr_at_halt) {
|
94 | e96e2044 | ths | return; /* masked */ |
95 | e96e2044 | ths | } |
96 | 833ed386 | aurel32 | env->intr_at_halt = 0;
|
97 | e96e2044 | ths | } |
98 | e96e2044 | ths | |
99 | e96e2044 | ths | if (do_irq) {
|
100 | e96e2044 | ths | irq_vector = sh_intc_get_pending_vector(env->intc_handle, |
101 | e96e2044 | ths | (env->sr >> 4) & 0xf); |
102 | e96e2044 | ths | if (irq_vector == -1) { |
103 | e96e2044 | ths | return; /* masked */ |
104 | e96e2044 | ths | } |
105 | e96e2044 | ths | } |
106 | e96e2044 | ths | |
107 | 8fec2b8c | aliguori | if (qemu_loglevel_mask(CPU_LOG_INT)) {
|
108 | fdf9b3e8 | bellard | const char *expname; |
109 | fdf9b3e8 | bellard | switch (env->exception_index) {
|
110 | fdf9b3e8 | bellard | case 0x0e0: |
111 | fdf9b3e8 | bellard | expname = "addr_error";
|
112 | fdf9b3e8 | bellard | break;
|
113 | fdf9b3e8 | bellard | case 0x040: |
114 | fdf9b3e8 | bellard | expname = "tlb_miss";
|
115 | fdf9b3e8 | bellard | break;
|
116 | fdf9b3e8 | bellard | case 0x0a0: |
117 | fdf9b3e8 | bellard | expname = "tlb_violation";
|
118 | fdf9b3e8 | bellard | break;
|
119 | fdf9b3e8 | bellard | case 0x180: |
120 | fdf9b3e8 | bellard | expname = "illegal_instruction";
|
121 | fdf9b3e8 | bellard | break;
|
122 | fdf9b3e8 | bellard | case 0x1a0: |
123 | fdf9b3e8 | bellard | expname = "slot_illegal_instruction";
|
124 | fdf9b3e8 | bellard | break;
|
125 | fdf9b3e8 | bellard | case 0x800: |
126 | fdf9b3e8 | bellard | expname = "fpu_disable";
|
127 | fdf9b3e8 | bellard | break;
|
128 | fdf9b3e8 | bellard | case 0x820: |
129 | fdf9b3e8 | bellard | expname = "slot_fpu";
|
130 | fdf9b3e8 | bellard | break;
|
131 | fdf9b3e8 | bellard | case 0x100: |
132 | fdf9b3e8 | bellard | expname = "data_write";
|
133 | fdf9b3e8 | bellard | break;
|
134 | fdf9b3e8 | bellard | case 0x060: |
135 | fdf9b3e8 | bellard | expname = "dtlb_miss_write";
|
136 | fdf9b3e8 | bellard | break;
|
137 | fdf9b3e8 | bellard | case 0x0c0: |
138 | fdf9b3e8 | bellard | expname = "dtlb_violation_write";
|
139 | fdf9b3e8 | bellard | break;
|
140 | fdf9b3e8 | bellard | case 0x120: |
141 | fdf9b3e8 | bellard | expname = "fpu_exception";
|
142 | fdf9b3e8 | bellard | break;
|
143 | fdf9b3e8 | bellard | case 0x080: |
144 | fdf9b3e8 | bellard | expname = "initial_page_write";
|
145 | fdf9b3e8 | bellard | break;
|
146 | fdf9b3e8 | bellard | case 0x160: |
147 | fdf9b3e8 | bellard | expname = "trapa";
|
148 | fdf9b3e8 | bellard | break;
|
149 | fdf9b3e8 | bellard | default:
|
150 | e96e2044 | ths | expname = do_irq ? "interrupt" : "???"; |
151 | e96e2044 | ths | break;
|
152 | fdf9b3e8 | bellard | } |
153 | 93fcfe39 | aliguori | qemu_log("exception 0x%03x [%s] raised\n",
|
154 | 93fcfe39 | aliguori | irq_vector, expname); |
155 | 93fcfe39 | aliguori | log_cpu_state(env, 0);
|
156 | fdf9b3e8 | bellard | } |
157 | fdf9b3e8 | bellard | |
158 | fdf9b3e8 | bellard | env->ssr = env->sr; |
159 | e96e2044 | ths | env->spc = env->pc; |
160 | fdf9b3e8 | bellard | env->sgr = env->gregs[15];
|
161 | fdf9b3e8 | bellard | env->sr |= SR_BL | SR_MD | SR_RB; |
162 | fdf9b3e8 | bellard | |
163 | 274a9e70 | aurel32 | if (env->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) {
|
164 | 274a9e70 | aurel32 | /* Branch instruction should be executed again before delay slot. */
|
165 | 274a9e70 | aurel32 | env->spc -= 2;
|
166 | 274a9e70 | aurel32 | /* Clear flags for exception/interrupt routine. */
|
167 | 274a9e70 | aurel32 | env->flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL | DELAY_SLOT_TRUE); |
168 | 274a9e70 | aurel32 | } |
169 | 274a9e70 | aurel32 | if (env->flags & DELAY_SLOT_CLEARME)
|
170 | 274a9e70 | aurel32 | env->flags = 0;
|
171 | 274a9e70 | aurel32 | |
172 | e96e2044 | ths | if (do_exp) {
|
173 | e96e2044 | ths | env->expevt = env->exception_index; |
174 | e96e2044 | ths | switch (env->exception_index) {
|
175 | e96e2044 | ths | case 0x000: |
176 | e96e2044 | ths | case 0x020: |
177 | e96e2044 | ths | case 0x140: |
178 | e96e2044 | ths | env->sr &= ~SR_FD; |
179 | e96e2044 | ths | env->sr |= 0xf << 4; /* IMASK */ |
180 | e96e2044 | ths | env->pc = 0xa0000000;
|
181 | e96e2044 | ths | break;
|
182 | e96e2044 | ths | case 0x040: |
183 | e96e2044 | ths | case 0x060: |
184 | e96e2044 | ths | env->pc = env->vbr + 0x400;
|
185 | e96e2044 | ths | break;
|
186 | e96e2044 | ths | case 0x160: |
187 | e96e2044 | ths | env->spc += 2; /* special case for TRAPA */ |
188 | e96e2044 | ths | /* fall through */
|
189 | e96e2044 | ths | default:
|
190 | e96e2044 | ths | env->pc = env->vbr + 0x100;
|
191 | e96e2044 | ths | break;
|
192 | e96e2044 | ths | } |
193 | e96e2044 | ths | return;
|
194 | e96e2044 | ths | } |
195 | e96e2044 | ths | |
196 | e96e2044 | ths | if (do_irq) {
|
197 | e96e2044 | ths | env->intevt = irq_vector; |
198 | e96e2044 | ths | env->pc = env->vbr + 0x600;
|
199 | e96e2044 | ths | return;
|
200 | fdf9b3e8 | bellard | } |
201 | fdf9b3e8 | bellard | } |
202 | fdf9b3e8 | bellard | |
203 | fdf9b3e8 | bellard | static void update_itlb_use(CPUState * env, int itlbnb) |
204 | fdf9b3e8 | bellard | { |
205 | fdf9b3e8 | bellard | uint8_t or_mask = 0, and_mask = (uint8_t) - 1; |
206 | fdf9b3e8 | bellard | |
207 | fdf9b3e8 | bellard | switch (itlbnb) {
|
208 | fdf9b3e8 | bellard | case 0: |
209 | ea2b542a | aurel32 | and_mask = 0x1f;
|
210 | fdf9b3e8 | bellard | break;
|
211 | fdf9b3e8 | bellard | case 1: |
212 | fdf9b3e8 | bellard | and_mask = 0xe7;
|
213 | fdf9b3e8 | bellard | or_mask = 0x80;
|
214 | fdf9b3e8 | bellard | break;
|
215 | fdf9b3e8 | bellard | case 2: |
216 | fdf9b3e8 | bellard | and_mask = 0xfb;
|
217 | fdf9b3e8 | bellard | or_mask = 0x50;
|
218 | fdf9b3e8 | bellard | break;
|
219 | fdf9b3e8 | bellard | case 3: |
220 | fdf9b3e8 | bellard | or_mask = 0x2c;
|
221 | fdf9b3e8 | bellard | break;
|
222 | fdf9b3e8 | bellard | } |
223 | fdf9b3e8 | bellard | |
224 | ea2b542a | aurel32 | env->mmucr &= (and_mask << 24) | 0x00ffffff; |
225 | fdf9b3e8 | bellard | env->mmucr |= (or_mask << 24);
|
226 | fdf9b3e8 | bellard | } |
227 | fdf9b3e8 | bellard | |
228 | fdf9b3e8 | bellard | static int itlb_replacement(CPUState * env) |
229 | fdf9b3e8 | bellard | { |
230 | fdf9b3e8 | bellard | if ((env->mmucr & 0xe0000000) == 0xe0000000) |
231 | fdf9b3e8 | bellard | return 0; |
232 | ea2b542a | aurel32 | if ((env->mmucr & 0x98000000) == 0x18000000) |
233 | fdf9b3e8 | bellard | return 1; |
234 | fdf9b3e8 | bellard | if ((env->mmucr & 0x54000000) == 0x04000000) |
235 | fdf9b3e8 | bellard | return 2; |
236 | fdf9b3e8 | bellard | if ((env->mmucr & 0x2c000000) == 0x00000000) |
237 | fdf9b3e8 | bellard | return 3; |
238 | 43dc2a64 | Blue Swirl | cpu_abort(env, "Unhandled itlb_replacement");
|
239 | fdf9b3e8 | bellard | } |
240 | fdf9b3e8 | bellard | |
241 | fdf9b3e8 | bellard | /* Find the corresponding entry in the right TLB
|
242 | fdf9b3e8 | bellard | Return entry, MMU_DTLB_MISS or MMU_DTLB_MULTIPLE
|
243 | fdf9b3e8 | bellard | */
|
244 | fdf9b3e8 | bellard | static int find_tlb_entry(CPUState * env, target_ulong address, |
245 | fdf9b3e8 | bellard | tlb_t * entries, uint8_t nbtlb, int use_asid)
|
246 | fdf9b3e8 | bellard | { |
247 | fdf9b3e8 | bellard | int match = MMU_DTLB_MISS;
|
248 | fdf9b3e8 | bellard | uint32_t start, end; |
249 | fdf9b3e8 | bellard | uint8_t asid; |
250 | fdf9b3e8 | bellard | int i;
|
251 | fdf9b3e8 | bellard | |
252 | fdf9b3e8 | bellard | asid = env->pteh & 0xff;
|
253 | fdf9b3e8 | bellard | |
254 | fdf9b3e8 | bellard | for (i = 0; i < nbtlb; i++) { |
255 | fdf9b3e8 | bellard | if (!entries[i].v)
|
256 | fdf9b3e8 | bellard | continue; /* Invalid entry */ |
257 | eeda6778 | aurel32 | if (!entries[i].sh && use_asid && entries[i].asid != asid)
|
258 | fdf9b3e8 | bellard | continue; /* Bad ASID */ |
259 | fdf9b3e8 | bellard | start = (entries[i].vpn << 10) & ~(entries[i].size - 1); |
260 | fdf9b3e8 | bellard | end = start + entries[i].size - 1;
|
261 | fdf9b3e8 | bellard | if (address >= start && address <= end) { /* Match */ |
262 | ea2b542a | aurel32 | if (match != MMU_DTLB_MISS)
|
263 | fdf9b3e8 | bellard | return MMU_DTLB_MULTIPLE; /* Multiple match */ |
264 | fdf9b3e8 | bellard | match = i; |
265 | fdf9b3e8 | bellard | } |
266 | fdf9b3e8 | bellard | } |
267 | fdf9b3e8 | bellard | return match;
|
268 | fdf9b3e8 | bellard | } |
269 | fdf9b3e8 | bellard | |
270 | 29e179bc | aurel32 | static void increment_urc(CPUState * env) |
271 | 29e179bc | aurel32 | { |
272 | 29e179bc | aurel32 | uint8_t urb, urc; |
273 | 29e179bc | aurel32 | |
274 | 29e179bc | aurel32 | /* Increment URC */
|
275 | 29e179bc | aurel32 | urb = ((env->mmucr) >> 18) & 0x3f; |
276 | 29e179bc | aurel32 | urc = ((env->mmucr) >> 10) & 0x3f; |
277 | 29e179bc | aurel32 | urc++; |
278 | 927e3a4e | aurel32 | if ((urb > 0 && urc > urb) || urc > (UTLB_SIZE - 1)) |
279 | 29e179bc | aurel32 | urc = 0;
|
280 | 29e179bc | aurel32 | env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10); |
281 | 29e179bc | aurel32 | } |
282 | 29e179bc | aurel32 | |
283 | 829a4927 | Aurelien Jarno | /* Copy and utlb entry into itlb
|
284 | 829a4927 | Aurelien Jarno | Return entry
|
285 | 829a4927 | Aurelien Jarno | */
|
286 | 829a4927 | Aurelien Jarno | static int copy_utlb_entry_itlb(CPUState *env, int utlb) |
287 | 829a4927 | Aurelien Jarno | { |
288 | 829a4927 | Aurelien Jarno | int itlb;
|
289 | 829a4927 | Aurelien Jarno | |
290 | 829a4927 | Aurelien Jarno | tlb_t * ientry; |
291 | 829a4927 | Aurelien Jarno | itlb = itlb_replacement(env); |
292 | 829a4927 | Aurelien Jarno | ientry = &env->itlb[itlb]; |
293 | 829a4927 | Aurelien Jarno | if (ientry->v) {
|
294 | 829a4927 | Aurelien Jarno | tlb_flush_page(env, ientry->vpn << 10);
|
295 | 829a4927 | Aurelien Jarno | } |
296 | 829a4927 | Aurelien Jarno | *ientry = env->utlb[utlb]; |
297 | 829a4927 | Aurelien Jarno | update_itlb_use(env, itlb); |
298 | 829a4927 | Aurelien Jarno | return itlb;
|
299 | 829a4927 | Aurelien Jarno | } |
300 | 829a4927 | Aurelien Jarno | |
301 | 829a4927 | Aurelien Jarno | /* Find itlb entry
|
302 | fdf9b3e8 | bellard | Return entry, MMU_ITLB_MISS, MMU_ITLB_MULTIPLE or MMU_DTLB_MULTIPLE
|
303 | fdf9b3e8 | bellard | */
|
304 | ef7ec1c1 | aurel32 | static int find_itlb_entry(CPUState * env, target_ulong address, |
305 | 829a4927 | Aurelien Jarno | int use_asid)
|
306 | fdf9b3e8 | bellard | { |
307 | 829a4927 | Aurelien Jarno | int e;
|
308 | fdf9b3e8 | bellard | |
309 | fdf9b3e8 | bellard | e = find_tlb_entry(env, address, env->itlb, ITLB_SIZE, use_asid); |
310 | 829a4927 | Aurelien Jarno | if (e == MMU_DTLB_MULTIPLE) {
|
311 | fdf9b3e8 | bellard | e = MMU_ITLB_MULTIPLE; |
312 | 829a4927 | Aurelien Jarno | } else if (e == MMU_DTLB_MISS) { |
313 | ea2b542a | aurel32 | e = MMU_ITLB_MISS; |
314 | 829a4927 | Aurelien Jarno | } else if (e >= 0) { |
315 | fdf9b3e8 | bellard | update_itlb_use(env, e); |
316 | 829a4927 | Aurelien Jarno | } |
317 | fdf9b3e8 | bellard | return e;
|
318 | fdf9b3e8 | bellard | } |
319 | fdf9b3e8 | bellard | |
320 | fdf9b3e8 | bellard | /* Find utlb entry
|
321 | fdf9b3e8 | bellard | Return entry, MMU_DTLB_MISS, MMU_DTLB_MULTIPLE */
|
322 | ef7ec1c1 | aurel32 | static int find_utlb_entry(CPUState * env, target_ulong address, int use_asid) |
323 | fdf9b3e8 | bellard | { |
324 | 29e179bc | aurel32 | /* per utlb access */
|
325 | 29e179bc | aurel32 | increment_urc(env); |
326 | fdf9b3e8 | bellard | |
327 | fdf9b3e8 | bellard | /* Return entry */
|
328 | fdf9b3e8 | bellard | return find_tlb_entry(env, address, env->utlb, UTLB_SIZE, use_asid);
|
329 | fdf9b3e8 | bellard | } |
330 | fdf9b3e8 | bellard | |
331 | fdf9b3e8 | bellard | /* Match address against MMU
|
332 | fdf9b3e8 | bellard | Return MMU_OK, MMU_DTLB_MISS_READ, MMU_DTLB_MISS_WRITE,
|
333 | fdf9b3e8 | bellard | MMU_DTLB_INITIAL_WRITE, MMU_DTLB_VIOLATION_READ,
|
334 | fdf9b3e8 | bellard | MMU_DTLB_VIOLATION_WRITE, MMU_ITLB_MISS,
|
335 | cf7055bd | aurel32 | MMU_ITLB_MULTIPLE, MMU_ITLB_VIOLATION,
|
336 | cf7055bd | aurel32 | MMU_IADDR_ERROR, MMU_DADDR_ERROR_READ, MMU_DADDR_ERROR_WRITE.
|
337 | fdf9b3e8 | bellard | */
|
338 | fdf9b3e8 | bellard | static int get_mmu_address(CPUState * env, target_ulong * physical, |
339 | fdf9b3e8 | bellard | int *prot, target_ulong address,
|
340 | fdf9b3e8 | bellard | int rw, int access_type) |
341 | fdf9b3e8 | bellard | { |
342 | cf7055bd | aurel32 | int use_asid, n;
|
343 | fdf9b3e8 | bellard | tlb_t *matching = NULL;
|
344 | fdf9b3e8 | bellard | |
345 | 06afe2c8 | aurel32 | use_asid = (env->mmucr & MMUCR_SV) == 0 || (env->sr & SR_MD) == 0; |
346 | fdf9b3e8 | bellard | |
347 | cf7055bd | aurel32 | if (rw == 2) { |
348 | 829a4927 | Aurelien Jarno | n = find_itlb_entry(env, address, use_asid); |
349 | fdf9b3e8 | bellard | if (n >= 0) { |
350 | fdf9b3e8 | bellard | matching = &env->itlb[n]; |
351 | 4d1e4ff6 | Aurelien Jarno | if (!(env->sr & SR_MD) && !(matching->pr & 2)) |
352 | fdf9b3e8 | bellard | n = MMU_ITLB_VIOLATION; |
353 | fdf9b3e8 | bellard | else
|
354 | 5a25cc2b | Aurelien Jarno | *prot = PAGE_EXEC; |
355 | 829a4927 | Aurelien Jarno | } else {
|
356 | 829a4927 | Aurelien Jarno | n = find_utlb_entry(env, address, use_asid); |
357 | 829a4927 | Aurelien Jarno | if (n >= 0) { |
358 | 829a4927 | Aurelien Jarno | n = copy_utlb_entry_itlb(env, n); |
359 | 829a4927 | Aurelien Jarno | matching = &env->itlb[n]; |
360 | 829a4927 | Aurelien Jarno | if (!(env->sr & SR_MD) && !(matching->pr & 2)) { |
361 | 829a4927 | Aurelien Jarno | n = MMU_ITLB_VIOLATION; |
362 | 829a4927 | Aurelien Jarno | } else {
|
363 | 829a4927 | Aurelien Jarno | *prot = PAGE_READ | PAGE_EXEC; |
364 | 829a4927 | Aurelien Jarno | if ((matching->pr & 1) && matching->d) { |
365 | 829a4927 | Aurelien Jarno | *prot |= PAGE_WRITE; |
366 | 829a4927 | Aurelien Jarno | } |
367 | 829a4927 | Aurelien Jarno | } |
368 | 829a4927 | Aurelien Jarno | } else if (n == MMU_DTLB_MULTIPLE) { |
369 | 829a4927 | Aurelien Jarno | n = MMU_ITLB_MULTIPLE; |
370 | 829a4927 | Aurelien Jarno | } else if (n == MMU_DTLB_MISS) { |
371 | 829a4927 | Aurelien Jarno | n = MMU_ITLB_MISS; |
372 | 829a4927 | Aurelien Jarno | } |
373 | fdf9b3e8 | bellard | } |
374 | fdf9b3e8 | bellard | } else {
|
375 | fdf9b3e8 | bellard | n = find_utlb_entry(env, address, use_asid); |
376 | fdf9b3e8 | bellard | if (n >= 0) { |
377 | fdf9b3e8 | bellard | matching = &env->utlb[n]; |
378 | 628b61a0 | Aurelien Jarno | if (!(env->sr & SR_MD) && !(matching->pr & 2)) { |
379 | 628b61a0 | Aurelien Jarno | n = (rw == 1) ? MMU_DTLB_VIOLATION_WRITE :
|
380 | 628b61a0 | Aurelien Jarno | MMU_DTLB_VIOLATION_READ; |
381 | 628b61a0 | Aurelien Jarno | } else if ((rw == 1) && !(matching->pr & 1)) { |
382 | 628b61a0 | Aurelien Jarno | n = MMU_DTLB_VIOLATION_WRITE; |
383 | 628b61a0 | Aurelien Jarno | } else if ((rw == 1) & !matching->d) { |
384 | 628b61a0 | Aurelien Jarno | n = MMU_DTLB_INITIAL_WRITE; |
385 | 628b61a0 | Aurelien Jarno | } else {
|
386 | 628b61a0 | Aurelien Jarno | *prot = PAGE_READ; |
387 | 628b61a0 | Aurelien Jarno | if ((matching->pr & 1) && matching->d) { |
388 | 628b61a0 | Aurelien Jarno | *prot |= PAGE_WRITE; |
389 | 628b61a0 | Aurelien Jarno | } |
390 | 628b61a0 | Aurelien Jarno | } |
391 | fdf9b3e8 | bellard | } else if (n == MMU_DTLB_MISS) { |
392 | cf7055bd | aurel32 | n = (rw == 1) ? MMU_DTLB_MISS_WRITE :
|
393 | fdf9b3e8 | bellard | MMU_DTLB_MISS_READ; |
394 | fdf9b3e8 | bellard | } |
395 | fdf9b3e8 | bellard | } |
396 | fdf9b3e8 | bellard | if (n >= 0) { |
397 | 628b61a0 | Aurelien Jarno | n = MMU_OK; |
398 | fdf9b3e8 | bellard | *physical = ((matching->ppn << 10) & ~(matching->size - 1)) | |
399 | fdf9b3e8 | bellard | (address & (matching->size - 1));
|
400 | fdf9b3e8 | bellard | } |
401 | fdf9b3e8 | bellard | return n;
|
402 | fdf9b3e8 | bellard | } |
403 | fdf9b3e8 | bellard | |
404 | ef7ec1c1 | aurel32 | static int get_physical_address(CPUState * env, target_ulong * physical, |
405 | ef7ec1c1 | aurel32 | int *prot, target_ulong address,
|
406 | ef7ec1c1 | aurel32 | int rw, int access_type) |
407 | fdf9b3e8 | bellard | { |
408 | fdf9b3e8 | bellard | /* P1, P2 and P4 areas do not use translation */
|
409 | fdf9b3e8 | bellard | if ((address >= 0x80000000 && address < 0xc0000000) || |
410 | fdf9b3e8 | bellard | address >= 0xe0000000) {
|
411 | fdf9b3e8 | bellard | if (!(env->sr & SR_MD)
|
412 | 03e3b61e | Aurelien Jarno | && (address < 0xe0000000 || address >= 0xe4000000)) { |
413 | fdf9b3e8 | bellard | /* Unauthorized access in user mode (only store queues are available) */
|
414 | fdf9b3e8 | bellard | fprintf(stderr, "Unauthorized access\n");
|
415 | cf7055bd | aurel32 | if (rw == 0) |
416 | cf7055bd | aurel32 | return MMU_DADDR_ERROR_READ;
|
417 | cf7055bd | aurel32 | else if (rw == 1) |
418 | cf7055bd | aurel32 | return MMU_DADDR_ERROR_WRITE;
|
419 | cf7055bd | aurel32 | else
|
420 | cf7055bd | aurel32 | return MMU_IADDR_ERROR;
|
421 | fdf9b3e8 | bellard | } |
422 | 29e179bc | aurel32 | if (address >= 0x80000000 && address < 0xc0000000) { |
423 | 29e179bc | aurel32 | /* Mask upper 3 bits for P1 and P2 areas */
|
424 | 29e179bc | aurel32 | *physical = address & 0x1fffffff;
|
425 | 29e179bc | aurel32 | } else {
|
426 | 29e179bc | aurel32 | *physical = address; |
427 | 29e179bc | aurel32 | } |
428 | 5a25cc2b | Aurelien Jarno | *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; |
429 | fdf9b3e8 | bellard | return MMU_OK;
|
430 | fdf9b3e8 | bellard | } |
431 | fdf9b3e8 | bellard | |
432 | fdf9b3e8 | bellard | /* If MMU is disabled, return the corresponding physical page */
|
433 | fdf9b3e8 | bellard | if (!env->mmucr & MMUCR_AT) {
|
434 | fdf9b3e8 | bellard | *physical = address & 0x1FFFFFFF;
|
435 | 5a25cc2b | Aurelien Jarno | *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; |
436 | fdf9b3e8 | bellard | return MMU_OK;
|
437 | fdf9b3e8 | bellard | } |
438 | fdf9b3e8 | bellard | |
439 | fdf9b3e8 | bellard | /* We need to resort to the MMU */
|
440 | fdf9b3e8 | bellard | return get_mmu_address(env, physical, prot, address, rw, access_type);
|
441 | fdf9b3e8 | bellard | } |
442 | fdf9b3e8 | bellard | |
443 | fdf9b3e8 | bellard | int cpu_sh4_handle_mmu_fault(CPUState * env, target_ulong address, int rw, |
444 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu) |
445 | fdf9b3e8 | bellard | { |
446 | 0f3f1ec7 | Aurelien Jarno | target_ulong physical; |
447 | fdf9b3e8 | bellard | int prot, ret, access_type;
|
448 | fdf9b3e8 | bellard | |
449 | fdf9b3e8 | bellard | access_type = ACCESS_INT; |
450 | fdf9b3e8 | bellard | ret = |
451 | fdf9b3e8 | bellard | get_physical_address(env, &physical, &prot, address, rw, |
452 | fdf9b3e8 | bellard | access_type); |
453 | fdf9b3e8 | bellard | |
454 | fdf9b3e8 | bellard | if (ret != MMU_OK) {
|
455 | fdf9b3e8 | bellard | env->tea = address; |
456 | fdf9b3e8 | bellard | switch (ret) {
|
457 | fdf9b3e8 | bellard | case MMU_ITLB_MISS:
|
458 | fdf9b3e8 | bellard | case MMU_DTLB_MISS_READ:
|
459 | fdf9b3e8 | bellard | env->exception_index = 0x040;
|
460 | fdf9b3e8 | bellard | break;
|
461 | fdf9b3e8 | bellard | case MMU_DTLB_MULTIPLE:
|
462 | fdf9b3e8 | bellard | case MMU_ITLB_MULTIPLE:
|
463 | fdf9b3e8 | bellard | env->exception_index = 0x140;
|
464 | fdf9b3e8 | bellard | break;
|
465 | fdf9b3e8 | bellard | case MMU_ITLB_VIOLATION:
|
466 | fdf9b3e8 | bellard | env->exception_index = 0x0a0;
|
467 | fdf9b3e8 | bellard | break;
|
468 | fdf9b3e8 | bellard | case MMU_DTLB_MISS_WRITE:
|
469 | fdf9b3e8 | bellard | env->exception_index = 0x060;
|
470 | fdf9b3e8 | bellard | break;
|
471 | fdf9b3e8 | bellard | case MMU_DTLB_INITIAL_WRITE:
|
472 | fdf9b3e8 | bellard | env->exception_index = 0x080;
|
473 | fdf9b3e8 | bellard | break;
|
474 | fdf9b3e8 | bellard | case MMU_DTLB_VIOLATION_READ:
|
475 | fdf9b3e8 | bellard | env->exception_index = 0x0a0;
|
476 | fdf9b3e8 | bellard | break;
|
477 | fdf9b3e8 | bellard | case MMU_DTLB_VIOLATION_WRITE:
|
478 | fdf9b3e8 | bellard | env->exception_index = 0x0c0;
|
479 | fdf9b3e8 | bellard | break;
|
480 | cf7055bd | aurel32 | case MMU_IADDR_ERROR:
|
481 | cf7055bd | aurel32 | case MMU_DADDR_ERROR_READ:
|
482 | cf7055bd | aurel32 | env->exception_index = 0x0c0;
|
483 | cf7055bd | aurel32 | break;
|
484 | cf7055bd | aurel32 | case MMU_DADDR_ERROR_WRITE:
|
485 | cf7055bd | aurel32 | env->exception_index = 0x100;
|
486 | cf7055bd | aurel32 | break;
|
487 | fdf9b3e8 | bellard | default:
|
488 | 43dc2a64 | Blue Swirl | cpu_abort(env, "Unhandled MMU fault");
|
489 | fdf9b3e8 | bellard | } |
490 | fdf9b3e8 | bellard | return 1; |
491 | fdf9b3e8 | bellard | } |
492 | fdf9b3e8 | bellard | |
493 | 0f3f1ec7 | Aurelien Jarno | address &= TARGET_PAGE_MASK; |
494 | 0f3f1ec7 | Aurelien Jarno | physical &= TARGET_PAGE_MASK; |
495 | fdf9b3e8 | bellard | |
496 | d4c430a8 | Paul Brook | tlb_set_page(env, address, physical, prot, mmu_idx, TARGET_PAGE_SIZE); |
497 | d4c430a8 | Paul Brook | return 0; |
498 | fdf9b3e8 | bellard | } |
499 | 355fb23d | pbrook | |
500 | c227f099 | Anthony Liguori | target_phys_addr_t cpu_get_phys_page_debug(CPUState * env, target_ulong addr) |
501 | 355fb23d | pbrook | { |
502 | 355fb23d | pbrook | target_ulong physical; |
503 | 355fb23d | pbrook | int prot;
|
504 | 355fb23d | pbrook | |
505 | cf7055bd | aurel32 | get_physical_address(env, &physical, &prot, addr, 0, 0); |
506 | 355fb23d | pbrook | return physical;
|
507 | 355fb23d | pbrook | } |
508 | 355fb23d | pbrook | |
509 | ef7ec1c1 | aurel32 | void cpu_load_tlb(CPUSH4State * env)
|
510 | ea2b542a | aurel32 | { |
511 | ea2b542a | aurel32 | int n = cpu_mmucr_urc(env->mmucr);
|
512 | ea2b542a | aurel32 | tlb_t * entry = &env->utlb[n]; |
513 | ea2b542a | aurel32 | |
514 | 06afe2c8 | aurel32 | if (entry->v) {
|
515 | 06afe2c8 | aurel32 | /* Overwriting valid entry in utlb. */
|
516 | 06afe2c8 | aurel32 | target_ulong address = entry->vpn << 10;
|
517 | 5a25cc2b | Aurelien Jarno | tlb_flush_page(env, address); |
518 | 06afe2c8 | aurel32 | } |
519 | 06afe2c8 | aurel32 | |
520 | ea2b542a | aurel32 | /* Take values into cpu status from registers. */
|
521 | ea2b542a | aurel32 | entry->asid = (uint8_t)cpu_pteh_asid(env->pteh); |
522 | ea2b542a | aurel32 | entry->vpn = cpu_pteh_vpn(env->pteh); |
523 | ea2b542a | aurel32 | entry->v = (uint8_t)cpu_ptel_v(env->ptel); |
524 | ea2b542a | aurel32 | entry->ppn = cpu_ptel_ppn(env->ptel); |
525 | ea2b542a | aurel32 | entry->sz = (uint8_t)cpu_ptel_sz(env->ptel); |
526 | ea2b542a | aurel32 | switch (entry->sz) {
|
527 | ea2b542a | aurel32 | case 0: /* 00 */ |
528 | ea2b542a | aurel32 | entry->size = 1024; /* 1K */ |
529 | ea2b542a | aurel32 | break;
|
530 | ea2b542a | aurel32 | case 1: /* 01 */ |
531 | ea2b542a | aurel32 | entry->size = 1024 * 4; /* 4K */ |
532 | ea2b542a | aurel32 | break;
|
533 | ea2b542a | aurel32 | case 2: /* 10 */ |
534 | ea2b542a | aurel32 | entry->size = 1024 * 64; /* 64K */ |
535 | ea2b542a | aurel32 | break;
|
536 | ea2b542a | aurel32 | case 3: /* 11 */ |
537 | ea2b542a | aurel32 | entry->size = 1024 * 1024; /* 1M */ |
538 | ea2b542a | aurel32 | break;
|
539 | ea2b542a | aurel32 | default:
|
540 | 43dc2a64 | Blue Swirl | cpu_abort(env, "Unhandled load_tlb");
|
541 | ea2b542a | aurel32 | break;
|
542 | ea2b542a | aurel32 | } |
543 | ea2b542a | aurel32 | entry->sh = (uint8_t)cpu_ptel_sh(env->ptel); |
544 | ea2b542a | aurel32 | entry->c = (uint8_t)cpu_ptel_c(env->ptel); |
545 | ea2b542a | aurel32 | entry->pr = (uint8_t)cpu_ptel_pr(env->ptel); |
546 | ea2b542a | aurel32 | entry->d = (uint8_t)cpu_ptel_d(env->ptel); |
547 | ea2b542a | aurel32 | entry->wt = (uint8_t)cpu_ptel_wt(env->ptel); |
548 | ea2b542a | aurel32 | entry->sa = (uint8_t)cpu_ptea_sa(env->ptea); |
549 | ea2b542a | aurel32 | entry->tc = (uint8_t)cpu_ptea_tc(env->ptea); |
550 | ea2b542a | aurel32 | } |
551 | ea2b542a | aurel32 | |
552 | e0bcb9ca | Aurelien Jarno | void cpu_sh4_invalidate_tlb(CPUSH4State *s)
|
553 | e0bcb9ca | Aurelien Jarno | { |
554 | e0bcb9ca | Aurelien Jarno | int i;
|
555 | e0bcb9ca | Aurelien Jarno | |
556 | e0bcb9ca | Aurelien Jarno | /* UTLB */
|
557 | e0bcb9ca | Aurelien Jarno | for (i = 0; i < UTLB_SIZE; i++) { |
558 | e0bcb9ca | Aurelien Jarno | tlb_t * entry = &s->utlb[i]; |
559 | e0bcb9ca | Aurelien Jarno | entry->v = 0;
|
560 | e0bcb9ca | Aurelien Jarno | } |
561 | e0bcb9ca | Aurelien Jarno | /* ITLB */
|
562 | e0bcb9ca | Aurelien Jarno | for (i = 0; i < UTLB_SIZE; i++) { |
563 | e0bcb9ca | Aurelien Jarno | tlb_t * entry = &s->utlb[i]; |
564 | e0bcb9ca | Aurelien Jarno | entry->v = 0;
|
565 | e0bcb9ca | Aurelien Jarno | } |
566 | e0bcb9ca | Aurelien Jarno | |
567 | e0bcb9ca | Aurelien Jarno | tlb_flush(s, 1);
|
568 | e0bcb9ca | Aurelien Jarno | } |
569 | e0bcb9ca | Aurelien Jarno | |
570 | c0f809c4 | Aurelien Jarno | void cpu_sh4_write_mmaped_itlb_addr(CPUSH4State *s, target_phys_addr_t addr,
|
571 | c0f809c4 | Aurelien Jarno | uint32_t mem_value) |
572 | c0f809c4 | Aurelien Jarno | { |
573 | c0f809c4 | Aurelien Jarno | uint32_t vpn = (mem_value & 0xfffffc00) >> 10; |
574 | c0f809c4 | Aurelien Jarno | uint8_t v = (uint8_t)((mem_value & 0x00000100) >> 8); |
575 | c0f809c4 | Aurelien Jarno | uint8_t asid = (uint8_t)(mem_value & 0x000000ff);
|
576 | c0f809c4 | Aurelien Jarno | |
577 | c0f809c4 | Aurelien Jarno | int index = (addr & 0x00003f00) >> 8; |
578 | c0f809c4 | Aurelien Jarno | tlb_t * entry = &s->itlb[index]; |
579 | c0f809c4 | Aurelien Jarno | if (entry->v) {
|
580 | c0f809c4 | Aurelien Jarno | /* Overwriting valid entry in itlb. */
|
581 | c0f809c4 | Aurelien Jarno | target_ulong address = entry->vpn << 10;
|
582 | c0f809c4 | Aurelien Jarno | tlb_flush_page(s, address); |
583 | c0f809c4 | Aurelien Jarno | } |
584 | c0f809c4 | Aurelien Jarno | entry->asid = asid; |
585 | c0f809c4 | Aurelien Jarno | entry->vpn = vpn; |
586 | c0f809c4 | Aurelien Jarno | entry->v = v; |
587 | c0f809c4 | Aurelien Jarno | } |
588 | c0f809c4 | Aurelien Jarno | |
589 | c227f099 | Anthony Liguori | void cpu_sh4_write_mmaped_utlb_addr(CPUSH4State *s, target_phys_addr_t addr,
|
590 | 29e179bc | aurel32 | uint32_t mem_value) |
591 | 29e179bc | aurel32 | { |
592 | 29e179bc | aurel32 | int associate = addr & 0x0000080; |
593 | 29e179bc | aurel32 | uint32_t vpn = (mem_value & 0xfffffc00) >> 10; |
594 | 29e179bc | aurel32 | uint8_t d = (uint8_t)((mem_value & 0x00000200) >> 9); |
595 | 29e179bc | aurel32 | uint8_t v = (uint8_t)((mem_value & 0x00000100) >> 8); |
596 | 29e179bc | aurel32 | uint8_t asid = (uint8_t)(mem_value & 0x000000ff);
|
597 | eeda6778 | aurel32 | int use_asid = (s->mmucr & MMUCR_SV) == 0 || (s->sr & SR_MD) == 0; |
598 | 29e179bc | aurel32 | |
599 | 29e179bc | aurel32 | if (associate) {
|
600 | 29e179bc | aurel32 | int i;
|
601 | 29e179bc | aurel32 | tlb_t * utlb_match_entry = NULL;
|
602 | 29e179bc | aurel32 | int needs_tlb_flush = 0; |
603 | 29e179bc | aurel32 | |
604 | 29e179bc | aurel32 | /* search UTLB */
|
605 | 29e179bc | aurel32 | for (i = 0; i < UTLB_SIZE; i++) { |
606 | 29e179bc | aurel32 | tlb_t * entry = &s->utlb[i]; |
607 | 29e179bc | aurel32 | if (!entry->v)
|
608 | 29e179bc | aurel32 | continue;
|
609 | 29e179bc | aurel32 | |
610 | eeda6778 | aurel32 | if (entry->vpn == vpn
|
611 | eeda6778 | aurel32 | && (!use_asid || entry->asid == asid || entry->sh)) { |
612 | 29e179bc | aurel32 | if (utlb_match_entry) {
|
613 | 29e179bc | aurel32 | /* Multiple TLB Exception */
|
614 | 29e179bc | aurel32 | s->exception_index = 0x140;
|
615 | 29e179bc | aurel32 | s->tea = addr; |
616 | 29e179bc | aurel32 | break;
|
617 | 29e179bc | aurel32 | } |
618 | 29e179bc | aurel32 | if (entry->v && !v)
|
619 | 29e179bc | aurel32 | needs_tlb_flush = 1;
|
620 | 29e179bc | aurel32 | entry->v = v; |
621 | 29e179bc | aurel32 | entry->d = d; |
622 | 29e179bc | aurel32 | utlb_match_entry = entry; |
623 | 29e179bc | aurel32 | } |
624 | 29e179bc | aurel32 | increment_urc(s); /* per utlb access */
|
625 | 29e179bc | aurel32 | } |
626 | 29e179bc | aurel32 | |
627 | 29e179bc | aurel32 | /* search ITLB */
|
628 | 29e179bc | aurel32 | for (i = 0; i < ITLB_SIZE; i++) { |
629 | 29e179bc | aurel32 | tlb_t * entry = &s->itlb[i]; |
630 | eeda6778 | aurel32 | if (entry->vpn == vpn
|
631 | eeda6778 | aurel32 | && (!use_asid || entry->asid == asid || entry->sh)) { |
632 | 29e179bc | aurel32 | if (entry->v && !v)
|
633 | 29e179bc | aurel32 | needs_tlb_flush = 1;
|
634 | 29e179bc | aurel32 | if (utlb_match_entry)
|
635 | 29e179bc | aurel32 | *entry = *utlb_match_entry; |
636 | 29e179bc | aurel32 | else
|
637 | 29e179bc | aurel32 | entry->v = v; |
638 | 29e179bc | aurel32 | break;
|
639 | 29e179bc | aurel32 | } |
640 | 29e179bc | aurel32 | } |
641 | 29e179bc | aurel32 | |
642 | 29e179bc | aurel32 | if (needs_tlb_flush)
|
643 | 29e179bc | aurel32 | tlb_flush_page(s, vpn << 10);
|
644 | 29e179bc | aurel32 | |
645 | 29e179bc | aurel32 | } else {
|
646 | 29e179bc | aurel32 | int index = (addr & 0x00003f00) >> 8; |
647 | 29e179bc | aurel32 | tlb_t * entry = &s->utlb[index]; |
648 | 29e179bc | aurel32 | if (entry->v) {
|
649 | 29e179bc | aurel32 | /* Overwriting valid entry in utlb. */
|
650 | 29e179bc | aurel32 | target_ulong address = entry->vpn << 10;
|
651 | 5a25cc2b | Aurelien Jarno | tlb_flush_page(s, address); |
652 | 29e179bc | aurel32 | } |
653 | 29e179bc | aurel32 | entry->asid = asid; |
654 | 29e179bc | aurel32 | entry->vpn = vpn; |
655 | 29e179bc | aurel32 | entry->d = d; |
656 | 29e179bc | aurel32 | entry->v = v; |
657 | 29e179bc | aurel32 | increment_urc(s); |
658 | 29e179bc | aurel32 | } |
659 | 29e179bc | aurel32 | } |
660 | 29e179bc | aurel32 | |
661 | 852d481f | edgar_igl | int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr)
|
662 | 852d481f | edgar_igl | { |
663 | 852d481f | edgar_igl | int n;
|
664 | 852d481f | edgar_igl | int use_asid = (env->mmucr & MMUCR_SV) == 0 || (env->sr & SR_MD) == 0; |
665 | 852d481f | edgar_igl | |
666 | 852d481f | edgar_igl | /* check area */
|
667 | 852d481f | edgar_igl | if (env->sr & SR_MD) {
|
668 | 852d481f | edgar_igl | /* For previledged mode, P2 and P4 area is not cachable. */
|
669 | 852d481f | edgar_igl | if ((0xA0000000 <= addr && addr < 0xC0000000) || 0xE0000000 <= addr) |
670 | 852d481f | edgar_igl | return 0; |
671 | 852d481f | edgar_igl | } else {
|
672 | 852d481f | edgar_igl | /* For user mode, only U0 area is cachable. */
|
673 | 852d481f | edgar_igl | if (0x80000000 <= addr) |
674 | 852d481f | edgar_igl | return 0; |
675 | 852d481f | edgar_igl | } |
676 | 852d481f | edgar_igl | |
677 | 852d481f | edgar_igl | /*
|
678 | 852d481f | edgar_igl | * TODO : Evaluate CCR and check if the cache is on or off.
|
679 | 852d481f | edgar_igl | * Now CCR is not in CPUSH4State, but in SH7750State.
|
680 | 852d481f | edgar_igl | * When you move the ccr inot CPUSH4State, the code will be
|
681 | 852d481f | edgar_igl | * as follows.
|
682 | 852d481f | edgar_igl | */
|
683 | 852d481f | edgar_igl | #if 0
|
684 | 852d481f | edgar_igl | /* check if operand cache is enabled or not. */
|
685 | 852d481f | edgar_igl | if (!(env->ccr & 1))
|
686 | 852d481f | edgar_igl | return 0;
|
687 | 852d481f | edgar_igl | #endif
|
688 | 852d481f | edgar_igl | |
689 | 852d481f | edgar_igl | /* if MMU is off, no check for TLB. */
|
690 | 852d481f | edgar_igl | if (env->mmucr & MMUCR_AT)
|
691 | 852d481f | edgar_igl | return 1; |
692 | 852d481f | edgar_igl | |
693 | 852d481f | edgar_igl | /* check TLB */
|
694 | 852d481f | edgar_igl | n = find_tlb_entry(env, addr, env->itlb, ITLB_SIZE, use_asid); |
695 | 852d481f | edgar_igl | if (n >= 0) |
696 | 852d481f | edgar_igl | return env->itlb[n].c;
|
697 | 852d481f | edgar_igl | |
698 | 852d481f | edgar_igl | n = find_tlb_entry(env, addr, env->utlb, UTLB_SIZE, use_asid); |
699 | 852d481f | edgar_igl | if (n >= 0) |
700 | 852d481f | edgar_igl | return env->utlb[n].c;
|
701 | 852d481f | edgar_igl | |
702 | 852d481f | edgar_igl | return 0; |
703 | 852d481f | edgar_igl | } |
704 | 852d481f | edgar_igl | |
705 | 355fb23d | pbrook | #endif |