1/* $NetBSD: main.c,v 1.17 2009/03/21 15:01:56 ad 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 40#include <lib/libkern/libkern.h> 41 42#include <lib/libsa/stand.h> 43 44#include <libi386.h> 45 46int errno; 47 48extern char bootprog_name[], bootprog_rev[], bootprog_kernrev[]; 49 50#define TIMEOUT 5 51 52void command_help(char *); 53void command_quit(char *); 54void command_boot(char *); 55 56const struct bootblk_command commands[] = { 57 { "help", command_help }, 58 { "?", command_help }, 59 { "quit", command_quit }, 60 { "boot", command_boot }, 61 { NULL, NULL }, 62}; 63 64int 65bootit(const char *filename, int howto) 66{ 67 if (exec_netbsd(filename, 0, howto, 0, clear_pc_screen) < 0) 68 printf("boot: %s\n", strerror(errno)); 69 else 70 printf("boot returned\n"); 71 return (-1); 72} 73 74static void 75print_banner(void) 76{ 77 clear_pc_screen(); 78 79 printf("\n" 80 ">> %s, Revision %s (from NetBSD %s)\n" 81 ">> Memory: %d/%d k\n" 82 "Press return to boot now, any other key for boot menu\n" 83 "starting in ", 84 bootprog_name, bootprog_rev, bootprog_kernrev, 85 getbasemem(), getextmem()); 86} 87 88int 89main(void) 90{ 91 char c; 92 93 initio(CONSDEV_AUTO); 94 gateA20(); 95 96 print_banner(); 97 98 c = awaitkey(TIMEOUT, 1); 99 if ((c != '\r') && (c != '\n') && (c != '\0')) { 100 printf("type \"?\" or \"help\" for help.\n"); 101 bootmenu(); /* does not return */ 102 } 103 104 bootit("netbsd", 0); 105 106 /* if that fails, let BIOS look for boot device */ 107 return (1); 108} 109 110/* ARGSUSED */ 111void 112command_help(char *arg) 113{ 114 printf("commands are:\n" 115 "boot [filename] [-acdqsv]\n" 116 " (ex. \"netbsd.old -s\"\n" 117 "help|?\n" 118 "quit\n"); 119} 120 121/* ARGSUSED */ 122void 123command_quit(char *arg) 124{ 125 printf("Exiting... goodbye...\n"); 126 _rtt(); 127} 128 129void 130command_boot(char *arg) 131{ 132 char *filename; 133 int howto; 134 135 if (parseboot(arg, &filename, &howto)) 136 bootit(filename, howto); 137} 138