[FREELDR]
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / pcdisk.c
index 9fbd3ec..0a89a84 100644 (file)
@@ -12,9 +12,9 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <freeldr.h>
@@ -22,6 +22,7 @@
 #define NDEBUG
 #include <debug.h>
 
+#include <pshpack2.h>
 typedef struct
 {
        UCHAR           PacketSize;                             // 00h - Size of packet (10h or 18h)
@@ -34,7 +35,8 @@ typedef struct
                                                                        //       used if DWORD at 04h is FFFFh:FFFFh
                                                                        //       Commented since some earlier BIOSes refuse to work with
                                                                        //       such extended structure
-} PACKED I386_DISK_ADDRESS_PACKET, *PI386_DISK_ADDRESS_PACKET;
+} I386_DISK_ADDRESS_PACKET, *PI386_DISK_ADDRESS_PACKET;
+#include <poppack.h>
 
 /////////////////////////////////////////////////////////////////////////////////////////////
 // FUNCTIONS
@@ -45,7 +47,7 @@ static BOOLEAN PcDiskResetController(ULONG DriveNumber)
        REGS    RegsIn;
        REGS    RegsOut;
 
-       DbgPrint((DPRINT_DISK, "PcDiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber));
+       DPRINTM(DPRINT_DISK, "PcDiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber);
 
        // BIOS Int 13h, function 0 - Reset disk system
        // AH = 00h
@@ -70,7 +72,7 @@ static BOOLEAN PcDiskReadLogicalSectorsLBA(ULONG DriveNumber, ULONGLONG SectorNu
        ULONG                                                   RetryCount;
        PI386_DISK_ADDRESS_PACKET       Packet = (PI386_DISK_ADDRESS_PACKET)(BIOSCALLBUFFER);
 
-       DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectorsLBA() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer));
+       DPRINTM(DPRINT_DISK, "PcDiskReadLogicalSectorsLBA() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer);
 
        // BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ
        RegsIn.b.ah = 0x42;                                     // Subfunction 42h
@@ -83,8 +85,8 @@ static BOOLEAN PcDiskReadLogicalSectorsLBA(ULONG DriveNumber, ULONGLONG SectorNu
        Packet->PacketSize = sizeof(I386_DISK_ADDRESS_PACKET);
        Packet->Reserved = 0;
        Packet->LBABlockCount = SectorCount;
-       Packet->TransferBufferOffset = ((ULONG)Buffer) & 0x0F;
-       Packet->TransferBufferSegment = ((ULONG)Buffer) >> 4;
+       Packet->TransferBufferOffset = ((ULONG_PTR)Buffer) & 0x0F;
+       Packet->TransferBufferSegment = ((ULONG_PTR)Buffer) >> 4;
        Packet->LBAStartBlock = SectorNumber;
 
        // BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ
@@ -121,7 +123,7 @@ static BOOLEAN PcDiskReadLogicalSectorsLBA(ULONG DriveNumber, ULONGLONG SectorNu
        }
 
        // If we get here then the read failed
-       DiskError("Disk Read Failed", RegsOut.b.ah);
+       DiskError("Disk Read Failed in LBA mode", RegsOut.b.ah);
 
        return FALSE;
 }
@@ -137,7 +139,7 @@ static BOOLEAN PcDiskReadLogicalSectorsCHS(ULONG DriveNumber, ULONGLONG SectorNu
        REGS            RegsOut;
        ULONG                   RetryCount;
 
-       DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectorsCHS()\n"));
+       DPRINTM(DPRINT_DISK, "PcDiskReadLogicalSectorsCHS()\n");
 
        //
        // Get the drive geometry
@@ -211,8 +213,8 @@ static BOOLEAN PcDiskReadLogicalSectorsCHS(ULONG DriveNumber, ULONGLONG SectorNu
                RegsIn.b.cl = (PhysicalSector + ((PhysicalTrack & 0x300) >> 2));
                RegsIn.b.dh = PhysicalHead;
                RegsIn.b.dl = DriveNumber;
-               RegsIn.w.es = ((ULONG)Buffer) >> 4;
-               RegsIn.w.bx = ((ULONG)Buffer) & 0x0F;
+               RegsIn.w.es = ((ULONG_PTR)Buffer) >> 4;
+               RegsIn.w.bx = ((ULONG_PTR)Buffer) & 0x0F;
 
                //
                // Perform the read
@@ -244,7 +246,7 @@ static BOOLEAN PcDiskReadLogicalSectorsCHS(ULONG DriveNumber, ULONGLONG SectorNu
                // If we retried 3 times then fail
                if (RetryCount >= 3)
                {
-                       DiskError("Disk Read Failed", RegsOut.b.ah);
+                       DiskError("Disk Read Failed in CHS mode, after retrying 3 times", RegsOut.b.ah);
                        return FALSE;
                }
 
@@ -269,26 +271,14 @@ static BOOLEAN PcDiskInt13ExtensionsSupported(ULONG DriveNumber)
        REGS    RegsIn;
        REGS    RegsOut;
 
-       DbgPrint((DPRINT_DISK, "PcDiskInt13ExtensionsSupported()\n"));
+       DPRINTM(DPRINT_DISK, "PcDiskInt13ExtensionsSupported()\n");
 
        if (DriveNumber == LastDriveNumber)
        {
-               DbgPrint((DPRINT_DISK, "Using cached value %s for drive 0x%x\n", LastSupported ? "TRUE" : "FALSE", DriveNumber));
+               DPRINTM(DPRINT_DISK, "Using cached value %s for drive 0x%x\n", LastSupported ? "TRUE" : "FALSE", DriveNumber);
                return LastSupported;
        }
 
-       // Some BIOSes report that extended disk access functions are not supported
-       // when booting from a CD (e.g. Phoenix BIOS v6.00PG and Insyde BIOS shipping
-       // with Intel Macs). Therefore we just return TRUE if we're booting from a CD -
-       // we can assume that all El Torito capable BIOSes support INT 13 extensions.
-       // We simply detect whether we're booting from CD by checking whether the drive
-       // number is >= 0x90. It's 0x90 on the Insyde BIOS, and 0x9F on most other BIOSes.
-       if (DriveNumber >= 0x90)
-       {
-               LastSupported = TRUE;
-               return TRUE;
-       }
-
        LastDriveNumber = DriveNumber;
 
        // IBM/MS INT 13 Extensions - INSTALLATION CHECK
@@ -336,15 +326,6 @@ static BOOLEAN PcDiskInt13ExtensionsSupported(ULONG DriveNumber)
                return FALSE;
        }
 
-       if (!(RegsOut.w.cx & 0x0001))
-       {
-               // CX = API subset support bitmap
-               // Bit 0, extended disk access functions (AH=42h-44h,47h,48h) supported
-               printf("Suspicious API subset support bitmap 0x%x on device 0x%lx\n", RegsOut.w.cx, DriveNumber);
-               LastSupported = FALSE;
-               return FALSE;
-       }
-
        LastSupported = TRUE;
        return TRUE;
 }
@@ -352,7 +333,7 @@ static BOOLEAN PcDiskInt13ExtensionsSupported(ULONG DriveNumber)
 BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
 {
 
-       DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer));
+       DPRINTM(DPRINT_DISK, "PcDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer);
 
        //
        // Check to see if it is a fixed disk drive
@@ -361,7 +342,7 @@ BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULON
        //
        if ((DriveNumber >= 0x80) && PcDiskInt13ExtensionsSupported(DriveNumber))
        {
-               DbgPrint((DPRINT_DISK, "Using Int 13 Extensions for read. PcDiskInt13ExtensionsSupported(%d) = %s\n", DriveNumber, PcDiskInt13ExtensionsSupported(DriveNumber) ? "TRUE" : "FALSE"));
+               DPRINTM(DPRINT_DISK, "Using Int 13 Extensions for read. PcDiskInt13ExtensionsSupported(%d) = %s\n", DriveNumber, PcDiskInt13ExtensionsSupported(DriveNumber) ? "TRUE" : "FALSE");
 
                //
                // LBA is easy, nothing to calculate
@@ -378,13 +359,6 @@ BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULON
        return TRUE;
 }
 
-BOOLEAN
-PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
-{
-  /* Just use the standard routine */
-  return DiskGetPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
-}
-
 BOOLEAN
 PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry)
 {
@@ -392,7 +366,7 @@ PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry)
   REGS RegsOut;
   ULONG Cylinders;
 
-  DbgPrint((DPRINT_DISK, "DiskGetDriveGeometry()\n"));
+  DPRINTM(DPRINT_DISK, "DiskGetDriveGeometry()\n");
 
   /* BIOS Int 13h, function 08h - Get drive parameters
    * AH = 08h