]> git.ozlabs.org Git - ccan/blob - ccan/cpuid/test/run.c
cpuid: avoid unions in parsing data
[ccan] / ccan / cpuid / test / run.c
1 #include "../cpuid.c"
2
3 #include <stdio.h>
4 #include <stdint.h>
5
6 int main(void)
7 {
8         if (!cpuid_is_supported()) {
9                 printf ("CPUID instruction is not supported by this CPU\n");
10                 return 1;
11         }
12
13         printf ("Vendor ID: %s\n", cpuid_get_cpu_type_string (cpuid_get_cpu_type ()));
14
15         char buf[48];
16         cpuid(CPU_PROC_BRAND_STRING, (uint32_t *)buf);
17         printf ("Processor Brand: %s\n", buf);
18
19         printf ("Highest extended function supported: %#010x\n", cpuid_highest_ext_func_supported());
20
21         uint32_t phys_virt[2];
22         cpuid(CPU_VIRT_PHYS_ADDR_SIZES, phys_virt);
23         printf ("Physical address size: %d\nVirtual address size: %d\n", phys_virt[0], phys_virt[1]);
24
25         uint32_t extfeatures[2];
26         cpuid(CPU_EXTENDED_PROC_INFO_FEATURE_BITS, extfeatures);
27         printf ("Extended processor info and feature bits: %d %d\n", extfeatures[0], extfeatures[1]);
28
29         uint32_t l2c[3];
30         cpuid(CPU_EXTENDED_L2_CACHE_FEATURES, l2c);
31         printf("L2 Line size: %u bytes\tAssociativity: %02xh\tCache Size: %u KB\n",
32                 l2c[0], l2c[1], l2c[2]);
33
34         uint32_t invalid;
35         cpuid(0x0ffffffUL, &invalid);
36         printf ("Testing invalid: %#010x\n", invalid);
37         return 0;
38 }