2 * $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $
3 * $FreeBSD: src/sys/boot/alpha/libalpha/elf_freebsd.c,v 1.12 2003/05/01 03:56:28 peter Exp $
4 * $DragonFly: src/sys/boot/alpha/libalpha/Attic/elf_freebsd.c,v 1.3 2003/11/10 06:08:29 dillon Exp $
8 * Copyright (c) 1997 The NetBSD Foundation, Inc.
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
13 * NASA Ames Research Center.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the NetBSD
26 * Foundation, Inc. and its contributors.
27 * 4. Neither the name of The NetBSD Foundation nor the names of its
28 * contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
32 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
35 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
45 * Copyright (c) 1992, 1993
46 * The Regents of the University of California. All rights reserved.
48 * This code is derived from software contributed to Berkeley by
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
54 * 1. Redistributions of source code must retain the above copyright
55 * notice, this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright
57 * notice, this list of conditions and the following disclaimer in the
58 * documentation and/or other materials provided with the distribution.
59 * 3. All advertising materials mentioning features or use of this software
60 * must display the following acknowledgement:
61 * This product includes software developed by the University of
62 * California, Berkeley and its contributors.
63 * 4. Neither the name of the University nor the names of its contributors
64 * may be used to endorse or promote products derived from this software
65 * without specific prior written permission.
67 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
68 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
71 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
79 * @(#)boot.c 8.1 (Berkeley) 6/10/93
85 #include <sys/param.h>
86 #include <sys/linker.h>
87 #include <machine/elf.h>
88 #include <machine/prom.h>
89 #include <machine/rpb.h>
90 #include <machine/bootinfo.h>
92 #include "bootstrap.h"
96 static int elf64_exec(struct preloaded_file *afp);
97 int bi_load(struct bootinfo_v1 *, vm_offset_t *,
98 struct preloaded_file *);
100 struct file_format alpha_elf = { elf64_loadfile, elf64_exec };
102 vm_offset_t ffp_save, ptbr_save;
105 elf64_exec(struct preloaded_file *fp)
107 static struct bootinfo_v1 bootinfo_v1;
108 struct file_metadata *md;
113 if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
114 return(EFTYPE); /* XXX actually EFUCKUP */
115 hdr = (Elf_Ehdr *)&(md->md_data);
117 /* XXX ffp_save does not appear to be used in the kernel.. */
118 bzero(&bootinfo_v1, sizeof(bootinfo_v1));
119 err = bi_load(&bootinfo_v1, &ffp_save, fp);
124 * Fill in rest of bootinfo for the kernel.
126 flen = prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo_v1.boot_flags,
127 sizeof(bootinfo_v1.boot_flags));
128 bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
129 bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
130 bootinfo_v1.cngetc = NULL;
131 bootinfo_v1.cnputc = NULL;
132 bootinfo_v1.cnpollc = NULL;
135 * Append the boot command flags.
137 if (fp->f_args != NULL && *fp->f_args != '\0') {
138 const char *p = fp->f_args;
142 while (*++p != ' ' && *p != '\0')
143 if (flen < sizeof(bootinfo_v1.boot_flags) - 1)
144 bootinfo_v1.boot_flags[flen++] = *p;
146 while (*p != ' ' && *p != '\0')
150 } while (*p != '\0');
151 bootinfo_v1.boot_flags[flen] = '\0';
154 printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry);
158 (*(void (*)())hdr->e_entry)(ffp_save, ptbr_save,
159 BOOTINFO_MAGIC, &bootinfo_v1, 1, 0);