1*95e1ffb1Schristos /* $NetBSD: bootxx.c,v 1.8 2005/12/11 12:16:20 christos Exp $ */
247acf988Scgd
347acf988Scgd /*
447acf988Scgd * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
547acf988Scgd *
647acf988Scgd * Redistribution and use in source and binary forms, with or without
747acf988Scgd * modification, are permitted provided that the following conditions
847acf988Scgd * are met:
947acf988Scgd * 1. Redistributions of source code must retain the above copyright
1047acf988Scgd * notice, this list of conditions and the following disclaimer.
1147acf988Scgd * 2. Redistributions in binary form must reproduce the above copyright
1247acf988Scgd * notice, this list of conditions and the following disclaimer in the
1347acf988Scgd * documentation and/or other materials provided with the distribution.
1447acf988Scgd * 3. All advertising materials mentioning features or use of this software
1547acf988Scgd * must display the following acknowledgement:
1647acf988Scgd * This product includes software developed by Christopher G. Demetriou
1747acf988Scgd * for the NetBSD Project.
1847acf988Scgd * 4. The name of the author may not be used to endorse or promote products
1947acf988Scgd * derived from this software without specific prior written permission
2047acf988Scgd *
2147acf988Scgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2247acf988Scgd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2347acf988Scgd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2447acf988Scgd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2547acf988Scgd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2647acf988Scgd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2747acf988Scgd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2847acf988Scgd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2947acf988Scgd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3047acf988Scgd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3147acf988Scgd */
3247acf988Scgd
3347acf988Scgd /*
3447acf988Scgd * Copyright (c) 1992, 1993
3547acf988Scgd * The Regents of the University of California. All rights reserved.
3647acf988Scgd *
3747acf988Scgd * This code is derived from software contributed to Berkeley by
3847acf988Scgd * Ralph Campbell.
3947acf988Scgd *
4047acf988Scgd * Redistribution and use in source and binary forms, with or without
4147acf988Scgd * modification, are permitted provided that the following conditions
4247acf988Scgd * are met:
4347acf988Scgd * 1. Redistributions of source code must retain the above copyright
4447acf988Scgd * notice, this list of conditions and the following disclaimer.
4547acf988Scgd * 2. Redistributions in binary form must reproduce the above copyright
4647acf988Scgd * notice, this list of conditions and the following disclaimer in the
4747acf988Scgd * documentation and/or other materials provided with the distribution.
48aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
4947acf988Scgd * may be used to endorse or promote products derived from this software
5047acf988Scgd * without specific prior written permission.
5147acf988Scgd *
5247acf988Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5347acf988Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5447acf988Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5547acf988Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5647acf988Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5747acf988Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5847acf988Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5947acf988Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6047acf988Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6147acf988Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6247acf988Scgd * SUCH DAMAGE.
6347acf988Scgd *
6447acf988Scgd * @(#)boot.c 8.1 (Berkeley) 6/10/93
6547acf988Scgd */
6647acf988Scgd
6747acf988Scgd #include <lib/libsa/stand.h>
68728d6723Sthorpej #include <lib/libkern/libkern.h>
6947acf988Scgd
7047acf988Scgd #include <sys/param.h>
7147acf988Scgd #include <sys/exec.h>
7247acf988Scgd #include <sys/exec_ecoff.h>
7347acf988Scgd
7447acf988Scgd #include <machine/autoconf.h>
7547acf988Scgd #include <machine/prom.h>
7647acf988Scgd #include <machine/rpb.h>
7747acf988Scgd
7847acf988Scgd #include <machine/pte.h>
7947acf988Scgd
8047acf988Scgd #include "../common/common.h"
8147acf988Scgd
82ebca60d3Scgd void main(void);
8347acf988Scgd
8447acf988Scgd void
main(void)85ebca60d3Scgd main(void)
8647acf988Scgd {
8747acf988Scgd struct stat sb;
8847acf988Scgd const char *reason;
8947acf988Scgd int fd;
9047acf988Scgd
9147acf988Scgd /* Init prom callback vector. */
9247acf988Scgd init_prom_calls();
9347acf988Scgd
945dd4815bScgd putstr("\nNetBSD/alpha " NETBSD_VERS " " BOOTXX_FS_NAME " Primary Bootstrap\n");
9547acf988Scgd
9647acf988Scgd if (!booted_dev_open()) {
9747acf988Scgd reason = "Can't open boot device.";
9847acf988Scgd goto fail;
9947acf988Scgd }
10047acf988Scgd
10147acf988Scgd fd = open("boot", 0);
10247acf988Scgd if (fd == -1 || (fstat(fd, &sb) == -1)) {
10347acf988Scgd reason = "Can't open /boot.";
10447acf988Scgd goto failclose;
10547acf988Scgd }
10647acf988Scgd
10747acf988Scgd if (sb.st_size > SECONDARY_MAX_LOAD) {
10847acf988Scgd reason = "/boot too large.";
10947acf988Scgd goto failclose;
11047acf988Scgd }
11147acf988Scgd
11247acf988Scgd if (read(fd, (void*)SECONDARY_LOAD_ADDRESS, sb.st_size) != sb.st_size) {
11347acf988Scgd reason = "/boot load failed.";
11447acf988Scgd goto failclose;
11547acf988Scgd }
11647acf988Scgd
11747acf988Scgd putstr("Jumping to entry point...\n");
11847acf988Scgd (*((void(*)(int))SECONDARY_LOAD_ADDRESS))(booted_dev_fd);
11947acf988Scgd
12047acf988Scgd reason = "Secondary boot returned!";
12147acf988Scgd failclose:
12247acf988Scgd booted_dev_close();
12347acf988Scgd fail:
12447acf988Scgd putstr(reason);
12547acf988Scgd putstr("\n\nPRIMARY BOOTSTRAP FAILED!\n");
12647acf988Scgd }
127