Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#ifndef ZEPHYR_INCLUDE_ARCH_X86_INTEL64_THREAD_H_
7#define ZEPHYR_INCLUDE_ARCH_X86_INTEL64_THREAD_H_
8
9#define X86_THREAD_FLAG_ALL 0x01 /* _thread_arch.flags: entire state saved */
10
11/*
12 * GDT selectors - these must agree with the GDT layout in locore.S.
13 */
14
15#define X86_KERNEL_CS_32 0x08 /* 32-bit kernel code */
16#define X86_KERNEL_DS_32 0x10 /* 32-bit kernel data */
17#define X86_KERNEL_CS 0x18 /* 64-bit kernel code */
18#define X86_KERNEL_DS 0x20 /* 64-bit kernel data */
19#define X86_USER_CS_32 0x28 /* 32-bit user data (unused) */
20#define X86_USER_DS 0x30 /* 64-bit user mode data */
21#define X86_USER_CS 0x38 /* 64-bit user mode code */
22
23/* Value programmed into bits 63:32 of STAR MSR with proper segment
24 * descriptors for implementing user mode with syscall/sysret
25 */
26#define X86_STAR_UPPER ((X86_USER_CS_32 << 16) | X86_KERNEL_CS)
27
28#define X86_KERNEL_CPU0_TR 0x40 /* 64-bit task state segment */
29#define X86_KERNEL_CPU1_TR 0x50 /* 64-bit task state segment */
30#define X86_KERNEL_CPU2_TR 0x60 /* 64-bit task state segment */
31#define X86_KERNEL_CPU3_TR 0x70 /* 64-bit task state segment */
32
33/*
34 * Some SSE definitions. Ideally these will ultimately be shared with 32-bit.
35 */
36
37#define X86_FXSAVE_SIZE 512 /* size and alignment of buffer ... */
38#define X86_FXSAVE_ALIGN 16 /* ... for FXSAVE/FXRSTOR ops */
39
40/* MXCSR Control and Status Register for SIMD floating-point operations.
41 * Set default value 1F80H according to the Intel(R) 64 and IA-32 Manual.
42 * Disable denormals-are-zeros mode.
43 */
44#define X86_MXCSR_SANE 0x1f80
45
46#ifndef _ASMLANGUAGE
47
48#include <zephyr/types.h>
50
51/*
52 * 64-bit Task State Segment. One defined per CPU.
53 */
54
55struct x86_tss64 {
56 /*
57 * Architecturally-defined portion. It is somewhat tedious to
58 * enumerate each member specifically (rather than using arrays)
59 * but we need to get (some of) their offsets from assembly.
60 */
61
63
64 uint64_t rsp0; /* privileged stacks */
67
69
70 uint64_t ist1; /* interrupt stacks */
77
79
80 uint16_t iomapb; /* offset to I/O base */
81
82 /*
83 * Zephyr specific portion. Stash per-CPU data here for convenience.
84 */
85
86 struct _cpu *cpu;
87#ifdef CONFIG_HW_SHADOW_STACK
88 uintptr_t *shstk_addr;
89 uintptr_t exception_shstk_addr;
90#endif
91
92#ifdef CONFIG_USERSPACE
93 /* Privilege mode stack pointer value when doing a system call */
94 char *psp;
95
96 /* Storage area for user mode stack pointer when doing a syscall */
97 char *usp;
98#endif /* CONFIG_USERSPACE */
99} __packed __aligned(8);
100
101typedef struct x86_tss64 x86_tss64_t;
102
103/*
104 * The _callee_saved registers are unconditionally saved/restored across
105 * context switches; the _thread_arch registers are only preserved when
106 * the thread is interrupted. _arch_thread.flags tells __resume when to
107 * cheat and only restore the first set. For more details see locore.S.
108 */
109
110struct _callee_saved {
111 uint64_t rsp;
112 uint64_t rbx;
113 uint64_t rbp;
114 uint64_t r12;
115 uint64_t r13;
116 uint64_t r14;
117 uint64_t r15;
118 uint64_t rip;
119 uint64_t rflags;
120};
121
122typedef struct _callee_saved _callee_saved_t;
123
124struct _thread_arch {
125 uint8_t flags;
126
127#ifdef CONFIG_USERSPACE
128#ifndef CONFIG_X86_COMMON_PAGE_TABLE
129 /* Physical address of the page tables used by this thread */
130 uintptr_t ptables;
131#endif /* CONFIG_X86_COMMON_PAGE_TABLE */
132
133 /* Initial privilege mode stack pointer when doing a system call.
134 * Un-set for supervisor threads.
135 */
136 char *psp;
137
138 /* SS and CS selectors for this thread when restoring context */
139 uint64_t ss;
140 uint64_t cs;
141#endif
142
143#ifdef CONFIG_HW_SHADOW_STACK
144 uintptr_t *shstk_addr;
145 uintptr_t *shstk_base;
146 size_t shstk_size;
147#endif
148
149 uint64_t rax;
150 uint64_t rcx;
151 uint64_t rdx;
152 uint64_t rsi;
153 uint64_t rdi;
154 uint64_t r8;
155 uint64_t r9;
156 uint64_t r10;
157 uint64_t r11;
158 char __aligned(X86_FXSAVE_ALIGN) sse[X86_FXSAVE_SIZE];
159};
160
161typedef struct _thread_arch _thread_arch_t;
162
163#endif /* _ASMLANGUAGE */
164
165#endif /* ZEPHYR_INCLUDE_ARCH_X86_INTEL64_THREAD_H_ */
#define X86_FXSAVE_ALIGN
Definition thread.h:38
#define X86_FXSAVE_SIZE
Definition thread.h:37
struct x86_tss64 x86_tss64_t
Definition thread.h:101
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Definition thread.h:55
uint64_t ist2
Definition thread.h:71
uint64_t ist6
Definition thread.h:75
struct _cpu * cpu
Definition thread.h:86
uint64_t rsp1
Definition thread.h:65
uint8_t reserved0[4]
Definition thread.h:62
uint8_t reserved1[10]
Definition thread.h:78
uint64_t ist4
Definition thread.h:73
uint64_t ist7
Definition thread.h:76
uint64_t ist3
Definition thread.h:72
char * psp
Definition thread.h:94
uint64_t rsp2
Definition thread.h:66
uint64_t ist1
Definition thread.h:70
uint64_t rsp0
Definition thread.h:64
uint64_t ist5
Definition thread.h:74
uint16_t iomapb
Definition thread.h:80
uint8_t reserved[8]
Definition thread.h:68
char * usp
Definition thread.h:97