xref: /titanic_44/usr/src/cmd/sgs/librtld_db/demo/sparc/regs.c (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
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 /*
23  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <sys/param.h>
30 
31 #include "rdb.h"
32 
33 static void
disp_reg_line(struct ps_prochandle * ph,pstatus_t * prst,char * r1,int ind1,char * r2,int ind2)34 disp_reg_line(struct ps_prochandle *ph, pstatus_t *prst, char *r1, int ind1,
35     char *r2, int ind2)
36 {
37 	char	str1[MAXPATHLEN], str2[MAXPATHLEN];
38 
39 	(void) strcpy(str1, print_address_ps(ph, prst->pr_lwp.pr_reg[ind1],
40 	    FLG_PAP_NOHEXNAME));
41 
42 	(void) strcpy(str2, print_address_ps(ph, prst->pr_lwp.pr_reg[ind2],
43 	    FLG_PAP_NOHEXNAME));
44 
45 	(void) printf("%8s: 0x%08x %-16s %8s: 0x%08x %-16s\n", r1,
46 	    prst->pr_lwp.pr_reg[ind1], str1, r2, prst->pr_lwp.pr_reg[ind2],
47 	    str2);
48 }
49 
50 void
display_local_regs(struct ps_prochandle * ph,pstatus_t * prst)51 display_local_regs(struct ps_prochandle *ph, pstatus_t *prst)
52 {
53 	pstatus_t	pstatus;
54 
55 	if (prst == NULL) {
56 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
57 		    0) == -1) {
58 			perror("dlr: reading status");
59 			return;
60 		}
61 		prst = &pstatus;
62 	}
63 	(void) printf("locals:\n");
64 	disp_reg_line(ph, prst, "l0", R_L0, "l4", R_L4);
65 	disp_reg_line(ph, prst, "l1", R_L1, "l5", R_L5);
66 	disp_reg_line(ph, prst, "l2", R_L2, "l6", R_L6);
67 	disp_reg_line(ph, prst, "l3", R_L3, "l7", R_L7);
68 }
69 
70 void
display_out_regs(struct ps_prochandle * ph,pstatus_t * prst)71 display_out_regs(struct ps_prochandle *ph, pstatus_t *prst)
72 {
73 	pstatus_t	pstatus;
74 
75 	if (prst == NULL) {
76 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
77 		    0) == -1) {
78 			perror("dor: reading status");
79 			return;
80 		}
81 		prst = &pstatus;
82 	}
83 	(void) printf("outs:\n");
84 	disp_reg_line(ph, prst, "o0", R_O0, "o4", R_O4);
85 	disp_reg_line(ph, prst, "o1", R_O1, "o5", R_O5);
86 	disp_reg_line(ph, prst, "o2", R_O2, "o6(sp)", R_O6);
87 	disp_reg_line(ph, prst, "o3", R_O3, "o7", R_O7);
88 }
89 
90 void
display_special_regs(struct ps_prochandle * ph,pstatus_t * prst)91 display_special_regs(struct ps_prochandle *ph, pstatus_t *prst)
92 {
93 	pstatus_t	pstatus;
94 
95 	if (prst == NULL) {
96 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
97 		    0) == -1) {
98 			perror("dsr: reading status");
99 			return;
100 		}
101 		prst = &pstatus;
102 	}
103 	(void) printf("specials:\n");
104 	disp_reg_line(ph, prst, "psr", R_PSR, "pc", R_PC);
105 	disp_reg_line(ph, prst, "npc", R_nPC, "Y", R_Y);
106 	disp_reg_line(ph, prst, "wim", R_WIM, "TBR", R_TBR);
107 }
108 
109 void
display_global_regs(struct ps_prochandle * ph,pstatus_t * prst)110 display_global_regs(struct ps_prochandle *ph, pstatus_t *prst)
111 {
112 	pstatus_t	pstatus;
113 
114 	if (prst == NULL) {
115 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
116 		    0) == -1) {
117 			perror("dgr: reading status");
118 			return;
119 		}
120 		prst = &pstatus;
121 	}
122 	(void) printf("globals:\n");
123 	disp_reg_line(ph, prst, "g0", R_G0, "g4", R_G4);
124 	disp_reg_line(ph, prst, "g1", R_G1, "g5", R_G5);
125 	disp_reg_line(ph, prst, "g2", R_G2, "g6", R_G6);
126 	disp_reg_line(ph, prst, "g3", R_G3, "g7", R_G7);
127 }
128 
129 void
display_in_regs(struct ps_prochandle * ph,pstatus_t * prst)130 display_in_regs(struct ps_prochandle *ph, pstatus_t *prst)
131 {
132 	pstatus_t	pstatus;
133 
134 	if (prst == NULL) {
135 		if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
136 		    0) == -1) {
137 			perror("dir: reading status");
138 			return;
139 		}
140 		prst = &pstatus;
141 	}
142 	(void) printf("ins:\n");
143 	disp_reg_line(ph, prst, "i0", R_I0, "i4", R_I4);
144 	disp_reg_line(ph, prst, "i1", R_I1, "i5", R_I5);
145 	disp_reg_line(ph, prst, "i2", R_I2, "i6(fp)", R_I6);
146 	disp_reg_line(ph, prst, "i3", R_I3, "i7", R_I7);
147 
148 }
149 
150 retc_t
display_all_regs(struct ps_prochandle * ph)151 display_all_regs(struct ps_prochandle *ph)
152 {
153 	pstatus_t	pstatus;
154 
155 	if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
156 	    0) == -1) {
157 		perror("dar: reading status");
158 		return (RET_FAILED);
159 	}
160 	display_global_regs(ph, &pstatus);
161 	display_in_regs(ph, &pstatus);
162 	display_local_regs(ph, &pstatus);
163 	display_out_regs(ph, &pstatus);
164 	display_special_regs(ph, &pstatus);
165 
166 	return (RET_OK);
167 }
168