cpufunc.h revision 3098
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.24 1994/09/16 13:33:30 davidg 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 u_char 52inb(u_short port) 53{ 54 u_char data; 55 56 __asm __volatile("inb %1,%0" : "=a" (data) : "d" (port)); 57 return data; 58} 59 60static inline u_short 61inw(u_short port) 62{ 63 u_short data; 64 65 __asm __volatile("inw %1,%0" : "=a" (data) : "d" (port)); 66 return data; 67} 68 69static inline u_long 70inl(u_short port) 71{ 72 u_long data; 73 74 __asm __volatile("inl %1,%0" : "=a" (data) : "d" (port)); 75 return data; 76} 77 78static inline void 79outb(u_short port, u_char val) 80{ 81 __asm __volatile("outb %0,%1" : :"a" (val), "d" (port)); 82} 83 84static inline void 85outw(u_short port, u_short val) 86{ 87 __asm __volatile("outw %0,%1" : :"a" (val), "d" (port)); 88} 89 90static inline void 91outl(u_short port, u_long val) 92{ 93 __asm __volatile("outl %0,%1" : :"a" (val), "d" (port)); 94} 95 96static inline int bdb(void) 97{ 98 extern int bdb_exists; 99 100 if (!bdb_exists) 101 return (0); 102 __asm("int $3"); 103 return (1); 104} 105 106static inline void 107disable_intr(void) 108{ 109 __asm __volatile("cli"); 110} 111 112static inline void 113enable_intr(void) 114{ 115 __asm __volatile("sti"); 116} 117 118static inline u_long 119read_eflags() 120{ 121 u_long ef; 122 __asm __volatile("pushf; popl %0" : "=a" (ef)); 123 return(ef); 124} 125 126static inline void 127write_eflags(u_long ef) 128{ 129 __asm __volatile("pushl %0; popf" : : "a" ((u_long) ef)); 130} 131 132static inline void 133pmap_update() 134{ 135 __asm __volatile("movl %%cr3, %%eax; movl %%eax, %%cr3" : : : "ax"); 136} 137 138static inline u_long 139rcr2() 140{ 141 u_long data; 142 __asm __volatile("movl %%cr2,%%eax" : "=a" (data)); 143 return data; 144} 145 146struct quehead { 147 struct quehead *qh_link; 148 struct quehead *qh_rlink; 149}; 150 151static inline void 152insque(void *a, void *b) 153{ 154 register struct quehead *element = a, *head = b; 155 element->qh_link = head->qh_link; 156 head->qh_link = (struct quehead *)element; 157 element->qh_rlink = (struct quehead *)head; 158 ((struct quehead *)(element->qh_link))->qh_rlink 159 = (struct quehead *)element; 160} 161 162static inline void 163remque(void *a) 164{ 165 register struct quehead *element = a; 166 ((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink; 167 ((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link; 168 element->qh_rlink = 0; 169} 170 171#else /* not __GNUC__ */ 172extern void insque __P((void *, void *)); 173extern void remque __P((void *)); 174 175int bdb __P((void)); 176void disable_intr __P((void)); 177void enable_intr __P((void)); 178u_char inb __P((u_int port)); 179void outb __P((u_int port, u_int data)); /* XXX - incompat */ 180 181#endif /* __GNUC__ */ 182 183void load_cr0 __P((u_int cr0)); 184u_int rcr0 __P((void)); 185void load_cr3(u_long); 186u_long rcr3(void); 187extern void DELAY(int); 188 189void setidt __P((int, void (*)(), int, int)); 190extern u_long kvtop(void *); 191extern void * outsb(int /*u_short*/, void *, size_t); 192extern void * outsw(int /*u_short*/, void *, size_t); 193extern void * outsl(int /*u_short*/, void *, size_t); 194extern void * insb(int /*u_short*/, void *, size_t); 195extern void * insw(int /*u_short*/, void *, size_t); 196extern void * insl(int /*u_short*/, void *, size_t); 197extern void fillw(int /*u_short*/, void *, size_t); 198extern void filli(int, void *, size_t); 199 200#endif /* _MACHINE_CPUFUNC_H_ */ 201