Home | History | Annotate | Line # | Download | only in boot
init_main.c revision 1.4
      1 /*	$NetBSD: init_main.c,v 1.4 2013/01/20 13:35:43 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992 OMRON Corporation.
      5  *
      6  * This code is derived from software contributed to Berkeley by
      7  * OMRON Corporation.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the University of
     20  *	California, Berkeley and its contributors.
     21  * 4. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
     38  */
     39 /*
     40  * Copyright (c) 1992, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * OMRON Corporation.
     45  *
     46  * Redistribution and use in source and binary forms, with or without
     47  * modification, are permitted provided that the following conditions
     48  * are met:
     49  * 1. Redistributions of source code must retain the above copyright
     50  *    notice, this list of conditions and the following disclaimer.
     51  * 2. Redistributions in binary form must reproduce the above copyright
     52  *    notice, this list of conditions and the following disclaimer in the
     53  *    documentation and/or other materials provided with the distribution.
     54  * 3. Neither the name of the University nor the names of its contributors
     55  *    may be used to endorse or promote products derived from this software
     56  *    without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  * SUCH DAMAGE.
     69  *
     70  *	@(#)init_main.c	8.2 (Berkeley) 8/15/93
     71  */
     72 
     73 #include <sys/param.h>
     74 #include <machine/cpu.h>
     75 #include <luna68k/stand/boot/samachdep.h>
     76 #include <luna68k/stand/boot/stinger.h>
     77 #include <luna68k/stand/boot/romvec.h>
     78 #include <luna68k/stand/boot/status.h>
     79 #include <lib/libsa/loadfile.h>
     80 #ifdef SUPPORT_ETHERNET
     81 #include <lib/libsa/dev_net.h>
     82 #endif
     83 
     84 static int get_plane_numbers(void);
     85 static int reorder_dipsw(int);
     86 
     87 int cpuspeed;	/* for DELAY() macro */
     88 int machtype;
     89 
     90 #define	VERS_LOCAL	"Phase-31"
     91 
     92 int nplane;
     93 
     94 /* KIFF */
     95 
     96 struct KernInter  KIFF;
     97 struct KernInter *kiff = &KIFF;
     98 
     99 /* for command parser */
    100 
    101 #define BUFFSIZE 100
    102 #define MAXARGS  30
    103 
    104 char buffer[BUFFSIZE];
    105 
    106 int   argc;
    107 char *argv[MAXARGS];
    108 
    109 char  prompt[16] = "boot> ";
    110 
    111 void
    112 main(void)
    113 {
    114 	int i, status = 0;
    115 	const char *machstr;
    116 
    117 	/*
    118 	 * Initialize the console before we print anything out.
    119 	 */
    120 	if (cputype == CPU_68030) {
    121 		machtype = LUNA_I;
    122 		machstr  = "LUNA-I";
    123 		cpuspeed = MHZ_25;
    124 	} else {
    125 		machtype = LUNA_II;
    126 		machstr  = "LUNA-II";
    127 		cpuspeed = MHZ_25 * 2;	/* XXX */
    128 	}
    129 
    130 	nplane   = get_plane_numbers();
    131 
    132 	cninit();
    133 
    134 	printf("\n");
    135 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
    136 	printf(">> (based on Stinger ver 0.0 [%s])\n", VERS_LOCAL);
    137 	printf("\n");
    138 
    139 	kiff->maxaddr = (void *) (ROM_memsize -1);
    140 	kiff->dipsw   = ~((dipsw2 << 8) | dipsw1) & 0xFFFF;
    141 	kiff->plane   = nplane;
    142 
    143 	i = (int) kiff->maxaddr + 1;
    144 	printf("Machine model   = %s\n", machstr);
    145 	printf("Physical Memory = 0x%x  ", i);
    146 	i >>= 20;
    147 	printf("(%d MB)\n", i);
    148 	printf("\n");
    149 
    150 	/*
    151 	 * IO configuration
    152 	 */
    153 
    154 #ifdef SUPPORT_ETHERNET
    155 	try_bootp = 1;
    156 #endif
    157 
    158 	find_devs();
    159 	configure();
    160 	printf("\n");
    161 
    162 	howto = reorder_dipsw(dipsw2);
    163 
    164 	if ((howto & 0xFE) == 0) {
    165 		printf("auto-boot %s\n", default_file);
    166 		bootnetbsd(default_file);
    167 	}
    168 
    169 	/*
    170 	 * Main Loop
    171 	 */
    172 
    173 	do {
    174 		memset(buffer, 0, BUFFSIZE);
    175 		if (getline(prompt, buffer) > 0) {
    176 			argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *));
    177 
    178 			status = parse(argc, argv);
    179 			if (status == ST_NOTFOUND)
    180 				printf("Command \"%s\" is not found !!\n", argv[0]);
    181 		}
    182 	} while(status != ST_EXIT);
    183 
    184 	exit(0);
    185 }
    186 
    187 int
    188 get_plane_numbers(void)
    189 {
    190 	int r = ROM_plane;
    191 	int n = 0;
    192 
    193 	for (; r ; r >>= 1)
    194 		if (r & 0x1)
    195 			n++;
    196 
    197 	return(n);
    198 }
    199 
    200 int
    201 reorder_dipsw(int dipsw)
    202 {
    203 	int i, sw = 0;
    204 
    205 	for (i = 0; i < 8; i++) {
    206 		if ((dipsw & 0x01) == 0)
    207 			sw += 1;
    208 
    209 		if (i == 7)
    210 			break;
    211 
    212 		sw <<= 1;
    213 		dipsw >>= 1;
    214 	}
    215 
    216 	return(sw);
    217 }
    218