Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.4
      1 /*	$NetBSD: boot.c,v 1.4 2001/05/12 22:35:30 chs Exp $	*/
      2 /*
      3  * Copyright (c) 1994 Rolf Grossmann
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Rolf Grossmann.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/param.h>
     33 #include <sys/reboot.h>
     34 
     35 #include <lib/libsa/stand.h>
     36 #include <lib/libsa/loadfile.h>
     37 #include <lib/libkern/libkern.h>
     38 
     39 #include <machine/cpu.h>        /* for NEXT_RAMBASE */
     40 
     41 #define KERN_LOADADDR NEXT_RAMBASE
     42 
     43 extern int errno;
     44 
     45 /*
     46  * Boot device is derived from PROM provided information.
     47  */
     48 
     49 extern char bootprog_rev[];
     50 extern char bootprog_name[];
     51 extern int build;
     52 #define KNAMEN 100
     53 char kernel[KNAMEN];
     54 int entry_point;		/* return value filled in by machdep_start */
     55 
     56 extern void rtc_init(void);
     57 
     58 extern int try_bootp;
     59 
     60 volatile int qq;
     61 
     62 int
     63 main(char *boot_arg)
     64 {
     65 	int fd;
     66 	u_long marks[MARK_MAX];
     67 
     68 	memset(marks, 0, sizeof(marks));
     69 	printf(">> %s BOOT [%s #%d]\n", bootprog_name, bootprog_rev, build);
     70 	rtc_init();
     71 
     72 	try_bootp = 1;
     73 
     74 #if 0
     75 	printf("Press return to continue.\n");
     76 	getchar();
     77 #endif
     78 
     79 	strcpy(kernel, boot_arg);
     80 	entry_point = NULL;
     81 
     82 	for (;;) {
     83 		marks[MARK_START] = (u_long)KERN_LOADADDR;
     84 		fd = loadfile(kernel, marks, LOAD_KERNEL);
     85 		if (fd != -1) {
     86 			break;
     87 		}
     88 
     89 		printf("load of %s: %s\n", kernel, strerror(errno));
     90 		printf("boot: ");
     91 		gets(kernel);
     92 		/* XXX we have to write this back into boot_arg or even mg->boot* */
     93 		if (kernel[0] == '\0')
     94 			return NULL;
     95 	}
     96 
     97 	*((u_long *)KERN_LOADADDR) = marks[MARK_END] - KERN_LOADADDR;
     98 	printf("entry 0x%lx esym 0x%lx\n",
     99 	       marks[MARK_ENTRY], marks[MARK_END] - KERN_LOADADDR);
    100 	return marks[MARK_ENTRY];
    101 }
    102