Initial revision
[linux-2.6.git] / include / asm-xen / xen-public / 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 #ifndef PACKED
13 /* GCC-specific way to pack structure definitions (no implicit padding). */
14 #define PACKED __attribute__ ((packed))
15 #endif
16
17 /*
18  * Pointers and other address fields inside interface structures are padded to
19  * 64 bits. This means that field alignments aren't different between 32- and
20  * 64-bit architectures. 
21  */
22 /* NB. Multi-level macro ensures __LINE__ is expanded before concatenation. */
23 #define __MEMORY_PADDING(_X) u32 __pad_ ## _X
24 #define _MEMORY_PADDING(_X)  __MEMORY_PADDING(_X)
25 #define MEMORY_PADDING       _MEMORY_PADDING(__LINE__)
26
27 /*
28  * SEGMENT DESCRIPTOR TABLES
29  */
30 /*
31  * A number of GDT entries are reserved by Xen. These are not situated at the
32  * start of the GDT because some stupid OSes export hard-coded selector values
33  * in their ABI. These hard-coded values are always near the start of the GDT,
34  * so Xen places itself out of the way.
35  * 
36  * NR_RESERVED_GDT_ENTRIES is (8 + 2 * NR_CPUS) Please update this value if 
37  * you increase NR_CPUS or add another GDT entry to gdt_table in x86_32.S
38  *
39  * NB. The reserved range is inclusive (that is, both FIRST_RESERVED_GDT_ENTRY
40  * and LAST_RESERVED_GDT_ENTRY are reserved).
41  */
42 #define NR_RESERVED_GDT_ENTRIES    72
43 #define FIRST_RESERVED_GDT_ENTRY   256
44 #define LAST_RESERVED_GDT_ENTRY    \
45   (FIRST_RESERVED_GDT_ENTRY + NR_RESERVED_GDT_ENTRIES - 1)
46
47
48 /*
49  * These flat segments are in the Xen-private section of every GDT. Since these
50  * are also present in the initial GDT, many OSes will be able to avoid
51  * installing their own GDT.
52  */
53 #define FLAT_RING1_CS 0x0819    /* GDT index 259 */
54 #define FLAT_RING1_DS 0x0821    /* GDT index 260 */
55 #define FLAT_RING1_SS 0x0821    /* GDT index 260 */
56 #define FLAT_RING3_CS 0x082b    /* GDT index 261 */
57 #define FLAT_RING3_DS 0x0833    /* GDT index 262 */
58 #define FLAT_RING3_SS 0x0833    /* GDT index 262 */
59
60 #define FLAT_KERNEL_CS FLAT_RING1_CS
61 #define FLAT_KERNEL_DS FLAT_RING1_DS
62 #define FLAT_KERNEL_SS FLAT_RING1_SS
63 #define FLAT_USER_CS    FLAT_RING3_CS
64 #define FLAT_USER_DS    FLAT_RING3_DS
65 #define FLAT_USER_SS    FLAT_RING3_SS
66
67 /* And the trap vector is... */
68 #define TRAP_INSTR "int $0x82"
69
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 #define HYPERVISOR_VIRT_START (0xFC000000UL)
76 #ifndef machine_to_phys_mapping
77 #define machine_to_phys_mapping ((u32 *)HYPERVISOR_VIRT_START)
78 #endif
79
80 #ifndef __ASSEMBLY__
81
82 /* NB. Both the following are 32 bits each. */
83 typedef unsigned long memory_t;   /* Full-sized pointer/address/memory-size. */
84 typedef unsigned long cpureg_t;   /* Full-sized register.                    */
85
86 /*
87  * Send an array of these to HYPERVISOR_set_trap_table()
88  */
89 #define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
90 #define TI_GET_IF(_ti)       ((_ti)->flags & 4)
91 #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
92 #define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
93 typedef struct {
94     u8       vector;  /* 0: exception vector                              */
95     u8       flags;   /* 1: 0-3: privilege level; 4: clear event enable?  */
96     u16      cs;      /* 2: code selector                                 */
97     memory_t address; /* 4: code address                                  */
98 } PACKED trap_info_t; /* 8 bytes */
99
100 typedef struct xen_regs
101 {
102     u32 ebx;
103     u32 ecx;
104     u32 edx;
105     u32 esi;
106     u32 edi;
107     u32 ebp;
108     u32 eax;
109     u16 error_code;    /* private */
110     u16 entry_vector;  /* private */
111     u32 eip;
112     u32 cs;
113     u32 eflags;
114     u32 esp;
115     u32 ss;
116     u32 es;
117     u32 ds;
118     u32 fs;
119     u32 gs;
120 } PACKED execution_context_t;
121
122 typedef u64 tsc_timestamp_t; /* RDTSC timestamp */
123
124 /*
125  * The following is all CPU context. Note that the i387_ctxt block is filled 
126  * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
127  */
128 typedef struct {
129 #define ECF_I387_VALID (1<<0)
130 #define ECF_VMX_GUEST  (1<<1)
131 #define ECF_IN_KERNEL (1<<2)
132     unsigned long flags;
133     execution_context_t cpu_ctxt;           /* User-level CPU registers     */
134     char          fpu_ctxt[256];            /* User-level FPU registers     */
135     trap_info_t   trap_ctxt[256];           /* Virtual IDT                  */
136     unsigned int  fast_trap_idx;            /* "Fast trap" vector offset    */
137     unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
138     unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
139     unsigned long kernel_ss, kernel_esp;  /* Virtual TSS (only SS1/ESP1)  */
140     unsigned long pt_base;                  /* CR3 (pagetable base)         */
141     unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
142     unsigned long event_callback_cs;        /* CS:EIP of event callback     */
143     unsigned long event_callback_eip;
144     unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
145     unsigned long failsafe_callback_eip;
146     unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
147 } PACKED full_execution_context_t;
148
149 typedef struct {
150     /* MFN of a table of MFNs that make up p2m table */
151     u64 pfn_to_mfn_frame_list;
152 } PACKED arch_shared_info_t;
153
154 typedef struct {
155 } PACKED arch_vcpu_info_t;
156
157 #define ARCH_HAS_FAST_TRAP
158
159 #endif
160
161 #endif