[FREELOADER]
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / hardware.c
index 761d164..f99e267 100644 (file)
@@ -2,6 +2,7 @@
  *  FreeLoader
  *
  *  Copyright (C) 2003, 2004  Eric Kohl
+ *  Copyright (C) 2009  HervĂ© Poussineau
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -13,9 +14,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>
@@ -236,24 +237,6 @@ DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
   DPRINTM(DPRINT_HWDETECT, "MaxNodeSize %u  NodeCount %u\n", NodeSize, NodeCount);
   DPRINTM(DPRINT_HWDETECT, "Estimated buffer size %u\n", NodeSize * NodeCount);
 
-    /* Create component key */
-    FldrCreateComponentKey(SystemKey,
-                           L"MultifunctionAdapter",
-                           *BusNumber,
-                           AdapterClass,
-                           MultiFunctionAdapter,
-                           &BusKey);
-    (*BusNumber)++;
-    
-    /* Set the component information */
-    FldrSetComponentInformation(BusKey,
-                                0x0,
-                                0x0,
-                                0xFFFFFFFF);
-    
-    /* Set the identifier */
-    FldrSetIdentifier(BusKey, "PNP BIOS");
-
     /* Set 'Configuration Data' value */
   Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + (NodeSize * NodeCount);
   PartialResourceList = MmHeapAlloc(Size);
@@ -319,16 +302,28 @@ DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 
   DPRINTM(DPRINT_HWDETECT, "Real buffer size: %u\n", PnpBufferSize);
   DPRINTM(DPRINT_HWDETECT, "Resource size: %u\n", Size);
-  
-    FldrSetConfigurationData(BusKey, PartialResourceList, Size);
+
+    /* Create component key */
+    FldrCreateComponentKey(SystemKey,
+                           AdapterClass,
+                           MultiFunctionAdapter,
+                           0x0,
+                           0x0,
+                           0xFFFFFFFF,
+                           "PNP BIOS",
+                           PartialResourceList,
+                           Size,
+                           &BusKey);
+
+    (*BusNumber)++;
+
     MmHeapFree(PartialResourceList);
 }
 
 
 
-static VOID
-SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey,
-                            ULONG DriveNumber)
+static PCM_PARTIAL_RESOURCE_LIST
+GetHarddiskConfigurationData(ULONG DriveNumber, ULONG* pSize)
 {
   PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
@@ -336,6 +331,11 @@ SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey,
   GEOMETRY Geometry;
   ULONG Size;
 
+    //
+    // Initialize returned size
+    //
+    *pSize = 0;
+
   /* Set 'Configuration Data' value */
   Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
         sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
@@ -344,7 +344,7 @@ SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey,
     {
       DPRINTM(DPRINT_HWDETECT,
                "Failed to allocate a full resource descriptor\n");
-      return;
+      return NULL;
     }
 
   memset(PartialResourceList, 0, Size);
@@ -381,7 +381,7 @@ SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey,
     {
       DPRINTM(DPRINT_HWDETECT, "Reading disk geometry failed\n");
       MmHeapFree(PartialResourceList);
-      return;
+      return NULL;
     }
   DPRINTM(DPRINT_HWDETECT,
           "Disk %x: %u Cylinders  %u Heads  %u Sectors  %u Bytes\n",
@@ -391,8 +391,11 @@ SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey,
           DiskGeometry->SectorsPerTrack,
           DiskGeometry->BytesPerSector);
 
-  FldrSetConfigurationData(DiskKey, PartialResourceList, Size);
-  MmHeapFree(PartialResourceList);
+    //
+    // Return configuration data
+    //
+    *pSize = Size;
+    return PartialResourceList;
 }
 
 typedef struct tagDISKCONTEXT
@@ -400,6 +403,7 @@ typedef struct tagDISKCONTEXT
     ULONG DriveNumber;
     ULONG SectorSize;
     ULONGLONG SectorOffset;
+    ULONGLONG SectorCount;
     ULONGLONG SectorNumber;
 } DISKCONTEXT;
 
@@ -413,7 +417,13 @@ static LONG DiskClose(ULONG FileId)
 
 static LONG DiskGetFileInformation(ULONG FileId, FILEINFORMATION* Information)
 {
-    return EINVAL;
+    DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
+
+    RtlZeroMemory(Information, sizeof(FILEINFORMATION));
+    Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
+    Information->CurrentAddress.LowPart = (Context->SectorOffset + Context->SectorNumber) * Context->SectorSize;
+
+    return ESUCCESS;
 }
 
 static LONG DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
@@ -421,17 +431,32 @@ static LONG DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
     DISKCONTEXT* Context;
     ULONG DriveNumber, DrivePartition, SectorSize;
     ULONGLONG SectorOffset = 0;
+    ULONGLONG SectorCount = 0;
     PARTITION_TABLE_ENTRY PartitionTableEntry;
     CHAR FileName[1];
 
     if (!DissectArcPath(Path, FileName, &DriveNumber, &DrivePartition))
         return EINVAL;
-    SectorSize = (DrivePartition == 0xff ? 2048 : 512);
+
+    if (DrivePartition == 0xff)
+    {
+        /* This is a CD-ROM device */
+        SectorSize = 2048;
+    }
+    else
+    {
+        /* This is either a floppy disk device (DrivePartition == 0) or
+         * a hard disk device (DrivePartition != 0 && DrivePartition != 0xFF) but
+         * it doesn't matter which one because they both have 512 bytes per sector */
+        SectorSize = 512;
+    }
+
     if (DrivePartition != 0xff && DrivePartition != 0)
     {
-        if (!MachDiskGetPartitionEntry(DriveNumber, DrivePartition, &PartitionTableEntry))
+        if (!DiskGetPartitionEntry(DriveNumber, DrivePartition, &PartitionTableEntry))
             return EINVAL;
         SectorOffset = PartitionTableEntry.SectorCountBeforePartition;
+        SectorCount = PartitionTableEntry.PartitionSectorCount;
     }
 
     Context = MmHeapAlloc(sizeof(DISKCONTEXT));
@@ -440,6 +465,7 @@ static LONG DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
     Context->DriveNumber = DriveNumber;
     Context->SectorSize = SectorSize;
     Context->SectorOffset = SectorOffset;
+    Context->SectorCount = SectorCount;
     Context->SectorNumber = 0;
     FsSetDeviceSpecific(*FileId, Context);
 
@@ -449,21 +475,31 @@ static LONG DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
 static LONG DiskRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
 {
     DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
+    UCHAR* Ptr = (UCHAR*)Buffer;
+    ULONG i, Length;
     BOOLEAN ret;
 
     *Count = 0;
-    if (N & (Context->SectorSize - 1))
-        return EINVAL;
-
-    ret = MachDiskReadLogicalSectors(
-        Context->DriveNumber,
-        Context->SectorNumber + Context->SectorOffset,
-        N / Context->SectorSize,
-        Buffer);
-    if (!ret)
-        return EIO;
+    i = 0;
+    while (N > 0)
+    {
+        Length = N;
+        if (Length > Context->SectorSize)
+            Length = Context->SectorSize;
+        ret = MachDiskReadLogicalSectors(
+            Context->DriveNumber,
+            Context->SectorNumber + Context->SectorOffset + i,
+            1,
+            (PVOID)DISKREADBUFFER);
+        if (!ret)
+            return EIO;
+        RtlCopyMemory(Ptr, (PVOID)DISKREADBUFFER, Length);
+        Ptr += Length;
+        *Count += Length;
+        N -= Length;
+        i++;
+    }
 
-    *Count = N;
     return ESUCCESS;
 }
 
@@ -490,7 +526,7 @@ static const DEVVTBL DiskVtbl = {
 };
 
 static VOID
-SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
+GetHarddiskIdentifier(PCHAR Identifier,
                      ULONG DriveNumber)
 {
   PMASTER_BOOT_RECORD Mbr;
@@ -498,7 +534,6 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
   ULONG i;
   ULONG Checksum;
   ULONG Signature;
-  CHAR Identifier[20];
   CHAR ArcName[256];
   PARTITION_TABLE_ENTRY PartitionTableEntry;
 
@@ -536,10 +571,10 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
   sprintf(ArcName, "multi(0)disk(0)rdisk(%lu)partition(0)", DriveNumber - 0x80);
   FsRegisterDevice(ArcName, &DiskVtbl);
 
-#if 0
   /* Add partitions */
-  i = 0;
-  while (MachDiskGetPartitionEntry(DriveNumber, i, &PartitionTableEntry))
+  i = 1;
+  DiskReportError(FALSE);
+  while (DiskGetPartitionEntry(DriveNumber, i, &PartitionTableEntry))
   {
     if (PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
     {
@@ -548,7 +583,7 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
     }
     i++;
   }
-#endif
+  DiskReportError(TRUE);
 
   /* Convert checksum and signature to identifier string */
   Identifier[0] = Hex[(Checksum >> 28) & 0x0F];
@@ -572,9 +607,6 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
   Identifier[18] = 'A';
   Identifier[19] = 0;
   DPRINTM(DPRINT_HWDETECT, "Identifier: %s\n", Identifier);
-
-  /* Set identifier */
-  FldrSetIdentifier(DiskKey, Identifier);
 }
 
 static ULONG
@@ -640,19 +672,9 @@ DetectBiosFloppyPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
     DiskResetController(FloppyNumber);
 
     Ptr = GetInt1eTable();
-    
-    FldrCreateComponentKey(ControllerKey,
-                           L"FloppyDiskPeripheral",
-                           FloppyNumber,
-                           PeripheralClass,
-                           FloppyDiskPeripheral,
-                           &PeripheralKey);
 
-    /* Set 'ComponentInformation' value */
-    FldrSetComponentInformation(PeripheralKey,
-                                Input | Output,
-                                FloppyNumber,
-                                0xFFFFFFFF);
+    /* Set 'Identifier' value */
+    sprintf(Identifier, "FLOPPY%ld", FloppyNumber + 1);
 
     Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
           sizeof(CM_FLOPPY_DEVICE_DATA);
@@ -685,21 +707,26 @@ DetectBiosFloppyPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
     FloppyData->MaximumTrackValue = (FloppyType == 1) ? 39 : 79;
     FloppyData->DataTransferRate = 0;
 
-    /* Set 'Configuration Data' value */
-    FldrSetConfigurationData(PeripheralKey, PartialResourceList, Size);
-    MmHeapFree(PartialResourceList);
+    FldrCreateComponentKey(ControllerKey,
+                           PeripheralClass,
+                           FloppyDiskPeripheral,
+                           Input | Output,
+                           FloppyNumber,
+                           0xFFFFFFFF,
+                           Identifier,
+                           PartialResourceList,
+                           Size,
+                           &PeripheralKey);
 
-    /* Set 'Identifier' value */
-    sprintf(Identifier, "FLOPPY%ld", FloppyNumber + 1);
-    FldrSetIdentifier(PeripheralKey, Identifier);
+    MmHeapFree(PartialResourceList);
   }
 }
 
 
 static VOID
-DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey,
-                           PCONFIGURATION_COMPONENT_DATA ControllerKey)
+DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
+  PCONFIGURATION_COMPONENT_DATA ControllerKey;
   PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
   ULONG Size;
@@ -752,21 +779,31 @@ DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey,
   PartialDescriptor->u.Dma.Channel = 2;
   PartialDescriptor->u.Dma.Port = 0;
 
-  /* Set 'Configuration Data' value */
-  FldrSetConfigurationData(ControllerKey, PartialResourceList, Size);
+    /* Create floppy disk controller */
+    FldrCreateComponentKey(BusKey,
+                           ControllerClass,
+                           DiskController,
+                           Output | Input,
+                           0x0,
+                           0xFFFFFFFF,
+                           NULL,
+                           PartialResourceList,
+                           Size,
+                           &ControllerKey);
+    DPRINTM(DPRINT_HWDETECT, "Created key: DiskController\\0\n");
+
   MmHeapFree(PartialResourceList);
 
   if (FloppyCount) DetectBiosFloppyPeripheral(ControllerKey);
 }
 
-static VOID
-DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey,
-                PCONFIGURATION_COMPONENT_DATA BusKey)
+static PCONFIGURATION_COMPONENT_DATA
+DetectSystem(VOID)
 {
+    PCONFIGURATION_COMPONENT_DATA SystemKey;
     PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
     PCM_INT13_DRIVE_PARAMETER Int13Drives;
     GEOMETRY Geometry;
-    PCONFIGURATION_COMPONENT_DATA DiskKey, ControllerKey;
     ULONG DiskCount;
     ULONG Size;
     ULONG i;
@@ -802,22 +839,6 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey,
     DPRINTM(DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n",
               (int)DiskCount, (DiskCount == 1) ? "": "s");
     
-    FldrCreateComponentKey(BusKey,
-                           L"DiskController",
-                           0,
-                           ControllerClass,
-                           DiskController,
-                           &ControllerKey);
-    DPRINTM(DPRINT_HWDETECT, "Created key: DiskController\\0\n");
-    
-    /* Set 'ComponentInformation' value */
-    FldrSetComponentInformation(ControllerKey,
-                                Output | Input | Removable,
-                                0,
-                                0xFFFFFFFF);
-    
-    DetectBiosFloppyController(BusKey, ControllerKey);
-    
     /* Allocate resource descriptor */
     Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
         sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount;
@@ -826,7 +847,7 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey,
     {
         DPRINTM(DPRINT_HWDETECT,
                   "Failed to allocate resource descriptor\n");
-        return;
+        return NULL;
     }
     
     /* Initialize resource descriptor */
@@ -861,35 +882,139 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey,
                       Geometry.BytesPerSector);
         }
     }
-    
-    /* Set 'Configuration Data' value */
-    FldrSetConfigurationData(SystemKey, PartialResourceList, Size);
+
+    FldrCreateComponentKey(NULL,
+                           SystemClass,
+                           MaximumType,
+                           0x0,
+                           0x0,
+                           0xFFFFFFFF,
+                           NULL,
+                           PartialResourceList,
+                           Size,
+                           &SystemKey);
+
     MmHeapFree(PartialResourceList);
+
+    return SystemKey;
+}
+
+static ULONG
+GetDiskCount(PCONFIGURATION_COMPONENT_DATA BusKey)
+{
+    PCONFIGURATION_COMPONENT_DATA System;
+    ULONG ConfigurationDataLength;
+    ULONG DiskCount = 0;
+
+    //
+    // Get root component
+    //
+    System = BusKey;
+    while (System->Parent)
+        System = System->Parent;
+
+    //
+    // Get root configuration data length
+    //
+    ConfigurationDataLength = System->ComponentEntry.ConfigurationDataLength;
+
+    //
+    // We assume that nothing wrong happened, and that configuration
+    // only consists of one CM_PARTIAL_RESOURCE_LIST entry, followed
+    // by n entries of CM_INT13_DRIVE_PARAMETER
+    //
+    if (ConfigurationDataLength > 0)
+        DiskCount = (ConfigurationDataLength - sizeof(CM_PARTIAL_RESOURCE_LIST))
+            / sizeof(CM_INT13_DRIVE_PARAMETER);
+
+    //
+    // Return number of disks
+    //
+    DPRINTM(DPRINT_HWDETECT, "Retrieving %lu INT13 disks\\0\n", DiskCount);
+    return DiskCount;
+};
+
+static VOID
+DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA BusKey)
+{
+    PCONFIGURATION_COMPONENT_DATA DiskKey, ControllerKey;
+    BOOLEAN BootDriveReported = FALSE;
+    ULONG i;
+    ULONG DiskCount = GetDiskCount(BusKey);
+    CHAR BootPath[512];
+
+    FldrCreateComponentKey(BusKey,
+                           ControllerClass,
+                           DiskController,
+                           Output | Input,
+                           0x0,
+                           0xFFFFFFFF,
+                           NULL,
+                           NULL,
+                           0,
+                           &ControllerKey);
+    DPRINTM(DPRINT_HWDETECT, "Created key: DiskController\\0\n");
     
     /* Create and fill subkey for each harddisk */
     for (i = 0; i < DiskCount; i++)
     {
+        PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
+        ULONG Size;
+        CHAR Identifier[20];
+
+        if (BootDrive == 0x80 + i)
+            BootDriveReported = TRUE;
+
+        /* Get disk values */
+        PartialResourceList = GetHarddiskConfigurationData(0x80 + i, &Size);
+        GetHarddiskIdentifier(Identifier, 0x80 + i);
+
         /* Create disk key */
         FldrCreateComponentKey(ControllerKey,
-                               L"DiskPeripheral",
-                               i,
                                PeripheralClass,
                                DiskPeripheral,
+                               Output | Input,
+                               0x0,
+                               0xFFFFFFFF,
+                               Identifier,
+                               PartialResourceList,
+                               Size,
                                &DiskKey);
-        
-        /* Set 'ComponentInformation' value */
-        FldrSetComponentInformation(DiskKey,
-                                    Output | Input,
-                                    0,
-                                    0xFFFFFFFF);
-        
-        /* Set disk values */
-        SetHarddiskConfigurationData(DiskKey, 0x80 + i);
-        SetHarddiskIdentifier(DiskKey, 0x80 + i);
     }
 
-    /* Also add one cdrom drive */
-    FsRegisterDevice("multi(0)disk(0)cdrom(224)", &DiskVtbl);
+    /* Get the drive we're booting from */
+    MachDiskGetBootPath(BootPath, sizeof(BootPath));
+
+    /* Add it, if it's a floppy or cdrom */
+    if ((BootDrive >= 0x80 && !BootDriveReported) ||
+        DiskIsDriveRemovable(BootDrive))
+    {
+        /* TODO: Check if it's really a cdrom drive */
+        ULONG* Buffer;
+        ULONG Checksum = 0;
+
+        /* Read the MBR */
+        if (!MachDiskReadLogicalSectors(BootDrive, 16ULL, 1, (PVOID)DISKREADBUFFER))
+        {
+          DPRINTM(DPRINT_HWDETECT, "Reading MBR failed\n");
+          return;
+        }
+
+        Buffer = (ULONG*)DISKREADBUFFER;
+
+        /* Calculate the MBR checksum */
+        for (i = 0; i < 2048 / sizeof(ULONG); i++) Checksum += Buffer[i];
+        DPRINTM(DPRINT_HWDETECT, "Checksum: %x\n", Checksum);
+
+        /* Fill out the ARC disk block */
+        reactos_arc_disk_info[reactos_disk_count].CheckSum = Checksum;
+        strcpy(reactos_arc_strings[reactos_disk_count], BootPath);
+        reactos_arc_disk_info[reactos_disk_count].ArcName =
+            reactos_arc_strings[reactos_disk_count];
+        reactos_disk_count++;
+
+        FsRegisterDevice(BootPath, &DiskVtbl);
+    }
 }
 
 static VOID
@@ -1203,35 +1328,27 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
            }
        }
 
-      /* Create 'PointerPeripheral' key */
-      FldrCreateComponentKey(ControllerKey,
-                             L"PointerPeripheral",
-                             0,
-                             PeripheralClass,
-                             PointerPeripheral,
-                             &PeripheralKey);
-      DPRINTM(DPRINT_HWDETECT,
-               "Created key: PointerPeripheral\\0\n");
-
-      /* Set 'ComponentInformation' value */
-      FldrSetComponentInformation(PeripheralKey,
-                                  Input,
-                                  0,
-                                  0xFFFFFFFF);
-
       /* Set 'Configuration Data' value */
       memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST));
       PartialResourceList.Version = 1;
       PartialResourceList.Revision = 1;
       PartialResourceList.Count = 0;
 
-      FldrSetConfigurationData(PeripheralKey,
-                               &PartialResourceList,
-                               sizeof(CM_PARTIAL_RESOURCE_LIST) -
-                               sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
+      /* Create 'PointerPeripheral' key */
+      FldrCreateComponentKey(ControllerKey,
+                             PeripheralClass,
+                             PointerPeripheral,
+                             Input,
+                             0x0,
+                             0xFFFFFFFF,
+                             Identifier,
+                             &PartialResourceList,
+                             sizeof(CM_PARTIAL_RESOURCE_LIST) -
+                                 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR),
+                             &PeripheralKey);
 
-      /* Set 'Identifier' value */
-      FldrSetIdentifier(PeripheralKey, Identifier);
+      DPRINTM(DPRINT_HWDETECT,
+          "Created key: PointerPeripheral\\0\n");
     }
 }
 
@@ -1266,19 +1383,8 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
                i + 1,
                Base);
 
-      /* Create controller key */
-      FldrCreateComponentKey(BusKey,
-                             L"SerialController",
-                             ControllerNumber,
-                             ControllerClass,
-                             SerialController,
-                             &ControllerKey);
-
-      /* Set 'ComponentInformation' value */
-      FldrSetComponentInformation(ControllerKey,
-                                  Output | Input | ConsoleIn | ConsoleOut,
-                                  ControllerNumber,
-                                  0xFFFFFFFF);
+      /* Set 'Identifier' value */
+      sprintf(Buffer, "COM%ld", i + 1);
 
       /* Build full device descriptor */
       Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
@@ -1310,10 +1416,10 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
       /* Set Interrupt */
       PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
       PartialDescriptor->Type = CmResourceTypeInterrupt;
-      PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
+      PartialDescriptor->ShareDisposition = CmResourceShareShared;
       PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
       PartialDescriptor->u.Interrupt.Level = Irq[i];
-      PartialDescriptor->u.Interrupt.Vector = 0;
+      PartialDescriptor->u.Interrupt.Vector = Irq[i];
       PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
 
       /* Set serial data (device specific) */
@@ -1327,16 +1433,19 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
        (PCM_SERIAL_DEVICE_DATA)&PartialResourceList->PartialDescriptors[3];
       SerialDeviceData->BaudClock = 1843200; /* UART Clock frequency (Hertz) */
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(ControllerKey, PartialResourceList, Size);
-      MmHeapFree(PartialResourceList);
+      /* Create controller key */
+      FldrCreateComponentKey(BusKey,
+                             ControllerClass,
+                             SerialController,
+                             Output | Input | ConsoleIn | ConsoleOut,
+                             ControllerNumber,
+                             0xFFFFFFFF,
+                             Buffer,
+                             PartialResourceList,
+                             Size,
+                             &ControllerKey);
 
-      /* Set 'Identifier' value */
-      sprintf(Buffer, "COM%ld", i + 1);
-      FldrSetIdentifier(ControllerKey, Buffer);
-      DPRINTM(DPRINT_HWDETECT,
-               "Created value: Identifier %s\n",
-               Buffer);
+      MmHeapFree(PartialResourceList);
 
       if (!Rs232PortInUse(Base))
         {
@@ -1378,19 +1487,8 @@ DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
                ControllerNumber,
                Base);
 
-      /* Create controller key */
-      FldrCreateComponentKey(BusKey,
-                             L"ParallelController",
-                             ControllerNumber,
-                             ControllerClass,
-                             ParallelController,
-                             &ControllerKey);
-
-      /* Set 'ComponentInformation' value */
-      FldrSetComponentInformation(ControllerKey,
-                                  Output,
-                                  ControllerNumber,
-                                  0xFFFFFFFF);
+      /* Set 'Identifier' value */
+      sprintf(Buffer, "PARALLEL%ld", i + 1);
 
       /* Build full device descriptor */
       Size = sizeof(CM_PARTIAL_RESOURCE_LIST);
@@ -1428,20 +1526,23 @@ DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
          PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
          PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
          PartialDescriptor->u.Interrupt.Level = Irq[i];
-         PartialDescriptor->u.Interrupt.Vector = 0;
+         PartialDescriptor->u.Interrupt.Vector = Irq[i];
          PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
        }
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(ControllerKey, PartialResourceList, Size);
-      MmHeapFree(PartialResourceList);
+      /* Create controller key */
+      FldrCreateComponentKey(BusKey,
+                             ControllerClass,
+                             ParallelController,
+                             Output,
+                             ControllerNumber,
+                             0xFFFFFFFF,
+                             Buffer,
+                             PartialResourceList,
+                             Size,
+                             &ControllerKey);
 
-      /* Set 'Identifier' value */
-      sprintf(Buffer, "PARALLEL%ld", i + 1);
-      FldrSetIdentifier(ControllerKey, Buffer);
-      DPRINTM(DPRINT_HWDETECT,
-               "Created value: Identifier %s\n",
-               Buffer);
+      MmHeapFree(PartialResourceList);
 
       ControllerNumber++;
     }
@@ -1533,21 +1634,6 @@ DetectKeyboardPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
   /* HACK: don't call DetectKeyboardDevice() as it fails in Qemu 0.8.2 */
   if (TRUE || DetectKeyboardDevice())
   {
-      /* Create controller key */
-      FldrCreateComponentKey(ControllerKey,
-                             L"KeyboardPeripheral",
-                             0,
-                             PeripheralClass,
-                             KeyboardPeripheral,
-                             &PeripheralKey);
-    DPRINTM(DPRINT_HWDETECT, "Created key: KeyboardPeripheral\\0\n");
-
-    /* Set 'ComponentInformation' value */
-    FldrSetComponentInformation(PeripheralKey,
-                                Input | ConsoleIn,
-                                0,
-                                0xFFFFFFFF);
-
     /* Set 'Configuration Data' value */
     Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
           sizeof(CM_KEYBOARD_DEVICE_DATA);
@@ -1577,12 +1663,20 @@ DetectKeyboardPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
     KeyboardData->Subtype = 0;
     KeyboardData->KeyboardFlags = 0x20;
 
-    /* Set 'Configuration Data' value */
-    FldrSetConfigurationData(PeripheralKey, PartialResourceList, Size);
-    MmHeapFree(PartialResourceList);
+        /* Create controller key */
+        FldrCreateComponentKey(ControllerKey,
+                               PeripheralClass,
+                               KeyboardPeripheral,
+                               Input | ConsoleIn,
+                               0x0,
+                               0xFFFFFFFF,
+                               "PCAT_ENHANCED",
+                               PartialResourceList,
+                               Size,
+                               &PeripheralKey);
+        DPRINTM(DPRINT_HWDETECT, "Created key: KeyboardPeripheral\\0\n");
 
-    /* Set 'Identifier' value */
-    FldrSetIdentifier(PeripheralKey, "PCAT_ENHANCED");
+    MmHeapFree(PartialResourceList);
   }
 }
 
@@ -1595,21 +1689,6 @@ DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey)
   PCONFIGURATION_COMPONENT_DATA ControllerKey;
   ULONG Size;
 
-  /* Create controller key */
-  FldrCreateComponentKey(BusKey,
-                         L"KeyboardController",
-                         0,
-                         ControllerClass,
-                         KeyboardController,
-                         &ControllerKey);
-  DPRINTM(DPRINT_HWDETECT, "Created key: KeyboardController\\0\n");
-
-  /* Set 'ComponentInformation' value */
-  FldrSetComponentInformation(ControllerKey,
-                              Input | ConsoleIn,
-                              0,
-                              0xFFFFFFFF);
-
   /* Set 'Configuration Data' value */
   Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
          2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
@@ -1633,7 +1712,7 @@ DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey)
   PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
   PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
   PartialDescriptor->u.Interrupt.Level = 1;
-  PartialDescriptor->u.Interrupt.Vector = 0;
+  PartialDescriptor->u.Interrupt.Vector = 1;
   PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
 
   /* Set IO Port 0x60 */
@@ -1654,8 +1733,19 @@ DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey)
   PartialDescriptor->u.Port.Start.HighPart = 0x0;
   PartialDescriptor->u.Port.Length = 1;
 
-  /* Set 'Configuration Data' value */
-  FldrSetConfigurationData(ControllerKey, PartialResourceList, Size);
+    /* Create controller key */
+    FldrCreateComponentKey(BusKey,
+                           ControllerClass,
+                           KeyboardController,
+                           Input | ConsoleIn,
+                           0x0,
+                           0xFFFFFFFF,
+                           NULL,
+                           PartialResourceList,
+                           Size,
+                           &ControllerKey);
+    DPRINTM(DPRINT_HWDETECT, "Created key: KeyboardController\\0\n");
+  
   MmHeapFree(PartialResourceList);
  
   DetectKeyboardPeripheral(ControllerKey);
@@ -1782,21 +1872,6 @@ DetectPS2Mouse(PCONFIGURATION_COMPONENT_DATA BusKey)
     {
       DPRINTM(DPRINT_HWDETECT, "Detected PS2 port\n");
 
-      /* Create controller key */
-      FldrCreateComponentKey(BusKey,
-                             L"PointerController",
-                             0,
-                             ControllerClass,
-                             PointerController,
-                             &ControllerKey);
-      DPRINTM(DPRINT_HWDETECT, "Created key: PointerController\\0\n");
-
-      /* Set 'ComponentInformation' value */
-      FldrSetComponentInformation(ControllerKey,
-                                  Input,
-                                  0,
-                                  0xFFFFFFFF);
-
       memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST));
 
       /* Initialize resource descriptor */
@@ -1809,47 +1884,45 @@ DetectPS2Mouse(PCONFIGURATION_COMPONENT_DATA BusKey)
       PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareUndetermined;
       PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_INTERRUPT_LATCHED;
       PartialResourceList.PartialDescriptors[0].u.Interrupt.Level = 12;
-      PartialResourceList.PartialDescriptors[0].u.Interrupt.Vector = 0;
+      PartialResourceList.PartialDescriptors[0].u.Interrupt.Vector = 12;
       PartialResourceList.PartialDescriptors[0].u.Interrupt.Affinity = 0xFFFFFFFF;
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(ControllerKey,
-                               &PartialResourceList,
-                               sizeof(CM_PARTIAL_RESOURCE_LIST));
+      /* Create controller key */
+      FldrCreateComponentKey(BusKey,
+                             ControllerClass,
+                             PointerController,
+                             Input,
+                             0x0,
+                             0xFFFFFFFF,
+                             NULL,
+                             &PartialResourceList,
+                             sizeof(CM_PARTIAL_RESOURCE_LIST),
+                             &ControllerKey);
+      DPRINTM(DPRINT_HWDETECT, "Created key: PointerController\\0\n");
 
       if (DetectPS2AuxDevice())
        {
          DPRINTM(DPRINT_HWDETECT, "Detected PS2 mouse\n");
 
-          /* Create peripheral key */
-          FldrCreateComponentKey(ControllerKey,
-                                 L"PointerPeripheral",
-                                 0,
-                                 ControllerClass,
-                                 PointerPeripheral,
-                                 &PeripheralKey);
-         DPRINTM(DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n");
-
-         /* Set 'ComponentInformation' value */
-         FldrSetComponentInformation(PeripheralKey,
-                                  Input,
-                                  0,
-                                  0xFFFFFFFF);
-
          /* Initialize resource descriptor */
          memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST));
          PartialResourceList.Version = 1;
          PartialResourceList.Revision = 1;
          PartialResourceList.Count = 0;
 
-         /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(PeripheralKey,
-                               &PartialResourceList,
-                               sizeof(CM_PARTIAL_RESOURCE_LIST) -
-                               sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
-
-         /* Set 'Identifier' value */
-      FldrSetIdentifier(PeripheralKey, "MICROSOFT PS2 MOUSE");
+          /* Create peripheral key */
+          FldrCreateComponentKey(ControllerKey,
+                                 ControllerClass,
+                                 PointerPeripheral,
+                                 Input,
+                                 0x0,
+                                 0xFFFFFFFF,
+                                 "MICROSOFT PS2 MOUSE",
+                                 &PartialResourceList,
+                                 sizeof(CM_PARTIAL_RESOURCE_LIST) -
+                                   sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR),
+                                 &PeripheralKey);
+          DPRINTM(DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n");
     }
   }
 }
@@ -1862,20 +1935,6 @@ DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
   PCONFIGURATION_COMPONENT_DATA ControllerKey;
   USHORT VesaVersion;
 
-  FldrCreateComponentKey(BusKey,
-                         L"DisplayController",
-                         0,
-                         ControllerClass,
-                         DisplayController,
-                         &ControllerKey);
-  DPRINTM(DPRINT_HWDETECT, "Created key: DisplayController\\0\n");
-
-  /* Set 'ComponentInformation' value */
-  FldrSetComponentInformation(ControllerKey,
-                              0x00,
-                              0,
-                              0xFFFFFFFF);
-
   /* FIXME: Set 'ComponentInformation' value */
 
   VesaVersion = BiosIsVesaSupported();
@@ -1903,8 +1962,17 @@ DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
              "VGA Display");
     }
 
-  /* Set 'Identifier' value */
-  FldrSetIdentifier(ControllerKey, Buffer);
+  FldrCreateComponentKey(BusKey,
+                         ControllerClass,
+                         DisplayController,
+                         0x0,
+                         0x0,
+                         0xFFFFFFFF,
+                         Buffer,
+                         NULL,
+                         0,
+                         &ControllerKey);
+  DPRINTM(DPRINT_HWDETECT, "Created key: DisplayController\\0\n");
 
   /* FIXME: Add display peripheral (monitor) data */
 }
@@ -1917,26 +1985,9 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
   PCONFIGURATION_COMPONENT_DATA BusKey;
   ULONG Size;
 
-  /* Create new bus key */
-  FldrCreateComponentKey(SystemKey,
-                         L"MultifunctionAdapter",
-                         *BusNumber,
-                         AdapterClass,
-                         MultiFunctionAdapter,
-                         &BusKey);
-
-  /* Set 'Component Information' value similar to my NT4 box */
-  FldrSetComponentInformation(BusKey,
-                              0x0,
-                              0x0,
-                              0xFFFFFFFF);
-
   /* Increment bus number */
   (*BusNumber)++;
 
-  /* Set 'Identifier' value */
-  FldrSetIdentifier(BusKey, "ISA");
-
   /* Set 'Configuration Data' value */
   Size = sizeof(CM_PARTIAL_RESOURCE_LIST) -
         sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
@@ -1954,12 +2005,24 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
   PartialResourceList->Revision = 1;
   PartialResourceList->Count = 0;
 
-  /* Set 'Configuration Data' value */
-  FldrSetConfigurationData(BusKey, PartialResourceList, Size);
+    /* Create new bus key */
+    FldrCreateComponentKey(SystemKey,
+                           AdapterClass,
+                           MultiFunctionAdapter,
+                           0x0,
+                           0x0,
+                           0xFFFFFFFF,
+                           "ISA",
+                           PartialResourceList,
+                           Size,
+                           &BusKey);
+
   MmHeapFree(PartialResourceList);
 
   /* Detect ISA/BIOS devices */
-  DetectBiosDisks(SystemKey, BusKey);
+  DetectBiosDisks(BusKey);
+
+    DetectBiosFloppyController(BusKey);
 
   DetectSerialPorts(BusKey);
 
@@ -1984,13 +2047,7 @@ PcHwDetect(VOID)
   DPRINTM(DPRINT_HWDETECT, "DetectHardware()\n");
 
   /* Create the 'System' key */
-  FldrCreateSystemKey(&SystemKey);
-
-  /* Set empty component information */
-  FldrSetComponentInformation(SystemKey,
-                              0x0,
-                              0x0,
-                              0xFFFFFFFF);
+  SystemKey = DetectSystem();
   
   /* Detect buses */
   DetectPciBios(SystemKey, &BusNumber);