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