stand: Move md_copymodules into modinfo.c and reduce copies
md_copymodules, bi_copymdoules, bi_copymodules32 (x2) and bi_copymodules64 (x2) are all the same routine... Replace them all with md_copymodules. This saves about 800 bytes on i386 BIOS loader, which is a nice bonus. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D36572
This commit is contained in:
parent
bca9c87b61
commit
5d1531d9d4
@ -93,49 +93,6 @@ md_copyenv(vm_offset_t addr)
|
||||
return(addr);
|
||||
}
|
||||
|
||||
static int align;
|
||||
#define MOD_ALIGN(l) roundup(l, align)
|
||||
|
||||
static vm_offset_t
|
||||
md_copymodules(vm_offset_t addr, int kern64)
|
||||
{
|
||||
struct preloaded_file *fp;
|
||||
struct file_metadata *md;
|
||||
uint64_t scratch64;
|
||||
uint32_t scratch32;
|
||||
int c;
|
||||
|
||||
c = addr != 0;
|
||||
/* start with the first module on the list, should be the kernel */
|
||||
for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
|
||||
|
||||
MOD_NAME(addr, fp->f_name, c); /* this field must come first */
|
||||
MOD_TYPE(addr, fp->f_type, c);
|
||||
if (fp->f_args)
|
||||
MOD_ARGS(addr, fp->f_args, c);
|
||||
if (kern64) {
|
||||
scratch64 = fp->f_addr;
|
||||
MOD_ADDR(addr, scratch64, c);
|
||||
scratch64 = fp->f_size;
|
||||
MOD_SIZE(addr, scratch64, c);
|
||||
} else {
|
||||
scratch32 = fp->f_addr;
|
||||
#ifdef __arm__
|
||||
scratch32 -= __elfN(relocation_offset);
|
||||
#endif
|
||||
MOD_ADDR(addr, scratch32, c);
|
||||
MOD_SIZE(addr, fp->f_size, c);
|
||||
}
|
||||
for (md = fp->f_metadata; md != NULL; md = md->md_next) {
|
||||
if (!(md->md_type & MODINFOMD_NOCOPY)) {
|
||||
MOD_METADATA(addr, md, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
MOD_END(addr, c);
|
||||
return(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the information expected by a kernel.
|
||||
*
|
||||
|
86
stand/common/modinfo.c
Normal file
86
stand/common/modinfo.c
Normal file
@ -0,0 +1,86 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: FreeBSD: src/sys/boot/sparc64/loader/metadata.c,v 1.6
|
||||
*/
|
||||
#include <stand.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/linker.h>
|
||||
#include <sys/boot.h>
|
||||
#include <sys/reboot.h>
|
||||
#if defined(LOADER_FDT_SUPPORT)
|
||||
#include <fdt_platform.h>
|
||||
#endif
|
||||
|
||||
#ifdef __arm__
|
||||
#include <machine/elf.h>
|
||||
#endif
|
||||
#include <machine/metadata.h>
|
||||
|
||||
#include "bootstrap.h"
|
||||
#include "modinfo.h"
|
||||
|
||||
static int align;
|
||||
#define MOD_ALIGN(l) roundup(l, align)
|
||||
|
||||
vm_offset_t
|
||||
md_copymodules(vm_offset_t addr, bool kern64)
|
||||
{
|
||||
struct preloaded_file *fp;
|
||||
struct file_metadata *md;
|
||||
uint64_t scratch64;
|
||||
uint32_t scratch32;
|
||||
int c;
|
||||
|
||||
c = addr != 0;
|
||||
/* start with the first module on the list, should be the kernel */
|
||||
for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
|
||||
|
||||
MOD_NAME(addr, fp->f_name, c); /* this field must come first */
|
||||
MOD_TYPE(addr, fp->f_type, c);
|
||||
if (fp->f_args)
|
||||
MOD_ARGS(addr, fp->f_args, c);
|
||||
if (kern64) {
|
||||
scratch64 = fp->f_addr;
|
||||
MOD_ADDR(addr, scratch64, c);
|
||||
scratch64 = fp->f_size;
|
||||
MOD_SIZE(addr, scratch64, c);
|
||||
} else {
|
||||
scratch32 = fp->f_addr;
|
||||
#ifdef __arm__
|
||||
scratch32 -= __elfN(relocation_offset);
|
||||
#endif
|
||||
MOD_ADDR(addr, scratch32, c);
|
||||
MOD_SIZE(addr, fp->f_size, c);
|
||||
}
|
||||
for (md = fp->f_metadata; md != NULL; md = md->md_next) {
|
||||
if (!(md->md_type & MODINFOMD_NOCOPY)) {
|
||||
MOD_METADATA(addr, md, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
MOD_END(addr, c);
|
||||
return(addr);
|
||||
}
|
@ -69,4 +69,6 @@
|
||||
COPY32(0, a, c); \
|
||||
}
|
||||
|
||||
vm_offset_t md_copymodules(vm_offset_t addr, bool kern64);
|
||||
|
||||
#endif /* COMMON_MODINFO_H */
|
||||
|
@ -61,11 +61,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include "geliboot.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Align to a pointer / long
|
||||
*/
|
||||
#define MOD_ALIGN(l) roundup(l, sizeof(u_long))
|
||||
|
||||
int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp,
|
||||
bool exit_bs);
|
||||
|
||||
@ -170,36 +165,6 @@ bi_copyenv(vm_offset_t start)
|
||||
return(last);
|
||||
}
|
||||
|
||||
static vm_offset_t
|
||||
bi_copymodules(vm_offset_t addr)
|
||||
{
|
||||
struct preloaded_file *fp;
|
||||
struct file_metadata *md;
|
||||
int c;
|
||||
uint64_t v;
|
||||
|
||||
c = addr != 0;
|
||||
/* Start with the first module on the list, should be the kernel. */
|
||||
for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
|
||||
MOD_NAME(addr, fp->f_name, c); /* This must come first. */
|
||||
MOD_TYPE(addr, fp->f_type, c);
|
||||
if (fp->f_args)
|
||||
MOD_ARGS(addr, fp->f_args, c);
|
||||
v = fp->f_addr;
|
||||
#if defined(__arm__)
|
||||
v -= __elfN(relocation_offset);
|
||||
#endif
|
||||
MOD_ADDR(addr, v, c);
|
||||
v = fp->f_size;
|
||||
MOD_SIZE(addr, v, c);
|
||||
for (md = fp->f_metadata; md != NULL; md = md->md_next)
|
||||
if (!(md->md_type & MODINFOMD_NOCOPY))
|
||||
MOD_METADATA(addr, md, c);
|
||||
}
|
||||
MOD_END(addr, c);
|
||||
return(addr);
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
efi_do_vmap(EFI_MEMORY_DESCRIPTOR *mm, UINTN sz, UINTN mmsz, UINT32 mmver)
|
||||
{
|
||||
@ -487,7 +452,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
|
||||
#endif
|
||||
bi_load_efi_data(kfp, exit_bs);
|
||||
|
||||
size = bi_copymodules(0);
|
||||
size = md_copymodules(0, true);
|
||||
kernend = roundup(addr + size, PAGE_SIZE);
|
||||
*kernendp = kernend;
|
||||
|
||||
@ -512,7 +477,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
|
||||
#endif
|
||||
|
||||
/* Copy module list and metadata. */
|
||||
(void)bi_copymodules(addr);
|
||||
(void)md_copymodules(addr, true);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -44,37 +44,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
static struct bootinfo bi;
|
||||
|
||||
/*
|
||||
* We have 4 byte alignment for 32-bit targets. This code is compiled as 32-bit
|
||||
* code...
|
||||
*/
|
||||
#define MOD_ALIGN(l) roundup(l, sizeof(u_long))
|
||||
|
||||
static vm_offset_t
|
||||
bi_copymodules32(vm_offset_t addr)
|
||||
{
|
||||
struct preloaded_file *fp;
|
||||
struct file_metadata *md;
|
||||
int c;
|
||||
|
||||
c = addr != 0;
|
||||
/* start with the first module on the list, should be the kernel */
|
||||
for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
|
||||
|
||||
MOD_NAME(addr, fp->f_name, c); /* this field must come first */
|
||||
MOD_TYPE(addr, fp->f_type, c);
|
||||
if (fp->f_args)
|
||||
MOD_ARGS(addr, fp->f_args, c);
|
||||
MOD_ADDR(addr, fp->f_addr, c);
|
||||
MOD_SIZE(addr, fp->f_size, c);
|
||||
for (md = fp->f_metadata; md != NULL; md = md->md_next)
|
||||
if (!(md->md_type & MODINFOMD_NOCOPY))
|
||||
MOD_METADATA(addr, md, c);
|
||||
}
|
||||
MOD_END(addr, c);
|
||||
return(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the information expected by an i386 kernel.
|
||||
*
|
||||
@ -179,7 +148,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t
|
||||
|
||||
/* Figure out the size and location of the metadata */
|
||||
*modulep = addr;
|
||||
size = bi_copymodules32(0);
|
||||
size = md_copymodules(0, false);
|
||||
kernend = roundup(addr + size, PAGE_SIZE);
|
||||
*kernendp = kernend;
|
||||
|
||||
@ -188,7 +157,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t
|
||||
bcopy(&kernend, md->md_data, sizeof kernend);
|
||||
|
||||
/* copy module list and metadata */
|
||||
(void)bi_copymodules32(addr);
|
||||
(void)md_copymodules(addr, false);
|
||||
|
||||
ssym = esym = 0;
|
||||
md = file_findmetadata(kfp, MODINFOMD_SSYM);
|
||||
|
@ -45,40 +45,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include "geliboot.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We have 8 byte alignment for 64-bit targets. This code is compiled as 64-bit
|
||||
* code...
|
||||
*/
|
||||
#define MOD_ALIGN(l) roundup(l, sizeof(uint64_t))
|
||||
|
||||
static vm_offset_t
|
||||
bi_copymodules64(vm_offset_t addr)
|
||||
{
|
||||
struct preloaded_file *fp;
|
||||
struct file_metadata *md;
|
||||
int c;
|
||||
uint64_t v;
|
||||
|
||||
c = addr != 0;
|
||||
/* start with the first module on the list, should be the kernel */
|
||||
for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
|
||||
|
||||
MOD_NAME(addr, fp->f_name, c); /* this field must come first */
|
||||
MOD_TYPE(addr, fp->f_type, c);
|
||||
if (fp->f_args)
|
||||
MOD_ARGS(addr, fp->f_args, c);
|
||||
v = fp->f_addr;
|
||||
MOD_ADDR(addr, v, c);
|
||||
v = fp->f_size;
|
||||
MOD_SIZE(addr, v, c);
|
||||
for (md = fp->f_metadata; md != NULL; md = md->md_next)
|
||||
if (!(md->md_type & MODINFOMD_NOCOPY))
|
||||
MOD_METADATA(addr, md, c);
|
||||
}
|
||||
MOD_END(addr, c);
|
||||
return(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if this CPU supports long mode.
|
||||
*/
|
||||
@ -197,7 +163,7 @@ bi_load64(char *args, vm_offset_t *modulep,
|
||||
#endif
|
||||
bi_load_vbe_data(kfp);
|
||||
|
||||
size = bi_copymodules64(0);
|
||||
size = md_copymodules(0, true);
|
||||
|
||||
/* copy our environment */
|
||||
envp = roundup(addr + size, PAGE_SIZE);
|
||||
@ -216,7 +182,7 @@ bi_load64(char *args, vm_offset_t *modulep,
|
||||
bcopy(&envp, md->md_data, sizeof envp);
|
||||
|
||||
/* copy module list and metadata */
|
||||
(void)bi_copymodules64(*modulep);
|
||||
(void)md_copymodules(*modulep, true);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ CFLAGS+=-I${LDRSRC}
|
||||
|
||||
SRCS+= boot.c commands.c console.c devopen.c interp.c
|
||||
SRCS+= interp_backslash.c interp_parse.c ls.c misc.c
|
||||
SRCS+= modinfo.c
|
||||
SRCS+= module.c nvstore.c pnglite.c tslog.c
|
||||
|
||||
CFLAGS.module.c += -I$(SRCTOP)/sys/teken -I${SRCTOP}/contrib/pnglite
|
||||
|
@ -43,36 +43,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
static struct bootinfo bi;
|
||||
|
||||
/*
|
||||
* We have 4 byte alignment for 32-bit targets.
|
||||
*/
|
||||
#define MOD_ALIGN(l) roundup(l, sizeof(uint32_t))
|
||||
|
||||
static vm_offset_t
|
||||
bi_copymodules32(vm_offset_t addr)
|
||||
{
|
||||
struct preloaded_file *fp;
|
||||
struct file_metadata *md;
|
||||
int c;
|
||||
|
||||
c = addr != 0;
|
||||
/* start with the first module on the list, should be the kernel */
|
||||
for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
|
||||
|
||||
MOD_NAME(addr, fp->f_name, c); /* this field must come first */
|
||||
MOD_TYPE(addr, fp->f_type, c);
|
||||
if (fp->f_args)
|
||||
MOD_ARGS(addr, fp->f_args, c);
|
||||
MOD_ADDR(addr, fp->f_addr, c);
|
||||
MOD_SIZE(addr, fp->f_size, c);
|
||||
for (md = fp->f_metadata; md != NULL; md = md->md_next)
|
||||
if (!(md->md_type & MODINFOMD_NOCOPY))
|
||||
MOD_METADATA(addr, md, c);
|
||||
}
|
||||
MOD_END(addr, c);
|
||||
return(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the information expected by an i386 kernel.
|
||||
*
|
||||
@ -157,7 +127,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t
|
||||
|
||||
/* Figure out the size and location of the metadata */
|
||||
*modulep = addr;
|
||||
size = bi_copymodules32(0);
|
||||
size = md_copymodules(0, false);
|
||||
kernend = roundup(addr + size, PAGE_SIZE);
|
||||
*kernendp = kernend;
|
||||
|
||||
@ -166,7 +136,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t
|
||||
bcopy(&kernend, md->md_data, sizeof kernend);
|
||||
|
||||
/* copy module list and metadata */
|
||||
(void)bi_copymodules32(addr);
|
||||
(void)md_copymodules(addr, false);
|
||||
|
||||
ssym = esym = 0;
|
||||
md = file_findmetadata(kfp, MODINFOMD_SSYM);
|
||||
|
@ -40,40 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include "modinfo.h"
|
||||
#include "libuserboot.h"
|
||||
|
||||
/*
|
||||
* We have 8 byte alignment for 64-bit targets. This code is compiled as 32-bit
|
||||
* code...
|
||||
*/
|
||||
#define MOD_ALIGN(l) roundup(l, sizeof(uint64_t))
|
||||
|
||||
static vm_offset_t
|
||||
bi_copymodules64(vm_offset_t addr)
|
||||
{
|
||||
struct preloaded_file *fp;
|
||||
struct file_metadata *md;
|
||||
int c;
|
||||
uint64_t v;
|
||||
|
||||
c = addr != 0;
|
||||
/* start with the first module on the list, should be the kernel */
|
||||
for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
|
||||
|
||||
MOD_NAME(addr, fp->f_name, c); /* this field must come first */
|
||||
MOD_TYPE(addr, fp->f_type, c);
|
||||
if (fp->f_args)
|
||||
MOD_ARGS(addr, fp->f_args, c);
|
||||
v = fp->f_addr;
|
||||
MOD_ADDR(addr, v, c);
|
||||
v = fp->f_size;
|
||||
MOD_SIZE(addr, v, c);
|
||||
for (md = fp->f_metadata; md != NULL; md = md->md_next)
|
||||
if (!(md->md_type & MODINFOMD_NOCOPY))
|
||||
MOD_METADATA(addr, md, c);
|
||||
}
|
||||
MOD_END(addr, c);
|
||||
return(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if this CPU supports long mode.
|
||||
*/
|
||||
@ -190,7 +156,7 @@ bi_load64(char *args, vm_offset_t *modulep, vm_offset_t *kernendp)
|
||||
|
||||
/* Figure out the size and location of the metadata */
|
||||
*modulep = addr;
|
||||
size = bi_copymodules64(0);
|
||||
size = md_copymodules(0, true);
|
||||
kernend = roundup(addr + size, PAGE_SIZE);
|
||||
*kernendp = kernend;
|
||||
|
||||
@ -199,7 +165,7 @@ bi_load64(char *args, vm_offset_t *modulep, vm_offset_t *kernendp)
|
||||
bcopy(&kernend, md->md_data, sizeof kernend);
|
||||
|
||||
/* copy module list and metadata */
|
||||
(void)bi_copymodules64(addr);
|
||||
(void)md_copymodules(addr, true);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user