[XDK]
[reactos.git] / include / xdk / amd64 / ke.h
1 $if (_WDMDDK_)
2 /** Kernel definitions for AMD64 **/
3
4 /* Interrupt request levels */
5 #define PASSIVE_LEVEL 0
6 #define LOW_LEVEL 0
7 #define APC_LEVEL 1
8 #define DISPATCH_LEVEL 2
9 #define CMCI_LEVEL 5
10 #define CLOCK_LEVEL 13
11 #define IPI_LEVEL 14
12 #define DRS_LEVEL 14
13 #define POWER_LEVEL 14
14 #define PROFILE_LEVEL 15
15 #define HIGH_LEVEL 15
16
17 #define KI_USER_SHARED_DATA 0xFFFFF78000000000ULL
18 #define SharedUserData ((PKUSER_SHARED_DATA const)KI_USER_SHARED_DATA)
19 #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
20 #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
21 #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
22
23 #define PAGE_SIZE 0x1000
24 #define PAGE_SHIFT 12L
25
26 #define EFLAG_SIGN 0x8000
27 #define EFLAG_ZERO 0x4000
28 #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
29
30 #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
31 #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
32 #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
33
34
35 typedef struct _KFLOATING_SAVE {
36 ULONG Dummy;
37 } KFLOATING_SAVE, *PKFLOATING_SAVE;
38
39 typedef XSAVE_FORMAT XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
40
41 #define KeQueryInterruptTime() \
42 (*(volatile ULONG64*)SharedInterruptTime)
43
44 #define KeQuerySystemTime(CurrentCount) \
45 *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedSystemTime
46
47 #define KeQueryTickCount(CurrentCount) \
48 *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedTickCount
49
50 #define KeGetDcacheFillSize() 1L
51
52 #define YieldProcessor _mm_pause
53
54 FORCEINLINE
55 KIRQL
56 KeGetCurrentIrql(VOID)
57 {
58 return (KIRQL)__readcr8();
59 }
60
61 FORCEINLINE
62 VOID
63 KeLowerIrql(IN KIRQL NewIrql)
64 {
65 //ASSERT(KeGetCurrentIrql() >= NewIrql);
66 __writecr8(NewIrql);
67 }
68
69 FORCEINLINE
70 KIRQL
71 KfRaiseIrql(IN KIRQL NewIrql)
72 {
73 KIRQL OldIrql;
74
75 OldIrql = __readcr8();
76 //ASSERT(OldIrql <= NewIrql);
77 __writecr8(NewIrql);
78 return OldIrql;
79 }
80 #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
81
82 FORCEINLINE
83 KIRQL
84 KeRaiseIrqlToDpcLevel(VOID)
85 {
86 return KfRaiseIrql(DISPATCH_LEVEL);
87 }
88
89 FORCEINLINE
90 KIRQL
91 KeRaiseIrqlToSynchLevel(VOID)
92 {
93 return KfRaiseIrql(12); // SYNCH_LEVEL = IPI_LEVEL - 2
94 }
95
96 FORCEINLINE
97 PKTHREAD
98 KeGetCurrentThread(VOID)
99 {
100 return (struct _KTHREAD *)__readgsqword(0x188);
101 }
102
103 /* x86 and x64 performs a 0x2C interrupt */
104 #define DbgRaiseAssertionFailure __int2c
105
106 $endif /* _WDMDDK_ */
107 $if (_NTDDK_)
108
109 #define PAUSE_PROCESSOR YieldProcessor();
110
111 #define KERNEL_STACK_SIZE 0x6000
112 #define KERNEL_LARGE_STACK_SIZE 0x12000
113 #define KERNEL_LARGE_STACK_COMMIT KERNEL_STACK_SIZE
114
115 #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
116
117 #define EXCEPTION_READ_FAULT 0
118 #define EXCEPTION_WRITE_FAULT 1
119 #define EXCEPTION_EXECUTE_FAULT 8
120
121 #if !defined(RC_INVOKED)
122
123 #define CONTEXT_AMD64 0x100000
124
125 #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
126 #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
127 #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
128 #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
129 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
130
131 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
132 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
133
134 #define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
135
136 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
137 #define CONTEXT_SERVICE_ACTIVE 0x10000000
138 #define CONTEXT_EXCEPTION_REQUEST 0x40000000
139 #define CONTEXT_EXCEPTION_REPORTING 0x80000000
140
141 #endif /* !defined(RC_INVOKED) */
142
143 #define INITIAL_MXCSR 0x1f80
144 #define INITIAL_FPCSR 0x027f
145
146 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
147 ULONG64 P1Home;
148 ULONG64 P2Home;
149 ULONG64 P3Home;
150 ULONG64 P4Home;
151 ULONG64 P5Home;
152 ULONG64 P6Home;
153 ULONG ContextFlags;
154 ULONG MxCsr;
155 USHORT SegCs;
156 USHORT SegDs;
157 USHORT SegEs;
158 USHORT SegFs;
159 USHORT SegGs;
160 USHORT SegSs;
161 ULONG EFlags;
162 ULONG64 Dr0;
163 ULONG64 Dr1;
164 ULONG64 Dr2;
165 ULONG64 Dr3;
166 ULONG64 Dr6;
167 ULONG64 Dr7;
168 ULONG64 Rax;
169 ULONG64 Rcx;
170 ULONG64 Rdx;
171 ULONG64 Rbx;
172 ULONG64 Rsp;
173 ULONG64 Rbp;
174 ULONG64 Rsi;
175 ULONG64 Rdi;
176 ULONG64 R8;
177 ULONG64 R9;
178 ULONG64 R10;
179 ULONG64 R11;
180 ULONG64 R12;
181 ULONG64 R13;
182 ULONG64 R14;
183 ULONG64 R15;
184 ULONG64 Rip;
185 union {
186 XMM_SAVE_AREA32 FltSave;
187 struct {
188 M128A Header[2];
189 M128A Legacy[8];
190 M128A Xmm0;
191 M128A Xmm1;
192 M128A Xmm2;
193 M128A Xmm3;
194 M128A Xmm4;
195 M128A Xmm5;
196 M128A Xmm6;
197 M128A Xmm7;
198 M128A Xmm8;
199 M128A Xmm9;
200 M128A Xmm10;
201 M128A Xmm11;
202 M128A Xmm12;
203 M128A Xmm13;
204 M128A Xmm14;
205 M128A Xmm15;
206 } DUMMYSTRUCTNAME;
207 } DUMMYUNIONNAME;
208 M128A VectorRegister[26];
209 ULONG64 VectorControl;
210 ULONG64 DebugControl;
211 ULONG64 LastBranchToRip;
212 ULONG64 LastBranchFromRip;
213 ULONG64 LastExceptionToRip;
214 ULONG64 LastExceptionFromRip;
215 } CONTEXT;
216
217 typedef struct _KPCR
218 {
219 _ANONYMOUS_UNION union
220 {
221 NT_TIB NtTib;
222 _ANONYMOUS_STRUCT struct
223 {
224 union _KGDTENTRY64 *GdtBase;
225 struct _KTSS64 *TssBase;
226 ULONG64 UserRsp;
227 struct _KPCR *Self;
228 struct _KPRCB *CurrentPrcb;
229 PKSPIN_LOCK_QUEUE LockArray;
230 PVOID Used_Self;
231 };
232 };
233 union _KIDTENTRY64 *IdtBase;
234 ULONG64 Unused[2];
235 KIRQL Irql;
236 UCHAR SecondLevelCacheAssociativity;
237 UCHAR ObsoleteNumber;
238 UCHAR Fill0;
239 ULONG Unused0[3];
240 USHORT MajorVersion;
241 USHORT MinorVersion;
242 ULONG StallScaleFactor;
243 PVOID Unused1[3];
244 ULONG KernelReserved[15];
245 ULONG SecondLevelCacheSize;
246 ULONG HalReserved[16];
247 ULONG Unused2;
248 PVOID KdVersionBlock;
249 PVOID Unused3;
250 ULONG PcrAlign1[24];
251 } KPCR, *PKPCR;
252
253 FORCEINLINE
254 PKPCR
255 KeGetPcr(VOID)
256 {
257 return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
258 }
259
260 FORCEINLINE
261 ULONG
262 KeGetCurrentProcessorNumber(VOID)
263 {
264 return (ULONG)__readgsword(0x184);
265 }
266
267 $endif /* _NTDDK_ */