diff --git a/arch/c5471/defconfig b/arch/c5471/defconfig index d0d7c755b3d61e7e971143c6f90ae4fdb6e2d9db..90ae4c8985af7a0fa58e0b273ec31b7b51879ac3 100644 --- a/arch/c5471/defconfig +++ b/arch/c5471/defconfig @@ -200,6 +200,8 @@ CONFIG_PREALLOC_WDOGS=32 # # CONFIG_BOOT_FROM_FLASH - Some configurations support XIP # operation from FLASH. +# CONFIG_CUSTOM_STACK - The up_ implementation will handle +# all stack operations outside of the nuttx model. # CONFIG_STACK_POINTER - The initial stack pointer (arm7tdmi only) # CONFIG_PROC_STACK_SIZE - The size of the initial stack # CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size @@ -208,6 +210,7 @@ CONFIG_PREALLOC_WDOGS=32 # CONFIG_HEAP_SIZE - The size of the heap # CONFIG_BOOT_FROM_FLASH=n +CONFIG_CUSTOM_STACK=n CONFIG_STACK_POINTER= CONFIG_PROC_STACK_SIZE=4096 CONFIG_PTHREAD_STACK_MIN=256 diff --git a/arch/c5471/src/up_irq.c b/arch/c5471/src/up_irq.c index 3c8a17371260abc068074496be5619c070cf1939..9c05bc91b3b967ee8647949fd579930d83947897 100644 --- a/arch/c5471/src/up_irq.c +++ b/arch/c5471/src/up_irq.c @@ -189,7 +189,7 @@ void up_irqinitialize(void) void up_disable_irq(int irq) { - if (irq < NR_IRQS) + if ((unsigned)irq < NR_IRQS) { uint32 reg = getreg32(MASK_IT_REG); putreg32(reg | (1 << irq), MASK_IT_REG); @@ -206,7 +206,7 @@ void up_disable_irq(int irq) void up_enable_irq(int irq) { - if (irq < NR_IRQS) + if ((unsigned)irq < NR_IRQS) { uint32 reg = getreg32(MASK_IT_REG); putreg32(reg & ~(1 << irq), MASK_IT_REG); diff --git a/arch/sim/defconfig b/arch/sim/defconfig index 58648c509692611891b5cf06ac2a01268795bf93..9a3cb893caa56b3cd75ea83bb870fee5ff168d40 100644 --- a/arch/sim/defconfig +++ b/arch/sim/defconfig @@ -167,6 +167,8 @@ CONFIG_PREALLOC_WDOGS=32 # # CONFIG_BOOT_FROM_FLASH - Some configurations support XIP # operation from FLASH. +# CONFIG_CUSTOM_STACK - The up_ implementation will handle +# all stack operations outside of the nuttx model. # CONFIG_STACK_POINTER - The initial stack pointer # CONFIG_PROC_STACK_SIZE - The size of the initial stack # CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size @@ -175,6 +177,7 @@ CONFIG_PREALLOC_WDOGS=32 # CONFIG_HEAP_SIZE - The size of the heap # CONFIG_BOOT_FROM_FLASH=n +CONFIG_CUSTOM_STACK=n CONFIG_PROC_STACK_SIZE=0x00001000 CONFIG_PTHREAD_STACK_MIN=256 CONFIG_PTHREAD_STACK_DEFAULT=8192 diff --git a/examples/ostest/main.c b/examples/ostest/main.c index 69d783c7f2e7615908954e0a902247d48a1867de..8e09230f50fe511c5181b6ee4435a43081a7c338 100644 --- a/examples/ostest/main.c +++ b/examples/ostest/main.c @@ -191,8 +191,13 @@ int user_start(int parm1, int parm2, int parm3, int parm4) /* Verify that we can spawn a new task */ +#ifndef CONFIG_CUSTOM_STACK result = task_create("ostest", PRIORITY, STACKSIZE, user_main, arg1, arg2, arg3, arg4); +#else + result = task_create("ostest", PRIORITY, user_main, + arg1, arg2, arg3, arg4); +#endif if (result == ERROR) { printf("user_start: ERROR Failed to start user_main\n"); diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 11e6a96fc041895b4482952424db65306683adef..a243a3f6a3578d68a8165294bf0b5a39ec796a5e 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -150,7 +150,9 @@ EXTERN void up_initial_state(FAR _TCB *tcb); * must be allocated. ************************************************************/ +#ifndef CONFIG_CUSTOM_STACK EXTERN STATUS up_create_stack(FAR _TCB *tcb, size_t stack_size); +#endif /************************************************************ * Name: up_use_stack @@ -173,7 +175,9 @@ EXTERN STATUS up_create_stack(FAR _TCB *tcb, size_t stack_size); * ************************************************************/ +#ifndef CONFIG_CUSTOM_STACK EXTERN STATUS up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size); +#endif /************************************************************ * Name: up_release_stack @@ -184,7 +188,9 @@ EXTERN STATUS up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size); * ************************************************************/ +#ifndef CONFIG_CUSTOM_STACK EXTERN void up_release_stack(FAR _TCB *dtcb); +#endif /************************************************************ * Name: up_unblock_task @@ -314,7 +320,9 @@ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority); * ************************************************************/ +#ifndef CONFIG_DISABLE_SIGNALS EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver); +#endif /************************************************************ * Name: up_allocate_heap diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h index a806adb1505f99119c9375d7b335cc7664de2465..e9b66293c4b583d3ddcabbc2620df70ebab1d9cc 100644 --- a/include/nuttx/irq.h +++ b/include/nuttx/irq.h @@ -73,10 +73,6 @@ typedef int (*swint_t)(int code, int parm2, int parm3, * Public Variables ************************************************************/ -#ifndef __ASSEMBLY__ -struct xcptcontext *current_xcp; -#endif - /************************************************************ * Public Function Prototypes ************************************************************/ diff --git a/include/sched.h b/include/sched.h index f83cfbe5329e03280150335e4e8b98cb102e5494..0cf8d58d551f4b2af22f339ba26ced5329fe5d96 100644 --- a/include/sched.h +++ b/include/sched.h @@ -190,6 +190,7 @@ struct _TCB /* Stack-Related Fields *********************************************/ +#ifndef CONFIG_CUSTOM_STACK size_t adj_stack_size; /* Stack size after adjustment */ /* for hardware, processor, etc. */ /* (for debug purposes only) */ @@ -197,6 +198,7 @@ struct _TCB /* Need to deallocate stack */ FAR void *adj_stack_ptr; /* Adjusted StatckAllocPtr for HW */ /* The initial stack pointer value */ +#endif /* POSIX thread Specific Data ***************************************/ @@ -269,14 +271,27 @@ extern "C" { /* Task Control Interfaces (non-standard) */ +#ifndef CONFIG_CUSTOM_STACK EXTERN STATUS task_init(FAR _TCB *tcb, const char *name, int priority, FAR uint32 *stack, uint32 stack_size, main_t entry, FAR char *arg1, FAR char *arg2, FAR char *arg3, FAR char *arg4); +#else +EXTERN STATUS task_init(FAR _TCB *tcb, const char *name, int priority, + main_t entry, + FAR char *arg1, FAR char *arg2, + FAR char *arg3, FAR char *arg4); +#endif EXTERN STATUS task_activate(FAR _TCB *tcb); +#ifndef CONFIG_CUSTOM_STACK EXTERN int task_create(const char *name, int priority, int stack_size, main_t main, FAR char *arg1, FAR char *arg2, FAR char *arg3, FAR char *arg4); +#else +EXTERN int task_create(const char *name, int priority, main_t main, + FAR char *arg1, FAR char *arg2, + FAR char *arg3, FAR char *arg4); +#endif EXTERN STATUS task_delete(pid_t pid); EXTERN STATUS task_restart(pid_t pid); diff --git a/include/string.h b/include/string.h index 0b05eccc52ef6753e07dfb462fe08e1f0d81533a..a5c1a1a9e85d4ca68f426ef983be542593097add 100644 --- a/include/string.h +++ b/include/string.h @@ -74,12 +74,12 @@ EXTERN char *strrchr(const char *, int); EXTERN size_t strspn(const char *, const char *); EXTERN size_t strcspn(const char *, const char *); EXTERN char *strstr(const char *, const char *); -EXTERN char *strtok(FAR char *, const char *); +EXTERN char *strtok(char *, const char *); -EXTERN void *memset(FAR void *s, int c, size_t n); -EXTERN void *memcpy(FAR void *dest, FAR const void *src, size_t n); -EXTERN int memcmp(FAR const void *s1, FAR const void *s2, size_t n); -EXTERN void *memmove(FAR void *dest, FAR const void *src, size_t count); +EXTERN void *memset(void *s, int c, size_t n); +EXTERN void *memcpy(void *dest, const void *src, size_t n); +EXTERN int memcmp(const void *s1, const void *s2, size_t n); +EXTERN void *memmove(void *dest, const void *src, size_t count); #ifndef CONFIG_ARCH_BZERO # define bzero(s,n) (void)memset(s,0,n) diff --git a/lib/lib_memcmp.c b/lib/lib_memcmp.c index 5de0b1c49820a7239c5eacf14243336c89996877..b433eda90f5b87e35c0a67d74b4515ac77a30c12 100644 --- a/lib/lib_memcmp.c +++ b/lib/lib_memcmp.c @@ -50,7 +50,7 @@ ************************************************************/ #ifndef CONFIG_ARCH_MEMCMP -int memcmp(FAR const void *s1, FAR const void *s2, size_t n) +int memcmp(const void *s1, const void *s2, size_t n) { unsigned char *p1 = (unsigned char *)s1; unsigned char *p2 = (unsigned char *)s2; diff --git a/lib/lib_memcpy.c b/lib/lib_memcpy.c index 417fdc82f8642601ae2137b0fac5d1aca02b254e..0953b4d2829018cfdaa0a035049a6e9b35155b88 100644 --- a/lib/lib_memcpy.c +++ b/lib/lib_memcpy.c @@ -50,7 +50,7 @@ ************************************************************/ #ifndef CONFIG_ARCH_MEMCPY -void *memcpy(FAR void *dest, FAR const void *src, size_t n) +void *memcpy(void *dest, const void *src, size_t n) { unsigned char *pout = (unsigned char*)dest; unsigned char *pin = (unsigned char*)src; diff --git a/lib/lib_memmove.c b/lib/lib_memmove.c index c640452046f894731a96e892b05ab71b39a50ec8..cad0fa2fc406f26a72af2500597f53ff23b25970 100644 --- a/lib/lib_memmove.c +++ b/lib/lib_memmove.c @@ -50,7 +50,7 @@ ************************************************************/ #ifndef CONFIG_ARCH_MEMMOVE -void *memmove(FAR void *dest, FAR const void *src, size_t count) +void *memmove(void *dest, const void *src, size_t count) { char *tmp, *s; if (dest <= src) diff --git a/lib/lib_memset.c b/lib/lib_memset.c index 33bead8db3c9dab6c70f665eed3e5000b5b29e76..25b4929ebd602f1821bd3170d3ff5a2322d1e442 100644 --- a/lib/lib_memset.c +++ b/lib/lib_memset.c @@ -50,7 +50,7 @@ ************************************************************/ #ifndef CONFIG_ARCH_MEMSET -void *memset(FAR void *s, int c, size_t n) +void *memset(void *s, int c, size_t n) { unsigned char *p = (unsigned char*)s; while (n-- > 0) *p++ = c; diff --git a/sched/Makefile b/sched/Makefile index af11ede3954da2b4119bca56d9877446936f62b4..d110cb664ae18b28efa620a0b1fe346511e6d4b1 100644 --- a/sched/Makefile +++ b/sched/Makefile @@ -44,7 +44,7 @@ MISC_SRCS = os_start.c get_errno_ptr.c \ sched_setupstreams.c sched_getfiles.c sched_getstreams.c \ sched_setupidlefiles.c sched_setuptaskfiles.c sched_setuppthreadfiles.c \ sched_releasefiles.c -TSK_SRCS = task_create.c task_delete.c task_restart.c \ +TSK_SRCS = task_create.c task_init.c task_delete.c task_restart.c \ exit.c abort.c atexit.c getpid.c \ sched_addreadytorun.c sched_removereadytorun.c sched_addprioritized.c \ sched_mergepending.c sched_addblocked.c sched_removeblocked.c \ diff --git a/sched/get_errno_ptr.c b/sched/get_errno_ptr.c index 7a8084c71a105d008dbb03e1d82d578b8e063054..23503243b279fd3bc8d89f5063c6018b0628cb7e 100644 --- a/sched/get_errno_ptr.c +++ b/sched/get_errno_ptr.c @@ -41,6 +41,8 @@ #include <errno.h> #include "os_internal.h" +#undef get_errno_ptr + /************************************************************ * Global Functions ************************************************************/ diff --git a/sched/os_internal.h b/sched/os_internal.h index 900484d9bdfe41213ffebe1f136df40cf1ca0b32..26a709a99add204f11f7e9f3883c4280b51861f3 100644 --- a/sched/os_internal.h +++ b/sched/os_internal.h @@ -239,6 +239,7 @@ extern const tasklist_t g_tasklisttable[NUM_TASK_STATES]; * Public Function Prototypes ************************************************************/ +extern void task_start(void); extern STATUS _task_init(FAR _TCB *tcb, const char *name, int priority, start_t start, main_t main, boolean pthread, diff --git a/sched/os_start.c b/sched/os_start.c index 1238342c4a807981df7ddd59967430139f3d80f9..18b8945ee05c05ed12883451b9f3039d31862acf 100644 --- a/sched/os_start.c +++ b/sched/os_start.c @@ -405,9 +405,14 @@ void os_start(void) */ dbg("Starting init thread\n"); +#ifndef CONFIG_CUSTOM_STACK init_taskid = task_create("init", SCHED_PRIORITY_DEFAULT, CONFIG_PROC_STACK_SIZE, (main_t)user_start, 0, 0, 0, 0); +#else + init_taskid = task_create("init", SCHED_PRIORITY_DEFAULT, + (main_t)user_start, 0, 0, 0, 0); +#endif ASSERT(init_taskid != ERROR); /* When control is return to this point, the system is idle. */ diff --git a/sched/sched_releasetcb.c b/sched/sched_releasetcb.c index 5e644839da72d3a5ee95999b0e1cf3807e40affa..6415fba2b70f309cc15c7f4468145352b49706f8 100644 --- a/sched/sched_releasetcb.c +++ b/sched/sched_releasetcb.c @@ -110,10 +110,12 @@ int sched_releasetcb(FAR _TCB *tcb) /* Delete the thread's stack if one has been allocated */ +#ifndef CONFIG_CUSTOM_STACK if (tcb->stack_alloc_ptr) { up_release_stack(tcb); } +#endif /* Release command line arguments that were allocated * for task start/re-start. diff --git a/sched/task_create.c b/sched/task_create.c index 399bba20c4ce706cd8d67fa0bc4b1544de195936..7b73c15fa79255a46fe53d3e5e97eb350d80cb69 100644 --- a/sched/task_create.c +++ b/sched/task_create.c @@ -70,53 +70,12 @@ static FAR char g_noname[] = "no name"; * Private Function Prototypes ************************************************************/ -static void task_start(void); static STATUS task_assignpid(FAR _TCB* tcb); /************************************************************ * Private Functions ************************************************************/ -/************************************************************ - * Name: task_start - * - * Description: - * This function is the low level entry point - * into the main thread of execution of a task. It receives - * initial control when the task is started and calls main - * entry point of the newly started task. - * - * Inputs: - * None - * - * Return: - * None - * - ************************************************************/ - -static void task_start(void) -{ - FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head; - int argc; - - /* Count how many non-null arguments we are passing */ - - for (argc = 1; argc <= NUM_TASK_ARGS; argc++) - { - /* The first non-null argument terminates the list */ - - if (!tcb->argv[argc]) - { - break; - } - } - - /* Call the 'main' entry point passing argc and argv. If/when - * the task returns, */ - - exit(tcb->entry.main(argc, tcb->argv)); -} - /************************************************************ * Name: task_assignpid * @@ -188,15 +147,55 @@ static STATUS task_assignpid(FAR _TCB *tcb) ************************************************************/ /************************************************************ - * Name: _task_init and task_init + * Name: task_start + * + * Description: + * This function is the low level entry point + * into the main thread of execution of a task. It receives + * initial control when the task is started and calls main + * entry point of the newly started task. + * + * Inputs: + * None + * + * Return: + * None + * + ************************************************************/ + +void task_start(void) +{ + FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head; + int argc; + + /* Count how many non-null arguments we are passing */ + + for (argc = 1; argc <= NUM_TASK_ARGS; argc++) + { + /* The first non-null argument terminates the list */ + + if (!tcb->argv[argc]) + { + break; + } + } + + /* Call the 'main' entry point passing argc and argv. If/when + * the task returns, */ + + exit(tcb->entry.main(argc, tcb->argv)); +} + +/************************************************************ + * Name: _task_init * * Description: - * These functions initializes a Task Control Block (TCB) + * This functions initializes a Task Control Block (TCB) * in preparation for starting a new thread. _task_init() - * is an internal version of the function that has some - * additional control arguments and task_init() is a wrapper - * function that creates a VxWorks-like user API. - * task_init() is, otherwise, not used by the OS. + * is an internal version of the task_init() function that + * has some additional control arguments and task_init() + * is a wrapper function that creates a VxWorks-like user + * API. task_init() is, otherwise, not used by the OS. * * _task_init() is called from task_init() and task_start().\ * It is also called from pthread_create() to create a @@ -332,39 +331,6 @@ STATUS _task_init(FAR _TCB *tcb, const char *name, int priority, return ret; } -/************************************************************ - * Name: _task_init and task_init - * - * Description: - * This is a wrapper around the internal _task_init() that - * provides a VxWorks-like API. See _task_init() for - * further information. - * - * Input Parameters: - * tcb - Address of the new task's TCB - * name - Name of the new task (not used) - * priority - Priority of the new task - * stack - start of the pre-allocated stack - * stack_size - size (in bytes) of the stack allocated - * entry - Application start point of the new task - * arg1-4 - Four required task arguments to pass to - * the task when it is started. - * - * Return Value: - * see _task_init() - * - ************************************************************/ - -STATUS task_init(FAR _TCB *tcb, const char *name, int priority, - FAR uint32 *stack, uint32 stack_size, main_t entry, - FAR char *arg1, FAR char *arg2, - FAR char *arg3, FAR char *arg4) -{ - up_use_stack(tcb, stack, stack_size); - return _task_init(tcb, name, priority, task_start, entry, - FALSE, arg1, arg2, arg3, arg4); -} - /************************************************************ * Name: task_activate * @@ -441,10 +407,17 @@ STATUS task_activate(FAR _TCB *tcb) * ************************************************************/ +#ifndef CONFIG_CUSTOM_STACK int task_create(const char *name, int priority, int stack_size, main_t entry, FAR char *arg1, FAR char *arg2, FAR char *arg3, FAR char *arg4) +#else +int task_create(const char *name, int priority, + main_t entry, + FAR char *arg1, FAR char *arg2, + FAR char *arg3, FAR char *arg4) +#endif { FAR _TCB *tcb; STATUS status; @@ -469,12 +442,14 @@ int task_create(const char *name, int priority, /* Allocate the stack for the TCB */ +#ifndef CONFIG_CUSTOM_STACK status = up_create_stack(tcb, stack_size); if (status != OK) { sched_releasetcb(tcb); return ERROR; } +#endif /* Initialize the task control block */ diff --git a/sched/task_init.c b/sched/task_init.c new file mode 100644 index 0000000000000000000000000000000000000000..17596378b047d771e4943c264a868c3cadd22c85 --- /dev/null +++ b/sched/task_init.c @@ -0,0 +1,114 @@ +/************************************************************ + * task_init.c + * + * Copyright (C) 2007 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 Gregory Nutt 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 <sys/types.h> +#include <sched.h> +#include "os_internal.h" + +/************************************************************ + * Definitions + ************************************************************/ + +/************************************************************ + * Private Type Declarations + ************************************************************/ + +/************************************************************ + * Global Variables + ************************************************************/ + +/************************************************************ + * Private Variables + ************************************************************/ + +/************************************************************ + * Private Function Prototypes + ************************************************************/ + +/************************************************************ + * Private Functions + ************************************************************/ + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: task_init + * + * Description: + * This is a wrapper around the internal _task_init() that + * provides a VxWorks-like API. See _task_init() for + * further information. + * + * Input Parameters: + * tcb - Address of the new task's TCB + * name - Name of the new task (not used) + * priority - Priority of the new task + * stack - start of the pre-allocated stack + * stack_size - size (in bytes) of the stack allocated + * entry - Application start point of the new task + * arg1-4 - Four required task arguments to pass to + * the task when it is started. + * + * Return Value: + * see _task_init() + * + ************************************************************/ + +#ifndef CONFIG_CUSTOM_STACK +STATUS task_init(FAR _TCB *tcb, const char *name, int priority, + FAR uint32 *stack, uint32 stack_size, main_t entry, + FAR char *arg1, FAR char *arg2, + FAR char *arg3, FAR char *arg4) +{ + up_use_stack(tcb, stack, stack_size); + return _task_init(tcb, name, priority, task_start, entry, + FALSE, arg1, arg2, arg3, arg4); +} +#else +STATUS task_init(FAR _TCB *tcb, const char *name, int priority, + main_t entry, + FAR char *arg1, FAR char *arg2, + FAR char *arg3, FAR char *arg4) +{ + return _task_init(tcb, name, priority, task_start, entry, + FALSE, arg1, arg2, arg3, arg4); +} +#endif