e2154a8614cbca9438294bcf265efece1057df7b
[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_CURRENT_THREAD 0x124
114 #define KPCR_PROCESSOR_NUMBER 0x130
115 #define KPCR_PRCB_SET_MEMBER 0x134
116 #define KPCR_NPX_THREAD 0x2F4
117 #define KPCR_DR6 0x428
118 #define KPCR_DR7 0x42C
119
120 //
121 // KGDTENTRY Offsets
122 //
123 #define KGDT_BASE_LOW 0x2
124 #define KGDT_BASE_MID 0x4
125 #define KGDT_BASE_HI 0x7
126 #define KGDT_LIMIT_HI 0x6
127 #define KGDT_LIMIT_LOW 0x0
128
129 //
130 // FPU Save Area Offsets
131 //
132 #define FN_CONTROL_WORD 0x0
133 #define FN_STATUS_WORD 0x4
134 #define FN_TAG_WORD 0x8
135 #define FN_DATA_SELECTOR 0x18
136 #define FN_CR0_NPX_STATE 0x20C
137 #define SIZEOF_FX_SAVE_AREA 528
138 #define NPX_FRAME_LENGTH 0x210
139
140 //
141 // Trap Frame Offsets
142 //
143 #define KTRAP_FRAME_DEBUGEBP 0x0
144 #define KTRAP_FRAME_DEBUGEIP 0x4
145 #define KTRAP_FRAME_DEBUGARGMARK 0x8
146 #define KTRAP_FRAME_DEBUGPOINTER 0xC
147 #define KTRAP_FRAME_TEMPCS 0x10
148 #define KTRAP_FRAME_TEMPESP 0x14
149 #define KTRAP_FRAME_DR0 0x18
150 #define KTRAP_FRAME_DR1 0x1C
151 #define KTRAP_FRAME_DR2 0x20
152 #define KTRAP_FRAME_DR3 0x24
153 #define KTRAP_FRAME_DR6 0x28
154 #define KTRAP_FRAME_DR7 0x2C
155 #define KTRAP_FRAME_GS 0x30
156 #define KTRAP_FRAME_RESERVED1 0x32
157 #define KTRAP_FRAME_ES 0x34
158 #define KTRAP_FRAME_RESERVED2 0x36
159 #define KTRAP_FRAME_DS 0x38
160 #define KTRAP_FRAME_RESERVED3 0x3A
161 #define KTRAP_FRAME_EDX 0x3C
162 #define KTRAP_FRAME_ECX 0x40
163 #define KTRAP_FRAME_EAX 0x44
164 #define KTRAP_FRAME_PREVIOUS_MODE 0x48
165 #define KTRAP_FRAME_EXCEPTION_LIST 0x4C
166 #define KTRAP_FRAME_FS 0x50
167 #define KTRAP_FRAME_RESERVED4 0x52
168 #define KTRAP_FRAME_EDI 0x54
169 #define KTRAP_FRAME_ESI 0x58
170 #define KTRAP_FRAME_EBX 0x5C
171 #define KTRAP_FRAME_EBP 0x60
172 #define KTRAP_FRAME_ERROR_CODE 0x64
173 #define KTRAP_FRAME_EIP 0x68
174 #define KTRAP_FRAME_CS 0x6C
175 #define KTRAP_FRAME_EFLAGS 0x70
176 #define KTRAP_FRAME_ESP 0x74
177 #define KTRAP_FRAME_SS 0x78
178 #define KTRAP_FRAME_RESERVED5 0x7A
179 #define KTRAP_FRAME_V86_ES 0x7C
180 #define KTRAP_FRAME_RESERVED6 0x7E
181 #define KTRAP_FRAME_V86_DS 0x80
182 #define KTRAP_FRAME_RESERVED7 0x82
183 #define KTRAP_FRAME_V86_FS 0x84
184 #define KTRAP_FRAME_RESERVED8 0x86
185 #define KTRAP_FRAME_V86_GS 0x88
186 #define KTRAP_FRAME_RESERVED9 0x8A
187 #define KTRAP_FRAME_SIZE 0x8C
188 #define KTRAP_FRAME_LENGTH 0x8C
189 #define KTRAP_FRAME_ALIGN 0x04
190
191 //
192 // KUSER_SHARED_DATA Offsets
193 //
194 #define KERNEL_USER_SHARED_DATA 0x7FFE0000
195 #define KUSER_SHARED_PROCESSOR_FEATURES KERNEL_USER_SHARED_DATA + 0x274
196 #define KUSER_SHARED_SYSCALL KERNEL_USER_SHARED_DATA + 0x300
197 #define KUSER_SHARED_SYSCALL_RET KERNEL_USER_SHARED_DATA + 0x304
198 #define PROCESSOR_FEATURE_FXSR KUSER_SHARED_PROCESSOR_FEATURES + 0x4
199
200 //
201 // CONTEXT Offsets
202 //
203 #define CONTEXT_FLAGS 0x0
204 #define CONTEXT_DR6 0x14
205 #define CONTEXT_FLOAT_SAVE 0x1C
206 #define CONTEXT_SEGGS 0x8C
207 #define CONTEXT_SEGFS 0x90
208 #define CONTEXT_SEGES 0x94
209 #define CONTEXT_SEGDS 0x98
210 #define CONTEXT_EDI 0x9C
211 #define CONTEXT_ESI 0xA0
212 #define CONTEXT_EBX 0xA4
213 #define CONTEXT_EDX 0xA8
214 #define CONTEXT_ECX 0xAC
215 #define CONTEXT_EAX 0xB0
216 #define CONTEXT_EBP 0xB4
217 #define CONTEXT_EIP 0xB8
218 #define CONTEXT_SEGCS 0xBC
219 #define CONTEXT_EFLAGS 0xC0
220 #define CONTEXT_ESP 0xC4
221 #define CONTEXT_SEGSS 0xC8
222 #define CONTEXT_FLOAT_SAVE_CONTROL_WORD CONTEXT_FLOAT_SAVE + FN_CONTROL_WORD
223 #define CONTEXT_FLOAT_SAVE_STATUS_WORD CONTEXT_FLOAT_SAVE + FN_STATUS_WORD
224 #define CONTEXT_FLOAT_SAVE_TAG_WORD CONTEXT_FLOAT_SAVE + FN_TAG_WORD
225
226 //
227 // EXCEPTION_RECORD Offsets
228 //
229 #define EXCEPTION_RECORD_EXCEPTION_CODE 0x0
230 #define EXCEPTION_RECORD_EXCEPTION_FLAGS 0x4
231 #define EXCEPTION_RECORD_EXCEPTION_RECORD 0x8
232 #define EXCEPTION_RECORD_EXCEPTION_ADDRESS 0xC
233 #define EXCEPTION_RECORD_NUMBER_PARAMETERS 0x10
234 #define SIZEOF_EXCEPTION_RECORD 0x14
235
236 //
237 // TEB Offsets
238 //
239 #define TEB_EXCEPTION_LIST 0x0
240 #define TEB_STACK_BASE 0x4
241 #define TEB_STACK_LIMIT 0x8
242 #define TEB_FIBER_DATA 0x10
243 #define TEB_PEB 0x30
244 #define TEB_EXCEPTION_CODE 0x1A4
245 #define TEB_ACTIVATION_CONTEXT_STACK_POINTER 0x1A8
246 #define TEB_DEALLOCATION_STACK 0xE0C
247 #define TEB_GUARANTEED_STACK_BYTES 0xF78
248 #define TEB_FLS_DATA 0xFB4
249
250 //
251 // PEB Offsets
252 //
253 #define PEB_KERNEL_CALLBACK_TABLE 0x2C
254
255 //
256 // FIBER Offsets
257 //
258 #define FIBER_PARAMETER 0x0
259 #define FIBER_EXCEPTION_LIST 0x4
260 #define FIBER_STACK_BASE 0x8
261 #define FIBER_STACK_LIMIT 0xC
262 #define FIBER_DEALLOCATION_STACK 0x10
263 #define FIBER_CONTEXT 0x14
264 #define FIBER_GUARANTEED_STACK_BYTES 0x2E0
265 #define FIBER_FLS_DATA 0x2E4
266 #define FIBER_ACTIVATION_CONTEXT_STACK 0x2E8
267 #define FIBER_CONTEXT_FLAGS FIBER_CONTEXT + CONTEXT_FLAGS
268 #define FIBER_CONTEXT_EAX FIBER_CONTEXT + CONTEXT_EAX
269 #define FIBER_CONTEXT_EBX FIBER_CONTEXT + CONTEXT_EBX
270 #define FIBER_CONTEXT_ECX FIBER_CONTEXT + CONTEXT_ECX
271 #define FIBER_CONTEXT_EDX FIBER_CONTEXT + CONTEXT_EDX
272 #define FIBER_CONTEXT_ESI FIBER_CONTEXT + CONTEXT_ESI
273 #define FIBER_CONTEXT_EDI FIBER_CONTEXT + CONTEXT_EDI
274 #define FIBER_CONTEXT_EBP FIBER_CONTEXT + CONTEXT_EBP
275 #define FIBER_CONTEXT_ESP FIBER_CONTEXT + CONTEXT_ESP
276 #define FIBER_CONTEXT_DR6 FIBER_CONTEXT + CONTEXT_DR6
277 #define FIBER_CONTEXT_FLOAT_SAVE_STATUS_WORD FIBER_CONTEXT + CONTEXT_FLOAT_SAVE_STATUS_WORD
278 #define FIBER_CONTEXT_FLOAT_SAVE_CONTROL_WORD FIBER_CONTEXT + CONTEXT_FLOAT_SAVE_CONTROL_WORD
279 #define FIBER_CONTEXT_FLOAT_SAVE_TAG_WORD FIBER_CONTEXT + CONTEXT_FLOAT_SAVE_TAG_WORD
280
281 //
282 // EFLAGS
283 //
284 #define EFLAGS_TF 0x100
285 #define EFLAGS_INTERRUPT_MASK 0x200
286 #define EFLAGS_NESTED_TASK 0x4000
287 #define EFLAGS_V86_MASK 0x20000
288 #define EFLAGS_ALIGN_CHECK 0x40000
289 #define EFLAGS_VIF 0x80000
290 #define EFLAGS_VIP 0x100000
291
292 //
293 // CR0
294 //
295 #define CR0_PE 0x1
296 #define CR0_MP 0x2
297 #define CR0_EM 0x4
298 #define CR0_TS 0x8
299 #define CR0_ET 0x10
300 #define CR0_NE 0x20
301 #define CR0_WP 0x10000
302 #define CR0_AM 0x40000
303 #define CR0_NW 0x20000000
304 #define CR0_CD 0x40000000
305 #define CR0_PG 0x80000000
306
307 //
308 // Generic Definitions
309 //
310 #define MAXIMUM_IDTVECTOR 0xFF
311 #endif // !_ASM_H
312