#include <oskit/machine/base_vm.h>
This header file provides generic virtual memory-related definitions commonly used throughout the base environment, which apply to both segmentation and paging. In particular, this file defines a set of macros and global variables which allow the rest of the base environment code in the toolkit (and the client OS, if it chooses) to maintain independence from the memory model in effect. These facilities allow code to avoid various assumptions about the relationships between kernel virtual addresses, linear addresses, and physical addresses.The following variable and associated macros are provided to convert between linear and kernel virtual addresses.
- linear_base_va
- This global variable defines the address in kernel virtual memory that corresponds to address 0 in linear memory. It is used by the following conversion macros; therefore, changing this variable changes the behavior of the associated macros.
- lintokv(la)
- This macro converts linear address la into a kernel virtual address and returns the result as an oskit_addr_t.
- kvtolin(va)
- For example, the segmentation initialization code uses kvtolin() to calculate the linear addresses of segmentation structures to be used in segment descriptor or pseudo-descriptor structures provided to the processor.
Similarly, the following variable and associated macros convert between physical and kernel virtual addresses. (Conversions between linear and physical addresses can be done by combining the two sets of macros.)
- phys_mem_va
- This global variable defines the address in kernel virtual memory that corresponds to address 0 in physical memory. It is used by the following conversion macros; therefore, changing this variable changes the behavior of the associated macros.
- phystokv(pa)
- This macro converts physical address pa into a kernel virtual address and returns the result as an oskit_addr_t. The macro makes the assumption that the specified physical address can be converted to a kernel virtual address this way: in OS kernels that do not direct-map all physical memory into the kernel's virtual address space, the caller must ensure that the supplied pa refers to a physical address that is mapped. For example, the primitive page table management code provided by the OSKit's base environment uses this macro to access page table entries given the physical address of the page table; therefore, these functions can only be used if page tables are allocated from physical pages that are direct-mapped into the kernel's address space.
- kvtophys(va)
- This macro converts kernel virtual address va into a physical address and returns the result as an oskit_addr_t. The macro assumes that the virtual address can be converted directly to a physical address this way; the caller must ensure that this is the case. For example, some operating systems only direct-map the kernel's code and statically allocated data; in such kernels, va should only refer to statically-allocated variables or data structures. This is generally sufficient for the OSKit's base environment code, which mostly operates on statically-allocated data structures; however, the OS must of course take its chosen memory model into consideration if it uses these macros as well.
XXX real_cs
Note that there is nothing in this header file that defines or relates to ``user-mode'' address spaces. This is because the base environment code in the OSKit is not concerned with user mode in any way; in fact, it doesn't even care whether or not the OS kernel implements user address spaces at all. For example, boot loaders or unprotected real-time kernels built using the OSKit probably do not need any notion of user mode at all.