wip: start to add multiple pd for each task

This commit is contained in:
2025-02-07 15:48:13 +01:00
parent 3b798e5daa
commit 8dd5373e7f
7 changed files with 101 additions and 85 deletions

View File

@ -4,10 +4,10 @@
#include <stdint.h>
u32 *page_directory = &boot_page_directory;
u32 page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
u32 frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
u32 mem_size;
uint32_t *page_directory = &boot_page_directory;
uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
uint32_t frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
uint32_t mem_size;
struct frame_zone *head;
static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
@ -24,16 +24,16 @@ static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
static void add_frame_node(multiboot_memory_map_t *mmmt)
{
static u32 index;
static uint32_t index;
/**
* # = kernel code
* - = blank
*/
u64 start_addr = mmmt->addr;
u64 end_addr = mmmt->addr + mmmt->len;
u64 len = mmmt->len;
uint64_t start_addr = mmmt->addr;
uint64_t end_addr = mmmt->addr + mmmt->len;
uint64_t len = mmmt->len;
/** Kernel code cover all the block
* this situation:
@ -61,22 +61,21 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
end_addr = ROUND_CEIL(start_addr + len, PAGE_SIZE);
init_page_table(frame_zones_page_table, 0);
page_directory[1022] =
((u32)frame_zones_page_table - HEAP_END) | 0x03;
page_directory[1022] = ((uint32_t)frame_zones_page_table - HEAP_END) | 0x03;
frame_zones_page_table[index] =
((u32)start_addr & PAGE_MASK) | INIT_FLAGS;
((uint32_t)start_addr & PAGE_MASK) | INIT_FLAGS;
struct frame_zone *current =
(struct frame_zone *)GET_PAGE_ADDR(1022, index++);
current->frame_table = (u8 *)current + sizeof(struct frame_zone);
current->frame_table = (uint8_t *)current + sizeof(struct frame_zone);
/** 8 is cause we are using u8
/** 8 is cause we are using uint8_t
nb_frame = size / (PAGE_SIZE + 1 / 8)
cause we are using non decimal number
nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1))
*/
const u32 nb_frame = ((len * 8) / (PAGE_SIZE * 8 + 1));
const uint32_t nb_frame = ((len * 8) / (PAGE_SIZE * 8 + 1));
current->first_free_frame = 0;
current->next = NULL;
current->remaining_frames = nb_frame;
@ -85,10 +84,10 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
memset(current->frame_table, 0,
nb_frame * sizeof(*current->frame_table));
u32 i = 1;
uint32_t i = 1;
for (; i < CEIL(nb_frame, PAGE_SIZE); i++)
frame_zones_page_table[index + i] =
((u32)(start_addr + i * PAGE_SIZE) & PAGE_MASK) |
((uint32_t)(start_addr + i * PAGE_SIZE) & PAGE_MASK) |
INIT_FLAGS;
current->addr = (void *)start_addr + i * PAGE_SIZE;
index += i - 1;
@ -97,7 +96,7 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
static void init_frame_zones(void)
{
for (u32 i = 0; i < mmap_length; i++) {
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)
@ -105,12 +104,12 @@ static void init_frame_zones(void)
}
}
void init_memory(multiboot_info_t *mbd, u32 magic)
void init_memory(multiboot_info_t *mbd, uint32_t magic)
{
for (u16 i = 0; i < 0x300; i++)
for (uint16_t i = 0; i < 0x300; i++)
page_directory[i] = 0x02;
init_page_table(page_table_default, 0);
page_directory[0] = ((u32)page_table_default - HEAP_END) | 0x03;
page_directory[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
init_multiboot(mbd, magic);
init_frame_zones();
}