summaryrefslogtreecommitdiff
path: root/nuttx/arch/arm/src/armv7-m
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/arch/arm/src/armv7-m')
-rw-r--r--nuttx/arch/arm/src/armv7-m/svcall.h13
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_initialstate.c57
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_svcall.c59
3 files changed, 62 insertions, 67 deletions
diff --git a/nuttx/arch/arm/src/armv7-m/svcall.h b/nuttx/arch/arm/src/armv7-m/svcall.h
index 13b9935a0..f6b068f86 100644
--- a/nuttx/arch/arm/src/armv7-m/svcall.h
+++ b/nuttx/arch/arm/src/armv7-m/svcall.h
@@ -57,9 +57,9 @@
#ifdef CONFIG_NUTTX_KERNEL
# ifndef CONFIG_SYS_RESERVED
-# error "CONFIG_SYS_RESERVED must be defined to the value 4"
-# elif CONFIG_SYS_RESERVED != 4
-# error "CONFIG_SYS_RESERVED must have the value 4"
+# error "CONFIG_SYS_RESERVED must be defined to the value 5"
+# elif CONFIG_SYS_RESERVED != 5
+# error "CONFIG_SYS_RESERVED must have the value 5"
# endif
#endif
@@ -93,6 +93,13 @@
*/
#define SYS_syscall_return (3)
+
+/* SYS call 3:
+ *
+ * void up_task_start(main_t taskentry, int argc, FAR char *argv[]) noreturn_function;
+ */
+
+#define SYS_task_start (4)
#endif
/************************************************************************************
diff --git a/nuttx/arch/arm/src/armv7-m/up_initialstate.c b/nuttx/arch/arm/src/armv7-m/up_initialstate.c
index 6f9abcd31..41828af5b 100644
--- a/nuttx/arch/arm/src/armv7-m/up_initialstate.c
+++ b/nuttx/arch/arm/src/armv7-m/up_initialstate.c
@@ -126,63 +126,20 @@ void up_initial_state(struct tcb_s *tcb)
#endif
#endif /* CONFIG_PIC */
-#ifdef CONFIG_ARMV7M_CMNVECTOR
- /* 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.
- *
- * If FPU support is not configured, set the bit that indicates that
- * the context does not include the volatile FP registers.
+ /* All tasks start via a stub function in kernel space. So all
+ * tasks must start in privileged thread mode. If CONFIG_NUTTX_KERNEL
+ * is defined, then that stub function will switch to unprivileged
+ * mode before transferring control to the user task.
*/
- xcp->regs[REG_EXC_RETURN] = EXC_RETURN_BASE | EXC_RETURN_THREAD_MODE;
+ xcp->regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
-#ifndef CONFIG_ARCH_FPU
-
- xcp->regs[REG_EXC_RETURN] |= EXC_RETURN_STD_CONTEXT;
-
-#else
+#if defined(CONFIG_ARMV7M_CMNVECTOR) && defined(CONFIG_ARCH_FPU)
xcp->regs[REG_FPSCR] = 0; // XXX initial FPSCR should be configurable
xcp->regs[REG_FPReserved] = 0;
-#endif /* CONFIG_ARCH_FPU */
-
-#ifdef CONFIG_NUTTX_KERNEL
- if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
- {
- /* It is a normal task or a pthread. Set user mode */
-
- xcp->regs[REG_EXC_RETURN] |= EXC_RETURN_PROCESS_STACK;
- }
-#endif /* CONFIG_NUTTX_KERNEL */
-
-#else /* CONFIG_ARMV7M_CMNVECTOR */
-
- /* 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 /* CONFIG_NUTTX_KERNEL */
-#endif /* CONFIG_ARMV7M_CMNVECTOR */
+#endif /* CONFIG_ARMV7M_CMNVECTOR && CONFIG_ARCH_FPU */
/* Enable or disable interrupts, based on user configuration */
diff --git a/nuttx/arch/arm/src/armv7-m/up_svcall.c b/nuttx/arch/arm/src/armv7-m/up_svcall.c
index 8321cd3bb..8f7efc1da 100644
--- a/nuttx/arch/arm/src/armv7-m/up_svcall.c
+++ b/nuttx/arch/arm/src/armv7-m/up_svcall.c
@@ -237,9 +237,9 @@ int up_svcall(int irq, FAR void *context)
}
break;
- /* R0=SYS_syscall_return: This a switch context command:
+ /* R0=SYS_syscall_return: This a syscall return command:
*
- * void up_sycall_return(void);
+ * void up_syscall_return(void);
*
* At this point, the following values are saved in context:
*
@@ -256,23 +256,54 @@ int up_svcall(int irq, FAR void *context)
/* Make sure that there is a saved syscall return address. */
- svcdbg("sysreturn: %08x excreturn: %08x\n",
- rtcb->xcp.sysreturn, rtcb->xcp.excreturn);
DEBUGASSERT(rtcb->xcp.sysreturn != 0);
/* Setup to return to the saved syscall return address in
* the original mode.
*/
- current_regs[REG_PC] = rtcb->xcp.sysreturn;
- current_regs[REG_EXC_RETURN] = rtcb->xcp.excreturn;
- rtcb->xcp.sysreturn = 0;
+ regs[REG_PC] = rtcb->xcp.sysreturn;
+ regs[REG_EXC_RETURN] = rtcb->xcp.excreturn;
+ rtcb->xcp.sysreturn = 0;
/* The return value must be in R0-R1. dispatch_syscall() temporarily
* moved the value for R0 into R2.
*/
- current_regs[REG_R0] = current_regs[REG_R2];
+ regs[REG_R0] = regs[REG_R2];
+ }
+ break;
+#endif
+
+ /* R0=SYS_task_start: This a user task start
+ *
+ * void up_task_start(main_t taskentry, int argc, FAR char *argv[]) noreturn_function;
+ *
+ * At this point, the following values are saved in context:
+ *
+ * R0 = SYS_task_start
+ * R1 = taskentry
+ * R2 = argc
+ * R3 = argv
+ */
+
+#ifdef CONFIG_NUTTX_KERNEL
+ case SYS_task_start:
+ {
+ /* Set up to return to the user-space task start-up function in
+ * unprivileged mode.
+ */
+
+ regs[REG_PC] = (uint32_t)USERSPACE->task_startup;
+ regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
+
+ /* Change the paramter ordering to match the expection of struct
+ * userpace_s task_startup:
+ */
+
+ regs[REG_R0] = regs[REG_R1]; /* Task entry */
+ regs[REG_R1] = regs[REG_R2]; /* argc */
+ regs[REG_R2] = regs[REG_R3]; /* argv */
}
break;
#endif
@@ -289,7 +320,7 @@ int up_svcall(int irq, FAR void *context)
/* Verify that the SYS call number is within range */
- DEBUGASSERT(current_regs[REG_R0] < SYS_maxsyscall);
+ DEBUGASSERT(regs[REG_R0] < SYS_maxsyscall);
/* Make sure that we got here that there is a no saved syscall
* return address. We cannot yet handle nested system calls.
@@ -299,15 +330,15 @@ int up_svcall(int irq, FAR void *context)
/* Setup to return to dispatch_syscall in privileged mode. */
- rtcb->xcp.sysreturn = regs[REG_PC];
- rtcb->xcp.excreturn = current_regs[REG_EXC_RETURN];
+ rtcb->xcp.sysreturn = regs[REG_PC];
+ rtcb->xcp.excreturn = regs[REG_EXC_RETURN];
- current_regs[REG_PC] = (uint32_t)dispatch_syscall;
- current_regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
+ regs[REG_PC] = (uint32_t)dispatch_syscall;
+ regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
/* Offset R0 to account for the reserved values */
- current_regs[REG_R0] -= CONFIG_SYS_RESERVED;
+ regs[REG_R0] -= CONFIG_SYS_RESERVED;
#else
slldbg("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
#endif