13c4dd356SDavid Greenman /*- 23c4dd356SDavid Greenman * Copyright (c) 1993 The Regents of the University of California. 33c4dd356SDavid Greenman * All rights reserved. 43c4dd356SDavid Greenman * 53c4dd356SDavid Greenman * Redistribution and use in source and binary forms, with or without 63c4dd356SDavid Greenman * modification, are permitted provided that the following conditions 73c4dd356SDavid Greenman * are met: 83c4dd356SDavid Greenman * 1. Redistributions of source code must retain the above copyright 93c4dd356SDavid Greenman * notice, this list of conditions and the following disclaimer. 103c4dd356SDavid Greenman * 2. Redistributions in binary form must reproduce the above copyright 113c4dd356SDavid Greenman * notice, this list of conditions and the following disclaimer in the 123c4dd356SDavid Greenman * documentation and/or other materials provided with the distribution. 133c4dd356SDavid Greenman * 3. All advertising materials mentioning features or use of this software 143c4dd356SDavid Greenman * must display the following acknowledgement: 153c4dd356SDavid Greenman * This product includes software developed by the University of 163c4dd356SDavid Greenman * California, Berkeley and its contributors. 173c4dd356SDavid Greenman * 4. Neither the name of the University nor the names of its contributors 183c4dd356SDavid Greenman * may be used to endorse or promote products derived from this software 193c4dd356SDavid Greenman * without specific prior written permission. 203c4dd356SDavid Greenman * 213c4dd356SDavid Greenman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 223c4dd356SDavid Greenman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 233c4dd356SDavid Greenman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 243c4dd356SDavid Greenman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 253c4dd356SDavid Greenman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 263c4dd356SDavid Greenman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 273c4dd356SDavid Greenman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 283c4dd356SDavid Greenman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 293c4dd356SDavid Greenman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 303c4dd356SDavid Greenman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 313c4dd356SDavid Greenman * SUCH DAMAGE. 323c4dd356SDavid Greenman * 338db02de8SPaul Richards * $Id: cpufunc.h,v 1.20 1994/09/02 04:12:16 davidg Exp $ 343c4dd356SDavid Greenman */ 353c4dd356SDavid Greenman 365b81b6b3SRodney W. Grimes /* 375b81b6b3SRodney W. Grimes * Functions to provide access to special i386 instructions. 385b81b6b3SRodney W. Grimes * XXX - bezillions more are defined in locore.s but are not declared anywhere. 395b81b6b3SRodney W. Grimes */ 405b81b6b3SRodney W. Grimes 416e393973SGarrett Wollman #ifndef _MACHINE_CPUFUNC_H_ 426e393973SGarrett Wollman #define _MACHINE_CPUFUNC_H_ 1 436e393973SGarrett Wollman 445b81b6b3SRodney W. Grimes #include <sys/cdefs.h> 455b81b6b3SRodney W. Grimes #include <sys/types.h> 465b81b6b3SRodney W. Grimes 47f540b106SGarrett Wollman #include <machine/spl.h> 48d2306226SDavid Greenman 495b81b6b3SRodney W. Grimes #ifdef __GNUC__ 505b81b6b3SRodney W. Grimes 51381fe1aaSGarrett Wollman static inline int bdb(void) 525b81b6b3SRodney W. Grimes { 535b81b6b3SRodney W. Grimes extern int bdb_exists; 545b81b6b3SRodney W. Grimes 555b81b6b3SRodney W. Grimes if (!bdb_exists) 565b81b6b3SRodney W. Grimes return (0); 575b81b6b3SRodney W. Grimes __asm("int $3"); 585b81b6b3SRodney W. Grimes return (1); 595b81b6b3SRodney W. Grimes } 605b81b6b3SRodney W. Grimes 61381fe1aaSGarrett Wollman static inline void 625b81b6b3SRodney W. Grimes disable_intr(void) 635b81b6b3SRodney W. Grimes { 645b81b6b3SRodney W. Grimes __asm __volatile("cli"); 655b81b6b3SRodney W. Grimes } 665b81b6b3SRodney W. Grimes 67381fe1aaSGarrett Wollman static inline void 685b81b6b3SRodney W. Grimes enable_intr(void) 695b81b6b3SRodney W. Grimes { 705b81b6b3SRodney W. Grimes __asm __volatile("sti"); 715b81b6b3SRodney W. Grimes } 725b81b6b3SRodney W. Grimes 738db02de8SPaul Richards static inline u_long 748db02de8SPaul Richards read_eflags() 755b81b6b3SRodney W. Grimes { 768db02de8SPaul Richards u_long ef; 778db02de8SPaul Richards __asm __volatile("pushf; popl %0" : "=a" (ef)); 788db02de8SPaul Richards return(ef); 795b81b6b3SRodney W. Grimes } 805b81b6b3SRodney W. Grimes 81381fe1aaSGarrett Wollman static inline void 828db02de8SPaul Richards write_eflags(u_long ef) 835b81b6b3SRodney W. Grimes { 848db02de8SPaul Richards __asm __volatile("pushl %0; popf" : : "a" ((u_long) ef)); 855b81b6b3SRodney W. Grimes } 865b81b6b3SRodney W. Grimes 87ec120393SDavid Greenman static inline void 882c7a40c7SDavid Greenman pmap_update() 89ec120393SDavid Greenman { 90ec120393SDavid Greenman __asm __volatile("movl %%cr3, %%eax; movl %%eax, %%cr3" : : : "ax"); 91ec120393SDavid Greenman } 92ec120393SDavid Greenman 933c256f53SDavid Greenman static inline u_long 943c256f53SDavid Greenman rcr2() 953c256f53SDavid Greenman { 963c256f53SDavid Greenman u_long data; 973c256f53SDavid Greenman __asm __volatile("movl %%cr2,%%eax" : "=a" (data)); 983c256f53SDavid Greenman return data; 993c256f53SDavid Greenman } 1003c256f53SDavid Greenman 101ee06dc60SDavid Greenman struct quehead { 102ee06dc60SDavid Greenman struct quehead *qh_link; 103ee06dc60SDavid Greenman struct quehead *qh_rlink; 104ee06dc60SDavid Greenman }; 105ee06dc60SDavid Greenman 106ee06dc60SDavid Greenman static inline void 107ee06dc60SDavid Greenman insque(void *a, void *b) 108ee06dc60SDavid Greenman { 109ee06dc60SDavid Greenman register struct quehead *element = a, *head = b; 110ee06dc60SDavid Greenman element->qh_link = head->qh_link; 111ee06dc60SDavid Greenman head->qh_link = (struct quehead *)element; 112ee06dc60SDavid Greenman element->qh_rlink = (struct quehead *)head; 113ee06dc60SDavid Greenman ((struct quehead *)(element->qh_link))->qh_rlink 114ee06dc60SDavid Greenman = (struct quehead *)element; 115ee06dc60SDavid Greenman } 116ee06dc60SDavid Greenman 117ee06dc60SDavid Greenman static inline void 118ee06dc60SDavid Greenman remque(void *a) 119ee06dc60SDavid Greenman { 120ee06dc60SDavid Greenman register struct quehead *element = a; 121ee06dc60SDavid Greenman ((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink; 122ee06dc60SDavid Greenman ((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link; 123ee06dc60SDavid Greenman element->qh_rlink = 0; 124ee06dc60SDavid Greenman } 125ee06dc60SDavid Greenman 1265b81b6b3SRodney W. Grimes #else /* not __GNUC__ */ 127aaf08d94SGarrett Wollman extern void insque __P((void *, void *)); 128aaf08d94SGarrett Wollman extern void remque __P((void *)); 1295b81b6b3SRodney W. Grimes 1305b81b6b3SRodney W. Grimes int bdb __P((void)); 1315b81b6b3SRodney W. Grimes void disable_intr __P((void)); 1325b81b6b3SRodney W. Grimes void enable_intr __P((void)); 1335b81b6b3SRodney W. Grimes u_char inb __P((u_int port)); 1345b81b6b3SRodney W. Grimes void outb __P((u_int port, u_int data)); /* XXX - incompat */ 1355b81b6b3SRodney W. Grimes 1365b81b6b3SRodney W. Grimes #endif /* __GNUC__ */ 1375b81b6b3SRodney W. Grimes 1385b81b6b3SRodney W. Grimes void load_cr0 __P((u_int cr0)); 139aaf08d94SGarrett Wollman u_int rcr0 __P((void)); 140aaf08d94SGarrett Wollman void load_cr3(u_long); 141aaf08d94SGarrett Wollman u_long rcr3(void); 142f23b4c91SGarrett Wollman extern void DELAY(int); 1435b81b6b3SRodney W. Grimes 144aaf08d94SGarrett Wollman void setidt __P((int, void (*)(), int, int)); 145aaf08d94SGarrett Wollman extern u_long kvtop(void *); 146aaf08d94SGarrett Wollman extern void outw(int /*u_short*/, int /*u_short*/); /* XXX inline!*/ 147e2f27b40SDavid Greenman extern void outsb(int /*u_short*/, void *, size_t); 148e2f27b40SDavid Greenman extern void outsw(int /*u_short*/, void *, size_t); 149e2f27b40SDavid Greenman extern void insw(int /*u_short*/, void *, size_t); 150e2f27b40SDavid Greenman extern void fillw(int /*u_short*/, void *, size_t); 151a301c9d5SDavid Greenman extern void filli(int, void *, size_t); 15226931201SDavid Greenman 1536e393973SGarrett Wollman #endif /* _MACHINE_CPUFUNC_H_ */ 154