Home | History | Annotate | Line # | Download | only in boot
boot.c revision 1.3.20.1
      1 /*	$NetBSD: boot.c,v 1.3.20.1 2007/02/01 08:48:09 ad 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/termios.h>
     73 #include <sys/ttydefaults.h>
     74 #include <machine/bootinfo.h>
     75 
     76 #include <lib/libkern/libkern.h>
     77 
     78 #include "stand.h"
     79 #include "libsa.h"
     80 #include "bugsyscalls.h"
     81 
     82 struct bug_bootinfo	bug_bootinfo;
     83 struct mvmeppc_bootinfo	bootinfo;
     84 
     85 static u_int32_t ioctrl2cflag(u_int32_t);
     86 
     87 void
     88 main(void)
     89 {
     90 	struct bug_buginfo *bbi;
     91 	struct bug_boardid *bid;
     92 	struct bug_ioinquiry *ioi, ioinq;
     93 	struct bug_ioctrl ioctrl;
     94 	char consname[CONSOLEDEV_LEN];
     95 	char line[80];
     96 	const char *file;
     97 	int ask = 0, howto, part;
     98 
     99 	if (bug_bootinfo.bbi_bugmode == 0)
    100 		panic("mvmeppc-boot: PReP boot mode not supported!");
    101 
    102 	bbi = &bug_bootinfo.bbi_bi.bbi;
    103 
    104 	if ((bid = bugsys_brdid()) == NULL)
    105 		panic("mvmeppc-boot: bugsys_brdid() failed!");
    106 
    107 	ioinq.ii_boardname = consname;
    108 	ioinq.ii_ioctrl = &ioctrl;
    109 	ioinq.ii_portnum = BUG_IOINQ_PORT_CONSOLE;
    110 	if ((ioi = bugsys_ioinq(&ioinq)) == NULL)
    111 		panic("mvmeppc-boot: bugsys_ioinq() failed!");
    112 
    113 	if (bid->bi_devtype > 9)
    114 		panic("mvmeppc-boot: Bogus boot device type (%d)",
    115 		    bid->bi_devtype);
    116 
    117 	printf(">> MVMEPPC boot on MVME%x\n", bid->bi_bnumber);
    118 
    119 	parse_args(bbi->bbi_argstart, bbi->bbi_argend, &file, &howto, &part);
    120 
    121 	for (;;) {
    122 		if (ask) {
    123 			printf("boot: ");
    124 			gets(line);
    125 			if (strcmp(line, "halt") == 0)
    126 				break;
    127 
    128 			if (line[0]) {
    129 				char *cp = line;
    130 
    131 				while (cp < (line + sizeof(line) - 1) && *cp)
    132 					cp++;
    133 
    134 				bbi->bbi_argstart = line;
    135 				bbi->bbi_argend = cp;
    136 				parse_args(bbi->bbi_argstart, bbi->bbi_argend,
    137 				    &file, &howto, &part);
    138 			}
    139 		}
    140 
    141 		bootinfo.bi_boothowto = howto;
    142 		bootinfo.bi_bootaddr = bbi->bbi_devaddr;
    143 		bootinfo.bi_bootclun = bbi->bbi_clun;
    144 		bootinfo.bi_bootclun = bbi->bbi_dlun;
    145 		strncpy(bootinfo.bi_bootline, bbi->bbi_argstart,
    146 		    MIN(BOOTLINE_LEN, bbi->bbi_argend - bbi->bbi_argstart));
    147 		strncpy(bootinfo.bi_consoledev, consname, CONSOLEDEV_LEN);
    148 		bootinfo.bi_consoleaddr = ioi->ii_devaddr;
    149 		bootinfo.bi_consolechan = ioi->ii_channel;
    150 		bootinfo.bi_consolespeed = ioctrl.ic_baud;
    151 		bootinfo.bi_consolecflag = ioctrl2cflag(ioctrl.ic_ctrlbits);
    152 		bootinfo.bi_modelnumber = bid->bi_bnumber;
    153 
    154 		exec_mvme(file, howto, part);
    155 		printf("boot: %s: %s\n", file, strerror(errno));
    156 		ask = 1;
    157 	}
    158 }
    159 
    160 static u_int32_t
    161 ioctrl2cflag(u_int32_t ctrlbits)
    162 {
    163 	u_int32_t rv;
    164 
    165 	rv = TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB | PARODD);
    166 
    167 	/* Convert parity */
    168 	if (ctrlbits & IOCTRL_PARITY_ODD)
    169 		rv |= PARENB | PARODD;
    170 	else
    171 	if (ctrlbits & IOCTRL_PARITY_EVEN)
    172 		rv |= PARENB;
    173 
    174 	/* Convert character length */
    175 	if (ctrlbits & IOCTRL_BITS_8)
    176 		rv |= CS8;
    177 	else
    178 	if (ctrlbits & IOCTRL_BITS_7)
    179 		rv |= CS7;
    180 	else
    181 	if (ctrlbits & IOCTRL_BITS_6)
    182 		rv |= CS6;
    183 	else
    184 	if (ctrlbits & IOCTRL_BITS_5)
    185 		rv |= CS5;
    186 	else
    187 		panic("ioctrl2cflag: Bad character length: 0x%x", ctrlbits);
    188 
    189 	/* Convert number of stop bits */
    190 	if (ctrlbits & IOCTRL_STOP_2)
    191 		rv |= CSTOPB;
    192 	else
    193 	if ((ctrlbits & IOCTRL_STOP_1) == 0)
    194 		panic("ioctrl2cflag: Bad number of stop bits: 0x%x", ctrlbits);
    195 
    196 	return (rv);
    197 }
    198