bootxx.c revision 1.4 1 /* $NetBSD: bootxx.c,v 1.4 2002/05/20 14:12:24 lukem Exp $ */
2
3 /*-
4 * Copyright (C) 1999 Tsubai Masanari. 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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <lib/libkern/libkern.h>
30 #include <lib/libsa/stand.h>
31 #include <machine/apcall.h>
32 #include <machine/romcall.h>
33
34 #include <sys/bootblock.h>
35
36 struct shared_bbinfo bbinfo = {
37 { NEWSMIPS_BBINFO_MAGIC }, /* bbi_magic[] */
38 0, /* bbi_block_size */
39 SHARED_BBINFO_MAXBLOCKS, /* bbi_block_count */
40 { 0 } /* bbi_block_tagle[] */
41 };
42
43 #ifndef DEFAULT_ENTRY_POINT
44 #define DEFAULT_ENTRY_POINT 0xa0700000
45 #endif
46
47 void (*entry_point)(u_int32_t, u_int32_t, u_int32_t, u_int32_t, void *) =
48 (void *)DEFAULT_ENTRY_POINT;
49
50 #ifdef BOOTXX_DEBUG
51 # define DPRINTF(x) printf x
52 #else
53 # define DPRINTF(x)
54 #endif
55
56 char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
57 struct apbus_sysinfo *_sip;
58 int apbus = 0;
59
60 void
61 bootxx(a0, a1, a2, a3, a4, a5)
62 u_int32_t a0, a1, a2, a3, a4, a5;
63 {
64 int fd, blk, bs;
65 int ctlr, unit, part, type;
66 int i;
67 int bootdev = a1;
68 char *addr;
69 char devname[32];
70
71 /*
72 * XXX a3 contains:
73 * maxmem (nws-3xxx)
74 * argv (apbus-based machine)
75 */
76 if (a3 & 0x80000000)
77 apbus = 1;
78 else
79 apbus = 0;
80
81 printf("NetBSD/newsmips Primary Boot\n");
82
83 DPRINTF(("\n"));
84 DPRINTF(("a0 %x\n", a0));
85 DPRINTF(("a1 %x\n", a1));
86 DPRINTF(("a2 %x (%s)\n", a2, (char *)a2));
87 DPRINTF(("a3 %x\n", a3));
88 DPRINTF(("a4 %x\n", a4));
89 DPRINTF(("a5 %x\n", a5));
90
91 DPRINTF(("block_size = %d\n", bbinfo.bbi_block_size));
92 DPRINTF(("block_count = %d\n", bbinfo.bbi_block_count));
93 DPRINTF(("entry_point = %p\n", entry_point));
94
95 if (apbus) {
96 strcpy(devname, (char *)a1);
97 fd = apcall_open(devname, 0);
98 } else {
99 /* sd(ctlr, lun, part, bus?, host) */
100
101 ctlr = BOOTDEV_CTLR(bootdev);
102 unit = BOOTDEV_UNIT(bootdev);
103 part = BOOTDEV_PART(bootdev);
104 type = BOOTDEV_TYPE(bootdev);
105
106 if (devs[type] == NULL) {
107 printf("unknown bootdev (0x%x)\n", bootdev);
108 return;
109 }
110 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
111
112 fd = rom_open(devname, 0);
113 }
114 if (fd == -1) {
115 printf("cannot open %s\n", devname);
116 return;
117 }
118
119 addr = (char *)entry_point;
120 bs = bbinfo.bbi_block_size;
121 DPRINTF(("reading block:"));
122 for (i = 0; i < bbinfo.bbi_block_count; i++) {
123 blk = bbinfo.bbi_block_table[i];
124
125 DPRINTF((" %d", blk));
126
127 if (apbus) {
128 apcall_lseek(fd, blk * 512, 0);
129 apcall_read(fd, addr, bs);
130 } else {
131 rom_lseek(fd, blk * 512, 0);
132 rom_read(fd, addr, bs);
133 }
134 addr += bs;
135 }
136 DPRINTF((" done\n"));
137 if (apbus)
138 apcall_close(fd);
139 else
140 rom_close(fd);
141
142 (*entry_point)(a0, a1, a2, a3, _sip);
143 }
144
145 void
146 putchar(x)
147 int x;
148 {
149 char c = x;
150
151 if (apbus)
152 apcall_write(1, &c, 1);
153 else
154 rom_write(1, &c, 1);
155 }
156