debuggers.hg

view xen/include/asm-x86/desc.h @ 3668:d55d523078f7

bitkeeper revision 1.1159.212.77 (4202221693AFbvFZWeMHHIjQfbzTIQ)

More x86_64 prgress. Many more gaps filled in. Next step is DOM0
construction.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Thu Feb 03 13:07:34 2005 +0000 (2005-02-03)
parents 060c1ea52343
children bbe8541361dd
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))
21 #define VALID_CODESEL(_s) ((_s) == FLAT_GUESTOS_CS || VALID_SEL(_s))
23 /* These are bitmasks for the high 32 bits of a descriptor table entry. */
24 #define _SEGMENT_TYPE (15<< 8)
25 #define _SEGMENT_EC ( 1<<10) /* Expand-down or Conforming segment */
26 #define _SEGMENT_CODE ( 1<<11) /* Code (vs data) segment for non-system
27 segments */
28 #define _SEGMENT_S ( 1<<12) /* System descriptor (yes iff S==0) */
29 #define _SEGMENT_DPL ( 3<<13) /* Descriptor Privilege Level */
30 #define _SEGMENT_P ( 1<<15) /* Segment Present */
31 #define _SEGMENT_DB ( 1<<22) /* 16- or 32-bit segment */
32 #define _SEGMENT_G ( 1<<23) /* Granularity */
34 struct desc_struct {
35 u32 a, b;
36 };
38 #if defined(__x86_64__)
40 #define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
41 #define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 2)
43 #define __TSS(n) (((n)<<2) + __FIRST_TSS_ENTRY)
44 #define __LDT(n) (((n)<<2) + __FIRST_LDT_ENTRY)
46 typedef struct {
47 u64 a, b;
48 } idt_entry_t;
50 #define _set_gate(gate_addr,type,dpl,addr) \
51 do { \
52 (gate_addr)->a = \
53 (((unsigned long)(addr) & 0xFFFF0000UL) << 32) | \
54 ((unsigned long)(dpl) << 45) | \
55 ((unsigned long)(type) << 40) | \
56 ((unsigned long)(addr) & 0xFFFFUL) | \
57 ((unsigned long)__HYPERVISOR_CS64 << 16) | \
58 (1UL << 47); \
59 (gate_addr)->b = \
60 ((unsigned long)(addr) >> 32); \
61 } while (0)
63 #define _set_tssldt_desc(desc,addr,limit,type) \
64 do { \
65 (desc)[0].a = \
66 ((u32)(addr) << 16) | ((u32)(limit) & 0xFFFF); \
67 (desc)[0].b = \
68 ((u32)(addr) & 0xFF000000U) | \
69 ((u32)(type) << 8) | 0x8000U | \
70 (((u32)(addr) & 0x00FF0000U) >> 16); \
71 (desc)[1].a = (u32)(((unsigned long)(addr)) >> 32); \
72 (desc)[1].b = 0; \
73 } while (0)
75 #elif defined(__i386__)
77 #define __DOUBLEFAULT_TSS_ENTRY FIRST_RESERVED_GDT_ENTRY
79 #define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
80 #define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 1)
82 #define __TSS(n) (((n)<<1) + __FIRST_TSS_ENTRY)
83 #define __LDT(n) (((n)<<1) + __FIRST_LDT_ENTRY)
85 typedef struct desc_struct idt_entry_t;
87 #define _set_gate(gate_addr,type,dpl,addr) \
88 do { \
89 int __d0, __d1; \
90 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
91 "movw %4,%%dx\n\t" \
92 "movl %%eax,%0\n\t" \
93 "movl %%edx,%1" \
94 :"=m" (*((long *) (gate_addr))), \
95 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
96 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
97 "3" ((char *) (addr)),"2" (__HYPERVISOR_CS << 16)); \
98 } while (0)
100 #define _set_tssldt_desc(n,addr,limit,type) \
101 __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
102 "movw %%ax,2(%2)\n\t" \
103 "rorl $16,%%eax\n\t" \
104 "movb %%al,4(%2)\n\t" \
105 "movb %4,5(%2)\n\t" \
106 "movb $0,6(%2)\n\t" \
107 "movb %%ah,7(%2)\n\t" \
108 "rorl $16,%%eax" \
109 : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type|0x80))
111 #endif
113 extern struct desc_struct gdt_table[];
114 extern struct desc_struct *gdt;
115 extern idt_entry_t *idt;
117 struct Xgt_desc_struct {
118 unsigned short size;
119 unsigned long address __attribute__((packed));
120 };
122 #define idt_descr (*(struct Xgt_desc_struct *)((char *)&idt - 2))
123 #define gdt_descr (*(struct Xgt_desc_struct *)((char *)&gdt - 2))
125 extern void set_intr_gate(unsigned int irq, void * addr);
126 extern void set_system_gate(unsigned int n, void *addr);
127 extern void set_task_gate(unsigned int n, unsigned int sel);
128 extern void set_tss_desc(unsigned int n, void *addr);
130 #endif /* !__ASSEMBLY__ */
131 #endif /* __ARCH_DESC_H */