root / target-ppc / helper.c @ 36081602
History | View | Annotate | Download (70.4 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 | 79aceca5 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 | 9a64fbe4 | bellard | |
31 | 9a64fbe4 | bellard | //#define DEBUG_MMU
|
32 | 9a64fbe4 | bellard | //#define DEBUG_BATS
|
33 | 76a66253 | j_mayer | //#define DEBUG_SOFTWARE_TLB
|
34 | 9a64fbe4 | bellard | //#define DEBUG_EXCEPTIONS
|
35 | fdabc366 | bellard | //#define FLUSH_ALL_TLBS
|
36 | 9a64fbe4 | bellard | |
37 | 9a64fbe4 | bellard | /*****************************************************************************/
|
38 | 3fc6c082 | bellard | /* PowerPC MMU emulation */
|
39 | a541f297 | bellard | |
40 | d9bce9d9 | j_mayer | #if defined(CONFIG_USER_ONLY)
|
41 | e96efcfc | j_mayer | int cpu_ppc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, |
42 | 24741ef3 | bellard | int is_user, int is_softmmu) |
43 | 24741ef3 | bellard | { |
44 | 24741ef3 | bellard | int exception, error_code;
|
45 | d9bce9d9 | j_mayer | |
46 | 24741ef3 | bellard | if (rw == 2) { |
47 | 24741ef3 | bellard | exception = EXCP_ISI; |
48 | 24741ef3 | bellard | error_code = 0;
|
49 | 24741ef3 | bellard | } else {
|
50 | 24741ef3 | bellard | exception = EXCP_DSI; |
51 | 24741ef3 | bellard | error_code = 0;
|
52 | 24741ef3 | bellard | if (rw)
|
53 | 24741ef3 | bellard | error_code |= 0x02000000;
|
54 | 24741ef3 | bellard | env->spr[SPR_DAR] = address; |
55 | 24741ef3 | bellard | env->spr[SPR_DSISR] = error_code; |
56 | 24741ef3 | bellard | } |
57 | 24741ef3 | bellard | env->exception_index = exception; |
58 | 24741ef3 | bellard | env->error_code = error_code; |
59 | 76a66253 | j_mayer | |
60 | 24741ef3 | bellard | return 1; |
61 | 24741ef3 | bellard | } |
62 | 76a66253 | j_mayer | |
63 | 9b3c35e0 | j_mayer | target_phys_addr_t cpu_get_phys_page_debug (CPUState *env, target_ulong addr) |
64 | 24741ef3 | bellard | { |
65 | 24741ef3 | bellard | return addr;
|
66 | 24741ef3 | bellard | } |
67 | 36081602 | j_mayer | |
68 | 24741ef3 | bellard | #else
|
69 | 76a66253 | j_mayer | /* Common routines used by software and hardware TLBs emulation */
|
70 | 76a66253 | j_mayer | static inline int pte_is_valid (target_ulong pte0) |
71 | 76a66253 | j_mayer | { |
72 | 76a66253 | j_mayer | return pte0 & 0x80000000 ? 1 : 0; |
73 | 76a66253 | j_mayer | } |
74 | 76a66253 | j_mayer | |
75 | 76a66253 | j_mayer | static inline void pte_invalidate (target_ulong *pte0) |
76 | 76a66253 | j_mayer | { |
77 | 76a66253 | j_mayer | *pte0 &= ~0x80000000;
|
78 | 76a66253 | j_mayer | } |
79 | 76a66253 | j_mayer | |
80 | 76a66253 | j_mayer | #define PTE_PTEM_MASK 0x7FFFFFBF |
81 | 76a66253 | j_mayer | #define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B) |
82 | 76a66253 | j_mayer | |
83 | 76a66253 | j_mayer | static int pte_check (mmu_ctx_t *ctx, |
84 | 76a66253 | j_mayer | target_ulong pte0, target_ulong pte1, int h, int rw) |
85 | 76a66253 | j_mayer | { |
86 | 76a66253 | j_mayer | int access, ret;
|
87 | 76a66253 | j_mayer | |
88 | 76a66253 | j_mayer | access = 0;
|
89 | 76a66253 | j_mayer | ret = -1;
|
90 | 76a66253 | j_mayer | /* Check validity and table match */
|
91 | 76a66253 | j_mayer | if (pte_is_valid(pte0) && (h == ((pte0 >> 6) & 1))) { |
92 | 76a66253 | j_mayer | /* Check vsid & api */
|
93 | 76a66253 | j_mayer | if ((pte0 & PTE_PTEM_MASK) == ctx->ptem) {
|
94 | 76a66253 | j_mayer | if (ctx->raddr != (target_ulong)-1) { |
95 | 76a66253 | j_mayer | /* all matches should have equal RPN, WIMG & PP */
|
96 | 76a66253 | j_mayer | if ((ctx->raddr & PTE_CHECK_MASK) != (pte1 & PTE_CHECK_MASK)) {
|
97 | 76a66253 | j_mayer | if (loglevel > 0) |
98 | 76a66253 | j_mayer | fprintf(logfile, "Bad RPN/WIMG/PP\n");
|
99 | 76a66253 | j_mayer | return -3; |
100 | 76a66253 | j_mayer | } |
101 | 76a66253 | j_mayer | } |
102 | 76a66253 | j_mayer | /* Compute access rights */
|
103 | 76a66253 | j_mayer | if (ctx->key == 0) { |
104 | 76a66253 | j_mayer | access = PAGE_READ; |
105 | 76a66253 | j_mayer | if ((pte1 & 0x00000003) != 0x3) |
106 | 76a66253 | j_mayer | access |= PAGE_WRITE; |
107 | 76a66253 | j_mayer | } else {
|
108 | 76a66253 | j_mayer | switch (pte1 & 0x00000003) { |
109 | 76a66253 | j_mayer | case 0x0: |
110 | 76a66253 | j_mayer | access = 0;
|
111 | 76a66253 | j_mayer | break;
|
112 | 76a66253 | j_mayer | case 0x1: |
113 | 76a66253 | j_mayer | case 0x3: |
114 | 76a66253 | j_mayer | access = PAGE_READ; |
115 | 76a66253 | j_mayer | break;
|
116 | 76a66253 | j_mayer | case 0x2: |
117 | 76a66253 | j_mayer | access = PAGE_READ | PAGE_WRITE; |
118 | 76a66253 | j_mayer | break;
|
119 | 76a66253 | j_mayer | } |
120 | 76a66253 | j_mayer | } |
121 | 76a66253 | j_mayer | /* Keep the matching PTE informations */
|
122 | 76a66253 | j_mayer | ctx->raddr = pte1; |
123 | 76a66253 | j_mayer | ctx->prot = access; |
124 | 76a66253 | j_mayer | if ((rw == 0 && (access & PAGE_READ)) || |
125 | 76a66253 | j_mayer | (rw == 1 && (access & PAGE_WRITE))) {
|
126 | 76a66253 | j_mayer | /* Access granted */
|
127 | 76a66253 | j_mayer | #if defined (DEBUG_MMU)
|
128 | 4a057712 | j_mayer | if (loglevel != 0) |
129 | 76a66253 | j_mayer | fprintf(logfile, "PTE access granted !\n");
|
130 | 76a66253 | j_mayer | #endif
|
131 | 76a66253 | j_mayer | ret = 0;
|
132 | 76a66253 | j_mayer | } else {
|
133 | 76a66253 | j_mayer | /* Access right violation */
|
134 | 76a66253 | j_mayer | #if defined (DEBUG_MMU)
|
135 | 4a057712 | j_mayer | if (loglevel != 0) |
136 | 76a66253 | j_mayer | fprintf(logfile, "PTE access rejected\n");
|
137 | 76a66253 | j_mayer | #endif
|
138 | 76a66253 | j_mayer | ret = -2;
|
139 | 76a66253 | j_mayer | } |
140 | 76a66253 | j_mayer | } |
141 | 76a66253 | j_mayer | } |
142 | 76a66253 | j_mayer | |
143 | 76a66253 | j_mayer | return ret;
|
144 | 76a66253 | j_mayer | } |
145 | 76a66253 | j_mayer | |
146 | 76a66253 | j_mayer | static int pte_update_flags (mmu_ctx_t *ctx, target_ulong *pte1p, |
147 | 76a66253 | j_mayer | int ret, int rw) |
148 | 76a66253 | j_mayer | { |
149 | 76a66253 | j_mayer | int store = 0; |
150 | 76a66253 | j_mayer | |
151 | 76a66253 | j_mayer | /* Update page flags */
|
152 | 76a66253 | j_mayer | if (!(*pte1p & 0x00000100)) { |
153 | 76a66253 | j_mayer | /* Update accessed flag */
|
154 | 76a66253 | j_mayer | *pte1p |= 0x00000100;
|
155 | 76a66253 | j_mayer | store = 1;
|
156 | 76a66253 | j_mayer | } |
157 | 76a66253 | j_mayer | if (!(*pte1p & 0x00000080)) { |
158 | 76a66253 | j_mayer | if (rw == 1 && ret == 0) { |
159 | 76a66253 | j_mayer | /* Update changed flag */
|
160 | 76a66253 | j_mayer | *pte1p |= 0x00000080;
|
161 | 76a66253 | j_mayer | store = 1;
|
162 | 76a66253 | j_mayer | } else {
|
163 | 76a66253 | j_mayer | /* Force page fault for first write access */
|
164 | 76a66253 | j_mayer | ctx->prot &= ~PAGE_WRITE; |
165 | 76a66253 | j_mayer | } |
166 | 76a66253 | j_mayer | } |
167 | 76a66253 | j_mayer | |
168 | 76a66253 | j_mayer | return store;
|
169 | 76a66253 | j_mayer | } |
170 | 76a66253 | j_mayer | |
171 | 76a66253 | j_mayer | /* Software driven TLB helpers */
|
172 | 76a66253 | j_mayer | static int ppc6xx_tlb_getnum (CPUState *env, target_ulong eaddr, |
173 | 76a66253 | j_mayer | int way, int is_code) |
174 | 76a66253 | j_mayer | { |
175 | 76a66253 | j_mayer | int nr;
|
176 | 76a66253 | j_mayer | |
177 | 76a66253 | j_mayer | /* Select TLB num in a way from address */
|
178 | 76a66253 | j_mayer | nr = (eaddr >> TARGET_PAGE_BITS) & (env->tlb_per_way - 1);
|
179 | 76a66253 | j_mayer | /* Select TLB way */
|
180 | 76a66253 | j_mayer | nr += env->tlb_per_way * way; |
181 | 76a66253 | j_mayer | /* 6xx have separate TLBs for instructions and data */
|
182 | 76a66253 | j_mayer | if (is_code && env->id_tlbs == 1) |
183 | 76a66253 | j_mayer | nr += env->nb_tlb; |
184 | 76a66253 | j_mayer | |
185 | 76a66253 | j_mayer | return nr;
|
186 | 76a66253 | j_mayer | } |
187 | 76a66253 | j_mayer | |
188 | 76a66253 | j_mayer | void ppc6xx_tlb_invalidate_all (CPUState *env)
|
189 | 76a66253 | j_mayer | { |
190 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
191 | 76a66253 | j_mayer | int nr, max;
|
192 | 76a66253 | j_mayer | |
193 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB) && 0 |
194 | 76a66253 | j_mayer | if (loglevel != 0) { |
195 | 76a66253 | j_mayer | fprintf(logfile, "Invalidate all TLBs\n");
|
196 | 76a66253 | j_mayer | } |
197 | 76a66253 | j_mayer | #endif
|
198 | 76a66253 | j_mayer | /* Invalidate all defined software TLB */
|
199 | 76a66253 | j_mayer | max = env->nb_tlb; |
200 | 76a66253 | j_mayer | if (env->id_tlbs == 1) |
201 | 76a66253 | j_mayer | max *= 2;
|
202 | 76a66253 | j_mayer | for (nr = 0; nr < max; nr++) { |
203 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
204 | 76a66253 | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
205 | 76a66253 | j_mayer | tlb_flush_page(env, tlb->EPN); |
206 | 76a66253 | j_mayer | #endif
|
207 | 76a66253 | j_mayer | pte_invalidate(&tlb->pte0); |
208 | 76a66253 | j_mayer | } |
209 | 76a66253 | j_mayer | #if defined(FLUSH_ALL_TLBS)
|
210 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
211 | 76a66253 | j_mayer | #endif
|
212 | 76a66253 | j_mayer | } |
213 | 76a66253 | j_mayer | |
214 | 76a66253 | j_mayer | static inline void __ppc6xx_tlb_invalidate_virt (CPUState *env, |
215 | 76a66253 | j_mayer | target_ulong eaddr, |
216 | 76a66253 | j_mayer | int is_code, int match_epn) |
217 | 76a66253 | j_mayer | { |
218 | 4a057712 | j_mayer | #if !defined(FLUSH_ALL_TLBS)
|
219 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
220 | 76a66253 | j_mayer | int way, nr;
|
221 | 76a66253 | j_mayer | |
222 | 76a66253 | j_mayer | /* Invalidate ITLB + DTLB, all ways */
|
223 | 76a66253 | j_mayer | for (way = 0; way < env->nb_ways; way++) { |
224 | 76a66253 | j_mayer | nr = ppc6xx_tlb_getnum(env, eaddr, way, is_code); |
225 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
226 | 76a66253 | j_mayer | if (pte_is_valid(tlb->pte0) && (match_epn == 0 || eaddr == tlb->EPN)) { |
227 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
228 | 76a66253 | j_mayer | if (loglevel != 0) { |
229 | 1b9eb036 | j_mayer | fprintf(logfile, "TLB invalidate %d/%d " ADDRX "\n", |
230 | 76a66253 | j_mayer | nr, env->nb_tlb, eaddr); |
231 | 76a66253 | j_mayer | } |
232 | 76a66253 | j_mayer | #endif
|
233 | 76a66253 | j_mayer | pte_invalidate(&tlb->pte0); |
234 | 76a66253 | j_mayer | tlb_flush_page(env, tlb->EPN); |
235 | 76a66253 | j_mayer | } |
236 | 76a66253 | j_mayer | } |
237 | 76a66253 | j_mayer | #else
|
238 | 76a66253 | j_mayer | /* XXX: PowerPC specification say this is valid as well */
|
239 | 76a66253 | j_mayer | ppc6xx_tlb_invalidate_all(env); |
240 | 76a66253 | j_mayer | #endif
|
241 | 76a66253 | j_mayer | } |
242 | 76a66253 | j_mayer | |
243 | 76a66253 | j_mayer | void ppc6xx_tlb_invalidate_virt (CPUState *env, target_ulong eaddr,
|
244 | 76a66253 | j_mayer | int is_code)
|
245 | 76a66253 | j_mayer | { |
246 | 76a66253 | j_mayer | __ppc6xx_tlb_invalidate_virt(env, eaddr, is_code, 0);
|
247 | 76a66253 | j_mayer | } |
248 | 76a66253 | j_mayer | |
249 | 76a66253 | j_mayer | void ppc6xx_tlb_store (CPUState *env, target_ulong EPN, int way, int is_code, |
250 | 76a66253 | j_mayer | target_ulong pte0, target_ulong pte1) |
251 | 76a66253 | j_mayer | { |
252 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
253 | 76a66253 | j_mayer | int nr;
|
254 | 76a66253 | j_mayer | |
255 | 76a66253 | j_mayer | nr = ppc6xx_tlb_getnum(env, EPN, way, is_code); |
256 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
257 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
258 | 76a66253 | j_mayer | if (loglevel != 0) { |
259 | 5fafdf24 | ths | fprintf(logfile, "Set TLB %d/%d EPN " ADDRX " PTE0 " ADDRX |
260 | 1b9eb036 | j_mayer | " PTE1 " ADDRX "\n", nr, env->nb_tlb, EPN, pte0, pte1); |
261 | 76a66253 | j_mayer | } |
262 | 76a66253 | j_mayer | #endif
|
263 | 76a66253 | j_mayer | /* Invalidate any pending reference in Qemu for this virtual address */
|
264 | 76a66253 | j_mayer | __ppc6xx_tlb_invalidate_virt(env, EPN, is_code, 1);
|
265 | 76a66253 | j_mayer | tlb->pte0 = pte0; |
266 | 76a66253 | j_mayer | tlb->pte1 = pte1; |
267 | 76a66253 | j_mayer | tlb->EPN = EPN; |
268 | 76a66253 | j_mayer | /* Store last way for LRU mechanism */
|
269 | 76a66253 | j_mayer | env->last_way = way; |
270 | 76a66253 | j_mayer | } |
271 | 76a66253 | j_mayer | |
272 | 76a66253 | j_mayer | static int ppc6xx_tlb_check (CPUState *env, mmu_ctx_t *ctx, |
273 | 76a66253 | j_mayer | target_ulong eaddr, int rw, int access_type) |
274 | 76a66253 | j_mayer | { |
275 | 1d0a48fb | j_mayer | ppc6xx_tlb_t *tlb; |
276 | 76a66253 | j_mayer | int nr, best, way;
|
277 | 76a66253 | j_mayer | int ret;
|
278 | d9bce9d9 | j_mayer | |
279 | 76a66253 | j_mayer | best = -1;
|
280 | 76a66253 | j_mayer | ret = -1; /* No TLB found */ |
281 | 76a66253 | j_mayer | for (way = 0; way < env->nb_ways; way++) { |
282 | 76a66253 | j_mayer | nr = ppc6xx_tlb_getnum(env, eaddr, way, |
283 | 76a66253 | j_mayer | access_type == ACCESS_CODE ? 1 : 0); |
284 | 1d0a48fb | j_mayer | tlb = &env->tlb[nr].tlb6; |
285 | 76a66253 | j_mayer | /* This test "emulates" the PTE index match for hardware TLBs */
|
286 | 76a66253 | j_mayer | if ((eaddr & TARGET_PAGE_MASK) != tlb->EPN) {
|
287 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
288 | 76a66253 | j_mayer | if (loglevel != 0) { |
289 | 1b9eb036 | j_mayer | fprintf(logfile, "TLB %d/%d %s [" ADDRX " " ADDRX |
290 | 1b9eb036 | j_mayer | "] <> " ADDRX "\n", |
291 | 76a66253 | j_mayer | nr, env->nb_tlb, |
292 | 76a66253 | j_mayer | pte_is_valid(tlb->pte0) ? "valid" : "inval", |
293 | 76a66253 | j_mayer | tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, eaddr); |
294 | 76a66253 | j_mayer | } |
295 | 76a66253 | j_mayer | #endif
|
296 | 76a66253 | j_mayer | continue;
|
297 | 76a66253 | j_mayer | } |
298 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
299 | 76a66253 | j_mayer | if (loglevel != 0) { |
300 | 1b9eb036 | j_mayer | fprintf(logfile, "TLB %d/%d %s " ADDRX " <> " ADDRX " " ADDRX |
301 | 1b9eb036 | j_mayer | " %c %c\n",
|
302 | 76a66253 | j_mayer | nr, env->nb_tlb, |
303 | 76a66253 | j_mayer | pte_is_valid(tlb->pte0) ? "valid" : "inval", |
304 | 76a66253 | j_mayer | tlb->EPN, eaddr, tlb->pte1, |
305 | 76a66253 | j_mayer | rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D'); |
306 | 76a66253 | j_mayer | } |
307 | 76a66253 | j_mayer | #endif
|
308 | 76a66253 | j_mayer | switch (pte_check(ctx, tlb->pte0, tlb->pte1, 0, rw)) { |
309 | 76a66253 | j_mayer | case -3: |
310 | 76a66253 | j_mayer | /* TLB inconsistency */
|
311 | 76a66253 | j_mayer | return -1; |
312 | 76a66253 | j_mayer | case -2: |
313 | 76a66253 | j_mayer | /* Access violation */
|
314 | 76a66253 | j_mayer | ret = -2;
|
315 | 76a66253 | j_mayer | best = nr; |
316 | 76a66253 | j_mayer | break;
|
317 | 76a66253 | j_mayer | case -1: |
318 | 76a66253 | j_mayer | default:
|
319 | 76a66253 | j_mayer | /* No match */
|
320 | 76a66253 | j_mayer | break;
|
321 | 76a66253 | j_mayer | case 0: |
322 | 76a66253 | j_mayer | /* access granted */
|
323 | 76a66253 | j_mayer | /* XXX: we should go on looping to check all TLBs consistency
|
324 | 76a66253 | j_mayer | * but we can speed-up the whole thing as the
|
325 | 76a66253 | j_mayer | * result would be undefined if TLBs are not consistent.
|
326 | 76a66253 | j_mayer | */
|
327 | 76a66253 | j_mayer | ret = 0;
|
328 | 76a66253 | j_mayer | best = nr; |
329 | 76a66253 | j_mayer | goto done;
|
330 | 76a66253 | j_mayer | } |
331 | 76a66253 | j_mayer | } |
332 | 76a66253 | j_mayer | if (best != -1) { |
333 | 76a66253 | j_mayer | done:
|
334 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
335 | 4a057712 | j_mayer | if (loglevel != 0) { |
336 | 76a66253 | j_mayer | fprintf(logfile, "found TLB at addr 0x%08lx prot=0x%01x ret=%d\n",
|
337 | 76a66253 | j_mayer | ctx->raddr & TARGET_PAGE_MASK, ctx->prot, ret); |
338 | 76a66253 | j_mayer | } |
339 | 76a66253 | j_mayer | #endif
|
340 | 76a66253 | j_mayer | /* Update page flags */
|
341 | 1d0a48fb | j_mayer | pte_update_flags(ctx, &env->tlb[best].tlb6.pte1, ret, rw); |
342 | 76a66253 | j_mayer | } |
343 | 76a66253 | j_mayer | |
344 | 76a66253 | j_mayer | return ret;
|
345 | 76a66253 | j_mayer | } |
346 | 76a66253 | j_mayer | |
347 | 9a64fbe4 | bellard | /* Perform BAT hit & translation */
|
348 | 76a66253 | j_mayer | static int get_bat (CPUState *env, mmu_ctx_t *ctx, |
349 | 76a66253 | j_mayer | target_ulong virtual, int rw, int type) |
350 | 9a64fbe4 | bellard | { |
351 | 76a66253 | j_mayer | target_ulong *BATlt, *BATut, *BATu, *BATl; |
352 | 76a66253 | j_mayer | target_ulong base, BEPIl, BEPIu, bl; |
353 | 9a64fbe4 | bellard | int i;
|
354 | 9a64fbe4 | bellard | int ret = -1; |
355 | 9a64fbe4 | bellard | |
356 | 9a64fbe4 | bellard | #if defined (DEBUG_BATS)
|
357 | 4a057712 | j_mayer | if (loglevel != 0) { |
358 | 1b9eb036 | j_mayer | fprintf(logfile, "%s: %cBAT v 0x" ADDRX "\n", __func__, |
359 | 76a66253 | j_mayer | type == ACCESS_CODE ? 'I' : 'D', virtual); |
360 | 9a64fbe4 | bellard | } |
361 | 9a64fbe4 | bellard | #endif
|
362 | 9a64fbe4 | bellard | switch (type) {
|
363 | 9a64fbe4 | bellard | case ACCESS_CODE:
|
364 | 9a64fbe4 | bellard | BATlt = env->IBAT[1];
|
365 | 9a64fbe4 | bellard | BATut = env->IBAT[0];
|
366 | 9a64fbe4 | bellard | break;
|
367 | 9a64fbe4 | bellard | default:
|
368 | 9a64fbe4 | bellard | BATlt = env->DBAT[1];
|
369 | 9a64fbe4 | bellard | BATut = env->DBAT[0];
|
370 | 9a64fbe4 | bellard | break;
|
371 | 9a64fbe4 | bellard | } |
372 | 9a64fbe4 | bellard | #if defined (DEBUG_BATS)
|
373 | 4a057712 | j_mayer | if (loglevel != 0) { |
374 | 1b9eb036 | j_mayer | fprintf(logfile, "%s...: %cBAT v 0x" ADDRX "\n", __func__, |
375 | 76a66253 | j_mayer | type == ACCESS_CODE ? 'I' : 'D', virtual); |
376 | 9a64fbe4 | bellard | } |
377 | 9a64fbe4 | bellard | #endif
|
378 | 9a64fbe4 | bellard | base = virtual & 0xFFFC0000;
|
379 | 9a64fbe4 | bellard | for (i = 0; i < 4; i++) { |
380 | 9a64fbe4 | bellard | BATu = &BATut[i]; |
381 | 9a64fbe4 | bellard | BATl = &BATlt[i]; |
382 | 9a64fbe4 | bellard | BEPIu = *BATu & 0xF0000000;
|
383 | 9a64fbe4 | bellard | BEPIl = *BATu & 0x0FFE0000;
|
384 | 9a64fbe4 | bellard | bl = (*BATu & 0x00001FFC) << 15; |
385 | 9a64fbe4 | bellard | #if defined (DEBUG_BATS)
|
386 | 4a057712 | j_mayer | if (loglevel != 0) { |
387 | 5fafdf24 | ths | fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX |
388 | 1b9eb036 | j_mayer | " BATl 0x" ADDRX "\n", |
389 | 9a64fbe4 | bellard | __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual, |
390 | 9a64fbe4 | bellard | *BATu, *BATl); |
391 | 9a64fbe4 | bellard | } |
392 | 9a64fbe4 | bellard | #endif
|
393 | 9a64fbe4 | bellard | if ((virtual & 0xF0000000) == BEPIu && |
394 | 9a64fbe4 | bellard | ((virtual & 0x0FFE0000) & ~bl) == BEPIl) {
|
395 | 9a64fbe4 | bellard | /* BAT matches */
|
396 | 9a64fbe4 | bellard | if ((msr_pr == 0 && (*BATu & 0x00000002)) || |
397 | 9a64fbe4 | bellard | (msr_pr == 1 && (*BATu & 0x00000001))) { |
398 | 9a64fbe4 | bellard | /* Get physical address */
|
399 | 76a66253 | j_mayer | ctx->raddr = (*BATl & 0xF0000000) |
|
400 | 9a64fbe4 | bellard | ((virtual & 0x0FFE0000 & bl) | (*BATl & 0x0FFE0000)) | |
401 | a541f297 | bellard | (virtual & 0x0001F000);
|
402 | 9a64fbe4 | bellard | if (*BATl & 0x00000001) |
403 | 76a66253 | j_mayer | ctx->prot = PAGE_READ; |
404 | 9a64fbe4 | bellard | if (*BATl & 0x00000002) |
405 | 76a66253 | j_mayer | ctx->prot = PAGE_WRITE | PAGE_READ; |
406 | 9a64fbe4 | bellard | #if defined (DEBUG_BATS)
|
407 | 4a057712 | j_mayer | if (loglevel != 0) { |
408 | 4a057712 | j_mayer | fprintf(logfile, "BAT %d match: r 0x" PADDRX
|
409 | 1b9eb036 | j_mayer | " prot=%c%c\n",
|
410 | 76a66253 | j_mayer | i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-', |
411 | 76a66253 | j_mayer | ctx->prot & PAGE_WRITE ? 'W' : '-'); |
412 | 9a64fbe4 | bellard | } |
413 | 9a64fbe4 | bellard | #endif
|
414 | 9a64fbe4 | bellard | ret = 0;
|
415 | 9a64fbe4 | bellard | break;
|
416 | 9a64fbe4 | bellard | } |
417 | 9a64fbe4 | bellard | } |
418 | 9a64fbe4 | bellard | } |
419 | 9a64fbe4 | bellard | if (ret < 0) { |
420 | 9a64fbe4 | bellard | #if defined (DEBUG_BATS)
|
421 | 4a057712 | j_mayer | if (loglevel != 0) { |
422 | 4a057712 | j_mayer | fprintf(logfile, "no BAT match for 0x" ADDRX ":\n", virtual); |
423 | 4a057712 | j_mayer | for (i = 0; i < 4; i++) { |
424 | 4a057712 | j_mayer | BATu = &BATut[i]; |
425 | 4a057712 | j_mayer | BATl = &BATlt[i]; |
426 | 4a057712 | j_mayer | BEPIu = *BATu & 0xF0000000;
|
427 | 4a057712 | j_mayer | BEPIl = *BATu & 0x0FFE0000;
|
428 | 4a057712 | j_mayer | bl = (*BATu & 0x00001FFC) << 15; |
429 | 4a057712 | j_mayer | fprintf(logfile, "%s: %cBAT%d v 0x" ADDRX " BATu 0x" ADDRX |
430 | 4a057712 | j_mayer | " BATl 0x" ADDRX " \n\t" |
431 | 4a057712 | j_mayer | "0x" ADDRX " 0x" ADDRX " 0x" ADDRX "\n", |
432 | 4a057712 | j_mayer | __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual, |
433 | 4a057712 | j_mayer | *BATu, *BATl, BEPIu, BEPIl, bl); |
434 | 4a057712 | j_mayer | } |
435 | 9a64fbe4 | bellard | } |
436 | 9a64fbe4 | bellard | #endif
|
437 | 9a64fbe4 | bellard | } |
438 | 9a64fbe4 | bellard | /* No hit */
|
439 | 9a64fbe4 | bellard | return ret;
|
440 | 9a64fbe4 | bellard | } |
441 | 9a64fbe4 | bellard | |
442 | 9a64fbe4 | bellard | /* PTE table lookup */
|
443 | 76a66253 | j_mayer | static int find_pte (mmu_ctx_t *ctx, int h, int rw) |
444 | 9a64fbe4 | bellard | { |
445 | 76a66253 | j_mayer | target_ulong base, pte0, pte1; |
446 | 76a66253 | j_mayer | int i, good = -1; |
447 | 76a66253 | j_mayer | int ret;
|
448 | 9a64fbe4 | bellard | |
449 | 76a66253 | j_mayer | ret = -1; /* No entry found */ |
450 | 76a66253 | j_mayer | base = ctx->pg_addr[h]; |
451 | 9a64fbe4 | bellard | for (i = 0; i < 8; i++) { |
452 | 8df1cd07 | bellard | pte0 = ldl_phys(base + (i * 8));
|
453 | 8df1cd07 | bellard | pte1 = ldl_phys(base + (i * 8) + 4); |
454 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
455 | d094807b | bellard | if (loglevel > 0) { |
456 | 5fafdf24 | ths | fprintf(logfile, "Load pte from 0x" ADDRX " => 0x" ADDRX |
457 | 1b9eb036 | j_mayer | " 0x" ADDRX " %d %d %d 0x" ADDRX "\n", |
458 | 1b9eb036 | j_mayer | base + (i * 8), pte0, pte1,
|
459 | 76a66253 | j_mayer | pte0 >> 31, h, (pte0 >> 6) & 1, ctx->ptem); |
460 | 76a66253 | j_mayer | } |
461 | 9a64fbe4 | bellard | #endif
|
462 | 76a66253 | j_mayer | switch (pte_check(ctx, pte0, pte1, h, rw)) {
|
463 | 76a66253 | j_mayer | case -3: |
464 | 76a66253 | j_mayer | /* PTE inconsistency */
|
465 | 76a66253 | j_mayer | return -1; |
466 | 76a66253 | j_mayer | case -2: |
467 | 76a66253 | j_mayer | /* Access violation */
|
468 | 76a66253 | j_mayer | ret = -2;
|
469 | 76a66253 | j_mayer | good = i; |
470 | 76a66253 | j_mayer | break;
|
471 | 76a66253 | j_mayer | case -1: |
472 | 76a66253 | j_mayer | default:
|
473 | 76a66253 | j_mayer | /* No PTE match */
|
474 | 76a66253 | j_mayer | break;
|
475 | 76a66253 | j_mayer | case 0: |
476 | 76a66253 | j_mayer | /* access granted */
|
477 | 76a66253 | j_mayer | /* XXX: we should go on looping to check all PTEs consistency
|
478 | 76a66253 | j_mayer | * but if we can speed-up the whole thing as the
|
479 | 76a66253 | j_mayer | * result would be undefined if PTEs are not consistent.
|
480 | 76a66253 | j_mayer | */
|
481 | 76a66253 | j_mayer | ret = 0;
|
482 | 76a66253 | j_mayer | good = i; |
483 | 76a66253 | j_mayer | goto done;
|
484 | 9a64fbe4 | bellard | } |
485 | 9a64fbe4 | bellard | } |
486 | 9a64fbe4 | bellard | if (good != -1) { |
487 | 76a66253 | j_mayer | done:
|
488 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
489 | 4a057712 | j_mayer | if (loglevel != 0) { |
490 | 4a057712 | j_mayer | fprintf(logfile, "found PTE at addr 0x" PADDRX " prot=0x%01x " |
491 | 1b9eb036 | j_mayer | "ret=%d\n",
|
492 | 76a66253 | j_mayer | ctx->raddr, ctx->prot, ret); |
493 | 76a66253 | j_mayer | } |
494 | 9a64fbe4 | bellard | #endif
|
495 | 9a64fbe4 | bellard | /* Update page flags */
|
496 | 76a66253 | j_mayer | pte1 = ctx->raddr; |
497 | 76a66253 | j_mayer | if (pte_update_flags(ctx, &pte1, ret, rw) == 1) |
498 | 76a66253 | j_mayer | stl_phys_notdirty(base + (good * 8) + 4, pte1); |
499 | 9a64fbe4 | bellard | } |
500 | 9a64fbe4 | bellard | |
501 | 9a64fbe4 | bellard | return ret;
|
502 | 79aceca5 | bellard | } |
503 | 79aceca5 | bellard | |
504 | 76a66253 | j_mayer | static inline target_phys_addr_t get_pgaddr (target_phys_addr_t sdr1, |
505 | 76a66253 | j_mayer | target_phys_addr_t hash, |
506 | 76a66253 | j_mayer | target_phys_addr_t mask) |
507 | 79aceca5 | bellard | { |
508 | 9a64fbe4 | bellard | return (sdr1 & 0xFFFF0000) | (hash & mask); |
509 | 79aceca5 | bellard | } |
510 | 79aceca5 | bellard | |
511 | 9a64fbe4 | bellard | /* Perform segment based translation */
|
512 | 76a66253 | j_mayer | static int get_segment (CPUState *env, mmu_ctx_t *ctx, |
513 | 76a66253 | j_mayer | target_ulong eaddr, int rw, int type) |
514 | 79aceca5 | bellard | { |
515 | 76a66253 | j_mayer | target_phys_addr_t sdr, hash, mask; |
516 | 76a66253 | j_mayer | target_ulong sr, vsid, pgidx; |
517 | 9a64fbe4 | bellard | int ret = -1, ret2; |
518 | 79aceca5 | bellard | |
519 | 76a66253 | j_mayer | sr = env->sr[eaddr >> 28];
|
520 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
521 | a541f297 | bellard | if (loglevel > 0) { |
522 | 1b9eb036 | j_mayer | fprintf(logfile, "Check segment v=0x" ADDRX " %d 0x" ADDRX " nip=0x" |
523 | 1b9eb036 | j_mayer | ADDRX " lr=0x" ADDRX " ir=%d dr=%d pr=%d %d t=%d\n", |
524 | 76a66253 | j_mayer | eaddr, eaddr >> 28, sr, env->nip,
|
525 | 76a66253 | j_mayer | env->lr, msr_ir, msr_dr, msr_pr, rw, type); |
526 | a541f297 | bellard | } |
527 | 9a64fbe4 | bellard | #endif
|
528 | 76a66253 | j_mayer | ctx->key = (((sr & 0x20000000) && msr_pr == 1) || |
529 | 76a66253 | j_mayer | ((sr & 0x40000000) && msr_pr == 0)) ? 1 : 0; |
530 | 9a64fbe4 | bellard | if ((sr & 0x80000000) == 0) { |
531 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
532 | 5fafdf24 | ths | if (loglevel > 0) |
533 | 1b9eb036 | j_mayer | fprintf(logfile, "pte segment: key=%d n=0x" ADDRX "\n", |
534 | 76a66253 | j_mayer | ctx->key, sr & 0x10000000);
|
535 | 9a64fbe4 | bellard | #endif
|
536 | 9a64fbe4 | bellard | /* Check if instruction fetch is allowed, if needed */
|
537 | 9a64fbe4 | bellard | if (type != ACCESS_CODE || (sr & 0x10000000) == 0) { |
538 | 9a64fbe4 | bellard | /* Page address translation */
|
539 | 76a66253 | j_mayer | pgidx = (eaddr >> TARGET_PAGE_BITS) & 0xFFFF;
|
540 | 9a64fbe4 | bellard | vsid = sr & 0x00FFFFFF;
|
541 | a541f297 | bellard | hash = ((vsid ^ pgidx) & 0x0007FFFF) << 6; |
542 | 76a66253 | j_mayer | /* Primary table address */
|
543 | 76a66253 | j_mayer | sdr = env->sdr1; |
544 | 9a64fbe4 | bellard | mask = ((sdr & 0x000001FF) << 16) | 0xFFC0; |
545 | 76a66253 | j_mayer | ctx->pg_addr[0] = get_pgaddr(sdr, hash, mask);
|
546 | 76a66253 | j_mayer | /* Secondary table address */
|
547 | 76a66253 | j_mayer | hash = (~hash) & 0x01FFFFC0;
|
548 | 76a66253 | j_mayer | ctx->pg_addr[1] = get_pgaddr(sdr, hash, mask);
|
549 | 76a66253 | j_mayer | ctx->ptem = (vsid << 7) | (pgidx >> 10); |
550 | 76a66253 | j_mayer | /* Initialize real address with an invalid value */
|
551 | 76a66253 | j_mayer | ctx->raddr = (target_ulong)-1;
|
552 | 76a66253 | j_mayer | if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
|
553 | 76a66253 | j_mayer | /* Software TLB search */
|
554 | 76a66253 | j_mayer | ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type); |
555 | 76a66253 | j_mayer | } else {
|
556 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
557 | 4a057712 | j_mayer | if (loglevel != 0) { |
558 | 4a057712 | j_mayer | fprintf(logfile, "0 sdr1=0x" PADDRX " vsid=0x%06x " |
559 | 4a057712 | j_mayer | "api=0x%04x hash=0x%07x pg_addr=0x" PADDRX "\n", |
560 | 4a057712 | j_mayer | sdr, (uint32_t)vsid, (uint32_t)pgidx, |
561 | 4a057712 | j_mayer | (uint32_t)hash, ctx->pg_addr[0]);
|
562 | 76a66253 | j_mayer | } |
563 | 9a64fbe4 | bellard | #endif
|
564 | 76a66253 | j_mayer | /* Primary table lookup */
|
565 | 76a66253 | j_mayer | ret = find_pte(ctx, 0, rw);
|
566 | 76a66253 | j_mayer | if (ret < 0) { |
567 | 76a66253 | j_mayer | /* Secondary table lookup */
|
568 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
569 | 4a057712 | j_mayer | if (eaddr != 0xEFFFFFFF && loglevel != 0) { |
570 | 76a66253 | j_mayer | fprintf(logfile, |
571 | 4a057712 | j_mayer | "1 sdr1=0x" PADDRX " vsid=0x%06x api=0x%04x " |
572 | 4a057712 | j_mayer | "hash=0x%05x pg_addr=0x" PADDRX "\n", |
573 | 4a057712 | j_mayer | sdr, (uint32_t)vsid, (uint32_t)pgidx, |
574 | 4a057712 | j_mayer | (uint32_t)hash, ctx->pg_addr[1]);
|
575 | 76a66253 | j_mayer | } |
576 | 9a64fbe4 | bellard | #endif
|
577 | 76a66253 | j_mayer | ret2 = find_pte(ctx, 1, rw);
|
578 | 76a66253 | j_mayer | if (ret2 != -1) |
579 | 76a66253 | j_mayer | ret = ret2; |
580 | 76a66253 | j_mayer | } |
581 | 9a64fbe4 | bellard | } |
582 | 9a64fbe4 | bellard | } else {
|
583 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
584 | 4a057712 | j_mayer | if (loglevel != 0) |
585 | 76a66253 | j_mayer | fprintf(logfile, "No access allowed\n");
|
586 | 9a64fbe4 | bellard | #endif
|
587 | 76a66253 | j_mayer | ret = -3;
|
588 | 9a64fbe4 | bellard | } |
589 | 9a64fbe4 | bellard | } else {
|
590 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
591 | 4a057712 | j_mayer | if (loglevel != 0) |
592 | 76a66253 | j_mayer | fprintf(logfile, "direct store...\n");
|
593 | 9a64fbe4 | bellard | #endif
|
594 | 9a64fbe4 | bellard | /* Direct-store segment : absolutely *BUGGY* for now */
|
595 | 9a64fbe4 | bellard | switch (type) {
|
596 | 9a64fbe4 | bellard | case ACCESS_INT:
|
597 | 9a64fbe4 | bellard | /* Integer load/store : only access allowed */
|
598 | 9a64fbe4 | bellard | break;
|
599 | 9a64fbe4 | bellard | case ACCESS_CODE:
|
600 | 9a64fbe4 | bellard | /* No code fetch is allowed in direct-store areas */
|
601 | 9a64fbe4 | bellard | return -4; |
602 | 9a64fbe4 | bellard | case ACCESS_FLOAT:
|
603 | 9a64fbe4 | bellard | /* Floating point load/store */
|
604 | 9a64fbe4 | bellard | return -4; |
605 | 9a64fbe4 | bellard | case ACCESS_RES:
|
606 | 9a64fbe4 | bellard | /* lwarx, ldarx or srwcx. */
|
607 | 9a64fbe4 | bellard | return -4; |
608 | 9a64fbe4 | bellard | case ACCESS_CACHE:
|
609 | 9a64fbe4 | bellard | /* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi */
|
610 | 9a64fbe4 | bellard | /* Should make the instruction do no-op.
|
611 | 9a64fbe4 | bellard | * As it already do no-op, it's quite easy :-)
|
612 | 9a64fbe4 | bellard | */
|
613 | 76a66253 | j_mayer | ctx->raddr = eaddr; |
614 | 9a64fbe4 | bellard | return 0; |
615 | 9a64fbe4 | bellard | case ACCESS_EXT:
|
616 | 9a64fbe4 | bellard | /* eciwx or ecowx */
|
617 | 9a64fbe4 | bellard | return -4; |
618 | 9a64fbe4 | bellard | default:
|
619 | 9a64fbe4 | bellard | if (logfile) {
|
620 | 9a64fbe4 | bellard | fprintf(logfile, "ERROR: instruction should not need "
|
621 | 9a64fbe4 | bellard | "address translation\n");
|
622 | 9a64fbe4 | bellard | } |
623 | 9a64fbe4 | bellard | return -4; |
624 | 9a64fbe4 | bellard | } |
625 | 76a66253 | j_mayer | if ((rw == 1 || ctx->key != 1) && (rw == 0 || ctx->key != 0)) { |
626 | 76a66253 | j_mayer | ctx->raddr = eaddr; |
627 | 9a64fbe4 | bellard | ret = 2;
|
628 | 9a64fbe4 | bellard | } else {
|
629 | 9a64fbe4 | bellard | ret = -2;
|
630 | 9a64fbe4 | bellard | } |
631 | 79aceca5 | bellard | } |
632 | 9a64fbe4 | bellard | |
633 | 9a64fbe4 | bellard | return ret;
|
634 | 79aceca5 | bellard | } |
635 | 79aceca5 | bellard | |
636 | c294fc58 | j_mayer | /* Generic TLB check function for embedded PowerPC implementations */
|
637 | c294fc58 | j_mayer | static int ppcemb_tlb_check (CPUState *env, ppcemb_tlb_t *tlb, |
638 | c294fc58 | j_mayer | target_phys_addr_t *raddrp, |
639 | 36081602 | j_mayer | target_ulong address, |
640 | 36081602 | j_mayer | uint32_t pid, int ext, int i) |
641 | c294fc58 | j_mayer | { |
642 | c294fc58 | j_mayer | target_ulong mask; |
643 | c294fc58 | j_mayer | |
644 | c294fc58 | j_mayer | /* Check valid flag */
|
645 | c294fc58 | j_mayer | if (!(tlb->prot & PAGE_VALID)) {
|
646 | c294fc58 | j_mayer | if (loglevel != 0) |
647 | c294fc58 | j_mayer | fprintf(logfile, "%s: TLB %d not valid\n", __func__, i);
|
648 | c294fc58 | j_mayer | return -1; |
649 | c294fc58 | j_mayer | } |
650 | c294fc58 | j_mayer | mask = ~(tlb->size - 1);
|
651 | c294fc58 | j_mayer | if (loglevel != 0) { |
652 | c294fc58 | j_mayer | fprintf(logfile, "%s: TLB %d address " ADDRX " PID %d <=> " |
653 | c294fc58 | j_mayer | ADDRX " " ADDRX " %d\n", |
654 | 36081602 | j_mayer | __func__, i, address, pid, tlb->EPN, mask, (int)tlb->PID);
|
655 | c294fc58 | j_mayer | } |
656 | c294fc58 | j_mayer | /* Check PID */
|
657 | 36081602 | j_mayer | if (tlb->PID != 0 && tlb->PID != pid) |
658 | c294fc58 | j_mayer | return -1; |
659 | c294fc58 | j_mayer | /* Check effective address */
|
660 | c294fc58 | j_mayer | if ((address & mask) != tlb->EPN)
|
661 | c294fc58 | j_mayer | return -1; |
662 | c294fc58 | j_mayer | *raddrp = (tlb->RPN & mask) | (address & ~mask); |
663 | 36081602 | j_mayer | if (ext) {
|
664 | 36081602 | j_mayer | /* Extend the physical address to 36 bits */
|
665 | 36081602 | j_mayer | *raddrp |= (target_phys_addr_t)(tlb->RPN & 0xF) << 32; |
666 | 36081602 | j_mayer | } |
667 | c294fc58 | j_mayer | |
668 | c294fc58 | j_mayer | return 0; |
669 | c294fc58 | j_mayer | } |
670 | c294fc58 | j_mayer | |
671 | c294fc58 | j_mayer | /* Generic TLB search function for PowerPC embedded implementations */
|
672 | 36081602 | j_mayer | int ppcemb_tlb_search (CPUPPCState *env, target_ulong address, uint32_t pid)
|
673 | c294fc58 | j_mayer | { |
674 | c294fc58 | j_mayer | ppcemb_tlb_t *tlb; |
675 | c294fc58 | j_mayer | target_phys_addr_t raddr; |
676 | c294fc58 | j_mayer | int i, ret;
|
677 | c294fc58 | j_mayer | |
678 | c294fc58 | j_mayer | /* Default return value is no match */
|
679 | c294fc58 | j_mayer | ret = -1;
|
680 | c294fc58 | j_mayer | for (i = 0; i < 64; i++) { |
681 | c294fc58 | j_mayer | tlb = &env->tlb[i].tlbe; |
682 | 36081602 | j_mayer | if (ppcemb_tlb_check(env, tlb, &raddr, address, pid, 0, i) == 0) { |
683 | c294fc58 | j_mayer | ret = i; |
684 | c294fc58 | j_mayer | break;
|
685 | c294fc58 | j_mayer | } |
686 | c294fc58 | j_mayer | } |
687 | c294fc58 | j_mayer | |
688 | c294fc58 | j_mayer | return ret;
|
689 | c294fc58 | j_mayer | } |
690 | c294fc58 | j_mayer | |
691 | c294fc58 | j_mayer | /* Helpers specific to PowerPC 40x implementations */
|
692 | 0a032cbe | j_mayer | void ppc4xx_tlb_invalidate_all (CPUState *env)
|
693 | 0a032cbe | j_mayer | { |
694 | 0a032cbe | j_mayer | ppcemb_tlb_t *tlb; |
695 | 0a032cbe | j_mayer | int i;
|
696 | 0a032cbe | j_mayer | |
697 | 0a032cbe | j_mayer | for (i = 0; i < env->nb_tlb; i++) { |
698 | 0a032cbe | j_mayer | tlb = &env->tlb[i].tlbe; |
699 | 0a032cbe | j_mayer | if (tlb->prot & PAGE_VALID) {
|
700 | 0a032cbe | j_mayer | #if 0 // XXX: TLB have variable sizes then we flush all Qemu TLB.
|
701 | 0a032cbe | j_mayer | end = tlb->EPN + tlb->size;
|
702 | 0a032cbe | j_mayer | for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
|
703 | 0a032cbe | j_mayer | tlb_flush_page(env, page);
|
704 | 0a032cbe | j_mayer | #endif
|
705 | 0a032cbe | j_mayer | tlb->prot &= ~PAGE_VALID; |
706 | 0a032cbe | j_mayer | } |
707 | 0a032cbe | j_mayer | } |
708 | 0a032cbe | j_mayer | tlb_flush(env, 1);
|
709 | 0a032cbe | j_mayer | } |
710 | 0a032cbe | j_mayer | |
711 | 36081602 | j_mayer | int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
|
712 | e96efcfc | j_mayer | target_ulong address, int rw, int access_type) |
713 | a8dea12f | j_mayer | { |
714 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
715 | a8dea12f | j_mayer | target_phys_addr_t raddr; |
716 | a8dea12f | j_mayer | int i, ret, zsel, zpr;
|
717 | 3b46e624 | ths | |
718 | c55e9aef | j_mayer | ret = -1;
|
719 | c55e9aef | j_mayer | raddr = -1;
|
720 | a8dea12f | j_mayer | for (i = 0; i < env->nb_tlb; i++) { |
721 | a8dea12f | j_mayer | tlb = &env->tlb[i].tlbe; |
722 | 36081602 | j_mayer | if (ppcemb_tlb_check(env, tlb, &raddr, address,
|
723 | 36081602 | j_mayer | env->spr[SPR_40x_PID], 0, i) < 0) |
724 | a8dea12f | j_mayer | continue;
|
725 | a8dea12f | j_mayer | zsel = (tlb->attr >> 4) & 0xF; |
726 | a8dea12f | j_mayer | zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3; |
727 | 4a057712 | j_mayer | if (loglevel != 0) { |
728 | a8dea12f | j_mayer | fprintf(logfile, "%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",
|
729 | a8dea12f | j_mayer | __func__, i, zsel, zpr, rw, tlb->attr); |
730 | a8dea12f | j_mayer | } |
731 | a8dea12f | j_mayer | if (access_type == ACCESS_CODE) {
|
732 | a8dea12f | j_mayer | /* Check execute enable bit */
|
733 | a8dea12f | j_mayer | switch (zpr) {
|
734 | c294fc58 | j_mayer | case 0x2: |
735 | c294fc58 | j_mayer | if (msr_pr)
|
736 | c294fc58 | j_mayer | goto check_exec_perm;
|
737 | c294fc58 | j_mayer | goto exec_granted;
|
738 | a8dea12f | j_mayer | case 0x0: |
739 | a8dea12f | j_mayer | if (msr_pr) {
|
740 | a8dea12f | j_mayer | ctx->prot = 0;
|
741 | c55e9aef | j_mayer | ret = -3;
|
742 | a8dea12f | j_mayer | break;
|
743 | a8dea12f | j_mayer | } |
744 | a8dea12f | j_mayer | /* No break here */
|
745 | a8dea12f | j_mayer | case 0x1: |
746 | c294fc58 | j_mayer | check_exec_perm:
|
747 | a8dea12f | j_mayer | /* Check from TLB entry */
|
748 | a8dea12f | j_mayer | if (!(tlb->prot & PAGE_EXEC)) {
|
749 | a8dea12f | j_mayer | ret = -3;
|
750 | a8dea12f | j_mayer | } else {
|
751 | c55e9aef | j_mayer | if (tlb->prot & PAGE_WRITE) {
|
752 | a8dea12f | j_mayer | ctx->prot = PAGE_READ | PAGE_WRITE; |
753 | c55e9aef | j_mayer | } else {
|
754 | a8dea12f | j_mayer | ctx->prot = PAGE_READ; |
755 | c55e9aef | j_mayer | } |
756 | a8dea12f | j_mayer | ret = 0;
|
757 | a8dea12f | j_mayer | } |
758 | a8dea12f | j_mayer | break;
|
759 | a8dea12f | j_mayer | case 0x3: |
760 | c294fc58 | j_mayer | exec_granted:
|
761 | a8dea12f | j_mayer | /* All accesses granted */
|
762 | a8dea12f | j_mayer | ctx->prot = PAGE_READ | PAGE_WRITE; |
763 | c55e9aef | j_mayer | ret = 0;
|
764 | a8dea12f | j_mayer | break;
|
765 | a8dea12f | j_mayer | } |
766 | a8dea12f | j_mayer | } else {
|
767 | a8dea12f | j_mayer | switch (zpr) {
|
768 | c294fc58 | j_mayer | case 0x2: |
769 | c294fc58 | j_mayer | if (msr_pr)
|
770 | c294fc58 | j_mayer | goto check_rw_perm;
|
771 | c294fc58 | j_mayer | goto rw_granted;
|
772 | a8dea12f | j_mayer | case 0x0: |
773 | a8dea12f | j_mayer | if (msr_pr) {
|
774 | a8dea12f | j_mayer | ctx->prot = 0;
|
775 | c55e9aef | j_mayer | ret = -2;
|
776 | a8dea12f | j_mayer | break;
|
777 | a8dea12f | j_mayer | } |
778 | a8dea12f | j_mayer | /* No break here */
|
779 | a8dea12f | j_mayer | case 0x1: |
780 | c294fc58 | j_mayer | check_rw_perm:
|
781 | a8dea12f | j_mayer | /* Check from TLB entry */
|
782 | a8dea12f | j_mayer | /* Check write protection bit */
|
783 | c55e9aef | j_mayer | if (tlb->prot & PAGE_WRITE) {
|
784 | c55e9aef | j_mayer | ctx->prot = PAGE_READ | PAGE_WRITE; |
785 | c55e9aef | j_mayer | ret = 0;
|
786 | a8dea12f | j_mayer | } else {
|
787 | c55e9aef | j_mayer | ctx->prot = PAGE_READ; |
788 | c55e9aef | j_mayer | if (rw)
|
789 | c55e9aef | j_mayer | ret = -2;
|
790 | a8dea12f | j_mayer | else
|
791 | c55e9aef | j_mayer | ret = 0;
|
792 | a8dea12f | j_mayer | } |
793 | a8dea12f | j_mayer | break;
|
794 | a8dea12f | j_mayer | case 0x3: |
795 | c294fc58 | j_mayer | rw_granted:
|
796 | a8dea12f | j_mayer | /* All accesses granted */
|
797 | a8dea12f | j_mayer | ctx->prot = PAGE_READ | PAGE_WRITE; |
798 | c55e9aef | j_mayer | ret = 0;
|
799 | a8dea12f | j_mayer | break;
|
800 | a8dea12f | j_mayer | } |
801 | a8dea12f | j_mayer | } |
802 | a8dea12f | j_mayer | if (ret >= 0) { |
803 | a8dea12f | j_mayer | ctx->raddr = raddr; |
804 | 4a057712 | j_mayer | if (loglevel != 0) { |
805 | a8dea12f | j_mayer | fprintf(logfile, "%s: access granted " ADDRX " => " REGX |
806 | c55e9aef | j_mayer | " %d %d\n", __func__, address, ctx->raddr, ctx->prot,
|
807 | c55e9aef | j_mayer | ret); |
808 | a8dea12f | j_mayer | } |
809 | c55e9aef | j_mayer | return 0; |
810 | a8dea12f | j_mayer | } |
811 | a8dea12f | j_mayer | } |
812 | 4a057712 | j_mayer | if (loglevel != 0) { |
813 | c55e9aef | j_mayer | fprintf(logfile, "%s: access refused " ADDRX " => " REGX |
814 | c55e9aef | j_mayer | " %d %d\n", __func__, address, raddr, ctx->prot,
|
815 | c55e9aef | j_mayer | ret); |
816 | c55e9aef | j_mayer | } |
817 | 3b46e624 | ths | |
818 | a8dea12f | j_mayer | return ret;
|
819 | a8dea12f | j_mayer | } |
820 | a8dea12f | j_mayer | |
821 | c294fc58 | j_mayer | void store_40x_sler (CPUPPCState *env, uint32_t val)
|
822 | c294fc58 | j_mayer | { |
823 | c294fc58 | j_mayer | /* XXX: TO BE FIXED */
|
824 | c294fc58 | j_mayer | if (val != 0x00000000) { |
825 | c294fc58 | j_mayer | cpu_abort(env, "Little-endian regions are not supported by now\n");
|
826 | c294fc58 | j_mayer | } |
827 | c294fc58 | j_mayer | env->spr[SPR_405_SLER] = val; |
828 | c294fc58 | j_mayer | } |
829 | c294fc58 | j_mayer | |
830 | 76a66253 | j_mayer | static int check_physical (CPUState *env, mmu_ctx_t *ctx, |
831 | 76a66253 | j_mayer | target_ulong eaddr, int rw)
|
832 | 76a66253 | j_mayer | { |
833 | 76a66253 | j_mayer | int in_plb, ret;
|
834 | 3b46e624 | ths | |
835 | 76a66253 | j_mayer | ctx->raddr = eaddr; |
836 | 76a66253 | j_mayer | ctx->prot = PAGE_READ; |
837 | 76a66253 | j_mayer | ret = 0;
|
838 | 76a66253 | j_mayer | if (unlikely(msr_pe != 0 && PPC_MMU(env) == PPC_FLAGS_MMU_403)) { |
839 | 76a66253 | j_mayer | /* 403 family add some particular protections,
|
840 | 76a66253 | j_mayer | * using PBL/PBU registers for accesses with no translation.
|
841 | 76a66253 | j_mayer | */
|
842 | 76a66253 | j_mayer | in_plb = |
843 | 76a66253 | j_mayer | /* Check PLB validity */
|
844 | 76a66253 | j_mayer | (env->pb[0] < env->pb[1] && |
845 | 76a66253 | j_mayer | /* and address in plb area */
|
846 | 76a66253 | j_mayer | eaddr >= env->pb[0] && eaddr < env->pb[1]) || |
847 | 76a66253 | j_mayer | (env->pb[2] < env->pb[3] && |
848 | 76a66253 | j_mayer | eaddr >= env->pb[2] && eaddr < env->pb[3]) ? 1 : 0; |
849 | 76a66253 | j_mayer | if (in_plb ^ msr_px) {
|
850 | 76a66253 | j_mayer | /* Access in protected area */
|
851 | 76a66253 | j_mayer | if (rw == 1) { |
852 | 76a66253 | j_mayer | /* Access is not allowed */
|
853 | 76a66253 | j_mayer | ret = -2;
|
854 | 76a66253 | j_mayer | } |
855 | 76a66253 | j_mayer | } else {
|
856 | 76a66253 | j_mayer | /* Read-write access is allowed */
|
857 | 76a66253 | j_mayer | ctx->prot |= PAGE_WRITE; |
858 | 76a66253 | j_mayer | } |
859 | 76a66253 | j_mayer | } else {
|
860 | 76a66253 | j_mayer | ctx->prot |= PAGE_WRITE; |
861 | 76a66253 | j_mayer | } |
862 | 76a66253 | j_mayer | |
863 | 76a66253 | j_mayer | return ret;
|
864 | 76a66253 | j_mayer | } |
865 | 76a66253 | j_mayer | |
866 | 76a66253 | j_mayer | int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr,
|
867 | 76a66253 | j_mayer | int rw, int access_type, int check_BATs) |
868 | 9a64fbe4 | bellard | { |
869 | 9a64fbe4 | bellard | int ret;
|
870 | 514fb8c1 | bellard | #if 0
|
871 | 4a057712 | j_mayer | if (loglevel != 0) {
|
872 | 9a64fbe4 | bellard | fprintf(logfile, "%s\n", __func__);
|
873 | 9a64fbe4 | bellard | }
|
874 | d9bce9d9 | j_mayer | #endif
|
875 | 4b3686fa | bellard | if ((access_type == ACCESS_CODE && msr_ir == 0) || |
876 | 4b3686fa | bellard | (access_type != ACCESS_CODE && msr_dr == 0)) {
|
877 | 9a64fbe4 | bellard | /* No address translation */
|
878 | 76a66253 | j_mayer | ret = check_physical(env, ctx, eaddr, rw); |
879 | 9a64fbe4 | bellard | } else {
|
880 | c55e9aef | j_mayer | ret = -1;
|
881 | a8dea12f | j_mayer | switch (PPC_MMU(env)) {
|
882 | a8dea12f | j_mayer | case PPC_FLAGS_MMU_32B:
|
883 | a8dea12f | j_mayer | case PPC_FLAGS_MMU_SOFT_6xx:
|
884 | a8dea12f | j_mayer | /* Try to find a BAT */
|
885 | a8dea12f | j_mayer | if (check_BATs)
|
886 | a8dea12f | j_mayer | ret = get_bat(env, ctx, eaddr, rw, access_type); |
887 | c55e9aef | j_mayer | /* No break here */
|
888 | c55e9aef | j_mayer | #if defined(TARGET_PPC64)
|
889 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_64B:
|
890 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_64BRIDGE:
|
891 | c55e9aef | j_mayer | #endif
|
892 | a8dea12f | j_mayer | if (ret < 0) { |
893 | c55e9aef | j_mayer | /* We didn't match any BAT entry or don't have BATs */
|
894 | a8dea12f | j_mayer | ret = get_segment(env, ctx, eaddr, rw, access_type); |
895 | a8dea12f | j_mayer | } |
896 | a8dea12f | j_mayer | break;
|
897 | a8dea12f | j_mayer | case PPC_FLAGS_MMU_SOFT_4xx:
|
898 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_403:
|
899 | 36081602 | j_mayer | ret = mmu40x_get_physical_address(env, ctx, eaddr, |
900 | a8dea12f | j_mayer | rw, access_type); |
901 | a8dea12f | j_mayer | break;
|
902 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_601:
|
903 | c55e9aef | j_mayer | /* XXX: TODO */
|
904 | c55e9aef | j_mayer | cpu_abort(env, "601 MMU model not implemented\n");
|
905 | c55e9aef | j_mayer | return -1; |
906 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_BOOKE:
|
907 | a8dea12f | j_mayer | /* XXX: TODO */
|
908 | c55e9aef | j_mayer | cpu_abort(env, "BookeE MMU model not implemented\n");
|
909 | c55e9aef | j_mayer | return -1; |
910 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_BOOKE_FSL:
|
911 | c55e9aef | j_mayer | /* XXX: TODO */
|
912 | c55e9aef | j_mayer | cpu_abort(env, "BookE FSL MMU model not implemented\n");
|
913 | c55e9aef | j_mayer | return -1; |
914 | c55e9aef | j_mayer | default:
|
915 | c55e9aef | j_mayer | cpu_abort(env, "Unknown or invalid MMU model\n");
|
916 | a8dea12f | j_mayer | return -1; |
917 | 9a64fbe4 | bellard | } |
918 | 9a64fbe4 | bellard | } |
919 | 514fb8c1 | bellard | #if 0
|
920 | 4a057712 | j_mayer | if (loglevel != 0) {
|
921 | 4a057712 | j_mayer | fprintf(logfile, "%s address " ADDRX " => %d " PADDRX "\n",
|
922 | c55e9aef | j_mayer | __func__, eaddr, ret, ctx->raddr);
|
923 | a541f297 | bellard | }
|
924 | 76a66253 | j_mayer | #endif
|
925 | d9bce9d9 | j_mayer | |
926 | 9a64fbe4 | bellard | return ret;
|
927 | 9a64fbe4 | bellard | } |
928 | 9a64fbe4 | bellard | |
929 | 9b3c35e0 | j_mayer | target_phys_addr_t cpu_get_phys_page_debug (CPUState *env, target_ulong addr) |
930 | a6b025d3 | bellard | { |
931 | 76a66253 | j_mayer | mmu_ctx_t ctx; |
932 | a6b025d3 | bellard | |
933 | 76a66253 | j_mayer | if (unlikely(get_physical_address(env, &ctx, addr, 0, ACCESS_INT, 1) != 0)) |
934 | a6b025d3 | bellard | return -1; |
935 | 76a66253 | j_mayer | |
936 | 76a66253 | j_mayer | return ctx.raddr & TARGET_PAGE_MASK;
|
937 | a6b025d3 | bellard | } |
938 | 9a64fbe4 | bellard | |
939 | 9a64fbe4 | bellard | /* Perform address translation */
|
940 | e96efcfc | j_mayer | int cpu_ppc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, |
941 | a541f297 | bellard | int is_user, int is_softmmu) |
942 | 9a64fbe4 | bellard | { |
943 | 76a66253 | j_mayer | mmu_ctx_t ctx; |
944 | 9a64fbe4 | bellard | int exception = 0, error_code = 0; |
945 | a541f297 | bellard | int access_type;
|
946 | 9a64fbe4 | bellard | int ret = 0; |
947 | d9bce9d9 | j_mayer | |
948 | b769d8fe | bellard | if (rw == 2) { |
949 | b769d8fe | bellard | /* code access */
|
950 | b769d8fe | bellard | rw = 0;
|
951 | b769d8fe | bellard | access_type = ACCESS_CODE; |
952 | b769d8fe | bellard | } else {
|
953 | b769d8fe | bellard | /* data access */
|
954 | b769d8fe | bellard | /* XXX: put correct access by using cpu_restore_state()
|
955 | b769d8fe | bellard | correctly */
|
956 | b769d8fe | bellard | access_type = ACCESS_INT; |
957 | b769d8fe | bellard | // access_type = env->access_type;
|
958 | b769d8fe | bellard | } |
959 | 76a66253 | j_mayer | ret = get_physical_address(env, &ctx, address, rw, access_type, 1);
|
960 | 9a64fbe4 | bellard | if (ret == 0) { |
961 | 76a66253 | j_mayer | ret = tlb_set_page(env, address & TARGET_PAGE_MASK, |
962 | 76a66253 | j_mayer | ctx.raddr & TARGET_PAGE_MASK, ctx.prot, |
963 | 76a66253 | j_mayer | is_user, is_softmmu); |
964 | 9a64fbe4 | bellard | } else if (ret < 0) { |
965 | 9a64fbe4 | bellard | #if defined (DEBUG_MMU)
|
966 | 4a057712 | j_mayer | if (loglevel != 0) |
967 | 76a66253 | j_mayer | cpu_dump_state(env, logfile, fprintf, 0);
|
968 | 9a64fbe4 | bellard | #endif
|
969 | 9a64fbe4 | bellard | if (access_type == ACCESS_CODE) {
|
970 | 9a64fbe4 | bellard | exception = EXCP_ISI; |
971 | 9a64fbe4 | bellard | switch (ret) {
|
972 | 9a64fbe4 | bellard | case -1: |
973 | 76a66253 | j_mayer | /* No matches in page tables or TLB */
|
974 | c55e9aef | j_mayer | switch (PPC_MMU(env)) {
|
975 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_SOFT_6xx:
|
976 | 76a66253 | j_mayer | exception = EXCP_I_TLBMISS; |
977 | 76a66253 | j_mayer | env->spr[SPR_IMISS] = address; |
978 | 76a66253 | j_mayer | env->spr[SPR_ICMP] = 0x80000000 | ctx.ptem;
|
979 | 76a66253 | j_mayer | error_code = 1 << 18; |
980 | 76a66253 | j_mayer | goto tlb_miss;
|
981 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_SOFT_4xx:
|
982 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_403:
|
983 | a8dea12f | j_mayer | exception = EXCP_40x_ITLBMISS; |
984 | a8dea12f | j_mayer | error_code = 0;
|
985 | a8dea12f | j_mayer | env->spr[SPR_40x_DEAR] = address; |
986 | a8dea12f | j_mayer | env->spr[SPR_40x_ESR] = 0x00000000;
|
987 | c55e9aef | j_mayer | break;
|
988 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_32B:
|
989 | 76a66253 | j_mayer | error_code = 0x40000000;
|
990 | c55e9aef | j_mayer | break;
|
991 | c55e9aef | j_mayer | #if defined(TARGET_PPC64)
|
992 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_64B:
|
993 | c55e9aef | j_mayer | /* XXX: TODO */
|
994 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
995 | c55e9aef | j_mayer | return -1; |
996 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_64BRIDGE:
|
997 | c55e9aef | j_mayer | /* XXX: TODO */
|
998 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
999 | c55e9aef | j_mayer | return -1; |
1000 | c55e9aef | j_mayer | #endif
|
1001 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_601:
|
1002 | c55e9aef | j_mayer | /* XXX: TODO */
|
1003 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1004 | c55e9aef | j_mayer | return -1; |
1005 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_BOOKE:
|
1006 | c55e9aef | j_mayer | /* XXX: TODO */
|
1007 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1008 | c55e9aef | j_mayer | return -1; |
1009 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_BOOKE_FSL:
|
1010 | c55e9aef | j_mayer | /* XXX: TODO */
|
1011 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1012 | c55e9aef | j_mayer | return -1; |
1013 | c55e9aef | j_mayer | default:
|
1014 | c55e9aef | j_mayer | cpu_abort(env, "Unknown or invalid MMU model\n");
|
1015 | c55e9aef | j_mayer | return -1; |
1016 | 76a66253 | j_mayer | } |
1017 | 9a64fbe4 | bellard | break;
|
1018 | 9a64fbe4 | bellard | case -2: |
1019 | 9a64fbe4 | bellard | /* Access rights violation */
|
1020 | 2be0071f | bellard | error_code = 0x08000000;
|
1021 | 9a64fbe4 | bellard | break;
|
1022 | 9a64fbe4 | bellard | case -3: |
1023 | 76a66253 | j_mayer | /* No execute protection violation */
|
1024 | 2be0071f | bellard | error_code = 0x10000000;
|
1025 | 9a64fbe4 | bellard | break;
|
1026 | 9a64fbe4 | bellard | case -4: |
1027 | 9a64fbe4 | bellard | /* Direct store exception */
|
1028 | 9a64fbe4 | bellard | /* No code fetch is allowed in direct-store areas */
|
1029 | 2be0071f | bellard | error_code = 0x10000000;
|
1030 | 2be0071f | bellard | break;
|
1031 | 2be0071f | bellard | case -5: |
1032 | 2be0071f | bellard | /* No match in segment table */
|
1033 | 2be0071f | bellard | exception = EXCP_ISEG; |
1034 | 2be0071f | bellard | error_code = 0;
|
1035 | 9a64fbe4 | bellard | break;
|
1036 | 9a64fbe4 | bellard | } |
1037 | 9a64fbe4 | bellard | } else {
|
1038 | 9a64fbe4 | bellard | exception = EXCP_DSI; |
1039 | 9a64fbe4 | bellard | switch (ret) {
|
1040 | 9a64fbe4 | bellard | case -1: |
1041 | 76a66253 | j_mayer | /* No matches in page tables or TLB */
|
1042 | c55e9aef | j_mayer | switch (PPC_MMU(env)) {
|
1043 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_SOFT_6xx:
|
1044 | 76a66253 | j_mayer | if (rw == 1) { |
1045 | 76a66253 | j_mayer | exception = EXCP_DS_TLBMISS; |
1046 | 76a66253 | j_mayer | error_code = 1 << 16; |
1047 | 76a66253 | j_mayer | } else {
|
1048 | 76a66253 | j_mayer | exception = EXCP_DL_TLBMISS; |
1049 | 76a66253 | j_mayer | error_code = 0;
|
1050 | 76a66253 | j_mayer | } |
1051 | 76a66253 | j_mayer | env->spr[SPR_DMISS] = address; |
1052 | 76a66253 | j_mayer | env->spr[SPR_DCMP] = 0x80000000 | ctx.ptem;
|
1053 | 76a66253 | j_mayer | tlb_miss:
|
1054 | 76a66253 | j_mayer | error_code |= ctx.key << 19;
|
1055 | 76a66253 | j_mayer | env->spr[SPR_HASH1] = ctx.pg_addr[0];
|
1056 | 76a66253 | j_mayer | env->spr[SPR_HASH2] = ctx.pg_addr[1];
|
1057 | 76a66253 | j_mayer | /* Do not alter DAR nor DSISR */
|
1058 | 76a66253 | j_mayer | goto out;
|
1059 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_SOFT_4xx:
|
1060 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_403:
|
1061 | a8dea12f | j_mayer | exception = EXCP_40x_DTLBMISS; |
1062 | a8dea12f | j_mayer | error_code = 0;
|
1063 | a8dea12f | j_mayer | env->spr[SPR_40x_DEAR] = address; |
1064 | a8dea12f | j_mayer | if (rw)
|
1065 | a8dea12f | j_mayer | env->spr[SPR_40x_ESR] = 0x00800000;
|
1066 | a8dea12f | j_mayer | else
|
1067 | a8dea12f | j_mayer | env->spr[SPR_40x_ESR] = 0x00000000;
|
1068 | c55e9aef | j_mayer | break;
|
1069 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_32B:
|
1070 | 76a66253 | j_mayer | error_code = 0x40000000;
|
1071 | c55e9aef | j_mayer | break;
|
1072 | c55e9aef | j_mayer | #if defined(TARGET_PPC64)
|
1073 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_64B:
|
1074 | c55e9aef | j_mayer | /* XXX: TODO */
|
1075 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1076 | c55e9aef | j_mayer | return -1; |
1077 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_64BRIDGE:
|
1078 | c55e9aef | j_mayer | /* XXX: TODO */
|
1079 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1080 | c55e9aef | j_mayer | return -1; |
1081 | c55e9aef | j_mayer | #endif
|
1082 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_601:
|
1083 | c55e9aef | j_mayer | /* XXX: TODO */
|
1084 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1085 | c55e9aef | j_mayer | return -1; |
1086 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_BOOKE:
|
1087 | c55e9aef | j_mayer | /* XXX: TODO */
|
1088 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1089 | c55e9aef | j_mayer | return -1; |
1090 | c55e9aef | j_mayer | case PPC_FLAGS_MMU_BOOKE_FSL:
|
1091 | c55e9aef | j_mayer | /* XXX: TODO */
|
1092 | c55e9aef | j_mayer | cpu_abort(env, "MMU model not implemented\n");
|
1093 | c55e9aef | j_mayer | return -1; |
1094 | c55e9aef | j_mayer | default:
|
1095 | c55e9aef | j_mayer | cpu_abort(env, "Unknown or invalid MMU model\n");
|
1096 | c55e9aef | j_mayer | return -1; |
1097 | 76a66253 | j_mayer | } |
1098 | 9a64fbe4 | bellard | break;
|
1099 | 9a64fbe4 | bellard | case -2: |
1100 | 9a64fbe4 | bellard | /* Access rights violation */
|
1101 | 2be0071f | bellard | error_code = 0x08000000;
|
1102 | 9a64fbe4 | bellard | break;
|
1103 | 9a64fbe4 | bellard | case -4: |
1104 | 9a64fbe4 | bellard | /* Direct store exception */
|
1105 | 9a64fbe4 | bellard | switch (access_type) {
|
1106 | 9a64fbe4 | bellard | case ACCESS_FLOAT:
|
1107 | 9a64fbe4 | bellard | /* Floating point load/store */
|
1108 | 9a64fbe4 | bellard | exception = EXCP_ALIGN; |
1109 | 9a64fbe4 | bellard | error_code = EXCP_ALIGN_FP; |
1110 | 9a64fbe4 | bellard | break;
|
1111 | 9a64fbe4 | bellard | case ACCESS_RES:
|
1112 | 9a64fbe4 | bellard | /* lwarx, ldarx or srwcx. */
|
1113 | 2be0071f | bellard | error_code = 0x04000000;
|
1114 | 9a64fbe4 | bellard | break;
|
1115 | 9a64fbe4 | bellard | case ACCESS_EXT:
|
1116 | 9a64fbe4 | bellard | /* eciwx or ecowx */
|
1117 | 2be0071f | bellard | error_code = 0x04100000;
|
1118 | 9a64fbe4 | bellard | break;
|
1119 | 9a64fbe4 | bellard | default:
|
1120 | 76a66253 | j_mayer | printf("DSI: invalid exception (%d)\n", ret);
|
1121 | 9a64fbe4 | bellard | exception = EXCP_PROGRAM; |
1122 | 9a64fbe4 | bellard | error_code = EXCP_INVAL | EXCP_INVAL_INVAL; |
1123 | 9a64fbe4 | bellard | break;
|
1124 | 9a64fbe4 | bellard | } |
1125 | fdabc366 | bellard | break;
|
1126 | 2be0071f | bellard | case -5: |
1127 | 2be0071f | bellard | /* No match in segment table */
|
1128 | 2be0071f | bellard | exception = EXCP_DSEG; |
1129 | 2be0071f | bellard | error_code = 0;
|
1130 | 2be0071f | bellard | break;
|
1131 | 9a64fbe4 | bellard | } |
1132 | fdabc366 | bellard | if (exception == EXCP_DSI && rw == 1) |
1133 | 2be0071f | bellard | error_code |= 0x02000000;
|
1134 | 76a66253 | j_mayer | /* Store fault address */
|
1135 | 76a66253 | j_mayer | env->spr[SPR_DAR] = address; |
1136 | 2be0071f | bellard | env->spr[SPR_DSISR] = error_code; |
1137 | 9a64fbe4 | bellard | } |
1138 | 76a66253 | j_mayer | out:
|
1139 | 9a64fbe4 | bellard | #if 0
|
1140 | 9a64fbe4 | bellard | printf("%s: set exception to %d %02x\n",
|
1141 | 9a64fbe4 | bellard | __func__, exception, error_code);
|
1142 | 9a64fbe4 | bellard | #endif
|
1143 | 9a64fbe4 | bellard | env->exception_index = exception; |
1144 | 9a64fbe4 | bellard | env->error_code = error_code; |
1145 | 9a64fbe4 | bellard | ret = 1;
|
1146 | 9a64fbe4 | bellard | } |
1147 | 76a66253 | j_mayer | |
1148 | 9a64fbe4 | bellard | return ret;
|
1149 | 9a64fbe4 | bellard | } |
1150 | 9a64fbe4 | bellard | |
1151 | 3fc6c082 | bellard | /*****************************************************************************/
|
1152 | 3fc6c082 | bellard | /* BATs management */
|
1153 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1154 | 3fc6c082 | bellard | static inline void do_invalidate_BAT (CPUPPCState *env, |
1155 | 3fc6c082 | bellard | target_ulong BATu, target_ulong mask) |
1156 | 3fc6c082 | bellard | { |
1157 | 3fc6c082 | bellard | target_ulong base, end, page; |
1158 | 76a66253 | j_mayer | |
1159 | 3fc6c082 | bellard | base = BATu & ~0x0001FFFF;
|
1160 | 3fc6c082 | bellard | end = base + mask + 0x00020000;
|
1161 | 3fc6c082 | bellard | #if defined (DEBUG_BATS)
|
1162 | 76a66253 | j_mayer | if (loglevel != 0) { |
1163 | 1b9eb036 | j_mayer | fprintf(logfile, "Flush BAT from " ADDRX " to " ADDRX " (" ADDRX ")\n", |
1164 | 76a66253 | j_mayer | base, end, mask); |
1165 | 76a66253 | j_mayer | } |
1166 | 3fc6c082 | bellard | #endif
|
1167 | 3fc6c082 | bellard | for (page = base; page != end; page += TARGET_PAGE_SIZE)
|
1168 | 3fc6c082 | bellard | tlb_flush_page(env, page); |
1169 | 3fc6c082 | bellard | #if defined (DEBUG_BATS)
|
1170 | 3fc6c082 | bellard | if (loglevel != 0) |
1171 | 3fc6c082 | bellard | fprintf(logfile, "Flush done\n");
|
1172 | 3fc6c082 | bellard | #endif
|
1173 | 3fc6c082 | bellard | } |
1174 | 3fc6c082 | bellard | #endif
|
1175 | 3fc6c082 | bellard | |
1176 | 3fc6c082 | bellard | static inline void dump_store_bat (CPUPPCState *env, char ID, int ul, int nr, |
1177 | 3fc6c082 | bellard | target_ulong value) |
1178 | 3fc6c082 | bellard | { |
1179 | 3fc6c082 | bellard | #if defined (DEBUG_BATS)
|
1180 | 3fc6c082 | bellard | if (loglevel != 0) { |
1181 | 1b9eb036 | j_mayer | fprintf(logfile, "Set %cBAT%d%c to 0x" ADDRX " (0x" ADDRX ")\n", |
1182 | 1b9eb036 | j_mayer | ID, nr, ul == 0 ? 'u' : 'l', value, env->nip); |
1183 | 3fc6c082 | bellard | } |
1184 | 3fc6c082 | bellard | #endif
|
1185 | 3fc6c082 | bellard | } |
1186 | 3fc6c082 | bellard | |
1187 | 3fc6c082 | bellard | target_ulong do_load_ibatu (CPUPPCState *env, int nr)
|
1188 | 3fc6c082 | bellard | { |
1189 | 3fc6c082 | bellard | return env->IBAT[0][nr]; |
1190 | 3fc6c082 | bellard | } |
1191 | 3fc6c082 | bellard | |
1192 | 3fc6c082 | bellard | target_ulong do_load_ibatl (CPUPPCState *env, int nr)
|
1193 | 3fc6c082 | bellard | { |
1194 | 3fc6c082 | bellard | return env->IBAT[1][nr]; |
1195 | 3fc6c082 | bellard | } |
1196 | 3fc6c082 | bellard | |
1197 | 3fc6c082 | bellard | void do_store_ibatu (CPUPPCState *env, int nr, target_ulong value) |
1198 | 3fc6c082 | bellard | { |
1199 | 3fc6c082 | bellard | target_ulong mask; |
1200 | 3fc6c082 | bellard | |
1201 | 3fc6c082 | bellard | dump_store_bat(env, 'I', 0, nr, value); |
1202 | 3fc6c082 | bellard | if (env->IBAT[0][nr] != value) { |
1203 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1204 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1205 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1206 | 3fc6c082 | bellard | #endif
|
1207 | 3fc6c082 | bellard | /* When storing valid upper BAT, mask BEPI and BRPN
|
1208 | 3fc6c082 | bellard | * and invalidate all TLBs covered by this BAT
|
1209 | 3fc6c082 | bellard | */
|
1210 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1211 | 3fc6c082 | bellard | env->IBAT[0][nr] = (value & 0x00001FFFUL) | |
1212 | 3fc6c082 | bellard | (value & ~0x0001FFFFUL & ~mask);
|
1213 | 3fc6c082 | bellard | env->IBAT[1][nr] = (env->IBAT[1][nr] & 0x0000007B) | |
1214 | 3fc6c082 | bellard | (env->IBAT[1][nr] & ~0x0001FFFF & ~mask); |
1215 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1216 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->IBAT[0][nr], mask);
|
1217 | 76a66253 | j_mayer | #else
|
1218 | 3fc6c082 | bellard | tlb_flush(env, 1);
|
1219 | 3fc6c082 | bellard | #endif
|
1220 | 3fc6c082 | bellard | } |
1221 | 3fc6c082 | bellard | } |
1222 | 3fc6c082 | bellard | |
1223 | 3fc6c082 | bellard | void do_store_ibatl (CPUPPCState *env, int nr, target_ulong value) |
1224 | 3fc6c082 | bellard | { |
1225 | 3fc6c082 | bellard | dump_store_bat(env, 'I', 1, nr, value); |
1226 | 3fc6c082 | bellard | env->IBAT[1][nr] = value;
|
1227 | 3fc6c082 | bellard | } |
1228 | 3fc6c082 | bellard | |
1229 | 3fc6c082 | bellard | target_ulong do_load_dbatu (CPUPPCState *env, int nr)
|
1230 | 3fc6c082 | bellard | { |
1231 | 3fc6c082 | bellard | return env->DBAT[0][nr]; |
1232 | 3fc6c082 | bellard | } |
1233 | 3fc6c082 | bellard | |
1234 | 3fc6c082 | bellard | target_ulong do_load_dbatl (CPUPPCState *env, int nr)
|
1235 | 3fc6c082 | bellard | { |
1236 | 3fc6c082 | bellard | return env->DBAT[1][nr]; |
1237 | 3fc6c082 | bellard | } |
1238 | 3fc6c082 | bellard | |
1239 | 3fc6c082 | bellard | void do_store_dbatu (CPUPPCState *env, int nr, target_ulong value) |
1240 | 3fc6c082 | bellard | { |
1241 | 3fc6c082 | bellard | target_ulong mask; |
1242 | 3fc6c082 | bellard | |
1243 | 3fc6c082 | bellard | dump_store_bat(env, 'D', 0, nr, value); |
1244 | 3fc6c082 | bellard | if (env->DBAT[0][nr] != value) { |
1245 | 3fc6c082 | bellard | /* When storing valid upper BAT, mask BEPI and BRPN
|
1246 | 3fc6c082 | bellard | * and invalidate all TLBs covered by this BAT
|
1247 | 3fc6c082 | bellard | */
|
1248 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1249 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1250 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->DBAT[0][nr], mask);
|
1251 | 3fc6c082 | bellard | #endif
|
1252 | 3fc6c082 | bellard | mask = (value << 15) & 0x0FFE0000UL; |
1253 | 3fc6c082 | bellard | env->DBAT[0][nr] = (value & 0x00001FFFUL) | |
1254 | 3fc6c082 | bellard | (value & ~0x0001FFFFUL & ~mask);
|
1255 | 3fc6c082 | bellard | env->DBAT[1][nr] = (env->DBAT[1][nr] & 0x0000007B) | |
1256 | 3fc6c082 | bellard | (env->DBAT[1][nr] & ~0x0001FFFF & ~mask); |
1257 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS)
|
1258 | 3fc6c082 | bellard | do_invalidate_BAT(env, env->DBAT[0][nr], mask);
|
1259 | 3fc6c082 | bellard | #else
|
1260 | 3fc6c082 | bellard | tlb_flush(env, 1);
|
1261 | 3fc6c082 | bellard | #endif
|
1262 | 3fc6c082 | bellard | } |
1263 | 3fc6c082 | bellard | } |
1264 | 3fc6c082 | bellard | |
1265 | 3fc6c082 | bellard | void do_store_dbatl (CPUPPCState *env, int nr, target_ulong value) |
1266 | 3fc6c082 | bellard | { |
1267 | 3fc6c082 | bellard | dump_store_bat(env, 'D', 1, nr, value); |
1268 | 3fc6c082 | bellard | env->DBAT[1][nr] = value;
|
1269 | 3fc6c082 | bellard | } |
1270 | 3fc6c082 | bellard | |
1271 | 0a032cbe | j_mayer | |
1272 | 0a032cbe | j_mayer | /*****************************************************************************/
|
1273 | 0a032cbe | j_mayer | /* TLB management */
|
1274 | 0a032cbe | j_mayer | void ppc_tlb_invalidate_all (CPUPPCState *env)
|
1275 | 0a032cbe | j_mayer | { |
1276 | 0a032cbe | j_mayer | if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
|
1277 | 0a032cbe | j_mayer | ppc6xx_tlb_invalidate_all(env); |
1278 | 0a032cbe | j_mayer | } else if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_4xx)) { |
1279 | 0a032cbe | j_mayer | ppc4xx_tlb_invalidate_all(env); |
1280 | 0a032cbe | j_mayer | } else {
|
1281 | 0a032cbe | j_mayer | tlb_flush(env, 1);
|
1282 | 0a032cbe | j_mayer | } |
1283 | 0a032cbe | j_mayer | } |
1284 | 0a032cbe | j_mayer | |
1285 | 3fc6c082 | bellard | /*****************************************************************************/
|
1286 | 3fc6c082 | bellard | /* Special registers manipulation */
|
1287 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
1288 | d9bce9d9 | j_mayer | target_ulong ppc_load_asr (CPUPPCState *env) |
1289 | d9bce9d9 | j_mayer | { |
1290 | d9bce9d9 | j_mayer | return env->asr;
|
1291 | d9bce9d9 | j_mayer | } |
1292 | d9bce9d9 | j_mayer | |
1293 | d9bce9d9 | j_mayer | void ppc_store_asr (CPUPPCState *env, target_ulong value)
|
1294 | d9bce9d9 | j_mayer | { |
1295 | d9bce9d9 | j_mayer | if (env->asr != value) {
|
1296 | d9bce9d9 | j_mayer | env->asr = value; |
1297 | d9bce9d9 | j_mayer | tlb_flush(env, 1);
|
1298 | d9bce9d9 | j_mayer | } |
1299 | d9bce9d9 | j_mayer | } |
1300 | d9bce9d9 | j_mayer | #endif
|
1301 | d9bce9d9 | j_mayer | |
1302 | 3fc6c082 | bellard | target_ulong do_load_sdr1 (CPUPPCState *env) |
1303 | 3fc6c082 | bellard | { |
1304 | 3fc6c082 | bellard | return env->sdr1;
|
1305 | 3fc6c082 | bellard | } |
1306 | 3fc6c082 | bellard | |
1307 | 3fc6c082 | bellard | void do_store_sdr1 (CPUPPCState *env, target_ulong value)
|
1308 | 3fc6c082 | bellard | { |
1309 | 3fc6c082 | bellard | #if defined (DEBUG_MMU)
|
1310 | 3fc6c082 | bellard | if (loglevel != 0) { |
1311 | 1b9eb036 | j_mayer | fprintf(logfile, "%s: 0x" ADDRX "\n", __func__, value); |
1312 | 3fc6c082 | bellard | } |
1313 | 3fc6c082 | bellard | #endif
|
1314 | 3fc6c082 | bellard | if (env->sdr1 != value) {
|
1315 | 3fc6c082 | bellard | env->sdr1 = value; |
1316 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
1317 | 3fc6c082 | bellard | } |
1318 | 3fc6c082 | bellard | } |
1319 | 3fc6c082 | bellard | |
1320 | 3fc6c082 | bellard | target_ulong do_load_sr (CPUPPCState *env, int srnum)
|
1321 | 3fc6c082 | bellard | { |
1322 | 3fc6c082 | bellard | return env->sr[srnum];
|
1323 | 3fc6c082 | bellard | } |
1324 | 3fc6c082 | bellard | |
1325 | 3fc6c082 | bellard | void do_store_sr (CPUPPCState *env, int srnum, target_ulong value) |
1326 | 3fc6c082 | bellard | { |
1327 | 3fc6c082 | bellard | #if defined (DEBUG_MMU)
|
1328 | 3fc6c082 | bellard | if (loglevel != 0) { |
1329 | 1b9eb036 | j_mayer | fprintf(logfile, "%s: reg=%d 0x" ADDRX " " ADDRX "\n", |
1330 | 1b9eb036 | j_mayer | __func__, srnum, value, env->sr[srnum]); |
1331 | 3fc6c082 | bellard | } |
1332 | 3fc6c082 | bellard | #endif
|
1333 | 3fc6c082 | bellard | if (env->sr[srnum] != value) {
|
1334 | 3fc6c082 | bellard | env->sr[srnum] = value; |
1335 | 3fc6c082 | bellard | #if !defined(FLUSH_ALL_TLBS) && 0 |
1336 | 3fc6c082 | bellard | { |
1337 | 3fc6c082 | bellard | target_ulong page, end; |
1338 | 3fc6c082 | bellard | /* Invalidate 256 MB of virtual memory */
|
1339 | 3fc6c082 | bellard | page = (16 << 20) * srnum; |
1340 | 3fc6c082 | bellard | end = page + (16 << 20); |
1341 | 3fc6c082 | bellard | for (; page != end; page += TARGET_PAGE_SIZE)
|
1342 | 3fc6c082 | bellard | tlb_flush_page(env, page); |
1343 | 3fc6c082 | bellard | } |
1344 | 3fc6c082 | bellard | #else
|
1345 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
1346 | 3fc6c082 | bellard | #endif
|
1347 | 3fc6c082 | bellard | } |
1348 | 3fc6c082 | bellard | } |
1349 | 76a66253 | j_mayer | #endif /* !defined (CONFIG_USER_ONLY) */ |
1350 | 3fc6c082 | bellard | |
1351 | 76a66253 | j_mayer | uint32_t ppc_load_xer (CPUPPCState *env) |
1352 | 79aceca5 | bellard | { |
1353 | 79aceca5 | bellard | return (xer_so << XER_SO) |
|
1354 | 79aceca5 | bellard | (xer_ov << XER_OV) | |
1355 | 79aceca5 | bellard | (xer_ca << XER_CA) | |
1356 | 3fc6c082 | bellard | (xer_bc << XER_BC) | |
1357 | 3fc6c082 | bellard | (xer_cmp << XER_CMP); |
1358 | 79aceca5 | bellard | } |
1359 | 79aceca5 | bellard | |
1360 | 76a66253 | j_mayer | void ppc_store_xer (CPUPPCState *env, uint32_t value)
|
1361 | 79aceca5 | bellard | { |
1362 | 79aceca5 | bellard | xer_so = (value >> XER_SO) & 0x01;
|
1363 | 79aceca5 | bellard | xer_ov = (value >> XER_OV) & 0x01;
|
1364 | 79aceca5 | bellard | xer_ca = (value >> XER_CA) & 0x01;
|
1365 | 3fc6c082 | bellard | xer_cmp = (value >> XER_CMP) & 0xFF;
|
1366 | d9bce9d9 | j_mayer | xer_bc = (value >> XER_BC) & 0x7F;
|
1367 | 79aceca5 | bellard | } |
1368 | 79aceca5 | bellard | |
1369 | 76a66253 | j_mayer | /* Swap temporary saved registers with GPRs */
|
1370 | 76a66253 | j_mayer | static inline void swap_gpr_tgpr (CPUPPCState *env) |
1371 | 79aceca5 | bellard | { |
1372 | 76a66253 | j_mayer | ppc_gpr_t tmp; |
1373 | 76a66253 | j_mayer | |
1374 | 76a66253 | j_mayer | tmp = env->gpr[0];
|
1375 | 76a66253 | j_mayer | env->gpr[0] = env->tgpr[0]; |
1376 | 76a66253 | j_mayer | env->tgpr[0] = tmp;
|
1377 | 76a66253 | j_mayer | tmp = env->gpr[1];
|
1378 | 76a66253 | j_mayer | env->gpr[1] = env->tgpr[1]; |
1379 | 76a66253 | j_mayer | env->tgpr[1] = tmp;
|
1380 | 76a66253 | j_mayer | tmp = env->gpr[2];
|
1381 | 76a66253 | j_mayer | env->gpr[2] = env->tgpr[2]; |
1382 | 76a66253 | j_mayer | env->tgpr[2] = tmp;
|
1383 | 76a66253 | j_mayer | tmp = env->gpr[3];
|
1384 | 76a66253 | j_mayer | env->gpr[3] = env->tgpr[3]; |
1385 | 76a66253 | j_mayer | env->tgpr[3] = tmp;
|
1386 | 79aceca5 | bellard | } |
1387 | 79aceca5 | bellard | |
1388 | 76a66253 | j_mayer | /* GDBstub can read and write MSR... */
|
1389 | 76a66253 | j_mayer | target_ulong do_load_msr (CPUPPCState *env) |
1390 | 79aceca5 | bellard | { |
1391 | 76a66253 | j_mayer | return
|
1392 | 76a66253 | j_mayer | #if defined (TARGET_PPC64)
|
1393 | d9bce9d9 | j_mayer | ((target_ulong)msr_sf << MSR_SF) | |
1394 | d9bce9d9 | j_mayer | ((target_ulong)msr_isf << MSR_ISF) | |
1395 | d9bce9d9 | j_mayer | ((target_ulong)msr_hv << MSR_HV) | |
1396 | 76a66253 | j_mayer | #endif
|
1397 | d9bce9d9 | j_mayer | ((target_ulong)msr_ucle << MSR_UCLE) | |
1398 | d9bce9d9 | j_mayer | ((target_ulong)msr_vr << MSR_VR) | /* VR / SPE */
|
1399 | d9bce9d9 | j_mayer | ((target_ulong)msr_ap << MSR_AP) | |
1400 | d9bce9d9 | j_mayer | ((target_ulong)msr_sa << MSR_SA) | |
1401 | d9bce9d9 | j_mayer | ((target_ulong)msr_key << MSR_KEY) | |
1402 | d9bce9d9 | j_mayer | ((target_ulong)msr_pow << MSR_POW) | /* POW / WE */
|
1403 | d9bce9d9 | j_mayer | ((target_ulong)msr_tlb << MSR_TLB) | /* TLB / TGPE / CE */
|
1404 | d9bce9d9 | j_mayer | ((target_ulong)msr_ile << MSR_ILE) | |
1405 | d9bce9d9 | j_mayer | ((target_ulong)msr_ee << MSR_EE) | |
1406 | d9bce9d9 | j_mayer | ((target_ulong)msr_pr << MSR_PR) | |
1407 | d9bce9d9 | j_mayer | ((target_ulong)msr_fp << MSR_FP) | |
1408 | d9bce9d9 | j_mayer | ((target_ulong)msr_me << MSR_ME) | |
1409 | d9bce9d9 | j_mayer | ((target_ulong)msr_fe0 << MSR_FE0) | |
1410 | d9bce9d9 | j_mayer | ((target_ulong)msr_se << MSR_SE) | /* SE / DWE / UBLE */
|
1411 | d9bce9d9 | j_mayer | ((target_ulong)msr_be << MSR_BE) | /* BE / DE */
|
1412 | d9bce9d9 | j_mayer | ((target_ulong)msr_fe1 << MSR_FE1) | |
1413 | d9bce9d9 | j_mayer | ((target_ulong)msr_al << MSR_AL) | |
1414 | d9bce9d9 | j_mayer | ((target_ulong)msr_ip << MSR_IP) | |
1415 | d9bce9d9 | j_mayer | ((target_ulong)msr_ir << MSR_IR) | /* IR / IS */
|
1416 | d9bce9d9 | j_mayer | ((target_ulong)msr_dr << MSR_DR) | /* DR / DS */
|
1417 | d9bce9d9 | j_mayer | ((target_ulong)msr_pe << MSR_PE) | /* PE / EP */
|
1418 | d9bce9d9 | j_mayer | ((target_ulong)msr_px << MSR_PX) | /* PX / PMM */
|
1419 | d9bce9d9 | j_mayer | ((target_ulong)msr_ri << MSR_RI) | |
1420 | d9bce9d9 | j_mayer | ((target_ulong)msr_le << MSR_LE); |
1421 | 3fc6c082 | bellard | } |
1422 | 3fc6c082 | bellard | |
1423 | 3fc6c082 | bellard | void do_store_msr (CPUPPCState *env, target_ulong value)
|
1424 | 313adae9 | bellard | { |
1425 | 50443c98 | bellard | int enter_pm;
|
1426 | 50443c98 | bellard | |
1427 | 3fc6c082 | bellard | value &= env->msr_mask; |
1428 | 3fc6c082 | bellard | if (((value >> MSR_IR) & 1) != msr_ir || |
1429 | 3fc6c082 | bellard | ((value >> MSR_DR) & 1) != msr_dr) {
|
1430 | 76a66253 | j_mayer | /* Flush all tlb when changing translation mode */
|
1431 | d094807b | bellard | tlb_flush(env, 1);
|
1432 | 3fc6c082 | bellard | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
1433 | a541f297 | bellard | } |
1434 | 3fc6c082 | bellard | #if 0
|
1435 | 3fc6c082 | bellard | if (loglevel != 0) {
|
1436 | 3fc6c082 | bellard | fprintf(logfile, "%s: T0 %08lx\n", __func__, value);
|
1437 | 3fc6c082 | bellard | }
|
1438 | 3fc6c082 | bellard | #endif
|
1439 | 76a66253 | j_mayer | switch (PPC_EXCP(env)) {
|
1440 | 76a66253 | j_mayer | case PPC_FLAGS_EXCP_602:
|
1441 | 76a66253 | j_mayer | case PPC_FLAGS_EXCP_603:
|
1442 | 76a66253 | j_mayer | if (((value >> MSR_TGPR) & 1) != msr_tgpr) { |
1443 | 76a66253 | j_mayer | /* Swap temporary saved registers with GPRs */
|
1444 | 76a66253 | j_mayer | swap_gpr_tgpr(env); |
1445 | 76a66253 | j_mayer | } |
1446 | 76a66253 | j_mayer | break;
|
1447 | 76a66253 | j_mayer | default:
|
1448 | 76a66253 | j_mayer | break;
|
1449 | 76a66253 | j_mayer | } |
1450 | 76a66253 | j_mayer | #if defined (TARGET_PPC64)
|
1451 | 76a66253 | j_mayer | msr_sf = (value >> MSR_SF) & 1;
|
1452 | 76a66253 | j_mayer | msr_isf = (value >> MSR_ISF) & 1;
|
1453 | 76a66253 | j_mayer | msr_hv = (value >> MSR_HV) & 1;
|
1454 | 76a66253 | j_mayer | #endif
|
1455 | 76a66253 | j_mayer | msr_ucle = (value >> MSR_UCLE) & 1;
|
1456 | 76a66253 | j_mayer | msr_vr = (value >> MSR_VR) & 1; /* VR / SPE */ |
1457 | 76a66253 | j_mayer | msr_ap = (value >> MSR_AP) & 1;
|
1458 | 76a66253 | j_mayer | msr_sa = (value >> MSR_SA) & 1;
|
1459 | 76a66253 | j_mayer | msr_key = (value >> MSR_KEY) & 1;
|
1460 | 76a66253 | j_mayer | msr_pow = (value >> MSR_POW) & 1; /* POW / WE */ |
1461 | 76a66253 | j_mayer | msr_tlb = (value >> MSR_TLB) & 1; /* TLB / TGPR / CE */ |
1462 | 76a66253 | j_mayer | msr_ile = (value >> MSR_ILE) & 1;
|
1463 | 76a66253 | j_mayer | msr_ee = (value >> MSR_EE) & 1;
|
1464 | 76a66253 | j_mayer | msr_pr = (value >> MSR_PR) & 1;
|
1465 | 76a66253 | j_mayer | msr_fp = (value >> MSR_FP) & 1;
|
1466 | 76a66253 | j_mayer | msr_me = (value >> MSR_ME) & 1;
|
1467 | 76a66253 | j_mayer | msr_fe0 = (value >> MSR_FE0) & 1;
|
1468 | 76a66253 | j_mayer | msr_se = (value >> MSR_SE) & 1; /* SE / DWE / UBLE */ |
1469 | 76a66253 | j_mayer | msr_be = (value >> MSR_BE) & 1; /* BE / DE */ |
1470 | 76a66253 | j_mayer | msr_fe1 = (value >> MSR_FE1) & 1;
|
1471 | 76a66253 | j_mayer | msr_al = (value >> MSR_AL) & 1;
|
1472 | 76a66253 | j_mayer | msr_ip = (value >> MSR_IP) & 1;
|
1473 | 76a66253 | j_mayer | msr_ir = (value >> MSR_IR) & 1; /* IR / IS */ |
1474 | 76a66253 | j_mayer | msr_dr = (value >> MSR_DR) & 1; /* DR / DS */ |
1475 | 76a66253 | j_mayer | msr_pe = (value >> MSR_PE) & 1; /* PE / EP */ |
1476 | 76a66253 | j_mayer | msr_px = (value >> MSR_PX) & 1; /* PX / PMM */ |
1477 | 76a66253 | j_mayer | msr_ri = (value >> MSR_RI) & 1;
|
1478 | 76a66253 | j_mayer | msr_le = (value >> MSR_LE) & 1;
|
1479 | 3fc6c082 | bellard | do_compute_hflags(env); |
1480 | 50443c98 | bellard | |
1481 | 50443c98 | bellard | enter_pm = 0;
|
1482 | 50443c98 | bellard | switch (PPC_EXCP(env)) {
|
1483 | d9bce9d9 | j_mayer | case PPC_FLAGS_EXCP_603:
|
1484 | d9bce9d9 | j_mayer | /* Don't handle SLEEP mode: we should disable all clocks...
|
1485 | d9bce9d9 | j_mayer | * No dynamic power-management.
|
1486 | d9bce9d9 | j_mayer | */
|
1487 | d9bce9d9 | j_mayer | if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00C00000) != 0) |
1488 | d9bce9d9 | j_mayer | enter_pm = 1;
|
1489 | d9bce9d9 | j_mayer | break;
|
1490 | d9bce9d9 | j_mayer | case PPC_FLAGS_EXCP_604:
|
1491 | d9bce9d9 | j_mayer | if (msr_pow == 1) |
1492 | d9bce9d9 | j_mayer | enter_pm = 1;
|
1493 | d9bce9d9 | j_mayer | break;
|
1494 | 50443c98 | bellard | case PPC_FLAGS_EXCP_7x0:
|
1495 | 76a66253 | j_mayer | if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00E00000) != 0) |
1496 | 50443c98 | bellard | enter_pm = 1;
|
1497 | 50443c98 | bellard | break;
|
1498 | 50443c98 | bellard | default:
|
1499 | 50443c98 | bellard | break;
|
1500 | 50443c98 | bellard | } |
1501 | 50443c98 | bellard | if (enter_pm) {
|
1502 | c19dbb94 | ths | if (likely(!env->halted)) {
|
1503 | c19dbb94 | ths | /* power save: exit cpu loop */
|
1504 | c19dbb94 | ths | env->halted = 1;
|
1505 | c19dbb94 | ths | env->exception_index = EXCP_HLT; |
1506 | c19dbb94 | ths | cpu_loop_exit(); |
1507 | c19dbb94 | ths | } |
1508 | e80e1cc4 | bellard | } |
1509 | 3fc6c082 | bellard | } |
1510 | 3fc6c082 | bellard | |
1511 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
1512 | 426613db | j_mayer | void ppc_store_msr_32 (CPUPPCState *env, uint32_t value)
|
1513 | d9bce9d9 | j_mayer | { |
1514 | 426613db | j_mayer | do_store_msr(env, |
1515 | 426613db | j_mayer | (do_load_msr(env) & ~0xFFFFFFFFULL) | (value & 0xFFFFFFFF)); |
1516 | d9bce9d9 | j_mayer | } |
1517 | d9bce9d9 | j_mayer | #endif
|
1518 | d9bce9d9 | j_mayer | |
1519 | 76a66253 | j_mayer | void do_compute_hflags (CPUPPCState *env)
|
1520 | 3fc6c082 | bellard | { |
1521 | 76a66253 | j_mayer | /* Compute current hflags */
|
1522 | c62db105 | j_mayer | env->hflags = (msr_cm << MSR_CM) | (msr_vr << MSR_VR) | |
1523 | c62db105 | j_mayer | (msr_ap << MSR_AP) | (msr_sa << MSR_SA) | (msr_pr << MSR_PR) | |
1524 | c62db105 | j_mayer | (msr_fp << MSR_FP) | (msr_fe0 << MSR_FE0) | (msr_se << MSR_SE) | |
1525 | c62db105 | j_mayer | (msr_be << MSR_BE) | (msr_fe1 << MSR_FE1) | (msr_le << MSR_LE); |
1526 | 76a66253 | j_mayer | #if defined (TARGET_PPC64)
|
1527 | c62db105 | j_mayer | /* No care here: PowerPC 64 MSR_SF means the same as MSR_CM for BookE */
|
1528 | d9bce9d9 | j_mayer | env->hflags |= (msr_sf << (MSR_SF - 32)) | (msr_hv << (MSR_HV - 32)); |
1529 | 4b3686fa | bellard | #endif
|
1530 | 3fc6c082 | bellard | } |
1531 | 3fc6c082 | bellard | |
1532 | 3fc6c082 | bellard | /*****************************************************************************/
|
1533 | 3fc6c082 | bellard | /* Exception processing */
|
1534 | 18fba28c | bellard | #if defined (CONFIG_USER_ONLY)
|
1535 | 9a64fbe4 | bellard | void do_interrupt (CPUState *env)
|
1536 | 79aceca5 | bellard | { |
1537 | 18fba28c | bellard | env->exception_index = -1;
|
1538 | 18fba28c | bellard | } |
1539 | 47103572 | j_mayer | |
1540 | e9df014c | j_mayer | void ppc_hw_interrupt (CPUState *env)
|
1541 | 47103572 | j_mayer | { |
1542 | 47103572 | j_mayer | env->exception_index = -1;
|
1543 | 47103572 | j_mayer | } |
1544 | 76a66253 | j_mayer | #else /* defined (CONFIG_USER_ONLY) */ |
1545 | 36081602 | j_mayer | static void dump_syscall (CPUState *env) |
1546 | d094807b | bellard | { |
1547 | d9bce9d9 | j_mayer | fprintf(logfile, "syscall r0=0x" REGX " r3=0x" REGX " r4=0x" REGX |
1548 | 1b9eb036 | j_mayer | " r5=0x" REGX " r6=0x" REGX " nip=0x" ADDRX "\n", |
1549 | d094807b | bellard | env->gpr[0], env->gpr[3], env->gpr[4], |
1550 | d094807b | bellard | env->gpr[5], env->gpr[6], env->nip); |
1551 | d094807b | bellard | } |
1552 | d094807b | bellard | |
1553 | 18fba28c | bellard | void do_interrupt (CPUState *env)
|
1554 | 18fba28c | bellard | { |
1555 | c62db105 | j_mayer | target_ulong msr, *srr_0, *srr_1, *asrr_0, *asrr_1; |
1556 | c62db105 | j_mayer | int excp, idx;
|
1557 | 79aceca5 | bellard | |
1558 | 18fba28c | bellard | excp = env->exception_index; |
1559 | 3fc6c082 | bellard | msr = do_load_msr(env); |
1560 | 2be0071f | bellard | /* The default is to use SRR0 & SRR1 to save the exception context */
|
1561 | 2be0071f | bellard | srr_0 = &env->spr[SPR_SRR0]; |
1562 | 2be0071f | bellard | srr_1 = &env->spr[SPR_SRR1]; |
1563 | c62db105 | j_mayer | asrr_0 = NULL;
|
1564 | c62db105 | j_mayer | asrr_1 = NULL;
|
1565 | 9a64fbe4 | bellard | #if defined (DEBUG_EXCEPTIONS)
|
1566 | 2be0071f | bellard | if ((excp == EXCP_PROGRAM || excp == EXCP_DSI) && msr_pr == 1) { |
1567 | 2be0071f | bellard | if (loglevel != 0) { |
1568 | 1b9eb036 | j_mayer | fprintf(logfile, |
1569 | 1b9eb036 | j_mayer | "Raise exception at 0x" ADDRX " => 0x%08x (%02x)\n", |
1570 | 1b9eb036 | j_mayer | env->nip, excp, env->error_code); |
1571 | 76a66253 | j_mayer | cpu_dump_state(env, logfile, fprintf, 0);
|
1572 | b769d8fe | bellard | } |
1573 | 79aceca5 | bellard | } |
1574 | 9a64fbe4 | bellard | #endif
|
1575 | b769d8fe | bellard | if (loglevel & CPU_LOG_INT) {
|
1576 | 1b9eb036 | j_mayer | fprintf(logfile, "Raise exception at 0x" ADDRX " => 0x%08x (%02x)\n", |
1577 | 1b9eb036 | j_mayer | env->nip, excp, env->error_code); |
1578 | b769d8fe | bellard | } |
1579 | 2be0071f | bellard | msr_pow = 0;
|
1580 | c62db105 | j_mayer | idx = -1;
|
1581 | 9a64fbe4 | bellard | /* Generate informations in save/restore registers */
|
1582 | 9a64fbe4 | bellard | switch (excp) {
|
1583 | 76a66253 | j_mayer | /* Generic PowerPC exceptions */
|
1584 | 2be0071f | bellard | case EXCP_RESET: /* 0x0100 */ |
1585 | c62db105 | j_mayer | switch (PPC_EXCP(env)) {
|
1586 | c62db105 | j_mayer | case PPC_FLAGS_EXCP_40x:
|
1587 | c62db105 | j_mayer | srr_0 = &env->spr[SPR_40x_SRR2]; |
1588 | c62db105 | j_mayer | srr_1 = &env->spr[SPR_40x_SRR3]; |
1589 | c62db105 | j_mayer | break;
|
1590 | c62db105 | j_mayer | case PPC_FLAGS_EXCP_BOOKE:
|
1591 | c62db105 | j_mayer | idx = 0;
|
1592 | c62db105 | j_mayer | srr_0 = &env->spr[SPR_BOOKE_CSRR0]; |
1593 | c62db105 | j_mayer | srr_1 = &env->spr[SPR_BOOKE_CSRR1]; |
1594 | c62db105 | j_mayer | break;
|
1595 | c62db105 | j_mayer | default:
|
1596 | 2be0071f | bellard | if (msr_ip)
|
1597 | 2be0071f | bellard | excp += 0xFFC00;
|
1598 | 2be0071f | bellard | excp |= 0xFFC00000;
|
1599 | c62db105 | j_mayer | break;
|
1600 | 2be0071f | bellard | } |
1601 | 9a64fbe4 | bellard | goto store_next;
|
1602 | 2be0071f | bellard | case EXCP_MACHINE_CHECK: /* 0x0200 */ |
1603 | c62db105 | j_mayer | switch (PPC_EXCP(env)) {
|
1604 | c62db105 | j_mayer | case PPC_FLAGS_EXCP_40x:
|
1605 | 2be0071f | bellard | srr_0 = &env->spr[SPR_40x_SRR2]; |
1606 | 2be0071f | bellard | srr_1 = &env->spr[SPR_40x_SRR3]; |
1607 | c62db105 | j_mayer | break;
|
1608 | c62db105 | j_mayer | case PPC_FLAGS_EXCP_BOOKE:
|
1609 | c62db105 | j_mayer | idx = 1;
|
1610 | c62db105 | j_mayer | srr_0 = &env->spr[SPR_BOOKE_MCSRR0]; |
1611 | c62db105 | j_mayer | srr_1 = &env->spr[SPR_BOOKE_MCSRR1]; |
1612 | c62db105 | j_mayer | asrr_0 = &env->spr[SPR_BOOKE_CSRR0]; |
1613 | c62db105 | j_mayer | asrr_1 = &env->spr[SPR_BOOKE_CSRR1]; |
1614 | c62db105 | j_mayer | msr_ce = 0;
|
1615 | c62db105 | j_mayer | break;
|
1616 | c62db105 | j_mayer | default:
|
1617 | c62db105 | j_mayer | break;
|
1618 | 2be0071f | bellard | } |
1619 | 9a64fbe4 | bellard | msr_me = 0;
|
1620 | 9a64fbe4 | bellard | break;
|
1621 | 2be0071f | bellard | case EXCP_DSI: /* 0x0300 */ |
1622 | 9a64fbe4 | bellard | /* Store exception cause */
|
1623 | 9a64fbe4 | bellard | /* data location address has been stored
|
1624 | 9a64fbe4 | bellard | * when the fault has been detected
|
1625 | 2be0071f | bellard | */
|
1626 | c62db105 | j_mayer | idx = 2;
|
1627 | 76a66253 | j_mayer | msr &= ~0xFFFF0000;
|
1628 | a541f297 | bellard | #if defined (DEBUG_EXCEPTIONS)
|
1629 | 4a057712 | j_mayer | if (loglevel != 0) { |
1630 | 1b9eb036 | j_mayer | fprintf(logfile, "DSI exception: DSISR=0x" ADDRX" DAR=0x" ADDRX |
1631 | 1b9eb036 | j_mayer | "\n", env->spr[SPR_DSISR], env->spr[SPR_DAR]);
|
1632 | 76a66253 | j_mayer | } |
1633 | a541f297 | bellard | #endif
|
1634 | a541f297 | bellard | goto store_next;
|
1635 | 2be0071f | bellard | case EXCP_ISI: /* 0x0400 */ |
1636 | 9a64fbe4 | bellard | /* Store exception cause */
|
1637 | c62db105 | j_mayer | idx = 3;
|
1638 | 76a66253 | j_mayer | msr &= ~0xFFFF0000;
|
1639 | 2be0071f | bellard | msr |= env->error_code; |
1640 | a541f297 | bellard | #if defined (DEBUG_EXCEPTIONS)
|
1641 | 76a66253 | j_mayer | if (loglevel != 0) { |
1642 | 1b9eb036 | j_mayer | fprintf(logfile, "ISI exception: msr=0x" ADDRX ", nip=0x" ADDRX |
1643 | 1b9eb036 | j_mayer | "\n", msr, env->nip);
|
1644 | 76a66253 | j_mayer | } |
1645 | a541f297 | bellard | #endif
|
1646 | 9a64fbe4 | bellard | goto store_next;
|
1647 | 2be0071f | bellard | case EXCP_EXTERNAL: /* 0x0500 */ |
1648 | c62db105 | j_mayer | idx = 4;
|
1649 | 9a64fbe4 | bellard | goto store_next;
|
1650 | 2be0071f | bellard | case EXCP_ALIGN: /* 0x0600 */ |
1651 | 76a66253 | j_mayer | if (likely(PPC_EXCP(env) != PPC_FLAGS_EXCP_601)) {
|
1652 | 2be0071f | bellard | /* Store exception cause */
|
1653 | c62db105 | j_mayer | idx = 5;
|
1654 | 2be0071f | bellard | /* Get rS/rD and rA from faulting opcode */
|
1655 | 2be0071f | bellard | env->spr[SPR_DSISR] |= |
1656 | 2be0071f | bellard | (ldl_code((env->nip - 4)) & 0x03FF0000) >> 16; |
1657 | 2be0071f | bellard | /* data location address has been stored
|
1658 | 2be0071f | bellard | * when the fault has been detected
|
1659 | 2be0071f | bellard | */
|
1660 | 2be0071f | bellard | } else {
|
1661 | 2be0071f | bellard | /* IO error exception on PowerPC 601 */
|
1662 | 2be0071f | bellard | /* XXX: TODO */
|
1663 | 2be0071f | bellard | cpu_abort(env, |
1664 | 2be0071f | bellard | "601 IO error exception is not implemented yet !\n");
|
1665 | 2be0071f | bellard | } |
1666 | 9a64fbe4 | bellard | goto store_current;
|
1667 | 2be0071f | bellard | case EXCP_PROGRAM: /* 0x0700 */ |
1668 | c62db105 | j_mayer | idx = 6;
|
1669 | 9a64fbe4 | bellard | msr &= ~0xFFFF0000;
|
1670 | 9a64fbe4 | bellard | switch (env->error_code & ~0xF) { |
1671 | 9a64fbe4 | bellard | case EXCP_FP:
|
1672 | 9a64fbe4 | bellard | if (msr_fe0 == 0 && msr_fe1 == 0) { |
1673 | 9a64fbe4 | bellard | #if defined (DEBUG_EXCEPTIONS)
|
1674 | 4a057712 | j_mayer | if (loglevel != 0) { |
1675 | a496775f | j_mayer | fprintf(logfile, "Ignore floating point exception\n");
|
1676 | a496775f | j_mayer | } |
1677 | 9a64fbe4 | bellard | #endif
|
1678 | 9a64fbe4 | bellard | return;
|
1679 | 76a66253 | j_mayer | } |
1680 | 9a64fbe4 | bellard | msr |= 0x00100000;
|
1681 | 9a64fbe4 | bellard | /* Set FX */
|
1682 | 9a64fbe4 | bellard | env->fpscr[7] |= 0x8; |
1683 | 9a64fbe4 | bellard | /* Finally, update FEX */
|
1684 | 9a64fbe4 | bellard | if ((((env->fpscr[7] & 0x3) << 3) | (env->fpscr[6] >> 1)) & |
1685 | 9a64fbe4 | bellard | ((env->fpscr[1] << 1) | (env->fpscr[0] >> 3))) |
1686 | 9a64fbe4 | bellard | env->fpscr[7] |= 0x4; |
1687 | 76a66253 | j_mayer | break;
|
1688 | 9a64fbe4 | bellard | case EXCP_INVAL:
|
1689 | a496775f | j_mayer | #if defined (DEBUG_EXCEPTIONS)
|
1690 | 4a057712 | j_mayer | if (loglevel != 0) { |
1691 | a496775f | j_mayer | fprintf(logfile, "Invalid instruction at 0x" ADDRX "\n", |
1692 | a496775f | j_mayer | env->nip); |
1693 | a496775f | j_mayer | } |
1694 | a496775f | j_mayer | #endif
|
1695 | 9a64fbe4 | bellard | msr |= 0x00080000;
|
1696 | 76a66253 | j_mayer | break;
|
1697 | 9a64fbe4 | bellard | case EXCP_PRIV:
|
1698 | 9a64fbe4 | bellard | msr |= 0x00040000;
|
1699 | 76a66253 | j_mayer | break;
|
1700 | 9a64fbe4 | bellard | case EXCP_TRAP:
|
1701 | c62db105 | j_mayer | idx = 15;
|
1702 | 9a64fbe4 | bellard | msr |= 0x00020000;
|
1703 | 9a64fbe4 | bellard | break;
|
1704 | 9a64fbe4 | bellard | default:
|
1705 | 9a64fbe4 | bellard | /* Should never occur */
|
1706 | 76a66253 | j_mayer | break;
|
1707 | 76a66253 | j_mayer | } |
1708 | 9a64fbe4 | bellard | msr |= 0x00010000;
|
1709 | 9a64fbe4 | bellard | goto store_current;
|
1710 | 2be0071f | bellard | case EXCP_NO_FP: /* 0x0800 */ |
1711 | c62db105 | j_mayer | idx = 7;
|
1712 | 4ecc3190 | bellard | msr &= ~0xFFFF0000;
|
1713 | 9a64fbe4 | bellard | goto store_current;
|
1714 | 9a64fbe4 | bellard | case EXCP_DECR:
|
1715 | 9a64fbe4 | bellard | goto store_next;
|
1716 | 2be0071f | bellard | case EXCP_SYSCALL: /* 0x0C00 */ |
1717 | c62db105 | j_mayer | idx = 8;
|
1718 | d094807b | bellard | /* NOTE: this is a temporary hack to support graphics OSI
|
1719 | d094807b | bellard | calls from the MOL driver */
|
1720 | d094807b | bellard | if (env->gpr[3] == 0x113724fa && env->gpr[4] == 0x77810f9b && |
1721 | d094807b | bellard | env->osi_call) { |
1722 | d094807b | bellard | if (env->osi_call(env) != 0) |
1723 | d094807b | bellard | return;
|
1724 | d094807b | bellard | } |
1725 | b769d8fe | bellard | if (loglevel & CPU_LOG_INT) {
|
1726 | d094807b | bellard | dump_syscall(env); |
1727 | b769d8fe | bellard | } |
1728 | 9a64fbe4 | bellard | goto store_next;
|
1729 | 2be0071f | bellard | case EXCP_TRACE: /* 0x0D00 */ |
1730 | 2be0071f | bellard | goto store_next;
|
1731 | 2be0071f | bellard | case EXCP_PERF: /* 0x0F00 */ |
1732 | 2be0071f | bellard | /* XXX: TODO */
|
1733 | 2be0071f | bellard | cpu_abort(env, |
1734 | 2be0071f | bellard | "Performance counter exception is not implemented yet !\n");
|
1735 | 2be0071f | bellard | goto store_next;
|
1736 | 2be0071f | bellard | /* 32 bits PowerPC specific exceptions */
|
1737 | 2be0071f | bellard | case EXCP_FP_ASSIST: /* 0x0E00 */ |
1738 | 2be0071f | bellard | /* XXX: TODO */
|
1739 | 2be0071f | bellard | cpu_abort(env, "Floating point assist exception "
|
1740 | 2be0071f | bellard | "is not implemented yet !\n");
|
1741 | 2be0071f | bellard | goto store_next;
|
1742 | 76a66253 | j_mayer | /* 64 bits PowerPC exceptions */
|
1743 | 2be0071f | bellard | case EXCP_DSEG: /* 0x0380 */ |
1744 | 2be0071f | bellard | /* XXX: TODO */
|
1745 | 2be0071f | bellard | cpu_abort(env, "Data segment exception is not implemented yet !\n");
|
1746 | 9a64fbe4 | bellard | goto store_next;
|
1747 | 2be0071f | bellard | case EXCP_ISEG: /* 0x0480 */ |
1748 | 2be0071f | bellard | /* XXX: TODO */
|
1749 | 2be0071f | bellard | cpu_abort(env, |
1750 | 2be0071f | bellard | "Instruction segment exception is not implemented yet !\n");
|
1751 | 9a64fbe4 | bellard | goto store_next;
|
1752 | 2be0071f | bellard | case EXCP_HDECR: /* 0x0980 */ |
1753 | 76a66253 | j_mayer | /* XXX: TODO */
|
1754 | 76a66253 | j_mayer | cpu_abort(env, "Hypervisor decrementer exception is not implemented "
|
1755 | 76a66253 | j_mayer | "yet !\n");
|
1756 | 2be0071f | bellard | goto store_next;
|
1757 | 2be0071f | bellard | /* Implementation specific exceptions */
|
1758 | 2be0071f | bellard | case 0x0A00: |
1759 | 76a66253 | j_mayer | if (likely(env->spr[SPR_PVR] == CPU_PPC_G2 ||
|
1760 | 76a66253 | j_mayer | env->spr[SPR_PVR] == CPU_PPC_G2LE)) { |
1761 | 2be0071f | bellard | /* Critical interrupt on G2 */
|
1762 | 2be0071f | bellard | /* XXX: TODO */
|
1763 | 2be0071f | bellard | cpu_abort(env, "G2 critical interrupt is not implemented yet !\n");
|
1764 | 2be0071f | bellard | goto store_next;
|
1765 | 2be0071f | bellard | } else {
|
1766 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x0A00 !\n");
|
1767 | 2be0071f | bellard | } |
1768 | 9a64fbe4 | bellard | return;
|
1769 | 2be0071f | bellard | case 0x0F20: |
1770 | c62db105 | j_mayer | idx = 9;
|
1771 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1772 | 2be0071f | bellard | case PPC_FLAGS_EXCP_40x:
|
1773 | 2be0071f | bellard | /* APU unavailable on 405 */
|
1774 | 2be0071f | bellard | /* XXX: TODO */
|
1775 | 2be0071f | bellard | cpu_abort(env, |
1776 | 2be0071f | bellard | "APU unavailable exception is not implemented yet !\n");
|
1777 | 2be0071f | bellard | goto store_next;
|
1778 | 2be0071f | bellard | case PPC_FLAGS_EXCP_74xx:
|
1779 | 2be0071f | bellard | /* Altivec unavailable */
|
1780 | 2be0071f | bellard | /* XXX: TODO */
|
1781 | 2be0071f | bellard | cpu_abort(env, "Altivec unavailable exception "
|
1782 | 2be0071f | bellard | "is not implemented yet !\n");
|
1783 | 2be0071f | bellard | goto store_next;
|
1784 | 2be0071f | bellard | default:
|
1785 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x0F20 !\n");
|
1786 | 2be0071f | bellard | break;
|
1787 | 2be0071f | bellard | } |
1788 | 2be0071f | bellard | return;
|
1789 | 2be0071f | bellard | case 0x1000: |
1790 | c62db105 | j_mayer | idx = 10;
|
1791 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1792 | 2be0071f | bellard | case PPC_FLAGS_EXCP_40x:
|
1793 | 2be0071f | bellard | /* PIT on 4xx */
|
1794 | c62db105 | j_mayer | msr &= ~0xFFFF0000;
|
1795 | a496775f | j_mayer | #if defined (DEBUG_EXCEPTIONS)
|
1796 | c62db105 | j_mayer | if (loglevel != 0) |
1797 | c62db105 | j_mayer | fprintf(logfile, "PIT exception\n");
|
1798 | a496775f | j_mayer | #endif
|
1799 | 2be0071f | bellard | goto store_next;
|
1800 | 2be0071f | bellard | case PPC_FLAGS_EXCP_602:
|
1801 | 2be0071f | bellard | case PPC_FLAGS_EXCP_603:
|
1802 | 2be0071f | bellard | /* ITLBMISS on 602/603 */
|
1803 | 2be0071f | bellard | goto store_gprs;
|
1804 | 76a66253 | j_mayer | case PPC_FLAGS_EXCP_7x5:
|
1805 | 76a66253 | j_mayer | /* ITLBMISS on 745/755 */
|
1806 | 76a66253 | j_mayer | goto tlb_miss;
|
1807 | 2be0071f | bellard | default:
|
1808 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1000 !\n");
|
1809 | 2be0071f | bellard | break;
|
1810 | 2be0071f | bellard | } |
1811 | 2be0071f | bellard | return;
|
1812 | 2be0071f | bellard | case 0x1010: |
1813 | c62db105 | j_mayer | idx = 11;
|
1814 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1815 | 2be0071f | bellard | case PPC_FLAGS_EXCP_40x:
|
1816 | 2be0071f | bellard | /* FIT on 4xx */
|
1817 | c62db105 | j_mayer | msr &= ~0xFFFF0000;
|
1818 | a496775f | j_mayer | #if defined (DEBUG_EXCEPTIONS)
|
1819 | c62db105 | j_mayer | if (loglevel != 0) |
1820 | c62db105 | j_mayer | fprintf(logfile, "FIT exception\n");
|
1821 | a496775f | j_mayer | #endif
|
1822 | 2be0071f | bellard | goto store_next;
|
1823 | 2be0071f | bellard | default:
|
1824 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1010 !\n");
|
1825 | 2be0071f | bellard | break;
|
1826 | 2be0071f | bellard | } |
1827 | 2be0071f | bellard | return;
|
1828 | 2be0071f | bellard | case 0x1020: |
1829 | c62db105 | j_mayer | idx = 12;
|
1830 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1831 | 2be0071f | bellard | case PPC_FLAGS_EXCP_40x:
|
1832 | 2be0071f | bellard | /* Watchdog on 4xx */
|
1833 | c62db105 | j_mayer | msr &= ~0xFFFF0000;
|
1834 | a496775f | j_mayer | #if defined (DEBUG_EXCEPTIONS)
|
1835 | c62db105 | j_mayer | if (loglevel != 0) |
1836 | c62db105 | j_mayer | fprintf(logfile, "WDT exception\n");
|
1837 | a496775f | j_mayer | #endif
|
1838 | 2be0071f | bellard | goto store_next;
|
1839 | c62db105 | j_mayer | case PPC_FLAGS_EXCP_BOOKE:
|
1840 | c62db105 | j_mayer | srr_0 = &env->spr[SPR_BOOKE_CSRR0]; |
1841 | c62db105 | j_mayer | srr_1 = &env->spr[SPR_BOOKE_CSRR1]; |
1842 | c62db105 | j_mayer | break;
|
1843 | 2be0071f | bellard | default:
|
1844 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1020 !\n");
|
1845 | 2be0071f | bellard | break;
|
1846 | 2be0071f | bellard | } |
1847 | 2be0071f | bellard | return;
|
1848 | 2be0071f | bellard | case 0x1100: |
1849 | c62db105 | j_mayer | idx = 13;
|
1850 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1851 | 2be0071f | bellard | case PPC_FLAGS_EXCP_40x:
|
1852 | 2be0071f | bellard | /* DTLBMISS on 4xx */
|
1853 | a8dea12f | j_mayer | msr &= ~0xFFFF0000;
|
1854 | 2be0071f | bellard | goto store_next;
|
1855 | 2be0071f | bellard | case PPC_FLAGS_EXCP_602:
|
1856 | 2be0071f | bellard | case PPC_FLAGS_EXCP_603:
|
1857 | 2be0071f | bellard | /* DLTLBMISS on 602/603 */
|
1858 | 2be0071f | bellard | goto store_gprs;
|
1859 | 76a66253 | j_mayer | case PPC_FLAGS_EXCP_7x5:
|
1860 | 76a66253 | j_mayer | /* DLTLBMISS on 745/755 */
|
1861 | 76a66253 | j_mayer | goto tlb_miss;
|
1862 | 2be0071f | bellard | default:
|
1863 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1100 !\n");
|
1864 | 2be0071f | bellard | break;
|
1865 | 2be0071f | bellard | } |
1866 | 2be0071f | bellard | return;
|
1867 | 2be0071f | bellard | case 0x1200: |
1868 | c62db105 | j_mayer | idx = 14;
|
1869 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1870 | 2be0071f | bellard | case PPC_FLAGS_EXCP_40x:
|
1871 | 2be0071f | bellard | /* ITLBMISS on 4xx */
|
1872 | a8dea12f | j_mayer | msr &= ~0xFFFF0000;
|
1873 | 2be0071f | bellard | goto store_next;
|
1874 | 2be0071f | bellard | case PPC_FLAGS_EXCP_602:
|
1875 | 2be0071f | bellard | case PPC_FLAGS_EXCP_603:
|
1876 | 2be0071f | bellard | /* DSTLBMISS on 602/603 */
|
1877 | 2be0071f | bellard | store_gprs:
|
1878 | 76a66253 | j_mayer | /* Swap temporary saved registers with GPRs */
|
1879 | 76a66253 | j_mayer | swap_gpr_tgpr(env); |
1880 | 76a66253 | j_mayer | msr_tgpr = 1;
|
1881 | 2be0071f | bellard | #if defined (DEBUG_SOFTWARE_TLB)
|
1882 | 2be0071f | bellard | if (loglevel != 0) { |
1883 | 76a66253 | j_mayer | const unsigned char *es; |
1884 | 76a66253 | j_mayer | target_ulong *miss, *cmp; |
1885 | 76a66253 | j_mayer | int en;
|
1886 | 76a66253 | j_mayer | if (excp == 0x1000) { |
1887 | 76a66253 | j_mayer | es = "I";
|
1888 | 76a66253 | j_mayer | en = 'I';
|
1889 | 76a66253 | j_mayer | miss = &env->spr[SPR_IMISS]; |
1890 | 76a66253 | j_mayer | cmp = &env->spr[SPR_ICMP]; |
1891 | 76a66253 | j_mayer | } else {
|
1892 | 76a66253 | j_mayer | if (excp == 0x1100) |
1893 | 76a66253 | j_mayer | es = "DL";
|
1894 | 76a66253 | j_mayer | else
|
1895 | 76a66253 | j_mayer | es = "DS";
|
1896 | 76a66253 | j_mayer | en = 'D';
|
1897 | 76a66253 | j_mayer | miss = &env->spr[SPR_DMISS]; |
1898 | 76a66253 | j_mayer | cmp = &env->spr[SPR_DCMP]; |
1899 | 76a66253 | j_mayer | } |
1900 | 1b9eb036 | j_mayer | fprintf(logfile, "6xx %sTLB miss: %cM " ADDRX " %cC " ADDRX |
1901 | 4a057712 | j_mayer | " H1 " ADDRX " H2 " ADDRX " %08x\n", |
1902 | 1b9eb036 | j_mayer | es, en, *miss, en, *cmp, |
1903 | 76a66253 | j_mayer | env->spr[SPR_HASH1], env->spr[SPR_HASH2], |
1904 | 2be0071f | bellard | env->error_code); |
1905 | 2be0071f | bellard | } |
1906 | 9a64fbe4 | bellard | #endif
|
1907 | 76a66253 | j_mayer | goto tlb_miss;
|
1908 | 76a66253 | j_mayer | case PPC_FLAGS_EXCP_7x5:
|
1909 | 76a66253 | j_mayer | /* DSTLBMISS on 745/755 */
|
1910 | 76a66253 | j_mayer | tlb_miss:
|
1911 | 76a66253 | j_mayer | msr &= ~0xF83F0000;
|
1912 | 2be0071f | bellard | msr |= env->crf[0] << 28; |
1913 | 2be0071f | bellard | msr |= env->error_code; /* key, D/I, S/L bits */
|
1914 | 2be0071f | bellard | /* Set way using a LRU mechanism */
|
1915 | 76a66253 | j_mayer | msr |= ((env->last_way + 1) & (env->nb_ways - 1)) << 17; |
1916 | 2be0071f | bellard | goto store_next;
|
1917 | 2be0071f | bellard | default:
|
1918 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1200 !\n");
|
1919 | 2be0071f | bellard | break;
|
1920 | 2be0071f | bellard | } |
1921 | 2be0071f | bellard | return;
|
1922 | 2be0071f | bellard | case 0x1300: |
1923 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1924 | 2be0071f | bellard | case PPC_FLAGS_EXCP_601:
|
1925 | 2be0071f | bellard | case PPC_FLAGS_EXCP_602:
|
1926 | 2be0071f | bellard | case PPC_FLAGS_EXCP_603:
|
1927 | 2be0071f | bellard | case PPC_FLAGS_EXCP_604:
|
1928 | 2be0071f | bellard | case PPC_FLAGS_EXCP_7x0:
|
1929 | 2be0071f | bellard | case PPC_FLAGS_EXCP_7x5:
|
1930 | 2be0071f | bellard | /* IABR on 6xx/7xx */
|
1931 | 2be0071f | bellard | /* XXX: TODO */
|
1932 | 2be0071f | bellard | cpu_abort(env, "IABR exception is not implemented yet !\n");
|
1933 | 2be0071f | bellard | goto store_next;
|
1934 | 2be0071f | bellard | default:
|
1935 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1300 !\n");
|
1936 | 2be0071f | bellard | break;
|
1937 | 2be0071f | bellard | } |
1938 | 2be0071f | bellard | return;
|
1939 | 2be0071f | bellard | case 0x1400: |
1940 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1941 | 2be0071f | bellard | case PPC_FLAGS_EXCP_601:
|
1942 | 2be0071f | bellard | case PPC_FLAGS_EXCP_602:
|
1943 | 2be0071f | bellard | case PPC_FLAGS_EXCP_603:
|
1944 | 2be0071f | bellard | case PPC_FLAGS_EXCP_604:
|
1945 | 2be0071f | bellard | case PPC_FLAGS_EXCP_7x0:
|
1946 | 2be0071f | bellard | case PPC_FLAGS_EXCP_7x5:
|
1947 | 2be0071f | bellard | /* SMI on 6xx/7xx */
|
1948 | 2be0071f | bellard | /* XXX: TODO */
|
1949 | 2be0071f | bellard | cpu_abort(env, "SMI exception is not implemented yet !\n");
|
1950 | 2be0071f | bellard | goto store_next;
|
1951 | 2be0071f | bellard | default:
|
1952 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1400 !\n");
|
1953 | 2be0071f | bellard | break;
|
1954 | 2be0071f | bellard | } |
1955 | 2be0071f | bellard | return;
|
1956 | 2be0071f | bellard | case 0x1500: |
1957 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1958 | 2be0071f | bellard | case PPC_FLAGS_EXCP_602:
|
1959 | 2be0071f | bellard | /* Watchdog on 602 */
|
1960 | 76a66253 | j_mayer | /* XXX: TODO */
|
1961 | 2be0071f | bellard | cpu_abort(env, |
1962 | 2be0071f | bellard | "602 watchdog exception is not implemented yet !\n");
|
1963 | 2be0071f | bellard | goto store_next;
|
1964 | 2be0071f | bellard | case PPC_FLAGS_EXCP_970:
|
1965 | 2be0071f | bellard | /* Soft patch exception on 970 */
|
1966 | 2be0071f | bellard | /* XXX: TODO */
|
1967 | 2be0071f | bellard | cpu_abort(env, |
1968 | 2be0071f | bellard | "970 soft-patch exception is not implemented yet !\n");
|
1969 | 2be0071f | bellard | goto store_next;
|
1970 | 2be0071f | bellard | case PPC_FLAGS_EXCP_74xx:
|
1971 | 2be0071f | bellard | /* VPU assist on 74xx */
|
1972 | 2be0071f | bellard | /* XXX: TODO */
|
1973 | 2be0071f | bellard | cpu_abort(env, "VPU assist exception is not implemented yet !\n");
|
1974 | 2be0071f | bellard | goto store_next;
|
1975 | 2be0071f | bellard | default:
|
1976 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1500 !\n");
|
1977 | 2be0071f | bellard | break;
|
1978 | 2be0071f | bellard | } |
1979 | 2be0071f | bellard | return;
|
1980 | 2be0071f | bellard | case 0x1600: |
1981 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
1982 | 2be0071f | bellard | case PPC_FLAGS_EXCP_602:
|
1983 | 2be0071f | bellard | /* Emulation trap on 602 */
|
1984 | 2be0071f | bellard | /* XXX: TODO */
|
1985 | 2be0071f | bellard | cpu_abort(env, "602 emulation trap exception "
|
1986 | 2be0071f | bellard | "is not implemented yet !\n");
|
1987 | 2be0071f | bellard | goto store_next;
|
1988 | 2be0071f | bellard | case PPC_FLAGS_EXCP_970:
|
1989 | 2be0071f | bellard | /* Maintenance exception on 970 */
|
1990 | 2be0071f | bellard | /* XXX: TODO */
|
1991 | 2be0071f | bellard | cpu_abort(env, |
1992 | 2be0071f | bellard | "970 maintenance exception is not implemented yet !\n");
|
1993 | 2be0071f | bellard | goto store_next;
|
1994 | 2be0071f | bellard | default:
|
1995 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1600 !\n");
|
1996 | 2be0071f | bellard | break;
|
1997 | 2be0071f | bellard | } |
1998 | 2be0071f | bellard | return;
|
1999 | 2be0071f | bellard | case 0x1700: |
2000 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
2001 | 2be0071f | bellard | case PPC_FLAGS_EXCP_7x0:
|
2002 | 2be0071f | bellard | case PPC_FLAGS_EXCP_7x5:
|
2003 | 2be0071f | bellard | /* Thermal management interrupt on G3 */
|
2004 | 2be0071f | bellard | /* XXX: TODO */
|
2005 | 2be0071f | bellard | cpu_abort(env, "G3 thermal management exception "
|
2006 | 2be0071f | bellard | "is not implemented yet !\n");
|
2007 | 2be0071f | bellard | goto store_next;
|
2008 | 2be0071f | bellard | case PPC_FLAGS_EXCP_970:
|
2009 | 2be0071f | bellard | /* VPU assist on 970 */
|
2010 | 2be0071f | bellard | /* XXX: TODO */
|
2011 | 2be0071f | bellard | cpu_abort(env, |
2012 | 2be0071f | bellard | "970 VPU assist exception is not implemented yet !\n");
|
2013 | 2be0071f | bellard | goto store_next;
|
2014 | 2be0071f | bellard | default:
|
2015 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1700 !\n");
|
2016 | 2be0071f | bellard | break;
|
2017 | 2be0071f | bellard | } |
2018 | 2be0071f | bellard | return;
|
2019 | 2be0071f | bellard | case 0x1800: |
2020 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
2021 | 2be0071f | bellard | case PPC_FLAGS_EXCP_970:
|
2022 | 2be0071f | bellard | /* Thermal exception on 970 */
|
2023 | 2be0071f | bellard | /* XXX: TODO */
|
2024 | 2be0071f | bellard | cpu_abort(env, "970 thermal management exception "
|
2025 | 2be0071f | bellard | "is not implemented yet !\n");
|
2026 | 2be0071f | bellard | goto store_next;
|
2027 | 2be0071f | bellard | default:
|
2028 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1800 !\n");
|
2029 | 2be0071f | bellard | break;
|
2030 | 2be0071f | bellard | } |
2031 | 2be0071f | bellard | return;
|
2032 | 2be0071f | bellard | case 0x2000: |
2033 | 2be0071f | bellard | switch (PPC_EXCP(env)) {
|
2034 | 2be0071f | bellard | case PPC_FLAGS_EXCP_40x:
|
2035 | 2be0071f | bellard | /* DEBUG on 4xx */
|
2036 | 2be0071f | bellard | /* XXX: TODO */
|
2037 | 2be0071f | bellard | cpu_abort(env, "40x debug exception is not implemented yet !\n");
|
2038 | 2be0071f | bellard | goto store_next;
|
2039 | 2be0071f | bellard | case PPC_FLAGS_EXCP_601:
|
2040 | 2be0071f | bellard | /* Run mode exception on 601 */
|
2041 | 2be0071f | bellard | /* XXX: TODO */
|
2042 | 2be0071f | bellard | cpu_abort(env, |
2043 | 2be0071f | bellard | "601 run mode exception is not implemented yet !\n");
|
2044 | 2be0071f | bellard | goto store_next;
|
2045 | c62db105 | j_mayer | case PPC_FLAGS_EXCP_BOOKE:
|
2046 | c62db105 | j_mayer | srr_0 = &env->spr[SPR_BOOKE_CSRR0]; |
2047 | c62db105 | j_mayer | srr_1 = &env->spr[SPR_BOOKE_CSRR1]; |
2048 | c62db105 | j_mayer | break;
|
2049 | 2be0071f | bellard | default:
|
2050 | 2be0071f | bellard | cpu_abort(env, "Invalid exception 0x1800 !\n");
|
2051 | 2be0071f | bellard | break;
|
2052 | 2be0071f | bellard | } |
2053 | 2be0071f | bellard | return;
|
2054 | 2be0071f | bellard | /* Other exceptions */
|
2055 | 2be0071f | bellard | /* Qemu internal exceptions:
|
2056 | 2be0071f | bellard | * we should never come here with those values: abort execution
|
2057 | 2be0071f | bellard | */
|
2058 | 2be0071f | bellard | default:
|
2059 | 2be0071f | bellard | cpu_abort(env, "Invalid exception: code %d (%04x)\n", excp, excp);
|
2060 | 9a64fbe4 | bellard | return;
|
2061 | 9a64fbe4 | bellard | store_current:
|
2062 | 2be0071f | bellard | /* save current instruction location */
|
2063 | c62db105 | j_mayer | *srr_0 = env->nip - 4;
|
2064 | 9a64fbe4 | bellard | break;
|
2065 | 9a64fbe4 | bellard | store_next:
|
2066 | 2be0071f | bellard | /* save next instruction location */
|
2067 | c62db105 | j_mayer | *srr_0 = env->nip; |
2068 | 9a64fbe4 | bellard | break;
|
2069 | 9a64fbe4 | bellard | } |
2070 | 2be0071f | bellard | /* Save msr */
|
2071 | 2be0071f | bellard | *srr_1 = msr; |
2072 | c62db105 | j_mayer | if (asrr_0 != NULL) |
2073 | c62db105 | j_mayer | *asrr_0 = *srr_0; |
2074 | c62db105 | j_mayer | if (asrr_1 != NULL) |
2075 | c62db105 | j_mayer | *asrr_1 = *srr_1; |
2076 | 2be0071f | bellard | /* If we disactivated any translation, flush TLBs */
|
2077 | 2be0071f | bellard | if (msr_ir || msr_dr) {
|
2078 | 2be0071f | bellard | tlb_flush(env, 1);
|
2079 | 2be0071f | bellard | } |
2080 | 9a64fbe4 | bellard | /* reload MSR with correct bits */
|
2081 | 9a64fbe4 | bellard | msr_ee = 0;
|
2082 | 9a64fbe4 | bellard | msr_pr = 0;
|
2083 | 9a64fbe4 | bellard | msr_fp = 0;
|
2084 | 9a64fbe4 | bellard | msr_fe0 = 0;
|
2085 | 9a64fbe4 | bellard | msr_se = 0;
|
2086 | 9a64fbe4 | bellard | msr_be = 0;
|
2087 | 9a64fbe4 | bellard | msr_fe1 = 0;
|
2088 | 9a64fbe4 | bellard | msr_ir = 0;
|
2089 | 9a64fbe4 | bellard | msr_dr = 0;
|
2090 | 9a64fbe4 | bellard | msr_ri = 0;
|
2091 | 9a64fbe4 | bellard | msr_le = msr_ile; |
2092 | c62db105 | j_mayer | if (PPC_EXCP(env) == PPC_FLAGS_EXCP_BOOKE) {
|
2093 | c62db105 | j_mayer | msr_cm = msr_icm; |
2094 | c62db105 | j_mayer | if (idx == -1 || (idx >= 16 && idx < 32)) { |
2095 | c62db105 | j_mayer | cpu_abort(env, "Invalid exception index for excp %d %08x idx %d\n",
|
2096 | c62db105 | j_mayer | excp, excp, idx); |
2097 | c62db105 | j_mayer | } |
2098 | c62db105 | j_mayer | #if defined(TARGET_PPC64)
|
2099 | c62db105 | j_mayer | if (msr_cm)
|
2100 | c62db105 | j_mayer | env->nip = (uint64_t)env->spr[SPR_BOOKE_IVPR]; |
2101 | c62db105 | j_mayer | else
|
2102 | c62db105 | j_mayer | #endif
|
2103 | c62db105 | j_mayer | env->nip = (uint32_t)env->spr[SPR_BOOKE_IVPR]; |
2104 | c62db105 | j_mayer | if (idx < 16) |
2105 | c62db105 | j_mayer | env->nip |= env->spr[SPR_BOOKE_IVOR0 + idx]; |
2106 | c62db105 | j_mayer | else if (idx < 38) |
2107 | c62db105 | j_mayer | env->nip |= env->spr[SPR_BOOKE_IVOR32 + idx - 32];
|
2108 | c62db105 | j_mayer | } else {
|
2109 | c62db105 | j_mayer | msr_sf = msr_isf; |
2110 | c62db105 | j_mayer | env->nip = excp; |
2111 | c62db105 | j_mayer | } |
2112 | 3fc6c082 | bellard | do_compute_hflags(env); |
2113 | 9a64fbe4 | bellard | /* Jump to handler */
|
2114 | 9a64fbe4 | bellard | env->exception_index = EXCP_NONE; |
2115 | fb0eaffc | bellard | } |
2116 | 47103572 | j_mayer | |
2117 | e9df014c | j_mayer | void ppc_hw_interrupt (CPUPPCState *env)
|
2118 | 47103572 | j_mayer | { |
2119 | 47103572 | j_mayer | int raised = 0; |
2120 | 47103572 | j_mayer | |
2121 | a496775f | j_mayer | #if 1 |
2122 | a496775f | j_mayer | if (loglevel & CPU_LOG_INT) {
|
2123 | a496775f | j_mayer | fprintf(logfile, "%s: %p pending %08x req %08x me %d ee %d\n",
|
2124 | a496775f | j_mayer | __func__, env, env->pending_interrupts, |
2125 | a496775f | j_mayer | env->interrupt_request, msr_me, msr_ee); |
2126 | a496775f | j_mayer | } |
2127 | 47103572 | j_mayer | #endif
|
2128 | 47103572 | j_mayer | /* Raise it */
|
2129 | 47103572 | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_RESET)) { |
2130 | 47103572 | j_mayer | /* External reset / critical input */
|
2131 | e9df014c | j_mayer | /* XXX: critical input should be handled another way.
|
2132 | e9df014c | j_mayer | * This code is not correct !
|
2133 | e9df014c | j_mayer | */
|
2134 | 47103572 | j_mayer | env->exception_index = EXCP_RESET; |
2135 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_RESET);
|
2136 | 47103572 | j_mayer | raised = 1;
|
2137 | 47103572 | j_mayer | } |
2138 | 47103572 | j_mayer | if (raised == 0 && msr_me != 0) { |
2139 | 47103572 | j_mayer | /* Machine check exception */
|
2140 | 47103572 | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_MCK)) { |
2141 | 47103572 | j_mayer | env->exception_index = EXCP_MACHINE_CHECK; |
2142 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_MCK);
|
2143 | 47103572 | j_mayer | raised = 1;
|
2144 | 47103572 | j_mayer | } |
2145 | 47103572 | j_mayer | } |
2146 | 47103572 | j_mayer | if (raised == 0 && msr_ee != 0) { |
2147 | 47103572 | j_mayer | #if defined(TARGET_PPC64H) /* PowerPC 64 with hypervisor mode support */ |
2148 | 47103572 | j_mayer | /* Hypervisor decrementer exception */
|
2149 | 47103572 | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_HDECR)) { |
2150 | 47103572 | j_mayer | env->exception_index = EXCP_HDECR; |
2151 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_HDECR);
|
2152 | 47103572 | j_mayer | raised = 1;
|
2153 | 47103572 | j_mayer | } else
|
2154 | 47103572 | j_mayer | #endif
|
2155 | 47103572 | j_mayer | /* Decrementer exception */
|
2156 | 47103572 | j_mayer | if (env->pending_interrupts & (1 << PPC_INTERRUPT_DECR)) { |
2157 | 47103572 | j_mayer | env->exception_index = EXCP_DECR; |
2158 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DECR);
|
2159 | 47103572 | j_mayer | raised = 1;
|
2160 | 47103572 | j_mayer | /* Programmable interval timer on embedded PowerPC */
|
2161 | 47103572 | j_mayer | } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_PIT)) { |
2162 | 47103572 | j_mayer | env->exception_index = EXCP_40x_PIT; |
2163 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PIT);
|
2164 | 47103572 | j_mayer | raised = 1;
|
2165 | 47103572 | j_mayer | /* Fixed interval timer on embedded PowerPC */
|
2166 | 47103572 | j_mayer | } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_FIT)) { |
2167 | 47103572 | j_mayer | env->exception_index = EXCP_40x_FIT; |
2168 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_FIT);
|
2169 | 47103572 | j_mayer | raised = 1;
|
2170 | 47103572 | j_mayer | /* Watchdog timer on embedded PowerPC */
|
2171 | 47103572 | j_mayer | } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_WDT)) { |
2172 | 47103572 | j_mayer | env->exception_index = EXCP_40x_WATCHDOG; |
2173 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_WDT);
|
2174 | 47103572 | j_mayer | raised = 1;
|
2175 | 47103572 | j_mayer | /* External interrupt */
|
2176 | 47103572 | j_mayer | } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_EXT)) { |
2177 | 47103572 | j_mayer | env->exception_index = EXCP_EXTERNAL; |
2178 | e9df014c | j_mayer | /* Taking an external interrupt does not clear the external
|
2179 | e9df014c | j_mayer | * interrupt status
|
2180 | e9df014c | j_mayer | */
|
2181 | e9df014c | j_mayer | #if 0
|
2182 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_EXT);
|
2183 | e9df014c | j_mayer | #endif
|
2184 | 47103572 | j_mayer | raised = 1;
|
2185 | d0dfae6e | j_mayer | #if 0 // TODO
|
2186 | d0dfae6e | j_mayer | /* Thermal interrupt */
|
2187 | d0dfae6e | j_mayer | } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_THERM)) {
|
2188 | d0dfae6e | j_mayer | env->exception_index = EXCP_970_THRM;
|
2189 | d0dfae6e | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_THERM);
|
2190 | d0dfae6e | j_mayer | raised = 1;
|
2191 | d0dfae6e | j_mayer | #endif
|
2192 | 47103572 | j_mayer | } |
2193 | 47103572 | j_mayer | #if 0 // TODO
|
2194 | 47103572 | j_mayer | /* External debug exception */
|
2195 | 47103572 | j_mayer | } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_DEBUG)) {
|
2196 | 47103572 | j_mayer | env->exception_index = EXCP_xxx;
|
2197 | 47103572 | j_mayer | env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DEBUG);
|
2198 | 47103572 | j_mayer | raised = 1;
|
2199 | 47103572 | j_mayer | #endif
|
2200 | 47103572 | j_mayer | } |
2201 | 47103572 | j_mayer | if (raised != 0) { |
2202 | 47103572 | j_mayer | env->error_code = 0;
|
2203 | 47103572 | j_mayer | do_interrupt(env); |
2204 | 47103572 | j_mayer | } |
2205 | 47103572 | j_mayer | } |
2206 | 18fba28c | bellard | #endif /* !CONFIG_USER_ONLY */ |
2207 | a496775f | j_mayer | |
2208 | a496775f | j_mayer | void cpu_dump_EA (target_ulong EA)
|
2209 | a496775f | j_mayer | { |
2210 | a496775f | j_mayer | FILE *f; |
2211 | a496775f | j_mayer | |
2212 | a496775f | j_mayer | if (logfile) {
|
2213 | a496775f | j_mayer | f = logfile; |
2214 | a496775f | j_mayer | } else {
|
2215 | a496775f | j_mayer | f = stdout; |
2216 | a496775f | j_mayer | return;
|
2217 | a496775f | j_mayer | } |
2218 | 4a057712 | j_mayer | fprintf(f, "Memory access at address " ADDRX "\n", EA); |
2219 | 4a057712 | j_mayer | } |
2220 | 4a057712 | j_mayer | |
2221 | 4a057712 | j_mayer | void cpu_dump_rfi (target_ulong RA, target_ulong msr)
|
2222 | 4a057712 | j_mayer | { |
2223 | 4a057712 | j_mayer | FILE *f; |
2224 | 4a057712 | j_mayer | |
2225 | 4a057712 | j_mayer | if (logfile) {
|
2226 | 4a057712 | j_mayer | f = logfile; |
2227 | 4a057712 | j_mayer | } else {
|
2228 | 4a057712 | j_mayer | f = stdout; |
2229 | 4a057712 | j_mayer | return;
|
2230 | 4a057712 | j_mayer | } |
2231 | 4a057712 | j_mayer | fprintf(f, "Return from exception at " ADDRX " with flags " ADDRX "\n", |
2232 | 4a057712 | j_mayer | RA, msr); |
2233 | a496775f | j_mayer | } |
2234 | a496775f | j_mayer | |
2235 | 0a032cbe | j_mayer | void cpu_ppc_reset (void *opaque) |
2236 | 0a032cbe | j_mayer | { |
2237 | 0a032cbe | j_mayer | CPUPPCState *env; |
2238 | 0a032cbe | j_mayer | |
2239 | 0a032cbe | j_mayer | env = opaque; |
2240 | 0a032cbe | j_mayer | #if defined (DO_SINGLE_STEP) && 0 |
2241 | 0a032cbe | j_mayer | /* Single step trace mode */
|
2242 | 0a032cbe | j_mayer | msr_se = 1;
|
2243 | 0a032cbe | j_mayer | msr_be = 1;
|
2244 | 0a032cbe | j_mayer | #endif
|
2245 | 0a032cbe | j_mayer | msr_fp = 1; /* Allow floating point exceptions */ |
2246 | 0a032cbe | j_mayer | msr_me = 1; /* Allow machine check exceptions */ |
2247 | 0a032cbe | j_mayer | #if defined(TARGET_PPC64)
|
2248 | 0a032cbe | j_mayer | msr_sf = 0; /* Boot in 32 bits mode */ |
2249 | 0a032cbe | j_mayer | msr_cm = 0;
|
2250 | 0a032cbe | j_mayer | #endif
|
2251 | 0a032cbe | j_mayer | #if defined(CONFIG_USER_ONLY)
|
2252 | 0a032cbe | j_mayer | msr_pr = 1;
|
2253 | 0a032cbe | j_mayer | tlb_flush(env, 1);
|
2254 | 0a032cbe | j_mayer | #else
|
2255 | 0a032cbe | j_mayer | env->nip = 0xFFFFFFFC;
|
2256 | 0a032cbe | j_mayer | ppc_tlb_invalidate_all(env); |
2257 | 0a032cbe | j_mayer | #endif
|
2258 | 0a032cbe | j_mayer | do_compute_hflags(env); |
2259 | 0a032cbe | j_mayer | env->reserve = -1;
|
2260 | 0a032cbe | j_mayer | } |
2261 | 0a032cbe | j_mayer | |
2262 | 0a032cbe | j_mayer | CPUPPCState *cpu_ppc_init (void)
|
2263 | 0a032cbe | j_mayer | { |
2264 | 0a032cbe | j_mayer | CPUPPCState *env; |
2265 | 0a032cbe | j_mayer | |
2266 | 0a032cbe | j_mayer | env = qemu_mallocz(sizeof(CPUPPCState));
|
2267 | 0a032cbe | j_mayer | if (!env)
|
2268 | 0a032cbe | j_mayer | return NULL; |
2269 | 0a032cbe | j_mayer | cpu_exec_init(env); |
2270 | 0a032cbe | j_mayer | cpu_ppc_reset(env); |
2271 | 0a032cbe | j_mayer | |
2272 | 0a032cbe | j_mayer | return env;
|
2273 | 0a032cbe | j_mayer | } |
2274 | 0a032cbe | j_mayer | |
2275 | 0a032cbe | j_mayer | void cpu_ppc_close (CPUPPCState *env)
|
2276 | 0a032cbe | j_mayer | { |
2277 | 0a032cbe | j_mayer | /* Should also remove all opcode tables... */
|
2278 | 0a032cbe | j_mayer | free(env); |
2279 | 0a032cbe | j_mayer | } |