cpufunc.h revision 2455
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.19 1994/08/23 13:41:37 paul 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
73static inline u_char
74inb(u_int port)
75{
76	u_char	data;
77	/*
78	 * We use %%dx and not %1 here because i/o is done at %dx and not at
79	 * %edx, while gcc-2.2.2 generates inferior code (movw instead of movl)
80	 * if we tell it to load (u_short) port.
81	 */
82	__asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
83	return data;
84}
85
86static inline void
87outb(u_int port, u_char data)
88{
89	u_char	al;
90
91	al = data;		/* help gcc-1.40's register allocator */
92	__asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
93}
94
95static inline void
96pmap_update()
97{
98	__asm __volatile("movl %%cr3, %%eax; movl %%eax, %%cr3" : : : "ax");
99}
100
101static inline u_long
102rcr2()
103{
104	u_long	data;
105	__asm __volatile("movl %%cr2,%%eax" : "=a" (data));
106	return data;
107}
108
109struct quehead {
110	struct quehead *qh_link;
111	struct quehead *qh_rlink;
112};
113
114static inline void
115insque(void *a, void *b)
116{
117	register struct quehead *element = a, *head = b;
118	element->qh_link = head->qh_link;
119	head->qh_link = (struct quehead *)element;
120	element->qh_rlink = (struct quehead *)head;
121	((struct quehead *)(element->qh_link))->qh_rlink
122	  = (struct quehead *)element;
123}
124
125static inline void
126remque(void *a)
127{
128	register struct quehead *element = a;
129	((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
130	((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
131	element->qh_rlink = 0;
132}
133
134#else /* not __GNUC__ */
135extern	void insque __P((void *, void *));
136extern	void remque __P((void *));
137
138int	bdb		__P((void));
139void	disable_intr	__P((void));
140void	enable_intr	__P((void));
141u_char	inb		__P((u_int port));
142void	outb		__P((u_int port, u_int data));	/* XXX - incompat */
143
144#endif	/* __GNUC__ */
145
146void	load_cr0	__P((u_int cr0));
147u_int	rcr0	__P((void));
148void load_cr3(u_long);
149u_long rcr3(void);
150extern void DELAY(int);
151
152void	setidt	__P((int, void (*)(), int, int));
153extern u_long kvtop(void *);
154extern void outw(int /*u_short*/, int /*u_short*/); /* XXX inline!*/
155extern void outsb(int /*u_short*/, void *, size_t);
156extern void outsw(int /*u_short*/, void *, size_t);
157extern void insw(int /*u_short*/, void *, size_t);
158extern void fillw(int /*u_short*/, void *, size_t);
159extern void filli(int, void *, size_t);
160
161#endif /* _MACHINE_CPUFUNC_H_ */
162