Print this page
XXX nobios
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/os/biosdisk.c
+++ new/usr/src/uts/i86pc/os/biosdisk.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/param.h>
28 28 #include <sys/controlregs.h>
29 29 #include <sys/bootconf.h>
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
30 30 #include <sys/bootvfs.h>
31 31 #include <sys/bootregs.h>
32 32 #include <sys/bootconf.h>
33 33 #include <sys/conf.h>
34 34 #include <sys/promif.h>
35 35 #include <sys/ddi.h>
36 36 #include <sys/sunddi.h>
37 37 #include <sys/sunndi.h>
38 38 #include <sys/biosdisk.h>
39 39 #include <sys/psw.h>
40 +#include <sys/machsystm.h>
40 41 #if defined(__xpv)
41 42 #include <sys/hypervisor.h>
42 43 #endif
43 44
44 45 extern int prom_debug;
45 46
46 47 /* hard code realmode memory address for now */
47 48 #define BIOS_RES_BUFFER_ADDR 0x7000
48 49
49 50 #define BIOSDEV_NUM 8
50 51 #define STARTING_DRVNUM 0x80
51 52 #define FP_OFF(fp) (((uintptr_t)(fp)) & 0xFFFF)
52 53 #define FP_SEG(fp) ((((uintptr_t)(fp)) >> 16) & 0xFFFF)
53 54
54 55 #ifdef DEBUG
55 56 int biosdebug = 0;
56 57 #define dprintf(fmt) \
57 58 if (biosdebug) \
58 59 prom_printf fmt
59 60 #else
60 61 #define dprintf(fmt)
61 62 #endif
62 63
63 64 biosdev_data_t biosdev_info[BIOSDEV_NUM]; /* from 0x80 to 0x87 */
64 65 int dobiosdev = 1;
65 66
66 67
67 68 static int bios_check_extension_present(uchar_t);
68 69 static int get_dev_params(uchar_t);
69 70 static int read_firstblock(uchar_t drivenum);
70 71 static int drive_present(uchar_t drivenum);
71 72 static void reset_disk(uchar_t drivenum);
72 73 static int is_eltorito(uchar_t drivenum);
73 74
74 75 #if !defined(__xpv)
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
75 76 void
76 77 startup_bios_disk()
77 78 {
78 79 uchar_t drivenum;
79 80 int got_devparams = 0;
80 81 int got_first_block = 0;
81 82 uchar_t name[20];
82 83 dev_info_t *devi;
83 84 int extensions;
84 85
85 - if (dobiosdev == 0)
86 + if (dobiosdev == 0 || !bios_calls_available) {
87 + /*
88 + * If BIOS calls have been disabled, or are not supported on
89 + * this system, we cannot probe for the startup disk.
90 + */
86 91 return;
92 + }
87 93
88 94 for (drivenum = 0x80; drivenum < (0x80 + BIOSDEV_NUM); drivenum++) {
89 95
90 96 if (!drive_present(drivenum))
91 97 continue;
92 98
93 99 extensions = bios_check_extension_present(drivenum);
94 100
95 101 /*
96 102 * If we're booting from an Eltorito CD/DVD image, there's
97 103 * no need to get the device parameters or read the first block
98 104 * because we'll never install onto this device.
99 105 */
100 106 if (extensions && is_eltorito(drivenum))
101 107 continue;
102 108
103 109 if (extensions && get_dev_params(drivenum))
104 110 got_devparams = 1;
105 111 else
106 112 got_devparams = 0;
107 113
108 114 if ((got_first_block = read_firstblock(drivenum)) == 0) {
109 115 /* retry */
110 116 got_first_block = read_firstblock(drivenum);
111 117 }
112 118
113 119 if (got_devparams || got_first_block) {
114 120 (void) sprintf((char *)name, "biosdev-0x%x", drivenum);
115 121 devi = ddi_root_node();
116 122 (void) e_ddi_prop_update_byte_array(DDI_DEV_T_NONE,
117 123 devi, (char *)name,
118 124 (uchar_t *)&biosdev_info[drivenum - 0x80],
119 125 sizeof (biosdev_data_t));
120 126 }
121 127 }
122 128 }
123 129 #endif
124 130
125 131 static int
126 132 bios_check_extension_present(uchar_t drivenum)
127 133 {
128 134 struct bop_regs rp = {0};
129 135 extern struct bootops *bootops;
130 136
131 137 rp.eax.word.ax = 0x4100;
132 138 rp.ebx.word.bx = 0x55AA;
133 139 rp.edx.word.dx = drivenum;
134 140
135 141 /* make sure we have extension support */
136 142 BOP_DOINT(bootops, 0x13, &rp);
137 143
138 144 if (((rp.eflags & PS_C) != 0) || (rp.ebx.word.bx != 0xAA55)) {
139 145 dprintf(("bios_check_extension_present int13 fn 41 "
140 146 "failed %d bx = %x\n", rp.eflags, rp.ebx.word.bx));
141 147 return (0);
142 148 }
143 149
144 150 if ((rp.ecx.word.cx & 0x7) == 0) {
145 151 dprintf(("bios_check_extension_present get device parameters "
146 152 "not supported cx = %x\n", rp.ecx.word.cx));
147 153 return (0);
148 154 }
149 155
150 156 return (1);
151 157 }
152 158
153 159 static int
154 160 get_dev_params(uchar_t drivenum)
155 161 {
156 162 struct bop_regs rp = {0};
157 163 fn48_t *bufp;
158 164 extern struct bootops *bootops;
159 165 int i;
160 166 int index;
161 167 uchar_t *tmp;
162 168
163 169 dprintf(("In get_dev_params\n"));
164 170
165 171 bufp = (fn48_t *)BIOS_RES_BUFFER_ADDR;
166 172
167 173 /*
168 174 * We cannot use bzero here as we're initializing data
169 175 * at an address below kernel base.
170 176 */
171 177 for (i = 0; i < sizeof (*bufp); i++)
172 178 ((uchar_t *)bufp)[i] = 0;
173 179
174 180 bufp->buflen = sizeof (*bufp);
175 181 rp.eax.word.ax = 0x4800;
176 182 rp.edx.byte.dl = drivenum;
177 183
178 184 rp.esi.word.si = (uint16_t)FP_OFF((uint_t)(uintptr_t)bufp);
179 185 rp.ds = FP_SEG((uint_t)(uintptr_t)bufp);
180 186
181 187 BOP_DOINT(bootops, 0x13, &rp);
182 188
183 189 if ((rp.eflags & PS_C) != 0) {
184 190 dprintf(("EDD FAILED on drive eflag = %x ah= %x\n",
185 191 rp.eflags, rp.eax.byte.ah));
186 192 return (0);
187 193 }
188 194
189 195 index = drivenum - 0x80;
190 196 biosdev_info[index].edd_valid = 1;
191 197
192 198 /*
193 199 * Some compilers turn a structure copy into a call
194 200 * to memcpy. Since we are copying data below kernel
195 201 * base intentionally, and memcpy asserts that's not
196 202 * the case, we do the copy manually here.
197 203 */
198 204 tmp = (uchar_t *)&biosdev_info[index].fn48_dev_params;
199 205 for (i = 0; i < sizeof (*bufp); i++)
200 206 tmp[i] = ((uchar_t *)bufp)[i];
201 207
202 208 return (1);
203 209 }
204 210
205 211 static int
206 212 drive_present(uchar_t drivenum)
207 213 {
208 214 struct bop_regs rp = {0};
209 215
210 216 rp.eax.byte.ah = 0x8; /* get params */
211 217 rp.edx.byte.dl = drivenum;
212 218
213 219 BOP_DOINT(bootops, 0x13, &rp);
214 220
215 221 if (((rp.eflags & PS_C) != 0) || rp.eax.byte.ah != 0) {
216 222 dprintf(("drive not present drivenum %x eflag %x ah %x\n",
217 223 drivenum, rp.eflags, rp.eax.byte.ah));
218 224 return (0);
219 225 }
220 226
221 227 dprintf(("drive-present %x\n", drivenum));
222 228 return (1);
223 229 }
224 230
225 231 static void
226 232 reset_disk(uchar_t drivenum)
227 233 {
228 234 struct bop_regs rp = {0};
229 235 int status;
230 236
231 237 rp.eax.byte.ah = 0x0; /* reset disk */
232 238 rp.edx.byte.dl = drivenum;
233 239
234 240 BOP_DOINT(bootops, 0x13, &rp);
235 241
236 242 status = rp.eax.byte.ah;
237 243
238 244 if (((rp.eflags & PS_C) != 0) || status != 0)
239 245 dprintf(("Bad disk reset driv %x, status %x\n", drivenum,
240 246 status));
241 247 }
242 248
243 249 /* Get first block */
244 250 static int
245 251 read_firstblock(uchar_t drivenum)
246 252 {
247 253
248 254 struct bop_regs rp = {0};
249 255 caddr_t bufp;
250 256 uchar_t status;
251 257 int i, index;
252 258
253 259
254 260 reset_disk(drivenum);
255 261 bufp = (caddr_t)BIOS_RES_BUFFER_ADDR;
256 262
257 263
258 264 rp.eax.byte.ah = 0x2; /* Read disk */
259 265 rp.eax.byte.al = 1; /* nsect */
260 266 rp.ecx.byte.ch = 0; /* cyl & 0xff */
261 267 rp.ecx.byte.cl = 1; /* cyl >> 2 & 0xc0 (sector number) */
262 268 rp.edx.byte.dh = 0; /* head */
263 269 rp.edx.byte.dl = drivenum; /* drivenum */
264 270
265 271 /* es:bx is buf address */
266 272 rp.ebx.word.bx = (uint16_t)FP_OFF((uint_t)(uintptr_t)bufp);
267 273 rp.es = FP_SEG((uint_t)(uintptr_t)bufp);
268 274
269 275 BOP_DOINT(bootops, 0x13, &rp);
270 276
271 277 status = rp.eax.byte.ah;
272 278 if (((rp.eflags & PS_C) != 0) || status != 0) {
273 279 dprintf(("read_firstblock AH not clear %x \n", status));
274 280 return (0);
275 281 }
276 282
277 283 dprintf(("drivenum %x uid at 0x1b8 is %x\n", drivenum,
278 284 *(uint32_t *)(bufp +0x1b8)));
279 285
280 286 index = drivenum - 0x80;
281 287
282 288 biosdev_info[index].first_block_valid = 1;
283 289 for (i = 0; i < 512; i++)
284 290 biosdev_info[index].first_block[i] = *((uchar_t *)bufp + i);
285 291
286 292 return (1);
287 293 }
288 294
289 295 static int
290 296 is_eltorito(uchar_t drivenum)
291 297 {
292 298 struct bop_regs rp = {0};
293 299 fn4b_t *bufp;
294 300 extern struct bootops *bootops;
295 301 int i;
296 302
297 303 dprintf(("In is_eltorito\n"));
298 304
299 305 bufp = (fn4b_t *)BIOS_RES_BUFFER_ADDR;
300 306
301 307 /*
302 308 * We cannot use bzero here as we're initializing data
303 309 * at an address below kernel base.
304 310 */
305 311 for (i = 0; i < sizeof (*bufp); i++)
306 312 ((uchar_t *)bufp)[i] = 0;
307 313
308 314 bufp->pkt_size = sizeof (*bufp);
309 315 rp.eax.word.ax = 0x4b01;
310 316 rp.edx.byte.dl = drivenum;
311 317
312 318 rp.esi.word.si = (uint16_t)FP_OFF((uint_t)(uintptr_t)bufp);
313 319 rp.ds = FP_SEG((uint_t)(uintptr_t)bufp);
314 320
315 321 BOP_DOINT(bootops, 0x13, &rp);
316 322
317 323 if ((rp.eflags & PS_C) != 0 || bufp->drivenum != drivenum) {
318 324 dprintf(("fn 0x4b01 FAILED on drive "
319 325 "eflags=%x ah=%x drivenum=%x\n",
320 326 rp.eflags, rp.eax.byte.ah, bufp->drivenum));
321 327 return (0);
322 328 }
323 329
324 330 if (prom_debug)
325 331 prom_printf("INT13 FN4B01 mtype => %x", bufp->boot_mtype);
326 332
327 333 return (1);
328 334 }
↓ open down ↓ |
232 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX