17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright (c) 1994-1995, by Sun Microsystems, Inc.
247c478bdstevel@tonic-gate * All rights reserved.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate#include <sys/param.h>
307c478bdstevel@tonic-gate#include <sys/modctl.h>
317c478bdstevel@tonic-gate#include <sys/salib.h>
327c478bdstevel@tonic-gate
337c478bdstevel@tonic-gate#include <sys/platnames.h>
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate/*
367c478bdstevel@tonic-gate * Supplied by modpath.c
377c478bdstevel@tonic-gate *
387c478bdstevel@tonic-gate * Making these externs here allows all sparc machines to share
397c478bdstevel@tonic-gate * mod_path_uname_m().
407c478bdstevel@tonic-gate */
417c478bdstevel@tonic-gateextern char *default_name;
427c478bdstevel@tonic-gateextern char *default_path;
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate/*
457c478bdstevel@tonic-gate * Is path "/platform/"dir"/" ?
467c478bdstevel@tonic-gate */
477c478bdstevel@tonic-gatestatic int
487c478bdstevel@tonic-gateplatcmp(char *path, char *dir)
497c478bdstevel@tonic-gate{
507c478bdstevel@tonic-gate	static char prefix[] = "/platform/";
517c478bdstevel@tonic-gate	static char suffix[] = "/kernel";
527c478bdstevel@tonic-gate	int len;
537c478bdstevel@tonic-gate
547c478bdstevel@tonic-gate	if (strncmp(path, prefix, sizeof (prefix) - 1) != 0)
557c478bdstevel@tonic-gate		return (0);
567c478bdstevel@tonic-gate	len = strlen(dir);
577c478bdstevel@tonic-gate	path += sizeof (prefix) - 1;
587c478bdstevel@tonic-gate	if (strncmp(path, dir, len) != 0)
597c478bdstevel@tonic-gate		return (0);
607c478bdstevel@tonic-gate	path += len;
617c478bdstevel@tonic-gate	if (strcmp(path, suffix) != 0)
627c478bdstevel@tonic-gate		return (0);
637c478bdstevel@tonic-gate	return (1);
647c478bdstevel@tonic-gate}
657c478bdstevel@tonic-gate
667c478bdstevel@tonic-gate/*
677c478bdstevel@tonic-gate * This function provides a hook for enhancing the module_path.
687c478bdstevel@tonic-gate */
697c478bdstevel@tonic-gate/*ARGSUSED*/
707c478bdstevel@tonic-gatevoid
717c478bdstevel@tonic-gatemod_path_uname_m(char *mod_path, char *ia_name)
727c478bdstevel@tonic-gate{
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gate	if (ia_name == NULL)
757c478bdstevel@tonic-gate		return;
767c478bdstevel@tonic-gate
777c478bdstevel@tonic-gate	/*
787c478bdstevel@tonic-gate	 * If we found the kernel in the default dir, prepend the ia_name
797c478bdstevel@tonic-gate	 * directory (e.g. /platform/SUNW,foo/kernel) to the mod_path unless
807c478bdstevel@tonic-gate	 * ia_name is the same as the default dir.  This can happen if we
817c478bdstevel@tonic-gate	 * found the kernel via the "compatible" property.
827c478bdstevel@tonic-gate	 *
837c478bdstevel@tonic-gate	 * If we found the kernel in the ia_name dir, append the default
847c478bdstevel@tonic-gate	 * directory to the modpath.
857c478bdstevel@tonic-gate	 *
867c478bdstevel@tonic-gate	 * If neither of the above are true, we were given a specific kernel
877c478bdstevel@tonic-gate	 * to boot, so we leave things well enough alone.
887c478bdstevel@tonic-gate	 */
897c478bdstevel@tonic-gate	if (platcmp(mod_path, default_name)) {
907c478bdstevel@tonic-gate		if (strcmp(ia_name, default_name) != 0) {
917c478bdstevel@tonic-gate			char tmp[MOD_MAXPATH];
927c478bdstevel@tonic-gate
937c478bdstevel@tonic-gate			(void) strcpy(tmp, mod_path);
947c478bdstevel@tonic-gate			(void) strcpy(mod_path, "/platform/");
957c478bdstevel@tonic-gate			(void) strcat(mod_path, ia_name);
967c478bdstevel@tonic-gate			(void) strcat(mod_path, "/kernel ");
977c478bdstevel@tonic-gate			(void) strcat(mod_path, tmp);
987c478bdstevel@tonic-gate		}
997c478bdstevel@tonic-gate	} else if (platcmp(mod_path, ia_name))
1007c478bdstevel@tonic-gate		(void) strcat(mod_path, default_path);
1017c478bdstevel@tonic-gate}
102