Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_X86_XEN_INTERFACE_64_H
0003 #define _ASM_X86_XEN_INTERFACE_64_H
0004 
0005 /*
0006  * 64-bit segment selectors
0007  * These flat segments are in the Xen-private section of every GDT. Since these
0008  * are also present in the initial GDT, many OSes will be able to avoid
0009  * installing their own GDT.
0010  */
0011 
0012 #define FLAT_RING3_CS32 0xe023  /* GDT index 260 */
0013 #define FLAT_RING3_CS64 0xe033  /* GDT index 261 */
0014 #define FLAT_RING3_DS32 0xe02b  /* GDT index 262 */
0015 #define FLAT_RING3_DS64 0x0000  /* NULL selector */
0016 #define FLAT_RING3_SS32 0xe02b  /* GDT index 262 */
0017 #define FLAT_RING3_SS64 0xe02b  /* GDT index 262 */
0018 
0019 #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
0020 #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
0021 #define FLAT_KERNEL_DS   FLAT_KERNEL_DS64
0022 #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
0023 #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
0024 #define FLAT_KERNEL_CS   FLAT_KERNEL_CS64
0025 #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
0026 #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
0027 #define FLAT_KERNEL_SS   FLAT_KERNEL_SS64
0028 
0029 #define FLAT_USER_DS64 FLAT_RING3_DS64
0030 #define FLAT_USER_DS32 FLAT_RING3_DS32
0031 #define FLAT_USER_DS   FLAT_USER_DS64
0032 #define FLAT_USER_CS64 FLAT_RING3_CS64
0033 #define FLAT_USER_CS32 FLAT_RING3_CS32
0034 #define FLAT_USER_CS   FLAT_USER_CS64
0035 #define FLAT_USER_SS64 FLAT_RING3_SS64
0036 #define FLAT_USER_SS32 FLAT_RING3_SS32
0037 #define FLAT_USER_SS   FLAT_USER_SS64
0038 
0039 #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
0040 #define __HYPERVISOR_VIRT_END   0xFFFF880000000000
0041 #define __MACH2PHYS_VIRT_START  0xFFFF800000000000
0042 #define __MACH2PHYS_VIRT_END    0xFFFF804000000000
0043 #define __MACH2PHYS_SHIFT       3
0044 
0045 /*
0046  * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
0047  *  @which == SEGBASE_*  ;  @base == 64-bit base address
0048  * Returns 0 on success.
0049  */
0050 #define SEGBASE_FS          0
0051 #define SEGBASE_GS_USER     1
0052 #define SEGBASE_GS_KERNEL   2
0053 #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
0054 
0055 /*
0056  * int HYPERVISOR_iret(void)
0057  * All arguments are on the kernel stack, in the following format.
0058  * Never returns if successful. Current kernel context is lost.
0059  * The saved CS is mapped as follows:
0060  *   RING0 -> RING3 kernel mode.
0061  *   RING1 -> RING3 kernel mode.
0062  *   RING2 -> RING3 kernel mode.
0063  *   RING3 -> RING3 user mode.
0064  * However RING0 indicates that the guest kernel should return to iteself
0065  * directly with
0066  *      orb   $3,1*8(%rsp)
0067  *      iretq
0068  * If flags contains VGCF_in_syscall:
0069  *   Restore RAX, RIP, RFLAGS, RSP.
0070  *   Discard R11, RCX, CS, SS.
0071  * Otherwise:
0072  *   Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
0073  * All other registers are saved on hypercall entry and restored to user.
0074  */
0075 /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
0076 #define _VGCF_in_syscall 8
0077 #define VGCF_in_syscall  (1<<_VGCF_in_syscall)
0078 #define VGCF_IN_SYSCALL  VGCF_in_syscall
0079 
0080 #ifndef __ASSEMBLY__
0081 
0082 struct iret_context {
0083     /* Top of stack (%rsp at point of hypercall). */
0084     uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
0085     /* Bottom of iret stack frame. */
0086 };
0087 
0088 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
0089 /* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
0090 #define __DECL_REG(name) union { \
0091     uint64_t r ## name, e ## name; \
0092     uint32_t _e ## name; \
0093 }
0094 #else
0095 /* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
0096 #define __DECL_REG(name) uint64_t r ## name
0097 #endif
0098 
0099 struct cpu_user_regs {
0100     uint64_t r15;
0101     uint64_t r14;
0102     uint64_t r13;
0103     uint64_t r12;
0104     __DECL_REG(bp);
0105     __DECL_REG(bx);
0106     uint64_t r11;
0107     uint64_t r10;
0108     uint64_t r9;
0109     uint64_t r8;
0110     __DECL_REG(ax);
0111     __DECL_REG(cx);
0112     __DECL_REG(dx);
0113     __DECL_REG(si);
0114     __DECL_REG(di);
0115     uint32_t error_code;    /* private */
0116     uint32_t entry_vector;  /* private */
0117     __DECL_REG(ip);
0118     uint16_t cs, _pad0[1];
0119     uint8_t  saved_upcall_mask;
0120     uint8_t  _pad1[3];
0121     __DECL_REG(flags);      /* rflags.IF == !saved_upcall_mask */
0122     __DECL_REG(sp);
0123     uint16_t ss, _pad2[3];
0124     uint16_t es, _pad3[3];
0125     uint16_t ds, _pad4[3];
0126     uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base.     */
0127     uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
0128 };
0129 DEFINE_GUEST_HANDLE_STRUCT(cpu_user_regs);
0130 
0131 #undef __DECL_REG
0132 
0133 #define xen_pfn_to_cr3(pfn) ((unsigned long)(pfn) << 12)
0134 #define xen_cr3_to_pfn(cr3) ((unsigned long)(cr3) >> 12)
0135 
0136 struct arch_vcpu_info {
0137     unsigned long cr2;
0138     unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
0139 };
0140 
0141 typedef unsigned long xen_callback_t;
0142 
0143 #define XEN_CALLBACK(__cs, __rip)               \
0144     ((unsigned long)(__rip))
0145 
0146 #endif /* !__ASSEMBLY__ */
0147 
0148 
0149 #endif /* _ASM_X86_XEN_INTERFACE_64_H */