Zephyr API Documentation 4.4.0
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
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 defined(CONFIG_CPU_AARCH32_ARM9)
108 int8_t exception_depth;
109#endif
110
111#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
112 /*
113 * Status variable holding several thread status flags
114 * as follows:
115 *
116 * byte 0
117 * +-bits 4-7-----bit-3----------bit-2--------bit-1---+----bit-0------+
118 * : | | | | |
119 * : reserved |<Guard FLOAT>| reserved | reserved | <priv mode> |
120 * : bits | | | | CONTROL.nPRIV |
121 * +------------------------------------------------------------------+
122 *
123 * byte 1
124 * +----------------------------bits 8-15-----------------------------+
125 * : Least significant byte of EXC_RETURN |
126 * : bit 15| bit 14| bit 13 | bit 12| bit 11 | bit 10 | bit 9 | bit 8 |
127 * : Res | S | DCRS | FType | Mode | SPSel | Res | ES |
128 * +------------------------------------------------------------------+
129 *
130 * Bit 0: thread's current privileged mode (Supervisor or User mode)
131 * Mirrors CONTROL.nPRIV flag.
132 * Bit 2: Deprecated in favor of FType. Note: FType = !CONTROL.FPCA.
133 * indicating whether the thread has an active FP context.
134 * Mirrors CONTROL.FPCA flag.
135 * Bit 3: indicating whether the thread is applying the long (FLOAT)
136 * or the default MPU stack guard size.
137 *
138 * Bits 8-15: Least significant octet of the EXC_RETURN value when a
139 * thread is switched-out. The value is copied from LR when
140 * entering the PendSV handler. When the thread is
141 * switched in again, the value is restored to LR before
142 * exiting the PendSV handler.
143 */
144 union {
145 uint32_t mode;
146
147#if defined(CONFIG_ARM_STORE_EXC_RETURN)
148 struct {
149 uint8_t mode_bits;
150 uint8_t mode_exc_return;
151 uint16_t mode_reserved2;
152 };
153#endif
154 };
155
156#if defined(CONFIG_USERSPACE)
157 uint32_t priv_stack_start;
158 uint32_t priv_stack_end;
159#if defined(CONFIG_CPU_AARCH32_CORTEX_R)
160 uint32_t sp_usr;
161#endif
162#endif
163#endif
164
165#if defined(CONFIG_ARM_PAC_PER_THREAD)
166 struct pac_keys pac_keys;
167#endif
168};
169
170#if defined(CONFIG_FPU_SHARING) && defined(CONFIG_MPU_STACK_GUARD)
171#define Z_ARM_MODE_MPU_GUARD_FLOAT_Msk (1 << 3)
172#endif
173typedef struct _thread_arch _thread_arch_t;
174
175#endif /* _ASMLANGUAGE */
176
177#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