17#ifndef ZEPHYR_INCLUDE_ARCH_ARM_ARM_M_SWITCH_H_
18#define ZEPHYR_INCLUDE_ARCH_ARM_ARM_M_SWITCH_H_
21#include <cmsis_core.h>
36#ifdef CONFIG_ARM_FP_CLOBBER_WORKAROUND
37#define _R7_CLOBBER_OPT(expr) expr
39#define _R7_CLOBBER_OPT(expr)
46#if defined(CONFIG_CPU_CORTEX_M4) || defined(CONFIG_CPU_CORTEX_M7) || defined(CONFIG_ARMV8_M_DSP)
47#define _ARM_M_SWITCH_HAVE_DSP
126void z_arm_configure_dynamic_mpu_regions(
struct k_thread *thread);
141 void *out, *in, *lr_save, *lr_fixup;
159#ifdef CONFIG_MULTITHREADING
185 void z_check_stack_sentinel(
void);
188 z_check_stack_sentinel();
198 if (_kernel.ready_q.cache == _current) {
214 if ((((
uint32_t)isr_lr & 0xFFFFFF00U) == 0xFFFFFF00U)
215 && (((
uint32_t)isr_lr & 0xC) == 0xC)) {
236#if defined(CONFIG_USERSPACE) || defined(CONFIG_MPU_STACK_GUARD)
237 z_arm_configure_dynamic_mpu_regions(_current);
240#ifdef CONFIG_THREAD_LOCAL_STORAGE
241 z_arm_tls_ptr = _current->tls;
244#if defined(CONFIG_USERSPACE) && defined(CONFIG_USE_SWITCH)
249 extern uint32_t arm_m_switch_control;
250 CONTROL_Type control = {.w = __get_CONTROL()};
252 __ASSERT_NO_MSG(!control.b.nPRIV);
253 arm_m_switch_control = control.w | (_current->arch.mode & 1);
266 __asm__
volatile(_R7_CLOBBER_OPT(
"push {r7};")
278 "mov r2, #0x01000000;"
280#ifdef CONFIG_BUILTIN_STACK_GUARD
303 " vldm r4!, {s0-s31};"
309#if defined(CONFIG_USERSPACE) && defined(CONFIG_USE_SWITCH)
310 " ldr r8, =arm_m_switch_control;"
323#if defined(CONFIG_USERSPACE) && defined(CONFIG_USE_SWITCH)
332#ifdef CONFIG_BUILTIN_STACK_GUARD
338#ifdef _ARM_M_SWITCH_HAVE_DSP
339 "msr apsr_nzcvqg, r2;"
341 "msr apsr_nzcvq, r2;"
347 _R7_CLOBBER_OPT(
"pop {r7};")::
"r"(r4),
349 :
"r6",
"r8",
"r9",
"r10",
350#ifndef CONFIG_ARM_FP_CLOBBER_WORKAROUND
356#ifdef CONFIG_USE_SWITCH
bool arm_m_iciit_check(uint32_t msp, uint32_t psp, uint32_t lr)
Recover an interrupted IT/ICI instruction after a context switch.
static void arm_m_exc_tail(void)
ISR-tail helper that patches the stacked LR for deferred switch fixup.
Definition arm-m-switch.h:157
void * arm_m_new_stack(char *base, uint32_t sz, void *entry, void *arg0, void *arg1, void *arg2, void *arg3)
Create an initial switch frame on a new thread's stack.
static ALWAYS_INLINE void arm_m_switch(void *switch_to, void **switched_from)
Core Cortex-M context switch routine.
Definition arm-m-switch.h:234
static ALWAYS_INLINE void arch_switch(void *switch_to, void **switched_from)
Public arch-level wrapper for the Cortex-M switch routine.
Definition arm-m-switch.h:366
void arm_m_iciit_stub(void)
Undefined-instruction stub used to force IT/ICI recovery.
void arm_m_exc_exit(void)
Assembly stub that completes the Cortex-M context restore.
uint32_t * arm_m_exc_lr_ptr
Pointer to the stacked LR word used by the ISR tail fixup path.
struct arm_m_cs_ptrs arm_m_cs_ptrs
Global instance with current callee-saved frame pointers.
bool arm_m_must_switch(void)
Evaluate whether an interrupt should trigger a context switch.
uint32_t arm_m_switch_stack_buffer
Backing storage used when relocating stacks during switch operations.
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:154
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Thread Structure.
Definition thread.h:258