[FREELDR]

- Massively refactor the winldr code
- move common parts of LoadReactOSSetup and LoadAndBootWindows into LoadAndBootWindowsCommon
- Combine architecture specific code into 2 functions: WinLdrSetupMachineDependent prepares the main stuff and WinLdrSetProcessorContext is the last thing done before transferring control to the kernel.
- rename WinLdrTunOnPaging to WinLdrSetupMemoryLayout
- Stop wasting stack space by decreasing the number of huge text buffers used
- Don't handle x86 specific data like Tss in portable code
- Add the progressbar for reactos setup as well
- Add missing DPRINT_PELOADER to DEBUG_ALL

svn path=/trunk/; revision=53510
This commit is contained in:
Timo Kreuzer 2011-08-31 13:47:25 +00:00
parent b93fdf2a65
commit 0c902fc496
11 changed files with 398 additions and 401 deletions

View file

@ -13,15 +13,20 @@ TitleBoxTextColor=White
TitleBoxColor=Red TitleBoxColor=Red
MessageBoxTextColor=White MessageBoxTextColor=White
MessageBoxColor=Blue MessageBoxColor=Blue
MenuTextColor=White MenuTextColor=Gray
MenuColor=Blue MenuColor=Black
TextColor=Yellow TextColor=Gray
SelectedTextColor=Black SelectedTextColor=Black
SelectedColor=Gray SelectedColor=Gray
ShowTime=No
MenuBox=No
CenterMenu=No
MinimalUI=Yes
TimeText=Seconds until highlighted choice will be started automatically:
[Operating Systems] [Operating Systems]
Setup="Setup" Setup="Setup"
[Setup] [Setup]
BootType=ReactOSSetup2 BootType=ReactOSSetup

View file

@ -22,6 +22,9 @@
PHARDWARE_PTE PxeBase; PHARDWARE_PTE PxeBase;
//PHARDWARE_PTE HalPageTable; //PHARDWARE_PTE HalPageTable;
PVOID GdtIdt;
ULONG PcrBasePage;
ULONG TssBasePage;
/* FUNCTIONS **************************************************************/ /* FUNCTIONS **************************************************************/
@ -43,8 +46,8 @@ MempAllocatePageTables()
/* Zero the PML4 */ /* Zero the PML4 */
RtlZeroMemory(PxeBase, PAGE_SIZE); RtlZeroMemory(PxeBase, PAGE_SIZE);
/* The page tables are located at 0xfffff68000000000 /* The page tables are located at 0xfffff68000000000
* We create a recursive self mapping through all 4 levels at * We create a recursive self mapping through all 4 levels at
* virtual address 0xfffff6fb7dbedf68 */ * virtual address 0xfffff6fb7dbedf68 */
PxeBase[VAtoPXI(PXE_BASE)].Valid = 1; PxeBase[VAtoPXI(PXE_BASE)].Valid = 1;
PxeBase[VAtoPXI(PXE_BASE)].Write = 1; PxeBase[VAtoPXI(PXE_BASE)].Write = 1;
@ -117,7 +120,7 @@ MempIsPageMapped(PVOID VirtualAddress)
{ {
PHARDWARE_PTE PpeBase, PdeBase, PteBase; PHARDWARE_PTE PpeBase, PdeBase, PteBase;
ULONG Index; ULONG Index;
Index = VAtoPXI(VirtualAddress); Index = VAtoPXI(VirtualAddress);
if (!PxeBase[Index].Valid) if (!PxeBase[Index].Valid)
return FALSE; return FALSE;
@ -161,7 +164,7 @@ BOOLEAN
MempSetupPaging(IN ULONG StartPage, MempSetupPaging(IN ULONG StartPage,
IN ULONG NumberOfPages) IN ULONG NumberOfPages)
{ {
DPRINTM(DPRINT_WINDOWS,">>> MempSetupPaging(0x%lx, %ld, %p)\n", DPRINTM(DPRINT_WINDOWS,">>> MempSetupPaging(0x%lx, %ld, %p)\n",
StartPage, NumberOfPages, StartPage * PAGE_SIZE + KSEG0_BASE); StartPage, NumberOfPages, StartPage * PAGE_SIZE + KSEG0_BASE);
/* Identity mapping */ /* Identity mapping */
@ -247,7 +250,7 @@ WinLdrMapSpecialPages(ULONG PcrBasePage)
} }
VOID VOID
WinLdrSetupGdt(PVOID GdtBase, ULONG64 TssBase) Amd64SetupGdt(PVOID GdtBase, ULONG64 TssBase)
{ {
PKGDTENTRY64 Entry; PKGDTENTRY64 Entry;
KDESCRIPTOR GdtDesc; KDESCRIPTOR GdtDesc;
@ -295,7 +298,7 @@ WinLdrSetupGdt(PVOID GdtBase, ULONG64 TssBase)
} }
VOID VOID
WinLdrSetupIdt(PVOID IdtBase) Amd64SetupIdt(PVOID IdtBase)
{ {
KDESCRIPTOR IdtDesc, OldIdt; KDESCRIPTOR IdtDesc, OldIdt;
@ -316,9 +319,9 @@ WinLdrSetupIdt(PVOID IdtBase)
} }
VOID VOID
WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG64 Pcr, IN ULONG64 Tss) WinLdrSetProcessorContext(void)
{ {
DPRINTM(DPRINT_WINDOWS, "WinLdrSetProcessorContext %p\n", Pcr); DPRINTM(DPRINT_WINDOWS, "WinLdrSetProcessorContext\n");
/* Disable Interrupts */ /* Disable Interrupts */
_disable(); _disable();
@ -333,10 +336,10 @@ WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG64 Pcr, IN ULONG64 Tss)
GdtIdt = (PVOID)((ULONG64)GdtIdt + KSEG0_BASE); GdtIdt = (PVOID)((ULONG64)GdtIdt + KSEG0_BASE);
/* Create gdt entries and load gdtr */ /* Create gdt entries and load gdtr */
WinLdrSetupGdt(GdtIdt, Tss); Amd64SetupGdt(GdtIdt, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
/* Copy old Idt and set idtr */ /* Copy old Idt and set idtr */
WinLdrSetupIdt((PVOID)((ULONG64)GdtIdt + 2048)); // HACK! Amd64SetupIdt((PVOID)((ULONG64)GdtIdt + 2048)); // HACK!
/* LDT is unused */ /* LDT is unused */
// __lldt(0); // __lldt(0);
@ -347,6 +350,59 @@ WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG64 Pcr, IN ULONG64 Tss)
DPRINTM(DPRINT_WINDOWS, "leave WinLdrSetProcessorContext\n"); DPRINTM(DPRINT_WINDOWS, "leave WinLdrSetProcessorContext\n");
} }
WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
{
ULONG TssSize;
ULONG_PTR KernelStack;
ULONG_PTR Pcr = 0;
ULONG_PTR Tss = 0;
ULONG BlockSize, NumPages;
LoaderBlock->u.I386.CommonDataArea = (PVOID)DbgPrint; // HACK
LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA;
/* Allocate 2 pages for PCR */
Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
PcrBasePage = Pcr >> MM_PAGE_SHIFT;
if (Pcr == 0)
{
UiMessageBox("Can't allocate PCR\n");
return;
}
RtlZeroMemory((PVOID)Pcr, 2 * MM_PAGE_SIZE);
/* Allocate a kernel stack */
Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
/* Allocate TSS */
BlockSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
Tss = (ULONG_PTR)MmAllocateMemoryWithType(BlockSize, LoaderMemoryData);
TssBasePage = Tss >> MM_PAGE_SHIFT;
/* Allocate space for new GDT + IDT */
BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here?
NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
*GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData);
if (*GdtIdt == NULL)
{
UiMessageBox("Can't allocate pages for GDT+IDT!\n");
return;
}
/* Zero newly prepared GDT+IDT */
RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT);
/* Write initial context information */
LoaderBlock->KernelStack = (ULONG_PTR)KernelStack;
LoaderBlock->KernelStack += KERNEL_STACK_SIZE;
LoaderBlock->Prcb = (ULONG_PTR)&Pcr->Prcb;
LoaderBlock->Process = (ULONG_PTR)PdrPage->InitialProcess;
LoaderBlock->Thread = (ULONG_PTR)PdrPage->InitialThread;
}
VOID VOID
MempDump() MempDump()
{ {

View file

@ -33,7 +33,7 @@ extern ULONG_PTR i386AlignmentCheck; // exc 17
#endif #endif
/* FUNCTIONS **************************************************************/ /* FUNCTIONS **************************************************************/
#if 0
// Last step before going virtual // Last step before going virtual
void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock, void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
PVOID *GdtIdt, PVOID *GdtIdt,
@ -81,3 +81,4 @@ void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
/* Zero newly prepared GDT+IDT */ /* Zero newly prepared GDT+IDT */
RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT); RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT);
} }
#endif

View file

@ -13,9 +13,6 @@
#include <ndk/asm.h> #include <ndk/asm.h>
#include <debug.h> #include <debug.h>
extern ULONG TotalNLSSize;
extern ULONG LoaderPagesSpanned;
// This is needed because headers define wrong one for ReactOS // This is needed because headers define wrong one for ReactOS
#undef KIP0PCRADDRESS #undef KIP0PCRADDRESS
#define KIP0PCRADDRESS 0xffdff000 #define KIP0PCRADDRESS 0xffdff000
@ -41,6 +38,10 @@ PUCHAR KernelPageTablesBuffer;
ULONG PhysicalPageTables; ULONG PhysicalPageTables;
ULONG KernelPageTables; ULONG KernelPageTables;
ULONG PcrBasePage;
ULONG TssBasePage;
PVOID GdtIdt;
/* FUNCTIONS **************************************************************/ /* FUNCTIONS **************************************************************/
BOOLEAN BOOLEAN
@ -244,7 +245,7 @@ WinLdrpMapApic()
} }
BOOLEAN BOOLEAN
WinLdrMapSpecialPages(ULONG PcrBasePage) WinLdrMapSpecialPages(void)
{ {
//VideoDisplayString(L"Hello from VGA, going into the kernel\n"); //VideoDisplayString(L"Hello from VGA, going into the kernel\n");
@ -270,16 +271,75 @@ WinLdrMapSpecialPages(ULONG PcrBasePage)
return TRUE; return TRUE;
} }
void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
{
ULONG TssSize;
//ULONG TssPages;
ULONG_PTR Pcr = 0;
ULONG_PTR Tss = 0;
ULONG BlockSize, NumPages;
LoaderBlock->u.I386.CommonDataArea = NULL; // Force No ABIOS support
LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA;
/* Allocate 2 pages for PCR */
Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage);
PcrBasePage = Pcr >> MM_PAGE_SHIFT;
if (Pcr == 0)
{
UiMessageBox("Can't allocate PCR\n");
return;
}
/* Allocate TSS */
TssSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
//TssPages = TssSize / MM_PAGE_SIZE;
Tss = (ULONG_PTR)MmAllocateMemoryWithType(TssSize, LoaderMemoryData);
TssBasePage = Tss >> MM_PAGE_SHIFT;
/* Allocate space for new GDT + IDT */
BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here?
NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData);
if (GdtIdt == NULL)
{
UiMessageBox("Can't allocate pages for GDT+IDT!\n");
return;
}
/* Zero newly prepared GDT+IDT */
RtlZeroMemory(GdtIdt, NumPages << MM_PAGE_SHIFT);
// Before we start mapping pages, create a block of memory, which will contain
// PDE and PTEs
if (MempAllocatePageTables() == FALSE)
{
// FIXME: bugcheck
}
/* Map stuff like PCR, KI_USER_SHARED_DATA and Apic */
WinLdrMapSpecialPages();
}
VOID VOID
WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss) WinLdrSetProcessorContext(void)
{ {
GDTIDT GdtDesc, IdtDesc, OldIdt; GDTIDT GdtDesc, IdtDesc, OldIdt;
PKGDTENTRY pGdt; PKGDTENTRY pGdt;
PKIDTENTRY pIdt; PKIDTENTRY pIdt;
USHORT Ldt = 0; USHORT Ldt = 0;
ULONG Pcr;
ULONG Tss;
//ULONG i; //ULONG i;
Pcr = KIP0PCRADDRESS;
Tss = KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT);
DPRINTM(DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n", DPRINTM(DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n",
GdtIdt, Pcr, Tss); GdtIdt, Pcr, Tss);

View file

@ -145,7 +145,7 @@ VOID RunLoader(VOID)
} }
TimeOut = GetTimeOut(); TimeOut = GetTimeOut();
if (!UiInitialize(TimeOut != 0)) if (!UiInitialize(1))
{ {
UiMessageBoxCritical("Unable to initialize UI."); UiMessageBoxCritical("Unable to initialize UI.");
return; return;
@ -238,7 +238,7 @@ VOID RunLoader(VOID)
#ifdef FREELDR_REACTOS_SETUP #ifdef FREELDR_REACTOS_SETUP
// WinLdr-style boot // WinLdr-style boot
LoadReactOSSetup2(); LoadReactOSSetup();
#elif defined(_M_IX86) #elif defined(_M_IX86)
if (_stricmp(BootType, "Windows") == 0) if (_stricmp(BootType, "Windows") == 0)
{ {

View file

@ -32,7 +32,7 @@
#if defined (DEBUG_ALL) #if defined (DEBUG_ALL)
ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM | ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM |
DPRINT_UI | DPRINT_DISK | DPRINT_CACHE | DPRINT_REACTOS | DPRINT_UI | DPRINT_DISK | DPRINT_CACHE | DPRINT_REACTOS |
DPRINT_LINUX | DPRINT_HWDETECT; DPRINT_LINUX | DPRINT_HWDETECT | DPRINT_PELOADER;
#elif defined (DEBUG_INIFILE) #elif defined (DEBUG_INIFILE)
ULONG DebugPrintMask = DPRINT_INIFILE; ULONG DebugPrintMask = DPRINT_INIFILE;
#elif defined (DEBUG_REACTOS) #elif defined (DEBUG_REACTOS)

View file

@ -121,8 +121,4 @@
VOID BootMain(LPSTR CmdLine); VOID BootMain(LPSTR CmdLine);
VOID RunLoader(VOID); VOID RunLoader(VOID);
/* Special hack for ReactOS setup OS type */
VOID LoadReactOSSetup(VOID);
VOID LoadReactOSSetup2(VOID);
#endif // defined __FREELDR_H #endif // defined __FREELDR_H

View file

@ -20,15 +20,6 @@
#pragma once #pragma once
///////////////////////////////////////////////////////////////////////////////////////
//
// ReactOS Loading Functions
//
///////////////////////////////////////////////////////////////////////////////////////
VOID LoadAndBootWindows(PCSTR OperatingSystemName,
PSTR SettingsValue,
USHORT OperatingSystemVersion);
/* Entry-point to kernel */ /* Entry-point to kernel */
typedef VOID (NTAPI *KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock); typedef VOID (NTAPI *KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock);
@ -40,6 +31,38 @@ typedef VOID (NTAPI *KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock);
#define NUM_GDT 128 // Must be 128 #define NUM_GDT 128 // Must be 128
#define NUM_IDT 0x100 // only 16 are used though. Must be 0x100 #define NUM_IDT 0x100 // only 16 are used though. Must be 0x100
/* FIXME: Should be moved to NDK, and respective ACPI header files */
typedef struct _ACPI_BIOS_DATA
{
PHYSICAL_ADDRESS RSDTAddress;
ULONGLONG Count;
BIOS_MEMORY_MAP MemoryMap[1]; /* Count of BIOS memory map entries */
} ACPI_BIOS_DATA, *PACPI_BIOS_DATA;
#include <pshpack1.h>
typedef struct /* Root System Descriptor Pointer */
{
CHAR signature [8]; /* contains "RSD PTR " */
UCHAR checksum; /* to make sum of struct == 0 */
CHAR oem_id [6]; /* OEM identification */
UCHAR revision; /* Must be 0 for 1.0, 2 for 2.0 */
ULONG rsdt_physical_address; /* 32-bit physical address of RSDT */
ULONG length; /* XSDT Length in bytes including hdr */
ULONGLONG xsdt_physical_address; /* 64-bit physical address of XSDT */
UCHAR extended_checksum; /* Checksum of entire table */
CHAR reserved [3]; /* reserved field must be 0 */
} RSDP_DESCRIPTOR, *PRSDP_DESCRIPTOR;
#include <poppack.h>
///////////////////////////////////////////////////////////////////////////////////////
//
// ReactOS Loading Functions
//
///////////////////////////////////////////////////////////////////////////////////////
VOID LoadAndBootWindows(PCSTR OperatingSystemName,
PSTR SettingsValue,
USHORT OperatingSystemVersion);
// conversion.c // conversion.c
PVOID VaToPa(PVOID Va); PVOID VaToPa(PVOID Va);
PVOID PaToVa(PVOID Pa); PVOID PaToVa(PVOID Pa);
@ -71,10 +94,7 @@ PVOID WinLdrLoadModule(PCSTR ModuleName, ULONG *Size,
// wlmemory.c // wlmemory.c
BOOLEAN BOOLEAN
WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock);
ULONG PcrBasePage,
ULONG TssBasePage,
PVOID GdtIdt);
// wlregistry.c // wlregistry.c
BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, BOOLEAN WinLdrInitSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
@ -84,25 +104,67 @@ BOOLEAN WinLdrScanSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
IN LPCSTR DirectoryPath); IN LPCSTR DirectoryPath);
/* FIXME: Should be moved to NDK, and respective ACPI header files */ BOOLEAN
typedef struct _ACPI_BIOS_DATA WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
{ IN PCH DllName,
PHYSICAL_ADDRESS RSDTAddress; OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry);
ULONGLONG Count;
BIOS_MEMORY_MAP MemoryMap[1]; /* Count of BIOS memory map entries */ BOOLEAN
} ACPI_BIOS_DATA, *PACPI_BIOS_DATA; WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, LPSTR BootPath);
VOID
WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
LPCSTR Options,
LPCSTR SystemPath,
LPCSTR BootPath,
USHORT VersionToBoot);
BOOLEAN
WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
IN LPCSTR DirectoryPath,
IN LPCSTR AnsiFileName,
IN LPCSTR OemFileName,
IN LPCSTR LanguageFileName);
BOOLEAN
WinLdrAddDriverToList(LIST_ENTRY *BootDriverListHead,
LPWSTR RegistryPath,
LPWSTR ImagePath,
LPWSTR ServiceName);
VOID
WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID
WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID
WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock);
BOOLEAN
MempAllocatePageTables();
BOOLEAN
MempSetupPaging(IN ULONG StartPage,
IN ULONG NumberOfPages);
VOID
MempUnmapPage(ULONG Page);
VOID
MempDump();
VOID
LoadAndBootWindowsCommon(
USHORT OperatingSystemVersion,
PLOADER_PARAMETER_BLOCK LoaderBlock,
LPCSTR BootOptions,
LPCSTR BootPath,
BOOLEAN Setup);
VOID LoadReactOSSetup(VOID);
VOID
WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID
WinLdrSetProcessorContext(VOID);
#include <pshpack1.h>
typedef struct /* Root System Descriptor Pointer */
{
CHAR signature [8]; /* contains "RSD PTR " */
UCHAR checksum; /* to make sum of struct == 0 */
CHAR oem_id [6]; /* OEM identification */
UCHAR revision; /* Must be 0 for 1.0, 2 for 2.0 */
ULONG rsdt_physical_address; /* 32-bit physical address of RSDT */
ULONG length; /* XSDT Length in bytes including hdr */
ULONGLONG xsdt_physical_address; /* 64-bit physical address of XSDT */
UCHAR extended_checksum; /* Checksum of entire table */
CHAR reserved [3]; /* reserved field must be 0 */
} RSDP_DESCRIPTOR, *PRSDP_DESCRIPTOR;
#include <poppack.h>

View file

@ -25,31 +25,14 @@
#include <debug.h> #include <debug.h>
void
WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID
WinLdrSetProcessorContext(void);
// TODO: Move to .h // TODO: Move to .h
VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock); VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock);
BOOLEAN WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, LPSTR BootPath);
void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
PVOID *GdtIdt,
ULONG *PcrBasePage,
ULONG *TssBasePage);
VOID
WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
PCHAR Options,
PCHAR SystemPath,
PCHAR BootPath,
USHORT VersionToBoot);
BOOLEAN
WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
IN LPCSTR DirectoryPath,
IN LPCSTR AnsiFileName,
IN LPCSTR OemFileName,
IN LPCSTR LanguageFileName);
BOOLEAN
WinLdrAddDriverToList(LIST_ENTRY *BootDriverListHead,
LPWSTR RegistryPath,
LPWSTR ImagePath,
LPWSTR ServiceName);
//FIXME: Do a better way to retrieve Arc disk information //FIXME: Do a better way to retrieve Arc disk information
extern ULONG reactos_disk_count; extern ULONG reactos_disk_count;
@ -157,72 +140,59 @@ SetupLdrScanBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPC
} while (InfFindNextLine(&InfContext, &InfContext)); } while (InfFindNextLine(&InfContext, &InfContext));
} }
VOID LoadReactOSSetup2(VOID) VOID LoadReactOSSetup(VOID)
{ {
CHAR SystemPath[512], SearchPath[512]; CHAR FileName[512];
CHAR FileName[512]; CHAR BootPath[512];
CHAR BootPath[512];
LPCSTR LoadOptions, BootOptions; LPCSTR LoadOptions, BootOptions;
BOOLEAN BootFromFloppy; BOOLEAN BootFromFloppy;
#if DBG
LPCSTR DbgOptions;
#endif
PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
BOOLEAN Status;
ULONG i, ErrorLine; ULONG i, ErrorLine;
HINF InfHandle; HINF InfHandle;
INFCONTEXT InfContext; INFCONTEXT InfContext;
PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA; PLOADER_PARAMETER_BLOCK LoaderBlock;
PSETUP_LOADER_BLOCK SetupBlock; PSETUP_LOADER_BLOCK SetupBlock;
KERNEL_ENTRY_POINT KiSystemStartup; LPCSTR SystemPath;
PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
// Mm-related things
PVOID GdtIdt;
ULONG PcrBasePage=0;
ULONG TssBasePage=0;
LPCSTR SourcePath;
LPCSTR SourcePaths[] = LPCSTR SourcePaths[] =
{ {
"", /* Only for floppy boot */ "\\", /* Only for floppy boot */
#if defined(_M_IX86) #if defined(_M_IX86)
"\\I386", "\\I386\\",
#elif defined(_M_MPPC) #elif defined(_M_MPPC)
"\\PPC", "\\PPC\\",
#elif defined(_M_MRX000) #elif defined(_M_MRX000)
"\\MIPS", "\\MIPS\\",
#endif #endif
"\\reactos", "\\reactos\\",
NULL NULL
}; };
/* Get boot path */ /* Get boot path */
MachDiskGetBootPath(SystemPath, sizeof(SystemPath)); MachDiskGetBootPath(BootPath, sizeof(BootPath));
/* And check if we booted from floppy */ /* And check if we booted from floppy */
BootFromFloppy = strstr(SystemPath, "fdisk") != NULL; BootFromFloppy = strstr(BootPath, "fdisk") != NULL;
/* Open 'txtsetup.sif' from any of source paths */ /* Open 'txtsetup.sif' from any of source paths */
for (i = BootFromFloppy ? 0 : 1; ; i++) for (i = BootFromFloppy ? 0 : 1; ; i++)
{ {
SourcePath = SourcePaths[i]; SystemPath = SourcePaths[i];
if (!SourcePath) if (!SystemPath)
{ {
printf("Failed to open 'txtsetup.sif'\n"); printf("Failed to open 'txtsetup.sif'\n");
return; return;
} }
sprintf(FileName, "%s\\txtsetup.sif", SourcePath); sprintf(FileName, "%stxtsetup.sif", SystemPath);
if (InfOpenFile (&InfHandle, FileName, &ErrorLine)) if (InfOpenFile (&InfHandle, FileName, &ErrorLine))
{ {
sprintf(BootPath, "%s%s\\", SystemPath, SourcePath); strcat(BootPath, SystemPath);
break; break;
} }
} }
DPRINTM(DPRINT_WINDOWS,"BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
/* Get Load options - debug and non-debug */ /* Get Load options - debug and non-debug */
if (!InfFindFirstLine(InfHandle, if (!InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext))
"SetupData",
"OsLoadOptions",
&InfContext))
{ {
printf("Failed to find 'SetupData/OsLoadOptions'\n"); printf("Failed to find 'SetupData/OsLoadOptions'\n");
return; return;
@ -238,31 +208,17 @@ VOID LoadReactOSSetup2(VOID)
#if DBG #if DBG
/* Get debug load options and use them */ /* Get debug load options and use them */
if (InfFindFirstLine(InfHandle, if (InfFindFirstLine(InfHandle, "SetupData", "DbgOsLoadOptions", &InfContext))
"SetupData",
"DbgOsLoadOptions",
&InfContext))
{ {
if (!InfGetDataField(&InfContext, 1, &DbgOptions)) if (InfGetDataField(&InfContext, 1, &LoadOptions))
DbgOptions = ""; BootOptions = LoadOptions;
else
BootOptions = DbgOptions;
} }
#endif #endif
DPRINTM(DPRINT_WINDOWS,"BootOptions: '%s'\n", BootOptions); DPRINTM(DPRINT_WINDOWS,"BootOptions: '%s'\n", BootOptions);
SetupUiInitialize(); //SetupUiInitialize();
UiDrawStatusText(""); UiDrawStatusText("");
UiDrawStatusText("Detecting Hardware...");
/* Let user know we started loading */
UiDrawStatusText("Loading...");
/* Construct the system path */
sprintf(SystemPath, "%s\\", SourcePath);
DPRINTM(DPRINT_WINDOWS,"BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
/* Allocate and minimalistic-initialize LPB */ /* Allocate and minimalistic-initialize LPB */
AllocateAndInitLPB(&LoaderBlock); AllocateAndInitLPB(&LoaderBlock);
@ -275,99 +231,18 @@ VOID LoadReactOSSetup2(VOID)
/* Set textmode setup flag */ /* Set textmode setup flag */
SetupBlock->Flags = SETUPLDR_TEXT_MODE; SetupBlock->Flags = SETUPLDR_TEXT_MODE;
/* Detect hardware */
UseRealHeap = TRUE;
LoaderBlock->ConfigurationRoot = MachHwDetect();
strcpy(FileName, "\\ArcName\\");
/* Load kernel */
strcpy(FileName+strlen("\\ArcName\\"), BootPath);
strcat(FileName, "SYSTEM32\\NTOSKRNL.EXE");
Status = WinLdrLoadImage(FileName+strlen("\\ArcName\\"), LoaderSystemCode, &NtosBase);
DPRINTM(DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase);
Status = WinLdrAllocateDataTableEntry(LoaderBlock, "ntoskrnl.exe",
FileName, NtosBase, &KernelDTE);
DPRINTM(DPRINT_WINDOWS, "Ntos Data Table Entry allocated with status %d at %p\n", Status, KernelDTE);
/* Load HAL */
strcpy(FileName+strlen("\\ArcName\\"), BootPath);
strcat(FileName, "SYSTEM32\\HAL.DLL");
Status = WinLdrLoadImage(FileName+strlen("\\ArcName\\"), LoaderHalCode, &HalBase);
DPRINTM(DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase);
Status = WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll",
FileName, HalBase, &HalDTE);
DPRINTM(DPRINT_WINDOWS, "HAL Data Table Entry allocated with status %d at %p\n", Status, HalDTE);
/* Load kernel-debugger support dll */
strcpy(FileName+strlen("\\ArcName\\"), BootPath);
strcat(FileName, "SYSTEM32\\KDCOM.DLL");
Status = WinLdrLoadImage(FileName+strlen("\\ArcName\\"), LoaderBootDriver, &KdComBase);
DPRINTM(DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase);
Status = WinLdrAllocateDataTableEntry(LoaderBlock, "kdcom.dll",
FileName, KdComBase, &KdComDTE);
DPRINTM(DPRINT_WINDOWS, "KdCom Data Table Entry allocated with status %d at %p\n", Status, HalDTE);
/* Load all referenced DLLs for kernel, HAL and kdcom.dll */
strcpy(SearchPath, BootPath);
strcat(SearchPath, "system32\\");
Status = WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KernelDTE);
Status &= WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, HalDTE);
if (KdComDTE)
Status &= WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KdComDTE);
if (!Status)
{
UiMessageBox("Error loading imported dll.");
return;
}
/* Load NLS data, they are in system32 */ /* Load NLS data, they are in system32 */
SetupLdrLoadNlsData(LoaderBlock, InfHandle, SearchPath); strcpy(FileName, BootPath);
strcat(FileName, "system32\\");
SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName);
/* Get a list of boot drivers */ /* Get a list of boot drivers */
SetupLdrScanBootDrivers(LoaderBlock, InfHandle, BootPath); SetupLdrScanBootDrivers(LoaderBlock, InfHandle, BootPath);
/* Load boot drivers */
Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
DPRINTM(DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status);
/* Alloc PCR, TSS, do magic things with the GDT/IDT */ LoadAndBootWindowsCommon(_WIN32_WINNT_WS03,
WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage); LoaderBlock,
BootOptions,
/* Initialize Phase 1 - no drivers loading anymore */ BootPath,
WinLdrInitializePhase1(LoaderBlock, (PCHAR)BootOptions, SystemPath, BootPath, _WIN32_WINNT_WS03); 1);
/* Save entry-point pointer and Loader block VAs */
KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;
LoaderBlockVA = PaToVa(LoaderBlock);
/* "Stop all motors", change videomode */
MachPrepareForReactOS(TRUE);
/* Debugging... */
//DumpMemoryAllocMap();
/* Turn on paging mode of CPU*/
WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt);
/* Save final value of LoaderPagesSpanned */
LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
KiSystemStartup, LoaderBlockVA);
//WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
//WinLdrpDumpBootDriver(LoaderBlockVA);
//WinLdrpDumpArcDisks(LoaderBlockVA);
/*asm(".intel_syntax noprefix\n");
asm("test1:\n");
asm("jmp test1\n");
asm(".att_syntax\n");*/
/* Pass control */
(*KiSystemStartup)(LoaderBlockVA);
return;
} }

View file

@ -24,12 +24,6 @@
#include <ndk/ldrtypes.h> #include <ndk/ldrtypes.h>
#include <debug.h> #include <debug.h>
// TODO: Move to .h
void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
PVOID *GdtIdt,
ULONG *PcrBasePage,
ULONG *TssBasePage);
//FIXME: Do a better way to retrieve Arc disk information //FIXME: Do a better way to retrieve Arc disk information
extern ULONG reactos_disk_count; extern ULONG reactos_disk_count;
extern ARC_DISK_SIGNATURE reactos_arc_disk_info[]; extern ARC_DISK_SIGNATURE reactos_arc_disk_info[];
@ -43,17 +37,8 @@ extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation;
extern BOOLEAN WinLdrTerminalConnected; extern BOOLEAN WinLdrTerminalConnected;
extern void WinLdrSetupEms(IN PCHAR BootOptions); extern void WinLdrSetupEms(IN PCHAR BootOptions);
BOOLEAN
WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
IN PCH DllName,
OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry);
// debug stuff // debug stuff
VOID DumpMemoryAllocMap(VOID); VOID DumpMemoryAllocMap(VOID);
VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock);
// Init "phase 0" // Init "phase 0"
VOID VOID
@ -85,9 +70,9 @@ AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
// Init "phase 1" // Init "phase 1"
VOID VOID
WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
PCHAR Options, LPCSTR Options,
PCHAR SystemRoot, LPCSTR SystemRoot,
PCHAR BootPath, LPCSTR BootPath,
USHORT VersionToBoot) USHORT VersionToBoot)
{ {
/* Examples of correct options and paths */ /* Examples of correct options and paths */
@ -435,6 +420,38 @@ WinLdrDetectVersion()
return _WIN32_WINNT_WS03; return _WIN32_WINNT_WS03;
} }
PVOID
LoadModule(
PLOADER_PARAMETER_BLOCK LoaderBlock,
PCCH Path,
PCCH File,
PLDR_DATA_TABLE_ENTRY *Dte,
ULONG Percentage)
{
CHAR FullFileName[MAX_PATH];
CHAR ProgressString[256];
NTSTATUS Status;
PVOID BaseAdress;
UiDrawBackdrop();
sprintf(ProgressString, "Loading %s...", File);
UiDrawProgressBarCenter(Percentage, 100, ProgressString);
strcpy(FullFileName, Path);
strcat(FullFileName, "SYSTEM32\\");
strcat(FullFileName, File);
Status = WinLdrLoadImage(FullFileName, LoaderSystemCode, &BaseAdress);
DPRINTM(DPRINT_WINDOWS, "%s loaded with status %d at %p\n",
File, Status, BaseAdress);
strcpy(FullFileName, "WINDOWS\\SYSTEM32\\");
strcat(FullFileName, File);
WinLdrAllocateDataTableEntry(LoaderBlock, File,
FullFileName, BaseAdress, Dte);
return BaseAdress;
}
VOID VOID
LoadAndBootWindows(PCSTR OperatingSystemName, LoadAndBootWindows(PCSTR OperatingSystemName,
@ -442,51 +459,39 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
USHORT OperatingSystemVersion) USHORT OperatingSystemVersion)
{ {
BOOLEAN HasSection; BOOLEAN HasSection;
char FullPath[MAX_PATH], SystemRoot[MAX_PATH], BootPath[MAX_PATH]; char BootPath[MAX_PATH];
CHAR FileName[MAX_PATH]; CHAR FileName[MAX_PATH];
CHAR BootOptions[256]; CHAR BootOptions[256];
PCHAR File; PCHAR File;
PCHAR PathSeparator;
PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
BOOLEAN Status; BOOLEAN Status;
ULONG_PTR SectionId; ULONG_PTR SectionId;
PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA; PLOADER_PARAMETER_BLOCK LoaderBlock;
KERNEL_ENTRY_POINT KiSystemStartup;
PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
// Mm-related things
PVOID GdtIdt;
ULONG PcrBasePage=0;
ULONG TssBasePage=0;
// Progress bar
CHAR ProgressString[256];
// Open the operating system section // Open the operating system section
// specified in the .ini file // specified in the .ini file
HasSection = IniOpenSection(OperatingSystemName, &SectionId); HasSection = IniOpenSection(OperatingSystemName, &SectionId);
UiDrawBackdrop(); UiDrawBackdrop();
UiDrawStatusText("Detecting Hardware..."); UiDrawProgressBarCenter(1, 100, "Loading NT...");
sprintf(ProgressString, "Loading NT...");
UiDrawProgressBarCenter(1, 100, ProgressString);
/* Read the system path is set in the .ini file */ /* Read the system path is set in the .ini file */
if (!HasSection || !IniReadSettingByName(SectionId, "SystemPath", FullPath, sizeof(FullPath))) if (!HasSection ||
!IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
{ {
strcpy(FullPath, OperatingSystemName); strcpy(BootPath, OperatingSystemName);
} }
/* Special case for LiveCD */ /* Special case for LiveCD */
if (!_strnicmp(FullPath, "LiveCD", strlen("LiveCD"))) if (!_strnicmp(BootPath, "LiveCD", strlen("LiveCD")))
{ {
strcpy(BootPath, FullPath + strlen("LiveCD")); strcpy(FileName, BootPath + strlen("LiveCD"));
MachDiskGetBootPath(FullPath, sizeof(FullPath)); MachDiskGetBootPath(BootPath, sizeof(BootPath));
strcat(FullPath, BootPath); strcat(BootPath, FileName);
} }
/* Convert FullPath to SystemRoot */ /* append a backslash */
PathSeparator = strstr(FullPath, "\\"); if ((strlen(BootPath)==0) || BootPath[strlen(BootPath)] != '\\')
strcpy(SystemRoot, PathSeparator); strcat(BootPath, "\\");
strcat(SystemRoot, "\\");
/* Read booting options */ /* Read booting options */
if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions))) if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions)))
@ -504,37 +509,23 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
/* Append boot-time options */ /* Append boot-time options */
AppendBootTimeOptions(BootOptions); AppendBootTimeOptions(BootOptions);
// /* Check if a ramdisk file was given */
// Check if a ramdisk file was given
//
File = strstr(BootOptions, "/RDPATH="); File = strstr(BootOptions, "/RDPATH=");
if (File) if (File)
{ {
// /* Copy the file name and everything else after it */
// Copy the file name and everything else after it
//
strcpy(FileName, File + 8); strcpy(FileName, File + 8);
// /* Null-terminate */
// Null-terminate
//
*strstr(FileName, " ") = ANSI_NULL; *strstr(FileName, " ") = ANSI_NULL;
// /* Load the ramdisk */
// Load the ramdisk
//
RamDiskLoadVirtualFile(FileName); RamDiskLoadVirtualFile(FileName);
} }
/* Let user know we started loading */ /* Let user know we started loading */
//UiDrawStatusText("Loading..."); //UiDrawStatusText("Loading...");
/* append a backslash */
strcpy(BootPath, FullPath);
if ((strlen(BootPath)==0) ||
BootPath[strlen(BootPath)] != '\\')
strcat(BootPath, "\\");
DPRINTM(DPRINT_WINDOWS,"BootPath: '%s'\n", BootPath); DPRINTM(DPRINT_WINDOWS,"BootPath: '%s'\n", BootPath);
/* Allocate and minimalistic-initialize LPB */ /* Allocate and minimalistic-initialize LPB */
@ -544,87 +535,83 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
/* Setup redirection support */ /* Setup redirection support */
WinLdrSetupEms(BootOptions); WinLdrSetupEms(BootOptions);
#endif #endif
/* Load Hive */
UiDrawBackdrop();
UiDrawProgressBarCenter(15, 100, "Loading system hive...");
Status = WinLdrInitSystemHive(LoaderBlock, BootPath);
DPRINTM(DPRINT_WINDOWS, "SYSTEM hive loaded with status %d\n", Status);
/* Load NLS data, OEM font, and prepare boot drivers list */
Status = WinLdrScanSystemHive(LoaderBlock, BootPath);
DPRINTM(DPRINT_WINDOWS, "SYSTEM hive scanned with status %d\n", Status);
LoadAndBootWindowsCommon(OperatingSystemVersion,
LoaderBlock,
BootOptions,
BootPath,
0);
}
VOID
LoadAndBootWindowsCommon(
USHORT OperatingSystemVersion,
PLOADER_PARAMETER_BLOCK LoaderBlock,
LPCSTR BootOptions,
LPCSTR BootPath,
BOOLEAN Setup)
{
PLOADER_PARAMETER_BLOCK LoaderBlockVA;
BOOLEAN Status;
CHAR FileName[MAX_PATH];
PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
KERNEL_ENTRY_POINT KiSystemStartup;
LPCSTR SystemRoot;
/* Convert BootPath to SystemRoot */
SystemRoot = strstr(BootPath, "\\");
/* Detect hardware */ /* Detect hardware */
UseRealHeap = TRUE; UseRealHeap = TRUE;
LoaderBlock->ConfigurationRoot = MachHwDetect(); LoaderBlock->ConfigurationRoot = MachHwDetect();
sprintf(ProgressString, "Loading system hive...");
UiDrawBackdrop();
UiDrawProgressBarCenter(15, 100, ProgressString);
/* Load Hive */
Status = WinLdrInitSystemHive(LoaderBlock, BootPath);
DPRINTM(DPRINT_WINDOWS, "SYSTEM hive loaded with status %d\n", Status);
if (OperatingSystemVersion == 0) if (OperatingSystemVersion == 0)
OperatingSystemVersion = WinLdrDetectVersion(); OperatingSystemVersion = WinLdrDetectVersion();
/* Load kernel */ /* Load kernel */
strcpy(FileName, BootPath); NtosBase = LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", &KernelDTE, 30);
strcat(FileName, "SYSTEM32\\NTOSKRNL.EXE");
sprintf(ProgressString, "Loading %s...", strchr(FileName, '\\') + 1);
UiDrawBackdrop();
UiDrawProgressBarCenter(30, 100, ProgressString);
Status = WinLdrLoadImage(FileName, LoaderSystemCode, &NtosBase);
DPRINTM(DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase);
/* Load HAL */ /* Load HAL */
strcpy(FileName, BootPath); HalBase = LoadModule(LoaderBlock, BootPath, "HAL.DLL", &HalDTE, 45);
strcat(FileName, "SYSTEM32\\HAL.DLL");
sprintf(ProgressString, "Loading %s...", strchr(FileName, '\\') + 1);
UiDrawBackdrop();
UiDrawProgressBarCenter(45, 100, ProgressString);
Status = WinLdrLoadImage(FileName, LoaderHalCode, &HalBase);
DPRINTM(DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase);
/* Load kernel-debugger support dll */ /* Load kernel-debugger support dll */
if (OperatingSystemVersion > _WIN32_WINNT_WIN2K) if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
{ {
strcpy(FileName, BootPath); KdComBase = LoadModule(LoaderBlock, BootPath, "KDCOM.DLL", &KdComDTE, 60);
strcat(FileName, "SYSTEM32\\KDCOM.DLL");
sprintf(ProgressString, "Loading %s...", strchr(FileName, '\\') + 1);
UiDrawBackdrop();
UiDrawProgressBarCenter(60, 100, ProgressString);
Status = WinLdrLoadImage(FileName, LoaderBootDriver, &KdComBase);
DPRINTM(DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase);
}
/* Allocate data table entries for above-loaded modules */
WinLdrAllocateDataTableEntry(LoaderBlock, "ntoskrnl.exe",
"WINDOWS\\SYSTEM32\\NTOSKRNL.EXE", NtosBase, &KernelDTE);
WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll",
"WINDOWS\\SYSTEM32\\HAL.DLL", HalBase, &HalDTE);
if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
{
WinLdrAllocateDataTableEntry(LoaderBlock, "kdcom.dll",
"WINDOWS\\SYSTEM32\\KDCOM.DLL", KdComBase, &KdComDTE);
} }
/* Load all referenced DLLs for kernel, HAL and kdcom.dll */ /* Load all referenced DLLs for kernel, HAL and kdcom.dll */
strcpy(FileName, BootPath); strcpy(FileName, BootPath);
strcat(FileName, "SYSTEM32\\"); strcat(FileName, "system32\\");
WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KernelDTE); Status = WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KernelDTE);
WinLdrScanImportDescriptorTable(LoaderBlock, FileName, HalDTE); Status &= WinLdrScanImportDescriptorTable(LoaderBlock, FileName, HalDTE);
if (KdComDTE) if (KdComDTE)
WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KdComDTE); Status &= WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KdComDTE);
sprintf(ProgressString, "Loading NLS and OEM fonts..."); if (!Status)
UiDrawBackdrop(); {
UiDrawProgressBarCenter(80, 100, ProgressString); UiMessageBox("Error loading imported dll.");
/* Load NLS data, OEM font, and prepare boot drivers list */ return;
Status = WinLdrScanSystemHive(LoaderBlock, BootPath); }
DPRINTM(DPRINT_WINDOWS, "SYSTEM hive scanned with status %d\n", Status);
/* Load boot drivers */ /* Load boot drivers */
sprintf(ProgressString, "Loading boot drivers...");
UiDrawBackdrop(); UiDrawBackdrop();
UiDrawProgressBarCenter(100, 100, ProgressString); UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath); Status = WinLdrLoadBootDrivers(LoaderBlock, (PCHAR)BootPath);
DPRINTM(DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status); DPRINTM(DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status);
/* Alloc PCR, TSS, do magic things with the GDT/IDT */
WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
/* Initialize Phase 1 - no drivers loading anymore */ /* Initialize Phase 1 - no drivers loading anymore */
WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemRoot, BootPath, OperatingSystemVersion); WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemRoot, BootPath, OperatingSystemVersion);
@ -633,19 +620,22 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
LoaderBlockVA = PaToVa(LoaderBlock); LoaderBlockVA = PaToVa(LoaderBlock);
/* "Stop all motors", change videomode */ /* "Stop all motors", change videomode */
if (OperatingSystemVersion < _WIN32_WINNT_WIN2K) MachPrepareForReactOS(Setup);
MachPrepareForReactOS(TRUE);
else
MachPrepareForReactOS(FALSE);
/* Debugging... */ /* Debugging... */
//DumpMemoryAllocMap(); //DumpMemoryAllocMap();
/* Turn on paging mode of CPU*/ /* Do the machine specific initialization */
WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt); WinLdrSetupMachineDependent(LoaderBlock);
/* Turn on paging mode of CPU */
WinLdrSetupMemoryLayout(LoaderBlock);
/* Save final value of LoaderPagesSpanned */ /* Save final value of LoaderPagesSpanned */
LoaderBlockVA->Extension->LoaderPagesSpanned = LoaderPagesSpanned; LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
/* Set processor context */
WinLdrSetProcessorContext();
DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n", DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
KiSystemStartup, LoaderBlockVA); KiSystemStartup, LoaderBlockVA);
@ -663,8 +653,6 @@ LoadAndBootWindows(PCSTR OperatingSystemName,
/* Pass control */ /* Pass control */
(*KiSystemStartup)(LoaderBlockVA); (*KiSystemStartup)(LoaderBlockVA);
return;
} }
VOID VOID

View file

@ -42,40 +42,10 @@ PCHAR MemTypeDesc[] = {
"BBTMemory " // == Bad "BBTMemory " // == Bad
}; };
VOID static VOID
WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID
MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
ULONG BasePage,
ULONG PageCount,
ULONG Type);
VOID
WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor); IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor);
VOID
WinLdrRemoveDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR Descriptor);
VOID
WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG_PTR Pcr, IN ULONG_PTR Tss);
BOOLEAN
MempAllocatePageTables();
BOOLEAN
MempSetupPaging(IN ULONG StartPage,
IN ULONG NumberOfPages);
BOOLEAN
WinLdrMapSpecialPages(ULONG PcrBasePage);
VOID
MempUnmapPage(ULONG Page);
VOID
MempDump();
/* GLOBALS ***************************************************************/ /* GLOBALS ***************************************************************/
@ -188,7 +158,7 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
return; return;
} }
// //
// Add descriptor // Add descriptor
// //
@ -197,7 +167,7 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
// //
// Map it (don't map low 1Mb because it was already contiguously // Map it (don't map low 1Mb because it was already contiguously
// mapped in WinLdrTurnOnPaging) // mapped in WinLdrPrepareMemoryLayout)
// //
if (BasePage >= 0x100) if (BasePage >= 0x100)
{ {
@ -215,10 +185,7 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
#endif #endif
BOOLEAN BOOLEAN
WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
ULONG PcrBasePage,
ULONG TssBasePage,
PVOID GdtIdt)
{ {
ULONG i, PagesCount, MemoryMapSizeInPages; ULONG i, PagesCount, MemoryMapSizeInPages;
ULONG LastPageIndex, LastPageType, MemoryMapStartPage; ULONG LastPageIndex, LastPageType, MemoryMapStartPage;
@ -249,11 +216,6 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
// StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD // StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD
// //
// Before we start mapping pages, create a block of memory, which will contain
// PDE and PTEs
if (MempAllocatePageTables() == FALSE)
return FALSE;
// Allocate memory for memory allocation descriptors // Allocate memory for memory allocation descriptors
Mad = MmHeapAlloc(sizeof(MEMORY_ALLOCATION_DESCRIPTOR) * 1024); Mad = MmHeapAlloc(sizeof(MEMORY_ALLOCATION_DESCRIPTOR) * 1024);
@ -350,15 +312,10 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
return; return;
}*/ }*/
/* Map stuff like PCR, KI_USER_SHARED_DATA and Apic */
WinLdrMapSpecialPages(PcrBasePage);
//Tss = (PKTSS)(KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
// Unmap what is not needed from kernel page table // Unmap what is not needed from kernel page table
MempDisablePages(); MempDisablePages();
// Fill the memory descriptor list and // Fill the memory descriptor list and
//PrepareMemoryDescriptorList(); //PrepareMemoryDescriptorList();
DPRINTM(DPRINT_WINDOWS, "Memory Descriptor List prepared, printing PDE\n"); DPRINTM(DPRINT_WINDOWS, "Memory Descriptor List prepared, printing PDE\n");
List_PaToVa(&LoaderBlock->MemoryDescriptorListHead); List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
@ -367,9 +324,6 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
MempDump(); MempDump();
#endif #endif
// Set processor context
WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
// Zero KI_USER_SHARED_DATA page // Zero KI_USER_SHARED_DATA page
memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE); memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE);
@ -378,7 +332,7 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
// Two special things this func does: it sorts descriptors, // Two special things this func does: it sorts descriptors,
// and it merges free ones // and it merges free ones
VOID static VOID
WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock, WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor) IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor)
{ {