diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index f42273bbc10..2cd72950039 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -76,6 +76,38 @@ config ISA_ARM processor start-up. Much of its functionality was subsumed into T32 with the introduction of Thumb-2 technology. +config ASSEMBLER_ISA_THUMB2 + bool + default y if ISA_THUMB2 && !ISA_ARM + depends on !ISA_ARM + help + This helper symbol specifies the default target instruction set for + the assembler. + + When only the Thumb-2 ISA is supported (i.e. on Cortex-M cores), the + assembler must use the Thumb-2 instruction set. + + When both the Thumb-2 and ARM ISAs are supported (i.e. on Cortex-A + and Cortex-R cores), the assembler must use the ARM instruction set + because the architecture assembly code makes use of the ARM + instructions. + +config COMPILER_ISA_THUMB2 + bool "Compile C/C++ functions using Thumb-2 instruction set" + depends on ISA_THUMB2 + default y + help + This option configures the compiler to compile all C/C++ functions + using the Thumb-2 instruction set. + + N.B. The scope of this symbol is not necessarily limited to the C and + C++ languages; in fact, this symbol refers to all forms of + "compiled" code. + + When an additional natively-compiled language support is added + in the future, this symbol shall also specify the Thumb-2 + instruction set for that language. + config NUM_IRQS int diff --git a/arch/arm/core/aarch32/thread.c b/arch/arm/core/aarch32/thread.c index 7563b9b893b..e7751d226bc 100644 --- a/arch/arm/core/aarch32/thread.c +++ b/arch/arm/core/aarch32/thread.c @@ -135,9 +135,13 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack, thread->callee_saved.psp = (u32_t)pInitCtx; #if defined(CONFIG_CPU_CORTEX_R) pInitCtx->basic.lr = (u32_t)pInitCtx->basic.pc; - thread->callee_saved.spsr = A_BIT | T_BIT | MODE_SYS; - thread->callee_saved.lr = (u32_t)pInitCtx->basic.pc; + thread->callee_saved.spsr = A_BIT | MODE_SYS; +#if defined(CONFIG_COMPILER_ISA_THUMB2) + thread->callee_saved.spsr |= T_BIT; #endif + + thread->callee_saved.lr = (u32_t)pInitCtx->basic.pc; +#endif /* CONFIG_CPU_CORTEX_R */ thread->arch.basepri = 0; #if defined(CONFIG_USERSPACE) || defined(CONFIG_FP_SHARING) diff --git a/cmake/compiler/gcc/target_arm.cmake b/cmake/compiler/gcc/target_arm.cmake index 5b9d31939a9..5aa5dbb10c6 100644 --- a/cmake/compiler/gcc/target_arm.cmake +++ b/cmake/compiler/gcc/target_arm.cmake @@ -7,14 +7,13 @@ if(CONFIG_ARM64) -mcpu=${GCC_M_CPU} ) else() - list(APPEND TOOLCHAIN_C_FLAGS - -mthumb - -mcpu=${GCC_M_CPU} - ) - list(APPEND TOOLCHAIN_LD_FLAGS - -mthumb - -mcpu=${GCC_M_CPU} - ) + list(APPEND TOOLCHAIN_C_FLAGS -mcpu=${GCC_M_CPU}) + list(APPEND TOOLCHAIN_LD_FLAGS -mcpu=${GCC_M_CPU}) + + if(CONFIG_COMPILER_ISA_THUMB2) + list(APPEND TOOLCHAIN_C_FLAGS -mthumb) + list(APPEND TOOLCHAIN_LD_FLAGS -mthumb) + endif() # Defines a mapping from GCC_M_CPU to FPU diff --git a/include/toolchain/gcc.h b/include/toolchain/gcc.h index 7c1fd8b06be..b5efc80165c 100644 --- a/include/toolchain/gcc.h +++ b/include/toolchain/gcc.h @@ -232,28 +232,24 @@ do { \ #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) -#if defined(CONFIG_ISA_THUMB2) +#if defined(CONFIG_ASSEMBLER_ISA_THUMB2) #define FUNC_CODE() .thumb; #define FUNC_INSTR(a) -#elif defined(CONFIG_ISA_ARM) +#else #define FUNC_CODE() .code 32 #define FUNC_INSTR(a) -#else - -#error unknown instruction set - -#endif /* ISA */ +#endif /* CONFIG_ASSEMBLER_ISA_THUMB2 */ #else #define FUNC_CODE() #define FUNC_INSTR(a) -#endif /* !CONFIG_ARM */ +#endif /* CONFIG_ARM && !CONFIG_ARM64 */ #endif /* _ASMLANGUAGE */ @@ -359,14 +355,16 @@ do { \ #endif /* _ASMLANGUAGE */ -#if defined(CONFIG_ARM) && defined(_ASMLANGUAGE) -#if defined(CONFIG_ISA_THUMB2) +#if defined(_ASMLANGUAGE) +#if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) +#if defined(CONFIG_ASSEMBLER_ISA_THUMB2) /* '.syntax unified' is a gcc-ism used in thumb-2 asm files */ #define _ASM_FILE_PROLOGUE .text; .syntax unified; .thumb #else #define _ASM_FILE_PROLOGUE .text; .code 32 -#endif -#endif +#endif /* CONFIG_ASSEMBLER_ISA_THUMB2 */ +#endif /* CONFIG_ARM && !CONFIG_ARM64 */ +#endif /* _ASMLANGUAGE */ /* * These macros generate absolute symbols for GCC