root / target-ppc / helper.c @ fa3966a3
History | View | Annotate | Download (93.7 kB)
1 | 79aceca5 | bellard | /*
|
---|---|---|---|
2 | 3fc6c082 | bellard | * PowerPC emulation helpers for qemu.
|
3 | 5fafdf24 | ths | *
|
4 | 76a66253 | j_mayer | * Copyright (c) 2003-2007 Jocelyn Mayer
|
5 | 79aceca5 | bellard | *
|
6 | 79aceca5 | bellard | * This library is free software; you can redistribute it and/or
|
7 | 79aceca5 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 79aceca5 | bellard | * License as published by the Free Software Foundation; either
|
9 | 79aceca5 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 79aceca5 | bellard | *
|
11 | 79aceca5 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 79aceca5 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 79aceca5 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 79aceca5 | bellard | * Lesser General Public License for more details.
|
15 | 79aceca5 | bellard | *
|
16 | 79aceca5 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 79aceca5 | bellard | * License along with this library; if not, write to the Free Software
|
18 | fad6cb1a | aurel32 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
|
19 | 79aceca5 | bellard | */
|
20 | fdabc366 | bellard | #include <stdarg.h> |
21 | fdabc366 | bellard | #include <stdlib.h> |
22 | fdabc366 | bellard | #include <stdio.h> |
23 | fdabc366 | bellard | #include <string.h> |
24 | fdabc366 | bellard | #include <inttypes.h> |
25 | fdabc366 | bellard | #include <signal.h> |
26 | fdabc366 | bellard | #include <assert.h> |
27 | fdabc366 | bellard | |
28 | fdabc366 | bellard | #include "cpu.h" |
29 | fdabc366 | bellard | #include "exec-all.h" |
30 | 0411a972 | j_mayer | #include "helper_regs.h" |
31 | ca10f867 | aurel32 | #include "qemu-common.h" |
32 | d76d1650 | aurel32 | #include "kvm.h" |
33 | 9a64fbe4 | bellard | |
34 | 9a64fbe4 | bellard | //#define DEBUG_MMU
|
35 | 9a64fbe4 | bellard | //#define DEBUG_BATS
|
36 | 6b542af7 | j_mayer | //#define DEBUG_SLB
|
37 | 76a66253 | j_mayer | //#define DEBUG_SOFTWARE_TLB
|
38 | 0411a972 | j_mayer | //#define DUMP_PAGE_TABLES
|
39 | 9a64fbe4 | bellard | //#define DEBUG_EXCEPTIONS
|
40 | fdabc366 | bellard | //#define FLUSH_ALL_TLBS
|
41 | 9a64fbe4 | bellard | |
42 | d12d51d5 | aliguori | #ifdef DEBUG_MMU
|
43 | 93fcfe39 | aliguori | # define LOG_MMU(...) qemu_log(__VA_ARGS__)
|
44 | 93fcfe39 | aliguori | # define LOG_MMU_STATE(env) log_cpu_state((env), 0) |
45 | d12d51d5 | aliguori | #else
|
46 | d12d51d5 | aliguori | # define LOG_MMU(...) do { } while (0) |
47 | d12d51d5 | aliguori | # define LOG_MMU_STATE(...) do { } while (0) |
48 | d12d51d5 | aliguori | #endif
|
49 | d12d51d5 | aliguori | |
50 | d12d51d5 | aliguori | |
51 | d12d51d5 | aliguori | #ifdef DEBUG_SOFTWARE_TLB
|
52 | 93fcfe39 | aliguori | # define LOG_SWTLB(...) qemu_log(__VA_ARGS__)
|
53 | d12d51d5 | aliguori | #else
|
54 | d12d51d5 | aliguori | # define LOG_SWTLB(...) do { } while (0) |
55 | d12d51d5 | aliguori | #endif
|
56 | d12d51d5 | aliguori | |
57 | d12d51d5 | aliguori | #ifdef DEBUG_BATS
|
58 | 93fcfe39 | aliguori | # define LOG_BATS(...) qemu_log(__VA_ARGS__)
|
59 | d12d51d5 | aliguori | #else
|
60 | d12d51d5 | aliguori | # define LOG_BATS(...) do { } while (0) |
61 | d12d51d5 | aliguori | #endif
|
62 | d12d51d5 | aliguori | |
63 | d12d51d5 | aliguori | #ifdef DEBUG_SLB
|
64 | 93fcfe39 | aliguori | # define LOG_SLB(...) qemu_log(__VA_ARGS__)
|
65 | d12d51d5 | aliguori | #else
|
66 | d12d51d5 | aliguori | # define LOG_SLB(...) do { } while (0) |
67 | d12d51d5 | aliguori | #endif
|
68 | d12d51d5 | aliguori | |
69 | d12d51d5 | aliguori | #ifdef DEBUG_EXCEPTIONS
|
70 | 93fcfe39 | aliguori | # define LOG_EXCP(...) qemu_log(__VA_ARGS__)
|
71 | d12d51d5 | aliguori | #else
|
72 | d12d51d5 | aliguori | # define LOG_EXCP(...) do { } while (0) |
73 | d12d51d5 | aliguori | #endif
|
74 | d12d51d5 | aliguori | |
75 | d12d51d5 | aliguori | |
76 | 9a64fbe4 | bellard | /*****************************************************************************/
|
77 | 3fc6c082 | bellard | /* PowerPC MMU emulation */
|
78 | a541f297 | bellard | |
79 | d9bce9d9 | j_mayer | #if defined(CONFIG_USER_ONLY)
|
80 | e96efcfc | j_mayer | int cpu_ppc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, |
81 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu) |
82 | 24741ef3 | bellard | { |
83 | 24741ef3 | bellard | int exception, error_code;
|
84 | d9bce9d9 | j_mayer | |
85 | 24741ef3 | bellard | if (rw == 2) { |
86 | e1833e1f | j_mayer | exception = POWERPC_EXCP_ISI; |
87 | 8f793433 | j_mayer | error_code = 0x40000000;
|
88 | 24741ef3 | bellard | } else {
|
89 | e1833e1f | j_mayer | exception = POWERPC_EXCP_DSI; |
90 | 8f793433 | j_mayer | error_code = 0x40000000;
|
91 | 24741ef3 | bellard | if (rw)
|
92 | 24741ef3 | bellard | error_code |= 0x02000000;
|
93 | 24741ef3 | bellard | env->spr[SPR_DAR] = address; |
94 | 24741ef3 | bellard | env->spr[SPR_DSISR] = error_code; |
95 | 24741ef3 | bellard | } |
96 | 24741ef3 | bellard | env->exception_index = exception; |
97 | 24741ef3 | bellard | env->error_code = error_code; |
98 | 76a66253 | j_mayer | |
99 | 24741ef3 | bellard | return 1; |
100 | 24741ef3 | bellard | } |
101 | 76a66253 | j_mayer | |
102 | 9b3c35e0 | j_mayer | target_phys_addr_t cpu_get_phys_page_debug (CPUState *env, target_ulong addr) |
103 | 24741ef3 | bellard | { |
104 | 24741ef3 | bellard | return addr;
|
105 | 24741ef3 | bellard | } |
106 | 36081602 | j_mayer | |
107 | 24741ef3 | bellard | #else
|
108 | 76a66253 | j_mayer | /* Common routines used by software and hardware TLBs emulation */
|
109 | b068d6a7 | j_mayer | static always_inline int pte_is_valid (target_ulong pte0) |
110 | 76a66253 | j_mayer | { |
111 | 76a66253 | j_mayer | return pte0 & 0x80000000 ? 1 : 0; |
112 | 76a66253 | j_mayer | } |
113 | 76a66253 | j_mayer | |
114 | b068d6a7 | j_mayer | static always_inline void pte_invalidate (target_ulong *pte0) |
115 | 76a66253 | j_mayer | { |
116 | 76a66253 | j_mayer | *pte0 &= ~0x80000000;
|
117 | 76a66253 | j_mayer | } |
118 | 76a66253 | j_mayer | |
119 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
120 | b068d6a7 | j_mayer | static always_inline int pte64_is_valid (target_ulong pte0) |
121 | caa4039c | j_mayer | { |
122 | caa4039c | j_mayer | return pte0 & 0x0000000000000001ULL ? 1 : 0; |
123 | caa4039c | j_mayer | } |
124 | caa4039c | j_mayer | |
125 | b068d6a7 | j_mayer | static always_inline void pte64_invalidate (target_ulong *pte0) |
126 | caa4039c | j_mayer | { |
127 | caa4039c | j_mayer | *pte0 &= ~0x0000000000000001ULL;
|
128 | caa4039c | j_mayer | } |
129 | caa4039c | j_mayer | #endif
|
130 | caa4039c | j_mayer | |
131 | 76a66253 | j_mayer | #define PTE_PTEM_MASK 0x7FFFFFBF |
132 | 76a66253 | j_mayer | #define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B) |
133 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
134 | caa4039c | j_mayer | #define PTE64_PTEM_MASK 0xFFFFFFFFFFFFFF80ULL |
135 | caa4039c | j_mayer | #define PTE64_CHECK_MASK (TARGET_PAGE_MASK | 0x7F) |
136 | caa4039c | j_mayer | #endif
|
137 | 76a66253 | j_mayer | |
138 | b227a8e9 | j_mayer | static always_inline int pp_check (int key, int pp, int nx) |
139 | b227a8e9 | j_mayer | { |
140 | b227a8e9 | j_mayer | int access;
|
141 | b227a8e9 | j_mayer | |
142 | b227a8e9 | j_mayer | /* Compute access rights */
|
143 | b227a8e9 | j_mayer | /* When pp is 3/7, the result is undefined. Set it to noaccess */
|
144 | b227a8e9 | j_mayer | access = 0;
|
145 | b227a8e9 | j_mayer | if (key == 0) { |
146 | b227a8e9 | j_mayer | switch (pp) {
|
147 | b227a8e9 | j_mayer | case 0x0: |
148 | b227a8e9 | j_mayer | case 0x1: |
149 | b227a8e9 | j_mayer | case 0x2: |
150 | b227a8e9 | j_mayer | access |= PAGE_WRITE; |
151 | b227a8e9 | j_mayer | /* No break here */
|
152 | b227a8e9 | j_mayer | case 0x3: |
153 | b227a8e9 | j_mayer | case 0x6: |
154 | b227a8e9 | j_mayer | access |= PAGE_READ; |
155 | b227a8e9 | j_mayer | break;
|
156 | b227a8e9 | j_mayer | } |
157 | b227a8e9 | j_mayer | } else {
|
158 | b227a8e9 | j_mayer | switch (pp) {
|
159 | b227a8e9 | j_mayer | case 0x0: |
160 | b227a8e9 | j_mayer | case 0x6: |
161 | b227a8e9 | j_mayer | access = 0;
|
162 | b227a8e9 | j_mayer | break;
|
163 | b227a8e9 | j_mayer | case 0x1: |
164 | b227a8e9 | j_mayer | case 0x3: |
165 | b227a8e9 | j_mayer | access = PAGE_READ; |
166 | b227a8e9 | j_mayer | break;
|
167 | b227a8e9 | j_mayer | case 0x2: |
168 | b227a8e9 | j_mayer | access = PAGE_READ | PAGE_WRITE; |
169 | b227a8e9 | j_mayer | break;
|
170 | b227a8e9 | j_mayer | } |
171 | b227a8e9 | j_mayer | } |
172 | b227a8e9 | j_mayer | if (nx == 0) |
173 | b227a8e9 | j_mayer | access |= PAGE_EXEC; |
174 | b227a8e9 | j_mayer | |
175 | b227a8e9 | j_mayer | return access;
|
176 | b227a8e9 | j_mayer | } |
177 | b227a8e9 | j_mayer | |
178 | b227a8e9 | j_mayer | static always_inline int check_prot (int prot, int rw, int access_type) |
179 | b227a8e9 | j_mayer | { |
180 | b227a8e9 | j_mayer | int ret;
|
181 | b227a8e9 | j_mayer | |
182 | b227a8e9 | j_mayer | if (access_type == ACCESS_CODE) {
|
183 | b227a8e9 | j_mayer | if (prot & PAGE_EXEC)
|
184 | b227a8e9 | j_mayer | ret = 0;
|
185 | b227a8e9 | j_mayer | else
|
186 | b227a8e9 | j_mayer | ret = -2;
|
187 | b227a8e9 | j_mayer | } else if (rw) { |
188 | b227a8e9 | j_mayer | if (prot & PAGE_WRITE)
|
189 | b227a8e9 | j_mayer | ret = 0;
|
190 | b227a8e9 | j_mayer | else
|
191 | b227a8e9 | j_mayer | ret = -2;
|
192 | b227a8e9 | j_mayer | } else {
|
193 | b227a8e9 | j_mayer | if (prot & PAGE_READ)
|
194 | b227a8e9 | j_mayer | ret = 0;
|
195 | b227a8e9 | j_mayer | else
|
196 | b227a8e9 | j_mayer | ret = -2;
|
197 | b227a8e9 | j_mayer | } |
198 | b227a8e9 | j_mayer | |
199 | b227a8e9 | j_mayer | return ret;
|
200 | b227a8e9 | j_mayer | } |
201 | b227a8e9 | j_mayer | |
202 | b068d6a7 | j_mayer | static always_inline int _pte_check (mmu_ctx_t *ctx, int is_64b, |
203 | b068d6a7 | j_mayer | target_ulong pte0, target_ulong pte1, |
204 | b227a8e9 | j_mayer | int h, int rw, int type) |
205 | 76a66253 | j_mayer | { |
206 | caa4039c | j_mayer | target_ulong ptem, mmask; |
207 | b227a8e9 | j_mayer | int access, ret, pteh, ptev, pp;
|
208 | 76a66253 | j_mayer | |
209 | 76a66253 | j_mayer | access = 0;
|
210 | 76a66253 | j_mayer | ret = -1;
|
211 | 76a66253 | j_mayer | /* Check validity and table match */
|
212 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
213 | caa4039c | j_mayer | if (is_64b) {
|
214 | caa4039c | j_mayer | ptev = pte64_is_valid(pte0); |
215 | caa4039c | j_mayer | pteh = (pte0 >> 1) & 1; |
216 | caa4039c | j_mayer | } else
|
217 | caa4039c | j_mayer | #endif
|
218 | caa4039c | j_mayer | { |
219 | caa4039c | j_mayer | ptev = pte_is_valid(pte0); |
220 | caa4039c | j_mayer | pteh = (pte0 >> 6) & 1; |
221 | caa4039c | j_mayer | } |
222 | caa4039c | j_mayer | if (ptev && h == pteh) {
|
223 | 76a66253 | j_mayer | /* Check vsid & api */
|
224 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
225 | caa4039c | j_mayer | if (is_64b) {
|
226 | caa4039c | j_mayer | ptem = pte0 & PTE64_PTEM_MASK; |
227 | caa4039c | j_mayer | mmask = PTE64_CHECK_MASK; |
228 | b227a8e9 | j_mayer | pp = (pte1 & 0x00000003) | ((pte1 >> 61) & 0x00000004); |
229 | 29c8ca6f | blueswir1 | ctx->nx = (pte1 >> 2) & 1; /* No execute bit */ |
230 | b227a8e9 | j_mayer | ctx->nx |= (pte1 >> 3) & 1; /* Guarded bit */ |
231 | caa4039c | j_mayer | } else
|
232 | caa4039c | j_mayer | #endif
|
233 | caa4039c | j_mayer | { |
234 | caa4039c | j_mayer | ptem = pte0 & PTE_PTEM_MASK; |
235 | caa4039c | j_mayer | mmask = PTE_CHECK_MASK; |
236 | b227a8e9 | j_mayer | pp = pte1 & 0x00000003;
|
237 | caa4039c | j_mayer | } |
238 | caa4039c | j_mayer | if (ptem == ctx->ptem) {
|
239 | 6f2d8978 | j_mayer | if (ctx->raddr != (target_phys_addr_t)-1ULL) { |
240 | 76a66253 | j_mayer | /* all matches should have equal RPN, WIMG & PP */
|
241 | caa4039c | j_mayer | if ((ctx->raddr & mmask) != (pte1 & mmask)) {
|
242 | 93fcfe39 | aliguori | qemu_log("Bad RPN/WIMG/PP\n");
|
243 | 76a66253 | j_mayer | return -3; |
244 | 76a66253 | j_mayer | } |
245 | 76a66253 | j_mayer | } |
246 | 76a66253 | j_mayer | /* Compute access rights */
|
247 | b227a8e9 | j_mayer | access = pp_check(ctx->key, pp, ctx->nx); |
248 | 76a66253 | j_mayer | /* Keep the matching PTE informations */
|
249 | 76a66253 | j_mayer | ctx->raddr = pte1; |
250 | 76a66253 | j_mayer | ctx->prot = access; |
251 | b227a8e9 | j_mayer | ret = check_prot(ctx->prot, rw, type); |
252 | b227a8e9 | j_mayer | if (ret == 0) { |
253 | 76a66253 | j_mayer | /* Access granted */
|
254 | d12d51d5 | aliguori | LOG_MMU("PTE access granted !\n");
|
255 | 76a66253 | j_mayer | } else {
|
256 | 76a66253 | j_mayer | /* Access right violation */
|
257 | d12d51d5 | aliguori | LOG_MMU("PTE access rejected\n");
|
258 | 76a66253 | j_mayer | } |
259 | 76a66253 | j_mayer | } |
260 | 76a66253 | j_mayer | } |
261 | 76a66253 | j_mayer | |
262 | 76a66253 | j_mayer | return ret;
|
263 | 76a66253 | j_mayer | } |
264 | 76a66253 | j_mayer | |
265 | a11b8151 | j_mayer | static always_inline int pte32_check (mmu_ctx_t *ctx, |
266 | a11b8151 | j_mayer | target_ulong pte0, target_ulong pte1, |
267 | a11b8151 | j_mayer | int h, int rw, int type) |
268 | caa4039c | j_mayer | { |
269 | b227a8e9 | j_mayer | return _pte_check(ctx, 0, pte0, pte1, h, rw, type); |
270 | caa4039c | j_mayer | } |
271 | caa4039c | j_mayer | |
272 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
273 | a11b8151 | j_mayer | static always_inline int pte64_check (mmu_ctx_t *ctx, |
274 | a11b8151 | j_mayer | target_ulong pte0, target_ulong pte1, |
275 | a11b8151 | j_mayer | int h, int rw, int type) |
276 | caa4039c | j_mayer | { |
277 | b227a8e9 | j_mayer | return _pte_check(ctx, 1, pte0, pte1, h, rw, type); |
278 | caa4039c | j_mayer | } |
279 | caa4039c | j_mayer | #endif
|
280 | caa4039c | j_mayer | |
281 | a11b8151 | j_mayer | static always_inline int pte_update_flags (mmu_ctx_t *ctx, target_ulong *pte1p, |
282 | a11b8151 | j_mayer | int ret, int rw) |
283 | 76a66253 | j_mayer | { |
284 | 76a66253 | j_mayer | int store = 0; |
285 | 76a66253 | j_mayer | |
286 | 76a66253 | j_mayer | /* Update page flags */
|
287 | 76a66253 | j_mayer | if (!(*pte1p & 0x00000100)) { |
288 | 76a66253 | j_mayer | /* Update accessed flag */
|
289 | 76a66253 | j_mayer | *pte1p |= 0x00000100;
|
290 | 76a66253 | j_mayer | store = 1;
|
291 | 76a66253 | j_mayer | } |
292 | 76a66253 | j_mayer | if (!(*pte1p & 0x00000080)) { |
293 | 76a66253 | j_mayer | if (rw == 1 && ret == 0) { |
294 | 76a66253 | j_mayer | /* Update changed flag */
|
295 | 76a66253 | j_mayer | *pte1p |= 0x00000080;
|
296 | 76a66253 | j_mayer | store = 1;
|
297 | 76a66253 | j_mayer | } else {
|
298 | 76a66253 | j_mayer | /* Force page fault for first write access */
|
299 | 76a66253 | j_mayer | ctx->prot &= ~PAGE_WRITE; |
300 | 76a66253 | j_mayer | } |
301 | 76a66253 | j_mayer | } |
302 | 76a66253 | j_mayer | |
303 | 76a66253 | j_mayer | return store;
|
304 | 76a66253 | j_mayer | } |
305 | 76a66253 | j_mayer | |
306 | 76a66253 | j_mayer | /* Software driven TLB helpers */
|
307 | a11b8151 | j_mayer | static always_inline int ppc6xx_tlb_getnum (CPUState *env, target_ulong eaddr, |
308 | a11b8151 | j_mayer | int way, int is_code) |
309 | 76a66253 | j_mayer | { |
310 | 76a66253 | j_mayer | int nr;
|
311 | 76a66253 | j_mayer | |
312 | 76a66253 | j_mayer | /* Select TLB num in a way from address */
|
313 | 76a66253 | j_mayer | nr = (eaddr >> TARGET_PAGE_BITS) & (env->tlb_per_way - 1);
|
314 | 76a66253 | j_mayer | /* Select TLB way */
|
315 | 76a66253 | j_mayer | nr += env->tlb_per_way * way; |
316 | 76a66253 | j_mayer | /* 6xx have separate TLBs for instructions and data */
|
317 | 76a66253 | j_mayer | if (is_code && env->id_tlbs == 1) |
318 | 76a66253 | j_mayer | nr += env->nb_tlb; |
319 | 76a66253 | j_mayer | |
320 | 76a66253 | j_mayer | return nr;
|
321 | 76a66253 | j_mayer | } |
322 | 76a66253 | j_mayer | |
323 | a11b8151 | j_mayer | static always_inline void ppc6xx_tlb_invalidate_all (CPUState *env) |
324 | 76a66253 | j_mayer | { |
325 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
326 | 76a66253 | j_mayer | int nr, max;
|
327 | 76a66253 | j_mayer | |
328 | d12d51d5 | aliguori | //LOG_SWTLB("Invalidate all TLBs\n");
|
329 | 76a66253 | j_mayer | /* Invalidate all defined software TLB */
|
330 | 76a66253 | j_mayer | max = env->nb_tlb; |
331 | 76a66253 | j_mayer | if (env->id_tlbs == 1) |
332 | 76a66253 | j_mayer | max *= 2;
|
333 | 76a66253 | j_mayer | for (nr = 0; nr < max; nr++) { |
334 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
335 | 76a66253 | j_mayer | pte_invalidate(&tlb->pte0); |
336 | 76a66253 | j_mayer | } |
337 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
338 | 76a66253 | j_mayer | } |
339 | 76a66253 | j_mayer | |
340 | b068d6a7 | j_mayer | static always_inline void __ppc6xx_tlb_invalidate_virt (CPUState *env, |
341 | b068d6a7 | j_mayer | target_ulong eaddr, |
342 | b068d6a7 | j_mayer | int is_code,
|
343 | b068d6a7 | j_mayer | int match_epn)
|
344 | 76a66253 | j_mayer | { |
345 | 4a057712 | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
346 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
347 | 76a66253 | j_mayer | int way, nr;
|
348 | 76a66253 | j_mayer | |
349 | 76a66253 | j_mayer | /* Invalidate ITLB + DTLB, all ways */
|
350 | 76a66253 | j_mayer | for (way = 0; way < env->nb_ways; way++) { |
351 | 76a66253 | j_mayer | nr = ppc6xx_tlb_getnum(env, eaddr, way, is_code); |
352 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
353 | 76a66253 | j_mayer | if (pte_is_valid(tlb->pte0) && (match_epn == 0 || eaddr == tlb->EPN)) { |
354 | d12d51d5 | aliguori | LOG_SWTLB("TLB invalidate %d/%d " ADDRX "\n", |
355 | 76a66253 | j_mayer | nr, env->nb_tlb, eaddr); |
356 | 76a66253 | j_mayer | pte_invalidate(&tlb->pte0); |
357 | 76a66253 | j_mayer | tlb_flush_page(env, tlb->EPN); |
358 | 76a66253 | j_mayer | } |
359 | 76a66253 | j_mayer | } |
360 | 76a66253 | j_mayer | #else
|
361 | 76a66253 | j_mayer | /* XXX: PowerPC specification say this is valid as well */
|
362 | 76a66253 | j_mayer | ppc6xx_tlb_invalidate_all(env); |
363 | 76a66253 | j_mayer | #endif
|
364 | 76a66253 | j_mayer | } |
365 | 76a66253 | j_mayer | |
366 | a11b8151 | j_mayer | static always_inline void ppc6xx_tlb_invalidate_virt (CPUState *env, |
367 | a11b8151 | j_mayer | target_ulong eaddr, |
368 | a11b8151 | j_mayer | int is_code)
|
369 | 76a66253 | j_mayer | { |
370 | 76a66253 | j_mayer | __ppc6xx_tlb_invalidate_virt(env, eaddr, is_code, 0);
|
371 | 76a66253 | j_mayer | } |
372 | 76a66253 | j_mayer | |
373 | 76a66253 | j_mayer | void ppc6xx_tlb_store (CPUState *env, target_ulong EPN, int way, int is_code, |
374 | 76a66253 | j_mayer | target_ulong pte0, target_ulong pte1) |
375 | 76a66253 | j_mayer | { |
376 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
377 | 76a66253 | j_mayer | int nr;
|
378 | 76a66253 | j_mayer | |
379 | 76a66253 | j_mayer | nr = ppc6xx_tlb_getnum(env, EPN, way, is_code); |
380 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
381 | d12d51d5 | aliguori | LOG_SWTLB("Set TLB %d/%d EPN " ADDRX " PTE0 " ADDRX |
382 | 1b9eb036 | j_mayer | " PTE1 " ADDRX "\n", nr, env->nb_tlb, EPN, pte0, pte1); |
383 | 76a66253 | j_mayer | /* Invalidate any pending reference in Qemu for this virtual address */
|
384 | 76a66253 | j_mayer | __ppc6xx_tlb_invalidate_virt(env, EPN, is_code, 1);
|
385 | 76a66253 | j_mayer | tlb->pte0 = pte0; |
386 | 76a66253 | j_mayer | tlb->pte1 = pte1; |
387 | 76a66253 | j_mayer | tlb->EPN = EPN; |
388 | 76a66253 | j_mayer | /* Store last way for LRU mechanism */
|
389 | 76a66253 | j_mayer | env->last_way = way; |
390 | 76a66253 | j_mayer | } |
391 | 76a66253 | j_mayer | |
392 | a11b8151 | j_mayer | static always_inline int ppc6xx_tlb_check (CPUState *env, mmu_ctx_t *ctx, |
393 | a11b8151 | j_mayer | target_ulong eaddr, int rw,
|
394 | a11b8151 | j_mayer | int access_type)
|
395 | 76a66253 | j_mayer | { |
396 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
397 | 76a66253 | j_mayer | int nr, best, way;
|
398 | 76a66253 | j_mayer | int ret;
|
399 | d9bce9d9 | j_mayer | |
400 | 76a66253 | j_mayer | best = -1;
|
401 | 76a66253 | j_mayer | ret = -1; /* No TLB found */ |
402 | 76a66253 | j_mayer | for (way = 0; way < env->nb_ways; way++) { |
403 | 76a66253 | j_mayer | nr = ppc6xx_tlb_getnum(env, eaddr, way, |
404 | 76a66253 | j_mayer | access_type == ACCESS_CODE ? 1 : 0); |
405 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
406 | 76a66253 | j_mayer | /* This test "emulates" the PTE index match for hardware TLBs */
|
407 | 76a66253 | j_mayer | if ((eaddr & TARGET_PAGE_MASK) != tlb->EPN) {
|
408 | d12d51d5 | aliguori | LOG_SWTLB("TLB %d/%d %s [" ADDRX " " ADDRX |
409 | 1b9eb036 | j_mayer | "] <> " ADDRX "\n", |
410 | 76a66253 | j_mayer | nr, env->nb_tlb, |
411 | 76a66253 | j_mayer | pte_is_valid(tlb->pte0) ? "valid" : "inval", |
412 | 76a66253 | j_mayer | tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, eaddr); |
413 | 76a66253 | j_mayer | continue;
|
414 | 76a66253 | j_mayer | } |
415 | d12d51d5 | aliguori | LOG_SWTLB("TLB %d/%d %s " ADDRX " <> " ADDRX " " ADDRX |
416 | 1b9eb036 | j_mayer | " %c %c\n",
|
417 | 76a66253 | j_mayer | nr, env->nb_tlb, |
418 | 76a66253 | j_mayer | pte_is_valid(tlb->pte0) ? "valid" : "inval", |
419 | 76a66253 | j_mayer | tlb->EPN, eaddr, tlb->pte1, |
420 | 76a66253 | j_mayer | rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D'); |
421 | b227a8e9 | j_mayer | switch (pte32_check(ctx, tlb->pte0, tlb->pte1, 0, rw, access_type)) { |
422 | 76a66253 | j_mayer | case -3: |
423 | 76a66253 | j_mayer | /* TLB inconsistency */
|
424 | 76a66253 | j_mayer | return -1; |
425 | 76a66253 | j_mayer | case -2: |
426 | 76a66253 | j_mayer | /* Access violation */
|
427 | 76a66253 | j_mayer | ret = -2;
|
428 | 76a66253 | j_mayer | best = nr; |
429 | 76a66253 | j_mayer | break;
|
430 | 76a66253 | j_mayer | case -1: |
431 | 76a66253 | j_mayer | default:
|
432 | 76a66253 | j_mayer | /* No match */
|
433 | 76a66253 | j_mayer | break;
|
434 | 76a66253 | j_mayer | case 0: |
435 | 76a66253 | j_mayer | /* access granted */
|
436 | 76a66253 | j_mayer | /* XXX: we should go on looping to check all TLBs consistency
|
437 | 76a66253 | j_mayer | * but we can speed-up the whole thing as the
|
438 | 76a66253 | j_mayer | * result would be undefined if TLBs are not consistent.
|
439 | 76a66253 | j_mayer | */
|
440 | 76a66253 | j_mayer | ret = 0;
|
441 | 76a66253 | j_mayer | best = nr; |
442 | 76a66253 | j_mayer | goto done;
|
443 | 76a66253 | j_mayer | } |
444 | 76a66253 | j_mayer | } |
445 | 76a66253 | j_mayer | if (best != -1) { |
446 | 76a66253 | j_mayer | done:
|
447 | d12d51d5 | aliguori | LOG_SWTLB("found TLB at addr " PADDRX " prot=%01x ret=%d\n", |
448 | 76a66253 | j_mayer | ctx->raddr & TARGET_PAGE_MASK, ctx->prot, ret); |
449 | 76a66253 | j_mayer | /* Update page flags */
|
450 | 1d0a48fb | j_mayer | pte_update_flags(ctx, &env->tlb[best].tlb6.pte1, ret, rw); |
451 | 76a66253 | j_mayer | } |
452 | 76a66253 | j_mayer | |
453 | 76a66253 | j_mayer | return ret;
|
454 | 76a66253 | j_mayer | } |
455 | 76a66253 | j_mayer | |
456 | 9a64fbe4 | bellard | /* Perform BAT hit & translation */
|
457 | faadf50e | j_mayer | static always_inline void bat_size_prot (CPUState *env, target_ulong *blp, |
458 | faadf50e | j_mayer | int *validp, int *protp, |
459 | faadf50e | j_mayer | target_ulong *BATu, target_ulong *BATl) |
460 | faadf50e | j_mayer | { |
461 | faadf50e | j_mayer | target_ulong bl; |
462 | faadf50e | j_mayer | int pp, valid, prot;
|
463 | faadf50e | j_mayer | |
464 | faadf50e | j_mayer | bl = (*BATu & 0x00001FFC) << 15; |
465 | faadf50e | j_mayer | valid = 0;
|
466 | faadf50e | j_mayer | prot = 0;
|
467 | faadf50e | j_mayer | if (((msr_pr == 0) && (*BATu & 0x00000002)) || |
468 | faadf50e | j_mayer | ((msr_pr != 0) && (*BATu & 0x00000001))) { |
469 | faadf50e | j_mayer | valid = 1;
|
470 | faadf50e | j_mayer | pp = *BATl & 0x00000003;
|
471 | faadf50e | j_mayer | if (pp != 0) { |
472 | faadf50e | j_mayer | prot = PAGE_READ | PAGE_EXEC; |
473 | faadf50e | j_mayer | if (pp == 0x2) |
474 | faadf50e | j_mayer | prot |= PAGE_WRITE; |
475 | faadf50e | j_mayer | } |
476 | faadf50e | j_mayer | } |
477 | faadf50e | j_mayer | *blp = bl; |
478 | faadf50e | j_mayer | *validp = valid; |
479 | faadf50e | j_mayer | *protp = prot; |
480 | faadf50e | j_mayer | } |
481 | faadf50e | j_mayer | |
482 | faadf50e | j_mayer | static always_inline void bat_601_size_prot (CPUState *env,target_ulong *blp, |
483 | faadf50e | j_mayer | int *validp, int *protp, |
484 | faadf50e | j_mayer | target_ulong *BATu, |
485 | faadf50e | j_mayer | target_ulong *BATl) |
486 | faadf50e | j_mayer | { |
487 | faadf50e | j_mayer | target_ulong bl; |
488 | faadf50e | j_mayer | int key, pp, valid, prot;
|
489 | faadf50e | j_mayer | |
490 | faadf50e | j_mayer | bl = (*BATl & 0x0000003F) << 17; |
491 | d12d51d5 | aliguori | LOG_BATS("b %02x ==> bl " ADDRX " msk " ADDRX "\n", |
492 | 6b542af7 | j_mayer | (uint8_t)(*BATl & 0x0000003F), bl, ~bl);
|
493 | faadf50e | j_mayer | prot = 0;
|
494 | faadf50e | j_mayer | valid = (*BATl >> 6) & 1; |
495 | faadf50e | j_mayer | if (valid) {
|
496 | faadf50e | j_mayer | pp = *BATu & 0x00000003;
|
497 | faadf50e | j_mayer | if (msr_pr == 0) |
498 | faadf50e | j_mayer | key = (*BATu >> 3) & 1; |
499 | faadf50e | j_mayer | else
|
500 | faadf50e | j_mayer | key = (*BATu >> 2) & 1; |
501 | faadf50e | j_mayer | prot = pp_check(key, pp, 0);
|
502 | faadf50e | j_mayer | } |
503 | faadf50e | j_mayer | *blp = bl; |
504 | faadf50e | j_mayer | *validp = valid; |
505 | faadf50e | j_mayer | *protp = prot; |
506 | faadf50e | j_mayer | } |
507 | faadf50e | j_mayer | |
508 | a11b8151 | j_mayer | static always_inline int get_bat (CPUState *env, mmu_ctx_t *ctx, |
509 | a11b8151 | j_mayer | target_ulong virtual, int rw, int type) |
510 | 9a64fbe4 | bellard | { |
511 | 76a66253 | j_mayer | target_ulong *BATlt, *BATut, *BATu, *BATl; |
512 | 76a66253 | j_mayer | target_ulong base, BEPIl, BEPIu, bl; |
513 | faadf50e | j_mayer | int i, valid, prot;
|
514 | 9a64fbe4 | bellard | int ret = -1; |
515 | 9a64fbe4 | bellard | |
516 | d12d51d5 | aliguori | LOG_BATS("%s: %cBAT v " ADDRX "\n", __func__, |
517 | 76a66253 | j_mayer | type == ACCESS_CODE ? 'I' : 'D', virtual); |
518 | 9a64fbe4 | bellard | switch (type) {
|
519 | 9a64fbe4 | bellard | case ACCESS_CODE:
|
520 | 9a64fbe4 | bellard | BATlt = env->IBAT[1];
|
521 | 9a64fbe4 | bellard | BATut = env->IBAT[0];
|
522 | 9a64fbe4 | bellard | break;
|
523 | 9a64fbe4 | bellard | default:
|
524 | 9a64fbe4 | bellard | BATlt = env->DBAT[1];
|
525 | 9a64fbe4 | bellard | BATut = env->DBAT[0];
|
526 | 9a64fbe4 | bellard | break;
|
527 | 9a64fbe4 | bellard | } |
528 | 9a64fbe4 | bellard | base = virtual & 0xFFFC0000;
|
529 | faadf50e | j_mayer | for (i = 0; i < env->nb_BATs; i++) { |
530 | 9a64fbe4 | bellard | BATu = &BATut[i]; |
531 | 9a64fbe4 | bellard | BATl = &BATlt[i]; |
532 | 9a64fbe4 | bellard | BEPIu = *BATu & 0xF0000000;
|
533 | 9a64fbe4 | bellard | BEPIl = *BATu & 0x0FFE0000;
|
534 | faadf50e | j_mayer | if (unlikely(env->mmu_model == POWERPC_MMU_601)) {
|
535 | faadf50e | j_mayer | bat_601_size_prot(env, &bl, &valid, &prot, BATu, BATl); |
536 | faadf50e | j_mayer | } else {
|
537 | faadf50e | j_mayer | bat_size_prot(env, &bl, &valid, &prot, BATu, BATl); |
538 | faadf50e | j_mayer | } |
539 | d12d51d5 | aliguori | LOG_BATS("%s: %cBAT%d v " ADDRX " BATu " ADDRX |
540 | 6b542af7 | j_mayer | " BATl " ADDRX "\n", __func__, |
541 | 6b542af7 | j_mayer | type == ACCESS_CODE ? 'I' : 'D', i, virtual, *BATu, *BATl); |
542 | 9a64fbe4 | bellard | if ((virtual & 0xF0000000) == BEPIu && |
543 | 9a64fbe4 | bellard | ((virtual & 0x0FFE0000) & ~bl) == BEPIl) {
|
544 | 9a64fbe4 | bellard | /* BAT matches */
|
545 | faadf50e | j_mayer | if (valid != 0) { |
546 | 9a64fbe4 | bellard | /* Get physical address */
|
547 | 76a66253 | j_mayer | ctx->raddr = (*BATl & 0xF0000000) |
|
548 | 9a64fbe4 | bellard | ((virtual & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) | |
549 | a541f297 | bellard | (virtual & 0x0001F000);
|
550 | b227a8e9 | j_mayer | /* Compute access rights */
|
551 | faadf50e | j_mayer | ctx->prot = prot; |
552 | b227a8e9 | j_mayer | ret = check_prot(ctx->prot, rw, type); |
553 | d12d51d5 | aliguori | if (ret == 0) |
554 | d12d51d5 | aliguori | LOG_BATS("BAT %d match: r " PADDRX " prot=%c%c\n", |
555 | d12d51d5 | aliguori | i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-', |
556 | d12d51d5 | aliguori | ctx->prot & PAGE_WRITE ? 'W' : '-'); |
557 | 9a64fbe4 | bellard | break;
|
558 | 9a64fbe4 | bellard | } |
559 | 9a64fbe4 | bellard | } |
560 | 9a64fbe4 | bellard | } |
561 | 9a64fbe4 | bellard | if (ret < 0) { |
562 | d12d51d5 | aliguori | #if defined(DEBUG_BATS)
|
563 | d12d51d5 | aliguori | if (IS_LOGGING) {
|
564 | d12d51d5 | aliguori | QEMU_LOG0("no BAT match for " ADDRX ":\n", virtual); |
565 | 4a057712 | j_mayer | for (i = 0; i < 4; i++) { |
566 | 4a057712 | j_mayer | BATu = &BATut[i]; |
567 | 4a057712 | j_mayer | BATl = &BATlt[i]; |
568 | 4a057712 | j_mayer | BEPIu = *BATu & 0xF0000000;
|
569 | 4a057712 | j_mayer | BEPIl = *BATu & 0x0FFE0000;
|
570 | 4a057712 | j_mayer | bl = (*BATu & 0x00001FFC) << 15; |
571 | d12d51d5 | aliguori | QEMU_LOG0("%s: %cBAT%d v " ADDRX " BATu " ADDRX |
572 | 6b542af7 | j_mayer | " BATl " ADDRX " \n\t" ADDRX " " ADDRX " " ADDRX "\n", |
573 | 4a057712 | j_mayer | __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual, |
574 | 4a057712 | j_mayer | *BATu, *BATl, BEPIu, BEPIl, bl); |
575 | 4a057712 | j_mayer | } |
576 | 9a64fbe4 | bellard | } |
577 | 9a64fbe4 | bellard | #endif
|
578 | 9a64fbe4 | bellard | } |
579 | 9a64fbe4 | bellard | /* No hit */
|
580 | 9a64fbe4 | bellard | return ret;
|
581 | 9a64fbe4 | bellard | } |
582 | 9a64fbe4 | bellard | |
583 | 9a64fbe4 | bellard | /* PTE table lookup */
|
584 | b227a8e9 | j_mayer | static always_inline int _find_pte (mmu_ctx_t *ctx, int is_64b, int h, |
585 | 5b5aba4f | blueswir1 | int rw, int type, |
586 | 5b5aba4f | blueswir1 | int target_page_bits)
|
587 | 9a64fbe4 | bellard | { |
588 | 76a66253 | j_mayer | target_ulong base, pte0, pte1; |
589 | 76a66253 | j_mayer | int i, good = -1; |
590 | caa4039c | j_mayer | int ret, r;
|
591 | 9a64fbe4 | bellard | |
592 | 76a66253 | j_mayer | ret = -1; /* No entry found */ |
593 | 76a66253 | j_mayer | base = ctx->pg_addr[h]; |
594 | 9a64fbe4 | bellard | for (i = 0; i < 8; i++) { |
595 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
596 | caa4039c | j_mayer | if (is_64b) {
|
597 | caa4039c | j_mayer | pte0 = ldq_phys(base + (i * 16));
|
598 | 5b5aba4f | blueswir1 | pte1 = ldq_phys(base + (i * 16) + 8); |
599 | 5b5aba4f | blueswir1 | |
600 | 5b5aba4f | blueswir1 | /* We have a TLB that saves 4K pages, so let's
|
601 | 5b5aba4f | blueswir1 | * split a huge page to 4k chunks */
|
602 | 5b5aba4f | blueswir1 | if (target_page_bits != TARGET_PAGE_BITS)
|
603 | 5b5aba4f | blueswir1 | pte1 |= (ctx->eaddr & (( 1 << target_page_bits ) - 1)) |
604 | 5b5aba4f | blueswir1 | & TARGET_PAGE_MASK; |
605 | 5b5aba4f | blueswir1 | |
606 | b227a8e9 | j_mayer | r = pte64_check(ctx, pte0, pte1, h, rw, type); |
607 | d12d51d5 | aliguori | LOG_MMU("Load pte from " ADDRX " => " ADDRX " " ADDRX |
608 | 6b542af7 | j_mayer | " %d %d %d " ADDRX "\n", |
609 | 12de9a39 | j_mayer | base + (i * 16), pte0, pte1,
|
610 | 12de9a39 | j_mayer | (int)(pte0 & 1), h, (int)((pte0 >> 1) & 1), |
611 | 12de9a39 | j_mayer | ctx->ptem); |
612 | caa4039c | j_mayer | } else
|
613 | caa4039c | j_mayer | #endif
|
614 | caa4039c | j_mayer | { |
615 | caa4039c | j_mayer | pte0 = ldl_phys(base + (i * 8));
|
616 | caa4039c | j_mayer | pte1 = ldl_phys(base + (i * 8) + 4); |
617 | b227a8e9 | j_mayer | r = pte32_check(ctx, pte0, pte1, h, rw, type); |
618 | d12d51d5 | aliguori | LOG_MMU("Load pte from " ADDRX " => " ADDRX " " ADDRX |
619 | 6b542af7 | j_mayer | " %d %d %d " ADDRX "\n", |
620 | 12de9a39 | j_mayer | base + (i * 8), pte0, pte1,
|
621 | 12de9a39 | j_mayer | (int)(pte0 >> 31), h, (int)((pte0 >> 6) & 1), |
622 | 12de9a39 | j_mayer | ctx->ptem); |
623 | 12de9a39 | j_mayer | } |
624 | caa4039c | j_mayer | switch (r) {
|
625 | 76a66253 | j_mayer | case -3: |
626 | 76a66253 | j_mayer | /* PTE inconsistency */
|
627 | 76a66253 | j_mayer | return -1; |
628 | 76a66253 | j_mayer | case -2: |
629 | 76a66253 | j_mayer | /* Access violation */
|
630 | 76a66253 | j_mayer | ret = -2;
|
631 | 76a66253 | j_mayer | good = i; |
632 | 76a66253 | j_mayer | break;
|
633 | 76a66253 | j_mayer | case -1: |
634 | 76a66253 | j_mayer | default:
|
635 | 76a66253 | j_mayer | /* No PTE match */
|
636 | 76a66253 | j_mayer | break;
|
637 | 76a66253 | j_mayer | case 0: |
638 | 76a66253 | j_mayer | /* access granted */
|
639 | 76a66253 | j_mayer | /* XXX: we should go on looping to check all PTEs consistency
|
640 | 76a66253 | j_mayer | * but if we can speed-up the whole thing as the
|
641 | 76a66253 | j_mayer | * result would be undefined if PTEs are not consistent.
|
642 | 76a66253 | j_mayer | */
|
643 | 76a66253 | j_mayer | ret = 0;
|
644 | 76a66253 | j_mayer | good = i; |
645 | 76a66253 | j_mayer | goto done;
|
646 | 9a64fbe4 | bellard | } |
647 | 9a64fbe4 | bellard | } |
648 | 9a64fbe4 | bellard | if (good != -1) { |
649 | 76a66253 | j_mayer | done:
|
650 | d12d51d5 | aliguori | LOG_MMU("found PTE at addr " PADDRX " prot=%01x ret=%d\n", |
651 | 76a66253 | j_mayer | ctx->raddr, ctx->prot, ret); |
652 | 9a64fbe4 | bellard | /* Update page flags */
|
653 | 76a66253 | j_mayer | pte1 = ctx->raddr; |
654 | caa4039c | j_mayer | if (pte_update_flags(ctx, &pte1, ret, rw) == 1) { |
655 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
656 | caa4039c | j_mayer | if (is_64b) {
|
657 | caa4039c | j_mayer | stq_phys_notdirty(base + (good * 16) + 8, pte1); |
658 | caa4039c | j_mayer | } else
|
659 | caa4039c | j_mayer | #endif
|
660 | caa4039c | j_mayer | { |
661 | caa4039c | j_mayer | stl_phys_notdirty(base + (good * 8) + 4, pte1); |
662 | caa4039c | j_mayer | } |
663 | caa4039c | j_mayer | } |
664 | 9a64fbe4 | bellard | } |
665 | 9a64fbe4 | bellard | |
666 | 9a64fbe4 | bellard | return ret;
|
667 | 79aceca5 | bellard | } |
668 | 79aceca5 | bellard | |
669 | 5b5aba4f | blueswir1 | static always_inline int find_pte32 (mmu_ctx_t *ctx, int h, int rw, |
670 | 5b5aba4f | blueswir1 | int type, int target_page_bits) |
671 | caa4039c | j_mayer | { |
672 | 5b5aba4f | blueswir1 | return _find_pte(ctx, 0, h, rw, type, target_page_bits); |
673 | caa4039c | j_mayer | } |
674 | caa4039c | j_mayer | |
675 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
676 | 5b5aba4f | blueswir1 | static always_inline int find_pte64 (mmu_ctx_t *ctx, int h, int rw, |
677 | 5b5aba4f | blueswir1 | int type, int target_page_bits) |
678 | caa4039c | j_mayer | { |
679 | 5b5aba4f | blueswir1 | return _find_pte(ctx, 1, h, rw, type, target_page_bits); |
680 | caa4039c | j_mayer | } |
681 | caa4039c | j_mayer | #endif
|
682 | caa4039c | j_mayer | |
683 | b068d6a7 | j_mayer | static always_inline int find_pte (CPUState *env, mmu_ctx_t *ctx, |
684 | 5b5aba4f | blueswir1 | int h, int rw, int type, |
685 | 5b5aba4f | blueswir1 | int target_page_bits)
|
686 | caa4039c | j_mayer | { |
687 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
688 | add78955 | j_mayer | if (env->mmu_model & POWERPC_MMU_64)
|
689 | 5b5aba4f | blueswir1 | return find_pte64(ctx, h, rw, type, target_page_bits);
|
690 | caa4039c | j_mayer | #endif
|
691 | caa4039c | j_mayer | |
692 | 5b5aba4f | blueswir1 | return find_pte32(ctx, h, rw, type, target_page_bits);
|
693 | caa4039c | j_mayer | } |
694 | caa4039c | j_mayer | |
695 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
696 | 8eee0af9 | blueswir1 | static ppc_slb_t *slb_get_entry(CPUPPCState *env, int nr) |
697 | eacc3249 | j_mayer | { |
698 | 8eee0af9 | blueswir1 | ppc_slb_t *retval = &env->slb[nr]; |
699 | 8eee0af9 | blueswir1 | |
700 | 8eee0af9 | blueswir1 | #if 0 // XXX implement bridge mode?
|
701 | 8eee0af9 | blueswir1 | if (env->spr[SPR_ASR] & 1) {
|
702 | 8eee0af9 | blueswir1 | target_phys_addr_t sr_base;
|
703 | 8eee0af9 | blueswir1 | |
704 | 8eee0af9 | blueswir1 | sr_base = env->spr[SPR_ASR] & 0xfffffffffffff000;
|
705 | 8eee0af9 | blueswir1 | sr_base += (12 * nr);
|
706 | 8eee0af9 | blueswir1 | |
707 | 8eee0af9 | blueswir1 | retval->tmp64 = ldq_phys(sr_base);
|
708 | 8eee0af9 | blueswir1 | retval->tmp = ldl_phys(sr_base + 8);
|
709 | 8eee0af9 | blueswir1 | }
|
710 | 8eee0af9 | blueswir1 | #endif
|
711 | 8eee0af9 | blueswir1 | |
712 | 8eee0af9 | blueswir1 | return retval;
|
713 | eacc3249 | j_mayer | } |
714 | eacc3249 | j_mayer | |
715 | 8eee0af9 | blueswir1 | static void slb_set_entry(CPUPPCState *env, int nr, ppc_slb_t *slb) |
716 | eacc3249 | j_mayer | { |
717 | 8eee0af9 | blueswir1 | ppc_slb_t *entry = &env->slb[nr]; |
718 | 8eee0af9 | blueswir1 | |
719 | 8eee0af9 | blueswir1 | if (slb == entry)
|
720 | 8eee0af9 | blueswir1 | return;
|
721 | 8eee0af9 | blueswir1 | |
722 | 8eee0af9 | blueswir1 | entry->tmp64 = slb->tmp64; |
723 | 8eee0af9 | blueswir1 | entry->tmp = slb->tmp; |
724 | 8eee0af9 | blueswir1 | } |
725 | 8eee0af9 | blueswir1 | |
726 | 8eee0af9 | blueswir1 | static always_inline int slb_is_valid (ppc_slb_t *slb) |
727 | 8eee0af9 | blueswir1 | { |
728 | 8eee0af9 | blueswir1 | return (int)(slb->tmp64 & 0x0000000008000000ULL); |
729 | 8eee0af9 | blueswir1 | } |
730 | 8eee0af9 | blueswir1 | |
731 | 8eee0af9 | blueswir1 | static always_inline void slb_invalidate (ppc_slb_t *slb) |
732 | 8eee0af9 | blueswir1 | { |
733 | 8eee0af9 | blueswir1 | slb->tmp64 &= ~0x0000000008000000ULL;
|
734 | eacc3249 | j_mayer | } |
735 | eacc3249 | j_mayer | |
736 | a11b8151 | j_mayer | static always_inline int slb_lookup (CPUPPCState *env, target_ulong eaddr, |
737 | a11b8151 | j_mayer | target_ulong *vsid, |
738 | 5b5aba4f | blueswir1 | target_ulong *page_mask, int *attr,
|
739 | 5b5aba4f | blueswir1 | int *target_page_bits)
|
740 | caa4039c | j_mayer | { |
741 | caa4039c | j_mayer | target_ulong mask; |
742 | caa4039c | j_mayer | int n, ret;
|
743 | caa4039c | j_mayer | |
744 | caa4039c | j_mayer | ret = -5;
|
745 | 8eee0af9 | blueswir1 | LOG_SLB("%s: eaddr " ADDRX "\n", __func__, eaddr); |
746 | caa4039c | j_mayer | mask = 0x0000000000000000ULL; /* Avoid gcc warning */ |
747 | eacc3249 | j_mayer | for (n = 0; n < env->slb_nr; n++) { |
748 | 8eee0af9 | blueswir1 | ppc_slb_t *slb = slb_get_entry(env, n); |
749 | 8eee0af9 | blueswir1 | |
750 | 8eee0af9 | blueswir1 | LOG_SLB("%s: seg %d %016" PRIx64 " %08" |
751 | 8eee0af9 | blueswir1 | PRIx32 "\n", __func__, n, slb->tmp64, slb->tmp);
|
752 | 8eee0af9 | blueswir1 | if (slb_is_valid(slb)) {
|
753 | caa4039c | j_mayer | /* SLB entry is valid */
|
754 | 8eee0af9 | blueswir1 | if (slb->tmp & 0x8) { |
755 | 5b5aba4f | blueswir1 | /* 1 TB Segment */
|
756 | caa4039c | j_mayer | mask = 0xFFFF000000000000ULL;
|
757 | 5b5aba4f | blueswir1 | if (target_page_bits)
|
758 | 5b5aba4f | blueswir1 | *target_page_bits = 24; // XXX 16M pages? |
759 | 5b5aba4f | blueswir1 | } else {
|
760 | 5b5aba4f | blueswir1 | /* 256MB Segment */
|
761 | 5b5aba4f | blueswir1 | mask = 0xFFFFFFFFF0000000ULL;
|
762 | 5b5aba4f | blueswir1 | if (target_page_bits)
|
763 | 5b5aba4f | blueswir1 | *target_page_bits = TARGET_PAGE_BITS; |
764 | caa4039c | j_mayer | } |
765 | 8eee0af9 | blueswir1 | if ((eaddr & mask) == (slb->tmp64 & mask)) {
|
766 | caa4039c | j_mayer | /* SLB match */
|
767 | 8eee0af9 | blueswir1 | *vsid = ((slb->tmp64 << 24) | (slb->tmp >> 8)) & 0x0003FFFFFFFFFFFFULL; |
768 | caa4039c | j_mayer | *page_mask = ~mask; |
769 | 8eee0af9 | blueswir1 | *attr = slb->tmp & 0xFF;
|
770 | eacc3249 | j_mayer | ret = n; |
771 | caa4039c | j_mayer | break;
|
772 | caa4039c | j_mayer | } |
773 | caa4039c | j_mayer | } |
774 | caa4039c | j_mayer | } |
775 | caa4039c | j_mayer | |
776 | caa4039c | j_mayer | return ret;
|
777 | 79aceca5 | bellard | } |
778 | 12de9a39 | j_mayer | |
779 | eacc3249 | j_mayer | void ppc_slb_invalidate_all (CPUPPCState *env)
|
780 | eacc3249 | j_mayer | { |
781 | eacc3249 | j_mayer | int n, do_invalidate;
|
782 | eacc3249 | j_mayer | |
783 | eacc3249 | j_mayer | do_invalidate = 0;
|
784 | 2c1ee068 | j_mayer | /* XXX: Warning: slbia never invalidates the first segment */
|
785 | 2c1ee068 | j_mayer | for (n = 1; n < env->slb_nr; n++) { |
786 | 8eee0af9 | blueswir1 | ppc_slb_t *slb = slb_get_entry(env, n); |
787 | 8eee0af9 | blueswir1 | |
788 | 8eee0af9 | blueswir1 | if (slb_is_valid(slb)) {
|
789 | 8eee0af9 | blueswir1 | slb_invalidate(slb); |
790 | 8eee0af9 | blueswir1 | slb_set_entry(env, n, slb); |
791 | eacc3249 | j_mayer | /* XXX: given the fact that segment size is 256 MB or 1TB,
|
792 | eacc3249 | j_mayer | * and we still don't have a tlb_flush_mask(env, n, mask)
|
793 | eacc3249 | j_mayer | * in Qemu, we just invalidate all TLBs
|
794 | eacc3249 | j_mayer | */
|
795 | eacc3249 | j_mayer | do_invalidate = 1;
|
796 | eacc3249 | j_mayer | } |
797 | eacc3249 | j_mayer | } |
798 | eacc3249 | j_mayer | if (do_invalidate)
|
799 | eacc3249 | j_mayer | tlb_flush(env, 1);
|
800 | eacc3249 | j_mayer | } |
801 | eacc3249 | j_mayer | |
802 | eacc3249 | j_mayer | void ppc_slb_invalidate_one (CPUPPCState *env, uint64_t T0)
|
803 | eacc3249 | j_mayer | { |
804 | eacc3249 | j_mayer | target_ulong vsid, page_mask; |
805 | eacc3249 | j_mayer | int attr;
|
806 | eacc3249 | j_mayer | int n;
|
807 | eacc3249 | j_mayer | |
808 | 5b5aba4f | blueswir1 | n = slb_lookup(env, T0, &vsid, &page_mask, &attr, NULL);
|
809 | eacc3249 | j_mayer | if (n >= 0) { |
810 | 8eee0af9 | blueswir1 | ppc_slb_t *slb = slb_get_entry(env, n); |
811 | 8eee0af9 | blueswir1 | |
812 | 8eee0af9 | blueswir1 | if (slb_is_valid(slb)) {
|
813 | 8eee0af9 | blueswir1 | slb_invalidate(slb); |
814 | 8eee0af9 | blueswir1 | slb_set_entry(env, n, slb); |
815 | eacc3249 | j_mayer | /* XXX: given the fact that segment size is 256 MB or 1TB,
|
816 | eacc3249 | j_mayer | * and we still don't have a tlb_flush_mask(env, n, mask)
|
817 | eacc3249 | j_mayer | * in Qemu, we just invalidate all TLBs
|
818 | eacc3249 | j_mayer | */
|
819 | eacc3249 | j_mayer | tlb_flush(env, 1);
|
820 | eacc3249 | j_mayer | } |
821 | eacc3249 | j_mayer | } |
822 | eacc3249 | j_mayer | } |
823 | eacc3249 | j_mayer | |
824 | 12de9a39 | j_mayer | target_ulong ppc_load_slb (CPUPPCState *env, int slb_nr)
|
825 | 12de9a39 | j_mayer | { |
826 | 12de9a39 | j_mayer | target_ulong rt; |
827 | 8eee0af9 | blueswir1 | ppc_slb_t *slb = slb_get_entry(env, slb_nr); |
828 | 8eee0af9 | blueswir1 | |
829 | 8eee0af9 | blueswir1 | if (slb_is_valid(slb)) {
|
830 | 12de9a39 | j_mayer | /* SLB entry is valid */
|
831 | 12de9a39 | j_mayer | /* Copy SLB bits 62:88 to Rt 37:63 (VSID 23:49) */
|
832 | 8eee0af9 | blueswir1 | rt = slb->tmp >> 8; /* 65:88 => 40:63 */ |
833 | 8eee0af9 | blueswir1 | rt |= (slb->tmp64 & 0x7) << 24; /* 62:64 => 37:39 */ |
834 | 12de9a39 | j_mayer | /* Copy SLB bits 89:92 to Rt 33:36 (KsKpNL) */
|
835 | 8eee0af9 | blueswir1 | rt |= ((slb->tmp >> 4) & 0xF) << 27; |
836 | 12de9a39 | j_mayer | } else {
|
837 | 12de9a39 | j_mayer | rt = 0;
|
838 | 12de9a39 | j_mayer | } |
839 | 8eee0af9 | blueswir1 | LOG_SLB("%s: %016" PRIx64 " %08" PRIx32 " => %d " |
840 | 8eee0af9 | blueswir1 | ADDRX "\n", __func__, slb->tmp64, slb->tmp, slb_nr, rt);
|
841 | 12de9a39 | j_mayer | |
842 | 12de9a39 | j_mayer | return rt;
|
843 | 12de9a39 | j_mayer | } |
844 | 12de9a39 | j_mayer | |
845 | f6b868fc | blueswir1 | void ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs)
|
846 | 12de9a39 | j_mayer | { |
847 | 8eee0af9 | blueswir1 | ppc_slb_t *slb; |
848 | 12de9a39 | j_mayer | |
849 | f6b868fc | blueswir1 | uint64_t vsid; |
850 | f6b868fc | blueswir1 | uint64_t esid; |
851 | f6b868fc | blueswir1 | int flags, valid, slb_nr;
|
852 | f6b868fc | blueswir1 | |
853 | f6b868fc | blueswir1 | vsid = rs >> 12;
|
854 | f6b868fc | blueswir1 | flags = ((rs >> 8) & 0xf); |
855 | f6b868fc | blueswir1 | |
856 | f6b868fc | blueswir1 | esid = rb >> 28;
|
857 | f6b868fc | blueswir1 | valid = (rb & (1 << 27)); |
858 | f6b868fc | blueswir1 | slb_nr = rb & 0xfff;
|
859 | f6b868fc | blueswir1 | |
860 | 8eee0af9 | blueswir1 | slb = slb_get_entry(env, slb_nr); |
861 | 8eee0af9 | blueswir1 | slb->tmp64 = (esid << 28) | valid | (vsid >> 24); |
862 | 8eee0af9 | blueswir1 | slb->tmp = (vsid << 8) | (flags << 3); |
863 | f6b868fc | blueswir1 | |
864 | 8eee0af9 | blueswir1 | LOG_SLB("%s: %d " ADDRX " - " ADDRX " => %016" PRIx64 |
865 | 6b542af7 | j_mayer | " %08" PRIx32 "\n", __func__, |
866 | 8eee0af9 | blueswir1 | slb_nr, rb, rs, tmp64, tmp); |
867 | f6b868fc | blueswir1 | |
868 | 8eee0af9 | blueswir1 | slb_set_entry(env, slb_nr, slb); |
869 | 12de9a39 | j_mayer | } |
870 | caa4039c | j_mayer | #endif /* defined(TARGET_PPC64) */ |
871 | 79aceca5 | bellard | |
872 | 9a64fbe4 | bellard | /* Perform segment based translation */
|
873 | b068d6a7 | j_mayer | static always_inline target_phys_addr_t get_pgaddr (target_phys_addr_t sdr1,
|
874 | b068d6a7 | j_mayer | int sdr_sh,
|
875 | b068d6a7 | j_mayer | target_phys_addr_t hash, |
876 | b068d6a7 | j_mayer | target_phys_addr_t mask) |
877 | 12de9a39 | j_mayer | { |
878 | 6f2d8978 | j_mayer | return (sdr1 & ((target_phys_addr_t)(-1ULL) << sdr_sh)) | (hash & mask); |
879 | 12de9a39 | j_mayer | } |
880 | 12de9a39 | j_mayer | |
881 | a11b8151 | j_mayer | static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx, |
882 | a11b8151 | j_mayer | target_ulong eaddr, int rw, int type) |
883 | 79aceca5 | bellard | { |
884 | 12de9a39 | j_mayer | target_phys_addr_t sdr, hash, mask, sdr_mask, htab_mask; |
885 | caa4039c | j_mayer | target_ulong sr, vsid, vsid_mask, pgidx, page_mask; |
886 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
887 | caa4039c | j_mayer | int attr;
|
888 | 9a64fbe4 | bellard | #endif
|
889 | 5b5aba4f | blueswir1 | int ds, vsid_sh, sdr_sh, pr, target_page_bits;
|
890 | caa4039c | j_mayer | int ret, ret2;
|
891 | caa4039c | j_mayer | |
892 | 0411a972 | j_mayer | pr = msr_pr; |
893 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
894 | add78955 | j_mayer | if (env->mmu_model & POWERPC_MMU_64) {
|
895 | d12d51d5 | aliguori | LOG_MMU("Check SLBs\n");
|
896 | 5b5aba4f | blueswir1 | ret = slb_lookup(env, eaddr, &vsid, &page_mask, &attr, |
897 | 5b5aba4f | blueswir1 | &target_page_bits); |
898 | caa4039c | j_mayer | if (ret < 0) |
899 | caa4039c | j_mayer | return ret;
|
900 | 0411a972 | j_mayer | ctx->key = ((attr & 0x40) && (pr != 0)) || |
901 | 0411a972 | j_mayer | ((attr & 0x80) && (pr == 0)) ? 1 : 0; |
902 | caa4039c | j_mayer | ds = 0;
|
903 | 5b5aba4f | blueswir1 | ctx->nx = attr & 0x10 ? 1 : 0; |
904 | 5b5aba4f | blueswir1 | ctx->eaddr = eaddr; |
905 | caa4039c | j_mayer | vsid_mask = 0x00003FFFFFFFFF80ULL;
|
906 | caa4039c | j_mayer | vsid_sh = 7;
|
907 | caa4039c | j_mayer | sdr_sh = 18;
|
908 | caa4039c | j_mayer | sdr_mask = 0x3FF80;
|
909 | caa4039c | j_mayer | } else
|
910 | caa4039c | j_mayer | #endif /* defined(TARGET_PPC64) */ |
911 | caa4039c | j_mayer | { |
912 | caa4039c | j_mayer | sr = env->sr[eaddr >> 28];
|
913 | caa4039c | j_mayer | page_mask = 0x0FFFFFFF;
|
914 | 0411a972 | j_mayer | ctx->key = (((sr & 0x20000000) && (pr != 0)) || |
915 | 0411a972 | j_mayer | ((sr & 0x40000000) && (pr == 0))) ? 1 : 0; |
916 | caa4039c | j_mayer | ds = sr & 0x80000000 ? 1 : 0; |
917 | b227a8e9 | j_mayer | ctx->nx = sr & 0x10000000 ? 1 : 0; |
918 | caa4039c | j_mayer | vsid = sr & 0x00FFFFFF;
|
919 | caa4039c | j_mayer | vsid_mask = 0x01FFFFC0;
|
920 | caa4039c | j_mayer | vsid_sh = 6;
|
921 | caa4039c | j_mayer | sdr_sh = 16;
|
922 | caa4039c | j_mayer | sdr_mask = 0xFFC0;
|
923 | 5b5aba4f | blueswir1 | target_page_bits = TARGET_PAGE_BITS; |
924 | d12d51d5 | aliguori | LOG_MMU("Check segment v=" ADDRX " %d " ADDRX |
925 | 6b542af7 | j_mayer | " nip=" ADDRX " lr=" ADDRX " ir=%d dr=%d pr=%d %d t=%d\n", |
926 | caa4039c | j_mayer | eaddr, (int)(eaddr >> 28), sr, env->nip, |
927 | 0411a972 | j_mayer | env->lr, (int)msr_ir, (int)msr_dr, pr != 0 ? 1 : 0, |
928 | 0411a972 | j_mayer | rw, type); |
929 | caa4039c | j_mayer | } |
930 | d12d51d5 | aliguori | LOG_MMU("pte segment: key=%d ds %d nx %d vsid " ADDRX "\n", |
931 | b227a8e9 | j_mayer | ctx->key, ds, ctx->nx, vsid); |
932 | caa4039c | j_mayer | ret = -1;
|
933 | caa4039c | j_mayer | if (!ds) {
|
934 | 9a64fbe4 | bellard | /* Check if instruction fetch is allowed, if needed */
|
935 | b227a8e9 | j_mayer | if (type != ACCESS_CODE || ctx->nx == 0) { |
936 | 9a64fbe4 | bellard | /* Page address translation */
|
937 | 76a66253 | j_mayer | /* Primary table address */
|
938 | 76a66253 | j_mayer | sdr = env->sdr1; |
939 | 5b5aba4f | blueswir1 | pgidx = (eaddr & page_mask) >> target_page_bits; |
940 | 12de9a39 | j_mayer | #if defined(TARGET_PPC64)
|
941 | add78955 | j_mayer | if (env->mmu_model & POWERPC_MMU_64) {
|
942 | 12de9a39 | j_mayer | htab_mask = 0x0FFFFFFF >> (28 - (sdr & 0x1F)); |
943 | 12de9a39 | j_mayer | /* XXX: this is false for 1 TB segments */
|
944 | 12de9a39 | j_mayer | hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask; |
945 | 12de9a39 | j_mayer | } else
|
946 | 12de9a39 | j_mayer | #endif
|
947 | 12de9a39 | j_mayer | { |
948 | 12de9a39 | j_mayer | htab_mask = sdr & 0x000001FF;
|
949 | 12de9a39 | j_mayer | hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask; |
950 | 12de9a39 | j_mayer | } |
951 | 12de9a39 | j_mayer | mask = (htab_mask << sdr_sh) | sdr_mask; |
952 | d12d51d5 | aliguori | LOG_MMU("sdr " PADDRX " sh %d hash " PADDRX |
953 | 6b542af7 | j_mayer | " mask " PADDRX " " ADDRX "\n", |
954 | 6b542af7 | j_mayer | sdr, sdr_sh, hash, mask, page_mask); |
955 | caa4039c | j_mayer | ctx->pg_addr[0] = get_pgaddr(sdr, sdr_sh, hash, mask);
|
956 | 76a66253 | j_mayer | /* Secondary table address */
|
957 | caa4039c | j_mayer | hash = (~hash) & vsid_mask; |
958 | d12d51d5 | aliguori | LOG_MMU("sdr " PADDRX " sh %d hash " PADDRX |
959 | 6b542af7 | j_mayer | " mask " PADDRX "\n", |
960 | 6b542af7 | j_mayer | sdr, sdr_sh, hash, mask); |
961 | caa4039c | j_mayer | ctx->pg_addr[1] = get_pgaddr(sdr, sdr_sh, hash, mask);
|
962 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
963 | add78955 | j_mayer | if (env->mmu_model & POWERPC_MMU_64) {
|
964 | caa4039c | j_mayer | /* Only 5 bits of the page index are used in the AVPN */
|
965 | 5b5aba4f | blueswir1 | if (target_page_bits > 23) { |
966 | 5b5aba4f | blueswir1 | ctx->ptem = (vsid << 12) |
|
967 | 5b5aba4f | blueswir1 | ((pgidx << (target_page_bits - 16)) & 0xF80); |
968 | 5b5aba4f | blueswir1 | } else {
|
969 | 5b5aba4f | blueswir1 | ctx->ptem = (vsid << 12) | ((pgidx >> 4) & 0x0F80); |
970 | 5b5aba4f | blueswir1 | } |
971 | caa4039c | j_mayer | } else
|
972 | caa4039c | j_mayer | #endif
|
973 | caa4039c | j_mayer | { |
974 | caa4039c | j_mayer | ctx->ptem = (vsid << 7) | (pgidx >> 10); |
975 | caa4039c | j_mayer | } |
976 | 76a66253 | j_mayer | /* Initialize real address with an invalid value */
|
977 | 6f2d8978 | j_mayer | ctx->raddr = (target_phys_addr_t)-1ULL;
|
978 | 7dbe11ac | j_mayer | if (unlikely(env->mmu_model == POWERPC_MMU_SOFT_6xx ||
|
979 | 7dbe11ac | j_mayer | env->mmu_model == POWERPC_MMU_SOFT_74xx)) { |
980 | 76a66253 | j_mayer | /* Software TLB search */
|
981 | 76a66253 | j_mayer | ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type); |
982 | 76a66253 | j_mayer | } else {
|
983 | d12d51d5 | aliguori | LOG_MMU("0 sdr1=" PADDRX " vsid=" ADDRX " " |
984 | 6b542af7 | j_mayer | "api=" ADDRX " hash=" PADDRX |
985 | 6b542af7 | j_mayer | " pg_addr=" PADDRX "\n", |
986 | 6b542af7 | j_mayer | sdr, vsid, pgidx, hash, ctx->pg_addr[0]);
|
987 | 76a66253 | j_mayer | /* Primary table lookup */
|
988 | 5b5aba4f | blueswir1 | ret = find_pte(env, ctx, 0, rw, type, target_page_bits);
|
989 | 76a66253 | j_mayer | if (ret < 0) { |
990 | 76a66253 | j_mayer | /* Secondary table lookup */
|
991 | d12d51d5 | aliguori | if (eaddr != 0xEFFFFFFF) |
992 | d12d51d5 | aliguori | LOG_MMU("1 sdr1=" PADDRX " vsid=" ADDRX " " |
993 | 6b542af7 | j_mayer | "api=" ADDRX " hash=" PADDRX |
994 | 6b542af7 | j_mayer | " pg_addr=" PADDRX "\n", |
995 | 6b542af7 | j_mayer | sdr, vsid, pgidx, hash, ctx->pg_addr[1]);
|
996 | 5b5aba4f | blueswir1 | ret2 = find_pte(env, ctx, 1, rw, type,
|
997 | 5b5aba4f | blueswir1 | target_page_bits); |
998 | 76a66253 | j_mayer | if (ret2 != -1) |
999 | 76a66253 | j_mayer | ret = ret2; |
1000 | 76a66253 | j_mayer | } |
1001 | 9a64fbe4 | bellard | } |
1002 | 0411a972 | j_mayer | #if defined (DUMP_PAGE_TABLES)
|
1003 | 93fcfe39 | aliguori | if (qemu_log_enabled()) {
|
1004 | b33c17e1 | j_mayer | target_phys_addr_t curaddr; |
1005 | b33c17e1 | j_mayer | uint32_t a0, a1, a2, a3; |
1006 | 93fcfe39 | aliguori | qemu_log("Page table: " PADDRX " len " PADDRX "\n", |
1007 | 93fcfe39 | aliguori | sdr, mask + 0x80);
|
1008 | b33c17e1 | j_mayer | for (curaddr = sdr; curaddr < (sdr + mask + 0x80); |
1009 | b33c17e1 | j_mayer | curaddr += 16) {
|
1010 | b33c17e1 | j_mayer | a0 = ldl_phys(curaddr); |
1011 | b33c17e1 | j_mayer | a1 = ldl_phys(curaddr + 4);
|
1012 | b33c17e1 | j_mayer | a2 = ldl_phys(curaddr + 8);
|
1013 | b33c17e1 | j_mayer | a3 = ldl_phys(curaddr + 12);
|
1014 | b33c17e1 | j_mayer | if (a0 != 0 || a1 != 0 || a2 != 0 || a3 != 0) { |
1015 | 93fcfe39 | aliguori | qemu_log(PADDRX ": %08x %08x %08x %08x\n",
|
1016 | 93fcfe39 | aliguori | curaddr, a0, a1, a2, a3); |
1017 | 12de9a39 | j_mayer | } |
1018 | b33c17e1 | j_mayer | } |
1019 | b33c17e1 | j_mayer | } |
1020 | 12de9a39 | j_mayer | #endif
|
1021 | 9a64fbe4 | bellard | } else {
|
1022 | d12d51d5 | aliguori | LOG_MMU("No access allowed\n");
|
1023 | 76a66253 | j_mayer | ret = -3;
|
1024 | 9a64fbe4 | bellard | } |
1025 | 9a64fbe4 | bellard | } else {
|
1026 | d12d51d5 | aliguori | LOG_MMU("direct store...\n");
|
1027 | 9a64fbe4 | bellard | /* Direct-store segment : absolutely *BUGGY* for now */
|
1028 | 9a64fbe4 | bellard | switch (type) {
|
1029 | 9a64fbe4 | bellard | case ACCESS_INT:
|
1030 | 9a64fbe4 | bellard | /* Integer load/store : only access allowed */
|
1031 | 9a64fbe4 | bellard | break;
|
1032 | 9a64fbe4 | bellard | case ACCESS_CODE:
|
1033 | 9a64fbe4 | bellard | /* No code fetch is allowed in direct-store areas */
|
1034 | 9a64fbe4 | bellard | return -4; |
1035 | 9a64fbe4 | bellard | case ACCESS_FLOAT:
|
1036 | 9a64fbe4 | bellard | /* Floating point load/store */
|
1037 | 9a64fbe4 | bellard | return -4; |
1038 | 9a64fbe4 | bellard | case ACCESS_RES:
|
1039 | 9a64fbe4 | bellard | /* lwarx, ldarx or srwcx. */
|
1040 | 9a64fbe4 | bellard | return -4; |
1041 | 9a64fbe4 | bellard | case ACCESS_CACHE:
|
1042 | 9a64fbe4 | bellard | /* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi */
|
1043 | 9a64fbe4 | bellard | /* Should make the instruction do no-op.
|
1044 | 9a64fbe4 | bellard | * As it already do no-op, it's quite easy :-)
|
1045 | 9a64fbe4 | bellard | */
|
1046 | 76a66253 | j_mayer | ctx->raddr = eaddr; |
1047 | 9a64fbe4 | bellard | return 0; |
1048 | 9a64fbe4 | bellard | case ACCESS_EXT:
|
1049 | 9a64fbe4 | bellard | /* eciwx or ecowx */
|
1050 | 9a64fbe4 | bellard | return -4; |
1051 | 9a64fbe4 | bellard | default:
|
1052 | 93fcfe39 | aliguori | qemu_log("ERROR: instruction should not need "
|
1053 | 9a64fbe4 | bellard | "address translation\n");
|
1054 | 9a64fbe4 | bellard | return -4; |
1055 | 9a64fbe4 | bellard | } |
1056 | 76a66253 | j_mayer | if ((rw == 1 || ctx->key != 1) && (rw == 0 || ctx->key != 0)) { |
1057 | 76a66253 | j_mayer | ctx->raddr = eaddr; |
1058 | 9a64fbe4 | bellard | ret = 2;
|
1059 | 9a64fbe4 | bellard | } else {
|
1060 | 9a64fbe4 | bellard | ret = -2;
|
1061 | 9a64fbe4 | bellard | } |
1062 | 79aceca5 | bellard | } |
1063 | 9a64fbe4 | bellard | |
1064 | 9a64fbe4 | bellard | return ret;
|
1065 | 79aceca5 | bellard | } |
1066 | 79aceca5 | bellard | |
1067 | c294fc58 | j_mayer | /* Generic TLB check function for embedded PowerPC implementations */
|
1068 | a11b8151 | j_mayer | static always_inline int ppcemb_tlb_check (CPUState *env, ppcemb_tlb_t *tlb, |
1069 | a11b8151 | j_mayer | target_phys_addr_t *raddrp, |
1070 | a11b8151 | j_mayer | target_ulong address, |
1071 | a11b8151 | j_mayer | uint32_t pid, int ext, int i) |
1072 | c294fc58 | j_mayer | { |
1073 | c294fc58 | j_mayer | target_ulong mask; |
1074 | c294fc58 | j_mayer | |
1075 | c294fc58 | j_mayer | /* Check valid flag */
|
1076 | c294fc58 | j_mayer | if (!(tlb->prot & PAGE_VALID)) {
|
1077 | 93fcfe39 | aliguori | qemu_log("%s: TLB %d not valid\n", __func__, i);
|
1078 | c294fc58 | j_mayer | return -1; |
1079 | c294fc58 | j_mayer | } |
1080 | c294fc58 | j_mayer | mask = ~(tlb->size - 1);
|
1081 | d12d51d5 | aliguori | LOG_SWTLB("%s: TLB %d address " ADDRX " PID %u <=> " ADDRX |
1082 | 6b542af7 | j_mayer | " " ADDRX " %u\n", |
1083 | 6b542af7 | j_mayer | __func__, i, address, pid, tlb->EPN, mask, (uint32_t)tlb->PID); |
1084 | c294fc58 | j_mayer | /* Check PID */
|
1085 | 36081602 | j_mayer | if (tlb->PID != 0 && tlb->PID != pid) |
1086 | c294fc58 | j_mayer | return -1; |
1087 | c294fc58 | j_mayer | /* Check effective address */
|
1088 | c294fc58 | j_mayer | if ((address & mask) != tlb->EPN)
|
1089 | c294fc58 | j_mayer | return -1; |
1090 | c294fc58 | j_mayer | *raddrp = (tlb->RPN & mask) | (address & ~mask); |
1091 | 9706285b | j_mayer | #if (TARGET_PHYS_ADDR_BITS >= 36) |
1092 | 36081602 | j_mayer | if (ext) {
|
1093 | 36081602 | j_mayer | /* Extend the physical address to 36 bits */
|
1094 | 36081602 | j_mayer | *raddrp |= (target_phys_addr_t)(tlb->RPN & 0xF) << 32; |
1095 | 36081602 | j_mayer | } |
1096 | 9706285b | j_mayer | #endif
|
1097 | c294fc58 | j_mayer | |
1098 | c294fc58 | j_mayer | return 0; |
1099 | c294fc58 | j_mayer | } |
1100 | c294fc58 | j_mayer | |
1101 | c294fc58 | j_mayer | /* Generic TLB search function for PowerPC embedded implementations */
|
1102 | 36081602 | j_mayer | int ppcemb_tlb_search (CPUPPCState *env, target_ulong address, uint32_t pid)
|
1103 | c294fc58 | j_mayer | { |
1104 | c294fc58 | j_mayer | ppcemb_tlb_t *tlb; |
1105 | c294fc58 | j_mayer | target_phys_addr_t raddr; |
1106 | c294fc58 | j_mayer | int i, ret;
|
1107 | c294fc58 | j_mayer | |
1108 | c294fc58 | j_mayer | /* Default return value is no match */
|
1109 | c294fc58 | j_mayer | ret = -1;
|
1110 | a750fc0b | j_mayer | for (i = 0; i < env->nb_tlb; i++) { |
1111 | c294fc58 | j_mayer | tlb = &env->tlb[i].tlbe; |
1112 | 36081602 | j_mayer | if (ppcemb_tlb_check(env, tlb, &raddr, address, pid, 0, i) == 0) { |
1113 | c294fc58 | j_mayer | ret = i; |
1114 | c294fc58 | j_mayer | break;
|
1115 | c294fc58 | j_mayer | } |
1116 | c294fc58 | j_mayer | } |
1117 | c294fc58 | j_mayer | |
1118 | c294fc58 | j_mayer | return ret;
|
1119 | c294fc58 | j_mayer | } |
1120 | c294fc58 | j_mayer | |
1121 | daf4f96e | j_mayer | /* Helpers specific to PowerPC 40x implementations */
|
1122 | a11b8151 | j_mayer | static always_inline void ppc4xx_tlb_invalidate_all (CPUState *env) |
1123 | a750fc0b | j_mayer | { |
1124 | a750fc0b | j_mayer | ppcemb_tlb_t *tlb; |
1125 | a750fc0b | j_mayer | int i;
|
1126 | a750fc0b | j_mayer | |
1127 | a750fc0b | j_mayer | for (i = 0; i < env->nb_tlb; i++) { |
1128 | a750fc0b | j_mayer | tlb = &env->tlb[i].tlbe; |
1129 | daf4f96e | j_mayer | tlb->prot &= ~PAGE_VALID; |
1130 | a750fc0b | j_mayer | } |
1131 | daf4f96e | j_mayer | tlb_flush(env, 1);
|
1132 | a750fc0b | j_mayer | } |
1133 | a750fc0b | j_mayer | |
1134 | a11b8151 | j_mayer | static always_inline void ppc4xx_tlb_invalidate_virt (CPUState *env, |
1135 | a11b8151 | j_mayer | target_ulong eaddr, |
1136 | a11b8151 | j_mayer | uint32_t pid) |
1137 | 0a032cbe | j_mayer | { |
1138 | daf4f96e | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
1139 | 0a032cbe | j_mayer | ppcemb_tlb_t *tlb; |
1140 | daf4f96e | j_mayer | target_phys_addr_t raddr; |
1141 | daf4f96e | j_mayer | target_ulong page, end; |
1142 | 0a032cbe | j_mayer | int i;
|
1143 | 0a032cbe | j_mayer | |
1144 | 0a032cbe | j_mayer | for (i = 0; i < env->nb_tlb; i++) { |
1145 | 0a032cbe | j_mayer | tlb = &env->tlb[i].tlbe; |
1146 | daf4f96e | j_mayer | if (ppcemb_tlb_check(env, tlb, &raddr, eaddr, pid, 0, i) == 0) { |
1147 | 0a032cbe | j_mayer | end = tlb->EPN + tlb->size; |
1148 | 0a032cbe | j_mayer | for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
|
1149 | 0a032cbe | j_mayer | tlb_flush_page(env, page); |
1150 | 0a032cbe | j_mayer | tlb->prot &= ~PAGE_VALID; |
1151 | daf4f96e | j_mayer | break;
|
1152 | 0a032cbe | j_mayer | } |
1153 | 0a032cbe | j_mayer | } |
1154 | daf4f96e | j_mayer | #else
|
1155 | daf4f96e | j_mayer | ppc4xx_tlb_invalidate_all(env); |
1156 | daf4f96e | j_mayer | #endif
|
1157 | 0a032cbe | j_mayer | } |
1158 | 0a032cbe | j_mayer | |
1159 | 93220573 | aurel32 | static int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx, |
1160 | e96efcfc | j_mayer | target_ulong address, int rw, int access_type) |
1161 | a8dea12f | j_mayer | { |
1162 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
1163 | a8dea12f | j_mayer | target_phys_addr_t raddr; |
1164 | 0411a972 | j_mayer | int i, ret, zsel, zpr, pr;
|
1165 | 3b46e624 | ths | |
1166 | c55e9aef | j_mayer | ret = -1;
|
1167 | 6f2d8978 | j_mayer | raddr = (target_phys_addr_t)-1ULL;
|
1168 | 0411a972 | j_mayer | pr = msr_pr; |
1169 | a8dea12f | j_mayer | for (i = 0; i < env->nb_tlb; i++) { |
1170 | a8dea12f | j_mayer | tlb = &env->tlb[i].tlbe; |
1171 | 36081602 | j_mayer | if (ppcemb_tlb_check(env, tlb, &raddr, address,
|
1172 | 36081602 | j_mayer | env->spr[SPR_40x_PID], 0, i) < 0) |
1173 | a8dea12f | j_mayer | continue;
|
1174 | a8dea12f | j_mayer | zsel = (tlb->attr >> 4) & 0xF; |
1175 | a8dea12f | j_mayer | zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3; |
1176 | d12d51d5 | aliguori | LOG_SWTLB("%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",
|
1177 | a8dea12f | j_mayer | __func__, i, zsel, zpr, rw, tlb->attr); |
1178 | b227a8e9 | j_mayer | /* Check execute enable bit */
|
1179 | b227a8e9 | j_mayer | switch (zpr) {
|
1180 | b227a8e9 | j_mayer | case 0x2: |
1181 | 0411a972 | j_mayer | if (pr != 0) |
1182 | b227a8e9 | j_mayer | goto check_perms;
|
1183 | b227a8e9 | j_mayer | /* No break here */
|
1184 | b227a8e9 | j_mayer | case 0x3: |
1185 | b227a8e9 | j_mayer | /* All accesses granted */
|
1186 | b227a8e9 | j_mayer | ctx->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; |
1187 | b227a8e9 | j_mayer | ret = 0;
|
1188 | b227a8e9 | j_mayer | break;
|
1189 | b227a8e9 | j_mayer | case 0x0: |
1190 | 0411a972 | j_mayer | if (pr != 0) { |
1191 | b227a8e9 | j_mayer | ctx->prot = 0;
|
1192 | b227a8e9 | j_mayer | ret = -2;
|
1193 | a8dea12f | j_mayer | break;
|
1194 | a8dea12f | j_mayer | } |
1195 | b227a8e9 | j_mayer | /* No break here */
|
1196 | b227a8e9 | j_mayer | case 0x1: |
1197 | b227a8e9 | j_mayer | check_perms:
|
1198 | b227a8e9 | j_mayer | /* Check from TLB entry */
|
1199 | b227a8e9 | j_mayer | /* XXX: there is a problem here or in the TLB fill code... */
|
1200 | b227a8e9 | j_mayer | ctx->prot = tlb->prot; |
1201 | b227a8e9 | j_mayer | ctx->prot |= PAGE_EXEC; |
1202 | b227a8e9 | j_mayer | ret = check_prot(ctx->prot, rw, access_type); |
1203 | b227a8e9 | j_mayer | break;
|
1204 | a8dea12f | j_mayer | } |
1205 | a8dea12f | j_mayer | if (ret >= 0) { |
1206 | a8dea12f | j_mayer | ctx->raddr = raddr; |
1207 | d12d51d5 | aliguori | LOG_SWTLB("%s: access granted " ADDRX " => " PADDRX |
1208 | c55e9aef | j_mayer | " %d %d\n", __func__, address, ctx->raddr, ctx->prot,
|
1209 | c55e9aef | j_mayer | ret); |
1210 | c55e9aef | j_mayer | return 0; |
1211 | a8dea12f | j_mayer | } |
1212 | a8dea12f | j_mayer | } |
1213 | d12d51d5 | aliguori | LOG_SWTLB("%s: access refused " ADDRX " => " PADDRX |
1214 | c55e9aef | j_mayer | " %d %d\n", __func__, address, raddr, ctx->prot,
|
1215 | c55e9aef | j_mayer | ret); |
1216 | 3b46e624 | ths | |
1217 | a8dea12f | j_mayer | return ret;
|
1218 | a8dea12f | j_mayer | } |
1219 | a8dea12f | j_mayer | |
1220 | c294fc58 | j_mayer | void store_40x_sler (CPUPPCState *env, uint32_t val)
|
1221 | c294fc58 | j_mayer | { |
1222 | c294fc58 | j_mayer | /* XXX: TO BE FIXED */
|
1223 | c294fc58 | j_mayer | if (val != 0x00000000) { |
1224 | c294fc58 | j_mayer | cpu_abort(env, "Little-endian regions are not supported by now\n");
|
1225 | c294fc58 | j_mayer | } |
1226 | c294fc58 | j_mayer | env->spr[SPR_405_SLER] = val; |
1227 | c294fc58 | j_mayer | } |
1228 | c294fc58 | j_mayer | |
1229 | 93220573 | aurel32 | static int mmubooke_get_physical_address (CPUState *env, mmu_ctx_t *ctx, |
1230 | 93220573 | aurel32 | target_ulong address, int rw,
|
1231 | 93220573 | aurel32 | int access_type)
|
1232 | 5eb7995e | j_mayer | { |
1233 | 5eb7995e | j_mayer | ppcemb_tlb_t *tlb; |
1234 | 5eb7995e | j_mayer | target_phys_addr_t raddr; |
1235 | 5eb7995e | j_mayer | int i, prot, ret;
|
1236 | 5eb7995e | j_mayer | |
1237 | 5eb7995e | j_mayer | ret = -1;
|
1238 | 6f2d8978 | j_mayer | raddr = (target_phys_addr_t)-1ULL;
|
1239 | 5eb7995e | j_mayer | for (i = 0; i < env->nb_tlb; i++) { |
1240 | 5eb7995e | j_mayer | tlb = &env->tlb[i].tlbe; |
1241 | 5eb7995e | j_mayer | if (ppcemb_tlb_check(env, tlb, &raddr, address,
|
1242 | 5eb7995e | j_mayer | env->spr[SPR_BOOKE_PID], 1, i) < 0) |
1243 | 5eb7995e | j_mayer | continue;
|
1244 | 0411a972 | j_mayer | if (msr_pr != 0) |
1245 | 5eb7995e | j_mayer | prot = tlb->prot & 0xF;
|
1246 | 5eb7995e | j_mayer | else
|
1247 | 5eb7995e | j_mayer | prot = (tlb->prot >> 4) & 0xF; |
1248 | 5eb7995e | j_mayer | /* Check the address space */
|
1249 | 5eb7995e | j_mayer | if (access_type == ACCESS_CODE) {
|
1250 | d26bfc9a | j_mayer | if (msr_ir != (tlb->attr & 1)) |
1251 | 5eb7995e | j_mayer | continue;
|
1252 | 5eb7995e | j_mayer | ctx->prot = prot; |
1253 | 5eb7995e | j_mayer | if (prot & PAGE_EXEC) {
|
1254 | 5eb7995e | j_mayer | ret = 0;
|
1255 | 5eb7995e | j_mayer | break;
|
1256 | 5eb7995e | j_mayer | } |
1257 | 5eb7995e | j_mayer | ret = -3;
|
1258 | 5eb7995e | j_mayer | } else {
|
1259 | d26bfc9a | j_mayer | if (msr_dr != (tlb->attr & 1)) |
1260 | 5eb7995e | j_mayer | continue;
|
1261 | 5eb7995e | j_mayer | ctx->prot = prot; |
1262 | 5eb7995e | j_mayer | if ((!rw && prot & PAGE_READ) || (rw && (prot & PAGE_WRITE))) {
|
1263 | 5eb7995e | j_mayer | ret = 0;
|
1264 | 5eb7995e | j_mayer | break;
|
1265 | 5eb7995e | j_mayer | } |
1266 | 5eb7995e | j_mayer | ret = -2;
|
1267 | 5eb7995e | j_mayer | } |
1268 | 5eb7995e | j_mayer | } |
1269 | 5eb7995e | j_mayer | if (ret >= 0) |
1270 | 5eb7995e | j_mayer | ctx->raddr = raddr; |
1271 | 5eb7995e | j_mayer | |
1272 | 5eb7995e | j_mayer | return ret;
|
1273 | 5eb7995e | j_mayer | } |
1274 | 5eb7995e | j_mayer | |
1275 | a11b8151 | j_mayer | static always_inline int check_physical (CPUState *env, mmu_ctx_t *ctx, |
1276 | a11b8151 | j_mayer | target_ulong eaddr, int rw)
|
1277 | 76a66253 | j_mayer | { |
1278 | 76a66253 | j_mayer | int in_plb, ret;
|
1279 | 3b46e624 | ths | |
1280 | 76a66253 | j_mayer | ctx->raddr = eaddr; |
1281 | b227a8e9 | j_mayer | ctx->prot = PAGE_READ | PAGE_EXEC; |
1282 | 76a66253 | j_mayer | ret = 0;
|
1283 | a750fc0b | j_mayer | switch (env->mmu_model) {
|
1284 | a750fc0b | j_mayer | case POWERPC_MMU_32B:
|
1285 | faadf50e | j_mayer | case POWERPC_MMU_601:
|
1286 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_6xx:
|
1287 | 7dbe11ac | j_mayer | case POWERPC_MMU_SOFT_74xx:
|
1288 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx:
|
1289 | b4095fed | j_mayer | case POWERPC_MMU_REAL:
|
1290 | 7dbe11ac | j_mayer | case POWERPC_MMU_BOOKE:
|
1291 | caa4039c | j_mayer | ctx->prot |= PAGE_WRITE; |
1292 | caa4039c | j_mayer | break;
|
1293 | caa4039c | j_mayer | #if defined(TARGET_PPC64)
|
1294 | add78955 | j_mayer | case POWERPC_MMU_620:
|
1295 | a750fc0b | j_mayer | case POWERPC_MMU_64B:
|
1296 | caa4039c | j_mayer | /* Real address are 60 bits long */
|
1297 | a750fc0b | j_mayer | ctx->raddr &= 0x0FFFFFFFFFFFFFFFULL;
|
1298 | caa4039c | j_mayer | ctx->prot |= PAGE_WRITE; |
1299 | caa4039c | j_mayer | break;
|
1300 | 9706285b | j_mayer | #endif
|
1301 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx_Z:
|
1302 | caa4039c | j_mayer | if (unlikely(msr_pe != 0)) { |
1303 | caa4039c | j_mayer | /* 403 family add some particular protections,
|
1304 | caa4039c | j_mayer | * using PBL/PBU registers for accesses with no translation.
|
1305 | caa4039c | j_mayer | */
|
1306 | caa4039c | j_mayer | in_plb = |
1307 | caa4039c | j_mayer | /* Check PLB validity */
|
1308 | caa4039c | j_mayer | (env->pb[0] < env->pb[1] && |
1309 | caa4039c | j_mayer | /* and address in plb area */
|
1310 | caa4039c | j_mayer | eaddr >= env->pb[0] && eaddr < env->pb[1]) || |
1311 | caa4039c | j_mayer | (env->pb[2] < env->pb[3] && |
1312 | caa4039c | j_mayer | eaddr >= env->pb[2] && eaddr < env->pb[3]) ? 1 : 0; |
1313 | caa4039c | j_mayer | if (in_plb ^ msr_px) {
|
1314 | caa4039c | j_mayer | /* Access in protected area */
|
1315 | caa4039c | j_mayer | if (rw == 1) { |
1316 | caa4039c | j_mayer | /* Access is not allowed */
|
1317 | caa4039c | j_mayer | ret = -2;
|
1318 | caa4039c | j_mayer | } |
1319 | caa4039c | j_mayer | } else {
|
1320 | caa4039c | j_mayer | /* Read-write access is allowed */
|
1321 | caa4039c | j_mayer | ctx->prot |= PAGE_WRITE; |
1322 | 76a66253 | j_mayer | } |
1323 | 76a66253 | j_mayer | } |
1324 | e1833e1f | j_mayer | break;
|
1325 | b4095fed | j_mayer | case POWERPC_MMU_MPC8xx:
|
1326 | b4095fed | j_mayer | /* XXX: TODO */
|
1327 | b4095fed | j_mayer | cpu_abort(env, "MPC8xx MMU model is not implemented\n");
|
1328 | b4095fed | j_mayer | break;
|
1329 | a750fc0b | j_mayer | case POWERPC_MMU_BOOKE_FSL:
|
1330 | caa4039c | j_mayer | /* XXX: TODO */
|
1331 | caa4039c | j_mayer | cpu_abort(env, "BookE FSL MMU model not implemented\n");
|
1332 | caa4039c | j_mayer | break;
|
1333 | caa4039c | j_mayer | default:
|
1334 | caa4039c | j_mayer | cpu_abort(env, "Unknown or invalid MMU model\n");
|
1335 | caa4039c | j_mayer | return -1; |
1336 | 76a66253 | j_mayer | } |
1337 | 76a66253 | j_mayer | |
1338 | 76a66253 | j_mayer | return ret;
|
1339 | 76a66253 | j_mayer | } |
1340 | 76a66253 | j_mayer | |
1341 | 76a66253 | j_mayer | int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr,
|
1342 | faadf50e | j_mayer | int rw, int access_type) |
1343 | 9a64fbe4 | bellard | { |
1344 | 9a64fbe4 | bellard | int ret;
|
1345 | 0411a972 | j_mayer | |
1346 | 514fb8c1 | bellard | #if 0
|
1347 | 93fcfe39 | aliguori | qemu_log("%s\n", __func__);
|
1348 | d9bce9d9 | j_mayer | #endif
|
1349 | 4b3686fa | bellard | if ((access_type == ACCESS_CODE && msr_ir == 0) || |
1350 | 4b3686fa | bellard | (access_type != ACCESS_CODE && msr_dr == 0)) {
|
1351 | 9a64fbe4 | bellard | /* No address translation */
|
1352 | 76a66253 | j_mayer | ret = check_physical(env, ctx, eaddr, rw); |
1353 | 9a64fbe4 | bellard | } else {
|
1354 | c55e9aef | j_mayer | ret = -1;
|
1355 | a750fc0b | j_mayer | switch (env->mmu_model) {
|
1356 | a750fc0b | j_mayer | case POWERPC_MMU_32B:
|
1357 | faadf50e | j_mayer | case POWERPC_MMU_601:
|
1358 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_6xx:
|
1359 | 7dbe11ac | j_mayer | case POWERPC_MMU_SOFT_74xx:
|
1360 | 94855937 | blueswir1 | /* Try to find a BAT */
|
1361 | 94855937 | blueswir1 | if (env->nb_BATs != 0) |
1362 | 94855937 | blueswir1 | ret = get_bat(env, ctx, eaddr, rw, access_type); |
1363 | c55e9aef | j_mayer | #if defined(TARGET_PPC64)
|
1364 | add78955 | j_mayer | case POWERPC_MMU_620:
|
1365 | a750fc0b | j_mayer | case POWERPC_MMU_64B:
|
1366 | c55e9aef | j_mayer | #endif
|
1367 | a8dea12f | j_mayer | if (ret < 0) { |
1368 | c55e9aef | j_mayer | /* We didn't match any BAT entry or don't have BATs */
|
1369 | a8dea12f | j_mayer | ret = get_segment(env, ctx, eaddr, rw, access_type); |
1370 | a8dea12f | j_mayer | } |
1371 | a8dea12f | j_mayer | break;
|
1372 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx:
|
1373 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx_Z:
|
1374 | 36081602 | j_mayer | ret = mmu40x_get_physical_address(env, ctx, eaddr, |
1375 | a8dea12f | j_mayer | rw, access_type); |
1376 | a8dea12f | j_mayer | break;
|
1377 | a750fc0b | j_mayer | case POWERPC_MMU_BOOKE:
|
1378 | 5eb7995e | j_mayer | ret = mmubooke_get_physical_address(env, ctx, eaddr, |
1379 | 5eb7995e | j_mayer | rw, access_type); |
1380 | 5eb7995e | j_mayer | break;
|
1381 | b4095fed | j_mayer | case POWERPC_MMU_MPC8xx:
|
1382 | b4095fed | j_mayer | /* XXX: TODO */
|
1383 | b4095fed | j_mayer | cpu_abort(env, "MPC8xx MMU model is not implemented\n");
|
1384 | b4095fed | j_mayer | break;
|
1385 | a750fc0b | j_mayer | case POWERPC_MMU_BOOKE_FSL:
|
1386 | c55e9aef | j_mayer | /* XXX: TODO */
|
1387 | c55e9aef | j_mayer | cpu_abort(env, "BookE FSL MMU model not implemented\n");
|
1388 | c55e9aef | j_mayer | return -1; |
1389 | b4095fed | j_mayer | case POWERPC_MMU_REAL:
|
1390 | b4095fed | j_mayer | cpu_abort(env, "PowerPC in real mode do not do any translation\n");
|
1391 | 2662a059 | j_mayer | return -1; |
1392 | c55e9aef | j_mayer | default:
|
1393 | c55e9aef | j_mayer | cpu_abort(env, "Unknown or invalid MMU model\n");
|
1394 | a8dea12f | j_mayer | return -1; |
1395 | 9a64fbe4 | bellard | } |
1396 | 9a64fbe4 | bellard | } |
1397 | 514fb8c1 | bellard | #if 0
|
1398 | 93fcfe39 | aliguori | qemu_log("%s address " ADDRX " => %d " PADDRX "\n",
|
1399 | c55e9aef | j_mayer | __func__, eaddr, ret, ctx->raddr);
|
1400 | 76a66253 | j_mayer | #endif
|
1401 | d9bce9d9 | j_mayer | |
1402 | 9a64fbe4 | bellard | return ret;
|
1403 | 9a64fbe4 | bellard | } |
1404 | 9a64fbe4 | bellard | |
1405 | 9b3c35e0 | j_mayer | target_phys_addr_t cpu_get_phys_page_debug (CPUState *env, target_ulong addr) |
1406 | a6b025d3 | bellard | { |
1407 | 76a66253 | j_mayer | mmu_ctx_t ctx; |
1408 | a6b025d3 | bellard | |
1409 | faadf50e | j_mayer | if (unlikely(get_physical_address(env, &ctx, addr, 0, ACCESS_INT) != 0)) |
1410 | a6b025d3 | bellard | return -1; |
1411 | 76a66253 | j_mayer | |
1412 | 76a66253 | j_mayer | return ctx.raddr & TARGET_PAGE_MASK;
|
1413 | a6b025d3 | bellard | } |
1414 | 9a64fbe4 | bellard | |
1415 | 9a64fbe4 | bellard | /* Perform address translation */
|
1416 | e96efcfc | j_mayer | int cpu_ppc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, |
1417 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu) |
1418 | 9a64fbe4 | bellard | { |
1419 | 76a66253 | j_mayer | mmu_ctx_t ctx; |
1420 | a541f297 | bellard | int access_type;
|
1421 | 9a64fbe4 | bellard | int ret = 0; |
1422 | d9bce9d9 | j_mayer | |
1423 | b769d8fe | bellard | if (rw == 2) { |
1424 | b769d8fe | bellard | /* code access */
|
1425 | b769d8fe | bellard | rw = 0;
|
1426 | b769d8fe | bellard | access_type = ACCESS_CODE; |
1427 | b769d8fe | bellard | } else {
|
1428 | b769d8fe | bellard | /* data access */
|
1429 | b4cec7b4 | aurel32 | access_type = env->access_type; |
1430 | b769d8fe | bellard | } |
1431 | faadf50e | j_mayer | ret = get_physical_address(env, &ctx, address, rw, access_type); |
1432 | 9a64fbe4 | bellard | if (ret == 0) { |
1433 | b227a8e9 | j_mayer | ret = tlb_set_page_exec(env, address & TARGET_PAGE_MASK, |
1434 | b227a8e9 | j_mayer | ctx.raddr & TARGET_PAGE_MASK, ctx.prot, |
1435 | b227a8e9 | j_mayer | mmu_idx, is_softmmu); |
1436 | 9a64fbe4 | bellard | } else if (ret < 0) { |
1437 | d12d51d5 | aliguori | LOG_MMU_STATE(env); |
1438 | 9a64fbe4 | bellard | if (access_type == ACCESS_CODE) {
|
1439 | 9a64fbe4 | bellard | switch (ret) {
|
1440 | 9a64fbe4 | bellard | case -1: |
1441 | 76a66253 | j_mayer | /* No matches in page tables or TLB */
|
1442 | a750fc0b | j_mayer | switch (env->mmu_model) {
|
1443 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_6xx:
|
1444 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_IFTLB; |
1445 | 8f793433 | j_mayer | env->error_code = 1 << 18; |
1446 | 76a66253 | j_mayer | env->spr[SPR_IMISS] = address; |
1447 | 76a66253 | j_mayer | env->spr[SPR_ICMP] = 0x80000000 | ctx.ptem;
|
1448 | 76a66253 | j_mayer | goto tlb_miss;
|
1449 | 7dbe11ac | j_mayer | case POWERPC_MMU_SOFT_74xx:
|
1450 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_IFTLB; |
1451 | 7dbe11ac | j_mayer | goto tlb_miss_74xx;
|
1452 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx:
|
1453 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx_Z:
|
1454 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_ITLB; |
1455 | 8f793433 | j_mayer | env->error_code = 0;
|
1456 | a8dea12f | j_mayer | env->spr[SPR_40x_DEAR] = address; |
1457 | a8dea12f | j_mayer | env->spr[SPR_40x_ESR] = 0x00000000;
|
1458 | c55e9aef | j_mayer | break;
|
1459 | a750fc0b | j_mayer | case POWERPC_MMU_32B:
|
1460 | faadf50e | j_mayer | case POWERPC_MMU_601:
|
1461 | c55e9aef | j_mayer | #if defined(TARGET_PPC64)
|
1462 | add78955 | j_mayer | case POWERPC_MMU_620:
|
1463 | a750fc0b | j_mayer | case POWERPC_MMU_64B:
|
1464 | c55e9aef | j_mayer | #endif
|
1465 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_ISI; |
1466 | 8f793433 | j_mayer | env->error_code = 0x40000000;
|
1467 | 8f793433 | j_mayer | break;
|
1468 | a750fc0b | j_mayer | case POWERPC_MMU_BOOKE:
|
1469 | c55e9aef | j_mayer | /* XXX: TODO */
|
1470 | b4095fed | j_mayer | cpu_abort(env, "BookE MMU model is not implemented\n");
|
1471 | c55e9aef | j_mayer | return -1; |
1472 | a750fc0b | j_mayer | case POWERPC_MMU_BOOKE_FSL:
|
1473 | c55e9aef | j_mayer | /* XXX: TODO */
|
1474 | b4095fed | j_mayer | cpu_abort(env, "BookE FSL MMU model is not implemented\n");
|
1475 | c55e9aef | j_mayer | return -1; |
1476 | b4095fed | j_mayer | case POWERPC_MMU_MPC8xx:
|
1477 | b4095fed | j_mayer | /* XXX: TODO */
|
1478 | b4095fed | j_mayer | cpu_abort(env, "MPC8xx MMU model is not implemented\n");
|
1479 | b4095fed | j_mayer | break;
|
1480 | b4095fed | j_mayer | case POWERPC_MMU_REAL:
|
1481 | b4095fed | j_mayer | cpu_abort(env, "PowerPC in real mode should never raise "
|
1482 | b4095fed | j_mayer | "any MMU exceptions\n");
|
1483 | 2662a059 | j_mayer | return -1; |
1484 | c55e9aef | j_mayer | default:
|
1485 | c55e9aef | j_mayer | cpu_abort(env, "Unknown or invalid MMU model\n");
|
1486 | c55e9aef | j_mayer | return -1; |
1487 | 76a66253 | j_mayer | } |
1488 | 9a64fbe4 | bellard | break;
|
1489 | 9a64fbe4 | bellard | case -2: |
1490 | 9a64fbe4 | bellard | /* Access rights violation */
|
1491 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_ISI; |
1492 | 8f793433 | j_mayer | env->error_code = 0x08000000;
|
1493 | 9a64fbe4 | bellard | break;
|
1494 | 9a64fbe4 | bellard | case -3: |
1495 | 76a66253 | j_mayer | /* No execute protection violation */
|
1496 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_ISI; |
1497 | 8f793433 | j_mayer | env->error_code = 0x10000000;
|
1498 | 9a64fbe4 | bellard | break;
|
1499 | 9a64fbe4 | bellard | case -4: |
1500 | 9a64fbe4 | bellard | /* Direct store exception */
|
1501 | 9a64fbe4 | bellard | /* No code fetch is allowed in direct-store areas */
|
1502 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_ISI; |
1503 | 8f793433 | j_mayer | env->error_code = 0x10000000;
|
1504 | 2be0071f | bellard | break;
|
1505 | e1833e1f | j_mayer | #if defined(TARGET_PPC64)
|
1506 | 2be0071f | bellard | case -5: |
1507 | 2be0071f | bellard | /* No match in segment table */
|
1508 | add78955 | j_mayer | if (env->mmu_model == POWERPC_MMU_620) {
|
1509 | add78955 | j_mayer | env->exception_index = POWERPC_EXCP_ISI; |
1510 | add78955 | j_mayer | /* XXX: this might be incorrect */
|
1511 | add78955 | j_mayer | env->error_code = 0x40000000;
|
1512 | add78955 | j_mayer | } else {
|
1513 | add78955 | j_mayer | env->exception_index = POWERPC_EXCP_ISEG; |
1514 | add78955 | j_mayer | env->error_code = 0;
|
1515 | add78955 | j_mayer | } |
1516 | 9a64fbe4 | bellard | break;
|
1517 | e1833e1f | j_mayer | #endif
|
1518 | 9a64fbe4 | bellard | } |
1519 | 9a64fbe4 | bellard | } else {
|
1520 | 9a64fbe4 | bellard | switch (ret) {
|
1521 | 9a64fbe4 | bellard | case -1: |
1522 | 76a66253 | j_mayer | /* No matches in page tables or TLB */
|
1523 | a750fc0b | j_mayer | switch (env->mmu_model) {
|
1524 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_6xx:
|
1525 | 76a66253 | j_mayer | if (rw == 1) { |
1526 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DSTLB; |
1527 | 8f793433 | j_mayer | env->error_code = 1 << 16; |
1528 | 76a66253 | j_mayer | } else {
|
1529 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DLTLB; |
1530 | 8f793433 | j_mayer | env->error_code = 0;
|
1531 | 76a66253 | j_mayer | } |
1532 | 76a66253 | j_mayer | env->spr[SPR_DMISS] = address; |
1533 | 76a66253 | j_mayer | env->spr[SPR_DCMP] = 0x80000000 | ctx.ptem;
|
1534 | 76a66253 | j_mayer | tlb_miss:
|
1535 | 8f793433 | j_mayer | env->error_code |= ctx.key << 19;
|
1536 | 76a66253 | j_mayer | env->spr[SPR_HASH1] = ctx.pg_addr[0];
|
1537 | 76a66253 | j_mayer | env->spr[SPR_HASH2] = ctx.pg_addr[1];
|
1538 | 8f793433 | j_mayer | break;
|
1539 | 7dbe11ac | j_mayer | case POWERPC_MMU_SOFT_74xx:
|
1540 | 7dbe11ac | j_mayer | if (rw == 1) { |
1541 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DSTLB; |
1542 | 7dbe11ac | j_mayer | } else {
|
1543 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DLTLB; |
1544 | 7dbe11ac | j_mayer | } |
1545 | 7dbe11ac | j_mayer | tlb_miss_74xx:
|
1546 | 7dbe11ac | j_mayer | /* Implement LRU algorithm */
|
1547 | 8f793433 | j_mayer | env->error_code = ctx.key << 19;
|
1548 | 7dbe11ac | j_mayer | env->spr[SPR_TLBMISS] = (address & ~((target_ulong)0x3)) |
|
1549 | 7dbe11ac | j_mayer | ((env->last_way + 1) & (env->nb_ways - 1)); |
1550 | 7dbe11ac | j_mayer | env->spr[SPR_PTEHI] = 0x80000000 | ctx.ptem;
|
1551 | 7dbe11ac | j_mayer | break;
|
1552 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx:
|
1553 | a750fc0b | j_mayer | case POWERPC_MMU_SOFT_4xx_Z:
|
1554 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DTLB; |
1555 | 8f793433 | j_mayer | env->error_code = 0;
|
1556 | a8dea12f | j_mayer | env->spr[SPR_40x_DEAR] = address; |
1557 | a8dea12f | j_mayer | if (rw)
|
1558 | a8dea12f | j_mayer | env->spr[SPR_40x_ESR] = 0x00800000;
|
1559 | a8dea12f | j_mayer | else
|
1560 | a8dea12f | j_mayer | env->spr[SPR_40x_ESR] = 0x00000000;
|
1561 | c55e9aef | j_mayer | break;
|
1562 | a750fc0b | j_mayer | case POWERPC_MMU_32B:
|
1563 | faadf50e | j_mayer | case POWERPC_MMU_601:
|
1564 | c55e9aef | j_mayer | #if defined(TARGET_PPC64)
|
1565 | add78955 | j_mayer | case POWERPC_MMU_620:
|
1566 | a750fc0b | j_mayer | case POWERPC_MMU_64B:
|
1567 | c55e9aef | j_mayer | #endif
|
1568 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DSI; |
1569 | 8f793433 | j_mayer | env->error_code = 0;
|
1570 | 8f793433 | j_mayer | env->spr[SPR_DAR] = address; |
1571 | 8f793433 | j_mayer | if (rw == 1) |
1572 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x42000000;
|
1573 | 8f793433 | j_mayer | else
|
1574 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x40000000;
|
1575 | 8f793433 | j_mayer | break;
|
1576 | b4095fed | j_mayer | case POWERPC_MMU_MPC8xx:
|
1577 | b4095fed | j_mayer | /* XXX: TODO */
|
1578 | b4095fed | j_mayer | cpu_abort(env, "MPC8xx MMU model is not implemented\n");
|
1579 | b4095fed | j_mayer | break;
|
1580 | a750fc0b | j_mayer | case POWERPC_MMU_BOOKE:
|
1581 | c55e9aef | j_mayer | /* XXX: TODO */
|
1582 | b4095fed | j_mayer | cpu_abort(env, "BookE MMU model is not implemented\n");
|
1583 | c55e9aef | j_mayer | return -1; |
1584 | a750fc0b | j_mayer | case POWERPC_MMU_BOOKE_FSL:
|
1585 | c55e9aef | j_mayer | /* XXX: TODO */
|
1586 | b4095fed | j_mayer | cpu_abort(env, "BookE FSL MMU model is not implemented\n");
|
1587 | c55e9aef | j_mayer | return -1; |
1588 | b4095fed | j_mayer | case POWERPC_MMU_REAL:
|
1589 | b4095fed | j_mayer | cpu_abort(env, "PowerPC in real mode should never raise "
|
1590 | b4095fed | j_mayer | "any MMU exceptions\n");
|
1591 | 2662a059 | j_mayer | return -1; |
1592 | c55e9aef | j_mayer | default:
|
1593 | c55e9aef | j_mayer | cpu_abort(env, "Unknown or invalid MMU model\n");
|
1594 | c55e9aef | j_mayer | return -1; |
1595 | 76a66253 | j_mayer | } |
1596 | 9a64fbe4 | bellard | break;
|
1597 | 9a64fbe4 | bellard | case -2: |
1598 | 9a64fbe4 | bellard | /* Access rights violation */
|
1599 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DSI; |
1600 | 8f793433 | j_mayer | env->error_code = 0;
|
1601 | 8f793433 | j_mayer | env->spr[SPR_DAR] = address; |
1602 | 8f793433 | j_mayer | if (rw == 1) |
1603 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x0A000000;
|
1604 | 8f793433 | j_mayer | else
|
1605 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x08000000;
|
1606 | 9a64fbe4 | bellard | break;
|
1607 | 9a64fbe4 | bellard | case -4: |
1608 | 9a64fbe4 | bellard | /* Direct store exception */
|
1609 | 9a64fbe4 | bellard | switch (access_type) {
|
1610 | 9a64fbe4 | bellard | case ACCESS_FLOAT:
|
1611 | 9a64fbe4 | bellard | /* Floating point load/store */
|
1612 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_ALIGN; |
1613 | 8f793433 | j_mayer | env->error_code = POWERPC_EXCP_ALIGN_FP; |
1614 | 8f793433 | j_mayer | env->spr[SPR_DAR] = address; |
1615 | 9a64fbe4 | bellard | break;
|
1616 | 9a64fbe4 | bellard | case ACCESS_RES:
|
1617 | 8f793433 | j_mayer | /* lwarx, ldarx or stwcx. */
|
1618 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DSI; |
1619 | 8f793433 | j_mayer | env->error_code = 0;
|
1620 | 8f793433 | j_mayer | env->spr[SPR_DAR] = address; |
1621 | 8f793433 | j_mayer | if (rw == 1) |
1622 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x06000000;
|
1623 | 8f793433 | j_mayer | else
|
1624 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x04000000;
|
1625 | 9a64fbe4 | bellard | break;
|
1626 | 9a64fbe4 | bellard | case ACCESS_EXT:
|
1627 | 9a64fbe4 | bellard | /* eciwx or ecowx */
|
1628 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_DSI; |
1629 | 8f793433 | j_mayer | env->error_code = 0;
|
1630 | 8f793433 | j_mayer | env->spr[SPR_DAR] = address; |
1631 | 8f793433 | j_mayer | if (rw == 1) |
1632 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x06100000;
|
1633 | 8f793433 | j_mayer | else
|
1634 | 8f793433 | j_mayer | env->spr[SPR_DSISR] = 0x04100000;
|
1635 | 9a64fbe4 | bellard | break;
|
1636 | 9a64fbe4 | bellard | default:
|
1637 | 76a66253 | j_mayer | printf("DSI: invalid exception (%d)\n", ret);
|
1638 | 8f793433 | j_mayer | env->exception_index = POWERPC_EXCP_PROGRAM; |
1639 | 8f793433 | j_mayer | env->error_code = |
1640 | 8f793433 | j_mayer | POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL; |
1641 | 8f793433 | j_mayer | env->spr[SPR_DAR] = address; |
1642 | 9a64fbe4 | bellard | break;
|
1643 | 9a64fbe4 | bellard | } |
1644 | fdabc366 | bellard | break;
|
1645 | e1833e1f | j_mayer | #if defined(TARGET_PPC64)
|
1646 | 2be0071f | bellard | case -5: |
1647 | 2be0071f | bellard | /* No match in segment table */
|
1648 | add78955 | j_mayer | if (env->mmu_model == POWERPC_MMU_620) {
|
1649 | add78955 | j_mayer | env->exception_index = POWERPC_EXCP_DSI; |
1650 | add78955 | j_mayer | env->error_code = 0;
|
1651 | add78955 | j_mayer | env->spr[SPR_DAR] = address; |
1652 | add78955 | j_mayer | /* XXX: this might be incorrect */
|
1653 | add78955 | j_mayer | if (rw == 1) |
1654 | add78955 | j_mayer | env->spr[SPR_DSISR] = 0x42000000;
|
1655 | add78955 | j_mayer | else
|
1656 | add78955 | j_mayer | env->spr[SPR_DSISR] = 0x40000000;
|
1657 | add78955 | j_mayer | } else {
|
1658 | add78955 | j_mayer | env->exception_index = POWERPC_EXCP_DSEG; |
1659 | add78955 | j_mayer | env->error_code = 0;
|
1660 | add78955 | j_mayer | env->spr[SPR_DAR] = address; |
1661 | add78955 | j_mayer | } |
1662 | 2be0071f | bellard | break;
|
1663 | e1833e1f | j_mayer | #endif
|
1664 | 9a64fbe4 | bellard | } |
1665 | 9a64fbe4 | bellard | } |
1666 | 9a64fbe4 | bellard | #if 0
|
1667 | 8f793433 | j_mayer | printf("%s: set exception to %d %02x\n", __func__,
|
1668 | 8f793433 | j_mayer | env->exception, env->error_code);
|
1669 | 9a64fbe4 | bellard | #endif
|
1670 | 9a64fbe4 | bellard | ret = 1;
|
1671 | 9a64fbe4 | bellard | } |
1672 | 76a66253 | j_mayer | |
1673 | 9a64fbe4 | bellard | return ret;
|
1674 | 9a64fbe4 | bellard | } |
1675 | 9a64fbe4 | bellard | |
1676 | 3fc6c082 | bellard | /*****************************************************************************/
|
1677 | 3fc6c082 | bellard | /* BATs management */
|
1678 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1679 | b068d6a7 | j_mayer | static always_inline void do_invalidate_BAT (CPUPPCState *env, |
1680 | b068d6a7 | j_mayer | target_ulong BATu, |
1681 | b068d6a7 | j_mayer | target_ulong mask) |
1682 | 3fc6c082 | bellard | { |
1683 | 3fc6c082 | bellard | target_ulong base, end, page; |
1684 | 76a66253 | j_mayer | |
1685 | 3fc6c082 | bellard | base = BATu & ~0x0001FFFF;
|
1686 | 3fc6c082 | bellard | end = base + mask + 0x00020000;
|
1687 | d12d51d5 | aliguori | LOG_BATS("Flush BAT from " ADDRX " to " ADDRX " (" ADDRX ")\n", |
1688 | 76a66253 | j_mayer | base, end, mask); |
1689 | 3fc6c082 | bellard | for (page = base; page != end; page += TARGET_PAGE_SIZE)
|
1690 | 3fc6c082 | bellard | tlb_flush_page(env, page); |
1691 | d12d51d5 | aliguori | LOG_BATS("Flush done\n");
|
1692 | 3fc6c082 | bellard | } |
1693 | 3fc6c082 | bellard | #endif
|
1694 | 3fc6c082 | bellard | |
1695 | b068d6a7 | j_mayer | static always_inline void dump_store_bat (CPUPPCState *env, char ID, |
1696 | b068d6a7 | j_mayer | int ul, int nr, target_ulong value) |
1697 | 3fc6c082 | bellard | { |
1698 | d12d51d5 | aliguori | LOG_BATS("Set %cBAT%d%c to " ADDRX " (" ADDRX ")\n", |
1699 | 1b9eb036 | j_mayer | ID, nr, ul == 0 ? 'u' : 'l', value, env->nip); |
1700 | 3fc6c082 | bellard | } |
1701 | 3fc6c082 | bellard | |
1702 | 45d827d2 | aurel32 | void ppc_store_ibatu (CPUPPCState *env, int nr, target_ulong value) |
1703 | 3fc6c082 | bellard | { |
1704 | 3fc6c082 | bellard | target_ulong mask; |
1705 | 3fc6c082 | bellard | |
1706 | 3fc6c082 | bellard | dump_store_bat(env, 'I', 0, nr, value); |
1707 | 3fc6c082 | bellard | if (env->IBAT[0][nr] != value) { |
1708 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1709 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1710 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1711 | 3fc6c082 | bellard | #endif
|
1712 | 3fc6c082 | bellard | /* When storing valid upper BAT, mask BEPI and BRPN
|
1713 | 3fc6c082 | bellard | * and invalidate all TLBs covered by this BAT
|
1714 | 3fc6c082 | bellard | */
|
1715 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1716 | 3fc6c082 | bellard | env->IBAT[0][nr] = (value & 0x00001FFFUL) | |
1717 | 3fc6c082 | bellard | (value & ~0x0001FFFFUL & ~mask);
|
1718 | 3fc6c082 | bellard | env->IBAT[1][nr] = (env->IBAT[1][nr] & 0x0000007B) | |
1719 | 3fc6c082 | bellard | (env->IBAT[1][nr] & ~0x0001FFFF & ~mask); |
1720 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1721 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1722 | 76a66253 | j_mayer | #else
|
1723 | 3fc6c082 | bellard | tlb_flush(env, 1);
|
1724 | 3fc6c082 | bellard | #endif
|
1725 | 3fc6c082 | bellard | } |
1726 | 3fc6c082 | bellard | } |
1727 | 3fc6c082 | bellard | |
1728 | 45d827d2 | aurel32 | void ppc_store_ibatl (CPUPPCState *env, int nr, target_ulong value) |
1729 | 3fc6c082 | bellard | { |
1730 | 3fc6c082 | bellard | dump_store_bat(env, 'I', 1, nr, value); |
1731 | 3fc6c082 | bellard | env->IBAT[1][nr] = value;
|
1732 | 3fc6c082 | bellard | } |
1733 | 3fc6c082 | bellard | |
1734 | 45d827d2 | aurel32 | void ppc_store_dbatu (CPUPPCState *env, int nr, target_ulong value) |
1735 | 3fc6c082 | bellard | { |
1736 | 3fc6c082 | bellard | target_ulong mask; |
1737 | 3fc6c082 | bellard | |
1738 | 3fc6c082 | bellard | dump_store_bat(env, 'D', 0, nr, value); |
1739 | 3fc6c082 | bellard | if (env->DBAT[0][nr] != value) { |
1740 | 3fc6c082 | bellard | /* When storing valid upper BAT, mask BEPI and BRPN
|
1741 | 3fc6c082 | bellard | * and invalidate all TLBs covered by this BAT
|
1742 | 3fc6c082 | bellard | */
|
1743 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1744 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1745 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->DBAT[0][nr], mask);
|
1746 | 3fc6c082 | bellard | #endif
|
1747 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1748 | 3fc6c082 | bellard | env->DBAT[0][nr] = (value & 0x00001FFFUL) | |
1749 | 3fc6c082 | bellard | (value & ~0x0001FFFFUL & ~mask);
|
1750 | 3fc6c082 | bellard | env->DBAT[1][nr] = (env->DBAT[1][nr] & 0x0000007B) | |
1751 | 3fc6c082 | bellard | (env->DBAT[1][nr] & ~0x0001FFFF & ~mask); |
1752 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1753 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->DBAT[0][nr], mask);
|
1754 | 3fc6c082 | bellard | #else
|
1755 | 3fc6c082 | bellard | tlb_flush(env, 1);
|
1756 | 3fc6c082 | bellard | #endif
|
1757 | 3fc6c082 | bellard | } |
1758 | 3fc6c082 | bellard | } |
1759 | 3fc6c082 | bellard | |
1760 | 45d827d2 | aurel32 | void ppc_store_dbatl (CPUPPCState *env, int nr, target_ulong value) |
1761 | 3fc6c082 | bellard | { |
1762 | 3fc6c082 | bellard | dump_store_bat(env, 'D', 1, nr, value); |
1763 | 3fc6c082 | bellard | env->DBAT[1][nr] = value;
|
1764 | 3fc6c082 | bellard | } |
1765 | 3fc6c082 | bellard | |
1766 | 45d827d2 | aurel32 | void ppc_store_ibatu_601 (CPUPPCState *env, int nr, target_ulong value) |
1767 | 056401ea | j_mayer | { |
1768 | 056401ea | j_mayer | target_ulong mask; |
1769 | 056401ea | j_mayer | int do_inval;
|
1770 | 056401ea | j_mayer | |
1771 | 056401ea | j_mayer | dump_store_bat(env, 'I', 0, nr, value); |
1772 | 056401ea | j_mayer | if (env->IBAT[0][nr] != value) { |
1773 | 056401ea | j_mayer | do_inval = 0;
|
1774 | 056401ea | j_mayer | mask = (env->IBAT[1][nr] << 17) & 0x0FFE0000UL; |
1775 | 056401ea | j_mayer | if (env->IBAT[1][nr] & 0x40) { |
1776 | 056401ea | j_mayer | /* Invalidate BAT only if it is valid */
|
1777 | 056401ea | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
1778 | 056401ea | j_mayer | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1779 | 056401ea | j_mayer | #else
|
1780 | 056401ea | j_mayer | do_inval = 1;
|
1781 | 056401ea | j_mayer | #endif
|
1782 | 056401ea | j_mayer | } |
1783 | 056401ea | j_mayer | /* When storing valid upper BAT, mask BEPI and BRPN
|
1784 | 056401ea | j_mayer | * and invalidate all TLBs covered by this BAT
|
1785 | 056401ea | j_mayer | */
|
1786 | 056401ea | j_mayer | env->IBAT[0][nr] = (value & 0x00001FFFUL) | |
1787 | 056401ea | j_mayer | (value & ~0x0001FFFFUL & ~mask);
|
1788 | 056401ea | j_mayer | env->DBAT[0][nr] = env->IBAT[0][nr]; |
1789 | 056401ea | j_mayer | if (env->IBAT[1][nr] & 0x40) { |
1790 | 056401ea | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
1791 | 056401ea | j_mayer | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1792 | 056401ea | j_mayer | #else
|
1793 | 056401ea | j_mayer | do_inval = 1;
|
1794 | 056401ea | j_mayer | #endif
|
1795 | 056401ea | j_mayer | } |
1796 | 056401ea | j_mayer | #if defined(FLUSH_ALL_TLBS)
|
1797 | 056401ea | j_mayer | if (do_inval)
|
1798 | 056401ea | j_mayer | tlb_flush(env, 1);
|
1799 | 056401ea | j_mayer | #endif
|
1800 | 056401ea | j_mayer | } |
1801 | 056401ea | j_mayer | } |
1802 | 056401ea | j_mayer | |
1803 | 45d827d2 | aurel32 | void ppc_store_ibatl_601 (CPUPPCState *env, int nr, target_ulong value) |
1804 | 056401ea | j_mayer | { |
1805 | 056401ea | j_mayer | target_ulong mask; |
1806 | 056401ea | j_mayer | int do_inval;
|
1807 | 056401ea | j_mayer | |
1808 | 056401ea | j_mayer | dump_store_bat(env, 'I', 1, nr, value); |
1809 | 056401ea | j_mayer | if (env->IBAT[1][nr] != value) { |
1810 | 056401ea | j_mayer | do_inval = 0;
|
1811 | 056401ea | j_mayer | if (env->IBAT[1][nr] & 0x40) { |
1812 | 056401ea | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
1813 | 056401ea | j_mayer | mask = (env->IBAT[1][nr] << 17) & 0x0FFE0000UL; |
1814 | 056401ea | j_mayer | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1815 | 056401ea | j_mayer | #else
|
1816 | 056401ea | j_mayer | do_inval = 1;
|
1817 | 056401ea | j_mayer | #endif
|
1818 | 056401ea | j_mayer | } |
1819 | 056401ea | j_mayer | if (value & 0x40) { |
1820 | 056401ea | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
1821 | 056401ea | j_mayer | mask = (value << 17) & 0x0FFE0000UL; |
1822 | 056401ea | j_mayer | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1823 | 056401ea | j_mayer | #else
|
1824 | 056401ea | j_mayer | do_inval = 1;
|
1825 | 056401ea | j_mayer | #endif
|
1826 | 056401ea | j_mayer | } |
1827 | 056401ea | j_mayer | env->IBAT[1][nr] = value;
|
1828 | 056401ea | j_mayer | env->DBAT[1][nr] = value;
|
1829 | 056401ea | j_mayer | #if defined(FLUSH_ALL_TLBS)
|
1830 | 056401ea | j_mayer | if (do_inval)
|
1831 | 056401ea | j_mayer | tlb_flush(env, 1);
|
1832 | 056401ea | j_mayer | #endif
|
1833 | 056401ea | j_mayer | } |
1834 | 056401ea | j_mayer | } |
1835 | 056401ea | j_mayer | |
1836 | 0a032cbe | j_mayer | /*****************************************************************************/
|
1837 | 0a032cbe | j_mayer | /* TLB management */
|
1838 | 0a032cbe | j_mayer | void ppc_tlb_invalidate_all (CPUPPCState *env)
|
1839 | 0a032cbe | j_mayer | { |
1840 | daf4f96e | j_mayer | switch (env->mmu_model) {
|
1841 | daf4f96e | j_mayer | case POWERPC_MMU_SOFT_6xx:
|
1842 | 7dbe11ac | j_mayer | case POWERPC_MMU_SOFT_74xx:
|
1843 | 0a032cbe | j_mayer | ppc6xx_tlb_invalidate_all(env); |
1844 | daf4f96e | j_mayer | break;
|
1845 | daf4f96e | j_mayer | case POWERPC_MMU_SOFT_4xx:
|
1846 | daf4f96e | j_mayer | case POWERPC_MMU_SOFT_4xx_Z:
|
1847 | 0a032cbe | j_mayer | ppc4xx_tlb_invalidate_all(env); |
1848 | daf4f96e | j_mayer | break;
|
1849 | b4095fed | j_mayer | case POWERPC_MMU_REAL:
|
1850 | 7dbe11ac | j_mayer | cpu_abort(env, "No TLB for PowerPC 4xx in real mode\n");
|
1851 | 7dbe11ac | j_mayer | break;
|
1852 | b4095fed | j_mayer | case POWERPC_MMU_MPC8xx:
|
1853 | b4095fed | j_mayer | /* XXX: TODO */
|
1854 | b4095fed | j_mayer | cpu_abort(env, "MPC8xx MMU model is not implemented\n");
|
1855 | b4095fed | j_mayer | break;
|
1856 | 7dbe11ac | j_mayer | case POWERPC_MMU_BOOKE:
|
1857 | 7dbe11ac | j_mayer | /* XXX: TODO */
|
1858 | b4095fed | j_mayer | cpu_abort(env, "BookE MMU model is not implemented\n");
|
1859 | 7dbe11ac | j_mayer | break;
|
1860 | 7dbe11ac | j_mayer | case POWERPC_MMU_BOOKE_FSL:
|
1861 | 7dbe11ac | j_mayer | /* XXX: TODO */
|
1862 | da07cf59 | aliguori | if (!kvm_enabled())
|
1863 | da07cf59 | aliguori | cpu_abort(env, "BookE MMU model is not implemented\n");
|
1864 | 7dbe11ac | j_mayer | break;
|
1865 | 7dbe11ac | j_mayer | case POWERPC_MMU_32B:
|
1866 | faadf50e | j_mayer | case POWERPC_MMU_601:
|
1867 | 00af685f | j_mayer | #if defined(TARGET_PPC64)
|
1868 | add78955 | j_mayer | case POWERPC_MMU_620:
|
1869 | 7dbe11ac | j_mayer | case POWERPC_MMU_64B:
|
1870 | 00af685f | j_mayer | #endif /* defined(TARGET_PPC64) */ |
1871 | 0a032cbe | j_mayer | tlb_flush(env, 1);
|
1872 | daf4f96e | j_mayer | break;
|
1873 | 00af685f | j_mayer | default:
|
1874 | 00af685f | j_mayer | /* XXX: TODO */
|
1875 | 12de9a39 | j_mayer | cpu_abort(env, "Unknown MMU model\n");
|
1876 | 00af685f | j_mayer | break;
|
1877 | 0a032cbe | j_mayer | } |
1878 | 0a032cbe | j_mayer | } |
1879 | 0a032cbe | j_mayer | |
1880 | daf4f96e | j_mayer | void ppc_tlb_invalidate_one (CPUPPCState *env, target_ulong addr)
|
1881 | daf4f96e | j_mayer | { |
1882 | daf4f96e | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
1883 | daf4f96e | j_mayer | addr &= TARGET_PAGE_MASK; |
1884 | daf4f96e | j_mayer | switch (env->mmu_model) {
|
1885 | daf4f96e | j_mayer | case POWERPC_MMU_SOFT_6xx:
|
1886 | 7dbe11ac | j_mayer | case POWERPC_MMU_SOFT_74xx:
|
1887 | daf4f96e | j_mayer | ppc6xx_tlb_invalidate_virt(env, addr, 0);
|
1888 | daf4f96e | j_mayer | if (env->id_tlbs == 1) |
1889 | daf4f96e | j_mayer | ppc6xx_tlb_invalidate_virt(env, addr, 1);
|
1890 | daf4f96e | j_mayer | break;
|
1891 | daf4f96e | j_mayer | case POWERPC_MMU_SOFT_4xx:
|
1892 | daf4f96e | j_mayer | case POWERPC_MMU_SOFT_4xx_Z:
|
1893 | daf4f96e | j_mayer | ppc4xx_tlb_invalidate_virt(env, addr, env->spr[SPR_40x_PID]); |
1894 | daf4f96e | j_mayer | break;
|
1895 | b4095fed | j_mayer | case POWERPC_MMU_REAL:
|
1896 | 7dbe11ac | j_mayer | cpu_abort(env, "No TLB for PowerPC 4xx in real mode\n");
|
1897 | 7dbe11ac | j_mayer | break;
|
1898 | b4095fed | j_mayer | case POWERPC_MMU_MPC8xx:
|
1899 | b4095fed | j_mayer | /* XXX: TODO */
|
1900 | b4095fed | j_mayer | cpu_abort(env, "MPC8xx MMU model is not implemented\n");
|
1901 | b4095fed | j_mayer | break;
|
1902 | 7dbe11ac | j_mayer | case POWERPC_MMU_BOOKE:
|
1903 | 7dbe11ac | j_mayer | /* XXX: TODO */
|
1904 | b4095fed | j_mayer | cpu_abort(env, "BookE MMU model is not implemented\n");
|
1905 | 7dbe11ac | j_mayer | break;
|
1906 | 7dbe11ac | j_mayer | case POWERPC_MMU_BOOKE_FSL:
|
1907 | 7dbe11ac | j_mayer | /* XXX: TODO */
|
1908 | b4095fed | j_mayer | cpu_abort(env, "BookE FSL MMU model is not implemented\n");
|
1909 | 7dbe11ac | j_mayer | break;
|
1910 | 7dbe11ac | j_mayer | case POWERPC_MMU_32B:
|
1911 | faadf50e | j_mayer | case POWERPC_MMU_601:
|
1912 | daf4f96e | j_mayer | /* tlbie invalidate TLBs for all segments */
|
1913 | 6f2d8978 | j_mayer | addr &= ~((target_ulong)-1ULL << 28); |
1914 | daf4f96e | j_mayer | /* XXX: this case should be optimized,
|
1915 | daf4f96e | j_mayer | * giving a mask to tlb_flush_page
|
1916 | daf4f96e | j_mayer | */
|
1917 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x0 << 28)); |
1918 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x1 << 28)); |
1919 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x2 << 28)); |
1920 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x3 << 28)); |
1921 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x4 << 28)); |
1922 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x5 << 28)); |
1923 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x6 << 28)); |
1924 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x7 << 28)); |
1925 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x8 << 28)); |
1926 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0x9 << 28)); |
1927 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0xA << 28)); |
1928 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0xB << 28)); |
1929 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0xC << 28)); |
1930 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0xD << 28)); |
1931 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0xE << 28)); |
1932 | daf4f96e | j_mayer | tlb_flush_page(env, addr | (0xF << 28)); |
1933 | 7dbe11ac | j_mayer | break;
|
1934 | 00af685f | j_mayer | #if defined(TARGET_PPC64)
|
1935 | add78955 | j_mayer | case POWERPC_MMU_620:
|
1936 | 7dbe11ac | j_mayer | case POWERPC_MMU_64B:
|
1937 | 7dbe11ac | j_mayer | /* tlbie invalidate TLBs for all segments */
|
1938 | 7dbe11ac | j_mayer | /* XXX: given the fact that there are too many segments to invalidate,
|
1939 | 00af685f | j_mayer | * and we still don't have a tlb_flush_mask(env, n, mask) in Qemu,
|
1940 | 7dbe11ac | j_mayer | * we just invalidate all TLBs
|
1941 | 7dbe11ac | j_mayer | */
|
1942 | 7dbe11ac | j_mayer | tlb_flush(env, 1);
|
1943 | 7dbe11ac | j_mayer | break;
|
1944 | 00af685f | j_mayer | #endif /* defined(TARGET_PPC64) */ |
1945 | 00af685f | j_mayer | default:
|
1946 | 00af685f | j_mayer | /* XXX: TODO */
|
1947 | 12de9a39 | j_mayer | cpu_abort(env, "Unknown MMU model\n");
|
1948 | 00af685f | j_mayer | break;
|
1949 | daf4f96e | j_mayer | } |
1950 | daf4f96e | j_mayer | #else
|
1951 | daf4f96e | j_mayer | ppc_tlb_invalidate_all(env); |
1952 | daf4f96e | j_mayer | #endif
|
1953 | daf4f96e | j_mayer | } |
1954 | daf4f96e | j_mayer | |
1955 | 3fc6c082 | bellard | /*****************************************************************************/
|
1956 | 3fc6c082 | bellard | /* Special registers manipulation */
|
1957 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
1958 | d9bce9d9 | j_mayer | void ppc_store_asr (CPUPPCState *env, target_ulong value)
|
1959 | d9bce9d9 | j_mayer | { |
1960 | d9bce9d9 | j_mayer | if (env->asr != value) {
|
1961 | d9bce9d9 | j_mayer | env->asr = value; |
1962 | d9bce9d9 | j_mayer | tlb_flush(env, 1);
|
1963 | d9bce9d9 | j_mayer | } |
1964 | d9bce9d9 | j_mayer | } |
1965 | d9bce9d9 | j_mayer | #endif
|
1966 | d9bce9d9 | j_mayer | |
1967 | 45d827d2 | aurel32 | void ppc_store_sdr1 (CPUPPCState *env, target_ulong value)
|
1968 | 3fc6c082 | bellard | { |
1969 | d12d51d5 | aliguori | LOG_MMU("%s: " ADDRX "\n", __func__, value); |
1970 | 3fc6c082 | bellard | if (env->sdr1 != value) {
|
1971 | 12de9a39 | j_mayer | /* XXX: for PowerPC 64, should check that the HTABSIZE value
|
1972 | 12de9a39 | j_mayer | * is <= 28
|
1973 | 12de9a39 | j_mayer | */
|
1974 | 3fc6c082 | bellard | env->sdr1 = value; |
1975 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
1976 | 3fc6c082 | bellard | } |
1977 | 3fc6c082 | bellard | } |
1978 | 3fc6c082 | bellard | |
1979 | f6b868fc | blueswir1 | #if defined(TARGET_PPC64)
|
1980 | f6b868fc | blueswir1 | target_ulong ppc_load_sr (CPUPPCState *env, int slb_nr)
|
1981 | f6b868fc | blueswir1 | { |
1982 | f6b868fc | blueswir1 | // XXX
|
1983 | f6b868fc | blueswir1 | return 0; |
1984 | f6b868fc | blueswir1 | } |
1985 | f6b868fc | blueswir1 | #endif
|
1986 | f6b868fc | blueswir1 | |
1987 | 45d827d2 | aurel32 | void ppc_store_sr (CPUPPCState *env, int srnum, target_ulong value) |
1988 | 3fc6c082 | bellard | { |
1989 | d12d51d5 | aliguori | LOG_MMU("%s: reg=%d " ADDRX " " ADDRX "\n", |
1990 | 1b9eb036 | j_mayer | __func__, srnum, value, env->sr[srnum]); |
1991 | f6b868fc | blueswir1 | #if defined(TARGET_PPC64)
|
1992 | f6b868fc | blueswir1 | if (env->mmu_model & POWERPC_MMU_64) {
|
1993 | f6b868fc | blueswir1 | uint64_t rb = 0, rs = 0; |
1994 | f6b868fc | blueswir1 | |
1995 | f6b868fc | blueswir1 | /* ESID = srnum */
|
1996 | f6b868fc | blueswir1 | rb |= ((uint32_t)srnum & 0xf) << 28; |
1997 | f6b868fc | blueswir1 | /* Set the valid bit */
|
1998 | f6b868fc | blueswir1 | rb |= 1 << 27; |
1999 | f6b868fc | blueswir1 | /* Index = ESID */
|
2000 | f6b868fc | blueswir1 | rb |= (uint32_t)srnum; |
2001 | f6b868fc | blueswir1 | |
2002 | f6b868fc | blueswir1 | /* VSID = VSID */
|
2003 | f6b868fc | blueswir1 | rs |= (value & 0xfffffff) << 12; |
2004 | f6b868fc | blueswir1 | /* flags = flags */
|
2005 | f6b868fc | blueswir1 | rs |= ((value >> 27) & 0xf) << 9; |
2006 | f6b868fc | blueswir1 | |
2007 | f6b868fc | blueswir1 | ppc_store_slb(env, rb, rs); |
2008 | f6b868fc | blueswir1 | } else
|
2009 | f6b868fc | blueswir1 | #endif
|
2010 | 3fc6c082 | bellard | if (env->sr[srnum] != value) {
|
2011 | 3fc6c082 | bellard | env->sr[srnum] = value; |
2012 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS) && 0 |
2013 | 3fc6c082 | bellard | { |
2014 | 3fc6c082 | bellard | target_ulong page, end; |
2015 | 3fc6c082 | bellard | /* Invalidate 256 MB of virtual memory */
|
2016 | 3fc6c082 | bellard | page = (16 << 20) * srnum; |
2017 | 3fc6c082 | bellard | end = page + (16 << 20); |
2018 | 3fc6c082 | bellard | for (; page != end; page += TARGET_PAGE_SIZE)
|
2019 | 3fc6c082 | bellard | tlb_flush_page(env, page); |
2020 | 3fc6c082 | bellard | } |
2021 | 3fc6c082 | bellard | #else
|
2022 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
2023 | 3fc6c082 | bellard | #endif
|
2024 | 3fc6c082 | bellard | } |
2025 | 3fc6c082 | bellard | } |
2026 | 76a66253 | j_mayer | #endif /* !defined (CONFIG_USER_ONLY) */ |
2027 | 3fc6c082 | bellard | |
2028 | 76a66253 | j_mayer | /* GDBstub can read and write MSR... */
|
2029 | 0411a972 | j_mayer | void ppc_store_msr (CPUPPCState *env, target_ulong value)
|
2030 | 3fc6c082 | bellard | { |
2031 | a4f30719 | j_mayer | hreg_store_msr(env, value, 0);
|
2032 | 3fc6c082 | bellard | } |
2033 | 3fc6c082 | bellard | |
2034 | 3fc6c082 | bellard | /*****************************************************************************/
|
2035 | 3fc6c082 | bellard | /* Exception processing */
|
2036 | 18fba28c | bellard | #if defined (CONFIG_USER_ONLY)
|
2037 | 9a64fbe4 | bellard | void do_interrupt (CPUState *env)
|
2038 | 79aceca5 | bellard | { |
2039 | e1833e1f | j_mayer | env->exception_index = POWERPC_EXCP_NONE; |
2040 | e1833e1f | j_mayer | env->error_code = 0;
|
2041 | 18fba28c | bellard | } |
2042 | 47103572 | j_mayer | |
2043 | e9df014c | j_mayer | void ppc_hw_interrupt (CPUState *env)
|
2044 | 47103572 | j_mayer | { |
2045 | e1833e1f | j_mayer | env->exception_index = POWERPC_EXCP_NONE; |
2046 | e1833e1f | j_mayer | env->error_code = 0;
|
2047 | 47103572 | j_mayer | } |
2048 | 76a66253 | j_mayer | #else /* defined (CONFIG_USER_ONLY) */ |
2049 | a11b8151 | j_mayer | static always_inline void dump_syscall (CPUState *env) |
2050 | d094807b | bellard | { |
2051 | 93fcfe39 | aliguori | qemu_log_mask(CPU_LOG_INT, "syscall r0=" REGX " r3=" REGX " r4=" REGX |
2052 | 6b542af7 | j_mayer | " r5=" REGX " r6=" REGX " nip=" ADDRX "\n", |
2053 | 6b542af7 | j_mayer | ppc_dump_gpr(env, 0), ppc_dump_gpr(env, 3), ppc_dump_gpr(env, 4), |
2054 | 6b542af7 | j_mayer | ppc_dump_gpr(env, 5), ppc_dump_gpr(env, 6), env->nip); |
2055 | d094807b | bellard | } |
2056 | d094807b | bellard | |
2057 | e1833e1f | j_mayer | /* Note that this function should be greatly optimized
|
2058 | e1833e1f | j_mayer | * when called with a constant excp, from ppc_hw_interrupt
|
2059 | e1833e1f | j_mayer | */
|
2060 | e1833e1f | j_mayer | static always_inline void powerpc_excp (CPUState *env, |
2061 | e1833e1f | j_mayer | int excp_model, int excp) |
2062 | 18fba28c | bellard | { |
2063 | 0411a972 | j_mayer | target_ulong msr, new_msr, vector; |
2064 | e1833e1f | j_mayer | int srr0, srr1, asrr0, asrr1;
|
2065 | a4f30719 | j_mayer | int lpes0, lpes1, lev;
|
2066 | 79aceca5 | bellard | |
2067 | b172c56a | j_mayer | if (0) { |
2068 | b172c56a | j_mayer | /* XXX: find a suitable condition to enable the hypervisor mode */
|
2069 | b172c56a | j_mayer | lpes0 = (env->spr[SPR_LPCR] >> 1) & 1; |
2070 | b172c56a | j_mayer | lpes1 = (env->spr[SPR_LPCR] >> 2) & 1; |
2071 | b172c56a | j_mayer | } else {
|
2072 | b172c56a | j_mayer | /* Those values ensure we won't enter the hypervisor mode */
|
2073 | b172c56a | j_mayer | lpes0 = 0;
|
2074 | b172c56a | j_mayer | lpes1 = 1;
|
2075 | b172c56a | j_mayer | } |
2076 | b172c56a | j_mayer | |
2077 | 93fcfe39 | aliguori | qemu_log_mask(CPU_LOG_INT, "Raise exception at " ADDRX " => %08x (%02x)\n", |
2078 | 93fcfe39 | aliguori | env->nip, excp, env->error_code); |
2079 | 0411a972 | j_mayer | msr = env->msr; |
2080 | 0411a972 | j_mayer | new_msr = msr; |
2081 | e1833e1f | j_mayer | srr0 = SPR_SRR0; |
2082 | e1833e1f | j_mayer | srr1 = SPR_SRR1; |
2083 | e1833e1f | j_mayer | asrr0 = -1;
|
2084 | e1833e1f | j_mayer | asrr1 = -1;
|
2085 | e1833e1f | j_mayer | msr &= ~((target_ulong)0x783F0000);
|
2086 | 9a64fbe4 | bellard | switch (excp) {
|
2087 | e1833e1f | j_mayer | case POWERPC_EXCP_NONE:
|
2088 | e1833e1f | j_mayer | /* Should never happen */
|
2089 | e1833e1f | j_mayer | return;
|
2090 | e1833e1f | j_mayer | case POWERPC_EXCP_CRITICAL: /* Critical input */ |
2091 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2092 | e1833e1f | j_mayer | switch (excp_model) {
|
2093 | a750fc0b | j_mayer | case POWERPC_EXCP_40x:
|
2094 | e1833e1f | j_mayer | srr0 = SPR_40x_SRR2; |
2095 | e1833e1f | j_mayer | srr1 = SPR_40x_SRR3; |
2096 | c62db105 | j_mayer | break;
|
2097 | a750fc0b | j_mayer | case POWERPC_EXCP_BOOKE:
|
2098 | e1833e1f | j_mayer | srr0 = SPR_BOOKE_CSRR0; |
2099 | e1833e1f | j_mayer | srr1 = SPR_BOOKE_CSRR1; |
2100 | c62db105 | j_mayer | break;
|
2101 | e1833e1f | j_mayer | case POWERPC_EXCP_G2:
|
2102 | c62db105 | j_mayer | break;
|
2103 | e1833e1f | j_mayer | default:
|
2104 | e1833e1f | j_mayer | goto excp_invalid;
|
2105 | 2be0071f | bellard | } |
2106 | 9a64fbe4 | bellard | goto store_next;
|
2107 | e1833e1f | j_mayer | case POWERPC_EXCP_MCHECK: /* Machine check exception */ |
2108 | e1833e1f | j_mayer | if (msr_me == 0) { |
2109 | e63ecc6f | j_mayer | /* Machine check exception is not enabled.
|
2110 | e63ecc6f | j_mayer | * Enter checkstop state.
|
2111 | e63ecc6f | j_mayer | */
|
2112 | 93fcfe39 | aliguori | if (qemu_log_enabled()) {
|
2113 | 93fcfe39 | aliguori | qemu_log("Machine check while not allowed. "
|
2114 | e63ecc6f | j_mayer | "Entering checkstop state\n");
|
2115 | e63ecc6f | j_mayer | } else {
|
2116 | e63ecc6f | j_mayer | fprintf(stderr, "Machine check while not allowed. "
|
2117 | e63ecc6f | j_mayer | "Entering checkstop state\n");
|
2118 | e63ecc6f | j_mayer | } |
2119 | e63ecc6f | j_mayer | env->halted = 1;
|
2120 | e63ecc6f | j_mayer | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
2121 | e1833e1f | j_mayer | } |
2122 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2123 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_ME);
|
2124 | b172c56a | j_mayer | if (0) { |
2125 | b172c56a | j_mayer | /* XXX: find a suitable condition to enable the hypervisor mode */
|
2126 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2127 | b172c56a | j_mayer | } |
2128 | e1833e1f | j_mayer | /* XXX: should also have something loaded in DAR / DSISR */
|
2129 | e1833e1f | j_mayer | switch (excp_model) {
|
2130 | a750fc0b | j_mayer | case POWERPC_EXCP_40x:
|
2131 | e1833e1f | j_mayer | srr0 = SPR_40x_SRR2; |
2132 | e1833e1f | j_mayer | srr1 = SPR_40x_SRR3; |
2133 | c62db105 | j_mayer | break;
|
2134 | a750fc0b | j_mayer | case POWERPC_EXCP_BOOKE:
|
2135 | e1833e1f | j_mayer | srr0 = SPR_BOOKE_MCSRR0; |
2136 | e1833e1f | j_mayer | srr1 = SPR_BOOKE_MCSRR1; |
2137 | e1833e1f | j_mayer | asrr0 = SPR_BOOKE_CSRR0; |
2138 | e1833e1f | j_mayer | asrr1 = SPR_BOOKE_CSRR1; |
2139 | c62db105 | j_mayer | break;
|
2140 | c62db105 | j_mayer | default:
|
2141 | c62db105 | j_mayer | break;
|
2142 | 2be0071f | bellard | } |
2143 | e1833e1f | j_mayer | goto store_next;
|
2144 | e1833e1f | j_mayer | case POWERPC_EXCP_DSI: /* Data storage exception */ |
2145 | d12d51d5 | aliguori | LOG_EXCP("DSI exception: DSISR=" ADDRX" DAR=" ADDRX "\n", |
2146 | 6b542af7 | j_mayer | env->spr[SPR_DSISR], env->spr[SPR_DAR]); |
2147 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2148 | e1833e1f | j_mayer | if (lpes1 == 0) |
2149 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2150 | a541f297 | bellard | goto store_next;
|
2151 | e1833e1f | j_mayer | case POWERPC_EXCP_ISI: /* Instruction storage exception */ |
2152 | d12d51d5 | aliguori | LOG_EXCP("ISI exception: msr=" ADDRX ", nip=" ADDRX "\n", |
2153 | 6b542af7 | j_mayer | msr, env->nip); |
2154 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2155 | e1833e1f | j_mayer | if (lpes1 == 0) |
2156 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2157 | e1833e1f | j_mayer | msr |= env->error_code; |
2158 | 9a64fbe4 | bellard | goto store_next;
|
2159 | e1833e1f | j_mayer | case POWERPC_EXCP_EXTERNAL: /* External input */ |
2160 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2161 | e1833e1f | j_mayer | if (lpes0 == 1) |
2162 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2163 | 9a64fbe4 | bellard | goto store_next;
|
2164 | e1833e1f | j_mayer | case POWERPC_EXCP_ALIGN: /* Alignment exception */ |
2165 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2166 | e1833e1f | j_mayer | if (lpes1 == 0) |
2167 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2168 | e1833e1f | j_mayer | /* XXX: this is false */
|
2169 | e1833e1f | j_mayer | /* Get rS/rD and rA from faulting opcode */
|
2170 | e1833e1f | j_mayer | env->spr[SPR_DSISR] |= (ldl_code((env->nip - 4)) & 0x03FF0000) >> 16; |
2171 | 9a64fbe4 | bellard | goto store_current;
|
2172 | e1833e1f | j_mayer | case POWERPC_EXCP_PROGRAM: /* Program exception */ |
2173 | 9a64fbe4 | bellard | switch (env->error_code & ~0xF) { |
2174 | e1833e1f | j_mayer | case POWERPC_EXCP_FP:
|
2175 | e1833e1f | j_mayer | if ((msr_fe0 == 0 && msr_fe1 == 0) || msr_fp == 0) { |
2176 | d12d51d5 | aliguori | LOG_EXCP("Ignore floating point exception\n");
|
2177 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_NONE; |
2178 | 7c58044c | j_mayer | env->error_code = 0;
|
2179 | 9a64fbe4 | bellard | return;
|
2180 | 76a66253 | j_mayer | } |
2181 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2182 | e1833e1f | j_mayer | if (lpes1 == 0) |
2183 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2184 | 9a64fbe4 | bellard | msr |= 0x00100000;
|
2185 | 5b52b991 | j_mayer | if (msr_fe0 == msr_fe1)
|
2186 | 5b52b991 | j_mayer | goto store_next;
|
2187 | 5b52b991 | j_mayer | msr |= 0x00010000;
|
2188 | 76a66253 | j_mayer | break;
|
2189 | e1833e1f | j_mayer | case POWERPC_EXCP_INVAL:
|
2190 | d12d51d5 | aliguori | LOG_EXCP("Invalid instruction at " ADDRX "\n", |
2191 | a496775f | j_mayer | env->nip); |
2192 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2193 | e1833e1f | j_mayer | if (lpes1 == 0) |
2194 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2195 | 9a64fbe4 | bellard | msr |= 0x00080000;
|
2196 | 76a66253 | j_mayer | break;
|
2197 | e1833e1f | j_mayer | case POWERPC_EXCP_PRIV:
|
2198 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2199 | e1833e1f | j_mayer | if (lpes1 == 0) |
2200 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2201 | 9a64fbe4 | bellard | msr |= 0x00040000;
|
2202 | 76a66253 | j_mayer | break;
|
2203 | e1833e1f | j_mayer | case POWERPC_EXCP_TRAP:
|
2204 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2205 | e1833e1f | j_mayer | if (lpes1 == 0) |
2206 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2207 | 9a64fbe4 | bellard | msr |= 0x00020000;
|
2208 | 9a64fbe4 | bellard | break;
|
2209 | 9a64fbe4 | bellard | default:
|
2210 | 9a64fbe4 | bellard | /* Should never occur */
|
2211 | e1833e1f | j_mayer | cpu_abort(env, "Invalid program exception %d. Aborting\n",
|
2212 | e1833e1f | j_mayer | env->error_code); |
2213 | 76a66253 | j_mayer | break;
|
2214 | 76a66253 | j_mayer | } |
2215 | 5b52b991 | j_mayer | goto store_current;
|
2216 | e1833e1f | j_mayer | case POWERPC_EXCP_FPU: /* Floating-point unavailable exception */ |
2217 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2218 | e1833e1f | j_mayer | if (lpes1 == 0) |
2219 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2220 | e1833e1f | j_mayer | goto store_current;
|
2221 | e1833e1f | j_mayer | case POWERPC_EXCP_SYSCALL: /* System call exception */ |
2222 | d094807b | bellard | /* NOTE: this is a temporary hack to support graphics OSI
|
2223 | d094807b | bellard | calls from the MOL driver */
|
2224 | e1833e1f | j_mayer | /* XXX: To be removed */
|
2225 | d094807b | bellard | if (env->gpr[3] == 0x113724fa && env->gpr[4] == 0x77810f9b && |
2226 | d094807b | bellard | env->osi_call) { |
2227 | 7c58044c | j_mayer | if (env->osi_call(env) != 0) { |
2228 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_NONE; |
2229 | 7c58044c | j_mayer | env->error_code = 0;
|
2230 | d094807b | bellard | return;
|
2231 | 7c58044c | j_mayer | } |
2232 | d094807b | bellard | } |
2233 | 93fcfe39 | aliguori | dump_syscall(env); |
2234 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2235 | f9fdea6b | j_mayer | lev = env->error_code; |
2236 | e1833e1f | j_mayer | if (lev == 1 || (lpes0 == 0 && lpes1 == 0)) |
2237 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2238 | e1833e1f | j_mayer | goto store_next;
|
2239 | e1833e1f | j_mayer | case POWERPC_EXCP_APU: /* Auxiliary processor unavailable */ |
2240 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2241 | e1833e1f | j_mayer | goto store_current;
|
2242 | e1833e1f | j_mayer | case POWERPC_EXCP_DECR: /* Decrementer exception */ |
2243 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2244 | e1833e1f | j_mayer | if (lpes1 == 0) |
2245 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2246 | e1833e1f | j_mayer | goto store_next;
|
2247 | e1833e1f | j_mayer | case POWERPC_EXCP_FIT: /* Fixed-interval timer interrupt */ |
2248 | e1833e1f | j_mayer | /* FIT on 4xx */
|
2249 | d12d51d5 | aliguori | LOG_EXCP("FIT exception\n");
|
2250 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2251 | 9a64fbe4 | bellard | goto store_next;
|
2252 | e1833e1f | j_mayer | case POWERPC_EXCP_WDT: /* Watchdog timer interrupt */ |
2253 | d12d51d5 | aliguori | LOG_EXCP("WDT exception\n");
|
2254 | e1833e1f | j_mayer | switch (excp_model) {
|
2255 | e1833e1f | j_mayer | case POWERPC_EXCP_BOOKE:
|
2256 | e1833e1f | j_mayer | srr0 = SPR_BOOKE_CSRR0; |
2257 | e1833e1f | j_mayer | srr1 = SPR_BOOKE_CSRR1; |
2258 | e1833e1f | j_mayer | break;
|
2259 | e1833e1f | j_mayer | default:
|
2260 | e1833e1f | j_mayer | break;
|
2261 | e1833e1f | j_mayer | } |
2262 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2263 | 2be0071f | bellard | goto store_next;
|
2264 | e1833e1f | j_mayer | case POWERPC_EXCP_DTLB: /* Data TLB error */ |
2265 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2266 | e1833e1f | j_mayer | goto store_next;
|
2267 | e1833e1f | j_mayer | case POWERPC_EXCP_ITLB: /* Instruction TLB error */ |
2268 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2269 | e1833e1f | j_mayer | goto store_next;
|
2270 | e1833e1f | j_mayer | case POWERPC_EXCP_DEBUG: /* Debug interrupt */ |
2271 | e1833e1f | j_mayer | switch (excp_model) {
|
2272 | e1833e1f | j_mayer | case POWERPC_EXCP_BOOKE:
|
2273 | e1833e1f | j_mayer | srr0 = SPR_BOOKE_DSRR0; |
2274 | e1833e1f | j_mayer | srr1 = SPR_BOOKE_DSRR1; |
2275 | e1833e1f | j_mayer | asrr0 = SPR_BOOKE_CSRR0; |
2276 | e1833e1f | j_mayer | asrr1 = SPR_BOOKE_CSRR1; |
2277 | e1833e1f | j_mayer | break;
|
2278 | e1833e1f | j_mayer | default:
|
2279 | e1833e1f | j_mayer | break;
|
2280 | e1833e1f | j_mayer | } |
2281 | 2be0071f | bellard | /* XXX: TODO */
|
2282 | e1833e1f | j_mayer | cpu_abort(env, "Debug exception is not implemented yet !\n");
|
2283 | 2be0071f | bellard | goto store_next;
|
2284 | e1833e1f | j_mayer | case POWERPC_EXCP_SPEU: /* SPE/embedded floating-point unavailable */ |
2285 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2286 | e1833e1f | j_mayer | goto store_current;
|
2287 | e1833e1f | j_mayer | case POWERPC_EXCP_EFPDI: /* Embedded floating-point data interrupt */ |
2288 | 2be0071f | bellard | /* XXX: TODO */
|
2289 | e1833e1f | j_mayer | cpu_abort(env, "Embedded floating point data exception "
|
2290 | 2be0071f | bellard | "is not implemented yet !\n");
|
2291 | 2be0071f | bellard | goto store_next;
|
2292 | e1833e1f | j_mayer | case POWERPC_EXCP_EFPRI: /* Embedded floating-point round interrupt */ |
2293 | 2be0071f | bellard | /* XXX: TODO */
|
2294 | e1833e1f | j_mayer | cpu_abort(env, "Embedded floating point round exception "
|
2295 | e1833e1f | j_mayer | "is not implemented yet !\n");
|
2296 | 9a64fbe4 | bellard | goto store_next;
|
2297 | e1833e1f | j_mayer | case POWERPC_EXCP_EPERFM: /* Embedded performance monitor interrupt */ |
2298 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2299 | 2be0071f | bellard | /* XXX: TODO */
|
2300 | 2be0071f | bellard | cpu_abort(env, |
2301 | e1833e1f | j_mayer | "Performance counter exception is not implemented yet !\n");
|
2302 | 9a64fbe4 | bellard | goto store_next;
|
2303 | e1833e1f | j_mayer | case POWERPC_EXCP_DOORI: /* Embedded doorbell interrupt */ |
2304 | 76a66253 | j_mayer | /* XXX: TODO */
|
2305 | e1833e1f | j_mayer | cpu_abort(env, |
2306 | e1833e1f | j_mayer | "Embedded doorbell interrupt is not implemented yet !\n");
|
2307 | 2be0071f | bellard | goto store_next;
|
2308 | e1833e1f | j_mayer | case POWERPC_EXCP_DOORCI: /* Embedded doorbell critical interrupt */ |
2309 | e1833e1f | j_mayer | switch (excp_model) {
|
2310 | e1833e1f | j_mayer | case POWERPC_EXCP_BOOKE:
|
2311 | e1833e1f | j_mayer | srr0 = SPR_BOOKE_CSRR0; |
2312 | e1833e1f | j_mayer | srr1 = SPR_BOOKE_CSRR1; |
2313 | a750fc0b | j_mayer | break;
|
2314 | 2be0071f | bellard | default:
|
2315 | 2be0071f | bellard | break;
|
2316 | 2be0071f | bellard | } |
2317 | e1833e1f | j_mayer | /* XXX: TODO */
|
2318 | e1833e1f | j_mayer | cpu_abort(env, "Embedded doorbell critical interrupt "
|
2319 | e1833e1f | j_mayer | "is not implemented yet !\n");
|
2320 | e1833e1f | j_mayer | goto store_next;
|
2321 | e1833e1f | j_mayer | case POWERPC_EXCP_RESET: /* System reset exception */ |
2322 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2323 | a4f30719 | j_mayer | if (0) { |
2324 | a4f30719 | j_mayer | /* XXX: find a suitable condition to enable the hypervisor mode */
|
2325 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2326 | a4f30719 | j_mayer | } |
2327 | e1833e1f | j_mayer | goto store_next;
|
2328 | e1833e1f | j_mayer | case POWERPC_EXCP_DSEG: /* Data segment exception */ |
2329 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2330 | e1833e1f | j_mayer | if (lpes1 == 0) |
2331 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2332 | e1833e1f | j_mayer | goto store_next;
|
2333 | e1833e1f | j_mayer | case POWERPC_EXCP_ISEG: /* Instruction segment exception */ |
2334 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2335 | e1833e1f | j_mayer | if (lpes1 == 0) |
2336 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2337 | e1833e1f | j_mayer | goto store_next;
|
2338 | e1833e1f | j_mayer | case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception */ |
2339 | e1833e1f | j_mayer | srr0 = SPR_HSRR0; |
2340 | f9fdea6b | j_mayer | srr1 = SPR_HSRR1; |
2341 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2342 | b172c56a | j_mayer | goto store_next;
|
2343 | e1833e1f | j_mayer | case POWERPC_EXCP_TRACE: /* Trace exception */ |
2344 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2345 | e1833e1f | j_mayer | if (lpes1 == 0) |
2346 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2347 | e1833e1f | j_mayer | goto store_next;
|
2348 | e1833e1f | j_mayer | case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception */ |
2349 | e1833e1f | j_mayer | srr0 = SPR_HSRR0; |
2350 | f9fdea6b | j_mayer | srr1 = SPR_HSRR1; |
2351 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2352 | e1833e1f | j_mayer | goto store_next;
|
2353 | e1833e1f | j_mayer | case POWERPC_EXCP_HISI: /* Hypervisor instruction storage exception */ |
2354 | e1833e1f | j_mayer | srr0 = SPR_HSRR0; |
2355 | f9fdea6b | j_mayer | srr1 = SPR_HSRR1; |
2356 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2357 | e1833e1f | j_mayer | goto store_next;
|
2358 | e1833e1f | j_mayer | case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception */ |
2359 | e1833e1f | j_mayer | srr0 = SPR_HSRR0; |
2360 | f9fdea6b | j_mayer | srr1 = SPR_HSRR1; |
2361 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2362 | e1833e1f | j_mayer | goto store_next;
|
2363 | e1833e1f | j_mayer | case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment exception */ |
2364 | e1833e1f | j_mayer | srr0 = SPR_HSRR0; |
2365 | f9fdea6b | j_mayer | srr1 = SPR_HSRR1; |
2366 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2367 | e1833e1f | j_mayer | goto store_next;
|
2368 | e1833e1f | j_mayer | case POWERPC_EXCP_VPU: /* Vector unavailable exception */ |
2369 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2370 | e1833e1f | j_mayer | if (lpes1 == 0) |
2371 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2372 | e1833e1f | j_mayer | goto store_current;
|
2373 | e1833e1f | j_mayer | case POWERPC_EXCP_PIT: /* Programmable interval timer interrupt */ |
2374 | d12d51d5 | aliguori | LOG_EXCP("PIT exception\n");
|
2375 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2376 | e1833e1f | j_mayer | goto store_next;
|
2377 | e1833e1f | j_mayer | case POWERPC_EXCP_IO: /* IO error exception */ |
2378 | e1833e1f | j_mayer | /* XXX: TODO */
|
2379 | e1833e1f | j_mayer | cpu_abort(env, "601 IO error exception is not implemented yet !\n");
|
2380 | e1833e1f | j_mayer | goto store_next;
|
2381 | e1833e1f | j_mayer | case POWERPC_EXCP_RUNM: /* Run mode exception */ |
2382 | e1833e1f | j_mayer | /* XXX: TODO */
|
2383 | e1833e1f | j_mayer | cpu_abort(env, "601 run mode exception is not implemented yet !\n");
|
2384 | e1833e1f | j_mayer | goto store_next;
|
2385 | e1833e1f | j_mayer | case POWERPC_EXCP_EMUL: /* Emulation trap exception */ |
2386 | e1833e1f | j_mayer | /* XXX: TODO */
|
2387 | e1833e1f | j_mayer | cpu_abort(env, "602 emulation trap exception "
|
2388 | e1833e1f | j_mayer | "is not implemented yet !\n");
|
2389 | e1833e1f | j_mayer | goto store_next;
|
2390 | e1833e1f | j_mayer | case POWERPC_EXCP_IFTLB: /* Instruction fetch TLB error */ |
2391 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2392 | a4f30719 | j_mayer | if (lpes1 == 0) /* XXX: check this */ |
2393 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2394 | e1833e1f | j_mayer | switch (excp_model) {
|
2395 | a750fc0b | j_mayer | case POWERPC_EXCP_602:
|
2396 | a750fc0b | j_mayer | case POWERPC_EXCP_603:
|
2397 | a750fc0b | j_mayer | case POWERPC_EXCP_603E:
|
2398 | a750fc0b | j_mayer | case POWERPC_EXCP_G2:
|
2399 | e1833e1f | j_mayer | goto tlb_miss_tgpr;
|
2400 | a750fc0b | j_mayer | case POWERPC_EXCP_7x5:
|
2401 | 76a66253 | j_mayer | goto tlb_miss;
|
2402 | 7dbe11ac | j_mayer | case POWERPC_EXCP_74xx:
|
2403 | 7dbe11ac | j_mayer | goto tlb_miss_74xx;
|
2404 | 2be0071f | bellard | default:
|
2405 | e1833e1f | j_mayer | cpu_abort(env, "Invalid instruction TLB miss exception\n");
|
2406 | 2be0071f | bellard | break;
|
2407 | 2be0071f | bellard | } |
2408 | e1833e1f | j_mayer | break;
|
2409 | e1833e1f | j_mayer | case POWERPC_EXCP_DLTLB: /* Data load TLB miss */ |
2410 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2411 | a4f30719 | j_mayer | if (lpes1 == 0) /* XXX: check this */ |
2412 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2413 | e1833e1f | j_mayer | switch (excp_model) {
|
2414 | a750fc0b | j_mayer | case POWERPC_EXCP_602:
|
2415 | a750fc0b | j_mayer | case POWERPC_EXCP_603:
|
2416 | a750fc0b | j_mayer | case POWERPC_EXCP_603E:
|
2417 | a750fc0b | j_mayer | case POWERPC_EXCP_G2:
|
2418 | e1833e1f | j_mayer | goto tlb_miss_tgpr;
|
2419 | a750fc0b | j_mayer | case POWERPC_EXCP_7x5:
|
2420 | 76a66253 | j_mayer | goto tlb_miss;
|
2421 | 7dbe11ac | j_mayer | case POWERPC_EXCP_74xx:
|
2422 | 7dbe11ac | j_mayer | goto tlb_miss_74xx;
|
2423 | 2be0071f | bellard | default:
|
2424 | e1833e1f | j_mayer | cpu_abort(env, "Invalid data load TLB miss exception\n");
|
2425 | 2be0071f | bellard | break;
|
2426 | 2be0071f | bellard | } |
2427 | e1833e1f | j_mayer | break;
|
2428 | e1833e1f | j_mayer | case POWERPC_EXCP_DSTLB: /* Data store TLB miss */ |
2429 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */ |
2430 | a4f30719 | j_mayer | if (lpes1 == 0) /* XXX: check this */ |
2431 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2432 | e1833e1f | j_mayer | switch (excp_model) {
|
2433 | a750fc0b | j_mayer | case POWERPC_EXCP_602:
|
2434 | a750fc0b | j_mayer | case POWERPC_EXCP_603:
|
2435 | a750fc0b | j_mayer | case POWERPC_EXCP_603E:
|
2436 | a750fc0b | j_mayer | case POWERPC_EXCP_G2:
|
2437 | e1833e1f | j_mayer | tlb_miss_tgpr:
|
2438 | 76a66253 | j_mayer | /* Swap temporary saved registers with GPRs */
|
2439 | 0411a972 | j_mayer | if (!(new_msr & ((target_ulong)1 << MSR_TGPR))) { |
2440 | 0411a972 | j_mayer | new_msr |= (target_ulong)1 << MSR_TGPR;
|
2441 | 0411a972 | j_mayer | hreg_swap_gpr_tgpr(env); |
2442 | 0411a972 | j_mayer | } |
2443 | e1833e1f | j_mayer | goto tlb_miss;
|
2444 | e1833e1f | j_mayer | case POWERPC_EXCP_7x5:
|
2445 | e1833e1f | j_mayer | tlb_miss:
|
2446 | 2be0071f | bellard | #if defined (DEBUG_SOFTWARE_TLB)
|
2447 | 93fcfe39 | aliguori | if (qemu_log_enabled()) {
|
2448 | 76a66253 | j_mayer | const unsigned char *es; |
2449 | 76a66253 | j_mayer | target_ulong *miss, *cmp; |
2450 | 76a66253 | j_mayer | int en;
|
2451 | 1e6784f9 | j_mayer | if (excp == POWERPC_EXCP_IFTLB) {
|
2452 | 76a66253 | j_mayer | es = "I";
|
2453 | 76a66253 | j_mayer | en = 'I';
|
2454 | 76a66253 | j_mayer | miss = &env->spr[SPR_IMISS]; |
2455 | 76a66253 | j_mayer | cmp = &env->spr[SPR_ICMP]; |
2456 | 76a66253 | j_mayer | } else {
|
2457 | 1e6784f9 | j_mayer | if (excp == POWERPC_EXCP_DLTLB)
|
2458 | 76a66253 | j_mayer | es = "DL";
|
2459 | 76a66253 | j_mayer | else
|
2460 | 76a66253 | j_mayer | es = "DS";
|
2461 | 76a66253 | j_mayer | en = 'D';
|
2462 | 76a66253 | j_mayer | miss = &env->spr[SPR_DMISS]; |
2463 | 76a66253 | j_mayer | cmp = &env->spr[SPR_DCMP]; |
2464 | 76a66253 | j_mayer | } |
2465 | 93fcfe39 | aliguori | qemu_log("6xx %sTLB miss: %cM " ADDRX " %cC " ADDRX |
2466 | 4a057712 | j_mayer | " H1 " ADDRX " H2 " ADDRX " %08x\n", |
2467 | 1b9eb036 | j_mayer | es, en, *miss, en, *cmp, |
2468 | 76a66253 | j_mayer | env->spr[SPR_HASH1], env->spr[SPR_HASH2], |
2469 | 2be0071f | bellard | env->error_code); |
2470 | 2be0071f | bellard | } |
2471 | 9a64fbe4 | bellard | #endif
|
2472 | 2be0071f | bellard | msr |= env->crf[0] << 28; |
2473 | 2be0071f | bellard | msr |= env->error_code; /* key, D/I, S/L bits */
|
2474 | 2be0071f | bellard | /* Set way using a LRU mechanism */
|
2475 | 76a66253 | j_mayer | msr |= ((env->last_way + 1) & (env->nb_ways - 1)) << 17; |
2476 | c62db105 | j_mayer | break;
|
2477 | 7dbe11ac | j_mayer | case POWERPC_EXCP_74xx:
|
2478 | 7dbe11ac | j_mayer | tlb_miss_74xx:
|
2479 | 7dbe11ac | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2480 | 93fcfe39 | aliguori | if (qemu_log_enabled()) {
|
2481 | 7dbe11ac | j_mayer | const unsigned char *es; |
2482 | 7dbe11ac | j_mayer | target_ulong *miss, *cmp; |
2483 | 7dbe11ac | j_mayer | int en;
|
2484 | 7dbe11ac | j_mayer | if (excp == POWERPC_EXCP_IFTLB) {
|
2485 | 7dbe11ac | j_mayer | es = "I";
|
2486 | 7dbe11ac | j_mayer | en = 'I';
|
2487 | 0411a972 | j_mayer | miss = &env->spr[SPR_TLBMISS]; |
2488 | 0411a972 | j_mayer | cmp = &env->spr[SPR_PTEHI]; |
2489 | 7dbe11ac | j_mayer | } else {
|
2490 | 7dbe11ac | j_mayer | if (excp == POWERPC_EXCP_DLTLB)
|
2491 | 7dbe11ac | j_mayer | es = "DL";
|
2492 | 7dbe11ac | j_mayer | else
|
2493 | 7dbe11ac | j_mayer | es = "DS";
|
2494 | 7dbe11ac | j_mayer | en = 'D';
|
2495 | 7dbe11ac | j_mayer | miss = &env->spr[SPR_TLBMISS]; |
2496 | 7dbe11ac | j_mayer | cmp = &env->spr[SPR_PTEHI]; |
2497 | 7dbe11ac | j_mayer | } |
2498 | 93fcfe39 | aliguori | qemu_log("74xx %sTLB miss: %cM " ADDRX " %cC " ADDRX |
2499 | 7dbe11ac | j_mayer | " %08x\n",
|
2500 | 7dbe11ac | j_mayer | es, en, *miss, en, *cmp, env->error_code); |
2501 | 7dbe11ac | j_mayer | } |
2502 | 7dbe11ac | j_mayer | #endif
|
2503 | 7dbe11ac | j_mayer | msr |= env->error_code; /* key bit */
|
2504 | 7dbe11ac | j_mayer | break;
|
2505 | 2be0071f | bellard | default:
|
2506 | e1833e1f | j_mayer | cpu_abort(env, "Invalid data store TLB miss exception\n");
|
2507 | 2be0071f | bellard | break;
|
2508 | 2be0071f | bellard | } |
2509 | e1833e1f | j_mayer | goto store_next;
|
2510 | e1833e1f | j_mayer | case POWERPC_EXCP_FPA: /* Floating-point assist exception */ |
2511 | e1833e1f | j_mayer | /* XXX: TODO */
|
2512 | e1833e1f | j_mayer | cpu_abort(env, "Floating point assist exception "
|
2513 | e1833e1f | j_mayer | "is not implemented yet !\n");
|
2514 | e1833e1f | j_mayer | goto store_next;
|
2515 | b4095fed | j_mayer | case POWERPC_EXCP_DABR: /* Data address breakpoint */ |
2516 | b4095fed | j_mayer | /* XXX: TODO */
|
2517 | b4095fed | j_mayer | cpu_abort(env, "DABR exception is not implemented yet !\n");
|
2518 | b4095fed | j_mayer | goto store_next;
|
2519 | e1833e1f | j_mayer | case POWERPC_EXCP_IABR: /* Instruction address breakpoint */ |
2520 | e1833e1f | j_mayer | /* XXX: TODO */
|
2521 | e1833e1f | j_mayer | cpu_abort(env, "IABR exception is not implemented yet !\n");
|
2522 | e1833e1f | j_mayer | goto store_next;
|
2523 | e1833e1f | j_mayer | case POWERPC_EXCP_SMI: /* System management interrupt */ |
2524 | e1833e1f | j_mayer | /* XXX: TODO */
|
2525 | e1833e1f | j_mayer | cpu_abort(env, "SMI exception is not implemented yet !\n");
|
2526 | e1833e1f | j_mayer | goto store_next;
|
2527 | e1833e1f | j_mayer | case POWERPC_EXCP_THERM: /* Thermal interrupt */ |
2528 | e1833e1f | j_mayer | /* XXX: TODO */
|
2529 | e1833e1f | j_mayer | cpu_abort(env, "Thermal management exception "
|
2530 | e1833e1f | j_mayer | "is not implemented yet !\n");
|
2531 | e1833e1f | j_mayer | goto store_next;
|
2532 | e1833e1f | j_mayer | case POWERPC_EXCP_PERFM: /* Embedded performance monitor interrupt */ |
2533 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_RI);
|
2534 | e1833e1f | j_mayer | if (lpes1 == 0) |
2535 | a4f30719 | j_mayer | new_msr |= (target_ulong)MSR_HVB; |
2536 | e1833e1f | j_mayer | /* XXX: TODO */
|
2537 | e1833e1f | j_mayer | cpu_abort(env, |
2538 | e1833e1f | j_mayer | "Performance counter exception is not implemented yet !\n");
|
2539 | e1833e1f | j_mayer | goto store_next;
|
2540 | e1833e1f | j_mayer | case POWERPC_EXCP_VPUA: /* Vector assist exception */ |
2541 | e1833e1f | j_mayer | /* XXX: TODO */
|
2542 | e1833e1f | j_mayer | cpu_abort(env, "VPU assist exception is not implemented yet !\n");
|
2543 | e1833e1f | j_mayer | goto store_next;
|
2544 | e1833e1f | j_mayer | case POWERPC_EXCP_SOFTP: /* Soft patch exception */ |
2545 | e1833e1f | j_mayer | /* XXX: TODO */
|
2546 | e1833e1f | j_mayer | cpu_abort(env, |
2547 | e1833e1f | j_mayer | "970 soft-patch exception is not implemented yet !\n");
|
2548 | e1833e1f | j_mayer | goto store_next;
|
2549 | e1833e1f | j_mayer | case POWERPC_EXCP_MAINT: /* Maintenance exception */ |
2550 | e1833e1f | j_mayer | /* XXX: TODO */
|
2551 | e1833e1f | j_mayer | cpu_abort(env, |
2552 | e1833e1f | j_mayer | "970 maintenance exception is not implemented yet !\n");
|
2553 | e1833e1f | j_mayer | goto store_next;
|
2554 | b4095fed | j_mayer | case POWERPC_EXCP_MEXTBR: /* Maskable external breakpoint */ |
2555 | b4095fed | j_mayer | /* XXX: TODO */
|
2556 | b4095fed | j_mayer | cpu_abort(env, "Maskable external exception "
|
2557 | b4095fed | j_mayer | "is not implemented yet !\n");
|
2558 | b4095fed | j_mayer | goto store_next;
|
2559 | b4095fed | j_mayer | case POWERPC_EXCP_NMEXTBR: /* Non maskable external breakpoint */ |
2560 | b4095fed | j_mayer | /* XXX: TODO */
|
2561 | b4095fed | j_mayer | cpu_abort(env, "Non maskable external exception "
|
2562 | b4095fed | j_mayer | "is not implemented yet !\n");
|
2563 | b4095fed | j_mayer | goto store_next;
|
2564 | 2be0071f | bellard | default:
|
2565 | e1833e1f | j_mayer | excp_invalid:
|
2566 | e1833e1f | j_mayer | cpu_abort(env, "Invalid PowerPC exception %d. Aborting\n", excp);
|
2567 | e1833e1f | j_mayer | break;
|
2568 | 9a64fbe4 | bellard | store_current:
|
2569 | 2be0071f | bellard | /* save current instruction location */
|
2570 | e1833e1f | j_mayer | env->spr[srr0] = env->nip - 4;
|
2571 | 9a64fbe4 | bellard | break;
|
2572 | 9a64fbe4 | bellard | store_next:
|
2573 | 2be0071f | bellard | /* save next instruction location */
|
2574 | e1833e1f | j_mayer | env->spr[srr0] = env->nip; |
2575 | 9a64fbe4 | bellard | break;
|
2576 | 9a64fbe4 | bellard | } |
2577 | e1833e1f | j_mayer | /* Save MSR */
|
2578 | e1833e1f | j_mayer | env->spr[srr1] = msr; |
2579 | e1833e1f | j_mayer | /* If any alternate SRR register are defined, duplicate saved values */
|
2580 | e1833e1f | j_mayer | if (asrr0 != -1) |
2581 | e1833e1f | j_mayer | env->spr[asrr0] = env->spr[srr0]; |
2582 | e1833e1f | j_mayer | if (asrr1 != -1) |
2583 | e1833e1f | j_mayer | env->spr[asrr1] = env->spr[srr1]; |
2584 | 2be0071f | bellard | /* If we disactivated any translation, flush TLBs */
|
2585 | 0411a972 | j_mayer | if (new_msr & ((1 << MSR_IR) | (1 << MSR_DR))) |
2586 | 2be0071f | bellard | tlb_flush(env, 1);
|
2587 | 9a64fbe4 | bellard | /* reload MSR with correct bits */
|
2588 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_EE);
|
2589 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_PR);
|
2590 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_FP);
|
2591 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_FE0);
|
2592 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_SE);
|
2593 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_BE);
|
2594 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_FE1);
|
2595 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_IR);
|
2596 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_DR);
|
2597 | e1833e1f | j_mayer | #if 0 /* Fix this: not on all targets */
|
2598 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_PMM);
|
2599 | e1833e1f | j_mayer | #endif
|
2600 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_LE);
|
2601 | 0411a972 | j_mayer | if (msr_ile)
|
2602 | 0411a972 | j_mayer | new_msr |= (target_ulong)1 << MSR_LE;
|
2603 | 0411a972 | j_mayer | else
|
2604 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_LE);
|
2605 | e1833e1f | j_mayer | /* Jump to handler */
|
2606 | e1833e1f | j_mayer | vector = env->excp_vectors[excp]; |
2607 | 6f2d8978 | j_mayer | if (vector == (target_ulong)-1ULL) { |
2608 | e1833e1f | j_mayer | cpu_abort(env, "Raised an exception without defined vector %d\n",
|
2609 | e1833e1f | j_mayer | excp); |
2610 | e1833e1f | j_mayer | } |
2611 | e1833e1f | j_mayer | vector |= env->excp_prefix; |
2612 | c62db105 | j_mayer | #if defined(TARGET_PPC64)
|
2613 | e1833e1f | j_mayer | if (excp_model == POWERPC_EXCP_BOOKE) {
|
2614 | 0411a972 | j_mayer | if (!msr_icm) {
|
2615 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_CM);
|
2616 | e1833e1f | j_mayer | vector = (uint32_t)vector; |
2617 | 0411a972 | j_mayer | } else {
|
2618 | 0411a972 | j_mayer | new_msr |= (target_ulong)1 << MSR_CM;
|
2619 | 0411a972 | j_mayer | } |
2620 | c62db105 | j_mayer | } else {
|
2621 | 6ce0ca12 | blueswir1 | if (!msr_isf && !(env->mmu_model & POWERPC_MMU_64)) {
|
2622 | 0411a972 | j_mayer | new_msr &= ~((target_ulong)1 << MSR_SF);
|
2623 | e1833e1f | j_mayer | vector = (uint32_t)vector; |
2624 | 0411a972 | j_mayer | } else {
|
2625 | 0411a972 | j_mayer | new_msr |= (target_ulong)1 << MSR_SF;
|
2626 | 0411a972 | j_mayer | } |
2627 | c62db105 | j_mayer | } |
2628 | e1833e1f | j_mayer | #endif
|
2629 | 0411a972 | j_mayer | /* XXX: we don't use hreg_store_msr here as already have treated
|
2630 | 0411a972 | j_mayer | * any special case that could occur. Just store MSR and update hflags
|
2631 | 0411a972 | j_mayer | */
|
2632 | a4f30719 | j_mayer | env->msr = new_msr & env->msr_mask; |
2633 | 0411a972 | j_mayer | hreg_compute_hflags(env); |
2634 | e1833e1f | j_mayer | env->nip = vector; |
2635 | e1833e1f | j_mayer | /* Reset exception state */
|
2636 | e1833e1f | j_mayer | env->exception_index = POWERPC_EXCP_NONE; |
2637 | e1833e1f | j_mayer | env->error_code = 0;
|
2638 | fb0eaffc | bellard | } |
2639 | 47103572 | j_mayer | |
2640 | e1833e1f | j_mayer | void do_interrupt (CPUState *env)
|
2641 | 47103572 | j_mayer | { |
2642 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, env->exception_index); |
2643 | e1833e1f | j_mayer | } |
2644 | 47103572 | j_mayer | |
2645 | e1833e1f | j_mayer | void ppc_hw_interrupt (CPUPPCState *env)
|
2646 | e1833e1f | j_mayer | { |
2647 | f9fdea6b | j_mayer | int hdice;
|
2648 | f9fdea6b | j_mayer | |
2649 | 0411a972 | j_mayer | #if 0
|
2650 | 93fcfe39 | aliguori | qemu_log_mask(CPU_LOG_INT, "%s: %p pending %08x req %08x me %d ee %d\n",
|
2651 | a496775f | j_mayer | __func__, env, env->pending_interrupts,
|
2652 | 0411a972 | j_mayer | env->interrupt_request, (int)msr_me, (int)msr_ee);
|
2653 | 47103572 | j_mayer | #endif
|
2654 | e1833e1f | j_mayer | /* External reset */
|
2655 | 47103572 | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_RESET)) { |
2656 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_RESET);
|
2657 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_RESET); |
2658 | e1833e1f | j_mayer | return;
|
2659 | e1833e1f | j_mayer | } |
2660 | e1833e1f | j_mayer | /* Machine check exception */
|
2661 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_MCK)) { |
2662 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_MCK);
|
2663 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_MCHECK); |
2664 | e1833e1f | j_mayer | return;
|
2665 | 47103572 | j_mayer | } |
2666 | e1833e1f | j_mayer | #if 0 /* TODO */
|
2667 | e1833e1f | j_mayer | /* External debug exception */
|
2668 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_DEBUG)) {
|
2669 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DEBUG);
|
2670 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_DEBUG);
|
2671 | e1833e1f | j_mayer | return;
|
2672 | e1833e1f | j_mayer | }
|
2673 | e1833e1f | j_mayer | #endif
|
2674 | b172c56a | j_mayer | if (0) { |
2675 | b172c56a | j_mayer | /* XXX: find a suitable condition to enable the hypervisor mode */
|
2676 | b172c56a | j_mayer | hdice = env->spr[SPR_LPCR] & 1;
|
2677 | b172c56a | j_mayer | } else {
|
2678 | b172c56a | j_mayer | hdice = 0;
|
2679 | b172c56a | j_mayer | } |
2680 | f9fdea6b | j_mayer | if ((msr_ee != 0 || msr_hv == 0 || msr_pr != 0) && hdice != 0) { |
2681 | 47103572 | j_mayer | /* Hypervisor decrementer exception */
|
2682 | 47103572 | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_HDECR)) { |
2683 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_HDECR);
|
2684 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_HDECR); |
2685 | e1833e1f | j_mayer | return;
|
2686 | e1833e1f | j_mayer | } |
2687 | e1833e1f | j_mayer | } |
2688 | e1833e1f | j_mayer | if (msr_ce != 0) { |
2689 | e1833e1f | j_mayer | /* External critical interrupt */
|
2690 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_CEXT)) { |
2691 | e1833e1f | j_mayer | /* Taking a critical external interrupt does not clear the external
|
2692 | e1833e1f | j_mayer | * critical interrupt status
|
2693 | e1833e1f | j_mayer | */
|
2694 | e1833e1f | j_mayer | #if 0
|
2695 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_CEXT);
|
2696 | 47103572 | j_mayer | #endif
|
2697 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_CRITICAL); |
2698 | e1833e1f | j_mayer | return;
|
2699 | e1833e1f | j_mayer | } |
2700 | e1833e1f | j_mayer | } |
2701 | e1833e1f | j_mayer | if (msr_ee != 0) { |
2702 | e1833e1f | j_mayer | /* Watchdog timer on embedded PowerPC */
|
2703 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_WDT)) { |
2704 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_WDT);
|
2705 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_WDT); |
2706 | e1833e1f | j_mayer | return;
|
2707 | e1833e1f | j_mayer | } |
2708 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_CDOORBELL)) { |
2709 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_CDOORBELL);
|
2710 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_DOORCI); |
2711 | e1833e1f | j_mayer | return;
|
2712 | e1833e1f | j_mayer | } |
2713 | e1833e1f | j_mayer | /* Fixed interval timer on embedded PowerPC */
|
2714 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_FIT)) { |
2715 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_FIT);
|
2716 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_FIT); |
2717 | e1833e1f | j_mayer | return;
|
2718 | e1833e1f | j_mayer | } |
2719 | e1833e1f | j_mayer | /* Programmable interval timer on embedded PowerPC */
|
2720 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_PIT)) { |
2721 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PIT);
|
2722 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_PIT); |
2723 | e1833e1f | j_mayer | return;
|
2724 | e1833e1f | j_mayer | } |
2725 | 47103572 | j_mayer | /* Decrementer exception */
|
2726 | 47103572 | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_DECR)) { |
2727 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DECR);
|
2728 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_DECR); |
2729 | e1833e1f | j_mayer | return;
|
2730 | e1833e1f | j_mayer | } |
2731 | 47103572 | j_mayer | /* External interrupt */
|
2732 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_EXT)) { |
2733 | e9df014c | j_mayer | /* Taking an external interrupt does not clear the external
|
2734 | e9df014c | j_mayer | * interrupt status
|
2735 | e9df014c | j_mayer | */
|
2736 | e9df014c | j_mayer | #if 0
|
2737 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_EXT);
|
2738 | e9df014c | j_mayer | #endif
|
2739 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_EXTERNAL); |
2740 | e1833e1f | j_mayer | return;
|
2741 | e1833e1f | j_mayer | } |
2742 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_DOORBELL)) { |
2743 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DOORBELL);
|
2744 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_DOORI); |
2745 | e1833e1f | j_mayer | return;
|
2746 | 47103572 | j_mayer | } |
2747 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_PERFM)) { |
2748 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PERFM);
|
2749 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_PERFM); |
2750 | e1833e1f | j_mayer | return;
|
2751 | e1833e1f | j_mayer | } |
2752 | e1833e1f | j_mayer | /* Thermal interrupt */
|
2753 | e1833e1f | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_THERM)) { |
2754 | e1833e1f | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_THERM);
|
2755 | e1833e1f | j_mayer | powerpc_excp(env, env->excp_model, POWERPC_EXCP_THERM); |
2756 | e1833e1f | j_mayer | return;
|
2757 | e1833e1f | j_mayer | } |
2758 | 47103572 | j_mayer | } |
2759 | 47103572 | j_mayer | } |
2760 | 18fba28c | bellard | #endif /* !CONFIG_USER_ONLY */ |
2761 | a496775f | j_mayer | |
2762 | 4a057712 | j_mayer | void cpu_dump_rfi (target_ulong RA, target_ulong msr)
|
2763 | 4a057712 | j_mayer | { |
2764 | 93fcfe39 | aliguori | qemu_log("Return from exception at " ADDRX " with flags " ADDRX "\n", |
2765 | 93fcfe39 | aliguori | RA, msr); |
2766 | a496775f | j_mayer | } |
2767 | a496775f | j_mayer | |
2768 | 0a032cbe | j_mayer | void cpu_ppc_reset (void *opaque) |
2769 | 0a032cbe | j_mayer | { |
2770 | eca1bdf4 | aliguori | CPUPPCState *env = opaque; |
2771 | 0411a972 | j_mayer | target_ulong msr; |
2772 | 0a032cbe | j_mayer | |
2773 | eca1bdf4 | aliguori | if (qemu_loglevel_mask(CPU_LOG_RESET)) {
|
2774 | eca1bdf4 | aliguori | qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
|
2775 | eca1bdf4 | aliguori | log_cpu_state(env, 0);
|
2776 | eca1bdf4 | aliguori | } |
2777 | eca1bdf4 | aliguori | |
2778 | 0411a972 | j_mayer | msr = (target_ulong)0;
|
2779 | a4f30719 | j_mayer | if (0) { |
2780 | a4f30719 | j_mayer | /* XXX: find a suitable condition to enable the hypervisor mode */
|
2781 | a4f30719 | j_mayer | msr |= (target_ulong)MSR_HVB; |
2782 | a4f30719 | j_mayer | } |
2783 | 0411a972 | j_mayer | msr |= (target_ulong)0 << MSR_AP; /* TO BE CHECKED */ |
2784 | 0411a972 | j_mayer | msr |= (target_ulong)0 << MSR_SA; /* TO BE CHECKED */ |
2785 | 0411a972 | j_mayer | msr |= (target_ulong)1 << MSR_EP;
|
2786 | 0a032cbe | j_mayer | #if defined (DO_SINGLE_STEP) && 0 |
2787 | 0a032cbe | j_mayer | /* Single step trace mode */
|
2788 | 0411a972 | j_mayer | msr |= (target_ulong)1 << MSR_SE;
|
2789 | 0411a972 | j_mayer | msr |= (target_ulong)1 << MSR_BE;
|
2790 | 0a032cbe | j_mayer | #endif
|
2791 | 0a032cbe | j_mayer | #if defined(CONFIG_USER_ONLY)
|
2792 | 0411a972 | j_mayer | msr |= (target_ulong)1 << MSR_FP; /* Allow floating point usage */ |
2793 | 4c2ab988 | aurel32 | msr |= (target_ulong)1 << MSR_VR; /* Allow altivec usage */ |
2794 | 4c2ab988 | aurel32 | msr |= (target_ulong)1 << MSR_SPE; /* Allow SPE usage */ |
2795 | 0411a972 | j_mayer | msr |= (target_ulong)1 << MSR_PR;
|
2796 | 0a032cbe | j_mayer | #else
|
2797 | 1c27f8fb | j_mayer | env->nip = env->hreset_vector | env->excp_prefix; |
2798 | b4095fed | j_mayer | if (env->mmu_model != POWERPC_MMU_REAL)
|
2799 | 141c8ae2 | j_mayer | ppc_tlb_invalidate_all(env); |
2800 | 0a032cbe | j_mayer | #endif
|
2801 | 07c485ce | blueswir1 | env->msr = msr & env->msr_mask; |
2802 | 6ce0ca12 | blueswir1 | #if defined(TARGET_PPC64)
|
2803 | 6ce0ca12 | blueswir1 | if (env->mmu_model & POWERPC_MMU_64)
|
2804 | 6ce0ca12 | blueswir1 | env->msr |= (1ULL << MSR_SF);
|
2805 | 6ce0ca12 | blueswir1 | #endif
|
2806 | 0411a972 | j_mayer | hreg_compute_hflags(env); |
2807 | 6f2d8978 | j_mayer | env->reserve = (target_ulong)-1ULL;
|
2808 | 5eb7995e | j_mayer | /* Be sure no exception or interrupt is pending */
|
2809 | 5eb7995e | j_mayer | env->pending_interrupts = 0;
|
2810 | e1833e1f | j_mayer | env->exception_index = POWERPC_EXCP_NONE; |
2811 | e1833e1f | j_mayer | env->error_code = 0;
|
2812 | 5eb7995e | j_mayer | /* Flush all TLBs */
|
2813 | 5eb7995e | j_mayer | tlb_flush(env, 1);
|
2814 | 0a032cbe | j_mayer | } |
2815 | 0a032cbe | j_mayer | |
2816 | aaed909a | bellard | CPUPPCState *cpu_ppc_init (const char *cpu_model) |
2817 | 0a032cbe | j_mayer | { |
2818 | 0a032cbe | j_mayer | CPUPPCState *env; |
2819 | aaed909a | bellard | const ppc_def_t *def;
|
2820 | aaed909a | bellard | |
2821 | aaed909a | bellard | def = cpu_ppc_find_by_name(cpu_model); |
2822 | aaed909a | bellard | if (!def)
|
2823 | aaed909a | bellard | return NULL; |
2824 | 0a032cbe | j_mayer | |
2825 | 0a032cbe | j_mayer | env = qemu_mallocz(sizeof(CPUPPCState));
|
2826 | 0a032cbe | j_mayer | cpu_exec_init(env); |
2827 | 2e70f6ef | pbrook | ppc_translate_init(); |
2828 | 01ba9816 | ths | env->cpu_model_str = cpu_model; |
2829 | aaed909a | bellard | cpu_ppc_register_internal(env, def); |
2830 | aaed909a | bellard | cpu_ppc_reset(env); |
2831 | d76d1650 | aurel32 | |
2832 | d76d1650 | aurel32 | if (kvm_enabled())
|
2833 | d76d1650 | aurel32 | kvm_init_vcpu(env); |
2834 | d76d1650 | aurel32 | |
2835 | 0a032cbe | j_mayer | return env;
|
2836 | 0a032cbe | j_mayer | } |
2837 | 0a032cbe | j_mayer | |
2838 | 0a032cbe | j_mayer | void cpu_ppc_close (CPUPPCState *env)
|
2839 | 0a032cbe | j_mayer | { |
2840 | 0a032cbe | j_mayer | /* Should also remove all opcode tables... */
|
2841 | aaed909a | bellard | qemu_free(env); |
2842 | 0a032cbe | j_mayer | } |