Zephyr Project API 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Intel Corporation
3 * Copyright 2025-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
19
20#ifndef ZEPHYR_INCLUDE_ARCH_ARM_THREAD_H_
21#define ZEPHYR_INCLUDE_ARCH_ARM_THREAD_H_
22
23#ifndef _ASMLANGUAGE
24#include <zephyr/types.h>
25
26/* Cortex M's USE_SWITCH implementation is somewhat unique and doesn't
27 * use much of the thread struct
28 */
29#if defined(CONFIG_CPU_CORTEX_M) && defined(CONFIG_USE_SWITCH)
30#define _ARM_M_SWITCH
31#endif
32
33struct _callee_saved {
34 uint32_t v1; /* r4 */
35 uint32_t v2; /* r5 */
36 uint32_t v3; /* r6 */
37 uint32_t v4; /* r7 */
38 uint32_t v5; /* r8 */
39 uint32_t v6; /* r9 */
40 uint32_t v7; /* r10 */
41 uint32_t v8; /* r11 */
42 uint32_t psp; /* r13 */
43#ifdef CONFIG_USE_SWITCH
44 uint32_t lr; /* lr */
45#endif
46};
47
48typedef struct _callee_saved _callee_saved_t;
49
50#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
51struct _preempt_float {
52#ifndef _ARM_M_SWITCH
53 float s16;
54 float s17;
55 float s18;
56 float s19;
57 float s20;
58 float s21;
59 float s22;
60 float s23;
61 float s24;
62 float s25;
63 float s26;
64 float s27;
65 float s28;
66 float s29;
67 float s30;
68 float s31;
69#endif /* !_ARM_M_SWITCH */
70};
71#endif
72
73#if defined(CONFIG_ARM_PAC_PER_THREAD)
74struct pac_keys {
75 uint32_t key_0;
76 uint32_t key_1;
77 uint32_t key_2;
78 uint32_t key_3;
79};
80#endif
81
82struct _thread_arch {
83
84#ifndef _ARM_M_SWITCH
85 /* interrupt locking key */
86 uint32_t basepri;
87
88 /* r0 in stack frame cannot be written to reliably */
89 uint32_t swap_return_value;
90#endif
91
92#ifdef _ARM_M_SWITCH
93 uint32_t iciit_pc;
94 uint32_t iciit_apsr;
95#endif
96
97#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
98 /*
99 * No cooperative floating point register set structure exists for
100 * the Cortex-M as it automatically saves the necessary registers
101 * in its exception stack frame.
102 */
103 struct _preempt_float preempt_float;
104#endif
105
106#if defined(CONFIG_CPU_AARCH32_CORTEX_A) || defined(CONFIG_CPU_AARCH32_CORTEX_R)
107 int8_t exception_depth;
108#endif
109
110#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
111 /*
112 * Status variable holding several thread status flags
113 * as follows:
114 *
115 * byte 0
116 * +-bits 4-7-----bit-3----------bit-2--------bit-1---+----bit-0------+
117 * : | | | | |
118 * : reserved |<Guard FLOAT>| reserved | reserved | <priv mode> |
119 * : bits | | | | CONTROL.nPRIV |
120 * +------------------------------------------------------------------+
121 *
122 * byte 1
123 * +----------------------------bits 8-15-----------------------------+
124 * : Least significant byte of EXC_RETURN |
125 * : bit 15| bit 14| bit 13 | bit 12| bit 11 | bit 10 | bit 9 | bit 8 |
126 * : Res | S | DCRS | FType | Mode | SPSel | Res | ES |
127 * +------------------------------------------------------------------+
128 *
129 * Bit 0: thread's current privileged mode (Supervisor or User mode)
130 * Mirrors CONTROL.nPRIV flag.
131 * Bit 2: Deprecated in favor of FType. Note: FType = !CONTROL.FPCA.
132 * indicating whether the thread has an active FP context.
133 * Mirrors CONTROL.FPCA flag.
134 * Bit 3: indicating whether the thread is applying the long (FLOAT)
135 * or the default MPU stack guard size.
136 *
137 * Bits 8-15: Least significant octet of the EXC_RETURN value when a
138 * thread is switched-out. The value is copied from LR when
139 * entering the PendSV handler. When the thread is
140 * switched in again, the value is restored to LR before
141 * exiting the PendSV handler.
142 */
143 union {
144 uint32_t mode;
145
146#if defined(CONFIG_ARM_STORE_EXC_RETURN)
147 struct {
148 uint8_t mode_bits;
149 uint8_t mode_exc_return;
150 uint16_t mode_reserved2;
151 };
152#endif
153 };
154
155#if defined(CONFIG_USERSPACE)
156 uint32_t priv_stack_start;
157 uint32_t priv_stack_end;
158#if defined(CONFIG_CPU_AARCH32_CORTEX_R)
159 uint32_t sp_usr;
160#endif
161#endif
162#endif
163
164#if defined(CONFIG_ARM_PAC_PER_THREAD)
165 struct pac_keys pac_keys;
166#endif
167};
168
169#if defined(CONFIG_FPU_SHARING) && defined(CONFIG_MPU_STACK_GUARD)
170#define Z_ARM_MODE_MPU_GUARD_FLOAT_Msk (1 << 3)
171#endif
172typedef struct _thread_arch _thread_arch_t;
173
174#endif /* _ASMLANGUAGE */
175
176#endif /* ZEPHYR_INCLUDE_ARCH_ARM_THREAD_H_ */
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT8_TYPE__ int8_t
Definition stdint.h:72