xref: /titanic_44/usr/src/lib/libdisasm/common/dis_sparc_fmt.c (revision f7184619589931c4b827180c213074c470f08a8f)
1*f7184619SJoshua M. Clulow /*
2*f7184619SJoshua M. Clulow  * CDDL HEADER START
3*f7184619SJoshua M. Clulow  *
4*f7184619SJoshua M. Clulow  * The contents of this file are subject to the terms of the
5*f7184619SJoshua M. Clulow  * Common Development and Distribution License (the "License").
6*f7184619SJoshua M. Clulow  * You may not use this file except in compliance with the License.
7*f7184619SJoshua M. Clulow  *
8*f7184619SJoshua M. Clulow  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*f7184619SJoshua M. Clulow  * or http://www.opensolaris.org/os/licensing.
10*f7184619SJoshua M. Clulow  * See the License for the specific language governing permissions
11*f7184619SJoshua M. Clulow  * and limitations under the License.
12*f7184619SJoshua M. Clulow  *
13*f7184619SJoshua M. Clulow  * When distributing Covered Code, include this CDDL HEADER in each
14*f7184619SJoshua M. Clulow  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*f7184619SJoshua M. Clulow  * If applicable, add the following below this CDDL HEADER, with the
16*f7184619SJoshua M. Clulow  * fields enclosed by brackets "[]" replaced with your own identifying
17*f7184619SJoshua M. Clulow  * information: Portions Copyright [yyyy] [name of copyright owner]
18*f7184619SJoshua M. Clulow  *
19*f7184619SJoshua M. Clulow  * CDDL HEADER END
20*f7184619SJoshua M. Clulow  */
21*f7184619SJoshua M. Clulow 
22*f7184619SJoshua M. Clulow /*
23*f7184619SJoshua M. Clulow  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*f7184619SJoshua M. Clulow  * Use is subject to license terms.
25*f7184619SJoshua M. Clulow  */
26*f7184619SJoshua M. Clulow 
27*f7184619SJoshua M. Clulow /*
28*f7184619SJoshua M. Clulow  * Copyright 2009 Jason King.  All rights reserved.
29*f7184619SJoshua M. Clulow  * Use is subject to license terms.
30*f7184619SJoshua M. Clulow  * Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
31*f7184619SJoshua M. Clulow  */
32*f7184619SJoshua M. Clulow 
33*f7184619SJoshua M. Clulow 
34*f7184619SJoshua M. Clulow #include <sys/byteorder.h>
35*f7184619SJoshua M. Clulow #include <stdarg.h>
36*f7184619SJoshua M. Clulow 
37*f7184619SJoshua M. Clulow #if !defined(DIS_STANDALONE)
38*f7184619SJoshua M. Clulow #include <stdio.h>
39*f7184619SJoshua M. Clulow #endif /* DIS_STANDALONE */
40*f7184619SJoshua M. Clulow 
41*f7184619SJoshua M. Clulow #include "libdisasm.h"
42*f7184619SJoshua M. Clulow #include "libdisasm_impl.h"
43*f7184619SJoshua M. Clulow #include "dis_sparc.h"
44*f7184619SJoshua M. Clulow #include "dis_sparc_fmt.h"
45*f7184619SJoshua M. Clulow 
46*f7184619SJoshua M. Clulow extern char *strncpy(char *, const char *, size_t);
47*f7184619SJoshua M. Clulow extern size_t strlen(const char *);
48*f7184619SJoshua M. Clulow extern int strcmp(const char *, const char *);
49*f7184619SJoshua M. Clulow extern int strncmp(const char *, const char *, size_t);
50*f7184619SJoshua M. Clulow extern size_t strlcat(char *, const char *, size_t);
51*f7184619SJoshua M. Clulow extern size_t strlcpy(char *, const char *, size_t);
52*f7184619SJoshua M. Clulow 
53*f7184619SJoshua M. Clulow /*
54*f7184619SJoshua M. Clulow  * This file has the functions that do all the dirty work of outputting the
55*f7184619SJoshua M. Clulow  * disassembled instruction
56*f7184619SJoshua M. Clulow  *
57*f7184619SJoshua M. Clulow  * All the non-static functions follow the format_fcn (in dis_sparc.h):
58*f7184619SJoshua M. Clulow  * Input:
59*f7184619SJoshua M. Clulow  *	disassembler handle/context
60*f7184619SJoshua M. Clulow  *	instruction to disassemble
61*f7184619SJoshua M. Clulow  *	instruction definition pointer (inst_t *)
62*f7184619SJoshua M. Clulow  *	index in the table of the instruction
63*f7184619SJoshua M. Clulow  * Return:
64*f7184619SJoshua M. Clulow  *	0 Success
65*f7184619SJoshua M. Clulow  *    !0 Invalid instruction
66*f7184619SJoshua M. Clulow  *
67*f7184619SJoshua M. Clulow  * Generally, instructions found in the same table use the same output format
68*f7184619SJoshua M. Clulow  * or have a few minor differences (which are described in the 'flags' field
69*f7184619SJoshua M. Clulow  * of the instruction definition. In some cases, certain instructions differ
70*f7184619SJoshua M. Clulow  * radically enough from those in the same table, that their own format
71*f7184619SJoshua M. Clulow  * function is used.
72*f7184619SJoshua M. Clulow  *
73*f7184619SJoshua M. Clulow  * Typically each table has a unique format function defined in this file.  In
74*f7184619SJoshua M. Clulow  * some cases (such as branches) a common one for all the tables is used.
75*f7184619SJoshua M. Clulow  *
76*f7184619SJoshua M. Clulow  * When adding support for new instructions, it is largely a judgement call
77*f7184619SJoshua M. Clulow  * as to when a new format function is defined.
78*f7184619SJoshua M. Clulow  */
79*f7184619SJoshua M. Clulow 
80*f7184619SJoshua M. Clulow /* The various instruction formats of a sparc instruction */
81*f7184619SJoshua M. Clulow 
82*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
83*f7184619SJoshua M. Clulow typedef struct format1 {
84*f7184619SJoshua M. Clulow 	uint32_t op:2;
85*f7184619SJoshua M. Clulow 	uint32_t disp30:30;
86*f7184619SJoshua M. Clulow } format1_t;
87*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
88*f7184619SJoshua M. Clulow typedef struct format1 {
89*f7184619SJoshua M. Clulow 	uint32_t disp30:30;
90*f7184619SJoshua M. Clulow 	uint32_t op:2;
91*f7184619SJoshua M. Clulow } format1_t;
92*f7184619SJoshua M. Clulow #else
93*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
94*f7184619SJoshua M. Clulow #endif
95*f7184619SJoshua M. Clulow 
96*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
97*f7184619SJoshua M. Clulow typedef struct format2 {
98*f7184619SJoshua M. Clulow 	uint32_t op:2;
99*f7184619SJoshua M. Clulow 	uint32_t rd:5;
100*f7184619SJoshua M. Clulow 	uint32_t op2:3;
101*f7184619SJoshua M. Clulow 	uint32_t imm22:22;
102*f7184619SJoshua M. Clulow } format2_t;
103*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
104*f7184619SJoshua M. Clulow typedef struct format2 {
105*f7184619SJoshua M. Clulow 	uint32_t imm22:22;
106*f7184619SJoshua M. Clulow 	uint32_t op2:3;
107*f7184619SJoshua M. Clulow 	uint32_t rd:5;
108*f7184619SJoshua M. Clulow 	uint32_t op:2;
109*f7184619SJoshua M. Clulow } format2_t;
110*f7184619SJoshua M. Clulow #else
111*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
112*f7184619SJoshua M. Clulow #endif
113*f7184619SJoshua M. Clulow 
114*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
115*f7184619SJoshua M. Clulow typedef struct format2a {
116*f7184619SJoshua M. Clulow 	uint32_t op:2;
117*f7184619SJoshua M. Clulow 	uint32_t a:1;
118*f7184619SJoshua M. Clulow 	uint32_t cond:4;
119*f7184619SJoshua M. Clulow 	uint32_t op2:3;
120*f7184619SJoshua M. Clulow 	uint32_t disp22:22;
121*f7184619SJoshua M. Clulow } format2a_t;
122*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
123*f7184619SJoshua M. Clulow typedef struct format2a {
124*f7184619SJoshua M. Clulow 	uint32_t disp22:22;
125*f7184619SJoshua M. Clulow 	uint32_t op2:3;
126*f7184619SJoshua M. Clulow 	uint32_t cond:4;
127*f7184619SJoshua M. Clulow 	uint32_t a:1;
128*f7184619SJoshua M. Clulow 	uint32_t op:2;
129*f7184619SJoshua M. Clulow } format2a_t;
130*f7184619SJoshua M. Clulow #else
131*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
132*f7184619SJoshua M. Clulow #endif
133*f7184619SJoshua M. Clulow 
134*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
135*f7184619SJoshua M. Clulow typedef struct format2b {
136*f7184619SJoshua M. Clulow 	uint32_t op:2;
137*f7184619SJoshua M. Clulow 	uint32_t a:1;
138*f7184619SJoshua M. Clulow 	uint32_t cond:4;
139*f7184619SJoshua M. Clulow 	uint32_t op2:3;
140*f7184619SJoshua M. Clulow 	uint32_t cc:2;
141*f7184619SJoshua M. Clulow 	uint32_t p:1;
142*f7184619SJoshua M. Clulow 	uint32_t disp19:19;
143*f7184619SJoshua M. Clulow } format2b_t;
144*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
145*f7184619SJoshua M. Clulow typedef struct format2b {
146*f7184619SJoshua M. Clulow 	uint32_t disp19:19;
147*f7184619SJoshua M. Clulow 	uint32_t p:1;
148*f7184619SJoshua M. Clulow 	uint32_t cc:2;
149*f7184619SJoshua M. Clulow 	uint32_t op2:3;
150*f7184619SJoshua M. Clulow 	uint32_t cond:4;
151*f7184619SJoshua M. Clulow 	uint32_t a:1;
152*f7184619SJoshua M. Clulow 	uint32_t op:2;
153*f7184619SJoshua M. Clulow } format2b_t;
154*f7184619SJoshua M. Clulow #else
155*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
156*f7184619SJoshua M. Clulow #endif
157*f7184619SJoshua M. Clulow 
158*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
159*f7184619SJoshua M. Clulow typedef struct format2c {
160*f7184619SJoshua M. Clulow 	uint32_t op:2;
161*f7184619SJoshua M. Clulow 	uint32_t a:1;
162*f7184619SJoshua M. Clulow 	uint32_t cond:4;
163*f7184619SJoshua M. Clulow 	uint32_t op2:3;
164*f7184619SJoshua M. Clulow 	uint32_t d16hi:2;
165*f7184619SJoshua M. Clulow 	uint32_t p:1;
166*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
167*f7184619SJoshua M. Clulow 	uint32_t d16lo:14;
168*f7184619SJoshua M. Clulow } format2c_t;
169*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
170*f7184619SJoshua M. Clulow typedef struct format2c {
171*f7184619SJoshua M. Clulow 	uint32_t d16lo:14;
172*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
173*f7184619SJoshua M. Clulow 	uint32_t p:1;
174*f7184619SJoshua M. Clulow 	uint32_t d16hi:2;
175*f7184619SJoshua M. Clulow 	uint32_t op2:3;
176*f7184619SJoshua M. Clulow 	uint32_t cond:4;
177*f7184619SJoshua M. Clulow 	uint32_t a:1;
178*f7184619SJoshua M. Clulow 	uint32_t op:2;
179*f7184619SJoshua M. Clulow } format2c_t;
180*f7184619SJoshua M. Clulow #else
181*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
182*f7184619SJoshua M. Clulow #endif
183*f7184619SJoshua M. Clulow 
184*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
185*f7184619SJoshua M. Clulow typedef struct format3 {
186*f7184619SJoshua M. Clulow 	uint32_t op:2;
187*f7184619SJoshua M. Clulow 	uint32_t rd:5;
188*f7184619SJoshua M. Clulow 	uint32_t op3:6;
189*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
190*f7184619SJoshua M. Clulow 	uint32_t i:1;
191*f7184619SJoshua M. Clulow 	uint32_t asi:8;
192*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
193*f7184619SJoshua M. Clulow } format3_t;
194*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
195*f7184619SJoshua M. Clulow typedef struct format3 {
196*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
197*f7184619SJoshua M. Clulow 	uint32_t asi:8;
198*f7184619SJoshua M. Clulow 	uint32_t i:1;
199*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
200*f7184619SJoshua M. Clulow 	uint32_t op3:6;
201*f7184619SJoshua M. Clulow 	uint32_t rd:5;
202*f7184619SJoshua M. Clulow 	uint32_t op:2;
203*f7184619SJoshua M. Clulow } format3_t;
204*f7184619SJoshua M. Clulow #else
205*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
206*f7184619SJoshua M. Clulow #endif
207*f7184619SJoshua M. Clulow 
208*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
209*f7184619SJoshua M. Clulow typedef struct format3a {
210*f7184619SJoshua M. Clulow 	uint32_t op:2;
211*f7184619SJoshua M. Clulow 	uint32_t rd:5;
212*f7184619SJoshua M. Clulow 	uint32_t op3:6;
213*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
214*f7184619SJoshua M. Clulow 	uint32_t i:1;
215*f7184619SJoshua M. Clulow 	uint32_t simm13:13;
216*f7184619SJoshua M. Clulow } format3a_t;
217*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
218*f7184619SJoshua M. Clulow typedef struct format3a {
219*f7184619SJoshua M. Clulow 	uint32_t simm13:13;
220*f7184619SJoshua M. Clulow 	uint32_t i:1;
221*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
222*f7184619SJoshua M. Clulow 	uint32_t op3:6;
223*f7184619SJoshua M. Clulow 	uint32_t rd:5;
224*f7184619SJoshua M. Clulow 	uint32_t op:2;
225*f7184619SJoshua M. Clulow } format3a_t;
226*f7184619SJoshua M. Clulow #else
227*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
228*f7184619SJoshua M. Clulow #endif
229*f7184619SJoshua M. Clulow 
230*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
231*f7184619SJoshua M. Clulow typedef struct format3b {
232*f7184619SJoshua M. Clulow 	uint32_t op:2;
233*f7184619SJoshua M. Clulow 	uint32_t rd:5;
234*f7184619SJoshua M. Clulow 	uint32_t op3:6;
235*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
236*f7184619SJoshua M. Clulow 	uint32_t i:1;
237*f7184619SJoshua M. Clulow 	uint32_t x:1;
238*f7184619SJoshua M. Clulow 	uint32_t undef:6;
239*f7184619SJoshua M. Clulow 	uint32_t shcnt:6;
240*f7184619SJoshua M. Clulow } format3b_t;
241*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
242*f7184619SJoshua M. Clulow typedef struct format3b {
243*f7184619SJoshua M. Clulow 	uint32_t shcnt:6;
244*f7184619SJoshua M. Clulow 	uint32_t undef:6;
245*f7184619SJoshua M. Clulow 	uint32_t x:1;
246*f7184619SJoshua M. Clulow 	uint32_t i:1;
247*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
248*f7184619SJoshua M. Clulow 	uint32_t op3:6;
249*f7184619SJoshua M. Clulow 	uint32_t rd:5;
250*f7184619SJoshua M. Clulow 	uint32_t op:2;
251*f7184619SJoshua M. Clulow } format3b_t;
252*f7184619SJoshua M. Clulow #else
253*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
254*f7184619SJoshua M. Clulow #endif
255*f7184619SJoshua M. Clulow 
256*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
257*f7184619SJoshua M. Clulow typedef struct format3c {
258*f7184619SJoshua M. Clulow 	uint32_t op:2;
259*f7184619SJoshua M. Clulow 	uint32_t rd:5;
260*f7184619SJoshua M. Clulow 	uint32_t op3:6;
261*f7184619SJoshua M. Clulow 	uint32_t cc2:1;
262*f7184619SJoshua M. Clulow 	uint32_t cond:4;
263*f7184619SJoshua M. Clulow 	uint32_t i:1;
264*f7184619SJoshua M. Clulow 	uint32_t cc:2;
265*f7184619SJoshua M. Clulow 	uint32_t simm11:11;
266*f7184619SJoshua M. Clulow } format3c_t;
267*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
268*f7184619SJoshua M. Clulow typedef struct format3c {
269*f7184619SJoshua M. Clulow 	uint32_t simm11:11;
270*f7184619SJoshua M. Clulow 	uint32_t cc:2;
271*f7184619SJoshua M. Clulow 	uint32_t i:1;
272*f7184619SJoshua M. Clulow 	uint32_t cond:4;
273*f7184619SJoshua M. Clulow 	uint32_t cc2:1;
274*f7184619SJoshua M. Clulow 	uint32_t op3:6;
275*f7184619SJoshua M. Clulow 	uint32_t rd:5;
276*f7184619SJoshua M. Clulow 	uint32_t op:2;
277*f7184619SJoshua M. Clulow } format3c_t;
278*f7184619SJoshua M. Clulow #else
279*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
280*f7184619SJoshua M. Clulow #endif
281*f7184619SJoshua M. Clulow 
282*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
283*f7184619SJoshua M. Clulow typedef struct format3d {
284*f7184619SJoshua M. Clulow 	uint32_t op:2;
285*f7184619SJoshua M. Clulow 	uint32_t rd:5;
286*f7184619SJoshua M. Clulow 	uint32_t op3:6;
287*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
288*f7184619SJoshua M. Clulow 	uint32_t i:1;
289*f7184619SJoshua M. Clulow 	uint32_t rcond:3;
290*f7184619SJoshua M. Clulow 	uint32_t simm10:10;
291*f7184619SJoshua M. Clulow } format3d_t;
292*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
293*f7184619SJoshua M. Clulow typedef struct format3d {
294*f7184619SJoshua M. Clulow 	uint32_t simm10:10;
295*f7184619SJoshua M. Clulow 	uint32_t rcond:3;
296*f7184619SJoshua M. Clulow 	uint32_t i:1;
297*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
298*f7184619SJoshua M. Clulow 	uint32_t op3:6;
299*f7184619SJoshua M. Clulow 	uint32_t rd:5;
300*f7184619SJoshua M. Clulow 	uint32_t op:2;
301*f7184619SJoshua M. Clulow } format3d_t;
302*f7184619SJoshua M. Clulow #else
303*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
304*f7184619SJoshua M. Clulow #endif
305*f7184619SJoshua M. Clulow 
306*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
307*f7184619SJoshua M. Clulow typedef struct formatcp {
308*f7184619SJoshua M. Clulow 	uint32_t op:2;
309*f7184619SJoshua M. Clulow 	uint32_t rd:5;
310*f7184619SJoshua M. Clulow 	uint32_t op3:6;
311*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
312*f7184619SJoshua M. Clulow 	uint32_t opc:9;
313*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
314*f7184619SJoshua M. Clulow } formatcp_t;
315*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
316*f7184619SJoshua M. Clulow typedef struct formatcp {
317*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
318*f7184619SJoshua M. Clulow 	uint32_t opc:9;
319*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
320*f7184619SJoshua M. Clulow 	uint32_t op3:6;
321*f7184619SJoshua M. Clulow 	uint32_t rd:5;
322*f7184619SJoshua M. Clulow 	uint32_t op:2;
323*f7184619SJoshua M. Clulow } formatcp_t;
324*f7184619SJoshua M. Clulow #else
325*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
326*f7184619SJoshua M. Clulow #endif
327*f7184619SJoshua M. Clulow 
328*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
329*f7184619SJoshua M. Clulow typedef struct formattcc {
330*f7184619SJoshua M. Clulow 	uint32_t op:2;
331*f7184619SJoshua M. Clulow 	uint32_t undef:1;
332*f7184619SJoshua M. Clulow 	uint32_t cond:4;
333*f7184619SJoshua M. Clulow 	uint32_t op3:6;
334*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
335*f7184619SJoshua M. Clulow 	uint32_t i:1;
336*f7184619SJoshua M. Clulow 	uint32_t cc:2;
337*f7184619SJoshua M. Clulow 	uint32_t undef2:3;
338*f7184619SJoshua M. Clulow 	uint32_t immtrap:8;
339*f7184619SJoshua M. Clulow } formattcc_t;
340*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
341*f7184619SJoshua M. Clulow typedef struct formattcc {
342*f7184619SJoshua M. Clulow 	uint32_t immtrap:8;
343*f7184619SJoshua M. Clulow 	uint32_t undef2:3;
344*f7184619SJoshua M. Clulow 	uint32_t cc:2;
345*f7184619SJoshua M. Clulow 	uint32_t i:1;
346*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
347*f7184619SJoshua M. Clulow 	uint32_t op3:6;
348*f7184619SJoshua M. Clulow 	uint32_t cond:4;
349*f7184619SJoshua M. Clulow 	uint32_t undef:1;
350*f7184619SJoshua M. Clulow 	uint32_t op:2;
351*f7184619SJoshua M. Clulow } formattcc_t;
352*f7184619SJoshua M. Clulow #else
353*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
354*f7184619SJoshua M. Clulow #endif
355*f7184619SJoshua M. Clulow 
356*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
357*f7184619SJoshua M. Clulow typedef struct formattcc2 {
358*f7184619SJoshua M. Clulow 	uint32_t op:2;
359*f7184619SJoshua M. Clulow 	uint32_t undef:1;
360*f7184619SJoshua M. Clulow 	uint32_t cond:4;
361*f7184619SJoshua M. Clulow 	uint32_t op3:6;
362*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
363*f7184619SJoshua M. Clulow 	uint32_t i:1;
364*f7184619SJoshua M. Clulow 	uint32_t cc:2;
365*f7184619SJoshua M. Clulow 	uint32_t undef2:6;
366*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
367*f7184619SJoshua M. Clulow } formattcc2_t;
368*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
369*f7184619SJoshua M. Clulow typedef struct formattcc2 {
370*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
371*f7184619SJoshua M. Clulow 	uint32_t undef2:6;
372*f7184619SJoshua M. Clulow 	uint32_t cc:2;
373*f7184619SJoshua M. Clulow 	uint32_t i:1;
374*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
375*f7184619SJoshua M. Clulow 	uint32_t op3:6;
376*f7184619SJoshua M. Clulow 	uint32_t cond:4;
377*f7184619SJoshua M. Clulow 	uint32_t undef:1;
378*f7184619SJoshua M. Clulow 	uint32_t op:2;
379*f7184619SJoshua M. Clulow } formattcc2_t;
380*f7184619SJoshua M. Clulow #else
381*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
382*f7184619SJoshua M. Clulow #endif
383*f7184619SJoshua M. Clulow 
384*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
385*f7184619SJoshua M. Clulow typedef struct formatmbr {
386*f7184619SJoshua M. Clulow 	uint32_t op:2;
387*f7184619SJoshua M. Clulow 	uint32_t rd:5;
388*f7184619SJoshua M. Clulow 	uint32_t op3:6;
389*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
390*f7184619SJoshua M. Clulow 	uint32_t i:1;
391*f7184619SJoshua M. Clulow 	uint32_t undef:6;
392*f7184619SJoshua M. Clulow 	uint32_t cmask:3;
393*f7184619SJoshua M. Clulow 	uint32_t mmask:4;
394*f7184619SJoshua M. Clulow } formatmbr_t;
395*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
396*f7184619SJoshua M. Clulow typedef struct formatmbr {
397*f7184619SJoshua M. Clulow 	uint32_t mmask:4;
398*f7184619SJoshua M. Clulow 	uint32_t cmask:3;
399*f7184619SJoshua M. Clulow 	uint32_t undef:6;
400*f7184619SJoshua M. Clulow 	uint32_t i:1;
401*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
402*f7184619SJoshua M. Clulow 	uint32_t op3:6;
403*f7184619SJoshua M. Clulow 	uint32_t rd:5;
404*f7184619SJoshua M. Clulow 	uint32_t op:2;
405*f7184619SJoshua M. Clulow } formatmbr_t;
406*f7184619SJoshua M. Clulow #else
407*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
408*f7184619SJoshua M. Clulow #endif
409*f7184619SJoshua M. Clulow 
410*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
411*f7184619SJoshua M. Clulow typedef struct formatfcmp {
412*f7184619SJoshua M. Clulow 	uint32_t op:2;
413*f7184619SJoshua M. Clulow 	uint32_t undef:3;
414*f7184619SJoshua M. Clulow 	uint32_t cc:2;
415*f7184619SJoshua M. Clulow 	uint32_t op3:6;
416*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
417*f7184619SJoshua M. Clulow 	uint32_t opf:9;
418*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
419*f7184619SJoshua M. Clulow } formatfcmp_t;
420*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
421*f7184619SJoshua M. Clulow typedef struct formatfcmp {
422*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
423*f7184619SJoshua M. Clulow 	uint32_t opf:9;
424*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
425*f7184619SJoshua M. Clulow 	uint32_t op3:6;
426*f7184619SJoshua M. Clulow 	uint32_t cc:2;
427*f7184619SJoshua M. Clulow 	uint32_t undef:3;
428*f7184619SJoshua M. Clulow 	uint32_t op:2;
429*f7184619SJoshua M. Clulow } formatfcmp_t;
430*f7184619SJoshua M. Clulow #else
431*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
432*f7184619SJoshua M. Clulow #endif
433*f7184619SJoshua M. Clulow 
434*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
435*f7184619SJoshua M. Clulow typedef struct formatfmov {
436*f7184619SJoshua M. Clulow 	uint32_t op:2;
437*f7184619SJoshua M. Clulow 	uint32_t rd:5;
438*f7184619SJoshua M. Clulow 	uint32_t op3:6;
439*f7184619SJoshua M. Clulow 	uint32_t undef:1;
440*f7184619SJoshua M. Clulow 	uint32_t cond:4;
441*f7184619SJoshua M. Clulow 	uint32_t cc:3;
442*f7184619SJoshua M. Clulow 	uint32_t opf:6;
443*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
444*f7184619SJoshua M. Clulow } formatfmov_t;
445*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
446*f7184619SJoshua M. Clulow typedef struct formatfmov {
447*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
448*f7184619SJoshua M. Clulow 	uint32_t opf:6;
449*f7184619SJoshua M. Clulow 	uint32_t cc:3;
450*f7184619SJoshua M. Clulow 	uint32_t cond:4;
451*f7184619SJoshua M. Clulow 	uint32_t undef:1;
452*f7184619SJoshua M. Clulow 	uint32_t op3:6;
453*f7184619SJoshua M. Clulow 	uint32_t rd:5;
454*f7184619SJoshua M. Clulow 	uint32_t op:2;
455*f7184619SJoshua M. Clulow } formatfmov_t;
456*f7184619SJoshua M. Clulow #else
457*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
458*f7184619SJoshua M. Clulow #endif
459*f7184619SJoshua M. Clulow 
460*f7184619SJoshua M. Clulow #if defined(_BIT_FIELDS_HTOL)
461*f7184619SJoshua M. Clulow typedef struct formatfused {
462*f7184619SJoshua M. Clulow 	uint32_t op:2;
463*f7184619SJoshua M. Clulow 	uint32_t rd:5;
464*f7184619SJoshua M. Clulow 	uint32_t op3:6;
465*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
466*f7184619SJoshua M. Clulow 	uint32_t rs3:5;
467*f7184619SJoshua M. Clulow 	uint32_t op5:4;
468*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
469*f7184619SJoshua M. Clulow } formatfused_t;
470*f7184619SJoshua M. Clulow #elif defined(_BIT_FIELDS_LTOH)
471*f7184619SJoshua M. Clulow typedef struct formatfused {
472*f7184619SJoshua M. Clulow 	uint32_t rs2:5;
473*f7184619SJoshua M. Clulow 	uint32_t op5:4;
474*f7184619SJoshua M. Clulow 	uint32_t rs3:5;
475*f7184619SJoshua M. Clulow 	uint32_t rs1:5;
476*f7184619SJoshua M. Clulow 	uint32_t op3:6;
477*f7184619SJoshua M. Clulow 	uint32_t rd:5;
478*f7184619SJoshua M. Clulow 	uint32_t op:2;
479*f7184619SJoshua M. Clulow } formatfused_t;
480*f7184619SJoshua M. Clulow #else
481*f7184619SJoshua M. Clulow #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
482*f7184619SJoshua M. Clulow #endif
483*f7184619SJoshua M. Clulow 
484*f7184619SJoshua M. Clulow typedef union ifmt {
485*f7184619SJoshua M. Clulow 	uint32_t	i;
486*f7184619SJoshua M. Clulow 	format1_t	f1;
487*f7184619SJoshua M. Clulow 	format2_t	f2;
488*f7184619SJoshua M. Clulow 	format2a_t	f2a;
489*f7184619SJoshua M. Clulow 	format2b_t	f2b;
490*f7184619SJoshua M. Clulow 	format2c_t	f2c;
491*f7184619SJoshua M. Clulow 	format3_t	f3;
492*f7184619SJoshua M. Clulow 	format3a_t	f3a;
493*f7184619SJoshua M. Clulow 	format3b_t	f3b;
494*f7184619SJoshua M. Clulow 	format3c_t	f3c;
495*f7184619SJoshua M. Clulow 	format3d_t	f3d;
496*f7184619SJoshua M. Clulow 	formatcp_t	fcp;
497*f7184619SJoshua M. Clulow 	formattcc_t	ftcc;
498*f7184619SJoshua M. Clulow 	formattcc2_t	ftcc2;
499*f7184619SJoshua M. Clulow 	formatfcmp_t	fcmp;
500*f7184619SJoshua M. Clulow 	formatmbr_t	fmb;
501*f7184619SJoshua M. Clulow 	formatfmov_t	fmv;
502*f7184619SJoshua M. Clulow 	formatfused_t	fused;
503*f7184619SJoshua M. Clulow } ifmt_t;
504*f7184619SJoshua M. Clulow 
505*f7184619SJoshua M. Clulow /* integer register names */
506*f7184619SJoshua M. Clulow static const char *reg_names[32] = {
507*f7184619SJoshua M. Clulow 	"%g0", "%g1", "%g2", "%g3", "%g4", "%g5", "%g6", "%g7",
508*f7184619SJoshua M. Clulow 	"%o0", "%o1", "%o2", "%o3", "%o4", "%o5", "%sp", "%o7",
509*f7184619SJoshua M. Clulow 	"%l0", "%l1", "%l2", "%l3", "%l4", "%l5", "%l6", "%l7",
510*f7184619SJoshua M. Clulow 	"%i0", "%i1", "%i2", "%i3", "%i4", "%i5", "%fp", "%i7"
511*f7184619SJoshua M. Clulow };
512*f7184619SJoshua M. Clulow 
513*f7184619SJoshua M. Clulow /* floating point register names */
514*f7184619SJoshua M. Clulow static const char *freg_names[32] = {
515*f7184619SJoshua M. Clulow 	"%f0",  "%f1",  "%f2",  "%f3",  "%f4",  "%f5",  "%f6",  "%f7",
516*f7184619SJoshua M. Clulow 	"%f8",  "%f9",  "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
517*f7184619SJoshua M. Clulow 	"%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
518*f7184619SJoshua M. Clulow 	"%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31"
519*f7184619SJoshua M. Clulow };
520*f7184619SJoshua M. Clulow 
521*f7184619SJoshua M. Clulow /* double precision register names */
522*f7184619SJoshua M. Clulow static const char *fdreg_names[32] = {
523*f7184619SJoshua M. Clulow 	"%d0",  "%d32", "%d2",  "%d34", "%d4",  "%d36", "%d6",  "%d38",
524*f7184619SJoshua M. Clulow 	"%d8",  "%d40", "%d10", "%d42", "%d12", "%d44", "%d14", "%d46",
525*f7184619SJoshua M. Clulow 	"%d16", "%d48", "%d18", "%d50", "%d20", "%d52", "%d22", "%d54",
526*f7184619SJoshua M. Clulow 	"%d24", "%d56", "%d26", "%d58", "%d28", "%d60", "%d30", "%d62"
527*f7184619SJoshua M. Clulow };
528*f7184619SJoshua M. Clulow 
529*f7184619SJoshua M. Clulow static const char *compat_fdreg_names[32] = {
530*f7184619SJoshua M. Clulow 	"%f0",  "%f32", "%f2",  "%f34", "%f4",  "%f36", "%f6",  "%f38",
531*f7184619SJoshua M. Clulow 	"%f8",  "%f40", "%f10", "%f42", "%f12", "%f44", "%f14", "%f46",
532*f7184619SJoshua M. Clulow 	"%f16", "%f48", "%f18", "%f50", "%f20", "%f52", "%f22", "%f54",
533*f7184619SJoshua M. Clulow 	"%f24", "%f56", "%f26", "%f58", "%f28", "%f60", "%f30", "%f62"
534*f7184619SJoshua M. Clulow };
535*f7184619SJoshua M. Clulow 
536*f7184619SJoshua M. Clulow 
537*f7184619SJoshua M. Clulow static const char *fqreg_names[32] = {
538*f7184619SJoshua M. Clulow 	"%q0",  "%q32", "%f2",  "%f3",  "%f4",  "%q4",  "%q36", "%f6",
539*f7184619SJoshua M. Clulow 	"%f7",  "%q8",  "%q40", "%f10", "%f11", "%q12", "%q44", "%f14",
540*f7184619SJoshua M. Clulow 	"%f15", "%q16", "%q48", "%f18", "%f19", "%q20", "%q52", "%f22",
541*f7184619SJoshua M. Clulow 	"%f23", "%q24", "%q56", "%f26", "%f27", "%q28", "%q60", "%f30",
542*f7184619SJoshua M. Clulow };
543*f7184619SJoshua M. Clulow 
544*f7184619SJoshua M. Clulow 
545*f7184619SJoshua M. Clulow /* coprocessor register names -- sparcv8 only */
546*f7184619SJoshua M. Clulow static const char *cpreg_names[32] = {
547*f7184619SJoshua M. Clulow 	"%c0",  "%c1",  "%c2",  "%c3",  "%c4",  "%c5",  "%c6",  "%c7",
548*f7184619SJoshua M. Clulow 	"%c8",  "%c9",  "%c10", "%c11", "%c12", "%c13", "%c14", "%c15",
549*f7184619SJoshua M. Clulow 	"%c16", "%c17", "%c18", "%c19", "%c20", "%c21", "%c22", "%c23",
550*f7184619SJoshua M. Clulow 	"%c24", "%c25", "%c26", "%c27", "%c28", "%c29", "%c30", "%c31",
551*f7184619SJoshua M. Clulow };
552*f7184619SJoshua M. Clulow 
553*f7184619SJoshua M. Clulow /* floating point condition code names */
554*f7184619SJoshua M. Clulow static const char *fcc_names[4] = {
555*f7184619SJoshua M. Clulow 	"%fcc0", "%fcc1", "%fcc2", "%fcc3"
556*f7184619SJoshua M. Clulow };
557*f7184619SJoshua M. Clulow 
558*f7184619SJoshua M. Clulow /* condition code names */
559*f7184619SJoshua M. Clulow static const char *icc_names[4] = {
560*f7184619SJoshua M. Clulow 	"%icc", NULL, "%xcc", NULL
561*f7184619SJoshua M. Clulow };
562*f7184619SJoshua M. Clulow 
563*f7184619SJoshua M. Clulow /* bitmask values for membar */
564*f7184619SJoshua M. Clulow static const char *membar_mmask[4] = {
565*f7184619SJoshua M. Clulow 	"#LoadLoad", "#StoreLoad", "#LoadStore", "#StoreStore"
566*f7184619SJoshua M. Clulow };
567*f7184619SJoshua M. Clulow 
568*f7184619SJoshua M. Clulow static const char *membar_cmask[3] = {
569*f7184619SJoshua M. Clulow 	"#Lookaside", "#MemIssue", "#Sync"
570*f7184619SJoshua M. Clulow };
571*f7184619SJoshua M. Clulow 
572*f7184619SJoshua M. Clulow /* v8 ancillary state register names */
573*f7184619SJoshua M. Clulow static const char *asr_names[32] = {
574*f7184619SJoshua M. Clulow 	"%y",	"%asr1",  "%asr2",  "%asr3",
575*f7184619SJoshua M. Clulow 	"%asr4",  "%asr5",  "%asr6",  "%asr7",
576*f7184619SJoshua M. Clulow 	"%asr8",  "%asr9",  "%asr10", "%asr11",
577*f7184619SJoshua M. Clulow 	"%asr12", "%asr13", "%asr14", "%asr15",
578*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
579*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
580*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
581*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL
582*f7184619SJoshua M. Clulow };
583*f7184619SJoshua M. Clulow static const uint32_t asr_rdmask = 0x0000ffffL;
584*f7184619SJoshua M. Clulow static const uint32_t asr_wrmask = 0x0000ffffL;
585*f7184619SJoshua M. Clulow 
586*f7184619SJoshua M. Clulow static const char *v9_asr_names[32] = {
587*f7184619SJoshua M. Clulow 	"%y",		NULL,		"%ccr",	"%asi",
588*f7184619SJoshua M. Clulow 	"%tick",	"%pc",		"%fprs",	NULL,
589*f7184619SJoshua M. Clulow 	NULL,		NULL,		NULL,	NULL,
590*f7184619SJoshua M. Clulow 	NULL,		NULL,		NULL,	NULL,
591*f7184619SJoshua M. Clulow 	"%pcr",		"%pic",		"%dcr",	"%gsr",
592*f7184619SJoshua M. Clulow 	"%softint_set",	"%softint_clr",	"%softint",	"%tick_cmpr",
593*f7184619SJoshua M. Clulow 	"%stick",	"%stick_cmpr",	NULL,	NULL,
594*f7184619SJoshua M. Clulow 	NULL,		NULL,		NULL,	NULL
595*f7184619SJoshua M. Clulow };
596*f7184619SJoshua M. Clulow /*
597*f7184619SJoshua M. Clulow  * on v9, only certain registers are valid for read or writing
598*f7184619SJoshua M. Clulow  * these are bitmasks corresponding to which registers are valid in which
599*f7184619SJoshua M. Clulow  * case. Any access to %dcr is illegal.
600*f7184619SJoshua M. Clulow  */
601*f7184619SJoshua M. Clulow static const uint32_t v9_asr_rdmask = 0x03cb007d;
602*f7184619SJoshua M. Clulow static const uint32_t v9_asr_wrmask = 0x03fb004d;
603*f7184619SJoshua M. Clulow 
604*f7184619SJoshua M. Clulow /* privledged register names on v9 */
605*f7184619SJoshua M. Clulow /* TODO: compat - NULL to %priv_nn */
606*f7184619SJoshua M. Clulow static const char *v9_privreg_names[32] = {
607*f7184619SJoshua M. Clulow 	"%tpc",	 "%tnpc",	"%tstate",  "%tt",
608*f7184619SJoshua M. Clulow 	"%tick",	"%tba",	 "%pstate",  "%tl",
609*f7184619SJoshua M. Clulow 	"%pil",	 "%cwp",	 "%cansave", "%canrestore",
610*f7184619SJoshua M. Clulow 	"%cleanwin", "%otherwin", "%wstate",  "%fq",
611*f7184619SJoshua M. Clulow 	"%gl",	NULL,	NULL,	NULL,
612*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
613*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
614*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	"%ver"
615*f7184619SJoshua M. Clulow };
616*f7184619SJoshua M. Clulow 
617*f7184619SJoshua M. Clulow /* hyper privileged register names on v9 */
618*f7184619SJoshua M. Clulow static const char *v9_hprivreg_names[32] = {
619*f7184619SJoshua M. Clulow 	"%hpstate",	 "%htstate",	NULL,  "%hintp",
620*f7184619SJoshua M. Clulow 	NULL,	"%htba",	 "%hver",  NULL,
621*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
622*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
623*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
624*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
625*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	NULL,
626*f7184619SJoshua M. Clulow 	NULL,	NULL,	NULL,	"%hstick_cmpr"
627*f7184619SJoshua M. Clulow };
628*f7184619SJoshua M. Clulow 
629*f7184619SJoshua M. Clulow static const uint32_t v9_pr_rdmask = 0x80017fff;
630*f7184619SJoshua M. Clulow static const uint32_t v9_pr_wrmask = 0x00017fff;
631*f7184619SJoshua M. Clulow static const uint32_t v9_hpr_rdmask = 0x8000006b;
632*f7184619SJoshua M. Clulow static const uint32_t v9_hpr_wrmask = 0x8000006b;
633*f7184619SJoshua M. Clulow 
634*f7184619SJoshua M. Clulow static const char *prefetch_str[32] = {
635*f7184619SJoshua M. Clulow 	"#n_reads", "#one_read",
636*f7184619SJoshua M. Clulow 	"#n_writes", "#one_write",
637*f7184619SJoshua M. Clulow 	"#page",    NULL, NULL, NULL,
638*f7184619SJoshua M. Clulow 	NULL, NULL, NULL, NULL,
639*f7184619SJoshua M. Clulow 	NULL, NULL, NULL, NULL,
640*f7184619SJoshua M. Clulow 	NULL, "#unified", NULL, NULL,
641*f7184619SJoshua M. Clulow 	"#n_reads_strong", "#one_read_strong",
642*f7184619SJoshua M. Clulow 	"#n_writes_strong", "#one_write_strong",
643*f7184619SJoshua M. Clulow 	NULL, NULL, NULL, NULL,
644*f7184619SJoshua M. Clulow 	NULL, NULL, NULL, NULL
645*f7184619SJoshua M. Clulow };
646*f7184619SJoshua M. Clulow 
647*f7184619SJoshua M. Clulow static void prt_field(const char *, uint32_t, int);
648*f7184619SJoshua M. Clulow 
649*f7184619SJoshua M. Clulow static const char *get_regname(dis_handle_t *, int, uint32_t);
650*f7184619SJoshua M. Clulow static int32_t sign_extend(int32_t, int32_t);
651*f7184619SJoshua M. Clulow 
652*f7184619SJoshua M. Clulow static void prt_name(dis_handle_t *, const char *, int);
653*f7184619SJoshua M. Clulow 
654*f7184619SJoshua M. Clulow #define	IMM_SIGNED 0x01  /* Is immediate value signed		*/
655*f7184619SJoshua M. Clulow #define	IMM_ADDR   0x02  /* Is immediate value part of an address */
656*f7184619SJoshua M. Clulow static void prt_imm(dis_handle_t *, uint32_t, int);
657*f7184619SJoshua M. Clulow 
658*f7184619SJoshua M. Clulow static void prt_asi(dis_handle_t *, uint32_t);
659*f7184619SJoshua M. Clulow static const char *get_asi_name(uint8_t);
660*f7184619SJoshua M. Clulow static void prt_address(dis_handle_t *, uint32_t, int);
661*f7184619SJoshua M. Clulow static void prt_aluargs(dis_handle_t *, uint32_t, uint32_t);
662*f7184619SJoshua M. Clulow static void bprintf(dis_handle_t *, const char *, ...);
663*f7184619SJoshua M. Clulow 
664*f7184619SJoshua M. Clulow /*
665*f7184619SJoshua M. Clulow  * print out val (which is 'bitlen' bits long) in binary
666*f7184619SJoshua M. Clulow  */
667*f7184619SJoshua M. Clulow #if defined(DIS_STANDALONE)
668*f7184619SJoshua M. Clulow /* ARGSUSED */
669*f7184619SJoshua M. Clulow void
prt_binary(uint32_t val,int bitlen)670*f7184619SJoshua M. Clulow prt_binary(uint32_t val, int bitlen)
671*f7184619SJoshua M. Clulow {
672*f7184619SJoshua M. Clulow 
673*f7184619SJoshua M. Clulow }
674*f7184619SJoshua M. Clulow 
675*f7184619SJoshua M. Clulow #else
676*f7184619SJoshua M. Clulow 
677*f7184619SJoshua M. Clulow void
prt_binary(uint32_t val,int bitlen)678*f7184619SJoshua M. Clulow prt_binary(uint32_t val, int bitlen)
679*f7184619SJoshua M. Clulow {
680*f7184619SJoshua M. Clulow 	int i;
681*f7184619SJoshua M. Clulow 
682*f7184619SJoshua M. Clulow 	for (i = bitlen - 1; i >= 0; --i) {
683*f7184619SJoshua M. Clulow 		(void) fprintf(stderr, ((val & (1L << i)) != 0) ? "1" : "0");
684*f7184619SJoshua M. Clulow 
685*f7184619SJoshua M. Clulow 		if (i % 4 == 0 && i != 0)
686*f7184619SJoshua M. Clulow 			(void) fprintf(stderr, " ");
687*f7184619SJoshua M. Clulow 	}
688*f7184619SJoshua M. Clulow }
689*f7184619SJoshua M. Clulow #endif /* DIS_STANDALONE */
690*f7184619SJoshua M. Clulow 
691*f7184619SJoshua M. Clulow 
692*f7184619SJoshua M. Clulow /*
693*f7184619SJoshua M. Clulow  * print out a call instruction
694*f7184619SJoshua M. Clulow  * format: call address  <name>
695*f7184619SJoshua M. Clulow  */
696*f7184619SJoshua M. Clulow /* ARGSUSED1 */
697*f7184619SJoshua M. Clulow int
fmt_call(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)698*f7184619SJoshua M. Clulow fmt_call(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
699*f7184619SJoshua M. Clulow {
700*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
701*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
702*f7184619SJoshua M. Clulow 
703*f7184619SJoshua M. Clulow 	int32_t disp;
704*f7184619SJoshua M. Clulow 	size_t curlen;
705*f7184619SJoshua M. Clulow 
706*f7184619SJoshua M. Clulow 	int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
707*f7184619SJoshua M. Clulow 
708*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
709*f7184619SJoshua M. Clulow 		prt_field("op", f->f1.op, 2);
710*f7184619SJoshua M. Clulow 		prt_field("disp30", f->f1.disp30, 30);
711*f7184619SJoshua M. Clulow 	}
712*f7184619SJoshua M. Clulow 
713*f7184619SJoshua M. Clulow 	disp = sign_extend(f->f1.disp30, 30) * 4;
714*f7184619SJoshua M. Clulow 
715*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
716*f7184619SJoshua M. Clulow 
717*f7184619SJoshua M. Clulow 	bprintf(dhp, (octal != 0) ? "%s0%-11lo" : "%s0x%-10lx",
718*f7184619SJoshua M. Clulow 	    (disp < 0) ? "-" : "+",
719*f7184619SJoshua M. Clulow 	    (disp < 0) ? (-disp) : disp);
720*f7184619SJoshua M. Clulow 
721*f7184619SJoshua M. Clulow 	(void) strlcat(dhx->dhx_buf, " <", dhx->dhx_buflen);
722*f7184619SJoshua M. Clulow 
723*f7184619SJoshua M. Clulow 	curlen = strlen(dhx->dhx_buf);
724*f7184619SJoshua M. Clulow 	dhp->dh_lookup(dhp->dh_data, dhp->dh_addr + (int64_t)disp,
725*f7184619SJoshua M. Clulow 	    dhx->dhx_buf + curlen, dhx->dhx_buflen - curlen - 1, NULL,
726*f7184619SJoshua M. Clulow 	    NULL);
727*f7184619SJoshua M. Clulow 	(void) strlcat(dhx->dhx_buf, ">", dhx->dhx_buflen);
728*f7184619SJoshua M. Clulow 
729*f7184619SJoshua M. Clulow 
730*f7184619SJoshua M. Clulow 	return (0);
731*f7184619SJoshua M. Clulow }
732*f7184619SJoshua M. Clulow 
733*f7184619SJoshua M. Clulow int
fmt_sethi(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)734*f7184619SJoshua M. Clulow fmt_sethi(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
735*f7184619SJoshua M. Clulow {
736*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
737*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
738*f7184619SJoshua M. Clulow 
739*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
740*f7184619SJoshua M. Clulow 		prt_field("op", f->f2.op, 2);
741*f7184619SJoshua M. Clulow 		prt_field("op2", f->f2.op2, 3);
742*f7184619SJoshua M. Clulow 		prt_field("rd", f->f2.rd, 5);
743*f7184619SJoshua M. Clulow 		prt_field("imm22", f->f2.imm22, 22);
744*f7184619SJoshua M. Clulow 	}
745*f7184619SJoshua M. Clulow 
746*f7184619SJoshua M. Clulow 	if (idx == 0) {
747*f7184619SJoshua M. Clulow 		/* unimp / illtrap */
748*f7184619SJoshua M. Clulow 		prt_name(dhp, inp->in_data.in_def.in_name, 1);
749*f7184619SJoshua M. Clulow 		prt_imm(dhp, f->f2.imm22, 0);
750*f7184619SJoshua M. Clulow 		return (0);
751*f7184619SJoshua M. Clulow 	}
752*f7184619SJoshua M. Clulow 
753*f7184619SJoshua M. Clulow 	if (f->f2.imm22 == 0 && f->f2.rd == 0) {
754*f7184619SJoshua M. Clulow 		prt_name(dhp, "nop", 0);
755*f7184619SJoshua M. Clulow 		return (0);
756*f7184619SJoshua M. Clulow 	}
757*f7184619SJoshua M. Clulow 
758*f7184619SJoshua M. Clulow 	/* ?? Should we return -1 if rd == 0 && disp != 0 */
759*f7184619SJoshua M. Clulow 
760*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
761*f7184619SJoshua M. Clulow 
762*f7184619SJoshua M. Clulow 	bprintf(dhp,
763*f7184619SJoshua M. Clulow 	    ((dhp->dh_flags & DIS_OCTAL) != 0) ?
764*f7184619SJoshua M. Clulow 	    "%%hi(0%lo), %s" : "%%hi(0x%lx), %s",
765*f7184619SJoshua M. Clulow 	    f->f2.imm22 << 10,
766*f7184619SJoshua M. Clulow 	    reg_names[f->f2.rd]);
767*f7184619SJoshua M. Clulow 
768*f7184619SJoshua M. Clulow 	return (0);
769*f7184619SJoshua M. Clulow }
770*f7184619SJoshua M. Clulow 
771*f7184619SJoshua M. Clulow /* ARGSUSED3 */
772*f7184619SJoshua M. Clulow int
fmt_branch(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)773*f7184619SJoshua M. Clulow fmt_branch(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
774*f7184619SJoshua M. Clulow {
775*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
776*f7184619SJoshua M. Clulow 	const char *name = inp->in_data.in_def.in_name;
777*f7184619SJoshua M. Clulow 	const char *r = NULL;
778*f7184619SJoshua M. Clulow 	const char *annul = "";
779*f7184619SJoshua M. Clulow 	const char *pred  = "";
780*f7184619SJoshua M. Clulow 
781*f7184619SJoshua M. Clulow 	char buf[15];
782*f7184619SJoshua M. Clulow 
783*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
784*f7184619SJoshua M. Clulow 
785*f7184619SJoshua M. Clulow 	size_t curlen;
786*f7184619SJoshua M. Clulow 	int32_t disp;
787*f7184619SJoshua M. Clulow 	uint32_t flags = inp->in_data.in_def.in_flags;
788*f7184619SJoshua M. Clulow 	int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
789*f7184619SJoshua M. Clulow 
790*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
791*f7184619SJoshua M. Clulow 		prt_field("op", f->f2.op, 2);
792*f7184619SJoshua M. Clulow 		prt_field("op2", f->f2.op2, 3);
793*f7184619SJoshua M. Clulow 
794*f7184619SJoshua M. Clulow 		switch (FLG_DISP_VAL(flags)) {
795*f7184619SJoshua M. Clulow 		case DISP22:
796*f7184619SJoshua M. Clulow 			prt_field("cond", f->f2a.cond, 4);
797*f7184619SJoshua M. Clulow 			prt_field("a", f->f2a.a, 1);
798*f7184619SJoshua M. Clulow 			prt_field("disp22", f->f2a.disp22, 22);
799*f7184619SJoshua M. Clulow 			break;
800*f7184619SJoshua M. Clulow 
801*f7184619SJoshua M. Clulow 		case DISP19:
802*f7184619SJoshua M. Clulow 			prt_field("cond", f->f2a.cond, 4);
803*f7184619SJoshua M. Clulow 			prt_field("a", f->f2a.a, 1);
804*f7184619SJoshua M. Clulow 			prt_field("p", f->f2b.p, 1);
805*f7184619SJoshua M. Clulow 			prt_field("cc", f->f2b.cc, 2);
806*f7184619SJoshua M. Clulow 			prt_field("disp19", f->f2b.disp19, 19);
807*f7184619SJoshua M. Clulow 			break;
808*f7184619SJoshua M. Clulow 
809*f7184619SJoshua M. Clulow 		case DISP16:
810*f7184619SJoshua M. Clulow 			prt_field("bit 28", ((instr & (1L << 28)) >> 28), 1);
811*f7184619SJoshua M. Clulow 			prt_field("rcond", f->f2c.cond, 3);
812*f7184619SJoshua M. Clulow 			prt_field("p", f->f2c.p, 1);
813*f7184619SJoshua M. Clulow 			prt_field("rs1", f->f2c.rs1, 5);
814*f7184619SJoshua M. Clulow 			prt_field("d16hi", f->f2c.d16hi, 2);
815*f7184619SJoshua M. Clulow 			prt_field("d16lo", f->f2c.d16lo, 14);
816*f7184619SJoshua M. Clulow 			break;
817*f7184619SJoshua M. Clulow 		}
818*f7184619SJoshua M. Clulow 	}
819*f7184619SJoshua M. Clulow 
820*f7184619SJoshua M. Clulow 	if (f->f2b.op2 == 0x01 && idx == 0x00 && f->f2b.p == 1 &&
821*f7184619SJoshua M. Clulow 	    f->f2b.cc == 0x02 && ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) != 0)) {
822*f7184619SJoshua M. Clulow 		name = "iprefetch";
823*f7184619SJoshua M. Clulow 		flags = FLG_RS1(REG_NONE)|FLG_DISP(DISP19);
824*f7184619SJoshua M. Clulow 	}
825*f7184619SJoshua M. Clulow 
826*f7184619SJoshua M. Clulow 
827*f7184619SJoshua M. Clulow 	switch (FLG_DISP_VAL(flags)) {
828*f7184619SJoshua M. Clulow 	case DISP22:
829*f7184619SJoshua M. Clulow 		disp = sign_extend(f->f2a.disp22, 22);
830*f7184619SJoshua M. Clulow 		break;
831*f7184619SJoshua M. Clulow 
832*f7184619SJoshua M. Clulow 	case DISP19:
833*f7184619SJoshua M. Clulow 		disp = sign_extend(f->f2b.disp19, 19);
834*f7184619SJoshua M. Clulow 		break;
835*f7184619SJoshua M. Clulow 
836*f7184619SJoshua M. Clulow 	case DISP16:
837*f7184619SJoshua M. Clulow 		disp = sign_extend((f->f2c.d16hi << 14)|f->f2c.d16lo, 16);
838*f7184619SJoshua M. Clulow 		break;
839*f7184619SJoshua M. Clulow 
840*f7184619SJoshua M. Clulow 	}
841*f7184619SJoshua M. Clulow 
842*f7184619SJoshua M. Clulow 	disp *= 4;
843*f7184619SJoshua M. Clulow 
844*f7184619SJoshua M. Clulow 	if ((FLG_RS1_VAL(flags) == REG_ICC) || (FLG_RS1_VAL(flags) == REG_FCC))
845*f7184619SJoshua M. Clulow 		r = get_regname(dhp, FLG_RS1_VAL(flags), f->f2b.cc);
846*f7184619SJoshua M. Clulow 	else
847*f7184619SJoshua M. Clulow 		r = get_regname(dhp, FLG_RS1_VAL(flags), f->f2c.rs1);
848*f7184619SJoshua M. Clulow 
849*f7184619SJoshua M. Clulow 	if (r == NULL)
850*f7184619SJoshua M. Clulow 		return (-1);
851*f7184619SJoshua M. Clulow 
852*f7184619SJoshua M. Clulow 	if (f->f2a.a == 1)
853*f7184619SJoshua M. Clulow 		annul = ",a";
854*f7184619SJoshua M. Clulow 
855*f7184619SJoshua M. Clulow 	if ((flags & FLG_PRED) != 0) {
856*f7184619SJoshua M. Clulow 		if (f->f2b.p == 0) {
857*f7184619SJoshua M. Clulow 			pred = ",pn";
858*f7184619SJoshua M. Clulow 		} else {
859*f7184619SJoshua M. Clulow 			if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0)
860*f7184619SJoshua M. Clulow 				pred = ",pt";
861*f7184619SJoshua M. Clulow 		}
862*f7184619SJoshua M. Clulow 	}
863*f7184619SJoshua M. Clulow 
864*f7184619SJoshua M. Clulow 	(void) dis_snprintf(buf, sizeof (buf), "%s%s%s", name, annul, pred);
865*f7184619SJoshua M. Clulow 	prt_name(dhp, buf, 1);
866*f7184619SJoshua M. Clulow 
867*f7184619SJoshua M. Clulow 
868*f7184619SJoshua M. Clulow 	switch (FLG_DISP_VAL(flags)) {
869*f7184619SJoshua M. Clulow 	case DISP22:
870*f7184619SJoshua M. Clulow 		bprintf(dhp,
871*f7184619SJoshua M. Clulow 		    (octal != 0) ? "%s0%-11lo <" : "%s0x%-10lx <",
872*f7184619SJoshua M. Clulow 		    (disp < 0) ? "-" : "+",
873*f7184619SJoshua M. Clulow 		    (disp < 0) ? (-disp) : disp);
874*f7184619SJoshua M. Clulow 		break;
875*f7184619SJoshua M. Clulow 
876*f7184619SJoshua M. Clulow 	case DISP19:
877*f7184619SJoshua M. Clulow 		bprintf(dhp,
878*f7184619SJoshua M. Clulow 		    (octal != 0) ? "%s, %s0%-5lo <" :
879*f7184619SJoshua M. Clulow 		    "%s, %s0x%-04lx <", r,
880*f7184619SJoshua M. Clulow 		    (disp < 0) ? "-" : "+",
881*f7184619SJoshua M. Clulow 		    (disp < 0) ? (-disp) : disp);
882*f7184619SJoshua M. Clulow 		break;
883*f7184619SJoshua M. Clulow 
884*f7184619SJoshua M. Clulow 	case DISP16:
885*f7184619SJoshua M. Clulow 		bprintf(dhp,
886*f7184619SJoshua M. Clulow 		    (octal != 0) ? "%s, %s0%-6lo <" : "%s, %s0x%-5lx <",
887*f7184619SJoshua M. Clulow 		    r,
888*f7184619SJoshua M. Clulow 		    (disp < 0) ? "-" : "+",
889*f7184619SJoshua M. Clulow 		    (disp < 0) ? (-disp) : disp);
890*f7184619SJoshua M. Clulow 		break;
891*f7184619SJoshua M. Clulow 	}
892*f7184619SJoshua M. Clulow 
893*f7184619SJoshua M. Clulow 	curlen = strlen(dhx->dhx_buf);
894*f7184619SJoshua M. Clulow 	dhp->dh_lookup(dhp->dh_data, dhp->dh_addr + (int64_t)disp,
895*f7184619SJoshua M. Clulow 	    dhx->dhx_buf + curlen, dhx->dhx_buflen - curlen - 1, NULL, NULL);
896*f7184619SJoshua M. Clulow 
897*f7184619SJoshua M. Clulow 	(void) strlcat(dhx->dhx_buf, ">", dhx->dhx_buflen);
898*f7184619SJoshua M. Clulow 
899*f7184619SJoshua M. Clulow 	return (0);
900*f7184619SJoshua M. Clulow }
901*f7184619SJoshua M. Clulow 
902*f7184619SJoshua M. Clulow 
903*f7184619SJoshua M. Clulow 
904*f7184619SJoshua M. Clulow /*
905*f7184619SJoshua M. Clulow  * print out the compare and swap instructions (casa/casxa)
906*f7184619SJoshua M. Clulow  * format: casa/casxa [%rs1] imm_asi, %rs2, %rd
907*f7184619SJoshua M. Clulow  *	    casa/casxa [%rs1] %asi, %rs2, %rd
908*f7184619SJoshua M. Clulow  *
909*f7184619SJoshua M. Clulow  * If DIS_DEBUG_SYN_ALL is set, synthetic instructions are emitted
910*f7184619SJoshua M. Clulow  * when an immediate ASI value is given as follows:
911*f7184619SJoshua M. Clulow  *
912*f7184619SJoshua M. Clulow  * casa  [%rs1]#ASI_P, %rs2, %rd    -> cas   [%rs1], %rs2, %rd
913*f7184619SJoshua M. Clulow  * casa  [%rs1]#ASI_P_L, %rs2, %rd  -> casl  [%rs1], %rs2, %rd
914*f7184619SJoshua M. Clulow  * casxa [%rs1]#ASI_P, %rs2, %rd    -> casx  [%rs1], %rs2, %rd
915*f7184619SJoshua M. Clulow  * casxa [%rs1]#ASI_P_L, %rs2, %rd  -> casxl [%rs1], %rs2, %rd
916*f7184619SJoshua M. Clulow  */
917*f7184619SJoshua M. Clulow static int
fmt_cas(dis_handle_t * dhp,uint32_t instr,const char * name)918*f7184619SJoshua M. Clulow fmt_cas(dis_handle_t *dhp, uint32_t instr, const char *name)
919*f7184619SJoshua M. Clulow {
920*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
921*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
922*f7184619SJoshua M. Clulow 	const char *asistr = NULL;
923*f7184619SJoshua M. Clulow 	int noasi = 0;
924*f7184619SJoshua M. Clulow 
925*f7184619SJoshua M. Clulow 	asistr = get_asi_name(f->f3.asi);
926*f7184619SJoshua M. Clulow 
927*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT)) != 0) {
928*f7184619SJoshua M. Clulow 		if (f->f3.op3 == 0x3c && f->f3.i == 0) {
929*f7184619SJoshua M. Clulow 			if (f->f3.asi == 0x80) {
930*f7184619SJoshua M. Clulow 				noasi = 1;
931*f7184619SJoshua M. Clulow 				name = "cas";
932*f7184619SJoshua M. Clulow 			}
933*f7184619SJoshua M. Clulow 
934*f7184619SJoshua M. Clulow 			if (f->f3.asi == 0x88) {
935*f7184619SJoshua M. Clulow 				noasi = 1;
936*f7184619SJoshua M. Clulow 				name = "casl";
937*f7184619SJoshua M. Clulow 			}
938*f7184619SJoshua M. Clulow 		}
939*f7184619SJoshua M. Clulow 
940*f7184619SJoshua M. Clulow 		if (f->f3.op3 == 0x3e && f->f3.i == 0) {
941*f7184619SJoshua M. Clulow 			if (f->f3.asi == 0x80) {
942*f7184619SJoshua M. Clulow 				noasi = 1;
943*f7184619SJoshua M. Clulow 				name = "casx";
944*f7184619SJoshua M. Clulow 			}
945*f7184619SJoshua M. Clulow 
946*f7184619SJoshua M. Clulow 			if (f->f3.asi == 0x88) {
947*f7184619SJoshua M. Clulow 				noasi = 1;
948*f7184619SJoshua M. Clulow 				name = "casxl";
949*f7184619SJoshua M. Clulow 			}
950*f7184619SJoshua M. Clulow 		}
951*f7184619SJoshua M. Clulow 	}
952*f7184619SJoshua M. Clulow 
953*f7184619SJoshua M. Clulow 	prt_name(dhp, name, 1);
954*f7184619SJoshua M. Clulow 
955*f7184619SJoshua M. Clulow 	bprintf(dhp, "[%s]", reg_names[f->f3.rs1]);
956*f7184619SJoshua M. Clulow 
957*f7184619SJoshua M. Clulow 	if (noasi == 0) {
958*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
959*f7184619SJoshua M. Clulow 		prt_asi(dhp, instr);
960*f7184619SJoshua M. Clulow 	}
961*f7184619SJoshua M. Clulow 
962*f7184619SJoshua M. Clulow 	bprintf(dhp, ", %s, %s", reg_names[f->f3.rs2], reg_names[f->f3.rd]);
963*f7184619SJoshua M. Clulow 
964*f7184619SJoshua M. Clulow 	if (noasi == 0 && asistr != NULL)
965*f7184619SJoshua M. Clulow 		bprintf(dhp, "\t<%s>", asistr);
966*f7184619SJoshua M. Clulow 
967*f7184619SJoshua M. Clulow 	return (0);
968*f7184619SJoshua M. Clulow }
969*f7184619SJoshua M. Clulow 
970*f7184619SJoshua M. Clulow /*
971*f7184619SJoshua M. Clulow  * format a load/store instruction
972*f7184619SJoshua M. Clulow  * format: ldXX [%rs1 + %rs2], %rd	  load, i==0
973*f7184619SJoshua M. Clulow  *	    ldXX [%rs1 +/- nn], %rd	  load, i==1
974*f7184619SJoshua M. Clulow  *	    ldXX [%rs1 + %rs2] #XX, %rd   load w/ imm_asi, i==0
975*f7184619SJoshua M. Clulow  *	    ldXX [%rs1 +/- nn] %asi, %rd  load from asi[%asi], i==1
976*f7184619SJoshua M. Clulow  *
977*f7184619SJoshua M. Clulow  *	    stXX %rd, [%rs1 + %rs2]	  store, i==0
978*f7184619SJoshua M. Clulow  *	    stXX %rd, [%rs1 +/- nn]	  store, i==1
979*f7184619SJoshua M. Clulow  *	    stXX %rd, [%rs1 + %rs1] #XX   store to imm_asi, i==0
980*f7184619SJoshua M. Clulow  *	    stXX %rd, [%rs1 +/-nn] %asi   store to asi[%asi], i==1
981*f7184619SJoshua M. Clulow  *
982*f7184619SJoshua M. Clulow  * The register sets used for %rd are set in the instructions flags field
983*f7184619SJoshua M. Clulow  * The asi variants are used if FLG_ASI is set in the instructions flags field
984*f7184619SJoshua M. Clulow  *
985*f7184619SJoshua M. Clulow  * If DIS_DEBUG_SYNTH_ALL or DIS_DEBUG_COMPAT are set,
986*f7184619SJoshua M. Clulow  * When %rs1, %rs2 or nn are 0, they are not printed, i.e.
987*f7184619SJoshua M. Clulow  * [ %rs1 + 0x0 ], %rd -> [%rs1], %rd for example
988*f7184619SJoshua M. Clulow  *
989*f7184619SJoshua M. Clulow  * The following synthetic instructions are also implemented:
990*f7184619SJoshua M. Clulow  *
991*f7184619SJoshua M. Clulow  * stb %g0, [addr] -> clrb [addr]    DIS_DEBUG_SYNTH_ALL
992*f7184619SJoshua M. Clulow  * sth %g0, [addr] -> crlh [addr]    DIS_DEBUG_SYNTH_ALL
993*f7184619SJoshua M. Clulow  * stw %g0, [addr] -> clr  [addr]    DIS_DEBUG_SYNTH_ALL|DIS_DEBUG_COMPAT
994*f7184619SJoshua M. Clulow  * stx %g0, [addr] -> clrx [addr]    DIS_DEBUG_SYNTH_ALL
995*f7184619SJoshua M. Clulow  *
996*f7184619SJoshua M. Clulow  * If DIS_DEBUG_COMPAT is set, the following substitutions also take place
997*f7184619SJoshua M. Clulow  *	lduw -> ld
998*f7184619SJoshua M. Clulow  *	ldtw -> ld
999*f7184619SJoshua M. Clulow  *	stuw -> st
1000*f7184619SJoshua M. Clulow  *	sttw -> st
1001*f7184619SJoshua M. Clulow  */
1002*f7184619SJoshua M. Clulow int
fmt_ls(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1003*f7184619SJoshua M. Clulow fmt_ls(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1004*f7184619SJoshua M. Clulow {
1005*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1006*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1007*f7184619SJoshua M. Clulow 	const char *regstr = NULL;
1008*f7184619SJoshua M. Clulow 	const char *asistr = NULL;
1009*f7184619SJoshua M. Clulow 
1010*f7184619SJoshua M. Clulow 	const char *iname = inp->in_data.in_def.in_name;
1011*f7184619SJoshua M. Clulow 	uint32_t flags = inp->in_data.in_def.in_flags;
1012*f7184619SJoshua M. Clulow 
1013*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1014*f7184619SJoshua M. Clulow 		prt_field("op", f->f3.op, 2);
1015*f7184619SJoshua M. Clulow 		prt_field("op3", f->f3.op3, 6);
1016*f7184619SJoshua M. Clulow 		prt_field("rs1", f->f3.rs1, 5);
1017*f7184619SJoshua M. Clulow 		prt_field("i", f->f3.i, 1);
1018*f7184619SJoshua M. Clulow 		if (f->f3.i != 0) {
1019*f7184619SJoshua M. Clulow 			prt_field("simm13", f->f3a.simm13, 13);
1020*f7184619SJoshua M. Clulow 		} else {
1021*f7184619SJoshua M. Clulow 			if ((flags & FLG_ASI) != 0)
1022*f7184619SJoshua M. Clulow 				prt_field("imm_asi", f->f3.asi, 8);
1023*f7184619SJoshua M. Clulow 			prt_field("rs2", f->f3.rs2, 5);
1024*f7184619SJoshua M. Clulow 		}
1025*f7184619SJoshua M. Clulow 		prt_field("rd", f->f3.rd, 5);
1026*f7184619SJoshua M. Clulow 	}
1027*f7184619SJoshua M. Clulow 
1028*f7184619SJoshua M. Clulow 	if (idx == 0x2d || idx == 0x3d) {
1029*f7184619SJoshua M. Clulow 		/* prefetch / prefetcha */
1030*f7184619SJoshua M. Clulow 
1031*f7184619SJoshua M. Clulow 		prt_name(dhp, iname, 1);
1032*f7184619SJoshua M. Clulow 
1033*f7184619SJoshua M. Clulow 		prt_address(dhp, instr, 0);
1034*f7184619SJoshua M. Clulow 
1035*f7184619SJoshua M. Clulow 		if (idx == 0x3d) {
1036*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
1037*f7184619SJoshua M. Clulow 			prt_asi(dhp, instr);
1038*f7184619SJoshua M. Clulow 		}
1039*f7184619SJoshua M. Clulow 
1040*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1041*f7184619SJoshua M. Clulow 
1042*f7184619SJoshua M. Clulow 		/* fcn field is the same as rd */
1043*f7184619SJoshua M. Clulow 		if (prefetch_str[f->f3.rd] != NULL)
1044*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, prefetch_str[f->f3.rd],
1045*f7184619SJoshua M. Clulow 			    dhx->dhx_buflen);
1046*f7184619SJoshua M. Clulow 		else
1047*f7184619SJoshua M. Clulow 			prt_imm(dhp, f->f3.rd, 0);
1048*f7184619SJoshua M. Clulow 
1049*f7184619SJoshua M. Clulow 		if (idx == 0x3d && f->f3.i == 0) {
1050*f7184619SJoshua M. Clulow 			asistr = get_asi_name(f->f3.asi);
1051*f7184619SJoshua M. Clulow 			if (asistr != NULL)
1052*f7184619SJoshua M. Clulow 				bprintf(dhp, "\t<%s>", asistr);
1053*f7184619SJoshua M. Clulow 		}
1054*f7184619SJoshua M. Clulow 
1055*f7184619SJoshua M. Clulow 		return (0);
1056*f7184619SJoshua M. Clulow 	}
1057*f7184619SJoshua M. Clulow 
1058*f7184619SJoshua M. Clulow 	/* casa / casxa */
1059*f7184619SJoshua M. Clulow 	if (idx == 0x3c || idx == 0x3e)
1060*f7184619SJoshua M. Clulow 		return (fmt_cas(dhp, instr, iname));
1061*f7184619SJoshua M. Clulow 
1062*f7184619SJoshua M. Clulow 	/* synthetic instructions & special cases */
1063*f7184619SJoshua M. Clulow 	switch (idx) {
1064*f7184619SJoshua M. Clulow 	case 0x00:
1065*f7184619SJoshua M. Clulow 		/* ld */
1066*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1067*f7184619SJoshua M. Clulow 			iname = "lduw";
1068*f7184619SJoshua M. Clulow 		break;
1069*f7184619SJoshua M. Clulow 
1070*f7184619SJoshua M. Clulow 	case 0x03:
1071*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1072*f7184619SJoshua M. Clulow 			iname = "ldtw";
1073*f7184619SJoshua M. Clulow 		break;
1074*f7184619SJoshua M. Clulow 
1075*f7184619SJoshua M. Clulow 	case 0x04:
1076*f7184619SJoshua M. Clulow 		/* stw */
1077*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1078*f7184619SJoshua M. Clulow 			iname = "stuw";
1079*f7184619SJoshua M. Clulow 
1080*f7184619SJoshua M. Clulow 		if ((dhp->dh_flags & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1081*f7184619SJoshua M. Clulow 		    == 0)
1082*f7184619SJoshua M. Clulow 			break;
1083*f7184619SJoshua M. Clulow 
1084*f7184619SJoshua M. Clulow 		if (f->f3.rd == 0) {
1085*f7184619SJoshua M. Clulow 			iname = "clr";
1086*f7184619SJoshua M. Clulow 			flags = FLG_RD(REG_NONE);
1087*f7184619SJoshua M. Clulow 		}
1088*f7184619SJoshua M. Clulow 		break;
1089*f7184619SJoshua M. Clulow 
1090*f7184619SJoshua M. Clulow 	case 0x05:
1091*f7184619SJoshua M. Clulow 		/* stb */
1092*f7184619SJoshua M. Clulow 		if ((dhp->dh_flags & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1093*f7184619SJoshua M. Clulow 		    == 0)
1094*f7184619SJoshua M. Clulow 			break;
1095*f7184619SJoshua M. Clulow 
1096*f7184619SJoshua M. Clulow 		if (f->f3.rd == 0) {
1097*f7184619SJoshua M. Clulow 			iname = "clrb";
1098*f7184619SJoshua M. Clulow 			flags = FLG_RD(REG_NONE);
1099*f7184619SJoshua M. Clulow 		}
1100*f7184619SJoshua M. Clulow 		break;
1101*f7184619SJoshua M. Clulow 
1102*f7184619SJoshua M. Clulow 	case 0x06:
1103*f7184619SJoshua M. Clulow 		/* sth */
1104*f7184619SJoshua M. Clulow 		if ((dhp->dh_flags & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1105*f7184619SJoshua M. Clulow 		    == 0)
1106*f7184619SJoshua M. Clulow 			break;
1107*f7184619SJoshua M. Clulow 
1108*f7184619SJoshua M. Clulow 		if (f->f3.rd == 0) {
1109*f7184619SJoshua M. Clulow 			iname = "clrh";
1110*f7184619SJoshua M. Clulow 			flags = FLG_RD(REG_NONE);
1111*f7184619SJoshua M. Clulow 		}
1112*f7184619SJoshua M. Clulow 		break;
1113*f7184619SJoshua M. Clulow 
1114*f7184619SJoshua M. Clulow 	case 0x07:
1115*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
1116*f7184619SJoshua M. Clulow 			iname = "sttw";
1117*f7184619SJoshua M. Clulow 		break;
1118*f7184619SJoshua M. Clulow 
1119*f7184619SJoshua M. Clulow 	case 0x0e:
1120*f7184619SJoshua M. Clulow 		/* stx */
1121*f7184619SJoshua M. Clulow 
1122*f7184619SJoshua M. Clulow 		if ((dhp->dh_flags & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1123*f7184619SJoshua M. Clulow 		    == 0)
1124*f7184619SJoshua M. Clulow 			break;
1125*f7184619SJoshua M. Clulow 
1126*f7184619SJoshua M. Clulow 		if (f->f3.rd == 0) {
1127*f7184619SJoshua M. Clulow 			iname = "clrx";
1128*f7184619SJoshua M. Clulow 			flags = FLG_RD(REG_NONE);
1129*f7184619SJoshua M. Clulow 		}
1130*f7184619SJoshua M. Clulow 		break;
1131*f7184619SJoshua M. Clulow 
1132*f7184619SJoshua M. Clulow 	case 0x13:
1133*f7184619SJoshua M. Clulow 		/* ldtwa */
1134*f7184619SJoshua M. Clulow 		if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0) &&
1135*f7184619SJoshua M. Clulow 		    ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0))
1136*f7184619SJoshua M. Clulow 			iname = "ldtwa";
1137*f7184619SJoshua M. Clulow 		break;
1138*f7184619SJoshua M. Clulow 
1139*f7184619SJoshua M. Clulow 	case 0x17:
1140*f7184619SJoshua M. Clulow 		/* sttwa */
1141*f7184619SJoshua M. Clulow 		if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0) &&
1142*f7184619SJoshua M. Clulow 		    ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0))
1143*f7184619SJoshua M. Clulow 			iname = "sttwa";
1144*f7184619SJoshua M. Clulow 		break;
1145*f7184619SJoshua M. Clulow 
1146*f7184619SJoshua M. Clulow 	case 0x21:
1147*f7184619SJoshua M. Clulow 	case 0x25:
1148*f7184619SJoshua M. Clulow 		/*
1149*f7184619SJoshua M. Clulow 		 * on sparcv8 it merely says that rd != 1 should generate an
1150*f7184619SJoshua M. Clulow 		 * exception, on v9, it is illegal
1151*f7184619SJoshua M. Clulow 		 */
1152*f7184619SJoshua M. Clulow 		if ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) == 0)
1153*f7184619SJoshua M. Clulow 			break;
1154*f7184619SJoshua M. Clulow 
1155*f7184619SJoshua M. Clulow 		iname = (idx == 0x21) ? "ldx" : "stx";
1156*f7184619SJoshua M. Clulow 
1157*f7184619SJoshua M. Clulow 		if (f->f3.rd > 1)
1158*f7184619SJoshua M. Clulow 			return (-1);
1159*f7184619SJoshua M. Clulow 
1160*f7184619SJoshua M. Clulow 		break;
1161*f7184619SJoshua M. Clulow 
1162*f7184619SJoshua M. Clulow 	case 0x31:
1163*f7184619SJoshua M. Clulow 		/* stda */
1164*f7184619SJoshua M. Clulow 		switch (f->f3.asi) {
1165*f7184619SJoshua M. Clulow 			case 0xc0:
1166*f7184619SJoshua M. Clulow 			case 0xc1:
1167*f7184619SJoshua M. Clulow 			case 0xc8:
1168*f7184619SJoshua M. Clulow 			case 0xc9:
1169*f7184619SJoshua M. Clulow 			case 0xc2:
1170*f7184619SJoshua M. Clulow 			case 0xc3:
1171*f7184619SJoshua M. Clulow 			case 0xca:
1172*f7184619SJoshua M. Clulow 			case 0xcb:
1173*f7184619SJoshua M. Clulow 			case 0xc4:
1174*f7184619SJoshua M. Clulow 			case 0xc5:
1175*f7184619SJoshua M. Clulow 			case 0xcc:
1176*f7184619SJoshua M. Clulow 			case 0xcd:
1177*f7184619SJoshua M. Clulow 				/*
1178*f7184619SJoshua M. Clulow 				 * store partial floating point, only valid w/
1179*f7184619SJoshua M. Clulow 				 * vis
1180*f7184619SJoshua M. Clulow 				 *
1181*f7184619SJoshua M. Clulow 				 * Somewhat confusingly, it uses the same op
1182*f7184619SJoshua M. Clulow 				 * code as 'stda' -- store double to alternate
1183*f7184619SJoshua M. Clulow 				 * space.  It is distinguised by specific
1184*f7184619SJoshua M. Clulow 				 * imm_asi values (as seen above), and
1185*f7184619SJoshua M. Clulow 				 * has a slightly different output syntax
1186*f7184619SJoshua M. Clulow 				 */
1187*f7184619SJoshua M. Clulow 
1188*f7184619SJoshua M. Clulow 				if ((dhp->dh_flags & DIS_SPARC_V9_SGI) == 0)
1189*f7184619SJoshua M. Clulow 					break;
1190*f7184619SJoshua M. Clulow 				if (f->f3.i != 0)
1191*f7184619SJoshua M. Clulow 					break;
1192*f7184619SJoshua M. Clulow 				prt_name(dhp, iname, 1);
1193*f7184619SJoshua M. Clulow 				bprintf(dhp, "%s, %s, [%s] ",
1194*f7184619SJoshua M. Clulow 				    get_regname(dhp, REG_FPD, f->f3.rd),
1195*f7184619SJoshua M. Clulow 				    get_regname(dhp, REG_FPD, f->f3.rs2),
1196*f7184619SJoshua M. Clulow 				    get_regname(dhp, REG_FPD, f->f3.rs1));
1197*f7184619SJoshua M. Clulow 				prt_asi(dhp, instr);
1198*f7184619SJoshua M. Clulow 				asistr = get_asi_name(f->f3.asi);
1199*f7184619SJoshua M. Clulow 				if (asistr != NULL)
1200*f7184619SJoshua M. Clulow 					bprintf(dhp, "\t<%s>", asistr);
1201*f7184619SJoshua M. Clulow 
1202*f7184619SJoshua M. Clulow 				return (0);
1203*f7184619SJoshua M. Clulow 
1204*f7184619SJoshua M. Clulow 			default:
1205*f7184619SJoshua M. Clulow 				break;
1206*f7184619SJoshua M. Clulow 		}
1207*f7184619SJoshua M. Clulow 
1208*f7184619SJoshua M. Clulow 	}
1209*f7184619SJoshua M. Clulow 
1210*f7184619SJoshua M. Clulow 	regstr = get_regname(dhp, FLG_RD_VAL(flags), f->f3.rd);
1211*f7184619SJoshua M. Clulow 
1212*f7184619SJoshua M. Clulow 	if (f->f3.i == 0)
1213*f7184619SJoshua M. Clulow 		asistr = get_asi_name(f->f3.asi);
1214*f7184619SJoshua M. Clulow 
1215*f7184619SJoshua M. Clulow 	prt_name(dhp, iname, 1);
1216*f7184619SJoshua M. Clulow 
1217*f7184619SJoshua M. Clulow 	if ((flags & FLG_STORE) != 0) {
1218*f7184619SJoshua M. Clulow 		if (regstr[0] != '\0') {
1219*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, regstr, dhx->dhx_buflen);
1220*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1221*f7184619SJoshua M. Clulow 		}
1222*f7184619SJoshua M. Clulow 
1223*f7184619SJoshua M. Clulow 		prt_address(dhp, instr, 0);
1224*f7184619SJoshua M. Clulow 		if ((flags & FLG_ASI) != 0) {
1225*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
1226*f7184619SJoshua M. Clulow 			prt_asi(dhp, instr);
1227*f7184619SJoshua M. Clulow 		}
1228*f7184619SJoshua M. Clulow 	} else {
1229*f7184619SJoshua M. Clulow 		prt_address(dhp, instr, 0);
1230*f7184619SJoshua M. Clulow 		if ((flags & FLG_ASI) != 0) {
1231*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, " ", dhx->dhx_buflen);
1232*f7184619SJoshua M. Clulow 			prt_asi(dhp, instr);
1233*f7184619SJoshua M. Clulow 		}
1234*f7184619SJoshua M. Clulow 
1235*f7184619SJoshua M. Clulow 		if (regstr[0] != '\0') {
1236*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1237*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, regstr, dhx->dhx_buflen);
1238*f7184619SJoshua M. Clulow 		}
1239*f7184619SJoshua M. Clulow 	}
1240*f7184619SJoshua M. Clulow 
1241*f7184619SJoshua M. Clulow 	if ((flags & FLG_ASI) != 0 && asistr != NULL)
1242*f7184619SJoshua M. Clulow 		bprintf(dhp, "\t<%s>", asistr);
1243*f7184619SJoshua M. Clulow 
1244*f7184619SJoshua M. Clulow 	return (0);
1245*f7184619SJoshua M. Clulow }
1246*f7184619SJoshua M. Clulow 
1247*f7184619SJoshua M. Clulow static int
fmt_cpop(dis_handle_t * dhp,uint32_t instr,const inst_t * inp)1248*f7184619SJoshua M. Clulow fmt_cpop(dis_handle_t *dhp, uint32_t instr, const inst_t *inp)
1249*f7184619SJoshua M. Clulow {
1250*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1251*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1252*f7184619SJoshua M. Clulow 	int flags = FLG_P1(REG_CP)|FLG_P2(REG_CP)|FLG_NOIMM|FLG_P3(REG_CP);
1253*f7184619SJoshua M. Clulow 
1254*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1255*f7184619SJoshua M. Clulow 		prt_field("op", f->fcp.op, 2);
1256*f7184619SJoshua M. Clulow 		prt_field("op3", f->fcp.op3, 6);
1257*f7184619SJoshua M. Clulow 		prt_field("opc", f->fcp.opc, 9);
1258*f7184619SJoshua M. Clulow 		prt_field("rs1", f->fcp.rs1, 5);
1259*f7184619SJoshua M. Clulow 		prt_field("rs2", f->fcp.rs2, 5);
1260*f7184619SJoshua M. Clulow 		prt_field("rd", f->fcp.rd, 5);
1261*f7184619SJoshua M. Clulow 	}
1262*f7184619SJoshua M. Clulow 
1263*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
1264*f7184619SJoshua M. Clulow 	prt_imm(dhp, f->fcp.opc, 0);
1265*f7184619SJoshua M. Clulow 
1266*f7184619SJoshua M. Clulow 	(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1267*f7184619SJoshua M. Clulow 	(void) prt_aluargs(dhp, instr, flags);
1268*f7184619SJoshua M. Clulow 
1269*f7184619SJoshua M. Clulow 	return (0);
1270*f7184619SJoshua M. Clulow }
1271*f7184619SJoshua M. Clulow 
1272*f7184619SJoshua M. Clulow static int
dis_fmt_rdwr(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1273*f7184619SJoshua M. Clulow dis_fmt_rdwr(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1274*f7184619SJoshua M. Clulow {
1275*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1276*f7184619SJoshua M. Clulow 	const char *psr_str = "%psr";
1277*f7184619SJoshua M. Clulow 	const char *wim_str = "%wim";
1278*f7184619SJoshua M. Clulow 	const char *tbr_str = "%tbr";
1279*f7184619SJoshua M. Clulow 
1280*f7184619SJoshua M. Clulow 	const char *name = inp->in_data.in_def.in_name;
1281*f7184619SJoshua M. Clulow 	const char *regstr = NULL;
1282*f7184619SJoshua M. Clulow 
1283*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1284*f7184619SJoshua M. Clulow 
1285*f7184619SJoshua M. Clulow 	int rd = (idx < 0x30);
1286*f7184619SJoshua M. Clulow 	int v9 = (dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI));
1287*f7184619SJoshua M. Clulow 	int ridx = f->f3.rs1;
1288*f7184619SJoshua M. Clulow 	int i, first;
1289*f7184619SJoshua M. Clulow 	int pr_rs1 = 1;
1290*f7184619SJoshua M. Clulow 	int pr_rs2 = 1;
1291*f7184619SJoshua M. Clulow 
1292*f7184619SJoshua M. Clulow 	int use_mask = 1;
1293*f7184619SJoshua M. Clulow 	uint32_t mask;
1294*f7184619SJoshua M. Clulow 
1295*f7184619SJoshua M. Clulow 	if (rd == 0)
1296*f7184619SJoshua M. Clulow 		ridx = f->f3.rd;
1297*f7184619SJoshua M. Clulow 
1298*f7184619SJoshua M. Clulow 	switch (idx) {
1299*f7184619SJoshua M. Clulow 	case 0x28:
1300*f7184619SJoshua M. Clulow 		/* rd */
1301*f7184619SJoshua M. Clulow 
1302*f7184619SJoshua M. Clulow 		/* stbar */
1303*f7184619SJoshua M. Clulow 		if ((f->f3.rd == 0) && (f->f3.rs1 == 15) && (f->f3.i == 0)) {
1304*f7184619SJoshua M. Clulow 			prt_name(dhp, "stbar", 0);
1305*f7184619SJoshua M. Clulow 			return (0);
1306*f7184619SJoshua M. Clulow 		}
1307*f7184619SJoshua M. Clulow 
1308*f7184619SJoshua M. Clulow 		/* membar */
1309*f7184619SJoshua M. Clulow 		if ((v9 != 0) && (f->f3.rd == 0) && (f->f3.rs1 == 15) &&
1310*f7184619SJoshua M. Clulow 		    (f->f3.i == 1) && ((f->i & (1L << 12)) == 0)) {
1311*f7184619SJoshua M. Clulow 
1312*f7184619SJoshua M. Clulow 			prt_name(dhp, "membar",
1313*f7184619SJoshua M. Clulow 			    ((f->fmb.cmask != 0) || (f->fmb.mmask != 0)));
1314*f7184619SJoshua M. Clulow 
1315*f7184619SJoshua M. Clulow 			first = 0;
1316*f7184619SJoshua M. Clulow 
1317*f7184619SJoshua M. Clulow 			for (i = 0; i < 4; ++i) {
1318*f7184619SJoshua M. Clulow 				if ((f->fmb.cmask & (1L << i)) != 0) {
1319*f7184619SJoshua M. Clulow 					bprintf(dhp, "%s%s",
1320*f7184619SJoshua M. Clulow 					    (first != 0) ? "|" : "",
1321*f7184619SJoshua M. Clulow 					    membar_cmask[i]);
1322*f7184619SJoshua M. Clulow 					first = 1;
1323*f7184619SJoshua M. Clulow 				}
1324*f7184619SJoshua M. Clulow 			}
1325*f7184619SJoshua M. Clulow 
1326*f7184619SJoshua M. Clulow 			for (i = 0; i < 5; ++i) {
1327*f7184619SJoshua M. Clulow 				if ((f->fmb.mmask & (1L << i)) != 0) {
1328*f7184619SJoshua M. Clulow 					bprintf(dhp, "%s%s",
1329*f7184619SJoshua M. Clulow 					    (first != 0) ? "|" : "",
1330*f7184619SJoshua M. Clulow 					    membar_mmask[i]);
1331*f7184619SJoshua M. Clulow 					first = 1;
1332*f7184619SJoshua M. Clulow 				}
1333*f7184619SJoshua M. Clulow 			}
1334*f7184619SJoshua M. Clulow 
1335*f7184619SJoshua M. Clulow 			return (0);
1336*f7184619SJoshua M. Clulow 		}
1337*f7184619SJoshua M. Clulow 
1338*f7184619SJoshua M. Clulow 		if (v9 != 0) {
1339*f7184619SJoshua M. Clulow 			regstr = v9_asr_names[ridx];
1340*f7184619SJoshua M. Clulow 			mask = v9_asr_rdmask;
1341*f7184619SJoshua M. Clulow 		} else {
1342*f7184619SJoshua M. Clulow 			regstr = asr_names[ridx];
1343*f7184619SJoshua M. Clulow 			mask = asr_rdmask;
1344*f7184619SJoshua M. Clulow 		}
1345*f7184619SJoshua M. Clulow 		break;
1346*f7184619SJoshua M. Clulow 
1347*f7184619SJoshua M. Clulow 	case 0x29:
1348*f7184619SJoshua M. Clulow 		if (v9 != 0) {
1349*f7184619SJoshua M. Clulow 			regstr = v9_hprivreg_names[ridx];
1350*f7184619SJoshua M. Clulow 			mask = v9_hpr_rdmask;
1351*f7184619SJoshua M. Clulow 		} else {
1352*f7184619SJoshua M. Clulow 			regstr = psr_str;
1353*f7184619SJoshua M. Clulow 			use_mask = 0;
1354*f7184619SJoshua M. Clulow 		}
1355*f7184619SJoshua M. Clulow 		break;
1356*f7184619SJoshua M. Clulow 
1357*f7184619SJoshua M. Clulow 	case 0x2a:
1358*f7184619SJoshua M. Clulow 		if (v9 != 0) {
1359*f7184619SJoshua M. Clulow 			regstr = v9_privreg_names[ridx];
1360*f7184619SJoshua M. Clulow 			mask = v9_pr_rdmask;
1361*f7184619SJoshua M. Clulow 		} else {
1362*f7184619SJoshua M. Clulow 			regstr = wim_str;
1363*f7184619SJoshua M. Clulow 			use_mask = 0;
1364*f7184619SJoshua M. Clulow 		}
1365*f7184619SJoshua M. Clulow 		break;
1366*f7184619SJoshua M. Clulow 
1367*f7184619SJoshua M. Clulow 	case 0x2b:
1368*f7184619SJoshua M. Clulow 		if (v9 != 0) {
1369*f7184619SJoshua M. Clulow 			/* flushw */
1370*f7184619SJoshua M. Clulow 			prt_name(dhp, name, 0);
1371*f7184619SJoshua M. Clulow 			return (0);
1372*f7184619SJoshua M. Clulow 		}
1373*f7184619SJoshua M. Clulow 
1374*f7184619SJoshua M. Clulow 		regstr = tbr_str;
1375*f7184619SJoshua M. Clulow 		use_mask = 0;
1376*f7184619SJoshua M. Clulow 		break;
1377*f7184619SJoshua M. Clulow 
1378*f7184619SJoshua M. Clulow 	case 0x30:
1379*f7184619SJoshua M. Clulow 		if (v9 != 0) {
1380*f7184619SJoshua M. Clulow 			regstr = v9_asr_names[ridx];
1381*f7184619SJoshua M. Clulow 			mask = v9_asr_wrmask;
1382*f7184619SJoshua M. Clulow 		} else {
1383*f7184619SJoshua M. Clulow 			regstr = asr_names[ridx];
1384*f7184619SJoshua M. Clulow 			mask = asr_wrmask;
1385*f7184619SJoshua M. Clulow 		}
1386*f7184619SJoshua M. Clulow 
1387*f7184619SJoshua M. Clulow 		/*
1388*f7184619SJoshua M. Clulow 		 * sir is shoehorned in here, per Ultrasparc 2007
1389*f7184619SJoshua M. Clulow 		 * hyperprivileged edition, section 7.88, all of
1390*f7184619SJoshua M. Clulow 		 * these must be true to distinguish from WRasr
1391*f7184619SJoshua M. Clulow 		 */
1392*f7184619SJoshua M. Clulow 		if (v9 != 0 && f->f3.rd == 15 && f->f3.rs1 == 0 &&
1393*f7184619SJoshua M. Clulow 		    f->f3.i == 1) {
1394*f7184619SJoshua M. Clulow 			prt_name(dhp, "sir", 1);
1395*f7184619SJoshua M. Clulow 			prt_imm(dhp, sign_extend(f->f3a.simm13, 13),
1396*f7184619SJoshua M. Clulow 			    IMM_SIGNED);
1397*f7184619SJoshua M. Clulow 			return (0);
1398*f7184619SJoshua M. Clulow 		}
1399*f7184619SJoshua M. Clulow 
1400*f7184619SJoshua M. Clulow 		/* synth: mov */
1401*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1402*f7184619SJoshua M. Clulow 		    == 0)
1403*f7184619SJoshua M. Clulow 			break;
1404*f7184619SJoshua M. Clulow 
1405*f7184619SJoshua M. Clulow 		if (v9 == 0) {
1406*f7184619SJoshua M. Clulow 			if (f->f3.rs1 == 0) {
1407*f7184619SJoshua M. Clulow 				name = "mov";
1408*f7184619SJoshua M. Clulow 				pr_rs1 = 0;
1409*f7184619SJoshua M. Clulow 			}
1410*f7184619SJoshua M. Clulow 
1411*f7184619SJoshua M. Clulow 			if ((f->f3.i == 0 && f->f3.rs2 == 0) ||
1412*f7184619SJoshua M. Clulow 			    (f->f3.i == 1 && f->f3a.simm13 == 0)) {
1413*f7184619SJoshua M. Clulow 				name = "mov";
1414*f7184619SJoshua M. Clulow 				pr_rs2 = 0;
1415*f7184619SJoshua M. Clulow 			}
1416*f7184619SJoshua M. Clulow 		}
1417*f7184619SJoshua M. Clulow 
1418*f7184619SJoshua M. Clulow 		if (pr_rs1 == 0)
1419*f7184619SJoshua M. Clulow 			pr_rs2 = 1;
1420*f7184619SJoshua M. Clulow 
1421*f7184619SJoshua M. Clulow 		break;
1422*f7184619SJoshua M. Clulow 
1423*f7184619SJoshua M. Clulow 	case 0x31:
1424*f7184619SJoshua M. Clulow 		/*
1425*f7184619SJoshua M. Clulow 		 * NOTE: due to the presence of an overlay entry for another
1426*f7184619SJoshua M. Clulow 		 * table, this case only happens when doing v8 instructions
1427*f7184619SJoshua M. Clulow 		 * only
1428*f7184619SJoshua M. Clulow 		 */
1429*f7184619SJoshua M. Clulow 		regstr = psr_str;
1430*f7184619SJoshua M. Clulow 		use_mask = 0;
1431*f7184619SJoshua M. Clulow 		break;
1432*f7184619SJoshua M. Clulow 
1433*f7184619SJoshua M. Clulow 	case 0x32:
1434*f7184619SJoshua M. Clulow 		if (v9 != 0) {
1435*f7184619SJoshua M. Clulow 			regstr = v9_privreg_names[ridx];
1436*f7184619SJoshua M. Clulow 			mask = v9_pr_wrmask;
1437*f7184619SJoshua M. Clulow 		} else {
1438*f7184619SJoshua M. Clulow 			regstr = wim_str;
1439*f7184619SJoshua M. Clulow 			use_mask = 0;
1440*f7184619SJoshua M. Clulow 		}
1441*f7184619SJoshua M. Clulow 		break;
1442*f7184619SJoshua M. Clulow 
1443*f7184619SJoshua M. Clulow 	case 0x33:
1444*f7184619SJoshua M. Clulow 		if (v9 != 0) {
1445*f7184619SJoshua M. Clulow 			regstr = v9_hprivreg_names[ridx];
1446*f7184619SJoshua M. Clulow 			mask = v9_hpr_wrmask;
1447*f7184619SJoshua M. Clulow 		} else {
1448*f7184619SJoshua M. Clulow 			regstr = tbr_str;
1449*f7184619SJoshua M. Clulow 			use_mask = 0;
1450*f7184619SJoshua M. Clulow 		}
1451*f7184619SJoshua M. Clulow 		break;
1452*f7184619SJoshua M. Clulow 	}
1453*f7184619SJoshua M. Clulow 
1454*f7184619SJoshua M. Clulow 	if (regstr == NULL)
1455*f7184619SJoshua M. Clulow 		return (-1);
1456*f7184619SJoshua M. Clulow 
1457*f7184619SJoshua M. Clulow 	if (use_mask != 0 && ((1L << ridx) & mask) == 0)
1458*f7184619SJoshua M. Clulow 		return (-1);
1459*f7184619SJoshua M. Clulow 
1460*f7184619SJoshua M. Clulow 	prt_name(dhp, name, 1);
1461*f7184619SJoshua M. Clulow 
1462*f7184619SJoshua M. Clulow 	if (rd != 0) {
1463*f7184619SJoshua M. Clulow 		bprintf(dhp, "%s, %s", regstr, reg_names[f->f3.rd]);
1464*f7184619SJoshua M. Clulow 	} else {
1465*f7184619SJoshua M. Clulow 		if (pr_rs1 == 1)
1466*f7184619SJoshua M. Clulow 			bprintf(dhp, "%s, ", reg_names[f->f3.rs1]);
1467*f7184619SJoshua M. Clulow 
1468*f7184619SJoshua M. Clulow 		if (pr_rs2 != 0) {
1469*f7184619SJoshua M. Clulow 			if (f->f3.i == 1)
1470*f7184619SJoshua M. Clulow 				prt_imm(dhp, sign_extend(f->f3a.simm13, 13),
1471*f7184619SJoshua M. Clulow 				    IMM_SIGNED);
1472*f7184619SJoshua M. Clulow 			else
1473*f7184619SJoshua M. Clulow 				(void) strlcat(dhx->dhx_buf,
1474*f7184619SJoshua M. Clulow 				    reg_names[f->f3.rs2], dhx->dhx_buflen);
1475*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
1476*f7184619SJoshua M. Clulow 		}
1477*f7184619SJoshua M. Clulow 
1478*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, regstr, dhx->dhx_buflen);
1479*f7184619SJoshua M. Clulow 	}
1480*f7184619SJoshua M. Clulow 
1481*f7184619SJoshua M. Clulow 	return (0);
1482*f7184619SJoshua M. Clulow }
1483*f7184619SJoshua M. Clulow 
1484*f7184619SJoshua M. Clulow /* ARGSUSED3 */
1485*f7184619SJoshua M. Clulow int
fmt_trap(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1486*f7184619SJoshua M. Clulow fmt_trap(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1487*f7184619SJoshua M. Clulow {
1488*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1489*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1490*f7184619SJoshua M. Clulow 
1491*f7184619SJoshua M. Clulow 	int v9 = ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0);
1492*f7184619SJoshua M. Clulow 	int p_rs1, p_t;
1493*f7184619SJoshua M. Clulow 
1494*f7184619SJoshua M. Clulow 	if (f->ftcc.undef != 0)
1495*f7184619SJoshua M. Clulow 		return (-1);
1496*f7184619SJoshua M. Clulow 
1497*f7184619SJoshua M. Clulow 	if (icc_names[f->ftcc.cc] == NULL)
1498*f7184619SJoshua M. Clulow 		return (-1);
1499*f7184619SJoshua M. Clulow 
1500*f7184619SJoshua M. Clulow 	if (f->ftcc.i == 1 && f->ftcc.undef2 != 0)
1501*f7184619SJoshua M. Clulow 		return (-1);
1502*f7184619SJoshua M. Clulow 
1503*f7184619SJoshua M. Clulow 	if (f->ftcc2.i == 0 && f->ftcc2.undef2 != 0)
1504*f7184619SJoshua M. Clulow 		return (-1);
1505*f7184619SJoshua M. Clulow 
1506*f7184619SJoshua M. Clulow 	p_rs1 = ((f->ftcc.rs1 != 0) ||
1507*f7184619SJoshua M. Clulow 	    ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0));
1508*f7184619SJoshua M. Clulow 
1509*f7184619SJoshua M. Clulow 	if (f->ftcc.i == 0) {
1510*f7184619SJoshua M. Clulow 		p_t = (f->f3.rs2 != 0 || p_rs1 == 0);
1511*f7184619SJoshua M. Clulow 
1512*f7184619SJoshua M. Clulow 		bprintf(dhp, "%-9s %s%s%s%s%s", inp->in_data.in_def.in_name,
1513*f7184619SJoshua M. Clulow 		    (v9 != 0) ? icc_names[f->ftcc2.cc] : "",
1514*f7184619SJoshua M. Clulow 		    (v9 != 0) ? ", " : "",
1515*f7184619SJoshua M. Clulow 		    (p_rs1 != 0) ? reg_names[f->ftcc2.rs1] : "",
1516*f7184619SJoshua M. Clulow 		    (p_rs1 != 0) ? " + " : "",
1517*f7184619SJoshua M. Clulow 		    (p_t != 0) ? reg_names[f->f3.rs2] : "");
1518*f7184619SJoshua M. Clulow 	} else {
1519*f7184619SJoshua M. Clulow 		bprintf(dhp, "%-9s %s%s%s%s0x%x", inp->in_data.in_def.in_name,
1520*f7184619SJoshua M. Clulow 		    (v9 != 0) ? icc_names[f->ftcc2.cc] : "",
1521*f7184619SJoshua M. Clulow 		    (v9 != 0) ? ", " : "",
1522*f7184619SJoshua M. Clulow 		    (p_rs1 != 0) ? reg_names[f->ftcc2.rs1] : "",
1523*f7184619SJoshua M. Clulow 		    (p_rs1 != 0) ? " + " : "",
1524*f7184619SJoshua M. Clulow 		    f->ftcc.immtrap);
1525*f7184619SJoshua M. Clulow 	}
1526*f7184619SJoshua M. Clulow 	return (0);
1527*f7184619SJoshua M. Clulow }
1528*f7184619SJoshua M. Clulow 
1529*f7184619SJoshua M. Clulow static int
prt_shift(dis_handle_t * dhp,uint32_t instr,const inst_t * inp)1530*f7184619SJoshua M. Clulow prt_shift(dis_handle_t *dhp, uint32_t instr, const inst_t *inp)
1531*f7184619SJoshua M. Clulow {
1532*f7184619SJoshua M. Clulow 	char name[5];
1533*f7184619SJoshua M. Clulow 	uint32_t cnt;
1534*f7184619SJoshua M. Clulow 
1535*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1536*f7184619SJoshua M. Clulow 	int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
1537*f7184619SJoshua M. Clulow 
1538*f7184619SJoshua M. Clulow 	name[0] = '\0';
1539*f7184619SJoshua M. Clulow 	(void) strlcat(name, inp->in_data.in_def.in_name, sizeof (name));
1540*f7184619SJoshua M. Clulow 
1541*f7184619SJoshua M. Clulow 	if (f->f3b.i == 1)
1542*f7184619SJoshua M. Clulow 		cnt = f->f3.rs2;
1543*f7184619SJoshua M. Clulow 
1544*f7184619SJoshua M. Clulow 	if (f->f3b.x == 1 && ((dhp->dh_flags & DIS_SPARC_V8) == 0)) {
1545*f7184619SJoshua M. Clulow 		cnt = f->f3b.shcnt;
1546*f7184619SJoshua M. Clulow 		(void) strlcat(name, "x", sizeof (name));
1547*f7184619SJoshua M. Clulow 	}
1548*f7184619SJoshua M. Clulow 
1549*f7184619SJoshua M. Clulow 	prt_name(dhp, name, 1);
1550*f7184619SJoshua M. Clulow 
1551*f7184619SJoshua M. Clulow 	if (f->f3b.i == 1)
1552*f7184619SJoshua M. Clulow 		bprintf(dhp, (octal != 0) ? "%s, 0%lo, %s" : "%s, 0x%lx, %s",
1553*f7184619SJoshua M. Clulow 		    reg_names[f->f3.rs1], cnt, reg_names[f->f3.rd]);
1554*f7184619SJoshua M. Clulow 	else
1555*f7184619SJoshua M. Clulow 		bprintf(dhp, "%s, %s, %s", reg_names[f->f3.rs1],
1556*f7184619SJoshua M. Clulow 		    reg_names[f->f3.rs2], reg_names[f->f3.rd]);
1557*f7184619SJoshua M. Clulow 
1558*f7184619SJoshua M. Clulow 	return (0);
1559*f7184619SJoshua M. Clulow }
1560*f7184619SJoshua M. Clulow 
1561*f7184619SJoshua M. Clulow /* ARGSUSED3 */
1562*f7184619SJoshua M. Clulow static int
prt_jmpl(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1563*f7184619SJoshua M. Clulow prt_jmpl(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1564*f7184619SJoshua M. Clulow {
1565*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1566*f7184619SJoshua M. Clulow 	const char *name = inp->in_data.in_def.in_name;
1567*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1568*f7184619SJoshua M. Clulow 
1569*f7184619SJoshua M. Clulow 	if (f->f3.rd == 15 && ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0))
1570*f7184619SJoshua M. Clulow 		name = "call";
1571*f7184619SJoshua M. Clulow 
1572*f7184619SJoshua M. Clulow 	if (f->f3.rd == 0) {
1573*f7184619SJoshua M. Clulow 		if (f->f3.i == 1 && f->f3a.simm13 == 8) {
1574*f7184619SJoshua M. Clulow 			if (f->f3.rs1 == 15) {
1575*f7184619SJoshua M. Clulow 				prt_name(dhp, "retl", 0);
1576*f7184619SJoshua M. Clulow 				return (0);
1577*f7184619SJoshua M. Clulow 			}
1578*f7184619SJoshua M. Clulow 
1579*f7184619SJoshua M. Clulow 			if (f->f3.rs1 == 31) {
1580*f7184619SJoshua M. Clulow 				prt_name(dhp, "ret", 0);
1581*f7184619SJoshua M. Clulow 				return (0);
1582*f7184619SJoshua M. Clulow 			}
1583*f7184619SJoshua M. Clulow 		}
1584*f7184619SJoshua M. Clulow 
1585*f7184619SJoshua M. Clulow 		name = "jmp";
1586*f7184619SJoshua M. Clulow 	}
1587*f7184619SJoshua M. Clulow 
1588*f7184619SJoshua M. Clulow 	prt_name(dhp, name, 1);
1589*f7184619SJoshua M. Clulow 	prt_address(dhp, instr, 1);
1590*f7184619SJoshua M. Clulow 
1591*f7184619SJoshua M. Clulow 	if (f->f3.rd == 0)
1592*f7184619SJoshua M. Clulow 		return (0);
1593*f7184619SJoshua M. Clulow 
1594*f7184619SJoshua M. Clulow 	if (f->f3.rd == 15 && ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0))
1595*f7184619SJoshua M. Clulow 		return (0);
1596*f7184619SJoshua M. Clulow 
1597*f7184619SJoshua M. Clulow 	bprintf(dhp, ", %s", reg_names[f->f3.rd]);
1598*f7184619SJoshua M. Clulow 
1599*f7184619SJoshua M. Clulow 	return (0);
1600*f7184619SJoshua M. Clulow }
1601*f7184619SJoshua M. Clulow 
1602*f7184619SJoshua M. Clulow int
fmt_alu(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1603*f7184619SJoshua M. Clulow fmt_alu(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1604*f7184619SJoshua M. Clulow {
1605*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1606*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1607*f7184619SJoshua M. Clulow 
1608*f7184619SJoshua M. Clulow 	const char *name = inp->in_data.in_def.in_name;
1609*f7184619SJoshua M. Clulow 	int flags = inp->in_data.in_def.in_flags;
1610*f7184619SJoshua M. Clulow 	int arg = 0;
1611*f7184619SJoshua M. Clulow 
1612*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1613*f7184619SJoshua M. Clulow 		prt_field("op", f->f3.op, 2);
1614*f7184619SJoshua M. Clulow 		prt_field("op3", f->f3.op3, 6);
1615*f7184619SJoshua M. Clulow 		prt_field("rs1", f->f3.rs1, 5);
1616*f7184619SJoshua M. Clulow 
1617*f7184619SJoshua M. Clulow 		switch (idx) {
1618*f7184619SJoshua M. Clulow 			/* TODO: more formats */
1619*f7184619SJoshua M. Clulow 
1620*f7184619SJoshua M. Clulow 		default:
1621*f7184619SJoshua M. Clulow 			if (f->f3.i == 0)
1622*f7184619SJoshua M. Clulow 				prt_field("rs2", f->f3.rs2, 5);
1623*f7184619SJoshua M. Clulow 			else
1624*f7184619SJoshua M. Clulow 				prt_field("simm13", f->f3a.simm13, 13);
1625*f7184619SJoshua M. Clulow 
1626*f7184619SJoshua M. Clulow 			prt_field("rd", f->f3.rd, 5);
1627*f7184619SJoshua M. Clulow 		}
1628*f7184619SJoshua M. Clulow 
1629*f7184619SJoshua M. Clulow 	}
1630*f7184619SJoshua M. Clulow 
1631*f7184619SJoshua M. Clulow 	switch (idx) {
1632*f7184619SJoshua M. Clulow 	case 0x00:
1633*f7184619SJoshua M. Clulow 		/* add */
1634*f7184619SJoshua M. Clulow 
1635*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) == 0)
1636*f7184619SJoshua M. Clulow 			break;
1637*f7184619SJoshua M. Clulow 
1638*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1639*f7184619SJoshua M. Clulow 		    f->f3a.simm13 == 1) {
1640*f7184619SJoshua M. Clulow 			name = "inc";
1641*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1642*f7184619SJoshua M. Clulow 			break;
1643*f7184619SJoshua M. Clulow 		}
1644*f7184619SJoshua M. Clulow 
1645*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1646*f7184619SJoshua M. Clulow 		    f->f3a.simm13 != 1) {
1647*f7184619SJoshua M. Clulow 			name = "inc";
1648*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE);
1649*f7184619SJoshua M. Clulow 			break;
1650*f7184619SJoshua M. Clulow 		}
1651*f7184619SJoshua M. Clulow 		break;
1652*f7184619SJoshua M. Clulow 
1653*f7184619SJoshua M. Clulow 	case 0x02:
1654*f7184619SJoshua M. Clulow 		/* or */
1655*f7184619SJoshua M. Clulow 
1656*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1657*f7184619SJoshua M. Clulow 		    == 0)
1658*f7184619SJoshua M. Clulow 			break;
1659*f7184619SJoshua M. Clulow 
1660*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) != 0) {
1661*f7184619SJoshua M. Clulow 			if (f->f3.rs1 == f->f3.rd) {
1662*f7184619SJoshua M. Clulow 				name = "bset";
1663*f7184619SJoshua M. Clulow 				flags = FLG_P1(REG_NONE);
1664*f7184619SJoshua M. Clulow 				break;
1665*f7184619SJoshua M. Clulow 			}
1666*f7184619SJoshua M. Clulow 		}
1667*f7184619SJoshua M. Clulow 
1668*f7184619SJoshua M. Clulow 		if (((f->f3.i == 0 && f->f3.rs2 == 0) ||
1669*f7184619SJoshua M. Clulow 		    (f->f3.i == 1 && f->f3a.simm13 == 0)) &&
1670*f7184619SJoshua M. Clulow 		    (f->f3.rs1 == 0)) {
1671*f7184619SJoshua M. Clulow 			name = "clr";
1672*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1673*f7184619SJoshua M. Clulow 			break;
1674*f7184619SJoshua M. Clulow 		}
1675*f7184619SJoshua M. Clulow 
1676*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == 0) {
1677*f7184619SJoshua M. Clulow 			name = "mov";
1678*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE);
1679*f7184619SJoshua M. Clulow 			break;
1680*f7184619SJoshua M. Clulow 		}
1681*f7184619SJoshua M. Clulow 		break;
1682*f7184619SJoshua M. Clulow 
1683*f7184619SJoshua M. Clulow 	case 0x04:
1684*f7184619SJoshua M. Clulow 		/* sub */
1685*f7184619SJoshua M. Clulow 
1686*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1687*f7184619SJoshua M. Clulow 		    == 0)
1688*f7184619SJoshua M. Clulow 			break;
1689*f7184619SJoshua M. Clulow 
1690*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == 0 && f->f3.i == 0 && f->f3.rs2 == f->f3.rd) {
1691*f7184619SJoshua M. Clulow 			name = "neg";
1692*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE);
1693*f7184619SJoshua M. Clulow 			break;
1694*f7184619SJoshua M. Clulow 		}
1695*f7184619SJoshua M. Clulow 
1696*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == 0 && f->f3.i == 0 && f->f3.rs2 != f->f3.rd) {
1697*f7184619SJoshua M. Clulow 			name = "neg";
1698*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE);
1699*f7184619SJoshua M. Clulow 			break;
1700*f7184619SJoshua M. Clulow 		}
1701*f7184619SJoshua M. Clulow 
1702*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) == 0)
1703*f7184619SJoshua M. Clulow 			break;
1704*f7184619SJoshua M. Clulow 
1705*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1706*f7184619SJoshua M. Clulow 		    f->f3a.simm13 == 1) {
1707*f7184619SJoshua M. Clulow 			name = "dec";
1708*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1709*f7184619SJoshua M. Clulow 			break;
1710*f7184619SJoshua M. Clulow 		}
1711*f7184619SJoshua M. Clulow 
1712*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1713*f7184619SJoshua M. Clulow 		    f->f3a.simm13 != 1) {
1714*f7184619SJoshua M. Clulow 			name = "dec";
1715*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE);
1716*f7184619SJoshua M. Clulow 			break;
1717*f7184619SJoshua M. Clulow 		}
1718*f7184619SJoshua M. Clulow 		break;
1719*f7184619SJoshua M. Clulow 
1720*f7184619SJoshua M. Clulow 	case 0x07:
1721*f7184619SJoshua M. Clulow 		/* xnor */
1722*f7184619SJoshua M. Clulow 
1723*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1724*f7184619SJoshua M. Clulow 		    == 0)
1725*f7184619SJoshua M. Clulow 			break;
1726*f7184619SJoshua M. Clulow 
1727*f7184619SJoshua M. Clulow 		/*
1728*f7184619SJoshua M. Clulow 		 * xnor -> not when you have:
1729*f7184619SJoshua M. Clulow 		 *	 xnor %rs1, 0x0 or %g0, %rd
1730*f7184619SJoshua M. Clulow 		 */
1731*f7184619SJoshua M. Clulow 		if ((f->f3.i == 0 && f->f3.rs2 != 0) ||
1732*f7184619SJoshua M. Clulow 		    (f->f3.i == 1 && f->f3a.simm13 != 0))
1733*f7184619SJoshua M. Clulow 			break;
1734*f7184619SJoshua M. Clulow 
1735*f7184619SJoshua M. Clulow 		name = "not";
1736*f7184619SJoshua M. Clulow 
1737*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd)
1738*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM|
1739*f7184619SJoshua M. Clulow 			    FLG_P3(REG_INT);
1740*f7184619SJoshua M. Clulow 		else
1741*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_INT)|FLG_P2(REG_NONE)|FLG_NOIMM|
1742*f7184619SJoshua M. Clulow 			    FLG_P3(REG_INT);
1743*f7184619SJoshua M. Clulow 
1744*f7184619SJoshua M. Clulow 		break;
1745*f7184619SJoshua M. Clulow 
1746*f7184619SJoshua M. Clulow 	case 0x10:
1747*f7184619SJoshua M. Clulow 		/* addcc */
1748*f7184619SJoshua M. Clulow 
1749*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_SYN_ALL) == 0)
1750*f7184619SJoshua M. Clulow 			break;
1751*f7184619SJoshua M. Clulow 
1752*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1753*f7184619SJoshua M. Clulow 		    f->f3a.simm13 == 1) {
1754*f7184619SJoshua M. Clulow 			name = "inccc";
1755*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1756*f7184619SJoshua M. Clulow 			break;
1757*f7184619SJoshua M. Clulow 		}
1758*f7184619SJoshua M. Clulow 
1759*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1760*f7184619SJoshua M. Clulow 		    f->f3a.simm13 != 1) {
1761*f7184619SJoshua M. Clulow 			name = "inccc";
1762*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE);
1763*f7184619SJoshua M. Clulow 			break;
1764*f7184619SJoshua M. Clulow 		}
1765*f7184619SJoshua M. Clulow 		break;
1766*f7184619SJoshua M. Clulow 
1767*f7184619SJoshua M. Clulow 	case 0x11:
1768*f7184619SJoshua M. Clulow 		/* andcc */
1769*f7184619SJoshua M. Clulow 
1770*f7184619SJoshua M. Clulow 		if (f->f3.rd != 0)
1771*f7184619SJoshua M. Clulow 			break;
1772*f7184619SJoshua M. Clulow 
1773*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL))
1774*f7184619SJoshua M. Clulow 		    == 0)
1775*f7184619SJoshua M. Clulow 			break;
1776*f7184619SJoshua M. Clulow 
1777*f7184619SJoshua M. Clulow 		if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0) &&
1778*f7184619SJoshua M. Clulow 		    ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) == 0))
1779*f7184619SJoshua M. Clulow 			break;
1780*f7184619SJoshua M. Clulow 
1781*f7184619SJoshua M. Clulow 		name = "btst";
1782*f7184619SJoshua M. Clulow 		flags = FLG_P1(REG_NONE);
1783*f7184619SJoshua M. Clulow 		f->f3.rd = f->f3.rs1;
1784*f7184619SJoshua M. Clulow 		break;
1785*f7184619SJoshua M. Clulow 
1786*f7184619SJoshua M. Clulow 	case 0x12:
1787*f7184619SJoshua M. Clulow 		/* orcc */
1788*f7184619SJoshua M. Clulow 
1789*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1790*f7184619SJoshua M. Clulow 		    == 0)
1791*f7184619SJoshua M. Clulow 			break;
1792*f7184619SJoshua M. Clulow 
1793*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == 0 && f->f3.rd == 0 && f->f3.i == 0) {
1794*f7184619SJoshua M. Clulow 			name = "tst";
1795*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P3(REG_NONE);
1796*f7184619SJoshua M. Clulow 			break;
1797*f7184619SJoshua M. Clulow 		}
1798*f7184619SJoshua M. Clulow 
1799*f7184619SJoshua M. Clulow 		if (f->f3.rs2 == 0 && f->f3.rd == 0 && f->f3.i == 0) {
1800*f7184619SJoshua M. Clulow 			name = "tst";
1801*f7184619SJoshua M. Clulow 			flags = FLG_P2(REG_NONE)|FLG_P3(REG_NONE);
1802*f7184619SJoshua M. Clulow 			break;
1803*f7184619SJoshua M. Clulow 		}
1804*f7184619SJoshua M. Clulow 
1805*f7184619SJoshua M. Clulow 		break;
1806*f7184619SJoshua M. Clulow 
1807*f7184619SJoshua M. Clulow 	case 0x14:
1808*f7184619SJoshua M. Clulow 		/* subcc */
1809*f7184619SJoshua M. Clulow 
1810*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1811*f7184619SJoshua M. Clulow 		    == 0)
1812*f7184619SJoshua M. Clulow 			break;
1813*f7184619SJoshua M. Clulow 
1814*f7184619SJoshua M. Clulow 		if (f->f3.rd == 0) {
1815*f7184619SJoshua M. Clulow 			name = "cmp";
1816*f7184619SJoshua M. Clulow 			flags = FLG_P3(REG_NONE);
1817*f7184619SJoshua M. Clulow 			break;
1818*f7184619SJoshua M. Clulow 		}
1819*f7184619SJoshua M. Clulow 
1820*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0)
1821*f7184619SJoshua M. Clulow 			break;
1822*f7184619SJoshua M. Clulow 
1823*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1824*f7184619SJoshua M. Clulow 		    f->f3a.simm13 == 1) {
1825*f7184619SJoshua M. Clulow 			name = "deccc";
1826*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE)|FLG_P2(REG_NONE)|FLG_NOIMM;
1827*f7184619SJoshua M. Clulow 			break;
1828*f7184619SJoshua M. Clulow 		}
1829*f7184619SJoshua M. Clulow 
1830*f7184619SJoshua M. Clulow 		if (f->f3.rs1 == f->f3.rd && f->f3.i == 1 &&
1831*f7184619SJoshua M. Clulow 		    f->f3a.simm13 != 1) {
1832*f7184619SJoshua M. Clulow 			name = "deccc";
1833*f7184619SJoshua M. Clulow 			flags = FLG_P1(REG_NONE);
1834*f7184619SJoshua M. Clulow 			break;
1835*f7184619SJoshua M. Clulow 		}
1836*f7184619SJoshua M. Clulow 
1837*f7184619SJoshua M. Clulow 		break;
1838*f7184619SJoshua M. Clulow 
1839*f7184619SJoshua M. Clulow 	case 0x25:
1840*f7184619SJoshua M. Clulow 	case 0x26:
1841*f7184619SJoshua M. Clulow 	case 0x27:
1842*f7184619SJoshua M. Clulow 		return (prt_shift(dhp, instr, inp));
1843*f7184619SJoshua M. Clulow 
1844*f7184619SJoshua M. Clulow 	case 0x28:
1845*f7184619SJoshua M. Clulow 	case 0x29:
1846*f7184619SJoshua M. Clulow 	case 0x2a:
1847*f7184619SJoshua M. Clulow 	case 0x2b:
1848*f7184619SJoshua M. Clulow 	case 0x30:
1849*f7184619SJoshua M. Clulow 	case 0x31:
1850*f7184619SJoshua M. Clulow 	case 0x32:
1851*f7184619SJoshua M. Clulow 	case 0x33:
1852*f7184619SJoshua M. Clulow 		return (dis_fmt_rdwr(dhp, instr, inp, idx));
1853*f7184619SJoshua M. Clulow 
1854*f7184619SJoshua M. Clulow 	case 0x36:
1855*f7184619SJoshua M. Clulow 	case 0x37:
1856*f7184619SJoshua M. Clulow 		/* NOTE: overlayed on v9 */
1857*f7184619SJoshua M. Clulow 		if ((dhp->dh_flags & DIS_SPARC_V8) != 0)
1858*f7184619SJoshua M. Clulow 			return (fmt_cpop(dhp, instr, inp));
1859*f7184619SJoshua M. Clulow 		break;
1860*f7184619SJoshua M. Clulow 
1861*f7184619SJoshua M. Clulow 	case 0x38:
1862*f7184619SJoshua M. Clulow 		/* jmpl */
1863*f7184619SJoshua M. Clulow 		return (prt_jmpl(dhp, instr, inp, idx));
1864*f7184619SJoshua M. Clulow 
1865*f7184619SJoshua M. Clulow 	case 0x39:
1866*f7184619SJoshua M. Clulow 		/* rett / return */
1867*f7184619SJoshua M. Clulow 		prt_name(dhp, name, 1);
1868*f7184619SJoshua M. Clulow 		prt_address(dhp, instr, 1);
1869*f7184619SJoshua M. Clulow 		return (0);
1870*f7184619SJoshua M. Clulow 
1871*f7184619SJoshua M. Clulow 	case 0x3b:
1872*f7184619SJoshua M. Clulow 		/* flush */
1873*f7184619SJoshua M. Clulow 		prt_name(dhp, name, 1);
1874*f7184619SJoshua M. Clulow 		prt_address(dhp, instr, 0);
1875*f7184619SJoshua M. Clulow 		return (0);
1876*f7184619SJoshua M. Clulow 
1877*f7184619SJoshua M. Clulow 	case 0x3c:
1878*f7184619SJoshua M. Clulow 	case 0x3d:
1879*f7184619SJoshua M. Clulow 		/* save / restore */
1880*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & (DIS_DEBUG_SYN_ALL|DIS_DEBUG_COMPAT))
1881*f7184619SJoshua M. Clulow 		    == 0)
1882*f7184619SJoshua M. Clulow 			break;
1883*f7184619SJoshua M. Clulow 
1884*f7184619SJoshua M. Clulow 		if (f->f3.rs1 != 0 || f->f3.rs2 != 0 || f->f3.rd != 0)
1885*f7184619SJoshua M. Clulow 			break;
1886*f7184619SJoshua M. Clulow 
1887*f7184619SJoshua M. Clulow 		if (f->f3.i != 0 && ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0))
1888*f7184619SJoshua M. Clulow 			break;
1889*f7184619SJoshua M. Clulow 
1890*f7184619SJoshua M. Clulow 		prt_name(dhp, name, 0);
1891*f7184619SJoshua M. Clulow 		return (0);
1892*f7184619SJoshua M. Clulow 	}
1893*f7184619SJoshua M. Clulow 
1894*f7184619SJoshua M. Clulow 	if (FLG_P1_VAL(flags) != REG_NONE || FLG_P2_VAL(flags) != REG_NONE ||
1895*f7184619SJoshua M. Clulow 	    FLG_P3_VAL(flags) != REG_NONE)
1896*f7184619SJoshua M. Clulow 		arg = 1;
1897*f7184619SJoshua M. Clulow 
1898*f7184619SJoshua M. Clulow 	prt_name(dhp, name, (arg != 0));
1899*f7184619SJoshua M. Clulow 	prt_aluargs(dhp, instr, flags);
1900*f7184619SJoshua M. Clulow 
1901*f7184619SJoshua M. Clulow 	return (0);
1902*f7184619SJoshua M. Clulow }
1903*f7184619SJoshua M. Clulow 
1904*f7184619SJoshua M. Clulow /* ARGSUSED1 */
1905*f7184619SJoshua M. Clulow int
fmt_regwin(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1906*f7184619SJoshua M. Clulow fmt_regwin(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1907*f7184619SJoshua M. Clulow {
1908*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 0);
1909*f7184619SJoshua M. Clulow 	return (0);
1910*f7184619SJoshua M. Clulow }
1911*f7184619SJoshua M. Clulow 
1912*f7184619SJoshua M. Clulow /* ARGSUSED1 */
1913*f7184619SJoshua M. Clulow int
fmt_trap_ret(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1914*f7184619SJoshua M. Clulow fmt_trap_ret(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1915*f7184619SJoshua M. Clulow {
1916*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1917*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
1918*f7184619SJoshua M. Clulow 
1919*f7184619SJoshua M. Clulow 	if (f->f3.rd == 0xf) {
1920*f7184619SJoshua M. Clulow 		/* jpriv */
1921*f7184619SJoshua M. Clulow 		prt_address(dhp, instr, 1);
1922*f7184619SJoshua M. Clulow 	}
1923*f7184619SJoshua M. Clulow 
1924*f7184619SJoshua M. Clulow 	return (0);
1925*f7184619SJoshua M. Clulow }
1926*f7184619SJoshua M. Clulow 
1927*f7184619SJoshua M. Clulow /* ARGSUSED3 */
1928*f7184619SJoshua M. Clulow int
fmt_movcc(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1929*f7184619SJoshua M. Clulow fmt_movcc(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1930*f7184619SJoshua M. Clulow {
1931*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1932*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1933*f7184619SJoshua M. Clulow 	const char **regs = NULL;
1934*f7184619SJoshua M. Clulow 
1935*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
1936*f7184619SJoshua M. Clulow 		prt_field("op", f->f3c.op, 2);
1937*f7184619SJoshua M. Clulow 		prt_field("op3", f->f3c.op3, 6);
1938*f7184619SJoshua M. Clulow 		prt_field("cond", f->f3c.cond, 4);
1939*f7184619SJoshua M. Clulow 		prt_field("cc2", f->f3c.cc2, 1);
1940*f7184619SJoshua M. Clulow 		prt_field("cc", f->f3c.cc, 2);
1941*f7184619SJoshua M. Clulow 		prt_field("i", f->f3c.i, 1);
1942*f7184619SJoshua M. Clulow 
1943*f7184619SJoshua M. Clulow 		if (f->f3c.i == 0)
1944*f7184619SJoshua M. Clulow 			prt_field("rs2", f->f3.rs2, 5);
1945*f7184619SJoshua M. Clulow 		else
1946*f7184619SJoshua M. Clulow 			prt_field("simm11", f->f3c.simm11, 11);
1947*f7184619SJoshua M. Clulow 
1948*f7184619SJoshua M. Clulow 		prt_field("rd", f->f3.rd, 5);
1949*f7184619SJoshua M. Clulow 	}
1950*f7184619SJoshua M. Clulow 
1951*f7184619SJoshua M. Clulow 	if (f->f3c.cc2 == 0) {
1952*f7184619SJoshua M. Clulow 		regs = fcc_names;
1953*f7184619SJoshua M. Clulow 	} else {
1954*f7184619SJoshua M. Clulow 		regs = icc_names;
1955*f7184619SJoshua M. Clulow 		if (regs[f->f3c.cc] == NULL)
1956*f7184619SJoshua M. Clulow 			return (-1);
1957*f7184619SJoshua M. Clulow 	}
1958*f7184619SJoshua M. Clulow 
1959*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
1960*f7184619SJoshua M. Clulow 
1961*f7184619SJoshua M. Clulow 	bprintf(dhp, "%s, ", regs[f->f3c.cc]);
1962*f7184619SJoshua M. Clulow 
1963*f7184619SJoshua M. Clulow 	if (f->f3c.i == 1)
1964*f7184619SJoshua M. Clulow 		prt_imm(dhp, sign_extend(f->f3c.simm11, 11), IMM_SIGNED);
1965*f7184619SJoshua M. Clulow 	else
1966*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, reg_names[f->f3.rs2],
1967*f7184619SJoshua M. Clulow 		    dhx->dhx_buflen);
1968*f7184619SJoshua M. Clulow 
1969*f7184619SJoshua M. Clulow 	bprintf(dhp, ", %s", reg_names[f->f3.rd]);
1970*f7184619SJoshua M. Clulow 
1971*f7184619SJoshua M. Clulow 	return (0);
1972*f7184619SJoshua M. Clulow }
1973*f7184619SJoshua M. Clulow 
1974*f7184619SJoshua M. Clulow /* ARGSUSED3 */
1975*f7184619SJoshua M. Clulow int
fmt_movr(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1976*f7184619SJoshua M. Clulow fmt_movr(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1977*f7184619SJoshua M. Clulow {
1978*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
1979*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
1980*f7184619SJoshua M. Clulow 
1981*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
1982*f7184619SJoshua M. Clulow 
1983*f7184619SJoshua M. Clulow 	bprintf(dhp, "%s, ", reg_names[f->f3d.rs1]);
1984*f7184619SJoshua M. Clulow 
1985*f7184619SJoshua M. Clulow 	if (f->f3d.i == 1)
1986*f7184619SJoshua M. Clulow 		prt_imm(dhp, sign_extend(f->f3d.simm10, 10), IMM_SIGNED);
1987*f7184619SJoshua M. Clulow 	else
1988*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, reg_names[f->f3.rs2],
1989*f7184619SJoshua M. Clulow 		    dhx->dhx_buflen);
1990*f7184619SJoshua M. Clulow 
1991*f7184619SJoshua M. Clulow 	bprintf(dhp, ", %s", reg_names[f->f3.rd]);
1992*f7184619SJoshua M. Clulow 
1993*f7184619SJoshua M. Clulow 	return (0);
1994*f7184619SJoshua M. Clulow }
1995*f7184619SJoshua M. Clulow 
1996*f7184619SJoshua M. Clulow /* ARGSUSED3 */
1997*f7184619SJoshua M. Clulow int
fmt_fpop1(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)1998*f7184619SJoshua M. Clulow fmt_fpop1(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
1999*f7184619SJoshua M. Clulow {
2000*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2001*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
2002*f7184619SJoshua M. Clulow 	int flags = inp->in_data.in_def.in_flags;
2003*f7184619SJoshua M. Clulow 
2004*f7184619SJoshua M. Clulow 	flags |= FLG_NOIMM;
2005*f7184619SJoshua M. Clulow 
2006*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
2007*f7184619SJoshua M. Clulow 		prt_field("op", f->f3.op, 2);
2008*f7184619SJoshua M. Clulow 		prt_field("op3", f->f3.op3, 6);
2009*f7184619SJoshua M. Clulow 		prt_field("opf", f->fcmp.opf, 9);
2010*f7184619SJoshua M. Clulow 		prt_field("rs1", f->f3.rs1, 5);
2011*f7184619SJoshua M. Clulow 		prt_field("rs2", f->f3.rs2, 5);
2012*f7184619SJoshua M. Clulow 		prt_field("rd", f->f3.rd, 5);
2013*f7184619SJoshua M. Clulow 	}
2014*f7184619SJoshua M. Clulow 
2015*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
2016*f7184619SJoshua M. Clulow 	prt_aluargs(dhp, instr, flags);
2017*f7184619SJoshua M. Clulow 
2018*f7184619SJoshua M. Clulow 	return (0);
2019*f7184619SJoshua M. Clulow }
2020*f7184619SJoshua M. Clulow 
2021*f7184619SJoshua M. Clulow int
fmt_fpop2(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)2022*f7184619SJoshua M. Clulow fmt_fpop2(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
2023*f7184619SJoshua M. Clulow {
2024*f7184619SJoshua M. Clulow 	static const char *condstr_icc[16] = {
2025*f7184619SJoshua M. Clulow 		"n", "e",  "le", "l",  "leu", "lu",  "neg", "vs",
2026*f7184619SJoshua M. Clulow 		"a", "nz", "g",  "ge", "gu",  "geu", "pos", "vc"
2027*f7184619SJoshua M. Clulow 	};
2028*f7184619SJoshua M. Clulow 
2029*f7184619SJoshua M. Clulow 	static const char *condstr_fcc[16] = {
2030*f7184619SJoshua M. Clulow 		"n", "nz", "lg", "ul", "l",   "ug", "g",   "u",
2031*f7184619SJoshua M. Clulow 		"a", "e",  "ue", "ge", "uge", "le", "ule", "o"
2032*f7184619SJoshua M. Clulow 	};
2033*f7184619SJoshua M. Clulow 
2034*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2035*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
2036*f7184619SJoshua M. Clulow 	const char *ccstr = "";
2037*f7184619SJoshua M. Clulow 	char name[15];
2038*f7184619SJoshua M. Clulow 
2039*f7184619SJoshua M. Clulow 	int flags = inp->in_data.in_def.in_flags;
2040*f7184619SJoshua M. Clulow 	int is_cmp = (idx == 0x51 || idx == 0x52 || idx == 0x53 ||
2041*f7184619SJoshua M. Clulow 	    idx == 0x55 || idx == 0x56 || idx == 0x57);
2042*f7184619SJoshua M. Clulow 	int is_fmov = (idx & 0x3f);
2043*f7184619SJoshua M. Clulow 	int is_v9 = ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0);
2044*f7184619SJoshua M. Clulow 	int is_compat = ((dhx->dhx_debug & DIS_DEBUG_COMPAT) != 0);
2045*f7184619SJoshua M. Clulow 
2046*f7184619SJoshua M. Clulow 	int p_cc = 0;
2047*f7184619SJoshua M. Clulow 
2048*f7184619SJoshua M. Clulow 	is_fmov = (is_fmov == 0x1 || is_fmov == 0x2 || is_fmov == 0x3);
2049*f7184619SJoshua M. Clulow 
2050*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
2051*f7184619SJoshua M. Clulow 		prt_field("op", f->f3.op, 2);
2052*f7184619SJoshua M. Clulow 		prt_field("op3", f->f3.op3, 6);
2053*f7184619SJoshua M. Clulow 		prt_field("opf", f->fcmp.opf, 9);
2054*f7184619SJoshua M. Clulow 
2055*f7184619SJoshua M. Clulow 		switch (idx & 0x3f) {
2056*f7184619SJoshua M. Clulow 		case 0x51:
2057*f7184619SJoshua M. Clulow 		case 0x52:
2058*f7184619SJoshua M. Clulow 		case 0x53:
2059*f7184619SJoshua M. Clulow 		case 0x55:
2060*f7184619SJoshua M. Clulow 		case 0x56:
2061*f7184619SJoshua M. Clulow 		case 0x57:
2062*f7184619SJoshua M. Clulow 			prt_field("cc", f->fcmp.cc, 2);
2063*f7184619SJoshua M. Clulow 			prt_field("rs1", f->f3.rs1, 5);
2064*f7184619SJoshua M. Clulow 			prt_field("rs2", f->f3.rs2, 5);
2065*f7184619SJoshua M. Clulow 			break;
2066*f7184619SJoshua M. Clulow 
2067*f7184619SJoshua M. Clulow 		case 0x01:
2068*f7184619SJoshua M. Clulow 		case 0x02:
2069*f7184619SJoshua M. Clulow 		case 0x03:
2070*f7184619SJoshua M. Clulow 			prt_field("opf_low", f->fmv.opf, 6);
2071*f7184619SJoshua M. Clulow 			prt_field("cond", f->fmv.cond, 4);
2072*f7184619SJoshua M. Clulow 			prt_field("opf_cc", f->fmv.cc, 3);
2073*f7184619SJoshua M. Clulow 			prt_field("rs2", f->fmv.rs2, 5);
2074*f7184619SJoshua M. Clulow 			break;
2075*f7184619SJoshua M. Clulow 
2076*f7184619SJoshua M. Clulow 		default:
2077*f7184619SJoshua M. Clulow 			prt_field("rs1", f->f3.rs1, 5);
2078*f7184619SJoshua M. Clulow 			prt_field("rs2", f->f3.rs2, 5);
2079*f7184619SJoshua M. Clulow 			prt_field("rd", f->f3.rd, 5);
2080*f7184619SJoshua M. Clulow 		}
2081*f7184619SJoshua M. Clulow 	}
2082*f7184619SJoshua M. Clulow 
2083*f7184619SJoshua M. Clulow 	name[0] = '\0';
2084*f7184619SJoshua M. Clulow 	(void) strlcat(name, inp->in_data.in_def.in_name, sizeof (name));
2085*f7184619SJoshua M. Clulow 
2086*f7184619SJoshua M. Clulow 	if (is_fmov != 0) {
2087*f7184619SJoshua M. Clulow 		(void) strlcat(name,
2088*f7184619SJoshua M. Clulow 		    (f->fmv.cc < 4) ? condstr_fcc[f->fmv.cond]
2089*f7184619SJoshua M. Clulow 		    : condstr_icc[f->fmv.cond],
2090*f7184619SJoshua M. Clulow 		    sizeof (name));
2091*f7184619SJoshua M. Clulow 	}
2092*f7184619SJoshua M. Clulow 
2093*f7184619SJoshua M. Clulow 	prt_name(dhp, name, 1);
2094*f7184619SJoshua M. Clulow 
2095*f7184619SJoshua M. Clulow 	if (is_cmp != 0)
2096*f7184619SJoshua M. Clulow 		ccstr = fcc_names[f->fcmp.cc];
2097*f7184619SJoshua M. Clulow 
2098*f7184619SJoshua M. Clulow 	if (is_fmov != 0)
2099*f7184619SJoshua M. Clulow 		ccstr = (f->fmv.cc < 4) ? fcc_names[f->fmv.cc & 0x3]
2100*f7184619SJoshua M. Clulow 		    : icc_names[f->fmv.cc & 0x3];
2101*f7184619SJoshua M. Clulow 
2102*f7184619SJoshua M. Clulow 	if (ccstr == NULL)
2103*f7184619SJoshua M. Clulow 		return (-1);
2104*f7184619SJoshua M. Clulow 
2105*f7184619SJoshua M. Clulow 	p_cc = (is_compat == 0 || is_v9 != 0 ||
2106*f7184619SJoshua M. Clulow 	    (is_cmp != 0 && f->fcmp.cc != 0) ||
2107*f7184619SJoshua M. Clulow 	    (is_fmov != 0 && f->fmv.cc != 0));
2108*f7184619SJoshua M. Clulow 
2109*f7184619SJoshua M. Clulow 	if (p_cc != 0)
2110*f7184619SJoshua M. Clulow 		bprintf(dhp, "%s, ", ccstr);
2111*f7184619SJoshua M. Clulow 
2112*f7184619SJoshua M. Clulow 	prt_aluargs(dhp, instr, flags);
2113*f7184619SJoshua M. Clulow 
2114*f7184619SJoshua M. Clulow 	return (0);
2115*f7184619SJoshua M. Clulow }
2116*f7184619SJoshua M. Clulow 
2117*f7184619SJoshua M. Clulow int
fmt_vis(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)2118*f7184619SJoshua M. Clulow fmt_vis(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
2119*f7184619SJoshua M. Clulow {
2120*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2121*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
2122*f7184619SJoshua M. Clulow 	int flags = inp->in_data.in_def.in_flags;
2123*f7184619SJoshua M. Clulow 
2124*f7184619SJoshua M. Clulow 	if ((dhx->dhx_debug & DIS_DEBUG_PRTFMT) != 0) {
2125*f7184619SJoshua M. Clulow 		prt_field("op", f->f3.op, 2);
2126*f7184619SJoshua M. Clulow 		prt_field("op3", f->f3.op3, 6);
2127*f7184619SJoshua M. Clulow 		prt_field("opf", f->fcmp.opf, 9);
2128*f7184619SJoshua M. Clulow 
2129*f7184619SJoshua M. Clulow 		if (idx == 0x081) {
2130*f7184619SJoshua M. Clulow 			prt_field("mode", instr & 02L, 2);
2131*f7184619SJoshua M. Clulow 		} else {
2132*f7184619SJoshua M. Clulow 			prt_field("rs1", f->f3.rs1, 5);
2133*f7184619SJoshua M. Clulow 			prt_field("rs2", f->f3.rs2, 5);
2134*f7184619SJoshua M. Clulow 			prt_field("rd", f->f3.rd, 5);
2135*f7184619SJoshua M. Clulow 		}
2136*f7184619SJoshua M. Clulow 	}
2137*f7184619SJoshua M. Clulow 
2138*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
2139*f7184619SJoshua M. Clulow 
2140*f7184619SJoshua M. Clulow 	if (idx == 0x081) {
2141*f7184619SJoshua M. Clulow 		/* siam */
2142*f7184619SJoshua M. Clulow 		bprintf(dhp, "%d", instr & 0x7L);
2143*f7184619SJoshua M. Clulow 		return (0);
2144*f7184619SJoshua M. Clulow 	}
2145*f7184619SJoshua M. Clulow 
2146*f7184619SJoshua M. Clulow 	prt_aluargs(dhp, instr, flags);
2147*f7184619SJoshua M. Clulow 
2148*f7184619SJoshua M. Clulow 	return (0);
2149*f7184619SJoshua M. Clulow }
2150*f7184619SJoshua M. Clulow 
2151*f7184619SJoshua M. Clulow /* ARGSUSED3 */
2152*f7184619SJoshua M. Clulow int
fmt_fused(dis_handle_t * dhp,uint32_t instr,const inst_t * inp,int idx)2153*f7184619SJoshua M. Clulow fmt_fused(dis_handle_t *dhp, uint32_t instr, const inst_t *inp, int idx)
2154*f7184619SJoshua M. Clulow {
2155*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
2156*f7184619SJoshua M. Clulow 	int flags = inp->in_data.in_def.in_flags;
2157*f7184619SJoshua M. Clulow 
2158*f7184619SJoshua M. Clulow 	prt_name(dhp, inp->in_data.in_def.in_name, 1);
2159*f7184619SJoshua M. Clulow 	bprintf(dhp, "%s, %s, %s, %s",
2160*f7184619SJoshua M. Clulow 	    get_regname(dhp, FLG_P1_VAL(flags), f->fused.rs1),
2161*f7184619SJoshua M. Clulow 	    get_regname(dhp, FLG_P1_VAL(flags), f->fused.rs2),
2162*f7184619SJoshua M. Clulow 	    get_regname(dhp, FLG_P1_VAL(flags), f->fused.rs3),
2163*f7184619SJoshua M. Clulow 	    get_regname(dhp, FLG_P1_VAL(flags), f->fused.rd));
2164*f7184619SJoshua M. Clulow 
2165*f7184619SJoshua M. Clulow 	return (0);
2166*f7184619SJoshua M. Clulow }
2167*f7184619SJoshua M. Clulow /*
2168*f7184619SJoshua M. Clulow  * put name into the output buffer
2169*f7184619SJoshua M. Clulow  * if add_space !=0, append a space after it
2170*f7184619SJoshua M. Clulow  */
2171*f7184619SJoshua M. Clulow static void
prt_name(dis_handle_t * dhp,const char * name,int add_space)2172*f7184619SJoshua M. Clulow prt_name(dis_handle_t *dhp, const char *name, int add_space)
2173*f7184619SJoshua M. Clulow {
2174*f7184619SJoshua M. Clulow 	bprintf(dhp, (add_space == 0) ? "%s" : "%-9s ", name);
2175*f7184619SJoshua M. Clulow }
2176*f7184619SJoshua M. Clulow 
2177*f7184619SJoshua M. Clulow /*
2178*f7184619SJoshua M. Clulow  * For debugging, print out a field of the instruction
2179*f7184619SJoshua M. Clulow  * field is the name of the field
2180*f7184619SJoshua M. Clulow  * val is the value of the field
2181*f7184619SJoshua M. Clulow  * len is the length of the field (in bits)
2182*f7184619SJoshua M. Clulow  */
2183*f7184619SJoshua M. Clulow #if defined(DIS_STANDALONE)
2184*f7184619SJoshua M. Clulow /* ARGSUSED */
2185*f7184619SJoshua M. Clulow static void
prt_field(const char * field,uint32_t val,int len)2186*f7184619SJoshua M. Clulow prt_field(const char *field, uint32_t val, int len)
2187*f7184619SJoshua M. Clulow {
2188*f7184619SJoshua M. Clulow 
2189*f7184619SJoshua M. Clulow }
2190*f7184619SJoshua M. Clulow 
2191*f7184619SJoshua M. Clulow #else
2192*f7184619SJoshua M. Clulow static void
prt_field(const char * field,uint32_t val,int len)2193*f7184619SJoshua M. Clulow prt_field(const char *field, uint32_t val, int len)
2194*f7184619SJoshua M. Clulow {
2195*f7184619SJoshua M. Clulow 	(void) fprintf(stderr, "DISASM: %8s = 0x%-8x (", field, val);
2196*f7184619SJoshua M. Clulow 	prt_binary(val, len);
2197*f7184619SJoshua M. Clulow 	(void) fprintf(stderr, ")\n");
2198*f7184619SJoshua M. Clulow }
2199*f7184619SJoshua M. Clulow #endif /* DIS_STANDALONE */
2200*f7184619SJoshua M. Clulow 
2201*f7184619SJoshua M. Clulow /*
2202*f7184619SJoshua M. Clulow  * sign extend a val (that is 'bits' bits in length) to a 32-bit signed
2203*f7184619SJoshua M. Clulow  * integer
2204*f7184619SJoshua M. Clulow  */
2205*f7184619SJoshua M. Clulow static int32_t
sign_extend(int32_t val,int32_t bits)2206*f7184619SJoshua M. Clulow sign_extend(int32_t val, int32_t bits)
2207*f7184619SJoshua M. Clulow {
2208*f7184619SJoshua M. Clulow 	if ((val & (1L << (bits - 1))) == 0)
2209*f7184619SJoshua M. Clulow 		return (val);
2210*f7184619SJoshua M. Clulow 
2211*f7184619SJoshua M. Clulow 	return ((-1L << bits) | val);
2212*f7184619SJoshua M. Clulow }
2213*f7184619SJoshua M. Clulow 
2214*f7184619SJoshua M. Clulow /*
2215*f7184619SJoshua M. Clulow  * print out an immediate (i.e. constant) value
2216*f7184619SJoshua M. Clulow  * val is the value
2217*f7184619SJoshua M. Clulow  * format indicates if it is:
2218*f7184619SJoshua M. Clulow  * 0		 Unsigned
2219*f7184619SJoshua M. Clulow  * IMM_SIGNED  A signed value (prepend +/- to the value)
2220*f7184619SJoshua M. Clulow  * IMM_ADDR    Part of an address expression (prepend +/- but with a space
2221*f7184619SJoshua M. Clulow  *		   between the sign and the value for things like [%i1 + 0x55]
2222*f7184619SJoshua M. Clulow  */
2223*f7184619SJoshua M. Clulow static void
prt_imm(dis_handle_t * dhp,uint32_t val,int format)2224*f7184619SJoshua M. Clulow prt_imm(dis_handle_t *dhp, uint32_t val, int format)
2225*f7184619SJoshua M. Clulow {
2226*f7184619SJoshua M. Clulow 	const char *fmtstr = NULL;
2227*f7184619SJoshua M. Clulow 	int32_t sv = (int32_t)val;
2228*f7184619SJoshua M. Clulow 	int octal = dhp->dh_flags & DIS_OCTAL;
2229*f7184619SJoshua M. Clulow 
2230*f7184619SJoshua M. Clulow 	switch (format) {
2231*f7184619SJoshua M. Clulow 	case IMM_ADDR:
2232*f7184619SJoshua M. Clulow 		if (sv < 0) {
2233*f7184619SJoshua M. Clulow 			sv = -sv;
2234*f7184619SJoshua M. Clulow 			fmtstr = (octal != 0) ? "- 0%lo" : "- 0x%lx";
2235*f7184619SJoshua M. Clulow 		} else {
2236*f7184619SJoshua M. Clulow 			fmtstr = (octal != 0) ? "+ 0%lo" : "+ 0x%lx";
2237*f7184619SJoshua M. Clulow 		}
2238*f7184619SJoshua M. Clulow 		break;
2239*f7184619SJoshua M. Clulow 
2240*f7184619SJoshua M. Clulow 	case IMM_SIGNED:
2241*f7184619SJoshua M. Clulow 		if (sv < 0) {
2242*f7184619SJoshua M. Clulow 			sv = -sv;
2243*f7184619SJoshua M. Clulow 			fmtstr = (octal != 0) ? "-0%lo" : "-0x%lx";
2244*f7184619SJoshua M. Clulow 			break;
2245*f7184619SJoshua M. Clulow 		}
2246*f7184619SJoshua M. Clulow 		/* fall through */
2247*f7184619SJoshua M. Clulow 
2248*f7184619SJoshua M. Clulow 	default:
2249*f7184619SJoshua M. Clulow 		fmtstr = (octal != 0) ? "0%lo" : "0x%lx";
2250*f7184619SJoshua M. Clulow 	}
2251*f7184619SJoshua M. Clulow 
2252*f7184619SJoshua M. Clulow 	bprintf(dhp, fmtstr, sv);
2253*f7184619SJoshua M. Clulow }
2254*f7184619SJoshua M. Clulow 
2255*f7184619SJoshua M. Clulow /*
2256*f7184619SJoshua M. Clulow  * return the symbolic name of a register
2257*f7184619SJoshua M. Clulow  * regset is one of the REG_* values indicating which type of register it is
2258*f7184619SJoshua M. Clulow  * such as integer, floating point, etc.
2259*f7184619SJoshua M. Clulow  * idx is the numeric value of the register
2260*f7184619SJoshua M. Clulow  *
2261*f7184619SJoshua M. Clulow  * If regset is REG_NONE, an empty, but non-NULL string is returned
2262*f7184619SJoshua M. Clulow  * NULL may be returned if the index indicates an invalid register value
2263*f7184619SJoshua M. Clulow  * such as with the %icc/%xcc sets
2264*f7184619SJoshua M. Clulow  */
2265*f7184619SJoshua M. Clulow static const char *
get_regname(dis_handle_t * dhp,int regset,uint32_t idx)2266*f7184619SJoshua M. Clulow get_regname(dis_handle_t *dhp, int regset, uint32_t idx)
2267*f7184619SJoshua M. Clulow {
2268*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2269*f7184619SJoshua M. Clulow 	const char *regname = NULL;
2270*f7184619SJoshua M. Clulow 
2271*f7184619SJoshua M. Clulow 	switch (regset) {
2272*f7184619SJoshua M. Clulow 	case REG_INT:
2273*f7184619SJoshua M. Clulow 		regname = reg_names[idx];
2274*f7184619SJoshua M. Clulow 		break;
2275*f7184619SJoshua M. Clulow 
2276*f7184619SJoshua M. Clulow 	case REG_FP:
2277*f7184619SJoshua M. Clulow 		regname = freg_names[idx];
2278*f7184619SJoshua M. Clulow 		break;
2279*f7184619SJoshua M. Clulow 
2280*f7184619SJoshua M. Clulow 	case REG_FPD:
2281*f7184619SJoshua M. Clulow 		if (((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0) ||
2282*f7184619SJoshua M. Clulow 		    ((dhp->dh_flags & (DIS_SPARC_V9|DIS_SPARC_V9_SGI)) != 0))
2283*f7184619SJoshua M. Clulow 			regname = fdreg_names[idx];
2284*f7184619SJoshua M. Clulow 		else
2285*f7184619SJoshua M. Clulow 			regname = compat_fdreg_names[idx];
2286*f7184619SJoshua M. Clulow 
2287*f7184619SJoshua M. Clulow 		break;
2288*f7184619SJoshua M. Clulow 
2289*f7184619SJoshua M. Clulow 	case REG_FPQ:
2290*f7184619SJoshua M. Clulow 		if ((dhx->dhx_debug & DIS_DEBUG_COMPAT) == 0)
2291*f7184619SJoshua M. Clulow 			regname = fqreg_names[idx];
2292*f7184619SJoshua M. Clulow 		else
2293*f7184619SJoshua M. Clulow 			regname = freg_names[idx];
2294*f7184619SJoshua M. Clulow 
2295*f7184619SJoshua M. Clulow 		break;
2296*f7184619SJoshua M. Clulow 
2297*f7184619SJoshua M. Clulow 	case REG_CP:
2298*f7184619SJoshua M. Clulow 		regname = cpreg_names[idx];
2299*f7184619SJoshua M. Clulow 		break;
2300*f7184619SJoshua M. Clulow 
2301*f7184619SJoshua M. Clulow 	case REG_ICC:
2302*f7184619SJoshua M. Clulow 		regname = icc_names[idx];
2303*f7184619SJoshua M. Clulow 		break;
2304*f7184619SJoshua M. Clulow 
2305*f7184619SJoshua M. Clulow 	case REG_FCC:
2306*f7184619SJoshua M. Clulow 		regname = fcc_names[idx];
2307*f7184619SJoshua M. Clulow 		break;
2308*f7184619SJoshua M. Clulow 
2309*f7184619SJoshua M. Clulow 	case REG_FSR:
2310*f7184619SJoshua M. Clulow 		regname = "%fsr";
2311*f7184619SJoshua M. Clulow 		break;
2312*f7184619SJoshua M. Clulow 
2313*f7184619SJoshua M. Clulow 	case REG_CSR:
2314*f7184619SJoshua M. Clulow 		regname = "%csr";
2315*f7184619SJoshua M. Clulow 		break;
2316*f7184619SJoshua M. Clulow 
2317*f7184619SJoshua M. Clulow 	case REG_CQ:
2318*f7184619SJoshua M. Clulow 		regname = "%cq";
2319*f7184619SJoshua M. Clulow 		break;
2320*f7184619SJoshua M. Clulow 
2321*f7184619SJoshua M. Clulow 	case REG_NONE:
2322*f7184619SJoshua M. Clulow 		regname = "";
2323*f7184619SJoshua M. Clulow 		break;
2324*f7184619SJoshua M. Clulow 	}
2325*f7184619SJoshua M. Clulow 
2326*f7184619SJoshua M. Clulow 	return (regname);
2327*f7184619SJoshua M. Clulow }
2328*f7184619SJoshua M. Clulow 
2329*f7184619SJoshua M. Clulow /*
2330*f7184619SJoshua M. Clulow  * output the asi value from the instruction
2331*f7184619SJoshua M. Clulow  *
2332*f7184619SJoshua M. Clulow  * TODO: investigate if this should perhaps have a mask -- are undefined ASI
2333*f7184619SJoshua M. Clulow  *	  values for an instruction still disassembled??
2334*f7184619SJoshua M. Clulow  */
2335*f7184619SJoshua M. Clulow static void
prt_asi(dis_handle_t * dhp,uint32_t instr)2336*f7184619SJoshua M. Clulow prt_asi(dis_handle_t *dhp, uint32_t instr)
2337*f7184619SJoshua M. Clulow {
2338*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
2339*f7184619SJoshua M. Clulow 	int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
2340*f7184619SJoshua M. Clulow 
2341*f7184619SJoshua M. Clulow 	if (f->f3.i != 0)
2342*f7184619SJoshua M. Clulow 		bprintf(dhp, "%%asi");
2343*f7184619SJoshua M. Clulow 	else
2344*f7184619SJoshua M. Clulow 		bprintf(dhp, (octal != 0) ? "0%03o" : "0x%02x", f->f3.asi);
2345*f7184619SJoshua M. Clulow 
2346*f7184619SJoshua M. Clulow }
2347*f7184619SJoshua M. Clulow 
2348*f7184619SJoshua M. Clulow /*
2349*f7184619SJoshua M. Clulow  * put an address expression into the output buffer
2350*f7184619SJoshua M. Clulow  *
2351*f7184619SJoshua M. Clulow  * instr is the instruction to use
2352*f7184619SJoshua M. Clulow  * if nobrackets != 0, [] are not added around the instruction
2353*f7184619SJoshua M. Clulow  *
2354*f7184619SJoshua M. Clulow  * Currently this option is set when printing out the address portion
2355*f7184619SJoshua M. Clulow  * of a jmpl instruction, but otherwise 0 for load/stores
2356*f7184619SJoshua M. Clulow  *
2357*f7184619SJoshua M. Clulow  * If no debug flags are set, the full expression is output, even when
2358*f7184619SJoshua M. Clulow  * %g0 or 0x0 appears in the address
2359*f7184619SJoshua M. Clulow  *
2360*f7184619SJoshua M. Clulow  * If DIS_DEBUG_SYN_ALL or DIS_DEBUG_COMPAT are set, when %g0 or 0x0
2361*f7184619SJoshua M. Clulow  * appear in the address, they are not output.  If the wierd (and probably
2362*f7184619SJoshua M. Clulow  * shouldn't happen) address of [%g0 + %g0] or [%g0 + 0x0] is encountered,
2363*f7184619SJoshua M. Clulow  * [%g0] is output
2364*f7184619SJoshua M. Clulow  */
2365*f7184619SJoshua M. Clulow static void
prt_address(dis_handle_t * dhp,uint32_t instr,int nobrackets)2366*f7184619SJoshua M. Clulow prt_address(dis_handle_t *dhp, uint32_t instr, int nobrackets)
2367*f7184619SJoshua M. Clulow {
2368*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2369*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
2370*f7184619SJoshua M. Clulow 	int32_t simm13;
2371*f7184619SJoshua M. Clulow 	int octal = ((dhp->dh_flags & DIS_OCTAL) != 0);
2372*f7184619SJoshua M. Clulow 	int p1 = ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0);
2373*f7184619SJoshua M. Clulow 	int p2 = ((dhx->dhx_debug & (DIS_DEBUG_COMPAT|DIS_DEBUG_SYN_ALL)) == 0);
2374*f7184619SJoshua M. Clulow 
2375*f7184619SJoshua M. Clulow 	if (f->f3a.i == 0) {
2376*f7184619SJoshua M. Clulow 		p1 |= ((f->f3a.rs1 != 0) || f->f3.rs2 == 0);
2377*f7184619SJoshua M. Clulow 		p2 |= (f->f3.rs2 != 0);
2378*f7184619SJoshua M. Clulow 
2379*f7184619SJoshua M. Clulow 		bprintf(dhp, "%s%s%s%s%s",
2380*f7184619SJoshua M. Clulow 		    (nobrackets == 0) ? "[" : "",
2381*f7184619SJoshua M. Clulow 		    (p1 != 0) ? reg_names[f->f3a.rs1] : "",
2382*f7184619SJoshua M. Clulow 		    (p1 != 0 && p2 != 0) ? " + " : "",
2383*f7184619SJoshua M. Clulow 		    (p2 != 0) ? reg_names[f->f3.rs2] : "",
2384*f7184619SJoshua M. Clulow 		    (nobrackets == 0) ? "]" : "");
2385*f7184619SJoshua M. Clulow 	} else {
2386*f7184619SJoshua M. Clulow 		const char *sign;
2387*f7184619SJoshua M. Clulow 
2388*f7184619SJoshua M. Clulow 		simm13 = sign_extend(f->f3a.simm13, 13);
2389*f7184619SJoshua M. Clulow 		sign = (simm13 < 0) ? "-" : "+";
2390*f7184619SJoshua M. Clulow 
2391*f7184619SJoshua M. Clulow 		p1 |= (f->f3a.rs1 != 0);
2392*f7184619SJoshua M. Clulow 		p2 |= (p1 == 0 || simm13 != 0);
2393*f7184619SJoshua M. Clulow 
2394*f7184619SJoshua M. Clulow 		if (p1 == 0 && simm13 == 0)
2395*f7184619SJoshua M. Clulow 			p2 = 1;
2396*f7184619SJoshua M. Clulow 
2397*f7184619SJoshua M. Clulow 		if (p1 == 0 && simm13 >= 0)
2398*f7184619SJoshua M. Clulow 			sign = "";
2399*f7184619SJoshua M. Clulow 
2400*f7184619SJoshua M. Clulow 		if (p2 != 0)
2401*f7184619SJoshua M. Clulow 			bprintf(dhp,
2402*f7184619SJoshua M. Clulow 			    (octal != 0) ? "%s%s%s%s%s0%lo%s" :
2403*f7184619SJoshua M. Clulow 			    "%s%s%s%s%s0x%lx%s",
2404*f7184619SJoshua M. Clulow 			    (nobrackets == 0) ? "[" : "",
2405*f7184619SJoshua M. Clulow 			    (p1 != 0) ? reg_names[f->f3a.rs1] : "",
2406*f7184619SJoshua M. Clulow 			    (p1 != 0) ? " " : "",
2407*f7184619SJoshua M. Clulow 			    sign,
2408*f7184619SJoshua M. Clulow 			    (p1 != 0) ? " " : "",
2409*f7184619SJoshua M. Clulow 			    (simm13 < 0) ? -(simm13) : simm13,
2410*f7184619SJoshua M. Clulow 			    (nobrackets == 0) ? "]" : "");
2411*f7184619SJoshua M. Clulow 		else
2412*f7184619SJoshua M. Clulow 			bprintf(dhp, "%s%s%s",
2413*f7184619SJoshua M. Clulow 			    (nobrackets == 0) ? "[" : "",
2414*f7184619SJoshua M. Clulow 			    reg_names[f->f3a.rs1],
2415*f7184619SJoshua M. Clulow 			    (nobrackets == 0) ? "]" : "");
2416*f7184619SJoshua M. Clulow 	}
2417*f7184619SJoshua M. Clulow }
2418*f7184619SJoshua M. Clulow 
2419*f7184619SJoshua M. Clulow /*
2420*f7184619SJoshua M. Clulow  * print out the arguments to an alu operation (add, sub, etc.)
2421*f7184619SJoshua M. Clulow  * conatined in 'instr'
2422*f7184619SJoshua M. Clulow  *
2423*f7184619SJoshua M. Clulow  * alu instructions have the following format:
2424*f7184619SJoshua M. Clulow  *	 %rs1, %rs2, %rd    (i == 0)
2425*f7184619SJoshua M. Clulow  *	 %rs1, 0xnnn, %rd   (i == 1)
2426*f7184619SJoshua M. Clulow  *	   ^	^	^
2427*f7184619SJoshua M. Clulow  *	   |	|	|
2428*f7184619SJoshua M. Clulow  *	  p1    p2	p3
2429*f7184619SJoshua M. Clulow  *
2430*f7184619SJoshua M. Clulow  * flags indicates the register set to use for each position (p1, p2, p3)
2431*f7184619SJoshua M. Clulow  * as well as if immediate values (i == 1) are allowed
2432*f7184619SJoshua M. Clulow  *
2433*f7184619SJoshua M. Clulow  * if flags indicates a specific position has REG_NONE set as it's register
2434*f7184619SJoshua M. Clulow  * set, it is omitted from the output.  This is primarly used for certain
2435*f7184619SJoshua M. Clulow  * floating point operations
2436*f7184619SJoshua M. Clulow  */
2437*f7184619SJoshua M. Clulow static void
prt_aluargs(dis_handle_t * dhp,uint32_t instr,uint32_t flags)2438*f7184619SJoshua M. Clulow prt_aluargs(dis_handle_t *dhp, uint32_t instr, uint32_t flags)
2439*f7184619SJoshua M. Clulow {
2440*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2441*f7184619SJoshua M. Clulow 	ifmt_t *f = (ifmt_t *)&instr;
2442*f7184619SJoshua M. Clulow 	const char *r1, *r2, *r3;
2443*f7184619SJoshua M. Clulow 	int p1, p2, p3;
2444*f7184619SJoshua M. Clulow 	unsigned int opf = 0;
2445*f7184619SJoshua M. Clulow 
2446*f7184619SJoshua M. Clulow 	r1 = get_regname(dhp, FLG_P1_VAL(flags), f->f3.rs1);
2447*f7184619SJoshua M. Clulow 	r2 = get_regname(dhp, FLG_P2_VAL(flags), f->f3.rs2);
2448*f7184619SJoshua M. Clulow 	r3 = get_regname(dhp, FLG_P3_VAL(flags), f->f3.rd);
2449*f7184619SJoshua M. Clulow 
2450*f7184619SJoshua M. Clulow 	p1 = (FLG_P1_VAL(flags) != REG_NONE);
2451*f7184619SJoshua M. Clulow 	p2 = (((flags & FLG_NOIMM) == 0) || (FLG_P2_VAL(flags) != REG_NONE));
2452*f7184619SJoshua M. Clulow 	p3 = (FLG_RD_VAL(flags) != REG_NONE);
2453*f7184619SJoshua M. Clulow 
2454*f7184619SJoshua M. Clulow 	if (r1 == NULL || r1[0] == '\0')
2455*f7184619SJoshua M. Clulow 		p1 = 0;
2456*f7184619SJoshua M. Clulow 
2457*f7184619SJoshua M. Clulow 	if (f->f3a.i == 0 && (r2 == NULL || r2[0] == '\0'))
2458*f7184619SJoshua M. Clulow 		p2 = 0;
2459*f7184619SJoshua M. Clulow 
2460*f7184619SJoshua M. Clulow 	if (r3 == NULL || r3[0] == '\0')
2461*f7184619SJoshua M. Clulow 		p3 = 0;
2462*f7184619SJoshua M. Clulow 
2463*f7184619SJoshua M. Clulow 	if ((f->fcmp.op == 2) && (f->fcmp.op3 == 0x36) && (f->fcmp.cc != 0))
2464*f7184619SJoshua M. Clulow 		opf = f->fcmp.opf;
2465*f7184619SJoshua M. Clulow 
2466*f7184619SJoshua M. Clulow 	if ((opf == 0x151) || (opf == 0x152)) {
2467*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, r3, dhx->dhx_buflen);
2468*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
2469*f7184619SJoshua M. Clulow 		p3 = 0;
2470*f7184619SJoshua M. Clulow 	}
2471*f7184619SJoshua M. Clulow 
2472*f7184619SJoshua M. Clulow 	if (p1 != 0) {
2473*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, r1, dhx->dhx_buflen);
2474*f7184619SJoshua M. Clulow 		if (p2 != 0 || p3 != 0)
2475*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
2476*f7184619SJoshua M. Clulow 	}
2477*f7184619SJoshua M. Clulow 
2478*f7184619SJoshua M. Clulow 	if (p2 != 0) {
2479*f7184619SJoshua M. Clulow 		if (f->f3.i == 0 || ((flags & FLG_NOIMM) != 0))
2480*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, r2, dhx->dhx_buflen);
2481*f7184619SJoshua M. Clulow 		else
2482*f7184619SJoshua M. Clulow 			prt_imm(dhp, sign_extend(f->f3a.simm13, 13),
2483*f7184619SJoshua M. Clulow 			    IMM_SIGNED);
2484*f7184619SJoshua M. Clulow 
2485*f7184619SJoshua M. Clulow 		if (p3 != 0)
2486*f7184619SJoshua M. Clulow 			(void) strlcat(dhx->dhx_buf, ", ", dhx->dhx_buflen);
2487*f7184619SJoshua M. Clulow 	}
2488*f7184619SJoshua M. Clulow 
2489*f7184619SJoshua M. Clulow 	if (p3 != 0)
2490*f7184619SJoshua M. Clulow 		(void) strlcat(dhx->dhx_buf, r3, dhx->dhx_buflen);
2491*f7184619SJoshua M. Clulow }
2492*f7184619SJoshua M. Clulow 
2493*f7184619SJoshua M. Clulow static const char *
get_asi_name(uint8_t asi)2494*f7184619SJoshua M. Clulow get_asi_name(uint8_t asi)
2495*f7184619SJoshua M. Clulow {
2496*f7184619SJoshua M. Clulow 	switch (asi) {
2497*f7184619SJoshua M. Clulow 		case 0x04:
2498*f7184619SJoshua M. Clulow 			return ("ASI_N");
2499*f7184619SJoshua M. Clulow 
2500*f7184619SJoshua M. Clulow 		case 0x0c:
2501*f7184619SJoshua M. Clulow 			return ("ASI_NL");
2502*f7184619SJoshua M. Clulow 
2503*f7184619SJoshua M. Clulow 		case 0x10:
2504*f7184619SJoshua M. Clulow 			return ("ASI_AIUP");
2505*f7184619SJoshua M. Clulow 
2506*f7184619SJoshua M. Clulow 		case 0x11:
2507*f7184619SJoshua M. Clulow 			return ("ASI_AIUS");
2508*f7184619SJoshua M. Clulow 
2509*f7184619SJoshua M. Clulow 		case 0x14:
2510*f7184619SJoshua M. Clulow 			return ("ASI_REAL");
2511*f7184619SJoshua M. Clulow 
2512*f7184619SJoshua M. Clulow 		case 0x15:
2513*f7184619SJoshua M. Clulow 			return ("ASI_REAL_IO");
2514*f7184619SJoshua M. Clulow 
2515*f7184619SJoshua M. Clulow 		case 0x16:
2516*f7184619SJoshua M. Clulow 			return ("ASI_BLK_AIUP");
2517*f7184619SJoshua M. Clulow 
2518*f7184619SJoshua M. Clulow 		case 0x17:
2519*f7184619SJoshua M. Clulow 			return ("ASI_BLK_AIUS");
2520*f7184619SJoshua M. Clulow 
2521*f7184619SJoshua M. Clulow 		case 0x18:
2522*f7184619SJoshua M. Clulow 			return ("ASI_AIUPL");
2523*f7184619SJoshua M. Clulow 
2524*f7184619SJoshua M. Clulow 		case 0x19:
2525*f7184619SJoshua M. Clulow 			return ("ASI_AIUSL");
2526*f7184619SJoshua M. Clulow 
2527*f7184619SJoshua M. Clulow 		case 0x1c:
2528*f7184619SJoshua M. Clulow 			return ("ASI_REAL_L");
2529*f7184619SJoshua M. Clulow 
2530*f7184619SJoshua M. Clulow 		case 0x1d:
2531*f7184619SJoshua M. Clulow 			return ("ASI_REAL_IO_L");
2532*f7184619SJoshua M. Clulow 
2533*f7184619SJoshua M. Clulow 		case 0x1e:
2534*f7184619SJoshua M. Clulow 			return ("ASI_BLK_AIUPL");
2535*f7184619SJoshua M. Clulow 
2536*f7184619SJoshua M. Clulow 		case 0x1f:
2537*f7184619SJoshua M. Clulow 			return ("ASI_BLK_AIUS_L");
2538*f7184619SJoshua M. Clulow 
2539*f7184619SJoshua M. Clulow 		case 0x20:
2540*f7184619SJoshua M. Clulow 			return ("ASI_SCRATCHPAD");
2541*f7184619SJoshua M. Clulow 
2542*f7184619SJoshua M. Clulow 		case 0x21:
2543*f7184619SJoshua M. Clulow 			return ("ASI_MMU_CONTEXTID");
2544*f7184619SJoshua M. Clulow 
2545*f7184619SJoshua M. Clulow 		case 0x22:
2546*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_AIUP");
2547*f7184619SJoshua M. Clulow 
2548*f7184619SJoshua M. Clulow 		case 0x23:
2549*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_AIUS");
2550*f7184619SJoshua M. Clulow 
2551*f7184619SJoshua M. Clulow 		case 0x25:
2552*f7184619SJoshua M. Clulow 			return ("ASI_QUEUE");
2553*f7184619SJoshua M. Clulow 
2554*f7184619SJoshua M. Clulow 		case 0x26:
2555*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_R");
2556*f7184619SJoshua M. Clulow 
2557*f7184619SJoshua M. Clulow 		case 0x27:
2558*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_N");
2559*f7184619SJoshua M. Clulow 
2560*f7184619SJoshua M. Clulow 		case 0x2a:
2561*f7184619SJoshua M. Clulow 			return ("ASI_LDTX_AIUPL");
2562*f7184619SJoshua M. Clulow 
2563*f7184619SJoshua M. Clulow 		case 0x2b:
2564*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_AIUS_L");
2565*f7184619SJoshua M. Clulow 
2566*f7184619SJoshua M. Clulow 		case 0x2e:
2567*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_REAL_L");
2568*f7184619SJoshua M. Clulow 
2569*f7184619SJoshua M. Clulow 		case 0x2f:
2570*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_NL");
2571*f7184619SJoshua M. Clulow 
2572*f7184619SJoshua M. Clulow 		case 0x30:
2573*f7184619SJoshua M. Clulow 			return ("ASI_AIPP");
2574*f7184619SJoshua M. Clulow 
2575*f7184619SJoshua M. Clulow 		case 0x31:
2576*f7184619SJoshua M. Clulow 			return ("ASI_AIPS");
2577*f7184619SJoshua M. Clulow 
2578*f7184619SJoshua M. Clulow 		case 0x36:
2579*f7184619SJoshua M. Clulow 			return ("ASI_AIPN");
2580*f7184619SJoshua M. Clulow 
2581*f7184619SJoshua M. Clulow 		case 0x38:
2582*f7184619SJoshua M. Clulow 			return ("ASI_AIPP_L");
2583*f7184619SJoshua M. Clulow 
2584*f7184619SJoshua M. Clulow 		case 0x39:
2585*f7184619SJoshua M. Clulow 			return ("ASI_AIPS_L");
2586*f7184619SJoshua M. Clulow 
2587*f7184619SJoshua M. Clulow 		case 0x3e:
2588*f7184619SJoshua M. Clulow 			return ("ASI_AIPN_L");
2589*f7184619SJoshua M. Clulow 
2590*f7184619SJoshua M. Clulow 		case 0x41:
2591*f7184619SJoshua M. Clulow 			return ("ASI_CMT_SHARED");
2592*f7184619SJoshua M. Clulow 
2593*f7184619SJoshua M. Clulow 		case 0x4f:
2594*f7184619SJoshua M. Clulow 			return ("ASI_HYP_SCRATCHPAD");
2595*f7184619SJoshua M. Clulow 
2596*f7184619SJoshua M. Clulow 		case 0x50:
2597*f7184619SJoshua M. Clulow 			return ("ASI_IMMU");
2598*f7184619SJoshua M. Clulow 
2599*f7184619SJoshua M. Clulow 		case 0x52:
2600*f7184619SJoshua M. Clulow 			return ("ASI_MMU_REAL");
2601*f7184619SJoshua M. Clulow 
2602*f7184619SJoshua M. Clulow 		case 0x54:
2603*f7184619SJoshua M. Clulow 			return ("ASI_MMU");
2604*f7184619SJoshua M. Clulow 
2605*f7184619SJoshua M. Clulow 		case 0x55:
2606*f7184619SJoshua M. Clulow 			return ("ASI_ITLB_DATA_ACCESS_REG");
2607*f7184619SJoshua M. Clulow 
2608*f7184619SJoshua M. Clulow 		case 0x56:
2609*f7184619SJoshua M. Clulow 			return ("ASI_ITLB_TAG_READ_REG");
2610*f7184619SJoshua M. Clulow 
2611*f7184619SJoshua M. Clulow 		case 0x57:
2612*f7184619SJoshua M. Clulow 			return ("ASI_IMMU_DEMAP");
2613*f7184619SJoshua M. Clulow 
2614*f7184619SJoshua M. Clulow 		case 0x58:
2615*f7184619SJoshua M. Clulow 			return ("ASI_DMMU / ASI_UMMU");
2616*f7184619SJoshua M. Clulow 
2617*f7184619SJoshua M. Clulow 		case 0x5c:
2618*f7184619SJoshua M. Clulow 			return ("ASI_DTLB_DATA_IN_REG");
2619*f7184619SJoshua M. Clulow 
2620*f7184619SJoshua M. Clulow 		case 0x5d:
2621*f7184619SJoshua M. Clulow 			return ("ASI_DTLB_DATA_ACCESS_REG");
2622*f7184619SJoshua M. Clulow 
2623*f7184619SJoshua M. Clulow 		case 0x5e:
2624*f7184619SJoshua M. Clulow 			return ("ASI_DTLB_TAG_READ_REG");
2625*f7184619SJoshua M. Clulow 
2626*f7184619SJoshua M. Clulow 		case 0x5f:
2627*f7184619SJoshua M. Clulow 			return ("ASI_DMMU_DEMAP");
2628*f7184619SJoshua M. Clulow 
2629*f7184619SJoshua M. Clulow 		case 0x63:
2630*f7184619SJoshua M. Clulow 			return ("ASI_CMT_PER_STRAND / ASI_CMT_PER_CORE");
2631*f7184619SJoshua M. Clulow 
2632*f7184619SJoshua M. Clulow 		case 0x80:
2633*f7184619SJoshua M. Clulow 			return ("ASI_P");
2634*f7184619SJoshua M. Clulow 
2635*f7184619SJoshua M. Clulow 		case 0x81:
2636*f7184619SJoshua M. Clulow 			return ("ASI_S");
2637*f7184619SJoshua M. Clulow 
2638*f7184619SJoshua M. Clulow 		case 0x82:
2639*f7184619SJoshua M. Clulow 			return ("ASI_PNF");
2640*f7184619SJoshua M. Clulow 
2641*f7184619SJoshua M. Clulow 		case 0x83:
2642*f7184619SJoshua M. Clulow 			return ("ASI_SNF");
2643*f7184619SJoshua M. Clulow 
2644*f7184619SJoshua M. Clulow 		case 0x88:
2645*f7184619SJoshua M. Clulow 			return ("ASI_PL");
2646*f7184619SJoshua M. Clulow 
2647*f7184619SJoshua M. Clulow 		case 0x89:
2648*f7184619SJoshua M. Clulow 			return ("ASI_SL");
2649*f7184619SJoshua M. Clulow 
2650*f7184619SJoshua M. Clulow 		case 0x8a:
2651*f7184619SJoshua M. Clulow 			return ("ASI_PNFL");
2652*f7184619SJoshua M. Clulow 
2653*f7184619SJoshua M. Clulow 		case 0x8b:
2654*f7184619SJoshua M. Clulow 			return ("ASI_SNFL");
2655*f7184619SJoshua M. Clulow 
2656*f7184619SJoshua M. Clulow 		case 0xc0:
2657*f7184619SJoshua M. Clulow 			return ("ASI_PST8_P");
2658*f7184619SJoshua M. Clulow 
2659*f7184619SJoshua M. Clulow 		case 0xc1:
2660*f7184619SJoshua M. Clulow 			return ("ASI_PST8_S");
2661*f7184619SJoshua M. Clulow 
2662*f7184619SJoshua M. Clulow 		case 0xc2:
2663*f7184619SJoshua M. Clulow 			return ("ASI_PST16_P");
2664*f7184619SJoshua M. Clulow 
2665*f7184619SJoshua M. Clulow 		case 0xc3:
2666*f7184619SJoshua M. Clulow 			return ("ASI_PST16_S");
2667*f7184619SJoshua M. Clulow 
2668*f7184619SJoshua M. Clulow 		case 0xc4:
2669*f7184619SJoshua M. Clulow 			return ("ASI_PST32_P");
2670*f7184619SJoshua M. Clulow 
2671*f7184619SJoshua M. Clulow 		case 0xc5:
2672*f7184619SJoshua M. Clulow 			return ("ASI_PST32_S");
2673*f7184619SJoshua M. Clulow 
2674*f7184619SJoshua M. Clulow 		case 0xc8:
2675*f7184619SJoshua M. Clulow 			return ("ASI_PST8_PL");
2676*f7184619SJoshua M. Clulow 
2677*f7184619SJoshua M. Clulow 		case 0xc9:
2678*f7184619SJoshua M. Clulow 			return ("ASI_PST8_SL");
2679*f7184619SJoshua M. Clulow 
2680*f7184619SJoshua M. Clulow 		case 0xca:
2681*f7184619SJoshua M. Clulow 			return ("ASI_PST16_PL");
2682*f7184619SJoshua M. Clulow 
2683*f7184619SJoshua M. Clulow 		case 0xcb:
2684*f7184619SJoshua M. Clulow 			return ("ASI_PST16_SL");
2685*f7184619SJoshua M. Clulow 
2686*f7184619SJoshua M. Clulow 		case 0xcc:
2687*f7184619SJoshua M. Clulow 			return ("ASI_PST32_PL");
2688*f7184619SJoshua M. Clulow 
2689*f7184619SJoshua M. Clulow 		case 0xcd:
2690*f7184619SJoshua M. Clulow 			return ("ASI_PST32_SL");
2691*f7184619SJoshua M. Clulow 
2692*f7184619SJoshua M. Clulow 		case 0xd0:
2693*f7184619SJoshua M. Clulow 			return ("ASI_FL8_P");
2694*f7184619SJoshua M. Clulow 
2695*f7184619SJoshua M. Clulow 		case 0xd1:
2696*f7184619SJoshua M. Clulow 			return ("ASI_FL8_S");
2697*f7184619SJoshua M. Clulow 
2698*f7184619SJoshua M. Clulow 		case 0xd2:
2699*f7184619SJoshua M. Clulow 			return ("ASI_FL16_P");
2700*f7184619SJoshua M. Clulow 
2701*f7184619SJoshua M. Clulow 		case 0xd3:
2702*f7184619SJoshua M. Clulow 			return ("ASI_FL16_S");
2703*f7184619SJoshua M. Clulow 
2704*f7184619SJoshua M. Clulow 		case 0xd8:
2705*f7184619SJoshua M. Clulow 			return ("ASI_FL8_PL");
2706*f7184619SJoshua M. Clulow 
2707*f7184619SJoshua M. Clulow 		case 0xd9:
2708*f7184619SJoshua M. Clulow 			return ("ASI_FL8_SL");
2709*f7184619SJoshua M. Clulow 
2710*f7184619SJoshua M. Clulow 		case 0xda:
2711*f7184619SJoshua M. Clulow 			return ("ASI_FL16_PL");
2712*f7184619SJoshua M. Clulow 
2713*f7184619SJoshua M. Clulow 		case 0xdb:
2714*f7184619SJoshua M. Clulow 			return ("ASI_FL16_SL");
2715*f7184619SJoshua M. Clulow 
2716*f7184619SJoshua M. Clulow 		case 0xe0:
2717*f7184619SJoshua M. Clulow 			return ("ASI_BLK_COMMIT_P");
2718*f7184619SJoshua M. Clulow 
2719*f7184619SJoshua M. Clulow 		case 0xe1:
2720*f7184619SJoshua M. Clulow 			return ("ASI_BLK_SOMMIT_S");
2721*f7184619SJoshua M. Clulow 
2722*f7184619SJoshua M. Clulow 		case 0xe2:
2723*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_P");
2724*f7184619SJoshua M. Clulow 
2725*f7184619SJoshua M. Clulow 		case 0xe3:
2726*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_S");
2727*f7184619SJoshua M. Clulow 
2728*f7184619SJoshua M. Clulow 		case 0xea:
2729*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_PL");
2730*f7184619SJoshua M. Clulow 
2731*f7184619SJoshua M. Clulow 		case 0xeb:
2732*f7184619SJoshua M. Clulow 			return ("ASI_TWINX_SL");
2733*f7184619SJoshua M. Clulow 
2734*f7184619SJoshua M. Clulow 		case 0xf0:
2735*f7184619SJoshua M. Clulow 			return ("ASI_BLK_P");
2736*f7184619SJoshua M. Clulow 
2737*f7184619SJoshua M. Clulow 		case 0xf1:
2738*f7184619SJoshua M. Clulow 			return ("ASI_BLK_S");
2739*f7184619SJoshua M. Clulow 
2740*f7184619SJoshua M. Clulow 		case 0xf8:
2741*f7184619SJoshua M. Clulow 			return ("ASI_BLK_PL");
2742*f7184619SJoshua M. Clulow 
2743*f7184619SJoshua M. Clulow 		case 0xf9:
2744*f7184619SJoshua M. Clulow 			return ("ASI_BLK_SL");
2745*f7184619SJoshua M. Clulow 
2746*f7184619SJoshua M. Clulow 		default:
2747*f7184619SJoshua M. Clulow 			return (NULL);
2748*f7184619SJoshua M. Clulow 	}
2749*f7184619SJoshua M. Clulow }
2750*f7184619SJoshua M. Clulow 
2751*f7184619SJoshua M. Clulow /*
2752*f7184619SJoshua M. Clulow  * just a handy function that takes care of managing the buffer length
2753*f7184619SJoshua M. Clulow  * w/ printf
2754*f7184619SJoshua M. Clulow  */
2755*f7184619SJoshua M. Clulow 
2756*f7184619SJoshua M. Clulow /*
2757*f7184619SJoshua M. Clulow  * PRINTF LIKE 1
2758*f7184619SJoshua M. Clulow  */
2759*f7184619SJoshua M. Clulow static void
bprintf(dis_handle_t * dhp,const char * fmt,...)2760*f7184619SJoshua M. Clulow bprintf(dis_handle_t *dhp, const char *fmt, ...)
2761*f7184619SJoshua M. Clulow {
2762*f7184619SJoshua M. Clulow 	dis_handle_sparc_t *dhx = dhp->dh_arch_private;
2763*f7184619SJoshua M. Clulow 	size_t curlen;
2764*f7184619SJoshua M. Clulow 	va_list ap;
2765*f7184619SJoshua M. Clulow 
2766*f7184619SJoshua M. Clulow 	curlen = strlen(dhx->dhx_buf);
2767*f7184619SJoshua M. Clulow 
2768*f7184619SJoshua M. Clulow 	va_start(ap, fmt);
2769*f7184619SJoshua M. Clulow 	(void) dis_vsnprintf(dhx->dhx_buf + curlen, dhx->dhx_buflen -
2770*f7184619SJoshua M. Clulow 	    curlen, fmt, ap);
2771*f7184619SJoshua M. Clulow 	va_end(ap);
2772*f7184619SJoshua M. Clulow }
2773