This source file includes following definitions.
- _get_base
- get_limit
- xchg_u8
- xchg_u16
- xchg_u32
- tas
- xchg_ptr
1 #ifndef __ASM_SYSTEM_H
2 #define __ASM_SYSTEM_H
3
4 #include <asm/segment.h>
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #define FIRST_TSS_ENTRY 8
20 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
21 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
22 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
23 #define load_TR(n) __asm__("ltr %%ax": :"a" (_TSS(n)))
24 #define load_ldt(n) __asm__("lldt %%ax": :"a" (_LDT(n)))
25 #define store_TR(n) \
26 __asm__("str %%ax\n\t" \
27 "subl %2,%%eax\n\t" \
28 "shrl $4,%%eax" \
29 :"=a" (n) \
30 :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
31
32
33
34 #define loaddebug(register) \
35 __asm__("movl %0,%%edx\n\t" \
36 "movl %%edx,%%db" #register "\n\t" \
37 : \
38 :"m" (current->debugreg[register]) \
39 :"dx");
40
41
42
43
44
45
46
47
48
49
50 #define switch_to(tsk) do { \
51 __asm__("cli\n\t" \
52 "xchgl %%ecx,"SYMBOL_NAME_STR(current)"\n\t" \
53 "ljmp %0\n\t" \
54 "sti\n\t" \
55 "cmpl %%ecx,"SYMBOL_NAME_STR(last_task_used_math)"\n\t" \
56 "jne 1f\n\t" \
57 "clts\n" \
58 "1:" \
59 : \
60 :"m" (*(((char *)&tsk->tss.tr)-4)), \
61 "c" (tsk) \
62 :"cx"); \
63 \
64 if(current->debugreg[7]){ \
65 loaddebug(0); \
66 loaddebug(1); \
67 loaddebug(2); \
68 loaddebug(3); \
69 loaddebug(6); \
70 } \
71 } while (0)
72
73 #define _set_base(addr,base) \
74 __asm__("movw %%dx,%0\n\t" \
75 "rorl $16,%%edx\n\t" \
76 "movb %%dl,%1\n\t" \
77 "movb %%dh,%2" \
78 : \
79 :"m" (*((addr)+2)), \
80 "m" (*((addr)+4)), \
81 "m" (*((addr)+7)), \
82 "d" (base) \
83 :"dx")
84
85 #define _set_limit(addr,limit) \
86 __asm__("movw %%dx,%0\n\t" \
87 "rorl $16,%%edx\n\t" \
88 "movb %1,%%dh\n\t" \
89 "andb $0xf0,%%dh\n\t" \
90 "orb %%dh,%%dl\n\t" \
91 "movb %%dl,%1" \
92 : \
93 :"m" (*(addr)), \
94 "m" (*((addr)+6)), \
95 "d" (limit) \
96 :"dx")
97
98 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
99 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
100
101 static inline unsigned long _get_base(char * addr)
102 {
103 unsigned long __base;
104 __asm__("movb %3,%%dh\n\t"
105 "movb %2,%%dl\n\t"
106 "shll $16,%%edx\n\t"
107 "movw %1,%%dx"
108 :"=&d" (__base)
109 :"m" (*((addr)+2)),
110 "m" (*((addr)+4)),
111 "m" (*((addr)+7)));
112 return __base;
113 }
114
115 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
116
117 static inline unsigned long get_limit(unsigned long segment)
118 {
119 unsigned long __limit;
120 __asm__("lsll %1,%0"
121 :"=r" (__limit):"r" (segment));
122 return __limit+1;
123 }
124
125 #define nop() __asm__ __volatile__ ("nop")
126
127
128
129
130 #define clts() __asm__ __volatile__ ("clts")
131 #define stts() \
132 __asm__ __volatile__ ( \
133 "movl %%cr0,%%eax\n\t" \
134 "orl $8,%%eax\n\t" \
135 "movl %%eax,%%cr0" \
136 : \
137 : \
138 :"ax")
139
140
141 extern inline unsigned long xchg_u8(char * m, unsigned long val)
142 {
143 __asm__("xchgb %b0,%1":"=q" (val),"=m" (*m):"0" (val):"memory");
144 return val;
145 }
146
147 extern inline unsigned long xchg_u16(short * m, unsigned long val)
148 {
149 __asm__("xchgw %w0,%1":"=r" (val),"=m" (*m):"0" (val):"memory");
150 return val;
151 }
152
153 extern inline unsigned long xchg_u32(int * m, unsigned long val)
154 {
155 __asm__("xchgl %0,%1":"=r" (val),"=m" (*m):"0" (val):"memory");
156 return val;
157 }
158
159 extern inline int tas(char * m)
160 {
161 return xchg_u8(m,1);
162 }
163
164 extern inline void * xchg_ptr(void * m, void * val)
165 {
166 return (void *) xchg_u32(m, (unsigned long) val);
167 }
168
169 #define mb() __asm__ __volatile__ ("" : : :"memory")
170 #define sti() __asm__ __volatile__ ("sti": : :"memory")
171 #define cli() __asm__ __volatile__ ("cli": : :"memory")
172
173 #define save_flags(x) \
174 __asm__ __volatile__("pushfl ; popl %0":"=r" (x): :"memory")
175
176 #define restore_flags(x) \
177 __asm__ __volatile__("pushl %0 ; popfl": :"r" (x):"memory")
178
179 #define iret() __asm__ __volatile__ ("iret": : :"memory")
180
181 #define _set_gate(gate_addr,type,dpl,addr) \
182 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
183 "movw %2,%%dx\n\t" \
184 "movl %%eax,%0\n\t" \
185 "movl %%edx,%1" \
186 :"=m" (*((long *) (gate_addr))), \
187 "=m" (*(1+(long *) (gate_addr))) \
188 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
189 "d" ((char *) (addr)),"a" (KERNEL_CS << 16) \
190 :"ax","dx")
191
192 #define set_intr_gate(n,addr) \
193 _set_gate(&idt[n],14,0,addr)
194
195 #define set_trap_gate(n,addr) \
196 _set_gate(&idt[n],15,0,addr)
197
198 #define set_system_gate(n,addr) \
199 _set_gate(&idt[n],15,3,addr)
200
201 #define set_call_gate(a,addr) \
202 _set_gate(a,12,3,addr)
203
204 #define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
205 *((gate_addr)+1) = ((base) & 0xff000000) | \
206 (((base) & 0x00ff0000)>>16) | \
207 ((limit) & 0xf0000) | \
208 ((dpl)<<13) | \
209 (0x00408000) | \
210 ((type)<<8); \
211 *(gate_addr) = (((base) & 0x0000ffff)<<16) | \
212 ((limit) & 0x0ffff); }
213
214 #define _set_tssldt_desc(n,addr,limit,type) \
215 __asm__ __volatile__ ("movw $" #limit ",%1\n\t" \
216 "movw %%ax,%2\n\t" \
217 "rorl $16,%%eax\n\t" \
218 "movb %%al,%3\n\t" \
219 "movb $" type ",%4\n\t" \
220 "movb $0x00,%5\n\t" \
221 "movb %%ah,%6\n\t" \
222 "rorl $16,%%eax" \
223 : \
224 :"a" (addr+0xc0000000), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \
225 "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \
226 )
227
228 #define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),235,"0x89")
229 #define set_ldt_desc(n,addr,size) \
230 _set_tssldt_desc(((char *) (n)),((int)(addr)),((size << 3) - 1),"0x82")
231
232
233
234
235
236 extern struct desc_struct default_ldt;
237
238
239
240
241 #define HAVE_DISABLE_HLT
242 void disable_hlt(void);
243 void enable_hlt(void);
244
245 #endif