[FREELDR] Cache INT13h drive data in pcdisk.c (#2097)
[reactos.git] / boot / freeldr / freeldr / arch / i386 / machpc.c
index 64b6a43..9525397 100644 (file)
@@ -20,7 +20,6 @@
 #include <cportlib/cportlib.h>
 
 #include <debug.h>
-
 DBG_DEFAULT_CHANNEL(HWDETECT);
 
 
@@ -77,6 +76,27 @@ DBG_DEFAULT_CHANNEL(HWDETECT);
 #define CONTROLLER_TIMEOUT                              250
 
 
+VOID
+PcGetExtendedBIOSData(PULONG ExtendedBIOSDataArea, PULONG ExtendedBIOSDataSize)
+{
+    REGS BiosRegs;
+
+    /* Get address and size of the extended BIOS data area */
+    BiosRegs.d.eax = 0xC100;
+    Int386(0x15, &BiosRegs, &BiosRegs);
+    if (INT386_SUCCESS(BiosRegs))
+    {
+        *ExtendedBIOSDataArea = BiosRegs.w.es << 4;
+        *ExtendedBIOSDataSize = 1024;
+    }
+    else
+    {
+        WARN("Int 15h AH=C1h call failed\n");
+        *ExtendedBIOSDataArea = 0;
+        *ExtendedBIOSDataSize = 0;
+    }
+}
+
 // NOTE: Similar to machxbox.c!XboxGetHarddiskConfigurationData(),
 // but with extended geometry support.
 static
@@ -85,7 +105,7 @@ PcGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize)
 {
     PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
     PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
-    EXTENDED_GEOMETRY ExtGeometry;
+    // EXTENDED_GEOMETRY ExtGeometry;
     GEOMETRY Geometry;
     ULONG Size;
 
@@ -119,6 +139,7 @@ PcGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize)
     DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST));
 
     /* Get the disk geometry */
+#if 0 // This is somehow replaced by what PcDiskGetDriveGeometry() does internally.
     ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
     if (DiskGetExtendedDriveParameters(DriveNumber, &ExtGeometry, ExtGeometry.Size))
     {
@@ -127,7 +148,9 @@ PcGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize)
         DiskGeometry->SectorsPerTrack = ExtGeometry.SectorsPerTrack;
         DiskGeometry->NumberOfHeads = ExtGeometry.Heads;
     }
-    else if (MachDiskGetDriveGeometry(DriveNumber, &Geometry))
+    else
+#endif
+    if (PcDiskGetDriveGeometry(DriveNumber, &Geometry))
     {
         DiskGeometry->BytesPerSector = Geometry.BytesPerSector;
         DiskGeometry->NumberOfCylinders = Geometry.Cylinders;
@@ -615,17 +638,32 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
     }
 }
 
-static
+ULONG
+PcGetSerialPort(ULONG Index, PULONG Irq)
+{
+    static const ULONG PcIrq[MAX_COM_PORTS] = {4, 3, 4, 3};
+    PUSHORT BasePtr;
+
+    /*
+     * The BIOS data area 0x400 holds the address of the first valid COM port.
+     * Each COM port address is stored in a 2-byte field.
+     * Infos at: http://www.bioscentral.com/misc/bda.htm
+     */
+    BasePtr = (PUSHORT)0x400;
+    *Irq = PcIrq[Index];
+
+    return (ULONG) *(BasePtr + Index);
+}
+
 VOID
-DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
+DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey, GET_SERIAL_PORT MachGetSerialPort, ULONG Count)
 {
     PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
     PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
     PCM_SERIAL_DEVICE_DATA SerialDeviceData;
-    ULONG Irq[MAX_COM_PORTS] = {4, 3, 4, 3};
+    ULONG Irq;
     ULONG Base;
     CHAR Buffer[80];
-    PUSHORT BasePtr;
     ULONG ControllerNumber = 0;
     PCONFIGURATION_COMPONENT_DATA ControllerKey;
     ULONG i;
@@ -633,17 +671,10 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
 
     TRACE("DetectSerialPorts()\n");
 
-    /*
-     * The BIOS data area 0x400 holds the address of the first valid COM port.
-     * Each COM port address is stored in a 2-byte field.
-     * Infos at: http://www.bioscentral.com/misc/bda.htm
-     */
-    BasePtr = (PUSHORT)0x400;
-
-    for (i = 0; i < MAX_COM_PORTS; i++, BasePtr++)
+    for (i = 0; i < Count; i++)
     {
-        Base = (ULONG) * BasePtr;
-        if (Base == 0 || !CpDoesPortExist((PUCHAR)Base))
+        Base = MachGetSerialPort(i, &Irq);
+        if ((Base == 0) || !CpDoesPortExist(UlongToPtr(Base)))
             continue;
 
         TRACE("Found COM%u port at 0x%x\n", i + 1, Base);
@@ -682,8 +713,8 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
         PartialDescriptor->Type = CmResourceTypeInterrupt;
         PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
         PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
-        PartialDescriptor->u.Interrupt.Level = Irq[i];
-        PartialDescriptor->u.Interrupt.Vector = Irq[i];
+        PartialDescriptor->u.Interrupt.Level = Irq;
+        PartialDescriptor->u.Interrupt.Vector = Irq;
         PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
 
         /* Set serial data (device specific) */
@@ -1194,6 +1225,12 @@ DetectPS2Mouse(PCONFIGURATION_COMPONENT_DATA BusKey)
     }
 }
 
+
+// Implemented in i386vid.c, returns the VESA version
+USHORT  BiosIsVesaSupported(VOID);
+BOOLEAN BiosIsVesaDdcSupported(VOID);
+BOOLEAN BiosVesaReadEdid(VOID);
+
 static VOID
 DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
@@ -1292,7 +1329,7 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 
     /* Detect ISA/BIOS devices */
     DetectBiosDisks(SystemKey, BusKey);
-    DetectSerialPorts(BusKey);
+    DetectSerialPorts(BusKey, PcGetSerialPort, MAX_COM_PORTS);
     DetectParallelPorts(BusKey);
     DetectKeyboardController(BusKey);
     DetectPS2Mouse(BusKey);
@@ -1301,6 +1338,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)
 {
@@ -1314,6 +1363,7 @@ PcHwDetect(VOID)
     // TODO: Discover and set the machine type as the Component->Identifier
 
     GetHarddiskConfigurationData = PcGetHarddiskConfigurationData;
+    FindPciBios = PcFindPciBios;
 
     /* Detect buses */
     DetectPciBios(SystemKey, &BusNumber);
@@ -1367,6 +1417,7 @@ PcMachInit(const char *CmdLine)
     MachVtbl.VideoSetDisplayMode = PcVideoSetDisplayMode;
     MachVtbl.VideoGetDisplaySize = PcVideoGetDisplaySize;
     MachVtbl.VideoGetBufferSize = PcVideoGetBufferSize;
+    MachVtbl.VideoGetFontsFromFirmware = PcVideoGetFontsFromFirmware;
     MachVtbl.VideoSetTextCursorPosition = PcVideoSetTextCursorPosition;
     MachVtbl.VideoHideShowTextCursor = PcVideoHideShowTextCursor;
     MachVtbl.VideoPutChar = PcVideoPutChar;
@@ -1378,7 +1429,8 @@ PcMachInit(const char *CmdLine)
     MachVtbl.Beep = PcBeep;
     MachVtbl.PrepareForReactOS = PcPrepareForReactOS;
     MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
-    MachVtbl.DiskGetBootPath = PcDiskGetBootPath;
+    MachVtbl.GetExtendedBIOSData = PcGetExtendedBIOSData;
+    MachVtbl.GetFloppyCount = PcGetFloppyCount;
     MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
     MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
     MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount;
@@ -1386,15 +1438,13 @@ PcMachInit(const char *CmdLine)
     MachVtbl.InitializeBootDevices = PcInitializeBootDevices;
     MachVtbl.HwDetect = PcHwDetect;
     MachVtbl.HwIdle = PcHwIdle;
-
-    // DiskGetPartitionEntry = DiskGetMbrPartitionEntry; // Default
 }
 
 VOID
-PcPrepareForReactOS(IN BOOLEAN Setup)
+PcPrepareForReactOS(VOID)
 {
     /* On PC, prepare video and turn off the floppy motor */
-    PcVideoPrepareForReactOS(Setup);
+    PcVideoPrepareForReactOS();
     DiskStopFloppyMotor();
 }