linux/arch/x86/include/asm/xen/interface_64.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_XEN_INTERFACE_64_H
#define _ASM_X86_XEN_INTERFACE_64_H

/*
 * 64-bit segment selectors
 * These flat segments are in the Xen-private section of every GDT. Since these
 * are also present in the initial GDT, many OSes will be able to avoid
 * installing their own GDT.
 */

#define FLAT_RING3_CS32
#define FLAT_RING3_CS64
#define FLAT_RING3_DS32
#define FLAT_RING3_DS64
#define FLAT_RING3_SS32
#define FLAT_RING3_SS64

#define FLAT_KERNEL_DS64
#define FLAT_KERNEL_DS32
#define FLAT_KERNEL_DS
#define FLAT_KERNEL_CS64
#define FLAT_KERNEL_CS32
#define FLAT_KERNEL_CS
#define FLAT_KERNEL_SS64
#define FLAT_KERNEL_SS32
#define FLAT_KERNEL_SS

#define FLAT_USER_DS64
#define FLAT_USER_DS32
#define FLAT_USER_DS
#define FLAT_USER_CS64
#define FLAT_USER_CS32
#define FLAT_USER_CS
#define FLAT_USER_SS64
#define FLAT_USER_SS32
#define FLAT_USER_SS

#define __HYPERVISOR_VIRT_START
#define __HYPERVISOR_VIRT_END
#define __MACH2PHYS_VIRT_START
#define __MACH2PHYS_VIRT_END
#define __MACH2PHYS_SHIFT

/*
 * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
 *  @which == SEGBASE_*  ;  @base == 64-bit base address
 * Returns 0 on success.
 */
#define SEGBASE_FS
#define SEGBASE_GS_USER
#define SEGBASE_GS_KERNEL
#define SEGBASE_GS_USER_SEL

/*
 * int HYPERVISOR_iret(void)
 * All arguments are on the kernel stack, in the following format.
 * Never returns if successful. Current kernel context is lost.
 * The saved CS is mapped as follows:
 *   RING0 -> RING3 kernel mode.
 *   RING1 -> RING3 kernel mode.
 *   RING2 -> RING3 kernel mode.
 *   RING3 -> RING3 user mode.
 * However RING0 indicates that the guest kernel should return to itself
 * directly with
 *      orb   $3,1*8(%rsp)
 *      iretq
 * If flags contains VGCF_in_syscall:
 *   Restore RAX, RIP, RFLAGS, RSP.
 *   Discard R11, RCX, CS, SS.
 * Otherwise:
 *   Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
 * All other registers are saved on hypercall entry and restored to user.
 */
/* Guest exited in SYSCALL context? Return to guest with SYSRET? */
#define _VGCF_in_syscall
#define VGCF_in_syscall
#define VGCF_IN_SYSCALL

#ifndef __ASSEMBLY__

struct iret_context {
    /* Top of stack (%rsp at point of hypercall). */
    uint64_t rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
    /* Bottom of iret stack frame. */
};

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes both 32- and 64-bit names (e.g., eax/rax). */
#define __DECL_REG
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rax). */
#define __DECL_REG
#endif

struct cpu_user_regs {
    uint64_t r15;
    uint64_t r14;
    uint64_t r13;
    uint64_t r12;
    __DECL_REG(bp);
    __DECL_REG(bx);
    uint64_t r11;
    uint64_t r10;
    uint64_t r9;
    uint64_t r8;
    __DECL_REG(ax);
    __DECL_REG(cx);
    __DECL_REG(dx);
    __DECL_REG(si);
    __DECL_REG(di);
    uint32_t error_code;    /* private */
    uint32_t entry_vector;  /* private */
    __DECL_REG(ip);
    uint16_t cs, _pad0[1];
    uint8_t  saved_upcall_mask;
    uint8_t  _pad1[3];
    __DECL_REG(flags);      /* rflags.IF == !saved_upcall_mask */
    __DECL_REG(sp);
    uint16_t ss, _pad2[3];
    uint16_t es, _pad3[3];
    uint16_t ds, _pad4[3];
    uint16_t fs, _pad5[3]; /* Non-zero => takes precedence over fs_base.     */
    uint16_t gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_usr. */
};
DEFINE_GUEST_HANDLE_STRUCT(cpu_user_regs);

#undef __DECL_REG

#define xen_pfn_to_cr3
#define xen_cr3_to_pfn

struct arch_vcpu_info {
    unsigned long cr2;
    unsigned long pad; /* sizeof(vcpu_info_t) == 64 */
};

typedef unsigned long xen_callback_t;

#define XEN_CALLBACK

#endif /* !__ASSEMBLY__ */


#endif /* _ASM_X86_XEN_INTERFACE_64_H */