153
153
#define bit_ENH_MOVSB 0x00000200
154
154
155
155
#if __i386__
156
- #define __cpuid (__level , __eax , __ebx , __ecx , __edx ) \
156
+ #define __cpuid (__leaf , __eax , __ebx , __ecx , __edx ) \
157
157
__asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
158
- : "0"(__level ))
158
+ : "0"(__leaf ))
159
159
160
- #define __cpuid_count (__level , __count , __eax , __ebx , __ecx , __edx ) \
160
+ #define __cpuid_count (__leaf , __count , __eax , __ebx , __ecx , __edx ) \
161
161
__asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
162
- : "0"(__level ), "2"(__count))
162
+ : "0"(__leaf ), "2"(__count))
163
163
#else
164
164
/* x86-64 uses %rbx as the base register, so preserve it. */
165
- #define __cpuid (__level , __eax , __ebx , __ecx , __edx ) \
165
+ #define __cpuid (__leaf , __eax , __ebx , __ecx , __edx ) \
166
166
__asm(" xchgq %%rbx,%q1\n" \
167
167
" cpuid\n" \
168
168
" xchgq %%rbx,%q1" \
169
169
: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
170
- : "0"(__level ))
170
+ : "0"(__leaf ))
171
171
172
- #define __cpuid_count (__level , __count , __eax , __ebx , __ecx , __edx ) \
172
+ #define __cpuid_count (__leaf , __count , __eax , __ebx , __ecx , __edx ) \
173
173
__asm(" xchgq %%rbx,%q1\n" \
174
174
" cpuid\n" \
175
175
" xchgq %%rbx,%q1" \
176
176
: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
177
- : "0"(__level ), "2"(__count))
177
+ : "0"(__leaf ), "2"(__count))
178
178
#endif
179
179
180
- static __inline int __get_cpuid (unsigned int __level , unsigned int * __eax ,
181
- unsigned int * __ebx , unsigned int * __ecx ,
182
- unsigned int * __edx ) {
183
- __cpuid (__level , * __eax , * __ebx , * __ecx , * __edx );
184
- return 1 ;
185
- }
186
-
187
- static __inline int __get_cpuid_max (unsigned int __level , unsigned int * __sig )
180
+ static __inline int __get_cpuid_max (unsigned int __leaf , unsigned int * __sig )
188
181
{
189
182
unsigned int __eax , __ebx , __ecx , __edx ;
190
183
#if __i386__
@@ -208,8 +201,35 @@ static __inline int __get_cpuid_max (unsigned int __level, unsigned int *__sig)
208
201
return 0 ;
209
202
#endif
210
203
211
- __cpuid (__level , __eax , __ebx , __ecx , __edx );
204
+ __cpuid (__leaf , __eax , __ebx , __ecx , __edx );
212
205
if (__sig )
213
206
* __sig = __ebx ;
214
207
return __eax ;
215
208
}
209
+
210
+ static __inline int __get_cpuid (unsigned int __leaf , unsigned int * __eax ,
211
+ unsigned int * __ebx , unsigned int * __ecx ,
212
+ unsigned int * __edx )
213
+ {
214
+ unsigned int __max_leaf = __get_cpuid_max (__leaf & 0x80000000 , 0 );
215
+
216
+ if (__max_leaf == 0 || __max_leaf < __leaf )
217
+ return 0 ;
218
+
219
+ __cpuid (__leaf , * __eax , * __ebx , * __ecx , * __edx );
220
+ return 1 ;
221
+ }
222
+
223
+ static __inline int __get_cpuid_count (unsigned int __leaf ,
224
+ unsigned int __subleaf ,
225
+ unsigned int * __eax , unsigned int * __ebx ,
226
+ unsigned int * __ecx , unsigned int * __edx )
227
+ {
228
+ unsigned int __max_leaf = __get_cpuid_max (__leaf & 0x80000000 , 0 );
229
+
230
+ if (__max_leaf == 0 || __max_leaf < __leaf )
231
+ return 0 ;
232
+
233
+ __cpuid_count (__leaf , __subleaf , * __eax , * __ebx , * __ecx , * __edx );
234
+ return 1 ;
235
+ }
0 commit comments