target/arm: Use tlb_set_page_full

Adjust GetPhysAddrResult to fill in CPUTLBEntryFull,
so that it may be passed directly to tlb_set_page_full.

The change is large, but mostly mechanical.  The major
non-mechanical change is page_size -> lg_page_size.
Most of the time this is obvious, and is related to
TARGET_PAGE_BITS.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20221001162318.153420-21-richard.henderson@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Richard Henderson 2022-10-01 09:22:56 -07:00 committed by Peter Maydell
parent 5b74f9b4ed
commit 7fa7ea8f48
5 changed files with 111 additions and 114 deletions

View File

@ -3323,8 +3323,8 @@ static uint64_t do_ats_write(CPUARMState *env, uint64_t value,
/* Create a 64-bit PAR */ /* Create a 64-bit PAR */
par64 = (1 << 11); /* LPAE bit always set */ par64 = (1 << 11); /* LPAE bit always set */
if (!ret) { if (!ret) {
par64 |= res.phys & ~0xfffULL; par64 |= res.f.phys_addr & ~0xfffULL;
if (!res.attrs.secure) { if (!res.f.attrs.secure) {
par64 |= (1 << 9); /* NS */ par64 |= (1 << 9); /* NS */
} }
par64 |= (uint64_t)res.cacheattrs.attrs << 56; /* ATTR */ par64 |= (uint64_t)res.cacheattrs.attrs << 56; /* ATTR */
@ -3348,13 +3348,13 @@ static uint64_t do_ats_write(CPUARMState *env, uint64_t value,
*/ */
if (!ret) { if (!ret) {
/* We do not set any attribute bits in the PAR */ /* We do not set any attribute bits in the PAR */
if (res.page_size == (1 << 24) if (res.f.lg_page_size == 24
&& arm_feature(env, ARM_FEATURE_V7)) { && arm_feature(env, ARM_FEATURE_V7)) {
par64 = (res.phys & 0xff000000) | (1 << 1); par64 = (res.f.phys_addr & 0xff000000) | (1 << 1);
} else { } else {
par64 = res.phys & 0xfffff000; par64 = res.f.phys_addr & 0xfffff000;
} }
if (!res.attrs.secure) { if (!res.f.attrs.secure) {
par64 |= (1 << 9); /* NS */ par64 |= (1 << 9); /* NS */
} }
} else { } else {

View File

@ -1071,10 +1071,7 @@ typedef struct ARMCacheAttrs {
/* Fields that are valid upon success. */ /* Fields that are valid upon success. */
typedef struct GetPhysAddrResult { typedef struct GetPhysAddrResult {
hwaddr phys; CPUTLBEntryFull f;
target_ulong page_size;
int prot;
MemTxAttrs attrs;
ARMCacheAttrs cacheattrs; ARMCacheAttrs cacheattrs;
} GetPhysAddrResult; } GetPhysAddrResult;

View File

@ -223,8 +223,8 @@ static bool v7m_stack_write(ARMCPU *cpu, uint32_t addr, uint32_t value,
} }
goto pend_fault; goto pend_fault;
} }
address_space_stl_le(arm_addressspace(cs, res.attrs), res.phys, value, address_space_stl_le(arm_addressspace(cs, res.f.attrs), res.f.phys_addr,
res.attrs, &txres); value, res.f.attrs, &txres);
if (txres != MEMTX_OK) { if (txres != MEMTX_OK) {
/* BusFault trying to write the data */ /* BusFault trying to write the data */
if (mode == STACK_LAZYFP) { if (mode == STACK_LAZYFP) {
@ -298,8 +298,8 @@ static bool v7m_stack_read(ARMCPU *cpu, uint32_t *dest, uint32_t addr,
goto pend_fault; goto pend_fault;
} }
value = address_space_ldl(arm_addressspace(cs, res.attrs), res.phys, value = address_space_ldl(arm_addressspace(cs, res.f.attrs),
res.attrs, &txres); res.f.phys_addr, res.f.attrs, &txres);
if (txres != MEMTX_OK) { if (txres != MEMTX_OK) {
/* BusFault trying to read the data */ /* BusFault trying to read the data */
qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.UNSTKERR\n"); qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.UNSTKERR\n");
@ -2022,8 +2022,8 @@ static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx, bool secure,
qemu_log_mask(CPU_LOG_INT, "...really MemManage with CFSR.IACCVIOL\n"); qemu_log_mask(CPU_LOG_INT, "...really MemManage with CFSR.IACCVIOL\n");
return false; return false;
} }
*insn = address_space_lduw_le(arm_addressspace(cs, res.attrs), res.phys, *insn = address_space_lduw_le(arm_addressspace(cs, res.f.attrs),
res.attrs, &txres); res.f.phys_addr, res.f.attrs, &txres);
if (txres != MEMTX_OK) { if (txres != MEMTX_OK) {
env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_IBUSERR_MASK; env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_IBUSERR_MASK;
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS, false); armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS, false);
@ -2069,8 +2069,8 @@ static bool v7m_read_sg_stack_word(ARMCPU *cpu, ARMMMUIdx mmu_idx,
} }
return false; return false;
} }
value = address_space_ldl(arm_addressspace(cs, res.attrs), res.phys, value = address_space_ldl(arm_addressspace(cs, res.f.attrs),
res.attrs, &txres); res.f.phys_addr, res.f.attrs, &txres);
if (txres != MEMTX_OK) { if (txres != MEMTX_OK) {
/* BusFault trying to read the data */ /* BusFault trying to read the data */
qemu_log_mask(CPU_LOG_INT, qemu_log_mask(CPU_LOG_INT,
@ -2817,8 +2817,8 @@ uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op)
} else { } else {
mrvalid = true; mrvalid = true;
} }
r = res.prot & PAGE_READ; r = res.f.prot & PAGE_READ;
rw = res.prot & PAGE_WRITE; rw = res.f.prot & PAGE_WRITE;
} else { } else {
r = false; r = false;
rw = false; rw = false;

View File

@ -256,7 +256,7 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx,
assert(!is_secure); assert(!is_secure);
} }
addr = s2.phys; addr = s2.f.phys_addr;
} }
return addr; return addr;
} }
@ -476,7 +476,7 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address,
/* 1Mb section. */ /* 1Mb section. */
phys_addr = (desc & 0xfff00000) | (address & 0x000fffff); phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);
ap = (desc >> 10) & 3; ap = (desc >> 10) & 3;
result->page_size = 1024 * 1024; result->f.lg_page_size = 20; /* 1MB */
} else { } else {
/* Lookup l2 entry. */ /* Lookup l2 entry. */
if (type == 1) { if (type == 1) {
@ -497,12 +497,12 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address,
case 1: /* 64k page. */ case 1: /* 64k page. */
phys_addr = (desc & 0xffff0000) | (address & 0xffff); phys_addr = (desc & 0xffff0000) | (address & 0xffff);
ap = (desc >> (4 + ((address >> 13) & 6))) & 3; ap = (desc >> (4 + ((address >> 13) & 6))) & 3;
result->page_size = 0x10000; result->f.lg_page_size = 16;
break; break;
case 2: /* 4k page. */ case 2: /* 4k page. */
phys_addr = (desc & 0xfffff000) | (address & 0xfff); phys_addr = (desc & 0xfffff000) | (address & 0xfff);
ap = (desc >> (4 + ((address >> 9) & 6))) & 3; ap = (desc >> (4 + ((address >> 9) & 6))) & 3;
result->page_size = 0x1000; result->f.lg_page_size = 12;
break; break;
case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */ case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */
if (type == 1) { if (type == 1) {
@ -510,7 +510,7 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address,
if (arm_feature(env, ARM_FEATURE_XSCALE) if (arm_feature(env, ARM_FEATURE_XSCALE)
|| arm_feature(env, ARM_FEATURE_V6)) { || arm_feature(env, ARM_FEATURE_V6)) {
phys_addr = (desc & 0xfffff000) | (address & 0xfff); phys_addr = (desc & 0xfffff000) | (address & 0xfff);
result->page_size = 0x1000; result->f.lg_page_size = 12;
} else { } else {
/* /*
* UNPREDICTABLE in ARMv5; we choose to take a * UNPREDICTABLE in ARMv5; we choose to take a
@ -521,7 +521,7 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address,
} }
} else { } else {
phys_addr = (desc & 0xfffffc00) | (address & 0x3ff); phys_addr = (desc & 0xfffffc00) | (address & 0x3ff);
result->page_size = 0x400; result->f.lg_page_size = 10;
} }
ap = (desc >> 4) & 3; ap = (desc >> 4) & 3;
break; break;
@ -530,14 +530,14 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address,
g_assert_not_reached(); g_assert_not_reached();
} }
} }
result->prot = ap_to_rw_prot(env, mmu_idx, ap, domain_prot); result->f.prot = ap_to_rw_prot(env, mmu_idx, ap, domain_prot);
result->prot |= result->prot ? PAGE_EXEC : 0; result->f.prot |= result->f.prot ? PAGE_EXEC : 0;
if (!(result->prot & (1 << access_type))) { if (!(result->f.prot & (1 << access_type))) {
/* Access permission fault. */ /* Access permission fault. */
fi->type = ARMFault_Permission; fi->type = ARMFault_Permission;
goto do_fault; goto do_fault;
} }
result->phys = phys_addr; result->f.phys_addr = phys_addr;
return false; return false;
do_fault: do_fault:
fi->domain = domain; fi->domain = domain;
@ -607,11 +607,11 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address,
phys_addr = (desc & 0xff000000) | (address & 0x00ffffff); phys_addr = (desc & 0xff000000) | (address & 0x00ffffff);
phys_addr |= (uint64_t)extract32(desc, 20, 4) << 32; phys_addr |= (uint64_t)extract32(desc, 20, 4) << 32;
phys_addr |= (uint64_t)extract32(desc, 5, 4) << 36; phys_addr |= (uint64_t)extract32(desc, 5, 4) << 36;
result->page_size = 0x1000000; result->f.lg_page_size = 24; /* 16MB */
} else { } else {
/* Section. */ /* Section. */
phys_addr = (desc & 0xfff00000) | (address & 0x000fffff); phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);
result->page_size = 0x100000; result->f.lg_page_size = 20; /* 1MB */
} }
ap = ((desc >> 10) & 3) | ((desc >> 13) & 4); ap = ((desc >> 10) & 3) | ((desc >> 13) & 4);
xn = desc & (1 << 4); xn = desc & (1 << 4);
@ -636,12 +636,12 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address,
case 1: /* 64k page. */ case 1: /* 64k page. */
phys_addr = (desc & 0xffff0000) | (address & 0xffff); phys_addr = (desc & 0xffff0000) | (address & 0xffff);
xn = desc & (1 << 15); xn = desc & (1 << 15);
result->page_size = 0x10000; result->f.lg_page_size = 16;
break; break;
case 2: case 3: /* 4k page. */ case 2: case 3: /* 4k page. */
phys_addr = (desc & 0xfffff000) | (address & 0xfff); phys_addr = (desc & 0xfffff000) | (address & 0xfff);
xn = desc & 1; xn = desc & 1;
result->page_size = 0x1000; result->f.lg_page_size = 12;
break; break;
default: default:
/* Never happens, but compiler isn't smart enough to tell. */ /* Never happens, but compiler isn't smart enough to tell. */
@ -649,7 +649,7 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address,
} }
} }
if (domain_prot == 3) { if (domain_prot == 3) {
result->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; result->f.prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
} else { } else {
if (pxn && !regime_is_user(env, mmu_idx)) { if (pxn && !regime_is_user(env, mmu_idx)) {
xn = 1; xn = 1;
@ -667,14 +667,14 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address,
fi->type = ARMFault_AccessFlag; fi->type = ARMFault_AccessFlag;
goto do_fault; goto do_fault;
} }
result->prot = simple_ap_to_rw_prot(env, mmu_idx, ap >> 1); result->f.prot = simple_ap_to_rw_prot(env, mmu_idx, ap >> 1);
} else { } else {
result->prot = ap_to_rw_prot(env, mmu_idx, ap, domain_prot); result->f.prot = ap_to_rw_prot(env, mmu_idx, ap, domain_prot);
} }
if (result->prot && !xn) { if (result->f.prot && !xn) {
result->prot |= PAGE_EXEC; result->f.prot |= PAGE_EXEC;
} }
if (!(result->prot & (1 << access_type))) { if (!(result->f.prot & (1 << access_type))) {
/* Access permission fault. */ /* Access permission fault. */
fi->type = ARMFault_Permission; fi->type = ARMFault_Permission;
goto do_fault; goto do_fault;
@ -685,9 +685,9 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address,
* the CPU doesn't support TZ or this is a non-secure translation * the CPU doesn't support TZ or this is a non-secure translation
* regime, because the attribute will already be non-secure. * regime, because the attribute will already be non-secure.
*/ */
result->attrs.secure = false; result->f.attrs.secure = false;
} }
result->phys = phys_addr; result->f.phys_addr = phys_addr;
return false; return false;
do_fault: do_fault:
fi->domain = domain; fi->domain = domain;
@ -1298,16 +1298,16 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address,
if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) {
ns = mmu_idx == ARMMMUIdx_Stage2; ns = mmu_idx == ARMMMUIdx_Stage2;
xn = extract32(attrs, 11, 2); xn = extract32(attrs, 11, 2);
result->prot = get_S2prot(env, ap, xn, s1_is_el0); result->f.prot = get_S2prot(env, ap, xn, s1_is_el0);
} else { } else {
ns = extract32(attrs, 3, 1); ns = extract32(attrs, 3, 1);
xn = extract32(attrs, 12, 1); xn = extract32(attrs, 12, 1);
pxn = extract32(attrs, 11, 1); pxn = extract32(attrs, 11, 1);
result->prot = get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn); result->f.prot = get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn);
} }
fault_type = ARMFault_Permission; fault_type = ARMFault_Permission;
if (!(result->prot & (1 << access_type))) { if (!(result->f.prot & (1 << access_type))) {
goto do_fault; goto do_fault;
} }
@ -1317,11 +1317,11 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address,
* the CPU doesn't support TZ or this is a non-secure translation * the CPU doesn't support TZ or this is a non-secure translation
* regime, because the attribute will already be non-secure. * regime, because the attribute will already be non-secure.
*/ */
result->attrs.secure = false; result->f.attrs.secure = false;
} }
/* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB. */ /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB. */
if (aarch64 && guarded && cpu_isar_feature(aa64_bti, cpu)) { if (aarch64 && guarded && cpu_isar_feature(aa64_bti, cpu)) {
arm_tlb_bti_gp(&result->attrs) = true; arm_tlb_bti_gp(&result->f.attrs) = true;
} }
if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) {
@ -1347,8 +1347,8 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address,
result->cacheattrs.shareability = extract32(attrs, 6, 2); result->cacheattrs.shareability = extract32(attrs, 6, 2);
} }
result->phys = descaddr; result->f.phys_addr = descaddr;
result->page_size = page_size; result->f.lg_page_size = ctz64(page_size);
return false; return false;
do_fault: do_fault:
@ -1373,12 +1373,12 @@ static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address,
if (regime_translation_disabled(env, mmu_idx, is_secure)) { if (regime_translation_disabled(env, mmu_idx, is_secure)) {
/* MPU disabled. */ /* MPU disabled. */
result->phys = address; result->f.phys_addr = address;
result->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; result->f.prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
return false; return false;
} }
result->phys = address; result->f.phys_addr = address;
for (n = 7; n >= 0; n--) { for (n = 7; n >= 0; n--) {
base = env->cp15.c6_region[n]; base = env->cp15.c6_region[n];
if ((base & 1) == 0) { if ((base & 1) == 0) {
@ -1414,16 +1414,16 @@ static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address,
fi->level = 1; fi->level = 1;
return true; return true;
} }
result->prot = PAGE_READ | PAGE_WRITE; result->f.prot = PAGE_READ | PAGE_WRITE;
break; break;
case 2: case 2:
result->prot = PAGE_READ; result->f.prot = PAGE_READ;
if (!is_user) { if (!is_user) {
result->prot |= PAGE_WRITE; result->f.prot |= PAGE_WRITE;
} }
break; break;
case 3: case 3:
result->prot = PAGE_READ | PAGE_WRITE; result->f.prot = PAGE_READ | PAGE_WRITE;
break; break;
case 5: case 5:
if (is_user) { if (is_user) {
@ -1431,10 +1431,10 @@ static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address,
fi->level = 1; fi->level = 1;
return true; return true;
} }
result->prot = PAGE_READ; result->f.prot = PAGE_READ;
break; break;
case 6: case 6:
result->prot = PAGE_READ; result->f.prot = PAGE_READ;
break; break;
default: default:
/* Bad permission. */ /* Bad permission. */
@ -1442,12 +1442,12 @@ static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address,
fi->level = 1; fi->level = 1;
return true; return true;
} }
result->prot |= PAGE_EXEC; result->f.prot |= PAGE_EXEC;
return false; return false;
} }
static void get_phys_addr_pmsav7_default(CPUARMState *env, ARMMMUIdx mmu_idx, static void get_phys_addr_pmsav7_default(CPUARMState *env, ARMMMUIdx mmu_idx,
int32_t address, int *prot) int32_t address, uint8_t *prot)
{ {
if (!arm_feature(env, ARM_FEATURE_M)) { if (!arm_feature(env, ARM_FEATURE_M)) {
*prot = PAGE_READ | PAGE_WRITE; *prot = PAGE_READ | PAGE_WRITE;
@ -1531,9 +1531,9 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
int n; int n;
bool is_user = regime_is_user(env, mmu_idx); bool is_user = regime_is_user(env, mmu_idx);
result->phys = address; result->f.phys_addr = address;
result->page_size = TARGET_PAGE_SIZE; result->f.lg_page_size = TARGET_PAGE_BITS;
result->prot = 0; result->f.prot = 0;
if (regime_translation_disabled(env, mmu_idx, secure) || if (regime_translation_disabled(env, mmu_idx, secure) ||
m_is_ppb_region(env, address)) { m_is_ppb_region(env, address)) {
@ -1545,7 +1545,7 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
* which always does a direct read using address_space_ldl(), rather * which always does a direct read using address_space_ldl(), rather
* than going via this function, so we don't need to check that here. * than going via this function, so we don't need to check that here.
*/ */
get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->prot); get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->f.prot);
} else { /* MPU enabled */ } else { /* MPU enabled */
for (n = (int)cpu->pmsav7_dregion - 1; n >= 0; n--) { for (n = (int)cpu->pmsav7_dregion - 1; n >= 0; n--) {
/* region search */ /* region search */
@ -1587,7 +1587,7 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
if (ranges_overlap(base, rmask, if (ranges_overlap(base, rmask,
address & TARGET_PAGE_MASK, address & TARGET_PAGE_MASK,
TARGET_PAGE_SIZE)) { TARGET_PAGE_SIZE)) {
result->page_size = 1; result->f.lg_page_size = 0;
} }
continue; continue;
} }
@ -1625,7 +1625,7 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
continue; continue;
} }
if (rsize < TARGET_PAGE_BITS) { if (rsize < TARGET_PAGE_BITS) {
result->page_size = 1 << rsize; result->f.lg_page_size = rsize;
} }
break; break;
} }
@ -1636,7 +1636,8 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
fi->type = ARMFault_Background; fi->type = ARMFault_Background;
return true; return true;
} }
get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->prot); get_phys_addr_pmsav7_default(env, mmu_idx, address,
&result->f.prot);
} else { /* a MPU hit! */ } else { /* a MPU hit! */
uint32_t ap = extract32(env->pmsav7.dracr[n], 8, 3); uint32_t ap = extract32(env->pmsav7.dracr[n], 8, 3);
uint32_t xn = extract32(env->pmsav7.dracr[n], 12, 1); uint32_t xn = extract32(env->pmsav7.dracr[n], 12, 1);
@ -1653,16 +1654,16 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
case 5: case 5:
break; /* no access */ break; /* no access */
case 3: case 3:
result->prot |= PAGE_WRITE; result->f.prot |= PAGE_WRITE;
/* fall through */ /* fall through */
case 2: case 2:
case 6: case 6:
result->prot |= PAGE_READ | PAGE_EXEC; result->f.prot |= PAGE_READ | PAGE_EXEC;
break; break;
case 7: case 7:
/* for v7M, same as 6; for R profile a reserved value */ /* for v7M, same as 6; for R profile a reserved value */
if (arm_feature(env, ARM_FEATURE_M)) { if (arm_feature(env, ARM_FEATURE_M)) {
result->prot |= PAGE_READ | PAGE_EXEC; result->f.prot |= PAGE_READ | PAGE_EXEC;
break; break;
} }
/* fall through */ /* fall through */
@ -1678,16 +1679,16 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
case 1: case 1:
case 2: case 2:
case 3: case 3:
result->prot |= PAGE_WRITE; result->f.prot |= PAGE_WRITE;
/* fall through */ /* fall through */
case 5: case 5:
case 6: case 6:
result->prot |= PAGE_READ | PAGE_EXEC; result->f.prot |= PAGE_READ | PAGE_EXEC;
break; break;
case 7: case 7:
/* for v7M, same as 6; for R profile a reserved value */ /* for v7M, same as 6; for R profile a reserved value */
if (arm_feature(env, ARM_FEATURE_M)) { if (arm_feature(env, ARM_FEATURE_M)) {
result->prot |= PAGE_READ | PAGE_EXEC; result->f.prot |= PAGE_READ | PAGE_EXEC;
break; break;
} }
/* fall through */ /* fall through */
@ -1700,14 +1701,14 @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
/* execute never */ /* execute never */
if (xn) { if (xn) {
result->prot &= ~PAGE_EXEC; result->f.prot &= ~PAGE_EXEC;
} }
} }
} }
fi->type = ARMFault_Permission; fi->type = ARMFault_Permission;
fi->level = 1; fi->level = 1;
return !(result->prot & (1 << access_type)); return !(result->f.prot & (1 << access_type));
} }
bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
@ -1733,9 +1734,9 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
uint32_t addr_page_base = address & TARGET_PAGE_MASK; uint32_t addr_page_base = address & TARGET_PAGE_MASK;
uint32_t addr_page_limit = addr_page_base + (TARGET_PAGE_SIZE - 1); uint32_t addr_page_limit = addr_page_base + (TARGET_PAGE_SIZE - 1);
result->page_size = TARGET_PAGE_SIZE; result->f.lg_page_size = TARGET_PAGE_BITS;
result->phys = address; result->f.phys_addr = address;
result->prot = 0; result->f.prot = 0;
if (mregion) { if (mregion) {
*mregion = -1; *mregion = -1;
} }
@ -1785,13 +1786,13 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
ranges_overlap(base, limit - base + 1, ranges_overlap(base, limit - base + 1,
addr_page_base, addr_page_base,
TARGET_PAGE_SIZE)) { TARGET_PAGE_SIZE)) {
result->page_size = 1; result->f.lg_page_size = 0;
} }
continue; continue;
} }
if (base > addr_page_base || limit < addr_page_limit) { if (base > addr_page_base || limit < addr_page_limit) {
result->page_size = 1; result->f.lg_page_size = 0;
} }
if (matchregion != -1) { if (matchregion != -1) {
@ -1817,7 +1818,7 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
if (matchregion == -1) { if (matchregion == -1) {
/* hit using the background region */ /* hit using the background region */
get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->prot); get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->f.prot);
} else { } else {
uint32_t ap = extract32(env->pmsav8.rbar[secure][matchregion], 1, 2); uint32_t ap = extract32(env->pmsav8.rbar[secure][matchregion], 1, 2);
uint32_t xn = extract32(env->pmsav8.rbar[secure][matchregion], 0, 1); uint32_t xn = extract32(env->pmsav8.rbar[secure][matchregion], 0, 1);
@ -1832,9 +1833,9 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
xn = 1; xn = 1;
} }
result->prot = simple_ap_to_rw_prot(env, mmu_idx, ap); result->f.prot = simple_ap_to_rw_prot(env, mmu_idx, ap);
if (result->prot && !xn && !(pxn && !is_user)) { if (result->f.prot && !xn && !(pxn && !is_user)) {
result->prot |= PAGE_EXEC; result->f.prot |= PAGE_EXEC;
} }
/* /*
* We don't need to look the attribute up in the MAIR0/MAIR1 * We don't need to look the attribute up in the MAIR0/MAIR1
@ -1847,7 +1848,7 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
fi->type = ARMFault_Permission; fi->type = ARMFault_Permission;
fi->level = 1; fi->level = 1;
return !(result->prot & (1 << access_type)); return !(result->f.prot & (1 << access_type));
} }
static bool v8m_is_sau_exempt(CPUARMState *env, static bool v8m_is_sau_exempt(CPUARMState *env,
@ -2011,9 +2012,9 @@ static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address,
} else { } else {
fi->type = ARMFault_QEMU_SFault; fi->type = ARMFault_QEMU_SFault;
} }
result->page_size = sattrs.subpage ? 1 : TARGET_PAGE_SIZE; result->f.lg_page_size = sattrs.subpage ? 0 : TARGET_PAGE_BITS;
result->phys = address; result->f.phys_addr = address;
result->prot = 0; result->f.prot = 0;
return true; return true;
} }
} else { } else {
@ -2023,7 +2024,7 @@ static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address,
* might downgrade a secure access to nonsecure. * might downgrade a secure access to nonsecure.
*/ */
if (sattrs.ns) { if (sattrs.ns) {
result->attrs.secure = false; result->f.attrs.secure = false;
} else if (!secure) { } else if (!secure) {
/* /*
* NS access to S memory must fault. * NS access to S memory must fault.
@ -2036,9 +2037,9 @@ static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address,
* for M_FAKE_FSR_SFAULT in arm_v7m_cpu_do_interrupt(). * for M_FAKE_FSR_SFAULT in arm_v7m_cpu_do_interrupt().
*/ */
fi->type = ARMFault_QEMU_SFault; fi->type = ARMFault_QEMU_SFault;
result->page_size = sattrs.subpage ? 1 : TARGET_PAGE_SIZE; result->f.lg_page_size = sattrs.subpage ? 0 : TARGET_PAGE_BITS;
result->phys = address; result->f.phys_addr = address;
result->prot = 0; result->f.prot = 0;
return true; return true;
} }
} }
@ -2047,7 +2048,7 @@ static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address,
ret = pmsav8_mpu_lookup(env, address, access_type, mmu_idx, secure, ret = pmsav8_mpu_lookup(env, address, access_type, mmu_idx, secure,
result, fi, NULL); result, fi, NULL);
if (sattrs.subpage) { if (sattrs.subpage) {
result->page_size = 1; result->f.lg_page_size = 0;
} }
return ret; return ret;
} }
@ -2338,9 +2339,9 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address,
result->cacheattrs.is_s2_format = false; result->cacheattrs.is_s2_format = false;
} }
result->phys = address; result->f.phys_addr = address;
result->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; result->f.prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
result->page_size = TARGET_PAGE_SIZE; result->f.lg_page_size = TARGET_PAGE_BITS;
result->cacheattrs.shareability = shareability; result->cacheattrs.shareability = shareability;
result->cacheattrs.attrs = memattr; result->cacheattrs.attrs = memattr;
return 0; return 0;
@ -2377,8 +2378,8 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
return ret; return ret;
} }
ipa = result->phys; ipa = result->f.phys_addr;
ipa_secure = result->attrs.secure; ipa_secure = result->f.attrs.secure;
if (is_secure) { if (is_secure) {
/* Select TCR based on the NS bit from the S1 walk. */ /* Select TCR based on the NS bit from the S1 walk. */
s2walk_secure = !(ipa_secure s2walk_secure = !(ipa_secure
@ -2398,7 +2399,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
* Save the stage1 results so that we may merge * Save the stage1 results so that we may merge
* prot and cacheattrs later. * prot and cacheattrs later.
*/ */
s1_prot = result->prot; s1_prot = result->f.prot;
cacheattrs1 = result->cacheattrs; cacheattrs1 = result->cacheattrs;
memset(result, 0, sizeof(*result)); memset(result, 0, sizeof(*result));
@ -2407,7 +2408,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
fi->s2addr = ipa; fi->s2addr = ipa;
/* Combine the S1 and S2 perms. */ /* Combine the S1 and S2 perms. */
result->prot &= s1_prot; result->f.prot &= s1_prot;
/* If S2 fails, return early. */ /* If S2 fails, return early. */
if (ret) { if (ret) {
@ -2436,7 +2437,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
* Check if IPA translates to secure or non-secure PA space. * Check if IPA translates to secure or non-secure PA space.
* Note that VSTCR overrides VTCR and {N}SW overrides {N}SA. * Note that VSTCR overrides VTCR and {N}SW overrides {N}SA.
*/ */
result->attrs.secure = result->f.attrs.secure =
(is_secure (is_secure
&& !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW)) && !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW))
&& (ipa_secure && (ipa_secure
@ -2456,8 +2457,8 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
* cannot upgrade an non-secure translation regime's attributes * cannot upgrade an non-secure translation regime's attributes
* to secure. * to secure.
*/ */
result->attrs.secure = is_secure; result->f.attrs.secure = is_secure;
result->attrs.user = regime_is_user(env, mmu_idx); result->f.attrs.user = regime_is_user(env, mmu_idx);
/* /*
* Fast Context Switch Extension. This doesn't exist at all in v8. * Fast Context Switch Extension. This doesn't exist at all in v8.
@ -2474,7 +2475,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
if (arm_feature(env, ARM_FEATURE_PMSA)) { if (arm_feature(env, ARM_FEATURE_PMSA)) {
bool ret; bool ret;
result->page_size = TARGET_PAGE_SIZE; result->f.lg_page_size = TARGET_PAGE_BITS;
if (arm_feature(env, ARM_FEATURE_V8)) { if (arm_feature(env, ARM_FEATURE_V8)) {
/* PMSAv8 */ /* PMSAv8 */
@ -2495,9 +2496,9 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
(access_type == MMU_DATA_STORE ? "writing" : "execute"), (access_type == MMU_DATA_STORE ? "writing" : "execute"),
(uint32_t)address, mmu_idx, (uint32_t)address, mmu_idx,
ret ? "Miss" : "Hit", ret ? "Miss" : "Hit",
result->prot & PAGE_READ ? 'r' : '-', result->f.prot & PAGE_READ ? 'r' : '-',
result->prot & PAGE_WRITE ? 'w' : '-', result->f.prot & PAGE_WRITE ? 'w' : '-',
result->prot & PAGE_EXEC ? 'x' : '-'); result->f.prot & PAGE_EXEC ? 'x' : '-');
return ret; return ret;
} }
@ -2572,10 +2573,10 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr,
bool ret; bool ret;
ret = get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &res, &fi); ret = get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &res, &fi);
*attrs = res.attrs; *attrs = res.f.attrs;
if (ret) { if (ret) {
return -1; return -1;
} }
return res.phys; return res.f.phys_addr;
} }

View File

@ -227,17 +227,16 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
* target page size are handled specially, so for those we * target page size are handled specially, so for those we
* pass in the exact addresses. * pass in the exact addresses.
*/ */
if (res.page_size >= TARGET_PAGE_SIZE) { if (res.f.lg_page_size >= TARGET_PAGE_BITS) {
res.phys &= TARGET_PAGE_MASK; res.f.phys_addr &= TARGET_PAGE_MASK;
address &= TARGET_PAGE_MASK; address &= TARGET_PAGE_MASK;
} }
/* Notice and record tagged memory. */ /* Notice and record tagged memory. */
if (cpu_isar_feature(aa64_mte, cpu) && res.cacheattrs.attrs == 0xf0) { if (cpu_isar_feature(aa64_mte, cpu) && res.cacheattrs.attrs == 0xf0) {
arm_tlb_mte_tagged(&res.attrs) = true; arm_tlb_mte_tagged(&res.f.attrs) = true;
} }
tlb_set_page_with_attrs(cs, address, res.phys, res.attrs, tlb_set_page_full(cs, mmu_idx, address, &res.f);
res.prot, mmu_idx, res.page_size);
return true; return true;
} else if (probe) { } else if (probe) {
return false; return false;