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
;
100 target_phys_addr_t
cpu_get_phys_page_debug (CPUState
*env
, target_ulong addr
)
106 /* Common routines used by software and hardware TLBs emulation */
107 static inline int pte_is_valid(target_ulong pte0
)
109 return pte0
& 0x80000000 ? 1 : 0;
112 static inline void pte_invalidate(target_ulong
*pte0
)
114 *pte0
&= ~0x80000000;
117 #if defined(TARGET_PPC64)
118 static inline int pte64_is_valid(target_ulong pte0
)
120 return pte0
& 0x0000000000000001ULL
? 1 : 0;
123 static inline void pte64_invalidate(target_ulong
*pte0
)
125 *pte0
&= ~0x0000000000000001ULL
;
129 #define PTE_PTEM_MASK 0x7FFFFFBF
130 #define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B)
131 #if defined(TARGET_PPC64)
132 #define PTE64_PTEM_MASK 0xFFFFFFFFFFFFFF80ULL
133 #define PTE64_CHECK_MASK (TARGET_PAGE_MASK | 0x7F)
136 static inline int pp_check(int key
, int pp
, int nx
)
140 /* Compute access rights */
141 /* When pp is 3/7, the result is undefined. Set it to noaccess */
148 access
|= PAGE_WRITE
;
166 access
= PAGE_READ
| PAGE_WRITE
;
176 static inline int check_prot(int prot
, int rw
, int access_type
)
180 if (access_type
== ACCESS_CODE
) {
181 if (prot
& PAGE_EXEC
)
186 if (prot
& PAGE_WRITE
)
191 if (prot
& PAGE_READ
)
200 static inline int _pte_check(mmu_ctx_t
*ctx
, int is_64b
, target_ulong pte0
,
201 target_ulong pte1
, int h
, int rw
, int type
)
203 target_ulong ptem
, mmask
;
204 int access
, ret
, pteh
, ptev
, pp
;
208 /* Check validity and table match */
209 #if defined(TARGET_PPC64)
211 ptev
= pte64_is_valid(pte0
);
212 pteh
= (pte0
>> 1) & 1;
216 ptev
= pte_is_valid(pte0
);
217 pteh
= (pte0
>> 6) & 1;
219 if (ptev
&& h
== pteh
) {
220 /* Check vsid & api */
221 #if defined(TARGET_PPC64)
223 ptem
= pte0
& PTE64_PTEM_MASK
;
224 mmask
= PTE64_CHECK_MASK
;
225 pp
= (pte1
& 0x00000003) | ((pte1
>> 61) & 0x00000004);
226 ctx
->nx
= (pte1
>> 2) & 1; /* No execute bit */
227 ctx
->nx
|= (pte1
>> 3) & 1; /* Guarded bit */
231 ptem
= pte0
& PTE_PTEM_MASK
;
232 mmask
= PTE_CHECK_MASK
;
233 pp
= pte1
& 0x00000003;
235 if (ptem
== ctx
->ptem
) {
236 if (ctx
->raddr
!= (target_phys_addr_t
)-1ULL) {
237 /* all matches should have equal RPN, WIMG & PP */
238 if ((ctx
->raddr
& mmask
) != (pte1
& mmask
)) {
239 qemu_log("Bad RPN/WIMG/PP\n");
243 /* Compute access rights */
244 access
= pp_check(ctx
->key
, pp
, ctx
->nx
);
245 /* Keep the matching PTE informations */
248 ret
= check_prot(ctx
->prot
, rw
, type
);
251 LOG_MMU("PTE access granted !\n");
253 /* Access right violation */
254 LOG_MMU("PTE access rejected\n");
262 static inline int pte32_check(mmu_ctx_t
*ctx
, target_ulong pte0
,
263 target_ulong pte1
, int h
, int rw
, int type
)
265 return _pte_check(ctx
, 0, pte0
, pte1
, h
, rw
, type
);
268 #if defined(TARGET_PPC64)
269 static inline int pte64_check(mmu_ctx_t
*ctx
, target_ulong pte0
,
270 target_ulong pte1
, int h
, int rw
, int type
)
272 return _pte_check(ctx
, 1, pte0
, pte1
, h
, rw
, type
);
276 static inline int pte_update_flags(mmu_ctx_t
*ctx
, target_ulong
*pte1p
,
281 /* Update page flags */
282 if (!(*pte1p
& 0x00000100)) {
283 /* Update accessed flag */
284 *pte1p
|= 0x00000100;
287 if (!(*pte1p
& 0x00000080)) {
288 if (rw
== 1 && ret
== 0) {
289 /* Update changed flag */
290 *pte1p
|= 0x00000080;
293 /* Force page fault for first write access */
294 ctx
->prot
&= ~PAGE_WRITE
;
301 /* Software driven TLB helpers */
302 static inline int ppc6xx_tlb_getnum(CPUState
*env
, target_ulong eaddr
, int way
,
307 /* Select TLB num in a way from address */
308 nr
= (eaddr
>> TARGET_PAGE_BITS
) & (env
->tlb_per_way
- 1);
310 nr
+= env
->tlb_per_way
* way
;
311 /* 6xx have separate TLBs for instructions and data */
312 if (is_code
&& env
->id_tlbs
== 1)
318 static inline void ppc6xx_tlb_invalidate_all(CPUState
*env
)
323 //LOG_SWTLB("Invalidate all TLBs\n");
324 /* Invalidate all defined software TLB */
326 if (env
->id_tlbs
== 1)
328 for (nr
= 0; nr
< max
; nr
++) {
329 tlb
= &env
->tlb
[nr
].tlb6
;
330 pte_invalidate(&tlb
->pte0
);
335 static inline void __ppc6xx_tlb_invalidate_virt(CPUState
*env
,
337 int is_code
, int match_epn
)
339 #if !defined(FLUSH_ALL_TLBS)
343 /* Invalidate ITLB + DTLB, all ways */
344 for (way
= 0; way
< env
->nb_ways
; way
++) {
345 nr
= ppc6xx_tlb_getnum(env
, eaddr
, way
, is_code
);
346 tlb
= &env
->tlb
[nr
].tlb6
;
347 if (pte_is_valid(tlb
->pte0
) && (match_epn
== 0 || eaddr
== tlb
->EPN
)) {
348 LOG_SWTLB("TLB invalidate %d/%d " TARGET_FMT_lx
"\n", nr
,
350 pte_invalidate(&tlb
->pte0
);
351 tlb_flush_page(env
, tlb
->EPN
);
355 /* XXX: PowerPC specification say this is valid as well */
356 ppc6xx_tlb_invalidate_all(env
);
360 static inline void ppc6xx_tlb_invalidate_virt(CPUState
*env
,
361 target_ulong eaddr
, int is_code
)
363 __ppc6xx_tlb_invalidate_virt(env
, eaddr
, is_code
, 0);
366 void ppc6xx_tlb_store (CPUState
*env
, target_ulong EPN
, int way
, int is_code
,
367 target_ulong pte0
, target_ulong pte1
)
372 nr
= ppc6xx_tlb_getnum(env
, EPN
, way
, is_code
);
373 tlb
= &env
->tlb
[nr
].tlb6
;
374 LOG_SWTLB("Set TLB %d/%d EPN " TARGET_FMT_lx
" PTE0 " TARGET_FMT_lx
375 " PTE1 " TARGET_FMT_lx
"\n", nr
, env
->nb_tlb
, EPN
, pte0
, pte1
);
376 /* Invalidate any pending reference in Qemu for this virtual address */
377 __ppc6xx_tlb_invalidate_virt(env
, EPN
, is_code
, 1);
381 /* Store last way for LRU mechanism */
385 static inline int ppc6xx_tlb_check(CPUState
*env
, mmu_ctx_t
*ctx
,
386 target_ulong eaddr
, int rw
, int access_type
)
393 ret
= -1; /* No TLB found */
394 for (way
= 0; way
< env
->nb_ways
; way
++) {
395 nr
= ppc6xx_tlb_getnum(env
, eaddr
, way
,
396 access_type
== ACCESS_CODE
? 1 : 0);
397 tlb
= &env
->tlb
[nr
].tlb6
;
398 /* This test "emulates" the PTE index match for hardware TLBs */
399 if ((eaddr
& TARGET_PAGE_MASK
) != tlb
->EPN
) {
400 LOG_SWTLB("TLB %d/%d %s [" TARGET_FMT_lx
" " TARGET_FMT_lx
401 "] <> " TARGET_FMT_lx
"\n", nr
, env
->nb_tlb
,
402 pte_is_valid(tlb
->pte0
) ? "valid" : "inval",
403 tlb
->EPN
, tlb
->EPN
+ TARGET_PAGE_SIZE
, eaddr
);
406 LOG_SWTLB("TLB %d/%d %s " TARGET_FMT_lx
" <> " TARGET_FMT_lx
" "
407 TARGET_FMT_lx
" %c %c\n", nr
, env
->nb_tlb
,
408 pte_is_valid(tlb
->pte0
) ? "valid" : "inval",
409 tlb
->EPN
, eaddr
, tlb
->pte1
,
410 rw
? 'S' : 'L', access_type
== ACCESS_CODE
? 'I' : 'D');
411 switch (pte32_check(ctx
, tlb
->pte0
, tlb
->pte1
, 0, rw
, access_type
)) {
413 /* TLB inconsistency */
416 /* Access violation */
426 /* XXX: we should go on looping to check all TLBs consistency
427 * but we can speed-up the whole thing as the
428 * result would be undefined if TLBs are not consistent.
437 LOG_SWTLB("found TLB at addr " TARGET_FMT_plx
" prot=%01x ret=%d\n",
438 ctx
->raddr
& TARGET_PAGE_MASK
, ctx
->prot
, ret
);
439 /* Update page flags */
440 pte_update_flags(ctx
, &env
->tlb
[best
].tlb6
.pte1
, ret
, rw
);
446 /* Perform BAT hit & translation */
447 static inline void bat_size_prot(CPUState
*env
, target_ulong
*blp
, int *validp
,
448 int *protp
, target_ulong
*BATu
,
454 bl
= (*BATu
& 0x00001FFC) << 15;
457 if (((msr_pr
== 0) && (*BATu
& 0x00000002)) ||
458 ((msr_pr
!= 0) && (*BATu
& 0x00000001))) {
460 pp
= *BATl
& 0x00000003;
462 prot
= PAGE_READ
| PAGE_EXEC
;
472 static inline void bat_601_size_prot(CPUState
*env
, target_ulong
*blp
,
473 int *validp
, int *protp
,
474 target_ulong
*BATu
, target_ulong
*BATl
)
477 int key
, pp
, valid
, prot
;
479 bl
= (*BATl
& 0x0000003F) << 17;
480 LOG_BATS("b %02x ==> bl " TARGET_FMT_lx
" msk " TARGET_FMT_lx
"\n",
481 (uint8_t)(*BATl
& 0x0000003F), bl
, ~bl
);
483 valid
= (*BATl
>> 6) & 1;
485 pp
= *BATu
& 0x00000003;
487 key
= (*BATu
>> 3) & 1;
489 key
= (*BATu
>> 2) & 1;
490 prot
= pp_check(key
, pp
, 0);
497 static inline int get_bat(CPUState
*env
, mmu_ctx_t
*ctx
, target_ulong
virtual,
500 target_ulong
*BATlt
, *BATut
, *BATu
, *BATl
;
501 target_ulong base
, BEPIl
, BEPIu
, bl
;
505 LOG_BATS("%s: %cBAT v " TARGET_FMT_lx
"\n", __func__
,
506 type
== ACCESS_CODE
? 'I' : 'D', virtual);
509 BATlt
= env
->IBAT
[1];
510 BATut
= env
->IBAT
[0];
513 BATlt
= env
->DBAT
[1];
514 BATut
= env
->DBAT
[0];
517 base
= virtual & 0xFFFC0000;
518 for (i
= 0; i
< env
->nb_BATs
; i
++) {
521 BEPIu
= *BATu
& 0xF0000000;
522 BEPIl
= *BATu
& 0x0FFE0000;
523 if (unlikely(env
->mmu_model
== POWERPC_MMU_601
)) {
524 bat_601_size_prot(env
, &bl
, &valid
, &prot
, BATu
, BATl
);
526 bat_size_prot(env
, &bl
, &valid
, &prot
, BATu
, BATl
);
528 LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx
" BATu " TARGET_FMT_lx
529 " BATl " TARGET_FMT_lx
"\n", __func__
,
530 type
== ACCESS_CODE
? 'I' : 'D', i
, virtual, *BATu
, *BATl
);
531 if ((virtual & 0xF0000000) == BEPIu
&&
532 ((virtual & 0x0FFE0000) & ~bl
) == BEPIl
) {
535 /* Get physical address */
536 ctx
->raddr
= (*BATl
& 0xF0000000) |
537 ((virtual & 0x0FFE0000 & bl
) | (*BATl
& 0x0FFE0000)) |
538 (virtual & 0x0001F000);
539 /* Compute access rights */
541 ret
= check_prot(ctx
->prot
, rw
, type
);
543 LOG_BATS("BAT %d match: r " TARGET_FMT_plx
" prot=%c%c\n",
544 i
, ctx
->raddr
, ctx
->prot
& PAGE_READ
? 'R' : '-',
545 ctx
->prot
& PAGE_WRITE
? 'W' : '-');
551 #if defined(DEBUG_BATS)
552 if (qemu_log_enabled()) {
553 LOG_BATS("no BAT match for " TARGET_FMT_lx
":\n", virtual);
554 for (i
= 0; i
< 4; i
++) {
557 BEPIu
= *BATu
& 0xF0000000;
558 BEPIl
= *BATu
& 0x0FFE0000;
559 bl
= (*BATu
& 0x00001FFC) << 15;
560 LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx
" BATu " TARGET_FMT_lx
561 " BATl " TARGET_FMT_lx
" \n\t" TARGET_FMT_lx
" "
562 TARGET_FMT_lx
" " TARGET_FMT_lx
"\n",
563 __func__
, type
== ACCESS_CODE
? 'I' : 'D', i
, virtual,
564 *BATu
, *BATl
, BEPIu
, BEPIl
, bl
);
573 /* PTE table lookup */
574 static inline int _find_pte(mmu_ctx_t
*ctx
, int is_64b
, int h
, int rw
,
575 int type
, int target_page_bits
)
577 target_ulong base
, pte0
, pte1
;
581 ret
= -1; /* No entry found */
582 base
= ctx
->pg_addr
[h
];
583 for (i
= 0; i
< 8; i
++) {
584 #if defined(TARGET_PPC64)
586 pte0
= ldq_phys(base
+ (i
* 16));
587 pte1
= ldq_phys(base
+ (i
* 16) + 8);
589 /* We have a TLB that saves 4K pages, so let's
590 * split a huge page to 4k chunks */
591 if (target_page_bits
!= TARGET_PAGE_BITS
)
592 pte1
|= (ctx
->eaddr
& (( 1 << target_page_bits
) - 1))
595 r
= pte64_check(ctx
, pte0
, pte1
, h
, rw
, type
);
596 LOG_MMU("Load pte from " TARGET_FMT_lx
" => " TARGET_FMT_lx
" "
597 TARGET_FMT_lx
" %d %d %d " TARGET_FMT_lx
"\n",
598 base
+ (i
* 16), pte0
, pte1
, (int)(pte0
& 1), h
,
599 (int)((pte0
>> 1) & 1), ctx
->ptem
);
603 pte0
= ldl_phys(base
+ (i
* 8));
604 pte1
= ldl_phys(base
+ (i
* 8) + 4);
605 r
= pte32_check(ctx
, pte0
, pte1
, h
, rw
, type
);
606 LOG_MMU("Load pte from " TARGET_FMT_lx
" => " TARGET_FMT_lx
" "
607 TARGET_FMT_lx
" %d %d %d " TARGET_FMT_lx
"\n",
608 base
+ (i
* 8), pte0
, pte1
, (int)(pte0
>> 31), h
,
609 (int)((pte0
>> 6) & 1), ctx
->ptem
);
613 /* PTE inconsistency */
616 /* Access violation */
626 /* XXX: we should go on looping to check all PTEs consistency
627 * but if we can speed-up the whole thing as the
628 * result would be undefined if PTEs are not consistent.
637 LOG_MMU("found PTE at addr " TARGET_FMT_lx
" prot=%01x ret=%d\n",
638 ctx
->raddr
, ctx
->prot
, ret
);
639 /* Update page flags */
641 if (pte_update_flags(ctx
, &pte1
, ret
, rw
) == 1) {
642 #if defined(TARGET_PPC64)
644 stq_phys_notdirty(base
+ (good
* 16) + 8, pte1
);
648 stl_phys_notdirty(base
+ (good
* 8) + 4, pte1
);
656 static inline int find_pte32(mmu_ctx_t
*ctx
, int h
, int rw
, int type
,
657 int target_page_bits
)
659 return _find_pte(ctx
, 0, h
, rw
, type
, target_page_bits
);
662 #if defined(TARGET_PPC64)
663 static inline int find_pte64(mmu_ctx_t
*ctx
, int h
, int rw
, int type
,
664 int target_page_bits
)
666 return _find_pte(ctx
, 1, h
, rw
, type
, target_page_bits
);
670 static inline int find_pte(CPUState
*env
, mmu_ctx_t
*ctx
, int h
, int rw
,
671 int type
, int target_page_bits
)
673 #if defined(TARGET_PPC64)
674 if (env
->mmu_model
& POWERPC_MMU_64
)
675 return find_pte64(ctx
, h
, rw
, type
, target_page_bits
);
678 return find_pte32(ctx
, h
, rw
, type
, target_page_bits
);
681 #if defined(TARGET_PPC64)
682 static ppc_slb_t
*slb_get_entry(CPUPPCState
*env
, int nr
)
684 ppc_slb_t
*retval
= &env
->slb
[nr
];
686 #if 0 // XXX implement bridge mode?
687 if (env
->spr
[SPR_ASR
] & 1) {
688 target_phys_addr_t sr_base
;
690 sr_base
= env
->spr
[SPR_ASR
] & 0xfffffffffffff000;
691 sr_base
+= (12 * nr
);
693 retval
->tmp64
= ldq_phys(sr_base
);
694 retval
->tmp
= ldl_phys(sr_base
+ 8);
701 static void slb_set_entry(CPUPPCState
*env
, int nr
, ppc_slb_t
*slb
)
703 ppc_slb_t
*entry
= &env
->slb
[nr
];
708 entry
->tmp64
= slb
->tmp64
;
709 entry
->tmp
= slb
->tmp
;
712 static inline int slb_is_valid(ppc_slb_t
*slb
)
714 return (int)(slb
->tmp64
& 0x0000000008000000ULL
);
717 static inline void slb_invalidate(ppc_slb_t
*slb
)
719 slb
->tmp64
&= ~0x0000000008000000ULL
;
722 static inline int slb_lookup(CPUPPCState
*env
, target_ulong eaddr
,
723 target_ulong
*vsid
, target_ulong
*page_mask
,
724 int *attr
, int *target_page_bits
)
730 LOG_SLB("%s: eaddr " TARGET_FMT_lx
"\n", __func__
, eaddr
);
731 mask
= 0x0000000000000000ULL
; /* Avoid gcc warning */
732 for (n
= 0; n
< env
->slb_nr
; n
++) {
733 ppc_slb_t
*slb
= slb_get_entry(env
, n
);
735 LOG_SLB("%s: seg %d %016" PRIx64
" %08"
736 PRIx32
"\n", __func__
, n
, slb
->tmp64
, slb
->tmp
);
737 if (slb_is_valid(slb
)) {
738 /* SLB entry is valid */
739 if (slb
->tmp
& 0x8) {
741 mask
= 0xFFFF000000000000ULL
;
742 if (target_page_bits
)
743 *target_page_bits
= 24; // XXX 16M pages?
746 mask
= 0xFFFFFFFFF0000000ULL
;
747 if (target_page_bits
)
748 *target_page_bits
= TARGET_PAGE_BITS
;
750 if ((eaddr
& mask
) == (slb
->tmp64
& mask
)) {
752 *vsid
= ((slb
->tmp64
<< 24) | (slb
->tmp
>> 8)) & 0x0003FFFFFFFFFFFFULL
;
754 *attr
= slb
->tmp
& 0xFF;
764 void ppc_slb_invalidate_all (CPUPPCState
*env
)
766 int n
, do_invalidate
;
769 /* XXX: Warning: slbia never invalidates the first segment */
770 for (n
= 1; n
< env
->slb_nr
; n
++) {
771 ppc_slb_t
*slb
= slb_get_entry(env
, n
);
773 if (slb_is_valid(slb
)) {
775 slb_set_entry(env
, n
, slb
);
776 /* XXX: given the fact that segment size is 256 MB or 1TB,
777 * and we still don't have a tlb_flush_mask(env, n, mask)
778 * in Qemu, we just invalidate all TLBs
787 void ppc_slb_invalidate_one (CPUPPCState
*env
, uint64_t T0
)
789 target_ulong vsid
, page_mask
;
793 n
= slb_lookup(env
, T0
, &vsid
, &page_mask
, &attr
, NULL
);
795 ppc_slb_t
*slb
= slb_get_entry(env
, n
);
797 if (slb_is_valid(slb
)) {
799 slb_set_entry(env
, n
, slb
);
800 /* XXX: given the fact that segment size is 256 MB or 1TB,
801 * and we still don't have a tlb_flush_mask(env, n, mask)
802 * in Qemu, we just invalidate all TLBs
809 target_ulong
ppc_load_slb (CPUPPCState
*env
, int slb_nr
)
812 ppc_slb_t
*slb
= slb_get_entry(env
, slb_nr
);
814 if (slb_is_valid(slb
)) {
815 /* SLB entry is valid */
816 /* Copy SLB bits 62:88 to Rt 37:63 (VSID 23:49) */
817 rt
= slb
->tmp
>> 8; /* 65:88 => 40:63 */
818 rt
|= (slb
->tmp64
& 0x7) << 24; /* 62:64 => 37:39 */
819 /* Copy SLB bits 89:92 to Rt 33:36 (KsKpNL) */
820 rt
|= ((slb
->tmp
>> 4) & 0xF) << 27;
824 LOG_SLB("%s: %016" PRIx64
" %08" PRIx32
" => %d "
825 TARGET_FMT_lx
"\n", __func__
, slb
->tmp64
, slb
->tmp
, slb_nr
, rt
);
830 void ppc_store_slb (CPUPPCState
*env
, target_ulong rb
, target_ulong rs
)
836 int flags
, valid
, slb_nr
;
839 flags
= ((rs
>> 8) & 0xf);
842 valid
= (rb
& (1 << 27));
845 slb
= slb_get_entry(env
, slb_nr
);
846 slb
->tmp64
= (esid
<< 28) | valid
| (vsid
>> 24);
847 slb
->tmp
= (vsid
<< 8) | (flags
<< 3);
849 LOG_SLB("%s: %d " TARGET_FMT_lx
" - " TARGET_FMT_lx
" => %016" PRIx64
850 " %08" PRIx32
"\n", __func__
, slb_nr
, rb
, rs
, slb
->tmp64
,
853 slb_set_entry(env
, slb_nr
, slb
);
855 #endif /* defined(TARGET_PPC64) */
857 /* Perform segment based translation */
858 static inline target_phys_addr_t
get_pgaddr(target_phys_addr_t sdr1
,
860 target_phys_addr_t hash
,
861 target_phys_addr_t mask
)
863 return (sdr1
& ((target_phys_addr_t
)(-1ULL) << sdr_sh
)) | (hash
& mask
);
866 static inline int get_segment(CPUState
*env
, mmu_ctx_t
*ctx
,
867 target_ulong eaddr
, int rw
, int type
)
869 target_phys_addr_t sdr
, hash
, mask
, sdr_mask
, htab_mask
;
870 target_ulong sr
, vsid
, vsid_mask
, pgidx
, page_mask
;
871 #if defined(TARGET_PPC64)
874 int ds
, vsid_sh
, sdr_sh
, pr
, target_page_bits
;
878 #if defined(TARGET_PPC64)
879 if (env
->mmu_model
& POWERPC_MMU_64
) {
880 LOG_MMU("Check SLBs\n");
881 ret
= slb_lookup(env
, eaddr
, &vsid
, &page_mask
, &attr
,
885 ctx
->key
= ((attr
& 0x40) && (pr
!= 0)) ||
886 ((attr
& 0x80) && (pr
== 0)) ? 1 : 0;
888 ctx
->nx
= attr
& 0x10 ? 1 : 0;
890 vsid_mask
= 0x00003FFFFFFFFF80ULL
;
895 #endif /* defined(TARGET_PPC64) */
897 sr
= env
->sr
[eaddr
>> 28];
898 page_mask
= 0x0FFFFFFF;
899 ctx
->key
= (((sr
& 0x20000000) && (pr
!= 0)) ||
900 ((sr
& 0x40000000) && (pr
== 0))) ? 1 : 0;
901 ds
= sr
& 0x80000000 ? 1 : 0;
902 ctx
->nx
= sr
& 0x10000000 ? 1 : 0;
903 vsid
= sr
& 0x00FFFFFF;
904 vsid_mask
= 0x01FFFFC0;
908 target_page_bits
= TARGET_PAGE_BITS
;
909 LOG_MMU("Check segment v=" TARGET_FMT_lx
" %d " TARGET_FMT_lx
" nip="
910 TARGET_FMT_lx
" lr=" TARGET_FMT_lx
911 " ir=%d dr=%d pr=%d %d t=%d\n",
912 eaddr
, (int)(eaddr
>> 28), sr
, env
->nip
, env
->lr
, (int)msr_ir
,
913 (int)msr_dr
, pr
!= 0 ? 1 : 0, rw
, type
);
915 LOG_MMU("pte segment: key=%d ds %d nx %d vsid " TARGET_FMT_lx
"\n",
916 ctx
->key
, ds
, ctx
->nx
, vsid
);
919 /* Check if instruction fetch is allowed, if needed */
920 if (type
!= ACCESS_CODE
|| ctx
->nx
== 0) {
921 /* Page address translation */
922 /* Primary table address */
924 pgidx
= (eaddr
& page_mask
) >> target_page_bits
;
925 #if defined(TARGET_PPC64)
926 if (env
->mmu_model
& POWERPC_MMU_64
) {
927 htab_mask
= 0x0FFFFFFF >> (28 - (sdr
& 0x1F));
928 /* XXX: this is false for 1 TB segments */
929 hash
= ((vsid
^ pgidx
) << vsid_sh
) & vsid_mask
;
933 htab_mask
= sdr
& 0x000001FF;
934 hash
= ((vsid
^ pgidx
) << vsid_sh
) & vsid_mask
;
936 mask
= (htab_mask
<< sdr_sh
) | sdr_mask
;
937 LOG_MMU("sdr " TARGET_FMT_plx
" sh %d hash " TARGET_FMT_plx
938 " mask " TARGET_FMT_plx
" " TARGET_FMT_lx
"\n",
939 sdr
, sdr_sh
, hash
, mask
, page_mask
);
940 ctx
->pg_addr
[0] = get_pgaddr(sdr
, sdr_sh
, hash
, mask
);
941 /* Secondary table address */
942 hash
= (~hash
) & vsid_mask
;
943 LOG_MMU("sdr " TARGET_FMT_plx
" sh %d hash " TARGET_FMT_plx
944 " mask " TARGET_FMT_plx
"\n", sdr
, sdr_sh
, hash
, mask
);
945 ctx
->pg_addr
[1] = get_pgaddr(sdr
, sdr_sh
, hash
, mask
);
946 #if defined(TARGET_PPC64)
947 if (env
->mmu_model
& POWERPC_MMU_64
) {
948 /* Only 5 bits of the page index are used in the AVPN */
949 if (target_page_bits
> 23) {
950 ctx
->ptem
= (vsid
<< 12) |
951 ((pgidx
<< (target_page_bits
- 16)) & 0xF80);
953 ctx
->ptem
= (vsid
<< 12) | ((pgidx
>> 4) & 0x0F80);
958 ctx
->ptem
= (vsid
<< 7) | (pgidx
>> 10);
960 /* Initialize real address with an invalid value */
961 ctx
->raddr
= (target_phys_addr_t
)-1ULL;
962 if (unlikely(env
->mmu_model
== POWERPC_MMU_SOFT_6xx
||
963 env
->mmu_model
== POWERPC_MMU_SOFT_74xx
)) {
964 /* Software TLB search */
965 ret
= ppc6xx_tlb_check(env
, ctx
, eaddr
, rw
, type
);
967 LOG_MMU("0 sdr1=" TARGET_FMT_plx
" vsid=" TARGET_FMT_lx
" "
968 "api=" TARGET_FMT_lx
" hash=" TARGET_FMT_plx
969 " pg_addr=" TARGET_FMT_plx
"\n",
970 sdr
, vsid
, pgidx
, hash
, ctx
->pg_addr
[0]);
971 /* Primary table lookup */
972 ret
= find_pte(env
, ctx
, 0, rw
, type
, target_page_bits
);
974 /* Secondary table lookup */
975 if (eaddr
!= 0xEFFFFFFF)
976 LOG_MMU("1 sdr1=" TARGET_FMT_plx
" vsid=" TARGET_FMT_lx
" "
977 "api=" TARGET_FMT_lx
" hash=" TARGET_FMT_plx
978 " pg_addr=" TARGET_FMT_plx
"\n", sdr
, vsid
,
979 pgidx
, hash
, ctx
->pg_addr
[1]);
980 ret2
= find_pte(env
, ctx
, 1, rw
, type
,
986 #if defined (DUMP_PAGE_TABLES)
987 if (qemu_log_enabled()) {
988 target_phys_addr_t curaddr
;
989 uint32_t a0
, a1
, a2
, a3
;
990 qemu_log("Page table: " TARGET_FMT_plx
" len " TARGET_FMT_plx
991 "\n", sdr
, mask
+ 0x80);
992 for (curaddr
= sdr
; curaddr
< (sdr
+ mask
+ 0x80);
994 a0
= ldl_phys(curaddr
);
995 a1
= ldl_phys(curaddr
+ 4);
996 a2
= ldl_phys(curaddr
+ 8);
997 a3
= ldl_phys(curaddr
+ 12);
998 if (a0
!= 0 || a1
!= 0 || a2
!= 0 || a3
!= 0) {
999 qemu_log(TARGET_FMT_plx
": %08x %08x %08x %08x\n",
1000 curaddr
, a0
, a1
, a2
, a3
);
1006 LOG_MMU("No access allowed\n");
1010 LOG_MMU("direct store...\n");
1011 /* Direct-store segment : absolutely *BUGGY* for now */
1014 /* Integer load/store : only access allowed */
1017 /* No code fetch is allowed in direct-store areas */
1020 /* Floating point load/store */
1023 /* lwarx, ldarx or srwcx. */
1026 /* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi */
1027 /* Should make the instruction do no-op.
1028 * As it already do no-op, it's quite easy :-)
1033 /* eciwx or ecowx */
1036 qemu_log("ERROR: instruction should not need "
1037 "address translation\n");
1040 if ((rw
== 1 || ctx
->key
!= 1) && (rw
== 0 || ctx
->key
!= 0)) {
1051 /* Generic TLB check function for embedded PowerPC implementations */
1052 static inline int ppcemb_tlb_check(CPUState
*env
, ppcemb_tlb_t
*tlb
,
1053 target_phys_addr_t
*raddrp
,
1054 target_ulong address
, uint32_t pid
, int ext
,
1059 /* Check valid flag */
1060 if (!(tlb
->prot
& PAGE_VALID
)) {
1061 qemu_log("%s: TLB %d not valid\n", __func__
, i
);
1064 mask
= ~(tlb
->size
- 1);
1065 LOG_SWTLB("%s: TLB %d address " TARGET_FMT_lx
" PID %u <=> " TARGET_FMT_lx
1066 " " TARGET_FMT_lx
" %u\n", __func__
, i
, address
, pid
, tlb
->EPN
,
1067 mask
, (uint32_t)tlb
->PID
);
1069 if (tlb
->PID
!= 0 && tlb
->PID
!= pid
)
1071 /* Check effective address */
1072 if ((address
& mask
) != tlb
->EPN
)
1074 *raddrp
= (tlb
->RPN
& mask
) | (address
& ~mask
);
1075 #if (TARGET_PHYS_ADDR_BITS >= 36)
1077 /* Extend the physical address to 36 bits */
1078 *raddrp
|= (target_phys_addr_t
)(tlb
->RPN
& 0xF) << 32;
1085 /* Generic TLB search function for PowerPC embedded implementations */
1086 int ppcemb_tlb_search (CPUPPCState
*env
, target_ulong address
, uint32_t pid
)
1089 target_phys_addr_t raddr
;
1092 /* Default return value is no match */
1094 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1095 tlb
= &env
->tlb
[i
].tlbe
;
1096 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
, pid
, 0, i
) == 0) {
1105 /* Helpers specific to PowerPC 40x implementations */
1106 static inline void ppc4xx_tlb_invalidate_all(CPUState
*env
)
1111 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1112 tlb
= &env
->tlb
[i
].tlbe
;
1113 tlb
->prot
&= ~PAGE_VALID
;
1118 static inline void ppc4xx_tlb_invalidate_virt(CPUState
*env
,
1119 target_ulong eaddr
, uint32_t pid
)
1121 #if !defined(FLUSH_ALL_TLBS)
1123 target_phys_addr_t raddr
;
1124 target_ulong page
, end
;
1127 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1128 tlb
= &env
->tlb
[i
].tlbe
;
1129 if (ppcemb_tlb_check(env
, tlb
, &raddr
, eaddr
, pid
, 0, i
) == 0) {
1130 end
= tlb
->EPN
+ tlb
->size
;
1131 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
1132 tlb_flush_page(env
, page
);
1133 tlb
->prot
&= ~PAGE_VALID
;
1138 ppc4xx_tlb_invalidate_all(env
);
1142 static int mmu40x_get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
,
1143 target_ulong address
, int rw
, int access_type
)
1146 target_phys_addr_t raddr
;
1147 int i
, ret
, zsel
, zpr
, pr
;
1150 raddr
= (target_phys_addr_t
)-1ULL;
1152 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1153 tlb
= &env
->tlb
[i
].tlbe
;
1154 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
,
1155 env
->spr
[SPR_40x_PID
], 0, i
) < 0)
1157 zsel
= (tlb
->attr
>> 4) & 0xF;
1158 zpr
= (env
->spr
[SPR_40x_ZPR
] >> (30 - (2 * zsel
))) & 0x3;
1159 LOG_SWTLB("%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",
1160 __func__
, i
, zsel
, zpr
, rw
, tlb
->attr
);
1161 /* Check execute enable bit */
1168 /* All accesses granted */
1169 ctx
->prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
1174 /* Raise Zone protection fault. */
1175 env
->spr
[SPR_40x_ESR
] = 1 << 22;
1183 /* Check from TLB entry */
1184 /* XXX: there is a problem here or in the TLB fill code... */
1185 ctx
->prot
= tlb
->prot
;
1186 ctx
->prot
|= PAGE_EXEC
;
1187 ret
= check_prot(ctx
->prot
, rw
, access_type
);
1189 env
->spr
[SPR_40x_ESR
] = 0;
1194 LOG_SWTLB("%s: access granted " TARGET_FMT_lx
" => " TARGET_FMT_plx
1195 " %d %d\n", __func__
, address
, ctx
->raddr
, ctx
->prot
,
1200 LOG_SWTLB("%s: access refused " TARGET_FMT_lx
" => " TARGET_FMT_plx
1201 " %d %d\n", __func__
, address
, raddr
, ctx
->prot
, ret
);
1206 void store_40x_sler (CPUPPCState
*env
, uint32_t val
)
1208 /* XXX: TO BE FIXED */
1209 if (val
!= 0x00000000) {
1210 cpu_abort(env
, "Little-endian regions are not supported by now\n");
1212 env
->spr
[SPR_405_SLER
] = val
;
1215 static int mmubooke_get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
,
1216 target_ulong address
, int rw
,
1220 target_phys_addr_t raddr
;
1224 raddr
= (target_phys_addr_t
)-1ULL;
1225 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1226 tlb
= &env
->tlb
[i
].tlbe
;
1227 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
,
1228 env
->spr
[SPR_BOOKE_PID
], 1, i
) < 0)
1231 prot
= tlb
->prot
& 0xF;
1233 prot
= (tlb
->prot
>> 4) & 0xF;
1234 /* Check the address space */
1235 if (access_type
== ACCESS_CODE
) {
1236 if (msr_ir
!= (tlb
->attr
& 1))
1239 if (prot
& PAGE_EXEC
) {
1245 if (msr_dr
!= (tlb
->attr
& 1))
1248 if ((!rw
&& prot
& PAGE_READ
) || (rw
&& (prot
& PAGE_WRITE
))) {
1261 static inline int check_physical(CPUState
*env
, mmu_ctx_t
*ctx
,
1262 target_ulong eaddr
, int rw
)
1267 ctx
->prot
= PAGE_READ
| PAGE_EXEC
;
1269 switch (env
->mmu_model
) {
1270 case POWERPC_MMU_32B
:
1271 case POWERPC_MMU_601
:
1272 case POWERPC_MMU_SOFT_6xx
:
1273 case POWERPC_MMU_SOFT_74xx
:
1274 case POWERPC_MMU_SOFT_4xx
:
1275 case POWERPC_MMU_REAL
:
1276 case POWERPC_MMU_BOOKE
:
1277 ctx
->prot
|= PAGE_WRITE
;
1279 #if defined(TARGET_PPC64)
1280 case POWERPC_MMU_620
:
1281 case POWERPC_MMU_64B
:
1282 /* Real address are 60 bits long */
1283 ctx
->raddr
&= 0x0FFFFFFFFFFFFFFFULL
;
1284 ctx
->prot
|= PAGE_WRITE
;
1287 case POWERPC_MMU_SOFT_4xx_Z
:
1288 if (unlikely(msr_pe
!= 0)) {
1289 /* 403 family add some particular protections,
1290 * using PBL/PBU registers for accesses with no translation.
1293 /* Check PLB validity */
1294 (env
->pb
[0] < env
->pb
[1] &&
1295 /* and address in plb area */
1296 eaddr
>= env
->pb
[0] && eaddr
< env
->pb
[1]) ||
1297 (env
->pb
[2] < env
->pb
[3] &&
1298 eaddr
>= env
->pb
[2] && eaddr
< env
->pb
[3]) ? 1 : 0;
1299 if (in_plb
^ msr_px
) {
1300 /* Access in protected area */
1302 /* Access is not allowed */
1306 /* Read-write access is allowed */
1307 ctx
->prot
|= PAGE_WRITE
;
1311 case POWERPC_MMU_MPC8xx
:
1313 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1315 case POWERPC_MMU_BOOKE_FSL
:
1317 cpu_abort(env
, "BookE FSL MMU model not implemented\n");
1320 cpu_abort(env
, "Unknown or invalid MMU model\n");
1327 int get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
, target_ulong eaddr
,
1328 int rw
, int access_type
)
1333 qemu_log("%s\n", __func__
);
1335 if ((access_type
== ACCESS_CODE
&& msr_ir
== 0) ||
1336 (access_type
!= ACCESS_CODE
&& msr_dr
== 0)) {
1337 /* No address translation */
1338 ret
= check_physical(env
, ctx
, eaddr
, rw
);
1341 switch (env
->mmu_model
) {
1342 case POWERPC_MMU_32B
:
1343 case POWERPC_MMU_601
:
1344 case POWERPC_MMU_SOFT_6xx
:
1345 case POWERPC_MMU_SOFT_74xx
:
1346 /* Try to find a BAT */
1347 if (env
->nb_BATs
!= 0)
1348 ret
= get_bat(env
, ctx
, eaddr
, rw
, access_type
);
1349 #if defined(TARGET_PPC64)
1350 case POWERPC_MMU_620
:
1351 case POWERPC_MMU_64B
:
1354 /* We didn't match any BAT entry or don't have BATs */
1355 ret
= get_segment(env
, ctx
, eaddr
, rw
, access_type
);
1358 case POWERPC_MMU_SOFT_4xx
:
1359 case POWERPC_MMU_SOFT_4xx_Z
:
1360 ret
= mmu40x_get_physical_address(env
, ctx
, eaddr
,
1363 case POWERPC_MMU_BOOKE
:
1364 ret
= mmubooke_get_physical_address(env
, ctx
, eaddr
,
1367 case POWERPC_MMU_MPC8xx
:
1369 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1371 case POWERPC_MMU_BOOKE_FSL
:
1373 cpu_abort(env
, "BookE FSL MMU model not implemented\n");
1375 case POWERPC_MMU_REAL
:
1376 cpu_abort(env
, "PowerPC in real mode do not do any translation\n");
1379 cpu_abort(env
, "Unknown or invalid MMU model\n");
1384 qemu_log("%s address " TARGET_FMT_lx
" => %d " TARGET_FMT_plx
"\n",
1385 __func__
, eaddr
, ret
, ctx
->raddr
);
1391 target_phys_addr_t
cpu_get_phys_page_debug (CPUState
*env
, target_ulong addr
)
1395 if (unlikely(get_physical_address(env
, &ctx
, addr
, 0, ACCESS_INT
) != 0))
1398 return ctx
.raddr
& TARGET_PAGE_MASK
;
1401 /* Perform address translation */
1402 int cpu_ppc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
1403 int mmu_idx
, int is_softmmu
)
1412 access_type
= ACCESS_CODE
;
1415 access_type
= env
->access_type
;
1417 ret
= get_physical_address(env
, &ctx
, address
, rw
, access_type
);
1419 ret
= tlb_set_page_exec(env
, address
& TARGET_PAGE_MASK
,
1420 ctx
.raddr
& TARGET_PAGE_MASK
, ctx
.prot
,
1421 mmu_idx
, is_softmmu
);
1422 } else if (ret
< 0) {
1424 if (access_type
== ACCESS_CODE
) {
1427 /* No matches in page tables or TLB */
1428 switch (env
->mmu_model
) {
1429 case POWERPC_MMU_SOFT_6xx
:
1430 env
->exception_index
= POWERPC_EXCP_IFTLB
;
1431 env
->error_code
= 1 << 18;
1432 env
->spr
[SPR_IMISS
] = address
;
1433 env
->spr
[SPR_ICMP
] = 0x80000000 | ctx
.ptem
;
1435 case POWERPC_MMU_SOFT_74xx
:
1436 env
->exception_index
= POWERPC_EXCP_IFTLB
;
1438 case POWERPC_MMU_SOFT_4xx
:
1439 case POWERPC_MMU_SOFT_4xx_Z
:
1440 env
->exception_index
= POWERPC_EXCP_ITLB
;
1441 env
->error_code
= 0;
1442 env
->spr
[SPR_40x_DEAR
] = address
;
1443 env
->spr
[SPR_40x_ESR
] = 0x00000000;
1445 case POWERPC_MMU_32B
:
1446 case POWERPC_MMU_601
:
1447 #if defined(TARGET_PPC64)
1448 case POWERPC_MMU_620
:
1449 case POWERPC_MMU_64B
:
1451 env
->exception_index
= POWERPC_EXCP_ISI
;
1452 env
->error_code
= 0x40000000;
1454 case POWERPC_MMU_BOOKE
:
1456 cpu_abort(env
, "BookE MMU model is not implemented\n");
1458 case POWERPC_MMU_BOOKE_FSL
:
1460 cpu_abort(env
, "BookE FSL MMU model is not implemented\n");
1462 case POWERPC_MMU_MPC8xx
:
1464 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1466 case POWERPC_MMU_REAL
:
1467 cpu_abort(env
, "PowerPC in real mode should never raise "
1468 "any MMU exceptions\n");
1471 cpu_abort(env
, "Unknown or invalid MMU model\n");
1476 /* Access rights violation */
1477 env
->exception_index
= POWERPC_EXCP_ISI
;
1478 env
->error_code
= 0x08000000;
1481 /* No execute protection violation */
1482 env
->exception_index
= POWERPC_EXCP_ISI
;
1483 env
->error_code
= 0x10000000;
1486 /* Direct store exception */
1487 /* No code fetch is allowed in direct-store areas */
1488 env
->exception_index
= POWERPC_EXCP_ISI
;
1489 env
->error_code
= 0x10000000;
1491 #if defined(TARGET_PPC64)
1493 /* No match in segment table */
1494 if (env
->mmu_model
== POWERPC_MMU_620
) {
1495 env
->exception_index
= POWERPC_EXCP_ISI
;
1496 /* XXX: this might be incorrect */
1497 env
->error_code
= 0x40000000;
1499 env
->exception_index
= POWERPC_EXCP_ISEG
;
1500 env
->error_code
= 0;
1508 /* No matches in page tables or TLB */
1509 switch (env
->mmu_model
) {
1510 case POWERPC_MMU_SOFT_6xx
:
1512 env
->exception_index
= POWERPC_EXCP_DSTLB
;
1513 env
->error_code
= 1 << 16;
1515 env
->exception_index
= POWERPC_EXCP_DLTLB
;
1516 env
->error_code
= 0;
1518 env
->spr
[SPR_DMISS
] = address
;
1519 env
->spr
[SPR_DCMP
] = 0x80000000 | ctx
.ptem
;
1521 env
->error_code
|= ctx
.key
<< 19;
1522 env
->spr
[SPR_HASH1
] = ctx
.pg_addr
[0];
1523 env
->spr
[SPR_HASH2
] = ctx
.pg_addr
[1];
1525 case POWERPC_MMU_SOFT_74xx
:
1527 env
->exception_index
= POWERPC_EXCP_DSTLB
;
1529 env
->exception_index
= POWERPC_EXCP_DLTLB
;
1532 /* Implement LRU algorithm */
1533 env
->error_code
= ctx
.key
<< 19;
1534 env
->spr
[SPR_TLBMISS
] = (address
& ~((target_ulong
)0x3)) |
1535 ((env
->last_way
+ 1) & (env
->nb_ways
- 1));
1536 env
->spr
[SPR_PTEHI
] = 0x80000000 | ctx
.ptem
;
1538 case POWERPC_MMU_SOFT_4xx
:
1539 case POWERPC_MMU_SOFT_4xx_Z
:
1540 env
->exception_index
= POWERPC_EXCP_DTLB
;
1541 env
->error_code
= 0;
1542 env
->spr
[SPR_40x_DEAR
] = address
;
1544 env
->spr
[SPR_40x_ESR
] = 0x00800000;
1546 env
->spr
[SPR_40x_ESR
] = 0x00000000;
1548 case POWERPC_MMU_32B
:
1549 case POWERPC_MMU_601
:
1550 #if defined(TARGET_PPC64)
1551 case POWERPC_MMU_620
:
1552 case POWERPC_MMU_64B
:
1554 env
->exception_index
= POWERPC_EXCP_DSI
;
1555 env
->error_code
= 0;
1556 env
->spr
[SPR_DAR
] = address
;
1558 env
->spr
[SPR_DSISR
] = 0x42000000;
1560 env
->spr
[SPR_DSISR
] = 0x40000000;
1562 case POWERPC_MMU_MPC8xx
:
1564 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1566 case POWERPC_MMU_BOOKE
:
1568 cpu_abort(env
, "BookE MMU model is not implemented\n");
1570 case POWERPC_MMU_BOOKE_FSL
:
1572 cpu_abort(env
, "BookE FSL MMU model is not implemented\n");
1574 case POWERPC_MMU_REAL
:
1575 cpu_abort(env
, "PowerPC in real mode should never raise "
1576 "any MMU exceptions\n");
1579 cpu_abort(env
, "Unknown or invalid MMU model\n");
1584 /* Access rights violation */
1585 env
->exception_index
= POWERPC_EXCP_DSI
;
1586 env
->error_code
= 0;
1587 if (env
->mmu_model
== POWERPC_MMU_SOFT_4xx
1588 || env
->mmu_model
== POWERPC_MMU_SOFT_4xx_Z
) {
1589 env
->spr
[SPR_40x_DEAR
] = address
;
1591 env
->spr
[SPR_40x_ESR
] |= 0x00800000;
1594 env
->spr
[SPR_DAR
] = address
;
1596 env
->spr
[SPR_DSISR
] = 0x0A000000;
1598 env
->spr
[SPR_DSISR
] = 0x08000000;
1603 /* Direct store exception */
1604 switch (access_type
) {
1606 /* Floating point load/store */
1607 env
->exception_index
= POWERPC_EXCP_ALIGN
;
1608 env
->error_code
= POWERPC_EXCP_ALIGN_FP
;
1609 env
->spr
[SPR_DAR
] = address
;
1612 /* lwarx, ldarx or stwcx. */
1613 env
->exception_index
= POWERPC_EXCP_DSI
;
1614 env
->error_code
= 0;
1615 env
->spr
[SPR_DAR
] = address
;
1617 env
->spr
[SPR_DSISR
] = 0x06000000;
1619 env
->spr
[SPR_DSISR
] = 0x04000000;
1622 /* eciwx or ecowx */
1623 env
->exception_index
= POWERPC_EXCP_DSI
;
1624 env
->error_code
= 0;
1625 env
->spr
[SPR_DAR
] = address
;
1627 env
->spr
[SPR_DSISR
] = 0x06100000;
1629 env
->spr
[SPR_DSISR
] = 0x04100000;
1632 printf("DSI: invalid exception (%d)\n", ret
);
1633 env
->exception_index
= POWERPC_EXCP_PROGRAM
;
1635 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_INVAL
;
1636 env
->spr
[SPR_DAR
] = address
;
1640 #if defined(TARGET_PPC64)
1642 /* No match in segment table */
1643 if (env
->mmu_model
== POWERPC_MMU_620
) {
1644 env
->exception_index
= POWERPC_EXCP_DSI
;
1645 env
->error_code
= 0;
1646 env
->spr
[SPR_DAR
] = address
;
1647 /* XXX: this might be incorrect */
1649 env
->spr
[SPR_DSISR
] = 0x42000000;
1651 env
->spr
[SPR_DSISR
] = 0x40000000;
1653 env
->exception_index
= POWERPC_EXCP_DSEG
;
1654 env
->error_code
= 0;
1655 env
->spr
[SPR_DAR
] = address
;
1662 printf("%s: set exception to %d %02x\n", __func__
,
1663 env
->exception
, env
->error_code
);
1671 /*****************************************************************************/
1672 /* BATs management */
1673 #if !defined(FLUSH_ALL_TLBS)
1674 static inline void do_invalidate_BAT(CPUPPCState
*env
, target_ulong BATu
,
1677 target_ulong base
, end
, page
;
1679 base
= BATu
& ~0x0001FFFF;
1680 end
= base
+ mask
+ 0x00020000;
1681 LOG_BATS("Flush BAT from " TARGET_FMT_lx
" to " TARGET_FMT_lx
" ("
1682 TARGET_FMT_lx
")\n", base
, end
, mask
);
1683 for (page
= base
; page
!= end
; page
+= TARGET_PAGE_SIZE
)
1684 tlb_flush_page(env
, page
);
1685 LOG_BATS("Flush done\n");
1689 static inline void dump_store_bat(CPUPPCState
*env
, char ID
, int ul
, int nr
,
1692 LOG_BATS("Set %cBAT%d%c to " TARGET_FMT_lx
" (" TARGET_FMT_lx
")\n", ID
,
1693 nr
, ul
== 0 ? 'u' : 'l', value
, env
->nip
);
1696 void ppc_store_ibatu (CPUPPCState
*env
, int nr
, target_ulong value
)
1700 dump_store_bat(env
, 'I', 0, nr
, value
);
1701 if (env
->IBAT
[0][nr
] != value
) {
1702 mask
= (value
<< 15) & 0x0FFE0000UL
;
1703 #if !defined(FLUSH_ALL_TLBS)
1704 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1706 /* When storing valid upper BAT, mask BEPI and BRPN
1707 * and invalidate all TLBs covered by this BAT
1709 mask
= (value
<< 15) & 0x0FFE0000UL
;
1710 env
->IBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1711 (value
& ~0x0001FFFFUL
& ~mask
);
1712 env
->IBAT
[1][nr
] = (env
->IBAT
[1][nr
] & 0x0000007B) |
1713 (env
->IBAT
[1][nr
] & ~0x0001FFFF & ~mask
);
1714 #if !defined(FLUSH_ALL_TLBS)
1715 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1722 void ppc_store_ibatl (CPUPPCState
*env
, int nr
, target_ulong value
)
1724 dump_store_bat(env
, 'I', 1, nr
, value
);
1725 env
->IBAT
[1][nr
] = value
;
1728 void ppc_store_dbatu (CPUPPCState
*env
, int nr
, target_ulong value
)
1732 dump_store_bat(env
, 'D', 0, nr
, value
);
1733 if (env
->DBAT
[0][nr
] != value
) {
1734 /* When storing valid upper BAT, mask BEPI and BRPN
1735 * and invalidate all TLBs covered by this BAT
1737 mask
= (value
<< 15) & 0x0FFE0000UL
;
1738 #if !defined(FLUSH_ALL_TLBS)
1739 do_invalidate_BAT(env
, env
->DBAT
[0][nr
], mask
);
1741 mask
= (value
<< 15) & 0x0FFE0000UL
;
1742 env
->DBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1743 (value
& ~0x0001FFFFUL
& ~mask
);
1744 env
->DBAT
[1][nr
] = (env
->DBAT
[1][nr
] & 0x0000007B) |
1745 (env
->DBAT
[1][nr
] & ~0x0001FFFF & ~mask
);
1746 #if !defined(FLUSH_ALL_TLBS)
1747 do_invalidate_BAT(env
, env
->DBAT
[0][nr
], mask
);
1754 void ppc_store_dbatl (CPUPPCState
*env
, int nr
, target_ulong value
)
1756 dump_store_bat(env
, 'D', 1, nr
, value
);
1757 env
->DBAT
[1][nr
] = value
;
1760 void ppc_store_ibatu_601 (CPUPPCState
*env
, int nr
, target_ulong value
)
1765 dump_store_bat(env
, 'I', 0, nr
, value
);
1766 if (env
->IBAT
[0][nr
] != value
) {
1768 mask
= (env
->IBAT
[1][nr
] << 17) & 0x0FFE0000UL
;
1769 if (env
->IBAT
[1][nr
] & 0x40) {
1770 /* Invalidate BAT only if it is valid */
1771 #if !defined(FLUSH_ALL_TLBS)
1772 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1777 /* When storing valid upper BAT, mask BEPI and BRPN
1778 * and invalidate all TLBs covered by this BAT
1780 env
->IBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1781 (value
& ~0x0001FFFFUL
& ~mask
);
1782 env
->DBAT
[0][nr
] = env
->IBAT
[0][nr
];
1783 if (env
->IBAT
[1][nr
] & 0x40) {
1784 #if !defined(FLUSH_ALL_TLBS)
1785 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1790 #if defined(FLUSH_ALL_TLBS)
1797 void ppc_store_ibatl_601 (CPUPPCState
*env
, int nr
, target_ulong value
)
1802 dump_store_bat(env
, 'I', 1, nr
, value
);
1803 if (env
->IBAT
[1][nr
] != value
) {
1805 if (env
->IBAT
[1][nr
] & 0x40) {
1806 #if !defined(FLUSH_ALL_TLBS)
1807 mask
= (env
->IBAT
[1][nr
] << 17) & 0x0FFE0000UL
;
1808 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1814 #if !defined(FLUSH_ALL_TLBS)
1815 mask
= (value
<< 17) & 0x0FFE0000UL
;
1816 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1821 env
->IBAT
[1][nr
] = value
;
1822 env
->DBAT
[1][nr
] = value
;
1823 #if defined(FLUSH_ALL_TLBS)
1830 /*****************************************************************************/
1831 /* TLB management */
1832 void ppc_tlb_invalidate_all (CPUPPCState
*env
)
1834 switch (env
->mmu_model
) {
1835 case POWERPC_MMU_SOFT_6xx
:
1836 case POWERPC_MMU_SOFT_74xx
:
1837 ppc6xx_tlb_invalidate_all(env
);
1839 case POWERPC_MMU_SOFT_4xx
:
1840 case POWERPC_MMU_SOFT_4xx_Z
:
1841 ppc4xx_tlb_invalidate_all(env
);
1843 case POWERPC_MMU_REAL
:
1844 cpu_abort(env
, "No TLB for PowerPC 4xx in real mode\n");
1846 case POWERPC_MMU_MPC8xx
:
1848 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1850 case POWERPC_MMU_BOOKE
:
1852 cpu_abort(env
, "BookE MMU model is not implemented\n");
1854 case POWERPC_MMU_BOOKE_FSL
:
1857 cpu_abort(env
, "BookE MMU model is not implemented\n");
1859 case POWERPC_MMU_32B
:
1860 case POWERPC_MMU_601
:
1861 #if defined(TARGET_PPC64)
1862 case POWERPC_MMU_620
:
1863 case POWERPC_MMU_64B
:
1864 #endif /* defined(TARGET_PPC64) */
1869 cpu_abort(env
, "Unknown MMU model\n");
1874 void ppc_tlb_invalidate_one (CPUPPCState
*env
, target_ulong addr
)
1876 #if !defined(FLUSH_ALL_TLBS)
1877 addr
&= TARGET_PAGE_MASK
;
1878 switch (env
->mmu_model
) {
1879 case POWERPC_MMU_SOFT_6xx
:
1880 case POWERPC_MMU_SOFT_74xx
:
1881 ppc6xx_tlb_invalidate_virt(env
, addr
, 0);
1882 if (env
->id_tlbs
== 1)
1883 ppc6xx_tlb_invalidate_virt(env
, addr
, 1);
1885 case POWERPC_MMU_SOFT_4xx
:
1886 case POWERPC_MMU_SOFT_4xx_Z
:
1887 ppc4xx_tlb_invalidate_virt(env
, addr
, env
->spr
[SPR_40x_PID
]);
1889 case POWERPC_MMU_REAL
:
1890 cpu_abort(env
, "No TLB for PowerPC 4xx in real mode\n");
1892 case POWERPC_MMU_MPC8xx
:
1894 cpu_abort(env
, "MPC8xx MMU model is not implemented\n");
1896 case POWERPC_MMU_BOOKE
:
1898 cpu_abort(env
, "BookE MMU model is not implemented\n");
1900 case POWERPC_MMU_BOOKE_FSL
:
1902 cpu_abort(env
, "BookE FSL MMU model is not implemented\n");
1904 case POWERPC_MMU_32B
:
1905 case POWERPC_MMU_601
:
1906 /* tlbie invalidate TLBs for all segments */
1907 addr
&= ~((target_ulong
)-1ULL << 28);
1908 /* XXX: this case should be optimized,
1909 * giving a mask to tlb_flush_page
1911 tlb_flush_page(env
, addr
| (0x0 << 28));
1912 tlb_flush_page(env
, addr
| (0x1 << 28));
1913 tlb_flush_page(env
, addr
| (0x2 << 28));
1914 tlb_flush_page(env
, addr
| (0x3 << 28));
1915 tlb_flush_page(env
, addr
| (0x4 << 28));
1916 tlb_flush_page(env
, addr
| (0x5 << 28));
1917 tlb_flush_page(env
, addr
| (0x6 << 28));
1918 tlb_flush_page(env
, addr
| (0x7 << 28));
1919 tlb_flush_page(env
, addr
| (0x8 << 28));
1920 tlb_flush_page(env
, addr
| (0x9 << 28));
1921 tlb_flush_page(env
, addr
| (0xA << 28));
1922 tlb_flush_page(env
, addr
| (0xB << 28));
1923 tlb_flush_page(env
, addr
| (0xC << 28));
1924 tlb_flush_page(env
, addr
| (0xD << 28));
1925 tlb_flush_page(env
, addr
| (0xE << 28));
1926 tlb_flush_page(env
, addr
| (0xF << 28));
1928 #if defined(TARGET_PPC64)
1929 case POWERPC_MMU_620
:
1930 case POWERPC_MMU_64B
:
1931 /* tlbie invalidate TLBs for all segments */
1932 /* XXX: given the fact that there are too many segments to invalidate,
1933 * and we still don't have a tlb_flush_mask(env, n, mask) in Qemu,
1934 * we just invalidate all TLBs
1938 #endif /* defined(TARGET_PPC64) */
1941 cpu_abort(env
, "Unknown MMU model\n");
1945 ppc_tlb_invalidate_all(env
);
1949 /*****************************************************************************/
1950 /* Special registers manipulation */
1951 #if defined(TARGET_PPC64)
1952 void ppc_store_asr (CPUPPCState
*env
, target_ulong value
)
1954 if (env
->asr
!= value
) {
1961 void ppc_store_sdr1 (CPUPPCState
*env
, target_ulong value
)
1963 LOG_MMU("%s: " TARGET_FMT_lx
"\n", __func__
, value
);
1964 if (env
->sdr1
!= value
) {
1965 /* XXX: for PowerPC 64, should check that the HTABSIZE value
1973 #if defined(TARGET_PPC64)
1974 target_ulong
ppc_load_sr (CPUPPCState
*env
, int slb_nr
)
1981 void ppc_store_sr (CPUPPCState
*env
, int srnum
, target_ulong value
)
1983 LOG_MMU("%s: reg=%d " TARGET_FMT_lx
" " TARGET_FMT_lx
"\n", __func__
,
1984 srnum
, value
, env
->sr
[srnum
]);
1985 #if defined(TARGET_PPC64)
1986 if (env
->mmu_model
& POWERPC_MMU_64
) {
1987 uint64_t rb
= 0, rs
= 0;
1990 rb
|= ((uint32_t)srnum
& 0xf) << 28;
1991 /* Set the valid bit */
1994 rb
|= (uint32_t)srnum
;
1997 rs
|= (value
& 0xfffffff) << 12;
1999 rs
|= ((value
>> 27) & 0xf) << 9;
2001 ppc_store_slb(env
, rb
, rs
);
2004 if (env
->sr
[srnum
] != value
) {
2005 env
->sr
[srnum
] = value
;
2006 /* Invalidating 256MB of virtual memory in 4kB pages is way longer than
2007 flusing the whole TLB. */
2008 #if !defined(FLUSH_ALL_TLBS) && 0
2010 target_ulong page
, end
;
2011 /* Invalidate 256 MB of virtual memory */
2012 page
= (16 << 20) * srnum
;
2013 end
= page
+ (16 << 20);
2014 for (; page
!= end
; page
+= TARGET_PAGE_SIZE
)
2015 tlb_flush_page(env
, page
);
2022 #endif /* !defined (CONFIG_USER_ONLY) */
2024 /* GDBstub can read and write MSR... */
2025 void ppc_store_msr (CPUPPCState
*env
, target_ulong value
)
2027 hreg_store_msr(env
, value
, 0);
2030 /*****************************************************************************/
2031 /* Exception processing */
2032 #if defined (CONFIG_USER_ONLY)
2033 void do_interrupt (CPUState
*env
)
2035 env
->exception_index
= POWERPC_EXCP_NONE
;
2036 env
->error_code
= 0;
2039 void ppc_hw_interrupt (CPUState
*env
)
2041 env
->exception_index
= POWERPC_EXCP_NONE
;
2042 env
->error_code
= 0;
2044 #else /* defined (CONFIG_USER_ONLY) */
2045 static inline void dump_syscall(CPUState
*env
)
2047 qemu_log_mask(CPU_LOG_INT
, "syscall r0=%016" PRIx64
" r3=%016" PRIx64
2048 " r4=%016" PRIx64
" r5=%016" PRIx64
" r6=%016" PRIx64
2049 " nip=" TARGET_FMT_lx
"\n",
2050 ppc_dump_gpr(env
, 0), ppc_dump_gpr(env
, 3),
2051 ppc_dump_gpr(env
, 4), ppc_dump_gpr(env
, 5),
2052 ppc_dump_gpr(env
, 6), env
->nip
);
2055 /* Note that this function should be greatly optimized
2056 * when called with a constant excp, from ppc_hw_interrupt
2058 static inline void powerpc_excp(CPUState
*env
, int excp_model
, int excp
)
2060 target_ulong msr
, new_msr
, vector
;
2061 int srr0
, srr1
, asrr0
, asrr1
;
2062 int lpes0
, lpes1
, lev
;
2065 /* XXX: find a suitable condition to enable the hypervisor mode */
2066 lpes0
= (env
->spr
[SPR_LPCR
] >> 1) & 1;
2067 lpes1
= (env
->spr
[SPR_LPCR
] >> 2) & 1;
2069 /* Those values ensure we won't enter the hypervisor mode */
2074 qemu_log_mask(CPU_LOG_INT
, "Raise exception at " TARGET_FMT_lx
2075 " => %08x (%02x)\n", env
->nip
, excp
, env
->error_code
);
2082 msr
&= ~((target_ulong
)0x783F0000);
2084 case POWERPC_EXCP_NONE
:
2085 /* Should never happen */
2087 case POWERPC_EXCP_CRITICAL
: /* Critical input */
2088 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2089 switch (excp_model
) {
2090 case POWERPC_EXCP_40x
:
2091 srr0
= SPR_40x_SRR2
;
2092 srr1
= SPR_40x_SRR3
;
2094 case POWERPC_EXCP_BOOKE
:
2095 srr0
= SPR_BOOKE_CSRR0
;
2096 srr1
= SPR_BOOKE_CSRR1
;
2098 case POWERPC_EXCP_G2
:
2104 case POWERPC_EXCP_MCHECK
: /* Machine check exception */
2106 /* Machine check exception is not enabled.
2107 * Enter checkstop state.
2109 if (qemu_log_enabled()) {
2110 qemu_log("Machine check while not allowed. "
2111 "Entering checkstop state\n");
2113 fprintf(stderr
, "Machine check while not allowed. "
2114 "Entering checkstop state\n");
2117 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
2119 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2120 new_msr
&= ~((target_ulong
)1 << MSR_ME
);
2122 /* XXX: find a suitable condition to enable the hypervisor mode */
2123 new_msr
|= (target_ulong
)MSR_HVB
;
2125 /* XXX: should also have something loaded in DAR / DSISR */
2126 switch (excp_model
) {
2127 case POWERPC_EXCP_40x
:
2128 srr0
= SPR_40x_SRR2
;
2129 srr1
= SPR_40x_SRR3
;
2131 case POWERPC_EXCP_BOOKE
:
2132 srr0
= SPR_BOOKE_MCSRR0
;
2133 srr1
= SPR_BOOKE_MCSRR1
;
2134 asrr0
= SPR_BOOKE_CSRR0
;
2135 asrr1
= SPR_BOOKE_CSRR1
;
2141 case POWERPC_EXCP_DSI
: /* Data storage exception */
2142 LOG_EXCP("DSI exception: DSISR=" TARGET_FMT_lx
" DAR=" TARGET_FMT_lx
2143 "\n", env
->spr
[SPR_DSISR
], env
->spr
[SPR_DAR
]);
2144 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2146 new_msr
|= (target_ulong
)MSR_HVB
;
2148 case POWERPC_EXCP_ISI
: /* Instruction storage exception */
2149 LOG_EXCP("ISI exception: msr=" TARGET_FMT_lx
", nip=" TARGET_FMT_lx
2150 "\n", msr
, env
->nip
);
2151 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2153 new_msr
|= (target_ulong
)MSR_HVB
;
2154 msr
|= env
->error_code
;
2156 case POWERPC_EXCP_EXTERNAL
: /* External input */
2157 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2159 new_msr
|= (target_ulong
)MSR_HVB
;
2161 case POWERPC_EXCP_ALIGN
: /* Alignment exception */
2162 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2164 new_msr
|= (target_ulong
)MSR_HVB
;
2165 /* XXX: this is false */
2166 /* Get rS/rD and rA from faulting opcode */
2167 env
->spr
[SPR_DSISR
] |= (ldl_code((env
->nip
- 4)) & 0x03FF0000) >> 16;
2169 case POWERPC_EXCP_PROGRAM
: /* Program exception */
2170 switch (env
->error_code
& ~0xF) {
2171 case POWERPC_EXCP_FP
:
2172 if ((msr_fe0
== 0 && msr_fe1
== 0) || msr_fp
== 0) {
2173 LOG_EXCP("Ignore floating point exception\n");
2174 env
->exception_index
= POWERPC_EXCP_NONE
;
2175 env
->error_code
= 0;
2178 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2180 new_msr
|= (target_ulong
)MSR_HVB
;
2182 if (msr_fe0
== msr_fe1
)
2186 case POWERPC_EXCP_INVAL
:
2187 LOG_EXCP("Invalid instruction at " TARGET_FMT_lx
"\n", env
->nip
);
2188 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2190 new_msr
|= (target_ulong
)MSR_HVB
;
2193 case POWERPC_EXCP_PRIV
:
2194 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2196 new_msr
|= (target_ulong
)MSR_HVB
;
2199 case POWERPC_EXCP_TRAP
:
2200 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2202 new_msr
|= (target_ulong
)MSR_HVB
;
2206 /* Should never occur */
2207 cpu_abort(env
, "Invalid program exception %d. Aborting\n",
2212 case POWERPC_EXCP_FPU
: /* Floating-point unavailable exception */
2213 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2215 new_msr
|= (target_ulong
)MSR_HVB
;
2217 case POWERPC_EXCP_SYSCALL
: /* System call exception */
2218 /* NOTE: this is a temporary hack to support graphics OSI
2219 calls from the MOL driver */
2220 /* XXX: To be removed */
2221 if (env
->gpr
[3] == 0x113724fa && env
->gpr
[4] == 0x77810f9b &&
2223 if (env
->osi_call(env
) != 0) {
2224 env
->exception_index
= POWERPC_EXCP_NONE
;
2225 env
->error_code
= 0;
2230 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2231 lev
= env
->error_code
;
2232 if (lev
== 1 || (lpes0
== 0 && lpes1
== 0))
2233 new_msr
|= (target_ulong
)MSR_HVB
;
2235 case POWERPC_EXCP_APU
: /* Auxiliary processor unavailable */
2236 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2238 case POWERPC_EXCP_DECR
: /* Decrementer exception */
2239 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2241 new_msr
|= (target_ulong
)MSR_HVB
;
2243 case POWERPC_EXCP_FIT
: /* Fixed-interval timer interrupt */
2245 LOG_EXCP("FIT exception\n");
2246 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2248 case POWERPC_EXCP_WDT
: /* Watchdog timer interrupt */
2249 LOG_EXCP("WDT exception\n");
2250 switch (excp_model
) {
2251 case POWERPC_EXCP_BOOKE
:
2252 srr0
= SPR_BOOKE_CSRR0
;
2253 srr1
= SPR_BOOKE_CSRR1
;
2258 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2260 case POWERPC_EXCP_DTLB
: /* Data TLB error */
2261 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2263 case POWERPC_EXCP_ITLB
: /* Instruction TLB error */
2264 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2266 case POWERPC_EXCP_DEBUG
: /* Debug interrupt */
2267 switch (excp_model
) {
2268 case POWERPC_EXCP_BOOKE
:
2269 srr0
= SPR_BOOKE_DSRR0
;
2270 srr1
= SPR_BOOKE_DSRR1
;
2271 asrr0
= SPR_BOOKE_CSRR0
;
2272 asrr1
= SPR_BOOKE_CSRR1
;
2278 cpu_abort(env
, "Debug exception is not implemented yet !\n");
2280 case POWERPC_EXCP_SPEU
: /* SPE/embedded floating-point unavailable */
2281 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2283 case POWERPC_EXCP_EFPDI
: /* Embedded floating-point data interrupt */
2285 cpu_abort(env
, "Embedded floating point data exception "
2286 "is not implemented yet !\n");
2288 case POWERPC_EXCP_EFPRI
: /* Embedded floating-point round interrupt */
2290 cpu_abort(env
, "Embedded floating point round exception "
2291 "is not implemented yet !\n");
2293 case POWERPC_EXCP_EPERFM
: /* Embedded performance monitor interrupt */
2294 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2297 "Performance counter exception is not implemented yet !\n");
2299 case POWERPC_EXCP_DOORI
: /* Embedded doorbell interrupt */
2302 "Embedded doorbell interrupt is not implemented yet !\n");
2304 case POWERPC_EXCP_DOORCI
: /* Embedded doorbell critical interrupt */
2305 switch (excp_model
) {
2306 case POWERPC_EXCP_BOOKE
:
2307 srr0
= SPR_BOOKE_CSRR0
;
2308 srr1
= SPR_BOOKE_CSRR1
;
2314 cpu_abort(env
, "Embedded doorbell critical interrupt "
2315 "is not implemented yet !\n");
2317 case POWERPC_EXCP_RESET
: /* System reset exception */
2318 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2320 /* XXX: find a suitable condition to enable the hypervisor mode */
2321 new_msr
|= (target_ulong
)MSR_HVB
;
2324 case POWERPC_EXCP_DSEG
: /* Data segment exception */
2325 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2327 new_msr
|= (target_ulong
)MSR_HVB
;
2329 case POWERPC_EXCP_ISEG
: /* Instruction segment exception */
2330 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2332 new_msr
|= (target_ulong
)MSR_HVB
;
2334 case POWERPC_EXCP_HDECR
: /* Hypervisor decrementer exception */
2337 new_msr
|= (target_ulong
)MSR_HVB
;
2339 case POWERPC_EXCP_TRACE
: /* Trace exception */
2340 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2342 new_msr
|= (target_ulong
)MSR_HVB
;
2344 case POWERPC_EXCP_HDSI
: /* Hypervisor data storage exception */
2347 new_msr
|= (target_ulong
)MSR_HVB
;
2349 case POWERPC_EXCP_HISI
: /* Hypervisor instruction storage exception */
2352 new_msr
|= (target_ulong
)MSR_HVB
;
2354 case POWERPC_EXCP_HDSEG
: /* Hypervisor data segment exception */
2357 new_msr
|= (target_ulong
)MSR_HVB
;
2359 case POWERPC_EXCP_HISEG
: /* Hypervisor instruction segment exception */
2362 new_msr
|= (target_ulong
)MSR_HVB
;
2364 case POWERPC_EXCP_VPU
: /* Vector unavailable exception */
2365 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2367 new_msr
|= (target_ulong
)MSR_HVB
;
2369 case POWERPC_EXCP_PIT
: /* Programmable interval timer interrupt */
2370 LOG_EXCP("PIT exception\n");
2371 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2373 case POWERPC_EXCP_IO
: /* IO error exception */
2375 cpu_abort(env
, "601 IO error exception is not implemented yet !\n");
2377 case POWERPC_EXCP_RUNM
: /* Run mode exception */
2379 cpu_abort(env
, "601 run mode exception is not implemented yet !\n");
2381 case POWERPC_EXCP_EMUL
: /* Emulation trap exception */
2383 cpu_abort(env
, "602 emulation trap exception "
2384 "is not implemented yet !\n");
2386 case POWERPC_EXCP_IFTLB
: /* Instruction fetch TLB error */
2387 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2388 if (lpes1
== 0) /* XXX: check this */
2389 new_msr
|= (target_ulong
)MSR_HVB
;
2390 switch (excp_model
) {
2391 case POWERPC_EXCP_602
:
2392 case POWERPC_EXCP_603
:
2393 case POWERPC_EXCP_603E
:
2394 case POWERPC_EXCP_G2
:
2396 case POWERPC_EXCP_7x5
:
2398 case POWERPC_EXCP_74xx
:
2401 cpu_abort(env
, "Invalid instruction TLB miss exception\n");
2405 case POWERPC_EXCP_DLTLB
: /* Data load TLB miss */
2406 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2407 if (lpes1
== 0) /* XXX: check this */
2408 new_msr
|= (target_ulong
)MSR_HVB
;
2409 switch (excp_model
) {
2410 case POWERPC_EXCP_602
:
2411 case POWERPC_EXCP_603
:
2412 case POWERPC_EXCP_603E
:
2413 case POWERPC_EXCP_G2
:
2415 case POWERPC_EXCP_7x5
:
2417 case POWERPC_EXCP_74xx
:
2420 cpu_abort(env
, "Invalid data load TLB miss exception\n");
2424 case POWERPC_EXCP_DSTLB
: /* Data store TLB miss */
2425 new_msr
&= ~((target_ulong
)1 << MSR_RI
); /* XXX: check this */
2426 if (lpes1
== 0) /* XXX: check this */
2427 new_msr
|= (target_ulong
)MSR_HVB
;
2428 switch (excp_model
) {
2429 case POWERPC_EXCP_602
:
2430 case POWERPC_EXCP_603
:
2431 case POWERPC_EXCP_603E
:
2432 case POWERPC_EXCP_G2
:
2434 /* Swap temporary saved registers with GPRs */
2435 if (!(new_msr
& ((target_ulong
)1 << MSR_TGPR
))) {
2436 new_msr
|= (target_ulong
)1 << MSR_TGPR
;
2437 hreg_swap_gpr_tgpr(env
);
2440 case POWERPC_EXCP_7x5
:
2442 #if defined (DEBUG_SOFTWARE_TLB)
2443 if (qemu_log_enabled()) {
2445 target_ulong
*miss
, *cmp
;
2447 if (excp
== POWERPC_EXCP_IFTLB
) {
2450 miss
= &env
->spr
[SPR_IMISS
];
2451 cmp
= &env
->spr
[SPR_ICMP
];
2453 if (excp
== POWERPC_EXCP_DLTLB
)
2458 miss
= &env
->spr
[SPR_DMISS
];
2459 cmp
= &env
->spr
[SPR_DCMP
];
2461 qemu_log("6xx %sTLB miss: %cM " TARGET_FMT_lx
" %cC "
2462 TARGET_FMT_lx
" H1 " TARGET_FMT_lx
" H2 "
2463 TARGET_FMT_lx
" %08x\n", es
, en
, *miss
, en
, *cmp
,
2464 env
->spr
[SPR_HASH1
], env
->spr
[SPR_HASH2
],
2468 msr
|= env
->crf
[0] << 28;
2469 msr
|= env
->error_code
; /* key, D/I, S/L bits */
2470 /* Set way using a LRU mechanism */
2471 msr
|= ((env
->last_way
+ 1) & (env
->nb_ways
- 1)) << 17;
2473 case POWERPC_EXCP_74xx
:
2475 #if defined (DEBUG_SOFTWARE_TLB)
2476 if (qemu_log_enabled()) {
2478 target_ulong
*miss
, *cmp
;
2480 if (excp
== POWERPC_EXCP_IFTLB
) {
2483 miss
= &env
->spr
[SPR_TLBMISS
];
2484 cmp
= &env
->spr
[SPR_PTEHI
];
2486 if (excp
== POWERPC_EXCP_DLTLB
)
2491 miss
= &env
->spr
[SPR_TLBMISS
];
2492 cmp
= &env
->spr
[SPR_PTEHI
];
2494 qemu_log("74xx %sTLB miss: %cM " TARGET_FMT_lx
" %cC "
2495 TARGET_FMT_lx
" %08x\n", es
, en
, *miss
, en
, *cmp
,
2499 msr
|= env
->error_code
; /* key bit */
2502 cpu_abort(env
, "Invalid data store TLB miss exception\n");
2506 case POWERPC_EXCP_FPA
: /* Floating-point assist exception */
2508 cpu_abort(env
, "Floating point assist exception "
2509 "is not implemented yet !\n");
2511 case POWERPC_EXCP_DABR
: /* Data address breakpoint */
2513 cpu_abort(env
, "DABR exception is not implemented yet !\n");
2515 case POWERPC_EXCP_IABR
: /* Instruction address breakpoint */
2517 cpu_abort(env
, "IABR exception is not implemented yet !\n");
2519 case POWERPC_EXCP_SMI
: /* System management interrupt */
2521 cpu_abort(env
, "SMI exception is not implemented yet !\n");
2523 case POWERPC_EXCP_THERM
: /* Thermal interrupt */
2525 cpu_abort(env
, "Thermal management exception "
2526 "is not implemented yet !\n");
2528 case POWERPC_EXCP_PERFM
: /* Embedded performance monitor interrupt */
2529 new_msr
&= ~((target_ulong
)1 << MSR_RI
);
2531 new_msr
|= (target_ulong
)MSR_HVB
;
2534 "Performance counter exception is not implemented yet !\n");
2536 case POWERPC_EXCP_VPUA
: /* Vector assist exception */
2538 cpu_abort(env
, "VPU assist exception is not implemented yet !\n");
2540 case POWERPC_EXCP_SOFTP
: /* Soft patch exception */
2543 "970 soft-patch exception is not implemented yet !\n");
2545 case POWERPC_EXCP_MAINT
: /* Maintenance exception */
2548 "970 maintenance exception is not implemented yet !\n");
2550 case POWERPC_EXCP_MEXTBR
: /* Maskable external breakpoint */
2552 cpu_abort(env
, "Maskable external exception "
2553 "is not implemented yet !\n");
2555 case POWERPC_EXCP_NMEXTBR
: /* Non maskable external breakpoint */
2557 cpu_abort(env
, "Non maskable external exception "
2558 "is not implemented yet !\n");
2562 cpu_abort(env
, "Invalid PowerPC exception %d. Aborting\n", excp
);
2565 /* save current instruction location */
2566 env
->spr
[srr0
] = env
->nip
- 4;
2569 /* save next instruction location */
2570 env
->spr
[srr0
] = env
->nip
;
2574 env
->spr
[srr1
] = msr
;
2575 /* If any alternate SRR register are defined, duplicate saved values */
2577 env
->spr
[asrr0
] = env
->spr
[srr0
];
2579 env
->spr
[asrr1
] = env
->spr
[srr1
];
2580 /* If we disactivated any translation, flush TLBs */
2581 if (new_msr
& ((1 << MSR_IR
) | (1 << MSR_DR
)))
2583 /* reload MSR with correct bits */
2584 new_msr
&= ~((target_ulong
)1 << MSR_EE
);
2585 new_msr
&= ~((target_ulong
)1 << MSR_PR
);
2586 new_msr
&= ~((target_ulong
)1 << MSR_FP
);
2587 new_msr
&= ~((target_ulong
)1 << MSR_FE0
);
2588 new_msr
&= ~((target_ulong
)1 << MSR_SE
);
2589 new_msr
&= ~((target_ulong
)1 << MSR_BE
);
2590 new_msr
&= ~((target_ulong
)1 << MSR_FE1
);
2591 new_msr
&= ~((target_ulong
)1 << MSR_IR
);
2592 new_msr
&= ~((target_ulong
)1 << MSR_DR
);
2593 #if 0 /* Fix this: not on all targets */
2594 new_msr
&= ~((target_ulong
)1 << MSR_PMM
);
2596 new_msr
&= ~((target_ulong
)1 << MSR_LE
);
2598 new_msr
|= (target_ulong
)1 << MSR_LE
;
2600 new_msr
&= ~((target_ulong
)1 << MSR_LE
);
2601 /* Jump to handler */
2602 vector
= env
->excp_vectors
[excp
];
2603 if (vector
== (target_ulong
)-1ULL) {
2604 cpu_abort(env
, "Raised an exception without defined vector %d\n",
2607 vector
|= env
->excp_prefix
;
2608 #if defined(TARGET_PPC64)
2609 if (excp_model
== POWERPC_EXCP_BOOKE
) {
2611 new_msr
&= ~((target_ulong
)1 << MSR_CM
);
2612 vector
= (uint32_t)vector
;
2614 new_msr
|= (target_ulong
)1 << MSR_CM
;
2617 if (!msr_isf
&& !(env
->mmu_model
& POWERPC_MMU_64
)) {
2618 new_msr
&= ~((target_ulong
)1 << MSR_SF
);
2619 vector
= (uint32_t)vector
;
2621 new_msr
|= (target_ulong
)1 << MSR_SF
;
2625 /* XXX: we don't use hreg_store_msr here as already have treated
2626 * any special case that could occur. Just store MSR and update hflags
2628 env
->msr
= new_msr
& env
->msr_mask
;
2629 hreg_compute_hflags(env
);
2631 /* Reset exception state */
2632 env
->exception_index
= POWERPC_EXCP_NONE
;
2633 env
->error_code
= 0;
2636 void do_interrupt (CPUState
*env
)
2638 powerpc_excp(env
, env
->excp_model
, env
->exception_index
);
2641 void ppc_hw_interrupt (CPUPPCState
*env
)
2646 qemu_log_mask(CPU_LOG_INT
, "%s: %p pending %08x req %08x me %d ee %d\n",
2647 __func__
, env
, env
->pending_interrupts
,
2648 env
->interrupt_request
, (int)msr_me
, (int)msr_ee
);
2650 /* External reset */
2651 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_RESET
)) {
2652 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_RESET
);
2653 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_RESET
);
2656 /* Machine check exception */
2657 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_MCK
)) {
2658 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_MCK
);
2659 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_MCHECK
);
2663 /* External debug exception */
2664 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DEBUG
)) {
2665 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DEBUG
);
2666 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DEBUG
);
2671 /* XXX: find a suitable condition to enable the hypervisor mode */
2672 hdice
= env
->spr
[SPR_LPCR
] & 1;
2676 if ((msr_ee
!= 0 || msr_hv
== 0 || msr_pr
!= 0) && hdice
!= 0) {
2677 /* Hypervisor decrementer exception */
2678 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_HDECR
)) {
2679 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_HDECR
);
2680 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_HDECR
);
2685 /* External critical interrupt */
2686 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_CEXT
)) {
2687 /* Taking a critical external interrupt does not clear the external
2688 * critical interrupt status
2691 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_CEXT
);
2693 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_CRITICAL
);
2698 /* Watchdog timer on embedded PowerPC */
2699 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_WDT
)) {
2700 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_WDT
);
2701 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_WDT
);
2704 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_CDOORBELL
)) {
2705 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_CDOORBELL
);
2706 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DOORCI
);
2709 /* Fixed interval timer on embedded PowerPC */
2710 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_FIT
)) {
2711 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_FIT
);
2712 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_FIT
);
2715 /* Programmable interval timer on embedded PowerPC */
2716 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_PIT
)) {
2717 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_PIT
);
2718 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_PIT
);
2721 /* Decrementer exception */
2722 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DECR
)) {
2723 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DECR
);
2724 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DECR
);
2727 /* External interrupt */
2728 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_EXT
)) {
2729 /* Taking an external interrupt does not clear the external
2733 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_EXT
);
2735 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_EXTERNAL
);
2738 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DOORBELL
)) {
2739 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DOORBELL
);
2740 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_DOORI
);
2743 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_PERFM
)) {
2744 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_PERFM
);
2745 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_PERFM
);
2748 /* Thermal interrupt */
2749 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_THERM
)) {
2750 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_THERM
);
2751 powerpc_excp(env
, env
->excp_model
, POWERPC_EXCP_THERM
);
2756 #endif /* !CONFIG_USER_ONLY */
2758 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
)
2760 qemu_log("Return from exception at " TARGET_FMT_lx
" with flags "
2761 TARGET_FMT_lx
"\n", RA
, msr
);
2764 void cpu_reset(CPUPPCState
*env
)
2768 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
2769 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
2770 log_cpu_state(env
, 0);
2773 msr
= (target_ulong
)0;
2775 /* XXX: find a suitable condition to enable the hypervisor mode */
2776 msr
|= (target_ulong
)MSR_HVB
;
2778 msr
|= (target_ulong
)0 << MSR_AP
; /* TO BE CHECKED */
2779 msr
|= (target_ulong
)0 << MSR_SA
; /* TO BE CHECKED */
2780 msr
|= (target_ulong
)1 << MSR_EP
;
2781 #if defined (DO_SINGLE_STEP) && 0
2782 /* Single step trace mode */
2783 msr
|= (target_ulong
)1 << MSR_SE
;
2784 msr
|= (target_ulong
)1 << MSR_BE
;
2786 #if defined(CONFIG_USER_ONLY)
2787 msr
|= (target_ulong
)1 << MSR_FP
; /* Allow floating point usage */
2788 msr
|= (target_ulong
)1 << MSR_VR
; /* Allow altivec usage */
2789 msr
|= (target_ulong
)1 << MSR_SPE
; /* Allow SPE usage */
2790 msr
|= (target_ulong
)1 << MSR_PR
;
2792 env
->excp_prefix
= env
->hreset_excp_prefix
;
2793 env
->nip
= env
->hreset_vector
| env
->excp_prefix
;
2794 if (env
->mmu_model
!= POWERPC_MMU_REAL
)
2795 ppc_tlb_invalidate_all(env
);
2797 env
->msr
= msr
& env
->msr_mask
;
2798 #if defined(TARGET_PPC64)
2799 if (env
->mmu_model
& POWERPC_MMU_64
)
2800 env
->msr
|= (1ULL << MSR_SF
);
2802 hreg_compute_hflags(env
);
2803 env
->reserve_addr
= (target_ulong
)-1ULL;
2804 /* Be sure no exception or interrupt is pending */
2805 env
->pending_interrupts
= 0;
2806 env
->exception_index
= POWERPC_EXCP_NONE
;
2807 env
->error_code
= 0;
2808 /* Flush all TLBs */
2812 CPUPPCState
*cpu_ppc_init (const char *cpu_model
)
2815 const ppc_def_t
*def
;
2817 def
= cpu_ppc_find_by_name(cpu_model
);
2821 env
= qemu_mallocz(sizeof(CPUPPCState
));
2823 ppc_translate_init();
2824 env
->cpu_model_str
= cpu_model
;
2825 cpu_ppc_register_internal(env
, def
);
2827 qemu_init_vcpu(env
);
2832 void cpu_ppc_close (CPUPPCState
*env
)
2834 /* Should also remove all opcode tables... */