lsflib/tools/cpuid.c
changeset 6 c3dc3eb3b541
child 77 49e0babccb23
equal deleted inserted replaced
5:d752cbe8208e 6:c3dc3eb3b541
       
     1 /*
       
     2  * cpuinfo.c
       
     3  */
       
     4 
       
     5 #include <cpuid.h>
       
     6 
       
     7 char *get_cpu_brand (int function)
       
     8 {
       
     9     ULONG brand[4];
       
    10 
       
    11     static char s[48];
       
    12 
       
    13   __asm__ ("cpuid":"=a" (brand[0]), "=b" (brand[1]), "=c" (brand[2]), "=d" (brand[3])
       
    14   :         "a" (function)
       
    15         );
       
    16 
       
    17     memcpy (s, brand, sizeof (brand));
       
    18     return s;
       
    19 }
       
    20 
       
    21 char *get_cpu_vendor ()
       
    22 {
       
    23     ULONG vendor[3];
       
    24     static char s[15];
       
    25 
       
    26     *s = 0;
       
    27 
       
    28   __asm__ ("cpuid":"=b" (vendor[0]), "=d" (vendor[1]), "=c" (vendor[2])
       
    29   :         "a" (0)
       
    30         );
       
    31 
       
    32     memcpy (s, vendor, sizeof (vendor));
       
    33     return s;
       
    34 }
       
    35 
       
    36 ULONG get_cpu_function (ULONG function, ULONG * ax, ULONG * bx, ULONG * cx, ULONG * dx)
       
    37 {
       
    38   __asm__ ("cpuid":"=a" (*ax), "=b" (*bx), "=c" (*cx), "=d" (*dx)
       
    39   :         "a" (function)
       
    40         );
       
    41 
       
    42     return (ULONG) (*ax);
       
    43 }