[FREELDR]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 5 Feb 2016 00:17:33 +0000 (00:17 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 5 Feb 2016 00:17:33 +0000 (00:17 +0000)
Start splitting FreeLdr in the same spirit as our new UEFI boot manager/loader: split into a boot library, the boot manager code, and the NT loader.
- The boot library provides the basic support (read INI/INF files, memory management, debugging, ARC compatibility/emulation, ...).
- The boot manager code is FreeLdr proper.
- The NT loader is used for loading Windows or ReactOS. Because of that fact I rename its directory "windows" into "NTLDR" to underline the fact it can load NT-type OSes (more exactly version 5.x), to which both Windows 2k/XP/2k3 and ReactOS belong. The APIs will certainly be renamed "NtLdrXXX" instead of "WinLdrXXX".
- The general PE loader is put into the boot library since it is needed also by FreeLdr proper to be able to load SCSI drivers (on x86/64/... architectures; on ARC systems SCSI support is automatically provided).

svn path=/trunk/; revision=70692

29 files changed:
reactos/boot/freeldr/freeldr/CMakeLists.txt
reactos/boot/freeldr/freeldr/arch/i386/halstub.c [moved from reactos/boot/freeldr/freeldr/windows/arch/i386/halstub.c with 99% similarity]
reactos/boot/freeldr/freeldr/arch/i386/ntoskrnl.c [moved from reactos/boot/freeldr/freeldr/windows/arch/i386/ntoskrnl.c with 99% similarity]
reactos/boot/freeldr/freeldr/include/conversion.h [new file with mode: 0644]
reactos/boot/freeldr/freeldr/include/freeldr.h
reactos/boot/freeldr/freeldr/include/ntoskrnl.h [moved from reactos/boot/freeldr/freeldr/windows/arch/i386/ntoskrnl.h with 100% similarity]
reactos/boot/freeldr/freeldr/lib/comm/rs232.c [moved from reactos/boot/freeldr/freeldr/comm/rs232.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/debug.c [moved from reactos/boot/freeldr/freeldr/debug.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/fs/ext2.c [moved from reactos/boot/freeldr/freeldr/fs/ext2.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/fs/fat.c [moved from reactos/boot/freeldr/freeldr/fs/fat.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/fs/fs.c [moved from reactos/boot/freeldr/freeldr/fs/fs.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/fs/iso.c [moved from reactos/boot/freeldr/freeldr/fs/iso.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/fs/ntfs.c [moved from reactos/boot/freeldr/freeldr/fs/ntfs.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/fs/pxe.c [moved from reactos/boot/freeldr/freeldr/fs/pxe.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/mm/heap.c [moved from reactos/boot/freeldr/freeldr/mm/heap.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/mm/meminit.c [moved from reactos/boot/freeldr/freeldr/mm/meminit.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/mm/mm.c [moved from reactos/boot/freeldr/freeldr/mm/mm.c with 100% similarity]
reactos/boot/freeldr/freeldr/lib/peloader.c [moved from reactos/boot/freeldr/freeldr/windows/peloader.c with 99% similarity]
reactos/boot/freeldr/freeldr/ntldr/arch/amd64/winldr.c [moved from reactos/boot/freeldr/freeldr/windows/arch/amd64/winldr.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/arch/arm/winldr.c [moved from reactos/boot/freeldr/freeldr/windows/arch/arm/winldr.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/arch/i386/winldr.c [moved from reactos/boot/freeldr/freeldr/windows/arch/i386/winldr.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/conversion.c [moved from reactos/boot/freeldr/freeldr/windows/conversion.c with 91% similarity]
reactos/boot/freeldr/freeldr/ntldr/headless.c [moved from reactos/boot/freeldr/freeldr/windows/headless.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/registry.c [moved from reactos/boot/freeldr/freeldr/windows/registry.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/registry.h [moved from reactos/boot/freeldr/freeldr/windows/registry.h with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/setupldr.c [moved from reactos/boot/freeldr/freeldr/windows/setupldr.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/winldr.c [moved from reactos/boot/freeldr/freeldr/windows/winldr.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/wlmemory.c [moved from reactos/boot/freeldr/freeldr/windows/wlmemory.c with 100% similarity]
reactos/boot/freeldr/freeldr/ntldr/wlregistry.c [moved from reactos/boot/freeldr/freeldr/windows/wlregistry.c with 100% similarity]

index 7e237eb..475a1a1 100644 (file)
@@ -32,37 +32,55 @@ include_directories(${REACTOS_SOURCE_DIR}/include/reactos/elf)
 
 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
 
 
 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
 
-list(APPEND FREELDR_COMMON_SOURCE
-    include/freeldr.h
+
+list(APPEND FREELDR_BOOTLIB_COMMON_SOURCE
+    lib/debug.c
+    lib/peloader.c
+
+    lib/comm/rs232.c
+    ## add KD support
+    lib/fs/ext2.c
+    lib/fs/fat.c
+    lib/fs/fs.c
+    lib/fs/iso.c
+    lib/fs/ntfs.c
+    lib/inifile/ini_init.c
+    lib/inifile/inifile.c
+    lib/inifile/parse.c
+    lib/mm/meminit.c
+    lib/mm/mm.c
+    lib/mm/heap.c
+    )
+
+list(APPEND FREELDR_NTLDR_COMMON_SOURCE
+    ntldr/conversion.c
+    ntldr/registry.c
+    ntldr/winldr.c
+    ntldr/wlmemory.c
+    ntldr/wlregistry.c
+    )
+
+list(APPEND FREELDR_ARC_COMMON_SOURCE
     arcname.c
     arcname.c
-    cmdline.c
-    custom.c
-    debug.c
-    linuxboot.c
-    miscboot.c
     machine.c
     machine.c
-    options.c
-    oslist.c
-    version.c
     arch/archwsup.c
     cache/blocklist.c
     cache/cache.c
     arch/archwsup.c
     cache/blocklist.c
     cache/cache.c
-    comm/rs232.c
     disk/disk.c
     disk/partition.c
     disk/ramdisk.c
     #disk/scsiport.c
     disk/disk.c
     disk/partition.c
     disk/ramdisk.c
     #disk/scsiport.c
-    fs/ext2.c
-    fs/fat.c
-    fs/fs.c
-    fs/iso.c
-    fs/ntfs.c
-    lib/inifile/ini_init.c
-    lib/inifile/inifile.c
-    lib/inifile/parse.c
-    mm/meminit.c
-    mm/mm.c
-    mm/heap.c
+    )
+
+list(APPEND FREELDR_COMMON_SOURCE
+    include/freeldr.h
+    cmdline.c
+    custom.c
+    linuxboot.c
+    miscboot.c
+    options.c
+    oslist.c
+    version.c
     ui/directui.c
     ui/gui.c
     ui/minitui.c
     ui/directui.c
     ui/gui.c
     ui/minitui.c
@@ -73,12 +91,7 @@ list(APPEND FREELDR_COMMON_SOURCE
     video/fade.c
     video/palette.c
     video/video.c
     video/fade.c
     video/palette.c
     video/video.c
-    windows/conversion.c
-    windows/peloader.c
-    windows/registry.c
-    windows/winldr.c
-    windows/wlmemory.c
-    windows/wlregistry.c)
+    )
 
 if(ARCH STREQUAL "i386")
     list(APPEND FREELDR_COMMON_ASM_SOURCE
 
 if(ARCH STREQUAL "i386")
     list(APPEND FREELDR_COMMON_ASM_SOURCE
@@ -86,9 +99,21 @@ if(ARCH STREQUAL "i386")
         arch/i386/i386pnp.S
         arch/i386/i386trap.S
         arch/i386/linux.S
         arch/i386/i386pnp.S
         arch/i386/i386trap.S
         arch/i386/linux.S
-        arch/i386/mb.S)
-    list(APPEND FREELDR_COMMON_SOURCE
-        fs/pxe.c
+        arch/i386/mb.S
+        )
+
+    list(APPEND FREELDR_NTLDR_COMMON_SOURCE
+        ntldr/arch/i386/winldr.c
+        ntldr/headless.c
+        )
+
+    ## list(APPEND FREELDR_COMMON_SOURCE
+    list(APPEND FREELDR_ARC_COMMON_SOURCE
+        lib/fs/pxe.c
+
+        arch/i386/halstub.c
+        arch/i386/ntoskrnl.c
+
         arch/i386/archmach.c
         arch/i386/drivemap.c
         arch/i386/hardware.c
         arch/i386/archmach.c
         arch/i386/drivemap.c
         arch/i386/hardware.c
@@ -116,10 +141,6 @@ if(ARCH STREQUAL "i386")
         arch/i386/xboxmem.c
         arch/i386/xboxrtc.c
         arch/i386/xboxvideo.c
         arch/i386/xboxmem.c
         arch/i386/xboxrtc.c
         arch/i386/xboxvideo.c
-        windows/arch/i386/halstub.c
-        windows/arch/i386/ntoskrnl.c
-        windows/arch/i386/winldr.c
-        windows/headless.c
         disk/scsiport.c)
     if(NOT MSVC)
         list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
         disk/scsiport.c)
     if(NOT MSVC)
         list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
@@ -129,8 +150,17 @@ elseif(ARCH STREQUAL "amd64")
         arch/amd64/entry.S
         arch/amd64/int386.S
         arch/amd64/pnpbios.S)
         arch/amd64/entry.S
         arch/amd64/int386.S
         arch/amd64/pnpbios.S)
-    list(APPEND FREELDR_COMMON_SOURCE
-        fs/pxe.c
+
+    list(APPEND FREELDR_NTLDR_COMMON_SOURCE
+        ntldr/arch/amd64/winldr.c
+        )
+
+    ## list(APPEND FREELDR_COMMON_SOURCE
+    list(APPEND FREELDR_ARC_COMMON_SOURCE
+        lib/fs/pxe.c
+
+        arch/i386/ntoskrnl.c
+
         arch/i386/drivemap.c
         arch/i386/hardware.c
         arch/i386/hwacpi.c
         arch/i386/drivemap.c
         arch/i386/hardware.c
         arch/i386/hwacpi.c
@@ -146,22 +176,27 @@ elseif(ARCH STREQUAL "amd64")
         arch/i386/pcdisk.c
         arch/i386/pcmem.c
         arch/i386/pcrtc.c
         arch/i386/pcdisk.c
         arch/i386/pcmem.c
         arch/i386/pcrtc.c
-        arch/i386/pcvideo.c
-        windows/arch/i386/ntoskrnl.c
-        windows/arch/amd64/winldr.c)
+        arch/i386/pcvideo.c)
 elseif(ARCH STREQUAL "arm")
     list(APPEND FREELDR_COMMON_ASM_SOURCE
         arch/arm/boot.S)
 elseif(ARCH STREQUAL "arm")
     list(APPEND FREELDR_COMMON_ASM_SOURCE
         arch/arm/boot.S)
-    list(APPEND FREELDR_COMMON_SOURCE
+
+    list(APPEND FREELDR_NTLDR_COMMON_SOURCE
+        ntldr/arch/arm/winldr.c
+        )
+
+    ## list(APPEND FREELDR_COMMON_SOURCE
+    list(APPEND FREELDR_ARC_COMMON_SOURCE
         arch/arm/entry.c
         arch/arm/entry.c
-        arch/arm/macharm.c
-        windows/arch/arm/winldr.c)
+        arch/arm/macharm.c)
 else()
 #TBD
 endif()
 
 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
 else()
 #TBD
 endif()
 
 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
-add_library(freeldr_common ${FREELDR_COMMON_SOURCE} ${freeldr_common_asm})
+add_library(freeldr_common ${FREELDR_BOOTLIB_COMMON_SOURCE} ${FREELDR_ARC_COMMON_SOURCE}
+            ${FREELDR_NTLDR_COMMON_SOURCE}
+            ${FREELDR_COMMON_SOURCE} ${freeldr_common_asm})
 add_pch(freeldr_common include/freeldr.h FREELDR_COMMON_SOURCE)
 add_dependencies(freeldr_common bugcodes asm xdk)
 
 add_pch(freeldr_common include/freeldr.h FREELDR_COMMON_SOURCE)
 add_dependencies(freeldr_common bugcodes asm xdk)
 
@@ -173,7 +208,10 @@ endif()
 list(APPEND FREELDR_BASE_SOURCE
     bootmgr.c # This file is compiled with custom definitions
     freeldr.c
 list(APPEND FREELDR_BASE_SOURCE
     bootmgr.c # This file is compiled with custom definitions
     freeldr.c
-    windows/setupldr.c
+    ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
+                     ## even if ${FREELDR_NTLDR_COMMON_SOURCE} is not added,
+                     ## otherwise we get linking errors with Rtl**Bitmap** APIs.
+                     ## Do not happen on MSVC builds however...
     lib/inffile/inffile.c
     lib/rtl/libsupp.c)
 
     lib/inffile/inffile.c
     lib/rtl/libsupp.c)
 
@@ -8,7 +8,7 @@
 
 /* INCLUDES ******************************************************************/
 
 
 /* INCLUDES ******************************************************************/
 
-#include "ntoskrnl.h"
+#include <ntoskrnl.h>
 #define NDEBUG
 #include <debug.h>
 
 #define NDEBUG
 #include <debug.h>
 
@@ -8,7 +8,7 @@
 
 /* INCLUDES ******************************************************************/
 
 
 /* INCLUDES ******************************************************************/
 
-#include "ntoskrnl.h"
+#include <ntoskrnl.h>
 
 /* For KeStallExecutionProcessor */
 #if defined(_M_IX86) || defined(_M_AMD64)
 
 /* For KeStallExecutionProcessor */
 #if defined(_M_IX86) || defined(_M_AMD64)
diff --git a/reactos/boot/freeldr/freeldr/include/conversion.h b/reactos/boot/freeldr/freeldr/include/conversion.h
new file mode 100644 (file)
index 0000000..3a0da85
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * PROJECT:         EFI Windows Loader
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            boot/freeldr/freeldr/windows/conversion.c
+ * PURPOSE:         Physical <-> Virtual addressing mode conversions (arch-specific)
+ * PROGRAMMERS:     Aleksey Bragin (aleksey@reactos.org)
+ */
+
+#pragma once
+
+#ifndef _ZOOM2_
+/* Arch-specific addresses translation implementation */
+FORCEINLINE
+PVOID
+VaToPa(PVOID Va)
+{
+    return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE);
+}
+
+FORCEINLINE
+PVOID
+PaToVa(PVOID Pa)
+{
+    return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE);
+}
+#else
+FORCEINLINE
+PVOID
+VaToPa(PVOID Va)
+{
+    return Va;
+}
+
+FORCEINLINE
+PVOID
+PaToVa(PVOID Pa)
+{
+    return Pa;
+}
+#endif
index 0b6d953..8dfb9c0 100644 (file)
@@ -81,6 +81,7 @@
 
 /* NTOS loader */
 #include <winldr.h>
 
 /* NTOS loader */
 #include <winldr.h>
+#include <conversion.h> // More-or-less related to MM also...
 
 /* File system headers */
 #include <fs/ext2.h>
 
 /* File system headers */
 #include <fs/ext2.h>
@@ -2,15 +2,18 @@
  * PROJECT:         FreeLoader
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            boot/freeldr/freeldr/windows/peloader.c
  * PROJECT:         FreeLoader
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            boot/freeldr/freeldr/windows/peloader.c
- * PURPOSE:         Provides routines for loading PE files. To be merged with
- *                  arch/i386/loader.c in future
- *                  This article was very handy during development:
- *                  http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/
+ * PURPOSE:         Provides routines for loading PE files.
+ *                  (Deprecated remark) To be merged with arch/i386/loader.c in future.
+ *
  * PROGRAMMERS:     Aleksey Bragin (aleksey@reactos.org)
  * PROGRAMMERS:     Aleksey Bragin (aleksey@reactos.org)
+ *
  *                  The source code in this file is based on the work of respective
  *                  authors of PE loading code in ReactOS and Brian Palmer and
  *                  Alex Ionescu's arch/i386/loader.c, and my research project
  *                  The source code in this file is based on the work of respective
  *                  authors of PE loading code in ReactOS and Brian Palmer and
  *                  Alex Ionescu's arch/i386/loader.c, and my research project
- *                  (creating a native EFI loader for Windows)
+ *                  (creating a native EFI loader for Windows).
+ *
+ * NOTE:            This article was very handy during development:
+ *                  http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/
  */
 
 /* INCLUDES ***************************************************************/
  */
 
 /* INCLUDES ***************************************************************/
@@ -17,33 +17,6 @@ DBG_DEFAULT_CHANNEL(WINDOWS);
 
 /* FUNCTIONS **************************************************************/
 
 
 /* FUNCTIONS **************************************************************/
 
-#ifndef _ZOOM2_
-/* Arch-specific addresses translation implementation */
-PVOID
-VaToPa(PVOID Va)
-{
-    return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE);
-}
-
-PVOID
-PaToVa(PVOID Pa)
-{
-    return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE);
-}
-#else
-PVOID
-VaToPa(PVOID Va)
-{
-    return Va;
-}
-
-PVOID
-PaToVa(PVOID Pa)
-{
-    return Pa;
-}
-#endif
-
 VOID
 List_PaToVa(_In_ PLIST_ENTRY ListHeadPa)
 {
 VOID
 List_PaToVa(_In_ PLIST_ENTRY ListHeadPa)
 {