Changeset View
Changeset View
Standalone View
Standalone View
head/stand/efi/loader/copy.c
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
#define KERNEL_PHYSICAL_BASE (2*1024*1024) | #define KERNEL_PHYSICAL_BASE (2*1024*1024) | ||||
static void | static void | ||||
efi_verify_staging_size(unsigned long *nr_pages) | efi_verify_staging_size(unsigned long *nr_pages) | ||||
{ | { | ||||
UINTN sz; | UINTN sz; | ||||
EFI_MEMORY_DESCRIPTOR *map, *p; | EFI_MEMORY_DESCRIPTOR *map = NULL, *p; | ||||
EFI_PHYSICAL_ADDRESS start, end; | EFI_PHYSICAL_ADDRESS start, end; | ||||
UINTN key, dsz; | UINTN key, dsz; | ||||
UINT32 dver; | UINT32 dver; | ||||
EFI_STATUS status; | EFI_STATUS status; | ||||
int i, ndesc; | int i, ndesc; | ||||
unsigned long available_pages = 0; | unsigned long available_pages = 0; | ||||
sz = 0; | sz = 0; | ||||
status = BS->GetMemoryMap(&sz, 0, &key, &dsz, &dver); | |||||
for (;;) { | |||||
status = BS->GetMemoryMap(&sz, map, &key, &dsz, &dver); | |||||
if (!EFI_ERROR(status)) | |||||
break; | |||||
if (status != EFI_BUFFER_TOO_SMALL) { | if (status != EFI_BUFFER_TOO_SMALL) { | ||||
printf("Can't determine memory map size\n"); | printf("Can't read memory map: %lu\n", | ||||
return; | EFI_ERROR_CODE(status)); | ||||
goto out; | |||||
} | } | ||||
map = malloc(sz); | free(map); | ||||
status = BS->GetMemoryMap(&sz, map, &key, &dsz, &dver); | |||||
if (EFI_ERROR(status)) { | /* Allocate 10 descriptors more than the size reported, | ||||
printf("Can't read memory map\n"); | * to allow for any fragmentation caused by calling | ||||
* malloc */ | |||||
map = malloc(sz + (10 * dsz)); | |||||
if (map == NULL) { | |||||
printf("Unable to allocate memory\n"); | |||||
goto out; | goto out; | ||||
} | |||||
} | } | ||||
ndesc = sz / dsz; | ndesc = sz / dsz; | ||||
for (i = 0, p = map; i < ndesc; | for (i = 0, p = map; i < ndesc; | ||||
i++, p = NextMemoryDescriptor(p, dsz)) { | i++, p = NextMemoryDescriptor(p, dsz)) { | ||||
start = p->PhysicalStart; | start = p->PhysicalStart; | ||||
end = start + p->NumberOfPages * EFI_PAGE_SIZE; | end = start + p->NumberOfPages * EFI_PAGE_SIZE; | ||||
▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines |