BarinkOS/source/kernel/bitmap.h
Nigel 656ca0baa8 KERNEL: Pre-kernel sets up the physical memory manager.
* BUG: allocated blocks is possibly incorrect!
* prekernel no longer gets compiled as being in physical memory
2022-09-03 01:00:17 +02:00

39 lines
734 B
C

#pragma once
#include <stddef.h>
#include <stdint.h>
inline void bitmap_set( uint32_t* map , int index )
{
map[index/32] |= (1 << (index % 32));
}
inline void bitmap_unset(uint32_t* map , int index)
{
map[index/32] &= ~(1 << (index % 32));
}
inline uint32_t bitmap_first_unset( uint32_t* map , int map_size)
{
for ( int i = 0 ; i < map_size ; i ++ )
{
// a bit or more is set within this byte!
if( (map[i] & 0xFFFFFFFF) > 0 ){
// which bit is set?
for(int j = 0 ; j < 32 ; j++){
if ( (map[i] & (0x00000001 << j)) > 0)
{
return (i*32)+j;
}
}
}
}
return -1;
}