VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/boot.c@ 92290

Last change on this file since 92290 was 84829, checked in by vboxsync, 5 years ago

BIOS: Don't panic and hard halt when the specified boot medium is not present/readable, either.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/* $Id: boot.c 84829 2020-06-15 10:23:18Z vboxsync $ */
2/** @file
3 * PC BIOS - ???
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 * --------------------------------------------------------------------
17 *
18 * This code is based on:
19 *
20 * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
21 *
22 * Copyright (C) 2002 MandrakeSoft S.A.
23 *
24 * MandrakeSoft S.A.
25 * 43, rue d'Aboukir
26 * 75002 Paris - France
27 * http://www.linux-mandrake.com/
28 * http://www.mandrakesoft.com/
29 *
30 * This library is free software; you can redistribute it and/or
31 * modify it under the terms of the GNU Lesser General Public
32 * License as published by the Free Software Foundation; either
33 * version 2 of the License, or (at your option) any later version.
34 *
35 * This library is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 * Lesser General Public License for more details.
39 *
40 * You should have received a copy of the GNU Lesser General Public
41 * License along with this library; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
43 *
44 */
45
46/*
47 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
48 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
49 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
50 * a choice of LGPL license versions is made available with the language indicating
51 * that LGPLv2 or any later version may be used, or where a choice of which version
52 * of the LGPL is applied is otherwise unspecified.
53 */
54
55
56#include <stdint.h>
57#include <string.h>
58#include "inlines.h"
59#include "biosint.h"
60#include "ebda.h"
61
62/* Sanity check the LAN boot segment definition. */
63#if VBOX_LANBOOT_SEG < 0xA000
64#error VBOX_LANBOOT_SEG incorrect!
65#endif
66
67/* PnP header used with LAN boot ROMs. */
68typedef struct {
69 uint32_t sig;
70 uint8_t revision;
71 uint8_t length;
72 uint16_t next_s;
73 uint8_t pad1;
74 uint8_t checksum;
75 uint32_t dev_id;
76 uint16_t mfg_string;
77 uint16_t prod_string;
78 uint8_t base_class;
79 uint8_t subclass;
80 uint8_t interface;
81 uint8_t dev_ind;
82 uint16_t boot_code;
83 uint16_t dv;
84 uint16_t bev;
85 uint16_t pad2;
86 uint16_t sriv;
87} pnp_exp_t;
88
89
90int read_boot_sec(uint8_t bootdrv, uint16_t segment);
91#pragma aux read_boot_sec = \
92 "mov ax,0201h" \
93 "mov dh,0" \
94 "mov cx,1" \
95 "xor bx,bx" \
96 "int 13h" \
97 "mov ax,0" \
98 "sbb ax,0" \
99 parm [dl] [es] modify [ax bx cx dx];
100
101//--------------------------------------------------------------------------
102// print_boot_device
103// displays the boot device
104//--------------------------------------------------------------------------
105
106static const char drivetypes[][10]={"Floppy","Hard Disk","CD-ROM","LAN"};
107
108/// @todo pass inputs as bit flags rather than bytes?
109void print_boot_device(uint8_t cdboot, uint8_t lanboot, uint8_t drive)
110{
111 int i;
112
113 // cdboot contains 0 if lan/floppy/harddisk, 1 otherwise
114 // lanboot contains 0 if floppy/harddisk, 1 otherwise
115 // drive contains real/emulated boot drive
116
117 if(cdboot)i=2; // CD-Rom
118 else if(lanboot)i=3; // LAN
119 else if((drive&0x0080)==0x00)i=0; // Floppy
120 else if((drive&0x0080)==0x80)i=1; // Hard drive
121 else return;
122
123 BX_INFO("Booting from %s...\n",drivetypes[i]);
124}
125
126//--------------------------------------------------------------------------
127// print_boot_failure
128// displays the reason why boot failed
129//--------------------------------------------------------------------------
130/// @todo pass inputs as bit flags rather than bytes?
131void print_boot_failure(uint8_t cdboot, uint8_t lanboot, uint8_t drive,
132 uint8_t reason, uint8_t lastdrive)
133{
134 uint16_t drivenum = drive&0x7f;
135
136 // cdboot: 1 if boot from cd, 0 otherwise
137 // lanboot: 1 if boot from lan, 0 otherwise
138 // drive : drive number
139 // reason: 0 signature check failed, 1 read error
140 // lastdrive: 1 boot drive is the last one in boot sequence
141
142 if (cdboot)
143 BX_INFO("Boot from %s failed\n",drivetypes[2]);
144 else if (lanboot)
145 BX_INFO("Boot from %s failed\n",drivetypes[3]);
146 else if (drive & 0x80)
147 BX_INFO("Boot from %s %d failed\n", drivetypes[1],drivenum);
148 else
149 BX_INFO("Boot from %s %d failed\n", drivetypes[0],drivenum);
150
151 if (lastdrive==1) {
152 if (reason==0)
153 BX_INFO_CON("No bootable medium found!\n");
154 else
155 BX_INFO_CON("Could not read from the boot medium!\n");
156 BX_INFO_CON("Please insert a bootable medium and reboot.\n");
157 }
158}
159
160//--------------------------------------------------------------------------
161// print_cdromboot_failure
162// displays the reason why boot failed
163//--------------------------------------------------------------------------
164void print_cdromboot_failure(uint16_t code)
165{
166 BX_INFO("CDROM boot failure code : %04x\n",code);
167 return;
168}
169
170// returns bootsegment in ax, drive in bl
171uint32_t BIOSCALL int19_function(uint8_t bseqnr)
172{
173 /// @todo common code for getting the EBDA segment
174 uint16_t ebda_seg=read_word(0x0040,0x000E);
175 uint16_t bootseq;
176 uint8_t bootdrv;
177 uint8_t bootcd;
178 uint8_t bootlan;
179 uint8_t bootchk;
180 uint16_t bootseg;
181 uint16_t status;
182 uint8_t lastdrive=0;
183
184 // if BX_ELTORITO_BOOT is not defined, old behavior
185 // check bit 5 in CMOS reg 0x2d. load either 0x00 or 0x80 into DL
186 // in preparation for the initial INT 13h (0=floppy A:, 0x80=C:)
187 // 0: system boot sequence, first drive C: then A:
188 // 1: system boot sequence, first drive A: then C:
189 // else BX_ELTORITO_BOOT is defined
190 // CMOS regs 0x3D and 0x38 contain the boot sequence:
191 // CMOS reg 0x3D & 0x0f : 1st boot device
192 // CMOS reg 0x3D & 0xf0 : 2nd boot device
193 // CMOS reg 0x38 & 0xf0 : 3rd boot device
194 // CMOS reg 0x3C & 0x0f : 4th boot device
195 // boot device codes:
196 // 0x00 : not defined
197 // 0x01 : first floppy
198 // 0x02 : first harddrive
199 // 0x03 : first cdrom
200 // 0x04 : local area network
201 // else : boot failure
202
203 // Get the boot sequence
204#if BX_ELTORITO_BOOT
205 bootseq=inb_cmos(0x3d);
206 bootseq|=((inb_cmos(0x38) & 0xf0) << 4);
207 bootseq|=((inb_cmos(0x3c) & 0x0f) << 12);
208 if (read_byte(ebda_seg, (uint16_t)&EbdaData->uForceBootDevice))
209 bootseq = read_byte(ebda_seg, (uint16_t)&EbdaData->uForceBootDevice);
210 /* Boot delay hack. */
211 if (bseqnr == 1)
212 delay_boot((inb_cmos(0x3c) & 0xf0) >> 4); /* Implemented in logo.c */
213
214 if (bseqnr==2) bootseq >>= 4;
215 if (bseqnr==3) bootseq >>= 8;
216 if (bseqnr==4) bootseq >>= 12;
217 if (bootseq<0x10) lastdrive = 1;
218 bootdrv=0x00; bootcd=0;
219 bootlan=0;
220 BX_INFO("Boot : bseqnr=%d, bootseq=%x\r\n",bseqnr, bootseq);
221
222 switch(bootseq & 0x0f) {
223 case 0x01:
224 bootdrv=0x00;
225 bootcd=0;
226 break;
227 case 0x02:
228 {
229 // Get the Boot drive.
230 uint8_t boot_drive = read_byte(ebda_seg, (uint16_t)&EbdaData->uForceBootDrive);
231
232 bootdrv = boot_drive + 0x80;
233 bootcd=0;
234 break;
235 }
236 case 0x03:
237 bootdrv=0x00;
238 bootcd=1;
239 break;
240 case 0x04: bootlan=1; break;
241 default: return 0x00000000;
242 }
243#else
244 bootseq=inb_cmos(0x2d);
245
246 if (bseqnr==2) {
247 bootseq ^= 0x20;
248 lastdrive = 1;
249 }
250 bootdrv=0x00; bootcd=0;
251 if((bootseq&0x20)==0) bootdrv=0x80;
252#endif // BX_ELTORITO_BOOT
253
254#if BX_ELTORITO_BOOT
255 // We have to boot from cd
256 if (bootcd != 0) {
257 status = cdrom_boot();
258
259 // If failure
260 if ( (status & 0x00ff) !=0 ) {
261 print_cdromboot_failure(status);
262 print_boot_failure(bootcd, bootlan, bootdrv, 1, lastdrive);
263 return 0x00000000;
264 }
265
266 bootseg = read_word(ebda_seg,(uint16_t)&EbdaData->cdemu.load_segment);
267 bootdrv = (uint8_t)(status>>8);
268 }
269
270#endif // BX_ELTORITO_BOOT
271
272 // Check for boot from LAN first
273 if (bootlan == 1) {
274 uint8_t __far *fplan;
275
276 fplan = MK_FP(VBOX_LANBOOT_SEG, 0);
277 if (*(uint16_t __far *)fplan == 0xaa55) {
278 pnp_exp_t __far *pnps;
279 uint32_t manuf;
280 void (__far *netboot_entry)(void);
281
282 // This is NOT a generic PnP implementation, but an Etherboot-specific hack.
283 pnps = (void __far *)(fplan + *(uint16_t __far *)(fplan + 0x1a));
284 if (pnps->sig == 0x506e5024/* '$PnP' */) {
285 // Found PnP signature
286 manuf = *(uint32_t __far *)(fplan + pnps->mfg_string);
287 if (manuf == 0x65687445/* 'Ethe' */) {
288 // Found Etherboot ROM
289 print_boot_device(bootcd, bootlan, bootdrv);
290 netboot_entry = (void __far *)(fplan + 6);
291 netboot_entry();
292 }
293 else
294 {
295 //Found Normal Pnp ROM
296 print_boot_device(bootcd, bootlan, bootdrv);
297 int_enable(); /* Disabled as we were invoked via INT instruction. */
298 netboot_entry = (void __far *)(fplan + pnps->bev);
299 netboot_entry();
300 }
301 }
302 }
303
304 // boot from LAN will not return if successful.
305 print_boot_failure(bootcd, bootlan, bootdrv, 1, lastdrive);
306 return 0x00000000;
307 }
308
309 // We have to boot from harddisk or floppy
310 if (bootcd == 0 && bootlan == 0) {
311 bootseg=0x07c0;
312
313 status = read_boot_sec(bootdrv,bootseg);
314 if (status != 0) {
315 print_boot_failure(bootcd, bootlan, bootdrv, 1, lastdrive);
316 return 0x00000000;
317 }
318 }
319
320 // There is *no* requirement whatsoever for a valid floppy boot sector
321 // to have a 55AAh signature. UNIX boot floppies typically have no such
322 // signature. In general, it is impossible to tell a valid bootsector
323 // from an invalid one.
324 // NB: It is somewhat common for failed OS installs to have the
325 // 0x55AA signature and a valid partition table but zeros in the
326 // rest of the boot sector. We do a quick check by comparing the first
327 // and third word of boot sector; if identical, the boot sector is
328 // extremely unlikely to be valid.
329 if (bootdrv != 0) bootchk = 0;
330 else bootchk = 1; /* disable 0x55AA signature check on drive A: */
331
332#if BX_ELTORITO_BOOT
333 // if boot from cd, no signature check
334 if (bootcd != 0)
335 bootchk = 1;
336#endif // BX_ELTORITO_BOOT
337
338 if (read_word(bootseg,0) == read_word(bootseg,4)
339 || (bootchk == 0 && read_word(bootseg,0x1fe) != 0xaa55))
340 {
341 print_boot_failure(bootcd, bootlan, bootdrv, 0, lastdrive);
342 return 0x00000000;
343 }
344
345#if BX_ELTORITO_BOOT
346 // Print out the boot string
347 print_boot_device(bootcd, bootlan, bootdrv);
348#else // BX_ELTORITO_BOOT
349 print_boot_device(0, bootlan, bootdrv);
350#endif // BX_ELTORITO_BOOT
351
352 // return the boot segment
353 return (((uint32_t)bootdrv) << 16) + bootseg;
354}
355
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette