From: Peter Maydell <[email protected]> Implement the translate_for_debug method instead of the get_phys_addr_attrs_debug one. This allows us to pass the caller the lg_page_size from our internal GetPhysAddrResult struct.
Awkwardly, translate_for_debug's "true on success" convention is the opposite of the one we use internally in ptw.c, so we have to be careful about the sense of the return values. This corresponds to the way that arm_cpu_tlb_fill_align() also has to return true when get_phys_addr() returns false. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-id: [email protected] Reviewed-by: Richard Henderson <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> --- target/arm/cpu.h | 3 --- target/arm/internals.h | 4 ++++ target/arm/cpu.c | 2 +- target/arm/ptw.c | 39 +++++++++++++++++++++++---------------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 60f11379bfb..15a13b92927 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1260,9 +1260,6 @@ extern const VMStateDescription vmstate_arm_cpu; void arm_cpu_do_interrupt(CPUState *cpu); void arm_v7m_cpu_do_interrupt(CPUState *cpu); -hwaddr arm_cpu_get_phys_addr_attrs_debug(CPUState *cpu, vaddr addr, - MemTxAttrs *attrs); - typedef struct ARMGranuleProtectionConfig { /* GPCCR_EL3 */ uint64_t gpccr; diff --git a/target/arm/internals.h b/target/arm/internals.h index 86b41b4724a..3edc15c7b4a 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1540,6 +1540,10 @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address, void arm_log_exception(CPUState *cs); +/* Implementation of SysemuCPUOps::translate_for_debug */ +bool arm_cpu_translate_for_debug(CPUState *cs, vaddr addr, + TranslateForDebugResult *result); + #endif /* !CONFIG_USER_ONLY */ /* diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 6e13873360d..31e0a12a986 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2498,7 +2498,7 @@ static vaddr aarch64_untagged_addr(CPUState *cs, vaddr x) static const struct SysemuCPUOps arm_sysemu_ops = { .has_work = arm_cpu_has_work, - .get_phys_addr_attrs_debug = arm_cpu_get_phys_addr_attrs_debug, + .translate_for_debug = arm_cpu_translate_for_debug, .asidx_from_attrs = arm_asidx_from_attrs, .write_elf32_note = arm_cpu_write_elf32_note, .write_elf64_note = arm_cpu_write_elf64_note, diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 24656b1a062..8706dd59dd6 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -3942,8 +3942,9 @@ bool get_phys_addr(CPUARMState *env, vaddr address, memop, result, fi); } -static hwaddr arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr, - MemTxAttrs *attrs, ARMMMUIdx mmu_idx) +static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr, + TranslateForDebugResult *result, + ARMMMUIdx mmu_idx) { S1Translate ptw = { .in_mmu_idx = mmu_idx, @@ -3954,26 +3955,31 @@ static hwaddr arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr, }; GetPhysAddrResult res = {}; ARMMMUFaultInfo fi = {}; - bool ret = get_phys_addr_gpc(env, &ptw, addr, MMU_DATA_LOAD, 0, &res, &fi); - *attrs = res.f.attrs; + bool fault = get_phys_addr_gpc(env, &ptw, addr, MMU_DATA_LOAD, 0, &res, &fi); - if (ret) { - return -1; + if (!fault) { + /* translation succeeded */ + result->physaddr = res.f.phys_addr; + result->attrs = res.f.attrs; + result->lg_page_size = res.f.lg_page_size; } - return res.f.phys_addr; + return fault; } -hwaddr arm_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr, - MemTxAttrs *attrs) +bool arm_cpu_translate_for_debug(CPUState *cs, vaddr addr, + TranslateForDebugResult *result) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; ARMMMUIdx mmu_idx = arm_mmu_idx(env); - hwaddr res = arm_cpu_get_phys_addr(env, addr, attrs, mmu_idx); - - if (res != -1) { - return res; + /* + * Note that this function returns true on translation success, + * but arm_cpu_get_phys_addr() and all the other get_phys_addr + * style functions in this file return true on failure. + */ + if (!arm_cpu_get_phys_addr(env, addr, result, mmu_idx)) { + return true; } /* @@ -3984,11 +3990,12 @@ hwaddr arm_cpu_get_phys_addr_attrs_debug(CPUState *cs, vaddr addr, switch (mmu_idx) { case ARMMMUIdx_E10_1: case ARMMMUIdx_E10_1_PAN: - return arm_cpu_get_phys_addr(env, addr, attrs, ARMMMUIdx_E10_0); + return !arm_cpu_get_phys_addr(env, addr, result, ARMMMUIdx_E10_0); case ARMMMUIdx_E20_2: case ARMMMUIdx_E20_2_PAN: - return arm_cpu_get_phys_addr(env, addr, attrs, ARMMMUIdx_E20_0); + return !arm_cpu_get_phys_addr(env, addr, result, ARMMMUIdx_E20_0); default: - return -1; + /* translation failed */ + return false; } } -- 2.53.0
