Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.2.2.3
      1  1.2.2.3  yamt /*	$NetBSD: boot.c,v 1.2.2.3 2014/05/22 11:39:55 yamt Exp $	*/
      2  1.2.2.2  yamt 
      3  1.2.2.2  yamt /*
      4  1.2.2.2  yamt  * Copyright (c) 1992 OMRON Corporation.
      5  1.2.2.2  yamt  *
      6  1.2.2.2  yamt  * This code is derived from software contributed to Berkeley by
      7  1.2.2.2  yamt  * OMRON Corporation.
      8  1.2.2.2  yamt  *
      9  1.2.2.2  yamt  * Redistribution and use in source and binary forms, with or without
     10  1.2.2.2  yamt  * modification, are permitted provided that the following conditions
     11  1.2.2.2  yamt  * are met:
     12  1.2.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     13  1.2.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     14  1.2.2.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.2.2.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     16  1.2.2.2  yamt  *    documentation and/or other materials provided with the distribution.
     17  1.2.2.2  yamt  * 3. All advertising materials mentioning features or use of this software
     18  1.2.2.2  yamt  *    must display the following acknowledgement:
     19  1.2.2.2  yamt  *	This product includes software developed by the University of
     20  1.2.2.2  yamt  *	California, Berkeley and its contributors.
     21  1.2.2.2  yamt  * 4. Neither the name of the University nor the names of its contributors
     22  1.2.2.2  yamt  *    may be used to endorse or promote products derived from this software
     23  1.2.2.2  yamt  *    without specific prior written permission.
     24  1.2.2.2  yamt  *
     25  1.2.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.2.2.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.2.2.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.2.2.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.2.2.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.2.2.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.2.2.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.2.2.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.2.2.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.2.2.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.2.2.2  yamt  * SUCH DAMAGE.
     36  1.2.2.2  yamt  *
     37  1.2.2.2  yamt  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
     38  1.2.2.2  yamt  */
     39  1.2.2.2  yamt /*
     40  1.2.2.2  yamt  * Copyright (c) 1992, 1993
     41  1.2.2.2  yamt  *	The Regents of the University of California.  All rights reserved.
     42  1.2.2.2  yamt  *
     43  1.2.2.2  yamt  * This code is derived from software contributed to Berkeley by
     44  1.2.2.2  yamt  * OMRON Corporation.
     45  1.2.2.2  yamt  *
     46  1.2.2.2  yamt  * Redistribution and use in source and binary forms, with or without
     47  1.2.2.2  yamt  * modification, are permitted provided that the following conditions
     48  1.2.2.2  yamt  * are met:
     49  1.2.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     50  1.2.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     51  1.2.2.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.2.2.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     53  1.2.2.2  yamt  *    documentation and/or other materials provided with the distribution.
     54  1.2.2.2  yamt  * 3. Neither the name of the University nor the names of its contributors
     55  1.2.2.2  yamt  *    may be used to endorse or promote products derived from this software
     56  1.2.2.2  yamt  *    without specific prior written permission.
     57  1.2.2.2  yamt  *
     58  1.2.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  1.2.2.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  1.2.2.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  1.2.2.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  1.2.2.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  1.2.2.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  1.2.2.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  1.2.2.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  1.2.2.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  1.2.2.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  1.2.2.2  yamt  * SUCH DAMAGE.
     69  1.2.2.2  yamt  *
     70  1.2.2.2  yamt  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
     71  1.2.2.2  yamt  */
     72  1.2.2.2  yamt 
     73  1.2.2.2  yamt /*
     74  1.2.2.2  yamt  * boot.c -- boot program
     75  1.2.2.2  yamt  * by A.Fujita, MAR-01-1992
     76  1.2.2.2  yamt  */
     77  1.2.2.2  yamt 
     78  1.2.2.2  yamt #include <sys/param.h>
     79  1.2.2.3  yamt #include <sys/boot_flag.h>
     80  1.2.2.2  yamt #include <sys/reboot.h>
     81  1.2.2.2  yamt #include <sys/exec.h>
     82  1.2.2.2  yamt #include <luna68k/stand/boot/samachdep.h>
     83  1.2.2.2  yamt #include <luna68k/stand/boot/status.h>
     84  1.2.2.2  yamt #include <lib/libsa/loadfile.h>
     85  1.2.2.2  yamt 
     86  1.2.2.2  yamt int
     87  1.2.2.2  yamt boot(int argc, char *argv[])
     88  1.2.2.2  yamt {
     89  1.2.2.3  yamt 	char *line, *opts;
     90  1.2.2.3  yamt 	int i, howto;
     91  1.2.2.3  yamt 	char c;
     92  1.2.2.3  yamt 
     93  1.2.2.3  yamt 	line = NULL;
     94  1.2.2.3  yamt 	howto = 0;
     95  1.2.2.3  yamt 	for (i = 1; i < argc; i++) {
     96  1.2.2.3  yamt 		if (argv[i][0] == '-') {
     97  1.2.2.3  yamt 			opts = argv[i];
     98  1.2.2.3  yamt 			while ((c = *++opts) && c != '\0')
     99  1.2.2.3  yamt 				BOOT_FLAG(c, howto);
    100  1.2.2.3  yamt 		} else if (line == NULL)
    101  1.2.2.3  yamt 			line = argv[i];
    102  1.2.2.3  yamt 	}
    103  1.2.2.3  yamt 	if (line == NULL)
    104  1.2.2.2  yamt 		line = default_file;
    105  1.2.2.2  yamt 
    106  1.2.2.3  yamt 	printf("Booting %s", line);
    107  1.2.2.3  yamt 	if (howto != 0)
    108  1.2.2.3  yamt 		printf(" (howto 0x%x)", howto);
    109  1.2.2.3  yamt 	printf("\n");
    110  1.2.2.2  yamt 
    111  1.2.2.3  yamt 	return bootnetbsd(line, howto);
    112  1.2.2.2  yamt }
    113  1.2.2.2  yamt 
    114  1.2.2.2  yamt int
    115  1.2.2.3  yamt bootnetbsd(char *line, int howto)
    116  1.2.2.2  yamt {
    117  1.2.2.2  yamt 	int io;
    118  1.2.2.2  yamt 	u_long marks[MARK_MAX];
    119  1.2.2.2  yamt 
    120  1.2.2.2  yamt 	/* Note marks[MARK_START] is passed as an load address offset */
    121  1.2.2.2  yamt 	memset(marks, 0, sizeof(marks));
    122  1.2.2.2  yamt 
    123  1.2.2.2  yamt 	io = loadfile(line, marks, LOAD_KERNEL);
    124  1.2.2.2  yamt 	if (io >= 0) {
    125  1.2.2.3  yamt 		int dev = 0, unit = 0, part = 0;
    126  1.2.2.3  yamt 		uint adpt, ctlr, id;
    127  1.2.2.3  yamt 		uint32_t bootdev;
    128  1.2.2.3  yamt 
    129  1.2.2.3  yamt 		make_device(line, &dev, &unit, &part, NULL);
    130  1.2.2.3  yamt 		adpt = dev2adpt[dev];
    131  1.2.2.3  yamt 		ctlr = CTLR(unit);
    132  1.2.2.3  yamt 		id   = TARGET(unit);
    133  1.2.2.3  yamt 		bootdev = MAKEBOOTDEV(0, adpt, ctlr, id, part);
    134  1.2.2.2  yamt #ifdef DEBUG
    135  1.2.2.2  yamt 		printf("entry = 0x%lx\n", marks[MARK_ENTRY]);
    136  1.2.2.2  yamt 		printf("ssym  = 0x%lx\n", marks[MARK_SYM]);
    137  1.2.2.2  yamt 		printf("esym  = 0x%lx\n", marks[MARK_END]);
    138  1.2.2.2  yamt #endif
    139  1.2.2.3  yamt 		__asm volatile (
    140  1.2.2.3  yamt 			"movl	%0,%%d7;"
    141  1.2.2.3  yamt 			"movl	%1,%%d6;"
    142  1.2.2.3  yamt 			"movl	%2,%%a0;"
    143  1.2.2.3  yamt 			"jbsr	%%a0@"
    144  1.2.2.3  yamt 			:
    145  1.2.2.3  yamt 			: "g" (howto), "g" (bootdev),
    146  1.2.2.3  yamt 			  "g" ((void *)marks[MARK_ENTRY])
    147  1.2.2.3  yamt 			: "d6", "d7", "a0");
    148  1.2.2.2  yamt 	}
    149  1.2.2.2  yamt 	printf("Booting kernel failed. (%s)\n", strerror(errno));
    150  1.2.2.2  yamt 
    151  1.2.2.2  yamt 	return ST_ERROR;
    152  1.2.2.2  yamt }
    153