2013-03-21 17:35:08 +00:00
|
|
|
/****************************************************************************
|
2020-04-27 03:25:22 +01:00
|
|
|
* arch/mips/src/common/mips_stackframe.c
|
2013-03-21 17:35:08 +00:00
|
|
|
*
|
2024-12-02 10:36:37 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
2021-03-28 16:10:05 +02: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-03-21 17:35:08 +00:00
|
|
|
*
|
2021-03-28 16:10:05 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-03-21 17:35:08 +00:00
|
|
|
*
|
2021-03-28 16:10:05 +02: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-03-21 17:35:08 +00:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <sched.h>
|
2026-04-01 05:11:15 +05:30
|
|
|
#include <nuttx/debug.h>
|
2013-03-21 17:35:08 +00:00
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
|
|
2020-04-27 03:25:22 +01:00
|
|
|
#include "mips_internal.h"
|
2013-03-21 17:35:08 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-02 17:42:29 -06:00
|
|
|
* Public Functions
|
2013-03-21 17:35:08 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: up_stack_frame
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Allocate a stack frame in the TCB's stack to hold thread-specific data.
|
|
|
|
|
* This function may be called anytime after up_create_stack() or
|
|
|
|
|
* up_use_stack() have been called but before the task has been started.
|
|
|
|
|
*
|
|
|
|
|
* Thread data may be kept in the stack (instead of in the TCB) if it is
|
2013-03-21 20:02:14 +00:00
|
|
|
* accessed by the user code directly. This includes such things as
|
2013-03-21 17:35:08 +00:00
|
|
|
* argv[]. The stack memory is guaranteed to be in the same protection
|
|
|
|
|
* domain as the thread.
|
|
|
|
|
*
|
|
|
|
|
* The following TCB fields will be re-initialized:
|
|
|
|
|
*
|
|
|
|
|
* - adj_stack_size: Stack size after removal of the stack frame from
|
|
|
|
|
* the stack
|
2021-04-12 23:44:08 +08:00
|
|
|
* - stack_base_ptr: Adjusted stack base pointer after the TLS Data and
|
|
|
|
|
* Arguments has been removed from the stack allocation.
|
2013-03-21 17:35:08 +00:00
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Input Parameters:
|
2013-03-21 17:35:08 +00:00
|
|
|
* - tcb: The TCB of new task
|
|
|
|
|
* - frame_size: The size of the stack frame to allocate.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* - A pointer to bottom of the allocated stack frame. NULL will be
|
|
|
|
|
* returned on any failures. The alignment of the returned value is
|
|
|
|
|
* the same as the alignment of the stack itself.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2022-04-17 20:48:23 +08:00
|
|
|
void *up_stack_frame(struct tcb_s *tcb, size_t frame_size)
|
2013-03-21 17:35:08 +00:00
|
|
|
{
|
2022-04-17 20:48:23 +08:00
|
|
|
void *ret;
|
2021-04-12 23:44:08 +08:00
|
|
|
|
2013-03-21 17:35:08 +00:00
|
|
|
/* Align the frame_size */
|
|
|
|
|
|
2025-05-16 21:06:21 +08:00
|
|
|
frame_size = STACKFRAME_ALIGN_UP(frame_size);
|
2014-04-13 16:22:22 -06:00
|
|
|
|
2013-03-21 17:35:08 +00:00
|
|
|
/* Is there already a stack allocated? Is it big enough? */
|
|
|
|
|
|
|
|
|
|
if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 23:44:08 +08:00
|
|
|
ret = tcb->stack_base_ptr;
|
|
|
|
|
memset(ret, 0, frame_size);
|
2013-03-21 23:37:11 +00:00
|
|
|
|
2021-04-12 23:44:08 +08:00
|
|
|
/* Save the adjusted stack values in the struct tcb_s */
|
2013-03-21 23:37:11 +00:00
|
|
|
|
2022-04-17 20:48:23 +08:00
|
|
|
tcb->stack_base_ptr = (uint8_t *)tcb->stack_base_ptr + frame_size;
|
2021-04-12 23:44:08 +08:00
|
|
|
tcb->adj_stack_size -= frame_size;
|
2013-03-21 23:37:11 +00:00
|
|
|
|
|
|
|
|
/* And return the pointer to the allocated region */
|
2013-03-21 17:35:08 +00:00
|
|
|
|
2021-04-12 23:44:08 +08:00
|
|
|
return ret;
|
2013-03-21 17:35:08 +00:00
|
|
|
}
|