a0d21f80a1a222d4f4a080fa9c58360a38e9f206
[dragonfly.git] / sys / cpu / amd64 / include / cpufunc.h
1 /*-
2  * Copyright (c) 2003 Peter Wemm.
3  * Copyright (c) 1993 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by the University of
17  *      California, Berkeley and its contributors.
18  * 4. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $FreeBSD: src/sys/amd64/include/cpufunc.h,v 1.139 2004/01/28 23:53:04 peter Exp $
35  * $DragonFly: src/sys/cpu/amd64/include/cpufunc.h,v 1.2 2007/09/23 04:29:30 yanyh Exp $
36  */
37
38 /*
39  * Functions to provide access to special i386 instructions.
40  * This in included in sys/systm.h, and that file should be
41  * used in preference to this.
42  */
43
44 #ifndef _CPU_CPUFUNC_H_
45 #define _CPU_CPUFUNC_H_
46
47 #include <sys/cdefs.h>
48 #include <machine/psl.h>
49
50 struct thread;
51 struct region_descriptor;
52
53 __BEGIN_DECLS
54 #define readb(va)       (*(volatile u_int8_t *) (va))
55 #define readw(va)       (*(volatile u_int16_t *) (va))
56 #define readl(va)       (*(volatile u_int32_t *) (va))
57 #define readq(va)       (*(volatile u_int64_t *) (va))
58
59 #define writeb(va, d)   (*(volatile u_int8_t *) (va) = (d))
60 #define writew(va, d)   (*(volatile u_int16_t *) (va) = (d))
61 #define writel(va, d)   (*(volatile u_int32_t *) (va) = (d))
62 #define writeq(va, d)   (*(volatile u_int64_t *) (va) = (d))
63
64 #ifdef  __GNUC__
65
66 static __inline void
67 breakpoint(void)
68 {
69         __asm __volatile("int $3");
70 }
71
72 static __inline void
73 cpu_pause(void)
74 {
75         __asm __volatile("pause");
76 }
77
78 static __inline u_int
79 bsfl(u_int mask)
80 {
81         u_int   result;
82
83         __asm __volatile("bsfl %1,%0" : "=r" (result) : "rm" (mask));
84         return (result);
85 }
86
87 static __inline u_long
88 bsfq(u_long mask)
89 {
90         u_long  result;
91
92         __asm __volatile("bsfq %1,%0" : "=r" (result) : "rm" (mask));
93         return (result);
94 }
95
96 static __inline u_int
97 bsrl(u_int mask)
98 {
99         u_int   result;
100
101         __asm __volatile("bsrl %1,%0" : "=r" (result) : "rm" (mask));
102         return (result);
103 }
104
105 static __inline u_long
106 bsrq(u_long mask)
107 {
108         u_long  result;
109
110         __asm __volatile("bsrq %1,%0" : "=r" (result) : "rm" (mask));
111         return (result);
112 }
113
114 static __inline void
115 disable_intr(void)
116 {
117         __asm __volatile("cli" : : : "memory");
118 }
119
120 static __inline void
121 do_cpuid(u_int ax, u_int *p)
122 {
123         __asm __volatile("cpuid"
124                          : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
125                          :  "0" (ax));
126 }
127
128 static __inline void
129 cpu_enable_intr(void)
130 {
131         __asm __volatile("sti");
132 }
133
134 /*
135  * Cpu and compiler memory ordering fence.  mfence ensures strong read and
136  * write ordering.
137  *
138  * A serializing or fence instruction is required here.  A locked bus
139  * cycle on data for which we already own cache mastership is the most
140  * portable.
141  */
142 static __inline void
143 cpu_mfence(void)
144 {
145 #ifdef SMP
146         __asm __volatile("lock; addl $0,(%%esp)" : : : "memory");
147 #else
148         __asm __volatile("" : : : "memory");
149 #endif
150 }
151
152 /*
153  * cpu_lfence() ensures strong read ordering for reads issued prior
154  * to the instruction verses reads issued afterwords.
155  *
156  * A serializing or fence instruction is required here.  A locked bus
157  * cycle on data for which we already own cache mastership is the most
158  * portable.
159  */
160 static __inline void
161 cpu_lfence(void)
162 {
163 #ifdef SMP
164         __asm __volatile("lock; addl $0,(%%esp)" : : : "memory");
165 #else
166         __asm __volatile("" : : : "memory");
167 #endif
168 }
169
170 /*
171  * cpu_sfence() ensures strong write ordering for writes issued prior
172  * to the instruction verses writes issued afterwords.  Writes are
173  * ordered on intel cpus so we do not actually have to do anything.
174  */
175 static __inline void
176 cpu_sfence(void)
177 {
178         __asm __volatile("" : : : "memory");
179 }
180
181 /*
182  * cpu_ccfence() prevents the compiler from reordering instructions, in
183  * particular stores, relative to the current cpu.  Use cpu_sfence() if
184  * you need to guarentee ordering by both the compiler and by the cpu.
185  *
186  * This also prevents the compiler from caching memory loads into local
187  * variables across the routine.
188  */
189 static __inline void
190 cpu_ccfence(void)
191 {
192         __asm __volatile("" : : : "memory");
193 }
194
195 #ifdef _KERNEL
196
197 #define HAVE_INLINE_FFS
198
199 static __inline int
200 ffs(int mask)
201 {
202 #if 0
203         /*
204          * Note that gcc-2's builtin ffs would be used if we didn't declare
205          * this inline or turn off the builtin.  The builtin is faster but
206          * broken in gcc-2.4.5 and slower but working in gcc-2.5 and later
207          * versions.
208          */
209         return (mask == 0 ? mask : (int)bsfl((u_int)mask) + 1);
210 #else
211         /* Actually, the above is way out of date.  The builtins use cmov etc */
212         return (__builtin_ffs(mask));
213 #endif
214 }
215
216 #define HAVE_INLINE_FFSL
217
218 static __inline int
219 ffsl(long mask)
220 {
221         return (mask == 0 ? mask : (int)bsfq((u_long)mask) + 1);
222 }
223
224 #define HAVE_INLINE_FLS
225
226 static __inline int
227 fls(int mask)
228 {
229         return (mask == 0 ? mask : (int)bsrl((u_int)mask) + 1);
230 }
231
232 #define HAVE_INLINE_FLSL
233
234 static __inline int
235 flsl(long mask)
236 {
237         return (mask == 0 ? mask : (int)bsrq((u_long)mask) + 1);
238 }
239
240 #endif /* _KERNEL */
241
242 static __inline void
243 halt(void)
244 {
245         __asm __volatile("hlt");
246 }
247
248 /*
249  * The following complications are to get around gcc not having a
250  * constraint letter for the range 0..255.  We still put "d" in the
251  * constraint because "i" isn't a valid constraint when the port
252  * isn't constant.  This only matters for -O0 because otherwise
253  * the non-working version gets optimized away.
254  * 
255  * Use an expression-statement instead of a conditional expression
256  * because gcc-2.6.0 would promote the operands of the conditional
257  * and produce poor code for "if ((inb(var) & const1) == const2)".
258  *
259  * The unnecessary test `(port) < 0x10000' is to generate a warning if
260  * the `port' has type u_short or smaller.  Such types are pessimal.
261  * This actually only works for signed types.  The range check is
262  * careful to avoid generating warnings.
263  */
264 #define inb(port) __extension__ ({                                      \
265         u_char  _data;                                                  \
266         if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100     \
267             && (port) < 0x10000)                                        \
268                 _data = inbc(port);                                     \
269         else                                                            \
270                 _data = inbv(port);                                     \
271         _data; })
272
273 #define outb(port, data) (                                              \
274         __builtin_constant_p(port) && ((port) & 0xffff) < 0x100         \
275         && (port) < 0x10000                                             \
276         ? outbc(port, data) : outbv(port, data))
277
278 static __inline u_char
279 inbc(u_int port)
280 {
281         u_char  data;
282
283         __asm __volatile("inb %1,%0" : "=a" (data) : "id" ((u_short)(port)));
284         return (data);
285 }
286
287 static __inline void
288 outbc(u_int port, u_char data)
289 {
290         __asm __volatile("outb %0,%1" : : "a" (data), "id" ((u_short)(port)));
291 }
292
293 static __inline u_char
294 inbv(u_int port)
295 {
296         u_char  data;
297         /*
298          * We use %%dx and not %1 here because i/o is done at %dx and not at
299          * %edx, while gcc generates inferior code (movw instead of movl)
300          * if we tell it to load (u_short) port.
301          */
302         __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
303         return (data);
304 }
305
306 static __inline u_int
307 inl(u_int port)
308 {
309         u_int   data;
310
311         __asm __volatile("inl %%dx,%0" : "=a" (data) : "d" (port));
312         return (data);
313 }
314
315 static __inline void
316 insb(u_int port, void *addr, size_t cnt)
317 {
318         __asm __volatile("cld; rep; insb"
319                          : "+D" (addr), "+c" (cnt)
320                          : "d" (port)
321                          : "memory");
322 }
323
324 static __inline void
325 insw(u_int port, void *addr, size_t cnt)
326 {
327         __asm __volatile("cld; rep; insw"
328                          : "+D" (addr), "+c" (cnt)
329                          : "d" (port)
330                          : "memory");
331 }
332
333 static __inline void
334 insl(u_int port, void *addr, size_t cnt)
335 {
336         __asm __volatile("cld; rep; insl"
337                          : "+D" (addr), "+c" (cnt)
338                          : "d" (port)
339                          : "memory");
340 }
341
342 static __inline void
343 invd(void)
344 {
345         __asm __volatile("invd");
346 }
347
348 static __inline u_short
349 inw(u_int port)
350 {
351         u_short data;
352
353         __asm __volatile("inw %%dx,%0" : "=a" (data) : "d" (port));
354         return (data);
355 }
356
357 static __inline u_int
358 loadandclear(volatile u_int *addr)
359 {
360         u_int   result;
361
362         __asm __volatile("xorl %0,%0; xchgl %1,%0"
363                         : "=&r" (result) : "m" (*addr));
364         return (result);
365 }
366
367 static __inline void
368 outbv(u_int port, u_char data)
369 {
370         u_char  al;
371         /*
372          * Use an unnecessary assignment to help gcc's register allocator.
373          * This make a large difference for gcc-1.40 and a tiny difference
374          * for gcc-2.6.0.  For gcc-1.40, al had to be ``asm("ax")'' for
375          * best results.  gcc-2.6.0 can't handle this.
376          */
377         al = data;
378         __asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
379 }
380
381 static __inline void
382 outl(u_int port, u_int data)
383 {
384         /*
385          * outl() and outw() aren't used much so we haven't looked at
386          * possible micro-optimizations such as the unnecessary
387          * assignment for them.
388          */
389         __asm __volatile("outl %0,%%dx" : : "a" (data), "d" (port));
390 }
391
392 static __inline void
393 outsb(u_int port, const void *addr, size_t cnt)
394 {
395         __asm __volatile("cld; rep; outsb"
396                          : "+S" (addr), "+c" (cnt)
397                          : "d" (port));
398 }
399
400 static __inline void
401 outsw(u_int port, const void *addr, size_t cnt)
402 {
403         __asm __volatile("cld; rep; outsw"
404                          : "+S" (addr), "+c" (cnt)
405                          : "d" (port));
406 }
407
408 static __inline void
409 outsl(u_int port, const void *addr, size_t cnt)
410 {
411         __asm __volatile("cld; rep; outsl"
412                          : "+S" (addr), "+c" (cnt)
413                          : "d" (port));
414 }
415
416 static __inline void
417 outw(u_int port, u_short data)
418 {
419         __asm __volatile("outw %0,%%dx" : : "a" (data), "d" (port));
420 }
421
422 static __inline void
423 ia32_pause(void)
424 {
425         __asm __volatile("pause");
426 }
427
428 static __inline u_long
429 read_rflags(void)
430 {
431         u_long  rf;
432
433         __asm __volatile("pushfq; popq %0" : "=r" (rf));
434         return (rf);
435 }
436
437 static __inline u_int64_t
438 rdmsr(u_int msr)
439 {
440         u_int32_t low, high;
441
442         __asm __volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr));
443         return (low | ((u_int64_t)high << 32));
444 }
445
446 static __inline u_int64_t
447 rdpmc(u_int pmc)
448 {
449         u_int32_t low, high;
450
451         __asm __volatile("rdpmc" : "=a" (low), "=d" (high) : "c" (pmc));
452         return (low | ((u_int64_t)high << 32));
453 }
454
455 static __inline u_int64_t
456 rdtsc(void)
457 {
458         u_int32_t low, high;
459
460         __asm __volatile("rdtsc" : "=a" (low), "=d" (high));
461         return (low | ((u_int64_t)high << 32));
462 }
463
464 static __inline void
465 wbinvd(void)
466 {
467         __asm __volatile("wbinvd");
468 }
469
470 static __inline void
471 write_rflags(u_long rf)
472 {
473         __asm __volatile("pushq %0;  popfq" : : "r" (rf));
474 }
475
476 static __inline void
477 wrmsr(u_int msr, u_int64_t newval)
478 {
479         u_int32_t low, high;
480
481         low = newval;
482         high = newval >> 32;
483         __asm __volatile("wrmsr" : : "a" (low), "d" (high), "c" (msr));
484 }
485
486 static __inline void
487 load_cr0(u_long data)
488 {
489
490         __asm __volatile("movq %0,%%cr0" : : "r" (data));
491 }
492
493 static __inline u_long
494 rcr0(void)
495 {
496         u_long  data;
497
498         __asm __volatile("movq %%cr0,%0" : "=r" (data));
499         return (data);
500 }
501
502 static __inline u_long
503 rcr2(void)
504 {
505         u_long  data;
506
507         __asm __volatile("movq %%cr2,%0" : "=r" (data));
508         return (data);
509 }
510
511 static __inline void
512 load_cr3(u_long data)
513 {
514
515         __asm __volatile("movq %0,%%cr3" : : "r" (data) : "memory");
516 }
517
518 static __inline u_long
519 rcr3(void)
520 {
521         u_long  data;
522
523         __asm __volatile("movq %%cr3,%0" : "=r" (data));
524         return (data);
525 }
526
527 static __inline void
528 load_cr4(u_long data)
529 {
530         __asm __volatile("movq %0,%%cr4" : : "r" (data));
531 }
532
533 static __inline u_long
534 rcr4(void)
535 {
536         u_long  data;
537
538         __asm __volatile("movq %%cr4,%0" : "=r" (data));
539         return (data);
540 }
541
542 /*
543  * Global TLB flush (except for thise for pages marked PG_G)
544  */
545 static __inline void
546 invltlb(void)
547 {
548
549         load_cr3(rcr3());
550 }
551
552 /*
553  * TLB flush for an individual page (even if it has PG_G).
554  * Only works on 486+ CPUs (i386 does not have PG_G).
555  */
556 static __inline void
557 invlpg(u_long addr)
558 {
559
560         __asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory");
561 }
562
563 static __inline u_int
564 rfs(void)
565 {
566         u_int sel;
567         __asm __volatile("movl %%fs,%0" : "=rm" (sel));
568         return (sel);
569 }
570
571 static __inline u_int
572 rgs(void)
573 {
574         u_int sel;
575         __asm __volatile("movl %%gs,%0" : "=rm" (sel));
576         return (sel);
577 }
578
579 static __inline void
580 load_ds(u_int sel)
581 {
582         __asm __volatile("movl %0,%%ds" : : "rm" (sel));
583 }
584
585 static __inline void
586 load_es(u_int sel)
587 {
588         __asm __volatile("movl %0,%%es" : : "rm" (sel));
589 }
590
591 #ifdef _KERNEL
592 /* This is defined in <machine/specialreg.h> but is too painful to get to */
593 #ifndef MSR_FSBASE
594 #define MSR_FSBASE      0xc0000100
595 #endif
596 static __inline void
597 load_fs(u_int sel)
598 {
599         register u_int32_t fsbase __asm("ecx");
600
601         /* Preserve the fsbase value across the selector load */
602         fsbase = MSR_FSBASE;
603         __asm __volatile("rdmsr; movl %0,%%fs; wrmsr"
604             : : "rm" (sel), "c" (fsbase) : "eax", "edx");
605 }
606
607 #ifndef MSR_GSBASE
608 #define MSR_GSBASE      0xc0000101
609 #endif
610 static __inline void
611 load_gs(u_int sel)
612 {
613         register u_int32_t gsbase __asm("ecx");
614
615         /*
616          * Preserve the gsbase value across the selector load.
617          * Note that we have to disable interrupts because the gsbase
618          * being trashed happens to be the kernel gsbase at the time.
619          */
620         gsbase = MSR_GSBASE;
621         __asm __volatile("pushfq; cli; rdmsr; movl %0,%%gs; wrmsr; popfq"
622             : : "rm" (sel), "c" (gsbase) : "eax", "edx");
623 }
624 #else
625 /* Usable by userland */
626 static __inline void
627 load_fs(u_int sel)
628 {
629         __asm __volatile("movl %0,%%fs" : : "rm" (sel));
630 }
631
632 static __inline void
633 load_gs(u_int sel)
634 {
635         __asm __volatile("movl %0,%%gs" : : "rm" (sel));
636 }
637 #endif
638
639 /* void lidt(struct region_descriptor *addr); */
640 static __inline void
641 lidt(struct region_descriptor *addr)
642 {
643         __asm __volatile("lidt (%0)" : : "r" (addr));
644 }
645
646 /* void lldt(u_short sel); */
647 static __inline void
648 lldt(u_short sel)
649 {
650         __asm __volatile("lldt %0" : : "r" (sel));
651 }
652
653 /* void ltr(u_short sel); */
654 static __inline void
655 ltr(u_short sel)
656 {
657         __asm __volatile("ltr %0" : : "r" (sel));
658 }
659
660 static __inline u_int64_t
661 rdr0(void)
662 {
663         u_int64_t data;
664         __asm __volatile("movq %%dr0,%0" : "=r" (data));
665         return (data);
666 }
667
668 static __inline void
669 load_dr0(u_int64_t dr0)
670 {
671         __asm __volatile("movq %0,%%dr0" : : "r" (dr0));
672 }
673
674 static __inline u_int64_t
675 rdr1(void)
676 {
677         u_int64_t data;
678         __asm __volatile("movq %%dr1,%0" : "=r" (data));
679         return (data);
680 }
681
682 static __inline void
683 load_dr1(u_int64_t dr1)
684 {
685         __asm __volatile("movq %0,%%dr1" : : "r" (dr1));
686 }
687
688 static __inline u_int64_t
689 rdr2(void)
690 {
691         u_int64_t data;
692         __asm __volatile("movq %%dr2,%0" : "=r" (data));
693         return (data);
694 }
695
696 static __inline void
697 load_dr2(u_int64_t dr2)
698 {
699         __asm __volatile("movq %0,%%dr2" : : "r" (dr2));
700 }
701
702 static __inline u_int64_t
703 rdr3(void)
704 {
705         u_int64_t data;
706         __asm __volatile("movq %%dr3,%0" : "=r" (data));
707         return (data);
708 }
709
710 static __inline void
711 load_dr3(u_int64_t dr3)
712 {
713         __asm __volatile("movq %0,%%dr3" : : "r" (dr3));
714 }
715
716 static __inline u_int64_t
717 rdr4(void)
718 {
719         u_int64_t data;
720         __asm __volatile("movq %%dr4,%0" : "=r" (data));
721         return (data);
722 }
723
724 static __inline void
725 load_dr4(u_int64_t dr4)
726 {
727         __asm __volatile("movq %0,%%dr4" : : "r" (dr4));
728 }
729
730 static __inline u_int64_t
731 rdr5(void)
732 {
733         u_int64_t data;
734         __asm __volatile("movq %%dr5,%0" : "=r" (data));
735         return (data);
736 }
737
738 static __inline void
739 load_dr5(u_int64_t dr5)
740 {
741         __asm __volatile("movq %0,%%dr5" : : "r" (dr5));
742 }
743
744 static __inline u_int64_t
745 rdr6(void)
746 {
747         u_int64_t data;
748         __asm __volatile("movq %%dr6,%0" : "=r" (data));
749         return (data);
750 }
751
752 static __inline void
753 load_dr6(u_int64_t dr6)
754 {
755         __asm __volatile("movq %0,%%dr6" : : "r" (dr6));
756 }
757
758 static __inline u_int64_t
759 rdr7(void)
760 {
761         u_int64_t data;
762         __asm __volatile("movq %%dr7,%0" : "=r" (data));
763         return (data);
764 }
765
766 static __inline void
767 load_dr7(u_int64_t dr7)
768 {
769         __asm __volatile("movq %0,%%dr7" : : "r" (dr7));
770 }
771
772 static __inline register_t
773 intr_disable(void)
774 {
775         register_t rflags;
776
777         rflags = read_rflags();
778         disable_intr();
779         return (rflags);
780 }
781
782 static __inline void
783 intr_restore(register_t rflags)
784 {
785         write_rflags(rflags);
786 }
787
788 #else /* !__GNUC__ */
789
790 int     breakpoint(void);
791 void    cpu_pause(void);
792 u_int   bsfl(u_int mask);
793 u_int   bsrl(u_int mask);
794 void    cpu_invlpg(u_long addr);
795 void    cpu_invlpg_range(u_long start, u_long end);
796 void    disable_intr(void);
797 void    do_cpuid(u_int ax, u_int *p);
798 void    enable_intr(void);
799 void    halt(void);
800 u_char  inb(u_int port);
801 u_int   inl(u_int port);
802 void    insb(u_int port, void *addr, size_t cnt);
803 void    insl(u_int port, void *addr, size_t cnt);
804 void    insw(u_int port, void *addr, size_t cnt);
805 void    invd(void);
806 void    invlpg(u_int addr);
807 void    invlpg_range(u_int start, u_int end);
808 void    invltlb(void);
809 u_short inw(u_int port);
810 void    load_cr0(u_int cr0);
811 void    load_cr3(u_int cr3);
812 void    load_cr4(u_int cr4);
813 void    load_fs(u_int sel);
814 void    load_gs(u_int sel);
815 struct region_descriptor;
816 void    lidt(struct region_descriptor *addr);
817 void    lldt(u_short sel);
818 void    ltr(u_short sel);
819 void    outb(u_int port, u_char data);
820 void    outl(u_int port, u_int data);
821 void    outsb(u_int port, void *addr, size_t cnt);
822 void    outsl(u_int port, void *addr, size_t cnt);
823 void    outsw(u_int port, void *addr, size_t cnt);
824 void    outw(u_int port, u_short data);
825 void    ia32_pause(void);
826 u_int   rcr0(void);
827 u_int   rcr2(void);
828 u_int   rcr3(void);
829 u_int   rcr4(void);
830 u_int   rfs(void);
831 u_int   rgs(void);
832 u_int64_t rdmsr(u_int msr);
833 u_int64_t rdpmc(u_int pmc);
834 u_int64_t rdtsc(void);
835 u_int   read_rflags(void);
836 void    wbinvd(void);
837 void    write_rflags(u_int rf);
838 void    wrmsr(u_int msr, u_int64_t newval);
839 u_int64_t       rdr0(void);
840 void    load_dr0(u_int64_t dr0);
841 u_int64_t       rdr1(void);
842 void    load_dr1(u_int64_t dr1);
843 u_int64_t       rdr2(void);
844 void    load_dr2(u_int64_t dr2);
845 u_int64_t       rdr3(void);
846 void    load_dr3(u_int64_t dr3);
847 u_int64_t       rdr4(void);
848 void    load_dr4(u_int64_t dr4);
849 u_int64_t       rdr5(void);
850 void    load_dr5(u_int64_t dr5);
851 u_int64_t       rdr6(void);
852 void    load_dr6(u_int64_t dr6);
853 u_int64_t       rdr7(void);
854 void    load_dr7(u_int64_t dr7);
855 register_t      intr_disable(void);
856 void    intr_restore(register_t rf);
857
858 #endif  /* __GNUC__ */
859
860 void    reset_dbregs(void);
861
862 __END_DECLS
863
864 #endif /* !_CPU_CPUFUNC_H_ */