13c4dd356SDavid Greenman /*- 23c4dd356SDavid Greenman * Copyright (c) 1993 The Regents of the University of California. 33c4dd356SDavid Greenman * All rights reserved. 43c4dd356SDavid Greenman * 53c4dd356SDavid Greenman * Redistribution and use in source and binary forms, with or without 63c4dd356SDavid Greenman * modification, are permitted provided that the following conditions 73c4dd356SDavid Greenman * are met: 83c4dd356SDavid Greenman * 1. Redistributions of source code must retain the above copyright 93c4dd356SDavid Greenman * notice, this list of conditions and the following disclaimer. 103c4dd356SDavid Greenman * 2. Redistributions in binary form must reproduce the above copyright 113c4dd356SDavid Greenman * notice, this list of conditions and the following disclaimer in the 123c4dd356SDavid Greenman * documentation and/or other materials provided with the distribution. 133c4dd356SDavid Greenman * 3. All advertising materials mentioning features or use of this software 143c4dd356SDavid Greenman * must display the following acknowledgement: 153c4dd356SDavid Greenman * This product includes software developed by the University of 163c4dd356SDavid Greenman * California, Berkeley and its contributors. 173c4dd356SDavid Greenman * 4. Neither the name of the University nor the names of its contributors 183c4dd356SDavid Greenman * may be used to endorse or promote products derived from this software 193c4dd356SDavid Greenman * without specific prior written permission. 203c4dd356SDavid Greenman * 213c4dd356SDavid Greenman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 223c4dd356SDavid Greenman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 233c4dd356SDavid Greenman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 243c4dd356SDavid Greenman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 253c4dd356SDavid Greenman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 263c4dd356SDavid Greenman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 273c4dd356SDavid Greenman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 283c4dd356SDavid Greenman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 293c4dd356SDavid Greenman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 303c4dd356SDavid Greenman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 313c4dd356SDavid Greenman * SUCH DAMAGE. 323c4dd356SDavid Greenman * 33f48bbd5fSBruce Evans * $Id: cpufunc.h,v 1.83 1999/01/08 19:17:45 bde Exp $ 343c4dd356SDavid Greenman */ 353c4dd356SDavid Greenman 365b81b6b3SRodney W. Grimes /* 375b81b6b3SRodney W. Grimes * Functions to provide access to special i386 instructions. 385b81b6b3SRodney W. Grimes */ 395b81b6b3SRodney W. Grimes 406e393973SGarrett Wollman #ifndef _MACHINE_CPUFUNC_H_ 41004bedebSBruce Evans #define _MACHINE_CPUFUNC_H_ 426e393973SGarrett Wollman 43e31fa854SDoug Rabson #define readb(va) (*(volatile u_int8_t *) (va)) 44e31fa854SDoug Rabson #define readw(va) (*(volatile u_int16_t *) (va)) 45e31fa854SDoug Rabson #define readl(va) (*(volatile u_int32_t *) (va)) 46e31fa854SDoug Rabson 47e31fa854SDoug Rabson #define writeb(va, d) (*(volatile u_int8_t *) (va) = (d)) 48e31fa854SDoug Rabson #define writew(va, d) (*(volatile u_int16_t *) (va) = (d)) 49e31fa854SDoug Rabson #define writel(va, d) (*(volatile u_int32_t *) (va) = (d)) 50e31fa854SDoug Rabson 515b81b6b3SRodney W. Grimes #ifdef __GNUC__ 525b81b6b3SRodney W. Grimes 532a32c15fSBruce Evans #ifdef SMP 542a32c15fSBruce Evans #include <machine/lock.h> /* XXX */ 552a32c15fSBruce Evans #endif 562a32c15fSBruce Evans 572a32c15fSBruce Evans #ifdef SWTCH_OPTIM_STATS 582a32c15fSBruce Evans extern int tlb_flush_count; /* XXX */ 592a32c15fSBruce Evans #endif 602a32c15fSBruce Evans 615dbd168eSBruce Evans static __inline void 625dbd168eSBruce Evans breakpoint(void) 63004bedebSBruce Evans { 64004bedebSBruce Evans __asm __volatile("int $3"); 655b81b6b3SRodney W. Grimes } 665b81b6b3SRodney W. Grimes 67004bedebSBruce Evans static __inline void 685b81b6b3SRodney W. Grimes disable_intr(void) 695b81b6b3SRodney W. Grimes { 708966b85cSJohn Dyson __asm __volatile("cli" : : : "memory"); 712a32c15fSBruce Evans #ifdef SMP 7220233f27SSteve Passe MPINTR_LOCK(); 732a32c15fSBruce Evans #endif 745b81b6b3SRodney W. Grimes } 755b81b6b3SRodney W. Grimes 76004bedebSBruce Evans static __inline void 775b81b6b3SRodney W. Grimes enable_intr(void) 785b81b6b3SRodney W. Grimes { 792a32c15fSBruce Evans #ifdef SMP 8020233f27SSteve Passe MPINTR_UNLOCK(); 812a32c15fSBruce Evans #endif 82fadc51bdSBruce Evans __asm __volatile("sti"); 835b81b6b3SRodney W. Grimes } 845b81b6b3SRodney W. Grimes 85004bedebSBruce Evans #define HAVE_INLINE_FFS 86004bedebSBruce Evans 87004bedebSBruce Evans static __inline int 88004bedebSBruce Evans ffs(int mask) 89004bedebSBruce Evans { 90004bedebSBruce Evans int result; 91004bedebSBruce Evans /* 92004bedebSBruce Evans * bsfl turns out to be not all that slow on 486's. It can beaten 93004bedebSBruce Evans * using a binary search to reduce to 4 bits and then a table lookup, 94004bedebSBruce Evans * but only if the code is inlined and in the cache, and the code 95004bedebSBruce Evans * is quite large so inlining it probably busts the cache. 96004bedebSBruce Evans * 97004bedebSBruce Evans * Note that gcc-2's builtin ffs would be used if we didn't declare 98004bedebSBruce Evans * this inline or turn off the builtin. The builtin is faster but 99004bedebSBruce Evans * broken in gcc-2.4.5 and slower but working in gcc-2.5 and 2.6. 100004bedebSBruce Evans */ 101004bedebSBruce Evans __asm __volatile("testl %0,%0; je 1f; bsfl %0,%0; incl %0; 1:" 102004bedebSBruce Evans : "=r" (result) : "0" (mask)); 103004bedebSBruce Evans return (result); 104004bedebSBruce Evans } 105004bedebSBruce Evans 10613f588f8SGarrett Wollman #define HAVE_INLINE_FLS 10713f588f8SGarrett Wollman 10813f588f8SGarrett Wollman static __inline int 10913f588f8SGarrett Wollman fls(int mask) 11013f588f8SGarrett Wollman { 11113f588f8SGarrett Wollman int result; 11213f588f8SGarrett Wollman __asm __volatile("testl %0,%0; je 1f; bsrl %0,%0; incl %0; 1:" 11313f588f8SGarrett Wollman : "=r" (result) : "0" (mask)); 11413f588f8SGarrett Wollman return (result); 11513f588f8SGarrett Wollman } 11613f588f8SGarrett Wollman 117004bedebSBruce Evans #if __GNUC__ < 2 118004bedebSBruce Evans 119004bedebSBruce Evans #define inb(port) inbv(port) 120004bedebSBruce Evans #define outb(port, data) outbv(port, data) 121004bedebSBruce Evans 122004bedebSBruce Evans #else /* __GNUC >= 2 */ 123004bedebSBruce Evans 124004bedebSBruce Evans /* 1258089a043SBruce Evans * The following complications are to get around gcc not having a 1268089a043SBruce Evans * constraint letter for the range 0..255. We still put "d" in the 1278089a043SBruce Evans * constraint because "i" isn't a valid constraint when the port 1288089a043SBruce Evans * isn't constant. This only matters for -O0 because otherwise 1298089a043SBruce Evans * the non-working version gets optimized away. 1308089a043SBruce Evans * 131004bedebSBruce Evans * Use an expression-statement instead of a conditional expression 132004bedebSBruce Evans * because gcc-2.6.0 would promote the operands of the conditional 133004bedebSBruce Evans * and produce poor code for "if ((inb(var) & const1) == const2)". 134388dfa71SBruce Evans * 135388dfa71SBruce Evans * The unnecessary test `(port) < 0x10000' is to generate a warning if 136388dfa71SBruce Evans * the `port' has type u_short or smaller. Such types are pessimal. 137388dfa71SBruce Evans * This actually only works for signed types. The range check is 138388dfa71SBruce Evans * careful to avoid generating warnings. 139004bedebSBruce Evans */ 140388dfa71SBruce Evans #define inb(port) __extension__ ({ \ 141004bedebSBruce Evans u_char _data; \ 142388dfa71SBruce Evans if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ 143388dfa71SBruce Evans && (port) < 0x10000) \ 144004bedebSBruce Evans _data = inbc(port); \ 145004bedebSBruce Evans else \ 146004bedebSBruce Evans _data = inbv(port); \ 147004bedebSBruce Evans _data; }) 148004bedebSBruce Evans 149388dfa71SBruce Evans #define outb(port, data) ( \ 150388dfa71SBruce Evans __builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ 151388dfa71SBruce Evans && (port) < 0x10000 \ 152004bedebSBruce Evans ? outbc(port, data) : outbv(port, data)) 153004bedebSBruce Evans 154004bedebSBruce Evans static __inline u_char 155004bedebSBruce Evans inbc(u_int port) 156004bedebSBruce Evans { 157004bedebSBruce Evans u_char data; 158004bedebSBruce Evans 1598089a043SBruce Evans __asm __volatile("inb %1,%0" : "=a" (data) : "id" ((u_short)(port))); 160004bedebSBruce Evans return (data); 161004bedebSBruce Evans } 162004bedebSBruce Evans 163004bedebSBruce Evans static __inline void 164004bedebSBruce Evans outbc(u_int port, u_char data) 165004bedebSBruce Evans { 1668089a043SBruce Evans __asm __volatile("outb %0,%1" : : "a" (data), "id" ((u_short)(port))); 167004bedebSBruce Evans } 168004bedebSBruce Evans 169004bedebSBruce Evans #endif /* __GNUC <= 2 */ 170004bedebSBruce Evans 171004bedebSBruce Evans static __inline u_char 172004bedebSBruce Evans inbv(u_int port) 173004bedebSBruce Evans { 174004bedebSBruce Evans u_char data; 175004bedebSBruce Evans /* 176004bedebSBruce Evans * We use %%dx and not %1 here because i/o is done at %dx and not at 177004bedebSBruce Evans * %edx, while gcc generates inferior code (movw instead of movl) 178004bedebSBruce Evans * if we tell it to load (u_short) port. 179004bedebSBruce Evans */ 180004bedebSBruce Evans __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port)); 181004bedebSBruce Evans return (data); 182004bedebSBruce Evans } 183004bedebSBruce Evans 18400be8601SBruce Evans static __inline u_int 185004bedebSBruce Evans inl(u_int port) 186004bedebSBruce Evans { 18700be8601SBruce Evans u_int data; 188004bedebSBruce Evans 189004bedebSBruce Evans __asm __volatile("inl %%dx,%0" : "=a" (data) : "d" (port)); 190004bedebSBruce Evans return (data); 191004bedebSBruce Evans } 192004bedebSBruce Evans 193004bedebSBruce Evans static __inline void 194004bedebSBruce Evans insb(u_int port, void *addr, size_t cnt) 195004bedebSBruce Evans { 196004bedebSBruce Evans __asm __volatile("cld; rep; insb" 197004bedebSBruce Evans : : "d" (port), "D" (addr), "c" (cnt) 198004bedebSBruce Evans : "di", "cx", "memory"); 199004bedebSBruce Evans } 200004bedebSBruce Evans 201004bedebSBruce Evans static __inline void 202004bedebSBruce Evans insw(u_int port, void *addr, size_t cnt) 203004bedebSBruce Evans { 204004bedebSBruce Evans __asm __volatile("cld; rep; insw" 205004bedebSBruce Evans : : "d" (port), "D" (addr), "c" (cnt) 206004bedebSBruce Evans : "di", "cx", "memory"); 207004bedebSBruce Evans } 208004bedebSBruce Evans 209004bedebSBruce Evans static __inline void 210004bedebSBruce Evans insl(u_int port, void *addr, size_t cnt) 211004bedebSBruce Evans { 212004bedebSBruce Evans __asm __volatile("cld; rep; insl" 213004bedebSBruce Evans : : "d" (port), "D" (addr), "c" (cnt) 214004bedebSBruce Evans : "di", "cx", "memory"); 215004bedebSBruce Evans } 216004bedebSBruce Evans 217ece15d78SBruce Evans static __inline void 2184c024bbdSKATO Takenori invd(void) 2194c024bbdSKATO Takenori { 2204c024bbdSKATO Takenori __asm __volatile("invd"); 2214c024bbdSKATO Takenori } 2224c024bbdSKATO Takenori 223f48bbd5fSBruce Evans #if defined(SMP) && defined(KERNEL) 224477a642cSPeter Wemm 225477a642cSPeter Wemm /* 226f48bbd5fSBruce Evans * When using APIC IPI's, invlpg() is not simply the invlpg instruction 227f48bbd5fSBruce Evans * (this is a bug) and the inlining cost is prohibitive since the call 228f40e6078SPeter Wemm * executes into the IPI transmission system. 229477a642cSPeter Wemm */ 230477a642cSPeter Wemm void invlpg __P((u_int addr)); 231477a642cSPeter Wemm void invltlb __P((void)); 232477a642cSPeter Wemm 2335498a452SJohn Dyson static __inline void 2345498a452SJohn Dyson cpu_invlpg(void *addr) 2355498a452SJohn Dyson { 2365498a452SJohn Dyson __asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory"); 2375498a452SJohn Dyson } 2385498a452SJohn Dyson 2395931a9c2STor Egge static __inline void 2405931a9c2STor Egge cpu_invltlb(void) 2415931a9c2STor Egge { 24200be8601SBruce Evans u_int temp; 2435931a9c2STor Egge /* 2445931a9c2STor Egge * This should be implemented as load_cr3(rcr3()) when load_cr3() 2455931a9c2STor Egge * is inlined. 2465931a9c2STor Egge */ 2475931a9c2STor Egge __asm __volatile("movl %%cr3, %0; movl %0, %%cr3" : "=r" (temp) 2485931a9c2STor Egge : : "memory"); 2495931a9c2STor Egge #if defined(SWTCH_OPTIM_STATS) 2505931a9c2STor Egge ++tlb_flush_count; 2515931a9c2STor Egge #endif 2525931a9c2STor Egge } 253f48bbd5fSBruce Evans 254f48bbd5fSBruce Evans #else /* !(SMP && KERNEL) */ 255477a642cSPeter Wemm 2564c024bbdSKATO Takenori static __inline void 257471176aaSJohn Dyson invlpg(u_int addr) 258ece15d78SBruce Evans { 2595498a452SJohn Dyson __asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory"); 260ece15d78SBruce Evans } 261ece15d78SBruce Evans 262ece15d78SBruce Evans static __inline void 263ece15d78SBruce Evans invltlb(void) 264ece15d78SBruce Evans { 26500be8601SBruce Evans u_int temp; 266ece15d78SBruce Evans /* 267ece15d78SBruce Evans * This should be implemented as load_cr3(rcr3()) when load_cr3() 268ece15d78SBruce Evans * is inlined. 269ece15d78SBruce Evans */ 270ece15d78SBruce Evans __asm __volatile("movl %%cr3, %0; movl %0, %%cr3" : "=r" (temp) 271ece15d78SBruce Evans : : "memory"); 272f48bbd5fSBruce Evans #ifdef SWTCH_OPTIM_STATS 27382566551SJohn Dyson ++tlb_flush_count; 27482566551SJohn Dyson #endif 275ece15d78SBruce Evans } 2762c5d02ffSSteve Passe 277f48bbd5fSBruce Evans #endif /* SMP && KERNEL */ 278ece15d78SBruce Evans 279004bedebSBruce Evans static __inline u_short 280004bedebSBruce Evans inw(u_int port) 281004bedebSBruce Evans { 282004bedebSBruce Evans u_short data; 283004bedebSBruce Evans 284004bedebSBruce Evans __asm __volatile("inw %%dx,%0" : "=a" (data) : "d" (port)); 285004bedebSBruce Evans return (data); 286004bedebSBruce Evans } 287004bedebSBruce Evans 2885dbd168eSBruce Evans static __inline u_int 2890ee893ebSBruce Evans loadandclear(u_int *addr) 2900ee893ebSBruce Evans { 2910ee893ebSBruce Evans u_int result; 2920ee893ebSBruce Evans 2930ee893ebSBruce Evans __asm __volatile("xorl %0,%0; xchgl %1,%0" 29430fd0561SDavid Greenman : "=&r" (result) : "m" (*addr)); 2950ee893ebSBruce Evans return (result); 2960ee893ebSBruce Evans } 2970ee893ebSBruce Evans 298004bedebSBruce Evans static __inline void 299004bedebSBruce Evans outbv(u_int port, u_char data) 300004bedebSBruce Evans { 301004bedebSBruce Evans u_char al; 302004bedebSBruce Evans /* 303004bedebSBruce Evans * Use an unnecessary assignment to help gcc's register allocator. 304004bedebSBruce Evans * This make a large difference for gcc-1.40 and a tiny difference 305004bedebSBruce Evans * for gcc-2.6.0. For gcc-1.40, al had to be ``asm("ax")'' for 306004bedebSBruce Evans * best results. gcc-2.6.0 can't handle this. 307004bedebSBruce Evans */ 308004bedebSBruce Evans al = data; 309004bedebSBruce Evans __asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port)); 310004bedebSBruce Evans } 311004bedebSBruce Evans 312004bedebSBruce Evans static __inline void 31300be8601SBruce Evans outl(u_int port, u_int data) 314004bedebSBruce Evans { 315004bedebSBruce Evans /* 316004bedebSBruce Evans * outl() and outw() aren't used much so we haven't looked at 317004bedebSBruce Evans * possible micro-optimizations such as the unnecessary 318004bedebSBruce Evans * assignment for them. 319004bedebSBruce Evans */ 320004bedebSBruce Evans __asm __volatile("outl %0,%%dx" : : "a" (data), "d" (port)); 321004bedebSBruce Evans } 322004bedebSBruce Evans 323004bedebSBruce Evans static __inline void 324e1a1bba4SJustin T. Gibbs outsb(u_int port, const void *addr, size_t cnt) 325004bedebSBruce Evans { 326004bedebSBruce Evans __asm __volatile("cld; rep; outsb" 327004bedebSBruce Evans : : "d" (port), "S" (addr), "c" (cnt) 328b5ba45f6SDavid Greenman : "si", "cx"); 329004bedebSBruce Evans } 330004bedebSBruce Evans 331004bedebSBruce Evans static __inline void 332e1a1bba4SJustin T. Gibbs outsw(u_int port, const void *addr, size_t cnt) 333004bedebSBruce Evans { 334004bedebSBruce Evans __asm __volatile("cld; rep; outsw" 335004bedebSBruce Evans : : "d" (port), "S" (addr), "c" (cnt) 336b5ba45f6SDavid Greenman : "si", "cx"); 337004bedebSBruce Evans } 338004bedebSBruce Evans 339004bedebSBruce Evans static __inline void 340e1a1bba4SJustin T. Gibbs outsl(u_int port, const void *addr, size_t cnt) 341004bedebSBruce Evans { 342004bedebSBruce Evans __asm __volatile("cld; rep; outsl" 343004bedebSBruce Evans : : "d" (port), "S" (addr), "c" (cnt) 344b5ba45f6SDavid Greenman : "si", "cx"); 345004bedebSBruce Evans } 346004bedebSBruce Evans 347004bedebSBruce Evans static __inline void 348004bedebSBruce Evans outw(u_int port, u_short data) 349004bedebSBruce Evans { 350004bedebSBruce Evans __asm __volatile("outw %0,%%dx" : : "a" (data), "d" (port)); 351004bedebSBruce Evans } 352004bedebSBruce Evans 35300be8601SBruce Evans static __inline u_int 354004bedebSBruce Evans rcr2(void) 355004bedebSBruce Evans { 35600be8601SBruce Evans u_int data; 357004bedebSBruce Evans 358004bedebSBruce Evans __asm __volatile("movl %%cr2,%0" : "=r" (data)); 359004bedebSBruce Evans return (data); 360004bedebSBruce Evans } 361004bedebSBruce Evans 36200be8601SBruce Evans static __inline u_int 363004bedebSBruce Evans read_eflags(void) 3645b81b6b3SRodney W. Grimes { 36500be8601SBruce Evans u_int ef; 366004bedebSBruce Evans 367004bedebSBruce Evans __asm __volatile("pushfl; popl %0" : "=r" (ef)); 3688db02de8SPaul Richards return (ef); 3695b81b6b3SRodney W. Grimes } 3705b81b6b3SRodney W. Grimes 37100be8601SBruce Evans static __inline u_int64_t 3725dbd168eSBruce Evans rdmsr(u_int msr) 3735dbd168eSBruce Evans { 37400be8601SBruce Evans u_int64_t rv; 3755dbd168eSBruce Evans 3765dbd168eSBruce Evans __asm __volatile(".byte 0x0f, 0x32" : "=A" (rv) : "c" (msr)); 3775dbd168eSBruce Evans return (rv); 3785dbd168eSBruce Evans } 3795dbd168eSBruce Evans 38000be8601SBruce Evans static __inline u_int64_t 3815dbd168eSBruce Evans rdpmc(u_int pmc) 3825dbd168eSBruce Evans { 38300be8601SBruce Evans u_int64_t rv; 3845dbd168eSBruce Evans 3855dbd168eSBruce Evans __asm __volatile(".byte 0x0f, 0x33" : "=A" (rv) : "c" (pmc)); 3865dbd168eSBruce Evans return (rv); 3875dbd168eSBruce Evans } 3885dbd168eSBruce Evans 38900be8601SBruce Evans static __inline u_int64_t 3905dbd168eSBruce Evans rdtsc(void) 3915dbd168eSBruce Evans { 39200be8601SBruce Evans u_int64_t rv; 3935dbd168eSBruce Evans 3945dbd168eSBruce Evans __asm __volatile(".byte 0x0f, 0x31" : "=A" (rv)); 3955dbd168eSBruce Evans return (rv); 3965dbd168eSBruce Evans } 3975dbd168eSBruce Evans 398004bedebSBruce Evans static __inline void 399f48bbd5fSBruce Evans setbits(volatile u_int *addr, u_int bits) 4007baccf64SBruce Evans { 401713da3edSJohn Polstra __asm __volatile( 402713da3edSJohn Polstra #ifdef SMP 403713da3edSJohn Polstra "lock; " 404713da3edSJohn Polstra #endif 405713da3edSJohn Polstra "orl %1,%0" : "=m" (*addr) : "ir" (bits)); 4067baccf64SBruce Evans } 4077baccf64SBruce Evans 4087baccf64SBruce Evans static __inline void 4094c024bbdSKATO Takenori wbinvd(void) 4104c024bbdSKATO Takenori { 4114c024bbdSKATO Takenori __asm __volatile("wbinvd"); 4124c024bbdSKATO Takenori } 4134c024bbdSKATO Takenori 4144c024bbdSKATO Takenori static __inline void 41500be8601SBruce Evans write_eflags(u_int ef) 4165b81b6b3SRodney W. Grimes { 417004bedebSBruce Evans __asm __volatile("pushl %0; popfl" : : "r" (ef)); 4185b81b6b3SRodney W. Grimes } 4195b81b6b3SRodney W. Grimes 420d69e8502SGarrett Wollman static __inline void 42100be8601SBruce Evans wrmsr(u_int msr, u_int64_t newval) 422d69e8502SGarrett Wollman { 42328dc3d27SGarrett Wollman __asm __volatile(".byte 0x0f, 0x30" : : "A" (newval), "c" (msr)); 424d69e8502SGarrett Wollman } 425d69e8502SGarrett Wollman 426004bedebSBruce Evans #else /* !__GNUC__ */ 4275b81b6b3SRodney W. Grimes 4285dbd168eSBruce Evans int breakpoint __P((void)); 4295b81b6b3SRodney W. Grimes void disable_intr __P((void)); 4305b81b6b3SRodney W. Grimes void enable_intr __P((void)); 4315b81b6b3SRodney W. Grimes u_char inb __P((u_int port)); 43200be8601SBruce Evans u_int inl __P((u_int port)); 433004bedebSBruce Evans void insb __P((u_int port, void *addr, size_t cnt)); 434004bedebSBruce Evans void insl __P((u_int port, void *addr, size_t cnt)); 435004bedebSBruce Evans void insw __P((u_int port, void *addr, size_t cnt)); 4364c024bbdSKATO Takenori void invd __P((void)); 437ece15d78SBruce Evans void invlpg __P((u_int addr)); 438ece15d78SBruce Evans void invltlb __P((void)); 439004bedebSBruce Evans u_short inw __P((u_int port)); 4400ee893ebSBruce Evans u_int loadandclear __P((u_int *addr)); 441004bedebSBruce Evans void outb __P((u_int port, u_char data)); 44200be8601SBruce Evans void outl __P((u_int port, u_int data)); 443004bedebSBruce Evans void outsb __P((u_int port, void *addr, size_t cnt)); 444004bedebSBruce Evans void outsl __P((u_int port, void *addr, size_t cnt)); 445004bedebSBruce Evans void outsw __P((u_int port, void *addr, size_t cnt)); 446004bedebSBruce Evans void outw __P((u_int port, u_short data)); 44700be8601SBruce Evans u_int rcr2 __P((void)); 44800be8601SBruce Evans u_int64_t rdmsr __P((u_int msr)); 44900be8601SBruce Evans u_int64_t rdpmc __P((u_int pmc)); 45000be8601SBruce Evans u_int64_t rdtsc __P((void)); 45100be8601SBruce Evans u_int read_eflags __P((void)); 452f48bbd5fSBruce Evans void setbits __P((volatile u_int *addr, u_int bits)); 4534c024bbdSKATO Takenori void wbinvd __P((void)); 45400be8601SBruce Evans void write_eflags __P((u_int ef)); 45500be8601SBruce Evans void wrmsr __P((u_int msr, u_int64_t newval)); 456004bedebSBruce Evans 4575b81b6b3SRodney W. Grimes #endif /* __GNUC__ */ 4585b81b6b3SRodney W. Grimes 45900be8601SBruce Evans void load_cr0 __P((u_int cr0)); 46000be8601SBruce Evans void load_cr3 __P((u_int cr3)); 46100be8601SBruce Evans void load_cr4 __P((u_int cr4)); 462004bedebSBruce Evans void ltr __P((u_short sel)); 463aaf08d94SGarrett Wollman u_int rcr0 __P((void)); 46400be8601SBruce Evans u_int rcr3 __P((void)); 46500be8601SBruce Evans u_int rcr4 __P((void)); 4665b81b6b3SRodney W. Grimes 467004bedebSBruce Evans #endif /* !_MACHINE_CPUFUNC_H_ */ 468