xref: /netbsd-src/sys/arch/sbmips/stand/common/bootxx.c (revision 95e1ffb15694e54f29f8baaa4232152b703c2a5a)
1*95e1ffb1Schristos /* $NetBSD: bootxx.c,v 1.3 2005/12/11 12:18:51 christos Exp $ */
2c188bc0cScgd 
3c188bc0cScgd /*
4c188bc0cScgd  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
5c188bc0cScgd  *
6c188bc0cScgd  * Redistribution and use in source and binary forms, with or without
7c188bc0cScgd  * modification, are permitted provided that the following conditions
8c188bc0cScgd  * are met:
9c188bc0cScgd  * 1. Redistributions of source code must retain the above copyright
10c188bc0cScgd  *    notice, this list of conditions and the following disclaimer.
11c188bc0cScgd  * 2. Redistributions in binary form must reproduce the above copyright
12c188bc0cScgd  *    notice, this list of conditions and the following disclaimer in the
13c188bc0cScgd  *    documentation and/or other materials provided with the distribution.
14c188bc0cScgd  * 3. All advertising materials mentioning features or use of this software
15c188bc0cScgd  *    must display the following acknowledgement:
16c188bc0cScgd  *      This product includes software developed by Christopher G. Demetriou
17c188bc0cScgd  *	for the NetBSD Project.
18c188bc0cScgd  * 4. The name of the author may not be used to endorse or promote products
19c188bc0cScgd  *    derived from this software without specific prior written permission
20c188bc0cScgd  *
21c188bc0cScgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22c188bc0cScgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23c188bc0cScgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24c188bc0cScgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25c188bc0cScgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26c188bc0cScgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27c188bc0cScgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28c188bc0cScgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29c188bc0cScgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30c188bc0cScgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31c188bc0cScgd  */
32c188bc0cScgd 
33c188bc0cScgd /*
34c188bc0cScgd  * Copyright (c) 1992, 1993
35c188bc0cScgd  *	The Regents of the University of California.  All rights reserved.
36c188bc0cScgd  *
37c188bc0cScgd  * This code is derived from software contributed to Berkeley by
38c188bc0cScgd  * Ralph Campbell.
39c188bc0cScgd  *
40c188bc0cScgd  * Redistribution and use in source and binary forms, with or without
41c188bc0cScgd  * modification, are permitted provided that the following conditions
42c188bc0cScgd  * are met:
43c188bc0cScgd  * 1. Redistributions of source code must retain the above copyright
44c188bc0cScgd  *    notice, this list of conditions and the following disclaimer.
45c188bc0cScgd  * 2. Redistributions in binary form must reproduce the above copyright
46c188bc0cScgd  *    notice, this list of conditions and the following disclaimer in the
47c188bc0cScgd  *    documentation and/or other materials provided with the distribution.
48aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
49c188bc0cScgd  *    may be used to endorse or promote products derived from this software
50c188bc0cScgd  *    without specific prior written permission.
51c188bc0cScgd  *
52c188bc0cScgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53c188bc0cScgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54c188bc0cScgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55c188bc0cScgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56c188bc0cScgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57c188bc0cScgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58c188bc0cScgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59c188bc0cScgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60c188bc0cScgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61c188bc0cScgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62c188bc0cScgd  * SUCH DAMAGE.
63c188bc0cScgd  *
64c188bc0cScgd  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
65c188bc0cScgd  */
66c188bc0cScgd 
67c188bc0cScgd #include <lib/libsa/stand.h>
68c188bc0cScgd #include <lib/libkern/libkern.h>
69c188bc0cScgd 
70c188bc0cScgd #include <sys/param.h>
71c188bc0cScgd #include <sys/exec.h>
72c188bc0cScgd #include <sys/exec_ecoff.h>
73c188bc0cScgd 
74c188bc0cScgd #include "../common/cfe_api.h"
75c188bc0cScgd 
76c188bc0cScgd #include "../common/common.h"
77c188bc0cScgd 
78c188bc0cScgd int main(long fwhandle,long evector,long fwentry,long fwseal);
79c188bc0cScgd 
80c188bc0cScgd int
main(long fwhandle,long evector,long fwentry,long fwseal)81c188bc0cScgd main(long fwhandle,long evector,long fwentry,long fwseal)
82c188bc0cScgd {
83c188bc0cScgd         struct stat sb;
84c188bc0cScgd 	const char *reason;
85c188bc0cScgd 	int fd;
86c188bc0cScgd 
87c188bc0cScgd 	/* Init prom callback vector. */
88c188bc0cScgd 	cfe_init(fwhandle,fwentry);
89c188bc0cScgd 	init_console();
90c188bc0cScgd 
91c188bc0cScgd         putstr("\nNetBSD/sbmips " NETBSD_VERS " " BOOTXX_FS_NAME " Primary Bootstrap\n");
92c188bc0cScgd 
93c188bc0cScgd         if (!booted_dev_open()) {
94c188bc0cScgd 		reason = "Can't open boot device.";
95c188bc0cScgd                 goto fail;
96c188bc0cScgd         }
97c188bc0cScgd 
98c188bc0cScgd 	fd = open("boot", 0);
99c188bc0cScgd 	if (fd == -1 || (fstat(fd, &sb) == -1)) {
100c188bc0cScgd 		reason = "Can't open /boot.";
101c188bc0cScgd 		goto failclose;
102c188bc0cScgd 	}
103c188bc0cScgd 
104c188bc0cScgd 	if (sb.st_size > SECONDARY_MAX_LOAD) {
105c188bc0cScgd 		reason = "/boot too large.";
106c188bc0cScgd 		goto failclose;
107c188bc0cScgd 	}
108c188bc0cScgd 
109c188bc0cScgd 	if (read(fd, (void*)SECONDARY_LOAD_ADDRESS, sb.st_size) != sb.st_size) {
110c188bc0cScgd 		reason = "/boot load failed.";
111c188bc0cScgd 		goto failclose;
112c188bc0cScgd 	}
113c188bc0cScgd 
114c188bc0cScgd 	cfe_flushcache(0);
115c188bc0cScgd 
116c188bc0cScgd 	putstr("Jumping to entry point...\n");
117c188bc0cScgd 	(*((void(*)(long,long,long))SECONDARY_LOAD_ADDRESS))(fwhandle,booted_dev_fd,fwentry);
118c188bc0cScgd 
119c188bc0cScgd 	reason = "Secondary boot returned!";
120c188bc0cScgd failclose:
121c188bc0cScgd 	booted_dev_close();
122c188bc0cScgd fail:
123c188bc0cScgd 	putstr(reason);
124c188bc0cScgd 	putstr("\n\nPRIMARY BOOTSTRAP FAILED!\n");
125c188bc0cScgd 
126c188bc0cScgd 	return 1;
127c188bc0cScgd }
128