1 /*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * William Jolitz.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: @(#)swapgeneric.c 5.5 (Berkeley) 5/9/91
37 * $FreeBSD$
38 */
39
40 #include <sys/param.h>
41 #include <sys/conf.h>
42 #include <sys/buf.h>
43 #include <sys/mount.h>
44 #include <sys/systm.h>
45 #include <sys/reboot.h>
46 #include <sys/disklabel.h>
47 #include <sys/kernel.h>
48
49 #include <i386/i386/cons.h>
50 #include <machine/md_var.h>
51
52 #include "wd.h"
53 #include "fd.h"
54 #include "cd.h"
55 #include "da.h"
56 #include "mcd.h"
57 #include "scd.h"
58 #include "matcd.h"
59
60 /*
61 * Generic configuration; all in one
62 */
63 dev_t rootdev = NODEV;
64 dev_t dumpdev = NODEV;
65
66 void gets __P((char *));
67
68 struct genericconf {
69 char *gc_name;
70 dev_t gc_root;
71 } genericconf[] = {
72 #if NWD > 0
73 { "wd", makedev(0, 0x00000000), },
74 #endif
75 #if NFD > 0
76 { "fd", makedev(2, 0x00000000), },
77 #endif
78 #if NCD > 0
79 { "cd", makedev(6, 0x00000000), },
80 #endif
81 #if NDA > 0
82 { "da", makedev(4, 0x00000000), },
83 #endif
84 #if NMCD > 0
85 { "mcd", makedev(7, 0x00000000), },
86 #endif
87 #if NSCD > 0
88 { "scd", makedev(16,0x00000000), },
89 #endif
90 #if NMATCD > 0
91 { "matcd", makedev(17,0x00000000), },
92 #endif
93 { 0 },
94 };
95
96 void setconf(void)
97 {
98 register struct genericconf *gc;
99 int bd;
100 int unit, swaponroot = 0;
101
102 if (rootdev != NODEV)
103 return;
104 if (boothowto & RB_ASKNAME) {
105 char name[128];
106 retry:
107 printf("root device? ");
108 gets(name);
109 for (gc = genericconf; gc->gc_name; gc++)
110 if (gc->gc_name[0] == name[0] &&
111 gc->gc_name[1] == name[1])
112 goto gotit;
113 goto bad;
114 gotit:
115 if (name[3] == '*') {
116 name[3] = name[4];
117 swaponroot++;
118 }
119 if (name[2] >= '' && name[2] <= '7' && name[3] == 0) {
120 unit = name[2] - '';
121 goto found;
122 }
123 printf("bad/missing unit number\n");
124 bad:
125 printf("use dk%%d\n");
126 goto retry;
127 }
128 /* XXX */
129 if (strcmp(mountrootfsname, "nfs") == 0) {
130 /*
131 * The NFS code in nfs_vfsops.c handles root and swap
132 * for us if we're booting diskless. This is just to
133 * make swapconf() happy.
134 */
135 dumplo = -1;
136 return;
137 }
138 unit = 0;
139 for (gc = genericconf; gc->gc_name; gc++) {
140 for (bd = 0; bd < nblkdev; bd++) {
141 if (bdevsw[bd] != NULL &&
142 strcmp(bdevsw[bd]->d_name, gc->gc_name) == 0) {
143 printf("root on %s0\n", bdevsw[bd]->d_name);
144 goto found;
145 }
146 }
147 }
148 printf("no suitable root -- press any key to reboot\n\n");
149 cngetc();
150 cpu_reset();
151 for(;;) ;
152 found:
153 gc->gc_root = makedev(major(gc->gc_root), unit * MAXPARTITIONS);
154 rootdev = gc->gc_root;
155 }
156
157 void gets(cp)
158 char *cp;
159 {
160 register char *lp;
161 register int c;
162
163 lp = cp;
164 for (;;) {
165 printf("%c", c = cngetc()&0177);
166 switch (c) {
167 case -1:
168 case '\n':
169 case '\r':
170 *lp++ = '\0';
171 return;
172 case '\b':
173 case '\177':
174 if (lp > cp) {
175 printf(" \b");
176 lp--;
177 }
178 continue;
179 case '#':
180 lp--;
181 if (lp < cp)
182 lp = cp;
183 continue;
184 case '@':
185 case 'u'&037:
186 lp = cp;
187 printf("%c", '\n');
188 continue;
189 default:
190 *lp++ = c;
191 }
192 }
193 }
Cache object: 485fe9928e111db90dfa186132ff3c07
|