VirtualBox

source: vbox/trunk/include/iprt/x86.h@ 49907

Last change on this file since 49907 was 49893, checked in by vboxsync, 11 years ago

MSR rewrite: initial hacking - half disabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 124.2 KB
Line 
1/** @file
2 * IPRT - X86 and AMD64 Structures and Definitions.
3 *
4 * @note x86.mac is generated from this file by running 'kmk incs' in the root.
5 */
6
7/*
8 * Copyright (C) 2006-2012 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * The contents of this file may alternatively be used under the terms
19 * of the Common Development and Distribution License Version 1.0
20 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21 * VirtualBox OSE distribution, in which case the provisions of the
22 * CDDL are applicable instead of those of the GPL.
23 *
24 * You may elect to license modified versions of this file under the
25 * terms and conditions of either the GPL or the CDDL or both.
26 */
27
28#ifndef ___iprt_x86_h
29#define ___iprt_x86_h
30
31#ifndef VBOX_FOR_DTRACE_LIB
32# include <iprt/types.h>
33# include <iprt/assert.h>
34#else
35# pragma D depends_on library vbox-types.d
36#endif
37
38/* Workaround for Solaris sys/regset.h defining CS, DS */
39#ifdef RT_OS_SOLARIS
40# undef CS
41# undef DS
42#endif
43
44/** @defgroup grp_rt_x86 x86 Types and Definitions
45 * @ingroup grp_rt
46 * @{
47 */
48
49#ifndef VBOX_FOR_DTRACE_LIB
50/**
51 * EFLAGS Bits.
52 */
53typedef struct X86EFLAGSBITS
54{
55 /** Bit 0 - CF - Carry flag - Status flag. */
56 unsigned u1CF : 1;
57 /** Bit 1 - 1 - Reserved flag. */
58 unsigned u1Reserved0 : 1;
59 /** Bit 2 - PF - Parity flag - Status flag. */
60 unsigned u1PF : 1;
61 /** Bit 3 - 0 - Reserved flag. */
62 unsigned u1Reserved1 : 1;
63 /** Bit 4 - AF - Auxiliary carry flag - Status flag. */
64 unsigned u1AF : 1;
65 /** Bit 5 - 0 - Reserved flag. */
66 unsigned u1Reserved2 : 1;
67 /** Bit 6 - ZF - Zero flag - Status flag. */
68 unsigned u1ZF : 1;
69 /** Bit 7 - SF - Signed flag - Status flag. */
70 unsigned u1SF : 1;
71 /** Bit 8 - TF - Trap flag - System flag. */
72 unsigned u1TF : 1;
73 /** Bit 9 - IF - Interrupt flag - System flag. */
74 unsigned u1IF : 1;
75 /** Bit 10 - DF - Direction flag - Control flag. */
76 unsigned u1DF : 1;
77 /** Bit 11 - OF - Overflow flag - Status flag. */
78 unsigned u1OF : 1;
79 /** Bit 12-13 - IOPL - I/O prvilege level flag - System flag. */
80 unsigned u2IOPL : 2;
81 /** Bit 14 - NT - Nested task flag - System flag. */
82 unsigned u1NT : 1;
83 /** Bit 15 - 0 - Reserved flag. */
84 unsigned u1Reserved3 : 1;
85 /** Bit 16 - RF - Resume flag - System flag. */
86 unsigned u1RF : 1;
87 /** Bit 17 - VM - Virtual 8086 mode - System flag. */
88 unsigned u1VM : 1;
89 /** Bit 18 - AC - Alignment check flag - System flag. Works with CR0.AM. */
90 unsigned u1AC : 1;
91 /** Bit 19 - VIF - Virtual interrupt flag - System flag. */
92 unsigned u1VIF : 1;
93 /** Bit 20 - VIP - Virtual interrupt pending flag - System flag. */
94 unsigned u1VIP : 1;
95 /** Bit 21 - ID - CPUID flag - System flag. If this responds to flipping CPUID is supported. */
96 unsigned u1ID : 1;
97 /** Bit 22-31 - 0 - Reserved flag. */
98 unsigned u10Reserved4 : 10;
99} X86EFLAGSBITS;
100/** Pointer to EFLAGS bits. */
101typedef X86EFLAGSBITS *PX86EFLAGSBITS;
102/** Pointer to const EFLAGS bits. */
103typedef const X86EFLAGSBITS *PCX86EFLAGSBITS;
104#endif /* !VBOX_FOR_DTRACE_LIB */
105
106/**
107 * EFLAGS.
108 */
109typedef union X86EFLAGS
110{
111 /** The plain unsigned view. */
112 uint32_t u;
113#ifndef VBOX_FOR_DTRACE_LIB
114 /** The bitfield view. */
115 X86EFLAGSBITS Bits;
116#endif
117 /** The 8-bit view. */
118 uint8_t au8[4];
119 /** The 16-bit view. */
120 uint16_t au16[2];
121 /** The 32-bit view. */
122 uint32_t au32[1];
123 /** The 32-bit view. */
124 uint32_t u32;
125} X86EFLAGS;
126/** Pointer to EFLAGS. */
127typedef X86EFLAGS *PX86EFLAGS;
128/** Pointer to const EFLAGS. */
129typedef const X86EFLAGS *PCX86EFLAGS;
130
131/**
132 * RFLAGS (32 upper bits are reserved).
133 */
134typedef union X86RFLAGS
135{
136 /** The plain unsigned view. */
137 uint64_t u;
138#ifndef VBOX_FOR_DTRACE_LIB
139 /** The bitfield view. */
140 X86EFLAGSBITS Bits;
141#endif
142 /** The 8-bit view. */
143 uint8_t au8[8];
144 /** The 16-bit view. */
145 uint16_t au16[4];
146 /** The 32-bit view. */
147 uint32_t au32[2];
148 /** The 64-bit view. */
149 uint64_t au64[1];
150 /** The 64-bit view. */
151 uint64_t u64;
152} X86RFLAGS;
153/** Pointer to RFLAGS. */
154typedef X86RFLAGS *PX86RFLAGS;
155/** Pointer to const RFLAGS. */
156typedef const X86RFLAGS *PCX86RFLAGS;
157
158
159/** @name EFLAGS
160 * @{
161 */
162/** Bit 0 - CF - Carry flag - Status flag. */
163#define X86_EFL_CF RT_BIT(0)
164#define X86_EFL_CF_BIT 0
165/** Bit 1 - Reserved, reads as 1. */
166#define X86_EFL_1 RT_BIT(1)
167/** Bit 2 - PF - Parity flag - Status flag. */
168#define X86_EFL_PF RT_BIT(2)
169/** Bit 4 - AF - Auxiliary carry flag - Status flag. */
170#define X86_EFL_AF RT_BIT(4)
171#define X86_EFL_AF_BIT 4
172/** Bit 6 - ZF - Zero flag - Status flag. */
173#define X86_EFL_ZF RT_BIT(6)
174#define X86_EFL_ZF_BIT 6
175/** Bit 7 - SF - Signed flag - Status flag. */
176#define X86_EFL_SF RT_BIT(7)
177#define X86_EFL_SF_BIT 7
178/** Bit 8 - TF - Trap flag - System flag. */
179#define X86_EFL_TF RT_BIT(8)
180/** Bit 9 - IF - Interrupt flag - System flag. */
181#define X86_EFL_IF RT_BIT(9)
182/** Bit 10 - DF - Direction flag - Control flag. */
183#define X86_EFL_DF RT_BIT(10)
184/** Bit 11 - OF - Overflow flag - Status flag. */
185#define X86_EFL_OF RT_BIT(11)
186#define X86_EFL_OF_BIT 11
187/** Bit 12-13 - IOPL - I/O prvilege level flag - System flag. */
188#define X86_EFL_IOPL (RT_BIT(12) | RT_BIT(13))
189/** Bit 14 - NT - Nested task flag - System flag. */
190#define X86_EFL_NT RT_BIT(14)
191/** Bit 16 - RF - Resume flag - System flag. */
192#define X86_EFL_RF RT_BIT(16)
193/** Bit 17 - VM - Virtual 8086 mode - System flag. */
194#define X86_EFL_VM RT_BIT(17)
195/** Bit 18 - AC - Alignment check flag - System flag. Works with CR0.AM. */
196#define X86_EFL_AC RT_BIT(18)
197/** Bit 19 - VIF - Virtual interrupt flag - System flag. */
198#define X86_EFL_VIF RT_BIT(19)
199/** Bit 20 - VIP - Virtual interrupt pending flag - System flag. */
200#define X86_EFL_VIP RT_BIT(20)
201/** Bit 21 - ID - CPUID flag - System flag. If this responds to flipping CPUID is supported. */
202#define X86_EFL_ID RT_BIT(21)
203/** All live bits. */
204#define X86_EFL_LIVE_MASK UINT32_C(0x003f7fd5)
205/** Read as 1 bits. */
206#define X86_EFL_RA1_MASK RT_BIT_32(1)
207/** IOPL shift. */
208#define X86_EFL_IOPL_SHIFT 12
209/** The the IOPL level from the flags. */
210#define X86_EFL_GET_IOPL(efl) (((efl) >> X86_EFL_IOPL_SHIFT) & 3)
211/** Bits restored by popf */
212#define X86_EFL_POPF_BITS ( X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_TF | X86_EFL_IF \
213 | X86_EFL_DF | X86_EFL_OF | X86_EFL_IOPL | X86_EFL_NT | X86_EFL_AC | X86_EFL_ID )
214/** The status bits commonly updated by arithmetic instructions. */
215#define X86_EFL_STATUS_BITS ( X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF )
216/** @} */
217
218
219/** CPUID Feature information - ECX.
220 * CPUID query with EAX=1.
221 */
222#ifndef VBOX_FOR_DTRACE_LIB
223typedef struct X86CPUIDFEATECX
224{
225 /** Bit 0 - SSE3 - Supports SSE3 or not. */
226 unsigned u1SSE3 : 1;
227 /** Bit 1 - PCLMULQDQ. */
228 unsigned u1PCLMULQDQ : 1;
229 /** Bit 2 - DS Area 64-bit layout. */
230 unsigned u1DTE64 : 1;
231 /** Bit 3 - MONITOR - Supports MONITOR/MWAIT. */
232 unsigned u1Monitor : 1;
233 /** Bit 4 - CPL-DS - CPL Qualified Debug Store. */
234 unsigned u1CPLDS : 1;
235 /** Bit 5 - VMX - Virtual Machine Technology. */
236 unsigned u1VMX : 1;
237 /** Bit 6 - SMX: Safer Mode Extensions. */
238 unsigned u1SMX : 1;
239 /** Bit 7 - EST - Enh. SpeedStep Tech. */
240 unsigned u1EST : 1;
241 /** Bit 8 - TM2 - Terminal Monitor 2. */
242 unsigned u1TM2 : 1;
243 /** Bit 9 - SSSE3 - Supplemental Streaming SIMD Extensions 3. */
244 unsigned u1SSSE3 : 1;
245 /** Bit 10 - CNTX-ID - L1 Context ID. */
246 unsigned u1CNTXID : 1;
247 /** Bit 11 - Reserved. */
248 unsigned u1Reserved1 : 1;
249 /** Bit 12 - FMA. */
250 unsigned u1FMA : 1;
251 /** Bit 13 - CX16 - CMPXCHG16B. */
252 unsigned u1CX16 : 1;
253 /** Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
254 unsigned u1TPRUpdate : 1;
255 /** Bit 15 - PDCM - Perf/Debug Capability MSR. */
256 unsigned u1PDCM : 1;
257 /** Bit 16 - Reserved. */
258 unsigned u1Reserved2 : 1;
259 /** Bit 17 - PCID - Process-context identifiers. */
260 unsigned u1PCID : 1;
261 /** Bit 18 - Direct Cache Access. */
262 unsigned u1DCA : 1;
263 /** Bit 19 - SSE4_1 - Supports SSE4_1 or not. */
264 unsigned u1SSE4_1 : 1;
265 /** Bit 20 - SSE4_2 - Supports SSE4_2 or not. */
266 unsigned u1SSE4_2 : 1;
267 /** Bit 21 - x2APIC. */
268 unsigned u1x2APIC : 1;
269 /** Bit 22 - MOVBE - Supports MOVBE. */
270 unsigned u1MOVBE : 1;
271 /** Bit 23 - POPCNT - Supports POPCNT. */
272 unsigned u1POPCNT : 1;
273 /** Bit 24 - TSC-Deadline. */
274 unsigned u1TSCDEADLINE : 1;
275 /** Bit 25 - AES. */
276 unsigned u1AES : 1;
277 /** Bit 26 - XSAVE - Supports XSAVE. */
278 unsigned u1XSAVE : 1;
279 /** Bit 27 - OSXSAVE - Supports OSXSAVE. */
280 unsigned u1OSXSAVE : 1;
281 /** Bit 28 - AVX - Supports AVX instruction extensions. */
282 unsigned u1AVX : 1;
283 /** Bit 29 - 30 - Reserved */
284 unsigned u2Reserved3 : 2;
285 /** Bit 31 - Hypervisor present (we're a guest). */
286 unsigned u1HVP : 1;
287} X86CPUIDFEATECX;
288#else /* VBOX_FOR_DTRACE_LIB */
289typedef uint32_t X86CPUIDFEATECX;
290#endif /* VBOX_FOR_DTRACE_LIB */
291/** Pointer to CPUID Feature Information - ECX. */
292typedef X86CPUIDFEATECX *PX86CPUIDFEATECX;
293/** Pointer to const CPUID Feature Information - ECX. */
294typedef const X86CPUIDFEATECX *PCX86CPUIDFEATECX;
295
296
297/** CPUID Feature Information - EDX.
298 * CPUID query with EAX=1.
299 */
300#ifndef VBOX_FOR_DTRACE_LIB /* DTrace different (brain-dead from a C pov) bitfield implementation */
301typedef struct X86CPUIDFEATEDX
302{
303 /** Bit 0 - FPU - x87 FPU on Chip. */
304 unsigned u1FPU : 1;
305 /** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
306 unsigned u1VME : 1;
307 /** Bit 2 - DE - Debugging extensions. */
308 unsigned u1DE : 1;
309 /** Bit 3 - PSE - Page Size Extension. */
310 unsigned u1PSE : 1;
311 /** Bit 4 - TSC - Time Stamp Counter. */
312 unsigned u1TSC : 1;
313 /** Bit 5 - MSR - Model Specific Registers RDMSR and WRMSR Instructions. */
314 unsigned u1MSR : 1;
315 /** Bit 6 - PAE - Physical Address Extension. */
316 unsigned u1PAE : 1;
317 /** Bit 7 - MCE - Machine Check Exception. */
318 unsigned u1MCE : 1;
319 /** Bit 8 - CX8 - CMPXCHG8B instruction. */
320 unsigned u1CX8 : 1;
321 /** Bit 9 - APIC - APIC On-Chip. */
322 unsigned u1APIC : 1;
323 /** Bit 10 - Reserved. */
324 unsigned u1Reserved1 : 1;
325 /** Bit 11 - SEP - SYSENTER and SYSEXIT. */
326 unsigned u1SEP : 1;
327 /** Bit 12 - MTRR - Memory Type Range Registers. */
328 unsigned u1MTRR : 1;
329 /** Bit 13 - PGE - PTE Global Bit. */
330 unsigned u1PGE : 1;
331 /** Bit 14 - MCA - Machine Check Architecture. */
332 unsigned u1MCA : 1;
333 /** Bit 15 - CMOV - Conditional Move Instructions. */
334 unsigned u1CMOV : 1;
335 /** Bit 16 - PAT - Page Attribute Table. */
336 unsigned u1PAT : 1;
337 /** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
338 unsigned u1PSE36 : 1;
339 /** Bit 18 - PSN - Processor Serial Number. */
340 unsigned u1PSN : 1;
341 /** Bit 19 - CLFSH - CLFLUSH Instruction. */
342 unsigned u1CLFSH : 1;
343 /** Bit 20 - Reserved. */
344 unsigned u1Reserved2 : 1;
345 /** Bit 21 - DS - Debug Store. */
346 unsigned u1DS : 1;
347 /** Bit 22 - ACPI - Thermal Monitor and Software Controlled Clock Facilities. */
348 unsigned u1ACPI : 1;
349 /** Bit 23 - MMX - Intel MMX 'Technology'. */
350 unsigned u1MMX : 1;
351 /** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
352 unsigned u1FXSR : 1;
353 /** Bit 25 - SSE - SSE Support. */
354 unsigned u1SSE : 1;
355 /** Bit 26 - SSE2 - SSE2 Support. */
356 unsigned u1SSE2 : 1;
357 /** Bit 27 - SS - Self Snoop. */
358 unsigned u1SS : 1;
359 /** Bit 28 - HTT - Hyper-Threading Technology. */
360 unsigned u1HTT : 1;
361 /** Bit 29 - TM - Thermal Monitor. */
362 unsigned u1TM : 1;
363 /** Bit 30 - Reserved - . */
364 unsigned u1Reserved3 : 1;
365 /** Bit 31 - PBE - Pending Break Enabled. */
366 unsigned u1PBE : 1;
367} X86CPUIDFEATEDX;
368#else /* VBOX_FOR_DTRACE_LIB */
369typedef uint32_t X86CPUIDFEATEDX;
370#endif /* VBOX_FOR_DTRACE_LIB */
371/** Pointer to CPUID Feature Information - EDX. */
372typedef X86CPUIDFEATEDX *PX86CPUIDFEATEDX;
373/** Pointer to const CPUID Feature Information - EDX. */
374typedef const X86CPUIDFEATEDX *PCX86CPUIDFEATEDX;
375
376/** @name CPUID Vendor information.
377 * CPUID query with EAX=0.
378 * @{
379 */
380#define X86_CPUID_VENDOR_INTEL_EBX 0x756e6547 /* Genu */
381#define X86_CPUID_VENDOR_INTEL_ECX 0x6c65746e /* ntel */
382#define X86_CPUID_VENDOR_INTEL_EDX 0x49656e69 /* ineI */
383
384#define X86_CPUID_VENDOR_AMD_EBX 0x68747541 /* Auth */
385#define X86_CPUID_VENDOR_AMD_ECX 0x444d4163 /* cAMD */
386#define X86_CPUID_VENDOR_AMD_EDX 0x69746e65 /* enti */
387
388#define X86_CPUID_VENDOR_VIA_EBX 0x746e6543 /* Cent */
389#define X86_CPUID_VENDOR_VIA_ECX 0x736c7561 /* auls */
390#define X86_CPUID_VENDOR_VIA_EDX 0x48727561 /* aurH */
391/** @} */
392
393
394/** @name CPUID Feature information.
395 * CPUID query with EAX=1.
396 * @{
397 */
398/** ECX Bit 0 - SSE3 - Supports SSE3 or not. */
399#define X86_CPUID_FEATURE_ECX_SSE3 RT_BIT(0)
400/** ECX Bit 1 - PCLMUL - PCLMULQDQ support (for AES-GCM). */
401#define X86_CPUID_FEATURE_ECX_PCLMUL RT_BIT(1)
402/** ECX Bit 2 - DTES64 - DS Area 64-bit Layout. */
403#define X86_CPUID_FEATURE_ECX_DTES64 RT_BIT(2)
404/** ECX Bit 3 - MONITOR - Supports MONITOR/MWAIT. */
405#define X86_CPUID_FEATURE_ECX_MONITOR RT_BIT(3)
406/** ECX Bit 4 - CPL-DS - CPL Qualified Debug Store. */
407#define X86_CPUID_FEATURE_ECX_CPLDS RT_BIT(4)
408/** ECX Bit 5 - VMX - Virtual Machine Technology. */
409#define X86_CPUID_FEATURE_ECX_VMX RT_BIT(5)
410/** ECX Bit 6 - SMX - Safer Mode Extensions. */
411#define X86_CPUID_FEATURE_ECX_SMX RT_BIT(6)
412/** ECX Bit 7 - EST - Enh. SpeedStep Tech. */
413#define X86_CPUID_FEATURE_ECX_EST RT_BIT(7)
414/** ECX Bit 8 - TM2 - Terminal Monitor 2. */
415#define X86_CPUID_FEATURE_ECX_TM2 RT_BIT(8)
416/** ECX Bit 9 - SSSE3 - Supplemental Streaming SIMD Extensions 3. */
417#define X86_CPUID_FEATURE_ECX_SSSE3 RT_BIT(9)
418/** ECX Bit 10 - CNTX-ID - L1 Context ID. */
419#define X86_CPUID_FEATURE_ECX_CNTXID RT_BIT(10)
420/** ECX Bit 12 - FMA. */
421#define X86_CPUID_FEATURE_ECX_FMA RT_BIT(12)
422/** ECX Bit 13 - CX16 - CMPXCHG16B. */
423#define X86_CPUID_FEATURE_ECX_CX16 RT_BIT(13)
424/** ECX Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
425#define X86_CPUID_FEATURE_ECX_TPRUPDATE RT_BIT(14)
426/** ECX Bit 15 - PDCM - Perf/Debug Capability MSR. */
427#define X86_CPUID_FEATURE_ECX_PDCM RT_BIT(15)
428/** ECX Bit 17 - PCID - Process-context identifiers. */
429#define X86_CPUID_FEATURE_ECX_PCID RT_BIT(17)
430/** ECX Bit 18 - DCA - Direct Cache Access. */
431#define X86_CPUID_FEATURE_ECX_DCA RT_BIT(18)
432/** ECX Bit 19 - SSE4_1 - Supports SSE4_1 or not. */
433#define X86_CPUID_FEATURE_ECX_SSE4_1 RT_BIT(19)
434/** ECX Bit 20 - SSE4_2 - Supports SSE4_2 or not. */
435#define X86_CPUID_FEATURE_ECX_SSE4_2 RT_BIT(20)
436/** ECX Bit 21 - x2APIC support. */
437#define X86_CPUID_FEATURE_ECX_X2APIC RT_BIT(21)
438/** ECX Bit 22 - MOVBE instruction. */
439#define X86_CPUID_FEATURE_ECX_MOVBE RT_BIT(22)
440/** ECX Bit 23 - POPCNT instruction. */
441#define X86_CPUID_FEATURE_ECX_POPCNT RT_BIT(23)
442/** ECX Bir 24 - TSC-Deadline. */
443#define X86_CPUID_FEATURE_ECX_TSCDEADL RT_BIT(24)
444/** ECX Bit 25 - AES instructions. */
445#define X86_CPUID_FEATURE_ECX_AES RT_BIT(25)
446/** ECX Bit 26 - XSAVE instruction. */
447#define X86_CPUID_FEATURE_ECX_XSAVE RT_BIT(26)
448/** ECX Bit 27 - OSXSAVE instruction. */
449#define X86_CPUID_FEATURE_ECX_OSXSAVE RT_BIT(27)
450/** ECX Bit 28 - AVX. */
451#define X86_CPUID_FEATURE_ECX_AVX RT_BIT(28)
452/** ECX Bit 29 - F16C - Half-precision convert instruction support. */
453#define X86_CPUID_FEATURE_ECX_F16C RT_BIT(29)
454/** ECX Bit 31 - Hypervisor Present (software only). */
455#define X86_CPUID_FEATURE_ECX_HVP RT_BIT(31)
456
457
458/** Bit 0 - FPU - x87 FPU on Chip. */
459#define X86_CPUID_FEATURE_EDX_FPU RT_BIT(0)
460/** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
461#define X86_CPUID_FEATURE_EDX_VME RT_BIT(1)
462/** Bit 2 - DE - Debugging extensions. */
463#define X86_CPUID_FEATURE_EDX_DE RT_BIT(2)
464/** Bit 3 - PSE - Page Size Extension. */
465#define X86_CPUID_FEATURE_EDX_PSE RT_BIT(3)
466/** Bit 4 - TSC - Time Stamp Counter. */
467#define X86_CPUID_FEATURE_EDX_TSC RT_BIT(4)
468/** Bit 5 - MSR - Model Specific Registers RDMSR and WRMSR Instructions. */
469#define X86_CPUID_FEATURE_EDX_MSR RT_BIT(5)
470/** Bit 6 - PAE - Physical Address Extension. */
471#define X86_CPUID_FEATURE_EDX_PAE RT_BIT(6)
472/** Bit 7 - MCE - Machine Check Exception. */
473#define X86_CPUID_FEATURE_EDX_MCE RT_BIT(7)
474/** Bit 8 - CX8 - CMPXCHG8B instruction. */
475#define X86_CPUID_FEATURE_EDX_CX8 RT_BIT(8)
476/** Bit 9 - APIC - APIC On-Chip. */
477#define X86_CPUID_FEATURE_EDX_APIC RT_BIT(9)
478/** Bit 11 - SEP - SYSENTER and SYSEXIT Present. */
479#define X86_CPUID_FEATURE_EDX_SEP RT_BIT(11)
480/** Bit 12 - MTRR - Memory Type Range Registers. */
481#define X86_CPUID_FEATURE_EDX_MTRR RT_BIT(12)
482/** Bit 13 - PGE - PTE Global Bit. */
483#define X86_CPUID_FEATURE_EDX_PGE RT_BIT(13)
484/** Bit 14 - MCA - Machine Check Architecture. */
485#define X86_CPUID_FEATURE_EDX_MCA RT_BIT(14)
486/** Bit 15 - CMOV - Conditional Move Instructions. */
487#define X86_CPUID_FEATURE_EDX_CMOV RT_BIT(15)
488/** Bit 16 - PAT - Page Attribute Table. */
489#define X86_CPUID_FEATURE_EDX_PAT RT_BIT(16)
490/** Bit 17 - PSE-36 - 36-bit Page Size Extension. */
491#define X86_CPUID_FEATURE_EDX_PSE36 RT_BIT(17)
492/** Bit 18 - PSN - Processor Serial Number. */
493#define X86_CPUID_FEATURE_EDX_PSN RT_BIT(18)
494/** Bit 19 - CLFSH - CLFLUSH Instruction. */
495#define X86_CPUID_FEATURE_EDX_CLFSH RT_BIT(19)
496/** Bit 21 - DS - Debug Store. */
497#define X86_CPUID_FEATURE_EDX_DS RT_BIT(21)
498/** Bit 22 - ACPI - Termal Monitor and Software Controlled Clock Facilities. */
499#define X86_CPUID_FEATURE_EDX_ACPI RT_BIT(22)
500/** Bit 23 - MMX - Intel MMX Technology. */
501#define X86_CPUID_FEATURE_EDX_MMX RT_BIT(23)
502/** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
503#define X86_CPUID_FEATURE_EDX_FXSR RT_BIT(24)
504/** Bit 25 - SSE - SSE Support. */
505#define X86_CPUID_FEATURE_EDX_SSE RT_BIT(25)
506/** Bit 26 - SSE2 - SSE2 Support. */
507#define X86_CPUID_FEATURE_EDX_SSE2 RT_BIT(26)
508/** Bit 27 - SS - Self Snoop. */
509#define X86_CPUID_FEATURE_EDX_SS RT_BIT(27)
510/** Bit 28 - HTT - Hyper-Threading Technology. */
511#define X86_CPUID_FEATURE_EDX_HTT RT_BIT(28)
512/** Bit 29 - TM - Therm. Monitor. */
513#define X86_CPUID_FEATURE_EDX_TM RT_BIT(29)
514/** Bit 31 - PBE - Pending Break Enabled. */
515#define X86_CPUID_FEATURE_EDX_PBE RT_BIT(31)
516/** @} */
517
518/** @name CPUID mwait/monitor information.
519 * CPUID query with EAX=5.
520 * @{
521 */
522/** ECX Bit 0 - MWAITEXT - Supports mwait/monitor extensions or not. */
523#define X86_CPUID_MWAIT_ECX_EXT RT_BIT(0)
524/** ECX Bit 1 - MWAITBREAK - Break mwait for external interrupt even if EFLAGS.IF=0. */
525#define X86_CPUID_MWAIT_ECX_BREAKIRQIF0 RT_BIT(1)
526/** @} */
527
528
529/** @name CPUID Extended Feature information.
530 * CPUID query with EAX=0x80000001.
531 * @{
532 */
533/** ECX Bit 0 - LAHF/SAHF support in 64-bit mode. */
534#define X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF RT_BIT(0)
535
536/** EDX Bit 11 - SYSCALL/SYSRET. */
537#define X86_CPUID_EXT_FEATURE_EDX_SYSCALL RT_BIT(11)
538/** EDX Bit 20 - No-Execute/Execute-Disable. */
539#define X86_CPUID_EXT_FEATURE_EDX_NX RT_BIT(20)
540/** EDX Bit 26 - 1 GB large page. */
541#define X86_CPUID_EXT_FEATURE_EDX_PAGE1GB RT_BIT(26)
542/** EDX Bit 27 - RDTSCP. */
543#define X86_CPUID_EXT_FEATURE_EDX_RDTSCP RT_BIT(27)
544/** EDX Bit 29 - AMD Long Mode/Intel-64 Instructions. */
545#define X86_CPUID_EXT_FEATURE_EDX_LONG_MODE RT_BIT(29)
546/** @}*/
547
548/** @name CPUID AMD Feature information.
549 * CPUID query with EAX=0x80000001.
550 * @{
551 */
552/** Bit 0 - FPU - x87 FPU on Chip. */
553#define X86_CPUID_AMD_FEATURE_EDX_FPU RT_BIT(0)
554/** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
555#define X86_CPUID_AMD_FEATURE_EDX_VME RT_BIT(1)
556/** Bit 2 - DE - Debugging extensions. */
557#define X86_CPUID_AMD_FEATURE_EDX_DE RT_BIT(2)
558/** Bit 3 - PSE - Page Size Extension. */
559#define X86_CPUID_AMD_FEATURE_EDX_PSE RT_BIT(3)
560/** Bit 4 - TSC - Time Stamp Counter. */
561#define X86_CPUID_AMD_FEATURE_EDX_TSC RT_BIT(4)
562/** Bit 5 - MSR - K86 Model Specific Registers RDMSR and WRMSR Instructions. */
563#define X86_CPUID_AMD_FEATURE_EDX_MSR RT_BIT(5)
564/** Bit 6 - PAE - Physical Address Extension. */
565#define X86_CPUID_AMD_FEATURE_EDX_PAE RT_BIT(6)
566/** Bit 7 - MCE - Machine Check Exception. */
567#define X86_CPUID_AMD_FEATURE_EDX_MCE RT_BIT(7)
568/** Bit 8 - CX8 - CMPXCHG8B instruction. */
569#define X86_CPUID_AMD_FEATURE_EDX_CX8 RT_BIT(8)
570/** Bit 9 - APIC - APIC On-Chip. */
571#define X86_CPUID_AMD_FEATURE_EDX_APIC RT_BIT(9)
572/** Bit 12 - MTRR - Memory Type Range Registers. */
573#define X86_CPUID_AMD_FEATURE_EDX_MTRR RT_BIT(12)
574/** Bit 13 - PGE - PTE Global Bit. */
575#define X86_CPUID_AMD_FEATURE_EDX_PGE RT_BIT(13)
576/** Bit 14 - MCA - Machine Check Architecture. */
577#define X86_CPUID_AMD_FEATURE_EDX_MCA RT_BIT(14)
578/** Bit 15 - CMOV - Conditional Move Instructions. */
579#define X86_CPUID_AMD_FEATURE_EDX_CMOV RT_BIT(15)
580/** Bit 16 - PAT - Page Attribute Table. */
581#define X86_CPUID_AMD_FEATURE_EDX_PAT RT_BIT(16)
582/** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
583#define X86_CPUID_AMD_FEATURE_EDX_PSE36 RT_BIT(17)
584/** Bit 22 - AXMMX - AMD Extensions to MMX Instructions. */
585#define X86_CPUID_AMD_FEATURE_EDX_AXMMX RT_BIT(22)
586/** Bit 23 - MMX - Intel MMX Technology. */
587#define X86_CPUID_AMD_FEATURE_EDX_MMX RT_BIT(23)
588/** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
589#define X86_CPUID_AMD_FEATURE_EDX_FXSR RT_BIT(24)
590/** Bit 25 - FFXSR - AMD fast FXSAVE and FXRSTOR Instructions. */
591#define X86_CPUID_AMD_FEATURE_EDX_FFXSR RT_BIT(25)
592/** Bit 30 - 3DNOWEXT - AMD Extensions to 3DNow. */
593#define X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX RT_BIT(30)
594/** Bit 31 - 3DNOW - AMD 3DNow. */
595#define X86_CPUID_AMD_FEATURE_EDX_3DNOW RT_BIT(31)
596
597/** Bit 1 - CMPL - Core multi-processing legacy mode. */
598#define X86_CPUID_AMD_FEATURE_ECX_CMPL RT_BIT(1)
599/** Bit 2 - SVM - AMD VM extensions. */
600#define X86_CPUID_AMD_FEATURE_ECX_SVM RT_BIT(2)
601/** Bit 3 - EXTAPIC - AMD extended APIC registers starting at 0x400. */
602#define X86_CPUID_AMD_FEATURE_ECX_EXT_APIC RT_BIT(3)
603/** Bit 4 - CR8L - AMD LOCK MOV CR0 means MOV CR8. */
604#define X86_CPUID_AMD_FEATURE_ECX_CR8L RT_BIT(4)
605/** Bit 5 - ABM - AMD Advanced bit manipulation. LZCNT instruction support. */
606#define X86_CPUID_AMD_FEATURE_ECX_ABM RT_BIT(5)
607/** Bit 6 - SSE4A - AMD EXTRQ, INSERTQ, MOVNTSS, and MOVNTSD instruction support. */
608#define X86_CPUID_AMD_FEATURE_ECX_SSE4A RT_BIT(6)
609/** Bit 7 - MISALIGNSSE - AMD Misaligned SSE mode. */
610#define X86_CPUID_AMD_FEATURE_ECX_MISALNSSE RT_BIT(7)
611/** Bit 8 - 3DNOWPRF - AMD PREFETCH and PREFETCHW instruction support. */
612#define X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF RT_BIT(8)
613/** Bit 9 - OSVW - AMD OS visible workaround. */
614#define X86_CPUID_AMD_FEATURE_ECX_OSVW RT_BIT(9)
615/** Bit 10 - IBS - Instruct based sampling. */
616#define X86_CPUID_AMD_FEATURE_ECX_IBS RT_BIT(10)
617/** Bit 11 - SSE5 - SSE5 instruction support. */
618#define X86_CPUID_AMD_FEATURE_ECX_SSE5 RT_BIT(11)
619/** Bit 12 - SKINIT - AMD SKINIT: SKINIT, STGI, and DEV support. */
620#define X86_CPUID_AMD_FEATURE_ECX_SKINIT RT_BIT(12)
621/** Bit 13 - WDT - AMD Watchdog timer support. */
622#define X86_CPUID_AMD_FEATURE_ECX_WDT RT_BIT(13)
623
624/** @} */
625
626
627/** @name CPUID AMD Feature information.
628 * CPUID query with EAX=0x80000007.
629 * @{
630 */
631/** Bit 0 - TS - Temperature Sensor. */
632#define X86_CPUID_AMD_ADVPOWER_EDX_TS RT_BIT(0)
633/** Bit 1 - FID - Frequency ID Control. */
634#define X86_CPUID_AMD_ADVPOWER_EDX_FID RT_BIT(1)
635/** Bit 2 - VID - Voltage ID Control. */
636#define X86_CPUID_AMD_ADVPOWER_EDX_VID RT_BIT(2)
637/** Bit 3 - TTP - THERMTRIP. */
638#define X86_CPUID_AMD_ADVPOWER_EDX_TTP RT_BIT(3)
639/** Bit 4 - TM - Hardware Thermal Control. */
640#define X86_CPUID_AMD_ADVPOWER_EDX_TM RT_BIT(4)
641/** Bit 5 - STC - Software Thermal Control. */
642#define X86_CPUID_AMD_ADVPOWER_EDX_STC RT_BIT(5)
643/** Bit 6 - MC - 100 Mhz Multiplier Control. */
644#define X86_CPUID_AMD_ADVPOWER_EDX_MC RT_BIT(6)
645/** Bit 7 - HWPSTATE - Hardware P-State Control. */
646#define X86_CPUID_AMD_ADVPOWER_EDX_HWPSTATE RT_BIT(7)
647/** Bit 8 - TSCINVAR - TSC Invariant. */
648#define X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR RT_BIT(8)
649/** @} */
650
651
652/** @name CR0
653 * @{ */
654/** Bit 0 - PE - Protection Enabled */
655#define X86_CR0_PE RT_BIT(0)
656#define X86_CR0_PROTECTION_ENABLE RT_BIT(0)
657/** Bit 1 - MP - Monitor Coprocessor */
658#define X86_CR0_MP RT_BIT(1)
659#define X86_CR0_MONITOR_COPROCESSOR RT_BIT(1)
660/** Bit 2 - EM - Emulation. */
661#define X86_CR0_EM RT_BIT(2)
662#define X86_CR0_EMULATE_FPU RT_BIT(2)
663/** Bit 3 - TS - Task Switch. */
664#define X86_CR0_TS RT_BIT(3)
665#define X86_CR0_TASK_SWITCH RT_BIT(3)
666/** Bit 4 - ET - Extension flag. ('hardcoded' to 1) */
667#define X86_CR0_ET RT_BIT(4)
668#define X86_CR0_EXTENSION_TYPE RT_BIT(4)
669/** Bit 5 - NE - Numeric error. */
670#define X86_CR0_NE RT_BIT(5)
671#define X86_CR0_NUMERIC_ERROR RT_BIT(5)
672/** Bit 16 - WP - Write Protect. */
673#define X86_CR0_WP RT_BIT(16)
674#define X86_CR0_WRITE_PROTECT RT_BIT(16)
675/** Bit 18 - AM - Alignment Mask. */
676#define X86_CR0_AM RT_BIT(18)
677#define X86_CR0_ALIGMENT_MASK RT_BIT(18)
678/** Bit 29 - NW - Not Write-though. */
679#define X86_CR0_NW RT_BIT(29)
680#define X86_CR0_NOT_WRITE_THROUGH RT_BIT(29)
681/** Bit 30 - WP - Cache Disable. */
682#define X86_CR0_CD RT_BIT(30)
683#define X86_CR0_CACHE_DISABLE RT_BIT(30)
684/** Bit 31 - PG - Paging. */
685#define X86_CR0_PG RT_BIT(31)
686#define X86_CR0_PAGING RT_BIT(31)
687/** @} */
688
689
690/** @name CR3
691 * @{ */
692/** Bit 3 - PWT - Page-level Writes Transparent. */
693#define X86_CR3_PWT RT_BIT(3)
694/** Bit 4 - PCD - Page-level Cache Disable. */
695#define X86_CR3_PCD RT_BIT(4)
696/** Bits 12-31 - - Page directory page number. */
697#define X86_CR3_PAGE_MASK (0xfffff000)
698/** Bits 5-31 - - PAE Page directory page number. */
699#define X86_CR3_PAE_PAGE_MASK (0xffffffe0)
700/** Bits 12-51 - - AMD64 Page directory page number. */
701#define X86_CR3_AMD64_PAGE_MASK UINT64_C(0x000ffffffffff000)
702/** @} */
703
704
705/** @name CR4
706 * @{ */
707/** Bit 0 - VME - Virtual-8086 Mode Extensions. */
708#define X86_CR4_VME RT_BIT(0)
709/** Bit 1 - PVI - Protected-Mode Virtual Interrupts. */
710#define X86_CR4_PVI RT_BIT(1)
711/** Bit 2 - TSD - Time Stamp Disable. */
712#define X86_CR4_TSD RT_BIT(2)
713/** Bit 3 - DE - Debugging Extensions. */
714#define X86_CR4_DE RT_BIT(3)
715/** Bit 4 - PSE - Page Size Extension. */
716#define X86_CR4_PSE RT_BIT(4)
717/** Bit 5 - PAE - Physical Address Extension. */
718#define X86_CR4_PAE RT_BIT(5)
719/** Bit 6 - MCE - Machine-Check Enable. */
720#define X86_CR4_MCE RT_BIT(6)
721/** Bit 7 - PGE - Page Global Enable. */
722#define X86_CR4_PGE RT_BIT(7)
723/** Bit 8 - PCE - Performance-Monitoring Counter Enable. */
724#define X86_CR4_PCE RT_BIT(8)
725/** Bit 9 - OSFSXR - Operating System Support for FXSAVE and FXRSTORE instruction. */
726#define X86_CR4_OSFSXR RT_BIT(9)
727/** Bit 10 - OSXMMEEXCPT - Operating System Support for Unmasked SIMD Floating-Point Exceptions. */
728#define X86_CR4_OSXMMEEXCPT RT_BIT(10)
729/** Bit 13 - VMXE - VMX mode is enabled. */
730#define X86_CR4_VMXE RT_BIT(13)
731/** Bit 14 - SMXE - Safer Mode Extensions Enabled. */
732#define X86_CR4_SMXE RT_BIT(14)
733/** Bit 17 - PCIDE - Process-Context Identifiers Enabled. */
734#define X86_CR4_PCIDE RT_BIT(17)
735/** Bit 18 - OSXSAVE - Operating System Support for XSAVE and processor
736 * extended states. */
737#define X86_CR4_OSXSAVE RT_BIT(18)
738/** Bit 20 - SMEP - Supervisor-mode Execution Prevention enabled. */
739#define X86_CR4_SMEP RT_BIT(20)
740/** @} */
741
742
743/** @name DR6
744 * @{ */
745/** Bit 0 - B0 - Breakpoint 0 condition detected. */
746#define X86_DR6_B0 RT_BIT(0)
747/** Bit 1 - B1 - Breakpoint 1 condition detected. */
748#define X86_DR6_B1 RT_BIT(1)
749/** Bit 2 - B2 - Breakpoint 2 condition detected. */
750#define X86_DR6_B2 RT_BIT(2)
751/** Bit 3 - B3 - Breakpoint 3 condition detected. */
752#define X86_DR6_B3 RT_BIT(3)
753/** Mask of all the Bx bits. */
754#define X86_DR6_B_MASK UINT64_C(0x0000000f)
755/** Bit 13 - BD - Debug register access detected. Corresponds to the X86_DR7_GD bit. */
756#define X86_DR6_BD RT_BIT(13)
757/** Bit 14 - BS - Single step */
758#define X86_DR6_BS RT_BIT(14)
759/** Bit 15 - BT - Task switch. (TSS T bit.) */
760#define X86_DR6_BT RT_BIT(15)
761/** Value of DR6 after powerup/reset. */
762#define X86_DR6_INIT_VAL UINT64_C(0xFFFF0FF0)
763/** Bits which must be 1s in DR6. */
764#define X86_DR6_RA1_MASK UINT64_C(0xffff0ff0)
765/** Bits which must be 0s in DR6. */
766#define X86_DR6_RAZ_MASK RT_BIT_64(12)
767/** Bits which must be 0s on writes to DR6. */
768#define X86_DR6_MBZ_MASK UINT64_C(0xffffffff00000000)
769/** @} */
770
771/** Get the DR6.Bx bit for a the given breakpoint. */
772#define X86_DR6_B(iBp) RT_BIT_64(iBp)
773
774
775/** @name DR7
776 * @{ */
777/** Bit 0 - L0 - Local breakpoint enable. Cleared on task switch. */
778#define X86_DR7_L0 RT_BIT(0)
779/** Bit 1 - G0 - Global breakpoint enable. Not cleared on task switch. */
780#define X86_DR7_G0 RT_BIT(1)
781/** Bit 2 - L1 - Local breakpoint enable. Cleared on task switch. */
782#define X86_DR7_L1 RT_BIT(2)
783/** Bit 3 - G1 - Global breakpoint enable. Not cleared on task switch. */
784#define X86_DR7_G1 RT_BIT(3)
785/** Bit 4 - L2 - Local breakpoint enable. Cleared on task switch. */
786#define X86_DR7_L2 RT_BIT(4)
787/** Bit 5 - G2 - Global breakpoint enable. Not cleared on task switch. */
788#define X86_DR7_G2 RT_BIT(5)
789/** Bit 6 - L3 - Local breakpoint enable. Cleared on task switch. */
790#define X86_DR7_L3 RT_BIT(6)
791/** Bit 7 - G3 - Global breakpoint enable. Not cleared on task switch. */
792#define X86_DR7_G3 RT_BIT(7)
793/** Bit 8 - LE - Local breakpoint exact. (Not supported (read ignored) by P6 and later.) */
794#define X86_DR7_LE RT_BIT(8)
795/** Bit 9 - GE - Local breakpoint exact. (Not supported (read ignored) by P6 and later.) */
796#define X86_DR7_GE RT_BIT(9)
797
798/** L0, L1, L2, and L3. */
799#define X86_DR7_LE_ALL UINT64_C(0x0000000000000055)
800/** L0, L1, L2, and L3. */
801#define X86_DR7_GE_ALL UINT64_C(0x00000000000000aa)
802
803/** Bit 13 - GD - General detect enable. Enables emulators to get exceptions when
804 * any DR register is accessed. */
805#define X86_DR7_GD RT_BIT(13)
806/** Bit 16 & 17 - R/W0 - Read write field 0. Values X86_DR7_RW_*. */
807#define X86_DR7_RW0_MASK (3 << 16)
808/** Bit 18 & 19 - LEN0 - Length field 0. Values X86_DR7_LEN_*. */
809#define X86_DR7_LEN0_MASK (3 << 18)
810/** Bit 20 & 21 - R/W1 - Read write field 0. Values X86_DR7_RW_*. */
811#define X86_DR7_RW1_MASK (3 << 20)
812/** Bit 22 & 23 - LEN1 - Length field 0. Values X86_DR7_LEN_*. */
813#define X86_DR7_LEN1_MASK (3 << 22)
814/** Bit 24 & 25 - R/W2 - Read write field 0. Values X86_DR7_RW_*. */
815#define X86_DR7_RW2_MASK (3 << 24)
816/** Bit 26 & 27 - LEN2 - Length field 0. Values X86_DR7_LEN_*. */
817#define X86_DR7_LEN2_MASK (3 << 26)
818/** Bit 28 & 29 - R/W3 - Read write field 0. Values X86_DR7_RW_*. */
819#define X86_DR7_RW3_MASK (3 << 28)
820/** Bit 30 & 31 - LEN3 - Length field 0. Values X86_DR7_LEN_*. */
821#define X86_DR7_LEN3_MASK (3 << 30)
822
823/** Bits which reads as 1s. */
824#define X86_DR7_RA1_MASK (RT_BIT(10))
825/** Bits which reads as zeros. */
826#define X86_DR7_RAZ_MASK UINT64_C(0x0000d800)
827/** Bits which must be 0s when writing to DR7. */
828#define X86_DR7_MBZ_MASK UINT64_C(0xffffffff00000000)
829
830/** Calcs the L bit of Nth breakpoint.
831 * @param iBp The breakpoint number [0..3].
832 */
833#define X86_DR7_L(iBp) ( UINT32_C(1) << (iBp * 2) )
834
835/** Calcs the G bit of Nth breakpoint.
836 * @param iBp The breakpoint number [0..3].
837 */
838#define X86_DR7_G(iBp) ( UINT32_C(1) << (iBp * 2 + 1) )
839
840/** Calcs the L and G bits of Nth breakpoint.
841 * @param iBp The breakpoint number [0..3].
842 */
843#define X86_DR7_L_G(iBp) ( UINT32_C(3) << (iBp * 2) )
844
845/** @name Read/Write values.
846 * @{ */
847/** Break on instruction fetch only. */
848#define X86_DR7_RW_EO 0U
849/** Break on write only. */
850#define X86_DR7_RW_WO 1U
851/** Break on I/O read/write. This is only defined if CR4.DE is set. */
852#define X86_DR7_RW_IO 2U
853/** Break on read or write (but not instruction fetches). */
854#define X86_DR7_RW_RW 3U
855/** @} */
856
857/** Shifts a X86_DR7_RW_* value to its right place.
858 * @param iBp The breakpoint number [0..3].
859 * @param fRw One of the X86_DR7_RW_* value.
860 */
861#define X86_DR7_RW(iBp, fRw) ( (fRw) << ((iBp) * 4 + 16) )
862
863/** Fetch the the R/Wx bits for a given breakpoint (so it can be compared with
864 * one of the X86_DR7_RW_XXX constants).
865 *
866 * @returns X86_DR7_RW_XXX
867 * @param uDR7 DR7 value
868 * @param iBp The breakpoint number [0..3].
869 */
870#define X86_DR7_GET_RW(uDR7, iBp) ( ( (uDR7) >> ((iBp) * 4 + 16) ) & UINT32_C(3) )
871
872/** R/W0, R/W1, R/W2, and R/W3. */
873#define X86_DR7_RW_ALL_MASKS UINT32_C(0x33330000)
874
875/** Checks if there are any I/O breakpoint types configured in the RW
876 * registers. Does NOT check if these are enabled, sorry. */
877#define X86_DR7_ANY_RW_IO(uDR7) \
878 ( ( UINT32_C(0x22220000) & (uDR7) ) /* any candidates? */ \
879 && ( ( (UINT32_C(0x22220000) & (uDR7) ) >> 1 ) & ~(uDR7) ) )
880AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x33330000)) == 0);
881AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x22220000)) == 1);
882AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x32320000)) == 1);
883AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x23230000)) == 1);
884AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x00000000)) == 0);
885AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x00010000)) == 0);
886AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x00020000)) == 1);
887AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x00030000)) == 0);
888AssertCompile(X86_DR7_ANY_RW_IO(UINT32_C(0x00040000)) == 0);
889
890/** @name Length values.
891 * @{ */
892#define X86_DR7_LEN_BYTE 0U
893#define X86_DR7_LEN_WORD 1U
894#define X86_DR7_LEN_QWORD 2U /**< AMD64 long mode only. */
895#define X86_DR7_LEN_DWORD 3U
896/** @} */
897
898/** Shifts a X86_DR7_LEN_* value to its right place.
899 * @param iBp The breakpoint number [0..3].
900 * @param cb One of the X86_DR7_LEN_* values.
901 */
902#define X86_DR7_LEN(iBp, cb) ( (cb) << ((iBp) * 4 + 18) )
903
904/** Fetch the breakpoint length bits from the DR7 value.
905 * @param uDR7 DR7 value
906 * @param iBp The breakpoint number [0..3].
907 */
908#define X86_DR7_GET_LEN(uDR7, iBp) ( ( (uDR7) >> ((iBp) * 4 + 18) ) & UINT32_C(0x3) )
909
910/** Mask used to check if any breakpoints are enabled. */
911#define X86_DR7_ENABLED_MASK UINT32_C(0x000000ff)
912
913/** LEN0, LEN1, LEN2, and LEN3. */
914#define X86_DR7_LEN_ALL_MASKS UINT32_C(0xcccc0000)
915/** R/W0, R/W1, R/W2, R/W3,LEN0, LEN1, LEN2, and LEN3. */
916#define X86_DR7_RW_LEN_ALL_MASKS UINT32_C(0xffff0000)
917
918/** Value of DR7 after powerup/reset. */
919#define X86_DR7_INIT_VAL 0x400
920/** @} */
921
922
923/** @name Machine Specific Registers
924 * @{
925 */
926/** Machine check address register (P5). */
927#define MSR_P5_MC_ADDR UINT32_C(0x00000000)
928/** Machine check type register (P5). */
929#define MSR_P5_MC_TYPE UINT32_C(0x00000001)
930/** Time Stamp Counter. */
931#define MSR_IA32_TSC 0x10
932#define MSR_IA32_CESR UINT32_C(0x00000011)
933#define MSR_IA32_CTR0 UINT32_C(0x00000012)
934#define MSR_IA32_CTR1 UINT32_C(0x00000013)
935
936#define MSR_IA32_PLATFORM_ID 0x17
937
938#ifndef MSR_IA32_APICBASE /* qemu cpu.h kludge */
939# define MSR_IA32_APICBASE 0x1b
940/** Local APIC enabled. */
941# define MSR_IA32_APICBASE_EN RT_BIT_64(11)
942/** X2APIC enabled (requires the EN bit to be set). */
943# define MSR_IA32_APICBASE_EXTD RT_BIT_64(10)
944/** The processor is the boot strap processor (BSP). */
945# define MSR_IA32_APICBASE_BSP RT_BIT_64(8)
946/** Minimum base address mask, consult CPUID leaf 0x80000008 for the actual
947 * width. */
948# define MSR_IA32_APICBASE_BASE_MIN UINT64_C(0x0000000ffffff000)
949#endif
950
951/** Undocumented intel MSR for reporting thread and core counts.
952 * Judging from the XNU sources, it seems to be introduced in Nehalem. The
953 * first 16 bits is the thread count. The next 16 bits the core count, except
954 * on Westmere where it seems it's only the next 4 bits for some reason. */
955#define MSR_CORE_THREAD_COUNT 0x35
956
957/** CPU Feature control. */
958#define MSR_IA32_FEATURE_CONTROL 0x3A
959#define MSR_IA32_FEATURE_CONTROL_LOCK RT_BIT(0)
960#define MSR_IA32_FEATURE_CONTROL_SMX_VMXON RT_BIT(1)
961#define MSR_IA32_FEATURE_CONTROL_VMXON RT_BIT(2)
962
963/** BIOS update trigger (microcode update). */
964#define MSR_IA32_BIOS_UPDT_TRIG 0x79
965
966/** BIOS update signature (microcode). */
967#define MSR_IA32_BIOS_SIGN_ID 0x8B
968
969/** General performance counter no. 0. */
970#define MSR_IA32_PMC0 0xC1
971/** General performance counter no. 1. */
972#define MSR_IA32_PMC1 0xC2
973/** General performance counter no. 2. */
974#define MSR_IA32_PMC2 0xC3
975/** General performance counter no. 3. */
976#define MSR_IA32_PMC3 0xC4
977
978/** Nehalem power control. */
979#define MSR_IA32_PLATFORM_INFO 0xCE
980
981/** Get FSB clock status (Intel-specific). */
982#define MSR_IA32_FSB_CLOCK_STS 0xCD
983
984/** C-State configuration control. Intel specific: Nehalem, Sandy Bridge. */
985#define MSR_PKG_CST_CONFIG_CONTROL UINT32_C(0x000000e2)
986
987/** C0 Maximum Frequency Clock Count */
988#define MSR_IA32_MPERF 0xE7
989/** C0 Actual Frequency Clock Count */
990#define MSR_IA32_APERF 0xE8
991
992/** MTRR Capabilities. */
993#define MSR_IA32_MTRR_CAP 0xFE
994
995/** Cache control/info. */
996#define MSR_BBL_CR_CTL3 UINT32_C(0x11e)
997
998#ifndef MSR_IA32_SYSENTER_CS /* qemu cpu.h kludge */
999/** SYSENTER_CS - the R0 CS, indirectly giving R0 SS, R3 CS and R3 DS.
1000 * R0 SS == CS + 8
1001 * R3 CS == CS + 16
1002 * R3 SS == CS + 24
1003 */
1004#define MSR_IA32_SYSENTER_CS 0x174
1005/** SYSENTER_ESP - the R0 ESP. */
1006#define MSR_IA32_SYSENTER_ESP 0x175
1007/** SYSENTER_EIP - the R0 EIP. */
1008#define MSR_IA32_SYSENTER_EIP 0x176
1009#endif
1010
1011/** Machine Check Global Capabilities Register. */
1012#define MSR_IA32_MCG_CAP 0x179
1013/** Machine Check Global Status Register. */
1014#define MSR_IA32_MCG_STATUS 0x17A
1015/** Machine Check Global Control Register. */
1016#define MSR_IA32_MCG_CTRL 0x17B
1017
1018/** Page Attribute Table. */
1019#define MSR_IA32_CR_PAT 0x277
1020
1021/** Performance counter MSRs. (Intel only) */
1022#define MSR_IA32_PERFEVTSEL0 0x186
1023#define MSR_IA32_PERFEVTSEL1 0x187
1024/** Flexible ratio, seems to be undocumented, used by XNU (tsc.c).
1025 * The 16th bit whether flex ratio is being used, in which case bits 15:8
1026 * holds a ratio that Apple takes for TSC granularity.
1027 *
1028 * @note This MSR conflics the P4 MSR_MCG_R12 register. */
1029#define MSR_FLEX_RATIO 0x194
1030/** Performance state value and starting with Intel core more.
1031 * Apple uses the >=core features to determine TSC granularity on older CPUs. */
1032#define MSR_IA32_PERF_STATUS 0x198
1033#define MSR_IA32_PERF_CTL 0x199
1034#define MSR_IA32_THERM_STATUS 0x19c
1035
1036/** Enable misc. processor features (R/W). */
1037#define MSR_IA32_MISC_ENABLE 0x1A0
1038/** Enable fast-strings feature (for REP MOVS and REP STORS). */
1039#define MSR_IA32_MISC_ENABLE_FAST_STRINGS RT_BIT_64(0)
1040/** Automatic Thermal Control Circuit Enable (R/W). */
1041#define MSR_IA32_MISC_ENABLE_TCC RT_BIT_64(3)
1042/** Performance Monitoring Available (R). */
1043#define MSR_IA32_MISC_ENABLE_PERF_MON RT_BIT_64(7)
1044/** Branch Trace Storage Unavailable (R/O). */
1045#define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL RT_BIT_64(11)
1046/** Precise Event Based Sampling (PEBS) Unavailable (R/O). */
1047#define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL RT_BIT_64(12)
1048/** Enhanced Intel SpeedStep Technology Enable (R/W). */
1049#define MSR_IA32_MISC_ENABLE_SST_ENABLE RT_BIT_64(16)
1050/** If MONITOR/MWAIT is supported (R/W). */
1051#define MSR_IA32_MISC_ENABLE_MONITOR RT_BIT_64(18)
1052/** Limit CPUID Maxval to 3 leafs (R/W). */
1053#define MSR_IA32_MISC_ENABLE_LIMIT_CPUID RT_BIT_64(22)
1054/** When set to 1, xTPR messages are disabled (R/W). */
1055#define MSR_IA32_MISC_ENABLE_XTPR_MSG_DISABLE RT_BIT_64(23)
1056/** When set to 1, the Execute Disable Bit feature (XD Bit) is disabled (R/W). */
1057#define MSR_IA32_MISC_ENABLE_XD_DISABLE RT_BIT_64(34)
1058
1059/** Trace/Profile Resource Control (R/W) */
1060#define MSR_IA32_DEBUGCTL UINT32_C(0x000001d9)
1061/** The number (0..3 or 0..15) of the last branch record register on P4 and
1062 * related Xeons. */
1063#define MSR_P4_LASTBRANCH_TOS UINT32_C(0x000001da)
1064/** @name Last branch registers for P4 and Xeon, models 0 thru 2.
1065 * @{ */
1066#define MSR_P4_LASTBRANCH_0 UINT32_C(0x000001db)
1067#define MSR_P4_LASTBRANCH_1 UINT32_C(0x000001dc)
1068#define MSR_P4_LASTBRANCH_2 UINT32_C(0x000001dd)
1069#define MSR_P4_LASTBRANCH_3 UINT32_C(0x000001de)
1070/** @} */
1071
1072
1073#define IA32_MTRR_PHYSBASE0 0x200
1074#define IA32_MTRR_PHYSMASK0 0x201
1075#define IA32_MTRR_PHYSBASE1 0x202
1076#define IA32_MTRR_PHYSMASK1 0x203
1077#define IA32_MTRR_PHYSBASE2 0x204
1078#define IA32_MTRR_PHYSMASK2 0x205
1079#define IA32_MTRR_PHYSBASE3 0x206
1080#define IA32_MTRR_PHYSMASK3 0x207
1081#define IA32_MTRR_PHYSBASE4 0x208
1082#define IA32_MTRR_PHYSMASK4 0x209
1083#define IA32_MTRR_PHYSBASE5 0x20a
1084#define IA32_MTRR_PHYSMASK5 0x20b
1085#define IA32_MTRR_PHYSBASE6 0x20c
1086#define IA32_MTRR_PHYSMASK6 0x20d
1087#define IA32_MTRR_PHYSBASE7 0x20e
1088#define IA32_MTRR_PHYSMASK7 0x20f
1089#define IA32_MTRR_PHYSBASE8 0x210
1090#define IA32_MTRR_PHYSMASK8 0x211
1091#define IA32_MTRR_PHYSBASE9 0x212
1092#define IA32_MTRR_PHYSMASK9 0x213
1093
1094/** Fixed range MTRRs.
1095 * @{ */
1096#define IA32_MTRR_FIX64K_00000 0x250
1097#define IA32_MTRR_FIX16K_80000 0x258
1098#define IA32_MTRR_FIX16K_A0000 0x259
1099#define IA32_MTRR_FIX4K_C0000 0x268
1100#define IA32_MTRR_FIX4K_C8000 0x269
1101#define IA32_MTRR_FIX4K_D0000 0x26a
1102#define IA32_MTRR_FIX4K_D8000 0x26b
1103#define IA32_MTRR_FIX4K_E0000 0x26c
1104#define IA32_MTRR_FIX4K_E8000 0x26d
1105#define IA32_MTRR_FIX4K_F0000 0x26e
1106#define IA32_MTRR_FIX4K_F8000 0x26f
1107/** @} */
1108
1109/** MTRR Default Range. */
1110#define MSR_IA32_MTRR_DEF_TYPE 0x2FF
1111
1112#define MSR_IA32_MC0_CTL 0x400
1113#define MSR_IA32_MC0_STATUS 0x401
1114
1115/** Basic VMX information. */
1116#define MSR_IA32_VMX_BASIC_INFO 0x480
1117/** Allowed settings for pin-based VM execution controls */
1118#define MSR_IA32_VMX_PINBASED_CTLS 0x481
1119/** Allowed settings for proc-based VM execution controls */
1120#define MSR_IA32_VMX_PROCBASED_CTLS 0x482
1121/** Allowed settings for the VMX exit controls. */
1122#define MSR_IA32_VMX_EXIT_CTLS 0x483
1123/** Allowed settings for the VMX entry controls. */
1124#define MSR_IA32_VMX_ENTRY_CTLS 0x484
1125/** Misc VMX info. */
1126#define MSR_IA32_VMX_MISC 0x485
1127/** Fixed cleared bits in CR0. */
1128#define MSR_IA32_VMX_CR0_FIXED0 0x486
1129/** Fixed set bits in CR0. */
1130#define MSR_IA32_VMX_CR0_FIXED1 0x487
1131/** Fixed cleared bits in CR4. */
1132#define MSR_IA32_VMX_CR4_FIXED0 0x488
1133/** Fixed set bits in CR4. */
1134#define MSR_IA32_VMX_CR4_FIXED1 0x489
1135/** Information for enumerating fields in the VMCS. */
1136#define MSR_IA32_VMX_VMCS_ENUM 0x48A
1137/** Allowed settings for the VM-functions controls. */
1138#define MSR_IA32_VMX_VMFUNC 0x491
1139/** Allowed settings for secondary proc-based VM execution controls */
1140#define MSR_IA32_VMX_PROCBASED_CTLS2 0x48B
1141/** EPT capabilities. */
1142#define MSR_IA32_VMX_EPT_VPID_CAP 0x48C
1143/** DS Save Area (R/W). */
1144#define MSR_IA32_DS_AREA 0x600
1145/** Running Average Power Limit (RAPL) power units. */
1146#define MSR_RAPL_POWER_UNIT 0x606
1147/** X2APIC MSR ranges. */
1148#define MSR_IA32_X2APIC_START 0x800
1149#define MSR_IA32_X2APIC_TPR 0x808
1150#define MSR_IA32_X2APIC_END 0xBFF
1151
1152/** K6 EFER - Extended Feature Enable Register. */
1153#define MSR_K6_EFER UINT32_C(0xc0000080)
1154/** @todo document EFER */
1155/** Bit 0 - SCE - System call extensions (SYSCALL / SYSRET). (R/W) */
1156#define MSR_K6_EFER_SCE RT_BIT(0)
1157/** Bit 8 - LME - Long mode enabled. (R/W) */
1158#define MSR_K6_EFER_LME RT_BIT(8)
1159/** Bit 10 - LMA - Long mode active. (R) */
1160#define MSR_K6_EFER_LMA RT_BIT(10)
1161/** Bit 11 - NXE - No-Execute Page Protection Enabled. (R/W) */
1162#define MSR_K6_EFER_NXE RT_BIT(11)
1163/** Bit 12 - SVME - Secure VM Extension Enabled. (R/W) */
1164#define MSR_K6_EFER_SVME RT_BIT(12)
1165/** Bit 13 - LMSLE - Long Mode Segment Limit Enable. (R/W?) */
1166#define MSR_K6_EFER_LMSLE RT_BIT(13)
1167/** Bit 14 - FFXSR - Fast FXSAVE / FXRSTOR (skip XMM*). (R/W) */
1168#define MSR_K6_EFER_FFXSR RT_BIT(14)
1169/** K6 STAR - SYSCALL/RET targets. */
1170#define MSR_K6_STAR UINT32_C(0xc0000081)
1171/** Shift value for getting the SYSRET CS and SS value. */
1172#define MSR_K6_STAR_SYSRET_CS_SS_SHIFT 48
1173/** Shift value for getting the SYSCALL CS and SS value. */
1174#define MSR_K6_STAR_SYSCALL_CS_SS_SHIFT 32
1175/** Selector mask for use after shifting. */
1176#define MSR_K6_STAR_SEL_MASK UINT32_C(0xffff)
1177/** The mask which give the SYSCALL EIP. */
1178#define MSR_K6_STAR_SYSCALL_EIP_MASK UINT32_C(0xffffffff)
1179/** K6 WHCR - Write Handling Control Register. */
1180#define MSR_K6_WHCR UINT32_C(0xc0000082)
1181/** K6 UWCCR - UC/WC Cacheability Control Register. */
1182#define MSR_K6_UWCCR UINT32_C(0xc0000085)
1183/** K6 PSOR - Processor State Observability Register. */
1184#define MSR_K6_PSOR UINT32_C(0xc0000087)
1185/** K6 PFIR - Page Flush/Invalidate Register. */
1186#define MSR_K6_PFIR UINT32_C(0xc0000088)
1187
1188/** Performance counter MSRs. (AMD only) */
1189#define MSR_K7_EVNTSEL0 UINT32_C(0xc0010000)
1190#define MSR_K7_EVNTSEL1 UINT32_C(0xc0010001)
1191#define MSR_K7_EVNTSEL2 UINT32_C(0xc0010002)
1192#define MSR_K7_EVNTSEL3 UINT32_C(0xc0010003)
1193#define MSR_K7_PERFCTR0 UINT32_C(0xc0010004)
1194#define MSR_K7_PERFCTR1 UINT32_C(0xc0010005)
1195#define MSR_K7_PERFCTR2 UINT32_C(0xc0010006)
1196#define MSR_K7_PERFCTR3 UINT32_C(0xc0010007)
1197
1198/** K8 LSTAR - Long mode SYSCALL target (RIP). */
1199#define MSR_K8_LSTAR UINT32_C(0xc0000082)
1200/** K8 CSTAR - Compatibility mode SYSCALL target (RIP). */
1201#define MSR_K8_CSTAR UINT32_C(0xc0000083)
1202/** K8 SF_MASK - SYSCALL flag mask. (aka SFMASK) */
1203#define MSR_K8_SF_MASK UINT32_C(0xc0000084)
1204/** K8 FS.base - The 64-bit base FS register. */
1205#define MSR_K8_FS_BASE UINT32_C(0xc0000100)
1206/** K8 GS.base - The 64-bit base GS register. */
1207#define MSR_K8_GS_BASE UINT32_C(0xc0000101)
1208/** K8 KernelGSbase - Used with SWAPGS. */
1209#define MSR_K8_KERNEL_GS_BASE UINT32_C(0xc0000102)
1210/** K8 TSC_AUX - Used with RDTSCP. */
1211#define MSR_K8_TSC_AUX UINT32_C(0xc0000103)
1212#define MSR_K8_SYSCFG UINT32_C(0xc0010010)
1213#define MSR_K8_HWCR UINT32_C(0xc0010015)
1214#define MSR_K8_IORRBASE0 UINT32_C(0xc0010016)
1215#define MSR_K8_IORRMASK0 UINT32_C(0xc0010017)
1216#define MSR_K8_IORRBASE1 UINT32_C(0xc0010018)
1217#define MSR_K8_IORRMASK1 UINT32_C(0xc0010019)
1218#define MSR_K8_TOP_MEM1 UINT32_C(0xc001001a)
1219#define MSR_K8_TOP_MEM2 UINT32_C(0xc001001d)
1220/** North bridge config? See BIOS & Kernel dev guides for
1221 * details. */
1222#define MSR_K8_NB_CFG UINT32_C(0xc001001f)
1223
1224/** Hypertransport interrupt pending register.
1225 * "BIOS and Kernel Developer's Guide for AMD NPT Family 0Fh Processors" */
1226#define MSR_K8_INT_PENDING UINT32_C(0xc0010055)
1227#define MSR_K8_VM_CR UINT32_C(0xc0010114)
1228#define MSR_K8_VM_CR_SVM_DISABLE RT_BIT(4)
1229
1230#define MSR_K8_IGNNE UINT32_C(0xc0010115)
1231#define MSR_K8_SMM_CTL UINT32_C(0xc0010116)
1232/** SVM - VM_HSAVE_PA - Physical address for saving and restoring
1233 * host state during world switch. */
1234#define MSR_K8_VM_HSAVE_PA UINT32_C(0xc0010117)
1235
1236/** @} */
1237
1238
1239/** @name Page Table / Directory / Directory Pointers / L4.
1240 * @{
1241 */
1242
1243/** Page table/directory entry as an unsigned integer. */
1244typedef uint32_t X86PGUINT;
1245/** Pointer to a page table/directory table entry as an unsigned integer. */
1246typedef X86PGUINT *PX86PGUINT;
1247/** Pointer to an const page table/directory table entry as an unsigned integer. */
1248typedef X86PGUINT const *PCX86PGUINT;
1249
1250/** Number of entries in a 32-bit PT/PD. */
1251#define X86_PG_ENTRIES 1024
1252
1253
1254/** PAE page table/page directory/pdpt/l4/l5 entry as an unsigned integer. */
1255typedef uint64_t X86PGPAEUINT;
1256/** Pointer to a PAE page table/page directory/pdpt/l4/l5 entry as an unsigned integer. */
1257typedef X86PGPAEUINT *PX86PGPAEUINT;
1258/** Pointer to an const PAE page table/page directory/pdpt/l4/l5 entry as an unsigned integer. */
1259typedef X86PGPAEUINT const *PCX86PGPAEUINT;
1260
1261/** Number of entries in a PAE PT/PD. */
1262#define X86_PG_PAE_ENTRIES 512
1263/** Number of entries in a PAE PDPT. */
1264#define X86_PG_PAE_PDPE_ENTRIES 4
1265
1266/** Number of entries in an AMD64 PT/PD/PDPT/L4/L5. */
1267#define X86_PG_AMD64_ENTRIES X86_PG_PAE_ENTRIES
1268/** Number of entries in an AMD64 PDPT.
1269 * Just for complementing X86_PG_PAE_PDPE_ENTRIES, using X86_PG_AMD64_ENTRIES for this is fine too. */
1270#define X86_PG_AMD64_PDPE_ENTRIES X86_PG_AMD64_ENTRIES
1271
1272/** The size of a 4KB page. */
1273#define X86_PAGE_4K_SIZE _4K
1274/** The page shift of a 4KB page. */
1275#define X86_PAGE_4K_SHIFT 12
1276/** The 4KB page offset mask. */
1277#define X86_PAGE_4K_OFFSET_MASK 0xfff
1278/** The 4KB page base mask for virtual addresses. */
1279#define X86_PAGE_4K_BASE_MASK 0xfffffffffffff000ULL
1280/** The 4KB page base mask for virtual addresses - 32bit version. */
1281#define X86_PAGE_4K_BASE_MASK_32 0xfffff000U
1282
1283/** The size of a 2MB page. */
1284#define X86_PAGE_2M_SIZE _2M
1285/** The page shift of a 2MB page. */
1286#define X86_PAGE_2M_SHIFT 21
1287/** The 2MB page offset mask. */
1288#define X86_PAGE_2M_OFFSET_MASK 0x001fffff
1289/** The 2MB page base mask for virtual addresses. */
1290#define X86_PAGE_2M_BASE_MASK 0xffffffffffe00000ULL
1291/** The 2MB page base mask for virtual addresses - 32bit version. */
1292#define X86_PAGE_2M_BASE_MASK_32 0xffe00000U
1293
1294/** The size of a 4MB page. */
1295#define X86_PAGE_4M_SIZE _4M
1296/** The page shift of a 4MB page. */
1297#define X86_PAGE_4M_SHIFT 22
1298/** The 4MB page offset mask. */
1299#define X86_PAGE_4M_OFFSET_MASK 0x003fffff
1300/** The 4MB page base mask for virtual addresses. */
1301#define X86_PAGE_4M_BASE_MASK 0xffffffffffc00000ULL
1302/** The 4MB page base mask for virtual addresses - 32bit version. */
1303#define X86_PAGE_4M_BASE_MASK_32 0xffc00000U
1304
1305/**
1306 * Check if the given address is canonical.
1307 */
1308#define X86_IS_CANONICAL(a_u64Addr) ((uint64_t)(a_u64Addr) + UINT64_C(0x800000000000) < UINT64_C(0x1000000000000))
1309
1310
1311/** @name Page Table Entry
1312 * @{
1313 */
1314/** Bit 0 - P - Present bit. */
1315#define X86_PTE_BIT_P 0
1316/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
1317#define X86_PTE_BIT_RW 1
1318/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
1319#define X86_PTE_BIT_US 2
1320/** Bit 3 - PWT - Page level write thru bit. */
1321#define X86_PTE_BIT_PWT 3
1322/** Bit 4 - PCD - Page level cache disable bit. */
1323#define X86_PTE_BIT_PCD 4
1324/** Bit 5 - A - Access bit. */
1325#define X86_PTE_BIT_A 5
1326/** Bit 6 - D - Dirty bit. */
1327#define X86_PTE_BIT_D 6
1328/** Bit 7 - PAT - Page Attribute Table index bit. Reserved and 0 if not supported. */
1329#define X86_PTE_BIT_PAT 7
1330/** Bit 8 - G - Global flag. */
1331#define X86_PTE_BIT_G 8
1332
1333/** Bit 0 - P - Present bit mask. */
1334#define X86_PTE_P RT_BIT(0)
1335/** Bit 1 - R/W - Read (clear) / Write (set) bit mask. */
1336#define X86_PTE_RW RT_BIT(1)
1337/** Bit 2 - U/S - User (set) / Supervisor (clear) bit mask. */
1338#define X86_PTE_US RT_BIT(2)
1339/** Bit 3 - PWT - Page level write thru bit mask. */
1340#define X86_PTE_PWT RT_BIT(3)
1341/** Bit 4 - PCD - Page level cache disable bit mask. */
1342#define X86_PTE_PCD RT_BIT(4)
1343/** Bit 5 - A - Access bit mask. */
1344#define X86_PTE_A RT_BIT(5)
1345/** Bit 6 - D - Dirty bit mask. */
1346#define X86_PTE_D RT_BIT(6)
1347/** Bit 7 - PAT - Page Attribute Table index bit mask. Reserved and 0 if not supported. */
1348#define X86_PTE_PAT RT_BIT(7)
1349/** Bit 8 - G - Global bit mask. */
1350#define X86_PTE_G RT_BIT(8)
1351
1352/** Bits 9-11 - - Available for use to system software. */
1353#define X86_PTE_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1354/** Bits 12-31 - - Physical Page number of the next level. */
1355#define X86_PTE_PG_MASK ( 0xfffff000 )
1356
1357/** Bits 12-51 - - PAE - Physical Page number of the next level. */
1358#define X86_PTE_PAE_PG_MASK UINT64_C(0x000ffffffffff000)
1359/** Bits 63 - NX - PAE/LM - No execution flag. */
1360#define X86_PTE_PAE_NX RT_BIT_64(63)
1361/** Bits 62-52 - - PAE - MBZ bits when NX is active. */
1362#define X86_PTE_PAE_MBZ_MASK_NX UINT64_C(0x7ff0000000000000)
1363/** Bits 63-52 - - PAE - MBZ bits when no NX. */
1364#define X86_PTE_PAE_MBZ_MASK_NO_NX UINT64_C(0xfff0000000000000)
1365/** No bits - - LM - MBZ bits when NX is active. */
1366#define X86_PTE_LM_MBZ_MASK_NX UINT64_C(0x0000000000000000)
1367/** Bits 63 - - LM - MBZ bits when no NX. */
1368#define X86_PTE_LM_MBZ_MASK_NO_NX UINT64_C(0x8000000000000000)
1369
1370/**
1371 * Page table entry.
1372 */
1373typedef struct X86PTEBITS
1374{
1375 /** Flags whether(=1) or not the page is present. */
1376 unsigned u1Present : 1;
1377 /** Read(=0) / Write(=1) flag. */
1378 unsigned u1Write : 1;
1379 /** User(=1) / Supervisor (=0) flag. */
1380 unsigned u1User : 1;
1381 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1382 unsigned u1WriteThru : 1;
1383 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1384 unsigned u1CacheDisable : 1;
1385 /** Accessed flag.
1386 * Indicates that the page have been read or written to. */
1387 unsigned u1Accessed : 1;
1388 /** Dirty flag.
1389 * Indicates that the page has been written to. */
1390 unsigned u1Dirty : 1;
1391 /** Reserved / If PAT enabled, bit 2 of the index. */
1392 unsigned u1PAT : 1;
1393 /** Global flag. (Ignored in all but final level.) */
1394 unsigned u1Global : 1;
1395 /** Available for use to system software. */
1396 unsigned u3Available : 3;
1397 /** Physical Page number of the next level. */
1398 unsigned u20PageNo : 20;
1399} X86PTEBITS;
1400/** Pointer to a page table entry. */
1401typedef X86PTEBITS *PX86PTEBITS;
1402/** Pointer to a const page table entry. */
1403typedef const X86PTEBITS *PCX86PTEBITS;
1404
1405/**
1406 * Page table entry.
1407 */
1408typedef union X86PTE
1409{
1410 /** Unsigned integer view */
1411 X86PGUINT u;
1412 /** Bit field view. */
1413 X86PTEBITS n;
1414 /** 32-bit view. */
1415 uint32_t au32[1];
1416 /** 16-bit view. */
1417 uint16_t au16[2];
1418 /** 8-bit view. */
1419 uint8_t au8[4];
1420} X86PTE;
1421/** Pointer to a page table entry. */
1422typedef X86PTE *PX86PTE;
1423/** Pointer to a const page table entry. */
1424typedef const X86PTE *PCX86PTE;
1425
1426
1427/**
1428 * PAE page table entry.
1429 */
1430typedef struct X86PTEPAEBITS
1431{
1432 /** Flags whether(=1) or not the page is present. */
1433 uint32_t u1Present : 1;
1434 /** Read(=0) / Write(=1) flag. */
1435 uint32_t u1Write : 1;
1436 /** User(=1) / Supervisor(=0) flag. */
1437 uint32_t u1User : 1;
1438 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1439 uint32_t u1WriteThru : 1;
1440 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1441 uint32_t u1CacheDisable : 1;
1442 /** Accessed flag.
1443 * Indicates that the page have been read or written to. */
1444 uint32_t u1Accessed : 1;
1445 /** Dirty flag.
1446 * Indicates that the page has been written to. */
1447 uint32_t u1Dirty : 1;
1448 /** Reserved / If PAT enabled, bit 2 of the index. */
1449 uint32_t u1PAT : 1;
1450 /** Global flag. (Ignored in all but final level.) */
1451 uint32_t u1Global : 1;
1452 /** Available for use to system software. */
1453 uint32_t u3Available : 3;
1454 /** Physical Page number of the next level - Low Part. Don't use this. */
1455 uint32_t u20PageNoLow : 20;
1456 /** Physical Page number of the next level - High Part. Don't use this. */
1457 uint32_t u20PageNoHigh : 20;
1458 /** MBZ bits */
1459 uint32_t u11Reserved : 11;
1460 /** No Execute flag. */
1461 uint32_t u1NoExecute : 1;
1462} X86PTEPAEBITS;
1463/** Pointer to a page table entry. */
1464typedef X86PTEPAEBITS *PX86PTEPAEBITS;
1465/** Pointer to a page table entry. */
1466typedef const X86PTEPAEBITS *PCX86PTEPAEBITS;
1467
1468/**
1469 * PAE Page table entry.
1470 */
1471typedef union X86PTEPAE
1472{
1473 /** Unsigned integer view */
1474 X86PGPAEUINT u;
1475 /** Bit field view. */
1476 X86PTEPAEBITS n;
1477 /** 32-bit view. */
1478 uint32_t au32[2];
1479 /** 16-bit view. */
1480 uint16_t au16[4];
1481 /** 8-bit view. */
1482 uint8_t au8[8];
1483} X86PTEPAE;
1484/** Pointer to a PAE page table entry. */
1485typedef X86PTEPAE *PX86PTEPAE;
1486/** Pointer to a const PAE page table entry. */
1487typedef const X86PTEPAE *PCX86PTEPAE;
1488/** @} */
1489
1490/**
1491 * Page table.
1492 */
1493typedef struct X86PT
1494{
1495 /** PTE Array. */
1496 X86PTE a[X86_PG_ENTRIES];
1497} X86PT;
1498/** Pointer to a page table. */
1499typedef X86PT *PX86PT;
1500/** Pointer to a const page table. */
1501typedef const X86PT *PCX86PT;
1502
1503/** The page shift to get the PT index. */
1504#define X86_PT_SHIFT 12
1505/** The PT index mask (apply to a shifted page address). */
1506#define X86_PT_MASK 0x3ff
1507
1508
1509/**
1510 * Page directory.
1511 */
1512typedef struct X86PTPAE
1513{
1514 /** PTE Array. */
1515 X86PTEPAE a[X86_PG_PAE_ENTRIES];
1516} X86PTPAE;
1517/** Pointer to a page table. */
1518typedef X86PTPAE *PX86PTPAE;
1519/** Pointer to a const page table. */
1520typedef const X86PTPAE *PCX86PTPAE;
1521
1522/** The page shift to get the PA PTE index. */
1523#define X86_PT_PAE_SHIFT 12
1524/** The PAE PT index mask (apply to a shifted page address). */
1525#define X86_PT_PAE_MASK 0x1ff
1526
1527
1528/** @name 4KB Page Directory Entry
1529 * @{
1530 */
1531/** Bit 0 - P - Present bit. */
1532#define X86_PDE_P RT_BIT(0)
1533/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
1534#define X86_PDE_RW RT_BIT(1)
1535/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
1536#define X86_PDE_US RT_BIT(2)
1537/** Bit 3 - PWT - Page level write thru bit. */
1538#define X86_PDE_PWT RT_BIT(3)
1539/** Bit 4 - PCD - Page level cache disable bit. */
1540#define X86_PDE_PCD RT_BIT(4)
1541/** Bit 5 - A - Access bit. */
1542#define X86_PDE_A RT_BIT(5)
1543/** Bit 7 - PS - Page size attribute.
1544 * Clear mean 4KB pages, set means large pages (2/4MB). */
1545#define X86_PDE_PS RT_BIT(7)
1546/** Bits 9-11 - - Available for use to system software. */
1547#define X86_PDE_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1548/** Bits 12-31 - - Physical Page number of the next level. */
1549#define X86_PDE_PG_MASK ( 0xfffff000 )
1550
1551/** Bits 12-51 - - PAE - Physical Page number of the next level. */
1552#define X86_PDE_PAE_PG_MASK UINT64_C(0x000ffffffffff000)
1553/** Bits 63 - NX - PAE/LM - No execution flag. */
1554#define X86_PDE_PAE_NX RT_BIT_64(63)
1555/** Bits 62-52, 7 - - PAE - MBZ bits when NX is active. */
1556#define X86_PDE_PAE_MBZ_MASK_NX UINT64_C(0x7ff0000000000080)
1557/** Bits 63-52, 7 - - PAE - MBZ bits when no NX. */
1558#define X86_PDE_PAE_MBZ_MASK_NO_NX UINT64_C(0xfff0000000000080)
1559/** Bit 7 - - LM - MBZ bits when NX is active. */
1560#define X86_PDE_LM_MBZ_MASK_NX UINT64_C(0x0000000000000080)
1561/** Bits 63, 7 - - LM - MBZ bits when no NX. */
1562#define X86_PDE_LM_MBZ_MASK_NO_NX UINT64_C(0x8000000000000080)
1563
1564/**
1565 * Page directory entry.
1566 */
1567typedef struct X86PDEBITS
1568{
1569 /** Flags whether(=1) or not the page is present. */
1570 unsigned u1Present : 1;
1571 /** Read(=0) / Write(=1) flag. */
1572 unsigned u1Write : 1;
1573 /** User(=1) / Supervisor (=0) flag. */
1574 unsigned u1User : 1;
1575 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1576 unsigned u1WriteThru : 1;
1577 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1578 unsigned u1CacheDisable : 1;
1579 /** Accessed flag.
1580 * Indicates that the page has been read or written to. */
1581 unsigned u1Accessed : 1;
1582 /** Reserved / Ignored (dirty bit). */
1583 unsigned u1Reserved0 : 1;
1584 /** Size bit if PSE is enabled - in any event it's 0. */
1585 unsigned u1Size : 1;
1586 /** Reserved / Ignored (global bit). */
1587 unsigned u1Reserved1 : 1;
1588 /** Available for use to system software. */
1589 unsigned u3Available : 3;
1590 /** Physical Page number of the next level. */
1591 unsigned u20PageNo : 20;
1592} X86PDEBITS;
1593/** Pointer to a page directory entry. */
1594typedef X86PDEBITS *PX86PDEBITS;
1595/** Pointer to a const page directory entry. */
1596typedef const X86PDEBITS *PCX86PDEBITS;
1597
1598
1599/**
1600 * PAE page directory entry.
1601 */
1602typedef struct X86PDEPAEBITS
1603{
1604 /** Flags whether(=1) or not the page is present. */
1605 uint32_t u1Present : 1;
1606 /** Read(=0) / Write(=1) flag. */
1607 uint32_t u1Write : 1;
1608 /** User(=1) / Supervisor (=0) flag. */
1609 uint32_t u1User : 1;
1610 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1611 uint32_t u1WriteThru : 1;
1612 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1613 uint32_t u1CacheDisable : 1;
1614 /** Accessed flag.
1615 * Indicates that the page has been read or written to. */
1616 uint32_t u1Accessed : 1;
1617 /** Reserved / Ignored (dirty bit). */
1618 uint32_t u1Reserved0 : 1;
1619 /** Size bit if PSE is enabled - in any event it's 0. */
1620 uint32_t u1Size : 1;
1621 /** Reserved / Ignored (global bit). / */
1622 uint32_t u1Reserved1 : 1;
1623 /** Available for use to system software. */
1624 uint32_t u3Available : 3;
1625 /** Physical Page number of the next level - Low Part. Don't use! */
1626 uint32_t u20PageNoLow : 20;
1627 /** Physical Page number of the next level - High Part. Don't use! */
1628 uint32_t u20PageNoHigh : 20;
1629 /** MBZ bits */
1630 uint32_t u11Reserved : 11;
1631 /** No Execute flag. */
1632 uint32_t u1NoExecute : 1;
1633} X86PDEPAEBITS;
1634/** Pointer to a page directory entry. */
1635typedef X86PDEPAEBITS *PX86PDEPAEBITS;
1636/** Pointer to a const page directory entry. */
1637typedef const X86PDEPAEBITS *PCX86PDEPAEBITS;
1638
1639/** @} */
1640
1641
1642/** @name 2/4MB Page Directory Entry
1643 * @{
1644 */
1645/** Bit 0 - P - Present bit. */
1646#define X86_PDE4M_P RT_BIT(0)
1647/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
1648#define X86_PDE4M_RW RT_BIT(1)
1649/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
1650#define X86_PDE4M_US RT_BIT(2)
1651/** Bit 3 - PWT - Page level write thru bit. */
1652#define X86_PDE4M_PWT RT_BIT(3)
1653/** Bit 4 - PCD - Page level cache disable bit. */
1654#define X86_PDE4M_PCD RT_BIT(4)
1655/** Bit 5 - A - Access bit. */
1656#define X86_PDE4M_A RT_BIT(5)
1657/** Bit 6 - D - Dirty bit. */
1658#define X86_PDE4M_D RT_BIT(6)
1659/** Bit 7 - PS - Page size attribute. Clear mean 4KB pages, set means large pages (2/4MB). */
1660#define X86_PDE4M_PS RT_BIT(7)
1661/** Bit 8 - G - Global flag. */
1662#define X86_PDE4M_G RT_BIT(8)
1663/** Bits 9-11 - AVL - Available for use to system software. */
1664#define X86_PDE4M_AVL (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1665/** Bit 12 - PAT - Page Attribute Table index bit. Reserved and 0 if not supported. */
1666#define X86_PDE4M_PAT RT_BIT(12)
1667/** Shift to get from X86_PTE_PAT to X86_PDE4M_PAT. */
1668#define X86_PDE4M_PAT_SHIFT (12 - 7)
1669/** Bits 22-31 - - Physical Page number. */
1670#define X86_PDE4M_PG_MASK ( 0xffc00000 )
1671/** Bits 20-13 - - Physical Page number high part (32-39 bits). AMD64 hack. */
1672#define X86_PDE4M_PG_HIGH_MASK ( 0x001fe000 )
1673/** The number of bits to the high part of the page number. */
1674#define X86_PDE4M_PG_HIGH_SHIFT 19
1675/** Bit 21 - - MBZ bits for AMD CPUs, no PSE36. */
1676#define X86_PDE4M_MBZ_MASK RT_BIT_32(21)
1677
1678/** Bits 21-51 - - PAE/LM - Physical Page number.
1679 * (Bits 40-51 (long mode) & bits 36-51 (pae legacy) are reserved according to the Intel docs; AMD allows for more.) */
1680#define X86_PDE2M_PAE_PG_MASK UINT64_C(0x000fffffffe00000)
1681/** Bits 63 - NX - PAE/LM - No execution flag. */
1682#define X86_PDE2M_PAE_NX RT_BIT_64(63)
1683/** Bits 62-52, 20-13 - - PAE - MBZ bits when NX is active. */
1684#define X86_PDE2M_PAE_MBZ_MASK_NX UINT64_C(0x7ff00000001fe000)
1685/** Bits 63-52, 20-13 - - PAE - MBZ bits when no NX. */
1686#define X86_PDE2M_PAE_MBZ_MASK_NO_NX UINT64_C(0xfff00000001fe000)
1687/** Bits 20-13 - - LM - MBZ bits when NX is active. */
1688#define X86_PDE2M_LM_MBZ_MASK_NX UINT64_C(0x00000000001fe000)
1689/** Bits 63, 20-13 - - LM - MBZ bits when no NX. */
1690#define X86_PDE2M_LM_MBZ_MASK_NO_NX UINT64_C(0x80000000001fe000)
1691
1692/**
1693 * 4MB page directory entry.
1694 */
1695typedef struct X86PDE4MBITS
1696{
1697 /** Flags whether(=1) or not the page is present. */
1698 unsigned u1Present : 1;
1699 /** Read(=0) / Write(=1) flag. */
1700 unsigned u1Write : 1;
1701 /** User(=1) / Supervisor (=0) flag. */
1702 unsigned u1User : 1;
1703 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1704 unsigned u1WriteThru : 1;
1705 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1706 unsigned u1CacheDisable : 1;
1707 /** Accessed flag.
1708 * Indicates that the page have been read or written to. */
1709 unsigned u1Accessed : 1;
1710 /** Dirty flag.
1711 * Indicates that the page has been written to. */
1712 unsigned u1Dirty : 1;
1713 /** Page size flag - always 1 for 4MB entries. */
1714 unsigned u1Size : 1;
1715 /** Global flag. */
1716 unsigned u1Global : 1;
1717 /** Available for use to system software. */
1718 unsigned u3Available : 3;
1719 /** Reserved / If PAT enabled, bit 2 of the index. */
1720 unsigned u1PAT : 1;
1721 /** Bits 32-39 of the page number on AMD64.
1722 * This AMD64 hack allows accessing 40bits of physical memory without PAE. */
1723 unsigned u8PageNoHigh : 8;
1724 /** Reserved. */
1725 unsigned u1Reserved : 1;
1726 /** Physical Page number of the page. */
1727 unsigned u10PageNo : 10;
1728} X86PDE4MBITS;
1729/** Pointer to a page table entry. */
1730typedef X86PDE4MBITS *PX86PDE4MBITS;
1731/** Pointer to a const page table entry. */
1732typedef const X86PDE4MBITS *PCX86PDE4MBITS;
1733
1734
1735/**
1736 * 2MB PAE page directory entry.
1737 */
1738typedef struct X86PDE2MPAEBITS
1739{
1740 /** Flags whether(=1) or not the page is present. */
1741 uint32_t u1Present : 1;
1742 /** Read(=0) / Write(=1) flag. */
1743 uint32_t u1Write : 1;
1744 /** User(=1) / Supervisor(=0) flag. */
1745 uint32_t u1User : 1;
1746 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1747 uint32_t u1WriteThru : 1;
1748 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1749 uint32_t u1CacheDisable : 1;
1750 /** Accessed flag.
1751 * Indicates that the page have been read or written to. */
1752 uint32_t u1Accessed : 1;
1753 /** Dirty flag.
1754 * Indicates that the page has been written to. */
1755 uint32_t u1Dirty : 1;
1756 /** Page size flag - always 1 for 2MB entries. */
1757 uint32_t u1Size : 1;
1758 /** Global flag. */
1759 uint32_t u1Global : 1;
1760 /** Available for use to system software. */
1761 uint32_t u3Available : 3;
1762 /** Reserved / If PAT enabled, bit 2 of the index. */
1763 uint32_t u1PAT : 1;
1764 /** Reserved. */
1765 uint32_t u9Reserved : 9;
1766 /** Physical Page number of the next level - Low part. Don't use! */
1767 uint32_t u10PageNoLow : 10;
1768 /** Physical Page number of the next level - High part. Don't use! */
1769 uint32_t u20PageNoHigh : 20;
1770 /** MBZ bits */
1771 uint32_t u11Reserved : 11;
1772 /** No Execute flag. */
1773 uint32_t u1NoExecute : 1;
1774} X86PDE2MPAEBITS;
1775/** Pointer to a 2MB PAE page table entry. */
1776typedef X86PDE2MPAEBITS *PX86PDE2MPAEBITS;
1777/** Pointer to a 2MB PAE page table entry. */
1778typedef const X86PDE2MPAEBITS *PCX86PDE2MPAEBITS;
1779
1780/** @} */
1781
1782/**
1783 * Page directory entry.
1784 */
1785typedef union X86PDE
1786{
1787 /** Unsigned integer view. */
1788 X86PGUINT u;
1789 /** Normal view. */
1790 X86PDEBITS n;
1791 /** 4MB view (big). */
1792 X86PDE4MBITS b;
1793 /** 8 bit unsigned integer view. */
1794 uint8_t au8[4];
1795 /** 16 bit unsigned integer view. */
1796 uint16_t au16[2];
1797 /** 32 bit unsigned integer view. */
1798 uint32_t au32[1];
1799} X86PDE;
1800/** Pointer to a page directory entry. */
1801typedef X86PDE *PX86PDE;
1802/** Pointer to a const page directory entry. */
1803typedef const X86PDE *PCX86PDE;
1804
1805/**
1806 * PAE page directory entry.
1807 */
1808typedef union X86PDEPAE
1809{
1810 /** Unsigned integer view. */
1811 X86PGPAEUINT u;
1812 /** Normal view. */
1813 X86PDEPAEBITS n;
1814 /** 2MB page view (big). */
1815 X86PDE2MPAEBITS b;
1816 /** 8 bit unsigned integer view. */
1817 uint8_t au8[8];
1818 /** 16 bit unsigned integer view. */
1819 uint16_t au16[4];
1820 /** 32 bit unsigned integer view. */
1821 uint32_t au32[2];
1822} X86PDEPAE;
1823/** Pointer to a page directory entry. */
1824typedef X86PDEPAE *PX86PDEPAE;
1825/** Pointer to a const page directory entry. */
1826typedef const X86PDEPAE *PCX86PDEPAE;
1827
1828/**
1829 * Page directory.
1830 */
1831typedef struct X86PD
1832{
1833 /** PDE Array. */
1834 X86PDE a[X86_PG_ENTRIES];
1835} X86PD;
1836/** Pointer to a page directory. */
1837typedef X86PD *PX86PD;
1838/** Pointer to a const page directory. */
1839typedef const X86PD *PCX86PD;
1840
1841/** The page shift to get the PD index. */
1842#define X86_PD_SHIFT 22
1843/** The PD index mask (apply to a shifted page address). */
1844#define X86_PD_MASK 0x3ff
1845
1846
1847/**
1848 * PAE page directory.
1849 */
1850typedef struct X86PDPAE
1851{
1852 /** PDE Array. */
1853 X86PDEPAE a[X86_PG_PAE_ENTRIES];
1854} X86PDPAE;
1855/** Pointer to a PAE page directory. */
1856typedef X86PDPAE *PX86PDPAE;
1857/** Pointer to a const PAE page directory. */
1858typedef const X86PDPAE *PCX86PDPAE;
1859
1860/** The page shift to get the PAE PD index. */
1861#define X86_PD_PAE_SHIFT 21
1862/** The PAE PD index mask (apply to a shifted page address). */
1863#define X86_PD_PAE_MASK 0x1ff
1864
1865
1866/** @name Page Directory Pointer Table Entry (PAE)
1867 * @{
1868 */
1869/** Bit 0 - P - Present bit. */
1870#define X86_PDPE_P RT_BIT(0)
1871/** Bit 1 - R/W - Read (clear) / Write (set) bit. Long Mode only. */
1872#define X86_PDPE_RW RT_BIT(1)
1873/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. Long Mode only. */
1874#define X86_PDPE_US RT_BIT(2)
1875/** Bit 3 - PWT - Page level write thru bit. */
1876#define X86_PDPE_PWT RT_BIT(3)
1877/** Bit 4 - PCD - Page level cache disable bit. */
1878#define X86_PDPE_PCD RT_BIT(4)
1879/** Bit 5 - A - Access bit. Long Mode only. */
1880#define X86_PDPE_A RT_BIT(5)
1881/** Bit 7 - PS - Page size (1GB). Long Mode only. */
1882#define X86_PDPE_LM_PS RT_BIT(7)
1883/** Bits 9-11 - - Available for use to system software. */
1884#define X86_PDPE_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
1885/** Bits 12-51 - - PAE - Physical Page number of the next level. */
1886#define X86_PDPE_PG_MASK UINT64_C(0x000ffffffffff000)
1887/** Bits 63-52, 8-5, 2-1 - - PAE - MBZ bits (NX is long mode only). */
1888#define X86_PDPE_PAE_MBZ_MASK UINT64_C(0xfff00000000001e6)
1889/** Bits 63 - NX - LM - No execution flag. Long Mode only. */
1890#define X86_PDPE_LM_NX RT_BIT_64(63)
1891/** Bits 8, 7 - - LM - MBZ bits when NX is active. */
1892#define X86_PDPE_LM_MBZ_MASK_NX UINT64_C(0x0000000000000180)
1893/** Bits 63, 8, 7 - - LM - MBZ bits when no NX. */
1894#define X86_PDPE_LM_MBZ_MASK_NO_NX UINT64_C(0x8000000000000180)
1895/** Bits 29-13 - - LM - MBZ bits for 1GB page entry when NX is active. */
1896#define X86_PDPE1G_LM_MBZ_MASK_NX UINT64_C(0x000000003fffe000)
1897/** Bits 63, 29-13 - - LM - MBZ bits for 1GB page entry when no NX. */
1898#define X86_PDPE1G_LM_MBZ_MASK_NO_NX UINT64_C(0x800000003fffe000)
1899
1900
1901/**
1902 * Page directory pointer table entry.
1903 */
1904typedef struct X86PDPEBITS
1905{
1906 /** Flags whether(=1) or not the page is present. */
1907 uint32_t u1Present : 1;
1908 /** Chunk of reserved bits. */
1909 uint32_t u2Reserved : 2;
1910 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1911 uint32_t u1WriteThru : 1;
1912 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1913 uint32_t u1CacheDisable : 1;
1914 /** Chunk of reserved bits. */
1915 uint32_t u4Reserved : 4;
1916 /** Available for use to system software. */
1917 uint32_t u3Available : 3;
1918 /** Physical Page number of the next level - Low Part. Don't use! */
1919 uint32_t u20PageNoLow : 20;
1920 /** Physical Page number of the next level - High Part. Don't use! */
1921 uint32_t u20PageNoHigh : 20;
1922 /** MBZ bits */
1923 uint32_t u12Reserved : 12;
1924} X86PDPEBITS;
1925/** Pointer to a page directory pointer table entry. */
1926typedef X86PDPEBITS *PX86PTPEBITS;
1927/** Pointer to a const page directory pointer table entry. */
1928typedef const X86PDPEBITS *PCX86PTPEBITS;
1929
1930/**
1931 * Page directory pointer table entry. AMD64 version
1932 */
1933typedef struct X86PDPEAMD64BITS
1934{
1935 /** Flags whether(=1) or not the page is present. */
1936 uint32_t u1Present : 1;
1937 /** Read(=0) / Write(=1) flag. */
1938 uint32_t u1Write : 1;
1939 /** User(=1) / Supervisor (=0) flag. */
1940 uint32_t u1User : 1;
1941 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
1942 uint32_t u1WriteThru : 1;
1943 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
1944 uint32_t u1CacheDisable : 1;
1945 /** Accessed flag.
1946 * Indicates that the page have been read or written to. */
1947 uint32_t u1Accessed : 1;
1948 /** Chunk of reserved bits. */
1949 uint32_t u3Reserved : 3;
1950 /** Available for use to system software. */
1951 uint32_t u3Available : 3;
1952 /** Physical Page number of the next level - Low Part. Don't use! */
1953 uint32_t u20PageNoLow : 20;
1954 /** Physical Page number of the next level - High Part. Don't use! */
1955 uint32_t u20PageNoHigh : 20;
1956 /** MBZ bits */
1957 uint32_t u11Reserved : 11;
1958 /** No Execute flag. */
1959 uint32_t u1NoExecute : 1;
1960} X86PDPEAMD64BITS;
1961/** Pointer to a page directory pointer table entry. */
1962typedef X86PDPEAMD64BITS *PX86PDPEAMD64BITS;
1963/** Pointer to a const page directory pointer table entry. */
1964typedef const X86PDPEAMD64BITS *PCX86PDPEAMD64BITS;
1965
1966/**
1967 * Page directory pointer table entry.
1968 */
1969typedef union X86PDPE
1970{
1971 /** Unsigned integer view. */
1972 X86PGPAEUINT u;
1973 /** Normal view. */
1974 X86PDPEBITS n;
1975 /** AMD64 view. */
1976 X86PDPEAMD64BITS lm;
1977 /** 8 bit unsigned integer view. */
1978 uint8_t au8[8];
1979 /** 16 bit unsigned integer view. */
1980 uint16_t au16[4];
1981 /** 32 bit unsigned integer view. */
1982 uint32_t au32[2];
1983} X86PDPE;
1984/** Pointer to a page directory pointer table entry. */
1985typedef X86PDPE *PX86PDPE;
1986/** Pointer to a const page directory pointer table entry. */
1987typedef const X86PDPE *PCX86PDPE;
1988
1989
1990/**
1991 * Page directory pointer table.
1992 */
1993typedef struct X86PDPT
1994{
1995 /** PDE Array. */
1996 X86PDPE a[X86_PG_AMD64_PDPE_ENTRIES];
1997} X86PDPT;
1998/** Pointer to a page directory pointer table. */
1999typedef X86PDPT *PX86PDPT;
2000/** Pointer to a const page directory pointer table. */
2001typedef const X86PDPT *PCX86PDPT;
2002
2003/** The page shift to get the PDPT index. */
2004#define X86_PDPT_SHIFT 30
2005/** The PDPT index mask (apply to a shifted page address). (32 bits PAE) */
2006#define X86_PDPT_MASK_PAE 0x3
2007/** The PDPT index mask (apply to a shifted page address). (64 bits PAE)*/
2008#define X86_PDPT_MASK_AMD64 0x1ff
2009
2010/** @} */
2011
2012
2013/** @name Page Map Level-4 Entry (Long Mode PAE)
2014 * @{
2015 */
2016/** Bit 0 - P - Present bit. */
2017#define X86_PML4E_P RT_BIT(0)
2018/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
2019#define X86_PML4E_RW RT_BIT(1)
2020/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
2021#define X86_PML4E_US RT_BIT(2)
2022/** Bit 3 - PWT - Page level write thru bit. */
2023#define X86_PML4E_PWT RT_BIT(3)
2024/** Bit 4 - PCD - Page level cache disable bit. */
2025#define X86_PML4E_PCD RT_BIT(4)
2026/** Bit 5 - A - Access bit. */
2027#define X86_PML4E_A RT_BIT(5)
2028/** Bits 9-11 - - Available for use to system software. */
2029#define X86_PML4E_AVL_MASK (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
2030/** Bits 12-51 - - PAE - Physical Page number of the next level. */
2031#define X86_PML4E_PG_MASK UINT64_C(0x000ffffffffff000)
2032/** Bits 8, 7 - - MBZ bits when NX is active. */
2033#define X86_PML4E_MBZ_MASK_NX UINT64_C(0x0000000000000080)
2034/** Bits 63, 7 - - MBZ bits when no NX. */
2035#define X86_PML4E_MBZ_MASK_NO_NX UINT64_C(0x8000000000000080)
2036/** Bits 63 - NX - PAE - No execution flag. */
2037#define X86_PML4E_NX RT_BIT_64(63)
2038
2039/**
2040 * Page Map Level-4 Entry
2041 */
2042typedef struct X86PML4EBITS
2043{
2044 /** Flags whether(=1) or not the page is present. */
2045 uint32_t u1Present : 1;
2046 /** Read(=0) / Write(=1) flag. */
2047 uint32_t u1Write : 1;
2048 /** User(=1) / Supervisor (=0) flag. */
2049 uint32_t u1User : 1;
2050 /** Write Thru flag. If PAT enabled, bit 0 of the index. */
2051 uint32_t u1WriteThru : 1;
2052 /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
2053 uint32_t u1CacheDisable : 1;
2054 /** Accessed flag.
2055 * Indicates that the page have been read or written to. */
2056 uint32_t u1Accessed : 1;
2057 /** Chunk of reserved bits. */
2058 uint32_t u3Reserved : 3;
2059 /** Available for use to system software. */
2060 uint32_t u3Available : 3;
2061 /** Physical Page number of the next level - Low Part. Don't use! */
2062 uint32_t u20PageNoLow : 20;
2063 /** Physical Page number of the next level - High Part. Don't use! */
2064 uint32_t u20PageNoHigh : 20;
2065 /** MBZ bits */
2066 uint32_t u11Reserved : 11;
2067 /** No Execute flag. */
2068 uint32_t u1NoExecute : 1;
2069} X86PML4EBITS;
2070/** Pointer to a page map level-4 entry. */
2071typedef X86PML4EBITS *PX86PML4EBITS;
2072/** Pointer to a const page map level-4 entry. */
2073typedef const X86PML4EBITS *PCX86PML4EBITS;
2074
2075/**
2076 * Page Map Level-4 Entry.
2077 */
2078typedef union X86PML4E
2079{
2080 /** Unsigned integer view. */
2081 X86PGPAEUINT u;
2082 /** Normal view. */
2083 X86PML4EBITS n;
2084 /** 8 bit unsigned integer view. */
2085 uint8_t au8[8];
2086 /** 16 bit unsigned integer view. */
2087 uint16_t au16[4];
2088 /** 32 bit unsigned integer view. */
2089 uint32_t au32[2];
2090} X86PML4E;
2091/** Pointer to a page map level-4 entry. */
2092typedef X86PML4E *PX86PML4E;
2093/** Pointer to a const page map level-4 entry. */
2094typedef const X86PML4E *PCX86PML4E;
2095
2096
2097/**
2098 * Page Map Level-4.
2099 */
2100typedef struct X86PML4
2101{
2102 /** PDE Array. */
2103 X86PML4E a[X86_PG_PAE_ENTRIES];
2104} X86PML4;
2105/** Pointer to a page map level-4. */
2106typedef X86PML4 *PX86PML4;
2107/** Pointer to a const page map level-4. */
2108typedef const X86PML4 *PCX86PML4;
2109
2110/** The page shift to get the PML4 index. */
2111#define X86_PML4_SHIFT 39
2112/** The PML4 index mask (apply to a shifted page address). */
2113#define X86_PML4_MASK 0x1ff
2114
2115/** @} */
2116
2117/** @} */
2118
2119/**
2120 * 32-bit protected mode FSTENV image.
2121 */
2122typedef struct X86FSTENV32P
2123{
2124 uint16_t FCW;
2125 uint16_t padding1;
2126 uint16_t FSW;
2127 uint16_t padding2;
2128 uint16_t FTW;
2129 uint16_t padding3;
2130 uint32_t FPUIP;
2131 uint16_t FPUCS;
2132 uint16_t FOP;
2133 uint32_t FPUDP;
2134 uint16_t FPUDS;
2135 uint16_t padding4;
2136} X86FSTENV32P;
2137/** Pointer to a 32-bit protected mode FSTENV image. */
2138typedef X86FSTENV32P *PX86FSTENV32P;
2139/** Pointer to a const 32-bit protected mode FSTENV image. */
2140typedef X86FSTENV32P const *PCX86FSTENV32P;
2141
2142
2143/**
2144 * 80-bit MMX/FPU register type.
2145 */
2146typedef struct X86FPUMMX
2147{
2148 uint8_t reg[10];
2149} X86FPUMMX;
2150/** Pointer to a 80-bit MMX/FPU register type. */
2151typedef X86FPUMMX *PX86FPUMMX;
2152/** Pointer to a const 80-bit MMX/FPU register type. */
2153typedef const X86FPUMMX *PCX86FPUMMX;
2154
2155/**
2156 * 32-bit FPU state (aka FSAVE/FRSTOR Memory Region).
2157 * @todo verify this...
2158 */
2159#pragma pack(1)
2160typedef struct X86FPUSTATE
2161{
2162 /** 0x00 - Control word. */
2163 uint16_t FCW;
2164 /** 0x02 - Alignment word */
2165 uint16_t Dummy1;
2166 /** 0x04 - Status word. */
2167 uint16_t FSW;
2168 /** 0x06 - Alignment word */
2169 uint16_t Dummy2;
2170 /** 0x08 - Tag word */
2171 uint16_t FTW;
2172 /** 0x0a - Alignment word */
2173 uint16_t Dummy3;
2174
2175 /** 0x0c - Instruction pointer. */
2176 uint32_t FPUIP;
2177 /** 0x10 - Code selector. */
2178 uint16_t CS;
2179 /** 0x12 - Opcode. */
2180 uint16_t FOP;
2181 /** 0x14 - FOO. */
2182 uint32_t FPUOO;
2183 /** 0x18 - FOS. */
2184 uint32_t FPUOS;
2185 /** 0x1c */
2186 union
2187 {
2188 /** MMX view. */
2189 uint64_t mmx;
2190 /** FPU view - todo. */
2191 X86FPUMMX fpu;
2192 /** Extended precision floating point view. */
2193 RTFLOAT80U r80;
2194 /** Extended precision floating point view v2. */
2195 RTFLOAT80U2 r80Ex;
2196 /** 8-bit view. */
2197 uint8_t au8[16];
2198 /** 16-bit view. */
2199 uint16_t au16[8];
2200 /** 32-bit view. */
2201 uint32_t au32[4];
2202 /** 64-bit view. */
2203 uint64_t au64[2];
2204 /** 128-bit view. (yeah, very helpful) */
2205 uint128_t au128[1];
2206 } regs[8];
2207} X86FPUSTATE;
2208#pragma pack()
2209/** Pointer to a FPU state. */
2210typedef X86FPUSTATE *PX86FPUSTATE;
2211/** Pointer to a const FPU state. */
2212typedef const X86FPUSTATE *PCX86FPUSTATE;
2213
2214/**
2215 * FPU Extended state (aka FXSAVE/FXRSTORE Memory Region).
2216 */
2217#pragma pack(1)
2218typedef struct X86FXSTATE
2219{
2220 /** 0x00 - Control word. */
2221 uint16_t FCW;
2222 /** 0x02 - Status word. */
2223 uint16_t FSW;
2224 /** 0x04 - Tag word. (The upper byte is always zero.) */
2225 uint16_t FTW;
2226 /** 0x06 - Opcode. */
2227 uint16_t FOP;
2228 /** 0x08 - Instruction pointer. */
2229 uint32_t FPUIP;
2230 /** 0x0c - Code selector. */
2231 uint16_t CS;
2232 uint16_t Rsrvd1;
2233 /** 0x10 - Data pointer. */
2234 uint32_t FPUDP;
2235 /** 0x14 - Data segment */
2236 uint16_t DS;
2237 /** 0x16 */
2238 uint16_t Rsrvd2;
2239 /** 0x18 */
2240 uint32_t MXCSR;
2241 /** 0x1c */
2242 uint32_t MXCSR_MASK;
2243 /** 0x20 */
2244 union
2245 {
2246 /** MMX view. */
2247 uint64_t mmx;
2248 /** FPU view - todo. */
2249 X86FPUMMX fpu;
2250 /** Extended precision floating point view. */
2251 RTFLOAT80U r80;
2252 /** Extended precision floating point view v2 */
2253 RTFLOAT80U2 r80Ex;
2254 /** 8-bit view. */
2255 uint8_t au8[16];
2256 /** 16-bit view. */
2257 uint16_t au16[8];
2258 /** 32-bit view. */
2259 uint32_t au32[4];
2260 /** 64-bit view. */
2261 uint64_t au64[2];
2262 /** 128-bit view. (yeah, very helpful) */
2263 uint128_t au128[1];
2264 } aRegs[8];
2265 /* - offset 160 - */
2266 union
2267 {
2268 /** XMM Register view *. */
2269 uint128_t xmm;
2270 /** 8-bit view. */
2271 uint8_t au8[16];
2272 /** 16-bit view. */
2273 uint16_t au16[8];
2274 /** 32-bit view. */
2275 uint32_t au32[4];
2276 /** 64-bit view. */
2277 uint64_t au64[2];
2278 /** 128-bit view. (yeah, very helpful) */
2279 uint128_t au128[1];
2280 } aXMM[16]; /* 8 registers in 32 bits mode; 16 in long mode */
2281 /* - offset 416 - */
2282 uint32_t au32RsrvdRest[(512 - 416) / sizeof(uint32_t)];
2283} X86FXSTATE;
2284#pragma pack()
2285/** Pointer to a FPU Extended state. */
2286typedef X86FXSTATE *PX86FXSTATE;
2287/** Pointer to a const FPU Extended state. */
2288typedef const X86FXSTATE *PCX86FXSTATE;
2289
2290/** @name FPU status word flags.
2291 * @{ */
2292/** Exception Flag: Invalid operation. */
2293#define X86_FSW_IE RT_BIT(0)
2294/** Exception Flag: Denormalized operand. */
2295#define X86_FSW_DE RT_BIT(1)
2296/** Exception Flag: Zero divide. */
2297#define X86_FSW_ZE RT_BIT(2)
2298/** Exception Flag: Overflow. */
2299#define X86_FSW_OE RT_BIT(3)
2300/** Exception Flag: Underflow. */
2301#define X86_FSW_UE RT_BIT(4)
2302/** Exception Flag: Precision. */
2303#define X86_FSW_PE RT_BIT(5)
2304/** Stack fault. */
2305#define X86_FSW_SF RT_BIT(6)
2306/** Error summary status. */
2307#define X86_FSW_ES RT_BIT(7)
2308/** Mask of exceptions flags, excluding the summary bit. */
2309#define X86_FSW_XCPT_MASK UINT16_C(0x007f)
2310/** Mask of exceptions flags, including the summary bit. */
2311#define X86_FSW_XCPT_ES_MASK UINT16_C(0x00ff)
2312/** Condition code 0. */
2313#define X86_FSW_C0 RT_BIT(8)
2314/** Condition code 1. */
2315#define X86_FSW_C1 RT_BIT(9)
2316/** Condition code 2. */
2317#define X86_FSW_C2 RT_BIT(10)
2318/** Top of the stack mask. */
2319#define X86_FSW_TOP_MASK UINT16_C(0x3800)
2320/** TOP shift value. */
2321#define X86_FSW_TOP_SHIFT 11
2322/** Mask for getting TOP value after shifting it right. */
2323#define X86_FSW_TOP_SMASK UINT16_C(0x0007)
2324/** Get the TOP value. */
2325#define X86_FSW_TOP_GET(a_uFsw) (((a_uFsw) >> X86_FSW_TOP_SHIFT) & X86_FSW_TOP_SMASK)
2326/** Condition code 3. */
2327#define X86_FSW_C3 RT_BIT(14)
2328/** Mask of exceptions flags, including the summary bit. */
2329#define X86_FSW_C_MASK UINT16_C(0x4700)
2330/** FPU busy. */
2331#define X86_FSW_B RT_BIT(15)
2332/** @} */
2333
2334
2335/** @name FPU control word flags.
2336 * @{ */
2337/** Exception Mask: Invalid operation. */
2338#define X86_FCW_IM RT_BIT(0)
2339/** Exception Mask: Denormalized operand. */
2340#define X86_FCW_DM RT_BIT(1)
2341/** Exception Mask: Zero divide. */
2342#define X86_FCW_ZM RT_BIT(2)
2343/** Exception Mask: Overflow. */
2344#define X86_FCW_OM RT_BIT(3)
2345/** Exception Mask: Underflow. */
2346#define X86_FCW_UM RT_BIT(4)
2347/** Exception Mask: Precision. */
2348#define X86_FCW_PM RT_BIT(5)
2349/** Mask all exceptions, the value typically loaded (by for instance fninit).
2350 * @remarks This includes reserved bit 6. */
2351#define X86_FCW_MASK_ALL UINT16_C(0x007f)
2352/** Mask all exceptions. Same as X86_FSW_XCPT_MASK. */
2353#define X86_FCW_XCPT_MASK UINT16_C(0x003f)
2354/** Precision control mask. */
2355#define X86_FCW_PC_MASK UINT16_C(0x0300)
2356/** Precision control: 24-bit. */
2357#define X86_FCW_PC_24 UINT16_C(0x0000)
2358/** Precision control: Reserved. */
2359#define X86_FCW_PC_RSVD UINT16_C(0x0100)
2360/** Precision control: 53-bit. */
2361#define X86_FCW_PC_53 UINT16_C(0x0200)
2362/** Precision control: 64-bit. */
2363#define X86_FCW_PC_64 UINT16_C(0x0300)
2364/** Rounding control mask. */
2365#define X86_FCW_RC_MASK UINT16_C(0x0c00)
2366/** Rounding control: To nearest. */
2367#define X86_FCW_RC_NEAREST UINT16_C(0x0000)
2368/** Rounding control: Down. */
2369#define X86_FCW_RC_DOWN UINT16_C(0x0400)
2370/** Rounding control: Up. */
2371#define X86_FCW_RC_UP UINT16_C(0x0800)
2372/** Rounding control: Towards zero. */
2373#define X86_FCW_RC_ZERO UINT16_C(0x0c00)
2374/** Bits which should be zero, apparently. */
2375#define X86_FCW_ZERO_MASK UINT16_C(0xf080)
2376/** @} */
2377
2378/** @name SSE MXCSR
2379 * @{ */
2380/** Exception Flag: Invalid operation. */
2381#define X86_MSXCR_IE RT_BIT(0)
2382/** Exception Flag: Denormalized operand. */
2383#define X86_MSXCR_DE RT_BIT(1)
2384/** Exception Flag: Zero divide. */
2385#define X86_MSXCR_ZE RT_BIT(2)
2386/** Exception Flag: Overflow. */
2387#define X86_MSXCR_OE RT_BIT(3)
2388/** Exception Flag: Underflow. */
2389#define X86_MSXCR_UE RT_BIT(4)
2390/** Exception Flag: Precision. */
2391#define X86_MSXCR_PE RT_BIT(5)
2392
2393/** Denormals are zero. */
2394#define X86_MSXCR_DAZ RT_BIT(6)
2395
2396/** Exception Mask: Invalid operation. */
2397#define X86_MSXCR_IM RT_BIT(7)
2398/** Exception Mask: Denormalized operand. */
2399#define X86_MSXCR_DM RT_BIT(8)
2400/** Exception Mask: Zero divide. */
2401#define X86_MSXCR_ZM RT_BIT(9)
2402/** Exception Mask: Overflow. */
2403#define X86_MSXCR_OM RT_BIT(10)
2404/** Exception Mask: Underflow. */
2405#define X86_MSXCR_UM RT_BIT(11)
2406/** Exception Mask: Precision. */
2407#define X86_MSXCR_PM RT_BIT(12)
2408
2409/** Rounding control mask. */
2410#define X86_MSXCR_RC_MASK UINT16_C(0x6000)
2411/** Rounding control: To nearest. */
2412#define X86_MSXCR_RC_NEAREST UINT16_C(0x0000)
2413/** Rounding control: Down. */
2414#define X86_MSXCR_RC_DOWN UINT16_C(0x2000)
2415/** Rounding control: Up. */
2416#define X86_MSXCR_RC_UP UINT16_C(0x4000)
2417/** Rounding control: Towards zero. */
2418#define X86_MSXCR_RC_ZERO UINT16_C(0x6000)
2419
2420/** Flush-to-zero for masked underflow. */
2421#define X86_MSXCR_FZ RT_BIT(15)
2422
2423/** Misaligned Exception Mask. */
2424#define X86_MSXCR_MM RT_BIT(16)
2425/** @} */
2426
2427
2428/** @name Selector Descriptor
2429 * @{
2430 */
2431
2432#ifndef VBOX_FOR_DTRACE_LIB
2433/**
2434 * Descriptor attributes (as seen by VT-x).
2435 */
2436typedef struct X86DESCATTRBITS
2437{
2438 /** 00 - Segment Type. */
2439 unsigned u4Type : 4;
2440 /** 04 - Descriptor Type. System(=0) or code/data selector */
2441 unsigned u1DescType : 1;
2442 /** 05 - Descriptor Privelege level. */
2443 unsigned u2Dpl : 2;
2444 /** 07 - Flags selector present(=1) or not. */
2445 unsigned u1Present : 1;
2446 /** 08 - Segment limit 16-19. */
2447 unsigned u4LimitHigh : 4;
2448 /** 0c - Available for system software. */
2449 unsigned u1Available : 1;
2450 /** 0d - 32 bits mode: Reserved - 0, long mode: Long Attribute Bit. */
2451 unsigned u1Long : 1;
2452 /** 0e - This flags meaning depends on the segment type. Try make sense out
2453 * of the intel manual yourself. */
2454 unsigned u1DefBig : 1;
2455 /** 0f - Granularity of the limit. If set 4KB granularity is used, if
2456 * clear byte. */
2457 unsigned u1Granularity : 1;
2458 /** 10 - "Unusable" selector, special Intel (VT-x only?) bit. */
2459 unsigned u1Unusable : 1;
2460} X86DESCATTRBITS;
2461#endif /* !VBOX_FOR_DTRACE_LIB */
2462
2463/** @name X86DESCATTR masks
2464 * @{ */
2465#define X86DESCATTR_TYPE UINT32_C(0x0000000f)
2466#define X86DESCATTR_DT UINT32_C(0x00000010)
2467#define X86DESCATTR_DPL UINT32_C(0x00000060)
2468#define X86DESCATTR_DPL_SHIFT 5 /**< Shift count for the DPL value. */
2469#define X86DESCATTR_P UINT32_C(0x00000080)
2470#define X86DESCATTR_LIMIT_HIGH UINT32_C(0x00000f00)
2471#define X86DESCATTR_AVL UINT32_C(0x00001000)
2472#define X86DESCATTR_L UINT32_C(0x00002000)
2473#define X86DESCATTR_D UINT32_C(0x00004000)
2474#define X86DESCATTR_G UINT32_C(0x00008000)
2475#define X86DESCATTR_UNUSABLE UINT32_C(0x00010000)
2476/** @} */
2477
2478#pragma pack(1)
2479typedef union X86DESCATTR
2480{
2481 /** Unsigned integer view. */
2482 uint32_t u;
2483#ifndef VBOX_FOR_DTRACE_LIB
2484 /** Normal view. */
2485 X86DESCATTRBITS n;
2486#endif
2487} X86DESCATTR;
2488#pragma pack()
2489/** Pointer to descriptor attributes. */
2490typedef X86DESCATTR *PX86DESCATTR;
2491/** Pointer to const descriptor attributes. */
2492typedef const X86DESCATTR *PCX86DESCATTR;
2493
2494#ifndef VBOX_FOR_DTRACE_LIB
2495
2496/**
2497 * Generic descriptor table entry
2498 */
2499#pragma pack(1)
2500typedef struct X86DESCGENERIC
2501{
2502 /** 00 - Limit - Low word. */
2503 unsigned u16LimitLow : 16;
2504 /** 10 - Base address - lowe word.
2505 * Don't try set this to 24 because MSC is doing stupid things then. */
2506 unsigned u16BaseLow : 16;
2507 /** 20 - Base address - first 8 bits of high word. */
2508 unsigned u8BaseHigh1 : 8;
2509 /** 28 - Segment Type. */
2510 unsigned u4Type : 4;
2511 /** 2c - Descriptor Type. System(=0) or code/data selector */
2512 unsigned u1DescType : 1;
2513 /** 2d - Descriptor Privelege level. */
2514 unsigned u2Dpl : 2;
2515 /** 2f - Flags selector present(=1) or not. */
2516 unsigned u1Present : 1;
2517 /** 30 - Segment limit 16-19. */
2518 unsigned u4LimitHigh : 4;
2519 /** 34 - Available for system software. */
2520 unsigned u1Available : 1;
2521 /** 35 - 32 bits mode: Reserved - 0, long mode: Long Attribute Bit. */
2522 unsigned u1Long : 1;
2523 /** 36 - This flags meaning depends on the segment type. Try make sense out
2524 * of the intel manual yourself. */
2525 unsigned u1DefBig : 1;
2526 /** 37 - Granularity of the limit. If set 4KB granularity is used, if
2527 * clear byte. */
2528 unsigned u1Granularity : 1;
2529 /** 38 - Base address - highest 8 bits. */
2530 unsigned u8BaseHigh2 : 8;
2531} X86DESCGENERIC;
2532#pragma pack()
2533/** Pointer to a generic descriptor entry. */
2534typedef X86DESCGENERIC *PX86DESCGENERIC;
2535/** Pointer to a const generic descriptor entry. */
2536typedef const X86DESCGENERIC *PCX86DESCGENERIC;
2537
2538/** @name Bit offsets of X86DESCGENERIC members.
2539 * @{*/
2540#define X86DESCGENERIC_BIT_OFF_LIMIT_LOW (0) /**< Bit offset of X86DESCGENERIC::u16LimitLow. */
2541#define X86DESCGENERIC_BIT_OFF_BASE_LOW (16) /**< Bit offset of X86DESCGENERIC::u16BaseLow. */
2542#define X86DESCGENERIC_BIT_OFF_BASE_HIGH1 (32) /**< Bit offset of X86DESCGENERIC::u8BaseHigh1. */
2543#define X86DESCGENERIC_BIT_OFF_TYPE (40) /**< Bit offset of X86DESCGENERIC::u4Type. */
2544#define X86DESCGENERIC_BIT_OFF_DESC_TYPE (44) /**< Bit offset of X86DESCGENERIC::u1DescType. */
2545#define X86DESCGENERIC_BIT_OFF_DPL (45) /**< Bit offset of X86DESCGENERIC::u2Dpl. */
2546#define X86DESCGENERIC_BIT_OFF_PRESENT (47) /**< Bit offset of X86DESCGENERIC::uu1Present. */
2547#define X86DESCGENERIC_BIT_OFF_LIMIT_HIGH (48) /**< Bit offset of X86DESCGENERIC::u4LimitHigh. */
2548#define X86DESCGENERIC_BIT_OFF_AVAILABLE (52) /**< Bit offset of X86DESCGENERIC::u1Available. */
2549#define X86DESCGENERIC_BIT_OFF_LONG (53) /**< Bit offset of X86DESCGENERIC::u1Long. */
2550#define X86DESCGENERIC_BIT_OFF_DEF_BIG (54) /**< Bit offset of X86DESCGENERIC::u1DefBig. */
2551#define X86DESCGENERIC_BIT_OFF_GRANULARITY (55) /**< Bit offset of X86DESCGENERIC::u1Granularity. */
2552#define X86DESCGENERIC_BIT_OFF_BASE_HIGH2 (56) /**< Bit offset of X86DESCGENERIC::u8BaseHigh2. */
2553/** @} */
2554
2555/**
2556 * Call-, Interrupt-, Trap- or Task-gate descriptor (legacy).
2557 */
2558typedef struct X86DESCGATE
2559{
2560 /** 00 - Target code segment offset - Low word.
2561 * Ignored if task-gate. */
2562 unsigned u16OffsetLow : 16;
2563 /** 10 - Target code segment selector for call-, interrupt- and trap-gates,
2564 * TSS selector if task-gate. */
2565 unsigned u16Sel : 16;
2566 /** 20 - Number of parameters for a call-gate.
2567 * Ignored if interrupt-, trap- or task-gate. */
2568 unsigned u4ParmCount : 4;
2569 /** 24 - Reserved / ignored. */
2570 unsigned u4Reserved : 4;
2571 /** 28 - Segment Type. */
2572 unsigned u4Type : 4;
2573 /** 2c - Descriptor Type (0 = system). */
2574 unsigned u1DescType : 1;
2575 /** 2d - Descriptor Privelege level. */
2576 unsigned u2Dpl : 2;
2577 /** 2f - Flags selector present(=1) or not. */
2578 unsigned u1Present : 1;
2579 /** 30 - Target code segment offset - High word.
2580 * Ignored if task-gate. */
2581 unsigned u16OffsetHigh : 16;
2582} X86DESCGATE;
2583/** Pointer to a Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
2584typedef X86DESCGATE *PX86DESCGATE;
2585/** Pointer to a const Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
2586typedef const X86DESCGATE *PCX86DESCGATE;
2587
2588#endif /* VBOX_FOR_DTRACE_LIB */
2589
2590/**
2591 * Descriptor table entry.
2592 */
2593#pragma pack(1)
2594typedef union X86DESC
2595{
2596#ifndef VBOX_FOR_DTRACE_LIB
2597 /** Generic descriptor view. */
2598 X86DESCGENERIC Gen;
2599 /** Gate descriptor view. */
2600 X86DESCGATE Gate;
2601#endif
2602
2603 /** 8 bit unsigned integer view. */
2604 uint8_t au8[8];
2605 /** 16 bit unsigned integer view. */
2606 uint16_t au16[4];
2607 /** 32 bit unsigned integer view. */
2608 uint32_t au32[2];
2609 /** 64 bit unsigned integer view. */
2610 uint64_t au64[1];
2611 /** Unsigned integer view. */
2612 uint64_t u;
2613} X86DESC;
2614#ifndef VBOX_FOR_DTRACE_LIB
2615AssertCompileSize(X86DESC, 8);
2616#endif
2617#pragma pack()
2618/** Pointer to descriptor table entry. */
2619typedef X86DESC *PX86DESC;
2620/** Pointer to const descriptor table entry. */
2621typedef const X86DESC *PCX86DESC;
2622
2623/** @def X86DESC_BASE
2624 * Return the base address of a descriptor.
2625 */
2626#define X86DESC_BASE(a_pDesc) /*ASM-NOINC*/ \
2627 ( ((uint32_t)((a_pDesc)->Gen.u8BaseHigh2) << 24) \
2628 | ( (a_pDesc)->Gen.u8BaseHigh1 << 16) \
2629 | ( (a_pDesc)->Gen.u16BaseLow ) )
2630
2631/** @def X86DESC_LIMIT
2632 * Return the limit of a descriptor.
2633 */
2634#define X86DESC_LIMIT(a_pDesc) /*ASM-NOINC*/ \
2635 ( ((uint32_t)((a_pDesc)->Gen.u4LimitHigh) << 16) \
2636 | ( (a_pDesc)->Gen.u16LimitLow ) )
2637
2638/** @def X86DESC_LIMIT_G
2639 * Return the limit of a descriptor with the granularity bit taken into account.
2640 * @returns Selector limit (uint32_t).
2641 * @param a_pDesc Pointer to the descriptor.
2642 */
2643#define X86DESC_LIMIT_G(a_pDesc) /*ASM-NOINC*/ \
2644 ( (a_pDesc)->Gen.u1Granularity \
2645 ? ( ( ((uint32_t)(a_pDesc)->Gen.u4LimitHigh << 16) | (a_pDesc)->Gen.u16LimitLow ) << 12 ) | UINT32_C(0xfff) \
2646 : ((uint32_t)(a_pDesc)->Gen.u4LimitHigh << 16) | (a_pDesc)->Gen.u16LimitLow \
2647 )
2648
2649/** @def X86DESC_GET_HID_ATTR
2650 * Get the descriptor attributes for the hidden register.
2651 */
2652#define X86DESC_GET_HID_ATTR(a_pDesc) /*ASM-NOINC*/ \
2653 ( ((a_pDesc)->u >> (16+16+8)) & UINT32_C(0xf0ff) ) /** @todo do we have a define for 0xf0ff? */
2654
2655#ifndef VBOX_FOR_DTRACE_LIB
2656
2657/**
2658 * 64 bits generic descriptor table entry
2659 * Note: most of these bits have no meaning in long mode.
2660 */
2661#pragma pack(1)
2662typedef struct X86DESC64GENERIC
2663{
2664 /** Limit - Low word - *IGNORED*. */
2665 unsigned u16LimitLow : 16;
2666 /** Base address - low word. - *IGNORED*
2667 * Don't try set this to 24 because MSC is doing stupid things then. */
2668 unsigned u16BaseLow : 16;
2669 /** Base address - first 8 bits of high word. - *IGNORED* */
2670 unsigned u8BaseHigh1 : 8;
2671 /** Segment Type. */
2672 unsigned u4Type : 4;
2673 /** Descriptor Type. System(=0) or code/data selector */
2674 unsigned u1DescType : 1;
2675 /** Descriptor Privelege level. */
2676 unsigned u2Dpl : 2;
2677 /** Flags selector present(=1) or not. */
2678 unsigned u1Present : 1;
2679 /** Segment limit 16-19. - *IGNORED* */
2680 unsigned u4LimitHigh : 4;
2681 /** Available for system software. - *IGNORED* */
2682 unsigned u1Available : 1;
2683 /** Long mode flag. */
2684 unsigned u1Long : 1;
2685 /** This flags meaning depends on the segment type. Try make sense out
2686 * of the intel manual yourself. */
2687 unsigned u1DefBig : 1;
2688 /** Granularity of the limit. If set 4KB granularity is used, if
2689 * clear byte. - *IGNORED* */
2690 unsigned u1Granularity : 1;
2691 /** Base address - highest 8 bits. - *IGNORED* */
2692 unsigned u8BaseHigh2 : 8;
2693 /** Base address - bits 63-32. */
2694 unsigned u32BaseHigh3 : 32;
2695 unsigned u8Reserved : 8;
2696 unsigned u5Zeros : 5;
2697 unsigned u19Reserved : 19;
2698} X86DESC64GENERIC;
2699#pragma pack()
2700/** Pointer to a generic descriptor entry. */
2701typedef X86DESC64GENERIC *PX86DESC64GENERIC;
2702/** Pointer to a const generic descriptor entry. */
2703typedef const X86DESC64GENERIC *PCX86DESC64GENERIC;
2704
2705/**
2706 * System descriptor table entry (64 bits)
2707 *
2708 * @remarks This is, save a couple of comments, identical to X86DESC64GENERIC...
2709 */
2710#pragma pack(1)
2711typedef struct X86DESC64SYSTEM
2712{
2713 /** Limit - Low word. */
2714 unsigned u16LimitLow : 16;
2715 /** Base address - lowe word.
2716 * Don't try set this to 24 because MSC is doing stupid things then. */
2717 unsigned u16BaseLow : 16;
2718 /** Base address - first 8 bits of high word. */
2719 unsigned u8BaseHigh1 : 8;
2720 /** Segment Type. */
2721 unsigned u4Type : 4;
2722 /** Descriptor Type. System(=0) or code/data selector */
2723 unsigned u1DescType : 1;
2724 /** Descriptor Privelege level. */
2725 unsigned u2Dpl : 2;
2726 /** Flags selector present(=1) or not. */
2727 unsigned u1Present : 1;
2728 /** Segment limit 16-19. */
2729 unsigned u4LimitHigh : 4;
2730 /** Available for system software. */
2731 unsigned u1Available : 1;
2732 /** Reserved - 0. */
2733 unsigned u1Reserved : 1;
2734 /** This flags meaning depends on the segment type. Try make sense out
2735 * of the intel manual yourself. */
2736 unsigned u1DefBig : 1;
2737 /** Granularity of the limit. If set 4KB granularity is used, if
2738 * clear byte. */
2739 unsigned u1Granularity : 1;
2740 /** Base address - bits 31-24. */
2741 unsigned u8BaseHigh2 : 8;
2742 /** Base address - bits 63-32. */
2743 unsigned u32BaseHigh3 : 32;
2744 unsigned u8Reserved : 8;
2745 unsigned u5Zeros : 5;
2746 unsigned u19Reserved : 19;
2747} X86DESC64SYSTEM;
2748#pragma pack()
2749/** Pointer to a system descriptor entry. */
2750typedef X86DESC64SYSTEM *PX86DESC64SYSTEM;
2751/** Pointer to a const system descriptor entry. */
2752typedef const X86DESC64SYSTEM *PCX86DESC64SYSTEM;
2753
2754/**
2755 * Call-, Interrupt-, Trap- or Task-gate descriptor (64-bit).
2756 */
2757typedef struct X86DESC64GATE
2758{
2759 /** Target code segment offset - Low word. */
2760 unsigned u16OffsetLow : 16;
2761 /** Target code segment selector. */
2762 unsigned u16Sel : 16;
2763 /** Interrupt stack table for interrupt- and trap-gates.
2764 * Ignored by call-gates. */
2765 unsigned u3IST : 3;
2766 /** Reserved / ignored. */
2767 unsigned u5Reserved : 5;
2768 /** Segment Type. */
2769 unsigned u4Type : 4;
2770 /** Descriptor Type (0 = system). */
2771 unsigned u1DescType : 1;
2772 /** Descriptor Privelege level. */
2773 unsigned u2Dpl : 2;
2774 /** Flags selector present(=1) or not. */
2775 unsigned u1Present : 1;
2776 /** Target code segment offset - High word.
2777 * Ignored if task-gate. */
2778 unsigned u16OffsetHigh : 16;
2779 /** Target code segment offset - Top dword.
2780 * Ignored if task-gate. */
2781 unsigned u32OffsetTop : 32;
2782 /** Reserved / ignored / must be zero.
2783 * For call-gates bits 8 thru 12 must be zero, the other gates ignores this. */
2784 unsigned u32Reserved : 32;
2785} X86DESC64GATE;
2786AssertCompileSize(X86DESC64GATE, 16);
2787/** Pointer to a Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
2788typedef X86DESC64GATE *PX86DESC64GATE;
2789/** Pointer to a const Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
2790typedef const X86DESC64GATE *PCX86DESC64GATE;
2791
2792#endif /* VBOX_FOR_DTRACE_LIB */
2793
2794/**
2795 * Descriptor table entry.
2796 */
2797#pragma pack(1)
2798typedef union X86DESC64
2799{
2800#ifndef VBOX_FOR_DTRACE_LIB
2801 /** Generic descriptor view. */
2802 X86DESC64GENERIC Gen;
2803 /** System descriptor view. */
2804 X86DESC64SYSTEM System;
2805 /** Gate descriptor view. */
2806 X86DESC64GATE Gate;
2807#endif
2808
2809 /** 8 bit unsigned integer view. */
2810 uint8_t au8[16];
2811 /** 16 bit unsigned integer view. */
2812 uint16_t au16[8];
2813 /** 32 bit unsigned integer view. */
2814 uint32_t au32[4];
2815 /** 64 bit unsigned integer view. */
2816 uint64_t au64[2];
2817} X86DESC64;
2818#ifndef VBOX_FOR_DTRACE_LIB
2819AssertCompileSize(X86DESC64, 16);
2820#endif
2821#pragma pack()
2822/** Pointer to descriptor table entry. */
2823typedef X86DESC64 *PX86DESC64;
2824/** Pointer to const descriptor table entry. */
2825typedef const X86DESC64 *PCX86DESC64;
2826
2827/** @def X86DESC64_BASE
2828 * Return the base of a 64-bit descriptor.
2829 */
2830#define X86DESC64_BASE(a_pDesc) /*ASM-NOINC*/ \
2831 ( ((uint64_t)((a_pDesc)->Gen.u32BaseHigh3) << 32) \
2832 | ((uint32_t)((a_pDesc)->Gen.u8BaseHigh2) << 24) \
2833 | ( (a_pDesc)->Gen.u8BaseHigh1 << 16) \
2834 | ( (a_pDesc)->Gen.u16BaseLow ) )
2835
2836
2837
2838/** @name Host system descriptor table entry - Use with care!
2839 * @{ */
2840/** Host system descriptor table entry. */
2841#if HC_ARCH_BITS == 64
2842typedef X86DESC64 X86DESCHC;
2843#else
2844typedef X86DESC X86DESCHC;
2845#endif
2846/** Pointer to a host system descriptor table entry. */
2847#if HC_ARCH_BITS == 64
2848typedef PX86DESC64 PX86DESCHC;
2849#else
2850typedef PX86DESC PX86DESCHC;
2851#endif
2852/** Pointer to a const host system descriptor table entry. */
2853#if HC_ARCH_BITS == 64
2854typedef PCX86DESC64 PCX86DESCHC;
2855#else
2856typedef PCX86DESC PCX86DESCHC;
2857#endif
2858/** @} */
2859
2860
2861/** @name Selector Descriptor Types.
2862 * @{
2863 */
2864
2865/** @name Non-System Selector Types.
2866 * @{ */
2867/** Code(=set)/Data(=clear) bit. */
2868#define X86_SEL_TYPE_CODE 8
2869/** Memory(=set)/System(=clear) bit. */
2870#define X86_SEL_TYPE_MEMORY RT_BIT(4)
2871/** Accessed bit. */
2872#define X86_SEL_TYPE_ACCESSED 1
2873/** Expand down bit (for data selectors only). */
2874#define X86_SEL_TYPE_DOWN 4
2875/** Conforming bit (for code selectors only). */
2876#define X86_SEL_TYPE_CONF 4
2877/** Write bit (for data selectors only). */
2878#define X86_SEL_TYPE_WRITE 2
2879/** Read bit (for code selectors only). */
2880#define X86_SEL_TYPE_READ 2
2881/** The bit number of the code segment read bit (relative to u4Type). */
2882#define X86_SEL_TYPE_READ_BIT 1
2883
2884/** Read only selector type. */
2885#define X86_SEL_TYPE_RO 0
2886/** Accessed read only selector type. */
2887#define X86_SEL_TYPE_RO_ACC (0 | X86_SEL_TYPE_ACCESSED)
2888/** Read write selector type. */
2889#define X86_SEL_TYPE_RW 2
2890/** Accessed read write selector type. */
2891#define X86_SEL_TYPE_RW_ACC (2 | X86_SEL_TYPE_ACCESSED)
2892/** Expand down read only selector type. */
2893#define X86_SEL_TYPE_RO_DOWN 4
2894/** Accessed expand down read only selector type. */
2895#define X86_SEL_TYPE_RO_DOWN_ACC (4 | X86_SEL_TYPE_ACCESSED)
2896/** Expand down read write selector type. */
2897#define X86_SEL_TYPE_RW_DOWN 6
2898/** Accessed expand down read write selector type. */
2899#define X86_SEL_TYPE_RW_DOWN_ACC (6 | X86_SEL_TYPE_ACCESSED)
2900/** Execute only selector type. */
2901#define X86_SEL_TYPE_EO (0 | X86_SEL_TYPE_CODE)
2902/** Accessed execute only selector type. */
2903#define X86_SEL_TYPE_EO_ACC (0 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2904/** Execute and read selector type. */
2905#define X86_SEL_TYPE_ER (2 | X86_SEL_TYPE_CODE)
2906/** Accessed execute and read selector type. */
2907#define X86_SEL_TYPE_ER_ACC (2 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2908/** Conforming execute only selector type. */
2909#define X86_SEL_TYPE_EO_CONF (4 | X86_SEL_TYPE_CODE)
2910/** Accessed Conforming execute only selector type. */
2911#define X86_SEL_TYPE_EO_CONF_ACC (4 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2912/** Conforming execute and write selector type. */
2913#define X86_SEL_TYPE_ER_CONF (6 | X86_SEL_TYPE_CODE)
2914/** Accessed Conforming execute and write selector type. */
2915#define X86_SEL_TYPE_ER_CONF_ACC (6 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
2916/** @} */
2917
2918
2919/** @name System Selector Types.
2920 * @{ */
2921/** The TSS busy bit mask. */
2922#define X86_SEL_TYPE_SYS_TSS_BUSY_MASK 2
2923
2924/** Undefined system selector type. */
2925#define X86_SEL_TYPE_SYS_UNDEFINED 0
2926/** 286 TSS selector. */
2927#define X86_SEL_TYPE_SYS_286_TSS_AVAIL 1
2928/** LDT selector. */
2929#define X86_SEL_TYPE_SYS_LDT 2
2930/** 286 TSS selector - Busy. */
2931#define X86_SEL_TYPE_SYS_286_TSS_BUSY 3
2932/** 286 Callgate selector. */
2933#define X86_SEL_TYPE_SYS_286_CALL_GATE 4
2934/** Taskgate selector. */
2935#define X86_SEL_TYPE_SYS_TASK_GATE 5
2936/** 286 Interrupt gate selector. */
2937#define X86_SEL_TYPE_SYS_286_INT_GATE 6
2938/** 286 Trapgate selector. */
2939#define X86_SEL_TYPE_SYS_286_TRAP_GATE 7
2940/** Undefined system selector. */
2941#define X86_SEL_TYPE_SYS_UNDEFINED2 8
2942/** 386 TSS selector. */
2943#define X86_SEL_TYPE_SYS_386_TSS_AVAIL 9
2944/** Undefined system selector. */
2945#define X86_SEL_TYPE_SYS_UNDEFINED3 0xA
2946/** 386 TSS selector - Busy. */
2947#define X86_SEL_TYPE_SYS_386_TSS_BUSY 0xB
2948/** 386 Callgate selector. */
2949#define X86_SEL_TYPE_SYS_386_CALL_GATE 0xC
2950/** Undefined system selector. */
2951#define X86_SEL_TYPE_SYS_UNDEFINED4 0xD
2952/** 386 Interruptgate selector. */
2953#define X86_SEL_TYPE_SYS_386_INT_GATE 0xE
2954/** 386 Trapgate selector. */
2955#define X86_SEL_TYPE_SYS_386_TRAP_GATE 0xF
2956/** @} */
2957
2958/** @name AMD64 System Selector Types.
2959 * @{ */
2960/** LDT selector. */
2961#define AMD64_SEL_TYPE_SYS_LDT 2
2962/** TSS selector - Busy. */
2963#define AMD64_SEL_TYPE_SYS_TSS_AVAIL 9
2964/** TSS selector - Busy. */
2965#define AMD64_SEL_TYPE_SYS_TSS_BUSY 0xB
2966/** Callgate selector. */
2967#define AMD64_SEL_TYPE_SYS_CALL_GATE 0xC
2968/** Interruptgate selector. */
2969#define AMD64_SEL_TYPE_SYS_INT_GATE 0xE
2970/** Trapgate selector. */
2971#define AMD64_SEL_TYPE_SYS_TRAP_GATE 0xF
2972/** @} */
2973
2974/** @} */
2975
2976
2977/** @name Descriptor Table Entry Flag Masks.
2978 * These are for the 2nd 32-bit word of a descriptor.
2979 * @{ */
2980/** Bits 8-11 - TYPE - Descriptor type mask. */
2981#define X86_DESC_TYPE_MASK (RT_BIT(8) | RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
2982/** Bit 12 - S - System (=0) or Code/Data (=1). */
2983#define X86_DESC_S RT_BIT(12)
2984/** Bits 13-14 - DPL - Descriptor Privilege Level. */
2985#define X86_DESC_DPL (RT_BIT(13) | RT_BIT(14))
2986/** Bit 15 - P - Present. */
2987#define X86_DESC_P RT_BIT(15)
2988/** Bit 20 - AVL - Available for system software. */
2989#define X86_DESC_AVL RT_BIT(20)
2990/** Bit 22 - DB - Default operation size. 0 = 16 bit, 1 = 32 bit. */
2991#define X86_DESC_DB RT_BIT(22)
2992/** Bit 23 - G - Granularity of the limit. If set 4KB granularity is
2993 * used, if clear byte. */
2994#define X86_DESC_G RT_BIT(23)
2995/** @} */
2996
2997/** @} */
2998
2999
3000/** @name Task Segments.
3001 * @{
3002 */
3003
3004/**
3005 * 16-bit Task Segment (TSS).
3006 */
3007#pragma pack(1)
3008typedef struct X86TSS16
3009{
3010 /** Back link to previous task. (static) */
3011 RTSEL selPrev;
3012 /** Ring-0 stack pointer. (static) */
3013 uint16_t sp0;
3014 /** Ring-0 stack segment. (static) */
3015 RTSEL ss0;
3016 /** Ring-1 stack pointer. (static) */
3017 uint16_t sp1;
3018 /** Ring-1 stack segment. (static) */
3019 RTSEL ss1;
3020 /** Ring-2 stack pointer. (static) */
3021 uint16_t sp2;
3022 /** Ring-2 stack segment. (static) */
3023 RTSEL ss2;
3024 /** IP before task switch. */
3025 uint16_t ip;
3026 /** FLAGS before task switch. */
3027 uint16_t flags;
3028 /** AX before task switch. */
3029 uint16_t ax;
3030 /** CX before task switch. */
3031 uint16_t cx;
3032 /** DX before task switch. */
3033 uint16_t dx;
3034 /** BX before task switch. */
3035 uint16_t bx;
3036 /** SP before task switch. */
3037 uint16_t sp;
3038 /** BP before task switch. */
3039 uint16_t bp;
3040 /** SI before task switch. */
3041 uint16_t si;
3042 /** DI before task switch. */
3043 uint16_t di;
3044 /** ES before task switch. */
3045 RTSEL es;
3046 /** CS before task switch. */
3047 RTSEL cs;
3048 /** SS before task switch. */
3049 RTSEL ss;
3050 /** DS before task switch. */
3051 RTSEL ds;
3052 /** LDTR before task switch. */
3053 RTSEL selLdt;
3054} X86TSS16;
3055#ifndef VBOX_FOR_DTRACE_LIB
3056AssertCompileSize(X86TSS16, 44);
3057#endif
3058#pragma pack()
3059/** Pointer to a 16-bit task segment. */
3060typedef X86TSS16 *PX86TSS16;
3061/** Pointer to a const 16-bit task segment. */
3062typedef const X86TSS16 *PCX86TSS16;
3063
3064
3065/**
3066 * 32-bit Task Segment (TSS).
3067 */
3068#pragma pack(1)
3069typedef struct X86TSS32
3070{
3071 /** Back link to previous task. (static) */
3072 RTSEL selPrev;
3073 uint16_t padding1;
3074 /** Ring-0 stack pointer. (static) */
3075 uint32_t esp0;
3076 /** Ring-0 stack segment. (static) */
3077 RTSEL ss0;
3078 uint16_t padding_ss0;
3079 /** Ring-1 stack pointer. (static) */
3080 uint32_t esp1;
3081 /** Ring-1 stack segment. (static) */
3082 RTSEL ss1;
3083 uint16_t padding_ss1;
3084 /** Ring-2 stack pointer. (static) */
3085 uint32_t esp2;
3086 /** Ring-2 stack segment. (static) */
3087 RTSEL ss2;
3088 uint16_t padding_ss2;
3089 /** Page directory for the task. (static) */
3090 uint32_t cr3;
3091 /** EIP before task switch. */
3092 uint32_t eip;
3093 /** EFLAGS before task switch. */
3094 uint32_t eflags;
3095 /** EAX before task switch. */
3096 uint32_t eax;
3097 /** ECX before task switch. */
3098 uint32_t ecx;
3099 /** EDX before task switch. */
3100 uint32_t edx;
3101 /** EBX before task switch. */
3102 uint32_t ebx;
3103 /** ESP before task switch. */
3104 uint32_t esp;
3105 /** EBP before task switch. */
3106 uint32_t ebp;
3107 /** ESI before task switch. */
3108 uint32_t esi;
3109 /** EDI before task switch. */
3110 uint32_t edi;
3111 /** ES before task switch. */
3112 RTSEL es;
3113 uint16_t padding_es;
3114 /** CS before task switch. */
3115 RTSEL cs;
3116 uint16_t padding_cs;
3117 /** SS before task switch. */
3118 RTSEL ss;
3119 uint16_t padding_ss;
3120 /** DS before task switch. */
3121 RTSEL ds;
3122 uint16_t padding_ds;
3123 /** FS before task switch. */
3124 RTSEL fs;
3125 uint16_t padding_fs;
3126 /** GS before task switch. */
3127 RTSEL gs;
3128 uint16_t padding_gs;
3129 /** LDTR before task switch. */
3130 RTSEL selLdt;
3131 uint16_t padding_ldt;
3132 /** Debug trap flag */
3133 uint16_t fDebugTrap;
3134 /** Offset relative to the TSS of the start of the I/O Bitmap
3135 * and the end of the interrupt redirection bitmap. */
3136 uint16_t offIoBitmap;
3137 /** 32 bytes for the virtual interrupt redirection bitmap. (VME) */
3138 uint8_t IntRedirBitmap[32];
3139} X86TSS32;
3140#pragma pack()
3141/** Pointer to task segment. */
3142typedef X86TSS32 *PX86TSS32;
3143/** Pointer to const task segment. */
3144typedef const X86TSS32 *PCX86TSS32;
3145
3146
3147/**
3148 * 64-bit Task segment.
3149 */
3150#pragma pack(1)
3151typedef struct X86TSS64
3152{
3153 /** Reserved. */
3154 uint32_t u32Reserved;
3155 /** Ring-0 stack pointer. (static) */
3156 uint64_t rsp0;
3157 /** Ring-1 stack pointer. (static) */
3158 uint64_t rsp1;
3159 /** Ring-2 stack pointer. (static) */
3160 uint64_t rsp2;
3161 /** Reserved. */
3162 uint32_t u32Reserved2[2];
3163 /* IST */
3164 uint64_t ist1;
3165 uint64_t ist2;
3166 uint64_t ist3;
3167 uint64_t ist4;
3168 uint64_t ist5;
3169 uint64_t ist6;
3170 uint64_t ist7;
3171 /* Reserved. */
3172 uint16_t u16Reserved[5];
3173 /** Offset relative to the TSS of the start of the I/O Bitmap
3174 * and the end of the interrupt redirection bitmap. */
3175 uint16_t offIoBitmap;
3176 /** 32 bytes for the virtual interrupt redirection bitmap. (VME) */
3177 uint8_t IntRedirBitmap[32];
3178} X86TSS64;
3179#pragma pack()
3180/** Pointer to a 64-bit task segment. */
3181typedef X86TSS64 *PX86TSS64;
3182/** Pointer to a const 64-bit task segment. */
3183typedef const X86TSS64 *PCX86TSS64;
3184#ifndef VBOX_FOR_DTRACE_LIB
3185AssertCompileSize(X86TSS64, 136);
3186#endif
3187
3188/** @} */
3189
3190
3191/** @name Selectors.
3192 * @{
3193 */
3194
3195/**
3196 * The shift used to convert a selector from and to index an index (C).
3197 */
3198#define X86_SEL_SHIFT 3
3199
3200/**
3201 * The mask used to mask off the table indicator and RPL of an selector.
3202 */
3203#define X86_SEL_MASK 0xfff8U
3204
3205/**
3206 * The mask used to mask off the RPL of an selector.
3207 * This is suitable for checking for NULL selectors.
3208 */
3209#define X86_SEL_MASK_OFF_RPL 0xfffcU
3210
3211/**
3212 * The bit indicating that a selector is in the LDT and not in the GDT.
3213 */
3214#define X86_SEL_LDT 0x0004U
3215
3216/**
3217 * The bit mask for getting the RPL of a selector.
3218 */
3219#define X86_SEL_RPL 0x0003U
3220
3221/**
3222 * The mask covering both RPL and LDT.
3223 * This is incidentally the same as sizeof(X86DESC) - 1, so good for limit
3224 * checks.
3225 */
3226#define X86_SEL_RPL_LDT 0x0007U
3227
3228/** @} */
3229
3230
3231/**
3232 * x86 Exceptions/Faults/Traps.
3233 */
3234typedef enum X86XCPT
3235{
3236 /** \#DE - Divide error. */
3237 X86_XCPT_DE = 0x00,
3238 /** \#DB - Debug event (single step, DRx, ..) */
3239 X86_XCPT_DB = 0x01,
3240 /** NMI - Non-Maskable Interrupt */
3241 X86_XCPT_NMI = 0x02,
3242 /** \#BP - Breakpoint (INT3). */
3243 X86_XCPT_BP = 0x03,
3244 /** \#OF - Overflow (INTO). */
3245 X86_XCPT_OF = 0x04,
3246 /** \#BR - Bound range exceeded (BOUND). */
3247 X86_XCPT_BR = 0x05,
3248 /** \#UD - Undefined opcode. */
3249 X86_XCPT_UD = 0x06,
3250 /** \#NM - Device not available (math coprocessor device). */
3251 X86_XCPT_NM = 0x07,
3252 /** \#DF - Double fault. */
3253 X86_XCPT_DF = 0x08,
3254 /** ??? - Coprocessor segment overrun (obsolete). */
3255 X86_XCPT_CO_SEG_OVERRUN = 0x09,
3256 /** \#TS - Taskswitch (TSS). */
3257 X86_XCPT_TS = 0x0a,
3258 /** \#NP - Segment no present. */
3259 X86_XCPT_NP = 0x0b,
3260 /** \#SS - Stack segment fault. */
3261 X86_XCPT_SS = 0x0c,
3262 /** \#GP - General protection fault. */
3263 X86_XCPT_GP = 0x0d,
3264 /** \#PF - Page fault. */
3265 X86_XCPT_PF = 0x0e,
3266 /* 0x0f is reserved (to avoid conflict with spurious interrupts in BIOS setup). */
3267 /** \#MF - Math fault (FPU). */
3268 X86_XCPT_MF = 0x10,
3269 /** \#AC - Alignment check. */
3270 X86_XCPT_AC = 0x11,
3271 /** \#MC - Machine check. */
3272 X86_XCPT_MC = 0x12,
3273 /** \#XF - SIMD Floating-Pointer Exception. */
3274 X86_XCPT_XF = 0x13,
3275 /** \#VE - Virtualzation Exception. */
3276 X86_XCPT_VE = 0x14,
3277 /** \#SX - Security Exception. */
3278 X86_XCPT_SX = 0x1f
3279} X86XCPT;
3280/** Pointer to a x86 exception code. */
3281typedef X86XCPT *PX86XCPT;
3282/** Pointer to a const x86 exception code. */
3283typedef const X86XCPT *PCX86XCPT;
3284/** The maximum exception value. */
3285#define X86_XCPT_MAX (X86_XCPT_SX)
3286
3287
3288/** @name Trap Error Codes
3289 * @{
3290 */
3291/** External indicator. */
3292#define X86_TRAP_ERR_EXTERNAL 1
3293/** IDT indicator. */
3294#define X86_TRAP_ERR_IDT 2
3295/** Descriptor table indicator - If set LDT, if clear GDT. */
3296#define X86_TRAP_ERR_TI 4
3297/** Mask for getting the selector. */
3298#define X86_TRAP_ERR_SEL_MASK 0xfff8
3299/** Shift for getting the selector table index (C type index). */
3300#define X86_TRAP_ERR_SEL_SHIFT 3
3301/** @} */
3302
3303
3304/** @name \#PF Trap Error Codes
3305 * @{
3306 */
3307/** Bit 0 - P - Not present (clear) or page level protection (set) fault. */
3308#define X86_TRAP_PF_P RT_BIT(0)
3309/** Bit 1 - R/W - Read (clear) or write (set) access. */
3310#define X86_TRAP_PF_RW RT_BIT(1)
3311/** Bit 2 - U/S - CPU executing in user mode (set) or supervisor mode (clear). */
3312#define X86_TRAP_PF_US RT_BIT(2)
3313/** Bit 3 - RSVD- Reserved bit violation (set), i.e. reserved bit was set to 1. */
3314#define X86_TRAP_PF_RSVD RT_BIT(3)
3315/** Bit 4 - I/D - Instruction fetch (set) / Data access (clear) - PAE + NXE. */
3316#define X86_TRAP_PF_ID RT_BIT(4)
3317/** @} */
3318
3319#pragma pack(1)
3320/**
3321 * 16-bit IDTR.
3322 */
3323typedef struct X86IDTR16
3324{
3325 /** Offset. */
3326 uint16_t offSel;
3327 /** Selector. */
3328 uint16_t uSel;
3329} X86IDTR16, *PX86IDTR16;
3330#pragma pack()
3331
3332#pragma pack(1)
3333/**
3334 * 32-bit IDTR/GDTR.
3335 */
3336typedef struct X86XDTR32
3337{
3338 /** Size of the descriptor table. */
3339 uint16_t cb;
3340 /** Address of the descriptor table. */
3341#ifndef VBOX_FOR_DTRACE_LIB
3342 uint32_t uAddr;
3343#else
3344 uint16_t au16Addr[2];
3345#endif
3346} X86XDTR32, *PX86XDTR32;
3347#pragma pack()
3348
3349#pragma pack(1)
3350/**
3351 * 64-bit IDTR/GDTR.
3352 */
3353typedef struct X86XDTR64
3354{
3355 /** Size of the descriptor table. */
3356 uint16_t cb;
3357 /** Address of the descriptor table. */
3358#ifndef VBOX_FOR_DTRACE_LIB
3359 uint64_t uAddr;
3360#else
3361 uint16_t au16Addr[4];
3362#endif
3363} X86XDTR64, *PX86XDTR64;
3364#pragma pack()
3365
3366
3367/** @name ModR/M
3368 * @{ */
3369#define X86_MODRM_RM_MASK UINT8_C(0x07)
3370#define X86_MODRM_REG_MASK UINT8_C(0x38)
3371#define X86_MODRM_REG_SMASK UINT8_C(0x07)
3372#define X86_MODRM_REG_SHIFT 3
3373#define X86_MODRM_MOD_MASK UINT8_C(0xc0)
3374#define X86_MODRM_MOD_SMASK UINT8_C(0x03)
3375#define X86_MODRM_MOD_SHIFT 6
3376#ifndef VBOX_FOR_DTRACE_LIB
3377AssertCompile((X86_MODRM_RM_MASK | X86_MODRM_REG_MASK | X86_MODRM_MOD_MASK) == 0xff);
3378AssertCompile((X86_MODRM_REG_MASK >> X86_MODRM_REG_SHIFT) == X86_MODRM_REG_SMASK);
3379AssertCompile((X86_MODRM_MOD_MASK >> X86_MODRM_MOD_SHIFT) == X86_MODRM_MOD_SMASK);
3380#endif
3381/** @} */
3382
3383/** @name SIB
3384 * @{ */
3385#define X86_SIB_BASE_MASK UINT8_C(0x07)
3386#define X86_SIB_INDEX_MASK UINT8_C(0x38)
3387#define X86_SIB_INDEX_SMASK UINT8_C(0x07)
3388#define X86_SIB_INDEX_SHIFT 3
3389#define X86_SIB_SCALE_MASK UINT8_C(0xc0)
3390#define X86_SIB_SCALE_SMASK UINT8_C(0x03)
3391#define X86_SIB_SCALE_SHIFT 6
3392#ifndef VBOX_FOR_DTRACE_LIB
3393AssertCompile((X86_SIB_BASE_MASK | X86_SIB_INDEX_MASK | X86_SIB_SCALE_MASK) == 0xff);
3394AssertCompile((X86_SIB_INDEX_MASK >> X86_SIB_INDEX_SHIFT) == X86_SIB_INDEX_SMASK);
3395AssertCompile((X86_SIB_SCALE_MASK >> X86_SIB_SCALE_SHIFT) == X86_SIB_SCALE_SMASK);
3396#endif
3397/** @} */
3398
3399/** @name General register indexes
3400 * @{ */
3401#define X86_GREG_xAX 0
3402#define X86_GREG_xCX 1
3403#define X86_GREG_xDX 2
3404#define X86_GREG_xBX 3
3405#define X86_GREG_xSP 4
3406#define X86_GREG_xBP 5
3407#define X86_GREG_xSI 6
3408#define X86_GREG_xDI 7
3409#define X86_GREG_x8 8
3410#define X86_GREG_x9 9
3411#define X86_GREG_x10 10
3412#define X86_GREG_x11 11
3413#define X86_GREG_x12 12
3414#define X86_GREG_x13 13
3415#define X86_GREG_x14 14
3416#define X86_GREG_x15 15
3417/** @} */
3418
3419/** @name X86_SREG_XXX - Segment register indexes.
3420 * @{ */
3421#define X86_SREG_ES 0
3422#define X86_SREG_CS 1
3423#define X86_SREG_SS 2
3424#define X86_SREG_DS 3
3425#define X86_SREG_FS 4
3426#define X86_SREG_GS 5
3427/** @} */
3428/** Segment register count. */
3429#define X86_SREG_COUNT 6
3430
3431
3432/** @name X86_OP_XXX - Prefixes
3433 * @{ */
3434#define X86_OP_PRF_CS UINT8_C(0x2e)
3435#define X86_OP_PRF_SS UINT8_C(0x36)
3436#define X86_OP_PRF_DS UINT8_C(0x3e)
3437#define X86_OP_PRF_ES UINT8_C(0x26)
3438#define X86_OP_PRF_FS UINT8_C(0x64)
3439#define X86_OP_PRF_GS UINT8_C(0x65)
3440#define X86_OP_PRF_SIZE_OP UINT8_C(0x66)
3441#define X86_OP_PRF_SIZE_ADDR UINT8_C(0x67)
3442#define X86_OP_PRF_LOCK UINT8_C(0xf0)
3443#define X86_OP_PRF_REPZ UINT8_C(0xf2)
3444#define X86_OP_PRF_REPNZ UINT8_C(0xf3)
3445#define X86_OP_REX_B UINT8_C(0x41)
3446#define X86_OP_REX_X UINT8_C(0x42)
3447#define X86_OP_REX_R UINT8_C(0x44)
3448#define X86_OP_REX_W UINT8_C(0x48)
3449/** @} */
3450
3451
3452/** @} */
3453
3454#endif
3455
Note: See TracBrowser for help on using the repository browser.

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