Add: starting to allow dynamic page allocation

This commit is contained in:
brice.boisson 2023-09-11 22:46:02 +09:00
parent df52b4aca2
commit 4339d5e349
2 changed files with 42 additions and 17 deletions

View File

@ -3,21 +3,20 @@ OUTPUT_FORMAT("elf32-i386")
SECTIONS SECTIONS
{ {
.text : ALIGN(CONSTANT(MAXPAGESIZE)) { .text : ALIGN(CONSTANT(MAXPAGESIZE)) {
_TEXT_START_ = .; _TEXT_START_ = .;
*(.multiboot) *(.text) *(.multiboot) *(.text)
_TEXT_END_ = .; _TEXT_END_ = .;
} }
.data : ALIGN(CONSTANT(MAXPAGESIZE)) { .data : ALIGN(CONSTANT(MAXPAGESIZE)) {
_DATA_START_ = .; _DATA_START_ = .;
*(.data) *(.data)
_DATA_END_ = .; }
}
.bss : ALIGN(CONSTANT(MAXPAGESIZE)) { .bss : ALIGN(CONSTANT(MAXPAGESIZE)) {
_BSS_START_ = .; _BSS_START_ = .;
*(.bss) *(.bss)
_BSS_END_ = .; _BSS_END_ = .;
} }
} }

View File

@ -3,8 +3,30 @@
#include "debug.h" #include "debug.h"
#include "serial.h" #include "serial.h"
struct page_directory_entry *page_dir = 0x5000; //__attribute__((aligned(4096))); struct page_directory_entry *page_dir; // = 0x3000000; //__attribute__((aligned(4096)));
struct page_table_entry *page_table = 0x6000; //__attribute__((aligned(4096))); struct page_table_entry *page_table; // = 0x3010000; //__attribute__((aligned(4096)));
u8 page_avl[131072] = { 0 };
int page_avl_index = 0x300000 / 8;
int find_page_avl(void)
{
for (int i = page_avl_index; i < 131071; i++) {
for (int j = 0; j < 8; j++) {
if ((page_avl[i] & (1 << j)) == 0) {
page_avl_index = i;
return i * 8 + j;
}
}
}
// TODO : Add memory deallocation policies
return -1;
}
void set_page(int address)
{
page_avl[address / 8] |= (1 << (address % 8));
}
struct page_directory_param { struct page_directory_param {
u8 P; u8 P;
@ -75,6 +97,9 @@ struct page_table_entry create_page_table_entry(struct page_table_param param)
int make_page(void) int make_page(void)
{ {
page_dir = (struct page_directory_entry *) 0x3000000;
page_table = (struct page_table_entry *) 0x3010000;
for (int i = 0; i < 1024; i++) for (int i = 0; i < 1024; i++)
{ {
page_table[i] = create_page_table_entry((struct page_table_param) { page_table[i] = create_page_table_entry((struct page_table_param) {
@ -132,6 +157,7 @@ int make_page(void)
DEBUG_INFO("address of Page Directory Array: %d", page_dir); DEBUG_INFO("address of Page Directory Array: %d", page_dir);
DEBUG_INFO("address of the first Page Table array: %d", page_table); DEBUG_INFO("address of the first Page Table array: %d", page_table);
// load page directory and enable paging (cr0 bit 31)
asm volatile (" \ asm volatile (" \
mov %0, %%eax \n \ mov %0, %%eax \n \
mov %%eax, %%cr3 \n \ mov %%eax, %%cr3 \n \