arch: aarch32: cortex_m/r: Add arch helper function

Create z_arm_thread_is_user_mode to abstract the implementation
differences between Cortex-M and R to determine if the current thread is
in user or kernel mode.

Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
This commit is contained in:
Bradley Bolen 2021-06-23 10:32:03 -04:00 committed by Christopher Friedt
commit 50a6dafdc5
7 changed files with 48 additions and 5 deletions

View file

@ -31,6 +31,10 @@ static ALWAYS_INLINE void arch_nop(void)
__asm__ volatile("nop");
}
#if defined(CONFIG_USERSPACE)
extern bool z_arm_thread_is_in_user_mode(void);
#endif
#endif
#ifdef __cplusplus

View file

@ -26,7 +26,7 @@
#include <zephyr/types.h>
#include <stdbool.h>
#include <arch/arm/aarch32/cortex_m/cmsis.h>
#include <arch/arm/aarch32/misc.h>
#ifdef __cplusplus
extern "C" {
@ -165,6 +165,7 @@ static inline uintptr_t arch_syscall_invoke0(uintptr_t call_id)
static inline bool arch_is_user_context(void)
{
#if defined(CONFIG_CPU_CORTEX_M)
uint32_t value;
/* check for handler mode */
@ -172,10 +173,9 @@ static inline bool arch_is_user_context(void)
if (value) {
return false;
}
#endif
/* if not handler mode, return mode information */
__asm__ volatile("mrs %0, CONTROL\n\t" : "=r"(value));
return (value & CONTROL_nPRIV_Msk) ? true : false;
return z_arm_thread_is_in_user_mode();
}
#ifdef __cplusplus