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