|
ginnOS
The reference: libc, the libraries and the kernel
|
Go to the source code of this file.
Macros | |
| #define | PDE_PRESENT 0x001u |
| #define | PDE_READ_WRITE 0x002u |
| #define | PDE_USER 0x004u |
| #define | PDE_WRITE_THROUGH 0x008u |
| #define | PDE_CACHE_DISABLE 0x010u |
| #define | PDE_ACCESSED 0x020u |
| #define | PDE_PAGE_SIZE 0x080u |
| #define | PTE_PRESENT 0x001u |
| #define | PTE_READ_WRITE 0x002u |
| #define | PTE_USER 0x004u |
| #define | PTE_WRITE_THROUGH 0x008u |
| #define | PTE_CACHE_DISABLE 0x010u |
| #define | PTE_ACCESSED 0x020u |
| #define | PTE_DIRTY 0x040u |
| #define | PTE_GLOBAL 0x100u |
| #define | PTE_SHARED 0x200u |
| #define | PTE_KERNEL_RW (PTE_PRESENT | PTE_READ_WRITE) |
| #define | PTE_USER_RW (PTE_PRESENT | PTE_READ_WRITE | PTE_USER) |
| #define | PDE_KERNEL_RW (PDE_PRESENT | PDE_READ_WRITE) |
| #define | PDE_USER_RW (PDE_PRESENT | PDE_READ_WRITE | PDE_USER) |
| #define | PAGE_DIR_INDEX(vaddr) |
| #define | PAGE_TABLE_INDEX(vaddr) |
| #define | PAGE_FRAME(entry) |
| #define | PAGE_ENTRIES 1024u |
Typedefs | |
| typedef uint32_t | pte_t |
| typedef pte_t | page_directory_t[PAGE_ENTRIES] |
| a page directory: array of 1024 32-bit entries. | |
| typedef pte_t | page_table_t[PAGE_ENTRIES] |
| a page table: array of 1024 32-bit entries. | |
Functions | |
| void | paging_init (void) |
| initialize the paging subsystem. | |
| bool | paging_map (uintptr_t virt, phys_addr_t phys, uint32_t flags) |
| map a single 4 KiB virtual page to a physical frame. | |
| void | paging_unmap (uintptr_t virt) |
| unmap a single 4 KiB virtual page. | |
| phys_addr_t | paging_get_physical (uintptr_t virt) |
| translate a virtual address to its mapped physical address. | |
| phys_addr_t | paging_get_physical_in (phys_addr_t pd_phys, uintptr_t virt) |
| translate a virtual address to its physical address within a specific page directory (not necessarily the active one). | |
| phys_addr_t | paging_directory_address (void) |
| return the physical address of the kernel page directory. | |
| uint32_t | paging_table_count (void) |
| return the number of page tables currently allocated. | |
| bool | paging_is_enabled (void) |
| check whether paging is currently enabled (CR0.PG bit). | |
| phys_addr_t | paging_clone_directory (void) |
| clone the kernel page directory for a new process. | |
| void | paging_free_directory (phys_addr_t pd_phys) |
| free a process page directory. | |
| bool | paging_copy_user (phys_addr_t dst_phys, phys_addr_t src_phys) |
| copy the user half of one page directory into another, empty one, for fork. | |
| uint32_t | paging_count_user (phys_addr_t pd_phys) |
| count the pages of RAM mapped in the user half of a page directory (a process's resident memory). | |
| bool | paging_map_in (phys_addr_t pd_phys, uintptr_t virt, phys_addr_t phys, uint32_t flags) |
| map a page in a specific page directory (not necessarily the current one). | |
| void | paging_reserve_tables (uintptr_t start, uintptr_t end) |
| make sure the kernel page directory has a page table for every 4 MiB in [start, end). | |
| bool | paging_user_range_ok (phys_addr_t pd_phys, uintptr_t addr, size_t len, bool write) |
| check that every page of [addr, addr + len) is mapped user-accessible in a page directory (and writable, if write is set), at both the directory and the table level. | |
| uintptr_t | paging_fault_address (void) |
| read CR2, the address of the most recent page fault. | |
| phys_addr_t | paging_unmap_in (phys_addr_t pd_phys, uintptr_t virt) |
| remove a user mapping from a page directory and drop its TLB entry. | |
| bool | paging_protect_in (phys_addr_t pd_phys, uintptr_t virt, uint32_t flags) |
| change the flags of an existing user mapping, keeping its frame, and drop its TLB entry. | |
| void | paging_switch_directory (phys_addr_t pd_phys) |
| switch the active page directory (load CR3). | |
| #define PDE_PRESENT 0x001u |
| #define PDE_READ_WRITE 0x002u |
| #define PDE_USER 0x004u |
| #define PDE_WRITE_THROUGH 0x008u |
| #define PDE_CACHE_DISABLE 0x010u |
| #define PDE_ACCESSED 0x020u |
| #define PDE_PAGE_SIZE 0x080u |
| #define PTE_PRESENT 0x001u |
| #define PTE_READ_WRITE 0x002u |
| #define PTE_USER 0x004u |
| #define PTE_WRITE_THROUGH 0x008u |
| #define PTE_CACHE_DISABLE 0x010u |
| #define PTE_ACCESSED 0x020u |
| #define PTE_DIRTY 0x040u |
| #define PTE_GLOBAL 0x100u |
| #define PTE_SHARED 0x200u |
| #define PTE_KERNEL_RW (PTE_PRESENT | PTE_READ_WRITE) |
| #define PTE_USER_RW (PTE_PRESENT | PTE_READ_WRITE | PTE_USER) |
| #define PDE_KERNEL_RW (PDE_PRESENT | PDE_READ_WRITE) |
| #define PDE_USER_RW (PDE_PRESENT | PDE_READ_WRITE | PDE_USER) |
| #define PAGE_DIR_INDEX | ( | vaddr | ) |
| #define PAGE_FRAME | ( | entry | ) |
| #define PAGE_ENTRIES 1024u |
| typedef pte_t page_directory_t[PAGE_ENTRIES] |
a page directory: array of 1024 32-bit entries.
each entry points to a page table (or is not present).
| typedef pte_t page_table_t[PAGE_ENTRIES] |
a page table: array of 1024 32-bit entries.
each entry maps a 4 KiB virtual page to a physical frame.
| void paging_init | ( | void | ) |
initialize the paging subsystem.
allocates the kernel page directory, identity-maps all usable physical RAM, installs the page fault handler, loads CR3, and enables paging. must be called after heap_init() and before io_enable_interrupts().
| bool paging_map | ( | uintptr_t | virt, |
| phys_addr_t | phys, | ||
| uint32_t | flags ) |
map a single 4 KiB virtual page to a physical frame.
allocates a new page table from the PMM if the relevant PDE is not present.
| virt | virtual address (must be page-aligned). |
| phys | physical address (must be page-aligned). |
| flags | PTE flags to apply (e.g. PTE_KERNEL_RW). |
| void paging_unmap | ( | uintptr_t | virt | ) |
unmap a single 4 KiB virtual page.
clears the PTE and invalidates the TLB entry.
| virt | virtual address to unmap (must be page-aligned). |
| phys_addr_t paging_get_physical | ( | uintptr_t | virt | ) |
translate a virtual address to its mapped physical address.
walks the current kernel page directory.
| virt | virtual address to translate. |
| phys_addr_t paging_get_physical_in | ( | phys_addr_t | pd_phys, |
| uintptr_t | virt ) |
translate a virtual address to its physical address within a specific page directory (not necessarily the active one).
walks the given directory directly, so it works for a process that is not current.
| pd_phys | physical address of the page directory to walk. |
| virt | virtual address to translate. |
| phys_addr_t paging_directory_address | ( | void | ) |
return the physical address of the kernel page directory.
only valid after paging_init() has been called.
| uint32_t paging_table_count | ( | void | ) |
return the number of page tables currently allocated.
only valid after paging_init() has been called.
| bool paging_is_enabled | ( | void | ) |
check whether paging is currently enabled (CR0.PG bit).
| phys_addr_t paging_clone_directory | ( | void | ) |
clone the kernel page directory for a new process.
copies kernel entries (indices 768–1023) from the kernel page directory. user entries (indices 0–767) are left empty (not present).
| void paging_free_directory | ( | phys_addr_t | pd_phys | ) |
free a process page directory.
frees any user-space page tables (indices 0–767) and their mapped frames, then frees the directory page itself. does NOT free kernel page tables (indices 768–1023) since those are shared.
| pd_phys | physical address of the page directory to free. |
| bool paging_copy_user | ( | phys_addr_t | dst_phys, |
| phys_addr_t | src_phys ) |
copy the user half of one page directory into another, empty one, for fork.
RAM frames are shared copy-on-write: they lose write access in both directories and get one more reference each. device frames are shared as they are.
| dst_phys | the new directory (its user half must be empty). |
| src_phys | the directory to copy. |
| uint32_t paging_count_user | ( | phys_addr_t | pd_phys | ) |
count the pages of RAM mapped in the user half of a page directory (a process's resident memory).
device mappings are not counted.
| pd_phys | the directory. |
| bool paging_map_in | ( | phys_addr_t | pd_phys, |
| uintptr_t | virt, | ||
| phys_addr_t | phys, | ||
| uint32_t | flags ) |
map a page in a specific page directory (not necessarily the current one).
used to set up process address spaces before switching to them.
| pd_phys | physical address of the target page directory. |
| virt | virtual address to map (page-aligned). |
| phys | physical address to map to (page-aligned). |
| flags | PTE flags. |
make sure the kernel page directory has a page table for every 4 MiB in [start, end).
must run before the first paging_clone_directory(): clones copy the directory entries, so only tables that exist by then are shared by every address space, and later mappings in them are seen everywhere.
| start | first virtual address of the range. |
| end | first virtual address past the range. |
| bool paging_user_range_ok | ( | phys_addr_t | pd_phys, |
| uintptr_t | addr, | ||
| size_t | len, | ||
| bool | write ) |
check that every page of [addr, addr + len) is mapped user-accessible in a page directory (and writable, if write is set), at both the directory and the table level.
| pd_phys | physical address of the page directory to walk. |
| addr | first byte of the range. |
| len | length of the range in bytes (0 is always accessible). |
| write | true if the kernel will write to the range. |
| uintptr_t paging_fault_address | ( | void | ) |
read CR2, the address of the most recent page fault.
| phys_addr_t paging_unmap_in | ( | phys_addr_t | pd_phys, |
| uintptr_t | virt ) |
remove a user mapping from a page directory and drop its TLB entry.
| pd_phys | physical address of the page directory. |
| virt | page-aligned user address. |
| bool paging_protect_in | ( | phys_addr_t | pd_phys, |
| uintptr_t | virt, | ||
| uint32_t | flags ) |
change the flags of an existing user mapping, keeping its frame, and drop its TLB entry.
| pd_phys | physical address of the page directory. |
| virt | page-aligned user address. |
| flags | new PTE flags (PTE_PRESENT must be set). |
| void paging_switch_directory | ( | phys_addr_t | pd_phys | ) |
switch the active page directory (load CR3).
does not modify CR0 paging must already be enabled.
| pd_phys | physical address of the page directory to activate. |