Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / atari / stand / bootxx / bootxx.c
blob12ee69bfbe6981097e03a3be2709297d5b5dda27
1 /* $NetBSD: bootxx.c,v 1.14 2009/03/18 16:00:10 cegger Exp $ */
3 /*
4 * Copyright (c) 1995 Waldi Ravens.
5 * All rights reserved.
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
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.
33 #define boot_BSD bsd_startup
35 #include <lib/libsa/stand.h>
36 #include <atari_stand.h>
37 #include <libkern.h>
38 #include <tosdefs.h>
39 #include <sys/boot_flag.h>
40 #include <sys/exec.h>
41 #include <sys/reboot.h>
42 #include <machine/cpu.h>
44 typedef int (*bxxx_t)(void *, void *, struct osdsc *);
46 int bootxx(void *, void *, int);
47 void boot_BSD(struct kparamb *) __attribute__((noreturn));
48 int bootxxx(void *, void *, struct osdsc *);
49 int load_booter(struct osdsc *);
50 int usr_info(struct osdsc *);
52 int
53 bootxx(void *readsector, void *disklabel, int autoboot)
55 static osdsc_t os_desc;
56 extern char end[], edata[];
57 osdsc_t *od = &os_desc;
58 bxxx_t bootxxx = (bxxx_t)(LOADADDR3);
60 memset(edata, 0, end - edata);
61 setheap(end, (void*)(LOADADDR3 - 4));
63 printf("\033v\nNetBSD/atari secondary bootloader"
64 " ($Revision: 1.15 $)\n\n");
66 if (init_dskio(readsector, disklabel, -1))
67 return -1;
69 for (;;) {
70 od->rootfs = 0; /* partition a */
71 od->osname = "/netbsd";
72 od->ostype = &od->osname[1];
73 od->boothowto = (RB_RDONLY);
75 if (!autoboot) {
76 int pref;
78 od->boothowto = (RB_RDONLY|RB_SINGLE);
79 pref = usr_info(od);
80 if (pref < 0)
81 continue;
82 if (pref > 0)
83 return pref;
85 autoboot = 0; /* in case auto boot fails */
87 if (init_dskio(readsector, disklabel, od->rootfs))
88 continue;
90 if (load_booter(od))
91 continue;
93 (*bootxxx)(readsector, disklabel, od);
95 /* NOTREACHED */
99 int
100 usr_info(osdsc_t *od)
102 static char line[800];
103 char c, *p = line;
105 printf("\nEnter os-type [.%s] root-fs [:a] kernel [%s]"
106 " options [none]:\n\033e", od->ostype, od->osname);
107 gets(p);
108 printf("\033f");
110 for (;;) {
111 while (isspace(*p))
112 *p++ = '\0';
114 switch (*p++) {
115 case '\0':
116 goto done;
117 case ':':
118 if ((c = *p) >= 'a' && c <= 'z')
119 od->rootfs = c - 'a';
120 else if (c >= 'A' && c <= 'Z')
121 od->rootfs = c - ('A' - 27);
122 else
123 return -1;
125 if (!od->rootfs)
126 break;
127 *p = 'b';
128 /* FALLTHROUGH */
129 case '-':
130 if ((c = *p) == 'a')
131 od->boothowto &= ~RB_SINGLE;
132 else if (c == 'b')
133 od->boothowto |= RB_ASKNAME;
134 else
135 BOOT_FLAG(c, od->boothowto);
136 break;
137 case '.':
138 od->ostype = p;
139 break;
140 case '/':
141 od->osname = --p;
142 break;
143 default:
144 return -1;
147 while ((c = *p) && !isspace(c))
148 p += 1;
151 done:
152 c = od->ostype[0];
153 if (isupper(c))
154 c = tolower(c);
156 switch (c) {
157 case 'n': /* NetBSD */
158 return 0;
159 case 'l': /* Linux */
160 return 0x10;
161 case 'a': /* ASV */
162 return 0x40;
163 case 't': /* TOS */
164 return 0x80;
165 default:
166 return -1;
171 load_booter(osdsc_t *od)
173 int fd = -1;
174 u_char *bstart = (u_char *)(LOADADDR3);
175 int bsize;
176 char *fname;
177 char *boot_names[] = { /* 3rd level boot names */
178 "/boot.atari", /* in order of preference */
179 "/boot",
180 "/boot.ata",
181 NULL }; /* NULL terminated! */
184 * Read booter's exec-header.
186 for (fname = boot_names[0]; fname != NULL; fname++) {
187 if ((fd = open(fname, 0)) < 0)
188 printf("Cannot open '%s'\n", fname);
189 else
190 break;
192 if (fd < 0)
193 return -1;
194 while ((bsize = read(fd, bstart, 1024)) > 0) {
195 bstart += bsize;
197 close(fd);
198 return 0;
201 void
202 _rtt(void)
205 printf("Halting...\n");
206 for (;;)