summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-05-18 22:34:11 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-05-18 22:34:11 +0000
commit3a44a6f462a612c7a3f3dec4e4c815c49fe18595 (patch)
tree5fbf7e69fc279d8a741a7048afc5cbdd2d95b8b3
parent8919a4aad6d342488a71b4707fd3bbc59601e187 (diff)
Add MIPS system call infrastructure
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3626 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rw-r--r--nuttx/arch/mips/include/mips32/syscall.h210
-rw-r--r--nuttx/arch/mips/include/syscall.h2
-rw-r--r--nuttx/arch/mips/src/common/up_exit.c1
-rwxr-xr-xnuttx/arch/mips/src/common/up_internal.h3
-rwxr-xr-xnuttx/arch/mips/src/mips32/up_blocktask.c3
-rwxr-xr-xnuttx/arch/mips/src/mips32/up_releasepending.c2
-rwxr-xr-xnuttx/arch/mips/src/mips32/up_reprioritizertr.c3
-rw-r--r--nuttx/arch/mips/src/mips32/up_sigdeliver.c1
-rw-r--r--nuttx/arch/mips/src/mips32/up_syscall0.S94
-rwxr-xr-xnuttx/arch/mips/src/mips32/up_unblocktask.c4
-rwxr-xr-xnuttx/arch/mips/src/pic32mx/Make.defs2
11 files changed, 265 insertions, 60 deletions
diff --git a/nuttx/arch/mips/include/mips32/syscall.h b/nuttx/arch/mips/include/mips32/syscall.h
index 0a6c5c3e26..e571e14b0d 100644
--- a/nuttx/arch/mips/include/mips32/syscall.h
+++ b/nuttx/arch/mips/include/mips32/syscall.h
@@ -45,19 +45,140 @@
****************************************************************************/
#include <nuttx/config.h>
-#include <stdint.h>
+
+#ifndef __ASSEMBLY__
+# include <stdint.h>
+#endif
/****************************************************************************
- * Pre-Processor Definitions
+ * Pro-processor Definitions
****************************************************************************/
-#define SYS_syscall 0x80
+#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.
+ */
+
+#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"
+# endif
+#endif
+
+/* sys_call macros ******************************************************************/
+/* System calls with 3 parameters and fewer are handled by sys_call0 (sys_call1,
+ * sys_call2, and sys_call3 are aliases for sys_call0). This is because the
+ * parmeters are passed in a0-a3. a0 is reserved for the syscall number leaving
+ * up to thre additional parameters that can be passed in registers. The remainder
+ * would have to be pushed onto the stack.
+ *
+ * Instead, these macros are provided which handle parameters four, five and six in
+ * a non-standard way: The use s0 ($7), s1 ($8), and s2 ($9) to pass the additional
+ * parameters.
+ */
+
+#ifndef __ASSEMBLY__
+
+/* System call SYS_ argument and four additional parameters. */
+
+#define sys_call4(nbr,parm1,parm2,parm3,parm4) __extension__({ \
+ uintptr_t __result; \
+ __asm__ __volatile__ (\
+ "\tmove $4, %0\n" \
+ "\tmove $5, %1\n" \
+ "\tmove $6, %2\n" \
+ "\tmove $7, %3\n" \
+ "\tmove $8, %4\n" \
+ "\la $12, sys_call3\n" \
+ "\jalr $12, $31\n" \
+ "\tmove %5, $r2\n" \
+ : "=r" (nbr) "=r" (parm1) "=r" (parm2) "=r" (parm3) "=r" (parm4) \
+ : " "r"(__result)\
+ : "memory"\
+ ); \
+ __result; \
+})
+
+/* System call SYS_ argument and five additional parameters. */
+
+#define sys_call5(nbr,parm1,parm2,parm3,parm4,parm5) __extension__({ \
+ uintptr_t __result; \
+ __asm__ __volatile__ (\
+ "\tmove $4, %0\n" \
+ "\tmove $5, %1\n" \
+ "\tmove $6, %2\n" \
+ "\tmove $7, %3\n" \
+ "\tmove $8, %4\n" \
+ "\tmove $9, %5\n" \
+ "\la $12, sys_call3\n" \
+ "\jalr $12, $31\n" \
+ "\tmove %6, $r2\n" \
+ : "=r" (nbr) "=r" (parm1) "=r" (parm2) "=r" (parm3) "=r" (parm4) "=r" (parm5) \
+ : " "r"(__result)\
+ : "memory"\
+ ); \
+ __result; \
+})
+
+/* System call SYS_ argument and six additional parameters. */
+
+#define sys_call5(nbr,parm1,parm2,parm3,parm4,parm5,parm6) __extension__({ \
+ uintptr_t __result; \
+ __asm__ __volatile__ (\
+ "\tmove $4, %0\n" \
+ "\tmove $5, %1\n" \
+ "\tmove $6, %2\n" \
+ "\tmove $7, %3\n" \
+ "\tmove $8, %4\n" \
+ "\tmove $9, %5\n" \
+ "\tmove $10, %5\n" \
+ "\la $12, sys_call3\n" \
+ "\jalr $12, $31\n" \
+ "\tmove %6, $r2\n" \
+ : "=r" (nbr) "=r" (parm1) "=r" (parm2) "=r" (parm3) "=r" (parm4) "=r" (parm5) \
+ : " "r"(__result)\
+ : "memory"\
+ ); \
+ __result; \
+})
+
+/* Context switching system calls ***************************************************/
+
+/* SYS call 0:
+ *
+ * void up_fullcontextrestore(uint32_t *restoreregs) __attribute__ ((noreturn));
+ */
+
+#define SYS_restore_context (1)
+#define up_fullcontextrestore(restoreregs) \
+ (void)sys_call1(SYS_restore_context, (uintptr_t)restoreregs)
+
+/* SYS call 1:
+ *
+ * void up_switchcontext(uint32_t *saveregs, uint32_t *restoreregs);
+ */
+
+#define SYS_switch_context (2)
+#define up_switchcontext(saveregs, restoreregs) \
+ (void)sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs)
+
+#endif /* __ASSEMBLY__ */
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
+ * Inline functions
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
* Public Variables
****************************************************************************/
@@ -65,7 +186,6 @@
* Public Function Prototypes
****************************************************************************/
-#ifndef __ASSEMBLY__
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C" {
@@ -73,66 +193,52 @@ extern "C" {
#define EXTERN extern
#endif
-/* SWI with SYS_ call number and six parameters */
-
-EXTERN uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1,
- uintptr_t parm2, uintptr_t parm3,
- uintptr_t parm4, uintptr_t parm5,
- uintptr_t parm6);
-
-/* SWI with SYS_ call number and no parameters */
-
-static inline uintptr_t sys_call0(unsigned int nbr)
-{
- return sys_call6(nbr, 0, 0, 0, 0, 0, 0);
-}
-
-/* SWI with SYS_ call number and one parameter */
-
-static inline uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1)
-{
- return sys_call6(nbr, parm1, 0, 0, 0, 0, 0);
-}
-
-/* SWI with SYS_ call number and two parameters */
+/****************************************************************************
+ * Name: up_syscall0
+ *
+ * Description:
+ * System call SYS_ argument and no additional parameters.
+ *
+ ****************************************************************************/
-static inline uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1,
- uintptr_t parm2)
-{
- return sys_call6(nbr, parm1, parm2, 0, 0, 0, 0);
-}
+EXTERN uintptr_t sys_call0(unsigned int nbr);
-/* SWI with SYS_ call number and three parameters */
+/****************************************************************************
+ * Name: up_syscall1
+ *
+ * Description:
+ * System call SYS_ argument and one additional parameter.
+ *
+ ****************************************************************************/
-static inline uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1,
- uintptr_t parm2, uintptr_t parm3)
-{
- return sys_call6(nbr, parm1, parm2, parm3, 0, 0, 0);
-}
+EXTERN uintptr_t sys_call1(unsigned int nbr, uintptr_t parm1);
-/* SWI with SYS_ call number and four parameters */
+/****************************************************************************
+ * Name: up_syscall2
+ *
+ * Description:
+ * System call SYS_ argument and two additional parameters.
+ *
+ ****************************************************************************/
-static inline uintptr_t sys_call4(unsigned int nbr, uintptr_t parm1,
- uintptr_t parm2, uintptr_t parm3,
- uintptr_t parm4)
-{
- return sys_call6(nbr, parm1, parm2, parm3, parm4, 0, 0);
-}
+EXTERN uintptr_t sys_call2(unsigned int nbr, uintptr_t parm1, uintptr_t parm2);
-/* SWI with SYS_ call number and five parameters */
+/****************************************************************************
+ * Name: up_syscall3
+ *
+ * Description:
+ * System call SYS_ argument and three additional parameters.
+ *
+ ****************************************************************************/
-static inline uintptr_t sys_call5(unsigned int nbr, uintptr_t parm1,
- uintptr_t parm2, uintptr_t parm3,
- uintptr_t parm4, uintptr_t parm5)
-{
- return sys_call6(nbr, parm1, parm2, parm3, parm4, parm5, 0);
-}
+EXTERN uintptr_t sys_call3(unsigned int nbr, uintptr_t parm1,
+ uintptr_t parm2, uintptr_t parm3);
#undef EXTERN
#ifdef __cplusplus
}
#endif
-#endif
+#endif /* __ASSEMBLY__ */
#endif /* __ARCH_MIPS_INCLUDE_MIPS32_SYSCALL_H */
diff --git a/nuttx/arch/mips/include/syscall.h b/nuttx/arch/mips/include/syscall.h
index d59eded488..9fe94e1492 100644
--- a/nuttx/arch/mips/include/syscall.h
+++ b/nuttx/arch/mips/include/syscall.h
@@ -44,7 +44,7 @@
* Included Files
****************************************************************************/
-/* Include MIPS architecture-specific syscall macros */
+/* Include ARM architecture-specific syscall macros */
#ifdef CONFIG_ARCH_MIPS32
# include <arch/mips32/syscall.h>
diff --git a/nuttx/arch/mips/src/common/up_exit.c b/nuttx/arch/mips/src/common/up_exit.c
index f0ea24d28e..cf6b25fda4 100644
--- a/nuttx/arch/mips/src/common/up_exit.c
+++ b/nuttx/arch/mips/src/common/up_exit.c
@@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <sched.h>
+#include <syscall.h>
#include <debug.h>
#include <nuttx/arch.h>
diff --git a/nuttx/arch/mips/src/common/up_internal.h b/nuttx/arch/mips/src/common/up_internal.h
index 1c8d4ed37c..3baa912352 100755
--- a/nuttx/arch/mips/src/common/up_internal.h
+++ b/nuttx/arch/mips/src/common/up_internal.h
@@ -165,9 +165,6 @@ extern void up_irqinitialize(void);
#ifdef CONFIG_ARCH_DMA
extern void weak_function up_dmainitialize(void);
#endif
-extern int up_saveusercontext(uint32_t *saveregs);
-extern void up_fullcontextrestore(uint32_t *restoreregs) __attribute__ ((noreturn));
-extern void up_switchcontext(uint32_t *saveregs, uint32_t *restoreregs);
extern void up_sigdeliver(void);
extern int up_timerisr(int irq, uint32_t *regs);
extern void up_lowputc(char ch);
diff --git a/nuttx/arch/mips/src/mips32/up_blocktask.c b/nuttx/arch/mips/src/mips32/up_blocktask.c
index ce92452b91..eb570b7a1a 100755
--- a/nuttx/arch/mips/src/mips32/up_blocktask.c
+++ b/nuttx/arch/mips/src/mips32/up_blocktask.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/src/mips32/up_blocktask.c
*
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,7 @@
#include <stdbool.h>
#include <sched.h>
+#include <syscall.h>
#include <debug.h>
#include <nuttx/arch.h>
diff --git a/nuttx/arch/mips/src/mips32/up_releasepending.c b/nuttx/arch/mips/src/mips32/up_releasepending.c
index ea36d152a9..978df0c7df 100755
--- a/nuttx/arch/mips/src/mips32/up_releasepending.c
+++ b/nuttx/arch/mips/src/mips32/up_releasepending.c
@@ -40,7 +40,9 @@
#include <nuttx/config.h>
#include <sched.h>
+#include <syscall.h>
#include <debug.h>
+
#include <nuttx/arch.h>
#include "os_internal.h"
diff --git a/nuttx/arch/mips/src/mips32/up_reprioritizertr.c b/nuttx/arch/mips/src/mips32/up_reprioritizertr.c
index 19a4f05c6f..24e33693cc 100755
--- a/nuttx/arch/mips/src/mips32/up_reprioritizertr.c
+++ b/nuttx/arch/mips/src/mips32/up_reprioritizertr.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/src/mips32/up_reprioritizertr.c
*
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <sched.h>
+#include <syscall.h>
#include <debug.h>
#include <nuttx/arch.h>
diff --git a/nuttx/arch/mips/src/mips32/up_sigdeliver.c b/nuttx/arch/mips/src/mips32/up_sigdeliver.c
index 05a9560701..7a291b58ba 100644
--- a/nuttx/arch/mips/src/mips32/up_sigdeliver.c
+++ b/nuttx/arch/mips/src/mips32/up_sigdeliver.c
@@ -41,6 +41,7 @@
#include <stdint.h>
#include <sched.h>
+#include <syscall.h>
#include <debug.h>
#include <nuttx/irq.h>
diff --git a/nuttx/arch/mips/src/mips32/up_syscall0.S b/nuttx/arch/mips/src/mips32/up_syscall0.S
new file mode 100644
index 0000000000..241fd7aa73
--- /dev/null
+++ b/nuttx/arch/mips/src/mips32/up_syscall0.S
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * arch/mips/src/mips32/up_syscall0.S
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <arch/mips32/registers.h>
+#include <arch/mips32/cp0.h>
+
+/****************************************************************************
+ * Global Symbols
+ ****************************************************************************/
+
+ .file "up_syscall0.S"
+ .global sys_call0
+ .global sys_call1
+ .global sys_call2
+ .global sys_call3
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_syscall0, up_syscall1, up_syscall2, up_syscall3
+ *
+ * Description:
+ * up_syscall0 - System call SYS_ argument and no additional parameters.
+ * up_syscall1 - System call SYS_ argument and one additional parameter.
+ * up_syscall2 - System call SYS_ argument and two additional parameters.
+ * up_syscall3 - System call SYS_ argument and three additional parameters.
+ *
+ ****************************************************************************/
+
+ .text
+ .set noreorder
+ .ent sys_call0
+sys_call0: /* r4 holds the syscall number */
+sys_call1: /* r4 holds the syscall number, argument in r5 */
+sys_call2: /* r4 holds the syscall number, arguments in r5 and r6 */
+sys_call3: /* r4 holds the syscall number, arguments in r5, r6, and r7 */
+
+ .set push
+ .set noat
+ mfc0 t3, MIPS32_CP0_CAUSE /* t3 = CP0 cause register */
+ ori t3, (1 << 8) /* Bit 8: Request software interrupt 0 */
+ .set noreorder
+ mtc0 t3, MIPS32_CP0_CAUSE /* Trigger the software interrupt */
+ nop /* Delay slot */
+ j ra /* Return with result in v0 */
+ .end sys_call0
diff --git a/nuttx/arch/mips/src/mips32/up_unblocktask.c b/nuttx/arch/mips/src/mips32/up_unblocktask.c
index c32bc573e9..c0106e94c3 100755
--- a/nuttx/arch/mips/src/mips32/up_unblocktask.c
+++ b/nuttx/arch/mips/src/mips32/up_unblocktask.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/src/mips32/up_unblocktask.c
*
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,9 @@
#include <nuttx/config.h>
#include <sched.h>
+#include <syscall.h>
#include <debug.h>
+
#include <nuttx/arch.h>
#include "os_internal.h"
diff --git a/nuttx/arch/mips/src/pic32mx/Make.defs b/nuttx/arch/mips/src/pic32mx/Make.defs
index 011cd1ba9d..b297d7fed2 100755
--- a/nuttx/arch/mips/src/pic32mx/Make.defs
+++ b/nuttx/arch/mips/src/pic32mx/Make.defs
@@ -39,7 +39,7 @@ HEAD_ASRC = pic32mx-head.S
# Common MIPS files
-CMN_ASRCS =
+CMN_ASRCS = up_syscall0.S
CMN_CSRCS = up_allocateheap.c up_assert.c up_blocktask.c up_copystate.c \
up_createstack.c up_doirq.c up_exit.c up_idle.c up_initialize.c \
up_initialstate.c up_interruptcontext.c up_irq.c up_lowputs.c \