cpufunc.h revision 3102
1/*-
2 * Copyright (c) 1993 The Regents of the University of California.
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 the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *
34 * Portions:
35 * Copyright (c) 1993 Charles Hannum.
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 *    notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 *    notice, this list of conditions and the following disclaimer in the
45 *    documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 *    must display the following acknowledgement:
48 *      This product includes software developed by Charles Hannum.
49 * 4. The name of the author may not be used to endorse or promote products
50 *    derived from this software without specific prior written permission
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *
63 *
64 *	$Id: cpufunc.h,v 1.26 1994/09/25 20:03:41 davidg Exp $
65 */
66
67
68/*
69 * Functions to provide access to special i386 instructions.
70 * XXX - bezillions more are defined in locore.s but are not declared anywhere.
71 */
72
73#ifndef _MACHINE_CPUFUNC_H_
74#define _MACHINE_CPUFUNC_H_ 1
75
76#include <sys/cdefs.h>
77#include <sys/types.h>
78
79#include <machine/spl.h>
80
81#ifdef	__GNUC__
82
83static __inline void
84insb(u_short port, void *addr, int cnt)
85{
86	__asm __volatile("cld;repne;insb" :
87			 : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
88}
89
90static __inline void
91insw(u_short port, void *addr, int cnt)
92{
93	__asm __volatile("cld;repne;insw" :
94			 : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
95}
96
97static __inline void
98insl(u_short port, void *addr, int cnt)
99{
100	__asm __volatile("cld;repne;insl" :
101			 : "d" (port), "D" (addr), "c" (cnt) : "%edi", "%ecx", "memory");
102}
103
104static __inline void
105outsb(u_short port, void *addr, int cnt)
106{
107	__asm __volatile("cld;repne;outsb" :
108			 : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
109}
110
111static __inline void
112outsw(u_short port, void *addr, int cnt)
113{
114	__asm __volatile("cld;repne;outsw" :
115			 : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
116}
117
118static __inline void
119outsl(u_short port, void *addr, int cnt)
120{
121	__asm __volatile("cld;repne;outsl" :
122			 : "d" (port), "S" (addr), "c" (cnt) : "%esi", "%ecx");
123}
124
125static inline u_char
126inb(u_short port)
127{
128	u_char data;
129
130	__asm __volatile("inb %1,%0" : "=a" (data) : "d" (port));
131	return data;
132}
133
134static inline u_short
135inw(u_short port)
136{
137	u_short data;
138
139	__asm __volatile("inw %1,%0" : "=a" (data) : "d" (port));
140	return data;
141}
142
143static inline u_long
144inl(u_short port)
145{
146	u_long data;
147
148	__asm __volatile("inl %1,%0" : "=a" (data) : "d" (port));
149	return data;
150}
151
152static inline void
153outb(u_short port, u_char val)
154{
155	__asm __volatile("outb %0,%1" : :"a" (val), "d" (port));
156}
157
158static inline void
159outw(u_short port, u_short val)
160{
161	__asm __volatile("outw %0,%1" : :"a" (val), "d" (port));
162}
163
164static inline void
165outl(u_short port, u_long val)
166{
167	__asm __volatile("outl %0,%1" : :"a" (val), "d" (port));
168}
169
170static inline int bdb(void)
171{
172	extern int bdb_exists;
173
174	if (!bdb_exists)
175		return (0);
176	__asm("int $3");
177	return (1);
178}
179
180static inline void
181disable_intr(void)
182{
183	__asm __volatile("cli");
184}
185
186static inline void
187enable_intr(void)
188{
189	__asm __volatile("sti");
190}
191
192static inline u_long
193read_eflags()
194{
195	u_long ef;
196	__asm __volatile("pushf; popl %0" : "=a" (ef));
197	return(ef);
198}
199
200static inline void
201write_eflags(u_long ef)
202{
203	__asm __volatile("pushl %0; popf" : : "a" ((u_long) ef));
204}
205
206static inline void
207pmap_update()
208{
209	__asm __volatile("movl %%cr3, %%eax; movl %%eax, %%cr3" : : : "ax");
210}
211
212static inline u_long
213rcr2()
214{
215	u_long	data;
216	__asm __volatile("movl %%cr2,%%eax" : "=a" (data));
217	return data;
218}
219
220struct quehead {
221	struct quehead *qh_link;
222	struct quehead *qh_rlink;
223};
224
225static inline void
226insque(void *a, void *b)
227{
228	register struct quehead *element = a, *head = b;
229	element->qh_link = head->qh_link;
230	head->qh_link = (struct quehead *)element;
231	element->qh_rlink = (struct quehead *)head;
232	((struct quehead *)(element->qh_link))->qh_rlink
233	  = (struct quehead *)element;
234}
235
236static inline void
237remque(void *a)
238{
239	register struct quehead *element = a;
240	((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
241	((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
242	element->qh_rlink = 0;
243}
244
245#else /* not __GNUC__ */
246extern	void insque __P((void *, void *));
247extern	void remque __P((void *));
248
249int	bdb		__P((void));
250void	disable_intr	__P((void));
251void	enable_intr	__P((void));
252u_char	inb		__P((u_int port));
253void	outb		__P((u_int port, u_int data));	/* XXX - incompat */
254
255#endif	/* __GNUC__ */
256
257void	load_cr0	__P((u_int cr0));
258u_int	rcr0	__P((void));
259void load_cr3(u_long);
260u_long rcr3(void);
261extern void DELAY(int);
262
263void	setidt	__P((int, void (*)(), int, int));
264extern u_long kvtop(void *);
265extern void fillw(int /*u_short*/, void *, size_t);
266extern void filli(int, void *, size_t);
267
268#endif /* _MACHINE_CPUFUNC_H_ */
269