[ros-diffs] [ros-arm-bringup] 32173: There was no reason to have most of the i386Disk routines as i386-only routines, since they are quite generic and portable assuming MBR-based disks. GPT disks are another matter, but in either case, any architecture should support both, and that's the real distinction. Made the ARM code use the shared disk routines, which allowed us to remove some hacks -> we now detect the boot/system volume just like on x86. FreeLDR now loads NTOSKRNL.EXE on ARM. Also made the DiskIsBootDeviceFloppy return FALSE for ramdisks. Finally, note that the disk routines were still kept as Machine-specific routines in the Mach Table, so other architectures can still override them if they really need to (for example, the XBOX port overrides one of them for a specific XBOX hack).

ros-arm-bringup at svn.reactos.org ros-arm-bringup at svn.reactos.org
Thu Feb 7 01:43:12 CET 2008


Author: ros-arm-bringup
Date: Thu Feb  7 03:43:09 2008
New Revision: 32173

URL: http://svn.reactos.org/svn/reactos?rev=32173&view=rev
Log:
There was no reason to have most of the i386Disk routines as i386-only routines, since they are quite generic and portable assuming MBR-based disks. GPT disks are another matter, but in either case, any architecture should support both, and that's the real distinction.
Made the ARM code use the shared disk routines, which allowed us to remove some hacks -> we now detect the boot/system volume just like on x86.
FreeLDR now loads NTOSKRNL.EXE on ARM.
Also made the DiskIsBootDeviceFloppy return FALSE for ramdisks.
Finally, note that the disk routines were still kept as Machine-specific routines in the Mach Table, so other architectures can still override them if they really need to (for example, the XBOX port overrides one of them for a specific XBOX hack).


Modified:
    trunk/reactos/boot/freeldr/freeldr/arch/arm/stubs.c
    trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S
    trunk/reactos/boot/freeldr/freeldr/arch/i386/boot.S
    trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c
    trunk/reactos/boot/freeldr/freeldr/arch/i386/linux.S
    trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c
    trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c
    trunk/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c
    trunk/reactos/boot/freeldr/freeldr/disk/disk.c
    trunk/reactos/boot/freeldr/freeldr/disk/ramdisk.c
    trunk/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h
    trunk/reactos/boot/freeldr/freeldr/include/disk.h

Modified: trunk/reactos/boot/freeldr/freeldr/arch/arm/stubs.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/arm/stubs.c?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/arm/stubs.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/arm/stubs.c Thu Feb  7 03:43:09 2008
@@ -24,7 +24,6 @@
     //
 }
 
-
 BOOLEAN
 ArmDiskGetDriveGeometry(IN ULONG DriveNumber,
                         OUT PGEOMETRY Geometry)
@@ -50,58 +49,6 @@
     return FALSE;
 }
 
-BOOLEAN
-ArmDiskGetBootVolume(IN PULONG DriveNumber,
-                     IN PULONGLONG StartSector,
-                     IN PULONGLONG SectorCount, 
-                     OUT PINT FsType)
-{
-    //
-    // We only support RAM disk for now -- add support for NAND later
-    //
-    ASSERT(gRamDiskBase);
-    ASSERT(gRamDiskSize);
-
-    //
-    // Use magic ramdisk drive number and count the number of 512-byte sectors
-    //
-    *DriveNumber = 0x49;
-    *StartSector = 63;
-    *SectorCount = gRamDiskSize * 512;
-
-    //
-    // Ramdisk support is FAT-only for now
-    //
-    *FsType = FS_FAT;
-
-    //
-    // Now that ramdisk is enabled, use ramdisk routines
-    //
-    RamDiskSwitchFromBios();
-    return TRUE;
-}
-
-BOOLEAN
-ArmDiskGetSystemVolume(IN PCHAR SystemPath,
-                       OUT PCHAR RemainingPath,
-                       OUT PULONG Device,
-                       OUT PULONG DriveNumber,
-                       OUT PULONGLONG StartSector,
-                       OUT PULONGLONG SectorCount,
-                       OUT PINT FsType)
-{
-    while (TRUE);
-    return FALSE;
-}
-
-BOOLEAN
-ArmDiskNormalizeSystemPath(IN PCHAR SystemPath,
-                           IN unsigned Size)
-{
-    while (TRUE);
-    return FALSE;
-}
-
 VOID
 ArmPrepareForReactOS(IN BOOLEAN Setup)
 {
@@ -111,8 +58,32 @@
 PCONFIGURATION_COMPONENT_DATA
 ArmHwDetect(VOID)
 {
-    while (TRUE);
-    return NULL;
+    PCONFIGURATION_COMPONENT_DATA RootNode;
+    
+    //
+    // Create the root node
+    //
+    FldrCreateSystemKey(&RootNode);
+    
+    //
+    // Write null component information
+    //
+    FldrSetComponentInformation(RootNode,
+                                0x0,
+                                0x0,
+                                0xFFFFFFFF);
+    
+    //
+    // TODO:
+    // There's no such thing as "PnP" on embedded hardware.
+    // The boot loader will send us a device tree, similar to ACPI
+    // or OpenFirmware device trees, and we will convert it to ARC.
+    //
+
+    //
+    // Return the root node
+    //
+    return RootNode;
 }
 
 ULONG
@@ -155,18 +126,31 @@
     }
     
     //
-    // Setup generic ARM routines
+    // Setup generic ARM routines for all boards
     //
     MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
     MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
-    MachVtbl.DiskGetBootVolume = ArmDiskGetBootVolume;
-    MachVtbl.DiskGetSystemVolume = ArmDiskGetSystemVolume;
-    MachVtbl.DiskNormalizeSystemPath = ArmDiskNormalizeSystemPath;
+    MachVtbl.HwDetect = ArmHwDetect;
+
+    //
+    // Setup disk I/O routines, switch to ramdisk ones for non-NAND boot
+    //
     MachVtbl.DiskReadLogicalSectors = ArmDiskReadLogicalSectors;
     MachVtbl.DiskGetDriveGeometry = ArmDiskGetDriveGeometry;
     MachVtbl.DiskGetCacheableBlockCount = ArmDiskGetCacheableBlockCount;
-    MachVtbl.HwDetect = ArmHwDetect;
-    
+    RamDiskSwitchFromBios();
+
+    //
+    // Now set default disk handling routines -- we don't need to override
+    //
+    MachVtbl.DiskGetBootVolume = DiskGetBootVolume;
+    MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume;
+    MachVtbl.DiskGetBootPath = DiskGetBootPath;
+    MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
+    MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy;
+    MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
+    MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry;
+
     //
     // We can now print to the console
     //

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/arch.S Thu Feb  7 03:43:09 2008
@@ -46,16 +46,16 @@
 
 	.code32
 
-	/* Zero i386BootDrive and i386BootPartition */
+	/* Zero BootDrive and BootPartition */
 	xorl	%eax,%eax
-	movl	%eax,(_i386BootDrive)
-	movl	%eax,(_i386BootPartition)
+	movl	%eax,(_BootDrive)
+	movl	%eax,(_BootPartition)
 
 	/* Store the boot drive */
-	movb	%dl,(_i386BootDrive)
+	movb	%dl,(_BootDrive)
 
 	/* Store the boot partition */
-	movb	%dh,(_i386BootPartition)
+	movb	%dh,(_BootPartition)
 
 	/* GO! */
 	pushl	%eax
@@ -395,12 +395,12 @@
 	movl	MB_INFO_BOOT_DEVICE_OFFSET(%ebx),%eax
 	shrl	$16,%eax
 	incb	%al
-	movb	%al,_i386BootPartition
-	movb	%ah,_i386BootDrive
+	movb	%al,_BootPartition
+	movb	%ah,_BootDrive
 	jmp	mb6
 mb5:	/* No boot device known, assume first partition of first harddisk */
-	movb	$0x80,_i386BootDrive
-	movb	$1,_i386BootPartition
+	movb	$0x80,_BootDrive
+	movb	$1,_BootPartition
 mb6:
 	/* Check for command line */
 	mov	$cmdline,%eax
@@ -484,14 +484,14 @@
 	.word	0x3ff		/* Limit */
 	.long	0			/* Base Address */
 
-EXTERN(_i386BootDrive)
-	.long	0
-
-EXTERN(_i386BootPartition)
-	.long	0
-
 mb_info:
 	.fill	MB_INFO_SIZE, 1, 0
 
 cmdline:
 	.fill	CMDLINE_SIZE, 1, 0
+
+EXTERN(_BootDrive)
+    .long 0
+    
+EXTERN(_BootPartition)
+    .long 0

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/boot.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/boot.S?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/boot.S (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/boot.S Thu Feb  7 03:43:09 2008
@@ -31,7 +31,7 @@
 	.code16
 
 	/* Set the boot drive */
-	movb	(_i386BootDrive),%dl
+	movb	(_BootDrive),%dl
 
 	/* Load segment registers */
 	cli

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/i386disk.c Thu Feb  7 03:43:09 2008
@@ -198,309 +198,6 @@
 	return TRUE;
 }
 
-BOOLEAN i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
-{
-	PARTITION_TABLE_ENTRY	PartitionTableEntry;
-	UCHAR			VolumeType;
-	ULONG			ActivePartition;
-
-	DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", i386BootDrive, i386BootPartition));
-
-	// Check and see if it is a floppy drive
-	// If so then just assume FAT12 file system type
-	if (DiskIsDriveRemovable(i386BootDrive))
-	{
-		DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
-
-		*DriveNumber = i386BootDrive;
-		*StartSector = 0;
-		*SectorCount = 2 * 80 * 18; /* FIXME hardcoded for 1.44 Mb */
-		*FsType = FS_FAT;
-		return TRUE;
-	}
-
-	// Check for ISO9660 file system type
-	if (i386BootDrive >= 0x80 && FsRecIsIso9660(i386BootDrive))
-	{
-		DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
-
-		*DriveNumber = i386BootDrive;
-		*StartSector = 0;
-		*SectorCount = 0;
-		*FsType = FS_ISO9660;
-		return TRUE;
-	}
-
-	// Get the requested partition entry
-	if (i386BootPartition == 0)
-	{
-		// Partition requested was zero which means the boot partition
-		if (! DiskGetActivePartitionEntry(i386BootDrive, &PartitionTableEntry, &ActivePartition))
-		{
-			/* Try partition-less disk */
-			*StartSector = 0;
-			*SectorCount = 0;
-		}
-		/* Check for valid partition */
-		else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
-		{
-			return FALSE;
-		}
-		else
-		{
-			*StartSector = PartitionTableEntry.SectorCountBeforePartition;
-			*SectorCount = PartitionTableEntry.PartitionSectorCount;
-		}
-	}
-	else if (0xff == i386BootPartition)
-	{
-		/* Partition-less disk */
-		*StartSector = 0;
-		*SectorCount = 0;
-	}
-	else
-	{
-		// Get requested partition
-		if (! MachDiskGetPartitionEntry(i386BootDrive, i386BootPartition, &PartitionTableEntry))
-		{
-			return FALSE;
-		}
-		/* Check for valid partition */
-		else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
-		{
-			return FALSE;
-		}
-		else
-		{
-			*StartSector = PartitionTableEntry.SectorCountBeforePartition;
-			*SectorCount = PartitionTableEntry.PartitionSectorCount;
-		}
-	}
-
-	// Try to recognize the file system
-	if (!FsRecognizeVolume(i386BootDrive, *StartSector, &VolumeType))
-	{
-		return FALSE;
-	}
-
-	*DriveNumber = i386BootDrive;
-
-	switch (VolumeType)
-	{
-	case PARTITION_FAT_12:
-	case PARTITION_FAT_16:
-	case PARTITION_HUGE:
-	case PARTITION_XINT13:
-	case PARTITION_FAT32:
-	case PARTITION_FAT32_XINT13:
-		*FsType = FS_FAT;
-		return TRUE;
-	case PARTITION_EXT2:
-		*FsType = FS_EXT2;
-		return TRUE;
-	case PARTITION_NTFS:
-		*FsType = FS_NTFS;
-		return TRUE;
-	default:
-		*FsType = 0;
-		return FALSE;
-	}
-
-	return TRUE;
-}
-
-VOID
-i386DiskGetBootDevice(PULONG BootDevice)
-{
-  ((char *)BootDevice)[0] = (char)i386BootDrive;
-  ((char *)BootDevice)[1] = (char)i386BootPartition;
-}
-
-BOOLEAN
-i386DiskBootingFromFloppy(VOID)
-{
-  return i386BootDrive < 0x80;
-}
-
-#define IsRecognizedPartition(P)  \
-    ((P) == PARTITION_FAT_12       || \
-     (P) == PARTITION_FAT_16       || \
-     (P) == PARTITION_HUGE         || \
-     (P) == PARTITION_IFS          || \
-     (P) == PARTITION_EXT2         || \
-     (P) == PARTITION_FAT32        || \
-     (P) == PARTITION_FAT32_XINT13 || \
-     (P) == PARTITION_XINT13)
-
-#define IsContainerPartition(P) \
-    ((P) == PARTITION_EXTENDED         || \
-     (P) == PARTITION_XINT13_EXTENDED)
-
-BOOLEAN i386DiskGetSystemVolume(char *SystemPath,
-                             char *RemainingPath,
-                             PULONG Device,
-                             PULONG DriveNumber,
-                             PULONGLONG StartSector,
-                             PULONGLONG SectorCount,
-                             int *FsType)
-{
-	ULONG PartitionNumber;
-	PARTITION_TABLE_ENTRY PartitionTableEntry;
-	UCHAR VolumeType;
-	CHAR BootPath[256];
-	unsigned i, RosPartition;
-
-	/*
-	 * Verify system path
-	 */
-	if (!DissectArcPath(SystemPath, BootPath, DriveNumber, &PartitionNumber))
-	{
-		return FALSE;
-	}
-	if (NULL != RemainingPath)
-	{
-		strcpy(RemainingPath, BootPath);
-	}
-
-	/* 0xff -> no partition table present, use whole device */
-	if (0xff == PartitionNumber)
-	{
-		PartitionTableEntry.SectorCountBeforePartition = 0;
-		i = 0xff;
-	}
-	else
-	{
-		/* recalculate the boot partition for freeldr */
-		i = 0;
-		RosPartition = 0;
-		while (1)
-		{
-			if (!MachDiskGetPartitionEntry(*DriveNumber, ++i, &PartitionTableEntry))
-			{
-				return FALSE;
-			}
-                        if (!IsContainerPartition(PartitionTableEntry.SystemIndicator) &&
-                            PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
-			{
-				if (++RosPartition == PartitionNumber)
-				{
-					break;
-				}
-			}
-		}
-	}
-
-	/* Check for ISO9660 file system type */
-	if (*DriveNumber >= 0x80 && FsRecIsIso9660(*DriveNumber))
-	{
-		DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
-
-		if (NULL != Device)
-		{
-			((char *)Device)[0] = (char)(*DriveNumber);
-			((char *)Device)[1] = (char)i;
-		}
-		*StartSector = 0;
-		*SectorCount = 0;
-		*FsType = FS_ISO9660;
-		return TRUE;
-	}
-
-	if (!FsRecognizeVolume(*DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
-	{
-		return FALSE;
-	}
-
-	if (NULL != Device)
-	{
-		((char *)Device)[0] = (char)(*DriveNumber);
-		((char *)Device)[1] = (char)i;
-	}
-	*StartSector = PartitionTableEntry.SectorCountBeforePartition;
-	*SectorCount = PartitionTableEntry.PartitionSectorCount;
-
-	switch (VolumeType)
-	{
-	case PARTITION_FAT_12:
-	case PARTITION_FAT_16:
-	case PARTITION_HUGE:
-	case PARTITION_XINT13:
-	case PARTITION_FAT32:
-	case PARTITION_FAT32_XINT13:
-		*FsType = FS_FAT;
-		return TRUE;
-	case PARTITION_EXT2:
-		*FsType = FS_EXT2;
-		return TRUE;
-	case PARTITION_NTFS:
-		*FsType = FS_NTFS;
-		return TRUE;
-	default:
-		*FsType = 0;
-		return FALSE;
-	}
-
-	return FALSE;
-}
-
-BOOLEAN
-i386DiskGetBootPath(char *BootPath, unsigned Size)
-{
-	static char Path[] = "multi(0)disk(0)";
-	char Device[4];
-
-	_itoa(i386BootDrive, Device, 10);
-	if (Size <= sizeof(Path) + 6 + strlen(Device))
-	{
-		return FALSE;
-	}
-	strcpy(BootPath, Path);
-	strcat(BootPath, MachDiskBootingFromFloppy() ? "fdisk" : "cdrom");
-	strcat(strcat(strcat(BootPath, "("), Device), ")");
-
-	return TRUE;
-}
-
-BOOLEAN
-i386DiskNormalizeSystemPath(char *SystemPath, unsigned Size)
-{
-	CHAR BootPath[256];
-	ULONG PartitionNumber;
-	ULONG DriveNumber;
-	PARTITION_TABLE_ENTRY PartEntry;
-	char *p;
-
-	if (!DissectArcPath(SystemPath, BootPath, &DriveNumber, &PartitionNumber))
-	{
-		return FALSE;
-	}
-
-	if (0 != PartitionNumber)
-	{
-		return TRUE;
-	}
-
-	if (! DiskGetActivePartitionEntry(DriveNumber,
-	                                  &PartEntry,
-	                                  &PartitionNumber) ||
-	    PartitionNumber < 1 || 9 < PartitionNumber)
-	{
-		return FALSE;
-	}
-
-	p = SystemPath;
-	while ('\0' != *p && 0 != _strnicmp(p, "partition(", 10)) {
-		p++;
-	}
-	p = strchr(p, ')');
-	if (NULL == p || '0' != *(p - 1)) {
-		return FALSE;
-	}
-	*(p - 1) = '0' + PartitionNumber;
-
-	return TRUE;
-}
-
 #endif /* defined __i386__ */
 
 /* EOF */

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/linux.S
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/linux.S?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/linux.S (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/linux.S Thu Feb  7 03:43:09 2008
@@ -30,7 +30,7 @@
 	.code16
 
 	/* Set the boot drive */
-	movb	(_i386BootDrive),%dl
+	movb	(_BootDrive),%dl
 
 	/* Load segment registers */
 	cli
@@ -66,7 +66,7 @@
 	.code16
 
 	/* Set the boot drive */
-	movb	(_i386BootDrive),%dl
+	movb	(_BootDrive),%dl
 
 	/* Load segment registers */
 	cli

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/machpc.c Thu Feb  7 03:43:09 2008
@@ -44,14 +44,14 @@
     MachVtbl.Beep = PcBeep;
     MachVtbl.PrepareForReactOS = PcPrepareForReactOS;
     MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
-    MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume;
-    MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume;
-    MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
-    MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
-    MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
-    MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
+    MachVtbl.DiskGetBootVolume = DiskGetBootVolume;
+    MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume;
+    MachVtbl.DiskGetBootPath = DiskGetBootPath;
+    MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
+    MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy;
+    MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
     MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
-    MachVtbl.DiskGetPartitionEntry = PcDiskGetPartitionEntry;
+    MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry;
     MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
     MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount;
     MachVtbl.RTCGetCurrentDateTime = PcRTCGetCurrentDateTime;

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c Thu Feb  7 03:43:09 2008
@@ -47,12 +47,12 @@
   MachVtbl.Beep = PcBeep;
   MachVtbl.PrepareForReactOS = XboxPrepareForReactOS;
   MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
-  MachVtbl.DiskGetBootVolume = i386DiskGetBootVolume;
-  MachVtbl.DiskGetSystemVolume = i386DiskGetSystemVolume;
-  MachVtbl.DiskGetBootPath = i386DiskGetBootPath;
-  MachVtbl.DiskGetBootDevice = i386DiskGetBootDevice;
-  MachVtbl.DiskBootingFromFloppy = i386DiskBootingFromFloppy;
-  MachVtbl.DiskNormalizeSystemPath = i386DiskNormalizeSystemPath;
+  MachVtbl.DiskGetBootVolume = DiskGetBootVolume;
+  MachVtbl.DiskGetSystemVolume = DiskGetSystemVolume;
+  MachVtbl.DiskGetBootPath = DiskGetBootPath;
+  MachVtbl.DiskGetBootDevice = DiskGetBootDevice;
+  MachVtbl.DiskBootingFromFloppy = DiskBootingFromFloppy;
+  MachVtbl.DiskNormalizeSystemPath = DiskNormalizeSystemPath;
   MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
   MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry;
   MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/pcdisk.c Thu Feb  7 03:43:09 2008
@@ -379,13 +379,6 @@
 }
 
 BOOLEAN
-PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry)
-{
-  /* Just use the standard routine */
-  return DiskGetPartitionEntry(DriveNumber, PartitionNumber, PartitionTableEntry);
-}
-
-BOOLEAN
 PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY Geometry)
 {
   REGS RegsIn;

Modified: trunk/reactos/boot/freeldr/freeldr/disk/disk.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/disk.c?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/disk/disk.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/disk/disk.c Thu Feb  7 03:43:09 2008
@@ -91,7 +91,8 @@
 	// Hard disks use drive numbers >= 0x80
 	// So if the drive number indicates a hard disk
 	// then return FALSE
-	if (DriveNumber >= 0x80)
+    // 0x49 is our magic ramdisk drive, so return FALSE for that too
+	if ((DriveNumber >= 0x80) || (DriveNumber == 0x49))
 	{
 		return FALSE;
 	}
@@ -100,6 +101,310 @@
 	return TRUE;
 }
 
+BOOLEAN DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector, PULONGLONG SectorCount, int *FsType)
+{
+	PARTITION_TABLE_ENTRY	PartitionTableEntry;
+	UCHAR			VolumeType;
+	ULONG			ActivePartition;
+    
+	DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", BootDrive, BootPartition));
+    
+	// Check and see if it is a floppy drive
+	// If so then just assume FAT12 file system type
+	if (DiskIsDriveRemovable(BootDrive))
+	{
+		DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
+        
+		*DriveNumber = BootDrive;
+		*StartSector = 0;
+		*SectorCount = 2 * 80 * 18; /* FIXME hardcoded for 1.44 Mb */
+		*FsType = FS_FAT;
+		return TRUE;
+	}
+    
+	// Check for ISO9660 file system type
+	if (BootDrive >= 0x80 && FsRecIsIso9660(BootDrive))
+	{
+		DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
+        
+		*DriveNumber = BootDrive;
+		*StartSector = 0;
+		*SectorCount = 0;
+		*FsType = FS_ISO9660;
+		return TRUE;
+	}
+    
+	// Get the requested partition entry
+	if (BootPartition == 0)
+	{
+		// Partition requested was zero which means the boot partition
+		if (! DiskGetActivePartitionEntry(BootDrive, &PartitionTableEntry, &ActivePartition))
+		{
+			/* Try partition-less disk */
+			*StartSector = 0;
+			*SectorCount = 0;
+		}
+		/* Check for valid partition */
+		else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
+		{
+			return FALSE;
+		}
+		else
+		{
+			*StartSector = PartitionTableEntry.SectorCountBeforePartition;
+			*SectorCount = PartitionTableEntry.PartitionSectorCount;
+		}
+	}
+	else if (0xff == BootPartition)
+	{
+		/* Partition-less disk */
+		*StartSector = 0;
+		*SectorCount = 0;
+	}
+	else
+	{
+		// Get requested partition
+		if (! MachDiskGetPartitionEntry(BootDrive, BootPartition, &PartitionTableEntry))
+		{
+			return FALSE;
+		}
+		/* Check for valid partition */
+		else if (PartitionTableEntry.SystemIndicator == PARTITION_ENTRY_UNUSED)
+		{
+			return FALSE;
+		}
+		else
+		{
+			*StartSector = PartitionTableEntry.SectorCountBeforePartition;
+			*SectorCount = PartitionTableEntry.PartitionSectorCount;
+		}
+	}
+    
+	// Try to recognize the file system
+	if (!FsRecognizeVolume(BootDrive, *StartSector, &VolumeType))
+	{
+		return FALSE;
+	}
+    
+	*DriveNumber = BootDrive;
+    
+	switch (VolumeType)
+	{
+        case PARTITION_FAT_12:
+        case PARTITION_FAT_16:
+        case PARTITION_HUGE:
+        case PARTITION_XINT13:
+        case PARTITION_FAT32:
+        case PARTITION_FAT32_XINT13:
+            *FsType = FS_FAT;
+            return TRUE;
+        case PARTITION_EXT2:
+            *FsType = FS_EXT2;
+            return TRUE;
+        case PARTITION_NTFS:
+            *FsType = FS_NTFS;
+            return TRUE;
+        default:
+            *FsType = 0;
+            return FALSE;
+	}
+    
+	return TRUE;
+}
+
+VOID
+DiskGetBootDevice(PULONG BootDevice)
+{
+    ((char *)BootDevice)[0] = (char)BootDrive;
+    ((char *)BootDevice)[1] = (char)BootPartition;
+}
+
+BOOLEAN
+DiskBootingFromFloppy(VOID)
+{
+    return BootDrive < 0x80;
+}
+
+#define IsRecognizedPartition(P)  \
+    ((P) == PARTITION_FAT_12       || \
+     (P) == PARTITION_FAT_16       || \
+     (P) == PARTITION_HUGE         || \
+     (P) == PARTITION_IFS          || \
+     (P) == PARTITION_EXT2         || \
+     (P) == PARTITION_FAT32        || \
+     (P) == PARTITION_FAT32_XINT13 || \
+     (P) == PARTITION_XINT13)
+
+#define IsContainerPartition(P) \
+    ((P) == PARTITION_EXTENDED         || \
+     (P) == PARTITION_XINT13_EXTENDED)
+
+BOOLEAN DiskGetSystemVolume(char *SystemPath,
+                            char *RemainingPath,
+                            PULONG Device,
+                            PULONG DriveNumber,
+                            PULONGLONG StartSector,
+                            PULONGLONG SectorCount,
+                            int *FsType)
+{
+	ULONG PartitionNumber;
+	PARTITION_TABLE_ENTRY PartitionTableEntry;
+	UCHAR VolumeType;
+	CHAR BootPath[256];
+	unsigned i, RosPartition;
+    
+	/*
+	 * Verify system path
+	 */
+	if (!DissectArcPath(SystemPath, BootPath, DriveNumber, &PartitionNumber))
+	{
+		return FALSE;
+	}
+	if (NULL != RemainingPath)
+	{
+		strcpy(RemainingPath, BootPath);
+	}
+    
+	/* 0xff -> no partition table present, use whole device */
+	if (0xff == PartitionNumber)
+	{
+		PartitionTableEntry.SectorCountBeforePartition = 0;
+		i = 0xff;
+	}
+	else
+	{
+		/* recalculate the boot partition for freeldr */
+		i = 0;
+		RosPartition = 0;
+		while (1)
+		{
+			if (!MachDiskGetPartitionEntry(*DriveNumber, ++i, &PartitionTableEntry))
+			{
+				return FALSE;
+			}
+            if (!IsContainerPartition(PartitionTableEntry.SystemIndicator) &&
+                PartitionTableEntry.SystemIndicator != PARTITION_ENTRY_UNUSED)
+			{
+				if (++RosPartition == PartitionNumber)
+				{
+					break;
+				}
+			}
+		}
+	}
+    
+	/* Check for ISO9660 file system type */
+	if (*DriveNumber >= 0x80 && FsRecIsIso9660(*DriveNumber))
+	{
+		DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
+        
+		if (NULL != Device)
+		{
+			((char *)Device)[0] = (char)(*DriveNumber);
+			((char *)Device)[1] = (char)i;
+		}
+		*StartSector = 0;
+		*SectorCount = 0;
+		*FsType = FS_ISO9660;
+		return TRUE;
+	}
+    
+	if (!FsRecognizeVolume(*DriveNumber, PartitionTableEntry.SectorCountBeforePartition, &VolumeType))
+	{
+		return FALSE;
+	}
+    
+	if (NULL != Device)
+	{
+		((char *)Device)[0] = (char)(*DriveNumber);
+		((char *)Device)[1] = (char)i;
+	}
+	*StartSector = PartitionTableEntry.SectorCountBeforePartition;
+	*SectorCount = PartitionTableEntry.PartitionSectorCount;
+    
+	switch (VolumeType)
+	{
+        case PARTITION_FAT_12:
+        case PARTITION_FAT_16:
+        case PARTITION_HUGE:
+        case PARTITION_XINT13:
+        case PARTITION_FAT32:
+        case PARTITION_FAT32_XINT13:
+            *FsType = FS_FAT;
+            return TRUE;
+        case PARTITION_EXT2:
+            *FsType = FS_EXT2;
+            return TRUE;
+        case PARTITION_NTFS:
+            *FsType = FS_NTFS;
+            return TRUE;
+        default:
+            *FsType = 0;
+            return FALSE;
+	}
+    
+	return FALSE;
+}
+
+BOOLEAN
+DiskGetBootPath(char *BootPath, unsigned Size)
+{
+	static char Path[] = "multi(0)disk(0)";
+	char Device[4];
+    
+	_itoa(BootDrive, Device, 10);
+	if (Size <= sizeof(Path) + 6 + strlen(Device))
+	{
+		return FALSE;
+	}
+	strcpy(BootPath, Path);
+	strcat(BootPath, MachDiskBootingFromFloppy() ? "fdisk" : "cdrom");
+	strcat(strcat(strcat(BootPath, "("), Device), ")");
+    
+	return TRUE;
+}
+
+BOOLEAN
+DiskNormalizeSystemPath(char *SystemPath, unsigned Size)
+{
+	CHAR BootPath[256];
+	ULONG PartitionNumber;
+	ULONG DriveNumber;
+	PARTITION_TABLE_ENTRY PartEntry;
+	char *p;
+    
+	if (!DissectArcPath(SystemPath, BootPath, &DriveNumber, &PartitionNumber))
+	{
+		return FALSE;
+	}
+    
+	if (0 != PartitionNumber)
+	{
+		return TRUE;
+	}
+    
+	if (! DiskGetActivePartitionEntry(DriveNumber,
+	                                  &PartEntry,
+	                                  &PartitionNumber) ||
+	    PartitionNumber < 1 || 9 < PartitionNumber)
+	{
+		return FALSE;
+	}
+    
+	p = SystemPath;
+	while ('\0' != *p && 0 != _strnicmp(p, "partition(", 10)) {
+		p++;
+	}
+	p = strchr(p, ')');
+	if (NULL == p || '0' != *(p - 1)) {
+		return FALSE;
+	}
+	*(p - 1) = '0' + PartitionNumber;
+    
+	return TRUE;
+}
+
+
 // This function is in arch/i386/i386disk.c
 //VOID DiskStopFloppyMotor(VOID)
 

Modified: trunk/reactos/boot/freeldr/freeldr/disk/ramdisk.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/ramdisk.c?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/disk/ramdisk.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/disk/ramdisk.c Thu Feb  7 03:43:09 2008
@@ -38,6 +38,7 @@
     //
     // Allow 32KB transfers (64 sectors), emulating BIOS LBA
     //
+    ASSERT(Reserved == 0x49);
     return 64;
 }
 
@@ -48,6 +49,7 @@
     //
     // Should never be called when the caller expects valid Geometry!
     //
+    ASSERT(Reserved == 0x49);
     return TRUE;
 }
 
@@ -59,7 +61,8 @@
 {
     PVOID StartAddress;
     ULONG Length;
-        
+    ASSERT(Reserved == 0x49);
+
     //
     // Get actual pointers and lengths
     //
@@ -145,6 +148,8 @@
 NTAPI
 RamDiskSwitchFromBios(VOID)
 {
+    extern ULONG BootDrive, BootPartition;
+
     //
     // Check if we have a ramdisk, in which case we need to switch routines
     //
@@ -161,5 +166,11 @@
         // Also disable cached FAT reads
         //
         gCacheEnabled = FALSE;
+        
+        //
+        // Switch to ramdisk boot partition
+        //
+        BootDrive = 0x49;
+        BootPartition = 0;
     }
 }

Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/arch/i386/i386.h Thu Feb  7 03:43:09 2008
@@ -22,19 +22,6 @@
 #define __I386_I386_H_
 
 
-extern ULONG i386BootDrive;
-extern ULONG i386BootPartition;
-
-extern BOOLEAN i386DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector,
-                                  PULONGLONG SectorCount, int *FsType);
-extern BOOLEAN i386DiskGetSystemVolume(char *SystemPath, char *RemainingPath,
-                                    PULONG Device, PULONG DriveNumber,
-                                    PULONGLONG StartSector,
-                                    PULONGLONG SectorCount, int *FsType);
-extern BOOLEAN i386DiskGetBootPath(char *BootPath, unsigned Size);
-extern VOID i386DiskGetBootDevice(PULONG BootDevice);
-extern BOOLEAN i386DiskBootingFromFloppy(VOID);
-extern BOOLEAN i386DiskNormalizeSystemPath(char *SystemPath, unsigned Size);
 
 #endif /* __I386_I386_H_ */
 

Modified: trunk/reactos/boot/freeldr/freeldr/include/disk.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/include/disk.h?rev=32173&r1=32172&r2=32173&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/disk.h (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/disk.h Thu Feb  7 03:43:09 2008
@@ -124,6 +124,20 @@
 BOOLEAN	DiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); // Implemented in i386disk.c
 BOOLEAN	DiskIsDriveRemovable(ULONG DriveNumber);
 VOID	DiskStopFloppyMotor(VOID);	// Implemented in i386disk.c
+extern ULONG BootDrive;
+extern ULONG BootPartition;
+
+BOOLEAN DiskGetBootVolume(PULONG DriveNumber, PULONGLONG StartSector,
+                          PULONGLONG SectorCount, int *FsType);
+BOOLEAN DiskGetSystemVolume(char *SystemPath, char *RemainingPath,
+                            PULONG Device, PULONG DriveNumber,
+                            PULONGLONG StartSector,
+                            PULONGLONG SectorCount, int *FsType);
+BOOLEAN DiskGetBootPath(char *BootPath, unsigned Size);
+VOID DiskGetBootDevice(PULONG BootDevice);
+BOOLEAN DiskBootingFromFloppy(VOID);
+BOOLEAN DiskNormalizeSystemPath(char *SystemPath, unsigned Size);
+
 
 ///////////////////////////////////////////////////////////////////////////////////////
 //




More information about the Ros-diffs mailing list