From adb11df30367cf1a78a30fc4b77541564dc1db3c Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Sat, 7 Jul 2007 04:43:08 +0000 Subject: [PATCH] Resolve imports at boot time by loading the appropriate modules. We still need to fix the same stuff in ntoskrnl for pnp loading. Thanks to hpoussin for fixing pnp so this works. svn path=/trunk/; revision=27444 --- .../boot/freeldr/freeldr/arch/i386/loader.c | 41 +++------ .../boot/freeldr/freeldr/reactos/reactos.c | 91 +++++++++++++++++-- .../boot/freeldr/freeldr/reactos/setupldr.c | 65 ++----------- 3 files changed, 102 insertions(+), 95 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/arch/i386/loader.c b/reactos/boot/freeldr/freeldr/arch/i386/loader.c index 8f119502469..78cbc168f36 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/loader.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/loader.c @@ -454,6 +454,8 @@ LdrPEProcessImportDirectoryEntry(PVOID DriverBase, return STATUS_SUCCESS; } +extern BOOLEAN FrLdrLoadDriver(PCHAR szFileName, INT nPos); + NTSTATUS NTAPI LdrPEGetOrLoadModule(IN PCHAR ModuleName, @@ -465,31 +467,15 @@ LdrPEGetOrLoadModule(IN PCHAR ModuleName, *ImportedModule = LdrGetModuleObject(ImportedName); if (*ImportedModule == NULL) { - /* - * For now, we only support import-loading the HAL. - * Later, FrLdrLoadDriver should be made to share the same - * code, and we'll just call it instead. - */ - if (!_stricmp(ImportedName, "hal.dll") || - !_stricmp(ImportedName, "kdcom.dll") || - !_stricmp(ImportedName, "bootvid.dll")) - { - /* Load the HAL */ - FrLdrLoadImage(ImportedName, 10, FALSE); - - /* Return the new module */ - *ImportedModule = LdrGetModuleObject(ImportedName); - if (*ImportedModule == NULL) - { - DbgPrint("Error loading import: %s\n", ImportedName); - return STATUS_UNSUCCESSFUL; - } - } - else - { - DbgPrint("Don't yet support loading new modules from imports\n"); - Status = STATUS_NOT_IMPLEMENTED; - } + if (!FrLdrLoadDriver(ImportedName, 0)) + { + return STATUS_UNSUCCESSFUL; + } + else + { + return LdrPEGetOrLoadModule + (ModuleName, ImportedName, ImportedModule); + } } return Status; @@ -512,7 +498,7 @@ LdrPEFixupImports(IN PVOID DllBase, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &Size); - while (ImportModuleDirectory->Name) + while (ImportModuleDirectory && ImportModuleDirectory->Name) { /* Check to make sure that import lib is kernel */ ImportedName = (PCHAR) DllBase + ImportModuleDirectory->Name; @@ -651,9 +637,6 @@ FrLdrMapImage(IN FILE *Image, /* Increase the next Load Base */ NextModuleBase = ROUND_UP(NextModuleBase + ImageSize, PAGE_SIZE); - /* Load HAL if this is the kernel */ - if (ImageType == 1) FrLdrLoadImage("hal.dll", 10, FALSE); - /* Perform import fixups */ if (!NT_SUCCESS(LdrPEFixupImports(LoadBase, Name))) { diff --git a/reactos/boot/freeldr/freeldr/reactos/reactos.c b/reactos/boot/freeldr/freeldr/reactos/reactos.c index 4a748920fd8..412ebca9fdf 100644 --- a/reactos/boot/freeldr/freeldr/reactos/reactos.c +++ b/reactos/boot/freeldr/freeldr/reactos/reactos.c @@ -33,10 +33,93 @@ char reactos_arc_strings[32][256]; unsigned long reactos_disk_count = 0; CHAR szHalName[255]; CHAR szBootPath[255]; +CHAR SystemRoot[255]; static CHAR szLoadingMsg[] = "Loading ReactOS..."; BOOLEAN FrLdrBootType; extern ULONG_PTR KernelBase, KernelEntry; +BOOLEAN +FrLdrLoadDriver(PCHAR szFileName, + INT nPos) +{ + PFILE FilePointer; + CHAR value[256], *FinalSlash; + LPSTR p; + + if (!_stricmp(szFileName, "hal.dll")) + { + /* Use the boot.ini name instead */ + szFileName = szHalName; + } + + FinalSlash = strrchr(szFileName, '\\'); + if(FinalSlash) + szFileName = FinalSlash + 1; + + /* Open the Driver */ + FilePointer = FsOpenFile(szFileName); + + /* Try under the system root in the main dir and drivers */ + if (FilePointer == NULL) + { + strcpy(value, SystemRoot); + if(value[strlen(value)-1] != '\\') + strcat(value, "\\"); + strcat(value, szFileName); + FilePointer = FsOpenFile(value); + } + + if (FilePointer == NULL) + { + strcpy(value, SystemRoot); + if(value[strlen(value)-1] != '\\') + strcat(value, "\\"); + strcat(value, "SYSTEM32\\"); + strcat(value, szFileName); + FilePointer = FsOpenFile(value); + } + + if (FilePointer == NULL) + { + strcpy(value, SystemRoot); + if(value[strlen(value)-1] != '\\') + strcat(value, "\\"); + strcat(value, "SYSTEM32\\DRIVERS\\"); + strcat(value, szFileName); + FilePointer = FsOpenFile(value); + } + + /* Make sure we did */ + if (FilePointer == NULL) { + + /* Fail if file wasn't opened */ + strcpy(value, szFileName); + strcat(value, " not found."); + return(FALSE); + } + + /* Update the status bar with the current file */ + strcpy(value, "Reading "); + p = strrchr(szFileName, '\\'); + if (p == NULL) { + + strcat(value, szFileName); + + } else { + + strcat(value, p + 1); + + } + UiDrawStatusText(value); + + /* Load the driver */ + FrLdrMapImage(FilePointer, szFileName, 0); + + /* Update status and return */ + UiDrawProgressBarCenter(nPos, 100, szLoadingMsg); + return(TRUE); +} + PVOID NTAPI FrLdrLoadImage(IN PCHAR szFileName, @@ -48,13 +131,6 @@ FrLdrLoadImage(IN PCHAR szFileName, CHAR szBuffer[256], szFullPath[256]; PVOID LoadBase; - /* Check if this the HAL being loaded */ - if (!_stricmp(szFileName, "hal.dll")) - { - /* Use the boot.ini name instead */ - szFileName = szHalName; - } - /* Extract filename without path */ szShortName = strrchr(szFileName, '\\'); if (!szShortName) @@ -618,6 +694,7 @@ LoadAndBootReactOS(PCSTR OperatingSystemName) strcat(szBootPath, "\\"); DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath)); + strcpy(SystemRoot, szBootPath); /* * Find the kernel image name diff --git a/reactos/boot/freeldr/freeldr/reactos/setupldr.c b/reactos/boot/freeldr/freeldr/reactos/setupldr.c index d47083d479f..575f6b7490f 100644 --- a/reactos/boot/freeldr/freeldr/reactos/setupldr.c +++ b/reactos/boot/freeldr/freeldr/reactos/setupldr.c @@ -30,8 +30,10 @@ unsigned long reactos_memory_map_descriptor_size; memory_map_t reactos_memory_map[32]; // Memory map char szBootPath[256]; char szHalName[256]; +CHAR SystemRoot[255]; extern ULONG_PTR KernelBase, KernelEntry; +extern BOOLEAN FrLdrLoadDriver(PCHAR szFileName, INT nPos); #define USE_UI @@ -91,65 +93,7 @@ static FrLdrLoadKernel(IN PCHAR szFileName, static BOOLEAN LoadDriver(PCSTR szSourcePath, PCSTR szFileName) { - CHAR szFullName[256]; -#ifdef USE_UI - CHAR szBuffer[80]; -#endif - PFILE FilePointer; - PCSTR szShortName; - - if (szSourcePath[0] != '\\') - { - strcpy(szFullName, "\\"); - strcat(szFullName, szSourcePath); - } - else - { - strcpy(szFullName, szSourcePath); - } - - if (szFullName[strlen(szFullName)] != '\\') - { - strcat(szFullName, "\\"); - } - - if (szFileName[0] != '\\') - { - strcat(szFullName, szFileName); - } - else - { - strcat(szFullName, szFileName + 1); - } - - szShortName = strrchr(szFileName, '\\'); - if (szShortName == NULL) - szShortName = szFileName; - else - szShortName = szShortName + 1; - - - FilePointer = FsOpenFile(szFullName); - if (FilePointer == NULL) - { - printf("Could not find %s\n", szFileName); - return(FALSE); - } - - /* - * Update the status bar with the current file - */ -#ifdef USE_UI - sprintf(szBuffer, "Setup is loading files (%s)", szShortName); - UiDrawStatusText(szBuffer); -#else - printf("Reading %s\n", szShortName); -#endif - - /* Load the driver */ - FrLdrMapImage(FilePointer, (LPSTR)szFileName, 2); - - return(TRUE); + return FrLdrLoadDriver((PCHAR)szFileName, 0); } @@ -342,6 +286,9 @@ VOID RunLoader(VOID) strcat(strcat(strcat(reactos_kernel_cmdline, SourcePath), " "), LoadOptions); + strcpy(SystemRoot, SourcePath); + strcat(SystemRoot, "\\"); + /* Setup the boot path and kernel path */ strcpy(szBootPath, SourcePath); strcpy(szKernelName, szBootPath);