Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.14
      1 /*	$NetBSD: boot.c,v 1.14 2008/01/11 09:26:26 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (C) 1999 Izumi Tsutsui.  All rights reserved.
      5  * Copyright (C) 1999 Tsubai Masanari.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include <lib/libkern/libkern.h>
     31 #include <lib/libsa/stand.h>
     32 #include <lib/libsa/loadfile.h>
     33 
     34 #include <machine/romcall.h>
     35 
     36 void boot(uint32_t, uint32_t, uint32_t, uint32_t);
     37 extern void ICIA(void);
     38 
     39 /* version strings in vers.c (generated by newvers.sh) */
     40 extern const char bootprog_name[];
     41 extern const char bootprog_rev[];
     42 extern const char bootprog_date[];
     43 extern const char bootprog_maker[];
     44 
     45 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
     46 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
     47 
     48 #ifdef BOOT_DEBUG
     49 # define DPRINTF printf
     50 #else
     51 # define DPRINTF while (0) printf
     52 #endif
     53 
     54 void
     55 boot(uint32_t d4, uint32_t d5, uint32_t d6, uint32_t d7)
     56 {
     57 	int fd, i;
     58 	int ctlr, unit, part, type;
     59 	uint32_t bootdev = d6;
     60 	char *netbsd = (char *)d5;
     61 	u_long marks[MARK_MAX];
     62 	static char devname[32], file[32];
     63 	void (*entry)(void);
     64 
     65 	printf("%s Secondary Boot, Revision %s\n",
     66 	    bootprog_name, bootprog_rev);
     67 	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
     68 
     69 	/* bootname is "boot" by default. */
     70 	if (netbsd == NULL || strcmp(netbsd, "boot") == 0 ||
     71 			      strcmp(netbsd, "/boot") == 0)
     72 		netbsd = "";
     73 
     74 	DPRINTF("howto = 0x%x\n", d7);
     75 	DPRINTF("bootdev = 0x%x\n", bootdev);
     76 	DPRINTF("bootname = %s\n", netbsd);
     77 	DPRINTF("maxmem = 0x%x\n", d4);
     78 
     79 #define	SET_MAGIC(bootdev, magic) ((bootdev & 0x0fffffff)| (magic << 28))
     80 	/* PROM monitor passes 0xa, but NEWS-OS /boot passed 0x5... */
     81 	bootdev = SET_MAGIC(bootdev, 5);
     82 
     83 	ctlr = BOOTDEV_CTLR(bootdev);
     84 	unit = BOOTDEV_UNIT(bootdev);
     85 	part = BOOTDEV_PART(bootdev);
     86 	type = BOOTDEV_TYPE(bootdev);
     87 
     88 	marks[MARK_START] = 0;
     89 
     90 	if (devs[type] == NULL) {
     91 		printf("unknown bootdev (0x%x)\n", bootdev);
     92 		return;
     93 	}
     94 
     95 	sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
     96 	printf("Booting %s%s\n", devname, netbsd);
     97 
     98 	/* use user specified kernel name if exists */
     99 	if (*netbsd) {
    100 		kernels[0] = netbsd;
    101 		kernels[1] = NULL;
    102 	}
    103 
    104 	for (i = 0; kernels[i]; i++) {
    105 		sprintf(file, "%s%s", devname, kernels[i]);
    106 		DPRINTF("trying %s...\n", file);
    107 		fd = loadfile(file, marks, LOAD_KERNEL);
    108 		if (fd != -1)
    109 			break;
    110 	}
    111 	if (kernels[i] == NULL) {
    112 #if 0 /* bootxx() may be overrided by loaded kernel */
    113 		return;
    114 #else
    115 		rom_halt();
    116 		/* NOTREACHED */
    117 #endif
    118 	}
    119 
    120 	DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
    121 	DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
    122 	DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
    123 
    124 	entry = (void *)marks[MARK_ENTRY];
    125 
    126 	printf("\n");
    127 
    128 	ICIA();
    129 	__asm volatile ("movl %0,%%d7" : : "m" (d7));
    130 	__asm volatile ("movl %0,%%d6" : : "m" (bootdev));
    131 	__asm volatile ("movl %0,%%d5" : : "m" (netbsd));
    132 	__asm volatile ("movl %0,%%d4" : : "m" (d4));
    133 	__asm volatile ("movl %0,%%d2" : : "m" (marks[MARK_END]));
    134 	(*entry)();
    135 }
    136 
    137 void
    138 _rtt(void)
    139 {
    140 
    141 	rom_halt();
    142 	for (;;)
    143 		;
    144 	/* NOTREACHED */
    145 }
    146