Deleted Added
full compact
elf32_freebsd.c (39887) elf32_freebsd.c (39902)
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: elf_freebsd.c,v 1.1 1998/09/30 19:48:09 peter Exp $
26 * $Id: elf_freebsd.c,v 1.2 1998/10/02 08:04:56 peter Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/exec.h>
31#include <sys/reboot.h>
32#include <sys/linker.h>
33#include <string.h>
34#include <machine/bootinfo.h>

--- 13 unchanged lines hidden (view full) ---

48/*
49 * There is an a.out kernel and one or more a.out modules loaded.
50 * We wish to start executing the kernel image, so make such
51 * preparations as are required, and do so.
52 */
53static int
54elf_exec(struct loaded_module *mp)
55{
27 */
28
29#include <sys/param.h>
30#include <sys/exec.h>
31#include <sys/reboot.h>
32#include <sys/linker.h>
33#include <string.h>
34#include <machine/bootinfo.h>

--- 13 unchanged lines hidden (view full) ---

48/*
49 * There is an a.out kernel and one or more a.out modules loaded.
50 * We wish to start executing the kernel image, so make such
51 * preparations as are required, and do so.
52 */
53static int
54elf_exec(struct loaded_module *mp)
55{
56 struct loaded_module *xp;
57 struct i386_devdesc *currdev;
58 struct module_metadata *md;
59 Elf_Ehdr *ehdr;
56 struct module_metadata *md;
57 Elf_Ehdr *ehdr;
60 u_int32_t argv[6]; /* kernel arguments */
61 int major, bootdevnr;
62 vm_offset_t addr, entry;
63 u_int pad;
64 vm_offset_t ssym, esym, *symptr;
58 vm_offset_t entry, bootinfop;
59 int boothowto, err, bootdev;
60 struct bootinfo *bi;
61 vm_offset_t ssym, esym;
65
66 if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL)
67 return(EFTYPE); /* XXX actually EFUCKUP */
68 ehdr = (Elf_Ehdr *)&(md->md_data);
69
62
63 if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL)
64 return(EFTYPE); /* XXX actually EFUCKUP */
65 ehdr = (Elf_Ehdr *)&(md->md_data);
66
70 /* Boot from whatever the current device is */
71 i386_getdev((void **)(&currdev), NULL, NULL);
72 switch(currdev->d_type) {
73 case DEVT_DISK:
74 major = 0; /* XXX work out the best possible major here */
75 bootdevnr = MAKEBOOTDEV(major,
76 currdev->d_kind.biosdisk.slice >> 4,
77 currdev->d_kind.biosdisk.slice & 0xf,
78 currdev->d_kind.biosdisk.unit,
79 currdev->d_kind.biosdisk.partition);
80 break;
81 default:
82 printf("elf_exec: WARNING - don't know how to boot from device type %d\n", currdev->d_type);
83 }
84 free(currdev);
67 /* XXX allow override? */
68 setenv("kernelname", mp->m_name, 1);
85
69
70 if ((err = bi_load(mp->m_args, &boothowto, &bootdev, &bootinfop)) != 0)
71 return(err);
72 entry = ehdr->e_entry & 0xffffff;
73
86 if ((md = mod_findmetadata(mp, MODINFOMD_ELFSSYM)) != NULL)
87 ssym = *((vm_offset_t *)&(md->md_data));
88 if ((md = mod_findmetadata(mp, MODINFOMD_ELFESYM)) != NULL)
89 esym = *((vm_offset_t *)&(md->md_data));
90 if (ssym == 0 || esym == 0)
91 ssym = esym = 0; /* sanity */
92
74 if ((md = mod_findmetadata(mp, MODINFOMD_ELFSSYM)) != NULL)
75 ssym = *((vm_offset_t *)&(md->md_data));
76 if ((md = mod_findmetadata(mp, MODINFOMD_ELFESYM)) != NULL)
77 esym = *((vm_offset_t *)&(md->md_data));
78 if (ssym == 0 || esym == 0)
79 ssym = esym = 0; /* sanity */
80
93 /* legacy bootinfo structure */
94 bi.bi_version = BOOTINFO_VERSION;
95 bi.bi_kernelname = 0; /* XXX char * -> kernel name */
96 bi.bi_nfs_diskless = 0; /* struct nfs_diskless * */
97 bi.bi_n_bios_used = 0; /* XXX would have to hook biosdisk driver for these */
98 /* bi.bi_bios_geom[] */
99 bi.bi_size = sizeof(bi);
100 bi.bi_memsizes_valid = 1;
101 bi.bi_vesa = 0; /* XXX correct value? */
102 bi.bi_basemem = getbasemem();
103 bi.bi_extmem = getextmem();
104 bi.bi_symtab = ssym;
105 bi.bi_esymtab = esym;
81 bi = (struct bootinfo *)PTOV(bootinfop);
82 bi->bi_symtab = ssym;
83 bi->bi_esymtab = esym;
106
84
107 /* Device data is kept in the kernel argv array */
108 argv[0] = bi_getboothowto(mp->m_args); /* boothowto */
109 argv[1] = bootdevnr; /* bootdev */
110 argv[2] = 0; /* old cyloffset */
111 argv[3] = 0; /* old esym */
112 argv[4] = 0; /* "new" bootinfo magic */
113 argv[5] = 0; /* physical addr of bootinfo */
114
85
115 /* find the last module in the chain */
116 for (xp = mp; xp->m_next != NULL; xp = xp->m_next)
117 ;
118 addr = xp->m_addr + xp->m_size;
119 /* pad to a page boundary */
120 pad = (u_int)addr & PAGE_MASK;
121 if (pad != 0) {
122 pad = PAGE_SIZE - pad;
123 addr += pad;
124 }
125 /* copy our environment */
126 bi.bi_envp = addr;
127 addr = bi_copyenv(addr);
128
129 /*
130 * Note, we could move the following onto a seperate page for reclaiming,
131 * but the environment is so small and so is this.
132 */
133
134 /* pad to a 4-byte boundary */
135 addr = (addr + 0x3) & ~0x3;
136
137 /* leave space for bootinfo */
138 argv[5] = (u_int32_t)addr;
139 addr += sizeof(struct bootinfo);
140
141 /* pad to a 4-byte boundary */
142 addr = (addr + 0x3) & ~0x3;
143
144 /* save in kernel name */
145 bi.bi_kernelname = addr;
146 i386_copyin(mp->m_name, addr, strlen(mp->m_name) + 1);
147 addr += strlen(mp->m_name) + 1;
148
149 /* pad to a page boundary */
150 pad = (u_int)addr & PAGE_MASK;
151 if (pad != 0) {
152 pad = PAGE_SIZE - pad;
153 addr += pad;
154 }
155 /* copy module list and metadata */
156 bi.bi_modulep = addr;
157 addr = bi_copymodules(addr);
158
159 /* all done copying stuff in, save end of loaded object space */
160 bi.bi_kernend = addr;
161
162 /* and insert bootinfo struct into reserved spot */
163 i386_copyin(&bi, (vm_offset_t)argv[5], sizeof(bi));
164 argv[0] |= RB_BOOTINFO; /* it's there now */
165
166 entry = ehdr->e_entry & 0xffffff;
167
168#ifdef DEBUG
86#ifdef DEBUG
169 {
170 int i;
171 for (i = 0; i < 6; i++)
172 printf("argv[%d]=%lx\n", i, argv[i]);
173 }
174
175 printf("Start @ 0x%lx ...\n", entry);
176#endif
177
87 printf("Start @ 0x%lx ...\n", entry);
88#endif
89
178 __exec((void *)entry, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
90 __exec((void *)entry, boothowto, bootdev, 0, 0, 0, bootinfop);
179
180 panic("exec returned");
181}
91
92 panic("exec returned");
93}