Fix some bad syscall dispatching log. This change is not testable until these is a tested NuttX kernel build.

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5713 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-03-06 19:56:32 +00:00
parent 4ee41237bd
commit bd1488bdab
11 changed files with 344 additions and 423 deletions

View File

@ -147,11 +147,11 @@
#ifndef __ASSEMBLY__
struct xcptcontext
{
#ifndef CONFIG_DISABLE_SIGNALS
/* The following function pointer is non-zero if there
* are pending signals to be processed.
*/
#ifndef CONFIG_DISABLE_SIGNALS
void *sigdeliver; /* Actual type is sig_deliver_t */
/* These are saved copies of LR, PRIMASK, and xPSR used during
@ -163,6 +163,12 @@ struct xcptcontext
uint32_t saved_xpsr;
#endif
#ifdef CONFIG_NUTTX_KERNEL
/* The following holds the return address from a system call */
uint32_t sysreturn;
#endif
/* Register save area */
uint32_t regs[XCPTCONTEXT_REGS];

View File

@ -106,11 +106,11 @@
#ifndef __ASSEMBLY__
struct xcptcontext
{
#ifndef CONFIG_DISABLE_SIGNALS
/* The following function pointer is non-zero if there
* are pending signals to be processed.
*/
#ifndef CONFIG_DISABLE_SIGNALS
void *sigdeliver; /* Actual type is sig_deliver_t */
/* These are saved copies of LR, PRIMASK, and xPSR used during
@ -126,6 +126,12 @@ struct xcptcontext
uint32_t saved_xpsr;
#endif
#ifdef CONFIG_NUTTX_KERNEL
/* The following holds the return address from a system call */
uint32_t sysreturn;
#endif
/* Register save area */
uint32_t regs[XCPTCONTEXT_REGS];

View File

@ -51,15 +51,15 @@
************************************************************************************/
/* Configuration ********************************************************************/
/* This logic uses three system calls {0,1,2} for context switching. The first three
* syscall values must be reserved.
/* This logic uses three system calls {0,1,2} for context switching and one for the
* syscall return. The first four syscall values must be reserved.
*/
#ifdef CONFIG_NUTTX_KERNEL
# ifndef CONFIG_SYS_RESERVED
# error "CONFIG_SYS_RESERVED must be defined to the value 3"
# elif CONFIG_SYS_RESERVED != 3
# error "CONFIG_SYS_RESERVED must have the value 3"
# 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"
# endif
#endif
@ -86,6 +86,15 @@
#define SYS_switch_context (2)
#ifdef CONFIG_NUTTX_KERNEL
/* SYS call 3:
*
* void up_syscall_return(void);
*/
#define SYS_syscall_return (3)
#endif
/************************************************************************************
* Inline Functions
************************************************************************************/

View File

@ -52,6 +52,8 @@
#endif
#include "svcall.h"
#include "exc_return.h"
#include "os_internal.h"
#include "up_internal.h"
/****************************************************************************
@ -59,29 +61,15 @@
****************************************************************************/
/* Configuration ************************************************************/
#undef SYSCALL_INTERRUPTIBLE
#if defined(CONFIG_NUTTX_KERNEL)
# if CONFIG_ARCH_INTERRUPTSTACK > 3
# warning "CONFIG_ARCH_INTERRUPTSTACK and CONFIG_NUTTX_KERNEL are incompatible"
# warning "options as currently implemented. Interrupts will have to be disabled"
# warning "during SYScall processing to avoid un-handled nested interrupts"
# else
# define SYSCALL_INTERRUPTIBLE 1
# endif
#endif
/* Debug ********************************************************************/
/* Debug output from this file may interfere with context switching! To get
* debug output you must enabled the following in your NuttX configuration:
*
* CONFIG_DEBUG and CONFIG_DEBUG_SCHED
*
* And you must explicitly define DEBUG_SVCALL below:
* CONFIG_DEBUG and CONFIG_DEBUG_SYSCALL
*/
#undef DEBUG_SVCALL /* Define to debug SVCall */
#ifdef DEBUG_SVCALL
# define svcdbg(format, arg...) slldbg(format, ##arg)
#ifdef CONFIG_DEBUG_SYSCALL
# define svcdbg(format, arg...) lldbg(format, ##arg)
#else
# define svcdbg(x...)
#endif
@ -102,121 +90,29 @@
* Name: dispatch_syscall
*
* Description:
* Dispatch a system call to the appropriate handling logic.
* Call the stub function corresponding to the system call.
*
****************************************************************************/
#ifdef CONFIG_NUTTX_KERNEL
static inline void dispatch_syscall(uint32_t *regs)
static void dispatch_syscall(void) naked_function;
static void dispatch_syscall(void)
{
uint32_t cmd = regs[REG_R0];
FAR struct tcb_s *rtcb = sched_self();
uintptr_t ret = (uintptr_t)ERROR;
/* Verify the the SYS call number is within range */
if (cmd < SYS_maxsyscall)
{
/* Report error and return ERROR */
slldbg("ERROR: Bad SYS call: %d\n", cmd);
}
else
{
/* The index into the syscall table is offset by the number of architecture-
* specific reserved entries at the beginning of the SYS call number space.
*/
int index = cmd - CONFIG_SYS_RESERVED;
/* Enable interrupts while the SYSCALL executes */
#ifdef SYSCALL_INTERRUPTIBLE
irqenable();
#endif
/* Call the correct stub for each SYS call, based on the number of parameters */
svcdbg("Calling stub%d at %p\n", index, g_stubloopkup[index].stub0);
switch (g_stubnparms[index])
{
/* No parameters */
case 0:
ret = g_stublookup[index].stub0();
break;
/* Number of parameters: 1 */
case 1:
ret = g_stublookup[index].stub1(regs[REG_R1]);
break;
/* Number of parameters: 2 */
case 2:
ret = g_stublookup[index].stub2(regs[REG_R1], regs[REG_R2]);
break;
/* Number of parameters: 3 */
case 3:
ret = g_stublookup[index].stub3(regs[REG_R1], regs[REG_R2],
regs[REG_R3]);
break;
/* Number of parameters: 4 */
case 4:
ret = g_stublookup[index].stub4(regs[REG_R1], regs[REG_R2],
regs[REG_R3], regs[REG_R4]);
break;
/* Number of parameters: 5 */
case 5:
ret = g_stublookup[index].stub5(regs[REG_R1], regs[REG_R2],
regs[REG_R3], regs[REG_R4],
regs[REG_R5]);
break;
/* Number of parameters: 6 */
case 6:
ret = g_stublookup[index].stub6(regs[REG_R1], regs[REG_R2],
regs[REG_R3], regs[REG_R4],
regs[REG_R5], regs[REG_R6]);
break;
/* Unsupported number of paramters. Report error and return ERROR */
default:
slldbg("ERROR: Bad SYS call %d number parameters %d\n",
cmd, g_stubnparms[index]);
break;
}
#ifdef SYSCALL_INTERRUPTIBLE
irqdisable();
#endif
}
/* Set up the return value. First, check if a context switch occurred.
* In this case, regs will no longer be the same as current_regs. In
* the case of a context switch, we will have to save the return value
* in the TCB where it can be returned later when the task is restarted.
*/
if (regs != current_regs)
{
regs = rtcb->xcp.regs;
}
/* Then return the result in R0 */
svcdbg("Return value regs: %p value: %d\n", regs, ret);
regs[REG_R0] = (uint32_t)ret;
__asm__ __volatile__
(
" push {r4-r6}\n" /* Save R4, R5 and R6 */
" mov r6, r14\n" /* Save LR in R6 */
" ldr r4, =g_stublookup\n" /* Get the base of the stub lookup table */
" lsl r3, r0, #2\n" /* Get the offset of the stub for this syscall */
" ldr r3, [r4, r3]\n" /* Load the entry of the stub for this syscall */
" blx r3\n" /* Call the stub */
" mov r14, r6\n" /* Restore R14 */
" pop {r4-r6}\n" /* Restore R4, R5, and R6 */
" mov r2, r0\n" /* Save the return value in R0 in R2 for now */
" mov r0, #3\n" /* R0=SYS_syscall_return */
" svc 0" /* Return from the syscall */
:::
);
}
#endif
@ -309,7 +205,7 @@ int up_svcall(int irq, FAR void *context)
*
* At this point, the following values are saved in context:
*
* R0 = 1
* R0 = SYS_switch_context
* R1 = saveregs
* R2 = restoreregs
*
@ -327,17 +223,81 @@ int up_svcall(int irq, FAR void *context)
}
break;
/* R0=SYS_syscall_return: This a switch context command:
*
* void up_sycall_return(void);
*
* 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.
*/
#ifdef CONFIG_NUTTX_KERNEL
case SYS_syscall_return:
{
struct tcb_s *rtcb = sched_self();
/* Make sure that we got here from a privileged thread and
* that there is a saved syscall return address.
*/
DEBUGASSERT(rtcb->xcp.sysreturn != NULL &&
regs[REG_EXC_RETURN] == EXC_RETURN_PRIVTHR);
/* Setup to return to the saved syscall return address in
* unprivileged mode.
*/
current_regs[REG_PC] = rtcb->xcp.sysreturn;
current_regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
rtcb->sysreturn = NULL;
/* The return value must be in R0-R1. dispatch_syscall() temporarily
* moved the value to R2.
*/
current_regs[REG_R0] = current_regs[REG_R2];
}
break;
#endif
/* 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:
{
#ifdef CONFIG_NUTTX_KERNEL
dispatch_syscall(regs);
FAR struct tcb_s *rtcb = sched_self();
/* Verify the the SYS call number is within range */
DEBUGASSERT(current_regs[REG_R0] < SYS_maxsyscall);
/* Make sure that we got here from an unprivileged thread and that
* there is a no saved syscall return address.
*/
DEBUGASSERT(rtcb->xcp.sysreturn == NULL &&
regs[REG_EXC_RETURN] == EXC_RETURN_UNPRIVTHR);
/* Setup to return to dispatch_syscall in privileged mode. */
rtcb->sysreturn = regs[REG_PC]
regs[REG_PC] = (uint32_t)dispatch_syscall;
current_regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
/* Offset R0 to account for the reserved values */
current_regs[REG_R0] -= CONFIG_SYS_RESERVED;
#else
slldbg("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
slldbg("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
#endif
}
break;
}

View File

@ -1,7 +1,7 @@
/************************************************************************************
* arch/arm/src/armv7-m/svcall.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -51,15 +51,15 @@
************************************************************************************/
/* Configuration ********************************************************************/
/* This logic uses three system calls {0,1,2} for context switching. The first three
* syscall values must be reserved.
/* This logic uses three system calls {0,1,2} for context switching and one for the
* syscall return. The first four syscall values must be reserved.
*/
#ifdef CONFIG_NUTTX_KERNEL
# ifndef CONFIG_SYS_RESERVED
# error "CONFIG_SYS_RESERVED must be defined to the value 3"
# elif CONFIG_SYS_RESERVED != 3
# error "CONFIG_SYS_RESERVED must have the value 3"
# 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"
# endif
#endif
@ -86,6 +86,15 @@
#define SYS_switch_context (2)
#ifdef CONFIG_NUTTX_KERNEL
/* SYS call 3:
*
* void up_syscall_return(void);
*/
#define SYS_syscall_return (3)
#endif
/************************************************************************************
* Inline Functions
************************************************************************************/

View File

@ -52,6 +52,8 @@
#endif
#include "svcall.h"
#include "exc_return.h"
#include "os_internal.h"
#include "up_internal.h"
/****************************************************************************
@ -59,29 +61,15 @@
****************************************************************************/
/* Configuration ************************************************************/
#undef SYSCALL_INTERRUPTIBLE
#if defined(CONFIG_NUTTX_KERNEL)
# if CONFIG_ARCH_INTERRUPTSTACK > 3
# warning "CONFIG_ARCH_INTERRUPTSTACK and CONFIG_NUTTX_KERNEL are incompatible"
# warning "options as currently implemented. Interrupts will have to be disabled"
# warning "during SYScall processing to avoid un-handled nested interrupts"
# else
# define SYSCALL_INTERRUPTIBLE 1
# endif
#endif
/* Debug ********************************************************************/
/* Debug output from this file may interfere with context switching! To get
* debug output you must enabled the following in your NuttX configuration:
*
* CONFIG_DEBUG and CONFIG_DEBUG_SCHED
*
* And you must explicitly define DEBUG_SVCALL below:
* CONFIG_DEBUG and CONFIG_DEBUG_SYSCALL
*/
#undef DEBUG_SVCALL /* Define to debug SVCall */
#ifdef DEBUG_SVCALL
# define svcdbg(format, arg...) slldbg(format, ##arg)
#ifdef CONFIG_DEBUG_SYSCALL
# define svcdbg(format, arg...) lldbg(format, ##arg)
#else
# define svcdbg(x...)
#endif
@ -102,121 +90,28 @@
* Name: dispatch_syscall
*
* Description:
* Dispatch a system call to the appropriate handling logic.
* Call the stub function corresponding to the system call.
*
****************************************************************************/
#ifdef CONFIG_NUTTX_KERNEL
static inline void dispatch_syscall(uint32_t *regs)
static void dispatch_syscall(void) naked_function;
static void dispatch_syscall(void)
{
uint32_t cmd = regs[REG_R0];
FAR struct tcb_s *rtcb = sched_self();
uintptr_t ret = (uintptr_t)ERROR;
/* Verify the the SYS call number is within range */
if (cmd < SYS_maxsyscall)
{
/* Report error and return ERROR */
slldbg("ERROR: Bad SYS call: %d\n", cmd);
}
else
{
/* The index into the syscall table is offset by the number of architecture-
* specific reserved entries at the beginning of the SYS call number space.
*/
int index = cmd - CONFIG_SYS_RESERVED;
/* Enable interrupts while the SYSCALL executes */
#ifdef SYSCALL_INTERRUPTIBLE
irqenable();
#endif
/* Call the correct stub for each SYS call, based on the number of parameters */
svcdbg("Calling stub%d at %p\n", index, g_stubloopkup[index].stub0);
switch (g_stubnparms[index])
{
/* No parameters */
case 0:
ret = g_stublookup[index].stub0();
break;
/* Number of parameters: 1 */
case 1:
ret = g_stublookup[index].stub1(regs[REG_R1]);
break;
/* Number of parameters: 2 */
case 2:
ret = g_stublookup[index].stub2(regs[REG_R1], regs[REG_R2]);
break;
/* Number of parameters: 3 */
case 3:
ret = g_stublookup[index].stub3(regs[REG_R1], regs[REG_R2],
regs[REG_R3]);
break;
/* Number of parameters: 4 */
case 4:
ret = g_stublookup[index].stub4(regs[REG_R1], regs[REG_R2],
regs[REG_R3], regs[REG_R4]);
break;
/* Number of parameters: 5 */
case 5:
ret = g_stublookup[index].stub5(regs[REG_R1], regs[REG_R2],
regs[REG_R3], regs[REG_R4],
regs[REG_R5]);
break;
/* Number of parameters: 6 */
case 6:
ret = g_stublookup[index].stub6(regs[REG_R1], regs[REG_R2],
regs[REG_R3], regs[REG_R4],
regs[REG_R5], regs[REG_R6]);
break;
/* Unsupported number of paramters. Report error and return ERROR */
default:
slldbg("ERROR: Bad SYS call %d number parameters %d\n",
cmd, g_stubnparms[index]);
break;
}
#ifdef SYSCALL_INTERRUPTIBLE
irqdisable();
#endif
}
/* Set up the return value. First, check if a context switch occurred.
* In this case, regs will no longer be the same as current_regs. In
* the case of a context switch, we will have to save the return value
* in the TCB where it can be returned later when the task is restarted.
*/
if (regs != current_regs)
{
regs = rtcb->xcp.regs;
}
/* Then return the result in R0 */
svcdbg("Return value regs: %p value: %d\n", regs, ret);
regs[REG_R0] = (uint32_t)ret;
__asm__ __volatile__
(
" push {r4, r5}\n" /* Save R4 and R5 */
" mov r5, r14\n" /* Save LR in R5 */
" ldr r4, =g_stublookup\n" /* Get the base of the stub lookup table */
" ldr r4, [r4, r0, lsl #2]\n" /* Load the entry of the stub for this syscall */
" blx r4\n" /* Call the stub */
" mov r14, r5\n" /* Restore R14 */
" pop {r4, r5}\n" /* Restore R4 and R5 */
" mov r2, r0\n" /* Save the return value in R0 in R2 for now */
" mov r0, #3\n" /* R0=SYS_syscall_return */
" svc 0" /* Return from the syscall */
:::
);
}
#endif
@ -327,17 +222,81 @@ int up_svcall(int irq, FAR void *context)
}
break;
/* R0=SYS_syscall_return: This a switch context command:
*
* void up_sycall_return(void);
*
* 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.
*/
#ifdef CONFIG_NUTTX_KERNEL
case SYS_syscall_return:
{
struct tcb_s *rtcb = sched_self();
/* Make sure that we got here from a privileged thread and
* that there is a saved syscall return address.
*/
DEBUGASSERT(rtcb->xcp.sysreturn != NULL &&
regs[REG_EXC_RETURN] == EXC_RETURN_PRIVTHR);
/* Setup to return to the saved syscall return address in
* unprivileged mode.
*/
current_regs[REG_PC] = rtcb->xcp.sysreturn;
current_regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
rtcb->sysreturn = NULL;
/* The return value must be in R0-R1. dispatch_syscall() temporarily
* moved the value to R2.
*/
current_regs[REG_R0] = current_regs[REG_R2];
}
break;
#endif
/* 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:
{
#ifdef CONFIG_NUTTX_KERNEL
dispatch_syscall(regs);
FAR struct tcb_s *rtcb = sched_self();
/* Verify the the SYS call number is within range */
DEBUGASSERT(current_regs[REG_R0] < SYS_maxsyscall);
/* Make sure that we got here from a unprivileged thread and that
* there is a no saved syscall return address.
*/
DEBUGASSERT(rtcb->xcp.sysreturn == NULL &&
regs[REG_EXC_RETURN] == EXC_RETURN_UNPRIVTHR);
/* Setup to return to dispatch_syscall in privileged mode. */
rtcb->sysreturn = regs[REG_PC]
regs[REG_PC] = (uint32_t)dispatch_syscall;
current_regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
/* Offset R0 to account for the reserved values */
current_regs[REG_R0] -= CONFIG_SYS_RESERVED;
#else
slldbg("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
slldbg("ERROR: Bad SYS call: %d\n", regs[REG_R0]);
#endif
}
break;
}

View File

@ -38,6 +38,10 @@
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <assert.h>
#include <arch/board/user_map.h>
#ifdef CONFIG_NUTTX_KERNEL

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/include/mips32/irq.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -310,11 +310,11 @@
struct xcptcontext
{
#ifndef CONFIG_DISABLE_SIGNALS
/* The following function pointer is non-NULL if there are pending signals
* to be processed.
*/
#ifndef CONFIG_DISABLE_SIGNALS
void *sigdeliver; /* Actual type is sig_deliver_t */
/* These additional register save locations are used to implement the
@ -325,6 +325,12 @@ struct xcptcontext
uint32_t saved_status; /* Status with interrupts disabled. */
#endif
#ifdef CONFIG_NUTTX_KERNEL
/* The following holds the return address from a system call */
uint32_t sysreturn;
#endif
/* Register save area */
uint32_t regs[XCPTCONTEXT_REGS];

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/include/mips32/syscall.h
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -57,15 +57,17 @@
#define SYS_syscall 0x00
/* Configuration ********************************************************************/
/* This logic uses three system calls {0,1,2} for context switching. The first three
* syscall values must be reserved.
/* SYS call 1 and 2 are defined for internal use by the PIC32MX port (see
* arch/mips/include/mips32/syscall.h). In addition, SYS call 3 is the return from
* a SYS call in kernel mode. The first four syscall values must, therefore, be
* reserved (0 is not used).
*/
#ifdef CONFIG_NUTTX_KERNEL
# ifndef CONFIG_SYS_RESERVED
# error "CONFIG_SYS_RESERVED must be defined to the value 2"
# elif CONFIG_SYS_RESERVED != 2
# error "CONFIG_SYS_RESERVED must have the value 2"
# 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"
# endif
#endif
@ -148,6 +150,8 @@
/* Context switching system calls ***************************************************/
/* SYS call 0: (not used) */
/* SYS call 1:
*
* void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function;
@ -166,6 +170,16 @@
#define up_switchcontext(saveregs, restoreregs) \
(void)sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs)
#ifdef CONFIG_NUTTX_KERNEL
/* SYS call 3:
*
* void up_syscall_return(void);
*/
#define SYS_syscall_return (3)
#define up_syscall_return() (void)sys_call0(SYS_syscall_return)
#endif
#endif /* __ASSEMBLY__ */
/****************************************************************************

View File

@ -57,29 +57,15 @@
****************************************************************************/
/* Configuration ************************************************************/
#undef SYSCALL_INTERRUPTIBLE
#if defined(CONFIG_NUTTX_KERNEL)
# if CONFIG_ARCH_INTERRUPTSTACK > 3
# warning "CONFIG_ARCH_INTERRUPTSTACK and CONFIG_NUTTX_KERNEL are incompatible"
# warning "options as currently implemented. Interrupts will have to be disabled"
# warning "during SYScall processing to avoid un-handled nested interrupts"
# else
# define SYSCALL_INTERRUPTIBLE 1
# endif
#endif
/* Debug ********************************************************************/
/* Debug output from this file may interfere with context switching! To get
* debug output you must enabled the following in your NuttX configuration:
*
* CONFIG_DEBUG and CONFIG_DEBUG_SCHED
*
* And you must explicitly define DEBUG_SWINT0 below:
* CONFIG_DEBUG and CONFIG_DEBUG_SYSCALL
*/
#undef DEBUG_SWINT0 /* Define to debug SWInt */
#ifdef DEBUG_SWINT0
# define swidbg(format, arg...) slldbg(format, ##arg)
#ifdef CONFIG_DEBUG_SYSCALL
# define swidbg(format, arg...) lldbg(format, ##arg)
#else
# define swidbg(x...)
#endif
@ -100,7 +86,7 @@
* Name: up_registerdump
****************************************************************************/
#ifdef DEBUG_SWINT0
#ifdef CONFIG_DEBUG_SYSCALL
static void up_registerdump(const uint32_t *regs)
{
swidbg("MFLO:%08x MFHI:%08x EPC:%08x STATUS:%08x\n",
@ -132,125 +118,27 @@ static void up_registerdump(const uint32_t *regs)
* Name: dispatch_syscall
*
* Description:
* Dispatch a system call to the appropriate handling logic.
* Call the stub function corresponding to the system call.
*
****************************************************************************/
#ifdef CONFIG_NUTTX_KERNEL
static inline void dispatch_syscall(uint32_t *regs)
static void dispatch_syscall(void) naked_function;
static void dispatch_syscall(void)
{
uint32_t cmd = regs[REG_A0];
FAR struct tcb_s *rtcb = sched_self();
uintptr_t ret = (uintptr_t)ERROR;
# error "Missing logic"
/* Verify the the SYS call number is within range */
if (cmd < SYS_maxsyscall)
{
/* Report error and return ERROR */
slldbg("ERROR: Bad SYS call: %d\n", cmd);
}
else
{
/* The index into the syscall table is offset by the number of
* architecture-specific reserved entries at the beginning of the
* SYS call number space.
*/
int index = cmd - CONFIG_SYS_RESERVED;
/* Enable interrupts while the SYSCALL executes */
#ifdef SYSCALL_INTERRUPTIBLE
irqenable();
#endif
/* Call the correct stub for each SYS call, based on the number of
* parameters: $5=parm1, $6=parm2, $7=parm3, $8=parm4, $9=parm5, and
* $10=parm6.
*/
swidbg("Calling stub%d at %p\n", index, g_stubloopkup[index].stub0);
switch (g_stubnparms[index])
{
/* No parameters */
case 0:
ret = g_stublookup[index].stub0();
break;
/* Number of parameters: 1 */
case 1:
ret = g_stublookup[index].stub1(regs[REG_A1]);
break;
/* Number of parameters: 2 */
case 2:
ret = g_stublookup[index].stub2(regs[REG_A1], regs[REG_A2]);
break;
/* Number of parameters: 3 */
case 3:
ret = g_stublookup[index].stub3(regs[REG_A1], regs[REG_A2],
regs[REG_A3]);
break;
/* Number of parameters: 4 */
case 4:
ret = g_stublookup[index].stub4(regs[REG_A1], regs[REG_A2],
regs[REG_A3], regs[REG_T0]);
break;
/* Number of parameters: 5 */
case 5:
ret = g_stublookup[index].stub5(regs[REG_A1], regs[REG_A2],
regs[REG_A3], regs[REG_T0],
regs[REG_T1]);
break;
/* Number of parameters: 6 */
case 6:
ret = g_stublookup[index].stub6(regs[REG_A1], regs[REG_A2],
regs[REG_A3], regs[REG_T0],
regs[REG_T1], regs[REG_T2]);
break;
/* Unsupported number of paramters. Report error and return ERROR */
default:
slldbg("ERROR: Bad SYS call %d number parameters %d\n",
cmd, g_stubnparms[index]);
break;
}
#ifdef SYSCALL_INTERRUPTIBLE
irqdisable();
#endif
}
/* Set up the return vaue. First, check if a context switch occurred.
* In this case, regs will no longer be the same as current_regs. In
* the case of a context switch, we will have to save the return value
* in the TCB where it can be returned later when the task is restarted.
*/
if (regs != current_regs)
{
regs = rtcb->xcp.regs;
}
/* Then return the result in v0 */
swidbg("Return value regs: %p value: %d\n", regs, ret);
regs[REG_v0] = (uint32_t)ret;
/* Refer to arch/arm/src/armv7-m/up_svcall.h for how this is done for ARM */
/* __asm__ __volatile__ */
/* (
/* Save registers */
/* Get the base of the stub lookup table */
/* Get the offset of the stub for this syscall */
/* Load the entry of the stub for this syscall */
/* Call the stub */
/* Restore regsisters */
/* Return from the syscall */
/* ); */
}
#endif
@ -279,7 +167,7 @@ int up_swint0(int irq, FAR void *context)
* arguments depending on the system call.
*/
#ifdef DEBUG_SWINT0
#ifdef CONFIG_DEBUG_SYSCALL
swidbg("Entry: regs: %p cmd: %d\n", regs, regs[REG_R4]);
up_registerdump(regs);
#endif
@ -334,23 +222,81 @@ int up_swint0(int irq, FAR void *context)
}
break;
/* R0=SYS_syscall_return: This a switch context command:
*
* void up_sycall_return(void);
*
* 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.
*/
#ifdef CONFIG_NUTTX_KERNEL
case SYS_syscall_return:
{
struct tcb_s *rtcb = sched_self();
/* Make sure that we got here from a privileged thread and
* that there is a saved syscall return address.
*/
#error "Missing logic -- need to test for privileged mode"
DEBUGASSERT(rtcb->xcp.sysreturn != NULL && ???);
/* Setup to return to the saved syscall return address in
* unprivileged mode.
*/
current_regs[REG_EPC] = rtcb->xcp.sysreturn;
#error "Missing logic -- need to set for unprivileged mode"
rtcb->sysreturn = NULL;
}
break;
#endif
/* This is not an architecture-specify 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:
{
#ifdef CONFIG_NUTTX_KERNEL
dispatch_syscall(regs);
FAR struct tcb_s *rtcb = sched_self();
/* Verify the the SYS call number is within range */
DEBUGASSERT(current_regs[REG_A0] < SYS_maxsyscall);
/* Make sure that we got here from an unprivileged thread and that
* there is a no saved syscall return address.
*/
#error "Missing logic -- Need to set unprivileged mode"
DEBUGASSERT(rtcb->xcp.sysreturn == NULL && ???);
/* Setup to return to dispatch_syscall in privileged mode. */
rtcb->sysreturn = regs[REG_EPC]
regs[REG_EPC] = (uint32_t)dispatch_syscall;
#error "Missing logic -- Need to set privileged mode"
/* Offset R0 to account for the reserved values */
current_regs[REG_R0] -= CONFIG_SYS_RESERVED;
#else
slldbg("ERROR: Bad SYS call: %d\n", regs[REG_A0]);
slldbg("ERROR: Bad SYS call: %d\n", regs[REG_A0]);
#endif
}
break;
}
/* Report what happened. That might difficult in the case of a context switch */
#ifdef DEBUG_SWINT0
#ifdef CONFIG_DEBUG_SYSCALL
if (regs != current_regs)
{
swidbg("SWInt Return: Context switch!\n");

View File

@ -1,7 +1,7 @@
/************************************************************************************
* arch/mips/src/pic32mx/pic32mx-config.h
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -485,15 +485,17 @@
#endif
/* SYS calls ************************************************************************/
/* SYS call 0 and 1 are defined for internal use by the PIC32MX port (see
* arch/mips/include/mips32/syscall.h
/* SYS call 1 and 2 are defined for internal use by the PIC32MX port (see
* arch/mips/include/mips32/syscall.h). In addition, SYS call 3 is the return from
* a SYS call in kernel mode. The first four syscall values must, therefore, be
* reserved (0 is not used).
*/
#ifdef CONFIG_NUTTX_KERNEL
# if !defined(CONFIG_SYS_RESERVED) || CONFIG_SYS_RESERVED < 2
# error "CONFIG_SYS_RESERVED must be defined to be 2 for a kernel build"
# elif CONFIG_SYS_RESERVED > 2
# warning "CONFIG_SYS_RESERVED should be defined to be 2 for a kernel build"
# if !defined(CONFIG_SYS_RESERVED) || CONFIG_SYS_RESERVED < 4
# error "CONFIG_SYS_RESERVED must be defined to be 4 for a kernel build"
# elif CONFIG_SYS_RESERVED > 4
# warning "CONFIG_SYS_RESERVED should be defined to be 4 for a kernel build"
# endif
#endif