18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci * arch-x86_32.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Guest OS interface to x86 32-bit Xen.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2004, K A Fraser
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _ASM_X86_XEN_INTERFACE_32_H
118c2ecf20Sopenharmony_ci#define _ASM_X86_XEN_INTERFACE_32_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * These flat segments are in the Xen-private section of every GDT. Since these
168c2ecf20Sopenharmony_ci * are also present in the initial GDT, many OSes will be able to avoid
178c2ecf20Sopenharmony_ci * installing their own GDT.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci#define FLAT_RING1_CS 0xe019    /* GDT index 259 */
208c2ecf20Sopenharmony_ci#define FLAT_RING1_DS 0xe021    /* GDT index 260 */
218c2ecf20Sopenharmony_ci#define FLAT_RING1_SS 0xe021    /* GDT index 260 */
228c2ecf20Sopenharmony_ci#define FLAT_RING3_CS 0xe02b    /* GDT index 261 */
238c2ecf20Sopenharmony_ci#define FLAT_RING3_DS 0xe033    /* GDT index 262 */
248c2ecf20Sopenharmony_ci#define FLAT_RING3_SS 0xe033    /* GDT index 262 */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define FLAT_KERNEL_CS FLAT_RING1_CS
278c2ecf20Sopenharmony_ci#define FLAT_KERNEL_DS FLAT_RING1_DS
288c2ecf20Sopenharmony_ci#define FLAT_KERNEL_SS FLAT_RING1_SS
298c2ecf20Sopenharmony_ci#define FLAT_USER_CS    FLAT_RING3_CS
308c2ecf20Sopenharmony_ci#define FLAT_USER_DS    FLAT_RING3_DS
318c2ecf20Sopenharmony_ci#define FLAT_USER_SS    FLAT_RING3_SS
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* And the trap vector is... */
348c2ecf20Sopenharmony_ci#define TRAP_INSTR "int $0x82"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define __MACH2PHYS_VIRT_START 0xF5800000
378c2ecf20Sopenharmony_ci#define __MACH2PHYS_VIRT_END   0xF6800000
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define __MACH2PHYS_SHIFT      2
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * Virtual addresses beyond this are not modifiable by guest OSes. The
438c2ecf20Sopenharmony_ci * machine->physical mapping table starts at this address, read-only.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#define __HYPERVISOR_VIRT_START 0xF5800000
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistruct cpu_user_regs {
508c2ecf20Sopenharmony_ci    uint32_t ebx;
518c2ecf20Sopenharmony_ci    uint32_t ecx;
528c2ecf20Sopenharmony_ci    uint32_t edx;
538c2ecf20Sopenharmony_ci    uint32_t esi;
548c2ecf20Sopenharmony_ci    uint32_t edi;
558c2ecf20Sopenharmony_ci    uint32_t ebp;
568c2ecf20Sopenharmony_ci    uint32_t eax;
578c2ecf20Sopenharmony_ci    uint16_t error_code;    /* private */
588c2ecf20Sopenharmony_ci    uint16_t entry_vector;  /* private */
598c2ecf20Sopenharmony_ci    uint32_t eip;
608c2ecf20Sopenharmony_ci    uint16_t cs;
618c2ecf20Sopenharmony_ci    uint8_t  saved_upcall_mask;
628c2ecf20Sopenharmony_ci    uint8_t  _pad0;
638c2ecf20Sopenharmony_ci    uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
648c2ecf20Sopenharmony_ci    uint32_t esp;
658c2ecf20Sopenharmony_ci    uint16_t ss, _pad1;
668c2ecf20Sopenharmony_ci    uint16_t es, _pad2;
678c2ecf20Sopenharmony_ci    uint16_t ds, _pad3;
688c2ecf20Sopenharmony_ci    uint16_t fs, _pad4;
698c2ecf20Sopenharmony_ci    uint16_t gs, _pad5;
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ciDEFINE_GUEST_HANDLE_STRUCT(cpu_user_regs);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_citypedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistruct arch_vcpu_info {
768c2ecf20Sopenharmony_ci    unsigned long cr2;
778c2ecf20Sopenharmony_ci    unsigned long pad[5]; /* sizeof(struct vcpu_info) == 64 */
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistruct xen_callback {
818c2ecf20Sopenharmony_ci	unsigned long cs;
828c2ecf20Sopenharmony_ci	unsigned long eip;
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_citypedef struct xen_callback xen_callback_t;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define XEN_CALLBACK(__cs, __eip)				\
878c2ecf20Sopenharmony_ci	((struct xen_callback){ .cs = (__cs), .eip = (unsigned long)(__eip) })
888c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/*
928c2ecf20Sopenharmony_ci * Page-directory addresses above 4GB do not fit into architectural %cr3.
938c2ecf20Sopenharmony_ci * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
948c2ecf20Sopenharmony_ci * must use the following accessor macros to pack/unpack valid MFNs.
958c2ecf20Sopenharmony_ci *
968c2ecf20Sopenharmony_ci * Note that Xen is using the fact that the pagetable base is always
978c2ecf20Sopenharmony_ci * page-aligned, and putting the 12 MSB of the address into the 12 LSB
988c2ecf20Sopenharmony_ci * of cr3.
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci#define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
1018c2ecf20Sopenharmony_ci#define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#endif /* _ASM_X86_XEN_INTERFACE_32_H */
104