Core integer types header file reorganization stage 1/2: Create and/or modify
[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 /* $DragonFly: src/sys/boot/arc/lib/Attic/elf_freebsd.c,v 1.2 2003/06/17 04:28:16 dillon Exp $ */
3 /* $NetBSD: loadfile.c,v 1.10 1998/06/25 06:45:46 ross Exp $ */
4
5 /*-
6  * Copyright (c) 1997 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
11  * NASA Ames Research Center.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgement:
23  *      This product includes software developed by the NetBSD
24  *      Foundation, Inc. and its contributors.
25  * 4. Neither the name of The NetBSD Foundation nor the names of its
26  *    contributors may be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  */
41
42 /*
43  * Copyright (c) 1992, 1993
44  *      The Regents of the University of California.  All rights reserved.
45  *
46  * This code is derived from software contributed to Berkeley by
47  * Ralph Campbell.
48  *
49  * Redistribution and use in source and binary forms, with or without
50  * modification, are permitted provided that the following conditions
51  * are met:
52  * 1. Redistributions of source code must retain the above copyright
53  *    notice, this list of conditions and the following disclaimer.
54  * 2. Redistributions in binary form must reproduce the above copyright
55  *    notice, this list of conditions and the following disclaimer in the
56  *    documentation and/or other materials provided with the distribution.
57  * 3. All advertising materials mentioning features or use of this software
58  *    must display the following acknowledgement:
59  *      This product includes software developed by the University of
60  *      California, Berkeley and its contributors.
61  * 4. Neither the name of the University nor the names of its contributors
62  *    may be used to endorse or promote products derived from this software
63  *    without specific prior written permission.
64  *
65  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
66  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
69  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
73  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
74  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75  * SUCH DAMAGE.
76  *
77  *      @(#)boot.c      8.1 (Berkeley) 6/10/93
78  */
79
80 #include <stand.h>
81 #include <string.h>
82
83 #include <sys/param.h>
84 #include <sys/linker.h>
85 #include <machine/elf.h>
86 #include <machine/prom.h>
87 #include <machine/rpb.h>
88 #include <machine/bootinfo.h>
89
90 #include "bootstrap.h"
91
92 #define _KERNEL
93
94 static int      elf_exec(struct loaded_module *amp);
95 int             bi_load(struct bootinfo_v1 *, vm_offset_t *,
96                         struct loaded_module *);
97
98 struct module_format alpha_elf = { elf_loadmodule, elf_exec };
99
100 vm_offset_t ffp_save, ptbr_save;
101
102 static int
103 elf_exec(struct loaded_module *mp)
104 {
105 #if 0
106     static struct bootinfo_v1   bootinfo_v1;
107     struct module_metadata      *md;
108     Elf_Ehdr                    *hdr;
109     int                         err;
110
111     if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL)
112         return(EFTYPE);                 /* XXX actually EFUCKUP */
113     hdr = (Elf_Ehdr *)&(md->md_data);
114
115     /* XXX ffp_save does not appear to be used in the kernel.. */
116     bzero(&bootinfo_v1, sizeof(bootinfo_v1));
117     err = bi_load(&bootinfo_v1, &ffp_save, mp);
118     if (err)
119         return(err);
120
121     /*
122      * Fill in the bootinfo for the kernel.
123      */
124     strncpy(bootinfo_v1.booted_kernel, mp->m_name,
125             sizeof(bootinfo_v1.booted_kernel));
126     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;
133
134     printf("Entering %s at 0x%lx...\n", mp->m_name, hdr->e_entry);
135     exit(0);
136     closeall();
137     alpha_pal_imb();
138     (*(void (*)())hdr->e_entry)(ffp_save, ptbr_save,
139                                BOOTINFO_MAGIC, &bootinfo_v1, 1, 0);
140 #endif
141 }
142
143
144