From 7a81bce7b14c4c19aa05c4292c49f28162e06f3d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 28 Aug 2014 12:09:49 -0600 Subject: [PATCH] The system call library can now be built with CONFIG_NUTTX_KERNEL. New select: CONFIG_LIB_SYSCALL --- Kconfig | 3 +-- Makefile.unix | 14 ++++++++++---- Makefile.win | 14 ++++++++++---- arch/arm/src/armv6-m/svcall.h | 22 +++++++++++++++------- arch/arm/src/armv6-m/up_svcall.c | 8 ++++---- arch/arm/src/armv7-m/svcall.h | 22 +++++++++++++++------- arch/arm/src/armv7-m/up_svcall.c | 8 ++++---- syscall/Kconfig | 28 +++++++++++++++++++++++++--- 8 files changed, 84 insertions(+), 35 deletions(-) diff --git a/Kconfig b/Kconfig index 7a5f41cba13..4a84866cf59 100644 --- a/Kconfig +++ b/Kconfig @@ -186,6 +186,7 @@ config PASS1_OBJECT config NUTTX_KERNEL bool "NuttX kernel build" default n + select LIB_SYSCALL ---help--- Builds NuttX as a separately compiled kernel. @@ -681,9 +682,7 @@ endmenu menu "RTOS Features" source sched/Kconfig -if NUTTX_KERNEL source syscall/Kconfig -endif endmenu menu "Device Drivers" diff --git a/Makefile.unix b/Makefile.unix index b0e7cca7b0e..ec662a6944d 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -119,9 +119,7 @@ OTHERDIRS = lib ifeq ($(CONFIG_NUTTX_KERNEL),y) -NONFSDIRS += syscall -CONTEXTDIRS += syscall -USERDIRS += syscall libc mm $(USER_ADDONS) +USERDIRS += libc mm $(USER_ADDONS) ifeq ($(CONFIG_HAVE_CXX),y) USERDIRS += libxx endif @@ -129,7 +127,7 @@ endif else NONFSDIRS += libc mm -OTHERDIRS += syscall $(USER_ADDONS) +OTHERDIRS += $(USER_ADDONS) ifeq ($(CONFIG_HAVE_CXX),y) NONFSDIRS += libxx else @@ -138,6 +136,14 @@ endif endif +ifeq ($(CONFIG_LIB_SYSCALL),y) +NONFSDIRS += syscall +CONTEXTDIRS += syscall +USERDIRS += syscall +else +OTHERDIRS += syscall +endif + ifeq ($(CONFIG_NX),y) NONFSDIRS += graphics libnx CONTEXTDIRS += graphics libnx diff --git a/Makefile.win b/Makefile.win index 91aec195e05..bc9cfcf5814 100644 --- a/Makefile.win +++ b/Makefile.win @@ -112,9 +112,7 @@ OTHERDIRS = lib ifeq ($(CONFIG_NUTTX_KERNEL),y) -NONFSDIRS += syscall -CONTEXTDIRS += syscall -USERDIRS += syscall libc mm $(USER_ADDONS) +USERDIRS += libc mm $(USER_ADDONS) ifeq ($(CONFIG_HAVE_CXX),y) USERDIRS += libxx endif @@ -122,7 +120,7 @@ endif else NONFSDIRS += libc mm -OTHERDIRS += syscall $(USER_ADDONS) +OTHERDIRS += $(USER_ADDONS) ifeq ($(CONFIG_HAVE_CXX),y) NONFSDIRS += libxx else @@ -131,6 +129,14 @@ endif endif +ifeq ($(CONFIG_LIB_SYSCALL),y) +NONFSDIRS += syscall +CONTEXTDIRS += syscall +USERDIRS += syscall +else +OTHERDIRS += syscall +endif + ifeq ($(CONFIG_NX),y) NONFSDIRS += graphics libnx CONTEXTDIRS += graphics libnx diff --git a/arch/arm/src/armv6-m/svcall.h b/arch/arm/src/armv6-m/svcall.h index daa70a0c0ec..f5511c525d0 100644 --- a/arch/arm/src/armv6-m/svcall.h +++ b/arch/arm/src/armv6-m/svcall.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/armv6-m/svcall.h * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,7 @@ #include -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL # include #endif @@ -55,11 +55,19 @@ * 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 have the value 8" -# elif CONFIG_SYS_RESERVED != 8 -# error "CONFIG_SYS_RESERVED must have the value 8" +#ifdef CONFIG_LIB_SYSCALL +# ifdef CONFIG_NUTTX_KERNEL +# ifndef CONFIG_SYS_RESERVED +# error "CONFIG_SYS_RESERVED must be defined to have the value 8" +# elif CONFIG_SYS_RESERVED != 8 +# error "CONFIG_SYS_RESERVED must have the value 8" +# endif +# else +# ifndef CONFIG_SYS_RESERVED +# error "CONFIG_SYS_RESERVED must be defined to have the value 3" +# elif CONFIG_SYS_RESERVED != 3 +# error "CONFIG_SYS_RESERVED must have the value 3" +# endif # endif #endif diff --git a/arch/arm/src/armv6-m/up_svcall.c b/arch/arm/src/armv6-m/up_svcall.c index 1b367259bee..ad9da62d48e 100644 --- a/arch/arm/src/armv6-m/up_svcall.c +++ b/arch/arm/src/armv6-m/up_svcall.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/armv6-m/up_svcall.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,7 +47,7 @@ #include #include -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL # include #endif @@ -119,7 +119,7 @@ * ****************************************************************************/ -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL static void dispatch_syscall(void) naked_function; static void dispatch_syscall(void) { @@ -444,7 +444,7 @@ int up_svcall(int irq, FAR void *context) default: { -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL FAR struct tcb_s *rtcb = sched_self(); int index = rtcb->xcp.nsyscalls; diff --git a/arch/arm/src/armv7-m/svcall.h b/arch/arm/src/armv7-m/svcall.h index 2c47353350f..64c4bdfe8d3 100644 --- a/arch/arm/src/armv7-m/svcall.h +++ b/arch/arm/src/armv7-m/svcall.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/arm/src/armv7-m/svcall.h * - * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,7 @@ #include -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL # include #endif @@ -55,11 +55,19 @@ * 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 have the value 8" -# elif CONFIG_SYS_RESERVED != 8 -# error "CONFIG_SYS_RESERVED must have the value 8" +#ifdef CONFIG_LIB_SYSCALL +# ifdef CONFIG_NUTTX_KERNEL +# ifndef CONFIG_SYS_RESERVED +# error "CONFIG_SYS_RESERVED must be defined to have the value 8" +# elif CONFIG_SYS_RESERVED != 8 +# error "CONFIG_SYS_RESERVED must have the value 8" +# endif +# else +# ifndef CONFIG_SYS_RESERVED +# error "CONFIG_SYS_RESERVED must be defined to have the value 3" +# elif CONFIG_SYS_RESERVED != 3 +# error "CONFIG_SYS_RESERVED must have the value 3" +# endif # endif #endif diff --git a/arch/arm/src/armv7-m/up_svcall.c b/arch/arm/src/armv7-m/up_svcall.c index be33b675d98..9909057d3fb 100644 --- a/arch/arm/src/armv7-m/up_svcall.c +++ b/arch/arm/src/armv7-m/up_svcall.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/armv7-m/up_svcall.c * - * Copyright (C) 2009, 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,7 +47,7 @@ #include #include -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL # include #endif @@ -116,7 +116,7 @@ * ****************************************************************************/ -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL static void dispatch_syscall(void) naked_function; static void dispatch_syscall(void) { @@ -443,7 +443,7 @@ int up_svcall(int irq, FAR void *context) default: { -#ifdef CONFIG_NUTTX_KERNEL +#ifdef CONFIG_LIB_SYSCALL FAR struct tcb_s *rtcb = sched_self(); int index = rtcb->xcp.nsyscalls; diff --git a/syscall/Kconfig b/syscall/Kconfig index 0c5b74ab177..f1138611ac6 100644 --- a/syscall/Kconfig +++ b/syscall/Kconfig @@ -3,9 +3,31 @@ # see misc/tools/kconfig-language.txt. # -if NUTTX_KERNEL +menuconfig LIB_SYSCALL + bool "System call support" + default n + ---help--- + Build in support for "system calls". System calls are used to + implement a call gate mechanism that can be be used to call from + user code into the kernel. This is only useful for user code that + likes outside of the kernel such as when the NUTTX_KERNEL build is + selected. -comment "System call configuration" + This permits calls from user-mode code into kernel mode; the call + gate will change the mode of operation from user to supervisor mode, + then call into the OS code on behalf of the user-mode application. + + If if there are no privilege issues preventing the call, system + calls may also be of value because it can eliminate the need for + symbol tables when linking external modules to the NuttX base code. + The selection will build libsyscall. External modules can then link + with libsyscall when they are built and they can call into the OS + with no knowledge of the actual address in the OS. In this case, + they call into a proxy that is link with the external code; that + proxy then marshals the call parameter and invokes the system call + to accomplish the interface. + +if LIB_SYSCALL config SYS_RESERVED int "Number of reserved system calls" @@ -34,4 +56,4 @@ config SYS_NNEST space memory. So it is expected that the maximum nesting level will be only 2. -endif +endif # LIB_SYSCALL