arch: aarch32: cortex_m/r: Add arch exception helper
Create z_arm_preempted_thread_in_user_mode to abstract the implementation differences between Cortex-M and R to determine if an exception came from userspace. Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
This commit is contained in:
parent
50a6dafdc5
commit
379bb70728
3 changed files with 27 additions and 2 deletions
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
#include <kernel.h>
|
||||
#include <kernel_arch_data.h>
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
|
||||
|
||||
|
@ -83,9 +84,9 @@ void z_do_kernel_oops(const z_arch_esf_t *esf)
|
|||
unsigned int reason = esf->basic.r0;
|
||||
|
||||
#if defined(CONFIG_USERSPACE)
|
||||
if ((__get_CONTROL() & CONTROL_nPRIV_Msk) == CONTROL_nPRIV_Msk) {
|
||||
if (z_arm_preempted_thread_in_user_mode(esf)) {
|
||||
/*
|
||||
* Exception triggered from nPRIV mode.
|
||||
* Exception triggered from user mode.
|
||||
*
|
||||
* User mode is only allowed to induce oopses and stack check
|
||||
* failures via software-triggered system fatal exceptions.
|
||||
|
|
|
@ -38,6 +38,17 @@ static ALWAYS_INLINE bool arch_is_in_isr(void)
|
|||
return (_kernel.cpus[0].nested != 0U);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_USERSPACE)
|
||||
/*
|
||||
* This function is used by privileged code to determine if the thread
|
||||
* associated with the stack frame is in user mode.
|
||||
*/
|
||||
static ALWAYS_INLINE bool z_arm_preempted_thread_in_user_mode(const z_arch_esf_t *esf)
|
||||
{
|
||||
return ((esf->basic.xpsr & CPSR_M_Msk) == CPSR_M_USR);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Setup system exceptions
|
||||
*
|
||||
|
|
|
@ -73,6 +73,19 @@ static ALWAYS_INLINE bool arch_is_in_nested_exception(const z_arch_esf_t *esf)
|
|||
return (esf->basic.xpsr & IPSR_ISR_Msk) ? (true) : (false);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_USERSPACE)
|
||||
/**
|
||||
* @brief Is the thread in unprivileged mode
|
||||
*
|
||||
* @param esf the exception stack frame (unused)
|
||||
* @return true if the current thread was in unprivileged mode
|
||||
*/
|
||||
static ALWAYS_INLINE bool z_arm_preempted_thread_in_user_mode(const z_arch_esf_t *esf)
|
||||
{
|
||||
return z_arm_thread_is_in_user_mode();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Setup system exceptions
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue