ia64/xen-unstable

view xen/include/public/arch-x86_64.h @ 6316:f7dfaa2af90c

merge?
author cl349@firebug.cl.cam.ac.uk
date Sun Aug 21 11:02:00 2005 +0000 (2005-08-21)
parents 1872e09bfba3
children 6721abf6b16d
line source
1 /******************************************************************************
2 * arch-x86_64.h
3 *
4 * Guest OS interface to x86 64-bit Xen.
5 *
6 * Copyright (c) 2004, K A Fraser
7 */
9 #ifndef __XEN_PUBLIC_ARCH_X86_64_H__
10 #define __XEN_PUBLIC_ARCH_X86_64_H__
12 /*
13 * SEGMENT DESCRIPTOR TABLES
14 */
15 /*
16 * A number of GDT entries are reserved by Xen. These are not situated at the
17 * start of the GDT because some stupid OSes export hard-coded selector values
18 * in their ABI. These hard-coded values are always near the start of the GDT,
19 * so Xen places itself out of the way, at the far end of the GDT.
20 */
21 #define FIRST_RESERVED_GDT_PAGE 14
22 #define FIRST_RESERVED_GDT_BYTE (FIRST_RESERVED_GDT_PAGE * 4096)
23 #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
25 /*
26 * 64-bit segment selectors
27 * These flat segments are in the Xen-private section of every GDT. Since these
28 * are also present in the initial GDT, many OSes will be able to avoid
29 * installing their own GDT.
30 */
32 #define FLAT_RING3_CS32 0xe023 /* GDT index 260 */
33 #define FLAT_RING3_CS64 0xe033 /* GDT index 261 */
34 #define FLAT_RING3_DS32 0xe02b /* GDT index 262 */
35 #define FLAT_RING3_DS64 0x0000 /* NULL selector */
36 #define FLAT_RING3_SS32 0xe02b /* GDT index 262 */
37 #define FLAT_RING3_SS64 0xe02b /* GDT index 262 */
39 #define FLAT_KERNEL_DS64 FLAT_RING3_DS64
40 #define FLAT_KERNEL_DS32 FLAT_RING3_DS32
41 #define FLAT_KERNEL_DS FLAT_KERNEL_DS64
42 #define FLAT_KERNEL_CS64 FLAT_RING3_CS64
43 #define FLAT_KERNEL_CS32 FLAT_RING3_CS32
44 #define FLAT_KERNEL_CS FLAT_KERNEL_CS64
45 #define FLAT_KERNEL_SS64 FLAT_RING3_SS64
46 #define FLAT_KERNEL_SS32 FLAT_RING3_SS32
47 #define FLAT_KERNEL_SS FLAT_KERNEL_SS64
49 #define FLAT_USER_DS64 FLAT_RING3_DS64
50 #define FLAT_USER_DS32 FLAT_RING3_DS32
51 #define FLAT_USER_DS FLAT_USER_DS64
52 #define FLAT_USER_CS64 FLAT_RING3_CS64
53 #define FLAT_USER_CS32 FLAT_RING3_CS32
54 #define FLAT_USER_CS FLAT_USER_CS64
55 #define FLAT_USER_SS64 FLAT_RING3_SS64
56 #define FLAT_USER_SS32 FLAT_RING3_SS32
57 #define FLAT_USER_SS FLAT_USER_SS64
59 /* And the trap vector is... */
60 #define TRAP_INSTR "syscall"
62 #ifndef HYPERVISOR_VIRT_START
63 #define HYPERVISOR_VIRT_START (0xFFFF800000000000UL)
64 #define HYPERVISOR_VIRT_END (0xFFFF880000000000UL)
65 #endif
67 /* Maximum number of virtual CPUs in multi-processor guests. */
68 #define MAX_VIRT_CPUS 32
70 #ifndef __ASSEMBLY__
72 /* The machine->physical mapping table starts at this address, read-only. */
73 #ifndef machine_to_phys_mapping
74 #define machine_to_phys_mapping ((u32 *)HYPERVISOR_VIRT_START)
75 #endif
77 /*
78 * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
79 * @which == SEGBASE_* ; @base == 64-bit base address
80 * Returns 0 on success.
81 */
82 #define SEGBASE_FS 0
83 #define SEGBASE_GS_USER 1
84 #define SEGBASE_GS_KERNEL 2
85 #define SEGBASE_GS_USER_SEL 3 /* Set user %gs specified in base[15:0] */
87 /*
88 * int HYPERVISOR_switch_to_user(void)
89 * All arguments are on the kernel stack, in the following format.
90 * Never returns if successful. Current kernel context is lost.
91 * If flags contains VGCF_IN_SYSCALL:
92 * Restore RAX, RIP, RFLAGS, RSP.
93 * Discard R11, RCX, CS, SS.
94 * Otherwise:
95 * Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
96 * All other registers are saved on hypercall entry and restored to user.
97 */
98 /* Guest exited in SYSCALL context? Return to guest with SYSRET? */
99 #define VGCF_IN_SYSCALL (1<<8)
100 struct switch_to_user {
101 /* Top of stack (%rsp at point of hypercall). */
102 u64 rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
103 /* Bottom of switch_to_user stack frame. */
104 };
106 /*
107 * Send an array of these to HYPERVISOR_set_trap_table().
108 * N.B. As in x86/32 mode, the privilege level specifies which modes may enter
109 * a trap via a software interrupt. Since rings 1 and 2 are unavailable, we
110 * allocate privilege levels as follows:
111 * Level == 0: Noone may enter
112 * Level == 1: Kernel may enter
113 * Level == 2: Kernel may enter
114 * Level == 3: Everyone may enter
115 */
116 #define TI_GET_DPL(_ti) ((_ti)->flags & 3)
117 #define TI_GET_IF(_ti) ((_ti)->flags & 4)
118 #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
119 #define TI_SET_IF(_ti,_if) ((_ti)->flags |= ((!!(_if))<<2))
120 typedef struct trap_info {
121 u8 vector; /* exception vector */
122 u8 flags; /* 0-3: privilege level; 4: clear event enable? */
123 u16 cs; /* code selector */
124 unsigned long address; /* code offset */
125 } trap_info_t;
127 typedef struct cpu_user_regs {
128 u64 r15;
129 u64 r14;
130 u64 r13;
131 u64 r12;
132 union { u64 rbp, ebp; };
133 union { u64 rbx, ebx; };
134 u64 r11;
135 u64 r10;
136 u64 r9;
137 u64 r8;
138 union { u64 rax, eax; };
139 union { u64 rcx, ecx; };
140 union { u64 rdx, edx; };
141 union { u64 rsi, esi; };
142 union { u64 rdi, edi; };
143 u32 error_code; /* private */
144 u32 entry_vector; /* private */
145 union { u64 rip, eip; };
146 u16 cs, _pad0[1];
147 u8 saved_upcall_mask;
148 u8 _pad1[3];
149 union { u64 rflags, eflags; };
150 union { u64 rsp, esp; };
151 u16 ss, _pad2[3];
152 u16 es, _pad3[3];
153 u16 ds, _pad4[3];
154 u16 fs, _pad5[3]; /* Non-zero => takes precedence over fs_base. */
155 u16 gs, _pad6[3]; /* Non-zero => takes precedence over gs_base_user. */
156 } cpu_user_regs_t;
158 typedef u64 tsc_timestamp_t; /* RDTSC timestamp */
160 /*
161 * The following is all CPU context. Note that the fpu_ctxt block is filled
162 * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
163 */
164 typedef struct vcpu_guest_context {
165 /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
166 struct { char x[512]; } fpu_ctxt; /* User-level FPU registers */
167 #define VGCF_I387_VALID (1<<0)
168 #define VGCF_VMX_GUEST (1<<1)
169 #define VGCF_IN_KERNEL (1<<2)
170 unsigned long flags; /* VGCF_* flags */
171 cpu_user_regs_t user_regs; /* User-level CPU registers */
172 trap_info_t trap_ctxt[256]; /* Virtual IDT */
173 unsigned long ldt_base, ldt_ents; /* LDT (linear address, # ents) */
174 unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
175 unsigned long kernel_ss, kernel_sp; /* Virtual TSS (only SS1/SP1) */
176 unsigned long ctrlreg[8]; /* CR0-CR7 (control registers) */
177 unsigned long debugreg[8]; /* DB0-DB7 (debug registers) */
178 unsigned long event_callback_eip;
179 unsigned long failsafe_callback_eip;
180 unsigned long syscall_callback_eip;
181 unsigned long vm_assist; /* VMASST_TYPE_* bitmap */
182 /* Segment base addresses. */
183 u64 fs_base;
184 u64 gs_base_kernel;
185 u64 gs_base_user;
186 } vcpu_guest_context_t;
188 typedef struct arch_shared_info {
189 /* MFN of a table of MFNs that make up p2m table */
190 u64 pfn_to_mfn_frame_list;
191 } arch_shared_info_t;
193 #endif /* !__ASSEMBLY__ */
195 #endif