2009-05-15 19:07:36 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <minix/minlib.h>
|
|
|
|
#include <minix/cpufeature.h>
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/vm.h>
|
2009-05-15 19:07:36 +02:00
|
|
|
|
|
|
|
int _cpufeature(int cpufeature)
|
|
|
|
{
|
2010-01-15 16:23:57 +01:00
|
|
|
u32_t eax, ebx, ecx, edx;
|
2009-05-15 19:07:36 +02:00
|
|
|
int proc;
|
|
|
|
|
2010-01-15 16:23:57 +01:00
|
|
|
eax = ebx = ecx = edx = 0;
|
2009-05-15 19:07:36 +02:00
|
|
|
proc = getprocessor();
|
|
|
|
|
|
|
|
/* If processor supports CPUID and its CPUID supports enough
|
|
|
|
* parameters, retrieve EDX feature flags to test against.
|
|
|
|
*/
|
|
|
|
if(proc >= 586) {
|
2010-01-15 16:23:57 +01:00
|
|
|
eax = 0;
|
|
|
|
_cpuid(&eax, &ebx, &ecx, &edx);
|
|
|
|
if(eax > 0) {
|
|
|
|
eax = 1;
|
|
|
|
_cpuid(&eax, &ebx, &ecx, &edx);
|
2009-05-15 19:07:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(cpufeature) {
|
|
|
|
case _CPUF_I386_PSE:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_PSE;
|
2009-05-15 19:07:36 +02:00
|
|
|
case _CPUF_I386_PGE:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_PGE;
|
2009-11-16 22:41:44 +01:00
|
|
|
case _CPUF_I386_APIC_ON_CHIP:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_APIC_ON_CHIP;
|
2009-11-16 22:41:44 +01:00
|
|
|
case _CPUF_I386_TSC:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_TSC;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_FPU:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_FPU;
|
2010-04-29 21:08:49 +02:00
|
|
|
#define SSE_FULL_EDX (CPUID1_EDX_FXSR | CPUID1_EDX_SSE | CPUID1_EDX_SSE2)
|
|
|
|
#define SSE_FULL_ECX (CPUID1_ECX_SSE3 | CPUID1_ECX_SSSE3 | \
|
|
|
|
CPUID1_ECX_SSE4_1 | CPUID1_ECX_SSE4_2)
|
|
|
|
case _CPUF_I386_SSE1234_12:
|
|
|
|
return (edx & SSE_FULL_EDX) == SSE_FULL_EDX &&
|
|
|
|
(ecx & SSE_FULL_ECX) == SSE_FULL_ECX;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_FXSR:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_FXSR;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_SSE:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_SSE;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_SSE2:
|
2010-01-15 16:23:57 +01:00
|
|
|
return edx & CPUID1_EDX_SSE2;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_SSE3:
|
2010-01-15 16:23:57 +01:00
|
|
|
return ecx & CPUID1_ECX_SSE3;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_SSSE3:
|
2010-01-15 16:23:57 +01:00
|
|
|
return ecx & CPUID1_ECX_SSSE3;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_SSE4_1:
|
2010-01-15 16:23:57 +01:00
|
|
|
return ecx & CPUID1_ECX_SSE4_1;
|
2009-12-02 14:01:48 +01:00
|
|
|
case _CPUF_I386_SSE4_2:
|
2010-01-15 16:23:57 +01:00
|
|
|
return ecx & CPUID1_ECX_SSE4_2;
|
|
|
|
case _CPUF_I386_HTT:
|
|
|
|
return edx & CPUID1_EDX_HTT;
|
|
|
|
case _CPUF_I386_HTT_MAX_NUM:
|
|
|
|
return (ebx >> 16) & 0xff;
|
2009-05-15 19:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|