Subversion Repositories HelenOS-historic

Rev

Rev 1248 | Rev 1549 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1248 Rev 1262
Line 37... Line 37...
37
#include <adt/bitmap.h>
37
#include <adt/bitmap.h>
38
#include <typedefs.h>
38
#include <typedefs.h>
39
#include <arch/types.h>
39
#include <arch/types.h>
40
#include <align.h>
40
#include <align.h>
41
#include <debug.h>
41
#include <debug.h>
-
 
42
#include <macros.h>
42
 
43
 
43
#define ALL_ONES    0xff
44
#define ALL_ONES    0xff
44
#define ALL_ZEROES  0x00
45
#define ALL_ZEROES  0x00
45
 
46
 
46
/** Initialize bitmap.
47
/** Initialize bitmap.
Line 66... Line 67...
66
void bitmap_set_range(bitmap_t *bitmap, index_t start, count_t bits)
67
void bitmap_set_range(bitmap_t *bitmap, index_t start, count_t bits)
67
{
68
{
68
    index_t i;
69
    index_t i;
69
    index_t aligned_start;
70
    index_t aligned_start;
70
    count_t lub;        /* leading unaligned bits */
71
    count_t lub;        /* leading unaligned bits */
-
 
72
    count_t amb;        /* aligned middle bits */
71
    count_t tub;        /* trailing unaligned bits */
73
    count_t tab;        /* trailing aligned bits */
72
   
74
   
73
    ASSERT(start + bits <= bitmap->bits);
75
    ASSERT(start + bits <= bitmap->bits);
74
   
76
   
75
    aligned_start = ALIGN_UP(start, 8);
77
    aligned_start = ALIGN_UP(start, 8);
76
    lub = aligned_start - start;
78
    lub = min(aligned_start - start, bits);
-
 
79
    amb = bits > lub ? bits - lub : 0;
77
    tub = (bits - lub) % 8;
80
    tab = amb % 8;
78
   
81
   
79
    if (lub) {
82
    if (lub) {
80
        /*
83
        /*
81
         * Make sure to set any leading unaligned bits.
84
         * Make sure to set any leading unaligned bits.
82
         */
85
         */
83
        bitmap->map[start / 8] |= ~((1 << (8 - lub)) - 1);
86
        bitmap->map[start / 8] |= ~((1 << (8 - lub)) - 1);
84
    }
87
    }
85
    for (i = 0; i < (bits - lub) / 8; i++) {
88
    for (i = 0; i < amb / 8; i++) {
86
        /*
89
        /*
87
         * The middle bits can be set byte by byte.
90
         * The middle bits can be set byte by byte.
88
         */
91
         */
89
        bitmap->map[aligned_start / 8 + i] = ALL_ONES;
92
        bitmap->map[aligned_start / 8 + i] = ALL_ONES;
90
    }
93
    }
91
    if (tub) {
94
    if (tab) {
92
        /*
95
        /*
93
         * Make sure to set any trailing unaligned bits.
96
         * Make sure to set any trailing aligned bits.
94
         */
97
         */
95
        bitmap->map[aligned_start / 8 + i] |= (1 << tub) - 1;
98
        bitmap->map[aligned_start / 8 + i] |= (1 << tab) - 1;
96
    }
99
    }
97
   
100
   
98
}
101
}
99
 
102
 
100
/** Clear range of bits.
103
/** Clear range of bits.
Line 106... Line 109...
106
void bitmap_clear_range(bitmap_t *bitmap, index_t start, count_t bits)
109
void bitmap_clear_range(bitmap_t *bitmap, index_t start, count_t bits)
107
{
110
{
108
    index_t i;
111
    index_t i;
109
    index_t aligned_start;
112
    index_t aligned_start;
110
    count_t lub;        /* leading unaligned bits */
113
    count_t lub;        /* leading unaligned bits */
-
 
114
    count_t amb;        /* aligned middle bits */
111
    count_t tub;        /* trailing unaligned bits */
115
    count_t tab;        /* trailing aligned bits */
112
   
116
   
113
    ASSERT(start + bits <= bitmap->bits);
117
    ASSERT(start + bits <= bitmap->bits);
114
   
118
   
115
    aligned_start = ALIGN_UP(start, 8);
119
    aligned_start = ALIGN_UP(start, 8);
116
    lub = aligned_start - start;
120
    lub = min(aligned_start - start, bits);
-
 
121
    amb = bits > lub ? bits - lub : 0;
117
    tub = (bits - lub) % 8;
122
    tab = amb % 8;
118
   
123
 
119
    if (lub) {
124
    if (lub) {
120
        /*
125
        /*
121
         * Make sure to clear any leading unaligned bits.
126
         * Make sure to clear any leading unaligned bits.
122
         */
127
         */
123
        bitmap->map[start / 8] &= (1 << (8 - lub)) - 1;
128
        bitmap->map[start / 8] &= (1 << (8 - lub)) - 1;
124
    }
129
    }
125
    for (i = 0; i < (bits - lub) / 8; i++) {
130
    for (i = 0; i < amb / 8; i++) {
126
        /*
131
        /*
127
         * The middle bits can be cleared byte by byte.
132
         * The middle bits can be cleared byte by byte.
128
         */
133
         */
129
        bitmap->map[aligned_start / 8 + i] = ALL_ZEROES;
134
        bitmap->map[aligned_start / 8 + i] = ALL_ZEROES;
130
    }
135
    }
131
    if (tub) {
136
    if (tab) {
132
        /*
137
        /*
133
         * Make sure to clear any trailing unaligned bits.
138
         * Make sure to clear any trailing aligned bits.
134
         */
139
         */
135
        bitmap->map[aligned_start / 8 + i] &= ~((1 << tub) - 1);
140
        bitmap->map[aligned_start / 8 + i] &= ~((1 << tab) - 1);
136
    }
141
    }
137
   
142
 
138
}
143
}
139
 
144
 
140
/** Copy portion of one bitmap into another bitmap.
145
/** Copy portion of one bitmap into another bitmap.
141
 *
146
 *
142
 * @param dst Destination bitmap.
147
 * @param dst Destination bitmap.