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