boot.c revision 1.3 1 1.3 tsubai /* $NetBSD: boot.c,v 1.3 1999/12/22 05:54:41 tsubai 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.1 tsubai #include <lib/libsa/loadfile.h>
32 1.1 tsubai
33 1.3 tsubai #include <machine/apcall.h>
34 1.2 tsubai #include <machine/bootinfo.h>
35 1.3 tsubai #include <machine/cpu.h>
36 1.1 tsubai #include <machine/romcall.h>
37 1.1 tsubai
38 1.3 tsubai void mips1_flushicache __P((void *, int));
39 1.1 tsubai extern char _edata[], _end[];
40 1.1 tsubai
41 1.3 tsubai struct apbus_sysinfo *_sip;
42 1.3 tsubai int apbus;
43 1.3 tsubai
44 1.1 tsubai char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
45 1.1 tsubai char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
46 1.1 tsubai
47 1.1 tsubai #ifdef BOOT_DEBUG
48 1.1 tsubai # define DPRINTF printf
49 1.1 tsubai #else
50 1.1 tsubai # define DPRINTF while (0) printf
51 1.1 tsubai #endif
52 1.1 tsubai
53 1.1 tsubai void
54 1.1 tsubai boot(a0, a1, a2, a3, a4, a5)
55 1.3 tsubai u_int a0, a1, a2, a3, a4, a5;
56 1.1 tsubai {
57 1.1 tsubai int fd, i;
58 1.3 tsubai char *netbsd = "";
59 1.3 tsubai int maxmem;
60 1.1 tsubai u_long marks[MARK_MAX];
61 1.1 tsubai char devname[32], file[32];
62 1.1 tsubai void (*entry)();
63 1.2 tsubai struct btinfo_symtab bi_sym;
64 1.3 tsubai struct btinfo_bootarg bi_arg;
65 1.3 tsubai struct btinfo_bootpath bi_bpath;
66 1.3 tsubai struct btinfo_systype bi_sys;
67 1.1 tsubai
68 1.1 tsubai /* Clear BSS. */
69 1.1 tsubai bzero(_edata, _end - _edata);
70 1.1 tsubai
71 1.3 tsubai /*
72 1.3 tsubai * XXX a3 contains:
73 1.3 tsubai * maxmem (nws-3xxx)
74 1.3 tsubai * argv (apbus-based machine)
75 1.3 tsubai */
76 1.3 tsubai if (a3 >= 0x80000000)
77 1.3 tsubai apbus = 1;
78 1.3 tsubai else
79 1.3 tsubai apbus = 0;
80 1.3 tsubai
81 1.3 tsubai if (apbus)
82 1.3 tsubai _sip = (void *)a4;
83 1.3 tsubai
84 1.1 tsubai printf("\n");
85 1.1 tsubai printf("NetBSD/newsmips Secondary Boot\n");
86 1.1 tsubai
87 1.3 tsubai if (apbus) {
88 1.3 tsubai char *bootdev = (char *)a1;
89 1.3 tsubai int argc = a2;
90 1.3 tsubai char **argv = (char **)a3;
91 1.3 tsubai
92 1.3 tsubai DPRINTF("APbus-based system\n");
93 1.3 tsubai
94 1.3 tsubai DPRINTF("argc = %d\n", argc);
95 1.3 tsubai for (i = 0; i < argc; i++) {
96 1.3 tsubai DPRINTF("argv[%d] = %s\n", i, argv[i]);
97 1.3 tsubai if (argv[i][0] != '-' && *netbsd == 0)
98 1.3 tsubai netbsd = argv[i];
99 1.3 tsubai }
100 1.3 tsubai maxmem = _sip->apbsi_memsize;
101 1.3 tsubai maxmem -= 0x100000; /* reserve 1MB for ROM monitor */
102 1.3 tsubai
103 1.3 tsubai DPRINTF("howto = 0x%x\n", a0);
104 1.3 tsubai DPRINTF("bootdev = %s\n", (char *)a1);
105 1.3 tsubai DPRINTF("bootname = %s\n", netbsd);
106 1.3 tsubai DPRINTF("maxmem = 0x%x\n", maxmem);
107 1.3 tsubai
108 1.3 tsubai /* XXX use "sonic()" instead of "tftp()" */
109 1.3 tsubai if (strncmp(bootdev, "tftp", 4) == 0)
110 1.3 tsubai bootdev = "sonic";
111 1.3 tsubai
112 1.3 tsubai strcpy(devname, bootdev);
113 1.3 tsubai if (strchr(devname, '(') == NULL)
114 1.3 tsubai strcat(devname, "()");
115 1.3 tsubai } else {
116 1.3 tsubai int bootdev = a1;
117 1.3 tsubai char *bootname = (char *)a2;
118 1.3 tsubai int ctlr, unit, part, type;
119 1.3 tsubai
120 1.3 tsubai DPRINTF("HB system.\n");
121 1.3 tsubai
122 1.3 tsubai /* bootname is "/boot" by default on HB system. */
123 1.3 tsubai if (bootname && strcmp(bootname, "/boot") != 0)
124 1.3 tsubai netbsd = bootname;
125 1.3 tsubai maxmem = a3;
126 1.3 tsubai
127 1.3 tsubai DPRINTF("howto = 0x%x\n", a0);
128 1.3 tsubai DPRINTF("bootdev = 0x%x\n", a1);
129 1.3 tsubai DPRINTF("bootname = %s\n", netbsd);
130 1.3 tsubai DPRINTF("maxmem = 0x%x\n", maxmem);
131 1.3 tsubai
132 1.3 tsubai ctlr = BOOTDEV_CTLR(bootdev);
133 1.3 tsubai unit = BOOTDEV_UNIT(bootdev);
134 1.3 tsubai part = BOOTDEV_PART(bootdev);
135 1.3 tsubai type = BOOTDEV_TYPE(bootdev);
136 1.3 tsubai
137 1.3 tsubai if (devs[type] == NULL) {
138 1.3 tsubai printf("unknown bootdev (0x%x)\n", bootdev);
139 1.3 tsubai _rtt();
140 1.3 tsubai }
141 1.1 tsubai
142 1.3 tsubai sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
143 1.1 tsubai }
144 1.1 tsubai
145 1.1 tsubai printf("Booting %s%s\n", devname, netbsd);
146 1.1 tsubai
147 1.1 tsubai /* use user specified kernel name if exists */
148 1.1 tsubai if (*netbsd) {
149 1.1 tsubai kernels[0] = netbsd;
150 1.1 tsubai kernels[1] = NULL;
151 1.1 tsubai }
152 1.1 tsubai
153 1.3 tsubai marks[MARK_START] = 0;
154 1.3 tsubai
155 1.1 tsubai for (i = 0; kernels[i]; i++) {
156 1.1 tsubai sprintf(file, "%s%s", devname, kernels[i]);
157 1.1 tsubai DPRINTF("trying %s...\n", file);
158 1.3 tsubai fd = loadfile(file, marks, LOAD_KERNEL);
159 1.1 tsubai if (fd != -1)
160 1.1 tsubai break;
161 1.1 tsubai }
162 1.1 tsubai if (fd == -1)
163 1.3 tsubai _rtt();
164 1.1 tsubai
165 1.1 tsubai DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
166 1.1 tsubai DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
167 1.1 tsubai DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
168 1.2 tsubai
169 1.3 tsubai bi_init(BOOTINFO_ADDR);
170 1.3 tsubai
171 1.2 tsubai bi_sym.nsym = marks[MARK_NSYM];
172 1.2 tsubai bi_sym.ssym = marks[MARK_SYM];
173 1.2 tsubai bi_sym.esym = marks[MARK_END];
174 1.2 tsubai bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));
175 1.1 tsubai
176 1.3 tsubai bi_arg.howto = a0;
177 1.3 tsubai bi_arg.bootdev = a1;
178 1.3 tsubai bi_arg.maxmem = maxmem;
179 1.3 tsubai bi_arg.sip = (int)_sip;
180 1.3 tsubai bi_add(&bi_arg, BTINFO_BOOTARG, sizeof(bi_arg));
181 1.3 tsubai
182 1.3 tsubai strcpy(bi_bpath.bootpath, file);
183 1.3 tsubai bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
184 1.3 tsubai
185 1.3 tsubai bi_sys.type = apbus ? NEWS5000 : NEWS3400; /* XXX */
186 1.3 tsubai bi_add(&bi_sys, BTINFO_SYSTYPE, sizeof(bi_sys));
187 1.3 tsubai
188 1.1 tsubai entry = (void *)marks[MARK_ENTRY];
189 1.3 tsubai
190 1.3 tsubai if (apbus)
191 1.3 tsubai apcall_flush_cache();
192 1.3 tsubai else
193 1.3 tsubai mips1_flushicache(entry, marks[MARK_SYM] - marks[MARK_ENTRY]);
194 1.1 tsubai
195 1.1 tsubai printf("\n");
196 1.1 tsubai (*entry)(a0, a1, a2, a3, a4, a5);
197 1.1 tsubai }
198 1.1 tsubai
199 1.1 tsubai void
200 1.1 tsubai putchar(x)
201 1.1 tsubai int x;
202 1.1 tsubai {
203 1.1 tsubai char c = x;
204 1.1 tsubai
205 1.3 tsubai if (apbus)
206 1.3 tsubai apcall_write(1, &c, 1);
207 1.3 tsubai else
208 1.3 tsubai rom_write(1, &c, 1);
209 1.3 tsubai }
210 1.3 tsubai
211 1.3 tsubai void halt __P((void));
212 1.3 tsubai
213 1.3 tsubai void
214 1.3 tsubai _rtt()
215 1.3 tsubai {
216 1.3 tsubai if (apbus)
217 1.3 tsubai apcall_exit(8);
218 1.3 tsubai else
219 1.3 tsubai halt();
220 1.3 tsubai
221 1.3 tsubai for (;;);
222 1.1 tsubai }
223