1 /* $NetBSD: main.c,v 1.4 2002/02/20 03:00:27 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1996 5 * Matthias Drochner. All rights reserved. 6 * Copyright (c) 1996 7 * Perry E. Metzger. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgements: 19 * This product includes software developed for the NetBSD Project 20 * by Matthias Drochner. 21 * This product includes software developed for the NetBSD Project 22 * by Perry E. Metzger. 23 * 4. The names of the authors may not be used to endorse or promote products 24 * derived from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 */ 38 39 #include <lib/libkern/libkern.h> 40 41 #include <lib/libsa/stand.h> 42 43 #include <libi386.h> 44 #include "pxeboot.h" 45 46 int errno; 47 int debug; 48 int try_bootp = 1; 49 50 extern char bootprog_name[], bootprog_rev[], bootprog_date[], 51 bootprog_maker[]; 52 53 #define TIMEOUT 5 54 55 int main(void); 56 57 void command_help __P((char *)); 58 void command_quit __P((char *)); 59 void command_boot __P((char *)); 60 61 const struct bootblk_command commands[] = { 62 { "help", command_help }, 63 { "?", command_help }, 64 { "quit", command_quit }, 65 { "boot", command_boot }, 66 { NULL, NULL }, 67 }; 68 69 #ifdef COMPAT_OLDBOOT 70 int 71 parsebootfile(const char *fname, char **fsname, char **devname, 72 u_int *unit, u_int *partition, const char **file) 73 { 74 return (EINVAL); 75 } 76 77 int 78 biosdisk_gettype(struct open_file *f) 79 { 80 return (0); 81 } 82 #endif 83 84 static int 85 bootit(const char *filename, int howto) 86 { 87 if (exec_netbsd(filename, 0, howto) < 0) 88 printf("boot: %s\n", strerror(errno)); 89 else 90 printf("boot returned\n"); 91 return (-1); 92 } 93 94 static void 95 print_banner(void) 96 { 97 int base = getbasemem(); 98 int ext = getextmem(); 99 100 printf("\n" 101 ">> %s, Revision %s\n" 102 ">> (%s, %s)\n" 103 ">> Memory: %d/%d k\n", 104 bootprog_name, bootprog_rev, 105 bootprog_maker, bootprog_date, 106 base, ext); 107 } 108 109 int 110 main(void) 111 { 112 char c; 113 114 #ifdef SUPPORT_SERIAL 115 initio(SUPPORT_SERIAL); 116 #else 117 initio(CONSDEV_PC); 118 #endif 119 gateA20(); 120 121 print_banner(); 122 123 printf("Press return to boot now, any other key for boot menu\n"); 124 printf("Starting in "); 125 126 c = awaitkey(TIMEOUT, 1); 127 if ((c != '\r') && (c != '\n') && (c != '\0')) { 128 printf("type \"?\" or \"help\" for help.\n"); 129 bootmenu(); /* does not return */ 130 } 131 132 /* 133 * The file name provided here is just a default. If the 134 * DHCP server provides a file name, we'll use that instead. 135 */ 136 bootit("netbsd", 0); 137 138 /* 139 * If that fails, let the BIOS try the next boot device. 140 */ 141 return (1); 142 } 143 144 /* ARGSUSED */ 145 void 146 command_help(char *arg) 147 { 148 printf("commands are:\n" 149 "boot [filename] [-adsqv]\n" 150 " (ex. \"netbsd.old -s\"\n" 151 "help|?\n" 152 "quit\n"); 153 } 154 155 /* ARGSUSED */ 156 void 157 command_quit(char *arg) 158 { 159 printf("Exiting... goodbye...\n"); 160 exit(0); 161 } 162 163 void 164 command_boot(char *arg) 165 { 166 char *filename; 167 int howto; 168 169 if (parseboot(arg, &filename, &howto)) 170 bootit(filename, howto); 171 } 172