zephyr/arch/nios2/core/thread.c
Andrew Boie 4e5c093e66 kernel: demote K_THREAD_STACK_BUFFER() to private
This macro is slated for complete removal, as it's not possible
on arches with an MPU stack guard to know the true buffer bounds
without also knowing the runtime state of its associated thread.

As removing this completely would be invasive to where we are
in the 1.14 release, demote to a private kernel Z_ API instead.
The current way that the macro is being used internally will
not cause any undue harm, we just don't want any external code
depending on it.

The final work to remove this (and overhaul stack specification in
general) will take place in 1.15 in the context of #14269

Fixes: #14766

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-05 16:10:02 -04:00

61 lines
1.6 KiB
C

/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <kernel_internal.h>
#include <kernel_structs.h>
#include <wait_q.h>
#include <string.h>
/* forward declaration to asm function to adjust setup the arguments
* to z_thread_entry() since this arch puts the first four arguments
* in r4-r7 and not on the stack
*/
void z_thread_entry_wrapper(k_thread_entry_t, void *, void *, void *);
struct init_stack_frame {
/* top of the stack / most recently pushed */
/* Used by z_thread_entry_wrapper. pulls these off the stack and
* into argument registers before calling z_thread_entry()
*/
k_thread_entry_t entry_point;
void *arg1;
void *arg2;
void *arg3;
/* least recently pushed */
};
void z_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
size_t stack_size, k_thread_entry_t thread_func,
void *arg1, void *arg2, void *arg3,
int priority, unsigned int options)
{
char *stack_memory = Z_THREAD_STACK_BUFFER(stack);
Z_ASSERT_VALID_PRIO(priority, thread_func);
struct init_stack_frame *iframe;
z_new_thread_init(thread, stack_memory, stack_size, priority, options);
/* Initial stack frame data, stored at the base of the stack */
iframe = (struct init_stack_frame *)
STACK_ROUND_DOWN(stack_memory + stack_size - sizeof(*iframe));
/* Setup the initial stack frame */
iframe->entry_point = thread_func;
iframe->arg1 = arg1;
iframe->arg2 = arg2;
iframe->arg3 = arg3;
thread->callee_saved.sp = (u32_t)iframe;
thread->callee_saved.ra = (u32_t)z_thread_entry_wrapper;
thread->callee_saved.key = NIOS2_STATUS_PIE_MSK;
/* Leave the rest of thread->callee_saved junk */
}