Compare commits
3 Commits
3bc05604db
...
0c280d971b
Author | SHA1 | Date | |
---|---|---|---|
0c280d971b | |||
94b2fa340c | |||
ec3a038a36 |
@ -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->remaining_frames == 0) {
|
if (!it || 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;
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,11 @@ 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 len = mmmt->len -
|
const uint32_t start_space =
|
||||||
((uint64_t)&_kernel_end - HEAP_END) -
|
CEIL(HEAP_START, PAGE_SIZE) * PAGE_SIZE;
|
||||||
(uint64_t)zone;
|
const uint32_t len = mmmt->len - (start_space - (uint32_t)zone);
|
||||||
mmmt->len = CEIL(len, PAGE_SIZE) * PAGE_SIZE;
|
mmmt->len = CEIL(len, PAGE_SIZE) * PAGE_SIZE;
|
||||||
zone =
|
zone = (void *)start_space;
|
||||||
(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);
|
||||||
@ -90,9 +89,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)) / 8
|
nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1))
|
||||||
*/
|
*/
|
||||||
const uint32_t nb_frame = ((mmmt->len * 8) / (PAGE_SIZE * 8 + 1)) - 1;
|
const uint32_t nb_frame = ((mmmt->len * 8) / (PAGE_SIZE * 8 + 1));
|
||||||
|
|
||||||
current->first_free_frame = 0;
|
current->first_free_frame = 0;
|
||||||
current->next = NULL;
|
current->next = NULL;
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
#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)
|
||||||
{
|
{
|
||||||
@ -49,7 +47,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] >> 12));
|
free_frame((void *)(page_table[j] & PAGE_MASK));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
|
page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
|
||||||
|
Loading…
Reference in New Issue
Block a user