10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
23*265Smws * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <strings.h>
300Sstevel@tonic-gate #include <stdio.h>
31*265Smws
32*265Smws #include <dt_impl.h>
330Sstevel@tonic-gate #include <dt_ident.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate /*ARGSUSED*/
360Sstevel@tonic-gate static void
dt_dis_log(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)370Sstevel@tonic-gate dt_dis_log(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate (void) fprintf(fp, "%-4s %%r%u, %%r%u, %%r%u", name,
400Sstevel@tonic-gate DIF_INSTR_R1(in), DIF_INSTR_R2(in), DIF_INSTR_RD(in));
410Sstevel@tonic-gate }
420Sstevel@tonic-gate
430Sstevel@tonic-gate /*ARGSUSED*/
440Sstevel@tonic-gate static void
dt_dis_branch(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)450Sstevel@tonic-gate dt_dis_branch(const dtrace_difo_t *dp, const char *name,
460Sstevel@tonic-gate dif_instr_t in, FILE *fp)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate (void) fprintf(fp, "%-4s %u", name, DIF_INSTR_LABEL(in));
490Sstevel@tonic-gate }
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*ARGSUSED*/
520Sstevel@tonic-gate static void
dt_dis_load(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)530Sstevel@tonic-gate dt_dis_load(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate (void) fprintf(fp, "%-4s [%%r%u], %%r%u", name,
560Sstevel@tonic-gate DIF_INSTR_R1(in), DIF_INSTR_RD(in));
570Sstevel@tonic-gate }
580Sstevel@tonic-gate
590Sstevel@tonic-gate /*ARGSUSED*/
600Sstevel@tonic-gate static void
dt_dis_store(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)610Sstevel@tonic-gate dt_dis_store(const dtrace_difo_t *dp, const char *name,
620Sstevel@tonic-gate dif_instr_t in, FILE *fp)
630Sstevel@tonic-gate {
640Sstevel@tonic-gate (void) fprintf(fp, "%-4s %%r%u, [%%r%u]", name,
650Sstevel@tonic-gate DIF_INSTR_R1(in), DIF_INSTR_RD(in));
660Sstevel@tonic-gate }
670Sstevel@tonic-gate
680Sstevel@tonic-gate /*ARGSUSED*/
690Sstevel@tonic-gate static void
dt_dis_str(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)700Sstevel@tonic-gate dt_dis_str(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate (void) fprintf(fp, "%s", name);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate /*ARGSUSED*/
760Sstevel@tonic-gate static void
dt_dis_r1rd(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)770Sstevel@tonic-gate dt_dis_r1rd(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
780Sstevel@tonic-gate {
790Sstevel@tonic-gate (void) fprintf(fp, "%-4s %%r%u, %%r%u", name,
800Sstevel@tonic-gate DIF_INSTR_R1(in), DIF_INSTR_RD(in));
810Sstevel@tonic-gate }
820Sstevel@tonic-gate
830Sstevel@tonic-gate /*ARGSUSED*/
840Sstevel@tonic-gate static void
dt_dis_cmp(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)850Sstevel@tonic-gate dt_dis_cmp(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate (void) fprintf(fp, "%-4s %%r%u, %%r%u", name,
880Sstevel@tonic-gate DIF_INSTR_R1(in), DIF_INSTR_R2(in));
890Sstevel@tonic-gate }
900Sstevel@tonic-gate
910Sstevel@tonic-gate /*ARGSUSED*/
920Sstevel@tonic-gate static void
dt_dis_tst(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)930Sstevel@tonic-gate dt_dis_tst(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate (void) fprintf(fp, "%-4s %%r%u", name, DIF_INSTR_R1(in));
960Sstevel@tonic-gate }
970Sstevel@tonic-gate
980Sstevel@tonic-gate static const char *
dt_dis_varname(const dtrace_difo_t * dp,uint_t id,uint_t scope)990Sstevel@tonic-gate dt_dis_varname(const dtrace_difo_t *dp, uint_t id, uint_t scope)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate const dtrace_difv_t *dvp = dp->dtdo_vartab;
1020Sstevel@tonic-gate uint_t i;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate for (i = 0; i < dp->dtdo_varlen; i++, dvp++) {
1050Sstevel@tonic-gate if (dvp->dtdv_id == id && dvp->dtdv_scope == scope) {
1060Sstevel@tonic-gate if (dvp->dtdv_name < dp->dtdo_strlen)
1070Sstevel@tonic-gate return (dp->dtdo_strtab + dvp->dtdv_name);
1080Sstevel@tonic-gate break;
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate return (NULL);
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate static uint_t
dt_dis_scope(const char * name)1160Sstevel@tonic-gate dt_dis_scope(const char *name)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate switch (name[2]) {
1190Sstevel@tonic-gate case 'l': return (DIFV_SCOPE_LOCAL);
1200Sstevel@tonic-gate case 't': return (DIFV_SCOPE_THREAD);
1210Sstevel@tonic-gate case 'g': return (DIFV_SCOPE_GLOBAL);
1220Sstevel@tonic-gate default: return (-1u);
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate static void
dt_dis_lda(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)1270Sstevel@tonic-gate dt_dis_lda(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate uint_t var = DIF_INSTR_R1(in);
1300Sstevel@tonic-gate const char *vname;
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate (void) fprintf(fp, "%-4s DT_VAR(%u), %%r%u, %%r%u", name,
1330Sstevel@tonic-gate var, DIF_INSTR_R2(in), DIF_INSTR_RD(in));
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL)
1360Sstevel@tonic-gate (void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate static void
dt_dis_ldv(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)1400Sstevel@tonic-gate dt_dis_ldv(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate uint_t var = DIF_INSTR_VAR(in);
1430Sstevel@tonic-gate const char *vname;
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate (void) fprintf(fp, "%-4s DT_VAR(%u), %%r%u",
1460Sstevel@tonic-gate name, var, DIF_INSTR_RD(in));
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL)
1490Sstevel@tonic-gate (void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate static void
dt_dis_stv(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)1530Sstevel@tonic-gate dt_dis_stv(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate uint_t var = DIF_INSTR_VAR(in);
1560Sstevel@tonic-gate const char *vname;
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate (void) fprintf(fp, "%-4s %%r%u, DT_VAR(%u)",
1590Sstevel@tonic-gate name, DIF_INSTR_RS(in), var);
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL)
1620Sstevel@tonic-gate (void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname);
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate static void
dt_dis_setx(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)1660Sstevel@tonic-gate dt_dis_setx(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1670Sstevel@tonic-gate {
1680Sstevel@tonic-gate uint_t intptr = DIF_INSTR_INTEGER(in);
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate (void) fprintf(fp, "%-4s DT_INTEGER[%u], %%r%u", name,
1710Sstevel@tonic-gate intptr, DIF_INSTR_RD(in));
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate if (intptr < dp->dtdo_intlen) {
1740Sstevel@tonic-gate (void) fprintf(fp, "\t\t! 0x%llx",
1750Sstevel@tonic-gate (u_longlong_t)dp->dtdo_inttab[intptr]);
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate static void
dt_dis_sets(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)1800Sstevel@tonic-gate dt_dis_sets(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1810Sstevel@tonic-gate {
1820Sstevel@tonic-gate uint_t strptr = DIF_INSTR_STRING(in);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate (void) fprintf(fp, "%-4s DT_STRING[%u], %%r%u", name,
1850Sstevel@tonic-gate strptr, DIF_INSTR_RD(in));
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate if (strptr < dp->dtdo_strlen)
1880Sstevel@tonic-gate (void) fprintf(fp, "\t\t! \"%s\"", dp->dtdo_strtab + strptr);
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate /*ARGSUSED*/
1920Sstevel@tonic-gate static void
dt_dis_ret(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)1930Sstevel@tonic-gate dt_dis_ret(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
1940Sstevel@tonic-gate {
1950Sstevel@tonic-gate (void) fprintf(fp, "%-4s %%r%u", name, DIF_INSTR_RD(in));
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate /*ARGSUSED*/
1990Sstevel@tonic-gate static void
dt_dis_call(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)2000Sstevel@tonic-gate dt_dis_call(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp)
2010Sstevel@tonic-gate {
202*265Smws uint_t subr = DIF_INSTR_SUBR(in);
2030Sstevel@tonic-gate
204*265Smws (void) fprintf(fp, "%-4s DIF_SUBR(%u), %%r%u\t\t! %s",
205*265Smws name, subr, DIF_INSTR_RD(in), dtrace_subrstr(NULL, subr));
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate /*ARGSUSED*/
2090Sstevel@tonic-gate static void
dt_dis_pushts(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)210*265Smws dt_dis_pushts(const dtrace_difo_t *dp,
211*265Smws const char *name, dif_instr_t in, FILE *fp)
2120Sstevel@tonic-gate {
2130Sstevel@tonic-gate static const char *const tnames[] = { "D type", "string" };
2140Sstevel@tonic-gate uint_t type = DIF_INSTR_TYPE(in);
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate (void) fprintf(fp, "%-4s DT_TYPE(%u), %%r%u, %%r%u",
2170Sstevel@tonic-gate name, type, DIF_INSTR_R2(in), DIF_INSTR_RS(in));
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate if (type < sizeof (tnames) / sizeof (tnames[0]))
2200Sstevel@tonic-gate (void) fprintf(fp, "\t! DT_TYPE(%u) = %s", type, tnames[type]);
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate
223*265Smws static void
dt_dis_xlate(const dtrace_difo_t * dp,const char * name,dif_instr_t in,FILE * fp)224*265Smws dt_dis_xlate(const dtrace_difo_t *dp,
225*265Smws const char *name, dif_instr_t in, FILE *fp)
226*265Smws {
227*265Smws uint_t xlr = DIF_INSTR_XLREF(in);
228*265Smws
229*265Smws (void) fprintf(fp, "%-4s DT_XLREF[%u], %%r%u",
230*265Smws name, xlr, DIF_INSTR_RD(in));
231*265Smws
232*265Smws if (xlr < dp->dtdo_xlmlen) {
233*265Smws (void) fprintf(fp, "\t\t! DT_XLREF[%u] = %u.%s", xlr,
234*265Smws (uint_t)dp->dtdo_xlmtab[xlr]->dn_membexpr->dn_xlator->dx_id,
235*265Smws dp->dtdo_xlmtab[xlr]->dn_membname);
236*265Smws }
237*265Smws }
238*265Smws
2390Sstevel@tonic-gate static char *
dt_dis_typestr(const dtrace_diftype_t * t,char * buf,size_t len)2400Sstevel@tonic-gate dt_dis_typestr(const dtrace_diftype_t *t, char *buf, size_t len)
2410Sstevel@tonic-gate {
2420Sstevel@tonic-gate char kind[16], ckind[16];
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate switch (t->dtdt_kind) {
2450Sstevel@tonic-gate case DIF_TYPE_CTF:
2460Sstevel@tonic-gate (void) strcpy(kind, "D type");
2470Sstevel@tonic-gate break;
2480Sstevel@tonic-gate case DIF_TYPE_STRING:
2490Sstevel@tonic-gate (void) strcpy(kind, "string");
2500Sstevel@tonic-gate break;
2510Sstevel@tonic-gate default:
2520Sstevel@tonic-gate (void) snprintf(kind, sizeof (kind), "0x%x", t->dtdt_kind);
2530Sstevel@tonic-gate }
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate switch (t->dtdt_ckind) {
2560Sstevel@tonic-gate case CTF_K_UNKNOWN:
2570Sstevel@tonic-gate (void) strcpy(ckind, "unknown");
2580Sstevel@tonic-gate break;
2590Sstevel@tonic-gate case CTF_K_INTEGER:
2600Sstevel@tonic-gate (void) strcpy(ckind, "integer");
2610Sstevel@tonic-gate break;
2620Sstevel@tonic-gate case CTF_K_FLOAT:
2630Sstevel@tonic-gate (void) strcpy(ckind, "float");
2640Sstevel@tonic-gate break;
2650Sstevel@tonic-gate case CTF_K_POINTER:
2660Sstevel@tonic-gate (void) strcpy(ckind, "pointer");
2670Sstevel@tonic-gate break;
2680Sstevel@tonic-gate case CTF_K_ARRAY:
2690Sstevel@tonic-gate (void) strcpy(ckind, "array");
2700Sstevel@tonic-gate break;
2710Sstevel@tonic-gate case CTF_K_FUNCTION:
2720Sstevel@tonic-gate (void) strcpy(ckind, "function");
2730Sstevel@tonic-gate break;
2740Sstevel@tonic-gate case CTF_K_STRUCT:
2750Sstevel@tonic-gate (void) strcpy(ckind, "struct");
2760Sstevel@tonic-gate break;
2770Sstevel@tonic-gate case CTF_K_UNION:
2780Sstevel@tonic-gate (void) strcpy(ckind, "union");
2790Sstevel@tonic-gate break;
2800Sstevel@tonic-gate case CTF_K_ENUM:
2810Sstevel@tonic-gate (void) strcpy(ckind, "enum");
2820Sstevel@tonic-gate break;
2830Sstevel@tonic-gate case CTF_K_FORWARD:
2840Sstevel@tonic-gate (void) strcpy(ckind, "forward");
2850Sstevel@tonic-gate break;
2860Sstevel@tonic-gate case CTF_K_TYPEDEF:
2870Sstevel@tonic-gate (void) strcpy(ckind, "typedef");
2880Sstevel@tonic-gate break;
2890Sstevel@tonic-gate case CTF_K_VOLATILE:
2900Sstevel@tonic-gate (void) strcpy(ckind, "volatile");
2910Sstevel@tonic-gate break;
2920Sstevel@tonic-gate case CTF_K_CONST:
2930Sstevel@tonic-gate (void) strcpy(ckind, "const");
2940Sstevel@tonic-gate break;
2950Sstevel@tonic-gate case CTF_K_RESTRICT:
2960Sstevel@tonic-gate (void) strcpy(ckind, "restrict");
2970Sstevel@tonic-gate break;
2980Sstevel@tonic-gate default:
2990Sstevel@tonic-gate (void) snprintf(ckind, sizeof (ckind), "0x%x", t->dtdt_ckind);
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate if (t->dtdt_flags & DIF_TF_BYREF) {
3030Sstevel@tonic-gate (void) snprintf(buf, len, "%s (%s) by ref (size %lu)",
3040Sstevel@tonic-gate kind, ckind, (ulong_t)t->dtdt_size);
3050Sstevel@tonic-gate } else {
3060Sstevel@tonic-gate (void) snprintf(buf, len, "%s (%s) (size %lu)",
3070Sstevel@tonic-gate kind, ckind, (ulong_t)t->dtdt_size);
3080Sstevel@tonic-gate }
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate return (buf);
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate
3130Sstevel@tonic-gate static void
dt_dis_rtab(const char * rtag,const dtrace_difo_t * dp,FILE * fp,const dof_relodesc_t * rp,uint32_t len)3140Sstevel@tonic-gate dt_dis_rtab(const char *rtag, const dtrace_difo_t *dp, FILE *fp,
3150Sstevel@tonic-gate const dof_relodesc_t *rp, uint32_t len)
3160Sstevel@tonic-gate {
3170Sstevel@tonic-gate (void) fprintf(fp, "\n%-4s %-8s %-8s %s\n",
3180Sstevel@tonic-gate rtag, "OFFSET", "DATA", "NAME");
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate for (; len != 0; len--, rp++) {
3210Sstevel@tonic-gate (void) fprintf(fp, "%-4u %-8llu %-8llu %s\n",
3220Sstevel@tonic-gate rp->dofr_type, (u_longlong_t)rp->dofr_offset,
3230Sstevel@tonic-gate (u_longlong_t)rp->dofr_data,
3240Sstevel@tonic-gate &dp->dtdo_strtab[rp->dofr_name]);
3250Sstevel@tonic-gate }
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate
3280Sstevel@tonic-gate void
dt_dis(const dtrace_difo_t * dp,FILE * fp)329*265Smws dt_dis(const dtrace_difo_t *dp, FILE *fp)
3300Sstevel@tonic-gate {
3310Sstevel@tonic-gate static const struct opent {
3320Sstevel@tonic-gate const char *op_name;
3330Sstevel@tonic-gate void (*op_func)(const dtrace_difo_t *, const char *,
3340Sstevel@tonic-gate dif_instr_t, FILE *);
3350Sstevel@tonic-gate } optab[] = {
3360Sstevel@tonic-gate { "(illegal opcode)", dt_dis_str },
3370Sstevel@tonic-gate { "or", dt_dis_log }, /* DIF_OP_OR */
3380Sstevel@tonic-gate { "xor", dt_dis_log }, /* DIF_OP_XOR */
3390Sstevel@tonic-gate { "and", dt_dis_log }, /* DIF_OP_AND */
3400Sstevel@tonic-gate { "sll", dt_dis_log }, /* DIF_OP_SLL */
3410Sstevel@tonic-gate { "srl", dt_dis_log }, /* DIF_OP_SRL */
3420Sstevel@tonic-gate { "sub", dt_dis_log }, /* DIF_OP_SUB */
3430Sstevel@tonic-gate { "add", dt_dis_log }, /* DIF_OP_ADD */
3440Sstevel@tonic-gate { "mul", dt_dis_log }, /* DIF_OP_MUL */
3450Sstevel@tonic-gate { "sdiv", dt_dis_log }, /* DIF_OP_SDIV */
3460Sstevel@tonic-gate { "udiv", dt_dis_log }, /* DIF_OP_UDIV */
3470Sstevel@tonic-gate { "srem", dt_dis_log }, /* DIF_OP_SREM */
3480Sstevel@tonic-gate { "urem", dt_dis_log }, /* DIF_OP_UREM */
3490Sstevel@tonic-gate { "not", dt_dis_r1rd }, /* DIF_OP_NOT */
3500Sstevel@tonic-gate { "mov", dt_dis_r1rd }, /* DIF_OP_MOV */
3510Sstevel@tonic-gate { "cmp", dt_dis_cmp }, /* DIF_OP_CMP */
3520Sstevel@tonic-gate { "tst", dt_dis_tst }, /* DIF_OP_TST */
3530Sstevel@tonic-gate { "ba", dt_dis_branch }, /* DIF_OP_BA */
3540Sstevel@tonic-gate { "be", dt_dis_branch }, /* DIF_OP_BE */
3550Sstevel@tonic-gate { "bne", dt_dis_branch }, /* DIF_OP_BNE */
3560Sstevel@tonic-gate { "bg", dt_dis_branch }, /* DIF_OP_BG */
3570Sstevel@tonic-gate { "bgu", dt_dis_branch }, /* DIF_OP_BGU */
3580Sstevel@tonic-gate { "bge", dt_dis_branch }, /* DIF_OP_BGE */
3590Sstevel@tonic-gate { "bgeu", dt_dis_branch }, /* DIF_OP_BGEU */
3600Sstevel@tonic-gate { "bl", dt_dis_branch }, /* DIF_OP_BL */
3610Sstevel@tonic-gate { "blu", dt_dis_branch }, /* DIF_OP_BLU */
3620Sstevel@tonic-gate { "ble", dt_dis_branch }, /* DIF_OP_BLE */
3630Sstevel@tonic-gate { "bleu", dt_dis_branch }, /* DIF_OP_BLEU */
3640Sstevel@tonic-gate { "ldsb", dt_dis_load }, /* DIF_OP_LDSB */
3650Sstevel@tonic-gate { "ldsh", dt_dis_load }, /* DIF_OP_LDSH */
3660Sstevel@tonic-gate { "ldsw", dt_dis_load }, /* DIF_OP_LDSW */
3670Sstevel@tonic-gate { "ldub", dt_dis_load }, /* DIF_OP_LDUB */
3680Sstevel@tonic-gate { "lduh", dt_dis_load }, /* DIF_OP_LDUH */
3690Sstevel@tonic-gate { "lduw", dt_dis_load }, /* DIF_OP_LDUW */
3700Sstevel@tonic-gate { "ldx", dt_dis_load }, /* DIF_OP_LDX */
3710Sstevel@tonic-gate { "ret", dt_dis_ret }, /* DIF_OP_RET */
3720Sstevel@tonic-gate { "nop", dt_dis_str }, /* DIF_OP_NOP */
3730Sstevel@tonic-gate { "setx", dt_dis_setx }, /* DIF_OP_SETX */
3740Sstevel@tonic-gate { "sets", dt_dis_sets }, /* DIF_OP_SETS */
3750Sstevel@tonic-gate { "scmp", dt_dis_cmp }, /* DIF_OP_SCMP */
3760Sstevel@tonic-gate { "ldga", dt_dis_lda }, /* DIF_OP_LDGA */
3770Sstevel@tonic-gate { "ldgs", dt_dis_ldv }, /* DIF_OP_LDGS */
3780Sstevel@tonic-gate { "stgs", dt_dis_stv }, /* DIF_OP_STGS */
3790Sstevel@tonic-gate { "ldta", dt_dis_lda }, /* DIF_OP_LDTA */
3800Sstevel@tonic-gate { "ldts", dt_dis_ldv }, /* DIF_OP_LDTS */
3810Sstevel@tonic-gate { "stts", dt_dis_stv }, /* DIF_OP_STTS */
3820Sstevel@tonic-gate { "sra", dt_dis_log }, /* DIF_OP_SRA */
3830Sstevel@tonic-gate { "call", dt_dis_call }, /* DIF_OP_CALL */
3840Sstevel@tonic-gate { "pushtr", dt_dis_pushts }, /* DIF_OP_PUSHTR */
3850Sstevel@tonic-gate { "pushtv", dt_dis_pushts }, /* DIF_OP_PUSHTV */
3860Sstevel@tonic-gate { "popts", dt_dis_str }, /* DIF_OP_POPTS */
3870Sstevel@tonic-gate { "flushts", dt_dis_str }, /* DIF_OP_FLUSHTS */
3880Sstevel@tonic-gate { "ldgaa", dt_dis_ldv }, /* DIF_OP_LDGAA */
3890Sstevel@tonic-gate { "ldtaa", dt_dis_ldv }, /* DIF_OP_LDTAA */
3900Sstevel@tonic-gate { "stgaa", dt_dis_stv }, /* DIF_OP_STGAA */
3910Sstevel@tonic-gate { "sttaa", dt_dis_stv }, /* DIF_OP_STTAA */
3920Sstevel@tonic-gate { "ldls", dt_dis_ldv }, /* DIF_OP_LDLS */
3930Sstevel@tonic-gate { "stls", dt_dis_stv }, /* DIF_OP_STLS */
3940Sstevel@tonic-gate { "allocs", dt_dis_r1rd }, /* DIF_OP_ALLOCS */
3950Sstevel@tonic-gate { "copys", dt_dis_log }, /* DIF_OP_COPYS */
3960Sstevel@tonic-gate { "stb", dt_dis_store }, /* DIF_OP_STB */
3970Sstevel@tonic-gate { "sth", dt_dis_store }, /* DIF_OP_STH */
3980Sstevel@tonic-gate { "stw", dt_dis_store }, /* DIF_OP_STW */
3990Sstevel@tonic-gate { "stx", dt_dis_store }, /* DIF_OP_STX */
4000Sstevel@tonic-gate { "uldsb", dt_dis_load }, /* DIF_OP_ULDSB */
4010Sstevel@tonic-gate { "uldsh", dt_dis_load }, /* DIF_OP_ULDSH */
4020Sstevel@tonic-gate { "uldsw", dt_dis_load }, /* DIF_OP_ULDSW */
4030Sstevel@tonic-gate { "uldub", dt_dis_load }, /* DIF_OP_ULDUB */
4040Sstevel@tonic-gate { "ulduh", dt_dis_load }, /* DIF_OP_ULDUH */
4050Sstevel@tonic-gate { "ulduw", dt_dis_load }, /* DIF_OP_ULDUW */
4060Sstevel@tonic-gate { "uldx", dt_dis_load }, /* DIF_OP_ULDX */
4070Sstevel@tonic-gate { "rldsb", dt_dis_load }, /* DIF_OP_RLDSB */
4080Sstevel@tonic-gate { "rldsh", dt_dis_load }, /* DIF_OP_RLDSH */
4090Sstevel@tonic-gate { "rldsw", dt_dis_load }, /* DIF_OP_RLDSW */
4100Sstevel@tonic-gate { "rldub", dt_dis_load }, /* DIF_OP_RLDUB */
4110Sstevel@tonic-gate { "rlduh", dt_dis_load }, /* DIF_OP_RLDUH */
4120Sstevel@tonic-gate { "rlduw", dt_dis_load }, /* DIF_OP_RLDUW */
4130Sstevel@tonic-gate { "rldx", dt_dis_load }, /* DIF_OP_RLDX */
414*265Smws { "xlate", dt_dis_xlate }, /* DIF_OP_XLATE */
415*265Smws { "xlarg", dt_dis_xlate }, /* DIF_OP_XLARG */
4160Sstevel@tonic-gate };
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate const struct opent *op;
4190Sstevel@tonic-gate ulong_t i = 0;
420*265Smws char type[DT_TYPE_NAMELEN];
4210Sstevel@tonic-gate
422*265Smws (void) fprintf(fp, "\nDIFO 0x%p returns %s\n", (void *)dp,
4230Sstevel@tonic-gate dt_dis_typestr(&dp->dtdo_rtype, type, sizeof (type)));
4240Sstevel@tonic-gate
4250Sstevel@tonic-gate (void) fprintf(fp, "%-3s %-8s %s\n",
4260Sstevel@tonic-gate "OFF", "OPCODE", "INSTRUCTION");
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate for (i = 0; i < dp->dtdo_len; i++) {
4290Sstevel@tonic-gate dif_instr_t instr = dp->dtdo_buf[i];
4300Sstevel@tonic-gate dif_instr_t opcode = DIF_INSTR_OP(instr);
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate if (opcode >= sizeof (optab) / sizeof (optab[0]))
4330Sstevel@tonic-gate opcode = 0; /* force invalid opcode message */
4340Sstevel@tonic-gate
4350Sstevel@tonic-gate op = &optab[opcode];
4360Sstevel@tonic-gate (void) fprintf(fp, "%02lu: %08x ", i, instr);
4370Sstevel@tonic-gate op->op_func(dp, op->op_name, instr, fp);
4380Sstevel@tonic-gate (void) fprintf(fp, "\n");
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate if (dp->dtdo_varlen != 0) {
4420Sstevel@tonic-gate (void) fprintf(fp, "\n%-16s %-4s %-3s %-3s %-4s %s\n",
4430Sstevel@tonic-gate "NAME", "ID", "KND", "SCP", "FLAG", "TYPE");
4440Sstevel@tonic-gate }
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate for (i = 0; i < dp->dtdo_varlen; i++) {
4470Sstevel@tonic-gate dtrace_difv_t *v = &dp->dtdo_vartab[i];
4480Sstevel@tonic-gate char kind[4], scope[4], flags[16] = { 0 };
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate switch (v->dtdv_kind) {
4510Sstevel@tonic-gate case DIFV_KIND_ARRAY:
4520Sstevel@tonic-gate (void) strcpy(kind, "arr");
4530Sstevel@tonic-gate break;
4540Sstevel@tonic-gate case DIFV_KIND_SCALAR:
4550Sstevel@tonic-gate (void) strcpy(kind, "scl");
4560Sstevel@tonic-gate break;
4570Sstevel@tonic-gate default:
4580Sstevel@tonic-gate (void) snprintf(kind, sizeof (kind),
4590Sstevel@tonic-gate "%u", v->dtdv_kind);
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate switch (v->dtdv_scope) {
4630Sstevel@tonic-gate case DIFV_SCOPE_GLOBAL:
4640Sstevel@tonic-gate (void) strcpy(scope, "glb");
4650Sstevel@tonic-gate break;
4660Sstevel@tonic-gate case DIFV_SCOPE_THREAD:
4670Sstevel@tonic-gate (void) strcpy(scope, "tls");
4680Sstevel@tonic-gate break;
4690Sstevel@tonic-gate case DIFV_SCOPE_LOCAL:
4700Sstevel@tonic-gate (void) strcpy(scope, "loc");
4710Sstevel@tonic-gate break;
4720Sstevel@tonic-gate default:
4730Sstevel@tonic-gate (void) snprintf(scope, sizeof (scope),
4740Sstevel@tonic-gate "%u", v->dtdv_scope);
4750Sstevel@tonic-gate }
4760Sstevel@tonic-gate
4770Sstevel@tonic-gate if (v->dtdv_flags & ~(DIFV_F_REF | DIFV_F_MOD)) {
4780Sstevel@tonic-gate (void) snprintf(flags, sizeof (flags), "/0x%x",
4790Sstevel@tonic-gate v->dtdv_flags & ~(DIFV_F_REF | DIFV_F_MOD));
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate
4820Sstevel@tonic-gate if (v->dtdv_flags & DIFV_F_REF)
4830Sstevel@tonic-gate (void) strcat(flags, "/r");
4840Sstevel@tonic-gate if (v->dtdv_flags & DIFV_F_MOD)
4850Sstevel@tonic-gate (void) strcat(flags, "/w");
4860Sstevel@tonic-gate
4870Sstevel@tonic-gate (void) fprintf(fp, "%-16s %-4x %-3s %-3s %-4s %s\n",
4880Sstevel@tonic-gate &dp->dtdo_strtab[v->dtdv_name],
4890Sstevel@tonic-gate v->dtdv_id, kind, scope, flags + 1,
4900Sstevel@tonic-gate dt_dis_typestr(&v->dtdv_type, type, sizeof (type)));
4910Sstevel@tonic-gate }
4920Sstevel@tonic-gate
493*265Smws if (dp->dtdo_xlmlen != 0) {
494*265Smws (void) fprintf(fp, "\n%-4s %-3s %-12s %s\n",
495*265Smws "XLID", "ARG", "MEMBER", "TYPE");
496*265Smws }
497*265Smws
498*265Smws for (i = 0; i < dp->dtdo_xlmlen; i++) {
499*265Smws dt_node_t *dnp = dp->dtdo_xlmtab[i];
500*265Smws dt_xlator_t *dxp = dnp->dn_membexpr->dn_xlator;
501*265Smws (void) fprintf(fp, "%-4u %-3d %-12s %s\n",
502*265Smws (uint_t)dxp->dx_id, dxp->dx_arg, dnp->dn_membname,
503*265Smws dt_node_type_name(dnp, type, sizeof (type)));
504*265Smws }
505*265Smws
5060Sstevel@tonic-gate if (dp->dtdo_krelen != 0)
5070Sstevel@tonic-gate dt_dis_rtab("KREL", dp, fp, dp->dtdo_kreltab, dp->dtdo_krelen);
5080Sstevel@tonic-gate
5090Sstevel@tonic-gate if (dp->dtdo_urelen != 0)
5100Sstevel@tonic-gate dt_dis_rtab("UREL", dp, fp, dp->dtdo_ureltab, dp->dtdo_urelen);
5110Sstevel@tonic-gate }
512