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