From eeff926ede1b2109bb0e129a960b74f3261cf2f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 13 Sep 2019 14:02:44 +0200 Subject: [PATCH] [FREELDR] Limit the usage of DiskStopFloppyMotor() in hardware/platform-specific code. - Move DiskStopFloppyMotor() calls into the implementations of Boot(New)LinuxKernel() and Reboot() HW functions, and the explanation comments in ChainLoadBiosBootSectorCode(). - Remove unneeded DiskStopFloppyMotor() dummies in ARM and PPC code. - Use more adequate bitmask value to be sent to floppy's Digital Output Register for shutting down its motor (based on OSDev & our floppy controller driver). --- boot/freeldr/freeldr/arch/amd64/entry.S | 18 +++++++++++++++++ boot/freeldr/freeldr/arch/arm/macharm.c | 4 ---- boot/freeldr/freeldr/arch/i386/entry.S | 13 ++++++++++++ boot/freeldr/freeldr/arch/i386/linux.S | 3 +++ boot/freeldr/freeldr/arch/i386/pcdisk.c | 6 ++++-- boot/freeldr/freeldr/arch/powerpc/mach.c | 3 --- boot/freeldr/freeldr/arch/realmode/amd64.S | 2 +- .../freeldr/freeldr/arch/realmode/helpers.inc | 1 + boot/freeldr/freeldr/arch/realmode/i386.S | 2 +- boot/freeldr/freeldr/custom.c | 4 ---- boot/freeldr/freeldr/freeldr.c | 3 --- boot/freeldr/freeldr/include/disk.h | 2 +- boot/freeldr/freeldr/linuxboot.c | 2 -- boot/freeldr/freeldr/miscboot.c | 20 ------------------- 14 files changed, 42 insertions(+), 41 deletions(-) diff --git a/boot/freeldr/freeldr/arch/amd64/entry.S b/boot/freeldr/freeldr/arch/amd64/entry.S index 26547c849df..31c6411ee00 100644 --- a/boot/freeldr/freeldr/arch/amd64/entry.S +++ b/boot/freeldr/freeldr/arch/amd64/entry.S @@ -5,6 +5,8 @@ EXTERN BootMain:PROC // EXTERN cmdline:DWORD +EXTERN DiskStopFloppyMotor:PROC + #ifdef _USE_ML EXTERN __bss_start__:FWORD EXTERN __bss_end__:FWORD @@ -70,6 +72,9 @@ stop: PUBLIC Reboot Reboot: + /* Stop the floppy drive motor */ + call DiskStopFloppyMotor + /* Set the function ID */ mov bx, FNID_Reboot @@ -102,6 +107,14 @@ continue: /* Store the 1-byte truncated partition number in DH */ mov dh, al + /* + * Don't stop the floppy drive motor when we are just booting a bootsector, + * a drive, or a partition. If we were to stop the floppy motor, the BIOS + * wouldn't be informed and if the next read is to a floppy then the BIOS + * will still think the motor is on and this will result in a read error. + */ + // call DiskStopFloppyMotor + /* Set the function ID */ mov bx, FNID_ChainLoadBiosBootSectorCode @@ -109,6 +122,11 @@ continue: jmp SwitchToReal +/* + * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter); + * + * RETURNS: + */ PUBLIC PxeCallApi PxeCallApi: xor eax, eax diff --git a/boot/freeldr/freeldr/arch/arm/macharm.c b/boot/freeldr/freeldr/arch/arm/macharm.c index 85aac23e567..348d3041e52 100644 --- a/boot/freeldr/freeldr/arch/arm/macharm.c +++ b/boot/freeldr/freeldr/arch/arm/macharm.c @@ -59,10 +59,6 @@ ULONG LenBits[] = /* FUNCTIONS ******************************************************************/ -VOID DiskStopFloppyMotor(VOID) -{ -} - VOID FrLdrCheckCpuCompatibility(VOID) { diff --git a/boot/freeldr/freeldr/arch/i386/entry.S b/boot/freeldr/freeldr/arch/i386/entry.S index 5147f798038..4c95e64e605 100644 --- a/boot/freeldr/freeldr/arch/i386/entry.S +++ b/boot/freeldr/freeldr/arch/i386/entry.S @@ -27,6 +27,8 @@ EXTERN _i386Idt:DWORD //EXTERN _i386idtptr:FWORD EXTERN cmdline:DWORD +EXTERN _DiskStopFloppyMotor:PROC + #ifdef _USE_ML EXTERN __bss_start__:DWORD EXTERN __bss_end__:DWORD @@ -101,6 +103,9 @@ stop: PUBLIC _Reboot _Reboot: + /* Stop the floppy drive motor */ + call _DiskStopFloppyMotor + /* Set the function ID */ mov bx, FNID_Reboot @@ -133,6 +138,14 @@ continue: /* Store the 1-byte truncated partition number in DH */ mov dh, al + /* + * Don't stop the floppy drive motor when we are just booting a bootsector, + * a drive, or a partition. If we were to stop the floppy motor, the BIOS + * wouldn't be informed and if the next read is to a floppy then the BIOS + * will still think the motor is on and this will result in a read error. + */ + // call _DiskStopFloppyMotor + /* Set the function ID */ mov bx, FNID_ChainLoadBiosBootSectorCode diff --git a/boot/freeldr/freeldr/arch/i386/linux.S b/boot/freeldr/freeldr/arch/i386/linux.S index 7ea8f3b7d22..d2b187cbf30 100644 --- a/boot/freeldr/freeldr/arch/i386/linux.S +++ b/boot/freeldr/freeldr/arch/i386/linux.S @@ -20,6 +20,7 @@ #include #include +EXTERN _DiskStopFloppyMotor:PROC EXTERN i386CallRealMode:PROC .code32 @@ -45,6 +46,8 @@ _BootOldLinuxKernel: PUBLIC _BootNewLinuxKernel _BootNewLinuxKernel: + /* Stop the floppy drive motor */ + call _DiskStopFloppyMotor mov bx, FNID_BootLinuxKernel call i386CallRealMode diff --git a/boot/freeldr/freeldr/arch/i386/pcdisk.c b/boot/freeldr/freeldr/arch/i386/pcdisk.c index 855326c42ec..0f1c5ad6509 100644 --- a/boot/freeldr/freeldr/arch/i386/pcdisk.c +++ b/boot/freeldr/freeldr/arch/i386/pcdisk.c @@ -478,10 +478,12 @@ BOOLEAN PcDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULON return TRUE; } -VOID DiskStopFloppyMotor(VOID) +#if defined(__i386__) || defined(_M_AMD64) +VOID __cdecl DiskStopFloppyMotor(VOID) { - WRITE_PORT_UCHAR((PUCHAR)0x3F2, 0); + WRITE_PORT_UCHAR((PUCHAR)0x3F2, 0x0C); // DOR_FDC_ENABLE | DOR_DMA_IO_INTERFACE_ENABLE } +#endif // defined __i386__ || defined(_M_AMD64) BOOLEAN DiskGetExtendedDriveParameters(UCHAR DriveNumber, PVOID Buffer, USHORT BufferSize) { diff --git a/boot/freeldr/freeldr/arch/powerpc/mach.c b/boot/freeldr/freeldr/arch/powerpc/mach.c index 8e9cf59f972..6c240a29ce9 100644 --- a/boot/freeldr/freeldr/arch/powerpc/mach.c +++ b/boot/freeldr/freeldr/arch/powerpc/mach.c @@ -534,9 +534,6 @@ void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value) { SetPhysByte(((ULONG)Address)+0x80000000, Value); } -void DiskStopFloppyMotor() { -} - void BootOldLinuxKernel( unsigned long size ) { ofw_exit(); } diff --git a/boot/freeldr/freeldr/arch/realmode/amd64.S b/boot/freeldr/freeldr/arch/realmode/amd64.S index cadeefce594..d6bf02c639b 100644 --- a/boot/freeldr/freeldr/arch/realmode/amd64.S +++ b/boot/freeldr/freeldr/arch/realmode/amd64.S @@ -346,9 +346,9 @@ stack16: #include "int386.inc" +#include "helpers.inc" #include "pxe.inc" #include "pnp.inc" -#include "helpers.inc" .org (FREELDR_PE_BASE - FREELDR_BASE - 1) .byte 0 diff --git a/boot/freeldr/freeldr/arch/realmode/helpers.inc b/boot/freeldr/freeldr/arch/realmode/helpers.inc index 981354826ae..9fbe7366ebc 100644 --- a/boot/freeldr/freeldr/arch/realmode/helpers.inc +++ b/boot/freeldr/freeldr/arch/realmode/helpers.inc @@ -110,6 +110,7 @@ writehex_common: popfd ret + Reboot: cli diff --git a/boot/freeldr/freeldr/arch/realmode/i386.S b/boot/freeldr/freeldr/arch/realmode/i386.S index f968ffde5b4..aaa261fdb70 100644 --- a/boot/freeldr/freeldr/arch/realmode/i386.S +++ b/boot/freeldr/freeldr/arch/realmode/i386.S @@ -198,10 +198,10 @@ rmode_idtptr: .long 0 /* Base Address */ #include "int386.inc" +#include "helpers.inc" #include "pxe.inc" #include "pnp.inc" #include "linux.inc" -#include "helpers.inc" .org (FREELDR_PE_BASE - FREELDR_BASE - 1) .byte 0 diff --git a/boot/freeldr/freeldr/custom.c b/boot/freeldr/freeldr/custom.c index e0afc7bb490..cf6065345d0 100644 --- a/boot/freeldr/freeldr/custom.c +++ b/boot/freeldr/freeldr/custom.c @@ -705,10 +705,6 @@ EditCustomBootReactOS( VOID OptionMenuReboot(VOID) { UiMessageBox("The system will now reboot."); - -#if defined(__i386__) || defined(_M_AMD64) - DiskStopFloppyMotor(); -#endif Reboot(); } diff --git a/boot/freeldr/freeldr/freeldr.c b/boot/freeldr/freeldr/freeldr.c index 0bcb03d8be0..f266081f067 100644 --- a/boot/freeldr/freeldr/freeldr.c +++ b/boot/freeldr/freeldr/freeldr.c @@ -65,9 +65,6 @@ VOID __cdecl BootMain(IN PCCH CmdLine) Quit: /* If we reach this point, something went wrong before, therefore reboot */ -#if defined(__i386__) || defined(_M_AMD64) - DiskStopFloppyMotor(); -#endif Reboot(); } diff --git a/boot/freeldr/freeldr/include/disk.h b/boot/freeldr/freeldr/include/disk.h index 67fb4b14b78..c07ed0117c8 100644 --- a/boot/freeldr/freeldr/include/disk.h +++ b/boot/freeldr/freeldr/include/disk.h @@ -114,7 +114,7 @@ typedef struct _MASTER_BOOT_RECORD // /////////////////////////////////////////////////////////////////////////////////////// #if defined(__i386__) || defined(_M_AMD64) -VOID DiskStopFloppyMotor(VOID); +VOID __cdecl DiskStopFloppyMotor(VOID); #endif // defined __i386__ || defined(_M_AMD64) /* Buffer for disk reads (hwdisk.c) */ diff --git a/boot/freeldr/freeldr/linuxboot.c b/boot/freeldr/freeldr/linuxboot.c index 07794661bb9..48ebf53f54c 100644 --- a/boot/freeldr/freeldr/linuxboot.c +++ b/boot/freeldr/freeldr/linuxboot.c @@ -259,8 +259,6 @@ LoadAndBootLinux( UiUnInitialize("Booting Linux..."); IniCleanup(); - DiskStopFloppyMotor(); - if (LinuxSetupSector->LoadFlags & LINUX_FLAG_LOAD_HIGH) BootNewLinuxKernel(); else diff --git a/boot/freeldr/freeldr/miscboot.c b/boot/freeldr/freeldr/miscboot.c index 5ef9d9a4f87..e8f91c8e674 100644 --- a/boot/freeldr/freeldr/miscboot.c +++ b/boot/freeldr/freeldr/miscboot.c @@ -118,16 +118,6 @@ LoadAndBootBootSector( UiUnInitialize("Booting..."); IniCleanup(); - /* - * Don't stop the floppy drive motor when we - * are just booting a bootsector, or drive, or partition. - * If we were to stop the floppy motor then - * the BIOS wouldn't be informed and if the - * next read is to a floppy then the BIOS will - * still think the motor is on and this will - * result in a read error. - */ - // DiskStopFloppyMotor(); ChainLoadBiosBootSectorCode(0 /*DriveNumber*/, 0 /*PartitionNumber*/); /* Must not return! */ return ESUCCESS; @@ -204,16 +194,6 @@ LoadAndBootPartitionOrDrive( UiUnInitialize("Booting..."); IniCleanup(); - /* - * Don't stop the floppy drive motor when we - * are just booting a bootsector, or drive, or partition. - * If we were to stop the floppy motor then - * the BIOS wouldn't be informed and if the - * next read is to a floppy then the BIOS will - * still think the motor is on and this will - * result in a read error. - */ - // DiskStopFloppyMotor(); ChainLoadBiosBootSectorCode(DriveNumber, PartitionNumber); /* Must not return! */ return ESUCCESS; -- 2.17.1