2013-02-16 16:32:19 +00:00
|
|
|
/****************************************************************************
|
2020-04-30 15:19:35 -06:00
|
|
|
* arch/arm/src/armv6-m/arm_svcall.c
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2020-04-30 10:58:54 -06:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2020-04-30 10:58:54 -06:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2020-04-30 10:58:54 -06:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
2020-11-21 09:22:01 +09:00
|
|
|
#include <inttypes.h>
|
2013-02-16 16:32:19 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <debug.h>
|
2022-02-25 02:46:21 +08:00
|
|
|
#include <syscall.h>
|
2013-02-16 16:32:19 +00:00
|
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
#include <nuttx/sched.h>
|
|
|
|
|
|
2023-12-19 13:03:51 +08:00
|
|
|
#include "sched/sched.h"
|
2019-11-28 12:47:36 -06:00
|
|
|
#include "signal/signal.h"
|
2013-03-06 19:56:32 +00:00
|
|
|
#include "exc_return.h"
|
2020-04-30 19:20:29 -06:00
|
|
|
#include "arm_internal.h"
|
2013-02-16 16:32:19 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: dispatch_syscall
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2013-03-21 00:25:17 +00:00
|
|
|
* Call the stub function corresponding to the system call. NOTE the non-
|
|
|
|
|
* standard parameter passing:
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2013-03-21 00:25:17 +00:00
|
|
|
* R0 = SYS_ call number
|
|
|
|
|
* R1 = parm0
|
|
|
|
|
* R2 = parm1
|
|
|
|
|
* R3 = parm2
|
|
|
|
|
* R4 = parm3
|
|
|
|
|
* R5 = parm4
|
|
|
|
|
* R6 = parm5
|
|
|
|
|
*
|
|
|
|
|
* The values of R4-R5 may be preserved in the proxy called by the user
|
|
|
|
|
* code if they are used (but otherwise will not be).
|
|
|
|
|
*
|
|
|
|
|
* Register usage:
|
|
|
|
|
*
|
|
|
|
|
* R0 - Need not be preserved.
|
|
|
|
|
* R1-R3 - Need to be preserved until the stub is called. The values of
|
|
|
|
|
* R0 and R1 returned by the stub must be preserved.
|
|
|
|
|
* R4-R11 must be preserved to support the expectations of the user-space
|
|
|
|
|
* callee. R4-R6 may have been preserved by the proxy, but don't know
|
|
|
|
|
* for sure.
|
|
|
|
|
* R12 - Need not be preserved
|
|
|
|
|
* R13 - (stack pointer)
|
|
|
|
|
* R14 - Need not be preserved
|
|
|
|
|
* R15 - (PC)
|
2013-03-06 20:54:59 +00:00
|
|
|
*
|
2013-02-16 16:32:19 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-08-28 12:09:49 -06:00
|
|
|
#ifdef CONFIG_LIB_SYSCALL
|
2013-03-06 19:56:32 +00:00
|
|
|
static void dispatch_syscall(void) naked_function;
|
|
|
|
|
static void dispatch_syscall(void)
|
2013-02-16 16:32:19 +00:00
|
|
|
{
|
2013-03-06 19:56:32 +00:00
|
|
|
__asm__ __volatile__
|
|
|
|
|
(
|
2013-03-13 17:32:37 +00:00
|
|
|
" push {r4, r5}\n" /* Save R4 and R5 */
|
2013-03-21 00:25:17 +00:00
|
|
|
" sub sp, sp, #12\n" /* Create a stack frame to hold 3 parms */
|
|
|
|
|
" str r4, [sp, #0]\n" /* Move parameter 4 (if any) into position */
|
|
|
|
|
" str r5, [sp, #4]\n" /* Move parameter 5 (if any) into position */
|
|
|
|
|
" str r6, [sp, #8]\n" /* Move parameter 6 (if any) into position */
|
2013-03-13 17:32:37 +00:00
|
|
|
" mov r5, lr\n" /* Save lr in R5 */
|
2013-03-06 20:54:59 +00:00
|
|
|
" ldr r4, =g_stublookup\n" /* R4=The base of the stub lookup table */
|
|
|
|
|
" lsl r0, r0, #2\n" /* R0=Offset of the stub for this syscall */
|
|
|
|
|
" ldr r4, [r4, r0]\n" /* R4=Address of the stub for this syscall */
|
2013-03-13 17:32:37 +00:00
|
|
|
" blx r5\n" /* Call the stub (modifies lr) */
|
|
|
|
|
" mov lr, r5\n" /* Restore lr */
|
2013-03-21 00:25:17 +00:00
|
|
|
" add sp, sp, #12\n" /* Destroy the stack frame */
|
|
|
|
|
" pop {r4, r5}\n" /* Recover R4 and R5 */
|
|
|
|
|
" mov r2, r0\n" /* R2=Save return value in R2 */
|
2022-02-22 15:25:56 +08:00
|
|
|
" mov r0, %0\n" /* R0=SYS_syscall_return */
|
|
|
|
|
" svc %1\n"::"i"(SYS_syscall_return),
|
|
|
|
|
"i"(SYS_syscall) /* Return from the SYSCALL */
|
2013-03-06 19:56:32 +00:00
|
|
|
);
|
2013-02-16 16:32:19 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-01 08:50:23 -06:00
|
|
|
* Name: arm_svcall
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This is SVCall exception handler that performs context switching
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2022-04-17 13:57:58 +08:00
|
|
|
int arm_svcall(int irq, void *context, void *arg)
|
2013-02-16 16:32:19 +00:00
|
|
|
{
|
2024-07-05 19:39:58 +08:00
|
|
|
struct tcb_s *tcb = this_task();
|
2015-10-06 16:23:47 -06:00
|
|
|
uint32_t *regs = (uint32_t *)context;
|
2013-03-16 00:34:43 +00:00
|
|
|
uint32_t cmd;
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2013-03-16 00:34:43 +00:00
|
|
|
cmd = regs[REG_R0];
|
2013-02-16 16:32:19 +00:00
|
|
|
|
|
|
|
|
/* The SVCall software interrupt is called with R0 = system call command
|
|
|
|
|
* and R1..R7 = variable number of arguments depending on the system call.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-06-16 08:12:38 -06:00
|
|
|
#ifdef CONFIG_DEBUG_SYSCALL_INFO
|
2023-05-20 06:32:34 +08:00
|
|
|
# ifndef CONFIG_DEBUG_SVCALL
|
2013-03-16 00:34:43 +00:00
|
|
|
if (cmd > SYS_switch_context)
|
2023-05-20 06:32:34 +08:00
|
|
|
# endif
|
2013-03-16 00:34:43 +00:00
|
|
|
{
|
2016-06-20 11:59:15 -06:00
|
|
|
svcinfo("SVCALL Entry: regs: %p cmd: %d\n", regs, cmd);
|
|
|
|
|
svcinfo(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
|
|
|
|
regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
|
|
|
|
regs[REG_R4], regs[REG_R5], regs[REG_R6], regs[REG_R7]);
|
|
|
|
|
svcinfo(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
|
|
|
|
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
|
|
|
|
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
|
|
|
|
svcinfo(" PSR: %08x PRIMASK: %08x EXC_RETURN: %08x\n",
|
|
|
|
|
regs[REG_XPSR], regs[REG_PRIMASK], regs[REG_EXC_RETURN]);
|
2013-03-16 00:34:43 +00:00
|
|
|
}
|
2013-02-25 23:00:19 +00:00
|
|
|
#endif
|
2013-02-16 16:32:19 +00:00
|
|
|
|
|
|
|
|
/* Handle the SVCall according to the command in R0 */
|
|
|
|
|
|
2013-03-16 00:34:43 +00:00
|
|
|
switch (cmd)
|
2013-02-16 16:32:19 +00:00
|
|
|
{
|
2013-03-16 17:37:40 +00:00
|
|
|
/* R0=SYS_restore_context: This a restore context command:
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2020-04-30 10:58:54 -06:00
|
|
|
* void arm_fullcontextrestore(uint32_t *restoreregs)
|
|
|
|
|
* noreturn_function;
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
|
|
|
|
* At this point, the following values are saved in context:
|
|
|
|
|
*
|
|
|
|
|
* R0 = SYS_restore_context
|
|
|
|
|
* R1 = restoreregs
|
|
|
|
|
*
|
2024-09-13 10:57:38 +08:00
|
|
|
* In this case, we simply need to set current_regs to restore register
|
|
|
|
|
* area referenced in the saved R1. context == current_regs is the
|
|
|
|
|
* normal exception return. By setting current_regs = context[R1], we
|
2020-04-30 10:58:54 -06:00
|
|
|
* force the return to the saved context referenced in R1.
|
2013-02-16 16:32:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
case SYS_restore_context:
|
|
|
|
|
{
|
|
|
|
|
DEBUGASSERT(regs[REG_R1] != 0);
|
2024-07-05 19:39:58 +08:00
|
|
|
tcb->xcp.regs = (uint32_t *)regs[REG_R1];
|
2013-02-16 16:32:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-03-16 17:37:40 +00:00
|
|
|
/* R0=SYS_switch_context: This a switch context command:
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
2022-03-01 01:06:24 +08:00
|
|
|
* void arm_switchcontext(uint32_t **saveregs,
|
|
|
|
|
* uint32_t *restoreregs);
|
2013-02-16 16:32:19 +00:00
|
|
|
*
|
|
|
|
|
* At this point, the following values are saved in context:
|
|
|
|
|
*
|
2013-03-06 19:56:32 +00:00
|
|
|
* R0 = SYS_switch_context
|
2013-02-16 16:32:19 +00:00
|
|
|
* R1 = saveregs
|
|
|
|
|
* R2 = restoreregs
|
|
|
|
|
*
|
|
|
|
|
* In this case, we do both: We save the context registers to the save
|
|
|
|
|
* register area reference by the saved contents of R1 and then set
|
2024-09-13 10:57:38 +08:00
|
|
|
* current_regs to the save register area referenced by the saved
|
2013-02-16 16:32:19 +00:00
|
|
|
* contents of R2.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
case SYS_switch_context:
|
|
|
|
|
{
|
|
|
|
|
DEBUGASSERT(regs[REG_R1] != 0 && regs[REG_R2] != 0);
|
2022-03-01 01:06:24 +08:00
|
|
|
*(uint32_t **)regs[REG_R1] = regs;
|
2024-07-05 19:39:58 +08:00
|
|
|
tcb->xcp.regs = (uint32_t *)regs[REG_R2];
|
2013-02-16 16:32:19 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-03-16 17:37:40 +00:00
|
|
|
/* R0=SYS_syscall_return: This a syscall return command:
|
2013-03-06 19:56:32 +00:00
|
|
|
*
|
2020-05-01 08:50:23 -06:00
|
|
|
* void arm_syscall_return(void);
|
2013-03-06 19:56:32 +00:00
|
|
|
*
|
|
|
|
|
* At this point, the following values are saved in context:
|
|
|
|
|
*
|
|
|
|
|
* R0 = SYS_syscall_return
|
|
|
|
|
*
|
|
|
|
|
* We need to restore the saved return address and return in
|
|
|
|
|
* unprivileged thread mode.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-08-28 14:52:14 -06:00
|
|
|
#ifdef CONFIG_LIB_SYSCALL
|
2013-03-06 19:56:32 +00:00
|
|
|
case SYS_syscall_return:
|
|
|
|
|
{
|
2024-07-15 17:52:00 +08:00
|
|
|
struct tcb_s *rtcb = this_task();
|
2013-03-17 16:13:28 +00:00
|
|
|
int index = (int)rtcb->xcp.nsyscalls - 1;
|
2013-03-06 19:56:32 +00:00
|
|
|
|
2013-03-16 00:34:43 +00:00
|
|
|
/* Make sure that there is a saved syscall return address. */
|
2013-03-06 19:56:32 +00:00
|
|
|
|
2013-03-17 16:13:28 +00:00
|
|
|
DEBUGASSERT(index >= 0);
|
2013-03-06 19:56:32 +00:00
|
|
|
|
|
|
|
|
/* Setup to return to the saved syscall return address in
|
2013-03-16 00:34:43 +00:00
|
|
|
* the original mode.
|
2013-03-06 19:56:32 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-03-17 16:13:28 +00:00
|
|
|
regs[REG_PC] = rtcb->xcp.syscall[index].sysreturn;
|
|
|
|
|
regs[REG_EXC_RETURN] = rtcb->xcp.syscall[index].excreturn;
|
2024-07-30 18:46:35 +08:00
|
|
|
regs[REG_CONTROL] = rtcb->xcp.syscall[index].ctrlreturn;
|
2013-03-17 16:13:28 +00:00
|
|
|
rtcb->xcp.nsyscalls = index;
|
2013-03-06 19:56:32 +00:00
|
|
|
|
2020-04-30 10:58:54 -06:00
|
|
|
/* The return value must be in R0-R1. dispatch_syscall()
|
|
|
|
|
* temporarily moved the value for R0 into R2.
|
2013-03-06 19:56:32 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-03-14 22:44:06 +00:00
|
|
|
regs[REG_R0] = regs[REG_R2];
|
2019-11-28 12:47:36 -06:00
|
|
|
|
|
|
|
|
/* Handle any signal actions that were deferred while processing
|
|
|
|
|
* the system call.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
rtcb->flags &= ~TCB_FLAG_SYSCALL;
|
2022-04-17 23:14:13 +08:00
|
|
|
nxsig_unmask_pendingsignal();
|
2013-03-14 22:44:06 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-03-16 17:37:40 +00:00
|
|
|
/* R0=SYS_task_start: This a user task start
|
2013-03-14 22:44:06 +00:00
|
|
|
*
|
2022-04-17 13:57:58 +08:00
|
|
|
* void up_task_start(main_t taskentry, int argc, char *argv[])
|
2020-04-30 10:58:54 -06:00
|
|
|
* noreturn_function;
|
2013-03-14 22:44:06 +00:00
|
|
|
*
|
|
|
|
|
* At this point, the following values are saved in context:
|
|
|
|
|
*
|
|
|
|
|
* R0 = SYS_task_start
|
|
|
|
|
* R1 = taskentry
|
|
|
|
|
* R2 = argc
|
|
|
|
|
* R3 = argv
|
|
|
|
|
*/
|
|
|
|
|
|
2014-08-29 14:47:22 -06:00
|
|
|
#ifdef CONFIG_BUILD_PROTECTED
|
2013-03-14 22:44:06 +00:00
|
|
|
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;
|
2023-07-05 21:37:14 +08:00
|
|
|
regs[REG_EXC_RETURN] = EXC_RETURN_THREAD;
|
2013-03-14 22:44:06 +00:00
|
|
|
|
2023-07-05 20:18:28 +08:00
|
|
|
/* Return unprivileged mode */
|
|
|
|
|
|
|
|
|
|
regs[REG_CONTROL] = getcontrol() | CONTROL_NPRIV;
|
|
|
|
|
|
2013-03-16 00:34:43 +00:00
|
|
|
/* Change the parameter ordering to match the expectation of struct
|
2013-03-14 22:44:06 +00:00
|
|
|
* 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 */
|
2013-03-06 19:56:32 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-03-16 17:37:40 +00:00
|
|
|
/* R0=SYS_pthread_start: This a user pthread start
|
|
|
|
|
*
|
2022-01-25 17:22:17 +08:00
|
|
|
* void up_pthread_start(pthread_startroutine_t entrypt,
|
|
|
|
|
* pthread_addr_t arg) noreturn_function;
|
2013-03-16 17:37:40 +00:00
|
|
|
*
|
|
|
|
|
* At this point, the following values are saved in context:
|
|
|
|
|
*
|
|
|
|
|
* R0 = SYS_pthread_start
|
2022-01-25 17:22:17 +08:00
|
|
|
* R1 = entrypt
|
|
|
|
|
* R2 = arg
|
2013-03-16 17:37:40 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-01-25 17:22:17 +08:00
|
|
|
#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
|
2013-03-16 17:37:40 +00:00
|
|
|
case SYS_pthread_start:
|
|
|
|
|
{
|
|
|
|
|
/* Set up to return to the user-space pthread start-up function in
|
|
|
|
|
* unprivileged mode.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-01-25 17:22:17 +08:00
|
|
|
regs[REG_PC] = (uint32_t)regs[REG_R1]; /* startup */
|
2023-07-05 21:37:14 +08:00
|
|
|
regs[REG_EXC_RETURN] = EXC_RETURN_THREAD;
|
2013-03-16 17:37:40 +00:00
|
|
|
|
2023-07-05 20:18:28 +08:00
|
|
|
/* Return unprivileged mode */
|
|
|
|
|
|
|
|
|
|
regs[REG_CONTROL] = getcontrol() | CONTROL_NPRIV;
|
|
|
|
|
|
2020-06-29 08:26:29 -06:00
|
|
|
/* Change the parameter ordering to match the expectation of the
|
|
|
|
|
* user space pthread_startup:
|
2013-03-16 17:37:40 +00:00
|
|
|
*/
|
|
|
|
|
|
2020-06-29 08:26:29 -06:00
|
|
|
regs[REG_R0] = regs[REG_R2]; /* pthread entry */
|
|
|
|
|
regs[REG_R1] = regs[REG_R3]; /* arg */
|
2013-03-16 17:37:40 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-03-17 00:40:49 +00:00
|
|
|
/* R0=SYS_signal_handler: This a user signal handler callback
|
|
|
|
|
*
|
|
|
|
|
* void signal_handler(_sa_sigaction_t sighand, int signo,
|
2022-04-17 13:57:58 +08:00
|
|
|
* siginfo_t *info, void *ucontext);
|
2013-03-17 00:40:49 +00:00
|
|
|
*
|
|
|
|
|
* At this point, the following values are saved in context:
|
|
|
|
|
*
|
|
|
|
|
* R0 = SYS_signal_handler
|
|
|
|
|
* R1 = sighand
|
|
|
|
|
* R2 = signo
|
|
|
|
|
* R3 = info
|
2018-08-24 07:11:18 -06:00
|
|
|
* R4 = ucontext
|
2013-03-17 00:40:49 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-04-29 14:52:05 -06:00
|
|
|
#ifdef CONFIG_BUILD_PROTECTED
|
2013-03-17 00:40:49 +00:00
|
|
|
case SYS_signal_handler:
|
|
|
|
|
{
|
2024-07-15 17:52:00 +08:00
|
|
|
struct tcb_s *rtcb = this_task();
|
2013-03-17 00:40:49 +00:00
|
|
|
|
|
|
|
|
/* Remember the caller's return address */
|
|
|
|
|
|
|
|
|
|
DEBUGASSERT(rtcb->xcp.sigreturn == 0);
|
|
|
|
|
rtcb->xcp.sigreturn = regs[REG_PC];
|
|
|
|
|
|
2020-02-20 11:53:33 +09:00
|
|
|
/* Set up to return to the user-space trampoline function in
|
2013-03-17 00:40:49 +00:00
|
|
|
* unprivileged mode.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
regs[REG_PC] = (uint32_t)USERSPACE->signal_handler;
|
2023-07-05 21:37:14 +08:00
|
|
|
regs[REG_EXC_RETURN] = EXC_RETURN_THREAD;
|
2013-03-17 00:40:49 +00:00
|
|
|
|
2023-07-05 20:18:28 +08:00
|
|
|
/* Return unprivileged mode */
|
|
|
|
|
|
|
|
|
|
regs[REG_CONTROL] = getcontrol() | CONTROL_NPRIV;
|
|
|
|
|
|
2013-03-17 00:40:49 +00:00
|
|
|
/* Change the parameter ordering to match the expectation of struct
|
|
|
|
|
* userpace_s signal_handler.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
regs[REG_R0] = regs[REG_R1]; /* sighand */
|
|
|
|
|
regs[REG_R1] = regs[REG_R2]; /* signal */
|
|
|
|
|
regs[REG_R2] = regs[REG_R3]; /* info */
|
2018-08-24 07:11:18 -06:00
|
|
|
regs[REG_R3] = regs[REG_R4]; /* ucontext */
|
2013-03-17 00:40:49 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* R0=SYS_signal_handler_return: This a user signal handler callback
|
|
|
|
|
*
|
|
|
|
|
* void signal_handler_return(void);
|
|
|
|
|
*
|
|
|
|
|
* At this point, the following values are saved in context:
|
|
|
|
|
*
|
|
|
|
|
* R0 = SYS_signal_handler_return
|
|
|
|
|
*/
|
|
|
|
|
|
2019-04-29 14:52:05 -06:00
|
|
|
#ifdef CONFIG_BUILD_PROTECTED
|
2013-03-17 00:40:49 +00:00
|
|
|
case SYS_signal_handler_return:
|
|
|
|
|
{
|
2024-07-15 17:52:00 +08:00
|
|
|
struct tcb_s *rtcb = this_task();
|
2013-03-17 00:40:49 +00:00
|
|
|
|
|
|
|
|
/* Set up to return to the kernel-mode signal dispatching logic. */
|
|
|
|
|
|
|
|
|
|
DEBUGASSERT(rtcb->xcp.sigreturn != 0);
|
|
|
|
|
|
|
|
|
|
regs[REG_PC] = rtcb->xcp.sigreturn;
|
2023-07-05 21:37:14 +08:00
|
|
|
regs[REG_EXC_RETURN] = EXC_RETURN_THREAD;
|
2023-07-05 20:18:28 +08:00
|
|
|
|
|
|
|
|
/* Return privileged mode */
|
|
|
|
|
|
|
|
|
|
regs[REG_CONTROL] = getcontrol() & ~CONTROL_NPRIV;
|
2013-03-22 21:59:05 +00:00
|
|
|
rtcb->xcp.sigreturn = 0;
|
2013-03-17 00:40:49 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-02-16 16:32:19 +00:00
|
|
|
/* This is not an architecture-specific system call. If NuttX is built
|
|
|
|
|
* as a standalone kernel with a system call interface, then all of the
|
|
|
|
|
* additional system calls must be handled as in the default case.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
default:
|
2013-03-06 19:56:32 +00:00
|
|
|
{
|
2014-08-28 12:09:49 -06:00
|
|
|
#ifdef CONFIG_LIB_SYSCALL
|
2024-07-15 17:52:00 +08:00
|
|
|
struct tcb_s *rtcb = this_task();
|
2013-03-17 16:13:28 +00:00
|
|
|
int index = rtcb->xcp.nsyscalls;
|
2013-03-06 19:56:32 +00:00
|
|
|
|
2013-03-16 00:34:43 +00:00
|
|
|
/* Verify that the SYS call number is within range */
|
2013-03-06 19:56:32 +00:00
|
|
|
|
2013-03-17 00:40:49 +00:00
|
|
|
DEBUGASSERT(cmd >= CONFIG_SYS_RESERVED && cmd < SYS_maxsyscall);
|
2013-03-06 19:56:32 +00:00
|
|
|
|
2013-03-16 00:34:43 +00:00
|
|
|
/* Make sure that there is a no saved syscall return address. We
|
|
|
|
|
* cannot yet handle nested system calls.
|
2013-03-06 19:56:32 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-03-17 16:13:28 +00:00
|
|
|
DEBUGASSERT(index < CONFIG_SYS_NNEST);
|
2013-03-06 19:56:32 +00:00
|
|
|
|
|
|
|
|
/* Setup to return to dispatch_syscall in privileged mode. */
|
|
|
|
|
|
2013-03-17 16:13:28 +00:00
|
|
|
rtcb->xcp.syscall[index].sysreturn = regs[REG_PC];
|
|
|
|
|
rtcb->xcp.syscall[index].excreturn = regs[REG_EXC_RETURN];
|
2024-07-30 18:46:35 +08:00
|
|
|
rtcb->xcp.syscall[index].ctrlreturn = regs[REG_CONTROL];
|
2013-03-17 16:13:28 +00:00
|
|
|
rtcb->xcp.nsyscalls = index + 1;
|
2013-03-16 00:34:43 +00:00
|
|
|
|
2013-03-14 22:44:06 +00:00
|
|
|
regs[REG_PC] = (uint32_t)dispatch_syscall;
|
2023-07-05 21:37:14 +08:00
|
|
|
regs[REG_EXC_RETURN] = EXC_RETURN_THREAD;
|
2013-03-06 19:56:32 +00:00
|
|
|
|
2023-07-05 20:18:28 +08:00
|
|
|
/* Return privileged mode */
|
|
|
|
|
|
|
|
|
|
regs[REG_CONTROL] = getcontrol() & ~CONTROL_NPRIV;
|
|
|
|
|
|
2013-03-06 19:56:32 +00:00
|
|
|
/* Offset R0 to account for the reserved values */
|
|
|
|
|
|
2019-11-28 12:47:36 -06:00
|
|
|
regs[REG_R0] -= CONFIG_SYS_RESERVED;
|
|
|
|
|
|
|
|
|
|
/* Indicate that we are in a syscall handler. */
|
|
|
|
|
|
|
|
|
|
rtcb->flags |= TCB_FLAG_SYSCALL;
|
2013-02-16 16:32:19 +00:00
|
|
|
#else
|
2020-11-21 09:22:01 +09:00
|
|
|
svcerr("ERROR: Bad SYS call: %" PRId32 "\n", regs[REG_R0]);
|
2013-02-16 16:32:19 +00:00
|
|
|
#endif
|
2013-03-06 19:56:32 +00:00
|
|
|
}
|
2013-02-16 16:32:19 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 10:58:54 -06:00
|
|
|
/* Report what happened. That might difficult in the case of a context
|
|
|
|
|
* switch.
|
|
|
|
|
*/
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2016-06-16 08:12:38 -06:00
|
|
|
#ifdef CONFIG_DEBUG_SYSCALL_INFO
|
2023-05-20 06:32:34 +08:00
|
|
|
# ifndef CONFIG_DEBUG_SVCALL
|
2013-03-16 00:34:43 +00:00
|
|
|
if (cmd > SYS_switch_context)
|
2023-05-20 06:32:34 +08:00
|
|
|
# else
|
2024-07-05 19:39:58 +08:00
|
|
|
if (regs != tcb->xcp.regs)
|
2023-05-20 06:32:34 +08:00
|
|
|
# endif
|
2013-02-16 16:32:19 +00:00
|
|
|
{
|
2024-07-05 19:39:58 +08:00
|
|
|
regs = (uint32_t *)tcb->xcp.regs;
|
|
|
|
|
|
2016-06-20 11:59:15 -06:00
|
|
|
svcinfo("SVCall Return:\n");
|
|
|
|
|
svcinfo(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
2024-07-05 19:39:58 +08:00
|
|
|
regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
|
|
|
|
regs[REG_R4], regs[REG_R5], regs[REG_R6], regs[REG_R7]);
|
2016-06-20 11:59:15 -06:00
|
|
|
svcinfo(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
2024-07-05 19:39:58 +08:00
|
|
|
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
|
|
|
|
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
|
|
|
|
svcinfo(" PSR: %08x EXC_RETURN: %08x CONTROL: %08x\n",
|
|
|
|
|
regs[REG_XPSR], regs[REG_EXC_RETURN], regs[REG_CONTROL]);
|
2013-02-16 16:32:19 +00:00
|
|
|
}
|
2023-05-20 06:32:34 +08:00
|
|
|
# ifdef CONFIG_DEBUG_SVCALL
|
2013-02-16 16:32:19 +00:00
|
|
|
else
|
|
|
|
|
{
|
2016-06-20 11:59:15 -06:00
|
|
|
svcinfo("SVCall Return: %d\n", regs[REG_R0]);
|
2013-02-16 16:32:19 +00:00
|
|
|
}
|
2023-05-20 06:32:34 +08:00
|
|
|
# endif
|
2013-03-16 00:34:43 +00:00
|
|
|
#endif
|
2013-02-16 16:32:19 +00:00
|
|
|
|
2024-09-25 12:30:05 +08:00
|
|
|
if (regs != tcb->xcp.regs)
|
2023-12-19 13:03:51 +08:00
|
|
|
{
|
2023-12-27 19:10:05 +08:00
|
|
|
restore_critical_section(this_task(), this_cpu());
|
2023-12-19 13:03:51 +08:00
|
|
|
}
|
|
|
|
|
|
2013-02-16 16:32:19 +00:00
|
|
|
return OK;
|
|
|
|
|
}
|