This source file includes following definitions.
- tas
1 #ifndef __ASM_SYSTEM_H
2 #define __ASM_SYSTEM_H
3
4 #define move_to_user_mode() \
5 __asm__ __volatile__ ("movl %%esp,%%eax\n\t" \
6 "pushl $0x17\n\t" \
7 "pushl %%eax\n\t" \
8 "pushfl\n\t" \
9 "pushl $0x0f\n\t" \
10 "pushl $1f\n\t" \
11 "iret\n" \
12 "1:\tmovl $0x17,%%eax\n\t" \
13 "mov %%ax,%%ds\n\t" \
14 "mov %%ax,%%es\n\t" \
15 "mov %%ax,%%fs\n\t" \
16 "mov %%ax,%%gs" \
17 :::"ax")
18
19 #define sti() __asm__ __volatile__ ("sti"::)
20 #define cli() __asm__ __volatile__ ("cli"::)
21 #define nop() __asm__ __volatile__ ("nop"::)
22
23 extern inline int tas(char * m)
24 {
25 char res;
26
27 __asm__("xchgb %0,%1":"=q" (res),"=m" (*m):"0" (0x1));
28 return res;
29 }
30
31 #define save_flags(x) \
32 __asm__ __volatile__("pushfl ; popl %0":"=r" (x))
33
34 #define restore_flags(x) \
35 __asm__ __volatile__("pushl %0 ; popfl"::"r" (x))
36
37 #define iret() __asm__ __volatile__ ("iret"::)
38
39 #define _set_gate(gate_addr,type,dpl,addr) \
40 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
41 "movw %0,%%dx\n\t" \
42 "movl %%eax,%1\n\t" \
43 "movl %%edx,%2" \
44 :: "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
45 "m" (*((char *) (gate_addr))), \
46 "m" (*(4+(char *) (gate_addr))), \
47 "d" ((char *) (addr)),"a" (0x00080000) \
48 :"ax","dx")
49
50 #define set_intr_gate(n,addr) \
51 _set_gate(&idt[n],14,0,addr)
52
53 #define set_trap_gate(n,addr) \
54 _set_gate(&idt[n],15,0,addr)
55
56 #define set_system_gate(n,addr) \
57 _set_gate(&idt[n],15,3,addr)
58
59 #define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
60 *(gate_addr) = ((base) & 0xff000000) | \
61 (((base) & 0x00ff0000)>>16) | \
62 ((limit) & 0xf0000) | \
63 ((dpl)<<13) | \
64 (0x00408000) | \
65 ((type)<<8); \
66 *((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \
67 ((limit) & 0x0ffff); }
68
69 #define _set_tssldt_desc(n,addr,limit,type) \
70 __asm__ __volatile__ ("movw $" #limit ",%1\n\t" \
71 "movw %%ax,%2\n\t" \
72 "rorl $16,%%eax\n\t" \
73 "movb %%al,%3\n\t" \
74 "movb $" type ",%4\n\t" \
75 "movb $0x00,%5\n\t" \
76 "movb %%ah,%6\n\t" \
77 "rorl $16,%%eax" \
78 ::"a" (addr+0xc0000000), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \
79 "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \
80 )
81
82 #define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),231,"0x89")
83 #define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),23,"0x82")
84
85 #endif