]> git.ozlabs.org Git - ccan/blob - ccan/cpuid/test/run.c
c96f3ab8dba0ed5b9ad5fc71e16aa94bbef11356
[ccan] / ccan / cpuid / test / run.c
1 #include "cpuid.h"
2
3 #include <stdio.h>
4 #include <stdint.h>
5
6 int main()
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         union {
22                 struct {
23                         uint32_t phys_bits : 8;
24                         uint32_t virt_bits : 8;
25                         uint32_t reserved  : 16;
26                 };
27                 uint32_t w;
28         } s;
29         cpuid(CPU_VIRT_PHYS_ADDR_SIZES, &s.w);
30         printf ("Physical address size: %d\nVirtual: %d\n", s.phys_bits, s.virt_bits);
31
32         uint32_t extfeatures[2];
33         cpuid(CPU_EXTENDED_PROC_INFO_FEATURE_BITS, extfeatures);
34         printf ("Extended processor info and feature bits: %d %d\n", extfeatures[0], extfeatures[1]);
35
36         union {
37                 struct {
38                         uint32_t line_size : 8;
39                         uint32_t reserved : 4;
40                         uint32_t assoc : 4;
41                         uint32_t cache_size : 16;
42                 };
43
44                 uint32_t w;
45         } l2c;
46
47         cpuid(CPU_EXTENDED_L2_CACHE_FEATURES, &l2c.w);
48         printf ("L2 Cache Size: %u KB\tLine Size: %u bytes\tAssociativity: %02xh\n",
49                         l2c.cache_size, l2c.line_size, l2c.assoc);
50
51         uint32_t invalid;
52         cpuid(0x0ffffffUL, &invalid);
53         printf ("Testing invalid: %#010x\n", invalid);
54         return 0;
55 }
56