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