4 * Copyright (c) 2000-2003 Marcel Moolenaar
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 /* __FBSDID("$FreeBSD: src/sys/ia64/disasm/disasm_format.c,v 1.2 2005/01/06 22:18:22 imp Exp $"); */
34 #include <sys/param.h>
35 #include <sys/systm.h>
39 #include <ia64/disasm/disasm_int.h>
40 #include <ia64/disasm/disasm.h>
43 * Mnemonics (keep in sync with enum asm_op).
45 static const char *asm_mnemonics
[] = {
47 "add", "addl", "addp4", "adds", "alloc", "and", "andcm",
48 "br", "break", "brl", "brp", "bsw",
49 "chk", "clrrrb", "cmp", "cmp4", "cmp8xchg16", "cmpxchg1", "cmpxchg2",
50 "cmpxchg4", "cmpxchg8", "cover", "czx1", "czx2",
53 "famax", "famin", "fand", "fandcm", "fc", "fchkf", "fclass", "fclrf",
54 "fcmp", "fcvt", "fetchadd4", "fetchadd8", "flushrs", "fma", "fmax",
55 "fmerge", "fmin", "fmix", "fms", "fnma", "for", "fpack", "fpamax",
56 "fpamin", "fpcmp", "fpcvt", "fpma", "fpmax", "fpmerge", "fpmin",
57 "fpms", "fpnma", "fprcpa", "fprsqrta", "frcpa", "frsqrta", "fselect",
58 "fsetc", "fswap", "fsxt", "fwb", "fxor",
60 "invala", "itc", "itr",
61 "ld1", "ld16", "ld2", "ld4", "ld8", "ldf", "ldf8", "ldfd", "ldfe",
62 "ldfp8", "ldfpd", "ldfps", "ldfs", "lfetch", "loadrs",
63 "mf", "mix1", "mix2", "mix4", "mov", "movl", "mux1", "mux2",
66 "pack2", "pack4", "padd1", "padd2", "padd4", "pavg1", "pavg2",
67 "pavgsub1", "pavgsub2", "pcmp1", "pcmp2", "pcmp4", "pmax1", "pmax2",
68 "pmin1", "pmin2", "pmpy2", "pmpyshr2", "popcnt", "probe", "psad1",
69 "pshl2", "pshl4", "pshladd2", "pshr2", "pshr4", "pshradd2", "psub1",
70 "psub2", "psub4", "ptc", "ptr",
72 "setf", "shl", "shladd", "shladdp4", "shr", "shrp", "srlz", "ssm",
73 "st1", "st16", "st2", "st4", "st8", "stf", "stf8", "stfd", "stfe",
74 "stfs", "sub", "sum", "sxt1", "sxt2", "sxt4", "sync",
75 "tak", "tbit", "thash", "tnat", "tpa", "ttag",
76 "unpack1", "unpack2", "unpack4",
77 "xchg1", "xchg2", "xchg4", "xchg8", "xma", "xor",
78 "zxt1", "zxt2", "zxt4"
82 * Completers (keep in sync with enum asm_cmpltr_type).
84 static const char *asm_completers
[] = {
89 ".c.clr", ".c.clr.acq", ".c.nc", ".call", ".cexit", ".cloop", ".clr",
91 ".d", ".dc.dc", ".dc.nt", ".dpnt", ".dptk",
92 ".e", ".eq", ".excl", ".exit", ".exp",
93 ".f", ".fault", ".few", ".fill", ".fx", ".fxu",
94 ".g", ".ga", ".ge", ".gt",
97 ".l", ".le", ".loop", ".lr", ".lt", ".ltu",
99 ".nc", ".ne", ".neq", ".nl", ".nle", ".nlt", ".nm", ".nr", ".ns",
100 ".nt.dc", ".nt.nt", ".nt.tk", ".nt1", ".nt2", ".nta", ".nz",
101 ".or", ".or.andcm", ".ord",
103 ".r", ".raz", ".rel", ".ret", ".rw",
104 ".s", ".s0", ".s1", ".s2", ".s3", ".sa", ".se", ".sig", ".spill",
105 ".spnt", ".sptk", ".sss",
106 ".tk.dc", ".tk.nt", ".tk.tk", ".trunc",
107 ".u", ".unc", ".unord", ".uss", ".uus", ".uuu",
108 ".w", ".wexit", ".wtop",
114 asm_completer(const struct asm_cmpltr
*c
, char *buf
)
116 strcpy(buf
, asm_completers
[c
->c_type
]);
120 asm_mnemonic(enum asm_op op
, char *buf
)
122 strcpy(buf
, asm_mnemonics
[(op
< ASM_OP_INTERNAL_OPCODES
) ? op
: 0]);
126 asm_operand(const struct asm_oper
*o
, char *buf
, uint64_t ip
)
133 switch ((int)o
->o_value
) {
134 case AR_K0
: n
= "k0"; break;
135 case AR_K1
: n
= "k1"; break;
136 case AR_K2
: n
= "k2"; break;
137 case AR_K3
: n
= "k3"; break;
138 case AR_K4
: n
= "k4"; break;
139 case AR_K5
: n
= "k5"; break;
140 case AR_K6
: n
= "k6"; break;
141 case AR_K7
: n
= "k7"; break;
142 case AR_RSC
: n
= "rsc"; break;
143 case AR_BSP
: n
= "bsp"; break;
144 case AR_BSPSTORE
: n
= "bspstore"; break;
145 case AR_RNAT
: n
= "rnat"; break;
146 case AR_FCR
: n
= "fcr"; break;
147 case AR_EFLAG
: n
= "eflag"; break;
148 case AR_CSD
: n
= "csd"; break;
149 case AR_SSD
: n
= "ssd"; break;
150 case AR_CFLG
: n
= "cflg"; break;
151 case AR_FSR
: n
= "fsr"; break;
152 case AR_FIR
: n
= "fir"; break;
153 case AR_FDR
: n
= "fdr"; break;
154 case AR_CCV
: n
= "ccv"; break;
155 case AR_UNAT
: n
= "unat"; break;
156 case AR_FPSR
: n
= "fpsr"; break;
157 case AR_ITC
: n
= "itc"; break;
158 case AR_PFS
: n
= "pfs"; break;
159 case AR_LC
: n
= "lc"; break;
160 case AR_EC
: n
= "ec"; break;
162 sprintf(buf
, "ar%d", (int)o
->o_value
);
165 sprintf(buf
, "ar.%s", n
);
169 sprintf(buf
, "b%d", (int)o
->o_value
);
177 switch ((int)o
->o_value
) {
178 case CR_DCR
: n
= "dcr"; break;
179 case CR_ITM
: n
= "itm"; break;
180 case CR_IVA
: n
= "iva"; break;
181 case CR_PTA
: n
= "pta"; break;
182 case CR_IPSR
: n
= "ipsr"; break;
183 case CR_ISR
: n
= "isr"; break;
184 case CR_IIP
: n
= "iip"; break;
185 case CR_IFA
: n
= "ifa"; break;
186 case CR_ITIR
: n
= "itir"; break;
187 case CR_IIPA
: n
= "iipa"; break;
188 case CR_IFS
: n
= "ifs"; break;
189 case CR_IIM
: n
= "iim"; break;
190 case CR_IHA
: n
= "iha"; break;
191 case CR_LID
: n
= "lid"; break;
192 case CR_IVR
: n
= "ivr"; break;
193 case CR_TPR
: n
= "tpr"; break;
194 case CR_EOI
: n
= "eoi"; break;
195 case CR_IRR0
: n
= "irr0"; break;
196 case CR_IRR1
: n
= "irr1"; break;
197 case CR_IRR2
: n
= "irr2"; break;
198 case CR_IRR3
: n
= "irr3"; break;
199 case CR_ITV
: n
= "itv"; break;
200 case CR_PMV
: n
= "pmv"; break;
201 case CR_CMCV
: n
= "cmcv"; break;
202 case CR_LRR0
: n
= "lrr0"; break;
203 case CR_LRR1
: n
= "lrr1"; break;
205 sprintf(buf
, "cr%d", (int)o
->o_value
);
208 sprintf(buf
, "cr.%s", n
);
214 sprintf(buf
, "%lx", ip
+ o
->o_value
);
220 sprintf(buf
, "f%d", (int)o
->o_value
);
228 sprintf(buf
, "0x%lx", o
->o_value
);
254 case ASM_OPER_PR_ROT
:
255 strcpy(buf
, "pr.rot");
258 sprintf(buf
, "p%d", (int)o
->o_value
);
264 strcpy(buf
, "psr.l");
266 case ASM_OPER_PSR_UM
:
267 strcpy(buf
, "psr.um");
277 buf
+= sprintf(buf
, "%s[", n
);
278 switch ((int)o
->o_value
) {
279 case 1: strcpy(buf
, "gp"); buf
+= 2; break;
280 case 12: strcpy(buf
, "sp"); buf
+= 2; break;
281 case 13: strcpy(buf
, "tp"); buf
+= 2; break;
282 default: buf
+= sprintf(buf
, "r%d", (int)o
->o_value
); break;
289 asm_print_bundle(const struct asm_bundle
*b
, uint64_t ip
)
291 asm_print_inst(b
, 0, ip
);
292 asm_print_inst(b
, 1, ip
);
293 asm_print_inst(b
, 2, ip
);
297 asm_print_inst(const struct asm_bundle
*b
, int slot
, uint64_t ip
)
300 const struct asm_inst
*i
;
304 tmpl
= b
->b_templ
+ slot
;
305 if (*tmpl
== ';' || (slot
== 2 && b
->b_templ
[1] == ';'))
307 i
= b
->b_inst
+ slot
;
308 if (*tmpl
== 'L' || i
->i_op
== ASM_OP_NONE
)
311 /* Address + slot. */
312 printf("%lx[%c] ", ip
+ slot
, *tmpl
);
315 if (i
->i_oper
[0].o_value
!= 0) {
316 asm_operand(i
->i_oper
+0, buf
, ip
);
324 /* Mnemonic & completers. */
325 asm_mnemonic(i
->i_op
, buf
);
329 while (n
< i
->i_ncmpltrs
) {
330 asm_completer(i
->i_cmpltr
+ n
, buf
);
341 while (n
< 7 && i
->i_oper
[n
].o_type
!= ASM_OPER_NONE
) {
343 if (n
== i
->i_srcidx
)
348 asm_operand(i
->i_oper
+ n
, buf
, ip
);