xref: /titanic_52/usr/src/cmd/sgs/liblddbg/common/cap.c (revision 1c1abfbc1c2d0908a973470fd549f89022b3dcc3)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
23*1c1abfbcSRod Evans  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26a194faf8Srie #include	<stdio.h>
275aefb655Srie #include	<debug.h>
285aefb655Srie #include	<libld.h>
295aefb655Srie #include	<conv.h>
307c478bd9Sstevel@tonic-gate #include	"msg.h"
317c478bd9Sstevel@tonic-gate #include	"_debug.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate void
3408278a5eSRod Evans Dbg_cap_candidate(Lm_list *lml, const char *name)
357c478bd9Sstevel@tonic-gate {
365aefb655Srie 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_FILES))
377c478bd9Sstevel@tonic-gate 		return;
387c478bd9Sstevel@tonic-gate 
3908278a5eSRod Evans 	dbg_print(lml, MSG_INTL(MSG_CAP_CANDIDATE), name);
407c478bd9Sstevel@tonic-gate }
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate void
4308278a5eSRod Evans Dbg_cap_filter(Lm_list *lml, const char *dir, Rt_map *flmp)
447c478bd9Sstevel@tonic-gate {
455aefb655Srie 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_FILES))
467c478bd9Sstevel@tonic-gate 		return;
477c478bd9Sstevel@tonic-gate 
485aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
495aefb655Srie 	if (flmp)
5008278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_FILTER_1), dir, NAME(flmp));
517c478bd9Sstevel@tonic-gate 	else
5208278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_FILTER_2), dir);
537c478bd9Sstevel@tonic-gate }
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate void
56*1c1abfbcSRod Evans Dbg_cap_identical(Lm_list *lml, const char *file1, const char *file2)
57*1c1abfbcSRod Evans {
58*1c1abfbcSRod Evans 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_FILES))
59*1c1abfbcSRod Evans 		return;
60*1c1abfbcSRod Evans 
61*1c1abfbcSRod Evans 	dbg_print(lml, MSG_INTL(MSG_CAP_IDENTICAL), file1, file2);
62*1c1abfbcSRod Evans }
63*1c1abfbcSRod Evans 
64*1c1abfbcSRod Evans void
6508278a5eSRod Evans Dbg_cap_val(Lm_list *lml, Syscapset *sys, Syscapset *alt, Half mach)
667c478bd9Sstevel@tonic-gate {
6708278a5eSRod Evans 	Conv_cap_val_buf_t	cap_val_buf;
6808278a5eSRod Evans 
6908278a5eSRod Evans 	if ((sys->sc_plat == NULL) && (sys->sc_mach == NULL) &&
7008278a5eSRod Evans 	    (sys->sc_hw_2 == 0) && (sys->sc_hw_1 == 0) &&
7108278a5eSRod Evans 	    (sys->sc_sf_1 == 0))
7208278a5eSRod Evans 		return;
73de777a60Sab196087 
745aefb655Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
7508278a5eSRod Evans 
7608278a5eSRod Evans 	/*
7708278a5eSRod Evans 	 * Print any capabilities in precedence order.
7808278a5eSRod Evans 	 */
7908278a5eSRod Evans 	if (sys->sc_plat) {
8008278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_PLAT), sys->sc_plat);
8108278a5eSRod Evans 	}
8208278a5eSRod Evans 	if (sys->sc_mach) {
8308278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_MACH), sys->sc_mach);
8408278a5eSRod Evans 	}
8508278a5eSRod Evans 	if (sys->sc_hw_2) {
8608278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_HW_2),
8708278a5eSRod Evans 		    conv_cap_val_hw2(sys->sc_hw_2, mach, 0,
8808278a5eSRod Evans 		    &cap_val_buf.cap_val_hw2_buf));
8908278a5eSRod Evans 	}
9008278a5eSRod Evans 	if (sys->sc_hw_1) {
9108278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_HW_1),
9208278a5eSRod Evans 		    conv_cap_val_hw1(sys->sc_hw_1, mach, 0,
9308278a5eSRod Evans 		    &cap_val_buf.cap_val_hw1_buf));
9408278a5eSRod Evans 	}
9508278a5eSRod Evans 	if (sys->sc_sf_1) {
9608278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_SF_1),
9708278a5eSRod Evans 		    conv_cap_val_sf1(sys->sc_sf_1, mach, 0,
9808278a5eSRod Evans 		    &cap_val_buf.cap_val_sf1_buf));
9908278a5eSRod Evans 	}
10008278a5eSRod Evans 
10108278a5eSRod Evans 	if (alt != sys) {
10208278a5eSRod Evans 		Dbg_util_nl(lml, DBG_NL_FRC);
10308278a5eSRod Evans 		if (alt->sc_plat != sys->sc_plat) {
10408278a5eSRod Evans 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_PLAT),
10508278a5eSRod Evans 			    alt->sc_plat);
10608278a5eSRod Evans 		}
10708278a5eSRod Evans 		if (alt->sc_mach != sys->sc_mach) {
10808278a5eSRod Evans 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_MACH),
10908278a5eSRod Evans 			    alt->sc_mach);
11008278a5eSRod Evans 		}
11108278a5eSRod Evans 		if (alt->sc_hw_2 != sys->sc_hw_2) {
11208278a5eSRod Evans 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_HW_2),
11308278a5eSRod Evans 			    conv_cap_val_hw2(alt->sc_hw_2, mach, 0,
11408278a5eSRod Evans 			    &cap_val_buf.cap_val_hw2_buf));
11508278a5eSRod Evans 		}
11608278a5eSRod Evans 		if (alt->sc_hw_1 != sys->sc_hw_1) {
11708278a5eSRod Evans 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_HW_1),
11808278a5eSRod Evans 			    conv_cap_val_hw1(alt->sc_hw_1, mach, 0,
11908278a5eSRod Evans 			    &cap_val_buf.cap_val_hw1_buf));
12008278a5eSRod Evans 		}
12108278a5eSRod Evans 		if (alt->sc_sf_1 != sys->sc_sf_1) {
12208278a5eSRod Evans 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_SF_1),
12308278a5eSRod Evans 			    conv_cap_val_sf1(alt->sc_sf_1, mach, 0,
12408278a5eSRod Evans 			    &cap_val_buf.cap_val_sf1_buf));
12508278a5eSRod Evans 		}
12608278a5eSRod Evans 	}
12708278a5eSRod Evans 
1285aefb655Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate 
13108278a5eSRod Evans /*
13208278a5eSRod Evans  * This version takes a pointer to a Capmask, and will report the exclusion
13308278a5eSRod Evans  * bits if they exist.
13408278a5eSRod Evans  */
1357c478bd9Sstevel@tonic-gate void
13608278a5eSRod Evans Dbg_cap_ptr_entry(Lm_list *lml, dbg_state_t dbg_state, Xword tag,
13708278a5eSRod Evans     const char *ptr)
13808278a5eSRod Evans {
13908278a5eSRod Evans 	Conv_inv_buf_t		inv_buf;
14008278a5eSRod Evans 
14108278a5eSRod Evans 	if (DBG_NOTCLASS(DBG_C_CAP))
14208278a5eSRod Evans 		return;
14308278a5eSRod Evans 
14408278a5eSRod Evans 	dbg_print(lml, MSG_INTL(MSG_CAP_SEC_ENTRY), Dbg_state_str(dbg_state),
14508278a5eSRod Evans 	    conv_cap_tag(tag, 0, &inv_buf), ptr);
14608278a5eSRod Evans }
14708278a5eSRod Evans 
14808278a5eSRod Evans /*
14908278a5eSRod Evans  * This version takes a pointer to a CapMask, and will report the exclusion
15008278a5eSRod Evans  * bits if they exist.
15108278a5eSRod Evans  */
15208278a5eSRod Evans void
15308278a5eSRod Evans Dbg_cap_val_entry(Lm_list *lml, dbg_state_t dbg_state, Xword tag, Xword val,
15469112eddSAli Bahrami     Half mach)
1557c478bd9Sstevel@tonic-gate {
156de777a60Sab196087 	Conv_inv_buf_t		inv_buf;
157de777a60Sab196087 	Conv_cap_val_buf_t	cap_val_buf;
158de777a60Sab196087 
1595aefb655Srie 	if (DBG_NOTCLASS(DBG_C_CAP))
1607c478bd9Sstevel@tonic-gate 		return;
1617c478bd9Sstevel@tonic-gate 
16208278a5eSRod Evans 	dbg_print(lml, MSG_INTL(MSG_CAP_SEC_ENTRY), Dbg_state_str(dbg_state),
16308278a5eSRod Evans 	    conv_cap_tag(tag, 0, &inv_buf), conv_cap_val(tag, val, mach, 0,
164de777a60Sab196087 	    &cap_val_buf));
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate void
168bb3b4f6cSRod Evans Dbg_cap_sec_title(Lm_list *lml, const char *name)
1697c478bd9Sstevel@tonic-gate {
1705aefb655Srie 	if (DBG_NOTCLASS(DBG_C_CAP))
1715aefb655Srie 		return;
1725aefb655Srie 
1735aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
174bb3b4f6cSRod Evans 	dbg_print(lml, MSG_INTL(MSG_CAP_SEC_TITLE), name);
1755aefb655Srie }
1765aefb655Srie 
1775aefb655Srie void
17869112eddSAli Bahrami Dbg_cap_mapfile_title(Lm_list *lml, Lineno lineno)
17969112eddSAli Bahrami {
18069112eddSAli Bahrami 	if (DBG_NOTCLASS(DBG_C_MAP | DBG_C_CAP))
18169112eddSAli Bahrami 		return;
18269112eddSAli Bahrami 
18369112eddSAli Bahrami 	dbg_print(lml, MSG_INTL(MSG_MAP_CAP), EC_LINENO(lineno));
18469112eddSAli Bahrami }
18569112eddSAli Bahrami 
18669112eddSAli Bahrami void
18708278a5eSRod Evans Dbg_cap_id(Lm_list *lml, Lineno lineno, const char *oid, const char *nid)
18808278a5eSRod Evans {
18908278a5eSRod Evans 	Dbg_cap_mapfile_title(lml, lineno);
19008278a5eSRod Evans 	Dbg_cap_ptr_entry(lml, DBG_STATE_CURRENT, CA_SUNW_ID, oid);
19108278a5eSRod Evans 	Dbg_cap_ptr_entry(lml, DBG_STATE_NEW, CA_SUNW_ID, nid);
19208278a5eSRod Evans 	Dbg_cap_ptr_entry(lml, DBG_STATE_RESOLVED, CA_SUNW_ID, nid);
19308278a5eSRod Evans }
19408278a5eSRod Evans 
19508278a5eSRod Evans void
19608278a5eSRod Evans Dbg_cap_post_title(Lm_list *lml, int *title)
19708278a5eSRod Evans {
19808278a5eSRod Evans 	if (DBG_NOTCLASS(DBG_C_CAP))
19908278a5eSRod Evans 		return;
20008278a5eSRod Evans 
20108278a5eSRod Evans 	Dbg_util_nl(lml, DBG_NL_STD);
20208278a5eSRod Evans 	if ((*title)++ == 0)
20308278a5eSRod Evans 		dbg_print(lml, MSG_INTL(MSG_CAP_POST_TITLE));
20408278a5eSRod Evans }
20508278a5eSRod Evans 
20608278a5eSRod Evans void
2075aefb655Srie Elf_cap_title(Lm_list *lml)
2085aefb655Srie {
2095aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_CAP_ELF_TITLE));
2105aefb655Srie }
2115aefb655Srie 
2125aefb655Srie void
21308278a5eSRod Evans Elf_cap_entry(Lm_list *lml, Cap *cap, int ndx, const char *str, size_t str_size,
21408278a5eSRod Evans     Half mach)
2155aefb655Srie {
216de777a60Sab196087 	Conv_inv_buf_t		inv_buf;
217de777a60Sab196087 	Conv_cap_val_buf_t	cap_val_buf;
2185aefb655Srie 	char			index[INDEX_STR_SIZE];
2195aefb655Srie 
2205aefb655Srie 	(void) snprintf(index, INDEX_STR_SIZE, MSG_ORIG(MSG_FMT_INDEX), ndx);
22108278a5eSRod Evans 
22208278a5eSRod Evans 	switch (cap->c_tag) {
22308278a5eSRod Evans 	case CA_SUNW_PLAT:
22408278a5eSRod Evans 	case CA_SUNW_MACH:
22508278a5eSRod Evans 	case CA_SUNW_ID:
22608278a5eSRod Evans 		/* If offset is in range, format as a string */
22708278a5eSRod Evans 		if (str && (cap->c_un.c_ptr < str_size)) {
22808278a5eSRod Evans 			str += cap->c_un.c_ptr;
22908278a5eSRod Evans 			break;
23008278a5eSRod Evans 		}
23108278a5eSRod Evans 		/*FALLTHROUGH*/
23208278a5eSRod Evans 	default:
23308278a5eSRod Evans 		/* Format numerically */
23408278a5eSRod Evans 		str = conv_cap_val(cap->c_tag, cap->c_un.c_val, mach, 0,
23508278a5eSRod Evans 		    &cap_val_buf);
23608278a5eSRod Evans 	}
23708278a5eSRod Evans 
2385aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_CAP_ELF_ENTRY), index,
23908278a5eSRod Evans 	    conv_cap_tag(cap->c_tag, 0, &inv_buf), str);
2407c478bd9Sstevel@tonic-gate }
241