bootxx.c revision 1.9 1 /* $NetBSD: bootxx.c,v 1.9 2002/04/18 20:12:01 leo Exp $ */
2
3 /*
4 * Copyright (c) 1995 Waldi Ravens.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Waldi Ravens.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #define boot_BSD bsd_startup
34
35 #include <stand.h>
36 #include <atari_stand.h>
37 #include <string.h>
38 #include <libkern.h>
39 #include <tosdefs.h>
40 #include <sys/boot_flag.h>
41 #include <sys/exec.h>
42 #include <sys/reboot.h>
43 #include <machine/cpu.h>
44
45
46 typedef int (*bxxx_t) __P((void *, void *, struct osdsc *));
47
48 void boot_BSD __P((struct kparamb *)__attribute__((noreturn)));
49 int bootxxx __P((void *, void *, struct osdsc *));
50 int load_booter __P((struct osdsc *));
51 int usr_info __P((struct osdsc *));
52
53 int
54 bootxx(readsector, disklabel, autoboot)
55 void *readsector,
56 *disklabel;
57 int autoboot;
58 {
59 static osdsc_t os_desc;
60 extern char end[], edata[];
61 osdsc_t *od = &os_desc;
62 bxxx_t bootxxx = (bxxx_t)(LOADADDR3);
63
64 bzero(edata, end - edata);
65 setheap(end, (void*)(LOADADDR3 - 4));
66
67 printf("\033v\nNetBSD/Atari secondary bootloader"
68 " ($Revision: 1.9 $)\n\n");
69
70 if (init_dskio(readsector, disklabel, -1))
71 return(-1);
72
73
74 for (;;) {
75 od->rootfs = 0; /* partition a */
76 od->osname = "/netbsd";
77 od->ostype = &od->osname[1];
78 od->boothowto = (RB_RDONLY);
79
80 if (!autoboot) {
81 int pref;
82
83 od->boothowto = (RB_RDONLY|RB_SINGLE);
84 pref = usr_info(od);
85 if (pref < 0)
86 continue;
87 if (pref > 0)
88 return(pref);
89 }
90 autoboot = 0; /* in case auto boot fails */
91
92
93 if (init_dskio(readsector, disklabel, od->rootfs))
94 continue;
95
96 if (load_booter(od))
97 continue;
98
99 (*bootxxx)(readsector, disklabel, od);
100 }
101 /* NOTREACHED */
102 }
103
104
105 int
106 usr_info(od)
107 osdsc_t *od;
108 {
109 static char line[800];
110 char c, *p = line;
111
112 printf("\nEnter os-type [.%s] root-fs [:a] kernel [%s]"
113 " options [none]:\n\033e", od->ostype, od->osname);
114 gets(p);
115 printf("\033f");
116
117 for (;;) {
118 while (isspace(*p))
119 *p++ = '\0';
120
121 switch (*p++) {
122 case '\0':
123 goto done;
124 case ':':
125 if ((c = *p) >= 'a' && c <= 'z')
126 od->rootfs = c - 'a';
127 else if (c >= 'A' && c <= 'Z')
128 od->rootfs = c - ('A' - 27);
129 else return(-1);
130
131 if (!od->rootfs)
132 break;
133 *p = 'b';
134 /* FALLTHROUGH */
135 case '-':
136 if ((c = *p) == 'a')
137 od->boothowto &= ~RB_SINGLE;
138 else if (c == 'b')
139 od->boothowto |= RB_ASKNAME;
140 else
141 BOOT_FLAG(c, od->boothowto);
142 break;
143 case '.':
144 od->ostype = p;
145 break;
146 case '/':
147 od->osname = --p;
148 break;
149 default:
150 return(-1);
151 }
152
153 while ((c = *p) && !isspace(c))
154 p += 1;
155 }
156
157 done:
158 c = od->ostype[0];
159 if (isupper(c))
160 c = tolower(c);
161
162 switch (c) {
163 case 'n': /* NetBSD */
164 return(0);
165 case 'l': /* Linux */
166 return(0x10);
167 case 'a': /* ASV */
168 return(0x40);
169 case 't': /* TOS */
170 return(0x80);
171 default:
172 return(-1);
173 }
174 }
175
176 int
177 load_booter(od)
178 osdsc_t *od;
179 {
180 int fd = -1;
181 u_char *bstart = (u_char *)(LOADADDR3);
182 int bsize;
183 char *fname;
184 char *boot_names[] = { /* 3rd level boot names */
185 "/boot.atari", /* in order of preference */
186 "/boot",
187 "/boot.ata",
188 NULL }; /* NULL terminated! */
189
190
191 /*
192 * Read booter's exec-header.
193 */
194 for (fname = boot_names[0]; fname != NULL; fname++) {
195 if ((fd = open(fname, 0)) < 0)
196 printf("Cannot open '%s'\n", fname);
197 else break;
198 }
199 if (fd < 0)
200 return (-1);
201 while((bsize = read(fd, bstart, 1024)) > 0) {
202 bstart += bsize;
203
204 }
205 close(fd);
206 return 0;
207 }
208
209 void
210 _rtt()
211 {
212 printf("Halting...\n");
213 for(;;)
214 ;
215 }
216