Home | History | Annotate | Line # | Download | only in bootxx
      1  1.17  dholland /*	$NetBSD: bootxx.c,v 1.17 2016/06/11 06:28:07 dholland 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.11  junyoung #include <lib/libsa/stand.h>
     36   1.2       leo #include <atari_stand.h>
     37   1.1       leo #include <libkern.h>
     38   1.6       leo #include <tosdefs.h>
     39   1.4  jdolecek #include <sys/boot_flag.h>
     40   1.1       leo #include <sys/exec.h>
     41   1.1       leo #include <sys/reboot.h>
     42   1.1       leo #include <machine/cpu.h>
     43   1.1       leo 
     44  1.10  junyoung typedef int      (*bxxx_t)(void *, void *, struct osdsc *);
     45   1.1       leo 
     46  1.13   tsutsui int	bootxx(void *, void *, int);
     47  1.10  junyoung void	boot_BSD(struct kparamb *) __attribute__((noreturn));
     48  1.10  junyoung int	bootxxx(void *, void *, struct osdsc *);
     49  1.10  junyoung int	load_booter(struct osdsc *);
     50  1.10  junyoung int	usr_info(struct osdsc *);
     51   1.1       leo 
     52  1.16   tsutsui #define	BOOTXXX_MAXSIZE	(64 * 1024)
     53  1.16   tsutsui #define	HEAPSIZE	(64 * 1024)	/* should be >32KB for ffs blocksize */
     54  1.16   tsutsui #define	HEAPSTART	(LOADADDR3 + BOOTXXX_MAXSIZE)
     55  1.16   tsutsui #define	HEAPEND		(HEAPSTART + HEAPSIZE)
     56  1.16   tsutsui 
     57   1.1       leo int
     58  1.10  junyoung bootxx(void *readsector, void *disklabel, int autoboot)
     59   1.1       leo {
     60   1.6       leo 	static osdsc_t	os_desc;
     61   1.1       leo 	extern char	end[], edata[];
     62   1.6       leo 	osdsc_t		*od = &os_desc;
     63   1.6       leo 	bxxx_t		bootxxx = (bxxx_t)(LOADADDR3);
     64   1.1       leo 
     65  1.14    cegger 	memset(edata, 0, end - edata);
     66  1.16   tsutsui 	setheap((void *)HEAPSTART, (void *)HEAPEND);
     67   1.1       leo 
     68  1.10  junyoung 	printf("\033v\nNetBSD/atari secondary bootloader"
     69  1.17  dholland 						" ($Revision: 1.17 $)\n\n");
     70   1.1       leo 
     71   1.1       leo 	if (init_dskio(readsector, disklabel, -1))
     72  1.10  junyoung 		return -1;
     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.10  junyoung 				return pref;
     89   1.1       leo 		}
     90   1.1       leo 		autoboot = 0;			/* in case auto boot fails */
     91   1.1       leo 
     92   1.1       leo 		if (init_dskio(readsector, disklabel, od->rootfs))
     93   1.1       leo 			continue;
     94   1.1       leo 
     95   1.6       leo 		if (load_booter(od))
     96   1.1       leo 			continue;
     97   1.1       leo 
     98   1.6       leo 		(*bootxxx)(readsector, disklabel, od);
     99   1.1       leo 	}
    100   1.1       leo 	/* NOTREACHED */
    101   1.1       leo }
    102   1.1       leo 
    103   1.1       leo 
    104   1.1       leo int
    105  1.10  junyoung usr_info(osdsc_t *od)
    106   1.1       leo {
    107   1.1       leo 	static char	line[800];
    108   1.1       leo 	char		c, *p = line;
    109   1.1       leo 
    110   1.1       leo 	printf("\nEnter os-type [.%s] root-fs [:a] kernel [%s]"
    111   1.1       leo 	       " options [none]:\n\033e", od->ostype, od->osname);
    112  1.17  dholland 	kgets(p, sizeof(line));
    113   1.1       leo 	printf("\033f");
    114   1.1       leo 
    115   1.1       leo 	for (;;) {
    116   1.1       leo 		while (isspace(*p))
    117   1.1       leo 			*p++ = '\0';
    118   1.1       leo 
    119   1.1       leo 		switch (*p++) {
    120  1.10  junyoung 		case '\0':
    121   1.1       leo 			goto done;
    122  1.10  junyoung 		case ':':
    123   1.1       leo 			if ((c = *p) >= 'a' && c <= 'z')
    124   1.1       leo 				od->rootfs = c - 'a';
    125   1.1       leo 			else if (c >= 'A' && c <= 'Z')
    126   1.1       leo 				od->rootfs = c - ('A' - 27);
    127  1.10  junyoung 			else
    128  1.10  junyoung 				return -1;
    129   1.1       leo 
    130   1.1       leo 			if (!od->rootfs)
    131   1.1       leo 				break;
    132   1.1       leo 			*p = 'b';
    133   1.1       leo 			/* FALLTHROUGH */
    134   1.1       leo 		  case '-':
    135   1.1       leo 			if ((c = *p) == 'a')
    136   1.1       leo 				od->boothowto &= ~RB_SINGLE;
    137   1.1       leo 			else if (c == 'b')
    138   1.1       leo 				od->boothowto |= RB_ASKNAME;
    139   1.4  jdolecek 			else
    140   1.4  jdolecek 				BOOT_FLAG(c, od->boothowto);
    141   1.1       leo 			break;
    142   1.1       leo 		  case '.':
    143   1.1       leo 			od->ostype = p;
    144   1.1       leo 			break;
    145   1.1       leo 		  case '/':
    146   1.1       leo 			od->osname = --p;
    147   1.1       leo 			break;
    148   1.1       leo 		  default:
    149  1.10  junyoung 			return -1;
    150   1.1       leo 		}
    151   1.1       leo 
    152   1.1       leo 		while ((c = *p) && !isspace(c))
    153   1.1       leo 			p += 1;
    154   1.1       leo 	}
    155   1.1       leo 
    156   1.1       leo done:
    157   1.1       leo 	c = od->ostype[0];
    158   1.1       leo 	if (isupper(c))
    159   1.1       leo 		c = tolower(c);
    160   1.1       leo 
    161   1.1       leo 	switch (c) {
    162  1.10  junyoung 	case 'n':		/* NetBSD */
    163  1.10  junyoung 		return 0;
    164  1.10  junyoung 	case 'l':		/* Linux  */
    165  1.10  junyoung 		return 0x10;
    166  1.10  junyoung 	case 'a':		/* ASV    */
    167  1.10  junyoung 		return 0x40;
    168  1.10  junyoung 	case 't':		/* TOS    */
    169  1.10  junyoung 		return 0x80;
    170  1.10  junyoung 	default:
    171  1.10  junyoung 		return -1;
    172   1.1       leo 	}
    173   1.1       leo }
    174   1.1       leo 
    175   1.1       leo int
    176  1.10  junyoung load_booter(osdsc_t *od)
    177   1.1       leo {
    178   1.9       leo 	int		fd = -1;
    179   1.6       leo 	u_char		*bstart = (u_char *)(LOADADDR3);
    180   1.6       leo 	int		bsize;
    181   1.8       leo 	char		*fname;
    182   1.8       leo 	char		*boot_names[] = {	/* 3rd level boot names	  */
    183   1.8       leo 				"/boot.atari",	/* in order of preference */
    184   1.8       leo 				"/boot",
    185   1.8       leo 				"/boot.ata",
    186   1.8       leo 				NULL };		/* NULL terminated!	  */
    187   1.8       leo 
    188   1.1       leo 	/*
    189   1.6       leo 	 * Read booter's exec-header.
    190   1.1       leo 	 */
    191   1.8       leo 	for (fname = boot_names[0]; fname != NULL; fname++) {
    192   1.8       leo 		if ((fd = open(fname, 0)) < 0)
    193   1.8       leo 			printf("Cannot open '%s'\n", fname);
    194  1.10  junyoung 		else
    195  1.10  junyoung 			break;
    196   1.6       leo 	}
    197   1.8       leo 	if (fd < 0)
    198  1.10  junyoung 		return -1;
    199  1.15   tsutsui 	while ((bsize = read(fd, bstart, 1024)) > 0) {
    200   1.6       leo 		bstart += bsize;
    201   1.1       leo 	}
    202   1.6       leo 	close(fd);
    203   1.6       leo 	return 0;
    204   1.1       leo }
    205   1.5    thomas 
    206   1.6       leo void
    207  1.10  junyoung _rtt(void)
    208   1.5    thomas {
    209  1.15   tsutsui 
    210   1.6       leo 	printf("Halting...\n");
    211  1.15   tsutsui 	for (;;)
    212   1.6       leo 		;
    213   1.5    thomas }
    214