Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
thread_stack.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ARCH_ARM64_THREAD_STACK_H_
8#define ZEPHYR_INCLUDE_ARCH_ARM64_THREAD_STACK_H_
9
12
13#define ARCH_STACK_PTR_ALIGN 16
14
15#if defined(CONFIG_USERSPACE) || defined(CONFIG_ARM64_STACK_PROTECTION)
16#define Z_ARM64_STACK_BASE_ALIGN MEM_DOMAIN_ALIGN_AND_SIZE
17#define Z_ARM64_STACK_SIZE_ALIGN MEM_DOMAIN_ALIGN_AND_SIZE
18#else
19#define Z_ARM64_STACK_BASE_ALIGN ARCH_STACK_PTR_ALIGN
20#define Z_ARM64_STACK_SIZE_ALIGN ARCH_STACK_PTR_ALIGN
21#endif
22
23#if defined(CONFIG_ARM64_STACK_PROTECTION)
24#define Z_ARM64_STACK_GUARD_SIZE MEM_DOMAIN_ALIGN_AND_SIZE
25#define Z_ARM64_K_STACK_BASE_ALIGN MEM_DOMAIN_ALIGN_AND_SIZE
26#else
27#define Z_ARM64_STACK_GUARD_SIZE 0
28#if defined(CONFIG_SMP)
29/* secondary cores invalidate their boot stack, which must own whole lines */
30#define Z_ARM64_K_STACK_BASE_ALIGN L1_CACHE_BYTES
31#else
32#define Z_ARM64_K_STACK_BASE_ALIGN ARCH_STACK_PTR_ALIGN
33#endif
34#endif
35
36/*
37 * [ see also comments in arch/arm64/core/thread.c ]
38 *
39 * High memory addresses
40 *
41 * +-------------------+ <- thread.stack_info.start + thread.stack_info.size
42 * | TLS |
43 * +-------------------+ <- initial sp (computable with thread.stack_info.delta)
44 * | |
45 * | Used stack |
46 * | |
47 * +...................+ <- thread's current stack pointer
48 * | |
49 * | Unused stack |
50 * | |
51 * +-------------------+ <- thread.stack_info.start
52 * | Privileged stack | } K_(THREAD|KERNEL)_STACK_RESERVED
53 * +-------------------+ <- thread stack limit (update on every context switch)
54 * | Stack guard | } Z_ARM64_STACK_GUARD_SIZE (protected by MMU/MPU)
55 * +-------------------+ <- thread.stack_obj
56 *
57 * Low Memory addresses
58 */
59
60/* thread stack */
61#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_ARM64_STACK_BASE_ALIGN
62#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
63 ROUND_UP((size), Z_ARM64_STACK_SIZE_ALIGN)
64#define ARCH_THREAD_STACK_RESERVED \
65 ROUND_UP(CONFIG_PRIVILEGED_STACK_SIZE + Z_ARM64_STACK_GUARD_SIZE, \
66 Z_ARM64_STACK_SIZE_ALIGN)
67
68/* kernel stack */
69#define ARCH_KERNEL_STACK_RESERVED Z_ARM64_STACK_GUARD_SIZE
70#define ARCH_KERNEL_STACK_OBJ_ALIGN Z_ARM64_K_STACK_BASE_ALIGN
71
72#ifndef _ASMLANGUAGE
73
74struct z_arm64_thread_stack_header {
75 char privilege_stack[CONFIG_PRIVILEGED_STACK_SIZE];
76} __packed __aligned(Z_ARM64_STACK_BASE_ALIGN);
77
78#endif /* _ASMLANGUAGE */
79
80#endif /* ZEPHYR_INCLUDE_ARCH_ARM64_THREAD_STACK_H_ */