but the address I'm requesting it allocate pages from is well within my 32 GB of memory. (Specifically, address 0x1000)
The error only doesn't occur when I request it allocate address 0x0, which doesn't make any sense to me.
Here's the code:
Code: Select all
EFI_FILE_HANDLE kernelHandle; // Kernel file handle
// Get a handle to the kernel file
uefi_call_wrapper(volumeHandle->Open, 5, volumeHandle, &kernelHandle, L"kernel.elf", EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
// Read from the kernel file and load it into memory
uint64_t kernelSize = FileSize(kernelHandle);
#define PAGE_SIZE 4096
#define PRE_ALLOC 5
// Allocate (kernelSize / PAGE_SIZE) + PRE_ALLOC pages for the kernel. UEFI initilizes the VAS as identity mapped,
// so I can't use AllocatePool, as the kernel address will be inconsistent otherwise.
UINTN numPages = (kernelSize / PAGE_SIZE) + PRE_ALLOC;
void* kernelAddress = (void*)0x1000;
Status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAddress, EfiLoaderCode, numPages, (EFI_PHYSICAL_ADDRESS*)&kernelAddress);
if (EFI_ERROR(Status) || kernelAddress == NULL)
{
Print(L"Could not allocate pages for the kernel! Stopping boot!\n");
Print(L"Failure Reason: ");
if (Status == EFI_OUT_OF_RESOURCES)
{
Print(L"EFI_OUT_OF_RESOURCES\n");
}
else if (Status == EFI_INVALID_PARAMETER)
{
Print(L"EFI_INVALID_PARAMETER\n");
}
else if (Status == EFI_NOT_FOUND)
{
Print(L"EFI_NOT_FOUND\n");
}
else if (Status == EFI_SUCCESS && kernelAddress == NULL)
{
Print(L"UNKNOWN_K_PTR_NULL\n");
}
Print(L"Please power off your machine. (I am too lazy to implement ACPI drivers)\n");
while (true) { }
}
uint8_t *kernelBuf = kernelAddress;
uefi_call_wrapper(kernelHandle->Read, 3, kernelHandle, &kernelSize, kernelBuf);
Print(L"Loaded kernel at address %x\n", kernelBuf);
while (true) { }
Here's the Github repo: https://github.com/ThatCodingGuy86/MimosaOS