Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/cg/err.D_NOREG.noreg.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/cg/err.D_NOREG.noreg.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/cg/err.D_NOREG.noreg.d (revision 250812) @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ + +/* + * Compile some code that requires exactly 9 registers. This should run out + * of registers. + * + * Changes to the code generator might cause this test to succeeed in which + * case the code should be changed to another sequence that exhausts the + * available internal registers. + * + * Note that this and err.baddif.d should be kept in sync. + */ + +BEGIN +{ + a = 4; + trace((a + a) * ((a + a) * ((a + a) * ((a + a) * ((a + a) * + ((a + a) * (a + a))))))); +} + +BEGIN +{ + exit(0); +} Index: head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/cg/err.baddif.d =================================================================== --- head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/cg/err.baddif.d (nonexistent) +++ head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/cg/err.baddif.d (revision 250812) @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ + +/* + * Compile some code that requires exactly 9 registers. This should generate + * invalid DIF because the kernel will flag the fact that we're using more + * registers than are available internally. + * + * Changes to the code generator might cause this test to succeeed in which + * case the code should be changed to another sequence that exhausts the + * available internal registers. + * + * Note that this and err.D_NOREG.noreg.d should be kept in sync. + */ + +#pragma D option iregs=9 + +BEGIN +{ + a = 4; + trace((a + a) * ((a + a) * ((a + a) * ((a + a) * ((a + a) * + ((a + a) * (a + a))))))); +} + +BEGIN +{ + exit(0); +} Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cg.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cg.c (revision 250811) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cg.c (revision 250812) @@ -1,2006 +1,2020 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ + /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ #include #include #include #include #include #include #include #include #include #include #include #include static void dt_cg_node(dt_node_t *, dt_irlist_t *, dt_regset_t *); static dt_irnode_t * dt_cg_node_alloc(uint_t label, dif_instr_t instr) { dt_irnode_t *dip = malloc(sizeof (dt_irnode_t)); if (dip == NULL) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); dip->di_label = label; dip->di_instr = instr; dip->di_extern = NULL; dip->di_next = NULL; return (dip); } /* * Code generator wrapper function for ctf_member_info. If we are given a * reference to a forward declaration tag, search the entire type space for * the actual definition and then call ctf_member_info on the result. */ static ctf_file_t * dt_cg_membinfo(ctf_file_t *fp, ctf_id_t type, const char *s, ctf_membinfo_t *mp) { while (ctf_type_kind(fp, type) == CTF_K_FORWARD) { char n[DT_TYPE_NAMELEN]; dtrace_typeinfo_t dtt; if (ctf_type_name(fp, type, n, sizeof (n)) == NULL || dt_type_lookup(n, &dtt) == -1 || ( dtt.dtt_ctfp == fp && dtt.dtt_type == type)) break; /* unable to improve our position */ fp = dtt.dtt_ctfp; type = ctf_type_resolve(fp, dtt.dtt_type); } if (ctf_member_info(fp, type, s, mp) == CTF_ERR) return (NULL); /* ctf_errno is set for us */ return (fp); } static void dt_cg_xsetx(dt_irlist_t *dlp, dt_ident_t *idp, uint_t lbl, int reg, uint64_t x) { int flag = idp != NULL ? DT_INT_PRIVATE : DT_INT_SHARED; int intoff = dt_inttab_insert(yypcb->pcb_inttab, x, flag); dif_instr_t instr = DIF_INSTR_SETX((uint_t)intoff, reg); if (intoff == -1) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (intoff > DIF_INTOFF_MAX) longjmp(yypcb->pcb_jmpbuf, EDT_INT2BIG); dt_irlist_append(dlp, dt_cg_node_alloc(lbl, instr)); if (idp != NULL) dlp->dl_last->di_extern = idp; } static void dt_cg_setx(dt_irlist_t *dlp, int reg, uint64_t x) { dt_cg_xsetx(dlp, NULL, DT_LBL_NONE, reg, x); } /* * When loading bit-fields, we want to convert a byte count in the range * 1-8 to the closest power of 2 (e.g. 3->4, 5->8, etc). The clp2() function * is a clever implementation from "Hacker's Delight" by Henry Warren, Jr. */ static size_t clp2(size_t x) { x--; x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); x |= (x >> 16); return (x + 1); } /* * Lookup the correct load opcode to use for the specified node and CTF type. * We determine the size and convert it to a 3-bit index. Our lookup table * is constructed to use a 5-bit index, consisting of the 3-bit size 0-7, a * bit for the sign, and a bit for userland address. For example, a 4-byte * signed load from userland would be at the following table index: * user=1 sign=1 size=4 => binary index 11011 = decimal index 27 */ static uint_t dt_cg_load(dt_node_t *dnp, ctf_file_t *ctfp, ctf_id_t type) { static const uint_t ops[] = { DIF_OP_LDUB, DIF_OP_LDUH, 0, DIF_OP_LDUW, 0, 0, 0, DIF_OP_LDX, DIF_OP_LDSB, DIF_OP_LDSH, 0, DIF_OP_LDSW, 0, 0, 0, DIF_OP_LDX, DIF_OP_ULDUB, DIF_OP_ULDUH, 0, DIF_OP_ULDUW, 0, 0, 0, DIF_OP_ULDX, DIF_OP_ULDSB, DIF_OP_ULDSH, 0, DIF_OP_ULDSW, 0, 0, 0, DIF_OP_ULDX, }; ctf_encoding_t e; ssize_t size; /* * If we're loading a bit-field, the size of our load is found by * rounding cte_bits up to a byte boundary and then finding the * nearest power of two to this value (see clp2(), above). */ if ((dnp->dn_flags & DT_NF_BITFIELD) && ctf_type_encoding(ctfp, type, &e) != CTF_ERR) size = clp2(P2ROUNDUP(e.cte_bits, NBBY) / NBBY); else size = ctf_type_size(ctfp, type); if (size < 1 || size > 8 || (size & (size - 1)) != 0) { xyerror(D_UNKNOWN, "internal error -- cg cannot load " "size %ld when passed by value\n", (long)size); } size--; /* convert size to 3-bit index */ if (dnp->dn_flags & DT_NF_SIGNED) size |= 0x08; if (dnp->dn_flags & DT_NF_USERLAND) size |= 0x10; return (ops[size]); } static void dt_cg_ptrsize(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp, uint_t op, int dreg) { ctf_file_t *ctfp = dnp->dn_ctfp; ctf_arinfo_t r; dif_instr_t instr; ctf_id_t type; uint_t kind; ssize_t size; int sreg; - if ((sreg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - type = ctf_type_resolve(ctfp, dnp->dn_type); kind = ctf_type_kind(ctfp, type); assert(kind == CTF_K_POINTER || kind == CTF_K_ARRAY); if (kind == CTF_K_ARRAY) { if (ctf_array_info(ctfp, type, &r) != 0) { yypcb->pcb_hdl->dt_ctferr = ctf_errno(ctfp); longjmp(yypcb->pcb_jmpbuf, EDT_CTF); } type = r.ctr_contents; } else type = ctf_type_reference(ctfp, type); if ((size = ctf_type_size(ctfp, type)) == 1) return; /* multiply or divide by one can be omitted */ + sreg = dt_regset_alloc(drp); dt_cg_setx(dlp, sreg, size); instr = DIF_INSTR_FMT(op, dreg, sreg, dreg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, sreg); } /* * If the result of a "." or "->" operation is a bit-field, we use this routine * to generate an epilogue to the load instruction that extracts the value. In * the diagrams below the "ld??" is the load instruction that is generated to * load the containing word that is generating prior to calling this function. * * Epilogue for unsigned fields: Epilogue for signed fields: * * ldu? [r1], r1 lds? [r1], r1 * setx USHIFT, r2 setx 64 - SSHIFT, r2 * srl r1, r2, r1 sll r1, r2, r1 * setx (1 << bits) - 1, r2 setx 64 - bits, r2 * and r1, r2, r1 sra r1, r2, r1 * * The *SHIFT constants above changes value depending on the endian-ness of our * target architecture. Refer to the comments below for more details. */ static void dt_cg_field_get(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp, ctf_file_t *fp, const ctf_membinfo_t *mp) { ctf_encoding_t e; dif_instr_t instr; uint64_t shift; int r1, r2; if (ctf_type_encoding(fp, mp->ctm_type, &e) != 0 || e.cte_bits > 64) { xyerror(D_UNKNOWN, "cg: bad field: off %lu type <%ld> " "bits %u\n", mp->ctm_offset, mp->ctm_type, e.cte_bits); } assert(dnp->dn_op == DT_TOK_PTR || dnp->dn_op == DT_TOK_DOT); r1 = dnp->dn_left->dn_reg; + r2 = dt_regset_alloc(drp); - if ((r2 = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - /* * On little-endian architectures, ctm_offset counts from the right so * ctm_offset % NBBY itself is the amount we want to shift right to * move the value bits to the little end of the register to mask them. * On big-endian architectures, ctm_offset counts from the left so we * must subtract (ctm_offset % NBBY + cte_bits) from the size in bits * we used for the load. The size of our load in turn is found by * rounding cte_bits up to a byte boundary and then finding the * nearest power of two to this value (see clp2(), above). These * properties are used to compute shift as USHIFT or SSHIFT, below. */ if (dnp->dn_flags & DT_NF_SIGNED) { #if BYTE_ORDER == _BIG_ENDIAN shift = clp2(P2ROUNDUP(e.cte_bits, NBBY) / NBBY) * NBBY - mp->ctm_offset % NBBY; #else shift = mp->ctm_offset % NBBY + e.cte_bits; #endif dt_cg_setx(dlp, r2, 64 - shift); instr = DIF_INSTR_FMT(DIF_OP_SLL, r1, r2, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, r2, 64 - e.cte_bits); instr = DIF_INSTR_FMT(DIF_OP_SRA, r1, r2, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } else { #if BYTE_ORDER == _BIG_ENDIAN shift = clp2(P2ROUNDUP(e.cte_bits, NBBY) / NBBY) * NBBY - (mp->ctm_offset % NBBY + e.cte_bits); #else shift = mp->ctm_offset % NBBY; #endif dt_cg_setx(dlp, r2, shift); instr = DIF_INSTR_FMT(DIF_OP_SRL, r1, r2, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, r2, (1ULL << e.cte_bits) - 1); instr = DIF_INSTR_FMT(DIF_OP_AND, r1, r2, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } dt_regset_free(drp, r2); } /* * If the destination of a store operation is a bit-field, we use this routine * to generate a prologue to the store instruction that loads the surrounding * bits, clears the destination field, and ORs in the new value of the field. * In the diagram below the "st?" is the store instruction that is generated to * store the containing word that is generating after calling this function. * * ld [dst->dn_reg], r1 * setx ~(((1 << cte_bits) - 1) << (ctm_offset % NBBY)), r2 * and r1, r2, r1 * * setx (1 << cte_bits) - 1, r2 * and src->dn_reg, r2, r2 * setx ctm_offset % NBBY, r3 * sll r2, r3, r2 * * or r1, r2, r1 * st? r1, [dst->dn_reg] * * This routine allocates a new register to hold the value to be stored and * returns it. The caller is responsible for freeing this register later. */ static int dt_cg_field_set(dt_node_t *src, dt_irlist_t *dlp, dt_regset_t *drp, dt_node_t *dst) { uint64_t cmask, fmask, shift; dif_instr_t instr; int r1, r2, r3; ctf_membinfo_t m; ctf_encoding_t e; ctf_file_t *fp, *ofp; ctf_id_t type; assert(dst->dn_op == DT_TOK_PTR || dst->dn_op == DT_TOK_DOT); assert(dst->dn_right->dn_kind == DT_NODE_IDENT); fp = dst->dn_left->dn_ctfp; type = ctf_type_resolve(fp, dst->dn_left->dn_type); if (dst->dn_op == DT_TOK_PTR) { type = ctf_type_reference(fp, type); type = ctf_type_resolve(fp, type); } if ((fp = dt_cg_membinfo(ofp = fp, type, dst->dn_right->dn_string, &m)) == NULL) { yypcb->pcb_hdl->dt_ctferr = ctf_errno(ofp); longjmp(yypcb->pcb_jmpbuf, EDT_CTF); } if (ctf_type_encoding(fp, m.ctm_type, &e) != 0 || e.cte_bits > 64) { xyerror(D_UNKNOWN, "cg: bad field: off %lu type <%ld> " "bits %u\n", m.ctm_offset, m.ctm_type, e.cte_bits); } - if ((r1 = dt_regset_alloc(drp)) == -1 || - (r2 = dt_regset_alloc(drp)) == -1 || - (r3 = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + r1 = dt_regset_alloc(drp); + r2 = dt_regset_alloc(drp); + r3 = dt_regset_alloc(drp); /* * Compute shifts and masks. We need to compute "shift" as the amount * we need to shift left to position our field in the containing word. * Refer to the comments in dt_cg_field_get(), above, for more info. * We then compute fmask as the mask that truncates the value in the * input register to width cte_bits, and cmask as the mask used to * pass through the containing bits and zero the field bits. */ #if BYTE_ORDER == _BIG_ENDIAN shift = clp2(P2ROUNDUP(e.cte_bits, NBBY) / NBBY) * NBBY - (m.ctm_offset % NBBY + e.cte_bits); #else shift = m.ctm_offset % NBBY; #endif fmask = (1ULL << e.cte_bits) - 1; cmask = ~(fmask << shift); instr = DIF_INSTR_LOAD( dt_cg_load(dst, fp, m.ctm_type), dst->dn_reg, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, r2, cmask); instr = DIF_INSTR_FMT(DIF_OP_AND, r1, r2, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, r2, fmask); instr = DIF_INSTR_FMT(DIF_OP_AND, src->dn_reg, r2, r2); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, r3, shift); instr = DIF_INSTR_FMT(DIF_OP_SLL, r2, r3, r2); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_FMT(DIF_OP_OR, r1, r2, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, r3); dt_regset_free(drp, r2); return (r1); } static void dt_cg_store(dt_node_t *src, dt_irlist_t *dlp, dt_regset_t *drp, dt_node_t *dst) { ctf_encoding_t e; dif_instr_t instr; size_t size; int reg; /* * If we're loading a bit-field, the size of our store is found by * rounding dst's cte_bits up to a byte boundary and then finding the * nearest power of two to this value (see clp2(), above). */ if ((dst->dn_flags & DT_NF_BITFIELD) && ctf_type_encoding(dst->dn_ctfp, dst->dn_type, &e) != CTF_ERR) size = clp2(P2ROUNDUP(e.cte_bits, NBBY) / NBBY); else size = dt_node_type_size(src); if (src->dn_flags & DT_NF_REF) { - if ((reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + reg = dt_regset_alloc(drp); dt_cg_setx(dlp, reg, size); instr = DIF_INSTR_COPYS(src->dn_reg, reg, dst->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, reg); } else { if (dst->dn_flags & DT_NF_BITFIELD) reg = dt_cg_field_set(src, dlp, drp, dst); else reg = src->dn_reg; switch (size) { case 1: instr = DIF_INSTR_STORE(DIF_OP_STB, reg, dst->dn_reg); break; case 2: instr = DIF_INSTR_STORE(DIF_OP_STH, reg, dst->dn_reg); break; case 4: instr = DIF_INSTR_STORE(DIF_OP_STW, reg, dst->dn_reg); break; case 8: instr = DIF_INSTR_STORE(DIF_OP_STX, reg, dst->dn_reg); break; default: xyerror(D_UNKNOWN, "internal error -- cg cannot store " "size %lu when passed by value\n", (ulong_t)size); } dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); if (dst->dn_flags & DT_NF_BITFIELD) dt_regset_free(drp, reg); } } /* * Generate code for a typecast or for argument promotion from the type of the * actual to the type of the formal. We need to generate code for casts when * a scalar type is being narrowed or changing signed-ness. We first shift the * desired bits high (losing excess bits if narrowing) and then shift them down * using logical shift (unsigned result) or arithmetic shift (signed result). */ static void dt_cg_typecast(const dt_node_t *src, const dt_node_t *dst, dt_irlist_t *dlp, dt_regset_t *drp) { size_t srcsize = dt_node_type_size(src); size_t dstsize = dt_node_type_size(dst); dif_instr_t instr; - int reg, n; + int rg; - if (dt_node_is_scalar(dst) && (dstsize < srcsize || - (src->dn_flags & DT_NF_SIGNED) ^ (dst->dn_flags & DT_NF_SIGNED))) { - if ((reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + if (!dt_node_is_scalar(dst)) + return; /* not a scalar */ + if (dstsize == srcsize && + ((src->dn_flags ^ dst->dn_flags) & DT_NF_SIGNED) != 0) + return; /* not narrowing or changing signed-ness */ + if (dstsize > srcsize && (src->dn_flags & DT_NF_SIGNED) == 0) + return; /* nothing to do in this case */ - if (dstsize < srcsize) - n = sizeof (uint64_t) * NBBY - dstsize * NBBY; - else - n = sizeof (uint64_t) * NBBY - srcsize * NBBY; + rg = dt_regset_alloc(drp); - dt_cg_setx(dlp, reg, n); + if (dstsize > srcsize) { + int n = sizeof (uint64_t) * NBBY - srcsize * NBBY; + int s = (dstsize - srcsize) * NBBY; - instr = DIF_INSTR_FMT(DIF_OP_SLL, - src->dn_reg, reg, dst->dn_reg); + dt_cg_setx(dlp, rg, n); + + instr = DIF_INSTR_FMT(DIF_OP_SLL, src->dn_reg, rg, dst->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); - instr = DIF_INSTR_FMT((dst->dn_flags & DT_NF_SIGNED) ? - DIF_OP_SRA : DIF_OP_SRL, dst->dn_reg, reg, dst->dn_reg); + if ((dst->dn_flags & DT_NF_SIGNED) || n == s) { + instr = DIF_INSTR_FMT(DIF_OP_SRA, + dst->dn_reg, rg, dst->dn_reg); + dt_irlist_append(dlp, + dt_cg_node_alloc(DT_LBL_NONE, instr)); + } else { + dt_cg_setx(dlp, rg, s); + instr = DIF_INSTR_FMT(DIF_OP_SRA, + dst->dn_reg, rg, dst->dn_reg); + dt_irlist_append(dlp, + dt_cg_node_alloc(DT_LBL_NONE, instr)); + dt_cg_setx(dlp, rg, n - s); + instr = DIF_INSTR_FMT(DIF_OP_SRL, + dst->dn_reg, rg, dst->dn_reg); + dt_irlist_append(dlp, + dt_cg_node_alloc(DT_LBL_NONE, instr)); + } + } else if (dstsize != sizeof (uint64_t)) { + int n = sizeof (uint64_t) * NBBY - dstsize * NBBY; + dt_cg_setx(dlp, rg, n); + + instr = DIF_INSTR_FMT(DIF_OP_SLL, src->dn_reg, rg, dst->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); - dt_regset_free(drp, reg); + + instr = DIF_INSTR_FMT((dst->dn_flags & DT_NF_SIGNED) ? + DIF_OP_SRA : DIF_OP_SRL, dst->dn_reg, rg, dst->dn_reg); + dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } + + dt_regset_free(drp, rg); } /* * Generate code to push the specified argument list on to the tuple stack. * We use this routine for handling subroutine calls and associative arrays. * We must first generate code for all subexpressions before loading the stack * because any subexpression could itself require the use of the tuple stack. * This holds a number of registers equal to the number of arguments, but this * is not a huge problem because the number of arguments can't exceed the * number of tuple register stack elements anyway. At most one extra register * is required (either by dt_cg_typecast() or for dtdt_size, below). This * implies that a DIF implementation should offer a number of general purpose * registers at least one greater than the number of tuple registers. */ static void dt_cg_arglist(dt_ident_t *idp, dt_node_t *args, dt_irlist_t *dlp, dt_regset_t *drp) { const dt_idsig_t *isp = idp->di_data; dt_node_t *dnp; int i = 0; for (dnp = args; dnp != NULL; dnp = dnp->dn_list) dt_cg_node(dnp, dlp, drp); - dt_irlist_append(dlp, - dt_cg_node_alloc(DT_LBL_NONE, DIF_INSTR_FLUSHTS)); + dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, DIF_INSTR_FLUSHTS)); for (dnp = args; dnp != NULL; dnp = dnp->dn_list, i++) { dtrace_diftype_t t; dif_instr_t instr; uint_t op; int reg; dt_node_diftype(yypcb->pcb_hdl, dnp, &t); isp->dis_args[i].dn_reg = dnp->dn_reg; /* re-use register */ dt_cg_typecast(dnp, &isp->dis_args[i], dlp, drp); isp->dis_args[i].dn_reg = -1; - if (t.dtdt_flags & DIF_TF_BYREF) + if (t.dtdt_flags & DIF_TF_BYREF) { op = DIF_OP_PUSHTR; - else + if (t.dtdt_size != 0) { + reg = dt_regset_alloc(drp); + dt_cg_setx(dlp, reg, t.dtdt_size); + } else { + reg = DIF_REG_R0; + } + } else { op = DIF_OP_PUSHTV; - - if (t.dtdt_size != 0) { - if ((reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - dt_cg_setx(dlp, reg, t.dtdt_size); - } else reg = DIF_REG_R0; + } instr = DIF_INSTR_PUSHTS(op, t.dtdt_kind, reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, dnp->dn_reg); if (reg != DIF_REG_R0) dt_regset_free(drp, reg); } if (i > yypcb->pcb_hdl->dt_conf.dtc_diftupregs) longjmp(yypcb->pcb_jmpbuf, EDT_NOTUPREG); } static void dt_cg_arithmetic_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp, uint_t op) { int is_ptr_op = (dnp->dn_op == DT_TOK_ADD || dnp->dn_op == DT_TOK_SUB || dnp->dn_op == DT_TOK_ADD_EQ || dnp->dn_op == DT_TOK_SUB_EQ); int lp_is_ptr = dt_node_is_pointer(dnp->dn_left); int rp_is_ptr = dt_node_is_pointer(dnp->dn_right); dif_instr_t instr; if (lp_is_ptr && rp_is_ptr) { assert(dnp->dn_op == DT_TOK_SUB); is_ptr_op = 0; } dt_cg_node(dnp->dn_left, dlp, drp); if (is_ptr_op && rp_is_ptr) dt_cg_ptrsize(dnp, dlp, drp, DIF_OP_MUL, dnp->dn_left->dn_reg); dt_cg_node(dnp->dn_right, dlp, drp); if (is_ptr_op && lp_is_ptr) dt_cg_ptrsize(dnp, dlp, drp, DIF_OP_MUL, dnp->dn_right->dn_reg); instr = DIF_INSTR_FMT(op, dnp->dn_left->dn_reg, dnp->dn_right->dn_reg, dnp->dn_left->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, dnp->dn_right->dn_reg); dnp->dn_reg = dnp->dn_left->dn_reg; if (lp_is_ptr && rp_is_ptr) dt_cg_ptrsize(dnp->dn_right, dlp, drp, DIF_OP_UDIV, dnp->dn_reg); } static uint_t dt_cg_stvar(const dt_ident_t *idp) { static const uint_t aops[] = { DIF_OP_STGAA, DIF_OP_STTAA, DIF_OP_NOP }; static const uint_t sops[] = { DIF_OP_STGS, DIF_OP_STTS, DIF_OP_STLS }; uint_t i = (((idp->di_flags & DT_IDFLG_LOCAL) != 0) << 1) | ((idp->di_flags & DT_IDFLG_TLS) != 0); return (idp->di_kind == DT_IDENT_ARRAY ? aops[i] : sops[i]); } static void dt_cg_prearith_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp, uint_t op) { ctf_file_t *ctfp = dnp->dn_ctfp; dif_instr_t instr; ctf_id_t type; ssize_t size = 1; int reg; if (dt_node_is_pointer(dnp)) { type = ctf_type_resolve(ctfp, dnp->dn_type); assert(ctf_type_kind(ctfp, type) == CTF_K_POINTER); size = ctf_type_size(ctfp, ctf_type_reference(ctfp, type)); } dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; - if ((reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - + reg = dt_regset_alloc(drp); dt_cg_setx(dlp, reg, size); instr = DIF_INSTR_FMT(op, dnp->dn_reg, reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, reg); /* * If we are modifying a variable, generate an stv instruction from * the variable specified by the identifier. If we are storing to a * memory address, generate code again for the left-hand side using * DT_NF_REF to get the address, and then generate a store to it. * In both paths, we store the value in dnp->dn_reg (the new value). */ if (dnp->dn_child->dn_kind == DT_NODE_VAR) { dt_ident_t *idp = dt_ident_resolve(dnp->dn_child->dn_ident); idp->di_flags |= DT_IDFLG_DIFW; instr = DIF_INSTR_STV(dt_cg_stvar(idp), idp->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } else { uint_t rbit = dnp->dn_child->dn_flags & DT_NF_REF; assert(dnp->dn_child->dn_flags & DT_NF_WRITABLE); assert(dnp->dn_child->dn_flags & DT_NF_LVALUE); dnp->dn_child->dn_flags |= DT_NF_REF; /* force pass-by-ref */ dt_cg_node(dnp->dn_child, dlp, drp); dt_cg_store(dnp, dlp, drp, dnp->dn_child); dt_regset_free(drp, dnp->dn_child->dn_reg); dnp->dn_left->dn_flags &= ~DT_NF_REF; dnp->dn_left->dn_flags |= rbit; } } static void dt_cg_postarith_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp, uint_t op) { ctf_file_t *ctfp = dnp->dn_ctfp; dif_instr_t instr; ctf_id_t type; ssize_t size = 1; int nreg; if (dt_node_is_pointer(dnp)) { type = ctf_type_resolve(ctfp, dnp->dn_type); assert(ctf_type_kind(ctfp, type) == CTF_K_POINTER); size = ctf_type_size(ctfp, ctf_type_reference(ctfp, type)); } dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; - if ((nreg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - + nreg = dt_regset_alloc(drp); dt_cg_setx(dlp, nreg, size); instr = DIF_INSTR_FMT(op, dnp->dn_reg, nreg, nreg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); /* * If we are modifying a variable, generate an stv instruction from * the variable specified by the identifier. If we are storing to a * memory address, generate code again for the left-hand side using * DT_NF_REF to get the address, and then generate a store to it. * In both paths, we store the value from 'nreg' (the new value). */ if (dnp->dn_child->dn_kind == DT_NODE_VAR) { dt_ident_t *idp = dt_ident_resolve(dnp->dn_child->dn_ident); idp->di_flags |= DT_IDFLG_DIFW; instr = DIF_INSTR_STV(dt_cg_stvar(idp), idp->di_id, nreg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } else { uint_t rbit = dnp->dn_child->dn_flags & DT_NF_REF; int oreg = dnp->dn_reg; assert(dnp->dn_child->dn_flags & DT_NF_WRITABLE); assert(dnp->dn_child->dn_flags & DT_NF_LVALUE); dnp->dn_child->dn_flags |= DT_NF_REF; /* force pass-by-ref */ dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = nreg; dt_cg_store(dnp, dlp, drp, dnp->dn_child); dnp->dn_reg = oreg; dt_regset_free(drp, dnp->dn_child->dn_reg); dnp->dn_left->dn_flags &= ~DT_NF_REF; dnp->dn_left->dn_flags |= rbit; } dt_regset_free(drp, nreg); } /* * Determine if we should perform signed or unsigned comparison for an OP2. * If both operands are of arithmetic type, perform the usual arithmetic * conversions to determine the common real type for comparison [ISOC 6.5.8.3]. */ static int dt_cg_compare_signed(dt_node_t *dnp) { dt_node_t dn; if (dt_node_is_string(dnp->dn_left) || dt_node_is_string(dnp->dn_right)) return (1); /* strings always compare signed */ else if (!dt_node_is_arith(dnp->dn_left) || !dt_node_is_arith(dnp->dn_right)) return (0); /* non-arithmetic types always compare unsigned */ bzero(&dn, sizeof (dn)); dt_node_promote(dnp->dn_left, dnp->dn_right, &dn); return (dn.dn_flags & DT_NF_SIGNED); } static void dt_cg_compare_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp, uint_t op) { uint_t lbl_true = dt_irlist_label(dlp); uint_t lbl_post = dt_irlist_label(dlp); dif_instr_t instr; uint_t opc; dt_cg_node(dnp->dn_left, dlp, drp); dt_cg_node(dnp->dn_right, dlp, drp); if (dt_node_is_string(dnp->dn_left) || dt_node_is_string(dnp->dn_right)) opc = DIF_OP_SCMP; else opc = DIF_OP_CMP; instr = DIF_INSTR_CMP(opc, dnp->dn_left->dn_reg, dnp->dn_right->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, dnp->dn_right->dn_reg); dnp->dn_reg = dnp->dn_left->dn_reg; instr = DIF_INSTR_BRANCH(op, lbl_true); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_MOV(DIF_REG_R0, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_BRANCH(DIF_OP_BA, lbl_post); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_xsetx(dlp, NULL, lbl_true, dnp->dn_reg, 1); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_post, DIF_INSTR_NOP)); } /* * Code generation for the ternary op requires some trickery with the assembler * in order to conserve registers. We generate code for dn_expr and dn_left * and free their registers so they do not have be consumed across codegen for * dn_right. We insert a dummy MOV at the end of dn_left into the destination * register, which is not yet known because we haven't done dn_right yet, and * save the pointer to this instruction node. We then generate code for * dn_right and use its register as our output. Finally, we reach back and * patch the instruction for dn_left to move its output into this register. */ static void dt_cg_ternary_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { uint_t lbl_false = dt_irlist_label(dlp); uint_t lbl_post = dt_irlist_label(dlp); dif_instr_t instr; dt_irnode_t *dip; dt_cg_node(dnp->dn_expr, dlp, drp); instr = DIF_INSTR_TST(dnp->dn_expr->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, dnp->dn_expr->dn_reg); instr = DIF_INSTR_BRANCH(DIF_OP_BE, lbl_false); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_node(dnp->dn_left, dlp, drp); instr = DIF_INSTR_MOV(dnp->dn_left->dn_reg, DIF_REG_R0); dip = dt_cg_node_alloc(DT_LBL_NONE, instr); /* save dip for below */ dt_irlist_append(dlp, dip); dt_regset_free(drp, dnp->dn_left->dn_reg); instr = DIF_INSTR_BRANCH(DIF_OP_BA, lbl_post); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_false, DIF_INSTR_NOP)); dt_cg_node(dnp->dn_right, dlp, drp); dnp->dn_reg = dnp->dn_right->dn_reg; /* * Now that dn_reg is assigned, reach back and patch the correct MOV * instruction into the tail of dn_left. We know dn_reg was unused * at that point because otherwise dn_right couldn't have allocated it. */ dip->di_instr = DIF_INSTR_MOV(dnp->dn_left->dn_reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_post, DIF_INSTR_NOP)); } static void dt_cg_logical_and(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { uint_t lbl_false = dt_irlist_label(dlp); uint_t lbl_post = dt_irlist_label(dlp); dif_instr_t instr; dt_cg_node(dnp->dn_left, dlp, drp); instr = DIF_INSTR_TST(dnp->dn_left->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, dnp->dn_left->dn_reg); instr = DIF_INSTR_BRANCH(DIF_OP_BE, lbl_false); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_node(dnp->dn_right, dlp, drp); instr = DIF_INSTR_TST(dnp->dn_right->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dnp->dn_reg = dnp->dn_right->dn_reg; instr = DIF_INSTR_BRANCH(DIF_OP_BE, lbl_false); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, dnp->dn_reg, 1); instr = DIF_INSTR_BRANCH(DIF_OP_BA, lbl_post); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_MOV(DIF_REG_R0, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_false, instr)); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_post, DIF_INSTR_NOP)); } static void dt_cg_logical_xor(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { uint_t lbl_next = dt_irlist_label(dlp); uint_t lbl_tail = dt_irlist_label(dlp); dif_instr_t instr; dt_cg_node(dnp->dn_left, dlp, drp); instr = DIF_INSTR_TST(dnp->dn_left->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_BRANCH(DIF_OP_BE, lbl_next); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, dnp->dn_left->dn_reg, 1); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_next, DIF_INSTR_NOP)); dt_cg_node(dnp->dn_right, dlp, drp); instr = DIF_INSTR_TST(dnp->dn_right->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_BRANCH(DIF_OP_BE, lbl_tail); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, dnp->dn_right->dn_reg, 1); instr = DIF_INSTR_FMT(DIF_OP_XOR, dnp->dn_left->dn_reg, dnp->dn_right->dn_reg, dnp->dn_left->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_tail, instr)); dt_regset_free(drp, dnp->dn_right->dn_reg); dnp->dn_reg = dnp->dn_left->dn_reg; } static void dt_cg_logical_or(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { uint_t lbl_true = dt_irlist_label(dlp); uint_t lbl_false = dt_irlist_label(dlp); uint_t lbl_post = dt_irlist_label(dlp); dif_instr_t instr; dt_cg_node(dnp->dn_left, dlp, drp); instr = DIF_INSTR_TST(dnp->dn_left->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, dnp->dn_left->dn_reg); instr = DIF_INSTR_BRANCH(DIF_OP_BNE, lbl_true); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_node(dnp->dn_right, dlp, drp); instr = DIF_INSTR_TST(dnp->dn_right->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dnp->dn_reg = dnp->dn_right->dn_reg; instr = DIF_INSTR_BRANCH(DIF_OP_BE, lbl_false); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_xsetx(dlp, NULL, lbl_true, dnp->dn_reg, 1); instr = DIF_INSTR_BRANCH(DIF_OP_BA, lbl_post); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_MOV(DIF_REG_R0, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_false, instr)); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_post, DIF_INSTR_NOP)); } static void dt_cg_logical_neg(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { uint_t lbl_zero = dt_irlist_label(dlp); uint_t lbl_post = dt_irlist_label(dlp); dif_instr_t instr; dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; instr = DIF_INSTR_TST(dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_BRANCH(DIF_OP_BE, lbl_zero); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_MOV(DIF_REG_R0, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_BRANCH(DIF_OP_BA, lbl_post); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_xsetx(dlp, NULL, lbl_zero, dnp->dn_reg, 1); dt_irlist_append(dlp, dt_cg_node_alloc(lbl_post, DIF_INSTR_NOP)); } static void dt_cg_asgn_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { dif_instr_t instr; dt_ident_t *idp; /* * If we are performing a structure assignment of a translated type, * we must instantiate all members and create a snapshot of the object * in scratch space. We allocs a chunk of memory, generate code for * each member, and then set dnp->dn_reg to the scratch object address. */ if ((idp = dt_node_resolve(dnp->dn_right, DT_IDENT_XLSOU)) != NULL) { ctf_membinfo_t ctm; dt_xlator_t *dxp = idp->di_data; dt_node_t *mnp, dn, mn; int r1, r2; /* * Create two fake dt_node_t's representing operator "." and a * right-hand identifier child node. These will be repeatedly * modified according to each instantiated member so that we * can pass them to dt_cg_store() and effect a member store. */ bzero(&dn, sizeof (dt_node_t)); dn.dn_kind = DT_NODE_OP2; dn.dn_op = DT_TOK_DOT; dn.dn_left = dnp; dn.dn_right = &mn; bzero(&mn, sizeof (dt_node_t)); mn.dn_kind = DT_NODE_IDENT; mn.dn_op = DT_TOK_IDENT; /* * Allocate a register for our scratch data pointer. First we * set it to the size of our data structure, and then replace * it with the result of an allocs of the specified size. */ - if ((r1 = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - + r1 = dt_regset_alloc(drp); dt_cg_setx(dlp, r1, ctf_type_size(dxp->dx_dst_ctfp, dxp->dx_dst_base)); instr = DIF_INSTR_ALLOCS(r1, r1); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); /* * When dt_cg_asgn_op() is called, we have already generated * code for dnp->dn_right, which is the translator input. We * now associate this register with the translator's input * identifier so it can be referenced during our member loop. */ dxp->dx_ident->di_flags |= DT_IDFLG_CGREG; dxp->dx_ident->di_id = dnp->dn_right->dn_reg; for (mnp = dxp->dx_members; mnp != NULL; mnp = mnp->dn_list) { /* * Generate code for the translator member expression, * and then cast the result to the member type. */ dt_cg_node(mnp->dn_membexpr, dlp, drp); mnp->dn_reg = mnp->dn_membexpr->dn_reg; dt_cg_typecast(mnp->dn_membexpr, mnp, dlp, drp); /* * Ask CTF for the offset of the member so we can store * to the appropriate offset. This call has already * been done once by the parser, so it should succeed. */ if (ctf_member_info(dxp->dx_dst_ctfp, dxp->dx_dst_base, mnp->dn_membname, &ctm) == CTF_ERR) { yypcb->pcb_hdl->dt_ctferr = ctf_errno(dxp->dx_dst_ctfp); longjmp(yypcb->pcb_jmpbuf, EDT_CTF); } /* * If the destination member is at offset 0, store the * result directly to r1 (the scratch buffer address). * Otherwise allocate another temporary for the offset * and add r1 to it before storing the result. */ if (ctm.ctm_offset != 0) { - if ((r2 = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + r2 = dt_regset_alloc(drp); /* * Add the member offset rounded down to the * nearest byte. If the offset was not aligned * on a byte boundary, this member is a bit- * field and dt_cg_store() will handle masking. */ dt_cg_setx(dlp, r2, ctm.ctm_offset / NBBY); instr = DIF_INSTR_FMT(DIF_OP_ADD, r1, r2, r2); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_node_type_propagate(mnp, &dn); dn.dn_right->dn_string = mnp->dn_membname; dn.dn_reg = r2; dt_cg_store(mnp, dlp, drp, &dn); dt_regset_free(drp, r2); } else { dt_node_type_propagate(mnp, &dn); dn.dn_right->dn_string = mnp->dn_membname; dn.dn_reg = r1; dt_cg_store(mnp, dlp, drp, &dn); } dt_regset_free(drp, mnp->dn_reg); } dxp->dx_ident->di_flags &= ~DT_IDFLG_CGREG; dxp->dx_ident->di_id = 0; if (dnp->dn_right->dn_reg != -1) dt_regset_free(drp, dnp->dn_right->dn_reg); assert(dnp->dn_reg == dnp->dn_right->dn_reg); dnp->dn_reg = r1; } /* * If we are storing to a variable, generate an stv instruction from * the variable specified by the identifier. If we are storing to a * memory address, generate code again for the left-hand side using * DT_NF_REF to get the address, and then generate a store to it. * In both paths, we assume dnp->dn_reg already has the new value. */ if (dnp->dn_left->dn_kind == DT_NODE_VAR) { idp = dt_ident_resolve(dnp->dn_left->dn_ident); if (idp->di_kind == DT_IDENT_ARRAY) dt_cg_arglist(idp, dnp->dn_left->dn_args, dlp, drp); idp->di_flags |= DT_IDFLG_DIFW; instr = DIF_INSTR_STV(dt_cg_stvar(idp), idp->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } else { uint_t rbit = dnp->dn_left->dn_flags & DT_NF_REF; assert(dnp->dn_left->dn_flags & DT_NF_WRITABLE); assert(dnp->dn_left->dn_flags & DT_NF_LVALUE); dnp->dn_left->dn_flags |= DT_NF_REF; /* force pass-by-ref */ dt_cg_node(dnp->dn_left, dlp, drp); dt_cg_store(dnp, dlp, drp, dnp->dn_left); dt_regset_free(drp, dnp->dn_left->dn_reg); dnp->dn_left->dn_flags &= ~DT_NF_REF; dnp->dn_left->dn_flags |= rbit; } } static void dt_cg_assoc_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { dif_instr_t instr; uint_t op; assert(dnp->dn_kind == DT_NODE_VAR); assert(!(dnp->dn_ident->di_flags & DT_IDFLG_LOCAL)); assert(dnp->dn_args != NULL); dt_cg_arglist(dnp->dn_ident, dnp->dn_args, dlp, drp); - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + dnp->dn_reg = dt_regset_alloc(drp); if (dnp->dn_ident->di_flags & DT_IDFLG_TLS) op = DIF_OP_LDTAA; else op = DIF_OP_LDGAA; dnp->dn_ident->di_flags |= DT_IDFLG_DIFR; instr = DIF_INSTR_LDV(op, dnp->dn_ident->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); /* * If the associative array is a pass-by-reference type, then we are * loading its value as a pointer to either load or store through it. * The array element in question may not have been faulted in yet, in * which case DIF_OP_LD*AA will return zero. We append an epilogue * of instructions similar to the following: * * ld?aa id, %r1 ! base ld?aa instruction above * tst %r1 ! start of epilogue * +--- bne label * | setx size, %r1 * | allocs %r1, %r1 * | st?aa id, %r1 * | ld?aa id, %r1 * v * label: < rest of code > * * The idea is that we allocs a zero-filled chunk of scratch space and * do a DIF_OP_ST*AA to fault in and initialize the array element, and * then reload it to get the faulted-in address of the new variable * storage. This isn't cheap, but pass-by-ref associative array values * are (thus far) uncommon and the allocs cost only occurs once. If * this path becomes important to DTrace users, we can improve things * by adding a new DIF opcode to fault in associative array elements. */ if (dnp->dn_flags & DT_NF_REF) { uint_t stvop = op == DIF_OP_LDTAA ? DIF_OP_STTAA : DIF_OP_STGAA; uint_t label = dt_irlist_label(dlp); instr = DIF_INSTR_TST(dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_BRANCH(DIF_OP_BNE, label); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_cg_setx(dlp, dnp->dn_reg, dt_node_type_size(dnp)); instr = DIF_INSTR_ALLOCS(dnp->dn_reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dnp->dn_ident->di_flags |= DT_IDFLG_DIFW; instr = DIF_INSTR_STV(stvop, dnp->dn_ident->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_LDV(op, dnp->dn_ident->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_irlist_append(dlp, dt_cg_node_alloc(label, DIF_INSTR_NOP)); } } static void dt_cg_array_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { dt_probe_t *prp = yypcb->pcb_probe; uintmax_t saved = dnp->dn_args->dn_value; dt_ident_t *idp = dnp->dn_ident; dif_instr_t instr; uint_t op; size_t size; int reg, n; assert(dnp->dn_kind == DT_NODE_VAR); assert(!(idp->di_flags & DT_IDFLG_LOCAL)); assert(dnp->dn_args->dn_kind == DT_NODE_INT); assert(dnp->dn_args->dn_list == NULL); /* * If this is a reference in the args[] array, temporarily modify the * array index according to the static argument mapping (if any), * unless the argument reference is provided by a dynamic translator. * If we're using a dynamic translator for args[], then just set dn_reg * to an invalid reg and return: DIF_OP_XLARG will fetch the arg later. */ if (idp->di_id == DIF_VAR_ARGS) { if ((idp->di_kind == DT_IDENT_XLPTR || idp->di_kind == DT_IDENT_XLSOU) && dt_xlator_dynamic(idp->di_data)) { dnp->dn_reg = -1; return; } dnp->dn_args->dn_value = prp->pr_mapping[saved]; } dt_cg_node(dnp->dn_args, dlp, drp); dnp->dn_args->dn_value = saved; dnp->dn_reg = dnp->dn_args->dn_reg; if (idp->di_flags & DT_IDFLG_TLS) op = DIF_OP_LDTA; else op = DIF_OP_LDGA; idp->di_flags |= DT_IDFLG_DIFR; instr = DIF_INSTR_LDA(op, idp->di_id, dnp->dn_args->dn_reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); /* * If this is a reference to the args[] array, we need to take the * additional step of explicitly eliminating any bits larger than the * type size: the DIF interpreter in the kernel will always give us * the raw (64-bit) argument value, and any bits larger than the type * size may be junk. As a practical matter, this arises only on 64-bit * architectures and only when the argument index is larger than the * number of arguments passed directly to DTrace: if a 8-, 16- or * 32-bit argument must be retrieved from the stack, it is possible * (and it some cases, likely) that the upper bits will be garbage. */ if (idp->di_id != DIF_VAR_ARGS || !dt_node_is_scalar(dnp)) return; if ((size = dt_node_type_size(dnp)) == sizeof (uint64_t)) return; - if ((reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - + reg = dt_regset_alloc(drp); assert(size < sizeof (uint64_t)); n = sizeof (uint64_t) * NBBY - size * NBBY; dt_cg_setx(dlp, reg, n); instr = DIF_INSTR_FMT(DIF_OP_SLL, dnp->dn_reg, reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); instr = DIF_INSTR_FMT((dnp->dn_flags & DT_NF_SIGNED) ? DIF_OP_SRA : DIF_OP_SRL, dnp->dn_reg, reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, reg); } /* * Generate code for an inlined variable reference. Inlines can be used to * define either scalar or associative array substitutions. For scalars, we * simply generate code for the parse tree saved in the identifier's din_root, * and then cast the resulting expression to the inline's declaration type. * For arrays, we take the input parameter subtrees from dnp->dn_args and * temporarily store them in the din_root of each din_argv[i] identifier, * which are themselves inlines and were set up for us by the parser. The * result is that any reference to the inlined parameter inside the top-level * din_root will turn into a recursive call to dt_cg_inline() for a scalar * inline whose din_root will refer to the subtree pointed to by the argument. */ static void dt_cg_inline(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { dt_ident_t *idp = dnp->dn_ident; dt_idnode_t *inp = idp->di_iarg; dt_idnode_t *pinp; dt_node_t *pnp; int i; assert(idp->di_flags & DT_IDFLG_INLINE); assert(idp->di_ops == &dt_idops_inline); if (idp->di_kind == DT_IDENT_ARRAY) { for (i = 0, pnp = dnp->dn_args; pnp != NULL; pnp = pnp->dn_list, i++) { if (inp->din_argv[i] != NULL) { pinp = inp->din_argv[i]->di_iarg; pinp->din_root = pnp; } } } dt_cg_node(inp->din_root, dlp, drp); dnp->dn_reg = inp->din_root->dn_reg; dt_cg_typecast(inp->din_root, dnp, dlp, drp); if (idp->di_kind == DT_IDENT_ARRAY) { for (i = 0; i < inp->din_argc; i++) { pinp = inp->din_argv[i]->di_iarg; pinp->din_root = NULL; } } } static void dt_cg_func_typeref(dtrace_hdl_t *dtp, dt_node_t *dnp) { dtrace_typeinfo_t dtt; dt_node_t *addr = dnp->dn_args; dt_node_t *nelm = addr->dn_list; dt_node_t *strp = nelm->dn_list; dt_node_t *typs = strp->dn_list; char buf[DT_TYPE_NAMELEN]; char *p; ctf_type_name(addr->dn_ctfp, addr->dn_type, buf, sizeof (buf)); /* * XXX Hack alert! XXX * The prototype has two dummy args that we munge to represent * the type string and the type size. * * Yes, I hear your grumble, but it works for now. We'll come * up with a more elegant implementation later. :-) */ free(strp->dn_string); if ((p = strchr(buf, '*')) != NULL) *p = '\0'; strp->dn_string = strdup(buf); if (dtrace_lookup_by_type(dtp, DTRACE_OBJ_EVERY, buf, &dtt) < 0) return; typs->dn_value = ctf_type_size(dtt.dtt_ctfp, dtt.dtt_type); } static void dt_cg_node(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp) { ctf_file_t *ctfp = dnp->dn_ctfp; ctf_file_t *octfp; ctf_membinfo_t m; ctf_id_t type; dif_instr_t instr; dt_ident_t *idp; ssize_t stroff; uint_t op; - int reg; switch (dnp->dn_op) { case DT_TOK_COMMA: dt_cg_node(dnp->dn_left, dlp, drp); dt_regset_free(drp, dnp->dn_left->dn_reg); dt_cg_node(dnp->dn_right, dlp, drp); dnp->dn_reg = dnp->dn_right->dn_reg; break; case DT_TOK_ASGN: dt_cg_node(dnp->dn_right, dlp, drp); dnp->dn_reg = dnp->dn_right->dn_reg; dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_ADD_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_ADD); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_SUB_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_SUB); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_MUL_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_MUL); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_DIV_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, (dnp->dn_flags & DT_NF_SIGNED) ? DIF_OP_SDIV : DIF_OP_UDIV); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_MOD_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, (dnp->dn_flags & DT_NF_SIGNED) ? DIF_OP_SREM : DIF_OP_UREM); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_AND_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_AND); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_XOR_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_XOR); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_OR_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_OR); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_LSH_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_SLL); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_RSH_EQ: dt_cg_arithmetic_op(dnp, dlp, drp, (dnp->dn_flags & DT_NF_SIGNED) ? DIF_OP_SRA : DIF_OP_SRL); dt_cg_asgn_op(dnp, dlp, drp); break; case DT_TOK_QUESTION: dt_cg_ternary_op(dnp, dlp, drp); break; case DT_TOK_LOR: dt_cg_logical_or(dnp, dlp, drp); break; case DT_TOK_LXOR: dt_cg_logical_xor(dnp, dlp, drp); break; case DT_TOK_LAND: dt_cg_logical_and(dnp, dlp, drp); break; case DT_TOK_BOR: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_OR); break; case DT_TOK_XOR: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_XOR); break; case DT_TOK_BAND: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_AND); break; case DT_TOK_EQU: dt_cg_compare_op(dnp, dlp, drp, DIF_OP_BE); break; case DT_TOK_NEQ: dt_cg_compare_op(dnp, dlp, drp, DIF_OP_BNE); break; case DT_TOK_LT: dt_cg_compare_op(dnp, dlp, drp, dt_cg_compare_signed(dnp) ? DIF_OP_BL : DIF_OP_BLU); break; case DT_TOK_LE: dt_cg_compare_op(dnp, dlp, drp, dt_cg_compare_signed(dnp) ? DIF_OP_BLE : DIF_OP_BLEU); break; case DT_TOK_GT: dt_cg_compare_op(dnp, dlp, drp, dt_cg_compare_signed(dnp) ? DIF_OP_BG : DIF_OP_BGU); break; case DT_TOK_GE: dt_cg_compare_op(dnp, dlp, drp, dt_cg_compare_signed(dnp) ? DIF_OP_BGE : DIF_OP_BGEU); break; case DT_TOK_LSH: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_SLL); break; case DT_TOK_RSH: dt_cg_arithmetic_op(dnp, dlp, drp, (dnp->dn_flags & DT_NF_SIGNED) ? DIF_OP_SRA : DIF_OP_SRL); break; case DT_TOK_ADD: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_ADD); break; case DT_TOK_SUB: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_SUB); break; case DT_TOK_MUL: dt_cg_arithmetic_op(dnp, dlp, drp, DIF_OP_MUL); break; case DT_TOK_DIV: dt_cg_arithmetic_op(dnp, dlp, drp, (dnp->dn_flags & DT_NF_SIGNED) ? DIF_OP_SDIV : DIF_OP_UDIV); break; case DT_TOK_MOD: dt_cg_arithmetic_op(dnp, dlp, drp, (dnp->dn_flags & DT_NF_SIGNED) ? DIF_OP_SREM : DIF_OP_UREM); break; case DT_TOK_LNEG: dt_cg_logical_neg(dnp, dlp, drp); break; case DT_TOK_BNEG: dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; instr = DIF_INSTR_NOT(dnp->dn_reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); break; case DT_TOK_PREINC: dt_cg_prearith_op(dnp, dlp, drp, DIF_OP_ADD); break; case DT_TOK_POSTINC: dt_cg_postarith_op(dnp, dlp, drp, DIF_OP_ADD); break; case DT_TOK_PREDEC: dt_cg_prearith_op(dnp, dlp, drp, DIF_OP_SUB); break; case DT_TOK_POSTDEC: dt_cg_postarith_op(dnp, dlp, drp, DIF_OP_SUB); break; case DT_TOK_IPOS: dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; break; case DT_TOK_INEG: dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; instr = DIF_INSTR_FMT(DIF_OP_SUB, DIF_REG_R0, dnp->dn_reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); break; case DT_TOK_DEREF: dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; if (!(dnp->dn_flags & DT_NF_REF)) { uint_t ubit = dnp->dn_flags & DT_NF_USERLAND; /* * Save and restore DT_NF_USERLAND across dt_cg_load(): * we need the sign bit from dnp and the user bit from * dnp->dn_child in order to get the proper opcode. */ dnp->dn_flags |= (dnp->dn_child->dn_flags & DT_NF_USERLAND); instr = DIF_INSTR_LOAD(dt_cg_load(dnp, ctfp, dnp->dn_type), dnp->dn_reg, dnp->dn_reg); dnp->dn_flags &= ~DT_NF_USERLAND; dnp->dn_flags |= ubit; dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } break; case DT_TOK_ADDROF: { uint_t rbit = dnp->dn_child->dn_flags & DT_NF_REF; dnp->dn_child->dn_flags |= DT_NF_REF; /* force pass-by-ref */ dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; dnp->dn_child->dn_flags &= ~DT_NF_REF; dnp->dn_child->dn_flags |= rbit; break; } case DT_TOK_SIZEOF: { size_t size = dt_node_sizeof(dnp->dn_child); - - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - + dnp->dn_reg = dt_regset_alloc(drp); assert(size != 0); dt_cg_setx(dlp, dnp->dn_reg, size); break; } case DT_TOK_STRINGOF: dt_cg_node(dnp->dn_child, dlp, drp); dnp->dn_reg = dnp->dn_child->dn_reg; break; case DT_TOK_XLATE: /* * An xlate operator appears in either an XLATOR, indicating a * reference to a dynamic translator, or an OP2, indicating * use of the xlate operator in the user's program. For the * dynamic case, generate an xlate opcode with a reference to * the corresponding member, pre-computed for us in dn_members. */ if (dnp->dn_kind == DT_NODE_XLATOR) { dt_xlator_t *dxp = dnp->dn_xlator; assert(dxp->dx_ident->di_flags & DT_IDFLG_CGREG); assert(dxp->dx_ident->di_id != 0); - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + dnp->dn_reg = dt_regset_alloc(drp); if (dxp->dx_arg == -1) { instr = DIF_INSTR_MOV( dxp->dx_ident->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); op = DIF_OP_XLATE; } else op = DIF_OP_XLARG; instr = DIF_INSTR_XLATE(op, 0, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dlp->dl_last->di_extern = dnp->dn_xmember; break; } assert(dnp->dn_kind == DT_NODE_OP2); dt_cg_node(dnp->dn_right, dlp, drp); dnp->dn_reg = dnp->dn_right->dn_reg; break; case DT_TOK_LPAR: dt_cg_node(dnp->dn_right, dlp, drp); dnp->dn_reg = dnp->dn_right->dn_reg; dt_cg_typecast(dnp->dn_right, dnp, dlp, drp); break; case DT_TOK_PTR: case DT_TOK_DOT: assert(dnp->dn_right->dn_kind == DT_NODE_IDENT); dt_cg_node(dnp->dn_left, dlp, drp); /* * If the left-hand side of PTR or DOT is a dynamic variable, * we expect it to be the output of a D translator. In this * case, we look up the parse tree corresponding to the member * that is being accessed and run the code generator over it. * We then cast the result as if by the assignment operator. */ if ((idp = dt_node_resolve( dnp->dn_left, DT_IDENT_XLSOU)) != NULL || (idp = dt_node_resolve( dnp->dn_left, DT_IDENT_XLPTR)) != NULL) { dt_xlator_t *dxp; dt_node_t *mnp; dxp = idp->di_data; mnp = dt_xlator_member(dxp, dnp->dn_right->dn_string); assert(mnp != NULL); dxp->dx_ident->di_flags |= DT_IDFLG_CGREG; dxp->dx_ident->di_id = dnp->dn_left->dn_reg; dt_cg_node(mnp->dn_membexpr, dlp, drp); dnp->dn_reg = mnp->dn_membexpr->dn_reg; dt_cg_typecast(mnp->dn_membexpr, dnp, dlp, drp); dxp->dx_ident->di_flags &= ~DT_IDFLG_CGREG; dxp->dx_ident->di_id = 0; if (dnp->dn_left->dn_reg != -1) dt_regset_free(drp, dnp->dn_left->dn_reg); break; } ctfp = dnp->dn_left->dn_ctfp; type = ctf_type_resolve(ctfp, dnp->dn_left->dn_type); if (dnp->dn_op == DT_TOK_PTR) { type = ctf_type_reference(ctfp, type); type = ctf_type_resolve(ctfp, type); } if ((ctfp = dt_cg_membinfo(octfp = ctfp, type, dnp->dn_right->dn_string, &m)) == NULL) { yypcb->pcb_hdl->dt_ctferr = ctf_errno(octfp); longjmp(yypcb->pcb_jmpbuf, EDT_CTF); } if (m.ctm_offset != 0) { - if ((reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + int reg; + reg = dt_regset_alloc(drp); + /* * If the offset is not aligned on a byte boundary, it * is a bit-field member and we will extract the value * bits below after we generate the appropriate load. */ dt_cg_setx(dlp, reg, m.ctm_offset / NBBY); instr = DIF_INSTR_FMT(DIF_OP_ADD, dnp->dn_left->dn_reg, reg, dnp->dn_left->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); dt_regset_free(drp, reg); } if (!(dnp->dn_flags & DT_NF_REF)) { uint_t ubit = dnp->dn_flags & DT_NF_USERLAND; /* * Save and restore DT_NF_USERLAND across dt_cg_load(): * we need the sign bit from dnp and the user bit from * dnp->dn_left in order to get the proper opcode. */ dnp->dn_flags |= (dnp->dn_left->dn_flags & DT_NF_USERLAND); instr = DIF_INSTR_LOAD(dt_cg_load(dnp, ctfp, m.ctm_type), dnp->dn_left->dn_reg, dnp->dn_left->dn_reg); dnp->dn_flags &= ~DT_NF_USERLAND; dnp->dn_flags |= ubit; dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); if (dnp->dn_flags & DT_NF_BITFIELD) dt_cg_field_get(dnp, dlp, drp, ctfp, &m); } dnp->dn_reg = dnp->dn_left->dn_reg; break; case DT_TOK_STRING: - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + dnp->dn_reg = dt_regset_alloc(drp); assert(dnp->dn_kind == DT_NODE_STRING); stroff = dt_strtab_insert(yypcb->pcb_strtab, dnp->dn_string); if (stroff == -1L) longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); if (stroff > DIF_STROFF_MAX) longjmp(yypcb->pcb_jmpbuf, EDT_STR2BIG); instr = DIF_INSTR_SETS((ulong_t)stroff, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); break; case DT_TOK_IDENT: /* * If the specified identifier is a variable on which we have * set the code generator register flag, then this variable * has already had code generated for it and saved in di_id. * Allocate a new register and copy the existing value to it. */ if (dnp->dn_kind == DT_NODE_VAR && (dnp->dn_ident->di_flags & DT_IDFLG_CGREG)) { - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + dnp->dn_reg = dt_regset_alloc(drp); instr = DIF_INSTR_MOV(dnp->dn_ident->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); break; } /* * Identifiers can represent function calls, variable refs, or * symbols. First we check for inlined variables, and handle * them by generating code for the inline parse tree. */ if (dnp->dn_kind == DT_NODE_VAR && (dnp->dn_ident->di_flags & DT_IDFLG_INLINE)) { dt_cg_inline(dnp, dlp, drp); break; } switch (dnp->dn_kind) { case DT_NODE_FUNC: { dtrace_hdl_t *dtp = yypcb->pcb_hdl; if ((idp = dnp->dn_ident)->di_kind != DT_IDENT_FUNC) { dnerror(dnp, D_CG_EXPR, "%s %s( ) may not be " "called from a D expression (D program " "context required)\n", dt_idkind_name(idp->di_kind), idp->di_name); } switch (idp->di_id) { case DIF_SUBR_TYPEREF: dt_cg_func_typeref(dtp, dnp); break; default: break; } dt_cg_arglist(dnp->dn_ident, dnp->dn_args, dlp, drp); - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + dnp->dn_reg = dt_regset_alloc(drp); + instr = DIF_INSTR_CALL(dnp->dn_ident->di_id, + dnp->dn_reg); - instr = DIF_INSTR_CALL( - dnp->dn_ident->di_id, dnp->dn_reg); - dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); break; } case DT_NODE_VAR: if (dnp->dn_ident->di_kind == DT_IDENT_XLSOU || dnp->dn_ident->di_kind == DT_IDENT_XLPTR) { /* * This can only happen if we have translated * args[]. See dt_idcook_args() for details. */ assert(dnp->dn_ident->di_id == DIF_VAR_ARGS); dt_cg_array_op(dnp, dlp, drp); break; } if (dnp->dn_ident->di_kind == DT_IDENT_ARRAY) { if (dnp->dn_ident->di_id > DIF_VAR_ARRAY_MAX) dt_cg_assoc_op(dnp, dlp, drp); else dt_cg_array_op(dnp, dlp, drp); break; } - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); + dnp->dn_reg = dt_regset_alloc(drp); if (dnp->dn_ident->di_flags & DT_IDFLG_LOCAL) op = DIF_OP_LDLS; else if (dnp->dn_ident->di_flags & DT_IDFLG_TLS) op = DIF_OP_LDTS; else op = DIF_OP_LDGS; dnp->dn_ident->di_flags |= DT_IDFLG_DIFR; instr = DIF_INSTR_LDV(op, dnp->dn_ident->di_id, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); break; case DT_NODE_SYM: { dtrace_hdl_t *dtp = yypcb->pcb_hdl; dtrace_syminfo_t *sip = dnp->dn_ident->di_data; GElf_Sym sym; if (dtrace_lookup_by_name(dtp, sip->dts_object, sip->dts_name, &sym, NULL) == -1) { xyerror(D_UNKNOWN, "cg failed for symbol %s`%s:" " %s\n", sip->dts_object, sip->dts_name, dtrace_errmsg(dtp, dtrace_errno(dtp))); } - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - + dnp->dn_reg = dt_regset_alloc(drp); dt_cg_xsetx(dlp, dnp->dn_ident, DT_LBL_NONE, dnp->dn_reg, sym.st_value); if (!(dnp->dn_flags & DT_NF_REF)) { instr = DIF_INSTR_LOAD(dt_cg_load(dnp, ctfp, dnp->dn_type), dnp->dn_reg, dnp->dn_reg); dt_irlist_append(dlp, dt_cg_node_alloc(DT_LBL_NONE, instr)); } break; } default: xyerror(D_UNKNOWN, "internal error -- node type %u is " "not valid for an identifier\n", dnp->dn_kind); } break; case DT_TOK_INT: - if ((dnp->dn_reg = dt_regset_alloc(drp)) == -1) - longjmp(yypcb->pcb_jmpbuf, EDT_NOREG); - + dnp->dn_reg = dt_regset_alloc(drp); dt_cg_setx(dlp, dnp->dn_reg, dnp->dn_value); break; default: xyerror(D_UNKNOWN, "internal error -- token type %u is not a " "valid D compilation token\n", dnp->dn_op); } } void dt_cg(dt_pcb_t *pcb, dt_node_t *dnp) { dif_instr_t instr; dt_xlator_t *dxp; + dt_ident_t *idp; if (pcb->pcb_regs == NULL && (pcb->pcb_regs = dt_regset_create(pcb->pcb_hdl->dt_conf.dtc_difintregs)) == NULL) longjmp(pcb->pcb_jmpbuf, EDT_NOMEM); dt_regset_reset(pcb->pcb_regs); (void) dt_regset_alloc(pcb->pcb_regs); /* allocate %r0 */ if (pcb->pcb_inttab != NULL) dt_inttab_destroy(pcb->pcb_inttab); if ((pcb->pcb_inttab = dt_inttab_create(yypcb->pcb_hdl)) == NULL) longjmp(pcb->pcb_jmpbuf, EDT_NOMEM); if (pcb->pcb_strtab != NULL) dt_strtab_destroy(pcb->pcb_strtab); if ((pcb->pcb_strtab = dt_strtab_create(BUFSIZ)) == NULL) longjmp(pcb->pcb_jmpbuf, EDT_NOMEM); dt_irlist_destroy(&pcb->pcb_ir); dt_irlist_create(&pcb->pcb_ir); assert(pcb->pcb_dret == NULL); pcb->pcb_dret = dnp; - if (dt_node_is_dynamic(dnp)) { + if (dt_node_resolve(dnp, DT_IDENT_XLPTR) != NULL) { dnerror(dnp, D_CG_DYN, "expression cannot evaluate to result " - "of dynamic type\n"); + "of a translated pointer\n"); } /* * If we're generating code for a translator body, assign the input * parameter to the first available register (i.e. caller passes %r1). */ if (dnp->dn_kind == DT_NODE_MEMBER) { dxp = dnp->dn_membxlator; dnp = dnp->dn_membexpr; dxp->dx_ident->di_flags |= DT_IDFLG_CGREG; dxp->dx_ident->di_id = dt_regset_alloc(pcb->pcb_regs); } dt_cg_node(dnp, &pcb->pcb_ir, pcb->pcb_regs); + + if ((idp = dt_node_resolve(dnp, DT_IDENT_XLSOU)) != NULL) { + int reg = dt_cg_xlate_expand(dnp, idp, + &pcb->pcb_ir, pcb->pcb_regs); + dt_regset_free(pcb->pcb_regs, dnp->dn_reg); + dnp->dn_reg = reg; + } + instr = DIF_INSTR_RET(dnp->dn_reg); dt_regset_free(pcb->pcb_regs, dnp->dn_reg); dt_irlist_append(&pcb->pcb_ir, dt_cg_node_alloc(DT_LBL_NONE, instr)); if (dnp->dn_kind == DT_NODE_MEMBER) { dt_regset_free(pcb->pcb_regs, dxp->dx_ident->di_id); dxp->dx_ident->di_id = 0; dxp->dx_ident->di_flags &= ~DT_IDFLG_CGREG; } + + dt_regset_free(pcb->pcb_regs, 0); + dt_regset_assert_free(pcb->pcb_regs); } Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dis.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dis.c (revision 250811) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_dis.c (revision 250812) @@ -1,511 +1,524 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ + /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ #include #include #include #include /*ARGSUSED*/ static void dt_dis_log(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s %%r%u, %%r%u, %%r%u", name, DIF_INSTR_R1(in), DIF_INSTR_R2(in), DIF_INSTR_RD(in)); } /*ARGSUSED*/ static void dt_dis_branch(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s %u", name, DIF_INSTR_LABEL(in)); } /*ARGSUSED*/ static void dt_dis_load(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s [%%r%u], %%r%u", name, DIF_INSTR_R1(in), DIF_INSTR_RD(in)); } /*ARGSUSED*/ static void dt_dis_store(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s %%r%u, [%%r%u]", name, DIF_INSTR_R1(in), DIF_INSTR_RD(in)); } /*ARGSUSED*/ static void dt_dis_str(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%s", name); } /*ARGSUSED*/ static void dt_dis_r1rd(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s %%r%u, %%r%u", name, DIF_INSTR_R1(in), DIF_INSTR_RD(in)); } /*ARGSUSED*/ static void dt_dis_cmp(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s %%r%u, %%r%u", name, DIF_INSTR_R1(in), DIF_INSTR_R2(in)); } /*ARGSUSED*/ static void dt_dis_tst(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s %%r%u", name, DIF_INSTR_R1(in)); } static const char * dt_dis_varname(const dtrace_difo_t *dp, uint_t id, uint_t scope) { const dtrace_difv_t *dvp = dp->dtdo_vartab; uint_t i; for (i = 0; i < dp->dtdo_varlen; i++, dvp++) { if (dvp->dtdv_id == id && dvp->dtdv_scope == scope) { if (dvp->dtdv_name < dp->dtdo_strlen) return (dp->dtdo_strtab + dvp->dtdv_name); break; } } return (NULL); } static uint_t dt_dis_scope(const char *name) { switch (name[2]) { case 'l': return (DIFV_SCOPE_LOCAL); case 't': return (DIFV_SCOPE_THREAD); case 'g': return (DIFV_SCOPE_GLOBAL); default: return (-1u); } } static void dt_dis_lda(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { uint_t var = DIF_INSTR_R1(in); const char *vname; (void) fprintf(fp, "%-4s DT_VAR(%u), %%r%u, %%r%u", name, var, DIF_INSTR_R2(in), DIF_INSTR_RD(in)); if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL) (void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname); } static void dt_dis_ldv(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { uint_t var = DIF_INSTR_VAR(in); const char *vname; (void) fprintf(fp, "%-4s DT_VAR(%u), %%r%u", name, var, DIF_INSTR_RD(in)); if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL) (void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname); } static void dt_dis_stv(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { uint_t var = DIF_INSTR_VAR(in); const char *vname; (void) fprintf(fp, "%-4s %%r%u, DT_VAR(%u)", name, DIF_INSTR_RS(in), var); if ((vname = dt_dis_varname(dp, var, dt_dis_scope(name))) != NULL) (void) fprintf(fp, "\t\t! DT_VAR(%u) = \"%s\"", var, vname); } static void dt_dis_setx(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { uint_t intptr = DIF_INSTR_INTEGER(in); (void) fprintf(fp, "%-4s DT_INTEGER[%u], %%r%u", name, intptr, DIF_INSTR_RD(in)); if (intptr < dp->dtdo_intlen) { (void) fprintf(fp, "\t\t! 0x%llx", (u_longlong_t)dp->dtdo_inttab[intptr]); } } static void dt_dis_sets(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { uint_t strptr = DIF_INSTR_STRING(in); (void) fprintf(fp, "%-4s DT_STRING[%u], %%r%u", name, strptr, DIF_INSTR_RD(in)); if (strptr < dp->dtdo_strlen) (void) fprintf(fp, "\t\t! \"%s\"", dp->dtdo_strtab + strptr); } /*ARGSUSED*/ static void dt_dis_ret(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { (void) fprintf(fp, "%-4s %%r%u", name, DIF_INSTR_RD(in)); } /*ARGSUSED*/ static void dt_dis_call(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { uint_t subr = DIF_INSTR_SUBR(in); (void) fprintf(fp, "%-4s DIF_SUBR(%u), %%r%u\t\t! %s", name, subr, DIF_INSTR_RD(in), dtrace_subrstr(NULL, subr)); } /*ARGSUSED*/ static void dt_dis_pushts(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { static const char *const tnames[] = { "D type", "string" }; uint_t type = DIF_INSTR_TYPE(in); + const char *pad; - (void) fprintf(fp, "%-4s DT_TYPE(%u), %%r%u, %%r%u", - name, type, DIF_INSTR_R2(in), DIF_INSTR_RS(in)); + if (DIF_INSTR_OP(in) == DIF_OP_PUSHTV) { + (void) fprintf(fp, "%-4s DT_TYPE(%u), %%r%u", + name, type, DIF_INSTR_RS(in)); + pad = "\t\t"; + } else { + (void) fprintf(fp, "%-4s DT_TYPE(%u), %%r%u, %%r%u", + name, type, DIF_INSTR_R2(in), DIF_INSTR_RS(in)); + pad = "\t"; + } - if (type < sizeof (tnames) / sizeof (tnames[0])) - (void) fprintf(fp, "\t! DT_TYPE(%u) = %s", type, tnames[type]); + if (type < sizeof (tnames) / sizeof (tnames[0])) { + (void) fprintf(fp, "%s! DT_TYPE(%u) = %s", pad, + type, tnames[type]); + } } static void dt_dis_xlate(const dtrace_difo_t *dp, const char *name, dif_instr_t in, FILE *fp) { uint_t xlr = DIF_INSTR_XLREF(in); (void) fprintf(fp, "%-4s DT_XLREF[%u], %%r%u", name, xlr, DIF_INSTR_RD(in)); if (xlr < dp->dtdo_xlmlen) { (void) fprintf(fp, "\t\t! DT_XLREF[%u] = %u.%s", xlr, (uint_t)dp->dtdo_xlmtab[xlr]->dn_membexpr->dn_xlator->dx_id, dp->dtdo_xlmtab[xlr]->dn_membname); } } static char * dt_dis_typestr(const dtrace_diftype_t *t, char *buf, size_t len) { char kind[16], ckind[16]; switch (t->dtdt_kind) { case DIF_TYPE_CTF: (void) strcpy(kind, "D type"); break; case DIF_TYPE_STRING: (void) strcpy(kind, "string"); break; default: (void) snprintf(kind, sizeof (kind), "0x%x", t->dtdt_kind); } switch (t->dtdt_ckind) { case CTF_K_UNKNOWN: (void) strcpy(ckind, "unknown"); break; case CTF_K_INTEGER: (void) strcpy(ckind, "integer"); break; case CTF_K_FLOAT: (void) strcpy(ckind, "float"); break; case CTF_K_POINTER: (void) strcpy(ckind, "pointer"); break; case CTF_K_ARRAY: (void) strcpy(ckind, "array"); break; case CTF_K_FUNCTION: (void) strcpy(ckind, "function"); break; case CTF_K_STRUCT: (void) strcpy(ckind, "struct"); break; case CTF_K_UNION: (void) strcpy(ckind, "union"); break; case CTF_K_ENUM: (void) strcpy(ckind, "enum"); break; case CTF_K_FORWARD: (void) strcpy(ckind, "forward"); break; case CTF_K_TYPEDEF: (void) strcpy(ckind, "typedef"); break; case CTF_K_VOLATILE: (void) strcpy(ckind, "volatile"); break; case CTF_K_CONST: (void) strcpy(ckind, "const"); break; case CTF_K_RESTRICT: (void) strcpy(ckind, "restrict"); break; default: (void) snprintf(ckind, sizeof (ckind), "0x%x", t->dtdt_ckind); } if (t->dtdt_flags & DIF_TF_BYREF) { (void) snprintf(buf, len, "%s (%s) by ref (size %lu)", kind, ckind, (ulong_t)t->dtdt_size); } else { (void) snprintf(buf, len, "%s (%s) (size %lu)", kind, ckind, (ulong_t)t->dtdt_size); } return (buf); } static void dt_dis_rtab(const char *rtag, const dtrace_difo_t *dp, FILE *fp, const dof_relodesc_t *rp, uint32_t len) { (void) fprintf(fp, "\n%-4s %-8s %-8s %s\n", rtag, "OFFSET", "DATA", "NAME"); for (; len != 0; len--, rp++) { (void) fprintf(fp, "%-4u %-8llu %-8llu %s\n", rp->dofr_type, (u_longlong_t)rp->dofr_offset, (u_longlong_t)rp->dofr_data, &dp->dtdo_strtab[rp->dofr_name]); } } void dt_dis(const dtrace_difo_t *dp, FILE *fp) { static const struct opent { const char *op_name; void (*op_func)(const dtrace_difo_t *, const char *, dif_instr_t, FILE *); } optab[] = { { "(illegal opcode)", dt_dis_str }, { "or", dt_dis_log }, /* DIF_OP_OR */ { "xor", dt_dis_log }, /* DIF_OP_XOR */ { "and", dt_dis_log }, /* DIF_OP_AND */ { "sll", dt_dis_log }, /* DIF_OP_SLL */ { "srl", dt_dis_log }, /* DIF_OP_SRL */ { "sub", dt_dis_log }, /* DIF_OP_SUB */ { "add", dt_dis_log }, /* DIF_OP_ADD */ { "mul", dt_dis_log }, /* DIF_OP_MUL */ { "sdiv", dt_dis_log }, /* DIF_OP_SDIV */ { "udiv", dt_dis_log }, /* DIF_OP_UDIV */ { "srem", dt_dis_log }, /* DIF_OP_SREM */ { "urem", dt_dis_log }, /* DIF_OP_UREM */ { "not", dt_dis_r1rd }, /* DIF_OP_NOT */ { "mov", dt_dis_r1rd }, /* DIF_OP_MOV */ { "cmp", dt_dis_cmp }, /* DIF_OP_CMP */ { "tst", dt_dis_tst }, /* DIF_OP_TST */ { "ba", dt_dis_branch }, /* DIF_OP_BA */ { "be", dt_dis_branch }, /* DIF_OP_BE */ { "bne", dt_dis_branch }, /* DIF_OP_BNE */ { "bg", dt_dis_branch }, /* DIF_OP_BG */ { "bgu", dt_dis_branch }, /* DIF_OP_BGU */ { "bge", dt_dis_branch }, /* DIF_OP_BGE */ { "bgeu", dt_dis_branch }, /* DIF_OP_BGEU */ { "bl", dt_dis_branch }, /* DIF_OP_BL */ { "blu", dt_dis_branch }, /* DIF_OP_BLU */ { "ble", dt_dis_branch }, /* DIF_OP_BLE */ { "bleu", dt_dis_branch }, /* DIF_OP_BLEU */ { "ldsb", dt_dis_load }, /* DIF_OP_LDSB */ { "ldsh", dt_dis_load }, /* DIF_OP_LDSH */ { "ldsw", dt_dis_load }, /* DIF_OP_LDSW */ { "ldub", dt_dis_load }, /* DIF_OP_LDUB */ { "lduh", dt_dis_load }, /* DIF_OP_LDUH */ { "lduw", dt_dis_load }, /* DIF_OP_LDUW */ { "ldx", dt_dis_load }, /* DIF_OP_LDX */ { "ret", dt_dis_ret }, /* DIF_OP_RET */ { "nop", dt_dis_str }, /* DIF_OP_NOP */ { "setx", dt_dis_setx }, /* DIF_OP_SETX */ { "sets", dt_dis_sets }, /* DIF_OP_SETS */ { "scmp", dt_dis_cmp }, /* DIF_OP_SCMP */ { "ldga", dt_dis_lda }, /* DIF_OP_LDGA */ { "ldgs", dt_dis_ldv }, /* DIF_OP_LDGS */ { "stgs", dt_dis_stv }, /* DIF_OP_STGS */ { "ldta", dt_dis_lda }, /* DIF_OP_LDTA */ { "ldts", dt_dis_ldv }, /* DIF_OP_LDTS */ { "stts", dt_dis_stv }, /* DIF_OP_STTS */ { "sra", dt_dis_log }, /* DIF_OP_SRA */ { "call", dt_dis_call }, /* DIF_OP_CALL */ { "pushtr", dt_dis_pushts }, /* DIF_OP_PUSHTR */ { "pushtv", dt_dis_pushts }, /* DIF_OP_PUSHTV */ { "popts", dt_dis_str }, /* DIF_OP_POPTS */ { "flushts", dt_dis_str }, /* DIF_OP_FLUSHTS */ { "ldgaa", dt_dis_ldv }, /* DIF_OP_LDGAA */ { "ldtaa", dt_dis_ldv }, /* DIF_OP_LDTAA */ { "stgaa", dt_dis_stv }, /* DIF_OP_STGAA */ { "sttaa", dt_dis_stv }, /* DIF_OP_STTAA */ { "ldls", dt_dis_ldv }, /* DIF_OP_LDLS */ { "stls", dt_dis_stv }, /* DIF_OP_STLS */ { "allocs", dt_dis_r1rd }, /* DIF_OP_ALLOCS */ { "copys", dt_dis_log }, /* DIF_OP_COPYS */ { "stb", dt_dis_store }, /* DIF_OP_STB */ { "sth", dt_dis_store }, /* DIF_OP_STH */ { "stw", dt_dis_store }, /* DIF_OP_STW */ { "stx", dt_dis_store }, /* DIF_OP_STX */ { "uldsb", dt_dis_load }, /* DIF_OP_ULDSB */ { "uldsh", dt_dis_load }, /* DIF_OP_ULDSH */ { "uldsw", dt_dis_load }, /* DIF_OP_ULDSW */ { "uldub", dt_dis_load }, /* DIF_OP_ULDUB */ { "ulduh", dt_dis_load }, /* DIF_OP_ULDUH */ { "ulduw", dt_dis_load }, /* DIF_OP_ULDUW */ { "uldx", dt_dis_load }, /* DIF_OP_ULDX */ { "rldsb", dt_dis_load }, /* DIF_OP_RLDSB */ { "rldsh", dt_dis_load }, /* DIF_OP_RLDSH */ { "rldsw", dt_dis_load }, /* DIF_OP_RLDSW */ { "rldub", dt_dis_load }, /* DIF_OP_RLDUB */ { "rlduh", dt_dis_load }, /* DIF_OP_RLDUH */ { "rlduw", dt_dis_load }, /* DIF_OP_RLDUW */ { "rldx", dt_dis_load }, /* DIF_OP_RLDX */ { "xlate", dt_dis_xlate }, /* DIF_OP_XLATE */ { "xlarg", dt_dis_xlate }, /* DIF_OP_XLARG */ }; const struct opent *op; ulong_t i = 0; char type[DT_TYPE_NAMELEN]; (void) fprintf(fp, "\nDIFO 0x%p returns %s\n", (void *)dp, dt_dis_typestr(&dp->dtdo_rtype, type, sizeof (type))); (void) fprintf(fp, "%-3s %-8s %s\n", "OFF", "OPCODE", "INSTRUCTION"); for (i = 0; i < dp->dtdo_len; i++) { dif_instr_t instr = dp->dtdo_buf[i]; dif_instr_t opcode = DIF_INSTR_OP(instr); if (opcode >= sizeof (optab) / sizeof (optab[0])) opcode = 0; /* force invalid opcode message */ op = &optab[opcode]; (void) fprintf(fp, "%02lu: %08x ", i, instr); op->op_func(dp, op->op_name, instr, fp); (void) fprintf(fp, "\n"); } if (dp->dtdo_varlen != 0) { (void) fprintf(fp, "\n%-16s %-4s %-3s %-3s %-4s %s\n", "NAME", "ID", "KND", "SCP", "FLAG", "TYPE"); } for (i = 0; i < dp->dtdo_varlen; i++) { dtrace_difv_t *v = &dp->dtdo_vartab[i]; char kind[4], scope[4], flags[16] = { 0 }; switch (v->dtdv_kind) { case DIFV_KIND_ARRAY: (void) strcpy(kind, "arr"); break; case DIFV_KIND_SCALAR: (void) strcpy(kind, "scl"); break; default: (void) snprintf(kind, sizeof (kind), "%u", v->dtdv_kind); } switch (v->dtdv_scope) { case DIFV_SCOPE_GLOBAL: (void) strcpy(scope, "glb"); break; case DIFV_SCOPE_THREAD: (void) strcpy(scope, "tls"); break; case DIFV_SCOPE_LOCAL: (void) strcpy(scope, "loc"); break; default: (void) snprintf(scope, sizeof (scope), "%u", v->dtdv_scope); } if (v->dtdv_flags & ~(DIFV_F_REF | DIFV_F_MOD)) { (void) snprintf(flags, sizeof (flags), "/0x%x", v->dtdv_flags & ~(DIFV_F_REF | DIFV_F_MOD)); } if (v->dtdv_flags & DIFV_F_REF) (void) strcat(flags, "/r"); if (v->dtdv_flags & DIFV_F_MOD) (void) strcat(flags, "/w"); (void) fprintf(fp, "%-16s %-4x %-3s %-3s %-4s %s\n", &dp->dtdo_strtab[v->dtdv_name], v->dtdv_id, kind, scope, flags + 1, dt_dis_typestr(&v->dtdv_type, type, sizeof (type))); } if (dp->dtdo_xlmlen != 0) { (void) fprintf(fp, "\n%-4s %-3s %-12s %s\n", "XLID", "ARG", "MEMBER", "TYPE"); } for (i = 0; i < dp->dtdo_xlmlen; i++) { dt_node_t *dnp = dp->dtdo_xlmtab[i]; dt_xlator_t *dxp = dnp->dn_membexpr->dn_xlator; (void) fprintf(fp, "%-4u %-3d %-12s %s\n", (uint_t)dxp->dx_id, dxp->dx_arg, dnp->dn_membname, dt_node_type_name(dnp, type, sizeof (type))); } if (dp->dtdo_krelen != 0) dt_dis_rtab("KREL", dp, fp, dp->dtdo_kreltab, dp->dtdo_krelen); if (dp->dtdo_urelen != 0) dt_dis_rtab("UREL", dp, fp, dp->dtdo_ureltab, dp->dtdo_urelen); } Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_error.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_error.c (revision 250811) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_error.c (revision 250812) @@ -1,234 +1,237 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ + #include #include #include static const struct { int err; const char *msg; } _dt_errlist[] = { { EDT_VERSION, "Client requested version newer than library" }, { EDT_VERSINVAL, "Version is not properly formatted or is too large" }, { EDT_VERSUNDEF, "Requested version is not supported by compiler" }, { EDT_VERSREDUCED, "Requested version conflicts with earlier setting" }, { EDT_CTF, "Unexpected libctf error" }, { EDT_COMPILER, "Error in D program compilation" }, - { EDT_NOREG, "Insufficient registers to generate code" }, { EDT_NOTUPREG, "Insufficient tuple registers to generate code" }, { EDT_NOMEM, "Memory allocation failure" }, { EDT_INT2BIG, "Integer constant table limit exceeded" }, { EDT_STR2BIG, "String constant table limit exceeded" }, { EDT_NOMOD, "Unknown module name" }, { EDT_NOPROV, "Unknown provider name" }, { EDT_NOPROBE, "No probe matches description" }, { EDT_NOSYM, "Unknown symbol name" }, { EDT_NOSYMADDR, "No symbol corresponds to address" }, { EDT_NOTYPE, "Unknown type name" }, { EDT_NOVAR, "Unknown variable name" }, { EDT_NOAGG, "Unknown aggregation name" }, { EDT_BADSCOPE, "Improper use of scoping operator in type name" }, { EDT_BADSPEC, "Overspecified probe description" }, { EDT_BADSPCV, "Undefined macro variable in probe description" }, { EDT_BADID, "Unknown probe identifier" }, { EDT_NOTLOADED, "Module is no longer loaded" }, { EDT_NOCTF, "Module does not contain any CTF data" }, { EDT_DATAMODEL, "Module and program data models do not match" }, { EDT_DIFVERS, "Library uses newer DIF version than kernel" }, { EDT_BADAGG, "Unknown aggregating action" }, { EDT_FIO, "Error occurred while reading from input stream" }, { EDT_DIFINVAL, "DIF program content is invalid" }, { EDT_DIFSIZE, "DIF program exceeds maximum program size" }, { EDT_DIFFAULT, "DIF program contains invalid pointer" }, { EDT_BADPROBE, "Invalid probe specification" }, { EDT_BADPGLOB, "Probe description has too many globbing characters" }, { EDT_NOSCOPE, "Declaration scope stack underflow" }, { EDT_NODECL, "Declaration stack underflow" }, { EDT_DMISMATCH, "Data record list does not match statement" }, { EDT_DOFFSET, "Data record offset exceeds buffer boundary" }, { EDT_DALIGN, "Data record has inappropriate alignment" }, { EDT_BADOPTNAME, "Invalid option name" }, { EDT_BADOPTVAL, "Invalid value for specified option" }, { EDT_BADOPTCTX, "Option cannot be used from within a D program" }, { EDT_CPPFORK, "Failed to fork preprocessor" }, { EDT_CPPEXEC, "Failed to exec preprocessor" }, { EDT_CPPENT, "Preprocessor not found" }, { EDT_CPPERR, "Preprocessor failed to process input program" }, { EDT_SYMOFLOW, "Symbol table identifier space exhausted" }, { EDT_ACTIVE, "Operation illegal when tracing is active" }, { EDT_DESTRUCTIVE, "Destructive actions not allowed" }, { EDT_NOANON, "No anonymous tracing state" }, { EDT_ISANON, "Can't claim anonymous state and enable probes" }, { EDT_ENDTOOBIG, "END enablings exceed size of principal buffer" }, { EDT_NOCONV, "Failed to load type for printf conversion" }, { EDT_BADCONV, "Incomplete printf conversion" }, { EDT_BADERROR, "Invalid library ERROR action" }, { EDT_ERRABORT, "Abort due to error" }, { EDT_DROPABORT, "Abort due to drop" }, { EDT_DIRABORT, "Abort explicitly directed" }, { EDT_BADRVAL, "Invalid return value from callback" }, { EDT_BADNORMAL, "Invalid normalization" }, { EDT_BUFTOOSMALL, "Enabling exceeds size of buffer" }, { EDT_BADTRUNC, "Invalid truncation" }, { EDT_BUSY, "DTrace cannot be used when kernel debugger is active" }, { EDT_ACCESS, "DTrace requires additional privileges" }, { EDT_NOENT, "DTrace device not available on system" }, { EDT_BRICKED, "Abort due to systemic unresponsiveness" }, { EDT_HARDWIRE, "Failed to load language definitions" }, { EDT_ELFVERSION, "libelf is out-of-date with respect to libdtrace" }, { EDT_NOBUFFERED, "Attempt to buffer output without handler" }, { EDT_UNSTABLE, "Description matched an unstable set of probes" }, { EDT_BADSETOPT, "Invalid setopt() library action" }, { EDT_BADSTACKPC, "Invalid stack program counter size" }, { EDT_BADAGGVAR, "Invalid aggregation variable identifier" }, { EDT_OVERSION, "Client requested deprecated version of library" }, { EDT_ENABLING_ERR, "Failed to enable probe" } }; static const int _dt_nerr = sizeof (_dt_errlist) / sizeof (_dt_errlist[0]); const char * dtrace_errmsg(dtrace_hdl_t *dtp, int error) { const char *str; int i; if (error == EDT_COMPILER && dtp != NULL && dtp->dt_errmsg[0] != '\0') str = dtp->dt_errmsg; else if (error == EDT_CTF && dtp != NULL && dtp->dt_ctferr != 0) str = ctf_errmsg(dtp->dt_ctferr); else if (error >= EDT_BASE && (error - EDT_BASE) < _dt_nerr) { for (i = 0; i < _dt_nerr; i++) { if (_dt_errlist[i].err == error) return (_dt_errlist[i].msg); } str = NULL; } else str = strerror(error); return (str ? str : "Unknown error"); } int dtrace_errno(dtrace_hdl_t *dtp) { return (dtp->dt_errno); } #if defined(sun) int dt_set_errno(dtrace_hdl_t *dtp, int err) { dtp->dt_errno = err; return (-1); } #else int _dt_set_errno(dtrace_hdl_t *dtp, int err, const char *errfile, int errline) { dtp->dt_errno = err; dtp->dt_errfile = errfile; dtp->dt_errline = errline; return (-1); } void dt_get_errloc(dtrace_hdl_t *dtp, const char **p_errfile, int *p_errline) { *p_errfile = dtp->dt_errfile; *p_errline = dtp->dt_errline; } #endif void dt_set_errmsg(dtrace_hdl_t *dtp, const char *errtag, const char *region, const char *filename, int lineno, const char *format, va_list ap) { size_t len, n; char *p, *s; s = dtp->dt_errmsg; n = sizeof (dtp->dt_errmsg); if (errtag != NULL && (yypcb->pcb_cflags & DTRACE_C_ETAGS)) (void) snprintf(s, n, "[%s] ", errtag); else s[0] = '\0'; len = strlen(dtp->dt_errmsg); s = dtp->dt_errmsg + len; n = sizeof (dtp->dt_errmsg) - len; if (filename == NULL) filename = dtp->dt_filetag; if (filename != NULL) (void) snprintf(s, n, "\"%s\", line %d: ", filename, lineno); else if (lineno != 0) (void) snprintf(s, n, "line %d: ", lineno); else if (region != NULL) (void) snprintf(s, n, "in %s: ", region); len = strlen(dtp->dt_errmsg); s = dtp->dt_errmsg + len; n = sizeof (dtp->dt_errmsg) - len; (void) vsnprintf(s, n, format, ap); if ((p = strrchr(dtp->dt_errmsg, '\n')) != NULL) *p = '\0'; /* remove trailing \n from message buffer */ dtp->dt_errtag = errtag; } /*ARGSUSED*/ const char * dtrace_faultstr(dtrace_hdl_t *dtp, int fault) { int i; static const struct { int code; const char *str; } faults[] = { { DTRACEFLT_BADADDR, "invalid address" }, { DTRACEFLT_BADALIGN, "invalid alignment" }, { DTRACEFLT_ILLOP, "illegal operation" }, { DTRACEFLT_DIVZERO, "divide-by-zero" }, { DTRACEFLT_NOSCRATCH, "out of scratch space" }, { DTRACEFLT_KPRIV, "invalid kernel access" }, { DTRACEFLT_UPRIV, "invalid user access" }, { DTRACEFLT_TUPOFLOW, "tuple stack overflow" }, { DTRACEFLT_BADSTACK, "bad stack" }, { DTRACEFLT_LIBRARY, "library-level fault" }, { 0, NULL } }; for (i = 0; faults[i].str != NULL; i++) { if (faults[i].code == fault) return (faults[i].str); } return ("unknown fault"); } Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_errtags.h =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_errtags.h (revision 250811) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_errtags.h (revision 250812) @@ -1,275 +1,276 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2011, Joyent, Inc. All rights reserved. - * Copyright (c) 2011 by Delphix. All rights reserved. + * Copyright (c) 2012 by Delphix. All rights reserved. */ #ifndef _DT_ERRTAGS_H #define _DT_ERRTAGS_H #ifdef __cplusplus extern "C" { #endif /* * This enum definition is used to define a set of error tags associated with * the D compiler's various error conditions. The shell script mkerrtags.sh is * used to parse this file and create a corresponding dt_errtags.c source file. * If you do something other than add a new error tag here, you may need to * update the mkerrtags shell script as it is based upon simple regexps. */ typedef enum { D_UNKNOWN, /* unknown D compiler error */ D_SYNTAX, /* syntax error in input stream */ D_EMPTY, /* empty translation unit */ D_TYPE_ERR, /* type definition missing */ D_TYPE_MEMBER, /* type member not found */ D_ASRELO, /* relocation remains against symbol */ D_CG_EXPR, /* tracing function called from expr */ D_CG_DYN, /* expression returns dynamic result */ D_ATTR_MIN, /* attributes less than amin setting */ D_ID_OFLOW, /* identifier space overflow */ D_PDESC_ZERO, /* probedesc matches zero probes */ D_PDESC_INVAL, /* probedesc is not valid */ D_PRED_SCALAR, /* predicate must be of scalar type */ D_FUNC_IDENT, /* function designator is not ident */ D_FUNC_UNDEF, /* function ident is not defined */ D_FUNC_IDKIND, /* function ident is of wrong idkind */ D_OFFSETOF_TYPE, /* offsetof arg is not sou type */ D_OFFSETOF_BITFIELD, /* offsetof applied to field member */ D_SIZEOF_TYPE, /* invalid sizeof type */ D_SIZEOF_BITFIELD, /* sizeof applied to field member */ D_STRINGOF_TYPE, /* invalid stringof type */ D_OP_IDENT, /* operand must be an identifier */ D_OP_INT, /* operand must be integral type */ D_OP_SCALAR, /* operand must be scalar type */ D_OP_ARITH, /* operand must be arithmetic type */ D_OP_WRITE, /* operand must be writable variable */ D_OP_LVAL, /* operand must be lvalue */ D_OP_INCOMPAT, /* operand types are not compatible */ D_OP_VFPTR, /* operand cannot be void or func ptr */ D_OP_ARRFUN, /* operand cannot be array or func */ D_OP_PTR, /* operand must be a pointer */ D_OP_SOU, /* operand must be struct or union */ D_OP_INCOMPLETE, /* operand is an incomplete type */ D_OP_DYN, /* operand cannot be of dynamic type */ D_OP_ACT, /* operand cannot be action */ D_AGG_REDEF, /* aggregation cannot be redefined */ D_AGG_FUNC, /* aggregating function required */ D_AGG_MDIM, /* aggregation used as multi-dim arr */ D_ARR_BADREF, /* access non-array using tuple */ D_ARR_LOCAL, /* cannot define local assc array */ D_DIV_ZERO, /* division by zero detected */ D_DEREF_NONPTR, /* dereference non-pointer type */ D_DEREF_VOID, /* dereference void pointer */ D_DEREF_FUNC, /* dereference function pointer */ D_ADDROF_LVAL, /* unary & applied to non-lvalue */ D_ADDROF_VAR, /* unary & applied to variable */ D_ADDROF_BITFIELD, /* unary & applied to field member */ D_XLATE_REDECL, /* translator redeclared */ D_XLATE_NOCONV, /* no conversion for member defined */ D_XLATE_NONE, /* no translator for type combo */ D_XLATE_SOU, /* dst must be struct or union type */ D_XLATE_INCOMPAT, /* translator member type incompat */ D_XLATE_MEMB, /* translator member is not valid */ D_CAST_INVAL, /* invalid cast expression */ D_PRAGERR, /* #pragma error message */ D_PRAGCTL_INVAL, /* invalid control directive */ D_PRAGMA_INVAL, /* invalid compiler pragma */ D_PRAGMA_UNUSED, /* unused compiler pragma */ D_PRAGMA_MALFORM, /* malformed #pragma argument list */ D_PRAGMA_OPTSET, /* failed to set #pragma option */ D_PRAGMA_SCOPE, /* #pragma identifier scope error */ D_PRAGMA_DEPEND, /* #pragma dependency not satisfied */ D_MACRO_UNDEF, /* macro parameter is not defined */ D_MACRO_OFLOW, /* macro parameter integer overflow */ D_MACRO_UNUSED, /* macro parameter is never used */ D_INT_OFLOW, /* integer constant overflow */ D_INT_DIGIT, /* integer digit is not valid */ D_STR_NL, /* newline in string literal */ D_CHR_NL, /* newline in character constant */ D_CHR_NULL, /* empty character constant */ D_CHR_OFLOW, /* character constant is too long */ D_IDENT_BADREF, /* identifier expected type mismatch */ D_IDENT_UNDEF, /* identifier is not known/defined */ D_IDENT_AMBIG, /* identifier is ambiguous (var/enum) */ D_SYM_BADREF, /* kernel/user symbol ref mismatch */ D_SYM_NOTYPES, /* no CTF data available for sym ref */ D_SYM_MODEL, /* module/program data model mismatch */ D_VAR_UNDEF, /* reference to undefined variable */ D_VAR_UNSUP, /* unsupported variable specification */ D_PROTO_LEN, /* prototype length mismatch */ D_PROTO_ARG, /* prototype argument mismatch */ D_ARGS_MULTI, /* description matches unstable set */ D_ARGS_XLATOR, /* no args[] translator defined */ D_ARGS_NONE, /* no args[] available */ D_ARGS_TYPE, /* invalid args[] type */ D_ARGS_IDX, /* invalid args[] index */ D_REGS_IDX, /* invalid regs[] index */ D_KEY_TYPE, /* invalid agg or array key type */ D_PRINTF_DYN_PROTO, /* dynamic size argument missing */ D_PRINTF_DYN_TYPE, /* dynamic size type mismatch */ D_PRINTF_AGG_CONV, /* improper use of %@ conversion */ D_PRINTF_ARG_PROTO, /* conversion missing value argument */ D_PRINTF_ARG_TYPE, /* conversion arg has wrong type */ D_PRINTF_ARG_EXTRA, /* extra arguments specified */ D_PRINTF_ARG_FMT, /* format string is not a constant */ D_PRINTF_FMT_EMPTY, /* format string is empty */ D_DECL_CHARATTR, /* bad attributes for char decl */ D_DECL_VOIDATTR, /* bad attributes for void decl */ D_DECL_SIGNINT, /* sign/unsign with non-integer decl */ D_DECL_LONGINT, /* long with non-arithmetic decl */ D_DECL_IDENT, /* old-style declaration or bad type */ D_DECL_CLASS, /* more than one storage class given */ D_DECL_BADCLASS, /* decl class not supported in D */ D_DECL_PARMCLASS, /* invalid class for parameter type */ D_DECL_COMBO, /* bad decl specifier combination */ D_DECL_ARRSUB, /* const int required for array size */ D_DECL_ARRNULL, /* array decl requires dim or tuple */ D_DECL_ARRBIG, /* array size too big */ D_DECL_IDRED, /* decl identifier redeclared */ D_DECL_TYPERED, /* decl type redeclared */ D_DECL_MNAME, /* member name missing */ D_DECL_SCOPE, /* scoping operator used in decl */ D_DECL_BFCONST, /* bit-field requires const size expr */ D_DECL_BFSIZE, /* bit-field size too big for type */ D_DECL_BFTYPE, /* bit-field type is not valid */ D_DECL_ENCONST, /* enum tag requires const size expr */ D_DECL_ENOFLOW, /* enumerator value overflows INT_MAX */ D_DECL_USELESS, /* useless external declaration */ D_DECL_LOCASSC, /* attempt to decl local assc array */ D_DECL_VOIDOBJ, /* attempt to decl void object */ D_DECL_DYNOBJ, /* attempt to decl dynamic object */ D_DECL_INCOMPLETE, /* declaration uses incomplete type */ D_DECL_PROTO_VARARGS, /* varargs not allowed in prototype */ D_DECL_PROTO_TYPE, /* type not allowed in prototype */ D_DECL_PROTO_VOID, /* void must be sole parameter */ D_DECL_PROTO_NAME, /* void parameter may not have a name */ D_DECL_PROTO_FORM, /* parameter name has no formal */ D_COMM_COMM, /* commit() after commit() */ D_COMM_DREC, /* commit() after data action */ D_SPEC_SPEC, /* speculate() after speculate() */ D_SPEC_COMM, /* speculate() after commit() */ D_SPEC_DREC, /* speculate() after data action */ D_AGG_COMM, /* aggregating act after commit() */ D_AGG_SPEC, /* aggregating act after speculate() */ D_AGG_NULL, /* aggregation stmt has null effect */ D_AGG_SCALAR, /* aggregating function needs scalar */ D_ACT_SPEC, /* destructive action after speculate */ D_EXIT_SPEC, /* exit() action after speculate */ D_DREC_COMM, /* data action after commit() */ D_PRINTA_PROTO, /* printa() prototype mismatch */ D_PRINTA_AGGARG, /* aggregation arg type mismatch */ D_PRINTA_AGGBAD, /* printa() aggregation not defined */ D_PRINTA_AGGKEY, /* printa() aggregation key mismatch */ D_PRINTA_AGGPROTO, /* printa() aggregation mismatch */ D_TRACE_VOID, /* trace() argument has void type */ D_TRACE_DYN, /* trace() argument has dynamic type */ D_PRINT_VOID, /* print() argument has void type */ D_PRINT_DYN, /* print() argument has dynamic type */ D_TRACEMEM_ADDR, /* tracemem() address bad type */ D_TRACEMEM_SIZE, /* tracemem() size bad type */ D_TRACEMEM_ARGS, /* tracemem() illegal number of args */ D_TRACEMEM_DYNSIZE, /* tracemem() dynamic size bad type */ D_STACK_PROTO, /* stack() prototype mismatch */ D_STACK_SIZE, /* stack() size argument bad type */ D_USTACK_FRAMES, /* ustack() frames arg bad type */ D_USTACK_STRSIZE, /* ustack() strsize arg bad type */ D_USTACK_PROTO, /* ustack() prototype mismatch */ D_LQUANT_BASETYPE, /* lquantize() bad base type */ D_LQUANT_BASEVAL, /* lquantize() bad base value */ D_LQUANT_LIMTYPE, /* lquantize() bad limit type */ D_LQUANT_LIMVAL, /* lquantize() bad limit value */ D_LQUANT_MISMATCH, /* lquantize() limit < base */ D_LQUANT_STEPTYPE, /* lquantize() bad step type */ D_LQUANT_STEPVAL, /* lquantize() bad step value */ D_LQUANT_STEPLARGE, /* lquantize() step too large */ D_LQUANT_STEPSMALL, /* lquantize() step too small */ D_QUANT_PROTO, /* quantize() prototype mismatch */ D_PROC_OFF, /* byte offset exceeds function size */ D_PROC_ALIGN, /* byte offset has invalid alignment */ D_PROC_NAME, /* invalid process probe name */ D_PROC_GRAB, /* failed to grab process */ D_PROC_DYN, /* process is not dynamically linked */ D_PROC_LIB, /* invalid process library name */ D_PROC_FUNC, /* no such function in process */ D_PROC_CREATEFAIL, /* pid probe creation failed */ D_PROC_NODEV, /* fasttrap device is not installed */ D_PROC_BADPID, /* user probe pid invalid */ D_PROC_BADPROV, /* user probe provider invalid */ D_PROC_USDT, /* problem initializing usdt */ D_CLEAR_PROTO, /* clear() prototype mismatch */ D_CLEAR_AGGARG, /* aggregation arg type mismatch */ D_CLEAR_AGGBAD, /* clear() aggregation not defined */ D_NORMALIZE_PROTO, /* normalize() prototype mismatch */ D_NORMALIZE_SCALAR, /* normalize() value must be scalar */ D_NORMALIZE_AGGARG, /* aggregation arg type mismatch */ D_NORMALIZE_AGGBAD, /* normalize() aggregation not def. */ D_TRUNC_PROTO, /* trunc() prototype mismatch */ D_TRUNC_SCALAR, /* trunc() value must be scalar */ D_TRUNC_AGGARG, /* aggregation arg type mismatch */ D_TRUNC_AGGBAD, /* trunc() aggregation not def. */ D_PROV_BADNAME, /* invalid provider name */ D_PROV_INCOMPAT, /* provider/probe interface mismatch */ D_PROV_PRDUP, /* duplicate probe declaration */ D_PROV_PRARGLEN, /* probe argument list too long */ D_PROV_PRXLATOR, /* probe argument translator missing */ D_FREOPEN_INVALID, /* frename() filename is invalid */ D_LQUANT_MATCHBASE, /* lquantize() mismatch on base */ D_LQUANT_MATCHLIM, /* lquantize() mismatch on limit */ D_LQUANT_MATCHSTEP, /* lquantize() mismatch on step */ D_LLQUANT_FACTORTYPE, /* llquantize() bad magnitude type */ D_LLQUANT_FACTORVAL, /* llquantize() bad magnitude value */ D_LLQUANT_FACTORMATCH, /* llquantize() mismatch on magnitude */ D_LLQUANT_LOWTYPE, /* llquantize() bad low mag type */ D_LLQUANT_LOWVAL, /* llquantize() bad low mag value */ D_LLQUANT_LOWMATCH, /* llquantize() mismatch on low mag */ D_LLQUANT_HIGHTYPE, /* llquantize() bad high mag type */ D_LLQUANT_HIGHVAL, /* llquantize() bad high mag value */ D_LLQUANT_HIGHMATCH, /* llquantize() mismatch on high mag */ D_LLQUANT_NSTEPTYPE, /* llquantize() bad # steps type */ D_LLQUANT_NSTEPVAL, /* llquantize() bad # steps value */ D_LLQUANT_NSTEPMATCH, /* llquantize() mismatch on # steps */ D_LLQUANT_MAGRANGE, /* llquantize() bad magnitude range */ D_LLQUANT_FACTORNSTEPS, /* llquantize() # steps < factor */ D_LLQUANT_FACTOREVEN, /* llquantize() bad # steps/factor */ D_LLQUANT_FACTORSMALL, /* llquantize() magnitude too small */ D_LLQUANT_MAGTOOBIG, /* llquantize() high mag too large */ + D_NOREG, /* no available internal registers */ D_PRINTM_ADDR, /* printm() memref bad type */ D_PRINTM_SIZE, /* printm() size bad type */ D_PRINTT_ADDR, /* printt() typeref bad type */ D_PRINTT_SIZE /* printt() size bad type */ } dt_errtag_t; extern const char *dt_errtag(dt_errtag_t); #ifdef __cplusplus } #endif #endif /* _DT_ERRTAGS_H */ Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c (revision 250811) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c (revision 250812) @@ -1,107 +1,132 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ + /* * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ #include #include #include #include #include #include +#include dt_regset_t * -dt_regset_create(ulong_t size) +dt_regset_create(ulong_t nregs) { - ulong_t n = BT_BITOUL(size + 1); /* + 1 for %r0 */ + ulong_t n = BT_BITOUL(nregs); dt_regset_t *drp = malloc(sizeof (dt_regset_t)); if (drp == NULL) return (NULL); drp->dr_bitmap = malloc(sizeof (ulong_t) * n); - drp->dr_size = size + 1; + drp->dr_size = nregs; if (drp->dr_bitmap == NULL) { dt_regset_destroy(drp); return (NULL); } bzero(drp->dr_bitmap, sizeof (ulong_t) * n); return (drp); } void dt_regset_destroy(dt_regset_t *drp) { free(drp->dr_bitmap); free(drp); } void dt_regset_reset(dt_regset_t *drp) { bzero(drp->dr_bitmap, sizeof (ulong_t) * BT_BITOUL(drp->dr_size)); } +void +dt_regset_assert_free(dt_regset_t *drp) +{ + int reg; + boolean_t fail = B_FALSE; + for (reg = 0; reg < drp->dr_size; reg++) { + if (BT_TEST(drp->dr_bitmap, reg) != 0) { + dt_dprintf("%%r%d was left allocated\n", reg); + fail = B_TRUE; + } + } + + /* + * We set this during dtest runs to check for register leaks. + */ + if (fail && getenv("DTRACE_DEBUG_REGSET") != NULL) + abort(); +} + int dt_regset_alloc(dt_regset_t *drp) { ulong_t nbits = drp->dr_size - 1; ulong_t maxw = nbits >> BT_ULSHIFT; ulong_t wx; for (wx = 0; wx <= maxw; wx++) { if (drp->dr_bitmap[wx] != ~0UL) break; } if (wx <= maxw) { ulong_t maxb = (wx == maxw) ? nbits & BT_ULMASK : BT_NBIPUL - 1; ulong_t word = drp->dr_bitmap[wx]; ulong_t bit, bx; int reg; for (bit = 1, bx = 0; bx <= maxb; bx++, bit <<= 1) { if ((word & bit) == 0) { reg = (int)((wx << BT_ULSHIFT) | bx); BT_SET(drp->dr_bitmap, reg); return (reg); } } } - return (-1); /* no available registers */ + xyerror(D_NOREG, "Insufficient registers to generate code"); + /*NOTREACHED*/ + return (-1); } void dt_regset_free(dt_regset_t *drp, int reg) { - assert(reg > 0 && reg < drp->dr_size); + assert(reg >= 0 && reg < drp->dr_size); assert(BT_TEST(drp->dr_bitmap, reg) != 0); BT_CLEAR(drp->dr_bitmap, reg); } Index: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.h =================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.h (revision 250811) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.h (revision 250812) @@ -1,53 +1,57 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ + /* * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright (c) 2012 by Delphix. All rights reserved. + */ + #ifndef _DT_REGSET_H #define _DT_REGSET_H -#pragma ident "%Z%%M% %I% %E% SMI" - #include #ifdef __cplusplus extern "C" { #endif typedef struct dt_regset { ulong_t dr_size; /* number of registers in set */ ulong_t *dr_bitmap; /* bitmap of active registers */ } dt_regset_t; extern dt_regset_t *dt_regset_create(ulong_t); extern void dt_regset_destroy(dt_regset_t *); extern void dt_regset_reset(dt_regset_t *); extern int dt_regset_alloc(dt_regset_t *); extern void dt_regset_free(dt_regset_t *, int); +extern void dt_regset_assert_free(dt_regset_t *); #ifdef __cplusplus } #endif #endif /* _DT_REGSET_H */