bootxx.c revision 1.9 1 1.9 christos /* $NetBSD: bootxx.c,v 1.9 2014/03/26 17:43:11 christos 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.8 tsutsui void bootxx(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
48 1.8 tsutsui void (*entry_point)(uint32_t, uint32_t, uint32_t, uint32_t, void *) =
49 1.4 lukem (void *)DEFAULT_ENTRY_POINT;
50 1.1 tsubai
51 1.1 tsubai #ifdef BOOTXX_DEBUG
52 1.6 tsutsui # define DPRINTF printf
53 1.1 tsubai #else
54 1.6 tsutsui # define DPRINTF while (0) printf
55 1.1 tsubai #endif
56 1.1 tsubai
57 1.1 tsubai char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
58 1.2 onoe struct apbus_sysinfo *_sip;
59 1.2 onoe int apbus = 0;
60 1.1 tsubai
61 1.1 tsubai void
62 1.8 tsutsui bootxx(uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4,
63 1.8 tsutsui uint32_t a5)
64 1.1 tsubai {
65 1.1 tsubai int fd, blk, bs;
66 1.1 tsubai int ctlr, unit, part, type;
67 1.1 tsubai int i;
68 1.1 tsubai int bootdev = a1;
69 1.1 tsubai char *addr;
70 1.1 tsubai char devname[32];
71 1.1 tsubai
72 1.2 onoe /*
73 1.2 onoe * XXX a3 contains:
74 1.2 onoe * maxmem (nws-3xxx)
75 1.2 onoe * argv (apbus-based machine)
76 1.2 onoe */
77 1.2 onoe if (a3 & 0x80000000)
78 1.2 onoe apbus = 1;
79 1.2 onoe else
80 1.2 onoe apbus = 0;
81 1.2 onoe
82 1.1 tsubai printf("NetBSD/newsmips Primary Boot\n");
83 1.1 tsubai
84 1.6 tsutsui DPRINTF("\n");
85 1.6 tsutsui DPRINTF("a0 %x\n", a0);
86 1.6 tsutsui DPRINTF("a1 %x\n", a1);
87 1.6 tsutsui DPRINTF("a2 %x (%s)\n", a2, (char *)a2);
88 1.6 tsutsui DPRINTF("a3 %x\n", a3);
89 1.6 tsutsui DPRINTF("a4 %x\n", a4);
90 1.6 tsutsui DPRINTF("a5 %x\n", a5);
91 1.6 tsutsui
92 1.6 tsutsui DPRINTF("block_size = %d\n", bbinfo.bbi_block_size);
93 1.6 tsutsui DPRINTF("block_count = %d\n", bbinfo.bbi_block_count);
94 1.6 tsutsui DPRINTF("entry_point = %p\n", entry_point);
95 1.1 tsubai
96 1.2 onoe if (apbus) {
97 1.2 onoe strcpy(devname, (char *)a1);
98 1.2 onoe fd = apcall_open(devname, 0);
99 1.2 onoe } else {
100 1.2 onoe /* sd(ctlr, lun, part, bus?, host) */
101 1.2 onoe
102 1.2 onoe ctlr = BOOTDEV_CTLR(bootdev);
103 1.2 onoe unit = BOOTDEV_UNIT(bootdev);
104 1.2 onoe part = BOOTDEV_PART(bootdev);
105 1.2 onoe type = BOOTDEV_TYPE(bootdev);
106 1.2 onoe
107 1.2 onoe if (devs[type] == NULL) {
108 1.2 onoe printf("unknown bootdev (0x%x)\n", bootdev);
109 1.2 onoe return;
110 1.2 onoe }
111 1.9 christos snprintf(devname, sizeof(devname), "%s(%d,%d,%d)",
112 1.9 christos 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.8 tsutsui putchar(int x)
149 1.1 tsubai {
150 1.1 tsubai char c = x;
151 1.1 tsubai
152 1.2 onoe if (apbus)
153 1.2 onoe apcall_write(1, &c, 1);
154 1.2 onoe else
155 1.2 onoe rom_write(1, &c, 1);
156 1.1 tsubai }
157