cpufunc.h revision 2112
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 *	$Id: cpufunc.h,v 1.16 1994/08/13 03:49:49 wollman Exp $
34 */
35
36/*
37 * Functions to provide access to special i386 instructions.
38 * XXX - bezillions more are defined in locore.s but are not declared anywhere.
39 */
40
41#ifndef _MACHINE_CPUFUNC_H_
42#define _MACHINE_CPUFUNC_H_ 1
43
44#include <sys/cdefs.h>
45#include <sys/types.h>
46
47#include <machine/spl.h>
48
49#ifdef	__GNUC__
50
51static inline int bdb(void)
52{
53	extern int bdb_exists;
54
55	if (!bdb_exists)
56		return (0);
57	__asm("int $3");
58	return (1);
59}
60
61static inline void
62disable_intr(void)
63{
64	__asm __volatile("cli");
65}
66
67static inline void
68enable_intr(void)
69{
70	__asm __volatile("sti");
71}
72
73/*
74 * This roundabout method of returning a u_char helps stop gcc-1.40 from
75 * generating unnecessary movzbl's.
76 */
77#define	inb(port)	((u_char) u_int_inb(port))
78
79static inline u_int
80u_int_inb(u_int port)
81{
82	u_char	data;
83	/*
84	 * We use %%dx and not %1 here because i/o is done at %dx and not at
85	 * %edx, while gcc-2.2.2 generates inferior code (movw instead of movl)
86	 * if we tell it to load (u_short) port.
87	 */
88	__asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
89	return data;
90}
91
92static inline void
93outb(u_int port, u_char data)
94{
95	u_char	al;
96
97	al = data;		/* help gcc-1.40's register allocator */
98	__asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
99}
100
101static inline void
102tlbflush()
103{
104	__asm __volatile("movl %%cr3, %%eax; movl %%eax, %%cr3" : : : "ax");
105}
106
107static inline u_long
108rcr2()
109{
110	u_long	data;
111	__asm __volatile("movl %%cr2,%%eax" : "=a" (data));
112	return data;
113}
114
115struct quehead {
116	struct quehead *qh_link;
117	struct quehead *qh_rlink;
118};
119
120static inline void
121insque(void *a, void *b)
122{
123	register struct quehead *element = a, *head = b;
124	element->qh_link = head->qh_link;
125	head->qh_link = (struct quehead *)element;
126	element->qh_rlink = (struct quehead *)head;
127	((struct quehead *)(element->qh_link))->qh_rlink
128	  = (struct quehead *)element;
129}
130
131static inline void
132remque(void *a)
133{
134	register struct quehead *element = a;
135	((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
136	((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
137	element->qh_rlink = 0;
138}
139
140#else /* not __GNUC__ */
141extern	void insque __P((void *, void *));
142extern	void remque __P((void *));
143
144int	bdb		__P((void));
145void	disable_intr	__P((void));
146void	enable_intr	__P((void));
147u_char	inb		__P((u_int port));
148void	outb		__P((u_int port, u_int data));	/* XXX - incompat */
149
150#endif	/* __GNUC__ */
151
152void	load_cr0	__P((u_int cr0));
153u_int	rcr0	__P((void));
154void load_cr3(u_long);
155u_long rcr3(void);
156extern void DELAY(int);
157
158void	setidt	__P((int, void (*)(), int, int));
159extern u_long kvtop(void *);
160extern void outw(int /*u_short*/, int /*u_short*/); /* XXX inline!*/
161extern void outsb(int /*u_short*/, void *, size_t);
162extern void outsw(int /*u_short*/, void *, size_t);
163extern void insw(int /*u_short*/, void *, size_t);
164extern void fillw(int /*u_short*/, void *, size_t);
165extern void filli(int, void *, size_t);
166
167#endif /* _MACHINE_CPUFUNC_H_ */
168