- Get rid of a bunch of multiboot crap FreeLDR was still doing for ReactOS.

- Remove some of the sixtuplicated routines to load a PE file. We're now down to a single function which takes an ImageType parameter for DLL/EXE/SYS, but even this is still temporary as the parameter will soon go away.
- We now load drivers in the same nice way that we load the kernel and DLLs, but we don't yet process their imports and relocate them in FreeLDR, because FreeLDR doesn't handle forwarders yet.
- We don't need a large hack in KiRosPrepareForSystemStartup anymore since the driver base addresses are now proper.
- Don't free boot-drivers anymore, since we'll load them in place soon.
- Don't load bootvid twice.
- Remove PAE stuff in FreeLDR since we don't support PAE anyway in the kernel and when we do, might as well implement it cleanly instead of relying on the broken FreeLDR stuff.

svn path=/trunk/; revision=25860
This commit is contained in:
Alex Ionescu 2007-02-20 20:02:52 +00:00
parent b4f7cf3523
commit 226a94773d
7 changed files with 164 additions and 757 deletions

View file

@ -492,13 +492,6 @@ HKLM,"SYSTEM\CurrentControlSet\Services\Blue","ImagePath",0x00020000,"system32\d
HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Start",0x00010001,0x00000001 HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Start",0x00010001,0x00000001
HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Type",0x00010001,0x00000001 HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Type",0x00010001,0x00000001
; Boot Video Driver
HKLM,"SYSTEM\CurrentControlSet\Services\BootVideo","ErrorControl",0x00010001,0x00000000
HKLM,"SYSTEM\CurrentControlSet\Services\BootVideo","Group",0x00000000,"Base"
HKLM,"SYSTEM\CurrentControlSet\Services\BootVideo","ImagePath",0x00020000,"system32\drivers\bootvid.dll"
HKLM,"SYSTEM\CurrentControlSet\Services\BootVideo","Start",0x00010001,0x00000000
HKLM,"SYSTEM\CurrentControlSet\Services\BootVideo","Type",0x00010001,0x00000002
; Cdfs (ISO96660) filesystem driver ; Cdfs (ISO96660) filesystem driver
HKLM,"SYSTEM\CurrentControlSet\Services\Cdfs","ErrorControl",0x00010001,0x00000000 HKLM,"SYSTEM\CurrentControlSet\Services\Cdfs","ErrorControl",0x00010001,0x00000000
HKLM,"SYSTEM\CurrentControlSet\Services\Cdfs","Group",0x00000000,"File System" HKLM,"SYSTEM\CurrentControlSet\Services\Cdfs","Group",0x00000000,"File System"

View file

@ -34,7 +34,6 @@
#define PDE_SHIFT 22 #define PDE_SHIFT 22
#define PDE_SHIFT_PAE 18 #define PDE_SHIFT_PAE 18
/* Converts a Relative Address read from the Kernel into a Physical Address */ /* Converts a Relative Address read from the Kernel into a Physical Address */
#define RaToPa(p) \ #define RaToPa(p) \
(ULONG_PTR)((ULONG_PTR)p + KERNEL_BASE_PHYS) (ULONG_PTR)((ULONG_PTR)p + KERNEL_BASE_PHYS)
@ -59,17 +58,10 @@
#define KpcrPageTableIndex (KPCR_BASE >> 22) #define KpcrPageTableIndex (KPCR_BASE >> 22)
#define ApicPageTableIndex (APIC_BASE >> 22) #define ApicPageTableIndex (APIC_BASE >> 22)
#define LowMemPageTableIndexPae 0
#define StartupPageTableIndexPae (STARTUP_BASE >> 21)
#define HyperspacePageTableIndexPae (HYPERSPACE_PAE_BASE >> 21)
#define KpcrPageTableIndexPae (KPCR_BASE >> 21)
#define ApicPageTableIndexPae (APIC_BASE >> 21)
#define KernelEntryPoint (KernelEntry - KERNEL_BASE_PHYS) + KernelBase #define KernelEntryPoint (KernelEntry - KERNEL_BASE_PHYS) + KernelBase
/* Load Address of Next Module */ /* Load Address of Next Module */
ULONG_PTR NextModuleBase = 0; ULONG_PTR NextModuleBase = KERNEL_BASE_PHYS;
/* Currently Opened Module */ /* Currently Opened Module */
PLOADER_MODULE CurrentModule = NULL; PLOADER_MODULE CurrentModule = NULL;
@ -77,9 +69,6 @@ PLOADER_MODULE CurrentModule = NULL;
/* Unrelocated Kernel Base in Virtual Memory */ /* Unrelocated Kernel Base in Virtual Memory */
ULONG_PTR KernelBase; ULONG_PTR KernelBase;
/* Whether PAE is to be used or not */
BOOLEAN PaeModeEnabled;
/* Kernel Entrypoint in Physical Memory */ /* Kernel Entrypoint in Physical Memory */
ULONG_PTR KernelEntry; ULONG_PTR KernelEntry;
@ -135,7 +124,8 @@ extern PAGE_DIRECTORY_X64 kpcr_pagetable_pae;
BOOLEAN BOOLEAN
NTAPI NTAPI
FrLdrLoadImage(IN PCHAR szFileName, FrLdrLoadImage(IN PCHAR szFileName,
IN INT nPos); IN INT nPos,
IN BOOLEAN IsKernel);
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
@ -165,9 +155,6 @@ FrLdrStartup(ULONG Magic)
/* Re-initalize EFLAGS */ /* Re-initalize EFLAGS */
Ke386EraseFlags(); Ke386EraseFlags();
/* Get the PAE Mode */
FrLdrGetPaeMode();
/* Initialize the page directory */ /* Initialize the page directory */
FrLdrSetupPageDirectory(); FrLdrSetupPageDirectory();
@ -199,14 +186,6 @@ FrLdrSetupPae(ULONG Magic)
ULONG_PTR PageDirectoryBaseAddress = (ULONG_PTR)&startup_pagedirectory; ULONG_PTR PageDirectoryBaseAddress = (ULONG_PTR)&startup_pagedirectory;
ASMCODE PagedJump; ASMCODE PagedJump;
if (PaeModeEnabled)
{
PageDirectoryBaseAddress = (ULONG_PTR)&startup_pagedirectorytable_pae;
/* Enable PAE */
__writecr4(__readcr4() | X86_CR4_PAE);
}
/* Set the PDBR */ /* Set the PDBR */
__writecr3(PageDirectoryBaseAddress); __writecr3(PageDirectoryBaseAddress);
@ -218,110 +197,6 @@ FrLdrSetupPae(ULONG Magic)
PagedJump(Magic, &LoaderBlock); PagedJump(Magic, &LoaderBlock);
} }
/*++
* FrLdrGetKernelBase
* INTERNAL
*
* Gets the Kernel Base to use.
*
* Params:
*
* Returns:
* None.
*
* Remarks:
* Sets both the FreeLdr internal variable as well as the one which
* will be used by the Kernel.
*
*--*/
static VOID
FASTCALL
FrLdrGetKernelBase(VOID)
{
PCHAR p;
/* Set KernelBase */
LoaderBlock.KernelBase = KernelBase;
/* Read Command Line */
p = (PCHAR)LoaderBlock.CommandLine;
while ((p = strchr(p, '/')) != NULL) {
/* Find "/3GB" */
if (!_strnicmp(p + 1, "3GB", 3)) {
/* Make sure there's nothing following it */
if (p[4] == ' ' || p[4] == 0) {
/* Use 3GB */
KernelBase = 0xE0000000;
LoaderBlock.KernelBase = 0xC0000000;
}
}
p++;
}
}
/*++
* FrLdrGetPaeMode
* INTERNAL
*
* Determines whether PAE mode should be enabled or not.
*
* Params:
* None.
*
* Returns:
* None.
*
* Remarks:
* None.
*
*--*/
VOID
FASTCALL
FrLdrGetPaeMode(VOID)
{
BOOLEAN PaeModeSupported;
PaeModeSupported = FALSE;
PaeModeEnabled = FALSE;
if (CpuidSupported() & 1)
{
ULONG eax, ebx, ecx, FeatureBits;
GetCpuid(1, &eax, &ebx, &ecx, &FeatureBits);
if (FeatureBits & X86_FEATURE_PAE)
{
PaeModeSupported = TRUE;
}
}
if (PaeModeSupported)
{
PCHAR p;
/* Read Command Line */
p = (PCHAR)LoaderBlock.CommandLine;
while ((p = strchr(p, '/')) != NULL) {
p++;
/* Find "PAE" */
if (!_strnicmp(p, "PAE", 3)) {
/* Make sure there's nothing following it */
if (p[3] == ' ' || p[3] == 0) {
/* Use Pae */
PaeModeEnabled = TRUE;
break;
}
}
}
}
}
/*++ /*++
* FrLdrSetupPageDirectory * FrLdrSetupPageDirectory
* INTERNAL * INTERNAL
@ -344,192 +219,85 @@ FASTCALL
FrLdrSetupPageDirectory(VOID) FrLdrSetupPageDirectory(VOID)
{ {
PPAGE_DIRECTORY_X86 PageDir; PPAGE_DIRECTORY_X86 PageDir;
PPAGE_DIRECTORY_TABLE_X64 PageDirTablePae;
PPAGE_DIRECTORY_X64 PageDirPae;
ULONG KernelPageTableIndex; ULONG KernelPageTableIndex;
ULONG i; ULONG i;
if (PaeModeEnabled) { /* Get the Kernel Table Index */
KernelPageTableIndex = KernelBase >> PDE_SHIFT;
/* Get the Kernel Table Index */ /* Get the Startup Page Directory */
KernelPageTableIndex = (KernelBase >> 21); PageDir = (PPAGE_DIRECTORY_X86)&startup_pagedirectory;
/* Get the Startup Page Directory Table */ /* Set up the Low Memory PDE */
PageDirTablePae = (PPAGE_DIRECTORY_TABLE_X64)&startup_pagedirectorytable_pae; PageDir->Pde[LowMemPageTableIndex].Valid = 1;
PageDir->Pde[LowMemPageTableIndex].Write = 1;
PageDir->Pde[LowMemPageTableIndex].PageFrameNumber = PaPtrToPfn(lowmem_pagetable);
/* Get the Startup Page Directory */ /* Set up the Kernel PDEs */
PageDirPae = (PPAGE_DIRECTORY_X64)&startup_pagedirectory_pae; PageDir->Pde[KernelPageTableIndex].Valid = 1;
PageDir->Pde[KernelPageTableIndex].Write = 1;
PageDir->Pde[KernelPageTableIndex].PageFrameNumber = PaPtrToPfn(kernel_pagetable);
PageDir->Pde[KernelPageTableIndex + 1].Valid = 1;
PageDir->Pde[KernelPageTableIndex + 1].Write = 1;
PageDir->Pde[KernelPageTableIndex + 1].PageFrameNumber = PaPtrToPfn(kernel_pagetable + 4096);
/* Set the Startup page directory table */ /* Set up the Startup PDE */
for (i = 0; i < 4; i++) PageDir->Pde[StartupPageTableIndex].Valid = 1;
{ PageDir->Pde[StartupPageTableIndex].Write = 1;
PageDirTablePae->Pde[i].Valid = 1; PageDir->Pde[StartupPageTableIndex].PageFrameNumber = PaPtrToPfn(startup_pagedirectory);
PageDirTablePae->Pde[i].PageFrameNumber = PaPtrToPfn(startup_pagedirectory_pae) + i;
}
/* Set up the Low Memory PDE */ /* Set up the Hyperspace PDE */
for (i = 0; i < 2; i++) PageDir->Pde[HyperspacePageTableIndex].Valid = 1;
{ PageDir->Pde[HyperspacePageTableIndex].Write = 1;
PageDirPae->Pde[LowMemPageTableIndexPae + i].Valid = 1; PageDir->Pde[HyperspacePageTableIndex].PageFrameNumber = PaPtrToPfn(hyperspace_pagetable);
PageDirPae->Pde[LowMemPageTableIndexPae + i].Write = 1;
PageDirPae->Pde[LowMemPageTableIndexPae + i].PageFrameNumber = PaPtrToPfn(lowmem_pagetable_pae) + i;
}
/* Set up the Kernel PDEs */ /* Set up the Apic PDE */
for (i = 0; i < 3; i++) PageDir->Pde[ApicPageTableIndex].Valid = 1;
{ PageDir->Pde[ApicPageTableIndex].Write = 1;
PageDirPae->Pde[KernelPageTableIndex + i].Valid = 1; PageDir->Pde[ApicPageTableIndex].PageFrameNumber = PaPtrToPfn(apic_pagetable);
PageDirPae->Pde[KernelPageTableIndex + i].Write = 1;
PageDirPae->Pde[KernelPageTableIndex + i].PageFrameNumber = PaPtrToPfn(kernel_pagetable_pae) + i;
}
/* Set up the Startup PDE */ /* Set up the KPCR PDE */
for (i = 0; i < 4; i++) PageDir->Pde[KpcrPageTableIndex].Valid = 1;
{ PageDir->Pde[KpcrPageTableIndex].Write = 1;
PageDirPae->Pde[StartupPageTableIndexPae + i].Valid = 1; PageDir->Pde[KpcrPageTableIndex].PageFrameNumber = PaPtrToPfn(kpcr_pagetable);
PageDirPae->Pde[StartupPageTableIndexPae + i].Write = 1;
PageDirPae->Pde[StartupPageTableIndexPae + i].PageFrameNumber = PaPtrToPfn(startup_pagedirectory_pae) + i;
}
/* Set up the Hyperspace PDE */ /* Set up Low Memory PTEs */
for (i = 0; i < 2; i++) PageDir = (PPAGE_DIRECTORY_X86)&lowmem_pagetable;
{ for (i=0; i<1024; i++) {
PageDirPae->Pde[HyperspacePageTableIndexPae + i].Valid = 1;
PageDirPae->Pde[HyperspacePageTableIndexPae + i].Write = 1;
PageDirPae->Pde[HyperspacePageTableIndexPae + i].PageFrameNumber = PaPtrToPfn(hyperspace_pagetable_pae) + i;
}
/* Set up the Apic PDE */ PageDir->Pde[i].Valid = 1;
for (i = 0; i < 2; i++) PageDir->Pde[i].Write = 1;
{ PageDir->Pde[i].Owner = 1;
PageDirPae->Pde[ApicPageTableIndexPae + i].Valid = 1; PageDir->Pde[i].PageFrameNumber = PaToPfn(i * PAGE_SIZE);
PageDirPae->Pde[ApicPageTableIndexPae + i].Write = 1;
PageDirPae->Pde[ApicPageTableIndexPae + i].PageFrameNumber = PaPtrToPfn(apic_pagetable_pae) + i;
}
/* Set up the KPCR PDE */
PageDirPae->Pde[KpcrPageTableIndexPae].Valid = 1;
PageDirPae->Pde[KpcrPageTableIndexPae].Write = 1;
PageDirPae->Pde[KpcrPageTableIndexPae].PageFrameNumber = PaPtrToPfn(kpcr_pagetable_pae);
/* Set up Low Memory PTEs */
PageDirPae = (PPAGE_DIRECTORY_X64)&lowmem_pagetable_pae;
for (i=0; i<1024; i++) {
PageDirPae->Pde[i].Valid = 1;
PageDirPae->Pde[i].Write = 1;
PageDirPae->Pde[i].Owner = 1;
PageDirPae->Pde[i].PageFrameNumber = i;
}
/* Set up Kernel PTEs */
PageDirPae = (PPAGE_DIRECTORY_X64)&kernel_pagetable_pae;
for (i=0; i<1536; i++) {
PageDirPae->Pde[i].Valid = 1;
PageDirPae->Pde[i].Write = 1;
PageDirPae->Pde[i].PageFrameNumber = PaToPfn(KERNEL_BASE_PHYS) + i;
}
/* Set up APIC PTEs */
PageDirPae = (PPAGE_DIRECTORY_X64)&apic_pagetable_pae;
PageDirPae->Pde[0].Valid = 1;
PageDirPae->Pde[0].Write = 1;
PageDirPae->Pde[0].CacheDisable = 1;
PageDirPae->Pde[0].WriteThrough = 1;
PageDirPae->Pde[0].PageFrameNumber = PaToPfn(APIC_BASE);
PageDirPae->Pde[0x200].Valid = 1;
PageDirPae->Pde[0x200].Write = 1;
PageDirPae->Pde[0x200].CacheDisable = 1;
PageDirPae->Pde[0x200].WriteThrough = 1;
PageDirPae->Pde[0x200].PageFrameNumber = PaToPfn(APIC_BASE + KERNEL_BASE_PHYS);
/* Set up KPCR PTEs */
PageDirPae = (PPAGE_DIRECTORY_X64)&kpcr_pagetable_pae;
PageDirPae->Pde[0].Valid = 1;
PageDirPae->Pde[0].Write = 1;
PageDirPae->Pde[0].PageFrameNumber = 1;
} else {
/* Get the Kernel Table Index */
KernelPageTableIndex = KernelBase >> PDE_SHIFT;
/* Get the Startup Page Directory */
PageDir = (PPAGE_DIRECTORY_X86)&startup_pagedirectory;
/* Set up the Low Memory PDE */
PageDir->Pde[LowMemPageTableIndex].Valid = 1;
PageDir->Pde[LowMemPageTableIndex].Write = 1;
PageDir->Pde[LowMemPageTableIndex].PageFrameNumber = PaPtrToPfn(lowmem_pagetable);
/* Set up the Kernel PDEs */
PageDir->Pde[KernelPageTableIndex].Valid = 1;
PageDir->Pde[KernelPageTableIndex].Write = 1;
PageDir->Pde[KernelPageTableIndex].PageFrameNumber = PaPtrToPfn(kernel_pagetable);
PageDir->Pde[KernelPageTableIndex + 1].Valid = 1;
PageDir->Pde[KernelPageTableIndex + 1].Write = 1;
PageDir->Pde[KernelPageTableIndex + 1].PageFrameNumber = PaPtrToPfn(kernel_pagetable + 4096);
/* Set up the Startup PDE */
PageDir->Pde[StartupPageTableIndex].Valid = 1;
PageDir->Pde[StartupPageTableIndex].Write = 1;
PageDir->Pde[StartupPageTableIndex].PageFrameNumber = PaPtrToPfn(startup_pagedirectory);
/* Set up the Hyperspace PDE */
PageDir->Pde[HyperspacePageTableIndex].Valid = 1;
PageDir->Pde[HyperspacePageTableIndex].Write = 1;
PageDir->Pde[HyperspacePageTableIndex].PageFrameNumber = PaPtrToPfn(hyperspace_pagetable);
/* Set up the Apic PDE */
PageDir->Pde[ApicPageTableIndex].Valid = 1;
PageDir->Pde[ApicPageTableIndex].Write = 1;
PageDir->Pde[ApicPageTableIndex].PageFrameNumber = PaPtrToPfn(apic_pagetable);
/* Set up the KPCR PDE */
PageDir->Pde[KpcrPageTableIndex].Valid = 1;
PageDir->Pde[KpcrPageTableIndex].Write = 1;
PageDir->Pde[KpcrPageTableIndex].PageFrameNumber = PaPtrToPfn(kpcr_pagetable);
/* Set up Low Memory PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&lowmem_pagetable;
for (i=0; i<1024; i++) {
PageDir->Pde[i].Valid = 1;
PageDir->Pde[i].Write = 1;
PageDir->Pde[i].Owner = 1;
PageDir->Pde[i].PageFrameNumber = PaToPfn(i * PAGE_SIZE);
}
/* Set up Kernel PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&kernel_pagetable;
for (i=0; i<1536; i++) {
PageDir->Pde[i].Valid = 1;
PageDir->Pde[i].Write = 1;
PageDir->Pde[i].PageFrameNumber = PaToPfn(KERNEL_BASE_PHYS + i * PAGE_SIZE);
}
/* Set up APIC PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&apic_pagetable;
PageDir->Pde[0].Valid = 1;
PageDir->Pde[0].Write = 1;
PageDir->Pde[0].CacheDisable = 1;
PageDir->Pde[0].WriteThrough = 1;
PageDir->Pde[0].PageFrameNumber = PaToPfn(APIC_BASE);
PageDir->Pde[0x200].Valid = 1;
PageDir->Pde[0x200].Write = 1;
PageDir->Pde[0x200].CacheDisable = 1;
PageDir->Pde[0x200].WriteThrough = 1;
PageDir->Pde[0x200].PageFrameNumber = PaToPfn(APIC_BASE + KERNEL_BASE_PHYS);
/* Set up KPCR PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&kpcr_pagetable;
PageDir->Pde[0].Valid = 1;
PageDir->Pde[0].Write = 1;
PageDir->Pde[0].PageFrameNumber = 1;
} }
return;
/* Set up Kernel PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&kernel_pagetable;
for (i=0; i<1536; i++) {
PageDir->Pde[i].Valid = 1;
PageDir->Pde[i].Write = 1;
PageDir->Pde[i].PageFrameNumber = PaToPfn(KERNEL_BASE_PHYS + i * PAGE_SIZE);
}
/* Set up APIC PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&apic_pagetable;
PageDir->Pde[0].Valid = 1;
PageDir->Pde[0].Write = 1;
PageDir->Pde[0].CacheDisable = 1;
PageDir->Pde[0].WriteThrough = 1;
PageDir->Pde[0].PageFrameNumber = PaToPfn(APIC_BASE);
PageDir->Pde[0x200].Valid = 1;
PageDir->Pde[0x200].Write = 1;
PageDir->Pde[0x200].CacheDisable = 1;
PageDir->Pde[0x200].WriteThrough = 1;
PageDir->Pde[0x200].PageFrameNumber = PaToPfn(APIC_BASE + KERNEL_BASE_PHYS);
/* Set up KPCR PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&kpcr_pagetable;
PageDir->Pde[0].Valid = 1;
PageDir->Pde[0].Write = 1;
PageDir->Pde[0].PageFrameNumber = 1;
} }
PVOID PVOID
@ -723,10 +491,6 @@ LdrGetModuleObject(PCHAR ModuleName)
return NULL; return NULL;
} }
BOOLEAN
NTAPI
FrLdrLoadHal(PCHAR szFileName, INT nPos);
NTSTATUS NTSTATUS
NTAPI NTAPI
LdrPEGetOrLoadModule(IN PCHAR ModuleName, LdrPEGetOrLoadModule(IN PCHAR ModuleName,
@ -748,7 +512,7 @@ LdrPEGetOrLoadModule(IN PCHAR ModuleName,
!_stricmp(ImportedName, "bootvid.dll")) !_stricmp(ImportedName, "bootvid.dll"))
{ {
/* Load the HAL */ /* Load the HAL */
FrLdrLoadImage(ImportedName, 10); FrLdrLoadImage(ImportedName, 10, FALSE);
/* Return the new module */ /* Return the new module */
*ImportedModule = LdrGetModuleObject(ImportedName); *ImportedModule = LdrGetModuleObject(ImportedName);
@ -847,91 +611,11 @@ FrLdrReMapImage(IN PIMAGE_NT_HEADERS NtHeader,
} }
} }
/*++
* FrLdrMapKernel
* INTERNAL
*
* Maps the Kernel into memory, does PE Section Mapping, initalizes the
* uninitialized data sections, and relocates the image.
*
* Params:
* KernelImage - FILE Structure representing the ntoskrnl image file.
*
* Returns:
* TRUE if the Kernel was mapped.
*
* Remarks:
* None.
*
*--*/
BOOLEAN BOOLEAN
NTAPI NTAPI
FrLdrMapKernel(FILE *KernelImage) FrLdrMapImage(IN FILE *Image,
{ IN PCHAR Name,
PIMAGE_NT_HEADERS NtHeader; IN ULONG ImageType)
ULONG ImageSize;
PVOID LoadBase;
/* Set the virtual (image) and physical (load) addresses */
LoadBase = (PVOID)KERNEL_BASE_PHYS;
/* Load the first 1024 bytes of the kernel image so we can read the PE header */
if (!FsReadFile(KernelImage, 1024, NULL, LoadBase)) return FALSE;
/* Now read the MZ header to get the offset to the PE Header */
NtHeader = RtlImageNtHeader(LoadBase);
/* Get Kernel Base */
KernelBase = NtHeader->OptionalHeader.ImageBase;
FrLdrGetKernelBase();
/* Save Entrypoint */
KernelEntry = RaToPa(NtHeader->OptionalHeader.AddressOfEntryPoint);
/* Save the Image Size */
ImageSize = NtHeader->OptionalHeader.SizeOfImage;
/* Set the file pointer to zero */
FsSetFilePointer(KernelImage, 0);
/* Load the file image */
FsReadFile(KernelImage, ImageSize, NULL, LoadBase);
/* Map it */
FrLdrReMapImage(NtHeader, LoadBase);
/* Calculate Difference between Real Base and Compiled Base*/
LdrRelocateImageWithBias(LoadBase,
KernelBase - (ULONG_PTR)LoadBase,
"FreeLdr",
STATUS_SUCCESS,
STATUS_UNSUCCESSFUL,
STATUS_UNSUCCESSFUL);
/* Fill out Module Data Structure */
reactos_modules[0].ModStart = KernelBase;
reactos_modules[0].ModEnd = KernelBase + ImageSize;
strcpy(reactos_module_strings[0], "ntoskrnl.exe");
reactos_modules[0].String = (ULONG_PTR)reactos_module_strings[0];
LoaderBlock.ModsCount++;
/* Increase the next Load Base */
NextModuleBase = ROUND_UP(LoadBase + ImageSize, PAGE_SIZE);
/* Load the HAL now (name will be changed internally if needed) */
FrLdrLoadImage("hal.dll", 10);
/* Perform import fixups */
LdrPEFixupImports(LoadBase, "ntoskrnl.exe");
/* Return Success */
return TRUE;
}
BOOLEAN
NTAPI
FrLdrMapImage(IN FILE *HalImage,
IN PCHAR Name)
{ {
PIMAGE_NT_HEADERS NtHeader; PIMAGE_NT_HEADERS NtHeader;
PVOID ImageBase, LoadBase; PVOID ImageBase, LoadBase;
@ -940,10 +624,10 @@ FrLdrMapImage(IN FILE *HalImage,
/* Set the virtual (image) and physical (load) addresses */ /* Set the virtual (image) and physical (load) addresses */
LoadBase = (PVOID)NextModuleBase; LoadBase = (PVOID)NextModuleBase;
ImageBase = RVA(LoadBase , -KERNEL_BASE_PHYS + KSEG0_BASE); ImageBase = RVA(LoadBase , -KERNEL_BASE_PHYS + KSEG0_BASE);
/* Load the first 1024 bytes of the HAL image so we can read the PE header */ /* Load the first 1024 bytes of the HAL image so we can read the PE header */
if (!FsReadFile(HalImage, 1024, NULL, LoadBase)) return FALSE; if (!FsReadFile(Image, 1024, NULL, LoadBase)) return FALSE;
/* Now read the MZ header to get the offset to the PE Header */ /* Now read the MZ header to get the offset to the PE Header */
NtHeader = RtlImageNtHeader(LoadBase); NtHeader = RtlImageNtHeader(LoadBase);
@ -952,21 +636,22 @@ FrLdrMapImage(IN FILE *HalImage,
ImageSize = NtHeader->OptionalHeader.SizeOfImage; ImageSize = NtHeader->OptionalHeader.SizeOfImage;
/* Set the file pointer to zero */ /* Set the file pointer to zero */
FsSetFilePointer(HalImage, 0); FsSetFilePointer(Image, 0);
/* Load the file image */ /* Load the file image */
FsReadFile(HalImage, ImageSize, NULL, LoadBase); FsReadFile(Image, ImageSize, NULL, LoadBase);
/* Map it into virtual memory */ /* Map it into virtual memory */
FrLdrReMapImage(NtHeader, LoadBase); if (ImageType != 2) FrLdrReMapImage(NtHeader, LoadBase);
/* Calculate Difference between Real Base and Compiled Base*/ /* Calculate Difference between Real Base and Compiled Base*/
LdrRelocateImageWithBias(LoadBase, if (ImageType != 2) LdrRelocateImageWithBias(LoadBase,
(ULONG_PTR)ImageBase - (ULONG_PTR)LoadBase, (ULONG_PTR)ImageBase -
"FreeLdr", (ULONG_PTR)LoadBase,
STATUS_SUCCESS, "FreeLdr",
STATUS_UNSUCCESSFUL, STATUS_SUCCESS,
STATUS_UNSUCCESSFUL); STATUS_UNSUCCESSFUL,
STATUS_UNSUCCESSFUL);
/* Fill out Module Data Structure */ /* Fill out Module Data Structure */
reactos_modules[ImageId].ModStart = (ULONG_PTR)ImageBase; reactos_modules[ImageId].ModStart = (ULONG_PTR)ImageBase;
@ -978,9 +663,20 @@ FrLdrMapImage(IN FILE *HalImage,
/* Increase the next Load Base */ /* Increase the next Load Base */
NextModuleBase = ROUND_UP(NextModuleBase + ImageSize, PAGE_SIZE); NextModuleBase = ROUND_UP(NextModuleBase + ImageSize, PAGE_SIZE);
/* Perform import fixups */ /* Successful load! */
//DbgPrint("Fixing up: %s loaded at: %p\n", Name, ImageBase); //DbgPrint("Image: %s loaded at: %p\n", Name, ImageBase);
LdrPEFixupImports(LoadBase, Name);
/* Load HAL if this is the kernel */
if (ImageType == 1)
{
KernelBase = NtHeader->OptionalHeader.ImageBase;
KernelEntry = RaToPa(NtHeader->OptionalHeader.AddressOfEntryPoint);
FrLdrLoadImage("hal.dll", 10, FALSE);
LoaderBlock.KernelBase = KernelBase;
}
/* Perform import fixups */
if (ImageType != 2) LdrPEFixupImports(LoadBase, Name);
/* Return Success */ /* Return Success */
return TRUE; return TRUE;

View file

@ -38,65 +38,19 @@ CHAR szBootPath[255];
static CHAR szLoadingMsg[] = "Loading ReactOS..."; static CHAR szLoadingMsg[] = "Loading ReactOS...";
BOOLEAN FrLdrBootType; BOOLEAN FrLdrBootType;
static BOOLEAN
NTAPI
FrLdrLoadKernel(PCHAR szFileName,
INT nPos)
{
PFILE FilePointer;
PCHAR szShortName;
CHAR szBuffer[256];
/* Extract Kernel filename without path */
szShortName = strrchr(szFileName, '\\');
if (szShortName == NULL) {
/* No path, leave it alone */
szShortName = szFileName;
} else {
/* Skip the path */
szShortName = szShortName + 1;
}
/* Open the Kernel */
FilePointer = FsOpenFile(szFileName);
/* Make sure it worked */
if (FilePointer == NULL) {
/* Return failure on the short name */
strcpy(szBuffer, szShortName);
strcat(szBuffer, " not found.");
UiMessageBox(szBuffer);
return(FALSE);
}
/* Update the status bar with the current file */
strcpy(szBuffer, "Reading ");
strcat(szBuffer, szShortName);
UiDrawStatusText(szBuffer);
/* Do the actual loading */
FrLdrMapKernel(FilePointer);
/* Update Processbar and return success */
UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
return(TRUE);
}
BOOLEAN BOOLEAN
NTAPI NTAPI
FrLdrMapImage( FrLdrMapImage(
IN FILE *Image, IN FILE *Image,
IN PCHAR ShortName IN PCHAR ShortName,
IN ULONG ImageType
); );
BOOLEAN BOOLEAN
NTAPI NTAPI
FrLdrLoadImage(IN PCHAR szFileName, FrLdrLoadImage(IN PCHAR szFileName,
IN INT nPos) IN INT nPos,
IN ULONG ImageType)
{ {
PFILE FilePointer; PFILE FilePointer;
PCHAR szShortName; PCHAR szShortName;
@ -153,76 +107,13 @@ FrLdrLoadImage(IN PCHAR szFileName,
UiDrawStatusText(szBuffer); UiDrawStatusText(szBuffer);
/* Do the actual loading */ /* Do the actual loading */
FrLdrMapImage(FilePointer, szShortName); FrLdrMapImage(FilePointer, szShortName, ImageType);
/* Update Processbar and return success */ /* Update Processbar and return success */
if (!FrLdrBootType) UiDrawProgressBarCenter(nPos, 100, szLoadingMsg); if (!FrLdrBootType) UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
return TRUE; return TRUE;
} }
static VOID
FreeldrFreeMem(PVOID Area)
{
MmFreeMemory(Area);
}
static PVOID
FreeldrAllocMem(ULONG_PTR Size)
{
return MmAllocateMemory((ULONG) Size);
}
static BOOLEAN
FreeldrReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
{
ULONG BytesRead;
return FsReadFile((PFILE) FileContext, (ULONG) Size, &BytesRead, Buffer)
&& Size == BytesRead;
}
static BOOLEAN
FreeldrSeekFile(PVOID FileContext, ULONG_PTR Position)
{
FsSetFilePointer((PFILE) FileContext, (ULONG) Position);
return TRUE;
}
static BOOLEAN
LoadKernelSymbols(PCHAR szKernelName, int nPos)
{
static ROSSYM_CALLBACKS FreeldrCallbacks =
{
FreeldrAllocMem,
FreeldrFreeMem,
FreeldrReadFile,
FreeldrSeekFile
};
PFILE FilePointer;
PROSSYM_INFO RosSymInfo;
ULONG Size;
ULONG_PTR Base;
//return TRUE;
RosSymInit(&FreeldrCallbacks);
FilePointer = FsOpenFile(szKernelName);
if (FilePointer == NULL)
{
return FALSE;
}
if (! RosSymCreateFromFile(FilePointer, &RosSymInfo))
{
return FALSE;
}
Base = FrLdrCreateModule("NTOSKRNL.SYM");
Size = RosSymGetRawDataLength(RosSymInfo);
RosSymGetRawData(RosSymInfo, (PVOID)Base);
FrLdrCloseModule(Base, Size);
RosSymDelete(RosSymInfo);
return TRUE;
}
static BOOLEAN static BOOLEAN
FrLdrLoadNlsFile(PCSTR szFileName, FrLdrLoadNlsFile(PCSTR szFileName,
PCSTR szModuleName) PCSTR szModuleName)
@ -374,49 +265,6 @@ FrLdrLoadNlsFiles(PCHAR szSystemRoot,
return(TRUE); return(TRUE);
} }
static BOOLEAN
FrLdrLoadDriver(PCHAR szFileName,
INT nPos)
{
PFILE FilePointer;
CHAR value[256];
LPSTR p;
/* Open the Driver */
FilePointer = FsOpenFile(szFileName);
/* Make sure we did */
if (FilePointer == NULL) {
/* Fail if file wasn't opened */
strcpy(value, szFileName);
strcat(value, " not found.");
UiMessageBox(value);
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 */
FrLdrLoadModule(FilePointer, szFileName, NULL);
/* Update status and return */
UiDrawProgressBarCenter(nPos, 100, szLoadingMsg);
return(TRUE);
}
static VOID static VOID
FrLdrLoadBootDrivers(PCHAR szSystemRoot, FrLdrLoadBootDrivers(PCHAR szSystemRoot,
INT nPos) INT nPos)
@ -552,7 +400,7 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
/* Update the position if needed */ /* Update the position if needed */
if (nPos < 100) nPos += 5; if (nPos < 100) nPos += 5;
FrLdrLoadDriver(ImagePath, nPos); FrLdrLoadImage(ImagePath, nPos, 2);
} else { } else {
@ -621,7 +469,7 @@ FrLdrLoadBootDrivers(PCHAR szSystemRoot,
if (nPos < 100) nPos += 5; if (nPos < 100) nPos += 5;
FrLdrLoadDriver(ImagePath, nPos); FrLdrLoadImage(ImagePath, nPos, 2);
} else { } else {
@ -647,15 +495,12 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
CHAR SystemPath[255]; CHAR SystemPath[255];
CHAR szKernelName[255]; CHAR szKernelName[255];
CHAR szFileName[255]; CHAR szFileName[255];
UINT i;
CHAR MsgBuffer[256]; CHAR MsgBuffer[256];
ULONG SectionId; ULONG SectionId;
ULONG_PTR Base; ULONG_PTR Base;
ULONG Size; ULONG Size;
extern ULONG PageDirectoryStart;
extern ULONG PageDirectoryEnd;
extern BOOLEAN AcpiPresent; extern BOOLEAN AcpiPresent;
// //
@ -676,47 +521,36 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
/* /*
* Setup multiboot information structure * Setup multiboot information structure
*/ */
LoaderBlock.Flags = MB_FLAGS_BOOT_DEVICE | MB_FLAGS_COMMAND_LINE | MB_FLAGS_MODULE_INFO;
LoaderBlock.PageDirectoryStart = (ULONG)&PageDirectoryStart;
LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd;
LoaderBlock.BootDevice = 0xffffffff;
LoaderBlock.CommandLine = reactos_kernel_cmdline; LoaderBlock.CommandLine = reactos_kernel_cmdline;
LoaderBlock.ModsCount = 0; LoaderBlock.ModsCount = 0;
LoaderBlock.ModsAddr = reactos_modules; LoaderBlock.ModsAddr = reactos_modules;
LoaderBlock.DrivesAddr = reactos_arc_disk_info; LoaderBlock.DrivesAddr = reactos_arc_disk_info;
LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&reactos_memory_map, 32) * sizeof(memory_map_t); LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&reactos_memory_map, 32) * sizeof(memory_map_t);
if (LoaderBlock.MmapLength) if (LoaderBlock.MmapLength)
{ {
LoaderBlock.MmapAddr = (unsigned long)&reactos_memory_map; ULONG i;
LoaderBlock.Flags |= MB_FLAGS_MEM_INFO | MB_FLAGS_MMAP_INFO;
reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24 LoaderBlock.MmapAddr = (unsigned long)&reactos_memory_map;
DbgPrint((DPRINT_REACTOS, "memory map length: %d\n", LoaderBlock.MmapLength)); reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
DbgPrint((DPRINT_REACTOS, "dumping memory map:\n")); for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++)
for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++) {
{ if (BiosMemoryUsable == reactos_memory_map[i].type &&
if (BiosMemoryUsable == reactos_memory_map[i].type && 0 == reactos_memory_map[i].base_addr_low)
0 == reactos_memory_map[i].base_addr_low) {
{ LoaderBlock.MemLower = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024;
LoaderBlock.MemLower = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024; if (640 < LoaderBlock.MemLower)
if (640 < LoaderBlock.MemLower) {
{ LoaderBlock.MemLower = 640;
LoaderBlock.MemLower = 640; }
} }
} if (BiosMemoryUsable == reactos_memory_map[i].type &&
if (BiosMemoryUsable == reactos_memory_map[i].type && reactos_memory_map[i].base_addr_low <= 1024 * 1024 &&
reactos_memory_map[i].base_addr_low <= 1024 * 1024 && 1024 * 1024 <= reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low)
1024 * 1024 <= reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) {
{ LoaderBlock.MemHigher = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024 - 1024;
LoaderBlock.MemHigher = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024 - 1024; }
} }
DbgPrint((DPRINT_REACTOS, "start: %x\t size: %x\t type %d\n", }
reactos_memory_map[i].base_addr_low,
reactos_memory_map[i].length_low,
reactos_memory_map[i].type));
}
}
DbgPrint((DPRINT_REACTOS, "low_mem = %d\n", LoaderBlock.MemLower));
DbgPrint((DPRINT_REACTOS, "high_mem = %d\n", LoaderBlock.MemHigher));
/* /*
* Initialize the registry * Initialize the registry
@ -848,7 +682,7 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
} }
/* Load the kernel */ /* Load the kernel */
if (!FrLdrLoadKernel(szKernelName, 5)) return; if (!FrLdrLoadImage(szKernelName, 5, 1)) return;
/* /*
* Load the System hive from disk * Load the System hive from disk
@ -916,12 +750,6 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
} }
UiDrawProgressBarCenter(30, 100, szLoadingMsg); UiDrawProgressBarCenter(30, 100, szLoadingMsg);
/*
* Load kernel symbols
*/
LoadKernelSymbols(szKernelName, 30);
UiDrawProgressBarCenter(40, 100, szLoadingMsg);
/* /*
* Load boot drivers * Load boot drivers
*/ */

View file

@ -31,21 +31,13 @@ char szHalName[256];
#define USE_UI #define USE_UI
static BOOLEAN BOOLEAN
FreeldrReadFile(PVOID FileContext, PVOID Buffer, ULONG Size) NTAPI
{ FrLdrMapImage(
ULONG BytesRead; IN FILE *Image,
IN PCHAR ShortName,
return FsReadFile((PFILE) FileContext, (ULONG) Size, &BytesRead, Buffer) IN ULONG ImageType
&& Size == BytesRead; );
}
static BOOLEAN
FreeldrSeekFile(PVOID FileContext, ULONG_PTR Position)
{
FsSetFilePointer((PFILE) FileContext, (ULONG) Position);
return TRUE;
}
BOOLEAN BOOLEAN
NTAPI NTAPI
@ -86,67 +78,12 @@ static FrLdrLoadKernel(IN PCHAR szFileName,
UiDrawStatusText(szBuffer); UiDrawStatusText(szBuffer);
/* Do the actual loading */ /* Do the actual loading */
FrLdrMapKernel(FilePointer); FrLdrMapImage(FilePointer, szShortName, 1);
/* Update Processbar and return success */ /* Update Processbar and return success */
return TRUE; return TRUE;
} }
static BOOLEAN
LoadKernelSymbols(PCSTR szSourcePath, PCSTR szFileName)
{
static ROSSYM_CALLBACKS FreeldrCallbacks =
{
MmAllocateMemory,
MmFreeMemory,
FreeldrReadFile,
FreeldrSeekFile
};
CHAR szFullName[256];
PFILE FilePointer;
PROSSYM_INFO RosSymInfo;
ULONG Size;
ULONG_PTR Base;
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);
}
RosSymInit(&FreeldrCallbacks);
FilePointer = FsOpenFile(szFullName);
if (FilePointer && RosSymCreateFromFile(FilePointer, &RosSymInfo))
{
Base = FrLdrCreateModule("NTOSKRNL.SYM");
Size = RosSymGetRawDataLength(RosSymInfo);
RosSymGetRawData(RosSymInfo, (PVOID)Base);
FrLdrCloseModule(Base, Size);
RosSymDelete(RosSymInfo);
return TRUE;
}
return FALSE;
}
static BOOLEAN static BOOLEAN
LoadDriver(PCSTR szSourcePath, PCSTR szFileName) LoadDriver(PCSTR szSourcePath, PCSTR szFileName)
{ {
@ -206,7 +143,7 @@ LoadDriver(PCSTR szSourcePath, PCSTR szFileName)
#endif #endif
/* Load the driver */ /* Load the driver */
FrLdrLoadModule(FilePointer, szFileName, NULL); FrLdrMapImage(FilePointer, (LPSTR)szFileName, 2);
return(TRUE); return(TRUE);
} }
@ -282,60 +219,42 @@ VOID RunLoader(VOID)
ULONG Size; ULONG Size;
const char *SourcePath; const char *SourcePath;
const char *LoadOptions; const char *LoadOptions;
UINT i;
char szKernelName[256]; char szKernelName[256];
HINF InfHandle; HINF InfHandle;
ULONG ErrorLine; ULONG ErrorLine;
INFCONTEXT InfContext; INFCONTEXT InfContext;
extern ULONG PageDirectoryStart;
extern ULONG PageDirectoryEnd;
/* Setup multiboot information structure */ /* Setup multiboot information structure */
LoaderBlock.Flags = MB_FLAGS_BOOT_DEVICE | MB_FLAGS_COMMAND_LINE | MB_FLAGS_MODULE_INFO;
LoaderBlock.PageDirectoryStart = (ULONG)&PageDirectoryStart;
LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd;
LoaderBlock.BootDevice = 0xffffffff;
LoaderBlock.CommandLine = reactos_kernel_cmdline; LoaderBlock.CommandLine = reactos_kernel_cmdline;
LoaderBlock.ModsCount = 0; LoaderBlock.ModsCount = 0;
LoaderBlock.ModsAddr = reactos_modules; LoaderBlock.ModsAddr = reactos_modules;
LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&reactos_memory_map, 32) * sizeof(memory_map_t); LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&reactos_memory_map, 32) * sizeof(memory_map_t);
if (LoaderBlock.MmapLength) if (LoaderBlock.MmapLength)
{ {
ULONG i;
LoaderBlock.MmapAddr = (unsigned long)&reactos_memory_map; LoaderBlock.MmapAddr = (unsigned long)&reactos_memory_map;
LoaderBlock.Flags |= MB_FLAGS_MEM_INFO | MB_FLAGS_MMAP_INFO;
reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24 reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
for (i = 0; i < (LoaderBlock.MmapLength / sizeof(memory_map_t)); i++) for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++)
{ {
if (BiosMemoryUsable == reactos_memory_map[i].type && if (BiosMemoryUsable == reactos_memory_map[i].type &&
0 == reactos_memory_map[i].base_addr_low) 0 == reactos_memory_map[i].base_addr_low)
{ {
LoaderBlock.MemLower = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024; LoaderBlock.MemLower = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024;
if (640 < LoaderBlock.MemLower) if (640 < LoaderBlock.MemLower)
{ {
LoaderBlock.MemLower = 640; LoaderBlock.MemLower = 640;
} }
} }
if (BiosMemoryUsable == reactos_memory_map[i].type && if (BiosMemoryUsable == reactos_memory_map[i].type &&
reactos_memory_map[i].base_addr_low <= 1024 * 1024 && reactos_memory_map[i].base_addr_low <= 1024 * 1024 &&
1024 * 1024 <= reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) 1024 * 1024 <= reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low)
{ {
LoaderBlock.MemHigher = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024 - 1024; LoaderBlock.MemHigher = (reactos_memory_map[i].base_addr_low + reactos_memory_map[i].length_low) / 1024 - 1024;
} }
#if 0 }
printf("start: %x\t size: %x\t type %d\n", }
reactos_memory_map[i].base_addr_low,
reactos_memory_map[i].length_low,
reactos_memory_map[i].type);
#endif
}
}
#if 0
printf("low_mem = %d\n", LoaderBlock.MemLower);
printf("high_mem = %d\n", LoaderBlock.MemHigher);
MachConsGetCh();
#endif
#ifdef USE_UI #ifdef USE_UI
SetupUiInitialize(); SetupUiInitialize();
@ -431,9 +350,6 @@ VOID RunLoader(VOID)
/* Load the kernel */ /* Load the kernel */
if (!FrLdrLoadKernel(szKernelName, 5)) return; if (!FrLdrLoadKernel(szKernelName, 5)) return;
/* Create ntoskrnl.sym */
LoadKernelSymbols(SourcePath, "ntoskrnl.exe");
/* Export the hardware hive */ /* Export the hardware hive */
Base = FrLdrCreateModule ("HARDWARE"); Base = FrLdrCreateModule ("HARDWARE");
RegExportBinaryHive (L"\\Registry\\Machine\\HARDWARE", (PVOID)Base, &Size); RegExportBinaryHive (L"\\Registry\\Machine\\HARDWARE", (PVOID)Base, &Size);

View file

@ -805,17 +805,6 @@ IopAttachFilterDrivers(
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static VOID INIT_FUNCTION
MiFreeBootDriverMemory(PVOID StartAddress, ULONG Length)
{
ULONG i;
for (i = 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++)
{
MmDeleteVirtualMapping(NULL, (char*)StartAddress + i * PAGE_SIZE, TRUE, NULL, NULL);
}
}
/* /*
* IopInitializeBuiltinDriver * IopInitializeBuiltinDriver
* *
@ -1028,7 +1017,7 @@ IopInitializeBootDrivers(VOID)
} }
/* Loop modules again */ /* Loop modules again */
NextEntry = ListHead->Flink->Flink->Flink->Flink; NextEntry = ListHead->Flink;
while (ListHead != NextEntry) while (ListHead != NextEntry)
{ {
/* Get the entry */ /* Get the entry */
@ -1037,11 +1026,10 @@ IopInitializeBootDrivers(VOID)
InLoadOrderLinks); InLoadOrderLinks);
/* Free memory */ /* Free memory */
DPRINT("Freeing memory at: %p of size: %lx for module: %wZ\n", DPRINT("Driver at: %p ending at: %p for module: %wZ\n",
LdrEntry->DllBase, LdrEntry->DllBase,
LdrEntry->SizeOfImage, (ULONG_PTR)LdrEntry->DllBase+ LdrEntry->SizeOfImage,
&LdrEntry->FullDllName); &LdrEntry->FullDllName);
MiFreeBootDriverMemory(LdrEntry->DllBase, LdrEntry->SizeOfImage);
/* Go to the next driver */ /* Go to the next driver */
NextEntry = NextEntry->Flink; NextEntry = NextEntry->Flink;

View file

@ -98,6 +98,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
if (!_stricmp(DriverName, "ansi.nls")) if (!_stricmp(DriverName, "ansi.nls"))
{ {
/* ANSI Code page */ /* ANSI Code page */
ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
LoaderBlock->NlsData->AnsiCodePageData = ModStart; LoaderBlock->NlsData->AnsiCodePageData = ModStart;
/* Create an MD for it */ /* Create an MD for it */
@ -112,6 +113,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
else if (!_stricmp(DriverName, "oem.nls")) else if (!_stricmp(DriverName, "oem.nls"))
{ {
/* OEM Code page */ /* OEM Code page */
ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
LoaderBlock->NlsData->OemCodePageData = ModStart; LoaderBlock->NlsData->OemCodePageData = ModStart;
/* Create an MD for it */ /* Create an MD for it */
@ -126,6 +128,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
else if (!_stricmp(DriverName, "casemap.nls")) else if (!_stricmp(DriverName, "casemap.nls"))
{ {
/* Unicode Code page */ /* Unicode Code page */
ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
LoaderBlock->NlsData->UnicodeCodePageData = ModStart; LoaderBlock->NlsData->UnicodeCodePageData = ModStart;
/* Create an MD for it */ /* Create an MD for it */
@ -143,6 +146,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
!(_stricmp(DriverName, "system.hiv"))) !(_stricmp(DriverName, "system.hiv")))
{ {
/* Save registry data */ /* Save registry data */
ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
LoaderBlock->RegistryBase = ModStart; LoaderBlock->RegistryBase = ModStart;
LoaderBlock->RegistryLength = ModSize; LoaderBlock->RegistryLength = ModSize;
@ -164,6 +168,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock,
!(_stricmp(DriverName, "hardware.hiv"))) !(_stricmp(DriverName, "hardware.hiv")))
{ {
/* Create an MD for it */ /* Create an MD for it */
ModStart = (PVOID)((ULONG_PTR)ModStart + (KSEG0_BASE - 0x200000));
MdEntry = &BldrMemoryDescriptors[i]; MdEntry = &BldrMemoryDescriptors[i];
MdEntry->MemoryType = LoaderRegistryData; MdEntry->MemoryType = LoaderRegistryData;
MdEntry->BasePage = (ULONG_PTR)ModStart >> PAGE_SHIFT; MdEntry->BasePage = (ULONG_PTR)ModStart >> PAGE_SHIFT;
@ -315,7 +320,6 @@ FASTCALL
KiRosPrepareForSystemStartup(IN ULONG Dummy, KiRosPrepareForSystemStartup(IN ULONG Dummy,
IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock) IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock)
{ {
ULONG i;
PLOADER_PARAMETER_BLOCK NtLoaderBlock; PLOADER_PARAMETER_BLOCK NtLoaderBlock;
PKTSS Tss; PKTSS Tss;
PKGDTENTRY TssEntry; PKGDTENTRY TssEntry;
@ -337,25 +341,6 @@ KiRosPrepareForSystemStartup(IN ULONG Dummy,
/* Save pointer to ROS Block */ /* Save pointer to ROS Block */
KeRosLoaderBlock = LoaderBlock; KeRosLoaderBlock = LoaderBlock;
/* Save the Base Address */
MmSystemRangeStart = (PVOID)KeRosLoaderBlock->KernelBase;
/* Convert every driver address to virtual memory */
for (i = 3; i < KeRosLoaderBlock->ModsCount; i++)
{
/* Subtract the base Address in Physical Memory */
KeRosLoaderBlock->ModsAddr[i].ModStart -= 0x200000;
/* Add the Kernel Base Address in Virtual Memory */
KeRosLoaderBlock->ModsAddr[i].ModStart += KSEG0_BASE;
/* Subtract the base Address in Physical Memory */
KeRosLoaderBlock->ModsAddr[i].ModEnd -= 0x200000;
/* Add the Kernel Base Address in Virtual Memory */
KeRosLoaderBlock->ModsAddr[i].ModEnd += KSEG0_BASE;
}
/* Save memory manager data */ /* Save memory manager data */
MmFreeLdrLastKernelAddress = PAGE_ROUND_UP(KeRosLoaderBlock-> MmFreeLdrLastKernelAddress = PAGE_ROUND_UP(KeRosLoaderBlock->
ModsAddr[KeRosLoaderBlock-> ModsAddr[KeRosLoaderBlock->

View file

@ -350,6 +350,7 @@ MmInit1(ULONG_PTR FirstKrnlPhysAddr,
} }
/* Set memory limits */ /* Set memory limits */
MmSystemRangeStart = (PVOID)KSEG0_BASE;
MmUserProbeAddress = (ULONG_PTR)MmSystemRangeStart - 0x10000; MmUserProbeAddress = (ULONG_PTR)MmSystemRangeStart - 0x10000;
MmHighestUserAddress = (PVOID)(MmUserProbeAddress - 1); MmHighestUserAddress = (PVOID)(MmUserProbeAddress - 1);