using a bitmap?
using a bitmap?
how would a use a bitmap for memory management? how do i even implement one in C?
oh microsoft, microsoft, what souls you have dismayed
Each bit in the bitmap would represent a PTE (Page Table Entry) or a PDE (Page Directory Entry). The bit should be set to 1 if and only if its corresponding PTE/PDE is allocated/present/etc.
I don't recommend using a bitmap because as small as it might seem to be, you can still use the 3 available bits of each PTE/PDE to determine whether it is allocated or not. Those bits are Bit 9, 10 and 11.
I use them to determine if that particular PTE is Moveable/Committed/Reserved.
I don't recommend using a bitmap because as small as it might seem to be, you can still use the 3 available bits of each PTE/PDE to determine whether it is allocated or not. Those bits are Bit 9, 10 and 11.
I use them to determine if that particular PTE is Moveable/Committed/Reserved.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
In C, use bit operations as follows:
Cheers,
Adam
Code: Select all
unsigned long my_bitmap[size];
;to set a bit:
my_bitmap[x] |= (1<<bittoset);
;to clear a bit:
my_bitmap[x]&=~(1<<bittoclear);
;to test a bit:
if(my_bitmap[x]&(1<<bittotest))
{
}
Adam
thanks
thanks for all the info. i know about page table entries and i am going to make the pages 4MB each, with a array of structures containg information on register saving, stack, etc.
oh microsoft, microsoft, what souls you have dismayed
- Kevin McGuire
- Member
- Posts: 843
- Joined: Tue Nov 09, 2004 12:00 am
- Location: United States
- Contact:
my_bitmap[bitnum/8] |= (1<<(bitnum%8 )); // set bit high
my_bitmap[bitnum/8] &= ~(1<<(bitnum%8 )); // set bit low
if(my_bitmap[bitnum/8] & (1<<(bitnum%8 ))); // check bit high
my_bitmap[(4GB>>12)/8]
my_bitmap[(0xFFFFFFFF>>12)/8]
my_bitmap[(TotalFreeMemoryFromGrubInBytes>>12)/8]
my_bitmap[bitnum/8] &= ~(1<<(bitnum%8 )); // set bit low
if(my_bitmap[bitnum/8] & (1<<(bitnum%8 ))); // check bit high
Code: Select all
AllocPageFromBitmap(uint8_t *my_bitmap, uint32_t pageAddr)
{
if(my_bitmap[(pageAddr>>12)/8] & (1<<((pageAddr>>12)%8 ) ) )
{
/// already allocated!
}
/// allocate
my_bitmap[(pageAddr>>12)/8] &= ~(1<<((pageAddr>>12)%8 ));
}
my_bitmap[(0xFFFFFFFF>>12)/8]
my_bitmap[(TotalFreeMemoryFromGrubInBytes>>12)/8]