target-ppc: Disentangle pte_check()
Currently support for both 32-bit and 64-bit hash MMUs share an implementation of pte_check. But there are enough differences that this means the shared function has several very ugly conditionals on "is_64b". This patch cleans things up by separating out the 64-bit version (putting it into mmu-hash64.c) and the 32-bit hash version (putting it in mmu-hash32.c). Another copy remains in mmu_helper.c, which is used for the 6xx software loaded TLB paths. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
10b4652543
commit
9d7c3f4a29
|
@ -1,7 +1,7 @@
|
||||||
obj-y += cpu-models.o
|
obj-y += cpu-models.o
|
||||||
obj-y += translate.o
|
obj-y += translate.o
|
||||||
ifeq ($(CONFIG_SOFTMMU),y)
|
ifeq ($(CONFIG_SOFTMMU),y)
|
||||||
obj-y += machine.o
|
obj-y += machine.o mmu-hash32.o
|
||||||
obj-$(TARGET_PPC64) += mmu-hash64.o
|
obj-$(TARGET_PPC64) += mmu-hash64.o
|
||||||
endif
|
endif
|
||||||
obj-$(CONFIG_KVM) += kvm.o kvm_ppc.o
|
obj-$(CONFIG_KVM) += kvm.o kvm_ppc.o
|
||||||
|
|
|
@ -1133,6 +1133,8 @@ void ppc_hw_interrupt (CPUPPCState *env);
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
void ppc_store_sdr1 (CPUPPCState *env, target_ulong value);
|
void ppc_store_sdr1 (CPUPPCState *env, target_ulong value);
|
||||||
|
int pp_check(int key, int pp, int nx);
|
||||||
|
int check_prot(int prot, int rw, int access_type);
|
||||||
#endif /* !defined(CONFIG_USER_ONLY) */
|
#endif /* !defined(CONFIG_USER_ONLY) */
|
||||||
void ppc_store_msr (CPUPPCState *env, target_ulong value);
|
void ppc_store_msr (CPUPPCState *env, target_ulong value);
|
||||||
|
|
||||||
|
|
85
target-ppc/mmu-hash32.c
Normal file
85
target-ppc/mmu-hash32.c
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* PowerPC MMU, TLB and BAT emulation helpers for QEMU.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003-2007 Jocelyn Mayer
|
||||||
|
* Copyright (c) 2013 David Gibson, IBM Corporation
|
||||||
|
*
|
||||||
|
* 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 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 "cpu.h"
|
||||||
|
#include "helper.h"
|
||||||
|
#include "sysemu/kvm.h"
|
||||||
|
#include "kvm_ppc.h"
|
||||||
|
#include "mmu-hash32.h"
|
||||||
|
|
||||||
|
//#define DEBUG_MMU
|
||||||
|
|
||||||
|
#ifdef DEBUG_MMU
|
||||||
|
# define LOG_MMU(...) qemu_log(__VA_ARGS__)
|
||||||
|
# define LOG_MMU_STATE(env) log_cpu_state((env), 0)
|
||||||
|
#else
|
||||||
|
# define LOG_MMU(...) do { } while (0)
|
||||||
|
# define LOG_MMU_STATE(...) do { } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PTE_PTEM_MASK 0x7FFFFFBF
|
||||||
|
#define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B)
|
||||||
|
|
||||||
|
static inline int pte_is_valid_hash32(target_ulong pte0)
|
||||||
|
{
|
||||||
|
return pte0 & 0x80000000 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pte_check_hash32(mmu_ctx_t *ctx, target_ulong pte0,
|
||||||
|
target_ulong pte1, int h, int rw, int type)
|
||||||
|
{
|
||||||
|
target_ulong ptem, mmask;
|
||||||
|
int access, ret, pteh, ptev, pp;
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
|
/* Check validity and table match */
|
||||||
|
ptev = pte_is_valid_hash32(pte0);
|
||||||
|
pteh = (pte0 >> 6) & 1;
|
||||||
|
if (ptev && h == pteh) {
|
||||||
|
/* Check vsid & api */
|
||||||
|
ptem = pte0 & PTE_PTEM_MASK;
|
||||||
|
mmask = PTE_CHECK_MASK;
|
||||||
|
pp = pte1 & 0x00000003;
|
||||||
|
if (ptem == ctx->ptem) {
|
||||||
|
if (ctx->raddr != (hwaddr)-1ULL) {
|
||||||
|
/* all matches should have equal RPN, WIMG & PP */
|
||||||
|
if ((ctx->raddr & mmask) != (pte1 & mmask)) {
|
||||||
|
qemu_log("Bad RPN/WIMG/PP\n");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Compute access rights */
|
||||||
|
access = pp_check(ctx->key, pp, ctx->nx);
|
||||||
|
/* Keep the matching PTE informations */
|
||||||
|
ctx->raddr = pte1;
|
||||||
|
ctx->prot = access;
|
||||||
|
ret = check_prot(ctx->prot, rw, type);
|
||||||
|
if (ret == 0) {
|
||||||
|
/* Access granted */
|
||||||
|
LOG_MMU("PTE access granted !\n");
|
||||||
|
} else {
|
||||||
|
/* Access right violation */
|
||||||
|
LOG_MMU("PTE access rejected\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
12
target-ppc/mmu-hash32.h
Normal file
12
target-ppc/mmu-hash32.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#if !defined (__MMU_HASH32_H__)
|
||||||
|
#define __MMU_HASH32_H__
|
||||||
|
|
||||||
|
#ifndef CONFIG_USER_ONLY
|
||||||
|
|
||||||
|
int pte32_is_valid(target_ulong pte0);
|
||||||
|
int pte_check_hash32(mmu_ctx_t *ctx, target_ulong pte0,
|
||||||
|
target_ulong pte1, int h, int rw, int type);
|
||||||
|
|
||||||
|
#endif /* CONFIG_USER_ONLY */
|
||||||
|
|
||||||
|
#endif /* __MMU_HASH32_H__ */
|
|
@ -23,8 +23,17 @@
|
||||||
#include "kvm_ppc.h"
|
#include "kvm_ppc.h"
|
||||||
#include "mmu-hash64.h"
|
#include "mmu-hash64.h"
|
||||||
|
|
||||||
|
//#define DEBUG_MMU
|
||||||
//#define DEBUG_SLB
|
//#define DEBUG_SLB
|
||||||
|
|
||||||
|
#ifdef DEBUG_MMU
|
||||||
|
# define LOG_MMU(...) qemu_log(__VA_ARGS__)
|
||||||
|
# define LOG_MMU_STATE(env) log_cpu_state((env), 0)
|
||||||
|
#else
|
||||||
|
# define LOG_MMU(...) do { } while (0)
|
||||||
|
# define LOG_MMU_STATE(...) do { } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_SLB
|
#ifdef DEBUG_SLB
|
||||||
# define LOG_SLB(...) qemu_log(__VA_ARGS__)
|
# define LOG_SLB(...) qemu_log(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
|
@ -209,3 +218,59 @@ target_ulong helper_load_slb_vsid(CPUPPCState *env, target_ulong rb)
|
||||||
}
|
}
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 64-bit hash table MMU handling
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define PTE64_PTEM_MASK 0xFFFFFFFFFFFFFF80ULL
|
||||||
|
#define PTE64_CHECK_MASK (TARGET_PAGE_MASK | 0x7F)
|
||||||
|
|
||||||
|
static inline int pte64_is_valid(target_ulong pte0)
|
||||||
|
{
|
||||||
|
return pte0 & 0x0000000000000001ULL ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pte64_check(mmu_ctx_t *ctx, target_ulong pte0,
|
||||||
|
target_ulong pte1, int h, int rw, int type)
|
||||||
|
{
|
||||||
|
target_ulong ptem, mmask;
|
||||||
|
int access, ret, pteh, ptev, pp;
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
|
/* Check validity and table match */
|
||||||
|
ptev = pte64_is_valid(pte0);
|
||||||
|
pteh = (pte0 >> 1) & 1;
|
||||||
|
if (ptev && h == pteh) {
|
||||||
|
/* Check vsid & api */
|
||||||
|
ptem = pte0 & PTE64_PTEM_MASK;
|
||||||
|
mmask = PTE64_CHECK_MASK;
|
||||||
|
pp = (pte1 & 0x00000003) | ((pte1 >> 61) & 0x00000004);
|
||||||
|
ctx->nx = (pte1 >> 2) & 1; /* No execute bit */
|
||||||
|
ctx->nx |= (pte1 >> 3) & 1; /* Guarded bit */
|
||||||
|
if (ptem == ctx->ptem) {
|
||||||
|
if (ctx->raddr != (hwaddr)-1ULL) {
|
||||||
|
/* all matches should have equal RPN, WIMG & PP */
|
||||||
|
if ((ctx->raddr & mmask) != (pte1 & mmask)) {
|
||||||
|
qemu_log("Bad RPN/WIMG/PP\n");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Compute access rights */
|
||||||
|
access = pp_check(ctx->key, pp, ctx->nx);
|
||||||
|
/* Keep the matching PTE informations */
|
||||||
|
ctx->raddr = pte1;
|
||||||
|
ctx->prot = access;
|
||||||
|
ret = check_prot(ctx->prot, rw, type);
|
||||||
|
if (ret == 0) {
|
||||||
|
/* Access granted */
|
||||||
|
LOG_MMU("PTE access granted !\n");
|
||||||
|
} else {
|
||||||
|
/* Access right violation */
|
||||||
|
LOG_MMU("PTE access rejected\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
ppc_slb_t *slb_lookup(CPUPPCState *env, target_ulong eaddr);
|
ppc_slb_t *slb_lookup(CPUPPCState *env, target_ulong eaddr);
|
||||||
void dump_slb(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env);
|
void dump_slb(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env);
|
||||||
int ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs);
|
int ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs);
|
||||||
|
int pte64_check(mmu_ctx_t *ctx, target_ulong pte0,
|
||||||
|
target_ulong pte1, int h, int rw, int type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_USER_ONLY */
|
#endif /* CONFIG_USER_ONLY */
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "sysemu/kvm.h"
|
#include "sysemu/kvm.h"
|
||||||
#include "kvm_ppc.h"
|
#include "kvm_ppc.h"
|
||||||
#include "mmu-hash64.h"
|
#include "mmu-hash64.h"
|
||||||
|
#include "mmu-hash32.h"
|
||||||
|
|
||||||
//#define DEBUG_MMU
|
//#define DEBUG_MMU
|
||||||
//#define DEBUG_BATS
|
//#define DEBUG_BATS
|
||||||
|
@ -87,21 +88,10 @@ static inline void pte_invalidate(target_ulong *pte0)
|
||||||
*pte0 &= ~0x80000000;
|
*pte0 &= ~0x80000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TARGET_PPC64)
|
|
||||||
static inline int pte64_is_valid(target_ulong pte0)
|
|
||||||
{
|
|
||||||
return pte0 & 0x0000000000000001ULL ? 1 : 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PTE_PTEM_MASK 0x7FFFFFBF
|
#define PTE_PTEM_MASK 0x7FFFFFBF
|
||||||
#define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B)
|
#define PTE_CHECK_MASK (TARGET_PAGE_MASK | 0x7B)
|
||||||
#if defined(TARGET_PPC64)
|
|
||||||
#define PTE64_PTEM_MASK 0xFFFFFFFFFFFFFF80ULL
|
|
||||||
#define PTE64_CHECK_MASK (TARGET_PAGE_MASK | 0x7F)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int pp_check(int key, int pp, int nx)
|
int pp_check(int key, int pp, int nx)
|
||||||
{
|
{
|
||||||
int access;
|
int access;
|
||||||
|
|
||||||
|
@ -142,7 +132,7 @@ static inline int pp_check(int key, int pp, int nx)
|
||||||
return access;
|
return access;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int check_prot(int prot, int rw, int access_type)
|
int check_prot(int prot, int rw, int access_type)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -169,7 +159,7 @@ static inline int check_prot(int prot, int rw, int access_type)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int pte_check(mmu_ctx_t *ctx, int is_64b, target_ulong pte0,
|
static inline int ppc6xx_tlb_pte_check(mmu_ctx_t *ctx, target_ulong pte0,
|
||||||
target_ulong pte1, int h, int rw, int type)
|
target_ulong pte1, int h, int rw, int type)
|
||||||
{
|
{
|
||||||
target_ulong ptem, mmask;
|
target_ulong ptem, mmask;
|
||||||
|
@ -177,32 +167,13 @@ static inline int pte_check(mmu_ctx_t *ctx, int is_64b, target_ulong pte0,
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
/* Check validity and table match */
|
/* Check validity and table match */
|
||||||
#if defined(TARGET_PPC64)
|
|
||||||
if (is_64b) {
|
|
||||||
ptev = pte64_is_valid(pte0);
|
|
||||||
pteh = (pte0 >> 1) & 1;
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
ptev = pte_is_valid(pte0);
|
ptev = pte_is_valid(pte0);
|
||||||
pteh = (pte0 >> 6) & 1;
|
pteh = (pte0 >> 6) & 1;
|
||||||
}
|
|
||||||
if (ptev && h == pteh) {
|
if (ptev && h == pteh) {
|
||||||
/* Check vsid & api */
|
/* Check vsid & api */
|
||||||
#if defined(TARGET_PPC64)
|
|
||||||
if (is_64b) {
|
|
||||||
ptem = pte0 & PTE64_PTEM_MASK;
|
|
||||||
mmask = PTE64_CHECK_MASK;
|
|
||||||
pp = (pte1 & 0x00000003) | ((pte1 >> 61) & 0x00000004);
|
|
||||||
ctx->nx = (pte1 >> 2) & 1; /* No execute bit */
|
|
||||||
ctx->nx |= (pte1 >> 3) & 1; /* Guarded bit */
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
ptem = pte0 & PTE_PTEM_MASK;
|
ptem = pte0 & PTE_PTEM_MASK;
|
||||||
mmask = PTE_CHECK_MASK;
|
mmask = PTE_CHECK_MASK;
|
||||||
pp = pte1 & 0x00000003;
|
pp = pte1 & 0x00000003;
|
||||||
}
|
|
||||||
if (ptem == ctx->ptem) {
|
if (ptem == ctx->ptem) {
|
||||||
if (ctx->raddr != (hwaddr)-1ULL) {
|
if (ctx->raddr != (hwaddr)-1ULL) {
|
||||||
/* all matches should have equal RPN, WIMG & PP */
|
/* all matches should have equal RPN, WIMG & PP */
|
||||||
|
@ -230,20 +201,6 @@ static inline int pte_check(mmu_ctx_t *ctx, int is_64b, target_ulong pte0,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int pte32_check(mmu_ctx_t *ctx, target_ulong pte0,
|
|
||||||
target_ulong pte1, int h, int rw, int type)
|
|
||||||
{
|
|
||||||
return pte_check(ctx, 0, pte0, pte1, h, rw, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(TARGET_PPC64)
|
|
||||||
static inline int pte64_check(mmu_ctx_t *ctx, target_ulong pte0,
|
|
||||||
target_ulong pte1, int h, int rw, int type)
|
|
||||||
{
|
|
||||||
return pte_check(ctx, 1, pte0, pte1, h, rw, type);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int pte_update_flags(mmu_ctx_t *ctx, target_ulong *pte1p,
|
static inline int pte_update_flags(mmu_ctx_t *ctx, target_ulong *pte1p,
|
||||||
int ret, int rw)
|
int ret, int rw)
|
||||||
{
|
{
|
||||||
|
@ -381,7 +338,7 @@ static inline int ppc6xx_tlb_check(CPUPPCState *env, mmu_ctx_t *ctx,
|
||||||
pte_is_valid(tlb->pte0) ? "valid" : "inval",
|
pte_is_valid(tlb->pte0) ? "valid" : "inval",
|
||||||
tlb->EPN, eaddr, tlb->pte1,
|
tlb->EPN, eaddr, tlb->pte1,
|
||||||
rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D');
|
rw ? 'S' : 'L', access_type == ACCESS_CODE ? 'I' : 'D');
|
||||||
switch (pte32_check(ctx, tlb->pte0, tlb->pte1, 0, rw, access_type)) {
|
switch (ppc6xx_tlb_pte_check(ctx, tlb->pte0, tlb->pte1, 0, rw, access_type)) {
|
||||||
case -3:
|
case -3:
|
||||||
/* TLB inconsistency */
|
/* TLB inconsistency */
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -590,7 +547,7 @@ static inline int find_pte2(CPUPPCState *env, mmu_ctx_t *ctx, int is_64b, int h,
|
||||||
pte0 = ldl_phys(env->htab_base + pteg_off + (i * 8));
|
pte0 = ldl_phys(env->htab_base + pteg_off + (i * 8));
|
||||||
pte1 = ldl_phys(env->htab_base + pteg_off + (i * 8) + 4);
|
pte1 = ldl_phys(env->htab_base + pteg_off + (i * 8) + 4);
|
||||||
}
|
}
|
||||||
r = pte32_check(ctx, pte0, pte1, h, rw, type);
|
r = pte_check_hash32(ctx, pte0, pte1, h, rw, type);
|
||||||
LOG_MMU("Load pte from %08" HWADDR_PRIx " => " TARGET_FMT_lx " "
|
LOG_MMU("Load pte from %08" HWADDR_PRIx " => " TARGET_FMT_lx " "
|
||||||
TARGET_FMT_lx " %d %d %d " TARGET_FMT_lx "\n",
|
TARGET_FMT_lx " %d %d %d " TARGET_FMT_lx "\n",
|
||||||
pteg_off + (i * 8), pte0, pte1, (int)(pte0 >> 31), h,
|
pteg_off + (i * 8), pte0, pte1, (int)(pte0 >> 31), h,
|
||||||
|
|
Loading…
Reference in a new issue