Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / mvmeppc / stand / boot / boot.c
blob6fda69881a8d27c610d50b448b5604596870b9de
1 /* $NetBSD: boot.c,v 1.4 2007/01/24 13:08:12 hubertf Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
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.
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.
33 * Copyright (c) 1982, 1986, 1990, 1993
34 * The Regents of the University of California. All rights reserved.
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.
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.
60 * @(#)boot.c 8.1 (Berkeley) 6/10/93
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>
69 #include <lib/libkern/libkern.h>
71 #include "stand.h"
72 #include "libsa.h"
73 #include "bugsyscalls.h"
75 struct bug_bootinfo bug_bootinfo;
76 struct mvmeppc_bootinfo bootinfo;
78 static u_int32_t ioctrl2cflag(u_int32_t);
80 void
81 main(void)
83 struct bug_buginfo *bbi;
84 struct bug_boardid *bid;
85 struct bug_ioinquiry *ioi, ioinq;
86 struct bug_ioctrl ioctrl;
87 char consname[CONSOLEDEV_LEN];
88 char line[80];
89 const char *file;
90 int ask = 0, howto, part;
92 if (bug_bootinfo.bbi_bugmode == 0)
93 panic("mvmeppc-boot: PReP boot mode not supported!");
95 bbi = &bug_bootinfo.bbi_bi.bbi;
97 if ((bid = bugsys_brdid()) == NULL)
98 panic("mvmeppc-boot: bugsys_brdid() failed!");
100 ioinq.ii_boardname = consname;
101 ioinq.ii_ioctrl = &ioctrl;
102 ioinq.ii_portnum = BUG_IOINQ_PORT_CONSOLE;
103 if ((ioi = bugsys_ioinq(&ioinq)) == NULL)
104 panic("mvmeppc-boot: bugsys_ioinq() failed!");
106 if (bid->bi_devtype > 9)
107 panic("mvmeppc-boot: Bogus boot device type (%d)",
108 bid->bi_devtype);
110 printf(">> MVMEPPC boot on MVME%x\n", bid->bi_bnumber);
112 parse_args(bbi->bbi_argstart, bbi->bbi_argend, &file, &howto, &part);
114 for (;;) {
115 if (ask) {
116 printf("boot: ");
117 gets(line);
118 if (strcmp(line, "halt") == 0)
119 break;
121 if (line[0]) {
122 char *cp = line;
124 while (cp < (line + sizeof(line) - 1) && *cp)
125 cp++;
127 bbi->bbi_argstart = line;
128 bbi->bbi_argend = cp;
129 parse_args(bbi->bbi_argstart, bbi->bbi_argend,
130 &file, &howto, &part);
134 bootinfo.bi_boothowto = howto;
135 bootinfo.bi_bootaddr = bbi->bbi_devaddr;
136 bootinfo.bi_bootclun = bbi->bbi_clun;
137 bootinfo.bi_bootclun = bbi->bbi_dlun;
138 strncpy(bootinfo.bi_bootline, bbi->bbi_argstart,
139 MIN(BOOTLINE_LEN, bbi->bbi_argend - bbi->bbi_argstart));
140 strncpy(bootinfo.bi_consoledev, consname, CONSOLEDEV_LEN);
141 bootinfo.bi_consoleaddr = ioi->ii_devaddr;
142 bootinfo.bi_consolechan = ioi->ii_channel;
143 bootinfo.bi_consolespeed = ioctrl.ic_baud;
144 bootinfo.bi_consolecflag = ioctrl2cflag(ioctrl.ic_ctrlbits);
145 bootinfo.bi_modelnumber = bid->bi_bnumber;
147 exec_mvme(file, howto, part);
148 printf("boot: %s: %s\n", file, strerror(errno));
149 ask = 1;
153 static u_int32_t
154 ioctrl2cflag(u_int32_t ctrlbits)
156 u_int32_t rv;
158 rv = TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB | PARODD);
160 /* Convert parity */
161 if (ctrlbits & IOCTRL_PARITY_ODD)
162 rv |= PARENB | PARODD;
163 else
164 if (ctrlbits & IOCTRL_PARITY_EVEN)
165 rv |= PARENB;
167 /* Convert character length */
168 if (ctrlbits & IOCTRL_BITS_8)
169 rv |= CS8;
170 else
171 if (ctrlbits & IOCTRL_BITS_7)
172 rv |= CS7;
173 else
174 if (ctrlbits & IOCTRL_BITS_6)
175 rv |= CS6;
176 else
177 if (ctrlbits & IOCTRL_BITS_5)
178 rv |= CS5;
179 else
180 panic("ioctrl2cflag: Bad character length: 0x%x", ctrlbits);
182 /* Convert number of stop bits */
183 if (ctrlbits & IOCTRL_STOP_2)
184 rv |= CSTOPB;
185 else
186 if ((ctrlbits & IOCTRL_STOP_1) == 0)
187 panic("ioctrl2cflag: Bad number of stop bits: 0x%x", ctrlbits);
189 return (rv);