Skip to content

Commit 7a5f9e8

Browse files
dcpleungandrewboie
authored andcommitted
x86: define dynamic thread object alignment
x86 and x86_64 require certain alignment in the k_thread struct since the buffer to save/restore FPU/SSE registers requires strict alignment. Fixes #29589 Fixes #29629 Signed-off-by: Daniel Leung <[email protected]>
1 parent fe477ea commit 7a5f9e8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

include/arch/x86/ia32/arch.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,25 @@ extern struct task_state_segment _main_tss;
445445
CODE_UNREACHABLE; \
446446
} while (false)
447447

448+
/*
449+
* Dynamic thread object memory alignment.
450+
*
451+
* If support for SSEx extensions is enabled a 16 byte boundary is required,
452+
* since the 'fxsave' and 'fxrstor' instructions require this. In all other
453+
* cases a 4 byte boundary is sufficient.
454+
*/
455+
#if defined(CONFIG_EAGER_FPU_SHARING) || defined(CONFIG_LAZY_FPU_SHARING)
456+
#ifdef CONFIG_SSE
457+
#define ARCH_DYMANIC_OBJ_K_THREAD_ALIGNMENT 16
458+
#else
459+
#define ARCH_DYMANIC_OBJ_K_THREAD_ALIGNMENT (sizeof(void *))
460+
#endif
461+
#else
462+
/* No special alignment requirements, simply align on pointer size. */
463+
#define ARCH_DYMANIC_OBJ_K_THREAD_ALIGNMENT (sizeof(void *))
464+
#endif /* CONFIG_*_FP_SHARING */
465+
466+
448467
#ifdef __cplusplus
449468
}
450469
#endif

include/arch/x86/intel64/arch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,9 @@ struct x86_ssf {
133133
(void (*)(const void *))isr_p, \
134134
isr_param_p, flags_p)
135135

136+
/*
137+
* Thread object needs to be 16-byte aligned.
138+
*/
139+
#define ARCH_DYMANIC_OBJ_K_THREAD_ALIGNMENT 16
140+
136141
#endif /* ZEPHYR_INCLUDE_ARCH_X86_INTEL64_ARCH_H_ */

0 commit comments

Comments
 (0)