bootxx.c revision 1.7 1 /* $NetBSD: bootxx.c,v 1.7 2004/12/11 03:32:27 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
34 #include <sys/bootblock.h>
35
36 struct shared_bbinfo bbinfo = {
37 { NEWS68K_BBINFO_MAGIC }, /* bbi_magic[] */
38 0, /* bbi_block_size */
39 SHARED_BBINFO_MAXBLOCKS, /* bbi_block_count */
40 { 0 }, /* bbi_block_table[] */
41 };
42
43 #ifndef DEFAULT_ENTRY_POINT
44 #define DEFAULT_ENTRY_POINT 0x003e0000
45 #endif
46 void (*entry_point)(uint32_t, uint32_t, uint32_t, uint32_t) =
47 (void *)DEFAULT_ENTRY_POINT;
48
49 #ifdef BOOTXX_DEBUG
50 # define DPRINTF printf
51 #else
52 # define DPRINTF while (0) printf
53 #endif
54
55 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
56
57 void
58 bootxx(uint32_t d4, uint32_t d5, uint32_t d6, uint32_t d7)
59 {
60 int fd, blk, bs;
61 int ctlr, unit, part, type;
62 int i;
63 int bootdev = d6;
64 char *addr;
65 char devname[32];
66
67 printf("NetBSD/news68k Primary Boot\n");
68
69 DPRINTF("\n");
70 DPRINTF("d4 %x\n", d4);
71 DPRINTF("d5 %x (%s)\n", d5, (char *)d5);
72 DPRINTF("d6 %x\n", d6);
73 DPRINTF("d7 %x\n", d7);
74
75 DPRINTF("block_size = %d\n", bbinfo.bbi_block_size);
76 DPRINTF("block_count = %d\n", bbinfo.bbi_block_count);
77 DPRINTF("entry_point = %p\n", entry_point);
78
79 /* sd(ctlr, lun, part, bus?, host) */
80
81 ctlr = BOOTDEV_CTLR(bootdev);
82 unit = BOOTDEV_UNIT(bootdev);
83 part = BOOTDEV_PART(bootdev);
84 type = BOOTDEV_TYPE(bootdev);
85
86 if (devs[type] == NULL) {
87 printf("unknown bootdev (0x%x)\n", bootdev);
88 return;
89 }
90
91 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
92
93 fd = rom_open(devname, 0);
94 if (fd == -1) {
95 printf("cannot open %s\n", devname);
96 return;
97 }
98
99 addr = (char *)entry_point;
100 bs = bbinfo.bbi_block_size;
101 DPRINTF("reading block:");
102 for (i = 0; i < bbinfo.bbi_block_count; i++) {
103 blk = bbinfo.bbi_block_table[i];
104
105 DPRINTF(" %d", blk);
106
107 rom_lseek(fd, blk * 512, 0);
108 rom_read(fd, addr, bs);
109 addr += bs;
110 }
111 DPRINTF(" done\n");
112 rom_close(fd);
113
114 (*entry_point)(d4, d5, d6, d7);
115 DPRINTF("bootxx returned?\n");
116 }
117