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
520c1c355SRod Evans  * Common Development and Distribution License (the "License").
620c1c355SRod Evans  * 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  */
2120c1c355SRod Evans 
227c478bd9Sstevel@tonic-gate /*
2320c1c355SRod Evans  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <stdio.h>
277c478bd9Sstevel@tonic-gate #include <unistd.h>
287c478bd9Sstevel@tonic-gate #include <string.h>
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include "rdb.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate static void
disp_reg_line(struct ps_prochandle * ph,pstatus_t * prst,char * r1,int ind1,char * r2,int ind2)3420c1c355SRod Evans disp_reg_line(struct ps_prochandle *ph, pstatus_t *prst, char *r1, int ind1,
3520c1c355SRod Evans     char *r2, int ind2)
367c478bd9Sstevel@tonic-gate {
3720c1c355SRod Evans 	char	str1[MAXPATHLEN], str2[MAXPATHLEN];
387c478bd9Sstevel@tonic-gate 
3920c1c355SRod Evans 	(void) strcpy(str1, print_address_ps(ph, prst->pr_lwp.pr_reg[ind1],
4020c1c355SRod Evans 	    FLG_PAP_NOHEXNAME));
417c478bd9Sstevel@tonic-gate 
4220c1c355SRod Evans 	(void) strcpy(str2, print_address_ps(ph, prst->pr_lwp.pr_reg[ind2],
4320c1c355SRod Evans 	    FLG_PAP_NOHEXNAME));
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 	if (ph->pp_dmodel == PR_MODEL_LP64) {
467c478bd9Sstevel@tonic-gate 		/*
477c478bd9Sstevel@tonic-gate 		 *  In 64-bits, the display gets too wide when
487c478bd9Sstevel@tonic-gate 		 *  you have both a 64-bit address and a symbol
497c478bd9Sstevel@tonic-gate 		 *  name, e.g. _GLOBAL_OFFSET_TABLE;  therefore,
507c478bd9Sstevel@tonic-gate 		 *  each is put on a separate line.  This isn't
517c478bd9Sstevel@tonic-gate 		 *  as convenient as the 32-bit display.
527c478bd9Sstevel@tonic-gate 		 */
5320c1c355SRod Evans 		(void) printf("%8s: 0x%08lx %-16s\n", r1,
5420c1c355SRod Evans 		    prst->pr_lwp.pr_reg[ind1], str1);
5520c1c355SRod Evans 		(void) printf("%8s: 0x%08lx %-16s\n", r2,
5620c1c355SRod Evans 		    prst->pr_lwp.pr_reg[ind2], str2);
577c478bd9Sstevel@tonic-gate 	} else
5820c1c355SRod Evans 		(void) printf("%8s: 0x%08lx %-16s %8s: 0x%08lx %-16s\n", r1,
5920c1c355SRod Evans 		    prst->pr_lwp.pr_reg[ind1], str1, r2,
6020c1c355SRod Evans 		    prst->pr_lwp.pr_reg[ind2], str2);
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate void
display_local_regs(struct ps_prochandle * ph,pstatus_t * prst)6420c1c355SRod Evans display_local_regs(struct ps_prochandle *ph, pstatus_t *prst)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 	pstatus_t	pstatus;
677c478bd9Sstevel@tonic-gate 
6820c1c355SRod Evans 	if (prst == NULL) {
697c478bd9Sstevel@tonic-gate 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
707c478bd9Sstevel@tonic-gate 		    0) == -1) {
717c478bd9Sstevel@tonic-gate 			perror("dar: reading status");
727c478bd9Sstevel@tonic-gate 			return;
737c478bd9Sstevel@tonic-gate 		}
747c478bd9Sstevel@tonic-gate 		prst = &pstatus;
757c478bd9Sstevel@tonic-gate 	}
7620c1c355SRod Evans 	(void) printf("locals:\n");
777c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "l0", R_L0, "l4", R_L4);
787c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "l1", R_L1, "l5", R_L5);
797c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "l2", R_L2, "l6", R_L6);
807c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "l3", R_L3, "l7", R_L7);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate void
display_out_regs(struct ps_prochandle * ph,pstatus_t * prst)8420c1c355SRod Evans display_out_regs(struct ps_prochandle *ph, pstatus_t *prst)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	pstatus_t	pstatus;
877c478bd9Sstevel@tonic-gate 
8820c1c355SRod Evans 	if (prst == NULL) {
897c478bd9Sstevel@tonic-gate 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
907c478bd9Sstevel@tonic-gate 		    0) == -1) {
917c478bd9Sstevel@tonic-gate 			perror("dar: reading status");
927c478bd9Sstevel@tonic-gate 			return;
937c478bd9Sstevel@tonic-gate 		}
947c478bd9Sstevel@tonic-gate 		prst = &pstatus;
957c478bd9Sstevel@tonic-gate 	}
9620c1c355SRod Evans 	(void) printf("outs:\n");
977c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "o0", R_O0, "o4", R_O4);
987c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "o1", R_O1, "o5", R_O5);
997c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "o2", R_O2, "o6(sp)", R_O6);
1007c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "o3", R_O3, "o7", R_O7);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate void
display_special_regs(struct ps_prochandle * ph,pstatus_t * prst)10420c1c355SRod Evans display_special_regs(struct ps_prochandle *ph, pstatus_t *prst)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	pstatus_t	pstatus;
1077c478bd9Sstevel@tonic-gate 
10820c1c355SRod Evans 	if (prst == NULL) {
1097c478bd9Sstevel@tonic-gate 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
1107c478bd9Sstevel@tonic-gate 		    0) == -1) {
1117c478bd9Sstevel@tonic-gate 			perror("dar: reading status");
1127c478bd9Sstevel@tonic-gate 			return;
1137c478bd9Sstevel@tonic-gate 		}
1147c478bd9Sstevel@tonic-gate 		prst = &pstatus;
1157c478bd9Sstevel@tonic-gate 	}
11620c1c355SRod Evans 	(void) printf("specials:\n");
1177c478bd9Sstevel@tonic-gate 	if (ph->pp_dmodel == PR_MODEL_LP64) {
1187c478bd9Sstevel@tonic-gate 		disp_reg_line(ph, prst, "ccr", R_CCR, "pc", R_PC);
1197c478bd9Sstevel@tonic-gate 		disp_reg_line(ph, prst, "npc", R_nPC, "Y", R_Y);
1207c478bd9Sstevel@tonic-gate 		disp_reg_line(ph, prst, "asi", R_ASI, "FPRS", R_FPRS);
1217c478bd9Sstevel@tonic-gate 	} else {
1227c478bd9Sstevel@tonic-gate 		disp_reg_line(ph, prst, "psr", R_PSR, "pc", R_PC);
1237c478bd9Sstevel@tonic-gate 		disp_reg_line(ph, prst, "npc", R_nPC, "Y", R_Y);
1247c478bd9Sstevel@tonic-gate 		disp_reg_line(ph, prst, "wim", R_WIM, "TBR", R_TBR);
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate void
display_global_regs(struct ps_prochandle * ph,pstatus_t * prst)12920c1c355SRod Evans display_global_regs(struct ps_prochandle *ph, pstatus_t *prst)
1307c478bd9Sstevel@tonic-gate {
1317c478bd9Sstevel@tonic-gate 	pstatus_t	pstatus;
1327c478bd9Sstevel@tonic-gate 
13320c1c355SRod Evans 	if (prst == NULL) {
1347c478bd9Sstevel@tonic-gate 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
1357c478bd9Sstevel@tonic-gate 		    0) == -1) {
1367c478bd9Sstevel@tonic-gate 			perror("dar: reading status");
1377c478bd9Sstevel@tonic-gate 			return;
1387c478bd9Sstevel@tonic-gate 		}
1397c478bd9Sstevel@tonic-gate 		prst = &pstatus;
1407c478bd9Sstevel@tonic-gate 	}
14120c1c355SRod Evans 	(void) printf("globals:\n");
1427c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "g0", R_G0, "g4", R_G4);
1437c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "g1", R_G1, "g5", R_G5);
1447c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "g2", R_G2, "g6", R_G6);
1457c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "g3", R_G3, "g7", R_G7);
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate void
display_in_regs(struct ps_prochandle * ph,pstatus_t * prst)14920c1c355SRod Evans display_in_regs(struct ps_prochandle *ph, pstatus_t *prst)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate 	pstatus_t	pstatus;
1527c478bd9Sstevel@tonic-gate 
15320c1c355SRod Evans 	if (prst == NULL) {
1547c478bd9Sstevel@tonic-gate 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
1557c478bd9Sstevel@tonic-gate 		    0) == -1) {
1567c478bd9Sstevel@tonic-gate 			perror("dar: reading status");
1577c478bd9Sstevel@tonic-gate 			return;
1587c478bd9Sstevel@tonic-gate 		}
1597c478bd9Sstevel@tonic-gate 		prst = &pstatus;
1607c478bd9Sstevel@tonic-gate 	}
16120c1c355SRod Evans 	(void) printf("ins:\n");
1627c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "i0", R_I0, "i4", R_I4);
1637c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "i1", R_I1, "i5", R_I5);
1647c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "i2", R_I2, "i6(fp)", R_I6);
1657c478bd9Sstevel@tonic-gate 	disp_reg_line(ph, prst, "i3", R_I3, "i7", R_I7);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate retc_t
display_all_regs(struct ps_prochandle * ph)17020c1c355SRod Evans display_all_regs(struct ps_prochandle *ph)
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate 	pstatus_t	pstatus;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
1757c478bd9Sstevel@tonic-gate 	    0) == -1) {
1767c478bd9Sstevel@tonic-gate 		perror("dar: reading status");
1777c478bd9Sstevel@tonic-gate 		return (RET_FAILED);
1787c478bd9Sstevel@tonic-gate 	}
1797c478bd9Sstevel@tonic-gate 	display_global_regs(ph, &pstatus);
1807c478bd9Sstevel@tonic-gate 	display_in_regs(ph, &pstatus);
1817c478bd9Sstevel@tonic-gate 	display_local_regs(ph, &pstatus);
1827c478bd9Sstevel@tonic-gate 	display_out_regs(ph, &pstatus);
1837c478bd9Sstevel@tonic-gate 	display_special_regs(ph, &pstatus);
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	return (RET_OK);
1867c478bd9Sstevel@tonic-gate }
187