提交 bb593904 编写于 作者: D David Gibson 提交者: Alexander Graf

Parse SDR1 on mtspr instead of at translate time

On ppc machines with hash table MMUs, the special purpose register SDR1
contains both the base address of the encoded size (hashed) page tables.

At present, we interpret the SDR1 value within the address translation
path.  But because the encodings of the size for 32-bit and 64-bit are
different this makes for a confusing branch on the MMU type with a bunch
of curly shifts and masks in the middle of the translate path.

This patch cleans things up by moving the interpretation on SDR1 into the
helper function handling the write to the register.  This leaves a simple
pre-sanitized base address and mask for the hash table in the CPUState
structure which is easier to work with in the translation path.

This makes the translation path more readable.  It addresses the FIXME
comment currently in the mtsdr1 helper, by validating the SDR1 value during
interpretation.  Finally it opens the way for emulating a pSeries-style
partition where the hash table used for translation is not mapped into
the guests's RAM.
Signed-off-by: NDavid Gibson <dwg@au1.ibm.com>
Signed-off-by: NAlexander Graf <agraf@suse.de>
上级 8500e3a9
...@@ -3462,7 +3462,7 @@ static const MonitorDef monitor_defs[] = { ...@@ -3462,7 +3462,7 @@ static const MonitorDef monitor_defs[] = {
{ "asr", offsetof(CPUState, asr) }, { "asr", offsetof(CPUState, asr) },
#endif #endif
/* Segment registers */ /* Segment registers */
{ "sdr1", offsetof(CPUState, sdr1) }, { "sdr1", offsetof(CPUState, spr[SPR_SDR1]) },
{ "sr0", offsetof(CPUState, sr[0]) }, { "sr0", offsetof(CPUState, sr[0]) },
{ "sr1", offsetof(CPUState, sr[1]) }, { "sr1", offsetof(CPUState, sr[1]) },
{ "sr2", offsetof(CPUState, sr[2]) }, { "sr2", offsetof(CPUState, sr[2]) },
......
...@@ -359,6 +359,14 @@ union ppc_tlb_t { ...@@ -359,6 +359,14 @@ union ppc_tlb_t {
}; };
#endif #endif
#define SDR_32_HTABORG 0xFFFF0000UL
#define SDR_32_HTABMASK 0x000001FFUL
#if defined(TARGET_PPC64)
#define SDR_64_HTABORG 0xFFFFFFFFFFFC0000ULL
#define SDR_64_HTABSIZE 0x000000000000001FULL
#endif /* defined(TARGET_PPC64 */
typedef struct ppc_slb_t ppc_slb_t; typedef struct ppc_slb_t ppc_slb_t;
struct ppc_slb_t { struct ppc_slb_t {
uint64_t esid; uint64_t esid;
...@@ -642,7 +650,8 @@ struct CPUPPCState { ...@@ -642,7 +650,8 @@ struct CPUPPCState {
int slb_nr; int slb_nr;
#endif #endif
/* segment registers */ /* segment registers */
target_ulong sdr1; target_phys_addr_t htab_base;
target_phys_addr_t htab_mask;
target_ulong sr[32]; target_ulong sr[32];
/* BATs */ /* BATs */
int nb_BATs; int nb_BATs;
......
...@@ -788,20 +788,19 @@ int ppc_load_slb_vsid (CPUPPCState *env, target_ulong rb, target_ulong *rt) ...@@ -788,20 +788,19 @@ int ppc_load_slb_vsid (CPUPPCState *env, target_ulong rb, target_ulong *rt)
#endif /* defined(TARGET_PPC64) */ #endif /* defined(TARGET_PPC64) */
/* Perform segment based translation */ /* Perform segment based translation */
static inline target_phys_addr_t get_pgaddr(target_phys_addr_t sdr1, static inline target_phys_addr_t get_pgaddr(target_phys_addr_t htab_base,
int sdr_sh, target_phys_addr_t htab_mask,
target_phys_addr_t hash, target_phys_addr_t hash)
target_phys_addr_t mask)
{ {
return (sdr1 & ((target_phys_addr_t)(-1ULL) << sdr_sh)) | (hash & mask); return htab_base | (hash & htab_mask);
} }
static inline int get_segment(CPUState *env, mmu_ctx_t *ctx, static inline int get_segment(CPUState *env, mmu_ctx_t *ctx,
target_ulong eaddr, int rw, int type) target_ulong eaddr, int rw, int type)
{ {
target_phys_addr_t sdr, hash, mask, sdr_mask, htab_mask; target_phys_addr_t hash;
target_ulong sr, vsid, vsid_mask, pgidx, page_mask; target_ulong sr, vsid, vsid_mask, pgidx, page_mask;
int ds, vsid_sh, sdr_sh, pr, target_page_bits; int ds, vsid_sh, pr, target_page_bits;
int ret, ret2; int ret, ret2;
pr = msr_pr; pr = msr_pr;
...@@ -826,8 +825,6 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx, ...@@ -826,8 +825,6 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx,
ctx->eaddr = eaddr; ctx->eaddr = eaddr;
vsid_mask = 0x00003FFFFFFFFF80ULL; vsid_mask = 0x00003FFFFFFFFF80ULL;
vsid_sh = 7; vsid_sh = 7;
sdr_sh = 18;
sdr_mask = 0x3FF80;
} else } else
#endif /* defined(TARGET_PPC64) */ #endif /* defined(TARGET_PPC64) */
{ {
...@@ -840,8 +837,6 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx, ...@@ -840,8 +837,6 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx,
vsid = sr & 0x00FFFFFF; vsid = sr & 0x00FFFFFF;
vsid_mask = 0x01FFFFC0; vsid_mask = 0x01FFFFC0;
vsid_sh = 6; vsid_sh = 6;
sdr_sh = 16;
sdr_mask = 0xFFC0;
target_page_bits = TARGET_PAGE_BITS; target_page_bits = TARGET_PAGE_BITS;
LOG_MMU("Check segment v=" TARGET_FMT_lx " %d " TARGET_FMT_lx " nip=" LOG_MMU("Check segment v=" TARGET_FMT_lx " %d " TARGET_FMT_lx " nip="
TARGET_FMT_lx " lr=" TARGET_FMT_lx TARGET_FMT_lx " lr=" TARGET_FMT_lx
...@@ -857,29 +852,26 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx, ...@@ -857,29 +852,26 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx,
if (type != ACCESS_CODE || ctx->nx == 0) { if (type != ACCESS_CODE || ctx->nx == 0) {
/* Page address translation */ /* Page address translation */
/* Primary table address */ /* Primary table address */
sdr = env->sdr1;
pgidx = (eaddr & page_mask) >> target_page_bits; pgidx = (eaddr & page_mask) >> target_page_bits;
#if defined(TARGET_PPC64) #if defined(TARGET_PPC64)
if (env->mmu_model & POWERPC_MMU_64) { if (env->mmu_model & POWERPC_MMU_64) {
htab_mask = 0x0FFFFFFF >> (28 - (sdr & 0x1F));
/* XXX: this is false for 1 TB segments */ /* XXX: this is false for 1 TB segments */
hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask; hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask;
} else } else
#endif #endif
{ {
htab_mask = sdr & 0x000001FF;
hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask; hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask;
} }
mask = (htab_mask << sdr_sh) | sdr_mask; LOG_MMU("htab_base " TARGET_FMT_plx " htab_mask " TARGET_FMT_plx
LOG_MMU("sdr " TARGET_FMT_plx " sh %d hash " TARGET_FMT_plx " hash " TARGET_FMT_plx "\n",
" mask " TARGET_FMT_plx " " TARGET_FMT_lx "\n", env->htab_base, env->htab_mask, hash);
sdr, sdr_sh, hash, mask, page_mask); ctx->pg_addr[0] = get_pgaddr(env->htab_base, env->htab_mask, hash);
ctx->pg_addr[0] = get_pgaddr(sdr, sdr_sh, hash, mask);
/* Secondary table address */ /* Secondary table address */
hash = (~hash) & vsid_mask; hash = (~hash) & vsid_mask;
LOG_MMU("sdr " TARGET_FMT_plx " sh %d hash " TARGET_FMT_plx LOG_MMU("htab_base " TARGET_FMT_plx " htab_mask " TARGET_FMT_plx
" mask " TARGET_FMT_plx "\n", sdr, sdr_sh, hash, mask); " hash " TARGET_FMT_plx "\n",
ctx->pg_addr[1] = get_pgaddr(sdr, sdr_sh, hash, mask); env->htab_base, env->htab_mask, hash);
ctx->pg_addr[1] = get_pgaddr(env->htab_base, env->htab_mask, hash);
#if defined(TARGET_PPC64) #if defined(TARGET_PPC64)
if (env->mmu_model & POWERPC_MMU_64) { if (env->mmu_model & POWERPC_MMU_64) {
/* Only 5 bits of the page index are used in the AVPN */ /* Only 5 bits of the page index are used in the AVPN */
...@@ -901,19 +893,22 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx, ...@@ -901,19 +893,22 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx,
/* Software TLB search */ /* Software TLB search */
ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type); ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type);
} else { } else {
LOG_MMU("0 sdr1=" TARGET_FMT_plx " vsid=" TARGET_FMT_lx " " LOG_MMU("0 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx
"api=" TARGET_FMT_lx " hash=" TARGET_FMT_plx " vsid=" TARGET_FMT_lx " api=" TARGET_FMT_lx
" pg_addr=" TARGET_FMT_plx "\n", " hash=" TARGET_FMT_plx " pg_addr=" TARGET_FMT_plx "\n",
sdr, vsid, pgidx, hash, ctx->pg_addr[0]); env->htab_base, env->htab_mask, vsid, pgidx, hash,
ctx->pg_addr[0]);
/* Primary table lookup */ /* Primary table lookup */
ret = find_pte(env, ctx, 0, rw, type, target_page_bits); ret = find_pte(env, ctx, 0, rw, type, target_page_bits);
if (ret < 0) { if (ret < 0) {
/* Secondary table lookup */ /* Secondary table lookup */
if (eaddr != 0xEFFFFFFF) if (eaddr != 0xEFFFFFFF)
LOG_MMU("1 sdr1=" TARGET_FMT_plx " vsid=" TARGET_FMT_lx " " LOG_MMU("1 htab=" TARGET_FMT_plx "/" TARGET_FMT_plx
"api=" TARGET_FMT_lx " hash=" TARGET_FMT_plx " vsid=" TARGET_FMT_lx " api=" TARGET_FMT_lx
" pg_addr=" TARGET_FMT_plx "\n", sdr, vsid, " hash=" TARGET_FMT_plx " pg_addr="
pgidx, hash, ctx->pg_addr[1]); TARGET_FMT_plx "\n", env->htab_base,
env->htab_mask, vsid, pgidx, hash,
ctx->pg_addr[1]);
ret2 = find_pte(env, ctx, 1, rw, type, ret2 = find_pte(env, ctx, 1, rw, type,
target_page_bits); target_page_bits);
if (ret2 != -1) if (ret2 != -1)
...@@ -1919,11 +1914,26 @@ void ppc_store_asr (CPUPPCState *env, target_ulong value) ...@@ -1919,11 +1914,26 @@ void ppc_store_asr (CPUPPCState *env, target_ulong value)
void ppc_store_sdr1 (CPUPPCState *env, target_ulong value) void ppc_store_sdr1 (CPUPPCState *env, target_ulong value)
{ {
LOG_MMU("%s: " TARGET_FMT_lx "\n", __func__, value); LOG_MMU("%s: " TARGET_FMT_lx "\n", __func__, value);
if (env->sdr1 != value) { if (env->spr[SPR_SDR1] != value) {
/* XXX: for PowerPC 64, should check that the HTABSIZE value env->spr[SPR_SDR1] = value;
* is <= 28 #if defined(TARGET_PPC64)
*/ if (env->mmu_model & POWERPC_MMU_64) {
env->sdr1 = value; target_ulong htabsize = value & SDR_64_HTABSIZE;
if (htabsize > 28) {
fprintf(stderr, "Invalid HTABSIZE 0x" TARGET_FMT_lx
" stored in SDR1\n", htabsize);
htabsize = 28;
}
env->htab_mask = (1ULL << (htabsize + 18)) - 1;
env->htab_base = value & SDR_64_HTABORG;
} else
#endif /* defined(TARGET_PPC64) */
{
/* FIXME: Should check for valid HTABMASK values */
env->htab_mask = ((value & SDR_32_HTABMASK) << 16) | 0xFFFF;
env->htab_base = value & SDR_32_HTABORG;
}
tlb_flush(env, 1); tlb_flush(env, 1);
} }
} }
......
...@@ -169,7 +169,7 @@ int kvm_arch_get_registers(CPUState *env) ...@@ -169,7 +169,7 @@ int kvm_arch_get_registers(CPUState *env)
#ifdef KVM_CAP_PPC_SEGSTATE #ifdef KVM_CAP_PPC_SEGSTATE
if (kvm_check_extension(env->kvm_state, KVM_CAP_PPC_SEGSTATE)) { if (kvm_check_extension(env->kvm_state, KVM_CAP_PPC_SEGSTATE)) {
env->sdr1 = sregs.u.s.sdr1; ppc_store_sdr1(env, sregs.u.s.sdr1);
/* Sync SLB */ /* Sync SLB */
#ifdef TARGET_PPC64 #ifdef TARGET_PPC64
......
...@@ -37,7 +37,7 @@ void cpu_save(QEMUFile *f, void *opaque) ...@@ -37,7 +37,7 @@ void cpu_save(QEMUFile *f, void *opaque)
qemu_put_betls(f, &env->asr); qemu_put_betls(f, &env->asr);
qemu_put_sbe32s(f, &env->slb_nr); qemu_put_sbe32s(f, &env->slb_nr);
#endif #endif
qemu_put_betls(f, &env->sdr1); qemu_put_betls(f, &env->spr[SPR_SDR1]);
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
qemu_put_betls(f, &env->sr[i]); qemu_put_betls(f, &env->sr[i]);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
...@@ -93,6 +93,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) ...@@ -93,6 +93,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
{ {
CPUState *env = (CPUState *)opaque; CPUState *env = (CPUState *)opaque;
unsigned int i, j; unsigned int i, j;
target_ulong sdr1;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
qemu_get_betls(f, &env->gpr[i]); qemu_get_betls(f, &env->gpr[i]);
...@@ -124,7 +125,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) ...@@ -124,7 +125,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
qemu_get_betls(f, &env->asr); qemu_get_betls(f, &env->asr);
qemu_get_sbe32s(f, &env->slb_nr); qemu_get_sbe32s(f, &env->slb_nr);
#endif #endif
qemu_get_betls(f, &env->sdr1); qemu_get_betls(f, &sdr1);
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
qemu_get_betls(f, &env->sr[i]); qemu_get_betls(f, &env->sr[i]);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
...@@ -152,6 +153,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) ...@@ -152,6 +153,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
#endif #endif
for (i = 0; i < 1024; i++) for (i = 0; i < 1024; i++)
qemu_get_betls(f, &env->spr[i]); qemu_get_betls(f, &env->spr[i]);
ppc_store_sdr1(env, sdr1);
qemu_get_be32s(f, &env->vscr); qemu_get_be32s(f, &env->vscr);
qemu_get_be64s(f, &env->spe_acc); qemu_get_be64s(f, &env->spe_acc);
qemu_get_be32s(f, &env->spe_fscr); qemu_get_be32s(f, &env->spe_fscr);
......
...@@ -9126,7 +9126,7 @@ void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf, ...@@ -9126,7 +9126,7 @@ void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf,
#if !defined(CONFIG_USER_ONLY) #if !defined(CONFIG_USER_ONLY)
cpu_fprintf(f, "SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx " SDR1 " cpu_fprintf(f, "SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx " SDR1 "
TARGET_FMT_lx "\n", env->spr[SPR_SRR0], env->spr[SPR_SRR1], TARGET_FMT_lx "\n", env->spr[SPR_SRR0], env->spr[SPR_SRR1],
env->sdr1); env->spr[SPR_SDR1]);
#endif #endif
#undef RGPL #undef RGPL
......
...@@ -343,11 +343,6 @@ static void spr_write_dbatl_h (void *opaque, int sprn, int gprn) ...@@ -343,11 +343,6 @@ static void spr_write_dbatl_h (void *opaque, int sprn, int gprn)
} }
/* SDR1 */ /* SDR1 */
static void spr_read_sdr1 (void *opaque, int gprn, int sprn)
{
tcg_gen_ld_tl(cpu_gpr[gprn], cpu_env, offsetof(CPUState, sdr1));
}
static void spr_write_sdr1 (void *opaque, int sprn, int gprn) static void spr_write_sdr1 (void *opaque, int sprn, int gprn)
{ {
gen_helper_store_sdr1(cpu_gpr[gprn]); gen_helper_store_sdr1(cpu_gpr[gprn]);
...@@ -671,7 +666,7 @@ static void gen_spr_ne_601 (CPUPPCState *env) ...@@ -671,7 +666,7 @@ static void gen_spr_ne_601 (CPUPPCState *env)
/* Memory management */ /* Memory management */
spr_register(env, SPR_SDR1, "SDR1", spr_register(env, SPR_SDR1, "SDR1",
SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS,
&spr_read_sdr1, &spr_write_sdr1, &spr_read_generic, &spr_write_sdr1,
0x00000000); 0x00000000);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册