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]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <sys/bitmap.h>
35 #include <dt_regset.h>
38 dt_regset_create(ulong_t size)
40 ulong_t n = BT_BITOUL(size + 1); /* + 1 for %r0 */
41 dt_regset_t *drp = malloc(sizeof (dt_regset_t));
46 drp->dr_bitmap = malloc(sizeof (ulong_t) * n);
47 drp->dr_size = size + 1;
49 if (drp->dr_bitmap == NULL) {
50 dt_regset_destroy(drp);
54 bzero(drp->dr_bitmap, sizeof (ulong_t) * n);
59 dt_regset_destroy(dt_regset_t *drp)
66 dt_regset_reset(dt_regset_t *drp)
68 bzero(drp->dr_bitmap, sizeof (ulong_t) * BT_BITOUL(drp->dr_size));
72 dt_regset_alloc(dt_regset_t *drp)
74 ulong_t nbits = drp->dr_size - 1;
75 ulong_t maxw = nbits >> BT_ULSHIFT;
78 for (wx = 0; wx <= maxw; wx++) {
79 if (drp->dr_bitmap[wx] != ~0UL)
84 ulong_t maxb = (wx == maxw) ? nbits & BT_ULMASK : BT_NBIPUL - 1;
85 ulong_t word = drp->dr_bitmap[wx];
89 for (bit = 1, bx = 0; bx <= maxb; bx++, bit <<= 1) {
90 if ((word & bit) == 0) {
91 reg = (int)((wx << BT_ULSHIFT) | bx);
92 BT_SET(drp->dr_bitmap, reg);
98 return (-1); /* no available registers */
102 dt_regset_free(dt_regset_t *drp, int reg)
104 assert(reg > 0 && reg < drp->dr_size);
105 assert(BT_TEST(drp->dr_bitmap, reg) != 0);
106 BT_CLEAR(drp->dr_bitmap, reg);