cpufunc.h revision 1.5 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.5 1994/01/28 23:44:07 jtc 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 tlbflush(void)
70 {
71 __asm __volatile("movl %%cr3,%%eax\n\tmovl %%eax,%%cr3" : : : "%eax");
72 }
73
74 static __inline void
75 lcr0(u_int val)
76 {
77 __asm __volatile("movl %0,%%cr0" : : "r" (val));
78 }
79
80 static __inline u_int
81 rcr0(void)
82 {
83 u_int val;
84 __asm __volatile("movl %%cr0,%0" : "=a" (val));
85 return val;
86 }
87
88 static __inline u_int
89 rcr2(void)
90 {
91 u_int val;
92 __asm __volatile("movl %%cr2,%0" : "=a" (val));
93 return val;
94 }
95
96 static __inline void
97 lcr3(u_int val)
98 {
99 __asm __volatile("movl %0,%%cr3" : : "r" (val));
100 }
101
102 static __inline u_int
103 rcr3(void)
104 {
105 u_int val;
106 __asm __volatile("movl %%cr3,%0" : "=a" (val));
107 return val;
108 }
109
110 #ifdef notyet
111 void setidt __P((int idx, /*XXX*/caddr_t func, int typ, int dpl));
112 #endif
113
114
115 /* XXXX ought to be in psl.h with spl() functions */
116
117 static __inline void
118 disable_intr(void)
119 {
120 __asm __volatile("cli");
121 }
122
123 static __inline void
124 enable_intr(void)
125 {
126 __asm __volatile("sti");
127 }
128
129