VirtualBox

source: vbox/trunk/include/VBox/x86.h@ 7660

Last change on this file since 7660 was 7660, checked in by vboxsync, 17 years ago

Split off amd64

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 78.6 KB
Line 
1/** @file
2 * X86 (and AMD64) Structures and Definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26/*
27 * x86.mac is generated from this file using:
28 * sed -e '/__VBox_x86_h__/d' -e '/#define/!d' -e 's/#define/%define/' include/VBox/x86.h
29 */
30
31#ifndef ___VBox_x86_h
32#define ___VBox_x86_h
33
34#include <VBox/types.h>
35
36/* Workaround for Solaris sys/regset.h defining CS, DS */
37#if defined(RT_OS_SOLARIS)
38# undef CS
39# undef DS
40#endif
41
42/** @defgroup grp_x86 x86 Types and Definitions
43 * @{
44 */
45
46/**
47 * EFLAGS Bits.
48 */
49typedef struct X86EFLAGSBITS
50{
51 /** Bit 0 - CF - Carry flag - Status flag. */
52 unsigned u1CF : 1;
53 /** Bit 1 - 1 - Reserved flag. */
54 unsigned u1Reserved0 : 1;
55 /** Bit 2 - PF - Parity flag - Status flag. */
56 unsigned u1PF : 1;
57 /** Bit 3 - 0 - Reserved flag. */
58 unsigned u1Reserved1 : 1;
59 /** Bit 4 - AF - Auxiliary carry flag - Status flag. */
60 unsigned u1AF : 1;
61 /** Bit 5 - 0 - Reserved flag. */
62 unsigned u1Reserved2 : 1;
63 /** Bit 6 - ZF - Zero flag - Status flag. */
64 unsigned u1ZF : 1;
65 /** Bit 7 - SF - Signed flag - Status flag. */
66 unsigned u1SF : 1;
67 /** Bit 8 - TF - Trap flag - System flag. */
68 unsigned u1TF : 1;
69 /** Bit 9 - IF - Interrupt flag - System flag. */
70 unsigned u1IF : 1;
71 /** Bit 10 - DF - Direction flag - Control flag. */
72 unsigned u1DF : 1;
73 /** Bit 11 - OF - Overflow flag - Status flag. */
74 unsigned u1OF : 1;
75 /** Bit 12-13 - IOPL - I/O prvilege level flag - System flag. */
76 unsigned u2IOPL : 2;
77 /** Bit 14 - NT - Nested task flag - System flag. */
78 unsigned u1NT : 1;
79 /** Bit 15 - 0 - Reserved flag. */
80 unsigned u1Reserved3 : 1;
81 /** Bit 16 - RF - Resume flag - System flag. */
82 unsigned u1RF : 1;
83 /** Bit 17 - VM - Virtual 8086 mode - System flag. */
84 unsigned u1VM : 1;
85 /** Bit 18 - AC - Alignment check flag - System flag. Works with CR0.AM. */
86 unsigned u1AC : 1;
87 /** Bit 19 - VIF - Virtual interupt flag - System flag. */
88 unsigned u1VIF : 1;
89 /** Bit 20 - VIP - Virtual interupt pending flag - System flag. */
90 unsigned u1VIP : 1;
91 /** Bit 21 - ID - CPUID flag - System flag. If this responds to flipping CPUID is supported. */
92 unsigned u1ID : 1;
93 /** Bit 22-31 - 0 - Reserved flag. */
94 unsigned u10Reserved4 : 10;
95} X86EFLAGSBITS;
96/** Pointer to EFLAGS bits. */
97typedef X86EFLAGSBITS *PX86EFLAGSBITS;
98/** Pointer to const EFLAGS bits. */
99typedef const X86EFLAGSBITS *PCX86EFLAGSBITS;
100
101/**
102 * EFLAGS.
103 */
104typedef union X86EFLAGS
105{
106 /** The bitfield view. */
107 X86EFLAGSBITS Bits;
108 /** The 8-bit view. */
109 uint8_t au8[4];
110 /** The 16-bit view. */
111 uint16_t au16[2];
112 /** The 32-bit view. */
113 uint32_t au32[1];
114 /** The 32-bit view. */
115 uint32_t u32;
116 /** The plain unsigned view. */
117 uint32_t u;
118} X86EFLAGS;
119/** Pointer to EFLAGS. */
120typedef X86EFLAGS *PX86EFLAGS;
121/** Pointer to const EFLAGS. */
122typedef const X86EFLAGS *PCX86EFLAGS;
123
124/**
125 * RFLAGS (32 upper bits are reserved).
126 */
127typedef union X86RFLAGS
128{
129 /** The bitfield view. */
130 X86EFLAGSBITS Bits;
131 /** The 8-bit view. */
132 uint8_t au8[8];
133 /** The 16-bit view. */
134 uint16_t au16[4];
135 /** The 32-bit view. */
136 uint32_t au32[2];
137 /** The 64-bit view. */
138 uint64_t au64[1];
139 /** The 64-bit view. */
140 uint64_t u64;
141 /** The plain unsigned view. */
142 uint64_t u;
143} X86RFLAGS;
144/** Pointer to RFLAGS. */
145typedef X86RFLAGS *PX86RFLAGS;
146/** Pointer to const RFLAGS. */
147typedef const X86RFLAGS *PCX86RFLAGS;
148
149
150/** @name EFLAGS
151 * @{
152 */
153/** Bit 0 - CF - Carry flag - Status flag. */
154#define X86_EFL_CF RT_BIT(0)
155/** Bit 2 - PF - Parity flag - Status flag. */
156#define X86_EFL_PF RT_BIT(2)
157/** Bit 4 - AF - Auxiliary carry flag - Status flag. */
158#define X86_EFL_AF RT_BIT(4)
159/** Bit 6 - ZF - Zero flag - Status flag. */
160#define X86_EFL_ZF RT_BIT(6)
161/** Bit 7 - SF - Signed flag - Status flag. */
162#define X86_EFL_SF RT_BIT(7)
163/** Bit 8 - TF - Trap flag - System flag. */
164#define X86_EFL_TF RT_BIT(8)
165/** Bit 9 - IF - Interrupt flag - System flag. */
166#define X86_EFL_IF RT_BIT(9)
167/** Bit 10 - DF - Direction flag - Control flag. */
168#define X86_EFL_DF RT_BIT(10)
169/** Bit 11 - OF - Overflow flag - Status flag. */
170#define X86_EFL_OF RT_BIT(11)
171/** Bit 12-13 - IOPL - I/O prvilege level flag - System flag. */
172#define X86_EFL_IOPL (RT_BIT(12) | RT_BIT(13))
173/** Bit 14 - NT - Nested task flag - System flag. */
174#define X86_EFL_NT RT_BIT(14)
175/** Bit 16 - RF - Resume flag - System flag. */
176#define X86_EFL_RF RT_BIT(16)
177/** Bit 17 - VM - Virtual 8086 mode - System flag. */
178#define X86_EFL_VM RT_BIT(17)
179/** Bit 18 - AC - Alignment check flag - System flag. Works with CR0.AM. */
180#define X86_EFL_AC RT_BIT(18)
181/** Bit 19 - VIF - Virtual interupt flag - System flag. */
182#define X86_EFL_VIF RT_BIT(19)
183/** Bit 20 - VIP - Virtual interupt pending flag - System flag. */
184#define X86_EFL_VIP RT_BIT(20)
185/** Bit 21 - ID - CPUID flag - System flag. If this responds to flipping CPUID is supported. */
186#define X86_EFL_ID RT_BIT(21)
187/** IOPL shift. */
188#define X86_EFL_IOPL_SHIFT 12
189/** The the IOPL level from the flags. */
190#define X86_EFL_GET_IOPL(efl) (((efl) >> X86_EFL_IOPL_SHIFT) & 3)
191/** @} */
192
193
194/** CPUID Feature information - ECX.
195 * CPUID query with EAX=1.
196 */
197typedef struct X86CPUIDFEATECX
198{
199 /** Bit 0 - SSE3 - Supports SSE3 or not. */
200 unsigned u1SSE3 : 1;
201 /** Reserved. */
202 unsigned u2Reserved1 : 2;
203 /** Bit 3 - MONITOR - Supports MONITOR/MWAIT. */
204 unsigned u1Monitor : 1;
205 /** Bit 4 - CPL-DS - CPL Qualified Debug Store. */
206 unsigned u1CPLDS : 1;
207 /** Bit 5 - VMX - Virtual Machine Technology. */
208 unsigned u1VMX : 1;
209 /** Reserved. */
210 unsigned u1Reserved2 : 1;
211 /** Bit 7 - EST - Enh. SpeedStep Tech. */
212 unsigned u1EST : 1;
213 /** Bit 8 - TM2 - Terminal Monitor 2. */
214 unsigned u1TM2 : 1;
215 /** Bit 9 - SSSE3 - Supplemental Streaming SIMD Extensions 3. */
216 unsigned u1SSSE3 : 1;
217 /** Bit 10 - CNTX-ID - L1 Context ID. */
218 unsigned u1CNTXID : 1;
219 /** Reserved. */
220 unsigned u2Reserved4 : 2;
221 /** Bit 13 - CX16 - CMPXCHG16B. */
222 unsigned u1CX16 : 1;
223 /** Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
224 unsigned u1TPRUpdate : 1;
225 /** Reserved. */
226 unsigned u17Reserved5 : 17;
227
228} X86CPUIDFEATECX;
229/** Pointer to CPUID Feature Information - ECX. */
230typedef X86CPUIDFEATECX *PX86CPUIDFEATECX;
231/** Pointer to const CPUID Feature Information - ECX. */
232typedef const X86CPUIDFEATECX *PCX86CPUIDFEATECX;
233
234
235/** CPUID Feature Information - EDX.
236 * CPUID query with EAX=1.
237 */
238typedef struct X86CPUIDFEATEDX
239{
240 /** Bit 0 - FPU - x87 FPU on Chip. */
241 unsigned u1FPU : 1;
242 /** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
243 unsigned u1VME : 1;
244 /** Bit 2 - DE - Debugging extensions. */
245 unsigned u1DE : 1;
246 /** Bit 3 - PSE - Page Size Extension. */
247 unsigned u1PSE : 1;
248 /** Bit 4 - TSC - Time Stamp Counter. */
249 unsigned u1TSC : 1;
250 /** Bit 5 - MSR - Model Specific Registers RDMSR and WRMSR Instructions. */
251 unsigned u1MSR : 1;
252 /** Bit 6 - PAE - Physical Address Extension. */
253 unsigned u1PAE : 1;
254 /** Bit 7 - MCE - Machine Check Exception. */
255 unsigned u1MCE : 1;
256 /** Bit 8 - CX8 - CMPXCHG8B instruction. */
257 unsigned u1CX8 : 1;
258 /** Bit 9 - APIC - APIC On-Chick. */
259 unsigned u1APIC : 1;
260 /** Bit 10 - Reserved. */
261 unsigned u1Reserved1 : 1;
262 /** Bit 11 - SEP - SYSENTER and SYSEXIT. */
263 unsigned u1SEP : 1;
264 /** Bit 12 - MTRR - Memory Type Range Registers. */
265 unsigned u1MTRR : 1;
266 /** Bit 13 - PGE - PTE Global Bit. */
267 unsigned u1PGE : 1;
268 /** Bit 14 - MCA - Machine Check Architecture. */
269 unsigned u1MCA : 1;
270 /** Bit 15 - CMOV - Conditional Move Instructions. */
271 unsigned u1CMOV : 1;
272 /** Bit 16 - PAT - Page Attribute Table. */
273 unsigned u1PAT : 1;
274 /** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
275 unsigned u1PSE36 : 1;
276 /** Bit 18 - PSN - Processor Serial Number. */
277 unsigned u1PSN : 1;
278 /** Bit 19 - CLFSH - CLFLUSH Instruction. */
279 unsigned u1CLFSH : 1;
280 /** Bit 20 - Reserved. */
281 unsigned u1Reserved2 : 1;
282 /** Bit 21 - DS - Debug Store. */
283 unsigned u1DS : 1;
284 /** Bit 22 - ACPI - Thermal Monitor and Software Controlled Clock Facilities. */
285 unsigned u1ACPI : 1;
286 /** Bit 23 - MMX - Intel MMX 'Technology'. */
287 unsigned u1MMX : 1;
288 /** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
289 unsigned u1FXSR : 1;
290 /** Bit 25 - SSE - SSE Support. */
291 unsigned u1SSE : 1;
292 /** Bit 26 - SSE2 - SSE2 Support. */
293 unsigned u1SSE2 : 1;
294 /** Bit 27 - SS - Self Snoop. */
295 unsigned u1SS : 1;
296 /** Bit 28 - HTT - Hyper-Threading Technology. */
297 unsigned u1HTT : 1;
298 /** Bit 29 - TM - Thermal Monitor. */
299 unsigned u1TM : 1;
300 /** Bit 30 - Reserved - . */
301 unsigned u1Reserved3 : 1;
302 /** Bit 31 - PBE - Pending Break Enabled. */
303 unsigned u1PBE : 1;
304} X86CPUIDFEATEDX;
305/** Pointer to CPUID Feature Information - EDX. */
306typedef X86CPUIDFEATEDX *PX86CPUIDFEATEDX;
307/** Pointer to const CPUID Feature Information - EDX. */
308typedef const X86CPUIDFEATEDX *PCX86CPUIDFEATEDX;
309
310/** @name CPUID Vendor information.
311 * CPUID query with EAX=0.
312 * @{
313 */
314#define X86_CPUID_VENDOR_INTEL_EBX 0x756e6547 /* Genu */
315#define X86_CPUID_VENDOR_INTEL_ECX 0x6c65746e /* ntel */
316#define X86_CPUID_VENDOR_INTEL_EDX 0x49656e69 /* ineI */
317
318#define X86_CPUID_VENDOR_AMD_EBX 0x68747541 /* Auth */
319#define X86_CPUID_VENDOR_AMD_ECX 0x444d4163 /* cAMD */
320#define X86_CPUID_VENDOR_AMD_EDX 0x69746e65 /* enti */
321/** @} */
322
323
324/** @name CPUID Feature information.
325 * CPUID query with EAX=1.
326 * @{
327 */
328/** ECX Bit 0 - SSE3 - Supports SSE3 or not. */
329#define X86_CPUID_FEATURE_ECX_SSE3 RT_BIT(0)
330/** ECX Bit 3 - MONITOR - Supports MONITOR/MWAIT. */
331#define X86_CPUID_FEATURE_ECX_MONITOR RT_BIT(3)
332/** ECX Bit 4 - CPL-DS - CPL Qualified Debug Store. */
333#define X86_CPUID_FEATURE_ECX_CPLDS RT_BIT(4)
334/** ECX Bit 5 - VMX - Virtual Machine Technology. */
335#define X86_CPUID_FEATURE_ECX_VMX RT_BIT(5)
336/** ECX Bit 7 - EST - Enh. SpeedStep Tech. */
337#define X86_CPUID_FEATURE_ECX_EST RT_BIT(7)
338/** ECX Bit 8 - TM2 - Terminal Monitor 2. */
339#define X86_CPUID_FEATURE_ECX_TM2 RT_BIT(8)
340/** ECX Bit 9 - SSSE3 - Supplemental Streaming SIMD Extensions 3. */
341#define X86_CPUID_FEATURE_ECX_SSSE3 RT_BIT(9)
342/** ECX Bit 10 - CNTX-ID - L1 Context ID. */
343#define X86_CPUID_FEATURE_ECX_CNTXID RT_BIT(10)
344/** ECX Bit 13 - CX16 - CMPXCHG16B. */
345#define X86_CPUID_FEATURE_ECX_CX16 RT_BIT(13)
346/** ECX Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
347#define X86_CPUID_FEATURE_ECX_TPRUPDATE RT_BIT(14)
348/** ECX Bit 23 - POPCOUNT instruction. */
349#define X86_CPUID_FEATURE_ECX_POPCOUNT RT_BIT(23)
350
351
352/** Bit 0 - FPU - x87 FPU on Chip. */
353#define X86_CPUID_FEATURE_EDX_FPU RT_BIT(0)
354/** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
355#define X86_CPUID_FEATURE_EDX_VME RT_BIT(1)
356/** Bit 2 - DE - Debugging extensions. */
357#define X86_CPUID_FEATURE_EDX_DE RT_BIT(2)
358/** Bit 3 - PSE - Page Size Extension. */
359#define X86_CPUID_FEATURE_EDX_PSE RT_BIT(3)
360/** Bit 4 - TSC - Time Stamp Counter. */
361#define X86_CPUID_FEATURE_EDX_TSC RT_BIT(4)
362/** Bit 5 - MSR - Model Specific Registers RDMSR and WRMSR Instructions. */
363#define X86_CPUID_FEATURE_EDX_MSR RT_BIT(5)
364/** Bit 6 - PAE - Physical Address Extension. */
365#define X86_CPUID_FEATURE_EDX_PAE RT_BIT(6)
366/** Bit 7 - MCE - Machine Check Exception. */
367#define X86_CPUID_FEATURE_EDX_MCE RT_BIT(7)
368/** Bit 8 - CX8 - CMPXCHG8B instruction. */
369#define X86_CPUID_FEATURE_EDX_CX8 RT_BIT(8)
370/** Bit 9 - APIC - APIC On-Chip. */
371#define X86_CPUID_FEATURE_EDX_APIC RT_BIT(9)
372/** Bit 11 - SEP - SYSENTER and SYSEXIT. */
373#define X86_CPUID_FEATURE_EDX_SEP RT_BIT(11)
374/** Bit 12 - MTRR - Memory Type Range Registers. */
375#define X86_CPUID_FEATURE_EDX_MTRR RT_BIT(12)
376/** Bit 13 - PGE - PTE Global Bit. */
377#define X86_CPUID_FEATURE_EDX_PGE RT_BIT(13)
378/** Bit 14 - MCA - Machine Check Architecture. */
379#define X86_CPUID_FEATURE_EDX_MCA RT_BIT(14)
380/** Bit 15 - CMOV - Conditional Move Instructions. */
381#define X86_CPUID_FEATURE_EDX_CMOV RT_BIT(15)
382/** Bit 16 - PAT - Page Attribute Table. */
383#define X86_CPUID_FEATURE_EDX_PAT RT_BIT(16)
384/** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
385#define X86_CPUID_FEATURE_EDX_PSE36 RT_BIT(17)
386/** Bit 18 - PSN - Processor Serial Number. */
387#define X86_CPUID_FEATURE_EDX_PSN RT_BIT(18)
388/** Bit 19 - CLFSH - CLFLUSH Instruction. */
389#define X86_CPUID_FEATURE_EDX_CLFSH RT_BIT(19)
390/** Bit 21 - DS - Debug Store. */
391#define X86_CPUID_FEATURE_EDX_DS RT_BIT(21)
392/** Bit 22 - ACPI - Termal Monitor and Software Controlled Clock Facilities. */
393#define X86_CPUID_FEATURE_EDX_ACPI RT_BIT(22)
394/** Bit 23 - MMX - Intel MMX Technology. */
395#define X86_CPUID_FEATURE_EDX_MMX RT_BIT(23)
396/** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
397#define X86_CPUID_FEATURE_EDX_FXSR RT_BIT(24)
398/** Bit 25 - SSE - SSE Support. */
399#define X86_CPUID_FEATURE_EDX_SSE RT_BIT(25)
400/** Bit 26 - SSE2 - SSE2 Support. */
401#define X86_CPUID_FEATURE_EDX_SSE2 RT_BIT(26)
402/** Bit 27 - SS - Self Snoop. */
403#define X86_CPUID_FEATURE_EDX_SS RT_BIT(27)
404/** Bit 28 - HTT - Hyper-Threading Technology. */
405#define X86_CPUID_FEATURE_EDX_HTT RT_BIT(28)
406/** Bit 29 - TM - Therm. Monitor. */
407#define X86_CPUID_FEATURE_EDX_TM RT_BIT(29)
408/** Bit 31 - PBE - Pending Break Enabled. */
409#define X86_CPUID_FEATURE_EDX_PBE RT_BIT(31)
410/** @} */
411
412
413/** @name CPUID AMD Feature information.
414 * CPUID query with EAX=0x80000001.
415 * @{
416 */
417/** Bit 0 - FPU - x87 FPU on Chip. */
418#define X86_CPUID_AMD_FEATURE_EDX_FPU RT_BIT(0)
419/** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
420#define X86_CPUID_AMD_FEATURE_EDX_VME RT_BIT(1)
421/** Bit 2 - DE - Debugging extensions. */
422#define X86_CPUID_AMD_FEATURE_EDX_DE RT_BIT(2)
423/** Bit 3 - PSE - Page Size Extension. */
424#define X86_CPUID_AMD_FEATURE_EDX_PSE RT_BIT(3)
425/** Bit 4 - TSC - Time Stamp Counter. */
426#define X86_CPUID_AMD_FEATURE_EDX_TSC RT_BIT(4)
427/** Bit 5 - MSR - K86 Model Specific Registers RDMSR and WRMSR Instructions. */
428#define X86_CPUID_AMD_FEATURE_EDX_MSR RT_BIT(5)
429/** Bit 6 - PAE - Physical Address Extension. */
430#define X86_CPUID_AMD_FEATURE_EDX_PAE RT_BIT(6)
431/** Bit 7 - MCE - Machine Check Exception. */
432#define X86_CPUID_AMD_FEATURE_EDX_MCE RT_BIT(7)
433/** Bit 8 - CX8 - CMPXCHG8B instruction. */
434#define X86_CPUID_AMD_FEATURE_EDX_CX8 RT_BIT(8)
435/** Bit 9 - APIC - APIC On-Chip. */
436#define X86_CPUID_AMD_FEATURE_EDX_APIC RT_BIT(9)
437/** Bit 11 - SEP - AMD SYSCALL and SYSRET. */
438#define X86_CPUID_AMD_FEATURE_EDX_SEP RT_BIT(11)
439/** Bit 12 - MTRR - Memory Type Range Registers. */
440#define X86_CPUID_AMD_FEATURE_EDX_MTRR RT_BIT(12)
441/** Bit 13 - PGE - PTE Global Bit. */
442#define X86_CPUID_AMD_FEATURE_EDX_PGE RT_BIT(13)
443/** Bit 14 - MCA - Machine Check Architecture. */
444#define X86_CPUID_AMD_FEATURE_EDX_MCA RT_BIT(14)
445/** Bit 15 - CMOV - Conditional Move Instructions. */
446#define X86_CPUID_AMD_FEATURE_EDX_CMOV RT_BIT(15)
447/** Bit 16 - PAT - Page Attribute Table. */
448#define X86_CPUID_AMD_FEATURE_EDX_PAT RT_BIT(16)
449/** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
450#define X86_CPUID_AMD_FEATURE_EDX_PSE36 RT_BIT(17)
451/** Bit 20 - NX - AMD No-Execute Page Protection. */
452#define X86_CPUID_AMD_FEATURE_EDX_NX RT_BIT(20)
453/** Bit 22 - AXMMX - AMD Extensions to MMX Instructions. */
454#define X86_CPUID_AMD_FEATURE_EDX_AXMMX RT_BIT(22)
455/** Bit 23 - MMX - Intel MMX Technology. */
456#define X86_CPUID_AMD_FEATURE_EDX_MMX RT_BIT(23)
457/** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
458#define X86_CPUID_AMD_FEATURE_EDX_FXSR RT_BIT(24)
459/** Bit 25 - FFXSR - AMD fast FXSAVE and FXRSTOR Instructions. */
460#define X86_CPUID_AMD_FEATURE_EDX_FFXSR RT_BIT(25)
461/** Bit 26 - PAGE1GB - AMD 1GB large page support. */
462#define X86_CPUID_AMD_FEATURE_EDX_PAGE1GB RT_BIT(26)
463/** Bit 27 - RDTSCP - AMD RDTSCP instruction. */
464#define X86_CPUID_AMD_FEATURE_EDX_RDTSCP RT_BIT(27)
465/** Bit 29 - LM - AMD Long Mode. */
466#define X86_CPUID_AMD_FEATURE_EDX_LONG_MODE RT_BIT(29)
467/** Bit 30 - 3DNOWEXT - AMD Extensions to 3DNow. */
468#define X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX RT_BIT(30)
469/** Bit 31 - 3DNOW - AMD 3DNow. */
470#define X86_CPUID_AMD_FEATURE_EDX_3DNOW RT_BIT(31)
471
472/** Bit 0 - LAHF/SAHF - AMD LAHF and SAHF in 64-bit mode. */
473#define X86_CPUID_AMD_FEATURE_ECX_LAHF_SAHF RT_BIT(0)
474/** Bit 1 - CMPL - Core multi-processing legacy mode. */
475#define X86_CPUID_AMD_FEATURE_ECX_CMPL RT_BIT(1)
476/** Bit 2 - SVM - AMD VM extensions. */
477#define X86_CPUID_AMD_FEATURE_ECX_SVM RT_BIT(2)
478/** Bit 3 - EXTAPIC - AMD extended APIC registers starting at 0x400. */
479#define X86_CPUID_AMD_FEATURE_ECX_EXT_APIC RT_BIT(3)
480/** Bit 4 - CR8L - AMD LOCK MOV CR0 means MOV CR8. */
481#define X86_CPUID_AMD_FEATURE_ECX_CR8L RT_BIT(4)
482/** Bit 5 - ABM - AMD Advanced bit manipulation. LZCNT instruction support. */
483#define X86_CPUID_AMD_FEATURE_ECX_ABM RT_BIT(5)
484/** Bit 6 - SSE4A - AMD EXTRQ, INSERTQ, MOVNTSS, and MOVNTSD instruction support. */
485#define X86_CPUID_AMD_FEATURE_ECX_SSE4A RT_BIT(6)
486/** Bit 7 - MISALIGNSSE - AMD Misaligned SSE mode. */
487#define X86_CPUID_AMD_FEATURE_ECX_MISALNSSE RT_BIT(7)
488/** Bit 8 - 3DNOWPRF - AMD PREFETCH and PREFETCHW instruction support. */
489#define X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF RT_BIT(8)
490/** Bit 9 - OSVW - AMD OS visible workaround. */
491#define X86_CPUID_AMD_FEATURE_ECX_OSVW RT_BIT(9)
492/** Bit 12 - SKINIT - AMD SKINIT: SKINIT, STGI, and DEV support. */
493#define X86_CPUID_AMD_FEATURE_ECX_SKINIT RT_BIT(12)
494/** Bit 13 - WDT - AMD Watchdog timer support. */
495#define X86_CPUID_AMD_FEATURE_ECX_WDT RT_BIT(13)
496
497/** @} */
498
499
500/** @name CR0
501 * @{ */
502/** Bit 0 - PE - Protection Enabled */
503#define X86_CR0_PE RT_BIT(0)
504#define X86_CR0_PROTECTION_ENABLE RT_BIT(0)
505/** Bit 1 - MP - Monitor Coprocessor */
506#define X86_CR0_MP RT_BIT(1)
507#define X86_CR0_MONITOR_COPROCESSOR RT_BIT(1)
508/** Bit 2 - EM - Emulation. */
509#define X86_CR0_EM RT_BIT(2)
510#define X86_CR0_EMULATE_FPU RT_BIT(2)
511/** Bit 3 - TS - Task Switch. */
512#define X86_CR0_TS RT_BIT(3)
513#define X86_CR0_TASK_SWITCH RT_BIT(3)
514/** Bit 4 - ET - Extension flag. ('hardcoded' to 1) */
515#define X86_CR0_ET RT_BIT(4)
516#define X86_CR0_EXTENSION_TYPE RT_BIT(4)
517/** Bit 5 - NE - Numeric error. */
518#define X86_CR0_NE RT_BIT(5)
519#define X86_CR0_NUMERIC_ERROR RT_BIT(5)
520/** Bit 16 - WP - Write Protect. */
521#define X86_CR0_WP RT_BIT(16)
522#define X86_CR0_WRITE_PROTECT RT_BIT(16)
523/** Bit 18 - AM - Alignment Mask. */
524#define X86_CR0_AM RT_BIT(18)
525#define X86_CR0_ALIGMENT_MASK RT_BIT(18)
526/** Bit 29 - NW - Not Write-though. */
527#define X86_CR0_NW RT_BIT(29)
528#define X86_CR0_NOT_WRITE_THROUGH RT_BIT(29)
529/** Bit 30 - WP - Cache Disable. */
530#define X86_CR0_CD RT_BIT(30)
531#define X86_CR0_CACHE_DISABLE RT_BIT(30)
532/** Bit 31 - PG - Paging. */
533#define X86_CR0_PG RT_BIT(31)
534#define X86_CR0_PAGING RT_BIT(31)
535/** @} */
536
537
538/** @name CR3
539 * @{ */
540/** Bit 3 - PWT - Page-level Writes Transparent. */
541#define X86_CR3_PWT RT_BIT(3)
542/** Bit 4 - PCD - Page-level Cache Disable. */
543#define X86_CR3_PCD RT_BIT(4)
544/** Bits 12-31 - - Page directory page number. */
545#define X86_CR3_PAGE_MASK (0xfffff000)
546/** Bits 5-31 - - PAE Page directory page number. */
547#define X86_CR3_PAE_PAGE_MASK (0xffffffe0)
548/** @} */
549
550
551/** @name CR4
552 * @{ */
553/** Bit 0 - VME - Virtual-8086 Mode Extensions. */
554#define X86_CR4_VME RT_BIT(0)
555/** Bit 1 - PVI - Protected-Mode Virtual Interrupts. */
556#define X86_CR4_PVI RT_BIT(1)
557/** Bit 2 - TSD - Time Stamp Disable. */
558#define X86_CR4_TSD RT_BIT(2)
559/** Bit 3 - DE - Debugging Extensions. */
560#define X86_CR4_DE RT_BIT(3)
561/** Bit 4 - PSE - Page Size Extension. */
562#define X86_CR4_PSE RT_BIT(4)
563/** Bit 5 - PAE - Physical Address Extension. */
564#define X86_CR4_PAE RT_BIT(5)
565/** Bit 6 - MCE - Machine-Check Enable. */
566#define X86_CR4_MCE RT_BIT(6)
567/** Bit 7 - PGE - Page Global Enable. */
568#define X86_CR4_PGE RT_BIT(7)
569/** Bit 8 - PCE - Performance-Monitoring Counter Enable. */
570#define X86_CR4_PCE RT_BIT(8)
571/** Bit 9 - OSFSXR - Operating System Support for FXSAVE and FXRSTORE instruction. */
572#define X86_CR4_OSFSXR RT_BIT(9)
573/** Bit 10 - OSXMMEEXCPT - Operating System Support for Unmasked SIMD Floating-Point Exceptions. */
574#define X86_CR4_OSXMMEEXCPT RT_BIT(10)
575/** Bit 13 - VMXE - VMX mode is enabled. */
576#define X86_CR4_VMXE RT_BIT(13)
577/** @} */
578
579
580/** @name DR6
581 * @{ */
582/** Bit 0 - B0 - Breakpoint 0 condition detected. */
583#define X86_DR6_B0 RT_BIT(0)
584/** Bit 1 - B1 - Breakpoint 1 condition detected. */
585#define X86_DR6_B1 RT_BIT(1)
586/** Bit 2 - B2 - Breakpoint 2 condition detected. */
587#define X86_DR6_B2 RT_BIT(2)
588/** Bit 3 - B3 - Breakpoint 3 condition detected. */
589#define X86_DR6_B3 RT_BIT(3)
590/** Bit 13 - BD - Debug register access detected. Corresponds to the X86_DR7_GD bit. */
591#define X86_DR6_BD RT_BIT(13)
592/** Bit 14 - BS - Single step */
593#define X86_DR6_BS RT_BIT(14)
594/** Bit 15 - BT - Task switch. (TSS T bit.) */
595#define X86_DR6_BT RT_BIT(15)
596/** @} */
597
598
599/** @name DR7
600 * @{ */
601/** Bit 0 - L0 - Local breakpoint enable. Cleared on task switch. */
602#define X86_DR7_L0 RT_BIT(0)
603/** Bit 1 - G0 - Global breakpoint enable. Not cleared on task switch. */
604#define X86_DR7_G0 RT_BIT(1)
605/** Bit 2 - L1 - Local breakpoint enable. Cleared on task switch. */
606#define X86_DR7_L1 RT_BIT(2)
607/** Bit 3 - G1 - Global breakpoint enable. Not cleared on task switch. */
608#define X86_DR7_G1 RT_BIT(3)
609/** Bit 4 - L2 - Local breakpoint enable. Cleared on task switch. */
610#define X86_DR7_L2 RT_BIT(4)
611/** Bit 5 - G2 - Global breakpoint enable. Not cleared on task switch. */
612#define X86_DR7_G2 RT_BIT(5)
613/** Bit 6 - L3 - Local breakpoint enable. Cleared on task switch. */
614#define X86_DR7_L3 RT_BIT(6)
615/** Bit 7 - G3 - Global breakpoint enable. Not cleared on task switch. */
616#define X86_DR7_G3 RT_BIT(7)
617/** Bit 8 - LE - Local breakpoint exact. (Not supported (read ignored) by P6 and later.) */
618#define X86_DR7_LE RT_BIT(8)
619/** Bit 9 - GE - Local breakpoint exact. (Not supported (read ignored) by P6 and later.) */
620#define X86_DR7_GE RT_BIT(9)
621
622/** Bit 13 - GD - General detect enable. Enables emulators to get exceptions when
623 * any DR register is accessed. */
624#define X86_DR7_GD RT_BIT(13)
625/** Bit 16 & 17 - R/W0 - Read write field 0. Values X86_DR7_RW_*. */
626#define X86_DR7_RW0_MASK (3 << 16)
627/** Bit 18 & 19 - LEN0 - Length field 0. Values X86_DR7_LEN_*. */
628#define X86_DR7_LEN0_MASK (3 << 18)
629/** Bit 20 & 21 - R/W1 - Read write field 0. Values X86_DR7_RW_*. */
630#define X86_DR7_RW1_MASK (3 << 20)
631/** Bit 22 & 23 - LEN1 - Length field 0. Values X86_DR7_LEN_*. */
632#define X86_DR7_LEN1_MASK (3 << 22)
633/** Bit 24 & 25 - R/W2 - Read write field 0. Values X86_DR7_RW_*. */
634#define X86_DR7_RW2_MASK (3 << 24)
635/** Bit 26 & 27 - LEN2 - Length field 0. Values X86_DR7_LEN_*. */
636#define X86_DR7_LEN2_MASK (3 << 26)
637/** Bit 28 & 29 - R/W3 - Read write field 0. Values X86_DR7_RW_*. */
638#define X86_DR7_RW3_MASK (3 << 28)
639/** Bit 30 & 31 - LEN3 - Length field 0. Values X86_DR7_LEN_*. */
640#define X86_DR7_LEN3_MASK (3 << 30)
641
642/** Bits which must be 1s. */
643#define X86_DR7_MB1_MASK (RT_BIT(10))
644
645/** Calcs the L bit of Nth breakpoint.
646 * @param iBp The breakpoint number [0..3].
647 */
648#define X86_DR7_L(iBp) ( 1 << (iBp * 2) )
649
650/** Calcs the G bit of Nth breakpoint.
651 * @param iBp The breakpoint number [0..3].
652 */
653#define X86_DR7_G(iBp) ( 1 << (iBp * 2 + 1) )
654
655/** @name Read/Write values.
656 * @{ */
657/** Break on instruction fetch only. */
658#define X86_DR7_RW_EO 0
659/** Break on write only. */
660#define X86_DR7_RW_WO 1
661/** Break on I/O read/write. This is only defined if CR4.DE is set. */
662#define X86_DR7_RW_IO 2
663/** Break on read or write (but not instruction fetches). */
664#define X86_DR7_RW_RW 3
665/** @} */
666
667/** Shifts a X86_DR7_RW_* value to its right place.
668 * @param iBp The breakpoint number [0..3].
669 * @param fRw One of the X86_DR7_RW_* value.
670 */
671#define X86_DR7_RW(iBp, fRw) ( (fRw) << ((iBp) * 4 + 16) )
672
673/** @name Length values.
674 * @{ */
675#define X86_DR7_LEN_BYTE 0
676#define X86_DR7_LEN_WORD 1
677#define X86_DR7_LEN_QWORD 2 /**< AMD64 long mode only. */
678#define X86_DR7_LEN_DWORD 3
679/** @} */
680
681/** Shifts a X86_DR7_LEN_* value to its right place.
682 * @param iBp The breakpoint number [0..3].
683 * @param cb One of the X86_DR7_LEN_* values.
684 */
685#define X86_DR7_LEN(iBp, cb) ( (cb) << ((iBp) * 4 + 18) )
686
687/** Mask used to check if any breakpoints are enabled. */
688#define X86_DR7_ENABLED_MASK (RT_BIT(0) | RT_BIT(1) | RT_BIT(2) | RT_BIT(3) | RT_BIT(4) | RT_BIT(6) | RT_BIT(7))
689
690/** @} */
691
692
693/** @name Machine Specific Registers
694 * @{
695 */
696/** CPU Feature control. */
697#define MSR_IA32_FEATURE_CONTROL 0x3A
698#define MSR_IA32_FEATURE_CONTROL_LOCK RT_BIT(0)
699#define MSR_IA32_FEATURE_CONTROL_VMXON RT_BIT(2)
700
701
702#ifndef MSR_IA32_SYSENTER_CS /* qemu cpu.h klugde */
703/** SYSENTER_CS - the R0 CS, indirectly giving R0 SS, R3 CS and R3 DS.
704 * R0 SS == CS + 8
705 * R3 CS == CS + 16
706 * R3 SS == CS + 24
707 */
708#define MSR_IA32_SYSENTER_CS 0x174
709/** SYSENTER_ESP - the R0 ESP. */
710#define MSR_IA32_SYSENTER_ESP 0x175
711/** SYSENTER_EIP - the R0 EIP. */
712#define MSR_IA32_SYSENTER_EIP 0x176
713#endif
714
715/** Basic VMX information. */
716#define MSR_IA32_VMX_BASIC_INFO 0x480
717/** Allowed settings for pin-based VM execution controls */
718#define MSR_IA32_VMX_PINBASED_CTLS 0x481
719/** Allowed settings for proc-based VM execution controls */
720#define MSR_IA32_VMX_PROCBASED_CTLS 0x482
721/** Allowed settings for the VMX exit controls. */
722#define MSR_IA32_VMX_EXIT_CTLS 0x483
723/** Allowed settings for the VMX entry controls. */
724#define MSR_IA32_VMX_ENTRY_CTLS 0x484
725/** Misc VMX info. */
726#define MSR_IA32_VMX_MISC 0x485
727/** Fixed cleared bits in CR0. */
728#define MSR_IA32_VMX_CR0_FIXED0 0x486
729/** Fixed set bits in CR0. */
730#define MSR_IA32_VMX_CR0_FIXED1 0x487
731/** Fixed cleared bits in CR4. */
732#define MSR_IA32_VMX_CR4_FIXED0 0x488
733/** Fixed set bits in CR4. */
734#define MSR_IA32_VMX_CR4_FIXED1 0x489
735/** Information for enumerating fields in the VMCS. */
736#define MSR_IA32_VMX_VMCS_ENUM 0x48A
737
738
739/** K6 EFER - Extended Feature Enable Register. */
740#define MSR_K6_EFER 0xc0000080
741/** @todo document EFER */
742/** Bit 0 - SCE - System call extensions (SYSCALL / SYSRET). (R/W) */
743#define MSR_K6_EFER_SCE RT_BIT(0)
744/** Bit 8 - LME - Long mode enabled. (R/W) */
745#define MSR_K6_EFER_LME RT_BIT(8)
746/** Bit 10 - LMA - Long mode active. (R) */
747#define MSR_K6_EFER_LMA RT_BIT(10)
748/** Bit 11 - NXE - No-Execute Page Protection Enabled. (R/W) */
749#define MSR_K6_EFER_NXE RT_BIT(11)
750/** Bit 12 - SVME - Secure VM Extension Enabled. (R/W) */
751#define MSR_K6_EFER_SVME RT_BIT(12)
752/** Bit 13 - LMSLE - Long Mode Segment Limit Enable. (R/W?) */
753#define MSR_K6_EFER_LMSLE RT_BIT(13)
754/** Bit 14 - FFXSR - Fast FXSAVE / FXRSTOR (skip XMM*). (R/W) */
755#define MSR_K6_EFER_FFXSR RT_BIT(14)
756/** K6 STAR - SYSCALL/RET targets. */
757#define MSR_K6_STAR 0xc0000081
758/** Shift value for getting the SYSRET CS and SS value. */
759#define MSR_K6_STAR_SYSRET_CS_SS_SHIFT 48
760/** Shift value for getting the SYSCALL CS and SS value. */
761#define MSR_K6_STAR_SYSCALL_CS_SS_SHIFT 32
762/** Selector mask for use after shifting. */
763#define MSR_K6_STAR_SEL_MASK 0xffff
764/** The mask which give the SYSCALL EIP. */
765#define MSR_K6_STAR_SYSCALL_EIP_MASK 0xffffffff
766/** K6 WHCR - Write Handling Control Register. */
767#define MSR_K6_WHCR 0xc0000082
768/** K6 UWCCR - UC/WC Cacheability Control Register. */
769#define MSR_K6_UWCCR 0xc0000085
770/** K6 PSOR - Processor State Observability Register. */
771#define MSR_K6_PSOR 0xc0000087
772/** K6 PFIR - Page Flush/Invalidate Register. */
773#define MSR_K6_PFIR 0xc0000088
774
775#define MSR_K7_EVNTSEL0 0xc0010000
776#define MSR_K7_EVNTSEL1 0xc0010001
777#define MSR_K7_EVNTSEL2 0xc0010002
778#define MSR_K7_EVNTSEL3 0xc0010003
779#define MSR_K7_PERFCTR0 0xc0010004
780#define MSR_K7_PERFCTR1 0xc0010005
781#define MSR_K7_PERFCTR2 0xc0010006
782#define MSR_K7_PERFCTR3 0xc0010007
783
784/** K8 LSTAR - Long mode SYSCALL target (RIP). */
785#define MSR_K8_LSTAR 0xc0000082
786/** K8 CSTAR - Compatibility mode SYSCALL target (RIP). */
787#define MSR_K8_CSTAR 0xc0000083
788/** K8 SF_MASK - SYSCALL flag mask. (aka SFMASK) */
789#define MSR_K8_SF_MASK 0xc0000084
790/** K8 FS.base - The 64-bit base FS register. */
791#define MSR_K8_FS_BASE 0xc0000100
792/** K8 GS.base - The 64-bit base GS register. */
793#define MSR_K8_GS_BASE 0xc0000101
794/** K8 KernelGSbase - Used with SWAPGS. */
795#define MSR_K8_KERNEL_GS_BASE 0xc0000102
796#define MSR_K8_TSC_AUX 0xc0000103
797#define MSR_K8_SYSCFG 0xc0010010
798#define MSR_K8_HWCR 0xc0010015
799#define MSR_K8_IORRBASE0 0xc0010016
800#define MSR_K8_IORRMASK0 0xc0010017
801#define MSR_K8_IORRBASE1 0xc0010018
802#define MSR_K8_IORRMASK1 0xc0010019
803#define MSR_K8_TOP_MEM1 0xc001001a
804#define MSR_K8_TOP_MEM2 0xc001001d
805#define MSR_K8_VM_CR 0xc0010114
806#define MSR_K8_VM_CR_SVM_DISABLE RT_BIT(4)
807
808#define MSR_K8_IGNNE 0xc0010115
809#define MSR_K8_SMM_CTL 0xc0010116
810/** SVM - VM_HSAVE_PA - Physical address for saving and restoring
811 * host state during world switch.
812 */
813#define MSR_K8_VM_HSAVE_PA 0xc0010117
814
815/** @} */
816
817
818/** @name Page Table / Directory / Directory Pointers / L4.
819 * @{
820 */
821
822/** Page table/directory entry as an unsigned integer. */
823typedef uint32_t X86PGUINT;
824/** Pointer to a page table/directory table entry as an unsigned integer. */
825typedef X86PGUINT *PX86PGUINT;
826
827/** Number of entries in a 32-bit PT/PD. */
828#define X86_PG_ENTRIES 1024
829
830
831/** PAE page table/page directory/pdptr/l4/l5 entry as an unsigned integer. */
832typedef uint64_t X86PGPAEUINT;
833/** Pointer to a PAE page table/page directory/pdptr/l4/l5 entry as an unsigned integer. */
834typedef X86PGPAEUINT *PX86PGPAEUINT;
835
836/** Number of entries in a PAE PT/PD/PDPTR/L4/L5. */
837#define X86_PG_PAE_ENTRIES 512
838
839
840/** The size of a 4KB page. */
841#define X86_PAGE_4K_SIZE _4K
842/** The page shift of a 4KB page. */
843#define X86_PAGE_4K_SHIFT 12
844/** The 4KB page offset mask. */
845#define X86_PAGE_4K_OFFSET_MASK 0xfff
846/** The 4KB page base mask for virtual addresses. */
847#define X86_PAGE_4K_BASE_MASK 0xfffffffffffff000ULL
848/** The 4KB page base mask for virtual addresses - 32bit version. */
849#define X86_PAGE_4K_BASE_MASK_32 0xfffff000U
850
851/** The size of a 2MB page. */
852#define X86_PAGE_2M_SIZE _2M
853/** The page shift of a 2MB page. */
854#define X86_PAGE_2M_SHIFT 21
855/** The 2MB page offset mask. */
856#define X86_PAGE_2M_OFFSET_MASK 0x001fffff
857/** The 2MB page base mask for virtual addresses. */
858#define X86_PAGE_2M_BASE_MASK 0xffffffffffe00000ULL
859/** The 2MB page base mask for virtual addresses - 32bit version. */
860#define X86_PAGE_2M_BASE_MASK_32 0xffe00000U
861
862/** The size of a 4MB page. */
863#define X86_PAGE_4M_SIZE _4M
864/** The page shift of a 4MB page. */
865#define X86_PAGE_4M_SHIFT 22
866/** The 4MB page offset mask. */
867#define X86_PAGE_4M_OFFSET_MASK 0x003fffff
868/** The 4MB page base mask for virtual addresses. */
869#define X86_PAGE_4M_BASE_MASK 0xffffffffffc00000ULL
870/** The 4MB page base mask for virtual addresses - 32bit version. */
871#define X86_PAGE_4M_BASE_MASK_32 0xffc00000U
872
873
874
875/** @name Page Table Entry
876 * @{
877 */
878/** Bit 0 - P - Present bit. */
879#define X86_PTE_P RT_BIT(0)
880/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
881#define X86_PTE_RW RT_BIT(1)
882/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
883#define X86_PTE_US RT_BIT(2)
884/** Bit 3 - PWT - Page level write thru bit. */
885#define X86_PTE_PWT RT_BIT(3)
886/** Bit 4 - PCD - Page level cache disable bit. */
887#define X86_PTE_PCD RT_BIT(4)
888/** Bit 5 - A - Access bit. */
889#define X86_PTE_A RT_BIT(5)
890/** Bit 6 - D - Dirty bit. */
891#define X86_PTE_D RT_BIT(6)
892/** Bit 7 - PAT - Page Attribute Table index bit. Reserved and 0 if not supported. */
893#define X86_PTE_PAT RT_BIT(7)
894/** Bit 8 - G - Global flag. */
895#define X86_PTE_G RT_BIT(8)
896/** Bits 9-11 - - Available for use to system software. */
897#define X86_PTE_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
898/** Bits 12-31 - - Physical Page number of the next level. */
899#define X86_PTE_PG_MASK ( 0xfffff000 )
900
901/** Bits 12-51 - - PAE - Physical Page number of the next level. */
902#if 1 /* we're using this internally and have to mask of the top 16-bit. */
903#define X86_PTE_PAE_PG_MASK ( 0x0000fffffffff000ULL )
904#else
905#define X86_PTE_PAE_PG_MASK ( 0x000ffffffffff000ULL )
906#endif
907/** Bits 63 - NX - PAE - No execution flag. */
908#define X86_PTE_PAE_NX RT_BIT_64(63)
909
910/**
911 * Page table entry.
912 */
913typedef struct X86PTEBITS
914{
915 /** Flags whether(=1) or not the page is present. */
916 unsigned u1Present : 1;
917 /** Read(=0) / Write(=1) flag. */
918 unsigned u1Write : 1;
919 /** User(=1) / Supervisor (=0) flag. */
920 unsigned u1User : 1;
921 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
922 unsigned u1WriteThru : 1;
923 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
924 unsigned u1CacheDisable : 1;
925 /** Accessed flag.
926 * Indicates that the page have been read or written to. */
927 unsigned u1Accessed : 1;
928 /** Dirty flag.
929 * Indicates that the page have been written to. */
930 unsigned u1Dirty : 1;
931 /** Reserved / If PAT enabled, bit 2 of the index. */
932 unsigned u1PAT : 1;
933 /** Global flag. (Ignored in all but final level.) */
934 unsigned u1Global : 1;
935 /** Available for use to system software. */
936 unsigned u3Available : 3;
937 /** Physical Page number of the next level. */
938 unsigned u20PageNo : 20;
939} X86PTEBITS;
940/** Pointer to a page table entry. */
941typedef X86PTEBITS *PX86PTEBITS;
942/** Pointer to a const page table entry. */
943typedef const X86PTEBITS *PCX86PTEBITS;
944
945/**
946 * Page table entry.
947 */
948typedef union X86PTE
949{
950 /** Bit field view. */
951 X86PTEBITS n;
952 /** Unsigned integer view */
953 X86PGUINT u;
954 /** 32-bit view. */
955 uint32_t au32[1];
956 /** 16-bit view. */
957 uint16_t au16[2];
958 /** 8-bit view. */
959 uint8_t au8[4];
960} X86PTE;
961/** Pointer to a page table entry. */
962typedef X86PTE *PX86PTE;
963/** Pointer to a const page table entry. */
964typedef const X86PTE *PCX86PTE;
965
966
967/**
968 * PAE page table entry.
969 */
970typedef struct X86PTEPAEBITS
971{
972 /** Flags whether(=1) or not the page is present. */
973 uint32_t u1Present : 1;
974 /** Read(=0) / Write(=1) flag. */
975 uint32_t u1Write : 1;
976 /** User(=1) / Supervisor(=0) flag. */
977 uint32_t u1User : 1;
978 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
979 uint32_t u1WriteThru : 1;
980 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
981 uint32_t u1CacheDisable : 1;
982 /** Accessed flag.
983 * Indicates that the page have been read or written to. */
984 uint32_t u1Accessed : 1;
985 /** Dirty flag.
986 * Indicates that the page have been written to. */
987 uint32_t u1Dirty : 1;
988 /** Reserved / If PAT enabled, bit 2 of the index. */
989 uint32_t u1PAT : 1;
990 /** Global flag. (Ignored in all but final level.) */
991 uint32_t u1Global : 1;
992 /** Available for use to system software. */
993 uint32_t u3Available : 3;
994 /** Physical Page number of the next level - Low Part. Don't use this. */
995 uint32_t u20PageNoLow : 20;
996 /** Physical Page number of the next level - High Part. Don't use this. */
997 uint32_t u20PageNoHigh : 20;
998 /** MBZ bits */
999 uint32_t u11Reserved : 11;
1000 /** No Execute flag. */
1001 uint32_t u1NoExecute : 1;
1002} X86PTEPAEBITS;
1003/** Pointer to a page table entry. */
1004typedef X86PTEPAEBITS *PX86PTEPAEBITS;
1005/** Pointer to a page table entry. */
1006typedef const X86PTEPAEBITS *PCX86PTEPAEBITS;
1007
1008/**
1009 * PAE Page table entry.
1010 */
1011typedef union X86PTEPAE
1012{
1013 /** Bit field view. */
1014 X86PTEPAEBITS n;
1015 /** Unsigned integer view */
1016 X86PGPAEUINT u;
1017 /** 32-bit view. */
1018 uint32_t au32[2];
1019 /** 16-bit view. */
1020 uint16_t au16[4];
1021 /** 8-bit view. */
1022 uint8_t au8[8];
1023} X86PTEPAE;
1024/** Pointer to a PAE page table entry. */
1025typedef X86PTEPAE *PX86PTEPAE;
1026/** Pointer to a const PAE page table entry. */
1027typedef const X86PTEPAE *PCX86PTEPAE;
1028/** @} */
1029
1030/**
1031 * Page table.
1032 */
1033typedef struct X86PT
1034{
1035 /** PTE Array. */
1036 X86PTE a[X86_PG_ENTRIES];
1037} X86PT;
1038/** Pointer to a page table. */
1039typedef X86PT *PX86PT;
1040/** Pointer to a const page table. */
1041typedef const X86PT *PCX86PT;
1042
1043/** The page shift to get the PT index. */
1044#define X86_PT_SHIFT 12
1045/** The PT index mask (apply to a shifted page address). */
1046#define X86_PT_MASK 0x3ff
1047
1048
1049/**
1050 * Page directory.
1051 */
1052typedef struct X86PTPAE
1053{
1054 /** PTE Array. */
1055 X86PTEPAE a[X86_PG_PAE_ENTRIES];
1056} X86PTPAE;
1057/** Pointer to a page table. */
1058typedef X86PTPAE *PX86PTPAE;
1059/** Pointer to a const page table. */
1060typedef const X86PTPAE *PCX86PTPAE;
1061
1062/** The page shift to get the PA PTE index. */
1063#define X86_PT_PAE_SHIFT 12
1064/** The PAE PT index mask (apply to a shifted page address). */
1065#define X86_PT_PAE_MASK 0x1ff
1066
1067
1068/** @name 4KB Page Directory Entry
1069 * @{
1070 */
1071/** Bit 0 - P - Present bit. */
1072#define X86_PDE_P RT_BIT(0)
1073/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
1074#define X86_PDE_RW RT_BIT(1)
1075/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
1076#define X86_PDE_US RT_BIT(2)
1077/** Bit 3 - PWT - Page level write thru bit. */
1078#define X86_PDE_PWT RT_BIT(3)
1079/** Bit 4 - PCD - Page level cache disable bit. */
1080#define X86_PDE_PCD RT_BIT(4)
1081/** Bit 5 - A - Access bit. */
1082#define X86_PDE_A RT_BIT(5)
1083/** Bit 7 - PS - Page size attribute.
1084 * Clear mean 4KB pages, set means large pages (2/4MB). */
1085#define X86_PDE_PS RT_BIT(7)
1086/** Bits 9-11 - - Available for use to system software. */
1087#define X86_PDE_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1088/** Bits 12-31 - - Physical Page number of the next level. */
1089#define X86_PDE_PG_MASK ( 0xfffff000 )
1090
1091/** Bits 12-51 - - PAE - Physical Page number of the next level. */
1092#if 1 /* we're using this internally and have to mask of the top 16-bit. */
1093#define X86_PDE_PAE_PG_MASK ( 0x0000fffffffff000ULL )
1094#else
1095#define X86_PDE_PAE_PG_MASK ( 0x000ffffffffff000ULL )
1096#endif
1097/** Bits 63 - NX - PAE - No execution flag. */
1098#define X86_PDE_PAE_NX RT_BIT_64(63)
1099
1100/**
1101 * Page directory entry.
1102 */
1103typedef struct X86PDEBITS
1104{
1105 /** Flags whether(=1) or not the page is present. */
1106 unsigned u1Present : 1;
1107 /** Read(=0) / Write(=1) flag. */
1108 unsigned u1Write : 1;
1109 /** User(=1) / Supervisor (=0) flag. */
1110 unsigned u1User : 1;
1111 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1112 unsigned u1WriteThru : 1;
1113 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1114 unsigned u1CacheDisable : 1;
1115 /** Accessed flag.
1116 * Indicates that the page have been read or written to. */
1117 unsigned u1Accessed : 1;
1118 /** Reserved / Ignored (dirty bit). */
1119 unsigned u1Reserved0 : 1;
1120 /** Size bit if PSE is enabled - in any event it's 0. */
1121 unsigned u1Size : 1;
1122 /** Reserved / Ignored (global bit). */
1123 unsigned u1Reserved1 : 1;
1124 /** Available for use to system software. */
1125 unsigned u3Available : 3;
1126 /** Physical Page number of the next level. */
1127 unsigned u20PageNo : 20;
1128} X86PDEBITS;
1129/** Pointer to a page directory entry. */
1130typedef X86PDEBITS *PX86PDEBITS;
1131/** Pointer to a const page directory entry. */
1132typedef const X86PDEBITS *PCX86PDEBITS;
1133
1134
1135/**
1136 * PAE page directory entry.
1137 */
1138typedef struct X86PDEPAEBITS
1139{
1140 /** Flags whether(=1) or not the page is present. */
1141 uint32_t u1Present : 1;
1142 /** Read(=0) / Write(=1) flag. */
1143 uint32_t u1Write : 1;
1144 /** User(=1) / Supervisor (=0) flag. */
1145 uint32_t u1User : 1;
1146 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1147 uint32_t u1WriteThru : 1;
1148 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1149 uint32_t u1CacheDisable : 1;
1150 /** Accessed flag.
1151 * Indicates that the page have been read or written to. */
1152 uint32_t u1Accessed : 1;
1153 /** Reserved / Ignored (dirty bit). */
1154 uint32_t u1Reserved0 : 1;
1155 /** Size bit if PSE is enabled - in any event it's 0. */
1156 uint32_t u1Size : 1;
1157 /** Reserved / Ignored (global bit). / */
1158 uint32_t u1Reserved1 : 1;
1159 /** Available for use to system software. */
1160 uint32_t u3Available : 3;
1161 /** Physical Page number of the next level - Low Part. Don't use! */
1162 uint32_t u20PageNoLow : 20;
1163 /** Physical Page number of the next level - High Part. Don't use! */
1164 uint32_t u20PageNoHigh : 20;
1165 /** MBZ bits */
1166 uint32_t u11Reserved : 11;
1167 /** No Execute flag. */
1168 uint32_t u1NoExecute : 1;
1169} X86PDEPAEBITS;
1170/** Pointer to a page directory entry. */
1171typedef X86PDEPAEBITS *PX86PDEPAEBITS;
1172/** Pointer to a const page directory entry. */
1173typedef const X86PDEPAEBITS *PCX86PDEPAEBITS;
1174
1175/** @} */
1176
1177
1178/** @name 2/4MB Page Directory Entry
1179 * @{
1180 */
1181/** Bit 0 - P - Present bit. */
1182#define X86_PDE4M_P RT_BIT(0)
1183/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
1184#define X86_PDE4M_RW RT_BIT(1)
1185/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
1186#define X86_PDE4M_US RT_BIT(2)
1187/** Bit 3 - PWT - Page level write thru bit. */
1188#define X86_PDE4M_PWT RT_BIT(3)
1189/** Bit 4 - PCD - Page level cache disable bit. */
1190#define X86_PDE4M_PCD RT_BIT(4)
1191/** Bit 5 - A - Access bit. */
1192#define X86_PDE4M_A RT_BIT(5)
1193/** Bit 6 - D - Dirty bit. */
1194#define X86_PDE4M_D RT_BIT(6)
1195/** Bit 7 - PS - Page size attribute. Clear mean 4KB pages, set means large pages (2/4MB). */
1196#define X86_PDE4M_PS RT_BIT(7)
1197/** Bit 8 - G - Global flag. */
1198#define X86_PDE4M_G RT_BIT(8)
1199/** Bits 9-11 - AVL - Available for use to system software. */
1200#define X86_PDE4M_AVL (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1201/** Bit 12 - PAT - Page Attribute Table index bit. Reserved and 0 if not supported. */
1202#define X86_PDE4M_PAT RT_BIT(12)
1203/** Shift to get from X86_PTE_PAT to X86_PDE4M_PAT. */
1204#define X86_PDE4M_PAT_SHIFT (12 - 7)
1205/** Bits 22-31 - - Physical Page number. */
1206#define X86_PDE4M_PG_MASK ( 0xffc00000 )
1207/** Bits 13-20 - - Physical Page number high part (32-39 bits). AMD64 hack. */
1208#define X86_PDE4M_PG_HIGH_MASK ( 0x001fe000 )
1209/** The number of bits to the high part of the page number. */
1210#define X86_PDE4M_PG_HIGH_SHIFT 19
1211
1212/** Bits 21-36 - - PAE - Physical Page number. */
1213#define X86_PDE2M_PAE_PG_MASK ( 0x0000000fffe00000ULL )
1214/** Bits 63 - NX - PAE - No execution flag. */
1215#define X86_PDE2M_PAE_NX RT_BIT_64(63)
1216
1217/** Bits 21-39 - - AMD64 - Physical Page number. (bits 40-51 are reserved) */
1218#define X86_PDE2M_AMD64_PG_MASK ( 0x000000ffffe00000ULL )
1219/** Bits 63 - NX - AMD64 - No execution flag. */
1220#define X86_PDE2M_AMD64_NX X86_PDE2M_PAE_NX
1221
1222/**
1223 * 4MB page directory entry.
1224 */
1225typedef struct X86PDE4MBITS
1226{
1227 /** Flags whether(=1) or not the page is present. */
1228 unsigned u1Present : 1;
1229 /** Read(=0) / Write(=1) flag. */
1230 unsigned u1Write : 1;
1231 /** User(=1) / Supervisor (=0) flag. */
1232 unsigned u1User : 1;
1233 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1234 unsigned u1WriteThru : 1;
1235 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1236 unsigned u1CacheDisable : 1;
1237 /** Accessed flag.
1238 * Indicates that the page have been read or written to. */
1239 unsigned u1Accessed : 1;
1240 /** Dirty flag.
1241 * Indicates that the page have been written to. */
1242 unsigned u1Dirty : 1;
1243 /** Page size flag - always 1 for 4MB entries. */
1244 unsigned u1Size : 1;
1245 /** Global flag. */
1246 unsigned u1Global : 1;
1247 /** Available for use to system software. */
1248 unsigned u3Available : 3;
1249 /** Reserved / If PAT enabled, bit 2 of the index. */
1250 unsigned u1PAT : 1;
1251 /** Bits 32-39 of the page number on AMD64.
1252 * This AMD64 hack allows accessing 40bits of physical memory without PAE. */
1253 unsigned u8PageNoHigh : 8;
1254 /** Reserved. */
1255 unsigned u1Reserved : 1;
1256 /** Physical Page number of the page. */
1257 unsigned u10PageNo : 10;
1258} X86PDE4MBITS;
1259/** Pointer to a page table entry. */
1260typedef X86PDE4MBITS *PX86PDE4MBITS;
1261/** Pointer to a const page table entry. */
1262typedef const X86PDE4MBITS *PCX86PDE4MBITS;
1263
1264
1265/**
1266 * 2MB PAE page directory entry.
1267 */
1268typedef struct X86PDE2MPAEBITS
1269{
1270 /** Flags whether(=1) or not the page is present. */
1271 uint32_t u1Present : 1;
1272 /** Read(=0) / Write(=1) flag. */
1273 uint32_t u1Write : 1;
1274 /** User(=1) / Supervisor(=0) flag. */
1275 uint32_t u1User : 1;
1276 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1277 uint32_t u1WriteThru : 1;
1278 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1279 uint32_t u1CacheDisable : 1;
1280 /** Accessed flag.
1281 * Indicates that the page have been read or written to. */
1282 uint32_t u1Accessed : 1;
1283 /** Dirty flag.
1284 * Indicates that the page have been written to. */
1285 uint32_t u1Dirty : 1;
1286 /** Page size flag - always 1 for 2MB entries. */
1287 uint32_t u1Size : 1;
1288 /** Global flag. */
1289 uint32_t u1Global : 1;
1290 /** Available for use to system software. */
1291 uint32_t u3Available : 3;
1292 /** Reserved / If PAT enabled, bit 2 of the index. */
1293 uint32_t u1PAT : 1;
1294 /** Reserved. */
1295 uint32_t u9Reserved : 9;
1296 /** Physical Page number of the next level - Low part. Don't use! */
1297 uint32_t u10PageNoLow : 10;
1298 /** Physical Page number of the next level - High part. Don't use! */
1299 uint32_t u20PageNoHigh : 20;
1300 /** MBZ bits */
1301 uint32_t u11Reserved : 11;
1302 /** No Execute flag. */
1303 uint32_t u1NoExecute : 1;
1304} X86PDE2MPAEBITS;
1305/** Pointer to a 4MB PAE page table entry. */
1306typedef X86PDE2MPAEBITS *PX86PDE2MPAEBITS;
1307/** Pointer to a 4MB PAE page table entry. */
1308typedef const X86PDE2MPAEBITS *PCX86PDE2MPAEBITS;
1309
1310/** @} */
1311
1312/**
1313 * Page directory entry.
1314 */
1315typedef union X86PDE
1316{
1317 /** Normal view. */
1318 X86PDEBITS n;
1319 /** 4MB view (big). */
1320 X86PDE4MBITS b;
1321 /** Unsigned integer view. */
1322 X86PGUINT u;
1323 /** 8 bit unsigned integer view. */
1324 uint8_t au8[4];
1325 /** 16 bit unsigned integer view. */
1326 uint16_t au16[2];
1327 /** 32 bit unsigned integer view. */
1328 uint32_t au32[1];
1329} X86PDE;
1330/** Pointer to a page directory entry. */
1331typedef X86PDE *PX86PDE;
1332/** Pointer to a const page directory entry. */
1333typedef const X86PDE *PCX86PDE;
1334
1335/**
1336 * PAE page directory entry.
1337 */
1338typedef union X86PDEPAE
1339{
1340 /** Normal view. */
1341 X86PDEPAEBITS n;
1342 /** 2MB page view (big). */
1343 X86PDE2MPAEBITS b;
1344 /** Unsigned integer view. */
1345 X86PGPAEUINT u;
1346 /** 8 bit unsigned integer view. */
1347 uint8_t au8[8];
1348 /** 16 bit unsigned integer view. */
1349 uint16_t au16[4];
1350 /** 32 bit unsigned integer view. */
1351 uint32_t au32[2];
1352} X86PDEPAE;
1353/** Pointer to a page directory entry. */
1354typedef X86PDEPAE *PX86PDEPAE;
1355/** Pointer to a const page directory entry. */
1356typedef const X86PDEPAE *PCX86PDEPAE;
1357
1358/**
1359 * Page directory.
1360 */
1361typedef struct X86PD
1362{
1363 /** PDE Array. */
1364 X86PDE a[X86_PG_ENTRIES];
1365} X86PD;
1366/** Pointer to a page directory. */
1367typedef X86PD *PX86PD;
1368/** Pointer to a const page directory. */
1369typedef const X86PD *PCX86PD;
1370
1371/** The page shift to get the PD index. */
1372#define X86_PD_SHIFT 22
1373/** The PD index mask (apply to a shifted page address). */
1374#define X86_PD_MASK 0x3ff
1375
1376
1377/**
1378 * PAE page directory.
1379 */
1380typedef struct X86PDPAE
1381{
1382 /** PDE Array. */
1383 X86PDEPAE a[X86_PG_PAE_ENTRIES];
1384} X86PDPAE;
1385/** Pointer to a PAE page directory. */
1386typedef X86PDPAE *PX86PDPAE;
1387/** Pointer to a const PAE page directory. */
1388typedef const X86PDPAE *PCX86PDPAE;
1389
1390/** The page shift to get the PAE PD index. */
1391#define X86_PD_PAE_SHIFT 21
1392/** The PAE PD index mask (apply to a shifted page address). */
1393#define X86_PD_PAE_MASK 0x1ff
1394
1395
1396/** @name Page Directory Pointer Table Entry (PAE)
1397 * @{
1398 */
1399/** Bit 0 - P - Present bit. */
1400#define X86_PDPE_P RT_BIT(0)
1401/** Bit 1 - R/W - Read (clear) / Write (set) bit. Long Mode only. */
1402#define X86_PDPE_RW RT_BIT(1)
1403/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. Long Mode only. */
1404#define X86_PDPE_US RT_BIT(2)
1405/** Bit 3 - PWT - Page level write thru bit. */
1406#define X86_PDPE_PWT RT_BIT(3)
1407/** Bit 4 - PCD - Page level cache disable bit. */
1408#define X86_PDPE_PCD RT_BIT(4)
1409/** Bit 5 - A - Access bit. Long Mode only. */
1410#define X86_PDPE_A RT_BIT(5)
1411/** Bits 9-11 - - Available for use to system software. */
1412#define X86_PDPE_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1413/** Bits 12-51 - - PAE - Physical Page number of the next level. */
1414#if 1 /* we're using this internally and have to mask of the top 16-bit. */
1415#define X86_PDPE_PG_MASK ( 0x0000fffffffff000ULL )
1416#else
1417#define X86_PDPE_PG_MASK ( 0x000ffffffffff000ULL )
1418#endif
1419/** Bits 63 - NX - PAE - No execution flag. */
1420#define X86_PDPE_NX RT_BIT_64(63)
1421
1422/**
1423 * Page directory pointer table entry.
1424 */
1425typedef struct X86PDPEBITS
1426{
1427 /** Flags whether(=1) or not the page is present. */
1428 uint32_t u1Present : 1;
1429 /** Read(=0) / Write(=1) flag. */
1430 uint32_t u1Write : 1;
1431 /** User(=1) / Supervisor (=0) flag. */
1432 uint32_t u1User : 1;
1433 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1434 uint32_t u1WriteThru : 1;
1435 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1436 uint32_t u1CacheDisable : 1;
1437 /** Accessed flag.
1438 * Indicates that the page have been read or written to. */
1439 uint32_t u1Accessed : 1;
1440 /** Chunk of reserved bits. */
1441 uint32_t u3Reserved : 3;
1442 /** Available for use to system software. */
1443 uint32_t u3Available : 3;
1444 /** Physical Page number of the next level - Low Part. Don't use! */
1445 uint32_t u20PageNoLow : 20;
1446 /** Physical Page number of the next level - High Part. Don't use! */
1447 uint32_t u20PageNoHigh : 20;
1448 /** MBZ bits */
1449 uint32_t u11Reserved : 11;
1450 /** No Execute flag. */
1451 uint32_t u1NoExecute : 1;
1452} X86PDPEBITS;
1453/** Pointer to a page directory pointer table entry. */
1454typedef X86PDPEBITS *PX86PTPEBITS;
1455/** Pointer to a const page directory pointer table entry. */
1456typedef const X86PDPEBITS *PCX86PTPEBITS;
1457
1458/**
1459 * Page directory pointer table entry.
1460 */
1461typedef union X86PDPE
1462{
1463 /** Normal view. */
1464 X86PDPEBITS n;
1465 /** Unsigned integer view. */
1466 X86PGPAEUINT u;
1467 /** 8 bit unsigned integer view. */
1468 uint8_t au8[8];
1469 /** 16 bit unsigned integer view. */
1470 uint16_t au16[4];
1471 /** 32 bit unsigned integer view. */
1472 uint32_t au32[2];
1473} X86PDPE;
1474/** Pointer to a page directory pointer table entry. */
1475typedef X86PDPE *PX86PDPE;
1476/** Pointer to a const page directory pointer table entry. */
1477typedef const X86PDPE *PCX86PDPE;
1478
1479
1480/**
1481 * Page directory pointer table.
1482 */
1483typedef struct X86PDPTR
1484{
1485 /** PDE Array. */
1486 X86PDPE a[X86_PG_PAE_ENTRIES];
1487} X86PDPTR;
1488/** Pointer to a page directory pointer table. */
1489typedef X86PDPTR *PX86PDPTR;
1490/** Pointer to a const page directory pointer table. */
1491typedef const X86PDPTR *PCX86PDPTR;
1492
1493/** The page shift to get the PDPTR index. */
1494#define X86_PDPTR_SHIFT 30
1495/** The PDPTR index mask (apply to a shifted page address). (32 bits PAE) */
1496#define X86_PDPTR_MASK_32 0x3
1497/** The PDPTR index mask (apply to a shifted page address). (64 bits PAE)*/
1498#define X86_PDPTR_MASK 0x1ff
1499
1500/** @} */
1501
1502
1503/** @name Page Map Level-4 Entry (Long Mode PAE)
1504 * @{
1505 */
1506/** Bit 0 - P - Present bit. */
1507#define X86_PML4E_P RT_BIT(0)
1508/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
1509#define X86_PML4E_RW RT_BIT(1)
1510/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
1511#define X86_PML4E_US RT_BIT(2)
1512/** Bit 3 - PWT - Page level write thru bit. */
1513#define X86_PML4E_PWT RT_BIT(3)
1514/** Bit 4 - PCD - Page level cache disable bit. */
1515#define X86_PML4E_PCD RT_BIT(4)
1516/** Bit 5 - A - Access bit. */
1517#define X86_PML4E_A RT_BIT(5)
1518/** Bits 9-11 - - Available for use to system software. */
1519#define X86_PML4E_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1520/** Bits 12-51 - - PAE - Physical Page number of the next level. */
1521#if 1 /* we're using this internally and have to mask of the top 16-bit. */
1522#define X86_PML4E_PG_MASK ( 0x0000fffffffff000ULL )
1523#else
1524#define X86_PML4E_PG_MASK ( 0x000ffffffffff000ULL )
1525#endif
1526/** Bits 63 - NX - PAE - No execution flag. */
1527#define X86_PML4E_NX RT_BIT_64(63)
1528
1529/**
1530 * Page Map Level-4 Entry
1531 */
1532typedef struct X86PML4EBITS
1533{
1534 /** Flags whether(=1) or not the page is present. */
1535 uint32_t u1Present : 1;
1536 /** Read(=0) / Write(=1) flag. */
1537 uint32_t u1Write : 1;
1538 /** User(=1) / Supervisor (=0) flag. */
1539 uint32_t u1User : 1;
1540 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1541 uint32_t u1WriteThru : 1;
1542 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1543 uint32_t u1CacheDisable : 1;
1544 /** Accessed flag.
1545 * Indicates that the page have been read or written to. */
1546 uint32_t u1Accessed : 1;
1547 /** Chunk of reserved bits. */
1548 uint32_t u3Reserved : 3;
1549 /** Available for use to system software. */
1550 uint32_t u3Available : 3;
1551 /** Physical Page number of the next level - Low Part. Don't use! */
1552 uint32_t u20PageNoLow : 20;
1553 /** Physical Page number of the next level - High Part. Don't use! */
1554 uint32_t u20PageNoHigh : 20;
1555 /** MBZ bits */
1556 uint32_t u11Reserved : 11;
1557 /** No Execute flag. */
1558 uint32_t u1NoExecute : 1;
1559} X86PML4EBITS;
1560/** Pointer to a page map level-4 entry. */
1561typedef X86PML4EBITS *PX86PML4EBITS;
1562/** Pointer to a const page map level-4 entry. */
1563typedef const X86PML4EBITS *PCX86PML4EBITS;
1564
1565/**
1566 * Page Map Level-4 Entry.
1567 */
1568typedef union X86PML4E
1569{
1570 /** Normal view. */
1571 X86PML4EBITS n;
1572 /** Unsigned integer view. */
1573 X86PGPAEUINT u;
1574 /** 8 bit unsigned integer view. */
1575 uint8_t au8[8];
1576 /** 16 bit unsigned integer view. */
1577 uint16_t au16[4];
1578 /** 32 bit unsigned integer view. */
1579 uint32_t au32[2];
1580} X86PML4E;
1581/** Pointer to a page map level-4 entry. */
1582typedef X86PML4E *PX86PML4E;
1583/** Pointer to a const page map level-4 entry. */
1584typedef const X86PML4E *PCX86PML4E;
1585
1586
1587/**
1588 * Page Map Level-4.
1589 */
1590typedef struct X86PML4
1591{
1592 /** PDE Array. */
1593 X86PML4E a[X86_PG_PAE_ENTRIES];
1594} X86PML4;
1595/** Pointer to a page map level-4. */
1596typedef X86PML4 *PX86PML4;
1597/** Pointer to a const page map level-4. */
1598typedef const X86PML4 *PCX86PML4;
1599
1600/** The page shift to get the PML4 index. */
1601#define X86_PML4_SHIFT 39
1602/** The PML4 index mask (apply to a shifted page address). */
1603#define X86_PML4_MASK 0x1ff
1604
1605/** @} */
1606
1607/** @} */
1608
1609
1610/**
1611 * 80-bit MMX/FPU register type.
1612 */
1613typedef struct X86FPUMMX
1614{
1615 uint8_t reg[10];
1616} X86FPUMMX;
1617/** Pointer to a 80-bit MMX/FPU register type. */
1618typedef X86FPUMMX *PX86FPUMMX;
1619/** Pointer to a const 80-bit MMX/FPU register type. */
1620typedef const X86FPUMMX *PCX86FPUMMX;
1621
1622/**
1623 * FPU state (aka FSAVE/FRSTOR Memory Region).
1624 */
1625#pragma pack(1)
1626typedef struct X86FPUSTATE
1627{
1628 /** Control word. */
1629 uint16_t FCW;
1630 /** Alignment word */
1631 uint16_t Dummy1;
1632 /** Status word. */
1633 uint16_t FSW;
1634 /** Alignment word */
1635 uint16_t Dummy2;
1636 /** Tag word */
1637 uint16_t FTW;
1638 /** Alignment word */
1639 uint16_t Dummy3;
1640
1641 /** Instruction pointer. */
1642 uint32_t FPUIP;
1643 /** Code selector. */
1644 uint16_t CS;
1645 /** Opcode. */
1646 uint16_t FOP;
1647 /** FOO. */
1648 uint32_t FPUOO;
1649 /** FOS. */
1650 uint32_t FPUOS;
1651 /** FPU view - todo. */
1652 X86FPUMMX regs[8];
1653} X86FPUSTATE;
1654#pragma pack()
1655/** Pointer to a FPU state. */
1656typedef X86FPUSTATE *PX86FPUSTATE;
1657/** Pointer to a const FPU state. */
1658typedef const X86FPUSTATE *PCX86FPUSTATE;
1659
1660/**
1661 * FPU Extended state (aka FXSAVE/FXRSTORE Memory Region).
1662 */
1663#pragma pack(1)
1664typedef struct X86FXSTATE
1665{
1666 /** Control word. */
1667 uint16_t FCW;
1668 /** Status word. */
1669 uint16_t FSW;
1670 /** Tag word (it's a byte actually). */
1671 uint8_t FTW;
1672 uint8_t huh1;
1673 /** Opcode. */
1674 uint16_t FOP;
1675 /** Instruction pointer. */
1676 uint32_t FPUIP;
1677 /** Code selector. */
1678 uint16_t CS;
1679 uint16_t Rsvrd1;
1680 /* - offset 16 - */
1681 /** Data pointer. */
1682 uint32_t FPUDP;
1683 /** Data segment */
1684 uint16_t DS;
1685 uint16_t Rsrvd2;
1686 uint32_t MXCSR;
1687 uint32_t MXCSR_MASK;
1688 /* - offset 32 - */
1689 union
1690 {
1691 /** MMX view. */
1692 uint64_t mmx;
1693 /** FPU view - todo. */
1694 X86FPUMMX fpu;
1695 /** 8-bit view. */
1696 uint8_t au8[16];
1697 /** 16-bit view. */
1698 uint16_t au16[8];
1699 /** 32-bit view. */
1700 uint32_t au32[4];
1701 /** 64-bit view. */
1702 uint64_t au64[2];
1703 /** 128-bit view. (yeah, very helpful) */
1704 uint128_t au128[1];
1705 } aRegs[8];
1706 /* - offset 160 - */
1707 union
1708 {
1709 /** XMM Register view *. */
1710 uint128_t xmm;
1711 /** 8-bit view. */
1712 uint8_t au8[16];
1713 /** 16-bit view. */
1714 uint16_t au16[8];
1715 /** 32-bit view. */
1716 uint32_t au32[4];
1717 /** 64-bit view. */
1718 uint64_t au64[2];
1719 /** 128-bit view. (yeah, very helpful) */
1720 uint128_t au128[1];
1721 } aXMM[16]; /* 8 registers in 32 bits mode; 16 in long mode */
1722 /* - offset 416 - */
1723 uint32_t au32RsrvdRest[(512 - 416) / sizeof(uint32_t)];
1724} X86FXSTATE;
1725#pragma pack()
1726/** Pointer to a FPU Extended state. */
1727typedef X86FXSTATE *PX86FXSTATE;
1728/** Pointer to a const FPU Extended state. */
1729typedef const X86FXSTATE *PCX86FXSTATE;
1730
1731
1732/** @name Selector Descriptor
1733 * @{
1734 */
1735
1736/**
1737 * Generic descriptor table entry
1738 */
1739#pragma pack(1)
1740typedef struct X86DESCGENERIC
1741{
1742 /** Limit - Low word. */
1743 unsigned u16LimitLow : 16;
1744 /** Base address - lowe word.
1745 * Don't try set this to 24 because MSC is doing studing things then. */
1746 unsigned u16BaseLow : 16;
1747 /** Base address - first 8 bits of high word. */
1748 unsigned u8BaseHigh1 : 8;
1749 /** Segment Type. */
1750 unsigned u4Type : 4;
1751 /** Descriptor Type. System(=0) or code/data selector */
1752 unsigned u1DescType : 1;
1753 /** Descriptor Privelege level. */
1754 unsigned u2Dpl : 2;
1755 /** Flags selector present(=1) or not. */
1756 unsigned u1Present : 1;
1757 /** Segment limit 16-19. */
1758 unsigned u4LimitHigh : 4;
1759 /** Available for system software. */
1760 unsigned u1Available : 1;
1761 /** Reserved - 0. */
1762 unsigned u1Reserved : 1;
1763 /** This flags meaning depends on the segment type. Try make sense out
1764 * of the intel manual yourself. */
1765 unsigned u1DefBig : 1;
1766 /** Granularity of the limit. If set 4KB granularity is used, if
1767 * clear byte. */
1768 unsigned u1Granularity : 1;
1769 /** Base address - highest 8 bits. */
1770 unsigned u8BaseHigh2 : 8;
1771} X86DESCGENERIC;
1772#pragma pack()
1773/** Pointer to a generic descriptor entry. */
1774typedef X86DESCGENERIC *PX86DESCGENERIC;
1775/** Pointer to a const generic descriptor entry. */
1776typedef const X86DESCGENERIC *PCX86DESCGENERIC;
1777
1778
1779/**
1780 * Descriptor attributes.
1781 */
1782typedef struct X86DESCATTRBITS
1783{
1784 /** Segment Type. */
1785 unsigned u4Type : 4;
1786 /** Descriptor Type. System(=0) or code/data selector */
1787 unsigned u1DescType : 1;
1788 /** Descriptor Privelege level. */
1789 unsigned u2Dpl : 2;
1790 /** Flags selector present(=1) or not. */
1791 unsigned u1Present : 1;
1792 /** Segment limit 16-19. */
1793 unsigned u4LimitHigh : 4;
1794 /** Available for system software. */
1795 unsigned u1Available : 1;
1796 /** Reserved - 0. */
1797 unsigned u1Reserved : 1;
1798 /** This flags meaning depends on the segment type. Try make sense out
1799 * of the intel manual yourself. */
1800 unsigned u1DefBig : 1;
1801 /** Granularity of the limit. If set 4KB granularity is used, if
1802 * clear byte. */
1803 unsigned u1Granularity : 1;
1804} X86DESCATTRBITS;
1805
1806
1807#pragma pack(1)
1808typedef union X86DESCATTR
1809{
1810 /** Normal view. */
1811 X86DESCATTRBITS n;
1812 /** Unsigned integer view. */
1813 uint32_t u;
1814} X86DESCATTR;
1815#pragma pack()
1816
1817/** Pointer to descriptor attributes. */
1818typedef X86DESCATTR *PX86DESCATTR;
1819/** Pointer to const descriptor attributes. */
1820typedef const X86DESCATTR *PCX86DESCATTR;
1821
1822
1823/**
1824 * Descriptor table entry.
1825 */
1826#pragma pack(1)
1827typedef union X86DESC
1828{
1829 /** Generic descriptor view. */
1830 X86DESCGENERIC Gen;
1831#if 0
1832 /** IDT view. */
1833 VBOXIDTE Idt;
1834#endif
1835
1836 /** 8 bit unsigned interger view. */
1837 uint8_t au8[8];
1838 /** 16 bit unsigned interger view. */
1839 uint16_t au16[4];
1840 /** 32 bit unsigned interger view. */
1841 uint32_t au32[2];
1842} X86DESC;
1843#pragma pack()
1844/** Pointer to descriptor table entry. */
1845typedef X86DESC *PX86DESC;
1846/** Pointer to const descriptor table entry. */
1847typedef const X86DESC *PCX86DESC;
1848
1849
1850/**
1851 * 64 bits generic descriptor table entry
1852 * Note: most of these bits have no meaning in long mode.
1853 */
1854#pragma pack(1)
1855typedef struct X86DESC64GENERIC
1856{
1857 /** Limit - Low word - *IGNORED*. */
1858 unsigned u16LimitLow : 16;
1859 /** Base address - lowe word. - *IGNORED*
1860 * Don't try set this to 24 because MSC is doing studing things then. */
1861 unsigned u16BaseLow : 16;
1862 /** Base address - first 8 bits of high word. - *IGNORED* */
1863 unsigned u8BaseHigh1 : 8;
1864 /** Segment Type. */
1865 unsigned u4Type : 4;
1866 /** Descriptor Type. System(=0) or code/data selector */
1867 unsigned u1DescType : 1;
1868 /** Descriptor Privelege level. */
1869 unsigned u2Dpl : 2;
1870 /** Flags selector present(=1) or not. */
1871 unsigned u1Present : 1;
1872 /** Segment limit 16-19. - *IGNORED* */
1873 unsigned u4LimitHigh : 4;
1874 /** Available for system software. - *IGNORED* */
1875 unsigned u1Available : 1;
1876 /** Long mode flag. */
1877 unsigned u1Long : 1;
1878 /** This flags meaning depends on the segment type. Try make sense out
1879 * of the intel manual yourself. */
1880 unsigned u1DefBig : 1;
1881 /** Granularity of the limit. If set 4KB granularity is used, if
1882 * clear byte. - *IGNORED* */
1883 unsigned u1Granularity : 1;
1884 /** Base address - highest 8 bits. - *IGNORED* */
1885 unsigned u8BaseHigh2 : 8;
1886 /** Base address - bits 63-32. */
1887 unsigned u32BaseHigh3 : 32;
1888 unsigned u8Reserved : 8;
1889 unsigned u5Zeros : 5;
1890 unsigned u19Reserved : 19;
1891} X86DESC64GENERIC;
1892#pragma pack()
1893/** Pointer to a generic descriptor entry. */
1894typedef X86DESC64GENERIC *PX86DESC64GENERIC;
1895/** Pointer to a const generic descriptor entry. */
1896typedef const X86DESC64GENERIC *PCX86DESC64GENERIC;
1897
1898/**
1899 * System descriptor table entry (64 bits)
1900 */
1901#pragma pack(1)
1902typedef struct X86DESC64SYSTEM
1903{
1904 /** Limit - Low word. */
1905 unsigned u16LimitLow : 16;
1906 /** Base address - lowe word.
1907 * Don't try set this to 24 because MSC is doing studing things then. */
1908 unsigned u16BaseLow : 16;
1909 /** Base address - first 8 bits of high word. */
1910 unsigned u8BaseHigh1 : 8;
1911 /** Segment Type. */
1912 unsigned u4Type : 4;
1913 /** Descriptor Type. System(=0) or code/data selector */
1914 unsigned u1DescType : 1;
1915 /** Descriptor Privelege level. */
1916 unsigned u2Dpl : 2;
1917 /** Flags selector present(=1) or not. */
1918 unsigned u1Present : 1;
1919 /** Segment limit 16-19. */
1920 unsigned u4LimitHigh : 4;
1921 /** Available for system software. */
1922 unsigned u1Available : 1;
1923 /** Reserved - 0. */
1924 unsigned u1Reserved : 1;
1925 /** This flags meaning depends on the segment type. Try make sense out
1926 * of the intel manual yourself. */
1927 unsigned u1DefBig : 1;
1928 /** Granularity of the limit. If set 4KB granularity is used, if
1929 * clear byte. */
1930 unsigned u1Granularity : 1;
1931 /** Base address - bits 31-24. */
1932 unsigned u8BaseHigh2 : 8;
1933 /** Base address - bits 63-32. */
1934 unsigned u32BaseHigh3 : 32;
1935 unsigned u8Reserved : 8;
1936 unsigned u5Zeros : 5;
1937 unsigned u19Reserved : 19;
1938} X86DESC64SYSTEM;
1939#pragma pack()
1940/** Pointer to a generic descriptor entry. */
1941typedef X86DESC64SYSTEM *PX86DESC64SYSTEM;
1942/** Pointer to a const generic descriptor entry. */
1943typedef const X86DESC64SYSTEM *PCX86DESC64SYSTEM;
1944
1945
1946/**
1947 * Descriptor table entry.
1948 */
1949#pragma pack(1)
1950typedef union X86DESC64
1951{
1952 /** Generic descriptor view. */
1953 X86DESC64GENERIC Gen;
1954 /** System descriptor view. */
1955 X86DESC64SYSTEM System;
1956#if 0
1957 X86DESC64GATE Gate;
1958#endif
1959
1960 /** 8 bit unsigned interger view. */
1961 uint8_t au8[16];
1962 /** 16 bit unsigned interger view. */
1963 uint16_t au16[8];
1964 /** 32 bit unsigned interger view. */
1965 uint32_t au32[4];
1966 /** 64 bit unsigned interger view. */
1967 uint64_t au64[2];
1968} X86DESC64;
1969#pragma pack()
1970/** Pointer to descriptor table entry. */
1971typedef X86DESC64 *PX86DESC64;
1972/** Pointer to const descriptor table entry. */
1973typedef const X86DESC64 *PCX86DESC64;
1974
1975#if HC_ARCH_BITS == 64
1976typedef X86DESC64 X86DESCHC;
1977typedef X86DESC64 *PX86DESCHC;
1978#else
1979typedef X86DESC X86DESCHC;
1980typedef X86DESC *PX86DESCHC;
1981#endif
1982
1983/** @name Selector Descriptor Types.
1984 * @{
1985 */
1986
1987/** @name Non-System Selector Types.
1988 * @{ */
1989/** Code(=set)/Data(=clear) bit. */
1990#define X86_SEL_TYPE_CODE 8
1991/** Memory(=set)/System(=clear) bit. */
1992#define X86_SEL_TYPE_MEMORY RT_BIT(4)
1993/** Accessed bit. */
1994#define X86_SEL_TYPE_ACCESSED 1
1995/** Expand down bit (for data selectors only). */
1996#define X86_SEL_TYPE_DOWN 4
1997/** Conforming bit (for code selectors only). */
1998#define X86_SEL_TYPE_CONF 4
1999/** Write bit (for data selectors only). */
2000#define X86_SEL_TYPE_WRITE 2
2001/** Read bit (for code selectors only). */
2002#define X86_SEL_TYPE_READ 2
2003
2004/** Read only selector type. */
2005#define X86_SEL_TYPE_RO 0
2006/** Accessed read only selector type. */
2007#define X86_SEL_TYPE_RO_ACC (0 | X86_SEL_TYPE_ACCESSED)
2008/** Read write selector type. */
2009#define X86_SEL_TYPE_RW 2
2010/** Accessed read write selector type. */
2011#define X86_SEL_TYPE_RW_ACC (2 | X86_SEL_TYPE_ACCESSED)
2012/** Expand down read only selector type. */
2013#define X86_SEL_TYPE_RO_DOWN 4
2014/** Accessed expand down read only selector type. */
2015#define X86_SEL_TYPE_RO_DOWN_ACC (4 | X86_SEL_TYPE_ACCESSED)
2016/** Expand down read write selector type. */
2017#define X86_SEL_TYPE_RW_DOWN 6
2018/** Accessed expand down read write selector type. */
2019#define X86_SEL_TYPE_RW_DOWN_ACC (6 | X86_SEL_TYPE_ACCESSED)
2020/** Execute only selector type. */
2021#define X86_SEL_TYPE_EO (0 | X86_SEL_TYPE_CODE)
2022/** Accessed execute only selector type. */
2023#define X86_SEL_TYPE_EO_ACC (0 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2024/** Execute and read selector type. */
2025#define X86_SEL_TYPE_ER (2 | X86_SEL_TYPE_CODE)
2026/** Accessed execute and read selector type. */
2027#define X86_SEL_TYPE_ER_ACC (2 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2028/** Conforming execute only selector type. */
2029#define X86_SEL_TYPE_EO_CONF (4 | X86_SEL_TYPE_CODE)
2030/** Accessed Conforming execute only selector type. */
2031#define X86_SEL_TYPE_EO_CONF_ACC (4 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2032/** Conforming execute and write selector type. */
2033#define X86_SEL_TYPE_ER_CONF (6 | X86_SEL_TYPE_CODE)
2034/** Accessed Conforming execute and write selector type. */
2035#define X86_SEL_TYPE_ER_CONF_ACC (6 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2036/** @} */
2037
2038
2039/** @name System Selector Types.
2040 * @{ */
2041/** Undefined system selector type. */
2042#define X86_SEL_TYPE_SYS_UNDEFINED 0
2043/** 286 TSS selector. */
2044#define X86_SEL_TYPE_SYS_286_TSS_AVAIL 1
2045/** LDT selector. */
2046#define X86_SEL_TYPE_SYS_LDT 2
2047/** 286 TSS selector - Busy. */
2048#define X86_SEL_TYPE_SYS_286_TSS_BUSY 3
2049/** 286 Callgate selector. */
2050#define X86_SEL_TYPE_SYS_286_CALL_GATE 4
2051/** Taskgate selector. */
2052#define X86_SEL_TYPE_SYS_TASK_GATE 5
2053/** 286 Interrupt gate selector. */
2054#define X86_SEL_TYPE_SYS_286_INT_GATE 6
2055/** 286 Trapgate selector. */
2056#define X86_SEL_TYPE_SYS_286_TRAP_GATE 7
2057/** Undefined system selector. */
2058#define X86_SEL_TYPE_SYS_UNDEFINED2 8
2059/** 386 TSS selector. */
2060#define X86_SEL_TYPE_SYS_386_TSS_AVAIL 9
2061/** Undefined system selector. */
2062#define X86_SEL_TYPE_SYS_UNDEFINED3 0xA
2063/** 386 TSS selector - Busy. */
2064#define X86_SEL_TYPE_SYS_386_TSS_BUSY 0xB
2065/** 386 Callgate selector. */
2066#define X86_SEL_TYPE_SYS_386_CALL_GATE 0xC
2067/** Undefined system selector. */
2068#define X86_SEL_TYPE_SYS_UNDEFINED4 0xD
2069/** 386 Interruptgate selector. */
2070#define X86_SEL_TYPE_SYS_386_INT_GATE 0xE
2071/** 386 Trapgate selector. */
2072#define X86_SEL_TYPE_SYS_386_TRAP_GATE 0xF
2073/** @} */
2074
2075/** @name AMD64 System Selector Types.
2076 * @{ */
2077#define AMD64_SEL_TYPE_SYS_LDT 2
2078/** 286 TSS selector - Busy. */
2079#define AMD64_SEL_TYPE_SYS_TSS_AVAIL 9
2080/** 386 TSS selector - Busy. */
2081#define AMD64_SEL_TYPE_SYS_TSS_BUSY 0xB
2082/** 386 Callgate selector. */
2083#define AMD64_SEL_TYPE_SYS_CALL_GATE 0xC
2084/** 386 Interruptgate selector. */
2085#define AMD64_SEL_TYPE_SYS_INT_GATE 0xE
2086/** 386 Trapgate selector. */
2087#define AMD64_SEL_TYPE_SYS_TRAP_GATE 0xF
2088/** @} */
2089
2090/** @} */
2091
2092
2093/** @name Descriptor Table Entry Flag Masks.
2094 * These are for the 2nd 32-bit word of a descriptor.
2095 * @{ */
2096/** Bits 8-11 - TYPE - Descriptor type mask. */
2097#define X86_DESC_TYPE_MASK (RT_BIT(8) | RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
2098/** Bit 12 - S - System (=0) or Code/Data (=1). */
2099#define X86_DESC_S RT_BIT(12)
2100/** Bits 13-14 - DPL - Descriptor Privilege Level. */
2101#define X86_DESC_DPL (RT_BIT(13) | RT_BIT(14))
2102/** Bit 15 - P - Present. */
2103#define X86_DESC_P RT_BIT(15)
2104/** Bit 20 - AVL - Available for system software. */
2105#define X86_DESC_AVL RT_BIT(20)
2106/** Bit 22 - DB - Default operation size. 0 = 16 bit, 1 = 32 bit. */
2107#define X86_DESC_DB RT_BIT(22)
2108/** Bit 23 - G - Granularity of the limit. If set 4KB granularity is
2109 * used, if clear byte. */
2110#define X86_DESC_G RT_BIT(23)
2111/** @} */
2112
2113/** @} */
2114
2115
2116/** @name Selectors.
2117 * @{
2118 */
2119
2120/**
2121 * The shift used to convert a selector from and to index an index (C).
2122 */
2123#define X86_SEL_SHIFT 3
2124
2125/**
2126 * The shift used to convert a selector from and to index an index (C).
2127 */
2128#define AMD64_SEL_SHIFT 4
2129
2130#if HC_ARCH_BITS == 64
2131#define X86_SEL_SHIFT_HC AMD64_SEL_SHIFT
2132#else
2133#define X86_SEL_SHIFT_HC X86_SEL_SHIFT
2134#endif
2135
2136/**
2137 * The mask used to mask off the table indicator and CPL of an selector.
2138 */
2139#define X86_SEL_MASK 0xfff8
2140
2141/**
2142 * The bit indicating that a selector is in the LDT and not in the GDT.
2143 */
2144#define X86_SEL_LDT 0x0004
2145/**
2146 * The bit mask for getting the RPL of a selector.
2147 */
2148#define X86_SEL_RPL 0x0003
2149
2150/** @} */
2151
2152
2153/**
2154 * x86 Exceptions/Faults/Traps.
2155 */
2156typedef enum X86XCPT
2157{
2158 /** \#DE - Divide error. */
2159 X86_XCPT_DE = 0x00,
2160 /** \#DB - Debug event (single step, DRx, ..) */
2161 X86_XCPT_DB = 0x01,
2162 /** NMI - Non-Maskable Interrupt */
2163 X86_XCPT_NMI = 0x02,
2164 /** \#BP - Breakpoint (INT3). */
2165 X86_XCPT_BP = 0x03,
2166 /** \#OF - Overflow (INTO). */
2167 X86_XCPT_OF = 0x04,
2168 /** \#BR - Bound range exceeded (BOUND). */
2169 X86_XCPT_BR = 0x05,
2170 /** \#UD - Undefined opcode. */
2171 X86_XCPT_UD = 0x06,
2172 /** \#NM - Device not available (math coprocessor device). */
2173 X86_XCPT_NM = 0x07,
2174 /** \#DF - Double fault. */
2175 X86_XCPT_DF = 0x08,
2176 /** ??? - Coprocessor segment overrun (obsolete). */
2177 X86_XCPT_CO_SEG_OVERRUN = 0x09,
2178 /** \#TS - Taskswitch (TSS). */
2179 X86_XCPT_TS = 0x0a,
2180 /** \#NP - Segment no present. */
2181 X86_XCPT_NP = 0x0b,
2182 /** \#SS - Stack segment fault. */
2183 X86_XCPT_SS = 0x0c,
2184 /** \#GP - General protection fault. */
2185 X86_XCPT_GP = 0x0d,
2186 /** \#PF - Page fault. */
2187 X86_XCPT_PF = 0x0e,
2188 /* 0x0f is reserved. */
2189 /** \#MF - Math fault (FPU). */
2190 X86_XCPT_MF = 0x10,
2191 /** \#AC - Alignment check. */
2192 X86_XCPT_AC = 0x11,
2193 /** \#MC - Machine check. */
2194 X86_XCPT_MC = 0x12,
2195 /** \#XF - SIMD Floating-Pointer Exception. */
2196 X86_XCPT_XF = 0x13
2197} X86XCPT;
2198/** Pointer to a x86 exception code. */
2199typedef X86XCPT *PX86XCPT;
2200/** Pointer to a const x86 exception code. */
2201typedef const X86XCPT *PCX86XCPT;
2202
2203
2204/** @name Trap Error Codes
2205 * @{
2206 */
2207/** External indicator. */
2208#define X86_TRAP_ERR_EXTERNAL 1
2209/** IDT indicator. */
2210#define X86_TRAP_ERR_IDT 2
2211/** Descriptor table indicator - If set LDT, if clear GDT. */
2212#define X86_TRAP_ERR_TI 4
2213/** Mask for getting the selector. */
2214#define X86_TRAP_ERR_SEL_MASK 0xfff8
2215/** Shift for getting the selector table index (C type index). */
2216#define X86_TRAP_ERR_SEL_SHIFT 3
2217/** @} */
2218
2219
2220/** @name \#PF Trap Error Codes
2221 * @{
2222 */
2223/** Bit 0 - P - Not present (clear) or page level protection (set) fault. */
2224#define X86_TRAP_PF_P RT_BIT(0)
2225/** Bit 1 - R/W - Read (clear) or write (set) access. */
2226#define X86_TRAP_PF_RW RT_BIT(1)
2227/** Bit 2 - U/S - CPU executing in user mode (set) or supervisor mode (clear). */
2228#define X86_TRAP_PF_US RT_BIT(2)
2229/** Bit 3 - RSVD- Reserved bit violation (set), i.e. reserved bit was set to 1. */
2230#define X86_TRAP_PF_RSVD RT_BIT(3)
2231/** Bit 4 - I/D - Instruction fetch (set) / Data access (clear) - PAE + NXE. */
2232#define X86_TRAP_PF_ID RT_BIT(4)
2233/** @} */
2234
2235#pragma pack(1)
2236/**
2237 * 32-bit IDTR/GDTR.
2238 */
2239typedef struct X86XDTR32
2240{
2241 /** Size of the descriptor table. */
2242 uint16_t cb;
2243 /** Address of the descriptor table. */
2244 uint32_t uAddr;
2245} X86XDTR32, *PX86XDTR32;
2246#pragma pack()
2247
2248#pragma pack(1)
2249/**
2250 * 64-bit IDTR/GDTR.
2251 */
2252typedef struct X86XDTR64
2253{
2254 /** Size of the descriptor table. */
2255 uint16_t cb;
2256 /** Address of the descriptor table. */
2257 uint64_t uAddr;
2258} X86XDTR64, *PX86XDTR64;
2259#pragma pack()
2260
2261/** @} */
2262
2263#endif
2264
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette