This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / xen / interface / arch-x86_32.h
1 /******************************************************************************
2  * arch-x86_32.h
3  * 
4  * Guest OS interface to x86 32-bit Xen.
5  * 
6  * Copyright (c) 2004, K A Fraser
7  */
8
9 #ifndef __XEN_PUBLIC_ARCH_X86_32_H__
10 #define __XEN_PUBLIC_ARCH_X86_32_H__
11
12 #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
13     typedef struct { type *p; } __guest_handle_ ## name
14
15 #define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
16 #define XEN_GUEST_HANDLE(name)          __guest_handle_ ## name
17 #define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
18 #ifdef __XEN_TOOLS__
19 #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
20 #endif
21
22 #ifndef __ASSEMBLY__
23 /* Guest handles for primitive C types. */
24 __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
25 __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
26 __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
27 DEFINE_XEN_GUEST_HANDLE(char);
28 DEFINE_XEN_GUEST_HANDLE(int);
29 DEFINE_XEN_GUEST_HANDLE(long);
30 DEFINE_XEN_GUEST_HANDLE(void);
31
32 typedef unsigned long xen_pfn_t;
33 DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
34 #endif
35
36 /*
37  * SEGMENT DESCRIPTOR TABLES
38  */
39 /*
40  * A number of GDT entries are reserved by Xen. These are not situated at the
41  * start of the GDT because some stupid OSes export hard-coded selector values
42  * in their ABI. These hard-coded values are always near the start of the GDT,
43  * so Xen places itself out of the way, at the far end of the GDT.
44  */
45 #define FIRST_RESERVED_GDT_PAGE  14
46 #define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
47 #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
48
49 /*
50  * These flat segments are in the Xen-private section of every GDT. Since these
51  * are also present in the initial GDT, many OSes will be able to avoid
52  * installing their own GDT.
53  */
54 #define FLAT_RING1_CS 0xe019    /* GDT index 259 */
55 #define FLAT_RING1_DS 0xe021    /* GDT index 260 */
56 #define FLAT_RING1_SS 0xe021    /* GDT index 260 */
57 #define FLAT_RING3_CS 0xe02b    /* GDT index 261 */
58 #define FLAT_RING3_DS 0xe033    /* GDT index 262 */
59 #define FLAT_RING3_SS 0xe033    /* GDT index 262 */
60
61 #define FLAT_KERNEL_CS FLAT_RING1_CS
62 #define FLAT_KERNEL_DS FLAT_RING1_DS
63 #define FLAT_KERNEL_SS FLAT_RING1_SS
64 #define FLAT_USER_CS    FLAT_RING3_CS
65 #define FLAT_USER_DS    FLAT_RING3_DS
66 #define FLAT_USER_SS    FLAT_RING3_SS
67
68 /* And the trap vector is... */
69 #define TRAP_INSTR "int $0x82"
70
71 /*
72  * Virtual addresses beyond this are not modifiable by guest OSes. The 
73  * machine->physical mapping table starts at this address, read-only.
74  */
75 #ifdef CONFIG_X86_PAE
76 #define __HYPERVISOR_VIRT_START 0xF5800000
77 #define __MACH2PHYS_VIRT_START  0xF5800000
78 #define __MACH2PHYS_VIRT_END    0xF6800000
79 #else
80 #define __HYPERVISOR_VIRT_START 0xFC000000
81 #define __MACH2PHYS_VIRT_START  0xFC000000
82 #define __MACH2PHYS_VIRT_END    0xFC400000
83 #endif
84
85 #ifndef HYPERVISOR_VIRT_START
86 #define HYPERVISOR_VIRT_START mk_unsigned_long(__HYPERVISOR_VIRT_START)
87 #endif
88
89 #define MACH2PHYS_VIRT_START  mk_unsigned_long(__MACH2PHYS_VIRT_START)
90 #define MACH2PHYS_VIRT_END    mk_unsigned_long(__MACH2PHYS_VIRT_END)
91 #define MACH2PHYS_NR_ENTRIES  ((MACH2PHYS_VIRT_END-MACH2PHYS_VIRT_START)>>2)
92 #ifndef machine_to_phys_mapping
93 #define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
94 #endif
95
96 /* Maximum number of virtual CPUs in multi-processor guests. */
97 #define MAX_VIRT_CPUS 32
98
99 #ifndef __ASSEMBLY__
100
101 typedef unsigned long xen_ulong_t;
102
103 /*
104  * Send an array of these to HYPERVISOR_set_trap_table()
105  */
106 #define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
107 #define TI_GET_IF(_ti)       ((_ti)->flags & 4)
108 #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
109 #define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
110 struct trap_info {
111     uint8_t       vector;  /* exception vector                              */
112     uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
113     uint16_t      cs;      /* code selector                                 */
114     unsigned long address; /* code offset                                   */
115 };
116 typedef struct trap_info trap_info_t;
117 DEFINE_XEN_GUEST_HANDLE(trap_info_t);
118
119 struct cpu_user_regs {
120     uint32_t ebx;
121     uint32_t ecx;
122     uint32_t edx;
123     uint32_t esi;
124     uint32_t edi;
125     uint32_t ebp;
126     uint32_t eax;
127     uint16_t error_code;    /* private */
128     uint16_t entry_vector;  /* private */
129     uint32_t eip;
130     uint16_t cs;
131     uint8_t  saved_upcall_mask;
132     uint8_t  _pad0;
133     uint32_t eflags;        /* eflags.IF == !saved_upcall_mask */
134     uint32_t esp;
135     uint16_t ss, _pad1;
136     uint16_t es, _pad2;
137     uint16_t ds, _pad3;
138     uint16_t fs, _pad4;
139     uint16_t gs, _pad5;
140 };
141 typedef struct cpu_user_regs cpu_user_regs_t;
142 DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
143
144 typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
145
146 /*
147  * The following is all CPU context. Note that the fpu_ctxt block is filled 
148  * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
149  */
150 struct vcpu_guest_context {
151     /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
152     struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
153 #define VGCF_I387_VALID                (1<<0)
154 #define VGCF_HVM_GUEST                 (1<<1)
155 #define VGCF_IN_KERNEL                 (1<<2)
156 #define _VGCF_i387_valid               0
157 #define VGCF_i387_valid                (1<<_VGCF_i387_valid)
158 #define _VGCF_hvm_guest                1
159 #define VGCF_hvm_guest                 (1<<_VGCF_hvm_guest)
160 #define _VGCF_in_kernel                2
161 #define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
162 #define _VGCF_failsafe_disables_events 3
163 #define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
164     unsigned long flags;                    /* VGCF_* flags                 */
165     struct cpu_user_regs user_regs;         /* User-level CPU registers     */
166     struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
167     unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
168     unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
169     unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
170     unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
171     unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
172     unsigned long event_callback_cs;        /* CS:EIP of event callback     */
173     unsigned long event_callback_eip;
174     unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
175     unsigned long failsafe_callback_eip;
176     unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
177 };
178 typedef struct vcpu_guest_context vcpu_guest_context_t;
179 DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
180
181 /*
182  * Page-directory addresses above 4GB do not fit into architectural %cr3.
183  * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
184  * must use the following accessor macros to pack/unpack valid MFNs.
185  */
186 #define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
187 #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
188
189 struct arch_shared_info {
190     unsigned long max_pfn;                  /* max pfn that appears in table */
191     /* Frame containing list of mfns containing list of mfns containing p2m. */
192     xen_pfn_t     pfn_to_mfn_frame_list_list;
193     unsigned long nmi_reason;
194     uint64_t pad[32];
195 };
196 typedef struct arch_shared_info arch_shared_info_t;
197
198 struct arch_vcpu_info {
199     unsigned long cr2;
200     unsigned long pad[5]; /* sizeof(vcpu_info_t) == 64 */
201 };
202 typedef struct arch_vcpu_info arch_vcpu_info_t;
203
204 struct xen_callback {
205     unsigned long cs;
206     unsigned long eip;
207 };
208 typedef struct xen_callback xen_callback_t;
209
210 #endif /* !__ASSEMBLY__ */
211
212 /*
213  * Prefix forces emulation of some non-trapping instructions.
214  * Currently only CPUID.
215  */
216 #ifdef __ASSEMBLY__
217 #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
218 #define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
219 #else
220 #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
221 #define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
222 #endif
223
224 #endif
225
226 /*
227  * Local variables:
228  * mode: C
229  * c-set-style: "BSD"
230  * c-basic-offset: 4
231  * tab-width: 4
232  * indent-tabs-mode: nil
233  * End:
234  */