Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
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
#define X86_MXCSR_SANE 0x1dc0
/* enable division-by-zero exception */
40
41
#ifndef _ASMLANGUAGE
42
43
#include <
zephyr/types.h
>
44
#include <
arch/x86/mmustructs.h
>
45
46
/*
47
* 64-bit Task State Segment. One defined per CPU.
48
*/
49
50
struct
x86_tss64
{
51
/*
52
* Architecturally-defined portion. It is somewhat tedious to
53
* enumerate each member specifically (rather than using arrays)
54
* but we need to get (some of) their offsets from assembly.
55
*/
56
57
uint8_t
reserved0
[4];
58
59
uint64_t
rsp0
;
/* privileged stacks */
60
uint64_t
rsp1
;
61
uint64_t
rsp2
;
62
63
uint8_t
reserved
[8];
64
65
uint64_t
ist1
;
/* interrupt stacks */
66
uint64_t
ist2
;
67
uint64_t
ist3
;
68
uint64_t
ist4
;
69
uint64_t
ist5
;
70
uint64_t
ist6
;
71
uint64_t
ist7
;
72
73
uint8_t
reserved1
[10];
74
75
uint16_t
iomapb
;
/* offset to I/O base */
76
77
/*
78
* Zephyr specific portion. Stash per-CPU data here for convenience.
79
*/
80
81
struct
_cpu *
cpu
;
82
#ifdef CONFIG_USERSPACE
83
/* Privilege mode stack pointer value when doing a system call */
84
char
*
psp
;
85
86
/* Storage area for user mode stack pointer when doing a syscall */
87
char
*
usp
;
88
#endif
/* CONFIG_USERSPACE */
89
} __packed __aligned(8);
90
91
typedef
struct
x86_tss64
x86_tss64_t
;
92
93
/*
94
* The _callee_saved registers are unconditionally saved/restored across
95
* context switches; the _thread_arch registers are only preserved when
96
* the thread is interrupted. _arch_thread.flags tells __resume when to
97
* cheat and only restore the first set. For more details see locore.S.
98
*/
99
100
struct
_callee_saved {
101
uint64_t
rsp;
102
uint64_t
rbx;
103
uint64_t
rbp;
104
uint64_t
r12;
105
uint64_t
r13;
106
uint64_t
r14;
107
uint64_t
r15;
108
uint64_t
rip;
109
uint64_t
rflags;
110
};
111
112
typedef
struct
_callee_saved _callee_saved_t;
113
114
struct
_thread_arch {
115
uint8_t
flags
;
116
117
#ifdef CONFIG_USERSPACE
118
#ifndef CONFIG_X86_COMMON_PAGE_TABLE
119
/* Physical address of the page tables used by this thread */
120
uintptr_t
ptables;
121
#endif
/* CONFIG_X86_COMMON_PAGE_TABLE */
122
123
/* Initial privilege mode stack pointer when doing a system call.
124
* Un-set for supervisor threads.
125
*/
126
char
*psp;
127
128
/* SS and CS selectors for this thread when restoring context */
129
uint64_t
ss;
130
uint64_t
cs;
131
#endif
132
133
uint64_t
rax;
134
uint64_t
rcx;
135
uint64_t
rdx;
136
uint64_t
rsi;
137
uint64_t
rdi;
138
uint64_t
r8;
139
uint64_t
r9;
140
uint64_t
r10;
141
uint64_t
r11;
142
char
__aligned(
X86_FXSAVE_ALIGN
) sse[
X86_FXSAVE_SIZE
];
143
};
144
145
typedef
struct
_thread_arch _thread_arch_t;
146
147
#endif
/* _ASMLANGUAGE */
148
149
#endif
/* ZEPHYR_INCLUDE_ARCH_X86_INTEL64_THREAD_H_ */
X86_FXSAVE_ALIGN
#define X86_FXSAVE_ALIGN
Definition:
thread.h:38
X86_FXSAVE_SIZE
#define X86_FXSAVE_SIZE
Definition:
thread.h:37
flags
flags
Definition:
http_parser.h:131
types.h
mmustructs.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition:
stdint.h:61
uint8_t
__UINT8_TYPE__ uint8_t
Definition:
stdint.h:58
uintptr_t
__UINTPTR_TYPE__ uintptr_t
Definition:
stdint.h:75
uint16_t
__UINT16_TYPE__ uint16_t
Definition:
stdint.h:59
x86_tss64
Definition:
thread.h:50
x86_tss64::ist2
uint64_t ist2
Definition:
thread.h:66
x86_tss64::ist6
uint64_t ist6
Definition:
thread.h:70
x86_tss64::cpu
struct _cpu * cpu
Definition:
thread.h:81
x86_tss64::rsp1
uint64_t rsp1
Definition:
thread.h:60
x86_tss64::reserved0
uint8_t reserved0[4]
Definition:
thread.h:57
x86_tss64::reserved1
uint8_t reserved1[10]
Definition:
thread.h:73
x86_tss64::ist4
uint64_t ist4
Definition:
thread.h:68
x86_tss64::ist7
uint64_t ist7
Definition:
thread.h:71
x86_tss64::ist3
uint64_t ist3
Definition:
thread.h:67
x86_tss64::psp
char * psp
Definition:
thread.h:84
x86_tss64::rsp2
uint64_t rsp2
Definition:
thread.h:61
x86_tss64::ist1
uint64_t ist1
Definition:
thread.h:65
x86_tss64::rsp0
uint64_t rsp0
Definition:
thread.h:59
x86_tss64::ist5
uint64_t ist5
Definition:
thread.h:69
x86_tss64::iomapb
uint16_t iomapb
Definition:
thread.h:75
x86_tss64::reserved
uint8_t reserved[8]
Definition:
thread.h:63
x86_tss64::usp
char * usp
Definition:
thread.h:87
include
arch
x86
intel64
thread.h
Generated on Sun Oct 9 2022 09:21:56 for Zephyr API Documentation by
1.9.4