Next: internals-kscript, Up: Internals
The gnufi kernel presents a slim memory interface that is used both by the loader and by the internals of the kernel itself.
The loader is responsible to feed memory information to the kernel.
It should do this by first allocating a region of the memory to hold
memory descriptor data. This is done using the efi_mm_init
function. Characteristics and attributes for different memory regions
are passed to the kernel using the efi_mm_set
function.
Note: Characteristics for the memory descriptor region must be
set manually by the loader. The kernel does not do that
itself. The memory type should be
EFI_MEMORY_TYPE_RUNTIME_SERVICES_DATA
. The loader should also
set the memory type to EFI_MEMORY_TYPE_RUNTIME_SERVICES_CODE
and EFI_MEMORY_TYPE_RUNTIME_SERVICES_DATA
for the kernels code
and data, respectively.
Note: Memory region starting at physical address zero should not be passed to the kernel as conventional memory, nor be used as memory for the memory descriptors.
Initialize memory system. addr points to the region that will be used to manage the memory descriptors. size gives the size of the memory region. Note that the memory region given to this function must be also be reserved using the
efi_mm_set
function.
Set memory type of specified range to memory type given in memory_type. The region is specified by start and end.
The efi_mm_alloc
function can be used to locate a region of
memory that is suitable for allocation, given the specified allocation
type. The caller is self responsible for changing memory type for the
resulting region.
Locate a suitable memory range for a memory allocation specified by allocate_type. num_pages gives the size of the requested memory.
The uefi specification mandates the changes to the memory descriptor database must be recorded, so that it may be noted if the database has been altered between two points. This is done using a “generation counter” that is increased when an alteration is done to the database.