Skip to content

Commit 483124b

Browse files
wearyzennashif
authored andcommitted
arch: arm: fix start of the privileged stack
Make sure that arch.mode is set with appropriate flags before setting up the privileged stack start. Fixes #99895 Signed-off-by: Sudan Landge <[email protected]> (cherry picked from commit 9962bc1)
1 parent 0004e41 commit 483124b

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

arch/arm/core/cortex_a_r/thread.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
107107
#endif /* FP_GUARD_EXTRA_SIZE */
108108
#endif /* CONFIG_MPU_STACK_GUARD */
109109

110+
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
111+
thread->arch.mode = 0;
112+
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
113+
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
114+
#endif
115+
#if FP_GUARD_EXTRA_SIZE > 0
116+
if ((thread->base.user_options & K_FP_REGS) != 0) {
117+
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
118+
}
119+
#endif
120+
#endif
121+
110122
iframe = Z_STACK_PTR_TO_FRAME(struct __basic_sf, stack_ptr);
111123
#if defined(CONFIG_USERSPACE)
112124
thread->arch.priv_stack_start = 0;
@@ -144,17 +156,6 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
144156
thread->callee_saved.psp = (uint32_t)iframe;
145157
thread->arch.basepri = 0;
146158

147-
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
148-
thread->arch.mode = 0;
149-
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
150-
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
151-
#endif
152-
#if FP_GUARD_EXTRA_SIZE > 0
153-
if ((thread->base.user_options & K_FP_REGS) != 0) {
154-
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
155-
}
156-
#endif
157-
#endif
158159
/*
159160
* initial values in all other registers/thread entries are
160161
* irrelevant.

arch/arm/core/cortex_m/thread.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
116116
#endif /* FP_GUARD_EXTRA_SIZE */
117117
#endif /* CONFIG_MPU_STACK_GUARD */
118118

119+
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
120+
thread->arch.mode = 0;
121+
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
122+
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
123+
#endif
124+
#if FP_GUARD_EXTRA_SIZE > 0
125+
if ((thread->base.user_options & K_FP_REGS) != 0) {
126+
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
127+
}
128+
#endif
129+
#endif
130+
119131
iframe = Z_STACK_PTR_TO_FRAME(struct __basic_sf, stack_ptr);
120132
#if defined(CONFIG_USERSPACE)
121133
thread->arch.priv_stack_start = 0;
@@ -143,17 +155,6 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
143155
thread->callee_saved.psp = (uint32_t)iframe;
144156
thread->arch.basepri = 0;
145157

146-
#if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
147-
thread->arch.mode = 0;
148-
#if defined(CONFIG_ARM_STORE_EXC_RETURN)
149-
thread->arch.mode_exc_return = DEFAULT_EXC_RETURN;
150-
#endif
151-
#if FP_GUARD_EXTRA_SIZE > 0
152-
if ((thread->base.user_options & K_FP_REGS) != 0) {
153-
thread->arch.mode |= Z_ARM_MODE_MPU_GUARD_FLOAT_Msk;
154-
}
155-
#endif
156-
#endif
157158
/*
158159
* initial values in all other registers/thread entries are
159160
* irrelevant.

0 commit comments

Comments
 (0)