Deleted Added
sdiff udiff text old ( 60938 ) new ( 61659 )
full compact
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 * $FreeBSD: head/sys/boot/common/bootstrap.h 61659 2000-06-14 10:34:29Z ps $
27 */
28
29#include <sys/types.h>
30#include <sys/queue.h>
31
32/* XXX debugging */
33extern struct console vidconsole;
34#define MARK(s, c) {vidconsole.c_out(s); vidconsole.c_out(c); while (!vidconsole.c_ready()) ; vidconsole.c_in();}
35
36/*
37 * Generic device specifier; architecture-dependant
38 * versions may be larger, but should be allowed to
39 * overlap.
40 */
41struct devdesc
42{
43 struct devsw *d_dev;
44 int d_type;
45#define DEVT_NONE 0
46#define DEVT_DISK 1
47#define DEVT_NET 2
48};
49
50/* Commands and return values; nonzero return sets command_errmsg != NULL */
51typedef int (bootblk_cmd_t)(int argc, char *argv[]);
52extern char *command_errmsg;
53extern char command_errbuf[]; /* XXX blah, length */
54#define CMD_OK 0
55#define CMD_ERROR 1
56
57/* interp.c */
58extern void interact(void);
59extern int include(char *filename);
60
61/* interp_parse.c */
62extern int parse(int *argc, char ***argv, char *str);
63
64/* interp_forth.c */
65extern void bf_init(void);
66extern int bf_run(char *line);
67
68/* boot.c */
69extern int autoboot(int delay, char *prompt);
70extern void autoboot_maybe(void);
71extern int getrootmount(char *rootdev);
72
73/* misc.c */
74extern char *unargv(int argc, char *argv[]);
75extern void hexdump(caddr_t region, size_t len);
76extern size_t strlenout(vm_offset_t str);
77extern char *strdupout(vm_offset_t str);
78
79/* bcache.c */
80extern int bcache_init(int nblks, size_t bsize);
81extern void bcache_flush();
82
83/*
84 * Disk block cache
85 */
86struct bcache_devdata
87{
88 int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, void *buf, size_t *rsize);
89 void *dv_devdata;
90};
91
92/*
93 * Modular console support.
94 */
95struct console
96{
97 char *c_name;
98 char *c_desc;
99 int c_flags;
100#define C_PRESENTIN (1<<0)
101#define C_PRESENTOUT (1<<1)
102#define C_ACTIVEIN (1<<2)
103#define C_ACTIVEOUT (1<<3)
104 void (* c_probe)(struct console *cp); /* set c_flags to match hardware */
105 int (* c_init)(int arg); /* reinit XXX may need more args */
106 void (* c_out)(int c); /* emit c */
107 int (* c_in)(void); /* wait for and return input */
108 int (* c_ready)(void); /* return nonzer if input waiting */
109};
110extern struct console *consoles[];
111extern void cons_probe(void);
112
113/*
114 * Plug-and-play enumerator/configurator interface.
115 */
116struct pnphandler
117{
118 char *pp_name; /* handler/bus name */
119 void (* pp_enumerate)(void); /* enumerate PnP devices, add to chain */
120};
121
122struct pnpident
123{
124 char *id_ident; /* ASCII identifier, actual format varies with bus/handler */
125 STAILQ_ENTRY(pnpident) id_link;
126};
127
128struct pnpinfo
129{
130 char *pi_desc; /* ASCII description, optional */
131 int pi_revision; /* optional revision (or -1) if not supported */
132 char *pi_module; /* module/args nominated to handle device */
133 int pi_argc; /* module arguments */
134 char **pi_argv;
135 struct pnphandler *pi_handler; /* handler which detected this device */
136 STAILQ_HEAD(,pnpident) pi_ident; /* list of identifiers */
137 STAILQ_ENTRY(pnpinfo) pi_link;
138};
139
140extern struct pnphandler *pnphandlers[]; /* provided by MD code */
141
142extern void pnp_addident(struct pnpinfo *pi, char *ident);
143extern struct pnpinfo *pnp_allocinfo(void);
144extern void pnp_freeinfo(struct pnpinfo *pi);
145extern void pnp_addinfo(struct pnpinfo *pi);
146extern char *pnp_eisaformat(u_int8_t *data);
147
148/*
149 * < 0 - No ISA in system
150 * == 0 - Maybe ISA, search for read data port
151 * > 0 - ISA in system, value is read data port address
152 */
153extern int isapnp_readport;
154
155/*
156 * Preloaded file metadata header.
157 *
158 * Metadata are allocated on our heap, and copied into kernel space
159 * before executing the kernel.
160 */
161struct file_metadata
162{
163 size_t md_size;
164 u_int16_t md_type;
165 struct file_metadata *md_next;
166 char md_data[0]; /* data are immediately appended */
167};
168
169struct preloaded_file;
170
171struct kernel_module
172{
173 char *m_name; /* module name */
174/* char *m_args;*/ /* arguments for the module */
175 struct preloaded_file *m_fp;
176 struct kernel_module *m_next;
177};
178
179/*
180 * Preloaded file information. Depending on type, file can contain
181 * additional units called 'modules'.
182 *
183 * At least one file (the kernel) must be loaded in order to boot.
184 * The kernel is always loaded first.
185 *
186 * String fields (m_name, m_type) should be dynamically allocated.
187 */
188struct preloaded_file
189{
190 char *f_name; /* file name */
191 char *f_type; /* verbose file type, eg 'ELF kernel', 'pnptable', etc. */
192 char *f_args; /* arguments for the file */
193 struct file_metadata *f_metadata; /* metadata that will be placed in the module directory */
194 int f_loader; /* index of the loader that read the file */
195 vm_offset_t f_addr; /* load address */
196 size_t f_size; /* file size */
197 struct kernel_module *f_modules; /* list of modules if any */
198 struct preloaded_file *f_next; /* next file */
199};
200
201struct file_format
202{
203 /* Load function must return EFTYPE if it can't handle the module supplied */
204 int (* l_load)(char *filename, vm_offset_t dest, struct preloaded_file **result);
205 /* Only a loader that will load a kernel (first module) should have an exec handler */
206 int (* l_exec)(struct preloaded_file *mp);
207};
208
209extern struct file_format *file_formats[]; /* supplied by consumer */
210extern struct preloaded_file *preloaded_files;
211
212extern int mod_load(char *name, int argc, char *argv[]);
213extern int mod_loadobj(char *type, char *name);
214
215struct preloaded_file *file_alloc(void);
216struct preloaded_file *file_findfile(char *name, char *type);
217struct file_metadata *file_findmetadata(struct preloaded_file *fp, int type);
218void file_discard(struct preloaded_file *fp);
219void file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p);
220int file_addmodule(struct preloaded_file *fp, char *modname,
221 struct kernel_module **newmp);
222
223
224/* MI module loaders */
225extern int aout_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
226extern vm_offset_t aout_findsym(char *name, struct preloaded_file *fp);
227
228extern int elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
229
230#ifndef NEW_LINKER_SET
231#include <sys/linker_set.h>
232
233/* XXX just for conversion's sake, until we move to the new linker set code */
234
235#define SET_FOREACH(pvar, set) \
236 for ((char*) pvar = set.ls_items; \
237 (char*) pvar < (char*) &set.ls_items[set.ls_length]; \
238 pvar++)
239
240#else /* NEW_LINKER_SET */
241
242/*
243 * Private macros, not to be used outside this header file.
244 */
245#define __MAKE_SET(set, sym) \
246 static void *__CONCAT(__setentry,__LINE__) \
247 __attribute__((__section__("set_" #set),__unused__)) = &sym
248#define __SET_BEGIN(set) \
249 ({ extern void *__CONCAT(__start_set_,set); \
250 &__CONCAT(__start_set_,set); })
251#define __SET_END(set) \
252 ({ extern void *__CONCAT(__stop_set_,set); \
253 &__CONCAT(__stop_set_,set); })
254
255/*
256 * Public macros.
257 */
258
259/* Add an entry to a set. */
260#define DATA_SET(set, sym) __MAKE_SET(set, sym)
261
262/*
263 * Iterate over all the elements of a set.
264 *
265 * Sets always contain addresses of things, and "pvar" points to words
266 * containing those addresses. Thus is must be declared as "type **pvar",
267 * and the address of each set item is obtained inside the loop by "*pvar".
268 */
269#define SET_FOREACH(pvar, set) \
270 for (pvar = (__typeof__(pvar))__SET_BEGIN(set); \
271 pvar < (__typeof__(pvar))__SET_END(set); pvar++)
272#endif
273
274/*
275 * Support for commands
276 */
277struct bootblk_command
278{
279 const char *c_name;
280 const char *c_desc;
281 bootblk_cmd_t *c_fn;
282};
283
284#define COMMAND_SET(tag, key, desc, func) \
285 static bootblk_cmd_t func; \
286 static struct bootblk_command _cmd_ ## tag = { key, desc, func }; \
287 DATA_SET(Xcommand_set, _cmd_ ## tag);
288
289extern struct linker_set Xcommand_set;
290
291/*
292 * The intention of the architecture switch is to provide a convenient
293 * encapsulation of the interface between the bootstrap MI and MD code.
294 * MD code may selectively populate the switch at runtime based on the
295 * actual configuration of the target system.
296 */
297struct arch_switch
298{
299 /* Automatically load modules as required by detected hardware */
300 int (* arch_autoload)();
301 /* Locate the device for (name), return pointer to tail in (*path) */
302 int (*arch_getdev)(void **dev, const char *name, const char **path);
303 /* Copy from local address space to module address space, similar to bcopy() */
304 int (*arch_copyin)(void *src, vm_offset_t dest, size_t len);
305 /* Copy to local address space from module address space, similar to bcopy() */
306 int (*arch_copyout)(vm_offset_t src, void *dest, size_t len);
307 /* Read from file to module address space, same semantics as read() */
308 int (*arch_readin)(int fd, vm_offset_t dest, size_t len);
309 /* Perform ISA byte port I/O (only for systems with ISA) */
310 int (*arch_isainb)(int port);
311 void (*arch_isaoutb)(int port, int value);
312};
313extern struct arch_switch archsw;
314
315/* This must be provided by the MD code, but should it be in the archsw? */
316extern void delay(int delay);
317
318extern void dev_cleanup(void);