ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/asm-i386/desc.h @ 8401:8ebcbcda3d37

Add and use write_ldt_entry, as seen in later linux kernel versions.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author chris@ubuntu.eng.hq.xensource.com
date Thu Dec 15 16:17:13 2005 -0700 (2005-12-15)
parents 06d84bf87159
children
line source
1 #ifndef __ARCH_DESC_H
2 #define __ARCH_DESC_H
4 #include <asm/ldt.h>
5 #include <asm/segment.h>
7 #define CPU_16BIT_STACK_SIZE 1024
9 #ifndef __ASSEMBLY__
11 #include <linux/preempt.h>
12 #include <linux/smp.h>
14 #include <asm/mmu.h>
16 extern struct desc_struct cpu_gdt_table[NR_CPUS][GDT_ENTRIES];
18 DECLARE_PER_CPU(unsigned char, cpu_16bit_stack[CPU_16BIT_STACK_SIZE]);
20 struct Xgt_desc_struct {
21 unsigned short size;
22 unsigned long address __attribute__((packed));
23 unsigned short pad;
24 } __attribute__ ((packed));
26 extern struct Xgt_desc_struct idt_descr, cpu_gdt_descr[NR_CPUS];
28 #define load_TR_desc() __asm__ __volatile__("ltr %%ax"::"a" (GDT_ENTRY_TSS*8))
29 #define load_LDT_desc() __asm__ __volatile__("lldt %%ax"::"a" (GDT_ENTRY_LDT*8))
31 #define get_cpu_gdt_table(_cpu) ((struct desc_struct *)cpu_gdt_descr[(_cpu)].address)
33 /*
34 * This is the ldt that every process will get unless we need
35 * something other than this.
36 */
37 extern struct desc_struct default_ldt[];
38 extern void set_intr_gate(unsigned int irq, void * addr);
40 #define _set_tssldt_desc(n,addr,limit,type) \
41 __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
42 "movw %%ax,2(%2)\n\t" \
43 "rorl $16,%%eax\n\t" \
44 "movb %%al,4(%2)\n\t" \
45 "movb %4,5(%2)\n\t" \
46 "movb $0,6(%2)\n\t" \
47 "movb %%ah,7(%2)\n\t" \
48 "rorl $16,%%eax" \
49 : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type))
51 static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, void *addr)
52 {
53 _set_tssldt_desc(&get_cpu_gdt_table(cpu)[entry], (int)addr,
54 offsetof(struct tss_struct, __cacheline_filler) - 1, 0x89);
55 }
57 #define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
59 static inline void set_ldt_desc(unsigned int cpu, void *addr, unsigned int size)
60 {
61 _set_tssldt_desc(&get_cpu_gdt_table(cpu)[GDT_ENTRY_LDT],
62 (int)addr, ((size << 3)-1), 0x82);
63 }
65 #define LDT_entry_a(info) \
66 ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
68 #define LDT_entry_b(info) \
69 (((info)->base_addr & 0xff000000) | \
70 (((info)->base_addr & 0x00ff0000) >> 16) | \
71 ((info)->limit & 0xf0000) | \
72 (((info)->read_exec_only ^ 1) << 9) | \
73 ((info)->contents << 10) | \
74 (((info)->seg_not_present ^ 1) << 15) | \
75 ((info)->seg_32bit << 22) | \
76 ((info)->limit_in_pages << 23) | \
77 ((info)->useable << 20) | \
78 0x7000)
80 #define LDT_empty(info) (\
81 (info)->base_addr == 0 && \
82 (info)->limit == 0 && \
83 (info)->contents == 0 && \
84 (info)->read_exec_only == 1 && \
85 (info)->seg_32bit == 0 && \
86 (info)->limit_in_pages == 0 && \
87 (info)->seg_not_present == 1 && \
88 (info)->useable == 0 )
90 extern int write_ldt_entry(void *ldt, int entry, __u32 entry_a, __u32 entry_b);
92 #if TLS_SIZE != 24
93 # error update this code.
94 #endif
96 static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
97 {
98 #define C(i) HYPERVISOR_update_descriptor(virt_to_machine(&get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN + i]), *(u64 *)&t->tls_array[i])
99 C(0); C(1); C(2);
100 #undef C
101 }
103 static inline void clear_LDT(void)
104 {
105 int cpu = get_cpu();
107 /*
108 * NB. We load the default_ldt for lcall7/27 handling on demand, as
109 * it slows down context switching. Noone uses it anyway.
110 */
111 cpu = cpu; /* XXX avoid compiler warning */
112 xen_set_ldt(0UL, 0);
113 put_cpu();
114 }
116 /*
117 * load one particular LDT into the current CPU
118 */
119 static inline void load_LDT_nolock(mm_context_t *pc, int cpu)
120 {
121 void *segments = pc->ldt;
122 int count = pc->size;
124 if (likely(!count))
125 segments = NULL;
127 xen_set_ldt((unsigned long)segments, count);
128 }
130 static inline void load_LDT(mm_context_t *pc)
131 {
132 int cpu = get_cpu();
133 load_LDT_nolock(pc, cpu);
134 put_cpu();
135 }
137 static inline unsigned long get_desc_base(unsigned long *desc)
138 {
139 unsigned long base;
140 base = ((desc[0] >> 16) & 0x0000ffff) |
141 ((desc[1] << 16) & 0x00ff0000) |
142 (desc[1] & 0xff000000);
143 return base;
144 }
146 #endif /* !__ASSEMBLY__ */
148 #endif