1b2535c44Smckusick /*
2*b8b5ca7bSbostic * Copyright (c) 1992, 1993
3*b8b5ca7bSbostic * The Regents of the University of California. All rights reserved.
4b2535c44Smckusick *
5b2535c44Smckusick * This code is derived from software contributed to Berkeley by
6b2535c44Smckusick * Ralph Campbell, and Kazumasa Utashiro of Software Research
7b2535c44Smckusick * Associates, Inc.
8b2535c44Smckusick *
9b2535c44Smckusick * %sccs.include.redist.c%
10b2535c44Smckusick *
11*b8b5ca7bSbostic * @(#)swapgeneric.c 8.1 (Berkeley) 06/16/93
12b2535c44Smckusick */
13b2535c44Smckusick
14a4eab072Sutashiro #include <sysparam.h>
15a4eab072Sutashiro #include <sysconf.h>
16a4eab072Sutashiro #include <sysbuf.h>
17a4eab072Sutashiro #include <syssystm.h>
18a4eab072Sutashiro #include <sysreboot.h>
19b2535c44Smckusick
20b2535c44Smckusick #ifdef CPU_DOUBLE
21a4eab072Sutashiro #include <news3400/iop/iopvar.h>
22b2535c44Smckusick #else /* CPU_DOUBLE */
23a4eab072Sutashiro #include <news3400/hbdev/hbvar.h>
24b2535c44Smckusick # define iop hb
25b2535c44Smckusick
26b2535c44Smckusick # define idinit hdinit
27b2535c44Smckusick
28b2535c44Smckusick # define im_driver hm_driver
29b2535c44Smckusick # define im_ctlr hm_ctlr
30b2535c44Smckusick # define im_alive hm_alive
31b2535c44Smckusick # define im_addr hm_addr
32b2535c44Smckusick # define im_intr hm_intr
33b2535c44Smckusick # define im_scnum hm_scnum
34b2535c44Smckusick # define im_hd hm_hd
35b2535c44Smckusick # define im_hbinfo hm_hbinfo
36b2535c44Smckusick # define im_tab hm_tab
37b2535c44Smckusick
38b2535c44Smckusick # define ii_driver hi_driver
39b2535c44Smckusick # define ii_unit hi_unit
40b2535c44Smckusick # define ii_ctlr hi_ctlr
41b2535c44Smckusick # define ii_slave hi_slave
42b2535c44Smckusick # define ii_addr hi_addr
43b2535c44Smckusick # define ii_intr hi_intr
44b2535c44Smckusick # define ii_dk hi_dk
45b2535c44Smckusick # define ii_flags hi_flags
46b2535c44Smckusick # define ii_alive hi_alive
47b2535c44Smckusick # define ii_type hi_type
48b2535c44Smckusick # define ii_forw hi_forw
49b2535c44Smckusick # define ii_mi hi_mi
50b2535c44Smckusick # define ii_hd hi_hd
51b2535c44Smckusick
52b2535c44Smckusick # define id_probe hd_probe
53b2535c44Smckusick # define id_slave hd_slave
54b2535c44Smckusick # define id_attach hd_attach
55b2535c44Smckusick # define id_dgo hd_dgo
56b2535c44Smckusick # define id_dname hd_dname
57b2535c44Smckusick # define id_dinfo hd_dinfo
58b2535c44Smckusick # define id_mname hd_mname
59b2535c44Smckusick # define id_minfo hd_minfo
60b2535c44Smckusick #endif /* CPU_DOUBLE */
61b2535c44Smckusick
62b2535c44Smckusick # include "sd.h"
63b2535c44Smckusick # include "hd.h"
64b2535c44Smckusick # include "fd.h"
65b2535c44Smckusick # include "od.h"
66b2535c44Smckusick
67b2535c44Smckusick /*
68b2535c44Smckusick * Generic configuration; all in one
69b2535c44Smckusick */
70b2535c44Smckusick dev_t rootdev = NODEV;
71b2535c44Smckusick dev_t argdev = NODEV;
72b2535c44Smckusick dev_t dumpdev = NODEV;
73b2535c44Smckusick int nswap;
74b2535c44Smckusick struct swdevt swdevt[] = {
75b2535c44Smckusick { -1, 1, 0 },
76986a99baSmckusick { NODEV, 0, 0 },
77b2535c44Smckusick };
78b2535c44Smckusick int dmmin, dmmax, dmtext;
79b2535c44Smckusick
80b2535c44Smckusick # if NSDC > 0
81b2535c44Smckusick extern struct iop/**/_driver sdcdriver;
82b2535c44Smckusick # endif
83b2535c44Smckusick # if NHC > 0
84b2535c44Smckusick extern struct iop/**/_driver hcdriver;
85b2535c44Smckusick # endif
86b2535c44Smckusick # if NFC > 0
87b2535c44Smckusick extern struct iop/**/_driver fcdriver;
88b2535c44Smckusick # endif
89b2535c44Smckusick # if NOC > 0
90b2535c44Smckusick extern struct iop/**/_driver ocdriver;
91b2535c44Smckusick # endif
92b2535c44Smckusick
93b2535c44Smckusick struct genericconf {
94b2535c44Smckusick caddr_t gc_driver;
95b2535c44Smckusick char *gc_name;
96b2535c44Smckusick dev_t gc_root;
97b2535c44Smckusick } genericconf[] = {
98b2535c44Smckusick # if NSDC > 0
99b2535c44Smckusick { (caddr_t)&sdcdriver, "sd", makedev(0, 0), },
100b2535c44Smckusick # endif
101b2535c44Smckusick # if NHC > 0
102b2535c44Smckusick { (caddr_t)&hcdriver, "hd", makedev(0, 0), },
103b2535c44Smckusick # endif
104b2535c44Smckusick # if NFC > 0
105b2535c44Smckusick { (caddr_t)&fcdriver, "fh", makedev(1, 0), },
106b2535c44Smckusick { (caddr_t)&fcdriver, "fd", makedev(1, 1), },
107b2535c44Smckusick # endif
108b2535c44Smckusick # if NOC > 0
109b2535c44Smckusick { (caddr_t)&ocdriver, "od", makedev(10, 0), },
110b2535c44Smckusick # endif
111b2535c44Smckusick { 0 },
112b2535c44Smckusick };
113b2535c44Smckusick
setconf()114b2535c44Smckusick setconf()
115b2535c44Smckusick {
116b2535c44Smckusick register struct scsi_device *dp;
117b2535c44Smckusick register struct genericconf *gc;
118b2535c44Smckusick register char *cp, *gp;
119b2535c44Smckusick int unit, swaponroot = 0;
120b2535c44Smckusick
121b2535c44Smckusick if (rootdev != NODEV)
122b2535c44Smckusick goto doswap;
123b2535c44Smckusick unit = 0;
124b2535c44Smckusick if (boothowto & RB_ASKNAME) {
125b2535c44Smckusick char name[128];
126b2535c44Smckusick retry:
127b2535c44Smckusick printf("root device? ");
128b2535c44Smckusick gets(name);
129b2535c44Smckusick for (gc = genericconf; gc->gc_driver; gc++)
130b2535c44Smckusick for (cp = name, gp = gc->gc_name; *cp == *gp; cp++)
131b2535c44Smckusick if (*++gp == 0)
132b2535c44Smckusick goto gotit;
133b2535c44Smckusick printf("use one of:");
134b2535c44Smckusick for (gc = genericconf; gc->gc_driver; gc++)
135b2535c44Smckusick printf(" %s%%d", gc->gc_name);
136b2535c44Smckusick printf("\n");
137b2535c44Smckusick goto retry;
138b2535c44Smckusick gotit:
139b2535c44Smckusick if (*++cp < '0' || *cp > '9') {
140b2535c44Smckusick printf("bad/missing unit number\n");
141b2535c44Smckusick goto retry;
142b2535c44Smckusick }
143b2535c44Smckusick while (*cp >= '0' && *cp <= '9')
144b2535c44Smckusick unit = 10 * unit + *cp++ - '0';
145b2535c44Smckusick if (*cp == '*')
146b2535c44Smckusick swaponroot++;
147b2535c44Smckusick goto found;
148b2535c44Smckusick }
149b2535c44Smckusick for (gc = genericconf; gc->gc_driver; gc++) {
150b2535c44Smckusick for (dp = scsi_dinit; dp->sd_driver; dp++) {
151b2535c44Smckusick if (dp->sd_alive == 0)
152b2535c44Smckusick continue;
153b2535c44Smckusick if (dp->sd_unit == unit &&
154b2535c44Smckusick dp->sd_driver == (struct driver *)gc->gc_driver) {
155b2535c44Smckusick printf("root on %s%d%c\n",
156b2535c44Smckusick dp->sd_driver->d_name, unit,
157b2535c44Smckusick "ab"[swaponroot]);
158b2535c44Smckusick goto found;
159b2535c44Smckusick }
160b2535c44Smckusick }
161b2535c44Smckusick }
162b2535c44Smckusick printf("no suitable root\n");
163b2535c44Smckusick goto retry;
164b2535c44Smckusick found:
165b2535c44Smckusick gc->gc_root = makedev(major(gc->gc_root), unit*8);
166b2535c44Smckusick rootdev = gc->gc_root;
167b2535c44Smckusick doswap:
168b2535c44Smckusick swdevt[0].sw_dev = argdev = dumpdev =
169b2535c44Smckusick makedev(major(rootdev), minor(rootdev)+1);
170b2535c44Smckusick /* swap size and dumplo set during autoconfigure */
171b2535c44Smckusick if (swaponroot)
172b2535c44Smckusick rootdev = dumpdev;
173b2535c44Smckusick }
174b2535c44Smckusick
gets(cp)175b2535c44Smckusick gets(cp)
176b2535c44Smckusick char *cp;
177b2535c44Smckusick {
178b2535c44Smckusick register char *lp;
179b2535c44Smckusick register c;
180b2535c44Smckusick int s;
181b2535c44Smckusick
182b2535c44Smckusick lp = cp;
183b2535c44Smckusick s = spltty();
184b2535c44Smckusick for (;;) {
185b2535c44Smckusick cnputc(c = cngetc());
186b2535c44Smckusick switch (c) {
187b2535c44Smckusick case '\r':
188b2535c44Smckusick cnputc('\n');
189b2535c44Smckusick *lp++ = '\0';
190b2535c44Smckusick break;
191b2535c44Smckusick case '\n':
192b2535c44Smckusick cnputc('\r');
193b2535c44Smckusick *lp++ = '\0';
194b2535c44Smckusick break;
195b2535c44Smckusick case '\b':
196b2535c44Smckusick case '\177':
197b2535c44Smckusick if (lp > cp) {
198b2535c44Smckusick lp--;
199b2535c44Smckusick cnputc(' ');
200b2535c44Smckusick cnputc('\b');
201b2535c44Smckusick }
202b2535c44Smckusick continue;
203b2535c44Smckusick case '#':
204b2535c44Smckusick lp--;
205b2535c44Smckusick if (lp < cp)
206b2535c44Smckusick lp = cp;
207b2535c44Smckusick continue;
208b2535c44Smckusick case '@':
209b2535c44Smckusick case 'u'&037:
210b2535c44Smckusick lp = cp;
211b2535c44Smckusick cnputc('\n');
212b2535c44Smckusick continue;
213b2535c44Smckusick default:
214b2535c44Smckusick *lp++ = c;
215b2535c44Smckusick continue;
216b2535c44Smckusick }
217b2535c44Smckusick break;
218b2535c44Smckusick }
219b2535c44Smckusick splx(s);
220b2535c44Smckusick }
221