2 * PowerPC emulation helpers for qemu.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 #include "helper_regs.h"
29 #include "qemu-common.h"
35 //#define DEBUG_SOFTWARE_TLB
36 //#define DUMP_PAGE_TABLES
37 //#define DEBUG_EXCEPTIONS
38 //#define FLUSH_ALL_TLBS
41 # define LOG_MMU(...) qemu_log(__VA_ARGS__)
42 # define LOG_MMU_STATE(env) log_cpu_state((env), 0)
44 # define LOG_MMU(...) do { } while (0)
45 # define LOG_MMU_STATE(...) do { } while (0)
49 #ifdef DEBUG_SOFTWARE_TLB
50 # define LOG_SWTLB(...) qemu_log(__VA_ARGS__)
52 # define LOG_SWTLB(...) do { } while (0)
56 # define LOG_BATS(...) qemu_log(__VA_ARGS__)
58 # define LOG_BATS(...) do { } while (0)
62 # define LOG_SLB(...) qemu_log(__VA_ARGS__)
64 # define LOG_SLB(...) do { } while (0)
67 #ifdef DEBUG_EXCEPTIONS
68 # define LOG_EXCP(...) qemu_log(__VA_ARGS__)
70 # define LOG_EXCP(...) do { } while (0)
74 /*****************************************************************************/
75 /* PowerPC MMU emulation */
77 #if defined(CONFIG_USER_ONLY)
78 int cpu_ppc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
79 int mmu_idx
, int is_softmmu
)
81 int exception
, error_code
;
84 exception
= POWERPC_EXCP_ISI
;
85 error_code
= 0x40000000;
87 exception
= POWERPC_EXCP_DSI
;
88 error_code
= 0x40000000;
90 error_code
|= 0x02000000;
91 env
->spr
[SPR_DAR
] = address
;
92 env
->spr
[SPR_DSISR
] = error_code
;
94 env
->exception_index
= exception
;
95 env
->error_code
= error_code
;
101 /* Common routines used by software and hardware TLBs emulation */
102 static inline int pte_is_valid(target_ulong pte0
)
104 return pte0
& 0x80000000 ? 1 : 0;
107 static inline void pte_invalidate(target_ulong
*pte0
)
109 *pte0
&= ~0x80000000;
112 #if defined(TARGET_PPC64)
113 static inline int pte64_is_valid(target_ulong pte0
)
115 return pte0
& 0x0000000000000001ULL
? 1 : 0;
118 static inline void pte64_invalidate(target_ulong
*pte0
)
120 *pte0
&= ~0x0000000000000001ULL
;
124 #define PTE_PTEM_MASK 0x7FFFFFBF
125 #define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B)
126 #if defined(TARGET_PPC64)
127 #define PTE64_PTEM_MASK 0xFFFFFFFFFFFFFF80ULL
128 #define PTE64_CHECK_MASK (TARGET_PAGE_MASK | 0x7F)
131 static inline int pp_check(int key
, int pp
, int nx
)
135 /* Compute access rights */
136 /* When pp is 3/7, the result is undefined. Set it to noaccess */
143 access
|= PAGE_WRITE
;
161 access
= PAGE_READ
| PAGE_WRITE
;
171 static inline int check_prot(int prot
, int rw
, int access_type
)
175 if (access_type
== ACCESS_CODE
) {
176 if (prot
& PAGE_EXEC
)
181 if (prot
& PAGE_WRITE
)
186 if (prot
& PAGE_READ
)
195 static inline int _pte_check(mmu_ctx_t
*ctx
, int is_64b
, target_ulong pte0
,
196 target_ulong pte1
, int h
, int rw
, int type
)
198 target_ulong ptem
, mmask
;
199 int access
, ret
, pteh
, ptev
, pp
;
203 /* Check validity and table match */
204 #if defined(TARGET_PPC64)
206 ptev
= pte64_is_valid(pte0
);
207 pteh
= (pte0
>> 1) & 1;
211 ptev
= pte_is_valid(pte0
);
212 pteh
= (pte0
>> 6) & 1;
214 if (ptev
&& h
== pteh
) {
215 /* Check vsid & api */
216 #if defined(TARGET_PPC64)
218 ptem
= pte0
& PTE64_PTEM_MASK
;
219 mmask
= PTE64_CHECK_MASK
;
220 pp
= (pte1
& 0x00000003) | ((pte1
>> 61) & 0x00000004);
221 ctx
->nx
= (pte1
>> 2) & 1; /* No execute bit */
222 ctx
->nx
|= (pte1
>> 3) & 1; /* Guarded bit */
226 ptem
= pte0
& PTE_PTEM_MASK
;
227 mmask
= PTE_CHECK_MASK
;
228 pp
= pte1
& 0x00000003;
230 if (ptem
== ctx
->ptem
) {
231 if (ctx
->raddr
!= (target_phys_addr_t
)-1ULL) {
232 /* all matches should have equal RPN, WIMG & PP */
233 if ((ctx
->raddr
& mmask
) != (pte1
& mmask
)) {
234 qemu_log("Bad RPN/WIMG/PP\n");
238 /* Compute access rights */
239 access
= pp_check(ctx
->key
, pp
, ctx
->nx
);
240 /* Keep the matching PTE informations */
243 ret
= check_prot(ctx
->prot
, rw
, type
);
246 LOG_MMU("PTE access granted !\n");
248 /* Access right violation */
249 LOG_MMU("PTE access rejected\n");
257 static inline int pte32_check(mmu_ctx_t
*ctx
, target_ulong pte0
,
258 target_ulong pte1
, int h
, int rw
, int type
)
260 return _pte_check(ctx
, 0, pte0
, pte1
, h
, rw
, type
);
263 #if defined(TARGET_PPC64)
264 static inline int pte64_check(mmu_ctx_t
*ctx
, target_ulong pte0
,
265 target_ulong pte1
, int h
, int rw
, int type
)
267 return _pte_check(ctx
, 1, pte0
, pte1
, h
, rw
, type
);
271 static inline int pte_update_flags(mmu_ctx_t
*ctx
, target_ulong
*pte1p
,
276 /* Update page flags */
277 if (!(*pte1p
& 0x00000100)) {
278 /* Update accessed flag */
279 *pte1p
|= 0x00000100;
282 if (!(*pte1p
& 0x00000080)) {
283 if (rw
== 1 && ret
== 0) {
284 /* Update changed flag */
285 *pte1p
|= 0x00000080;
288 /* Force page fault for first write access */
289 ctx
->prot
&= ~PAGE_WRITE
;
296 /* Software driven TLB helpers */
297 static inline int ppc6xx_tlb_getnum(CPUState
*env
, target_ulong eaddr
, int way
,
302 /* Select TLB num in a way from address */
303 nr
= (eaddr
>> TARGET_PAGE_BITS
) & (env
->tlb_per_way
- 1);
305 nr
+= env
->tlb_per_way
* way
;
306 /* 6xx have separate TLBs for instructions and data */
307 if (is_code
&& env
->id_tlbs
== 1)
313 static inline void ppc6xx_tlb_invalidate_all(CPUState
*env
)
318 //LOG_SWTLB("Invalidate all TLBs\n");
319 /* Invalidate all defined software TLB */
321 if (env
->id_tlbs
== 1)
323 for (nr
= 0; nr
< max
; nr
++) {
324 tlb
= &env
->tlb
[nr
].tlb6
;
325 pte_invalidate(&tlb
->pte0
);
330 static inline void __ppc6xx_tlb_invalidate_virt(CPUState
*env
,
332 int is_code
, int match_epn
)
334 #if !defined(FLUSH_ALL_TLBS)
338 /* Invalidate ITLB + DTLB, all ways */
339 for (way
= 0; way
< env
->nb_ways
; way
++) {
340 nr
= ppc6xx_tlb_getnum(env
, eaddr
, way
, is_code
);
341 tlb
= &env
->tlb
[nr
].tlb6
;
342 if (pte_is_valid(tlb
->pte0
) && (match_epn
== 0 || eaddr
== tlb
->EPN
)) {
343 LOG_SWTLB("TLB invalidate %d/%d " TARGET_FMT_lx
"\n", nr
,
345 pte_invalidate(&tlb
->pte0
);
346 tlb_flush_page(env
, tlb
->EPN
);
350 /* XXX: PowerPC specification say this is valid as well */
351 ppc6xx_tlb_invalidate_all(env
);
355 static inline void ppc6xx_tlb_invalidate_virt(CPUState
*env
,
356 target_ulong eaddr
, int is_code
)
358 __ppc6xx_tlb_invalidate_virt(env
, eaddr
, is_code
, 0);
361 void ppc6xx_tlb_store (CPUState
*env
, target_ulong EPN
, int way
, int is_code
,
362 target_ulong pte0
, target_ulong pte1
)
367 nr
= ppc6xx_tlb_getnum(env
, EPN
, way
, is_code
);
368 tlb
= &env
->tlb
[nr
].tlb6
;
369 LOG_SWTLB("Set TLB %d/%d EPN " TARGET_FMT_lx
" PTE0 " TARGET_FMT_lx
370 " PTE1 " TARGET_FMT_lx
"\n", nr
, env
->nb_tlb
, EPN
, pte0
, pte1
);
371 /* Invalidate any pending reference in Qemu for this virtual address */
372 __ppc6xx_tlb_invalidate_virt(env
, EPN
, is_code
, 1);
376 /* Store last way for LRU mechanism */
380 static inline int ppc6xx_tlb_check(CPUState
*env
, mmu_ctx_t
*ctx
,
381 target_ulong eaddr
, int rw
, int access_type
)
388 ret
= -1; /* No TLB found */
389 for (way
= 0; way
< env
->nb_ways
; way
++) {
390 nr
= ppc6xx_tlb_getnum(env
, eaddr
, way
,
391 access_type
== ACCESS_CODE
? 1 : 0);
392 tlb
= &env
->tlb
[nr
].tlb6
;
393 /* This test "emulates" the PTE index match for hardware TLBs */
394 if ((eaddr
& TARGET_PAGE_MASK
) != tlb
->EPN
) {
395 LOG_SWTLB("TLB %d/%d %s [" TARGET_FMT_lx
" " TARGET_FMT_lx
396 "] <> " TARGET_FMT_lx
"\n", nr
, env
->nb_tlb
,
397 pte_is_valid(tlb
->pte0
) ? "valid" : "inval",
398 tlb
->EPN
, tlb
->EPN
+ TARGET_PAGE_SIZE
, eaddr
);
401 LOG_SWTLB("TLB %d/%d %s " TARGET_FMT_lx
" <> " TARGET_FMT_lx
" "
402 TARGET_FMT_lx
" %c %c\n", nr
, env
->nb_tlb
,
403 pte_is_valid(tlb
->pte0
) ? "valid" : "inval",
404 tlb
->EPN
, eaddr
, tlb
->pte1
,
405 rw
? 'S' : 'L', access_type
== ACCESS_CODE
? 'I' : 'D');
406 switch (pte32_check(ctx
, tlb
->pte0
, tlb
->pte1
, 0, rw
, access_type
)) {
408 /* TLB inconsistency */
411 /* Access violation */
421 /* XXX: we should go on looping to check all TLBs consistency
422 * but we can speed-up the whole thing as the
423 * result would be undefined if TLBs are not consistent.
432 LOG_SWTLB("found TLB at addr " TARGET_FMT_plx
" prot=%01x ret=%d\n",
433 ctx
->raddr
& TARGET_PAGE_MASK
, ctx
->prot
, ret
);
434 /* Update page flags */
435 pte_update_flags(ctx
, &env
->tlb
[best
].tlb6
.pte1
, ret
, rw
);
441 /* Perform BAT hit & translation */
442 static inline void bat_size_prot(CPUState
*env
, target_ulong
*blp
, int *validp
,
443 int *protp
, target_ulong
*BATu
,
449 bl
= (*BATu
& 0x00001FFC) << 15;
452 if (((msr_pr
== 0) && (*BATu
& 0x00000002)) ||
453 ((msr_pr
!= 0) && (*BATu
& 0x00000001))) {
455 pp
= *BATl
& 0x00000003;
457 prot
= PAGE_READ
| PAGE_EXEC
;
467 static inline void bat_601_size_prot(CPUState
*env
, target_ulong
*blp
,
468 int *validp
, int *protp
,
469 target_ulong
*BATu
, target_ulong
*BATl
)
472 int key
, pp
, valid
, prot
;
474 bl
= (*BATl
& 0x0000003F) << 17;
475 LOG_BATS("b %02x ==> bl " TARGET_FMT_lx
" msk " TARGET_FMT_lx
"\n",
476 (uint8_t)(*BATl
& 0x0000003F), bl
, ~bl
);
478 valid
= (*BATl
>> 6) & 1;
480 pp
= *BATu
& 0x00000003;
482 key
= (*BATu
>> 3) & 1;
484 key
= (*BATu
>> 2) & 1;
485 prot
= pp_check(key
, pp
, 0);
492 static inline int get_bat(CPUState
*env
, mmu_ctx_t
*ctx
, target_ulong
virtual,
495 target_ulong
*BATlt
, *BATut
, *BATu
, *BATl
;
496 target_ulong base
, BEPIl
, BEPIu
, bl
;
500 LOG_BATS("%s: %cBAT v " TARGET_FMT_lx
"\n", __func__
,
501 type
== ACCESS_CODE
? 'I' : 'D', virtual);
504 BATlt
= env
->IBAT
[1];
505 BATut
= env
->IBAT
[0];
508 BATlt
= env
->DBAT
[1];
509 BATut
= env
->DBAT
[0];
512 base
= virtual & 0xFFFC0000;
513 for (i
= 0; i
< env
->nb_BATs
; i
++) {
516 BEPIu
= *BATu
& 0xF0000000;
517 BEPIl
= *BATu
& 0x0FFE0000;
518 if (unlikely(env
->mmu_model
== POWERPC_MMU_601
)) {
519 bat_601_size_prot(env
, &bl
, &valid
, &prot
, BATu
, BATl
);
521 bat_size_prot(env
, &bl
, &valid
, &prot
, BATu
, BATl
);
523 LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx
" BATu " TARGET_FMT_lx
524 " BATl " TARGET_FMT_lx
"\n", __func__
,
525 type
== ACCESS_CODE
? 'I' : 'D', i
, virtual, *BATu
, *BATl
);
526 if ((virtual & 0xF0000000) == BEPIu
&&
527 ((virtual & 0x0FFE0000) & ~bl
) == BEPIl
) {
530 /* Get physical address */
531 ctx
->raddr
= (*BATl
& 0xF0000000) |
532 ((virtual & 0x0FFE0000 & bl
) | (*BATl
& 0x0FFE0000)) |
533 (virtual & 0x0001F000);
534 /* Compute access rights */
536 ret
= check_prot(ctx
->prot
, rw
, type
);
538 LOG_BATS("BAT %d match: r " TARGET_FMT_plx
" prot=%c%c\n",
539 i
, ctx
->raddr
, ctx
->prot
& PAGE_READ
? 'R' : '-',
540 ctx
->prot
& PAGE_WRITE
? 'W' : '-');
546 #if defined(DEBUG_BATS)
547 if (qemu_log_enabled()) {
548 LOG_BATS("no BAT match for " TARGET_FMT_lx
":\n", virtual);
549 for (i
= 0; i
< 4; i
++) {
552 BEPIu
= *BATu
& 0xF0000000;
553 BEPIl
= *BATu
& 0x0FFE0000;
554 bl
= (*BATu
& 0x00001FFC) << 15;
555 LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx
" BATu " TARGET_FMT_lx
556 " BATl " TARGET_FMT_lx
" \n\t" TARGET_FMT_lx
" "
557 TARGET_FMT_lx
" " TARGET_FMT_lx
"\n",
558 __func__
, type
== ACCESS_CODE
? 'I' : 'D', i
, virtual,
559 *BATu
, *BATl
, BEPIu
, BEPIl
, bl
);
568 /* PTE table lookup */
569 static inline int _find_pte(mmu_ctx_t
*ctx
, int is_64b
, int h
, int rw
,
570 int type
, int target_page_bits
)
572 target_ulong base
, pte0
, pte1
;
576 ret
= -1; /* No entry found */
577 base
= ctx
->pg_addr
[h
];
578 for (i
= 0; i
< 8; i
++) {
579 #if defined(TARGET_PPC64)
581 pte0
= ldq_phys(base
+ (i
* 16));
582 pte1
= ldq_phys(base
+ (i
* 16) + 8);
584 /* We have a TLB that saves 4K pages, so let's
585 * split a huge page to 4k chunks */
586 if (target_page_bits
!= TARGET_PAGE_BITS
)
587 pte1
|= (ctx
->eaddr
& (( 1 << target_page_bits
) - 1))
590 r
= pte64_check(ctx
, pte0
, pte1
, h
, rw
, type
);
591 LOG_MMU("Load pte from " TARGET_FMT_lx
" => " TARGET_FMT_lx
" "
592 TARGET_FMT_lx
" %d %d %d " TARGET_FMT_lx
"\n",
593 base
+ (i
* 16), pte0
, pte1
, (int)(pte0
& 1), h
,
594 (int)((pte0
>> 1) & 1), ctx
->ptem
);
598 pte0
= ldl_phys(base
+ (i
* 8));
599 pte1
= ldl_phys(base
+ (i
* 8) + 4);
600 r
= pte32_check(ctx
, pte0
, pte1
, h
, rw
, type
);
601 LOG_MMU("Load pte from " TARGET_FMT_lx
" => " TARGET_FMT_lx
" "
602 TARGET_FMT_lx
" %d %d %d " TARGET_FMT_lx
"\n",
603 base
+ (i
* 8), pte0
, pte1
, (int)(pte0
>> 31), h
,
604 (int)((pte0
>> 6) & 1), ctx
->ptem
);
608 /* PTE inconsistency */
611 /* Access violation */
621 /* XXX: we should go on looping to check all PTEs consistency
622 * but if we can speed-up the whole thing as the
623 * result would be undefined if PTEs are not consistent.
632 LOG_MMU("found PTE at addr " TARGET_FMT_lx
" prot=%01x ret=%d\n",
633 ctx
->raddr
, ctx
->prot
, ret
);
634 /* Update page flags */
636 if (pte_update_flags(ctx
, &pte1
, ret
, rw
) == 1) {
637 #if defined(TARGET_PPC64)
639 stq_phys_notdirty(base
+ (good
* 16) + 8, pte1
);
643 stl_phys_notdirty(base
+ (good
* 8) + 4, pte1
);
651 static inline int find_pte32(mmu_ctx_t
*ctx
, int h
, int rw
, int type
,
652 int target_page_bits
)
654 return _find_pte(ctx
, 0, h
, rw
, type
, target_page_bits
);
657 #if defined(TARGET_PPC64)
658 static inline int find_pte64(mmu_ctx_t
*ctx
, int h
, int rw
, int type
,
659 int target_page_bits
)
661 return _find_pte(ctx
, 1, h
, rw
, type
, target_page_bits
);
665 static inline int find_pte(CPUState
*env
, mmu_ctx_t
*ctx
, int h
, int rw
,
666 int type
, int target_page_bits
)
668 #if defined(TARGET_PPC64)
669 if (env
->mmu_model
& POWERPC_MMU_64
)
670 return find_pte64(ctx
, h
, rw
, type
, target_page_bits
);
673 return find_pte32(ctx
, h
, rw
, type
, target_page_bits
);
676 #if defined(TARGET_PPC64)
677 static ppc_slb_t
*slb_get_entry(CPUPPCState
*env
, int nr
)
679 ppc_slb_t
*retval
= &env
->slb
[nr
];
681 #if 0 // XXX implement bridge mode?
682 if (env
->spr
[SPR_ASR
] & 1) {
683 target_phys_addr_t sr_base
;
685 sr_base
= env
->spr
[SPR_ASR
] & 0xfffffffffffff000;
686 sr_base
+= (12 * nr
);
688 retval
->tmp64
= ldq_phys(sr_base
);
689 retval
->tmp
= ldl_phys(sr_base
+ 8);
696 static void slb_set_entry(CPUPPCState
*env
, int nr
, ppc_slb_t
*slb
)
698 ppc_slb_t
*entry
= &env
->slb
[nr
];
703 entry
->tmp64
= slb
->tmp64
;
704 entry
->tmp
= slb
->tmp
;
707 static inline int slb_is_valid(ppc_slb_t
*slb
)
709 return (int)(slb
->tmp64
& 0x0000000008000000ULL
);
712 static inline void slb_invalidate(ppc_slb_t
*slb
)
714 slb
->tmp64
&= ~0x0000000008000000ULL
;
717 static inline int slb_lookup(CPUPPCState
*env
, target_ulong eaddr
,
718 target_ulong
*vsid
, target_ulong
*page_mask
,
719 int *attr
, int *target_page_bits
)
725 LOG_SLB("%s: eaddr " TARGET_FMT_lx
"\n", __func__
, eaddr
);
726 mask
= 0x0000000000000000ULL
; /* Avoid gcc warning */
727 for (n
= 0; n
< env
->slb_nr
; n
++) {
728 ppc_slb_t
*slb
= slb_get_entry(env
, n
);
730 LOG_SLB("%s: seg %d %016" PRIx64
" %08"
731 PRIx32
"\n", __func__
, n
, slb
->tmp64
, slb
->tmp
);
732 if (slb_is_valid(slb
)) {
733 /* SLB entry is valid */
734 mask
= 0xFFFFFFFFF0000000ULL
;
735 if (slb
->tmp
& 0x8) {
737 if (target_page_bits
)
738 *target_page_bits
= 24;
741 if (target_page_bits
)
742 *target_page_bits
= TARGET_PAGE_BITS
;
744 if ((eaddr
& mask
) == (slb
->tmp64
& mask
)) {
746 *vsid
= ((slb
->tmp64
<< 24) | (slb
->tmp
>> 8)) & 0x0003FFFFFFFFFFFFULL
;
748 *attr
= slb
->tmp
& 0xFF;
758 void ppc_slb_invalidate_all (CPUPPCState
*env
)
760 int n
, do_invalidate
;
763 /* XXX: Warning: slbia never invalidates the first segment */
764 for (n
= 1; n
< env
->slb_nr
; n
++) {
765 ppc_slb_t
*slb
= slb_get_entry(env
, n
);
767 if (slb_is_valid(slb
)) {
769 slb_set_entry(env
, n
, slb
);
770 /* XXX: given the fact that segment size is 256 MB or 1TB,
771 * and we still don't have a tlb_flush_mask(env, n, mask)
772 * in Qemu, we just invalidate all TLBs
781 void ppc_slb_invalidate_one (CPUPPCState
*env
, uint64_t T0
)
783 target_ulong vsid
, page_mask
;
787 n
= slb_lookup(env
, T0
, &vsid
, &page_mask
, &attr
, NULL
);
789 ppc_slb_t
*slb
= slb_get_entry(env
, n
);
791 if (slb_is_valid(slb
)) {
793 slb_set_entry(env
, n
, slb
);
794 /* XXX: given the fact that segment size is 256 MB or 1TB,
795 * and we still don't have a tlb_flush_mask(env, n, mask)
796 * in Qemu, we just invalidate all TLBs
803 target_ulong
ppc_load_slb (CPUPPCState
*env
, int slb_nr
)
806 ppc_slb_t
*slb
= slb_get_entry(env
, slb_nr
);
808 if (slb_is_valid(slb
)) {
809 /* SLB entry is valid */
810 /* Copy SLB bits 62:88 to Rt 37:63 (VSID 23:49) */
811 rt
= slb
->tmp
>> 8; /* 65:88 => 40:63 */
812 rt
|= (slb
->tmp64
& 0x7) << 24; /* 62:64 => 37:39 */
813 /* Copy SLB bits 89:92 to Rt 33:36 (KsKpNL) */
814 rt
|= ((slb
->tmp
>> 4) & 0xF) << 27;
818 LOG_SLB("%s: %016" PRIx64
" %08" PRIx32
" => %d "
819 TARGET_FMT_lx
"\n", __func__
, slb
->tmp64
, slb
->tmp
, slb_nr
, rt
);
824 void ppc_store_slb (CPUPPCState
*env
, target_ulong rb
, target_ulong rs
)
830 int flags
, valid
, slb_nr
;
833 flags
= ((rs
>> 8) & 0xf);
836 valid
= (rb
& (1 << 27));
839 slb
= slb_get_entry(env
, slb_nr
);
840 slb
->tmp64
= (esid
<< 28) | valid
| (vsid
>> 24);
841 slb
->tmp
= (vsid
<< 8) | (flags
<< 3);
843 LOG_SLB("%s: %d " TARGET_FMT_lx
" - " TARGET_FMT_lx
" => %016" PRIx64
844 " %08" PRIx32
"\n", __func__
, slb_nr
, rb
, rs
, slb
->tmp64
,
847 slb_set_entry(env
, slb_nr
, slb
);
849 #endif /* defined(TARGET_PPC64) */
851 /* Perform segment based translation */
852 static inline target_phys_addr_t
get_pgaddr(target_phys_addr_t sdr1
,
854 target_phys_addr_t hash
,
855 target_phys_addr_t mask
)
857 return (sdr1
& ((target_phys_addr_t
)(-1ULL) << sdr_sh
)) | (hash
& mask
);
860 static inline int get_segment(CPUState
*env
, mmu_ctx_t
*ctx
,
861 target_ulong eaddr
, int rw
, int type
)
863 target_phys_addr_t sdr
, hash
, mask
, sdr_mask
, htab_mask
;
864 target_ulong sr
, vsid
, vsid_mask
, pgidx
, page_mask
;
865 #if defined(TARGET_PPC64)
868 int ds
, vsid_sh
, sdr_sh
, pr
, target_page_bits
;
872 #if defined(TARGET_PPC64)
873 if (env
->mmu_model
& POWERPC_MMU_64
) {
874 LOG_MMU("Check SLBs\n");
875 ret
= slb_lookup(env
, eaddr
, &vsid
, &page_mask
, &attr
,
879 ctx
->key
= ((attr
& 0x40) && (pr
!= 0)) ||
880 ((attr
& 0x80) && (pr
== 0)) ? 1 : 0;
882 ctx
->nx
= attr
& 0x10 ? 1 : 0;
884 vsid_mask
= 0x00003FFFFFFFFF80ULL
;
889 #endif /* defined(TARGET_PPC64) */
891 sr
= env
->sr
[eaddr
>> 28];
892 page_mask
= 0x0FFFFFFF;
893 ctx
->key
= (((sr
& 0x20000000) && (pr
!= 0)) ||
894 ((sr
& 0x40000000) && (pr
== 0))) ? 1 : 0;
895 ds
= sr
& 0x80000000 ? 1 : 0;
896 ctx
->nx
= sr
& 0x10000000 ? 1 : 0;
897 vsid
= sr
& 0x00FFFFFF;
898 vsid_mask
= 0x01FFFFC0;
902 target_page_bits
= TARGET_PAGE_BITS
;
903 LOG_MMU("Check segment v=" TARGET_FMT_lx
" %d " TARGET_FMT_lx
" nip="
904 TARGET_FMT_lx
" lr=" TARGET_FMT_lx
905 " ir=%d dr=%d pr=%d %d t=%d\n",
906 eaddr
, (int)(eaddr
>> 28), sr
, env
->nip
, env
->lr
, (int)msr_ir
,
907 (int)msr_dr
, pr
!= 0 ? 1 : 0, rw
, type
);
909 LOG_MMU("pte segment: key=%d ds %d nx %d vsid " TARGET_FMT_lx
"\n",
910 ctx
->key
, ds
, ctx
->nx
, vsid
);
913 /* Check if instruction fetch is allowed, if needed */
914 if (type
!= ACCESS_CODE
|| ctx
->nx
== 0) {
915 /* Page address translation */
916 /* Primary table address */
918 pgidx
= (eaddr
& page_mask
) >> target_page_bits
;
919 #if defined(TARGET_PPC64)
920 if (env
->mmu_model
& POWERPC_MMU_64
) {
921 htab_mask
= 0x0FFFFFFF >> (28 - (sdr
& 0x1F));
922 /* XXX: this is false for 1 TB segments */
923 hash
= ((vsid
^ pgidx
) << vsid_sh
) & vsid_mask
;
927 htab_mask
= sdr
& 0x000001FF;
928 hash
= ((vsid
^ pgidx
) << vsid_sh
) & vsid_mask
;
930 mask
= (htab_mask
<< sdr_sh
) | sdr_mask
;
931 LOG_MMU("sdr " TARGET_FMT_plx
" sh %d hash " TARGET_FMT_plx
932 " mask " TARGET_FMT_plx
" " TARGET_FMT_lx
"\n",
933 sdr
, sdr_sh
, hash
, mask
, page_mask
);
934 ctx
->pg_addr
[0] = get_pgaddr(sdr
, sdr_sh
, hash
, mask
);
935 /* Secondary table address */
936 hash
= (~hash
) & vsid_mask
;
937 LOG_MMU("sdr " TARGET_FMT_plx
" sh %d hash " TARGET_FMT_plx
938 " mask " TARGET_FMT_plx
"\n", sdr
, sdr_sh
, hash
, mask
);
939 ctx
->pg_addr
[1] = get_pgaddr(sdr
, sdr_sh
, hash
, mask
);
940 #if defined(TARGET_PPC64)
941 if (env
->mmu_model
& POWERPC_MMU_64
) {
942 /* Only 5 bits of the page index are used in the AVPN */
943 if (target_page_bits
> 23) {
944 ctx
->ptem
= (vsid
<< 12) |
945 ((pgidx
<< (target_page_bits
- 16)) & 0xF80);
947 ctx
->ptem
= (vsid
<< 12) | ((pgidx
>> 4) & 0x0F80);
952 ctx
->ptem
= (vsid
<< 7) | (pgidx
>> 10);
954 /* Initialize real address with an invalid value */
955 ctx
->raddr
= (target_phys_addr_t
)-1ULL;
956 if (unlikely(env
->mmu_model
== POWERPC_MMU_SOFT_6xx
||
957 env
->mmu_model
== POWERPC_MMU_SOFT_74xx
)) {
958 /* Software TLB search */
959 ret
= ppc6xx_tlb_check(env
, ctx
, eaddr
, rw
, type
);
961 LOG_MMU("0 sdr1=" TARGET_FMT_plx
" vsid=" TARGET_FMT_lx
" "
962 "api=" TARGET_FMT_lx
" hash=" TARGET_FMT_plx
963 " pg_addr=" TARGET_FMT_plx
"\n",
964 sdr
, vsid
, pgidx
, hash
, ctx
->pg_addr
[0]);
965 /* Primary table lookup */
966 ret
= find_pte(env
, ctx
, 0, rw
, type
, target_page_bits
);
968 /* Secondary table lookup */
969 if (eaddr
!= 0xEFFFFFFF)
970 LOG_MMU("1 sdr1=" TARGET_FMT_plx
" vsid=" TARGET_FMT_lx
" "
971 "api=" TARGET_FMT_lx
" hash=" TARGET_FMT_plx
972 " pg_addr=" TARGET_FMT_plx
"\n", sdr
, vsid
,
973 pgidx
, hash
, ctx
->pg_addr
[1]);
974 ret2
= find_pte(env
, ctx
, 1, rw
, type
,
980 #if defined (DUMP_PAGE_TABLES)
981 if (qemu_log_enabled()) {
982 target_phys_addr_t curaddr
;
983 uint32_t a0
, a1
, a2
, a3
;
984 qemu_log("Page table: " TARGET_FMT_plx
" len " TARGET_FMT_plx
985 "\n", sdr
, mask
+ 0x80);
986 for (curaddr
= sdr
; curaddr
< (sdr
+ mask
+ 0x80);
988 a0
= ldl_phys(curaddr
);
989 a1
= ldl_phys(curaddr
+ 4);
990 a2
= ldl_phys(curaddr
+ 8);
991 a3
= ldl_phys(curaddr
+ 12);
992 if (a0
!= 0 || a1
!= 0 || a2
!= 0 || a3
!= 0) {
993 qemu_log(TARGET_FMT_plx
": %08x %08x %08x %08x\n",
994 curaddr
, a0
, a1
, a2
, a3
);
1000 LOG_MMU("No access allowed\n");
1004 LOG_MMU("direct store...\n");
1005 /* Direct-store segment : absolutely *BUGGY* for now */
1008 /* Integer load/store : only access allowed */
1011 /* No code fetch is allowed in direct-store areas */
1014 /* Floating point load/store */
1017 /* lwarx, ldarx or srwcx. */
1020 /* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi */
1021 /* Should make the instruction do no-op.
1022 * As it already do no-op, it's quite easy :-)
1027 /* eciwx or ecowx */
1030 qemu_log("ERROR: instruction should not need "
1031 "address translation\n");
1034 if ((rw
== 1 || ctx
->key
!= 1) && (rw
== 0 || ctx
->key
!= 0)) {
1045 /* Generic TLB check function for embedded PowerPC implementations */
1046 static inline int ppcemb_tlb_check(CPUState
*env
, ppcemb_tlb_t
*tlb
,
1047 target_phys_addr_t
*raddrp
,
1048 target_ulong address
, uint32_t pid
, int ext
,
1053 /* Check valid flag */
1054 if (!(tlb
->prot
& PAGE_VALID
)) {
1055 qemu_log("%s: TLB %d not valid\n", __func__
, i
);
1058 mask
= ~(tlb
->size
- 1);
1059 LOG_SWTLB("%s: TLB %d address " TARGET_FMT_lx
" PID %u <=> " TARGET_FMT_lx
1060 " " TARGET_FMT_lx
" %u\n", __func__
, i
, address
, pid
, tlb
->EPN
,
1061 mask
, (uint32_t)tlb
->PID
);
1063 if (tlb
->PID
!= 0 && tlb
->PID
!= pid
)
1065 /* Check effective address */
1066 if ((address
& mask
) != tlb
->EPN
)
1068 *raddrp
= (tlb
->RPN
& mask
) | (address
& ~mask
);
1069 #if (TARGET_PHYS_ADDR_BITS >= 36)
1071 /* Extend the physical address to 36 bits */
1072 *raddrp
|= (target_phys_addr_t
)(tlb
->RPN
& 0xF) << 32;
1079 /* Generic TLB search function for PowerPC embedded implementations */
1080 int ppcemb_tlb_search (CPUPPCState
*env
, target_ulong address
, uint32_t pid
)
1083 target_phys_addr_t raddr
;
1086 /* Default return value is no match */
1088 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1089 tlb
= &env
->tlb
[i
].tlbe
;
1090 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
, pid
, 0, i
) == 0) {
1099 /* Helpers specific to PowerPC 40x implementations */
1100 static inline void ppc4xx_tlb_invalidate_all(CPUState
*env
)
1105 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1106 tlb
= &env
->tlb
[i
].tlbe
;
1107 tlb
->prot
&= ~PAGE_VALID
;
1112 static inline void ppc4xx_tlb_invalidate_virt(CPUState
*env
,
1113 target_ulong eaddr
, uint32_t pid
)
1115 #if !defined(FLUSH_ALL_TLBS)
1117 target_phys_addr_t raddr
;
1118 target_ulong page
, end
;
1121 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1122 tlb
= &env
->tlb
[i
].tlbe
;
1123 if (ppcemb_tlb_check(env
, tlb
, &raddr
, eaddr
, pid
, 0, i
) == 0) {
1124 end
= tlb
->EPN
+ tlb
->size
;
1125 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
1126 tlb_flush_page(env
, page
);
1127 tlb
->prot
&= ~PAGE_VALID
;
1132 ppc4xx_tlb_invalidate_all(env
);
1136 static int mmu40x_get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
,
1137 target_ulong address
, int rw
, int access_type
)
1140 target_phys_addr_t raddr
;
1141 int i
, ret
, zsel
, zpr
, pr
;
1144 raddr
= (target_phys_addr_t
)-1ULL;
1146 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1147 tlb
= &env
->tlb
[i
].tlbe
;
1148 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
,
1149 env
->spr
[SPR_40x_PID
], 0, i
) < 0)
1151 zsel
= (tlb
->attr
>> 4) & 0xF;
1152 zpr
= (env
->spr
[SPR_40x_ZPR
] >> (30 - (2 * zsel
))) & 0x3;
1153 LOG_SWTLB("%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",
1154 __func__
, i
, zsel
, zpr
, rw
, tlb
->attr
);
1155 /* Check execute enable bit */
1162 /* All accesses granted */
1163 ctx
->prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
1168 /* Raise Zone protection fault. */
1169 env
->spr
[SPR_40x_ESR
] = 1 << 22;
1177 /* Check from TLB entry */
1178 /* XXX: there is a problem here or in the TLB fill code... */
1179 ctx
->prot
= tlb
->prot
;
1180 ctx
->prot
|= PAGE_EXEC
;
1181 ret
= check_prot(ctx
->prot
, rw
, access_type
);
1183 env
->spr
[SPR_40x_ESR
] = 0;
1188 LOG_SWTLB("%s: access granted " TARGET_FMT_lx
" => " TARGET_FMT_plx
1189 " %d %d\n", __func__
, address
, ctx
->raddr
, ctx
->prot
,
1194 LOG_SWTLB("%s: access refused " TARGET_FMT_lx
" => " TARGET_FMT_plx
1195 " %d %d\n", __func__
, address
, raddr
, ctx
->prot
, ret
);
1200 void store_40x_sler (CPUPPCState
*env
, uint32_t val
)
1202 /* XXX: TO BE FIXED */
1203 if (val
!= 0x00000000) {
1204 cpu_abort(env
, "Little-endian regions are not supported by now\n");
1206 env
->spr
[SPR_405_SLER
] = val
;
1209 static int mmubooke_get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
,
1210 target_ulong address
, int rw
,
1214 target_phys_addr_t raddr
;
1218 raddr
= (target_phys_addr_t
)-1ULL;
1219 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1220 tlb
= &env
->tlb
[i
].tlbe
;
1221 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
,
1222 env
->spr
[SPR_BOOKE_PID
], 1, i
) < 0)
1225 prot
= tlb
->prot
& 0xF;
1227 prot
= (tlb
->prot
>> 4) & 0xF;
1228 /* Check the address space */
1229 if (access_type
== ACCESS_CODE
) {
1230 if (msr_ir
!= (tlb
->attr
& 1))
1233 if (prot
& PAGE_EXEC
) {
1239 if (msr_dr
!= (tlb
->attr
& 1))
1242 if ((!rw
&& prot
& PAGE_READ
) || (rw
&& (prot
& PAGE_WRITE
))) {
1255 static inline int check_physical(CPUState
*env
, mmu_ctx_t
*ctx
,
1256 target_ulong eaddr
, int rw
)
1261 ctx
->prot
= PAGE_READ
| PAGE_EXEC
;
1263 switch (env
->mmu_model
) {
1264 case POWERPC_MMU_32B
:
1265 case POWERPC_MMU_601
:
1266 case POWERPC_MMU_SOFT_6xx
:
1267 case POWERPC_MMU_SOFT_74xx
:
1268 case POWERPC_MMU_SOFT_4xx
:
1269 case POWERPC_MMU_REAL
:
1270 case POWERPC_MMU_BOOKE
:
1271 ctx
->prot
|= PAGE_WRITE
;
1273 #if defined(TARGET_PPC64)
1274 case POWERPC_MMU_620
:
1275 case POWERPC_MMU_64B
:
1276 /* Real address are 60 bits long */
1277 ctx
->raddr
&= 0x0FFFFFFFFFFFFFFFULL
;
1278 ctx
->prot
|= PAGE_WRITE
;
1281 case POWERPC_MMU_SOFT_4xx_Z
:
1282 if (unlikely(msr_pe
!= 0)) {
1283 /* 403 family add some particular protections,
1284 * using PBL/PBU registers for accesses with no translation.
1287 /* Check PLB validity */
1288 (env
->pb
[0] < env
->pb
[1] &&
1289 /* and address in plb area */
1290 eaddr
>= env
->pb
[0] && eaddr
< env
->pb
[1]) ||
1291 (env
->pb
[2] < env
->pb
[3] &&
1292 eaddr
>= env
->pb
[2] && eaddr
< env
->pb
[3]) ? 1 : 0;
1293 if (in_plb
^ msr_px
) {
1294 /* Access in protected area */
1296 /* Access is not allowed */
1300 /* Read-write access is allowed */
1301 ctx
->prot
|= PAGE_WRITE
;
1305 case POWERPC_MMU_MPC8xx
:
1307 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1309 case POWERPC_MMU_BOOKE_FSL
:
1311 cpu_abort(env
, "BookE FSL MMU model not implemented\n");
1314 cpu_abort(env
, "Unknown or invalid MMU model\n");
1321 int get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
, target_ulong eaddr
,
1322 int rw
, int access_type
)
1327 qemu_log("%s\n", __func__
);
1329 if ((access_type
== ACCESS_CODE
&& msr_ir
== 0) ||
1330 (access_type
!= ACCESS_CODE
&& msr_dr
== 0)) {
1331 /* No address translation */
1332 ret
= check_physical(env
, ctx
, eaddr
, rw
);
1335 switch (env
->mmu_model
) {
1336 case POWERPC_MMU_32B
:
1337 case POWERPC_MMU_601
:
1338 case POWERPC_MMU_SOFT_6xx
:
1339 case POWERPC_MMU_SOFT_74xx
:
1340 /* Try to find a BAT */
1341 if (env
->nb_BATs
!= 0)
1342 ret
= get_bat(env
, ctx
, eaddr
, rw
, access_type
);
1343 #if defined(TARGET_PPC64)
1344 case POWERPC_MMU_620
:
1345 case POWERPC_MMU_64B
:
1348 /* We didn't match any BAT entry or don't have BATs */
1349 ret
= get_segment(env
, ctx
, eaddr
, rw
, access_type
);
1352 case POWERPC_MMU_SOFT_4xx
:
1353 case POWERPC_MMU_SOFT_4xx_Z
:
1354 ret
= mmu40x_get_physical_address(env
, ctx
, eaddr
,
1357 case POWERPC_MMU_BOOKE
:
1358 ret
= mmubooke_get_physical_address(env
, ctx
, eaddr
,
1361 case POWERPC_MMU_MPC8xx
:
1363 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1365 case POWERPC_MMU_BOOKE_FSL
:
1367 cpu_abort(env
, "BookE FSL MMU model not implemented\n");
1369 case POWERPC_MMU_REAL
:
1370 cpu_abort(env
, "PowerPC in real mode do not do any translation\n");
1373 cpu_abort(env
, "Unknown or invalid MMU model\n");
1378 qemu_log("%s address " TARGET_FMT_lx
" => %d " TARGET_FMT_plx
"\n",
1379 __func__
, eaddr
, ret
, ctx
->raddr
);
1385 target_phys_addr_t
cpu_get_phys_page_debug (CPUState
*env
, target_ulong addr
)
1389 if (unlikely(get_physical_address(env
, &ctx
, addr
, 0, ACCESS_INT
) != 0))
1392 return ctx
.raddr
& TARGET_PAGE_MASK
;
1395 /* Perform address translation */
1396 int cpu_ppc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
1397 int mmu_idx
, int is_softmmu
)
1406 access_type
= ACCESS_CODE
;
1409 access_type
= env
->access_type
;
1411 ret
= get_physical_address(env
, &ctx
, address
, rw
, access_type
);
1413 tlb_set_page(env
, address
& TARGET_PAGE_MASK
,
1414 ctx
.raddr
& TARGET_PAGE_MASK
, ctx
.prot
,
1415 mmu_idx
, TARGET_PAGE_SIZE
);
1417 } else if (ret
< 0) {
1419 if (access_type
== ACCESS_CODE
) {
1422 /* No matches in page tables or TLB */
1423 switch (env
->mmu_model
) {
1424 case POWERPC_MMU_SOFT_6xx
:
1425 env
->exception_index
= POWERPC_EXCP_IFTLB
;
1426 env
->error_code
= 1 << 18;
1427 env
->spr
[SPR_IMISS
] = address
;
1428 env
->spr
[SPR_ICMP
] = 0x80000000 | ctx
.ptem
;
1430 case POWERPC_MMU_SOFT_74xx
:
1431 env
->exception_index
= POWERPC_EXCP_IFTLB
;
1433 case POWERPC_MMU_SOFT_4xx
:
1434 case POWERPC_MMU_SOFT_4xx_Z
:
1435 env
->exception_index
= POWERPC_EXCP_ITLB
;
1436 env
->error_code
= 0;
1437 env
->spr
[SPR_40x_DEAR
] = address
;
1438 env
->spr
[SPR_40x_ESR
] = 0x00000000;
1440 case POWERPC_MMU_32B
:
1441 case POWERPC_MMU_601
:
1442 #if defined(TARGET_PPC64)
1443 case POWERPC_MMU_620
:
1444 case POWERPC_MMU_64B
:
1446 env
->exception_index
= POWERPC_EXCP_ISI
;
1447 env
->error_code
= 0x40000000;
1449 case POWERPC_MMU_BOOKE
:
1451 cpu_abort(env
, "BookE MMU model is not implemented\n");
1453 case POWERPC_MMU_BOOKE_FSL
:
1455 cpu_abort(env
, "BookE FSL MMU model is not implemented\n");
1457 case POWERPC_MMU_MPC8xx
:
1459 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1461 case POWERPC_MMU_REAL
:
1462 cpu_abort(env
, "PowerPC in real mode should never raise "
1463 "any MMU exceptions\n");
1466 cpu_abort(env
, "Unknown or invalid MMU model\n");
1471 /* Access rights violation */
1472 env
->exception_index
= POWERPC_EXCP_ISI
;
1473 env
->error_code
= 0x08000000;
1476 /* No execute protection violation */
1477 env
->exception_index
= POWERPC_EXCP_ISI
;
1478 env
->error_code
= 0x10000000;
1481 /* Direct store exception */
1482 /* No code fetch is allowed in direct-store areas */
1483 env
->exception_index
= POWERPC_EXCP_ISI
;
1484 env
->error_code
= 0x10000000;
1486 #if defined(TARGET_PPC64)
1488 /* No match in segment table */
1489 if (env
->mmu_model
== POWERPC_MMU_620
) {
1490 env
->exception_index
= POWERPC_EXCP_ISI
;
1491 /* XXX: this might be incorrect */
1492 env
->error_code
= 0x40000000;
1494 env
->exception_index
= POWERPC_EXCP_ISEG
;
1495 env
->error_code
= 0;
1503 /* No matches in page tables or TLB */
1504 switch (env
->mmu_model
) {
1505 case POWERPC_MMU_SOFT_6xx
:
1507 env
->exception_index
= POWERPC_EXCP_DSTLB
;
1508 env
->error_code
= 1 << 16;
1510 env
->exception_index
= POWERPC_EXCP_DLTLB
;
1511 env
->error_code
= 0;
1513 env
->spr
[SPR_DMISS
] = address
;
1514 env
->spr
[SPR_DCMP
] = 0x80000000 | ctx
.ptem
;
1516 env
->error_code
|= ctx
.key
<< 19;
1517 env
->spr
[SPR_HASH1
] = ctx
.pg_addr
[0];
1518 env
->spr
[SPR_HASH2
] = ctx
.pg_addr
[1];
1520 case POWERPC_MMU_SOFT_74xx
:
1522 env
->exception_index
= POWERPC_EXCP_DSTLB
;
1524 env
->exception_index
= POWERPC_EXCP_DLTLB
;
1527 /* Implement LRU algorithm */
1528 env
->error_code
= ctx
.key
<< 19;
1529 env
->spr
[SPR_TLBMISS
] = (address
& ~((target_ulong
)0x3)) |
1530 ((env
->last_way
+ 1) & (env
->nb_ways
- 1));
1531 env
->spr
[SPR_PTEHI
] = 0x80000000 | ctx
.ptem
;
1533 case POWERPC_MMU_SOFT_4xx
:
1534 case POWERPC_MMU_SOFT_4xx_Z
:
1535 env
->exception_index
= POWERPC_EXCP_DTLB
;
1536 env
->error_code
= 0;
1537 env
->spr
[SPR_40x_DEAR
] = address
;
1539 env
->spr
[SPR_40x_ESR
] = 0x00800000;
1541 env
->spr
[SPR_40x_ESR
] = 0x00000000;
1543 case POWERPC_MMU_32B
:
1544 case POWERPC_MMU_601
:
1545 #if defined(TARGET_PPC64)
1546 case POWERPC_MMU_620
:
1547 case POWERPC_MMU_64B
:
1549 env
->exception_index
= POWERPC_EXCP_DSI
;
1550 env
->error_code
= 0;
1551 env
->spr
[SPR_DAR
] = address
;
1553 env
->spr
[SPR_DSISR
] = 0x42000000;
1555 env
->spr
[SPR_DSISR
] = 0x40000000;
1557 case POWERPC_MMU_MPC8xx
:
1559 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1561 case POWERPC_MMU_BOOKE
:
1563 cpu_abort(env
, "BookE MMU model is not implemented\n");
1565 case POWERPC_MMU_BOOKE_FSL
:
1567 cpu_abort(env
, "BookE FSL MMU model is not implemented\n");
1569 case POWERPC_MMU_REAL
:
1570 cpu_abort(env
, "PowerPC in real mode should never raise "
1571 "any MMU exceptions\n");
1574 cpu_abort(env
, "Unknown or invalid MMU model\n");
1579 /* Access rights violation */
1580 env
->exception_index
= POWERPC_EXCP_DSI
;
1581 env
->error_code
= 0;
1582 if (env
->mmu_model
== POWERPC_MMU_SOFT_4xx
1583 || env
->mmu_model
== POWERPC_MMU_SOFT_4xx_Z
) {
1584 env
->spr
[SPR_40x_DEAR
] = address
;
1586 env
->spr
[SPR_40x_ESR
] |= 0x00800000;
1589 env
->spr
[SPR_DAR
] = address
;
1591 env
->spr
[SPR_DSISR
] = 0x0A000000;
1593 env
->spr
[SPR_DSISR
] = 0x08000000;
1598 /* Direct store exception */
1599 switch (access_type
) {
1601 /* Floating point load/store */
1602 env
->exception_index
= POWERPC_EXCP_ALIGN
;
1603 env
->error_code
= POWERPC_EXCP_ALIGN_FP
;
1604 env
->spr
[SPR_DAR
] = address
;
1607 /* lwarx, ldarx or stwcx. */
1608 env
->exception_index
= POWERPC_EXCP_DSI
;
1609 env
->error_code
= 0;
1610 env
->spr
[SPR_DAR
] = address
;
1612 env
->spr
[SPR_DSISR
] = 0x06000000;
1614 env
->spr
[SPR_DSISR
] = 0x04000000;
1617 /* eciwx or ecowx */
1618 env
->exception_index
= POWERPC_EXCP_DSI
;
1619 env
->error_code
= 0;
1620 env
->spr
[SPR_DAR
] = address
;
1622 env
->spr
[SPR_DSISR
] = 0x06100000;
1624 env
->spr
[SPR_DSISR
] = 0x04100000;
1627 printf("DSI: invalid exception (%d)\n", ret
);
1628 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
1630 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
;
1631 env
->spr
[SPR_DAR
] = address
;
1635 #if defined(TARGET_PPC64)
1637 /* No match in segment table */
1638 if (env
->mmu_model
== POWERPC_MMU_620
) {
1639 env
->exception_index
= POWERPC_EXCP_DSI
;
1640 env
->error_code
= 0;
1641 env
->spr
[SPR_DAR
] = address
;
1642 /* XXX: this might be incorrect */
1644 env
->spr
[SPR_DSISR
] = 0x42000000;
1646 env
->spr
[SPR_DSISR
] = 0x40000000;
1648 env
->exception_index
= POWERPC_EXCP_DSEG
;
1649 env
->error_code
= 0;
1650 env
->spr
[SPR_DAR
] = address
;
1657 printf("%s: set exception to %d %02x\n", __func__
,
1658 env
->exception
, env
->error_code
);
1666 /*****************************************************************************/
1667 /* BATs management */
1668 #if !defined(FLUSH_ALL_TLBS)
1669 static inline void do_invalidate_BAT(CPUPPCState
*env
, target_ulong BATu
,
1672 target_ulong base
, end
, page
;
1674 base
= BATu
& ~0x0001FFFF;
1675 end
= base
+ mask
+ 0x00020000;
1676 LOG_BATS("Flush BAT from " TARGET_FMT_lx
" to " TARGET_FMT_lx
" ("
1677 TARGET_FMT_lx
")\n", base
, end
, mask
);
1678 for (page
= base
; page
!= end
; page
+= TARGET_PAGE_SIZE
)
1679 tlb_flush_page(env
, page
);
1680 LOG_BATS("Flush done\n");
1684 static inline void dump_store_bat(CPUPPCState
*env
, char ID
, int ul
, int nr
,
1687 LOG_BATS("Set %cBAT%d%c to " TARGET_FMT_lx
" (" TARGET_FMT_lx
")\n", ID
,
1688 nr
, ul
== 0 ? 'u' : 'l', value
, env
->nip
);
1691 void ppc_store_ibatu (CPUPPCState
*env
, int nr
, target_ulong value
)
1695 dump_store_bat(env
, 'I', 0, nr
, value
);
1696 if (env
->IBAT
[0][nr
] != value
) {
1697 mask
= (value
<< 15) & 0x0FFE0000UL
;
1698 #if !defined(FLUSH_ALL_TLBS)
1699 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1701 /* When storing valid upper BAT, mask BEPI and BRPN
1702 * and invalidate all TLBs covered by this BAT
1704 mask
= (value
<< 15) & 0x0FFE0000UL
;
1705 env
->IBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1706 (value
& ~0x0001FFFFUL
& ~mask
);
1707 env
->IBAT
[1][nr
] = (env
->IBAT
[1][nr
] & 0x0000007B) |
1708 (env
->IBAT
[1][nr
] & ~0x0001FFFF & ~mask
);
1709 #if !defined(FLUSH_ALL_TLBS)
1710 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1717 void ppc_store_ibatl (CPUPPCState
*env
, int nr
, target_ulong value
)
1719 dump_store_bat(env
, 'I', 1, nr
, value
);
1720 env
->IBAT
[1][nr
] = value
;
1723 void ppc_store_dbatu (CPUPPCState
*env
, int nr
, target_ulong value
)
1727 dump_store_bat(env
, 'D', 0, nr
, value
);
1728 if (env
->DBAT
[0][nr
] != value
) {
1729 /* When storing valid upper BAT, mask BEPI and BRPN
1730 * and invalidate all TLBs covered by this BAT
1732 mask
= (value
<< 15) & 0x0FFE0000UL
;
1733 #if !defined(FLUSH_ALL_TLBS)
1734 do_invalidate_BAT(env
, env
->DBAT
[0][nr
], mask
);
1736 mask
= (value
<< 15) & 0x0FFE0000UL
;
1737 env
->DBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1738 (value
& ~0x0001FFFFUL
& ~mask
);
1739 env
->DBAT
[1][nr
] = (env
->DBAT
[1][nr
] & 0x0000007B) |
1740 (env
->DBAT
[1][nr
] & ~0x0001FFFF & ~mask
);
1741 #if !defined(FLUSH_ALL_TLBS)
1742 do_invalidate_BAT(env
, env
->DBAT
[0][nr
], mask
);
1749 void ppc_store_dbatl (CPUPPCState
*env
, int nr
, target_ulong value
)
1751 dump_store_bat(env
, 'D', 1, nr
, value
);
1752 env
->DBAT
[1][nr
] = value
;
1755 void ppc_store_ibatu_601 (CPUPPCState
*env
, int nr
, target_ulong value
)
1760 dump_store_bat(env
, 'I', 0, nr
, value
);
1761 if (env
->IBAT
[0][nr
] != value
) {
1763 mask
= (env
->IBAT
[1][nr
] << 17) & 0x0FFE0000UL
;
1764 if (env
->IBAT
[1][nr
] & 0x40) {
1765 /* Invalidate BAT only if it is valid */
1766 #if !defined(FLUSH_ALL_TLBS)
1767 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1772 /* When storing valid upper BAT, mask BEPI and BRPN
1773 * and invalidate all TLBs covered by this BAT
1775 env
->IBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1776 (value
& ~0x0001FFFFUL
& ~mask
);
1777 env
->DBAT
[0][nr
] = env
->IBAT
[0][nr
];
1778 if (env
->IBAT
[1][nr
] & 0x40) {
1779 #if !defined(FLUSH_ALL_TLBS)
1780 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1785 #if defined(FLUSH_ALL_TLBS)
1792 void ppc_store_ibatl_601 (CPUPPCState
*env
, int nr
, target_ulong value
)
1797 dump_store_bat(env
, 'I', 1, nr
, value
);
1798 if (env
->IBAT
[1][nr
] != value
) {
1800 if (env
->IBAT
[1][nr
] & 0x40) {
1801 #if !defined(FLUSH_ALL_TLBS)
1802 mask
= (env
->IBAT
[1][nr
] << 17) & 0x0FFE0000UL
;
1803 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1809 #if !defined(FLUSH_ALL_TLBS)
1810 mask
= (value
<< 17) & 0x0FFE0000UL
;
1811 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1816 env
->IBAT
[1][nr
] = value
;
1817 env
->DBAT
[1][nr
] = value
;
1818 #if defined(FLUSH_ALL_TLBS)
1825 /*****************************************************************************/
1826 /* TLB management */
1827 void ppc_tlb_invalidate_all (CPUPPCState
*env
)
1829 switch (env
->mmu_model
) {
1830 case POWERPC_MMU_SOFT_6xx
:
1831 case POWERPC_MMU_SOFT_74xx
:
1832 ppc6xx_tlb_invalidate_all(env
);
1834 case POWERPC_MMU_SOFT_4xx
:
1835 case POWERPC_MMU_SOFT_4xx_Z
:
1836 ppc4xx_tlb_invalidate_all(env
);
1838 case POWERPC_MMU_REAL
:
1839 cpu_abort(env
, "No TLB for PowerPC 4xx in real mode\n");
1841 case POWERPC_MMU_MPC8xx
:
1843 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1845 case POWERPC_MMU_BOOKE
:
1847 cpu_abort(env
, "BookE MMU model is not implemented\n");
1849 case POWERPC_MMU_BOOKE_FSL
:
1852 cpu_abort(env
, "BookE MMU model is not implemented\n");
1854 case POWERPC_MMU_32B
:
1855 case POWERPC_MMU_601
:
1856 #if defined(TARGET_PPC64)
1857 case POWERPC_MMU_620
:
1858 case POWERPC_MMU_64B
:
1859 #endif /* defined(TARGET_PPC64) */
1864 cpu_abort(env
, "Unknown MMU model\n");
1869 void ppc_tlb_invalidate_one (CPUPPCState
*env
, target_ulong addr
)
1871 #if !defined(FLUSH_ALL_TLBS)
1872 addr
&= TARGET_PAGE_MASK
;
1873 switch (env
->mmu_model
) {
1874 case POWERPC_MMU_SOFT_6xx
:
1875 case POWERPC_MMU_SOFT_74xx
:
1876 ppc6xx_tlb_invalidate_virt(env
, addr
, 0);
1877 if (env
->id_tlbs
== 1)
1878 ppc6xx_tlb_invalidate_virt(env
, addr
, 1);
1880 case POWERPC_MMU_SOFT_4xx
:
1881 case POWERPC_MMU_SOFT_4xx_Z
:
1882 ppc4xx_tlb_invalidate_virt(env
, addr
, env
->spr
[SPR_40x_PID
]);
1884 case POWERPC_MMU_REAL
:
1885 cpu_abort(env
, "No TLB for PowerPC 4xx in real mode\n");
1887 case POWERPC_MMU_MPC8xx
:
1889 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1891 case POWERPC_MMU_BOOKE
:
1893 cpu_abort(env
, "BookE MMU model is not implemented\n");
1895 case POWERPC_MMU_BOOKE_FSL
:
1897 cpu_abort(env
, "BookE FSL MMU model is not implemented\n");
1899 case POWERPC_MMU_32B
:
1900 case POWERPC_MMU_601
:
1901 /* tlbie invalidate TLBs for all segments */
1902 addr
&= ~((target_ulong
)-1ULL << 28);
1903 /* XXX: this case should be optimized,
1904 * giving a mask to tlb_flush_page
1906 tlb_flush_page(env
, addr
| (0x0 << 28));
1907 tlb_flush_page(env
, addr
| (0x1 << 28));
1908 tlb_flush_page(env
, addr
| (0x2 << 28));
1909 tlb_flush_page(env
, addr
| (0x3 << 28));
1910 tlb_flush_page(env
, addr
| (0x4 << 28));
1911 tlb_flush_page(env
, addr
| (0x5 << 28));
1912 tlb_flush_page(env
, addr
| (0x6 << 28));
1913 tlb_flush_page(env
, addr
| (0x7 << 28));
1914 tlb_flush_page(env
, addr
| (0x8 << 28));
1915 tlb_flush_page(env
, addr
| (0x9 << 28));
1916 tlb_flush_page(env
, addr
| (0xA << 28));
1917 tlb_flush_page(env
, addr
| (0xB << 28));
1918 tlb_flush_page(env
, addr
| (0xC << 28));
1919 tlb_flush_page(env
, addr
| (0xD << 28));
1920 tlb_flush_page(env
, addr
| (0xE << 28));
1921 tlb_flush_page(env
, addr
| (0xF << 28));
1923 #if defined(TARGET_PPC64)
1924 case POWERPC_MMU_620
:
1925 case POWERPC_MMU_64B
:
1926 /* tlbie invalidate TLBs for all segments */
1927 /* XXX: given the fact that there are too many segments to invalidate,
1928 * and we still don't have a tlb_flush_mask(env, n, mask) in Qemu,
1929 * we just invalidate all TLBs
1933 #endif /* defined(TARGET_PPC64) */
1936 cpu_abort(env
, "Unknown MMU model\n");
1940 ppc_tlb_invalidate_all(env
);
1944 /*****************************************************************************/
1945 /* Special registers manipulation */
1946 #if defined(TARGET_PPC64)
1947 void ppc_store_asr (CPUPPCState
*env
, target_ulong value
)
1949 if (env
->asr
!= value
) {
1956 void ppc_store_sdr1 (CPUPPCState
*env
, target_ulong value
)
1958 LOG_MMU("%s: " TARGET_FMT_lx
"\n", __func__
, value
);
1959 if (env
->sdr1
!= value
) {
1960 /* XXX: for PowerPC 64, should check that the HTABSIZE value
1968 #if defined(TARGET_PPC64)
1969 target_ulong
ppc_load_sr (CPUPPCState
*env
, int slb_nr
)
1976 void ppc_store_sr (CPUPPCState
*env
, int srnum
, target_ulong value
)
1978 LOG_MMU("%s: reg=%d " TARGET_FMT_lx
" " TARGET_FMT_lx
"\n", __func__
,
1979 srnum
, value
, env
->sr
[srnum
]);
1980 #if defined(TARGET_PPC64)
1981 if (env
->mmu_model
& POWERPC_MMU_64
) {
1982 uint64_t rb
= 0, rs
= 0;
1985 rb
|= ((uint32_t)srnum
& 0xf) << 28;
1986 /* Set the valid bit */
1989 rb
|= (uint32_t)srnum
;
1992 rs
|= (value
& 0xfffffff) << 12;
1994 rs
|= ((value
>> 27) & 0xf) << 9;
1996 ppc_store_slb(env
, rb
, rs
);
1999 if (env
->sr
[srnum
] != value
) {
2000 env
->sr
[srnum
] = value
;
2001 /* Invalidating 256MB of virtual memory in 4kB pages is way longer than
2002 flusing the whole TLB. */
2003 #if !defined(FLUSH_ALL_TLBS) && 0
2005 target_ulong page
, end
;
2006 /* Invalidate 256 MB of virtual memory */
2007 page
= (16 << 20) * srnum
;
2008 end
= page
+ (16 << 20);
2009 for (; page
!= end
; page
+= TARGET_PAGE_SIZE
)
2010 tlb_flush_page(env
, page
);
2017 #endif /* !defined (CONFIG_USER_ONLY) */
2019 /* GDBstub can read and write MSR... */
2020 void ppc_store_msr (CPUPPCState
*env
, target_ulong value
)
2022 hreg_store_msr(env
, value
, 0);
2025 /*****************************************************************************/
2026 /* Exception processing */
2027 #if defined (CONFIG_USER_ONLY)
2028 void do_interrupt (CPUState
*env
)
2030 env
->exception_index
= POWERPC_EXCP_NONE
;
2031 env
->error_code
= 0;
2034 void ppc_hw_interrupt (CPUState
*env
)
2036 env
->exception_index
= POWERPC_EXCP_NONE
;
2037 env
->error_code
= 0;
2039 #else /* defined (CONFIG_USER_ONLY) */
2040 static inline void dump_syscall(CPUState
*env
)
2042 qemu_log_mask(CPU_LOG_INT
, "syscall r0=%016" PRIx64
" r3=%016" PRIx64
2043 " r4=%016" PRIx64
" r5=%016" PRIx64
" r6=%016" PRIx64
2044 " nip=" TARGET_FMT_lx
"\n",
2045 ppc_dump_gpr(env
, 0), ppc_dump_gpr(env
, 3),
2046 ppc_dump_gpr(env
, 4), ppc_dump_gpr(env
, 5),
2047 ppc_dump_gpr(env
, 6), env
->nip
);
2050 /* Note that this function should be greatly optimized
2051 * when called with a constant excp, from ppc_hw_interrupt
2053 static inline void powerpc_excp(CPUState
*env
, int excp_model
, int excp
)
2055 target_ulong msr
, new_msr
, vector
;
2056 int srr0
, srr1
, asrr0
, asrr1
;
2057 int lpes0
, lpes1
, lev
;
2060 /* XXX: find a suitable condition to enable the hypervisor mode */
2061 lpes0
= (env
->spr
[SPR_LPCR
] >> 1) & 1;
2062 lpes1
= (env
->spr
[SPR_LPCR
] >> 2) & 1;
2064 /* Those values ensure we won't enter the hypervisor mode */
2069 qemu_log_mask(CPU_LOG_INT
, "Raise exception at " TARGET_FMT_lx
2070 " => %08x (%02x)\n", env
->nip
, excp
, env
->error_code
);
2077 msr
&= ~((target_ulong
)0x783F0000);
2079 case POWERPC_EXCP_NONE
:
2080 /* Should never happen */
2082 case POWERPC_EXCP_CRITICAL
: /* Critical input */
2083 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2084 switch (excp_model
) {
2085 case POWERPC_EXCP_40x
:
2086 srr0
= SPR_40x_SRR2
;
2087 srr1
= SPR_40x_SRR3
;
2089 case POWERPC_EXCP_BOOKE
:
2090 srr0
= SPR_BOOKE_CSRR0
;
2091 srr1
= SPR_BOOKE_CSRR1
;
2093 case POWERPC_EXCP_G2
:
2099 case POWERPC_EXCP_MCHECK
: /* Machine check exception */
2101 /* Machine check exception is not enabled.
2102 * Enter checkstop state.
2104 if (qemu_log_enabled()) {
2105 qemu_log("Machine check while not allowed. "
2106 "Entering checkstop state\n");
2108 fprintf(stderr
, "Machine check while not allowed. "
2109 "Entering checkstop state\n");
2112 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
2114 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2115 new_msr
&= ~((target_ulong
)1 << MSR_ME
);
2117 /* XXX: find a suitable condition to enable the hypervisor mode */
2118 new_msr
|= (target_ulong
)MSR_HVB
;
2120 /* XXX: should also have something loaded in DAR / DSISR */
2121 switch (excp_model
) {
2122 case POWERPC_EXCP_40x
:
2123 srr0
= SPR_40x_SRR2
;
2124 srr1
= SPR_40x_SRR3
;
2126 case POWERPC_EXCP_BOOKE
:
2127 srr0
= SPR_BOOKE_MCSRR0
;
2128 srr1
= SPR_BOOKE_MCSRR1
;
2129 asrr0
= SPR_BOOKE_CSRR0
;
2130 asrr1
= SPR_BOOKE_CSRR1
;
2136 case POWERPC_EXCP_DSI
: /* Data storage exception */
2137 LOG_EXCP("DSI exception: DSISR=" TARGET_FMT_lx
" DAR=" TARGET_FMT_lx
2138 "\n", env
->spr
[SPR_DSISR
], env
->spr
[SPR_DAR
]);
2139 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2141 new_msr
|= (target_ulong
)MSR_HVB
;
2143 case POWERPC_EXCP_ISI
: /* Instruction storage exception */
2144 LOG_EXCP("ISI exception: msr=" TARGET_FMT_lx
", nip=" TARGET_FMT_lx
2145 "\n", msr
, env
->nip
);
2146 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2148 new_msr
|= (target_ulong
)MSR_HVB
;
2149 msr
|= env
->error_code
;
2151 case POWERPC_EXCP_EXTERNAL
: /* External input */
2152 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2154 new_msr
|= (target_ulong
)MSR_HVB
;
2156 case POWERPC_EXCP_ALIGN
: /* Alignment exception */
2157 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2159 new_msr
|= (target_ulong
)MSR_HVB
;
2160 /* XXX: this is false */
2161 /* Get rS/rD and rA from faulting opcode */
2162 env
->spr
[SPR_DSISR
] |= (ldl_code((env
->nip
- 4)) & 0x03FF0000) >> 16;
2164 case POWERPC_EXCP_PROGRAM
: /* Program exception */
2165 switch (env
->error_code
& ~0xF) {
2166 case POWERPC_EXCP_FP
:
2167 if ((msr_fe0
== 0 && msr_fe1
== 0) || msr_fp
== 0) {
2168 LOG_EXCP("Ignore floating point exception\n");
2169 env
->exception_index
= POWERPC_EXCP_NONE
;
2170 env
->error_code
= 0;
2173 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2175 new_msr
|= (target_ulong
)MSR_HVB
;
2177 if (msr_fe0
== msr_fe1
)
2181 case POWERPC_EXCP_INVAL
:
2182 LOG_EXCP("Invalid instruction at " TARGET_FMT_lx
"\n", env
->nip
);
2183 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2185 new_msr
|= (target_ulong
)MSR_HVB
;
2188 case POWERPC_EXCP_PRIV
:
2189 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2191 new_msr
|= (target_ulong
)MSR_HVB
;
2194 case POWERPC_EXCP_TRAP
:
2195 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2197 new_msr
|= (target_ulong
)MSR_HVB
;
2201 /* Should never occur */
2202 cpu_abort(env
, "Invalid program exception %d. Aborting\n",
2207 case POWERPC_EXCP_FPU
: /* Floating-point unavailable exception */
2208 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2210 new_msr
|= (target_ulong
)MSR_HVB
;
2212 case POWERPC_EXCP_SYSCALL
: /* System call exception */
2213 /* NOTE: this is a temporary hack to support graphics OSI
2214 calls from the MOL driver */
2215 /* XXX: To be removed */
2216 if (env
->gpr
[3] == 0x113724fa && env
->gpr
[4] == 0x77810f9b &&
2218 if (env
->osi_call(env
) != 0) {
2219 env
->exception_index
= POWERPC_EXCP_NONE
;
2220 env
->error_code
= 0;
2225 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2226 lev
= env
->error_code
;
2227 if (lev
== 1 || (lpes0
== 0 && lpes1
== 0))
2228 new_msr
|= (target_ulong
)MSR_HVB
;
2230 case POWERPC_EXCP_APU
: /* Auxiliary processor unavailable */
2231 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2233 case POWERPC_EXCP_DECR
: /* Decrementer exception */
2234 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2236 new_msr
|= (target_ulong
)MSR_HVB
;
2238 case POWERPC_EXCP_FIT
: /* Fixed-interval timer interrupt */
2240 LOG_EXCP("FIT exception\n");
2241 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2243 case POWERPC_EXCP_WDT
: /* Watchdog timer interrupt */
2244 LOG_EXCP("WDT exception\n");
2245 switch (excp_model
) {
2246 case POWERPC_EXCP_BOOKE
:
2247 srr0
= SPR_BOOKE_CSRR0
;
2248 srr1
= SPR_BOOKE_CSRR1
;
2253 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2255 case POWERPC_EXCP_DTLB
: /* Data TLB error */
2256 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2258 case POWERPC_EXCP_ITLB
: /* Instruction TLB error */
2259 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2261 case POWERPC_EXCP_DEBUG
: /* Debug interrupt */
2262 switch (excp_model
) {
2263 case POWERPC_EXCP_BOOKE
:
2264 srr0
= SPR_BOOKE_DSRR0
;
2265 srr1
= SPR_BOOKE_DSRR1
;
2266 asrr0
= SPR_BOOKE_CSRR0
;
2267 asrr1
= SPR_BOOKE_CSRR1
;
2273 cpu_abort(env
, "Debug exception is not implemented yet !\n");
2275 case POWERPC_EXCP_SPEU
: /* SPE/embedded floating-point unavailable */
2276 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2278 case POWERPC_EXCP_EFPDI
: /* Embedded floating-point data interrupt */
2280 cpu_abort(env
, "Embedded floating point data exception "
2281 "is not implemented yet !\n");
2283 case POWERPC_EXCP_EFPRI
: /* Embedded floating-point round interrupt */
2285 cpu_abort(env
, "Embedded floating point round exception "
2286 "is not implemented yet !\n");
2288 case POWERPC_EXCP_EPERFM
: /* Embedded performance monitor interrupt */
2289 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2292 "Performance counter exception is not implemented yet !\n");
2294 case POWERPC_EXCP_DOORI
: /* Embedded doorbell interrupt */
2297 "Embedded doorbell interrupt is not implemented yet !\n");
2299 case POWERPC_EXCP_DOORCI
: /* Embedded doorbell critical interrupt */
2300 switch (excp_model
) {
2301 case POWERPC_EXCP_BOOKE
:
2302 srr0
= SPR_BOOKE_CSRR0
;
2303 srr1
= SPR_BOOKE_CSRR1
;
2309 cpu_abort(env
, "Embedded doorbell critical interrupt "
2310 "is not implemented yet !\n");
2312 case POWERPC_EXCP_RESET
: /* System reset exception */
2313 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2315 /* XXX: find a suitable condition to enable the hypervisor mode */
2316 new_msr
|= (target_ulong
)MSR_HVB
;
2319 case POWERPC_EXCP_DSEG
: /* Data segment exception */
2320 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2322 new_msr
|= (target_ulong
)MSR_HVB
;
2324 case POWERPC_EXCP_ISEG
: /* Instruction segment exception */
2325 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2327 new_msr
|= (target_ulong
)MSR_HVB
;
2329 case POWERPC_EXCP_HDECR
: /* Hypervisor decrementer exception */
2332 new_msr
|= (target_ulong
)MSR_HVB
;
2334 case POWERPC_EXCP_TRACE
: /* Trace exception */
2335 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2337 new_msr
|= (target_ulong
)MSR_HVB
;
2339 case POWERPC_EXCP_HDSI
: /* Hypervisor data storage exception */
2342 new_msr
|= (target_ulong
)MSR_HVB
;
2344 case POWERPC_EXCP_HISI
: /* Hypervisor instruction storage exception */
2347 new_msr
|= (target_ulong
)MSR_HVB
;
2349 case POWERPC_EXCP_HDSEG
: /* Hypervisor data segment exception */
2352 new_msr
|= (target_ulong
)MSR_HVB
;
2354 case POWERPC_EXCP_HISEG
: /* Hypervisor instruction segment exception */
2357 new_msr
|= (target_ulong
)MSR_HVB
;
2359 case POWERPC_EXCP_VPU
: /* Vector unavailable exception */
2360 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2362 new_msr
|= (target_ulong
)MSR_HVB
;
2364 case POWERPC_EXCP_PIT
: /* Programmable interval timer interrupt */
2365 LOG_EXCP("PIT exception\n");
2366 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2368 case POWERPC_EXCP_IO
: /* IO error exception */
2370 cpu_abort(env
, "601 IO error exception is not implemented yet !\n");
2372 case POWERPC_EXCP_RUNM
: /* Run mode exception */
2374 cpu_abort(env
, "601 run mode exception is not implemented yet !\n");
2376 case POWERPC_EXCP_EMUL
: /* Emulation trap exception */
2378 cpu_abort(env
, "602 emulation trap exception "
2379 "is not implemented yet !\n");
2381 case POWERPC_EXCP_IFTLB
: /* Instruction fetch TLB error */
2382 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2383 if (lpes1
== 0) /* XXX: check this */
2384 new_msr
|= (target_ulong
)MSR_HVB
;
2385 switch (excp_model
) {
2386 case POWERPC_EXCP_602
:
2387 case POWERPC_EXCP_603
:
2388 case POWERPC_EXCP_603E
:
2389 case POWERPC_EXCP_G2
:
2391 case POWERPC_EXCP_7x5
:
2393 case POWERPC_EXCP_74xx
:
2396 cpu_abort(env
, "Invalid instruction TLB miss exception\n");
2400 case POWERPC_EXCP_DLTLB
: /* Data load TLB miss */
2401 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2402 if (lpes1
== 0) /* XXX: check this */
2403 new_msr
|= (target_ulong
)MSR_HVB
;
2404 switch (excp_model
) {
2405 case POWERPC_EXCP_602
:
2406 case POWERPC_EXCP_603
:
2407 case POWERPC_EXCP_603E
:
2408 case POWERPC_EXCP_G2
:
2410 case POWERPC_EXCP_7x5
:
2412 case POWERPC_EXCP_74xx
:
2415 cpu_abort(env
, "Invalid data load TLB miss exception\n");
2419 case POWERPC_EXCP_DSTLB
: /* Data store TLB miss */
2420 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2421 if (lpes1
== 0) /* XXX: check this */
2422 new_msr
|= (target_ulong
)MSR_HVB
;
2423 switch (excp_model
) {
2424 case POWERPC_EXCP_602
:
2425 case POWERPC_EXCP_603
:
2426 case POWERPC_EXCP_603E
:
2427 case POWERPC_EXCP_G2
:
2429 /* Swap temporary saved registers with GPRs */
2430 if (!(new_msr
& ((target_ulong
)1 << MSR_TGPR
))) {
2431 new_msr
|= (target_ulong
)1 << MSR_TGPR
;
2432 hreg_swap_gpr_tgpr(env
);
2435 case POWERPC_EXCP_7x5
:
2437 #if defined (DEBUG_SOFTWARE_TLB)
2438 if (qemu_log_enabled()) {
2440 target_ulong
*miss
, *cmp
;
2442 if (excp
== POWERPC_EXCP_IFTLB
) {
2445 miss
= &env
->spr
[SPR_IMISS
];
2446 cmp
= &env
->spr
[SPR_ICMP
];
2448 if (excp
== POWERPC_EXCP_DLTLB
)
2453 miss
= &env
->spr
[SPR_DMISS
];
2454 cmp
= &env
->spr
[SPR_DCMP
];
2456 qemu_log("6xx %sTLB miss: %cM " TARGET_FMT_lx
" %cC "
2457 TARGET_FMT_lx
" H1 " TARGET_FMT_lx
" H2 "
2458 TARGET_FMT_lx
" %08x\n", es
, en
, *miss
, en
, *cmp
,
2459 env
->spr
[SPR_HASH1
], env
->spr
[SPR_HASH2
],
2463 msr
|= env
->crf
[0] << 28;
2464 msr
|= env
->error_code
; /* key, D/I, S/L bits */
2465 /* Set way using a LRU mechanism */
2466 msr
|= ((env
->last_way
+ 1) & (env
->nb_ways
- 1)) << 17;
2468 case POWERPC_EXCP_74xx
:
2470 #if defined (DEBUG_SOFTWARE_TLB)
2471 if (qemu_log_enabled()) {
2473 target_ulong
*miss
, *cmp
;
2475 if (excp
== POWERPC_EXCP_IFTLB
) {
2478 miss
= &env
->spr
[SPR_TLBMISS
];
2479 cmp
= &env
->spr
[SPR_PTEHI
];
2481 if (excp
== POWERPC_EXCP_DLTLB
)
2486 miss
= &env
->spr
[SPR_TLBMISS
];
2487 cmp
= &env
->spr
[SPR_PTEHI
];
2489 qemu_log("74xx %sTLB miss: %cM " TARGET_FMT_lx
" %cC "
2490 TARGET_FMT_lx
" %08x\n", es
, en
, *miss
, en
, *cmp
,
2494 msr
|= env
->error_code
; /* key bit */
2497 cpu_abort(env
, "Invalid data store TLB miss exception\n");
2501 case POWERPC_EXCP_FPA
: /* Floating-point assist exception */
2503 cpu_abort(env
, "Floating point assist exception "
2504 "is not implemented yet !\n");
2506 case POWERPC_EXCP_DABR
: /* Data address breakpoint */
2508 cpu_abort(env
, "DABR exception is not implemented yet !\n");
2510 case POWERPC_EXCP_IABR
: /* Instruction address breakpoint */
2512 cpu_abort(env
, "IABR exception is not implemented yet !\n");
2514 case POWERPC_EXCP_SMI
: /* System management interrupt */
2516 cpu_abort(env
, "SMI exception is not implemented yet !\n");
2518 case POWERPC_EXCP_THERM
: /* Thermal interrupt */
2520 cpu_abort(env
, "Thermal management exception "
2521 "is not implemented yet !\n");
2523 case POWERPC_EXCP_PERFM
: /* Embedded performance monitor interrupt */
2524 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2526 new_msr
|= (target_ulong
)MSR_HVB
;
2529 "Performance counter exception is not implemented yet !\n");
2531 case POWERPC_EXCP_VPUA
: /* Vector assist exception */
2533 cpu_abort(env
, "VPU assist exception is not implemented yet !\n");
2535 case POWERPC_EXCP_SOFTP
: /* Soft patch exception */
2538 "970 soft-patch exception is not implemented yet !\n");
2540 case POWERPC_EXCP_MAINT
: /* Maintenance exception */
2543 "970 maintenance exception is not implemented yet !\n");
2545 case POWERPC_EXCP_MEXTBR
: /* Maskable external breakpoint */
2547 cpu_abort(env
, "Maskable external exception "
2548 "is not implemented yet !\n");
2550 case POWERPC_EXCP_NMEXTBR
: /* Non maskable external breakpoint */
2552 cpu_abort(env
, "Non maskable external exception "
2553 "is not implemented yet !\n");
2557 cpu_abort(env
, "Invalid PowerPC exception %d. Aborting\n", excp
);
2560 /* save current instruction location */
2561 env
->spr
[srr0
] = env
->nip
- 4;
2564 /* save next instruction location */
2565 env
->spr
[srr0
] = env
->nip
;
2569 env
->spr
[srr1
] = msr
;
2570 /* If any alternate SRR register are defined, duplicate saved values */
2572 env
->spr
[asrr0
] = env
->spr
[srr0
];
2574 env
->spr
[asrr1
] = env
->spr
[srr1
];
2575 /* If we disactivated any translation, flush TLBs */
2576 if (new_msr
& ((1 << MSR_IR
) | (1 << MSR_DR
)))
2578 /* reload MSR with correct bits */
2579 new_msr
&= ~((target_ulong
)1 << MSR_EE
);
2580 new_msr
&= ~((target_ulong
)1 << MSR_PR
);
2581 new_msr
&= ~((target_ulong
)1 << MSR_FP
);
2582 new_msr
&= ~((target_ulong
)1 << MSR_FE0
);
2583 new_msr
&= ~((target_ulong
)1 << MSR_SE
);
2584 new_msr
&= ~((target_ulong
)1 << MSR_BE
);
2585 new_msr
&= ~((target_ulong
)1 << MSR_FE1
);
2586 new_msr
&= ~((target_ulong
)1 << MSR_IR
);
2587 new_msr
&= ~((target_ulong
)1 << MSR_DR
);
2588 #if 0 /* Fix this: not on all targets */
2589 new_msr
&= ~((target_ulong
)1 << MSR_PMM
);
2591 new_msr
&= ~((target_ulong
)1 << MSR_LE
);
2593 new_msr
|= (target_ulong
)1 << MSR_LE
;
2595 new_msr
&= ~((target_ulong
)1 << MSR_LE
);
2596 /* Jump to handler */
2597 vector
= env
->excp_vectors
[excp
];
2598 if (vector
== (target_ulong
)-1ULL) {
2599 cpu_abort(env
, "Raised an exception without defined vector %d\n",
2602 vector
|= env
->excp_prefix
;
2603 #if defined(TARGET_PPC64)
2604 if (excp_model
== POWERPC_EXCP_BOOKE
) {
2606 new_msr
&= ~((target_ulong
)1 << MSR_CM
);
2607 vector
= (uint32_t)vector
;
2609 new_msr
|= (target_ulong
)1 << MSR_CM
;
2612 if (!msr_isf
&& !(env
->mmu_model
& POWERPC_MMU_64
)) {
2613 new_msr
&= ~((target_ulong
)1 << MSR_SF
);
2614 vector
= (uint32_t)vector
;
2616 new_msr
|= (target_ulong
)1 << MSR_SF
;
2620 /* XXX: we don't use hreg_store_msr here as already have treated
2621 * any special case that could occur. Just store MSR and update hflags
2623 env
->msr
= new_msr
& env
->msr_mask
;
2624 hreg_compute_hflags(env
);
2626 /* Reset exception state */
2627 env
->exception_index
= POWERPC_EXCP_NONE
;
2628 env
->error_code
= 0;
2631 void do_interrupt (CPUState
*env
)
2633 powerpc_excp(env
, env
->excp_model
, env
->exception_index
);
2636 void ppc_hw_interrupt (CPUPPCState
*env
)
2641 qemu_log_mask(CPU_LOG_INT
, "%s: %p pending %08x req %08x me %d ee %d\n",
2642 __func__
, env
, env
->pending_interrupts
,
2643 env
->interrupt_request
, (int)msr_me
, (int)msr_ee
);
2645 /* External reset */
2646 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_RESET
)) {
2647 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_RESET
);
2648 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_RESET
);
2651 /* Machine check exception */
2652 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_MCK
)) {
2653 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_MCK
);
2654 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_MCHECK
);
2658 /* External debug exception */
2659 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DEBUG
)) {
2660 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DEBUG
);
2661 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DEBUG
);
2666 /* XXX: find a suitable condition to enable the hypervisor mode */
2667 hdice
= env
->spr
[SPR_LPCR
] & 1;
2671 if ((msr_ee
!= 0 || msr_hv
== 0 || msr_pr
!= 0) && hdice
!= 0) {
2672 /* Hypervisor decrementer exception */
2673 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_HDECR
)) {
2674 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_HDECR
);
2675 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_HDECR
);
2680 /* External critical interrupt */
2681 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_CEXT
)) {
2682 /* Taking a critical external interrupt does not clear the external
2683 * critical interrupt status
2686 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_CEXT
);
2688 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_CRITICAL
);
2693 /* Watchdog timer on embedded PowerPC */
2694 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_WDT
)) {
2695 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_WDT
);
2696 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_WDT
);
2699 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_CDOORBELL
)) {
2700 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_CDOORBELL
);
2701 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DOORCI
);
2704 /* Fixed interval timer on embedded PowerPC */
2705 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_FIT
)) {
2706 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_FIT
);
2707 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_FIT
);
2710 /* Programmable interval timer on embedded PowerPC */
2711 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_PIT
)) {
2712 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_PIT
);
2713 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_PIT
);
2716 /* Decrementer exception */
2717 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DECR
)) {
2718 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DECR
);
2719 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DECR
);
2722 /* External interrupt */
2723 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_EXT
)) {
2724 /* Taking an external interrupt does not clear the external
2728 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_EXT
);
2730 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_EXTERNAL
);
2733 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DOORBELL
)) {
2734 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DOORBELL
);
2735 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DOORI
);
2738 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_PERFM
)) {
2739 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_PERFM
);
2740 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_PERFM
);
2743 /* Thermal interrupt */
2744 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_THERM
)) {
2745 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_THERM
);
2746 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_THERM
);
2751 #endif /* !CONFIG_USER_ONLY */
2753 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
)
2755 qemu_log("Return from exception at " TARGET_FMT_lx
" with flags "
2756 TARGET_FMT_lx
"\n", RA
, msr
);
2759 void cpu_reset(CPUPPCState
*env
)
2763 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
2764 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
2765 log_cpu_state(env
, 0);
2768 msr
= (target_ulong
)0;
2770 /* XXX: find a suitable condition to enable the hypervisor mode */
2771 msr
|= (target_ulong
)MSR_HVB
;
2773 msr
|= (target_ulong
)0 << MSR_AP
; /* TO BE CHECKED */
2774 msr
|= (target_ulong
)0 << MSR_SA
; /* TO BE CHECKED */
2775 msr
|= (target_ulong
)1 << MSR_EP
;
2776 #if defined (DO_SINGLE_STEP) && 0
2777 /* Single step trace mode */
2778 msr
|= (target_ulong
)1 << MSR_SE
;
2779 msr
|= (target_ulong
)1 << MSR_BE
;
2781 #if defined(CONFIG_USER_ONLY)
2782 msr
|= (target_ulong
)1 << MSR_FP
; /* Allow floating point usage */
2783 msr
|= (target_ulong
)1 << MSR_VR
; /* Allow altivec usage */
2784 msr
|= (target_ulong
)1 << MSR_SPE
; /* Allow SPE usage */
2785 msr
|= (target_ulong
)1 << MSR_PR
;
2787 env
->excp_prefix
= env
->hreset_excp_prefix
;
2788 env
->nip
= env
->hreset_vector
| env
->excp_prefix
;
2789 if (env
->mmu_model
!= POWERPC_MMU_REAL
)
2790 ppc_tlb_invalidate_all(env
);
2792 env
->msr
= msr
& env
->msr_mask
;
2793 #if defined(TARGET_PPC64)
2794 if (env
->mmu_model
& POWERPC_MMU_64
)
2795 env
->msr
|= (1ULL << MSR_SF
);
2797 hreg_compute_hflags(env
);
2798 env
->reserve_addr
= (target_ulong
)-1ULL;
2799 /* Be sure no exception or interrupt is pending */
2800 env
->pending_interrupts
= 0;
2801 env
->exception_index
= POWERPC_EXCP_NONE
;
2802 env
->error_code
= 0;
2803 /* Flush all TLBs */
2807 CPUPPCState
*cpu_ppc_init (const char *cpu_model
)
2810 const ppc_def_t
*def
;
2812 def
= cpu_ppc_find_by_name(cpu_model
);
2816 env
= qemu_mallocz(sizeof(CPUPPCState
));
2818 ppc_translate_init();
2819 env
->cpu_model_str
= cpu_model
;
2820 cpu_ppc_register_internal(env
, def
);
2822 qemu_init_vcpu(env
);
2827 void cpu_ppc_close (CPUPPCState
*env
)
2829 /* Should also remove all opcode tables... */