Commit 20eeaa3a by triazo

Add function to free page

parent 3e9db9e5
Showing with 13 additions and 1 deletions
...@@ -64,6 +64,18 @@ void* page_allocate() ...@@ -64,6 +64,18 @@ void* page_allocate()
return (void*)&_kernel_end + 0x1000 * page_number; return (void*)&_kernel_end + 0x1000 * page_number;
} }
void page_free(void* page_start)
{
if (((uint32_t)page_start & 0xfff) != 0)
{
serial_writestring("tried to free a non-page as a page");
}
uint32_t page_number = (uint32_t)(page_start - (void*)&_kernel_end) / 0x1000;
uint8_t* index = (uint8_t*) &_kernel_end + page_number / 8;
*index = ~(~*index | (1<<(8-(page_number%8))));
}
// This goes through all available memory, and maps 1 to 1 virtual memory to it. // This goes through all available memory, and maps 1 to 1 virtual memory to it.
page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot_memory_map* mmap_end) page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot_memory_map* mmap_end)
{ {
......
...@@ -32,7 +32,7 @@ extern char _kernel_end[]; ...@@ -32,7 +32,7 @@ extern char _kernel_end[];
// Allocation of pages // Allocation of pages
void* page_allocate(); void* page_allocate();
void page_free(void* page_start);
// Allocatoion of memory // Allocatoion of memory
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment