diff options
Diffstat (limited to 'nuttx/arch/arm/src/cortexm3/up_initialstate.c')
-rw-r--r-- | nuttx/arch/arm/src/cortexm3/up_initialstate.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/nuttx/arch/arm/src/cortexm3/up_initialstate.c b/nuttx/arch/arm/src/cortexm3/up_initialstate.c index 40f98bf8c..094a3adba 100644 --- a/nuttx/arch/arm/src/cortexm3/up_initialstate.c +++ b/nuttx/arch/arm/src/cortexm3/up_initialstate.c @@ -47,7 +47,9 @@ #include "up_internal.h" #include "up_arch.h" + #include "psr.h" +#include "exc_return.h" /**************************************************************************** * Pre-processor Definitions @@ -124,6 +126,28 @@ void up_initial_state(_TCB *tcb) #endif #endif + /* Set privileged- or unprivileged-mode, depending on how NuttX is + * configured and what kind of thread is being started. + * + * If the kernel build is not selected, then all threads run in + * privileged thread mode. + */ + +#ifdef CONFIG_NUTTX_KERNEL + if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL) + { + /* It is a kernel thread.. set privileged thread mode */ + + xcp->regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR; + } + else + { + /* It is a normal task or a pthread. Set user mode */ + + xcp->regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR; + } +#endif + /* Enable or disable interrupts, based on user configuration */ # ifdef CONFIG_SUPPRESS_INTERRUPTS |