xref: /titanic_52/usr/src/psm/stand/lib/names/sparc/common/uname-m.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1994-1995, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/param.h>
30 #include <sys/modctl.h>
31 #include <sys/salib.h>
32 
33 #include <sys/platnames.h>
34 
35 /*
36  * Supplied by modpath.c
37  *
38  * Making these externs here allows all sparc machines to share
39  * mod_path_uname_m().
40  */
41 extern char *default_name;
42 extern char *default_path;
43 
44 /*
45  * Is path "/platform/"dir"/" ?
46  */
47 static int
48 platcmp(char *path, char *dir)
49 {
50 	static char prefix[] = "/platform/";
51 	static char suffix[] = "/kernel";
52 	int len;
53 
54 	if (strncmp(path, prefix, sizeof (prefix) - 1) != 0)
55 		return (0);
56 	len = strlen(dir);
57 	path += sizeof (prefix) - 1;
58 	if (strncmp(path, dir, len) != 0)
59 		return (0);
60 	path += len;
61 	if (strcmp(path, suffix) != 0)
62 		return (0);
63 	return (1);
64 }
65 
66 /*
67  * This function provides a hook for enhancing the module_path.
68  */
69 /*ARGSUSED*/
70 void
71 mod_path_uname_m(char *mod_path, char *ia_name)
72 {
73 
74 	if (ia_name == NULL)
75 		return;
76 
77 	/*
78 	 * If we found the kernel in the default dir, prepend the ia_name
79 	 * directory (e.g. /platform/SUNW,foo/kernel) to the mod_path unless
80 	 * ia_name is the same as the default dir.  This can happen if we
81 	 * found the kernel via the "compatible" property.
82 	 *
83 	 * If we found the kernel in the ia_name dir, append the default
84 	 * directory to the modpath.
85 	 *
86 	 * If neither of the above are true, we were given a specific kernel
87 	 * to boot, so we leave things well enough alone.
88 	 */
89 	if (platcmp(mod_path, default_name)) {
90 		if (strcmp(ia_name, default_name) != 0) {
91 			char tmp[MOD_MAXPATH];
92 
93 			(void) strcpy(tmp, mod_path);
94 			(void) strcpy(mod_path, "/platform/");
95 			(void) strcat(mod_path, ia_name);
96 			(void) strcat(mod_path, "/kernel ");
97 			(void) strcat(mod_path, tmp);
98 		}
99 	} else if (platcmp(mod_path, ia_name))
100 		(void) strcat(mod_path, default_path);
101 }
102