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