24 Print(L
"Initializing basic allocator... ");
28 if (EFI_ERROR(status))
30 Print(L
"failed to initialize memory map (0x%lx)!\n", status);
38 if (desc->Type == EfiConventionalMemory)
40 availPages += desc->NumberOfPages;
46 Print(L
"basic alloc using %llu pages... ",
basicAllocator.maxPages);
48 status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiLoaderData,
basicAllocator.maxPages,
50 if (EFI_ERROR(status))
52 Print(L
"failed to allocate buffer (0x%lx)!\n", status);
66 EFI_STATUS status = EFI_SUCCESS;
71 return EFI_OUT_OF_RESOURCES;
95 uint32_t color = 0xFF000000 | (red << 16) | (green << 8) | (blue);
116 for (
uint64_t i = 0; i < amount; i++)
139 maxAddress =
MAX(maxAddress, desc->PhysicalStart + desc->NumberOfPages *
PAGE_SIZE);
161 if (
page_table_map(table, (
void*)desc->VirtualStart, (
void*)desc->PhysicalStart, desc->NumberOfPages,
#define BOOT_MEMORY_MAP_GET_DESCRIPTOR(map, index)
EFI_STATUS mem_map_init(boot_memory_map_t *map)
Initialize and load the memory map provided by the UEFI firmware.
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.
#define MEM_BASIC_ALLOCATOR_RESERVE_PERCENTAGE
The percentage of available memory that we will reserve for the basic allocator.
#define MEM_BASIC_ALLOCATOR_MIN_PAGES
The minimum amount of pages that we will reserve for the basic allocator.
void mem_map_deinit(boot_memory_map_t *map)
Deinitializes the memory map and frees any allocated resources.
EFI_STATUS mem_init(void)
Initializes the basic memory allocator.
#define NORETURN
GCC noreturn function attribute.
#define PML_CALLBACK_NONE
Special callback ID that indicates no callback is associated with the page.
static uint64_t page_table_map(page_table_t *table, void *virtAddr, void *physAddr, uint64_t pageAmount, pml_flags_t flags, pml_callback_id_t callbackId)
Maps a range of virtual addresses to physical addresses in the page table.
#define PML_LOWER_HALF_END
The end of the lower half of the address space.
#define PML_LOWER_TO_HIGHER(addr)
Converts an address from the lower half to the higher half.
static uint64_t page_table_init(page_table_t *table, pml_alloc_pages_t allocPages, pml_free_pages_t freePages)
Initializes a page table.
#define PML_HIGHER_HALF_START
The start of the higher half of the address space.
#define PAGE_SIZE
Memory page size.
#define BYTES_TO_PAGES(amount)
Convert bytes to pages.
#define NULL
Pointer error value.
#define ERR
Integer error value.
static NORETURN void panic_without_boot_services(uint8_t red, uint8_t green, uint8_t blue)
EFI_PHYSICAL_ADDRESS buffer
static uint64_t basic_allocator_alloc_pages(void **pages, uint64_t amount)
struct @29 basicAllocator
__UINTPTR_TYPE__ uintptr_t
EFI_MEMORY_DESCRIPTOR * descriptors