diff --git a/arch/x86/core/intel64/locore.S b/arch/x86/core/intel64/locore.S index c685c4347bb..c0c0cab393d 100644 --- a/arch/x86/core/intel64/locore.S +++ b/arch/x86/core/intel64/locore.S @@ -175,7 +175,7 @@ __swap: movq $_kernel, %rsi movq _kernel_offset_to_current(%rsi), %rsi - orb $_THREAD_SWAPPED, _thread_offset_to_thread_state(%rsi) + andb $~X86_THREAD_FLAG_ALL, _thread_offset_to_flags(%rsi) movl _k_neg_eagain, %eax movl %eax, _thread_offset_to_rax(%rsi) @@ -219,8 +219,8 @@ __resume: movq _thread_offset_to_r15(%rsi), %r15 movq _thread_offset_to_rax(%rsi), %rax - testb $_THREAD_SWAPPED, _thread_offset_to_thread_state(%rsi) - jnz 1f + testb $X86_THREAD_FLAG_ALL, _thread_offset_to_flags(%rsi) + jz 1f fxrstor _thread_offset_to_sse(%rsi) movq _thread_offset_to_rcx(%rsi), %rcx @@ -466,7 +466,7 @@ irq_enter_nested: /* Nested IRQ: dump register state to stack. */ irq_enter_unnested: /* Not nested: dump state to thread struct for __resume */ movq _kernel_offset_to_current(%rsi), %rsi - andb $(~_THREAD_SWAPPED), _thread_offset_to_thread_state(%rsi) + orb $X86_THREAD_FLAG_ALL, _thread_offset_to_flags(%rsi) fxsave _thread_offset_to_sse(%rsi) movq %rbx, _thread_offset_to_rbx(%rsi) movq %rbp, _thread_offset_to_rbp(%rsi) diff --git a/arch/x86/core/intel64/thread.c b/arch/x86/core/intel64/thread.c index 9a222bb45b4..e84ecfbac4c 100644 --- a/arch/x86/core/intel64/thread.c +++ b/arch/x86/core/intel64/thread.c @@ -30,4 +30,6 @@ void z_new_thread(struct k_thread *thread, k_thread_stack_t *stack, thread->arch.rcx = (long) parameter3; x86_sse_init(thread); + + thread->arch.flags = X86_THREAD_FLAG_ALL; } diff --git a/arch/x86/core/offsets/intel64_offsets.c b/arch/x86/core/offsets/intel64_offsets.c index 74d864d6fc4..81a25d711f0 100644 --- a/arch/x86/core/offsets/intel64_offsets.c +++ b/arch/x86/core/offsets/intel64_offsets.c @@ -18,6 +18,7 @@ GEN_OFFSET_SYM(_callee_saved_t, rip); GEN_OFFSET_SYM(_callee_saved_t, rflags); GEN_OFFSET_SYM(_callee_saved_t, rax); +GEN_OFFSET_SYM(_thread_arch_t, flags); GEN_OFFSET_SYM(_thread_arch_t, rcx); GEN_OFFSET_SYM(_thread_arch_t, rdx); GEN_OFFSET_SYM(_thread_arch_t, rsi); diff --git a/arch/x86/include/intel64/kernel_arch_data.h b/arch/x86/include/intel64/kernel_arch_data.h index c551cd32cf3..18c6ae5ea5b 100644 --- a/arch/x86/include/intel64/kernel_arch_data.h +++ b/arch/x86/include/intel64/kernel_arch_data.h @@ -14,14 +14,6 @@ #define X86_FXSAVE_ALIGN 16 /* ... for FXSAVE/FXRSTOR ops */ #define X86_MXCSR_SANE 0x1dc0 /* enable division-by-zero exception */ -/* - * A flag for k_thread.thread_state to tell __resume that the thread - * voluntarily switched itself out, so only a portion of the register - * state needs to be restored. See kernel_arch_thread.h and locore.S. - */ - -#define _THREAD_SWAPPED BIT(7) - /* * GDT selectors - these must agree with the GDT layout in locore.S. */ diff --git a/arch/x86/include/intel64/kernel_arch_thread.h b/arch/x86/include/intel64/kernel_arch_thread.h index 07d47a5faad..fae7d26716e 100644 --- a/arch/x86/include/intel64/kernel_arch_thread.h +++ b/arch/x86/include/intel64/kernel_arch_thread.h @@ -6,6 +6,8 @@ #ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_THREAD_H_ #define ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_THREAD_H_ +#define X86_THREAD_FLAG_ALL 0x01 /* _thread_arch.flags: entire state saved */ + #ifndef _ASMLANGUAGE #include @@ -14,7 +16,7 @@ /* * The _callee_saved registers are unconditionally saved/restored across * context switches; the _thread_arch registers are only preserved when - * the thread is interrupted. _THREAD_SWAPPED tells __resume when it can + * the thread is interrupted. _arch_thread.flags tells __resume when to * cheat and only restore the first set. For more details see locore.S. */ @@ -34,6 +36,8 @@ struct _callee_saved { typedef struct _callee_saved _callee_saved_t; struct _thread_arch { + u8_t flags; + u64_t rcx; u64_t rdx; u64_t rsi; diff --git a/arch/x86/include/intel64/offsets_short_arch.h b/arch/x86/include/intel64/offsets_short_arch.h index 24b97c8ba37..5da0e111bf8 100644 --- a/arch/x86/include/intel64/offsets_short_arch.h +++ b/arch/x86/include/intel64/offsets_short_arch.h @@ -38,6 +38,9 @@ #define _thread_offset_to_rax \ (___thread_t_callee_saved_OFFSET + ___callee_saved_t_rax_OFFSET) +#define _thread_offset_to_flags \ + (___thread_t_arch_OFFSET + ___thread_arch_t_flags_OFFSET) + #define _thread_offset_to_rcx \ (___thread_t_arch_OFFSET + ___thread_arch_t_rcx_OFFSET)