Home | History | Annotate | Line # | Download | only in include
cpufunc.h revision 1.6
      1 /*
      2  * Copyright (c) 1993 Charles Hannum.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *      This product includes software developed by Charles Hannum.
     16  * 4. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  *
     30  *	$Id: cpufunc.h,v 1.6 1994/10/09 13:02:56 mycroft Exp $
     31  */
     32 
     33 /*
     34  * Functions to provide access to i386-specific instructions.
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 #include <sys/types.h>
     39 
     40 static __inline int bdb(void)
     41 {
     42 	extern int bdb_exists;
     43 
     44 	if (!bdb_exists)
     45 		return (0);
     46 	__asm __volatile("int $3");
     47 	return (1);
     48 }
     49 
     50 static __inline void
     51 lidt(void *p)
     52 {
     53 	__asm __volatile("lidt (%0)" : : "r" (p));
     54 }
     55 
     56 static __inline void
     57 lldt(u_short sel)
     58 {
     59 	__asm __volatile("lldt %0" : : "r" (sel));
     60 }
     61 
     62 static __inline void
     63 ltr(u_short sel)
     64 {
     65 	__asm __volatile("ltr %0" : : "r" (sel));
     66 }
     67 
     68 static __inline void
     69 lcr0(u_int val)
     70 {
     71 	__asm __volatile("movl %0,%%cr0" : : "r" (val));
     72 }
     73 
     74 static __inline u_int
     75 rcr0(void)
     76 {
     77 	u_int val;
     78 	__asm __volatile("movl %%cr0,%0" : "=r" (val));
     79 	return val;
     80 }
     81 
     82 static __inline u_int
     83 rcr2(void)
     84 {
     85 	u_int val;
     86 	__asm __volatile("movl %%cr2,%0" : "=r" (val));
     87 	return val;
     88 }
     89 
     90 static __inline void
     91 lcr3(u_int val)
     92 {
     93 	__asm __volatile("movl %0,%%cr3" : : "r" (val));
     94 }
     95 
     96 static __inline u_int
     97 rcr3(void)
     98 {
     99 	u_int val;
    100 	__asm __volatile("movl %%cr3,%0" : "=r" (val));
    101 	return val;
    102 }
    103 
    104 static __inline void
    105 tlbflush(void)
    106 {
    107 	u_int val;
    108 	__asm __volatile("movl %%cr3,%0" : "=r" (val));
    109 	__asm __volatile("movl %0,%%cr3" : : "r" (val));
    110 }
    111 
    112 #ifdef notyet
    113 void	setidt	__P((int idx, /*XXX*/caddr_t func, int typ, int dpl));
    114 #endif
    115 
    116 
    117 /* XXXX ought to be in psl.h with spl() functions */
    118 
    119 static __inline void
    120 disable_intr(void)
    121 {
    122 	__asm __volatile("cli");
    123 }
    124 
    125 static __inline void
    126 enable_intr(void)
    127 {
    128 	__asm __volatile("sti");
    129 }
    130 
    131