- Fix KeAttackProcess, KeStackAttachProcess, KeUnstackDetachProcess and KeDetachProce...
[reactos.git] / reactos / include / ndk / asm.h
1 /*++ NDK Version: 0095
2
3 Copyright (c) Alex Ionescu. All rights reserved.
4
5 Header Name:
6
7 asm.h
8
9 Abstract:
10
11 ASM Offsets for dealing with de-referencing structures in registers.
12
13 Author:
14
15 Alex Ionescu (alex.ionescu@reactos.com) 06-Oct-2004
16
17 --*/
18
19 #ifndef _ASM_H
20 #define _ASM_H
21
22 //
23 // Selector Names
24 //
25 #define RPL_MASK 0x0003
26 #define MODE_MASK 0x0001
27 #define KGDT_R0_CODE (0x8)
28 #define KGDT_R0_DATA (0x10)
29 #define KGDT_R3_CODE (0x18)
30 #define KGDT_R3_DATA (0x20)
31 #define KGDT_TSS (0x28)
32 #define KGDT_R0_PCR (0x30)
33 #define KGDT_R3_TEB (0x38)
34 #define KGDT_LDT (0x48)
35 #define KGDT_DF_TSS (0x50)
36 #define KGDT_NMI_TSS (0x58)
37
38 //
39 // KV86M_REGISTERS Offsets
40 //
41 #define KV86M_REGISTERS_EBP 0x0
42 #define KV86M_REGISTERS_EDI 0x4
43 #define KV86M_REGISTERS_ESI 0x8
44 #define KV86M_REGISTERS_EDX 0xC
45 #define KV86M_REGISTERS_ECX 0x10
46 #define KV86M_REGISTERS_EBX 0x14
47 #define KV86M_REGISTERS_EAX 0x18
48 #define KV86M_REGISTERS_DS 0x1C
49 #define KV86M_REGISTERS_ES 0x20
50 #define KV86M_REGISTERS_FS 0x24
51 #define KV86M_REGISTERS_GS 0x28
52 #define KV86M_REGISTERS_EIP 0x2C
53 #define KV86M_REGISTERS_CS 0x30
54 #define KV86M_REGISTERS_EFLAGS 0x34
55 #define KV86M_REGISTERS_ESP 0x38
56 #define KV86M_REGISTERS_SS 0x3C
57 #define TF_SAVED_EXCEPTION_STACK 0x8C
58 #define TF_REGS 0x90
59 #define TF_ORIG_EBP 0x94
60
61 //
62 // TSS Offsets
63 //
64 #define KTSS_ESP0 0x4
65 #define KTSS_CR3 0x1C
66 #define KTSS_EFLAGS 0x24
67 #define KTSS_IOMAPBASE 0x66
68 #define KTSS_IO_MAPS 0x68
69
70 //
71 // KTHREAD Offsets
72 //
73 #define KTHREAD_DEBUG_ACTIVE 0x03
74 #define KTHREAD_INITIAL_STACK 0x18
75 #define KTHREAD_STACK_LIMIT 0x1C
76 #define KTHREAD_TEB 0x74
77 #define KTHREAD_KERNEL_STACK 0x20
78 #define KTHREAD_NPX_STATE 0x4D
79 #define KTHREAD_STATE 0x4C
80 #define KTHREAD_ALERTED 0x5E
81 #define KTHREAD_APCSTATE_PROCESS 0x28 + 0x10
82 #define KTHREAD_PENDING_USER_APC 0x28 + 0x16
83 #define KTHREAD_PENDING_KERNEL_APC 0x28 + 0x15
84 #define KTHREAD_CONTEXT_SWITCHES 0x48
85 #define KTHREAD_WAIT_IRQL 0x4E
86 #define KTHREAD_SERVICE_TABLE 0x118
87 #define KTHREAD_PREVIOUS_MODE 0xD7
88 #define KTHREAD_TRAP_FRAME 0x110
89 #define KTHREAD_CALLBACK_STACK 0x114
90
91 //
92 // KPROCESS Offsets
93 //
94 #define KPROCESS_DIRECTORY_TABLE_BASE 0x18
95 #define KPROCESS_LDT_DESCRIPTOR0 0x20
96 #define KPROCESS_LDT_DESCRIPTOR1 0x24
97 #define KPROCESS_IOPM_OFFSET 0x30
98
99 //
100 // KPCR Offsets
101 //
102 #define KPCR_EXCEPTION_LIST 0x0
103 #define KPCR_INITIAL_STACK 0x4
104 #define KPCR_STACK_LIMIT 0x8
105 #define KPCR_SET_MEMBER_COPY 0x14
106 #define KPCR_TEB 0x18
107 #define KPCR_SELF 0x1C
108 #define KPCR_PRCB 0x20
109 #define KPCR_KD_VERSION_BLOCK 0x34
110 #define KPCR_GDT 0x3C
111 #define KPCR_TSS 0x40
112 #define KPCR_SET_MEMBER 0x48
113 #define KPCR_NUMBER 0x51
114 #define KPCR_CURRENT_THREAD 0x124
115 #define KPCR_PROCESSOR_NUMBER 0x130
116 #define KPCR_PRCB_SET_MEMBER 0x134
117 #define KPCR_NPX_THREAD 0x2F4
118 #define KPCR_DR6 0x428
119 #define KPCR_DR7 0x42C
120
121 //
122 // KGDTENTRY Offsets
123 //
124 #define KGDT_BASE_LOW 0x2
125 #define KGDT_BASE_MID 0x4
126 #define KGDT_BASE_HI 0x7
127 #define KGDT_LIMIT_HI 0x6
128 #define KGDT_LIMIT_LOW 0x0
129
130 //
131 // FPU Save Area Offsets
132 //
133 #define FN_CONTROL_WORD 0x0
134 #define FN_STATUS_WORD 0x4
135 #define FN_TAG_WORD 0x8
136 #define FN_DATA_SELECTOR 0x18
137 #define FN_CR0_NPX_STATE 0x20C
138 #define SIZEOF_FX_SAVE_AREA 528
139 #define NPX_FRAME_LENGTH 0x210
140
141 //
142 // Trap Frame Offsets
143 //
144 #define KTRAP_FRAME_DEBUGEBP 0x0
145 #define KTRAP_FRAME_DEBUGEIP 0x4
146 #define KTRAP_FRAME_DEBUGARGMARK 0x8
147 #define KTRAP_FRAME_DEBUGPOINTER 0xC
148 #define KTRAP_FRAME_TEMPCS 0x10
149 #define KTRAP_FRAME_TEMPESP 0x14
150 #define KTRAP_FRAME_DR0 0x18
151 #define KTRAP_FRAME_DR1 0x1C
152 #define KTRAP_FRAME_DR2 0x20
153 #define KTRAP_FRAME_DR3 0x24
154 #define KTRAP_FRAME_DR6 0x28
155 #define KTRAP_FRAME_DR7 0x2C
156 #define KTRAP_FRAME_GS 0x30
157 #define KTRAP_FRAME_RESERVED1 0x32
158 #define KTRAP_FRAME_ES 0x34
159 #define KTRAP_FRAME_RESERVED2 0x36
160 #define KTRAP_FRAME_DS 0x38
161 #define KTRAP_FRAME_RESERVED3 0x3A
162 #define KTRAP_FRAME_EDX 0x3C
163 #define KTRAP_FRAME_ECX 0x40
164 #define KTRAP_FRAME_EAX 0x44
165 #define KTRAP_FRAME_PREVIOUS_MODE 0x48
166 #define KTRAP_FRAME_EXCEPTION_LIST 0x4C
167 #define KTRAP_FRAME_FS 0x50
168 #define KTRAP_FRAME_RESERVED4 0x52
169 #define KTRAP_FRAME_EDI 0x54
170 #define KTRAP_FRAME_ESI 0x58
171 #define KTRAP_FRAME_EBX 0x5C
172 #define KTRAP_FRAME_EBP 0x60
173 #define KTRAP_FRAME_ERROR_CODE 0x64
174 #define KTRAP_FRAME_EIP 0x68
175 #define KTRAP_FRAME_CS 0x6C
176 #define KTRAP_FRAME_EFLAGS 0x70
177 #define KTRAP_FRAME_ESP 0x74
178 #define KTRAP_FRAME_SS 0x78
179 #define KTRAP_FRAME_RESERVED5 0x7A
180 #define KTRAP_FRAME_V86_ES 0x7C
181 #define KTRAP_FRAME_RESERVED6 0x7E
182 #define KTRAP_FRAME_V86_DS 0x80
183 #define KTRAP_FRAME_RESERVED7 0x82
184 #define KTRAP_FRAME_V86_FS 0x84
185 #define KTRAP_FRAME_RESERVED8 0x86
186 #define KTRAP_FRAME_V86_GS 0x88
187 #define KTRAP_FRAME_RESERVED9 0x8A
188 #define KTRAP_FRAME_SIZE 0x8C
189 #define KTRAP_FRAME_LENGTH 0x8C
190 #define KTRAP_FRAME_ALIGN 0x04
191
192 //
193 // KUSER_SHARED_DATA Offsets
194 //
195 #define KERNEL_USER_SHARED_DATA 0x7FFE0000
196 #define KUSER_SHARED_PROCESSOR_FEATURES KERNEL_USER_SHARED_DATA + 0x274
197 #define KUSER_SHARED_SYSCALL KERNEL_USER_SHARED_DATA + 0x300
198 #define KUSER_SHARED_SYSCALL_RET KERNEL_USER_SHARED_DATA + 0x304
199 #define PROCESSOR_FEATURE_FXSR KUSER_SHARED_PROCESSOR_FEATURES + 0x4
200
201 //
202 // CONTEXT Offsets
203 //
204 #define CONTEXT_FLAGS 0x0
205 #define CONTEXT_DR6 0x14
206 #define CONTEXT_FLOAT_SAVE 0x1C
207 #define CONTEXT_SEGGS 0x8C
208 #define CONTEXT_SEGFS 0x90
209 #define CONTEXT_SEGES 0x94
210 #define CONTEXT_SEGDS 0x98
211 #define CONTEXT_EDI 0x9C
212 #define CONTEXT_ESI 0xA0
213 #define CONTEXT_EBX 0xA4
214 #define CONTEXT_EDX 0xA8
215 #define CONTEXT_ECX 0xAC
216 #define CONTEXT_EAX 0xB0
217 #define CONTEXT_EBP 0xB4
218 #define CONTEXT_EIP 0xB8
219 #define CONTEXT_SEGCS 0xBC
220 #define CONTEXT_EFLAGS 0xC0
221 #define CONTEXT_ESP 0xC4
222 #define CONTEXT_SEGSS 0xC8
223 #define CONTEXT_FLOAT_SAVE_CONTROL_WORD CONTEXT_FLOAT_SAVE + FN_CONTROL_WORD
224 #define CONTEXT_FLOAT_SAVE_STATUS_WORD CONTEXT_FLOAT_SAVE + FN_STATUS_WORD
225 #define CONTEXT_FLOAT_SAVE_TAG_WORD CONTEXT_FLOAT_SAVE + FN_TAG_WORD
226
227 //
228 // EXCEPTION_RECORD Offsets
229 //
230 #define EXCEPTION_RECORD_EXCEPTION_CODE 0x0
231 #define EXCEPTION_RECORD_EXCEPTION_FLAGS 0x4
232 #define EXCEPTION_RECORD_EXCEPTION_RECORD 0x8
233 #define EXCEPTION_RECORD_EXCEPTION_ADDRESS 0xC
234 #define EXCEPTION_RECORD_NUMBER_PARAMETERS 0x10
235 #define SIZEOF_EXCEPTION_RECORD 0x14
236
237 //
238 // TEB Offsets
239 //
240 #define TEB_EXCEPTION_LIST 0x0
241 #define TEB_STACK_BASE 0x4
242 #define TEB_STACK_LIMIT 0x8
243 #define TEB_FIBER_DATA 0x10
244 #define TEB_PEB 0x30
245 #define TEB_EXCEPTION_CODE 0x1A4
246 #define TEB_ACTIVATION_CONTEXT_STACK_POINTER 0x1A8
247 #define TEB_DEALLOCATION_STACK 0xE0C
248 #define TEB_GUARANTEED_STACK_BYTES 0xF78
249 #define TEB_FLS_DATA 0xFB4
250
251 //
252 // PEB Offsets
253 //
254 #define PEB_KERNEL_CALLBACK_TABLE 0x2C
255
256 //
257 // FIBER Offsets
258 //
259 #define FIBER_PARAMETER 0x0
260 #define FIBER_EXCEPTION_LIST 0x4
261 #define FIBER_STACK_BASE 0x8
262 #define FIBER_STACK_LIMIT 0xC
263 #define FIBER_DEALLOCATION_STACK 0x10
264 #define FIBER_CONTEXT 0x14
265 #define FIBER_GUARANTEED_STACK_BYTES 0x2E0
266 #define FIBER_FLS_DATA 0x2E4
267 #define FIBER_ACTIVATION_CONTEXT_STACK 0x2E8
268 #define FIBER_CONTEXT_FLAGS FIBER_CONTEXT + CONTEXT_FLAGS
269 #define FIBER_CONTEXT_EAX FIBER_CONTEXT + CONTEXT_EAX
270 #define FIBER_CONTEXT_EBX FIBER_CONTEXT + CONTEXT_EBX
271 #define FIBER_CONTEXT_ECX FIBER_CONTEXT + CONTEXT_ECX
272 #define FIBER_CONTEXT_EDX FIBER_CONTEXT + CONTEXT_EDX
273 #define FIBER_CONTEXT_ESI FIBER_CONTEXT + CONTEXT_ESI
274 #define FIBER_CONTEXT_EDI FIBER_CONTEXT + CONTEXT_EDI
275 #define FIBER_CONTEXT_EBP FIBER_CONTEXT + CONTEXT_EBP
276 #define FIBER_CONTEXT_ESP FIBER_CONTEXT + CONTEXT_ESP
277 #define FIBER_CONTEXT_DR6 FIBER_CONTEXT + CONTEXT_DR6
278 #define FIBER_CONTEXT_FLOAT_SAVE_STATUS_WORD FIBER_CONTEXT + CONTEXT_FLOAT_SAVE_STATUS_WORD
279 #define FIBER_CONTEXT_FLOAT_SAVE_CONTROL_WORD FIBER_CONTEXT + CONTEXT_FLOAT_SAVE_CONTROL_WORD
280 #define FIBER_CONTEXT_FLOAT_SAVE_TAG_WORD FIBER_CONTEXT + CONTEXT_FLOAT_SAVE_TAG_WORD
281
282 //
283 // EFLAGS
284 //
285 #define EFLAGS_TF 0x100
286 #define EFLAGS_INTERRUPT_MASK 0x200
287 #define EFLAGS_NESTED_TASK 0x4000
288 #define EFLAGS_V86_MASK 0x20000
289 #define EFLAGS_ALIGN_CHECK 0x40000
290 #define EFLAGS_VIF 0x80000
291 #define EFLAGS_VIP 0x100000
292
293 //
294 // CR0
295 //
296 #define CR0_PE 0x1
297 #define CR0_MP 0x2
298 #define CR0_EM 0x4
299 #define CR0_TS 0x8
300 #define CR0_ET 0x10
301 #define CR0_NE 0x20
302 #define CR0_WP 0x10000
303 #define CR0_AM 0x40000
304 #define CR0_NW 0x20000000
305 #define CR0_CD 0x40000000
306 #define CR0_PG 0x80000000
307
308 //
309 // Generic Definitions
310 //
311 #define MAXIMUM_IDTVECTOR 0xFF
312 #endif // !_ASM_H
313