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