debuggers.hg

view xen/include/asm-x86/desc.h @ 3659:bf2c38625b39

bitkeeper revision 1.1159.212.72 (42011b79Y7C9nEKFZ5pdQXwp8jC9hw)

More x86/64. Now boot secondary CPUs, but I seem to have problems
executing IRET, so interrupts are fatal.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Wed Feb 02 18:27:05 2005 +0000 (2005-02-02)
parents fd1dd0663b09
children 060c1ea52343
line source
1 #ifndef __ARCH_DESC_H
2 #define __ARCH_DESC_H
3 #ifndef __ASSEMBLY__
5 #define LDT_ENTRY_SIZE 8
7 #define __DOUBLEFAULT_TSS_ENTRY FIRST_RESERVED_GDT_ENTRY
9 #define __FIRST_TSS_ENTRY (FIRST_RESERVED_GDT_ENTRY + 8)
10 #define __FIRST_LDT_ENTRY (__FIRST_TSS_ENTRY + 1)
12 #define __TSS(n) (((n)<<1) + __FIRST_TSS_ENTRY)
13 #define __LDT(n) (((n)<<1) + __FIRST_LDT_ENTRY)
15 #define load_TR(n) __asm__ __volatile__ ("ltr %%ax" : : "a" (__TSS(n)<<3) )
17 /*
18 * Guest OS must provide its own code selectors, or use the one we provide. The
19 * RPL must be 1, as we only create bounce frames to ring 1. Any LDT selector
20 * value is okay. Note that checking only the RPL is insufficient: if the
21 * selector is poked into an interrupt, trap or call gate then the RPL is
22 * ignored when the gate is accessed.
23 */
24 #define VALID_SEL(_s) \
25 (((((_s)>>3) < FIRST_RESERVED_GDT_ENTRY) || \
26 (((_s)>>3) > LAST_RESERVED_GDT_ENTRY) || \
27 ((_s)&4)) && \
28 (((_s)&3) == 1))
30 /* These are bitmasks for the high 32 bits of a descriptor table entry. */
31 #define _SEGMENT_TYPE (15<< 8)
32 #define _SEGMENT_EC ( 1<<10) /* Expand-down or Conforming segment */
33 #define _SEGMENT_CODE ( 1<<11) /* Code (vs data) segment for non-system
34 segments */
35 #define _SEGMENT_S ( 1<<12) /* System descriptor (yes iff S==0) */
36 #define _SEGMENT_DPL ( 3<<13) /* Descriptor Privilege Level */
37 #define _SEGMENT_P ( 1<<15) /* Segment Present */
38 #define _SEGMENT_DB ( 1<<22) /* 16- or 32-bit segment */
39 #define _SEGMENT_G ( 1<<23) /* Granularity */
41 struct desc_struct {
42 u32 a, b;
43 };
45 #if defined(__x86_64__)
47 #define VALID_CODESEL(_s) ((_s) == FLAT_RING3_CS64 || VALID_SEL(_s))
49 typedef struct {
50 u64 a, b;
51 } idt_entry_t;
53 #define _set_gate(gate_addr,type,dpl,addr) \
54 do { \
55 (gate_addr)->a = \
56 (((unsigned long)(addr) & 0xFFFF0000UL) << 32) | \
57 ((unsigned long)(dpl) << 45) | \
58 ((unsigned long)(type) << 40) | \
59 ((unsigned long)(addr) & 0xFFFFUL) | \
60 ((unsigned long)__HYPERVISOR_CS64 << 16) | \
61 (1UL << 47); \
62 (gate_addr)->b = \
63 ((unsigned long)(addr) >> 32); \
64 } while (0)
66 #define _set_tssldt_desc(n,addr,limit,type) ((void)0)
68 #elif defined(__i386__)
70 #define VALID_CODESEL(_s) ((_s) == FLAT_RING1_CS || VALID_SEL(_s))
72 typedef struct desc_struct idt_entry_t;
74 #define _set_gate(gate_addr,type,dpl,addr) \
75 do { \
76 int __d0, __d1; \
77 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
78 "movw %4,%%dx\n\t" \
79 "movl %%eax,%0\n\t" \
80 "movl %%edx,%1" \
81 :"=m" (*((long *) (gate_addr))), \
82 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
83 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
84 "3" ((char *) (addr)),"2" (__HYPERVISOR_CS << 16)); \
85 } while (0)
87 #define _set_tssldt_desc(n,addr,limit,type) \
88 __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
89 "movw %%ax,2(%2)\n\t" \
90 "rorl $16,%%eax\n\t" \
91 "movb %%al,4(%2)\n\t" \
92 "movb %4,5(%2)\n\t" \
93 "movb $0,6(%2)\n\t" \
94 "movb %%ah,7(%2)\n\t" \
95 "rorl $16,%%eax" \
96 : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type))
98 #endif
100 extern struct desc_struct gdt_table[];
101 extern struct desc_struct *gdt;
102 extern idt_entry_t *idt;
104 struct Xgt_desc_struct {
105 unsigned short size;
106 unsigned long address __attribute__((packed));
107 };
109 #define idt_descr (*(struct Xgt_desc_struct *)((char *)&idt - 2))
110 #define gdt_descr (*(struct Xgt_desc_struct *)((char *)&gdt - 2))
112 extern void set_intr_gate(unsigned int irq, void * addr);
113 extern void set_system_gate(unsigned int n, void *addr);
114 extern void set_task_gate(unsigned int n, unsigned int sel);
115 extern void set_tss_desc(unsigned int n, void *addr);
117 #endif /* !__ASSEMBLY__ */
118 #endif /* __ARCH_DESC_H */