implements first free mem block
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <kernel/_kernel.h>
|
||||
#include <kernel/pmm.h>
|
||||
|
||||
/**
|
||||
@ -37,11 +40,19 @@ void __pmm_unset(int bit, uint32_t* bitmap)
|
||||
bitmap[bit / 32] &= ~(1 << (bit % 32));
|
||||
}
|
||||
|
||||
void __pmm_first_free(struct pmm_mem_info mem_block)
|
||||
int __pmm_first_free(struct pmm_mem_info mem_block)
|
||||
{
|
||||
for (uint32_t i = 0; i < PMM_GET_MEM_BLOCKS(mem_block) / 32; i++) {
|
||||
|
||||
if (mem_block.bitmap[i] == 0xFFFFFFFF) // this segment is full
|
||||
continue;
|
||||
for (int j = 0; j < 32; j++) {
|
||||
if (mem_block.bitmap[i] & (1 << j))
|
||||
continue; // this page is used
|
||||
return (i * 32) + j; // i * 32 is the chunk of 32, plus j to get to the page in the chunk
|
||||
}
|
||||
}
|
||||
kwarn("OUT OF MEMORY");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void pmm_set(int bit)
|
||||
|
Reference in New Issue
Block a user