1 /* $NetBSD: init_main.c,v 1.6 2013/03/05 15:34:53 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 <sys/boot_flag.h> 75 #include <machine/cpu.h> 76 #include <luna68k/stand/boot/samachdep.h> 77 #include <luna68k/stand/boot/stinger.h> 78 #include <luna68k/stand/boot/romvec.h> 79 #include <luna68k/stand/boot/status.h> 80 #include <lib/libsa/loadfile.h> 81 #ifdef SUPPORT_ETHERNET 82 #include <lib/libsa/dev_net.h> 83 #endif 84 85 static int get_plane_numbers(void); 86 static int reorder_dipsw(int); 87 88 int cpuspeed; /* for DELAY() macro */ 89 int hz = 60; 90 int machtype; 91 char default_file[64]; 92 93 #define VERS_LOCAL "Phase-31" 94 95 int nplane; 96 97 /* KIFF */ 98 99 struct KernInter KIFF; 100 struct KernInter *kiff = &KIFF; 101 102 /* for command parser */ 103 104 #define BUFFSIZE 100 105 #define MAXARGS 30 106 107 char buffer[BUFFSIZE]; 108 109 int argc; 110 char *argv[MAXARGS]; 111 112 #define BOOT_TIMEOUT 10 113 int boot_timeout = BOOT_TIMEOUT; 114 115 char prompt[16] = "boot> "; 116 117 void 118 main(void) 119 { 120 int i, status = 0; 121 const char *machstr; 122 const char *cp; 123 char bootarg[64]; 124 bool netboot = false; 125 int unit, part; 126 127 /* 128 * Initialize the console before we print anything out. 129 */ 130 if (cputype == CPU_68030) { 131 machtype = LUNA_I; 132 machstr = "LUNA-I"; 133 cpuspeed = MHZ_25; 134 hz = 60; 135 memcpy(bootarg, (char *)*RVPtr->vec53, sizeof(bootarg)); 136 137 /* check netboot */ 138 for (i = 0, cp = bootarg; i < sizeof(bootarg); i++, cp++) { 139 if (*cp == '\0') 140 break; 141 if (*cp == 'E' && memcmp("ENADDR=", cp, 7) == 0) { 142 netboot = true; 143 break; 144 } 145 } 146 } else { 147 machtype = LUNA_II; 148 machstr = "LUNA-II"; 149 cpuspeed = MHZ_25 * 2; /* XXX */ 150 hz = 100; 151 memcpy(bootarg, (char *)*RVPtr->vec02, sizeof(bootarg)); 152 153 /* LUNA-II's boot monitor doesn't support netboot */ 154 } 155 156 nplane = get_plane_numbers(); 157 158 cninit(); 159 160 printf("\n"); 161 printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev); 162 printf(">> (based on Stinger ver 0.0 [%s])\n", VERS_LOCAL); 163 printf("\n"); 164 165 kiff->maxaddr = (void *) (ROM_memsize -1); 166 kiff->dipsw = ~((dipsw2 << 8) | dipsw1) & 0xFFFF; 167 kiff->plane = nplane; 168 169 i = (int) kiff->maxaddr + 1; 170 printf("Machine model = %s\n", machstr); 171 printf("Physical Memory = 0x%x ", i); 172 i >>= 20; 173 printf("(%d MB)\n", i); 174 printf("\n"); 175 176 /* 177 * IO configuration 178 */ 179 180 #ifdef SUPPORT_ETHERNET 181 try_bootp = 1; 182 #endif 183 184 find_devs(); 185 configure(); 186 printf("\n"); 187 188 unit = 0; /* XXX should parse monitor's Boot-file constant */ 189 part = 0; 190 snprintf(default_file, sizeof(default_file), 191 "%s(%d,%d)%s", netboot ? "le" : "sd", unit, part, "netbsd"); 192 193 howto = reorder_dipsw(dipsw2); 194 195 if ((howto & 0xFE) == 0) { 196 char c; 197 198 printf("Press return to boot now," 199 " any other key for boot menu\n"); 200 printf("booting %s - starting in ", default_file); 201 c = awaitkey("%d seconds. ", boot_timeout, true); 202 if (c == '\r' || c == '\n' || c == 0) { 203 printf("auto-boot %s\n", default_file); 204 bootnetbsd(default_file); 205 } 206 } 207 208 /* 209 * Main Loop 210 */ 211 212 printf("type \"help\" for help.\n"); 213 214 do { 215 memset(buffer, 0, BUFFSIZE); 216 if (getline(prompt, buffer) > 0) { 217 argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *)); 218 219 status = parse(argc, argv); 220 if (status == ST_NOTFOUND) 221 printf("Command \"%s\" is not found !!\n", argv[0]); 222 } 223 } while(status != ST_EXIT); 224 225 exit(0); 226 } 227 228 int 229 get_plane_numbers(void) 230 { 231 int r = ROM_plane; 232 int n = 0; 233 234 for (; r ; r >>= 1) 235 if (r & 0x1) 236 n++; 237 238 return(n); 239 } 240 241 int 242 reorder_dipsw(int dipsw) 243 { 244 int i, sw = 0; 245 246 for (i = 0; i < 8; i++) { 247 if ((dipsw & 0x01) == 0) 248 sw += 1; 249 250 if (i == 7) 251 break; 252 253 sw <<= 1; 254 dipsw >>= 1; 255 } 256 257 return(sw); 258 } 259