init_main.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* $OpenBSD: init_main.c,v 1.6 2014/02/23 20:01:04 miod Exp $ */
  2. /* $NetBSD: init_main.c,v 1.6 2013/03/05 15:34:53 tsutsui Exp $ */
  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. * Mach Operating System
  74. * Copyright (c) 1993-1991 Carnegie Mellon University
  75. * Copyright (c) 1991 OMRON Corporation
  76. * All Rights Reserved.
  77. *
  78. * Permission to use, copy, modify and distribute this software and its
  79. * documentation is hereby granted, provided that both the copyright
  80. * notice and this permission notice appear in all copies of the
  81. * software, derivative works or modified versions, and any portions
  82. * thereof, and that both notices appear in supporting documentation.
  83. *
  84. * CARNEGIE MELLON AND OMRON ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  85. * CONDITION. CARNEGIE MELLON AND OMRON DISCLAIM ANY LIABILITY OF ANY KIND
  86. * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  87. *
  88. * Carnegie Mellon requests users of this software to return to
  89. *
  90. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  91. * School of Computer Science
  92. * Carnegie Mellon University
  93. * Pittsburgh PA 15213-3890
  94. *
  95. * any improvements or extensions that they make and grant Carnegie the
  96. * rights to redistribute these changes.
  97. */
  98. #include <sys/param.h>
  99. #include <machine/board.h>
  100. #include <luna88k/stand/boot/samachdep.h>
  101. #include <luna88k/stand/boot/status.h>
  102. #include <lib/libsa/loadfile.h>
  103. #include "dev_net.h"
  104. static void get_fuse_rom_data(void);
  105. static void get_nvram_data(void);
  106. static int get_plane_numbers(void);
  107. static const char *nvram_by_symbol(char *);
  108. int cpuspeed; /* for DELAY() macro */
  109. int machtype;
  110. char default_file[64];
  111. uint16_t dipswitch = 0;
  112. int nplane;
  113. /* for command parser */
  114. #define BUFFSIZE 100
  115. #define MAXARGS 30
  116. char buffer[BUFFSIZE];
  117. int argc;
  118. char *argv[MAXARGS];
  119. #define BOOT_TIMEOUT 5
  120. int boot_timeout = BOOT_TIMEOUT;
  121. static const char prompt[] = "boot> ";
  122. int debug;
  123. /*
  124. * FUSE ROM and NVRAM data
  125. */
  126. struct fuse_rom_byte {
  127. u_int32_t h;
  128. u_int32_t l;
  129. };
  130. #define FUSE_ROM_SPACE 1024
  131. #define FUSE_ROM_BYTES (FUSE_ROM_SPACE / sizeof(struct fuse_rom_byte))
  132. char fuse_rom_data[FUSE_ROM_BYTES];
  133. #define NNVSYM 8
  134. #define NVSYMLEN 16
  135. #define NVVALLEN 16
  136. struct nvram_t {
  137. char symbol[1 + NVSYMLEN];
  138. char value[1 + NVVALLEN];
  139. } nvram[NNVSYM];
  140. int
  141. main(void)
  142. {
  143. int status = ST_NORMAL;
  144. const char *machstr;
  145. const char *nvv;
  146. int unit, part;
  147. /* Determine the machine type from FUSE ROM data. */
  148. get_fuse_rom_data();
  149. if (strncmp(fuse_rom_data, "MNAME=LUNA88K+", 14) == 0)
  150. machtype = LUNA_88K2;
  151. else
  152. machtype = LUNA_88K;
  153. /*
  154. * Initialize the console before we print anything out.
  155. */
  156. if (machtype == LUNA_88K) {
  157. machstr = "LUNA-88K";
  158. cpuspeed = MHZ_25;
  159. } else {
  160. machstr = "LUNA-88K2";
  161. cpuspeed = MHZ_33;
  162. }
  163. nplane = get_plane_numbers();
  164. cninit();
  165. printf("\nOpenBSD/" MACHINE " (%s) boot 0.4\n\n", machstr);
  166. #ifdef SUPPORT_ETHERNET
  167. try_bootp = 1;
  168. #endif
  169. /* Determine the 'auto-boot' device from NVRAM data */
  170. get_nvram_data();
  171. nvv = nvram_by_symbol("boot_unit");
  172. if (nvv != NULL)
  173. unit = (int)strtol(nvv, NULL, 10);
  174. else
  175. unit = 0;
  176. nvv = nvram_by_symbol("boot_partition");
  177. if (nvv != NULL)
  178. part = (int)strtol(nvv, NULL, 10);
  179. else
  180. part = 0;
  181. nvv = nvram_by_symbol("boot_device");
  182. snprintf(default_file, sizeof(default_file),
  183. "%s(%d,%d)%s", nvv != NULL ? nvv : "sd", unit, part, "bsd");
  184. /* auto-boot? (SW1) */
  185. if ((dipswitch & 0x8000) != 0) {
  186. char c;
  187. printf("Press return to boot now,"
  188. " any other key for boot menu\n");
  189. printf("booting %s - starting in ", default_file);
  190. c = awaitkey("%d seconds. ", boot_timeout, 1);
  191. if (c == '\r' || c == '\n' || c == 0) {
  192. printf("auto-boot %s\n", default_file);
  193. bootunix(default_file);
  194. }
  195. }
  196. /*
  197. * Main Loop
  198. */
  199. printf("type \"help\" for help.\n");
  200. do {
  201. memset(buffer, 0, BUFFSIZE);
  202. if (getline(prompt, buffer) > 0) {
  203. argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *));
  204. status = parse(argc, argv);
  205. if (status == ST_NOTFOUND)
  206. printf("unknown command \"%s\"\n", argv[0]);
  207. }
  208. } while (status != ST_EXIT);
  209. _rtt();
  210. /* NOTREACHED */
  211. }
  212. int
  213. get_plane_numbers(void)
  214. {
  215. int r = *((int *)0x1114);
  216. int n = 0;
  217. for (; r ; r >>= 1)
  218. if (r & 0x1)
  219. n++;
  220. return(n);
  221. }
  222. /* Get data from FUSE ROM */
  223. void
  224. get_fuse_rom_data(void)
  225. {
  226. int i;
  227. struct fuse_rom_byte *p = (struct fuse_rom_byte *)FUSE_ROM_ADDR;
  228. for (i = 0; i < FUSE_ROM_BYTES; i++) {
  229. fuse_rom_data[i] =
  230. (char)((((p->h) >> 24) & 0x000000f0) |
  231. (((p->l) >> 28) & 0x0000000f));
  232. p++;
  233. }
  234. }
  235. /* Get data from NVRAM */
  236. void
  237. get_nvram_data(void)
  238. {
  239. int i, j;
  240. u_int8_t *page;
  241. char buf[NVSYMLEN], *data;
  242. if (machtype == LUNA_88K) {
  243. data = (char *)(NVRAM_ADDR + 0x80);
  244. for (i = 0; i < NNVSYM; i++) {
  245. for (j = 0; j < NVSYMLEN; j++) {
  246. buf[j] = *data;
  247. data += 4;
  248. }
  249. strncpy(nvram[i].symbol, buf, sizeof(nvram[i].symbol));
  250. for (j = 0; j < NVVALLEN; j++) {
  251. buf[j] = *data;
  252. data += 4;
  253. }
  254. strncpy(nvram[i].value, buf, sizeof(nvram[i].value));
  255. }
  256. } else if (machtype == LUNA_88K2) {
  257. page = (u_int8_t *)(NVRAM_ADDR_88K2 + 0x20);
  258. for (i = 0; i < NNVSYM; i++) {
  259. *page = (u_int8_t)i;
  260. data = (char *)NVRAM_ADDR_88K2;
  261. strncpy(nvram[i].symbol, data, sizeof(nvram[i].symbol));
  262. data = (char *)(NVRAM_ADDR_88K2 + 0x10);
  263. strncpy(nvram[i].value, data, sizeof(nvram[i].value));
  264. }
  265. }
  266. }
  267. const char *
  268. nvram_by_symbol(symbol)
  269. char *symbol;
  270. {
  271. const char *value;
  272. int i;
  273. value = NULL;
  274. for (i = 0; i < NNVSYM; i++) {
  275. if (strncmp(nvram[i].symbol, symbol, NVSYMLEN) == 0) {
  276. value = nvram[i].value;
  277. break;
  278. }
  279. }
  280. return value;
  281. }
  282. void
  283. _rtt(void)
  284. {
  285. *(volatile unsigned int *)RESET_CPU_ALL = 0;
  286. for (;;) ;
  287. /* NOTREACHED */
  288. }