summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jones <davej@redhat.com>2011-02-22 16:57:37 -0500
committerDave Jones <davej@redhat.com>2011-02-22 16:57:37 -0500
commit011991ec8c4163e770cfc87e6876763cea5aee12 (patch)
tree040e874851b483680fad4ccc23532a3cb27784fe
parent1301ab544fcff60d5839247ff8d7d118186b0fa3 (diff)
split the command line parsing out
-rw-r--r--Makefile1
-rw-r--r--commandline.c178
-rw-r--r--x86info.c167
-rw-r--r--x86info.h46
4 files changed, 206 insertions, 186 deletions
diff --git a/Makefile b/Makefile
index 781857f..fc367ac 100644
--- a/Makefile
+++ b/Makefile
@@ -77,6 +77,7 @@ X86INFO_SRC =\
SiS/identify.c\
\
x86info.c\
+ commandline.c\
havecpuid.c\
cpuid.c\
dumpregs.c\
diff --git a/commandline.c b/commandline.c
new file mode 100644
index 0000000..ded0a30
--- /dev/null
+++ b/commandline.c
@@ -0,0 +1,178 @@
+/*
+ * (C) 2011 Dave Jones.
+ *
+ * Licensed under the terms of the GNU GPL License version 2.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "x86info.h"
+
+unsigned int show_apic = 0;
+unsigned int show_bench = 0;
+unsigned int show_bios = 0;
+unsigned int show_machine_check = 0;
+unsigned int show_bugs = 0;
+unsigned int show_cacheinfo = 0;
+unsigned int show_connector = 0;
+unsigned int show_eblcr = 0;
+unsigned int show_msr = 0;
+unsigned int show_microcode = 0;
+unsigned int show_mtrr = 0;
+unsigned int show_pm = 0;
+unsigned int show_registers = 0;
+unsigned int show_urls = 0;
+unsigned int show_mptable = 0;
+unsigned int show_flags = 0;
+unsigned int show_MHz = 0;
+unsigned int show_addr_sizes = 0;
+unsigned int all_cpus = 0;
+
+unsigned int debug = 0;
+unsigned int verbose = 0;
+unsigned int need_root = 0;
+
+
+static void usage(char *programname)
+{
+ printf("Usage: %s [<switches>]\n\
+-a, --all\n\
+ --all-cpus\n\
+ --addr\n\
+ --apic\n\
+ --bench\n\
+ --bios\n\
+ --bugs\n\
+-c, --cache\n\
+ --connector\n\
+ --debug\n\
+-f, --flags\n\
+-mce, --show-machine-check\n\
+-mhz, --mhz\n\
+ --microcode\n\
+-mp, --mptable\n\
+-m, --msr\n\
+ --mult\n\
+ --mtrr\n\
+ --pm\n\
+-r, --registers\n\
+-u, --urls\n\
+-v, --verbose\n\
+\n", programname);
+ exit (0);
+}
+
+void parse_command_line(int argc, char **argv)
+{
+ char **argp, *arg;
+
+ for (argp = argv+1; argp <= argv + argc && (arg = *argp); argp++) {
+ if ((!strcmp(arg, "-a") || !strcmp(arg, "--all"))) {
+
+ if (user_is_root) {
+ show_apic = 1;
+ show_bios = 1;
+ show_msr = 1;
+ show_microcode = 1;
+ need_root = 1;
+ show_mptable =1;
+ show_mtrr = 1;
+ show_machine_check = 1;
+ show_eblcr =1;
+ }
+ show_addr_sizes = 1;
+ show_bugs = 1;
+ show_cacheinfo = 1;
+ show_connector = 1;
+ show_flags = 1;
+ show_MHz = 1;
+ show_pm = 1;
+ show_registers = 1;
+ show_urls = 1;
+ }
+
+ if (!strcmp(arg, "--all-cpus"))
+ all_cpus = 1;
+
+ if (!strcmp(arg, "--addr"))
+ show_addr_sizes = 1;
+
+ if (!strcmp(arg, "--apic")) {
+ need_root = 1;
+ show_apic = 1;
+ }
+
+ if (!strcmp(arg, "--bench"))
+ show_bench = 1;
+
+ if (!strcmp(arg, "--bios")) {
+ need_root = 1;
+ show_bios = 1;
+ }
+
+ if (!strcmp(arg, "--bugs"))
+ show_bugs = 1;
+
+ if ((!strcmp(arg, "-c") || !strcmp(arg, "--cache")))
+ show_cacheinfo = 1;
+
+ if (!strcmp(arg, "--connector"))
+ show_connector = 1;
+
+ if (!strcmp(arg, "--debug"))
+ debug = 1;
+
+ if ((!strcmp(arg, "-f") || !strcmp(arg, "--flags")))
+ show_flags = 1;
+
+ if ((!strcmp(arg, "-m") || !strcmp(arg, "--msr"))) {
+ need_root = 1;
+ show_msr = 1;
+ }
+
+ if (!strcmp(arg, "--microcode")) {
+ need_root = 1;
+ show_microcode = 1;
+ }
+
+ if ((!strcmp(arg, "-mhz") || !strcmp(arg, "--mhz")))
+ show_MHz = 1;
+
+ if ((!strcmp(arg, "-mp") || !strcmp(arg, "--mptable"))) {
+ need_root = 1;
+ show_mptable = 1;
+ }
+
+ if (!strcmp(arg, "--mtrr")) {
+ need_root = 1;
+ show_mtrr = 1;
+ }
+
+ if (!strcmp(arg, "--mult")) {
+ need_root = 1;
+ show_eblcr = 1;
+ }
+
+ if (!strcmp(arg, "--pm"))
+ show_pm = 1;
+
+ if ((!strcmp(arg, "-r") || !strcmp(arg, "--registers")))
+ show_registers = 1;
+
+ if ((!strcmp(arg, "-mce") || !strcmp(arg, "--show-machine-check"))) {
+ need_root = 1;
+ show_machine_check = 1;
+ }
+
+ if ((!strcmp(arg, "-u") || !strcmp(arg, "--urls")))
+ show_urls = 1;
+
+ if ((!strcmp(arg, "-v") || !strcmp(arg, "--verbose")))
+ verbose = 1;
+
+ if ((!strcmp(arg, "?") || !strcmp(arg, "--help")))
+ usage(argv[0]);
+ }
+}
diff --git a/x86info.c b/x86info.c
index 4835a82..6ba04a4 100644
--- a/x86info.c
+++ b/x86info.c
@@ -14,181 +14,14 @@
#include "Intel/Intel.h"
-int show_apic=0;
-int show_bench=0;
-int show_bios=0;
-int show_machine_check=0;
-int show_bugs=0;
-int show_cacheinfo=0;
-int show_connector=0;
-int show_eblcr=0;
-int show_msr=0;
-int show_microcode=0;
-int show_mtrr=0;
-int show_pm=0;
-int show_registers=0;
-int show_urls=0;
-
-static int show_mptable=0;
-static int show_flags=0;
-static int show_MHz=0;
-static int show_addr_sizes=0;
-
-unsigned int all_cpus = 0;
-
-int debug = 0;
-int verbose = 0;
int used_UP = 0;
int user_is_root = 0;
-static int need_root = 0;
unsigned int nrCPUs=1;
static unsigned int nrSMPCPUs;
struct cpudata *firstcpu;
-static void usage (char *programname)
-{
- printf("Usage: %s [<switches>]\n\
--a, --all\n\
- --all-cpus\n\
- --addr\n\
- --apic\n\
- --bench\n\
- --bios\n\
- --bugs\n\
--c, --cache\n\
- --connector\n\
- --debug\n\
--f, --flags\n\
--mce, --show-machine-check\n\
--mhz, --mhz\n\
- --microcode\n\
--mp, --mptable\n\
--m, --msr\n\
- --mult\n\
- --mtrr\n\
- --pm\n\
--r, --registers\n\
--u, --urls\n\
--v, --verbose\n\
-\n", programname);
- exit (0);
-}
-
-static void parse_command_line (int argc, char **argv)
-{
- char **argp, *arg;
-
- for (argp = argv+1; argp <= argv + argc && (arg = *argp); argp++) {
- if ((!strcmp(arg, "-a") || !strcmp(arg, "--all"))) {
-
- if (user_is_root) {
- show_apic = 1;
- show_bios = 1;
- show_msr = 1;
- show_microcode = 1;
- need_root = 1;
- show_mptable =1;
- show_mtrr = 1;
- show_machine_check = 1;
- show_eblcr =1;
- }
- show_addr_sizes = 1;
- show_bugs = 1;
- show_cacheinfo = 1;
- show_connector = 1;
- show_flags = 1;
- show_MHz = 1;
- show_pm = 1;
- show_registers = 1;
- show_urls = 1;
- }
-
- if (!strcmp(arg, "--all-cpus"))
- all_cpus = 1;
-
- if (!strcmp(arg, "--addr"))
- show_addr_sizes = 1;
-
- if (!strcmp(arg, "--apic")) {
- need_root = 1;
- show_apic = 1;
- }
-
- if (!strcmp(arg, "--bench"))
- show_bench = 1;
-
- if (!strcmp(arg, "--bios")) {
- need_root = 1;
- show_bios = 1;
- }
-
- if (!strcmp(arg, "--bugs"))
- show_bugs = 1;
-
- if ((!strcmp(arg, "-c") || !strcmp(arg, "--cache")))
- show_cacheinfo = 1;
-
- if (!strcmp(arg, "--connector"))
- show_connector = 1;
-
- if (!strcmp(arg, "--debug"))
- debug = 1;
-
- if ((!strcmp(arg, "-f") || !strcmp(arg, "--flags")))
- show_flags = 1;
-
- if ((!strcmp(arg, "-m") || !strcmp(arg, "--msr"))) {
- need_root = 1;
- show_msr = 1;
- }
-
- if (!strcmp(arg, "--microcode")) {
- need_root = 1;
- show_microcode = 1;
- }
-
- if ((!strcmp(arg, "-mhz") || !strcmp(arg, "--mhz")))
- show_MHz = 1;
-
- if ((!strcmp(arg, "-mp") || !strcmp(arg, "--mptable"))) {
- need_root = 1;
- show_mptable = 1;
- }
-
- if (!strcmp(arg, "--mtrr")) {
- need_root = 1;
- show_mtrr = 1;
- }
-
- if (!strcmp(arg, "--mult")) {
- need_root = 1;
- show_eblcr = 1;
- }
-
- if (!strcmp(arg, "--pm"))
- show_pm = 1;
-
- if ((!strcmp(arg, "-r") || !strcmp(arg, "--registers")))
- show_registers = 1;
-
- if ((!strcmp(arg, "-mce") || !strcmp(arg, "--show-machine-check"))) {
- need_root = 1;
- show_machine_check = 1;
- }
-
- if ((!strcmp(arg, "-u") || !strcmp(arg, "--urls")))
- show_urls = 1;
-
- if ((!strcmp(arg, "-v") || !strcmp(arg, "--verbose")))
- verbose = 1;
-
- if ((!strcmp(arg, "?") || !strcmp(arg, "--help")))
- usage(argv[0]);
- }
-}
-
static void separator(void)
{
diff --git a/x86info.h b/x86info.h
index 8870551..78588f7 100644
--- a/x86info.h
+++ b/x86info.h
@@ -145,6 +145,8 @@ extern void display_features(struct cpudata *cpu);
extern void show_extra_intel_flags(struct cpudata *cpu);
#define X86_FEATURE_HT (1<<28)
+void parse_command_line(int argc, char **argv);
+
extern void get_cpu_info_basics(struct cpudata *cpu);
extern void identify(struct cpudata *cpu);
extern void show_info(struct cpudata *cpu);
@@ -174,31 +176,37 @@ extern void show_intel_topology(struct cpudata *cpu);
void decode_AMD_cacheinfo(struct cpudata *cpu);
-extern int show_bench;
-extern int show_bios;
-extern int show_machine_check;
-extern int show_bugs;
-extern int show_cacheinfo;
-extern int show_connector;
-extern int show_eblcr;
-extern int verbose;
-extern int show_microcode;
-extern int show_msr;
-extern int show_mtrr;
-extern int show_pm;
-extern int show_registers;
-extern int show_urls;
-
extern unsigned int nrCPUs;
-extern unsigned int all_cpus;
-
extern struct cpudata *firstcpu;
extern int used_UP;
extern int user_is_root;
-
-extern int debug;
+extern unsigned int need_root;
+
+
+/* command line args */
+extern unsigned int show_apic;
+extern unsigned int show_bench;
+extern unsigned int show_bios;
+extern unsigned int show_machine_check;
+extern unsigned int show_bugs;
+extern unsigned int show_cacheinfo;
+extern unsigned int show_connector;
+extern unsigned int show_eblcr;
+extern unsigned int show_msr;
+extern unsigned int show_microcode;
+extern unsigned int show_mtrr;
+extern unsigned int show_pm;
+extern unsigned int show_registers;
+extern unsigned int show_urls;
+extern unsigned int show_mptable;
+extern unsigned int show_flags;
+extern unsigned int show_MHz;
+extern unsigned int show_addr_sizes;
+extern unsigned int all_cpus;
+extern unsigned int debug;
+extern unsigned int verbose;
#define X86_FEATURE_MTRR 1<<12
#define X86_FEATURE_APIC 1<<9