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