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