xref: /netbsd-src/sys/arch/news68k/stand/boot/boot.c (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1 /*	$NetBSD: boot.c,v 1.20 2014/03/28 15:02:34 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999 Izumi Tsutsui.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 /*-
28  * Copyright (C) 1999 Tsubai Masanari.  All rights reserved.
29  *
30  * Redistribution and use in source and binary forms, with or without
31  * modification, are permitted provided that the following conditions
32  * are met:
33  * 1. Redistributions of source code must retain the above copyright
34  *    notice, this list of conditions and the following disclaimer.
35  * 2. Redistributions in binary form must reproduce the above copyright
36  *    notice, this list of conditions and the following disclaimer in the
37  *    documentation and/or other materials provided with the distribution.
38  * 3. The name of the author may not be used to endorse or promote products
39  *    derived from this software without specific prior written permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
45  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51  */
52 
53 #include <lib/libkern/libkern.h>
54 #include <lib/libsa/stand.h>
55 #include <lib/libsa/loadfile.h>
56 
57 #include <machine/romcall.h>
58 
59 void boot(uint32_t, uint32_t, uint32_t, uint32_t);
60 extern void ICIA(void);
61 
62 /* version strings in vers.c (generated by newvers.sh) */
63 extern const char bootprog_name[];
64 extern const char bootprog_rev[];
65 extern const char bootprog_kernrev[];
66 
67 char *devs[] = { "hd", "fh", "fd", NULL, NULL, "rd", "st" };
68 char *kernels[] = { "/netbsd", "/netbsd.gz", NULL };
69 
70 #ifdef BOOT_DEBUG
71 # define DPRINTF printf
72 #else
73 # define DPRINTF while (0) printf
74 #endif
75 
76 void
77 boot(uint32_t d4, uint32_t d5, uint32_t d6, uint32_t d7)
78 {
79 	int fd, i;
80 	int ctlr, unit, part, type;
81 	uint32_t bootdev = d6;
82 	char *netbsd = (char *)d5;
83 	u_long marks[MARK_MAX];
84 	static char devname[32], file[32];
85 	void (*entry)(void);
86 	int loadflag;
87 
88 	printf("%s Secondary Boot, Revision %s (from NetBSD %s)\n",
89 	    bootprog_name, bootprog_rev, bootprog_kernrev);
90 
91 	/* bootname is "boot" by default. */
92 	if (netbsd == NULL || strcmp(netbsd, "boot") == 0 ||
93 			      strcmp(netbsd, "/boot") == 0)
94 		netbsd = "";
95 
96 	DPRINTF("howto = 0x%x\n", d7);
97 	DPRINTF("bootdev = 0x%x\n", bootdev);
98 	DPRINTF("bootname = %s\n", netbsd);
99 	DPRINTF("maxmem = 0x%x\n", d4);
100 
101 #define	SET_MAGIC(bootdev, magic) ((bootdev & 0x0fffffff)| (magic << 28))
102 	/* PROM monitor passes 0xa, but NEWS-OS /boot passed 0x5... */
103 	bootdev = SET_MAGIC(bootdev, 5);
104 
105 	ctlr = BOOTDEV_CTLR(bootdev);
106 	unit = BOOTDEV_UNIT(bootdev);
107 	part = BOOTDEV_PART(bootdev);
108 	type = BOOTDEV_TYPE(bootdev);
109 
110 	marks[MARK_START] = 0;
111 
112 	if (devs[type] == NULL) {
113 		printf("unknown bootdev (0x%x)\n", bootdev);
114 		return;
115 	}
116 
117 	snprintf(devname, sizeof(devname),
118 	    "%s(%d,%d,%d)", devs[type], ctlr, unit, part);
119 	printf("Booting %s%s\n", devname, netbsd);
120 
121 	/* use user specified kernel name if exists */
122 	if (*netbsd) {
123 		kernels[0] = netbsd;
124 		kernels[1] = NULL;
125 	}
126 
127 	loadflag = LOAD_KERNEL;
128 	if (devname[0] == 'f')	/* XXX */
129 		loadflag &= ~LOAD_BACKWARDS;
130 
131 	for (i = 0; kernels[i]; i++) {
132 		snprintf(file, sizeof(file), "%s%s", devname, kernels[i]);
133 		DPRINTF("trying %s...\n", file);
134 		fd = loadfile(file, marks, loadflag);
135 		if (fd != -1)
136 			break;
137 	}
138 	if (kernels[i] == NULL) {
139 #if 0 /* bootxx() may be overrided by loaded kernel */
140 		return;
141 #else
142 		rom_halt();
143 		/* NOTREACHED */
144 #endif
145 	}
146 
147 	DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
148 	DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
149 	DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);
150 
151 	entry = (void *)marks[MARK_ENTRY];
152 
153 	printf("\n");
154 
155 	ICIA();
156 	__asm volatile ("movl %0,%%d7" : : "m" (d7));
157 	__asm volatile ("movl %0,%%d6" : : "m" (bootdev));
158 	__asm volatile ("movl %0,%%d5" : : "m" (netbsd));
159 	__asm volatile ("movl %0,%%d4" : : "m" (d4));
160 	__asm volatile ("movl %0,%%d2" : : "m" (marks[MARK_END]));
161 	(*entry)();
162 }
163 
164 void
165 _rtt(void)
166 {
167 
168 	rom_halt();
169 	for (;;)
170 		;
171 	/* NOTREACHED */
172 }
173