199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _BOOTSTRAP_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _BOOTSTRAP_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/types.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/queue.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/linker_set.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Commands and return values; nonzero return sets command_errmsg != NULL */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int (bootblk_cmd_t)(int argc, char *argv[]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define COMMAND_ERRBUFSZ (256)
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern const char *command_errmsg;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char command_errbuf[COMMAND_ERRBUFSZ];
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMD_OK 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMD_WARN 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMD_ERROR 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMD_CRIT 3
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CMD_FATAL 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* interp.c */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid interact(const char *rc);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint include(const char *filename);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* interp_backslash.c */
199767f8919635c4928607450d9e0abb932109ceToomas Soomechar *backslash(char *str);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* interp_parse.c */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint parse(int *argc, char ***argv, char *str);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* interp_forth.c */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid bf_init(char *rc);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint bf_run(char *line);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* boot.c */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint autoboot(int timeout, char *prompt);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid autoboot_maybe(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint getrootmount(char *rootdev);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* misc.c */
199767f8919635c4928607450d9e0abb932109ceToomas Soomechar *unargv(int argc, char *argv[]);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid hexdump(caddr_t region, size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soomesize_t strlenout(vm_offset_t str);
199767f8919635c4928607450d9e0abb932109ceToomas Soomechar *strdupout(vm_offset_t str);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid kern_bzero(vm_offset_t dest, size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kern_pread(int fd, vm_offset_t dest, size_t len, off_t off);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid *alloc_pread(int fd, off_t off, size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* bcache.c */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid bcache_init(u_int nblks, size_t bsize);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid bcache_add_dev(int);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid *bcache_allocate(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid bcache_free(void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint bcache_strategy(void *devdata, int rw, daddr_t blk,
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t offset, size_t size, char *buf, size_t *rsize);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Disk block cache
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct bcache_devdata
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*dv_strategy)(void *devdata, int rw, daddr_t blk,
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t offset, size_t size, char *buf, size_t *rsize);
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *dv_devdata;
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *dv_cache;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Modular console support.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct console
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *c_name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *c_desc;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int c_flags;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define C_PRESENTIN (1<<0) /* console can provide input */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define C_PRESENTOUT (1<<1) /* console can provide output */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define C_ACTIVEIN (1<<2) /* user wants input from console */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define C_ACTIVEOUT (1<<3) /* user wants output to console */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define C_MODERAW (1<<4) /* raw mode */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*c_probe)(struct console *); /* set c_flags to match hardware */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*c_init)(struct console *, int); /* reinit XXX may need more args */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*c_out)(struct console *, int); /* emit c */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*c_in)(struct console *); /* wait for and return input */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*c_ready)(struct console *); /* return nonzer if input waiting */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *private; /* private data */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern struct console *consoles[];
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid cons_probe(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid cons_mode(int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Plug-and-play enumerator/configurator interface.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct pnphandler
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *pp_name; /* handler/bus name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (* pp_enumerate)(void); /* enumerate PnP devices, add to chain */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct pnpident
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *id_ident; /* ASCII identifier, actual format varies with bus/handler */
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_ENTRY(pnpident) id_link;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct pnpinfo
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *pi_desc; /* ASCII description, optional */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int pi_revision; /* optional revision (or -1) if not supported */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *pi_module; /* module/args nominated to handle device */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int pi_argc; /* module arguments */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char **pi_argv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct pnphandler *pi_handler; /* handler which detected this device */
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_HEAD(,pnpident) pi_ident; /* list of identifiers */
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_ENTRY(pnpinfo) pi_link;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeSTAILQ_HEAD(pnpinfo_stql, pnpinfo);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern struct pnpinfo_stql pnp_devices;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern struct pnphandler *pnphandlers[]; /* provided by MD code */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid pnp_addident(struct pnpinfo *pi, char *ident);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct pnpinfo *pnp_allocinfo(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid pnp_freeinfo(struct pnpinfo *pi);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid pnp_addinfo(struct pnpinfo *pi);
199767f8919635c4928607450d9e0abb932109ceToomas Soomechar *pnp_eisaformat(u_int8_t *data);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * < 0 - No ISA in system
199767f8919635c4928607450d9e0abb932109ceToomas Soome * == 0 - Maybe ISA, search for read data port
199767f8919635c4928607450d9e0abb932109ceToomas Soome * > 0 - ISA in system, value is read data port address
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int isapnp_readport;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Preloaded file metadata header.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Metadata are allocated on our heap, and copied into kernel space
199767f8919635c4928607450d9e0abb932109ceToomas Soome * before executing the kernel.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct file_metadata
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t md_size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int16_t md_type;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct file_metadata *md_next;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char md_data[1]; /* data are immediately appended */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct preloaded_file;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct mod_depend;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct kernel_module
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *m_name; /* module name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int m_version; /* module version */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *m_args; /* arguments for the module */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct preloaded_file *m_fp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct kernel_module *m_next;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Preloaded file information. Depending on type, file can contain
199767f8919635c4928607450d9e0abb932109ceToomas Soome * additional units called 'modules'.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * At least one file (the kernel) must be loaded in order to boot.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The kernel is always loaded first.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * String fields (m_name, m_type) should be dynamically allocated.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct preloaded_file
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *f_name; /* file name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *f_type; /* verbose file type, eg 'ELF kernel', 'pnptable', etc. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *f_args; /* arguments for the file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct file_metadata *f_metadata; /* metadata that will be placed in the module directory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int f_loader; /* index of the loader that read the file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vm_offset_t f_addr; /* load address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t f_size; /* file size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct kernel_module *f_modules; /* list of modules if any */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct preloaded_file *f_next; /* next file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct file_format
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Load function must return EFTYPE if it can't handle the module supplied */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (* l_load)(char *filename, u_int64_t dest, struct preloaded_file **result);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Only a loader that will load a kernel (first module) should have an exec handler */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (* l_exec)(struct preloaded_file *mp);
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern struct file_format *file_formats[]; /* supplied by consumer */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern struct preloaded_file *preloaded_files;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint mod_load(char *name, struct mod_depend *verinfo, int argc, char *argv[]);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint mod_loadkld(const char *name, int argc, char *argv[]);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid unload(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct preloaded_file *file_alloc(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct preloaded_file *file_findfile(const char *name, const char *type);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct file_metadata *file_findmetadata(struct preloaded_file *fp, int type);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct preloaded_file *file_loadraw(const char *name, char *type, int argc,
199767f8919635c4928607450d9e0abb932109ceToomas Soome char **argv, int insert);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid file_discard(struct preloaded_file *fp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint file_addmodule(struct preloaded_file *fp, char *modname, int version,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct kernel_module **newmp);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* MI module loaders */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef __elfN
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Relocation types. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ELF_RELOC_REL 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ELF_RELOC_RELA 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Relocation offset for some architectures */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern u_int64_t __elfN(relocation_offset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct elf_file;
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef Elf_Addr (symaddr_fn)(struct elf_file *ef, Elf_Size symidx);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint __elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint __elfN(obj_loadfile)(char *filename, u_int64_t dest,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct preloaded_file **result);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr,
199767f8919635c4928607450d9e0abb932109ceToomas Soome const void *reldata, int reltype, Elf_Addr relbase,
199767f8919635c4928607450d9e0abb932109ceToomas Soome Elf_Addr dataaddr, void *data, size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint __elfN(loadfile_raw)(char *filename, u_int64_t dest,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct preloaded_file **result, int multiboot);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint __elfN(load_modmetadata)(struct preloaded_file *fp, u_int64_t dest);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Support for commands
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct bootblk_command
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *c_name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *c_desc;
199767f8919635c4928607450d9e0abb932109ceToomas Soome bootblk_cmd_t *c_fn;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define COMMAND_SET(tag, key, desc, func) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome static bootblk_cmd_t func; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct bootblk_command _cmd_ ## tag = { key, desc, func }; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_SET(Xcommand_set, _cmd_ ## tag)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeSET_DECLARE(Xcommand_set, struct bootblk_command);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The intention of the architecture switch is to provide a convenient
199767f8919635c4928607450d9e0abb932109ceToomas Soome * encapsulation of the interface between the bootstrap MI and MD code.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * MD code may selectively populate the switch at runtime based on the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * actual configuration of the target system.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct arch_switch
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Automatically load modules as required by detected hardware */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*arch_autoload)(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Locate the device for (name), return pointer to tail in (*path) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*arch_getdev)(void **dev, const char *name, const char **path);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Copy from local address space to module address space, similar to bcopy() */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ssize_t (*arch_copyin)(const void *src, vm_offset_t dest,
199767f8919635c4928607450d9e0abb932109ceToomas Soome const size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Copy to local address space from module address space, similar to bcopy() */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ssize_t (*arch_copyout)(const vm_offset_t src, void *dest,
199767f8919635c4928607450d9e0abb932109ceToomas Soome const size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Read from file to module address space, same semantics as read() */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ssize_t (*arch_readin)(const int fd, vm_offset_t dest,
199767f8919635c4928607450d9e0abb932109ceToomas Soome const size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Perform ISA byte port I/O (only for systems with ISA) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int (*arch_isainb)(int port);
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*arch_isaoutb)(int port, int value);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Interface to adjust the load address according to the "object"
199767f8919635c4928607450d9e0abb932109ceToomas Soome * being loaded.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t (*arch_loadaddr)(u_int type, void *data, uint64_t addr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LOAD_ELF 1 /* data points to the ELF header. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LOAD_RAW 2 /* data points to the file name. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Interface to inform MD code about a loaded (ELF) segment. This
199767f8919635c4928607450d9e0abb932109ceToomas Soome * can be used to flush caches and/or set up translations.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef __elfN
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*arch_loadseg)(Elf_Ehdr *eh, Elf_Phdr *ph, uint64_t delta);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*arch_loadseg)(void *eh, void *ph, uint64_t delta);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Probe ZFS pool(s), if needed. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*arch_zfs_probe)(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern struct arch_switch archsw;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* This must be provided by the MD code, but should it be in the archsw? */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid delay(int delay);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid dev_cleanup(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef CTASSERT /* Allow lint to override */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CTASSERT(x) _CTASSERT(x, __LINE__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _CTASSERT(x, y) __CTASSERT(x, y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_BOOTSTRAP_H_ */