https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7547f85b7eead1fc4d8d0…
commit 7547f85b7eead1fc4d8d0c70b122fbdb4ee6910d
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Thu Jul 18 23:50:48 2019 +0300
Commit: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
CommitDate: Thu Jul 18 22:50:48 2019 +0200
[FREELDR] Abstract floppy drive detection code (#1735)
Make floppy detection code machine-specific, because Xbox CMOS cannot be used to
detect floppies. Based on a patch by Matt Borgerson.
CORE-16204 CORE-16207
Co-authored-by: Matt Borgerson <contact(a)mborgerson.com>
---
boot/freeldr/freeldr/arch/i386/hardware.c | 14 +-------------
boot/freeldr/freeldr/arch/i386/machpc.c | 13 +++++++++++++
boot/freeldr/freeldr/arch/i386/machxbox.c | 17 +++++++++++++++++
boot/freeldr/freeldr/include/machine.h | 3 +++
4 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/boot/freeldr/freeldr/arch/i386/hardware.c
b/boot/freeldr/freeldr/arch/i386/hardware.c
index a94ab48e324..f8d628d2640 100644
--- a/boot/freeldr/freeldr/arch/i386/hardware.c
+++ b/boot/freeldr/freeldr/arch/i386/hardware.c
@@ -165,18 +165,6 @@ HalpCalibrateStallExecution(VOID)
}
-static
-UCHAR
-GetFloppyCount(VOID)
-{
- UCHAR Data;
-
- WRITE_PORT_UCHAR((PUCHAR)0x70, 0x10);
- Data = READ_PORT_UCHAR((PUCHAR)0x71);
-
- return ((Data & 0xF0) ? 1 : 0) + ((Data & 0x0F) ? 1 : 0);
-}
-
static
UCHAR
GetFloppyType(UCHAR DriveNumber)
@@ -285,7 +273,7 @@ DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey)
ULONG Size;
ULONG FloppyCount;
- FloppyCount = GetFloppyCount();
+ FloppyCount = MachGetFloppyCount();
TRACE("Floppy count: %u\n", FloppyCount);
/* Always create a BIOS disk controller, no matter if we have floppy drives or not
*/
diff --git a/boot/freeldr/freeldr/arch/i386/machpc.c
b/boot/freeldr/freeldr/arch/i386/machpc.c
index 4e21727a19b..6e9de4ee26f 100644
--- a/boot/freeldr/freeldr/arch/i386/machpc.c
+++ b/boot/freeldr/freeldr/arch/i386/machpc.c
@@ -1301,6 +1301,18 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG
*BusNumber)
/* FIXME: Detect more ISA devices */
}
+static
+UCHAR
+PcGetFloppyCount(VOID)
+{
+ UCHAR Data;
+
+ WRITE_PORT_UCHAR((PUCHAR)0x70, 0x10);
+ Data = READ_PORT_UCHAR((PUCHAR)0x71);
+
+ return ((Data & 0xF0) ? 1 : 0) + ((Data & 0x0F) ? 1 : 0);
+}
+
PCONFIGURATION_COMPONENT_DATA
PcHwDetect(VOID)
{
@@ -1378,6 +1390,7 @@ PcMachInit(const char *CmdLine)
MachVtbl.Beep = PcBeep;
MachVtbl.PrepareForReactOS = PcPrepareForReactOS;
MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
+ MachVtbl.GetFloppyCount = PcGetFloppyCount;
MachVtbl.DiskGetBootPath = PcDiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
diff --git a/boot/freeldr/freeldr/arch/i386/machxbox.c
b/boot/freeldr/freeldr/arch/i386/machxbox.c
index c7873f0c0f3..030b9772c99 100644
--- a/boot/freeldr/freeldr/arch/i386/machxbox.c
+++ b/boot/freeldr/freeldr/arch/i386/machxbox.c
@@ -139,6 +139,22 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG
*BusNumber)
/* FIXME: Detect more ISA devices */
}
+static
+UCHAR
+XboxGetFloppyCount(VOID)
+{
+ /* On a PC we use CMOS/RTC I/O ports 0x70 and 0x71 to detect floppies.
+ * However an Xbox CMOS memory range [0x10, 0x70) and [0x80, 0x100)
+ * is filled with 0x55 0xAA 0x55 0xAA ... byte pattern which is used
+ * to validate the date/time settings by Xbox OS.
+ *
+ * Technically it's possible to connect a floppy drive to Xbox, but
+ * CMOS detection method should not be used here. */
+
+ WARN("XboxGetFloppyCount() is UNIMPLEMENTED, returning 0\n");
+ return 0;
+}
+
PCONFIGURATION_COMPONENT_DATA
XboxHwDetect(VOID)
{
@@ -195,6 +211,7 @@ XboxMachInit(const char *CmdLine)
MachVtbl.Beep = PcBeep;
MachVtbl.PrepareForReactOS = XboxPrepareForReactOS;
MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
+ MachVtbl.GetFloppyCount = XboxGetFloppyCount;
MachVtbl.DiskGetBootPath = DiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
diff --git a/boot/freeldr/freeldr/include/machine.h
b/boot/freeldr/freeldr/include/machine.h
index abf6a4d343c..8a9b02e9291 100644
--- a/boot/freeldr/freeldr/include/machine.h
+++ b/boot/freeldr/freeldr/include/machine.h
@@ -61,6 +61,7 @@ typedef struct tagMACHVTBL
FREELDR_MEMORY_DESCRIPTOR* (*GetMemoryDescriptor)(FREELDR_MEMORY_DESCRIPTOR*
Current);
PFREELDR_MEMORY_DESCRIPTOR (*GetMemoryMap)(PULONG MaxMemoryMapSize);
+ UCHAR (*GetFloppyCount)(VOID);
BOOLEAN (*DiskGetBootPath)(PCHAR BootPath, ULONG Size);
BOOLEAN (*DiskReadLogicalSectors)(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG
SectorCount, PVOID Buffer);
BOOLEAN (*DiskGetDriveGeometry)(UCHAR DriveNumber, PGEOMETRY DriveGeometry);
@@ -115,6 +116,8 @@ VOID MachInit(const char *CmdLine);
MachVtbl.Beep()
#define MachPrepareForReactOS() \
MachVtbl.PrepareForReactOS()
+#define MachGetFloppyCount() \
+ MachVtbl.GetFloppyCount()
#define MachDiskGetBootPath(Path, Size) \
MachVtbl.DiskGetBootPath((Path), (Size))
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf) \