Home | History | Annotate | Line # | Download | only in loadbsd
loadbsd.c revision 1.16
      1  1.16  leo /*	$NetBSD: loadbsd.c,v 1.16 2001/09/27 14:29:22 leo Exp $	*/
      2   1.1  leo 
      3   1.1  leo /*
      4   1.1  leo  * Copyright (c) 1995 L. Weppelman
      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 Leo Weppelman.
     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 /*
     34   1.1  leo  * NetBSD loader for the Atari-TT.
     35   1.1  leo  */
     36   1.1  leo 
     37  1.16  leo #include "exec_elf.h"
     38   1.1  leo #include <a_out.h>
     39   1.1  leo #include <fcntl.h>
     40  1.10  leo #include <stdio.h>
     41   1.1  leo #include <osbind.h>
     42   1.1  leo #include <stdarg.h>
     43  1.10  leo #include <stdlib.h>
     44  1.10  leo #include <string.h>
     45  1.10  leo #include <unistd.h>
     46  1.10  leo #include "libtos.h"
     47   1.1  leo #include "loader.h"
     48   1.1  leo 
     49  1.15  leo #ifdef COMPRESSED_READ
     50  1.15  leo #define	open	copen
     51  1.15  leo #define	read	cread
     52  1.15  leo #define	lseek	clseek
     53  1.15  leo #define	close	cclose
     54  1.15  leo #endif /* COMPRESSED_READ */
     55  1.15  leo 
     56   1.1  leo char	*Progname;		/* How are we called		*/
     57  1.10  leo int	d_flag  = 0;		/* Output debugging output?	*/
     58  1.10  leo int	h_flag  = 0;		/* show help			*/
     59  1.16  leo int	N_flag  = 0;		/* No symbols?			*/
     60  1.10  leo int	s_flag  = 0;		/* St-ram only			*/
     61  1.10  leo int	t_flag  = 0;		/* Just test, do not execute	*/
     62  1.10  leo int	v_flag  = 0;		/* show version			*/
     63   1.1  leo 
     64  1.16  leo const char version[] = "$Revision: 1.16 $";
     65   1.1  leo 
     66   1.1  leo /*
     67   1.1  leo  * Default name of kernel to boot, large enough to patch
     68   1.1  leo  */
     69  1.10  leo char	kname[80] = "n:/netbsd";
     70  1.10  leo 
     71  1.10  leo static struct kparamb kparam;
     72   1.1  leo 
     73  1.10  leo void help  PROTO((void));
     74  1.10  leo void usage PROTO((void));
     75  1.16  leo int  aout_load PROTO((int));
     76  1.16  leo int  elf_load PROTO((int));
     77  1.10  leo void get_sys_info PROTO((void));
     78  1.10  leo void start_kernel PROTO((void));
     79   1.1  leo 
     80  1.16  leo #define ELFMAGIC	((ELFMAG0 << 24) | (ELFMAG1 << 16) | \
     81  1.16  leo 				(ELFMAG2 << 8) | ELFMAG3)
     82  1.10  leo int
     83  1.10  leo main(argc, argv)
     84   1.1  leo int	argc;
     85   1.1  leo char	**argv;
     86   1.1  leo {
     87   1.1  leo 	/*
     88   1.1  leo 	 * Option parsing
     89   1.1  leo 	 */
     90   1.1  leo 	extern	int	optind;
     91   1.1  leo 	extern	char	*optarg;
     92   1.1  leo 	int		ch;
     93   1.1  leo 	int		fd;
     94   1.1  leo 
     95  1.10  leo 	init_toslib(argv[0]);
     96   1.1  leo 	Progname = argv[0];
     97   1.1  leo 
     98   1.1  leo 	kparam.boothowto = RB_SINGLE;
     99   1.1  leo 
    100  1.16  leo 	while ((ch = getopt(argc, argv, "abdDhNstVwo:S:T:")) != -1) {
    101  1.10  leo 		switch (ch) {
    102   1.1  leo 		case 'a':
    103   1.1  leo 			kparam.boothowto &= ~(RB_SINGLE);
    104   1.1  leo 			kparam.boothowto |= RB_AUTOBOOT;
    105   1.1  leo 			break;
    106   1.1  leo 		case 'b':
    107   1.1  leo 			kparam.boothowto |= RB_ASKNAME;
    108   1.1  leo 			break;
    109   1.1  leo 		case 'd':
    110   1.1  leo 			kparam.boothowto |= RB_KDB;
    111   1.1  leo 			break;
    112   1.3  leo 		case 'D':
    113   1.3  leo 			d_flag = 1;
    114   1.3  leo 			break;
    115  1.10  leo 		case 'h':
    116  1.10  leo 			h_flag = 1;
    117  1.10  leo 			break;
    118  1.16  leo 		case 'N':
    119  1.16  leo 			N_flag = 1;
    120  1.16  leo 			break;
    121  1.10  leo 		case 'o':
    122  1.10  leo 			redirect_output(optarg);
    123  1.10  leo 			break;
    124   1.3  leo 		case 's':
    125   1.3  leo 			s_flag = 1;
    126   1.3  leo 			break;
    127   1.3  leo 		case 'S':
    128   1.3  leo 			kparam.stmem_size = atoi(optarg);
    129   1.3  leo 			break;
    130   1.1  leo 		case 't':
    131   1.1  leo 			t_flag = 1;
    132   1.1  leo 			break;
    133   1.5  leo 		case 'T':
    134   1.5  leo 			kparam.ttmem_size = atoi(optarg);
    135   1.5  leo 			break;
    136  1.10  leo 		case 'V':
    137  1.10  leo 			v_flag = 1;
    138  1.10  leo 			break;
    139  1.10  leo 		case 'w':
    140  1.10  leo 			set_wait_for_key();
    141   1.1  leo 			break;
    142   1.1  leo 		default:
    143   1.1  leo 			usage();
    144   1.1  leo 		}
    145   1.1  leo 	}
    146   1.1  leo 	argc -= optind;
    147   1.1  leo 	argv += optind;
    148  1.10  leo 	if (argc == 1)
    149   1.1  leo 		strcpy(kname, argv[0]);
    150   1.1  leo 
    151  1.10  leo 	if (h_flag)
    152  1.10  leo 		help();
    153  1.10  leo 	if (v_flag)
    154  1.10  leo 		eprintf("%s\r\n", version);
    155  1.10  leo 
    156   1.1  leo 	/*
    157   1.2  leo 	 * Get system info to pass to NetBSD
    158   1.1  leo 	 */
    159   1.1  leo 	get_sys_info();
    160   1.1  leo 
    161   1.1  leo 	/*
    162   1.1  leo 	 * Find the kernel to boot and read it's exec-header
    163   1.1  leo 	 */
    164  1.10  leo 	if ((fd = open(kname, O_RDONLY)) < 0)
    165  1.10  leo 		fatal(-1, "Cannot open kernel '%s'", kname);
    166  1.16  leo 	if (elf_load(fd) == 0)
    167  1.16  leo 		if (aout_load(fd) == 0)
    168  1.16  leo 			fatal(-1, "Not an ELF or NMAGIC file '%s'", kname);
    169  1.16  leo 	close(fd);
    170  1.16  leo 
    171  1.16  leo 	if (d_flag) {
    172  1.16  leo 	    eprintf("\r\nKernel info:\r\n");
    173  1.16  leo 	    eprintf("Kernel loadaddr\t: 0x%08x\r\n", kparam.kp);
    174  1.16  leo 	    eprintf("Kernel size\t: %10d bytes\r\n", kparam.ksize);
    175  1.16  leo 	    eprintf("Kernel entry\t: 0x%08x\r\n", kparam.entry);
    176  1.16  leo 	    eprintf("Kernel esym\t: 0x%08x\r\n", kparam.esym_loc);
    177  1.16  leo 	}
    178  1.16  leo 
    179  1.16  leo 	if (!t_flag)
    180  1.16  leo 		start_kernel();
    181  1.16  leo 		/* NOT REACHED */
    182  1.16  leo 
    183  1.16  leo 	eprintf("Kernel '%s' was loaded OK\r\n", kname);
    184  1.16  leo 	xexit(0);
    185  1.16  leo 	return 0;
    186  1.16  leo }
    187  1.16  leo 
    188  1.16  leo int
    189  1.16  leo aout_load(fd)
    190  1.16  leo int				fd;
    191  1.16  leo {
    192  1.16  leo 	long		textsz, stringsz;
    193  1.16  leo 	struct exec	ehdr;
    194  1.16  leo 
    195  1.16  leo 	lseek(fd, (off_t)0, SEEK_SET);
    196  1.10  leo 	if (read(fd, (char *)&ehdr, sizeof(ehdr)) != sizeof(ehdr))
    197  1.16  leo 		return 0;
    198  1.14  leo 
    199  1.10  leo 	if (N_MAGIC(ehdr) != NMAGIC)
    200  1.16  leo 		return 0;
    201   1.1  leo 
    202   1.1  leo 	/*
    203   1.1  leo 	 * Extract various sizes from the kernel executable
    204   1.1  leo 	 */
    205   1.1  leo 	textsz          = (ehdr.a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1);
    206   1.1  leo 	kparam.esym_loc = 0;
    207   1.1  leo 	kparam.ksize    = textsz + ehdr.a_data + ehdr.a_bss;
    208   1.1  leo 	kparam.entry    = ehdr.a_entry;
    209   1.1  leo 
    210  1.16  leo 	if (!N_flag && ehdr.a_syms) {
    211  1.15  leo 	  if (lseek(fd,ehdr.a_text+ehdr.a_data+ehdr.a_syms+sizeof(ehdr),0)
    212  1.15  leo 									<= 0)
    213  1.10  leo 		fatal(-1, "Cannot seek to string table in '%s'", kname);
    214  1.10  leo 	  if (read(fd, (char *)&stringsz, sizeof(long)) != sizeof(long))
    215  1.10  leo 		fatal(-1, "Cannot read string-table size");
    216  1.10  leo 	  if (lseek(fd, sizeof(ehdr), 0) <= 0)
    217  1.10  leo 		fatal(-1, "Cannot seek back to text start");
    218   1.1  leo 	  kparam.ksize += ehdr.a_syms + sizeof(long) + stringsz;
    219   1.1  leo 	}
    220   1.1  leo 
    221  1.10  leo 	if ((kparam.kp = (u_char *)malloc(kparam.ksize)) == NULL)
    222  1.10  leo 		fatal(-1, "Cannot malloc kernel image space");
    223   1.1  leo 
    224   1.1  leo 	/*
    225   1.1  leo 	 * Read text & data, clear bss
    226   1.1  leo 	 */
    227  1.10  leo 	if ((read(fd, (char *)kparam.kp, ehdr.a_text) != ehdr.a_text)
    228  1.15  leo 	    ||(read(fd,(char *)(kparam.kp+textsz),ehdr.a_data) != ehdr.a_data))
    229  1.10  leo 		fatal(-1, "Unable to read kernel image\n");
    230   1.1  leo 	memset(kparam.kp + textsz + ehdr.a_data, 0, ehdr.a_bss);
    231   1.1  leo 
    232   1.1  leo 	/*
    233   1.1  leo 	 * Read symbol and string table
    234   1.1  leo 	 */
    235  1.16  leo 	if (!N_flag && ehdr.a_syms) {
    236  1.14  leo 	    long	*p;
    237   1.1  leo 
    238  1.14  leo 	    p = (long *)(kparam.kp + textsz + ehdr.a_data + ehdr.a_bss);
    239  1.14  leo 	    *p++ = ehdr.a_syms;
    240  1.14  leo 	    if (read(fd, (char *)p, ehdr.a_syms) != ehdr.a_syms)
    241  1.14  leo 		fatal(-1, "Cannot read symbol table\n");
    242  1.14  leo 	    p = (long *)((char *)p + ehdr.a_syms);
    243  1.14  leo 	    if (read(fd, (char *)p, stringsz) != stringsz)
    244  1.14  leo 		fatal(-1, "Cannot read string table\n");
    245  1.14  leo 	    kparam.esym_loc = (long)((char *)p-(char *)kparam.kp +stringsz);
    246   1.1  leo 	}
    247  1.16  leo 
    248  1.16  leo 	return 1;
    249  1.16  leo }
    250  1.16  leo 
    251  1.16  leo int
    252  1.16  leo elf_load(fd)
    253  1.16  leo int				fd;
    254  1.16  leo {
    255  1.16  leo 	int		i,j;
    256  1.16  leo 	Elf32_Ehdr	ehdr;
    257  1.16  leo 	Elf32_Phdr	*phdrs;
    258  1.16  leo 	Elf32_Word	symsize, symstart;
    259  1.16  leo 	long		kernsize;
    260  1.16  leo 
    261  1.16  leo 	lseek(fd, (off_t)0, SEEK_SET);
    262  1.16  leo 	if (read(fd, (char *)&ehdr, sizeof(ehdr)) != sizeof(ehdr))
    263  1.16  leo 		return 0;
    264  1.16  leo 
    265  1.16  leo 	if (*((u_int *)ehdr.e_ident) != ELFMAGIC)
    266  1.16  leo 		return 0;
    267  1.16  leo 
    268  1.16  leo 	/*
    269  1.16  leo 	 * calculate highest used address
    270  1.16  leo 	 */
    271  1.16  leo 	i = ehdr.e_phnum * sizeof(Elf32_Phdr);
    272  1.16  leo 	if ((phdrs = (Elf32_Phdr *)malloc(i)) == NULL)
    273  1.16  leo 		fatal(-1, "Cannot malloc Elf phdr storage space");
    274  1.16  leo 	if (read(fd, phdrs, i) != i)
    275  1.16  leo 		fatal(-1, "Cannot read Elf32_Phdrs");
    276  1.16  leo 
    277  1.16  leo 	kernsize = 0;
    278  1.16  leo 	for (i = 0; i < ehdr.e_phnum; i++) {
    279  1.16  leo 		Elf32_Word sum;
    280  1.16  leo 
    281  1.16  leo 		sum = phdrs[i].p_vaddr + phdrs[i].p_memsz;
    282  1.16  leo 		if ((phdrs[i].p_flags & (PF_W|PF_X)) && (sum > kernsize))
    283  1.16  leo 			kernsize = sum;
    284  1.16  leo 	}
    285  1.16  leo 
    286  1.16  leo 	/*
    287  1.16  leo 	 * look for symbols and calculate the size
    288  1.16  leo 	 * XXX: This increases the load time by a factor 2 for gzipped
    289  1.16  leo 	 *      images!
    290  1.16  leo 	 */
    291  1.16  leo 	symsize  = 0;
    292  1.16  leo 	symstart = 0;
    293  1.16  leo 	if (!N_flag) {
    294  1.16  leo 	    i = ehdr.e_shnum + 1;
    295  1.16  leo 	    if (lseek(fd, (off_t)ehdr.e_shoff, SEEK_SET) != ehdr.e_shoff)
    296  1.16  leo 		fatal(-1, "Cannot seek to e_shoff location");
    297  1.16  leo 	    while (--i) {
    298  1.16  leo 	      Elf32_Shdr shdr;
    299  1.16  leo 
    300  1.16  leo 	      if (read(fd, &shdr, sizeof(shdr)) != sizeof(shdr))
    301  1.16  leo 		fatal(-1, "Cannot read Elf32_shdr");
    302  1.16  leo 	      if ((shdr.sh_type == SHT_SYMTAB) || (shdr.sh_type == SHT_STRTAB))
    303  1.16  leo 		symsize += shdr.sh_size;
    304  1.16  leo 	    }
    305  1.16  leo 	}
    306   1.1  leo 
    307  1.16  leo 	if (symsize) {
    308  1.16  leo 	  symstart = kernsize;
    309  1.16  leo 	  kernsize += symsize + sizeof(ehdr) + ehdr.e_shnum*sizeof(Elf32_Shdr);
    310   1.4  leo 	}
    311   1.4  leo 
    312  1.16  leo 	/*
    313  1.16  leo 	 * Extract various sizes from the kernel executable
    314  1.16  leo 	 */
    315  1.16  leo 	kparam.esym_loc = symsize ? kernsize : 0;
    316  1.16  leo 	kparam.ksize    = kernsize;
    317  1.16  leo 	kparam.entry    = ehdr.e_entry;
    318  1.16  leo 
    319  1.16  leo 	if ((kparam.kp = (u_char *)malloc(kparam.ksize)) == NULL)
    320  1.16  leo 		fatal(-1, "Cannot malloc kernel image space");
    321  1.16  leo 
    322  1.16  leo 	/*
    323  1.16  leo 	 * Read text & data, clear bss
    324  1.16  leo 	 */
    325  1.16  leo 	for (i = 0; i < ehdr.e_phnum; i++) {
    326  1.16  leo 	    u_char	*p;
    327  1.16  leo 	    Elf32_Phdr	*php = &phdrs[i];
    328  1.16  leo 
    329  1.16  leo 	    if (php->p_flags & (PF_W|PF_X)) {
    330  1.16  leo 		if (lseek(fd, (off_t)php->p_offset, SEEK_SET) != php->p_offset)
    331  1.16  leo 		    fatal(-1, "Seek error while reading text segment\n");
    332  1.16  leo 		p = (u_char *)(kparam.kp) + php->p_vaddr;
    333  1.16  leo 		if (read(fd, p, php->p_filesz) != php->p_filesz)
    334  1.16  leo 		    fatal(-1, "Read error in text segment\n");
    335  1.16  leo 		if (php->p_memsz > php->p_filesz)
    336  1.16  leo 		    memset(p + php->p_filesz, 0, php->p_memsz - php->p_filesz);
    337  1.16  leo 	    }
    338  1.16  leo 	}
    339   1.1  leo 
    340  1.16  leo 	/*
    341  1.16  leo 	 * Read symbols and strings
    342  1.16  leo 	 */
    343  1.16  leo 	if (symsize) {
    344  1.16  leo 	    u_char	*p, *symtab;
    345  1.16  leo 	    int		nhdrs;
    346  1.16  leo 	    Elf32_Shdr	*shp;
    347  1.16  leo 
    348  1.16  leo 	    symtab = kparam.kp + symstart;
    349  1.16  leo 
    350  1.16  leo 	    p = symtab + sizeof(ehdr);
    351  1.16  leo 	    nhdrs = ehdr.e_shnum;
    352  1.16  leo 	    if (lseek(fd, (off_t)ehdr.e_shoff, SEEK_SET) != ehdr.e_shoff)
    353  1.16  leo 		fatal(-1, "Error seeking to section headers");
    354  1.16  leo 	    if (read(fd, p, nhdrs * sizeof(*shp)) != nhdrs * sizeof(*shp))
    355  1.16  leo 		fatal(-1, "Error reading section headers");
    356  1.16  leo 	    shp = (Elf32_Shdr*)p;
    357  1.16  leo 	    p  += nhdrs * sizeof(*shp);
    358  1.16  leo 	    for (i = 0; i < nhdrs; i++) {
    359  1.16  leo 		if (shp[i].sh_type == SHT_SYMTAB) {
    360  1.16  leo 		    if (shp[i].sh_offset == 0)
    361  1.16  leo 			continue;
    362  1.16  leo 		    /* Got the symbol table. */
    363  1.16  leo 		    if (lseek(fd, (off_t)shp[i].sh_offset, SEEK_SET) !=
    364  1.16  leo 							shp[i].sh_offset)
    365  1.16  leo 		    	fatal(-1, "Error seeking to symbols");
    366  1.16  leo 		    if (read(fd, p, shp[i].sh_size) != shp[i].sh_size)
    367  1.16  leo 			fatal(-1, "Error reading symbols");
    368  1.16  leo 		    shp[i].sh_offset = p - symtab;
    369  1.16  leo 		    /* Find the string table to go with it. */
    370  1.16  leo 		    j = shp[i].sh_link;
    371  1.16  leo 		    if (shp[j].sh_offset == 0)
    372  1.16  leo 			continue;
    373  1.16  leo 		    p += shp[i].sh_size;
    374  1.16  leo 		    if (lseek(fd, (off_t)shp[j].sh_offset, SEEK_SET) !=
    375  1.16  leo 				    			shp[j].sh_offset)
    376  1.16  leo 		    	fatal(-1, "Error seeking to string table");
    377  1.16  leo 		    if (read(fd, p, shp[j].sh_size) != shp[j].sh_size)
    378  1.16  leo 			fatal(-1, "Error reading strings");
    379  1.16  leo 		    shp[j].sh_offset = p - symtab;
    380  1.16  leo 		    /* There should only be one symbol table. */
    381  1.16  leo 		    break;
    382  1.16  leo 		}
    383  1.16  leo 	    }
    384  1.16  leo 	    ehdr.e_shoff = sizeof(ehdr);
    385  1.16  leo 	    bcopy(&ehdr, symtab, sizeof(ehdr));
    386  1.16  leo 	}
    387  1.16  leo 	return 1;
    388   1.1  leo }
    389   1.1  leo 
    390   1.1  leo /*
    391   1.1  leo  * Extract memory and cpu/fpu info from system.
    392   1.1  leo  */
    393  1.10  leo void
    394  1.10  leo get_sys_info()
    395   1.1  leo {
    396   1.1  leo 	long	stck;
    397   1.1  leo 	long	*jar;
    398   1.7  leo 	OSH	*oshdr;
    399   1.1  leo 
    400  1.10  leo 	kparam.bootflags = 0;
    401   1.1  leo 
    402   1.1  leo 	stck = Super(0);
    403   1.7  leo 
    404   1.7  leo 	/*
    405   1.7  leo 	 * Some GEMDOS versions use a different year-base in the RTC.
    406   1.7  leo 	 */
    407   1.7  leo 	oshdr = *ADDR_OSHEAD;
    408   1.7  leo 	oshdr = oshdr->os_beg;
    409  1.10  leo 	if ((oshdr->os_version > 0x0300) && (oshdr->os_version < 0x0306))
    410  1.10  leo 		kparam.bootflags |= ATARI_CLKBROKEN;
    411   1.1  leo 
    412  1.10  leo 	if (kparam.stmem_size <= 0)
    413   1.3  leo 		kparam.stmem_size  = *ADDR_PHYSTOP;
    414   1.3  leo 
    415  1.10  leo 	if (kparam.ttmem_size)
    416   1.5  leo 		kparam.ttmem_start  = TTRAM_BASE;
    417   1.5  leo 	else {
    418  1.10  leo 		if (!s_flag && (*ADDR_CHKRAMTOP == RAM_TOP_MAGIC)) {
    419   1.5  leo 			kparam.ttmem_size  = *ADDR_RAMTOP;
    420  1.10  leo 			if (kparam.ttmem_size > TTRAM_BASE) {
    421   1.5  leo 				kparam.ttmem_size  -= TTRAM_BASE;
    422   1.5  leo 				kparam.ttmem_start  = TTRAM_BASE;
    423   1.5  leo 			}
    424   1.5  leo 			else kparam.ttmem_size = 0;
    425   1.4  leo 		}
    426   1.4  leo 	}
    427   1.1  leo 
    428   1.1  leo 	/*
    429   1.8  leo 	 * Scan cookiejar for cpu types
    430   1.1  leo 	 */
    431   1.1  leo 	jar = *ADDR_P_COOKIE;
    432  1.10  leo 	if (jar != NULL) {
    433   1.1  leo 		do {
    434  1.14  leo 		    if (jar[0] == 0x5f435055) { /* _CPU	*/
    435  1.14  leo 			switch (jar[1]) {
    436  1.14  leo 				case 0:
    437  1.14  leo 					kparam.bootflags |= ATARI_68000;
    438  1.14  leo 					break;
    439  1.14  leo 				case 10:
    440  1.14  leo 					kparam.bootflags |= ATARI_68010;
    441  1.14  leo 					break;
    442  1.14  leo 				case 20:
    443  1.14  leo 					kparam.bootflags |= ATARI_68020;
    444  1.14  leo 					break;
    445  1.14  leo 				case 30:
    446  1.14  leo 					kparam.bootflags |= ATARI_68030;
    447  1.14  leo 					break;
    448  1.14  leo 				case 40:
    449  1.14  leo 					kparam.bootflags |= ATARI_68040;
    450  1.14  leo 					break;
    451  1.14  leo 				case 60:
    452  1.14  leo 					kparam.bootflags |= ATARI_68060;
    453  1.14  leo 					break;
    454  1.14  leo 				default:
    455  1.14  leo 					fatal(-1, "Unknown CPU-type");
    456   1.1  leo 			}
    457  1.14  leo 		    }
    458  1.14  leo 		    if (jar[0] == 0x42504658) { /* BPFX	*/
    459  1.14  leo 			unsigned long	*p;
    460  1.14  leo 
    461  1.14  leo 			p = (unsigned long*)jar[1];
    462  1.14  leo 
    463  1.14  leo 			kparam.ttmem_start = p[1];
    464  1.14  leo 			kparam.ttmem_size  = p[2];
    465  1.14  leo 		    }
    466  1.14  leo 		    if (jar[0] == 0x5f435432) { /* _CT2	*/
    467  1.14  leo 			/*
    468  1.14  leo 			 * The CT2 board has a different physical base address!
    469  1.14  leo 			 */
    470  1.14  leo 			kparam.ttmem_start = CTRAM_BASE;
    471  1.14  leo 		    }
    472  1.14  leo 		    jar = &jar[2];
    473  1.10  leo 		} while (jar[-2]);
    474   1.1  leo 	}
    475  1.10  leo 	if (!(kparam.bootflags & ATARI_ANYCPU))
    476  1.10  leo 		fatal(-1, "Cannot determine CPU-type");
    477   1.1  leo 
    478  1.10  leo 	(void)Super(stck);
    479   1.3  leo 
    480  1.10  leo 	if (d_flag) {
    481  1.10  leo 	    eprintf("Machine info:\r\n");
    482  1.10  leo 	    eprintf("ST-RAM size\t: %10d bytes\r\n",kparam.stmem_size);
    483  1.10  leo 	    eprintf("TT-RAM size\t: %10d bytes\r\n",kparam.ttmem_size);
    484  1.10  leo 	    eprintf("TT-RAM start\t: 0x%08x\r\n", kparam.ttmem_start);
    485  1.10  leo 	    eprintf("Cpu-type\t: 0x%08x\r\n", kparam.bootflags);
    486   1.3  leo 	}
    487   1.1  leo }
    488   1.1  leo 
    489  1.10  leo void
    490  1.10  leo help()
    491   1.1  leo {
    492  1.10  leo 	eprintf("\r
    493   1.3  leo NetBSD loader for the Atari-TT\r
    494   1.3  leo \r
    495  1.10  leo Usage: %s [-abdhstVD] [-S <stram-size>] [-T <ttram-size>] [kernel]\r
    496   1.3  leo \r
    497   1.3  leo Description of options:\r
    498   1.3  leo \r
    499   1.3  leo \t-a  Boot up to multi-user mode.\r
    500   1.3  leo \t-b  Ask for root device to use.\r
    501   1.3  leo \t-d  Enter kernel debugger.\r
    502  1.10  leo \t-D  printout debug information while loading\r
    503  1.11  leo \t-h  What you're getting right now.\r
    504  1.16  leo `t-N  No symbols must be loaded.\r
    505  1.10  leo \t-o  Write output to both <output file> and stdout.\r
    506   1.3  leo \t-s  Use only ST-compatible RAM\r
    507   1.3  leo \t-S  Set amount of ST-compatible RAM\r
    508   1.5  leo \t-T  Set amount of TT-compatible RAM\r
    509   1.3  leo \t-t  Test the loader. It will do everything except executing the\r
    510   1.3  leo \t    loaded kernel.\r
    511  1.10  leo \t-V  Print loader version.\r
    512  1.10  leo \t-w  Wait for a keypress before exiting.\r
    513   1.1  leo ", Progname);
    514  1.10  leo 	xexit(0);
    515   1.1  leo }
    516   1.1  leo 
    517  1.10  leo void
    518  1.10  leo usage()
    519   1.1  leo {
    520  1.10  leo 	eprintf("Usage: %s [-abdhstVD] [-S <stram-size>] "
    521  1.10  leo 		"[-T <ttram-size>] [kernel]\r\n", Progname);
    522  1.10  leo 	xexit(1);
    523   1.3  leo }
    524   1.3  leo 
    525  1.10  leo void
    526  1.10  leo start_kernel()
    527   1.1  leo {
    528   1.1  leo 	long	stck;
    529   1.1  leo 
    530   1.1  leo 	stck = Super(0);
    531  1.10  leo 	bsd_startup(&kparam);
    532   1.1  leo 	/* NOT REACHED */
    533   1.1  leo 
    534  1.10  leo 	(void)Super(stck);
    535   1.1  leo }
    536