cpufunc.h revision 1.21 1 1.21 yamt /* $NetBSD: cpufunc.h,v 1.21 2002/07/03 02:46:16 yamt Exp $ */
2 1.8 cgd
3 1.16 mycroft /*-
4 1.16 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.4 mycroft * All rights reserved.
6 1.2 mycroft *
7 1.16 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.16 mycroft * by Charles M. Hannum.
9 1.16 mycroft *
10 1.4 mycroft * Redistribution and use in source and binary forms, with or without
11 1.4 mycroft * modification, are permitted provided that the following conditions
12 1.4 mycroft * are met:
13 1.4 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.4 mycroft * notice, this list of conditions and the following disclaimer.
15 1.4 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.4 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.4 mycroft * documentation and/or other materials provided with the distribution.
18 1.4 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.4 mycroft * must display the following acknowledgement:
20 1.16 mycroft * This product includes software developed by the NetBSD
21 1.16 mycroft * Foundation, Inc. and its contributors.
22 1.16 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.16 mycroft * contributors may be used to endorse or promote products derived
24 1.16 mycroft * from this software without specific prior written permission.
25 1.4 mycroft *
26 1.16 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.16 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.16 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.16 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.16 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.16 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.16 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.16 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.16 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.16 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.16 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.4 mycroft */
38 1.4 mycroft
39 1.7 mycroft #ifndef _I386_CPUFUNC_H_
40 1.7 mycroft #define _I386_CPUFUNC_H_
41 1.7 mycroft
42 1.4 mycroft /*
43 1.4 mycroft * Functions to provide access to i386-specific instructions.
44 1.1 cgd */
45 1.1 cgd
46 1.1 cgd #include <sys/cdefs.h>
47 1.1 cgd #include <sys/types.h>
48 1.13 perry
49 1.14 perry #ifdef _KERNEL
50 1.1 cgd
51 1.10 chuck static __inline void
52 1.10 chuck invlpg(u_int addr)
53 1.10 chuck {
54 1.10 chuck __asm __volatile("invlpg (%0)" : : "r" (addr) : "memory");
55 1.10 chuck }
56 1.10 chuck
57 1.1 cgd static __inline void
58 1.4 mycroft lidt(void *p)
59 1.4 mycroft {
60 1.4 mycroft __asm __volatile("lidt (%0)" : : "r" (p));
61 1.4 mycroft }
62 1.4 mycroft
63 1.4 mycroft static __inline void
64 1.4 mycroft lldt(u_short sel)
65 1.4 mycroft {
66 1.4 mycroft __asm __volatile("lldt %0" : : "r" (sel));
67 1.4 mycroft }
68 1.4 mycroft
69 1.4 mycroft static __inline void
70 1.4 mycroft ltr(u_short sel)
71 1.4 mycroft {
72 1.4 mycroft __asm __volatile("ltr %0" : : "r" (sel));
73 1.4 mycroft }
74 1.4 mycroft
75 1.4 mycroft static __inline void
76 1.4 mycroft lcr0(u_int val)
77 1.4 mycroft {
78 1.4 mycroft __asm __volatile("movl %0,%%cr0" : : "r" (val));
79 1.4 mycroft }
80 1.4 mycroft
81 1.4 mycroft static __inline u_int
82 1.4 mycroft rcr0(void)
83 1.4 mycroft {
84 1.4 mycroft u_int val;
85 1.6 mycroft __asm __volatile("movl %%cr0,%0" : "=r" (val));
86 1.4 mycroft return val;
87 1.4 mycroft }
88 1.4 mycroft
89 1.4 mycroft static __inline u_int
90 1.4 mycroft rcr2(void)
91 1.4 mycroft {
92 1.4 mycroft u_int val;
93 1.6 mycroft __asm __volatile("movl %%cr2,%0" : "=r" (val));
94 1.4 mycroft return val;
95 1.4 mycroft }
96 1.4 mycroft
97 1.4 mycroft static __inline void
98 1.4 mycroft lcr3(u_int val)
99 1.4 mycroft {
100 1.4 mycroft __asm __volatile("movl %0,%%cr3" : : "r" (val));
101 1.4 mycroft }
102 1.4 mycroft
103 1.4 mycroft static __inline u_int
104 1.4 mycroft rcr3(void)
105 1.4 mycroft {
106 1.4 mycroft u_int val;
107 1.6 mycroft __asm __volatile("movl %%cr3,%0" : "=r" (val));
108 1.10 chuck return val;
109 1.10 chuck }
110 1.10 chuck
111 1.10 chuck static __inline void
112 1.10 chuck lcr4(u_int val)
113 1.10 chuck {
114 1.10 chuck __asm __volatile("movl %0,%%cr4" : : "r" (val));
115 1.10 chuck }
116 1.10 chuck
117 1.10 chuck static __inline u_int
118 1.10 chuck rcr4(void)
119 1.10 chuck {
120 1.10 chuck u_int val;
121 1.10 chuck __asm __volatile("movl %%cr4,%0" : "=r" (val));
122 1.4 mycroft return val;
123 1.6 mycroft }
124 1.6 mycroft
125 1.6 mycroft static __inline void
126 1.6 mycroft tlbflush(void)
127 1.6 mycroft {
128 1.6 mycroft u_int val;
129 1.6 mycroft __asm __volatile("movl %%cr3,%0" : "=r" (val));
130 1.6 mycroft __asm __volatile("movl %0,%%cr3" : : "r" (val));
131 1.4 mycroft }
132 1.4 mycroft
133 1.4 mycroft #ifdef notyet
134 1.4 mycroft void setidt __P((int idx, /*XXX*/caddr_t func, int typ, int dpl));
135 1.4 mycroft #endif
136 1.4 mycroft
137 1.21 yamt /* debug register */
138 1.21 yamt void dr0(caddr_t, u_int32_t, u_int32_t, u_int32_t);
139 1.21 yamt
140 1.21 yamt static __inline u_int
141 1.21 yamt rdr6(void)
142 1.21 yamt {
143 1.21 yamt u_int val;
144 1.21 yamt
145 1.21 yamt __asm __volatile("movl %%dr6,%0" : "=r" (val));
146 1.21 yamt return val;
147 1.21 yamt }
148 1.21 yamt
149 1.21 yamt static __inline void
150 1.21 yamt ldr6(u_int val)
151 1.21 yamt {
152 1.21 yamt
153 1.21 yamt __asm __volatile("movl %0,%%dr6" : : "r" (val));
154 1.21 yamt }
155 1.4 mycroft
156 1.4 mycroft /* XXXX ought to be in psl.h with spl() functions */
157 1.4 mycroft
158 1.4 mycroft static __inline void
159 1.1 cgd disable_intr(void)
160 1.1 cgd {
161 1.1 cgd __asm __volatile("cli");
162 1.1 cgd }
163 1.1 cgd
164 1.1 cgd static __inline void
165 1.1 cgd enable_intr(void)
166 1.1 cgd {
167 1.1 cgd __asm __volatile("sti");
168 1.12 drochner }
169 1.12 drochner
170 1.12 drochner static __inline u_long
171 1.12 drochner read_eflags(void)
172 1.12 drochner {
173 1.12 drochner u_long ef;
174 1.12 drochner
175 1.12 drochner __asm __volatile("pushfl; popl %0" : "=r" (ef));
176 1.12 drochner return (ef);
177 1.12 drochner }
178 1.12 drochner
179 1.12 drochner static __inline void
180 1.12 drochner write_eflags(u_long ef)
181 1.12 drochner {
182 1.12 drochner __asm __volatile("pushl %0; popfl" : : "r" (ef));
183 1.17 thorpej }
184 1.17 thorpej
185 1.17 thorpej static __inline u_int64_t
186 1.17 thorpej rdmsr(u_int msr)
187 1.17 thorpej {
188 1.17 thorpej u_int64_t rv;
189 1.17 thorpej
190 1.19 thorpej __asm __volatile("rdmsr" : "=A" (rv) : "c" (msr));
191 1.17 thorpej return (rv);
192 1.17 thorpej }
193 1.17 thorpej
194 1.17 thorpej static __inline void
195 1.17 thorpej wrmsr(u_int msr, u_int64_t newval)
196 1.17 thorpej {
197 1.19 thorpej __asm __volatile("wrmsr" : : "A" (newval), "c" (msr));
198 1.17 thorpej }
199 1.17 thorpej
200 1.17 thorpej static __inline void
201 1.17 thorpej wbinvd(void)
202 1.17 thorpej {
203 1.17 thorpej __asm __volatile("wbinvd");
204 1.18 thorpej }
205 1.18 thorpej
206 1.18 thorpej static __inline u_int64_t
207 1.18 thorpej rdtsc(void)
208 1.18 thorpej {
209 1.18 thorpej u_int64_t rv;
210 1.18 thorpej
211 1.19 thorpej __asm __volatile("rdtsc" : "=A" (rv));
212 1.18 thorpej return (rv);
213 1.18 thorpej }
214 1.18 thorpej
215 1.18 thorpej static __inline u_int64_t
216 1.18 thorpej rdpmc(u_int pmc)
217 1.18 thorpej {
218 1.18 thorpej u_int64_t rv;
219 1.18 thorpej
220 1.19 thorpej __asm __volatile("rdpmc" : "=A" (rv) : "c" (pmc));
221 1.18 thorpej return (rv);
222 1.9 thorpej }
223 1.9 thorpej
224 1.9 thorpej /* Break into DDB/KGDB. */
225 1.9 thorpej static __inline void
226 1.9 thorpej breakpoint(void)
227 1.9 thorpej {
228 1.9 thorpej __asm __volatile("int $3");
229 1.1 cgd }
230 1.20 thorpej
231 1.20 thorpej /*
232 1.20 thorpej * XXX Maybe these don't belong here...
233 1.20 thorpej */
234 1.20 thorpej
235 1.20 thorpej extern int (*copyout_func)(const void *, void *, size_t);
236 1.20 thorpej extern int (*copyin_func)(const void *, void *, size_t);
237 1.20 thorpej
238 1.20 thorpej int i386_copyout(const void *, void *, size_t);
239 1.20 thorpej int i486_copyout(const void *, void *, size_t);
240 1.20 thorpej
241 1.20 thorpej int i386_copyin(const void *, void *, size_t);
242 1.14 perry
243 1.14 perry #endif /* _KERNEL */
244 1.1 cgd
245 1.7 mycroft #endif /* !_I386_CPUFUNC_H_ */
246