Deleted Added
full compact
bootinfo64.c (38764) bootinfo64.c (39178)
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 * 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.
13 *
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
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 * 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.
13 *
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
24 * SUCH DAMAGE.
25 *
26 * $Id: bootinfo.c,v 1.1.1.1 1998/08/21 03:17:41 msmith Exp $
26 * $Id: bootinfo.c,v 1.2 1998/09/03 02:10:09 msmith Exp $
27 */
28
29#include <sys/reboot.h>
30#include <stand.h>
31#include "bootstrap.h"
32
33
34/*
35 * Return a 'boothowto' value corresponding to the kernel arguments in
36 * (kargs) and any relevant environment variables.
37 */
38static struct
39{
40 char *ev;
41 int mask;
42} howto_names[] = {
43 {"boot_askname", RB_ASKNAME},
44 {"boot_userconfig", RB_CONFIG},
45 {"boot_ddb", RB_KDB},
46 {"boot_gdb", RB_GDB},
47 {"boot_single", RB_SINGLE},
48 {"boot_verbose", RB_VERBOSE},
49 {NULL, 0}
50};
51
52int
53bi_getboothowto(char *kargs)
54{
55 char *cp;
56 int howto;
57 int active;
58 int i;
59
27 */
28
29#include <sys/reboot.h>
30#include <stand.h>
31#include "bootstrap.h"
32
33
34/*
35 * Return a 'boothowto' value corresponding to the kernel arguments in
36 * (kargs) and any relevant environment variables.
37 */
38static struct
39{
40 char *ev;
41 int mask;
42} howto_names[] = {
43 {"boot_askname", RB_ASKNAME},
44 {"boot_userconfig", RB_CONFIG},
45 {"boot_ddb", RB_KDB},
46 {"boot_gdb", RB_GDB},
47 {"boot_single", RB_SINGLE},
48 {"boot_verbose", RB_VERBOSE},
49 {NULL, 0}
50};
51
52int
53bi_getboothowto(char *kargs)
54{
55 char *cp;
56 int howto;
57 int active;
58 int i;
59
60 /* Parse kargs */
60 howto = 0;
61 if (kargs != NULL) {
62 cp = kargs;
63 active = 0;
64 while (*cp != 0) {
65 if (!active && (*cp == '-')) {
66 active = 1;
67 } else if (active)
68 switch (*cp) {
69 case 'a':
70 howto |= RB_ASKNAME;
71 break;
72 case 'c':
73 howto |= RB_CONFIG;
74 break;
75 case 'd':
76 howto |= RB_KDB;
77 break;
78 case 'g':
79 howto |= RB_GDB;
80 break;
81 case 'h':
82 howto |= RB_SERIAL;
83 break;
84 case 'r':
85 howto |= RB_DFLTROOT;
86 break;
87 case 's':
88 howto |= RB_SINGLE;
89 break;
90 case 'v':
91 howto |= RB_VERBOSE;
92 break;
93 default:
94 active = 0;
95 break;
96 }
61 howto = 0;
62 if (kargs != NULL) {
63 cp = kargs;
64 active = 0;
65 while (*cp != 0) {
66 if (!active && (*cp == '-')) {
67 active = 1;
68 } else if (active)
69 switch (*cp) {
70 case 'a':
71 howto |= RB_ASKNAME;
72 break;
73 case 'c':
74 howto |= RB_CONFIG;
75 break;
76 case 'd':
77 howto |= RB_KDB;
78 break;
79 case 'g':
80 howto |= RB_GDB;
81 break;
82 case 'h':
83 howto |= RB_SERIAL;
84 break;
85 case 'r':
86 howto |= RB_DFLTROOT;
87 break;
88 case 's':
89 howto |= RB_SINGLE;
90 break;
91 case 'v':
92 howto |= RB_VERBOSE;
93 break;
94 default:
95 active = 0;
96 break;
97 }
98 active = 0;
99 cp++;
97 }
100 }
98 cp++;
99 }
101 }
102 /* get equivalents from the environment */
100 for (i = 0; howto_names[i].ev != NULL; i++)
101 if (getenv(howto_names[i].ev) != NULL)
102 howto |= howto_names[i].mask;
103 if (!strcmp(getenv("console"), "comconsole"))
104 howto |= RB_SERIAL;
105 return(howto);
106}
107
108/*
109 * Copy the environment into the load area starting at (addr).
110 * Each variable is formatted as <name>=<value>, with a single nul
111 * separating each variable, and a double nul terminating the environment.
112 */
113vm_offset_t
114bi_copyenv(vm_offset_t addr)
115{
116 struct env_var *ep;
117
118 /* traverse the environment */
119 for (ep = environ; ep != NULL; ep = ep->ev_next) {
120 vpbcopy(ep->ev_name, addr, strlen(ep->ev_name));
121 addr += strlen(ep->ev_name);
122 vpbcopy("=", addr, 1);
123 addr++;
124 if (ep->ev_value != NULL) {
125 vpbcopy(ep->ev_value, addr, strlen(ep->ev_value));
126 addr += strlen(ep->ev_value);
127 }
128 vpbcopy("", addr, 1);
129 addr++;
130 }
131 vpbcopy("", addr, 1);
132 addr++;
133}
134
135/*
136 * Copy module-related data into the load area, where it can be
137 * used as a directory for loaded modules.
138 *
139 * Module data is presented in a self-describing format. Each datum
103 for (i = 0; howto_names[i].ev != NULL; i++)
104 if (getenv(howto_names[i].ev) != NULL)
105 howto |= howto_names[i].mask;
106 if (!strcmp(getenv("console"), "comconsole"))
107 howto |= RB_SERIAL;
108 return(howto);
109}
110
111/*
112 * Copy the environment into the load area starting at (addr).
113 * Each variable is formatted as <name>=<value>, with a single nul
114 * separating each variable, and a double nul terminating the environment.
115 */
116vm_offset_t
117bi_copyenv(vm_offset_t addr)
118{
119 struct env_var *ep;
120
121 /* traverse the environment */
122 for (ep = environ; ep != NULL; ep = ep->ev_next) {
123 vpbcopy(ep->ev_name, addr, strlen(ep->ev_name));
124 addr += strlen(ep->ev_name);
125 vpbcopy("=", addr, 1);
126 addr++;
127 if (ep->ev_value != NULL) {
128 vpbcopy(ep->ev_value, addr, strlen(ep->ev_value));
129 addr += strlen(ep->ev_value);
130 }
131 vpbcopy("", addr, 1);
132 addr++;
133 }
134 vpbcopy("", addr, 1);
135 addr++;
136}
137
138/*
139 * Copy module-related data into the load area, where it can be
140 * used as a directory for loaded modules.
141 *
142 * Module data is presented in a self-describing format. Each datum
140 * is preceeded by a 16-bit identifier and a 16-bit size field.
143 * is preceeded by a 32-bit identifier and a 32-bit size field.
141 *
142 * Currently, the following data are saved:
143 *
144 * MOD_NAME (variable) module name (string)
145 * MOD_TYPE (variable) module type (string)
146 * MOD_ADDR sizeof(vm_offset_t) module load address
147 * MOD_SIZE sizeof(size_t) module size
148 * MOD_METADATA (variable) type-specific metadata
149 */
150#define MOD_STR(t, a, s) { \
151 u_int32_t ident = (t << 16) + strlen(s) + 1; \
152 vpbcopy(&ident, a, sizeof(ident)); \
153 a += sizeof(ident); \
154 vpbcopy(s, a, strlen(s) + 1); \
155 a += strlen(s) + 1; \
156}
157
158#define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s)
159#define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s)
160
161#define MOD_VAR(t, a, s) { \
162 u_int32_t ident = (t << 16) + sizeof(s); \
163 vpbcopy(&ident, a, sizeof(ident)); \
164 a += sizeof(ident); \
165 vpbcopy(&s, a, sizeof(s)); \
166 a += sizeof(s); \
167}
168
169#define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s)
170#define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s)
171
172#define MOD_METADATA(a, mm) { \
173 u_int32_t ident = ((MODINFO_METADATA | mm->md_type) << 16) + mm->md_size; \
174 vpbcopy(&ident, a, sizeof(ident)); \
175 a += sizeof(ident); \
176 vpbcopy(mm->md_data, a, mm->md_size); \
177 a += mm->md_size; \
178}
179
144 *
145 * Currently, the following data are saved:
146 *
147 * MOD_NAME (variable) module name (string)
148 * MOD_TYPE (variable) module type (string)
149 * MOD_ADDR sizeof(vm_offset_t) module load address
150 * MOD_SIZE sizeof(size_t) module size
151 * MOD_METADATA (variable) type-specific metadata
152 */
153#define MOD_STR(t, a, s) { \
154 u_int32_t ident = (t << 16) + strlen(s) + 1; \
155 vpbcopy(&ident, a, sizeof(ident)); \
156 a += sizeof(ident); \
157 vpbcopy(s, a, strlen(s) + 1); \
158 a += strlen(s) + 1; \
159}
160
161#define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s)
162#define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s)
163
164#define MOD_VAR(t, a, s) { \
165 u_int32_t ident = (t << 16) + sizeof(s); \
166 vpbcopy(&ident, a, sizeof(ident)); \
167 a += sizeof(ident); \
168 vpbcopy(&s, a, sizeof(s)); \
169 a += sizeof(s); \
170}
171
172#define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s)
173#define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s)
174
175#define MOD_METADATA(a, mm) { \
176 u_int32_t ident = ((MODINFO_METADATA | mm->md_type) << 16) + mm->md_size; \
177 vpbcopy(&ident, a, sizeof(ident)); \
178 a += sizeof(ident); \
179 vpbcopy(mm->md_data, a, mm->md_size); \
180 a += mm->md_size; \
181}
182
183#define MOD_END(a) { \
184 u_int32_t ident = 0; \
185 vpbcopy(&ident, a, sizeof(ident)); \
186 a += sizeof(ident); \
187 vpbcopy(&ident, a, sizeof(ident)); \
188 a += sizeof(ident); \
189}
190
180vm_offset_t
181bi_copymodules(vm_offset_t addr)
182{
183 struct loaded_module *mp;
184 struct module_metadata *md;
185
186 /* start with the first module on the list, should be the kernel */
187 for (mp = mod_findmodule(NULL, NULL); mp != NULL; mp = mp->m_next) {
188
191vm_offset_t
192bi_copymodules(vm_offset_t addr)
193{
194 struct loaded_module *mp;
195 struct module_metadata *md;
196
197 /* start with the first module on the list, should be the kernel */
198 for (mp = mod_findmodule(NULL, NULL); mp != NULL; mp = mp->m_next) {
199
189 MOD_NAME(addr, mp->m_name);
200 MOD_NAME(addr, mp->m_name); /* this field must come first */
190 MOD_TYPE(addr, mp->m_type);
191 MOD_ADDR(addr, mp->m_addr);
192 MOD_SIZE(addr, mp->m_size);
193 for (md = mp->m_metadata; md != NULL; md = md->md_next)
194 if (!(md->md_type & MODINFOMD_NOCOPY))
195 MOD_METADATA(addr, md);
196 }
201 MOD_TYPE(addr, mp->m_type);
202 MOD_ADDR(addr, mp->m_addr);
203 MOD_SIZE(addr, mp->m_size);
204 for (md = mp->m_metadata; md != NULL; md = md->md_next)
205 if (!(md->md_type & MODINFOMD_NOCOPY))
206 MOD_METADATA(addr, md);
207 }
208 MOD_END(addr);
197 return(addr);
198}
209 return(addr);
210}