1 #ifndef _ASM_X86_DESC_H
2 #define _ASM_X86_DESC_H
48 static inline struct desc_struct *get_cpu_gdt_table(
unsigned int cpu)
58 gate->offset_low =
PTR_LOW(func);
71 static inline void pack_gate(
gate_desc *gate,
unsigned char type,
72 unsigned long base,
unsigned dpl,
unsigned flags,
75 gate->
a = (seg << 16) | (base & 0xffff);
76 gate->
b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
85 return !(desc[0] | desc[1]);
88 #ifdef CONFIG_PARAVIRT
89 #include <asm/paravirt.h>
91 #define load_TR_desc() native_load_tr_desc()
92 #define load_gdt(dtr) native_load_gdt(dtr)
93 #define load_idt(dtr) native_load_idt(dtr)
94 #define load_tr(tr) asm volatile("ltr %0"::"m" (tr))
95 #define load_ldt(ldt) asm volatile("lldt %0"::"m" (ldt))
97 #define store_gdt(dtr) native_store_gdt(dtr)
98 #define store_idt(dtr) native_store_idt(dtr)
99 #define store_tr(tr) (tr = native_store_tr())
101 #define load_TLS(t, cpu) native_load_tls(t, cpu)
102 #define set_ldt native_set_ldt
104 #define write_ldt_entry(dt, entry, desc) native_write_ldt_entry(dt, entry, desc)
105 #define write_gdt_entry(dt, entry, desc, type) native_write_gdt_entry(dt, entry, desc, type)
106 #define write_idt_entry(dt, entry, g) native_write_idt_entry(dt, entry, g)
117 #define store_ldt(ldt) asm("sldt %0" : "=m"(ldt))
121 memcpy(&idt[entry], gate,
sizeof(*gate));
126 memcpy(&ldt[entry], desc, 8);
137 default: size =
sizeof(*gdt);
break;
140 memcpy(&gdt[entry], desc, size);
143 static inline void pack_descriptor(
struct desc_struct *desc,
unsigned long base,
144 unsigned long limit,
unsigned char type,
147 desc->
a = ((base & 0xffff) << 16) | (limit & 0xffff);
148 desc->
b = (base & 0xff000000) | ((base & 0xff0000) >> 16) |
149 (limit & 0x000f0000) | ((type & 0xff) << 8) |
150 ((flags & 0xf) << 20);
155 static inline void set_tssldt_descriptor(
void *
d,
unsigned long addr,
unsigned type,
unsigned size)
160 memset(desc, 0,
sizeof(*desc));
162 desc->
limit0 = size & 0xFFFF;
167 desc->
limit1 = (size >> 16) & 0xF;
171 pack_descriptor((
struct desc_struct *)d, addr, size, 0x80 | type, 0);
175 static inline void __set_tss_desc(
unsigned cpu,
unsigned int entry,
void *addr)
187 set_tssldt_descriptor(&tss, (
unsigned long)addr,
DESC_TSS,
189 sizeof(
unsigned long) - 1);
193 #define set_tss_desc(cpu, addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
195 static inline void native_set_ldt(
const void *addr,
unsigned int entries)
198 asm volatile(
"lldt %w0"::
"q" (0));
203 set_tssldt_descriptor(&ldt, (
unsigned long)addr,
DESC_LDT,
211 static inline void native_load_tr_desc(
void)
216 static inline void native_load_gdt(
const struct desc_ptr *
dtr)
218 asm volatile(
"lgdt %0"::
"m" (*dtr));
221 static inline void native_load_idt(
const struct desc_ptr *
dtr)
223 asm volatile(
"lidt %0"::
"m" (*dtr));
226 static inline void native_store_gdt(
struct desc_ptr *
dtr)
228 asm volatile(
"sgdt %0":
"=m" (*dtr));
231 static inline void native_store_idt(
struct desc_ptr *
dtr)
233 asm volatile(
"sidt %0":
"=m" (*dtr));
236 static inline unsigned long native_store_tr(
void)
240 asm volatile(
"str %0":
"=r" (tr));
245 static inline void native_load_tls(
struct thread_struct *
t,
unsigned int cpu)
254 #define _LDT_empty(info) \
255 ((info)->base_addr == 0 && \
256 (info)->limit == 0 && \
257 (info)->contents == 0 && \
258 (info)->read_exec_only == 1 && \
259 (info)->seg_32bit == 0 && \
260 (info)->limit_in_pages == 0 && \
261 (info)->seg_not_present == 1 && \
262 (info)->useable == 0)
265 #define LDT_empty(info) (_LDT_empty(info) && ((info)->lm == 0))
267 #define LDT_empty(info) (_LDT_empty(info))
270 static inline void clear_LDT(
void)
290 static inline unsigned long get_desc_base(
const struct desc_struct *desc)
292 return (
unsigned)(desc->
base0 | ((desc->
base1) << 16) | ((desc->
base2) << 24));
295 static inline void set_desc_base(
struct desc_struct *desc,
unsigned long base)
297 desc->
base0 = base & 0xffff;
298 desc->
base1 = (base >> 16) & 0xff;
299 desc->
base2 = (base >> 24) & 0xff;
302 static inline unsigned long get_desc_limit(
const struct desc_struct *desc)
307 static inline void set_desc_limit(
struct desc_struct *desc,
unsigned long limit)
309 desc->
limit0 = limit & 0xffff;
310 desc->
limit = (limit >> 16) & 0xf;
314 static inline void set_nmi_gate(
int gate,
void *addr)
323 static inline void _set_gate(
int gate,
unsigned type,
void *addr,
324 unsigned dpl,
unsigned ist,
unsigned seg)
328 pack_gate(&s, type, (
unsigned long)addr, dpl, ist, seg);
342 static inline void set_intr_gate(
unsigned int n,
void *addr)
344 BUG_ON((
unsigned)n > 0xFF);
352 static inline void alloc_system_vector(
int vector)
354 if (!
test_bit(vector, used_vectors)) {
356 if (first_system_vector > vector)
357 first_system_vector =
vector;
363 static inline void alloc_intr_gate(
unsigned int n,
void *addr)
365 alloc_system_vector(n);
366 set_intr_gate(n, addr);
372 static inline void set_system_intr_gate(
unsigned int n,
void *addr)
374 BUG_ON((
unsigned)n > 0xFF);
378 static inline void set_system_trap_gate(
unsigned int n,
void *addr)
380 BUG_ON((
unsigned)n > 0xFF);
384 static inline void set_trap_gate(
unsigned int n,
void *addr)
386 BUG_ON((
unsigned)n > 0xFF);
390 static inline void set_task_gate(
unsigned int n,
unsigned int gdt_entry)
392 BUG_ON((
unsigned)n > 0xFF);
393 _set_gate(n,
GATE_TASK, (
void *)0, 0, 0, (gdt_entry<<3));
396 static inline void set_intr_gate_ist(
int n,
void *addr,
unsigned ist)
398 BUG_ON((
unsigned)n > 0xFF);
402 static inline void set_system_intr_gate_ist(
int n,
void *addr,
unsigned ist)
404 BUG_ON((
unsigned)n > 0xFF);