freebsd-dev/sys/boot/common/bootstrap.h

319 lines
10 KiB
C
Raw Normal View History

/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
1999-08-28 01:08:13 +00:00
* $FreeBSD$
*/
#include <sys/types.h>
#include <sys/queue.h>
/* XXX debugging */
extern struct console vidconsole;
#define MARK(s, c) {vidconsole.c_out(s); vidconsole.c_out(c); while (!vidconsole.c_ready()) ; vidconsole.c_in();}
/*
* Generic device specifier; architecture-dependant
* versions may be larger, but should be allowed to
* overlap.
*/
struct devdesc
{
struct devsw *d_dev;
int d_type;
#define DEVT_NONE 0
#define DEVT_DISK 1
#define DEVT_NET 2
};
/* Commands and return values; nonzero return sets command_errmsg != NULL */
typedef int (bootblk_cmd_t)(int argc, char *argv[]);
extern char *command_errmsg;
extern char command_errbuf[]; /* XXX blah, length */
#define CMD_OK 0
#define CMD_ERROR 1
/* interp.c */
extern void interact(void);
extern int include(char *filename);
/* interp_parse.c */
extern int parse(int *argc, char ***argv, char *str);
/* interp_forth.c */
extern void bf_init(void);
extern int bf_run(char *line);
/* boot.c */
extern int autoboot(int delay, char *prompt);
extern void autoboot_maybe(void);
extern int getrootmount(char *rootdev);
/* misc.c */
extern char *unargv(int argc, char *argv[]);
extern void hexdump(caddr_t region, size_t len);
Bootstrap updates. - Move some startup code from MD to MI sections - Add a 'copyout' and some copyout-related functions. These will be obsoleted when BTX is available for the 386 and the kernel load area becomes directly addressable. - Add the ability load an arbitrary file as a module, associating and arbitrary type string with it. This can be used eg. for loading splash-screen images etc. - Add KLD module dependancy infrastructure. We know how to look for dependancies inside KLD modules, how to resolve these dependancies and what to do if things go wrong. Only works for a.out at the moment, due to lack of an MI ELF loader. Attach KLD module information to loaded modules as metadata, but don't pass it to the kernel (it can find it itself). - Load a.out KLD modules on a page boundary. Only pad the a.out BSS for the kernel, as it may want to throw symbols away. (We might want to do this for KLD modules too.) - Allow commands to be hidden from the '?' display, to avoid cluttering it with things like 'echo'. Add 'echo'. - Bring the 'prompt' command into line with the parser syntax. - Fix the verbose 'ls'; it was using an uninitialised stack variable. - Add a '-v' flag to 'lsmod' to have it display module metadata as well (not terribly useful for the average user) - Support a 'module searchpath' for required modules. - The bootstrap file on i386 is now called 'loader' to permit the /boot directory to use that name. - Discard the old i386 pread() function, as it's replaced by arch_readin()
1998-09-03 02:10:09 +00:00
extern size_t strlenout(vm_offset_t str);
extern char *strdupout(vm_offset_t str);
/* bcache.c */
extern int bcache_init(int nblks, size_t bsize);
extern void bcache_flush();
/*
* Disk block cache
*/
struct bcache_devdata
{
int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, void *buf, size_t *rsize);
void *dv_devdata;
};
/*
* Modular console support.
*/
struct console
{
char *c_name;
char *c_desc;
int c_flags;
#define C_PRESENTIN (1<<0)
#define C_PRESENTOUT (1<<1)
#define C_ACTIVEIN (1<<2)
#define C_ACTIVEOUT (1<<3)
void (* c_probe)(struct console *cp); /* set c_flags to match hardware */
int (* c_init)(int arg); /* reinit XXX may need more args */
void (* c_out)(int c); /* emit c */
int (* c_in)(void); /* wait for and return input */
int (* c_ready)(void); /* return nonzer if input waiting */
};
extern struct console *consoles[];
extern void cons_probe(void);
/*
* Plug-and-play enumerator/configurator interface.
*/
struct pnphandler
{
char *pp_name; /* handler/bus name */
void (* pp_enumerate)(void); /* enumerate PnP devices, add to chain */
};
struct pnpident
{
char *id_ident; /* ASCII identifier, actual format varies with bus/handler */
STAILQ_ENTRY(pnpident) id_link;
};
struct pnpinfo
{
char *pi_desc; /* ASCII description, optional */
int pi_revision; /* optional revision (or -1) if not supported */
char *pi_module; /* module/args nominated to handle device */
int pi_argc; /* module arguments */
char **pi_argv;
struct pnphandler *pi_handler; /* handler which detected this device */
STAILQ_HEAD(,pnpident) pi_ident; /* list of identifiers */
STAILQ_ENTRY(pnpinfo) pi_link;
};
extern struct pnphandler *pnphandlers[]; /* provided by MD code */
extern void pnp_addident(struct pnpinfo *pi, char *ident);
extern struct pnpinfo *pnp_allocinfo(void);
extern void pnp_freeinfo(struct pnpinfo *pi);
extern void pnp_addinfo(struct pnpinfo *pi);
extern char *pnp_eisaformat(u_int8_t *data);
/*
* < 0 - No ISA in system
* == 0 - Maybe ISA, search for read data port
* > 0 - ISA in system, value is read data port address
*/
extern int isapnp_readport;
/*
* Preloaded file metadata header.
*
* Metadata are allocated on our heap, and copied into kernel space
* before executing the kernel.
*/
struct file_metadata
{
size_t md_size;
u_int16_t md_type;
struct file_metadata *md_next;
char md_data[0]; /* data are immediately appended */
};
struct preloaded_file;
struct kernel_module
{
char *m_name; /* module name */
/* char *m_args;*/ /* arguments for the module */
struct preloaded_file *m_fp;
struct kernel_module *m_next;
};
/*
* Preloaded file information. Depending on type, file can contain
* additional units called 'modules'.
*
* At least one file (the kernel) must be loaded in order to boot.
* The kernel is always loaded first.
*
* String fields (m_name, m_type) should be dynamically allocated.
*/
struct preloaded_file
{
char *f_name; /* file name */
char *f_type; /* verbose file type, eg 'ELF kernel', 'pnptable', etc. */
char *f_args; /* arguments for the file */
struct file_metadata *f_metadata; /* metadata that will be placed in the module directory */
int f_loader; /* index of the loader that read the file */
vm_offset_t f_addr; /* load address */
size_t f_size; /* file size */
struct kernel_module *f_modules; /* list of modules if any */
struct preloaded_file *f_next; /* next file */
};
struct file_format
{
/* Load function must return EFTYPE if it can't handle the module supplied */
int (* l_load)(char *filename, vm_offset_t dest, struct preloaded_file **result);
/* Only a loader that will load a kernel (first module) should have an exec handler */
int (* l_exec)(struct preloaded_file *mp);
};
extern struct file_format *file_formats[]; /* supplied by consumer */
extern struct preloaded_file *preloaded_files;
extern int mod_load(char *name, int argc, char *argv[]);
Bootstrap updates. - Move some startup code from MD to MI sections - Add a 'copyout' and some copyout-related functions. These will be obsoleted when BTX is available for the 386 and the kernel load area becomes directly addressable. - Add the ability load an arbitrary file as a module, associating and arbitrary type string with it. This can be used eg. for loading splash-screen images etc. - Add KLD module dependancy infrastructure. We know how to look for dependancies inside KLD modules, how to resolve these dependancies and what to do if things go wrong. Only works for a.out at the moment, due to lack of an MI ELF loader. Attach KLD module information to loaded modules as metadata, but don't pass it to the kernel (it can find it itself). - Load a.out KLD modules on a page boundary. Only pad the a.out BSS for the kernel, as it may want to throw symbols away. (We might want to do this for KLD modules too.) - Allow commands to be hidden from the '?' display, to avoid cluttering it with things like 'echo'. Add 'echo'. - Bring the 'prompt' command into line with the parser syntax. - Fix the verbose 'ls'; it was using an uninitialised stack variable. - Add a '-v' flag to 'lsmod' to have it display module metadata as well (not terribly useful for the average user) - Support a 'module searchpath' for required modules. - The bootstrap file on i386 is now called 'loader' to permit the /boot directory to use that name. - Discard the old i386 pread() function, as it's replaced by arch_readin()
1998-09-03 02:10:09 +00:00
extern int mod_loadobj(char *type, char *name);
struct preloaded_file *file_alloc(void);
struct preloaded_file *file_findfile(char *name, char *type);
struct file_metadata *file_findmetadata(struct preloaded_file *fp, int type);
void file_discard(struct preloaded_file *fp);
void file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p);
int file_addmodule(struct preloaded_file *fp, char *modname,
struct kernel_module **newmp);
/* MI module loaders */
extern int aout_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
extern vm_offset_t aout_findsym(char *name, struct preloaded_file *fp);
extern int elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
#ifndef NEW_LINKER_SET
#include <sys/linker_set.h>
/* XXX just for conversion's sake, until we move to the new linker set code */
#define SET_FOREACH(pvar, set) \
for ((char*) pvar = set.ls_items; \
(char*) pvar < (char*) &set.ls_items[set.ls_length]; \
pvar++)
#else /* NEW_LINKER_SET */
/*
* Private macros, not to be used outside this header file.
*/
#define __MAKE_SET(set, sym) \
static void *__CONCAT(__setentry,__LINE__) \
__attribute__((__section__("set_" #set),__unused__)) = &sym
#define __SET_BEGIN(set) \
({ extern void *__CONCAT(__start_set_,set); \
&__CONCAT(__start_set_,set); })
#define __SET_END(set) \
({ extern void *__CONCAT(__stop_set_,set); \
&__CONCAT(__stop_set_,set); })
/*
* Public macros.
*/
/* Add an entry to a set. */
#define DATA_SET(set, sym) __MAKE_SET(set, sym)
/*
* Iterate over all the elements of a set.
*
* Sets always contain addresses of things, and "pvar" points to words
* containing those addresses. Thus is must be declared as "type **pvar",
* and the address of each set item is obtained inside the loop by "*pvar".
*/
#define SET_FOREACH(pvar, set) \
for (pvar = (__typeof__(pvar))__SET_BEGIN(set); \
pvar < (__typeof__(pvar))__SET_END(set); pvar++)
#endif
/*
* Support for commands
*/
struct bootblk_command
{
const char *c_name;
const char *c_desc;
bootblk_cmd_t *c_fn;
};
#define COMMAND_SET(tag, key, desc, func) \
static bootblk_cmd_t func; \
static struct bootblk_command _cmd_ ## tag = { key, desc, func }; \
DATA_SET(Xcommand_set, _cmd_ ## tag);
extern struct linker_set Xcommand_set;
/*
* The intention of the architecture switch is to provide a convenient
* encapsulation of the interface between the bootstrap MI and MD code.
* MD code may selectively populate the switch at runtime based on the
* actual configuration of the target system.
*/
struct arch_switch
{
/* Automatically load modules as required by detected hardware */
int (* arch_autoload)();
/* Locate the device for (name), return pointer to tail in (*path) */
int (*arch_getdev)(void **dev, const char *name, const char **path);
/* Copy from local address space to module address space, similar to bcopy() */
int (*arch_copyin)(void *src, vm_offset_t dest, size_t len);
Bootstrap updates. - Move some startup code from MD to MI sections - Add a 'copyout' and some copyout-related functions. These will be obsoleted when BTX is available for the 386 and the kernel load area becomes directly addressable. - Add the ability load an arbitrary file as a module, associating and arbitrary type string with it. This can be used eg. for loading splash-screen images etc. - Add KLD module dependancy infrastructure. We know how to look for dependancies inside KLD modules, how to resolve these dependancies and what to do if things go wrong. Only works for a.out at the moment, due to lack of an MI ELF loader. Attach KLD module information to loaded modules as metadata, but don't pass it to the kernel (it can find it itself). - Load a.out KLD modules on a page boundary. Only pad the a.out BSS for the kernel, as it may want to throw symbols away. (We might want to do this for KLD modules too.) - Allow commands to be hidden from the '?' display, to avoid cluttering it with things like 'echo'. Add 'echo'. - Bring the 'prompt' command into line with the parser syntax. - Fix the verbose 'ls'; it was using an uninitialised stack variable. - Add a '-v' flag to 'lsmod' to have it display module metadata as well (not terribly useful for the average user) - Support a 'module searchpath' for required modules. - The bootstrap file on i386 is now called 'loader' to permit the /boot directory to use that name. - Discard the old i386 pread() function, as it's replaced by arch_readin()
1998-09-03 02:10:09 +00:00
/* Copy to local address space from module address space, similar to bcopy() */
int (*arch_copyout)(vm_offset_t src, void *dest, size_t len);
/* Read from file to module address space, same semantics as read() */
int (*arch_readin)(int fd, vm_offset_t dest, size_t len);
/* Perform ISA byte port I/O (only for systems with ISA) */
int (*arch_isainb)(int port);
void (*arch_isaoutb)(int port, int value);
};
extern struct arch_switch archsw;
/* This must be provided by the MD code, but should it be in the archsw? */
extern void delay(int delay);
extern void dev_cleanup(void);