diff options
author | msmith <msmith@FreeBSD.org> | 1998-08-31 21:10:43 +0000 |
---|---|---|
committer | msmith <msmith@FreeBSD.org> | 1998-08-31 21:10:43 +0000 |
commit | 815f3686d0275b1e63d326042e37d5244e051121 (patch) | |
tree | a32c9c92f2b120f904fc9aa7d0755d8b8a74f6b0 /sys/boot/alpha/libalpha | |
parent | c3fa37d604772f443b31aa7d26c331bd64c2675d (diff) | |
download | FreeBSD-src-815f3686d0275b1e63d326042e37d5244e051121.zip FreeBSD-src-815f3686d0275b1e63d326042e37d5244e051121.tar.gz |
Bootloader update.
- Implement a new copyin/readin interface for loading modules.
This allows the module loaders to become MI, reducing code duplication.
- Simplify the search for an image activator for the loaded kernel.
- Use the common module management code for all module metadata.
- Add an 'unload' command that throws everything away.
- Move the a.out module loader to MI code, add support for a.out
kld modules.
Submitted by: Alpha changes fixed by Doug Rabson <dfr@freebsd.org>
Diffstat (limited to 'sys/boot/alpha/libalpha')
-rw-r--r-- | sys/boot/alpha/libalpha/Makefile | 4 | ||||
-rw-r--r-- | sys/boot/alpha/libalpha/alpha_copy.c | 50 | ||||
-rw-r--r-- | sys/boot/alpha/libalpha/alpha_module.c | 18 | ||||
-rw-r--r-- | sys/boot/alpha/libalpha/elf_freebsd.c | 50 | ||||
-rw-r--r-- | sys/boot/alpha/libalpha/libalpha.h | 36 |
5 files changed, 83 insertions, 75 deletions
diff --git a/sys/boot/alpha/libalpha/Makefile b/sys/boot/alpha/libalpha/Makefile index 58bf824..92ccbdf 100644 --- a/sys/boot/alpha/libalpha/Makefile +++ b/sys/boot/alpha/libalpha/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.1.1.1 1998/08/21 03:17:42 msmith Exp $ +# $Id: Makefile,v 1.2 1998/08/22 10:31:01 dfr Exp $ LIB= alpha NOPIC= true @@ -18,7 +18,7 @@ CFLAGS+= -DDISK_DEBUG SRCS= OSFpal.c elf_freebsd.c prom.c prom_disp.S prom_swpal.S start.S \ pal.S reboot.c delay.c time.c alpha_module.c devicename.c \ - srmdisk.c srmnet.c getsecs.c + srmdisk.c srmnet.c getsecs.c alpha_copy.c all: libalpha.a diff --git a/sys/boot/alpha/libalpha/alpha_copy.c b/sys/boot/alpha/libalpha/alpha_copy.c new file mode 100644 index 0000000..9e164de --- /dev/null +++ b/sys/boot/alpha/libalpha/alpha_copy.c @@ -0,0 +1,50 @@ +/*- + * 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. + * + * $Id$ + */ +/* + * MD primitives supporting placement of module data + * + * XXX should check load address/size against memory top. + */ +#include <stand.h> + +#include "libalpha.h" + +int +alpha_copyin(void *src, vm_offset_t dest, size_t len) +{ + bcopy(src, dest, len); + return(len); +} + +int +alpha_readin(int fd, vm_offset_t dest, size_t len) +{ + return(read(fd, dest, len)); +} + + diff --git a/sys/boot/alpha/libalpha/alpha_module.c b/sys/boot/alpha/libalpha/alpha_module.c index a08fc85..afa065f 100644 --- a/sys/boot/alpha/libalpha/alpha_module.c +++ b/sys/boot/alpha/libalpha/alpha_module.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: alpha_module.c,v 1.1.1.1 1998/08/21 03:17:42 msmith Exp $ */ /* @@ -38,22 +38,6 @@ #include "libalpha.h" /* - * Look for a method and having found it, boot the kernel module. - */ -int -alpha_boot(void) -{ - int i; - - for (i = 0; module_formats[i] != NULL; i++) { - if (((loaded_modules->m_flags & MF_FORMATMASK) == module_formats[i]->l_format) && - (module_formats[i]->l_exec != NULL)) { - return((module_formats[i]->l_exec)(loaded_modules)); - } - } -} - -/* * Use voodoo to load modules required by current hardware. */ int diff --git a/sys/boot/alpha/libalpha/elf_freebsd.c b/sys/boot/alpha/libalpha/elf_freebsd.c index 4f618d8..b2e59ae 100644 --- a/sys/boot/alpha/libalpha/elf_freebsd.c +++ b/sys/boot/alpha/libalpha/elf_freebsd.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: elf_freebsd.c,v 1.1.1.1 1998/08/21 03:17:42 msmith Exp $ */ /* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */ /*- @@ -89,18 +89,11 @@ #define _KERNEL -struct elf_kernel_module -{ - struct loaded_module m; - vm_offset_t m_entry; /* module entrypoint */ - struct bootinfo_v1 m_bi; /* legacy bootinfo */ -}; - static int elf_loadmodule(char *filename, vm_offset_t dest, struct loaded_module **result); static int elf_exec(struct loaded_module *amp); static int elf_load(int fd, Elf_Ehdr *elf, vm_offset_t dest); -struct module_format alpha_elf = { MF_ELF, elf_loadmodule, elf_exec }; +struct module_format alpha_elf = { elf_loadmodule, elf_exec }; vm_offset_t ffp_save, ptbr_save; vm_offset_t ssym, esym; @@ -108,7 +101,7 @@ vm_offset_t ssym, esym; static int elf_loadmodule(char *filename, vm_offset_t dest, struct loaded_module **result) { - struct elf_kernel_module *mp; + struct loaded_module *mp; Elf_Ehdr hdr; ssize_t nr; int fd, rval; @@ -137,21 +130,23 @@ elf_loadmodule(char *filename, vm_offset_t dest, struct loaded_module **result) /* * Ok, we think this is for us. */ - mp = malloc(sizeof(struct elf_kernel_module)); - mp->m.m_name = strdup(filename); /* XXX should we prune the name? */ - mp->m.m_type = "elf kernel"; /* XXX only if that's what we really are */ - mp->m.m_args = NULL; /* XXX should we put the bootstrap args here and parse later? */ - mp->m.m_flags = MF_ELF; /* we're an elf kernel */ - mp->m_entry = hdr.e_entry; - if (dest == 0) - dest = (vm_offset_t) hdr.e_entry; - if (mod_findmodule(NULL, mp->m.m_type) != NULL) { + mp = malloc(sizeof(struct loaded_module)); + mp->m_name = strdup(filename); /* XXX should we prune the name? */ + mp->m_type = strdup("elf kernel"); /* XXX only if that's what we really are */ + mp->m_args = NULL; /* XXX should we put the bootstrap args here and parse later? */ + mp->m_metadata = NULL; + dest = (vm_offset_t) hdr.e_entry; + mp->m_addr = dest; + if (mod_findmodule(NULL, NULL) != NULL) { printf("elf_loadmodule: kernel already loaded\n"); rval = EPERM; goto err; } rval = elf_load(fd, &hdr, (vm_offset_t) dest); + /* save ELF header as metadata */ + mod_addmetadata(mp, MODINFOMD_ELFHDR, sizeof(Elf_Ehdr), &hdr); + *result = (struct loaded_module *)mp; err: @@ -284,10 +279,15 @@ elf_load(int fd, Elf_Ehdr *elf, vm_offset_t dest) } static int -elf_exec(struct loaded_module *amp) +elf_exec(struct loaded_module *mp) { - struct elf_kernel_module *mp = (struct elf_kernel_module *)amp; - static struct bootinfo_v1 bootinfo_v1; + static struct bootinfo_v1 bootinfo_v1; + struct module_metadata *md; + Elf_Ehdr *hdr; + + if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL) + return(EFTYPE); /* XXX actually EFUCKUP */ + hdr = (Elf_Ehdr *)&(md->md_data); /* * Fill in the bootinfo for the kernel. @@ -295,7 +295,7 @@ elf_exec(struct loaded_module *amp) bzero(&bootinfo_v1, sizeof(bootinfo_v1)); bootinfo_v1.ssym = ssym; bootinfo_v1.esym = esym; - strncpy(bootinfo_v1.booted_kernel, mp->m.m_name, + strncpy(bootinfo_v1.booted_kernel, mp->m_name, sizeof(bootinfo_v1.booted_kernel)); prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo_v1.boot_flags, sizeof(bootinfo_v1.boot_flags)); @@ -305,10 +305,10 @@ elf_exec(struct loaded_module *amp) bootinfo_v1.cnputc = NULL; bootinfo_v1.cnpollc = NULL; - printf("Entering %s at 0x%lx...\n", mp->m.m_name, mp->m_entry); + printf("Entering %s at 0x%lx...\n", mp->m_name, hdr->e_entry); closeall(); alpha_pal_imb(); - (*(void (*)())mp->m_entry)(ffp_save, ptbr_save, + (*(void (*)())hdr->e_entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC, &bootinfo_v1, 1, 0); } diff --git a/sys/boot/alpha/libalpha/libalpha.h b/sys/boot/alpha/libalpha/libalpha.h index 24b29d2..0308ea2 100644 --- a/sys/boot/alpha/libalpha/libalpha.h +++ b/sys/boot/alpha/libalpha/libalpha.h @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: libalpha.h,v 1.1.1.1 1998/08/21 03:17:42 msmith Exp $ */ /* * Copyright (c) 1996 @@ -74,34 +74,8 @@ extern struct netif_driver srmnet; extern void delay(int); extern void reboot(void); -/* - * alpha module loader - */ -#define MF_FORMATMASK 0xf -#define MF_AOUT 0 /* not supported */ -#define MF_ELF 1 - -struct alpha_module -{ - char *m_name; /* module name */ - char *m_type; /* module type, eg 'kernel', 'pnptable', etc. */ - char *m_args; /* arguments for the module */ - int m_flags; /* 0xffff reserved for arch-specific use */ - struct alpha_module *m_next; /* next module */ - physaddr_t m_addr; /* load address */ - size_t m_size; /* module size */ -}; - -struct alpha_format -{ - int l_format; - /* Load function must return EFTYPE if it can't handle the module supplied */ - int (* l_load)(char *filename, physaddr_t dest, struct alpha_module **result); - int (* l_exec)(struct alpha_module *amp); -}; -extern struct alpha_format *formats[]; /* supplied by consumer */ -extern struct alpha_format alpha_elf; +extern int alpha_copyin(void *src, vm_offset_t dest, size_t len); +extern int alpha_readin(int fd, vm_offset_t dest, size_t len); -extern int alpha_boot(void); -extern int alpha_autoload(void); -extern struct alpha_module *alpha_findmodule(char *name, char *type); +extern int alpha_boot(void); +extern int alpha_autoload(void); |