Compare commits

..

No commits in common. "0c280d971b5d14a82a6f93a53da6331c4b5767cf" and "3bc05604dbe92f1a0e5b6790c06849f150adfe0b" have entirely different histories.

3 changed files with 11 additions and 8 deletions

View File

@ -13,7 +13,7 @@ void *alloc_frame(void)
struct frame_zone *it = head; struct frame_zone *it = head;
while (it && !it->remaining_frames) while (it && !it->remaining_frames)
it = it->next; it = it->next;
if (!it || it->remaining_frames == 0) { if (it->remaining_frames == 0) {
kprintf(KERN_CRIT "No memory zone available (ratio)\n"); kprintf(KERN_CRIT "No memory zone available (ratio)\n");
return NULL; return NULL;
} }

View File

@ -68,11 +68,12 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
// KERNEL code partially on the block // KERNEL code partially on the block
if (HEAP_START >= zone) { if (HEAP_START >= zone) {
const uint32_t start_space = const uint32_t len = mmmt->len -
CEIL(HEAP_START, PAGE_SIZE) * PAGE_SIZE; ((uint64_t)&_kernel_end - HEAP_END) -
const uint32_t len = mmmt->len - (start_space - (uint32_t)zone); (uint64_t)zone;
mmmt->len = CEIL(len, PAGE_SIZE) * PAGE_SIZE; mmmt->len = CEIL(len, PAGE_SIZE) * PAGE_SIZE;
zone = (void *)start_space; zone =
(void *)((uint32_t)CEIL(HEAP_START, PAGE_SIZE) * PAGE_SIZE);
} }
init_page_table(frame_zones_page_table, 0); init_page_table(frame_zones_page_table, 0);
@ -89,9 +90,9 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
/** 8 is cause we are using uint8_t /** 8 is cause we are using uint8_t
nb_frame = size / (PAGE_SIZE + 1 / 8) nb_frame = size / (PAGE_SIZE + 1 / 8)
cause we are using non decimal number cause we are using non decimal number
nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1)) nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1)) / 8
*/ */
const uint32_t nb_frame = ((mmmt->len * 8) / (PAGE_SIZE * 8 + 1)); const uint32_t nb_frame = ((mmmt->len * 8) / (PAGE_SIZE * 8 + 1)) - 1;
current->first_free_frame = 0; current->first_free_frame = 0;
current->next = NULL; current->next = NULL;

View File

@ -7,6 +7,8 @@
#include "memory.h" #include "memory.h"
#include "utils.h" #include "utils.h"
#define MAX_TLB_ENTRIES 32
static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr, static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
uint32_t **page_table_ptr) uint32_t **page_table_ptr)
{ {
@ -47,7 +49,7 @@ void *alloc_pages(size_t size)
void *frame = alloc_frame(); void *frame = alloc_frame();
if (!frame) { if (!frame) {
for (size_t j = index; j < i; j++) for (size_t j = index; j < i; j++)
free_frame((void *)(page_table[j] & PAGE_MASK)); free_frame((void *)(page_table[j] >> 12));
return NULL; return NULL;
} }
page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS; page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;