1 /* $NetBSD: boot.c,v 1.16 2005/12/11 12:18:25 christos Exp $ */
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
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
;
52 char *devs
[] = { "sd", "fh", "fd", NULL
, NULL
, "rd", "st" };
53 char *kernels
[] = { "/netbsd", "/netbsd.gz", NULL
};
56 # define DPRINTF printf
58 # define DPRINTF while (0) printf
62 boot(uint32_t a0
, uint32_t a1
, uint32_t a2
, uint32_t a3
, uint32_t a4
,
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,
72 struct btinfo_symtab bi_sym
;
73 struct btinfo_bootarg bi_arg
;
74 struct btinfo_bootpath bi_bpath
;
75 struct btinfo_systype bi_sys
;
79 memset(_edata
, 0, _end
- _edata
);
84 * argv (apbus-based machine)
94 printf("%s Secondary Boot, Revision %s\n",
95 bootprog_name
, bootprog_rev
);
96 printf("(%s, %s)\n", bootprog_maker
, bootprog_date
);
99 char *bootdev
= (char *)a1
;
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)
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)
123 strcpy(devname
, bootdev
);
124 if (strchr(devname
, '(') == NULL
)
125 strcat(devname
, "()");
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)
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
);
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 */
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
);
178 if (kernels
[i
] == NULL
)
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
));
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
];
209 mips1_flushicache(entry
, marks
[MARK_SYM
] - marks
[MARK_ENTRY
]);
212 (*entry
)(a0
, a1
, a2
, a3
, a4
, a5
);
221 apcall_write(1, &c
, 1);
229 unsigned char c
= '\0';
233 i
= apbus
? apcall_read(1, &c
, 1) : rom_read(1, &c
, 1);
236 if (i
!= -2 && i
!= 0)