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