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