1 /* $FreeBSD: src/sys/boot/alpha/libalpha/elf_freebsd.c,v 1.8.2.2 2001/03/04 05:21:25 obrien Exp $ */
2 /* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
5 * Copyright (c) 1997 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
42 * Copyright (c) 1992, 1993
43 * The Regents of the University of California. All rights reserved.
45 * This code is derived from software contributed to Berkeley by
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission.
64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76 * @(#)boot.c 8.1 (Berkeley) 6/10/93
82 #include <sys/param.h>
83 #include <sys/linker.h>
84 #include <machine/elf.h>
85 #include <machine/prom.h>
86 #include <machine/rpb.h>
87 #include <machine/bootinfo.h>
89 #include "bootstrap.h"
93 static int elf_exec(struct loaded_module *amp);
94 int bi_load(struct bootinfo_v1 *, vm_offset_t *,
95 struct loaded_module *);
97 struct module_format alpha_elf = { elf_loadmodule, elf_exec };
99 vm_offset_t ffp_save, ptbr_save;
102 elf_exec(struct loaded_module *mp)
104 static struct bootinfo_v1 bootinfo_v1;
105 struct module_metadata *md;
110 if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL)
111 return(EFTYPE); /* XXX actually EFUCKUP */
112 hdr = (Elf_Ehdr *)&(md->md_data);
114 /* XXX ffp_save does not appear to be used in the kernel.. */
115 bzero(&bootinfo_v1, sizeof(bootinfo_v1));
116 err = bi_load(&bootinfo_v1, &ffp_save, mp);
121 * Fill in rest of bootinfo for the kernel.
123 flen = prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo_v1.boot_flags,
124 sizeof(bootinfo_v1.boot_flags));
125 bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
126 bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
127 bootinfo_v1.cngetc = NULL;
128 bootinfo_v1.cnputc = NULL;
129 bootinfo_v1.cnpollc = NULL;
132 * Append the boot command flags.
134 if (mp->m_args != NULL && *mp->m_args != '\0') {
135 const char *p = mp->m_args;
139 while (*++p != ' ' && *p != '\0')
140 if (flen < sizeof(bootinfo_v1.boot_flags) - 1)
141 bootinfo_v1.boot_flags[flen++] = *p;
143 while (*p != ' ' && *p != '\0')
147 } while (*p != '\0');
148 bootinfo_v1.boot_flags[flen] = '\0';
151 printf("Entering %s at 0x%lx...\n", mp->m_name, hdr->e_entry);
155 (*(void (*)())hdr->e_entry)(ffp_save, ptbr_save,
156 BOOTINFO_MAGIC, &bootinfo_v1, 1, 0);