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