main.c revision 1.1 1 /*
2 * $NetBSD: main.c,v 1.1 2001/12/17 05:40:40 mhitch Exp $
3 *
4 *
5 * Copyright (c) 1996,1999 Ignatios Souvatzis
6 * Copyright (c) 1994 Michael L. Hitch
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Michael L. Hitch.
20 * 4. The name of the authors may not be used to endorse or promote products
21 * derived from this software without specific prior written permission
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35
36 #include <sys/cdefs.h>
37 #include <sys/reboot.h>
38 #include <sys/types.h>
39
40 #include <sys/exec_aout.h>
41
42 #include <amiga/cfdev.h>
43 #include <amiga/memlist.h>
44 #include <include/cpu.h>
45
46 #include <saerrno.h>
47 #include <stand.h>
48
49 #include "libstubs.h"
50 #include "samachdep.h"
51
52 #undef __LDPGSZ
53 #define __LDPGSZ 8192
54 #define __PGSZ 8192
55
56 #define DRACOREVISION (*(u_int8_t *)0x02000009)
57 #define DRACOMMUMARGIN 0x200000
58 #define DRACOZ2OFFSET 0x3000000
59 #define DRACOZ2MAX 0x1000000
60
61 #define EXECMIN 36
62
63 /*
64 * vers.c (generated by newvers.sh)
65 */
66 extern const char bootprog_rev[];
67
68 void startit __P((void *, void *, void *));
69
70 int consclose(void);
71
72 extern void *ConsoleBase;
73
74 int
75 pain(aio)
76 void *aio;
77 {
78 long int io = 0;
79 caddr_t kp;
80 int ksize;
81 struct stat sb;
82
83 extern u_int16_t timelimit;
84
85 xdinit(aio);
86
87 if (consinit(NULL)) /* Initialize fresh console */
88 return(1);
89
90 #ifdef PPCBOOTER
91 printf("NetBSD/AmigaPPC " NETBSD_VERS " Primary Bootstrap %s\n", bootprog_rev);
92 #else
93 printf("NetBSD/Amiga " NETBSD_VERS " Primary Bootstrap %s\n", bootprog_rev);
94 #endif
95 io = open("/boot.amiga", 0); /* Try /boot.amiga first */
96 if (io < 0) {
97 io = open("/boot", 0); /* Fallback to /boot */
98 if (io < 0) {
99 io = open("/boot.ami", 0); /* 8.3 name? */
100 if (io < 0) {
101 goto err;
102 }
103 }
104 }
105
106 /* get size of file? */
107 if (fstat(io, &sb))
108 goto err;
109 /* allocate memory for file */
110 ksize = sb.st_size;
111 if (ksize == 0) {
112 printf("Bad size, using 32K\n"); /* XXX debug? */
113 ksize = 32 * 1024;
114 }
115 kp = alloc(ksize);
116 if (kp == 0) {
117 errno = ENOMEM;
118 goto err;
119 }
120 /* read file into memory */
121 if (read(io, kp, ksize) != ksize) {
122 errno = ENOEXEC;
123 goto freeall;
124 }
125 /* validate boot: DOS\0 and checksum? */
126 if (strcmp(kp, "DOS") != 0 &&
127 (*(u_int32_t *)kp) != 0x424f4f54) {
128 errno = ENOEXEC;
129 goto freeall;
130 }
131 /* call boot+12(aio, sysbase); */
132 close(io);
133 startit(kp, aio, ConsoleBase);
134 errno = -1;
135
136 freeall:
137 free(kp, ksize);
138 err:
139 printf("Error %ld\n", (long)errno);
140 close(io);
141
142 timelimit = 10;
143 (void)getchar();
144 consclose();
145 return 1;
146 }
147