diff --git a/stand/common/metadata.c b/stand/common/metadata.c --- a/stand/common/metadata.c +++ b/stand/common/metadata.c @@ -123,14 +123,14 @@ addr = xp->f_addr + xp->f_size; } /* Pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); /* Copy our environment */ envp = addr; addr = md_copyenv(addr); /* Pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #if defined(LOADER_FDT_SUPPORT) /* Copy out FDT */ @@ -141,7 +141,7 @@ { size = fdt_copy(addr); fdtp = addr; - addr = roundup(addr + size, PAGE_SIZE); + addr = md_align(addr + size); } #endif @@ -176,7 +176,7 @@ *modulep = addr; size = md_copymodules(0, kern64); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); md = file_findmetadata(kfp, MODINFOMD_KERNEND); if (kern64) { diff --git a/stand/common/modinfo.h b/stand/common/modinfo.h --- a/stand/common/modinfo.h +++ b/stand/common/modinfo.h @@ -16,5 +16,6 @@ vm_offset_t md_copymodules(vm_offset_t addr, bool kern64); vm_offset_t md_copyenv(vm_offset_t addr); +vm_offset_t md_align(vm_offset_t addr); #endif /* COMMON_MODINFO_H */ diff --git a/stand/common/modinfo.c b/stand/common/modinfo.c --- a/stand/common/modinfo.c +++ b/stand/common/modinfo.c @@ -194,3 +194,25 @@ last = start; return(last); } + +/* + * Take the ending address and round it up to the currently required + * alignment. This typically is the page size, but is the larger of the compiled + * kernel page size, the loader page size, and the typical page size on the + * platform. + * + * XXX For the moment, it's just PAGE_SIZE to make the refactoring go faster, + * but needs to hook-in arch_loadaddr (or its replacement) functionality. + * + * Also, we may need other logical things when dealing with different types of + * page sizes and/or masking or sizes. This works well for addr and sizes, but + * not for masks. + * + * Also, this is different than the MOD_ALIGN macro above, which is used for + * aligning elements in the metadata lists, not for whare modules can begin. + */ +vm_offset_t +md_align(vm_offset_t addr) +{ + return (roundup(addr, PAGE_SIZE)); +} diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -389,18 +389,18 @@ } /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #ifdef EFI addr = build_font_module(addr); /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); addr = build_splash_module(addr); /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #endif /* Copy our environment. */ @@ -408,7 +408,7 @@ addr = md_copyenv(addr); /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #if defined(LOADER_FDT_SUPPORT) /* Handle device tree blob */ @@ -417,7 +417,7 @@ /* Pad to a page boundary */ if (dtb_size) - addr += roundup(dtb_size, PAGE_SIZE); + addr += md_align(dtb_size); #endif kfp = file_findfile(NULL, md_kerntype); @@ -461,7 +461,7 @@ #endif size = md_copymodules(0, is64); /* Find the size of the modules */ - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/i386/libi386/bootinfo32.c b/stand/i386/libi386/bootinfo32.c --- a/stand/i386/libi386/bootinfo32.c +++ b/stand/i386/libi386/bootinfo32.c @@ -118,7 +118,7 @@ addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); addr = build_font_module(addr); @@ -127,7 +127,7 @@ addr = md_copyenv(addr); /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); kfp = file_findfile(NULL, md_kerntype); if (kfp == NULL) @@ -145,7 +145,7 @@ /* Figure out the size and location of the metadata */ *modulep = addr; size = md_copymodules(0, false); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/i386/libi386/bootinfo64.c b/stand/i386/libi386/bootinfo64.c --- a/stand/i386/libi386/bootinfo64.c +++ b/stand/i386/libi386/bootinfo64.c @@ -136,7 +136,7 @@ addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); addr = build_font_module(addr); @@ -161,11 +161,11 @@ size = md_copymodules(0, true); /* copy our environment */ - envp = roundup(addr + size, PAGE_SIZE); + envp = md_align(addr + size); addr = md_copyenv(envp); /* set kernend */ - kernend = roundup(addr, PAGE_SIZE); + kernend = md_align(addr); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/userboot/userboot/bootinfo32.c b/stand/userboot/userboot/bootinfo32.c --- a/stand/userboot/userboot/bootinfo32.c +++ b/stand/userboot/userboot/bootinfo32.c @@ -99,14 +99,14 @@ addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); /* copy our environment */ envp = addr; addr = md_copyenv(addr); /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); kfp = file_findfile(NULL, md_kerntype); if (kfp == NULL) @@ -123,7 +123,7 @@ /* Figure out the size and location of the metadata */ *modulep = addr; size = md_copymodules(0, false); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/userboot/userboot/bootinfo64.c b/stand/userboot/userboot/bootinfo64.c --- a/stand/userboot/userboot/bootinfo64.c +++ b/stand/userboot/userboot/bootinfo64.c @@ -131,14 +131,14 @@ addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); /* copy our environment */ envp = addr; addr = md_copyenv(addr); /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); kfp = file_findfile(NULL, md_kerntype); if (kfp == NULL) @@ -152,7 +152,7 @@ /* Figure out the size and location of the metadata */ *modulep = addr; size = md_copymodules(0, true); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */