PatchworkOS
Loading...
Searching...
No Matches
Memory Management

Basic memory managment. More...

Macros

#define MEM_BASIC_ALLOCATOR_MIN_PAGES   8192
 The minimum amount of pages that we will reserve for the basic allocator.
 
#define MEM_BASIC_ALLOCATOR_RESERVE_PERCENTAGE   5
 The percentage of available memory that we will reserve for the basic allocator.
 

Functions

EFI_STATUS mem_init (void)
 Initializes the basic memory allocator.
 
EFI_STATUS mem_map_init (boot_memory_map_t *map)
 Initialize and load the memory map provided by the UEFI firmware.
 
void mem_map_deinit (boot_memory_map_t *map)
 Deinitializes the memory map and frees any allocated resources.
 
void mem_page_table_init (page_table_t *table, boot_memory_map_t *map, boot_gop_t *gop, boot_kernel_t *kernel)
 Initializes a page table for use by the kernel.
 

Detailed Description

Basic memory managment.

Handles the loading of the UEFI memory map and setting up a basic memory allocator for after we have exited boot services but before we jump to the kernel as we cant use the normal memory allocator after exiting boot services.

Macro Definition Documentation

◆ MEM_BASIC_ALLOCATOR_MIN_PAGES

#define MEM_BASIC_ALLOCATOR_MIN_PAGES   8192

The minimum amount of pages that we will reserve for the basic allocator.

Definition at line 22 of file mem.h.

◆ MEM_BASIC_ALLOCATOR_RESERVE_PERCENTAGE

#define MEM_BASIC_ALLOCATOR_RESERVE_PERCENTAGE   5

The percentage of available memory that we will reserve for the basic allocator.

This is rounded up to at least MEM_BASIC_ALLOCATOR_MIN_PAGES.

Definition at line 29 of file mem.h.

Function Documentation

◆ mem_init()

EFI_STATUS mem_init ( void  )

Initializes the basic memory allocator.

Returns
On success, EFI_SUCCESS. On failure, an error code.

Definition at line 22 of file mem.c.

References basicAllocator, BOOT_MEMORY_MAP_GET_DESCRIPTOR, boot_memory_map_t::length, map, MAX, MEM_BASIC_ALLOCATOR_MIN_PAGES, MEM_BASIC_ALLOCATOR_RESERVE_PERCENTAGE, mem_map_init(), and NULL.

Referenced by efi_main().

◆ mem_map_deinit()

void mem_map_deinit ( boot_memory_map_t map)

Deinitializes the memory map and frees any allocated resources.

Parameters
mapThe boot memory map structure to deinitialize.

Definition at line 83 of file mem.c.

References boot_memory_map_t::descriptors, boot_memory_map_t::length, map, and NULL.

Referenced by exit_boot_services().

◆ mem_map_init()

EFI_STATUS mem_map_init ( boot_memory_map_t map)

Initialize and load the memory map provided by the UEFI firmware.

Parameters
mapThe boot memory map structure to initialize.
Returns
On success, EFI_SUCCESS. On failure, an error code.

Definition at line 64 of file mem.c.

References BOOT_MEMORY_MAP_GET_DESCRIPTOR, boot_memory_map_t::descriptors, boot_memory_map_t::descSize, boot_memory_map_t::descVersion, boot_memory_map_t::key, boot_memory_map_t::length, map, NULL, and PML_LOWER_TO_HIGHER.

Referenced by exit_boot_services(), and mem_init().

◆ mem_page_table_init()

void mem_page_table_init ( page_table_t table,
boot_memory_map_t map,
boot_gop_t gop,
boot_kernel_t kernel 
)

Initializes a page table for use by the kernel.

This function sets up a new page table and maps the memory regions specified in the boot memory map, the graphics output protocol (GOP) framebuffer, and the kernel itself.

It is intended to be used after exiting UEFI boot services and will fill the screen with a solid color and halt the CPU if it encounters an error, as there is very little we can do in that situation.

Parameters
tableThe page table to initialize.
mapThe boot memory map containing memory descriptors to be mapped.
gopThe graphics output protocol information for mapping the framebuffer.
kernelThe kernel information for mapping the kernel binary.

Definition at line 125 of file mem.c.

References basic_allocator_alloc_pages(), basicAllocator, BOOT_MEMORY_MAP_GET_DESCRIPTOR, BYTES_TO_PAGES, ERR, gop, boot_memory_map_t::length, map, MAX, NULL, PAGE_SIZE, page_table_init(), page_table_map(), panic_without_boot_services(), boot_gop_t::physAddr, boot_kernel_t::physStart, PML_CALLBACK_NONE, PML_HIGHER_HALF_START, PML_LOWER_HALF_END, PML_PRESENT, PML_WRITE, boot_gop_t::size, boot_kernel_t::size, boot_gop_t::virtAddr, and boot_kernel_t::virtStart.

Referenced by exit_boot_services().