73
68
/* Common routines used by software and hardware TLBs emulation */
74
static always_inline int pte_is_valid (target_ulong pte0)
69
static inline int pte_is_valid (target_ulong pte0)
76
71
return pte0 & 0x80000000 ? 1 : 0;
79
static always_inline void pte_invalidate (target_ulong *pte0)
74
static inline void pte_invalidate (target_ulong *pte0)
81
76
*pte0 &= ~0x80000000;
84
#if defined(TARGET_PPC64)
85
static always_inline int pte64_is_valid (target_ulong pte0)
87
return pte0 & 0x0000000000000001ULL ? 1 : 0;
90
static always_inline void pte64_invalidate (target_ulong *pte0)
92
*pte0 &= ~0x0000000000000001ULL;
96
79
#define PTE_PTEM_MASK 0x7FFFFFBF
97
80
#define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B)
98
#if defined(TARGET_PPC64)
99
#define PTE64_PTEM_MASK 0xFFFFFFFFFFFFFF80ULL
100
#define PTE64_CHECK_MASK (TARGET_PAGE_MASK | 0x7F)
103
static always_inline int pp_check (int key, int pp, int nx)
107
/* Compute access rights */
108
/* When pp is 3/7, the result is undefined. Set it to noaccess */
115
access |= PAGE_WRITE;
133
access = PAGE_READ | PAGE_WRITE;
143
static always_inline int check_prot (int prot, int rw, int access_type)
147
if (access_type == ACCESS_CODE) {
148
if (prot & PAGE_EXEC)
153
if (prot & PAGE_WRITE)
158
if (prot & PAGE_READ)
167
static always_inline int _pte_check (mmu_ctx_t *ctx, int is_64b,
168
target_ulong pte0, target_ulong pte1,
169
int h, int rw, int type)
171
target_ulong ptem, mmask;
172
int access, ret, pteh, ptev, pp;
82
static int pte_check (mmu_ctx_t *ctx,
83
target_ulong pte0, target_ulong pte1, int h, int rw)
176
89
/* Check validity and table match */
177
#if defined(TARGET_PPC64)
179
ptev = pte64_is_valid(pte0);
180
pteh = (pte0 >> 1) & 1;
184
ptev = pte_is_valid(pte0);
185
pteh = (pte0 >> 6) & 1;
187
if (ptev && h == pteh) {
90
if (pte_is_valid(pte0) && (h == ((pte0 >> 6) & 1))) {
188
91
/* Check vsid & api */
189
#if defined(TARGET_PPC64)
191
ptem = pte0 & PTE64_PTEM_MASK;
192
mmask = PTE64_CHECK_MASK;
193
pp = (pte1 & 0x00000003) | ((pte1 >> 61) & 0x00000004);
194
ctx->nx |= (pte1 >> 2) & 1; /* No execute bit */
195
ctx->nx |= (pte1 >> 3) & 1; /* Guarded bit */
199
ptem = pte0 & PTE_PTEM_MASK;
200
mmask = PTE_CHECK_MASK;
201
pp = pte1 & 0x00000003;
203
if (ptem == ctx->ptem) {
204
if (ctx->raddr != (target_phys_addr_t)-1ULL) {
92
if ((pte0 & PTE_PTEM_MASK) == ctx->ptem) {
93
if (ctx->raddr != (target_ulong)-1) {
205
94
/* all matches should have equal RPN, WIMG & PP */
206
if ((ctx->raddr & mmask) != (pte1 & mmask)) {
95
if ((ctx->raddr & PTE_CHECK_MASK) != (pte1 & PTE_CHECK_MASK)) {
208
97
fprintf(logfile, "Bad RPN/WIMG/PP\n");
212
101
/* Compute access rights */
213
access = pp_check(ctx->key, pp, ctx->nx);
104
if ((pte1 & 0x00000003) != 0x3)
105
access |= PAGE_WRITE;
107
switch (pte1 & 0x00000003) {
116
access = PAGE_READ | PAGE_WRITE;
214
120
/* Keep the matching PTE informations */
215
121
ctx->raddr = pte1;
216
122
ctx->prot = access;
217
ret = check_prot(ctx->prot, rw, type);
123
if ((rw == 0 && (access & PAGE_READ)) ||
124
(rw == 1 && (access & PAGE_WRITE))) {
219
125
/* Access granted */
220
126
#if defined (DEBUG_MMU)
221
127
if (loglevel != 0)
222
128
fprintf(logfile, "PTE access granted !\n");
225
132
/* Access right violation */
226
133
#if defined (DEBUG_MMU)
227
134
if (loglevel != 0)
228
135
fprintf(logfile, "PTE access rejected\n");
662
487
#if defined (DEBUG_MMU)
663
488
if (loglevel != 0) {
664
fprintf(logfile, "found PTE at addr " PADDRX " prot=%01x ret=%d\n",
489
fprintf(logfile, "found PTE at addr 0x" PADDRX " prot=0x%01x "
665
491
ctx->raddr, ctx->prot, ret);
668
494
/* Update page flags */
669
495
pte1 = ctx->raddr;
670
if (pte_update_flags(ctx, &pte1, ret, rw) == 1) {
671
#if defined(TARGET_PPC64)
673
stq_phys_notdirty(base + (good * 16) + 8, pte1);
677
stl_phys_notdirty(base + (good * 8) + 4, pte1);
685
static always_inline int find_pte32 (mmu_ctx_t *ctx, int h, int rw, int type)
687
return _find_pte(ctx, 0, h, rw, type);
690
#if defined(TARGET_PPC64)
691
static always_inline int find_pte64 (mmu_ctx_t *ctx, int h, int rw, int type)
693
return _find_pte(ctx, 1, h, rw, type);
697
static always_inline int find_pte (CPUState *env, mmu_ctx_t *ctx,
698
int h, int rw, int type)
700
#if defined(TARGET_PPC64)
701
if (env->mmu_model & POWERPC_MMU_64)
702
return find_pte64(ctx, h, rw, type);
705
return find_pte32(ctx, h, rw, type);
708
#if defined(TARGET_PPC64)
709
static always_inline int slb_is_valid (uint64_t slb64)
711
return slb64 & 0x0000000008000000ULL ? 1 : 0;
714
static always_inline void slb_invalidate (uint64_t *slb64)
716
*slb64 &= ~0x0000000008000000ULL;
719
static always_inline int slb_lookup (CPUPPCState *env, target_ulong eaddr,
721
target_ulong *page_mask, int *attr)
723
target_phys_addr_t sr_base;
730
sr_base = env->spr[SPR_ASR];
731
#if defined(DEBUG_SLB)
733
fprintf(logfile, "%s: eaddr " ADDRX " base " PADDRX "\n",
734
__func__, eaddr, sr_base);
737
mask = 0x0000000000000000ULL; /* Avoid gcc warning */
738
for (n = 0; n < env->slb_nr; n++) {
739
tmp64 = ldq_phys(sr_base);
740
tmp = ldl_phys(sr_base + 8);
741
#if defined(DEBUG_SLB)
743
fprintf(logfile, "%s: seg %d " PADDRX " %016" PRIx64 " %08"
744
PRIx32 "\n", __func__, n, sr_base, tmp64, tmp);
747
if (slb_is_valid(tmp64)) {
748
/* SLB entry is valid */
749
switch (tmp64 & 0x0000000006000000ULL) {
750
case 0x0000000000000000ULL:
752
mask = 0xFFFFFFFFF0000000ULL;
754
case 0x0000000002000000ULL:
756
mask = 0xFFFF000000000000ULL;
758
case 0x0000000004000000ULL:
759
case 0x0000000006000000ULL:
760
/* Reserved => segment is invalid */
763
if ((eaddr & mask) == (tmp64 & mask)) {
765
*vsid = ((tmp64 << 24) | (tmp >> 8)) & 0x0003FFFFFFFFFFFFULL;
778
void ppc_slb_invalidate_all (CPUPPCState *env)
780
target_phys_addr_t sr_base;
782
int n, do_invalidate;
785
sr_base = env->spr[SPR_ASR];
786
/* XXX: Warning: slbia never invalidates the first segment */
787
for (n = 1; n < env->slb_nr; n++) {
788
tmp64 = ldq_phys(sr_base);
789
if (slb_is_valid(tmp64)) {
790
slb_invalidate(&tmp64);
791
stq_phys(sr_base, tmp64);
792
/* XXX: given the fact that segment size is 256 MB or 1TB,
793
* and we still don't have a tlb_flush_mask(env, n, mask)
794
* in Qemu, we just invalidate all TLBs
804
void ppc_slb_invalidate_one (CPUPPCState *env, uint64_t T0)
806
target_phys_addr_t sr_base;
807
target_ulong vsid, page_mask;
812
n = slb_lookup(env, T0, &vsid, &page_mask, &attr);
814
sr_base = env->spr[SPR_ASR];
816
tmp64 = ldq_phys(sr_base);
817
if (slb_is_valid(tmp64)) {
818
slb_invalidate(&tmp64);
819
stq_phys(sr_base, tmp64);
820
/* XXX: given the fact that segment size is 256 MB or 1TB,
821
* and we still don't have a tlb_flush_mask(env, n, mask)
822
* in Qemu, we just invalidate all TLBs
829
target_ulong ppc_load_slb (CPUPPCState *env, int slb_nr)
831
target_phys_addr_t sr_base;
836
sr_base = env->spr[SPR_ASR];
837
sr_base += 12 * slb_nr;
838
tmp64 = ldq_phys(sr_base);
839
tmp = ldl_phys(sr_base + 8);
840
if (tmp64 & 0x0000000008000000ULL) {
841
/* SLB entry is valid */
842
/* Copy SLB bits 62:88 to Rt 37:63 (VSID 23:49) */
843
rt = tmp >> 8; /* 65:88 => 40:63 */
844
rt |= (tmp64 & 0x7) << 24; /* 62:64 => 37:39 */
845
/* Copy SLB bits 89:92 to Rt 33:36 (KsKpNL) */
846
rt |= ((tmp >> 4) & 0xF) << 27;
850
#if defined(DEBUG_SLB)
852
fprintf(logfile, "%s: " PADDRX " %016" PRIx64 " %08" PRIx32 " => %d "
853
ADDRX "\n", __func__, sr_base, tmp64, tmp, slb_nr, rt);
860
void ppc_store_slb (CPUPPCState *env, int slb_nr, target_ulong rs)
862
target_phys_addr_t sr_base;
866
sr_base = env->spr[SPR_ASR];
867
sr_base += 12 * slb_nr;
868
/* Copy Rs bits 37:63 to SLB 62:88 */
870
tmp64 = (rs >> 24) & 0x7;
871
/* Copy Rs bits 33:36 to SLB 89:92 */
872
tmp |= ((rs >> 27) & 0xF) << 4;
873
/* Set the valid bit */
876
tmp64 |= (uint32_t)slb_nr << 28;
877
#if defined(DEBUG_SLB)
879
fprintf(logfile, "%s: %d " ADDRX " => " PADDRX " %016" PRIx64
880
" %08" PRIx32 "\n", __func__,
881
slb_nr, rs, sr_base, tmp64, tmp);
884
/* Write SLB entry to memory */
885
stq_phys(sr_base, tmp64);
886
stl_phys(sr_base + 8, tmp);
888
#endif /* defined(TARGET_PPC64) */
496
if (pte_update_flags(ctx, &pte1, ret, rw) == 1)
497
stl_phys_notdirty(base + (good * 8) + 4, pte1);
503
static inline target_phys_addr_t get_pgaddr (target_phys_addr_t sdr1,
504
target_phys_addr_t hash,
505
target_phys_addr_t mask)
507
return (sdr1 & 0xFFFF0000) | (hash & mask);
890
510
/* Perform segment based translation */
891
static always_inline target_phys_addr_t get_pgaddr (target_phys_addr_t sdr1,
893
target_phys_addr_t hash,
894
target_phys_addr_t mask)
896
return (sdr1 & ((target_phys_addr_t)(-1ULL) << sdr_sh)) | (hash & mask);
899
static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx,
900
target_ulong eaddr, int rw, int type)
902
target_phys_addr_t sdr, hash, mask, sdr_mask, htab_mask;
903
target_ulong sr, vsid, vsid_mask, pgidx, page_mask;
904
#if defined(TARGET_PPC64)
907
int ds, vsid_sh, sdr_sh, pr;
911
#if defined(TARGET_PPC64)
912
if (env->mmu_model & POWERPC_MMU_64) {
913
#if defined (DEBUG_MMU)
915
fprintf(logfile, "Check SLBs\n");
918
ret = slb_lookup(env, eaddr, &vsid, &page_mask, &attr);
921
ctx->key = ((attr & 0x40) && (pr != 0)) ||
922
((attr & 0x80) && (pr == 0)) ? 1 : 0;
924
ctx->nx = attr & 0x20 ? 1 : 0;
925
vsid_mask = 0x00003FFFFFFFFF80ULL;
930
#endif /* defined(TARGET_PPC64) */
932
sr = env->sr[eaddr >> 28];
933
page_mask = 0x0FFFFFFF;
934
ctx->key = (((sr & 0x20000000) && (pr != 0)) ||
935
((sr & 0x40000000) && (pr == 0))) ? 1 : 0;
936
ds = sr & 0x80000000 ? 1 : 0;
937
ctx->nx = sr & 0x10000000 ? 1 : 0;
938
vsid = sr & 0x00FFFFFF;
939
vsid_mask = 0x01FFFFC0;
943
#if defined (DEBUG_MMU)
945
fprintf(logfile, "Check segment v=" ADDRX " %d " ADDRX
946
" nip=" ADDRX " lr=" ADDRX " ir=%d dr=%d pr=%d %d t=%d\n",
947
eaddr, (int)(eaddr >> 28), sr, env->nip,
948
env->lr, (int)msr_ir, (int)msr_dr, pr != 0 ? 1 : 0,
953
#if defined (DEBUG_MMU)
955
fprintf(logfile, "pte segment: key=%d ds %d nx %d vsid " ADDRX "\n",
956
ctx->key, ds, ctx->nx, vsid);
511
static int get_segment (CPUState *env, mmu_ctx_t *ctx,
512
target_ulong eaddr, int rw, int type)
514
target_phys_addr_t sdr, hash, mask;
515
target_ulong sr, vsid, pgidx;
518
sr = env->sr[eaddr >> 28];
519
#if defined (DEBUG_MMU)
521
fprintf(logfile, "Check segment v=0x" ADDRX " %d 0x" ADDRX " nip=0x"
522
ADDRX " lr=0x" ADDRX " ir=%d dr=%d pr=%d %d t=%d\n",
523
eaddr, eaddr >> 28, sr, env->nip,
524
env->lr, msr_ir, msr_dr, msr_pr, rw, type);
527
ctx->key = (((sr & 0x20000000) && msr_pr == 1) ||
528
((sr & 0x40000000) && msr_pr == 0)) ? 1 : 0;
529
if ((sr & 0x80000000) == 0) {
530
#if defined (DEBUG_MMU)
532
fprintf(logfile, "pte segment: key=%d n=0x" ADDRX "\n",
533
ctx->key, sr & 0x10000000);
961
535
/* Check if instruction fetch is allowed, if needed */
962
if (type != ACCESS_CODE || ctx->nx == 0) {
536
if (type != ACCESS_CODE || (sr & 0x10000000) == 0) {
963
537
/* Page address translation */
538
pgidx = (eaddr >> TARGET_PAGE_BITS) & 0xFFFF;
539
vsid = sr & 0x00FFFFFF;
540
hash = ((vsid ^ pgidx) & 0x0007FFFF) << 6;
964
541
/* Primary table address */
966
pgidx = (eaddr & page_mask) >> TARGET_PAGE_BITS;
967
#if defined(TARGET_PPC64)
968
if (env->mmu_model & POWERPC_MMU_64) {
969
htab_mask = 0x0FFFFFFF >> (28 - (sdr & 0x1F));
970
/* XXX: this is false for 1 TB segments */
971
hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask;
975
htab_mask = sdr & 0x000001FF;
976
hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask;
978
mask = (htab_mask << sdr_sh) | sdr_mask;
979
#if defined (DEBUG_MMU)
981
fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX
982
" mask " PADDRX " " ADDRX "\n",
983
sdr, sdr_sh, hash, mask, page_mask);
986
ctx->pg_addr[0] = get_pgaddr(sdr, sdr_sh, hash, mask);
543
mask = ((sdr & 0x000001FF) << 16) | 0xFFC0;
544
ctx->pg_addr[0] = get_pgaddr(sdr, hash, mask);
987
545
/* Secondary table address */
988
hash = (~hash) & vsid_mask;
989
#if defined (DEBUG_MMU)
991
fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX
992
" mask " PADDRX "\n",
993
sdr, sdr_sh, hash, mask);
996
ctx->pg_addr[1] = get_pgaddr(sdr, sdr_sh, hash, mask);
997
#if defined(TARGET_PPC64)
998
if (env->mmu_model & POWERPC_MMU_64) {
999
/* Only 5 bits of the page index are used in the AVPN */
1000
ctx->ptem = (vsid << 12) | ((pgidx >> 4) & 0x0F80);
1004
ctx->ptem = (vsid << 7) | (pgidx >> 10);
546
hash = (~hash) & 0x01FFFFC0;
547
ctx->pg_addr[1] = get_pgaddr(sdr, hash, mask);
548
ctx->ptem = (vsid << 7) | (pgidx >> 10);
1006
549
/* Initialize real address with an invalid value */
1007
ctx->raddr = (target_phys_addr_t)-1ULL;
1008
if (unlikely(env->mmu_model == POWERPC_MMU_SOFT_6xx ||
1009
env->mmu_model == POWERPC_MMU_SOFT_74xx)) {
550
ctx->raddr = (target_ulong)-1;
551
if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
1010
552
/* Software TLB search */
1011
553
ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type);
1013
555
#if defined (DEBUG_MMU)
1014
556
if (loglevel != 0) {
1015
fprintf(logfile, "0 sdr1=" PADDRX " vsid=" ADDRX " "
1016
"api=" ADDRX " hash=" PADDRX
1017
" pg_addr=" PADDRX "\n",
1018
sdr, vsid, pgidx, hash, ctx->pg_addr[0]);
557
fprintf(logfile, "0 sdr1=0x" PADDRX " vsid=0x%06x "
558
"api=0x%04x hash=0x%07x pg_addr=0x" PADDRX "\n",
559
sdr, (uint32_t)vsid, (uint32_t)pgidx,
560
(uint32_t)hash, ctx->pg_addr[0]);
1021
563
/* Primary table lookup */
1022
ret = find_pte(env, ctx, 0, rw, type);
564
ret = find_pte(ctx, 0, rw);
1024
566
/* Secondary table lookup */
1025
567
#if defined (DEBUG_MMU)
1026
568
if (eaddr != 0xEFFFFFFF && loglevel != 0) {
1027
fprintf(logfile, "1 sdr1=" PADDRX " vsid=" ADDRX " "
1028
"api=" ADDRX " hash=" PADDRX
1029
" pg_addr=" PADDRX "\n",
1030
sdr, vsid, pgidx, hash, ctx->pg_addr[1]);
570
"1 sdr1=0x" PADDRX " vsid=0x%06x api=0x%04x "
571
"hash=0x%05x pg_addr=0x" PADDRX "\n",
572
sdr, (uint32_t)vsid, (uint32_t)pgidx,
573
(uint32_t)hash, ctx->pg_addr[1]);
1033
ret2 = find_pte(env, ctx, 1, rw, type);
576
ret2 = find_pte(ctx, 1, rw);
1038
#if defined (DUMP_PAGE_TABLES)
1039
if (loglevel != 0) {
1040
target_phys_addr_t curaddr;
1041
uint32_t a0, a1, a2, a3;
1042
fprintf(logfile, "Page table: " PADDRX " len " PADDRX "\n",
1044
for (curaddr = sdr; curaddr < (sdr + mask + 0x80);
1046
a0 = ldl_phys(curaddr);
1047
a1 = ldl_phys(curaddr + 4);
1048
a2 = ldl_phys(curaddr + 8);
1049
a3 = ldl_phys(curaddr + 12);
1050
if (a0 != 0 || a1 != 0 || a2 != 0 || a3 != 0) {
1051
fprintf(logfile, PADDRX ": %08x %08x %08x %08x\n",
1052
curaddr, a0, a1, a2, a3);
1058
582
#if defined (DEBUG_MMU)
1059
583
if (loglevel != 0)
1170
686
/* Helpers specific to PowerPC 40x implementations */
1171
static always_inline void ppc4xx_tlb_invalidate_all (CPUState *env)
1176
for (i = 0; i < env->nb_tlb; i++) {
1177
tlb = &env->tlb[i].tlbe;
1178
tlb->prot &= ~PAGE_VALID;
1183
static always_inline void ppc4xx_tlb_invalidate_virt (CPUState *env,
1187
#if !defined(FLUSH_ALL_TLBS)
1189
target_phys_addr_t raddr;
1190
target_ulong page, end;
1193
for (i = 0; i < env->nb_tlb; i++) {
1194
tlb = &env->tlb[i].tlbe;
1195
if (ppcemb_tlb_check(env, tlb, &raddr, eaddr, pid, 0, i) == 0) {
687
void ppc4xx_tlb_invalidate_all (CPUState *env)
692
for (i = 0; i < env->nb_tlb; i++) {
693
tlb = &env->tlb[i].tlbe;
694
if (tlb->prot & PAGE_VALID) {
695
#if 0 // XXX: TLB have variable sizes then we flush all Qemu TLB.
1196
696
end = tlb->EPN + tlb->size;
1197
697
for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
1198
698
tlb_flush_page(env, page);
1199
700
tlb->prot &= ~PAGE_VALID;
1204
ppc4xx_tlb_invalidate_all(env);
1208
int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
706
int mmu4xx_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
1209
707
target_ulong address, int rw, int access_type)
1211
709
ppcemb_tlb_t *tlb;
1212
710
target_phys_addr_t raddr;
1213
int i, ret, zsel, zpr, pr;
711
int i, ret, zsel, zpr;
1216
raddr = (target_phys_addr_t)-1ULL;
1218
715
for (i = 0; i < env->nb_tlb; i++) {
1219
716
tlb = &env->tlb[i].tlbe;
1220
if (ppcemb_tlb_check(env, tlb, &raddr, address,
1221
env->spr[SPR_40x_PID], 0, i) < 0)
717
if (ppcemb_tlb_check(env, tlb, &raddr, address, i) < 0)
1223
719
zsel = (tlb->attr >> 4) & 0xF;
1224
720
zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3;
1225
#if defined (DEBUG_SOFTWARE_TLB)
1226
721
if (loglevel != 0) {
1227
722
fprintf(logfile, "%s: TLB %d zsel %d zpr %d rw %d attr %08x\n",
1228
723
__func__, i, zsel, zpr, rw, tlb->attr);
1231
/* Check execute enable bit */
1238
/* All accesses granted */
1239
ctx->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
1251
/* Check from TLB entry */
1252
/* XXX: there is a problem here or in the TLB fill code... */
1253
ctx->prot = tlb->prot;
1254
ctx->prot |= PAGE_EXEC;
1255
ret = check_prot(ctx->prot, rw, access_type);
725
if (access_type == ACCESS_CODE) {
726
/* Check execute enable bit */
730
goto check_exec_perm;
741
/* Check from TLB entry */
742
if (!(tlb->prot & PAGE_EXEC)) {
745
if (tlb->prot & PAGE_WRITE) {
746
ctx->prot = PAGE_READ | PAGE_WRITE;
748
ctx->prot = PAGE_READ;
755
/* All accesses granted */
756
ctx->prot = PAGE_READ | PAGE_WRITE;
775
/* Check from TLB entry */
776
/* Check write protection bit */
777
if (tlb->prot & PAGE_WRITE) {
778
ctx->prot = PAGE_READ | PAGE_WRITE;
781
ctx->prot = PAGE_READ;
790
/* All accesses granted */
791
ctx->prot = PAGE_READ | PAGE_WRITE;
1259
797
ctx->raddr = raddr;
1260
#if defined (DEBUG_SOFTWARE_TLB)
1261
798
if (loglevel != 0) {
1262
fprintf(logfile, "%s: access granted " ADDRX " => " PADDRX
799
fprintf(logfile, "%s: access granted " ADDRX " => " REGX
1263
800
" %d %d\n", __func__, address, ctx->raddr, ctx->prot,
1270
#if defined (DEBUG_SOFTWARE_TLB)
1271
806
if (loglevel != 0) {
1272
fprintf(logfile, "%s: access refused " ADDRX " => " PADDRX
807
fprintf(logfile, "%s: access refused " ADDRX " => " REGX
1273
808
" %d %d\n", __func__, address, raddr, ctx->prot,
1287
821
env->spr[SPR_405_SLER] = val;
1290
int mmubooke_get_physical_address (CPUState *env, mmu_ctx_t *ctx,
1291
target_ulong address, int rw,
1295
target_phys_addr_t raddr;
1299
raddr = (target_phys_addr_t)-1ULL;
1300
for (i = 0; i < env->nb_tlb; i++) {
1301
tlb = &env->tlb[i].tlbe;
1302
if (ppcemb_tlb_check(env, tlb, &raddr, address,
1303
env->spr[SPR_BOOKE_PID], 1, i) < 0)
1306
prot = tlb->prot & 0xF;
1308
prot = (tlb->prot >> 4) & 0xF;
1309
/* Check the address space */
1310
if (access_type == ACCESS_CODE) {
1311
if (msr_ir != (tlb->attr & 1))
1314
if (prot & PAGE_EXEC) {
1320
if (msr_dr != (tlb->attr & 1))
1323
if ((!rw && prot & PAGE_READ) || (rw && (prot & PAGE_WRITE))) {
1336
static always_inline int check_physical (CPUState *env, mmu_ctx_t *ctx,
1337
target_ulong eaddr, int rw)
824
static int check_physical (CPUState *env, mmu_ctx_t *ctx,
825
target_ulong eaddr, int rw)
1339
827
int in_plb, ret;
1341
829
ctx->raddr = eaddr;
1342
ctx->prot = PAGE_READ | PAGE_EXEC;
830
ctx->prot = PAGE_READ;
1344
switch (env->mmu_model) {
1345
case POWERPC_MMU_32B:
1346
case POWERPC_MMU_601:
1347
case POWERPC_MMU_SOFT_6xx:
1348
case POWERPC_MMU_SOFT_74xx:
1349
case POWERPC_MMU_SOFT_4xx:
1350
case POWERPC_MMU_REAL:
1351
case POWERPC_MMU_BOOKE:
1352
ctx->prot |= PAGE_WRITE;
1354
#if defined(TARGET_PPC64)
1355
case POWERPC_MMU_620:
1356
case POWERPC_MMU_64B:
1357
/* Real address are 60 bits long */
1358
ctx->raddr &= 0x0FFFFFFFFFFFFFFFULL;
1359
ctx->prot |= PAGE_WRITE;
1362
case POWERPC_MMU_SOFT_4xx_Z:
1363
if (unlikely(msr_pe != 0)) {
1364
/* 403 family add some particular protections,
1365
* using PBL/PBU registers for accesses with no translation.
1368
/* Check PLB validity */
1369
(env->pb[0] < env->pb[1] &&
1370
/* and address in plb area */
1371
eaddr >= env->pb[0] && eaddr < env->pb[1]) ||
1372
(env->pb[2] < env->pb[3] &&
1373
eaddr >= env->pb[2] && eaddr < env->pb[3]) ? 1 : 0;
1374
if (in_plb ^ msr_px) {
1375
/* Access in protected area */
1377
/* Access is not allowed */
1381
/* Read-write access is allowed */
1382
ctx->prot |= PAGE_WRITE;
832
if (unlikely(msr_pe != 0 && PPC_MMU(env) == PPC_FLAGS_MMU_403)) {
833
/* 403 family add some particular protections,
834
* using PBL/PBU registers for accesses with no translation.
837
/* Check PLB validity */
838
(env->pb[0] < env->pb[1] &&
839
/* and address in plb area */
840
eaddr >= env->pb[0] && eaddr < env->pb[1]) ||
841
(env->pb[2] < env->pb[3] &&
842
eaddr >= env->pb[2] && eaddr < env->pb[3]) ? 1 : 0;
843
if (in_plb ^ msr_px) {
844
/* Access in protected area */
846
/* Access is not allowed */
850
/* Read-write access is allowed */
851
ctx->prot |= PAGE_WRITE;
1386
case POWERPC_MMU_MPC8xx:
1388
cpu_abort(env, "MPC8xx MMU model is not implemented\n");
1390
case POWERPC_MMU_BOOKE_FSL:
1392
cpu_abort(env, "BookE FSL MMU model not implemented\n");
1395
cpu_abort(env, "Unknown or invalid MMU model\n");
854
ctx->prot |= PAGE_WRITE;
1402
860
int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr,
1403
int rw, int access_type)
861
int rw, int access_type, int check_BATs)
1408
865
if (loglevel != 0) {
1409
866
fprintf(logfile, "%s\n", __func__);
1561
1013
/* Access rights violation */
1562
env->exception_index = POWERPC_EXCP_ISI;
1563
env->error_code = 0x08000000;
1014
error_code = 0x08000000;
1566
1017
/* No execute protection violation */
1567
env->exception_index = POWERPC_EXCP_ISI;
1568
env->error_code = 0x10000000;
1018
error_code = 0x10000000;
1571
1021
/* Direct store exception */
1572
1022
/* No code fetch is allowed in direct-store areas */
1573
env->exception_index = POWERPC_EXCP_ISI;
1574
env->error_code = 0x10000000;
1023
error_code = 0x10000000;
1576
#if defined(TARGET_PPC64)
1578
1026
/* No match in segment table */
1579
if (env->mmu_model == POWERPC_MMU_620) {
1580
env->exception_index = POWERPC_EXCP_ISI;
1581
/* XXX: this might be incorrect */
1582
env->error_code = 0x40000000;
1584
env->exception_index = POWERPC_EXCP_ISEG;
1585
env->error_code = 0;
1027
exception = EXCP_ISEG;
1032
exception = EXCP_DSI;
1593
1035
/* No matches in page tables or TLB */
1594
switch (env->mmu_model) {
1595
case POWERPC_MMU_SOFT_6xx:
1036
switch (PPC_MMU(env)) {
1037
case PPC_FLAGS_MMU_SOFT_6xx:
1597
env->exception_index = POWERPC_EXCP_DSTLB;
1598
env->error_code = 1 << 16;
1039
exception = EXCP_DS_TLBMISS;
1040
error_code = 1 << 16;
1600
env->exception_index = POWERPC_EXCP_DLTLB;
1601
env->error_code = 0;
1042
exception = EXCP_DL_TLBMISS;
1603
1045
env->spr[SPR_DMISS] = address;
1604
1046
env->spr[SPR_DCMP] = 0x80000000 | ctx.ptem;
1606
env->error_code |= ctx.key << 19;
1048
error_code |= ctx.key << 19;
1607
1049
env->spr[SPR_HASH1] = ctx.pg_addr[0];
1608
1050
env->spr[SPR_HASH2] = ctx.pg_addr[1];
1610
case POWERPC_MMU_SOFT_74xx:
1612
env->exception_index = POWERPC_EXCP_DSTLB;
1614
env->exception_index = POWERPC_EXCP_DLTLB;
1617
/* Implement LRU algorithm */
1618
env->error_code = ctx.key << 19;
1619
env->spr[SPR_TLBMISS] = (address & ~((target_ulong)0x3)) |
1620
((env->last_way + 1) & (env->nb_ways - 1));
1621
env->spr[SPR_PTEHI] = 0x80000000 | ctx.ptem;
1623
case POWERPC_MMU_SOFT_4xx:
1624
case POWERPC_MMU_SOFT_4xx_Z:
1625
env->exception_index = POWERPC_EXCP_DTLB;
1626
env->error_code = 0;
1051
/* Do not alter DAR nor DSISR */
1053
case PPC_FLAGS_MMU_SOFT_4xx:
1054
case PPC_FLAGS_MMU_403:
1055
exception = EXCP_40x_DTLBMISS;
1627
1057
env->spr[SPR_40x_DEAR] = address;
1629
1059
env->spr[SPR_40x_ESR] = 0x00800000;
1631
1061
env->spr[SPR_40x_ESR] = 0x00000000;
1633
case POWERPC_MMU_32B:
1634
case POWERPC_MMU_601:
1063
case PPC_FLAGS_MMU_32B:
1064
error_code = 0x40000000;
1635
1066
#if defined(TARGET_PPC64)
1636
case POWERPC_MMU_620:
1637
case POWERPC_MMU_64B:
1067
case PPC_FLAGS_MMU_64B:
1069
cpu_abort(env, "MMU model not implemented\n");
1071
case PPC_FLAGS_MMU_64BRIDGE:
1073
cpu_abort(env, "MMU model not implemented\n");
1639
env->exception_index = POWERPC_EXCP_DSI;
1640
env->error_code = 0;
1641
env->spr[SPR_DAR] = address;
1643
env->spr[SPR_DSISR] = 0x42000000;
1645
env->spr[SPR_DSISR] = 0x40000000;
1647
case POWERPC_MMU_MPC8xx:
1649
cpu_abort(env, "MPC8xx MMU model is not implemented\n");
1651
case POWERPC_MMU_BOOKE:
1653
cpu_abort(env, "BookE MMU model is not implemented\n");
1655
case POWERPC_MMU_BOOKE_FSL:
1657
cpu_abort(env, "BookE FSL MMU model is not implemented\n");
1659
case POWERPC_MMU_REAL:
1660
cpu_abort(env, "PowerPC in real mode should never raise "
1661
"any MMU exceptions\n");
1076
case PPC_FLAGS_MMU_601:
1078
cpu_abort(env, "MMU model not implemented\n");
1080
case PPC_FLAGS_MMU_BOOKE:
1082
cpu_abort(env, "MMU model not implemented\n");
1084
case PPC_FLAGS_MMU_BOOKE_FSL:
1086
cpu_abort(env, "MMU model not implemented\n");
1664
1089
cpu_abort(env, "Unknown or invalid MMU model\n");
1865
1262
env->DBAT[1][nr] = value;
1868
void do_store_ibatu_601 (CPUPPCState *env, int nr, target_ulong value)
1873
dump_store_bat(env, 'I', 0, nr, value);
1874
if (env->IBAT[0][nr] != value) {
1876
mask = (env->IBAT[1][nr] << 17) & 0x0FFE0000UL;
1877
if (env->IBAT[1][nr] & 0x40) {
1878
/* Invalidate BAT only if it is valid */
1879
#if !defined(FLUSH_ALL_TLBS)
1880
do_invalidate_BAT(env, env->IBAT[0][nr], mask);
1885
/* When storing valid upper BAT, mask BEPI and BRPN
1886
* and invalidate all TLBs covered by this BAT
1888
env->IBAT[0][nr] = (value & 0x00001FFFUL) |
1889
(value & ~0x0001FFFFUL & ~mask);
1890
env->DBAT[0][nr] = env->IBAT[0][nr];
1891
if (env->IBAT[1][nr] & 0x40) {
1892
#if !defined(FLUSH_ALL_TLBS)
1893
do_invalidate_BAT(env, env->IBAT[0][nr], mask);
1898
#if defined(FLUSH_ALL_TLBS)
1905
void do_store_ibatl_601 (CPUPPCState *env, int nr, target_ulong value)
1910
dump_store_bat(env, 'I', 1, nr, value);
1911
if (env->IBAT[1][nr] != value) {
1913
if (env->IBAT[1][nr] & 0x40) {
1914
#if !defined(FLUSH_ALL_TLBS)
1915
mask = (env->IBAT[1][nr] << 17) & 0x0FFE0000UL;
1916
do_invalidate_BAT(env, env->IBAT[0][nr], mask);
1922
#if !defined(FLUSH_ALL_TLBS)
1923
mask = (value << 17) & 0x0FFE0000UL;
1924
do_invalidate_BAT(env, env->IBAT[0][nr], mask);
1929
env->IBAT[1][nr] = value;
1930
env->DBAT[1][nr] = value;
1931
#if defined(FLUSH_ALL_TLBS)
1938
1266
/*****************************************************************************/
1939
1267
/* TLB management */
1940
1268
void ppc_tlb_invalidate_all (CPUPPCState *env)
1942
switch (env->mmu_model) {
1943
case POWERPC_MMU_SOFT_6xx:
1944
case POWERPC_MMU_SOFT_74xx:
1270
if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_6xx)) {
1945
1271
ppc6xx_tlb_invalidate_all(env);
1947
case POWERPC_MMU_SOFT_4xx:
1948
case POWERPC_MMU_SOFT_4xx_Z:
1272
} else if (unlikely(PPC_MMU(env) == PPC_FLAGS_MMU_SOFT_4xx)) {
1949
1273
ppc4xx_tlb_invalidate_all(env);
1951
case POWERPC_MMU_REAL:
1952
cpu_abort(env, "No TLB for PowerPC 4xx in real mode\n");
1954
case POWERPC_MMU_MPC8xx:
1956
cpu_abort(env, "MPC8xx MMU model is not implemented\n");
1958
case POWERPC_MMU_BOOKE:
1960
cpu_abort(env, "BookE MMU model is not implemented\n");
1962
case POWERPC_MMU_BOOKE_FSL:
1964
cpu_abort(env, "BookE MMU model is not implemented\n");
1966
case POWERPC_MMU_32B:
1967
case POWERPC_MMU_601:
1968
#if defined(TARGET_PPC64)
1969
case POWERPC_MMU_620:
1970
case POWERPC_MMU_64B:
1971
#endif /* defined(TARGET_PPC64) */
1976
cpu_abort(env, "Unknown MMU model\n");
1981
void ppc_tlb_invalidate_one (CPUPPCState *env, target_ulong addr)
1983
#if !defined(FLUSH_ALL_TLBS)
1984
addr &= TARGET_PAGE_MASK;
1985
switch (env->mmu_model) {
1986
case POWERPC_MMU_SOFT_6xx:
1987
case POWERPC_MMU_SOFT_74xx:
1988
ppc6xx_tlb_invalidate_virt(env, addr, 0);
1989
if (env->id_tlbs == 1)
1990
ppc6xx_tlb_invalidate_virt(env, addr, 1);
1992
case POWERPC_MMU_SOFT_4xx:
1993
case POWERPC_MMU_SOFT_4xx_Z:
1994
ppc4xx_tlb_invalidate_virt(env, addr, env->spr[SPR_40x_PID]);
1996
case POWERPC_MMU_REAL:
1997
cpu_abort(env, "No TLB for PowerPC 4xx in real mode\n");
1999
case POWERPC_MMU_MPC8xx:
2001
cpu_abort(env, "MPC8xx MMU model is not implemented\n");
2003
case POWERPC_MMU_BOOKE:
2005
cpu_abort(env, "BookE MMU model is not implemented\n");
2007
case POWERPC_MMU_BOOKE_FSL:
2009
cpu_abort(env, "BookE FSL MMU model is not implemented\n");
2011
case POWERPC_MMU_32B:
2012
case POWERPC_MMU_601:
2013
/* tlbie invalidate TLBs for all segments */
2014
addr &= ~((target_ulong)-1ULL << 28);
2015
/* XXX: this case should be optimized,
2016
* giving a mask to tlb_flush_page
2018
tlb_flush_page(env, addr | (0x0 << 28));
2019
tlb_flush_page(env, addr | (0x1 << 28));
2020
tlb_flush_page(env, addr | (0x2 << 28));
2021
tlb_flush_page(env, addr | (0x3 << 28));
2022
tlb_flush_page(env, addr | (0x4 << 28));
2023
tlb_flush_page(env, addr | (0x5 << 28));
2024
tlb_flush_page(env, addr | (0x6 << 28));
2025
tlb_flush_page(env, addr | (0x7 << 28));
2026
tlb_flush_page(env, addr | (0x8 << 28));
2027
tlb_flush_page(env, addr | (0x9 << 28));
2028
tlb_flush_page(env, addr | (0xA << 28));
2029
tlb_flush_page(env, addr | (0xB << 28));
2030
tlb_flush_page(env, addr | (0xC << 28));
2031
tlb_flush_page(env, addr | (0xD << 28));
2032
tlb_flush_page(env, addr | (0xE << 28));
2033
tlb_flush_page(env, addr | (0xF << 28));
2035
#if defined(TARGET_PPC64)
2036
case POWERPC_MMU_620:
2037
case POWERPC_MMU_64B:
2038
/* tlbie invalidate TLBs for all segments */
2039
/* XXX: given the fact that there are too many segments to invalidate,
2040
* and we still don't have a tlb_flush_mask(env, n, mask) in Qemu,
2041
* we just invalidate all TLBs
2045
#endif /* defined(TARGET_PPC64) */
2048
cpu_abort(env, "Unknown MMU model\n");
2052
ppc_tlb_invalidate_all(env);
2056
1279
/*****************************************************************************/
2125
1343
#endif /* !defined (CONFIG_USER_ONLY) */
1345
uint32_t ppc_load_xer (CPUPPCState *env)
1347
return (xer_so << XER_SO) |
1348
(xer_ov << XER_OV) |
1349
(xer_ca << XER_CA) |
1350
(xer_bc << XER_BC) |
1351
(xer_cmp << XER_CMP);
1354
void ppc_store_xer (CPUPPCState *env, uint32_t value)
1356
xer_so = (value >> XER_SO) & 0x01;
1357
xer_ov = (value >> XER_OV) & 0x01;
1358
xer_ca = (value >> XER_CA) & 0x01;
1359
xer_cmp = (value >> XER_CMP) & 0xFF;
1360
xer_bc = (value >> XER_BC) & 0x7F;
1363
/* Swap temporary saved registers with GPRs */
1364
static inline void swap_gpr_tgpr (CPUPPCState *env)
1369
env->gpr[0] = env->tgpr[0];
1372
env->gpr[1] = env->tgpr[1];
1375
env->gpr[2] = env->tgpr[2];
1378
env->gpr[3] = env->tgpr[3];
2127
1382
/* GDBstub can read and write MSR... */
2128
void ppc_store_msr (CPUPPCState *env, target_ulong value)
2130
hreg_store_msr(env, value, 0);
1383
target_ulong do_load_msr (CPUPPCState *env)
1386
#if defined (TARGET_PPC64)
1387
((target_ulong)msr_sf << MSR_SF) |
1388
((target_ulong)msr_isf << MSR_ISF) |
1389
((target_ulong)msr_hv << MSR_HV) |
1391
((target_ulong)msr_ucle << MSR_UCLE) |
1392
((target_ulong)msr_vr << MSR_VR) | /* VR / SPE */
1393
((target_ulong)msr_ap << MSR_AP) |
1394
((target_ulong)msr_sa << MSR_SA) |
1395
((target_ulong)msr_key << MSR_KEY) |
1396
((target_ulong)msr_pow << MSR_POW) | /* POW / WE */
1397
((target_ulong)msr_tlb << MSR_TLB) | /* TLB / TGPE / CE */
1398
((target_ulong)msr_ile << MSR_ILE) |
1399
((target_ulong)msr_ee << MSR_EE) |
1400
((target_ulong)msr_pr << MSR_PR) |
1401
((target_ulong)msr_fp << MSR_FP) |
1402
((target_ulong)msr_me << MSR_ME) |
1403
((target_ulong)msr_fe0 << MSR_FE0) |
1404
((target_ulong)msr_se << MSR_SE) | /* SE / DWE / UBLE */
1405
((target_ulong)msr_be << MSR_BE) | /* BE / DE */
1406
((target_ulong)msr_fe1 << MSR_FE1) |
1407
((target_ulong)msr_al << MSR_AL) |
1408
((target_ulong)msr_ip << MSR_IP) |
1409
((target_ulong)msr_ir << MSR_IR) | /* IR / IS */
1410
((target_ulong)msr_dr << MSR_DR) | /* DR / DS */
1411
((target_ulong)msr_pe << MSR_PE) | /* PE / EP */
1412
((target_ulong)msr_px << MSR_PX) | /* PX / PMM */
1413
((target_ulong)msr_ri << MSR_RI) |
1414
((target_ulong)msr_le << MSR_LE);
1417
void do_store_msr (CPUPPCState *env, target_ulong value)
1421
value &= env->msr_mask;
1422
if (((value >> MSR_IR) & 1) != msr_ir ||
1423
((value >> MSR_DR) & 1) != msr_dr) {
1424
/* Flush all tlb when changing translation mode */
1426
env->interrupt_request |= CPU_INTERRUPT_EXITTB;
1429
if (loglevel != 0) {
1430
fprintf(logfile, "%s: T0 %08lx\n", __func__, value);
1433
switch (PPC_EXCP(env)) {
1434
case PPC_FLAGS_EXCP_602:
1435
case PPC_FLAGS_EXCP_603:
1436
if (((value >> MSR_TGPR) & 1) != msr_tgpr) {
1437
/* Swap temporary saved registers with GPRs */
1444
#if defined (TARGET_PPC64)
1445
msr_sf = (value >> MSR_SF) & 1;
1446
msr_isf = (value >> MSR_ISF) & 1;
1447
msr_hv = (value >> MSR_HV) & 1;
1449
msr_ucle = (value >> MSR_UCLE) & 1;
1450
msr_vr = (value >> MSR_VR) & 1; /* VR / SPE */
1451
msr_ap = (value >> MSR_AP) & 1;
1452
msr_sa = (value >> MSR_SA) & 1;
1453
msr_key = (value >> MSR_KEY) & 1;
1454
msr_pow = (value >> MSR_POW) & 1; /* POW / WE */
1455
msr_tlb = (value >> MSR_TLB) & 1; /* TLB / TGPR / CE */
1456
msr_ile = (value >> MSR_ILE) & 1;
1457
msr_ee = (value >> MSR_EE) & 1;
1458
msr_pr = (value >> MSR_PR) & 1;
1459
msr_fp = (value >> MSR_FP) & 1;
1460
msr_me = (value >> MSR_ME) & 1;
1461
msr_fe0 = (value >> MSR_FE0) & 1;
1462
msr_se = (value >> MSR_SE) & 1; /* SE / DWE / UBLE */
1463
msr_be = (value >> MSR_BE) & 1; /* BE / DE */
1464
msr_fe1 = (value >> MSR_FE1) & 1;
1465
msr_al = (value >> MSR_AL) & 1;
1466
msr_ip = (value >> MSR_IP) & 1;
1467
msr_ir = (value >> MSR_IR) & 1; /* IR / IS */
1468
msr_dr = (value >> MSR_DR) & 1; /* DR / DS */
1469
msr_pe = (value >> MSR_PE) & 1; /* PE / EP */
1470
msr_px = (value >> MSR_PX) & 1; /* PX / PMM */
1471
msr_ri = (value >> MSR_RI) & 1;
1472
msr_le = (value >> MSR_LE) & 1;
1473
do_compute_hflags(env);
1476
switch (PPC_EXCP(env)) {
1477
case PPC_FLAGS_EXCP_603:
1478
/* Don't handle SLEEP mode: we should disable all clocks...
1479
* No dynamic power-management.
1481
if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00C00000) != 0)
1484
case PPC_FLAGS_EXCP_604:
1488
case PPC_FLAGS_EXCP_7x0:
1489
if (msr_pow == 1 && (env->spr[SPR_HID0] & 0x00E00000) != 0)
1496
/* power save: exit cpu loop */
1498
env->exception_index = EXCP_HLT;
1503
#if defined(TARGET_PPC64)
1504
void ppc_store_msr_32 (CPUPPCState *env, uint32_t value)
1507
(do_load_msr(env) & ~0xFFFFFFFFULL) | (value & 0xFFFFFFFF));
1511
void do_compute_hflags (CPUPPCState *env)
1513
/* Compute current hflags */
1514
env->hflags = (msr_cm << MSR_CM) | (msr_vr << MSR_VR) |
1515
(msr_ap << MSR_AP) | (msr_sa << MSR_SA) | (msr_pr << MSR_PR) |
1516
(msr_fp << MSR_FP) | (msr_fe0 << MSR_FE0) | (msr_se << MSR_SE) |
1517
(msr_be << MSR_BE) | (msr_fe1 << MSR_FE1) | (msr_le << MSR_LE);
1518
#if defined (TARGET_PPC64)
1519
/* No care here: PowerPC 64 MSR_SF means the same as MSR_CM for BookE */
1520
env->hflags |= (msr_sf << (MSR_SF - 32)) | (msr_hv << (MSR_HV - 32));
2133
1524
/*****************************************************************************/
2135
1526
#if defined (CONFIG_USER_ONLY)
2136
1527
void do_interrupt (CPUState *env)
2138
env->exception_index = POWERPC_EXCP_NONE;
2139
env->error_code = 0;
1529
env->exception_index = -1;
2142
1532
void ppc_hw_interrupt (CPUState *env)
2144
env->exception_index = POWERPC_EXCP_NONE;
2145
env->error_code = 0;
1534
env->exception_index = -1;
2147
1536
#else /* defined (CONFIG_USER_ONLY) */
2148
static always_inline void dump_syscall (CPUState *env)
1537
static void dump_syscall(CPUState *env)
2150
fprintf(logfile, "syscall r0=" REGX " r3=" REGX " r4=" REGX
2151
" r5=" REGX " r6=" REGX " nip=" ADDRX "\n",
2152
ppc_dump_gpr(env, 0), ppc_dump_gpr(env, 3), ppc_dump_gpr(env, 4),
2153
ppc_dump_gpr(env, 5), ppc_dump_gpr(env, 6), env->nip);
1539
fprintf(logfile, "syscall r0=0x" REGX " r3=0x" REGX " r4=0x" REGX
1540
" r5=0x" REGX " r6=0x" REGX " nip=0x" ADDRX "\n",
1541
env->gpr[0], env->gpr[3], env->gpr[4],
1542
env->gpr[5], env->gpr[6], env->nip);
2156
/* Note that this function should be greatly optimized
2157
* when called with a constant excp, from ppc_hw_interrupt
2159
static always_inline void powerpc_excp (CPUState *env,
2160
int excp_model, int excp)
1545
void do_interrupt (CPUState *env)
2162
target_ulong msr, new_msr, vector;
2163
int srr0, srr1, asrr0, asrr1;
2164
int lpes0, lpes1, lev;
1547
target_ulong msr, *srr_0, *srr_1, *asrr_0, *asrr_1;
2167
/* XXX: find a suitable condition to enable the hypervisor mode */
2168
lpes0 = (env->spr[SPR_LPCR] >> 1) & 1;
2169
lpes1 = (env->spr[SPR_LPCR] >> 2) & 1;
2171
/* Those values ensure we won't enter the hypervisor mode */
1550
excp = env->exception_index;
1551
msr = do_load_msr(env);
1552
/* The default is to use SRR0 & SRR1 to save the exception context */
1553
srr_0 = &env->spr[SPR_SRR0];
1554
srr_1 = &env->spr[SPR_SRR1];
1557
#if defined (DEBUG_EXCEPTIONS)
1558
if ((excp == EXCP_PROGRAM || excp == EXCP_DSI) && msr_pr == 1) {
1559
if (loglevel != 0) {
1561
"Raise exception at 0x" ADDRX " => 0x%08x (%02x)\n",
1562
env->nip, excp, env->error_code);
1563
cpu_dump_state(env, logfile, fprintf, 0);
2176
1567
if (loglevel & CPU_LOG_INT) {
2177
fprintf(logfile, "Raise exception at " ADDRX " => %08x (%02x)\n",
1568
fprintf(logfile, "Raise exception at 0x" ADDRX " => 0x%08x (%02x)\n",
2178
1569
env->nip, excp, env->error_code);
2186
msr &= ~((target_ulong)0x783F0000);
1573
/* Generate informations in save/restore registers */
2187
1574
switch (excp) {
2188
case POWERPC_EXCP_NONE:
2189
/* Should never happen */
2191
case POWERPC_EXCP_CRITICAL: /* Critical input */
2192
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2193
switch (excp_model) {
2194
case POWERPC_EXCP_40x:
2195
srr0 = SPR_40x_SRR2;
2196
srr1 = SPR_40x_SRR3;
2198
case POWERPC_EXCP_BOOKE:
2199
srr0 = SPR_BOOKE_CSRR0;
2200
srr1 = SPR_BOOKE_CSRR1;
2202
case POWERPC_EXCP_G2:
2208
case POWERPC_EXCP_MCHECK: /* Machine check exception */
2210
/* Machine check exception is not enabled.
2211
* Enter checkstop state.
2213
if (loglevel != 0) {
2214
fprintf(logfile, "Machine check while not allowed. "
2215
"Entering checkstop state\n");
2217
fprintf(stderr, "Machine check while not allowed. "
2218
"Entering checkstop state\n");
2221
env->interrupt_request |= CPU_INTERRUPT_EXITTB;
2223
new_msr &= ~((target_ulong)1 << MSR_RI);
2224
new_msr &= ~((target_ulong)1 << MSR_ME);
2226
/* XXX: find a suitable condition to enable the hypervisor mode */
2227
new_msr |= (target_ulong)MSR_HVB;
2229
/* XXX: should also have something loaded in DAR / DSISR */
2230
switch (excp_model) {
2231
case POWERPC_EXCP_40x:
2232
srr0 = SPR_40x_SRR2;
2233
srr1 = SPR_40x_SRR3;
2235
case POWERPC_EXCP_BOOKE:
2236
srr0 = SPR_BOOKE_MCSRR0;
2237
srr1 = SPR_BOOKE_MCSRR1;
2238
asrr0 = SPR_BOOKE_CSRR0;
2239
asrr1 = SPR_BOOKE_CSRR1;
2245
case POWERPC_EXCP_DSI: /* Data storage exception */
2246
#if defined (DEBUG_EXCEPTIONS)
2247
if (loglevel != 0) {
2248
fprintf(logfile, "DSI exception: DSISR=" ADDRX" DAR=" ADDRX "\n",
2249
env->spr[SPR_DSISR], env->spr[SPR_DAR]);
2252
new_msr &= ~((target_ulong)1 << MSR_RI);
2254
new_msr |= (target_ulong)MSR_HVB;
2256
case POWERPC_EXCP_ISI: /* Instruction storage exception */
2257
#if defined (DEBUG_EXCEPTIONS)
2258
if (loglevel != 0) {
2259
fprintf(logfile, "ISI exception: msr=" ADDRX ", nip=" ADDRX "\n",
2263
new_msr &= ~((target_ulong)1 << MSR_RI);
2265
new_msr |= (target_ulong)MSR_HVB;
1575
/* Generic PowerPC exceptions */
1576
case EXCP_RESET: /* 0x0100 */
1577
switch (PPC_EXCP(env)) {
1578
case PPC_FLAGS_EXCP_40x:
1579
srr_0 = &env->spr[SPR_40x_SRR2];
1580
srr_1 = &env->spr[SPR_40x_SRR3];
1582
case PPC_FLAGS_EXCP_BOOKE:
1584
srr_0 = &env->spr[SPR_BOOKE_CSRR0];
1585
srr_1 = &env->spr[SPR_BOOKE_CSRR1];
1594
case EXCP_MACHINE_CHECK: /* 0x0200 */
1595
switch (PPC_EXCP(env)) {
1596
case PPC_FLAGS_EXCP_40x:
1597
srr_0 = &env->spr[SPR_40x_SRR2];
1598
srr_1 = &env->spr[SPR_40x_SRR3];
1600
case PPC_FLAGS_EXCP_BOOKE:
1602
srr_0 = &env->spr[SPR_BOOKE_MCSRR0];
1603
srr_1 = &env->spr[SPR_BOOKE_MCSRR1];
1604
asrr_0 = &env->spr[SPR_BOOKE_CSRR0];
1605
asrr_1 = &env->spr[SPR_BOOKE_CSRR1];
1613
case EXCP_DSI: /* 0x0300 */
1614
/* Store exception cause */
1615
/* data location address has been stored
1616
* when the fault has been detected
1620
#if defined (DEBUG_EXCEPTIONS)
1621
if (loglevel != 0) {
1622
fprintf(logfile, "DSI exception: DSISR=0x" ADDRX" DAR=0x" ADDRX
1623
"\n", env->spr[SPR_DSISR], env->spr[SPR_DAR]);
1627
case EXCP_ISI: /* 0x0400 */
1628
/* Store exception cause */
2266
1631
msr |= env->error_code;
2268
case POWERPC_EXCP_EXTERNAL: /* External input */
2269
new_msr &= ~((target_ulong)1 << MSR_RI);
2271
new_msr |= (target_ulong)MSR_HVB;
2273
case POWERPC_EXCP_ALIGN: /* Alignment exception */
2274
new_msr &= ~((target_ulong)1 << MSR_RI);
2276
new_msr |= (target_ulong)MSR_HVB;
2277
/* XXX: this is false */
2278
/* Get rS/rD and rA from faulting opcode */
2279
env->spr[SPR_DSISR] |= (ldl_code((env->nip - 4)) & 0x03FF0000) >> 16;
1632
#if defined (DEBUG_EXCEPTIONS)
1633
if (loglevel != 0) {
1634
fprintf(logfile, "ISI exception: msr=0x" ADDRX ", nip=0x" ADDRX
1635
"\n", msr, env->nip);
1639
case EXCP_EXTERNAL: /* 0x0500 */
1642
case EXCP_ALIGN: /* 0x0600 */
1643
if (likely(PPC_EXCP(env) != PPC_FLAGS_EXCP_601)) {
1644
/* Store exception cause */
1646
/* Get rS/rD and rA from faulting opcode */
1647
env->spr[SPR_DSISR] |=
1648
(ldl_code((env->nip - 4)) & 0x03FF0000) >> 16;
1649
/* data location address has been stored
1650
* when the fault has been detected
1653
/* IO error exception on PowerPC 601 */
1656
"601 IO error exception is not implemented yet !\n");
2280
1658
goto store_current;
2281
case POWERPC_EXCP_PROGRAM: /* Program exception */
1659
case EXCP_PROGRAM: /* 0x0700 */
2282
1662
switch (env->error_code & ~0xF) {
2283
case POWERPC_EXCP_FP:
2284
if ((msr_fe0 == 0 && msr_fe1 == 0) || msr_fp == 0) {
1664
if (msr_fe0 == 0 && msr_fe1 == 0) {
2285
1665
#if defined (DEBUG_EXCEPTIONS)
2286
1666
if (loglevel != 0) {
2287
1667
fprintf(logfile, "Ignore floating point exception\n");
2290
env->exception_index = POWERPC_EXCP_NONE;
2291
env->error_code = 0;
2294
new_msr &= ~((target_ulong)1 << MSR_RI);
2296
new_msr |= (target_ulong)MSR_HVB;
2297
1672
msr |= 0x00100000;
2298
if (msr_fe0 == msr_fe1)
1674
env->fpscr[7] |= 0x8;
1675
/* Finally, update FEX */
1676
if ((((env->fpscr[7] & 0x3) << 3) | (env->fpscr[6] >> 1)) &
1677
((env->fpscr[1] << 1) | (env->fpscr[0] >> 3)))
1678
env->fpscr[7] |= 0x4;
2302
case POWERPC_EXCP_INVAL:
2303
1681
#if defined (DEBUG_EXCEPTIONS)
2304
1682
if (loglevel != 0) {
2305
fprintf(logfile, "Invalid instruction at " ADDRX "\n",
1683
fprintf(logfile, "Invalid instruction at 0x" ADDRX "\n",
2309
new_msr &= ~((target_ulong)1 << MSR_RI);
2311
new_msr |= (target_ulong)MSR_HVB;
2312
1687
msr |= 0x00080000;
2314
case POWERPC_EXCP_PRIV:
2315
new_msr &= ~((target_ulong)1 << MSR_RI);
2317
new_msr |= (target_ulong)MSR_HVB;
2318
1690
msr |= 0x00040000;
2320
case POWERPC_EXCP_TRAP:
2321
new_msr &= ~((target_ulong)1 << MSR_RI);
2323
new_msr |= (target_ulong)MSR_HVB;
2324
1694
msr |= 0x00020000;
2327
1697
/* Should never occur */
2328
cpu_abort(env, "Invalid program exception %d. Aborting\n",
2333
case POWERPC_EXCP_FPU: /* Floating-point unavailable exception */
2334
new_msr &= ~((target_ulong)1 << MSR_RI);
2336
new_msr |= (target_ulong)MSR_HVB;
2338
case POWERPC_EXCP_SYSCALL: /* System call exception */
1702
case EXCP_NO_FP: /* 0x0800 */
1708
case EXCP_SYSCALL: /* 0x0C00 */
2339
1710
/* NOTE: this is a temporary hack to support graphics OSI
2340
1711
calls from the MOL driver */
2341
/* XXX: To be removed */
2342
1712
if (env->gpr[3] == 0x113724fa && env->gpr[4] == 0x77810f9b &&
2343
1713
env->osi_call) {
2344
if (env->osi_call(env) != 0) {
2345
env->exception_index = POWERPC_EXCP_NONE;
2346
env->error_code = 0;
1714
if (env->osi_call(env) != 0)
2350
1717
if (loglevel & CPU_LOG_INT) {
2351
1718
dump_syscall(env);
2353
new_msr &= ~((target_ulong)1 << MSR_RI);
2354
lev = env->error_code;
2355
if (lev == 1 || (lpes0 == 0 && lpes1 == 0))
2356
new_msr |= (target_ulong)MSR_HVB;
2358
case POWERPC_EXCP_APU: /* Auxiliary processor unavailable */
2359
new_msr &= ~((target_ulong)1 << MSR_RI);
2361
case POWERPC_EXCP_DECR: /* Decrementer exception */
2362
new_msr &= ~((target_ulong)1 << MSR_RI);
2364
new_msr |= (target_ulong)MSR_HVB;
2366
case POWERPC_EXCP_FIT: /* Fixed-interval timer interrupt */
2368
#if defined (DEBUG_EXCEPTIONS)
2370
fprintf(logfile, "FIT exception\n");
2372
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2374
case POWERPC_EXCP_WDT: /* Watchdog timer interrupt */
2375
#if defined (DEBUG_EXCEPTIONS)
2377
fprintf(logfile, "WDT exception\n");
2379
switch (excp_model) {
2380
case POWERPC_EXCP_BOOKE:
2381
srr0 = SPR_BOOKE_CSRR0;
2382
srr1 = SPR_BOOKE_CSRR1;
2387
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2389
case POWERPC_EXCP_DTLB: /* Data TLB error */
2390
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2392
case POWERPC_EXCP_ITLB: /* Instruction TLB error */
2393
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2395
case POWERPC_EXCP_DEBUG: /* Debug interrupt */
2396
switch (excp_model) {
2397
case POWERPC_EXCP_BOOKE:
2398
srr0 = SPR_BOOKE_DSRR0;
2399
srr1 = SPR_BOOKE_DSRR1;
2400
asrr0 = SPR_BOOKE_CSRR0;
2401
asrr1 = SPR_BOOKE_CSRR1;
2407
cpu_abort(env, "Debug exception is not implemented yet !\n");
2409
case POWERPC_EXCP_SPEU: /* SPE/embedded floating-point unavailable */
2410
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2412
case POWERPC_EXCP_EFPDI: /* Embedded floating-point data interrupt */
2414
cpu_abort(env, "Embedded floating point data exception "
2415
"is not implemented yet !\n");
2417
case POWERPC_EXCP_EFPRI: /* Embedded floating-point round interrupt */
2419
cpu_abort(env, "Embedded floating point round exception "
2420
"is not implemented yet !\n");
2422
case POWERPC_EXCP_EPERFM: /* Embedded performance monitor interrupt */
2423
new_msr &= ~((target_ulong)1 << MSR_RI);
1721
case EXCP_TRACE: /* 0x0D00 */
1723
case EXCP_PERF: /* 0x0F00 */
2424
1724
/* XXX: TODO */
2426
1726
"Performance counter exception is not implemented yet !\n");
2427
1727
goto store_next;
2428
case POWERPC_EXCP_DOORI: /* Embedded doorbell interrupt */
1728
/* 32 bits PowerPC specific exceptions */
1729
case EXCP_FP_ASSIST: /* 0x0E00 */
1731
cpu_abort(env, "Floating point assist exception "
1732
"is not implemented yet !\n");
1734
/* 64 bits PowerPC exceptions */
1735
case EXCP_DSEG: /* 0x0380 */
1737
cpu_abort(env, "Data segment exception is not implemented yet !\n");
1739
case EXCP_ISEG: /* 0x0480 */
2429
1740
/* XXX: TODO */
2431
"Embedded doorbell interrupt is not implemented yet !\n");
2433
case POWERPC_EXCP_DOORCI: /* Embedded doorbell critical interrupt */
2434
switch (excp_model) {
2435
case POWERPC_EXCP_BOOKE:
2436
srr0 = SPR_BOOKE_CSRR0;
2437
srr1 = SPR_BOOKE_CSRR1;
2443
cpu_abort(env, "Embedded doorbell critical interrupt "
2444
"is not implemented yet !\n");
2446
case POWERPC_EXCP_RESET: /* System reset exception */
2447
new_msr &= ~((target_ulong)1 << MSR_RI);
2449
/* XXX: find a suitable condition to enable the hypervisor mode */
2450
new_msr |= (target_ulong)MSR_HVB;
2453
case POWERPC_EXCP_DSEG: /* Data segment exception */
2454
new_msr &= ~((target_ulong)1 << MSR_RI);
2456
new_msr |= (target_ulong)MSR_HVB;
2458
case POWERPC_EXCP_ISEG: /* Instruction segment exception */
2459
new_msr &= ~((target_ulong)1 << MSR_RI);
2461
new_msr |= (target_ulong)MSR_HVB;
2463
case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception */
2466
new_msr |= (target_ulong)MSR_HVB;
2468
case POWERPC_EXCP_TRACE: /* Trace exception */
2469
new_msr &= ~((target_ulong)1 << MSR_RI);
2471
new_msr |= (target_ulong)MSR_HVB;
2473
case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception */
2476
new_msr |= (target_ulong)MSR_HVB;
2478
case POWERPC_EXCP_HISI: /* Hypervisor instruction storage exception */
2481
new_msr |= (target_ulong)MSR_HVB;
2483
case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception */
2486
new_msr |= (target_ulong)MSR_HVB;
2488
case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment exception */
2491
new_msr |= (target_ulong)MSR_HVB;
2493
case POWERPC_EXCP_VPU: /* Vector unavailable exception */
2494
new_msr &= ~((target_ulong)1 << MSR_RI);
2496
new_msr |= (target_ulong)MSR_HVB;
2498
case POWERPC_EXCP_PIT: /* Programmable interval timer interrupt */
2499
#if defined (DEBUG_EXCEPTIONS)
2501
fprintf(logfile, "PIT exception\n");
2503
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2505
case POWERPC_EXCP_IO: /* IO error exception */
2507
cpu_abort(env, "601 IO error exception is not implemented yet !\n");
2509
case POWERPC_EXCP_RUNM: /* Run mode exception */
2511
cpu_abort(env, "601 run mode exception is not implemented yet !\n");
2513
case POWERPC_EXCP_EMUL: /* Emulation trap exception */
2515
cpu_abort(env, "602 emulation trap exception "
2516
"is not implemented yet !\n");
2518
case POWERPC_EXCP_IFTLB: /* Instruction fetch TLB error */
2519
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2520
if (lpes1 == 0) /* XXX: check this */
2521
new_msr |= (target_ulong)MSR_HVB;
2522
switch (excp_model) {
2523
case POWERPC_EXCP_602:
2524
case POWERPC_EXCP_603:
2525
case POWERPC_EXCP_603E:
2526
case POWERPC_EXCP_G2:
2528
case POWERPC_EXCP_7x5:
2530
case POWERPC_EXCP_74xx:
2533
cpu_abort(env, "Invalid instruction TLB miss exception\n");
2537
case POWERPC_EXCP_DLTLB: /* Data load TLB miss */
2538
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2539
if (lpes1 == 0) /* XXX: check this */
2540
new_msr |= (target_ulong)MSR_HVB;
2541
switch (excp_model) {
2542
case POWERPC_EXCP_602:
2543
case POWERPC_EXCP_603:
2544
case POWERPC_EXCP_603E:
2545
case POWERPC_EXCP_G2:
2547
case POWERPC_EXCP_7x5:
2549
case POWERPC_EXCP_74xx:
2552
cpu_abort(env, "Invalid data load TLB miss exception\n");
2556
case POWERPC_EXCP_DSTLB: /* Data store TLB miss */
2557
new_msr &= ~((target_ulong)1 << MSR_RI); /* XXX: check this */
2558
if (lpes1 == 0) /* XXX: check this */
2559
new_msr |= (target_ulong)MSR_HVB;
2560
switch (excp_model) {
2561
case POWERPC_EXCP_602:
2562
case POWERPC_EXCP_603:
2563
case POWERPC_EXCP_603E:
2564
case POWERPC_EXCP_G2:
1742
"Instruction segment exception is not implemented yet !\n");
1744
case EXCP_HDECR: /* 0x0980 */
1746
cpu_abort(env, "Hypervisor decrementer exception is not implemented "
1749
/* Implementation specific exceptions */
1751
if (likely(env->spr[SPR_PVR] == CPU_PPC_G2 ||
1752
env->spr[SPR_PVR] == CPU_PPC_G2LE)) {
1753
/* Critical interrupt on G2 */
1755
cpu_abort(env, "G2 critical interrupt is not implemented yet !\n");
1758
cpu_abort(env, "Invalid exception 0x0A00 !\n");
1763
switch (PPC_EXCP(env)) {
1764
case PPC_FLAGS_EXCP_40x:
1765
/* APU unavailable on 405 */
1768
"APU unavailable exception is not implemented yet !\n");
1770
case PPC_FLAGS_EXCP_74xx:
1771
/* Altivec unavailable */
1773
cpu_abort(env, "Altivec unavailable exception "
1774
"is not implemented yet !\n");
1777
cpu_abort(env, "Invalid exception 0x0F20 !\n");
1783
switch (PPC_EXCP(env)) {
1784
case PPC_FLAGS_EXCP_40x:
1787
#if defined (DEBUG_EXCEPTIONS)
1789
fprintf(logfile, "PIT exception\n");
1792
case PPC_FLAGS_EXCP_602:
1793
case PPC_FLAGS_EXCP_603:
1794
/* ITLBMISS on 602/603 */
1796
case PPC_FLAGS_EXCP_7x5:
1797
/* ITLBMISS on 745/755 */
1800
cpu_abort(env, "Invalid exception 0x1000 !\n");
1806
switch (PPC_EXCP(env)) {
1807
case PPC_FLAGS_EXCP_40x:
1810
#if defined (DEBUG_EXCEPTIONS)
1812
fprintf(logfile, "FIT exception\n");
1816
cpu_abort(env, "Invalid exception 0x1010 !\n");
1822
switch (PPC_EXCP(env)) {
1823
case PPC_FLAGS_EXCP_40x:
1824
/* Watchdog on 4xx */
1826
#if defined (DEBUG_EXCEPTIONS)
1828
fprintf(logfile, "WDT exception\n");
1831
case PPC_FLAGS_EXCP_BOOKE:
1832
srr_0 = &env->spr[SPR_BOOKE_CSRR0];
1833
srr_1 = &env->spr[SPR_BOOKE_CSRR1];
1836
cpu_abort(env, "Invalid exception 0x1020 !\n");
1842
switch (PPC_EXCP(env)) {
1843
case PPC_FLAGS_EXCP_40x:
1844
/* DTLBMISS on 4xx */
1847
case PPC_FLAGS_EXCP_602:
1848
case PPC_FLAGS_EXCP_603:
1849
/* DLTLBMISS on 602/603 */
1851
case PPC_FLAGS_EXCP_7x5:
1852
/* DLTLBMISS on 745/755 */
1855
cpu_abort(env, "Invalid exception 0x1100 !\n");
1861
switch (PPC_EXCP(env)) {
1862
case PPC_FLAGS_EXCP_40x:
1863
/* ITLBMISS on 4xx */
1866
case PPC_FLAGS_EXCP_602:
1867
case PPC_FLAGS_EXCP_603:
1868
/* DSTLBMISS on 602/603 */
2566
1870
/* Swap temporary saved registers with GPRs */
2567
if (!(new_msr & ((target_ulong)1 << MSR_TGPR))) {
2568
new_msr |= (target_ulong)1 << MSR_TGPR;
2569
hreg_swap_gpr_tgpr(env);
2572
case POWERPC_EXCP_7x5:
2574
1873
#if defined (DEBUG_SOFTWARE_TLB)
2575
1874
if (loglevel != 0) {
2576
1875
const unsigned char *es;
2577
1876
target_ulong *miss, *cmp;
2579
if (excp == POWERPC_EXCP_IFTLB) {
1878
if (excp == 0x1000) {
2582
1881
miss = &env->spr[SPR_IMISS];
2583
1882
cmp = &env->spr[SPR_ICMP];
2585
if (excp == POWERPC_EXCP_DLTLB)
2597
1896
env->error_code);
1900
case PPC_FLAGS_EXCP_7x5:
1901
/* DSTLBMISS on 745/755 */
2600
1904
msr |= env->crf[0] << 28;
2601
1905
msr |= env->error_code; /* key, D/I, S/L bits */
2602
1906
/* Set way using a LRU mechanism */
2603
1907
msr |= ((env->last_way + 1) & (env->nb_ways - 1)) << 17;
2605
case POWERPC_EXCP_74xx:
2607
#if defined (DEBUG_SOFTWARE_TLB)
2608
if (loglevel != 0) {
2609
const unsigned char *es;
2610
target_ulong *miss, *cmp;
2612
if (excp == POWERPC_EXCP_IFTLB) {
2615
miss = &env->spr[SPR_TLBMISS];
2616
cmp = &env->spr[SPR_PTEHI];
2618
if (excp == POWERPC_EXCP_DLTLB)
2623
miss = &env->spr[SPR_TLBMISS];
2624
cmp = &env->spr[SPR_PTEHI];
2626
fprintf(logfile, "74xx %sTLB miss: %cM " ADDRX " %cC " ADDRX
2628
es, en, *miss, en, *cmp, env->error_code);
2631
msr |= env->error_code; /* key bit */
2634
cpu_abort(env, "Invalid data store TLB miss exception\n");
2638
case POWERPC_EXCP_FPA: /* Floating-point assist exception */
2640
cpu_abort(env, "Floating point assist exception "
2641
"is not implemented yet !\n");
2643
case POWERPC_EXCP_DABR: /* Data address breakpoint */
2645
cpu_abort(env, "DABR exception is not implemented yet !\n");
2647
case POWERPC_EXCP_IABR: /* Instruction address breakpoint */
2649
cpu_abort(env, "IABR exception is not implemented yet !\n");
2651
case POWERPC_EXCP_SMI: /* System management interrupt */
2653
cpu_abort(env, "SMI exception is not implemented yet !\n");
2655
case POWERPC_EXCP_THERM: /* Thermal interrupt */
2657
cpu_abort(env, "Thermal management exception "
2658
"is not implemented yet !\n");
2660
case POWERPC_EXCP_PERFM: /* Embedded performance monitor interrupt */
2661
new_msr &= ~((target_ulong)1 << MSR_RI);
2663
new_msr |= (target_ulong)MSR_HVB;
2666
"Performance counter exception is not implemented yet !\n");
2668
case POWERPC_EXCP_VPUA: /* Vector assist exception */
2670
cpu_abort(env, "VPU assist exception is not implemented yet !\n");
2672
case POWERPC_EXCP_SOFTP: /* Soft patch exception */
2675
"970 soft-patch exception is not implemented yet !\n");
2677
case POWERPC_EXCP_MAINT: /* Maintenance exception */
2680
"970 maintenance exception is not implemented yet !\n");
2682
case POWERPC_EXCP_MEXTBR: /* Maskable external breakpoint */
2684
cpu_abort(env, "Maskable external exception "
2685
"is not implemented yet !\n");
2687
case POWERPC_EXCP_NMEXTBR: /* Non maskable external breakpoint */
2689
cpu_abort(env, "Non maskable external exception "
2690
"is not implemented yet !\n");
1910
cpu_abort(env, "Invalid exception 0x1200 !\n");
1915
switch (PPC_EXCP(env)) {
1916
case PPC_FLAGS_EXCP_601:
1917
case PPC_FLAGS_EXCP_602:
1918
case PPC_FLAGS_EXCP_603:
1919
case PPC_FLAGS_EXCP_604:
1920
case PPC_FLAGS_EXCP_7x0:
1921
case PPC_FLAGS_EXCP_7x5:
1922
/* IABR on 6xx/7xx */
1924
cpu_abort(env, "IABR exception is not implemented yet !\n");
1927
cpu_abort(env, "Invalid exception 0x1300 !\n");
1932
switch (PPC_EXCP(env)) {
1933
case PPC_FLAGS_EXCP_601:
1934
case PPC_FLAGS_EXCP_602:
1935
case PPC_FLAGS_EXCP_603:
1936
case PPC_FLAGS_EXCP_604:
1937
case PPC_FLAGS_EXCP_7x0:
1938
case PPC_FLAGS_EXCP_7x5:
1939
/* SMI on 6xx/7xx */
1941
cpu_abort(env, "SMI exception is not implemented yet !\n");
1944
cpu_abort(env, "Invalid exception 0x1400 !\n");
1949
switch (PPC_EXCP(env)) {
1950
case PPC_FLAGS_EXCP_602:
1951
/* Watchdog on 602 */
1954
"602 watchdog exception is not implemented yet !\n");
1956
case PPC_FLAGS_EXCP_970:
1957
/* Soft patch exception on 970 */
1960
"970 soft-patch exception is not implemented yet !\n");
1962
case PPC_FLAGS_EXCP_74xx:
1963
/* VPU assist on 74xx */
1965
cpu_abort(env, "VPU assist exception is not implemented yet !\n");
1968
cpu_abort(env, "Invalid exception 0x1500 !\n");
1973
switch (PPC_EXCP(env)) {
1974
case PPC_FLAGS_EXCP_602:
1975
/* Emulation trap on 602 */
1977
cpu_abort(env, "602 emulation trap exception "
1978
"is not implemented yet !\n");
1980
case PPC_FLAGS_EXCP_970:
1981
/* Maintenance exception on 970 */
1984
"970 maintenance exception is not implemented yet !\n");
1987
cpu_abort(env, "Invalid exception 0x1600 !\n");
1992
switch (PPC_EXCP(env)) {
1993
case PPC_FLAGS_EXCP_7x0:
1994
case PPC_FLAGS_EXCP_7x5:
1995
/* Thermal management interrupt on G3 */
1997
cpu_abort(env, "G3 thermal management exception "
1998
"is not implemented yet !\n");
2000
case PPC_FLAGS_EXCP_970:
2001
/* VPU assist on 970 */
2004
"970 VPU assist exception is not implemented yet !\n");
2007
cpu_abort(env, "Invalid exception 0x1700 !\n");
2012
switch (PPC_EXCP(env)) {
2013
case PPC_FLAGS_EXCP_970:
2014
/* Thermal exception on 970 */
2016
cpu_abort(env, "970 thermal management exception "
2017
"is not implemented yet !\n");
2020
cpu_abort(env, "Invalid exception 0x1800 !\n");
2025
switch (PPC_EXCP(env)) {
2026
case PPC_FLAGS_EXCP_40x:
2029
cpu_abort(env, "40x debug exception is not implemented yet !\n");
2031
case PPC_FLAGS_EXCP_601:
2032
/* Run mode exception on 601 */
2035
"601 run mode exception is not implemented yet !\n");
2037
case PPC_FLAGS_EXCP_BOOKE:
2038
srr_0 = &env->spr[SPR_BOOKE_CSRR0];
2039
srr_1 = &env->spr[SPR_BOOKE_CSRR1];
2042
cpu_abort(env, "Invalid exception 0x1800 !\n");
2046
/* Other exceptions */
2047
/* Qemu internal exceptions:
2048
* we should never come here with those values: abort execution
2694
cpu_abort(env, "Invalid PowerPC exception %d. Aborting\n", excp);
2051
cpu_abort(env, "Invalid exception: code %d (%04x)\n", excp, excp);
2697
2054
/* save current instruction location */
2698
env->spr[srr0] = env->nip - 4;
2055
*srr_0 = env->nip - 4;
2701
2058
/* save next instruction location */
2702
env->spr[srr0] = env->nip;
2706
env->spr[srr1] = msr;
2707
/* If any alternate SRR register are defined, duplicate saved values */
2709
env->spr[asrr0] = env->spr[srr0];
2711
env->spr[asrr1] = env->spr[srr1];
2712
2068
/* If we disactivated any translation, flush TLBs */
2713
if (new_msr & ((1 << MSR_IR) | (1 << MSR_DR)))
2069
if (msr_ir || msr_dr) {
2714
2070
tlb_flush(env, 1);
2715
2072
/* reload MSR with correct bits */
2716
new_msr &= ~((target_ulong)1 << MSR_EE);
2717
new_msr &= ~((target_ulong)1 << MSR_PR);
2718
new_msr &= ~((target_ulong)1 << MSR_FP);
2719
new_msr &= ~((target_ulong)1 << MSR_FE0);
2720
new_msr &= ~((target_ulong)1 << MSR_SE);
2721
new_msr &= ~((target_ulong)1 << MSR_BE);
2722
new_msr &= ~((target_ulong)1 << MSR_FE1);
2723
new_msr &= ~((target_ulong)1 << MSR_IR);
2724
new_msr &= ~((target_ulong)1 << MSR_DR);
2725
#if 0 /* Fix this: not on all targets */
2726
new_msr &= ~((target_ulong)1 << MSR_PMM);
2084
if (PPC_EXCP(env) == PPC_FLAGS_EXCP_BOOKE) {
2086
if (idx == -1 || (idx >= 16 && idx < 32)) {
2087
cpu_abort(env, "Invalid exception index for excp %d %08x idx %d\n",
2090
#if defined(TARGET_PPC64)
2092
env->nip = (uint64_t)env->spr[SPR_BOOKE_IVPR];
2728
new_msr &= ~((target_ulong)1 << MSR_LE);
2730
new_msr |= (target_ulong)1 << MSR_LE;
2732
new_msr &= ~((target_ulong)1 << MSR_LE);
2095
env->nip = (uint32_t)env->spr[SPR_BOOKE_IVPR];
2097
env->nip |= env->spr[SPR_BOOKE_IVOR0 + idx];
2099
env->nip |= env->spr[SPR_BOOKE_IVOR32 + idx - 32];
2104
do_compute_hflags(env);
2733
2105
/* Jump to handler */
2734
vector = env->excp_vectors[excp];
2735
if (vector == (target_ulong)-1ULL) {
2736
cpu_abort(env, "Raised an exception without defined vector %d\n",
2739
vector |= env->excp_prefix;
2740
#if defined(TARGET_PPC64)
2741
if (excp_model == POWERPC_EXCP_BOOKE) {
2743
new_msr &= ~((target_ulong)1 << MSR_CM);
2744
vector = (uint32_t)vector;
2746
new_msr |= (target_ulong)1 << MSR_CM;
2750
new_msr &= ~((target_ulong)1 << MSR_SF);
2751
vector = (uint32_t)vector;
2753
new_msr |= (target_ulong)1 << MSR_SF;
2757
/* XXX: we don't use hreg_store_msr here as already have treated
2758
* any special case that could occur. Just store MSR and update hflags
2760
env->msr = new_msr & env->msr_mask;
2761
hreg_compute_hflags(env);
2763
/* Reset exception state */
2764
env->exception_index = POWERPC_EXCP_NONE;
2765
env->error_code = 0;
2768
void do_interrupt (CPUState *env)
2770
powerpc_excp(env, env->excp_model, env->exception_index);
2106
env->exception_index = EXCP_NONE;
2773
2109
void ppc_hw_interrupt (CPUPPCState *env)
2778
2114
if (loglevel & CPU_LOG_INT) {
2779
2115
fprintf(logfile, "%s: %p pending %08x req %08x me %d ee %d\n",
2780
2116
__func__, env, env->pending_interrupts,
2781
env->interrupt_request, (int)msr_me, (int)msr_ee);
2117
env->interrupt_request, msr_me, msr_ee);
2784
/* External reset */
2785
2121
if (env->pending_interrupts & (1 << PPC_INTERRUPT_RESET)) {
2122
/* External reset / critical input */
2123
/* XXX: critical input should be handled another way.
2124
* This code is not correct !
2126
env->exception_index = EXCP_RESET;
2786
2127
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_RESET);
2787
powerpc_excp(env, env->excp_model, POWERPC_EXCP_RESET);
2790
/* Machine check exception */
2791
if (env->pending_interrupts & (1 << PPC_INTERRUPT_MCK)) {
2792
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_MCK);
2793
powerpc_excp(env, env->excp_model, POWERPC_EXCP_MCHECK);
2797
/* External debug exception */
2798
if (env->pending_interrupts & (1 << PPC_INTERRUPT_DEBUG)) {
2799
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DEBUG);
2800
powerpc_excp(env, env->excp_model, POWERPC_EXCP_DEBUG);
2805
/* XXX: find a suitable condition to enable the hypervisor mode */
2806
hdice = env->spr[SPR_LPCR] & 1;
2810
if ((msr_ee != 0 || msr_hv == 0 || msr_pr != 0) && hdice != 0) {
2130
if (raised == 0 && msr_me != 0) {
2131
/* Machine check exception */
2132
if (env->pending_interrupts & (1 << PPC_INTERRUPT_MCK)) {
2133
env->exception_index = EXCP_MACHINE_CHECK;
2134
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_MCK);
2138
if (raised == 0 && msr_ee != 0) {
2139
#if defined(TARGET_PPC64H) /* PowerPC 64 with hypervisor mode support */
2811
2140
/* Hypervisor decrementer exception */
2812
2141
if (env->pending_interrupts & (1 << PPC_INTERRUPT_HDECR)) {
2142
env->exception_index = EXCP_HDECR;
2813
2143
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_HDECR);
2814
powerpc_excp(env, env->excp_model, POWERPC_EXCP_HDECR);
2819
/* External critical interrupt */
2820
if (env->pending_interrupts & (1 << PPC_INTERRUPT_CEXT)) {
2821
/* Taking a critical external interrupt does not clear the external
2822
* critical interrupt status
2825
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_CEXT);
2827
powerpc_excp(env, env->excp_model, POWERPC_EXCP_CRITICAL);
2832
/* Watchdog timer on embedded PowerPC */
2833
if (env->pending_interrupts & (1 << PPC_INTERRUPT_WDT)) {
2834
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_WDT);
2835
powerpc_excp(env, env->excp_model, POWERPC_EXCP_WDT);
2838
if (env->pending_interrupts & (1 << PPC_INTERRUPT_CDOORBELL)) {
2839
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_CDOORBELL);
2840
powerpc_excp(env, env->excp_model, POWERPC_EXCP_DOORCI);
2843
/* Fixed interval timer on embedded PowerPC */
2844
if (env->pending_interrupts & (1 << PPC_INTERRUPT_FIT)) {
2845
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_FIT);
2846
powerpc_excp(env, env->excp_model, POWERPC_EXCP_FIT);
2849
/* Programmable interval timer on embedded PowerPC */
2850
if (env->pending_interrupts & (1 << PPC_INTERRUPT_PIT)) {
2851
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PIT);
2852
powerpc_excp(env, env->excp_model, POWERPC_EXCP_PIT);
2855
2147
/* Decrementer exception */
2856
2148
if (env->pending_interrupts & (1 << PPC_INTERRUPT_DECR)) {
2149
env->exception_index = EXCP_DECR;
2857
2150
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DECR);
2858
powerpc_excp(env, env->excp_model, POWERPC_EXCP_DECR);
2152
/* Programmable interval timer on embedded PowerPC */
2153
} else if (env->pending_interrupts & (1 << PPC_INTERRUPT_PIT)) {
2154
env->exception_index = EXCP_40x_PIT;
2155
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PIT);
2157
/* Fixed interval timer on embedded PowerPC */
2158
} else if (env->pending_interrupts & (1 << PPC_INTERRUPT_FIT)) {
2159
env->exception_index = EXCP_40x_FIT;
2160
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_FIT);
2162
/* Watchdog timer on embedded PowerPC */
2163
} else if (env->pending_interrupts & (1 << PPC_INTERRUPT_WDT)) {
2164
env->exception_index = EXCP_40x_WATCHDOG;
2165
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_WDT);
2861
2167
/* External interrupt */
2862
if (env->pending_interrupts & (1 << PPC_INTERRUPT_EXT)) {
2168
} else if (env->pending_interrupts & (1 << PPC_INTERRUPT_EXT)) {
2169
env->exception_index = EXCP_EXTERNAL;
2863
2170
/* Taking an external interrupt does not clear the external
2864
2171
* interrupt status
2867
2174
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_EXT);
2869
powerpc_excp(env, env->excp_model, POWERPC_EXCP_EXTERNAL);
2872
if (env->pending_interrupts & (1 << PPC_INTERRUPT_DOORBELL)) {
2873
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DOORBELL);
2874
powerpc_excp(env, env->excp_model, POWERPC_EXCP_DOORI);
2877
if (env->pending_interrupts & (1 << PPC_INTERRUPT_PERFM)) {
2878
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PERFM);
2879
powerpc_excp(env, env->excp_model, POWERPC_EXCP_PERFM);
2882
2178
/* Thermal interrupt */
2883
if (env->pending_interrupts & (1 << PPC_INTERRUPT_THERM)) {
2179
} else if (env->pending_interrupts & (1 << PPC_INTERRUPT_THERM)) {
2180
env->exception_index = EXCP_970_THRM;
2884
2181
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_THERM);
2885
powerpc_excp(env, env->excp_model, POWERPC_EXCP_THERM);
2186
/* External debug exception */
2187
} else if (env->pending_interrupts & (1 << PPC_INTERRUPT_DEBUG)) {
2188
env->exception_index = EXCP_xxx;
2189
env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DEBUG);
2194
env->error_code = 0;
2890
2198
#endif /* !CONFIG_USER_ONLY */
2200
void cpu_dump_EA (target_ulong EA)
2210
fprintf(f, "Memory access at address " ADDRX "\n", EA);
2892
2213
void cpu_dump_rfi (target_ulong RA, target_ulong msr)