4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
29 * Copyright (c) 2012 by Delphix. All rights reserved.
32 #include <sys/types.h>
33 #include <sys/bitmap.h>
38 #include <dt_regset.h>
42 dt_regset_create(ulong_t nregs)
44 ulong_t n = BT_BITOUL(nregs);
45 dt_regset_t *drp = malloc(sizeof (dt_regset_t));
50 drp->dr_bitmap = malloc(sizeof (ulong_t) * n);
53 if (drp->dr_bitmap == NULL) {
54 dt_regset_destroy(drp);
58 bzero(drp->dr_bitmap, sizeof (ulong_t) * n);
63 dt_regset_destroy(dt_regset_t *drp)
70 dt_regset_reset(dt_regset_t *drp)
72 bzero(drp->dr_bitmap, sizeof (ulong_t) * BT_BITOUL(drp->dr_size));
76 dt_regset_assert_free(dt_regset_t *drp)
79 boolean_t fail = B_FALSE;
80 for (reg = 0; reg < drp->dr_size; reg++) {
81 if (BT_TEST(drp->dr_bitmap, reg) != 0) {
82 dt_dprintf("%%r%d was left allocated\n", reg);
88 * We set this during dtest runs to check for register leaks.
90 if (fail && getenv("DTRACE_DEBUG_REGSET") != NULL)
95 dt_regset_alloc(dt_regset_t *drp)
97 ulong_t nbits = drp->dr_size - 1;
98 ulong_t maxw = nbits >> BT_ULSHIFT;
101 for (wx = 0; wx <= maxw; wx++) {
102 if (drp->dr_bitmap[wx] != ~0UL)
107 ulong_t maxb = (wx == maxw) ? nbits & BT_ULMASK : BT_NBIPUL - 1;
108 ulong_t word = drp->dr_bitmap[wx];
112 for (bit = 1, bx = 0; bx <= maxb; bx++, bit <<= 1) {
113 if ((word & bit) == 0) {
114 reg = (int)((wx << BT_ULSHIFT) | bx);
115 BT_SET(drp->dr_bitmap, reg);
121 xyerror(D_NOREG, "Insufficient registers to generate code");
127 dt_regset_free(dt_regset_t *drp, int reg)
129 assert(reg >= 0 && reg < drp->dr_size);
130 assert(BT_TEST(drp->dr_bitmap, reg) != 0);
131 BT_CLEAR(drp->dr_bitmap, reg);