xref: /titanic_50/usr/src/cmd/mdb/common/kmdb/kctl/kctl_auxv.c (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <kmdb/kctl/kctl.h>
29 
30 #include <sys/modctl.h>
31 #include <sys/bootconf.h>
32 #include <sys/kobj.h>
33 #include <sys/kobj_impl.h>
34 #include <sys/kmdb.h>
35 
36 static uintptr_t
kctl_lookup_by_name(char * modname,char * symname)37 kctl_lookup_by_name(char *modname, char *symname)
38 {
39 	struct modctl *mctl;
40 	Sym *ksym;
41 	uintptr_t addr;
42 
43 	if ((mctl = mod_hold_by_name(modname)) == NULL)
44 		return (0);
45 	if ((ksym = kobj_lookup_all(mctl->mod_mp, symname, 1)) == NULL) {
46 		mod_release_mod(mctl);
47 		return (0);
48 	}
49 
50 	addr = ksym->st_value;
51 
52 	mod_release_mod(mctl);
53 
54 	return (addr);
55 }
56 
57 static uintptr_t
kctl_boot_lookup_by_name(char * modname,char * symname)58 kctl_boot_lookup_by_name(char *modname, char *symname)
59 {
60 	struct modctl *mctl;
61 	Sym *ksym;
62 
63 	if ((mctl = kobj_boot_mod_lookup(modname)) == NULL)
64 		return (0);
65 
66 	if ((ksym = kobj_lookup_all(mctl->mod_mp, symname, 1)) == NULL)
67 		return (0);
68 
69 	return (ksym->st_value);
70 }
71 
72 void
kctl_auxv_init(kmdb_auxv_t * kav,const char * cfg,const char ** argv,void * romp)73 kctl_auxv_init(kmdb_auxv_t *kav, const char *cfg, const char **argv, void *romp)
74 {
75 	bzero(kav, sizeof (kmdb_auxv_t));
76 	kav->kav_dseg = kctl.kctl_dseg;
77 	kav->kav_dseg_size = kctl.kctl_dseg_size;
78 	kav->kav_pagesize = PAGESIZE;
79 	kav->kav_ncpu = NCPU;
80 	kav->kav_kdi = &kobj_kdi;
81 	kav->kav_wrintr_fire = kctl_wrintr_fire;
82 
83 	kav->kav_config = cfg;
84 	kav->kav_argv = argv;
85 	kav->kav_modpath = kobj_module_path;
86 
87 	kctl_dprintf("kctl_auxv_init: modpath '%s'", kav->kav_modpath);
88 
89 	if (kctl.kctl_boot_loaded) {
90 		kav->kav_lookup_by_name = kctl_boot_lookup_by_name;
91 		kav->kav_flags |= KMDB_AUXV_FL_NOUNLOAD;
92 	} else
93 		kav->kav_lookup_by_name = kctl_lookup_by_name;
94 
95 	if (kctl.kctl_flags & KMDB_F_TRAP_NOSWITCH)
96 		kav->kav_flags |= KMDB_AUXV_FL_NOTRPSWTCH;
97 
98 	kctl_auxv_init_isadep(kav, romp); /* can modify anything in kav */
99 }
100 
101 void
kctl_auxv_fini(kmdb_auxv_t * kav)102 kctl_auxv_fini(kmdb_auxv_t *kav)
103 {
104 	kctl_auxv_fini_isadep(kav);
105 }
106