Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "cpu_features.h"
  3.  
  4. /* level 1 edx bits */
  5. #define EDX_CX8     (1 << 8)    /* CMPXCHG8B */
  6. #define EDX_CMOV    (1 << 15)
  7. #define EDX_MMX     (1 << 23)
  8. #define EDX_FXSR    (1 << 24)   /* FXSAVE and FXRSTOR */
  9. #define EDX_SSE     (1 << 25)
  10. #define EDX_SSE2    (1 << 26)
  11.  
  12. /*  level 1 ecx bits */
  13. #define ECX_SSE3    (1 << 0)
  14. #define ECX_CX16    (1 << 13)   /* CMPXCHG16B */
  15.  
  16. /* extended level 0x80000001 edx bits */
  17. #define EDX_3DNOW   (1 << 31)
  18. #define EDX_3DNOWP  (1 << 30)
  19. #define EDX_LM      (1 << 29)   /*LONG MODE */
  20.  
  21. #define __cpuid(level,a,b,c,d)                                  \
  22.   __asm__ __volatile__ ("cpuid;"                                \
  23.                         : "=a" (a), "=b" (b), "=c" (c), "=d" (d)\
  24.                         : "0" (level))
  25.  
  26. /* Combine the different cpuid flags into a single bitmap.  */
  27.  
  28. unsigned int __cpu_features = 0;
  29.  
  30. void  __cpu_features_init (void)
  31. {
  32.     unsigned int eax, ebx, ecx, edx;
  33.  
  34.   __cpuid (0, eax, ebx, ecx, edx);
  35.   if (eax == 0)
  36.     return;
  37.  
  38.   __cpuid (1, eax, ebx, ecx, edx);
  39.  
  40.   if (edx & EDX_CX8)
  41.      __cpu_features |= _CRT_CMPXCHG8B;
  42.   if (edx & EDX_CMOV)
  43.      __cpu_features |= _CRT_CMOV;
  44.  
  45.   if (edx & EDX_MMX)
  46.      __cpu_features |= _CRT_MMX;
  47.   if (edx & EDX_FXSR)
  48.      __cpu_features |= _CRT_FXSR;
  49.   if (edx & EDX_SSE)
  50.      __cpu_features |= _CRT_SSE;
  51.   if (edx & EDX_SSE2)
  52.      __cpu_features |= _CRT_SSE2;
  53.  
  54.  
  55.   if (ecx & ECX_SSE3)
  56.      __cpu_features |= _CRT_SSE3;
  57.   if (ecx & ECX_CX16)
  58.      __cpu_features |= _CRT_CMPXCHG16B;
  59.  
  60.   __cpuid (0x80000000, eax, ebx, ecx, edx);
  61.   if (eax < 0x80000001)
  62.     return;
  63.   __cpuid (0x80000001, eax, ebx, ecx, edx);
  64.   if (edx & EDX_3DNOW)
  65.     __cpu_features |= _CRT_3DNOW;
  66.   if (edx & EDX_3DNOWP)
  67.     __cpu_features |= _CRT_3DNOWP;
  68.  
  69.   return;
  70. }
  71.  
  72.  
  73.