PatchworkOS  a7b3d61
A non-POSIX operating system.
Loading...
Searching...
No Matches
bitmap_clear_range.c
Go to the documentation of this file.
1#include <sys/bitmap.h>
2
4{
5 if (low >= high || high > map->length)
6 {
7 return;
8 }
9
10 if (low < map->firstZeroIdx)
11 {
12 map->firstZeroIdx = low;
13 }
14
15 uint64_t firstQwordIdx = low / 64;
16 uint64_t firstBitInQword = low % 64;
17 uint64_t lastQwordIdx = (high - 1) / 64;
18 uint64_t lastBitInQword = (high - 1) % 64;
19
20 if (firstQwordIdx == lastQwordIdx)
21 {
22 uint64_t mask = (~0ULL << firstBitInQword) & (~0ULL >> (63 - lastBitInQword));
23 map->buffer[firstQwordIdx] &= ~mask;
24 return;
25 }
26
27 map->buffer[firstQwordIdx] &= ~(~0ULL << firstBitInQword);
28
29 for (uint64_t i = firstQwordIdx + 1; i < lastQwordIdx; i++)
30 {
31 map->buffer[i] = 0ULL;
32 }
33
34 map->buffer[lastQwordIdx] &= ~(~0ULL >> (63 - lastBitInQword));
35}
void bitmap_clear_range(bitmap_t *map, uint64_t low, uint64_t high)
Clear a range of bits in the bitmap.
boot_memory_map_t * map
Definition mem.c:19
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Bitmap structure.
Definition bitmap.h:22
uint64_t length
Definition boot_info.h:58