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