[FREELDR] Diverse enhancements.
[reactos.git] / boot / freeldr / freeldr / arch / powerpc / mboot.c
index 352d237..aa57f06 100644 (file)
@@ -25,7 +25,6 @@
 #include "ppcmmu/mmu.h"
 #include "compat.h"
 
-#define NDEBUG
 #include <debug.h>
 
 /* We'll check this to see if we're in OFW land */
@@ -359,7 +358,7 @@ FrLdrGetKernelBase(VOID)
  * FrLdrGetPaeMode
  * INTERNAL
  *
- *     Determines whether PAE mode shoudl be enabled or not.
+ *     Determines whether PAE mode should be enabled or not.
  *
  * Params:
  *     None.
@@ -390,7 +389,7 @@ FrLdrGetPaeMode(VOID)
  *     None.
  *
  * Remarks:
- *     We are setting PDEs, but using the equvivalent (for our purpose) PTE structure.
+ *     We are setting PDEs, but using the equivalent (for our purpose) PTE structure.
  *     As such, please note that PageFrameNumber == PageEntryNumber.
  *
  *--*/
@@ -432,6 +431,7 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
     PCHAR sptr;
     Elf32_Ehdr ehdr;
     Elf32_Shdr *shdr;
+    LARGE_INTEGER Position;
     LPSTR TempName;
 
     TempName = strrchr(ImageName, '\\');
@@ -452,7 +452,7 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
     //printf("Loading file (elf at %x)\n", KernelAddr);
 
     /* Load the first 1024 bytes of the kernel image so we can read the PE header */
-    if (!FsReadFile(KernelImage, sizeof(ehdr), NULL, &ehdr)) {
+    if (ArcRead(KernelImage, &ehdr, sizeof(ehdr), NULL) != ESUCCESS) {
 
         /* Fail if we couldn't read */
     printf("Couldn't read the elf header\n");
@@ -467,8 +467,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
     sptr = (PCHAR)FrLdrTempAlloc(shnum * shsize, TAG_MBOOT);
 
     /* Read section headers */
-    FsSetFilePointer(KernelImage,  ehdr.e_shoff);
-    FsReadFile(KernelImage, shsize * shnum, NULL, sptr);
+    Position.QuadPart = ehdr.e_shoff;
+    ArcSeek(KernelImage, &Position, SeekAbsolute);
+    ArcRead(KernelImage, sptr, shsize * shnum, NULL);
 
     /* Now we'll get the PE Header */
     for( i = 0; i < shnum; i++ )
@@ -479,8 +480,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
     /* Find the PE Header */
     if (shdr->sh_type == TYPE_PEHEADER)
     {
-        FsSetFilePointer(KernelImage, shdr->sh_offset);
-        FsReadFile(KernelImage, shdr->sh_size, NULL, MemLoadAddr);
+        Position.QuadPart = shdr->sh_offset;
+        ArcSeek(KernelImage, &Position, SeekAbsolute);
+        ArcRead(KernelImage, MemLoadAddr, shdr->sh_size, NULL);
         ImageHeader = (PIMAGE_DOS_HEADER)MemLoadAddr;
         NtHeader = (PIMAGE_NT_HEADERS)((PCHAR)MemLoadAddr + SWAPD(ImageHeader->e_lfanew));
 #if 0
@@ -528,8 +530,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
     {
         /* Content area */
         printf("Loading section %d at %x (real: %x:%d)\n", i, KernelAddr + SectionAddr, MemLoadAddr+SectionAddr, shdr->sh_size);
-        FsSetFilePointer(KernelImage, shdr->sh_offset);
-        FsReadFile(KernelImage, shdr->sh_size, NULL, MemLoadAddr + SectionAddr);
+        Position.QuadPart = shdr->sh_offset;
+        ArcSeek(KernelImage, &Position, SeekAbsolute);
+        ArcRead(KernelImage, MemLoadAddr + SectionAddr, shdr->sh_size, NULL);
     }
     else
     {
@@ -566,15 +569,17 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
     if (!ELF_SECTION(targetSection)->sh_addr) continue;
 
     RelocSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT);
-    FsSetFilePointer(KernelImage, relstart);
-    FsReadFile(KernelImage, shdr->sh_size, NULL, RelocSection);
+    Position.QuadPart = relstart;
+    ArcSeek(KernelImage, &Position, SeekAbsolute);
+    ArcRead(KernelImage, RelocSection, shdr->sh_size, NULL);
 
     /* Get the symbol section */
     shdr = ELF_SECTION(shdr->sh_link);
 
     SymbolSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT);
-    FsSetFilePointer(KernelImage, shdr->sh_offset);
-    FsReadFile(KernelImage, shdr->sh_size, NULL, SymbolSection);
+    Position.QuadPart = shdr->sh_offset;
+    ArcSeek(KernelImage, &Position, SeekAbsolute);
+    ArcRead(KernelImage, SymbolSection, shdr->sh_size, NULL);
 
     for(j = 0; j < numreloc; j++)
     {
@@ -706,6 +711,8 @@ FrLdrLoadModule(FILE *ModuleImage,
                 LPCSTR ModuleName,
                 PULONG ModuleSize)
 {
+    ARC_STATUS Status;
+    FILEINFORMATION FileInfo;
     ULONG LocalModuleSize;
     ULONG_PTR ThisModuleBase = NextModuleBase;
     PLOADER_MODULE ModuleData;
@@ -727,9 +734,12 @@ FrLdrLoadModule(FILE *ModuleImage,
     } while(TempName);
     NameBuffer = reactos_module_strings[LoaderBlock.ModsCount];
 
-
     /* Get Module Size */
-    LocalModuleSize = FsGetFileSize(ModuleImage);
+    Status = ArcGetFileInformation(ModuleImage, &FileInfo);
+    if (Status != ESUCCESS || FileInfo.EndingAddress.HighPart != 0)
+        LocalModuleSize = 0;
+    else
+        LocalModuleSize = FileInfo.EndingAddress.LowPart;
 
     /* Fill out Module Data Structure */
     ModuleData->ModStart = NextModuleBase;
@@ -740,7 +750,7 @@ FrLdrLoadModule(FILE *ModuleImage,
     ModuleData->String = (ULONG_PTR)NameBuffer;
 
     /* Load the file image */
-    FsReadFile(ModuleImage, LocalModuleSize, NULL, (PVOID)NextModuleBase);
+    ArcRead(ModuleImage, (PVOID)NextModuleBase, LocalModuleSize, NULL);
 
     /* Move to next memory block and increase Module Count */
     NextModuleBase = ROUND_UP(ModuleData->ModEnd, PAGE_SIZE);