bootxx.c revision 1.6 1 1.6 tsutsui /* $NetBSD: bootxx.c,v 1.6 2003/11/21 19:44:53 tsutsui 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.5 tsutsui void bootxx __P((u_int32_t, u_int32_t, uint32_t, u_int32_t, u_int32_t,
48 1.5 tsutsui u_int32_t));
49 1.5 tsutsui void (*entry_point) __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t, void *)) =
50 1.4 lukem (void *)DEFAULT_ENTRY_POINT;
51 1.1 tsubai
52 1.1 tsubai #ifdef BOOTXX_DEBUG
53 1.6 tsutsui # define DPRINTF printf
54 1.1 tsubai #else
55 1.6 tsutsui # define DPRINTF while (0) printf
56 1.1 tsubai #endif
57 1.1 tsubai
58 1.1 tsubai char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
59 1.2 onoe struct apbus_sysinfo *_sip;
60 1.2 onoe int apbus = 0;
61 1.1 tsubai
62 1.1 tsubai void
63 1.1 tsubai bootxx(a0, a1, a2, a3, a4, a5)
64 1.4 lukem u_int32_t a0, a1, a2, a3, a4, a5;
65 1.1 tsubai {
66 1.1 tsubai int fd, blk, bs;
67 1.1 tsubai int ctlr, unit, part, type;
68 1.1 tsubai int i;
69 1.1 tsubai int bootdev = a1;
70 1.1 tsubai char *addr;
71 1.1 tsubai char devname[32];
72 1.1 tsubai
73 1.2 onoe /*
74 1.2 onoe * XXX a3 contains:
75 1.2 onoe * maxmem (nws-3xxx)
76 1.2 onoe * argv (apbus-based machine)
77 1.2 onoe */
78 1.2 onoe if (a3 & 0x80000000)
79 1.2 onoe apbus = 1;
80 1.2 onoe else
81 1.2 onoe apbus = 0;
82 1.2 onoe
83 1.1 tsubai printf("NetBSD/newsmips Primary Boot\n");
84 1.1 tsubai
85 1.6 tsutsui DPRINTF("\n");
86 1.6 tsutsui DPRINTF("a0 %x\n", a0);
87 1.6 tsutsui DPRINTF("a1 %x\n", a1);
88 1.6 tsutsui DPRINTF("a2 %x (%s)\n", a2, (char *)a2);
89 1.6 tsutsui DPRINTF("a3 %x\n", a3);
90 1.6 tsutsui DPRINTF("a4 %x\n", a4);
91 1.6 tsutsui DPRINTF("a5 %x\n", a5);
92 1.6 tsutsui
93 1.6 tsutsui DPRINTF("block_size = %d\n", bbinfo.bbi_block_size);
94 1.6 tsutsui DPRINTF("block_count = %d\n", bbinfo.bbi_block_count);
95 1.6 tsutsui DPRINTF("entry_point = %p\n", entry_point);
96 1.1 tsubai
97 1.2 onoe if (apbus) {
98 1.2 onoe strcpy(devname, (char *)a1);
99 1.2 onoe fd = apcall_open(devname, 0);
100 1.2 onoe } else {
101 1.2 onoe /* sd(ctlr, lun, part, bus?, host) */
102 1.2 onoe
103 1.2 onoe ctlr = BOOTDEV_CTLR(bootdev);
104 1.2 onoe unit = BOOTDEV_UNIT(bootdev);
105 1.2 onoe part = BOOTDEV_PART(bootdev);
106 1.2 onoe type = BOOTDEV_TYPE(bootdev);
107 1.2 onoe
108 1.2 onoe if (devs[type] == NULL) {
109 1.2 onoe printf("unknown bootdev (0x%x)\n", bootdev);
110 1.2 onoe return;
111 1.2 onoe }
112 1.2 onoe sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
113 1.1 tsubai
114 1.2 onoe fd = rom_open(devname, 0);
115 1.1 tsubai }
116 1.1 tsubai if (fd == -1) {
117 1.1 tsubai printf("cannot open %s\n", devname);
118 1.1 tsubai return;
119 1.1 tsubai }
120 1.1 tsubai
121 1.1 tsubai addr = (char *)entry_point;
122 1.4 lukem bs = bbinfo.bbi_block_size;
123 1.6 tsutsui DPRINTF("reading block:");
124 1.4 lukem for (i = 0; i < bbinfo.bbi_block_count; i++) {
125 1.4 lukem blk = bbinfo.bbi_block_table[i];
126 1.1 tsubai
127 1.6 tsutsui DPRINTF(" %d", blk);
128 1.1 tsubai
129 1.2 onoe if (apbus) {
130 1.2 onoe apcall_lseek(fd, blk * 512, 0);
131 1.2 onoe apcall_read(fd, addr, bs);
132 1.2 onoe } else {
133 1.2 onoe rom_lseek(fd, blk * 512, 0);
134 1.2 onoe rom_read(fd, addr, bs);
135 1.2 onoe }
136 1.1 tsubai addr += bs;
137 1.1 tsubai }
138 1.6 tsutsui DPRINTF(" done\n");
139 1.2 onoe if (apbus)
140 1.2 onoe apcall_close(fd);
141 1.2 onoe else
142 1.2 onoe rom_close(fd);
143 1.1 tsubai
144 1.2 onoe (*entry_point)(a0, a1, a2, a3, _sip);
145 1.1 tsubai }
146 1.1 tsubai
147 1.1 tsubai void
148 1.1 tsubai putchar(x)
149 1.1 tsubai int x;
150 1.1 tsubai {
151 1.1 tsubai char c = x;
152 1.1 tsubai
153 1.2 onoe if (apbus)
154 1.2 onoe apcall_write(1, &c, 1);
155 1.2 onoe else
156 1.2 onoe rom_write(1, &c, 1);
157 1.1 tsubai }
158