commit b08a86171f237f948fad94fa4906374ad3f413bc
Author: patacongo
Date: Sat Feb 17 23:21:28 2007 +0000
NuttX RTOS
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3 42af7a65-404d-4744-a932-0658087f49c3
diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html
new file mode 100644
index 0000000000..576e2c86d7
--- /dev/null
+++ b/Documentation/NuttxPortingGuide.html
@@ -0,0 +1,121 @@
+
+
+
+Nuttx Porting Manual
+
+
+
+
+
+
+ Nuttx Operating System
+ Porting Guide
+
+ by
+ Gregory Nutt
+ Last Update: February 8, 2007
+
+
+Table of Contents
+1.0 1.0 Introduction
+2.0 Directory Structure
+
+3.0 Configuring and Building
+
+
+
+
+Overview
+ This document provides and overview of the Nuttx build and configuration
+ logic and provides hints for the incorporation of new processor/board archectures
+ into the build.
+
+
+ See also arch/README.txt.
+
+
+General Philosophy.
+
+
+
+
+The general directly layout for Nuttx is very similar to the directory structure
+of the Linux kernel -- at least at the most superficial layers.
+At the top level is the main makefile and a series of sub-directories identified
+below and discussed in the following paragraphs:
+
+
+.
+|-- Makefile
+|-- Documentation
+| `-- (documentation files)
+|-- arch
+| |-- (architecture)
+| | |-- Make.defs
+| | |-- defconfig
+| | |-- include
+| | |-- setenv.sh
+| | `-- src
+| `-- (other architectures)
+|-- drivers
+| |-- Makefile
+| `-- (driver source files)
+|-- examples
+| `-- (example)
+| |-- Makefile
+| `-- (example source files)
+|-- fs
+| |-- Makefile
+| `-- (fs source files)
+|-- include
+| |-- (standard header files)
+| |-- nuttx
+| | `-- (nuttx specific header files)
+| `- sys
+| | `-- (more standard header files)
+|-- lib
+| |-- Makefile
+| `-- (lib source files)
+|-- mm
+| |-- Makefile
+| `-- (mm source files)
+|-- sched
+| |-- Makefile
+| `-- (sched source files)
+`-- tools
+ |-- Makefile.mkconfig
+ |-- configure.sh
+ |-- mkconfig.c
+ |-- mkdeps.sh
+ `-- zipme
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html
new file mode 100644
index 0000000000..c8e26278d3
--- /dev/null
+++ b/Documentation/NuttxUserGuide.html
@@ -0,0 +1,4105 @@
+
+
+
+Nuttx Users Manual
+
+
+
+
+
+Nuttx Operating System
+
+User's Manual
+
+
+by
+
+Gregory Nutt
+
+Last Update: January 28, 2007
+
+
+
+
+
+This user's manual is divided into five sections:
+
+- Section 1.0, Introduction:
+This section provides an overview of the Nuttx user's manual.
+
- Section 2.0, OS Interfaces:
+This section details the interfaces provided by Nuttx from the
+perspective of the firmware developer. This section is divided
+into several paragraphs that describe different groups of OS interfaces:
+
+
- Section 3.0, OS Data Structures:
+This section documents the data structures that are used at the Nuttx
+interface.
+
- Section 4.0, Known Problems. This section
+lists known problems in the latest release of Nuttx.
+
+
+
+
+
+
+This section describes each C-callable interface to the Nuttx
+Operating System. The description of each interface is presented
+in the following format:
+
+Function Prototype: The C prototype of the interface function
+is provided.
+
+Description: The operation performed by the interface function
+is discussed.
+
+Input Parameters: All input parameters are listed along
+with brief descriptions of each input parameter.
+
+Returned Values: All possible values returned by the interface
+function are listed. Values returned as side-effects (through
+pointer input parameters or through global variables) will be
+addressed in the description of the interface function.
+
+Assumptions/Limitations: Any unusual assumptions made by
+the interface function or any non-obvious limitations to the use
+of the interface function will be indicated here.
+
+POSIX Compatibility: Any significant differences between the
+Nuttx interface and its corresponding POSIX interface will be noted
+here.
+
+NOTE: In order to achieve an independent name space for the Nuttx
+interface functions, differences in function names and types are
+to be expected and will not be identified as differences in these
+paragraphs.
+
+
+
+
+
+Tasks.
+Nuttx is a flat address OS. As such it does not support "processes"
+in the way that, say, Linux does.
+Nuttx only supports simple threads running within the same address space.
+However, the programming model makes a distinction between "tasks"
+and pthreads:
+
+- tasks are threads which have a degree of independence
+
- pthreads share some resources.
+
+
+File Descriptors and Streams.
+This applies, in particular, in the area of opened file descriptors and streams.
+When a task is started using the interfaces in this section, it will be created
+with at most three open files.
+
+If CONFIG_DEV_CONSOLE is defined, the first three file descriptors (corresponding
+to stdin, stdout, stderr) will be duplicated for the the new task.
+Since these file descriptors are duplicated, the child task can free close
+them or manipulate them in any way without effecting the parent task.
+File-related operations (open, close, etc.) within a task will have no effect
+on other tasks.
+Since the three file descriptors are duplicated, it is also possible to perform
+some level of redirection.
+
+pthreads, on the other hand, will always share file descriptors with the parent
+thread. In this case, file operations will have effect only all pthreads the
+were started from the same parent thread.
+
+
2.1.1 task_create
+
+
+Function Prototype:
+
+ #include <sched.h>
+ int task_create(
+ char *name,
+ int priority,
+ int stack_size,
+ main_t entry,
+ char *arg1, char *arg2, char *arg3, char *arg4);
+
+
+
+Description:
+ This function creates and activates a new task with a
+ specified priority and returns its system-assigned ID.
+
+
+The entry address entry is the address of the "main"
+ function of the task.
+ This function will be called once the C environment has been set up.
+ The specified function will be called with four arguments.
+ Should the specified routine return, a call to exit() will automatically be made.
+
+
+ Note that four (and only four) arguments must be passed for the
+ spawned functions.
+
+
+ The newly created task does not inherity characteristics
+ from the parent task: The new task is started at the
+ default system priority and with the SCHED_FIFO scheduling
+ policy. These characteristcs may be modified after the new
+ task has been started.
+
+
+Input Parameters:
+
+ - name. Name of the new task
+ - priority. Priority of the new task
+ - stack_size. size (in bytes) of the stack needed
+ - entry. Entry point of a new task
+ - arg1, arg2, arg3, and arg4. Four required task arguments to pass to the task
+
+
+ Returned Values:
+
+
+-
+ Returns the non-zero task ID of the new task or
+ ERROR if memory is insufficient or the task cannot be
+ created (errno is not set).
+
+
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following similar interface:
+
+ int taskSpawn(
+ char *name,
+ int priority,
+ int options,
+ int stackSize,
+ FUNCPTR entryPt,
+ int arg1, int arg2, int arg3, int arg4, int arg5,
+ int arg6, int arg7, int arg8, int arg9, int arg10);
+
+
+
+The Nuttx task_create() differs from VxWorks' taskSpawn() in the
+following ways:
+
+- Function name
+
- Various differences in types or arguments
+
- There is no options arguement.
+
- One four parameters can be passed to a task (VxWorks allows
+ten).
+
+
+2.1.2 task_init
+
+
+Function Prototype:
+
+ #include <sched.h>
+ STATUS task_init(
+ _TCB *tcb,
+ char *name,
+ int priority,
+ uint32 *stack,
+ uint32 stack_size,
+ maint_t entry,
+ int arg1, int arg2, int arg3, int arg4);
+
+
+
+Description:
+
+ This function initializes a Task Control Block (TCB)
+ in preparation for starting a new thread.
+
+
+ Unlike task_create(), task_init() does not activate the task.
+ This must be done by calling task_activate().
+
+
+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 pre-allocated stack
+
- entry. Entry point of a new task
+
- arg1, arg2, arg3, and arg4. Four required task arguments to pass to the task
+
+
+
+Returned Values:
+
+
+ OK, or ERROR if the task cannot be initialized.
+ This function can only failure is it is unable to assign
+ a new, unique task ID to the TCB (errno is not set).
+
+
+Assumptions/Limitations:
+
+- task_init() is provided to support internal OS functionality. It is
+not recommended for normal usage. task_create() is the preferred
+mechanism to initialize and start a new task.
+
+
+POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following similar interface:
+
+ STATUS taskInit(
+ WIND_TCB *pTcb,
+ char *name,
+ int priority,
+ int options,
+ uint32 *pStackBase,
+ int stackSize,
+ FUNCPTR entryPt,
+ int arg1, int arg2, int arg3, int arg4, int arg5,
+ int arg6, int arg7, int arg8, int arg9, int arg10);
+
+
+
+The Nuttx task_init() differs from VxWorks' taskInit() in the
+following ways:
+
+- Function name
+
- Various differences in types or arguments
+
- There is no options argument.
+
- One four parameters can be passed to a task (VxWorks allows ten).
+
+
+2.1.3 task_activate
+
+
+Function Prototype:
+
+ #include <sched.h>
+ STATUS task_activate( _TCB *tcb );
+
+
+
+Description: This function activates tasks created by task_init().
+Without activation, a task is ineligible for execution by the
+scheduler.
+
+Input Parameters:
+
+- tcb. The TCB for the task for the task (same as the
+task_init argument).
+
+
+
+Returned Values:
+
+- OK, or ERROR if the task cannot be activated (errno is not set).
+
+
+
+Assumptions/Limitations:
+
+- task_activate() is provided to support internal OS functionality. It is
+not recommended for normal usage. task_create() is the preferred
+mechanism to initialize and start a new task.
+
+
+POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following similar interface:
+
+ STATUS taskActivate( int tid );
+
+
+
+The Nuttx task_activate() differs from VxWorks' taskActivate() in the
+following ways:
+
+- Function name
+
- With VxWork's taskActivate, the pid argument is supposed to be
+the pointer to the WIND_TCB cast to an integer.
+
+
+2.1.4 task_delete
+
+
+Function Prototype:
+
+ #include <sched.h>
+ STATUS task_delete( pid_t pid );
+
+
+
+Description: This function causes a specified task to cease
+to exist -- its stack and TCB will be deallocated. This function
+is the companion to task_create().
+
+Input Parameters:
+
+- pid. The task ID of the task to delete. An ID of
+zero signifies the calling task.
+
+
+
+Returned Values:
+
+- OK, or ERROR if the task cannot be deleted.
+This function can fail if the provided pid does not correspond to a task (errno is not set)
+
+
+
+Assumptions/Limitations:
+
+task_delete() must be used with caution: If the task holds resources
+(for example, allocated memory or semaphores needed by other tasks), then
+task_delete() can strand those resources.
+
+POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following similar interface:
+
+ STATUS taskDelete( int tid );
+
+
+
+The Nuttx task_delete() differs from VxWorks' taskDelete() in
+the following ways:
+
+- No support is provided for calling the tasks deletion routines
+(because taskDeleteHookAdd() is not supported).
+
- Deletion of self is not supported. Use _exit();
+
+
+2.1.5 exit
+
+
+Function Prototype:
+
+ #include <sched.h>
+ void exit( int code );
+
+ #include <nuttx/unistd.h>
+ void _exit( int code );
+
+
+
+Description: This function causes the calling task to cease
+to exist -- its stack and TCB will be deallocated. exit differs from
+_exit in that it flushs streams, closes file descriptors and will
+execute any function registered with atexit().
+
+Input Parameters:
+
+
+
+Returned Values: None.
+
+
+Assumptions/Limitations:
+
+
+POSIX Compatibility: This is equivalent to the ANSI interface:
+
+ void exit( int code );
+
+And the unix interface:
+
+ void _exit( int code );
+
+
+
+The Nuttx exit() differs from ANSI exit() in
+the following ways:
+
+- The code parameter is ignored.
+
+
+2.1.6 task_restart
+
+
+Function Prototype:
+
+ #include <sched.h>
+ STATUS task_restart( pid_t pid );
+
+
+
+Description: This function "restarts" a task.
+The task is first terminated and then reinitialized with same
+ID, priority, original entry point, stack size, and parameters
+it had when it was first started.
+
+Input Parameters:
+
+- pid. The task ID of the task to delete. An ID of
+zero signifies the calling task.
+
+
+
+Returned Values:
+
+-
+ OK, or ERROR if the task ID is invalid or the task could
+ not be restarted.
+ This function can fail if:
+ (1) A pid of zero or the pid of the calling task is provided (functionality not implemented)
+ (2) The pid is not associated with any task known to the system.
+
+
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following similar interface:
+
+ STATUS taskRestart (int tid);
+
+
+
+The Nuttx task_restart() differs from VxWorks' taskRestart() in
+the following ways:
+
+- Restart of the currently running task is not supported.
+
- The VxWorks description says that the ID, priority, etc. take
+the value that they had when the task was terminated.
+
+
+2.1.7 getpid
+
+
+Function Prototype:
+
+ #include <unistd.h>
+ pid_t getpid( void );
+
+
+
+Description: This function returns the task ID of the
+calling task. The task ID will be invalid if called at the interrupt
+level.
+
+Input Parameters: None.
+
+Returned Values:
+
+- The task ID of the calling task.
+
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility:
+Compatible with the POSIX interface of the same name.
+
+
+
+
+Nuttx performs strict priority scheduling: Tasks of higher
+priority have exclusive access to the CPU until they become blocked.
+At that time, the CPU is available to tasks of lower priority.
+Tasks of equal priority are scheduled FIFO.
+
+The OS interfaces described in the following paragraphs provide
+a POSIX- compliant interface to the Nuttx scheduler. However, these
+POSIX interfaces assume a greater range of scheduling options
+than those provided by the Nuttx scheduler. As a result, many of
+these POSIX interfaces are little more than stubs.
+
+
2.2.1 sched_setparam
+
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_setparam( pid_t pid, const struct sched_param *param );
+
+
+
+Description: This function sets the priority of the task
+specified by pid input parameter.
+
+NOTE: Setting a task's priority to the same value has the similar
+effect to sched_yield() -- The task will be moved to after all
+other tasks with the same priority.
+
+Input Parameters:
+
+- pid. The task ID of the task. If pid is zero, the
+priority of the calling task is set.
+
- param. A structure whose member sched_priority is the
+integer priority. The range of valid priority numbers is from
+SCHED_PRIORITY_MIN through SCHED_PRIORITY_MAX.
+
+
+
+Returned Values:
+
+-
+ 0 (OK) if successful, otherwise -1 (ERROR).
+ This function can fail for the following reasons:
+ (1) parm is NULL or parm->sched_priority is out of range.
+ (2) pid does not correspond to any task.
+
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the full POSIX implementation include:
+
+- The range of priority values for the POSIX call is 0 to 255
+
+
+2.2.2 sched_getparam
+
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_getparam (pid_t pid, struct sched_param *param);
+
+
+
+Description: This function gets the scheduling priority
+of the task specified by pid.
+
+Input Parameters:
+
+- pid. The task ID of the task. If pid is zero, the
+priority of the calling task is returned.
+
- param. A structure whose member sched_priority is the
+integer priority. The task's priority is copied to the sched_priority
+element of this structure.
+
+
+
+Returned Values:
+
+- 0 (OK) if successful, otherwise -1 (ERROR).
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.2.3 sched_setscheduler
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_setscheduler (pid_t pid, int policy, const struct sched_param *param);
+
+
+ Description:
+ sched_setscheduler() sets both the scheduling policy
+ and the priority for the task identified by pid.
+ If pid equals zero, the scheduler of the calling
+ thread will be set.
+ The parameter 'param' holds the priority of the thread under the new policy.
+
+
+Input Parameters:
+
+ - pid. The task ID of the task. If pid is zero, the
+ priority of the calling task is set.
+
- policy. Scheduling policy requested (either SCHED_FIFO
+ or SCHED_RR).
+
- param. A structure whose member sched_priority is the
+ integer priority. The range of valid priority numbers is from
+ SCHED_PRIORITY_MIN through SCHED_PRIORITY_MAX.
+
+
+ Returned Values:
+ On success, sched_setscheduler() returns OK (zero). On
+ error, ERROR (-1) is returned, and errno is set appropriately:
+
+
+ - EINVAL The scheduling policy is not one of the
+ recognized policies.
+ - ESRCH The task whose ID is pid could not be found.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.2.4 sched_getscheduler
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_getscheduler (pid_t pid);
+
+
+ Description:
+ sched_getscheduler() returns the scheduling policy
+ currently applied to the process identified by pid. If
+ pid equals zero, the policy of the calling process will
+ be retrieved.
+ *
+ * Inputs:
+ *
+ * Return Value:
+
+ This function returns the current scheduling
+policy.
+
+Input Parameters:
+
+ - pid.
+ The task ID of the task to query.
+ If pid is zero, the calling task is queried.
+
+
+
+Returned Values:
+
+ -
+ On success, sched_getscheduler() returns the policy for
+ the task (either SCHED_FIFO or SCHED_RR).
+ On error, ERROR (-1) is returned, and errno is set appropriately:
+
+ - ESRCH The task whose ID is pid could not be found.
+
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the full POSIX implementation include:
+
+- Does not report errors via errno.
+
+
+2.2.5 sched_yield
+
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_yield( void );
+
+
+
+Description: This function forces the calling task to give
+up the CPU (only to other tasks at the same priority).
+
+Input Parameters: None.
+
+Returned Values:
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.2.6 sched_get_priority_max
+
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_get_priority_max (int policy)
+
+
+
+Description: This function returns the value of the highest
+possible task priority for a specified scheduling policy.
+
+Input Parameters:
+
+- policy. Scheduling policy requested.
+
+
+
+Returned Values:
+
+- The maximum priority value or -1 (ERROR).
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.2.7 sched_get_priority_min
+
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_get_priority_min (int policy);
+
+
+
+Description: This function returns the value of the lowest
+possible task priority for a specified scheduling policy.
+
+Input Parameters:
+
+- policy. Scheduling policy requested.
+
+
+
+Returned Values:
+
+- The minimum priority value or -1 (ERROR)
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.2.8 sched_get_rr_interval
+
+
+Function Prototype:
+
+ #include <sched.h>
+ int sched_get_rr_interval (pid_t pid, struct timespec *interval);
+
+
+
+ Description:
+ sched_rr_get_interval() writes the timeslice interval
+ for task identified by pid into the timespec structure
+ pointed to by interval. If pid is zero, the timeslice
+ for the calling process is written into 'interval. The
+ identified process should be running under the SCHED_RR
+ scheduling policy.'
+
+
+ Input Parameters:
+
+
+- pid. The task ID of the task. If pid is zero, the
+priority of the calling task is returned.
+
- interval. A structure used to return the time slice.
+
+
+
+ Returned Values:
+ On success, sched_rr_get_interval() returns OK (0). On
+ error, ERROR (-1) is returned, and errno is set to:
+
+
+ - EFAULT Cannot copy to interval
+ - EINVAL Invalid pid.
+ - ENOSYS The system call is not yet implemented.
+ - ESRCH The process whose ID is pid could not be found.
+
+
+
+ Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+ interface of the same name.
+
+
+
+
+2.3.1 sched_lock
+
+
+Function Prototype:
+
+ #include <sched.h>
+ STATUS sched_lock( void );
+
+
+
+Description: This function disables context switching by
+Disabling addition of new tasks to the ready-to-run task list.
+The task that calls this function will be the only task that is
+allowed to run until it either calls sched_unlock (the appropriate
+number of times) or until it blocks itself.
+
+Input Parameters: None.
+
+Returned Values:
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the comparable interface:
+
+ STATUS taskLock( void );
+
+
+2.3.2 sched_unlock
+
+
+Function Prototype:
+
+ #include <sched.h>
+ STATUS sched_unlock( void );
+
+
+
+Description: This function decrements the preemption lock
+count. Typically this is paired with sched_lock() and concludes
+a critical section of code. Preemption will not be unlocked until
+sched_unlock() has been called as many times as sched_lock().
+When the lockCount is decremented to zero, any tasks that were
+eligible to preempt the current task will execute.
+
+Input Parameters: None.
+
+Returned Values:
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the comparable interface:
+
+ STATUS taskUnlock( void );
+
+
+2.3.3 sched_lockcount
+
+
+Function Prototype:
+
+ #include <sched.h>
+ sint32 sched_lockcount( void )
+
+
+
+Description: This function returns the current value of
+the lockCount. If zero, preemption is enabled; if non-zero, this
+value indicates the number of times that sched_lock() has been called
+on this thread of execution.
+
+Input Parameters: None.
+
+Returned Values:
+
+- The current value of the lockCount.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: None.
+
+
+
+
+
+The Nuttx supports POSIX named message queues for intertask communication.
+Any task may send or receive messages on named message queues.
+Interrupt handlers may send messages via named message queues.
+
+
2.4.1 mq_open
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ mqd_t mq_open( const char *mqName, int oflags, ... );
+
+
+
+Description: This function establish a connection between
+a named message queue and the calling task. After a successful
+call of mq_open(), the task can reference the message queue using
+the address returned by the call. The message queue remains usable
+until it is closed by a successful call to mq_close().
+
+Input Parameters:
+
+- mqName. Name of the queue to open
+
- oflags. Open flags. These may be any combination of:
+
+- O_RDONLY. Open for read access.
+
- O_WRONLY. Open for write access.
+
- O_RDWR. Open for both read & write access.
+
- O_CREAT. Create message queue if it does not already
+exist.
+
- O_EXCL. Name must not exist when opened.
+
- O_NONBLOCK. Don't wait for data.
+
+
+ - ... Optional parameters.
+When the O_CREAT flag is specified, POSIX requires that a third
+and fourth parameter be supplied:
+
+- mode. The mode parameter is of type mode_t. In the POSIX
+specification, this mode value provides file permission bits for the
+message queue. This parameter is required but not used in the present
+implementation.
+
- attr. A pointer to an mq_attr that is provided to initialize.
+the message queue. If attr is NULL, then the messages queue is created
+with implementation-defined default message queue attributes. If attr is
+non-NULL, then the message queue mq_maxmsg attribute is set to the
+corresponding value when the queue is created. The mq_maxmsg attribute
+determines the maximum number of messages that can be queued before
+addition attempts to send messages on the message queue fail or cause the
+sender to block; the mq_msgsize attribute determines the maximum size of a
+message that can be sent or received. Other elements of attr are ignored
+(i.e, set to default message queue attributes).
+
+
+
+
+Returned Values:
+
+- A message queue descriptor or -1 (ERROR)
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX interface
+of the same name.
+Differences from the full POSIX implementation include:
+
+- The mq_msgsize attributes determines the maximum size of a message that
+may be sent or received. In the present implementation, this maximum
+message size is limited at 22 bytes.
+
+
+2.4.2 mq_close
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ int mq_close( mqd_t mqdes );
+
+
+
+Description: This function is used to indicate that the
+calling task is finished with the specified message queued mqdes.
+The mq_close() deallocates any system resources allocated by the
+system for use by this task for its message queue.
+
+If the calling task has attached a notification request to the message
+queue via this mqdes (see mq_notify()), this attachment will be
+removed and the message queue is available for another task to attach
+for notification.
+
+Input Parameters:
+
+- mqdes. Message queue descriptor.
+
+
+
+Returned Values:
+
+- 0 (OK) if the message queue is closed successfully, otherwise,
+-1 (ERROR).
+
+
+
+Assumptions/Limitations:
+
+
+- The behavior of a task that is blocked on either a mq_send() or
+mq_receive() is undefined when mq_close() is called.
+
- The result of using this message queue descriptor after successful
+return from mq_close() is undefined.
+
+
+ POSIX Compatibility: Comparable to the POSIX interface
+of the same name.
+
+
2.4.3 mq_unlink
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ int mq_unlink( const char *mqName );
+
+
+
+Description: This function removes the message queue named
+by "mqName." If one or more tasks have the message queue
+open when mq_unlink() is called, removal of the message queue
+is postponed until all references to the message queue have been
+closed.
+
+Input Parameters:
+
+- mqName. Name of the message queue
+
+
+
+Returned Values: None.
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.4.4 mq_send
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ int mq_send( mqd_t mqdes, const void *msg, size_t msgLen, int msgPrio );
+
+
+
+Description: This function adds the specified message (msg)
+to the message queue (mqdes). The "msgLen" parameter
+specifies the length of the message in bytes pointed to by "msg."
+This length must not exceed the maximum message length from the
+mq_getattr().
+
+If the message queue is not full, mq_send() will in the message
+in the message queue at the position indicated by the "msgPrio"
+argument. Messages with higher priority will be inserted before
+lower priority messages. The value of "msgPrio" must
+not exceed MQ_PRIO_MAX.
+
+If the specified message queue is full and O_NONBLOCK is not
+set in the message queue, then mq_send() will block until space
+becomes available to the queue the message.
+
+If the message queue is full and osNON_BLOCK is set, the message
+is not queued and ERROR is returned.
+
+Input Parameters:
+
+- mqdes. Message queue descriptor
+
- msg. Message to send
+
- msgLen. The length of the message in bytes
+
- msgPrio. The priority of the message
+
+
+
+Returned Values: None.
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the full POSIX implementation include:
+
+- Control is not returned if a signal is received.
+
+
+2.4.5 mq_receive
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ int mq_receive( mqd_t mqdes, void *msg, size_t msgLen, int *msgPrio );
+
+
+
+Description: This function receives the oldest of the highest
+priority messages from the message queue specified by "mqdes."
+If the size of the buffer in bytes (msgLen) is less than the "mq_msgsize"
+attribute of the message queue, mq_receive will return an error.
+Otherwise, the select message is removed from the queue and copied
+to "msg."
+
+If the message queue is empty and O_NONBLOCK was not set, mq_receive()
+will block until a message is added to the message queue. If more
+than one task is waiting to receive a message, only the task with
+the highest priority that has waited the longest will be unblocked.
+
+If the queue is empty and O_NONBLOCK is set, ERROR will be
+returned.
+
+Input Parameters:
+
+- mqdes. Message Queue Descriptor
+
- msg. Buffer to receive the message
+
- msgLen. Size of the buffer in bytes
+
- msgPrio. If not NULL, the location to store message
+priority.
+
+
+
+Returned Values:
+
+- Length of the selected message in bytes, otherwise -1 (ERROR).
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the full POSIX implementation include:
+
+- Control is not returned if a signal is received.
+
+
+2.4.6 mq_notify
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ int mq_notify( mqd_t mqdes, const struct sigevent *notification );
+
+
+
+Description: If the "notification" input parameter
+is not NULL, this function connects the task with the message queue such
+that the specified signal will be sent to the task whenever the message
+changes from empty to non-empty. One notification can be attached
+to a message queue.
+
+If "notification" is NULL, the attached notification
+is detached (if it was held by the calling task) and the queue
+is available to attach another notification.
+
+When the notification is sent to the registered task, its registration
+will be removed. The message queue will then be available for
+registration.
+
+Input Parameters:
+
+- mqdes. Message queue descriptor
+
- notification. Real-time signal structure containing:
+
+- sigev_notify. Should be osSIGEV_SIGNAL (but actually
+ignored)
+
- sigev_signo. The signo to use for the notification
+
- sigev_value. Value associated with the signal
+
+
+
+
+
+Returned Values: None.
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX interface
+of the same name.
+Differences from the full POSIX implementation include:
+
+- The notification signal will be sent to the registered task even if
+another task is waiting for the message queue to become non-empty. This is
+inconsistent with the POSIX specification which states, "If a process
+has registered for notification of message arrival at a message queue and
+some process is blocked in mq_receive waiting to receive a message
+when a message arrives at the queue, the arriving message shall satisfy the
+appropriate mq_receive() ... The resulting behavior is as if the
+message queue remains empty, and no notification shall be sent."
+
+
+2.4.7 mq_setattr
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ int mq_setattr( mqd_t mqdes, const struct mq_attr *mqStat,
+ struct mq_attr *oldMqStat);
+
+
+
+Description: This function sets the attributes associated
+with the specified message queue "mqdes." Only the "O_NONBLOCK"
+bit of the "mq_flags" can be changed.
+
+If "oldMqStat" is non-null, mq_setattr() will store
+the previous message queue attributes at that location (just as
+would have been returned by mq_getattr()).
+
+Input Parameters:
+
+- mqdes. Message queue descriptor
+
- mqStat. New attributes
+
- oldMqState. Old attributes
+
+
+
+Returned Values:
+
+- 0 (OK) if attributes are set successfully, otherwise -1
+(ERROR).
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.4.8 mq_getattr
+
+
+Function Prototype:
+
+ #include <mqueue.h>
+ int mq_getattr( mqd_t mqdes, struct mq_attr *mqStat);
+
+
+
+Description: This functions gets status information and
+attributes associated with the specified message queue.
+
+Input Parameters:
+
+- mqdes. Message queue descriptor
+
- mqStat. Buffer in which to return attributes. The returned
+attributes include:
+
+- mq_maxmsg. Max number of messages in queue.
+
- mq_msgsize. Max message size.
+
- mq_flags. Queue flags.
+
- mq_curmsgs. Number of messages currently in queue.
+
+
+
+
+
+Returned Values:
+
+- 0 (OK) if attributes provided, -1 (ERROR) otherwise.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
+
+
+Semaphores. Semaphores are the basis for
+synchronization and mutual exclusion in Nuttx. Nuttx supports
+POSIX semaphores.
+
+Semaphores are the preferred mechanism for gaining exclusive access to a
+resource. sched_lock() and sched_unlock() can also be used for this purpose.
+However, sched_lock() and sched_unlock() have other undesirable side-affects
+in the operation of the system: sched_lock() also prevents higher-priority
+tasks from running that do not depend upon the semaphore-managed resource
+and, as a result, can adversely affect system response times.
+
+Priority Inversion. Proper use of semaphores avoids the issues of
+sched_lock(). However, consider the following example:
+
+- Some low-priority task, Task C, acquires a semphore in order to
+get exclusive access to a protected resource.
+
- Task C is suspended to allow some high-priority task,
+Task A, to execute.
+
- Task A attempts to acquire the semaphore held by Task C and
+gets blocked until Task C relinquishes the semaphore.
+
- Task C is allowed to execute again, but gets suspended by some
+medium-priority Task B.
+
+At this point, the high-priority Task A cannot execute until
+Task B (and possibly other medium-priority tasks) completes and until
+Task C relinquishes the semaphore. In effect, the high-priority task,
+Task A behaves as though it were lower in priority than the
+low-priority task, Task C! This phenomenon is called priority
+inversion.
+
+Some operating systems avoid priority inversion by automatically
+increasing the priority of the low-priority Task C (the operable
+buzz-word for this behavior is mutex semaphores). The Nuttx does not
+support this behavior. As a consequence, it is left to the designer to
+provide implementations that will not suffer from priority inversion.
+The designer may, as examples:
+
+- Implement all tasks that need the semphore-managed resources at the
+same priority level,
+
- Boost the priority of the low-priority task before the semaphore is
+acquired, or
+
- Use sched_lock() in the low-priority task.
+
+
+
+
2.5.1 sem_init
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_init ( sem_t *sem, int pshared, unsigned int value );
+
+
+
+Description: This function initializes the UN-NAMED semaphore
+sem. Following a successful call to sem_init(), the semaphore
+may be used in subsequent calls to sem_wait(), sem_post(), and
+sem_trywait(). The semaphore remains usable until it is destroyed.
+
+Only sem itself may be used for performing synchronization. The
+result of referring to copies of sem in calls to sem_wait(),
+sem_trywait(), sem_post(), and sem_destroy(), is
+not defined.
+
+Input Parameters:
+
+- sem. Semaphore to be initialized
+
- pshared. Process sharing (not used)
+
- value. Semaphore initialization value
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if unsuccessful.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the full POSIX implementation include:
+
+
+2.5.2 sem_destroy
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_destroy ( sem_t *sem );
+
+
+
+Description: This function is used to destroy the un-named semaphore
+indicated by sem. Only a semaphore that was created using
+sem_init() may be destroyed using sem_destroy(). The effect
+of calling sem_destroy() with a named semaphore is undefined. The
+effect of subsequent use of the semaphore sem is undefined until
+sem is re-initialized by another call to sem_init().
+
+The effect of destroying a semaphore upon which other tasks are currently
+blocked is undefined.
+
+Input Parameters:
+
+- sem. Semaphore to be destroyed.
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if unsuccessful.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.5.3 sem_open
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ sem_t *sem_open ( const char *name, int oflag, ...);
+
+
+
+Description: This function establishes a connection between
+named semaphores and a task. Following a call to sem_open() with
+the semaphore name, the task may reference the semaphore associated
+with name using the address returned by this call. The semaphore
+may be used in subsequent calls to sem_wait(), sem_trywait(),
+and sem_post(). The semaphore remains usable until the semaphore
+is closed by a successful call to sem_close().
+
+If a task makes multiple calls to sem_open() with the same name,
+then the same semaphore address is returned (provided there have
+been no calls to sem_unlink()).
+
+Input Parameters:
+
+- name. Semaphore name
+
- oflag. Semaphore creation options. This may one of
+the following bit settings:
+
+- oflag = 0: Connect to the semaphore only if it already
+exists.
+
- oflag = O_CREAT: Connect to the semaphore if it exists,
+otherwise create the semaphore.
+
- oflag = O_CREAT with O_EXCL (O_CREAT|O_EXCL): Create
+a new semaphore unless one of this name already exists.
+
+ - ... Optional parameters.
+NOTE: When the O_CREAT flag is specified, POSIX requires that a third
+and fourth parameter be supplied:
+
+- mode. The mode parameter is of type mode_t.
+This parameter is required but not used in the present
+implementation.
+
- value. The value parameter is type unsigned int. The semaphore
+is created with an initial value of value. Valid initial values for
+semaphores must be less than or equal to SEM_MAX_VALUE.
+
+
+
+
+Returned Values:
+
+- A pointer to sem_t or -1 (ERROR) if unsuccessful.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the full POSIX implementation include:
+
+- Treatment of links/connections is highly simplified. It is
+just a counting semaphore.
+
+
+2.5.4 sem_close
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_close ( sem_t *sem );
+
+
+
+Description: This function is called to indicate that the
+calling task is finished with the specified named semaphore, sem.
+The sem_close() deallocates any system resources allocated by
+the system for this named semaphore.
+
+If the semaphore has not been removed with a call to sem_unlink(),
+then sem_close() has no effect on the named semaphore. However,
+when the named semaphore has been fully unlinked, the semaphore
+will vanish when the last task closes it.
+
+Care must be taken to avoid risking the deletion of a semaphore
+that another calling task has already locked.
+
+Input Parameters:
+
+- sem. Semaphore descriptor
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if unsuccessful.
+
+
+
+Assumptions/Limitations:
+
+- Care must be taken to avoid deletion of a semaphore that another task
+has already locked.
+
- sem_close() must not be called with an un-named semaphore.
+
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.5.5 sem_unlink
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_unlink ( const char *name );
+
+
+
+Description: This function will remove the semaphore named by the
+input name parameter. If one or more tasks have the semaphore named by
+name oepn when sem_unlink() is called, destruction of the semaphore will
+be postponed until all references have been destroyed by calls to
+sem_close().
+
+Input Parameters:
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if unsuccessful.
+
+
+
+Assumptions/Limitations:
+
+- Care must be taken to avoid deletion of a semaphore that another task
+has already locked.
+
- sem_unlink() must not be called with an un-named semaphore.
+
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the full POSIX implementation include:
+
+- Treatment of links/connections is highly simplified. It is
+just a counting semaphore.
+
- Calls to sem_open() to re-create or re-connect to the semaphore may
+refer to the same semaphore; POSIX specifies that a new semaphore with the
+same name should be created after sem_unlink() is called.
+
+
+2.5.6 sem_wait
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_wait ( sem_t *sem );
+
+
+
+Description: This function attempts to lock the semaphore
+referenced by sem. If the semaphore as already locked by another
+task, the calling task will not return until it either successfully acquires
+the lock or the call is interrupted by a signal.
+
+Input Parameters:
+
+- sem. Semaphore descriptor.
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) is unsuccessful
+
+
+If sem_wait returns -1 (ERROR) then the cause of the failure
+will be indicated by the thread-specific errno value (a pointer
+to this value can be obtained using get_errno_ptr()). The following
+lists the possible values for errno:
+
+
+- EINVAL: Indicates that the sem input parameter is
+not valid.
+
- EINTR: Indicates that the wait was interrupt by a signal
+received by this task. In this case, the semaphore has not be acquired.
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.5.7 sem_trywait
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_trywait ( sem_t *sem );
+
+
+
+Description: This function locks the specified semaphore
+only if the semaphore is currently not locked. In any event, the call
+returns without blocking.
+
+Input Parameters:
+
+- sem. The semaphore descriptor
+
+
+
+Returned Values:
+
+- 0 (OK) or -1 (ERROR) if unsuccessful
+
+If sem_wait returns -1 (ERROR) then the cause of the failure
+will be indicated by the thread-specific errno value (a pointer
+to this value can be obtained using get_errno_ptr()). The following
+lists the possible values for errno:
+
+
+- EINVAL: Indicates that the sem input parameter is
+not valid.
+
- EAGAIN: Indicates that the semaphore was not acquired.
+
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.5.8 sem_post
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_post ( sem_t *sem );
+
+
+
+Description: When a task has finished with a semaphore,
+it will call sem_post(). This function unlocks the semaphore referenced
+by sem by performing the semaphore unlock operation.
+
+If the semaphore value resulting from this operation is positive, then
+no tasks were blocked waiting for the semaphore to become unlocked;
+The semaphore value is simply incremented.
+
+If the value of the semaphore resulting from this operation is zero, then
+on of the tasks blocked waiting for the semaphore will be allowed to
+return successfully from its call to sem_wait().
+
+NOTE: sem_post() may be called from an interrupt handler.
+
+Input Parameters:
+
+- sem. Semaphore descriptor
+
+
+
+Returned Values:
+
+- 0 (OK) or -1 (ERROR) if unsuccessful.
+
+
+
+Assumptions/Limitations: This function cannot be called
+from an interrupt handler. It assumes the currently executing
+task is the one that is performing the unlock.
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.5.9 sem_getvalue
+
+
+Function Prototype:
+
+ #include <semaphore.h>
+ int sem_getvalue ( sem_t *sem, int *sval );
+
+
+
+Description: This function updates the location referenced
+by sval argument to have the value of the semaphore referenced
+by sem without effecting the state of the semaphore. The updated
+value represents the actual semaphore value that occurred at some
+unspecified time during the call, but may not reflect the actual
+value of the semaphore when it is returned to the calling task.
+
+If sem is locked, the value return by sem_getvalue() will either
+be zero or a negative number whose absolute value represents the
+number of tasks waiting for the semaphore.
+
+Input Parameters:
+
+- sem. Semaphore descriptor
+
- sval. Buffer by which the value is returned
+
+
+
+Returned Values:
+
+- 0 (OK) or -1 (ERROR) if unsuccessful.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
+
+
+
+
+The Nuttx provides a general watchdog timer facility. This
+facility allows the Nuttx user to specify a watchdog timer function
+that will run after a specified delay. The watchdog timer function
+will run in the context of the timer interrupt handler. Because
+of this, a limited number of Nuttx interfaces are available to
+the watchdog timer function. However, the watchdog timer function
+may use mq_send(), and sigqueue() to communicate with Nuttx tasks.
+
+
2.6.1 wd_create
+
+
+Function Prototype:
+
+ #include <wdog.h>
+ WDOG_ID wd_create (void);
+
+
+
+Description: The wd_create function will create a watchdog
+by allocating the appropriate resources for the watchdog.
+
+Input Parameters: None.
+
+Returned Values:
+
+- Pointer to watchdog that may be used as a handle in subsequent
+Nuttx calls (i.e., the watchdog ID), or NULL if insufficient resources
+are available to create the watchdogs.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following comparable interface:
+
+ WDOG_ID wdCreate (void);
+
+
+
+Differences from the VxWorks interface include:
+
+- The number of available watchdogs is fixed (configured at
+initialization time).
+
+
+2.6.2 wd_delete
+
+
+Function Prototype:
+
+ #include <wdog.h>
+ STATUS wd_delete (WDOG_ID wdId);
+
+
+
+Description: The wd_delete function will deallocate a
+watchdog. The watchdog will be removed from the timer queue if
+has been started.
+
+Input Parameters:
+
+- wdId. The watchdog ID to delete. This is actually a
+pointer to a watchdog structure.
+
+
+
+Returned Values:
+
+
+
+Assumptions/Limitations: It is the responsibility of the
+caller to assure that the watchdog is inactive before deleting
+it.
+
+ POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following comparable interface:
+
+ STATUS wdDelete (WDOG_ID wdId);
+
+
+
+Differences from the VxWorks interface include:
+
+- Does not make any checks to see if the watchdog is being used
+before de-allocating it (i.e., never returns ERROR).
+
+
+2.6.3 wd_start
+
+
+Function Prototype:
+
+ #include <wdog.h>
+ STATUS wd_start( WDOG_ID wdId, int delay, wdentry_t wdentry,
+ int parm1, int parm2, int parm3, int parm4 );
+
+
+
+Description: This function adds a watchdog to the timer
+queue. The specified watchdog function will be called from the
+interrupt level after the specified number of ticks has elapsed.
+Watchdog timers may be started from the interrupt level.
+
+Watchdog times execute in the context of the timer interrupt handler, but
+with the PIC/PID address environment that was in place when wd_start()
+was called.
+
+Watchdog timers execute only once.
+
+To replace either the timeout delay or the function to be executed,
+call wd_start again with the same wdId; only the most recent
+wd_start() on a given watchdog ID has any effect.
+
+Input Parameters:
+
+- wdId. Watchdog ID
+
- delay. Delay count in clock ticks
+
- wdentry. Function to call on timeout
+
- parm1..4. Parameters to pass to wdentry
+
+
+
+Returned Values:
+
+
+
+Assumptions/Limitations: The watchdog routine runs in the
+context of the timer interrupt handler and is subject to all ISR
+restrictions.
+
+ POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following comparable interface:
+
+ STATUS wdStart (WDOG_ID wdId, int delay, FUNCPTR wdentry, int parameter);
+
+
+
+Differences from the VxWorks interface include:
+
+- The present implementation supports four parameters passed
+to wdentry; VxWorks supports only a single parameter.
+
+
+2.6.4 wd_cancel
+
+
+Function Prototype:
+
+ #include <wdog.h>
+ STATUS wd_cancel (WDOG_ID wdId);
+
+
+
+Description: This function cancels a currently running
+watchdog timer. Watchdog timers may be canceled from the interrupt
+level.
+
+Input Parameters:
+
+- wdId. ID of the watchdog to cancel.
+
+
+
+Returned Values:
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: This is a NON-POSIX interface.
+VxWorks provides the following comparable interface:
+
+ STATUS wdCancel (WDOG_ID wdId);
+
+
+
+
+
+
+
+The Nuttx provides signal interfaces for tasks. Signals are
+used to alter the flow control of tasks by communicating asynchronous
+events within or between task contexts. Any task or interrupt
+handler can post (or send) a signal to a particular task. The
+task being signaled will execute task-specified signal handler
+function the next time that the task has priority.
+The signal handler is a user-supplied function that is bound to
+a specific signal and performs whatever actions are necessary
+whenever the signal is received.
+
+Signal handlers execute in the context of the task that registered
+the signal handler.
+
+There are no predefined actions for any signal.
+The default action for all signals (i.e., when no signal handler has
+been supplied by the user) is to ignore the signal.
+
+Tasks may also suspend themselves and wait until a signal is received.
+
+
2.7.1 sigemptyset
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigemptyset(sigset_t *set);
+
+
+
+Description: This function initializes the signal set specified
+by set such that all signals are excluded.
+
+Input Parameters:
+
+- set. Signal set to initialize.
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if the signal set cannot be initialized.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.2 sigfillset
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigfillset(sigset_t *set);
+
+
+
+Description: This function initializes the signal set specified
+by set such that all signals are included.
+
+Input Parameters:
+
+- set. Signal set to initialize
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if the signal set cannot be initialized.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.3 sigaddset
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigaddset(sigset_t *set, int signo);
+
+
+
+Description: This function adds the signal specified by
+signo to the signal set specified by set.
+
+Input Parameters:
+
+- set. Signal set to add signal to
+
- signo. Signal to add
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if the signal number is invalid.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.4 sigdelset
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigdelset(sigset_t *set, int signo);
+
+
+
+Description: This function deletes the signal specified
+by signo from the signal set specified by set.
+
+Input Parameters:
+
+- set. Signal set to delete the signal from
+
- signo. Signal to delete
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if the signal number is invalid.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.5 sigismember
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigismember(const sigset_t *set, int signo);
+
+
+
+Description: This function tests whether the signal specified
+by signo is a member of the set specified by set.
+
+Input Parameters:
+
+- set. Signal set to test
+
- signo. Signal to test for
+
+
+
+Returned Values:
+
+- 1 (TRUE), if the specified signal is a member of the set,
+
- 0 (OK or FALSE), if it is not, or
+
- -1 (ERROR) if the signal number is invalid.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.6 sigaction
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigaction( int signo, const struct sigaction *act,
+ struct sigaction *oact );
+
+
+
+Description: This function allows the calling task to
+examine and/or specify the action to be associated with a specific
+signal.
+
+The structure sigaction, used to describe an action to be taken, is defined
+to include the following members:
+
+- sa_u.sa_handler. A pointer to a signal-catching function.
+
- sa_u.sa_sigaction. An alternative form for the signal catching
+function.
+
- sa_mask. Additional set of signals to be blocked during
+execution of the signal-catching function.
+
- sa_flags: Special flags to affect behavior of a signal.
+
+
+If the argument act is not NULL, it points to a structure specifying the
+action to be associated with the specified signal. If the argument oact
+is not NULL, the action previously associated with the signal is stored
+in the location pointed to by the argument oact. If the argument act is
+NULL, signal handling is unchanged by this function call; thus, the call
+can be used to enquire about the current handling of a given signal.
+
+When a signal is caught by a signal-catching function installed by the
+sigaction() function, a new signal mask is calculated and installed for
+the duration of the signal-catching function. This mask is formed by taking
+the union of the current signal mask and the value of the sa_mask for the
+signal being delivered, and then including the signal being delivered. If
+and when the signal handler returns, the original signal mask is restored.
+
+Signal catching functions execute in the same address environment as the
+task that called sigaction() to install the signal-catching function.
+
+Once an action is installed for a specific signal, it remains installed
+until another action is explicitly requested by another call to
+sigaction().
+
+Input Parameters:
+
+- sig. Signal of interest
+
- act. Location of new handler
+
- oact. Location to store old handler
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if the signal number is invalid.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the POSIX implementation include:
+
+- Special values of sa_handler in the struct sigaction act input
+not handled (SIG_DFL, SIG_IGN).
+
- All sa_flags in struct sigaction of act input are ignored
+(all treated like SA_SIGINFO).
+
+
+2.7.7 sigprocmask
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
+
+
+
+Description: This function allows the calling task to
+examine and/or change its signal mask. If the set is not NULL,
+then it points to a set of signals to be used to change the currently
+blocked set. The value of how indicates the manner in which the
+set is changed.
+
+If there are any pending unblocked signals after the call to sigprocmask(),
+those signals will be delivered before sigprocmask() returns.
+
+If sigprocmask() fails, the signal mask of the task is not changed.
+
+Input Parameters:
+
+- how. How the signal mast will be changed:
+
+- osSIG_BLOCK. The resulting set is the union of the
+current set and the signal set pointed to by the set input parameter.
+
- osSIG_UNBLOCK. The resulting set is the intersection
+of the current set and the complement of the signal set pointed
+to by the set input parameter.
+
- osSIG_SETMASK. The resulting set is the signal set
+pointed to by the set input parameter.
+
+
+ - set. Location of the new signal mask
+
- oset. Location to store the old signal mask
+
+
+
+Returned Values:
+
+- 0 (OK), or -1 (ERROR) if how is invalid.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.8 sigpending
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigpending( sigset_t *set );
+
+
+
+Description: This function stores the returns the set of
+signals that are blocked for delivery and that are pending for
+the calling task in the space pointed to by set.
+
+If the task receiving a signal has the signal blocked via its
+sigprocmask, the signal will pend until it is unmasked. Only one pending
+signal (for a given signo) is retained by the system. This is consistent
+with POSIX which states: "If a subsequent occurrence of a pending
+signal is generated, it is implementation defined as to whether the signal
+is delivered more than once."
+
+Input Parameters:
+
+- set. The location to return the pending signal set.
+
+
+
+Returned Values:
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.9 sigsuspend
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigsuspend( const sigset_t *set );
+
+
+
+Description: The sigsuspend() function replaces the signal mask
+with the set of signals pointed to by the argument set and then suspends
+the task until delivery of a signal to the task.
+
+If the effect of the set argument is to unblock a pending signal, then
+no wait is performed.
+
+The original signal mask is restored when sigsuspend() returns.
+
+Waiting for an empty signal set stops a task without freeing any
+resources (a very bad idea).
+
+Input Parameters:
+
+- set. The value of the signal mask to use while
+suspended.
+
+
+
+Returned Values:
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the POSIX specification include:
+
+- POSIX does not indicate that the original signal mask is restored.
+
- POSIX states that sigsuspend() "suspends the task until
+delivery of a signal whose action is either to execute a signal-catching
+function or to terminate the task." Only delivery of the signal
+is required in the present implementation (even if the signal is ignored).
+
+
+2.7.10 sigwaitinfo
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigwaitinfo(const sigset_t *set, struct siginfo *info);
+
+
+
+Description: This function is equivalent to sigtimedwait()
+with a NULL timeout parameter. (see below).
+
+Input Parameters:
+
+- set. The set of pending signals to wait for.
+
- info. The returned signal values
+
+
+
+Returned Values:
+
+- Signal number that cause the wait to be terminated, otherwise
+-1 (ERROR) is returned.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.7.11 sigtimedwait
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigtimedwait( const sigset_t *set, struct siginfo *info,
+ const struct timespec *timeout );
+
+
+
+Description: This function selects the pending signal set
+specified by the argument set. If multiple signals are pending in set,
+it will remove and return the lowest numbered one. If no signals in set
+are pending at the time of the call, the calling task will be suspended
+until one of the signals in set becomes pending OR until the task
+interrupted by an unblocked signal OR until the time interval specified by
+timeout (if any), has expired. If timeout is NULL, then the timeout interval
+is forever.
+
+If the info argument is non-NULL, the selected signal number is
+stored in the si_signo member and the cause of the signal is store
+in the si_code member. The content of si_value is only meaningful
+if the signal was generated by sigqueue(). The following values
+for si_code are defined in signal.h:
+
+- Standard:
+
+- SI_QUEUE. Signal sent from sigqueue
+
- SI_MESGQ. Signal generated by arrival of a message
+on an empty message queue
+
+
+ - Unique to this implementation:
+
+- SI_TIMEOUT. No Signal, restarted by timeout
+
+
+
+
+
+Input Parameters:
+
+- set. The set of pending signals to wait for.
+
- info. The returned signal values
+
- timeout. The amount of time to wait
+
+
+
+Returned Values:
+
+- Signal number that cause the wait to be terminated, otherwise
+-1 (ERROR) is returned.
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the POSIX interface include:
+
+- Values for si_codes differ
+
- No mechanism to return cause of ERROR. (It can be inferred
+from si_code in a non-standard way).
+
- POSIX states that "If no signal is pending at the time of the
+call, the calling task shall be suspended until one or more signals
+in set become pending or until it is interrupted by an unblocked,
+caught signal." The present implementation does not require
+that the unblocked signal be caught; the task will be resumed even if
+the unblocked signal is ignored.
+
+
+2.7.12 sigqueue
+
+
+Function Prototype:
+
+ #include <signal.h>
+ int sigqueue (int tid, int signo, const union sigval value);
+
+
+
+Description: This function sends the signal specified by
+signo with the signal parameter value to the task specified
+by tid.
+
+If the receiving task has the signal blocked via its sigprocmask,
+the signal will pend until it is unmasked. Only one pending signal
+(for a given signo) is retained by the system. This is consistent with
+POSIX which states: "If a subsequent occurrence of a pending signal
+is generated, it is implementation defined as to whether the signal
+is delivered more than once."
+
+Input Parameters:
+
+- tid. Process ID of task to receive signal
+
- signo. Signal number
+
- value. Value to pass to task with signal
+
+
+
+Returned Values:
+
+
+
+Assumptions/Limitations:
+
+ POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+Differences from the POSIX interface include:
+
+- Default action is to ignore signals.
+
- Signals are processed one at a time in order
+
- Signals will (most likely) be processed on the caller's thread
+of execution.
+
- POSIX states that, "If signo is zero (the null signal), error
+checking will be performed but no signal is actually sent."
+There is no null signal in the present implementation; a zero signal will
+be sent.
+
+
+
+
+
2.8.1 pthread_attr_init
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_init(pthread_attr_t *attr);
+
+
+Description:
+Initializes a thread attributes object (attr) with default values
+for all of the individual attributes used by the implementation.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.2 pthread_attr_destroy
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_destroy(pthread_attr_t *attr);
+
+
+Description:
+An attributes object can be deleted when it is no longer needed.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.3 pthread_attr_setschedpolicy
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.4 pthread_attr_getschedpolicy
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_getschedpolicy(pthread_attr_t *attr, int *policy);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.5 pthread_attr_setschedparam
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_setschedparam(pthread_attr_t *attr,
+ const struct sched_param *param);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.6 pthread_attr_getschedparam
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_getschedparam(pthread_attr_t *attr,
+ struct sched_param *param);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.7 pthread_attr_setinheritsched
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_setinheritsched(pthread_attr_t *attr,
+ int inheritsched);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.8 pthread_attr_getinheritsched
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_getinheritsched(const pthread_attr_t *attr,
+ int *inheritsched);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.9 pthread_attr_setstacksize
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_setstacksize(pthread_attr_t *attr, long stacksize);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.10 pthread_attr_getstacksize
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_attr_getstacksize(pthread_attr_t *attr, long *stackaddr);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.11 pthread_create
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
+ pthread_startroutine_t startRoutine,
+ pthread_addr_t arg);
+
+
+Description:
+To create a thread object and runnable thread, a routine
+must be specified as the new thread's start routine. An
+argument may be passed to this routine, as an untyped
+address; an untyped address may also be returned as the
+routine's value. An attributes object may be used to
+specify details about the kind of thread being created.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.12 pthread_detach
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_detach(pthread_t thread);
+
+
+Description:
+A thread object may be "detached" to specify that the
+return value and completion status will not be requested.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.13 pthread_exit
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ void pthread_exit(pthread_addr_t pvValue);
+
+
+Description:
+A thread may terminate it's own execution.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.14 pthread_cancel
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_cancel(pthread_t thread);
+
+
+Description:
+
+
The pthread_cancel() function shall request that thread
+be canceled. The target thread's cancelability state determines
+when the cancellation takes effect. When the
+cancellation is acted on, thread shall be terminated.
+
+When cancelability is disabled, all cancels are held pending
+in the target thread until the thread changes the cancelability.
+When cancelability is deferred, all cancels are held pending in
+the target thread until the thread changes the cancelability or
+calls pthread_testcancel().
+
+Cancelability is asynchronous; all cancels are acted upon
+immediately (when enable), interrupting the thread with its processing.
+
+
+Input Parameters:
+
+
+- thread.
+Identifies the thread to be canceled.
+
+
+Returned Values:
+
+If successful, the ptnread_cancel() function will return zero (OK).
+Otherwise, an error number will be returned to indicate the error:
+
+
+- ESRCH.
+No thread could be found corresponding to that specified by the given thread ID.
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name. Except:
+
+- The thread-specific data destructor functions shall be called for thread.
+However, these destructors are not currently supported.
+- Cancellation types are not supported. The thread will be canceled
+at the time that pthread_cancel() is called or, if cancelation is disabled, at
+the time when cancelation is re-enabled.
+- pthread_testcancel() is not supported.
+- Thread cancellation at cancellation points is not supported.
+
+
+2.8.15 pthread_setcancelstate
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_setcancelstate(int state, int *oldstate);
+
+
+Description:
+
The pthread_setcancelstate() function atomically
+sets both the calling thread's cancelability state to the indicated
+state and returns the previous cancelability state at the location
+referenced by oldstate.
+Legal values for state are PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DISABLE.<.li>
+
+
Any pending thread cancelation may occur at the time that the
+cancelation state is set to PTHREAD_CANCEL_ENABLE.
+
+Input Parameters:
+
+
+- state
+New cancelation state. One of PTHREAD_CANCEL_ENABLE or PTHREAD_CANCEL_DISABLE.<.li>
+
- oldstate.
+Location to return the previous cancelation state.
+
+
+Returned Values:
+
+If successful, the pthread_setcancelstate() function will return
+zero (OK). Otherwise, an error number will be returned to indicate the error:
+
+
+- ESRCH.
+No thread could be found corresponding to that specified by the given thread ID.
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.16 pthread_setcancelstate
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_setcancelstate(int state, int *oldstate);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.17 pthread_join
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_join(pthread_t thread, pthread_addr_t *ppvValue);
+
+
+Description:
+A thread can await termination of another thread and retrieve
+the return value of the thread.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.18 pthread_yield
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ void pthread_yield(void);
+
+
+Description:
+A thread may tell the scheduler that its processor can be
+made available.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.19 pthread_self
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ pthread_t pthread_self(void);
+
+
+Description:
+A thread may obtain a copy of its own thread handle.
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.20 pthread_getschedparam
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_getschedparam(pthread_t thread, int *policy,
+ struct sched_param *param);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.21 pthread_setschedparam
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_setschedparam(pthread_t thread, int policy,
+ const struct sched_param *param);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.22 pthread_key_create
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_key_create( pthread_key_t *key, void (*destructor)(void*) )
+
+
+Description:
+
+This function creates a thread-specific data key visible
+to all threads in the system. Although the same key value
+may be used by different threads, the values bound to
+the key by pthread_setspecific() are maintained on a
+per-thread basis and persist for the life of the calling
+thread.
+
+Upon key creation, the value NULL will be associated with
+the the new key in all active threads. Upon thread
+creation, the value NULL will be associated with all
+defined keys in the new thread.
+
+Input Parameters:
+
+
+- key is a pointer to the key to create.
+
- destructor is an optional destructor() function that may
+be associated with each key that is invoked when a
+thread exits. However, this argument is ignored in
+the current implementation.
+
+
+Returned Values:
+
+If successful, the pthread_key_create() function will
+store the newly created key value at *key and return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+- EAGAIN. The system lacked sufficient resources
+to create another thread-specific data key, or the
+system-imposed limit on the total number of keys
+per task {PTHREAD_KEYS_MAX} has been exceeded
+
- ENONMEM Insufficient memory exists to create the key.
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+- The present implementation ignores the destructor argument.
+
+
+2.8.23 pthread_setspecific
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_setspecific( pthread_key_t key, void *value )
+
+
+Description:
+
+The pthread_setspecific() function associates a thread-
+specific value with a key obtained via a previous call
+to pthread_key_create(). Different threads may bind
+different values to the same key. These values are
+typically pointers to blocks of dynamically allocated
+memory that have been reserved for use by the calling
+thread.
+
+The effect of calling pthread_setspecific() with a key value
+not obtained from pthread_key_create() or after a key has been
+deleted with pthread_key_delete() is undefined.
+
+Input Parameters:
+
+
+- key. The data key to set the binding for.
+
- value. The value to bind to the key.
+
+
+Returned Values:
+
+If successful, pthread_setspecific() will return zero (OK).
+Otherwise, an error number will be returned:
+
+
+- ENOMEM. Insufficient memory exists to associate the value
+with the key.
+
- EINVAL. The key value is invalid.
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+- pthread_setspecific() may be called from a thread-specific data
+destructor function.
+
+
+2.8.24 pthread_getspecific
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ void *pthread_getspecific( pthread_key_t key )
+
+
+Description:
+
+The pthread_getspecific() function returns the value
+currently bound to the specified key on behalf of the
+calling thread.
+
+The effect of calling pthread_getspecific() with a key value
+not obtained from pthread_key_create() or after a key has been
+deleted with pthread_key_delete() is undefined.
+
+Input Parameters:
+
+
+- key. The data key to get the binding for.
+
+
+Returned Values:
+
+The function pthread_getspecific() returns the thread-
+specific data associated with the given key. If no
+thread specific data is associated with the key, then
+the value NULL is returned.
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+- pthread_getspecific() may be called from a thread-specific data
+destructor function.
+
+
+2.8.25 pthread_key_delete
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_key_delete( pthread_key_t key )
+
+
+Description:
+
+This POSIX function should delete a thread-specific data
+key previously returned by pthread_key_create(). However,
+this function does nothing in the present implementation.
+
+Input Parameters:
+
+
+- key. The key to delete
+
+
+Returned Values:
+
+
+- Always returns EINVAL.
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.26 pthread_mutexattr_init
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutexattr_init(pthread_mutexattr_t *attr);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.27 pthread_mutexattr_destroy
+
+Function Protoype:
+
+
+ #include <pthread.h>
+ int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.28 pthread_mutexattr_getpshared
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr,
+ int *pshared);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.29 pthread_mutexattr_setpshared
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
+ int pshared);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.30 pthread_mutex_init
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutex_init(pthread_mutex_t *mutex,
+ pthread_mutexattr_t *attr);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.31 pthread_mutex_destroy
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutex_destroy(pthread_mutex_t *mutex);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.32 pthread_mutex_lock
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutex_lock(pthread_mutex_t *mutex);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.33 pthread_mutex_trylock
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutex_trylock(pthread_mutex_t *mutex);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.34 pthread_mutex_unlock
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_mutex_unlock(pthread_mutex_t *mutex);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.35 pthread_condattr_init
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_condattr_init(pthread_condattr_t *attr);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.36 pthread_condattr_destroy
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_condattr_destroy(pthread_condattr_t *attr);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.37 pthread_cond_init
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.38 pthread_cond_destroy
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_cond_destroy(pthread_cond_t *cond);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.39 pthread_cond_broadcast
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_cond_broadcast(pthread_cond_t *cond);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.40 pthread_cond_signal
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_cond_signal(pthread_cond_t *dond);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.41 pthread_cond_wait
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
2.8.42 pthread_cond_timedwait
+
+Function Prototype:
+
+
+ #include <pthread.h>
+ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime);
+
+
+Description:
+
+Input Parameters:
+
+
+
+Returned Values:
+
+If successful, the xxx() function will return
+zero (OK). Otherwise, an error number will be
+returned to indicate the error:
+
+
+Assumptions/Limitations:
+
+POSIX Compatibility: Comparable to the POSIX
+interface of the same name.
+
+
+
+
+3.1 Scalar types
+
+Many of the types used to communicate with Nuttx are simple
+scalar types. These types are used to provide architecture independence
+of the OS from the application. The scalar types used at the Nuttx
+interface include:
+
+- pid_t
+
- size_t
+
- sigset_t
+
- STATUS
+
- time_t
+
+
+3.2 Hidden Interface Structures
+
+Several of the types used to interface with Nuttx are
+structures that are intended to be hidden from the application.
+From the standpoint of the application, these structures (and
+structure pointers) should be treated as simple handles to reference
+OS resources. These hidden structures include:
+
+- _TCB
+
- mqd_t
+
- sem_t
+
- WDOG_ID
+
- pthread_key_t
+
+
+In order to maintain portability, applications should not reference
+specific elements within these hidden structures. These hidden
+structures will not be described further in this user's manual.
+
+
+
3.3. Access to the errno Variable
+
+A pointer to the thread-specific errno. value is available through a
+function call:
+
+Function Prototype:
+
+
int *get_errno_ptr( void )
+
+Description: osGetErrnorPtr() returns a pointer to
+the thread-specific errno value.
+
+This differs somewhat from the use for errno in a multi-threaded process environment:
+Each pthread will have its own private copy of errno and the errno will not be shared
+between pthreads.
+
+Input Parameters: None
+
+Returned Values:
+
+
+- A pointer to the thread-specific errno value.
+
+
+
+
3.4 User Interface Structures
+
+
3.4.1 main_t
+
+main_t defines the type of a task entry point. main_t is declared
+in sys/types.h as:
+
+ typedef int (*main_t)(int argc, char *argv[]);
+
+
+3.4.2 struct sched_param
+
+
+This structure is used to pass scheduling priorities to and from
+Nuttx;
+
+ struct sched_param
+ {
+ int sched_priority;
+ };
+
+
+3.4.3 struct timespec
+
+
+This structure is used to pass timing information between the
+Nuttx and a user application:
+
+ struct timespec
+ {
+ time_t tv_sec; /* Seconds */
+ long tv_nsec; /* Nanoseconds */
+ };
+
+
+3.4.4 struct mq_attr
+
+
+This structure is used to communicate message queue attributes
+between Nuttx and a MoBY application:
+
+ struct mq_attr {
+ size_t mq_maxmsg; /* Max number of messages in queue */
+ size_t mq_msgsize; /* Max message size */
+ unsigned mq_flags; /* Queue flags */
+ size_t mq_curmsgs; /* Number of messages currently in queue */
+ };
+
+
+3.4.5 struct sigaction
+
+
+The following structure defines the action to take for given signal:
+
+ struct sigaction {
+ union {
+ saHandType *_sa_handler;
+ saVxHandType *_sa_sigaction;
+ } sa_u;
+ sigset_t sa_mask;
+ int sa_flags;
+ };
+ #define sa_handler sa_u._sa_handler
+ #define sa_sigaction sa_u._sa_sigaction
+
+
+
+where:
+
+ typedef void saHandType( int signo );
+ typedef void saVxHandType( int signo, siginfo_t *info, void *context );
+
+
+3.4.6 struct siginfo/siginfo_t
+
+
+The following types is used to pass parameters to/from signal
+handlers:
+
+ typedef struct siginfo
+ {
+ int si_signo;
+ int si_code;
+ union sigval si_value;
+ } siginfo_t;
+
+
+3.4.7 union sigval
+
+
+This defines the type of the struct siginfo si_value field and
+is used to pass parameters with signals.
+
+ union sigval
+ {
+ int sival_int;
+ void *sival_ptr;
+ };
+
+
+3.4.8 struct sigevent
+
+
+The following is used to attach a signal to a message queue to
+notify a task when a message is available on a queue.
+
+ struct sigevent
+ {
+ int sigev_signo;
+ union sigval sigev_value;
+ int sigev_notify;
+ };
+
+
+
+
+
+
+This section documents know problems with Nuttx at the time
+of this writing.
+
+
+Problem:
+There is a problem with the unblock logic in os_signal.c when message queue
+becomes not-empty -- sig_mqnotempty() calls sig_received().
+sig_received() relies on task_state == TSTATE_WAIT_SIG and will ignore
+tasks that are waiting on a message queue to become non-empty.
+
+Priority: LOW. If a task is blocked a waiting for a message
+queue to become non-empty, it will be re-started anyway.
+
+
+Problem: task_restart won't restart a running task
+
+Priority: LOW.
+
+
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000..34bb7ab895
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,139 @@
+############################################################
+# Makefile
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+
+TOPDIR = ${shell pwd}
+-include ${TOPDIR}/.config
+-include ${TOPDIR}/Make.defs
+
+ARCH_DIR = arch/$(CONFIG_ARCH)
+ARCH_SRC = $(ARCH_DIR)/src
+
+SUBDIRS = sched lib $(ARCH_SRC) mm fs drivers examples/$(CONFIG_EXAMPLE)
+
+OBJS = $(ARCH_SRC)/up_head.o
+LIBGCC = ${shell $(CC) -print-libgcc-file-name}
+LIBS = sched/libsched.a $(ARCH_SRC)/libarch.a mm/libmm.a \
+ fs/libfs.a drivers/libdrivers.a lib/liblib.a \
+ examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE).a
+LDLIBS = -lsched -larch -lmm -lfs -ldrivers -llib -l$(CONFIG_EXAMPLE) $(LIBGCC) $(EXTRA_LIBS)
+
+BIN = nuttx
+
+LDFLAGS += -Lsched -Llib -L$(ARCH_SRC) -Lmm -Lfs -Ldrivers -Lexamples/$(CONFIG_EXAMPLE)
+
+all: $(BIN)
+.PHONY: clean context clean_context distclean
+
+tools/mkconfig:
+ $(MAKE) -C tools -f Makefile.mkconfig TOPDIR=$(TOPDIR) mkconfig
+
+include/nuttx/config.h: $(ARCH_DIR)/defconfig tools/mkconfig
+ tools/mkconfig $(ARCH_DIR) > include/nuttx/config.h
+
+include/arch: include/nuttx/config.h
+ ln -sf $(TOPDIR)/$(ARCH_DIR)/include include/arch
+
+context: check_context include/nuttx/config.h include/arch
+
+clean_context:
+ rm -f include/nuttx/config.h
+ rm -f include/arch
+
+check_context:
+ @if [ ! -e ${TOPDIR}/.config -o ! -e ${TOPDIR}/Make.defs ]; then \
+ echo "" ; echo "Nuttx has not been configured:" ; \
+ echo " cd tools; ./configure.sh \n" ; echo "" ;\
+ exit 1 ; \
+ fi
+
+sched/libsched.a: context
+ $(MAKE) -C sched TOPDIR=$(TOPDIR) libsched.a
+
+lib/liblib.a: context
+ $(MAKE) -C lib TOPDIR=$(TOPDIR) liblib.a
+
+$(ARCH_SRC)/libarch.a: context
+ $(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) libarch.a
+
+$(ARCH_SRC)/up_head.o: context
+ $(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) up_head.o
+
+mm/libmm.a: context
+ $(MAKE) -C mm TOPDIR=$(TOPDIR) libmm.a
+
+fs/libfs.a: context
+ $(MAKE) -C fs TOPDIR=$(TOPDIR) libfs.a
+
+drivers/libdrivers.a: context
+ $(MAKE) -C drivers TOPDIR=$(TOPDIR) libdrivers.a
+
+examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE).a: context
+ $(MAKE) -C examples/$(CONFIG_EXAMPLE) TOPDIR=$(TOPDIR) lib$(CONFIG_EXAMPLE).a
+
+$(BIN): context depend $(OBJS) $(LIBS)
+ifeq ($(CONFIG_ARCH),sim)
+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(LDLIBS)
+ $(NM) $(BIN) | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
+else
+ $(LD) --entry=__start $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(LDLIBS)
+ $(NM) $(BIN) | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
+ @export vflashstart=`$(OBJDUMP) --all-headers $(BIN) | grep _vflashstart | cut -d' ' -f1`; \
+ if [ ! -z "$$vflashstart" ]; then \
+ $(OBJCOPY) --adjust-section-vma=.vector=0x$$vflashstart $(BIN) $(BIN).flashimage; \
+ mv $(BIN).flashimage $(BIN); \
+ fi
+endif
+
+depend:
+ @for dir in $(SUBDIRS) ; do \
+ $(MAKE) -C $$dir TOPDIR=$(TOPDIR) depend ; \
+ done
+
+clean:
+ @for dir in $(SUBDIRS) ; do \
+ $(MAKE) -C $$dir TOPDIR=$(TOPDIR) clean ; \
+ done
+ $(MAKE) -C tools -f Makefile.mkconfig TOPDIR=$(TOPDIR) clean
+ $(MAKE) -C mm -f Makefile.test TOPDIR=$(TOPDIR) clean
+ rm -f $(BIN) context mm_test System.map *~ *.flashimage
+
+distclean: clean clean_context
+ @for dir in $(SUBDIRS) ; do \
+ $(MAKE) -C $$dir TOPDIR=$(TOPDIR) distclean ; \
+ done
+ $(MAKE) -C examples/$(CONFIG_EXAMPLE) TOPDIR=$(TOPDIR) distclean
+ rm -f Make.defs setenv.sh .config
+
+
diff --git a/arch/README.txt b/arch/README.txt
new file mode 100644
index 0000000000..85175c6a07
--- /dev/null
+++ b/arch/README.txt
@@ -0,0 +1,189 @@
+Architecture-Specific Code
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The file include/nuttx/arch.h identifies all of the APIs that must
+be provided by the architecture specific logic. (It also includes
+arch//arch.h as described below).
+
+Directory Structure
+^^^^^^^^^^^^^^^^^^^
+
+Thie arch directory contains architecture specific logic. Each aructure
+provide a a subdirectory under arch/ with the folling characteristics:
+
+
+
+ |-- Make.defs
+ |-- defconfig
+ |-- setenv.sh
+ |-- include
+ | |-- arch.h
+ | |-- irq.h
+ | `-- types.h
+ `-- src
+ |-- Makefile
+ `-- (architecture-specific source files)
+
+Summary of Files
+^^^^^^^^^^^^^^^^
+
+Make.defs -- This makefile fragment provides architecture and
+ tool-specific build options. It will be included by all other
+ makefiles in the build (once it is installed). This make fragment
+ should define:
+
+ Tools: CC, LD, AR, NM, OBJCOPY, OBJDUMP
+ Tool options: CFLAGS, LDFLAGS
+
+ When this makefile fragment runs, it will be passed TOPDIR which
+ is the path to the root directory of the build. This makefile
+ fragment may include ${TOPDIR}/.config to perform configuration
+ specific settings. For example, the CFLAGS will most likely be
+ different if CONFIG_DEBUG=y.
+
+defconfig -- This is a configuration file similar to the Linux
+ configuration file. In contains varialble/value pairs like:
+
+ CONFIG_VARIABLE=value
+
+ This configuration file will be used at build time:
+
+ (1) as a makefile fragment included in other makefiles, and
+ (2) to generate include/nuttx/config.h which is included by
+ most C files in the system.
+
+ The following variables are recognized by the build (you may
+ also include architecture-specific settings).
+
+ Architecture selection:
+
+ CONFIG_ARCH - identifies the arch subdirectory
+ CONFIG_ARCH_name - for use in C code
+
+ General OS setup
+
+ CONFIG_EXAMPLE - identifies the subdirectgory in examples
+ that will be used in the build
+ CONFIG_DEBUG - enables built-in debug options
+ CONFIG_DEBUG_VERBOSE - enables verbose debug output
+ CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot
+ time console output
+ CONFIG_RR_INTERVAL - The round robin timeslice will be set
+ this number of milliseconds; Round robin scheduling can
+ be disabled by setting this value to zero.
+ CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
+ scheduler to monitor system performance
+ CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
+ task name to save in the TCB. Useful if scheduler
+ instrumentation is selected. Set to zero to disable.
+ CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
+ Used to initialize the internal time logic.
+ CONFIG_JULIAN_TIME - Enables Julian time conversions
+ CONFIG_DEV_CONSOLE - Set if architecture-specific logic
+ provides /dev/console. Enables stdout, stderr, stdin.
+
+ Allow for artchitecture optimized implementations
+
+ The architecture can provide optimized versions of the
+ following to improve sysem performance
+
+ CONFIG_ARCH_MEMCPY, CONFIG_ARCH_MEMCMP, CONFIG_ARCH_MEMMOVE
+ CONFIG_ARCH_MEMSET, CONFIG_ARCH_STRCMP, CONFIG_ARCH_STRCPY
+ CONFIG_ARCH_STRNCPY, CONFIG_ARCH_STRLEN, CONFIG_ARCH_BZERO
+ CONFIG_ARCH_KMALLOC, CONFIG_ARCH_KZMALLOC, CONFIG_ARCH_KFREE
+
+ General Compile environment setup
+
+ CONFIG_HAVE_LONG_LONG - enable if your architecture supports
+ long long types and if you plan to use them
+
+ Sizes of configurable things (0 disables)
+
+ CONFIG_NPTHREAD_KEYS - The number of items of thread-
+ specific data that can be retained
+ CONFIG_NFILE_DESCRIPTORS - The maximum number of file
+ descriptors (one for each open)
+ CONFIG_NFILE_STREAMS - The maximum number of streams that
+ can be fopen'ed
+ CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
+ on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
+ CONFIG_NUNGET_CHARS - Number of characters that can be
+ buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
+ CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
+ structures. The system manages a pool of preallocated
+ message structures to minimize dynamic allocations
+ CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
+ a fixed payload size given by this settin (does not include
+ other message structure overhead.
+ CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
+ structures. The system manages a pool of preallocated
+ watchdog structures to minimize dynamic allocations
+
+ Stack and heap information
+
+ CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
+ operation from FLASH.
+ 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
+ CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
+ CONFIG_HEAP_BASE - The beginning of the heap
+ CONFIG_HEAP_SIZE - The size of the heap
+
+setenv.sh -- This is a script that you can include that will be installed at
+ the toplevel of the directory structure and can be sourced to set any
+ necessary environment variables.
+
+include/arch.h
+ This is a hook for any architecture specific definitions that may
+ be needed by the system. It is included by include/nuttx/arch.h
+
+include/types.h
+ This provides architecture/toolchain-specific definitions for
+ standard types. This file should typedef:
+
+ sbyte, ubyte, uint8, boolean, sint16, uint16, sint32, uint32, sint64, uint64
+
+ This file will be included by include/sys/types.h and be made
+ available to all files.
+
+include/irq.h
+ This file needs to define some architecture specific functions (usually
+ inline) and structure. These include:
+
+ - struct xcptcontext. This structures represents the saved context
+ of a thread.
+
+ - static inline uint32 irqsave(void) -- Used to disable
+ all interrupts.
+
+ - static inline void irqrestore(uint32 flags) -- Used to
+ restore interrupts enables to the same state as before irqsave
+ was called.
+
+ This file must also define NR_IRQS, the total number of IRQs supported
+ by the board.
+
+src/Makefile
+ This makefile will be executed to build the targets src/libup.a and
+ src/up_head.o. The up_head.o file holds the entry point into the system
+ (power-on reset entry point, for example). It will be used in
+ the final link with libup.a and other system archives to generate the
+ final executable.
+
+Configuring NuttX
+^^^^^^^^^^^^^^^^^
+
+Configuring NuttX requires only copying
+
+ arch//Make.def to ${TOPDIR}/Make.defs
+ arch//setenv.sh to ${TOPDIR}/setenv.sh
+ arch//defconfig to ${TOPDIR}/.config
+
+There is a script that automates these steps. The following steps will
+accomplish the same configuration:
+
+ cd tools
+ ./configure.sh
+
+
diff --git a/arch/c5471/Make.defs b/arch/c5471/Make.defs
new file mode 100644
index 0000000000..7e68d8e566
--- /dev/null
+++ b/arch/c5471/Make.defs
@@ -0,0 +1,70 @@
+############################################################
+# Make.defs
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+
+include ${TOPDIR}/.config
+
+ifeq ("${CONFIG_DEBUG}","y")
+ ARCHOPTIMIZATION = -g
+else
+ ARCHOPTIMIZATION = -Os -fno-strict-aliasing -fno-strength-reduce \
+ -fomit-frame-pointer
+endif
+
+ARCHCPUFLAGS = -mapcs-32 -mcpu=arm7tdmi -msoft-float
+ARCHPICFLAGS = -fpic
+ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
+ARCHDEFINES =
+ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
+ARCHSCRIPT = -T$(TOPDIR)/arch/$(CONFIG_ARCH)/ld.script
+
+CROSSDEV = arm-elf-
+CC = $(CROSSDEV)gcc
+LD = $(CROSSDEV)ld
+AR = $(CROSSDEV)ar
+NM = $(CROSSDEV)nm
+OBJCOPY = $(CROSSDEV)objcopy
+OBJDUMP = $(CROSSDEV)objdump
+
+CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
+ $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) -pipe
+
+LDFLAGS = $(ARCHSCRIPT)
+EXTRA_LIBS =
+
+ifeq ("${CONFIG_DEBUG}","y")
+ LDFLAGS += -g
+endif
+
+
diff --git a/arch/c5471/defconfig b/arch/c5471/defconfig
new file mode 100644
index 0000000000..c48d0b8379
--- /dev/null
+++ b/arch/c5471/defconfig
@@ -0,0 +1,157 @@
+############################################################
+# defconfig
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+#
+# architecture selection
+#
+# CONFIG_ARCH - identifies the arch subdirectory
+# CONFIG_ARCH_name - for use in C code
+# CONFIG_ROM_VECTORS - unique to arm7tdmi
+#
+CONFIG_ARCH=c5471
+CONFIG_ARCH_C5471=y
+CONFIG_ROM_VECTORS=n
+
+#
+# General OS setup
+#
+# CONFIG_EXAMPLE - identifies the subdirectgory in examples
+# that will be used in the build
+# CONFIG_DEBUG - enables built-in debug options
+# CONFIG_DEBUG_VERBOSE - enables verbose debug output
+# CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot
+# time console output
+# CONFIG_RR_INTERVAL - The round robin timeslice will be set
+# this number of milliseconds; Round robin scheduling can
+# be disabled by setting this value to zero.
+# CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
+# scheduler to monitor system performance
+# CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
+# task name to save in the TCB. Useful if scheduler
+# instrumentation is selected. Set to zero to disable.
+# CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
+# Used to initialize the internal time logic.
+# CONFIG_JULIAN_TIME - Enables Julian time conversions
+# CONFIG_DEV_CONSOLE - Set if architecture-specific logic
+# provides /dev/console. Enables stdout, stderr, stdin.
+#
+CONFIG_EXAMPLE=ostest
+CONFIG_DEBUG=y
+CONFIG_DEBUG_VERBOSE=n
+CONFIG_ARCH_LOWPUTC=n
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_INSTRUMENTATION=n
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_START_YEAR=2007
+CONFIG_START_MONTH=2
+CONFIG_START_DAY=13
+CONFIG_JULIAN_TIME=n
+CONFIG_DEV_CONSOLE=n
+
+#
+# Allow for artchitecture optimized implementations
+#
+# The architecture can provide optimized versions of the
+# following to improve sysem performance
+#
+CONFIG_ARCH_MEMCPY=n
+CONFIG_ARCH_MEMCMP=n
+CONFIG_ARCH_MEMMOVE=n
+CONFIG_ARCH_MEMSET=n
+CONFIG_ARCH_STRCMP=n
+CONFIG_ARCH_STRCPY=n
+CONFIG_ARCH_STRNCPY=n
+CONFIG_ARCH_STRLEN=n
+CONFIG_ARCH_BZERO=n
+CONFIG_ARCH_KMALLOC=n
+CONFIG_ARCH_KZMALLOC=n
+CONFIG_ARCH_KFREE=n
+
+# General Compile environment setup
+#
+# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
+# long long types and if you plan to use them
+CONFIG_HAVE_LONG_LONG=n
+
+#
+# Sizes of configurable things (0 disables)
+#
+# CONFIG_NPTHREAD_KEYS - The number of items of thread-
+# specific data that can be retained
+# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
+# descriptors (one for each open)
+# CONFIG_NFILE_STREAMS - The maximum number of streams that
+# can be fopen'ed
+# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
+# on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_NUNGET_CHARS - Number of characters that can be
+# buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
+# structures. The system manages a pool of preallocated
+# message structures to minimize dynamic allocations
+# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
+# a fixed payload size given by this settin (does not include
+# other message structure overhead.
+# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
+# structures. The system manages a pool of preallocated
+# watchdog structures to minimize dynamic allocations
+#
+CONFIG_NPTHREAD_KEYS=4
+CONFIG_NFILE_DESCRIPTORS=32
+CONFIG_NFILE_STREAMS=16
+CONFIG_STDIO_BUFFER_SIZE=1024
+CONFIG_NUNGET_CHARS=2
+CONFIG_PREALLOC_MQ_MSGS=32
+CONFIG_MQ_MAXMSGSIZE=32
+CONFIG_PREALLOC_WDOGS=32
+
+#
+# Stack and heap information
+#
+# CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
+# operation from FLASH.
+# 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
+# CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
+# CONFIG_HEAP_BASE - The beginning of the heap
+# CONFIG_HEAP_SIZE - The size of the heap
+#
+CONFIG_BOOT_FROM_FLASH=n
+CONFIG_STACK_POINTER=0x02100000
+CONFIG_PROC_STACK_SIZE=0x00001000
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=4096
+CONFIG_HEAP_BASE=0x02100000
+CONFIG_HEAP_SIZE=0x00100000
diff --git a/arch/c5471/include/arch.h b/arch/c5471/include/arch.h
new file mode 100644
index 0000000000..86d6652b62
--- /dev/null
+++ b/arch/c5471/include/arch.h
@@ -0,0 +1,80 @@
+/************************************************************
+ * arch.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+/* This file should never be included directed but, rather,
+ * only indirectly through nuttx/arch.h
+ */
+
+#ifndef __ARCH_C5471_ARCH_H
+#define __ARCH_C5471_ARCH_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Inline functions
+ ************************************************************/
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ARCH_C5471_ARCH_H */
+
diff --git a/arch/c5471/include/irq.h b/arch/c5471/include/irq.h
new file mode 100644
index 0000000000..c3bb57c293
--- /dev/null
+++ b/arch/c5471/include/irq.h
@@ -0,0 +1,252 @@
+/************************************************************
+ * irq.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+/* This file should never be included directed but, rather,
+ * only indirectly through nuttx/irq.h
+ */
+
+#ifndef __ARCH_C5471_IRQ_H
+#define __ARCH_C5471_IRQ_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* IRQ Stack Frame Format:
+ *
+ * Context is always saved/restored in the same way:
+ *
+ * (1) stmia rx, {r0-r3, r12}
+ * (2) stmia rx, (cpsr, r4-r11, r13-r14}
+ *
+ * This results in the following set of indices that
+ * can be used to access individual registers in the
+ * xcp.regs array:
+ */
+
+#define JB_R0 (0)
+#define JB_R1 (1)
+#define JB_R2 (2)
+#define JB_R3 (3)
+#define JB_R12 (4)
+
+#define XCPTCONTEXT_IRQ_REGS (5)
+#define XCPTCONTEXT_UOFFSET (4 * XCPTCONTEXT_IRQ_REGS)
+
+#define JB_CPSR (0 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R4 (1 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R5 (2 + XCPTCONTEXT_IRQ_REGS
+#define JB_R6 (3 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R7 (4 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R8 (5 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R9 (6 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R10 (7 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R11 (8 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R13 (9 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R14 (10 + XCPTCONTEXT_IRQ_REGS)
+#define JB_R15 /* Not saved */
+
+#define XCPTCONTEXT_USER_REG (11)
+#define XCPTCONTEST_REGS (XCPTCONTEXT_USER_REG+XCPTCONTEXT_IRQ_REGS)
+#define XCPTCONTEXT_SIZE (4 * XCPTCONTEST_REGS)
+
+#define JB_A1 JB_R0
+#define JB_A2 JB_R1
+#define JB_A3 JB_R2
+#define JB_A4 JB_R3
+#define JB_V1 JB_R4
+#define JB_V2 JB_R5
+#define JB_V3 JB_R6
+#define JB_V4 JB_R7
+#define JB_V5 JB_R8
+#define JB_V6 JB_R9
+#define JB_V7 JB_R10
+#define JB_SB JB_R9
+#define JB_SL JB_R10
+#define JB_FP JB_R11
+#define JB_IP JB_R12
+#define JB_SP JB_R13
+#define JB_LR JB_R14
+#define JB_PC JB_R15
+
+/* C5471 Interrupts */
+
+#define C5471_IRQ_TIMER0 0
+#define C5471_IRQ_TIMER1 1
+#define C5471_IRQ_TIMER2 2
+#define C5471_IRQ_GPIO0 3
+#define C5471_IRQ_ETHER 4
+#define C5471_IRQ_KBGPIO_0_7 5
+#define C5471_IRQ_UART 6
+#define C5471_IRQ_UART_IRDA 7
+#define C5471_IRQ_KBGPIO_8_15 8
+#define C5471_IRQ_GPIO3 9
+#define C5471_IRQ_GPIO2 10
+#define C5471_IRQ_I2C 11
+#define C5471_IRQ_GPIO1 12
+#define C5471_IRQ_SPI 13
+#define C5471_IRQ_GPIO_4_19 14
+#define C5471_IRQ_API 15
+
+#define C5471_IRQ_WATCHDOG C5471_IRQ_TIMER0
+#define C5471_IRQ_SYSTIMER C5471_IRQ_TIMER1
+#define NR_IRQS (C5471_IRQ_API+1)
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+/* This struct defines the way the registers are stored. We
+ * need to save:
+ *
+ * 1 CPSR
+ * 7 Static registers, v1-v7 (aka r4-r10)
+ * 1 Frame pointer, fp (aka r11)
+ * 1 Stack pointer, sp (aka r13)
+ * 1 Return address, lr (aka r14)
+ * ---
+ * 11 (XCPTCONTEXT_USER_REG)
+ *
+ * On interrupts, we also need to save:
+ * 4 Volatile registers, a1-a4 (aka r0-r3)
+ * 1 Scratch Register, ip (aka r12)
+ *---
+ * 5 (XCPTCONTEXT_IRQ_REGS)
+ *
+ * For a total of 17 (XCPTCONTEST_REGS)
+ */
+
+#ifndef __ASSEMBLY__
+struct xcptcontext
+{
+ /* The following function pointer is non-zero if there
+ * are pending signals to be processed.
+ */
+
+ void *sigdeliver; /* Actual type is sig_deliver_t */
+
+ /* These are saved copies of LR and CPSR used during
+ * signal processing.
+ */
+
+ uint32 saved_lr;
+ uint32 saved_cpsr;
+
+ /* Register save area */
+
+ uint32 regs[XCPTCONTEST_REGS];
+};
+#endif
+
+/************************************************************
+ * Inline functions
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/* Save the current interrupt enable state & disable IRQs */
+
+static inline uint32 irqsave(void)
+{
+ unsigned long flags;
+ unsigned long temp;
+ __asm__ __volatile__
+ (
+ "\tmrs %0, cpsr\n"
+ "\torr %1, %0, #128\n"
+ "\tmsr cpsr_c, %1"
+ : "=r" (flags), "=r" (temp)
+ :
+ : "memory");
+ return flags;
+}
+
+/* Restore saved IRQ & FIQ state */
+
+static inline void irqrestore(uint32 flags)
+{
+ __asm__ __volatile__
+ (
+ "msr cpsr_c, %0"
+ :
+ : "r" (flags)
+ : "memory");
+}
+
+static inline void system_call(swint_t func, uint32 parm1,
+ uint32 parm2, uint32 parm3)
+{
+ __asm__ __volatile__
+ (
+ "mov\tr0,%0\n\t"
+ "mov\tr1,%1\n\t"
+ "mov\tr2,%2\n\t"
+ "mov\tr2,%3\n\t"
+ "swi\t0x900001\n\t"
+ :
+ : "r" ((long)(func)), "r" ((long)(parm1)),
+ "r" ((long)(parm2)), "r" ((long)(parm3))
+ : "r0", "r1", "r2", "r3", "lr");
+}
+#endif
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+#endif /* __ARCH_C5471_IRQ_H */
+
diff --git a/arch/c5471/include/types.h b/arch/c5471/include/types.h
new file mode 100644
index 0000000000..7b39302f0b
--- /dev/null
+++ b/arch/c5471/include/types.h
@@ -0,0 +1,70 @@
+/************************************************************
+ * types.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+/* This file should never be included directed but, rather,
+ * only indirectly through sys/types.h
+ */
+
+#ifndef __ARCH_C5471_TYPES_H
+#define __ARCH_C5471_TYPES_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Type Declarations
+ ************************************************************/
+
+typedef char sbyte;
+typedef unsigned char ubyte;
+typedef unsigned char uint8;
+typedef unsigned char boolean;
+typedef short sint16;
+typedef unsigned short uint16;
+typedef int sint32;
+typedef unsigned int uint32;
+typedef long long sint64;
+typedef unsigned long long uint64;
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#endif /* __ARCH_C5471_TYPES_H */
diff --git a/arch/c5471/ld.script b/arch/c5471/ld.script
new file mode 100644
index 0000000000..f8bdf630ed
--- /dev/null
+++ b/arch/c5471/ld.script
@@ -0,0 +1,107 @@
+/************************************************************
+ * ld.script
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+OUTPUT_ARCH(arm)
+ENTRY(_stext)
+SECTIONS
+{
+ /* Interrupt vector trampoline and command line parameters
+ * are provided in IRAM by the rrload bootloader. Vectors will be
+ * copied into _svectors from _vflashstart.
+ */
+
+ . = 0xffc00000;
+ _svectors = ABSOLUTE(.);
+
+ /* These are locations in IRAM where the rrload bootloader passes
+ * information to the running program
+ */
+
+ . = 0xffc00020;
+ __KernCommandLineMagicStr = .; /* magic pattern string == "kcmdline-->" */
+ . = 0xffc0002C; /* advance to .+strlen("kcmdline-->")+1 */
+ __KernCommandLineOverride = .; /* location of kernel command line string */
+
+ . = 0xffc00100;
+ __EtherMACMagicStr = .; /* magic pattern string == "etherMAC-->" */
+ . = 0xffc0010C; /* advance to .+strlen("etherMAC-->")+1 */
+ __EtherMAC = .;
+
+
+ /* The OS entry point is here */
+
+ . = 0x01030000;
+ .text : {
+ _stext = ABSOLUTE(.);
+ *(.text)
+ *(.fixup)
+ *(.gnu.warning)
+ *(.rodata)
+ *(.glue_7)
+ *(.glue_7t)
+ *(.got) /* Global offset table */
+ _etext = ABSOLUTE(.);
+ }
+
+ _eronly = ABSOLUTE(.); /* See below */
+ . = ALIGN(4096);
+
+ .data : {
+ _sdata = ABSOLUTE(.);
+ *(.data)
+ CONSTRUCTORS
+ _edata = ABSOLUTE(.);
+ }
+
+ .bss : { /* BSS */
+ _sbss = ABSOLUTE(.);
+ *(.bss)
+ *(COMMON)
+ _ebss = ABSOLUTE(.);
+ }
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_info 0 : { *(.debug_info) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ .debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/arch/c5471/setenv.sh b/arch/c5471/setenv.sh
new file mode 100755
index 0000000000..bb3bd49c5c
--- /dev/null
+++ b/arch/c5471/setenv.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# setenv.sh
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+if [ "$(basename $0)" = "setenv" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+if [ -z ${PATH_ORIG} ]; then export PATH_ORIG=${PATH}; fi
+
+WD=`pwd`
+export BUILDROOT_BIN=${WD}/../buildroot/build_arm_nofpu/staging_dir/bin
+export PATH=${BUILDROOT_BIN}:/sbin:/usr/sbin:${PATH_ORIG}
+
+echo "PATH : ${PATH}"
diff --git a/arch/c5471/src/Makefile b/arch/c5471/src/Makefile
new file mode 100644
index 0000000000..d5dc016e1e
--- /dev/null
+++ b/arch/c5471/src/Makefile
@@ -0,0 +1,79 @@
+############################################################
+# Makefile
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+
+-include $(TOPDIR)/Make.defs
+
+MKDEP = $(TOPDIR)/tools/mkdeps.sh
+CFLAGS += -I$(TOPDIR)/sched
+
+ASRCS = up_vectors.S up_saveusercontext.S up_fullcontextrestore.S
+AOBJS = $(ASRCS:.S=.o)
+
+CSRCS = up_initialize.c up_initialstate.c up_idle.c \
+ up_irq.c up_syscall.c up_dataabort.c up_prefetchabort.c \
+ up_undefinedinsn.c up_interruptcontext.c up_timerisr.c \
+ up_createstack.c up_usestack.c up_releasestack.c \
+ up_exit.c up_assert.c up_blocktask.c up_unblocktask.c \
+ up_releasepending.c up_reprioritizertr.c up_copystate.c \
+ up_schedulesigaction.c up_sigdeliver.c
+COBJS = $(CSRCS:.c=.o)
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+all: up_head.o libarch.a
+
+$(AOBJS) up_head.o: %.o: %.S
+ $(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
+
+$(COBJS): %.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+libarch.a: $(OBJS)
+ $(AR) rcs $@ $(OBJS)
+
+.depend: Makefile $(SRCS)
+ $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ touch $@
+
+depend: .depend
+
+clean:
+ rm -f libarch.a *.o *~
+
+distclean: clean
+ rm -f Make.dep .depend
+
+-include Make.dep
diff --git a/arch/c5471/src/c5471.h b/arch/c5471/src/c5471.h
new file mode 100644
index 0000000000..c7104be621
--- /dev/null
+++ b/arch/c5471/src/c5471.h
@@ -0,0 +1,376 @@
+/************************************************************
+ * c5471.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+#ifndef __C5471_H
+#define __C5471_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+# include
+#endif
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/* Arm7Tdmi *************************************************/
+
+/* CPSR bits */
+
+#define USR26_MODE 0x00
+#define FIQ26_MODE 0x01
+#define IRQ26_MODE 0x02
+#define SVC26_MODE 0x03
+#define USR_MODE 0x10
+#define FIQ_MODE 0x11
+#define IRQ_MODE 0x12
+#define SVC_MODE 0x13
+#define ABT_MODE 0x17
+#define UND_MODE 0x1b
+#define SYSTEM_MODE 0x1f
+#define MODE_MASK 0x1f
+#define T_BIT 0x20
+#define F_BIT 0x40
+#define I_BIT 0x80
+#define CC_V_BIT (1 << 28)
+#define CC_C_BIT (1 << 29)
+#define CC_Z_BIT (1 << 30)
+#define CC_N_BIT (1 << 31)
+
+/* UARTs ****************************************************/
+
+#define UART_IRDA_BASE 0xffff0800
+#define UART_MODEM_BASE 0xffff1000
+#define UARTn_IO_RANGE 0x00000800
+
+/* Common UART Registers. Expressed as offsets from the BASE address */
+
+#define UART_RHR_OFFS 0x00000000 /* Rcv Holding Register */
+#define UART_THR_OFFS 0x00000004 /* Xmit Holding Register */
+#define UART_FCR_OFFS 0x00000008 /* FIFO Control Register */
+#define UART_RFCR_OFFS 0x00000008 /* Rcv FIFO Control Register */
+#define UART_TFCR_OFFS 0x00000008 /* Xmit FIFO Control Register */
+#define UART_SCR_OFFS 0x0000000c /* Status Control Register */
+#define UART_LCR_OFFS 0x00000010 /* Line Control Register */
+#define UART_LSR_OFFS 0x00000014 /* Line Status Register */
+#define UART_SSR_OFFS 0x00000018 /* Supplementary Status Register */
+#define UART_MCR_OFFS 0x0000001c /* Modem Control Register */
+#define UART_MSR_OFFS 0x00000020 /* Modem Status Register */
+#define UART_IER_OFFS 0x00000024 /* Interrupt Enable Register */
+#define UART_ISR_OFFS 0x00000028 /* Interrupt Status Register */
+#define UART_EFR_OFFS 0x0000002c /* Enhanced Feature Register */
+#define UART_XON1_OFFS 0x00000030 /* XON1 Character Register */
+#define UART_XON2_OFFS 0x00000034 /* XON2 Character Register */
+#define UART_XOFF1_OFFS 0x00000038 /* XOFF1 Character Register */
+#define UART_XOFF2_OFFS 0x0000003c /* XOFF2 Character Register */
+#define UART_SPR_OFFS 0x00000040 /* Scratch-pad Register */
+#define UART_DIV_115K_OFFS 0x00000044 /* Divisor for baud generation */
+#define UART_DIV_BIT_RATE_OFFS 0x00000048 /* For baud rate generation */
+#define UART_TCR_OFFS 0x0000004c /* Transmission Control Register */
+#define UART_TLR_OFFS 0x00000050 /* Trigger Level Register */
+#define UART_MDR_OFFS 0x00000054 /* Mode Definition Register */
+
+/* Registers available only for the IrDA UART (absolute address). */
+
+#define UART_IRDA_MDR1 0xffff0854 /* Mode Definition Register 1 */
+#define UART_IRDA_MDR2 0xffff0858 /* Mode Definition Register 2 */
+#define UART_IRDA_TXFLL 0xffff085c /* LS Xmit Frame Length Register */
+#define UART_IRDA_TXFLH 0xffff0860 /* MS Xmit Frame Length Register */
+#define UART_IRDA_RXFLL 0xffff0864 /* LS Rcvd Frame Length Register */
+#define UART_IRDA_RXFLH 0xffff0868 /* MS Rcvd Frame Length Register */
+#define UART_IRDA_SFLSR 0xffff086c /* Status FIFO Line Status Reg */
+#define UART_IRDA_SFREGL 0xffff0870 /* LS Status FIFO Register */
+#define UART_IRDA_SFREGH 0xffff0874 /* MS Status FIFO Register */
+#define UART_IRDA_BLR 0xffff0878 /* Begin of File Length Register */
+#define UART_IRDA_PULSE_WIDTH 0xffff087c /* Pulse Width Register */
+#define UART_IRDA_ACREG 0xffff0880 /* Auxiliary Control Register */
+#define UART_IRDA_PULSE_START 0xffff0884 /* Start time of pulse */
+#define UART_IRDA_RX_W_PTR 0xffff0888 /* RX FIFO write pointer */
+#define UART_IRDA_RX_R_PTR 0xffff088c /* RX FIFO read pointer */
+#define UART_IRDA_TX_W_PTR 0xffff0890 /* TX FIFO write pointer */
+#define UART_IRDA_TX_R_PTR 0xffff0894 /* TX FIFO read pointer */
+#define UART_IRDA_STATUS_W_PTR 0xffff0898 /* Write pointer of status FIFO */
+#define UART_IRDA_STATUS_R_PTR 0xffff089c /* Read pointer of status FIFO */
+#define UART_IRDA_RESUME 0xffff08a0 /* Resume register */
+#define UART_IRDA_MUX 0xffff08a4 /* Selects UART_IRDA output mux */
+
+/* Registers available for the Modem UART (absolute addresses) */
+
+#define UART_MODEM_MDR 0xffff1054 /* Mode Definition Register */
+#define UART_MODEM_UASR 0xffff1058 /* UART Auto-baud Status Register */
+#define UART_MODEM_RDPTR_URX 0xffff105c /* RX FIFO Read Pointer Register */
+#define UART_MODEM_WRPTR_URX 0xffff1060 /* RX FIFO Write Pointer Register */
+#define UART_MODEM_RDPTR_UTX 0xffff1064 /* TX FIFO Read Pointer Register */
+#define UART_MODEM_WRPTR_UTX 0xffff1068 /* TX FIFO Write Pointer Register */
+
+/* UART Settings ********************************************/
+
+/* Miscellaneous UART settings. */
+
+#define UART_RX_FIFO_NOEMPTY 0x00000001
+#define UART_SSR_TXFULL 0x00000001
+#define UART_LSR_TREF 0x00000020
+
+#define UART_XMIT_FIFO_SIZE 64
+#define UART_IRDA_XMIT_FIFO_SIZE 64
+
+/* UART_LCR Register */
+ /* Bits 31-7: Reserved */
+#define UART_LCR_BOC 0x00000040 /* Bit 6: Break Control */
+ /* Bit 5: Parity Type 2 */
+#define UART_LCR_ParEven 0x00000010 /* Bit 4: Parity Type 1 */
+#define UART_LCR_ParOdd 0x00000000
+#define UART_LCR_ParEn 0x00000008 /* Bit 3: Paity Enable */
+#define UART_LCR_ParDis 0x00000000
+#define UART_LCR_2stop 0x00000004 /* Bit 2: Number of stop bits */
+#define UART_LCR_1stop 0x00000000
+#define UART_LCR_5bits 0x00000000 /* Bits 0-1: Word-length */
+#define UART_LCR_6bits 0x00000001
+#define UART_LCR_7bits 0x00000002
+#define UART_LCR_8bits 0x00000003
+
+#define UART_FCR_FTL 0x00000000
+#define UART_FCR_FIFO_EN 0x00000001
+#define UART_FCR_TX_CLR 0x00000002
+#define UART_FCR_RX_CLR 0x00000004
+
+#define UART_IER_RecvInt 0x00000001
+#define UART_IER_XmitInt 0x00000002
+#define UART_IER_LineStsInt 0x00000004
+#define UART_IER_ModemStsInt 0x00000008 /* IrDA UART only */
+#define UART_IER_XoffInt 0x00000020
+#define UART_IER_RtsInt 0x00000040 /* IrDA UART only */
+#define UART_IER_CtsInt 0x00000080 /* IrDA UART only */
+#define UART_IER_AllInts 0x000000ff
+
+#define BAUD_115200 0x00000001
+#define BAUD_57600 0x00000002
+#define BAUD_38400 0x00000003
+#define BAUD_19200 0x00000006
+#define BAUD_9600 0x0000000C
+#define BAUD_4800 0x00000018
+#define BAUD_2400 0x00000030
+#define BAUD_1200 0x00000060
+
+#define MDR_UART_MODE 0x00000000 /* Both IrDA and Modem UARTs */
+#define MDR_SIR_MODE 0x00000001 /* IrDA UART only */
+#define MDR_AUTOBAUDING_MODE 0x00000002 /* Modem UART only */
+#define MDR_RESET_MODE 0x00000007 /* Both IrDA and Modem UARTs */
+
+/* SPI ******************************************************/
+
+#define MAX_SPI 3
+
+#define SPI_REGISTER_BASE 0xffff2000
+
+/* GIO ******************************************************/
+
+#define MAX_GIO (35)
+
+#define GIO_REGISTER_BASE 0xffff2800
+
+#define GPIO_IO 0xffff2800 /* Writeable when I/O is configured
+ * as an output; reads value on I/O
+ * pin when I/O is configured as an
+ * input */
+#define GPIO_CIO 0xffff2804 /* GPIO configuration register */
+#define GPIO_IRQA 0xffff2808 /* In conjunction with GPIO_IRQB
+ * determines the behavior when GPIO
+ * pins configured as input IRQ */
+#define GPIO_IRQB 0xffff280c /* Determines the behavior when GPIO
+ * pins configured as input IRQ */
+#define GPIO_DDIO 0xffff2810 /* Delta Detect Register
+ * (detects changes in the I/O pins) */
+#define GPIO_EN 0xffff2814 /* Selects register for muxed GPIOs */
+
+#define KGIO_REGISTER_BASE 0xffff2900
+
+#define KBGPIO_IO 0xffff2900 /* Keyboard I/O bits: Writeable
+ * when KBGPIO is configured as an
+ * output; reads value on I/O pin
+ * when KBGPIO is configured as an
+ * input */
+#define KBGPIO_CIO 0xffff2904 /* KBGPIO configuration register */
+#define KBGPIO_IRQA 0xffff2908 /* In conjunction with KBGPIO_IRQB
+ * determines the behavior when
+ * KBGPIO pins configured as input
+ * IRQ */
+#define KBGPIO_IRQB 0xffff290c /* In conjunction with KBGPIO_IRQA
+ * determines the behavior when
+ * KBGPIO pins configured as input
+ * IRQ */
+#define KBGPIO_DDIO 0xffff2910 /* Delta Detect Register (detects
+ * changes in the KBGPIO pins) */
+#define KBGPIO_EN 0xffff2914 /* Selects register for muxed
+ * KBGPIOs */
+
+/* Timers ***************************************************/
+
+#define C5471_TIMER0_CTRL 0xffff2a00
+#define C5471_TIMER0_CNT 0xffff2a04
+#define C5471_TIMER1_CTRL 0xffff2b00
+#define C5471_TIMER1_CNT 0xffff2b04
+#define C5471_TIMER2_CTRL 0xffff2c00
+
+#define C5471_TIMER2_CNT 0xffff2c04
+
+/* Interrupts */
+
+#define HAVE_SRC_IRQ_BIN_REG 0
+
+#define INT_FIRST_IO 0xffff2d00
+#define INT_IO_RANGE 0x5C
+
+#define IT_REG 0xffff2d00
+#define MASK_IT_REG 0xffff2d04
+#define SRC_IRQ_REG 0xffff2d08
+#define SRC_FIQ_REG 0xffff2d0c
+#define SRC_IRQ_BIN_REG 0xffff2d10
+#define INT_CTRL_REG 0xffff2d18
+
+#define ILR_IRQ0_REG 0xffff2d1C /* 0-Timer 0 */
+#define ILR_IRQ1_REG 0xffff2d20 /* 1-Timer 1 */
+#define ILR_IRQ2_REG 0xffff2d24 /* 2-Timer 2 */
+#define ILR_IRQ3_REG 0xffff2d28 /* 3-GPIO0 */
+#define ILR_IRQ4_REG 0xffff2d2c /* 4-Ethernet */
+#define ILR_IRQ5_REG 0xffff2d30 /* 5-KBGPIO[7:0] */
+#define ILR_IRQ6_REG 0xffff2d34 /* 6-Uart serial */
+#define ILR_IRQ7_REG 0xffff2d38 /* 7-Uart IRDA */
+#define ILR_IRQ8_REG 0xffff2d3c /* 8-KBGPIO[15:8] */
+#define ILR_IRQ9_REG 0xffff2d40 /* 9-GPIO3 */
+#define ILR_IRQ10_REG 0xffff2d44 /* 10-GPIO2 */
+#define ILR_IRQ11_REG 0xffff2d48 /* 11-I2C */
+#define ILR_IRQ12_REG 0xffff2d4c /* 12-GPIO1 */
+#define ILR_IRQ13_REG 0xffff2d50 /* 13-SPI */
+#define ILR_IRQ14_REG 0xffff2d54 /* 14-GPIO[19:4] */
+#define ILR_IRQ15_REG 0xffff2d58 /* 15-API */
+
+/* I2C ******************************************************/
+
+#define MAX_I2C 1
+
+/* API ******************************************************/
+
+#define DSPRAM_BASE 0xffe00000 /* DSPRAM base address */
+#define DSPRAM_END 0xffe03fff
+
+/* This is the API address range in the DSP address space. */
+
+#define DSPMEM_DSP_START 0x2000
+#define DSPMEM_DSP_END 0x3fff
+
+/* This is the API address range in the ARM address space. */
+
+#define DSPMEM_ARM_START DSPRAM_BASE /* Defined in hardware.h */
+#define DSPMEM_ARM_END DSPRAM_END
+
+/* DSPMEM_IN_RANGE is a generic macro to test is a value is within
+ * a range of values.
+ */
+
+#define DSPMEM_IN_RANGE(addr, start, end) \
+ ((((__u32)(addr)) >= (start)) && (((__u32)(addr)) <= (end)))
+
+/* DSPMEM_ADDR_ALIGNED verifies that a potential DSP address is
+ * properly word aligned.
+ */
+
+#define DSPMEM_ADDR_ALIGNED(addr, cpu) ((((__u32)(addr)) & 1) == 0)
+
+/* DSPMEM_DSP_ADDR checks if a DSP address lies in within the
+ * DSP's API address range.
+ */
+
+#define DSPMEM_DSP_ADDR(addr, cpu) \
+ DSPMEM_IN_RANGE(addr, DSPMEM_DSP_START, DSPMEM_DSP_END)
+
+/* DSPMEM_ARM_ADDR checks if a ARM address lies in within the
+ * ARM's API address range.
+ */
+
+#define DSPMEM_ARM_ADDR(addr) \
+ DSPMEM_IN_RANGE(addr, DSPMEM_ARM_START, DSPMEM_ARM_END)
+
+/* DSPMEM_DSP_TO_ARM maps a DSP API address into an ARM API address */
+
+#define DSPMEM_DSP_TO_ARM(addr, cpu) \
+ ((((__u32)(addr) - DSPMEM_DSP_START) << 1) + DSPMEM_ARM_START)
+
+/* DSPMEM_ARM_TO_DSP maps an ARM API address into a DSP API address */
+
+#define DSPMEM_ARM_TO_DSP(addr) \
+ ((((__u32)(addr) - DSPMEM_ARM_START) >> 1) + DSPMEM_DSP_START)
+
+/************************************************************
+ * Inline Functions
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+
+# define getreg8(a) (*(volatile ubyte *)(a))
+# define putreg8(v,a) (*(volatile ubyte *)(a) = (v))
+# define getreg32(a) (*(volatile uint32 *)(a))
+# define putreg32(v,a) (*(volatile uint32 *)(a) = (v))
+
+
+/* Some compiler options will convert short loads and stores into byte loads
+ * and stores. We don't want this to happen for IO reads and writes!
+ */
+
+/* # define getreg16(a) (*(volatile uint16 *)(a)) */
+static inline unsigned short getreg16(unsigned int addr)
+{
+ unsigned short retval;
+ __asm__ __volatile__("\tldrh %0, [%1]\n\t" : "=r"(retval) : "r"(addr));
+ return retval;
+}
+
+/* define putreg16(v,a) (*(volatile uint16 *)(a) = (v)) */
+static inline void putreg16(uint16 val, unsigned int addr)
+{
+ __asm__ __volatile__("\tstrh %0, [%1]\n\t": : "r"(val), "r"(addr));
+}
+
+/* Most C5471 registers are 16-bits wide */
+
+#define getreg(a) getreg16(1)
+#define putreg(v,a) putreg16(v,a)
+
+#endif
+
+#endif /* __C5471_H */
diff --git a/arch/c5471/src/up_assert.c b/arch/c5471/src/up_assert.c
new file mode 100644
index 0000000000..eaddc7c8e1
--- /dev/null
+++ b/arch/c5471/src/up_assert.c
@@ -0,0 +1,82 @@
+/************************************************************
+ * up_assert.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_assert
+ ************************************************************/
+
+void up_assert(const ubyte *filename, uint32 lineno)
+{
+ dbg("Assertion failed at file:%s line: %d\n",
+ filename, lineno);
+ exit(EXIT_FAILURE);
+}
+
+/************************************************************
+ * Name: up_assert_code
+ ************************************************************/
+
+void up_assert_code(const ubyte *filename, uint32 lineno, uint16 errorcode)
+{
+ dbg("Assertion failed at file:%s line: %d error code: %d\n",
+ filename, lineno, errorcode);
+ exit(errorcode);
+}
diff --git a/arch/c5471/src/up_blocktask.c b/arch/c5471/src/up_blocktask.c
new file mode 100644
index 0000000000..6b42d42702
--- /dev/null
+++ b/arch/c5471/src/up_blocktask.c
@@ -0,0 +1,168 @@
+/************************************************************
+ * up_blocktask.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_block_task
+ *
+ * Description:
+ * The currently executing task at the head of
+ * the ready to run list must be stopped. Save its context
+ * and move it to the inactive list specified by task_state.
+ *
+ * Inputs:
+ * tcb: Refers to a task in the ready-to-run list (normally
+ * the task at the the head of the list). It most be
+ * stopped, its context saved and moved into one of the
+ * waiting task lists. It it was the task at the head
+ * of the ready-to-run list, then a context to the new
+ * ready to run task must be performed.
+ * task_state: Specifies which waiting task list should be
+ * hold the blocked task TCB.
+ *
+ ************************************************************/
+
+void up_block_task(_TCB *tcb, tstate_t task_state)
+{
+ /* Verify that the context switch can be performed */
+
+ if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) ||
+ (tcb->task_state > LAST_READY_TO_RUN_STATE))
+ {
+ PANIC(OSERR_BADBLOCKSTATE);
+ }
+ else
+ {
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+ boolean switch_needed;
+
+ dbg("Blocking TCB=%p\n", tcb);
+
+ /* Remove the tcb task from the ready-to-run list. If we
+ * are blocking the task at the head of the task list (the
+ * most likely case), then a context switch to the next
+ * ready-to-run task is needed. In this case, it should
+ * also be true that rtcb == tcb.
+ */
+
+ switch_needed = sched_removereadytorun(tcb);
+
+ /* Add the task to the specified blocked task list */
+
+ sched_addblocked(tcb, (tstate_t)task_state);
+
+ /* If there are any pending tasks, then add them to the g_readytorun
+ * task list now
+ */
+
+ if (g_pendingtasks.head)
+ {
+ switch_needed |= sched_mergepending();
+ }
+
+ /* Now, perform the context switch if one is needed */
+
+ if (switch_needed)
+ {
+ /* Are we in an interrupt handler? */
+
+ if (current_regs)
+ {
+ /* Yes, then we have to do things differently.
+ * Just copy the current_regs into the OLD rtcb.
+ */
+
+ up_copystate(rtcb->xcp.regs, current_regs);
+
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_copystate(current_regs, rtcb->xcp.regs);
+ }
+
+ /* Copy the user C context into the TCB at the (old) head of the
+ * g_readytorun Task list. if up_saveusercontext returns a non-zero
+ * value, then this is really the previously running task restarting!
+ */
+
+ else if (!up_saveusercontext(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_fullcontextrestore(rtcb->xcp.regs);
+ }
+ }
+ }
+}
diff --git a/arch/c5471/src/up_copystate.c b/arch/c5471/src/up_copystate.c
new file mode 100644
index 0000000000..8e8586699b
--- /dev/null
+++ b/arch/c5471/src/up_copystate.c
@@ -0,0 +1,75 @@
+/************************************************************
+ * up_copystate.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_undefinedinsn
+ ************************************************************/
+
+/* A little faster than most memcpy's */
+
+void up_copystate(uint32 *dest, uint32 *src)
+{
+ int i;
+ for (i = 0; i < XCPTCONTEST_REGS; i++)
+ {
+ *dest++ = *src++;
+ }
+}
+
diff --git a/arch/c5471/src/up_createstack.c b/arch/c5471/src/up_createstack.c
new file mode 100644
index 0000000000..20276bff09
--- /dev/null
+++ b/arch/c5471/src/up_createstack.c
@@ -0,0 +1,126 @@
+/************************************************************
+ * up_createstack.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Types
+ ************************************************************/
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_create_stack
+ *
+ * Description:
+ * Allocate a stack for a new thread and setup
+ * up stack-related information in the TCB.
+ *
+ * The following TCB fields must be initialized:
+ * adj_stack_size: Stack size after adjustment for hardware,
+ * processor, etc. This value is retained only for debug
+ * purposes.
+ * stack_alloc_ptr: Pointer to allocated stack
+ * adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
+ * initial value of the stack pointer.
+ *
+ * Inputs:
+ * tcb: The TCB of new task
+ * stack_size: The requested stack size. At least this much
+ * must be allocated.
+ ************************************************************/
+
+STATUS up_create_stack(_TCB *tcb, uint32 stack_size)
+{
+ if (tcb->stack_alloc_ptr &&
+ tcb->adj_stack_size != stack_size)
+ {
+ sched_free(tcb->stack_alloc_ptr);
+ tcb->stack_alloc_ptr = NULL;
+ }
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ tcb->stack_alloc_ptr = (uint32 *)kzmalloc(stack_size);
+ }
+
+ if (tcb->stack_alloc_ptr)
+ {
+ uint32 top_of_stack;
+ uint32 size_of_stack;
+
+ /* The Arm7Tdmi uses a push-down stack: the stack grows
+ * toward loweraddresses in memory. The stack pointer
+ * register, points to the lowest, valid work address
+ * (the "top" of the stack). Items on the stack are
+ * referenced as positive word offsets from sp.
+ */
+
+ top_of_stack = (uint32)tcb->stack_alloc_ptr + stack_size - 4;
+
+ /* The Arm7Tdmi stack must be aligned at word (4 byte)
+ * boundaries. If necessary top_of_stack must be rounded
+ * down to the next boundary
+ */
+
+ top_of_stack &= ~3;
+ size_of_stack = top_of_stack - (uint32)tcb->stack_alloc_ptr + 4;
+
+ /* Save the adjusted stack values in the _TCB */
+
+ tcb->adj_stack_size = top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ return OK;
+ }
+
+ return ERROR;
+}
diff --git a/arch/c5471/src/up_dataabort.c b/arch/c5471/src/up_dataabort.c
new file mode 100644
index 0000000000..ca1ade7238
--- /dev/null
+++ b/arch/c5471/src/up_dataabort.c
@@ -0,0 +1,68 @@
+/************************************************************
+ * up_dataabort.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_dataabort
+ ************************************************************/
+
+void up_dataabort(uint32 *regs)
+{
+ PANIC(OSERR_ERREXCEPTION);
+}
diff --git a/arch/c5471/src/up_exit.c b/arch/c5471/src/up_exit.c
new file mode 100644
index 0000000000..8e211e0c2e
--- /dev/null
+++ b/arch/c5471/src/up_exit.c
@@ -0,0 +1,111 @@
+/************************************************************
+ * up_exit.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: _exit
+ *
+ * Description:
+ * This function causes the currently executing task to cease
+ * to exist. This is a special case of task_delete().
+ *
+ ************************************************************/
+
+void _exit(int status)
+{
+ _TCB* tcb = (_TCB*)g_readytorun.head;
+
+ dbg("TCB=%p exitting\n", tcb);
+
+ /* Remove the tcb task from the ready-to-run list. We can
+ * ignore the return value because we know that a context
+ * switch is needed.
+ */
+
+ (void)sched_removereadytorun(tcb);
+
+ /* Move the TCB to the specified blocked task list and delete it */
+
+ sched_addblocked(tcb, TSTATE_TASK_INACTIVE);
+ task_delete(tcb->pid);
+
+ /* If there are any pending tasks, then add them to the g_readytorun
+ * task list now
+ */
+
+ if (g_pendingtasks.head)
+ {
+ (void)sched_mergepending();
+ }
+
+ /* Now, perform the context switch to the new ready-to-run task at the
+ * head of the list.
+ */
+
+ tcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", tcb);
+
+ /* Then switch contexts */
+
+ up_fullcontextrestore(tcb->xcp.regs);
+}
+
diff --git a/arch/c5471/src/up_fullcontextrestore.S b/arch/c5471/src/up_fullcontextrestore.S
new file mode 100644
index 0000000000..c4b230316c
--- /dev/null
+++ b/arch/c5471/src/up_fullcontextrestore.S
@@ -0,0 +1,115 @@
+/**************************************************************************
+ * up_fullcontextrestore.S
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include "up_internal.h"
+
+/**************************************************************************
+ * Private Definitions
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Types
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Function Prototypes
+ **************************************************************************/
+
+/**************************************************************************
+ * Global Variables
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Variables
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Functions
+ **************************************************************************/
+
+/**************************************************************************
+ * Public Functions
+ **************************************************************************/
+
+/**************************************************************************
+ * Name: up_fullcontextrestore
+ **************************************************************************/
+
+ .globl up_fullcontextrestore
+ .type up_fullcontextrestore, function
+up_fullcontextrestore:
+
+ /* On entry, a1 (r0) holds address of the register save area */
+
+ /* Restore the volatile registers. This is not necessary for
+ * normally task-to-task context switches (where the context
+ * was saved by up_saveusercontext()), but is necesary when
+ * the full context was saved through interrupt handling.
+ */
+
+ /* Recover the user context (we will then have a new stack pointer) */
+
+ add r1, r0, #XCPTCONTEXT_UOFFSET
+ ldmia r1, {r3-r11, r13-r14}
+
+ /* Save the CSPR value and one scratch register on the stack */
+
+ sub sp, sp, #2*4 /* Create a frame to hold two regs */
+ stmia sp, {r3, r4} /* Save the CPSR (r3) and scratch (r4) */
+
+ /* Then recover the remaining registers */
+
+ ldmia r0, {r0-r3, r12} /* Recover volatile regs */
+
+ /* Now we can restore the CPSR (probably re-enabling interrupts) */
+
+ ldr r4, [sp]
+ msr cpsr, r4
+
+ /* Then recover the correct r4 value */
+
+ ldr r4, [sp, #4]
+
+ /* Destroy the temporary stack frame and return */
+
+ add sp, sp, #2*4
+ movs pc, lr
+ .size up_fullcontextrestore, . - up_fullcontextrestore
+
diff --git a/arch/c5471/src/up_head.S b/arch/c5471/src/up_head.S
new file mode 100644
index 0000000000..f4540c54b6
--- /dev/null
+++ b/arch/c5471/src/up_head.S
@@ -0,0 +1,125 @@
+/************************************************************
+ * up_head.S
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include "c5471.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * OS Entry Point
+ ************************************************************/
+
+/* We assume the bootloader has already initialized most of the h/w for
+ * us and that only leaves us having to do some os specific things
+ * below.
+ */
+ .global __start
+ .type __start, #function
+__start:
+
+/* First, setup initial processor mode */
+
+ mov r0, #(SVC_MODE | I_BIT | F_BIT )
+ msr cpsr, r0
+
+/* Setup system stack (and get the BSS range) */
+
+ adr r0, LC0
+ ldmia r0, {r4, r5, sp}
+
+/* Clear system BSS section */
+
+ mov r0, #0
+1: cmp r4, r5
+ strcc r0, [r4], #4
+ bcc 1b
+
+/* Copy system .data sections to new home in RAM. */
+
+#ifdef CONFIG_BOOT_FROM_FLASH
+
+ adr r3, LC2
+ ldmia r3, {r0, r1, r2}
+
+1: ldmia r0!, {r3 - r10}
+ stmia r1!, {r3 - r10}
+ cmp r1, r2
+ blt 1b
+
+#endif
+
+/* Initialize Kernel Stack Contents */
+
+#if 0
+ mov r1, sp
+ sub r1, r1, #INITIAL_STACK_SIZE
+ ldr r0, L_STACK_MAGIC
+ str r0, [r1], #4
+ ldr r0, L_STACK_UNTOUCHED_MAGIC
+1: cmp r1, sp
+ strcc r0, [r1], #4
+ bcc 1b
+#endif
+
+/* Jump to OS entry */
+
+ mov fp, #0
+ b os_start
+
+/* Variables */
+
+LC0: .long _sbss
+ .long _ebss
+ .long CONFIG_STACK_POINTER+CONFIG_PROC_STACK_SIZE-4
+
+#ifdef CONFIG_BOOT_FROM_FLASH
+LC2: .long _eronly @ Where .data defaults are stored in Flash.
+ .long _sdata @ Where .data needs to reside in SDRAM.
+ .long _edata
+#endif
+
+#if 0
+L_STACK_UNTOUCHED_MAGIC: .long 0xfeef1ef0
+L_STACK_MAGIC: .long 0xdeadbeef
+#endif
+ .end
+
diff --git a/arch/c5471/src/up_idle.c b/arch/c5471/src/up_idle.c
new file mode 100644
index 0000000000..46177a3de8
--- /dev/null
+++ b/arch/c5471/src/up_idle.c
@@ -0,0 +1,79 @@
+/************************************************************
+ * up_idle.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_idle
+ *
+ * Description:
+ * up_idle() is the logic that will be executed when their
+ * is no other ready-to-run task. This is processor idle
+ * time and will continue until some interrupt occurs to
+ * cause a context switch from the idle task.
+ *
+ * Processing in this state may be processor-specific. e.g.,
+ * this is where power management operations might be
+ * performed.
+ *
+ ************************************************************/
+
+void up_idle(void)
+{
+}
+
diff --git a/arch/c5471/src/up_initialize.c b/arch/c5471/src/up_initialize.c
new file mode 100644
index 0000000000..660cf44d72
--- /dev/null
+++ b/arch/c5471/src/up_initialize.c
@@ -0,0 +1,93 @@
+/************************************************************
+ * up_initialize.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Types
+ ************************************************************/
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_initialize
+ *
+ * Description:
+ * up_initialize will be called once during OS
+ * initialization after the basic OS services have been
+ * initialized. The architecture specific details of
+ * initializing the OS will be handled here. Such things as
+ * setting up interrupt service routines, starting the
+ * clock, and registering device drivers are some of the
+ * things that are different for each processor and hardware
+ * platform.
+ *
+ * up_initialize is called after the OS initialized but
+ * before the init process has been started and before the
+ * libraries have been initialized. OS services and driver
+ * services are available.
+ *
+ ************************************************************/
+
+void up_initialize(void)
+{
+ /* Initialize global variables */
+
+ current_regs = NULL;
+
+ /* Initialize the interrupt subsystem */
+
+ up_irqinitialize();
+
+ /* Attach and enable the timer interrupt */
+
+ up_disable_irq(C5471_IRQ_SYSTIMER);
+ irq_attach(C5471_IRQ_SYSTIMER, (xcpt_t)up_timerisr);
+ up_enable_irq(C5471_IRQ_SYSTIMER);
+}
diff --git a/arch/c5471/src/up_initialstate.c b/arch/c5471/src/up_initialstate.c
new file mode 100644
index 0000000000..3a26c45f1a
--- /dev/null
+++ b/arch/c5471/src/up_initialstate.c
@@ -0,0 +1,85 @@
+/************************************************************
+ * up_initialstate.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_initial_state
+ *
+ * Description:
+ * A new thread is being started and a new TCB
+ * has been created. This function is called to initialize
+ * the processor specific portions of the new TCB.
+ *
+ * This function must setup the intial architecture registers
+ * and/or stack so that execution will begin at tcb->start
+ * on the next context switch.
+ *
+ ************************************************************/
+
+void up_initial_state(_TCB *tcb)
+{
+ struct xcptcontext *xcp = &tcb->xcp;
+
+ /* Initialize the initial exception register context structure */
+
+ memset(xcp, 0, sizeof(struct xcptcontext));
+ xcp->regs[JB_SP] = (uint32)tcb->adj_stack_ptr;
+ xcp->regs[JB_LR] = (uint32)tcb->start;
+}
diff --git a/arch/c5471/src/up_internal.h b/arch/c5471/src/up_internal.h
new file mode 100644
index 0000000000..d3e806d12b
--- /dev/null
+++ b/arch/c5471/src/up_internal.h
@@ -0,0 +1,99 @@
+/************************************************************
+ * up_internal.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+#ifndef __UP_INTERNAL_H
+#define __UP_INTERNAL_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+typedef void (*up_vector_t)(void);
+#endif
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+extern uint32 *current_regs;
+#endif
+
+/************************************************************
+ * Inline Functions
+ ************************************************************/
+
+
+/************************************************************
+ * Public Functions
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/* Defined in files with the same name as the function */
+
+extern void up_copystate(uint32 *dest, uint32 *src);
+extern void up_dataabort(uint32 *regs);
+extern void up_fullcontextrestore(uint32 *regs) __attribute__ ((noreturn));
+extern void up_irqinitialize(void);
+extern void up_prefetchabort(uint32 *regs);
+extern int up_saveusercontext(uint32 *regs);
+extern void up_sigdeliver(void);
+extern void up_syscall(uint32 *regs);
+extern int up_timerisr(int irq, uint32 *regs);
+extern void up_undefinedinsn(uint32 *regs);
+
+/* Defined in up_vectors.S */
+
+extern void up_vectorundefinsn(void);
+extern void up_vectorswi(void);
+extern void up_vectorprefetch(void);
+extern void up_vectordata(void);
+extern void up_vectoraddrexcptn(void);
+extern void up_vectorirq(void);
+extern void up_vectorfiq(void);
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __UP_INTERNAL_H */
diff --git a/arch/c5471/src/up_interruptcontext.c b/arch/c5471/src/up_interruptcontext.c
new file mode 100644
index 0000000000..b6df69ea4c
--- /dev/null
+++ b/arch/c5471/src/up_interruptcontext.c
@@ -0,0 +1,68 @@
+/************************************************************
+ * up_interruptcontext.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Types
+ ************************************************************/
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_interrupt_context
+ *
+ * Description: Return TRUE is we are currently executing in
+ * the interrupt handler context.
+ ************************************************************/
+
+boolean up_interrupt_context(void)
+{
+ return current_regs != NULL;
+}
diff --git a/arch/c5471/src/up_irq.c b/arch/c5471/src/up_irq.c
new file mode 100644
index 0000000000..d388f6446a
--- /dev/null
+++ b/arch/c5471/src/up_irq.c
@@ -0,0 +1,243 @@
+/************************************************************
+ * up_irq.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include "c5471.h"
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#define EdgeSensitive 0x00000020
+#define Priority 0x0000001E
+
+/************************************************************
+ * Public Data
+ ************************************************************/
+
+uint32 *current_regs;
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/* The value of _vflashstart is defined in ld.script. It
+ * could be hard-coded because we know that correct IRAM
+ * area is 0xffc00000.
+ */
+
+extern int _svectors; /* Type does not matter */
+
+/* The C5471 has FLASH at the low end of memory. The
+ * rrload bootloaer will catch all interrupts and re-vector
+ * them to vectors stored in IRAM. The following table is
+ * used to initialize those vectors.
+ */
+
+static up_vector_t g_vectorinittab[] =
+{
+ (up_vector_t)NULL,
+ up_vectorundefinsn,
+ up_vectorswi,
+ up_vectorprefetch,
+ up_vectordata,
+ up_vectoraddrexcptn,
+ up_vectorirq,
+ up_vectorfiq
+};
+#define NVECTORS ((sizeof(g_vectorinittab)) / sizeof(up_vector_t))
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_ackirq
+ *
+ * Description:
+ * Acknowlede the IRQ.Bit 0 of the Interrupt Control
+ * Register == New IRQ agreement (NEW_IRQ_AGR). Reset IRQ
+ * output. Clear source IRQ register. Enables a new IRQ
+ * generation. Reset by internal logic.
+ *
+ ************************************************************/
+
+static inline void up_ackirq(unsigned int irq)
+{
+ uint32 reg;
+ reg = getreg32(SRC_IRQ_REG); /* Insure appropriate IT_REG bit clears */
+ putreg32(reg | 0x00000001, INT_CTRL_REG); /* write the NEW_IRQ_AGR bit. */
+}
+
+/************************************************************
+ * Name: up_ackfiq
+ *
+ * Description:
+ * Acknowledge the FIQ. Bit 1 of the Interrupt Control
+ * Register == New FIQ agreement (NEW_FIQ_AGR). Reset FIQ
+ * output. Clear source FIQ register. Enables a new FIQ
+ * generation. Reset by internal logic.
+ *
+ ************************************************************/
+
+static inline void up_ackfiq(unsigned int irq)
+{
+ uint32 reg;
+ reg = getreg32(SRC_FIQ_REG); /* Insure appropriate IT_REG bit clears */
+ putreg32(reg | 0x00000002, INT_CTRL_REG); /* write the NEW_FIQ_AGR bit. */
+}
+
+/************************************************************
+ * Name: up_vectorinitialize
+ ************************************************************/
+
+static inline void up_vectorinitialize(void)
+{
+ up_vector_t *src = g_vectorinittab;
+ up_vector_t *dest = (up_vector_t*)&_svectors;
+ int i;
+ for (i = 0; i < NVECTORS; i++)
+ {
+ *dest++ = *src++;
+ }
+}
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: irq_initialize
+ ************************************************************/
+
+void up_irqinitialize(void)
+{
+ /* Disable all interrupts. */
+
+ putreg32(0x0000ffff, MASK_IT_REG);
+
+ /* Clear any pending interrupts */
+
+ up_ackirq(0);
+ up_ackfiq(0);
+ putreg32(0x00000000, IT_REG);
+
+ /* Override hardware defaults */
+
+ putreg32(EdgeSensitive | Priority, ILR_IRQ2_REG);
+ putreg32(EdgeSensitive | Priority, ILR_IRQ4_REG);
+ putreg32(Priority, ILR_IRQ6_REG);
+ putreg32(EdgeSensitive | Priority, ILR_IRQ15_REG);
+
+ /* Initialize hardware interrupt vectors */
+
+ up_vectorinitialize();
+ current_regs = NULL;
+
+ /* And finally, enable interrupts */
+
+ irqrestore(SVC_MODE | F_BIT);
+}
+
+/************************************************************
+ * Name: up_disable_irq
+ *
+ * Description:
+ * Disable the IRQ specified by 'irq'
+ *
+ ************************************************************/
+
+void up_disable_irq(int irq)
+{
+ if (irq < NR_IRQS)
+ {
+ uint32 reg = getreg32(MASK_IT_REG);
+ putreg32(reg | (1 << irq), MASK_IT_REG);
+ }
+}
+
+/************************************************************
+ * Name: up_enable_irq
+ *
+ * Description:
+ * Enable the IRQ specified by 'irq'
+ *
+ ************************************************************/
+
+void up_enable_irq(int irq)
+{
+ if (irq < NR_IRQS)
+ {
+ uint32 reg = getreg32(MASK_IT_REG);
+ putreg32(reg & ~(1 << irq), MASK_IT_REG);
+ }
+}
+
+/************************************************************
+ * Name: up_acknowledge_irq
+ *
+ * Description:
+ * Disable the IRQ specified by 'irq'
+ *
+ ************************************************************/
+
+/* Bit 0 of the Interrupt Control Rigster == New IRQ
+ * agreement (NEW_IRQ_AGR). Reset IRQ output. Clear source
+ * IRQ register. Enables a new IRQ generation. Reset by
+ * internal logic.
+ *
+ * IRQ (FIQ) output and SRC_IRQ_REG and SRC_IRQ_BIN_REG
+ * (SRC_FIQ_REG) registers are reset only if the bit in the
+ * Interrupt register (IT_REG) corresponding to the interrupt
+ * having requested MCU action is already cleared or masked.
+ *
+ * For an edge-sensitive interrupt, the Interrupt register bit is
+ * deactivated when reading the SRC_IRQ_REG or SRC_IRQ_BIN_REG
+ * (SRC_FIQ_REG) registers.
+ */
+
+void up_acknowledge_irq(int irq)
+{
+ uint32 reg = getreg32(INT_CTRL_REG);
+ putreg32(reg | 0x00000001, INT_CTRL_REG); /* write the NEW_IRQ_AGR bit. */
+}
diff --git a/arch/c5471/src/up_prefetchabort.c b/arch/c5471/src/up_prefetchabort.c
new file mode 100644
index 0000000000..7756b7c351
--- /dev/null
+++ b/arch/c5471/src/up_prefetchabort.c
@@ -0,0 +1,69 @@
+/************************************************************
+ * up_prefetchabort.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_prefetchabort
+ ************************************************************/
+
+void up_prefetchabort(uint32 *regs)
+{
+ PANIC(OSERR_ERREXCEPTION);
+}
diff --git a/arch/c5471/src/up_releasepending.c b/arch/c5471/src/up_releasepending.c
new file mode 100644
index 0000000000..c1b5a88509
--- /dev/null
+++ b/arch/c5471/src/up_releasepending.c
@@ -0,0 +1,131 @@
+/************************************************************
+ * up_releasepending.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_release_pending
+ *
+ * Description:
+ * Release and ready-to-run tasks that have
+ * collected in the pending task list. This can call a
+ * context switch if a new task is placed at the head of
+ * the ready to run list.
+ *
+ ************************************************************/
+
+void up_release_pending(void)
+{
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+
+ dbg("From TCB=%p\n", rtcb);
+
+ /* Merge the g_pendingtasks list into the g_readytorun task list */
+
+ /* sched_lock(); */
+ if (sched_mergepending())
+ {
+ /* The currently active task has changed! We will need to
+ * switch contexts. First check if we are operating in
+ * interrupt context:
+ */
+
+ if (current_regs)
+ {
+ /* Yes, then we have to do things differently.
+ * Just copy the current_regs into the OLD rtcb.
+ */
+
+ up_copystate(rtcb->xcp.regs, current_regs);
+
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_copystate(current_regs, rtcb->xcp.regs);
+ }
+
+ /* Copy the exception context into the TCB of the task that
+ * was currently active. if up_saveusercontext returns a non-zero
+ * value, then this is really the previously running task
+ * restarting!
+ */
+
+ else if (!up_saveusercontext(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_fullcontextrestore(rtcb->xcp.regs);
+ }
+ }
+}
diff --git a/arch/c5471/src/up_releasestack.c b/arch/c5471/src/up_releasestack.c
new file mode 100644
index 0000000000..e300c93bf5
--- /dev/null
+++ b/arch/c5471/src/up_releasestack.c
@@ -0,0 +1,78 @@
+/************************************************************
+ * up_releasestack.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Types
+ ************************************************************/
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_release_stack
+ *
+ * Description:
+ * A task has been stopped. Free all stack
+ * related resources retained int the defunct TCB.
+ *
+ ************************************************************/
+
+void up_release_stack(_TCB *dtcb)
+{
+ if (dtcb->stack_alloc_ptr)
+ {
+ sched_free(dtcb->stack_alloc_ptr);
+ dtcb->stack_alloc_ptr = NULL;
+ }
+
+ dtcb->adj_stack_size = 0;
+}
diff --git a/arch/c5471/src/up_reprioritizertr.c b/arch/c5471/src/up_reprioritizertr.c
new file mode 100644
index 0000000000..414b410d06
--- /dev/null
+++ b/arch/c5471/src/up_reprioritizertr.c
@@ -0,0 +1,178 @@
+/************************************************************
+ * up_reprioritizertr.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_reprioritize_rtr
+ *
+ * Description:
+ * Called when the priority of a running or
+ * ready-to-run task changes and the reprioritization will
+ * cause a context switch. Two cases:
+ *
+ * 1) The priority of the currently running task drops and the next
+ * task in the ready to run list has priority.
+ * 2) An idle, ready to run task's priority has been raised above the
+ * the priority of the current, running task and it now has the
+ * priority.
+ *
+ * Inputs:
+ * tcb: The TCB of the task that has been reprioritized
+ * priority: The new task priority
+ *
+ ************************************************************/
+
+void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
+{
+ /* Verify that the caller is sane */
+
+ if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
+ tcb->task_state > LAST_READY_TO_RUN_STATE ||
+ priority < SCHED_PRIORITY_MIN ||
+ priority > SCHED_PRIORITY_MAX)
+ {
+ PANIC(OSERR_BADREPRIORITIZESTATE);
+ }
+ else
+ {
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+ boolean switch_needed;
+
+ dbg("TCB=%p PRI=%d\n", tcb, priority);
+
+ /* Remove the tcb task from the ready-to-run list.
+ * sched_removereadytorun will return TRUE if we just
+ * remove the head of the ready to run list.
+ */
+
+ switch_needed = sched_removereadytorun(tcb);
+
+ /* Setup up the new task priority */
+
+ tcb->sched_priority = (ubyte)priority;
+
+ /* Return the task to the specified blocked task list.
+ * sched_addreadytorun will return TRUE if the task was
+ * added to the new list. We will need to perform a context
+ * switch only if the EXCLUSIVE or of the two calls is non-zero
+ * (i.e., one and only one the calls changes the head of the
+ * ready-to-run list).
+ */
+
+ switch_needed ^= sched_addreadytorun(tcb);
+
+ /* Now, perform the context switch if one is needed */
+
+ if (switch_needed)
+ {
+ /* If we are going to do a context switch, then now is the right
+ * time to add any pending tasks back into the ready-to-run list.
+ * task list now
+ */
+
+ if (g_pendingtasks.head)
+ {
+ sched_mergepending();
+ }
+
+ /* Are we in an interrupt handler? */
+
+ if (current_regs)
+ {
+ /* Yes, then we have to do things differently.
+ * Just copy the current_regs into the OLD rtcb.
+ */
+
+ up_copystate(rtcb->xcp.regs, current_regs);
+
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_copystate(current_regs, rtcb->xcp.regs);
+ }
+ /* Copy the exception context into the TCB at the (old) head of the
+ * g_readytorun Task list. if up_saveusercontext returns a non-zero
+ * value, then this is really the previously running task restarting!
+ */
+
+ if (!up_saveusercontext(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_fullcontextrestore(rtcb->xcp.regs);
+ }
+ }
+ }
+}
diff --git a/arch/c5471/src/up_saveusercontext.S b/arch/c5471/src/up_saveusercontext.S
new file mode 100644
index 0000000000..b9a9c2501d
--- /dev/null
+++ b/arch/c5471/src/up_saveusercontext.S
@@ -0,0 +1,121 @@
+/**************************************************************************
+ * up_saveusercontext.S
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include "up_internal.h"
+
+/**************************************************************************
+ * Private Definitions
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Types
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Function Prototypes
+ **************************************************************************/
+
+/**************************************************************************
+ * Global Variables
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Variables
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Functions
+ **************************************************************************/
+
+/**************************************************************************
+ * Public Functions
+ **************************************************************************/
+
+/**************************************************************************
+ * Name: up_saveusercontext
+ **************************************************************************/
+
+ .text
+ .globl up_saveusercontext
+ .type up_saveusercontext, function
+up_saveusercontext:
+ /* On entry, a1 (r0) holds address of struct xcptcontext.
+ * Offset to the user region.
+ */
+
+ /* Make sure that the return value will be non-zero (the
+ * value of the other volatile registers don't matter --
+ * r1-r3, ip). This function is called throught the
+ * noraml C calling conventions and the values of these
+ * registers cannot be assumed at the point of setjmp
+ * return.
+ */
+
+ mov ip, #1
+ str ip, [r0, #JB_R0]
+
+ /* Get the offset to the user save area */
+
+ add r0, r0, #XCPTCONTEXT_UOFFSET
+
+ /* Get the current cpsr as well */
+
+ mrs r3, cpsr /* R3 = CPSR value */
+
+ /* We need to save:
+ *
+ * Volatile register: r3 (holds the cpsr value)
+ * Static registers: v1-v7 (aka r4-r10)
+ * Frame pointer: fp (aka r11)
+ * Stack pointer: sp (aka r13)
+ * Return address: lr (aka r14)
+ *
+ * These have to be save in the same order as is done
+ * by the interrupt handling logic.
+ */
+
+ stmia r0, {r3-r11, r13-r14}
+
+ /* Return 0 */
+
+ mov r0, #0 /* Return value == 0 */
+ mov pc, lr /* Return */
+ .size up_saveusercontext, . - up_saveusercontext
+
diff --git a/arch/c5471/src/up_schedulesigaction.c b/arch/c5471/src/up_schedulesigaction.c
new file mode 100644
index 0000000000..7fa92e49ff
--- /dev/null
+++ b/arch/c5471/src/up_schedulesigaction.c
@@ -0,0 +1,186 @@
+/************************************************************
+ * up_schedulesigaction.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+#include "c5471.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_schedule_sigaction
+ *
+ * Description:
+ * This function is called by the OS when one or more
+ * signal handling actions have been queued for execution.
+ * The architecture specific code must configure things so
+ * that the 'igdeliver' callback is executed on the thread
+ * specified by 'tcb' as soon as possible.
+ *
+ * This function may be called from interrupt handling logic.
+ *
+ * This operation should not cause the task to be unblocked
+ * nor should it cause any immediate execution of sigdeliver.
+ * Typically, a few cases need to be considered:
+ *
+ * (1) This function may be called from an interrupt handler
+ * During interrupt processing, all xcptcontext structures
+ * should be valid for all tasks. That structure should
+ * be modified to invoke sigdeliver() either on return
+ * from (this) interrupt or on some subsequent context
+ * switch to the recipient task.
+ * (2) If not in an interrupt handler and the tcb is NOT
+ * the currently executing task, then again just modify
+ * the saved xcptcontext structure for the recipient
+ * task so it will invoke sigdeliver when that task is
+ * later resumed.
+ * (3) If not in an interrupt handler and the tcb IS the
+ * currently executing task -- just call the signal
+ * handler now.
+ *
+ ************************************************************/
+
+void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver)
+{
+ /* Refuse to handle nested signal actions */
+
+ if (!tcb->xcp.sigdeliver)
+ {
+ uint32 flags;
+
+ /* Make sure that interrupts are disabled */
+
+ flags = irqsave();
+
+ /* First, handle some special cases when the signal is
+ * being delivered to the currently executing task.
+ */
+
+ if (tcb == (_TCB*)g_readytorun.head)
+ {
+ /* CASE 1: We are not in an interrupt handler and
+ * a task is signalling itself for some reason.
+ */
+
+ if (!current_regs)
+ {
+ /* In this case just deliver the signal now. */
+
+ sigdeliver(tcb);
+ }
+
+ /* CASE 2: We are in an interrupt handler AND the
+ * interrupted task is the same as the one that
+ * must receive the signal, then we will have to modify
+ * the return state as well as the state in the TCB.
+ */
+
+ else
+ {
+ /* Save the return lr and cpsr and one scratch register
+ * These will be restored by the signal trampoline after
+ * the signals have been delivered.
+ */
+
+ tcb->xcp.sigdeliver = sigdeliver;
+ tcb->xcp.saved_lr = current_regs[JB_LR];
+ tcb->xcp.saved_cpsr = current_regs[JB_CPSR];
+
+ /* Then set up to vector to the trampoline with interrupts
+ * disabled
+ */
+
+ current_regs[JB_LR] = (uint32)up_sigdeliver;
+ current_regs[JB_CPSR] = SVC_MODE | I_BIT | F_BIT;
+
+ /* And make sure that the saved context in the TCB
+ * is the same as the interrupt return context.
+ */
+
+ up_copystate(tcb->xcp.regs, current_regs);
+ }
+ }
+
+ /* Otherwise, we are (1) signaling a task is not running
+ * from an interrupt handler or (2) we are not in an
+ * interrupt handler and the running task is signalling
+ * some non-running task.
+ */
+
+ else
+ {
+ /* Save the return lr and cpsr and one scratch register
+ * These will be restored by the signal trampoline after
+ * the signals have been delivered.
+ */
+
+ tcb->xcp.sigdeliver = sigdeliver;
+ tcb->xcp.saved_lr = tcb->xcp.regs[JB_LR];
+ tcb->xcp.saved_cpsr = tcb->xcp.regs[JB_CPSR];
+
+ /* Then set up to vector to the trampoline with interrupts
+ * disabled
+ */
+
+ tcb->xcp.regs[JB_LR] = (uint32)up_sigdeliver;
+ tcb->xcp.regs[JB_CPSR] = SVC_MODE | I_BIT | F_BIT;
+ }
+
+ irqrestore(flags);
+ }
+}
diff --git a/arch/c5471/src/up_sigdeliver.c b/arch/c5471/src/up_sigdeliver.c
new file mode 100644
index 0000000000..00b38a9dd4
--- /dev/null
+++ b/arch/c5471/src/up_sigdeliver.c
@@ -0,0 +1,117 @@
+/************************************************************
+ * up_sigdeliver.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+#include "c5471.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_sigdeliver
+ *
+ * Description:
+ * This is the a signal handling trampoline. When a
+ * signal action was posted. The task context was mucked
+ * with and forced to branch to this location with interrupts
+ * disabled.
+ *
+ ************************************************************/
+
+void up_sigdeliver(void)
+{
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+ uint32 regs[XCPTCONTEST_REGS];
+ sig_deliver_t sigdeliver;
+
+ ASSERT(rtcb->xcp.sigdeliver);
+
+ /* Save the real return state on the stack. */
+
+ up_copystate(regs, rtcb->xcp.regs);
+ regs[JB_LR] = rtcb->xcp.saved_lr;
+ regs[JB_CPSR] = rtcb->xcp.saved_cpsr;
+
+ /* Get a local copy of the sigdeliver function pointer.
+ * we do this so that we can nullify the sigdeliver
+ * function point in the TCB and accept more signal
+ * deliveries while processing the current pending
+ * signals.
+ */
+
+ sigdeliver = rtcb->xcp.sigdeliver;
+ rtcb->xcp.sigdeliver = NULL;
+
+ /* Then enable interrupts. We should still be safe from
+ * any further signal handling actions until we also
+ * nullify tcb->xcp.sigdeliver.
+ */
+
+ irqrestore(SVC_MODE | F_BIT);
+
+ /* Deliver the signals */
+
+ sigdeliver(rtcb);
+
+ /* Then restore the correct state for this thread of
+ * execution.
+ */
+
+ up_fullcontextrestore(regs);
+}
diff --git a/arch/c5471/src/up_syscall.c b/arch/c5471/src/up_syscall.c
new file mode 100644
index 0000000000..be4cee7459
--- /dev/null
+++ b/arch/c5471/src/up_syscall.c
@@ -0,0 +1,82 @@
+/************************************************************
+ * up_syscall.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include "c5471.h"
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * vectors
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Public Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_syscall
+ *
+ * Description:
+ * SWI interrupts will vection here with insn=the SWI
+ * instruction and xcp=the interrupt context
+ *
+ * The handler may get the SWI number be de-referencing
+ * the return address saved in the xcp and decoding
+ * the SWI instruction
+ *
+ ************************************************************/
+
+void up_syscall(uint32 *regs)
+{
+ PANIC(OSERR_ERREXCEPTION);
+}
diff --git a/arch/c5471/src/up_timerisr.c b/arch/c5471/src/up_timerisr.c
new file mode 100644
index 0000000000..b636d10844
--- /dev/null
+++ b/arch/c5471/src/up_timerisr.c
@@ -0,0 +1,93 @@
+/************************************************************
+ * up_timerisr.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Types
+ ************************************************************/
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Functions
+ ************************************************************/
+
+/************************************************************
+ * Function: timer_isr
+ *
+ * Description:
+ * The timer ISR will perform a variety of services for
+ * various portions of the systems.
+ *
+ ************************************************************/
+
+int up_timerisr(int irq, uint32 *regs)
+{
+ uint32 *saved_regs;
+
+ /* Save the pointer to the interrupted context (exercising some
+ * logic for the unexpected case of nested interrupts).
+ */
+
+ if (!current_regs)
+ {
+ saved_regs = NULL;
+ current_regs = regs;
+ }
+ else
+ {
+ saved_regs = current_regs;
+ }
+
+ /* Process timer interrupt */
+
+ sched_process_timer();
+
+ /* Restore the previous context */
+
+ current_regs = saved_regs;
+ return 0;
+}
diff --git a/arch/c5471/src/up_unblocktask.c b/arch/c5471/src/up_unblocktask.c
new file mode 100644
index 0000000000..98cc042baa
--- /dev/null
+++ b/arch/c5471/src/up_unblocktask.c
@@ -0,0 +1,160 @@
+/************************************************************
+ * up_unblocktask.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_unblock_task
+ *
+ * Description:
+ * A task is currently in an inactive task list
+ * but has been prepped to execute. Move the TCB to the
+ * ready-to-run list, restore its context, and start execution.
+ *
+ * Inputs:
+ * tcb: Refers to the tcb to be unblocked. This tcb is
+ * in one of the waiting tasks lists. It must be moved to
+ * the ready-to-run list and, if it is the highest priority
+ * ready to run taks, executed.
+ *
+ ************************************************************/
+
+void up_unblock_task(_TCB *tcb)
+{
+ /* Verify that the context switch can be performed */
+ if ((tcb->task_state < FIRST_BLOCKED_STATE) ||
+ (tcb->task_state > LAST_BLOCKED_STATE))
+ {
+ PANIC(OSERR_BADUNBLOCKSTATE);
+ }
+ else
+ {
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+
+ dbg("Unblocking TCB=%p\n", tcb);
+
+ /* Remove the task from the blocked task list */
+
+ sched_removeblocked(tcb);
+
+ /* Reset its timeslice. This is only meaningful for round
+ * robin tasks but it doesn't here to do it for everything
+ */
+
+#if CONFIG_RR_INTERVAL > 0
+ tcb->timeslice = CONFIG_RR_INTERVAL;
+#endif
+
+ /* Add the task in the correct location in the prioritized
+ * g_readytorun task list
+ */
+
+ if (sched_addreadytorun(tcb))
+ {
+ /* The currently active task has changed! We need to do
+ * a context switch to the new task.
+ *
+ * Are we in an interrupt handler?
+ */
+
+ if (current_regs)
+ {
+ /* Yes, then we have to do things differently.
+ * Just copy the current_regs into the OLD rtcb.
+ */
+
+ up_copystate(rtcb->xcp.regs, current_regs);
+
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_copystate(current_regs, rtcb->xcp.regs);
+ }
+
+ /* We are not in an interrupt andler. Copy the user C context
+ * into the TCB of the task that was previously active. if
+ * up_saveusercontext returns a non-zero value, then this is really the
+ * previously running task restarting!
+ */
+
+ else if (!up_saveusercontext(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the new task that is ready to
+ * run (probably tcb). This is the new rtcb at the head of the
+ * g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* Then switch contexts */
+
+ up_fullcontextrestore(rtcb->xcp.regs);
+ }
+ }
+ }
+}
diff --git a/arch/c5471/src/up_undefinedinsn.c b/arch/c5471/src/up_undefinedinsn.c
new file mode 100644
index 0000000000..3c213eb31c
--- /dev/null
+++ b/arch/c5471/src/up_undefinedinsn.c
@@ -0,0 +1,68 @@
+/************************************************************
+ * up_undefinedinsn.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_undefinedinsn
+ ************************************************************/
+
+void up_undefinedinsn(uint32 *regs)
+{
+ PANIC(OSERR_UNDEFINEDINSN);
+}
diff --git a/arch/c5471/src/up_usestack.c b/arch/c5471/src/up_usestack.c
new file mode 100644
index 0000000000..4cab9209fc
--- /dev/null
+++ b/arch/c5471/src/up_usestack.c
@@ -0,0 +1,118 @@
+/************************************************************
+ * up_usestack.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Types
+ ************************************************************/
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+/************************************************************
+ * Global Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_use_stack
+ *
+ * Description:
+ * Setup up stack-related information in the TCB
+ * using pre-allocated stack memory
+ *
+ * The following TCB fields must be initialized:
+ * adj_stack_size: Stack size after adjustment for hardware,
+ * processor, etc. This value is retained only for debug
+ * purposes.
+ * stack_alloc_ptr: Pointer to allocated stack
+ * adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
+ * initial value of the stack pointer.
+ *
+ * Inputs:
+ * tcb: The TCB of new task
+ * stack_size: The allocated stack size.
+ *
+ ************************************************************/
+
+STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size)
+{
+ uint32 top_of_stack;
+ uint32 size_of_stack;
+
+ if (tcb->stack_alloc_ptr)
+ {
+ sched_free(tcb->stack_alloc_ptr);
+ }
+
+ /* Save the stack allocation */
+
+ tcb->stack_alloc_ptr = stack;
+
+ /* The Arm7Tdmi uses a push-down stack: the stack grows
+ * toward loweraddresses in memory. The stack pointer
+ * register, points to the lowest, valid work address
+ * (the "top" of the stack). Items on the stack are
+ * referenced as positive word offsets from sp.
+ */
+
+ top_of_stack = (uint32)tcb->stack_alloc_ptr + stack_size - 4;
+
+ /* The Arm7Tdmi stack must be aligned at word (4 byte)
+ * boundaries. If necessary top_of_stack must be rounded
+ * down to the next boundary
+ */
+
+ top_of_stack &= ~3;
+ size_of_stack = top_of_stack - (uint32)tcb->stack_alloc_ptr + 4;
+
+ /* Save the adjusted stack values in the _TCB */
+
+ tcb->adj_stack_size = top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ return OK;
+}
diff --git a/arch/c5471/src/up_vectors.S b/arch/c5471/src/up_vectors.S
new file mode 100644
index 0000000000..f1c8467504
--- /dev/null
+++ b/arch/c5471/src/up_vectors.S
@@ -0,0 +1,449 @@
+/************************************************************
+ * up_vectors.S
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include "c5471.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Global Data
+ ************************************************************/
+
+ .data
+up_irqtmp:
+ .word 0 /* Saved lr */
+ .word 0 /* Saved spsr */
+up_undeftmp:
+ .word 0 /* Saved lr */
+ .word 0 /* Saved spsr */
+up_aborttmp:
+ .word 0 /* Saved lr */
+ .word 0 /* Saved spsr */
+
+/************************************************************
+ * Macros
+ ************************************************************/
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+ .text
+
+/************************************************************
+ * Public Functions
+ ************************************************************/
+
+ .text
+
+/************************************************************
+ * Name: up_vectorirq
+ *
+ * Description:
+ * Interrupt excetpion. Entered in IRQ mode with spsr = SVC
+ * CPSR, lr = SVC PC
+ ************************************************************/
+
+ .global up_vectorirq
+ .type up_vectorirq, %function
+up_vectorirq:
+ /* On entry, we are in IRQ mode. We are free to use
+ * the IRQ mode r13 and r14.
+ *
+ */
+
+ ldr r13, .Lirqtmp
+ sub lr, lr, #4
+ str lr, [r13] @ save lr_IRQ
+ mrs lr, spsr
+ str lr, [r13, #4] @ save spsr_IRQ
+
+ /* Then switch back to SVC mode */
+
+ bic lr, lr, #MODE_MASK /* Keep F and T bits */
+ orr lr, lr, #I_BIT | SVC_MODE
+ msr spsr_c, lr /* Swith to SVC mode */
+
+ /* Create a context structure */
+
+ sub sp, sp, #XCPTCONTEXT_SIZE
+ stmia sp, {r0-r3, r12} /* Save volatile regs */
+ ldr r0, .Lirqtmp /* Points to temp storage */
+ ldr lr, [r0] /* Recover lr */
+ ldr r3, [r0, $4] /* Recover SPSR */
+ add r1, sp, #XCPTCONTEXT_UOFFSET
+ stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
+
+ /* Now decode the interrupt */
+
+#if 0
+ ldr lr, =SRC_IRQ_BIN_REG /* Fetch encoded IRQ */
+ ldr r0, [lr]
+ and r0, r0, #0x0f /* Valid range is 0..15 */
+
+ /* Problems here... cannot read SRC_IRQ_BIN_REQ (and/or
+ * SRC_IRQ_REQ because this will clear edge triggered
+ * interrupts. Plus, no way to validate spurious
+ * interrupt.
+ */
+#else
+ ldr r6, =SRC_IRQ_REG
+ ldr r6, [r6] /* Get source IRQ reg */
+ mov r0, #0 /* Assume IRQ0_IRQ set */
+.Lmorebits:
+ tst r6, #1 /* Is IRQ set? */
+ bne .Lhaveirq /* Yes... we have the IRQ */
+ add r0, r0, #1 /* Setup next IRQ */
+ mov r6, r6, lsr #1 /* Shift right one */
+ cmp r0, #16 /* Only 16 valid bits */
+ bcc .Lmorebits /* Keep until we have looked
+ * at all bits */
+ b .Lnoirqset /* If we get here, there is
+ * no pending interrupt */
+.Lhaveirq:
+#endif
+ /* Then call the data abort handler with interrupt disabled.
+ * rq_dispatch(int irq, struct xcptcontext *xcp)
+ */
+
+ mov fp, #0 /* Init frame pointer */
+ mov r1, sp /* Get r1=xcp */
+ bl up_prefetchabort /* Call the handler */
+
+ /* Recover the SVC_MODE registers */
+.Lnoirqset:
+ add r0, sp, #XCPTCONTEXT_UOFFSET
+ ldmia r0, {r3-r11, r13-r14}
+ msr spsr, r3
+ ldmia sp, {r0-r3, r12} /* recover volatile regs */
+ add sp, sp, #XCPTCONTEXT_SIZE
+ movs pc, lr /* return & move spsr into cpsr */
+
+ @
+ @ now branch to the relevent MODE handling routine
+ @
+
+ and lr, lr, #15
+ ldr lr, [pc, lr, lsl #2]
+ movs pc, lr @ Changes mode and branches
+
+.Lirqtmp:
+ .word up_irqtmp
+
+ .align 5
+
+/************************************************************
+ * Function: up_vectorswi
+ *
+ * Description:
+ * SWI interrupt. We enter the SWI in SVC mode
+ ************************************************************/
+
+ .align 5
+ .global up_vectorswi
+ .type up_vectorswi, %function
+up_vectorswi:
+
+ /* The c547x rrload bootloader intemediates all
+ * interrupts. For the* case of the SWI, it mucked
+ * with the stack to create some temporary registers.
+ * We'll have to recover from this mucking here.
+ */
+
+ ldr r14, [sp,#-0x4] /* rrload workaround */
+
+ /* Create a context structure */
+
+ sub sp, sp, #XCPTCONTEXT_SIZE
+ stmia sp, {r0-r3, r12} /* Save volatile regs */
+ mrs r3, spsr /* Get r3=interrupted CPSR */
+ add r0, sp, #XCPTCONTEXT_UOFFSET
+ stmia r0, {r3-r11, r13-r14} /* Save CPSR+r4-r11+lr+sp */
+
+ /* Then call the SWI handler with interrupt disabled.
+ * void up_syscall(struct xcptcontext *xcp)
+ */
+
+ mov fp, #0 /* Init frame pointer */
+ mov r0, sp /* Get r0=xcp */
+ bl up_syscall /* Call the handler */
+
+.LignoreSWI:
+ /* Recover the SVC_MODE registers */
+
+ add r0, sp, #XCPTCONTEXT_UOFFSET
+ ldmia r0, {r3-r11, r13-r14}
+ msr spsr, r3
+ ldmia sp, {r0-r3, r12} /* recover volatile regs */
+ add sp, sp, #XCPTCONTEXT_SIZE
+ movs pc, lr /* return & move spsr into cpsr */
+
+/************************************************************
+ * Name: up_vectordata
+ *
+ * Description:
+ * Data abort Exception dispatcher. Give control to data
+ * abort handler. This function is entered in ABORT mode
+ * with spsr = SVC CPSR, lr = SVC PC
+ *
+ ************************************************************/
+
+ .text
+ .global up_vectordata
+ .type up_vectordata, %function
+up_vectordata:
+ /* On entry we are free to use the ABORT mode registers
+ * r13 and r14
+ */
+
+ ldr r13, .Ldaborttmp /* Points to temp storage */
+ sub lr, lr, #8 /* Fixup return */
+ str lr, [r13] /* Save in temp storage */
+ mrs lr, spsr /* Get SPSR */
+ str lr, [r13, #4] /* Save in temp storage */
+
+ /* Then switch back to SVC mode */
+
+ bic lr, lr, #MODE_MASK /* Keep F and T bits */
+ orr lr, lr, #I_BIT | SVC_MODE
+ msr spsr_c, lr /* Swith to SVC mode */
+
+ /* Create a context structure */
+
+ sub sp, sp, #XCPTCONTEXT_SIZE
+ stmia sp, {r0-r3, r12} /* Save volatile regs */
+ ldr r0, .Ldaborttmp /* Points to temp storage */
+ ldr lr, [r0] /* Recover lr */
+ ldr r3, [r0, $4] /* Recover SPSR */
+ add r1, sp, #XCPTCONTEXT_UOFFSET
+ stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
+
+ /* Then call the data abort handler with interrupt disabled.
+ * void up_dataabort(struct xcptcontext *xcp)
+ */
+
+ mov fp, #0 /* Init frame pointer */
+ mov r0, sp /* Get r0=xcp */
+ bl up_dataabort /* Call the handler */
+
+ /* Recover the SVC_MODE registers */
+
+ add r0, sp, #XCPTCONTEXT_UOFFSET
+ ldmia r0, {r3-r11, r13-r14}
+ msr spsr, r3
+ ldmia sp, {r0-r3, r12} /* recover volatile regs */
+ add sp, sp, #XCPTCONTEXT_SIZE
+ movs pc, lr /* return & move spsr into cpsr */
+
+ @
+ @ now branch to the relevent MODE handling routine
+ @
+
+ and lr, lr, #15
+ ldr lr, [pc, lr, lsl #2]
+ movs pc, lr @ Changes mode and branches
+
+.Ldaborttmp:
+ .word up_aborttmp
+
+ .align 5
+
+/************************************************************
+ * Name: up_vectorprefetch
+ *
+ * Description:
+ * Prefetch abort exception. Entered in ABT mode with
+ * spsr = SVC CPSR, lr = SVC PC
+ ************************************************************/
+
+ .global up_vectorprefetch
+ .type up_vectorprefetch, %function
+up_vectorprefetch:
+ /* On entry we are free to use the ABORT mode registers
+ * r13 and r14
+ */
+
+ ldr r13, .Lpaborttmp /* Points to temp storage */
+ sub lr, lr, #4 /* Fixup return */
+ str lr, [r13] /* Save in temp storage */
+ mrs lr, spsr /* Get SPSR */
+ str lr, [r13, #4] /* Save in temp storage */
+
+ /* Then switch back to SVC mode */
+
+ bic lr, lr, #MODE_MASK /* Keep F and T bits */
+ orr lr, lr, #I_BIT | SVC_MODE
+ msr spsr_c, lr /* Swith to SVC mode */
+
+ /* Create a context structure */
+
+ sub sp, sp, #XCPTCONTEXT_SIZE
+ stmia sp, {r0-r3, r12} /* Save volatile regs */
+ ldr r0, .Lpaborttmp /* Points to temp storage */
+ ldr lr, [r0] /* Recover lr */
+ ldr r3, [r0, $4] /* Recover SPSR */
+ add r1, sp, #XCPTCONTEXT_UOFFSET
+ stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
+
+ /* Then call the data abort handler with interrupt disabled.
+ * void up_prefetchabort(struct xcptcontext *xcp)
+ */
+
+ mov fp, #0 /* Init frame pointer */
+ mov r0, sp /* Get r0=xcp */
+ bl up_prefetchabort /* Call the handler */
+
+ /* Recover the SVC_MODE registers */
+
+ add r0, sp, #XCPTCONTEXT_UOFFSET
+ ldmia r0, {r3-r11, r13-r14}
+ msr spsr, r3
+ ldmia sp, {r0-r3, r12} /* recover volatile regs */
+ add sp, sp, #XCPTCONTEXT_SIZE
+ movs pc, lr /* return & move spsr into cpsr */
+
+ @
+ @ now branch to the relevent MODE handling routine
+ @
+
+ and lr, lr, #15
+ ldr lr, [pc, lr, lsl #2]
+ movs pc, lr @ Changes mode and branches
+
+.Lpaborttmp:
+ .word up_aborttmp
+
+ .align 5
+
+/************************************************************
+ * Name: up_vectorundefinsn
+ *
+ * Description:
+ * Undefined instruction entry exception. Entered in
+ * UND mode, spsr = SVC CPSR, lr = SVC PC
+ *
+ ************************************************************/
+
+ .global up_vectorundefinsn
+ .type up_vectorundefinsn, %function
+up_vectorundefinsn:
+ /* On entry we are free to use the UND mode registers
+ * r13 and r14
+ */
+
+ ldr r13, .Lundeftmp /* Points to temp storage */
+ str lr, [r13] /* Save in temp storage */
+ mrs lr, spsr /* Get SPSR */
+ str lr, [r13, #4] /* Save in temp storage */
+
+ /* Then switch back to SVC mode */
+
+ bic lr, lr, #MODE_MASK /* Keep F and T bits */
+ orr lr, lr, #I_BIT | SVC_MODE
+ msr spsr_c, lr /* Swith to SVC mode */
+
+ /* Create a context structure */
+
+ sub sp, sp, #XCPTCONTEXT_SIZE
+ stmia sp, {r0-r3, r12} /* Save volatile regs */
+ ldr r0, .Lundeftmp /* Points to temp storage */
+ ldr lr, [r0] /* Recover lr */
+ ldr r3, [r0, $4] /* Recover SPSR */
+ add r1, sp, #XCPTCONTEXT_UOFFSET
+ stmia r1, {r3-r11, r13-r14} /* Save SPSR+r4-r11+lr+sp */
+
+ /* Then call the data abort handler with interrupt disabled.
+ * void up_undefinedinsn(struct xcptcontext *xcp)
+ */
+
+ mov fp, #0 /* Init frame pointer */
+ mov r0, sp /* Get r0=xcp */
+ bl up_undefinedinsn /* Call the handler */
+
+ /* Recover the SVC_MODE registers */
+
+ add r0, sp, #XCPTCONTEXT_UOFFSET
+ ldmia r0, {r3-r11, r13-r14}
+ msr spsr, r3
+ ldmia sp, {r0-r3, r12} /* recover volatile regs */
+ add sp, sp, #XCPTCONTEXT_SIZE
+ movs pc, lr /* return & move spsr into cpsr */
+
+ @
+ @ now branch to the relevent MODE handling routine
+ @
+
+ and lr, lr, #15
+ ldr lr, [pc, lr, lsl #2]
+ movs pc, lr @ Changes mode and branches
+
+.Lundeftmp:
+ .word up_undeftmp
+
+ .align 5
+
+/************************************************************
+ * Name: up_vectorfiq
+ *
+ * Description:
+ * Shouldn't happen
+ ************************************************************/
+
+ .global up_vectorfiq
+ .type up_vectorfiq, %function
+up_vectorfiq:
+ subs pc, lr, #4
+
+/************************************************************
+ * Name: up_vectoraddrexcption
+ *
+ * Description:
+ * Shouldn't happen
+ *
+ ************************************************************/
+
+ .global up_vectoraddrexcptn
+ .type up_vectoraddrexcptn, %function
+up_vectoraddrexcptn:
+ b up_vectoraddrexcptn
+ .end
diff --git a/arch/sim/Make.defs b/arch/sim/Make.defs
new file mode 100644
index 0000000000..12e288a573
--- /dev/null
+++ b/arch/sim/Make.defs
@@ -0,0 +1,69 @@
+############################################################
+# Make.defs
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+
+include ${TOPDIR}/.config
+
+ifeq ("${CONFIG_DEBUG}","y")
+ ARCHOPTIMIZATION = -g
+else
+ ARCHOPTIMIZATION = -O2
+endif
+
+ARCHCPUFLAGS =
+ARCHPICFLAGS = -fpic
+ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
+ARCHDEFINES =
+ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
+ARCHSCRIPT =
+
+CROSSDEV =
+CC = $(CROSSDEV)gcc
+LD = $(CROSSDEV)ld
+AR = $(CROSSDEV)ar
+NM = $(CROSSDEV)nm
+OBJCOPY = $(CROSSDEV)objcopy
+OBJDUMP = $(CROSSDEV)objdump
+
+CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
+ $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) -pipe
+
+LDFLAGS = $(ARCHSCRIPT)
+EXTRA_LIBS = -lc
+
+ifeq ("${CONFIG_DEBUG}","y")
+ LDFLAGS += -g
+endif
+
+
diff --git a/arch/sim/defconfig b/arch/sim/defconfig
new file mode 100644
index 0000000000..60656fce38
--- /dev/null
+++ b/arch/sim/defconfig
@@ -0,0 +1,154 @@
+############################################################
+# defconfig
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+#
+# architecture selection
+#
+# CONFIG_ARCH - identifies the arch subdirectory
+# CONFIG_ARCH_name - for use in C code
+#
+CONFIG_ARCH=sim
+CONFIG_ARCH_SIM=y
+
+#
+# General OS setup
+#
+# CONFIG_EXAMPLE - identifies the subdirectgory in examples
+# that will be used in the build
+# CONFIG_DEBUG - enables built-in debug options
+# CONFIG_DEBUG_VERBOSE - enables verbose debug output
+# CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot
+# time console output
+# CONFIG_RR_INTERVAL - The round robin timeslice will be set
+# this number of milliseconds; Round robin scheduling can
+# be disabled by setting this value to zero.
+# CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
+# scheduler to monitor system performance
+# CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
+# task name to save in the TCB. Useful if scheduler
+# instrumentation is selected. Set to zero to disable.
+# CONFIG_JULIAN_TIME - Enables Julian time conversions
+# CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
+# Used to initialize the internal time logic.
+# CONFIG_DEV_CONSOLE - Set if architecture-specific logic
+# provides /dev/console. Enables stdout, stderr, stdin.
+#
+CONFIG_EXAMPLE=ostest
+CONFIG_DEBUG=y
+CONFIG_DEBUG_VERBOSE=y
+CONFIG_ARCH_LOWPUTC=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_INSTRUMENTATION=n
+CONFIG_TASK_NAME_SIZE=32
+CONFIG_START_YEAR=2007
+CONFIG_START_MONTH=2
+CONFIG_START_DAY=13
+CONFIG_JULIAN_TIME=n
+CONFIG_DEV_CONSOLE=y
+
+#
+# Allow for artchitecture optimized implementations
+#
+# The architecture can provide optimized versions of the
+# following to improve sysem performance
+#
+CONFIG_ARCH_MEMCPY=n
+CONFIG_ARCH_MEMCMP=n
+CONFIG_ARCH_MEMMOVE=n
+CONFIG_ARCH_MEMSET=n
+CONFIG_ARCH_STRCMP=n
+CONFIG_ARCH_STRCPY=n
+CONFIG_ARCH_STRNCPY=n
+CONFIG_ARCH_STRLEN=n
+CONFIG_ARCH_BZERO=n
+CONFIG_ARCH_KMALLOC=n
+CONFIG_ARCH_KZMALLOC=n
+CONFIG_ARCH_KFREE=n
+
+# General Compile environment setup
+#
+# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
+# long long types and if you plan to use them
+CONFIG_HAVE_LONG_LONG=n
+
+#
+# Sizes of configurable things (0 disables)
+#
+# CONFIG_NPTHREAD_KEYS - The number of items of thread-
+# specific data that can be retained
+# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
+# descriptors (one for each open)
+# CONFIG_NFILE_STREAMS - The maximum number of streams that
+# can be fopen'ed
+# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
+# on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_NUNGET_CHARS - Number of characters that can be
+# buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
+# structures. The system manages a pool of preallocated
+# message structures to minimize dynamic allocations
+# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
+# a fixed payload size given by this settin (does not include
+# other message structure overhead.
+# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
+# structures. The system manages a pool of preallocated
+# watchdog structures to minimize dynamic allocations
+#
+CONFIG_NPTHREAD_KEYS=4
+CONFIG_NFILE_DESCRIPTORS=32
+CONFIG_NFILE_STREAMS=16
+CONFIG_STDIO_BUFFER_SIZE=1024
+CONFIG_NUNGET_CHARS=2
+CONFIG_PREALLOC_MQ_MSGS=32
+CONFIG_MQ_MAXMSGSIZE=32
+CONFIG_PREALLOC_WDOGS=32
+
+#
+# Stack and heap information
+#
+# CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
+# operation from FLASH.
+# 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
+# CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
+# CONFIG_HEAP_BASE - The beginning of the heap
+# CONFIG_HEAP_SIZE - The size of the heap
+#
+CONFIG_BOOT_FROM_FLASH=n
+CONFIG_PROC_STACK_SIZE=0x00001000
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=8192
+CONFIG_HEAP_BASE=
+CONFIG_HEAP_SIZE=
diff --git a/arch/sim/include/arch.h b/arch/sim/include/arch.h
new file mode 100644
index 0000000000..32eadcd178
--- /dev/null
+++ b/arch/sim/include/arch.h
@@ -0,0 +1,80 @@
+/************************************************************
+ * arch.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+/* This file should never be included directed but, rather,
+ * only indirectly through nuttx/arch.h
+ */
+
+#ifndef __ARCH_ARCH_H
+#define __ARCH_ARCH_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Inline functions
+ ************************************************************/
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ARCH_ARCH_H */
+
diff --git a/arch/sim/include/irq.h b/arch/sim/include/irq.h
new file mode 100644
index 0000000000..3ae46aa42d
--- /dev/null
+++ b/arch/sim/include/irq.h
@@ -0,0 +1,106 @@
+/************************************************************
+ * irq.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+/* This file should never be included directed but, rather,
+ * only indirectly through nuttx/irq.h
+ */
+
+#ifndef __ARCH_IRQ_H
+#define __ARCH_IRQ_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#define NR_IRQS 0
+
+/************************************************************
+ * Public Types
+ ************************************************************/
+
+/* This struct defines the way the registers are stored */
+
+#ifndef __ASSEMBLY__
+struct xcptcontext
+{
+ void *sigdeliver; /* Actual type is sig_deliver_t */
+
+ /* Storage order: %ebx, $esi, %edi, %ebp, sp, and return PC */
+
+ int regs[6];
+};
+#endif
+
+/************************************************************
+ * Inline functions
+ ************************************************************/
+
+#ifndef __ASSEMBLY__
+static inline uint32 irqsave(void)
+{
+ return 0;
+}
+
+static inline void irqrestore(uint32 flags)
+{
+}
+#endif
+
+/************************************************************
+ * Public Variables
+ ************************************************************/
+
+/************************************************************
+ * Public Function Prototypes
+ ************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ARCH_IRQ_H */
+
diff --git a/arch/sim/include/types.h b/arch/sim/include/types.h
new file mode 100644
index 0000000000..39232af7d7
--- /dev/null
+++ b/arch/sim/include/types.h
@@ -0,0 +1,70 @@
+/************************************************************
+ * types.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+/* This file should never be included directed but, rather,
+ * only indirectly through sys/types.h
+ */
+
+#ifndef __ARCH_TYPES_H
+#define __ARCH_TYPES_H
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+/************************************************************
+ * Type Declarations
+ ************************************************************/
+
+typedef char sbyte;
+typedef unsigned char ubyte;
+typedef unsigned char uint8;
+typedef unsigned char boolean;
+typedef short sint16;
+typedef unsigned short uint16;
+typedef int sint32;
+typedef unsigned int uint32;
+typedef long long sint64;
+typedef unsigned long long uint64;
+
+/************************************************************
+ * Global Function Prototypes
+ ************************************************************/
+
+#endif /* __ARCH_TYPES_H */
diff --git a/arch/sim/setenv.sh b/arch/sim/setenv.sh
new file mode 100755
index 0000000000..d0a05bfdf9
--- /dev/null
+++ b/arch/sim/setenv.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# setenv.sh
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+
+if [ "$(basename $0)" = "setenv" ] ; then
+ echo "You must source this script, not run it!" 1>&2
+ exit 1
+fi
+
+if [ -z ${PATH_ORIG} ]; then export PATH_ORIG=${PATH}; fi
+
+#export NUTTX_BIN=
+#export PATH=${NUTTX_BIN}:/sbin:/usr/sbin:${PATH_ORIG}
+
+echo "PATH : ${PATH}"
diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile
new file mode 100644
index 0000000000..780cff5968
--- /dev/null
+++ b/arch/sim/src/Makefile
@@ -0,0 +1,76 @@
+############################################################
+# Makefile
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+
+-include $(TOPDIR)/Make.defs
+
+MKDEP = $(TOPDIR)/tools/mkdeps.sh
+CFLAGS += -I$(TOPDIR)/sched
+
+ASRCS = up_setjmp.S
+AOBJS = $(ASRCS:.S=.o)
+CSRCS = up_initialize.c up_idle.c up_interruptcontext.c up_initialstate.c \
+ up_createstack.c up_usestack.c up_releasestack.c \
+ up_unblocktask.c up_blocktask.c up_releasepending.c up_reprioritizertr.c \
+ up_exit.c up_schedulesigaction.c up_allocateheap.c up_devconsole.c
+COBJS = $(CSRCS:.c=.o)
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+all: up_head.o libarch.a
+
+$(AOBJS): %.o: %.S
+ $(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
+
+$(COBJS) up_head.o: %.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+libarch.a: $(OBJS)
+ $(AR) rcs $@ $(OBJS)
+
+.depend: Makefile $(SRCS)
+ $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ touch $@
+
+depend: .depend
+
+clean:
+ rm -f libarch.a *.o *~
+
+distclean: clean
+ rm -f Make.dep .depend
+
+
+-include Make.dep
diff --git a/arch/sim/src/up_allocateheap.c b/arch/sim/src/up_allocateheap.c
new file mode 100644
index 0000000000..b464719d41
--- /dev/null
+++ b/arch/sim/src/up_allocateheap.c
@@ -0,0 +1,81 @@
+/************************************************************
+ * up_allocateheap.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+static ubyte sim_heap[SIM_HEAP_SIZE];
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_allocate_heap
+ *
+ * Description:
+ * The heap may be statically allocated by
+ * defining CONFIG_HEAP_BASE and CONFIG_HEAP_SIZE. If these
+ * are not defined, then this function will be called to
+ * dynamically set aside the heap region.
+ *
+ ************************************************************/
+
+void up_allocate_heap(void **heap_start, size_t *heap_size)
+{
+ *heap_start = sim_heap;
+ *heap_size = SIM_HEAP_SIZE;
+}
diff --git a/arch/sim/src/up_blocktask.c b/arch/sim/src/up_blocktask.c
new file mode 100644
index 0000000000..66cd893723
--- /dev/null
+++ b/arch/sim/src/up_blocktask.c
@@ -0,0 +1,157 @@
+/************************************************************
+ * up_blocktask.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_block_task
+ *
+ * Description:
+ * The currently executing task at the head of
+ * the ready to run list must be stopped. Save its context
+ * and move it to the inactive list specified by task_state.
+ *
+ * Inputs:
+ * tcb: Refers to a task in the ready-to-run list (normally
+ * the task at the the head of the list). It most be
+ * stopped, its context saved and moved into one of the
+ * waiting task lists. It it was the task at the head
+ * of the ready-to-run list, then a context to the new
+ * ready to run task must be performed.
+ * task_state: Specifies which waiting task list should be
+ * hold the blocked task TCB.
+ *
+ ************************************************************/
+
+void up_block_task(_TCB *tcb, tstate_t task_state)
+{
+ /* Verify that the context switch can be performed */
+ if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) ||
+ (tcb->task_state > LAST_READY_TO_RUN_STATE))
+ {
+ PANIC(OSERR_BADBLOCKSTATE);
+ }
+ else
+ {
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+ boolean switch_needed;
+
+ dbg("Blocking TCB=%p\n", tcb);
+
+ /* Remove the tcb task from the ready-to-run list. If we
+ * are blocking the task at the head of the task list (the
+ * most likely case), then a context switch to the next
+ * ready-to-run task is needed. In this case, it should
+ * also be true that rtcb == tcb.
+ */
+
+ switch_needed = sched_removereadytorun(tcb);
+
+ /* Add the task to the specified blocked task list */
+
+ sched_addblocked(tcb, (tstate_t)task_state);
+
+ /* If there are any pending tasks, then add them to the g_readytorun
+ * task list now
+ */
+
+ if (g_pendingtasks.head)
+ {
+ switch_needed |= sched_mergepending();
+ }
+
+ /* Now, perform the context switch if one is needed */
+
+ if (switch_needed)
+ {
+ /* Copy the exception context into the TCB at the (old) head of the
+ * g_readytorun Task list. if up_setjmp returns a non-zero
+ * value, then this is really the previously running task restarting!
+ */
+
+ if (!up_setjmp(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* The way that we handle signals in the simulation is kind of
+ * a kludge. This would be unsafe in a truly multi-threaded, interrupt
+ * driven environment.
+ */
+
+ if (rtcb->xcp.sigdeliver)
+ {
+ dbg("Delivering signals TCB=%p\n", rtcb);
+ ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
+ rtcb->xcp.sigdeliver = NULL;
+ }
+
+ /* Then switch contexts */
+
+ up_longjmp(rtcb->xcp.regs, 1);
+ }
+ }
+ }
+}
diff --git a/arch/sim/src/up_createstack.c b/arch/sim/src/up_createstack.c
new file mode 100644
index 0000000000..0e2c63e4d1
--- /dev/null
+++ b/arch/sim/src/up_createstack.c
@@ -0,0 +1,109 @@
+/************************************************************
+ * up_createstack.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_create_stack
+ *
+ * Description:
+ * Allocate a stack for a new thread and setup
+ * up stack-related information in the TCB.
+ *
+ * The following TCB fields must be initialized:
+ * adj_stack_size: Stack size after adjustment for hardware,
+ * processor, etc. This value is retained only for debug
+ * purposes.
+ * stack_alloc_ptr: Pointer to allocated stack
+ * adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
+ * initial value of the stack pointer.
+ *
+ * Inputs:
+ * tcb: The TCB of new task
+ * stack_size: The requested stack size. At least this much
+ * must be allocated.
+ *
+ ************************************************************/
+
+STATUS up_create_stack(_TCB *tcb, uint32 stack_size)
+{
+ STATUS ret = ERROR;
+
+ /* Move up to next even word boundary if necessary */
+
+ uint32 adj_stack_size = (stack_size + 3) & ~3;
+ uint32 adj_stack_words = adj_stack_size >> 2;
+
+ /* Allocate the memory for the stack */
+
+ uint32 *stack_alloc_ptr = (uint32*)kmalloc(adj_stack_size);
+ if (stack_alloc_ptr)
+ {
+ /* This is the address of the last word in the allocation */
+
+ uint32 *adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1];
+
+ /* Save the values in the TCB */
+ tcb->adj_stack_size = adj_stack_size;
+ tcb->stack_alloc_ptr = stack_alloc_ptr;
+ tcb->adj_stack_ptr = adj_stack_ptr;
+ ret = OK;
+ }
+ return ret;
+}
diff --git a/arch/sim/src/up_devconsole.c b/arch/sim/src/up_devconsole.c
new file mode 100644
index 0000000000..b55df53dff
--- /dev/null
+++ b/arch/sim/src/up_devconsole.c
@@ -0,0 +1,136 @@
+/************************************************************
+ * up_devconsole.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+
+#include
+#include
+
+#include
+
+#include "up_internal.h"
+
+/************************************************************
+ * Definitions
+ ************************************************************/
+
+#define READ 3
+#define WRITE 4
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+static ssize_t devconsole_read(struct file *, char *, size_t);
+static ssize_t devconsole_write(struct file *, const char *, size_t);
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+static struct file_operations devconsole_fops =
+{
+ .read = devconsole_read,
+ .write = devconsole_write,
+};
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+static inline int up_read(int fd, void* buf, size_t count)
+{
+ uint32 result;
+
+ __asm__ volatile ("int $0x80" \
+ : "=a" (result) \
+ : "0" (READ), "b" ((uint32)(fd)), "c" ((uint32)(buf)), "d" ((uint32)(count)) \
+ : "memory");
+
+ return (int)result;
+}
+
+static inline int up_write(int fd, const void* buf, size_t count)
+{
+ uint32 result;
+
+ __asm__ volatile ("int $0x80" \
+ : "=a" (result) \
+ : "0" (WRITE), "b" ((uint32)(fd)), "c" ((uint32)(buf)), "d" ((uint32)(count)) \
+ : "memory");
+
+ return (int)result;
+}
+
+static inline int up_check_result(int result)
+{
+ if (result >= (uint32)(-(128 + 1)))
+ {
+ *get_errno_ptr() = -result;
+ result = ERROR;
+ }
+ return result;
+}
+
+static ssize_t devconsole_read(struct file *filp, char *buffer, size_t len)
+{
+ return up_check_result(up_read(1, buffer, len));
+}
+
+static ssize_t devconsole_write(struct file *filp, const char *buffer, size_t len)
+{
+ return up_check_result(up_write(1, buffer, len));
+}
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+void up_devconsole(void)
+{
+ (void)register_inode("/dev/console", &devconsole_fops, 0666, NULL);
+}
+
+int up_putc(int ch)
+{
+ char b = ch;
+ (void)up_write(1, &b, 1);
+ return ch;
+}
diff --git a/arch/sim/src/up_exit.c b/arch/sim/src/up_exit.c
new file mode 100644
index 0000000000..a0a3bdc9ab
--- /dev/null
+++ b/arch/sim/src/up_exit.c
@@ -0,0 +1,123 @@
+/************************************************************
+ * up_exit.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: _exit
+ *
+ * Description:
+ * This function causes the currently executing task to cease
+ * to exist. This is a special case of task_delete().
+ *
+ ************************************************************/
+
+void _exit(int status)
+{
+ _TCB* tcb = (_TCB*)g_readytorun.head;
+
+ dbg("TCB=%p exitting\n", tcb);
+
+ /* Remove the tcb task from the ready-to-run list. We can
+ * ignore the return value because we know that a context
+ * switch is needed.
+ */
+
+ (void)sched_removereadytorun(tcb);
+
+ /* Move the TCB to the specified blocked task list and delete it */
+
+ sched_addblocked(tcb, TSTATE_TASK_INACTIVE);
+ task_delete(tcb->pid);
+
+ /* If there are any pending tasks, then add them to the g_readytorun
+ * task list now
+ */
+
+ if (g_pendingtasks.head)
+ {
+ (void)sched_mergepending();
+ }
+
+ /* Now, perform the context switch to the new ready-to-run task at the
+ * head of the list.
+ */
+
+ tcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", tcb);
+
+ /* The way that we handle signals in the simulation is kind of
+ * a kludge. This would be unsafe in a truly multi-threaded, interrupt
+ * driven environment.
+ */
+
+ if (tcb->xcp.sigdeliver)
+ {
+ dbg("Delivering signals TCB=%p\n", tcb);
+ ((sig_deliver_t)tcb->xcp.sigdeliver)(tcb);
+ tcb->xcp.sigdeliver = NULL;
+ }
+
+ /* Then switch contexts */
+
+ up_longjmp(tcb->xcp.regs, 1);
+}
+
diff --git a/arch/sim/src/up_head.c b/arch/sim/src/up_head.c
new file mode 100644
index 0000000000..9d1ccf1533
--- /dev/null
+++ b/arch/sim/src/up_head.c
@@ -0,0 +1,77 @@
+/************************************************************
+ * up_head.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include
+#include
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+static jmp_buf sim_abort;
+
+/************************************************************
+ * Global Funtions
+ ************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ if (setjmp(sim_abort) == 0)
+ {
+ os_start();
+ }
+ return 0;
+}
+
+void up_assert(const ubyte *filename, uint32 line)
+{
+ fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line);
+ longjmp(sim_abort, 1);
+}
+
+void up_assert_code(const ubyte *filename, uint32 line, uint16 code)
+{
+ fprintf(stderr, "Assertion failed at file:%s line: %d error code: %d\n", filename, line, code);
+ longjmp(sim_abort, 1);
+}
diff --git a/arch/sim/src/up_idle.c b/arch/sim/src/up_idle.c
new file mode 100644
index 0000000000..b40b2e3d87
--- /dev/null
+++ b/arch/sim/src/up_idle.c
@@ -0,0 +1,84 @@
+/************************************************************
+ * up_idle.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_idle
+ *
+ * Description:
+ * up_idle() is the logic that will be executed when their
+ * is no other ready-to-run task. This is processor idle
+ * time and will continue until some interrupt occurs to
+ * cause a context switch from the idle task.
+ *
+ * Processing in this state may be processor-specific. e.g.,
+ * this is where power management operations might be
+ * performed.
+ *
+ ************************************************************/
+
+void up_idle(void)
+{
+ /* If the system, then process timer interrupts. Hopefully
+ * something will wake up.
+ */
+
+ sched_process_timer();
+}
+
diff --git a/arch/sim/src/up_initialize.c b/arch/sim/src/up_initialize.c
new file mode 100644
index 0000000000..90b0b49e47
--- /dev/null
+++ b/arch/sim/src/up_initialize.c
@@ -0,0 +1,88 @@
+/************************************************************
+ * up_initialize.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_initialize
+ *
+ * Description:
+ * up_initialize will be called once during OS
+ * initialization after the basic OS services have been
+ * initialized. The architecture specific details of
+ * initializing the OS will be handled here. Such things as
+ * setting up interrupt service routines, starting the
+ * clock, and registering device drivers are some of the
+ * things that are different for each processor and hardware
+ * platform.
+ *
+ * up_initialize is called after the OS initialized but
+ * before the init process has been started and before the
+ * libraries have been initialized. OS services and driver
+ * services are available.
+ *
+ ************************************************************/
+
+void up_initialize(void)
+{
+ /* Register devices */
+
+ devnull_register(); /* Standard /dev/null */
+ up_devconsole(); /* Our private /dev/console */
+}
diff --git a/arch/sim/src/up_initialstate.c b/arch/sim/src/up_initialstate.c
new file mode 100644
index 0000000000..ec3e50991b
--- /dev/null
+++ b/arch/sim/src/up_initialstate.c
@@ -0,0 +1,81 @@
+/************************************************************
+ * up_initialstate.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_initial_state
+ *
+ * Description:
+ * A new thread is being started and a new TCB
+ * has been created. This function is called to initialize
+ * the processor specific portions of the new TCB.
+ *
+ * This function must setup the intial architecture registers
+ * and/or stack so that execution will begin at tcb->start
+ * on the next context switch.
+ *
+ ************************************************************/
+
+void up_initial_state(_TCB *tcb)
+{
+ memset(&tcb->xcp, 0, sizeof(struct xcptcontext));
+ tcb->xcp.regs[JB_SP] = (uint32)tcb->adj_stack_ptr;
+ tcb->xcp.regs[JB_PC] = (uint32)tcb->start;
+}
diff --git a/arch/sim/src/up_internal.h b/arch/sim/src/up_internal.h
new file mode 100644
index 0000000000..29defe0296
--- /dev/null
+++ b/arch/sim/src/up_internal.h
@@ -0,0 +1,91 @@
+/**************************************************************************
+ * up_internal.h
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef __ARCH_UP_INTERNAL_H
+#define __ARCH_UP_INTERNAL_H
+
+/**************************************************************************
+ * Included Files
+ **************************************************************************/
+
+#include
+
+/**************************************************************************
+ * Public Definitions
+ **************************************************************************/
+
+/* Storage order: %ebx, $esi, %edi, %ebp, sp, and return PC */
+#ifdef __ASSEMBLY__
+# define JB_EBX (0*4)
+# define JB_ESI (1*4)
+# define JB_EDI (2*4)
+# define JB_EBP (3*4)
+# define JB_SP (4*4)
+# define JB_PC (5*4)
+#else
+# define JB_EBX (0)
+# define JB_ESI (1)
+# define JB_EDI (2)
+# define JB_EBP (3)
+# define JB_SP (4)
+# define JB_PC (5)
+#endif /* __ASSEMBLY__ */
+
+#define SIM_HEAP_SIZE (4*1024*1024)
+
+/**************************************************************************
+ * Public Types
+ **************************************************************************/
+
+/**************************************************************************
+ * Public Variables
+ **************************************************************************/
+
+/**************************************************************************
+ * Public Function Prototypes
+ **************************************************************************/
+
+#ifndef __ASSEMBLY__
+/* up_setjmp.S ************************************************************/
+
+extern int up_setjmp(int *jb);
+extern void up_longjmp(int *jb, int val) __attribute__ ((noreturn));
+
+/* up_devconsole **********************************************************/
+
+extern void up_devconsole(void);
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_UP_INTERNAL_H */
diff --git a/arch/sim/src/up_interruptcontext.c b/arch/sim/src/up_interruptcontext.c
new file mode 100644
index 0000000000..ad1eb74d7e
--- /dev/null
+++ b/arch/sim/src/up_interruptcontext.c
@@ -0,0 +1,74 @@
+/************************************************************
+ * up_interruptcontext.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_interrupt_context
+ *
+ * Description:
+ * Return TRUE is we are currently executing in
+ * the interrupt handler context.
+ ************************************************************/
+
+boolean up_interrupt_context(void)
+{
+ /* The simulation is never in the interrupt state */
+ return FALSE;
+}
+
diff --git a/arch/sim/src/up_releasepending.c b/arch/sim/src/up_releasepending.c
new file mode 100644
index 0000000000..8a494a3542
--- /dev/null
+++ b/arch/sim/src/up_releasepending.c
@@ -0,0 +1,118 @@
+/************************************************************
+ * up_releasepending.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_release_pending
+ *
+ * Description:
+ * Release and ready-to-run tasks that have
+ * collected in the pending task list. This can call a
+ * context switch if a new task is placed at the head of
+ * the ready to run list.
+ *
+ ************************************************************/
+
+void up_release_pending(void)
+{
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+
+ dbg("From TCB=%p\n", rtcb);
+
+ /* Merge the g_pendingtasks list into the g_readytorun task list */
+
+ /* sched_lock(); */
+ if (sched_mergepending())
+ {
+ /* The currently active task has changed! Copy the exception context
+ * into the TCB of the task that was currently active. if up_setjmp
+ * returns a non-zero value, then this is really the previously
+ * running task restarting!
+ */
+
+ if (!up_setjmp(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* The way that we handle signals in the simulation is kind of
+ * a kludge. This would be unsafe in a truly multi-threaded, interrupt
+ * driven environment.
+ */
+
+ if (rtcb->xcp.sigdeliver)
+ {
+ dbg("Delivering signals TCB=%p\n", rtcb);
+ ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
+ rtcb->xcp.sigdeliver = NULL;
+ }
+
+ /* Then switch contexts */
+
+ up_longjmp(rtcb->xcp.regs, 1);
+ }
+ }
+}
diff --git a/arch/sim/src/up_releasestack.c b/arch/sim/src/up_releasestack.c
new file mode 100644
index 0000000000..5fc950c6ab
--- /dev/null
+++ b/arch/sim/src/up_releasestack.c
@@ -0,0 +1,81 @@
+/************************************************************
+ * up_releasestack.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_release_stack
+ *
+ * Description:
+ * A task has been stopped. Free all stack
+ * related resources retained int the defunct TCB.
+ *
+ ************************************************************/
+
+void up_release_stack(_TCB *dtcb)
+{
+ if (dtcb->stack_alloc_ptr)
+ {
+ free(dtcb->stack_alloc_ptr);
+ }
+
+ dtcb->stack_alloc_ptr = NULL;
+ dtcb->adj_stack_size = 0;
+ dtcb->adj_stack_ptr = NULL;
+}
diff --git a/arch/sim/src/up_reprioritizertr.c b/arch/sim/src/up_reprioritizertr.c
new file mode 100644
index 0000000000..d4d91a88e1
--- /dev/null
+++ b/arch/sim/src/up_reprioritizertr.c
@@ -0,0 +1,169 @@
+/************************************************************
+ * up_reprioritizertr.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_reprioritize_rtr
+ *
+ * Description:
+ * Called when the priority of a running or
+ * ready-to-run task changes and the reprioritization will
+ * cause a context switch. Two cases:
+ *
+ * 1) The priority of the currently running task drops and the next
+ * task in the ready to run list has priority.
+ * 2) An idle, ready to run task's priority has been raised above the
+ * the priority of the current, running task and it now has the
+ * priority.
+ *
+ * Inputs:
+ * tcb: The TCB of the task that has been reprioritized
+ * priority: The new task priority
+ *
+ ************************************************************/
+
+void up_reprioritize_rtr(_TCB *tcb, ubyte priority)
+{
+ /* Verify that the caller is sane */
+
+ if (tcb->task_state < FIRST_READY_TO_RUN_STATE ||
+ tcb->task_state > LAST_READY_TO_RUN_STATE ||
+ priority < SCHED_PRIORITY_MIN ||
+ priority > SCHED_PRIORITY_MAX)
+ {
+ PANIC(OSERR_BADREPRIORITIZESTATE);
+ }
+ else
+ {
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+ boolean switch_needed;
+
+ dbg("TCB=%p PRI=%d\n", tcb, priority);
+
+ /* Remove the tcb task from the ready-to-run list.
+ * sched_removereadytorun will return TRUE if we just
+ * remove the head of the ready to run list.
+ */
+
+ switch_needed = sched_removereadytorun(tcb);
+
+ /* Setup up the new task priority */
+
+ tcb->sched_priority = (ubyte)priority;
+
+ /* Return the task to the specified blocked task list.
+ * sched_addreadytorun will return TRUE if the task was
+ * added to the new list. We will need to perform a context
+ * switch only if the EXCLUSIVE or of the two calls is non-zero
+ * (i.e., one and only one the calls changes the head of the
+ * ready-to-run list).
+ */
+
+ switch_needed ^= sched_addreadytorun(tcb);
+
+ /* Now, perform the context switch if one is needed */
+
+ if (switch_needed)
+ {
+ /* If we are going to do a context switch, then now is the right
+ * time to add any pending tasks back into the ready-to-run list.
+ * task list now
+ */
+
+ if (g_pendingtasks.head)
+ {
+ sched_mergepending();
+ }
+
+ /* Copy the exception context into the TCB at the (old) head of the
+ * g_readytorun Task list. if up_setjmp returns a non-zero
+ * value, then this is really the previously running task restarting!
+ */
+
+ if (!up_setjmp(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* The way that we handle signals in the simulation is kind of
+ * a kludge. This would be unsafe in a truly multi-threaded, interrupt
+ * driven environment.
+ */
+
+ if (rtcb->xcp.sigdeliver)
+ {
+ dbg("Delivering signals TCB=%p\n", rtcb);
+ ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
+ rtcb->xcp.sigdeliver = NULL;
+ }
+
+ /* Then switch contexts */
+
+ up_longjmp(rtcb->xcp.regs, 1);
+ }
+ }
+ }
+}
diff --git a/arch/sim/src/up_schedulesigaction.c b/arch/sim/src/up_schedulesigaction.c
new file mode 100644
index 0000000000..6e6d13911b
--- /dev/null
+++ b/arch/sim/src/up_schedulesigaction.c
@@ -0,0 +1,109 @@
+/************************************************************
+ * up_schedulesigaction.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_schedule_sigaction
+ *
+ * Description:
+ * This function is called by the OS when one or more
+ * signal handling actions have been queued for execution.
+ * The architecture specific code must configure things so
+ * that the 'igdeliver' callback is executed on the thread
+ * specified by 'tcb' as soon as possible.
+ *
+ * This function may be called from interrupt handling logic.
+ *
+ * This operation should not cause the task to be unblocked
+ * nor should it cause any immediate execution of sigdeliver.
+ * Typically, a few cases need to be considered:
+ *
+ * (1) This function may be called from an interrupt handler
+ * During interrupt processing, all xcptcontext structures
+ * should be valid for all tasks. That structure should
+ * be modified to invoke sigdeliver() either on return
+ * from (this) interrupt or on some subsequent context
+ * switch to the recipient task.
+ * (2) If not in an interrupt handler and the tcb is NOT
+ * the currently executing task, then again just modify
+ * the saved xcptcontext structure for the recipient
+ * task so it will invoke sigdeliver when that task is
+ * later resumed.
+ * (3) If not in an interrupt handler and the tcb IS the
+ * currently executing task -- just call the signal
+ * handler now.
+ *
+ ************************************************************/
+
+void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver)
+{
+ /* We don't have to anything complex of the simulated target */
+
+ if (tcb == (_TCB*)g_readytorun.head)
+ {
+ sigdeliver(tcb);
+ }
+ else
+ {
+ tcb->xcp.sigdeliver = sigdeliver;
+ }
+}
diff --git a/arch/sim/src/up_setjmp.S b/arch/sim/src/up_setjmp.S
new file mode 100644
index 0000000000..96b9bfee88
--- /dev/null
+++ b/arch/sim/src/up_setjmp.S
@@ -0,0 +1,129 @@
+/**************************************************************************
+ * up_setjmp.S
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+/**************************************************************************
+ * Conditional Compilation Options
+ **************************************************************************/
+
+/**************************************************************************
+ * Included Files
+ **************************************************************************/
+
+#include "up_internal.h"
+
+/**************************************************************************
+ * Private Definitions
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Types
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Function Prototypes
+ **************************************************************************/
+
+/**************************************************************************
+ * Global Variables
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Variables
+ **************************************************************************/
+
+/**************************************************************************
+ * Private Functions
+ **************************************************************************/
+
+/**************************************************************************
+ * Public Functions
+ **************************************************************************/
+
+ .text
+ .globl up_setjmp
+ .type up_setjmp, @function
+up_setjmp:
+
+ /* %ebx, %esi, %edi, and %ebp must be preserved.
+ * save %ebx, $esi, and %edi now... */
+
+ movl 4(%esp), %eax
+ movl %ebx, (JB_EBX)(%eax)
+ movl %esi, (JB_ESI)(%eax)
+ movl %edi, (JB_EDI)(%eax)
+
+ /* Save the value of SP as will be after we return */
+
+ leal 4(%esp), %ecx
+ movl %ecx, (JB_SP)(%eax)
+
+ /* Save the return PC */
+
+ movl 0(%esp), %ecx
+ movl %ecx, (JB_PC)(%eax)
+
+ /* Save the framepointer */
+
+ movl %ebp, (JB_EBP)(%eax)
+
+ /* And return 0 */
+
+ xorl %eax, %eax
+ ret
+ .size up_setjmp, . - up_setjmp
+
+ .globl up_longjmp
+ .type up_longjmp, @function
+up_longjmp:
+ movl 4(%esp), %ecx /* U_pthread_jmpbuf in %ecx. */
+ movl 8(%esp), %eax /* Second argument is return value. */
+
+ /* Save the return address now. */
+
+ movl (JB_PC)(%ecx), %edx
+
+ /* Restore registers. */
+
+ movl (JB_EBX)(%ecx), %ebx
+ movl (JB_ESI)(%ecx), %esi
+ movl (JB_EDI)(%ecx), %edi
+ movl (JB_EBP)(%ecx), %ebp
+ movl (JB_SP)(%ecx), %esp
+
+ /* Jump to saved PC. */
+
+ jmp *%edx
+ .size up_longjmp, . - up_longjmp
+
diff --git a/arch/sim/src/up_unblocktask.c b/arch/sim/src/up_unblocktask.c
new file mode 100644
index 0000000000..bf3148506a
--- /dev/null
+++ b/arch/sim/src/up_unblocktask.c
@@ -0,0 +1,146 @@
+/************************************************************
+ * up_unblocktask.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_unblock_task
+ *
+ * Description:
+ * A task is currently in an inactive task list
+ * but has been prepped to execute. Move the TCB to the
+ * ready-to-run list, restore its context, and start execution.
+ *
+ * Inputs:
+ * tcb: Refers to the tcb to be unblocked. This tcb is
+ * in one of the waiting tasks lists. It must be moved to
+ * the ready-to-run list and, if it is the highest priority
+ * ready to run taks, executed.
+ *
+ ************************************************************/
+
+void up_unblock_task(_TCB *tcb)
+{
+ /* Verify that the context switch can be performed */
+ if ((tcb->task_state < FIRST_BLOCKED_STATE) ||
+ (tcb->task_state > LAST_BLOCKED_STATE))
+ {
+ PANIC(OSERR_BADUNBLOCKSTATE);
+ }
+ else
+ {
+ _TCB *rtcb = (_TCB*)g_readytorun.head;
+
+ dbg("Unblocking TCB=%p\n", tcb);
+
+ /* Remove the task from the blocked task list */
+
+ sched_removeblocked(tcb);
+
+ /* Reset its timeslice. This is only meaningful for round
+ * robin tasks but it doesn't here to do it for everything
+ */
+
+#if CONFIG_RR_INTERVAL > 0
+ tcb->timeslice = CONFIG_RR_INTERVAL;
+#endif
+
+ /* Add the task in the correct location in the prioritized
+ * g_readytorun task list
+ */
+
+ if (sched_addreadytorun(tcb))
+ {
+ /* The currently active task has changed! Copy the exception context
+ * into the TCB of the task that was previously active. if
+ * up_setjmp returns a non-zero value, then this is really the
+ * previously running task restarting!
+ */
+
+ if (!up_setjmp(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the new task that is ready to
+ * run (probably tcb). This is the new rtcb at the head of the
+ * g_readytorun task list.
+ */
+
+ rtcb = (_TCB*)g_readytorun.head;
+ dbg("New Active Task TCB=%p\n", rtcb);
+
+ /* The way that we handle signals in the simulation is kind of
+ * a kludge. This would be unsafe in a truly multi-threaded, interrupt
+ * driven environment.
+ */
+
+ if (rtcb->xcp.sigdeliver)
+ {
+ dbg("Delivering signals TCB=%p\n", rtcb);
+ ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb);
+ rtcb->xcp.sigdeliver = NULL;
+ }
+
+ /* Then switch contexts */
+
+ up_longjmp(rtcb->xcp.regs, 1);
+ }
+ }
+ }
+}
diff --git a/arch/sim/src/up_usestack.c b/arch/sim/src/up_usestack.c
new file mode 100644
index 0000000000..26bf14b211
--- /dev/null
+++ b/arch/sim/src/up_usestack.c
@@ -0,0 +1,100 @@
+/************************************************************
+ * up_usestack.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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
+#include
+#include
+#include
+#include "os_internal.h"
+#include "up_internal.h"
+
+/************************************************************
+ * Private Definitions
+ ************************************************************/
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+/************************************************************
+ * Private Funtions
+ ************************************************************/
+
+/************************************************************
+ * Public Funtions
+ ************************************************************/
+
+/************************************************************
+ * Name: up_use_stack
+ *
+ * Description:
+ * Setup up stack-related information in the TCB
+ * using pre-allocated stack memory
+ *
+ * The following TCB fields must be initialized:
+ * adj_stack_size: Stack size after adjustment for hardware,
+ * processor, etc. This value is retained only for debug
+ * purposes.
+ * stack_alloc_ptr: Pointer to allocated stack
+ * adj_stack_ptr: Adjusted StatckAllocPtr for HW. The
+ * initial value of the stack pointer.
+ *
+ * Inputs:
+ * tcb: The TCB of new task
+ * stack_size: The allocated stack size.
+ *
+ ************************************************************/
+
+STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size)
+{
+ /* Move up to next even word boundary if necessary */
+
+ uint32 adj_stack_size = stack_size & ~3;
+ uint32 adj_stack_words = adj_stack_size >> 2;
+
+ /* This is the address of the last word in the allocation */
+
+ uint32 *adj_stack_ptr = &stack[adj_stack_words - 1];
+
+ /* Save the values in the TCB */
+ tcb->adj_stack_size = adj_stack_size;
+ tcb->stack_alloc_ptr = stack;
+ tcb->adj_stack_ptr = adj_stack_ptr;
+ return OK;
+}
diff --git a/drivers/Makefile b/drivers/Makefile
new file mode 100644
index 0000000000..dcd4dec625
--- /dev/null
+++ b/drivers/Makefile
@@ -0,0 +1,74 @@
+############################################################
+# Makefile
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+
+-include $(TOPDIR)/Make.defs
+
+MKDEP = $(TOPDIR)/tools/mkdeps.sh
+
+ASRCS =
+AOBJS = $(ASRCS:.S=.o)
+
+CSRCS = dev_null.c
+COBJS = $(CSRCS:.c=.o)
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+BIN = libdrivers.a
+
+all: $(BIN)
+
+$(AOBJS): %.o: %.S
+ $(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
+
+$(cOBJS): %.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+$(BIN): $(OBJS)
+ $(AR) rcs $@ $(OBJS)
+
+.depend: Makefile $(SRCS)
+ $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ touch $@
+
+depend: .depend
+
+clean:
+ rm -f $(BIN) *.o *~
+
+distclean: clean
+ rm -f Make.dep .depend
+
+-include Make.dep
diff --git a/drivers/dev_null.c b/drivers/dev_null.c
new file mode 100644
index 0000000000..f4211b5138
--- /dev/null
+++ b/drivers/dev_null.c
@@ -0,0 +1,89 @@
+/************************************************************
+ * dev_null.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ************************************************************/
+
+/************************************************************
+ * Compilation Switches
+ ************************************************************/
+
+/************************************************************
+ * Included Files
+ ************************************************************/
+
+#include
+
+#include
+#include
+#include
+#include
+
+/************************************************************
+ * Private Function Prototypes
+ ************************************************************/
+
+static ssize_t devnull_read(struct file *, char *, size_t);
+static ssize_t devnull_write(struct file *, const char *, size_t);
+
+/************************************************************
+ * Private Data
+ ************************************************************/
+
+static struct file_operations devnull_fops =
+{
+ .read = devnull_read,
+ .write = devnull_write,
+};
+
+/************************************************************
+ * Private Functions
+ ************************************************************/
+
+static ssize_t devnull_read(struct file *filp, char *buffer, size_t len)
+{
+ return 0; /* Return EOF */
+}
+
+static ssize_t devnull_write(struct file *filp, const char *buffer, size_t len)
+{
+ return len; /* Say that everything was written */
+}
+
+/************************************************************
+ * Public Functions
+ ************************************************************/
+
+void devnull_register(void)
+{
+ (void)register_inode("/dev/null", &devnull_fops, 0666, NULL);
+}
diff --git a/examples/ostest/Makefile b/examples/ostest/Makefile
new file mode 100644
index 0000000000..85612a9921
--- /dev/null
+++ b/examples/ostest/Makefile
@@ -0,0 +1,75 @@
+############################################################
+# Makefile
+#
+# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt
+#
+# 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.
+#
+############################################################
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+
+MKDEP = $(TOPDIR)/tools/mkdeps.sh
+
+ASRCS =
+AOBJS = $(ASRCS:.S=.o)
+CSRCS = main.c dev_null.c mutex.c cancel.c sem.c cond.c \
+ timedwait.c mqueue.c sighand.c
+COBJS = $(CSRCS:.c=.o)
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+BIN = lib$(CONFIG_EXAMPLE).a
+
+all: $(BIN)
+
+$(AOBJS): %.o: %.S
+ $(CC) -c $(CFLAGS) $< -o $@
+
+$(COBJS): %.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+$(BIN): $(OBJS)
+ $(AR) rcs $@ $(OBJS)
+
+.depend: Makefile $(SRCS)
+ $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ touch $@
+
+depend: .depend
+
+clean:
+ rm -f $(BIN) *.o *~
+
+distclean: clean
+ rm -f Make.dep .depend
+
+-include Make.dep
diff --git a/examples/ostest/cancel.c b/examples/ostest/cancel.c
new file mode 100644
index 0000000000..d52c596fcf
--- /dev/null
+++ b/examples/ostest/cancel.c
@@ -0,0 +1,308 @@
+/***********************************************************************
+ * cancel.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * 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.
+ *
+ ***********************************************************************/
+
+#include
+#include
+#include