1 #ifndef __VKI_XEN_X86_H 2 #define __VKI_XEN_X86_H 3 4 #if defined(__i386__) 5 #define ___DEFINE_VKI_XEN_GUEST_HANDLE(name, type) \ 6 typedef struct { type *p; } \ 7 __vki_xen_guest_handle_ ## name; \ 8 typedef struct { union { type *p; vki_xen_uint64_aligned_t q; }; } \ 9 __vki_xen_guest_handle_64_ ## name 10 #define vki_xen_uint64_aligned_t vki_uint64_t __attribute__((aligned(8))) 11 #define __VKI_XEN_GUEST_HANDLE_64(name) __vki_xen_guest_handle_64_ ## name 12 #define VKI_XEN_GUEST_HANDLE_64(name) __VKI_XEN_GUEST_HANDLE_64(name) 13 #else 14 #define ___DEFINE_VKI_XEN_GUEST_HANDLE(name, type) \ 15 typedef struct { type *p; } __vki_xen_guest_handle_ ## name 16 #define vki_xen_uint64_aligned_t vki_uint64_t 17 #define __DEFINE_VKI_XEN_GUEST_HANDLE(name, type) \ 18 ___DEFINE_VKI_XEN_GUEST_HANDLE(name, type); \ 19 ___DEFINE_VKI_XEN_GUEST_HANDLE(const_##name, const type) 20 #define DEFINE_VKI_XEN_GUEST_HANDLE(name) __DEFINE_VKI_XEN_GUEST_HANDLE(name, name) 21 #define VKI_XEN_GUEST_HANDLE_64(name) VKI_XEN_GUEST_HANDLE(name) 22 #endif 23 24 #define __VKI_XEN_GUEST_HANDLE(name) __vki_xen_guest_handle_ ## name 25 #define VKI_XEN_GUEST_HANDLE(name) __VKI_XEN_GUEST_HANDLE(name) 26 27 typedef unsigned long vki_xen_pfn_t; 28 typedef unsigned long vki_xen_ulong_t; 29 30 #if defined(__i386__) 31 struct vki_xen_cpu_user_regs { 32 vki_uint32_t ebx; 33 vki_uint32_t ecx; 34 vki_uint32_t edx; 35 vki_uint32_t esi; 36 vki_uint32_t edi; 37 vki_uint32_t ebp; 38 vki_uint32_t eax; 39 vki_uint16_t error_code; /* private */ 40 vki_uint16_t entry_vector; /* private */ 41 vki_uint32_t eip; 42 vki_uint16_t cs; 43 vki_uint8_t saved_upcall_mask; 44 vki_uint8_t _pad0; 45 vki_uint32_t eflags; /* eflags.IF == !saved_upcall_mask */ 46 vki_uint32_t esp; 47 vki_uint16_t ss, _pad1; 48 vki_uint16_t es, _pad2; 49 vki_uint16_t ds, _pad3; 50 vki_uint16_t fs, _pad4; 51 vki_uint16_t gs, _pad5; 52 }; 53 #else 54 struct vki_xen_cpu_user_regs { 55 vki_uint64_t r15; 56 vki_uint64_t r14; 57 vki_uint64_t r13; 58 vki_uint64_t r12; 59 vki_uint64_t rbp; 60 vki_uint64_t rbx; 61 vki_uint64_t r11; 62 vki_uint64_t r10; 63 vki_uint64_t r9; 64 vki_uint64_t r8; 65 vki_uint64_t rax; 66 vki_uint64_t rcx; 67 vki_uint64_t rdx; 68 vki_uint64_t rsi; 69 vki_uint64_t rdi; 70 vki_uint32_t error_code; /* private */ 71 vki_uint32_t entry_vector; /* private */ 72 vki_uint64_t rip; 73 vki_uint16_t cs, _pad0[1]; 74 vki_uint8_t saved_upcall_mask; 75 vki_uint8_t _pad1[3]; 76 vki_uint64_t rflags; /* rflags.IF == !saved_upcall_mask */ 77 vki_uint64_t rsp; 78 vki_uint16_t ss, _pad2[3]; 79 vki_uint16_t es, _pad3[3]; 80 vki_uint16_t ds, _pad4[3]; 81 vki_uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */ 82 vki_uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */ 83 }; 84 #endif 85 86 struct vki_xen_trap_info { 87 vki_uint8_t vector; /* exception vector */ 88 vki_uint8_t flags; /* 0-3: privilege level; 4: clear event enable? */ 89 vki_uint16_t cs; /* code selector */ 90 unsigned long address; /* code offset */ 91 }; 92 93 struct vki_xen_vcpu_guest_context { 94 /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */ 95 struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */ 96 unsigned long flags; /* VGCF_* flags */ 97 struct vki_xen_cpu_user_regs user_regs; /* User-level CPU registers */ 98 struct vki_xen_trap_info trap_ctxt[256];/* Virtual IDT */ 99 unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */ 100 unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */ 101 unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */ 102 /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */ 103 unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */ 104 unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */ 105 #ifdef __i386__ 106 unsigned long event_callback_cs; /* CS:EIP of event callback */ 107 unsigned long event_callback_eip; 108 unsigned long failsafe_callback_cs; /* CS:EIP of failsafe callback */ 109 unsigned long failsafe_callback_eip; 110 #else 111 unsigned long event_callback_eip; 112 unsigned long failsafe_callback_eip; 113 unsigned long syscall_callback_eip; 114 #endif 115 unsigned long vm_assist; /* VMASST_TYPE_* bitmap */ 116 #ifdef __x86_64__ 117 /* Segment base addresses. */ 118 vki_uint64_t fs_base; 119 vki_uint64_t gs_base_kernel; 120 vki_uint64_t gs_base_user; 121 #endif 122 }; 123 typedef struct vki_xen_vcpu_guest_context vki_xen_vcpu_guest_context_t; 124 DEFINE_VKI_XEN_GUEST_HANDLE(vki_xen_vcpu_guest_context_t); 125 126 127 /* HVM_SAVE types and declarations for getcontext_partial */ 128 # define VKI_DECLARE_HVM_SAVE_TYPE(_x, _code, _type) \ 129 struct __VKI_HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];} 130 131 #define VKI_HVM_SAVE_TYPE(_x) typeof (((struct __VKI_HVM_SAVE_TYPE_##_x *)(0))->t) 132 #define VKI_HVM_SAVE_LENGTH(_x) (sizeof (VKI_HVM_SAVE_TYPE(_x))) 133 #define VKI_HVM_SAVE_CODE(_x) (sizeof (((struct __VKI_HVM_SAVE_TYPE_##_x *)(0))->c)) 134 135 struct vki_hvm_hw_cpu { 136 vki_uint8_t fpu_regs[512]; 137 138 vki_uint64_t rax; 139 vki_uint64_t rbx; 140 vki_uint64_t rcx; 141 vki_uint64_t rdx; 142 vki_uint64_t rbp; 143 vki_uint64_t rsi; 144 vki_uint64_t rdi; 145 vki_uint64_t rsp; 146 vki_uint64_t r8; 147 vki_uint64_t r9; 148 vki_uint64_t r10; 149 vki_uint64_t r11; 150 vki_uint64_t r12; 151 vki_uint64_t r13; 152 vki_uint64_t r14; 153 vki_uint64_t r15; 154 155 vki_uint64_t rip; 156 vki_uint64_t rflags; 157 158 vki_uint64_t cr0; 159 vki_uint64_t cr2; 160 vki_uint64_t cr3; 161 vki_uint64_t cr4; 162 163 vki_uint64_t dr0; 164 vki_uint64_t dr1; 165 vki_uint64_t dr2; 166 vki_uint64_t dr3; 167 vki_uint64_t dr6; 168 vki_uint64_t dr7; 169 170 vki_uint32_t cs_sel; 171 vki_uint32_t ds_sel; 172 vki_uint32_t es_sel; 173 vki_uint32_t fs_sel; 174 vki_uint32_t gs_sel; 175 vki_uint32_t ss_sel; 176 vki_uint32_t tr_sel; 177 vki_uint32_t ldtr_sel; 178 179 vki_uint32_t cs_limit; 180 vki_uint32_t ds_limit; 181 vki_uint32_t es_limit; 182 vki_uint32_t fs_limit; 183 vki_uint32_t gs_limit; 184 vki_uint32_t ss_limit; 185 vki_uint32_t tr_limit; 186 vki_uint32_t ldtr_limit; 187 vki_uint32_t idtr_limit; 188 vki_uint32_t gdtr_limit; 189 190 vki_uint64_t cs_base; 191 vki_uint64_t ds_base; 192 vki_uint64_t es_base; 193 vki_uint64_t fs_base; 194 vki_uint64_t gs_base; 195 vki_uint64_t ss_base; 196 vki_uint64_t tr_base; 197 vki_uint64_t ldtr_base; 198 vki_uint64_t idtr_base; 199 vki_uint64_t gdtr_base; 200 201 vki_uint32_t cs_arbytes; 202 vki_uint32_t ds_arbytes; 203 vki_uint32_t es_arbytes; 204 vki_uint32_t fs_arbytes; 205 vki_uint32_t gs_arbytes; 206 vki_uint32_t ss_arbytes; 207 vki_uint32_t tr_arbytes; 208 vki_uint32_t ldtr_arbytes; 209 210 vki_uint64_t sysenter_cs; 211 vki_uint64_t sysenter_esp; 212 vki_uint64_t sysenter_eip; 213 214 /* msr for em64t */ 215 vki_uint64_t shadow_gs; 216 217 /* msr content saved/restored. */ 218 vki_uint64_t msr_flags; 219 vki_uint64_t msr_lstar; 220 vki_uint64_t msr_star; 221 vki_uint64_t msr_cstar; 222 vki_uint64_t msr_syscall_mask; 223 vki_uint64_t msr_efer; 224 vki_uint64_t msr_tsc_aux; 225 226 /* guest's idea of what rdtsc() would return */ 227 vki_uint64_t tsc; 228 229 /* pending event, if any */ 230 union { 231 vki_uint32_t pending_event; 232 struct { 233 vki_uint8_t pending_vector:8; 234 vki_uint8_t pending_type:3; 235 vki_uint8_t pending_error_valid:1; 236 vki_uint32_t pending_reserved:19; 237 vki_uint8_t pending_valid:1; 238 }; 239 }; 240 /* error code for pending event */ 241 vki_uint32_t error_code; 242 }; 243 244 VKI_DECLARE_HVM_SAVE_TYPE(CPU, 2, struct vki_hvm_hw_cpu); 245 246 #endif // __VKI_XEN_H 247 248 /*--------------------------------------------------------------------*/ 249 /*--- end ---*/ 250 /*--------------------------------------------------------------------*/ 251