Home | History | Annotate | Line # | Download | only in bootxx_ffs
      1   1.1    mhitch /*
      2  1.10       rin  * $NetBSD: main.c,v 1.10 2022/04/29 07:18:17 rin Exp $
      3   1.1    mhitch  *
      4   1.1    mhitch  *
      5   1.1    mhitch  * Copyright (c) 1996,1999 Ignatios Souvatzis
      6   1.1    mhitch  * Copyright (c) 1994 Michael L. Hitch
      7   1.1    mhitch  * All rights reserved.
      8   1.1    mhitch  *
      9   1.1    mhitch  * Redistribution and use in source and binary forms, with or without
     10   1.1    mhitch  * modification, are permitted provided that the following conditions
     11   1.1    mhitch  * are met:
     12   1.1    mhitch  * 1. Redistributions of source code must retain the above copyright
     13   1.1    mhitch  *    notice, this list of conditions and the following disclaimer.
     14   1.1    mhitch  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1    mhitch  *    notice, this list of conditions and the following disclaimer in the
     16   1.1    mhitch  *    documentation and/or other materials provided with the distribution.
     17   1.1    mhitch  *
     18   1.1    mhitch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19   1.1    mhitch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20   1.1    mhitch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21   1.1    mhitch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22   1.1    mhitch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23   1.1    mhitch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24   1.1    mhitch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25   1.1    mhitch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26   1.1    mhitch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27   1.1    mhitch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28   1.1    mhitch  *
     29   1.1    mhitch  */
     30   1.1    mhitch 
     31   1.1    mhitch #include <sys/cdefs.h>
     32   1.1    mhitch #include <sys/reboot.h>
     33   1.1    mhitch #include <sys/types.h>
     34   1.1    mhitch 
     35   1.1    mhitch #include <sys/exec_aout.h>
     36   1.1    mhitch 
     37   1.1    mhitch #include <amiga/cfdev.h>
     38   1.1    mhitch #include <amiga/memlist.h>
     39   1.1    mhitch #include <include/cpu.h>
     40   1.1    mhitch 
     41   1.1    mhitch #include <saerrno.h>
     42   1.4  junyoung #include <lib/libsa/stand.h>
     43   1.8   tsutsui #include <lib/libkern/libkern.h>
     44   1.1    mhitch 
     45   1.1    mhitch #include "libstubs.h"
     46   1.1    mhitch #include "samachdep.h"
     47   1.1    mhitch 
     48   1.3   thorpej #undef AOUT_LDPGSZ
     49   1.3   thorpej #define AOUT_LDPGSZ 8192
     50   1.1    mhitch #define __PGSZ 8192
     51   1.1    mhitch 
     52   1.1    mhitch #define DRACOREVISION	(*(u_int8_t *)0x02000009)
     53   1.1    mhitch #define DRACOMMUMARGIN	0x200000
     54   1.1    mhitch #define DRACOZ2OFFSET	0x3000000
     55   1.1    mhitch #define DRACOZ2MAX	0x1000000
     56   1.1    mhitch 
     57   1.1    mhitch #define EXECMIN 36
     58   1.1    mhitch 
     59   1.1    mhitch /*
     60   1.1    mhitch  * vers.c (generated by newvers.sh)
     61   1.1    mhitch  */
     62   1.1    mhitch extern const char bootprog_rev[];
     63   1.1    mhitch 
     64   1.2   aymeric void startit(void *, void *, void *);
     65   1.1    mhitch 
     66   1.1    mhitch int consclose(void);
     67   1.1    mhitch 
     68   1.1    mhitch extern void *ConsoleBase;
     69   1.1    mhitch 
     70   1.1    mhitch int
     71   1.2   aymeric pain(void *aio)
     72   1.1    mhitch {
     73   1.1    mhitch 	long int io = 0;
     74   1.7  christos 	void *kp;
     75   1.1    mhitch 	int ksize;
     76   1.1    mhitch 	struct stat sb;
     77   1.1    mhitch 
     78   1.1    mhitch 	extern u_int16_t timelimit;
     79   1.1    mhitch 
     80   1.1    mhitch 	xdinit(aio);
     81   1.1    mhitch 
     82   1.1    mhitch 	if (consinit(NULL))		/* Initialize fresh console */
     83   1.1    mhitch 		return(1);
     84   1.1    mhitch 
     85   1.1    mhitch #ifdef PPCBOOTER
     86   1.1    mhitch 	printf("NetBSD/AmigaPPC " NETBSD_VERS " Primary Bootstrap %s\n", bootprog_rev);
     87   1.1    mhitch #else
     88   1.1    mhitch 	printf("NetBSD/Amiga " NETBSD_VERS " Primary Bootstrap %s\n", bootprog_rev);
     89   1.1    mhitch #endif
     90   1.1    mhitch 	io = open("/boot.amiga", 0);	/* Try /boot.amiga first */
     91   1.1    mhitch 	if (io < 0) {
     92   1.1    mhitch 		io = open("/boot", 0);	/* Fallback to /boot */
     93   1.1    mhitch 		if (io < 0) {
     94   1.1    mhitch 			io = open("/boot.ami", 0);	/* 8.3 name? */
     95   1.1    mhitch 			if (io < 0) {
     96   1.1    mhitch 				goto err;
     97   1.1    mhitch 			}
     98   1.1    mhitch 		}
     99   1.1    mhitch 	}
    100   1.1    mhitch 
    101   1.1    mhitch 	/* get size of file? */
    102   1.1    mhitch 	if (fstat(io, &sb))
    103   1.1    mhitch 		goto err;
    104   1.1    mhitch 	/* allocate memory for file */
    105   1.1    mhitch 	ksize = sb.st_size;
    106   1.1    mhitch 	if (ksize == 0) {
    107   1.1    mhitch 		printf("Bad size, using 32K\n");	/* XXX debug? */
    108   1.1    mhitch 		ksize = 32 * 1024;
    109   1.1    mhitch 	}
    110   1.1    mhitch 	kp = alloc(ksize);
    111   1.1    mhitch 	if (kp == 0) {
    112   1.1    mhitch 		errno = ENOMEM;
    113   1.1    mhitch 		goto err;
    114   1.1    mhitch 	}
    115   1.1    mhitch 	/* read file into memory */
    116   1.1    mhitch 	if (read(io, kp, ksize) != ksize) {
    117   1.1    mhitch 		errno = ENOEXEC;
    118   1.1    mhitch 		goto freeall;
    119   1.1    mhitch 	}
    120   1.1    mhitch 	/* validate boot: DOS\0 and checksum? */
    121   1.1    mhitch 	if (strcmp(kp, "DOS") != 0 &&
    122   1.1    mhitch 	    (*(u_int32_t *)kp) != 0x424f4f54) {
    123   1.1    mhitch 		errno = ENOEXEC;
    124   1.1    mhitch 		goto freeall;
    125   1.1    mhitch 	}
    126   1.1    mhitch 	/* call boot+12(aio, sysbase); */
    127   1.1    mhitch 	close(io);
    128   1.1    mhitch 	startit(kp, aio, ConsoleBase);
    129   1.1    mhitch 	errno = -1;
    130   1.1    mhitch 
    131   1.1    mhitch freeall:
    132   1.6  christos 	dealloc(kp, ksize);
    133   1.1    mhitch err:
    134   1.1    mhitch 	printf("Error %ld\n", (long)errno);
    135   1.1    mhitch 	close(io);
    136   1.1    mhitch 
    137   1.1    mhitch 	timelimit = 10;
    138   1.1    mhitch 	(void)getchar();
    139   1.1    mhitch 	consclose();
    140   1.1    mhitch 	return 1;
    141   1.1    mhitch }
    142  1.10       rin 
    143  1.10       rin void
    144  1.10       rin twiddle(void)
    145  1.10       rin {
    146  1.10       rin 
    147  1.10       rin 	/* Keep silence; boot.amiga should be small enough. */
    148  1.10       rin }
    149