xref: /onnv-gate/usr/src/cmd/sgs/librtld_db/demo/sparc/regs.c (revision 12927:a27c46eb192b)
1*12927SRod.Evans@Sun.COM /*
2*12927SRod.Evans@Sun.COM  * CDDL HEADER START
3*12927SRod.Evans@Sun.COM  *
4*12927SRod.Evans@Sun.COM  * The contents of this file are subject to the terms of the
5*12927SRod.Evans@Sun.COM  * Common Development and Distribution License (the "License").
6*12927SRod.Evans@Sun.COM  * You may not use this file except in compliance with the License.
7*12927SRod.Evans@Sun.COM  *
8*12927SRod.Evans@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12927SRod.Evans@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*12927SRod.Evans@Sun.COM  * See the License for the specific language governing permissions
11*12927SRod.Evans@Sun.COM  * and limitations under the License.
12*12927SRod.Evans@Sun.COM  *
13*12927SRod.Evans@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*12927SRod.Evans@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*12927SRod.Evans@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*12927SRod.Evans@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*12927SRod.Evans@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*12927SRod.Evans@Sun.COM  *
19*12927SRod.Evans@Sun.COM  * CDDL HEADER END
20*12927SRod.Evans@Sun.COM  */
21*12927SRod.Evans@Sun.COM 
22*12927SRod.Evans@Sun.COM /*
23*12927SRod.Evans@Sun.COM  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24*12927SRod.Evans@Sun.COM  */
25*12927SRod.Evans@Sun.COM 
26*12927SRod.Evans@Sun.COM #include <stdio.h>
27*12927SRod.Evans@Sun.COM #include <unistd.h>
28*12927SRod.Evans@Sun.COM #include <string.h>
29*12927SRod.Evans@Sun.COM #include <sys/param.h>
30*12927SRod.Evans@Sun.COM 
31*12927SRod.Evans@Sun.COM #include "rdb.h"
32*12927SRod.Evans@Sun.COM 
33*12927SRod.Evans@Sun.COM static void
disp_reg_line(struct ps_prochandle * ph,pstatus_t * prst,char * r1,int ind1,char * r2,int ind2)34*12927SRod.Evans@Sun.COM disp_reg_line(struct ps_prochandle *ph, pstatus_t *prst, char *r1, int ind1,
35*12927SRod.Evans@Sun.COM     char *r2, int ind2)
36*12927SRod.Evans@Sun.COM {
37*12927SRod.Evans@Sun.COM 	char	str1[MAXPATHLEN], str2[MAXPATHLEN];
38*12927SRod.Evans@Sun.COM 
39*12927SRod.Evans@Sun.COM 	(void) strcpy(str1, print_address_ps(ph, prst->pr_lwp.pr_reg[ind1],
40*12927SRod.Evans@Sun.COM 	    FLG_PAP_NOHEXNAME));
41*12927SRod.Evans@Sun.COM 
42*12927SRod.Evans@Sun.COM 	(void) strcpy(str2, print_address_ps(ph, prst->pr_lwp.pr_reg[ind2],
43*12927SRod.Evans@Sun.COM 	    FLG_PAP_NOHEXNAME));
44*12927SRod.Evans@Sun.COM 
45*12927SRod.Evans@Sun.COM 	(void) printf("%8s: 0x%08x %-16s %8s: 0x%08x %-16s\n", r1,
46*12927SRod.Evans@Sun.COM 	    prst->pr_lwp.pr_reg[ind1], str1, r2, prst->pr_lwp.pr_reg[ind2],
47*12927SRod.Evans@Sun.COM 	    str2);
48*12927SRod.Evans@Sun.COM }
49*12927SRod.Evans@Sun.COM 
50*12927SRod.Evans@Sun.COM void
display_local_regs(struct ps_prochandle * ph,pstatus_t * prst)51*12927SRod.Evans@Sun.COM display_local_regs(struct ps_prochandle *ph, pstatus_t *prst)
52*12927SRod.Evans@Sun.COM {
53*12927SRod.Evans@Sun.COM 	pstatus_t	pstatus;
54*12927SRod.Evans@Sun.COM 
55*12927SRod.Evans@Sun.COM 	if (prst == NULL) {
56*12927SRod.Evans@Sun.COM 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
57*12927SRod.Evans@Sun.COM 		    0) == -1) {
58*12927SRod.Evans@Sun.COM 			perror("dlr: reading status");
59*12927SRod.Evans@Sun.COM 			return;
60*12927SRod.Evans@Sun.COM 		}
61*12927SRod.Evans@Sun.COM 		prst = &pstatus;
62*12927SRod.Evans@Sun.COM 	}
63*12927SRod.Evans@Sun.COM 	(void) printf("locals:\n");
64*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "l0", R_L0, "l4", R_L4);
65*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "l1", R_L1, "l5", R_L5);
66*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "l2", R_L2, "l6", R_L6);
67*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "l3", R_L3, "l7", R_L7);
68*12927SRod.Evans@Sun.COM }
69*12927SRod.Evans@Sun.COM 
70*12927SRod.Evans@Sun.COM void
display_out_regs(struct ps_prochandle * ph,pstatus_t * prst)71*12927SRod.Evans@Sun.COM display_out_regs(struct ps_prochandle *ph, pstatus_t *prst)
72*12927SRod.Evans@Sun.COM {
73*12927SRod.Evans@Sun.COM 	pstatus_t	pstatus;
74*12927SRod.Evans@Sun.COM 
75*12927SRod.Evans@Sun.COM 	if (prst == NULL) {
76*12927SRod.Evans@Sun.COM 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
77*12927SRod.Evans@Sun.COM 		    0) == -1) {
78*12927SRod.Evans@Sun.COM 			perror("dor: reading status");
79*12927SRod.Evans@Sun.COM 			return;
80*12927SRod.Evans@Sun.COM 		}
81*12927SRod.Evans@Sun.COM 		prst = &pstatus;
82*12927SRod.Evans@Sun.COM 	}
83*12927SRod.Evans@Sun.COM 	(void) printf("outs:\n");
84*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "o0", R_O0, "o4", R_O4);
85*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "o1", R_O1, "o5", R_O5);
86*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "o2", R_O2, "o6(sp)", R_O6);
87*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "o3", R_O3, "o7", R_O7);
88*12927SRod.Evans@Sun.COM }
89*12927SRod.Evans@Sun.COM 
90*12927SRod.Evans@Sun.COM void
display_special_regs(struct ps_prochandle * ph,pstatus_t * prst)91*12927SRod.Evans@Sun.COM display_special_regs(struct ps_prochandle *ph, pstatus_t *prst)
92*12927SRod.Evans@Sun.COM {
93*12927SRod.Evans@Sun.COM 	pstatus_t	pstatus;
94*12927SRod.Evans@Sun.COM 
95*12927SRod.Evans@Sun.COM 	if (prst == NULL) {
96*12927SRod.Evans@Sun.COM 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
97*12927SRod.Evans@Sun.COM 		    0) == -1) {
98*12927SRod.Evans@Sun.COM 			perror("dsr: reading status");
99*12927SRod.Evans@Sun.COM 			return;
100*12927SRod.Evans@Sun.COM 		}
101*12927SRod.Evans@Sun.COM 		prst = &pstatus;
102*12927SRod.Evans@Sun.COM 	}
103*12927SRod.Evans@Sun.COM 	(void) printf("specials:\n");
104*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "psr", R_PSR, "pc", R_PC);
105*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "npc", R_nPC, "Y", R_Y);
106*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "wim", R_WIM, "TBR", R_TBR);
107*12927SRod.Evans@Sun.COM }
108*12927SRod.Evans@Sun.COM 
109*12927SRod.Evans@Sun.COM void
display_global_regs(struct ps_prochandle * ph,pstatus_t * prst)110*12927SRod.Evans@Sun.COM display_global_regs(struct ps_prochandle *ph, pstatus_t *prst)
111*12927SRod.Evans@Sun.COM {
112*12927SRod.Evans@Sun.COM 	pstatus_t	pstatus;
113*12927SRod.Evans@Sun.COM 
114*12927SRod.Evans@Sun.COM 	if (prst == NULL) {
115*12927SRod.Evans@Sun.COM 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
116*12927SRod.Evans@Sun.COM 		    0) == -1) {
117*12927SRod.Evans@Sun.COM 			perror("dgr: reading status");
118*12927SRod.Evans@Sun.COM 			return;
119*12927SRod.Evans@Sun.COM 		}
120*12927SRod.Evans@Sun.COM 		prst = &pstatus;
121*12927SRod.Evans@Sun.COM 	}
122*12927SRod.Evans@Sun.COM 	(void) printf("globals:\n");
123*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "g0", R_G0, "g4", R_G4);
124*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "g1", R_G1, "g5", R_G5);
125*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "g2", R_G2, "g6", R_G6);
126*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "g3", R_G3, "g7", R_G7);
127*12927SRod.Evans@Sun.COM }
128*12927SRod.Evans@Sun.COM 
129*12927SRod.Evans@Sun.COM void
display_in_regs(struct ps_prochandle * ph,pstatus_t * prst)130*12927SRod.Evans@Sun.COM display_in_regs(struct ps_prochandle *ph, pstatus_t *prst)
131*12927SRod.Evans@Sun.COM {
132*12927SRod.Evans@Sun.COM 	pstatus_t	pstatus;
133*12927SRod.Evans@Sun.COM 
134*12927SRod.Evans@Sun.COM 	if (prst == NULL) {
135*12927SRod.Evans@Sun.COM 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
136*12927SRod.Evans@Sun.COM 		    0) == -1) {
137*12927SRod.Evans@Sun.COM 			perror("dir: reading status");
138*12927SRod.Evans@Sun.COM 			return;
139*12927SRod.Evans@Sun.COM 		}
140*12927SRod.Evans@Sun.COM 		prst = &pstatus;
141*12927SRod.Evans@Sun.COM 	}
142*12927SRod.Evans@Sun.COM 	(void) printf("ins:\n");
143*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "i0", R_I0, "i4", R_I4);
144*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "i1", R_I1, "i5", R_I5);
145*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "i2", R_I2, "i6(fp)", R_I6);
146*12927SRod.Evans@Sun.COM 	disp_reg_line(ph, prst, "i3", R_I3, "i7", R_I7);
147*12927SRod.Evans@Sun.COM 
148*12927SRod.Evans@Sun.COM }
149*12927SRod.Evans@Sun.COM 
150*12927SRod.Evans@Sun.COM retc_t
display_all_regs(struct ps_prochandle * ph)151*12927SRod.Evans@Sun.COM display_all_regs(struct ps_prochandle *ph)
152*12927SRod.Evans@Sun.COM {
153*12927SRod.Evans@Sun.COM 	pstatus_t	pstatus;
154*12927SRod.Evans@Sun.COM 
155*12927SRod.Evans@Sun.COM 	if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
156*12927SRod.Evans@Sun.COM 	    0) == -1) {
157*12927SRod.Evans@Sun.COM 		perror("dar: reading status");
158*12927SRod.Evans@Sun.COM 		return (RET_FAILED);
159*12927SRod.Evans@Sun.COM 	}
160*12927SRod.Evans@Sun.COM 	display_global_regs(ph, &pstatus);
161*12927SRod.Evans@Sun.COM 	display_in_regs(ph, &pstatus);
162*12927SRod.Evans@Sun.COM 	display_local_regs(ph, &pstatus);
163*12927SRod.Evans@Sun.COM 	display_out_regs(ph, &pstatus);
164*12927SRod.Evans@Sun.COM 	display_special_regs(ph, &pstatus);
165*12927SRod.Evans@Sun.COM 
166*12927SRod.Evans@Sun.COM 	return (RET_OK);
167*12927SRod.Evans@Sun.COM }
168