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