From e05de3375f2587c32be2c7ad6ddd125fa1b6092e Mon Sep 17 00:00:00 2001 From: msaitoh Date: Mon, 23 Dec 2013 12:35:33 +0000 Subject: [PATCH] Add verbose flag. On x86 cpu, cpuctl -v identify dumps the return values of the cpuid functions. The max levels are taken from CPUID 0 and CPUID 8000_0000. It's useful for the future CPU. --- usr.sbin/cpuctl/arch/i386.c | 26 ++++++++++++++++++++++++-- usr.sbin/cpuctl/cpuctl.8 | 11 +++++++++-- usr.sbin/cpuctl/cpuctl.c | 24 ++++++++++++++++++------ usr.sbin/cpuctl/cpuctl.h | 4 +++- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/usr.sbin/cpuctl/arch/i386.c b/usr.sbin/cpuctl/arch/i386.c index 3a5d97126139..b2a4e27e6c2e 100644 --- a/usr.sbin/cpuctl/arch/i386.c +++ b/usr.sbin/cpuctl/arch/i386.c @@ -1,4 +1,4 @@ -/* $NetBSD: i386.c,v 1.52 2013/12/23 11:17:20 msaitoh Exp $ */ +/* $NetBSD: i386.c,v 1.53 2013/12/23 12:35:33 msaitoh Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ #include #ifndef lint -__RCSID("$NetBSD: i386.c,v 1.52 2013/12/23 11:17:20 msaitoh Exp $"); +__RCSID("$NetBSD: i386.c,v 1.53 2013/12/23 12:35:33 msaitoh Exp $"); #endif /* not lint */ #include @@ -1432,6 +1432,17 @@ cpu_probe_base_features(struct cpu_info *ci, const char *cpuname) ci->ci_vendor[2] = descs[2]; ci->ci_vendor[1] = descs[3]; ci->ci_vendor[3] = 0; + if (verbose) { + int bf; + + printf("%s: cpuid basic function max = %08x\n", cpuname, + descs[0]); + for (bf = 0; bf <= ci->ci_cpuid_level; bf++) { + x86_cpuid(bf, descs); + printf("%s: %08x: %08x %08x %08x %08x\n", cpuname, + bf, descs[0], descs[1], descs[2], descs[3]); + } + } /* * Fn8000_0000: @@ -1444,6 +1455,17 @@ cpu_probe_base_features(struct cpu_info *ci, const char *cpuname) /* Set lower value than 0x80000000 */ ci->ci_cpuid_extlevel = 0; } + if (verbose) { + unsigned int ef; + + printf("%s: cpuid extended function max = %08x\n", cpuname, + descs[0]); + for (ef = 0x80000000; ef <= ci->ci_cpuid_extlevel; ef++) { + x86_cpuid(ef, descs); + printf("%s: %08x: %08x %08x %08x %08x\n", cpuname, + ef, descs[0], descs[1], descs[2], descs[3]); + } + } /* * Fn8000_000[2-4]: diff --git a/usr.sbin/cpuctl/cpuctl.8 b/usr.sbin/cpuctl/cpuctl.8 index 0b1922ff558c..fd0d0ac38a37 100644 --- a/usr.sbin/cpuctl/cpuctl.8 +++ b/usr.sbin/cpuctl/cpuctl.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: cpuctl.8,v 1.9 2012/03/15 22:35:03 njoly Exp $ +.\" $NetBSD: cpuctl.8,v 1.10 2013/12/23 12:35:33 msaitoh Exp $ .\" .\" Copyright (c) 2007, 2008, 2012 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 13, 2012 +.Dd December 23, 2013 .Dt CPUCTL 8 .Os .Sh NAME @@ -35,6 +35,7 @@ .Nd program to control CPUs .Sh SYNOPSIS .Nm cpuctl +.Op Fl v .Ar command .Op Ar arguments .Sh DESCRIPTION @@ -76,6 +77,12 @@ On success the .Cm identify command show different ucode versions before and after this command. .El +.Pp +Valid flag is: +.Bl -tag -width indent +.It Fl v +Be more verbose. +.El .Sh FILES .Bl -tag -width /dev/cpuctl -compact .It Pa /dev/cpuctl diff --git a/usr.sbin/cpuctl/cpuctl.c b/usr.sbin/cpuctl/cpuctl.c index c4645a065687..8b399f63265d 100644 --- a/usr.sbin/cpuctl/cpuctl.c +++ b/usr.sbin/cpuctl/cpuctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpuctl.c,v 1.22 2013/01/31 19:47:59 matt Exp $ */ +/* $NetBSD: cpuctl.c,v 1.23 2013/12/23 12:35:33 msaitoh Exp $ */ /*- * Copyright (c) 2007, 2008, 2009, 2012 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #ifndef lint #include -__RCSID("$NetBSD: cpuctl.c,v 1.22 2013/01/31 19:47:59 matt Exp $"); +__RCSID("$NetBSD: cpuctl.c,v 1.23 2013/12/23 12:35:33 msaitoh Exp $"); #endif /* not lint */ #include @@ -82,26 +82,38 @@ static struct cmdtab { }; static int fd; +int verbose; int main(int argc, char **argv) { const struct cmdtab *ct; + int ch; - if (argc < 2) + while ((ch = getopt(argc, argv, "v")) != -1) + switch (ch) { + case 'v': + verbose = 1; + break; + default: + usage(); + } + argc -= optind; + argv += optind; + if (argc < 1) usage(); if ((fd = open(_PATH_CPUCTL, O_RDWR)) < 0) err(EXIT_FAILURE, _PATH_CPUCTL); for (ct = cpu_cmdtab; ct->label != NULL; ct++) { - if (strcmp(argv[1], ct->label) == 0) { + if (strcmp(argv[0], ct->label) == 0) { if (!ct->argsoptional && - ((ct->takesargs == 0) ^ (argv[2] == NULL))) + ((ct->takesargs == 0) ^ (argv[1] == NULL))) { usage(); } - (*ct->func)(argv + 2); + (*ct->func)(argv + 1); break; } } diff --git a/usr.sbin/cpuctl/cpuctl.h b/usr.sbin/cpuctl/cpuctl.h index 4f066c51c27c..b04f719ef4ad 100644 --- a/usr.sbin/cpuctl/cpuctl.h +++ b/usr.sbin/cpuctl/cpuctl.h @@ -1,4 +1,4 @@ -/* $NetBSD: cpuctl.h,v 1.4 2012/08/29 17:13:23 drochner Exp $ */ +/* $NetBSD: cpuctl.h,v 1.5 2013/12/23 12:35:33 msaitoh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -35,3 +35,5 @@ int aprint_error_dev(const char *, const char *, ...) __printflike(2, 3); void identifycpu(int, const char *); int ucodeupdate_check(int, struct cpu_ucode *); + +extern int verbose;