as an amateur os developer, I'm still stuck in the world of memory management, confused as to what would be a reasonably good design and implementation method. Nevertheless, I decided to implement basic memory management using bitmaps just so that I could get a jump start and probably switch to something better as the code matures. My question is regarding my implemetation of a bitmap based allocation technique as shown below. I am using this function to allocate 4k slots in the kernel virtual address space which will be mapped to physical pages.
Code: Select all
static void* mp_bitmap;
static uint32 mp_bitmap_i32 =0;
static uint16 mp_bitmap_i16 =0;
static uint8 mp_bitmap_i8 =0;
uint32 get_slot()
{
uint8 b, bit;
if ( ((uint32*)(mp_bitmap))[mp_bitmap_i32] == 0xFFFFFFFF)
for(mp_bitmap_i32 = 0;
((uint32*)(mp_bitmap))[mp_bitmap_i32] == 0xFFFFFFFF; ++mp_bitmap_i32);
if ( ((uint16*)(mp_bitmap))[mp_bitmap_i16] == 0xFFFF)
for(mp_bitmap_i16 = mp_bitmap_i32*4;
((uint16*)(mp_bitmap))[mp_bitmap_i16] == 0xFFFF; ++mp_bitmap_i16);
if ( ((uint8*)(mp_bitmap))[mp_bitmap_i8] == 0xFF)
for(mp_bitmap_i8 = mp_bitmap_i16*2;
((uint8*)(mp_bitmap))[mp_bitmap_i8] == 0xFF; ++mp_bitmap_i8);
b = ((uint8*)mp_bitmap)[mp_bitmap_i8];
for(bit = 7; b & 1; b = b >> 1)
bit--;
((uint8*)mp_bitmap)[mp_bitmap_i8] |= (0x80 >> bit);
return ((mp_bitmap_i8) * 8) + (bit);
}
Vivek