Home | History | Annotate | Line # | Download | only in boot
main.c revision 1.11
      1   1.1       is /*
      2  1.10       is  * $NetBSD: main.c,v 1.11 1999/11/28 22:10:47 is Exp $
      3   1.1       is  *
      4   1.1       is  *
      5  1.11       is  * Copyright (c) 1996,1999 Ignatios Souvatzis
      6   1.1       is  * Copyright (c) 1994 Michael L. Hitch
      7   1.1       is  * All rights reserved.
      8   1.1       is  *
      9   1.1       is  * Redistribution and use in source and binary forms, with or without
     10   1.1       is  * modification, are permitted provided that the following conditions
     11   1.1       is  * are met:
     12   1.1       is  * 1. Redistributions of source code must retain the above copyright
     13   1.1       is  *    notice, this list of conditions and the following disclaimer.
     14   1.1       is  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1       is  *    notice, this list of conditions and the following disclaimer in the
     16   1.1       is  *    documentation and/or other materials provided with the distribution.
     17   1.1       is  * 3. All advertising materials mentioning features or use of this software
     18   1.1       is  *    must display the following acknowledgement:
     19   1.1       is  *      This product includes software developed by Michael L. Hitch.
     20   1.1       is  * 4. The name of the authors may not be used to endorse or promote products
     21   1.1       is  *    derived from this software without specific prior written permission
     22   1.1       is  *
     23   1.1       is  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24   1.1       is  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25   1.1       is  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26   1.1       is  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27   1.1       is  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28   1.1       is  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29   1.1       is  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30   1.1       is  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31   1.1       is  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32   1.1       is  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33   1.1       is  *
     34   1.1       is  */
     35   1.1       is 
     36   1.1       is #include <sys/cdefs.h>
     37   1.1       is #include <sys/reboot.h>
     38   1.1       is #include <sys/types.h>
     39   1.1       is 
     40   1.1       is #include <sys/exec_aout.h>
     41   1.1       is 
     42   1.1       is #include <amiga/cfdev.h>
     43   1.1       is #include <amiga/memlist.h>
     44   1.1       is #include <include/cpu.h>
     45   1.1       is 
     46   1.2       is #include <saerrno.h>
     47   1.2       is #include <stand.h>
     48   1.1       is 
     49   1.1       is #include "libstubs.h"
     50   1.1       is #include "samachdep.h"
     51   1.1       is 
     52   1.4  mycroft #undef __LDPGSZ
     53   1.1       is #define __LDPGSZ 8192
     54   1.1       is #define __PGSZ 8192
     55   1.1       is 
     56   1.1       is #define DRACOREVISION	(*(u_int8_t *)0x02000009)
     57   1.1       is #define DRACOMMUMARGIN	0x200000
     58   1.1       is #define DRACOZ2OFFSET	0x3000000
     59   1.1       is #define DRACOZ2MAX	0x1000000
     60   1.1       is 
     61   1.1       is #define EXECMIN 36
     62   1.1       is 
     63   1.1       is void startit __P((void *, u_long, u_long, void *, u_long, u_long, int, void *,
     64   1.3   mhitch 	int, int, u_long, u_long, u_long, int));
     65  1.11       is int get_cpuid __P((u_int32_t *));
     66  1.11       is #ifdef PPCBOOTER
     67  1.11       is u_int16_t kickstart[];
     68  1.11       is size_t kicksize;
     69  1.11       is #else
     70   1.1       is void startit_end __P((void));
     71  1.11       is #endif
     72   1.1       is 
     73   1.1       is /*
     74   1.1       is  * Kernel startup interface version
     75   1.1       is  *	1:      first version of loadbsd
     76   1.1       is  *	2:      needs esym location passed in a4
     77   1.1       is  *	3:      load kernel image into fastmem rather than chipmem
     78   1.1       is  *	MAX:    highest version with backward compatibility.
     79   1.1       is  */
     80   1.1       is 
     81   1.1       is #define KERNEL_STARTUP_VERSION		3
     82   1.1       is #define KERNEL_STARTUP_VERSION_MAX	9
     83   1.1       is 
     84   1.1       is static long get_number(char **);
     85   1.1       is 
     86  1.11       is #define VERSION "2.2"
     87  1.10       is 
     88   1.9       is char default_command[] = "netbsd -ASn2";
     89   1.1       is 
     90   1.1       is int
     91  1.10       is pain(aio)
     92  1.10       is 	void *aio;
     93   1.1       is {
     94   1.1       is 	long int io = 0;
     95   1.1       is 	char linebuf[128];
     96   1.1       is 	char	*kernel_name = default_command;
     97   1.1       is 	char	*path = default_command;
     98   1.1       is 	int	boothowto = RB_AUTOBOOT;
     99   1.1       is 	u_int32_t cpuid = 0;
    100   1.1       is 	int	amiga_flags = 0;
    101   1.1       is 	u_int32_t I_flag = 0;
    102   1.1       is 	int	k_flag = 0;
    103   1.1       is 	int	p_flag = 0;
    104   1.1       is 	int	m_value = 0;
    105   1.1       is 	int	S_flag = 0;
    106   1.1       is 	int	t_flag = 0;
    107   1.1       is 	long stringsz;
    108   1.1       is 
    109   1.1       is 	u_int32_t fmem = 0x0;
    110   1.1       is 	int	fmemsz = 0x0;
    111   1.1       is 	int	cmemsz = 0x0;
    112   1.1       is 	int	eclock = SysBase->EClockFreq;
    113   1.1       is 	/* int	skip_chipmem = 0; */
    114   1.1       is 
    115   1.1       is 	void (*start_it)(void *, u_long, u_long, void *, u_long, u_long, int,
    116  1.11       is 	    void *, int, int, u_long, u_long, u_long, int);
    117   1.1       is 
    118   1.1       is 	caddr_t kp;
    119   1.1       is 	u_int16_t *kvers;
    120   1.9       is 	struct exec ehs;
    121   1.1       is 	int	textsz, ksize;
    122   1.1       is 	void	*esym = 0;
    123   1.1       is 	int32_t *nkcd;
    124   1.1       is 	struct cfdev *cd, *kcd;
    125   1.1       is 	struct boot_memseg *kmemseg;
    126   1.1       is 	struct boot_memseg *memseg;
    127   1.1       is 	struct MemHead *mh;
    128   1.1       is 	u_int32_t from, size, vfrom, vsize;
    129   1.1       is 	int contflag, mapped1to1;
    130   1.1       is 
    131   1.1       is 	int ncd, nseg;
    132   1.1       is 	char c;
    133   1.1       is 
    134   1.1       is 	extern u_int16_t timelimit;
    135   1.1       is 
    136   1.3   mhitch 	extern u_int32_t aio_base;
    137   1.3   mhitch 
    138  1.10       is 	xdinit(aio);
    139  1.10       is 
    140  1.10       is 	if (consinit())
    141  1.10       is 		return(1);
    142  1.10       is 
    143   1.1       is 	/*
    144   1.1       is 	 * we need V36 for: EClock, RDB Bootblocks, CacheClearU
    145   1.1       is 	 */
    146   1.1       is 
    147   1.1       is 	if (SysBase->LibNode.Version < EXECMIN) {
    148   1.1       is 		printf("Exec V%ld, need V%ld\n",
    149   1.1       is 		    (long)SysBase->LibNode.Version, (long)EXECMIN);
    150   1.1       is 		goto out;
    151   1.1       is 	}
    152   1.1       is 
    153  1.11       is #ifdef PPCBOOTER
    154  1.11       is 	printf("\2337mNetBSD/AmigaPPC bootblock " VERSION "\2330m\n%s :- ",
    155  1.11       is 		kernel_name);
    156  1.11       is #else
    157  1.10       is 	printf("\2337mNetBSD/Amiga bootblock " VERSION "\2330m\n%s :- ",
    158  1.10       is 		kernel_name);
    159  1.11       is #endif
    160   1.1       is 
    161   1.1       is 	timelimit = 3;
    162   1.1       is 	gets(linebuf);
    163   1.1       is 
    164   1.1       is 	if (*linebuf == 'q')
    165   1.1       is 		return 1;
    166   1.1       is 
    167   1.1       is 	if (*linebuf)
    168   1.1       is 		path = linebuf;
    169   1.1       is 
    170   1.1       is 	/*
    171   1.1       is 	 * parse boot command for path name and process any options
    172   1.1       is 	 */
    173   1.1       is 	while ((c = *path)) {
    174   1.1       is 		while (c == ' ')
    175   1.1       is 			c = *++path;
    176   1.1       is 		if (c == '-') {
    177   1.1       is 			while ((c = *++path) && c != ' ') {
    178   1.1       is 				switch (c) {
    179   1.1       is 				case 'a':	/* multi-user state */
    180   1.1       is 					boothowto &= ~RB_SINGLE;
    181   1.1       is 					break;
    182   1.1       is 				case 'b':	/* ask for root device */
    183   1.1       is 					boothowto |= RB_ASKNAME;
    184   1.1       is 					break;
    185   1.1       is 				case 'c':	/* force machine model */
    186   1.1       is 					cpuid = get_number(&path) << 16;
    187   1.1       is 					break;
    188   1.1       is 				case 'k':	/* Reserve first 4M fastmem */
    189   1.1       is 					k_flag++;
    190   1.1       is 					break;
    191   1.1       is 				case 'm':	/* Force fastmem size */
    192   1.1       is 					m_value = get_number(&path) * 1024;
    193   1.1       is 					break;
    194   1.1       is 				case 'n':	/* non-contiguous memory */
    195   1.1       is 					amiga_flags |=
    196   1.1       is 					    (get_number(&path) & 3) << 1;
    197   1.1       is 					break;
    198   1.1       is 				case 'p':	/* Select fastmem by priority */
    199   1.1       is 					p_flag++;
    200   1.1       is 					break;
    201   1.1       is 				case 's':	/* single-user state */
    202   1.1       is 					boothowto |= RB_SINGLE;
    203   1.1       is 					break;
    204   1.1       is 				case 't':	/* test flag */
    205   1.1       is 					t_flag = 1;
    206   1.1       is 					break;
    207   1.1       is 				case 'A':	/* enable AGA modes */
    208   1.1       is 					amiga_flags |= 1;
    209   1.1       is 					break;
    210   1.1       is 				case 'D':	/* enter Debugger */
    211   1.1       is 					boothowto |= RB_KDB;
    212   1.1       is 					break;
    213   1.1       is 				case 'I':	/* inhibit sync negotiation */
    214   1.1       is 					I_flag = get_number(&path);
    215   1.1       is 					break;
    216   1.1       is 				case 'K':	/* remove 1st 4MB fastmem */
    217   1.1       is 					break;
    218   1.1       is 				case 'S':	/* include debug symbols */
    219   1.1       is 					S_flag = 1;
    220   1.1       is 					break;
    221   1.1       is 				}
    222   1.1       is 			}
    223   1.1       is 		} else {
    224   1.1       is 			kernel_name = path;
    225   1.1       is 			while ((c = *++path) && c != ' ')
    226   1.1       is 				;
    227   1.1       is 			if (c)
    228   1.1       is 				*path++ = 0;
    229   1.1       is 		}
    230   1.1       is 	}
    231   1.1       is 	while ((c = *kernel_name) && c == ' ')
    232   1.1       is 		++kernel_name;
    233   1.1       is 	path = kernel_name;
    234   1.1       is 	while ((c = *path) && c != ' ')
    235   1.1       is 		++path;
    236   1.1       is 	if (c)
    237   1.1       is 		*path = 0;
    238   1.1       is 
    239   1.1       is 	if (get_cpuid(&cpuid))
    240   1.1       is 		goto out;
    241   1.1       is 
    242   1.1       is 	ExpansionBase = OpenLibrary("expansion.library", 0);
    243   1.1       is 	if (!ExpansionBase) {
    244   1.1       is 		printf("can't open %s\n", "expansion.library");
    245   1.1       is 		return 1;
    246   1.1       is 	}
    247   1.1       is 
    248   1.1       is 	for (ncd=0, cd=0; (cd = FindConfigDev(cd, -1, -1)); ncd++)
    249   1.1       is 		/* nothing */;
    250   1.1       is 
    251   1.1       is 	/* find memory list */
    252   1.1       is 
    253   1.1       is 	memseg = (struct boot_memseg *)alloc(16*sizeof(struct boot_memseg));
    254   1.1       is 
    255   1.1       is 	/* Forbid(); */
    256   1.1       is 
    257   1.1       is 	nseg = 0;
    258   1.1       is 	mh = SysBase->MemLst;
    259   1.1       is 	vfrom = mh->Lower & -__PGSZ;
    260   1.5  mycroft 	vsize = (mh->Upper & -__PGSZ) - vfrom;
    261   1.1       is 	contflag = mapped1to1 = 0;
    262   1.1       is 
    263   1.1       is 	do {
    264   1.1       is 		size = vsize;
    265   1.1       is 
    266   1.1       is 		if (SysBase->LibNode.Version > 36) {
    267   1.1       is 			from = CachePreDMA(vfrom, &size, contflag);
    268   1.1       is 			contflag = DMAF_Continue;
    269   1.1       is 			mapped1to1 = (from == vfrom);
    270   1.1       is 			vsize -= size;
    271   1.1       is 			vfrom += size;
    272   1.1       is 		} else {
    273   1.1       is 			from = vfrom;
    274   1.6  mycroft 			mapped1to1 = 1;
    275   1.1       is 			vsize = 0;
    276   1.1       is 		}
    277   1.1       is 
    278   1.5  mycroft #ifdef DEBUG_MEMORY_LIST
    279   1.1       is 		printf("%lx %lx %lx %ld/%lx %lx\n",
    280   1.1       is 			(long)from, (long)size,
    281   1.1       is 			(long)mh->Attribs, (long)mh->Pri,
    282   1.1       is 			(long)vfrom, (long)vsize);
    283   1.1       is #endif
    284   1.1       is 		/* Insert The Evergrowing Kludge List Here: */
    285   1.1       is 
    286   1.1       is 		/* a) dont load kernel over DraCo MMU table */
    287   1.1       is 
    288   1.1       is 		if (((cpuid >> 24) == 0x7D) &&
    289   1.1       is 		    ((from & -DRACOMMUMARGIN) == 0x40000000) &&
    290   1.1       is 		    (size >= DRACOMMUMARGIN)) {
    291   1.1       is 
    292   1.1       is 			memseg[nseg].ms_start = from & -DRACOMMUMARGIN;
    293   1.1       is 			memseg[nseg].ms_size = DRACOMMUMARGIN;
    294   1.1       is 			memseg[nseg].ms_attrib = mh->Attribs;
    295   1.1       is 			memseg[nseg].ms_pri = mh->Pri;
    296   1.1       is 
    297   1.1       is 			size -= DRACOMMUMARGIN - (from & (DRACOMMUMARGIN - 1));
    298   1.1       is 			from += DRACOMMUMARGIN - (from & (DRACOMMUMARGIN - 1));
    299   1.1       is 			++nseg;
    300   1.1       is 		}
    301   1.1       is 
    302   1.1       is 		if ((mh->Attribs & (MEMF_CHIP|MEMF_FAST)) == MEMF_CHIP) {
    303   1.1       is 			size += from;
    304   1.1       is 			cmemsz = size;;
    305   1.1       is 			from = 0;
    306   1.1       is 		} else if ((fmemsz < size) && mapped1to1) {
    307   1.1       is 			fmem = from;
    308   1.1       is 			fmemsz = size;
    309   1.1       is 		}
    310   1.1       is 
    311   1.1       is 		memseg[nseg].ms_start = from;
    312   1.1       is 		memseg[nseg].ms_size = size;
    313   1.1       is 		memseg[nseg].ms_attrib = mh->Attribs;
    314   1.1       is 		memseg[nseg].ms_pri = mh->Pri;
    315   1.1       is 
    316   1.1       is 		if (vsize == 0) {
    317   1.1       is 			mh = mh->next;
    318   1.1       is 			contflag = 0;
    319   1.1       is 			if (mh->next) {
    320   1.1       is 				vfrom = mh->Lower & -__PGSZ;
    321   1.5  mycroft 				vsize = (mh->Upper & -__PGSZ) - vfrom;
    322   1.1       is 			}
    323   1.1       is 		}
    324   1.1       is 	} while ((++nseg <= 16) && vsize);
    325   1.1       is 
    326   1.1       is 	/* Permit(); */
    327   1.1       is 
    328   1.8   chopps 	if (k_flag) {
    329   1.8   chopps 		fmem += 4*1024*1024;
    330   1.8   chopps 		fmemsz -= 4*1024*1024;
    331   1.8   chopps 	}
    332   1.8   chopps 	if (m_value && m_value < fmemsz)
    333   1.8   chopps 		fmemsz = m_value;
    334   1.8   chopps 
    335   1.1       is 	printf("Loading %s: ", kernel_name);
    336   1.1       is 	io = open(kernel_name, 0);
    337   1.1       is 	if (io < 0)
    338   1.1       is 		goto err;
    339   1.1       is 
    340   1.9       is 	if (read(io, &ehs, sizeof(ehs)) != sizeof(ehs)) {
    341   1.1       is 		errno = ENOEXEC;
    342   1.1       is 		goto err;
    343   1.1       is 	}
    344   1.1       is 
    345  1.11       is #ifdef PPCBOOTER
    346  1.11       is 	/* XXX to be done */
    347  1.11       is #else
    348   1.9       is 	if ((N_GETMAGIC(ehs) != NMAGIC) || (N_GETMID(ehs) != MID_M68K)) {
    349   1.1       is 		errno = ENOEXEC;
    350   1.1       is 		goto err;
    351   1.1       is 	}
    352  1.11       is #endif
    353   1.1       is 
    354   1.9       is 	textsz = (ehs.a_text + __LDPGSZ - 1) & (-__LDPGSZ);
    355   1.1       is 	esym = 0;
    356   1.1       is 
    357   1.9       is 	ksize = textsz + ehs.a_data + ehs.a_bss
    358   1.1       is 	    + sizeof(*nkcd) + ncd*sizeof(*cd)
    359   1.1       is 	    + sizeof(*nkcd) + nseg * sizeof(struct boot_memseg);
    360   1.1       is 
    361   1.9       is 	if (S_flag && ehs.a_syms) {
    362   1.9       is 		if (lseek(io, ehs.a_text+ ehs.a_data+ ehs.a_syms, SEEK_CUR)
    363   1.1       is 		    <= 0
    364   1.1       is 		    || read(io, &stringsz, 4) != 4
    365   1.9       is 		    || lseek(io, sizeof(ehs), SEEK_SET) < 0)
    366   1.1       is 			goto err;
    367   1.9       is 		ksize += ehs.a_syms + 4 + ((stringsz + 3) & ~3);
    368   1.1       is 	}
    369  1.11       is #ifdef PPCBOOTER
    370  1.11       is 	kp = alloc(ksize);
    371  1.11       is #else
    372   1.1       is 	kp = alloc(ksize + 256 + ((u_char *)startit_end - (u_char *)startit));
    373  1.11       is #endif
    374   1.1       is 	if (kp == 0) {
    375   1.1       is 		errno = ENOMEM;
    376   1.1       is 		goto err;
    377   1.1       is 	}
    378   1.1       is 
    379   1.9       is 	printf("%ld", ehs.a_text);
    380  1.11       is 	if (ehs.a_text && (read(io, kp, ehs.a_text) != ehs.a_text))
    381   1.1       is 		goto err;
    382   1.1       is 
    383   1.9       is 	printf("+%ld", ehs.a_data);
    384  1.11       is 	if (ehs.a_data && (read(io, kp + textsz, ehs.a_data) != ehs.a_data))
    385   1.1       is 		goto err;
    386   1.1       is 
    387   1.9       is 	printf("+%ld", ehs.a_bss);
    388   1.1       is 
    389  1.11       is         nkcd = (int *)(kp + textsz + ehs.a_data + ehs.a_bss);
    390  1.11       is #ifndef PPCBOOTER
    391   1.9       is 	kvers = (u_short *)(kp + ehs.a_entry - 2);
    392   1.1       is 
    393   1.1       is 	if (*kvers > KERNEL_STARTUP_VERSION_MAX && *kvers != 0x4e73) {
    394   1.1       is                 printf("\nnewer bootblock required: %ld\n", (long)*kvers);
    395   1.1       is 		goto freeall;
    396   1.1       is 	}
    397   1.7   chopps 	if (*kvers < KERNEL_STARTUP_VERSION || *kvers == 0x4e73) {
    398   1.7   chopps                 printf("\nkernel too old for bootblock\n");
    399   1.7   chopps 		goto freeall;
    400   1.7   chopps 	}
    401   1.1       is #if 0
    402   1.1       is         if (*kvers > KERNEL_STARTUP_VERSION)
    403   1.1       is 		printf("\nKernel V%ld newer than bootblock V%ld\n",
    404   1.1       is 		    (long)*kvers, (long)KERNEL_STARTUP_VERSION);
    405   1.1       is #endif
    406   1.9       is         if (*kvers != 0x4e73 && *kvers > 1 && S_flag && ehs.a_syms) {
    407   1.9       is                 *nkcd++ = ehs.a_syms;
    408   1.9       is 		printf("+[%ld", ehs.a_syms);
    409   1.9       is                 if (read(io, (char *)nkcd, ehs.a_syms) != ehs.a_syms)
    410   1.1       is 			goto err;
    411   1.9       is                 nkcd = (int *)((char *)nkcd + ehs.a_syms);
    412   1.1       is 		printf("+%ld]", stringsz);
    413   1.1       is                 if (read(io, (char *)nkcd, stringsz) != stringsz)
    414   1.1       is 			goto err;
    415   1.1       is                 nkcd = (int*)((char *)nkcd + ((stringsz + 3) & ~3));
    416   1.9       is                 esym = (char *)(textsz + ehs.a_data + ehs.a_bss
    417   1.9       is                     + ehs.a_syms + 4 + ((stringsz + 3) & ~3));
    418   1.1       is         }
    419  1.11       is #endif
    420   1.1       is 	putchar('\n');
    421   1.1       is 
    422   1.1       is 	*nkcd = ncd;
    423   1.1       is 	kcd = (struct cfdev *)(nkcd + 1);
    424   1.1       is 
    425   1.1       is 	while ((cd = FindConfigDev(cd, -1, -1))) {
    426   1.1       is 		*kcd = *cd;
    427  1.11       is #ifndef PPCBOOTER
    428   1.1       is 		if (((cpuid >> 24) == 0x7D) &&
    429   1.1       is 		    ((u_long)kcd->addr < 0x1000000)) {
    430   1.1       is 			kcd->addr += 0x3000000;
    431   1.1       is 		}
    432  1.11       is #endif
    433   1.1       is 		++kcd;
    434   1.1       is 	}
    435   1.1       is 
    436   1.1       is 	nkcd = (u_int32_t *)kcd;
    437   1.1       is 	*nkcd = nseg;
    438   1.1       is 
    439   1.1       is 	kmemseg = (struct boot_memseg *)(nkcd + 1);
    440   1.1       is 
    441   1.1       is 	while (nseg-- > 0)
    442   1.1       is 		*kmemseg++ = *memseg++;
    443   1.1       is 
    444  1.11       is #ifdef PPCBOOTER
    445  1.11       is 	/*
    446  1.11       is 	 * we use the ppc starter...
    447  1.11       is 	 */
    448  1.11       is 	start_it = startit;
    449  1.11       is #else
    450   1.7   chopps 	/*
    451   1.8   chopps 	 * Copy startup code to end of kernel image and set start_it.
    452   1.7   chopps 	 */
    453   1.7   chopps 	memcpy(kp + ksize + 256, (char *)startit,
    454   1.7   chopps 	    (char *)startit_end - (char *)startit);
    455   1.7   chopps 	CacheClearU();
    456   1.7   chopps 	(caddr_t)start_it = kp + ksize + 256;
    457  1.11       is #endif
    458   1.7   chopps 	printf("*** Loading from %08lx to Fastmem %08lx ***\n",
    459   1.7   chopps 	    (u_long)kp, (u_long)fmem);
    460   1.7   chopps 	/* sleep(2); */
    461   1.1       is 
    462   1.1       is #if 0
    463   1.1       is 	printf("would start(kp=0x%lx, ksize=%ld, entry=0x%lx,\n"
    464   1.1       is 		"fmem=0x%lx, fmemsz=%ld, cmemsz=%ld\n"
    465   1.1       is 		"boothow=0x%lx, esym=0x%lx, cpuid=0x%lx, eclock=%ld\n"
    466   1.7   chopps 		"amigaflags=0x%lx, I_flags=0x%lx, ok?\n",
    467   1.9       is 	    (u_long)kp, (u_long)ksize, ehs.a_entry,
    468   1.1       is 	    (u_long)fmem, (u_long)fmemsz, (u_long)cmemsz,
    469   1.1       is 	    (u_long)boothowto, (u_long)esym, (u_long)cpuid, (u_long)eclock,
    470   1.7   chopps 	    (u_long)amiga_flags, (u_long)I_flag);
    471   1.1       is #endif
    472   1.5  mycroft #ifdef DEBUG_MEMORY_LIST
    473   1.5  mycroft 	timelimit = 0;
    474   1.5  mycroft #else
    475   1.1       is 	timelimit = 2;
    476   1.5  mycroft #endif
    477   1.1       is 	(void)getchar();
    478   1.1       is 
    479  1.11       is #ifdef PPCBOOTER
    480  1.11       is 	startit
    481  1.11       is #else
    482  1.11       is 	start_it
    483  1.11       is #endif
    484  1.11       is 		(kp, ksize, ehs.a_entry, (void *)fmem, fmemsz, cmemsz,
    485   1.3   mhitch 	    boothowto, esym, cpuid, eclock, amiga_flags, I_flag,
    486   1.7   chopps 	    aio_base >> 9, 1);
    487   1.1       is 	/*NOTREACHED*/
    488   1.1       is 
    489   1.1       is freeall:
    490   1.1       is 	free(kp, ksize);
    491   1.1       is err:
    492   1.1       is 	printf("\nError %ld\n", (long)errno);
    493   1.1       is 	close(io);
    494   1.1       is out:
    495   1.1       is 	timelimit = 10;
    496   1.1       is 	(void)getchar();
    497   1.1       is 	return 1;
    498   1.1       is }
    499   1.1       is 
    500   1.1       is static
    501   1.1       is long get_number(ptr)
    502   1.1       is char **ptr;
    503   1.1       is {
    504   1.1       is 	long value = 0;
    505   1.1       is 	int base = 10;
    506   1.1       is 	char *p = *ptr;
    507   1.1       is 	char c;
    508   1.1       is 	char sign = 0;
    509   1.1       is 
    510   1.1       is 	c = *++p;
    511   1.1       is 	while (c == ' ')
    512   1.1       is 		c = *++p;
    513   1.1       is 	if (c == '-') {
    514   1.1       is 		sign = -1;
    515   1.1       is 		c = *++p;
    516   1.1       is 	}
    517   1.1       is 	if (c == '$') {
    518   1.1       is 		base = 16;
    519   1.1       is 		c = *++p;
    520   1.1       is 	} else if (c == '0') {
    521   1.1       is 		c = *++p;
    522   1.1       is 		if ((c & 0xdf) == 'X') {
    523   1.1       is 			base = 16;
    524   1.1       is 			c = *++p;
    525   1.1       is 		}
    526   1.1       is 	}
    527   1.1       is 	while (c) {
    528   1.1       is 		if (c >= '0' && c <= '9')
    529   1.1       is 			c -= '0';
    530   1.1       is 		else {
    531   1.1       is 			c = (c & 0xdf) - 'A' + 10;
    532   1.1       is 			if (base != 16 || c < 10 || c > 15)
    533   1.1       is 				break;
    534   1.1       is 		}
    535   1.1       is 		value = value * base + c;
    536   1.1       is 		c = *++p;
    537   1.1       is 	}
    538   1.1       is 	*ptr = p - 1;
    539   1.1       is #ifdef TEST
    540   1.1       is 	fprintf(stderr, "get_number: got %c0x%x",
    541   1.1       is 	    sign ? '-' : '+', value);
    542   1.1       is #endif
    543   1.1       is 	return (sign ? -value : value);
    544   1.1       is }
    545   1.1       is 
    546   1.1       is /*
    547   1.1       is  * Try to determine the machine ID by searching the resident module list
    548   1.1       is  * for modules only present on specific machines.  (Thanks, Bill!)
    549   1.1       is  */
    550   1.1       is 
    551   1.1       is int
    552   1.1       is get_cpuid(cpuid)
    553   1.1       is 	u_int32_t *cpuid;
    554   1.1       is {
    555   1.1       is 	*cpuid |= SysBase->AttnFlags;	/* get FPU and CPU flags */
    556   1.1       is 	if (*cpuid & 0xffff0000) {
    557   1.1       is 		if ((*cpuid >> 24) == 0x7D)
    558   1.1       is 			return 0;
    559   1.1       is 
    560   1.1       is 		switch (*cpuid >> 16) {
    561   1.1       is 		case 500:
    562   1.1       is 		case 600:
    563   1.1       is 		case 1000:
    564   1.1       is 		case 1200:
    565   1.1       is 		case 2000:
    566   1.1       is 		case 3000:
    567   1.1       is 		case 4000:
    568   1.1       is 			return 0;
    569   1.1       is 		default:
    570   1.1       is 			printf("Amiga %ld ???\n",
    571   1.1       is 			    (long)(*cpuid >> 16));
    572   1.1       is 			return(1);
    573   1.1       is 		}
    574   1.1       is 	}
    575   1.1       is 	if (FindResident("A4000 Bonus") || FindResident("A4000 bonus")
    576   1.1       is 	    || FindResident("A1000 Bonus"))
    577   1.1       is 		*cpuid |= 4000 << 16;
    578   1.1       is 	else if (FindResident("A3000 Bonus") || FindResident("A3000 bonus")
    579   1.1       is 	    || (SysBase->LibNode.Version == 36))
    580   1.1       is 		*cpuid |= 3000 << 16;
    581   1.1       is 	else if (OpenResource("card.resource")) {
    582   1.1       is 		/* Test for AGA? */
    583   1.1       is 		*cpuid |= 1200 << 16;
    584   1.1       is 	} else if (OpenResource("draco.resource")) {
    585   1.1       is 		*cpuid |= (32000 | DRACOREVISION) << 16;
    586   1.1       is 	}
    587   1.1       is 	/*
    588   1.1       is 	 * Nothing found, it's probably an A2000 or A500
    589   1.1       is 	 */
    590   1.1       is 	if ((*cpuid >> 16) == 0)
    591   1.1       is 		*cpuid |= 2000 << 16;
    592   1.1       is 
    593   1.1       is 	return 0;
    594   1.1       is }
    595