debuggers.hg

view xen/include/asm-x86/desc.h @ 3661:060c1ea52343

bitkeeper revision 1.1159.212.73 (420154ceFUvIANCrxSTgPyOjFi1Pag)

More x86_64 work. Interrupts and exceptions are now working. Next step is
DOM0 construction. First part of that is to map rest of physical memory,
allocate and map the mach_to_phys table, and fix arch_init_memory().
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@viper.(none)
date Wed Feb 02 22:31:42 2005 +0000 (2005-02-02)
parents bf2c38625b39
children d55d523078f7
line source
1 #ifndef __ARCH_DESC_H
2 #define __ARCH_DESC_H
3 #ifndef __ASSEMBLY__
5 #define LDT_ENTRY_SIZE 8
7 #define load_TR(n) __asm__ __volatile__ ("ltr %%ax" : : "a" (__TSS(n)<<3) )
9 /*
10 * Guest OS must provide its own code selectors, or use the one we provide. The
11 * RPL must be 1, as we only create bounce frames to ring 1. Any LDT selector
12 * value is okay. Note that checking only the RPL is insufficient: if the
13 * selector is poked into an interrupt, trap or call gate then the RPL is
14 * ignored when the gate is accessed.
15 */
16 #define VALID_SEL(_s) \
17 (((((_s)>>3) < FIRST_RESERVED_GDT_ENTRY) || \
18 (((_s)>>3) > LAST_RESERVED_GDT_ENTRY) || \
19 ((_s)&4)) && \
20 (((_s)&3) == 1))
22 /* These are bitmasks for the high 32 bits of a descriptor table entry. */
23 #define _SEGMENT_TYPE (15<< 8)
24 #define _SEGMENT_EC ( 1<<10) /* Expand-down or Conforming segment */
25 #define _SEGMENT_CODE ( 1<<11) /* Code (vs data) segment for non-system
26 segments */
27 #define _SEGMENT_S ( 1<<12) /* System descriptor (yes iff S==0) */
28 #define _SEGMENT_DPL ( 3<<13) /* Descriptor Privilege Level */
29 #define _SEGMENT_P ( 1<<15) /* Segment Present */
30 #define _SEGMENT_DB ( 1<<22) /* 16- or 32-bit segment */
31 #define _SEGMENT_G ( 1<<23) /* Granularity */
33 struct desc_struct {
34 u32 a, b;
35 };
37 #if defined(__x86_64__)
39 #define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
40 #define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 2)
42 #define __TSS(n) (((n)<<2) + __FIRST_TSS_ENTRY)
43 #define __LDT(n) (((n)<<2) + __FIRST_LDT_ENTRY)
45 #define VALID_CODESEL(_s) ((_s) == FLAT_RING3_CS64 || VALID_SEL(_s))
47 typedef struct {
48 u64 a, b;
49 } idt_entry_t;
51 #define _set_gate(gate_addr,type,dpl,addr) \
52 do { \
53 (gate_addr)->a = \
54 (((unsigned long)(addr) & 0xFFFF0000UL) << 32) | \
55 ((unsigned long)(dpl) << 45) | \
56 ((unsigned long)(type) << 40) | \
57 ((unsigned long)(addr) & 0xFFFFUL) | \
58 ((unsigned long)__HYPERVISOR_CS64 << 16) | \
59 (1UL << 47); \
60 (gate_addr)->b = \
61 ((unsigned long)(addr) >> 32); \
62 } while (0)
64 #define _set_tssldt_desc(desc,addr,limit,type) \
65 do { \
66 (desc)[0].a = \
67 ((u32)(addr) << 16) | ((u32)(limit) & 0xFFFF); \
68 (desc)[0].b = \
69 ((u32)(addr) & 0xFF000000U) | \
70 ((u32)(type) << 8) | 0x8000U | \
71 (((u32)(addr) & 0x00FF0000U) >> 16); \
72 (desc)[1].a = (u32)(((unsigned long)(addr)) >> 32); \
73 (desc)[1].b = 0; \
74 } while (0)
76 #elif defined(__i386__)
78 #define __DOUBLEFAULT_TSS_ENTRY FIRST_RESERVED_GDT_ENTRY
80 #define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
81 #define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 1)
83 #define __TSS(n) (((n)<<1) + __FIRST_TSS_ENTRY)
84 #define __LDT(n) (((n)<<1) + __FIRST_LDT_ENTRY)
86 #define VALID_CODESEL(_s) ((_s) == FLAT_RING1_CS || VALID_SEL(_s))
88 typedef struct desc_struct idt_entry_t;
90 #define _set_gate(gate_addr,type,dpl,addr) \
91 do { \
92 int __d0, __d1; \
93 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
94 "movw %4,%%dx\n\t" \
95 "movl %%eax,%0\n\t" \
96 "movl %%edx,%1" \
97 :"=m" (*((long *) (gate_addr))), \
98 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
99 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
100 "3" ((char *) (addr)),"2" (__HYPERVISOR_CS << 16)); \
101 } while (0)
103 #define _set_tssldt_desc(n,addr,limit,type) \
104 __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
105 "movw %%ax,2(%2)\n\t" \
106 "rorl $16,%%eax\n\t" \
107 "movb %%al,4(%2)\n\t" \
108 "movb %4,5(%2)\n\t" \
109 "movb $0,6(%2)\n\t" \
110 "movb %%ah,7(%2)\n\t" \
111 "rorl $16,%%eax" \
112 : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type|0x80))
114 #endif
116 extern struct desc_struct gdt_table[];
117 extern struct desc_struct *gdt;
118 extern idt_entry_t *idt;
120 struct Xgt_desc_struct {
121 unsigned short size;
122 unsigned long address __attribute__((packed));
123 };
125 #define idt_descr (*(struct Xgt_desc_struct *)((char *)&idt - 2))
126 #define gdt_descr (*(struct Xgt_desc_struct *)((char *)&gdt - 2))
128 extern void set_intr_gate(unsigned int irq, void * addr);
129 extern void set_system_gate(unsigned int n, void *addr);
130 extern void set_task_gate(unsigned int n, unsigned int sel);
131 extern void set_tss_desc(unsigned int n, void *addr);
133 #endif /* !__ASSEMBLY__ */
134 #endif /* __ARCH_DESC_H */