xref: /netbsd-src/sys/arch/mvmeppc/stand/boot/boot.c (revision 85e3fbd2ebdea4c043943e3fc74aae69c997bc76)
1 /*	$NetBSD: boot.c,v 1.7 2016/06/11 06:34:00 dholland Exp $	*/
2 
3 /*-
4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Steve C. Woodford.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1982, 1986, 1990, 1993
34  *	The Regents of the University of California.  All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. Neither the name of the University nor the names of its contributors
45  *    may be used to endorse or promote products derived from this software
46  *    without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  * 	@(#)boot.c	8.1 (Berkeley) 6/10/93
61  */
62 
63 #include <sys/param.h>
64 #include <sys/reboot.h>
65 #include <sys/termios.h>
66 #include <sys/ttydefaults.h>
67 #include <machine/bootinfo.h>
68 
69 #include <lib/libkern/libkern.h>
70 
71 #include "stand.h"
72 #include "libsa.h"
73 #include "bugsyscalls.h"
74 
75 struct bug_bootinfo	bug_bootinfo;
76 struct mvmeppc_bootinfo	bootinfo;
77 
78 static u_int32_t ioctrl2cflag(u_int32_t);
79 
80 void main(void);
81 
82 void
main(void)83 main(void)
84 {
85 	struct bug_buginfo *bbi;
86 	struct bug_boardid *bid;
87 	struct bug_ioinquiry *ioi, ioinq;
88 	struct bug_ioctrl ioctrl;
89 	char consname[CONSOLEDEV_LEN];
90 	char line[80];
91 	const char *file;
92 	int ask = 0, howto, part;
93 
94 	if (bug_bootinfo.bbi_bugmode == 0)
95 		panic("mvmeppc-boot: PReP boot mode not supported!");
96 
97 	bbi = &bug_bootinfo.bbi_bi.bbi;
98 
99 	if ((bid = bugsys_brdid()) == NULL)
100 		panic("mvmeppc-boot: bugsys_brdid() failed!");
101 
102 	ioinq.ii_boardname = consname;
103 	ioinq.ii_ioctrl = &ioctrl;
104 	ioinq.ii_portnum = BUG_IOINQ_PORT_CONSOLE;
105 	if ((ioi = bugsys_ioinq(&ioinq)) == NULL)
106 		panic("mvmeppc-boot: bugsys_ioinq() failed!");
107 
108 	if (bid->bi_devtype > 9)
109 		panic("mvmeppc-boot: Bogus boot device type (%d)",
110 		    bid->bi_devtype);
111 
112 	printf(">> MVMEPPC boot on MVME%x\n", bid->bi_bnumber);
113 
114 	parse_args(bbi->bbi_argstart, bbi->bbi_argend, &file, &howto, &part);
115 
116 	for (;;) {
117 		if (ask) {
118 			printf("boot: ");
119 			kgets(line, sizeof(line));
120 			if (strcmp(line, "halt") == 0)
121 				break;
122 
123 			if (line[0]) {
124 				char *cp = line;
125 
126 				while (cp < (line + sizeof(line) - 1) && *cp)
127 					cp++;
128 
129 				bbi->bbi_argstart = line;
130 				bbi->bbi_argend = cp;
131 				parse_args(bbi->bbi_argstart, bbi->bbi_argend,
132 				    &file, &howto, &part);
133 			}
134 		}
135 
136 		bootinfo.bi_boothowto = howto;
137 		bootinfo.bi_bootaddr = bbi->bbi_devaddr;
138 		bootinfo.bi_bootclun = bbi->bbi_clun;
139 		bootinfo.bi_bootclun = bbi->bbi_dlun;
140 		strncpy(bootinfo.bi_bootline, bbi->bbi_argstart,
141 		    MIN(BOOTLINE_LEN, bbi->bbi_argend - bbi->bbi_argstart));
142 		strncpy(bootinfo.bi_consoledev, consname, CONSOLEDEV_LEN);
143 		bootinfo.bi_consoleaddr = ioi->ii_devaddr;
144 		bootinfo.bi_consolechan = ioi->ii_channel;
145 		bootinfo.bi_consolespeed = ioctrl.ic_baud;
146 		bootinfo.bi_consolecflag = ioctrl2cflag(ioctrl.ic_ctrlbits);
147 		bootinfo.bi_modelnumber = bid->bi_bnumber;
148 
149 		exec_mvme(file, howto, part);
150 		printf("boot: %s: %s\n", file, strerror(errno));
151 		ask = 1;
152 	}
153 }
154 
155 static u_int32_t
ioctrl2cflag(u_int32_t ctrlbits)156 ioctrl2cflag(u_int32_t ctrlbits)
157 {
158 	u_int32_t rv;
159 
160 	rv = TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB | PARODD);
161 
162 	/* Convert parity */
163 	if (ctrlbits & IOCTRL_PARITY_ODD)
164 		rv |= PARENB | PARODD;
165 	else
166 	if (ctrlbits & IOCTRL_PARITY_EVEN)
167 		rv |= PARENB;
168 
169 	/* Convert character length */
170 	if (ctrlbits & IOCTRL_BITS_8)
171 		rv |= CS8;
172 	else
173 	if (ctrlbits & IOCTRL_BITS_7)
174 		rv |= CS7;
175 	else
176 	if (ctrlbits & IOCTRL_BITS_6)
177 		rv |= CS6;
178 	else
179 	if (ctrlbits & IOCTRL_BITS_5)
180 		rv |= CS5;
181 	else
182 		panic("ioctrl2cflag: Bad character length: 0x%x", ctrlbits);
183 
184 	/* Convert number of stop bits */
185 	if (ctrlbits & IOCTRL_STOP_2)
186 		rv |= CSTOPB;
187 	else
188 	if ((ctrlbits & IOCTRL_STOP_1) == 0)
189 		panic("ioctrl2cflag: Bad number of stop bits: 0x%x", ctrlbits);
190 
191 	return (rv);
192 }
193