2013-07-19 11:43:04 -06:00
|
|
|
/****************************************************************************
|
2021-03-08 18:39:04 -03:00
|
|
|
* arch/arm/src/armv7-a/arm_initialstate.c
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
2024-12-05 14:05:04 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
2021-03-24 09:12:29 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
2021-03-24 09:12:29 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
2021-03-24 09:12:29 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
|
|
|
|
|
|
#include "arm.h"
|
2020-04-30 19:20:29 -06:00
|
|
|
#include "arm_internal.h"
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_initial_state
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2014-06-21 09:55:09 -06:00
|
|
|
* 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.
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
2014-06-21 09:55:09 -06:00
|
|
|
* This function must setup the initial architecture registers and/or
|
|
|
|
|
* stack so that execution will begin at tcb->start on the next context
|
|
|
|
|
* switch.
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void up_initial_state(struct tcb_s *tcb)
|
|
|
|
|
{
|
|
|
|
|
struct xcptcontext *xcp = &tcb->xcp;
|
|
|
|
|
uint32_t cpsr;
|
2023-05-31 14:39:09 +03:00
|
|
|
#ifdef CONFIG_ARCH_KERNEL_STACK
|
|
|
|
|
uint32_t *kstack = xcp->kstack;
|
|
|
|
|
#endif
|
2013-07-19 11:43:04 -06:00
|
|
|
|
2022-03-01 01:06:24 +08:00
|
|
|
/* Initialize the initial exception register context structure */
|
|
|
|
|
|
|
|
|
|
memset(xcp, 0, sizeof(struct xcptcontext));
|
|
|
|
|
|
2020-07-05 13:37:48 +08:00
|
|
|
/* Initialize the idle thread stack */
|
|
|
|
|
|
2022-03-21 23:47:09 +01:00
|
|
|
if (tcb->pid == IDLE_PROCESS_ID)
|
2020-07-05 13:37:48 +08:00
|
|
|
{
|
2020-10-23 11:46:53 +08:00
|
|
|
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
|
|
|
|
|
CONFIG_IDLETHREAD_STACKSIZE);
|
2021-06-08 17:55:04 +08:00
|
|
|
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
|
2020-10-23 11:46:53 +08:00
|
|
|
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
|
2021-06-08 17:55:04 +08:00
|
|
|
|
|
|
|
|
#ifdef CONFIG_STACK_COLORATION
|
|
|
|
|
/* If stack debug is enabled, then fill the stack with a
|
|
|
|
|
* recognizable value that we can use later to test for high
|
|
|
|
|
* water marks.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
arm_stack_color(tcb->stack_alloc_ptr, 0);
|
|
|
|
|
#endif /* CONFIG_STACK_COLORATION */
|
2022-03-01 01:06:24 +08:00
|
|
|
|
|
|
|
|
return;
|
2020-07-05 13:37:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-05-31 14:39:09 +03:00
|
|
|
#ifdef CONFIG_ARCH_KERNEL_STACK
|
|
|
|
|
xcp->kstack = kstack;
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-01 01:06:24 +08:00
|
|
|
/* Initialize the context registers to stack top */
|
2013-07-19 11:43:04 -06:00
|
|
|
|
2022-04-17 13:57:58 +08:00
|
|
|
xcp->regs = (void *)((uint32_t)tcb->stack_base_ptr +
|
|
|
|
|
tcb->adj_stack_size -
|
|
|
|
|
XCPTCONTEXT_SIZE);
|
2022-03-01 01:06:24 +08:00
|
|
|
|
|
|
|
|
/* Initialize the xcp registers */
|
|
|
|
|
|
|
|
|
|
memset(xcp->regs, 0, XCPTCONTEXT_SIZE);
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
/* Save the initial stack pointer */
|
|
|
|
|
|
2022-03-18 00:06:12 +08:00
|
|
|
xcp->regs[REG_SP] = (uint32_t)tcb->stack_base_ptr +
|
|
|
|
|
tcb->adj_stack_size;
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
/* Save the task entry point */
|
|
|
|
|
|
2014-06-21 09:55:09 -06:00
|
|
|
xcp->regs[REG_PC] = (uint32_t)tcb->start;
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
/* If this task is running PIC, then set the PIC base register to the
|
|
|
|
|
* address of the allocated D-Space region.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PIC
|
|
|
|
|
if (tcb->dspace != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* Set the PIC base register (probably R10) to the address of the
|
|
|
|
|
* alloacated D-Space region.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-09-11 18:42:52 -06:00
|
|
|
/* Set supervisor-mode and disable FIQs, regardless of how NuttX is
|
|
|
|
|
* configured and of what kind of thread is being started. That is
|
|
|
|
|
* because all threads, even user-mode threads will start in kernel
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 13:42:51 -06:00
|
|
|
* trampoline at nxtask_start() or pthread_start(). The thread's
|
2014-09-11 18:42:52 -06:00
|
|
|
* privileges will be dropped before transitioning to user code.
|
2013-07-19 11:43:04 -06:00
|
|
|
*/
|
|
|
|
|
|
2022-03-14 10:34:51 +08:00
|
|
|
cpsr = PSR_MODE_SYS;
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
/* Enable or disable interrupts, based on user configuration */
|
|
|
|
|
|
2014-06-21 09:55:09 -06:00
|
|
|
#ifdef CONFIG_SUPPRESS_INTERRUPTS
|
|
|
|
|
/* Disable interrupts (both IRQs and FIQs) */
|
2013-07-19 11:43:04 -06:00
|
|
|
|
2014-06-21 09:55:09 -06:00
|
|
|
cpsr |= (PSR_I_BIT | PSR_F_BIT);
|
|
|
|
|
|
2023-11-27 17:27:48 +08:00
|
|
|
#elif defined(CONFIG_ARCH_TRUSTZONE_SECURE)
|
|
|
|
|
/* In tee, we need to disable the IRQ interrupt to make the A core
|
|
|
|
|
* policy consistent with the M core.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
cpsr |= PSR_I_BIT;
|
|
|
|
|
#elif !defined(CONFIG_ARCH_HIPRI_INTERRUPT)
|
2023-06-27 10:40:06 +08:00
|
|
|
/* Leave IRQs enabled (Also FIQs if CONFIG_ARCH_TRUSTZONE_SECURE or
|
|
|
|
|
* CONFIG_ARCH_HIPRI_INTERRUPT is selected)
|
|
|
|
|
*/
|
2014-06-21 09:55:09 -06:00
|
|
|
|
|
|
|
|
cpsr |= PSR_F_BIT;
|
2023-06-27 10:40:06 +08:00
|
|
|
#endif
|
2014-06-21 09:55:09 -06:00
|
|
|
|
2019-03-19 11:10:41 -06:00
|
|
|
#ifdef CONFIG_ARM_THUMB
|
|
|
|
|
cpsr |= PSR_T_BIT;
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-06-21 09:55:09 -06:00
|
|
|
xcp->regs[REG_CPSR] = cpsr;
|
2013-07-19 11:43:04 -06:00
|
|
|
}
|