Module Name: src
Committed By: nonaka
Date: Fri Jul 26 12:09:48 UTC 2019
Modified Files:
src/sys/arch/i386/stand/efiboot: boot.c efimemory.c
src/sys/arch/i386/stand/lib: exec.c libi386.h
Log Message:
Pre-allocate memory for the kernel space at startup.
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/i386/stand/efiboot/boot.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/i386/stand/efiboot/efimemory.c
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/i386/stand/lib/exec.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/i386/stand/lib/libi386.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/i386/stand/efiboot/boot.c
diff -u src/sys/arch/i386/stand/efiboot/boot.c:1.11 src/sys/arch/i386/stand/efiboot/boot.c:1.12
--- src/sys/arch/i386/stand/efiboot/boot.c:1.11 Thu Jun 20 17:33:31 2019
+++ src/sys/arch/i386/stand/efiboot/boot.c Fri Jul 26 12:09:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: boot.c,v 1.11 2019/06/20 17:33:31 maxv Exp $ */
+/* $NetBSD: boot.c,v 1.12 2019/07/26 12:09:48 nonaka Exp $ */
/*-
* Copyright (c) 2016 Kimihiro Nonaka <[email protected]>
@@ -226,40 +226,16 @@ clearit(void)
static void
bootit(const char *filename, int howto)
{
- EFI_STATUS status;
- EFI_PHYSICAL_ADDRESS bouncebuf;
- UINTN npages;
- u_long allocsz;
if (howto & AB_VERBOSE)
printf("booting %s (howto 0x%x)\n", sprint_bootsel(filename),
howto);
- if (count_netbsd(filename, &allocsz) < 0) {
- printf("boot: %s: %s\n", sprint_bootsel(filename),
- strerror(errno));
- return;
- }
-
- bouncebuf = EFI_ALLOCATE_MAX_ADDRESS;
- npages = EFI_SIZE_TO_PAGES(allocsz);
- status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress,
- EfiLoaderData, npages, &bouncebuf);
- if (EFI_ERROR(status)) {
- printf("boot: %s: %s\n", sprint_bootsel(filename),
- strerror(ENOMEM));
- return;
- }
-
- efi_loadaddr = bouncebuf;
- if (exec_netbsd(filename, bouncebuf, howto, 0, efi_cleanup) < 0)
+ if (exec_netbsd(filename, efi_loadaddr, howto, 0, efi_cleanup) < 0)
printf("boot: %s: %s\n", sprint_bootsel(filename),
strerror(errno));
else
printf("boot returned\n");
-
- (void) uefi_call_wrapper(BS->FreePages, 2, bouncebuf, npages);
- efi_loadaddr = 0;
}
void
Index: src/sys/arch/i386/stand/efiboot/efimemory.c
diff -u src/sys/arch/i386/stand/efiboot/efimemory.c:1.5 src/sys/arch/i386/stand/efiboot/efimemory.c:1.6
--- src/sys/arch/i386/stand/efiboot/efimemory.c:1.5 Tue Mar 27 14:15:05 2018
+++ src/sys/arch/i386/stand/efiboot/efimemory.c Fri Jul 26 12:09:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efimemory.c,v 1.5 2018/03/27 14:15:05 nonaka Exp $ */
+/* $NetBSD: efimemory.c,v 1.6 2019/07/26 12:09:48 nonaka Exp $ */
/*-
* Copyright (c) 2016 Kimihiro Nonaka <[email protected]>
@@ -64,6 +64,10 @@ static const char *efimemtypes[] = {
"PersistentMemory",
};
+#ifndef KERN_LOADSPACE_SIZE
+#define KERN_LOADSPACE_SIZE (128 * 1024 * 1024) /* 128MiB */
+#endif
+
static int
getmemtype(EFI_MEMORY_DESCRIPTOR *md)
{
@@ -231,13 +235,21 @@ void
efi_memory_probe(void)
{
EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next;
+ EFI_STATUS status;
+ EFI_PHYSICAL_ADDRESS bouncebuf;
UINTN i, n, NoEntries, MapKey, DescriptorSize, MappingSize;
UINT32 DescriptorVersion;
int memtype;
+ bouncebuf = EFI_ALLOCATE_MAX_ADDRESS;
+ status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress,
+ EfiLoaderData, EFI_SIZE_TO_PAGES(KERN_LOADSPACE_SIZE), &bouncebuf);
+ if (EFI_ERROR(status))
+ panic("couldn't allocate kernel space.");
+ efi_loadaddr = bouncebuf;
+
mdtop = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize,
&DescriptorVersion, false);
-
printf(" mem[");
for (i = 0, n = 0, md = mdtop; i < NoEntries; i++, md = next) {
next = NextMemoryDescriptor(md, DescriptorSize);
Index: src/sys/arch/i386/stand/lib/exec.c
diff -u src/sys/arch/i386/stand/lib/exec.c:1.72 src/sys/arch/i386/stand/lib/exec.c:1.73
--- src/sys/arch/i386/stand/lib/exec.c:1.72 Mon Jun 24 13:58:24 2019
+++ src/sys/arch/i386/stand/lib/exec.c Fri Jul 26 12:09:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.72 2019/06/24 13:58:24 pgoyette Exp $ */
+/* $NetBSD: exec.c,v 1.73 2019/07/26 12:09:48 nonaka Exp $ */
/*
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -573,64 +573,6 @@ out:
return -1;
}
-int
-count_netbsd(const char *file, u_long *rsz)
-{
- u_long marks[MARK_MAX];
- char kdev[64];
- char base_path[64] = "/";
- struct stat st;
- boot_module_t *bm;
- u_long sz;
- int err, fd;
-
- if (has_prekern) {
- /*
- * Hardcoded for now. Need to count both the prekern and the
- * kernel. 128MB is enough in all cases, so use that.
- */
- *rsz = (128UL << 20);
- return 0;
- }
-
- howto = AB_SILENT;
-
- memset(marks, 0, sizeof(marks));
- if ((fd = loadfile(file, marks, COUNT_KERNEL | LOAD_NOTE)) == -1)
- return -1;
- close(fd);
- marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
- (-sizeof(int));
- sz = marks[MARK_END];
-
- /* The modules must be allocated after the kernel */
- if (boot_modules_enabled) {
- extract_device(file, kdev, sizeof(kdev));
- module_base_path(base_path, sizeof(base_path));
-
- /* If the root fs type is unusual, load its module. */
- if (fsmod != NULL)
- module_add_split(fsmod, BM_TYPE_KMOD);
-
- for (bm = boot_modules; bm; bm = bm->bm_next) {
- fd = module_open(bm, 0, kdev, base_path, false);
- if (fd == -1)
- continue;
- sz = (sz + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
- err = fstat(fd, &st);
- if (err == -1 || st.st_size == -1) {
- close(fd);
- continue;
- }
- sz += st.st_size;
- close(fd);
- }
- }
-
- *rsz = sz;
- return 0;
-}
-
static void
extract_device(const char *path, char *buf, size_t buflen)
{
Index: src/sys/arch/i386/stand/lib/libi386.h
diff -u src/sys/arch/i386/stand/lib/libi386.h:1.43 src/sys/arch/i386/stand/lib/libi386.h:1.44
--- src/sys/arch/i386/stand/lib/libi386.h:1.43 Mon Jun 24 13:58:24 2019
+++ src/sys/arch/i386/stand/lib/libi386.h Fri Jul 26 12:09:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: libi386.h,v 1.43 2019/06/24 13:58:24 pgoyette Exp $ */
+/* $NetBSD: libi386.h,v 1.44 2019/07/26 12:09:48 nonaka Exp $ */
/*
* Copyright (c) 1996
@@ -43,7 +43,6 @@ void multiboot(physaddr_t, physaddr_t, p
int exec_netbsd(const char *, physaddr_t, int, int, void (*)(void));
int exec_multiboot(const char *, char *);
-int count_netbsd(const char *, u_long *);
void delay(int);
int getbasemem(void);