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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 //#define DEBUG_SOFTWARE_TLB
34 //#define DEBUG_EXCEPTIONS
35 //#define FLUSH_ALL_TLBS
37 /*****************************************************************************/
38 /* PowerPC MMU emulation */
40 #if defined(CONFIG_USER_ONLY)
41 int cpu_ppc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
42 int is_user
, int is_softmmu
)
44 int exception
, error_code
;
53 error_code
|= 0x02000000;
54 env
->spr
[SPR_DAR
] = address
;
55 env
->spr
[SPR_DSISR
] = error_code
;
57 env
->exception_index
= exception
;
58 env
->error_code
= error_code
;
63 target_phys_addr_t
cpu_get_phys_page_debug (CPUState
*env
, target_ulong addr
)
69 /* Common routines used by software and hardware TLBs emulation */
70 static inline int pte_is_valid (target_ulong pte0
)
72 return pte0
& 0x80000000 ? 1 : 0;
75 static inline void pte_invalidate (target_ulong
*pte0
)
80 #if defined(TARGET_PPC64)
81 static inline int pte64_is_valid (target_ulong pte0
)
83 return pte0
& 0x0000000000000001ULL
? 1 : 0;
86 static inline void pte64_invalidate (target_ulong
*pte0
)
88 *pte0
&= ~0x0000000000000001ULL
;
92 #define PTE_PTEM_MASK 0x7FFFFFBF
93 #define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B)
94 #if defined(TARGET_PPC64)
95 #define PTE64_PTEM_MASK 0xFFFFFFFFFFFFFF80ULL
96 #define PTE64_CHECK_MASK (TARGET_PAGE_MASK | 0x7F)
99 static inline int _pte_check (mmu_ctx_t
*ctx
, int is_64b
,
100 target_ulong pte0
, target_ulong pte1
,
103 target_ulong ptem
, mmask
;
104 int access
, ret
, pteh
, ptev
;
108 /* Check validity and table match */
109 #if defined(TARGET_PPC64)
111 ptev
= pte64_is_valid(pte0
);
112 pteh
= (pte0
>> 1) & 1;
116 ptev
= pte_is_valid(pte0
);
117 pteh
= (pte0
>> 6) & 1;
119 if (ptev
&& h
== pteh
) {
120 /* Check vsid & api */
121 #if defined(TARGET_PPC64)
123 ptem
= pte0
& PTE64_PTEM_MASK
;
124 mmask
= PTE64_CHECK_MASK
;
128 ptem
= pte0
& PTE_PTEM_MASK
;
129 mmask
= PTE_CHECK_MASK
;
131 if (ptem
== ctx
->ptem
) {
132 if (ctx
->raddr
!= (target_ulong
)-1) {
133 /* all matches should have equal RPN, WIMG & PP */
134 if ((ctx
->raddr
& mmask
) != (pte1
& mmask
)) {
136 fprintf(logfile
, "Bad RPN/WIMG/PP\n");
140 /* Compute access rights */
143 if ((pte1
& 0x00000003) != 0x3)
144 access
|= PAGE_WRITE
;
146 switch (pte1
& 0x00000003) {
155 access
= PAGE_READ
| PAGE_WRITE
;
159 /* Keep the matching PTE informations */
162 if ((rw
== 0 && (access
& PAGE_READ
)) ||
163 (rw
== 1 && (access
& PAGE_WRITE
))) {
165 #if defined (DEBUG_MMU)
167 fprintf(logfile
, "PTE access granted !\n");
171 /* Access right violation */
172 #if defined (DEBUG_MMU)
174 fprintf(logfile
, "PTE access rejected\n");
184 static int pte32_check (mmu_ctx_t
*ctx
,
185 target_ulong pte0
, target_ulong pte1
, int h
, int rw
)
187 return _pte_check(ctx
, 0, pte0
, pte1
, h
, rw
);
190 #if defined(TARGET_PPC64)
191 static int pte64_check (mmu_ctx_t
*ctx
,
192 target_ulong pte0
, target_ulong pte1
, int h
, int rw
)
194 return _pte_check(ctx
, 1, pte0
, pte1
, h
, rw
);
198 static int pte_update_flags (mmu_ctx_t
*ctx
, target_ulong
*pte1p
,
203 /* Update page flags */
204 if (!(*pte1p
& 0x00000100)) {
205 /* Update accessed flag */
206 *pte1p
|= 0x00000100;
209 if (!(*pte1p
& 0x00000080)) {
210 if (rw
== 1 && ret
== 0) {
211 /* Update changed flag */
212 *pte1p
|= 0x00000080;
215 /* Force page fault for first write access */
216 ctx
->prot
&= ~PAGE_WRITE
;
223 /* Software driven TLB helpers */
224 static int ppc6xx_tlb_getnum (CPUState
*env
, target_ulong eaddr
,
225 int way
, int is_code
)
229 /* Select TLB num in a way from address */
230 nr
= (eaddr
>> TARGET_PAGE_BITS
) & (env
->tlb_per_way
- 1);
232 nr
+= env
->tlb_per_way
* way
;
233 /* 6xx have separate TLBs for instructions and data */
234 if (is_code
&& env
->id_tlbs
== 1)
240 void ppc6xx_tlb_invalidate_all (CPUState
*env
)
245 #if defined (DEBUG_SOFTWARE_TLB) && 0
247 fprintf(logfile
, "Invalidate all TLBs\n");
250 /* Invalidate all defined software TLB */
252 if (env
->id_tlbs
== 1)
254 for (nr
= 0; nr
< max
; nr
++) {
255 tlb
= &env
->tlb
[nr
].tlb6
;
256 #if !defined(FLUSH_ALL_TLBS)
257 tlb_flush_page(env
, tlb
->EPN
);
259 pte_invalidate(&tlb
->pte0
);
261 #if defined(FLUSH_ALL_TLBS)
266 static inline void __ppc6xx_tlb_invalidate_virt (CPUState
*env
,
268 int is_code
, int match_epn
)
270 #if !defined(FLUSH_ALL_TLBS)
274 /* Invalidate ITLB + DTLB, all ways */
275 for (way
= 0; way
< env
->nb_ways
; way
++) {
276 nr
= ppc6xx_tlb_getnum(env
, eaddr
, way
, is_code
);
277 tlb
= &env
->tlb
[nr
].tlb6
;
278 if (pte_is_valid(tlb
->pte0
) && (match_epn
== 0 || eaddr
== tlb
->EPN
)) {
279 #if defined (DEBUG_SOFTWARE_TLB)
281 fprintf(logfile
, "TLB invalidate %d/%d " ADDRX
"\n",
282 nr
, env
->nb_tlb
, eaddr
);
285 pte_invalidate(&tlb
->pte0
);
286 tlb_flush_page(env
, tlb
->EPN
);
290 /* XXX: PowerPC specification say this is valid as well */
291 ppc6xx_tlb_invalidate_all(env
);
295 void ppc6xx_tlb_invalidate_virt (CPUState
*env
, target_ulong eaddr
,
298 __ppc6xx_tlb_invalidate_virt(env
, eaddr
, is_code
, 0);
301 void ppc6xx_tlb_store (CPUState
*env
, target_ulong EPN
, int way
, int is_code
,
302 target_ulong pte0
, target_ulong pte1
)
307 nr
= ppc6xx_tlb_getnum(env
, EPN
, way
, is_code
);
308 tlb
= &env
->tlb
[nr
].tlb6
;
309 #if defined (DEBUG_SOFTWARE_TLB)
311 fprintf(logfile
, "Set TLB %d/%d EPN " ADDRX
" PTE0 " ADDRX
312 " PTE1 " ADDRX
"\n", nr
, env
->nb_tlb
, EPN
, pte0
, pte1
);
315 /* Invalidate any pending reference in Qemu for this virtual address */
316 __ppc6xx_tlb_invalidate_virt(env
, EPN
, is_code
, 1);
320 /* Store last way for LRU mechanism */
324 static int ppc6xx_tlb_check (CPUState
*env
, mmu_ctx_t
*ctx
,
325 target_ulong eaddr
, int rw
, int access_type
)
332 ret
= -1; /* No TLB found */
333 for (way
= 0; way
< env
->nb_ways
; way
++) {
334 nr
= ppc6xx_tlb_getnum(env
, eaddr
, way
,
335 access_type
== ACCESS_CODE
? 1 : 0);
336 tlb
= &env
->tlb
[nr
].tlb6
;
337 /* This test "emulates" the PTE index match for hardware TLBs */
338 if ((eaddr
& TARGET_PAGE_MASK
) != tlb
->EPN
) {
339 #if defined (DEBUG_SOFTWARE_TLB)
341 fprintf(logfile
, "TLB %d/%d %s [" ADDRX
" " ADDRX
344 pte_is_valid(tlb
->pte0
) ? "valid" : "inval",
345 tlb
->EPN
, tlb
->EPN
+ TARGET_PAGE_SIZE
, eaddr
);
350 #if defined (DEBUG_SOFTWARE_TLB)
352 fprintf(logfile
, "TLB %d/%d %s " ADDRX
" <> " ADDRX
" " ADDRX
355 pte_is_valid(tlb
->pte0
) ? "valid" : "inval",
356 tlb
->EPN
, eaddr
, tlb
->pte1
,
357 rw
? 'S' : 'L', access_type
== ACCESS_CODE
? 'I' : 'D');
360 switch (pte32_check(ctx
, tlb
->pte0
, tlb
->pte1
, 0, rw
)) {
362 /* TLB inconsistency */
365 /* Access violation */
375 /* XXX: we should go on looping to check all TLBs consistency
376 * but we can speed-up the whole thing as the
377 * result would be undefined if TLBs are not consistent.
386 #if defined (DEBUG_SOFTWARE_TLB)
388 fprintf(logfile
, "found TLB at addr 0x%08lx prot=0x%01x ret=%d\n",
389 ctx
->raddr
& TARGET_PAGE_MASK
, ctx
->prot
, ret
);
392 /* Update page flags */
393 pte_update_flags(ctx
, &env
->tlb
[best
].tlb6
.pte1
, ret
, rw
);
399 /* Perform BAT hit & translation */
400 static int get_bat (CPUState
*env
, mmu_ctx_t
*ctx
,
401 target_ulong
virtual, int rw
, int type
)
403 target_ulong
*BATlt
, *BATut
, *BATu
, *BATl
;
404 target_ulong base
, BEPIl
, BEPIu
, bl
;
408 #if defined (DEBUG_BATS)
410 fprintf(logfile
, "%s: %cBAT v 0x" ADDRX
"\n", __func__
,
411 type
== ACCESS_CODE
? 'I' : 'D', virtual);
416 BATlt
= env
->IBAT
[1];
417 BATut
= env
->IBAT
[0];
420 BATlt
= env
->DBAT
[1];
421 BATut
= env
->DBAT
[0];
424 #if defined (DEBUG_BATS)
426 fprintf(logfile
, "%s...: %cBAT v 0x" ADDRX
"\n", __func__
,
427 type
== ACCESS_CODE
? 'I' : 'D', virtual);
430 base
= virtual & 0xFFFC0000;
431 for (i
= 0; i
< 4; i
++) {
434 BEPIu
= *BATu
& 0xF0000000;
435 BEPIl
= *BATu
& 0x0FFE0000;
436 bl
= (*BATu
& 0x00001FFC) << 15;
437 #if defined (DEBUG_BATS)
439 fprintf(logfile
, "%s: %cBAT%d v 0x" ADDRX
" BATu 0x" ADDRX
440 " BATl 0x" ADDRX
"\n",
441 __func__
, type
== ACCESS_CODE
? 'I' : 'D', i
, virtual,
445 if ((virtual & 0xF0000000) == BEPIu
&&
446 ((virtual & 0x0FFE0000) & ~bl
) == BEPIl
) {
448 if ((msr_pr
== 0 && (*BATu
& 0x00000002)) ||
449 (msr_pr
== 1 && (*BATu
& 0x00000001))) {
450 /* Get physical address */
451 ctx
->raddr
= (*BATl
& 0xF0000000) |
452 ((virtual & 0x0FFE0000 & bl
) | (*BATl
& 0x0FFE0000)) |
453 (virtual & 0x0001F000);
454 if (*BATl
& 0x00000001)
455 ctx
->prot
= PAGE_READ
;
456 if (*BATl
& 0x00000002)
457 ctx
->prot
= PAGE_WRITE
| PAGE_READ
;
458 #if defined (DEBUG_BATS)
460 fprintf(logfile
, "BAT %d match: r 0x" PADDRX
462 i
, ctx
->raddr
, ctx
->prot
& PAGE_READ
? 'R' : '-',
463 ctx
->prot
& PAGE_WRITE
? 'W' : '-');
472 #if defined (DEBUG_BATS)
474 fprintf(logfile
, "no BAT match for 0x" ADDRX
":\n", virtual);
475 for (i
= 0; i
< 4; i
++) {
478 BEPIu
= *BATu
& 0xF0000000;
479 BEPIl
= *BATu
& 0x0FFE0000;
480 bl
= (*BATu
& 0x00001FFC) << 15;
481 fprintf(logfile
, "%s: %cBAT%d v 0x" ADDRX
" BATu 0x" ADDRX
482 " BATl 0x" ADDRX
" \n\t"
483 "0x" ADDRX
" 0x" ADDRX
" 0x" ADDRX
"\n",
484 __func__
, type
== ACCESS_CODE
? 'I' : 'D', i
, virtual,
485 *BATu
, *BATl
, BEPIu
, BEPIl
, bl
);
494 /* PTE table lookup */
495 static inline int _find_pte (mmu_ctx_t
*ctx
, int is_64b
, int h
, int rw
)
497 target_ulong base
, pte0
, pte1
;
501 ret
= -1; /* No entry found */
502 base
= ctx
->pg_addr
[h
];
503 for (i
= 0; i
< 8; i
++) {
504 #if defined(TARGET_PPC64)
506 pte0
= ldq_phys(base
+ (i
* 16));
507 pte1
= ldq_phys(base
+ (i
* 16) + 8);
508 r
= pte64_check(ctx
, pte0
, pte1
, h
, rw
);
512 pte0
= ldl_phys(base
+ (i
* 8));
513 pte1
= ldl_phys(base
+ (i
* 8) + 4);
514 r
= pte32_check(ctx
, pte0
, pte1
, h
, rw
);
516 #if defined (DEBUG_MMU)
518 fprintf(logfile
, "Load pte from 0x" ADDRX
" => 0x" ADDRX
519 " 0x" ADDRX
" %d %d %d 0x" ADDRX
"\n",
520 base
+ (i
* 8), pte0
, pte1
,
521 (int)(pte0
>> 31), h
, (int)((pte0
>> 6) & 1), ctx
->ptem
);
526 /* PTE inconsistency */
529 /* Access violation */
539 /* XXX: we should go on looping to check all PTEs consistency
540 * but if we can speed-up the whole thing as the
541 * result would be undefined if PTEs are not consistent.
550 #if defined (DEBUG_MMU)
552 fprintf(logfile
, "found PTE at addr 0x" PADDRX
" prot=0x%01x "
554 ctx
->raddr
, ctx
->prot
, ret
);
557 /* Update page flags */
559 if (pte_update_flags(ctx
, &pte1
, ret
, rw
) == 1) {
560 #if defined(TARGET_PPC64)
562 stq_phys_notdirty(base
+ (good
* 16) + 8, pte1
);
566 stl_phys_notdirty(base
+ (good
* 8) + 4, pte1
);
574 static int find_pte32 (mmu_ctx_t
*ctx
, int h
, int rw
)
576 return _find_pte(ctx
, 0, h
, rw
);
579 #if defined(TARGET_PPC64)
580 static int find_pte64 (mmu_ctx_t
*ctx
, int h
, int rw
)
582 return _find_pte(ctx
, 1, h
, rw
);
586 static inline int find_pte (CPUState
*env
, mmu_ctx_t
*ctx
, int h
, int rw
)
588 #if defined(TARGET_PPC64)
589 if (PPC_MMU(env
) == PPC_FLAGS_MMU_64B
||
590 PPC_MMU(env
) == PPC_FLAGS_MMU_64BRIDGE
)
591 return find_pte64(ctx
, h
, rw
);
594 return find_pte32(ctx
, h
, rw
);
597 static inline target_phys_addr_t
get_pgaddr (target_phys_addr_t sdr1
,
599 target_phys_addr_t hash
,
600 target_phys_addr_t mask
)
602 return (sdr1
& ((target_ulong
)(-1ULL) << sdr_sh
)) | (hash
& mask
);
605 #if defined(TARGET_PPC64)
606 static int slb_lookup (CPUState
*env
, target_ulong eaddr
,
607 target_ulong
*vsid
, target_ulong
*page_mask
, int *attr
)
609 target_phys_addr_t sr_base
;
617 sr_base
= env
->spr
[SPR_ASR
];
618 mask
= 0x0000000000000000ULL
; /* Avoid gcc warning */
619 #if 0 /* XXX: Fix this */
620 slb_nr
= env
->slb_nr
;
624 for (n
= 0; n
< slb_nr
; n
++) {
625 tmp64
= ldq_phys(sr_base
);
626 if (tmp64
& 0x0000000008000000ULL
) {
627 /* SLB entry is valid */
628 switch (tmp64
& 0x0000000006000000ULL
) {
629 case 0x0000000000000000ULL
:
631 mask
= 0xFFFFFFFFF0000000ULL
;
633 case 0x0000000002000000ULL
:
635 mask
= 0xFFFF000000000000ULL
;
637 case 0x0000000004000000ULL
:
638 case 0x0000000006000000ULL
:
639 /* Reserved => segment is invalid */
642 if ((eaddr
& mask
) == (tmp64
& mask
)) {
644 tmp
= ldl_phys(sr_base
+ 8);
645 *vsid
= ((tmp64
<< 24) | (tmp
>> 8)) & 0x0003FFFFFFFFFFFFULL
;
657 #endif /* defined(TARGET_PPC64) */
659 /* Perform segment based translation */
660 static int get_segment (CPUState
*env
, mmu_ctx_t
*ctx
,
661 target_ulong eaddr
, int rw
, int type
)
663 target_phys_addr_t sdr
, hash
, mask
, sdr_mask
;
664 target_ulong sr
, vsid
, vsid_mask
, pgidx
, page_mask
;
665 #if defined(TARGET_PPC64)
668 int ds
, nx
, vsid_sh
, sdr_sh
;
671 #if defined(TARGET_PPC64)
672 if (PPC_MMU(env
) == PPC_FLAGS_MMU_64B
) {
673 ret
= slb_lookup(env
, eaddr
, &vsid
, &page_mask
, &attr
);
676 ctx
->key
= ((attr
& 0x40) && msr_pr
== 1) ||
677 ((attr
& 0x80) && msr_pr
== 0) ? 1 : 0;
679 nx
= attr
& 0x20 ? 1 : 0;
680 vsid_mask
= 0x00003FFFFFFFFF80ULL
;
685 #endif /* defined(TARGET_PPC64) */
687 sr
= env
->sr
[eaddr
>> 28];
688 page_mask
= 0x0FFFFFFF;
689 ctx
->key
= (((sr
& 0x20000000) && msr_pr
== 1) ||
690 ((sr
& 0x40000000) && msr_pr
== 0)) ? 1 : 0;
691 ds
= sr
& 0x80000000 ? 1 : 0;
692 nx
= sr
& 0x10000000 ? 1 : 0;
693 vsid
= sr
& 0x00FFFFFF;
694 vsid_mask
= 0x01FFFFC0;
698 #if defined (DEBUG_MMU)
700 fprintf(logfile
, "Check segment v=0x" ADDRX
" %d 0x" ADDRX
701 " nip=0x" ADDRX
" lr=0x" ADDRX
702 " ir=%d dr=%d pr=%d %d t=%d\n",
703 eaddr
, (int)(eaddr
>> 28), sr
, env
->nip
,
704 env
->lr
, msr_ir
, msr_dr
, msr_pr
, rw
, type
);
706 if (!ds
&& loglevel
!= 0) {
707 fprintf(logfile
, "pte segment: key=%d n=0x" ADDRX
"\n",
708 ctx
->key
, sr
& 0x10000000);
714 /* Check if instruction fetch is allowed, if needed */
715 if (type
!= ACCESS_CODE
|| nx
== 0) {
716 /* Page address translation */
717 pgidx
= (eaddr
& page_mask
) >> TARGET_PAGE_BITS
;
718 hash
= ((vsid
^ pgidx
) << vsid_sh
) & vsid_mask
;
719 /* Primary table address */
721 mask
= ((sdr
& 0x000001FF) << sdr_sh
) | sdr_mask
;
722 ctx
->pg_addr
[0] = get_pgaddr(sdr
, sdr_sh
, hash
, mask
);
723 /* Secondary table address */
724 hash
= (~hash
) & vsid_mask
;
725 ctx
->pg_addr
[1] = get_pgaddr(sdr
, sdr_sh
, hash
, mask
);
726 #if defined(TARGET_PPC64)
727 if (PPC_MMU(env
) == PPC_FLAGS_MMU_64B
||
728 PPC_MMU(env
) == PPC_FLAGS_MMU_64BRIDGE
) {
729 /* Only 5 bits of the page index are used in the AVPN */
730 ctx
->ptem
= (vsid
<< 12) | ((pgidx
>> 4) & 0x0F80);
734 ctx
->ptem
= (vsid
<< 7) | (pgidx
>> 10);
736 /* Initialize real address with an invalid value */
737 ctx
->raddr
= (target_ulong
)-1;
738 if (unlikely(PPC_MMU(env
) == PPC_FLAGS_MMU_SOFT_6xx
)) {
739 /* Software TLB search */
740 ret
= ppc6xx_tlb_check(env
, ctx
, eaddr
, rw
, type
);
742 #if defined (DEBUG_MMU)
744 fprintf(logfile
, "0 sdr1=0x" PADDRX
" vsid=0x%06x "
745 "api=0x%04x hash=0x%07x pg_addr=0x" PADDRX
"\n",
746 sdr
, (uint32_t)vsid
, (uint32_t)pgidx
,
747 (uint32_t)hash
, ctx
->pg_addr
[0]);
750 /* Primary table lookup */
751 ret
= find_pte(env
, ctx
, 0, rw
);
753 /* Secondary table lookup */
754 #if defined (DEBUG_MMU)
755 if (eaddr
!= 0xEFFFFFFF && loglevel
!= 0) {
757 "1 sdr1=0x" PADDRX
" vsid=0x%06x api=0x%04x "
758 "hash=0x%05x pg_addr=0x" PADDRX
"\n",
759 sdr
, (uint32_t)vsid
, (uint32_t)pgidx
,
760 (uint32_t)hash
, ctx
->pg_addr
[1]);
763 ret2
= find_pte(env
, ctx
, 1, rw
);
769 #if defined (DEBUG_MMU)
771 fprintf(logfile
, "No access allowed\n");
776 #if defined (DEBUG_MMU)
778 fprintf(logfile
, "direct store...\n");
780 /* Direct-store segment : absolutely *BUGGY* for now */
783 /* Integer load/store : only access allowed */
786 /* No code fetch is allowed in direct-store areas */
789 /* Floating point load/store */
792 /* lwarx, ldarx or srwcx. */
795 /* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi */
796 /* Should make the instruction do no-op.
797 * As it already do no-op, it's quite easy :-)
806 fprintf(logfile
, "ERROR: instruction should not need "
807 "address translation\n");
811 if ((rw
== 1 || ctx
->key
!= 1) && (rw
== 0 || ctx
->key
!= 0)) {
822 /* Generic TLB check function for embedded PowerPC implementations */
823 static int ppcemb_tlb_check (CPUState
*env
, ppcemb_tlb_t
*tlb
,
824 target_phys_addr_t
*raddrp
,
825 target_ulong address
,
826 uint32_t pid
, int ext
, int i
)
830 /* Check valid flag */
831 if (!(tlb
->prot
& PAGE_VALID
)) {
833 fprintf(logfile
, "%s: TLB %d not valid\n", __func__
, i
);
836 mask
= ~(tlb
->size
- 1);
838 fprintf(logfile
, "%s: TLB %d address " ADDRX
" PID %d <=> "
839 ADDRX
" " ADDRX
" %d\n",
840 __func__
, i
, address
, pid
, tlb
->EPN
, mask
, (int)tlb
->PID
);
843 if (tlb
->PID
!= 0 && tlb
->PID
!= pid
)
845 /* Check effective address */
846 if ((address
& mask
) != tlb
->EPN
)
848 *raddrp
= (tlb
->RPN
& mask
) | (address
& ~mask
);
849 #if (TARGET_PHYS_ADDR_BITS >= 36)
851 /* Extend the physical address to 36 bits */
852 *raddrp
|= (target_phys_addr_t
)(tlb
->RPN
& 0xF) << 32;
859 /* Generic TLB search function for PowerPC embedded implementations */
860 int ppcemb_tlb_search (CPUPPCState
*env
, target_ulong address
, uint32_t pid
)
863 target_phys_addr_t raddr
;
866 /* Default return value is no match */
868 for (i
= 0; i
< 64; i
++) {
869 tlb
= &env
->tlb
[i
].tlbe
;
870 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
, pid
, 0, i
) == 0) {
879 /* Helpers specific to PowerPC 40x implementations */
880 void ppc4xx_tlb_invalidate_all (CPUState
*env
)
885 for (i
= 0; i
< env
->nb_tlb
; i
++) {
886 tlb
= &env
->tlb
[i
].tlbe
;
887 if (tlb
->prot
& PAGE_VALID
) {
888 #if 0 // XXX: TLB have variable sizes then we flush all Qemu TLB.
889 end
= tlb
->EPN
+ tlb
->size
;
890 for (page
= tlb
->EPN
; page
< end
; page
+= TARGET_PAGE_SIZE
)
891 tlb_flush_page(env
, page
);
893 tlb
->prot
&= ~PAGE_VALID
;
899 int mmu40x_get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
,
900 target_ulong address
, int rw
, int access_type
)
903 target_phys_addr_t raddr
;
904 int i
, ret
, zsel
, zpr
;
908 for (i
= 0; i
< env
->nb_tlb
; i
++) {
909 tlb
= &env
->tlb
[i
].tlbe
;
910 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
,
911 env
->spr
[SPR_40x_PID
], 0, i
) < 0)
913 zsel
= (tlb
->attr
>> 4) & 0xF;
914 zpr
= (env
->spr
[SPR_40x_ZPR
] >> (28 - (2 * zsel
))) & 0x3;
916 fprintf(logfile
, "%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",
917 __func__
, i
, zsel
, zpr
, rw
, tlb
->attr
);
919 if (access_type
== ACCESS_CODE
) {
920 /* Check execute enable bit */
924 goto check_exec_perm
;
935 /* Check from TLB entry */
936 if (!(tlb
->prot
& PAGE_EXEC
)) {
939 if (tlb
->prot
& PAGE_WRITE
) {
940 ctx
->prot
= PAGE_READ
| PAGE_WRITE
;
942 ctx
->prot
= PAGE_READ
;
949 /* All accesses granted */
950 ctx
->prot
= PAGE_READ
| PAGE_WRITE
;
969 /* Check from TLB entry */
970 /* Check write protection bit */
971 if (tlb
->prot
& PAGE_WRITE
) {
972 ctx
->prot
= PAGE_READ
| PAGE_WRITE
;
975 ctx
->prot
= PAGE_READ
;
984 /* All accesses granted */
985 ctx
->prot
= PAGE_READ
| PAGE_WRITE
;
993 fprintf(logfile
, "%s: access granted " ADDRX
" => " REGX
994 " %d %d\n", __func__
, address
, ctx
->raddr
, ctx
->prot
,
1000 if (loglevel
!= 0) {
1001 fprintf(logfile
, "%s: access refused " ADDRX
" => " REGX
1002 " %d %d\n", __func__
, address
, raddr
, ctx
->prot
,
1009 void store_40x_sler (CPUPPCState
*env
, uint32_t val
)
1011 /* XXX: TO BE FIXED */
1012 if (val
!= 0x00000000) {
1013 cpu_abort(env
, "Little-endian regions are not supported by now\n");
1015 env
->spr
[SPR_405_SLER
] = val
;
1018 int mmubooke_get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
,
1019 target_ulong address
, int rw
,
1023 target_phys_addr_t raddr
;
1028 for (i
= 0; i
< env
->nb_tlb
; i
++) {
1029 tlb
= &env
->tlb
[i
].tlbe
;
1030 if (ppcemb_tlb_check(env
, tlb
, &raddr
, address
,
1031 env
->spr
[SPR_BOOKE_PID
], 1, i
) < 0)
1034 prot
= tlb
->prot
& 0xF;
1036 prot
= (tlb
->prot
>> 4) & 0xF;
1037 /* Check the address space */
1038 if (access_type
== ACCESS_CODE
) {
1039 if (msr_is
!= (tlb
->attr
& 1))
1042 if (prot
& PAGE_EXEC
) {
1048 if (msr_ds
!= (tlb
->attr
& 1))
1051 if ((!rw
&& prot
& PAGE_READ
) || (rw
&& (prot
& PAGE_WRITE
))) {
1064 static int check_physical (CPUState
*env
, mmu_ctx_t
*ctx
,
1065 target_ulong eaddr
, int rw
)
1070 ctx
->prot
= PAGE_READ
;
1072 switch (PPC_MMU(env
)) {
1073 case PPC_FLAGS_MMU_32B
:
1074 case PPC_FLAGS_MMU_SOFT_6xx
:
1075 case PPC_FLAGS_MMU_601
:
1076 case PPC_FLAGS_MMU_SOFT_4xx
:
1077 case PPC_FLAGS_MMU_401
:
1078 ctx
->prot
|= PAGE_WRITE
;
1080 #if defined(TARGET_PPC64)
1081 case PPC_FLAGS_MMU_64B
:
1082 case PPC_FLAGS_MMU_64BRIDGE
:
1083 /* Real address are 60 bits long */
1084 ctx
->raddr
&= 0x0FFFFFFFFFFFFFFFUL
;
1085 ctx
->prot
|= PAGE_WRITE
;
1088 case PPC_FLAGS_MMU_403
:
1089 if (unlikely(msr_pe
!= 0)) {
1090 /* 403 family add some particular protections,
1091 * using PBL/PBU registers for accesses with no translation.
1094 /* Check PLB validity */
1095 (env
->pb
[0] < env
->pb
[1] &&
1096 /* and address in plb area */
1097 eaddr
>= env
->pb
[0] && eaddr
< env
->pb
[1]) ||
1098 (env
->pb
[2] < env
->pb
[3] &&
1099 eaddr
>= env
->pb
[2] && eaddr
< env
->pb
[3]) ? 1 : 0;
1100 if (in_plb
^ msr_px
) {
1101 /* Access in protected area */
1103 /* Access is not allowed */
1107 /* Read-write access is allowed */
1108 ctx
->prot
|= PAGE_WRITE
;
1111 case PPC_FLAGS_MMU_BOOKE
:
1112 ctx
->prot
|= PAGE_WRITE
;
1114 case PPC_FLAGS_MMU_BOOKE_FSL
:
1116 cpu_abort(env
, "BookE FSL MMU model not implemented\n");
1119 cpu_abort(env
, "Unknown or invalid MMU model\n");
1126 int get_physical_address (CPUState
*env
, mmu_ctx_t
*ctx
, target_ulong eaddr
,
1127 int rw
, int access_type
, int check_BATs
)
1131 if (loglevel
!= 0) {
1132 fprintf(logfile
, "%s\n", __func__
);
1135 if ((access_type
== ACCESS_CODE
&& msr_ir
== 0) ||
1136 (access_type
!= ACCESS_CODE
&& msr_dr
== 0)) {
1137 /* No address translation */
1138 ret
= check_physical(env
, ctx
, eaddr
, rw
);
1141 switch (PPC_MMU(env
)) {
1142 case PPC_FLAGS_MMU_32B
:
1143 case PPC_FLAGS_MMU_SOFT_6xx
:
1144 /* Try to find a BAT */
1146 ret
= get_bat(env
, ctx
, eaddr
, rw
, access_type
);
1148 #if defined(TARGET_PPC64)
1149 case PPC_FLAGS_MMU_64B
:
1150 case PPC_FLAGS_MMU_64BRIDGE
:
1153 /* We didn't match any BAT entry or don't have BATs */
1154 ret
= get_segment(env
, ctx
, eaddr
, rw
, access_type
);
1157 case PPC_FLAGS_MMU_SOFT_4xx
:
1158 case PPC_FLAGS_MMU_403
:
1159 ret
= mmu40x_get_physical_address(env
, ctx
, eaddr
,
1162 case PPC_FLAGS_MMU_601
:
1164 cpu_abort(env
, "601 MMU model not implemented\n");
1166 case PPC_FLAGS_MMU_BOOKE
:
1167 ret
= mmubooke_get_physical_address(env
, ctx
, eaddr
,
1170 case PPC_FLAGS_MMU_BOOKE_FSL
:
1172 cpu_abort(env
, "BookE FSL MMU model not implemented\n");
1174 case PPC_FLAGS_MMU_401
:
1175 cpu_abort(env
, "PowerPC 401 does not do any translation\n");
1178 cpu_abort(env
, "Unknown or invalid MMU model\n");
1183 if (loglevel
!= 0) {
1184 fprintf(logfile
, "%s address " ADDRX
" => %d " PADDRX
"\n",
1185 __func__
, eaddr
, ret
, ctx
->raddr
);
1192 target_phys_addr_t
cpu_get_phys_page_debug (CPUState
*env
, target_ulong addr
)
1196 if (unlikely(get_physical_address(env
, &ctx
, addr
, 0, ACCESS_INT
, 1) != 0))
1199 return ctx
.raddr
& TARGET_PAGE_MASK
;
1202 /* Perform address translation */
1203 int cpu_ppc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
1204 int is_user
, int is_softmmu
)
1207 int exception
= 0, error_code
= 0;
1214 access_type
= ACCESS_CODE
;
1217 /* XXX: put correct access by using cpu_restore_state()
1219 access_type
= ACCESS_INT
;
1220 // access_type = env->access_type;
1222 ret
= get_physical_address(env
, &ctx
, address
, rw
, access_type
, 1);
1224 ret
= tlb_set_page(env
, address
& TARGET_PAGE_MASK
,
1225 ctx
.raddr
& TARGET_PAGE_MASK
, ctx
.prot
,
1226 is_user
, is_softmmu
);
1227 } else if (ret
< 0) {
1228 #if defined (DEBUG_MMU)
1230 cpu_dump_state(env
, logfile
, fprintf
, 0);
1232 if (access_type
== ACCESS_CODE
) {
1233 exception
= EXCP_ISI
;
1236 /* No matches in page tables or TLB */
1237 switch (PPC_MMU(env
)) {
1238 case PPC_FLAGS_MMU_SOFT_6xx
:
1239 exception
= EXCP_I_TLBMISS
;
1240 env
->spr
[SPR_IMISS
] = address
;
1241 env
->spr
[SPR_ICMP
] = 0x80000000 | ctx
.ptem
;
1242 error_code
= 1 << 18;
1244 case PPC_FLAGS_MMU_SOFT_4xx
:
1245 case PPC_FLAGS_MMU_403
:
1246 exception
= EXCP_40x_ITLBMISS
;
1248 env
->spr
[SPR_40x_DEAR
] = address
;
1249 env
->spr
[SPR_40x_ESR
] = 0x00000000;
1251 case PPC_FLAGS_MMU_32B
:
1252 error_code
= 0x40000000;
1254 #if defined(TARGET_PPC64)
1255 case PPC_FLAGS_MMU_64B
:
1257 cpu_abort(env
, "MMU model not implemented\n");
1259 case PPC_FLAGS_MMU_64BRIDGE
:
1261 cpu_abort(env
, "MMU model not implemented\n");
1264 case PPC_FLAGS_MMU_601
:
1266 cpu_abort(env
, "MMU model not implemented\n");
1268 case PPC_FLAGS_MMU_BOOKE
:
1270 cpu_abort(env
, "MMU model not implemented\n");
1272 case PPC_FLAGS_MMU_BOOKE_FSL
:
1274 cpu_abort(env
, "MMU model not implemented\n");
1276 case PPC_FLAGS_MMU_401
:
1277 cpu_abort(env
, "PowerPC 401 should never raise any MMU "
1281 cpu_abort(env
, "Unknown or invalid MMU model\n");
1286 /* Access rights violation */
1287 error_code
= 0x08000000;
1290 /* No execute protection violation */
1291 error_code
= 0x10000000;
1294 /* Direct store exception */
1295 /* No code fetch is allowed in direct-store areas */
1296 error_code
= 0x10000000;
1299 /* No match in segment table */
1300 exception
= EXCP_ISEG
;
1305 exception
= EXCP_DSI
;
1308 /* No matches in page tables or TLB */
1309 switch (PPC_MMU(env
)) {
1310 case PPC_FLAGS_MMU_SOFT_6xx
:
1312 exception
= EXCP_DS_TLBMISS
;
1313 error_code
= 1 << 16;
1315 exception
= EXCP_DL_TLBMISS
;
1318 env
->spr
[SPR_DMISS
] = address
;
1319 env
->spr
[SPR_DCMP
] = 0x80000000 | ctx
.ptem
;
1321 error_code
|= ctx
.key
<< 19;
1322 env
->spr
[SPR_HASH1
] = ctx
.pg_addr
[0];
1323 env
->spr
[SPR_HASH2
] = ctx
.pg_addr
[1];
1324 /* Do not alter DAR nor DSISR */
1326 case PPC_FLAGS_MMU_SOFT_4xx
:
1327 case PPC_FLAGS_MMU_403
:
1328 exception
= EXCP_40x_DTLBMISS
;
1330 env
->spr
[SPR_40x_DEAR
] = address
;
1332 env
->spr
[SPR_40x_ESR
] = 0x00800000;
1334 env
->spr
[SPR_40x_ESR
] = 0x00000000;
1336 case PPC_FLAGS_MMU_32B
:
1337 error_code
= 0x40000000;
1339 #if defined(TARGET_PPC64)
1340 case PPC_FLAGS_MMU_64B
:
1342 cpu_abort(env
, "MMU model not implemented\n");
1344 case PPC_FLAGS_MMU_64BRIDGE
:
1346 cpu_abort(env
, "MMU model not implemented\n");
1349 case PPC_FLAGS_MMU_601
:
1351 cpu_abort(env
, "MMU model not implemented\n");
1353 case PPC_FLAGS_MMU_BOOKE
:
1355 cpu_abort(env
, "MMU model not implemented\n");
1357 case PPC_FLAGS_MMU_BOOKE_FSL
:
1359 cpu_abort(env
, "MMU model not implemented\n");
1361 case PPC_FLAGS_MMU_401
:
1362 cpu_abort(env
, "PowerPC 401 should never raise any MMU "
1366 cpu_abort(env
, "Unknown or invalid MMU model\n");
1371 /* Access rights violation */
1372 error_code
= 0x08000000;
1375 /* Direct store exception */
1376 switch (access_type
) {
1378 /* Floating point load/store */
1379 exception
= EXCP_ALIGN
;
1380 error_code
= EXCP_ALIGN_FP
;
1383 /* lwarx, ldarx or srwcx. */
1384 error_code
= 0x04000000;
1387 /* eciwx or ecowx */
1388 error_code
= 0x04100000;
1391 printf("DSI: invalid exception (%d)\n", ret
);
1392 exception
= EXCP_PROGRAM
;
1393 error_code
= EXCP_INVAL
| EXCP_INVAL_INVAL
;
1398 /* No match in segment table */
1399 exception
= EXCP_DSEG
;
1403 if (exception
== EXCP_DSI
&& rw
== 1)
1404 error_code
|= 0x02000000;
1405 /* Store fault address */
1406 env
->spr
[SPR_DAR
] = address
;
1407 env
->spr
[SPR_DSISR
] = error_code
;
1411 printf("%s: set exception to %d %02x\n",
1412 __func__
, exception
, error_code
);
1414 env
->exception_index
= exception
;
1415 env
->error_code
= error_code
;
1422 /*****************************************************************************/
1423 /* BATs management */
1424 #if !defined(FLUSH_ALL_TLBS)
1425 static inline void do_invalidate_BAT (CPUPPCState
*env
,
1426 target_ulong BATu
, target_ulong mask
)
1428 target_ulong base
, end
, page
;
1430 base
= BATu
& ~0x0001FFFF;
1431 end
= base
+ mask
+ 0x00020000;
1432 #if defined (DEBUG_BATS)
1433 if (loglevel
!= 0) {
1434 fprintf(logfile
, "Flush BAT from " ADDRX
" to " ADDRX
" (" ADDRX
")\n",
1438 for (page
= base
; page
!= end
; page
+= TARGET_PAGE_SIZE
)
1439 tlb_flush_page(env
, page
);
1440 #if defined (DEBUG_BATS)
1442 fprintf(logfile
, "Flush done\n");
1447 static inline void dump_store_bat (CPUPPCState
*env
, char ID
, int ul
, int nr
,
1450 #if defined (DEBUG_BATS)
1451 if (loglevel
!= 0) {
1452 fprintf(logfile
, "Set %cBAT%d%c to 0x" ADDRX
" (0x" ADDRX
")\n",
1453 ID
, nr
, ul
== 0 ? 'u' : 'l', value
, env
->nip
);
1458 target_ulong
do_load_ibatu (CPUPPCState
*env
, int nr
)
1460 return env
->IBAT
[0][nr
];
1463 target_ulong
do_load_ibatl (CPUPPCState
*env
, int nr
)
1465 return env
->IBAT
[1][nr
];
1468 void do_store_ibatu (CPUPPCState
*env
, int nr
, target_ulong value
)
1472 dump_store_bat(env
, 'I', 0, nr
, value
);
1473 if (env
->IBAT
[0][nr
] != value
) {
1474 mask
= (value
<< 15) & 0x0FFE0000UL
;
1475 #if !defined(FLUSH_ALL_TLBS)
1476 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1478 /* When storing valid upper BAT, mask BEPI and BRPN
1479 * and invalidate all TLBs covered by this BAT
1481 mask
= (value
<< 15) & 0x0FFE0000UL
;
1482 env
->IBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1483 (value
& ~0x0001FFFFUL
& ~mask
);
1484 env
->IBAT
[1][nr
] = (env
->IBAT
[1][nr
] & 0x0000007B) |
1485 (env
->IBAT
[1][nr
] & ~0x0001FFFF & ~mask
);
1486 #if !defined(FLUSH_ALL_TLBS)
1487 do_invalidate_BAT(env
, env
->IBAT
[0][nr
], mask
);
1494 void do_store_ibatl (CPUPPCState
*env
, int nr
, target_ulong value
)
1496 dump_store_bat(env
, 'I', 1, nr
, value
);
1497 env
->IBAT
[1][nr
] = value
;
1500 target_ulong
do_load_dbatu (CPUPPCState
*env
, int nr
)
1502 return env
->DBAT
[0][nr
];
1505 target_ulong
do_load_dbatl (CPUPPCState
*env
, int nr
)
1507 return env
->DBAT
[1][nr
];
1510 void do_store_dbatu (CPUPPCState
*env
, int nr
, target_ulong value
)
1514 dump_store_bat(env
, 'D', 0, nr
, value
);
1515 if (env
->DBAT
[0][nr
] != value
) {
1516 /* When storing valid upper BAT, mask BEPI and BRPN
1517 * and invalidate all TLBs covered by this BAT
1519 mask
= (value
<< 15) & 0x0FFE0000UL
;
1520 #if !defined(FLUSH_ALL_TLBS)
1521 do_invalidate_BAT(env
, env
->DBAT
[0][nr
], mask
);
1523 mask
= (value
<< 15) & 0x0FFE0000UL
;
1524 env
->DBAT
[0][nr
] = (value
& 0x00001FFFUL
) |
1525 (value
& ~0x0001FFFFUL
& ~mask
);
1526 env
->DBAT
[1][nr
] = (env
->DBAT
[1][nr
] & 0x0000007B) |
1527 (env
->DBAT
[1][nr
] & ~0x0001FFFF & ~mask
);
1528 #if !defined(FLUSH_ALL_TLBS)
1529 do_invalidate_BAT(env
, env
->DBAT
[0][nr
], mask
);
1536 void do_store_dbatl (CPUPPCState
*env
, int nr
, target_ulong value
)
1538 dump_store_bat(env
, 'D', 1, nr
, value
);
1539 env
->DBAT
[1][nr
] = value
;
1543 /*****************************************************************************/
1544 /* TLB management */
1545 void ppc_tlb_invalidate_all (CPUPPCState
*env
)
1547 if (unlikely(PPC_MMU(env
) == PPC_FLAGS_MMU_SOFT_6xx
)) {
1548 ppc6xx_tlb_invalidate_all(env
);
1549 } else if (unlikely(PPC_MMU(env
) == PPC_FLAGS_MMU_SOFT_4xx
)) {
1550 ppc4xx_tlb_invalidate_all(env
);
1556 /*****************************************************************************/
1557 /* Special registers manipulation */
1558 #if defined(TARGET_PPC64)
1559 target_ulong
ppc_load_asr (CPUPPCState
*env
)
1564 void ppc_store_asr (CPUPPCState
*env
, target_ulong value
)
1566 if (env
->asr
!= value
) {
1573 target_ulong
do_load_sdr1 (CPUPPCState
*env
)
1578 void do_store_sdr1 (CPUPPCState
*env
, target_ulong value
)
1580 #if defined (DEBUG_MMU)
1581 if (loglevel
!= 0) {
1582 fprintf(logfile
, "%s: 0x" ADDRX
"\n", __func__
, value
);
1585 if (env
->sdr1
!= value
) {
1591 target_ulong
do_load_sr (CPUPPCState
*env
, int srnum
)
1593 return env
->sr
[srnum
];
1596 void do_store_sr (CPUPPCState
*env
, int srnum
, target_ulong value
)
1598 #if defined (DEBUG_MMU)
1599 if (loglevel
!= 0) {
1600 fprintf(logfile
, "%s: reg=%d 0x" ADDRX
" " ADDRX
"\n",
1601 __func__
, srnum
, value
, env
->sr
[srnum
]);
1604 if (env
->sr
[srnum
] != value
) {
1605 env
->sr
[srnum
] = value
;
1606 #if !defined(FLUSH_ALL_TLBS) && 0
1608 target_ulong page
, end
;
1609 /* Invalidate 256 MB of virtual memory */
1610 page
= (16 << 20) * srnum
;
1611 end
= page
+ (16 << 20);
1612 for (; page
!= end
; page
+= TARGET_PAGE_SIZE
)
1613 tlb_flush_page(env
, page
);
1620 #endif /* !defined (CONFIG_USER_ONLY) */
1622 uint32_t ppc_load_xer (CPUPPCState
*env
)
1624 return (xer_so
<< XER_SO
) |
1625 (xer_ov
<< XER_OV
) |
1626 (xer_ca
<< XER_CA
) |
1627 (xer_bc
<< XER_BC
) |
1628 (xer_cmp
<< XER_CMP
);
1631 void ppc_store_xer (CPUPPCState
*env
, uint32_t value
)
1633 xer_so
= (value
>> XER_SO
) & 0x01;
1634 xer_ov
= (value
>> XER_OV
) & 0x01;
1635 xer_ca
= (value
>> XER_CA
) & 0x01;
1636 xer_cmp
= (value
>> XER_CMP
) & 0xFF;
1637 xer_bc
= (value
>> XER_BC
) & 0x7F;
1640 /* Swap temporary saved registers with GPRs */
1641 static inline void swap_gpr_tgpr (CPUPPCState
*env
)
1646 env
->gpr
[0] = env
->tgpr
[0];
1649 env
->gpr
[1] = env
->tgpr
[1];
1652 env
->gpr
[2] = env
->tgpr
[2];
1655 env
->gpr
[3] = env
->tgpr
[3];
1659 /* GDBstub can read and write MSR... */
1660 target_ulong
do_load_msr (CPUPPCState
*env
)
1663 #if defined (TARGET_PPC64)
1664 ((target_ulong
)msr_sf
<< MSR_SF
) |
1665 ((target_ulong
)msr_isf
<< MSR_ISF
) |
1666 ((target_ulong
)msr_hv
<< MSR_HV
) |
1668 ((target_ulong
)msr_ucle
<< MSR_UCLE
) |
1669 ((target_ulong
)msr_vr
<< MSR_VR
) | /* VR / SPE */
1670 ((target_ulong
)msr_ap
<< MSR_AP
) |
1671 ((target_ulong
)msr_sa
<< MSR_SA
) |
1672 ((target_ulong
)msr_key
<< MSR_KEY
) |
1673 ((target_ulong
)msr_pow
<< MSR_POW
) | /* POW / WE */
1674 ((target_ulong
)msr_tlb
<< MSR_TLB
) | /* TLB / TGPE / CE */
1675 ((target_ulong
)msr_ile
<< MSR_ILE
) |
1676 ((target_ulong
)msr_ee
<< MSR_EE
) |
1677 ((target_ulong
)msr_pr
<< MSR_PR
) |
1678 ((target_ulong
)msr_fp
<< MSR_FP
) |
1679 ((target_ulong
)msr_me
<< MSR_ME
) |
1680 ((target_ulong
)msr_fe0
<< MSR_FE0
) |
1681 ((target_ulong
)msr_se
<< MSR_SE
) | /* SE / DWE / UBLE */
1682 ((target_ulong
)msr_be
<< MSR_BE
) | /* BE / DE */
1683 ((target_ulong
)msr_fe1
<< MSR_FE1
) |
1684 ((target_ulong
)msr_al
<< MSR_AL
) |
1685 ((target_ulong
)msr_ip
<< MSR_IP
) |
1686 ((target_ulong
)msr_ir
<< MSR_IR
) | /* IR / IS */
1687 ((target_ulong
)msr_dr
<< MSR_DR
) | /* DR / DS */
1688 ((target_ulong
)msr_pe
<< MSR_PE
) | /* PE / EP */
1689 ((target_ulong
)msr_px
<< MSR_PX
) | /* PX / PMM */
1690 ((target_ulong
)msr_ri
<< MSR_RI
) |
1691 ((target_ulong
)msr_le
<< MSR_LE
);
1694 void do_store_msr (CPUPPCState
*env
, target_ulong value
)
1698 value
&= env
->msr_mask
;
1699 if (((value
>> MSR_IR
) & 1) != msr_ir
||
1700 ((value
>> MSR_DR
) & 1) != msr_dr
) {
1701 /* Flush all tlb when changing translation mode */
1703 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1706 if (loglevel
!= 0) {
1707 fprintf(logfile
, "%s: T0 %08lx\n", __func__
, value
);
1710 switch (PPC_EXCP(env
)) {
1711 case PPC_FLAGS_EXCP_602
:
1712 case PPC_FLAGS_EXCP_603
:
1713 if (((value
>> MSR_TGPR
) & 1) != msr_tgpr
) {
1714 /* Swap temporary saved registers with GPRs */
1721 #if defined (TARGET_PPC64)
1722 msr_sf
= (value
>> MSR_SF
) & 1;
1723 msr_isf
= (value
>> MSR_ISF
) & 1;
1724 msr_hv
= (value
>> MSR_HV
) & 1;
1726 msr_ucle
= (value
>> MSR_UCLE
) & 1;
1727 msr_vr
= (value
>> MSR_VR
) & 1; /* VR / SPE */
1728 msr_ap
= (value
>> MSR_AP
) & 1;
1729 msr_sa
= (value
>> MSR_SA
) & 1;
1730 msr_key
= (value
>> MSR_KEY
) & 1;
1731 msr_pow
= (value
>> MSR_POW
) & 1; /* POW / WE */
1732 msr_tlb
= (value
>> MSR_TLB
) & 1; /* TLB / TGPR / CE */
1733 msr_ile
= (value
>> MSR_ILE
) & 1;
1734 msr_ee
= (value
>> MSR_EE
) & 1;
1735 msr_pr
= (value
>> MSR_PR
) & 1;
1736 msr_fp
= (value
>> MSR_FP
) & 1;
1737 msr_me
= (value
>> MSR_ME
) & 1;
1738 msr_fe0
= (value
>> MSR_FE0
) & 1;
1739 msr_se
= (value
>> MSR_SE
) & 1; /* SE / DWE / UBLE */
1740 msr_be
= (value
>> MSR_BE
) & 1; /* BE / DE */
1741 msr_fe1
= (value
>> MSR_FE1
) & 1;
1742 msr_al
= (value
>> MSR_AL
) & 1;
1743 msr_ip
= (value
>> MSR_IP
) & 1;
1744 msr_ir
= (value
>> MSR_IR
) & 1; /* IR / IS */
1745 msr_dr
= (value
>> MSR_DR
) & 1; /* DR / DS */
1746 msr_pe
= (value
>> MSR_PE
) & 1; /* PE / EP */
1747 msr_px
= (value
>> MSR_PX
) & 1; /* PX / PMM */
1748 msr_ri
= (value
>> MSR_RI
) & 1;
1749 msr_le
= (value
>> MSR_LE
) & 1;
1750 do_compute_hflags(env
);
1753 switch (PPC_EXCP(env
)) {
1754 case PPC_FLAGS_EXCP_603
:
1755 /* Don't handle SLEEP mode: we should disable all clocks...
1756 * No dynamic power-management.
1758 if (msr_pow
== 1 && (env
->spr
[SPR_HID0
] & 0x00C00000) != 0)
1761 case PPC_FLAGS_EXCP_604
:
1765 case PPC_FLAGS_EXCP_7x0
:
1766 if (msr_pow
== 1 && (env
->spr
[SPR_HID0
] & 0x00E00000) != 0)
1773 if (likely(!env
->halted
)) {
1774 /* power save: exit cpu loop */
1776 env
->exception_index
= EXCP_HLT
;
1782 #if defined(TARGET_PPC64)
1783 void ppc_store_msr_32 (CPUPPCState
*env
, uint32_t value
)
1786 (do_load_msr(env
) & ~0xFFFFFFFFULL
) | (value
& 0xFFFFFFFF));
1790 void do_compute_hflags (CPUPPCState
*env
)
1792 /* Compute current hflags */
1793 env
->hflags
= (msr_vr
<< MSR_VR
) |
1794 (msr_ap
<< MSR_AP
) | (msr_sa
<< MSR_SA
) | (msr_pr
<< MSR_PR
) |
1795 (msr_fp
<< MSR_FP
) | (msr_fe0
<< MSR_FE0
) | (msr_se
<< MSR_SE
) |
1796 (msr_be
<< MSR_BE
) | (msr_fe1
<< MSR_FE1
) | (msr_le
<< MSR_LE
);
1797 #if defined (TARGET_PPC64)
1798 env
->hflags
|= msr_cm
<< MSR_CM
;
1799 env
->hflags
|= (uint64_t)msr_sf
<< MSR_SF
;
1800 env
->hflags
|= (uint64_t)msr_hv
<< MSR_HV
;
1804 /*****************************************************************************/
1805 /* Exception processing */
1806 #if defined (CONFIG_USER_ONLY)
1807 void do_interrupt (CPUState
*env
)
1809 env
->exception_index
= -1;
1812 void ppc_hw_interrupt (CPUState
*env
)
1814 env
->exception_index
= -1;
1816 #else /* defined (CONFIG_USER_ONLY) */
1817 static void dump_syscall (CPUState
*env
)
1819 fprintf(logfile
, "syscall r0=0x" REGX
" r3=0x" REGX
" r4=0x" REGX
1820 " r5=0x" REGX
" r6=0x" REGX
" nip=0x" ADDRX
"\n",
1821 env
->gpr
[0], env
->gpr
[3], env
->gpr
[4],
1822 env
->gpr
[5], env
->gpr
[6], env
->nip
);
1825 void do_interrupt (CPUState
*env
)
1827 target_ulong msr
, *srr_0
, *srr_1
, *asrr_0
, *asrr_1
;
1830 excp
= env
->exception_index
;
1831 msr
= do_load_msr(env
);
1832 /* The default is to use SRR0 & SRR1 to save the exception context */
1833 srr_0
= &env
->spr
[SPR_SRR0
];
1834 srr_1
= &env
->spr
[SPR_SRR1
];
1837 #if defined (DEBUG_EXCEPTIONS)
1838 if ((excp
== EXCP_PROGRAM
|| excp
== EXCP_DSI
) && msr_pr
== 1) {
1839 if (loglevel
!= 0) {
1841 "Raise exception at 0x" ADDRX
" => 0x%08x (%02x)\n",
1842 env
->nip
, excp
, env
->error_code
);
1843 cpu_dump_state(env
, logfile
, fprintf
, 0);
1847 if (loglevel
& CPU_LOG_INT
) {
1848 fprintf(logfile
, "Raise exception at 0x" ADDRX
" => 0x%08x (%02x)\n",
1849 env
->nip
, excp
, env
->error_code
);
1853 /* Generate informations in save/restore registers */
1855 /* Generic PowerPC exceptions */
1856 case EXCP_RESET
: /* 0x0100 */
1857 switch (PPC_EXCP(env
)) {
1858 case PPC_FLAGS_EXCP_40x
:
1859 srr_0
= &env
->spr
[SPR_40x_SRR2
];
1860 srr_1
= &env
->spr
[SPR_40x_SRR3
];
1862 case PPC_FLAGS_EXCP_BOOKE
:
1864 srr_0
= &env
->spr
[SPR_BOOKE_CSRR0
];
1865 srr_1
= &env
->spr
[SPR_BOOKE_CSRR1
];
1874 case EXCP_MACHINE_CHECK
: /* 0x0200 */
1875 switch (PPC_EXCP(env
)) {
1876 case PPC_FLAGS_EXCP_40x
:
1877 srr_0
= &env
->spr
[SPR_40x_SRR2
];
1878 srr_1
= &env
->spr
[SPR_40x_SRR3
];
1880 case PPC_FLAGS_EXCP_BOOKE
:
1882 srr_0
= &env
->spr
[SPR_BOOKE_MCSRR0
];
1883 srr_1
= &env
->spr
[SPR_BOOKE_MCSRR1
];
1884 asrr_0
= &env
->spr
[SPR_BOOKE_CSRR0
];
1885 asrr_1
= &env
->spr
[SPR_BOOKE_CSRR1
];
1893 case EXCP_DSI
: /* 0x0300 */
1894 /* Store exception cause */
1895 /* data location address has been stored
1896 * when the fault has been detected
1900 #if defined (DEBUG_EXCEPTIONS)
1901 if (loglevel
!= 0) {
1902 fprintf(logfile
, "DSI exception: DSISR=0x" ADDRX
" DAR=0x" ADDRX
1903 "\n", env
->spr
[SPR_DSISR
], env
->spr
[SPR_DAR
]);
1907 case EXCP_ISI
: /* 0x0400 */
1908 /* Store exception cause */
1911 msr
|= env
->error_code
;
1912 #if defined (DEBUG_EXCEPTIONS)
1913 if (loglevel
!= 0) {
1914 fprintf(logfile
, "ISI exception: msr=0x" ADDRX
", nip=0x" ADDRX
1915 "\n", msr
, env
->nip
);
1919 case EXCP_EXTERNAL
: /* 0x0500 */
1922 case EXCP_ALIGN
: /* 0x0600 */
1923 if (likely(PPC_EXCP(env
) != PPC_FLAGS_EXCP_601
)) {
1924 /* Store exception cause */
1926 /* Get rS/rD and rA from faulting opcode */
1927 env
->spr
[SPR_DSISR
] |=
1928 (ldl_code((env
->nip
- 4)) & 0x03FF0000) >> 16;
1929 /* data location address has been stored
1930 * when the fault has been detected
1933 /* IO error exception on PowerPC 601 */
1936 "601 IO error exception is not implemented yet !\n");
1939 case EXCP_PROGRAM
: /* 0x0700 */
1942 switch (env
->error_code
& ~0xF) {
1944 if (msr_fe0
== 0 && msr_fe1
== 0) {
1945 #if defined (DEBUG_EXCEPTIONS)
1946 if (loglevel
!= 0) {
1947 fprintf(logfile
, "Ignore floating point exception\n");
1954 env
->fpscr
[7] |= 0x8;
1955 /* Finally, update FEX */
1956 if ((((env
->fpscr
[7] & 0x3) << 3) | (env
->fpscr
[6] >> 1)) &
1957 ((env
->fpscr
[1] << 1) | (env
->fpscr
[0] >> 3)))
1958 env
->fpscr
[7] |= 0x4;
1961 #if defined (DEBUG_EXCEPTIONS)
1962 if (loglevel
!= 0) {
1963 fprintf(logfile
, "Invalid instruction at 0x" ADDRX
"\n",
1977 /* Should never occur */
1982 case EXCP_NO_FP
: /* 0x0800 */
1988 case EXCP_SYSCALL
: /* 0x0C00 */
1990 /* NOTE: this is a temporary hack to support graphics OSI
1991 calls from the MOL driver */
1992 if (env
->gpr
[3] == 0x113724fa && env
->gpr
[4] == 0x77810f9b &&
1994 if (env
->osi_call(env
) != 0)
1997 if (loglevel
& CPU_LOG_INT
) {
2001 case EXCP_TRACE
: /* 0x0D00 */
2003 case EXCP_PERF
: /* 0x0F00 */
2006 "Performance counter exception is not implemented yet !\n");
2008 /* 32 bits PowerPC specific exceptions */
2009 case EXCP_FP_ASSIST
: /* 0x0E00 */
2011 cpu_abort(env
, "Floating point assist exception "
2012 "is not implemented yet !\n");
2014 /* 64 bits PowerPC exceptions */
2015 case EXCP_DSEG
: /* 0x0380 */
2017 cpu_abort(env
, "Data segment exception is not implemented yet !\n");
2019 case EXCP_ISEG
: /* 0x0480 */
2022 "Instruction segment exception is not implemented yet !\n");
2024 case EXCP_HDECR
: /* 0x0980 */
2026 cpu_abort(env
, "Hypervisor decrementer exception is not implemented "
2029 /* Implementation specific exceptions */
2031 if (likely(env
->spr
[SPR_PVR
] == CPU_PPC_G2
||
2032 env
->spr
[SPR_PVR
] == CPU_PPC_G2LE
)) {
2033 /* Critical interrupt on G2 */
2035 cpu_abort(env
, "G2 critical interrupt is not implemented yet !\n");
2038 cpu_abort(env
, "Invalid exception 0x0A00 !\n");
2043 switch (PPC_EXCP(env
)) {
2044 case PPC_FLAGS_EXCP_40x
:
2045 /* APU unavailable on 405 */
2048 "APU unavailable exception is not implemented yet !\n");
2050 case PPC_FLAGS_EXCP_74xx
:
2051 /* Altivec unavailable */
2053 cpu_abort(env
, "Altivec unavailable exception "
2054 "is not implemented yet !\n");
2057 cpu_abort(env
, "Invalid exception 0x0F20 !\n");
2063 switch (PPC_EXCP(env
)) {
2064 case PPC_FLAGS_EXCP_40x
:
2067 #if defined (DEBUG_EXCEPTIONS)
2069 fprintf(logfile
, "PIT exception\n");
2072 case PPC_FLAGS_EXCP_602
:
2073 case PPC_FLAGS_EXCP_603
:
2074 /* ITLBMISS on 602/603 */
2076 case PPC_FLAGS_EXCP_7x5
:
2077 /* ITLBMISS on 745/755 */
2080 cpu_abort(env
, "Invalid exception 0x1000 !\n");
2086 switch (PPC_EXCP(env
)) {
2087 case PPC_FLAGS_EXCP_40x
:
2090 #if defined (DEBUG_EXCEPTIONS)
2092 fprintf(logfile
, "FIT exception\n");
2096 cpu_abort(env
, "Invalid exception 0x1010 !\n");
2102 switch (PPC_EXCP(env
)) {
2103 case PPC_FLAGS_EXCP_40x
:
2104 /* Watchdog on 4xx */
2106 #if defined (DEBUG_EXCEPTIONS)
2108 fprintf(logfile
, "WDT exception\n");
2111 case PPC_FLAGS_EXCP_BOOKE
:
2112 srr_0
= &env
->spr
[SPR_BOOKE_CSRR0
];
2113 srr_1
= &env
->spr
[SPR_BOOKE_CSRR1
];
2116 cpu_abort(env
, "Invalid exception 0x1020 !\n");
2122 switch (PPC_EXCP(env
)) {
2123 case PPC_FLAGS_EXCP_40x
:
2124 /* DTLBMISS on 4xx */
2127 case PPC_FLAGS_EXCP_602
:
2128 case PPC_FLAGS_EXCP_603
:
2129 /* DLTLBMISS on 602/603 */
2131 case PPC_FLAGS_EXCP_7x5
:
2132 /* DLTLBMISS on 745/755 */
2135 cpu_abort(env
, "Invalid exception 0x1100 !\n");
2141 switch (PPC_EXCP(env
)) {
2142 case PPC_FLAGS_EXCP_40x
:
2143 /* ITLBMISS on 4xx */
2146 case PPC_FLAGS_EXCP_602
:
2147 case PPC_FLAGS_EXCP_603
:
2148 /* DSTLBMISS on 602/603 */
2150 /* Swap temporary saved registers with GPRs */
2153 #if defined (DEBUG_SOFTWARE_TLB)
2154 if (loglevel
!= 0) {
2155 const unsigned char *es
;
2156 target_ulong
*miss
, *cmp
;
2158 if (excp
== 0x1000) {
2161 miss
= &env
->spr
[SPR_IMISS
];
2162 cmp
= &env
->spr
[SPR_ICMP
];
2169 miss
= &env
->spr
[SPR_DMISS
];
2170 cmp
= &env
->spr
[SPR_DCMP
];
2172 fprintf(logfile
, "6xx %sTLB miss: %cM " ADDRX
" %cC " ADDRX
2173 " H1 " ADDRX
" H2 " ADDRX
" %08x\n",
2174 es
, en
, *miss
, en
, *cmp
,
2175 env
->spr
[SPR_HASH1
], env
->spr
[SPR_HASH2
],
2180 case PPC_FLAGS_EXCP_7x5
:
2181 /* DSTLBMISS on 745/755 */
2184 msr
|= env
->crf
[0] << 28;
2185 msr
|= env
->error_code
; /* key, D/I, S/L bits */
2186 /* Set way using a LRU mechanism */
2187 msr
|= ((env
->last_way
+ 1) & (env
->nb_ways
- 1)) << 17;
2190 cpu_abort(env
, "Invalid exception 0x1200 !\n");
2195 switch (PPC_EXCP(env
)) {
2196 case PPC_FLAGS_EXCP_601
:
2197 case PPC_FLAGS_EXCP_602
:
2198 case PPC_FLAGS_EXCP_603
:
2199 case PPC_FLAGS_EXCP_604
:
2200 case PPC_FLAGS_EXCP_7x0
:
2201 case PPC_FLAGS_EXCP_7x5
:
2202 /* IABR on 6xx/7xx */
2204 cpu_abort(env
, "IABR exception is not implemented yet !\n");
2207 cpu_abort(env
, "Invalid exception 0x1300 !\n");
2212 switch (PPC_EXCP(env
)) {
2213 case PPC_FLAGS_EXCP_601
:
2214 case PPC_FLAGS_EXCP_602
:
2215 case PPC_FLAGS_EXCP_603
:
2216 case PPC_FLAGS_EXCP_604
:
2217 case PPC_FLAGS_EXCP_7x0
:
2218 case PPC_FLAGS_EXCP_7x5
:
2219 /* SMI on 6xx/7xx */
2221 cpu_abort(env
, "SMI exception is not implemented yet !\n");
2224 cpu_abort(env
, "Invalid exception 0x1400 !\n");
2229 switch (PPC_EXCP(env
)) {
2230 case PPC_FLAGS_EXCP_602
:
2231 /* Watchdog on 602 */
2234 "602 watchdog exception is not implemented yet !\n");
2236 case PPC_FLAGS_EXCP_970
:
2237 /* Soft patch exception on 970 */
2240 "970 soft-patch exception is not implemented yet !\n");
2242 case PPC_FLAGS_EXCP_74xx
:
2243 /* VPU assist on 74xx */
2245 cpu_abort(env
, "VPU assist exception is not implemented yet !\n");
2248 cpu_abort(env
, "Invalid exception 0x1500 !\n");
2253 switch (PPC_EXCP(env
)) {
2254 case PPC_FLAGS_EXCP_602
:
2255 /* Emulation trap on 602 */
2257 cpu_abort(env
, "602 emulation trap exception "
2258 "is not implemented yet !\n");
2260 case PPC_FLAGS_EXCP_970
:
2261 /* Maintenance exception on 970 */
2264 "970 maintenance exception is not implemented yet !\n");
2267 cpu_abort(env
, "Invalid exception 0x1600 !\n");
2272 switch (PPC_EXCP(env
)) {
2273 case PPC_FLAGS_EXCP_7x0
:
2274 case PPC_FLAGS_EXCP_7x5
:
2275 /* Thermal management interrupt on G3 */
2277 cpu_abort(env
, "G3 thermal management exception "
2278 "is not implemented yet !\n");
2280 case PPC_FLAGS_EXCP_970
:
2281 /* VPU assist on 970 */
2284 "970 VPU assist exception is not implemented yet !\n");
2287 cpu_abort(env
, "Invalid exception 0x1700 !\n");
2292 switch (PPC_EXCP(env
)) {
2293 case PPC_FLAGS_EXCP_970
:
2294 /* Thermal exception on 970 */
2296 cpu_abort(env
, "970 thermal management exception "
2297 "is not implemented yet !\n");
2300 cpu_abort(env
, "Invalid exception 0x1800 !\n");
2305 switch (PPC_EXCP(env
)) {
2306 case PPC_FLAGS_EXCP_40x
:
2309 cpu_abort(env
, "40x debug exception is not implemented yet !\n");
2311 case PPC_FLAGS_EXCP_601
:
2312 /* Run mode exception on 601 */
2315 "601 run mode exception is not implemented yet !\n");
2317 case PPC_FLAGS_EXCP_BOOKE
:
2318 srr_0
= &env
->spr
[SPR_BOOKE_CSRR0
];
2319 srr_1
= &env
->spr
[SPR_BOOKE_CSRR1
];
2322 cpu_abort(env
, "Invalid exception 0x1800 !\n");
2326 /* Other exceptions */
2327 /* Qemu internal exceptions:
2328 * we should never come here with those values: abort execution
2331 cpu_abort(env
, "Invalid exception: code %d (%04x)\n", excp
, excp
);
2334 /* save current instruction location */
2335 *srr_0
= env
->nip
- 4;
2338 /* save next instruction location */
2348 /* If we disactivated any translation, flush TLBs */
2349 if (msr_ir
|| msr_dr
) {
2352 /* reload MSR with correct bits */
2364 if (PPC_EXCP(env
) == PPC_FLAGS_EXCP_BOOKE
) {
2366 if (idx
== -1 || (idx
>= 16 && idx
< 32)) {
2367 cpu_abort(env
, "Invalid exception index for excp %d %08x idx %d\n",
2370 #if defined(TARGET_PPC64)
2372 env
->nip
= (uint64_t)env
->spr
[SPR_BOOKE_IVPR
];
2375 env
->nip
= (uint32_t)env
->spr
[SPR_BOOKE_IVPR
];
2377 env
->nip
|= env
->spr
[SPR_BOOKE_IVOR0
+ idx
];
2379 env
->nip
|= env
->spr
[SPR_BOOKE_IVOR32
+ idx
- 32];
2384 do_compute_hflags(env
);
2385 /* Jump to handler */
2386 env
->exception_index
= EXCP_NONE
;
2389 void ppc_hw_interrupt (CPUPPCState
*env
)
2394 if (loglevel
& CPU_LOG_INT
) {
2395 fprintf(logfile
, "%s: %p pending %08x req %08x me %d ee %d\n",
2396 __func__
, env
, env
->pending_interrupts
,
2397 env
->interrupt_request
, msr_me
, msr_ee
);
2401 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_RESET
)) {
2402 /* External reset / critical input */
2403 /* XXX: critical input should be handled another way.
2404 * This code is not correct !
2406 env
->exception_index
= EXCP_RESET
;
2407 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_RESET
);
2410 if (raised
== 0 && msr_me
!= 0) {
2411 /* Machine check exception */
2412 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_MCK
)) {
2413 env
->exception_index
= EXCP_MACHINE_CHECK
;
2414 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_MCK
);
2418 if (raised
== 0 && msr_ee
!= 0) {
2419 #if defined(TARGET_PPC64H) /* PowerPC 64 with hypervisor mode support */
2420 /* Hypervisor decrementer exception */
2421 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_HDECR
)) {
2422 env
->exception_index
= EXCP_HDECR
;
2423 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_HDECR
);
2427 /* Decrementer exception */
2428 if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DECR
)) {
2429 env
->exception_index
= EXCP_DECR
;
2430 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DECR
);
2432 /* Programmable interval timer on embedded PowerPC */
2433 } else if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_PIT
)) {
2434 env
->exception_index
= EXCP_40x_PIT
;
2435 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_PIT
);
2437 /* Fixed interval timer on embedded PowerPC */
2438 } else if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_FIT
)) {
2439 env
->exception_index
= EXCP_40x_FIT
;
2440 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_FIT
);
2442 /* Watchdog timer on embedded PowerPC */
2443 } else if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_WDT
)) {
2444 env
->exception_index
= EXCP_40x_WATCHDOG
;
2445 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_WDT
);
2447 /* External interrupt */
2448 } else if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_EXT
)) {
2449 env
->exception_index
= EXCP_EXTERNAL
;
2450 /* Taking an external interrupt does not clear the external
2454 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_EXT
);
2458 /* Thermal interrupt */
2459 } else if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_THERM
)) {
2460 env
->exception_index
= EXCP_970_THRM
;
2461 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_THERM
);
2466 /* External debug exception */
2467 } else if (env
->pending_interrupts
& (1 << PPC_INTERRUPT_DEBUG
)) {
2468 env
->exception_index
= EXCP_xxx
;
2469 env
->pending_interrupts
&= ~(1 << PPC_INTERRUPT_DEBUG
);
2474 env
->error_code
= 0;
2478 #endif /* !CONFIG_USER_ONLY */
2480 void cpu_dump_EA (target_ulong EA
)
2490 fprintf(f
, "Memory access at address " ADDRX
"\n", EA
);
2493 void cpu_dump_rfi (target_ulong RA
, target_ulong msr
)
2503 fprintf(f
, "Return from exception at " ADDRX
" with flags " ADDRX
"\n",
2507 void cpu_ppc_reset (void *opaque
)
2513 /* XXX: some of those flags initialisation values could depend
2514 * on the actual PowerPC implementation
2516 for (i
= 0; i
< 63; i
++)
2518 #if defined(TARGET_PPC64)
2519 msr_hv
= 0; /* Should be 1... */
2521 msr_ap
= 0; /* TO BE CHECKED */
2522 msr_sa
= 0; /* TO BE CHECKED */
2523 msr_ip
= 0; /* TO BE CHECKED */
2524 #if defined (DO_SINGLE_STEP) && 0
2525 /* Single step trace mode */
2529 #if defined(CONFIG_USER_ONLY)
2530 msr_fp
= 1; /* Allow floating point exceptions */
2533 env
->nip
= 0xFFFFFFFC;
2534 ppc_tlb_invalidate_all(env
);
2536 do_compute_hflags(env
);
2538 /* Be sure no exception or interrupt is pending */
2539 env
->pending_interrupts
= 0;
2540 env
->exception_index
= EXCP_NONE
;
2541 /* Flush all TLBs */
2545 CPUPPCState
*cpu_ppc_init (void)
2549 env
= qemu_mallocz(sizeof(CPUPPCState
));
2558 void cpu_ppc_close (CPUPPCState
*env
)
2560 /* Should also remove all opcode tables... */