1 #define move_to_user_mode() \ 2 __asm__ ("movl %%esp,%%eax\n\t" \ 3 "pushl $0x17\n\t" \ 4 "pushl %%eax\n\t" \ 5 "pushfl\n\t" \ 6 "pushl $0x0f\n\t" \ 7 "pushl $1f\n\t" \ 8 "iret\n" \ 9 "1:\tmovl $0x17,%%eax\n\t" \ 10 "mov %%ax,%%ds\n\t" \ 11 "mov %%ax,%%es\n\t" \ 12 "mov %%ax,%%fs\n\t" \ 13 "mov %%ax,%%gs" \ 14 :::"ax") 15 16 #define sti() __asm__ ("sti"::) 17 #define cli() __asm__ ("cli"::) 18 #define nop() __asm__ ("nop"::) 19 20 #define iret() __asm__ ("iret"::) 21 22 #define _set_gate(gate_addr,type,dpl,addr) \ 23 __asm__ ("movw %%dx,%%ax\n\t" \ 24 "movw %0,%%dx\n\t" \ 25 "movl %%eax,%1\n\t" \ 26 "movl %%edx,%2" \ 27 :: "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \ 28 "m" (*((char *) (gate_addr))), \ 29 "m" (*(4+(char *) (gate_addr))), \ 30 "d" ((char *) (addr)),"a" (0x00080000) \ 31 :"ax","dx") 32 33 #define set_intr_gate(n,addr) \ 34 _set_gate(&idt[n],14,0,addr) 35 36 #define set_trap_gate(n,addr) \ 37 _set_gate(&idt[n],15,0,addr) 38 39 #define set_system_gate(n,addr) \ 40 _set_gate(&idt[n],15,3,addr) 41 42 #define _set_seg_desc(gate_addr,type,dpl,base,limit) {\ 43 *(gate_addr) = ((base) & 0xff000000) | \ 44 (((base) & 0x00ff0000)>>16) | \ 45 ((limit) & 0xf0000) | \ 46 ((dpl)<<13) | \ 47 (0x00408000) | \ 48 ((type)<<8); \ 49 *((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \ 50 ((limit) & 0x0ffff); } 51 52 #define _set_tssldt_desc(n,addr,type) \ 53 __asm__ ("movw $232,%1\n\t" \ 54 "movw %%ax,%2\n\t" \ 55 "rorl $16,%%eax\n\t" \ 56 "movb %%al,%3\n\t" \ 57 "movb $" type ",%4\n\t" \ 58 "movb $0x00,%5\n\t" \ 59 "movb %%ah,%6\n\t" \ 60 "rorl $16,%%eax" \ 61 ::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \ 62 "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \ 63 ) 64 65 #define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),addr,"0x89") 66 #define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),addr,"0x82")