From: Colin Finck Date: Wed, 3 May 2017 14:53:57 +0000 (+0000) Subject: [FREELDR] X-Git-Tag: ReactOS-0.4.6~780 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=11cbbbb746f265781c77d8c3fd353f78df42104d [FREELDR] Set BootPartition (DH) to 0xFF in isoboot.S when booting from CD. Then check for that 0xFF value in FreeLdr to unambiguously detect CD booting instead of using BIOS functions (which don't work reliably on broken BIOSes) or checking for an MBR (which doesn't work on hybrid ISOs). CORE-12692 svn path=/trunk/; revision=74460 --- diff --git a/reactos/boot/freeldr/bootsect/isoboot.S b/reactos/boot/freeldr/bootsect/isoboot.S index 354df591dbc..c9c3443e66e 100644 --- a/reactos/boot/freeldr/bootsect/isoboot.S +++ b/reactos/boot/freeldr/bootsect/isoboot.S @@ -310,10 +310,15 @@ found_drive: mov cx, HEX(FFFF) call getfssec - // Fetch our stored drive number to DL and set the boot partition to 0 in DH. - mov dl, byte ptr ds:[DriveNumber] - mov dh, 0 + // Pass two parameters to SETUPLDR: + // DL = BIOS Drive Number + // DH = Boot Partition (0 for HDD booting in hybrid mode, FFh for CD booting) + movzx dx, byte ptr ds:[DriveNumber] + cmp word ptr ds:[GetlinsecPtr], offset getlinsec_ebios + je .jump_to_setupldr + mov dh, HEX(FF) +.jump_to_setupldr: // Transfer execution to the bootloader. ljmp16 0, FREELDR_BASE diff --git a/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c b/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c index be051df775f..7c282a6f904 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c @@ -575,69 +575,6 @@ PcDiskGetCacheableBlockCount(UCHAR DriveNumber) } } - -static BOOLEAN -FallbackDiskIsCdRomDrive(UCHAR DriveNumber) -{ - MASTER_BOOT_RECORD MasterBootRecord; - - TRACE("FallbackDiskIsCdRomDrive(0x%x)\n", DriveNumber); - - /* CD-ROM drive numbers are always > 0x80 */ - if (DriveNumber <= 0x80) - return FALSE; - - /* - * We suppose that a CD-ROM does not have a MBR - * (not always true: example of the Hybrid USB-ISOs). - */ - return !DiskReadBootRecord(DriveNumber, 0, &MasterBootRecord); -} - -BOOLEAN DiskIsCdRomDrive(UCHAR DriveNumber) -{ - REGS RegsIn, RegsOut; - PI386_CDROM_SPEC_PACKET Packet = (PI386_CDROM_SPEC_PACKET)(BIOSCALLBUFFER); - - TRACE("DiskIsCdRomDrive(0x%x)\n", DriveNumber); - - /* CD-ROM drive numbers are always > 0x80 */ - if (DriveNumber <= 0x80) - return FALSE; - - /* Setup disk address packet */ - RtlZeroMemory(Packet, sizeof(*Packet)); - Packet->PacketSize = sizeof(*Packet); - - /* - * BIOS Int 13h, function 4B01h - Bootable CD-ROM - Get Disk Emulation Status - * AX = 4B01h - * DL = drive number - * DS:SI -> empty specification packet - * Return: - * CF clear if successful - * CF set on error - * AX = return codes - * DS:SI specification packet filled - */ - RegsIn.w.ax = 0x4B01; - RegsIn.b.dl = DriveNumber; - RegsIn.x.ds = BIOSCALLBUFSEGMENT; // DS:SI -> specification packet - RegsIn.w.si = BIOSCALLBUFOFFSET; - - Int386(0x13, &RegsIn, &RegsOut); - - // return (INT386_SUCCESS(RegsOut) && (Packet->DriveNumber == DriveNumber)); - /* - * If the simple test failed, try to use the fallback code, - * but we can be on *very* thin ice. - */ - if (!INT386_SUCCESS(RegsOut) || (Packet->DriveNumber != DriveNumber)) - return FallbackDiskIsCdRomDrive(DriveNumber); - else - return TRUE; -} - BOOLEAN PcDiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size) { diff --git a/reactos/boot/freeldr/freeldr/disk/disk.c b/reactos/boot/freeldr/freeldr/disk/disk.c index accf8d51f15..012e4fd1d77 100644 --- a/reactos/boot/freeldr/freeldr/disk/disk.c +++ b/reactos/boot/freeldr/freeldr/disk/disk.c @@ -100,10 +100,6 @@ BOOLEAN DiskIsDriveRemovable(UCHAR DriveNumber) return TRUE; } - -extern BOOLEAN -DiskIsCdRomDrive(UCHAR DriveNumber); - BOOLEAN DiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size) { if (*FrldrBootPath) @@ -121,9 +117,9 @@ BOOLEAN DiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size) /* This is a floppy */ sprintf(FrldrBootPath, "multi(0)disk(0)fdisk(%u)", FrldrBootDrive); } - else if (DiskIsCdRomDrive(FrldrBootDrive)) + else if (FrldrBootPartition == 0xFF) { - /* This is a CD-ROM drive */ + /* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */ sprintf(FrldrBootPath, "multi(0)disk(0)cdrom(%u)", FrldrBootDrive - 0x80); } else