implements first free mem block

This commit is contained in:
2025-06-11 17:41:35 -04:00
parent f216c32f22
commit 98f8a0dc88
3 changed files with 13 additions and 27 deletions

View File

@ -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)