Author: arty Date: Sat Apr 21 05:36:56 2007 New Revision: 26446
URL: http://svn.reactos.org/svn/reactos?rev=26446&view=rev Log: Adapt fat for BE booting. Add proper port io in mach.c
Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c branches/powerpc/reactos/boot/freeldr/freeldr/fs/fat.c
Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c URL: http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fre... ============================================================================== --- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c (original) +++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c Sat Apr 21 05:36:56 2007 @@ -616,10 +616,11 @@ }
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address) { - return 0xff; + return GetPhysByte(((ULONG)Address)+0x80000000); }
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value) { + SetPhysByte(((ULONG)Address)+0x80000000, Value); }
void DiskStopFloppyMotor() {
Modified: branches/powerpc/reactos/boot/freeldr/freeldr/fs/fat.c URL: http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fre... ============================================================================== --- branches/powerpc/reactos/boot/freeldr/freeldr/fs/fat.c (original) +++ branches/powerpc/reactos/boot/freeldr/freeldr/fs/fat.c Sat Apr 21 05:36:56 2007 @@ -19,7 +19,7 @@
#include <freeldr.h>
-#define NDEBUG +//#define NDEBUG #include <debug.h>
ULONG BytesPerSector; /* Number of bytes per sector */ @@ -37,6 +37,84 @@ ULONG FatType = 0; /* FAT12, FAT16, FAT32, FATX16 or FATX32 */ ULONG FatDriveNumber = 0;
+VOID FatSwapFatBootSector(PFAT_BOOTSECTOR Obj) +{ + SW(Obj, BytesPerSector); + SW(Obj, ReservedSectors); + SW(Obj, RootDirEntries); + SW(Obj, TotalSectors); + SW(Obj, SectorsPerFat); + SW(Obj, SectorsPerTrack); + SW(Obj, NumberOfHeads); + SD(Obj, HiddenSectors); + SD(Obj, TotalSectorsBig); + SD(Obj, VolumeSerialNumber); + SW(Obj, BootSectorMagic); +} + +VOID FatSwapFat32BootSector(PFAT32_BOOTSECTOR Obj) +{ + SW(Obj, BytesPerSector); + SW(Obj, ReservedSectors); + SW(Obj, RootDirEntries); + SW(Obj, TotalSectors); + SW(Obj, SectorsPerFat); + SW(Obj, NumberOfHeads); + SD(Obj, HiddenSectors); + SD(Obj, TotalSectorsBig); + SD(Obj, SectorsPerFatBig); + SW(Obj, ExtendedFlags); + SW(Obj, FileSystemVersion); + SD(Obj, RootDirStartCluster); + SW(Obj, FsInfo); + SW(Obj, BackupBootSector); + SD(Obj, VolumeSerialNumber); + SW(Obj, BootSectorMagic); +} + +VOID FatSwapFatXBootSector(PFATX_BOOTSECTOR Obj) +{ + SD(Obj, VolumeSerialNumber); + SD(Obj, SectorsPerCluster); + SW(Obj, NumberOfFats); +} + +VOID FatSwapDirEntry(PDIRENTRY Obj) +{ + SW(Obj, CreateTime); + SW(Obj, CreateDate); + SW(Obj, LastAccessDate); + SW(Obj, ClusterHigh); + SW(Obj, Time); + SW(Obj, Date); + SW(Obj, ClusterLow); + SD(Obj, Size); +} + +VOID FatSwapLFNDirEntry(PLFN_DIRENTRY Obj) +{ + int i; + SW(Obj, StartCluster); + for(i = 0; i < 5; i++) + Obj->Name0_4[i] = SWAPW(Obj->Name0_4[i]); + for(i = 0; i < 6; i++) + Obj->Name5_10[i] = SWAPW(Obj->Name5_10[i]); + for(i = 0; i < 2; i++) + Obj->Name11_12[i] = SWAPW(Obj->Name11_12[i]); +} + +VOID FatSwapFatXDirEntry(PFATX_DIRENTRY Obj) +{ + SD(Obj, StartCluster); + SD(Obj, Size); + SW(Obj, Time); + SW(Obj, Date); + SW(Obj, CreateTime); + SW(Obj, CreateDate); + SW(Obj, LastAccessTime); + SW(Obj, LastAccessDate); +} + BOOLEAN FatOpenVolume(ULONG DriveNumber, ULONG VolumeStartSector, ULONG PartitionSectorCount) { char ErrMsg[80]; @@ -75,6 +153,7 @@ } RtlCopyMemory(FatVolumeBootSector, (PVOID)DISKREADBUFFER, 512);
+ // Get the FAT type FatType = FatDetermineFatType(FatVolumeBootSector, PartitionSectorCount);
@@ -84,6 +163,7 @@
if (ISFATX(FatType)) { + FatSwapFatXBootSector(FatXVolumeBootSector); DbgPrint((DPRINT_FILESYSTEM, "sizeof(FATX_BOOTSECTOR) = 0x%x.\n", sizeof(FATX_BOOTSECTOR)));
DbgPrint((DPRINT_FILESYSTEM, "FileSystemType: %c%c%c%c.\n", FatXVolumeBootSector->FileSystemType[0], FatXVolumeBootSector->FileSystemType[1], FatXVolumeBootSector->FileSystemType[2], FatXVolumeBootSector->FileSystemType[3])); @@ -97,6 +177,7 @@ } else if (FatType == FAT32) { + FatSwapFat32BootSector(Fat32VolumeBootSector); DbgPrint((DPRINT_FILESYSTEM, "sizeof(FAT32_BOOTSECTOR) = 0x%x.\n", sizeof(FAT32_BOOTSECTOR)));
DbgPrint((DPRINT_FILESYSTEM, "JumpBoot: 0x%x 0x%x 0x%x\n", Fat32VolumeBootSector->JumpBoot[0], Fat32VolumeBootSector->JumpBoot[1], Fat32VolumeBootSector->JumpBoot[2])); @@ -130,6 +211,7 @@ } else { + FatSwapFatBootSector(FatVolumeBootSector); DbgPrint((DPRINT_FILESYSTEM, "sizeof(FAT_BOOTSECTOR) = 0x%x.\n", sizeof(FAT_BOOTSECTOR)));
DbgPrint((DPRINT_FILESYSTEM, "JumpBoot: 0x%x 0x%x 0x%x\n", FatVolumeBootSector->JumpBoot[0], FatVolumeBootSector->JumpBoot[1], FatVolumeBootSector->JumpBoot[2])); @@ -165,7 +247,7 @@ // // Check the boot sector magic // - if (! ISFATX(FatType) && FatVolumeBootSector->BootSectorMagic != 0xaa55) + if (! ISFATX(FatType) && SWAPW(FatVolumeBootSector->BootSectorMagic) != 0x55aa) { sprintf(ErrMsg, "Invalid boot sector magic on drive 0x%x (expected 0xaa55 found 0x%x)", DriveNumber, FatVolumeBootSector->BootSectorMagic); @@ -205,7 +287,7 @@ if (ISFATX(FatType)) { BytesPerSector = 512; - SectorsPerCluster = FatXVolumeBootSector->SectorsPerCluster; + SectorsPerCluster = SWAPD(FatXVolumeBootSector->SectorsPerCluster); FatSectorStart = (4096 / BytesPerSector); ActiveFatSectorStart = FatSectorStart; NumberOfFats = 1; @@ -260,6 +342,7 @@ // // Initialize the disk cache for this drive // + printf("About to do cache init\n"); if (!CacheInitializeDrive(DriveNumber)) { return FALSE; @@ -307,10 +390,10 @@ } else { - RootDirSectors = ((FatBootSector->RootDirEntries * 32) + (FatBootSector->BytesPerSector - 1)) / FatBootSector->BytesPerSector; - SectorsPerFat = FatBootSector->SectorsPerFat ? FatBootSector->SectorsPerFat : Fat32BootSector->SectorsPerFatBig; - TotalSectors = FatBootSector->TotalSectors ? FatBootSector->TotalSectors : FatBootSector->TotalSectorsBig; - DataSectorCount = TotalSectors - (FatBootSector->ReservedSectors + (FatBootSector->NumberOfFats * SectorsPerFat) + RootDirSectors); + RootDirSectors = ((SWAPW(FatBootSector->RootDirEntries) * 32) + (SWAPW(FatBootSector->BytesPerSector) - 1)) / SWAPW(FatBootSector->BytesPerSector); + SectorsPerFat = SWAPW(FatBootSector->SectorsPerFat) ? SWAPW(FatBootSector->SectorsPerFat) : SWAPD(Fat32BootSector->SectorsPerFatBig); + TotalSectors = SWAPW(FatBootSector->TotalSectors) ? SWAPW(FatBootSector->TotalSectors) : SWAPD(FatBootSector->TotalSectorsBig); + DataSectorCount = TotalSectors - (SWAPW(FatBootSector->ReservedSectors) + (FatBootSector->NumberOfFats * SectorsPerFat) + RootDirSectors);
//mjl if (FatBootSector->SectorsPerCluster == 0) @@ -402,11 +485,13 @@ { ULONG EntryCount; ULONG CurrentEntry; - PDIRENTRY DirEntry; - PLFN_DIRENTRY LfnDirEntry; CHAR LfnNameBuffer[265]; CHAR ShortNameBuffer[20]; ULONG StartCluster; + DIRENTRY OurDirEntry; + LFN_DIRENTRY OurLfnDirEntry; + PDIRENTRY DirEntry = &OurDirEntry; + PLFN_DIRENTRY LfnDirEntry = &OurLfnDirEntry;
EntryCount = DirectorySize / sizeof(DIRENTRY);
@@ -415,10 +500,12 @@ memset(ShortNameBuffer, 0, 13 * sizeof(CHAR)); memset(LfnNameBuffer, 0, 261 * sizeof(CHAR));
- DirEntry = (PDIRENTRY) DirectoryBuffer; - for (CurrentEntry=0; CurrentEntry<EntryCount; CurrentEntry++, DirEntry++) - { - LfnDirEntry = (PLFN_DIRENTRY)DirEntry; + for (CurrentEntry=0; CurrentEntry<EntryCount; CurrentEntry++, DirectoryBuffer = ((PDIRENTRY)DirectoryBuffer)+1) + { + OurLfnDirEntry = *((PLFN_DIRENTRY) DirectoryBuffer); + FatSwapLFNDirEntry(LfnDirEntry); + OurDirEntry = *((PDIRENTRY) DirectoryBuffer); + FatSwapDirEntry(DirEntry);
//DbgPrint((DPRINT_FILESYSTEM, "Dumping directory entry %d:\n", CurrentEntry)); //DbgDumpBuffer(DPRINT_FILESYSTEM, DirEntry, sizeof(DIRENTRY)); @@ -613,17 +700,20 @@ { ULONG EntryCount; ULONG CurrentEntry; - PFATX_DIRENTRY DirEntry; ULONG FileNameLen; + FATX_DIRENTRY OurDirEntry; + PFATX_DIRENTRY DirEntry = &OurDirEntry;
EntryCount = DirectorySize / sizeof(FATX_DIRENTRY);
DbgPrint((DPRINT_FILESYSTEM, "FatXSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x EntryCount = %d FileName = %s\n", DirectoryBuffer, EntryCount, FileName));
FileNameLen = strlen(FileName); - DirEntry = (PFATX_DIRENTRY) DirectoryBuffer; - for (CurrentEntry = 0; CurrentEntry < EntryCount; CurrentEntry++, DirEntry++) - { + + for (CurrentEntry = 0; CurrentEntry < EntryCount; CurrentEntry++, DirectoryBuffer = ((PFATX_DIRENTRY)DirectoryBuffer)+1) + { + OurDirEntry = *(PFATX_DIRENTRY) DirectoryBuffer; + FatSwapFatXDirEntry(&OurDirEntry); if (0xff == DirEntry->FileNameSize) { break; @@ -721,6 +811,7 @@ // Buffer the directory contents // DirectoryBuffer = FatBufferDirectory(DirectoryStartCluster, &DirectorySize, (i == 0) ); + if (DirectoryBuffer == NULL) { return FALSE; @@ -854,6 +945,7 @@ }
fat = *((USHORT *) ((ULONG_PTR)FILESYSBUFFER + ThisFatEntOffset)); + fat = SWAPW(fat); if (Cluster & 0x0001) fat = fat >> 4; /* Cluster number is ODD */ else @@ -874,6 +966,7 @@ }
fat = *((USHORT *) ((ULONG_PTR)FILESYSBUFFER + ThisFatEntOffset)); + fat = SWAPW(fat);
break;
@@ -891,6 +984,7 @@
// Get the fat entry fat = (*((ULONG *) ((ULONG_PTR)FILESYSBUFFER + ThisFatEntOffset))) & 0x0FFFFFFF; + fat = SWAPD(fat);
break;