Physical Memory Manger
Posted: Fri Apr 06, 2012 7:49 pm
Hi,
I am following the OS development tutorial and I am at the Physical Memory Manager section.
I have a query related to the function for allocation a block of memory.
void* pmmngr_alloc_block () {
if (pmmngr_get_free_block_count() <= 0)
return 0; //out of memory
int frame = mmap_first_free ();
if (frame == -1)
return 0; //out of memory
mmap_set (frame);
physical_addr addr = frame * PMMNGR_BLOCK_SIZE;
_mmngr_used_blocks++;
return (void*)addr;
}
I am not understanding how does this return the actual physical address. As far as I understand the value of 'frame' is the number of the first free bit from
the beginning of bitmap. So how does multiplying this value by block size gives the physical address of the block ? It might be a stupid question but my confusion is that in the bitmap only first bit was set to occupied while the kernel itself starts at 1MB. So many more bits should be set. I am not understanding which frame is the first frame in bitmap. Is it the first frame of memory or the first frame after kernel ends? If it is the first frame of memory then the bit(s) corresponding to frame(s) occupied by kernel should also be set. However if it is the first frame starting from the end of kernel then the
above computation doesn't make sense. Please explain.
Please help.
I am following the OS development tutorial and I am at the Physical Memory Manager section.
I have a query related to the function for allocation a block of memory.
void* pmmngr_alloc_block () {
if (pmmngr_get_free_block_count() <= 0)
return 0; //out of memory
int frame = mmap_first_free ();
if (frame == -1)
return 0; //out of memory
mmap_set (frame);
physical_addr addr = frame * PMMNGR_BLOCK_SIZE;
_mmngr_used_blocks++;
return (void*)addr;
}
I am not understanding how does this return the actual physical address. As far as I understand the value of 'frame' is the number of the first free bit from
the beginning of bitmap. So how does multiplying this value by block size gives the physical address of the block ? It might be a stupid question but my confusion is that in the bitmap only first bit was set to occupied while the kernel itself starts at 1MB. So many more bits should be set. I am not understanding which frame is the first frame in bitmap. Is it the first frame of memory or the first frame after kernel ends? If it is the first frame of memory then the bit(s) corresponding to frame(s) occupied by kernel should also be set. However if it is the first frame starting from the end of kernel then the
above computation doesn't make sense. Please explain.
Please help.