Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker: introduce boot and pinned regions #34717

Merged
merged 19 commits into from
May 10, 2021
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
kernel: refactor stack declaration macros
These macros are identical except the specified linker region.
So refactor them.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
  • Loading branch information
dcpleung committed May 10, 2021
commit 4be37c2a2111b3dc127f9c2269236fe91f012166
115 changes: 97 additions & 18 deletions include/sys/thread_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,45 @@ static inline char *z_stack_ptr_align(char *ptr)
* @{
*/

/**
* @def Z_KERNEL_STACK_DEFINE_IN
* @brief Define a toplevel kernel stack memory region in specified section
*
* This declares a region of memory for use as a thread stack in
* the specified linker section.
*
* It is legal to precede this definition with the 'static' keyword.
*
* It is NOT legal to take the sizeof(sym) and pass that to the stackSize
* parameter of k_thread_create(), it may not be the same as the
* 'size' parameter. Use K_KERNEL_STACK_SIZEOF() instead.
*
* The total amount of memory allocated may be increased to accommodate
* fixed-size stack overflow guards.
*
* @param sym Thread stack symbol name
* @param size Size of the stack memory region
* @param lsect Linker section for this stack
*/
#define Z_KERNEL_STACK_DEFINE_IN(sym, size, lsect) \
struct z_thread_stack_element lsect \
__aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
sym[Z_KERNEL_STACK_SIZE_ADJUST(size)]

/**
* @def Z_KERNEL_STACK_ARRAY_DEFINE_IN
* @brief Define a toplevel array of kernel stack memory regions in specified section
*
* @param sym Kernel stack array symbol name
* @param nmemb Number of stacks to declare
* @param size Size of the stack memory region
* @param lsect Linker section for this array of stacks
*/
#define Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, lsect) \
struct z_thread_stack_element lsect \
__aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
sym[nmemb][Z_KERNEL_STACK_LEN(size)]

/**
* @def K_KERNEL_STACK_DEFINE
* @brief Define a toplevel kernel stack memory region
Expand All @@ -134,9 +173,7 @@ static inline char *z_stack_ptr_align(char *ptr)
* @param size Size of the stack memory region
*/
#define K_KERNEL_STACK_DEFINE(sym, size) \
struct z_thread_stack_element __kstackmem \
__aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
sym[Z_KERNEL_STACK_SIZE_ADJUST(size)]
Z_KERNEL_STACK_DEFINE_IN(sym, size, __kstackmem)

#define Z_KERNEL_STACK_LEN(size) \
ROUND_UP(Z_KERNEL_STACK_SIZE_ADJUST(size), Z_KERNEL_STACK_OBJ_ALIGN)
Expand All @@ -152,9 +189,7 @@ static inline char *z_stack_ptr_align(char *ptr)
* @param size Size of the stack memory region
*/
#define K_KERNEL_STACK_ARRAY_DEFINE(sym, nmemb, size) \
struct z_thread_stack_element __kstackmem \
__aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
sym[nmemb][Z_KERNEL_STACK_LEN(size)]
Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __kstackmem)

/**
* @def K_KERNEL_STACK_MEMBER
Expand All @@ -167,9 +202,7 @@ static inline char *z_stack_ptr_align(char *ptr)
* @param size Size of the stack memory region
*/
#define K_KERNEL_STACK_MEMBER(sym, size) \
struct z_thread_stack_element \
__aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
sym[Z_KERNEL_STACK_SIZE_ADJUST(size)]
Z_KERNEL_STACK_DEFINE_IN(sym, size,)

#define K_KERNEL_STACK_SIZEOF(sym) (sizeof(sym) - K_KERNEL_STACK_RESERVED)

Expand Down Expand Up @@ -308,6 +341,58 @@ static inline char *Z_KERNEL_STACK_BUFFER(k_thread_stack_t *sym)
*/
#define K_THREAD_STACK_SIZEOF(sym) (sizeof(sym) - K_THREAD_STACK_RESERVED)

/**
* @brief Declare a toplevel thread stack memory region in specified region
*
* This declares a region of memory suitable for use as a thread's stack
* in specified region.
*
* This is the generic, historical definition. Align to Z_THREAD_STACK_OBJ_ALIGN
* and put in 'noinit' section so that it isn't zeroed at boot
*
* The declared symbol will always be a k_thread_stack_t which can be passed to
* k_thread_create(), but should otherwise not be manipulated. If the buffer
* inside needs to be examined, examine thread->stack_info for the associated
* thread object to obtain the boundaries.
*
* It is legal to precede this definition with the 'static' keyword.
*
* It is NOT legal to take the sizeof(sym) and pass that to the stackSize
* parameter of k_thread_create(), it may not be the same as the
* 'size' parameter. Use K_THREAD_STACK_SIZEOF() instead.
*
* Some arches may round the size of the usable stack region up to satisfy
* alignment constraints. K_THREAD_STACK_SIZEOF() will return the aligned
* size.
*
* @param sym Thread stack symbol name
* @param size Size of the stack memory region
* @param lsect Linker section for this stack
*/
#define Z_THREAD_STACK_DEFINE_IN(sym, size, lsect) \
struct z_thread_stack_element lsect \
__aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
sym[Z_THREAD_STACK_SIZE_ADJUST(size)]

/**
* @brief Declare a toplevel array of thread stack memory regions in specified region
*
* Create an array of equally sized stacks. See Z_THREAD_STACK_DEFINE_IN
* definition for additional details and constraints.
*
* This is the generic, historical definition. Align to Z_THREAD_STACK_OBJ_ALIGN
* and put in specified section so that it isn't zeroed at boot
*
* @param sym Thread stack symbol name
* @param nmemb Number of stacks to declare
* @param size Size of the stack memory region
* @param lsect Linker section for this stack
*/
#define Z_THREAD_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, lsect) \
struct z_thread_stack_element lsect \
__aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
sym[nmemb][K_THREAD_STACK_LEN(size)]

/**
* @brief Declare a toplevel thread stack memory region
*
Expand Down Expand Up @@ -335,9 +420,7 @@ static inline char *Z_KERNEL_STACK_BUFFER(k_thread_stack_t *sym)
* @param size Size of the stack memory region
*/
#define K_THREAD_STACK_DEFINE(sym, size) \
struct z_thread_stack_element __stackmem \
__aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
sym[Z_THREAD_STACK_SIZE_ADJUST(size)]
Z_THREAD_STACK_DEFINE_IN(sym, size, __stackmem)

/**
* @brief Calculate size of stacks to be allocated in a stack array
Expand Down Expand Up @@ -370,9 +453,7 @@ static inline char *Z_KERNEL_STACK_BUFFER(k_thread_stack_t *sym)
* @param size Size of the stack memory region
*/
#define K_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \
struct z_thread_stack_element __stackmem \
__aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
sym[nmemb][K_THREAD_STACK_LEN(size)]
Z_THREAD_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __stackmem)

/**
* @brief Declare an embedded stack memory region
Expand All @@ -393,9 +474,7 @@ static inline char *Z_KERNEL_STACK_BUFFER(k_thread_stack_t *sym)
* @param size Size of the stack memory region
*/
#define K_THREAD_STACK_MEMBER(sym, size) \
struct z_thread_stack_element \
__aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
sym[Z_THREAD_STACK_SIZE_ADJUST(size)]
Z_THREAD_STACK_DEFINE_IN(sym, size,)

/** @} */

Expand Down