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