This stack check implementation leverages the compiler's profiling (gcc -p)
[linux-2.6.git] / include / asm-i386 / desc.h
1 #ifndef __ARCH_DESC_H
2 #define __ARCH_DESC_H
3
4 #include <asm/ldt.h>
5 #include <asm/segment.h>
6
7 #ifndef __ASSEMBLY__
8
9 #include <linux/preempt.h>
10 #include <linux/smp.h>
11
12 #include <asm/mmu.h>
13
14 extern struct desc_struct cpu_gdt_table[NR_CPUS][GDT_ENTRIES];
15
16 struct Xgt_desc_struct {
17         unsigned short size;
18         unsigned long address __attribute__((packed));
19         unsigned short pad;
20 } __attribute__ ((packed));
21
22 extern struct Xgt_desc_struct idt_descr, cpu_gdt_descr[NR_CPUS];
23
24 extern void trap_init_virtual_IDT(void);
25 extern void trap_init_virtual_GDT(void);
26
27 asmlinkage int system_call(void);
28 asmlinkage void lcall7(void);
29 asmlinkage void lcall27(void);
30
31 #define load_TR_desc() __asm__ __volatile__("ltr %%ax"::"a" (GDT_ENTRY_TSS*8))
32 #define load_LDT_desc() __asm__ __volatile__("lldt %%ax"::"a" (GDT_ENTRY_LDT*8))
33
34 /*
35  * This is the ldt that every process will get unless we need
36  * something other than this.
37  */
38 extern struct desc_struct default_ldt[];
39 extern void set_intr_gate(unsigned int irq, void * addr);
40 extern void set_trap_gate(unsigned int n, void *addr);
41
42 #define _set_tssldt_desc(n,addr,limit,type) \
43 __asm__ __volatile__ ("movw %w3,0(%2)\n\t" \
44         "movw %%ax,2(%2)\n\t" \
45         "rorl $16,%%eax\n\t" \
46         "movb %%al,4(%2)\n\t" \
47         "movb %4,5(%2)\n\t" \
48         "movb $0,6(%2)\n\t" \
49         "movb %%ah,7(%2)\n\t" \
50         "rorl $16,%%eax" \
51         : "=m"(*(n)) : "a" (addr), "r"(n), "ir"(limit), "i"(type))
52
53 static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, void *addr)
54 {
55         _set_tssldt_desc(&cpu_gdt_table[cpu][entry], (int)addr, 235, 0x89);
56 }
57
58 #define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
59
60 static inline void set_ldt_desc(unsigned int cpu, void *addr, unsigned int size)
61 {
62         _set_tssldt_desc(&cpu_gdt_table[cpu][GDT_ENTRY_LDT], (int)addr, ((size << 3)-1), 0x82);
63 }
64
65 #define LDT_entry_a(info) \
66         ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
67
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)
79
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    )
89
90 #if TLS_SIZE != 24
91 # error update this code.
92 #endif
93
94 static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
95 {
96 #define C(i) cpu_gdt_table[cpu][GDT_ENTRY_TLS_MIN + i] = t->tls_array[i]
97         C(0); C(1); C(2);
98 #undef C
99 }
100
101 extern struct page *default_ldt_page;
102 extern void load_LDT_nolock(mm_context_t *pc, int cpu);
103
104 static inline void load_LDT(mm_context_t *pc)
105 {
106         int cpu = get_cpu();
107         load_LDT_nolock(pc, cpu);
108         put_cpu();
109 }
110
111 static inline void set_user_cs(struct desc_struct *desc, unsigned long limit)
112 {
113         limit = (limit - 1) / PAGE_SIZE;
114         desc->a = limit & 0xffff;
115         desc->b = (limit & 0xf0000) | 0x00c0fb00;
116 }
117
118 #define load_user_cs_desc(cpu, mm) \
119         cpu_gdt_table[(cpu)][GDT_ENTRY_DEFAULT_USER_CS] = (mm)->context.user_cs
120
121 extern void arch_add_exec_range(struct mm_struct *mm, unsigned long limit);
122 extern void arch_remove_exec_range(struct mm_struct *mm, unsigned long limit);
123 extern void arch_flush_exec_range(struct mm_struct *mm);
124
125
126 #endif /* !__ASSEMBLY__ */
127 #endif