Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

x86.h

Go to the documentation of this file.
/** @file
 * X86 (and AMD64) Structures and Definitions (VMM,++).
 *
 * x86.mac is generated from this file by running 'kmk incs' in the root.
 */

/*
 * Copyright (C) 2006-2009 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 *
 * The contents of this file may alternatively be used under the terms
 * of the Common Development and Distribution License Version 1.0
 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
 * VirtualBox OSE distribution, in which case the provisions of the
 * CDDL are applicable instead of those of the GPL.
 *
 * You may elect to license modified versions of this file under the
 * terms and conditions of either the GPL or the CDDL or both.
 */

#ifndef ___VBox_x86_h
#define ___VBox_x86_h

#include <VBox/types.h>
#include <iprt/assert.h>

/* Workaround for Solaris sys/regset.h defining CS, DS */
#ifdef RT_OS_SOLARIS
# undef CS
# undef DS
#endif

/** @defgroup grp_x86   x86 Types and Definitions
 * @{
 */

/**
 * EFLAGS Bits.
 */
00047 typedef struct X86EFLAGSBITS
{
    /** Bit 0 - CF - Carry flag - Status flag. */
00050     unsigned    u1CF : 1;
    /** Bit 1 -  1 - Reserved flag. */
00052     unsigned    u1Reserved0 : 1;
    /** Bit 2 - PF - Parity flag - Status flag. */
00054     unsigned    u1PF : 1;
    /** Bit 3 -  0 - Reserved flag. */
00056     unsigned    u1Reserved1 : 1;
    /** Bit 4 - AF - Auxiliary carry flag - Status flag. */
00058     unsigned    u1AF : 1;
    /** Bit 5 -  0 - Reserved flag. */
00060     unsigned    u1Reserved2 : 1;
    /** Bit 6 - ZF - Zero flag - Status flag. */
00062     unsigned    u1ZF : 1;
    /** Bit 7 - SF - Signed flag - Status flag. */
00064     unsigned    u1SF : 1;
    /** Bit 8 - TF - Trap flag - System flag. */
00066     unsigned    u1TF : 1;
    /** Bit 9 - IF - Interrupt flag - System flag. */
00068     unsigned    u1IF : 1;
    /** Bit 10 - DF - Direction flag - Control flag. */
00070     unsigned    u1DF : 1;
    /** Bit 11 - OF - Overflow flag - Status flag. */
00072     unsigned    u1OF : 1;
    /** Bit 12-13 - IOPL - I/O prvilege level flag - System flag. */
00074     unsigned    u2IOPL : 2;
    /** Bit 14 - NT - Nested task flag - System flag. */
00076     unsigned    u1NT : 1;
    /** Bit 15 -  0 - Reserved flag. */
00078     unsigned    u1Reserved3 : 1;
    /** Bit 16 - RF - Resume flag - System flag. */
00080     unsigned    u1RF : 1;
    /** Bit 17 - VM - Virtual 8086 mode - System flag. */
00082     unsigned    u1VM : 1;
    /** Bit 18 - AC - Alignment check flag - System flag. Works with CR0.AM. */
00084     unsigned    u1AC : 1;
    /** Bit 19 - VIF - Virtual interupt flag - System flag. */
00086     unsigned    u1VIF : 1;
    /** Bit 20 - VIP - Virtual interupt pending flag - System flag. */
00088     unsigned    u1VIP : 1;
    /** Bit 21 - ID - CPUID flag - System flag. If this responds to flipping CPUID is supported. */
00090     unsigned    u1ID : 1;
    /** Bit 22-31 - 0 - Reserved flag. */
00092     unsigned    u10Reserved4 : 10;
} X86EFLAGSBITS;
/** Pointer to EFLAGS bits. */
00095 typedef X86EFLAGSBITS *PX86EFLAGSBITS;
/** Pointer to const EFLAGS bits. */
00097 typedef const X86EFLAGSBITS *PCX86EFLAGSBITS;

/**
 * EFLAGS.
 */
00102 typedef union X86EFLAGS
{
    /** The plain unsigned view. */
00105     uint32_t        u;
    /** The bitfield view. */
00107     X86EFLAGSBITS   Bits;
    /** The 8-bit view. */
00109     uint8_t         au8[4];
    /** The 16-bit view. */
00111     uint16_t        au16[2];
    /** The 32-bit view. */
00113     uint32_t        au32[1];
    /** The 32-bit view. */
00115     uint32_t        u32;
} X86EFLAGS;
/** Pointer to EFLAGS. */
00118 typedef X86EFLAGS *PX86EFLAGS;
/** Pointer to const EFLAGS. */
00120 typedef const X86EFLAGS *PCX86EFLAGS;

/**
 * RFLAGS (32 upper bits are reserved).
 */
00125 typedef union X86RFLAGS
{
    /** The plain unsigned view. */
00128     uint64_t        u;
    /** The bitfield view. */
00130     X86EFLAGSBITS   Bits;
    /** The 8-bit view. */
00132     uint8_t         au8[8];
    /** The 16-bit view. */
00134     uint16_t        au16[4];
    /** The 32-bit view. */
00136     uint32_t        au32[2];
    /** The 64-bit view. */
00138     uint64_t        au64[1];
    /** The 64-bit view. */
00140     uint64_t        u64;
} X86RFLAGS;
/** Pointer to RFLAGS. */
00143 typedef X86RFLAGS *PX86RFLAGS;
/** Pointer to const RFLAGS. */
00145 typedef const X86RFLAGS *PCX86RFLAGS;


/** @name EFLAGS
 * @{
 */
/** Bit 0 - CF - Carry flag - Status flag. */
00152 #define X86_EFL_CF          RT_BIT(0)
/** Bit 2 - PF - Parity flag - Status flag. */
00154 #define X86_EFL_PF          RT_BIT(2)
/** Bit 4 - AF - Auxiliary carry flag - Status flag. */
00156 #define X86_EFL_AF          RT_BIT(4)
/** Bit 6 - ZF - Zero flag - Status flag. */
00158 #define X86_EFL_ZF          RT_BIT(6)
/** Bit 7 - SF - Signed flag - Status flag. */
00160 #define X86_EFL_SF          RT_BIT(7)
/** Bit 8 - TF - Trap flag - System flag. */
00162 #define X86_EFL_TF          RT_BIT(8)
/** Bit 9 - IF - Interrupt flag - System flag. */
00164 #define X86_EFL_IF          RT_BIT(9)
/** Bit 10 - DF - Direction flag - Control flag. */
00166 #define X86_EFL_DF          RT_BIT(10)
/** Bit 11 - OF - Overflow flag - Status flag. */
00168 #define X86_EFL_OF          RT_BIT(11)
/** Bit 12-13 - IOPL - I/O prvilege level flag - System flag. */
00170 #define X86_EFL_IOPL        (RT_BIT(12) | RT_BIT(13))
/** Bit 14 - NT - Nested task flag - System flag. */
00172 #define X86_EFL_NT          RT_BIT(14)
/** Bit 16 - RF - Resume flag - System flag. */
00174 #define X86_EFL_RF          RT_BIT(16)
/** Bit 17 - VM - Virtual 8086 mode - System flag. */
00176 #define X86_EFL_VM          RT_BIT(17)
/** Bit 18 - AC - Alignment check flag - System flag. Works with CR0.AM. */
00178 #define X86_EFL_AC          RT_BIT(18)
/** Bit 19 - VIF - Virtual interupt flag - System flag. */
00180 #define X86_EFL_VIF         RT_BIT(19)
/** Bit 20 - VIP - Virtual interupt pending flag - System flag. */
00182 #define X86_EFL_VIP         RT_BIT(20)
/** Bit 21 - ID - CPUID flag - System flag. If this responds to flipping CPUID is supported. */
00184 #define X86_EFL_ID          RT_BIT(21)
/** IOPL shift. */
00186 #define X86_EFL_IOPL_SHIFT  12
/** The the IOPL level from the flags. */
00188 #define X86_EFL_GET_IOPL(efl)   (((efl) >> X86_EFL_IOPL_SHIFT) & 3)
/** Bits restored by popf */
00190 #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 | X86_EFL_DF | X86_EFL_OF | X86_EFL_IOPL | X86_EFL_NT | X86_EFL_AC | X86_EFL_ID)
/** @} */


/** CPUID Feature information - ECX.
 * CPUID query with EAX=1.
 */
00197 typedef struct X86CPUIDFEATECX
{
    /** Bit 0 - SSE3 - Supports SSE3 or not. */
00200     unsigned    u1SSE3 : 1;
    /** Reserved. */
00202     unsigned    u1Reserved1 : 1;
    /** Bit 2 - DS Area 64-bit layout. */
00204     unsigned    u1DTE64 : 1;
    /** Bit 3 - MONITOR - Supports MONITOR/MWAIT. */
00206     unsigned    u1Monitor : 1;
    /** Bit 4 - CPL-DS - CPL Qualified Debug Store. */
00208     unsigned    u1CPLDS : 1;
    /** Bit 5 - VMX - Virtual Machine Technology. */
00210     unsigned    u1VMX : 1;
    /** Bit 6 - SMX: Safer Mode Extensions. */
00212     unsigned    u1SMX : 1;
    /** Bit 7 - EST - Enh. SpeedStep Tech. */
00214     unsigned    u1EST : 1;
    /** Bit 8 - TM2 - Terminal Monitor 2. */
00216     unsigned    u1TM2 : 1;
    /** Bit 9 - SSSE3 - Supplemental Streaming SIMD Extensions 3. */
00218     unsigned    u1SSSE3 : 1;
    /** Bit 10 - CNTX-ID - L1 Context ID. */
00220     unsigned    u1CNTXID : 1;
    /** Bit 11 - FMA. */
00222     unsigned    u1FMA : 1;
    /** Bit 12 - Reserved. */
00224     unsigned    u1Reserved2 : 1;
    /** Bit 13 - CX16 - CMPXCHG16B. */
00226     unsigned    u1CX16 : 1;
    /** Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
00228     unsigned    u1TPRUpdate : 1;
    /** Bit 15 - PDCM - Perf/Debug Capability MSR. */
00230     unsigned    u1PDCM : 1;
    /** Reserved. */
00232     unsigned    u2Reserved3 : 2;
    /** Bit 18 - Direct Cache Access. */
00234     unsigned    u1DCA : 1;
    /** Bit 19 - SSE4_1 - Supports SSE4_1 or not. */
00236     unsigned    u1SSE4_1 : 1;
    /** Bit 20 - SSE4_2 - Supports SSE4_2 or not. */
00238     unsigned    u1SSE4_2 : 1;
    /** Bit 21 - x2APIC. */
00240     unsigned    u1x2APIC : 1;
    /** Bit 22 - MOVBE - Supports MOVBE. */
00242     unsigned    u1MOVBE : 1;
    /** Bit 23 - POPCNT - Supports POPCNT. */
00244     unsigned    u1POPCNT : 1;
    /** Bit 24 - Reserved. */
00246     unsigned    u1Reserved4 : 1;
    /** Bit 25 - AES. */
00248     unsigned    u1AES : 1;
    /** Bit 26 - XSAVE - Supports XSAVE. */
00250     unsigned    u1XSAVE : 1;
    /** Bit 27 - OSXSAVE - Supports OSXSAVE. */
00252     unsigned    u1OSXSAVE : 1;
    /** Reserved. */
00254     unsigned    u4Reserved5 : 4;
} X86CPUIDFEATECX;
/** Pointer to CPUID Feature Information - ECX. */
00257 typedef X86CPUIDFEATECX *PX86CPUIDFEATECX;
/** Pointer to const CPUID Feature Information - ECX. */
00259 typedef const X86CPUIDFEATECX *PCX86CPUIDFEATECX;


/** CPUID Feature Information - EDX.
 * CPUID query with EAX=1.
 */
00265 typedef struct X86CPUIDFEATEDX
{
    /** Bit 0 - FPU - x87 FPU on Chip. */
00268     unsigned    u1FPU : 1;
    /** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
00270     unsigned    u1VME : 1;
    /** Bit 2 - DE - Debugging extensions. */
00272     unsigned    u1DE : 1;
    /** Bit 3 - PSE - Page Size Extension. */
00274     unsigned    u1PSE : 1;
    /** Bit 4 - TSC - Time Stamp Counter. */
00276     unsigned    u1TSC : 1;
    /** Bit 5 - MSR - Model Specific Registers RDMSR and WRMSR Instructions. */
00278     unsigned    u1MSR : 1;
    /** Bit 6 - PAE - Physical Address Extension. */
00280     unsigned    u1PAE : 1;
    /** Bit 7 - MCE - Machine Check Exception. */
00282     unsigned    u1MCE : 1;
    /** Bit 8 - CX8 - CMPXCHG8B instruction. */
00284     unsigned    u1CX8 : 1;
    /** Bit 9 - APIC - APIC On-Chip. */
00286     unsigned    u1APIC : 1;
    /** Bit 10 - Reserved. */
00288     unsigned    u1Reserved1 : 1;
    /** Bit 11 - SEP - SYSENTER and SYSEXIT. */
00290     unsigned    u1SEP : 1;
    /** Bit 12 - MTRR - Memory Type Range Registers. */
00292     unsigned    u1MTRR : 1;
    /** Bit 13 - PGE - PTE Global Bit. */
00294     unsigned    u1PGE : 1;
    /** Bit 14 - MCA - Machine Check Architecture. */
00296     unsigned    u1MCA : 1;
    /** Bit 15 - CMOV - Conditional Move Instructions. */
00298     unsigned    u1CMOV : 1;
    /** Bit 16 - PAT - Page Attribute Table. */
00300     unsigned    u1PAT : 1;
    /** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
00302     unsigned    u1PSE36 : 1;
    /** Bit 18 - PSN - Processor Serial Number. */
00304     unsigned    u1PSN : 1;
    /** Bit 19 - CLFSH - CLFLUSH Instruction. */
00306     unsigned    u1CLFSH : 1;
    /** Bit 20 - Reserved. */
00308     unsigned    u1Reserved2 : 1;
    /** Bit 21 - DS - Debug Store. */
00310     unsigned    u1DS : 1;
    /** Bit 22 - ACPI - Thermal Monitor and Software Controlled Clock Facilities. */
00312     unsigned    u1ACPI : 1;
    /** Bit 23 - MMX - Intel MMX 'Technology'. */
00314     unsigned    u1MMX : 1;
    /** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
00316     unsigned    u1FXSR : 1;
    /** Bit 25 - SSE - SSE Support. */
00318     unsigned    u1SSE : 1;
    /** Bit 26 - SSE2 - SSE2 Support. */
00320     unsigned    u1SSE2 : 1;
    /** Bit 27 - SS - Self Snoop. */
00322     unsigned    u1SS : 1;
    /** Bit 28 - HTT - Hyper-Threading Technology. */
00324     unsigned    u1HTT : 1;
    /** Bit 29 - TM - Thermal Monitor. */
00326     unsigned    u1TM : 1;
    /** Bit 30 - Reserved - . */
00328     unsigned    u1Reserved3 : 1;
    /** Bit 31 - PBE - Pending Break Enabled. */
00330     unsigned    u1PBE : 1;
} X86CPUIDFEATEDX;
/** Pointer to CPUID Feature Information - EDX. */
00333 typedef X86CPUIDFEATEDX *PX86CPUIDFEATEDX;
/** Pointer to const CPUID Feature Information - EDX. */
00335 typedef const X86CPUIDFEATEDX *PCX86CPUIDFEATEDX;

/** @name CPUID Vendor information.
 * CPUID query with EAX=0.
 * @{
 */
#define X86_CPUID_VENDOR_INTEL_EBX      0x756e6547      /* Genu */
#define X86_CPUID_VENDOR_INTEL_ECX      0x6c65746e      /* ntel */
#define X86_CPUID_VENDOR_INTEL_EDX      0x49656e69      /* ineI */

#define X86_CPUID_VENDOR_AMD_EBX        0x68747541      /* Auth */
#define X86_CPUID_VENDOR_AMD_ECX        0x444d4163      /* cAMD */
#define X86_CPUID_VENDOR_AMD_EDX        0x69746e65      /* enti */
/** @} */


/** @name CPUID Feature information.
 * CPUID query with EAX=1.
 * @{
 */
/** ECX Bit 0 - SSE3 - Supports SSE3 or not. */
00356 #define X86_CPUID_FEATURE_ECX_SSE3      RT_BIT(0)
/** ECX Bit 1 - PCLMUL - PCLMULQDQ support (for AES-GCM). */
00358 #define X86_CPUID_FEATURE_ECX_PCLMUL    RT_BIT(1)
/** ECX Bit 2 - DTES64 - DS Area 64-bit Layout. */
00360 #define X86_CPUID_FEATURE_ECX_DTES64    RT_BIT(2)
/** ECX Bit 3 - MONITOR - Supports MONITOR/MWAIT. */
00362 #define X86_CPUID_FEATURE_ECX_MONITOR   RT_BIT(3)
/** ECX Bit 4 - CPL-DS - CPL Qualified Debug Store. */
00364 #define X86_CPUID_FEATURE_ECX_CPLDS     RT_BIT(4)
/** ECX Bit 5 - VMX - Virtual Machine Technology. */
00366 #define X86_CPUID_FEATURE_ECX_VMX       RT_BIT(5)
/** ECX Bit 6 - SMX - Safer Mode Extensions. */
00368 #define X86_CPUID_FEATURE_ECX_SMX       RT_BIT(6)
/** ECX Bit 7 - EST - Enh. SpeedStep Tech. */
00370 #define X86_CPUID_FEATURE_ECX_EST       RT_BIT(7)
/** ECX Bit 8 - TM2 - Terminal Monitor 2. */
00372 #define X86_CPUID_FEATURE_ECX_TM2       RT_BIT(8)
/** ECX Bit 9 - SSSE3 - Supplemental Streaming SIMD Extensions 3. */
00374 #define X86_CPUID_FEATURE_ECX_SSSE3     RT_BIT(9)
/** ECX Bit 10 - CNTX-ID - L1 Context ID. */
00376 #define X86_CPUID_FEATURE_ECX_CNTXID    RT_BIT(10)
/** ECX Bit 12 - FMA. */
00378 #define X86_CPUID_FEATURE_ECX_FMA       RT_BIT(12)
/** ECX Bit 13 - CX16 - CMPXCHG16B. */
00380 #define X86_CPUID_FEATURE_ECX_CX16      RT_BIT(13)
/** ECX Bit 14 - xTPR Update Control. Processor supports changing IA32_MISC_ENABLES[bit 23]. */
00382 #define X86_CPUID_FEATURE_ECX_TPRUPDATE RT_BIT(14)
/** ECX Bit 15 - PDCM - Perf/Debug Capability MSR. */
00384 #define X86_CPUID_FEATURE_ECX_PDCM      RT_BIT(15)
/** ECX Bit 18 - DCA - Direct Cache Access. */
00386 #define X86_CPUID_FEATURE_ECX_DCA       RT_BIT(18)
/** ECX Bit 19 - SSE4_1 - Supports SSE4_1 or not. */
00388 #define X86_CPUID_FEATURE_ECX_SSE4_1    RT_BIT(19)
/** ECX Bit 20 - SSE4_2 - Supports SSE4_2 or not. */
00390 #define X86_CPUID_FEATURE_ECX_SSE4_2    RT_BIT(20)
/** ECX Bit 21 - x2APIC support. */
00392 #define X86_CPUID_FEATURE_ECX_X2APIC    RT_BIT(21)
/** ECX Bit 22 - MOVBE instruction. */
00394 #define X86_CPUID_FEATURE_ECX_MOVBE     RT_BIT(22)
/** ECX Bit 23 - POPCNT instruction. */
00396 #define X86_CPUID_FEATURE_ECX_POPCNT    RT_BIT(23)
/** ECX Bit 25 - AES instructions. */
00398 #define X86_CPUID_FEATURE_ECX_AES       RT_BIT(25)
/** ECX Bit 26 - XSAVE instruction. */
00400 #define X86_CPUID_FEATURE_ECX_XSAVE     RT_BIT(26)
/** ECX Bit 27 - OSXSAVE instruction. */
00402 #define X86_CPUID_FEATURE_ECX_OSXSAVE   RT_BIT(27)
/** ECX Bit 28 - AVX. */
00404 #define X86_CPUID_FEATURE_ECX_AVX       RT_BIT(28)


/** Bit 0 - FPU - x87 FPU on Chip. */
00408 #define X86_CPUID_FEATURE_EDX_FPU       RT_BIT(0)
/** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
00410 #define X86_CPUID_FEATURE_EDX_VME       RT_BIT(1)
/** Bit 2 - DE - Debugging extensions. */
00412 #define X86_CPUID_FEATURE_EDX_DE        RT_BIT(2)
/** Bit 3 - PSE - Page Size Extension. */
00414 #define X86_CPUID_FEATURE_EDX_PSE       RT_BIT(3)
/** Bit 4 - TSC - Time Stamp Counter. */
00416 #define X86_CPUID_FEATURE_EDX_TSC       RT_BIT(4)
/** Bit 5 - MSR - Model Specific Registers RDMSR and WRMSR Instructions. */
00418 #define X86_CPUID_FEATURE_EDX_MSR       RT_BIT(5)
/** Bit 6 - PAE - Physical Address Extension. */
00420 #define X86_CPUID_FEATURE_EDX_PAE       RT_BIT(6)
/** Bit 7 - MCE - Machine Check Exception. */
00422 #define X86_CPUID_FEATURE_EDX_MCE       RT_BIT(7)
/** Bit 8 - CX8 - CMPXCHG8B instruction. */
00424 #define X86_CPUID_FEATURE_EDX_CX8       RT_BIT(8)
/** Bit 9 - APIC - APIC On-Chip. */
00426 #define X86_CPUID_FEATURE_EDX_APIC      RT_BIT(9)
/** Bit 11 - SEP - SYSENTER and SYSEXIT. */
00428 #define X86_CPUID_FEATURE_EDX_SEP       RT_BIT(11)
/** Bit 12 - MTRR - Memory Type Range Registers. */
00430 #define X86_CPUID_FEATURE_EDX_MTRR      RT_BIT(12)
/** Bit 13 - PGE - PTE Global Bit. */
00432 #define X86_CPUID_FEATURE_EDX_PGE       RT_BIT(13)
/** Bit 14 - MCA - Machine Check Architecture. */
00434 #define X86_CPUID_FEATURE_EDX_MCA       RT_BIT(14)
/** Bit 15 - CMOV - Conditional Move Instructions. */
00436 #define X86_CPUID_FEATURE_EDX_CMOV      RT_BIT(15)
/** Bit 16 - PAT - Page Attribute Table. */
00438 #define X86_CPUID_FEATURE_EDX_PAT       RT_BIT(16)
/** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
00440 #define X86_CPUID_FEATURE_EDX_PSE36     RT_BIT(17)
/** Bit 18 - PSN - Processor Serial Number. */
00442 #define X86_CPUID_FEATURE_EDX_PSN       RT_BIT(18)
/** Bit 19 - CLFSH - CLFLUSH Instruction. */
00444 #define X86_CPUID_FEATURE_EDX_CLFSH     RT_BIT(19)
/** Bit 21 - DS - Debug Store. */
00446 #define X86_CPUID_FEATURE_EDX_DS        RT_BIT(21)
/** Bit 22 - ACPI - Termal Monitor and Software Controlled Clock Facilities. */
00448 #define X86_CPUID_FEATURE_EDX_ACPI      RT_BIT(22)
/** Bit 23 - MMX - Intel MMX Technology. */
00450 #define X86_CPUID_FEATURE_EDX_MMX       RT_BIT(23)
/** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
00452 #define X86_CPUID_FEATURE_EDX_FXSR      RT_BIT(24)
/** Bit 25 - SSE - SSE Support. */
00454 #define X86_CPUID_FEATURE_EDX_SSE       RT_BIT(25)
/** Bit 26 - SSE2 - SSE2 Support. */
00456 #define X86_CPUID_FEATURE_EDX_SSE2      RT_BIT(26)
/** Bit 27 - SS - Self Snoop. */
00458 #define X86_CPUID_FEATURE_EDX_SS        RT_BIT(27)
/** Bit 28 - HTT - Hyper-Threading Technology. */
00460 #define X86_CPUID_FEATURE_EDX_HTT       RT_BIT(28)
/** Bit 29 - TM - Therm. Monitor. */
00462 #define X86_CPUID_FEATURE_EDX_TM        RT_BIT(29)
/** Bit 31 - PBE - Pending Break Enabled. */
00464 #define X86_CPUID_FEATURE_EDX_PBE       RT_BIT(31)
/** @} */

/** @name CPUID mwait/monitor information.
 * CPUID query with EAX=5.
 * @{
 */
/** ECX Bit 0 - MWAITEXT - Supports mwait/monitor extensions or not. */
00472 #define X86_CPUID_MWAIT_ECX_EXT            RT_BIT(0)
/** ECX Bit 1 - MWAITBREAK - Break mwait for external interrupt even if EFLAGS.IF=0. */
00474 #define X86_CPUID_MWAIT_ECX_BREAKIRQIF0    RT_BIT(1)
/** @} */


/** @name CPUID AMD Feature information.
 * CPUID query with EAX=0x80000001.
 * @{
 */
/** Bit 0 - FPU - x87 FPU on Chip. */
00483 #define X86_CPUID_AMD_FEATURE_EDX_FPU       RT_BIT(0)
/** Bit 1 - VME - Virtual 8086 Mode Enhancements. */
00485 #define X86_CPUID_AMD_FEATURE_EDX_VME       RT_BIT(1)
/** Bit 2 - DE - Debugging extensions. */
00487 #define X86_CPUID_AMD_FEATURE_EDX_DE        RT_BIT(2)
/** Bit 3 - PSE - Page Size Extension. */
00489 #define X86_CPUID_AMD_FEATURE_EDX_PSE       RT_BIT(3)
/** Bit 4 - TSC - Time Stamp Counter. */
00491 #define X86_CPUID_AMD_FEATURE_EDX_TSC       RT_BIT(4)
/** Bit 5 - MSR - K86 Model Specific Registers RDMSR and WRMSR Instructions. */
00493 #define X86_CPUID_AMD_FEATURE_EDX_MSR       RT_BIT(5)
/** Bit 6 - PAE - Physical Address Extension. */
00495 #define X86_CPUID_AMD_FEATURE_EDX_PAE       RT_BIT(6)
/** Bit 7 - MCE - Machine Check Exception. */
00497 #define X86_CPUID_AMD_FEATURE_EDX_MCE       RT_BIT(7)
/** Bit 8 - CX8 - CMPXCHG8B instruction. */
00499 #define X86_CPUID_AMD_FEATURE_EDX_CX8       RT_BIT(8)
/** Bit 9 - APIC - APIC On-Chip. */
00501 #define X86_CPUID_AMD_FEATURE_EDX_APIC      RT_BIT(9)
/** Bit 11 - SEP - AMD SYSCALL and SYSRET. */
00503 #define X86_CPUID_AMD_FEATURE_EDX_SEP       RT_BIT(11)
/** Bit 12 - MTRR - Memory Type Range Registers. */
00505 #define X86_CPUID_AMD_FEATURE_EDX_MTRR      RT_BIT(12)
/** Bit 13 - PGE - PTE Global Bit. */
00507 #define X86_CPUID_AMD_FEATURE_EDX_PGE       RT_BIT(13)
/** Bit 14 - MCA - Machine Check Architecture. */
00509 #define X86_CPUID_AMD_FEATURE_EDX_MCA       RT_BIT(14)
/** Bit 15 - CMOV - Conditional Move Instructions. */
00511 #define X86_CPUID_AMD_FEATURE_EDX_CMOV      RT_BIT(15)
/** Bit 16 - PAT - Page Attribute Table. */
00513 #define X86_CPUID_AMD_FEATURE_EDX_PAT       RT_BIT(16)
/** Bit 17 - PSE-36 - 36-bit Page Size Extention. */
00515 #define X86_CPUID_AMD_FEATURE_EDX_PSE36     RT_BIT(17)
/** Bit 20 - NX - AMD No-Execute Page Protection. */
00517 #define X86_CPUID_AMD_FEATURE_EDX_NX        RT_BIT(20)
/** Bit 22 - AXMMX - AMD Extensions to MMX Instructions. */
00519 #define X86_CPUID_AMD_FEATURE_EDX_AXMMX     RT_BIT(22)
/** Bit 23 - MMX - Intel MMX Technology. */
00521 #define X86_CPUID_AMD_FEATURE_EDX_MMX       RT_BIT(23)
/** Bit 24 - FXSR - FXSAVE and FXRSTOR Instructions. */
00523 #define X86_CPUID_AMD_FEATURE_EDX_FXSR      RT_BIT(24)
/** Bit 25 - FFXSR - AMD fast FXSAVE and FXRSTOR Instructions. */
00525 #define X86_CPUID_AMD_FEATURE_EDX_FFXSR     RT_BIT(25)
/** Bit 26 - PAGE1GB - AMD 1GB large page support. */
00527 #define X86_CPUID_AMD_FEATURE_EDX_PAGE1GB   RT_BIT(26)
/** Bit 27 - RDTSCP - AMD RDTSCP instruction. */
00529 #define X86_CPUID_AMD_FEATURE_EDX_RDTSCP    RT_BIT(27)
/** Bit 29 - LM - AMD Long Mode. */
00531 #define X86_CPUID_AMD_FEATURE_EDX_LONG_MODE RT_BIT(29)
/** Bit 30 - 3DNOWEXT - AMD Extensions to 3DNow. */
00533 #define X86_CPUID_AMD_FEATURE_EDX_3DNOW_EX  RT_BIT(30)
/** Bit 31 - 3DNOW - AMD 3DNow. */
00535 #define X86_CPUID_AMD_FEATURE_EDX_3DNOW     RT_BIT(31)

/** Bit 0 - LAHF/SAHF - AMD LAHF and SAHF in 64-bit mode. */
00538 #define X86_CPUID_AMD_FEATURE_ECX_LAHF_SAHF RT_BIT(0)
/** Bit 1 - CMPL - Core multi-processing legacy mode. */
00540 #define X86_CPUID_AMD_FEATURE_ECX_CMPL      RT_BIT(1)
/** Bit 2 - SVM - AMD VM extensions. */
00542 #define X86_CPUID_AMD_FEATURE_ECX_SVM       RT_BIT(2)
/** Bit 3 - EXTAPIC - AMD extended APIC registers starting at 0x400. */
00544 #define X86_CPUID_AMD_FEATURE_ECX_EXT_APIC  RT_BIT(3)
/** Bit 4 - CR8L - AMD LOCK MOV CR0 means MOV CR8. */
00546 #define X86_CPUID_AMD_FEATURE_ECX_CR8L      RT_BIT(4)
/** Bit 5 - ABM - AMD Advanced bit manipulation. LZCNT instruction support. */
00548 #define X86_CPUID_AMD_FEATURE_ECX_ABM       RT_BIT(5)
/** Bit 6 - SSE4A - AMD EXTRQ, INSERTQ, MOVNTSS, and MOVNTSD instruction support. */
00550 #define X86_CPUID_AMD_FEATURE_ECX_SSE4A     RT_BIT(6)
/** Bit 7 - MISALIGNSSE - AMD Misaligned SSE mode. */
00552 #define X86_CPUID_AMD_FEATURE_ECX_MISALNSSE RT_BIT(7)
/** Bit 8 - 3DNOWPRF - AMD PREFETCH and PREFETCHW instruction support. */
00554 #define X86_CPUID_AMD_FEATURE_ECX_3DNOWPRF  RT_BIT(8)
/** Bit 9 - OSVW - AMD OS visible workaround. */
00556 #define X86_CPUID_AMD_FEATURE_ECX_OSVW      RT_BIT(9)
/** Bit 10 - IBS - Instruct based sampling. */
00558 #define X86_CPUID_AMD_FEATURE_ECX_IBS       RT_BIT(10)
/** Bit 11 - SSE5 - SSE5 instruction support. */
00560 #define X86_CPUID_AMD_FEATURE_ECX_SSE5      RT_BIT(11)
/** Bit 12 - SKINIT - AMD SKINIT: SKINIT, STGI, and DEV support. */
00562 #define X86_CPUID_AMD_FEATURE_ECX_SKINIT    RT_BIT(12)
/** Bit 13 - WDT - AMD Watchdog timer support. */
00564 #define X86_CPUID_AMD_FEATURE_ECX_WDT       RT_BIT(13)

/** @} */


/** @name CPUID AMD Feature information.
 * CPUID query with EAX=0x80000007.
 * @{
 */
/** Bit 0 - TS - Temperature Sensor. */
00574 #define X86_CPUID_AMD_ADVPOWER_EDX_TS        RT_BIT(0)
/** Bit 1 - FID - Frequency ID Control. */
00576 #define X86_CPUID_AMD_ADVPOWER_EDX_FID       RT_BIT(1)
/** Bit 2 - VID - Voltage ID Control. */
00578 #define X86_CPUID_AMD_ADVPOWER_EDX_VID       RT_BIT(2)
/** Bit 3 - TTP - THERMTRIP. */
00580 #define X86_CPUID_AMD_ADVPOWER_EDX_TTP       RT_BIT(3)
/** Bit 4 - TM - Hardware Thermal Control. */
00582 #define X86_CPUID_AMD_ADVPOWER_EDX_TM        RT_BIT(4)
/** Bit 5 - STC - Software Thermal Control. */
00584 #define X86_CPUID_AMD_ADVPOWER_EDX_STC       RT_BIT(5)
/** Bit 6 - MC - 100 Mhz Multiplier Control. */
00586 #define X86_CPUID_AMD_ADVPOWER_EDX_MC        RT_BIT(6)
/** Bit 7 - HWPSTATE - Hardware P-State Control. */
00588 #define X86_CPUID_AMD_ADVPOWER_EDX_HWPSTATE  RT_BIT(7)
/** Bit 8 - TSCINVAR - TSC Invariant. */
00590 #define X86_CPUID_AMD_ADVPOWER_EDX_TSCINVAR  RT_BIT(8)
/** @} */


/** @name CR0
 * @{ */
/** Bit 0 - PE - Protection Enabled */
00597 #define X86_CR0_PE                          RT_BIT(0)
#define X86_CR0_PROTECTION_ENABLE           RT_BIT(0)
/** Bit 1 - MP - Monitor Coprocessor */
00600 #define X86_CR0_MP                          RT_BIT(1)
#define X86_CR0_MONITOR_COPROCESSOR         RT_BIT(1)
/** Bit 2 - EM - Emulation. */
00603 #define X86_CR0_EM                          RT_BIT(2)
#define X86_CR0_EMULATE_FPU                 RT_BIT(2)
/** Bit 3 - TS - Task Switch. */
00606 #define X86_CR0_TS                          RT_BIT(3)
#define X86_CR0_TASK_SWITCH                 RT_BIT(3)
/** Bit 4 - ET - Extension flag. ('hardcoded' to 1) */
00609 #define X86_CR0_ET                          RT_BIT(4)
#define X86_CR0_EXTENSION_TYPE              RT_BIT(4)
/** Bit 5 - NE - Numeric error. */
00612 #define X86_CR0_NE                          RT_BIT(5)
#define X86_CR0_NUMERIC_ERROR               RT_BIT(5)
/** Bit 16 - WP - Write Protect. */
00615 #define X86_CR0_WP                          RT_BIT(16)
#define X86_CR0_WRITE_PROTECT               RT_BIT(16)
/** Bit 18 - AM - Alignment Mask. */
00618 #define X86_CR0_AM                          RT_BIT(18)
#define X86_CR0_ALIGMENT_MASK               RT_BIT(18)
/** Bit 29 - NW - Not Write-though. */
00621 #define X86_CR0_NW                          RT_BIT(29)
#define X86_CR0_NOT_WRITE_THROUGH           RT_BIT(29)
/** Bit 30 - WP - Cache Disable. */
00624 #define X86_CR0_CD                          RT_BIT(30)
#define X86_CR0_CACHE_DISABLE               RT_BIT(30)
/** Bit 31 - PG - Paging. */
00627 #define X86_CR0_PG                          RT_BIT(31)
#define X86_CR0_PAGING                      RT_BIT(31)
/** @} */


/** @name CR3
 * @{ */
/** Bit 3 - PWT - Page-level Writes Transparent. */
00635 #define X86_CR3_PWT                         RT_BIT(3)
/** Bit 4 - PCD - Page-level Cache Disable. */
00637 #define X86_CR3_PCD                         RT_BIT(4)
/** Bits 12-31 - - Page directory page number. */
00639 #define X86_CR3_PAGE_MASK                   (0xfffff000)
/** Bits  5-31 - - PAE Page directory page number. */
00641 #define X86_CR3_PAE_PAGE_MASK               (0xffffffe0)
/** Bits 12-51 - - AMD64 Page directory page number. */
00643 #define X86_CR3_AMD64_PAGE_MASK             UINT64_C(0x000ffffffffff000)
/** @} */


/** @name CR4
 * @{ */
/** Bit 0 - VME - Virtual-8086 Mode Extensions. */
00650 #define X86_CR4_VME                         RT_BIT(0)
/** Bit 1 - PVI - Protected-Mode Virtual Interrupts. */
00652 #define X86_CR4_PVI                         RT_BIT(1)
/** Bit 2 - TSD - Time Stamp Disable. */
00654 #define X86_CR4_TSD                         RT_BIT(2)
/** Bit 3 - DE - Debugging Extensions. */
00656 #define X86_CR4_DE                          RT_BIT(3)
/** Bit 4 - PSE - Page Size Extension. */
00658 #define X86_CR4_PSE                         RT_BIT(4)
/** Bit 5 - PAE - Physical Address Extension. */
00660 #define X86_CR4_PAE                         RT_BIT(5)
/** Bit 6 - MCE - Machine-Check Enable. */
00662 #define X86_CR4_MCE                         RT_BIT(6)
/** Bit 7 - PGE - Page Global Enable. */
00664 #define X86_CR4_PGE                         RT_BIT(7)
/** Bit 8 - PCE - Performance-Monitoring Counter Enable. */
00666 #define X86_CR4_PCE                         RT_BIT(8)
/** Bit 9 - OSFSXR - Operating System Support for FXSAVE and FXRSTORE instruction. */
00668 #define X86_CR4_OSFSXR                      RT_BIT(9)
/** Bit 10 - OSXMMEEXCPT - Operating System Support for Unmasked SIMD Floating-Point Exceptions. */
00670 #define X86_CR4_OSXMMEEXCPT                 RT_BIT(10)
/** Bit 13 - VMXE - VMX mode is enabled. */
00672 #define X86_CR4_VMXE                        RT_BIT(13)
/** @} */


/** @name DR6
 * @{ */
/** Bit 0 - B0 - Breakpoint 0 condition detected. */
00679 #define X86_DR6_B0                          RT_BIT(0)
/** Bit 1 - B1 - Breakpoint 1 condition detected. */
00681 #define X86_DR6_B1                          RT_BIT(1)
/** Bit 2 - B2 - Breakpoint 2 condition detected. */
00683 #define X86_DR6_B2                          RT_BIT(2)
/** Bit 3 - B3 - Breakpoint 3 condition detected. */
00685 #define X86_DR6_B3                          RT_BIT(3)
/** Bit 13 - BD - Debug register access detected. Corresponds to the X86_DR7_GD bit. */
00687 #define X86_DR6_BD                          RT_BIT(13)
/** Bit 14 - BS - Single step */
00689 #define X86_DR6_BS                          RT_BIT(14)
/** Bit 15 - BT - Task switch. (TSS T bit.) */
00691 #define X86_DR6_BT                          RT_BIT(15)
/** Value of DR6 after powerup/reset. */
00693 #define X86_DR6_INIT_VAL                    UINT64_C(0xFFFF0FF0)
/** @} */


/** @name DR7
 * @{ */
/** Bit 0 - L0 - Local breakpoint enable. Cleared on task switch. */
00700 #define X86_DR7_L0                          RT_BIT(0)
/** Bit 1 - G0 - Global breakpoint enable. Not cleared on task switch. */
00702 #define X86_DR7_G0                          RT_BIT(1)
/** Bit 2 - L1 - Local breakpoint enable. Cleared on task switch. */
00704 #define X86_DR7_L1                          RT_BIT(2)
/** Bit 3 - G1 - Global breakpoint enable. Not cleared on task switch. */
00706 #define X86_DR7_G1                          RT_BIT(3)
/** Bit 4 - L2 - Local breakpoint enable. Cleared on task switch. */
00708 #define X86_DR7_L2                          RT_BIT(4)
/** Bit 5 - G2 - Global breakpoint enable. Not cleared on task switch. */
00710 #define X86_DR7_G2                          RT_BIT(5)
/** Bit 6 - L3 - Local breakpoint enable. Cleared on task switch. */
00712 #define X86_DR7_L3                          RT_BIT(6)
/** Bit 7 - G3 - Global breakpoint enable. Not cleared on task switch. */
00714 #define X86_DR7_G3                          RT_BIT(7)
/** Bit 8 - LE - Local breakpoint exact. (Not supported (read ignored) by P6 and later.) */
00716 #define X86_DR7_LE                          RT_BIT(8)
/** Bit 9 - GE - Local breakpoint exact. (Not supported (read ignored) by P6 and later.) */
00718 #define X86_DR7_GE                          RT_BIT(9)

/** Bit 13 - GD - General detect enable. Enables emulators to get exceptions when
 * any DR register is accessed. */
00722 #define X86_DR7_GD                          RT_BIT(13)
/** Bit 16 & 17 - R/W0 - Read write field 0. Values X86_DR7_RW_*. */
00724 #define X86_DR7_RW0_MASK                    (3 << 16)
/** Bit 18 & 19 - LEN0 - Length field 0. Values X86_DR7_LEN_*. */
00726 #define X86_DR7_LEN0_MASK                   (3 << 18)
/** Bit 20 & 21 - R/W1 - Read write field 0. Values X86_DR7_RW_*. */
00728 #define X86_DR7_RW1_MASK                    (3 << 20)
/** Bit 22 & 23 - LEN1 - Length field 0. Values X86_DR7_LEN_*. */
00730 #define X86_DR7_LEN1_MASK                   (3 << 22)
/** Bit 24 & 25 - R/W2 - Read write field 0. Values X86_DR7_RW_*. */
00732 #define X86_DR7_RW2_MASK                    (3 << 24)
/** Bit 26 & 27 - LEN2 - Length field 0. Values X86_DR7_LEN_*. */
00734 #define X86_DR7_LEN2_MASK                   (3 << 26)
/** Bit 28 & 29 - R/W3 - Read write field 0. Values X86_DR7_RW_*. */
00736 #define X86_DR7_RW3_MASK                    (3 << 28)
/** Bit 30 & 31 - LEN3 - Length field 0. Values X86_DR7_LEN_*. */
00738 #define X86_DR7_LEN3_MASK                   (3 << 30)

/** Bits which must be 1s. */
00741 #define X86_DR7_MB1_MASK                    (RT_BIT(10))

/** Calcs the L bit of Nth breakpoint.
 * @param   iBp     The breakpoint number [0..3].
 */
00746 #define X86_DR7_L(iBp)                      ( UINT32_C(1) << (iBp * 2) )

/** Calcs the G bit of Nth breakpoint.
 * @param   iBp     The breakpoint number [0..3].
 */
00751 #define X86_DR7_G(iBp)                      ( UINT32_C(1) << (iBp * 2 + 1) )

/** @name Read/Write values.
 * @{ */
/** Break on instruction fetch only. */
00756 #define X86_DR7_RW_EO                       0U
/** Break on write only. */
00758 #define X86_DR7_RW_WO                       1U
/** Break on I/O read/write. This is only defined if CR4.DE is set. */
00760 #define X86_DR7_RW_IO                       2U
/** Break on read or write (but not instruction fetches). */
00762 #define X86_DR7_RW_RW                       3U
/** @} */

/** Shifts a X86_DR7_RW_* value to its right place.
 * @param   iBp     The breakpoint number [0..3].
 * @param   fRw     One of the X86_DR7_RW_* value.
 */
00769 #define X86_DR7_RW(iBp, fRw)                ( (fRw) << ((iBp) * 4 + 16) )

/** @name Length values.
 * @{ */
#define X86_DR7_LEN_BYTE                    0U
#define X86_DR7_LEN_WORD                    1U
00775 #define X86_DR7_LEN_QWORD                   2U /**< AMD64 long mode only. */
#define X86_DR7_LEN_DWORD                   3U
/** @} */

/** Shifts a X86_DR7_LEN_* value to its right place.
 * @param   iBp     The breakpoint number [0..3].
 * @param   cb      One of the X86_DR7_LEN_* values.
 */
00783 #define X86_DR7_LEN(iBp, cb)                ( (cb) << ((iBp) * 4 + 18) )

/** Fetch the breakpoint length bits from the DR7 value.
 * @param   uDR7    DR7 value
 * @param   iBp     The breakpoint number [0..3].
 */
00789 #define X86_DR7_GET_LEN(uDR7, iBp)          ( ( (uDR7) >> ((iBp) * 4 + 18) ) & 0x3U)

/** Mask used to check if any breakpoints are enabled. */
00792 #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))

/** Mask used to check if any io breakpoints are set. */
00795 #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))

/** Value of DR7 after powerup/reset. */
00798 #define X86_DR7_INIT_VAL                    0x400
/** @} */


/** @name Machine Specific Registers
 * @{
 */

/** Time Stamp Counter. */
00807 #define MSR_IA32_TSC                        0x10

#define MSR_IA32_PLATFORM_ID                0x17

#ifndef MSR_IA32_APICBASE /* qemu cpu.h klugde */
#define MSR_IA32_APICBASE                   0x1b
#endif

/** CPU Feature control. */
00816 #define MSR_IA32_FEATURE_CONTROL            0x3A
#define MSR_IA32_FEATURE_CONTROL_LOCK       RT_BIT(0)
#define MSR_IA32_FEATURE_CONTROL_VMXON      RT_BIT(2)

/** BIOS update trigger (microcode update). */
00821 #define MSR_IA32_BIOS_UPDT_TRIG             0x79

/** BIOS update signature (microcode). */
00824 #define MSR_IA32_BIOS_SIGN_ID               0x8B

/** General performance counter no. 0. */
00827 #define MSR_IA32_PMC0                       0xC1
/** General performance counter no. 1. */
00829 #define MSR_IA32_PMC1                       0xC2
/** General performance counter no. 2. */
00831 #define MSR_IA32_PMC2                       0xC3
/** General performance counter no. 3. */
00833 #define MSR_IA32_PMC3                       0xC4

/** Nehalem power control. */
00836 #define MSR_IA32_PLATFORM_INFO              0xCE

/** Get FSB clock status (Intel-specific). */
00839 #define MSR_IA32_FSB_CLOCK_STS              0xCD

/** MTRR Capabilities. */
00842 #define MSR_IA32_MTRR_CAP                   0xFE


#ifndef MSR_IA32_SYSENTER_CS /* qemu cpu.h klugde */
/** SYSENTER_CS - the R0 CS, indirectly giving R0 SS, R3 CS and R3 DS.
 * R0 SS == CS + 8
 * R3 CS == CS + 16
 * R3 SS == CS + 24
 */
00851 #define MSR_IA32_SYSENTER_CS                0x174
/** SYSENTER_ESP - the R0 ESP. */
00853 #define MSR_IA32_SYSENTER_ESP               0x175
/** SYSENTER_EIP - the R0 EIP. */
00855 #define MSR_IA32_SYSENTER_EIP               0x176
#endif

/** Machine Check Global Capabilities Register. */
00859 #define MSR_IA32_MCP_CAP                    0x179
/** Machine Check Global Status Register. */
00861 #define MSR_IA32_MCP_STATUS                 0x17A
/** Machine Check Global Control Register. */
00863 #define MSR_IA32_MCP_CTRL                   0x17B

/** Trace/Profile Resource Control (R/W) */
00866 #define MSR_IA32_DEBUGCTL                   0x1D9

/* Page Attribute Table. */
#define MSR_IA32_CR_PAT                     0x277

/** Performance counter MSRs. (Intel only) */
00872 #define MSR_IA32_PERFEVTSEL0                0x186
#define MSR_IA32_PERFEVTSEL1                0x187
#define MSR_IA32_FLEX_RATIO                 0x194
#define MSR_IA32_PERF_STATUS                0x198
#define MSR_IA32_PERF_CTL                   0x199
#define MSR_IA32_THERM_STATUS               0x19c

/** Enable misc. processor features (R/W). */
00880 #define MSR_IA32_MISC_ENABLE                0x1A0

/** MTRR Default Range. */
00883 #define MSR_IA32_MTRR_DEF_TYPE              0x2FF

#define MSR_IA32_MC0_CTL                    0x400
#define MSR_IA32_MC0_STATUS                 0x401

/** Basic VMX information. */
00889 #define MSR_IA32_VMX_BASIC_INFO             0x480
/** Allowed settings for pin-based VM execution controls */
00891 #define MSR_IA32_VMX_PINBASED_CTLS          0x481
/** Allowed settings for proc-based VM execution controls */
00893 #define MSR_IA32_VMX_PROCBASED_CTLS         0x482
/** Allowed settings for the VMX exit controls. */
00895 #define MSR_IA32_VMX_EXIT_CTLS              0x483
/** Allowed settings for the VMX entry controls. */
00897 #define MSR_IA32_VMX_ENTRY_CTLS             0x484
/** Misc VMX info. */
00899 #define MSR_IA32_VMX_MISC                   0x485
/** Fixed cleared bits in CR0. */
00901 #define MSR_IA32_VMX_CR0_FIXED0             0x486
/** Fixed set bits in CR0. */
00903 #define MSR_IA32_VMX_CR0_FIXED1             0x487
/** Fixed cleared bits in CR4. */
00905 #define MSR_IA32_VMX_CR4_FIXED0             0x488
/** Fixed set bits in CR4. */
00907 #define MSR_IA32_VMX_CR4_FIXED1             0x489
/** Information for enumerating fields in the VMCS. */
00909 #define MSR_IA32_VMX_VMCS_ENUM              0x48A
/** Allowed settings for secondary proc-based VM execution controls */
00911 #define MSR_IA32_VMX_PROCBASED_CTLS2        0x48B
/** EPT capabilities. */
00913 #define MSR_IA32_VMX_EPT_CAPS               0x48C
/** DS Save Area (R/W). */
00915 #define MSR_IA32_DS_AREA                    0x600
/** X2APIC MSR ranges. */
00917 #define MSR_IA32_APIC_START                 0x800
#define MSR_IA32_APIC_END                   0x900

/** K6 EFER - Extended Feature Enable Register. */
00921 #define MSR_K6_EFER                         0xc0000080
/** @todo document EFER */
/** Bit 0 - SCE - System call extensions (SYSCALL / SYSRET). (R/W) */
00924 #define  MSR_K6_EFER_SCE                     RT_BIT(0)
/** Bit 8 - LME - Long mode enabled. (R/W) */
00926 #define  MSR_K6_EFER_LME                     RT_BIT(8)
/** Bit 10 - LMA - Long mode active. (R) */
00928 #define  MSR_K6_EFER_LMA                     RT_BIT(10)
/** Bit 11 - NXE - No-Execute Page Protection Enabled. (R/W) */
00930 #define  MSR_K6_EFER_NXE                     RT_BIT(11)
/** Bit 12 - SVME - Secure VM Extension Enabled. (R/W) */
00932 #define  MSR_K6_EFER_SVME                    RT_BIT(12)
/** Bit 13 - LMSLE - Long Mode Segment Limit Enable. (R/W?) */
00934 #define  MSR_K6_EFER_LMSLE                   RT_BIT(13)
/** Bit 14 - FFXSR - Fast FXSAVE / FXRSTOR (skip XMM*). (R/W) */
00936 #define  MSR_K6_EFER_FFXSR                   RT_BIT(14)
/** K6 STAR - SYSCALL/RET targets. */
00938 #define MSR_K6_STAR                         0xc0000081
/** Shift value for getting the SYSRET CS and SS value. */
00940 #define  MSR_K6_STAR_SYSRET_CS_SS_SHIFT     48
/** Shift value for getting the SYSCALL CS and SS value. */
00942 #define  MSR_K6_STAR_SYSCALL_CS_SS_SHIFT    32
/** Selector mask for use after shifting. */
00944 #define  MSR_K6_STAR_SEL_MASK               0xffff
/** The mask which give the SYSCALL EIP. */
00946 #define  MSR_K6_STAR_SYSCALL_EIP_MASK       0xffffffff
/** K6 WHCR - Write Handling Control Register. */
00948 #define MSR_K6_WHCR                         0xc0000082
/** K6 UWCCR - UC/WC Cacheability Control Register. */
00950 #define MSR_K6_UWCCR                        0xc0000085
/** K6 PSOR - Processor State Observability Register. */
00952 #define MSR_K6_PSOR                         0xc0000087
/** K6 PFIR - Page Flush/Invalidate Register. */
00954 #define MSR_K6_PFIR                         0xc0000088

/** Performance counter MSRs. (AMD only) */
00957 #define MSR_K7_EVNTSEL0                     0xc0010000
#define MSR_K7_EVNTSEL1                     0xc0010001
#define MSR_K7_EVNTSEL2                     0xc0010002
#define MSR_K7_EVNTSEL3                     0xc0010003
#define MSR_K7_PERFCTR0                     0xc0010004
#define MSR_K7_PERFCTR1                     0xc0010005
#define MSR_K7_PERFCTR2                     0xc0010006
#define MSR_K7_PERFCTR3                     0xc0010007

#define MSR_K8_HWCR                         0xc0010015

/** K8 LSTAR - Long mode SYSCALL target (RIP). */
00969 #define MSR_K8_LSTAR                        0xc0000082
/** K8 CSTAR - Compatibility mode SYSCALL target (RIP). */
00971 #define MSR_K8_CSTAR                        0xc0000083
/** K8 SF_MASK - SYSCALL flag mask. (aka SFMASK) */
00973 #define MSR_K8_SF_MASK                      0xc0000084
/** K8 FS.base - The 64-bit base FS register. */
00975 #define MSR_K8_FS_BASE                      0xc0000100
/** K8 GS.base - The 64-bit base GS register. */
00977 #define MSR_K8_GS_BASE                      0xc0000101
/** K8 KernelGSbase - Used with SWAPGS. */
00979 #define MSR_K8_KERNEL_GS_BASE               0xc0000102
#define MSR_K8_TSC_AUX                      0xc0000103
#define MSR_K8_SYSCFG                       0xc0010010
#define MSR_K8_HWCR                         0xc0010015
#define MSR_K8_IORRBASE0                    0xc0010016
#define MSR_K8_IORRMASK0                    0xc0010017
#define MSR_K8_IORRBASE1                    0xc0010018
#define MSR_K8_IORRMASK1                    0xc0010019
#define MSR_K8_TOP_MEM1                     0xc001001a
#define MSR_K8_TOP_MEM2                     0xc001001d
#define MSR_K8_VM_CR                        0xc0010114
#define MSR_K8_VM_CR_SVM_DISABLE            RT_BIT(4)

#define MSR_K8_IGNNE                        0xc0010115
#define MSR_K8_SMM_CTL                      0xc0010116
/** SVM - VM_HSAVE_PA - Physical address for saving and restoring
 *                      host state during world switch.
 */
00997 #define MSR_K8_VM_HSAVE_PA                  0xc0010117

/** @} */


/** @name Page Table / Directory / Directory Pointers / L4.
 * @{
 */

/** Page table/directory  entry as an unsigned integer. */
01007 typedef uint32_t X86PGUINT;
/** Pointer to a page table/directory table entry as an unsigned integer. */
01009 typedef X86PGUINT *PX86PGUINT;
/** Pointer to an const page table/directory table entry as an unsigned integer. */
01011 typedef X86PGUINT const *PCX86PGUINT;

/** Number of entries in a 32-bit PT/PD. */
01014 #define X86_PG_ENTRIES                      1024


/** PAE page table/page directory/pdpt/l4/l5 entry as an unsigned integer. */
01018 typedef uint64_t X86PGPAEUINT;
/** Pointer to a PAE page table/page directory/pdpt/l4/l5 entry as an unsigned integer. */
01020 typedef X86PGPAEUINT *PX86PGPAEUINT;
/** Pointer to an const PAE page table/page directory/pdpt/l4/l5 entry as an unsigned integer. */
01022 typedef X86PGPAEUINT const *PCX86PGPAEUINT;

/** Number of entries in a PAE PT/PD. */
01025 #define X86_PG_PAE_ENTRIES                  512
/** Number of entries in a PAE PDPT. */
01027 #define X86_PG_PAE_PDPE_ENTRIES             4

/** Number of entries in an AMD64 PT/PD/PDPT/L4/L5. */
01030 #define X86_PG_AMD64_ENTRIES                X86_PG_PAE_ENTRIES
/** Number of entries in an AMD64 PDPT.
 * Just for complementing X86_PG_PAE_PDPE_ENTRIES, using X86_PG_AMD64_ENTRIES for this is fine too. */
01033 #define X86_PG_AMD64_PDPE_ENTRIES           X86_PG_AMD64_ENTRIES

/** The size of a 4KB page. */
01036 #define X86_PAGE_4K_SIZE                    _4K
/** The page shift of a 4KB page. */
01038 #define X86_PAGE_4K_SHIFT                   12
/** The 4KB page offset mask. */
01040 #define X86_PAGE_4K_OFFSET_MASK             0xfff
/** The 4KB page base mask for virtual addresses. */
01042 #define X86_PAGE_4K_BASE_MASK               0xfffffffffffff000ULL
/** The 4KB page base mask for virtual addresses - 32bit version. */
01044 #define X86_PAGE_4K_BASE_MASK_32            0xfffff000U

/** The size of a 2MB page. */
01047 #define X86_PAGE_2M_SIZE                    _2M
/** The page shift of a 2MB page. */
01049 #define X86_PAGE_2M_SHIFT                   21
/** The 2MB page offset mask. */
01051 #define X86_PAGE_2M_OFFSET_MASK             0x001fffff
/** The 2MB page base mask for virtual addresses. */
01053 #define X86_PAGE_2M_BASE_MASK               0xffffffffffe00000ULL
/** The 2MB page base mask for virtual addresses - 32bit version. */
01055 #define X86_PAGE_2M_BASE_MASK_32            0xffe00000U

/** The size of a 4MB page. */
01058 #define X86_PAGE_4M_SIZE                    _4M
/** The page shift of a 4MB page. */
01060 #define X86_PAGE_4M_SHIFT                   22
/** The 4MB page offset mask. */
01062 #define X86_PAGE_4M_OFFSET_MASK             0x003fffff
/** The 4MB page base mask for virtual addresses. */
01064 #define X86_PAGE_4M_BASE_MASK               0xffffffffffc00000ULL
/** The 4MB page base mask for virtual addresses - 32bit version. */
01066 #define X86_PAGE_4M_BASE_MASK_32            0xffc00000U



/** @name Page Table Entry
 * @{
 */
/** Bit 0 -  P  - Present bit. */
01074 #define X86_PTE_BIT_P                       0
/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
01076 #define X86_PTE_BIT_RW                      1
/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
01078 #define X86_PTE_BIT_US                      2
/** Bit 3 - PWT - Page level write thru bit. */
01080 #define X86_PTE_BIT_PWT                     3
/** Bit 4 - PCD - Page level cache disable bit. */
01082 #define X86_PTE_BIT_PCD                     4
/** Bit 5 -  A  - Access bit. */
01084 #define X86_PTE_BIT_A                       5
/** Bit 6 -  D  - Dirty bit. */
01086 #define X86_PTE_BIT_D                       6
/** Bit 7 - PAT - Page Attribute Table index bit. Reserved and 0 if not supported. */
01088 #define X86_PTE_BIT_PAT                     7
/** Bit 8 -  G  - Global flag. */
01090 #define X86_PTE_BIT_G                       8

/** Bit 0 -  P  - Present bit mask. */
01093 #define X86_PTE_P                           RT_BIT(0)
/** Bit 1 - R/W - Read (clear) / Write (set) bit mask. */
01095 #define X86_PTE_RW                          RT_BIT(1)
/** Bit 2 - U/S - User (set) / Supervisor (clear) bit mask. */
01097 #define X86_PTE_US                          RT_BIT(2)
/** Bit 3 - PWT - Page level write thru bit mask. */
01099 #define X86_PTE_PWT                         RT_BIT(3)
/** Bit 4 - PCD - Page level cache disable bit mask. */
01101 #define X86_PTE_PCD                         RT_BIT(4)
/** Bit 5 -  A  - Access bit mask. */
01103 #define X86_PTE_A                           RT_BIT(5)
/** Bit 6 -  D  - Dirty bit mask. */
01105 #define X86_PTE_D                           RT_BIT(6)
/** Bit 7 - PAT - Page Attribute Table index bit mask. Reserved and 0 if not supported. */
01107 #define X86_PTE_PAT                         RT_BIT(7)
/** Bit 8 -  G  - Global bit mask. */
01109 #define X86_PTE_G                           RT_BIT(8)

/** Bits 9-11 - - Available for use to system software. */
01112 #define X86_PTE_AVL_MASK                    (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
/** Bits 12-31 - - Physical Page number of the next level. */
01114 #define X86_PTE_PG_MASK                     ( 0xfffff000 )

/** Bits 12-51 - - PAE - Physical Page number of the next level. */
#if 1 /* we're using this internally and have to mask of the top 16-bit. */
01118 #define X86_PTE_PAE_PG_MASK                 ( 0x0000fffffffff000ULL )
/** @todo Get rid of the above hack; makes code unreadable. */
01120 #define X86_PTE_PAE_PG_MASK_FULL            ( 0x000ffffffffff000ULL )
#else
#define X86_PTE_PAE_PG_MASK                 ( 0x000ffffffffff000ULL )
#endif
/** Bits 63 - NX - PAE - No execution flag. */
01125 #define X86_PTE_PAE_NX                      RT_BIT_64(63)

/**
 * Page table entry.
 */
01130 typedef struct X86PTEBITS
{
    /** Flags whether(=1) or not the page is present. */
01133     unsigned    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01135     unsigned    u1Write : 1;
    /** User(=1) / Supervisor (=0) flag. */
01137     unsigned    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01139     unsigned    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01141     unsigned    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page have been read or written to. */
01144     unsigned    u1Accessed : 1;
    /** Dirty flag.
     * Indicates that the page has been written to. */
01147     unsigned    u1Dirty : 1;
    /** Reserved / If PAT enabled, bit 2 of the index.  */
01149     unsigned    u1PAT : 1;
    /** Global flag. (Ignored in all but final level.) */
01151     unsigned    u1Global : 1;
    /** Available for use to system software. */
01153     unsigned    u3Available : 3;
    /** Physical Page number of the next level. */
01155     unsigned    u20PageNo : 20;
} X86PTEBITS;
/** Pointer to a page table entry. */
01158 typedef X86PTEBITS *PX86PTEBITS;
/** Pointer to a const page table entry. */
01160 typedef const X86PTEBITS *PCX86PTEBITS;

/**
 * Page table entry.
 */
01165 typedef union X86PTE
{
    /** Unsigned integer view */
01168     X86PGUINT       u;
    /** Bit field view. */
01170     X86PTEBITS      n;
    /** 32-bit view. */
01172     uint32_t        au32[1];
    /** 16-bit view. */
01174     uint16_t        au16[2];
    /** 8-bit view. */
01176     uint8_t         au8[4];
} X86PTE;
/** Pointer to a page table entry. */
01179 typedef X86PTE *PX86PTE;
/** Pointer to a const page table entry. */
01181 typedef const X86PTE *PCX86PTE;


/**
 * PAE page table entry.
 */
01187 typedef struct X86PTEPAEBITS
{
    /** Flags whether(=1) or not the page is present. */
01190     uint32_t    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01192     uint32_t    u1Write : 1;
    /** User(=1) / Supervisor(=0) flag. */
01194     uint32_t    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01196     uint32_t    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01198     uint32_t    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page have been read or written to. */
01201     uint32_t    u1Accessed : 1;
    /** Dirty flag.
     * Indicates that the page has been written to. */
01204     uint32_t    u1Dirty : 1;
    /** Reserved / If PAT enabled, bit 2 of the index.  */
01206     uint32_t    u1PAT : 1;
    /** Global flag. (Ignored in all but final level.) */
01208     uint32_t    u1Global : 1;
    /** Available for use to system software. */
01210     uint32_t    u3Available : 3;
    /** Physical Page number of the next level - Low Part. Don't use this. */
01212     uint32_t    u20PageNoLow : 20;
    /** Physical Page number of the next level - High Part. Don't use this. */
01214     uint32_t    u20PageNoHigh : 20;
    /** MBZ bits */
01216     uint32_t    u11Reserved : 11;
    /** No Execute flag. */
01218     uint32_t    u1NoExecute : 1;
} X86PTEPAEBITS;
/** Pointer to a page table entry. */
01221 typedef X86PTEPAEBITS *PX86PTEPAEBITS;
/** Pointer to a page table entry. */
01223 typedef const X86PTEPAEBITS *PCX86PTEPAEBITS;

/**
 * PAE Page table entry.
 */
01228 typedef union X86PTEPAE
{
    /** Unsigned integer view */
01231     X86PGPAEUINT    u;
    /** Bit field view. */
01233     X86PTEPAEBITS   n;
    /** 32-bit view. */
01235     uint32_t        au32[2];
    /** 16-bit view. */
01237     uint16_t        au16[4];
    /** 8-bit view. */
01239     uint8_t         au8[8];
} X86PTEPAE;
/** Pointer to a PAE page table entry. */
01242 typedef X86PTEPAE *PX86PTEPAE;
/** Pointer to a const PAE page table entry. */
01244 typedef const X86PTEPAE *PCX86PTEPAE;
/** @} */

/**
 * Page table.
 */
01250 typedef struct X86PT
{
    /** PTE Array. */
01253     X86PTE     a[X86_PG_ENTRIES];
} X86PT;
/** Pointer to a page table. */
01256 typedef X86PT *PX86PT;
/** Pointer to a const page table. */
01258 typedef const X86PT *PCX86PT;

/** The page shift to get the PT index. */
01261 #define X86_PT_SHIFT                        12
/** The PT index mask (apply to a shifted page address). */
01263 #define X86_PT_MASK                         0x3ff


/**
 * Page directory.
 */
01269 typedef struct X86PTPAE
{
    /** PTE Array. */
01272     X86PTEPAE  a[X86_PG_PAE_ENTRIES];
} X86PTPAE;
/** Pointer to a page table. */
01275 typedef X86PTPAE *PX86PTPAE;
/** Pointer to a const page table. */
01277 typedef const X86PTPAE *PCX86PTPAE;

/** The page shift to get the PA PTE index. */
01280 #define X86_PT_PAE_SHIFT                    12
/** The PAE PT index mask (apply to a shifted page address). */
01282 #define X86_PT_PAE_MASK                     0x1ff


/** @name 4KB Page Directory Entry
 * @{
 */
/** Bit 0 -  P  - Present bit. */
01289 #define X86_PDE_P                           RT_BIT(0)
/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
01291 #define X86_PDE_RW                          RT_BIT(1)
/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
01293 #define X86_PDE_US                          RT_BIT(2)
/** Bit 3 - PWT - Page level write thru bit. */
01295 #define X86_PDE_PWT                         RT_BIT(3)
/** Bit 4 - PCD - Page level cache disable bit. */
01297 #define X86_PDE_PCD                         RT_BIT(4)
/** Bit 5 -  A  - Access bit. */
01299 #define X86_PDE_A                           RT_BIT(5)
/** Bit 7 - PS  - Page size attribute.
 * Clear mean 4KB pages, set means large pages (2/4MB). */
01302 #define X86_PDE_PS                          RT_BIT(7)
/** Bits 9-11 - - Available for use to system software. */
01304 #define X86_PDE_AVL_MASK                    (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
/** Bits 12-31 -  - Physical Page number of the next level. */
01306 #define X86_PDE_PG_MASK                     ( 0xfffff000 )

/** Bits 12-51 - - PAE - Physical Page number of the next level. */
#if 1 /* we're using this internally and have to mask of the top 16-bit. */
/* Note: This is kind of dangerous if the guest uses these bits (legally or illegally);
 *       we partly or that part into shadow page table entries. Will be corrected
 *       soon.
 */
01314 #define X86_PDE_PAE_PG_MASK                 ( 0x0000fffffffff000ULL )
#define X86_PDE_PAE_PG_MASK_FULL            ( 0x000ffffffffff000ULL )
#else
#define X86_PDE_PAE_PG_MASK                 ( 0x000ffffffffff000ULL )
#endif
/** Bits 63 - NX - PAE - No execution flag. */
01320 #define X86_PDE_PAE_NX                      RT_BIT_64(63)

/**
 * Page directory entry.
 */
01325 typedef struct X86PDEBITS
{
    /** Flags whether(=1) or not the page is present. */
01328     unsigned    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01330     unsigned    u1Write : 1;
    /** User(=1) / Supervisor (=0) flag. */
01332     unsigned    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01334     unsigned    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01336     unsigned    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page has been read or written to. */
01339     unsigned    u1Accessed : 1;
    /** Reserved / Ignored (dirty bit). */
01341     unsigned    u1Reserved0 : 1;
    /** Size bit if PSE is enabled - in any event it's 0. */
01343     unsigned    u1Size : 1;
    /** Reserved / Ignored (global bit). */
01345     unsigned    u1Reserved1 : 1;
    /** Available for use to system software. */
01347     unsigned    u3Available : 3;
    /** Physical Page number of the next level. */
01349     unsigned    u20PageNo : 20;
} X86PDEBITS;
/** Pointer to a page directory entry. */
01352 typedef X86PDEBITS *PX86PDEBITS;
/** Pointer to a const page directory entry. */
01354 typedef const X86PDEBITS *PCX86PDEBITS;


/**
 * PAE page directory entry.
 */
01360 typedef struct X86PDEPAEBITS
{
    /** Flags whether(=1) or not the page is present. */
01363     uint32_t    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01365     uint32_t    u1Write : 1;
    /** User(=1) / Supervisor (=0) flag. */
01367     uint32_t    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01369     uint32_t    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01371     uint32_t    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page has been read or written to. */
01374     uint32_t    u1Accessed : 1;
    /** Reserved / Ignored (dirty bit). */
01376     uint32_t    u1Reserved0 : 1;
    /** Size bit if PSE is enabled - in any event it's 0. */
01378     uint32_t    u1Size : 1;
    /** Reserved / Ignored (global bit). /  */
01380     uint32_t    u1Reserved1 : 1;
    /** Available for use to system software. */
01382     uint32_t    u3Available : 3;
    /** Physical Page number of the next level - Low Part. Don't use! */
01384     uint32_t    u20PageNoLow : 20;
    /** Physical Page number of the next level - High Part. Don't use! */
01386     uint32_t    u20PageNoHigh : 20;
    /** MBZ bits */
01388     uint32_t    u11Reserved : 11;
    /** No Execute flag. */
01390     uint32_t    u1NoExecute : 1;
} X86PDEPAEBITS;
/** Pointer to a page directory entry. */
01393 typedef X86PDEPAEBITS *PX86PDEPAEBITS;
/** Pointer to a const page directory entry. */
01395 typedef const X86PDEPAEBITS *PCX86PDEPAEBITS;

/** @} */


/** @name 2/4MB Page Directory Entry
 * @{
 */
/** Bit 0 -  P  - Present bit. */
01404 #define X86_PDE4M_P                         RT_BIT(0)
/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
01406 #define X86_PDE4M_RW                        RT_BIT(1)
/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
01408 #define X86_PDE4M_US                        RT_BIT(2)
/** Bit 3 - PWT - Page level write thru bit. */
01410 #define X86_PDE4M_PWT                       RT_BIT(3)
/** Bit 4 - PCD - Page level cache disable bit. */
01412 #define X86_PDE4M_PCD                       RT_BIT(4)
/** Bit 5 -  A  - Access bit. */
01414 #define X86_PDE4M_A                         RT_BIT(5)
/** Bit 6 -  D  - Dirty bit. */
01416 #define X86_PDE4M_D                         RT_BIT(6)
/** Bit 7 - PS  - Page size attribute. Clear mean 4KB pages, set means large pages (2/4MB). */
01418 #define X86_PDE4M_PS                        RT_BIT(7)
/** Bit 8 -  G  - Global flag. */
01420 #define X86_PDE4M_G                         RT_BIT(8)
/** Bits 9-11 - AVL - Available for use to system software. */
01422 #define X86_PDE4M_AVL                       (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
/** Bit 12 - PAT - Page Attribute Table index bit. Reserved and 0 if not supported. */
01424 #define X86_PDE4M_PAT                       RT_BIT(12)
/** Shift to get from X86_PTE_PAT to X86_PDE4M_PAT. */
01426 #define X86_PDE4M_PAT_SHIFT                 (12 - 7)
/** Bits 22-31 - - Physical Page number. */
01428 #define X86_PDE4M_PG_MASK                   ( 0xffc00000 )
/** Bits 13-20 - - Physical Page number high part (32-39 bits). AMD64 hack. */
01430 #define X86_PDE4M_PG_HIGH_MASK              ( 0x001fe000 )
/** The number of bits to the high part of the page number. */
01432 #define X86_PDE4M_PG_HIGH_SHIFT             19

/** Bits 21-51 - - PAE & AMD64 - Physical Page number.
 * (Bits 40-51 (long mode) & bits 36-51 (pae legacy) are reserved according to the Intel docs; AMD allows for more.) */
01436 #define X86_PDE2M_PAE_PG_MASK               ( 0x000fffffffe00000ULL )
/** Bits 63 - NX - PAE & AMD64 - No execution flag. */
01438 #define X86_PDE2M_PAE_NX                    X86_PDE2M_PAE_NX

/**
 * 4MB page directory entry.
 */
01443 typedef struct X86PDE4MBITS
{
    /** Flags whether(=1) or not the page is present. */
01446     unsigned    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01448     unsigned    u1Write : 1;
    /** User(=1) / Supervisor (=0) flag. */
01450     unsigned    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01452     unsigned    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01454     unsigned    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page have been read or written to. */
01457     unsigned    u1Accessed : 1;
    /** Dirty flag.
     * Indicates that the page has been written to. */
01460     unsigned    u1Dirty : 1;
    /** Page size flag - always 1 for 4MB entries. */
01462     unsigned    u1Size : 1;
    /** Global flag.  */
01464     unsigned    u1Global : 1;
    /** Available for use to system software. */
01466     unsigned    u3Available : 3;
    /** Reserved / If PAT enabled, bit 2 of the index.  */
01468     unsigned    u1PAT : 1;
    /** Bits 32-39 of the page number on AMD64.
     * This AMD64 hack allows accessing 40bits of physical memory without PAE. */
01471     unsigned    u8PageNoHigh : 8;
    /** Reserved. */
01473     unsigned    u1Reserved : 1;
    /** Physical Page number of the page. */
01475     unsigned    u10PageNo : 10;
} X86PDE4MBITS;
/** Pointer to a page table entry. */
01478 typedef X86PDE4MBITS *PX86PDE4MBITS;
/** Pointer to a const page table entry. */
01480 typedef const X86PDE4MBITS *PCX86PDE4MBITS;


/**
 * 2MB PAE page directory entry.
 */
01486 typedef struct X86PDE2MPAEBITS
{
    /** Flags whether(=1) or not the page is present. */
01489     uint32_t    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01491     uint32_t    u1Write : 1;
    /** User(=1) / Supervisor(=0) flag. */
01493     uint32_t    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01495     uint32_t    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01497     uint32_t    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page have been read or written to. */
01500     uint32_t    u1Accessed : 1;
    /** Dirty flag.
     * Indicates that the page has been written to. */
01503     uint32_t    u1Dirty : 1;
    /** Page size flag - always 1 for 2MB entries. */
01505     uint32_t    u1Size : 1;
    /** Global flag.  */
01507     uint32_t    u1Global : 1;
    /** Available for use to system software. */
01509     uint32_t    u3Available : 3;
    /** Reserved / If PAT enabled, bit 2 of the index.  */
01511     uint32_t    u1PAT : 1;
    /** Reserved. */
01513     uint32_t    u9Reserved : 9;
    /** Physical Page number of the next level - Low part. Don't use! */
01515     uint32_t    u10PageNoLow : 10;
    /** Physical Page number of the next level - High part. Don't use! */
01517     uint32_t    u20PageNoHigh : 20;
    /** MBZ bits */
01519     uint32_t    u11Reserved : 11;
    /** No Execute flag. */
01521     uint32_t    u1NoExecute : 1;
} X86PDE2MPAEBITS;
/** Pointer to a 2MB PAE page table entry. */
01524 typedef X86PDE2MPAEBITS *PX86PDE2MPAEBITS;
/** Pointer to a 2MB PAE page table entry. */
01526 typedef const X86PDE2MPAEBITS *PCX86PDE2MPAEBITS;

/** @} */

/**
 * Page directory entry.
 */
01533 typedef union X86PDE
{
    /** Unsigned integer view. */
01536     X86PGUINT       u;
    /** Normal view. */
01538     X86PDEBITS      n;
    /** 4MB view (big). */
01540     X86PDE4MBITS    b;
    /** 8 bit unsigned integer view. */
01542     uint8_t         au8[4];
    /** 16 bit unsigned integer view. */
01544     uint16_t        au16[2];
    /** 32 bit unsigned integer view. */
01546     uint32_t        au32[1];
} X86PDE;
/** Pointer to a page directory entry. */
01549 typedef X86PDE *PX86PDE;
/** Pointer to a const page directory entry. */
01551 typedef const X86PDE *PCX86PDE;

/**
 * PAE page directory entry.
 */
01556 typedef union X86PDEPAE
{
    /** Unsigned integer view. */
01559     X86PGPAEUINT    u;
    /** Normal view. */
01561     X86PDEPAEBITS   n;
    /** 2MB page view (big). */
01563     X86PDE2MPAEBITS b;
    /** 8 bit unsigned integer view. */
01565     uint8_t         au8[8];
    /** 16 bit unsigned integer view. */
01567     uint16_t        au16[4];
    /** 32 bit unsigned integer view. */
01569     uint32_t        au32[2];
} X86PDEPAE;
/** Pointer to a page directory entry. */
01572 typedef X86PDEPAE *PX86PDEPAE;
/** Pointer to a const page directory entry. */
01574 typedef const X86PDEPAE *PCX86PDEPAE;

/**
 * Page directory.
 */
01579 typedef struct X86PD
{
    /** PDE Array. */
01582     X86PDE      a[X86_PG_ENTRIES];
} X86PD;
/** Pointer to a page directory. */
01585 typedef X86PD *PX86PD;
/** Pointer to a const page directory. */
01587 typedef const X86PD *PCX86PD;

/** The page shift to get the PD index. */
01590 #define X86_PD_SHIFT                        22
/** The PD index mask (apply to a shifted page address). */
01592 #define X86_PD_MASK                         0x3ff


/**
 * PAE page directory.
 */
01598 typedef struct X86PDPAE
{
    /** PDE Array. */
01601     X86PDEPAE   a[X86_PG_PAE_ENTRIES];
} X86PDPAE;
/** Pointer to a PAE page directory. */
01604 typedef X86PDPAE *PX86PDPAE;
/** Pointer to a const PAE page directory. */
01606 typedef const X86PDPAE *PCX86PDPAE;

/** The page shift to get the PAE PD index. */
01609 #define X86_PD_PAE_SHIFT                    21
/** The PAE PD index mask (apply to a shifted page address). */
01611 #define X86_PD_PAE_MASK                     0x1ff


/** @name Page Directory Pointer Table Entry (PAE)
 * @{
 */
/** Bit 0 -  P  - Present bit. */
01618 #define X86_PDPE_P                          RT_BIT(0)
/** Bit 1 - R/W - Read (clear) / Write (set) bit. Long Mode only. */
01620 #define X86_PDPE_RW                         RT_BIT(1)
/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. Long Mode only. */
01622 #define X86_PDPE_US                         RT_BIT(2)
/** Bit 3 - PWT - Page level write thru bit. */
01624 #define X86_PDPE_PWT                        RT_BIT(3)
/** Bit 4 - PCD - Page level cache disable bit. */
01626 #define X86_PDPE_PCD                        RT_BIT(4)
/** Bit 5 -  A  - Access bit. Long Mode only. */
01628 #define X86_PDPE_A                          RT_BIT(5)
/** Bits 9-11 - - Available for use to system software. */
01630 #define X86_PDPE_AVL_MASK                   (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
/** Bits 12-51 - - PAE - Physical Page number of the next level. */
#if 1 /* we're using this internally and have to mask of the top 16-bit. */
01633 #define X86_PDPE_PG_MASK                    ( 0x0000fffffffff000ULL )
/** @todo Get rid of the above hack; makes code unreadable. */
01635 #define X86_PDPE_PG_MASK_FULL               ( 0x000ffffffffff000ULL )
#else
#define X86_PDPE_PG_MASK                    ( 0x000ffffffffff000ULL )
#endif
/** Bits 63 - NX - PAE - No execution flag. Long Mode only. */
01640 #define X86_PDPE_NX                         RT_BIT_64(63)

/**
 * Page directory pointer table entry.
 */
01645 typedef struct X86PDPEBITS
{
    /** Flags whether(=1) or not the page is present. */
01648     uint32_t    u1Present : 1;
    /** Chunk of reserved bits. */
01650     uint32_t    u2Reserved : 2;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01652     uint32_t    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01654     uint32_t    u1CacheDisable : 1;
    /** Chunk of reserved bits. */
01656     uint32_t    u4Reserved : 4;
    /** Available for use to system software. */
01658     uint32_t    u3Available : 3;
    /** Physical Page number of the next level - Low Part. Don't use! */
01660     uint32_t    u20PageNoLow : 20;
    /** Physical Page number of the next level - High Part. Don't use! */
01662     uint32_t    u20PageNoHigh : 20;
    /** MBZ bits */
01664     uint32_t    u12Reserved : 12;
} X86PDPEBITS;
/** Pointer to a page directory pointer table entry. */
01667 typedef X86PDPEBITS *PX86PTPEBITS;
/** Pointer to a const page directory pointer table entry. */
01669 typedef const X86PDPEBITS *PCX86PTPEBITS;

/**
 * Page directory pointer table entry. AMD64 version
 */
01674 typedef struct X86PDPEAMD64BITS
{
    /** Flags whether(=1) or not the page is present. */
01677     uint32_t    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01679     uint32_t    u1Write : 1;
    /** User(=1) / Supervisor (=0) flag. */
01681     uint32_t    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01683     uint32_t    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01685     uint32_t    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page have been read or written to. */
01688     uint32_t    u1Accessed : 1;
    /** Chunk of reserved bits. */
01690     uint32_t    u3Reserved : 3;
    /** Available for use to system software. */
01692     uint32_t    u3Available : 3;
    /** Physical Page number of the next level - Low Part. Don't use! */
01694     uint32_t    u20PageNoLow : 20;
    /** Physical Page number of the next level - High Part. Don't use! */
01696     uint32_t    u20PageNoHigh : 20;
    /** MBZ bits */
01698     uint32_t    u11Reserved : 11;
    /** No Execute flag. */
01700     uint32_t    u1NoExecute : 1;
} X86PDPEAMD64BITS;
/** Pointer to a page directory pointer table entry. */
01703 typedef X86PDPEAMD64BITS *PX86PDPEAMD64BITS;
/** Pointer to a const page directory pointer table entry. */
01705 typedef const X86PDPEBITS *PCX86PDPEAMD64BITS;

/**
 * Page directory pointer table entry.
 */
01710 typedef union X86PDPE
{
    /** Unsigned integer view. */
01713     X86PGPAEUINT    u;
    /** Normal view. */
01715     X86PDPEBITS     n;
    /** AMD64 view. */
01717     X86PDPEAMD64BITS lm;
    /** 8 bit unsigned integer view. */
01719     uint8_t         au8[8];
    /** 16 bit unsigned integer view. */
01721     uint16_t        au16[4];
    /** 32 bit unsigned integer view. */
01723     uint32_t        au32[2];
} X86PDPE;
/** Pointer to a page directory pointer table entry. */
01726 typedef X86PDPE *PX86PDPE;
/** Pointer to a const page directory pointer table entry. */
01728 typedef const X86PDPE *PCX86PDPE;


/**
 * Page directory pointer table.
 */
01734 typedef struct X86PDPT
{
    /** PDE Array. */
01737     X86PDPE         a[X86_PG_AMD64_PDPE_ENTRIES];
} X86PDPT;
/** Pointer to a page directory pointer table. */
01740 typedef X86PDPT *PX86PDPT;
/** Pointer to a const page directory pointer table. */
01742 typedef const X86PDPT *PCX86PDPT;

/** The page shift to get the PDPT index. */
01745 #define X86_PDPT_SHIFT             30
/** The PDPT index mask (apply to a shifted page address). (32 bits PAE) */
01747 #define X86_PDPT_MASK_PAE          0x3
/** The PDPT index mask (apply to a shifted page address). (64 bits PAE)*/
01749 #define X86_PDPT_MASK_AMD64        0x1ff

/** @} */


/** @name Page Map Level-4 Entry (Long Mode PAE)
 * @{
 */
/** Bit 0 -  P  - Present bit. */
01758 #define X86_PML4E_P                         RT_BIT(0)
/** Bit 1 - R/W - Read (clear) / Write (set) bit. */
01760 #define X86_PML4E_RW                        RT_BIT(1)
/** Bit 2 - U/S - User (set) / Supervisor (clear) bit. */
01762 #define X86_PML4E_US                        RT_BIT(2)
/** Bit 3 - PWT - Page level write thru bit. */
01764 #define X86_PML4E_PWT                       RT_BIT(3)
/** Bit 4 - PCD - Page level cache disable bit. */
01766 #define X86_PML4E_PCD                       RT_BIT(4)
/** Bit 5 -  A  - Access bit. */
01768 #define X86_PML4E_A                         RT_BIT(5)
/** Bits 9-11 - - Available for use to system software. */
01770 #define X86_PML4E_AVL_MASK                  (RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
/** Bits 12-51 - - PAE - Physical Page number of the next level. */
#if 1 /* we're using this internally and have to mask of the top 16-bit. */
01773 #define X86_PML4E_PG_MASK                   ( 0x0000fffffffff000ULL )
#define X86_PML4E_PG_MASK_FULL              ( 0x000ffffffffff000ULL )
#else
#define X86_PML4E_PG_MASK                   ( 0x000ffffffffff000ULL )
#endif
/** Bits 63 - NX - PAE - No execution flag. */
01779 #define X86_PML4E_NX                        RT_BIT_64(63)

/**
 * Page Map Level-4 Entry
 */
01784 typedef struct X86PML4EBITS
{
    /** Flags whether(=1) or not the page is present. */
01787     uint32_t    u1Present : 1;
    /** Read(=0) / Write(=1) flag. */
01789     uint32_t    u1Write : 1;
    /** User(=1) / Supervisor (=0) flag. */
01791     uint32_t    u1User : 1;
    /** Write Thru flag. If PAT enabled, bit 0 of the index. */
01793     uint32_t    u1WriteThru : 1;
    /** Cache disabled flag. If PAT enabled, bit 1 of the index. */
01795     uint32_t    u1CacheDisable : 1;
    /** Accessed flag.
     * Indicates that the page have been read or written to. */
01798     uint32_t    u1Accessed : 1;
    /** Chunk of reserved bits. */
01800     uint32_t    u3Reserved : 3;
    /** Available for use to system software. */
01802     uint32_t    u3Available : 3;
    /** Physical Page number of the next level - Low Part. Don't use! */
01804     uint32_t    u20PageNoLow : 20;
    /** Physical Page number of the next level - High Part. Don't use! */
01806     uint32_t    u20PageNoHigh : 20;
    /** MBZ bits */
01808     uint32_t    u11Reserved : 11;
    /** No Execute flag. */
01810     uint32_t    u1NoExecute : 1;
} X86PML4EBITS;
/** Pointer to a page map level-4 entry. */
01813 typedef X86PML4EBITS *PX86PML4EBITS;
/** Pointer to a const page map level-4 entry. */
01815 typedef const X86PML4EBITS *PCX86PML4EBITS;

/**
 * Page Map Level-4 Entry.
 */
01820 typedef union X86PML4E
{
    /** Unsigned integer view. */
01823     X86PGPAEUINT    u;
    /** Normal view. */
01825     X86PML4EBITS    n;
    /** 8 bit unsigned integer view. */
01827     uint8_t         au8[8];
    /** 16 bit unsigned integer view. */
01829     uint16_t        au16[4];
    /** 32 bit unsigned integer view. */
01831     uint32_t        au32[2];
} X86PML4E;
/** Pointer to a page map level-4 entry. */
01834 typedef X86PML4E *PX86PML4E;
/** Pointer to a const page map level-4 entry. */
01836 typedef const X86PML4E *PCX86PML4E;


/**
 * Page Map Level-4.
 */
01842 typedef struct X86PML4
{
    /** PDE Array. */
01845     X86PML4E        a[X86_PG_PAE_ENTRIES];
} X86PML4;
/** Pointer to a page map level-4. */
01848 typedef X86PML4 *PX86PML4;
/** Pointer to a const page map level-4. */
01850 typedef const X86PML4 *PCX86PML4;

/** The page shift to get the PML4 index. */
01853 #define X86_PML4_SHIFT              39
/** The PML4 index mask (apply to a shifted page address). */
01855 #define X86_PML4_MASK               0x1ff

/** @} */

/** @} */


/**
 * 80-bit MMX/FPU register type.
 */
01865 typedef struct X86FPUMMX
{
    uint8_t reg[10];
} X86FPUMMX;
/** Pointer to a 80-bit MMX/FPU register type. */
01870 typedef X86FPUMMX *PX86FPUMMX;
/** Pointer to a const 80-bit MMX/FPU register type. */
01872 typedef const X86FPUMMX *PCX86FPUMMX;

/**
 * FPU state (aka FSAVE/FRSTOR Memory Region).
 */
#pragma pack(1)
01878 typedef struct X86FPUSTATE
{
    /** Control word. */
01881     uint16_t    FCW;
    /** Alignment word */
01883     uint16_t    Dummy1;
    /** Status word. */
01885     uint16_t    FSW;
    /** Alignment word */
01887     uint16_t    Dummy2;
    /** Tag word */
01889     uint16_t    FTW;
    /** Alignment word */
01891     uint16_t    Dummy3;

    /** Instruction pointer. */
01894     uint32_t    FPUIP;
    /** Code selector. */
01896     uint16_t    CS;
    /** Opcode. */
01898     uint16_t    FOP;
    /** FOO. */
01900     uint32_t    FPUOO;
    /** FOS. */
01902     uint32_t    FPUOS;
    /** FPU view - todo. */
01904     X86FPUMMX   regs[8];
} X86FPUSTATE;
#pragma pack()
/** Pointer to a FPU state. */
01908 typedef X86FPUSTATE  *PX86FPUSTATE;
/** Pointer to a const FPU state. */
01910 typedef const X86FPUSTATE  *PCX86FPUSTATE;

/**
 * FPU Extended state (aka FXSAVE/FXRSTORE Memory Region).
 */
#pragma pack(1)
01916 typedef struct X86FXSTATE
{
    /** Control word. */
01919     uint16_t    FCW;
    /** Status word. */
01921     uint16_t    FSW;
    /** Tag word. (The upper byte is always zero.) */
01923     uint16_t    FTW;
    /** Opcode. */
01925     uint16_t    FOP;
    /** Instruction pointer. */
01927     uint32_t    FPUIP;
    /** Code selector. */
01929     uint16_t    CS;
    uint16_t    Rsvrd1;
    /* - offset 16 - */
    /** Data pointer. */
01933     uint32_t    FPUDP;
    /** Data segment */
01935     uint16_t    DS;
    uint16_t    Rsrvd2;
    uint32_t    MXCSR;
    uint32_t    MXCSR_MASK;
    /* - offset 32 - */
    union
    {
        /** MMX view. */
01943         uint64_t    mmx;
        /** FPU view - todo. */
01945         X86FPUMMX   fpu;
        /** 8-bit view. */
01947         uint8_t     au8[16];
        /** 16-bit view. */
01949         uint16_t    au16[8];
        /** 32-bit view. */
01951         uint32_t    au32[4];
        /** 64-bit view. */
01953         uint64_t    au64[2];
        /** 128-bit view. (yeah, very helpful) */
01955         uint128_t   au128[1];
    } aRegs[8];
    /* - offset 160 - */
    union
    {
        /** XMM Register view *. */
01961         uint128_t   xmm;
        /** 8-bit view. */
        uint8_t     au8[16];
        /** 16-bit view. */
        uint16_t    au16[8];
        /** 32-bit view. */
        uint32_t    au32[4];
        /** 64-bit view. */
        uint64_t    au64[2];
        /** 128-bit view. (yeah, very helpful) */
        uint128_t   au128[1];
    } aXMM[16]; /* 8 registers in 32 bits mode; 16 in long mode */
    /* - offset 416 - */
    uint32_t    au32RsrvdRest[(512 - 416) / sizeof(uint32_t)];
} X86FXSTATE;
#pragma pack()
/** Pointer to a FPU Extended state. */
01978 typedef X86FXSTATE *PX86FXSTATE;
/** Pointer to a const FPU Extended state. */
01980 typedef const X86FXSTATE *PCX86FXSTATE;


/** @name Selector Descriptor
 * @{
 */

/**
 * Descriptor attributes.
 */
01990 typedef struct X86DESCATTRBITS
{
    /** 00 - Segment Type. */
01993     unsigned    u4Type : 4;
    /** 04 - Descriptor Type. System(=0) or code/data selector */
01995     unsigned    u1DescType : 1;
    /** 05 - Descriptor Privelege level. */
01997     unsigned    u2Dpl : 2;
    /** 07 - Flags selector present(=1) or not. */
01999     unsigned    u1Present : 1;
    /** 08 - Segment limit 16-19. */
02001     unsigned    u4LimitHigh : 4;
    /** 0c - Available for system software. */
02003     unsigned    u1Available : 1;
    /** 0d - 32 bits mode: Reserved - 0, long mode: Long Attribute Bit. */
02005     unsigned    u1Long : 1;
    /** 0e - This flags meaning depends on the segment type. Try make sense out
     * of the intel manual yourself.  */
02008     unsigned    u1DefBig : 1;
    /** 0f - Granularity of the limit. If set 4KB granularity is used, if
     * clear byte. */
02011     unsigned    u1Granularity : 1;
} X86DESCATTRBITS;


#pragma pack(1)
02016 typedef union X86DESCATTR
{
    /** Unsigned integer view. */
02019     uint32_t           u;
    /** Normal view. */
02021     X86DESCATTRBITS    n;
} X86DESCATTR;
#pragma pack()
/** Pointer to descriptor attributes. */
02025 typedef X86DESCATTR *PX86DESCATTR;
/** Pointer to const descriptor attributes. */
02027 typedef const X86DESCATTR *PCX86DESCATTR;


/**
 * Generic descriptor table entry
 */
#pragma pack(1)
02034 typedef struct X86DESCGENERIC
{
    /** Limit - Low word. */
02037     unsigned    u16LimitLow : 16;
    /** Base address - lowe word.
     * Don't try set this to 24 because MSC is doing stupid things then. */
02040     unsigned    u16BaseLow : 16;
    /** Base address - first 8 bits of high word. */
02042     unsigned    u8BaseHigh1 : 8;
    /** Segment Type. */
02044     unsigned    u4Type : 4;
    /** Descriptor Type. System(=0) or code/data selector */
02046     unsigned    u1DescType : 1;
    /** Descriptor Privelege level. */
02048     unsigned    u2Dpl : 2;
    /** Flags selector present(=1) or not. */
02050     unsigned    u1Present : 1;
    /** Segment limit 16-19. */
02052     unsigned    u4LimitHigh : 4;
    /** Available for system software. */
02054     unsigned    u1Available : 1;
    /** 32 bits mode: Reserved - 0, long mode: Long Attribute Bit. */
02056     unsigned    u1Long : 1;
    /** This flags meaning depends on the segment type. Try make sense out
     * of the intel manual yourself.  */
02059     unsigned    u1DefBig : 1;
    /** Granularity of the limit. If set 4KB granularity is used, if
     * clear byte. */
02062     unsigned    u1Granularity : 1;
    /** Base address - highest 8 bits. */
02064     unsigned    u8BaseHigh2 : 8;
} X86DESCGENERIC;
#pragma pack()
/** Pointer to a generic descriptor entry. */
02068 typedef X86DESCGENERIC *PX86DESCGENERIC;
/** Pointer to a const generic descriptor entry. */
02070 typedef const X86DESCGENERIC *PCX86DESCGENERIC;

/**
 * Call-, Interrupt-, Trap- or Task-gate descriptor (legacy).
 */
02075 typedef struct X86DESCGATE
{
    /** Target code segment offset - Low word.
     * Ignored if task-gate. */
02079     unsigned    u16OffsetLow : 16;
    /** Target code segment selector for call-, interrupt- and trap-gates,
     * TSS selector if task-gate. */
02082     unsigned    u16Sel : 16;
    /** Number of parameters for a call-gate.
     * Ignored if interrupt-, trap- or task-gate. */
02085     unsigned    u4ParmCount : 4;
    /** Reserved / ignored. */
02087     unsigned    u4Reserved : 4;
    /** Segment Type. */
02089     unsigned    u4Type : 4;
    /** Descriptor Type (0 = system). */
02091     unsigned    u1DescType : 1;
    /** Descriptor Privelege level. */
02093     unsigned    u2Dpl : 2;
    /** Flags selector present(=1) or not. */
02095     unsigned    u1Present : 1;
    /** Target code segment offset - High word.
     * Ignored if task-gate. */
02098     unsigned    u16OffsetHigh : 16;
} X86DESCGATE;
AssertCompileSize(X86DESCGATE, 8);
/** Pointer to a Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
02102 typedef X86DESCGATE *PX86DESCGATE;
/** Pointer to a const Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
02104 typedef const X86DESCGATE *PCX86DESCGATE;

/**
 * Descriptor table entry.
 */
#pragma pack(1)
02110 typedef union X86DESC
{
    /** Generic descriptor view. */
02113     X86DESCGENERIC  Gen;
    /** Gate descriptor view. */
02115     X86DESCGATE     Gate;

    /** 8 bit unsigned interger view. */
02118     uint8_t         au8[8];
    /** 16 bit unsigned interger view. */
02120     uint16_t        au16[4];
    /** 32 bit unsigned interger view. */
02122     uint32_t        au32[2];
} X86DESC;
AssertCompileSize(X86DESC, 8);
#pragma pack()
/** Pointer to descriptor table entry. */
02127 typedef X86DESC *PX86DESC;
/** Pointer to const descriptor table entry. */
02129 typedef const X86DESC *PCX86DESC;

/** @def X86DESC_BASE
 * Return the base address of a descriptor.
 */
02134 #define X86DESC_BASE(desc) /*ASM-NOINC*/ \
        (  ((uint32_t)((desc).Gen.u8BaseHigh2) << 24) \
         | (           (desc).Gen.u8BaseHigh1  << 16) \
         | (           (desc).Gen.u16BaseLow        ) )

/** @def X86DESC_LIMIT
 * Return the limit of a descriptor.
 */
02142 #define X86DESC_LIMIT(desc) /*ASM-NOINC*/ \
        (  ((uint32_t)((desc).Gen.u4LimitHigh) << 16) \
         | (           (desc).Gen.u16LimitLow       ) )

/**
 * 64 bits generic descriptor table entry
 * Note: most of these bits have no meaning in long mode.
 */
#pragma pack(1)
02151 typedef struct X86DESC64GENERIC
{
    /** Limit - Low word - *IGNORED*. */
02154     unsigned    u16LimitLow : 16;
    /** Base address - lowe word. - *IGNORED*
     * Don't try set this to 24 because MSC is doing stupid things then. */
02157     unsigned    u16BaseLow : 16;
    /** Base address - first 8 bits of high word. - *IGNORED* */
02159     unsigned    u8BaseHigh1 : 8;
    /** Segment Type. */
02161     unsigned    u4Type : 4;
    /** Descriptor Type. System(=0) or code/data selector */
02163     unsigned    u1DescType : 1;
    /** Descriptor Privelege level. */
02165     unsigned    u2Dpl : 2;
    /** Flags selector present(=1) or not. */
02167     unsigned    u1Present : 1;
    /** Segment limit 16-19. - *IGNORED* */
02169     unsigned    u4LimitHigh : 4;
    /** Available for system software. - *IGNORED* */
02171     unsigned    u1Available : 1;
    /** Long mode flag. */
02173     unsigned    u1Long : 1;
    /** This flags meaning depends on the segment type. Try make sense out
     * of the intel manual yourself.  */
02176     unsigned    u1DefBig : 1;
    /** Granularity of the limit. If set 4KB granularity is used, if
     * clear byte. - *IGNORED* */
02179     unsigned    u1Granularity : 1;
    /** Base address - highest 8 bits. - *IGNORED* */
02181     unsigned    u8BaseHigh2 : 8;
    /** Base address - bits 63-32. */
02183     unsigned    u32BaseHigh3    : 32;
    unsigned    u8Reserved      : 8;
    unsigned    u5Zeros         : 5;
    unsigned    u19Reserved     : 19;
} X86DESC64GENERIC;
#pragma pack()
/** Pointer to a generic descriptor entry. */
02190 typedef X86DESC64GENERIC *PX86DESC64GENERIC;
/** Pointer to a const generic descriptor entry. */
02192 typedef const X86DESC64GENERIC *PCX86DESC64GENERIC;

/**
 * System descriptor table entry (64 bits)
 *
 * @remarks This is, save a couple of comments, identical to X86DESC64GENERIC...
 */
#pragma pack(1)
02200 typedef struct X86DESC64SYSTEM
{
    /** Limit - Low word. */
02203     unsigned    u16LimitLow     : 16;
    /** Base address - lowe word.
     * Don't try set this to 24 because MSC is doing stupid things then. */
02206     unsigned    u16BaseLow      : 16;
    /** Base address - first 8 bits of high word. */
02208     unsigned    u8BaseHigh1     : 8;
    /** Segment Type. */
02210     unsigned    u4Type          : 4;
    /** Descriptor Type. System(=0) or code/data selector */
02212     unsigned    u1DescType      : 1;
    /** Descriptor Privelege level. */
02214     unsigned    u2Dpl           : 2;
    /** Flags selector present(=1) or not. */
02216     unsigned    u1Present       : 1;
    /** Segment limit 16-19. */
02218     unsigned    u4LimitHigh     : 4;
    /** Available for system software. */
02220     unsigned    u1Available     : 1;
    /** Reserved - 0. */
02222     unsigned    u1Reserved      : 1;
    /** This flags meaning depends on the segment type. Try make sense out
     * of the intel manual yourself.  */
02225     unsigned    u1DefBig        : 1;
    /** Granularity of the limit. If set 4KB granularity is used, if
     * clear byte. */
02228     unsigned    u1Granularity   : 1;
    /** Base address - bits 31-24. */
02230     unsigned    u8BaseHigh2     : 8;
    /** Base address - bits 63-32. */
02232     unsigned    u32BaseHigh3    : 32;
    unsigned    u8Reserved      : 8;
    unsigned    u5Zeros         : 5;
    unsigned    u19Reserved     : 19;
} X86DESC64SYSTEM;
#pragma pack()
/** Pointer to a system descriptor entry. */
02239 typedef X86DESC64SYSTEM *PX86DESC64SYSTEM;
/** Pointer to a const system descriptor entry. */
02241 typedef const X86DESC64SYSTEM *PCX86DESC64SYSTEM;

/**
 * Call-, Interrupt-, Trap- or Task-gate descriptor (64-bit).
 */
02246 typedef struct X86DESC64GATE
{
    /** Target code segment offset - Low word. */
02249     unsigned    u16OffsetLow : 16;
    /** Target code segment selector. */
02251     unsigned    u16Sel : 16;
    /** Interrupt stack table for interrupt- and trap-gates.
     * Ignored by call-gates. */
02254     unsigned    u3IST : 3;
    /** Reserved / ignored. */
02256     unsigned    u5Reserved : 5;
    /** Segment Type. */
02258     unsigned    u4Type : 4;
    /** Descriptor Type (0 = system). */
02260     unsigned    u1DescType : 1;
    /** Descriptor Privelege level. */
02262     unsigned    u2Dpl : 2;
    /** Flags selector present(=1) or not. */
02264     unsigned    u1Present : 1;
    /** Target code segment offset - High word.
     * Ignored if task-gate. */
02267     unsigned    u16OffsetHigh : 16;
    /** Target code segment offset - Top dword.
     * Ignored if task-gate. */
02270     unsigned    u32OffsetTop : 32;
    /** Reserved / ignored / must be zero.
     * For call-gates bits 8 thru 12 must be zero, the other gates ignores this. */
02273     unsigned    u32Reserved : 32;
} X86DESC64GATE;
AssertCompileSize(X86DESC64GATE, 16);
/** Pointer to a Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
02277 typedef X86DESC64GATE *PX86DESC64GATE;
/** Pointer to a const Call-, Interrupt-, Trap- or Task-gate descriptor entry. */
02279 typedef const X86DESC64GATE *PCX86DESC64GATE;


/**
 * Descriptor table entry.
 */
#pragma pack(1)
02286 typedef union X86DESC64
{
    /** Generic descriptor view. */
02289     X86DESC64GENERIC    Gen;
    /** System descriptor view. */
02291     X86DESC64SYSTEM     System;
    /** Gate descriptor view. */
02293     X86DESC64GATE       Gate;

    /** 8 bit unsigned interger view. */
02296     uint8_t             au8[16];
    /** 16 bit unsigned interger view. */
02298     uint16_t            au16[8];
    /** 32 bit unsigned interger view. */
02300     uint32_t            au32[4];
    /** 64 bit unsigned interger view. */
02302     uint64_t            au64[2];
} X86DESC64;
AssertCompileSize(X86DESC64, 16);
#pragma pack()
/** Pointer to descriptor table entry. */
02307 typedef X86DESC64 *PX86DESC64;
/** Pointer to const descriptor table entry. */
02309 typedef const X86DESC64 *PCX86DESC64;

/** @def X86DESC64_BASE
 * Return the base of a 64-bit descriptor.
 */
02314 #define X86DESC64_BASE(desc) /*ASM-NOINC*/ \
        (  ((uint64_t)((desc).Gen.u32BaseHigh3) << 32) \
         | ((uint32_t)((desc).Gen.u8BaseHigh2)  << 24) \
         | (           (desc).Gen.u8BaseHigh1   << 16) \
         | (           (desc).Gen.u16BaseLow         ) )



/** @name Host system descriptor table entry - Use with care!
 * @{ */
/** Host system descriptor table entry. */
#if HC_ARCH_BITS == 64
typedef X86DESC64   X86DESCHC;
#else
02328 typedef X86DESC     X86DESCHC;
#endif
/** Pointer to a host system descriptor table entry. */
#if HC_ARCH_BITS == 64
typedef PX86DESC64  PX86DESCHC;
#else
02334 typedef PX86DESC    PX86DESCHC;
#endif
/** Pointer to a const host system descriptor table entry. */
#if HC_ARCH_BITS == 64
typedef PCX86DESC64 PCX86DESCHC;
#else
02340 typedef PCX86DESC   PCX86DESCHC;
#endif
/** @} */


/** @name Selector Descriptor Types.
 * @{
 */

/** @name Non-System Selector Types.
 * @{ */
/** Code(=set)/Data(=clear) bit. */
02352 #define X86_SEL_TYPE_CODE                   8
/** Memory(=set)/System(=clear) bit. */
02354 #define X86_SEL_TYPE_MEMORY                 RT_BIT(4)
/** Accessed bit. */
02356 #define X86_SEL_TYPE_ACCESSED               1
/** Expand down bit (for data selectors only). */
02358 #define X86_SEL_TYPE_DOWN                   4
/** Conforming bit (for code selectors only). */
02360 #define X86_SEL_TYPE_CONF                   4
/** Write bit (for data selectors only). */
02362 #define X86_SEL_TYPE_WRITE                  2
/** Read bit (for code selectors only). */
02364 #define X86_SEL_TYPE_READ                   2

/** Read only selector type. */
02367 #define X86_SEL_TYPE_RO                     0
/** Accessed read only selector type. */
02369 #define X86_SEL_TYPE_RO_ACC                (0 | X86_SEL_TYPE_ACCESSED)
/** Read write selector type. */
02371 #define X86_SEL_TYPE_RW                     2
/** Accessed read write selector type. */
02373 #define X86_SEL_TYPE_RW_ACC                (2 | X86_SEL_TYPE_ACCESSED)
/** Expand down read only selector type. */
02375 #define X86_SEL_TYPE_RO_DOWN                4
/** Accessed expand down read only selector type. */
02377 #define X86_SEL_TYPE_RO_DOWN_ACC           (4 | X86_SEL_TYPE_ACCESSED)
/** Expand down read write selector type. */
02379 #define X86_SEL_TYPE_RW_DOWN                6
/** Accessed expand down read write selector type. */
02381 #define X86_SEL_TYPE_RW_DOWN_ACC           (6 | X86_SEL_TYPE_ACCESSED)
/** Execute only selector type. */
02383 #define X86_SEL_TYPE_EO                    (0 | X86_SEL_TYPE_CODE)
/** Accessed execute only selector type. */
02385 #define X86_SEL_TYPE_EO_ACC                (0 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
/** Execute and read selector type. */
02387 #define X86_SEL_TYPE_ER                    (2 | X86_SEL_TYPE_CODE)
/** Accessed execute and read selector type. */
02389 #define X86_SEL_TYPE_ER_ACC                (2 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
/** Conforming execute only selector type. */
02391 #define X86_SEL_TYPE_EO_CONF               (4 | X86_SEL_TYPE_CODE)
/** Accessed Conforming execute only selector type. */
02393 #define X86_SEL_TYPE_EO_CONF_ACC           (4 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
/** Conforming execute and write selector type. */
02395 #define X86_SEL_TYPE_ER_CONF               (6 | X86_SEL_TYPE_CODE)
/** Accessed Conforming execute and write selector type. */
02397 #define X86_SEL_TYPE_ER_CONF_ACC           (6 | X86_SEL_TYPE_CODE | X86_SEL_TYPE_ACCESSED)
/** @} */


/** @name System Selector Types.
 * @{ */
/** Undefined system selector type. */
02404 #define X86_SEL_TYPE_SYS_UNDEFINED          0
/** 286 TSS selector. */
02406 #define X86_SEL_TYPE_SYS_286_TSS_AVAIL      1
/** LDT selector. */
02408 #define X86_SEL_TYPE_SYS_LDT                2
/** 286 TSS selector - Busy. */
02410 #define X86_SEL_TYPE_SYS_286_TSS_BUSY       3
/** 286 Callgate selector. */
02412 #define X86_SEL_TYPE_SYS_286_CALL_GATE      4
/** Taskgate selector. */
02414 #define X86_SEL_TYPE_SYS_TASK_GATE          5
/** 286 Interrupt gate selector. */
02416 #define X86_SEL_TYPE_SYS_286_INT_GATE       6
/** 286 Trapgate selector. */
02418 #define X86_SEL_TYPE_SYS_286_TRAP_GATE      7
/** Undefined system selector. */
02420 #define X86_SEL_TYPE_SYS_UNDEFINED2         8
/** 386 TSS selector. */
02422 #define X86_SEL_TYPE_SYS_386_TSS_AVAIL      9
/** Undefined system selector. */
02424 #define X86_SEL_TYPE_SYS_UNDEFINED3         0xA
/** 386 TSS selector - Busy. */
02426 #define X86_SEL_TYPE_SYS_386_TSS_BUSY       0xB
/** 386 Callgate selector. */
02428 #define X86_SEL_TYPE_SYS_386_CALL_GATE      0xC
/** Undefined system selector. */
02430 #define X86_SEL_TYPE_SYS_UNDEFINED4         0xD
/** 386 Interruptgate selector. */
02432 #define X86_SEL_TYPE_SYS_386_INT_GATE       0xE
/** 386 Trapgate selector. */
02434 #define X86_SEL_TYPE_SYS_386_TRAP_GATE      0xF
/** @} */

/** @name AMD64 System Selector Types.
 * @{ */
#define AMD64_SEL_TYPE_SYS_LDT              2
/** 286 TSS selector - Busy. */
02441 #define AMD64_SEL_TYPE_SYS_TSS_AVAIL        9
/** 386 TSS selector - Busy. */
02443 #define AMD64_SEL_TYPE_SYS_TSS_BUSY         0xB
/** 386 Callgate selector. */
02445 #define AMD64_SEL_TYPE_SYS_CALL_GATE        0xC
/** 386 Interruptgate selector. */
02447 #define AMD64_SEL_TYPE_SYS_INT_GATE         0xE
/** 386 Trapgate selector. */
02449 #define AMD64_SEL_TYPE_SYS_TRAP_GATE        0xF
/** @} */

/** @} */


/** @name Descriptor Table Entry Flag Masks.
 * These are for the 2nd 32-bit word of a descriptor.
 * @{ */
/** Bits 8-11 - TYPE - Descriptor type mask. */
02459 #define X86_DESC_TYPE_MASK                  (RT_BIT(8) | RT_BIT(9) | RT_BIT(10) | RT_BIT(11))
/** Bit 12 - S - System (=0) or Code/Data (=1). */
02461 #define X86_DESC_S                          RT_BIT(12)
/** Bits 13-14 - DPL - Descriptor Privilege Level. */
02463 #define X86_DESC_DPL                       (RT_BIT(13) | RT_BIT(14))
/** Bit 15 - P - Present. */
02465 #define X86_DESC_P                          RT_BIT(15)
/** Bit 20 - AVL - Available for system software. */
02467 #define X86_DESC_AVL                        RT_BIT(20)
/** Bit 22 - DB - Default operation size. 0 = 16 bit, 1 = 32 bit. */
02469 #define X86_DESC_DB                         RT_BIT(22)
/** Bit 23 - G - Granularity of the limit. If set 4KB granularity is
 * used, if clear byte. */
02472 #define X86_DESC_G                          RT_BIT(23)
/** @} */

/** @} */

/** @name Task segment.
 * @{
 */
#pragma pack(1)
02481 typedef struct X86TSS32
{
    /** Back link to previous task. (static) */
02484     RTSEL       selPrev;
    uint16_t    padding1;
    /** Ring-0 stack pointer. (static) */
02487     uint32_t    esp0;
    /** Ring-0 stack segment. (static) */
02489     RTSEL       ss0;
    uint16_t    padding_ss0;
    /** Ring-1 stack pointer. (static) */
02492     uint32_t    esp1;
    /** Ring-1 stack segment. (static) */
02494     RTSEL       ss1;
    uint16_t    padding_ss1;
    /** Ring-2 stack pointer. (static) */
02497     uint32_t    esp2;
    /** Ring-2 stack segment. (static) */
02499     RTSEL       ss2;
    uint16_t    padding_ss2;
    /** Page directory for the task. (static) */
02502     uint32_t    cr3;
    /** EIP before task switch. */
02504     uint32_t    eip;
    /** EFLAGS before task switch. */
02506     uint32_t    eflags;
    /** EAX before task switch. */
02508     uint32_t    eax;
    /** ECX before task switch. */
02510     uint32_t    ecx;
    /** EDX before task switch. */
02512     uint32_t    edx;
    /** EBX before task switch. */
02514     uint32_t    ebx;
    /** ESP before task switch. */
02516     uint32_t    esp;
    /** EBP before task switch. */
02518     uint32_t    ebp;
    /** ESI before task switch. */
02520     uint32_t    esi;
    /** EDI before task switch. */
02522     uint32_t    edi;
    /** ES before task switch. */
02524     RTSEL       es;
    uint16_t    padding_es;
    /** CS before task switch. */
02527     RTSEL       cs;
    uint16_t    padding_cs;
    /** SS before task switch. */
02530     RTSEL       ss;
    uint16_t    padding_ss;
    /** DS before task switch. */
02533     RTSEL       ds;
    uint16_t    padding_ds;
    /** FS before task switch. */
02536     RTSEL       fs;
    uint16_t    padding_fs;
    /** GS before task switch. */
02539     RTSEL       gs;
    uint16_t    padding_gs;
    /** LDTR before task switch. */
02542     RTSEL       selLdt;
    uint16_t    padding_ldt;
    /** Debug trap flag */
02545     uint16_t    fDebugTrap;
    /** Offset relative to the TSS of the start of the I/O Bitmap
     * and the end of the interrupt redirection bitmap. */
02548     uint16_t    offIoBitmap;
    /** 32 bytes for the virtual interrupt redirection bitmap. (VME) */
02550     uint8_t     IntRedirBitmap[32];
} X86TSS32;
#pragma pack()
/** Pointer to task segment. */
02554 typedef X86TSS32 *PX86TSS32;
/** Pointer to const task segment. */
02556 typedef const X86TSS32 *PCX86TSS32;
/** @} */


/** @name 64 bits Task segment.
 * @{
 */
#pragma pack(1)
02564 typedef struct X86TSS64
{
    /** Reserved. */
02567     uint32_t    u32Reserved;
    /** Ring-0 stack pointer. (static) */
02569     uint64_t    rsp0;
    /** Ring-1 stack pointer. (static) */
02571     uint64_t    rsp1;
    /** Ring-2 stack pointer. (static) */
02573     uint64_t    rsp2;
    /** Reserved. */
02575     uint32_t    u32Reserved2[2];
    /* IST */
    uint64_t    ist1;
    uint64_t    ist2;
    uint64_t    ist3;
    uint64_t    ist4;
    uint64_t    ist5;
    uint64_t    ist6;
    uint64_t    ist7;
    /* Reserved. */
    uint16_t    u16Reserved[5];
    /** Offset relative to the TSS of the start of the I/O Bitmap
     * and the end of the interrupt redirection bitmap. */
02588     uint16_t    offIoBitmap;
    /** 32 bytes for the virtual interrupt redirection bitmap. (VME) */
02590     uint8_t     IntRedirBitmap[32];
} X86TSS64;
#pragma pack()
/** Pointer to task segment. */
02594 typedef X86TSS64 *PX86TSS64;
/** Pointer to const task segment. */
02596 typedef const X86TSS64 *PCX86TSS64;
AssertCompileSize(X86TSS64, 136);

/** @} */


/** @name Selectors.
 * @{
 */

/**
 * The shift used to convert a selector from and to index an index (C).
 */
02609 #define X86_SEL_SHIFT       3

/**
 * The mask used to mask off the table indicator and CPL of an selector.
 */
02614 #define X86_SEL_MASK        0xfff8

/**
 * The bit indicating that a selector is in the LDT and not in the GDT.
 */
02619 #define X86_SEL_LDT         0x0004
/**
 * The bit mask for getting the RPL of a selector.
 */
02623 #define X86_SEL_RPL         0x0003

/** @} */


/**
 * x86 Exceptions/Faults/Traps.
 */
02631 typedef enum X86XCPT
{
    /** \#DE - Divide error. */
02634     X86_XCPT_DE = 0x00,
    /** \#DB - Debug event (single step, DRx, ..) */
02636     X86_XCPT_DB = 0x01,
    /** NMI - Non-Maskable Interrupt */
02638     X86_XCPT_NMI = 0x02,
    /** \#BP - Breakpoint (INT3). */
02640     X86_XCPT_BP = 0x03,
    /** \#OF - Overflow (INTO). */
02642     X86_XCPT_OF = 0x04,
    /** \#BR - Bound range exceeded (BOUND). */
02644     X86_XCPT_BR = 0x05,
    /** \#UD - Undefined opcode. */
02646     X86_XCPT_UD = 0x06,
    /** \#NM - Device not available (math coprocessor device). */
02648     X86_XCPT_NM = 0x07,
    /** \#DF - Double fault. */
02650     X86_XCPT_DF = 0x08,
    /** ??? - Coprocessor segment overrun (obsolete). */
02652     X86_XCPT_CO_SEG_OVERRUN = 0x09,
    /** \#TS - Taskswitch (TSS). */
02654     X86_XCPT_TS = 0x0a,
    /** \#NP - Segment no present. */
02656     X86_XCPT_NP = 0x0b,
    /** \#SS - Stack segment fault. */
02658     X86_XCPT_SS = 0x0c,
    /** \#GP - General protection fault. */
02660     X86_XCPT_GP = 0x0d,
    /** \#PF - Page fault. */
02662     X86_XCPT_PF = 0x0e,
    /* 0x0f is reserved. */
    /** \#MF - Math fault (FPU). */
02665     X86_XCPT_MF = 0x10,
    /** \#AC - Alignment check. */
02667     X86_XCPT_AC = 0x11,
    /** \#MC - Machine check. */
02669     X86_XCPT_MC = 0x12,
    /** \#XF - SIMD Floating-Pointer Exception. */
02671     X86_XCPT_XF = 0x13
} X86XCPT;
/** Pointer to a x86 exception code. */
02674 typedef X86XCPT *PX86XCPT;
/** Pointer to a const x86 exception code. */
02676 typedef const X86XCPT *PCX86XCPT;


/** @name Trap Error Codes
 * @{
 */
/** External indicator. */
02683 #define X86_TRAP_ERR_EXTERNAL       1
/** IDT indicator. */
02685 #define X86_TRAP_ERR_IDT            2
/** Descriptor table indicator - If set LDT, if clear GDT. */
02687 #define X86_TRAP_ERR_TI             4
/** Mask for getting the selector. */
02689 #define X86_TRAP_ERR_SEL_MASK       0xfff8
/** Shift for getting the selector table index (C type index). */
02691 #define X86_TRAP_ERR_SEL_SHIFT      3
/** @} */


/** @name \#PF Trap Error Codes
 * @{
 */
/** Bit 0 -   P - Not present (clear) or page level protection (set) fault. */
02699 #define X86_TRAP_PF_P               RT_BIT(0)
/** Bit 1 - R/W - Read (clear) or write (set) access. */
02701 #define X86_TRAP_PF_RW              RT_BIT(1)
/** Bit 2 - U/S - CPU executing in user mode (set) or supervisor mode (clear). */
02703 #define X86_TRAP_PF_US              RT_BIT(2)
/** Bit 3 - RSVD- Reserved bit violation (set), i.e. reserved bit was set to 1. */
02705 #define X86_TRAP_PF_RSVD            RT_BIT(3)
/** Bit 4 - I/D - Instruction fetch (set) / Data access (clear) - PAE + NXE. */
02707 #define X86_TRAP_PF_ID              RT_BIT(4)
/** @} */

#pragma pack(1)
/**
 * 32-bit IDTR/GDTR.
 */
02714 typedef struct X86XDTR32
{
    /** Size of the descriptor table. */
02717     uint16_t    cb;
    /** Address of the descriptor table. */
02719     uint32_t    uAddr;
} X86XDTR32, *PX86XDTR32;
#pragma pack()

#pragma pack(1)
/**
 * 64-bit IDTR/GDTR.
 */
02727 typedef struct X86XDTR64
{
    /** Size of the descriptor table. */
02730     uint16_t    cb;
    /** Address of the descriptor table. */
02732     uint64_t    uAddr;
} X86XDTR64, *PX86XDTR64;
#pragma pack()

/** @} */

#endif


Generated by  Doxygen 1.6.0   Back to index