diff --git a/arch/x86/core/intel64/locore.S b/arch/x86/core/intel64/locore.S index aed28fd2861..67846b16cd9 100644 --- a/arch/x86/core/intel64/locore.S +++ b/arch/x86/core/intel64/locore.S @@ -189,12 +189,16 @@ mxcsr: .long X86_MXCSR_SANE * 'struct k_thread', thus: * * RDI = (struct k_thread *) switch_to - * RSI = (struct k_thread **) switched_from + * RSI = (struct k_thread **) address of output thread switch_handle field */ .globl z_x86_switch z_x86_switch: - movq (%rsi), %rsi + /* RSI contains the switch_handle field to which we are + * notionally supposed to store. Offset it to get back to the + * thread handle instead. + */ + subq $___thread_t_switch_handle_OFFSET, %rsi andb $~X86_THREAD_FLAG_ALL, _thread_offset_to_flags(%rsi) diff --git a/kernel/include/kernel_offsets.h b/kernel/include/kernel_offsets.h index edca4b1d592..8e233b1e9d0 100644 --- a/kernel/include/kernel_offsets.h +++ b/kernel/include/kernel_offsets.h @@ -64,6 +64,10 @@ GEN_OFFSET_SYM(_thread_t, base); GEN_OFFSET_SYM(_thread_t, callee_saved); GEN_OFFSET_SYM(_thread_t, arch); +#ifdef CONFIG_USE_SWITCH +GEN_OFFSET_SYM(_thread_t, switch_handle); +#endif + #ifdef CONFIG_THREAD_STACK_INFO GEN_OFFSET_SYM(_thread_stack_info_t, start); GEN_OFFSET_SYM(_thread_stack_info_t, size);