-
Notifications
You must be signed in to change notification settings - Fork 3
Pagination
Silcos kernel uses the memory protection and organization technique known as paging. In this technique, each virtual address is mapped to a physical address in blocks known as pages. These pages can be of various sizes - 4KB and 2MB (IA32, PAE). The blocks in physical memory are known as page-frames and in virtual memory they are called only pages.
The kernel supports various functions to control memory paging in a cross-platform manner. The functions `EnsureUsability, EnsureMapping, EnsureFaulty** operate on single pages in memory.
The KernelHost is supposed to expose an interface for managing page-tables and mapping ranges of virtual addresses to physical addresses in a platform-independent manner. Note that this responsibility does not come under the jurisdiction of the HAL as it is considered primitive and therefore kernel-initialization directly depends on pagination support. This is done through the header Memory/Pager.h
in which the struct CONTEXT
is given and various utility function prototypes to manipulate the object.
Module: KernelHost
File: IA32/Boot/Pager.cpp
Prototype:
decl_c void EnsureMapping(unsigned long vaddr, PADDRESS paddr, CONTEXT *cxt, unsigned long frFlags, PAGE_ATTRIBUTES pgAttr);
Summary:
This function maps the given physical address paddr
to the virtual address vaddr
that resides in the address space represented by the given context object. If the virtual address is kernel-owned, then null
is also a valid argument for the context object.
The caller can set the flags by which the page-table is to be allocated from the page-frame manager using allocation flags. This can be necessary when the kernel has not fully initialization or if the call is coming from a interrupt-handler.
Parameters:
-
vaddr - the virtual address of the page that needs to be mapped. This need not be 4-KB aligned as it will be automatically by this function.
-
paddr - the physical address to which the page is to be mapped. This should be 4-KB aligned otherwise the flags for mapping may be corrupted.
-
cxt - address in which the virtual-address resides.
-
frFlags - allocation-flags for the page-frame allocator; used if the page-table for mapping was not already present in the page-directory. This can be used to turn frame-caching off or keeping interrupts off.
-
pgAttr - attributes of mapping. (see page-transalator)
Module: KernelHost
File: IA32/Paging/Pager.cpp
Prototype:
decl_c void EnsureUsability(unsigned long address, CONTEXT *cxt, unsigned long frFrames, PAGE_ATTRIBUTES pgAttr);
Summary:
This function ensures that the page at the given virtual address address
is mapped to a valid page-frame by allocating one before mapping it. In other words, it ensures that the page is usable and will not cause a page-fault on reading (and writing unless the PageReadWrite
attribute wasn't passed).
Parameters:
-
address - the virtual address of the page to be used. It need not be 4-KB aligned as it will be automatically.
-
cxt - the context in which the virtual address resides. Note that if the address is kernel-owned, then
null
should be passed as the argument. -
frFlags - allocation flags for getting a page-frame; these will also be used in case the page-table also needs allocation.
-
pgAttr - attributes for mapping the page.