2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
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
26 * from: FreeBSD: src/sys/boot/i386/libi386/bootinfo.c,v 1.29
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/reboot.h>
35 #include <sys/linker.h>
37 #include <machine/metadata.h>
39 #include "bootstrap.h"
42 extern struct tlb_entry *dtlb_store;
43 extern struct tlb_entry *itlb_store;
48 static int md_bootserial(void);
51 * Return a 'boothowto' value corresponding to the kernel arguments in
52 * (kargs) and any relevant environment variables.
59 {"boot_askname", RB_ASKNAME},
60 {"boot_cdrom", RB_CDROM},
62 {"boot_dfltroot", RB_DFLTROOT},
64 {"boot_multicons", RB_MULTIPLE},
65 {"boot_mute", RB_MUTE},
66 {"boot_pause", RB_PAUSE},
67 {"boot_serial", RB_SERIAL},
68 {"boot_single", RB_SINGLE},
69 {"boot_verbose", RB_VERBOSE},
74 md_getboothowto(char *kargs)
87 if (!active && (*cp == '-')) {
101 howto |= RB_MULTIPLE;
116 howto |= RB_DFLTROOT;
131 /* get equivalents from the environment */
132 for (i = 0; howto_names[i].ev != NULL; i++)
133 if (getenv(howto_names[i].ev) != NULL)
134 howto |= howto_names[i].mask;
135 if (md_bootserial() != -1)
149 if ((node = OF_finddevice("/options")) == -1)
151 if (OF_getprop(node, "input-device", buf, sizeof(buf)) == -1)
153 input = OF_finddevice(buf);
154 if (OF_getprop(node, "output-device", buf, sizeof(buf)) == -1)
156 output = OF_finddevice(buf);
157 if (input == -1 || output == -1 || OF_getproplen(input, "keyboard") >= 0) {
158 if ((node = OF_finddevice("/chosen")) == -1)
160 if (OF_getprop(node, "stdin", &inst, sizeof(inst)) == -1)
162 if ((input = OF_instance_to_package(inst)) == -1)
164 if (OF_getprop(node, "stdout", &inst, sizeof(inst)) == -1)
166 if ((output = OF_instance_to_package(inst)) == -1)
171 if (OF_getprop(input, "device_type", buf, sizeof(buf)) == -1)
173 if (strcmp(buf, "serial") != 0)
179 * Copy the environment into the load area starting at (addr).
180 * Each variable is formatted as <name>=<value>, with a single nul
181 * separating each variable, and a double nul terminating the environment.
184 md_copyenv(vm_offset_t addr)
188 /* traverse the environment */
189 for (ep = environ; ep != NULL; ep = ep->ev_next) {
190 archsw.arch_copyin(ep->ev_name, addr, strlen(ep->ev_name));
191 addr += strlen(ep->ev_name);
192 archsw.arch_copyin("=", addr, 1);
194 if (ep->ev_value != NULL) {
195 archsw.arch_copyin(ep->ev_value, addr, strlen(ep->ev_value));
196 addr += strlen(ep->ev_value);
198 archsw.arch_copyin("", addr, 1);
201 archsw.arch_copyin("", addr, 1);
207 * Copy module-related data into the load area, where it can be
208 * used as a directory for loaded modules.
210 * Module data is presented in a self-describing format. Each datum
211 * is preceded by a 32-bit identifier and a 32-bit size field.
213 * Currently, the following data are saved:
215 * MOD_NAME (variable) module name (string)
216 * MOD_TYPE (variable) module type (string)
217 * MOD_ARGS (variable) module parameters (string)
218 * MOD_ADDR sizeof(vm_offset_t) module load address
219 * MOD_SIZE sizeof(size_t) module size
220 * MOD_METADATA (variable) type-specific metadata
222 #define COPY32(v, a, c) { \
225 archsw.arch_copyin(&x, a, sizeof(x)); \
229 #define MOD_STR(t, a, s, c) { \
231 COPY32(strlen(s) + 1, a, c) \
233 archsw.arch_copyin(s, a, strlen(s) + 1);\
234 a += roundup(strlen(s) + 1, sizeof(u_long));\
237 #define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
238 #define MOD_TYPE(a, s, c) MOD_STR(MODINFO_TYPE, a, s, c)
239 #define MOD_ARGS(a, s, c) MOD_STR(MODINFO_ARGS, a, s, c)
241 #define MOD_VAR(t, a, s, c) { \
243 COPY32(sizeof(s), a, c); \
245 archsw.arch_copyin(&s, a, sizeof(s)); \
246 a += roundup(sizeof(s), sizeof(u_long)); \
249 #define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
250 #define MOD_SIZE(a, s, c) MOD_VAR(MODINFO_SIZE, a, s, c)
252 #define MOD_METADATA(a, mm, c) { \
253 COPY32(MODINFO_METADATA | mm->md_type, a, c);\
254 COPY32(mm->md_size, a, c); \
256 archsw.arch_copyin(mm->md_data, a, mm->md_size);\
257 a += roundup(mm->md_size, sizeof(u_long)); \
260 #define MOD_END(a, c) { \
261 COPY32(MODINFO_END, a, c); \
266 md_copymodules(vm_offset_t addr)
268 struct preloaded_file *fp;
269 struct file_metadata *md;
273 /* start with the first module on the list, should be the kernel */
274 for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
276 MOD_NAME(addr, fp->f_name, c); /* this field must come first */
277 MOD_TYPE(addr, fp->f_type, c);
279 MOD_ARGS(addr, fp->f_args, c);
280 MOD_ADDR(addr, fp->f_addr, c);
281 MOD_SIZE(addr, fp->f_size, c);
282 for (md = fp->f_metadata; md != NULL; md = md->md_next) {
283 if (!(md->md_type & MODINFOMD_NOCOPY)) {
284 MOD_METADATA(addr, md, c);
293 * Load the information expected by a sparc64 kernel.
295 * - The 'boothowto' argument is constructed
296 * - The 'bootdev' argument is constructed
297 * - The kernel environment is copied into kernel space.
298 * - Module metadata are formatted and placed in kernel space.
301 md_load(char *args, vm_offset_t *modulep)
303 struct preloaded_file *kfp;
304 struct preloaded_file *xp;
305 struct file_metadata *md;
313 howto = md_getboothowto(args);
316 * Allow the environment variable 'rootdev' to override the supplied device
317 * This should perhaps go to MI code and/or have $rootdev tested/set by
318 * MI code before launching the kernel.
320 if ((rootdevname = getenv("rootdev")) == NULL)
321 rootdevname = getenv("currdev");
322 getrootmount(rootdevname);
324 /* find the last module in the chain */
326 for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
327 if (addr < (xp->f_addr + xp->f_size))
328 addr = xp->f_addr + xp->f_size;
330 /* pad to a page boundary */
331 addr = roundup(addr, PAGE_SIZE);
333 /* copy our environment */
335 addr = md_copyenv(addr);
337 /* pad to a page boundary */
338 addr = roundup(addr, PAGE_SIZE);
341 kfp = file_findfile(NULL, "elf64 kernel");
343 kfp = file_findfile(NULL, "elf kernel");
345 panic("can't find kernel file");
346 file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
347 file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
348 file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
349 file_addmetadata(kfp, MODINFOMD_DTLB_SLOTS, sizeof dtlb_slot, &dtlb_slot);
350 file_addmetadata(kfp, MODINFOMD_ITLB_SLOTS, sizeof itlb_slot, &itlb_slot);
351 file_addmetadata(kfp, MODINFOMD_DTLB,
352 dtlb_slot * sizeof(*dtlb_store), dtlb_store);
353 file_addmetadata(kfp, MODINFOMD_ITLB,
354 itlb_slot * sizeof(*itlb_store), itlb_store);
357 size = md_copymodules(0);
358 kernend = roundup(addr + size, PAGE_SIZE);
360 md = file_findmetadata(kfp, MODINFOMD_KERNEND);
361 bcopy(&kernend, md->md_data, sizeof kernend);
363 (void)md_copymodules(addr);