arch/x86/intel64: do not use thread_state for arch data

k_thread.thread_state (or rather, _thread_base.thread_state) should be
private to the kernel/scheduler, so flags previously stored there are
moved to _thread_arch where the belong.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
This commit is contained in:
Charles E. Youse 2019-09-18 17:55:25 -04:00 committed by Anas Nashif
commit a224998355
6 changed files with 15 additions and 13 deletions

View file

@ -175,7 +175,7 @@ __swap:
movq $_kernel, %rsi movq $_kernel, %rsi
movq _kernel_offset_to_current(%rsi), %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 _k_neg_eagain, %eax
movl %eax, _thread_offset_to_rax(%rsi) movl %eax, _thread_offset_to_rax(%rsi)
@ -219,8 +219,8 @@ __resume:
movq _thread_offset_to_r15(%rsi), %r15 movq _thread_offset_to_r15(%rsi), %r15
movq _thread_offset_to_rax(%rsi), %rax movq _thread_offset_to_rax(%rsi), %rax
testb $_THREAD_SWAPPED, _thread_offset_to_thread_state(%rsi) testb $X86_THREAD_FLAG_ALL, _thread_offset_to_flags(%rsi)
jnz 1f jz 1f
fxrstor _thread_offset_to_sse(%rsi) fxrstor _thread_offset_to_sse(%rsi)
movq _thread_offset_to_rcx(%rsi), %rcx 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 */ irq_enter_unnested: /* Not nested: dump state to thread struct for __resume */
movq _kernel_offset_to_current(%rsi), %rsi 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) fxsave _thread_offset_to_sse(%rsi)
movq %rbx, _thread_offset_to_rbx(%rsi) movq %rbx, _thread_offset_to_rbx(%rsi)
movq %rbp, _thread_offset_to_rbp(%rsi) movq %rbp, _thread_offset_to_rbp(%rsi)

View file

@ -30,4 +30,6 @@ void z_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
thread->arch.rcx = (long) parameter3; thread->arch.rcx = (long) parameter3;
x86_sse_init(thread); x86_sse_init(thread);
thread->arch.flags = X86_THREAD_FLAG_ALL;
} }

View file

@ -18,6 +18,7 @@ GEN_OFFSET_SYM(_callee_saved_t, rip);
GEN_OFFSET_SYM(_callee_saved_t, rflags); GEN_OFFSET_SYM(_callee_saved_t, rflags);
GEN_OFFSET_SYM(_callee_saved_t, rax); 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, rcx);
GEN_OFFSET_SYM(_thread_arch_t, rdx); GEN_OFFSET_SYM(_thread_arch_t, rdx);
GEN_OFFSET_SYM(_thread_arch_t, rsi); GEN_OFFSET_SYM(_thread_arch_t, rsi);

View file

@ -14,14 +14,6 @@
#define X86_FXSAVE_ALIGN 16 /* ... for FXSAVE/FXRSTOR ops */ #define X86_FXSAVE_ALIGN 16 /* ... for FXSAVE/FXRSTOR ops */
#define X86_MXCSR_SANE 0x1dc0 /* enable division-by-zero exception */ #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. * GDT selectors - these must agree with the GDT layout in locore.S.
*/ */

View file

@ -6,6 +6,8 @@
#ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_THREAD_H_ #ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_THREAD_H_
#define 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 #ifndef _ASMLANGUAGE
#include <zephyr/types.h> #include <zephyr/types.h>
@ -14,7 +16,7 @@
/* /*
* The _callee_saved registers are unconditionally saved/restored across * The _callee_saved registers are unconditionally saved/restored across
* context switches; the _thread_arch registers are only preserved when * 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. * 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; typedef struct _callee_saved _callee_saved_t;
struct _thread_arch { struct _thread_arch {
u8_t flags;
u64_t rcx; u64_t rcx;
u64_t rdx; u64_t rdx;
u64_t rsi; u64_t rsi;

View file

@ -38,6 +38,9 @@
#define _thread_offset_to_rax \ #define _thread_offset_to_rax \
(___thread_t_callee_saved_OFFSET + ___callee_saved_t_rax_OFFSET) (___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 \ #define _thread_offset_to_rcx \
(___thread_t_arch_OFFSET + ___thread_arch_t_rcx_OFFSET) (___thread_t_arch_OFFSET + ___thread_arch_t_rcx_OFFSET)