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