Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / boot / arc / lib / elf_freebsd.c
1 /* $FreeBSD: src/sys/boot/arc/lib/elf_freebsd.c,v 1.2 1999/08/28 00:39:38 peter Exp $ */
2 /* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
3
4 /*-
5  * Copyright (c) 1997 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
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.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
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.
27  *
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.
39  */
40
41 /*
42  * Copyright (c) 1992, 1993
43  *      The Regents of the University of California.  All rights reserved.
44  *
45  * This code is derived from software contributed to Berkeley by
46  * Ralph Campbell.
47  *
48  * Redistribution and use in source and binary forms, with or without
49  * modification, are permitted provided that the following conditions
50  * are met:
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.
63  *
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
74  * SUCH DAMAGE.
75  *
76  *      @(#)boot.c      8.1 (Berkeley) 6/10/93
77  */
78
79 #include <stand.h>
80 #include <string.h>
81
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>
88
89 #include "bootstrap.h"
90
91 #define _KERNEL
92
93 static int      elf_exec(struct loaded_module *amp);
94 int             bi_load(struct bootinfo_v1 *, vm_offset_t *,
95                         struct loaded_module *);
96
97 struct module_format alpha_elf = { elf_loadmodule, elf_exec };
98
99 vm_offset_t ffp_save, ptbr_save;
100
101 static int
102 elf_exec(struct loaded_module *mp)
103 {
104 #if 0
105     static struct bootinfo_v1   bootinfo_v1;
106     struct module_metadata      *md;
107     Elf_Ehdr                    *hdr;
108     int                         err;
109
110     if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL)
111         return(EFTYPE);                 /* XXX actually EFUCKUP */
112     hdr = (Elf_Ehdr *)&(md->md_data);
113
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);
117     if (err)
118         return(err);
119
120     /*
121      * Fill in the bootinfo for the kernel.
122      */
123     strncpy(bootinfo_v1.booted_kernel, mp->m_name,
124             sizeof(bootinfo_v1.booted_kernel));
125     prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo_v1.boot_flags,
126                 sizeof(bootinfo_v1.boot_flags));
127     bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
128     bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
129     bootinfo_v1.cngetc = NULL;
130     bootinfo_v1.cnputc = NULL;
131     bootinfo_v1.cnpollc = NULL;
132
133     printf("Entering %s at 0x%lx...\n", mp->m_name, hdr->e_entry);
134     exit(0);
135     closeall();
136     alpha_pal_imb();
137     (*(void (*)())hdr->e_entry)(ffp_save, ptbr_save,
138                                BOOTINFO_MAGIC, &bootinfo_v1, 1, 0);
139 #endif
140 }
141
142
143