Cortex-M Execution Modes and Stacks

The Cortex-M architecture includes features that are useful for a multitasking kernel. The CPU can be running in handler (privileged) mode, which can access all CPU instructions and states, or in thread mode, where only non-privileged instructions may be executed. The Cortex-M CPU also has two stack pointers: a system stack pointer and a process stack pointer.

When processing exceptions, the Cortex-M CPU runs in handler mode and uses the system stack. Non-exception code (“normal code”) can run in either handler or thread mode, depending on how the system is set up. When using REXIS, once REXIS_SysStart is called, the REXIS kernel takes over and will set up the system in the way in which it wishes to operate:

 

Cortex-M Modes

Possible Stack Pointer

Possible Usage

REXIS Usage

Handler

System stack pointer, or Thread stack pointer

Interrupt and exception handlers; normal CPU code

Interrupt and exception handlers, and kernel code

Thread

Thread stack pointer

Normal CPU code

Task code