diff options
author | px4dev <px4@purgatory.org> | 2013-01-11 00:39:22 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2013-01-11 00:39:22 -0800 |
commit | ccf9882dc5dbe38b621110f82c4e2ff63aef900e (patch) | |
tree | 18b0af628174bf27815dd52a376c8b72b6a626d4 /nuttx/include | |
parent | 40dfbf0d977729951d73bcb089ca8f89c7b83efe (diff) | |
parent | 0f2decb70f505b108999fcdb80e89d7aae6760ce (diff) | |
download | px4-firmware-ccf9882dc5dbe38b621110f82c4e2ff63aef900e.tar.gz px4-firmware-ccf9882dc5dbe38b621110f82c4e2ff63aef900e.tar.bz2 px4-firmware-ccf9882dc5dbe38b621110f82c4e2ff63aef900e.zip |
Merge branch 'master' into nuttx-merge-5447
Diffstat (limited to 'nuttx/include')
-rw-r--r-- | nuttx/include/cxx/cmath | 62 | ||||
-rw-r--r-- | nuttx/include/cxx/cstdlib | 1 | ||||
-rw-r--r-- | nuttx/include/debug.h | 25 | ||||
-rw-r--r-- | nuttx/include/nuttx/arch.h | 290 | ||||
-rw-r--r-- | nuttx/include/nuttx/binfmt/binfmt.h | 338 | ||||
-rw-r--r-- | nuttx/include/nuttx/binfmt/elf.h | 340 | ||||
-rw-r--r-- | nuttx/include/nuttx/binfmt/nxflat.h | 287 | ||||
-rw-r--r-- | nuttx/include/nuttx/compiler.h | 2 | ||||
-rw-r--r-- | nuttx/include/nuttx/fs/fs.h | 2 | ||||
-rw-r--r-- | nuttx/include/nuttx/input/keypad.h | 54 | ||||
-rw-r--r-- | nuttx/include/nuttx/math.h | 270 | ||||
-rw-r--r-- | nuttx/include/nuttx/mtd.h | 3 | ||||
-rw-r--r-- | nuttx/include/nuttx/sched.h | 32 | ||||
-rw-r--r-- | nuttx/include/nuttx/vt100.h | 4 | ||||
-rw-r--r-- | nuttx/include/stdbool.h | 35 |
15 files changed, 1682 insertions, 63 deletions
diff --git a/nuttx/include/cxx/cmath b/nuttx/include/cxx/cmath index 7cb3a2109..b30d5548b 100644 --- a/nuttx/include/cxx/cmath +++ b/nuttx/include/cxx/cmath @@ -40,6 +40,9 @@ // Included Files //*************************************************************************** +#include <nuttx/config.h> +#include <nuttx/compiler.h> + #include <math.h> //*************************************************************************** @@ -48,6 +51,34 @@ namespace std { +#if CONFIG_HAVE_FLOAT + using ::acosf; + using ::asinf; + using ::atanf; + using ::atan2f; + using ::ceilf; + using ::cosf; + using ::coshf; + using ::expf; + using ::fabsf; + using ::floorf; + using ::fmodf; + using ::frexpf; + using ::ldexpf; + using ::logf; + using ::log10f; + using ::log2f; + using ::modff; + using ::roundf; + using ::powf; + using ::sinf; + using ::sinhf; + using ::sqrtf; + using ::tanf; + using ::tanhf; +#endif + +#if CONFIG_HAVE_DOUBLE using ::acos; using ::asin; using ::atan; @@ -63,13 +94,44 @@ namespace std using ::ldexp; using ::log; using ::log10; + using ::log2; using ::modf; + using ::round; using ::pow; using ::sin; using ::sinh; using ::sqrt; using ::tan; using ::tanh; +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE + using ::acosl; + using ::asinl; + using ::atanl; + using ::atan2l; + using ::ceill; + using ::cosl; + using ::coshl; + using ::expl; + using ::fabsl; + using ::floorl; + using ::fmodl; + using ::frexpl; + using ::ldexpl; + using ::logl; + using ::log10l; + using ::log2l; + using ::modfl; + using ::roundl; + using ::powl; + using ::sinl; + using ::sinhl; + using ::sqrtl; + using ::tanl; + using ::tanhl; +#endif + } #endif // __INCLUDE_CXX_CMATH diff --git a/nuttx/include/cxx/cstdlib b/nuttx/include/cxx/cstdlib index 522f3fdb1..1bf8ed9da 100644 --- a/nuttx/include/cxx/cstdlib +++ b/nuttx/include/cxx/cstdlib @@ -70,6 +70,7 @@ namespace std #endif using ::strtol; + using ::strtoul; using ::strtod; using ::malloc; diff --git a/nuttx/include/debug.h b/nuttx/include/debug.h index 1f8c7d7ca..aa5efd432 100644 --- a/nuttx/include/debug.h +++ b/nuttx/include/debug.h @@ -571,12 +571,9 @@ * Public Function Prototypes ****************************************************************************/ -#undef EXTERN #if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern +extern "C" +{ #endif /* These low-level debug APIs are provided by the NuttX library. If the @@ -585,21 +582,20 @@ extern "C" { * or the other of the following. */ -EXTERN int lib_rawprintf(FAR const char *format, ...); +int lib_rawprintf(FAR const char *format, ...); #ifdef CONFIG_ARCH_LOWPUTC -EXTERN int lib_lowprintf(FAR const char *format, ...); +int lib_lowprintf(FAR const char *format, ...); #endif /* Dump a buffer of data */ -EXTERN void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, - unsigned int buflen); +void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen); /* Enable or disable debug output */ #ifdef CONFIG_DEBUG_ENABLE -EXTERN void dbg_enable(bool enable); +void dbg_enable(bool enable); #endif /* If the cross-compiler's pre-processor does not support variable length @@ -608,23 +604,22 @@ EXTERN void dbg_enable(bool enable); #ifndef CONFIG_CPP_HAVE_VARARGS #ifdef CONFIG_DEBUG -EXTERN int dbg(const char *format, ...); +int dbg(const char *format, ...); # ifdef CONFIG_ARCH_LOWPUTC -EXTERN int lldbg(const char *format, ...); +int lldbg(const char *format, ...); # endif # ifdef CONFIG_DEBUG_VERBOSE -EXTERN int vdbg(const char *format, ...); +int vdbg(const char *format, ...); # ifdef CONFIG_ARCH_LOWPUTC -EXTERN int llvdbg(const char *format, ...); +int llvdbg(const char *format, ...); # endif #endif #endif /* CONFIG_DEBUG */ #endif /* CONFIG_CPP_HAVE_VARARGS */ -#undef EXTERN #if defined(__cplusplus) } #endif diff --git a/nuttx/include/nuttx/arch.h b/nuttx/include/nuttx/arch.h index bf6be1ce0..8b4b10ade 100644 --- a/nuttx/include/nuttx/arch.h +++ b/nuttx/include/nuttx/arch.h @@ -46,6 +46,7 @@ #include <stdint.h> #include <stdbool.h> #include <sched.h> + #include <arch/arch.h> /**************************************************************************** @@ -67,10 +68,8 @@ typedef CODE void (*sig_deliver_t)(FAR _TCB *tcb); ****************************************************************************/ #ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern +extern "C" +{ #endif /**************************************************************************** @@ -98,7 +97,7 @@ extern "C" { * ****************************************************************************/ -EXTERN void up_initialize(void); +void up_initialize(void); /**************************************************************************** * Name: up_idle @@ -114,7 +113,7 @@ EXTERN void up_initialize(void); * ****************************************************************************/ -EXTERN void up_idle(void); +void up_idle(void); /**************************************************************************** * Name: up_initial_state @@ -130,7 +129,7 @@ EXTERN void up_idle(void); * ****************************************************************************/ -EXTERN void up_initial_state(FAR _TCB *tcb); +void up_initial_state(FAR _TCB *tcb); /**************************************************************************** * Name: up_create_stack @@ -155,7 +154,7 @@ EXTERN void up_initial_state(FAR _TCB *tcb); ****************************************************************************/ #ifndef CONFIG_CUSTOM_STACK -EXTERN int up_create_stack(FAR _TCB *tcb, size_t stack_size); +int up_create_stack(FAR _TCB *tcb, size_t stack_size); #endif /**************************************************************************** @@ -180,7 +179,7 @@ EXTERN int up_create_stack(FAR _TCB *tcb, size_t stack_size); ****************************************************************************/ #ifndef CONFIG_CUSTOM_STACK -EXTERN int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size); +int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size); #endif /**************************************************************************** @@ -193,7 +192,7 @@ EXTERN int 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); +void up_release_stack(FAR _TCB *dtcb); #endif /**************************************************************************** @@ -216,7 +215,7 @@ EXTERN void up_release_stack(FAR _TCB *dtcb); * ****************************************************************************/ -EXTERN void up_unblock_task(FAR _TCB *tcb); +void up_unblock_task(FAR _TCB *tcb); /**************************************************************************** * Name: up_block_task @@ -242,7 +241,7 @@ EXTERN void up_unblock_task(FAR _TCB *tcb); * ****************************************************************************/ -EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state); +void up_block_task(FAR _TCB *tcb, tstate_t task_state); /**************************************************************************** * Name: up_release_pending @@ -261,7 +260,7 @@ EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state); * ****************************************************************************/ -EXTERN void up_release_pending(void); +void up_release_pending(void); /**************************************************************************** * Name: up_reprioritize_rtr @@ -287,7 +286,7 @@ EXTERN void up_release_pending(void); * ****************************************************************************/ -EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority); +void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority); /**************************************************************************** * Name: _exit @@ -349,7 +348,7 @@ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority); ****************************************************************************/ #ifndef CONFIG_DISABLE_SIGNALS -EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver); +void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver); #endif /**************************************************************************** @@ -363,7 +362,7 @@ EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver); ****************************************************************************/ #ifndef CONFIG_HEAP_BASE -EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size); +void up_allocate_heap(FAR void **heap_start, size_t *heap_size); #endif /**************************************************************************** @@ -383,6 +382,214 @@ EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size); #endif /**************************************************************************** + * Address Environment Interfaces + * + * Low-level interfaces used in binfmt/ to instantiate tasks with address + * environments. These interfaces all operate on type task_addrenv_t which + * is an abstract representation of a task's address environment and must be + * defined in arch/arch.h if CONFIG_ADDRENV is defined. + * + * up_addrenv_create - Create an address environment + * up_addrenv_vaddr - Returns the virtual base address of the address + * environment + * up_addrenv_select - Instantiate an address environment + * up_addrenv_restore - Restore an address environment + * up_addrenv_destroy - Destroy an address environment. + * up_addrenv_assign - Assign an address environment to a TCB + * + * Higher-level interfaces used by the tasking logic. These interfaces are + * used by the functions in sched/ and all operate on the TCB which as been + * assigned an address environment by up_addrenv_assign(). + * + * up_addrenv_share - Clone the address environment assigned to one TCB + * to another. This operation is done when a pthread + * is created that share's the same address + * environment. + * up_addrenv_release - Release the TCBs reference to an address + * environment when a task/thread exits. + * + ****************************************************************************/ +/**************************************************************************** + * Name: up_addrenv_create + * + * Description: + * This function is called from the binary loader logic when a new + * task is created in order to instantiate an address environment for the + * task. up_addrenv_create is essentially the allocator of the physical + * memory for the new task. + * + * Input Parameters: + * envsize - The size (in bytes) of the address environment needed by the + * task. + * addrenv - The location to return the representation of the task address + * environment. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_create(size_t envsize, FAR task_addrenv_t *addrenv); +#endif + +/**************************************************************************** + * Name: up_addrenv_vaddr + * + * Description: + * Return the virtual address associated with the newly create address + * environment. This function is used by the binary loaders in order + * get an address that can be used to initialize the new task. + * + * Input Parameters: + * addrenv - The representation of the task address environment previously + * returned by up_addrenv_create. + * vaddr - The location to return the virtual address. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_vaddr(FAR task_addrenv_t addrenv, FAR void **vaddr); +#endif + +/**************************************************************************** + * Name: up_addrenv_select + * + * Description: + * After an address environment has been established for a task (via + * up_addrenv_create(). This function may be called to to instantiate + * that address environment in the virtual address space. this might be + * necessary, for example, to load the code for the task from a file or + * to access address environment private data. + * + * Input Parameters: + * addrenv - The representation of the task address environment previously + * returned by up_addrenv_create. + * oldenv + * The address environment that was in place before up_addrenv_select(). + * This may be used with up_addrenv_restore() to restore the original + * address environment that was in place before up_addrenv_select() was + * called. Note that this may be a task agnostic, hardware + * representation that is different from task_addrenv_t. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_select(task_addrenv_t addrenv, hw_addrenv_t *oldenv); +#endif + +/**************************************************************************** + * Name: up_addrenv_restore + * + * Description: + * After an address environment has been temporarilty instantiated by + * up_addrenv_select, this function may be called to to restore the + * original address environment. + * + * Input Parameters: + * oldenv - The hardware representation of the address environment + * previously returned by up_addrenv_select. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_restore(hw_addrenv_t oldenv); +#endif + +/**************************************************************************** + * Name: up_addrenv_destroy + * + * Description: + * Called from the binary loader loader during error handling to destroy + * the address environment previously created by up_addrenv_create(). + * + * Input Parameters: + * addrenv - The representation of the task address environment previously + * returned by up_addrenv_create. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_destroy(task_addrenv_t addrenv); +#endif + +/**************************************************************************** + * Name: up_addrenv_assign + * + * Description: + * Assign an address environment to a TCB. + * + * Input Parameters: + * addrenv - The representation of the task address environment previously + * returned by up_addrenv_create. + * tcb - The TCB of the task to receive the address environment. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_assign(task_addrenv_t addrenv, FAR _TCB *tcb); +#endif + +/**************************************************************************** + * Name: up_addrenv_share + * + * Description: + * This function is called from the core scheduler logic when a thread + * is created that needs to share the address ennvironment of its parent + * task. In this case, the parent's address environment needs to be + * "cloned" for the child. + * + * Input Parameters: + * ptcb - The TCB of the parent task that has the address environment. + * ctcb - The TCB of the child thread needing the address environment. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_share(FAR const _TCB *ptcb, FAR _TCB *ctcb); +#endif + +/**************************************************************************** + * Name: up_addrenv_release + * + * Description: + * This function is called when a task or thread exits in order to release + * its reference to an address environment. When there are no further + * references to an address environment, that address environment should + * be destroyed. + * + * Input Parameters: + * tcb - The TCB of the task or thread whose the address environment will + * be released. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_ADDRENV +int up_addrenv_release(FAR _TCB *tcb); +#endif + +/**************************************************************************** * Name: up_interrupt_context * * Description: @@ -391,7 +598,7 @@ EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size); * ****************************************************************************/ -EXTERN bool up_interrupt_context(void); +bool up_interrupt_context(void); /**************************************************************************** * Name: up_enable_irq @@ -413,7 +620,7 @@ EXTERN bool up_interrupt_context(void); ****************************************************************************/ #ifndef CONFIG_ARCH_NOINTC -EXTERN void up_enable_irq(int irq); +void up_enable_irq(int irq); #endif /**************************************************************************** @@ -431,7 +638,7 @@ EXTERN void up_enable_irq(int irq); ****************************************************************************/ #ifndef CONFIG_ARCH_NOINTC -EXTERN void up_disable_irq(int irq); +void up_disable_irq(int irq); #endif /**************************************************************************** @@ -446,7 +653,7 @@ EXTERN void up_disable_irq(int irq); ****************************************************************************/ #ifdef CONFIG_ARCH_IRQPRIO -EXTERN int up_prioritize_irq(int irq, int priority); +int up_prioritize_irq(int irq, int priority); #endif /**************************************************************************** @@ -483,7 +690,7 @@ EXTERN int up_prioritize_irq(int irq, int priority); ****************************************************************************/ #ifdef CONFIG_ARCH_ROMGETC -EXTERN char up_romgetc(FAR const char *ptr); +char up_romgetc(FAR const char *ptr); #else # define up_romgetc(ptr) (*ptr) #endif @@ -497,8 +704,8 @@ EXTERN char up_romgetc(FAR const char *ptr); * ***************************************************************************/ -EXTERN void up_mdelay(unsigned int milliseconds); -EXTERN void up_udelay(useconds_t microseconds); +void up_mdelay(unsigned int milliseconds); +void up_udelay(useconds_t microseconds); /**************************************************************************** * Name: up_cxxinitialize @@ -517,7 +724,7 @@ EXTERN void up_udelay(useconds_t microseconds); ***************************************************************************/ #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) -EXTERN void up_cxxinitialize(void); +void up_cxxinitialize(void); #endif /**************************************************************************** @@ -537,7 +744,7 @@ EXTERN void up_cxxinitialize(void); * ****************************************************************************/ -EXTERN void sched_process_timer(void); +void sched_process_timer(void); /**************************************************************************** * Name: irq_dispatch @@ -549,7 +756,7 @@ EXTERN void sched_process_timer(void); * ***************************************************************************/ -EXTERN void irq_dispatch(int irq, FAR void *context); +void irq_dispatch(int irq, FAR void *context); /**************************************************************************** * Board-specific button interfaces exported by the board-specific logic @@ -571,7 +778,7 @@ EXTERN void irq_dispatch(int irq, FAR void *context); ****************************************************************************/ #ifdef CONFIG_ARCH_BUTTONS -EXTERN void up_buttoninit(void); +void up_buttoninit(void); #endif /**************************************************************************** @@ -592,7 +799,7 @@ EXTERN void up_buttoninit(void); ****************************************************************************/ #ifdef CONFIG_ARCH_BUTTONS -EXTERN uint8_t up_buttons(void); +uint8_t up_buttons(void); #endif /**************************************************************************** @@ -613,7 +820,29 @@ EXTERN uint8_t up_buttons(void); ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler); +xcpt_t up_irqbutton(int id, xcpt_t irqhandler); +#endif + +/************************************************************************************ + * Relay control functions + * + * Description: + * Non-standard functions for relay control. + * + ************************************************************************************/ + +#ifdef CONFIG_ARCH_RELAYS +void up_relaysinit(void); +void relays_setstat(int relays, bool stat); +bool relays_getstat(int relays); +void relays_setstats(uint32_t relays_stat); +uint32_t relays_getstats(void); +void relays_onoff(int relays, uint32_t mdelay); +void relays_onoffs(uint32_t relays_stat, uint32_t mdelay); +void relays_resetmode(int relays); +void relays_powermode(int relays); +void relays_resetmodes(uint32_t relays_stat); +void relays_powermodes(uint32_t relays_stat); #endif /**************************************************************************** @@ -628,9 +857,8 @@ EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler); * ****************************************************************************/ -EXTERN int up_putc(int ch); +int up_putc(int ch); -#undef EXTERN #ifdef __cplusplus } #endif diff --git a/nuttx/include/nuttx/binfmt/binfmt.h b/nuttx/include/nuttx/binfmt/binfmt.h new file mode 100644 index 000000000..6df5190d2 --- /dev/null +++ b/nuttx/include/nuttx/binfmt/binfmt.h @@ -0,0 +1,338 @@ +/**************************************************************************** + * include/nuttx/binfmt/binfmt.h + * + * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_BINFMT_BINFMT_H +#define __INCLUDE_NUTTX_BINFMT_BINFMT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <nxflat.h> + +#include <nuttx/arch.h> +#include <nuttx/sched.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BINFMT_NALLOC 3 + +/**************************************************************************** + * Public Types + ****************************************************************************/ +/* EXEPATH_HANDLE is an opaque handle used to traverse the absolute paths + * assigned to the PATH environment variable. + */ + +#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH) +typedef FAR void *EXEPATH_HANDLE; +#endif + +/* The type of one C++ constructor or destructor */ + +typedef FAR void (*binfmt_ctor_t)(void); +typedef FAR void (*binfmt_dtor_t)(void); + +/* This describes the file to be loaded. + * + * NOTE 1: The 'filename' must be the full, absolute path to the file to be + * executed unless CONFIG_BINFMT_EXEPATH is defined. In that case, + * 'filename' may be a relative path; a set of candidate absolute paths + * will be generated using the PATH environment variable and load_module() + * will attempt to load each file that is found at those absolute paths. + */ + +struct symtab_s; +struct binary_s +{ + /* Information provided to the loader to load and bind a module */ + + FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */ + FAR const char **argv; /* Argument list */ + FAR const struct symtab_s *exports; /* Table of exported symbols */ + int nexports; /* The number of symbols in exports[] */ + + /* Information provided from the loader (if successful) describing the + * resources used by the loaded module. + */ + + main_t entrypt; /* Entry point into a program module */ + FAR void *mapped; /* Memory-mapped, address space */ + FAR void *alloc[BINFMT_NALLOC]; /* Allocated address spaces */ + + /* Constructors/destructors */ + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */ + FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */ + uint16_t nctors; /* Number of constructors in the list */ + uint16_t ndtors; /* Number of destructors in the list */ +#endif + + /* Address environment. + * + * addrenv - This is the handle created by up_addrenv_create() that can be + * used to manage the tasks address space. + */ + +#ifdef CONFIG_ADDRENV + task_addrenv_t addrenv; /* Task address environment */ +#endif + + size_t mapsize; /* Size of the mapped address region (needed for munmap) */ + size_t stacksize; /* Size of the stack in bytes (unallocated) */ +}; + +/* This describes one binary format handler */ + +struct binfmt_s +{ + FAR struct binfmt_s *next; /* Supports a singly-linked list */ + int (*load)(FAR struct binary_s *bin); /* Verify and load binary into memory */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: register_binfmt + * + * Description: + * Register a loader for a binary format + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int register_binfmt(FAR struct binfmt_s *binfmt); + +/**************************************************************************** + * Name: unregister_binfmt + * + * Description: + * Register a loader for a binary format + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int unregister_binfmt(FAR struct binfmt_s *binfmt); + +/**************************************************************************** + * Name: load_module + * + * Description: + * Load a module into memory, bind it to an exported symbol take, and + * prep the module for execution. + * + * Returned Value: + * This is an end-user function, so it follows the normal convention: + * Returns 0 (OK) on success. On failure, it returns -1 (ERROR) with + * errno set appropriately. + * + ****************************************************************************/ + +int load_module(FAR struct binary_s *bin); + +/**************************************************************************** + * Name: unload_module + * + * Description: + * Unload a (non-executing) module from memory. If the module has + * been started (via exec_module) and has not exited, calling this will + * be fatal. + * + * However, this function must be called after the module exist. How + * this is done is up to your logic. Perhaps you register it to be + * called by on_exit()? + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int unload_module(FAR const struct binary_s *bin); + +/**************************************************************************** + * Name: exec_module + * + * Description: + * Execute a module that has been loaded into memory by load_module(). + * + * Returned Value: + * This is an end-user function, so it follows the normal convention: + * Returns the PID of the exec'ed module. On failure, it.returns + * -1 (ERROR) and sets errno appropriately. + * + ****************************************************************************/ + +int exec_module(FAR const struct binary_s *bin, int priority); + +/**************************************************************************** + * Name: exec + * + * Description: + * This is a convenience function that wraps load_ and exec_module into + * one call. + * + * Input Parameter: + * filename - Fulll path to the binary to be loaded + * argv - Argument list + * exports - Table of exported symbols + * nexports - The number of symbols in exports + * + * Returned Value: + * This is an end-user function, so it follows the normal convention: + * Returns the PID of the exec'ed module. On failure, it.returns + * -1 (ERROR) and sets errno appropriately. + * + ****************************************************************************/ + +int exec(FAR const char *filename, FAR const char **argv, + FAR const struct symtab_s *exports, int nexports); + +/**************************************************************************** + * Name: exepath_init + * + * Description: + * Initialize for the traversal of each value in the PATH variable. The + * usage is sequence is as follows: + * + * 1) Call exepath_init() to initialize for the traversal. exepath_init() + * will return an opaque handle that can then be provided to + * exepath_next() and exepath_release(). + * 2) Call exepath_next() repeatedly to examine every file that lies + * in the directories of the PATH variable + * 3) Call exepath_release() to free resources set aside by exepath_init(). + * + * Input Parameters: + * None + * + * Returned Value: + * On success, exepath_init() return a non-NULL, opaque handle that may + * subsequently be used in calls to exepath_next() and exepath_release(). + * On error, a NULL handle value will be returned. The most likely cause + * of an error would be that the there is no value associated with the + * PATH variable. + * + ****************************************************************************/ + +#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH) +EXEPATH_HANDLE exepath_init(void); +#endif + +/**************************************************************************** + * Name: exepath_next + * + * Description: + * Traverse all possible values in the PATH variable in attempt to find + * the full path to an executable file when only a relative path is + * provided. + * + * Input Parameters: + * handle - The handle value returned by exepath_init + * relpath - The relative path to the file to be found. + * + * Returned Value: + * On success, a non-NULL pointer to a null-terminated string is provided. + * This is the full path to a file that exists in the file system. This + * function will verify that the file exists (but will not verify that it + * is marked executable). + * + * NOTE: The string pointer return in the success case points to allocated + * memory. This memory must be freed by the called by calling kfree(). + * + * NULL is returned if no path is found to any file with the provided + * 'relpath' from any absolute path in the PATH variable. In this case, + * there is no point in calling exepath_next() further; exepath_release() + * must be called to release resources set aside by expath_init(). + * + ****************************************************************************/ + +#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH) +FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath); +#endif + +/**************************************************************************** + * Name: exepath_release + * + * Description: + * Release all resources set aside by exepath_init() when the handle value + * was created. The handle value is invalid on return from this function. + * Attempts to all exepath_next() or exepath_release() with such a 'stale' + * handle will result in undefined (i.e., not good) behavior. + * + * Input Parameters: + * handle - The handle value returned by exepath_init + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH) +void exepath_release(EXEPATH_HANDLE handle); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_BINFMT_BINFMT_H */ + diff --git a/nuttx/include/nuttx/binfmt/elf.h b/nuttx/include/nuttx/binfmt/elf.h new file mode 100644 index 000000000..6b6851934 --- /dev/null +++ b/nuttx/include/nuttx/binfmt/elf.h @@ -0,0 +1,340 @@ +/**************************************************************************** + * include/nuttx/binfmt/elf.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_BINFMT_ELF_H +#define __INCLUDE_NUTTX_BINFMT_ELF_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> + +#include <stdint.h> +#include <stdbool.h> +#include <elf32.h> + +#include <nuttx/binfmt/binfmt.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifndef CONFIG_ELF_ALIGN_LOG2 +# define CONFIG_ELF_ALIGN_LOG2 2 +#endif + +#ifndef CONFIG_ELF_STACKSIZE +# define CONFIG_ELF_STACKSIZE 2048 +#endif + +#ifndef CONFIG_ELF_BUFFERSIZE +# define CONFIG_ELF_BUFFERSIZE 128 +#endif + +#ifndef CONFIG_ELF_BUFFERINCR +# define CONFIG_ELF_BUFFERINCR 32 +#endif + +/* Allocation array size and indices */ + +#define LIBELF_ELF_ALLOC 0 +#ifdef CONFIG_BINFMT_CONSTRUCTORS +# define LIBELF_CTORS_ALLOC 1 +# define LIBELF_CTPRS_ALLOC 2 +# define LIBELF_NALLOC 3 +#else +# define LIBELF_NALLOC 1 +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This struct provides a desciption of the currently loaded instantiation + * of an ELF binary. + */ + +struct elf_loadinfo_s +{ + /* elfalloc is the base address of the memory that is allocated to hold the + * ELF program image. + * + * If CONFIG_ADDRENV=n, elfalloc will be allocated using kmalloc() (or + * kzalloc()). If CONFIG_ADDRENV-y, then elfalloc will be allocated using + * up_addrenv_create(). In either case, there will be a unique instance + * of elfalloc (and stack) for each instance of a process. + * + * The alloc[] array in struct binary_s will hold memory that persists after + * the ELF module has been loaded. + */ + + uintptr_t elfalloc; /* Memory allocated when ELF file was loaded */ + size_t elfsize; /* Size of the ELF memory allocation */ + off_t filelen; /* Length of the entire ELF file */ + Elf32_Ehdr ehdr; /* Buffered ELF file header */ + FAR Elf32_Shdr *shdr; /* Buffered ELF section headers */ + uint8_t *iobuffer; /* File I/O buffer */ + + /* Constructors and destructors */ + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + FAR void *ctoralloc; /* Memory allocated for ctors */ + FAR void *dtoralloc; /* Memory allocated dtors */ + FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */ + FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */ + uint16_t nctors; /* Number of constructors */ + uint16_t ndtors; /* Number of destructors */ +#endif + + /* Address environment. + * + * addrenv - This is the handle created by up_addrenv_create() that can be + * used to manage the tasks address space. + * oldenv - This is a value returned by up_addrenv_select() that must be + * used to restore the current hardware address environment. + */ + +#ifdef CONFIG_ADDRENV + task_addrenv_t addrenv; /* Task address environment */ + hw_addrenv_t oldenv; /* Saved hardware address environment */ +#endif + + uint16_t symtabidx; /* Symbol table section index */ + uint16_t strtabidx; /* String table section index */ + uint16_t buflen; /* size of iobuffer[] */ + int filfd; /* Descriptor for the file being loaded */ +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * These are APIs exported by libelf (but are used only by the binfmt logic): + ****************************************************************************/ + +/**************************************************************************** + * Name: elf_init + * + * Description: + * This function is called to configure the library to process an ELF + * program binary. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int elf_init(FAR const char *filename, + FAR struct elf_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: elf_uninit + * + * Description: + * Releases any resources committed by elf_init(). This essentially + * undoes the actions of elf_init. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int elf_uninit(FAR struct elf_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: elf_load + * + * Description: + * Loads the binary into memory, allocating memory, performing relocations + * and inializing the data and bss segments. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int elf_load(FAR struct elf_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: elf_bind + * + * Description: + * Bind the imported symbol names in the loaded module described by + * 'loadinfo' using the exported symbol values provided by 'symtab'. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +struct symtab_s; +EXTERN int elf_bind(FAR struct elf_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports); + +/**************************************************************************** + * Name: elf_unload + * + * Description: + * This function unloads the object from memory. This essentially undoes + * the actions of elf_load. It is called only under certain error + * conditions after the the module has been loaded but not yet started. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int elf_unload(struct elf_loadinfo_s *loadinfo); + +/**************************************************************************** + * These are APIs used outside of binfmt by NuttX: + ****************************************************************************/ +/**************************************************************************** + * Name: elf_initialize + * + * Description: + * ELF support is built unconditionally. However, it order to + * use this binary format, this function must be called during system + * format in order to register the ELF binary format. + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int elf_initialize(void); + +/**************************************************************************** + * Name: elf_uninitialize + * + * Description: + * Unregister the ELF binary loader + * + * Returned Value: + * None + * + ****************************************************************************/ + +EXTERN void elf_uninitialize(void); + +/**************************************************************************** + * These are APIs must be provided by architecture-specific logic: + ****************************************************************************/ +/**************************************************************************** + * Name: arch_checkarch + * + * Description: + * Given the ELF header in 'hdr', verify that the ELF file is appropriate + * for the current, configured architecture. Every architecture that uses + * the ELF loader must provide this function. + * + * Input Parameters: + * hdr - The ELF header read from the ELF file. + * + * Returned Value: + * True if the architecture supports this ELF file. + * + ****************************************************************************/ + +EXTERN bool arch_checkarch(FAR const Elf32_Ehdr *hdr); + +/**************************************************************************** + * Name: arch_relocate and arch_relocateadd + * + * Description: + * Perform on architecture-specific ELF relocation. Every architecture + * that uses the ELF loader must provide this function. + * + * Input Parameters: + * rel - The relocation type + * sym - The ELF symbol structure containing the fully resolved value. + * addr - The address that requires the relocation. + * + * Returned Value: + * Zero (OK) if the relocation was successful. Otherwise, a negated errno + * value indicating the cause of the relocation failure. + * + ****************************************************************************/ + +EXTERN int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, + uintptr_t addr); +EXTERN int arch_relocateadd(FAR const Elf32_Rela *rel, + FAR const Elf32_Sym *sym, uintptr_t addr); + +/**************************************************************************** + * Name: arch_flushicache + * + * Description: + * Flush the instruction cache. + * + * Input Parameters: + * addr - Start address to flush + * len - Number of bytes to flush + * + * Returned Value: + * True if the architecture supports this ELF file. + * + ****************************************************************************/ + +#ifdef CONFIG_ELF_ICACHE +EXTERN bool arch_flushicache(FAR void *addr, size_t len); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_BINFMT_ELF_H */ diff --git a/nuttx/include/nuttx/binfmt/nxflat.h b/nuttx/include/nuttx/binfmt/nxflat.h new file mode 100644 index 000000000..db396771b --- /dev/null +++ b/nuttx/include/nuttx/binfmt/nxflat.h @@ -0,0 +1,287 @@ +/**************************************************************************** + * include/nuttx/binfmt/nxflat.h + * + * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_BINFMT_NXFLAT_H +#define __INCLUDE_NUTTX_BINFMT_NXFLAT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <nxflat.h> + +#include <nuttx/sched.h> +#include <nuttx/arch.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This struct provides a desciption of the currently loaded instantiation + * of an nxflat binary. + */ + +struct nxflat_loadinfo_s +{ + /* Instruction Space (ISpace): This region contains the nxflat file header + * plus everything from the text section. + * + * The ISpace region is allocated using mmap() and, thus, can be shared by + * multiple tasks. Ideally, will have only one mmap'ed text section + * instance in the system for each module. + */ + + uintptr_t ispace; /* Address where hdr/text is loaded */ + uint32_t entryoffs; /* Offset from ispace to entry point */ + uint32_t isize; /* Size of ispace. */ + + /* Data Space (DSpace): This region contains all information that is + * referenced as data (other than the stack which is separately allocated). + * + * If CONFIG_ADDRENV=n, DSpace will be allocated using kmalloc() (or + * kzalloc()). If CONFIG_ADDRENV-y, then DSpace will be allocated using + * up_addrenv_create(). In either case, there will be a unique instance + * of DSpace (and stack) for each instance of a process. + */ + + struct dspace_s *dspace; /* Allocated D-Space (data/bss/etc) */ + uint32_t datasize; /* Size of data segment in dspace */ + uint32_t bsssize; /* Size of bss segment in dspace */ + uint32_t stacksize; /* Size of stack (not allocated) */ + uint32_t dsize; /* Size of dspace (may be large than parts) */ + + /* This is temporary memory where relocation records will be loaded. */ + + uint32_t relocstart; /* Start of array of struct flat_reloc */ + uint16_t reloccount; /* Number of elements in reloc array */ + + /* Address environment. + * + * addrenv - This is the handle created by up_addrenv_create() that can be + * used to manage the tasks address space. + * oldenv - This is a value returned by up_addrenv_select() that must be + * used to restore the current hardware address environment. + */ + +#ifdef CONFIG_ADDRENV + task_addrenv_t addrenv; /* Task address environment */ + hw_addrenv_t oldenv; /* Saved hardware address environment */ +#endif + + /* File descriptors */ + + int filfd; /* Descriptor for the file being loaded */ + + /* This is a copy of the NXFLAT header (still in network order) */ + + struct nxflat_hdr_s header; +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * These are APIs exported by libnxflat (and may be used outside of NuttX): + ****************************************************************************/ + +/**************************************************************************** + * Name: nxflat_verifyheader + * + * Description: + * Given the header from a possible NXFLAT executable, verify that it is + * an NXFLAT executable. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int nxflat_verifyheader(const struct nxflat_hdr_s *header); + +/**************************************************************************** + * Name: nxflat_init + * + * Description: + * This function is called to configure the library to process an NXFLAT + * program binary. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int nxflat_init(const char *filename, + struct nxflat_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: nxflat_uninit + * + * Description: + * Releases any resources committed by nxflat_init(). This essentially + * undoes the actions of nxflat_init. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: nxflat_load + * + * Description: + * Loads the binary specified by nxflat_init into memory, mapping + * the I-space executable regions, allocating the D-Space region, + * and inializing the data segment (relocation information is + * temporarily loaded into the BSS region. BSS will be cleared + * by nxflat_bind() after the relocation data has been processed). + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int nxflat_load(struct nxflat_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: nxflat_read + * + * Description: + * Read 'readsize' bytes from the object file at 'offset' + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, + int readsize, int offset); + +/**************************************************************************** + * Name: nxflat_bind + * + * Description: + * Bind the imported symbol names in the loaded module described by + * 'loadinfo' using the exported symbol values provided by 'symtab' + * After binding the module, clear the BSS region (which held the relocation + * data) in preparation for execution. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +struct symtab_s; +EXTERN int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports); + +/**************************************************************************** + * Name: nxflat_unload + * + * Description: + * This function unloads the object from memory. This essentially undoes + * the actions of nxflat_load. It is called only under certain error + * conditions after the the module has been loaded but not yet started. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int nxflat_unload(struct nxflat_loadinfo_s *loadinfo); + +/**************************************************************************** + * These are APIs used internally only by NuttX: + ****************************************************************************/ +/**************************************************************************** + * Name: nxflat_initialize + * + * Description: + * NXFLAT support is built unconditionally. However, it order to + * use this binary format, this function must be called during system + * format in order to register the NXFLAT binary format. + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +EXTERN int nxflat_initialize(void); + +/**************************************************************************** + * Name: nxflat_uninitialize + * + * Description: + * Unregister the NXFLAT binary loader + * + * Returned Value: + * None + * + ****************************************************************************/ + +EXTERN void nxflat_uninitialize(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_BINFMT_NXFLAT_H */ diff --git a/nuttx/include/nuttx/compiler.h b/nuttx/include/nuttx/compiler.h index d74fcbea0..d8f79fe9e 100644 --- a/nuttx/include/nuttx/compiler.h +++ b/nuttx/include/nuttx/compiler.h @@ -255,7 +255,7 @@ * external RAM. */ -#if defined(__z80) || defined(__gbz80) +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_gbz80) # define FAR # define NEAR # define CODE diff --git a/nuttx/include/nuttx/fs/fs.h b/nuttx/include/nuttx/fs/fs.h index 81f81622f..79090a8da 100644 --- a/nuttx/include/nuttx/fs/fs.h +++ b/nuttx/include/nuttx/fs/fs.h @@ -172,7 +172,7 @@ struct mountpt_operations int (*statfs)(FAR struct inode *mountpt, FAR struct statfs *buf); - /* Operations on pathes */ + /* Operations on paths */ int (*unlink)(FAR struct inode *mountpt, FAR const char *relpath); int (*mkdir)(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode); diff --git a/nuttx/include/nuttx/input/keypad.h b/nuttx/include/nuttx/input/keypad.h new file mode 100644 index 000000000..574b421c1 --- /dev/null +++ b/nuttx/include/nuttx/input/keypad.h @@ -0,0 +1,54 @@ +/************************************************************************************ + * include/nuttx/input/keypad.h + * + * Copyright (C) 2012 Denis Carikli. + * Author: Denis Carikli <GNUtoo@no-log.org> + * + * 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. + * + ************************************************************************************/ + +#ifndef __INCLUDE_NUTTX_INPUT_KEYPAD_H +#define __INCLUDE_NUTTX_INPUT_KEYPAD_H + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +int keypad_kbdinit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_INPUT_KEYPAD_H */ + diff --git a/nuttx/include/nuttx/math.h b/nuttx/include/nuttx/math.h index 84dbea6e0..aaadb9c91 100644 --- a/nuttx/include/nuttx/math.h +++ b/nuttx/include/nuttx/math.h @@ -50,14 +50,280 @@ #ifdef CONFIG_ARCH_MATH_H # include <arch/math.h> -#endif + +/* If CONFIG_LIB is enabled, then the math library at lib/math will be + * built. This library was taken from the math library developed for the + * Rhombus OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus). + * The port or the Rhombus math library was contributed by Darcy Gong. + */ + +#else if defined CONFIG_LIBM /**************************************************************************** - * Type Definitions + * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * ****************************************************************************/ /**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/compiler.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* General Constants ********************************************************/ + +#define INFINITY (1.0/0.0) +#define NAN (0.0/0.0) +#define HUGE_VAL INFINITY + +#define isnan(x) ((x) != (x)) +#define isinf(x) (((x) == INFINITY) || ((x) == -INFINITY)) + +/* Exponential and Logarithmic constants ************************************/ + +#define M_E 2.7182818284590452353602874713526625 +#define M_SQRT2 1.4142135623730950488016887242096981 +#define M_SQRT1_2 0.7071067811865475244008443621048490 +#define M_LOG2E 1.4426950408889634073599246810018921 +#define M_LOG10E 0.4342944819032518276511289189166051 +#define M_LN2 0.6931471805599453094172321214581765 +#define M_LN10 2.3025850929940456840179914546843642 + +/* Trigonometric Constants **************************************************/ + +#define M_PI 3.1415926535897932384626433832795029 +#define M_PI_2 1.5707963267948966192313216916397514 +#define M_PI_4 0.7853981633974483096156608458198757 +#define M_1_PI 0.3183098861837906715377675267450287 +#define M_2_PI 0.6366197723675813430755350534900574 +#define M_2_SQRTPI 1.1283791670955125738961589031215452 + +/**************************************************************************** * Public Function Prototypes ****************************************************************************/ +#if defined(__cplusplus) +extern "C" { +#endif + +/* General Functions ********************************************************/ + +float ceilf (float x); +#if CONFIG_HAVE_DOUBLE +double ceil (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double ceill (long double x); +#endif + +float floorf(float x); +#if CONFIG_HAVE_DOUBLE +double floor (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double floorl(long double x); +#endif + +float roundf(float x); +#if CONFIG_HAVE_DOUBLE +double round (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double roundl(long double x); +#endif + +float fabsf (float x); +#if CONFIG_HAVE_DOUBLE +double fabs (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double fabsl (long double x); +#endif + +float modff (float x, float *iptr); +#if CONFIG_HAVE_DOUBLE +double modf (double x, double *iptr); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double modfl (long double x, long double *iptr); +#endif + +float fmodf (float x, float div); +#if CONFIG_HAVE_DOUBLE +double fmod (double x, double div); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double fmodl (long double x, long double div); +#endif + +/* Exponential and Logarithmic Functions ************************************/ + +float powf (float b, float e); +#if CONFIG_HAVE_DOUBLE +double pow (double b, double e); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double powl (long double b, long double e); +#endif + +float expf (float x); +#if CONFIG_HAVE_DOUBLE +double exp (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double expl (long double x); +#endif + +float logf (float x); +#if CONFIG_HAVE_DOUBLE +double log (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double logl (long double x); +#endif + +float log10f(float x); +#if CONFIG_HAVE_DOUBLE +double log10 (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double log10l(long double x); +#endif + +float log2f (float x); +#if CONFIG_HAVE_DOUBLE +double log2 (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double log2l (long double x); +#endif + +float sqrtf (float x); +#if CONFIG_HAVE_DOUBLE +double sqrt (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double sqrtl (long double x); +#endif + +float ldexpf(float x, int n); +#if CONFIG_HAVE_DOUBLE +double ldexp (double x, int n); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double ldexpl(long double x, int n); +#endif + +float frexpf(float x, int *exp); +#if CONFIG_HAVE_DOUBLE +double frexp (double x, int *exp); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double frexpl(long double x, int *exp); +#endif + +/* Trigonometric Functions **************************************************/ + +float sinf (float x); +#if CONFIG_HAVE_DOUBLE +double sin (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double sinl (long double x); +#endif + +float cosf (float x); +#if CONFIG_HAVE_DOUBLE +double cos (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double cosl (long double x); +#endif + +float tanf (float x); +#if CONFIG_HAVE_DOUBLE +double tan (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double tanl (long double x); +#endif + +float asinf (float x); +#if CONFIG_HAVE_DOUBLE +double asin (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double asinl (long double x); +#endif + +float acosf (float x); +#if CONFIG_HAVE_DOUBLE +double acos (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double acosl (long double x); +#endif + +float atanf (float x); +#if CONFIG_HAVE_DOUBLE +double atan (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double atanl (long double x); +#endif + +float atan2f(float y, float x); +#if CONFIG_HAVE_DOUBLE +double atan2 (double y, double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double atan2l(long double y, long double x); +#endif + +float sinhf (float x); +#if CONFIG_HAVE_DOUBLE +double sinh (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double sinhl (long double x); +#endif + +float coshf (float x); +#if CONFIG_HAVE_DOUBLE +double cosh (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double coshl (long double x); +#endif + +float tanhf (float x); +#if CONFIG_HAVE_DOUBLE +double tanh (double x); +#endif +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double tanhl (long double x); +#endif + +#if defined(__cplusplus) +} +#endif + +#endif /* CONFIG_LIBM */ #endif /* __INCLUDE_NUTTX_MATH_H */ diff --git a/nuttx/include/nuttx/mtd.h b/nuttx/include/nuttx/mtd.h index 44582c412..ff48d313f 100644 --- a/nuttx/include/nuttx/mtd.h +++ b/nuttx/include/nuttx/mtd.h @@ -220,7 +220,6 @@ EXTERN FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev); EXTERN FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev); - /**************************************************************************** * Name: w25_initialize * @@ -233,6 +232,8 @@ EXTERN FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev); EXTERN FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev); +EXTERN FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev); + #undef EXTERN #ifdef __cplusplus } diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 241af6210..54094c8f1 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -163,24 +163,40 @@ typedef struct environ_s environ_t; # define SIZEOF_ENVIRON_T(alloc) (sizeof(environ_t) + alloc - 1) #endif -/* This structure describes a reference counted D-Space region */ +/* This structure describes a reference counted D-Space region. This must be a + * separately allocated "break-away" structure that can be owned by a task and + * any pthreads created by the task. + */ +#ifdef CONFIG_PIC struct dspace_s { - uint32_t crefs; /* This is the number of pthreads that shared the - * the same D-Space */ - uint8_t region[1]; /* Beginning of the allocated region */ -}; + /* The life of the structure allocation is determined by this reference + * count. This count is number of threads that shared the the same D-Space. + * This includes the parent task as well as any pthreads created by the + * parent task or any of its child threads. + */ + + uint16_t crefs; -#define SIZEOF_DSPACE_S(n) (sizeof(struct dspace_s) - 1 + (n)) + /* This is the allocated D-Space memory region. This may be a physical + * address allocated with kmalloc(), or it may be virtual address associated + * with an address environment (if CONFIG_ADDRENV=y). + */ -/* This is the task control block (TCB) */ + FAR uint8_t *region; +}; +#endif + +/* This is the task control block (TCB). Each task or thread is represented by + * a TCB. The TCB is the heart of the NuttX task-control logic. + */ struct _TCB { /* Fields used to support list management *************************************/ - FAR struct _TCB *flink; /* link in DQ of TCBs */ + FAR struct _TCB *flink; /* Doubly linked list */ FAR struct _TCB *blink; /* Task Management Fields *****************************************************/ diff --git a/nuttx/include/nuttx/vt100.h b/nuttx/include/nuttx/vt100.h index d834f48f0..32344a1de 100644 --- a/nuttx/include/nuttx/vt100.h +++ b/nuttx/include/nuttx/vt100.h @@ -179,8 +179,8 @@ #define VT52_CLEAREOL {ASCII_ESC, 'K'} /* Erase to end of current line */ #define VT52_CLEAREOS {ASCII_ESC, 'J'} /* Erase to end of screen */ -#define VT52_IDENT {ASCII_ESC, 'Z'} /* dentify what the terminal is */ -#define VT52_IDENTRESP {ASCII_ESC, '/', 'Z'} /* Correct response to ident */ +#define VT52_IDENT {ASCII_ESC, 'Z'} /* Identify what the terminal is */ +#define VT52_IDENTRESP {ASCII_ESC, '/', 'Z'} /* Correct response to ident */ /* VT100 Special Key Codes * diff --git a/nuttx/include/stdbool.h b/nuttx/include/stdbool.h index f11219912..9c16aee29 100644 --- a/nuttx/include/stdbool.h +++ b/nuttx/include/stdbool.h @@ -42,10 +42,33 @@ #include <nuttx/config.h> +/* If CONFIG_ARCH_STDBOOL_H is set, then the archecture will provide its own + * stdbool.h file. In this case, this header file will simply re-direct to + * the architecture-specfiic stdbool.h header file. + */ + #ifdef CONFIG_ARCH_STDBOOL_H # include <arch/stdbool.h> + +/* NuttX will insist that the sizeof(bool) is 8-bits. The sizeof of _Bool + * used by any specific compiler is implementation specific: It can vary from + * compiler-to-compiler and even vary between different versions of the same + * compiler. Compilers seems to be converging to sizeof(_Bool) == 1. If that + * is true for your compiler, you should define CONFIG_C99_BOOL8 in your NuttX + * configuration for better standards compatibility. + * + * CONFIG_C99_BOOL8 - Means (1) your C++ compiler has sizeof(_Bool) == 8, + * (2) your C compiler supports the C99 _Bool intrinsic type, and (2) that + * the C99 _Bool type also has size 1. + */ + #else + + /* nuttx/compiler.h may also define or undefine CONFIG_C99_BOOL8 */ + # include <nuttx/compiler.h> + +#if !defined(__cplusplus) || !defined(CONFIG_C99_BOOL8) # include <stdint.h> /**************************************************************************** @@ -58,10 +81,15 @@ * NOTE: Under C99 'bool' is required to be defined to be the intrinsic type * _Bool. However, in this NuttX context, we need backward compatibility * to pre-C99 standards where _Bool is not an intrinsic type. Hence, we - * use _Bool8 as the underlying type. + * use _Bool8 as the underlying type (unless CONFIG_C99_BOOL8 is defined) */ -#define bool _Bool8 +#ifdef CONFIG_C99_BOOL8 +# define bool _Bool +#else +# define bool _Bool8 +#endif + #define true 1 #define false 0 @@ -83,7 +111,10 @@ * as the underlying type. */ +#ifndef CONFIG_C99_BOOL8 typedef uint8_t _Bool8; +#endif +#endif /* __cplusplus && CONFIG_C99_BOOL8 */ #endif /* CONFIG_ARCH_STDBOOL_H */ #endif /* __INCLUDE_STDBOOL_H */ |