Module Name:    src
Committed By:   msaitoh
Date:           Mon Dec 23 12:35:33 UTC 2013

Modified Files:
        src/usr.sbin/cpuctl: cpuctl.8 cpuctl.c cpuctl.h
        src/usr.sbin/cpuctl/arch: i386.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/cpuctl/cpuctl.8
cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/cpuctl/cpuctl.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/cpuctl/cpuctl.h
cvs rdiff -u -r1.52 -r1.53 src/usr.sbin/cpuctl/arch/i386.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/cpuctl/cpuctl.8
diff -u src/usr.sbin/cpuctl/cpuctl.8:1.9 src/usr.sbin/cpuctl/cpuctl.8:1.10
--- src/usr.sbin/cpuctl/cpuctl.8:1.9	Thu Mar 15 22:35:03 2012
+++ src/usr.sbin/cpuctl/cpuctl.8	Mon Dec 23 12:35:33 2013
@@ -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

Index: src/usr.sbin/cpuctl/cpuctl.c
diff -u src/usr.sbin/cpuctl/cpuctl.c:1.22 src/usr.sbin/cpuctl/cpuctl.c:1.23
--- src/usr.sbin/cpuctl/cpuctl.c:1.22	Thu Jan 31 19:47:59 2013
+++ src/usr.sbin/cpuctl/cpuctl.c	Mon Dec 23 12:35:33 2013
@@ -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 <sys/cdefs.h>
-__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 <sys/param.h>
@@ -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;
 		}
 	}

Index: src/usr.sbin/cpuctl/cpuctl.h
diff -u src/usr.sbin/cpuctl/cpuctl.h:1.4 src/usr.sbin/cpuctl/cpuctl.h:1.5
--- src/usr.sbin/cpuctl/cpuctl.h:1.4	Wed Aug 29 17:13:23 2012
+++ src/usr.sbin/cpuctl/cpuctl.h	Mon Dec 23 12:35:33 2013
@@ -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
 
 void	identifycpu(int, const char *);
 int	ucodeupdate_check(int, struct cpu_ucode *);
+
+extern int verbose;

Index: src/usr.sbin/cpuctl/arch/i386.c
diff -u src/usr.sbin/cpuctl/arch/i386.c:1.52 src/usr.sbin/cpuctl/arch/i386.c:1.53
--- src/usr.sbin/cpuctl/arch/i386.c:1.52	Mon Dec 23 11:17:20 2013
+++ src/usr.sbin/cpuctl/arch/i386.c	Mon Dec 23 12:35:33 2013
@@ -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 <sys/cdefs.h>
 #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 <sys/types.h>
@@ -1432,6 +1432,17 @@ cpu_probe_base_features(struct cpu_info 
 	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 
 		/* 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]:

Reply via email to