Home | History | Annotate | Line # | Download | only in loadbsd
loadbsd.c revision 1.7.16.1
      1       1.1     itohy /*
      2       1.1     itohy  *	Load and boot NetBSD kernel on Human68k
      3       1.1     itohy  *
      4       1.1     itohy  *	written by Yasha (ITOH Yasufumi)
      5       1.1     itohy  *	public domain
      6       1.1     itohy  *
      7       1.1     itohy  *	loadbsd [-hvV] [-abDs] [-r root_device] netbsd
      8       1.1     itohy  *
      9       1.1     itohy  *	loadbsd options:
     10       1.1     itohy  *		-h	help
     11       1.1     itohy  *		-V	print version and exit
     12       1.1     itohy  *
     13       1.1     itohy  *	kernel options:
     14       1.1     itohy  *		-a	auto boot, opposite of -s
     15       1.1     itohy  *		-s	single user boot (default)
     16       1.1     itohy  *		-D	enter kernel debugger
     17       1.1     itohy  *		-b	ask root device
     18       1.1     itohy  *		-r	specify root device
     19       1.6  jdolecek  *		-q	quiet boot
     20       1.6  jdolecek  *		-v	verbose boot (also turn on verbosity of loadbsd)
     21       1.1     itohy  *
     22  1.7.16.1   gehenna  *	$NetBSD: loadbsd.c,v 1.7.16.1 2002/05/30 15:36:42 gehenna Exp $
     23       1.1     itohy  */
     24       1.1     itohy 
     25       1.1     itohy #include <sys/cdefs.h>
     26       1.1     itohy 
     27  1.7.16.1   gehenna __RCSID("$NetBSD: loadbsd.c,v 1.7.16.1 2002/05/30 15:36:42 gehenna Exp $");
     28  1.7.16.1   gehenna #define VERSION	"$Revision: 1.7.16.1 $ $Date: 2002/05/30 15:36:42 $"
     29       1.1     itohy 
     30       1.1     itohy #include <sys/types.h>		/* ntohl */
     31       1.1     itohy #include <sys/reboot.h>
     32       1.1     itohy #include <sys/param.h>		/* ALIGN, ALIGNBYTES */
     33       1.1     itohy #include <a.out.h>
     34  1.7.16.1   gehenna #include <sys/exec_elf.h>
     35       1.1     itohy #include <string.h>
     36       1.1     itohy #include <machine/bootinfo.h>
     37       1.1     itohy 
     38       1.1     itohy #include <dos.h>
     39       1.1     itohy #include <iocs.h>
     40       1.1     itohy #include "../common/xprintf.h"
     41       1.1     itohy #include "trampoline.h"
     42       1.1     itohy 
     43       1.1     itohy #define DEFAULT_ROOTDEVNAME	"sd@0,0:a"
     44       1.1     itohy 
     45       1.1     itohy #define ISDIGIT(c)	((c) >= '0' && (c) <= '9')
     46       1.1     itohy 
     47       1.1     itohy #define GETDECIMAL(var, str)	\
     48       1.1     itohy 	do {	var *= 10; var += *str++ - '0'; } while (ISDIGIT(*str))
     49       1.1     itohy 
     50       1.1     itohy static const char *lookupif __P((const char *name,
     51       1.1     itohy 				 unsigned *pif, unsigned *punit));
     52       1.1     itohy static void get_current_scsi_interface __P((unsigned *pif, unsigned *punit));
     53       1.1     itohy static int bootdev __P((const char *devstr));
     54       1.1     itohy static struct tramparg *read_kernel __P((const char *fn));
     55       1.1     itohy static int chkmpu __P((void));
     56       1.1     itohy static __dead void usage __P((int status, const char *msg))
     57       1.1     itohy 					__attribute__((noreturn));
     58       1.1     itohy 
     59       1.1     itohy int main __P((int argc, char *argv[]));
     60       1.1     itohy 
     61       1.1     itohy int opt_v;
     62       1.1     itohy int opt_N;
     63  1.7.16.1   gehenna const char *kernel_fn;
     64       1.1     itohy 
     65       1.1     itohy const struct hatbl {
     66       1.1     itohy 	char name[4];
     67       1.1     itohy 	unsigned short id;
     68       1.1     itohy } hatable[] = {
     69       1.1     itohy 	X68K_BOOT_SCSIIF_LIST
     70       1.1     itohy };
     71       1.1     itohy 
     72       1.1     itohy /*
     73       1.1     itohy  * parse interface name
     74       1.3     itohy  * return the next position
     75       1.1     itohy  */
     76       1.1     itohy static const char *
     77       1.1     itohy lookupif(name, pif, punit)
     78       1.1     itohy 	const char *name;
     79       1.1     itohy 	unsigned *pif, *punit;
     80       1.1     itohy {
     81       1.1     itohy 	unsigned u, unit;
     82       1.1     itohy 	const char *p;
     83       1.1     itohy 
     84       1.1     itohy 	for (u = 0; u < sizeof hatable / sizeof hatable[0]; u++) {
     85       1.1     itohy 		const char *n;
     86       1.1     itohy 
     87       1.1     itohy 		for (n = hatable[u].name, p = name; *n && *n == *p; n++, p++)
     88       1.1     itohy 			;
     89       1.1     itohy 		if (!*n)
     90       1.1     itohy 			goto found;
     91       1.1     itohy 	}
     92       1.1     itohy 	/* not found */
     93       1.1     itohy 	return (char *) 0;
     94       1.1     itohy 
     95       1.1     itohy found:
     96       1.1     itohy 	if (*p == '@')
     97       1.1     itohy 		p++;
     98       1.1     itohy 
     99       1.1     itohy 	/* get unit # */
    100       1.1     itohy 	if (!ISDIGIT(*p))
    101       1.1     itohy 		return (char *) 0;
    102       1.1     itohy 
    103       1.1     itohy 	unit = 0;
    104       1.1     itohy 	GETDECIMAL(unit, p);
    105       1.1     itohy 
    106       1.1     itohy 	*pif = hatable[u].id;
    107       1.1     itohy 	*punit = unit;
    108       1.1     itohy 
    109       1.1     itohy 	return p;
    110       1.1     itohy }
    111       1.1     itohy 
    112       1.1     itohy /*
    113       1.1     itohy  * if the SCSI interface is not specified, use the current one
    114       1.1     itohy  */
    115       1.1     itohy static void
    116       1.1     itohy get_current_scsi_interface(pif, punit)
    117       1.1     itohy 	unsigned *pif, *punit;
    118       1.1     itohy {
    119       1.1     itohy 	unsigned binf;
    120       1.1     itohy 	char *bootrom;
    121       1.1     itohy 	int bus_err_buf;
    122       1.1     itohy 
    123       1.1     itohy 	binf = (unsigned) IOCS_BOOTINF();
    124       1.1     itohy 	if (binf < 0x00fc0000)
    125       1.1     itohy 		return;			/* not booted from SCSI */
    126       1.1     itohy 
    127       1.1     itohy 	bootrom = (char *) (binf & 0x00ffffe0);
    128       1.1     itohy 	if (IOCS_B_LPEEK(bootrom + 0x24) == 0x53435349 &&	/* 'SCSI' */
    129       1.1     itohy 	    IOCS_B_WPEEK(bootrom + 0x28) == 0x494E) {		/* 'IN' */
    130       1.1     itohy 		/* spc0 */
    131       1.1     itohy 		*pif = X68K_BOOT_SCSIIF_SPC;
    132       1.1     itohy 		*punit = 0;
    133       1.1     itohy 	} else if (DOS_BUS_ERR(&bus_err_buf, (void *)EXSPC_BDID, 1)) {
    134       1.1     itohy 		/* mha0 */
    135       1.1     itohy 		*pif = X68K_BOOT_SCSIIF_MHA;
    136       1.1     itohy 		*punit = 0;
    137       1.1     itohy 	} else {
    138       1.1     itohy 		/* spc1 */
    139       1.1     itohy 		*pif = X68K_BOOT_SCSIIF_SPC;
    140       1.1     itohy 		*punit = 1;
    141       1.1     itohy 	}
    142       1.1     itohy }
    143       1.1     itohy 
    144       1.1     itohy /*
    145       1.1     itohy  * parse device name
    146       1.1     itohy  *
    147       1.1     itohy  * [/<controller>@<unit>/]<device>@<unit>[,<lun>][:<partition>]
    148       1.1     itohy  *
    149       1.1     itohy  * <unit> must be target SCSI ID if <device> is a SCSI device
    150       1.1     itohy  *
    151       1.1     itohy  *	full form:
    152       1.1     itohy  *		/spc@0/sd@1,2:e
    153       1.1     itohy  *
    154       1.1     itohy  *	partial form:
    155       1.3     itohy  *		/mha@0/sd@1	= /mha@0/sd@1,0:a
    156       1.1     itohy  *		sd@1:e		= /current_device/sd@1,0e
    157       1.1     itohy  *		sd@1,2:e	= /current_device/sd@1,2:e
    158       1.1     itohy  */
    159       1.1     itohy 
    160       1.1     itohy const struct devtbl {
    161       1.1     itohy 	char name[3];
    162       1.1     itohy 	u_char major;
    163       1.1     itohy } devtable[] = {
    164       1.4   minoura 	X68K_BOOT_DEV_LIST,
    165       1.4   minoura 	X68K_BOOT_NETIF_LIST
    166       1.1     itohy };
    167       1.1     itohy 
    168       1.1     itohy static int
    169       1.1     itohy bootdev(devstr)
    170       1.1     itohy 	const char *devstr;
    171       1.1     itohy {
    172       1.1     itohy 	unsigned u;
    173       1.1     itohy 	unsigned major, unit, lun, partition;
    174       1.1     itohy 	int dev;
    175       1.1     itohy 	const char *s = devstr;
    176       1.1     itohy 	unsigned interface = 0, unit_if = 0;
    177       1.1     itohy 
    178       1.1     itohy 	if (*s == '/') {
    179       1.1     itohy 		/*
    180       1.1     itohy 		 * /<interface>/<device>"
    181       1.1     itohy 		 * "/spc@1/sd@2,3:e"
    182       1.1     itohy 		 */
    183       1.1     itohy 		while (*++s == '/')	/* skip slashes */
    184       1.1     itohy 			;
    185       1.1     itohy 		if (!strchr(s, '/'))
    186       1.1     itohy 			xerrx(1, "%s: bad format", devstr);
    187       1.1     itohy 
    188       1.1     itohy 		if (!(s = lookupif(s, &interface, &unit_if)))
    189       1.1     itohy 			xerrx(1, "%s: unknown interface", devstr);
    190       1.1     itohy 
    191       1.1     itohy 		while (*s == '/')	/* skip slashes */
    192       1.1     itohy 			s++;
    193       1.1     itohy 	} else {
    194       1.1     itohy 		/* make lint happy */
    195       1.1     itohy 		interface = 0;
    196       1.1     itohy 		unit_if = 0;
    197       1.1     itohy 	}
    198       1.1     itohy 
    199       1.1     itohy 	/* allow r at the top */
    200       1.1     itohy 	if (*s == 'r')
    201       1.1     itohy 		s++;
    202       1.1     itohy 
    203       1.1     itohy 	for (u = 0; u < sizeof devtable / sizeof devtable[0]; u++)
    204       1.1     itohy 		if (s[0] == devtable[u].name[0] && s[1] == devtable[u].name[1])
    205       1.1     itohy 			goto found;
    206       1.1     itohy 
    207       1.1     itohy 	/* not found */
    208       1.1     itohy 	xerrx(1, "%s: unknown device", devstr);
    209       1.1     itohy 
    210       1.1     itohy found:	major = devtable[u].major;
    211       1.1     itohy 
    212       1.1     itohy 	/*
    213       1.1     itohy 	 * <type>@unit[,lun][:part]
    214       1.1     itohy 	 * "sd@1,3:a"
    215       1.1     itohy 	 */
    216       1.1     itohy 
    217       1.1     itohy 	/* get device unit # */
    218       1.1     itohy 	s += 2;
    219       1.1     itohy 	if (*s == '@')
    220       1.1     itohy 		s++;
    221       1.1     itohy 	if (!*s)
    222       1.1     itohy 		xerrx(1, "%s: missing unit number", devstr);
    223       1.1     itohy 	if (!ISDIGIT(*s))
    224       1.1     itohy 		xerrx(1, "%s: wrong device", devstr);
    225       1.1     itohy 
    226       1.1     itohy 	unit = 0;
    227       1.1     itohy 	GETDECIMAL(unit, s);
    228       1.1     itohy 
    229       1.1     itohy 	lun = 0;
    230       1.1     itohy 	if (*s == ',') {
    231       1.1     itohy 		s++;
    232       1.1     itohy 		if (!ISDIGIT(*s))
    233       1.1     itohy 			xerrx(1, "%s: wrong device", devstr);
    234       1.1     itohy 		GETDECIMAL(lun, s);
    235       1.1     itohy 	}
    236       1.1     itohy 
    237       1.1     itohy 	/* get device partition */
    238       1.1     itohy 	if (*s == ':')
    239       1.1     itohy 		s++;
    240       1.1     itohy 	if (!*s)
    241       1.1     itohy 		partition = 0;	/* no partition letter -- assuming 'a' */
    242       1.1     itohy 	else if (!s[1])
    243       1.1     itohy 		partition = *s - 'a';
    244       1.1     itohy 	else
    245       1.1     itohy 		xerrx(1, "%s: wrong partition letter", devstr);
    246       1.1     itohy 
    247       1.1     itohy 	/*
    248       1.1     itohy 	 * sanity check
    249       1.1     itohy 	 */
    250       1.1     itohy 	if (unit_if >= 16)
    251       1.1     itohy 		xerrx(1, "%s: interface unit # too large", devstr);
    252       1.1     itohy 	if (unit >= 16)
    253       1.1     itohy 		xerrx(1, "%s: device unit # too large", devstr);
    254       1.1     itohy 	if (lun >= 8)
    255       1.1     itohy 		xerrx(1, "%s: SCSI LUN >= 8 is not supported yet", devstr);
    256       1.1     itohy 	if (partition >= 16)
    257       1.1     itohy 		xerrx(1, "%s: unsupported partition", devstr);
    258       1.1     itohy 
    259       1.1     itohy 	/*
    260       1.1     itohy 	 * encode device to be passed to kernel
    261       1.1     itohy 	 */
    262       1.1     itohy 	if (X68K_BOOT_DEV_IS_SCSI(major)) {
    263       1.1     itohy 		/*
    264       1.1     itohy 		 * encode SCSI device
    265       1.1     itohy 		 */
    266       1.1     itohy 		if (interface == 0)
    267       1.1     itohy 			get_current_scsi_interface(&interface, &unit_if);
    268       1.1     itohy 
    269       1.1     itohy 		dev = X68K_MAKESCSIBOOTDEV(major, interface, unit_if,
    270       1.1     itohy 						unit, lun, partition);
    271       1.1     itohy 	} else {
    272       1.1     itohy 		/* encode non-SCSI device */
    273       1.1     itohy 		dev = X68K_MAKEBOOTDEV(major, unit, partition);
    274       1.1     itohy 	}
    275       1.1     itohy 
    276       1.1     itohy 	if (opt_v)
    277       1.1     itohy 		xwarnx("%s: major %u, if %u, un_if %u, unit %u, lun %u, partition %u; bootdev 0x%x",
    278       1.1     itohy 			devstr, major, interface, unit_if, unit, lun, partition, dev);
    279       1.1     itohy 
    280       1.1     itohy 	return dev;
    281       1.1     itohy }
    282       1.1     itohy 
    283  1.7.16.1   gehenna #define LOADBSD
    284  1.7.16.1   gehenna #include "../common/exec_sub.c"
    285  1.7.16.1   gehenna 
    286       1.1     itohy /*
    287       1.1     itohy  * read kernel and create trampoline
    288       1.1     itohy  *
    289       1.1     itohy  *	|----------------------| <- allocated buf addr
    290       1.1     itohy  *	| kernel image         |
    291  1.7.16.1   gehenna  *	~ (exec file contents) ~
    292       1.1     itohy  *	|                      |
    293       1.1     itohy  *	|----------------------| <- return value (entry addr of trampoline)
    294       1.1     itohy  *	| struct tramparg      |
    295       1.1     itohy  *	| (trampoline args)    |
    296       1.1     itohy  *	|----------------------|
    297       1.1     itohy  *	| trampoline code      |
    298       1.1     itohy  *	| (in assembly)        |
    299       1.1     itohy  *	|----------------------|
    300       1.1     itohy  */
    301       1.1     itohy static struct tramparg *
    302       1.1     itohy read_kernel(fn)
    303       1.1     itohy 	const char *fn;
    304       1.1     itohy {
    305       1.1     itohy 	int fd;
    306       1.1     itohy 	union dos_fcb *fcb;
    307       1.1     itohy 	size_t filesize, nread;
    308       1.1     itohy 	void *buf;
    309       1.1     itohy 	struct tramparg *arg;
    310       1.1     itohy 	size_t size_tramp = end_trampoline - trampoline;
    311       1.1     itohy 
    312  1.7.16.1   gehenna 	kernel_fn = fn;
    313  1.7.16.1   gehenna 
    314  1.7.16.1   gehenna 	if ((fd = DOS_OPEN(fn, 0x00)) < 0)	/* read only */
    315       1.1     itohy 		xerr(1, "%s: open", fn);
    316       1.1     itohy 
    317       1.1     itohy 	if ((int)(fcb = DOS_GET_FCB_ADR(fd)) < 0)
    318       1.1     itohy 		xerr(1, "%s: get_fcb_adr", fn);
    319       1.1     itohy 
    320       1.1     itohy 	/*
    321       1.1     itohy 	 * XXX FCB is in supervisor area
    322       1.1     itohy 	 */
    323       1.1     itohy 	/*if (fcb->blk.mode != 0)*/
    324       1.1     itohy 	if (IOCS_B_BPEEK((char *)fcb + 1) & 0x80)
    325       1.1     itohy 		xerrx(1, "%s: Not a regular file", fn);
    326       1.1     itohy 
    327       1.1     itohy 	/*filesize = fcb->blk.size;*/
    328       1.1     itohy 	filesize = IOCS_B_LPEEK(&fcb->blk.size);
    329       1.1     itohy 
    330  1.7.16.1   gehenna 	if (filesize < sizeof(Elf32_Ehdr))
    331  1.7.16.1   gehenna 		xerrx(1, "%s: Unknown format", fn);
    332       1.1     itohy 
    333       1.1     itohy 	/*
    334  1.7.16.1   gehenna 	 * read entire file
    335       1.1     itohy 	 */
    336  1.7.16.1   gehenna 	if ((int)(buf = DOS_MALLOC(filesize + ALIGNBYTES
    337       1.1     itohy 				   + sizeof(struct tramparg)
    338       1.1     itohy 				   + size_tramp + SIZE_TMPSTACK)) < 0)
    339       1.1     itohy 		xerr(1, "read_kernel");
    340       1.1     itohy 
    341  1.7.16.1   gehenna 	if ((nread = DOS_READ(fd, buf, filesize)) != filesize) {
    342       1.1     itohy 		if ((int)nread < 0)
    343       1.1     itohy 			xerr(1, "%s: read", fn);
    344       1.1     itohy 		else
    345       1.1     itohy 			xerrx(1, "%s: short read", fn);
    346       1.1     itohy 	}
    347       1.1     itohy 
    348       1.1     itohy 	if (DOS_CLOSE(fd) < 0)
    349       1.1     itohy 		xerr(1, "%s: close", fn);
    350       1.1     itohy 
    351       1.1     itohy 	/*
    352  1.7.16.1   gehenna 	 * address for argument for trampoline code
    353       1.1     itohy 	 */
    354  1.7.16.1   gehenna 	arg = (struct tramparg *) ALIGN((char *) buf + nread);
    355       1.1     itohy 
    356       1.1     itohy 	if (opt_v)
    357       1.1     itohy 		xwarnx("trampoline arg at %p", arg);
    358       1.1     itohy 
    359  1.7.16.1   gehenna 	xk_load(&arg->xk, buf, 0 /* XXX load addr should not be fixed */);
    360  1.7.16.1   gehenna 
    361  1.7.16.1   gehenna 	/*
    362  1.7.16.1   gehenna 	 * create argument for trampoline code
    363  1.7.16.1   gehenna 	 */
    364       1.2   minoura 	arg->bsr_inst = TRAMP_BSR + sizeof(struct tramparg) - 2;
    365       1.1     itohy 	arg->tmp_stack = (char *) arg + sizeof(struct tramparg)
    366       1.1     itohy 				+ size_tramp + SIZE_TMPSTACK;
    367       1.1     itohy 	arg->mpu_type = IOCS_MPU_STAT() & 0xff;
    368  1.7.16.1   gehenna 
    369       1.1     itohy 	arg->xk.d5 = IOCS_BOOTINF();	/* unused for now */
    370       1.1     itohy #if 0
    371       1.1     itohy 	/* filled afterwards */
    372       1.1     itohy 	arg->xk.rootdev =
    373       1.1     itohy 	arg->xk.boothowto =
    374       1.1     itohy #endif
    375       1.1     itohy 
    376       1.1     itohy 	if (opt_v)
    377       1.1     itohy 		xwarnx("args: mpu %d, image %p, load 0x%x, entry 0x%x",
    378  1.7.16.1   gehenna 			arg->mpu_type, arg->xk.sec[0].sec_image,
    379  1.7.16.1   gehenna 			arg->xk.load_addr, arg->xk.entry_addr);
    380       1.1     itohy 
    381       1.1     itohy 	/*
    382       1.1     itohy 	 * copy trampoline code
    383       1.1     itohy 	 */
    384       1.1     itohy 	if (opt_v)
    385       1.1     itohy 		xwarnx("trampoline code at %p (%u bytes)",
    386       1.1     itohy 			(char *) arg + sizeof(struct tramparg), size_tramp);
    387       1.1     itohy 
    388       1.1     itohy 	memcpy((char *) arg + sizeof(struct tramparg), trampoline, size_tramp);
    389       1.1     itohy 
    390       1.1     itohy 	return arg;
    391       1.1     itohy }
    392       1.1     itohy 
    393       1.1     itohy /*
    394       1.1     itohy  * MC68000/010		-> return zero
    395       1.1     itohy  * MC68020 and later	-> return nonzero
    396       1.1     itohy  */
    397       1.1     itohy static int
    398       1.1     itohy chkmpu()
    399       1.1     itohy {
    400       1.7   minoura 	register int ret asm("%d0");
    401       1.1     itohy 
    402       1.7   minoura 	asm("| %0 <- this must be %%d0\n\
    403       1.7   minoura 	moveq	#1,%%d0\n\
    404       1.7   minoura 	.long	0x103B02FF	| foo: moveb %%pc@((foo+1)-foo-2:B,d0:W:2),%%d0\n\
    405       1.1     itohy 	|	      ^ ^\n\
    406       1.7   minoura 	| %%d0.b	= 0x02	(68000/010)\n\
    407       1.1     itohy 	|	= 0xff	(68020 and later)\n\
    408       1.1     itohy 	bmis	1f\n\
    409       1.7   minoura 	moveq	#0,%%d0		| 68000/010\n\
    410       1.1     itohy 1:"	: "=d" (ret));
    411       1.1     itohy 
    412       1.1     itohy 	return ret;
    413       1.1     itohy }
    414       1.1     itohy 
    415       1.1     itohy static __dead void
    416       1.1     itohy usage(status, msg)
    417       1.1     itohy 	int status;
    418       1.1     itohy 	const char *msg;
    419       1.1     itohy {
    420       1.1     itohy 	extern const char *const __progname;
    421       1.1     itohy 
    422       1.1     itohy 	if (msg)
    423       1.1     itohy 		xwarnx("%s", msg);
    424       1.1     itohy 
    425       1.1     itohy 	xerrprintf("\
    426       1.1     itohy %s [-hvV] [-abDs] [-r root_device] netbsd\n\
    427       1.1     itohy \n\
    428       1.1     itohy loadbsd options:\n\
    429       1.1     itohy \t-h	help\n\
    430       1.1     itohy \t-v	verbose\n\
    431       1.1     itohy \t-V	print version and exit\n\
    432       1.1     itohy \n\
    433       1.1     itohy kernel options:\n\
    434       1.1     itohy \t-a	auto boot, opposite of -s\n\
    435       1.1     itohy \t-s	single user boot (default)\n\
    436       1.1     itohy \t-D	enter kernel debugger\n\
    437       1.1     itohy \t-b	ask root device\n\
    438       1.1     itohy \t-r	specify root device (default %s)\n\
    439       1.1     itohy \t	format:  [/interface/]device@unit[,lun][:partition]\n\
    440       1.1     itohy \t	    interface: one of  spc@0, spc@1, mha@0\n\
    441       1.1     itohy \t		       (current boot interface if omitted)\n\
    442       1.4   minoura \t	    device:    one of  fd, sd, cd, md, ne\n\
    443       1.1     itohy \t	    unit:      device unit number (SCSI ID for SCSI device)\n\
    444       1.1     itohy \t	    lun:       SCSI LUN # (0 if omitted)\n\
    445       1.1     itohy \t	    partition: partition letter ('a' if omitted)\n\
    446       1.1     itohy ", __progname, DEFAULT_ROOTDEVNAME);
    447       1.1     itohy 
    448       1.1     itohy 	DOS_EXIT2(status);
    449       1.1     itohy }
    450       1.1     itohy 
    451       1.1     itohy int
    452       1.1     itohy main(argc, argv)
    453       1.1     itohy 	int argc;
    454       1.1     itohy 	char *argv[];
    455       1.1     itohy {
    456       1.1     itohy 	char *rootdevname = 0;
    457       1.1     itohy 	int rootdev;
    458       1.1     itohy 	u_long boothowto = RB_SINGLE;
    459       1.1     itohy 	const char *kernel;
    460       1.1     itohy 	char *p, **flg, **arg;
    461       1.1     itohy 	struct tramparg *tramp;
    462       1.1     itohy 	struct dos_dregs regs;	/* unused... */
    463       1.1     itohy 	int i;
    464       1.1     itohy 
    465       1.1     itohy 	/* parse options */
    466       1.1     itohy 	for (arg = flg = argv + 1; (p = *flg) && *p == '-'; ) {
    467       1.1     itohy 		int c;
    468       1.1     itohy 
    469       1.1     itohy 		while ((c = *++p))
    470       1.1     itohy 			switch (c) {
    471       1.1     itohy 			case 'h':
    472       1.1     itohy 				usage(0, (char *) 0);
    473       1.1     itohy 				/* NOTREACHED */
    474       1.1     itohy 				break;
    475       1.1     itohy 			case 'N':	/* don't actually execute kernel */
    476       1.1     itohy 				opt_N = 1;
    477       1.1     itohy 				break;
    478       1.1     itohy 			case 'v':
    479       1.1     itohy 				opt_v = 1;
    480       1.6  jdolecek 				boothowto |= AB_VERBOSE; /* XXX */
    481       1.1     itohy 				break;
    482       1.1     itohy 			case 'V':
    483       1.1     itohy 				xprintf("loadbsd %s\n", VERSION);
    484       1.1     itohy 				return 0;
    485       1.1     itohy 
    486       1.1     itohy 			/*
    487       1.1     itohy 			 * kernel boot flags
    488       1.1     itohy 			 */
    489       1.1     itohy 			case 'r':
    490       1.1     itohy 				if (rootdevname)
    491       1.1     itohy 					usage(1, "multiple -r flags");
    492       1.1     itohy 				else if (!*++arg)
    493       1.1     itohy 					usage(1, "-r requires device name");
    494       1.1     itohy 				else
    495       1.1     itohy 					rootdevname = *arg;
    496       1.1     itohy 				break;
    497       1.1     itohy 			case 'b':
    498       1.1     itohy 				boothowto |= RB_ASKNAME;
    499       1.1     itohy 				break;
    500       1.1     itohy 			case 'a':
    501       1.1     itohy 				boothowto &= ~RB_SINGLE;
    502       1.1     itohy 				break;
    503       1.1     itohy 			case 's':
    504       1.1     itohy 				boothowto |= RB_SINGLE;
    505       1.1     itohy 				break;
    506       1.1     itohy 			case 'D':
    507       1.1     itohy 				boothowto |= RB_KDB;
    508       1.6  jdolecek 				break;
    509       1.6  jdolecek 			case 'q':
    510       1.6  jdolecek 				boothowto |= AB_QUIET;
    511       1.1     itohy 				break;
    512       1.1     itohy 
    513       1.1     itohy 			default:
    514       1.1     itohy 				usage(1, (char *) 0);
    515       1.1     itohy 				/* NOTREACHED */
    516       1.1     itohy 				break;
    517       1.1     itohy 			}
    518       1.1     itohy 		flg = ++arg;
    519       1.1     itohy 	}
    520       1.1     itohy 
    521       1.1     itohy 	/* check MPU */
    522       1.1     itohy 	if (chkmpu() == 0)
    523       1.1     itohy 		xerrx(1, "Can't boot NetBSD on 68000/010");
    524       1.1     itohy 
    525       1.1     itohy 	argc -= arg - argv;
    526       1.1     itohy 	argv = arg;
    527       1.1     itohy 
    528       1.1     itohy 	if (argc != 1)
    529       1.1     itohy 		usage(1, (char *) 0);
    530       1.1     itohy 
    531       1.1     itohy 	kernel = *argv;
    532       1.1     itohy 
    533       1.1     itohy 	rootdev = bootdev(rootdevname ? rootdevname : DEFAULT_ROOTDEVNAME);
    534       1.1     itohy 
    535       1.1     itohy 	if (opt_v)
    536       1.1     itohy 		xwarnx("boothowto 0x%x", boothowto);
    537       1.1     itohy 
    538       1.1     itohy 	tramp = read_kernel(kernel);
    539       1.1     itohy 
    540       1.1     itohy 	tramp->xk.rootdev = rootdev;
    541       1.1     itohy 	tramp->xk.boothowto = boothowto;
    542       1.1     itohy 
    543       1.1     itohy 	/*
    544       1.3     itohy 	 * we never return, and make sure the disk cache
    545       1.1     itohy 	 * be flushed (if write-back cache is enabled)
    546       1.1     itohy 	 */
    547       1.1     itohy 	if (opt_v)
    548       1.1     itohy 		xwarnx("flush disk cache...");
    549       1.1     itohy 
    550       1.1     itohy 	i = DOS_FFLUSH_SET(1);		/* enable fflush */
    551       1.1     itohy 	DOS_FFLUSH();			/* then, issue fflush */
    552       1.1     itohy 	(void) DOS_FFLUSH_SET(i);	/* restore old mode just in case */
    553       1.1     itohy 
    554       1.1     itohy 	/*
    555       1.1     itohy 	 * the program assumes the MPU caches off
    556       1.1     itohy 	 */
    557       1.1     itohy 	if (opt_v)
    558       1.1     itohy 		xwarnx("flush and disable MPU caches...");
    559       1.1     itohy 
    560       1.1     itohy 	IOCS_CACHE_MD(-1);		/* flush */
    561       1.1     itohy 	if (!opt_N)
    562       1.1     itohy 		IOCS_CACHE_MD(0);	/* disable both caches */
    563       1.1     itohy 
    564       1.1     itohy 	if (opt_v)
    565       1.1     itohy 		xwarnx("Jumping to the kernel.  Good Luck!");
    566       1.1     itohy 
    567       1.1     itohy 	if (opt_N)
    568       1.1     itohy 		xerrx(0, "But don't actually do it.");
    569       1.1     itohy 
    570       1.1     itohy 	DOS_SUPER_JSR((void (*) __P((void))) tramp, &regs, &regs);
    571       1.1     itohy 
    572       1.1     itohy 	/* NOTREACHED */
    573       1.1     itohy 
    574       1.1     itohy 	xwarnx("??? return from kernel");
    575       1.1     itohy 
    576       1.1     itohy 	return 1;
    577       1.1     itohy }
    578