Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.2
      1 /*	$NetBSD: boot.c,v 1.2 1999/12/18 08:02:05 tsubai Exp $	*/
      2 
      3 /*-
      4  * Copyright (C) 1999 Tsubai Masanari.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <lib/libkern/libkern.h>
     30 #include <lib/libsa/stand.h>
     31 #include <lib/libsa/loadfile.h>
     32 
     33 #include <machine/bootinfo.h>
     34 #include <machine/romcall.h>
     35 
     36 void flushicache __P((void *, int));
     37 extern char _edata[], _end[];
     38 
     39 char *devs[] = { "sd", "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(a0, a1, a2, a3, a4, a5)
     50 	int a0, a1, a2, a3, a4, a5;
     51 {
     52 	int fd, i;
     53 	int ctlr, unit, part, type;
     54 	int bootdev = a1;
     55 	char *netbsd = (char *)a2;
     56 	u_long marks[MARK_MAX];
     57 	char devname[32], file[32];
     58 	void (*entry)();
     59 	struct btinfo_symtab bi_sym;
     60 
     61 	/* Clear BSS. */
     62 	bzero(_edata, _end - _edata);
     63 
     64 	printf("\n");
     65 	printf("NetBSD/newsmips Secondary Boot\n");
     66 
     67 	bi_init(BOOTINFO_ADDR);
     68 
     69 	/* bootname is "/boot" by default. */
     70 	if (netbsd == NULL || strcmp(netbsd, "/boot") == 0)
     71 		netbsd = "";
     72 
     73 	DPRINTF("howto = 0x%x\n", a0);
     74 	DPRINTF("bootdev = 0x%x\n", bootdev);
     75 	DPRINTF("bootname = %s\n", netbsd);
     76 	DPRINTF("maxmem = 0x%x\n", a3);
     77 
     78 	ctlr = BOOTDEV_CTLR(bootdev);
     79 	unit = BOOTDEV_UNIT(bootdev);
     80 	part = BOOTDEV_PART(bootdev);
     81 	type = BOOTDEV_TYPE(bootdev);
     82 
     83 	marks[MARK_START] = 0;
     84 
     85 	if (devs[type] == NULL) {
     86 		printf("unknown bootdev (0x%x)\n", bootdev);
     87 		return;
     88 	}
     89 
     90 	sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
     91 	printf("Booting %s%s\n", devname, netbsd);
     92 
     93 	/* use user specified kernel name if exists */
     94 	if (*netbsd) {
     95 		kernels[0] = netbsd;
     96 		kernels[1] = NULL;
     97 	}
     98 
     99 	for (i = 0; kernels[i]; i++) {
    100 		sprintf(file, "%s%s", devname, kernels[i]);
    101 		DPRINTF("trying %s...\n", file);
    102 		fd = loadfile(file, marks, LOAD_ALL);
    103 		if (fd != -1)
    104 			break;
    105 	}
    106 	if (fd == -1)
    107 		return;
    108 
    109 	DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
    110 	DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
    111 	DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
    112 
    113 	bi_sym.nsym = marks[MARK_NSYM];
    114 	bi_sym.ssym = marks[MARK_SYM];
    115 	bi_sym.esym = marks[MARK_END];
    116 	bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));
    117 
    118 	entry = (void *)marks[MARK_ENTRY];
    119 	flushicache(entry, marks[MARK_SYM] - marks[MARK_ENTRY]);
    120 
    121 	printf("\n");
    122 	(*entry)(a0, a1, a2, a3, a4, a5);
    123 }
    124 
    125 void
    126 putchar(x)
    127 	int x;
    128 {
    129 	char c = x;
    130 
    131 	rom_write(1, &c, 1);
    132 }
    133