1 /* $NetBSD: boot.c,v 1.1 2001/06/14 12:57:16 fredette Exp $ */ 2 3 /*- 4 * Copyright (c) 1982, 1986, 1990, 1993 5 * The Regents of the University of California. 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 the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)boot.c 8.1 (Berkeley) 6/10/93 36 */ 37 38 #include <sys/param.h> 39 #include <sys/reboot.h> 40 #include <machine/mon.h> 41 42 #include <stand.h> 43 #include <loadfile.h> 44 #include "libsa.h" 45 46 /* 47 * Default the name (really tape segment number). 48 * The defaults assume the following tape layout: 49 * segment 0: tapeboot 50 * segment 1: netbsd.sun3 (RAMDISK3) 51 * segment 2: netbsd.sun3x (RAMDISK3X) 52 * segment 3: miniroot image 53 * Therefore, the default name is "1" or "2" 54 * for sun3 and sun3x respectively. 55 */ 56 57 char defname[32] = "1"; 58 char line[80]; 59 60 int 61 main() 62 { 63 char *cp, *file; 64 void *entry; 65 u_long marks[MARK_MAX]; 66 int fd; 67 68 printf(">> %s tapeboot [%s]\n", bootprog_name, bootprog_rev); 69 prom_get_boot_info(); 70 71 /* 72 * Can not hold open the tape device as is done 73 * in the other boot programs because it does 74 * its position-to-segment on open. 75 */ 76 77 /* If running on a Sun3X, use segment 2. */ 78 if (_is3x) 79 defname[0] = '2'; 80 file = defname; 81 82 cp = prom_bootfile; 83 if (cp && *cp) 84 file = cp; 85 86 for (;;) { 87 if (prom_boothow & RB_ASKNAME) { 88 printf("tapeboot: segment? [%s]: ", defname); 89 gets(line); 90 if (line[0]) 91 file = line; 92 else 93 file = defname; 94 } else 95 printf("tapeboot: loading segment %s\n", file); 96 97 marks[MARK_START] = KERN_LOADADDR; 98 if ((fd = loadfile(file, marks, LOAD_KERNEL)) != -1) { 99 break; 100 } 101 printf("tapeboot: segment %s: %s\n", file, strerror(errno)); 102 prom_boothow |= RB_ASKNAME; 103 } 104 close(fd); 105 106 entry = (void *)marks[MARK_ENTRY]; 107 printf("Starting program at 0x%x\n", entry); 108 chain_to(entry); 109 } 110