/* Calcite, src/kernel/paging.h * Copyright 2025-2026 Benji Dial * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #pragma once #include extern uint64_t kernel_p3_physical_address; //kernel physical and virtual bases are passed so that we can compute the //physical addresses of the kernel's statically allocated paging structures. void init_paging(uint64_t kernel_physical_base, void *kernel_virtual_base); //base and length should be page-aligned void mark_physical_memory_free(uint64_t base, uint64_t length); //maps one page. physical and virtual bases should be page-aligned. //virtual address should be within kernel range. void map_in_kernel_page_table( uint64_t physical_base, void *virtual_base, int writable, int executable); //virtual base should be page-aligned and within kernel range. void create_kernel_guard_page(void *virtual_base); //unmaps one page. base should be page-aligned and within kernel range. void unmap_kernel_page(void *virtual_base); //unmaps one page, and frees the corresponding physical page. //base should be page-aligned and within kernel range. void unmap_and_free_kernel_page(void *virtual_base); //returns a region of contiguous pages in kernel virtual memory where nothing //is mapped. length should be page-aligned. void *find_free_kernel_region(uint64_t length); uint64_t take_free_physical_page(); //implemented in paging.asm. the continuation should be noreturn. [[noreturn]] void switch_to_kernel_page_tables(void (*continuation)()); //returns the top void *create_syscall_stack(); void destroy_syscall_stack(void *stack_top); //return value in bytes uint64_t count_free_pram(); //return value in bytes uint64_t count_free_kernel_vram();