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
27 * $DragonFly: src/sys/boot/alpha/libalpha/Attic/bootinfo.c,v 1.3 2003/11/10 06:08:29 dillon Exp $
32 #include <sys/param.h>
33 #include <sys/linker.h>
34 #include <machine/elf.h>
35 #include <machine/prom.h>
36 #include <machine/rpb.h>
37 #include <machine/bootinfo.h>
38 #include "bootstrap.h"
40 extern char *alpha_fmtdev(void *vdev);
43 * Copy the environment into the load area starting at (addr).
44 * Each variable is formatted as <name>=<value>, with a single nul
45 * separating each variable, and a double nul terminating the environment.
48 bi_copyenv(vm_offset_t addr)
52 /* traverse the environment */
53 for (ep = environ; ep != NULL; ep = ep->ev_next) {
54 alpha_copyin(ep->ev_name, addr, strlen(ep->ev_name));
55 addr += strlen(ep->ev_name);
56 alpha_copyin("=", addr, 1);
58 if (ep->ev_value != NULL) {
59 alpha_copyin(ep->ev_value, addr, strlen(ep->ev_value));
60 addr += strlen(ep->ev_value);
62 alpha_copyin("", addr, 1);
65 alpha_copyin("", addr, 1);
71 * Copy module-related data into the load area, where it can be
72 * used as a directory for loaded modules.
74 * Module data is presented in a self-describing format. Each datum
75 * is preceded by a 32-bit identifier and a 32-bit size field.
77 * Currently, the following data are saved:
79 * MOD_NAME (variable) module name (string)
80 * MOD_TYPE (variable) module type (string)
81 * MOD_ARGS (variable) module parameters (string)
82 * MOD_ADDR sizeof(vm_offset_t) module load address
83 * MOD_SIZE sizeof(size_t) module size
84 * MOD_METADATA (variable) type-specific metadata
86 #define COPY32(v, a) { \
88 alpha_copyin(&x, a, sizeof(x)); \
92 #define MOD_STR(t, a, s) { \
94 COPY32(strlen(s) + 1, a); \
95 alpha_copyin(s, a, strlen(s) + 1); \
96 a += roundup(strlen(s) + 1, sizeof(u_int64_t));\
99 #define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s)
100 #define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s)
101 #define MOD_ARGS(a, s) MOD_STR(MODINFO_ARGS, a, s)
103 #define MOD_VAR(t, a, s) { \
105 COPY32(sizeof(s), a); \
106 alpha_copyin(&s, a, sizeof(s)); \
107 a += roundup(sizeof(s), sizeof(u_int64_t)); \
110 #define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s)
111 #define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s)
113 #define MOD_METADATA(a, mm) { \
114 COPY32(MODINFO_METADATA | mm->md_type, a); \
115 COPY32(mm->md_size, a); \
116 alpha_copyin(mm->md_data, a, mm->md_size); \
117 a += roundup(mm->md_size, sizeof(u_int64_t));\
120 #define MOD_END(a) { \
121 COPY32(MODINFO_END, a); \
126 bi_copymodules(vm_offset_t addr)
128 struct preloaded_file *fp;
129 struct file_metadata *md;
131 /* start with the first module on the list, should be the kernel */
132 for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
134 MOD_NAME(addr, fp->f_name); /* this field must come first */
135 MOD_TYPE(addr, fp->f_type);
137 MOD_ARGS(addr, fp->f_args);
138 MOD_ADDR(addr, fp->f_addr);
139 MOD_SIZE(addr, fp->f_size);
140 for (md = fp->f_metadata; md != NULL; md = md->md_next)
141 if (!(md->md_type & MODINFOMD_NOCOPY))
142 MOD_METADATA(addr, md);
149 * Load the information expected by an alpha kernel.
151 * - The kernel environment is copied into kernel space.
152 * - Module metadata are formatted and placed in kernel space.
155 bi_load(struct bootinfo_v1 *bi, vm_offset_t *ffp_save,
156 struct preloaded_file *fp)
159 struct alpha_devdesc *rootdev;
160 struct preloaded_file *xp;
161 vm_offset_t addr, bootinfo_addr;
164 vm_offset_t ssym, esym;
165 struct file_metadata *md;
168 * Allow the environment variable 'rootdev' to override the supplied device
169 * This should perhaps go to MI code and/or have $rootdev tested/set by
170 * MI code before launching the kernel.
172 rootdevname = getenv("rootdev");
173 alpha_getdev((void **)(&rootdev), rootdevname, NULL);
174 if (rootdev == NULL) { /* bad $rootdev/$currdev */
175 printf("can't determine root device\n");
179 /* Try reading the /etc/fstab file to select the root device */
180 getrootmount(alpha_fmtdev((void *)rootdev));
184 if ((md = file_findmetadata(fp, MODINFOMD_SSYM)) != NULL)
185 ssym = *((vm_offset_t *)&(md->md_data));
186 if ((md = file_findmetadata(fp, MODINFOMD_ESYM)) != NULL)
187 esym = *((vm_offset_t *)&(md->md_data));
188 if (ssym == 0 || esym == 0)
189 ssym = esym = 0; /* sanity */
194 /* find the last module in the chain */
196 for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
197 if (addr < (xp->f_addr + xp->f_size))
198 addr = xp->f_addr + xp->f_size;
200 /* pad to a page boundary */
201 pad = (u_int)addr & PAGE_MASK;
203 pad = PAGE_SIZE - pad;
207 /* copy our environment */
208 bi->envp = (char *)addr;
209 addr = bi_copyenv(addr);
211 /* pad to a page boundary */
212 pad = (u_int)addr & PAGE_MASK;
214 pad = PAGE_SIZE - pad;
217 /* copy module list and metadata */
219 addr = bi_copymodules(addr);
221 /* all done copying stuff in, save end of loaded object space */
224 *ffp_save = ALPHA_K0SEG_TO_PHYS((addr + PAGE_MASK) & ~PAGE_MASK)
226 *ffp_save += 2; /* XXX OSF/1 does this, no idea why. */
228 kernelname = getenv("kernelname");
230 strncpy(bi->booted_kernel, kernelname, sizeof(bi->booted_kernel) - 1);