Home | History | Annotate | Line # | Download | only in bootxx
bootxx.c revision 1.7.50.1
      1  1.7.50.1     matt /*	bootxx.c,v 1.7 2005/12/11 12:18:25 christos Exp	*/
      2       1.1   tsubai 
      3       1.1   tsubai /*-
      4       1.1   tsubai  * Copyright (C) 1999 Tsubai Masanari.  All rights reserved.
      5       1.1   tsubai  *
      6       1.1   tsubai  * Redistribution and use in source and binary forms, with or without
      7       1.1   tsubai  * modification, are permitted provided that the following conditions
      8       1.1   tsubai  * are met:
      9       1.1   tsubai  * 1. Redistributions of source code must retain the above copyright
     10       1.1   tsubai  *    notice, this list of conditions and the following disclaimer.
     11       1.1   tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1   tsubai  *    notice, this list of conditions and the following disclaimer in the
     13       1.1   tsubai  *    documentation and/or other materials provided with the distribution.
     14       1.1   tsubai  * 3. The name of the author may not be used to endorse or promote products
     15       1.1   tsubai  *    derived from this software without specific prior written permission.
     16       1.1   tsubai  *
     17       1.1   tsubai  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18       1.1   tsubai  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19       1.1   tsubai  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20       1.1   tsubai  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21       1.1   tsubai  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22       1.1   tsubai  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23       1.1   tsubai  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24       1.1   tsubai  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25       1.1   tsubai  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26       1.1   tsubai  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27       1.1   tsubai  */
     28       1.1   tsubai 
     29       1.1   tsubai #include <lib/libkern/libkern.h>
     30       1.1   tsubai #include <lib/libsa/stand.h>
     31       1.2     onoe #include <machine/apcall.h>
     32       1.1   tsubai #include <machine/romcall.h>
     33       1.1   tsubai 
     34       1.4    lukem #include <sys/bootblock.h>
     35       1.1   tsubai 
     36       1.4    lukem struct shared_bbinfo bbinfo = {
     37       1.4    lukem 	{ NEWSMIPS_BBINFO_MAGIC },	/* bbi_magic[] */
     38       1.4    lukem 	0,				/* bbi_block_size */
     39       1.4    lukem 	SHARED_BBINFO_MAXBLOCKS,	/* bbi_block_count */
     40       1.4    lukem 	{ 0 }				/* bbi_block_tagle[] */
     41       1.4    lukem };
     42       1.4    lukem 
     43       1.4    lukem #ifndef DEFAULT_ENTRY_POINT
     44       1.4    lukem #define DEFAULT_ENTRY_POINT	0xa0700000
     45       1.4    lukem #endif
     46       1.4    lukem 
     47  1.7.50.1     matt void bootxx(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
     48  1.7.50.1     matt void (*entry_point)(uint32_t, uint32_t, uint32_t, uint32_t, void *) =
     49       1.4    lukem     (void *)DEFAULT_ENTRY_POINT;
     50       1.1   tsubai 
     51       1.1   tsubai #ifdef BOOTXX_DEBUG
     52       1.6  tsutsui # define DPRINTF printf
     53       1.1   tsubai #else
     54       1.6  tsutsui # define DPRINTF while (0) printf
     55       1.1   tsubai #endif
     56       1.1   tsubai 
     57       1.1   tsubai char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
     58       1.2     onoe struct apbus_sysinfo *_sip;
     59       1.2     onoe int apbus = 0;
     60       1.1   tsubai 
     61       1.1   tsubai void
     62  1.7.50.1     matt bootxx(uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4,
     63  1.7.50.1     matt     uint32_t a5)
     64       1.1   tsubai {
     65       1.1   tsubai 	int fd, blk, bs;
     66       1.1   tsubai 	int ctlr, unit, part, type;
     67       1.1   tsubai 	int i;
     68       1.1   tsubai 	int bootdev = a1;
     69       1.1   tsubai 	char *addr;
     70       1.1   tsubai 	char devname[32];
     71       1.1   tsubai 
     72       1.2     onoe 	/*
     73       1.2     onoe 	 * XXX a3 contains:
     74       1.2     onoe 	 *     maxmem (nws-3xxx)
     75       1.2     onoe 	 *     argv   (apbus-based machine)
     76       1.2     onoe 	 */
     77       1.2     onoe 	if (a3 & 0x80000000)
     78       1.2     onoe 		apbus = 1;
     79       1.2     onoe 	else
     80       1.2     onoe 		apbus = 0;
     81       1.2     onoe 
     82       1.1   tsubai 	printf("NetBSD/newsmips Primary Boot\n");
     83       1.1   tsubai 
     84       1.6  tsutsui 	DPRINTF("\n");
     85       1.6  tsutsui 	DPRINTF("a0 %x\n", a0);
     86       1.6  tsutsui 	DPRINTF("a1 %x\n", a1);
     87       1.6  tsutsui 	DPRINTF("a2 %x (%s)\n", a2, (char *)a2);
     88       1.6  tsutsui 	DPRINTF("a3 %x\n", a3);
     89       1.6  tsutsui 	DPRINTF("a4 %x\n", a4);
     90       1.6  tsutsui 	DPRINTF("a5 %x\n", a5);
     91       1.6  tsutsui 
     92       1.6  tsutsui 	DPRINTF("block_size  = %d\n", bbinfo.bbi_block_size);
     93       1.6  tsutsui 	DPRINTF("block_count = %d\n", bbinfo.bbi_block_count);
     94       1.6  tsutsui 	DPRINTF("entry_point = %p\n", entry_point);
     95       1.1   tsubai 
     96       1.2     onoe 	if (apbus) {
     97       1.2     onoe 		strcpy(devname, (char *)a1);
     98       1.2     onoe 		fd = apcall_open(devname, 0);
     99       1.2     onoe 	} else {
    100       1.2     onoe 		/* sd(ctlr, lun, part, bus?, host) */
    101       1.2     onoe 
    102       1.2     onoe 		ctlr = BOOTDEV_CTLR(bootdev);
    103       1.2     onoe 		unit = BOOTDEV_UNIT(bootdev);
    104       1.2     onoe 		part = BOOTDEV_PART(bootdev);
    105       1.2     onoe 		type = BOOTDEV_TYPE(bootdev);
    106       1.2     onoe 
    107       1.2     onoe 		if (devs[type] == NULL) {
    108       1.2     onoe 			printf("unknown bootdev (0x%x)\n", bootdev);
    109       1.2     onoe 			return;
    110       1.2     onoe 		}
    111       1.2     onoe 		sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
    112       1.1   tsubai 
    113       1.2     onoe 		fd = rom_open(devname, 0);
    114       1.1   tsubai 	}
    115       1.1   tsubai 	if (fd == -1) {
    116       1.1   tsubai 		printf("cannot open %s\n", devname);
    117       1.1   tsubai 		return;
    118       1.1   tsubai 	}
    119       1.1   tsubai 
    120       1.1   tsubai 	addr = (char *)entry_point;
    121       1.4    lukem 	bs = bbinfo.bbi_block_size;
    122       1.6  tsutsui 	DPRINTF("reading block:");
    123       1.4    lukem 	for (i = 0; i < bbinfo.bbi_block_count; i++) {
    124       1.4    lukem 		blk = bbinfo.bbi_block_table[i];
    125       1.1   tsubai 
    126       1.6  tsutsui 		DPRINTF(" %d", blk);
    127       1.1   tsubai 
    128       1.2     onoe 		if (apbus) {
    129       1.2     onoe 			apcall_lseek(fd, blk * 512, 0);
    130       1.2     onoe 			apcall_read(fd, addr, bs);
    131       1.2     onoe 		} else {
    132       1.2     onoe 			rom_lseek(fd, blk * 512, 0);
    133       1.2     onoe 			rom_read(fd, addr, bs);
    134       1.2     onoe 		}
    135       1.1   tsubai 		addr += bs;
    136       1.1   tsubai 	}
    137       1.6  tsutsui 	DPRINTF(" done\n");
    138       1.2     onoe 	if (apbus)
    139       1.2     onoe 		apcall_close(fd);
    140       1.2     onoe 	else
    141       1.2     onoe 		rom_close(fd);
    142       1.1   tsubai 
    143       1.2     onoe 	(*entry_point)(a0, a1, a2, a3, _sip);
    144       1.1   tsubai }
    145       1.1   tsubai 
    146       1.1   tsubai void
    147  1.7.50.1     matt putchar(int x)
    148       1.1   tsubai {
    149       1.1   tsubai 	char c = x;
    150       1.1   tsubai 
    151       1.2     onoe 	if (apbus)
    152       1.2     onoe 		apcall_write(1, &c, 1);
    153       1.2     onoe 	else
    154       1.2     onoe 		rom_write(1, &c, 1);
    155       1.1   tsubai }
    156