target/arm: Allow compilation without CONFIG_ARM_V7M
v3 cover target/arm: Allow compilation without CONFIG_ARM_V7M
We've got a switch to disable v7m code since a long time - but it currently cannot be disabled since linking then fails due to missing functions. But thanks to the clean-ups that have been done during the past years, it's not that difficult anymore to finally make it possible to disable CONFIG_ARM_V7M: We just have to move some v7m-related code out of cpu32.c to a separate file (that we only compile if the switch CONFIG_ARM_V7M is enabled) and make sure to use the stub functions in m_helper.c if it is disabled. Then we can finally remove the hard-coded "select ARM_V7M" from the Kconfig file.
v3:
- Rebase to current master branch
- Make sure that the stubs use g_assert_not_reached() in the second patch
v2:
- Updated a comment
- Avoid #ifdef in cpu-v7m.c, handle it via meson.build instead
Thomas Huth (3):
target/arm: Move v7m-related code from cpu32.c into a separate file target/arm/tcg/m_helper.c: Include the full helpers only with
CONFIG_ARM_V7M
target/arm/Kconfig: Stop requiring CONFIG_ARM_V7M
target/arm/tcg/cpu-v7m.c | 290 +++++++++++++++++++++++++++++++++++++ target/arm/tcg/cpu32.c | 261 --------------------------------- target/arm/tcg/m_helper.c | 93 ++++++++---- target/arm/Kconfig | 4 - target/arm/meson.build | 3 + target/arm/tcg/meson.build | 3 + 6 files changed, 357 insertions(+), 297 deletions(-) create mode 100644 target/arm/tcg/cpu-v7m.c
Signature · 1 line
2.44.0
PATCH v3 1/3 target/arm: Move v7m-related code from cpu32.c into a separate file
Move the code to a separate file so that we do not have to compile it anymore if CONFIG_ARM_V7M is not set.
--- target/arm/tcg/cpu-v7m.c | 290 +++++++++++++++++++++++++++++++++++++ target/arm/tcg/cpu32.c | 261 --------------------------------- target/arm/meson.build | 3 + target/arm/tcg/meson.build | 3 + 4 files changed, 296 insertions(+), 261 deletions(-) create mode 100644 target/arm/tcg/cpu-v7m.c
target/arm/tcg/cpu-v7m.c new file +290 -0
@@ -0,0 +1,290 @@ +/* +* QEMU ARMv7-M TCG-only CPUs. +* +* Copyright (c) 2012 SUSE LINUX Products GmbH +* +* This code is licensed under the GNU GPL v2 or later. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/core/tcg-cpu-ops.h" +#include "internals.h" + +#if !defined(CONFIG_USER_ONLY ) + +#include "hw/intc/armv7m_nvic.h" + +static bool arm_v7m_cpu_exec_interrupt (CPUState *cs,int interrupt_request) +{ +CPUClass *cc =CPU_GET_CLASS (cs); +ARMCPU *cpu =ARM_CPU (cs); +CPUARMState *env = &cpu->env; +bool ret = false; + +/* +* ARMv7-M interrupt masking works differently than -A or -R. +* There is no FIQ/IRQ distinction. Instead of I and F bits +* masking FIQ and IRQ interrupts, an exception is taken only +* if it is higher priority than the current execution priority +* (which depends on state like BASEPRI, FAULTMASK and the +* currently active exception). +*/ +if (interrupt_request &CPU_INTERRUPT_HARD + && (armv7m_nvic_can_take_pending_exception (env->nvic))) { + cs->exception_index =EXCP_IRQ ; + cc->tcg_ops->do_interrupt (cs); + ret = true; + } +return ret; +} + +#endif /* !CONFIG_USER_ONLY */ + +static void cortex_m0_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); +set_feature (&cpu->env,ARM_FEATURE_V6 ); +set_feature (&cpu->env,ARM_FEATURE_M ); + + cpu->midr =0x410cc200 ; + +/* +* These ID register values are not guest visible, because +* we do not implement the Main Extension. They must be set +* to values corresponding to the Cortex-M0's implemented +* features, because QEMU generally controls its emulation +* by looking at ID register fields. We use the same values as +* for the M3. +*/ + cpu->isar.id_pfr0 =0x00000030 ; + cpu->isar.id_pfr1 =0x00000200 ; + cpu->isar.id_dfr0 =0x00100000 ; + cpu->id_afr0 =0x00000000 ; + cpu->isar.id_mmfr0 =0x00000030 ; + cpu->isar.id_mmfr1 =0x00000000 ; + cpu->isar.id_mmfr2 =0x00000000 ; + cpu->isar.id_mmfr3 =0x00000000 ; + cpu->isar.id_isar0 =0x01141110 ; + cpu->isar.id_isar1 =0x02111000 ; + cpu->isar.id_isar2 =0x21112231 ; + cpu->isar.id_isar3 =0x01111110 ; + cpu->isar.id_isar4 =0x01310102 ; + cpu->isar.id_isar5 =0x00000000 ; + cpu->isar.id_isar6 =0x00000000 ; +} + +static void cortex_m3_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); +set_feature (&cpu->env,ARM_FEATURE_V7 ); +set_feature (&cpu->env,ARM_FEATURE_M ); +set_feature (&cpu->env,ARM_FEATURE_M_MAIN ); + cpu->midr =0x410fc231 ; + cpu->pmsav7_dregion =8 ; + cpu->isar.id_pfr0 =0x00000030 ; + cpu->isar.id_pfr1 =0x00000200 ; + cpu->isar.id_dfr0 =0x00100000 ; + cpu->id_afr0 =0x00000000 ; + cpu->isar.id_mmfr0 =0x00000030 ; + cpu->isar.id_mmfr1 =0x00000000 ; + cpu->isar.id_mmfr2 =0x00000000 ; + cpu->isar.id_mmfr3 =0x00000000 ; + cpu->isar.id_isar0 =0x01141110 ; + cpu->isar.id_isar1 =0x02111000 ; + cpu->isar.id_isar2 =0x21112231 ; + cpu->isar.id_isar3 =0x01111110 ; + cpu->isar.id_isar4 =0x01310102 ; + cpu->isar.id_isar5 =0x00000000 ; + cpu->isar.id_isar6 =0x00000000 ; +} + +static void cortex_m4_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); + +set_feature (&cpu->env,ARM_FEATURE_V7 ); +set_feature (&cpu->env,ARM_FEATURE_M ); +set_feature (&cpu->env,ARM_FEATURE_M_MAIN ); +set_feature (&cpu->env,ARM_FEATURE_THUMB_DSP ); + cpu->midr =0x410fc240 ;/* r0p0 */ + cpu->pmsav7_dregion =8 ; + cpu->isar.mvfr0 =0x10110021 ; + cpu->isar.mvfr1 =0x11000011 ; + cpu->isar.mvfr2 =0x00000000 ; + cpu->isar.id_pfr0 =0x00000030 ; + cpu->isar.id_pfr1 =0x00000200 ; + cpu->isar.id_dfr0 =0x00100000 ; + cpu->id_afr0 =0x00000000 ; + cpu->isar.id_mmfr0 =0x00000030 ; + cpu->isar.id_mmfr1 =0x00000000 ; + cpu->isar.id_mmfr2 =0x00000000 ; + cpu->isar.id_mmfr3 =0x00000000 ; + cpu->isar.id_isar0 =0x01141110 ; + cpu->isar.id_isar1 =0x02111000 ; + cpu->isar.id_isar2 =0x21112231 ; + cpu->isar.id_isar3 =0x01111110 ; + cpu->isar.id_isar4 =0x01310102 ; + cpu->isar.id_isar5 =0x00000000 ; + cpu->isar.id_isar6 =0x00000000 ; +} + +static void cortex_m7_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); + +set_feature (&cpu->env,ARM_FEATURE_V7 ); +set_feature (&cpu->env,ARM_FEATURE_M ); +set_feature (&cpu->env,ARM_FEATURE_M_MAIN ); +set_feature (&cpu->env,ARM_FEATURE_THUMB_DSP ); + cpu->midr =0x411fc272 ;/* r1p2 */ + cpu->pmsav7_dregion =8 ; + cpu->isar.mvfr0 =0x10110221 ; + cpu->isar.mvfr1 =0x12000011 ; + cpu->isar.mvfr2 =0x00000040 ; + cpu->isar.id_pfr0 =0x00000030 ; + cpu->isar.id_pfr1 =0x00000200 ; + cpu->isar.id_dfr0 =0x00100000 ; + cpu->id_afr0 =0x00000000 ; + cpu->isar.id_mmfr0 =0x00100030 ; + cpu->isar.id_mmfr1 =0x00000000 ; + cpu->isar.id_mmfr2 =0x01000000 ; + cpu->isar.id_mmfr3 =0x00000000 ; + cpu->isar.id_isar0 =0x01101110 ; + cpu->isar.id_isar1 =0x02112000 ; + cpu->isar.id_isar2 =0x20232231 ; + cpu->isar.id_isar3 =0x01111131 ; + cpu->isar.id_isar4 =0x01310132 ; + cpu->isar.id_isar5 =0x00000000 ; + cpu->isar.id_isar6 =0x00000000 ; +} + +static void cortex_m33_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); + +set_feature (&cpu->env,ARM_FEATURE_V8 ); +set_feature (&cpu->env,ARM_FEATURE_M ); +set_feature (&cpu->env,ARM_FEATURE_M_MAIN ); +set_feature (&cpu->env,ARM_FEATURE_M_SECURITY ); +set_feature (&cpu->env,ARM_FEATURE_THUMB_DSP ); + cpu->midr =0x410fd213 ;/* r0p3 */ + cpu->pmsav7_dregion =16 ; + cpu->sau_sregion =8 ; + cpu->isar.mvfr0 =0x10110021 ; + cpu->isar.mvfr1 =0x11000011 ; + cpu->isar.mvfr2 =0x00000040 ; + cpu->isar.id_pfr0 =0x00000030 ; + cpu->isar.id_pfr1 =0x00000210 ; + cpu->isar.id_dfr0 =0x00200000 ; + cpu->id_afr0 =0x00000000 ; + cpu->isar.id_mmfr0 =0x00101F40 ; + cpu->isar.id_mmfr1 =0x00000000 ; + cpu->isar.id_mmfr2 =0x01000000 ; + cpu->isar.id_mmfr3 =0x00000000 ; + cpu->isar.id_isar0 =0x01101110 ; + cpu->isar.id_isar1 =0x02212000 ; + cpu->isar.id_isar2 =0x20232232 ; + cpu->isar.id_isar3 =0x01111131 ; + cpu->isar.id_isar4 =0x01310132 ; + cpu->isar.id_isar5 =0x00000000 ; + cpu->isar.id_isar6 =0x00000000 ; + cpu->clidr =0x00000000 ; + cpu->ctr =0x8000c000 ; +} + +static void cortex_m55_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); + +set_feature (&cpu->env,ARM_FEATURE_V8 ); +set_feature (&cpu->env,ARM_FEATURE_V8_1M ); +set_feature (&cpu->env,ARM_FEATURE_M ); +set_feature (&cpu->env,ARM_FEATURE_M_MAIN ); +set_feature (&cpu->env,ARM_FEATURE_M_SECURITY ); +set_feature (&cpu->env,ARM_FEATURE_THUMB_DSP ); + cpu->midr =0x410fd221 ;/* r0p1 */ + cpu->revidr =0 ; + cpu->pmsav7_dregion =16 ; + cpu->sau_sregion =8 ; +/* These are the MVFR* values for the FPU + full MVE configuration */ + cpu->isar.mvfr0 =0x10110221 ; + cpu->isar.mvfr1 =0x12100211 ; + cpu->isar.mvfr2 =0x00000040 ; + cpu->isar.id_pfr0 =0x20000030 ; + cpu->isar.id_pfr1 =0x00000230 ; + cpu->isar.id_dfr0 =0x10200000 ; + cpu->id_afr0 =0x00000000 ; + cpu->isar.id_mmfr0 =0x00111040 ; + cpu->isar.id_mmfr1 =0x00000000 ; + cpu->isar.id_mmfr2 =0x01000000 ; + cpu->isar.id_mmfr3 =0x00000011 ; + cpu->isar.id_isar0 =0x01103110 ; + cpu->isar.id_isar1 =0x02212000 ; + cpu->isar.id_isar2 =0x20232232 ; + cpu->isar.id_isar3 =0x01111131 ; + cpu->isar.id_isar4 =0x01310132 ; + cpu->isar.id_isar5 =0x00000000 ; + cpu->isar.id_isar6 =0x00000000 ; + cpu->clidr =0x00000000 ;/* caches not implemented */ + cpu->ctr =0x8303c003 ; +} + +static const TCGCPUOps arm_v7m_tcg_ops = { + .initialize = arm_translate_init, + .synchronize_from_tb = arm_cpu_synchronize_from_tb, + .debug_excp_handler = arm_debug_excp_handler, + .restore_state_to_opc = arm_restore_state_to_opc, + +#ifdef CONFIG_USER_ONLY + .record_sigsegv = arm_cpu_record_sigsegv, + .record_sigbus = arm_cpu_record_sigbus, +#else + .tlb_fill = arm_cpu_tlb_fill, + .cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt, + .do_interrupt = arm_v7m_cpu_do_interrupt, + .do_transaction_failed = arm_cpu_do_transaction_failed, + .do_unaligned_access = arm_cpu_do_unaligned_access, + .adjust_watchpoint_address = arm_adjust_watchpoint_address, + .debug_check_watchpoint = arm_debug_check_watchpoint, + .debug_check_breakpoint = arm_debug_check_breakpoint, +#endif /* !CONFIG_USER_ONLY */ +}; + +static void arm_v7m_class_init (ObjectClass *oc,void *data) +{ +ARMCPUClass *acc =ARM_CPU_CLASS (oc); +CPUClass *cc =CPU_CLASS (oc); + + acc->info = data; + cc->tcg_ops = &arm_v7m_tcg_ops; + cc->gdb_core_xml_file ="arm-m-profile.xml" ; +} + +static const ARMCPUInfo arm_v7m_cpus[] = { + { .name ="cortex-m0" , .initfn = cortex_m0_initfn, + .class_init = arm_v7m_class_init }, + { .name ="cortex-m3" , .initfn = cortex_m3_initfn, + .class_init = arm_v7m_class_init }, + { .name ="cortex-m4" , .initfn = cortex_m4_initfn, + .class_init = arm_v7m_class_init }, + { .name ="cortex-m7" , .initfn = cortex_m7_initfn, + .class_init = arm_v7m_class_init }, + { .name ="cortex-m33" , .initfn = cortex_m33_initfn, + .class_init = arm_v7m_class_init }, + { .name ="cortex-m55" , .initfn = cortex_m55_initfn, + .class_init = arm_v7m_class_init }, +}; + +static void arm_v7m_cpu_register_types (void ) +{ +size_t i; + +for (i =0 ; i <ARRAY_SIZE (arm_v7m_cpus); ++i) { +arm_cpu_register (&arm_v7m_cpus[i]); + } +} + +type_init (arm_v7m_cpu_register_types)
target/arm/tcg/cpu32.c +0 -261
291 lines not on this page · raw message
target/arm/meson.build +3 -0
@@ -26,6 +26,8 @@ arm_system_ss.add(files( 'ptw.c', )) +arm_user_ss = ss.source_set() + subdir('hvf') if 'CONFIG_TCG' in config_all_accel
@@ -36,3 +38,4 @@ endif target_arch += {'arm': arm_ss} target_system_arch += {'arm': arm_system_ss} +target_user_arch += {'arm': arm_user_ss}
target/arm/tcg/meson.build +3 -0
@@ -55,3 +55,6 @@ arm_ss.add(when: 'TARGET_AARCH64', if_true: files( arm_system_ss.add(files( 'psci.c', )) + +arm_system_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('cpu-v7m.c')) +arm_user_ss.add(when: 'TARGET_AARCH64', if_false: files('cpu-v7m.c'))
Signature · 1 line
2.44.0
PATCH v3 2/3 target/arm/tcg/m_helper.c: Include the full helpers only with CONFIG_ARM_V7M
In reply to Thomas HuthIf CONFIG_ARM_V7M is not set, we don't want to include the full-fledged helper functions that require additional functions for linking. Use some stubs functions that call g_assert_not_reached() instead.
--- target/arm/tcg/m_helper.c | 93 +++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 32 deletions(-)
target/arm/tcg/m_helper.c +61 -32
@@ -22,8 +22,11 @@#endif #if !defined(CONFIG_USER_ONLY )#include "hw/intc/armv7m_nvic.h" +#include CONFIG_DEVICES #endif +#if defined(CONFIG_USER_ONLY ) || defined(CONFIG_ARM_V7M ) +static void v7m_msr_xpsr (CPUARMState *env,uint32_t mask,uint32_t reg,uint32_t val) {
@@ -58,6 +61,8 @@ static uint32_t v7m_mrs_xpsr(CPUARMState *env, uint32_t reg, unsigned el) return xpsr_read(env) & mask; } +#endif +uint32_t arm_v7m_mrs_control (CPUARMState *env,uint32_t secure) {uint32_t value = env->v7m.control[secure];
@@ -69,6 +74,40 @@ uint32_t arm_v7m_mrs_control(CPUARMState *env, uint32_t secure)return value; } +#if defined(CONFIG_USER_ONLY ) || !defined(CONFIG_ARM_V7M ) + +void HELPER (v7m_bxns )(CPUARMState *env,uint32_t dest) +{ +/* translate.c should never generate calls here in user-only mode */ +g_assert_not_reached (); +} + +void HELPER (v7m_blxns )(CPUARMState *env,uint32_t dest) +{ +/* translate.c should never generate calls here in user-only mode */ +g_assert_not_reached (); +} + +void HELPER (v7m_preserve_fp_state )(CPUARMState *env) +{ +/* translate.c should never generate calls here in user-only mode */ +g_assert_not_reached (); +} + +void HELPER (v7m_vlstm )(CPUARMState *env,uint32_t fptr) +{ +/* translate.c should never generate calls here in user-only mode */ +g_assert_not_reached (); +} + +void HELPER (v7m_vlldm )(CPUARMState *env,uint32_t fptr) +{ +/* translate.c should never generate calls here in user-only mode */ +g_assert_not_reached (); +} + +#endif +#ifdef CONFIG_USER_ONLY void HELPER (v7m_msr )(CPUARMState *env,uint32_t maskreg,uint32_t val)
@@ -101,37 +140,6 @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)return 0 ; } } - -void HELPER (v7m_bxns )(CPUARMState *env,uint32_t dest) -{ -/* translate.c should never generate calls here in user-only mode */ -g_assert_not_reached (); -} - -void HELPER (v7m_blxns )(CPUARMState *env,uint32_t dest) -{ -/* translate.c should never generate calls here in user-only mode */ -g_assert_not_reached (); -} - -void HELPER (v7m_preserve_fp_state )(CPUARMState *env) -{ -/* translate.c should never generate calls here in user-only mode */ -g_assert_not_reached (); -} - -void HELPER (v7m_vlstm )(CPUARMState *env,uint32_t fptr) -{ -/* translate.c should never generate calls here in user-only mode */ -g_assert_not_reached (); -} - -void HELPER (v7m_vlldm )(CPUARMState *env,uint32_t fptr) -{ -/* translate.c should never generate calls here in user-only mode */ -g_assert_not_reached (); -} -uint32_t HELPER (v7m_tt )(CPUARMState *env,uint32_t addr,uint32_t op) {/*
@@ -160,7 +168,28 @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate) return ARMMMUIdx_MUser; } -#else /* !CONFIG_USER_ONLY */ +#elif !defined(CONFIG_ARM_V7M) + +void HELPER (v7m_msr )(CPUARMState *env,uint32_t maskreg,uint32_t val) +{ +g_assert_not_reached (); +} + +uint32_t HELPER (v7m_mrs )(CPUARMState *env,uint32_t reg) +{ +g_assert_not_reached (); +} +uint32_t HELPER (v7m_tt )(CPUARMState *env,uint32_t addr,uint32_t op) +{ +g_assert_not_reached (); +} + +ARMMMUIdx arm_v7m_mmu_idx_for_secstate (CPUARMState *env,bool secstate) +{ +g_assert_not_reached (); +} + +#else static ARMMMUIdx arm_v7m_mmu_idx_all (CPUARMState *env,bool secstate,bool priv,bool negpri)
Signature · 1 line
2.44.0
PATCH v3 3/3 target/arm/Kconfig: Stop requiring CONFIG_ARM_V7M
In reply to Thomas HuthNow that we made sure that ARM_V7M code only gets compiled if really needed, we can drop the hard requirement for CONFIG_ARM_V7M in the Kconfig file.
--- target/arm/Kconfig | 4 ---- 1 file changed, 4 deletions(-)
target/arm/Kconfig +0 -4
@@ -2,10 +2,6 @@ config ARM bool select ARM_COMPATIBLE_SEMIHOSTING if TCG - # We need to select this until we move m_helper.c and the - # translate.c v7m helpers under ARM_V7M. - select ARM_V7M if TCG - config AARCH64 bool select ARM
Signature · 1 line
2.44.0
Peter Maydell
AppliedQuoted 10 lines · Thomas Huth
We've got a switch to disable v7m code since a long time - but it currently cannot be disabled since linking then fails due to missing functions. But thanks to the clean-ups that have been done during the past years, it's not that difficult anymore to finally make it possible to disable
CONFIG_ARM_V7M: We just have to move some v7m-related code out ofcpu32.cto a separate file (that we only compile if the switchCONFIG_ARM_V7Mis enabled) and make sure to use the stub functions inm_helper.cif it is disabled. Then we can finally remove the hard-coded "selectARM_V7M" from theKconfigfile.
I've applied patch 1 to target-arm.next; thanks.
-- PMM