xref: /openbmc/qemu/target/i386/cpu.h (revision cdec2b753b487d9e8aab028231c35d87789ea083)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  * i386 virtual CPU header
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  *  Copyright (c) 2003 Fabrice Bellard
5fcf5ef2aSThomas Huth  *
6fcf5ef2aSThomas Huth  * This library is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth  * modify it under the terms of the GNU Lesser General Public
8fcf5ef2aSThomas Huth  * License as published by the Free Software Foundation; either
9d9ff33adSChetan Pant  * version 2.1 of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth  *
11fcf5ef2aSThomas Huth  * This library is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14fcf5ef2aSThomas Huth  * Lesser General Public License for more details.
15fcf5ef2aSThomas Huth  *
16fcf5ef2aSThomas Huth  * You should have received a copy of the GNU Lesser General Public
17fcf5ef2aSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18fcf5ef2aSThomas Huth  */
19fcf5ef2aSThomas Huth 
20fcf5ef2aSThomas Huth #ifndef I386_CPU_H
21fcf5ef2aSThomas Huth #define I386_CPU_H
22fcf5ef2aSThomas Huth 
2314a48c1dSMarkus Armbruster #include "sysemu/tcg.h"
24fcf5ef2aSThomas Huth #include "cpu-qom.h"
25a9dc68d9SClaudio Fontana #include "kvm/hyperv-proto.h"
26c97d6d2cSSergio Andres Gomez Del Real #include "exec/cpu-defs.h"
2730d6ff66SVitaly Kuznetsov #include "qapi/qapi-types-common.h"
28c97d6d2cSSergio Andres Gomez Del Real 
2972c1701fSAlex Bennée /* The x86 has a strong memory model with some store-after-load re-ordering */
3072c1701fSAlex Bennée #define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
3172c1701fSAlex Bennée 
32e24fd076SDongjiu Geng #define KVM_HAVE_MCE_INJECTION 1
33e24fd076SDongjiu Geng 
34fcf5ef2aSThomas Huth /* support for self modifying code even if the modified instruction is
35fcf5ef2aSThomas Huth    close to the modifying instruction */
36fcf5ef2aSThomas Huth #define TARGET_HAS_PRECISE_SMC
37fcf5ef2aSThomas Huth 
38fcf5ef2aSThomas Huth #ifdef TARGET_X86_64
39fcf5ef2aSThomas Huth #define I386_ELF_MACHINE  EM_X86_64
40fcf5ef2aSThomas Huth #define ELF_MACHINE_UNAME "x86_64"
41fcf5ef2aSThomas Huth #else
42fcf5ef2aSThomas Huth #define I386_ELF_MACHINE  EM_386
43fcf5ef2aSThomas Huth #define ELF_MACHINE_UNAME "i686"
44fcf5ef2aSThomas Huth #endif
45fcf5ef2aSThomas Huth 
466701d81dSPaolo Bonzini enum {
476701d81dSPaolo Bonzini     R_EAX = 0,
486701d81dSPaolo Bonzini     R_ECX = 1,
496701d81dSPaolo Bonzini     R_EDX = 2,
506701d81dSPaolo Bonzini     R_EBX = 3,
516701d81dSPaolo Bonzini     R_ESP = 4,
526701d81dSPaolo Bonzini     R_EBP = 5,
536701d81dSPaolo Bonzini     R_ESI = 6,
546701d81dSPaolo Bonzini     R_EDI = 7,
556701d81dSPaolo Bonzini     R_R8 = 8,
566701d81dSPaolo Bonzini     R_R9 = 9,
576701d81dSPaolo Bonzini     R_R10 = 10,
586701d81dSPaolo Bonzini     R_R11 = 11,
596701d81dSPaolo Bonzini     R_R12 = 12,
606701d81dSPaolo Bonzini     R_R13 = 13,
616701d81dSPaolo Bonzini     R_R14 = 14,
626701d81dSPaolo Bonzini     R_R15 = 15,
63fcf5ef2aSThomas Huth 
646701d81dSPaolo Bonzini     R_AL = 0,
656701d81dSPaolo Bonzini     R_CL = 1,
666701d81dSPaolo Bonzini     R_DL = 2,
676701d81dSPaolo Bonzini     R_BL = 3,
686701d81dSPaolo Bonzini     R_AH = 4,
696701d81dSPaolo Bonzini     R_CH = 5,
706701d81dSPaolo Bonzini     R_DH = 6,
716701d81dSPaolo Bonzini     R_BH = 7,
726701d81dSPaolo Bonzini };
73fcf5ef2aSThomas Huth 
746701d81dSPaolo Bonzini typedef enum X86Seg {
756701d81dSPaolo Bonzini     R_ES = 0,
766701d81dSPaolo Bonzini     R_CS = 1,
776701d81dSPaolo Bonzini     R_SS = 2,
786701d81dSPaolo Bonzini     R_DS = 3,
796701d81dSPaolo Bonzini     R_FS = 4,
806701d81dSPaolo Bonzini     R_GS = 5,
816701d81dSPaolo Bonzini     R_LDTR = 6,
826701d81dSPaolo Bonzini     R_TR = 7,
836701d81dSPaolo Bonzini } X86Seg;
84fcf5ef2aSThomas Huth 
85fcf5ef2aSThomas Huth /* segment descriptor fields */
86c97d6d2cSSergio Andres Gomez Del Real #define DESC_G_SHIFT    23
87c97d6d2cSSergio Andres Gomez Del Real #define DESC_G_MASK     (1 << DESC_G_SHIFT)
88fcf5ef2aSThomas Huth #define DESC_B_SHIFT    22
89fcf5ef2aSThomas Huth #define DESC_B_MASK     (1 << DESC_B_SHIFT)
90fcf5ef2aSThomas Huth #define DESC_L_SHIFT    21 /* x86_64 only : 64 bit code segment */
91fcf5ef2aSThomas Huth #define DESC_L_MASK     (1 << DESC_L_SHIFT)
92c97d6d2cSSergio Andres Gomez Del Real #define DESC_AVL_SHIFT  20
93c97d6d2cSSergio Andres Gomez Del Real #define DESC_AVL_MASK   (1 << DESC_AVL_SHIFT)
94c97d6d2cSSergio Andres Gomez Del Real #define DESC_P_SHIFT    15
95c97d6d2cSSergio Andres Gomez Del Real #define DESC_P_MASK     (1 << DESC_P_SHIFT)
96fcf5ef2aSThomas Huth #define DESC_DPL_SHIFT  13
97fcf5ef2aSThomas Huth #define DESC_DPL_MASK   (3 << DESC_DPL_SHIFT)
98c97d6d2cSSergio Andres Gomez Del Real #define DESC_S_SHIFT    12
99c97d6d2cSSergio Andres Gomez Del Real #define DESC_S_MASK     (1 << DESC_S_SHIFT)
100fcf5ef2aSThomas Huth #define DESC_TYPE_SHIFT 8
101fcf5ef2aSThomas Huth #define DESC_TYPE_MASK  (15 << DESC_TYPE_SHIFT)
102fcf5ef2aSThomas Huth #define DESC_A_MASK     (1 << 8)
103fcf5ef2aSThomas Huth 
104fcf5ef2aSThomas Huth #define DESC_CS_MASK    (1 << 11) /* 1=code segment 0=data segment */
105fcf5ef2aSThomas Huth #define DESC_C_MASK     (1 << 10) /* code: conforming */
106fcf5ef2aSThomas Huth #define DESC_R_MASK     (1 << 9)  /* code: readable */
107fcf5ef2aSThomas Huth 
108fcf5ef2aSThomas Huth #define DESC_E_MASK     (1 << 10) /* data: expansion direction */
109fcf5ef2aSThomas Huth #define DESC_W_MASK     (1 << 9)  /* data: writable */
110fcf5ef2aSThomas Huth 
111fcf5ef2aSThomas Huth #define DESC_TSS_BUSY_MASK (1 << 9)
112fcf5ef2aSThomas Huth 
113fcf5ef2aSThomas Huth /* eflags masks */
114fcf5ef2aSThomas Huth #define CC_C    0x0001
115fcf5ef2aSThomas Huth #define CC_P    0x0004
116fcf5ef2aSThomas Huth #define CC_A    0x0010
117fcf5ef2aSThomas Huth #define CC_Z    0x0040
118fcf5ef2aSThomas Huth #define CC_S    0x0080
119fcf5ef2aSThomas Huth #define CC_O    0x0800
120fcf5ef2aSThomas Huth 
121fcf5ef2aSThomas Huth #define TF_SHIFT   8
122fcf5ef2aSThomas Huth #define IOPL_SHIFT 12
123fcf5ef2aSThomas Huth #define VM_SHIFT   17
124fcf5ef2aSThomas Huth 
125fcf5ef2aSThomas Huth #define TF_MASK                 0x00000100
126fcf5ef2aSThomas Huth #define IF_MASK                 0x00000200
127fcf5ef2aSThomas Huth #define DF_MASK                 0x00000400
128fcf5ef2aSThomas Huth #define IOPL_MASK               0x00003000
129fcf5ef2aSThomas Huth #define NT_MASK                 0x00004000
130fcf5ef2aSThomas Huth #define RF_MASK                 0x00010000
131fcf5ef2aSThomas Huth #define VM_MASK                 0x00020000
132fcf5ef2aSThomas Huth #define AC_MASK                 0x00040000
133fcf5ef2aSThomas Huth #define VIF_MASK                0x00080000
134fcf5ef2aSThomas Huth #define VIP_MASK                0x00100000
135fcf5ef2aSThomas Huth #define ID_MASK                 0x00200000
136fcf5ef2aSThomas Huth 
137fcf5ef2aSThomas Huth /* hidden flags - used internally by qemu to represent additional cpu
138fcf5ef2aSThomas Huth    states. Only the INHIBIT_IRQ, SMM and SVMI are not redundant. We
139fcf5ef2aSThomas Huth    avoid using the IOPL_MASK, TF_MASK, VM_MASK and AC_MASK bit
140fcf5ef2aSThomas Huth    positions to ease oring with eflags. */
141fcf5ef2aSThomas Huth /* current cpl */
142fcf5ef2aSThomas Huth #define HF_CPL_SHIFT         0
143fcf5ef2aSThomas Huth /* true if hardware interrupts must be disabled for next instruction */
144fcf5ef2aSThomas Huth #define HF_INHIBIT_IRQ_SHIFT 3
145fcf5ef2aSThomas Huth /* 16 or 32 segments */
146fcf5ef2aSThomas Huth #define HF_CS32_SHIFT        4
147fcf5ef2aSThomas Huth #define HF_SS32_SHIFT        5
148fcf5ef2aSThomas Huth /* zero base for DS, ES and SS : can be '0' only in 32 bit CS segment */
149fcf5ef2aSThomas Huth #define HF_ADDSEG_SHIFT      6
150fcf5ef2aSThomas Huth /* copy of CR0.PE (protected mode) */
151fcf5ef2aSThomas Huth #define HF_PE_SHIFT          7
152fcf5ef2aSThomas Huth #define HF_TF_SHIFT          8 /* must be same as eflags */
153fcf5ef2aSThomas Huth #define HF_MP_SHIFT          9 /* the order must be MP, EM, TS */
154fcf5ef2aSThomas Huth #define HF_EM_SHIFT         10
155fcf5ef2aSThomas Huth #define HF_TS_SHIFT         11
156fcf5ef2aSThomas Huth #define HF_IOPL_SHIFT       12 /* must be same as eflags */
157fcf5ef2aSThomas Huth #define HF_LMA_SHIFT        14 /* only used on x86_64: long mode active */
158fcf5ef2aSThomas Huth #define HF_CS64_SHIFT       15 /* only used on x86_64: 64 bit code segment  */
159fcf5ef2aSThomas Huth #define HF_RF_SHIFT         16 /* must be same as eflags */
160fcf5ef2aSThomas Huth #define HF_VM_SHIFT         17 /* must be same as eflags */
161fcf5ef2aSThomas Huth #define HF_AC_SHIFT         18 /* must be same as eflags */
162fcf5ef2aSThomas Huth #define HF_SMM_SHIFT        19 /* CPU in SMM mode */
163fcf5ef2aSThomas Huth #define HF_SVME_SHIFT       20 /* SVME enabled (copy of EFER.SVME) */
164f8dc4c64SPaolo Bonzini #define HF_GUEST_SHIFT      21 /* SVM intercepts are active */
165fcf5ef2aSThomas Huth #define HF_OSFXSR_SHIFT     22 /* CR4.OSFXSR */
166fcf5ef2aSThomas Huth #define HF_SMAP_SHIFT       23 /* CR4.SMAP */
167fcf5ef2aSThomas Huth #define HF_IOBPT_SHIFT      24 /* an io breakpoint enabled */
168fcf5ef2aSThomas Huth #define HF_MPX_EN_SHIFT     25 /* MPX Enabled (CR4+XCR0+BNDCFGx) */
169fcf5ef2aSThomas Huth #define HF_MPX_IU_SHIFT     26 /* BND registers in-use */
170637f1ee3SGareth Webb #define HF_UMIP_SHIFT       27 /* CR4.UMIP */
171fcf5ef2aSThomas Huth 
172fcf5ef2aSThomas Huth #define HF_CPL_MASK          (3 << HF_CPL_SHIFT)
173fcf5ef2aSThomas Huth #define HF_INHIBIT_IRQ_MASK  (1 << HF_INHIBIT_IRQ_SHIFT)
174fcf5ef2aSThomas Huth #define HF_CS32_MASK         (1 << HF_CS32_SHIFT)
175fcf5ef2aSThomas Huth #define HF_SS32_MASK         (1 << HF_SS32_SHIFT)
176fcf5ef2aSThomas Huth #define HF_ADDSEG_MASK       (1 << HF_ADDSEG_SHIFT)
177fcf5ef2aSThomas Huth #define HF_PE_MASK           (1 << HF_PE_SHIFT)
178fcf5ef2aSThomas Huth #define HF_TF_MASK           (1 << HF_TF_SHIFT)
179fcf5ef2aSThomas Huth #define HF_MP_MASK           (1 << HF_MP_SHIFT)
180fcf5ef2aSThomas Huth #define HF_EM_MASK           (1 << HF_EM_SHIFT)
181fcf5ef2aSThomas Huth #define HF_TS_MASK           (1 << HF_TS_SHIFT)
182fcf5ef2aSThomas Huth #define HF_IOPL_MASK         (3 << HF_IOPL_SHIFT)
183fcf5ef2aSThomas Huth #define HF_LMA_MASK          (1 << HF_LMA_SHIFT)
184fcf5ef2aSThomas Huth #define HF_CS64_MASK         (1 << HF_CS64_SHIFT)
185fcf5ef2aSThomas Huth #define HF_RF_MASK           (1 << HF_RF_SHIFT)
186fcf5ef2aSThomas Huth #define HF_VM_MASK           (1 << HF_VM_SHIFT)
187fcf5ef2aSThomas Huth #define HF_AC_MASK           (1 << HF_AC_SHIFT)
188fcf5ef2aSThomas Huth #define HF_SMM_MASK          (1 << HF_SMM_SHIFT)
189fcf5ef2aSThomas Huth #define HF_SVME_MASK         (1 << HF_SVME_SHIFT)
190f8dc4c64SPaolo Bonzini #define HF_GUEST_MASK        (1 << HF_GUEST_SHIFT)
191fcf5ef2aSThomas Huth #define HF_OSFXSR_MASK       (1 << HF_OSFXSR_SHIFT)
192fcf5ef2aSThomas Huth #define HF_SMAP_MASK         (1 << HF_SMAP_SHIFT)
193fcf5ef2aSThomas Huth #define HF_IOBPT_MASK        (1 << HF_IOBPT_SHIFT)
194fcf5ef2aSThomas Huth #define HF_MPX_EN_MASK       (1 << HF_MPX_EN_SHIFT)
195fcf5ef2aSThomas Huth #define HF_MPX_IU_MASK       (1 << HF_MPX_IU_SHIFT)
196637f1ee3SGareth Webb #define HF_UMIP_MASK         (1 << HF_UMIP_SHIFT)
197fcf5ef2aSThomas Huth 
198fcf5ef2aSThomas Huth /* hflags2 */
199fcf5ef2aSThomas Huth 
200fcf5ef2aSThomas Huth #define HF2_GIF_SHIFT            0 /* if set CPU takes interrupts */
201fcf5ef2aSThomas Huth #define HF2_HIF_SHIFT            1 /* value of IF_MASK when entering SVM */
202fcf5ef2aSThomas Huth #define HF2_NMI_SHIFT            2 /* CPU serving NMI */
203fcf5ef2aSThomas Huth #define HF2_VINTR_SHIFT          3 /* value of V_INTR_MASKING bit */
204fcf5ef2aSThomas Huth #define HF2_SMM_INSIDE_NMI_SHIFT 4 /* CPU serving SMI nested inside NMI */
205fcf5ef2aSThomas Huth #define HF2_MPX_PR_SHIFT         5 /* BNDCFGx.BNDPRESERVE */
206fe441054SJan Kiszka #define HF2_NPT_SHIFT            6 /* Nested Paging enabled */
207bf13bfabSPaolo Bonzini #define HF2_IGNNE_SHIFT          7 /* Ignore CR0.NE=0 */
208b67e2796SLara Lazier #define HF2_VGIF_SHIFT           8 /* Can take VIRQ*/
209fcf5ef2aSThomas Huth 
210fcf5ef2aSThomas Huth #define HF2_GIF_MASK            (1 << HF2_GIF_SHIFT)
211fcf5ef2aSThomas Huth #define HF2_HIF_MASK            (1 << HF2_HIF_SHIFT)
212fcf5ef2aSThomas Huth #define HF2_NMI_MASK            (1 << HF2_NMI_SHIFT)
213fcf5ef2aSThomas Huth #define HF2_VINTR_MASK          (1 << HF2_VINTR_SHIFT)
214fcf5ef2aSThomas Huth #define HF2_SMM_INSIDE_NMI_MASK (1 << HF2_SMM_INSIDE_NMI_SHIFT)
215fcf5ef2aSThomas Huth #define HF2_MPX_PR_MASK         (1 << HF2_MPX_PR_SHIFT)
216fe441054SJan Kiszka #define HF2_NPT_MASK            (1 << HF2_NPT_SHIFT)
217bf13bfabSPaolo Bonzini #define HF2_IGNNE_MASK          (1 << HF2_IGNNE_SHIFT)
218b67e2796SLara Lazier #define HF2_VGIF_MASK           (1 << HF2_VGIF_SHIFT)
219fcf5ef2aSThomas Huth 
220fcf5ef2aSThomas Huth #define CR0_PE_SHIFT 0
221fcf5ef2aSThomas Huth #define CR0_MP_SHIFT 1
222fcf5ef2aSThomas Huth 
223fcf5ef2aSThomas Huth #define CR0_PE_MASK  (1U << 0)
224fcf5ef2aSThomas Huth #define CR0_MP_MASK  (1U << 1)
225fcf5ef2aSThomas Huth #define CR0_EM_MASK  (1U << 2)
226fcf5ef2aSThomas Huth #define CR0_TS_MASK  (1U << 3)
227fcf5ef2aSThomas Huth #define CR0_ET_MASK  (1U << 4)
228fcf5ef2aSThomas Huth #define CR0_NE_MASK  (1U << 5)
229fcf5ef2aSThomas Huth #define CR0_WP_MASK  (1U << 16)
230fcf5ef2aSThomas Huth #define CR0_AM_MASK  (1U << 18)
231498df2a7SLara Lazier #define CR0_NW_MASK  (1U << 29)
232498df2a7SLara Lazier #define CR0_CD_MASK  (1U << 30)
233fcf5ef2aSThomas Huth #define CR0_PG_MASK  (1U << 31)
234fcf5ef2aSThomas Huth 
235fcf5ef2aSThomas Huth #define CR4_VME_MASK  (1U << 0)
236fcf5ef2aSThomas Huth #define CR4_PVI_MASK  (1U << 1)
237fcf5ef2aSThomas Huth #define CR4_TSD_MASK  (1U << 2)
238fcf5ef2aSThomas Huth #define CR4_DE_MASK   (1U << 3)
239fcf5ef2aSThomas Huth #define CR4_PSE_MASK  (1U << 4)
240fcf5ef2aSThomas Huth #define CR4_PAE_MASK  (1U << 5)
241fcf5ef2aSThomas Huth #define CR4_MCE_MASK  (1U << 6)
242fcf5ef2aSThomas Huth #define CR4_PGE_MASK  (1U << 7)
243fcf5ef2aSThomas Huth #define CR4_PCE_MASK  (1U << 8)
244fcf5ef2aSThomas Huth #define CR4_OSFXSR_SHIFT 9
245fcf5ef2aSThomas Huth #define CR4_OSFXSR_MASK (1U << CR4_OSFXSR_SHIFT)
246fcf5ef2aSThomas Huth #define CR4_OSXMMEXCPT_MASK  (1U << 10)
247213ff024SLara Lazier #define CR4_UMIP_MASK   (1U << 11)
2486c7c3c21SKirill A. Shutemov #define CR4_LA57_MASK   (1U << 12)
249fcf5ef2aSThomas Huth #define CR4_VMXE_MASK   (1U << 13)
250fcf5ef2aSThomas Huth #define CR4_SMXE_MASK   (1U << 14)
251fcf5ef2aSThomas Huth #define CR4_FSGSBASE_MASK (1U << 16)
252fcf5ef2aSThomas Huth #define CR4_PCIDE_MASK  (1U << 17)
253fcf5ef2aSThomas Huth #define CR4_OSXSAVE_MASK (1U << 18)
254fcf5ef2aSThomas Huth #define CR4_SMEP_MASK   (1U << 20)
255fcf5ef2aSThomas Huth #define CR4_SMAP_MASK   (1U << 21)
256fcf5ef2aSThomas Huth #define CR4_PKE_MASK   (1U << 22)
257e7e7bdabSPaolo Bonzini #define CR4_PKS_MASK   (1U << 24)
258fcf5ef2aSThomas Huth 
259213ff024SLara Lazier #define CR4_RESERVED_MASK \
260213ff024SLara Lazier (~(target_ulong)(CR4_VME_MASK | CR4_PVI_MASK | CR4_TSD_MASK \
261213ff024SLara Lazier                 | CR4_DE_MASK | CR4_PSE_MASK | CR4_PAE_MASK \
262213ff024SLara Lazier                 | CR4_MCE_MASK | CR4_PGE_MASK | CR4_PCE_MASK \
263213ff024SLara Lazier                 | CR4_OSFXSR_MASK | CR4_OSXMMEXCPT_MASK | CR4_UMIP_MASK \
26469e3895fSDaniel P. Berrangé                 | CR4_LA57_MASK \
265213ff024SLara Lazier                 | CR4_FSGSBASE_MASK | CR4_PCIDE_MASK | CR4_OSXSAVE_MASK \
266213ff024SLara Lazier                 | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_PKS_MASK))
267213ff024SLara Lazier 
268fcf5ef2aSThomas Huth #define DR6_BD          (1 << 13)
269fcf5ef2aSThomas Huth #define DR6_BS          (1 << 14)
270fcf5ef2aSThomas Huth #define DR6_BT          (1 << 15)
271fcf5ef2aSThomas Huth #define DR6_FIXED_1     0xffff0ff0
272fcf5ef2aSThomas Huth 
273fcf5ef2aSThomas Huth #define DR7_GD          (1 << 13)
274fcf5ef2aSThomas Huth #define DR7_TYPE_SHIFT  16
275fcf5ef2aSThomas Huth #define DR7_LEN_SHIFT   18
276fcf5ef2aSThomas Huth #define DR7_FIXED_1     0x00000400
277fcf5ef2aSThomas Huth #define DR7_GLOBAL_BP_MASK   0xaa
278fcf5ef2aSThomas Huth #define DR7_LOCAL_BP_MASK    0x55
279fcf5ef2aSThomas Huth #define DR7_MAX_BP           4
280fcf5ef2aSThomas Huth #define DR7_TYPE_BP_INST     0x0
281fcf5ef2aSThomas Huth #define DR7_TYPE_DATA_WR     0x1
282fcf5ef2aSThomas Huth #define DR7_TYPE_IO_RW       0x2
283fcf5ef2aSThomas Huth #define DR7_TYPE_DATA_RW     0x3
284fcf5ef2aSThomas Huth 
285533883fdSPaolo Bonzini #define DR_RESERVED_MASK 0xffffffff00000000ULL
286533883fdSPaolo Bonzini 
287fcf5ef2aSThomas Huth #define PG_PRESENT_BIT  0
288fcf5ef2aSThomas Huth #define PG_RW_BIT       1
289fcf5ef2aSThomas Huth #define PG_USER_BIT     2
290fcf5ef2aSThomas Huth #define PG_PWT_BIT      3
291fcf5ef2aSThomas Huth #define PG_PCD_BIT      4
292fcf5ef2aSThomas Huth #define PG_ACCESSED_BIT 5
293fcf5ef2aSThomas Huth #define PG_DIRTY_BIT    6
294fcf5ef2aSThomas Huth #define PG_PSE_BIT      7
295fcf5ef2aSThomas Huth #define PG_GLOBAL_BIT   8
296fcf5ef2aSThomas Huth #define PG_PSE_PAT_BIT  12
297fcf5ef2aSThomas Huth #define PG_PKRU_BIT     59
298fcf5ef2aSThomas Huth #define PG_NX_BIT       63
299fcf5ef2aSThomas Huth 
300fcf5ef2aSThomas Huth #define PG_PRESENT_MASK  (1 << PG_PRESENT_BIT)
301fcf5ef2aSThomas Huth #define PG_RW_MASK       (1 << PG_RW_BIT)
302fcf5ef2aSThomas Huth #define PG_USER_MASK     (1 << PG_USER_BIT)
303fcf5ef2aSThomas Huth #define PG_PWT_MASK      (1 << PG_PWT_BIT)
304fcf5ef2aSThomas Huth #define PG_PCD_MASK      (1 << PG_PCD_BIT)
305fcf5ef2aSThomas Huth #define PG_ACCESSED_MASK (1 << PG_ACCESSED_BIT)
306fcf5ef2aSThomas Huth #define PG_DIRTY_MASK    (1 << PG_DIRTY_BIT)
307fcf5ef2aSThomas Huth #define PG_PSE_MASK      (1 << PG_PSE_BIT)
308fcf5ef2aSThomas Huth #define PG_GLOBAL_MASK   (1 << PG_GLOBAL_BIT)
309fcf5ef2aSThomas Huth #define PG_PSE_PAT_MASK  (1 << PG_PSE_PAT_BIT)
310fcf5ef2aSThomas Huth #define PG_ADDRESS_MASK  0x000ffffffffff000LL
311fcf5ef2aSThomas Huth #define PG_HI_USER_MASK  0x7ff0000000000000LL
312fcf5ef2aSThomas Huth #define PG_PKRU_MASK     (15ULL << PG_PKRU_BIT)
313fcf5ef2aSThomas Huth #define PG_NX_MASK       (1ULL << PG_NX_BIT)
314fcf5ef2aSThomas Huth 
315fcf5ef2aSThomas Huth #define PG_ERROR_W_BIT     1
316fcf5ef2aSThomas Huth 
317fcf5ef2aSThomas Huth #define PG_ERROR_P_MASK    0x01
318fcf5ef2aSThomas Huth #define PG_ERROR_W_MASK    (1 << PG_ERROR_W_BIT)
319fcf5ef2aSThomas Huth #define PG_ERROR_U_MASK    0x04
320fcf5ef2aSThomas Huth #define PG_ERROR_RSVD_MASK 0x08
321fcf5ef2aSThomas Huth #define PG_ERROR_I_D_MASK  0x10
322fcf5ef2aSThomas Huth #define PG_ERROR_PK_MASK   0x20
323fcf5ef2aSThomas Huth 
324616a89eaSPaolo Bonzini #define PG_MODE_PAE      (1 << 0)
325616a89eaSPaolo Bonzini #define PG_MODE_LMA      (1 << 1)
326616a89eaSPaolo Bonzini #define PG_MODE_NXE      (1 << 2)
327616a89eaSPaolo Bonzini #define PG_MODE_PSE      (1 << 3)
32831dd35ebSPaolo Bonzini #define PG_MODE_LA57     (1 << 4)
32931dd35ebSPaolo Bonzini #define PG_MODE_SVM_MASK MAKE_64BIT_MASK(0, 15)
33031dd35ebSPaolo Bonzini 
33131dd35ebSPaolo Bonzini /* Bits of CR4 that do not affect the NPT page format.  */
33231dd35ebSPaolo Bonzini #define PG_MODE_WP       (1 << 16)
33331dd35ebSPaolo Bonzini #define PG_MODE_PKE      (1 << 17)
33431dd35ebSPaolo Bonzini #define PG_MODE_PKS      (1 << 18)
33531dd35ebSPaolo Bonzini #define PG_MODE_SMEP     (1 << 19)
336616a89eaSPaolo Bonzini 
337fcf5ef2aSThomas Huth #define MCG_CTL_P       (1ULL<<8)   /* MCG_CAP register available */
338fcf5ef2aSThomas Huth #define MCG_SER_P       (1ULL<<24) /* MCA recovery/new status bits */
339fcf5ef2aSThomas Huth #define MCG_LMCE_P      (1ULL<<27) /* Local Machine Check Supported */
340fcf5ef2aSThomas Huth 
341fcf5ef2aSThomas Huth #define MCE_CAP_DEF     (MCG_CTL_P|MCG_SER_P)
342fcf5ef2aSThomas Huth #define MCE_BANKS_DEF   10
343fcf5ef2aSThomas Huth 
344fcf5ef2aSThomas Huth #define MCG_CAP_BANKS_MASK 0xff
345fcf5ef2aSThomas Huth 
346fcf5ef2aSThomas Huth #define MCG_STATUS_RIPV (1ULL<<0)   /* restart ip valid */
347fcf5ef2aSThomas Huth #define MCG_STATUS_EIPV (1ULL<<1)   /* ip points to correct instruction */
348fcf5ef2aSThomas Huth #define MCG_STATUS_MCIP (1ULL<<2)   /* machine check in progress */
349fcf5ef2aSThomas Huth #define MCG_STATUS_LMCE (1ULL<<3)   /* Local MCE signaled */
350fcf5ef2aSThomas Huth 
351fcf5ef2aSThomas Huth #define MCG_EXT_CTL_LMCE_EN (1ULL<<0) /* Local MCE enabled */
352fcf5ef2aSThomas Huth 
353fcf5ef2aSThomas Huth #define MCI_STATUS_VAL   (1ULL<<63)  /* valid error */
354fcf5ef2aSThomas Huth #define MCI_STATUS_OVER  (1ULL<<62)  /* previous errors lost */
355fcf5ef2aSThomas Huth #define MCI_STATUS_UC    (1ULL<<61)  /* uncorrected error */
356fcf5ef2aSThomas Huth #define MCI_STATUS_EN    (1ULL<<60)  /* error enabled */
357fcf5ef2aSThomas Huth #define MCI_STATUS_MISCV (1ULL<<59)  /* misc error reg. valid */
358fcf5ef2aSThomas Huth #define MCI_STATUS_ADDRV (1ULL<<58)  /* addr reg. valid */
359fcf5ef2aSThomas Huth #define MCI_STATUS_PCC   (1ULL<<57)  /* processor context corrupt */
360fcf5ef2aSThomas Huth #define MCI_STATUS_S     (1ULL<<56)  /* Signaled machine check */
361fcf5ef2aSThomas Huth #define MCI_STATUS_AR    (1ULL<<55)  /* Action required */
362fcf5ef2aSThomas Huth 
363fcf5ef2aSThomas Huth /* MISC register defines */
364fcf5ef2aSThomas Huth #define MCM_ADDR_SEGOFF  0      /* segment offset */
365fcf5ef2aSThomas Huth #define MCM_ADDR_LINEAR  1      /* linear address */
366fcf5ef2aSThomas Huth #define MCM_ADDR_PHYS    2      /* physical address */
367fcf5ef2aSThomas Huth #define MCM_ADDR_MEM     3      /* memory address */
368fcf5ef2aSThomas Huth #define MCM_ADDR_GENERIC 7      /* generic */
369fcf5ef2aSThomas Huth 
370fcf5ef2aSThomas Huth #define MSR_IA32_TSC                    0x10
371fcf5ef2aSThomas Huth #define MSR_IA32_APICBASE               0x1b
372fcf5ef2aSThomas Huth #define MSR_IA32_APICBASE_BSP           (1<<8)
373fcf5ef2aSThomas Huth #define MSR_IA32_APICBASE_ENABLE        (1<<11)
374fcf5ef2aSThomas Huth #define MSR_IA32_APICBASE_EXTD          (1 << 10)
375fcf5ef2aSThomas Huth #define MSR_IA32_APICBASE_BASE          (0xfffffU<<12)
376fcf5ef2aSThomas Huth #define MSR_IA32_FEATURE_CONTROL        0x0000003a
377fcf5ef2aSThomas Huth #define MSR_TSC_ADJUST                  0x0000003b
378a33a2cfeSPaolo Bonzini #define MSR_IA32_SPEC_CTRL              0x48
379cfeea0c0SKonrad Rzeszutek Wilk #define MSR_VIRT_SSBD                   0xc001011f
3808c80c99fSRobert Hoo #define MSR_IA32_PRED_CMD               0x49
3814e45aff3SPaolo Bonzini #define MSR_IA32_UCODE_REV              0x8b
382597360c0SXiaoyao Li #define MSR_IA32_CORE_CAPABILITY        0xcf
3832a9758c5SPaolo Bonzini 
3848c80c99fSRobert Hoo #define MSR_IA32_ARCH_CAPABILITIES      0x10a
3852a9758c5SPaolo Bonzini #define ARCH_CAP_TSX_CTRL_MSR		(1<<7)
3862a9758c5SPaolo Bonzini 
387ea39f9b6SLike Xu #define MSR_IA32_PERF_CAPABILITIES      0x345
388ea39f9b6SLike Xu 
3892a9758c5SPaolo Bonzini #define MSR_IA32_TSX_CTRL		0x122
390fcf5ef2aSThomas Huth #define MSR_IA32_TSCDEADLINE            0x6e0
391e7e7bdabSPaolo Bonzini #define MSR_IA32_PKRS                   0x6e1
392fcf5ef2aSThomas Huth 
393fcf5ef2aSThomas Huth #define FEATURE_CONTROL_LOCKED                    (1<<0)
3945c76b651SSean Christopherson #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX  (1ULL << 1)
395fcf5ef2aSThomas Huth #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
3965c76b651SSean Christopherson #define FEATURE_CONTROL_SGX_LC                    (1ULL << 17)
3975c76b651SSean Christopherson #define FEATURE_CONTROL_SGX                       (1ULL << 18)
398fcf5ef2aSThomas Huth #define FEATURE_CONTROL_LMCE                      (1<<20)
399fcf5ef2aSThomas Huth 
4005c76b651SSean Christopherson #define MSR_IA32_SGXLEPUBKEYHASH0       0x8c
4015c76b651SSean Christopherson #define MSR_IA32_SGXLEPUBKEYHASH1       0x8d
4025c76b651SSean Christopherson #define MSR_IA32_SGXLEPUBKEYHASH2       0x8e
4035c76b651SSean Christopherson #define MSR_IA32_SGXLEPUBKEYHASH3       0x8f
4045c76b651SSean Christopherson 
405fcf5ef2aSThomas Huth #define MSR_P6_PERFCTR0                 0xc1
406fcf5ef2aSThomas Huth 
407fcf5ef2aSThomas Huth #define MSR_IA32_SMBASE                 0x9e
408e13713dbSLiran Alon #define MSR_SMI_COUNT                   0x34
409027ac0cbSVladislav Yaroshchuk #define MSR_CORE_THREAD_COUNT           0x35
410fcf5ef2aSThomas Huth #define MSR_MTRRcap                     0xfe
411fcf5ef2aSThomas Huth #define MSR_MTRRcap_VCNT                8
412fcf5ef2aSThomas Huth #define MSR_MTRRcap_FIXRANGE_SUPPORT    (1 << 8)
413fcf5ef2aSThomas Huth #define MSR_MTRRcap_WC_SUPPORTED        (1 << 10)
414fcf5ef2aSThomas Huth 
415fcf5ef2aSThomas Huth #define MSR_IA32_SYSENTER_CS            0x174
416fcf5ef2aSThomas Huth #define MSR_IA32_SYSENTER_ESP           0x175
417fcf5ef2aSThomas Huth #define MSR_IA32_SYSENTER_EIP           0x176
418fcf5ef2aSThomas Huth 
419fcf5ef2aSThomas Huth #define MSR_MCG_CAP                     0x179
420fcf5ef2aSThomas Huth #define MSR_MCG_STATUS                  0x17a
421fcf5ef2aSThomas Huth #define MSR_MCG_CTL                     0x17b
422fcf5ef2aSThomas Huth #define MSR_MCG_EXT_CTL                 0x4d0
423fcf5ef2aSThomas Huth 
424fcf5ef2aSThomas Huth #define MSR_P6_EVNTSEL0                 0x186
425fcf5ef2aSThomas Huth 
426fcf5ef2aSThomas Huth #define MSR_IA32_PERF_STATUS            0x198
427fcf5ef2aSThomas Huth 
428fcf5ef2aSThomas Huth #define MSR_IA32_MISC_ENABLE            0x1a0
429fcf5ef2aSThomas Huth /* Indicates good rep/movs microcode on some processors: */
430fcf5ef2aSThomas Huth #define MSR_IA32_MISC_ENABLE_DEFAULT    1
4314cfd7babSWanpeng Li #define MSR_IA32_MISC_ENABLE_MWAIT      (1ULL << 18)
432fcf5ef2aSThomas Huth 
433fcf5ef2aSThomas Huth #define MSR_MTRRphysBase(reg)           (0x200 + 2 * (reg))
434fcf5ef2aSThomas Huth #define MSR_MTRRphysMask(reg)           (0x200 + 2 * (reg) + 1)
435fcf5ef2aSThomas Huth 
436fcf5ef2aSThomas Huth #define MSR_MTRRphysIndex(addr)         ((((addr) & ~1u) - 0x200) / 2)
437fcf5ef2aSThomas Huth 
438fcf5ef2aSThomas Huth #define MSR_MTRRfix64K_00000            0x250
439fcf5ef2aSThomas Huth #define MSR_MTRRfix16K_80000            0x258
440fcf5ef2aSThomas Huth #define MSR_MTRRfix16K_A0000            0x259
441fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_C0000             0x268
442fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_C8000             0x269
443fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_D0000             0x26a
444fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_D8000             0x26b
445fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_E0000             0x26c
446fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_E8000             0x26d
447fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_F0000             0x26e
448fcf5ef2aSThomas Huth #define MSR_MTRRfix4K_F8000             0x26f
449fcf5ef2aSThomas Huth 
450fcf5ef2aSThomas Huth #define MSR_PAT                         0x277
451fcf5ef2aSThomas Huth 
452fcf5ef2aSThomas Huth #define MSR_MTRRdefType                 0x2ff
453fcf5ef2aSThomas Huth 
454fcf5ef2aSThomas Huth #define MSR_CORE_PERF_FIXED_CTR0        0x309
455fcf5ef2aSThomas Huth #define MSR_CORE_PERF_FIXED_CTR1        0x30a
456fcf5ef2aSThomas Huth #define MSR_CORE_PERF_FIXED_CTR2        0x30b
457fcf5ef2aSThomas Huth #define MSR_CORE_PERF_FIXED_CTR_CTRL    0x38d
458fcf5ef2aSThomas Huth #define MSR_CORE_PERF_GLOBAL_STATUS     0x38e
459fcf5ef2aSThomas Huth #define MSR_CORE_PERF_GLOBAL_CTRL       0x38f
460fcf5ef2aSThomas Huth #define MSR_CORE_PERF_GLOBAL_OVF_CTRL   0x390
461fcf5ef2aSThomas Huth 
462fcf5ef2aSThomas Huth #define MSR_MC0_CTL                     0x400
463fcf5ef2aSThomas Huth #define MSR_MC0_STATUS                  0x401
464fcf5ef2aSThomas Huth #define MSR_MC0_ADDR                    0x402
465fcf5ef2aSThomas Huth #define MSR_MC0_MISC                    0x403
466fcf5ef2aSThomas Huth 
467b77146e9SChao Peng #define MSR_IA32_RTIT_OUTPUT_BASE       0x560
468b77146e9SChao Peng #define MSR_IA32_RTIT_OUTPUT_MASK       0x561
469b77146e9SChao Peng #define MSR_IA32_RTIT_CTL               0x570
470b77146e9SChao Peng #define MSR_IA32_RTIT_STATUS            0x571
471b77146e9SChao Peng #define MSR_IA32_RTIT_CR3_MATCH         0x572
472b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR0_A           0x580
473b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR0_B           0x581
474b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR1_A           0x582
475b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR1_B           0x583
476b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR2_A           0x584
477b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR2_B           0x585
478b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR3_A           0x586
479b77146e9SChao Peng #define MSR_IA32_RTIT_ADDR3_B           0x587
480b77146e9SChao Peng #define MAX_RTIT_ADDRS                  8
481b77146e9SChao Peng 
482fcf5ef2aSThomas Huth #define MSR_EFER                        0xc0000080
483fcf5ef2aSThomas Huth 
484fcf5ef2aSThomas Huth #define MSR_EFER_SCE   (1 << 0)
485fcf5ef2aSThomas Huth #define MSR_EFER_LME   (1 << 8)
486fcf5ef2aSThomas Huth #define MSR_EFER_LMA   (1 << 10)
487fcf5ef2aSThomas Huth #define MSR_EFER_NXE   (1 << 11)
488fcf5ef2aSThomas Huth #define MSR_EFER_SVME  (1 << 12)
489fcf5ef2aSThomas Huth #define MSR_EFER_FFXSR (1 << 14)
490fcf5ef2aSThomas Huth 
491d499f196SLara Lazier #define MSR_EFER_RESERVED\
492d499f196SLara Lazier         (~(target_ulong)(MSR_EFER_SCE | MSR_EFER_LME\
493d499f196SLara Lazier             | MSR_EFER_LMA | MSR_EFER_NXE | MSR_EFER_SVME\
494d499f196SLara Lazier             | MSR_EFER_FFXSR))
495d499f196SLara Lazier 
496fcf5ef2aSThomas Huth #define MSR_STAR                        0xc0000081
497fcf5ef2aSThomas Huth #define MSR_LSTAR                       0xc0000082
498fcf5ef2aSThomas Huth #define MSR_CSTAR                       0xc0000083
499fcf5ef2aSThomas Huth #define MSR_FMASK                       0xc0000084
500fcf5ef2aSThomas Huth #define MSR_FSBASE                      0xc0000100
501fcf5ef2aSThomas Huth #define MSR_GSBASE                      0xc0000101
502fcf5ef2aSThomas Huth #define MSR_KERNELGSBASE                0xc0000102
503fcf5ef2aSThomas Huth #define MSR_TSC_AUX                     0xc0000103
504cabf9862SMaxim Levitsky #define MSR_AMD64_TSC_RATIO             0xc0000104
505cabf9862SMaxim Levitsky 
506cabf9862SMaxim Levitsky #define MSR_AMD64_TSC_RATIO_DEFAULT     0x100000000ULL
507fcf5ef2aSThomas Huth 
508fcf5ef2aSThomas Huth #define MSR_VM_HSAVE_PA                 0xc0010117
509fcf5ef2aSThomas Huth 
510*cdec2b75SZeng Guang #define MSR_IA32_XFD                    0x000001c4
511*cdec2b75SZeng Guang #define MSR_IA32_XFD_ERR                0x000001c5
512*cdec2b75SZeng Guang 
513fcf5ef2aSThomas Huth #define MSR_IA32_BNDCFGS                0x00000d90
514fcf5ef2aSThomas Huth #define MSR_IA32_XSS                    0x00000da0
51565087997STao Xu #define MSR_IA32_UMWAIT_CONTROL         0xe1
516fcf5ef2aSThomas Huth 
517704798adSPaolo Bonzini #define MSR_IA32_VMX_BASIC              0x00000480
518704798adSPaolo Bonzini #define MSR_IA32_VMX_PINBASED_CTLS      0x00000481
519704798adSPaolo Bonzini #define MSR_IA32_VMX_PROCBASED_CTLS     0x00000482
520704798adSPaolo Bonzini #define MSR_IA32_VMX_EXIT_CTLS          0x00000483
521704798adSPaolo Bonzini #define MSR_IA32_VMX_ENTRY_CTLS         0x00000484
522704798adSPaolo Bonzini #define MSR_IA32_VMX_MISC               0x00000485
523704798adSPaolo Bonzini #define MSR_IA32_VMX_CR0_FIXED0         0x00000486
524704798adSPaolo Bonzini #define MSR_IA32_VMX_CR0_FIXED1         0x00000487
525704798adSPaolo Bonzini #define MSR_IA32_VMX_CR4_FIXED0         0x00000488
526704798adSPaolo Bonzini #define MSR_IA32_VMX_CR4_FIXED1         0x00000489
527704798adSPaolo Bonzini #define MSR_IA32_VMX_VMCS_ENUM          0x0000048a
528704798adSPaolo Bonzini #define MSR_IA32_VMX_PROCBASED_CTLS2    0x0000048b
529704798adSPaolo Bonzini #define MSR_IA32_VMX_EPT_VPID_CAP       0x0000048c
530704798adSPaolo Bonzini #define MSR_IA32_VMX_TRUE_PINBASED_CTLS  0x0000048d
531704798adSPaolo Bonzini #define MSR_IA32_VMX_TRUE_PROCBASED_CTLS 0x0000048e
532704798adSPaolo Bonzini #define MSR_IA32_VMX_TRUE_EXIT_CTLS      0x0000048f
533704798adSPaolo Bonzini #define MSR_IA32_VMX_TRUE_ENTRY_CTLS     0x00000490
534704798adSPaolo Bonzini #define MSR_IA32_VMX_VMFUNC             0x00000491
535704798adSPaolo Bonzini 
536fcf5ef2aSThomas Huth #define XSTATE_FP_BIT                   0
537fcf5ef2aSThomas Huth #define XSTATE_SSE_BIT                  1
538fcf5ef2aSThomas Huth #define XSTATE_YMM_BIT                  2
539fcf5ef2aSThomas Huth #define XSTATE_BNDREGS_BIT              3
540fcf5ef2aSThomas Huth #define XSTATE_BNDCSR_BIT               4
541fcf5ef2aSThomas Huth #define XSTATE_OPMASK_BIT               5
542fcf5ef2aSThomas Huth #define XSTATE_ZMM_Hi256_BIT            6
543fcf5ef2aSThomas Huth #define XSTATE_Hi16_ZMM_BIT             7
544fcf5ef2aSThomas Huth #define XSTATE_PKRU_BIT                 9
5451f16764fSJing Liu #define XSTATE_XTILE_CFG_BIT            17
5461f16764fSJing Liu #define XSTATE_XTILE_DATA_BIT           18
547fcf5ef2aSThomas Huth 
548fcf5ef2aSThomas Huth #define XSTATE_FP_MASK                  (1ULL << XSTATE_FP_BIT)
549fcf5ef2aSThomas Huth #define XSTATE_SSE_MASK                 (1ULL << XSTATE_SSE_BIT)
550fcf5ef2aSThomas Huth #define XSTATE_YMM_MASK                 (1ULL << XSTATE_YMM_BIT)
551fcf5ef2aSThomas Huth #define XSTATE_BNDREGS_MASK             (1ULL << XSTATE_BNDREGS_BIT)
552fcf5ef2aSThomas Huth #define XSTATE_BNDCSR_MASK              (1ULL << XSTATE_BNDCSR_BIT)
553fcf5ef2aSThomas Huth #define XSTATE_OPMASK_MASK              (1ULL << XSTATE_OPMASK_BIT)
554fcf5ef2aSThomas Huth #define XSTATE_ZMM_Hi256_MASK           (1ULL << XSTATE_ZMM_Hi256_BIT)
555fcf5ef2aSThomas Huth #define XSTATE_Hi16_ZMM_MASK            (1ULL << XSTATE_Hi16_ZMM_BIT)
556fcf5ef2aSThomas Huth #define XSTATE_PKRU_MASK                (1ULL << XSTATE_PKRU_BIT)
55719db68caSYang Zhong #define XSTATE_XTILE_CFG_MASK           (1ULL << XSTATE_XTILE_CFG_BIT)
55819db68caSYang Zhong #define XSTATE_XTILE_DATA_MASK          (1ULL << XSTATE_XTILE_DATA_BIT)
55919db68caSYang Zhong 
56019db68caSYang Zhong #define XSTATE_DYNAMIC_MASK             (XSTATE_XTILE_DATA_MASK)
561fcf5ef2aSThomas Huth 
562131266b7SJing Liu #define ESA_FEATURE_ALIGN64_BIT         1
5630f17f6b3SJing Liu #define ESA_FEATURE_XFD_BIT             2
564131266b7SJing Liu 
565131266b7SJing Liu #define ESA_FEATURE_ALIGN64_MASK        (1U << ESA_FEATURE_ALIGN64_BIT)
5660f17f6b3SJing Liu #define ESA_FEATURE_XFD_MASK            (1U << ESA_FEATURE_XFD_BIT)
567131266b7SJing Liu 
568131266b7SJing Liu 
569fcf5ef2aSThomas Huth /* CPUID feature words */
570fcf5ef2aSThomas Huth typedef enum FeatureWord {
571fcf5ef2aSThomas Huth     FEAT_1_EDX,         /* CPUID[1].EDX */
572fcf5ef2aSThomas Huth     FEAT_1_ECX,         /* CPUID[1].ECX */
573fcf5ef2aSThomas Huth     FEAT_7_0_EBX,       /* CPUID[EAX=7,ECX=0].EBX */
574fcf5ef2aSThomas Huth     FEAT_7_0_ECX,       /* CPUID[EAX=7,ECX=0].ECX */
575fcf5ef2aSThomas Huth     FEAT_7_0_EDX,       /* CPUID[EAX=7,ECX=0].EDX */
57680db491dSJing Liu     FEAT_7_1_EAX,       /* CPUID[EAX=7,ECX=1].EAX */
577fcf5ef2aSThomas Huth     FEAT_8000_0001_EDX, /* CPUID[8000_0001].EDX */
578fcf5ef2aSThomas Huth     FEAT_8000_0001_ECX, /* CPUID[8000_0001].ECX */
579fcf5ef2aSThomas Huth     FEAT_8000_0007_EDX, /* CPUID[8000_0007].EDX */
5801b3420e1SEduardo Habkost     FEAT_8000_0008_EBX, /* CPUID[8000_0008].EBX */
581fcf5ef2aSThomas Huth     FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */
582fcf5ef2aSThomas Huth     FEAT_KVM,           /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */
583be777326SWanpeng Li     FEAT_KVM_HINTS,     /* CPUID[4000_0001].EDX */
584fcf5ef2aSThomas Huth     FEAT_SVM,           /* CPUID[8000_000A].EDX */
585fcf5ef2aSThomas Huth     FEAT_XSAVE,         /* CPUID[EAX=0xd,ECX=1].EAX */
586fcf5ef2aSThomas Huth     FEAT_6_EAX,         /* CPUID[6].EAX */
587fcf5ef2aSThomas Huth     FEAT_XSAVE_COMP_LO, /* CPUID[EAX=0xd,ECX=0].EAX */
588fcf5ef2aSThomas Huth     FEAT_XSAVE_COMP_HI, /* CPUID[EAX=0xd,ECX=0].EDX */
589d86f9636SRobert Hoo     FEAT_ARCH_CAPABILITIES,
590597360c0SXiaoyao Li     FEAT_CORE_CAPABILITY,
591ea39f9b6SLike Xu     FEAT_PERF_CAPABILITIES,
59220a78b02SPaolo Bonzini     FEAT_VMX_PROCBASED_CTLS,
59320a78b02SPaolo Bonzini     FEAT_VMX_SECONDARY_CTLS,
59420a78b02SPaolo Bonzini     FEAT_VMX_PINBASED_CTLS,
59520a78b02SPaolo Bonzini     FEAT_VMX_EXIT_CTLS,
59620a78b02SPaolo Bonzini     FEAT_VMX_ENTRY_CTLS,
59720a78b02SPaolo Bonzini     FEAT_VMX_MISC,
59820a78b02SPaolo Bonzini     FEAT_VMX_EPT_VPID_CAPS,
59920a78b02SPaolo Bonzini     FEAT_VMX_BASIC,
60020a78b02SPaolo Bonzini     FEAT_VMX_VMFUNC,
601d1615ea5SLuwei Kang     FEAT_14_0_ECX,
6024b841a79SSean Christopherson     FEAT_SGX_12_0_EAX,  /* CPUID[EAX=0x12,ECX=0].EAX (SGX) */
603120ca112SSean Christopherson     FEAT_SGX_12_0_EBX,  /* CPUID[EAX=0x12,ECX=0].EBX (SGX MISCSELECT[31:0]) */
604165981a5SSean Christopherson     FEAT_SGX_12_1_EAX,  /* CPUID[EAX=0x12,ECX=1].EAX (SGX ATTRIBUTES[31:0]) */
605fcf5ef2aSThomas Huth     FEATURE_WORDS,
606fcf5ef2aSThomas Huth } FeatureWord;
607fcf5ef2aSThomas Huth 
608ede146c2SPaolo Bonzini typedef uint64_t FeatureWordArray[FEATURE_WORDS];
609fcf5ef2aSThomas Huth 
610fcf5ef2aSThomas Huth /* cpuid_features bits */
611fcf5ef2aSThomas Huth #define CPUID_FP87 (1U << 0)
612fcf5ef2aSThomas Huth #define CPUID_VME  (1U << 1)
613fcf5ef2aSThomas Huth #define CPUID_DE   (1U << 2)
614fcf5ef2aSThomas Huth #define CPUID_PSE  (1U << 3)
615fcf5ef2aSThomas Huth #define CPUID_TSC  (1U << 4)
616fcf5ef2aSThomas Huth #define CPUID_MSR  (1U << 5)
617fcf5ef2aSThomas Huth #define CPUID_PAE  (1U << 6)
618fcf5ef2aSThomas Huth #define CPUID_MCE  (1U << 7)
619fcf5ef2aSThomas Huth #define CPUID_CX8  (1U << 8)
620fcf5ef2aSThomas Huth #define CPUID_APIC (1U << 9)
621fcf5ef2aSThomas Huth #define CPUID_SEP  (1U << 11) /* sysenter/sysexit */
622fcf5ef2aSThomas Huth #define CPUID_MTRR (1U << 12)
623fcf5ef2aSThomas Huth #define CPUID_PGE  (1U << 13)
624fcf5ef2aSThomas Huth #define CPUID_MCA  (1U << 14)
625fcf5ef2aSThomas Huth #define CPUID_CMOV (1U << 15)
626fcf5ef2aSThomas Huth #define CPUID_PAT  (1U << 16)
627fcf5ef2aSThomas Huth #define CPUID_PSE36   (1U << 17)
628fcf5ef2aSThomas Huth #define CPUID_PN   (1U << 18)
629fcf5ef2aSThomas Huth #define CPUID_CLFLUSH (1U << 19)
630fcf5ef2aSThomas Huth #define CPUID_DTS (1U << 21)
631fcf5ef2aSThomas Huth #define CPUID_ACPI (1U << 22)
632fcf5ef2aSThomas Huth #define CPUID_MMX  (1U << 23)
633fcf5ef2aSThomas Huth #define CPUID_FXSR (1U << 24)
634fcf5ef2aSThomas Huth #define CPUID_SSE  (1U << 25)
635fcf5ef2aSThomas Huth #define CPUID_SSE2 (1U << 26)
636fcf5ef2aSThomas Huth #define CPUID_SS (1U << 27)
637fcf5ef2aSThomas Huth #define CPUID_HT (1U << 28)
638fcf5ef2aSThomas Huth #define CPUID_TM (1U << 29)
639fcf5ef2aSThomas Huth #define CPUID_IA64 (1U << 30)
640fcf5ef2aSThomas Huth #define CPUID_PBE (1U << 31)
641fcf5ef2aSThomas Huth 
642fcf5ef2aSThomas Huth #define CPUID_EXT_SSE3     (1U << 0)
643fcf5ef2aSThomas Huth #define CPUID_EXT_PCLMULQDQ (1U << 1)
644fcf5ef2aSThomas Huth #define CPUID_EXT_DTES64   (1U << 2)
645fcf5ef2aSThomas Huth #define CPUID_EXT_MONITOR  (1U << 3)
646fcf5ef2aSThomas Huth #define CPUID_EXT_DSCPL    (1U << 4)
647fcf5ef2aSThomas Huth #define CPUID_EXT_VMX      (1U << 5)
648fcf5ef2aSThomas Huth #define CPUID_EXT_SMX      (1U << 6)
649fcf5ef2aSThomas Huth #define CPUID_EXT_EST      (1U << 7)
650fcf5ef2aSThomas Huth #define CPUID_EXT_TM2      (1U << 8)
651fcf5ef2aSThomas Huth #define CPUID_EXT_SSSE3    (1U << 9)
652fcf5ef2aSThomas Huth #define CPUID_EXT_CID      (1U << 10)
653fcf5ef2aSThomas Huth #define CPUID_EXT_FMA      (1U << 12)
654fcf5ef2aSThomas Huth #define CPUID_EXT_CX16     (1U << 13)
655fcf5ef2aSThomas Huth #define CPUID_EXT_XTPR     (1U << 14)
656fcf5ef2aSThomas Huth #define CPUID_EXT_PDCM     (1U << 15)
657fcf5ef2aSThomas Huth #define CPUID_EXT_PCID     (1U << 17)
658fcf5ef2aSThomas Huth #define CPUID_EXT_DCA      (1U << 18)
659fcf5ef2aSThomas Huth #define CPUID_EXT_SSE41    (1U << 19)
660fcf5ef2aSThomas Huth #define CPUID_EXT_SSE42    (1U << 20)
661fcf5ef2aSThomas Huth #define CPUID_EXT_X2APIC   (1U << 21)
662fcf5ef2aSThomas Huth #define CPUID_EXT_MOVBE    (1U << 22)
663fcf5ef2aSThomas Huth #define CPUID_EXT_POPCNT   (1U << 23)
664fcf5ef2aSThomas Huth #define CPUID_EXT_TSC_DEADLINE_TIMER (1U << 24)
665fcf5ef2aSThomas Huth #define CPUID_EXT_AES      (1U << 25)
666fcf5ef2aSThomas Huth #define CPUID_EXT_XSAVE    (1U << 26)
667fcf5ef2aSThomas Huth #define CPUID_EXT_OSXSAVE  (1U << 27)
668fcf5ef2aSThomas Huth #define CPUID_EXT_AVX      (1U << 28)
669fcf5ef2aSThomas Huth #define CPUID_EXT_F16C     (1U << 29)
670fcf5ef2aSThomas Huth #define CPUID_EXT_RDRAND   (1U << 30)
671fcf5ef2aSThomas Huth #define CPUID_EXT_HYPERVISOR  (1U << 31)
672fcf5ef2aSThomas Huth 
673fcf5ef2aSThomas Huth #define CPUID_EXT2_FPU     (1U << 0)
674fcf5ef2aSThomas Huth #define CPUID_EXT2_VME     (1U << 1)
675fcf5ef2aSThomas Huth #define CPUID_EXT2_DE      (1U << 2)
676fcf5ef2aSThomas Huth #define CPUID_EXT2_PSE     (1U << 3)
677fcf5ef2aSThomas Huth #define CPUID_EXT2_TSC     (1U << 4)
678fcf5ef2aSThomas Huth #define CPUID_EXT2_MSR     (1U << 5)
679fcf5ef2aSThomas Huth #define CPUID_EXT2_PAE     (1U << 6)
680fcf5ef2aSThomas Huth #define CPUID_EXT2_MCE     (1U << 7)
681fcf5ef2aSThomas Huth #define CPUID_EXT2_CX8     (1U << 8)
682fcf5ef2aSThomas Huth #define CPUID_EXT2_APIC    (1U << 9)
683fcf5ef2aSThomas Huth #define CPUID_EXT2_SYSCALL (1U << 11)
684fcf5ef2aSThomas Huth #define CPUID_EXT2_MTRR    (1U << 12)
685fcf5ef2aSThomas Huth #define CPUID_EXT2_PGE     (1U << 13)
686fcf5ef2aSThomas Huth #define CPUID_EXT2_MCA     (1U << 14)
687fcf5ef2aSThomas Huth #define CPUID_EXT2_CMOV    (1U << 15)
688fcf5ef2aSThomas Huth #define CPUID_EXT2_PAT     (1U << 16)
689fcf5ef2aSThomas Huth #define CPUID_EXT2_PSE36   (1U << 17)
690fcf5ef2aSThomas Huth #define CPUID_EXT2_MP      (1U << 19)
691fcf5ef2aSThomas Huth #define CPUID_EXT2_NX      (1U << 20)
692fcf5ef2aSThomas Huth #define CPUID_EXT2_MMXEXT  (1U << 22)
693fcf5ef2aSThomas Huth #define CPUID_EXT2_MMX     (1U << 23)
694fcf5ef2aSThomas Huth #define CPUID_EXT2_FXSR    (1U << 24)
695fcf5ef2aSThomas Huth #define CPUID_EXT2_FFXSR   (1U << 25)
696fcf5ef2aSThomas Huth #define CPUID_EXT2_PDPE1GB (1U << 26)
697fcf5ef2aSThomas Huth #define CPUID_EXT2_RDTSCP  (1U << 27)
698fcf5ef2aSThomas Huth #define CPUID_EXT2_LM      (1U << 29)
699fcf5ef2aSThomas Huth #define CPUID_EXT2_3DNOWEXT (1U << 30)
700fcf5ef2aSThomas Huth #define CPUID_EXT2_3DNOW   (1U << 31)
701fcf5ef2aSThomas Huth 
702fcf5ef2aSThomas Huth /* CPUID[8000_0001].EDX bits that are aliase of CPUID[1].EDX bits on AMD CPUs */
703fcf5ef2aSThomas Huth #define CPUID_EXT2_AMD_ALIASES (CPUID_EXT2_FPU | CPUID_EXT2_VME | \
704fcf5ef2aSThomas Huth                                 CPUID_EXT2_DE | CPUID_EXT2_PSE | \
705fcf5ef2aSThomas Huth                                 CPUID_EXT2_TSC | CPUID_EXT2_MSR | \
706fcf5ef2aSThomas Huth                                 CPUID_EXT2_PAE | CPUID_EXT2_MCE | \
707fcf5ef2aSThomas Huth                                 CPUID_EXT2_CX8 | CPUID_EXT2_APIC | \
708fcf5ef2aSThomas Huth                                 CPUID_EXT2_MTRR | CPUID_EXT2_PGE | \
709fcf5ef2aSThomas Huth                                 CPUID_EXT2_MCA | CPUID_EXT2_CMOV | \
710fcf5ef2aSThomas Huth                                 CPUID_EXT2_PAT | CPUID_EXT2_PSE36 | \
711fcf5ef2aSThomas Huth                                 CPUID_EXT2_MMX | CPUID_EXT2_FXSR)
712fcf5ef2aSThomas Huth 
713fcf5ef2aSThomas Huth #define CPUID_EXT3_LAHF_LM (1U << 0)
714fcf5ef2aSThomas Huth #define CPUID_EXT3_CMP_LEG (1U << 1)
715fcf5ef2aSThomas Huth #define CPUID_EXT3_SVM     (1U << 2)
716fcf5ef2aSThomas Huth #define CPUID_EXT3_EXTAPIC (1U << 3)
717fcf5ef2aSThomas Huth #define CPUID_EXT3_CR8LEG  (1U << 4)
718fcf5ef2aSThomas Huth #define CPUID_EXT3_ABM     (1U << 5)
719fcf5ef2aSThomas Huth #define CPUID_EXT3_SSE4A   (1U << 6)
720fcf5ef2aSThomas Huth #define CPUID_EXT3_MISALIGNSSE (1U << 7)
721fcf5ef2aSThomas Huth #define CPUID_EXT3_3DNOWPREFETCH (1U << 8)
722fcf5ef2aSThomas Huth #define CPUID_EXT3_OSVW    (1U << 9)
723fcf5ef2aSThomas Huth #define CPUID_EXT3_IBS     (1U << 10)
724fcf5ef2aSThomas Huth #define CPUID_EXT3_XOP     (1U << 11)
725fcf5ef2aSThomas Huth #define CPUID_EXT3_SKINIT  (1U << 12)
726fcf5ef2aSThomas Huth #define CPUID_EXT3_WDT     (1U << 13)
727fcf5ef2aSThomas Huth #define CPUID_EXT3_LWP     (1U << 15)
728fcf5ef2aSThomas Huth #define CPUID_EXT3_FMA4    (1U << 16)
729fcf5ef2aSThomas Huth #define CPUID_EXT3_TCE     (1U << 17)
730fcf5ef2aSThomas Huth #define CPUID_EXT3_NODEID  (1U << 19)
731fcf5ef2aSThomas Huth #define CPUID_EXT3_TBM     (1U << 21)
732fcf5ef2aSThomas Huth #define CPUID_EXT3_TOPOEXT (1U << 22)
733fcf5ef2aSThomas Huth #define CPUID_EXT3_PERFCORE (1U << 23)
734fcf5ef2aSThomas Huth #define CPUID_EXT3_PERFNB  (1U << 24)
735fcf5ef2aSThomas Huth 
736fcf5ef2aSThomas Huth #define CPUID_SVM_NPT             (1U << 0)
737fcf5ef2aSThomas Huth #define CPUID_SVM_LBRV            (1U << 1)
738fcf5ef2aSThomas Huth #define CPUID_SVM_SVMLOCK         (1U << 2)
739fcf5ef2aSThomas Huth #define CPUID_SVM_NRIPSAVE        (1U << 3)
740fcf5ef2aSThomas Huth #define CPUID_SVM_TSCSCALE        (1U << 4)
741fcf5ef2aSThomas Huth #define CPUID_SVM_VMCBCLEAN       (1U << 5)
742fcf5ef2aSThomas Huth #define CPUID_SVM_FLUSHASID       (1U << 6)
743fcf5ef2aSThomas Huth #define CPUID_SVM_DECODEASSIST    (1U << 7)
744fcf5ef2aSThomas Huth #define CPUID_SVM_PAUSEFILTER     (1U << 10)
745fcf5ef2aSThomas Huth #define CPUID_SVM_PFTHRESHOLD     (1U << 12)
7465447089cSWei Huang #define CPUID_SVM_AVIC            (1U << 13)
7475447089cSWei Huang #define CPUID_SVM_V_VMSAVE_VMLOAD (1U << 15)
7485447089cSWei Huang #define CPUID_SVM_VGIF            (1U << 16)
7495447089cSWei Huang #define CPUID_SVM_SVME_ADDR_CHK   (1U << 28)
750fcf5ef2aSThomas Huth 
751f2be0bebSTao Xu /* Support RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE */
752fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_FSGSBASE          (1U << 0)
7535c76b651SSean Christopherson /* Support SGX */
7545c76b651SSean Christopherson #define CPUID_7_0_EBX_SGX               (1U << 2)
755f2be0bebSTao Xu /* 1st Group of Advanced Bit Manipulation Extensions */
756fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_BMI1              (1U << 3)
757f2be0bebSTao Xu /* Hardware Lock Elision */
758fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_HLE               (1U << 4)
759f2be0bebSTao Xu /* Intel Advanced Vector Extensions 2 */
760fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_AVX2              (1U << 5)
761f2be0bebSTao Xu /* Supervisor-mode Execution Prevention */
762fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_SMEP              (1U << 7)
763f2be0bebSTao Xu /* 2nd Group of Advanced Bit Manipulation Extensions */
764fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_BMI2              (1U << 8)
765f2be0bebSTao Xu /* Enhanced REP MOVSB/STOSB */
766fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_ERMS              (1U << 9)
767f2be0bebSTao Xu /* Invalidate Process-Context Identifier */
768fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_INVPCID           (1U << 10)
769f2be0bebSTao Xu /* Restricted Transactional Memory */
770fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_RTM               (1U << 11)
771f2be0bebSTao Xu /* Memory Protection Extension */
772fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_MPX               (1U << 14)
773f2be0bebSTao Xu /* AVX-512 Foundation */
774f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512F           (1U << 16)
775f2be0bebSTao Xu /* AVX-512 Doubleword & Quadword Instruction */
776f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512DQ          (1U << 17)
777f2be0bebSTao Xu /* Read Random SEED */
778fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_RDSEED            (1U << 18)
779f2be0bebSTao Xu /* ADCX and ADOX instructions */
780fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_ADX               (1U << 19)
781f2be0bebSTao Xu /* Supervisor Mode Access Prevention */
782fcf5ef2aSThomas Huth #define CPUID_7_0_EBX_SMAP              (1U << 20)
783f2be0bebSTao Xu /* AVX-512 Integer Fused Multiply Add */
784f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512IFMA        (1U << 21)
785f2be0bebSTao Xu /* Persistent Commit */
786f2be0bebSTao Xu #define CPUID_7_0_EBX_PCOMMIT           (1U << 22)
787f2be0bebSTao Xu /* Flush a Cache Line Optimized */
788f2be0bebSTao Xu #define CPUID_7_0_EBX_CLFLUSHOPT        (1U << 23)
789f2be0bebSTao Xu /* Cache Line Write Back */
790f2be0bebSTao Xu #define CPUID_7_0_EBX_CLWB              (1U << 24)
791f2be0bebSTao Xu /* Intel Processor Trace */
792f2be0bebSTao Xu #define CPUID_7_0_EBX_INTEL_PT          (1U << 25)
793f2be0bebSTao Xu /* AVX-512 Prefetch */
794f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512PF          (1U << 26)
795f2be0bebSTao Xu /* AVX-512 Exponential and Reciprocal */
796f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512ER          (1U << 27)
797f2be0bebSTao Xu /* AVX-512 Conflict Detection */
798f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512CD          (1U << 28)
799f2be0bebSTao Xu /* SHA1/SHA256 Instruction Extensions */
800f2be0bebSTao Xu #define CPUID_7_0_EBX_SHA_NI            (1U << 29)
801f2be0bebSTao Xu /* AVX-512 Byte and Word Instructions */
802f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512BW          (1U << 30)
803f2be0bebSTao Xu /* AVX-512 Vector Length Extensions */
804f2be0bebSTao Xu #define CPUID_7_0_EBX_AVX512VL          (1U << 31)
805fcf5ef2aSThomas Huth 
806f2be0bebSTao Xu /* AVX-512 Vector Byte Manipulation Instruction */
807e7694a5eSTao Xu #define CPUID_7_0_ECX_AVX512_VBMI       (1U << 1)
808f2be0bebSTao Xu /* User-Mode Instruction Prevention */
809fcf5ef2aSThomas Huth #define CPUID_7_0_ECX_UMIP              (1U << 2)
810f2be0bebSTao Xu /* Protection Keys for User-mode Pages */
811fcf5ef2aSThomas Huth #define CPUID_7_0_ECX_PKU               (1U << 3)
812f2be0bebSTao Xu /* OS Enable Protection Keys */
813fcf5ef2aSThomas Huth #define CPUID_7_0_ECX_OSPKE             (1U << 4)
81467192a29STao Xu /* UMONITOR/UMWAIT/TPAUSE Instructions */
81567192a29STao Xu #define CPUID_7_0_ECX_WAITPKG           (1U << 5)
816f2be0bebSTao Xu /* Additional AVX-512 Vector Byte Manipulation Instruction */
817e7694a5eSTao Xu #define CPUID_7_0_ECX_AVX512_VBMI2      (1U << 6)
818f2be0bebSTao Xu /* Galois Field New Instructions */
819aff9e6e4SYang Zhong #define CPUID_7_0_ECX_GFNI              (1U << 8)
820f2be0bebSTao Xu /* Vector AES Instructions */
821aff9e6e4SYang Zhong #define CPUID_7_0_ECX_VAES              (1U << 9)
822f2be0bebSTao Xu /* Carry-Less Multiplication Quadword */
823aff9e6e4SYang Zhong #define CPUID_7_0_ECX_VPCLMULQDQ        (1U << 10)
824f2be0bebSTao Xu /* Vector Neural Network Instructions */
825aff9e6e4SYang Zhong #define CPUID_7_0_ECX_AVX512VNNI        (1U << 11)
826f2be0bebSTao Xu /* Support for VPOPCNT[B,W] and VPSHUFBITQMB */
827aff9e6e4SYang Zhong #define CPUID_7_0_ECX_AVX512BITALG      (1U << 12)
828f2be0bebSTao Xu /* POPCNT for vectors of DW/QW */
829f2be0bebSTao Xu #define CPUID_7_0_ECX_AVX512_VPOPCNTDQ  (1U << 14)
830f2be0bebSTao Xu /* 5-level Page Tables */
8316c7c3c21SKirill A. Shutemov #define CPUID_7_0_ECX_LA57              (1U << 16)
832f2be0bebSTao Xu /* Read Processor ID */
833fcf5ef2aSThomas Huth #define CPUID_7_0_ECX_RDPID             (1U << 22)
83406e878b4SChenyi Qiang /* Bus Lock Debug Exception */
83506e878b4SChenyi Qiang #define CPUID_7_0_ECX_BUS_LOCK_DETECT   (1U << 24)
836f2be0bebSTao Xu /* Cache Line Demote Instruction */
837f2be0bebSTao Xu #define CPUID_7_0_ECX_CLDEMOTE          (1U << 25)
838f2be0bebSTao Xu /* Move Doubleword as Direct Store Instruction */
839f2be0bebSTao Xu #define CPUID_7_0_ECX_MOVDIRI           (1U << 27)
840f2be0bebSTao Xu /* Move 64 Bytes as Direct Store Instruction */
841f2be0bebSTao Xu #define CPUID_7_0_ECX_MOVDIR64B         (1U << 28)
8425c76b651SSean Christopherson /* Support SGX Launch Control */
8435c76b651SSean Christopherson #define CPUID_7_0_ECX_SGX_LC            (1U << 30)
844e7e7bdabSPaolo Bonzini /* Protection Keys for Supervisor-mode Pages */
845e7e7bdabSPaolo Bonzini #define CPUID_7_0_ECX_PKS               (1U << 31)
846fcf5ef2aSThomas Huth 
847f2be0bebSTao Xu /* AVX512 Neural Network Instructions */
848f2be0bebSTao Xu #define CPUID_7_0_EDX_AVX512_4VNNIW     (1U << 2)
849f2be0bebSTao Xu /* AVX512 Multiply Accumulation Single Precision */
850f2be0bebSTao Xu #define CPUID_7_0_EDX_AVX512_4FMAPS     (1U << 3)
8515cb287d2SChenyi Qiang /* Fast Short Rep Mov */
8525cb287d2SChenyi Qiang #define CPUID_7_0_EDX_FSRM              (1U << 4)
853353f98c9SCathy Zhang /* AVX512 Vector Pair Intersection to a Pair of Mask Registers */
854353f98c9SCathy Zhang #define CPUID_7_0_EDX_AVX512_VP2INTERSECT (1U << 8)
8555dd13f2aSCathy Zhang /* SERIALIZE instruction */
8565dd13f2aSCathy Zhang #define CPUID_7_0_EDX_SERIALIZE         (1U << 14)
857b3c7344eSCathy Zhang /* TSX Suspend Load Address Tracking instruction */
858b3c7344eSCathy Zhang #define CPUID_7_0_EDX_TSX_LDTRK         (1U << 16)
85940399ecbSCathy Zhang /* AVX512_FP16 instruction */
86040399ecbSCathy Zhang #define CPUID_7_0_EDX_AVX512_FP16       (1U << 23)
8611f16764fSJing Liu /* AMX tile (two-dimensional register) */
8621f16764fSJing Liu #define CPUID_7_0_EDX_AMX_TILE          (1U << 24)
863f2be0bebSTao Xu /* Speculation Control */
864f2be0bebSTao Xu #define CPUID_7_0_EDX_SPEC_CTRL         (1U << 26)
8655af514d0SCathy Zhang /* Single Thread Indirect Branch Predictors */
8665af514d0SCathy Zhang #define CPUID_7_0_EDX_STIBP             (1U << 27)
867f2be0bebSTao Xu /* Arch Capabilities */
868f2be0bebSTao Xu #define CPUID_7_0_EDX_ARCH_CAPABILITIES (1U << 29)
869f2be0bebSTao Xu /* Core Capability */
870f2be0bebSTao Xu #define CPUID_7_0_EDX_CORE_CAPABILITY   (1U << 30)
871f2be0bebSTao Xu /* Speculative Store Bypass Disable */
872f2be0bebSTao Xu #define CPUID_7_0_EDX_SPEC_CTRL_SSBD    (1U << 31)
873fcf5ef2aSThomas Huth 
874c1826ea6SYang Zhong /* AVX VNNI Instruction */
875c1826ea6SYang Zhong #define CPUID_7_1_EAX_AVX_VNNI          (1U << 4)
876f2be0bebSTao Xu /* AVX512 BFloat16 Instruction */
877f2be0bebSTao Xu #define CPUID_7_1_EAX_AVX512_BF16       (1U << 5)
878*cdec2b75SZeng Guang /* XFD Extend Feature Disabled */
879*cdec2b75SZeng Guang #define CPUID_D_1_EAX_XFD               (1U << 4)
88080db491dSJing Liu 
881d1615ea5SLuwei Kang /* Packets which contain IP payload have LIP values */
882d1615ea5SLuwei Kang #define CPUID_14_0_ECX_LIP              (1U << 31)
883d1615ea5SLuwei Kang 
884f2be0bebSTao Xu /* CLZERO instruction */
885f2be0bebSTao Xu #define CPUID_8000_0008_EBX_CLZERO      (1U << 0)
886f2be0bebSTao Xu /* Always save/restore FP error pointers */
887f2be0bebSTao Xu #define CPUID_8000_0008_EBX_XSAVEERPTR  (1U << 2)
888f2be0bebSTao Xu /* Write back and do not invalidate cache */
889f2be0bebSTao Xu #define CPUID_8000_0008_EBX_WBNOINVD    (1U << 9)
890f2be0bebSTao Xu /* Indirect Branch Prediction Barrier */
891f2be0bebSTao Xu #define CPUID_8000_0008_EBX_IBPB        (1U << 12)
892623972ceSBabu Moger /* Indirect Branch Restricted Speculation */
893623972ceSBabu Moger #define CPUID_8000_0008_EBX_IBRS        (1U << 14)
894143c30d4SMoger, Babu /* Single Thread Indirect Branch Predictors */
895143c30d4SMoger, Babu #define CPUID_8000_0008_EBX_STIBP       (1U << 15)
896623972ceSBabu Moger /* Speculative Store Bypass Disable */
897623972ceSBabu Moger #define CPUID_8000_0008_EBX_AMD_SSBD    (1U << 24)
8981b3420e1SEduardo Habkost 
899fcf5ef2aSThomas Huth #define CPUID_XSAVE_XSAVEOPT   (1U << 0)
900fcf5ef2aSThomas Huth #define CPUID_XSAVE_XSAVEC     (1U << 1)
901fcf5ef2aSThomas Huth #define CPUID_XSAVE_XGETBV1    (1U << 2)
902fcf5ef2aSThomas Huth #define CPUID_XSAVE_XSAVES     (1U << 3)
903fcf5ef2aSThomas Huth 
904fcf5ef2aSThomas Huth #define CPUID_6_EAX_ARAT       (1U << 2)
905fcf5ef2aSThomas Huth 
906fcf5ef2aSThomas Huth /* CPUID[0x80000007].EDX flags: */
907fcf5ef2aSThomas Huth #define CPUID_APM_INVTSC       (1U << 8)
908fcf5ef2aSThomas Huth 
909fcf5ef2aSThomas Huth #define CPUID_VENDOR_SZ      12
910fcf5ef2aSThomas Huth 
911fcf5ef2aSThomas Huth #define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */
912fcf5ef2aSThomas Huth #define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */
913fcf5ef2aSThomas Huth #define CPUID_VENDOR_INTEL_3 0x6c65746e /* "ntel" */
914fcf5ef2aSThomas Huth #define CPUID_VENDOR_INTEL "GenuineIntel"
915fcf5ef2aSThomas Huth 
916fcf5ef2aSThomas Huth #define CPUID_VENDOR_AMD_1   0x68747541 /* "Auth" */
917fcf5ef2aSThomas Huth #define CPUID_VENDOR_AMD_2   0x69746e65 /* "enti" */
918fcf5ef2aSThomas Huth #define CPUID_VENDOR_AMD_3   0x444d4163 /* "cAMD" */
919fcf5ef2aSThomas Huth #define CPUID_VENDOR_AMD   "AuthenticAMD"
920fcf5ef2aSThomas Huth 
921fcf5ef2aSThomas Huth #define CPUID_VENDOR_VIA   "CentaurHauls"
922fcf5ef2aSThomas Huth 
9238d031cecSPu Wen #define CPUID_VENDOR_HYGON    "HygonGenuine"
9248d031cecSPu Wen 
92518ab37baSLiran Alon #define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
92618ab37baSLiran Alon                            (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
92718ab37baSLiran Alon                            (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
92818ab37baSLiran Alon #define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
92918ab37baSLiran Alon                          (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
93018ab37baSLiran Alon                          (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
93118ab37baSLiran Alon 
932fcf5ef2aSThomas Huth #define CPUID_MWAIT_IBE     (1U << 1) /* Interrupts can exit capability */
933fcf5ef2aSThomas Huth #define CPUID_MWAIT_EMX     (1U << 0) /* enumeration supported */
934fcf5ef2aSThomas Huth 
935fcf5ef2aSThomas Huth /* CPUID[0xB].ECX level types */
936fcf5ef2aSThomas Huth #define CPUID_TOPOLOGY_LEVEL_INVALID  (0U << 8)
937fcf5ef2aSThomas Huth #define CPUID_TOPOLOGY_LEVEL_SMT      (1U << 8)
938fcf5ef2aSThomas Huth #define CPUID_TOPOLOGY_LEVEL_CORE     (2U << 8)
939a94e1428SLike Xu #define CPUID_TOPOLOGY_LEVEL_DIE      (5U << 8)
940fcf5ef2aSThomas Huth 
941d86f9636SRobert Hoo /* MSR Feature Bits */
942d86f9636SRobert Hoo #define MSR_ARCH_CAP_RDCL_NO            (1U << 0)
943d86f9636SRobert Hoo #define MSR_ARCH_CAP_IBRS_ALL           (1U << 1)
944d86f9636SRobert Hoo #define MSR_ARCH_CAP_RSBA               (1U << 2)
945d86f9636SRobert Hoo #define MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY (1U << 3)
946d86f9636SRobert Hoo #define MSR_ARCH_CAP_SSB_NO             (1U << 4)
94777b168d2SCathy Zhang #define MSR_ARCH_CAP_MDS_NO             (1U << 5)
9486c997b4aSXiaoyao Li #define MSR_ARCH_CAP_PSCHANGE_MC_NO     (1U << 6)
9496c997b4aSXiaoyao Li #define MSR_ARCH_CAP_TSX_CTRL_MSR       (1U << 7)
9506c997b4aSXiaoyao Li #define MSR_ARCH_CAP_TAA_NO             (1U << 8)
951d86f9636SRobert Hoo 
952597360c0SXiaoyao Li #define MSR_CORE_CAP_SPLIT_LOCK_DETECT  (1U << 5)
953597360c0SXiaoyao Li 
954704798adSPaolo Bonzini /* VMX MSR features */
955704798adSPaolo Bonzini #define MSR_VMX_BASIC_VMCS_REVISION_MASK             0x7FFFFFFFull
956704798adSPaolo Bonzini #define MSR_VMX_BASIC_VMXON_REGION_SIZE_MASK         (0x00001FFFull << 32)
957704798adSPaolo Bonzini #define MSR_VMX_BASIC_VMCS_MEM_TYPE_MASK             (0x003C0000ull << 32)
958704798adSPaolo Bonzini #define MSR_VMX_BASIC_DUAL_MONITOR                   (1ULL << 49)
959704798adSPaolo Bonzini #define MSR_VMX_BASIC_INS_OUTS                       (1ULL << 54)
960704798adSPaolo Bonzini #define MSR_VMX_BASIC_TRUE_CTLS                      (1ULL << 55)
961704798adSPaolo Bonzini 
962704798adSPaolo Bonzini #define MSR_VMX_MISC_PREEMPTION_TIMER_SHIFT_MASK     0x1Full
963704798adSPaolo Bonzini #define MSR_VMX_MISC_STORE_LMA                       (1ULL << 5)
964704798adSPaolo Bonzini #define MSR_VMX_MISC_ACTIVITY_HLT                    (1ULL << 6)
965704798adSPaolo Bonzini #define MSR_VMX_MISC_ACTIVITY_SHUTDOWN               (1ULL << 7)
966704798adSPaolo Bonzini #define MSR_VMX_MISC_ACTIVITY_WAIT_SIPI              (1ULL << 8)
967704798adSPaolo Bonzini #define MSR_VMX_MISC_MAX_MSR_LIST_SIZE_MASK          0x0E000000ull
968704798adSPaolo Bonzini #define MSR_VMX_MISC_VMWRITE_VMEXIT                  (1ULL << 29)
969704798adSPaolo Bonzini #define MSR_VMX_MISC_ZERO_LEN_INJECT                 (1ULL << 30)
970704798adSPaolo Bonzini 
971704798adSPaolo Bonzini #define MSR_VMX_EPT_EXECONLY                         (1ULL << 0)
972704798adSPaolo Bonzini #define MSR_VMX_EPT_PAGE_WALK_LENGTH_4               (1ULL << 6)
973704798adSPaolo Bonzini #define MSR_VMX_EPT_PAGE_WALK_LENGTH_5               (1ULL << 7)
974704798adSPaolo Bonzini #define MSR_VMX_EPT_UC                               (1ULL << 8)
975704798adSPaolo Bonzini #define MSR_VMX_EPT_WB                               (1ULL << 14)
976704798adSPaolo Bonzini #define MSR_VMX_EPT_2MB                              (1ULL << 16)
977704798adSPaolo Bonzini #define MSR_VMX_EPT_1GB                              (1ULL << 17)
978704798adSPaolo Bonzini #define MSR_VMX_EPT_INVEPT                           (1ULL << 20)
979704798adSPaolo Bonzini #define MSR_VMX_EPT_AD_BITS                          (1ULL << 21)
980704798adSPaolo Bonzini #define MSR_VMX_EPT_ADVANCED_VMEXIT_INFO             (1ULL << 22)
981704798adSPaolo Bonzini #define MSR_VMX_EPT_INVEPT_SINGLE_CONTEXT            (1ULL << 25)
982704798adSPaolo Bonzini #define MSR_VMX_EPT_INVEPT_ALL_CONTEXT               (1ULL << 26)
983704798adSPaolo Bonzini #define MSR_VMX_EPT_INVVPID                          (1ULL << 32)
984704798adSPaolo Bonzini #define MSR_VMX_EPT_INVVPID_SINGLE_ADDR              (1ULL << 40)
985704798adSPaolo Bonzini #define MSR_VMX_EPT_INVVPID_SINGLE_CONTEXT           (1ULL << 41)
986704798adSPaolo Bonzini #define MSR_VMX_EPT_INVVPID_ALL_CONTEXT              (1ULL << 42)
987704798adSPaolo Bonzini #define MSR_VMX_EPT_INVVPID_SINGLE_CONTEXT_NOGLOBALS (1ULL << 43)
988704798adSPaolo Bonzini 
989704798adSPaolo Bonzini #define MSR_VMX_VMFUNC_EPT_SWITCHING                 (1ULL << 0)
990704798adSPaolo Bonzini 
991704798adSPaolo Bonzini 
992704798adSPaolo Bonzini /* VMX controls */
993704798adSPaolo Bonzini #define VMX_CPU_BASED_VIRTUAL_INTR_PENDING          0x00000004
994704798adSPaolo Bonzini #define VMX_CPU_BASED_USE_TSC_OFFSETING             0x00000008
995704798adSPaolo Bonzini #define VMX_CPU_BASED_HLT_EXITING                   0x00000080
996704798adSPaolo Bonzini #define VMX_CPU_BASED_INVLPG_EXITING                0x00000200
997704798adSPaolo Bonzini #define VMX_CPU_BASED_MWAIT_EXITING                 0x00000400
998704798adSPaolo Bonzini #define VMX_CPU_BASED_RDPMC_EXITING                 0x00000800
999704798adSPaolo Bonzini #define VMX_CPU_BASED_RDTSC_EXITING                 0x00001000
1000704798adSPaolo Bonzini #define VMX_CPU_BASED_CR3_LOAD_EXITING              0x00008000
1001704798adSPaolo Bonzini #define VMX_CPU_BASED_CR3_STORE_EXITING             0x00010000
1002704798adSPaolo Bonzini #define VMX_CPU_BASED_CR8_LOAD_EXITING              0x00080000
1003704798adSPaolo Bonzini #define VMX_CPU_BASED_CR8_STORE_EXITING             0x00100000
1004704798adSPaolo Bonzini #define VMX_CPU_BASED_TPR_SHADOW                    0x00200000
1005704798adSPaolo Bonzini #define VMX_CPU_BASED_VIRTUAL_NMI_PENDING           0x00400000
1006704798adSPaolo Bonzini #define VMX_CPU_BASED_MOV_DR_EXITING                0x00800000
1007704798adSPaolo Bonzini #define VMX_CPU_BASED_UNCOND_IO_EXITING             0x01000000
1008704798adSPaolo Bonzini #define VMX_CPU_BASED_USE_IO_BITMAPS                0x02000000
1009704798adSPaolo Bonzini #define VMX_CPU_BASED_MONITOR_TRAP_FLAG             0x08000000
1010704798adSPaolo Bonzini #define VMX_CPU_BASED_USE_MSR_BITMAPS               0x10000000
1011704798adSPaolo Bonzini #define VMX_CPU_BASED_MONITOR_EXITING               0x20000000
1012704798adSPaolo Bonzini #define VMX_CPU_BASED_PAUSE_EXITING                 0x40000000
1013704798adSPaolo Bonzini #define VMX_CPU_BASED_ACTIVATE_SECONDARY_CONTROLS   0x80000000
1014704798adSPaolo Bonzini 
1015704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES 0x00000001
1016704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_ENABLE_EPT               0x00000002
1017704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_DESC                     0x00000004
1018704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_RDTSCP                   0x00000008
1019704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE   0x00000010
1020704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_ENABLE_VPID              0x00000020
1021704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_WBINVD_EXITING           0x00000040
1022704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_UNRESTRICTED_GUEST       0x00000080
1023704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_APIC_REGISTER_VIRT       0x00000100
1024704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY    0x00000200
1025704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_PAUSE_LOOP_EXITING       0x00000400
1026704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_RDRAND_EXITING           0x00000800
1027704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_ENABLE_INVPCID           0x00001000
1028704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_ENABLE_VMFUNC            0x00002000
1029704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_SHADOW_VMCS              0x00004000
1030704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_ENCLS_EXITING            0x00008000
1031704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_RDSEED_EXITING           0x00010000
1032704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_ENABLE_PML               0x00020000
1033704798adSPaolo Bonzini #define VMX_SECONDARY_EXEC_XSAVES                   0x00100000
10349ce8af4dSPaolo Bonzini #define VMX_SECONDARY_EXEC_TSC_SCALING              0x02000000
1035704798adSPaolo Bonzini 
1036704798adSPaolo Bonzini #define VMX_PIN_BASED_EXT_INTR_MASK                 0x00000001
1037704798adSPaolo Bonzini #define VMX_PIN_BASED_NMI_EXITING                   0x00000008
1038704798adSPaolo Bonzini #define VMX_PIN_BASED_VIRTUAL_NMIS                  0x00000020
1039704798adSPaolo Bonzini #define VMX_PIN_BASED_VMX_PREEMPTION_TIMER          0x00000040
1040704798adSPaolo Bonzini #define VMX_PIN_BASED_POSTED_INTR                   0x00000080
1041704798adSPaolo Bonzini 
1042704798adSPaolo Bonzini #define VMX_VM_EXIT_SAVE_DEBUG_CONTROLS             0x00000004
1043704798adSPaolo Bonzini #define VMX_VM_EXIT_HOST_ADDR_SPACE_SIZE            0x00000200
1044704798adSPaolo Bonzini #define VMX_VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL      0x00001000
1045704798adSPaolo Bonzini #define VMX_VM_EXIT_ACK_INTR_ON_EXIT                0x00008000
1046704798adSPaolo Bonzini #define VMX_VM_EXIT_SAVE_IA32_PAT                   0x00040000
1047704798adSPaolo Bonzini #define VMX_VM_EXIT_LOAD_IA32_PAT                   0x00080000
1048704798adSPaolo Bonzini #define VMX_VM_EXIT_SAVE_IA32_EFER                  0x00100000
1049704798adSPaolo Bonzini #define VMX_VM_EXIT_LOAD_IA32_EFER                  0x00200000
1050704798adSPaolo Bonzini #define VMX_VM_EXIT_SAVE_VMX_PREEMPTION_TIMER       0x00400000
1051704798adSPaolo Bonzini #define VMX_VM_EXIT_CLEAR_BNDCFGS                   0x00800000
1052704798adSPaolo Bonzini #define VMX_VM_EXIT_PT_CONCEAL_PIP                  0x01000000
1053704798adSPaolo Bonzini #define VMX_VM_EXIT_CLEAR_IA32_RTIT_CTL             0x02000000
105452a44ad2SChenyi Qiang #define VMX_VM_EXIT_LOAD_IA32_PKRS                  0x20000000
1055704798adSPaolo Bonzini 
1056704798adSPaolo Bonzini #define VMX_VM_ENTRY_LOAD_DEBUG_CONTROLS            0x00000004
1057704798adSPaolo Bonzini #define VMX_VM_ENTRY_IA32E_MODE                     0x00000200
1058704798adSPaolo Bonzini #define VMX_VM_ENTRY_SMM                            0x00000400
1059704798adSPaolo Bonzini #define VMX_VM_ENTRY_DEACT_DUAL_MONITOR             0x00000800
1060704798adSPaolo Bonzini #define VMX_VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL     0x00002000
1061704798adSPaolo Bonzini #define VMX_VM_ENTRY_LOAD_IA32_PAT                  0x00004000
1062704798adSPaolo Bonzini #define VMX_VM_ENTRY_LOAD_IA32_EFER                 0x00008000
1063704798adSPaolo Bonzini #define VMX_VM_ENTRY_LOAD_BNDCFGS                   0x00010000
1064704798adSPaolo Bonzini #define VMX_VM_ENTRY_PT_CONCEAL_PIP                 0x00020000
1065704798adSPaolo Bonzini #define VMX_VM_ENTRY_LOAD_IA32_RTIT_CTL             0x00040000
106652a44ad2SChenyi Qiang #define VMX_VM_ENTRY_LOAD_IA32_PKRS                 0x00400000
1067704798adSPaolo Bonzini 
10682d384d7cSVitaly Kuznetsov /* Supported Hyper-V Enlightenments */
10692d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_RELAXED             0
10702d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_VAPIC               1
10712d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_TIME                2
10722d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_CRASH               3
10732d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_RESET               4
10742d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_VPINDEX             5
10752d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_RUNTIME             6
10762d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_SYNIC               7
10772d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_STIMER              8
10782d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_FREQUENCIES         9
10792d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_REENLIGHTENMENT     10
10802d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_TLBFLUSH            11
10812d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_EVMCS               12
10822d384d7cSVitaly Kuznetsov #define HYPERV_FEAT_IPI                 13
1083128531d9SVitaly Kuznetsov #define HYPERV_FEAT_STIMER_DIRECT       14
1084e1f9a8e8SVitaly Kuznetsov #define HYPERV_FEAT_AVIC                15
10852d384d7cSVitaly Kuznetsov 
1086f701c082SVitaly Kuznetsov #ifndef HYPERV_SPINLOCK_NEVER_NOTIFY
1087f701c082SVitaly Kuznetsov #define HYPERV_SPINLOCK_NEVER_NOTIFY             0xFFFFFFFF
1088fcf5ef2aSThomas Huth #endif
1089fcf5ef2aSThomas Huth 
1090fcf5ef2aSThomas Huth #define EXCP00_DIVZ	0
1091fcf5ef2aSThomas Huth #define EXCP01_DB	1
1092fcf5ef2aSThomas Huth #define EXCP02_NMI	2
1093fcf5ef2aSThomas Huth #define EXCP03_INT3	3
1094fcf5ef2aSThomas Huth #define EXCP04_INTO	4
1095fcf5ef2aSThomas Huth #define EXCP05_BOUND	5
1096fcf5ef2aSThomas Huth #define EXCP06_ILLOP	6
1097fcf5ef2aSThomas Huth #define EXCP07_PREX	7
1098fcf5ef2aSThomas Huth #define EXCP08_DBLE	8
1099fcf5ef2aSThomas Huth #define EXCP09_XERR	9
1100fcf5ef2aSThomas Huth #define EXCP0A_TSS	10
1101fcf5ef2aSThomas Huth #define EXCP0B_NOSEG	11
1102fcf5ef2aSThomas Huth #define EXCP0C_STACK	12
1103fcf5ef2aSThomas Huth #define EXCP0D_GPF	13
1104fcf5ef2aSThomas Huth #define EXCP0E_PAGE	14
1105fcf5ef2aSThomas Huth #define EXCP10_COPR	16
1106fcf5ef2aSThomas Huth #define EXCP11_ALGN	17
1107fcf5ef2aSThomas Huth #define EXCP12_MCHK	18
1108fcf5ef2aSThomas Huth 
110962846089SRichard Henderson #define EXCP_VMEXIT     0x100 /* only for system emulation */
111062846089SRichard Henderson #define EXCP_SYSCALL    0x101 /* only for user emulation */
1111b26491b4SRichard Henderson #define EXCP_VSYSCALL   0x102 /* only for user emulation */
1112fcf5ef2aSThomas Huth 
1113fcf5ef2aSThomas Huth /* i386-specific interrupt pending bits.  */
1114fcf5ef2aSThomas Huth #define CPU_INTERRUPT_POLL      CPU_INTERRUPT_TGT_EXT_1
1115fcf5ef2aSThomas Huth #define CPU_INTERRUPT_SMI       CPU_INTERRUPT_TGT_EXT_2
1116fcf5ef2aSThomas Huth #define CPU_INTERRUPT_NMI       CPU_INTERRUPT_TGT_EXT_3
1117fcf5ef2aSThomas Huth #define CPU_INTERRUPT_MCE       CPU_INTERRUPT_TGT_EXT_4
1118fcf5ef2aSThomas Huth #define CPU_INTERRUPT_VIRQ      CPU_INTERRUPT_TGT_INT_0
1119fcf5ef2aSThomas Huth #define CPU_INTERRUPT_SIPI      CPU_INTERRUPT_TGT_INT_1
1120fcf5ef2aSThomas Huth #define CPU_INTERRUPT_TPR       CPU_INTERRUPT_TGT_INT_2
1121fcf5ef2aSThomas Huth 
1122fcf5ef2aSThomas Huth /* Use a clearer name for this.  */
1123fcf5ef2aSThomas Huth #define CPU_INTERRUPT_INIT      CPU_INTERRUPT_RESET
1124fcf5ef2aSThomas Huth 
1125fcf5ef2aSThomas Huth /* Instead of computing the condition codes after each x86 instruction,
1126fcf5ef2aSThomas Huth  * QEMU just stores one operand (called CC_SRC), the result
1127fcf5ef2aSThomas Huth  * (called CC_DST) and the type of operation (called CC_OP). When the
1128fcf5ef2aSThomas Huth  * condition codes are needed, the condition codes can be calculated
1129fcf5ef2aSThomas Huth  * using this information. Condition codes are not generated if they
1130fcf5ef2aSThomas Huth  * are only needed for conditional branches.
1131fcf5ef2aSThomas Huth  */
1132fcf5ef2aSThomas Huth typedef enum {
1133fcf5ef2aSThomas Huth     CC_OP_DYNAMIC, /* must use dynamic code to get cc_op */
1134fcf5ef2aSThomas Huth     CC_OP_EFLAGS,  /* all cc are explicitly computed, CC_SRC = flags */
1135fcf5ef2aSThomas Huth 
1136fcf5ef2aSThomas Huth     CC_OP_MULB, /* modify all flags, C, O = (CC_SRC != 0) */
1137fcf5ef2aSThomas Huth     CC_OP_MULW,
1138fcf5ef2aSThomas Huth     CC_OP_MULL,
1139fcf5ef2aSThomas Huth     CC_OP_MULQ,
1140fcf5ef2aSThomas Huth 
1141fcf5ef2aSThomas Huth     CC_OP_ADDB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
1142fcf5ef2aSThomas Huth     CC_OP_ADDW,
1143fcf5ef2aSThomas Huth     CC_OP_ADDL,
1144fcf5ef2aSThomas Huth     CC_OP_ADDQ,
1145fcf5ef2aSThomas Huth 
1146fcf5ef2aSThomas Huth     CC_OP_ADCB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
1147fcf5ef2aSThomas Huth     CC_OP_ADCW,
1148fcf5ef2aSThomas Huth     CC_OP_ADCL,
1149fcf5ef2aSThomas Huth     CC_OP_ADCQ,
1150fcf5ef2aSThomas Huth 
1151fcf5ef2aSThomas Huth     CC_OP_SUBB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
1152fcf5ef2aSThomas Huth     CC_OP_SUBW,
1153fcf5ef2aSThomas Huth     CC_OP_SUBL,
1154fcf5ef2aSThomas Huth     CC_OP_SUBQ,
1155fcf5ef2aSThomas Huth 
1156fcf5ef2aSThomas Huth     CC_OP_SBBB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
1157fcf5ef2aSThomas Huth     CC_OP_SBBW,
1158fcf5ef2aSThomas Huth     CC_OP_SBBL,
1159fcf5ef2aSThomas Huth     CC_OP_SBBQ,
1160fcf5ef2aSThomas Huth 
1161fcf5ef2aSThomas Huth     CC_OP_LOGICB, /* modify all flags, CC_DST = res */
1162fcf5ef2aSThomas Huth     CC_OP_LOGICW,
1163fcf5ef2aSThomas Huth     CC_OP_LOGICL,
1164fcf5ef2aSThomas Huth     CC_OP_LOGICQ,
1165fcf5ef2aSThomas Huth 
1166fcf5ef2aSThomas Huth     CC_OP_INCB, /* modify all flags except, CC_DST = res, CC_SRC = C */
1167fcf5ef2aSThomas Huth     CC_OP_INCW,
1168fcf5ef2aSThomas Huth     CC_OP_INCL,
1169fcf5ef2aSThomas Huth     CC_OP_INCQ,
1170fcf5ef2aSThomas Huth 
1171fcf5ef2aSThomas Huth     CC_OP_DECB, /* modify all flags except, CC_DST = res, CC_SRC = C  */
1172fcf5ef2aSThomas Huth     CC_OP_DECW,
1173fcf5ef2aSThomas Huth     CC_OP_DECL,
1174fcf5ef2aSThomas Huth     CC_OP_DECQ,
1175fcf5ef2aSThomas Huth 
1176fcf5ef2aSThomas Huth     CC_OP_SHLB, /* modify all flags, CC_DST = res, CC_SRC.msb = C */
1177fcf5ef2aSThomas Huth     CC_OP_SHLW,
1178fcf5ef2aSThomas Huth     CC_OP_SHLL,
1179fcf5ef2aSThomas Huth     CC_OP_SHLQ,
1180fcf5ef2aSThomas Huth 
1181fcf5ef2aSThomas Huth     CC_OP_SARB, /* modify all flags, CC_DST = res, CC_SRC.lsb = C */
1182fcf5ef2aSThomas Huth     CC_OP_SARW,
1183fcf5ef2aSThomas Huth     CC_OP_SARL,
1184fcf5ef2aSThomas Huth     CC_OP_SARQ,
1185fcf5ef2aSThomas Huth 
1186fcf5ef2aSThomas Huth     CC_OP_BMILGB, /* Z,S via CC_DST, C = SRC==0; O=0; P,A undefined */
1187fcf5ef2aSThomas Huth     CC_OP_BMILGW,
1188fcf5ef2aSThomas Huth     CC_OP_BMILGL,
1189fcf5ef2aSThomas Huth     CC_OP_BMILGQ,
1190fcf5ef2aSThomas Huth 
1191fcf5ef2aSThomas Huth     CC_OP_ADCX, /* CC_DST = C, CC_SRC = rest.  */
1192fcf5ef2aSThomas Huth     CC_OP_ADOX, /* CC_DST = O, CC_SRC = rest.  */
1193fcf5ef2aSThomas Huth     CC_OP_ADCOX, /* CC_DST = C, CC_SRC2 = O, CC_SRC = rest.  */
1194fcf5ef2aSThomas Huth 
1195fcf5ef2aSThomas Huth     CC_OP_CLR, /* Z set, all other flags clear.  */
11964885c3c4SRichard Henderson     CC_OP_POPCNT, /* Z via CC_SRC, all other flags clear.  */
1197fcf5ef2aSThomas Huth 
1198fcf5ef2aSThomas Huth     CC_OP_NB,
1199fcf5ef2aSThomas Huth } CCOp;
1200fcf5ef2aSThomas Huth 
1201fcf5ef2aSThomas Huth typedef struct SegmentCache {
1202fcf5ef2aSThomas Huth     uint32_t selector;
1203fcf5ef2aSThomas Huth     target_ulong base;
1204fcf5ef2aSThomas Huth     uint32_t limit;
1205fcf5ef2aSThomas Huth     uint32_t flags;
1206fcf5ef2aSThomas Huth } SegmentCache;
1207fcf5ef2aSThomas Huth 
1208fcf5ef2aSThomas Huth #define MMREG_UNION(n, bits)        \
1209fcf5ef2aSThomas Huth     union n {                       \
1210fcf5ef2aSThomas Huth         uint8_t  _b_##n[(bits)/8];  \
1211fcf5ef2aSThomas Huth         uint16_t _w_##n[(bits)/16]; \
1212fcf5ef2aSThomas Huth         uint32_t _l_##n[(bits)/32]; \
1213fcf5ef2aSThomas Huth         uint64_t _q_##n[(bits)/64]; \
1214fcf5ef2aSThomas Huth         float32  _s_##n[(bits)/32]; \
1215fcf5ef2aSThomas Huth         float64  _d_##n[(bits)/64]; \
1216fcf5ef2aSThomas Huth     }
1217fcf5ef2aSThomas Huth 
1218c97d6d2cSSergio Andres Gomez Del Real typedef union {
1219c97d6d2cSSergio Andres Gomez Del Real     uint8_t _b[16];
1220c97d6d2cSSergio Andres Gomez Del Real     uint16_t _w[8];
1221c97d6d2cSSergio Andres Gomez Del Real     uint32_t _l[4];
1222c97d6d2cSSergio Andres Gomez Del Real     uint64_t _q[2];
1223c97d6d2cSSergio Andres Gomez Del Real } XMMReg;
1224c97d6d2cSSergio Andres Gomez Del Real 
1225c97d6d2cSSergio Andres Gomez Del Real typedef union {
1226c97d6d2cSSergio Andres Gomez Del Real     uint8_t _b[32];
1227c97d6d2cSSergio Andres Gomez Del Real     uint16_t _w[16];
1228c97d6d2cSSergio Andres Gomez Del Real     uint32_t _l[8];
1229c97d6d2cSSergio Andres Gomez Del Real     uint64_t _q[4];
1230c97d6d2cSSergio Andres Gomez Del Real } YMMReg;
1231c97d6d2cSSergio Andres Gomez Del Real 
1232fcf5ef2aSThomas Huth typedef MMREG_UNION(ZMMReg, 512) ZMMReg;
1233fcf5ef2aSThomas Huth typedef MMREG_UNION(MMXReg, 64)  MMXReg;
1234fcf5ef2aSThomas Huth 
1235fcf5ef2aSThomas Huth typedef struct BNDReg {
1236fcf5ef2aSThomas Huth     uint64_t lb;
1237fcf5ef2aSThomas Huth     uint64_t ub;
1238fcf5ef2aSThomas Huth } BNDReg;
1239fcf5ef2aSThomas Huth 
1240fcf5ef2aSThomas Huth typedef struct BNDCSReg {
1241fcf5ef2aSThomas Huth     uint64_t cfgu;
1242fcf5ef2aSThomas Huth     uint64_t sts;
1243fcf5ef2aSThomas Huth } BNDCSReg;
1244fcf5ef2aSThomas Huth 
1245fcf5ef2aSThomas Huth #define BNDCFG_ENABLE       1ULL
1246fcf5ef2aSThomas Huth #define BNDCFG_BNDPRESERVE  2ULL
1247fcf5ef2aSThomas Huth #define BNDCFG_BDIR_MASK    TARGET_PAGE_MASK
1248fcf5ef2aSThomas Huth 
1249fcf5ef2aSThomas Huth #ifdef HOST_WORDS_BIGENDIAN
1250fcf5ef2aSThomas Huth #define ZMM_B(n) _b_ZMMReg[63 - (n)]
1251fcf5ef2aSThomas Huth #define ZMM_W(n) _w_ZMMReg[31 - (n)]
1252fcf5ef2aSThomas Huth #define ZMM_L(n) _l_ZMMReg[15 - (n)]
1253fcf5ef2aSThomas Huth #define ZMM_S(n) _s_ZMMReg[15 - (n)]
1254fcf5ef2aSThomas Huth #define ZMM_Q(n) _q_ZMMReg[7 - (n)]
1255fcf5ef2aSThomas Huth #define ZMM_D(n) _d_ZMMReg[7 - (n)]
1256fcf5ef2aSThomas Huth 
1257fcf5ef2aSThomas Huth #define MMX_B(n) _b_MMXReg[7 - (n)]
1258fcf5ef2aSThomas Huth #define MMX_W(n) _w_MMXReg[3 - (n)]
1259fcf5ef2aSThomas Huth #define MMX_L(n) _l_MMXReg[1 - (n)]
1260fcf5ef2aSThomas Huth #define MMX_S(n) _s_MMXReg[1 - (n)]
1261fcf5ef2aSThomas Huth #else
1262fcf5ef2aSThomas Huth #define ZMM_B(n) _b_ZMMReg[n]
1263fcf5ef2aSThomas Huth #define ZMM_W(n) _w_ZMMReg[n]
1264fcf5ef2aSThomas Huth #define ZMM_L(n) _l_ZMMReg[n]
1265fcf5ef2aSThomas Huth #define ZMM_S(n) _s_ZMMReg[n]
1266fcf5ef2aSThomas Huth #define ZMM_Q(n) _q_ZMMReg[n]
1267fcf5ef2aSThomas Huth #define ZMM_D(n) _d_ZMMReg[n]
1268fcf5ef2aSThomas Huth 
1269fcf5ef2aSThomas Huth #define MMX_B(n) _b_MMXReg[n]
1270fcf5ef2aSThomas Huth #define MMX_W(n) _w_MMXReg[n]
1271fcf5ef2aSThomas Huth #define MMX_L(n) _l_MMXReg[n]
1272fcf5ef2aSThomas Huth #define MMX_S(n) _s_MMXReg[n]
1273fcf5ef2aSThomas Huth #endif
1274fcf5ef2aSThomas Huth #define MMX_Q(n) _q_MMXReg[n]
1275fcf5ef2aSThomas Huth 
1276fcf5ef2aSThomas Huth typedef union {
1277fcf5ef2aSThomas Huth     floatx80 d __attribute__((aligned(16)));
1278fcf5ef2aSThomas Huth     MMXReg mmx;
1279fcf5ef2aSThomas Huth } FPReg;
1280fcf5ef2aSThomas Huth 
1281fcf5ef2aSThomas Huth typedef struct {
1282fcf5ef2aSThomas Huth     uint64_t base;
1283fcf5ef2aSThomas Huth     uint64_t mask;
1284fcf5ef2aSThomas Huth } MTRRVar;
1285fcf5ef2aSThomas Huth 
1286fcf5ef2aSThomas Huth #define CPU_NB_REGS64 16
1287fcf5ef2aSThomas Huth #define CPU_NB_REGS32 8
1288fcf5ef2aSThomas Huth 
1289fcf5ef2aSThomas Huth #ifdef TARGET_X86_64
1290fcf5ef2aSThomas Huth #define CPU_NB_REGS CPU_NB_REGS64
1291fcf5ef2aSThomas Huth #else
1292fcf5ef2aSThomas Huth #define CPU_NB_REGS CPU_NB_REGS32
1293fcf5ef2aSThomas Huth #endif
1294fcf5ef2aSThomas Huth 
1295fcf5ef2aSThomas Huth #define MAX_FIXED_COUNTERS 3
1296fcf5ef2aSThomas Huth #define MAX_GP_COUNTERS    (MSR_IA32_PERF_STATUS - MSR_P6_EVNTSEL0)
1297fcf5ef2aSThomas Huth 
1298fcf5ef2aSThomas Huth #define TARGET_INSN_START_EXTRA_WORDS 1
1299fcf5ef2aSThomas Huth 
1300fcf5ef2aSThomas Huth #define NB_OPMASK_REGS 8
1301fcf5ef2aSThomas Huth 
1302fcf5ef2aSThomas Huth /* CPU can't have 0xFFFFFFFF APIC ID, use that value to distinguish
1303fcf5ef2aSThomas Huth  * that APIC ID hasn't been set yet
1304fcf5ef2aSThomas Huth  */
1305fcf5ef2aSThomas Huth #define UNASSIGNED_APIC_ID 0xFFFFFFFF
1306fcf5ef2aSThomas Huth 
1307fcf5ef2aSThomas Huth typedef union X86LegacyXSaveArea {
1308fcf5ef2aSThomas Huth     struct {
1309fcf5ef2aSThomas Huth         uint16_t fcw;
1310fcf5ef2aSThomas Huth         uint16_t fsw;
1311fcf5ef2aSThomas Huth         uint8_t ftw;
1312fcf5ef2aSThomas Huth         uint8_t reserved;
1313fcf5ef2aSThomas Huth         uint16_t fpop;
1314fcf5ef2aSThomas Huth         uint64_t fpip;
1315fcf5ef2aSThomas Huth         uint64_t fpdp;
1316fcf5ef2aSThomas Huth         uint32_t mxcsr;
1317fcf5ef2aSThomas Huth         uint32_t mxcsr_mask;
1318fcf5ef2aSThomas Huth         FPReg fpregs[8];
1319fcf5ef2aSThomas Huth         uint8_t xmm_regs[16][16];
1320fcf5ef2aSThomas Huth     };
1321fcf5ef2aSThomas Huth     uint8_t data[512];
1322fcf5ef2aSThomas Huth } X86LegacyXSaveArea;
1323fcf5ef2aSThomas Huth 
1324fcf5ef2aSThomas Huth typedef struct X86XSaveHeader {
1325fcf5ef2aSThomas Huth     uint64_t xstate_bv;
1326fcf5ef2aSThomas Huth     uint64_t xcomp_bv;
1327fcf5ef2aSThomas Huth     uint64_t reserve0;
1328fcf5ef2aSThomas Huth     uint8_t reserved[40];
1329fcf5ef2aSThomas Huth } X86XSaveHeader;
1330fcf5ef2aSThomas Huth 
1331fcf5ef2aSThomas Huth /* Ext. save area 2: AVX State */
1332fcf5ef2aSThomas Huth typedef struct XSaveAVX {
1333fcf5ef2aSThomas Huth     uint8_t ymmh[16][16];
1334fcf5ef2aSThomas Huth } XSaveAVX;
1335fcf5ef2aSThomas Huth 
1336fcf5ef2aSThomas Huth /* Ext. save area 3: BNDREG */
1337fcf5ef2aSThomas Huth typedef struct XSaveBNDREG {
1338fcf5ef2aSThomas Huth     BNDReg bnd_regs[4];
1339fcf5ef2aSThomas Huth } XSaveBNDREG;
1340fcf5ef2aSThomas Huth 
1341fcf5ef2aSThomas Huth /* Ext. save area 4: BNDCSR */
1342fcf5ef2aSThomas Huth typedef union XSaveBNDCSR {
1343fcf5ef2aSThomas Huth     BNDCSReg bndcsr;
1344fcf5ef2aSThomas Huth     uint8_t data[64];
1345fcf5ef2aSThomas Huth } XSaveBNDCSR;
1346fcf5ef2aSThomas Huth 
1347fcf5ef2aSThomas Huth /* Ext. save area 5: Opmask */
1348fcf5ef2aSThomas Huth typedef struct XSaveOpmask {
1349fcf5ef2aSThomas Huth     uint64_t opmask_regs[NB_OPMASK_REGS];
1350fcf5ef2aSThomas Huth } XSaveOpmask;
1351fcf5ef2aSThomas Huth 
1352fcf5ef2aSThomas Huth /* Ext. save area 6: ZMM_Hi256 */
1353fcf5ef2aSThomas Huth typedef struct XSaveZMM_Hi256 {
1354fcf5ef2aSThomas Huth     uint8_t zmm_hi256[16][32];
1355fcf5ef2aSThomas Huth } XSaveZMM_Hi256;
1356fcf5ef2aSThomas Huth 
1357fcf5ef2aSThomas Huth /* Ext. save area 7: Hi16_ZMM */
1358fcf5ef2aSThomas Huth typedef struct XSaveHi16_ZMM {
1359fcf5ef2aSThomas Huth     uint8_t hi16_zmm[16][64];
1360fcf5ef2aSThomas Huth } XSaveHi16_ZMM;
1361fcf5ef2aSThomas Huth 
1362fcf5ef2aSThomas Huth /* Ext. save area 9: PKRU state */
1363fcf5ef2aSThomas Huth typedef struct XSavePKRU {
1364fcf5ef2aSThomas Huth     uint32_t pkru;
1365fcf5ef2aSThomas Huth     uint32_t padding;
1366fcf5ef2aSThomas Huth } XSavePKRU;
1367fcf5ef2aSThomas Huth 
13681f16764fSJing Liu /* Ext. save area 17: AMX XTILECFG state */
13691f16764fSJing Liu typedef struct XSaveXTILECFG {
13701f16764fSJing Liu     uint8_t xtilecfg[64];
13711f16764fSJing Liu } XSaveXTILECFG;
13721f16764fSJing Liu 
13731f16764fSJing Liu /* Ext. save area 18: AMX XTILEDATA state */
13741f16764fSJing Liu typedef struct XSaveXTILEDATA {
13751f16764fSJing Liu     uint8_t xtiledata[8][1024];
13761f16764fSJing Liu } XSaveXTILEDATA;
13771f16764fSJing Liu 
1378fcf5ef2aSThomas Huth QEMU_BUILD_BUG_ON(sizeof(XSaveAVX) != 0x100);
1379fcf5ef2aSThomas Huth QEMU_BUILD_BUG_ON(sizeof(XSaveBNDREG) != 0x40);
1380fcf5ef2aSThomas Huth QEMU_BUILD_BUG_ON(sizeof(XSaveBNDCSR) != 0x40);
1381fcf5ef2aSThomas Huth QEMU_BUILD_BUG_ON(sizeof(XSaveOpmask) != 0x40);
1382fcf5ef2aSThomas Huth QEMU_BUILD_BUG_ON(sizeof(XSaveZMM_Hi256) != 0x200);
1383fcf5ef2aSThomas Huth QEMU_BUILD_BUG_ON(sizeof(XSaveHi16_ZMM) != 0x400);
1384fcf5ef2aSThomas Huth QEMU_BUILD_BUG_ON(sizeof(XSavePKRU) != 0x8);
13851f16764fSJing Liu QEMU_BUILD_BUG_ON(sizeof(XSaveXTILECFG) != 0x40);
13861f16764fSJing Liu QEMU_BUILD_BUG_ON(sizeof(XSaveXTILEDATA) != 0x2000);
1387fcf5ef2aSThomas Huth 
13885aa10ab1SDavid Edmondson typedef struct ExtSaveArea {
13895aa10ab1SDavid Edmondson     uint32_t feature, bits;
13905aa10ab1SDavid Edmondson     uint32_t offset, size;
1391131266b7SJing Liu     uint32_t ecx;
13925aa10ab1SDavid Edmondson } ExtSaveArea;
13935aa10ab1SDavid Edmondson 
13941f16764fSJing Liu #define XSAVE_STATE_AREA_COUNT (XSTATE_XTILE_DATA_BIT + 1)
13955aa10ab1SDavid Edmondson 
1396fea45008SDavid Edmondson extern ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT];
13975aa10ab1SDavid Edmondson 
1398fcf5ef2aSThomas Huth typedef enum TPRAccess {
1399fcf5ef2aSThomas Huth     TPR_ACCESS_READ,
1400fcf5ef2aSThomas Huth     TPR_ACCESS_WRITE,
1401fcf5ef2aSThomas Huth } TPRAccess;
1402fcf5ef2aSThomas Huth 
14037e3482f8SEduardo Habkost /* Cache information data structures: */
14047e3482f8SEduardo Habkost 
14057e3482f8SEduardo Habkost enum CacheType {
14065f00335aSEduardo Habkost     DATA_CACHE,
14075f00335aSEduardo Habkost     INSTRUCTION_CACHE,
14087e3482f8SEduardo Habkost     UNIFIED_CACHE
14097e3482f8SEduardo Habkost };
14107e3482f8SEduardo Habkost 
14117e3482f8SEduardo Habkost typedef struct CPUCacheInfo {
14127e3482f8SEduardo Habkost     enum CacheType type;
14137e3482f8SEduardo Habkost     uint8_t level;
14147e3482f8SEduardo Habkost     /* Size in bytes */
14157e3482f8SEduardo Habkost     uint32_t size;
14167e3482f8SEduardo Habkost     /* Line size, in bytes */
14177e3482f8SEduardo Habkost     uint16_t line_size;
14187e3482f8SEduardo Habkost     /*
14197e3482f8SEduardo Habkost      * Associativity.
14207e3482f8SEduardo Habkost      * Note: representation of fully-associative caches is not implemented
14217e3482f8SEduardo Habkost      */
14227e3482f8SEduardo Habkost     uint8_t associativity;
14237e3482f8SEduardo Habkost     /* Physical line partitions. CPUID[0x8000001D].EBX, CPUID[4].EBX */
14247e3482f8SEduardo Habkost     uint8_t partitions;
14257e3482f8SEduardo Habkost     /* Number of sets. CPUID[0x8000001D].ECX, CPUID[4].ECX */
14267e3482f8SEduardo Habkost     uint32_t sets;
14277e3482f8SEduardo Habkost     /*
14287e3482f8SEduardo Habkost      * Lines per tag.
14297e3482f8SEduardo Habkost      * AMD-specific: CPUID[0x80000005], CPUID[0x80000006].
14307e3482f8SEduardo Habkost      * (Is this synonym to @partitions?)
14317e3482f8SEduardo Habkost      */
14327e3482f8SEduardo Habkost     uint8_t lines_per_tag;
14337e3482f8SEduardo Habkost 
14347e3482f8SEduardo Habkost     /* Self-initializing cache */
14357e3482f8SEduardo Habkost     bool self_init;
14367e3482f8SEduardo Habkost     /*
14377e3482f8SEduardo Habkost      * WBINVD/INVD is not guaranteed to act upon lower level caches of
14387e3482f8SEduardo Habkost      * non-originating threads sharing this cache.
14397e3482f8SEduardo Habkost      * CPUID[4].EDX[bit 0], CPUID[0x8000001D].EDX[bit 0]
14407e3482f8SEduardo Habkost      */
14417e3482f8SEduardo Habkost     bool no_invd_sharing;
14427e3482f8SEduardo Habkost     /*
14437e3482f8SEduardo Habkost      * Cache is inclusive of lower cache levels.
14447e3482f8SEduardo Habkost      * CPUID[4].EDX[bit 1], CPUID[0x8000001D].EDX[bit 1].
14457e3482f8SEduardo Habkost      */
14467e3482f8SEduardo Habkost     bool inclusive;
14477e3482f8SEduardo Habkost     /*
14487e3482f8SEduardo Habkost      * A complex function is used to index the cache, potentially using all
14497e3482f8SEduardo Habkost      * address bits.  CPUID[4].EDX[bit 2].
14507e3482f8SEduardo Habkost      */
14517e3482f8SEduardo Habkost     bool complex_indexing;
14527e3482f8SEduardo Habkost } CPUCacheInfo;
14537e3482f8SEduardo Habkost 
14547e3482f8SEduardo Habkost 
14556aaeb054SBabu Moger typedef struct CPUCaches {
1456a9f27ea9SEduardo Habkost         CPUCacheInfo *l1d_cache;
1457a9f27ea9SEduardo Habkost         CPUCacheInfo *l1i_cache;
1458a9f27ea9SEduardo Habkost         CPUCacheInfo *l2_cache;
1459a9f27ea9SEduardo Habkost         CPUCacheInfo *l3_cache;
14606aaeb054SBabu Moger } CPUCaches;
14617e3482f8SEduardo Habkost 
1462577f02b8SRoman Bolshakov typedef struct HVFX86LazyFlags {
1463577f02b8SRoman Bolshakov     target_ulong result;
1464577f02b8SRoman Bolshakov     target_ulong auxbits;
1465577f02b8SRoman Bolshakov } HVFX86LazyFlags;
1466577f02b8SRoman Bolshakov 
14671ea4a06aSPhilippe Mathieu-Daudé typedef struct CPUArchState {
1468fcf5ef2aSThomas Huth     /* standard registers */
1469fcf5ef2aSThomas Huth     target_ulong regs[CPU_NB_REGS];
1470fcf5ef2aSThomas Huth     target_ulong eip;
1471fcf5ef2aSThomas Huth     target_ulong eflags; /* eflags register. During CPU emulation, CC
1472fcf5ef2aSThomas Huth                         flags and DF are set to zero because they are
1473fcf5ef2aSThomas Huth                         stored elsewhere */
1474fcf5ef2aSThomas Huth 
1475fcf5ef2aSThomas Huth     /* emulator internal eflags handling */
1476fcf5ef2aSThomas Huth     target_ulong cc_dst;
1477fcf5ef2aSThomas Huth     target_ulong cc_src;
1478fcf5ef2aSThomas Huth     target_ulong cc_src2;
1479fcf5ef2aSThomas Huth     uint32_t cc_op;
1480fcf5ef2aSThomas Huth     int32_t df; /* D flag : 1 if D = 0, -1 if D = 1 */
1481fcf5ef2aSThomas Huth     uint32_t hflags; /* TB flags, see HF_xxx constants. These flags
1482fcf5ef2aSThomas Huth                         are known at translation time. */
1483fcf5ef2aSThomas Huth     uint32_t hflags2; /* various other flags, see HF2_xxx constants. */
1484fcf5ef2aSThomas Huth 
1485fcf5ef2aSThomas Huth     /* segments */
1486fcf5ef2aSThomas Huth     SegmentCache segs[6]; /* selector values */
1487fcf5ef2aSThomas Huth     SegmentCache ldt;
1488fcf5ef2aSThomas Huth     SegmentCache tr;
1489fcf5ef2aSThomas Huth     SegmentCache gdt; /* only base and limit are used */
1490fcf5ef2aSThomas Huth     SegmentCache idt; /* only base and limit are used */
1491fcf5ef2aSThomas Huth 
1492fcf5ef2aSThomas Huth     target_ulong cr[5]; /* NOTE: cr1 is unused */
14938f515d38SMaxim Levitsky 
14948f515d38SMaxim Levitsky     bool pdptrs_valid;
14958f515d38SMaxim Levitsky     uint64_t pdptrs[4];
1496fcf5ef2aSThomas Huth     int32_t a20_mask;
1497fcf5ef2aSThomas Huth 
1498fcf5ef2aSThomas Huth     BNDReg bnd_regs[4];
1499fcf5ef2aSThomas Huth     BNDCSReg bndcs_regs;
1500fcf5ef2aSThomas Huth     uint64_t msr_bndcfgs;
1501fcf5ef2aSThomas Huth     uint64_t efer;
1502fcf5ef2aSThomas Huth 
1503fcf5ef2aSThomas Huth     /* Beginning of state preserved by INIT (dummy marker).  */
1504fcf5ef2aSThomas Huth     struct {} start_init_save;
1505fcf5ef2aSThomas Huth 
1506fcf5ef2aSThomas Huth     /* FPU state */
1507fcf5ef2aSThomas Huth     unsigned int fpstt; /* top of stack index */
1508fcf5ef2aSThomas Huth     uint16_t fpus;
1509fcf5ef2aSThomas Huth     uint16_t fpuc;
1510fcf5ef2aSThomas Huth     uint8_t fptags[8];   /* 0 = valid, 1 = empty */
1511fcf5ef2aSThomas Huth     FPReg fpregs[8];
1512fcf5ef2aSThomas Huth     /* KVM-only so far */
1513fcf5ef2aSThomas Huth     uint16_t fpop;
151484abdd7dSZiqiao Kong     uint16_t fpcs;
151584abdd7dSZiqiao Kong     uint16_t fpds;
1516fcf5ef2aSThomas Huth     uint64_t fpip;
1517fcf5ef2aSThomas Huth     uint64_t fpdp;
1518fcf5ef2aSThomas Huth 
1519fcf5ef2aSThomas Huth     /* emulator internal variables */
1520fcf5ef2aSThomas Huth     float_status fp_status;
1521fcf5ef2aSThomas Huth     floatx80 ft0;
1522fcf5ef2aSThomas Huth 
1523fcf5ef2aSThomas Huth     float_status mmx_status; /* for 3DNow! float ops */
1524fcf5ef2aSThomas Huth     float_status sse_status;
1525fcf5ef2aSThomas Huth     uint32_t mxcsr;
1526fcf5ef2aSThomas Huth     ZMMReg xmm_regs[CPU_NB_REGS == 8 ? 8 : 32];
1527fcf5ef2aSThomas Huth     ZMMReg xmm_t0;
1528fcf5ef2aSThomas Huth     MMXReg mmx_t0;
1529fcf5ef2aSThomas Huth 
1530c97d6d2cSSergio Andres Gomez Del Real     XMMReg ymmh_regs[CPU_NB_REGS];
1531c97d6d2cSSergio Andres Gomez Del Real 
1532fcf5ef2aSThomas Huth     uint64_t opmask_regs[NB_OPMASK_REGS];
1533c97d6d2cSSergio Andres Gomez Del Real     YMMReg zmmh_regs[CPU_NB_REGS];
1534c97d6d2cSSergio Andres Gomez Del Real     ZMMReg hi16_zmm_regs[CPU_NB_REGS];
1535e56dd3c7SJing Liu #ifdef TARGET_X86_64
1536e56dd3c7SJing Liu     uint8_t xtilecfg[64];
1537e56dd3c7SJing Liu     uint8_t xtiledata[8192];
1538e56dd3c7SJing Liu #endif
1539fcf5ef2aSThomas Huth 
1540fcf5ef2aSThomas Huth     /* sysenter registers */
1541fcf5ef2aSThomas Huth     uint32_t sysenter_cs;
1542fcf5ef2aSThomas Huth     target_ulong sysenter_esp;
1543fcf5ef2aSThomas Huth     target_ulong sysenter_eip;
1544fcf5ef2aSThomas Huth     uint64_t star;
1545fcf5ef2aSThomas Huth 
1546fcf5ef2aSThomas Huth     uint64_t vm_hsave;
1547fcf5ef2aSThomas Huth 
1548fcf5ef2aSThomas Huth #ifdef TARGET_X86_64
1549fcf5ef2aSThomas Huth     target_ulong lstar;
1550fcf5ef2aSThomas Huth     target_ulong cstar;
1551fcf5ef2aSThomas Huth     target_ulong fmask;
1552fcf5ef2aSThomas Huth     target_ulong kernelgsbase;
1553fcf5ef2aSThomas Huth #endif
1554fcf5ef2aSThomas Huth 
1555fcf5ef2aSThomas Huth     uint64_t tsc;
1556fcf5ef2aSThomas Huth     uint64_t tsc_adjust;
1557fcf5ef2aSThomas Huth     uint64_t tsc_deadline;
1558fcf5ef2aSThomas Huth     uint64_t tsc_aux;
1559fcf5ef2aSThomas Huth 
1560fcf5ef2aSThomas Huth     uint64_t xcr0;
1561fcf5ef2aSThomas Huth 
1562fcf5ef2aSThomas Huth     uint64_t mcg_status;
1563fcf5ef2aSThomas Huth     uint64_t msr_ia32_misc_enable;
1564fcf5ef2aSThomas Huth     uint64_t msr_ia32_feature_control;
1565db888065SSean Christopherson     uint64_t msr_ia32_sgxlepubkeyhash[4];
1566fcf5ef2aSThomas Huth 
1567fcf5ef2aSThomas Huth     uint64_t msr_fixed_ctr_ctrl;
1568fcf5ef2aSThomas Huth     uint64_t msr_global_ctrl;
1569fcf5ef2aSThomas Huth     uint64_t msr_global_status;
1570fcf5ef2aSThomas Huth     uint64_t msr_global_ovf_ctrl;
1571fcf5ef2aSThomas Huth     uint64_t msr_fixed_counters[MAX_FIXED_COUNTERS];
1572fcf5ef2aSThomas Huth     uint64_t msr_gp_counters[MAX_GP_COUNTERS];
1573fcf5ef2aSThomas Huth     uint64_t msr_gp_evtsel[MAX_GP_COUNTERS];
1574fcf5ef2aSThomas Huth 
1575fcf5ef2aSThomas Huth     uint64_t pat;
1576fcf5ef2aSThomas Huth     uint32_t smbase;
1577e13713dbSLiran Alon     uint64_t msr_smi_count;
1578fcf5ef2aSThomas Huth 
1579fcf5ef2aSThomas Huth     uint32_t pkru;
1580e7e7bdabSPaolo Bonzini     uint32_t pkrs;
15812a9758c5SPaolo Bonzini     uint32_t tsx_ctrl;
1582fcf5ef2aSThomas Huth 
1583a33a2cfeSPaolo Bonzini     uint64_t spec_ctrl;
1584cabf9862SMaxim Levitsky     uint64_t amd_tsc_scale_msr;
1585cfeea0c0SKonrad Rzeszutek Wilk     uint64_t virt_ssbd;
1586a33a2cfeSPaolo Bonzini 
1587fcf5ef2aSThomas Huth     /* End of state preserved by INIT (dummy marker).  */
1588fcf5ef2aSThomas Huth     struct {} end_init_save;
1589fcf5ef2aSThomas Huth 
1590fcf5ef2aSThomas Huth     uint64_t system_time_msr;
1591fcf5ef2aSThomas Huth     uint64_t wall_clock_msr;
1592fcf5ef2aSThomas Huth     uint64_t steal_time_msr;
1593fcf5ef2aSThomas Huth     uint64_t async_pf_en_msr;
1594db5daafaSVitaly Kuznetsov     uint64_t async_pf_int_msr;
1595fcf5ef2aSThomas Huth     uint64_t pv_eoi_en_msr;
1596d645e132SMarcelo Tosatti     uint64_t poll_control_msr;
1597fcf5ef2aSThomas Huth 
1598da1cc323SEvgeny Yakovlev     /* Partition-wide HV MSRs, will be updated only on the first vcpu */
1599fcf5ef2aSThomas Huth     uint64_t msr_hv_hypercall;
1600fcf5ef2aSThomas Huth     uint64_t msr_hv_guest_os_id;
1601fcf5ef2aSThomas Huth     uint64_t msr_hv_tsc;
1602da1cc323SEvgeny Yakovlev 
1603da1cc323SEvgeny Yakovlev     /* Per-VCPU HV MSRs */
1604da1cc323SEvgeny Yakovlev     uint64_t msr_hv_vapic;
16055e953812SRoman Kagan     uint64_t msr_hv_crash_params[HV_CRASH_PARAMS];
1606fcf5ef2aSThomas Huth     uint64_t msr_hv_runtime;
1607fcf5ef2aSThomas Huth     uint64_t msr_hv_synic_control;
1608fcf5ef2aSThomas Huth     uint64_t msr_hv_synic_evt_page;
1609fcf5ef2aSThomas Huth     uint64_t msr_hv_synic_msg_page;
16105e953812SRoman Kagan     uint64_t msr_hv_synic_sint[HV_SINT_COUNT];
16115e953812SRoman Kagan     uint64_t msr_hv_stimer_config[HV_STIMER_COUNT];
16125e953812SRoman Kagan     uint64_t msr_hv_stimer_count[HV_STIMER_COUNT];
1613ba6a4fd9SVitaly Kuznetsov     uint64_t msr_hv_reenlightenment_control;
1614ba6a4fd9SVitaly Kuznetsov     uint64_t msr_hv_tsc_emulation_control;
1615ba6a4fd9SVitaly Kuznetsov     uint64_t msr_hv_tsc_emulation_status;
1616fcf5ef2aSThomas Huth 
1617b77146e9SChao Peng     uint64_t msr_rtit_ctrl;
1618b77146e9SChao Peng     uint64_t msr_rtit_status;
1619b77146e9SChao Peng     uint64_t msr_rtit_output_base;
1620b77146e9SChao Peng     uint64_t msr_rtit_output_mask;
1621b77146e9SChao Peng     uint64_t msr_rtit_cr3_match;
1622b77146e9SChao Peng     uint64_t msr_rtit_addrs[MAX_RTIT_ADDRS];
1623b77146e9SChao Peng 
1624*cdec2b75SZeng Guang     /* Per-VCPU XFD MSRs */
1625*cdec2b75SZeng Guang     uint64_t msr_xfd;
1626*cdec2b75SZeng Guang     uint64_t msr_xfd_err;
1627*cdec2b75SZeng Guang 
1628fcf5ef2aSThomas Huth     /* exception/interrupt handling */
1629fcf5ef2aSThomas Huth     int error_code;
1630fcf5ef2aSThomas Huth     int exception_is_int;
1631fcf5ef2aSThomas Huth     target_ulong exception_next_eip;
1632fcf5ef2aSThomas Huth     target_ulong dr[8]; /* debug registers; note dr4 and dr5 are unused */
1633fcf5ef2aSThomas Huth     union {
1634fcf5ef2aSThomas Huth         struct CPUBreakpoint *cpu_breakpoint[4];
1635fcf5ef2aSThomas Huth         struct CPUWatchpoint *cpu_watchpoint[4];
1636fcf5ef2aSThomas Huth     }; /* break/watchpoints for dr[0..3] */
1637fcf5ef2aSThomas Huth     int old_exception;  /* exception in flight */
1638fcf5ef2aSThomas Huth 
1639fcf5ef2aSThomas Huth     uint64_t vm_vmcb;
1640fcf5ef2aSThomas Huth     uint64_t tsc_offset;
1641fcf5ef2aSThomas Huth     uint64_t intercept;
1642fcf5ef2aSThomas Huth     uint16_t intercept_cr_read;
1643fcf5ef2aSThomas Huth     uint16_t intercept_cr_write;
1644fcf5ef2aSThomas Huth     uint16_t intercept_dr_read;
1645fcf5ef2aSThomas Huth     uint16_t intercept_dr_write;
1646fcf5ef2aSThomas Huth     uint32_t intercept_exceptions;
1647fe441054SJan Kiszka     uint64_t nested_cr3;
1648fe441054SJan Kiszka     uint32_t nested_pg_mode;
1649fcf5ef2aSThomas Huth     uint8_t v_tpr;
1650e3126a5cSLara Lazier     uint32_t int_ctl;
1651fcf5ef2aSThomas Huth 
1652fcf5ef2aSThomas Huth     /* KVM states, automatically cleared on reset */
1653fcf5ef2aSThomas Huth     uint8_t nmi_injected;
1654fcf5ef2aSThomas Huth     uint8_t nmi_pending;
1655fcf5ef2aSThomas Huth 
1656fe441054SJan Kiszka     uintptr_t retaddr;
1657fe441054SJan Kiszka 
16581f5c00cfSAlex Bennée     /* Fields up to this point are cleared by a CPU reset */
16591f5c00cfSAlex Bennée     struct {} end_reset_fields;
16601f5c00cfSAlex Bennée 
1661e8b5fae5SRichard Henderson     /* Fields after this point are preserved across CPU reset. */
1662fcf5ef2aSThomas Huth 
1663fcf5ef2aSThomas Huth     /* processor features (e.g. for CPUID insn) */
166480db491dSJing Liu     /* Minimum cpuid leaf 7 value */
166580db491dSJing Liu     uint32_t cpuid_level_func7;
166680db491dSJing Liu     /* Actual cpuid leaf 7 value */
166780db491dSJing Liu     uint32_t cpuid_min_level_func7;
1668fcf5ef2aSThomas Huth     /* Minimum level/xlevel/xlevel2, based on CPU model + features */
1669fcf5ef2aSThomas Huth     uint32_t cpuid_min_level, cpuid_min_xlevel, cpuid_min_xlevel2;
1670fcf5ef2aSThomas Huth     /* Maximum level/xlevel/xlevel2 value for auto-assignment: */
1671fcf5ef2aSThomas Huth     uint32_t cpuid_max_level, cpuid_max_xlevel, cpuid_max_xlevel2;
1672fcf5ef2aSThomas Huth     /* Actual level/xlevel/xlevel2 value: */
1673fcf5ef2aSThomas Huth     uint32_t cpuid_level, cpuid_xlevel, cpuid_xlevel2;
1674fcf5ef2aSThomas Huth     uint32_t cpuid_vendor1;
1675fcf5ef2aSThomas Huth     uint32_t cpuid_vendor2;
1676fcf5ef2aSThomas Huth     uint32_t cpuid_vendor3;
1677fcf5ef2aSThomas Huth     uint32_t cpuid_version;
1678fcf5ef2aSThomas Huth     FeatureWordArray features;
1679d4a606b3SEduardo Habkost     /* Features that were explicitly enabled/disabled */
1680d4a606b3SEduardo Habkost     FeatureWordArray user_features;
1681fcf5ef2aSThomas Huth     uint32_t cpuid_model[12];
1682a9f27ea9SEduardo Habkost     /* Cache information for CPUID.  When legacy-cache=on, the cache data
1683a9f27ea9SEduardo Habkost      * on each CPUID leaf will be different, because we keep compatibility
1684a9f27ea9SEduardo Habkost      * with old QEMU versions.
1685a9f27ea9SEduardo Habkost      */
1686a9f27ea9SEduardo Habkost     CPUCaches cache_info_cpuid2, cache_info_cpuid4, cache_info_amd;
1687fcf5ef2aSThomas Huth 
1688fcf5ef2aSThomas Huth     /* MTRRs */
1689fcf5ef2aSThomas Huth     uint64_t mtrr_fixed[11];
1690fcf5ef2aSThomas Huth     uint64_t mtrr_deftype;
1691fcf5ef2aSThomas Huth     MTRRVar mtrr_var[MSR_MTRRcap_VCNT];
1692fcf5ef2aSThomas Huth 
1693fcf5ef2aSThomas Huth     /* For KVM */
1694fcf5ef2aSThomas Huth     uint32_t mp_state;
1695fd13f23bSLiran Alon     int32_t exception_nr;
1696fcf5ef2aSThomas Huth     int32_t interrupt_injected;
1697fcf5ef2aSThomas Huth     uint8_t soft_interrupt;
1698fd13f23bSLiran Alon     uint8_t exception_pending;
1699fd13f23bSLiran Alon     uint8_t exception_injected;
1700fcf5ef2aSThomas Huth     uint8_t has_error_code;
1701fd13f23bSLiran Alon     uint8_t exception_has_payload;
1702fd13f23bSLiran Alon     uint64_t exception_payload;
1703c97d6d2cSSergio Andres Gomez Del Real     uint32_t ins_len;
1704fcf5ef2aSThomas Huth     uint32_t sipi_vector;
1705fcf5ef2aSThomas Huth     bool tsc_valid;
1706fcf5ef2aSThomas Huth     int64_t tsc_khz;
1707fcf5ef2aSThomas Huth     int64_t user_tsc_khz; /* for sanity check only */
170873b994f6SLiran Alon     uint64_t apic_bus_freq;
17095b8063c4SLiran Alon #if defined(CONFIG_KVM) || defined(CONFIG_HVF)
17105b8063c4SLiran Alon     void *xsave_buf;
1711c0198c5fSDavid Edmondson     uint32_t xsave_buf_len;
17125b8063c4SLiran Alon #endif
1713ebbfef2fSLiran Alon #if defined(CONFIG_KVM)
1714ebbfef2fSLiran Alon     struct kvm_nested_state *nested_state;
1715ebbfef2fSLiran Alon #endif
1716c97d6d2cSSergio Andres Gomez Del Real #if defined(CONFIG_HVF)
1717577f02b8SRoman Bolshakov     HVFX86LazyFlags hvf_lflags;
1718fe76b09cSRoman Bolshakov     void *hvf_mmio_buf;
1719c97d6d2cSSergio Andres Gomez Del Real #endif
1720fcf5ef2aSThomas Huth 
1721fcf5ef2aSThomas Huth     uint64_t mcg_cap;
1722fcf5ef2aSThomas Huth     uint64_t mcg_ctl;
1723fcf5ef2aSThomas Huth     uint64_t mcg_ext_ctl;
1724fcf5ef2aSThomas Huth     uint64_t mce_banks[MCE_BANKS_DEF*4];
1725fcf5ef2aSThomas Huth     uint64_t xstate_bv;
1726fcf5ef2aSThomas Huth 
1727fcf5ef2aSThomas Huth     /* vmstate */
1728fcf5ef2aSThomas Huth     uint16_t fpus_vmstate;
1729fcf5ef2aSThomas Huth     uint16_t fptag_vmstate;
1730fcf5ef2aSThomas Huth     uint16_t fpregs_format_vmstate;
1731fcf5ef2aSThomas Huth 
1732fcf5ef2aSThomas Huth     uint64_t xss;
173365087997STao Xu     uint32_t umwait;
1734fcf5ef2aSThomas Huth 
1735fcf5ef2aSThomas Huth     TPRAccess tpr_access_type;
1736c26ae610SLike Xu 
1737c26ae610SLike Xu     unsigned nr_dies;
1738fcf5ef2aSThomas Huth } CPUX86State;
1739fcf5ef2aSThomas Huth 
1740fcf5ef2aSThomas Huth struct kvm_msrs;
1741fcf5ef2aSThomas Huth 
1742fcf5ef2aSThomas Huth /**
1743fcf5ef2aSThomas Huth  * X86CPU:
1744fcf5ef2aSThomas Huth  * @env: #CPUX86State
1745fcf5ef2aSThomas Huth  * @migratable: If set, only migratable flags will be accepted when "enforce"
1746fcf5ef2aSThomas Huth  * mode is used, and only migratable flags will be included in the "host"
1747fcf5ef2aSThomas Huth  * CPU model.
1748fcf5ef2aSThomas Huth  *
1749fcf5ef2aSThomas Huth  * An x86 CPU.
1750fcf5ef2aSThomas Huth  */
1751b36e239eSPhilippe Mathieu-Daudé struct ArchCPU {
1752fcf5ef2aSThomas Huth     /*< private >*/
1753fcf5ef2aSThomas Huth     CPUState parent_obj;
1754fcf5ef2aSThomas Huth     /*< public >*/
1755fcf5ef2aSThomas Huth 
17565b146dc7SRichard Henderson     CPUNegativeOffsetState neg;
1757fcf5ef2aSThomas Huth     CPUX86State env;
17582a693142SPan Nengyuan     VMChangeStateEntry *vmsentry;
1759fcf5ef2aSThomas Huth 
17604e45aff3SPaolo Bonzini     uint64_t ucode_rev;
17614e45aff3SPaolo Bonzini 
17624f2beda4SEduardo Habkost     uint32_t hyperv_spinlock_attempts;
176308856771SVitaly Kuznetsov     char *hyperv_vendor;
17649b4cf107SRoman Kagan     bool hyperv_synic_kvm_only;
17652d384d7cSVitaly Kuznetsov     uint64_t hyperv_features;
1766e48ddcc6SVitaly Kuznetsov     bool hyperv_passthrough;
176730d6ff66SVitaly Kuznetsov     OnOffAuto hyperv_no_nonarch_cs;
176808856771SVitaly Kuznetsov     uint32_t hyperv_vendor_id[3];
1769735db465SVitaly Kuznetsov     uint32_t hyperv_interface_id[4];
177023eb5d03SVitaly Kuznetsov     uint32_t hyperv_limits[3];
1771c830015eSVitaly Kuznetsov     uint32_t hyperv_nested[4];
177270367f09SVitaly Kuznetsov     bool hyperv_enforce_cpuid;
1773af7228b8SVitaly Kuznetsov     uint32_t hyperv_ver_id_build;
1774af7228b8SVitaly Kuznetsov     uint16_t hyperv_ver_id_major;
1775af7228b8SVitaly Kuznetsov     uint16_t hyperv_ver_id_minor;
1776af7228b8SVitaly Kuznetsov     uint32_t hyperv_ver_id_sp;
1777af7228b8SVitaly Kuznetsov     uint8_t hyperv_ver_id_sb;
1778af7228b8SVitaly Kuznetsov     uint32_t hyperv_ver_id_sn;
17792d384d7cSVitaly Kuznetsov 
1780fcf5ef2aSThomas Huth     bool check_cpuid;
1781fcf5ef2aSThomas Huth     bool enforce_cpuid;
1782dac1deaeSEduardo Habkost     /*
1783dac1deaeSEduardo Habkost      * Force features to be enabled even if the host doesn't support them.
1784dac1deaeSEduardo Habkost      * This is dangerous and should be done only for testing CPUID
1785dac1deaeSEduardo Habkost      * compatibility.
1786dac1deaeSEduardo Habkost      */
1787dac1deaeSEduardo Habkost     bool force_features;
1788fcf5ef2aSThomas Huth     bool expose_kvm;
17891ce36bfeSDaniel P. Berrange     bool expose_tcg;
1790fcf5ef2aSThomas Huth     bool migratable;
1791990e0be2SPaolo Bonzini     bool migrate_smi_count;
179244bd8e53SEduardo Habkost     bool max_features; /* Enable all supported features automatically */
1793fcf5ef2aSThomas Huth     uint32_t apic_id;
1794fcf5ef2aSThomas Huth 
17959954a158SPhil Dennis-Jordan     /* Enables publishing of TSC increment and Local APIC bus frequencies to
17969954a158SPhil Dennis-Jordan      * the guest OS in CPUID page 0x40000010, the same way that VMWare does. */
17979954a158SPhil Dennis-Jordan     bool vmware_cpuid_freq;
17989954a158SPhil Dennis-Jordan 
1799fcf5ef2aSThomas Huth     /* if true the CPUID code directly forward host cache leaves to the guest */
1800fcf5ef2aSThomas Huth     bool cache_info_passthrough;
1801fcf5ef2aSThomas Huth 
18022266d443SMichael S. Tsirkin     /* if true the CPUID code directly forwards
18032266d443SMichael S. Tsirkin      * host monitor/mwait leaves to the guest */
18042266d443SMichael S. Tsirkin     struct {
18052266d443SMichael S. Tsirkin         uint32_t eax;
18062266d443SMichael S. Tsirkin         uint32_t ebx;
18072266d443SMichael S. Tsirkin         uint32_t ecx;
18082266d443SMichael S. Tsirkin         uint32_t edx;
18092266d443SMichael S. Tsirkin     } mwait;
18102266d443SMichael S. Tsirkin 
1811fcf5ef2aSThomas Huth     /* Features that were filtered out because of missing host capabilities */
1812f69ecddbSWei Yang     FeatureWordArray filtered_features;
1813fcf5ef2aSThomas Huth 
1814fcf5ef2aSThomas Huth     /* Enable PMU CPUID bits. This can't be enabled by default yet because
1815fcf5ef2aSThomas Huth      * it doesn't have ABI stability guarantees, as it passes all PMU CPUID
1816fcf5ef2aSThomas Huth      * bits returned by GET_SUPPORTED_CPUID (that depend on host CPU and kernel
1817fcf5ef2aSThomas Huth      * capabilities) directly to the guest.
1818fcf5ef2aSThomas Huth      */
1819fcf5ef2aSThomas Huth     bool enable_pmu;
1820fcf5ef2aSThomas Huth 
1821fcf5ef2aSThomas Huth     /* LMCE support can be enabled/disabled via cpu option 'lmce=on/off'. It is
1822fcf5ef2aSThomas Huth      * disabled by default to avoid breaking migration between QEMU with
1823fcf5ef2aSThomas Huth      * different LMCE configurations.
1824fcf5ef2aSThomas Huth      */
1825fcf5ef2aSThomas Huth     bool enable_lmce;
1826fcf5ef2aSThomas Huth 
1827fcf5ef2aSThomas Huth     /* Compatibility bits for old machine types.
1828fcf5ef2aSThomas Huth      * If true present virtual l3 cache for VM, the vcpus in the same virtual
1829fcf5ef2aSThomas Huth      * socket share an virtual l3 cache.
1830fcf5ef2aSThomas Huth      */
1831fcf5ef2aSThomas Huth     bool enable_l3_cache;
1832fcf5ef2aSThomas Huth 
1833ab8f992eSBabu Moger     /* Compatibility bits for old machine types.
1834ab8f992eSBabu Moger      * If true present the old cache topology information
1835ab8f992eSBabu Moger      */
1836ab8f992eSBabu Moger     bool legacy_cache;
1837ab8f992eSBabu Moger 
1838fcf5ef2aSThomas Huth     /* Compatibility bits for old machine types: */
1839fcf5ef2aSThomas Huth     bool enable_cpuid_0xb;
1840fcf5ef2aSThomas Huth 
1841fcf5ef2aSThomas Huth     /* Enable auto level-increase for all CPUID leaves */
1842fcf5ef2aSThomas Huth     bool full_cpuid_auto_level;
1843fcf5ef2aSThomas Huth 
1844a7a0da84SMichael Roth     /* Only advertise CPUID leaves defined by the vendor */
1845a7a0da84SMichael Roth     bool vendor_cpuid_only;
1846a7a0da84SMichael Roth 
1847f24c3a79SLuwei Kang     /* Enable auto level-increase for Intel Processor Trace leave */
1848f24c3a79SLuwei Kang     bool intel_pt_auto_level;
1849f24c3a79SLuwei Kang 
1850fcf5ef2aSThomas Huth     /* if true fill the top bits of the MTRR_PHYSMASKn variable range */
1851fcf5ef2aSThomas Huth     bool fill_mtrr_mask;
1852fcf5ef2aSThomas Huth 
1853fcf5ef2aSThomas Huth     /* if true override the phys_bits value with a value read from the host */
1854fcf5ef2aSThomas Huth     bool host_phys_bits;
1855fcf5ef2aSThomas Huth 
1856258fe08bSEduardo Habkost     /* if set, limit maximum value for phys_bits when host_phys_bits is true */
1857258fe08bSEduardo Habkost     uint8_t host_phys_bits_limit;
1858258fe08bSEduardo Habkost 
1859fc3a1fd7SDr. David Alan Gilbert     /* Stop SMI delivery for migration compatibility with old machines */
1860fc3a1fd7SDr. David Alan Gilbert     bool kvm_no_smi_migration;
1861fc3a1fd7SDr. David Alan Gilbert 
1862988f7b8bSVitaly Kuznetsov     /* Forcefully disable KVM PV features not exposed in guest CPUIDs */
1863988f7b8bSVitaly Kuznetsov     bool kvm_pv_enforce_cpuid;
1864988f7b8bSVitaly Kuznetsov 
1865fcf5ef2aSThomas Huth     /* Number of physical address bits supported */
1866fcf5ef2aSThomas Huth     uint32_t phys_bits;
1867fcf5ef2aSThomas Huth 
1868fcf5ef2aSThomas Huth     /* in order to simplify APIC support, we leave this pointer to the
1869fcf5ef2aSThomas Huth        user */
1870fcf5ef2aSThomas Huth     struct DeviceState *apic_state;
1871fcf5ef2aSThomas Huth     struct MemoryRegion *cpu_as_root, *cpu_as_mem, *smram;
1872fcf5ef2aSThomas Huth     Notifier machine_done;
1873fcf5ef2aSThomas Huth 
1874fcf5ef2aSThomas Huth     struct kvm_msrs *kvm_msr_buf;
1875fcf5ef2aSThomas Huth 
187615f8b142SIgor Mammedov     int32_t node_id; /* NUMA node this CPU belongs to */
1877fcf5ef2aSThomas Huth     int32_t socket_id;
1878176d2cdaSLike Xu     int32_t die_id;
1879fcf5ef2aSThomas Huth     int32_t core_id;
1880fcf5ef2aSThomas Huth     int32_t thread_id;
18816c69dfb6SGonglei 
18826c69dfb6SGonglei     int32_t hv_max_vps;
1883fcf5ef2aSThomas Huth };
1884fcf5ef2aSThomas Huth 
1885fcf5ef2aSThomas Huth 
1886fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
1887ac701a4fSKeqian Zhu extern const VMStateDescription vmstate_x86_cpu;
1888fcf5ef2aSThomas Huth #endif
1889fcf5ef2aSThomas Huth 
189092d5f1a4SPaolo Bonzini int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request);
1891fcf5ef2aSThomas Huth 
1892fcf5ef2aSThomas Huth int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
1893fcf5ef2aSThomas Huth                              int cpuid, void *opaque);
1894fcf5ef2aSThomas Huth int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
1895fcf5ef2aSThomas Huth                              int cpuid, void *opaque);
1896fcf5ef2aSThomas Huth int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
1897fcf5ef2aSThomas Huth                                  void *opaque);
1898fcf5ef2aSThomas Huth int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
1899fcf5ef2aSThomas Huth                                  void *opaque);
1900fcf5ef2aSThomas Huth 
1901fcf5ef2aSThomas Huth void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
1902fcf5ef2aSThomas Huth                                 Error **errp);
1903fcf5ef2aSThomas Huth 
190490c84c56SMarkus Armbruster void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags);
1905fcf5ef2aSThomas Huth 
190656f99750SDmitry Poletaev hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
190756f99750SDmitry Poletaev                                          MemTxAttrs *attrs);
1908fcf5ef2aSThomas Huth 
1909a010bdbeSAlex Bennée int x86_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
1910fcf5ef2aSThomas Huth int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
1911fcf5ef2aSThomas Huth 
19120442428aSMarkus Armbruster void x86_cpu_list(void);
1913fcf5ef2aSThomas Huth int cpu_x86_support_mca_broadcast(CPUX86State *env);
1914fcf5ef2aSThomas Huth 
191576d0042bSPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
1916fcf5ef2aSThomas Huth int cpu_get_pic_interrupt(CPUX86State *s);
19177ce08865SPhilippe Mathieu-Daudé 
1918fcf5ef2aSThomas Huth /* MSDOS compatibility mode FPU exception support */
19196f529b75SPaolo Bonzini void x86_register_ferr_irq(qemu_irq irq);
192083a3d9c7SClaudio Fontana void fpu_check_raise_ferr_irq(CPUX86State *s);
1921bf13bfabSPaolo Bonzini void cpu_set_ignne(void);
192283a3d9c7SClaudio Fontana void cpu_clear_ignne(void);
19237ce08865SPhilippe Mathieu-Daudé #endif
192483a3d9c7SClaudio Fontana 
19255e76d84eSPaolo Bonzini /* mpx_helper.c */
19265e76d84eSPaolo Bonzini void cpu_sync_bndcs_hflags(CPUX86State *env);
1927fcf5ef2aSThomas Huth 
1928fcf5ef2aSThomas Huth /* this function must always be used to load data in the segment
1929fcf5ef2aSThomas Huth    cache: it synchronizes the hflags with the segment cache values */
1930fcf5ef2aSThomas Huth static inline void cpu_x86_load_seg_cache(CPUX86State *env,
1931c117e5b1SPhilippe Mathieu-Daudé                                           X86Seg seg_reg, unsigned int selector,
1932fcf5ef2aSThomas Huth                                           target_ulong base,
1933fcf5ef2aSThomas Huth                                           unsigned int limit,
1934fcf5ef2aSThomas Huth                                           unsigned int flags)
1935fcf5ef2aSThomas Huth {
1936fcf5ef2aSThomas Huth     SegmentCache *sc;
1937fcf5ef2aSThomas Huth     unsigned int new_hflags;
1938fcf5ef2aSThomas Huth 
1939fcf5ef2aSThomas Huth     sc = &env->segs[seg_reg];
1940fcf5ef2aSThomas Huth     sc->selector = selector;
1941fcf5ef2aSThomas Huth     sc->base = base;
1942fcf5ef2aSThomas Huth     sc->limit = limit;
1943fcf5ef2aSThomas Huth     sc->flags = flags;
1944fcf5ef2aSThomas Huth 
1945fcf5ef2aSThomas Huth     /* update the hidden flags */
1946fcf5ef2aSThomas Huth     {
1947fcf5ef2aSThomas Huth         if (seg_reg == R_CS) {
1948fcf5ef2aSThomas Huth #ifdef TARGET_X86_64
1949fcf5ef2aSThomas Huth             if ((env->hflags & HF_LMA_MASK) && (flags & DESC_L_MASK)) {
1950fcf5ef2aSThomas Huth                 /* long mode */
1951fcf5ef2aSThomas Huth                 env->hflags |= HF_CS32_MASK | HF_SS32_MASK | HF_CS64_MASK;
1952fcf5ef2aSThomas Huth                 env->hflags &= ~(HF_ADDSEG_MASK);
1953fcf5ef2aSThomas Huth             } else
1954fcf5ef2aSThomas Huth #endif
1955fcf5ef2aSThomas Huth             {
1956fcf5ef2aSThomas Huth                 /* legacy / compatibility case */
1957fcf5ef2aSThomas Huth                 new_hflags = (env->segs[R_CS].flags & DESC_B_MASK)
1958fcf5ef2aSThomas Huth                     >> (DESC_B_SHIFT - HF_CS32_SHIFT);
1959fcf5ef2aSThomas Huth                 env->hflags = (env->hflags & ~(HF_CS32_MASK | HF_CS64_MASK)) |
1960fcf5ef2aSThomas Huth                     new_hflags;
1961fcf5ef2aSThomas Huth             }
1962fcf5ef2aSThomas Huth         }
1963fcf5ef2aSThomas Huth         if (seg_reg == R_SS) {
1964fcf5ef2aSThomas Huth             int cpl = (flags >> DESC_DPL_SHIFT) & 3;
1965fcf5ef2aSThomas Huth #if HF_CPL_MASK != 3
1966fcf5ef2aSThomas Huth #error HF_CPL_MASK is hardcoded
1967fcf5ef2aSThomas Huth #endif
1968fcf5ef2aSThomas Huth             env->hflags = (env->hflags & ~HF_CPL_MASK) | cpl;
19695e76d84eSPaolo Bonzini             /* Possibly switch between BNDCFGS and BNDCFGU */
19705e76d84eSPaolo Bonzini             cpu_sync_bndcs_hflags(env);
1971fcf5ef2aSThomas Huth         }
1972fcf5ef2aSThomas Huth         new_hflags = (env->segs[R_SS].flags & DESC_B_MASK)
1973fcf5ef2aSThomas Huth             >> (DESC_B_SHIFT - HF_SS32_SHIFT);
1974fcf5ef2aSThomas Huth         if (env->hflags & HF_CS64_MASK) {
1975fcf5ef2aSThomas Huth             /* zero base assumed for DS, ES and SS in long mode */
1976fcf5ef2aSThomas Huth         } else if (!(env->cr[0] & CR0_PE_MASK) ||
1977fcf5ef2aSThomas Huth                    (env->eflags & VM_MASK) ||
1978fcf5ef2aSThomas Huth                    !(env->hflags & HF_CS32_MASK)) {
1979fcf5ef2aSThomas Huth             /* XXX: try to avoid this test. The problem comes from the
1980fcf5ef2aSThomas Huth                fact that is real mode or vm86 mode we only modify the
1981fcf5ef2aSThomas Huth                'base' and 'selector' fields of the segment cache to go
1982fcf5ef2aSThomas Huth                faster. A solution may be to force addseg to one in
1983fcf5ef2aSThomas Huth                translate-i386.c. */
1984fcf5ef2aSThomas Huth             new_hflags |= HF_ADDSEG_MASK;
1985fcf5ef2aSThomas Huth         } else {
1986fcf5ef2aSThomas Huth             new_hflags |= ((env->segs[R_DS].base |
1987fcf5ef2aSThomas Huth                             env->segs[R_ES].base |
1988fcf5ef2aSThomas Huth                             env->segs[R_SS].base) != 0) <<
1989fcf5ef2aSThomas Huth                 HF_ADDSEG_SHIFT;
1990fcf5ef2aSThomas Huth         }
1991fcf5ef2aSThomas Huth         env->hflags = (env->hflags &
1992fcf5ef2aSThomas Huth                        ~(HF_SS32_MASK | HF_ADDSEG_MASK)) | new_hflags;
1993fcf5ef2aSThomas Huth     }
1994fcf5ef2aSThomas Huth }
1995fcf5ef2aSThomas Huth 
1996fcf5ef2aSThomas Huth static inline void cpu_x86_load_seg_cache_sipi(X86CPU *cpu,
1997fcf5ef2aSThomas Huth                                                uint8_t sipi_vector)
1998fcf5ef2aSThomas Huth {
1999fcf5ef2aSThomas Huth     CPUState *cs = CPU(cpu);
2000fcf5ef2aSThomas Huth     CPUX86State *env = &cpu->env;
2001fcf5ef2aSThomas Huth 
2002fcf5ef2aSThomas Huth     env->eip = 0;
2003fcf5ef2aSThomas Huth     cpu_x86_load_seg_cache(env, R_CS, sipi_vector << 8,
2004fcf5ef2aSThomas Huth                            sipi_vector << 12,
2005fcf5ef2aSThomas Huth                            env->segs[R_CS].limit,
2006fcf5ef2aSThomas Huth                            env->segs[R_CS].flags);
2007fcf5ef2aSThomas Huth     cs->halted = 0;
2008fcf5ef2aSThomas Huth }
2009fcf5ef2aSThomas Huth 
2010fcf5ef2aSThomas Huth int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
2011fcf5ef2aSThomas Huth                             target_ulong *base, unsigned int *limit,
2012fcf5ef2aSThomas Huth                             unsigned int *flags);
2013fcf5ef2aSThomas Huth 
2014fcf5ef2aSThomas Huth /* op_helper.c */
2015fcf5ef2aSThomas Huth /* used for debug or cpu save/restore */
2016fcf5ef2aSThomas Huth 
2017fcf5ef2aSThomas Huth /* cpu-exec.c */
2018fcf5ef2aSThomas Huth /* the following helpers are only usable in user mode simulation as
2019fcf5ef2aSThomas Huth    they can trigger unexpected exceptions */
2020c117e5b1SPhilippe Mathieu-Daudé void cpu_x86_load_seg(CPUX86State *s, X86Seg seg_reg, int selector);
2021fcf5ef2aSThomas Huth void cpu_x86_fsave(CPUX86State *s, target_ulong ptr, int data32);
2022fcf5ef2aSThomas Huth void cpu_x86_frstor(CPUX86State *s, target_ulong ptr, int data32);
20231c1df019SPranith Kumar void cpu_x86_fxsave(CPUX86State *s, target_ulong ptr);
20241c1df019SPranith Kumar void cpu_x86_fxrstor(CPUX86State *s, target_ulong ptr);
2025fcf5ef2aSThomas Huth 
2026fcf5ef2aSThomas Huth /* cpu.c */
2027f5cc5a5cSClaudio Fontana void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
2028f5cc5a5cSClaudio Fontana                               uint32_t vendor2, uint32_t vendor3);
2029f5cc5a5cSClaudio Fontana typedef struct PropValue {
2030f5cc5a5cSClaudio Fontana     const char *prop, *value;
2031f5cc5a5cSClaudio Fontana } PropValue;
2032f5cc5a5cSClaudio Fontana void x86_cpu_apply_props(X86CPU *cpu, PropValue *props);
2033f5cc5a5cSClaudio Fontana 
203497afb47eSLara Lazier uint32_t cpu_x86_virtual_addr_width(CPUX86State *env);
203597afb47eSLara Lazier 
2036f5cc5a5cSClaudio Fontana /* cpu.c other functions (cpuid) */
2037fcf5ef2aSThomas Huth void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
2038fcf5ef2aSThomas Huth                    uint32_t *eax, uint32_t *ebx,
2039fcf5ef2aSThomas Huth                    uint32_t *ecx, uint32_t *edx);
2040fcf5ef2aSThomas Huth void cpu_clear_apic_feature(CPUX86State *env);
2041fcf5ef2aSThomas Huth void host_cpuid(uint32_t function, uint32_t count,
2042fcf5ef2aSThomas Huth                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
2043fcf5ef2aSThomas Huth 
2044fcf5ef2aSThomas Huth /* helper.c */
2045fcf5ef2aSThomas Huth void x86_cpu_set_a20(X86CPU *cpu, int a20_state);
2046fcf5ef2aSThomas Huth 
2047fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
2048f8c45c65SPaolo Bonzini static inline int x86_asidx_from_attrs(CPUState *cs, MemTxAttrs attrs)
2049f8c45c65SPaolo Bonzini {
2050f8c45c65SPaolo Bonzini     return !!attrs.secure;
2051f8c45c65SPaolo Bonzini }
2052f8c45c65SPaolo Bonzini 
2053f8c45c65SPaolo Bonzini static inline AddressSpace *cpu_addressspace(CPUState *cs, MemTxAttrs attrs)
2054f8c45c65SPaolo Bonzini {
2055f8c45c65SPaolo Bonzini     return cpu_get_address_space(cs, cpu_asidx_from_attrs(cs, attrs));
2056f8c45c65SPaolo Bonzini }
2057f8c45c65SPaolo Bonzini 
205863087289SClaudio Fontana /*
205963087289SClaudio Fontana  * load efer and update the corresponding hflags. XXX: do consistency
206063087289SClaudio Fontana  * checks with cpuid bits?
206163087289SClaudio Fontana  */
206263087289SClaudio Fontana void cpu_load_efer(CPUX86State *env, uint64_t val);
2063fcf5ef2aSThomas Huth uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr);
2064fcf5ef2aSThomas Huth uint32_t x86_lduw_phys(CPUState *cs, hwaddr addr);
2065fcf5ef2aSThomas Huth uint32_t x86_ldl_phys(CPUState *cs, hwaddr addr);
2066fcf5ef2aSThomas Huth uint64_t x86_ldq_phys(CPUState *cs, hwaddr addr);
2067fcf5ef2aSThomas Huth void x86_stb_phys(CPUState *cs, hwaddr addr, uint8_t val);
2068fcf5ef2aSThomas Huth void x86_stl_phys_notdirty(CPUState *cs, hwaddr addr, uint32_t val);
2069fcf5ef2aSThomas Huth void x86_stw_phys(CPUState *cs, hwaddr addr, uint32_t val);
2070fcf5ef2aSThomas Huth void x86_stl_phys(CPUState *cs, hwaddr addr, uint32_t val);
2071fcf5ef2aSThomas Huth void x86_stq_phys(CPUState *cs, hwaddr addr, uint64_t val);
2072fcf5ef2aSThomas Huth #endif
2073fcf5ef2aSThomas Huth 
2074fcf5ef2aSThomas Huth /* will be suppressed */
2075fcf5ef2aSThomas Huth void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0);
2076fcf5ef2aSThomas Huth void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);
2077fcf5ef2aSThomas Huth void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4);
2078fcf5ef2aSThomas Huth void cpu_x86_update_dr7(CPUX86State *env, uint32_t new_dr7);
2079fcf5ef2aSThomas Huth 
2080fcf5ef2aSThomas Huth /* hw/pc.c */
2081fcf5ef2aSThomas Huth uint64_t cpu_get_tsc(CPUX86State *env);
2082fcf5ef2aSThomas Huth 
2083311ca98dSIgor Mammedov #define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
2084311ca98dSIgor Mammedov #define X86_CPU_TYPE_NAME(name) (name X86_CPU_TYPE_SUFFIX)
20850dacec87SIgor Mammedov #define CPU_RESOLVING_TYPE TYPE_X86_CPU
2086311ca98dSIgor Mammedov 
2087311ca98dSIgor Mammedov #ifdef TARGET_X86_64
2088311ca98dSIgor Mammedov #define TARGET_DEFAULT_CPU_TYPE X86_CPU_TYPE_NAME("qemu64")
2089311ca98dSIgor Mammedov #else
2090311ca98dSIgor Mammedov #define TARGET_DEFAULT_CPU_TYPE X86_CPU_TYPE_NAME("qemu32")
2091311ca98dSIgor Mammedov #endif
2092311ca98dSIgor Mammedov 
2093fcf5ef2aSThomas Huth #define cpu_list x86_cpu_list
2094fcf5ef2aSThomas Huth 
2095fcf5ef2aSThomas Huth /* MMU modes definitions */
2096fcf5ef2aSThomas Huth #define MMU_KSMAP_IDX   0
2097fcf5ef2aSThomas Huth #define MMU_USER_IDX    1
2098fcf5ef2aSThomas Huth #define MMU_KNOSMAP_IDX 2
2099fcf5ef2aSThomas Huth static inline int cpu_mmu_index(CPUX86State *env, bool ifetch)
2100fcf5ef2aSThomas Huth {
2101fcf5ef2aSThomas Huth     return (env->hflags & HF_CPL_MASK) == 3 ? MMU_USER_IDX :
2102fcf5ef2aSThomas Huth         (!(env->hflags & HF_SMAP_MASK) || (env->eflags & AC_MASK))
2103fcf5ef2aSThomas Huth         ? MMU_KNOSMAP_IDX : MMU_KSMAP_IDX;
2104fcf5ef2aSThomas Huth }
2105fcf5ef2aSThomas Huth 
2106fcf5ef2aSThomas Huth static inline int cpu_mmu_index_kernel(CPUX86State *env)
2107fcf5ef2aSThomas Huth {
2108fcf5ef2aSThomas Huth     return !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP_IDX :
2109fcf5ef2aSThomas Huth         ((env->hflags & HF_CPL_MASK) < 3 && (env->eflags & AC_MASK))
2110fcf5ef2aSThomas Huth         ? MMU_KNOSMAP_IDX : MMU_KSMAP_IDX;
2111fcf5ef2aSThomas Huth }
2112fcf5ef2aSThomas Huth 
2113fcf5ef2aSThomas Huth #define CC_DST  (env->cc_dst)
2114fcf5ef2aSThomas Huth #define CC_SRC  (env->cc_src)
2115fcf5ef2aSThomas Huth #define CC_SRC2 (env->cc_src2)
2116fcf5ef2aSThomas Huth #define CC_OP   (env->cc_op)
2117fcf5ef2aSThomas Huth 
2118fcf5ef2aSThomas Huth #include "exec/cpu-all.h"
2119fcf5ef2aSThomas Huth #include "svm.h"
2120fcf5ef2aSThomas Huth 
2121fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
2122fcf5ef2aSThomas Huth #include "hw/i386/apic.h"
2123fcf5ef2aSThomas Huth #endif
2124fcf5ef2aSThomas Huth 
2125fcf5ef2aSThomas Huth static inline void cpu_get_tb_cpu_state(CPUX86State *env, target_ulong *pc,
2126fcf5ef2aSThomas Huth                                         target_ulong *cs_base, uint32_t *flags)
2127fcf5ef2aSThomas Huth {
2128fcf5ef2aSThomas Huth     *cs_base = env->segs[R_CS].base;
2129fcf5ef2aSThomas Huth     *pc = *cs_base + env->eip;
2130fcf5ef2aSThomas Huth     *flags = env->hflags |
2131fcf5ef2aSThomas Huth         (env->eflags & (IOPL_MASK | TF_MASK | RF_MASK | VM_MASK | AC_MASK));
2132fcf5ef2aSThomas Huth }
2133fcf5ef2aSThomas Huth 
2134fcf5ef2aSThomas Huth void do_cpu_init(X86CPU *cpu);
2135fcf5ef2aSThomas Huth void do_cpu_sipi(X86CPU *cpu);
2136fcf5ef2aSThomas Huth 
2137fcf5ef2aSThomas Huth #define MCE_INJECT_BROADCAST    1
2138fcf5ef2aSThomas Huth #define MCE_INJECT_UNCOND_AO    2
2139fcf5ef2aSThomas Huth 
2140fcf5ef2aSThomas Huth void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
2141fcf5ef2aSThomas Huth                         uint64_t status, uint64_t mcg_status, uint64_t addr,
2142fcf5ef2aSThomas Huth                         uint64_t misc, int flags);
2143fcf5ef2aSThomas Huth 
2144fcf5ef2aSThomas Huth uint32_t cpu_cc_compute_all(CPUX86State *env1, int op);
2145fcf5ef2aSThomas Huth 
2146fcf5ef2aSThomas Huth static inline uint32_t cpu_compute_eflags(CPUX86State *env)
2147fcf5ef2aSThomas Huth {
214879c664f6SYang Zhong     uint32_t eflags = env->eflags;
214979c664f6SYang Zhong     if (tcg_enabled()) {
215079c664f6SYang Zhong         eflags |= cpu_cc_compute_all(env, CC_OP) | (env->df & DF_MASK);
215179c664f6SYang Zhong     }
215279c664f6SYang Zhong     return eflags;
2153fcf5ef2aSThomas Huth }
2154fcf5ef2aSThomas Huth 
2155fcf5ef2aSThomas Huth static inline MemTxAttrs cpu_get_mem_attrs(CPUX86State *env)
2156fcf5ef2aSThomas Huth {
2157fcf5ef2aSThomas Huth     return ((MemTxAttrs) { .secure = (env->hflags & HF_SMM_MASK) != 0 });
2158fcf5ef2aSThomas Huth }
2159fcf5ef2aSThomas Huth 
2160c8bc83a4SPaolo Bonzini static inline int32_t x86_get_a20_mask(CPUX86State *env)
2161c8bc83a4SPaolo Bonzini {
2162c8bc83a4SPaolo Bonzini     if (env->hflags & HF_SMM_MASK) {
2163c8bc83a4SPaolo Bonzini         return -1;
2164c8bc83a4SPaolo Bonzini     } else {
2165c8bc83a4SPaolo Bonzini         return env->a20_mask;
2166c8bc83a4SPaolo Bonzini     }
2167c8bc83a4SPaolo Bonzini }
2168c8bc83a4SPaolo Bonzini 
216918ab37baSLiran Alon static inline bool cpu_has_vmx(CPUX86State *env)
217018ab37baSLiran Alon {
217118ab37baSLiran Alon     return env->features[FEAT_1_ECX] & CPUID_EXT_VMX;
217218ab37baSLiran Alon }
217318ab37baSLiran Alon 
2174b16c0e20SPaolo Bonzini static inline bool cpu_has_svm(CPUX86State *env)
2175b16c0e20SPaolo Bonzini {
2176b16c0e20SPaolo Bonzini     return env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM;
2177b16c0e20SPaolo Bonzini }
2178b16c0e20SPaolo Bonzini 
217979a197abSLiran Alon /*
218079a197abSLiran Alon  * In order for a vCPU to enter VMX operation it must have CR4.VMXE set.
218179a197abSLiran Alon  * Since it was set, CR4.VMXE must remain set as long as vCPU is in
218279a197abSLiran Alon  * VMX operation. This is because CR4.VMXE is one of the bits set
218379a197abSLiran Alon  * in MSR_IA32_VMX_CR4_FIXED1.
218479a197abSLiran Alon  *
218579a197abSLiran Alon  * There is one exception to above statement when vCPU enters SMM mode.
218679a197abSLiran Alon  * When a vCPU enters SMM mode, it temporarily exit VMX operation and
218779a197abSLiran Alon  * may also reset CR4.VMXE during execution in SMM mode.
218879a197abSLiran Alon  * When vCPU exits SMM mode, vCPU state is restored to be in VMX operation
218979a197abSLiran Alon  * and CR4.VMXE is restored to it's original value of being set.
219079a197abSLiran Alon  *
219179a197abSLiran Alon  * Therefore, when vCPU is not in SMM mode, we can infer whether
219279a197abSLiran Alon  * VMX is being used by examining CR4.VMXE. Otherwise, we cannot
219379a197abSLiran Alon  * know for certain.
219479a197abSLiran Alon  */
219579a197abSLiran Alon static inline bool cpu_vmx_maybe_enabled(CPUX86State *env)
219679a197abSLiran Alon {
219779a197abSLiran Alon     return cpu_has_vmx(env) &&
219879a197abSLiran Alon            ((env->cr[4] & CR4_VMXE_MASK) || (env->hflags & HF_SMM_MASK));
219979a197abSLiran Alon }
220079a197abSLiran Alon 
2201616a89eaSPaolo Bonzini /* excp_helper.c */
2202616a89eaSPaolo Bonzini int get_pg_mode(CPUX86State *env);
2203616a89eaSPaolo Bonzini 
2204fcf5ef2aSThomas Huth /* fpu_helper.c */
22051d8ad165SYang Zhong void update_fp_status(CPUX86State *env);
22061d8ad165SYang Zhong void update_mxcsr_status(CPUX86State *env);
2207418b0f93SJoseph Myers void update_mxcsr_from_sse_status(CPUX86State *env);
22081d8ad165SYang Zhong 
22091d8ad165SYang Zhong static inline void cpu_set_mxcsr(CPUX86State *env, uint32_t mxcsr)
22101d8ad165SYang Zhong {
22111d8ad165SYang Zhong     env->mxcsr = mxcsr;
22121d8ad165SYang Zhong     if (tcg_enabled()) {
22131d8ad165SYang Zhong         update_mxcsr_status(env);
22141d8ad165SYang Zhong     }
22151d8ad165SYang Zhong }
22161d8ad165SYang Zhong 
22171d8ad165SYang Zhong static inline void cpu_set_fpuc(CPUX86State *env, uint16_t fpuc)
22181d8ad165SYang Zhong {
22191d8ad165SYang Zhong      env->fpuc = fpuc;
22201d8ad165SYang Zhong      if (tcg_enabled()) {
22211d8ad165SYang Zhong         update_fp_status(env);
22221d8ad165SYang Zhong      }
22231d8ad165SYang Zhong }
2224fcf5ef2aSThomas Huth 
2225fcf5ef2aSThomas Huth /* mem_helper.c */
2226fcf5ef2aSThomas Huth void helper_lock_init(void);
2227fcf5ef2aSThomas Huth 
2228fcf5ef2aSThomas Huth /* svm_helper.c */
222927bd3216SRichard Henderson #ifdef CONFIG_USER_ONLY
223027bd3216SRichard Henderson static inline void
223127bd3216SRichard Henderson cpu_svm_check_intercept_param(CPUX86State *env1, uint32_t type,
223227bd3216SRichard Henderson                               uint64_t param, uintptr_t retaddr)
223327bd3216SRichard Henderson { /* no-op */ }
2234813c6459SLara Lazier static inline bool
2235813c6459SLara Lazier cpu_svm_has_intercept(CPUX86State *env, uint32_t type)
2236813c6459SLara Lazier { return false; }
223727bd3216SRichard Henderson #else
2238fcf5ef2aSThomas Huth void cpu_svm_check_intercept_param(CPUX86State *env1, uint32_t type,
223965c9d60aSPaolo Bonzini                                    uint64_t param, uintptr_t retaddr);
2240813c6459SLara Lazier bool cpu_svm_has_intercept(CPUX86State *env, uint32_t type);
224127bd3216SRichard Henderson #endif
224227bd3216SRichard Henderson 
2243fcf5ef2aSThomas Huth /* apic.c */
2244fcf5ef2aSThomas Huth void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
2245fcf5ef2aSThomas Huth void apic_handle_tpr_access_report(DeviceState *d, target_ulong ip,
2246fcf5ef2aSThomas Huth                                    TPRAccess access);
2247fcf5ef2aSThomas Huth 
2248dcafd1efSEduardo Habkost /* Special values for X86CPUVersion: */
2249dcafd1efSEduardo Habkost 
2250dcafd1efSEduardo Habkost /* Resolve to latest CPU version */
2251dcafd1efSEduardo Habkost #define CPU_VERSION_LATEST -1
2252dcafd1efSEduardo Habkost 
22530788a56bSEduardo Habkost /*
22540788a56bSEduardo Habkost  * Resolve to version defined by current machine type.
22550788a56bSEduardo Habkost  * See x86_cpu_set_default_version()
22560788a56bSEduardo Habkost  */
22570788a56bSEduardo Habkost #define CPU_VERSION_AUTO   -2
22580788a56bSEduardo Habkost 
2259dcafd1efSEduardo Habkost /* Don't resolve to any versioned CPU models, like old QEMU versions */
2260dcafd1efSEduardo Habkost #define CPU_VERSION_LEGACY  0
2261dcafd1efSEduardo Habkost 
2262dcafd1efSEduardo Habkost typedef int X86CPUVersion;
2263dcafd1efSEduardo Habkost 
22640788a56bSEduardo Habkost /*
22650788a56bSEduardo Habkost  * Set default CPU model version for CPU models having
22660788a56bSEduardo Habkost  * version == CPU_VERSION_AUTO.
22670788a56bSEduardo Habkost  */
22680788a56bSEduardo Habkost void x86_cpu_set_default_version(X86CPUVersion version);
22690788a56bSEduardo Habkost 
2270fcf5ef2aSThomas Huth #define APIC_DEFAULT_ADDRESS 0xfee00000
2271fcf5ef2aSThomas Huth #define APIC_SPACE_SIZE      0x100000
2272fcf5ef2aSThomas Huth 
22730c36af8cSClaudio Fontana /* cpu-dump.c */
2274d3fd9e4bSMarkus Armbruster void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);
2275fcf5ef2aSThomas Huth 
2276fcf5ef2aSThomas Huth /* cpu.c */
2277fcf5ef2aSThomas Huth bool cpu_is_bsp(X86CPU *cpu);
2278fcf5ef2aSThomas Huth 
2279c0198c5fSDavid Edmondson void x86_cpu_xrstor_all_areas(X86CPU *cpu, const void *buf, uint32_t buflen);
2280c0198c5fSDavid Edmondson void x86_cpu_xsave_all_areas(X86CPU *cpu, void *buf, uint32_t buflen);
228135b1b927STao Wu void x86_update_hflags(CPUX86State* env);
228235b1b927STao Wu 
22832d384d7cSVitaly Kuznetsov static inline bool hyperv_feat_enabled(X86CPU *cpu, int feat)
22842d384d7cSVitaly Kuznetsov {
22852d384d7cSVitaly Kuznetsov     return !!(cpu->hyperv_features & BIT(feat));
22862d384d7cSVitaly Kuznetsov }
22872d384d7cSVitaly Kuznetsov 
2288213ff024SLara Lazier static inline uint64_t cr4_reserved_bits(CPUX86State *env)
2289213ff024SLara Lazier {
2290213ff024SLara Lazier     uint64_t reserved_bits = CR4_RESERVED_MASK;
2291213ff024SLara Lazier     if (!env->features[FEAT_XSAVE]) {
2292213ff024SLara Lazier         reserved_bits |= CR4_OSXSAVE_MASK;
2293213ff024SLara Lazier     }
2294213ff024SLara Lazier     if (!(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SMEP)) {
2295213ff024SLara Lazier         reserved_bits |= CR4_SMEP_MASK;
2296213ff024SLara Lazier     }
2297213ff024SLara Lazier     if (!(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SMAP)) {
2298213ff024SLara Lazier         reserved_bits |= CR4_SMAP_MASK;
2299213ff024SLara Lazier     }
2300213ff024SLara Lazier     if (!(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_FSGSBASE)) {
2301213ff024SLara Lazier         reserved_bits |= CR4_FSGSBASE_MASK;
2302213ff024SLara Lazier     }
2303213ff024SLara Lazier     if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_PKU)) {
2304213ff024SLara Lazier         reserved_bits |= CR4_PKE_MASK;
2305213ff024SLara Lazier     }
2306213ff024SLara Lazier     if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_LA57)) {
2307213ff024SLara Lazier         reserved_bits |= CR4_LA57_MASK;
2308213ff024SLara Lazier     }
2309213ff024SLara Lazier     if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_UMIP)) {
2310213ff024SLara Lazier         reserved_bits |= CR4_UMIP_MASK;
2311213ff024SLara Lazier     }
2312213ff024SLara Lazier     if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_PKS)) {
2313213ff024SLara Lazier         reserved_bits |= CR4_PKS_MASK;
2314213ff024SLara Lazier     }
2315213ff024SLara Lazier     return reserved_bits;
2316213ff024SLara Lazier }
2317213ff024SLara Lazier 
23187760bb06SLara Lazier static inline bool ctl_has_irq(CPUX86State *env)
23197760bb06SLara Lazier {
23207760bb06SLara Lazier     uint32_t int_prio;
23217760bb06SLara Lazier     uint32_t tpr;
23227760bb06SLara Lazier 
23237760bb06SLara Lazier     int_prio = (env->int_ctl & V_INTR_PRIO_MASK) >> V_INTR_PRIO_SHIFT;
23247760bb06SLara Lazier     tpr = env->int_ctl & V_TPR_MASK;
23257760bb06SLara Lazier 
23267760bb06SLara Lazier     if (env->int_ctl & V_IGN_TPR_MASK) {
23277760bb06SLara Lazier         return (env->int_ctl & V_IRQ_MASK);
23287760bb06SLara Lazier     }
23297760bb06SLara Lazier 
23307760bb06SLara Lazier     return (env->int_ctl & V_IRQ_MASK) && (int_prio >= tpr);
23317760bb06SLara Lazier }
23327760bb06SLara Lazier 
233352fb8ad3SLara Lazier hwaddr get_hphys(CPUState *cs, hwaddr gphys, MMUAccessType access_type,
233452fb8ad3SLara Lazier                         int *prot);
2335b26491b4SRichard Henderson #if defined(TARGET_X86_64) && \
2336b26491b4SRichard Henderson     defined(CONFIG_USER_ONLY) && \
2337b26491b4SRichard Henderson     defined(CONFIG_LINUX)
2338b26491b4SRichard Henderson # define TARGET_VSYSCALL_PAGE  (UINT64_C(-10) << 20)
2339b26491b4SRichard Henderson #endif
2340b26491b4SRichard Henderson 
2341fcf5ef2aSThomas Huth #endif /* I386_CPU_H */
2342