Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.1
      1 /*	$NetBSD: boot.c,v 1.1 1999/12/09 14:53:21 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 ICIA __P((void));
     37 extern char edata[], end[];
     38 
     39 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
     40 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
     41 
     42 #ifdef BOOT_DEBUG
     43 # define DPRINTF printf
     44 #else
     45 # define DPRINTF while (0) printf
     46 #endif
     47 
     48 void
     49 boot(d4, d5, d6, d7)
     50 	int d4, d5, d6, d7;
     51 {
     52 	int fd, i;
     53 	int ctlr, unit, part, type;
     54 	int bootdev = d6;
     55 	char *netbsd = (char *)d5;
     56 	u_long marks[MARK_MAX];
     57 	char devname[32], file[32];
     58 	void (*entry)();
     59 
     60 	printf("\n");
     61 	printf("NetBSD/news68k Secondary Boot\n");
     62 
     63 	/* bootname is "boot" by default. */
     64 	if (netbsd == NULL || strcmp(netbsd, "boot") == 0)
     65 		netbsd = "";
     66 
     67 	DPRINTF("howto = 0x%x\n", d7);
     68 	DPRINTF("bootdev = 0x%x\n", bootdev);
     69 	DPRINTF("bootname = %s\n", netbsd);
     70 	DPRINTF("maxmem = 0x%x\n", d4);
     71 
     72 #define	SET_MAGIC(bootdev, magic) ((bootdev & 0x0fffffff)| (magic << 28))
     73 	/* PROM monitor passes 0xa, but NEWS-OS /boot passed 0x5... */
     74 	bootdev = SET_MAGIC(bootdev, 5);
     75 
     76 	ctlr = BOOTDEV_CTLR(bootdev);
     77 	unit = BOOTDEV_UNIT(bootdev);
     78 	part = BOOTDEV_PART(bootdev);
     79 	type = BOOTDEV_TYPE(bootdev);
     80 
     81 	marks[MARK_START] = 0;
     82 
     83 	if (devs[type] == NULL) {
     84 		printf("unknown bootdev (0x%x)\n", bootdev);
     85 		return;
     86 	}
     87 
     88 	sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
     89 	printf("Booting %s%s\n", devname, netbsd);
     90 
     91 	/* use user specified kernel name if exists */
     92 	if (*netbsd) {
     93 		kernels[0] = netbsd;
     94 		kernels[1] = NULL;
     95 	}
     96 
     97 	for (i = 0; kernels[i]; i++) {
     98 		sprintf(file, "%s%s", devname, kernels[i]);
     99 		DPRINTF("trying %s...\n", file);
    100 		fd = loadfile(file, marks, LOAD_KERNEL);
    101 		if (fd != -1)
    102 			break;
    103 	}
    104 	if (fd == -1)
    105 		return;
    106 
    107 	DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
    108 	DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
    109 	DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
    110 
    111 	entry = (void *)marks[MARK_ENTRY];
    112 
    113 	printf("\n");
    114 
    115 	ICIA();
    116 	__asm __volatile ("movl %0,%%d7" : : "m" (d7));
    117 	__asm __volatile ("movl %0,%%d6" : : "m" (bootdev));
    118 	__asm __volatile ("movl %0,%%d5" : : "m" (netbsd));
    119 	__asm __volatile ("movl %0,%%d4" : : "m" (d4));
    120 	__asm __volatile ("movl %0,%%d2" : : "m" (marks[MARK_END]));
    121 	(*((int (*)())entry))();
    122 }
    123