boot.c revision 8f66dec264d4b13b02d5041e7e2e73273855d66d
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
* --------------------------------------------------------------------
*
* This code is based on:
*
*
* Copyright (C) 2002 MandrakeSoft S.A.
*
* MandrakeSoft S.A.
* 43, rue d'Aboukir
* 75002 Paris - France
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <stdint.h>
#include <string.h>
#include "inlines.h"
#include "biosint.h"
#include "ebda.h"
/* Sanity check the LAN boot segment definition. */
#if VBOX_LANBOOT_SEG < 0xA000
#endif
/* PnP header used with LAN boot ROMs. */
typedef struct {
} pnp_exp_t;
#pragma aux read_boot_sec = \
"mov ax,0201h" \
"mov dh,0" \
"mov cx,1" \
"xor bx,bx" \
"int 13h" \
"mov ax,0" \
"sbb ax,0" \
//--------------------------------------------------------------------------
// print_boot_device
// displays the boot device
//--------------------------------------------------------------------------
//@todo: pass inputs as bit flags rather than bytes?
{
int i;
else return;
}
//--------------------------------------------------------------------------
// print_boot_failure
// displays the reason why boot failed
//--------------------------------------------------------------------------
//@todo: pass inputs as bit flags rather than bytes?
{
// cdboot: 1 if boot from cd, 0 otherwise
// lanboot: 1 if boot from lan, 0 otherwise
// drive : drive number
// reason: 0 signature check failed, 1 read error
// lastdrive: 1 boot drive is the last one in boot sequence
if (cdboot)
else if (lanboot)
else if (drive & 0x80)
else
if (lastdrive==1) {
if (reason==0)
BX_PANIC("No bootable medium found! System halted.\n");
else
BX_PANIC("Could not read from the boot medium! System halted.\n");
}
}
//--------------------------------------------------------------------------
// print_cdromboot_failure
// displays the reason why boot failed
//--------------------------------------------------------------------------
{
return;
}
// returns bootsegment in ax, drive in bl
{
//@todo: common code for getting the EBDA segment
// if BX_ELTORITO_BOOT is not defined, old behavior
// check bit 5 in CMOS reg 0x2d. load either 0x00 or 0x80 into DL
// in preparation for the initial INT 13h (0=floppy A:, 0x80=C:)
// 0: system boot sequence, first drive C: then A:
// 1: system boot sequence, first drive A: then C:
// else BX_ELTORITO_BOOT is defined
// CMOS regs 0x3D and 0x38 contain the boot sequence:
// CMOS reg 0x3D & 0x0f : 1st boot device
// CMOS reg 0x3D & 0xf0 : 2nd boot device
// CMOS reg 0x38 & 0xf0 : 3rd boot device
// CMOS reg 0x3C & 0x0f : 4th boot device
// boot device codes:
// 0x00 : not defined
// 0x01 : first floppy
// 0x02 : first harddrive
// 0x03 : first cdrom
// 0x04 : local area network
// else : boot failure
// Get the boot sequence
#if BX_ELTORITO_BOOT
/* Boot delay hack. */
if (bseqnr == 1)
bootlan=0;
switch(bootseq & 0x0f) {
case 0x01:
bootdrv=0x00;
bootcd=0;
break;
case 0x02:
{
// Get the Boot drive.
bootcd=0;
break;
}
case 0x03:
bootdrv=0x00;
bootcd=1;
break;
default: return 0x00000000;
}
#else
if (bseqnr==2) {
bootseq ^= 0x20;
lastdrive = 1;
}
#endif // BX_ELTORITO_BOOT
#if BX_ELTORITO_BOOT
// We have to boot from cd
if (bootcd != 0) {
status = cdrom_boot();
// If failure
if ( (status & 0x00ff) !=0 ) {
return 0x00000000;
}
}
#endif // BX_ELTORITO_BOOT
// Check for boot from LAN first
if (bootlan == 1) {
void (__far *netboot_entry)(void);
// This is NOT a generic PnP implementation, but an Etherboot-specific hack.
// Found PnP signature
// Found Etherboot ROM
}
else
{
//Found Normal Pnp ROM
int_enable(); /* Disabled as we were invoked via INT instruction. */
}
}
}
// boot from LAN will not return if successful.
return 0x00000000;
}
// We have to boot from harddisk or floppy
bootseg=0x07c0;
if (status != 0) {
return 0x00000000;
}
}
// There is *no* requirement whatsoever for a valid floppy boot sector
// to have a 55AAh signature. UNIX boot floppies typically have no such
// signature. In general, it is impossible to tell a valid bootsector
// from an invalid one.
// NB: It is somewhat common for failed OS installs to have the
// 0x55AA signature and a valid partition table but zeros in the
// rest of the boot sector. We do a quick check by comparing the first
// two words of boot sector; if identical, the boot sector is
// extremely unlikely to be valid.
#if BX_ELTORITO_BOOT
// if boot from cd, no signature check
if (bootcd != 0)
bootchk = 1;
#endif // BX_ELTORITO_BOOT
{
return 0x00000000;
}
#if BX_ELTORITO_BOOT
// Print out the boot string
#else // BX_ELTORITO_BOOT
#endif // BX_ELTORITO_BOOT
// return the boot segment
}