24a524f5e1a279328eb9995429603cc28eebe7b3
5 #include <asm/desc_defs.h>
10 static inline void fill_ldt(struct desc_struct
*desc
,
11 const struct user_desc
*info
)
13 desc
->limit0
= info
->limit
& 0x0ffff;
14 desc
->base0
= info
->base_addr
& 0x0000ffff;
16 desc
->base1
= (info
->base_addr
& 0x00ff0000) >> 16;
17 desc
->type
= (info
->read_exec_only
^ 1) << 1;
18 desc
->type
|= info
->contents
<< 2;
21 desc
->p
= info
->seg_not_present
^ 1;
22 desc
->limit
= (info
->limit
& 0xf0000) >> 16;
23 desc
->avl
= info
->useable
;
24 desc
->d
= info
->seg_32bit
;
25 desc
->g
= info
->limit_in_pages
;
26 desc
->base2
= (info
->base_addr
& 0xff000000) >> 24;
29 extern struct desc_ptr idt_descr
;
30 extern gate_desc idt_table
[];
33 struct desc_struct gdt
[GDT_ENTRIES
];
34 } __attribute__((aligned(PAGE_SIZE
)));
35 DECLARE_PER_CPU(struct gdt_page
, gdt_page
);
37 static inline struct desc_struct
*get_cpu_gdt_table(unsigned int cpu
)
39 return per_cpu(gdt_page
, cpu
).gdt
;
44 static inline void pack_gate(gate_desc
*gate
, unsigned type
, unsigned long func
,
45 unsigned dpl
, unsigned ist
, unsigned seg
)
47 gate
->offset_low
= PTR_LOW(func
);
48 gate
->segment
= __KERNEL_CS
;
55 gate
->offset_middle
= PTR_MIDDLE(func
);
56 gate
->offset_high
= PTR_HIGH(func
);
60 static inline void pack_gate(gate_desc
*gate
, unsigned char type
,
61 unsigned long base
, unsigned dpl
, unsigned flags
,
64 gate
->a
= (seg
<< 16) | (base
& 0xffff);
65 gate
->b
= (base
& 0xffff0000) |
66 (((0x80 | type
| (dpl
<< 5)) & 0xff) << 8);
71 static inline int desc_empty(const void *ptr
)
73 const u32
*desc
= ptr
;
74 return !(desc
[0] | desc
[1]);
77 #ifdef CONFIG_PARAVIRT
78 #include <asm/paravirt.h>
80 #define load_TR_desc() native_load_tr_desc()
81 #define load_gdt(dtr) native_load_gdt(dtr)
82 #define load_idt(dtr) native_load_idt(dtr)
83 #define load_tr(tr) asm volatile("ltr %0"::"m" (tr))
84 #define load_ldt(ldt) asm volatile("lldt %0"::"m" (ldt))
86 #define store_gdt(dtr) native_store_gdt(dtr)
87 #define store_idt(dtr) native_store_idt(dtr)
88 #define store_tr(tr) (tr = native_store_tr())
89 #define store_ldt(ldt) asm("sldt %0":"=m" (ldt))
91 #define load_TLS(t, cpu) native_load_tls(t, cpu)
92 #define set_ldt native_set_ldt
94 #define write_ldt_entry(dt, entry, desc) \
95 native_write_ldt_entry(dt, entry, desc)
96 #define write_gdt_entry(dt, entry, desc, type) \
97 native_write_gdt_entry(dt, entry, desc, type)
98 #define write_idt_entry(dt, entry, g) \
99 native_write_idt_entry(dt, entry, g)
101 static inline void paravirt_alloc_ldt(struct desc_struct
*ldt
, unsigned entries
)
105 static inline void paravirt_free_ldt(struct desc_struct
*ldt
, unsigned entries
)
108 #endif /* CONFIG_PARAVIRT */
110 static inline void native_write_idt_entry(gate_desc
*idt
, int entry
,
111 const gate_desc
*gate
)
113 memcpy(&idt
[entry
], gate
, sizeof(*gate
));
116 static inline void native_write_ldt_entry(struct desc_struct
*ldt
, int entry
,
119 memcpy(&ldt
[entry
], desc
, 8);
122 static inline void native_write_gdt_entry(struct desc_struct
*gdt
, int entry
,
123 const void *desc
, int type
)
128 size
= sizeof(tss_desc
);
131 size
= sizeof(ldt_desc
);
134 size
= sizeof(struct desc_struct
);
137 memcpy(&gdt
[entry
], desc
, size
);
140 static inline void pack_descriptor(struct desc_struct
*desc
, unsigned long base
,
141 unsigned long limit
, unsigned char type
,
144 desc
->a
= ((base
& 0xffff) << 16) | (limit
& 0xffff);
145 desc
->b
= (base
& 0xff000000) | ((base
& 0xff0000) >> 16) |
146 (limit
& 0x000f0000) | ((type
& 0xff) << 8) |
147 ((flags
& 0xf) << 20);
152 static inline void set_tssldt_descriptor(void *d
, unsigned long addr
,
153 unsigned type
, unsigned size
)
156 struct ldttss_desc64
*desc
= d
;
157 memset(desc
, 0, sizeof(*desc
));
158 desc
->limit0
= size
& 0xFFFF;
159 desc
->base0
= PTR_LOW(addr
);
160 desc
->base1
= PTR_MIDDLE(addr
) & 0xFF;
163 desc
->limit1
= (size
>> 16) & 0xF;
164 desc
->base2
= (PTR_MIDDLE(addr
) >> 8) & 0xFF;
165 desc
->base3
= PTR_HIGH(addr
);
167 pack_descriptor((struct desc_struct
*)d
, addr
, size
, 0x80 | type
, 0);
171 static inline void __set_tss_desc(unsigned cpu
, unsigned int entry
, void *addr
)
173 struct desc_struct
*d
= get_cpu_gdt_table(cpu
);
177 * sizeof(unsigned long) coming from an extra "long" at the end
178 * of the iobitmap. See tss_struct definition in processor.h
180 * -1? seg base+limit should be pointing to the address of the
183 set_tssldt_descriptor(&tss
, (unsigned long)addr
, DESC_TSS
,
184 IO_BITMAP_OFFSET
+ IO_BITMAP_BYTES
+
185 sizeof(unsigned long) - 1);
186 write_gdt_entry(d
, entry
, &tss
, DESC_TSS
);
189 #define set_tss_desc(cpu, addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
191 static inline void native_set_ldt(const void *addr
, unsigned int entries
)
193 if (likely(entries
== 0))
194 asm volatile("lldt %w0"::"q" (0));
196 unsigned cpu
= smp_processor_id();
199 set_tssldt_descriptor(&ldt
, (unsigned long)addr
, DESC_LDT
,
200 entries
* LDT_ENTRY_SIZE
- 1);
201 write_gdt_entry(get_cpu_gdt_table(cpu
), GDT_ENTRY_LDT
,
203 asm volatile("lldt %w0"::"q" (GDT_ENTRY_LDT
*8));
207 static inline void native_load_tr_desc(void)
209 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS
*8));
212 static inline void native_load_gdt(const struct desc_ptr
*dtr
)
214 asm volatile("lgdt %0"::"m" (*dtr
));
217 static inline void native_load_idt(const struct desc_ptr
*dtr
)
219 asm volatile("lidt %0"::"m" (*dtr
));
222 static inline void native_store_gdt(struct desc_ptr
*dtr
)
224 asm volatile("sgdt %0":"=m" (*dtr
));
227 static inline void native_store_idt(struct desc_ptr
*dtr
)
229 asm volatile("sidt %0":"=m" (*dtr
));
232 static inline unsigned long native_store_tr(void)
235 asm volatile("str %0":"=r" (tr
));
239 static inline void native_load_tls(struct thread_struct
*t
, unsigned int cpu
)
242 struct desc_struct
*gdt
= get_cpu_gdt_table(cpu
);
244 for (i
= 0; i
< GDT_ENTRY_TLS_ENTRIES
; i
++)
245 gdt
[GDT_ENTRY_TLS_MIN
+ i
] = t
->tls_array
[i
];
248 #define _LDT_empty(info) \
249 ((info)->base_addr == 0 && \
250 (info)->limit == 0 && \
251 (info)->contents == 0 && \
252 (info)->read_exec_only == 1 && \
253 (info)->seg_32bit == 0 && \
254 (info)->limit_in_pages == 0 && \
255 (info)->seg_not_present == 1 && \
256 (info)->useable == 0)
259 #define LDT_empty(info) (_LDT_empty(info) && ((info)->lm == 0))
261 #define LDT_empty(info) (_LDT_empty(info))
264 static inline void clear_LDT(void)
270 * load one particular LDT into the current CPU
272 static inline void load_LDT_nolock(mm_context_t
*pc
)
274 set_ldt(pc
->ldt
, pc
->size
);
277 static inline void load_LDT(mm_context_t
*pc
)
284 static inline unsigned long get_desc_base(const struct desc_struct
*desc
)
286 return desc
->base0
| ((desc
->base1
) << 16) | ((desc
->base2
) << 24);
289 static inline unsigned long get_desc_limit(const struct desc_struct
*desc
)
291 return desc
->limit0
| (desc
->limit
<< 16);
294 static inline void _set_gate(int gate
, unsigned type
, void *addr
,
295 unsigned dpl
, unsigned ist
, unsigned seg
)
298 pack_gate(&s
, type
, (unsigned long)addr
, dpl
, ist
, seg
);
300 * does not need to be atomic because it is only done once at
303 write_idt_entry(idt_table
, gate
, &s
);
307 * This needs to use 'idt_table' rather than 'idt', and
308 * thus use the _nonmapped_ version of the IDT, as the
309 * Pentium F0 0F bugfix can have resulted in the mapped
310 * IDT being write-protected.
312 static inline void set_intr_gate(unsigned int n
, void *addr
)
314 BUG_ON((unsigned)n
> 0xFF);
315 _set_gate(n
, GATE_INTERRUPT
, addr
, 0, 0, __KERNEL_CS
);
318 #define SYS_VECTOR_FREE 0
319 #define SYS_VECTOR_ALLOCED 1
321 extern int first_system_vector
;
322 extern char system_vectors
[];
324 static inline void alloc_system_vector(int vector
)
326 if (system_vectors
[vector
] == SYS_VECTOR_FREE
) {
327 system_vectors
[vector
] = SYS_VECTOR_ALLOCED
;
328 if (first_system_vector
> vector
)
329 first_system_vector
= vector
;
334 static inline void alloc_intr_gate(unsigned int n
, void *addr
)
336 alloc_system_vector(n
);
337 set_intr_gate(n
, addr
);
341 * This routine sets up an interrupt gate at directory privilege level 3.
343 static inline void set_system_intr_gate(unsigned int n
, void *addr
)
345 BUG_ON((unsigned)n
> 0xFF);
346 _set_gate(n
, GATE_INTERRUPT
, addr
, 0x3, 0, __KERNEL_CS
);
349 static inline void set_trap_gate(unsigned int n
, void *addr
)
351 BUG_ON((unsigned)n
> 0xFF);
352 _set_gate(n
, GATE_TRAP
, addr
, 0, 0, __KERNEL_CS
);
355 static inline void set_system_gate(unsigned int n
, void *addr
)
357 BUG_ON((unsigned)n
> 0xFF);
359 _set_gate(n
, GATE_TRAP
, addr
, 0x3, 0, __KERNEL_CS
);
361 _set_gate(n
, GATE_INTERRUPT
, addr
, 0x3, 0, __KERNEL_CS
);
365 static inline void set_task_gate(unsigned int n
, unsigned int gdt_entry
)
367 BUG_ON((unsigned)n
> 0xFF);
368 _set_gate(n
, GATE_TASK
, (void *)0, 0, 0, (gdt_entry
<<3));
371 static inline void set_intr_gate_ist(int n
, void *addr
, unsigned ist
)
373 BUG_ON((unsigned)n
> 0xFF);
374 _set_gate(n
, GATE_INTERRUPT
, addr
, 0, ist
, __KERNEL_CS
);
377 static inline void set_system_gate_ist(int n
, void *addr
, unsigned ist
)
379 BUG_ON((unsigned)n
> 0xFF);
380 _set_gate(n
, GATE_INTERRUPT
, addr
, 0x3, ist
, __KERNEL_CS
);
385 * GET_DESC_BASE reads the descriptor base of the specified segment.
388 * idx - descriptor index
390 * base - 32bit register to which the base will be written
391 * lo_w - lo word of the "base" register
392 * lo_b - lo byte of the "base" register
393 * hi_b - hi byte of the low word of the "base" register
396 * GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah)
397 * Will read the base address of GDT_ENTRY_ESPFIX_SS and put it into %eax.
399 #define GET_DESC_BASE(idx, gdt, base, lo_w, lo_b, hi_b) \
400 movb idx * 8 + 4(gdt), lo_b; \
401 movb idx * 8 + 7(gdt), hi_b; \
403 movw idx * 8 + 2(gdt), lo_w;
406 #endif /* __ASSEMBLY__ */
This page took 0.064118 seconds and 4 git commands to generate.