summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2016-05-20 19:09:25 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2016-05-20 19:09:25 +0000
commit4a3390f1c5393143478ee646cf2d6e5436e40c82 (patch)
tree53f1e852d004333fe544a0955f35c41fbb294449
parent5a17df1c820a4c96c214bf2409809bf4bf04a760 (diff)
Attempt to allocate 32MB at the lowest address that is aligned on a 256MB
border. Our kernel currently relies on being loaded at the start of physical memory. Hopefully this algorithm achieves that. In the future I hope to make it possible to load the kernel at any 256MB aligned border such that the algorithm works even if the lowest 32MB are not available.
-rw-r--r--sys/arch/armv7/stand/efiboot/efiboot.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/sys/arch/armv7/stand/efiboot/efiboot.c b/sys/arch/armv7/stand/efiboot/efiboot.c
index 34d545c9375..9cece196adf 100644
--- a/sys/arch/armv7/stand/efiboot/efiboot.c
+++ b/sys/arch/armv7/stand/efiboot/efiboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: efiboot.c,v 1.8 2016/05/20 11:53:19 kettenis Exp $ */
+/* $OpenBSD: efiboot.c,v 1.9 2016/05/20 19:09:24 kettenis Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
@@ -294,18 +294,27 @@ u_long efi_loadaddr;
void
machdep(void)
{
- EFI_STATUS status;
- EFI_PHYSICAL_ADDRESS addr = 0x10000000;
+ EFI_PHYSICAL_ADDRESS addr;
+ EFI_STATUS status;
cninit();
- printf("pos %p\n", machdep);
-
- status = BS->AllocatePages(AllocateAddress, EfiLoaderData,
- EFI_SIZE_TO_PAGES(32 * 1024 * 1024), &addr);
- if (status != EFI_SUCCESS)
+ /*
+ * The kernel expects to be loaded at offset 0x00300000 into a
+ * block of memory aligned on a 256MB boundary. We allocate a
+ * block of 32MB of memory, which gives us plenty of room for
+ * growth.
+ */
+ for (addr = 0x10000000; addr <= 0xf0000000; addr += 0x10000000) {
+ status = BS->AllocatePages(AllocateAddress, EfiLoaderData,
+ EFI_SIZE_TO_PAGES(32 * 1024 * 1024), &addr);
+ if (status == EFI_SUCCESS) {
+ efi_loadaddr = addr;
+ break;
+ }
+ }
+ if (efi_loadaddr == 0)
printf("Can't allocate memory\n");
- efi_loadaddr = addr;
efi_heap_init();
efi_timer_init();