Home | History | Annotate | Line # | Download | only in bootxx
bootxx.c revision 1.8
      1 /*	$NetBSD: bootxx.c,v 1.8 2008/02/21 14:32:31 tsutsui 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 <machine/apcall.h>
     32 #include <machine/romcall.h>
     33 
     34 #include <sys/bootblock.h>
     35 
     36 struct shared_bbinfo bbinfo = {
     37 	{ NEWSMIPS_BBINFO_MAGIC },	/* bbi_magic[] */
     38 	0,				/* bbi_block_size */
     39 	SHARED_BBINFO_MAXBLOCKS,	/* bbi_block_count */
     40 	{ 0 }				/* bbi_block_tagle[] */
     41 };
     42 
     43 #ifndef DEFAULT_ENTRY_POINT
     44 #define DEFAULT_ENTRY_POINT	0xa0700000
     45 #endif
     46 
     47 void bootxx(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
     48 void (*entry_point)(uint32_t, uint32_t, uint32_t, uint32_t, void *) =
     49     (void *)DEFAULT_ENTRY_POINT;
     50 
     51 #ifdef BOOTXX_DEBUG
     52 # define DPRINTF printf
     53 #else
     54 # define DPRINTF while (0) printf
     55 #endif
     56 
     57 char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
     58 struct apbus_sysinfo *_sip;
     59 int apbus = 0;
     60 
     61 void
     62 bootxx(uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4,
     63     uint32_t a5)
     64 {
     65 	int fd, blk, bs;
     66 	int ctlr, unit, part, type;
     67 	int i;
     68 	int bootdev = a1;
     69 	char *addr;
     70 	char devname[32];
     71 
     72 	/*
     73 	 * XXX a3 contains:
     74 	 *     maxmem (nws-3xxx)
     75 	 *     argv   (apbus-based machine)
     76 	 */
     77 	if (a3 & 0x80000000)
     78 		apbus = 1;
     79 	else
     80 		apbus = 0;
     81 
     82 	printf("NetBSD/newsmips Primary Boot\n");
     83 
     84 	DPRINTF("\n");
     85 	DPRINTF("a0 %x\n", a0);
     86 	DPRINTF("a1 %x\n", a1);
     87 	DPRINTF("a2 %x (%s)\n", a2, (char *)a2);
     88 	DPRINTF("a3 %x\n", a3);
     89 	DPRINTF("a4 %x\n", a4);
     90 	DPRINTF("a5 %x\n", a5);
     91 
     92 	DPRINTF("block_size  = %d\n", bbinfo.bbi_block_size);
     93 	DPRINTF("block_count = %d\n", bbinfo.bbi_block_count);
     94 	DPRINTF("entry_point = %p\n", entry_point);
     95 
     96 	if (apbus) {
     97 		strcpy(devname, (char *)a1);
     98 		fd = apcall_open(devname, 0);
     99 	} else {
    100 		/* sd(ctlr, lun, part, bus?, host) */
    101 
    102 		ctlr = BOOTDEV_CTLR(bootdev);
    103 		unit = BOOTDEV_UNIT(bootdev);
    104 		part = BOOTDEV_PART(bootdev);
    105 		type = BOOTDEV_TYPE(bootdev);
    106 
    107 		if (devs[type] == NULL) {
    108 			printf("unknown bootdev (0x%x)\n", bootdev);
    109 			return;
    110 		}
    111 		sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
    112 
    113 		fd = rom_open(devname, 0);
    114 	}
    115 	if (fd == -1) {
    116 		printf("cannot open %s\n", devname);
    117 		return;
    118 	}
    119 
    120 	addr = (char *)entry_point;
    121 	bs = bbinfo.bbi_block_size;
    122 	DPRINTF("reading block:");
    123 	for (i = 0; i < bbinfo.bbi_block_count; i++) {
    124 		blk = bbinfo.bbi_block_table[i];
    125 
    126 		DPRINTF(" %d", blk);
    127 
    128 		if (apbus) {
    129 			apcall_lseek(fd, blk * 512, 0);
    130 			apcall_read(fd, addr, bs);
    131 		} else {
    132 			rom_lseek(fd, blk * 512, 0);
    133 			rom_read(fd, addr, bs);
    134 		}
    135 		addr += bs;
    136 	}
    137 	DPRINTF(" done\n");
    138 	if (apbus)
    139 		apcall_close(fd);
    140 	else
    141 		rom_close(fd);
    142 
    143 	(*entry_point)(a0, a1, a2, a3, _sip);
    144 }
    145 
    146 void
    147 putchar(int x)
    148 {
    149 	char c = x;
    150 
    151 	if (apbus)
    152 		apcall_write(1, &c, 1);
    153 	else
    154 		rom_write(1, &c, 1);
    155 }
    156