5 #include <asm/segment.h>
9 #include <linux/preempt.h>
10 #include <linux/smp.h>
11 #include <linux/percpu.h>
15 extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];
16 DECLARE_PER_CPU(struct desc_struct, cpu_gdt_table[GDT_ENTRIES]);
18 struct Xgt_desc_struct {
20 unsigned long address __attribute__((packed));
22 } __attribute__ ((packed));
24 extern struct Xgt_desc_struct idt_descr, cpu_gdt_descr[NR_CPUS];
26 #define load_TR_desc() __asm__ __volatile__("ltr %%ax"::"a" (GDT_ENTRY_TSS*8))
27 #define load_LDT_desc() __asm__ __volatile__("lldt %%ax"::"a" (GDT_ENTRY_LDT*8))
30 * This is the ldt that every process will get unless we need
31 * something other than this.
33 extern struct desc_struct default_ldt[];
34 extern void set_intr_gate(unsigned int irq, void * addr);
36 #define _set_tssldt_desc(n,addr,limit,type) \
37 __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
38 "movw %%ax,2(%2)\n\t" \
39 "rorl $16,%%eax\n\t" \
40 "movb %%al,4(%2)\n\t" \
43 "movb %%ah,7(%2)\n\t" \
45 : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type))
47 static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, void *addr)
49 _set_tssldt_desc(&per_cpu(cpu_gdt_table, cpu)[entry], (int)addr,
50 offsetof(struct tss_struct, __cacheline_filler) - 1, 0x89);
53 #define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
55 static inline void set_ldt_desc(unsigned int cpu, void *addr, unsigned int size)
57 _set_tssldt_desc(&per_cpu(cpu_gdt_table, cpu)[GDT_ENTRY_LDT], (int)addr, ((size << 3)-1), 0x82);
60 #define LDT_entry_a(info) \
61 ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
63 #define LDT_entry_b(info) \
64 (((info)->base_addr & 0xff000000) | \
65 (((info)->base_addr & 0x00ff0000) >> 16) | \
66 ((info)->limit & 0xf0000) | \
67 (((info)->read_exec_only ^ 1) << 9) | \
68 ((info)->contents << 10) | \
69 (((info)->seg_not_present ^ 1) << 15) | \
70 ((info)->seg_32bit << 22) | \
71 ((info)->limit_in_pages << 23) | \
72 ((info)->useable << 20) | \
75 #define LDT_empty(info) (\
76 (info)->base_addr == 0 && \
77 (info)->limit == 0 && \
78 (info)->contents == 0 && \
79 (info)->read_exec_only == 1 && \
80 (info)->seg_32bit == 0 && \
81 (info)->limit_in_pages == 0 && \
82 (info)->seg_not_present == 1 && \
83 (info)->useable == 0 )
86 # error update this code.
89 static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
91 #define C(i) per_cpu(cpu_gdt_table, cpu)[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i]
96 static inline void clear_LDT(void)
100 set_ldt_desc(cpu, &default_ldt[0], 5);
106 * load one particular LDT into the current CPU
108 static inline void load_LDT_nolock(mm_context_t *pc, int cpu)
110 void *segments = pc->ldt;
111 int count = pc->size;
113 if (likely(!count)) {
114 segments = &default_ldt[0];
118 set_ldt_desc(cpu, segments, count);
122 static inline void load_LDT(mm_context_t *pc)
125 load_LDT_nolock(pc, cpu);
129 #endif /* !__ASSEMBLY__ */