Module Name:    src
Committed By:   snj
Date:           Sat Mar 21 17:32:13 UTC 2015

Modified Files:
        src/sys/arch/sparc64/sparc64 [netbsd-7]: autoconf.c machdep.c

Log Message:
Pull up following revision(s) (requested by nakayama in ticket #628):
        sys/arch/sparc64/sparc64/autoconf.c: revision 1.202
        sys/arch/sparc64/sparc64/machdep.c: revision 1.281
Reuse results of "bootpath" and "bootargs" from openfirmware
instead of calling openfirmware in each sysctl CPU_BOOT*.
This change reduces openfirmware calls from userland since sysctl
CPU_BOOTED_KERNEL is used in system commands such as pstat and
netstat.


To generate a diff of this commit:
cvs rdiff -u -r1.198.2.1 -r1.198.2.2 src/sys/arch/sparc64/sparc64/autoconf.c
cvs rdiff -u -r1.278.2.2 -r1.278.2.3 src/sys/arch/sparc64/sparc64/machdep.c

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

Modified files:

Index: src/sys/arch/sparc64/sparc64/autoconf.c
diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.198.2.1 src/sys/arch/sparc64/sparc64/autoconf.c:1.198.2.2
--- src/sys/arch/sparc64/sparc64/autoconf.c:1.198.2.1	Tue Aug 12 18:56:51 2014
+++ src/sys/arch/sparc64/sparc64/autoconf.c	Sat Mar 21 17:32:13 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.198.2.1 2014/08/12 18:56:51 riz Exp $ */
+/*	$NetBSD: autoconf.c,v 1.198.2.2 2015/03/21 17:32:13 snj Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.198.2.1 2014/08/12 18:56:51 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.198.2.2 2015/03/21 17:32:13 snj Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -145,6 +145,7 @@ int kgdb_break_at_attach;
 char	machine_banner[100];
 char	machine_model[100];
 char	ofbootpath[OFPATHLEN], *ofboottarget, *ofbootpartition;
+char	ofbootargs[OFPATHLEN], *ofbootfile, *ofbootflags;
 int	ofbootpackage;
 
 static	int mbprint(void *, const char *);
@@ -417,8 +418,9 @@ get_bootpath_from_prom(void)
 	/* Setup pointer to boot flags */
 	if (OF_getprop(chosen, "bootargs", sbuf, sizeof(sbuf)) == -1)
 		return;
+	strcpy(ofbootargs, sbuf);
 
-	cp = sbuf;
+	cp = ofbootargs;
 
 	/* Find start of boot flags */
 	while (*cp) {
@@ -426,8 +428,12 @@ get_bootpath_from_prom(void)
 		if (*cp == '-' || *cp == '\0')
 			break;
 		while(*cp != ' ' && *cp != '\t' && *cp != '\0') cp++;
-		
+		if (*cp != '\0')
+			*cp++ = '\0';
 	}
+	if (cp != ofbootargs)
+		ofbootfile = ofbootargs;
+	ofbootflags = cp;
 	if (*cp != '-')
 		return;
 

Index: src/sys/arch/sparc64/sparc64/machdep.c
diff -u src/sys/arch/sparc64/sparc64/machdep.c:1.278.2.2 src/sys/arch/sparc64/sparc64/machdep.c:1.278.2.3
--- src/sys/arch/sparc64/sparc64/machdep.c:1.278.2.2	Mon Nov 10 17:59:57 2014
+++ src/sys/arch/sparc64/sparc64/machdep.c	Sat Mar 21 17:32:13 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.278.2.2 2014/11/10 17:59:57 snj Exp $ */
+/*	$NetBSD: machdep.c,v 1.278.2.3 2015/03/21 17:32:13 snj Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.278.2.2 2014/11/10 17:59:57 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.278.2.3 2015/03/21 17:32:13 snj Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -295,59 +295,6 @@ setregs(struct lwp *l, struct exec_packa
 #endif
 }
 
-static char *parse_bootfile(char *);
-static char *parse_bootargs(char *);
-
-static char *
-parse_bootfile(char *args)
-{
-	char *cp;
-
-	/*
-	 * bootargs is of the form: [kernelname] [args...]
-	 * It can be the empty string if we booted from the default
-	 * kernel name.
-	 */
-	cp = args;
-	for (cp = args; *cp != 0 && *cp != ' ' && *cp != '\t'; cp++) {
-		if (*cp == '-') {
-			int c;
-			/*
-			 * If this `-' is most likely the start of boot
-			 * options, we're done.
-			 */
-			if (cp == args)
-				break;
-			if ((c = *(cp-1)) == ' ' || c == '\t')
-				break;
-		}
-	}
-	/* Now we've separated out the kernel name from the args */
-	*cp = '\0';
-	return (args);
-}
-
-static char *
-parse_bootargs(char *args)
-{
-	char *cp;
-
-	for (cp = args; *cp != '\0'; cp++) {
-		if (*cp == '-') {
-			int c;
-			/*
-			 * Looks like options start here, but check this
-			 * `-' is not part of the kernel name.
-			 */
-			if (cp == args)
-				break;
-			if ((c = *(cp-1)) == ' ' || c == '\t')
-				break;
-		}
-	}
-	return (cp);
-}
-
 /*
  * machine dependent system variables.
  */
@@ -355,31 +302,28 @@ static int
 sysctl_machdep_boot(SYSCTLFN_ARGS)
 {
 	struct sysctlnode node = *rnode;
-	u_int chosen;
-	char bootargs[256];
-	const char *cp;
-
-	if ((chosen = OF_finddevice("/chosen")) == -1)
-		return (ENOENT);
-	if (node.sysctl_num == CPU_BOOTED_DEVICE)
-		cp = "bootpath";
-	else
-		cp = "bootargs";
-	if (OF_getprop(chosen, cp, bootargs, sizeof bootargs) < 0)
-		return (ENOENT);
+	char bootpath[256];
+	const char *cp = NULL;
+	extern char ofbootpath[], *ofbootpartition, *ofbootfile, *ofbootflags;
 
 	switch (node.sysctl_num) {
 	case CPU_BOOTED_KERNEL:
-		cp = parse_bootfile(bootargs);
-                if (cp != NULL && cp[0] == '\0')
+		cp = ofbootfile;
+                if (cp == NULL || cp[0] == '\0')
                         /* Unknown to firmware, return default name */
                         cp = "netbsd";
 		break;
 	case CPU_BOOT_ARGS:
-		cp = parse_bootargs(bootargs);
+		cp = ofbootflags;
 		break;
 	case CPU_BOOTED_DEVICE:
-		cp = bootargs;
+		if (ofbootpartition) {
+			snprintf(bootpath, sizeof(bootpath), "%s:%s",
+			    ofbootpath, ofbootpartition);
+			cp = bootpath;
+		} else {
+			cp = ofbootpath;
+		}
 		break;
 	}
 

Reply via email to