1 // Routines to let C code use special x86 instructions.
8 asm volatile("in %1,%0" : "=a" (data
) : "d" (port
));
13 insl(int port
, void *addr
, int cnt
)
15 asm volatile("cld; rep insl" :
16 "=D" (addr
), "=c" (cnt
) :
17 "d" (port
), "0" (addr
), "1" (cnt
) :
22 outb(ushort port
, uchar data
)
24 asm volatile("out %0,%1" : : "a" (data
), "d" (port
));
28 outw(ushort port
, ushort data
)
30 asm volatile("out %0,%1" : : "a" (data
), "d" (port
));
34 outsl(int port
, const void *addr
, int cnt
)
36 asm volatile("cld; rep outsl" :
37 "=S" (addr
), "=c" (cnt
) :
38 "d" (port
), "0" (addr
), "1" (cnt
) :
43 stosb(void *addr
, int data
, int cnt
)
45 asm volatile("cld; rep stosb" :
46 "=D" (addr
), "=c" (cnt
) :
47 "0" (addr
), "1" (cnt
), "a" (data
) :
54 lgdt(struct segdesc
*p
, int size
)
56 volatile ushort pd
[3];
60 pd
[2] = (uint
)p
>> 16;
62 asm volatile("lgdt (%0)" : : "r" (pd
));
68 lidt(struct gatedesc
*p
, int size
)
70 volatile ushort pd
[3];
74 pd
[2] = (uint
)p
>> 16;
76 asm volatile("lidt (%0)" : : "r" (pd
));
82 asm volatile("ltr %0" : : "r" (sel
));
89 asm volatile("pushfl; popl %0" : "=r" (eflags
));
96 asm volatile("movw %0, %%gs" : : "r" (v
));
103 asm volatile("movl %%ebp,%0" : "=r" (val
));
111 asm volatile("movl %%esp,%0" : "=r" (val
));
128 xchg(volatile uint
*addr
, uint newval
)
132 // The + in "+m" denotes a read-modify-write operand.
133 asm volatile("lock; xchgl %0, %1" :
134 "+m" (*addr
), "=a" (result
) :
143 asm volatile("movl %0,%%cr0" : : "r" (val
));
150 asm volatile("movl %%cr0,%0" : "=r" (val
));
158 asm volatile("movl %%cr2,%0" : "=r" (val
));
165 asm volatile("movl %0,%%cr3" : : "r" (val
));
172 asm volatile("movl %%cr3,%0" : "=r" (val
));
176 // Layout of the trap frame built on the stack by the
177 // hardware and by trapasm.S, and passed to trap().
179 // registers as pushed by pusha
183 uint oesp
; // useless & ignored
189 // rest of trap frame
200 // below here defined by x86 hardware
207 // below here only when crossing rings, such as from user to kernel