- Fix incorrect sector size detection which caused seeking to fail when booting...
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / hardware.c
index 0481f39..d4654cc 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>
 /* Timeout in ms for sending to keyboard controller. */
 #define CONTROLLER_TIMEOUT                              250
 
-
-typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
-{
-  ULONG BytesPerSector;
-  ULONG NumberOfCylinders;
-  ULONG SectorsPerTrack;
-  ULONG NumberOfHeads;
-} CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
-
-
-typedef struct _CM_PNP_BIOS_DEVICE_NODE
-{
-  USHORT Size;
-  CHAR  Node;
-  ULONG ProductId;
-  CHAR  DeviceType[3];
-  USHORT DeviceAttributes;
-} __attribute__((packed)) CM_PNP_BIOS_DEVICE_NODE, *PCM_PNP_BIOS_DEVICE_NODE;
-
-
-typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
-{
-  UCHAR  Signature[4];
-  UCHAR  Revision;
-  UCHAR  Length;
-  USHORT ControlField;
-  UCHAR  Checksum;
-  ULONG EventFlagAddress;
-  USHORT RealModeEntryOffset;
-  USHORT RealModeEntrySegment;
-  USHORT ProtectedModeEntryOffset;
-  ULONG ProtectedModeCodeBaseAddress;
-  ULONG OemDeviceId;
-  USHORT RealModeDataBaseAddress;
-  ULONG ProtectedModeDataBaseAddress;
-} __attribute__((packed)) CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
-
-
-static WCHAR Hex[] = L"0123456789ABCDEF";
+static CHAR Hex[] = "0123456789abcdef";
 static unsigned int delay_count = 1;
 
 extern ULONG reactos_disk_count;
@@ -130,7 +93,7 @@ extern char reactos_arc_strings[32][256];
 static VOID
 __StallExecutionProcessor(ULONG Loops)
 {
-  volatile register unsigned int i;
+  register volatile unsigned int i;
   for (i = 0; i < Loops; i++);
 }
 
@@ -236,7 +199,7 @@ HalpCalibrateStallExecution(VOID)
 static VOID
 DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PNP_BIOS_DEVICE_NODE DeviceNode;
   PCM_PNP_BIOS_INSTALLATION_CHECK InstData;
   PCONFIGURATION_COMPONENT_DATA BusKey;
@@ -253,12 +216,12 @@ DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
   InstData = (PCM_PNP_BIOS_INSTALLATION_CHECK)PnpBiosSupported();
   if (InstData == NULL || strncmp((CHAR*)InstData->Signature, "$PnP", 4))
     {
-      DbgPrint((DPRINT_HWDETECT, "PnP-BIOS not supported\n"));
+      DPRINTM(DPRINT_HWDETECT, "PnP-BIOS not supported\n");
       return;
     }
-  DbgPrint((DPRINT_HWDETECT, "Signature '%c%c%c%c'\n",
+  DPRINTM(DPRINT_HWDETECT, "Signature '%c%c%c%c'\n",
            InstData->Signature[0], InstData->Signature[1],
-           InstData->Signature[2], InstData->Signature[3]));
+           InstData->Signature[2], InstData->Signature[3]);
 
 
   x = PnpBiosGetDeviceNodeCount(&NodeSize, &NodeCount);
@@ -267,54 +230,34 @@ DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
                      // e.g. look: http://my.execpc.com/~geezer/osd/pnp/pnp16.c
   if (x != 0 || NodeSize == 0 || NodeCount == 0)
     {
-      DbgPrint((DPRINT_HWDETECT, "PnP-BIOS failed to enumerate device nodes\n"));
+      DPRINTM(DPRINT_HWDETECT, "PnP-BIOS failed to enumerate device nodes\n");
       return;
     }
-  DbgPrint((DPRINT_HWDETECT, "PnP-BIOS supported\n"));
-  DbgPrint((DPRINT_HWDETECT, "MaxNodeSize %u  NodeCount %u\n", NodeSize, NodeCount));
-  DbgPrint((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, L"PNP BIOS");
+  DPRINTM(DPRINT_HWDETECT, "PnP-BIOS supported\n");
+  DPRINTM(DPRINT_HWDETECT, "MaxNodeSize %u  NodeCount %u\n", NodeSize, NodeCount);
+  DPRINTM(DPRINT_HWDETECT, "Estimated buffer size %u\n", NodeSize * NodeCount);
 
     /* Set 'Configuration Data' value */
-  Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) + (NodeSize * NodeCount);
-  FullResourceDescriptor = MmAllocateMemory(Size);
-  if (FullResourceDescriptor == NULL)
+  Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + (NodeSize * NodeCount);
+  PartialResourceList = MmHeapAlloc(Size);
+  if (PartialResourceList == NULL)
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "Failed to allocate resource descriptor\n"));
+      DPRINTM(DPRINT_HWDETECT,
+               "Failed to allocate resource descriptor\n");
       return;
     }
-  memset(FullResourceDescriptor, 0, Size);
+  memset(PartialResourceList, 0, Size);
 
   /* Initialize resource descriptor */
-  FullResourceDescriptor->InterfaceType = Internal;
-  FullResourceDescriptor->BusNumber = 0;
-  FullResourceDescriptor->PartialResourceList.Version = 1;
-  FullResourceDescriptor->PartialResourceList.Revision = 1;
-  FullResourceDescriptor->PartialResourceList.Count = 1;
-  FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Type =
+  PartialResourceList->Version = 1;
+  PartialResourceList->Revision = 1;
+  PartialResourceList->Count = 1;
+  PartialResourceList->PartialDescriptors[0].Type =
     CmResourceTypeDeviceSpecific;
-  FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].ShareDisposition =
+  PartialResourceList->PartialDescriptors[0].ShareDisposition =
     CmResourceShareUndetermined;
 
-  Ptr = (char *)(((ULONG_PTR)&FullResourceDescriptor->PartialResourceList.PartialDescriptors[0]) +
+  Ptr = (char *)(((ULONG_PTR)&PartialResourceList->PartialDescriptors[0]) +
                 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
 
   /* Set instalation check data */
@@ -333,11 +276,11 @@ DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
        {
          DeviceNode = (PCM_PNP_BIOS_DEVICE_NODE)DISKREADBUFFER;
 
-         DbgPrint((DPRINT_HWDETECT,
+         DPRINTM(DPRINT_HWDETECT,
                    "Node: %u  Size %u (0x%x)\n",
                    DeviceNode->Node,
                    DeviceNode->Size,
-                   DeviceNode->Size));
+                   DeviceNode->Size);
 
          memcpy (Ptr,
                  DeviceNode,
@@ -353,55 +296,70 @@ DetectPnpBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
     }
 
   /* Set real data size */
-  FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].u.DeviceSpecificData.DataSize =
+  PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize =
     PnpBufferSize;
-  Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) + PnpBufferSize;
+  Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + PnpBufferSize;
 
-  DbgPrint((DPRINT_HWDETECT, "Real buffer size: %u\n", PnpBufferSize));
-  DbgPrint((DPRINT_HWDETECT, "Resource size: %u\n", Size));
-  
-    FldrSetConfigurationData(BusKey, FullResourceDescriptor, Size);
-    MmFreeMemory(FullResourceDescriptor);
+  DPRINTM(DPRINT_HWDETECT, "Real buffer size: %u\n", PnpBufferSize);
+  DPRINTM(DPRINT_HWDETECT, "Resource size: %u\n", 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_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
   EXTENDED_GEOMETRY ExtGeometry;
   GEOMETRY Geometry;
   ULONG Size;
 
+    //
+    // Initialize returned size
+    //
+    *pSize = 0;
+
   /* Set 'Configuration Data' value */
-  Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) +
+  Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
         sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
-  FullResourceDescriptor = MmAllocateMemory(Size);
-  if (FullResourceDescriptor == NULL)
+  PartialResourceList = MmHeapAlloc(Size);
+  if (PartialResourceList == NULL)
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "Failed to allocate a full resource descriptor\n"));
-      return;
+      DPRINTM(DPRINT_HWDETECT,
+               "Failed to allocate a full resource descriptor\n");
+      return NULL;
     }
 
-  memset(FullResourceDescriptor, 0, Size);
-  FullResourceDescriptor->InterfaceType = InterfaceTypeUndefined;
-  FullResourceDescriptor->BusNumber = 0;
-  FullResourceDescriptor->PartialResourceList.Version = 1;
-  FullResourceDescriptor->PartialResourceList.Revision = 1;
-  FullResourceDescriptor->PartialResourceList.Count = 1;
-  FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Type =
+  memset(PartialResourceList, 0, Size);
+  PartialResourceList->Version = 1;
+  PartialResourceList->Revision = 1;
+  PartialResourceList->Count = 1;
+  PartialResourceList->PartialDescriptors[0].Type =
     CmResourceTypeDeviceSpecific;
-//  FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].ShareDisposition =
-//  FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Flags =
-  FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].u.DeviceSpecificData.DataSize =
+//  PartialResourceList->PartialDescriptors[0].ShareDisposition =
+//  PartialResourceList->PartialDescriptors[0].Flags =
+  PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize =
     sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
 
   /* Get pointer to geometry data */
-  DiskGeometry = (PVOID)(((ULONG_PTR)FullResourceDescriptor) + sizeof(CM_FULL_RESOURCE_DESCRIPTOR));
+  DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST));
 
   /* Get the disk geometry */
   ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
@@ -421,25 +379,157 @@ SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey,
     }
   else
     {
-      DbgPrint((DPRINT_HWDETECT, "Reading disk geometry failed\n"));
-      MmFreeMemory(FullResourceDescriptor);
-      return;
+      DPRINTM(DPRINT_HWDETECT, "Reading disk geometry failed\n");
+      MmHeapFree(PartialResourceList);
+      return NULL;
     }
-  DbgPrint((DPRINT_HWDETECT,
+  DPRINTM(DPRINT_HWDETECT,
           "Disk %x: %u Cylinders  %u Heads  %u Sectors  %u Bytes\n",
           DriveNumber,
           DiskGeometry->NumberOfCylinders,
           DiskGeometry->NumberOfHeads,
           DiskGeometry->SectorsPerTrack,
-          DiskGeometry->BytesPerSector));
+          DiskGeometry->BytesPerSector);
+
+    //
+    // Return configuration data
+    //
+    *pSize = Size;
+    return PartialResourceList;
+}
+
+typedef struct tagDISKCONTEXT
+{
+    ULONG DriveNumber;
+    ULONG SectorSize;
+    ULONGLONG SectorOffset;
+    ULONGLONG SectorCount;
+    ULONGLONG SectorNumber;
+} DISKCONTEXT;
+
+static LONG DiskClose(ULONG FileId)
+{
+    DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
+
+    MmHeapFree(Context);
+    return ESUCCESS;
+}
+
+static LONG DiskGetFileInformation(ULONG FileId, FILEINFORMATION* Information)
+{
+    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)
+{
+    DISKCONTEXT* Context;
+    ULONG DriveNumber, DrivePartition, SectorSize;
+    ULONGLONG SectorOffset = 0;
+    ULONGLONG SectorCount = 0;
+    PARTITION_TABLE_ENTRY PartitionTableEntry;
+    GEOMETRY Geometry;
+    EXTENDED_GEOMETRY ExtGeometry;
+    CHAR FileName[1];
+
+    if (!DissectArcPath(Path, FileName, &DriveNumber, &DrivePartition))
+        return EINVAL;
+
+    ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
+    if (DiskGetExtendedDriveParameters(DriveNumber, &ExtGeometry, ExtGeometry.Size))
+    {
+        SectorSize = ExtGeometry.BytesPerSector;
+        SectorCount = ExtGeometry.Sectors;
+    }
+    else if (MachDiskGetDriveGeometry(DriveNumber, &Geometry))
+    {
+        SectorSize = Geometry.BytesPerSector;
+        SectorCount = Geometry.Sectors;
+    }
+    else
+        return EINVAL;
+
+    if (DrivePartition != 0xff && DrivePartition != 0)
+    {
+        if (!DiskGetPartitionEntry(DriveNumber, DrivePartition, &PartitionTableEntry))
+            return EINVAL;
+        SectorOffset = PartitionTableEntry.SectorCountBeforePartition;
+        SectorCount = PartitionTableEntry.PartitionSectorCount;
+    }
+
+    Context = MmHeapAlloc(sizeof(DISKCONTEXT));
+    if (!Context)
+        return ENOMEM;
+    Context->DriveNumber = DriveNumber;
+    Context->SectorSize = SectorSize;
+    Context->SectorOffset = SectorOffset;
+    Context->SectorCount = SectorCount;
+    Context->SectorNumber = 0;
+    FsSetDeviceSpecific(*FileId, Context);
+
+    return ESUCCESS;
+}
+
+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;
+    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++;
+    }
 
-  FldrSetConfigurationData(DiskKey, FullResourceDescriptor, Size);
-  MmFreeMemory(FullResourceDescriptor);
+    return ESUCCESS;
 }
 
+static LONG DiskSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode)
+{
+    DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
+
+    if (SeekMode != SeekAbsolute)
+        return EINVAL;
+    if (Position->LowPart & (Context->SectorSize - 1))
+        return EINVAL;
+
+    /* FIXME: take HighPart into account */
+    Context->SectorNumber = Position->LowPart / Context->SectorSize;
+    return ESUCCESS;
+}
+
+static const DEVVTBL DiskVtbl = {
+    DiskClose,
+    DiskGetFileInformation,
+    DiskOpen,
+    DiskRead,
+    DiskSeek,
+};
 
 static VOID
-SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
+GetHarddiskIdentifier(PCHAR Identifier,
                      ULONG DriveNumber)
 {
   PMASTER_BOOT_RECORD Mbr;
@@ -447,13 +537,13 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
   ULONG i;
   ULONG Checksum;
   ULONG Signature;
-  WCHAR Identifier[20];
   CHAR ArcName[256];
+  PARTITION_TABLE_ENTRY PartitionTableEntry;
 
   /* Read the MBR */
   if (!MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, (PVOID)DISKREADBUFFER))
     {
-      DbgPrint((DPRINT_HWDETECT, "Reading MBR failed\n"));
+      DPRINTM(DPRINT_HWDETECT, "Reading MBR failed\n");
       return;
     }
 
@@ -461,7 +551,7 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
   Mbr = (PMASTER_BOOT_RECORD)DISKREADBUFFER;
 
   Signature =  Mbr->Signature;
-  DbgPrint((DPRINT_HWDETECT, "Signature: %x\n", Signature));
+  DPRINTM(DPRINT_HWDETECT, "Signature: %x\n", Signature);
 
   /* Calculate the MBR checksum */
   Checksum = 0;
@@ -470,7 +560,7 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
       Checksum += Buffer[i];
     }
   Checksum = ~Checksum + 1;
-  DbgPrint((DPRINT_HWDETECT, "Checksum: %x\n", Checksum));
+  DPRINTM(DPRINT_HWDETECT, "Checksum: %x\n", Checksum);
 
   /* Fill out the ARC disk block */
   reactos_arc_disk_info[reactos_disk_count].Signature = Signature;
@@ -481,6 +571,23 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
       reactos_arc_strings[reactos_disk_count];
   reactos_disk_count++;
 
+  sprintf(ArcName, "multi(0)disk(0)rdisk(%lu)partition(0)", DriveNumber - 0x80);
+  FsRegisterDevice(ArcName, &DiskVtbl);
+
+  /* Add partitions */
+  i = 1;
+  DiskReportError(FALSE);
+  while (DiskGetPartitionEntry(DriveNumber, i, &PartitionTableEntry))
+  {
+    if (PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
+    {
+      sprintf(ArcName, "multi(0)disk(0)rdisk(%lu)partition(%lu)", DriveNumber - 0x80, i);
+      FsRegisterDevice(ArcName, &DiskVtbl);
+    }
+    i++;
+  }
+  DiskReportError(TRUE);
+
   /* Convert checksum and signature to identifier string */
   Identifier[0] = Hex[(Checksum >> 28) & 0x0F];
   Identifier[1] = Hex[(Checksum >> 24) & 0x0F];
@@ -490,7 +597,7 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
   Identifier[5] = Hex[(Checksum >> 8) & 0x0F];
   Identifier[6] = Hex[(Checksum >> 4) & 0x0F];
   Identifier[7] = Hex[Checksum & 0x0F];
-  Identifier[8] = L'-';
+  Identifier[8] = '-';
   Identifier[9] = Hex[(Signature >> 28) & 0x0F];
   Identifier[10] = Hex[(Signature >> 24) & 0x0F];
   Identifier[11] = Hex[(Signature >> 20) & 0x0F];
@@ -499,13 +606,10 @@ SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey,
   Identifier[14] = Hex[(Signature >> 8) & 0x0F];
   Identifier[15] = Hex[(Signature >> 4) & 0x0F];
   Identifier[16] = Hex[Signature & 0x0F];
-  Identifier[17] = L'-';
-  Identifier[18] = L'A';
+  Identifier[17] = '-';
+  Identifier[18] = 'A';
   Identifier[19] = 0;
-  DbgPrint((DPRINT_HWDETECT, "Identifier: %S\n", Identifier));
-
-  /* Set identifier */
-  FldrSetIdentifier(DiskKey, Identifier);
+  DPRINTM(DPRINT_HWDETECT, "Identifier: %s\n", Identifier);
 }
 
 static ULONG
@@ -550,10 +654,10 @@ GetInt1eTable(VOID)
 static VOID
 DetectBiosFloppyPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
   PCM_FLOPPY_DEVICE_DATA FloppyData;
-  WCHAR Identifier[20];
+  CHAR Identifier[20];
   PCONFIGURATION_COMPONENT_DATA PeripheralKey;
   ULONG Size;
   ULONG FloppyNumber;
@@ -571,43 +675,31 @@ 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_FULL_RESOURCE_DESCRIPTOR) +
+    Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
           sizeof(CM_FLOPPY_DEVICE_DATA);
-    FullResourceDescriptor = MmAllocateMemory(Size);
-    if (FullResourceDescriptor == NULL)
+    PartialResourceList = MmHeapAlloc(Size);
+    if (PartialResourceList == NULL)
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "Failed to allocate resource descriptor\n"));
+      DPRINTM(DPRINT_HWDETECT,
+               "Failed to allocate resource descriptor\n");
       return;
     }
 
-    memset(FullResourceDescriptor, 0, Size);
-    FullResourceDescriptor->InterfaceType = Isa;
-    FullResourceDescriptor->BusNumber = 0;
-    FullResourceDescriptor->PartialResourceList.Version = 1;
-    FullResourceDescriptor->PartialResourceList.Revision = 1;
-    FullResourceDescriptor->PartialResourceList.Count = 1;
+    memset(PartialResourceList, 0, Size);
+    PartialResourceList->Version = 1;
+    PartialResourceList->Revision = 1;
+    PartialResourceList->Count = 1;
 
-    PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[0];
+    PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
     PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
     PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
     PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(CM_FLOPPY_DEVICE_DATA);
 
-    FloppyData = (PVOID)(((ULONG_PTR)FullResourceDescriptor) + sizeof(CM_FULL_RESOURCE_DESCRIPTOR));
+    FloppyData = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST));
     FloppyData->Version = 2;
     FloppyData->Revision = 0;
     FloppyData->MaxDensity = MaxDensity[FloppyType];
@@ -618,51 +710,54 @@ DetectBiosFloppyPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
     FloppyData->MaximumTrackValue = (FloppyType == 1) ? 39 : 79;
     FloppyData->DataTransferRate = 0;
 
-    /* Set 'Configuration Data' value */
-    FldrSetConfigurationData(PeripheralKey, FullResourceDescriptor, Size);
-    MmFreeMemory(FullResourceDescriptor);
+    FldrCreateComponentKey(ControllerKey,
+                           PeripheralClass,
+                           FloppyDiskPeripheral,
+                           Input | Output,
+                           FloppyNumber,
+                           0xFFFFFFFF,
+                           Identifier,
+                           PartialResourceList,
+                           Size,
+                           &PeripheralKey);
 
-    /* Set 'Identifier' value */
-    swprintf(Identifier, L"FLOPPY%u", FloppyNumber + 1);
-    FldrSetIdentifier(PeripheralKey, Identifier);
+    MmHeapFree(PartialResourceList);
   }
 }
 
 
 static VOID
-DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey,
-                           PCONFIGURATION_COMPONENT_DATA ControllerKey)
+DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCONFIGURATION_COMPONENT_DATA ControllerKey;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
   ULONG Size;
   ULONG FloppyCount;
 
   FloppyCount = GetFloppyCount();
-  DbgPrint((DPRINT_HWDETECT,
+  DPRINTM(DPRINT_HWDETECT,
            "Floppy count: %u\n",
-           FloppyCount));
+           FloppyCount);
   
-  Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) +
+  Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
         2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
-  FullResourceDescriptor = MmAllocateMemory(Size);
-  if (FullResourceDescriptor == NULL)
+  PartialResourceList = MmHeapAlloc(Size);
+  if (PartialResourceList == NULL)
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "Failed to allocate resource descriptor\n"));
+      DPRINTM(DPRINT_HWDETECT,
+               "Failed to allocate resource descriptor\n");
       return;
     }
-  memset(FullResourceDescriptor, 0, Size);
+  memset(PartialResourceList, 0, Size);
 
   /* Initialize resource descriptor */
-  FullResourceDescriptor->InterfaceType = Isa;
-  FullResourceDescriptor->BusNumber = 0;
-  FullResourceDescriptor->PartialResourceList.Version = 1;
-  FullResourceDescriptor->PartialResourceList.Revision = 1;
-  FullResourceDescriptor->PartialResourceList.Count = 3;
+  PartialResourceList->Version = 1;
+  PartialResourceList->Revision = 1;
+  PartialResourceList->Count = 3;
 
   /* Set IO Port */
-  PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[0];
+  PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
   PartialDescriptor->Type = CmResourceTypePort;
   PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
   PartialDescriptor->Flags = CM_RESOURCE_PORT_IO;
@@ -671,7 +766,7 @@ DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey,
   PartialDescriptor->u.Port.Length = 8;
 
   /* Set Interrupt */
-  PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[1];
+  PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
   PartialDescriptor->Type = CmResourceTypeInterrupt;
   PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
   PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
@@ -680,28 +775,38 @@ DetectBiosFloppyController(PCONFIGURATION_COMPONENT_DATA BusKey,
   PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
 
   /* Set DMA channel */
-  PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[2];
+  PartialDescriptor = &PartialResourceList->PartialDescriptors[2];
   PartialDescriptor->Type = CmResourceTypeDma;
   PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
   PartialDescriptor->Flags = 0;
   PartialDescriptor->u.Dma.Channel = 2;
   PartialDescriptor->u.Dma.Port = 0;
 
-  /* Set 'Configuration Data' value */
-  FldrSetConfigurationData(ControllerKey, FullResourceDescriptor, Size);
-  MmFreeMemory(FullResourceDescriptor);
+    /* 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)
 {
-    PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+    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;
@@ -726,59 +831,41 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey,
         }
         if (! Changed)
         {
-            DbgPrint((DPRINT_HWDETECT, "BIOS reports success for disk %d but data didn't change\n",
-                      (int)DiskCount));
+            DPRINTM(DPRINT_HWDETECT, "BIOS reports success for disk %d but data didn't change\n",
+                      (int)DiskCount);
             break;
         }
         DiskCount++;
         memset((PVOID) DISKREADBUFFER, 0xcd, 512);
     }
     DiskReportError(TRUE);
-    DbgPrint((DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n",
-              (int)DiskCount, (DiskCount == 1) ? "": "s"));
-    
-    FldrCreateComponentKey(BusKey,
-                           L"DiskController",
-                           0,
-                           ControllerClass,
-                           DiskController,
-                           &ControllerKey);
-    DbgPrint((DPRINT_HWDETECT, "Created key: DiskController\\0\n"));
-    
-    /* Set 'ComponentInformation' value */
-    FldrSetComponentInformation(ControllerKey,
-                                Output | Input | Removable,
-                                0,
-                                0xFFFFFFFF);
-    
-    DetectBiosFloppyController(BusKey, ControllerKey);
+    DPRINTM(DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n",
+              (int)DiskCount, (DiskCount == 1) ? "": "s");
     
     /* Allocate resource descriptor */
-    Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) +
+    Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
         sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount;
-    FullResourceDescriptor = MmAllocateMemory(Size);
-    if (FullResourceDescriptor == NULL)
+    PartialResourceList = MmHeapAlloc(Size);
+    if (PartialResourceList == NULL)
     {
-        DbgPrint((DPRINT_HWDETECT,
-                  "Failed to allocate resource descriptor\n"));
-        return;
+        DPRINTM(DPRINT_HWDETECT,
+                  "Failed to allocate resource descriptor\n");
+        return NULL;
     }
     
     /* Initialize resource descriptor */
-    memset(FullResourceDescriptor, 0, Size);
-    FullResourceDescriptor->InterfaceType = InterfaceTypeUndefined;
-    FullResourceDescriptor->BusNumber = -1;
-    FullResourceDescriptor->PartialResourceList.Version = 1;
-    FullResourceDescriptor->PartialResourceList.Revision = 1;
-    FullResourceDescriptor->PartialResourceList.Count = 1;
-    FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeDeviceSpecific;
-    FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].ShareDisposition = 0;
-    FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Flags = 0;
-    FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].u.DeviceSpecificData.DataSize =
+    memset(PartialResourceList, 0, Size);
+    PartialResourceList->Version = 1;
+    PartialResourceList->Revision = 1;
+    PartialResourceList->Count = 1;
+    PartialResourceList->PartialDescriptors[0].Type = CmResourceTypeDeviceSpecific;
+    PartialResourceList->PartialDescriptors[0].ShareDisposition = 0;
+    PartialResourceList->PartialDescriptors[0].Flags = 0;
+    PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize =
         sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount;
     
     /* Get harddisk Int13 geometry data */
-    Int13Drives = (PVOID)(((ULONG_PTR)FullResourceDescriptor) + sizeof(CM_FULL_RESOURCE_DESCRIPTOR));
+    Int13Drives = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST));
     for (i = 0; i < DiskCount; i++)
     {
         if (MachDiskGetDriveGeometry(0x80 + i, &Geometry))
@@ -789,59 +876,166 @@ DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey,
             Int13Drives[i].MaxHeads = Geometry.Heads - 1;
             Int13Drives[i].NumberDrives = DiskCount;
             
-            DbgPrint((DPRINT_HWDETECT,
+            DPRINTM(DPRINT_HWDETECT,
                       "Disk %x: %u Cylinders  %u Heads  %u Sectors  %u Bytes\n",
                       0x80 + i,
                       Geometry.Cylinders - 1,
                       Geometry.Heads -1,
                       Geometry.Sectors,
-                      Geometry.BytesPerSector));
+                      Geometry.BytesPerSector);
         }
     }
-    
-    /* Set 'Configuration Data' value */
-    FldrSetConfigurationData(SystemKey, FullResourceDescriptor, Size);
-    MmFreeMemory(FullResourceDescriptor);
+
+    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);
+    }
+
+    /* 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
-InitializeSerialPort(ULONG Port,
+InitializeSerialPort(PUCHAR Port,
                     ULONG LineControl)
 {
-  WRITE_PORT_UCHAR((PUCHAR)Port + 3, 0x80);  /* set DLAB on   */
-  WRITE_PORT_UCHAR((PUCHAR)Port,     0x60);  /* speed LO byte */
-  WRITE_PORT_UCHAR((PUCHAR)Port + 1, 0);     /* speed HI byte */
-  WRITE_PORT_UCHAR((PUCHAR)Port + 3, LineControl);
-  WRITE_PORT_UCHAR((PUCHAR)Port + 1, 0);     /* set comm and DLAB to 0 */
-  WRITE_PORT_UCHAR((PUCHAR)Port + 4, 0x09);  /* DR int enable */
-  READ_PORT_UCHAR((PUCHAR)Port + 5);  /* clear error bits */
+  WRITE_PORT_UCHAR(Port + 3, 0x80);  /* set DLAB on   */
+  WRITE_PORT_UCHAR(Port,     0x60);  /* speed LO byte */
+  WRITE_PORT_UCHAR(Port + 1, 0);     /* speed HI byte */
+  WRITE_PORT_UCHAR(Port + 3, LineControl);
+  WRITE_PORT_UCHAR(Port + 1, 0);     /* set comm and DLAB to 0 */
+  WRITE_PORT_UCHAR(Port + 4, 0x09);  /* DR int enable */
+  READ_PORT_UCHAR(Port + 5);  /* clear error bits */
 }
 
 
 static ULONG
-DetectSerialMouse(ULONG Port)
+DetectSerialMouse(PUCHAR Port)
 {
   CHAR Buffer[4];
   ULONG i;
@@ -849,8 +1043,8 @@ DetectSerialMouse(ULONG Port)
   UCHAR LineControl;
 
   /* Shutdown mouse or something like that */
-  LineControl = READ_PORT_UCHAR((PUCHAR)Port + 4);
-  WRITE_PORT_UCHAR((PUCHAR)Port + 4, (LineControl & ~0x02) | 0x01);
+  LineControl = READ_PORT_UCHAR(Port + 4);
+  WRITE_PORT_UCHAR(Port + 4, (LineControl & ~0x02) | 0x01);
   StallExecutionProcessor(100000);
 
   /*
@@ -860,18 +1054,18 @@ DetectSerialMouse(ULONG Port)
    * therefore we must give up after some time.
    */
   TimeOut = 200;
-  while (READ_PORT_UCHAR((PUCHAR)Port + 5) & 0x01)
+  while (READ_PORT_UCHAR(Port + 5) & 0x01)
     {
       if (--TimeOut == 0)
         return MOUSE_TYPE_NONE;
-      READ_PORT_UCHAR((PUCHAR)Port);
+      READ_PORT_UCHAR(Port);
     }
 
   /*
    * Send modem control with 'Data Terminal Ready', 'Request To Send' and
    * 'Output Line 2' message. This enables mouse to identify.
    */
-  WRITE_PORT_UCHAR((PUCHAR)Port + 4, 0x0b);
+  WRITE_PORT_UCHAR(Port + 4, 0x0b);
 
   /* Wait 10 milliseconds for the mouse getting ready */
   StallExecutionProcessor(10000);
@@ -880,19 +1074,19 @@ DetectSerialMouse(ULONG Port)
   TimeOut = 200;
   for (i = 0; i < 4; i++)
     {
-      while (((READ_PORT_UCHAR((PUCHAR)Port + 5) & 1) == 0) && (TimeOut > 0))
+      while (((READ_PORT_UCHAR(Port + 5) & 1) == 0) && (TimeOut > 0))
        {
          StallExecutionProcessor(1000);
          --TimeOut;
          if (TimeOut == 0)
            return MOUSE_TYPE_NONE;
        }
-      Buffer[i] = READ_PORT_UCHAR((PUCHAR)Port);
+      Buffer[i] = READ_PORT_UCHAR(Port);
     }
 
-  DbgPrint((DPRINT_HWDETECT,
+  DPRINTM(DPRINT_HWDETECT,
            "Mouse data: %x %x %x %x\n",
-           Buffer[0],Buffer[1],Buffer[2],Buffer[3]));
+           Buffer[0],Buffer[1],Buffer[2],Buffer[3]);
 
   /* Check that four bytes for signs */
   for (i = 0; i < 4; ++i)
@@ -916,19 +1110,19 @@ DetectSerialMouse(ULONG Port)
          switch (Buffer[i + 1])
            {
              case '3':
-               DbgPrint((DPRINT_HWDETECT,
-                         "Microsoft Mouse with 3-buttons detected\n"));
+               DPRINTM(DPRINT_HWDETECT,
+                         "Microsoft Mouse with 3-buttons detected\n");
                return MOUSE_TYPE_LOGITECH;
 
              case 'Z':
-               DbgPrint((DPRINT_HWDETECT,
-                         "Microsoft Wheel Mouse detected\n"));
+               DPRINTM(DPRINT_HWDETECT,
+                         "Microsoft Wheel Mouse detected\n");
                return MOUSE_TYPE_WHEELZ;
 
              /* case '2': */
              default:
-               DbgPrint((DPRINT_HWDETECT,
-                         "Microsoft Mouse with 2-buttons detected\n"));
+               DPRINTM(DPRINT_HWDETECT,
+                         "Microsoft Mouse with 2-buttons detected\n");
                return MOUSE_TYPE_MICROSOFT;
            }
        }
@@ -939,26 +1133,26 @@ DetectSerialMouse(ULONG Port)
 
 
 static ULONG
-GetSerialMousePnpId(ULONG Port, char *Buffer)
+GetSerialMousePnpId(PUCHAR Port, char *Buffer)
 {
   ULONG TimeOut;
   ULONG i = 0;
   char c;
   char x;
 
-  WRITE_PORT_UCHAR((PUCHAR)Port + 4, 0x09);
+  WRITE_PORT_UCHAR(Port + 4, 0x09);
 
   /* Wait 10 milliseconds for the mouse getting ready */
   StallExecutionProcessor(10000);
 
-  WRITE_PORT_UCHAR((PUCHAR)Port + 4, 0x0b);
+  WRITE_PORT_UCHAR(Port + 4, 0x0b);
 
   StallExecutionProcessor(10000);
 
   for (;;)
     {
       TimeOut = 200;
-      while (((READ_PORT_UCHAR((PUCHAR)Port + 5) & 1) == 0) && (TimeOut > 0))
+      while (((READ_PORT_UCHAR(Port + 5) & 1) == 0) && (TimeOut > 0))
        {
          StallExecutionProcessor(1000);
          --TimeOut;
@@ -968,7 +1162,7 @@ GetSerialMousePnpId(ULONG Port, char *Buffer)
            }
        }
 
-      c = READ_PORT_UCHAR((PUCHAR)Port);
+      c = READ_PORT_UCHAR(Port);
       if (c == 0x08 || c == 0x28)
        break;
     }
@@ -979,14 +1173,14 @@ GetSerialMousePnpId(ULONG Port, char *Buffer)
   for (;;)
     {
       TimeOut = 200;
-      while (((READ_PORT_UCHAR((PUCHAR)Port + 5) & 1) == 0) && (TimeOut > 0))
+      while (((READ_PORT_UCHAR(Port + 5) & 1) == 0) && (TimeOut > 0))
        {
          StallExecutionProcessor(1000);
          --TimeOut;
          if (TimeOut == 0)
            return 0;
        }
-      c = READ_PORT_UCHAR((PUCHAR)Port);
+      c = READ_PORT_UCHAR(Port);
       Buffer[i++] = c;
       if (c == x)
        break;
@@ -1000,11 +1194,11 @@ GetSerialMousePnpId(ULONG Port, char *Buffer)
 
 static VOID
 DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
-                             ULONG Base)
+                             PUCHAR Base)
 {
-  CM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  CM_PARTIAL_RESOURCE_LIST PartialResourceList;
   char Buffer[256];
-  WCHAR Identifier[256];
+  CHAR Identifier[256];
   PCONFIGURATION_COMPONENT_DATA PeripheralKey;
   ULONG MouseType;
   ULONG Length;
@@ -1012,8 +1206,8 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
   ULONG j;
   ULONG k;
 
-  DbgPrint((DPRINT_HWDETECT,
-           "DetectSerialPointerPeripheral()\n"));
+  DPRINTM(DPRINT_HWDETECT,
+           "DetectSerialPointerPeripheral()\n");
 
   Identifier[0] = 0;
 
@@ -1023,9 +1217,9 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
   if (MouseType != MOUSE_TYPE_NONE)
     {
       Length = GetSerialMousePnpId(Base, Buffer);
-      DbgPrint((DPRINT_HWDETECT,
+      DPRINTM(DPRINT_HWDETECT,
                "PnP ID length: %u\n",
-               Length));
+               Length);
 
       if (Length != 0)
        {
@@ -1037,9 +1231,9 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
            }
          Buffer[Length] = 0;
 
-         DbgPrint((DPRINT_HWDETECT,
+         DPRINTM(DPRINT_HWDETECT,
                    "PnP ID string: %s\n",
-                   Buffer));
+                   Buffer);
 
          /* Copy PnpId string */
           for (i = 0; i < 7; i++)
@@ -1110,64 +1304,54 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
                }
            }
 
-         DbgPrint((DPRINT_HWDETECT,
-                   "Identifier string: %S\n",
-                   Identifier));
+         DPRINTM(DPRINT_HWDETECT,
+                   "Identifier string: %s\n",
+                   Identifier);
        }
 
-      if (Length == 0 || wcslen(Identifier) < 11)
+      if (Length == 0 || strlen(Identifier) < 11)
        {
          switch (MouseType)
            {
              case MOUSE_TYPE_LOGITECH:
-               wcscpy (Identifier,
-                       L"LOGITECH SERIAL MOUSE");
+               strcpy (Identifier,
+                       "LOGITECH SERIAL MOUSE");
                break;
 
              case MOUSE_TYPE_WHEELZ:
-               wcscpy (Identifier,
-                       L"MICROSOFT SERIAL MOUSE WITH WHEEL");
+               strcpy (Identifier,
+                       "MICROSOFT SERIAL MOUSE WITH WHEEL");
                break;
 
              case MOUSE_TYPE_MICROSOFT:
              default:
-               wcscpy (Identifier,
-                       L"MICROSOFT SERIAL MOUSE");
+               strcpy (Identifier,
+                       "MICROSOFT SERIAL MOUSE");
                break;
            }
        }
 
+      /* Set 'Configuration Data' value */
+      memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST));
+      PartialResourceList.Version = 1;
+      PartialResourceList.Revision = 1;
+      PartialResourceList.Count = 0;
+
       /* Create 'PointerPeripheral' key */
       FldrCreateComponentKey(ControllerKey,
-                             L"PointerPeripheral",
-                             0,
                              PeripheralClass,
                              PointerPeripheral,
+                             Input,
+                             0x0,
+                             0xFFFFFFFF,
+                             Identifier,
+                             &PartialResourceList,
+                             sizeof(CM_PARTIAL_RESOURCE_LIST) -
+                                 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR),
                              &PeripheralKey);
-      DbgPrint((DPRINT_HWDETECT,
-               "Created key: PointerPeripheral\\0\n"));
-
-      /* Set 'ComponentInformation' value */
-      FldrSetComponentInformation(PeripheralKey,
-                                  Input,
-                                  0,
-                                  0xFFFFFFFF);
-
-      /* Set 'Configuration Data' value */
-      memset(&FullResourceDescriptor, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR));
-      FullResourceDescriptor.InterfaceType = Isa;
-      FullResourceDescriptor.BusNumber = 0;
-      FullResourceDescriptor.PartialResourceList.Version = 1;
-      FullResourceDescriptor.PartialResourceList.Revision = 1;
-      FullResourceDescriptor.PartialResourceList.Count = 0;
-
-      FldrSetConfigurationData(PeripheralKey,
-                               &FullResourceDescriptor,
-                               sizeof(CM_FULL_RESOURCE_DESCRIPTOR) -
-                               sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
 
-      /* Set 'Identifier' value */
-      FldrSetIdentifier(PeripheralKey, Identifier);
+      DPRINTM(DPRINT_HWDETECT,
+          "Created key: PointerPeripheral\\0\n");
     }
 }
 
@@ -1175,19 +1359,19 @@ DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey,
 static VOID
 DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
   PCM_SERIAL_DEVICE_DATA SerialDeviceData;
   ULONG Irq[4] = {4, 3, 4, 3};
   ULONG Base;
-  WCHAR Buffer[80];
+  CHAR Buffer[80];
   PUSHORT BasePtr;
   ULONG ControllerNumber = 0;
   PCONFIGURATION_COMPONENT_DATA ControllerKey;
   ULONG i;
   ULONG Size;
 
-  DbgPrint((DPRINT_HWDETECT, "DetectSerialPorts()\n"));
+  DPRINTM(DPRINT_HWDETECT, "DetectSerialPorts()\n");
 
   ControllerNumber = 0;
   BasePtr = (PUSHORT)0x400;
@@ -1197,47 +1381,34 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
       if (Base == 0)
         continue;
 
-      DbgPrint((DPRINT_HWDETECT,
+      DPRINTM(DPRINT_HWDETECT,
                "Found COM%u port at 0x%x\n",
                i + 1,
-               Base));
+               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_FULL_RESOURCE_DESCRIPTOR) +
+      Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
             2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) +
             sizeof(CM_SERIAL_DEVICE_DATA);
-      FullResourceDescriptor = MmAllocateMemory(Size);
-      if (FullResourceDescriptor == NULL)
+      PartialResourceList = MmHeapAlloc(Size);
+      if (PartialResourceList == NULL)
        {
-         DbgPrint((DPRINT_HWDETECT,
-                   "Failed to allocate resource descriptor\n"));
+         DPRINTM(DPRINT_HWDETECT,
+                   "Failed to allocate resource descriptor\n");
          continue;
        }
-      memset(FullResourceDescriptor, 0, Size);
+      memset(PartialResourceList, 0, Size);
 
       /* Initialize resource descriptor */
-      FullResourceDescriptor->InterfaceType = Isa;
-      FullResourceDescriptor->BusNumber = 0;
-      FullResourceDescriptor->PartialResourceList.Version = 1;
-      FullResourceDescriptor->PartialResourceList.Revision = 1;
-      FullResourceDescriptor->PartialResourceList.Count = 3;
+      PartialResourceList->Version = 1;
+      PartialResourceList->Revision = 1;
+      PartialResourceList->Count = 3;
 
       /* Set IO Port */
-      PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[0];
+      PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
       PartialDescriptor->Type = CmResourceTypePort;
       PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
       PartialDescriptor->Flags = CM_RESOURCE_PORT_IO;
@@ -1246,7 +1417,7 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
       PartialDescriptor->u.Port.Length = 7;
 
       /* Set Interrupt */
-      PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[1];
+      PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
       PartialDescriptor->Type = CmResourceTypeInterrupt;
       PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
       PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
@@ -1255,31 +1426,34 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
       PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
 
       /* Set serial data (device specific) */
-      PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[2];
+      PartialDescriptor = &PartialResourceList->PartialDescriptors[2];
       PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
       PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
       PartialDescriptor->Flags = 0;
       PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(CM_SERIAL_DEVICE_DATA);
 
       SerialDeviceData =
-       (PCM_SERIAL_DEVICE_DATA)&FullResourceDescriptor->PartialResourceList.PartialDescriptors[3];
+       (PCM_SERIAL_DEVICE_DATA)&PartialResourceList->PartialDescriptors[3];
       SerialDeviceData->BaudClock = 1843200; /* UART Clock frequency (Hertz) */
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(ControllerKey, FullResourceDescriptor, Size);
-      MmFreeMemory(FullResourceDescriptor);
-      
-      /* Set 'Identifier' value */
-      swprintf(Buffer, L"COM%u", i + 1);
-      FldrSetIdentifier(ControllerKey, Buffer);
-      DbgPrint((DPRINT_HWDETECT,
-               "Created value: Identifier %s\n",
-               Buffer));
+      /* Create controller key */
+      FldrCreateComponentKey(BusKey,
+                             ControllerClass,
+                             SerialController,
+                             Output | Input | ConsoleIn | ConsoleOut,
+                             ControllerNumber,
+                             0xFFFFFFFF,
+                             Buffer,
+                             PartialResourceList,
+                             Size,
+                             &ControllerKey);
+
+      MmHeapFree(PartialResourceList);
 
       if (!Rs232PortInUse(Base))
         {
           /* Detect serial mouse */
-          DetectSerialPointerPeripheral(ControllerKey, Base);
+          DetectSerialPointerPeripheral(ControllerKey, UlongToPtr(Base));
         }
 
       ControllerNumber++;
@@ -1290,10 +1464,10 @@ DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
 static VOID
 DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
   ULONG Irq[3] = {7, 5, (ULONG)-1};
-  WCHAR Buffer[80];
+  CHAR Buffer[80];
   PCONFIGURATION_COMPONENT_DATA ControllerKey;
   PUSHORT BasePtr;
   ULONG Base;
@@ -1301,7 +1475,7 @@ DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
   ULONG i;
   ULONG Size;
 
-  DbgPrint((DPRINT_HWDETECT, "DetectParallelPorts() called\n"));
+  DPRINTM(DPRINT_HWDETECT, "DetectParallelPorts() called\n");
 
   ControllerNumber = 0;
   BasePtr = (PUSHORT)0x408;
@@ -1311,48 +1485,35 @@ DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
       if (Base == 0)
         continue;
 
-      DbgPrint((DPRINT_HWDETECT,
+      DPRINTM(DPRINT_HWDETECT,
                "Parallel port %u: %x\n",
                ControllerNumber,
-               Base));
-
-      /* Create controller key */
-      FldrCreateComponentKey(BusKey,
-                             L"ParallelController",
-                             ControllerNumber,
-                             ControllerClass,
-                             ParallelController,
-                             &ControllerKey);
+               Base);
 
-      /* Set 'ComponentInformation' value */
-      FldrSetComponentInformation(ControllerKey,
-                                  Output,
-                                  ControllerNumber,
-                                  0xFFFFFFFF);
+      /* Set 'Identifier' value */
+      sprintf(Buffer, "PARALLEL%ld", i + 1);
 
       /* Build full device descriptor */
-      Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR);
+      Size = sizeof(CM_PARTIAL_RESOURCE_LIST);
       if (Irq[i] != (ULONG)-1)
        Size += sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
 
-      FullResourceDescriptor = MmAllocateMemory(Size);
-      if (FullResourceDescriptor == NULL)
+      PartialResourceList = MmHeapAlloc(Size);
+      if (PartialResourceList == NULL)
        {
-         DbgPrint((DPRINT_HWDETECT,
-                   "Failed to allocate resource descriptor\n"));
+         DPRINTM(DPRINT_HWDETECT,
+                   "Failed to allocate resource descriptor\n");
          continue;
        }
-      memset(FullResourceDescriptor, 0, Size);
+      memset(PartialResourceList, 0, Size);
 
       /* Initialize resource descriptor */
-      FullResourceDescriptor->InterfaceType = Isa;
-      FullResourceDescriptor->BusNumber = 0;
-      FullResourceDescriptor->PartialResourceList.Version = 1;
-      FullResourceDescriptor->PartialResourceList.Revision = 1;
-      FullResourceDescriptor->PartialResourceList.Count = (Irq[i] != (ULONG)-1) ? 2 : 1;
+      PartialResourceList->Version = 1;
+      PartialResourceList->Revision = 1;
+      PartialResourceList->Count = (Irq[i] != (ULONG)-1) ? 2 : 1;
 
       /* Set IO Port */
-      PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[0];
+      PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
       PartialDescriptor->Type = CmResourceTypePort;
       PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
       PartialDescriptor->Flags = CM_RESOURCE_PORT_IO;
@@ -1363,7 +1524,7 @@ DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
       /* Set Interrupt */
       if (Irq[i] != (ULONG)-1)
        {
-         PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[1];
+         PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
          PartialDescriptor->Type = CmResourceTypeInterrupt;
          PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
          PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
@@ -1372,21 +1533,24 @@ DetectParallelPorts(PCONFIGURATION_COMPONENT_DATA BusKey)
          PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
        }
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(ControllerKey, FullResourceDescriptor, Size);
-      MmFreeMemory(FullResourceDescriptor);
+      /* Create controller key */
+      FldrCreateComponentKey(BusKey,
+                             ControllerClass,
+                             ParallelController,
+                             Output,
+                             ControllerNumber,
+                             0xFFFFFFFF,
+                             Buffer,
+                             PartialResourceList,
+                             Size,
+                             &ControllerKey);
 
-      /* Set 'Identifier' value */
-      swprintf(Buffer, L"PARALLEL%u", i + 1);
-      FldrSetIdentifier(ControllerKey, Buffer);
-      DbgPrint((DPRINT_HWDETECT,
-               "Created value: Identifier %s\n",
-               Buffer));
+      MmHeapFree(PartialResourceList);
 
       ControllerNumber++;
     }
 
-  DbgPrint((DPRINT_HWDETECT, "DetectParallelPorts() done\n"));
+  DPRINTM(DPRINT_HWDETECT, "DetectParallelPorts() done\n");
 }
 
 
@@ -1464,7 +1628,7 @@ DetectKeyboardDevice(VOID)
 static VOID
 DetectKeyboardPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
   PCM_KEYBOARD_DEVICE_DATA KeyboardData;
   PCONFIGURATION_COMPONENT_DATA PeripheralKey;
@@ -1473,41 +1637,24 @@ 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);
-    DbgPrint((DPRINT_HWDETECT, "Created key: KeyboardPeripheral\\0\n"));
-
-    /* Set 'ComponentInformation' value */
-    FldrSetComponentInformation(PeripheralKey,
-                                Input | ConsoleIn,
-                                0,
-                                0xFFFFFFFF);
-
     /* Set 'Configuration Data' value */
-    Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) +
+    Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
           sizeof(CM_KEYBOARD_DEVICE_DATA);
-    FullResourceDescriptor = MmAllocateMemory(Size);
-    if (FullResourceDescriptor == NULL)
+    PartialResourceList = MmHeapAlloc(Size);
+    if (PartialResourceList == NULL)
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "Failed to allocate resource descriptor\n"));
+      DPRINTM(DPRINT_HWDETECT,
+               "Failed to allocate resource descriptor\n");
       return;
     }
 
     /* Initialize resource descriptor */
-    memset(FullResourceDescriptor, 0, Size);
-    FullResourceDescriptor->InterfaceType = Isa;
-    FullResourceDescriptor->BusNumber = 0;
-    FullResourceDescriptor->PartialResourceList.Version = 1;
-    FullResourceDescriptor->PartialResourceList.Revision = 1;
-    FullResourceDescriptor->PartialResourceList.Count = 1;
-
-    PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[0];
+    memset(PartialResourceList, 0, Size);
+    PartialResourceList->Version = 1;
+    PartialResourceList->Revision = 1;
+    PartialResourceList->Count = 1;
+
+    PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
     PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
     PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
     PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(CM_KEYBOARD_DEVICE_DATA);
@@ -1519,12 +1666,20 @@ DetectKeyboardPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
     KeyboardData->Subtype = 0;
     KeyboardData->KeyboardFlags = 0x20;
 
-    /* Set 'Configuration Data' value */
-    FldrSetConfigurationData(PeripheralKey, FullResourceDescriptor, Size);
-    MmFreeMemory(FullResourceDescriptor);
-
-    /* Set 'Identifier' value */
-    FldrSetIdentifier(PeripheralKey, L"PCAT_ENHANCED");
+        /* Create controller key */
+        FldrCreateComponentKey(ControllerKey,
+                               PeripheralClass,
+                               KeyboardPeripheral,
+                               Input | ConsoleIn,
+                               0x0,
+                               0xFFFFFFFF,
+                               "PCAT_ENHANCED",
+                               PartialResourceList,
+                               Size,
+                               &PeripheralKey);
+        DPRINTM(DPRINT_HWDETECT, "Created key: KeyboardPeripheral\\0\n");
+
+    MmHeapFree(PartialResourceList);
   }
 }
 
@@ -1532,47 +1687,30 @@ DetectKeyboardPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey)
 static VOID
 DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
   PCONFIGURATION_COMPONENT_DATA ControllerKey;
   ULONG Size;
 
-  /* Create controller key */
-  FldrCreateComponentKey(BusKey,
-                         L"KeyboardController",
-                         0,
-                         ControllerClass,
-                         KeyboardController,
-                         &ControllerKey);
-  DbgPrint((DPRINT_HWDETECT, "Created key: KeyboardController\\0\n"));
-
-  /* Set 'ComponentInformation' value */
-  FldrSetComponentInformation(ControllerKey,
-                              Input | ConsoleIn,
-                              0,
-                              0xFFFFFFFF);
-
   /* Set 'Configuration Data' value */
-  Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) +
+  Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
          2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
-  FullResourceDescriptor = MmAllocateMemory(Size);
-  if (FullResourceDescriptor == NULL)
+  PartialResourceList = MmHeapAlloc(Size);
+  if (PartialResourceList == NULL)
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "Failed to allocate resource descriptor\n"));
+      DPRINTM(DPRINT_HWDETECT,
+               "Failed to allocate resource descriptor\n");
       return;
     }
 
   /* Initialize resource descriptor */
-  memset(FullResourceDescriptor, 0, Size);
-  FullResourceDescriptor->InterfaceType = Isa;
-  FullResourceDescriptor->BusNumber = 0;
-  FullResourceDescriptor->PartialResourceList.Version = 1;
-  FullResourceDescriptor->PartialResourceList.Revision = 1;
-  FullResourceDescriptor->PartialResourceList.Count = 3;
+  memset(PartialResourceList, 0, Size);
+  PartialResourceList->Version = 1;
+  PartialResourceList->Revision = 1;
+  PartialResourceList->Count = 3;
 
   /* Set Interrupt */
-  PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[0];
+  PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
   PartialDescriptor->Type = CmResourceTypeInterrupt;
   PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
   PartialDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
@@ -1581,7 +1719,7 @@ DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey)
   PartialDescriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
 
   /* Set IO Port 0x60 */
-  PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[1];
+  PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
   PartialDescriptor->Type = CmResourceTypePort;
   PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
   PartialDescriptor->Flags = CM_RESOURCE_PORT_IO;
@@ -1590,7 +1728,7 @@ DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey)
   PartialDescriptor->u.Port.Length = 1;
 
   /* Set IO Port 0x64 */
-  PartialDescriptor = &FullResourceDescriptor->PartialResourceList.PartialDescriptors[2];
+  PartialDescriptor = &PartialResourceList->PartialDescriptors[2];
   PartialDescriptor->Type = CmResourceTypePort;
   PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
   PartialDescriptor->Flags = CM_RESOURCE_PORT_IO;
@@ -1598,9 +1736,20 @@ DetectKeyboardController(PCONFIGURATION_COMPONENT_DATA BusKey)
   PartialDescriptor->u.Port.Start.HighPart = 0x0;
   PartialDescriptor->u.Port.Length = 1;
 
-  /* Set 'Configuration Data' value */
-  FldrSetConfigurationData(ControllerKey, FullResourceDescriptor, Size);
-  MmFreeMemory(FullResourceDescriptor);
+    /* 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);
 }
@@ -1718,86 +1867,65 @@ DetectPS2AuxDevice(VOID)
 static VOID
 DetectPS2Mouse(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
-  CM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  CM_PARTIAL_RESOURCE_LIST PartialResourceList;
   PCONFIGURATION_COMPONENT_DATA ControllerKey;
   PCONFIGURATION_COMPONENT_DATA PeripheralKey;
 
   if (DetectPS2AuxPort())
     {
-      DbgPrint((DPRINT_HWDETECT, "Detected PS2 port\n"));
-
-      /* Create controller key */
-      FldrCreateComponentKey(BusKey,
-                             L"PointerController",
-                             0,
-                             ControllerClass,
-                             PointerController,
-                             &ControllerKey);
-      DbgPrint((DPRINT_HWDETECT, "Created key: PointerController\\0\n"));
+      DPRINTM(DPRINT_HWDETECT, "Detected PS2 port\n");
 
-      /* Set 'ComponentInformation' value */
-      FldrSetComponentInformation(ControllerKey,
-                                  Input,
-                                  0,
-                                  0xFFFFFFFF);
-
-      memset(&FullResourceDescriptor, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR));
+      memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST));
 
       /* Initialize resource descriptor */
-      FullResourceDescriptor.InterfaceType = Isa;
-      FullResourceDescriptor.BusNumber = 0;
-      FullResourceDescriptor.PartialResourceList.Version = 1;
-      FullResourceDescriptor.PartialResourceList.Revision = 1;
-      FullResourceDescriptor.PartialResourceList.Count = 1;
+      PartialResourceList.Version = 1;
+      PartialResourceList.Revision = 1;
+      PartialResourceList.Count = 1;
 
       /* Set Interrupt */
-      FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeInterrupt;
-      FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareUndetermined;
-      FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_INTERRUPT_LATCHED;
-      FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].u.Interrupt.Level = 12;
-      FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].u.Interrupt.Vector = 0;
-      FullResourceDescriptor.PartialResourceList.PartialDescriptors[0].u.Interrupt.Affinity = 0xFFFFFFFF;
+      PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeInterrupt;
+      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.Affinity = 0xFFFFFFFF;
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(ControllerKey,
-                               &FullResourceDescriptor,
-                               sizeof(CM_FULL_RESOURCE_DESCRIPTOR));
+      /* 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())
        {
-         DbgPrint((DPRINT_HWDETECT, "Detected PS2 mouse\n"));
+         DPRINTM(DPRINT_HWDETECT, "Detected PS2 mouse\n");
+
+         /* Initialize resource descriptor */
+         memset(&PartialResourceList, 0, sizeof(CM_PARTIAL_RESOURCE_LIST));
+         PartialResourceList.Version = 1;
+         PartialResourceList.Revision = 1;
+         PartialResourceList.Count = 0;
 
           /* Create peripheral key */
           FldrCreateComponentKey(ControllerKey,
-                                 L"PointerPeripheral",
-                                 0,
                                  ControllerClass,
                                  PointerPeripheral,
+                                 Input,
+                                 0x0,
+                                 0xFFFFFFFF,
+                                 "MICROSOFT PS2 MOUSE",
+                                 &PartialResourceList,
+                                 sizeof(CM_PARTIAL_RESOURCE_LIST) -
+                                   sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR),
                                  &PeripheralKey);
-         DbgPrint((DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n"));
-
-         /* Set 'ComponentInformation' value */
-         FldrSetComponentInformation(PeripheralKey,
-                                  Input,
-                                  0,
-                                  0xFFFFFFFF);
-
-         /* Initialize resource descriptor */
-         memset(&FullResourceDescriptor, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR));
-         FullResourceDescriptor.InterfaceType = Isa;
-         FullResourceDescriptor.BusNumber = 0;
-         FullResourceDescriptor.PartialResourceList.Version = 1;
-         FullResourceDescriptor.PartialResourceList.Revision = 1;
-         FullResourceDescriptor.PartialResourceList.Count = 0;
-
-         /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(PeripheralKey,
-                               &FullResourceDescriptor,
-                               sizeof(CM_FULL_RESOURCE_DESCRIPTOR) -
-                               sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
-
-         /* Set 'Identifier' value */
-      FldrSetIdentifier(PeripheralKey, L"MICROSOFT PS2 MOUSE");
+          DPRINTM(DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n");
     }
   }
 }
@@ -1806,53 +1934,48 @@ DetectPS2Mouse(PCONFIGURATION_COMPONENT_DATA BusKey)
 static VOID
 DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
 {
-  WCHAR Buffer[80];
+  CHAR Buffer[80];
   PCONFIGURATION_COMPONENT_DATA ControllerKey;
   USHORT VesaVersion;
 
-  FldrCreateComponentKey(BusKey,
-                         L"DisplayController",
-                         0,
-                         ControllerClass,
-                         DisplayController,
-                         &ControllerKey);
-  DbgPrint((DPRINT_HWDETECT, "Created key: DisplayController\\0\n"));
-
-  /* Set 'ComponentInformation' value */
-  FldrSetComponentInformation(ControllerKey,
-                              0x00,
-                              0,
-                              0xFFFFFFFF);
-
   /* FIXME: Set 'ComponentInformation' value */
 
   VesaVersion = BiosIsVesaSupported();
   if (VesaVersion != 0)
     {
-      DbgPrint((DPRINT_HWDETECT,
+      DPRINTM(DPRINT_HWDETECT,
                "VESA version %c.%c\n",
                (VesaVersion >> 8) + '0',
-               (VesaVersion & 0xFF) + '0'));
+               (VesaVersion & 0xFF) + '0');
     }
   else
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "VESA not supported\n"));
+      DPRINTM(DPRINT_HWDETECT,
+               "VESA not supported\n");
     }
 
   if (VesaVersion >= 0x0200)
     {
-      wcscpy(Buffer,
-             L"VBE Display");
+      strcpy(Buffer,
+             "VBE Display");
     }
   else
     {
-      wcscpy(Buffer,
-             L"VGA Display");
+      strcpy(Buffer,
+             "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 */
 }
@@ -1861,55 +1984,48 @@ DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey)
 static VOID
 DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 {
-  PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor;
+  PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
   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, L"ISA");
-
   /* Set 'Configuration Data' value */
-  Size = sizeof(CM_FULL_RESOURCE_DESCRIPTOR) -
+  Size = sizeof(CM_PARTIAL_RESOURCE_LIST) -
         sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
-  FullResourceDescriptor = MmAllocateMemory(Size);
-  if (FullResourceDescriptor == NULL)
+  PartialResourceList = MmHeapAlloc(Size);
+  if (PartialResourceList == NULL)
     {
-      DbgPrint((DPRINT_HWDETECT,
-               "Failed to allocate resource descriptor\n"));
+      DPRINTM(DPRINT_HWDETECT,
+               "Failed to allocate resource descriptor\n");
       return;
     }
 
   /* Initialize resource descriptor */
-  memset(FullResourceDescriptor, 0, Size);
-  FullResourceDescriptor->InterfaceType = Isa;
-  FullResourceDescriptor->BusNumber = 0;
-  FullResourceDescriptor->PartialResourceList.Version = 1;
-  FullResourceDescriptor->PartialResourceList.Revision = 1;
-  FullResourceDescriptor->PartialResourceList.Count = 0;
+  memset(PartialResourceList, 0, Size);
+  PartialResourceList->Version = 1;
+  PartialResourceList->Revision = 1;
+  PartialResourceList->Count = 0;
 
-  /* Set 'Configuration Data' value */
-  FldrSetConfigurationData(BusKey, FullResourceDescriptor, Size);
-  MmFreeMemory(FullResourceDescriptor);
+    /* 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);
 
@@ -1925,22 +2041,16 @@ DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 }
 
 
-VOID
+PCONFIGURATION_COMPONENT_DATA
 PcHwDetect(VOID)
 {
   PCONFIGURATION_COMPONENT_DATA SystemKey;
   ULONG BusNumber = 0;
 
-  DbgPrint((DPRINT_HWDETECT, "DetectHardware()\n"));
+  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);
@@ -1949,7 +2059,9 @@ PcHwDetect(VOID)
   DetectIsaBios(SystemKey, &BusNumber);
   DetectAcpiBios(SystemKey, &BusNumber);
   
-  DbgPrint((DPRINT_HWDETECT, "DetectHardware() Done\n"));
+  DPRINTM(DPRINT_HWDETECT, "DetectHardware() Done\n");
+
+  return SystemKey;
 }
 
 /* EOF */