fix: memory: use rigth index and addr, add page to pt before write it

This commit is contained in:
2024-10-29 15:17:59 +01:00
parent 659ba24f12
commit ff058d0ae1
4 changed files with 17 additions and 11 deletions

View File

@ -2,6 +2,7 @@
#include <stddef.h>
#include <stdint.h>
#include "debug.h"
#include "kprintf.h"
#include "memory.h"
#include "utils.h"
@ -15,11 +16,12 @@ static int16_t find_next_block(size_t nb_pages)
{
for (uint16_t pd_index = 1; pd_index < 768; pd_index++) {
if (page_directory[pd_index] == 0x02) {
if (create_page_table(pd_index) < 0)
if (add_page_table(pd_index) < 0)
return -2;
}
current_pd_index = pd_index;
current_page_table = (uint32_t *)((PT_START + pd_index) * 1024);
current_page_table =
(uint32_t *)GET_PAGE_ADDR(0, pd_index + PT_START);
for (uint16_t i = 0; i + nb_pages < PT_SIZE; i++) {
uint16_t j;
for (j = 0; current_page_table[i + j] >> 12 == i + j &&
@ -56,7 +58,7 @@ void *alloc_pages(size_t size)
current_page_table[i] =
((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
}
return (void *)(((current_pd_index * 1024) + index) * 1024);
return (void *)GET_PAGE_ADDR(current_pd_index, index);
}
int free_pages(void *page_ptr, size_t size)