added emc context save struct
[unix-history] / usr / src / sys / i386 / i386 / autoconf.c
CommitLineData
4bd1c0bf
WN
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 * %sccs.include.386.c%
9 *
2130ffdb 10 * @(#)autoconf.c 5.3 (Berkeley) %G%
4bd1c0bf 11 */
4fea1aeb
BJ
12
13/*
14 * Setup the system to run on the current machine.
15 *
16 * Configure() is called at boot time and initializes the vba
17 * device tables and the memory controller monitoring. Available
18 * devices are determined (from possibilities mentioned in ioconf.c),
19 * and the drivers are initialized.
20 */
21#include "param.h"
22#include "systm.h"
23#include "map.h"
24#include "buf.h"
25#include "dkstat.h"
26#include "vm.h"
27#include "conf.h"
28#include "dmap.h"
29#include "reboot.h"
30
31#include "pte.h"
4bd1c0bf 32#include "../machine/device.h"
4fea1aeb
BJ
33
34/*
35 * The following several variables are related to
36 * the configuration process, and are used in initializing
37 * the machine.
38 */
39int dkn; /* number of iostat dk numbers assigned so far */
40int cold; /* cold start flag initialized in locore.s */
41
4fea1aeb
BJ
42/*
43 * Determine i/o configuration for a machine.
44 */
45configure()
46{
47 register int *ip;
48 extern caddr_t Sysbase;
4bd1c0bf
WN
49 struct device *dvp;
50 struct driver *dp;
51 register s;
52
53 for (dvp = devtab; dp = dvp->driver; dvp++) {
54 s = splhigh();
55 dvp->alive = (*dp->probe)(dvp);
56 if (dvp->alive) {
57 printf("%s%d", dp->name, dvp->unit);
58 (*dp->attach)(dvp);
fd024d7a 59 printf(" at 0x%x on isa0\n", dvp->ioa);
4bd1c0bf
WN
60 }
61 splx(s);
62 }
4fea1aeb 63
4bd1c0bf
WN
64/*pg("setroot");*/
65#if GENERICxxx
4fea1aeb
BJ
66 if ((boothowto & RB_ASKNAME) == 0)
67 setroot();
68 setconf();
69#else
70 setroot();
71#endif
72 /*
73 * Configure swap area and related system
74 * parameter based on device(s) used.
75 */
4bd1c0bf 76/*pg("swapconf");*/
4fea1aeb
BJ
77 swapconf();
78 cold = 0;
4fea1aeb
BJ
79}
80
81/*
82 * Configure swap space and related parameters.
83 */
84swapconf()
85{
86 register struct swdevt *swp;
87 register int nblks;
88
4bd1c0bf
WN
89 for (swp = swdevt; swp->sw_dev > 0; swp++)
90 {
91 if ( swp->sw_dev < 0 || swp->sw_dev > nblkdev ) break;
4fea1aeb
BJ
92 if (bdevsw[major(swp->sw_dev)].d_psize) {
93 nblks =
94 (*bdevsw[major(swp->sw_dev)].d_psize)(swp->sw_dev);
95 if (nblks != -1 &&
96 (swp->sw_nblks == 0 || swp->sw_nblks > nblks))
97 swp->sw_nblks = nblks;
98 }
4bd1c0bf 99 }
4fea1aeb
BJ
100 if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize)
101 dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem;
102 if (dumplo < 0)
103 dumplo = 0;
104}
105
106#define DOSWAP /* change swdevt, argdev, and dumpdev too */
107u_long bootdev; /* should be dev_t, but not until 32 bits */
108
109static char devname[][2] = {
110 0,0, /* 0 = ud */
111 'd','k', /* 1 = vd */
112 0,0, /* 2 = xp */
113};
114
115#define PARTITIONMASK 0x7
116#define PARTITIONSHIFT 3
117
118/*
119 * Attempt to find the device from which we were booted.
120 * If we can do so, and not instructed not to do so,
121 * change rootdev to correspond to the load device.
122 */
123setroot()
124{
125 int majdev, mindev, unit, part, adaptor;
126 dev_t temp, orootdev;
127 struct swdevt *swp;
128
129 if (boothowto & RB_DFLTROOT ||
130 (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
131 return;
132 majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK;
133 if (majdev > sizeof(devname) / sizeof(devname[0]))
134 return;
135 adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK;
136 part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
137 unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
4fea1aeb
BJ
138 mindev = (mindev << PARTITIONSHIFT) + part;
139 orootdev = rootdev;
140 rootdev = makedev(majdev, mindev);
141 /*
142 * If the original rootdev is the same as the one
143 * just calculated, don't need to adjust the swap configuration.
144 */
145 if (rootdev == orootdev)
146 return;
147 printf("changing root device to %c%c%d%c\n",
148 devname[majdev][0], devname[majdev][1],
149 mindev >> PARTITIONSHIFT, part + 'a');
150#ifdef DOSWAP
151 mindev &= ~PARTITIONMASK;
152 for (swp = swdevt; swp->sw_dev; swp++) {
153 if (majdev == major(swp->sw_dev) &&
154 mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) {
155 temp = swdevt[0].sw_dev;
156 swdevt[0].sw_dev = swp->sw_dev;
157 swp->sw_dev = temp;
158 break;
159 }
160 }
161 if (swp->sw_dev == 0)
162 return;
163 /*
164 * If argdev and dumpdev were the same as the old primary swap
165 * device, move them to the new primary swap device.
166 */
167 if (temp == dumpdev)
168 dumpdev = swdevt[0].sw_dev;
169 if (temp == argdev)
170 argdev = swdevt[0].sw_dev;
171#endif
172}