2021-07-23 20:56:25 +03:00
|
|
|
/*
|
|
|
|
* PowerPC MMU, TLB, SLB and BAT emulation helpers for QEMU.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2007 Jocelyn Mayer
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu/units.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "sysemu/kvm.h"
|
|
|
|
#include "kvm_ppc.h"
|
|
|
|
#include "mmu-hash64.h"
|
|
|
|
#include "mmu-hash32.h"
|
|
|
|
#include "exec/exec-all.h"
|
2023-12-06 22:27:32 +03:00
|
|
|
#include "exec/page-protection.h"
|
2021-07-23 20:56:25 +03:00
|
|
|
#include "exec/log.h"
|
|
|
|
#include "helper_regs.h"
|
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qemu/qemu-print.h"
|
|
|
|
#include "internal.h"
|
|
|
|
#include "mmu-book3s-v3.h"
|
|
|
|
#include "mmu-radix64.h"
|
2024-05-13 02:28:08 +03:00
|
|
|
#include "mmu-booke.h"
|
2021-07-23 20:56:25 +03:00
|
|
|
|
|
|
|
/* #define DUMP_PAGE_TABLES */
|
|
|
|
|
2021-07-23 20:56:26 +03:00
|
|
|
void ppc_store_sdr1(CPUPPCState *env, target_ulong value)
|
|
|
|
{
|
|
|
|
PowerPCCPU *cpu = env_archcpu(env);
|
|
|
|
qemu_log_mask(CPU_LOG_MMU, "%s: " TARGET_FMT_lx "\n", __func__, value);
|
|
|
|
assert(!cpu->env.has_hv_mode || !cpu->vhyp);
|
|
|
|
#if defined(TARGET_PPC64)
|
|
|
|
if (mmu_is_64bit(env->mmu_model)) {
|
|
|
|
target_ulong sdr_mask = SDR_64_HTABORG | SDR_64_HTABSIZE;
|
|
|
|
target_ulong htabsize = value & SDR_64_HTABSIZE;
|
|
|
|
|
|
|
|
if (value & ~sdr_mask) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "Invalid bits 0x"TARGET_FMT_lx
|
|
|
|
" set in SDR1", value & ~sdr_mask);
|
|
|
|
value &= sdr_mask;
|
|
|
|
}
|
|
|
|
if (htabsize > 28) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "Invalid HTABSIZE 0x" TARGET_FMT_lx
|
|
|
|
" stored in SDR1", htabsize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* defined(TARGET_PPC64) */
|
|
|
|
/* FIXME: Should check for valid HTABMASK values in 32-bit case */
|
|
|
|
env->spr[SPR_SDR1] = value;
|
|
|
|
}
|
|
|
|
|
2021-07-23 20:56:25 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* PowerPC MMU emulation */
|
|
|
|
|
|
|
|
int ppc6xx_tlb_getnum(CPUPPCState *env, target_ulong eaddr,
|
|
|
|
int way, int is_code)
|
|
|
|
{
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
/* Select TLB num in a way from address */
|
|
|
|
nr = (eaddr >> TARGET_PAGE_BITS) & (env->tlb_per_way - 1);
|
|
|
|
/* Select TLB way */
|
|
|
|
nr += env->tlb_per_way * way;
|
2024-05-13 02:28:02 +03:00
|
|
|
/* 6xx has separate TLBs for instructions and data */
|
|
|
|
if (is_code) {
|
2021-07-23 20:56:25 +03:00
|
|
|
nr += env->nb_tlb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Software driven TLB helpers */
|
|
|
|
|
2024-05-27 02:12:58 +03:00
|
|
|
static int ppc6xx_tlb_check(CPUPPCState *env, hwaddr *raddr, int *prot,
|
|
|
|
target_ulong eaddr, MMUAccessType access_type,
|
|
|
|
target_ulong ptem, bool key, bool nx)
|
2021-07-23 20:56:25 +03:00
|
|
|
{
|
|
|
|
ppc6xx_tlb_t *tlb;
|
2024-05-27 02:12:46 +03:00
|
|
|
target_ulong *pte1p;
|
|
|
|
int nr, best, way, ret;
|
2024-05-27 02:12:53 +03:00
|
|
|
bool is_code = (access_type == MMU_INST_FETCH);
|
2021-07-23 20:56:25 +03:00
|
|
|
|
2024-05-27 02:12:56 +03:00
|
|
|
/* Initialize real address with an invalid value */
|
2024-05-27 02:12:58 +03:00
|
|
|
*raddr = (hwaddr)-1ULL;
|
2021-07-23 20:56:25 +03:00
|
|
|
best = -1;
|
|
|
|
ret = -1; /* No TLB found */
|
|
|
|
for (way = 0; way < env->nb_ways; way++) {
|
2024-05-27 02:12:53 +03:00
|
|
|
nr = ppc6xx_tlb_getnum(env, eaddr, way, is_code);
|
2021-07-23 20:56:25 +03:00
|
|
|
tlb = &env->tlb.tlb6[nr];
|
|
|
|
/* This test "emulates" the PTE index match for hardware TLBs */
|
|
|
|
if ((eaddr & TARGET_PAGE_MASK) != tlb->EPN) {
|
2022-01-04 09:55:34 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "TLB %d/%d %s [" TARGET_FMT_lx
|
|
|
|
" " TARGET_FMT_lx "] <> " TARGET_FMT_lx "\n",
|
|
|
|
nr, env->nb_tlb,
|
|
|
|
pte_is_valid(tlb->pte0) ? "valid" : "inval",
|
|
|
|
tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE, eaddr);
|
2021-07-23 20:56:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-04 09:55:34 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "TLB %d/%d %s " TARGET_FMT_lx " <> "
|
|
|
|
TARGET_FMT_lx " " TARGET_FMT_lx " %c %c\n",
|
|
|
|
nr, env->nb_tlb,
|
|
|
|
pte_is_valid(tlb->pte0) ? "valid" : "inval",
|
|
|
|
tlb->EPN, eaddr, tlb->pte1,
|
|
|
|
access_type == MMU_DATA_STORE ? 'S' : 'L',
|
|
|
|
access_type == MMU_INST_FETCH ? 'I' : 'D');
|
2024-05-27 02:12:51 +03:00
|
|
|
/* Check validity and table match */
|
|
|
|
if (!pte_is_valid(tlb->pte0) || ((tlb->pte0 >> 6) & 1) != 0 ||
|
2024-05-27 02:12:53 +03:00
|
|
|
(tlb->pte0 & PTE_PTEM_MASK) != ptem) {
|
2024-05-27 02:12:51 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* all matches should have equal RPN, WIMG & PP */
|
2024-05-27 02:12:58 +03:00
|
|
|
if (*raddr != (hwaddr)-1ULL &&
|
|
|
|
(*raddr & PTE_CHECK_MASK) != (tlb->pte1 & PTE_CHECK_MASK)) {
|
2024-05-27 02:12:51 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "Bad RPN/WIMG/PP\n");
|
|
|
|
/* TLB inconsistency */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Keep the matching PTE information */
|
|
|
|
best = nr;
|
2024-05-27 02:12:58 +03:00
|
|
|
*raddr = tlb->pte1;
|
|
|
|
*prot = ppc_hash32_prot(key, tlb->pte1 & HPTE32_R_PP, nx);
|
|
|
|
if (check_prot_access_type(*prot, access_type)) {
|
2024-05-27 02:12:51 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "PTE access granted !\n");
|
2021-07-23 20:56:25 +03:00
|
|
|
ret = 0;
|
2024-05-27 02:12:51 +03:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(CPU_LOG_MMU, "PTE access rejected\n");
|
|
|
|
ret = -2;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best != -1) {
|
2023-01-11 00:29:47 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "found TLB at addr " HWADDR_FMT_plx
|
2022-01-04 09:55:34 +03:00
|
|
|
" prot=%01x ret=%d\n",
|
2024-05-27 02:12:58 +03:00
|
|
|
*raddr & TARGET_PAGE_MASK, *prot, ret);
|
2021-07-23 20:56:25 +03:00
|
|
|
/* Update page flags */
|
2024-05-27 02:12:46 +03:00
|
|
|
pte1p = &env->tlb.tlb6[best].pte1;
|
|
|
|
*pte1p |= 0x00000100; /* Update accessed flag */
|
|
|
|
if (!(*pte1p & 0x00000080)) {
|
|
|
|
if (access_type == MMU_DATA_STORE && ret == 0) {
|
|
|
|
/* Update changed flag */
|
|
|
|
*pte1p |= 0x00000080;
|
|
|
|
} else {
|
|
|
|
/* Force page fault for first write access */
|
2024-05-27 02:12:58 +03:00
|
|
|
*prot &= ~PAGE_WRITE;
|
2024-05-27 02:12:46 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
2024-05-27 02:12:53 +03:00
|
|
|
if (ret == -1) {
|
|
|
|
int r = is_code ? SPR_ICMP : SPR_DCMP;
|
|
|
|
env->spr[r] = ptem;
|
|
|
|
}
|
2024-05-13 02:27:41 +03:00
|
|
|
#if defined(DUMP_PAGE_TABLES)
|
|
|
|
if (qemu_loglevel_mask(CPU_LOG_MMU)) {
|
|
|
|
CPUState *cs = env_cpu(env);
|
|
|
|
hwaddr base = ppc_hash32_hpt_base(env_archcpu(env));
|
|
|
|
hwaddr len = ppc_hash32_hpt_mask(env_archcpu(env)) + 0x80;
|
|
|
|
uint32_t a0, a1, a2, a3;
|
|
|
|
|
|
|
|
qemu_log("Page table: " HWADDR_FMT_plx " len " HWADDR_FMT_plx "\n",
|
|
|
|
base, len);
|
|
|
|
for (hwaddr curaddr = base; curaddr < base + len; curaddr += 16) {
|
|
|
|
a0 = ldl_phys(cs->as, curaddr);
|
|
|
|
a1 = ldl_phys(cs->as, curaddr + 4);
|
|
|
|
a2 = ldl_phys(cs->as, curaddr + 8);
|
|
|
|
a3 = ldl_phys(cs->as, curaddr + 12);
|
|
|
|
if (a0 != 0 || a1 != 0 || a2 != 0 || a3 != 0) {
|
|
|
|
qemu_log(HWADDR_FMT_plx ": %08x %08x %08x %08x\n",
|
|
|
|
curaddr, a0, a1, a2, a3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-07-23 20:56:25 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-05-27 02:13:02 +03:00
|
|
|
static int get_bat_6xx_tlb(CPUPPCState *env, hwaddr *raddr, int *prot,
|
2024-05-27 02:13:01 +03:00
|
|
|
target_ulong eaddr, MMUAccessType access_type,
|
|
|
|
bool pr)
|
2021-07-23 20:56:25 +03:00
|
|
|
{
|
|
|
|
target_ulong *BATlt, *BATut, *BATu, *BATl;
|
|
|
|
target_ulong BEPIl, BEPIu, bl;
|
2024-05-27 02:13:01 +03:00
|
|
|
int i, ret = -1;
|
2021-07-23 20:56:25 +03:00
|
|
|
bool ifetch = access_type == MMU_INST_FETCH;
|
|
|
|
|
2024-05-13 02:27:47 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "%s: %cBAT v " TARGET_FMT_lx "\n", __func__,
|
2024-05-27 02:12:59 +03:00
|
|
|
ifetch ? 'I' : 'D', eaddr);
|
2021-07-23 20:56:25 +03:00
|
|
|
if (ifetch) {
|
|
|
|
BATlt = env->IBAT[1];
|
|
|
|
BATut = env->IBAT[0];
|
|
|
|
} else {
|
|
|
|
BATlt = env->DBAT[1];
|
|
|
|
BATut = env->DBAT[0];
|
|
|
|
}
|
|
|
|
for (i = 0; i < env->nb_BATs; i++) {
|
|
|
|
BATu = &BATut[i];
|
|
|
|
BATl = &BATlt[i];
|
2024-05-27 02:13:00 +03:00
|
|
|
BEPIu = *BATu & BATU32_BEPIU;
|
|
|
|
BEPIl = *BATu & BATU32_BEPIL;
|
2024-05-13 02:27:47 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "%s: %cBAT%d v " TARGET_FMT_lx " BATu "
|
|
|
|
TARGET_FMT_lx " BATl " TARGET_FMT_lx "\n", __func__,
|
2024-05-27 02:12:59 +03:00
|
|
|
ifetch ? 'I' : 'D', i, eaddr, *BATu, *BATl);
|
2024-05-27 02:13:01 +03:00
|
|
|
bl = (*BATu & BATU32_BL) << 15;
|
|
|
|
if ((!pr && (*BATu & BATU32_VS)) || (pr && (*BATu & BATU32_VP))) {
|
|
|
|
if ((eaddr & BATU32_BEPIU) == BEPIu &&
|
|
|
|
((eaddr & BATU32_BEPIL) & ~bl) == BEPIl) {
|
2021-07-23 20:56:25 +03:00
|
|
|
/* Get physical address */
|
2024-05-27 02:13:02 +03:00
|
|
|
*raddr = (*BATl & BATU32_BEPIU) |
|
2024-05-27 02:13:00 +03:00
|
|
|
((eaddr & BATU32_BEPIL & bl) | (*BATl & BATU32_BEPIL)) |
|
2024-05-27 02:12:59 +03:00
|
|
|
(eaddr & 0x0001F000);
|
2021-07-23 20:56:25 +03:00
|
|
|
/* Compute access rights */
|
2024-05-27 02:13:02 +03:00
|
|
|
*prot = ppc_hash32_bat_prot(*BATu, *BATl);
|
|
|
|
if (check_prot_access_type(*prot, access_type)) {
|
2023-01-11 00:29:47 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "BAT %d match: r " HWADDR_FMT_plx
|
2024-05-27 02:13:02 +03:00
|
|
|
" prot=%c%c\n", i, *raddr,
|
|
|
|
*prot & PAGE_READ ? 'R' : '-',
|
|
|
|
*prot & PAGE_WRITE ? 'W' : '-');
|
2024-05-13 02:28:07 +03:00
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
ret = -2;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
|
|
|
if (qemu_log_enabled()) {
|
2022-01-04 09:55:34 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "no BAT match for "
|
2024-05-27 02:12:59 +03:00
|
|
|
TARGET_FMT_lx ":\n", eaddr);
|
2021-07-23 20:56:25 +03:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
BATu = &BATut[i];
|
|
|
|
BATl = &BATlt[i];
|
2024-05-27 02:13:00 +03:00
|
|
|
BEPIu = *BATu & BATU32_BEPIU;
|
|
|
|
BEPIl = *BATu & BATU32_BEPIL;
|
|
|
|
bl = (*BATu & BATU32_BL) << 15;
|
2024-05-13 02:27:47 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "%s: %cBAT%d v " TARGET_FMT_lx
|
|
|
|
" BATu " TARGET_FMT_lx " BATl " TARGET_FMT_lx
|
|
|
|
"\n\t" TARGET_FMT_lx " " TARGET_FMT_lx " "
|
|
|
|
TARGET_FMT_lx "\n", __func__, ifetch ? 'I' : 'D',
|
2024-05-27 02:12:59 +03:00
|
|
|
i, eaddr, *BATu, *BATl, BEPIu, BEPIl, bl);
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* No hit */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-05-27 02:13:03 +03:00
|
|
|
static int mmu6xx_get_physical_address(CPUPPCState *env, hwaddr *raddr,
|
|
|
|
int *prot, target_ulong eaddr,
|
2024-05-27 02:12:57 +03:00
|
|
|
hwaddr *hashp, bool *keyp,
|
2024-05-13 02:27:39 +03:00
|
|
|
MMUAccessType access_type, int type)
|
2021-07-23 20:56:25 +03:00
|
|
|
{
|
|
|
|
PowerPCCPU *cpu = env_archcpu(env);
|
|
|
|
hwaddr hash;
|
2024-05-27 02:12:53 +03:00
|
|
|
target_ulong vsid, sr, pgidx, ptem;
|
2024-05-27 02:13:01 +03:00
|
|
|
bool key, ds, nx;
|
|
|
|
bool pr = FIELD_EX64(env->msr, MSR, PR);
|
2021-07-23 20:56:25 +03:00
|
|
|
|
2024-05-13 02:27:39 +03:00
|
|
|
/* First try to find a BAT entry if there are any */
|
2024-05-27 02:13:01 +03:00
|
|
|
if (env->nb_BATs &&
|
2024-05-27 02:13:03 +03:00
|
|
|
get_bat_6xx_tlb(env, raddr, prot, eaddr, access_type, pr) == 0) {
|
2024-05-13 02:27:39 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform segment based translation when no BATs matched */
|
2021-07-23 20:56:25 +03:00
|
|
|
sr = env->sr[eaddr >> 28];
|
2024-05-27 02:12:57 +03:00
|
|
|
key = ppc_hash32_key(pr, sr);
|
|
|
|
*keyp = key;
|
2024-05-27 02:12:48 +03:00
|
|
|
ds = sr & SR32_T;
|
2024-05-27 02:12:47 +03:00
|
|
|
nx = sr & SR32_NX;
|
|
|
|
vsid = sr & SR32_VSID;
|
2021-07-23 20:56:25 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU,
|
2022-01-04 09:55:34 +03:00
|
|
|
"Check segment v=" TARGET_FMT_lx " %d " TARGET_FMT_lx
|
|
|
|
" nip=" TARGET_FMT_lx " lr=" TARGET_FMT_lx
|
|
|
|
" ir=%d dr=%d pr=%d %d t=%d\n",
|
2022-05-05 00:05:22 +03:00
|
|
|
eaddr, (int)(eaddr >> 28), sr, env->nip, env->lr,
|
2022-05-05 00:05:34 +03:00
|
|
|
(int)FIELD_EX64(env->msr, MSR, IR),
|
|
|
|
(int)FIELD_EX64(env->msr, MSR, DR), pr ? 1 : 0,
|
2022-01-04 09:55:34 +03:00
|
|
|
access_type == MMU_DATA_STORE, type);
|
2024-05-27 02:12:49 +03:00
|
|
|
pgidx = (eaddr & ~SEGMENT_MASK_256M) >> TARGET_PAGE_BITS;
|
2021-07-23 20:56:25 +03:00
|
|
|
hash = vsid ^ pgidx;
|
2024-05-27 02:12:53 +03:00
|
|
|
ptem = (vsid << 7) | (pgidx >> 10); /* Virtual segment ID | API */
|
2021-07-23 20:56:25 +03:00
|
|
|
|
2024-05-13 02:27:47 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "pte segment: key=%d ds %d nx %d vsid "
|
2024-05-27 02:12:57 +03:00
|
|
|
TARGET_FMT_lx "\n", key, ds, nx, vsid);
|
2021-07-23 20:56:25 +03:00
|
|
|
if (!ds) {
|
|
|
|
/* Check if instruction fetch is allowed, if needed */
|
2024-05-27 02:12:47 +03:00
|
|
|
if (type == ACCESS_CODE && nx) {
|
2024-05-13 02:27:40 +03:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "No access allowed\n");
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
/* Page address translation */
|
|
|
|
qemu_log_mask(CPU_LOG_MMU, "htab_base " HWADDR_FMT_plx " htab_mask "
|
|
|
|
HWADDR_FMT_plx " hash " HWADDR_FMT_plx "\n",
|
|
|
|
ppc_hash32_hpt_base(cpu), ppc_hash32_hpt_mask(cpu), hash);
|
2024-05-27 02:12:45 +03:00
|
|
|
*hashp = hash;
|
2024-05-13 02:27:40 +03:00
|
|
|
|
|
|
|
/* Software TLB search */
|
2024-05-27 02:13:03 +03:00
|
|
|
return ppc6xx_tlb_check(env, raddr, prot, eaddr,
|
2024-05-27 02:12:58 +03:00
|
|
|
access_type, ptem, key, nx);
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
|
2024-05-13 02:27:42 +03:00
|
|
|
/* Direct-store segment : absolutely *BUGGY* for now */
|
|
|
|
qemu_log_mask(CPU_LOG_MMU, "direct store...\n");
|
|
|
|
switch (type) {
|
|
|
|
case ACCESS_INT:
|
|
|
|
/* Integer load/store : only access allowed */
|
|
|
|
break;
|
|
|
|
case ACCESS_CACHE:
|
|
|
|
/*
|
|
|
|
* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi
|
|
|
|
*
|
|
|
|
* Should make the instruction do no-op. As it already do
|
|
|
|
* no-op, it's quite easy :-)
|
|
|
|
*/
|
2024-05-27 02:13:03 +03:00
|
|
|
*raddr = eaddr;
|
2024-05-13 02:27:42 +03:00
|
|
|
return 0;
|
2024-05-27 02:12:50 +03:00
|
|
|
case ACCESS_CODE: /* No code fetch is allowed in direct-store areas */
|
|
|
|
case ACCESS_FLOAT: /* Floating point load/store */
|
|
|
|
case ACCESS_RES: /* lwarx, ldarx or srwcx. */
|
|
|
|
case ACCESS_EXT: /* eciwx or ecowx */
|
2024-05-13 02:27:42 +03:00
|
|
|
return -4;
|
|
|
|
}
|
2024-05-27 02:12:57 +03:00
|
|
|
if ((access_type == MMU_DATA_STORE || !key) &&
|
|
|
|
(access_type == MMU_DATA_LOAD || key)) {
|
2024-05-27 02:13:03 +03:00
|
|
|
*raddr = eaddr;
|
2024-05-13 02:27:42 +03:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return -2;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *book3e_tsize_to_str[32] = {
|
|
|
|
"1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K",
|
|
|
|
"1M", "2M", "4M", "8M", "16M", "32M", "64M", "128M", "256M", "512M",
|
|
|
|
"1G", "2G", "4G", "8G", "16G", "32G", "64G", "128G", "256G", "512G",
|
|
|
|
"1T", "2T"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mmubooke_dump_mmu(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
ppcemb_tlb_t *entry;
|
|
|
|
int i;
|
|
|
|
|
2023-04-04 12:14:58 +03:00
|
|
|
#ifdef CONFIG_KVM
|
2021-07-23 20:56:25 +03:00
|
|
|
if (kvm_enabled() && !env->kvm_sw_tlb) {
|
|
|
|
qemu_printf("Cannot access KVM TLB\n");
|
|
|
|
return;
|
|
|
|
}
|
2023-04-04 12:14:58 +03:00
|
|
|
#endif
|
2021-07-23 20:56:25 +03:00
|
|
|
|
|
|
|
qemu_printf("\nTLB:\n");
|
|
|
|
qemu_printf("Effective Physical Size PID Prot "
|
|
|
|
"Attr\n");
|
|
|
|
|
|
|
|
entry = &env->tlb.tlbe[0];
|
|
|
|
for (i = 0; i < env->nb_tlb; i++, entry++) {
|
|
|
|
hwaddr ea, pa;
|
|
|
|
target_ulong mask;
|
|
|
|
uint64_t size = (uint64_t)entry->size;
|
|
|
|
char size_buf[20];
|
|
|
|
|
|
|
|
/* Check valid flag */
|
|
|
|
if (!(entry->prot & PAGE_VALID)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = ~(entry->size - 1);
|
|
|
|
ea = entry->EPN & mask;
|
|
|
|
pa = entry->RPN & mask;
|
|
|
|
/* Extend the physical address to 36 bits */
|
|
|
|
pa |= (hwaddr)(entry->RPN & 0xF) << 32;
|
|
|
|
if (size >= 1 * MiB) {
|
|
|
|
snprintf(size_buf, sizeof(size_buf), "%3" PRId64 "M", size / MiB);
|
|
|
|
} else {
|
|
|
|
snprintf(size_buf, sizeof(size_buf), "%3" PRId64 "k", size / KiB);
|
|
|
|
}
|
|
|
|
qemu_printf("0x%016" PRIx64 " 0x%016" PRIx64 " %s %-5u %08x %08x\n",
|
|
|
|
(uint64_t)ea, (uint64_t)pa, size_buf, (uint32_t)entry->PID,
|
|
|
|
entry->prot, entry->attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmubooke206_dump_one_tlb(CPUPPCState *env, int tlbn, int offset,
|
|
|
|
int tlbsize)
|
|
|
|
{
|
|
|
|
ppcmas_tlb_t *entry;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
qemu_printf("\nTLB%d:\n", tlbn);
|
|
|
|
qemu_printf("Effective Physical Size TID TS SRWX"
|
|
|
|
" URWX WIMGE U0123\n");
|
|
|
|
|
|
|
|
entry = &env->tlb.tlbm[offset];
|
|
|
|
for (i = 0; i < tlbsize; i++, entry++) {
|
|
|
|
hwaddr ea, pa, size;
|
|
|
|
int tsize;
|
|
|
|
|
|
|
|
if (!(entry->mas1 & MAS1_VALID)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsize = (entry->mas1 & MAS1_TSIZE_MASK) >> MAS1_TSIZE_SHIFT;
|
|
|
|
size = 1024ULL << tsize;
|
|
|
|
ea = entry->mas2 & ~(size - 1);
|
|
|
|
pa = entry->mas7_3 & ~(size - 1);
|
|
|
|
|
|
|
|
qemu_printf("0x%016" PRIx64 " 0x%016" PRIx64 " %4s %-5u %1u S%c%c%c"
|
2022-12-16 17:57:05 +03:00
|
|
|
" U%c%c%c %c%c%c%c%c U%c%c%c%c\n",
|
2021-07-23 20:56:25 +03:00
|
|
|
(uint64_t)ea, (uint64_t)pa,
|
|
|
|
book3e_tsize_to_str[tsize],
|
|
|
|
(entry->mas1 & MAS1_TID_MASK) >> MAS1_TID_SHIFT,
|
|
|
|
(entry->mas1 & MAS1_TS) >> MAS1_TS_SHIFT,
|
|
|
|
entry->mas7_3 & MAS3_SR ? 'R' : '-',
|
|
|
|
entry->mas7_3 & MAS3_SW ? 'W' : '-',
|
|
|
|
entry->mas7_3 & MAS3_SX ? 'X' : '-',
|
|
|
|
entry->mas7_3 & MAS3_UR ? 'R' : '-',
|
|
|
|
entry->mas7_3 & MAS3_UW ? 'W' : '-',
|
|
|
|
entry->mas7_3 & MAS3_UX ? 'X' : '-',
|
|
|
|
entry->mas2 & MAS2_W ? 'W' : '-',
|
|
|
|
entry->mas2 & MAS2_I ? 'I' : '-',
|
|
|
|
entry->mas2 & MAS2_M ? 'M' : '-',
|
|
|
|
entry->mas2 & MAS2_G ? 'G' : '-',
|
|
|
|
entry->mas2 & MAS2_E ? 'E' : '-',
|
|
|
|
entry->mas7_3 & MAS3_U0 ? '0' : '-',
|
|
|
|
entry->mas7_3 & MAS3_U1 ? '1' : '-',
|
|
|
|
entry->mas7_3 & MAS3_U2 ? '2' : '-',
|
|
|
|
entry->mas7_3 & MAS3_U3 ? '3' : '-');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmubooke206_dump_mmu(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
int offset = 0;
|
|
|
|
int i;
|
|
|
|
|
2023-04-04 12:14:58 +03:00
|
|
|
#ifdef CONFIG_KVM
|
2021-07-23 20:56:25 +03:00
|
|
|
if (kvm_enabled() && !env->kvm_sw_tlb) {
|
|
|
|
qemu_printf("Cannot access KVM TLB\n");
|
|
|
|
return;
|
|
|
|
}
|
2023-04-04 12:14:58 +03:00
|
|
|
#endif
|
2021-07-23 20:56:25 +03:00
|
|
|
|
|
|
|
for (i = 0; i < BOOKE206_MAX_TLBN; i++) {
|
|
|
|
int size = booke206_tlb_size(env, i);
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mmubooke206_dump_one_tlb(env, i, offset, size);
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmu6xx_dump_BATs(CPUPPCState *env, int type)
|
|
|
|
{
|
|
|
|
target_ulong *BATlt, *BATut, *BATu, *BATl;
|
|
|
|
target_ulong BEPIl, BEPIu, bl;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ACCESS_CODE:
|
|
|
|
BATlt = env->IBAT[1];
|
|
|
|
BATut = env->IBAT[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BATlt = env->DBAT[1];
|
|
|
|
BATut = env->DBAT[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < env->nb_BATs; i++) {
|
|
|
|
BATu = &BATut[i];
|
|
|
|
BATl = &BATlt[i];
|
2024-05-27 02:13:00 +03:00
|
|
|
BEPIu = *BATu & BATU32_BEPIU;
|
|
|
|
BEPIl = *BATu & BATU32_BEPIL;
|
|
|
|
bl = (*BATu & BATU32_BL) << 15;
|
2021-07-23 20:56:25 +03:00
|
|
|
qemu_printf("%s BAT%d BATu " TARGET_FMT_lx
|
|
|
|
" BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " "
|
|
|
|
TARGET_FMT_lx " " TARGET_FMT_lx "\n",
|
|
|
|
type == ACCESS_CODE ? "code" : "data", i,
|
|
|
|
*BATu, *BATl, BEPIu, BEPIl, bl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmu6xx_dump_mmu(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
PowerPCCPU *cpu = env_archcpu(env);
|
|
|
|
ppc6xx_tlb_t *tlb;
|
|
|
|
target_ulong sr;
|
|
|
|
int type, way, entry, i;
|
|
|
|
|
|
|
|
qemu_printf("HTAB base = 0x%"HWADDR_PRIx"\n", ppc_hash32_hpt_base(cpu));
|
|
|
|
qemu_printf("HTAB mask = 0x%"HWADDR_PRIx"\n", ppc_hash32_hpt_mask(cpu));
|
|
|
|
|
|
|
|
qemu_printf("\nSegment registers:\n");
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
sr = env->sr[i];
|
|
|
|
if (sr & 0x80000000) {
|
|
|
|
qemu_printf("%02d T=%d Ks=%d Kp=%d BUID=0x%03x "
|
|
|
|
"CNTLR_SPEC=0x%05x\n", i,
|
|
|
|
sr & 0x80000000 ? 1 : 0, sr & 0x40000000 ? 1 : 0,
|
|
|
|
sr & 0x20000000 ? 1 : 0, (uint32_t)((sr >> 20) & 0x1FF),
|
|
|
|
(uint32_t)(sr & 0xFFFFF));
|
|
|
|
} else {
|
|
|
|
qemu_printf("%02d T=%d Ks=%d Kp=%d N=%d VSID=0x%06x\n", i,
|
|
|
|
sr & 0x80000000 ? 1 : 0, sr & 0x40000000 ? 1 : 0,
|
|
|
|
sr & 0x20000000 ? 1 : 0, sr & 0x10000000 ? 1 : 0,
|
|
|
|
(uint32_t)(sr & 0x00FFFFFF));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_printf("\nBATs:\n");
|
|
|
|
mmu6xx_dump_BATs(env, ACCESS_INT);
|
|
|
|
mmu6xx_dump_BATs(env, ACCESS_CODE);
|
|
|
|
|
|
|
|
qemu_printf("\nTLBs [EPN EPN + SIZE]\n");
|
|
|
|
for (type = 0; type < 2; type++) {
|
|
|
|
for (way = 0; way < env->nb_ways; way++) {
|
|
|
|
for (entry = env->nb_tlb * type + env->tlb_per_way * way;
|
|
|
|
entry < (env->nb_tlb * type + env->tlb_per_way * (way + 1));
|
|
|
|
entry++) {
|
|
|
|
|
|
|
|
tlb = &env->tlb.tlb6[entry];
|
|
|
|
qemu_printf("%s TLB %02d/%02d way:%d %s ["
|
|
|
|
TARGET_FMT_lx " " TARGET_FMT_lx "]\n",
|
|
|
|
type ? "code" : "data", entry % env->nb_tlb,
|
|
|
|
env->nb_tlb, way,
|
|
|
|
pte_is_valid(tlb->pte0) ? "valid" : "inval",
|
|
|
|
tlb->EPN, tlb->EPN + TARGET_PAGE_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_mmu(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
switch (env->mmu_model) {
|
|
|
|
case POWERPC_MMU_BOOKE:
|
|
|
|
mmubooke_dump_mmu(env);
|
|
|
|
break;
|
|
|
|
case POWERPC_MMU_BOOKE206:
|
|
|
|
mmubooke206_dump_mmu(env);
|
|
|
|
break;
|
|
|
|
case POWERPC_MMU_SOFT_6xx:
|
|
|
|
mmu6xx_dump_mmu(env);
|
|
|
|
break;
|
|
|
|
#if defined(TARGET_PPC64)
|
|
|
|
case POWERPC_MMU_64B:
|
|
|
|
case POWERPC_MMU_2_03:
|
|
|
|
case POWERPC_MMU_2_06:
|
|
|
|
case POWERPC_MMU_2_07:
|
|
|
|
dump_slb(env_archcpu(env));
|
|
|
|
break;
|
|
|
|
case POWERPC_MMU_3_00:
|
|
|
|
if (ppc64_v3_radix(env_archcpu(env))) {
|
|
|
|
qemu_log_mask(LOG_UNIMP, "%s: the PPC64 MMU is unsupported\n",
|
|
|
|
__func__);
|
|
|
|
} else {
|
|
|
|
dump_slb(env_archcpu(env));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_UNIMP, "%s: unimplemented\n", __func__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-13 02:27:54 +03:00
|
|
|
|
2024-05-13 02:27:57 +03:00
|
|
|
static bool ppc_real_mode_xlate(PowerPCCPU *cpu, vaddr eaddr,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
hwaddr *raddrp, int *psizep, int *protp)
|
|
|
|
{
|
|
|
|
CPUPPCState *env = &cpu->env;
|
|
|
|
|
|
|
|
if (access_type == MMU_INST_FETCH ? !FIELD_EX64(env->msr, MSR, IR)
|
|
|
|
: !FIELD_EX64(env->msr, MSR, DR)) {
|
|
|
|
*raddrp = eaddr;
|
|
|
|
*protp = PAGE_RWX;
|
|
|
|
*psizep = TARGET_PAGE_BITS;
|
|
|
|
return true;
|
|
|
|
} else if (env->mmu_model == POWERPC_MMU_REAL) {
|
|
|
|
cpu_abort(CPU(cpu), "PowerPC in real mode shold not do translation\n");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-13 02:27:58 +03:00
|
|
|
static bool ppc_40x_xlate(PowerPCCPU *cpu, vaddr eaddr,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
hwaddr *raddrp, int *psizep, int *protp,
|
|
|
|
int mmu_idx, bool guest_visible)
|
|
|
|
{
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
CPUPPCState *env = &cpu->env;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (ppc_real_mode_xlate(cpu, eaddr, access_type, raddrp, psizep, protp)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = mmu40x_get_physical_address(env, raddrp, protp, eaddr, access_type);
|
|
|
|
if (ret == 0) {
|
|
|
|
*psizep = TARGET_PAGE_BITS;
|
|
|
|
return true;
|
|
|
|
} else if (!guest_visible) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_cpu_state_mask(CPU_LOG_MMU, cs, 0);
|
|
|
|
if (access_type == MMU_INST_FETCH) {
|
|
|
|
switch (ret) {
|
|
|
|
case -1:
|
|
|
|
/* No matches in page tables or TLB */
|
|
|
|
cs->exception_index = POWERPC_EXCP_ITLB;
|
|
|
|
env->error_code = 0;
|
|
|
|
env->spr[SPR_40x_DEAR] = eaddr;
|
|
|
|
env->spr[SPR_40x_ESR] = 0x00000000;
|
|
|
|
break;
|
|
|
|
case -2:
|
|
|
|
/* Access rights violation */
|
|
|
|
cs->exception_index = POWERPC_EXCP_ISI;
|
|
|
|
env->error_code = 0x08000000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (ret) {
|
|
|
|
case -1:
|
|
|
|
/* No matches in page tables or TLB */
|
|
|
|
cs->exception_index = POWERPC_EXCP_DTLB;
|
|
|
|
env->error_code = 0;
|
|
|
|
env->spr[SPR_40x_DEAR] = eaddr;
|
|
|
|
if (access_type == MMU_DATA_STORE) {
|
|
|
|
env->spr[SPR_40x_ESR] = 0x00800000;
|
|
|
|
} else {
|
|
|
|
env->spr[SPR_40x_ESR] = 0x00000000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -2:
|
|
|
|
/* Access rights violation */
|
|
|
|
cs->exception_index = POWERPC_EXCP_DSI;
|
|
|
|
env->error_code = 0;
|
|
|
|
env->spr[SPR_40x_DEAR] = eaddr;
|
|
|
|
if (access_type == MMU_DATA_STORE) {
|
|
|
|
env->spr[SPR_40x_ESR] |= 0x00800000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-13 02:27:59 +03:00
|
|
|
static bool ppc_6xx_xlate(PowerPCCPU *cpu, vaddr eaddr,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
hwaddr *raddrp, int *psizep, int *protp,
|
|
|
|
int mmu_idx, bool guest_visible)
|
2021-07-23 20:56:25 +03:00
|
|
|
{
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
CPUPPCState *env = &cpu->env;
|
2024-05-27 02:12:45 +03:00
|
|
|
hwaddr hash = 0; /* init to 0 to avoid used uninit warning */
|
2024-05-27 02:12:57 +03:00
|
|
|
bool key;
|
2024-05-27 02:12:45 +03:00
|
|
|
int type, ret;
|
2021-07-23 20:56:25 +03:00
|
|
|
|
2024-05-13 02:27:57 +03:00
|
|
|
if (ppc_real_mode_xlate(cpu, eaddr, access_type, raddrp, psizep, protp)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-23 20:56:25 +03:00
|
|
|
if (access_type == MMU_INST_FETCH) {
|
|
|
|
/* code access */
|
|
|
|
type = ACCESS_CODE;
|
|
|
|
} else if (guest_visible) {
|
|
|
|
/* data access */
|
|
|
|
type = env->access_type;
|
|
|
|
} else {
|
|
|
|
type = ACCESS_INT;
|
|
|
|
}
|
|
|
|
|
2024-05-27 02:13:03 +03:00
|
|
|
ret = mmu6xx_get_physical_address(env, raddrp, protp, eaddr, &hash, &key,
|
2024-05-27 02:12:45 +03:00
|
|
|
access_type, type);
|
2021-07-23 20:56:25 +03:00
|
|
|
if (ret == 0) {
|
|
|
|
*psizep = TARGET_PAGE_BITS;
|
|
|
|
return true;
|
2024-05-13 02:27:48 +03:00
|
|
|
} else if (!guest_visible) {
|
|
|
|
return false;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
|
2024-05-13 02:27:48 +03:00
|
|
|
log_cpu_state_mask(CPU_LOG_MMU, cs, 0);
|
|
|
|
if (type == ACCESS_CODE) {
|
|
|
|
switch (ret) {
|
|
|
|
case -1:
|
|
|
|
/* No matches in page tables or TLB */
|
2024-05-13 02:27:58 +03:00
|
|
|
cs->exception_index = POWERPC_EXCP_IFTLB;
|
|
|
|
env->error_code = 1 << 18;
|
|
|
|
env->spr[SPR_IMISS] = eaddr;
|
2024-05-27 02:12:53 +03:00
|
|
|
env->spr[SPR_ICMP] |= 0x80000000;
|
2024-05-13 02:27:58 +03:00
|
|
|
goto tlb_miss;
|
2024-05-13 02:27:48 +03:00
|
|
|
case -2:
|
|
|
|
/* Access rights violation */
|
|
|
|
cs->exception_index = POWERPC_EXCP_ISI;
|
2024-05-13 02:27:54 +03:00
|
|
|
env->error_code = 0x08000000;
|
2024-05-13 02:27:48 +03:00
|
|
|
break;
|
|
|
|
case -3:
|
|
|
|
/* No execute protection violation */
|
|
|
|
cs->exception_index = POWERPC_EXCP_ISI;
|
2024-05-13 02:27:54 +03:00
|
|
|
env->error_code = 0x10000000;
|
2024-05-13 02:27:48 +03:00
|
|
|
break;
|
|
|
|
case -4:
|
|
|
|
/* Direct store exception */
|
|
|
|
/* No code fetch is allowed in direct-store areas */
|
|
|
|
cs->exception_index = POWERPC_EXCP_ISI;
|
2024-05-13 02:27:53 +03:00
|
|
|
env->error_code = 0x10000000;
|
2024-05-13 02:27:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (ret) {
|
|
|
|
case -1:
|
|
|
|
/* No matches in page tables or TLB */
|
2024-05-13 02:27:58 +03:00
|
|
|
if (access_type == MMU_DATA_STORE) {
|
|
|
|
cs->exception_index = POWERPC_EXCP_DSTLB;
|
|
|
|
env->error_code = 1 << 16;
|
|
|
|
} else {
|
|
|
|
cs->exception_index = POWERPC_EXCP_DLTLB;
|
2024-05-13 02:27:48 +03:00
|
|
|
env->error_code = 0;
|
|
|
|
}
|
2024-05-13 02:27:58 +03:00
|
|
|
env->spr[SPR_DMISS] = eaddr;
|
2024-05-27 02:12:53 +03:00
|
|
|
env->spr[SPR_DCMP] |= 0x80000000;
|
2024-05-13 02:27:58 +03:00
|
|
|
tlb_miss:
|
2024-05-27 02:12:57 +03:00
|
|
|
env->error_code |= key << 19;
|
2024-05-13 02:27:58 +03:00
|
|
|
env->spr[SPR_HASH1] = ppc_hash32_hpt_base(cpu) +
|
2024-05-27 02:12:45 +03:00
|
|
|
get_pteg_offset32(cpu, hash);
|
2024-05-13 02:27:58 +03:00
|
|
|
env->spr[SPR_HASH2] = ppc_hash32_hpt_base(cpu) +
|
2024-05-27 02:12:45 +03:00
|
|
|
get_pteg_offset32(cpu, ~hash);
|
2024-05-13 02:27:48 +03:00
|
|
|
break;
|
|
|
|
case -2:
|
|
|
|
/* Access rights violation */
|
|
|
|
cs->exception_index = POWERPC_EXCP_DSI;
|
|
|
|
env->error_code = 0;
|
2024-05-13 02:27:58 +03:00
|
|
|
env->spr[SPR_DAR] = eaddr;
|
|
|
|
if (access_type == MMU_DATA_STORE) {
|
|
|
|
env->spr[SPR_DSISR] = 0x0A000000;
|
2024-05-13 02:27:48 +03:00
|
|
|
} else {
|
2024-05-13 02:27:58 +03:00
|
|
|
env->spr[SPR_DSISR] = 0x08000000;
|
2024-05-13 02:27:48 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -4:
|
|
|
|
/* Direct store exception */
|
|
|
|
switch (type) {
|
|
|
|
case ACCESS_FLOAT:
|
|
|
|
/* Floating point load/store */
|
|
|
|
cs->exception_index = POWERPC_EXCP_ALIGN;
|
|
|
|
env->error_code = POWERPC_EXCP_ALIGN_FP;
|
|
|
|
env->spr[SPR_DAR] = eaddr;
|
2021-07-23 20:56:25 +03:00
|
|
|
break;
|
2024-05-13 02:27:48 +03:00
|
|
|
case ACCESS_RES:
|
|
|
|
/* lwarx, ldarx or stwcx. */
|
2021-07-23 20:56:25 +03:00
|
|
|
cs->exception_index = POWERPC_EXCP_DSI;
|
|
|
|
env->error_code = 0;
|
2024-05-13 02:27:48 +03:00
|
|
|
env->spr[SPR_DAR] = eaddr;
|
|
|
|
if (access_type == MMU_DATA_STORE) {
|
|
|
|
env->spr[SPR_DSISR] = 0x06000000;
|
2021-07-23 20:56:25 +03:00
|
|
|
} else {
|
2024-05-13 02:27:48 +03:00
|
|
|
env->spr[SPR_DSISR] = 0x04000000;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
break;
|
2024-05-13 02:27:48 +03:00
|
|
|
case ACCESS_EXT:
|
|
|
|
/* eciwx or ecowx */
|
|
|
|
cs->exception_index = POWERPC_EXCP_DSI;
|
|
|
|
env->error_code = 0;
|
|
|
|
env->spr[SPR_DAR] = eaddr;
|
|
|
|
if (access_type == MMU_DATA_STORE) {
|
|
|
|
env->spr[SPR_DSISR] = 0x06100000;
|
|
|
|
} else {
|
|
|
|
env->spr[SPR_DSISR] = 0x04100000;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
break;
|
2024-05-13 02:27:48 +03:00
|
|
|
default:
|
|
|
|
printf("DSI: invalid exception (%d)\n", ret);
|
|
|
|
cs->exception_index = POWERPC_EXCP_PROGRAM;
|
|
|
|
env->error_code = POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL;
|
|
|
|
env->spr[SPR_DAR] = eaddr;
|
|
|
|
break;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
2024-05-13 02:27:48 +03:00
|
|
|
break;
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
bool ppc_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
|
|
|
|
hwaddr *raddrp, int *psizep, int *protp,
|
|
|
|
int mmu_idx, bool guest_visible)
|
|
|
|
{
|
|
|
|
switch (cpu->env.mmu_model) {
|
|
|
|
#if defined(TARGET_PPC64)
|
|
|
|
case POWERPC_MMU_3_00:
|
|
|
|
if (ppc64_v3_radix(cpu)) {
|
|
|
|
return ppc_radix64_xlate(cpu, eaddr, access_type, raddrp,
|
|
|
|
psizep, protp, mmu_idx, guest_visible);
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case POWERPC_MMU_64B:
|
|
|
|
case POWERPC_MMU_2_03:
|
|
|
|
case POWERPC_MMU_2_06:
|
|
|
|
case POWERPC_MMU_2_07:
|
|
|
|
return ppc_hash64_xlate(cpu, eaddr, access_type,
|
|
|
|
raddrp, psizep, protp, mmu_idx, guest_visible);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case POWERPC_MMU_32B:
|
|
|
|
return ppc_hash32_xlate(cpu, eaddr, access_type, raddrp,
|
2024-05-13 02:27:54 +03:00
|
|
|
psizep, protp, mmu_idx, guest_visible);
|
|
|
|
case POWERPC_MMU_BOOKE:
|
|
|
|
case POWERPC_MMU_BOOKE206:
|
|
|
|
return ppc_booke_xlate(cpu, eaddr, access_type, raddrp,
|
2021-07-23 20:56:25 +03:00
|
|
|
psizep, protp, mmu_idx, guest_visible);
|
2024-05-13 02:27:58 +03:00
|
|
|
case POWERPC_MMU_SOFT_4xx:
|
|
|
|
return ppc_40x_xlate(cpu, eaddr, access_type, raddrp,
|
|
|
|
psizep, protp, mmu_idx, guest_visible);
|
2024-05-13 02:27:59 +03:00
|
|
|
case POWERPC_MMU_SOFT_6xx:
|
|
|
|
return ppc_6xx_xlate(cpu, eaddr, access_type, raddrp,
|
|
|
|
psizep, protp, mmu_idx, guest_visible);
|
2024-05-13 02:27:57 +03:00
|
|
|
case POWERPC_MMU_REAL:
|
|
|
|
return ppc_real_mode_xlate(cpu, eaddr, access_type, raddrp, psizep,
|
|
|
|
protp);
|
2024-05-13 02:27:38 +03:00
|
|
|
case POWERPC_MMU_MPC8xx:
|
|
|
|
cpu_abort(env_cpu(&cpu->env), "MPC8xx MMU model is not implemented\n");
|
2021-07-23 20:56:25 +03:00
|
|
|
default:
|
2024-05-13 02:27:59 +03:00
|
|
|
cpu_abort(CPU(cpu), "Unknown or invalid MMU model\n");
|
2021-07-23 20:56:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hwaddr ppc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
|
|
|
|
{
|
|
|
|
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
|
|
|
hwaddr raddr;
|
|
|
|
int s, p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some MMUs have separate TLBs for code and data. If we only
|
|
|
|
* try an MMU_DATA_LOAD, we may not be able to read instructions
|
|
|
|
* mapped by code TLBs, so we also try a MMU_INST_FETCH.
|
|
|
|
*/
|
|
|
|
if (ppc_xlate(cpu, addr, MMU_DATA_LOAD, &raddr, &s, &p,
|
2024-01-29 03:18:33 +03:00
|
|
|
ppc_env_mmu_index(&cpu->env, false), false) ||
|
2021-07-23 20:56:25 +03:00
|
|
|
ppc_xlate(cpu, addr, MMU_INST_FETCH, &raddr, &s, &p,
|
2024-01-29 03:18:33 +03:00
|
|
|
ppc_env_mmu_index(&cpu->env, true), false)) {
|
2021-07-23 20:56:25 +03:00
|
|
|
return raddr & TARGET_PAGE_MASK;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|