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