VirtualBox

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

Last change on this file since 17616 was 15631, checked in by vboxsync, 16 years ago

Added X86TSS32 & X86TSS64.

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