]> git.ozlabs.org Git - ccan/blob - ccan/cpuid/test/run.c
cpuid: add 2 new functions + some more tests
[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         char buf[128];
14         cpuid(CPU_VENDORID, buf);
15         printf ("Vendor ID: %s\n", buf);
16
17         cpuid(CPU_PROC_BRAND_STRING, buf);
18         printf ("Processor Brand: %s\n", buf);
19
20         int addr;
21         cpuid(CPU_HIGHEST_EXTENDED_FUNCTION_SUPPORTED, &addr);
22         printf ("Highest extended function supported: %#010x\n", addr);
23
24         union {
25                 struct {
26                         uint32_t phys_bits : 8;
27                         uint32_t virt_bits : 8;
28                         uint32_t reserved  : 16;
29                 };
30                 uint32_t w;
31         } s;
32         cpuid(CPU_VIRT_PHYS_ADDR_SIZES, &s.w);
33         printf ("Physical address size: %d\nVirtual: %d\n", s.phys_bits, s.virt_bits);
34
35         int extfeatures[2];
36         cpuid(CPU_EXTENDED_PROC_INFO_FEATURE_BITS, extfeatures);
37         printf ("Extended processor info and feature bits: %d %d\n", extfeatures[0], extfeatures[1]);
38
39         union {
40                 struct {
41                         uint32_t line_size : 8;
42                         uint32_t reserved : 4;
43                         uint32_t assoc : 4;
44                         uint32_t cache_size : 16;
45                 };
46
47                 uint32_t w;
48         } l2c;
49
50         cpuid(CPU_EXTENDED_L2_CACHE_FEATURES, &l2c.w);
51         printf ("L2 Cache Size: %u KB\tLine Size: %u bytes\tAssociativity: %02xh\n",
52                         l2c.cache_size, l2c.line_size, l2c.assoc);
53
54         int invalid;
55         cpuid(0x0ffffffUL, &invalid);
56         printf ("Testing invalid: %#010x\n", invalid);
57         return 0;
58 }