cpufunc.h revision 621
1/* 2 * Functions to provide access to special i386 instructions. 3 * XXX - bezillions more are defined in locore.s but are not declared anywhere. 4 * 5 * $Id$ 6 */ 7 8#include <sys/cdefs.h> 9#include <sys/types.h> 10 11#ifdef __GNUC__ 12 13static __inline int bdb(void) 14{ 15 extern int bdb_exists; 16 17 if (!bdb_exists) 18 return (0); 19 __asm("int $3"); 20 return (1); 21} 22 23static __inline void 24disable_intr(void) 25{ 26 __asm __volatile("cli"); 27} 28 29static __inline void 30enable_intr(void) 31{ 32 __asm __volatile("sti"); 33} 34 35/* 36 * This roundabout method of returning a u_char helps stop gcc-1.40 from 37 * generating unnecessary movzbl's. 38 */ 39#define inb(port) ((u_char) u_int_inb(port)) 40 41static __inline u_int 42u_int_inb(u_int port) 43{ 44 u_char data; 45 /* 46 * We use %%dx and not %1 here because i/o is done at %dx and not at 47 * %edx, while gcc-2.2.2 generates inferior code (movw instead of movl) 48 * if we tell it to load (u_short) port. 49 */ 50 __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port)); 51 return data; 52} 53 54static __inline void 55outb(u_int port, u_char data) 56{ 57 register u_char al asm("ax"); 58 59 al = data; /* help gcc-1.40's register allocator */ 60 __asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port)); 61} 62 63static __inline__ 64imin(a, b) 65 int a, b; 66{ 67 68 return (a < b ? a : b); 69} 70 71static __inline__ 72imax(a, b) 73 int a, b; 74{ 75 76 return (a > b ? a : b); 77} 78 79static __inline__ 80unsigned int 81min(a, b) 82 unsigned int a, b; 83{ 84 85 return (a < b ? a : b); 86} 87 88static __inline__ 89unsigned int 90max(a, b) 91 unsigned int a, b; 92{ 93 94 return (a > b ? a : b); 95} 96 97static __inline__ 98long 99lmin(a, b) 100 long a, b; 101{ 102 103 return (a < b ? a : b); 104} 105 106static __inline__ 107long 108lmax(a, b) 109 long a, b; 110{ 111 112 return (a > b ? a : b); 113} 114 115static __inline__ 116unsigned long 117ulmin(a, b) 118 unsigned long a, b; 119{ 120 121 return (a < b ? a : b); 122} 123 124static __inline__ 125unsigned long 126ulmax(a, b) 127 unsigned long a, b; 128{ 129 130 return (a > b ? a : b); 131} 132 133static __inline__ 134ffs(mask) 135 register long mask; 136{ 137 register int bit; 138 139 if (!mask) 140 return(0); 141 for (bit = 1;; ++bit) { 142 if (mask&0x01) 143 return(bit); 144 mask >>= 1; 145 } 146} 147 148static __inline__ 149bcmp(v1, v2, len) 150 void *v1, *v2; 151 register unsigned len; 152{ 153 register u_char *s1 = v1, *s2 = v2; 154 155 while (len--) 156 if (*s1++ != *s2++) 157 return (1); 158 return (0); 159} 160 161static __inline__ 162size_t 163strlen(s1) 164 register __const__ char *s1; 165{ 166 register size_t len; 167 168 for (len = 0; *s1++ != '\0'; len++) 169 ; 170 return (len); 171} 172 173#else /* not __GNUC__ */ 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 183#define really_u_int int /* XXX */ 184#define really_void int /* XXX */ 185 186void load_cr0 __P((u_int cr0)); 187really_u_int rcr0 __P((void)); 188 189#ifdef notyet 190really_void setidt __P((int idx, /*XXX*/caddr_t func, int typ, int dpl)); 191#endif 192 193#undef really_u_int 194#undef really_void 195 196