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