aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-02-07 00:09:31 -0800
committerH. Peter Anvin <hpa@zytor.com>2010-02-07 00:09:31 -0800
commit7def7a90e13cfb9a25fdb89029c977653a47e04f (patch)
treebb728ce04a370b3853e61014f9cd67692372a21e
parent640825ec66c2f02504a689d160350133bd968a46 (diff)
downloadsyslinux.git-7def7a90e13cfb9a25fdb89029c977653a47e04f.tar.gz
syslinux.git-7def7a90e13cfb9a25fdb89029c977653a47e04f.tar.xz
syslinux.git-7def7a90e13cfb9a25fdb89029c977653a47e04f.zip
sysdump: dump CPUID informationsyslinux-3.85-pre7
Dump CPUID information in as generic of a way as is possible, given the ugliness in certain places. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--com32/sysdump/cpuid.c112
-rw-r--r--com32/sysdump/main.c1
-rw-r--r--com32/sysdump/sysdump.h2
3 files changed, 115 insertions, 0 deletions
diff --git a/com32/sysdump/cpuid.c b/com32/sysdump/cpuid.c
new file mode 100644
index 00000000..40b20618
--- /dev/null
+++ b/com32/sysdump/cpuid.c
@@ -0,0 +1,112 @@
+/*
+ * Dump CPUID information
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <com32.h>
+#include <sys/cpu.h>
+#include "sysdump.h"
+#include "backend.h"
+
+struct cpuid_data {
+ uint32_t eax, ebx, ecx, edx;
+};
+
+struct cpuid_info {
+ uint32_t eax, ecx;
+ struct cpuid_data data;
+};
+
+static bool has_eflag(uint32_t flag)
+{
+ uint32_t f0, f1;
+
+ asm("pushfl ; "
+ "pushfl ; "
+ "popl %0 ; "
+ "movl %0,%1 ; "
+ "xorl %2,%1 ; "
+ "pushl %1 ; "
+ "popfl ; "
+ "pushfl ; "
+ "popl %1 ; "
+ "popfl"
+ : "=&r" (f0), "=&r" (f1)
+ : "ri" (flag));
+
+ return !!((f0^f1) & flag);
+}
+
+static inline void get_cpuid(uint32_t eax, uint32_t ecx,
+ struct cpuid_data *data)
+{
+ asm("cpuid"
+ : "=a" (data->eax), "=b" (data->ebx),
+ "=c" (data->ecx), "=d" (data->edx)
+ : "a" (eax), "c" (ecx));
+}
+
+#define CPUID_CHUNK 128
+
+void dump_cpuid(struct backend *be)
+{
+ struct cpuid_info *buf = NULL;
+ int nentry, nalloc;
+ uint32_t region;
+ struct cpuid_data base_leaf;
+ uint32_t base, leaf, count;
+ struct cpuid_data invalid_leaf;
+ struct cpuid_data data;
+
+ if (!has_eflag(EFLAGS_ID))
+ return;
+
+ printf("Dumping CPUID... ");
+
+ nentry = nalloc = 0;
+
+ /* Find out what the CPU returns for invalid leaves */
+ get_cpuid(0, 0, &base_leaf);
+ get_cpuid(base_leaf.eax+1, 0, &invalid_leaf);
+
+ for (region = 0 ; region <= 0xffff ; region++) {
+ base = region << 16;
+
+ get_cpuid(base, 0, &base_leaf);
+ if (region && !memcmp(&base_leaf, &invalid_leaf, sizeof base_leaf))
+ continue;
+
+ if ((base_leaf.eax ^ base) & 0xffff0000)
+ continue;
+
+ for (leaf = base ; leaf <= base_leaf.eax ; leaf++) {
+ get_cpuid(leaf, 0, &data);
+ count = 0;
+
+ do {
+ if (nentry >= nalloc) {
+ nalloc += CPUID_CHUNK;
+ buf = realloc(buf, nalloc*sizeof *buf);
+ if (!buf)
+ return; /* FAILED */
+ }
+ buf[nentry].eax = leaf;
+ buf[nentry].ecx = count;
+ buf[nentry].data = data;
+ nentry++;
+ count++;
+
+ get_cpuid(leaf, count, &data);
+ } while (memcmp(&data, &buf[nentry-1].data, sizeof data) &&
+ (data.eax | data.ebx | data.ecx | data.edx));
+ }
+ }
+
+ if (nentry)
+ cpio_writefile(be, "cpuid", buf, nentry*sizeof *buf);
+ free(buf);
+
+ printf("done.\n");
+}
diff --git a/com32/sysdump/main.c b/com32/sysdump/main.c
index fd3fc934..c231c29e 100644
--- a/com32/sysdump/main.c
+++ b/com32/sysdump/main.c
@@ -37,6 +37,7 @@ static void dump_all(struct backend *be, const char *argv[], size_t len)
dump_memory_map(be);
dump_memory(be);
dump_dmi(be);
+ dump_cpuid(be);
dump_pci(be);
dump_vesa_tables(be);
diff --git a/com32/sysdump/sysdump.h b/com32/sysdump/sysdump.h
index f2c8f7a0..61a04a2b 100644
--- a/com32/sysdump/sysdump.h
+++ b/com32/sysdump/sysdump.h
@@ -4,8 +4,10 @@
struct backend;
void dump_memory_map(struct backend *);
+void snapshot_lowmem(void);
void dump_memory(struct backend *);
void dump_dmi(struct backend *);
+void dump_cpuid(struct backend *);
void dump_pci(struct backend *);
void dump_vesa_tables(struct backend *);