wip: frame_allocator working pretty good (?)

core: remove physical allocatory
This commit is contained in:
2024-11-19 16:57:19 +01:00
parent e8fd6c55eb
commit 3315d85e0c
14 changed files with 61 additions and 471 deletions

View File

@ -8,28 +8,36 @@
#include "string.h"
#include "utils.h"
void *alloc_frames(size_t size)
void *alloc_frame(void)
{
const uint32_t nb_frames = CEIL(size, PAGE_SIZE);
for (uint32_t i = 0; i < mmap_length; i++) {
multiboot_memory_map_t *mmmt =
(multiboot_memory_map_t *)mmap_addr + i;
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) {
kprintf("type: %d, addr: %p, len: %u, size: %u, \n",
mmmt->type, mmmt->addr, mmmt->len, mmmt->size);
}
PRINT_PTR(mmmt);
struct frame_zone *it = head;
while (it && !it->remaining_frames)
it = it->next;
if (it->remaining_frames == 0) {
kprintf(KERN_CRIT "No memory zone available (ratio)\n");
return NULL;
}
PRINT_PTR(head);
PRINT_PTR(head->addr);
PRINT_PTR(head->frame_table);
PRINT_UINT(head->size);
PRINT_UINT(head->remaining_frames);
PRINT_PTR(head->next);
return NULL;
size_t i = it->first_free_frame;
for (; GET_FRAME(it->frame_table, i); i++)
;
it->first_free_frame++;
it->remaining_frames--;
SET_FRAME(it->frame_table, i, 1);
return it->addr + i * PAGE_SIZE;
}
int free_frames(void *frame_ptr, size_t size)
int free_frame(void *frame_ptr)
{
struct frame_zone *it = head;
while (it && (frame_ptr < it->addr || frame_ptr >= it->addr + it->len))
it = it->next;
uint32_t index =
(frame_ptr + (it->len - it->size) - it->addr) / PAGE_SIZE;
SET_FRAME(it->frame_table, index, 0);
if (it->first_free_frame > index)
it->first_free_frame = index;
it->remaining_frames++;
return 0;
}