Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:28:42

0001 /*
0002    This file is part of Valgrind, a dynamic binary instrumentation
0003    framework.
0004 
0005    Copyright (C) 2012-2017 Citrix
0006 
0007    This program is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU General Public License as
0009    published by the Free Software Foundation; either version 2 of the
0010    License, or (at your option) any later version.
0011 
0012    This program is distributed in the hope that it will be useful, but
0013    WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    General Public License for more details.
0016 
0017    You should have received a copy of the GNU General Public License
0018    along with this program; if not, see <http://www.gnu.org/licenses/>.
0019 
0020    The GNU General Public License is contained in the file COPYING.
0021 */
0022 
0023 /* Contributed by Andrew Cooper <andrew.cooper3@citrix.com>
0024    and Ian Campbell <ian.campbell@citrix.com> */
0025 
0026 #ifndef __VKI_XEN_X86_H
0027 #define __VKI_XEN_X86_H
0028 
0029 #if defined(__i386__)
0030 #define ___DEFINE_VKI_XEN_GUEST_HANDLE(name, type)          \
0031     typedef struct { type *p; }                     \
0032         __vki_xen_guest_handle_ ## name;                                \
0033     typedef struct { union { type *p; vki_xen_uint64_aligned_t q; }; }  \
0034         __vki_xen_guest_handle_64_ ## name
0035 #define vki_xen_uint64_aligned_t vki_uint64_t __attribute__((aligned(8)))
0036 #define __VKI_XEN_GUEST_HANDLE_64(name) __vki_xen_guest_handle_64_ ## name
0037 #define VKI_XEN_GUEST_HANDLE_64(name) __VKI_XEN_GUEST_HANDLE_64(name)
0038 #else
0039 #define ___DEFINE_VKI_XEN_GUEST_HANDLE(name, type) \
0040     typedef struct { type *p; } __vki_xen_guest_handle_ ## name
0041 #define vki_xen_uint64_aligned_t vki_uint64_t
0042 #define __DEFINE_VKI_XEN_GUEST_HANDLE(name, type) \
0043     ___DEFINE_VKI_XEN_GUEST_HANDLE(name, type);   \
0044     ___DEFINE_VKI_XEN_GUEST_HANDLE(const_##name, const type)
0045 #define DEFINE_VKI_XEN_GUEST_HANDLE(name)   __DEFINE_VKI_XEN_GUEST_HANDLE(name, name)
0046 #define VKI_XEN_GUEST_HANDLE_64(name) VKI_XEN_GUEST_HANDLE(name)
0047 #endif
0048 
0049 #define __VKI_XEN_GUEST_HANDLE(name)  __vki_xen_guest_handle_ ## name
0050 #define VKI_XEN_GUEST_HANDLE(name)    __VKI_XEN_GUEST_HANDLE(name)
0051 
0052 typedef unsigned long vki_xen_pfn_t;
0053 typedef unsigned long vki_xen_ulong_t;
0054 
0055 #if defined(__i386__)
0056 struct vki_xen_cpu_user_regs {
0057     vki_uint32_t ebx;
0058     vki_uint32_t ecx;
0059     vki_uint32_t edx;
0060     vki_uint32_t esi;
0061     vki_uint32_t edi;
0062     vki_uint32_t ebp;
0063     vki_uint32_t eax;
0064     vki_uint16_t error_code;    /* private */
0065     vki_uint16_t entry_vector;  /* private */
0066     vki_uint32_t eip;
0067     vki_uint16_t cs;
0068     vki_uint8_t  saved_upcall_mask;
0069     vki_uint8_t  _pad0;
0070     vki_uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
0071     vki_uint32_t esp;
0072     vki_uint16_t ss, _pad1;
0073     vki_uint16_t es, _pad2;
0074     vki_uint16_t ds, _pad3;
0075     vki_uint16_t fs, _pad4;
0076     vki_uint16_t gs, _pad5;
0077 };
0078 #else
0079 struct vki_xen_cpu_user_regs {
0080     vki_uint64_t r15;
0081     vki_uint64_t r14;
0082     vki_uint64_t r13;
0083     vki_uint64_t r12;
0084     vki_uint64_t rbp;
0085     vki_uint64_t rbx;
0086     vki_uint64_t r11;
0087     vki_uint64_t r10;
0088     vki_uint64_t r9;
0089     vki_uint64_t r8;
0090     vki_uint64_t rax;
0091     vki_uint64_t rcx;
0092     vki_uint64_t rdx;
0093     vki_uint64_t rsi;
0094     vki_uint64_t rdi;
0095     vki_uint32_t error_code;    /* private */
0096     vki_uint32_t entry_vector;  /* private */
0097     vki_uint64_t rip;
0098     vki_uint16_t cs, _pad0[1];
0099     vki_uint8_t  saved_upcall_mask;
0100     vki_uint8_t  _pad1[3];
0101     vki_uint64_t rflags;      /* rflags.IF == !saved_upcall_mask */
0102     vki_uint64_t rsp;
0103     vki_uint16_t ss, _pad2[3];
0104     vki_uint16_t es, _pad3[3];
0105     vki_uint16_t ds, _pad4[3];
0106     vki_uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base.     */
0107     vki_uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
0108 };
0109 #endif
0110 
0111 struct vki_xen_trap_info {
0112     vki_uint8_t   vector;  /* exception vector                              */
0113     vki_uint8_t   flags;   /* 0-3: privilege level; 4: clear event enable?  */
0114     vki_uint16_t  cs;      /* code selector                                 */
0115     unsigned long address; /* code offset                                   */
0116 };
0117 
0118 struct vki_xen_vcpu_guest_context {
0119     /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
0120     struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
0121     unsigned long flags;                    /* VGCF_* flags                 */
0122     struct vki_xen_cpu_user_regs user_regs; /* User-level CPU registers     */
0123     struct vki_xen_trap_info trap_ctxt[256];/* Virtual IDT                  */
0124     unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
0125     unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
0126     unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
0127     /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
0128     unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
0129     unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
0130 #ifdef __i386__
0131     unsigned long event_callback_cs;        /* CS:EIP of event callback     */
0132     unsigned long event_callback_eip;
0133     unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
0134     unsigned long failsafe_callback_eip;
0135 #else
0136     unsigned long event_callback_eip;
0137     unsigned long failsafe_callback_eip;
0138     unsigned long syscall_callback_eip;
0139 #endif
0140     unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
0141 #ifdef __x86_64__
0142     /* Segment base addresses. */
0143     vki_uint64_t  fs_base;
0144     vki_uint64_t  gs_base_kernel;
0145     vki_uint64_t  gs_base_user;
0146 #endif
0147 };
0148 typedef struct vki_xen_vcpu_guest_context vki_xen_vcpu_guest_context_t;
0149 DEFINE_VKI_XEN_GUEST_HANDLE(vki_xen_vcpu_guest_context_t);
0150 
0151 
0152 /* HVM_SAVE types and declarations for getcontext_partial */
0153 # define VKI_DECLARE_HVM_SAVE_TYPE(_x, _code, _type)                         \
0154     struct __VKI_HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}
0155 
0156 #define VKI_HVM_SAVE_TYPE(_x) typeof (((struct __VKI_HVM_SAVE_TYPE_##_x *)(0))->t)
0157 #define VKI_HVM_SAVE_LENGTH(_x) (sizeof (VKI_HVM_SAVE_TYPE(_x)))
0158 #define VKI_HVM_SAVE_CODE(_x) (sizeof (((struct __VKI_HVM_SAVE_TYPE_##_x *)(0))->c))
0159 
0160 struct vki_hvm_hw_cpu {
0161    vki_uint8_t  fpu_regs[512];
0162 
0163    vki_uint64_t rax;
0164    vki_uint64_t rbx;
0165    vki_uint64_t rcx;
0166    vki_uint64_t rdx;
0167    vki_uint64_t rbp;
0168    vki_uint64_t rsi;
0169    vki_uint64_t rdi;
0170    vki_uint64_t rsp;
0171    vki_uint64_t r8;
0172    vki_uint64_t r9;
0173    vki_uint64_t r10;
0174    vki_uint64_t r11;
0175    vki_uint64_t r12;
0176    vki_uint64_t r13;
0177    vki_uint64_t r14;
0178    vki_uint64_t r15;
0179 
0180    vki_uint64_t rip;
0181    vki_uint64_t rflags;
0182 
0183    vki_uint64_t cr0;
0184    vki_uint64_t cr2;
0185    vki_uint64_t cr3;
0186    vki_uint64_t cr4;
0187 
0188    vki_uint64_t dr0;
0189    vki_uint64_t dr1;
0190    vki_uint64_t dr2;
0191    vki_uint64_t dr3;
0192    vki_uint64_t dr6;
0193    vki_uint64_t dr7;
0194 
0195    vki_uint32_t cs_sel;
0196    vki_uint32_t ds_sel;
0197    vki_uint32_t es_sel;
0198    vki_uint32_t fs_sel;
0199    vki_uint32_t gs_sel;
0200    vki_uint32_t ss_sel;
0201    vki_uint32_t tr_sel;
0202    vki_uint32_t ldtr_sel;
0203 
0204    vki_uint32_t cs_limit;
0205    vki_uint32_t ds_limit;
0206    vki_uint32_t es_limit;
0207    vki_uint32_t fs_limit;
0208    vki_uint32_t gs_limit;
0209    vki_uint32_t ss_limit;
0210    vki_uint32_t tr_limit;
0211    vki_uint32_t ldtr_limit;
0212    vki_uint32_t idtr_limit;
0213    vki_uint32_t gdtr_limit;
0214 
0215    vki_uint64_t cs_base;
0216    vki_uint64_t ds_base;
0217    vki_uint64_t es_base;
0218    vki_uint64_t fs_base;
0219    vki_uint64_t gs_base;
0220    vki_uint64_t ss_base;
0221    vki_uint64_t tr_base;
0222    vki_uint64_t ldtr_base;
0223    vki_uint64_t idtr_base;
0224    vki_uint64_t gdtr_base;
0225 
0226    vki_uint32_t cs_arbytes;
0227    vki_uint32_t ds_arbytes;
0228    vki_uint32_t es_arbytes;
0229    vki_uint32_t fs_arbytes;
0230    vki_uint32_t gs_arbytes;
0231    vki_uint32_t ss_arbytes;
0232    vki_uint32_t tr_arbytes;
0233    vki_uint32_t ldtr_arbytes;
0234 
0235    vki_uint64_t sysenter_cs;
0236    vki_uint64_t sysenter_esp;
0237    vki_uint64_t sysenter_eip;
0238 
0239     /* msr for em64t */
0240    vki_uint64_t shadow_gs;
0241 
0242     /* msr content saved/restored. */
0243    vki_uint64_t msr_flags;
0244    vki_uint64_t msr_lstar;
0245    vki_uint64_t msr_star;
0246    vki_uint64_t msr_cstar;
0247    vki_uint64_t msr_syscall_mask;
0248    vki_uint64_t msr_efer;
0249    vki_uint64_t msr_tsc_aux;
0250 
0251     /* guest's idea of what rdtsc() would return */
0252    vki_uint64_t tsc;
0253 
0254     /* pending event, if any */
0255     union {
0256        vki_uint32_t pending_event;
0257         struct {
0258            vki_uint8_t  pending_vector:8;
0259            vki_uint8_t  pending_type:3;
0260            vki_uint8_t  pending_error_valid:1;
0261            vki_uint32_t pending_reserved:19;
0262            vki_uint8_t  pending_valid:1;
0263         };
0264     };
0265     /* error code for pending event */
0266    vki_uint32_t error_code;
0267 };
0268 
0269 VKI_DECLARE_HVM_SAVE_TYPE(CPU, 2, struct vki_hvm_hw_cpu);
0270 
0271 struct vki_hvm_hw_mtrr {
0272 #define VKI_MTRR_VCNT     8
0273 #define VKI_NUM_FIXED_MSR 11
0274    vki_uint64_t msr_pat_cr;
0275    /* mtrr physbase & physmask msr pair*/
0276    vki_uint64_t msr_mtrr_var[VKI_MTRR_VCNT*2];
0277    vki_uint64_t msr_mtrr_fixed[VKI_NUM_FIXED_MSR];
0278    vki_uint64_t msr_mtrr_cap;
0279    vki_uint64_t msr_mtrr_def_type;
0280 };
0281 
0282 VKI_DECLARE_HVM_SAVE_TYPE(MTRR, 14, struct vki_hvm_hw_mtrr);
0283 
0284 #endif // __VKI_XEN_H
0285 
0286 /*--------------------------------------------------------------------*/
0287 /*--- end                                                          ---*/
0288 /*--------------------------------------------------------------------*/