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 if (ph->pp_dmodel == PR_MODEL_LP64) {
46*12927SRod.Evans@Sun.COM /*
47*12927SRod.Evans@Sun.COM * In 64-bits, the display gets too wide when
48*12927SRod.Evans@Sun.COM * you have both a 64-bit address and a symbol
49*12927SRod.Evans@Sun.COM * name, e.g. _GLOBAL_OFFSET_TABLE; therefore,
50*12927SRod.Evans@Sun.COM * each is put on a separate line. This isn't
51*12927SRod.Evans@Sun.COM * as convenient as the 32-bit display.
52*12927SRod.Evans@Sun.COM */
53*12927SRod.Evans@Sun.COM (void) printf("%8s: 0x%08lx %-16s\n", r1,
54*12927SRod.Evans@Sun.COM prst->pr_lwp.pr_reg[ind1], str1);
55*12927SRod.Evans@Sun.COM (void) printf("%8s: 0x%08lx %-16s\n", r2,
56*12927SRod.Evans@Sun.COM prst->pr_lwp.pr_reg[ind2], str2);
57*12927SRod.Evans@Sun.COM } else
58*12927SRod.Evans@Sun.COM (void) printf("%8s: 0x%08lx %-16s %8s: 0x%08lx %-16s\n", r1,
59*12927SRod.Evans@Sun.COM prst->pr_lwp.pr_reg[ind1], str1, r2,
60*12927SRod.Evans@Sun.COM prst->pr_lwp.pr_reg[ind2], str2);
61*12927SRod.Evans@Sun.COM }
62*12927SRod.Evans@Sun.COM
63*12927SRod.Evans@Sun.COM void
display_local_regs(struct ps_prochandle * ph,pstatus_t * prst)64*12927SRod.Evans@Sun.COM display_local_regs(struct ps_prochandle *ph, pstatus_t *prst)
65*12927SRod.Evans@Sun.COM {
66*12927SRod.Evans@Sun.COM pstatus_t pstatus;
67*12927SRod.Evans@Sun.COM
68*12927SRod.Evans@Sun.COM if (prst == NULL) {
69*12927SRod.Evans@Sun.COM if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
70*12927SRod.Evans@Sun.COM 0) == -1) {
71*12927SRod.Evans@Sun.COM perror("dar: reading status");
72*12927SRod.Evans@Sun.COM return;
73*12927SRod.Evans@Sun.COM }
74*12927SRod.Evans@Sun.COM prst = &pstatus;
75*12927SRod.Evans@Sun.COM }
76*12927SRod.Evans@Sun.COM (void) printf("locals:\n");
77*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "l0", R_L0, "l4", R_L4);
78*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "l1", R_L1, "l5", R_L5);
79*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "l2", R_L2, "l6", R_L6);
80*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "l3", R_L3, "l7", R_L7);
81*12927SRod.Evans@Sun.COM }
82*12927SRod.Evans@Sun.COM
83*12927SRod.Evans@Sun.COM void
display_out_regs(struct ps_prochandle * ph,pstatus_t * prst)84*12927SRod.Evans@Sun.COM display_out_regs(struct ps_prochandle *ph, pstatus_t *prst)
85*12927SRod.Evans@Sun.COM {
86*12927SRod.Evans@Sun.COM pstatus_t pstatus;
87*12927SRod.Evans@Sun.COM
88*12927SRod.Evans@Sun.COM if (prst == NULL) {
89*12927SRod.Evans@Sun.COM if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
90*12927SRod.Evans@Sun.COM 0) == -1) {
91*12927SRod.Evans@Sun.COM perror("dar: reading status");
92*12927SRod.Evans@Sun.COM return;
93*12927SRod.Evans@Sun.COM }
94*12927SRod.Evans@Sun.COM prst = &pstatus;
95*12927SRod.Evans@Sun.COM }
96*12927SRod.Evans@Sun.COM (void) printf("outs:\n");
97*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "o0", R_O0, "o4", R_O4);
98*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "o1", R_O1, "o5", R_O5);
99*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "o2", R_O2, "o6(sp)", R_O6);
100*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "o3", R_O3, "o7", R_O7);
101*12927SRod.Evans@Sun.COM }
102*12927SRod.Evans@Sun.COM
103*12927SRod.Evans@Sun.COM void
display_special_regs(struct ps_prochandle * ph,pstatus_t * prst)104*12927SRod.Evans@Sun.COM display_special_regs(struct ps_prochandle *ph, pstatus_t *prst)
105*12927SRod.Evans@Sun.COM {
106*12927SRod.Evans@Sun.COM pstatus_t pstatus;
107*12927SRod.Evans@Sun.COM
108*12927SRod.Evans@Sun.COM if (prst == NULL) {
109*12927SRod.Evans@Sun.COM if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
110*12927SRod.Evans@Sun.COM 0) == -1) {
111*12927SRod.Evans@Sun.COM perror("dar: reading status");
112*12927SRod.Evans@Sun.COM return;
113*12927SRod.Evans@Sun.COM }
114*12927SRod.Evans@Sun.COM prst = &pstatus;
115*12927SRod.Evans@Sun.COM }
116*12927SRod.Evans@Sun.COM (void) printf("specials:\n");
117*12927SRod.Evans@Sun.COM if (ph->pp_dmodel == PR_MODEL_LP64) {
118*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "ccr", R_CCR, "pc", R_PC);
119*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "npc", R_nPC, "Y", R_Y);
120*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "asi", R_ASI, "FPRS", R_FPRS);
121*12927SRod.Evans@Sun.COM } else {
122*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "psr", R_PSR, "pc", R_PC);
123*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "npc", R_nPC, "Y", R_Y);
124*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "wim", R_WIM, "TBR", R_TBR);
125*12927SRod.Evans@Sun.COM }
126*12927SRod.Evans@Sun.COM }
127*12927SRod.Evans@Sun.COM
128*12927SRod.Evans@Sun.COM void
display_global_regs(struct ps_prochandle * ph,pstatus_t * prst)129*12927SRod.Evans@Sun.COM display_global_regs(struct ps_prochandle *ph, pstatus_t *prst)
130*12927SRod.Evans@Sun.COM {
131*12927SRod.Evans@Sun.COM pstatus_t pstatus;
132*12927SRod.Evans@Sun.COM
133*12927SRod.Evans@Sun.COM if (prst == NULL) {
134*12927SRod.Evans@Sun.COM if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
135*12927SRod.Evans@Sun.COM 0) == -1) {
136*12927SRod.Evans@Sun.COM perror("dar: reading status");
137*12927SRod.Evans@Sun.COM return;
138*12927SRod.Evans@Sun.COM }
139*12927SRod.Evans@Sun.COM prst = &pstatus;
140*12927SRod.Evans@Sun.COM }
141*12927SRod.Evans@Sun.COM (void) printf("globals:\n");
142*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "g0", R_G0, "g4", R_G4);
143*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "g1", R_G1, "g5", R_G5);
144*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "g2", R_G2, "g6", R_G6);
145*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "g3", R_G3, "g7", R_G7);
146*12927SRod.Evans@Sun.COM }
147*12927SRod.Evans@Sun.COM
148*12927SRod.Evans@Sun.COM void
display_in_regs(struct ps_prochandle * ph,pstatus_t * prst)149*12927SRod.Evans@Sun.COM display_in_regs(struct ps_prochandle *ph, pstatus_t *prst)
150*12927SRod.Evans@Sun.COM {
151*12927SRod.Evans@Sun.COM pstatus_t pstatus;
152*12927SRod.Evans@Sun.COM
153*12927SRod.Evans@Sun.COM if (prst == NULL) {
154*12927SRod.Evans@Sun.COM if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
155*12927SRod.Evans@Sun.COM 0) == -1) {
156*12927SRod.Evans@Sun.COM perror("dar: reading status");
157*12927SRod.Evans@Sun.COM return;
158*12927SRod.Evans@Sun.COM }
159*12927SRod.Evans@Sun.COM prst = &pstatus;
160*12927SRod.Evans@Sun.COM }
161*12927SRod.Evans@Sun.COM (void) printf("ins:\n");
162*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "i0", R_I0, "i4", R_I4);
163*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "i1", R_I1, "i5", R_I5);
164*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "i2", R_I2, "i6(fp)", R_I6);
165*12927SRod.Evans@Sun.COM disp_reg_line(ph, prst, "i3", R_I3, "i7", R_I7);
166*12927SRod.Evans@Sun.COM
167*12927SRod.Evans@Sun.COM }
168*12927SRod.Evans@Sun.COM
169*12927SRod.Evans@Sun.COM retc_t
display_all_regs(struct ps_prochandle * ph)170*12927SRod.Evans@Sun.COM display_all_regs(struct ps_prochandle *ph)
171*12927SRod.Evans@Sun.COM {
172*12927SRod.Evans@Sun.COM pstatus_t pstatus;
173*12927SRod.Evans@Sun.COM
174*12927SRod.Evans@Sun.COM if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
175*12927SRod.Evans@Sun.COM 0) == -1) {
176*12927SRod.Evans@Sun.COM perror("dar: reading status");
177*12927SRod.Evans@Sun.COM return (RET_FAILED);
178*12927SRod.Evans@Sun.COM }
179*12927SRod.Evans@Sun.COM display_global_regs(ph, &pstatus);
180*12927SRod.Evans@Sun.COM display_in_regs(ph, &pstatus);
181*12927SRod.Evans@Sun.COM display_local_regs(ph, &pstatus);
182*12927SRod.Evans@Sun.COM display_out_regs(ph, &pstatus);
183*12927SRod.Evans@Sun.COM display_special_regs(ph, &pstatus);
184*12927SRod.Evans@Sun.COM
185*12927SRod.Evans@Sun.COM return (RET_OK);
186*12927SRod.Evans@Sun.COM }
187