2014-08-23 18:59:24 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* arch/arm/src/armv7/arm_addrenv.c
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Address Environment Interfaces
|
|
|
|
|
*
|
|
|
|
|
* Low-level interfaces used in binfmt/ to instantiate tasks with address
|
|
|
|
|
* environments. These interfaces all operate on type group_addrenv_t which
|
|
|
|
|
* is an abstract representation of a task group's address environment and
|
2014-08-24 06:42:11 -06:00
|
|
|
* must be defined in arch/arch.h if CONFIG_ARCH_ADDRENV is defined.
|
2014-08-23 18:59:24 -06:00
|
|
|
*
|
|
|
|
|
* up_addrenv_create - Create an address environment
|
|
|
|
|
* up_addrenv_destroy - Destroy an address environment.
|
2014-08-24 11:54:14 -06:00
|
|
|
* up_addrenv_vtext - Returns the virtual base address of the .text
|
|
|
|
|
* address environment
|
|
|
|
|
* up_addrenv_vdata - Returns the virtual base address of the .bss/.data
|
|
|
|
|
* address environment
|
2014-08-23 18:59:24 -06:00
|
|
|
* up_addrenv_select - Instantiate an address environment
|
|
|
|
|
* up_addrenv_restore - Restore an address environment
|
|
|
|
|
* up_addrenv_assign - Assign an address environment to a group
|
|
|
|
|
*
|
|
|
|
|
* Higher-level interfaces used by the tasking logic. These interfaces are
|
|
|
|
|
* used by the functions in sched/ and all operate on the thread which whose
|
|
|
|
|
* group been assigned an address environment by up_addrenv_assign().
|
|
|
|
|
*
|
|
|
|
|
* up_addrenv_attach - Clone the address environment assigned to one TCB
|
|
|
|
|
* to another. This operation is done when a pthread
|
|
|
|
|
* is created that share's the same address
|
|
|
|
|
* environment.
|
|
|
|
|
* up_addrenv_detach - Release the threads reference to an address
|
|
|
|
|
* environment when a task/thread exits.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
2014-08-24 11:54:14 -06:00
|
|
|
#include <string.h>
|
2014-08-23 18:59:24 -06:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
2014-08-24 09:57:53 -06:00
|
|
|
#include <nuttx/addrenv.h>
|
2014-08-23 18:59:24 -06:00
|
|
|
#include <arch/arch.h>
|
|
|
|
|
|
2014-08-24 06:42:11 -06:00
|
|
|
#ifdef CONFIG_ARCH_ADDRENV
|
2014-08-23 18:59:24 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Pre-processor Definitions
|
|
|
|
|
****************************************************************************/
|
2014-08-24 09:57:53 -06:00
|
|
|
/* Configuration ************************************************************/
|
2014-08-23 18:59:24 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Data
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_create
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is called when a new task is created in order to
|
2014-08-24 09:57:53 -06:00
|
|
|
* instantiate an address environment for the new task group.
|
2014-08-23 18:59:24 -06:00
|
|
|
* up_addrenv_create() is essentially the allocator of the physical
|
|
|
|
|
* memory for the new task.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
2014-08-24 11:54:14 -06:00
|
|
|
* textsize - The size (in bytes) of the .text address environment needed
|
|
|
|
|
* by the task. This region may be read/execute only.
|
|
|
|
|
* datasize - The size (in bytes) of the .data/.bss address environment
|
|
|
|
|
* needed by the task. This region may be read/write only.
|
2014-08-23 18:59:24 -06:00
|
|
|
* addrenv - The location to return the representation of the task address
|
|
|
|
|
* environment.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-08-24 11:54:14 -06:00
|
|
|
int up_addrenv_create(size_t textsize, size_t datasize,
|
|
|
|
|
FAR group_addrenv_t *addrenv)
|
2014-08-23 18:59:24 -06:00
|
|
|
{
|
|
|
|
|
#warning Missing logic
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_destroy
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is called when a final thread leaves the task group and
|
|
|
|
|
* the task group is destroyed. This function then destroys the defunct
|
|
|
|
|
* address environment, releasing the underlying physical memory.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* addrenv - The address environment to be destroyed.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int up_addrenv_destroy(group_addrenv_t addrenv)
|
|
|
|
|
{
|
|
|
|
|
#warning Missing logic
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-08-24 11:54:14 -06:00
|
|
|
* Name: up_addrenv_vtext
|
2014-08-23 18:59:24 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
2014-08-24 11:54:14 -06:00
|
|
|
* Return the virtual address associated with the newly create .text
|
|
|
|
|
* address environment. This function is used by the binary loaders in
|
|
|
|
|
* order get an address that can be used to initialize the new task.
|
2014-08-23 18:59:24 -06:00
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* addrenv - The representation of the task address environment previously
|
|
|
|
|
* returned by up_addrenv_create.
|
2014-08-24 11:54:14 -06:00
|
|
|
* vtext - The location to return the virtual address.
|
2014-08-23 18:59:24 -06:00
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-08-24 11:54:14 -06:00
|
|
|
int up_addrenv_vtext(FAR group_addrenv_t addrenv, FAR void **vtext)
|
2014-08-23 18:59:24 -06:00
|
|
|
{
|
2014-08-24 11:54:14 -06:00
|
|
|
/* Not much to do in this case */
|
|
|
|
|
|
|
|
|
|
DEBUGASSERT(addrenv && vtext);
|
|
|
|
|
*vtext = (FAR void *)CONFIG_ARCH_TEXT_VBASE;
|
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_vdata
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Return the virtual address associated with the newly create .text
|
|
|
|
|
* address environment. This function is used by the binary loaders in
|
|
|
|
|
* order get an address that can be used to initialize the new task.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* addrenv - The representation of the task address environment previously
|
|
|
|
|
* returned by up_addrenv_create.
|
|
|
|
|
* textsize - For some implementations, the text and data will be saved
|
|
|
|
|
* in the same memory region (read/write/execute) and, in this case,
|
|
|
|
|
* the virtual address of the data just lies at this offset into the
|
|
|
|
|
* common region.
|
|
|
|
|
* vdata - The location to return the virtual address.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int up_addrenv_vdata(FAR group_addrenv_t addrenv, uintptr_t textsize,
|
|
|
|
|
FAR void **vdata)
|
|
|
|
|
{
|
|
|
|
|
/* Not much to do in this case */
|
|
|
|
|
|
|
|
|
|
DEBUGASSERT(addrenv && vdata);
|
|
|
|
|
*vdata = (FAR void *)CONFIG_ARCH_DATA_VBASE;
|
|
|
|
|
return OK;
|
2014-08-23 18:59:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_select
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* After an address environment has been established for a task group (via
|
|
|
|
|
* up_addrenv_create(). This function may be called to to instantiate
|
|
|
|
|
* that address environment in the virtual address space. this might be
|
|
|
|
|
* necessary, for example, to load the code for the task group from a file or
|
|
|
|
|
* to access address environment private data.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* addrenv - The representation of the task address environment previously
|
|
|
|
|
* returned by up_addrenv_create.
|
|
|
|
|
* oldenv
|
|
|
|
|
* The address environment that was in place before up_addrenv_select().
|
|
|
|
|
* This may be used with up_addrenv_restore() to restore the original
|
|
|
|
|
* address environment that was in place before up_addrenv_select() was
|
2014-08-24 11:54:14 -06:00
|
|
|
* called. Note that this may be a task agnostic, platform-specific
|
|
|
|
|
* representation that may or may not be different from group_addrenv_t.
|
2014-08-23 18:59:24 -06:00
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-08-24 09:57:53 -06:00
|
|
|
int up_addrenv_select(group_addrenv_t addrenv, save_addrenv_t *oldenv)
|
2014-08-23 18:59:24 -06:00
|
|
|
{
|
|
|
|
|
#warning Missing logic
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_restore
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* After an address environment has been temporarily instantiated by
|
|
|
|
|
* up_addrenv_select(), this function may be called to to restore the
|
|
|
|
|
* original address environment.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
2014-08-24 11:54:14 -06:00
|
|
|
* oldenv - The platform-specific representation of the address environment
|
2014-08-23 18:59:24 -06:00
|
|
|
* previously returned by up_addrenv_select.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-08-24 09:57:53 -06:00
|
|
|
int up_addrenv_restore(save_addrenv_t oldenv)
|
2014-08-23 18:59:24 -06:00
|
|
|
{
|
|
|
|
|
#warning Missing logic
|
|
|
|
|
return -ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_assign
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Assign an address environment to a new task group.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* addrenv - The representation of the task address environment previously
|
|
|
|
|
* returned by up_addrenv_create().
|
|
|
|
|
* group - The new task group to receive the address environment.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-08-24 11:54:14 -06:00
|
|
|
int up_addrenv_assign(FAR const group_addrenv_t *addrenv,
|
|
|
|
|
FAR struct task_group_s *group)
|
2014-08-23 18:59:24 -06:00
|
|
|
{
|
2014-08-24 11:54:14 -06:00
|
|
|
DEBUGASSERT(addrenv && group);
|
|
|
|
|
|
|
|
|
|
/* Just copy the addess environment into the group */
|
|
|
|
|
|
|
|
|
|
memcpy(&group->addrenv, addrenv, sizeof(group_addrenv_t));
|
|
|
|
|
return OK;
|
2014-08-23 18:59:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_attach
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is called from the core scheduler logic when a thread
|
|
|
|
|
* is created that needs to share the address environment of its task
|
|
|
|
|
* group.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: In some platforms, nothing will need to be done in this case.
|
|
|
|
|
* Simply being a member of the group that has the address environment
|
|
|
|
|
* may be sufficient.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* group - The task group to which the new thread belongs.
|
|
|
|
|
* tcb - The TCB of the thread needing the address environment.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int up_addrenv_attach(FAR struct task_group_s *group, FAR struct tcb_s *tcb)
|
|
|
|
|
{
|
2014-08-24 11:54:14 -06:00
|
|
|
/* Nothing needs to be done in this implementation */
|
|
|
|
|
|
|
|
|
|
return OK;
|
2014-08-23 18:59:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_addrenv_detach
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is called when a task or thread exits in order to release
|
|
|
|
|
* its reference to an address environment. The address environment,
|
|
|
|
|
* however, should persist until up_addrenv_destroy() is called when the
|
|
|
|
|
* task group is itself destroyed. Any resources unique to this thread
|
|
|
|
|
* may be destroyed now.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: In some platforms, nothing will need to be done in this case.
|
|
|
|
|
* Simply being a member of the group that has the address environment
|
|
|
|
|
* may be sufficient.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* group - The group to which the thread belonged.
|
|
|
|
|
* tcb - The TCB of the task or thread whose the address environment will
|
|
|
|
|
* be released.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int up_addrenv_detach(FAR struct task_group_s *group, FAR struct tcb_s *tcb)
|
|
|
|
|
{
|
2014-08-24 11:54:14 -06:00
|
|
|
/* Nothing needs to be done in this implementation */
|
|
|
|
|
|
|
|
|
|
return OK;
|
2014-08-23 18:59:24 -06:00
|
|
|
}
|
|
|
|
|
|
2014-08-24 06:42:11 -06:00
|
|
|
#endif /* CONFIG_ARCH_ADDRENV */
|