Adding upstream version 4.00~pre61+dfsg.
[syslinux-debian/hramrach.git] / com32 / modules / cpuid.c
blob78cb3f58fec370ac2eb613124fb4770673b8b2a3
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2010 Intel Corporation; author: H. Peter Anvin
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <sys/cpu.h>
16 #include <console.h>
17 #include <com32.h>
19 static void dump_reg(const char *name, uint32_t val)
21 int i;
23 printf("%-3s : %10u 0x%08x ", name, val, val);
25 for (i = 3; i >= 0; i--) {
26 uint8_t c = val >> (i*8);
27 putchar((c >= ' ' && c <= '~') ? c : '.');
29 putchar('\n');
32 int main(int argc, char *argv[])
34 uint32_t leaf, counter;
35 uint32_t eax, ebx, ecx, edx;
37 openconsole(&dev_null_r, &dev_stdcon_w);
39 if (argc < 2 || argc > 4) {
40 printf("Usage: %s leaf [counter]\n", argv[0]);
41 exit(1);
44 leaf = strtoul(argv[1], NULL, 0);
45 counter = (argc > 2) ? strtoul(argv[2], NULL, 0) : 0;
47 if (!cpu_has_eflag(EFLAGS_ID)) {
48 printf("The CPUID instruction is not supported\n");
49 exit(1);
52 cpuid_count(leaf, counter, &eax, &ebx, &ecx, &edx);
54 dump_reg("eax", eax);
55 dump_reg("ebx", ebx);
56 dump_reg("ecx", ecx);
57 dump_reg("edx", edx);
59 return 0;