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
29 #include <sys/types.h>
30 #include <sys/queue.h>
33 extern struct console vidconsole;
34 #define MARK(s, c) {vidconsole.c_out(s); vidconsole.c_out(c); while (!vidconsole.c_ready()) ; vidconsole.c_in();}
37 * Generic device specifier; architecture-dependant
38 * versions may be larger, but should be allowed to
50 /* Commands and return values; nonzero return sets command_errmsg != NULL */
51 typedef int (bootblk_cmd_t)(int argc, char *argv[]);
52 extern char *command_errmsg;
53 extern char command_errbuf[]; /* XXX blah, length */
58 extern void interact(void);
59 extern int include(char *filename);
62 extern int parse(int *argc, char ***argv, char *str);
65 extern void bf_init(void);
66 extern int bf_run(char *line);
69 extern int autoboot(int delay, char *prompt);
70 extern void autoboot_maybe(void);
71 extern int getrootmount(char *rootdev);
74 extern char *unargv(int argc, char *argv[]);
75 extern void hexdump(caddr_t region, size_t len);
76 extern size_t strlenout(vm_offset_t str);
77 extern char *strdupout(vm_offset_t str);
80 extern int bcache_init(int nblks, size_t bsize);
81 extern void bcache_flush();
88 int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, void *buf, size_t *rsize);
93 * Modular console support.
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 */
110 extern struct console *consoles[];
111 extern void cons_probe(void);
114 * Plug-and-play enumerator/configurator interface.
118 char *pp_name; /* handler/bus name */
119 void (* pp_enumerate)(void); /* enumerate PnP devices, add to chain */
124 char *id_ident; /* ASCII identifier, actual format varies with bus/handler */
125 STAILQ_ENTRY(pnpident) id_link;
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 */
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;
140 extern struct pnphandler *pnphandlers[]; /* provided by MD code */
142 extern void pnp_addident(struct pnpinfo *pi, char *ident);
143 extern struct pnpinfo *pnp_allocinfo(void);
144 extern void pnp_freeinfo(struct pnpinfo *pi);
145 extern void pnp_addinfo(struct pnpinfo *pi);
146 extern char *pnp_eisaformat(u_int8_t *data);
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
153 extern int isapnp_readport;
156 * Preloaded file metadata header.
158 * Metadata are allocated on our heap, and copied into kernel space
159 * before executing the kernel.
165 struct file_metadata *md_next;
166 char md_data[0]; /* data are immediately appended */
169 struct preloaded_file;
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;
180 * Preloaded file information. Depending on type, file can contain
181 * additional units called 'modules'.
183 * At least one file (the kernel) must be loaded in order to boot.
184 * The kernel is always loaded first.
186 * String fields (m_name, m_type) should be dynamically allocated.
188 struct preloaded_file
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 */
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);
209 extern struct file_format *file_formats[]; /* supplied by consumer */
210 extern struct preloaded_file *preloaded_files;
212 extern int mod_load(char *name, int argc, char *argv[]);
213 extern int mod_loadobj(char *type, char *name);
215 struct preloaded_file *file_alloc(void);
216 struct preloaded_file *file_findfile(char *name, char *type);
217 struct file_metadata *file_findmetadata(struct preloaded_file *fp, int type);
218 void file_discard(struct preloaded_file *fp);
219 void file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p);
220 int file_addmodule(struct preloaded_file *fp, char *modname,
221 struct kernel_module **newmp);
224 /* MI module loaders */
225 extern int aout_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
226 extern vm_offset_t aout_findsym(char *name, struct preloaded_file *fp);
228 extern int elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
230 #ifndef NEW_LINKER_SET
231 #include <sys/linker_set.h>
233 /* XXX just for conversion's sake, until we move to the new linker set code */
235 #define SET_FOREACH(pvar, set) \
236 for ((char*) pvar = set.ls_items; \
237 (char*) pvar < (char*) &set.ls_items[set.ls_length]; \
240 #else /* NEW_LINKER_SET */
243 * Private macros, not to be used outside this header file.
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); })
259 /* Add an entry to a set. */
260 #define DATA_SET(set, sym) __MAKE_SET(set, sym)
263 * Iterate over all the elements of a set.
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".
269 #define SET_FOREACH(pvar, set) \
270 for (pvar = (__typeof__(pvar))__SET_BEGIN(set); \
271 pvar < (__typeof__(pvar))__SET_END(set); pvar++)
275 * Support for commands
277 struct bootblk_command
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);
289 extern struct linker_set Xcommand_set;
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.
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);
313 extern struct arch_switch archsw;
315 /* This must be provided by the MD code, but should it be in the archsw? */
316 extern void delay(int delay);