Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / newsmips / stand / boot / boot.c
blobe65a4f83ca1eafce33cd383e9b2ba1821d0464eb
1 /* $NetBSD: boot.c,v 1.16 2005/12/11 12:18:25 christos Exp $ */
3 /*-
4 * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
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.
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.
29 #include <lib/libkern/libkern.h>
30 #include <lib/libsa/stand.h>
31 #include <lib/libsa/loadfile.h>
33 #include <machine/apcall.h>
34 #include <machine/bootinfo.h>
35 #include <machine/cpu.h>
36 #include <machine/romcall.h>
38 void boot(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
40 void mips1_flushicache(void *, int);
41 extern char _edata[], _end[];
43 /* version strings in vers.c (generated by newvers.sh) */
44 extern const char bootprog_name[];
45 extern const char bootprog_rev[];
46 extern const char bootprog_date[];
47 extern const char bootprog_maker[];
49 struct apbus_sysinfo *_sip;
50 int apbus;
52 char *devs[] = { "sd", "fh", "fd", NULL, NULL, "rd", "st" };
53 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
55 #ifdef BOOT_DEBUG
56 # define DPRINTF printf
57 #else
58 # define DPRINTF while (0) printf
59 #endif
61 void
62 boot(uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4,
63 uint32_t a5)
65 int fd, i;
66 char *netbsd = "";
67 int maxmem;
68 u_long marks[MARK_MAX];
69 char devname[32], file[32];
70 void (*entry)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
71 uint32_t);
72 struct btinfo_symtab bi_sym;
73 struct btinfo_bootarg bi_arg;
74 struct btinfo_bootpath bi_bpath;
75 struct btinfo_systype bi_sys;
76 int loadflag;
78 /* Clear BSS. */
79 memset(_edata, 0, _end - _edata);
82 * XXX a3 contains:
83 * maxmem (nws-3xxx)
84 * argv (apbus-based machine)
86 if (a3 >= 0x80000000)
87 apbus = 1;
88 else
89 apbus = 0;
91 if (apbus)
92 _sip = (void *)a4;
94 printf("%s Secondary Boot, Revision %s\n",
95 bootprog_name, bootprog_rev);
96 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
98 if (apbus) {
99 char *bootdev = (char *)a1;
100 int argc = a2;
101 char **argv = (char **)a3;
103 DPRINTF("APbus-based system\n");
105 DPRINTF("argc = %d\n", argc);
106 for (i = 0; i < argc; i++) {
107 DPRINTF("argv[%d] = %s\n", i, argv[i]);
108 if (argv[i][0] != '-' && *netbsd == 0)
109 netbsd = argv[i];
111 maxmem = _sip->apbsi_memsize;
112 maxmem -= 0x100000; /* reserve 1MB for ROM monitor */
114 DPRINTF("howto = 0x%x\n", a0);
115 DPRINTF("bootdev = %s\n", (char *)a1);
116 DPRINTF("bootname = %s\n", netbsd);
117 DPRINTF("maxmem = 0x%x\n", maxmem);
119 /* XXX use "sonic()" instead of "tftp()" */
120 if (strncmp(bootdev, "tftp", 4) == 0)
121 bootdev = "sonic";
123 strcpy(devname, bootdev);
124 if (strchr(devname, '(') == NULL)
125 strcat(devname, "()");
126 } else {
127 int bootdev = a1;
128 char *bootname = (char *)a2;
129 int ctlr, unit, part, type;
131 DPRINTF("HB system.\n");
133 /* bootname is "/boot" by default on HB system. */
134 if (bootname && strcmp(bootname, "/boot") != 0)
135 netbsd = bootname;
136 maxmem = a3;
138 DPRINTF("howto = 0x%x\n", a0);
139 DPRINTF("bootdev = 0x%x\n", a1);
140 DPRINTF("bootname = %s\n", netbsd);
141 DPRINTF("maxmem = 0x%x\n", maxmem);
143 ctlr = BOOTDEV_CTLR(bootdev);
144 unit = BOOTDEV_UNIT(bootdev);
145 part = BOOTDEV_PART(bootdev);
146 type = BOOTDEV_TYPE(bootdev);
148 if (devs[type] == NULL) {
149 printf("unknown bootdev (0x%x)\n", bootdev);
150 _rtt();
153 sprintf(devname, "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
156 printf("Booting %s%s\n", devname, netbsd);
158 /* use user specified kernel name if exists */
159 if (*netbsd) {
160 kernels[0] = netbsd;
161 kernels[1] = NULL;
164 /* disable LOAD_NOTE on floppy to avoid backward seek across volumes */
165 loadflag = LOAD_KERNEL;
166 if (devname[0] == 'f') /* XXX */
167 loadflag &= ~LOAD_NOTE;
169 marks[MARK_START] = 0;
171 for (i = 0; kernels[i]; i++) {
172 sprintf(file, "%s%s", devname, kernels[i]);
173 DPRINTF("trying %s...\n", file);
174 fd = loadfile(file, marks, loadflag);
175 if (fd != -1)
176 break;
178 if (kernels[i] == NULL)
179 _rtt();
181 DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
182 DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
183 DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
185 bi_init(BOOTINFO_ADDR);
187 bi_sym.nsym = marks[MARK_NSYM];
188 bi_sym.ssym = marks[MARK_SYM];
189 bi_sym.esym = marks[MARK_END];
190 bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));
192 bi_arg.howto = a0;
193 bi_arg.bootdev = a1;
194 bi_arg.maxmem = maxmem;
195 bi_arg.sip = (int)_sip;
196 bi_add(&bi_arg, BTINFO_BOOTARG, sizeof(bi_arg));
198 strcpy(bi_bpath.bootpath, file);
199 bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));
201 bi_sys.type = apbus ? NEWS5000 : NEWS3400; /* XXX */
202 bi_add(&bi_sys, BTINFO_SYSTYPE, sizeof(bi_sys));
204 entry = (void *)marks[MARK_ENTRY];
206 if (apbus)
207 apcall_flushcache();
208 else
209 mips1_flushicache(entry, marks[MARK_SYM] - marks[MARK_ENTRY]);
211 printf("\n");
212 (*entry)(a0, a1, a2, a3, a4, a5);
215 void
216 putchar(int x)
218 char c = x;
220 if (apbus)
221 apcall_write(1, &c, 1);
222 else
223 rom_write(1, &c, 1);
227 getchar(void)
229 unsigned char c = '\0';
230 int i;
232 for (;;) {
233 i = apbus ? apcall_read(1, &c, 1) : rom_read(1, &c, 1);
234 if (i == 1)
235 break;
236 if (i != -2 && i != 0)
237 return -1;
239 return c;
242 void
243 _rtt(void)
245 if (apbus)
246 apcall_exit(8);
247 else
248 rom_halt();
250 for (;;);