Author: tkreuzer
Date: Wed Aug 24 18:17:13 2011
New Revision: 53422
URL:
http://svn.reactos.org/svn/reactos?rev=53422&view=rev
Log:
[FREELDR]
- Move architecture specific files all into arch/*
- Rename setupldr2.c to setupldr.c
- cleanup the mess in bootmgr.c
Added:
trunk/reactos/boot/freeldr/freeldr/arch/amd64/ntsetup.c
- copied unchanged from r53408,
trunk/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c
trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c
- copied unchanged from r53408,
trunk/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c
trunk/reactos/boot/freeldr/freeldr/arch/arm/wlmemory.c
- copied unchanged from r53408,
trunk/reactos/boot/freeldr/freeldr/windows/arm/wlmemory.c
trunk/reactos/boot/freeldr/freeldr/arch/i386/ntsetup.c
- copied unchanged from r53408,
trunk/reactos/boot/freeldr/freeldr/windows/i386/ntsetup.c
trunk/reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c
- copied unchanged from r53408,
trunk/reactos/boot/freeldr/freeldr/windows/i386/wlmemory.c
trunk/reactos/boot/freeldr/freeldr/windows/setupldr.c
- copied unchanged from r53408,
trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c
Removed:
trunk/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c
trunk/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c
trunk/reactos/boot/freeldr/freeldr/windows/arm/wlmemory.c
trunk/reactos/boot/freeldr/freeldr/windows/i386/ntsetup.c
trunk/reactos/boot/freeldr/freeldr/windows/i386/wlmemory.c
trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c
Modified:
trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt
trunk/reactos/boot/freeldr/freeldr/bootmgr.c
trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild
trunk/reactos/boot/freeldr/freeldr/setupldr_main.rbuild
Modified: trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/CMake…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] Wed Aug 24 18:17:13
2011
@@ -107,8 +107,8 @@
arch/i386/xboxmem.c
arch/i386/xboxrtc.c
arch/i386/xboxvideo.c
- windows/i386/ntsetup.c
- windows/i386/wlmemory.c
+ arch/i386/ntsetup.c
+ arch/i386/wlmemory.c
windows/headless.c
disk/scsiport.c)
if(NOT MSVC)
@@ -134,8 +134,8 @@
arch/i386/pcmem.c
arch/i386/pcrtc.c
arch/i386/pcvideo.c
- windows/amd64/ntsetup.c
- windows/amd64/wlmemory.c)
+ arch/amd64/ntsetup.c
+ arch/amd64/wlmemory.c)
else()
#TBD
endif()
@@ -191,7 +191,7 @@
inffile/inffile.c)
if(ARCH MATCHES i386 OR ARCH MATCHES amd64)
- list(APPEND SETUPLDR_SOURCE windows/setupldr2.c)
+ list(APPEND SETUPLDR_SOURCE windows/setupldr.c)
endif()
if(NOT MSVC)
Modified: trunk/reactos/boot/freeldr/freeldr/bootmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/bootm…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/bootmgr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/bootmgr.c [iso-8859-1] Wed Aug 24 18:17:13 2011
@@ -213,7 +213,7 @@
if (BootType[0] == ANSI_NULL && SectionName[0] != ANSI_NULL)
{
// Try to infere boot type value
-#ifdef __i386__
+#ifdef _M_IX86
ULONG FileId;
if (ArcOpen((CHAR*)SectionName, OpenReadOnly, &FileId) == ESUCCESS)
{
@@ -231,20 +231,15 @@
IniOpenSection("Operating Systems", &SectionId);
IniReadSettingByName(SectionId, SectionName, SettingValue, sizeof(SettingValue));
-#ifndef _M_ARM
// Install the drive mapper according to this sections drive mappings
-#if defined(__i386__) && !defined(_MSC_VER)
+#if defined(_M_IX86) && !defined(_MSC_VER)
DriveMapMapDrivesInSection(SectionName);
#endif
+
#ifdef FREELDR_REACTOS_SETUP
- if (_stricmp(BootType, "ReactOSSetup2") == 0)
- {
- // WinLdr-style boot
- LoadReactOSSetup2();
- }
- else
-#endif
-#ifdef __i386__
+ // WinLdr-style boot
+ LoadReactOSSetup2();
+#elif defined(_M_IX86)
if (_stricmp(BootType, "Windows") == 0)
{
LoadAndBootWindows(SectionName, SettingValue, 0);
@@ -273,12 +268,10 @@
{
LoadAndBootDrive(SectionName);
}
-#endif
#else
- LoadAndBootWindows(SectionName, SettingValue, _WIN32_WINNT_WS03);
-#endif
- }
-
+ LoadAndBootWindows(SectionName, SettingValue, _WIN32_WINNT_WS03);
+#endif
+ }
reboot:
UiUnInitialize("Rebooting...");
Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild [iso-8859-1] Wed Aug 24
18:17:13 2011
@@ -41,6 +41,8 @@
<file>xboxmem.c</file>
<file>xboxrtc.c</file>
<file>xboxvideo.c</file>
+ <file>ntsetup.c</file>
+ <file>wlmemory.c</file>
</if>
</directory>
<directory name="powerpc">
@@ -69,6 +71,8 @@
<if property="ARCH" value="amd64">
<directory name="amd64">
<file>loader.c</file>
+ <file>ntsetup.c</file>
+ <file>wlmemory.c</file>
</directory>
<directory name="i386">
<file>hardware.c</file>
@@ -87,23 +91,8 @@
</directory>
</if>
- </directory>
-
- <directory name="windows">
- <if property="ARCH" value="arm">
- <directory name="arm">
- <file>wlmemory.c</file>
- </directory>
- </if>
- <if property="ARCH" value="i386">
- <directory name="i386">
- <file>ntsetup.c</file>
- <file>wlmemory.c</file>
- </directory>
- </if>
- <if property="ARCH" value="amd64">
- <directory name="amd64">
- <file>ntsetup.c</file>
+ <if property="ARCH" value="arm">
+ <directory name="arm">
<file>wlmemory.c</file>
</directory>
</if>
Modified: trunk/reactos/boot/freeldr/freeldr/setupldr_main.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/setup…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/setupldr_main.rbuild [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/setupldr_main.rbuild [iso-8859-1] Wed Aug 24
18:17:13 2011
@@ -9,14 +9,7 @@
<directory name="inffile">
<file>inffile.c</file>
</directory>
- <if property="ARCH" value="i386">
- <directory name="windows">
- <file>setupldr2.c</file>
- </directory>
- </if>
- <if property="ARCH" value="amd64">
- <directory name="windows">
- <file>setupldr2.c</file>
- </directory>
- </if>
+ <directory name="windows">
+ <file>setupldr.c</file>
+ </directory>
</module>
Removed: trunk/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/amd64/ntsetup.c (removed)
@@ -1,84 +1,0 @@
-/*
- * PROJECT: EFI Windows Loader
- * LICENSE: GPL - See COPYING in the top level directory
- * FILE: freeldr/windows/i386/ntsetup.c
- * PURPOSE: i386-specific setup for Windows boot
- * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org)
- */
-
-/* INCLUDES ***************************************************************/
-
-#include <freeldr.h>
-#include <debug.h>
-
-// this is needed for new IDT filling
-#if 0
-extern ULONG_PTR i386DivideByZero;
-extern ULONG_PTR i386DebugException;
-extern ULONG_PTR i386NMIException;
-extern ULONG_PTR i386Breakpoint;
-extern ULONG_PTR i386Overflow;
-extern ULONG_PTR i386BoundException;
-extern ULONG_PTR i386InvalidOpcode;
-extern ULONG_PTR i386FPUNotAvailable;
-extern ULONG_PTR i386DoubleFault;
-extern ULONG_PTR i386CoprocessorSegment;
-extern ULONG_PTR i386InvalidTSS;
-extern ULONG_PTR i386SegmentNotPresent;
-extern ULONG_PTR i386StackException;
-extern ULONG_PTR i386GeneralProtectionFault;
-extern ULONG_PTR i386PageFault; // exc 14
-extern ULONG_PTR i386CoprocessorError; // exc 16
-extern ULONG_PTR i386AlignmentCheck; // exc 17
-#endif
-
-/* FUNCTIONS **************************************************************/
-
-// Last step before going virtual
-void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
- PVOID *GdtIdt,
- ULONG *PcrBasePage,
- ULONG *TssBasePage)
-{
- ULONG TssSize;
- ULONG TssPages;
- 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;
- RtlZeroMemory((PVOID)Pcr, 2 * MM_PAGE_SIZE);
-
- 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);
-}
Removed: trunk/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/amd64/wlmemory.c (removed)
@@ -1,354 +1,0 @@
-/*
- * PROJECT: EFI Windows Loader
- * LICENSE: GPL - See COPYING in the top level directory
- * FILE: freeldr/amd64/wlmemory.c
- * PURPOSE: Memory related routines
- * PROGRAMMERS: Timo Kreuzer (timo.kreuzer(a)reactos.org)
- */
-
-/* INCLUDES ***************************************************************/
-
-#include <freeldr.h>
-
-#include <ndk/asm.h>
-#include <debug.h>
-
-//extern ULONG LoaderPagesSpanned;
-
-#define HYPER_SPACE_ENTRY 0x1EE
-
-/* GLOBALS ***************************************************************/
-
-PHARDWARE_PTE PxeBase;
-//PHARDWARE_PTE HalPageTable;
-
-
-/* FUNCTIONS **************************************************************/
-
-BOOLEAN
-MempAllocatePageTables()
-{
- DPRINTM(DPRINT_WINDOWS,">>> MempAllocatePageTables\n");
-
- /* Allocate a page for the PML4 */
- PxeBase = MmAllocateMemoryWithType(PAGE_SIZE, LoaderMemoryData);
- if (!PxeBase)
- {
- DPRINTM(DPRINT_WINDOWS,"failed to allocate PML4\n");
- return FALSE;
- }
-
- // FIXME: Physical PTEs = FirmwareTemporary ?
-
- /* Zero the PML4 */
- RtlZeroMemory(PxeBase, PAGE_SIZE);
-
- /* The page tables are located at 0xfffff68000000000
- * We create a recursive self mapping through all 4 levels at
- * virtual address 0xfffff6fb7dbedf68 */
- PxeBase[VAtoPXI(PXE_BASE)].Valid = 1;
- PxeBase[VAtoPXI(PXE_BASE)].Write = 1;
- PxeBase[VAtoPXI(PXE_BASE)].PageFrameNumber = PtrToPfn(PxeBase);
-
- // FIXME: map PDE's for hals memory mapping
-
- DPRINTM(DPRINT_WINDOWS,">>> leave MempAllocatePageTables\n");
-
- return TRUE;
-}
-
-PHARDWARE_PTE
-MempGetOrCreatePageDir(PHARDWARE_PTE PdeBase, ULONG Index)
-{
- PHARDWARE_PTE SubDir;
-
- if (!PdeBase)
- return NULL;
-
- if (!PdeBase[Index].Valid)
- {
- SubDir = MmAllocateMemoryWithType(PAGE_SIZE, LoaderMemoryData);
- if (!SubDir)
- return NULL;
- RtlZeroMemory(SubDir, PAGE_SIZE);
- PdeBase[Index].PageFrameNumber = PtrToPfn(SubDir);
- PdeBase[Index].Valid = 1;
- PdeBase[Index].Write = 1;
- }
- else
- {
- SubDir = (PVOID)((ULONG64)(PdeBase[Index].PageFrameNumber) * PAGE_SIZE);
- }
- return SubDir;
-}
-
-BOOLEAN
-MempMapSinglePage(ULONG64 VirtualAddress, ULONG64 PhysicalAddress)
-{
- PHARDWARE_PTE PpeBase, PdeBase, PteBase;
- ULONG Index;
-
- PpeBase = MempGetOrCreatePageDir(PxeBase, VAtoPXI(VirtualAddress));
- PdeBase = MempGetOrCreatePageDir(PpeBase, VAtoPPI(VirtualAddress));
- PteBase = MempGetOrCreatePageDir(PdeBase, VAtoPDI(VirtualAddress));
-
- if (!PteBase)
- {
- DPRINTM(DPRINT_WINDOWS,"!!!No Dir %p, %p, %p, %p\n", PxeBase, PpeBase,
PdeBase, PteBase);
- return FALSE;
- }
-
- Index = VAtoPTI(VirtualAddress);
- if (PteBase[Index].Valid)
- {
- DPRINTM(DPRINT_WINDOWS,"!!!Already mapped %ld\n", Index);
- return FALSE;
- }
-
- PteBase[Index].Valid = 1;
- PteBase[Index].Write = 1;
- PteBase[Index].PageFrameNumber = PhysicalAddress / PAGE_SIZE;
-
- return TRUE;
-}
-
-BOOLEAN
-MempIsPageMapped(PVOID VirtualAddress)
-{
- PHARDWARE_PTE PpeBase, PdeBase, PteBase;
- ULONG Index;
-
- Index = VAtoPXI(VirtualAddress);
- if (!PxeBase[Index].Valid)
- return FALSE;
-
- PpeBase = (PVOID)((ULONG64)(PxeBase[Index].PageFrameNumber) * PAGE_SIZE);
- Index = VAtoPPI(VirtualAddress);
- if (!PpeBase[Index].Valid)
- return FALSE;
-
- PdeBase = (PVOID)((ULONG64)(PpeBase[Index].PageFrameNumber) * PAGE_SIZE);
- Index = VAtoPDI(VirtualAddress);
- if (!PdeBase[Index].Valid)
- return FALSE;
-
- PteBase = (PVOID)((ULONG64)(PdeBase[Index].PageFrameNumber) * PAGE_SIZE);
- Index = VAtoPTI(VirtualAddress);
- if (!PteBase[Index].Valid)
- return FALSE;
-
- return TRUE;
-}
-
-ULONG
-MempMapRangeOfPages(ULONG64 VirtualAddress, ULONG64 PhysicalAddress, ULONG cPages)
-{
- ULONG i;
-
- for (i = 0; i < cPages; i++)
- {
- if (!MempMapSinglePage(VirtualAddress, PhysicalAddress))
- {
- return i;
- }
- VirtualAddress += PAGE_SIZE;
- PhysicalAddress += PAGE_SIZE;
- }
- return i;
-}
-
-BOOLEAN
-MempSetupPaging(IN ULONG StartPage,
- IN ULONG NumberOfPages)
-{
- DPRINTM(DPRINT_WINDOWS,">>> MempSetupPaging(0x%lx, %ld, %p)\n",
- StartPage, NumberOfPages, StartPage * PAGE_SIZE + KSEG0_BASE);
-
- /* Identity mapping */
- if (MempMapRangeOfPages(StartPage * PAGE_SIZE,
- StartPage * PAGE_SIZE,
- NumberOfPages) != NumberOfPages)
- {
- DPRINTM(DPRINT_WINDOWS,"Failed to map pages 1\n");
- return FALSE;
- }
-
- /* Kernel mapping */
- if (MempMapRangeOfPages(StartPage * PAGE_SIZE + KSEG0_BASE,
- StartPage * PAGE_SIZE,
- NumberOfPages) != NumberOfPages)
- {
- DPRINTM(DPRINT_WINDOWS,"Failed to map pages 2\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-VOID
-MempUnmapPage(ULONG Page)
-{
- // DPRINTM(DPRINT_WINDOWS,">>> MempUnmapPage\n");
-}
-
-VOID
-WinLdrpMapApic()
-{
- BOOLEAN LocalAPIC;
- LARGE_INTEGER MsrValue;
- ULONG CpuInfo[4];
- ULONG64 APICAddress;
-
- DPRINTM(DPRINT_WINDOWS,">>> WinLdrpMapApic\n");
-
- /* Check if we have a local APIC */
- __cpuid((int*)CpuInfo, 1);
- LocalAPIC = (((CpuInfo[3] >> 9) & 1) != 0);
-
- /* If there is no APIC, just return */
- if (!LocalAPIC)
- {
- DPRINTM(DPRINT_WINDOWS,"No APIC found.\n");
- return;
- }
-
- /* Read the APIC Address */
- MsrValue.QuadPart = __readmsr(0x1B);
- APICAddress = (MsrValue.LowPart & 0xFFFFF000);
-
- DPRINTM(DPRINT_WINDOWS, "Local APIC detected at address 0x%x\n",
- APICAddress);
-
- /* Map it */
- MempMapSinglePage(APIC_BASE, APICAddress);
-}
-
-BOOLEAN
-WinLdrMapSpecialPages(ULONG PcrBasePage)
-{
- /* Map the PCR page */
- if (!MempMapSinglePage(KIP0PCRADDRESS, PcrBasePage * PAGE_SIZE))
- {
- DPRINTM(DPRINT_WINDOWS, "Could not map PCR @ %lx\n", PcrBasePage);
- return FALSE;
- }
-
- /* Map KI_USER_SHARED_DATA */
- if (!MempMapSinglePage(KI_USER_SHARED_DATA, (PcrBasePage+1) * PAGE_SIZE))
- {
- DPRINTM(DPRINT_WINDOWS, "Could not map KI_USER_SHARED_DATA\n");
- return FALSE;
- }
-
- /* Map the APIC page */
- WinLdrpMapApic();
-
- return TRUE;
-}
-
-VOID
-WinLdrSetupGdt(PVOID GdtBase, ULONG64 TssBase)
-{
- PKGDTENTRY64 Entry;
- KDESCRIPTOR GdtDesc;
-
- /* Setup KGDT64_NULL */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_NULL);
- *(PULONG64)Entry = 0x0000000000000000ULL;
-
- /* Setup KGDT64_R0_CODE */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_R0_CODE);
- *(PULONG64)Entry = 0x00209b0000000000ULL;
-
- /* Setup KGDT64_R0_DATA */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_R0_DATA);
- *(PULONG64)Entry = 0x00cf93000000ffffULL;
-
- /* Setup KGDT64_R3_CMCODE */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_R3_CMCODE);
- *(PULONG64)Entry = 0x00cffb000000ffffULL;
-
- /* Setup KGDT64_R3_DATA */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_R3_DATA);
- *(PULONG64)Entry = 0x00cff3000000ffffULL;
-
- /* Setup KGDT64_R3_CODE */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_R3_CODE);
- *(PULONG64)Entry = 0x0020fb0000000000ULL;
-
- /* Setup KGDT64_R3_CMTEB */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_R3_CMTEB);
- *(PULONG64)Entry = 0xff40f3fd50003c00ULL;
-
- /* Setup TSS entry */
- Entry = KiGetGdtEntry(GdtBase, KGDT64_SYS_TSS);
- KiInitGdtEntry(Entry, TssBase, sizeof(KTSS), I386_TSS, 0);
-
- /* Setup GDT descriptor */
- GdtDesc.Base = GdtBase;
- GdtDesc.Limit = NUM_GDT * sizeof(KGDTENTRY) - 1;
-
- /* Set the new Gdt */
- __lgdt(&GdtDesc.Limit);
- DbgPrint("Gdtr.Base = %p, num = %ld\n", GdtDesc.Base, NUM_GDT);
-
-}
-
-VOID
-WinLdrSetupIdt(PVOID IdtBase)
-{
- KDESCRIPTOR IdtDesc, OldIdt;
-
- /* Get old IDT */
- __sidt(&OldIdt);
-
- /* Copy the old IDT */
- RtlCopyMemory(IdtBase, (PVOID)OldIdt.Base, OldIdt.Limit + 1);
-
- /* Setup the new IDT descriptor */
- IdtDesc.Base = IdtBase;
- IdtDesc.Limit = NUM_IDT * sizeof(KIDTENTRY) - 1;
-
- /* Set the new IDT */
- __lidt(&IdtDesc.Limit);
- DbgPrint("Idtr.Base = %p\n", IdtDesc.Base);
-
-}
-
-VOID
-WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG64 Pcr, IN ULONG64 Tss)
-{
- DPRINTM(DPRINT_WINDOWS, "WinLdrSetProcessorContext %p\n", Pcr);
-
- /* Disable Interrupts */
- _disable();
-
- /* Re-initalize EFLAGS */
- __writeeflags(0);
-
- /* Set the new PML4 */
- __writecr3((ULONG64)PxeBase);
-
- /* Get kernel mode address of gdt / idt */
- GdtIdt = (PVOID)((ULONG64)GdtIdt + KSEG0_BASE);
-
- /* Create gdt entries and load gdtr */
- WinLdrSetupGdt(GdtIdt, Tss);
-
- /* Copy old Idt and set idtr */
- WinLdrSetupIdt((PVOID)((ULONG64)GdtIdt + 2048)); // HACK!
-
- /* LDT is unused */
-// __lldt(0);
-
- /* Load TSR */
- __ltr(KGDT64_SYS_TSS);
-
- DPRINTM(DPRINT_WINDOWS, "leave WinLdrSetProcessorContext\n");
-}
-
-VOID
-MempDump()
-{
-}
-
Removed: trunk/reactos/boot/freeldr/freeldr/windows/arm/wlmemory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/arm/wlmemory.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/arm/wlmemory.c (removed)
@@ -1,274 +1,0 @@
-/*
- * PROJECT: ReactOS Boot Loader
- * LICENSE: BSD - See COPYING.ARM in the top level directory
- * FILE: boot/freeldr/arch/arm/loader.c
- * PURPOSE: ARM Kernel Loader
- * PROGRAMMERS: ReactOS Portable Systems Group
- */
-
-/* INCLUDES ***************************************************************/
-
-#include <freeldr.h>
-#include <debug.h>
-#include <internal/arm/mm.h>
-#include <internal/arm/intrin_i.h>
-
-#define PFN_SHIFT 12
-#define LARGE_PFN_SHIFT 20
-
-#define PTE_BASE 0xC0000000
-#define PDE_BASE 0xC0400000
-#define PDR_BASE 0xFFD00000
-#define VECTOR_BASE 0xFFFF0000
-
-#ifdef _ZOOM2_
-#define IDMAP_BASE 0x81000000
-#define MMIO_BASE 0x10000000
-#else
-#define IDMAP_BASE 0x00000000
-#define MMIO_BASE 0x10000000
-#endif
-
-#define LowMemPageTableIndex (IDMAP_BASE >> PDE_SHIFT)
-#define MmioPageTableIndex (MMIO_BASE >> PDE_SHIFT)
-#define KernelPageTableIndex (KSEG0_BASE >> PDE_SHIFT)
-#define StartupPtePageTableIndex (PTE_BASE >> PDE_SHIFT)
-#define StartupPdePageTableIndex (PDE_BASE >> PDE_SHIFT)
-#define PdrPageTableIndex (PDR_BASE >> PDE_SHIFT)
-#define VectorPageTableIndex (VECTOR_BASE >> PDE_SHIFT)
-
-#ifndef _ZOOM2_
-PVOID MempPdrBaseAddress = (PVOID)0x70000;
-PVOID MempKernelBaseAddress = (PVOID)0;
-#else
-PVOID MempPdrBaseAddress = (PVOID)0x81100000;
-PVOID MempKernelBaseAddress = (PVOID)0x80000000;
-#endif
-
-/* Converts a Physical Address into a Page Frame Number */
-#define PaToPfn(p) ((p) >> PFN_SHIFT)
-#define PaToLargePfn(p) ((p) >> LARGE_PFN_SHIFT)
-#define PaPtrToPfn(p) (((ULONG_PTR)(p)) >> PFN_SHIFT)
-
-/* Converts a Physical Address into a Coarse Page Table PFN */
-#define PaPtrToPdePfn(p) (((ULONG_PTR)(p)) >> CPT_SHIFT)
-
-typedef struct _KPDR_PAGE
-{
- PAGE_DIRECTORY_ARM PageDir; // 0xC0400000 [0xFFD00000]
- CHAR HyperSpace[233 * PAGE_SIZE]; // 0xC0404000 [0xFFD04000]
- PAGE_TABLE_ARM KernelPageTable[3]; // 0xC04ED000 [0xFFDED000]
- CHAR SharedData[PAGE_SIZE]; // 0xC04F0000 [0xFFDF0000]
- CHAR KernelStack[KERNEL_STACK_SIZE]; // 0xC04F1000 [0xFFDF1000]
- CHAR PanicStack[KERNEL_STACK_SIZE]; // 0xC04F4000 [0xFFDF4000]
- CHAR InterruptStack[KERNEL_STACK_SIZE]; // 0xC04F7000 [0xFFDF7000]
- CHAR InitialProcess[PAGE_SIZE]; // 0xC04FA000 [0xFFDFA000]
- CHAR InitialThread[PAGE_SIZE]; // 0xC04FB000 [0xFFDFB000]
- CHAR Prcb[PAGE_SIZE]; // 0xC04FC000 [0xFFDFC000]
- PAGE_TABLE_ARM PageDirPageTable; // 0xC04FD000 [0xFFDFD000]
- PAGE_TABLE_ARM VectorPageTable; // 0xC04FE000 [0xFFDFE000]
- CHAR Pcr[PAGE_SIZE]; // 0xC04FF000 [0xFFDFF000]
-} KPDR_PAGE, *PKPDR_PAGE;
-
-C_ASSERT(sizeof(KPDR_PAGE) == (1 * 1024 * 1024));
-
-HARDWARE_PTE_ARMV6 TempPte;
-HARDWARE_LARGE_PTE_ARMV6 TempLargePte;
-HARDWARE_PDE_ARMV6 TempPde;
-PKPDR_PAGE PdrPage;
-
-/* FUNCTIONS **************************************************************/
-
-BOOLEAN
-MempSetupPaging(IN ULONG StartPage,
- IN ULONG NumberOfPages)
-{
- return TRUE;
-}
-
-VOID
-MempUnmapPage(IN ULONG Page)
-{
- return;
-}
-
-VOID
-MempDump(VOID)
-{
- return;
-}
-
-BOOLEAN
-WinLdrMapSpecialPages(ULONG PcrBasePage)
-{
- ULONG i;
- PHARDWARE_PTE_ARMV6 PointerPte;
- PHARDWARE_PDE_ARMV6 PointerPde;
- PHARDWARE_LARGE_PTE_ARMV6 LargePte;
- PFN_NUMBER Pfn;
-
- /* Setup the Startup PDE */
- LargePte = &PdrPage->PageDir.Pte[StartupPdePageTableIndex];
- TempLargePte.PageFrameNumber = PaToLargePfn((ULONG_PTR)&PdrPage->PageDir);
- *LargePte = TempLargePte;
-
- /* Map-in the PDR */
- LargePte = &PdrPage->PageDir.Pte[PdrPageTableIndex];
- *LargePte = TempLargePte;
-
- /* After this point, any MiAddressToPde is guaranteed not to fault */
-
- /*
- * Link them in the Startup PDE.
- * Note these are the entries in the PD at (MiAddressToPde(PTE_BASE)).
- */
- PointerPde = &PdrPage->PageDir.Pde[StartupPtePageTableIndex];
- Pfn = PaPtrToPdePfn(&PdrPage->PageDirPageTable);
- for (i = 0; i < 4; i++)
- {
- TempPde.PageFrameNumber = Pfn++;
- *PointerPde++ = TempPde;
- }
-
- /*
- * Now map these page tables in PTE space (MiAddressToPte(PTE_BASE)).
- * Note that they all live on a single page, since each is 1KB.
- */
- PointerPte = &PdrPage->PageDirPageTable.Pte[0x300];
- TempPte.PageFrameNumber = PaPtrToPfn(&PdrPage->PageDirPageTable);
- *PointerPte = TempPte;
-
- /*
- * After this point, MiAddressToPte((PDE_BASE) to MiAddressToPte(PDE_TOP))
- * is guaranteed not to fault.
- * Any subsequent page allocation will first need its page table created
- * and mapped in the PTE_BASE first, then the page table itself will be
- * editable through its flat PTE address.
- */
-
- /* Setup the Vector PDE */
- PointerPde = &PdrPage->PageDir.Pde[VectorPageTableIndex];
- TempPde.PageFrameNumber = PaPtrToPdePfn(&PdrPage->VectorPageTable);
- *PointerPde = TempPde;
-
- /* Setup the Vector PTEs */
- PointerPte = &PdrPage->VectorPageTable.Pte[0xF0];
- TempPte.PageFrameNumber = 0;
- *PointerPte = TempPte;
-
- /* TODO: Map in the kernel CPTs */
- return TRUE;
-}
-
-VOID
-WinLdrSetupForNt(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
- IN PVOID *GdtIdt,
- IN ULONG *PcrBasePage,
- IN ULONG *TssBasePage)
-{
- PKPDR_PAGE PdrPage = (PVOID)0xFFD00000;
-
- /* Load cache information */
- LoaderBlock->u.Arm.FirstLevelDcacheSize = FirstLevelDcacheSize;
- LoaderBlock->u.Arm.FirstLevelDcacheFillSize = FirstLevelDcacheFillSize;
- LoaderBlock->u.Arm.FirstLevelIcacheSize = FirstLevelIcacheSize;
- LoaderBlock->u.Arm.FirstLevelIcacheFillSize = FirstLevelIcacheFillSize;
- LoaderBlock->u.Arm.SecondLevelDcacheSize = SecondLevelDcacheSize;
- LoaderBlock->u.Arm.SecondLevelDcacheFillSize = SecondLevelDcacheFillSize;
- LoaderBlock->u.Arm.SecondLevelIcacheSize = SecondLevelIcacheSize;
- LoaderBlock->u.Arm.SecondLevelIcacheFillSize = SecondLevelIcacheSize;
-
- /* Write initial context information */
- LoaderBlock->KernelStack = (ULONG_PTR)PdrPage->KernelStack;
- LoaderBlock->KernelStack += KERNEL_STACK_SIZE;
- LoaderBlock->u.Arm.PanicStack = (ULONG_PTR)PdrPage->PanicStack;
- LoaderBlock->u.Arm.PanicStack += KERNEL_STACK_SIZE;
- LoaderBlock->u.Arm.InterruptStack = (ULONG_PTR)PdrPage->InterruptStack;
- LoaderBlock->u.Arm.InterruptStack += KERNEL_STACK_SIZE;
- LoaderBlock->Prcb = (ULONG_PTR)PdrPage->Prcb;
- LoaderBlock->Process = (ULONG_PTR)PdrPage->InitialProcess;
- LoaderBlock->Thread = (ULONG_PTR)PdrPage->InitialThread;
-}
-
-BOOLEAN
-MempAllocatePageTables(VOID)
-{
- ULONG i;
- PHARDWARE_PTE_ARMV6 PointerPte;
- PHARDWARE_PDE_ARMV6 PointerPde;
- PHARDWARE_LARGE_PTE_ARMV6 LargePte;
- PFN_NUMBER Pfn;
-
- /* Setup templates */
- TempPte.Sbo = TempPte.Valid = TempLargePte.LargePage = TempLargePte.Sbo =
TempPde.Valid = 1;
-
- /* Allocate the 1MB "PDR" (Processor Data Region). Must be 1MB aligned */
- PdrPage = MmAllocateMemoryAtAddress(sizeof(KPDR_PAGE),
- MempPdrBaseAddress,
- LoaderMemoryData);
-
- /* Setup the Low Memory PDE as an identity-mapped Large Page (1MB) */
- LargePte = &PdrPage->PageDir.Pte[LowMemPageTableIndex];
- TempLargePte.PageFrameNumber = PaToLargePfn(IDMAP_BASE);
- *LargePte = TempLargePte;
-
- /* Setup the MMIO PDE as two identity mapped large pages -- the kernel will blow
these away later */
- LargePte = &PdrPage->PageDir.Pte[MmioPageTableIndex];
- Pfn = PaToLargePfn(MMIO_BASE);
- for (i = 0; i < 2; i++)
- {
- TempLargePte.PageFrameNumber = Pfn++;
- *LargePte++ = TempLargePte;
- }
-
- /* Setup the Kernel PDEs */
- PointerPde = &PdrPage->PageDir.Pde[KernelPageTableIndex];
- Pfn = PaPtrToPdePfn(PdrPage->KernelPageTable);
- for (i = 0; i < 12; i++)
- {
- TempPde.PageFrameNumber = Pfn;
- *PointerPde++ = TempPde;
- Pfn++;
- }
-
- /* Setup the Kernel PTEs */
- PointerPte = PdrPage->KernelPageTable[0].Pte;
- Pfn = PaPtrToPfn(MempKernelBaseAddress);
- for (i = 0; i < 3072; i++)
- {
- TempPte.PageFrameNumber = Pfn++;
- *PointerPte++ = TempPte;
- }
-
- /* Done */
- return TRUE;
-}
-
-VOID
-WinLdrSetProcessorContext(PVOID GdtIdt,
- IN ULONG Pcr,
- IN ULONG Tss)
-{
- ARM_CONTROL_REGISTER ControlRegister;
- ARM_TTB_REGISTER TtbRegister;
- ARM_DOMAIN_REGISTER DomainRegister;
-
- /* Set the TTBR */
- TtbRegister.AsUlong = (ULONG_PTR)&PdrPage->PageDir;
- ASSERT(TtbRegister.Reserved == 0);
- KeArmTranslationTableRegisterSet(TtbRegister);
-
- /* Disable domains and simply use access bits on PTEs */
- DomainRegister.AsUlong = 0;
- DomainRegister.Domain0 = ClientDomain;
- KeArmDomainRegisterSet(DomainRegister);
-
- /* Enable ARMv6+ paging (MMU), caches and the access bit */
- ControlRegister = KeArmControlRegisterGet();
- ControlRegister.MmuEnabled = TRUE;
- ControlRegister.ICacheEnabled = TRUE;
- ControlRegister.DCacheEnabled = TRUE;
- ControlRegister.ForceAp = TRUE;
- ControlRegister.ExtendedPageTables = TRUE;
- KeArmControlRegisterSet(ControlRegister);
-}
Removed: trunk/reactos/boot/freeldr/freeldr/windows/i386/ntsetup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/i386/ntsetup.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/i386/ntsetup.c (removed)
@@ -1,83 +1,0 @@
-/*
- * PROJECT: EFI Windows Loader
- * LICENSE: GPL - See COPYING in the top level directory
- * FILE: freeldr/windows/i386/ntsetup.c
- * PURPOSE: i386-specific setup for Windows boot
- * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org)
- */
-
-/* INCLUDES ***************************************************************/
-
-#include <freeldr.h>
-#include <debug.h>
-
-// this is needed for new IDT filling
-#if 0
-extern ULONG_PTR i386DivideByZero;
-extern ULONG_PTR i386DebugException;
-extern ULONG_PTR i386NMIException;
-extern ULONG_PTR i386Breakpoint;
-extern ULONG_PTR i386Overflow;
-extern ULONG_PTR i386BoundException;
-extern ULONG_PTR i386InvalidOpcode;
-extern ULONG_PTR i386FPUNotAvailable;
-extern ULONG_PTR i386DoubleFault;
-extern ULONG_PTR i386CoprocessorSegment;
-extern ULONG_PTR i386InvalidTSS;
-extern ULONG_PTR i386SegmentNotPresent;
-extern ULONG_PTR i386StackException;
-extern ULONG_PTR i386GeneralProtectionFault;
-extern ULONG_PTR i386PageFault; // exc 14
-extern ULONG_PTR i386CoprocessorError; // exc 16
-extern ULONG_PTR i386AlignmentCheck; // exc 17
-#endif
-
-/* FUNCTIONS **************************************************************/
-
-// Last step before going virtual
-void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
- PVOID *GdtIdt,
- ULONG *PcrBasePage,
- ULONG *TssBasePage)
-{
- 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);
-}
Removed: trunk/reactos/boot/freeldr/freeldr/windows/i386/wlmemory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/i386/wlmemory.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/i386/wlmemory.c (removed)
@@ -1,553 +1,0 @@
-/*
- * PROJECT: EFI Windows Loader
- * LICENSE: GPL - See COPYING in the top level directory
- * FILE: freeldr/winldr/i386/wlmemory.c
- * PURPOSE: Memory related routines
- * PROGRAMMERS: Aleksey Bragin (aleksey(a)reactos.org)
- */
-
-/* INCLUDES ***************************************************************/
-
-#include <freeldr.h>
-
-#include <ndk/asm.h>
-#include <debug.h>
-
-extern ULONG TotalNLSSize;
-extern ULONG LoaderPagesSpanned;
-
-// This is needed because headers define wrong one for ReactOS
-#undef KIP0PCRADDRESS
-#define KIP0PCRADDRESS 0xffdff000
-
-#define HYPER_SPACE_ENTRY 0x300
-
-// This is needed only for SetProcessorContext routine
-#pragma pack(2)
- typedef struct
- {
- USHORT Limit;
- ULONG Base;
- } GDTIDT;
-#pragma pack(4)
-
-/* GLOBALS ***************************************************************/
-
-PHARDWARE_PTE PDE;
-PHARDWARE_PTE HalPageTable;
-
-PUCHAR PhysicalPageTablesBuffer;
-PUCHAR KernelPageTablesBuffer;
-ULONG PhysicalPageTables;
-ULONG KernelPageTables;
-
-/* FUNCTIONS **************************************************************/
-
-BOOLEAN
-MempAllocatePageTables()
-{
- ULONG NumPageTables, TotalSize;
- PUCHAR Buffer;
- // It's better to allocate PDE + PTEs contigiuos
-
- // Max number of entries = MaxPageNum >> 10
- // FIXME: This is a number to describe ALL physical memory
- // and windows doesn't expect ALL memory mapped...
- NumPageTables = TotalPagesInLookupTable >> 10;
-
- DPRINTM(DPRINT_WINDOWS, "NumPageTables = %d\n", NumPageTables);
-
- // Allocate memory block for all these things:
- // PDE, HAL mapping page table, physical mapping, kernel mapping
- TotalSize = (1 + 1 + NumPageTables * 2) * MM_PAGE_SIZE;
-
- // PDE+HAL+KernelPTEs == MemoryData
- Buffer = MmAllocateMemoryWithType(TotalSize, LoaderMemoryData);
-
- // Physical PTEs = FirmwareTemporary
- PhysicalPageTablesBuffer = (PUCHAR)Buffer + TotalSize - NumPageTables*MM_PAGE_SIZE;
- MmSetMemoryType(PhysicalPageTablesBuffer,
- NumPageTables*MM_PAGE_SIZE,
- LoaderFirmwareTemporary);
-
- // This check is now redundant
- if (Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) !=
- PhysicalPageTablesBuffer)
- {
- DPRINTM(DPRINT_WINDOWS, "There was a problem allocating two adjacent blocks of
memory!");
- }
-
- if (Buffer == NULL || PhysicalPageTablesBuffer == NULL)
- {
- UiMessageBox("Impossible to allocate memory block for page tables!");
- return FALSE;
- }
-
- // Zero all this memory block
- RtlZeroMemory(Buffer, TotalSize);
-
- // Set up pointers correctly now
- PDE = (PHARDWARE_PTE)Buffer;
-
- // Map the page directory at 0xC0000000 (maps itself)
- PDE[HYPER_SPACE_ENTRY].PageFrameNumber = (ULONG)PDE >> MM_PAGE_SHIFT;
- PDE[HYPER_SPACE_ENTRY].Valid = 1;
- PDE[HYPER_SPACE_ENTRY].Write = 1;
-
- // The last PDE slot is allocated for HAL's memory mapping (Virtual Addresses
0xFFC00000 - 0xFFFFFFFF)
- HalPageTable = (PHARDWARE_PTE)&Buffer[MM_PAGE_SIZE*1];
-
- // Map it
- PDE[1023].PageFrameNumber = (ULONG)HalPageTable >> MM_PAGE_SHIFT;
- PDE[1023].Valid = 1;
- PDE[1023].Write = 1;
-
- // Store pointer to the table for easier access
- KernelPageTablesBuffer = &Buffer[MM_PAGE_SIZE*2];
-
- // Zero counters of page tables used
- PhysicalPageTables = 0;
- KernelPageTables = 0;
-
- return TRUE;
-}
-
-VOID
-MempAllocatePTE(ULONG Entry, PHARDWARE_PTE *PhysicalPT, PHARDWARE_PTE *KernelPT)
-{
- //Print(L"Creating PDE Entry %X\n", Entry);
-
- // Identity mapping
- *PhysicalPT =
(PHARDWARE_PTE)&PhysicalPageTablesBuffer[PhysicalPageTables*MM_PAGE_SIZE];
- PhysicalPageTables++;
-
- PDE[Entry].PageFrameNumber = (ULONG)*PhysicalPT >> MM_PAGE_SHIFT;
- PDE[Entry].Valid = 1;
- PDE[Entry].Write = 1;
-
- if (Entry+(KSEG0_BASE >> 22) > 1023)
- {
- DPRINTM(DPRINT_WINDOWS, "WARNING! Entry: %X > 1023\n", Entry+(KSEG0_BASE
>> 22));
- }
-
- // Kernel-mode mapping
- *KernelPT = (PHARDWARE_PTE)&KernelPageTablesBuffer[KernelPageTables*MM_PAGE_SIZE];
- KernelPageTables++;
-
- PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber = ((ULONG)*KernelPT >>
MM_PAGE_SHIFT);
- PDE[Entry+(KSEG0_BASE >> 22)].Valid = 1;
- PDE[Entry+(KSEG0_BASE >> 22)].Write = 1;
-}
-
-BOOLEAN
-MempSetupPaging(IN ULONG StartPage,
- IN ULONG NumberOfPages)
-{
- PHARDWARE_PTE PhysicalPT;
- PHARDWARE_PTE KernelPT;
- ULONG Entry, Page;
-
- //Print(L"MempSetupPaging: SP 0x%X, Number: 0x%X\n", StartPage,
NumberOfPages);
-
- // HACK
- if (StartPage+NumberOfPages >= 0x80000)
- {
- //
- // We can't map this as it requires more than 1 PDE
- // and in fact it's not possible at all ;)
- //
- //Print(L"skipping...\n");
- return TRUE;
- }
-
- //
- // Now actually set up the page tables for identity mapping
- //
- for (Page = StartPage; Page < StartPage + NumberOfPages; Page++)
- {
- Entry = Page >> 10;
-
- if (((PULONG)PDE)[Entry] == 0)
- {
- MempAllocatePTE(Entry, &PhysicalPT, &KernelPT);
- }
- else
- {
- PhysicalPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT);
- KernelPT = (PHARDWARE_PTE)(PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber
<< MM_PAGE_SHIFT);
- }
-
- PhysicalPT[Page & 0x3ff].PageFrameNumber = Page;
- PhysicalPT[Page & 0x3ff].Valid = (Page != 0);
- PhysicalPT[Page & 0x3ff].Write = (Page != 0);
-
- KernelPT[Page & 0x3ff].PageFrameNumber = Page;
- KernelPT[Page & 0x3ff].Valid = (Page != 0);
- KernelPT[Page & 0x3ff].Write = (Page != 0);
- }
-
- return TRUE;
-}
-
-VOID
-MempUnmapPage(ULONG Page)
-{
- PHARDWARE_PTE KernelPT;
- ULONG Entry = (Page >> 10) + (KSEG0_BASE >> 22);
-
- /* Don't unmap hyperspace or HAL entries */
- if (Entry == HYPER_SPACE_ENTRY || Entry == 1023)
- return;
-
- if (PDE[Entry].Valid)
- {
- KernelPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT);
-
- if (KernelPT)
- {
- KernelPT[Page & 0x3ff].PageFrameNumber = 0;
- KernelPT[Page & 0x3ff].Valid = 0;
- KernelPT[Page & 0x3ff].Write = 0;
- }
- }
-}
-
-VOID
-WinLdrpMapApic()
-{
- BOOLEAN LocalAPIC;
- LARGE_INTEGER MsrValue;
- ULONG APICAddress, CpuInfo[4];
-
- /* Check if we have a local APIC */
- __cpuid((int*)CpuInfo, 1);
- LocalAPIC = (((CpuInfo[3] >> 9) & 1) != 0);
-
- /* If there is no APIC, just return */
- if (!LocalAPIC)
- return;
-
- /* Read the APIC Address */
- MsrValue.QuadPart = __readmsr(0x1B);
- APICAddress = (MsrValue.LowPart & 0xFFFFF000);
-
- DPRINTM(DPRINT_WINDOWS, "Local APIC detected at address 0x%x\n",
- APICAddress);
-
- /* Map it */
- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber
- = APICAddress >> MM_PAGE_SHIFT;
- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1;
- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1;
- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].WriteThrough = 1;
- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].CacheDisable = 1;
-}
-
-BOOLEAN
-WinLdrMapSpecialPages(ULONG PcrBasePage)
-{
-
- //VideoDisplayString(L"Hello from VGA, going into the kernel\n");
- DPRINTM(DPRINT_WINDOWS, "HalPageTable: 0x%X\n", HalPageTable);
-
- // Page Tables have been setup, make special handling for PCR and TSS
- // (which is done in BlSetupFotNt in usual ntldr)
- HalPageTable[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber
= PcrBasePage+1;
- HalPageTable[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1;
- HalPageTable[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1;
-
- HalPageTable[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber =
PcrBasePage;
- HalPageTable[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1;
- HalPageTable[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1;
-
- // Map APIC
- WinLdrpMapApic();
-
- // Map VGA memory
- //VideoMemoryBase = MmMapIoSpace(0xb8000, 4000, MmNonCached);
- //DPRINTM(DPRINT_WINDOWS, "VideoMemoryBase: 0x%X\n", VideoMemoryBase);
-
- return TRUE;
-}
-
-
-VOID
-WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss)
-{
- GDTIDT GdtDesc, IdtDesc, OldIdt;
- PKGDTENTRY pGdt;
- PKIDTENTRY pIdt;
- USHORT Ldt = 0;
- //ULONG i;
-
- DPRINTM(DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n",
- GdtIdt, Pcr, Tss);
-
- // Enable paging
- //BS->ExitBootServices(ImageHandle,MapKey);
-
- // Disable Interrupts
- _disable();
-
- // Re-initalize EFLAGS
- __writeeflags(0);
-
- // Set the PDBR
- __writecr3((ULONG_PTR)PDE);
-
- // Enable paging by modifying CR0
- __writecr0(__readcr0() | CR0_PG);
-
- // Kernel expects the PCR to be zero-filled on startup
- // FIXME: Why zero it here when we can zero it right after allocation?
- RtlZeroMemory((PVOID)Pcr, MM_PAGE_SIZE); //FIXME: Why zero only 1 page when we allocate
2?
-
- // Get old values of GDT and IDT
- Ke386GetGlobalDescriptorTable(&GdtDesc);
- __sidt(&IdtDesc);
-
- // Save old IDT
- OldIdt.Base = IdtDesc.Base;
- OldIdt.Limit = IdtDesc.Limit;
-
- // Prepare new IDT+GDT
- GdtDesc.Base = KSEG0_BASE | (ULONG_PTR)GdtIdt;
- GdtDesc.Limit = NUM_GDT * sizeof(KGDTENTRY) - 1;
- IdtDesc.Base = (ULONG)((PUCHAR)GdtDesc.Base + GdtDesc.Limit + 1);
- IdtDesc.Limit = NUM_IDT * sizeof(KIDTENTRY) - 1;
-
- // ========================
- // Fill all descriptors now
- // ========================
-
- pGdt = (PKGDTENTRY)GdtDesc.Base;
- pIdt = (PKIDTENTRY)IdtDesc.Base;
-
- //
- // Code selector (0x8)
- // Flat 4Gb
- //
- pGdt[1].LimitLow = 0xFFFF;
- pGdt[1].BaseLow = 0;
- pGdt[1].HighWord.Bytes.BaseMid = 0;
- pGdt[1].HighWord.Bytes.Flags1 = 0x9A;
- pGdt[1].HighWord.Bytes.Flags2 = 0xCF;
- pGdt[1].HighWord.Bytes.BaseHi = 0;
-
- //
- // Data selector (0x10)
- // Flat 4Gb
- //
- pGdt[2].LimitLow = 0xFFFF;
- pGdt[2].BaseLow = 0;
- pGdt[2].HighWord.Bytes.BaseMid = 0;
- pGdt[2].HighWord.Bytes.Flags1 = 0x92;
- pGdt[2].HighWord.Bytes.Flags2 = 0xCF;
- pGdt[2].HighWord.Bytes.BaseHi = 0;
-
- //
- // Selector (0x18)
- // Flat 2Gb
- //
- pGdt[3].LimitLow = 0xFFFF;
- pGdt[3].BaseLow = 0;
- pGdt[3].HighWord.Bytes.BaseMid = 0;
- pGdt[3].HighWord.Bytes.Flags1 = 0xFA;
- pGdt[3].HighWord.Bytes.Flags2 = 0xCF;
- pGdt[3].HighWord.Bytes.BaseHi = 0;
-
- //
- // Selector (0x20)
- // Flat 2Gb
- //
- pGdt[4].LimitLow = 0xFFFF;
- pGdt[4].BaseLow = 0;
- pGdt[4].HighWord.Bytes.BaseMid = 0;
- pGdt[4].HighWord.Bytes.Flags1 = 0xF2;
- pGdt[4].HighWord.Bytes.Flags2 = 0xCF;
- pGdt[4].HighWord.Bytes.BaseHi = 0;
-
- //
- // TSS Selector (0x28)
- //
- pGdt[5].LimitLow = 0x78-1; //FIXME: Check this
- pGdt[5].BaseLow = (USHORT)(Tss & 0xffff);
- pGdt[5].HighWord.Bytes.BaseMid = (UCHAR)((Tss >> 16) & 0xff);
- pGdt[5].HighWord.Bytes.Flags1 = 0x89;
- pGdt[5].HighWord.Bytes.Flags2 = 0x00;
- pGdt[5].HighWord.Bytes.BaseHi = (UCHAR)((Tss >> 24) & 0xff);
-
- //
- // PCR Selector (0x30)
- //
- pGdt[6].LimitLow = 0x01;
- pGdt[6].BaseLow = (USHORT)(Pcr & 0xffff);
- pGdt[6].HighWord.Bytes.BaseMid = (UCHAR)((Pcr >> 16) & 0xff);
- pGdt[6].HighWord.Bytes.Flags1 = 0x92;
- pGdt[6].HighWord.Bytes.Flags2 = 0xC0;
- pGdt[6].HighWord.Bytes.BaseHi = (UCHAR)((Pcr >> 24) & 0xff);
-
- //
- // Selector (0x38)
- //
- pGdt[7].LimitLow = 0xFFFF;
- pGdt[7].BaseLow = 0;
- pGdt[7].HighWord.Bytes.BaseMid = 0;
- pGdt[7].HighWord.Bytes.Flags1 = 0xF3;
- pGdt[7].HighWord.Bytes.Flags2 = 0x40;
- pGdt[7].HighWord.Bytes.BaseHi = 0;
-
- //
- // Some BIOS stuff (0x40)
- //
- pGdt[8].LimitLow = 0xFFFF;
- pGdt[8].BaseLow = 0x400;
- pGdt[8].HighWord.Bytes.BaseMid = 0;
- pGdt[8].HighWord.Bytes.Flags1 = 0xF2;
- pGdt[8].HighWord.Bytes.Flags2 = 0x0;
- pGdt[8].HighWord.Bytes.BaseHi = 0;
-
- //
- // Selector (0x48)
- //
- pGdt[9].LimitLow = 0;
- pGdt[9].BaseLow = 0;
- pGdt[9].HighWord.Bytes.BaseMid = 0;
- pGdt[9].HighWord.Bytes.Flags1 = 0;
- pGdt[9].HighWord.Bytes.Flags2 = 0;
- pGdt[9].HighWord.Bytes.BaseHi = 0;
-
- //
- // Selector (0x50)
- //
- pGdt[10].LimitLow = 0xFFFF; //FIXME: Not correct!
- pGdt[10].BaseLow = 0;
- pGdt[10].HighWord.Bytes.BaseMid = 0x2;
- pGdt[10].HighWord.Bytes.Flags1 = 0x89;
- pGdt[10].HighWord.Bytes.Flags2 = 0;
- pGdt[10].HighWord.Bytes.BaseHi = 0;
-
- //
- // Selector (0x58)
- //
- pGdt[11].LimitLow = 0xFFFF;
- pGdt[11].BaseLow = 0;
- pGdt[11].HighWord.Bytes.BaseMid = 0x2;
- pGdt[11].HighWord.Bytes.Flags1 = 0x9A;
- pGdt[11].HighWord.Bytes.Flags2 = 0;
- pGdt[11].HighWord.Bytes.BaseHi = 0;
-
- //
- // Selector (0x60)
- //
- pGdt[12].LimitLow = 0xFFFF;
- pGdt[12].BaseLow = 0; //FIXME: Maybe not correct, but noone cares
- pGdt[12].HighWord.Bytes.BaseMid = 0x2;
- pGdt[12].HighWord.Bytes.Flags1 = 0x92;
- pGdt[12].HighWord.Bytes.Flags2 = 0;
- pGdt[12].HighWord.Bytes.BaseHi = 0;
-
- //
- // Video buffer Selector (0x68)
- //
- pGdt[13].LimitLow = 0x3FFF;
- pGdt[13].BaseLow = 0x8000;
- pGdt[13].HighWord.Bytes.BaseMid = 0x0B;
- pGdt[13].HighWord.Bytes.Flags1 = 0x92;
- pGdt[13].HighWord.Bytes.Flags2 = 0;
- pGdt[13].HighWord.Bytes.BaseHi = 0;
-
- //
- // Points to GDT (0x70)
- //
- pGdt[14].LimitLow = NUM_GDT*sizeof(KGDTENTRY) - 1;
- pGdt[14].BaseLow = 0x7000;
- pGdt[14].HighWord.Bytes.BaseMid = 0xFF;
- pGdt[14].HighWord.Bytes.Flags1 = 0x92;
- pGdt[14].HighWord.Bytes.Flags2 = 0;
- pGdt[14].HighWord.Bytes.BaseHi = 0xFF;
-
- //
- // Some unused descriptors should go here
- //
-
- // Copy the old IDT
- RtlCopyMemory(pIdt, (PVOID)OldIdt.Base, OldIdt.Limit + 1);
-
- // Mask interrupts
- //asm("cli\n"); // they are already masked before enabling paged mode
-
- // Load GDT+IDT
- Ke386SetGlobalDescriptorTable(&GdtDesc);
- __lidt(&IdtDesc);
-
- // Jump to proper CS and clear prefetch queue
-#if defined(__GNUC__)
- asm("ljmp $0x08, $1f\n"
- "1:\n");
-#elif defined(_MSC_VER)
- /* We can't express the above in MASM so we use this far return instead */
- __asm
- {
- push 8
- push offset resume
- retf
- resume:
- };
-#else
-#error
-#endif
-
- // Set SS selector
- Ke386SetSs(0x10); // DataSelector=0x10
-
- // Set DS and ES selectors
- Ke386SetDs(0x10);
- Ke386SetEs(0x10); // this is vital for rep stosd
-
- // LDT = not used ever, thus set to 0
- Ke386SetLocalDescriptorTable(Ldt);
-
- // Load TSR
- Ke386SetTr(KGDT_TSS);
-
- // Clear GS
- Ke386SetGs(0);
-
- // Set FS to PCR
- Ke386SetFs(0x30);
-
- // Real end of the function, just for information
- /* do not uncomment!
- pop edi;
- pop esi;
- pop ebx;
- mov esp, ebp;
- pop ebp;
- ret
- */
-}
-
-#if DBG
-VOID
-MempDump()
-{
- ULONG *PDE_Addr=(ULONG *)PDE;//0xC0300000;
- int i, j;
-
- DPRINTM(DPRINT_WINDOWS, "\nPDE\n");
-
- for (i=0; i<128; i++)
- {
- DPRINTM(DPRINT_WINDOWS, "0x%04X | ", i*8);
-
- for (j=0; j<8; j++)
- {
- DPRINTM(DPRINT_WINDOWS, "0x%08X ", PDE_Addr[i*8+j]);
- }
-
- DPRINTM(DPRINT_WINDOWS, "\n");
- }
-}
-#endif
-
Removed: trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windo…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c (removed)
@@ -1,373 +1,0 @@
-/*
- * FreeLoader
- *
- * Copyright (C) 2009 Aleksey Bragin <aleksey(a)reactos.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <freeldr.h>
-
-#include <ndk/ldrtypes.h>
-#include <arc/setupblk.h>
-
-#include <debug.h>
-
-// TODO: Move to .h
-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
-extern ULONG reactos_disk_count;
-extern ARC_DISK_SIGNATURE reactos_arc_disk_info[];
-extern char reactos_arc_strings[32][256];
-
-extern BOOLEAN UseRealHeap;
-extern ULONG LoaderPagesSpanned;
-
-
-VOID
-SetupLdrLoadNlsData(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPCSTR
SearchPath)
-{
- INFCONTEXT InfContext;
- BOOLEAN Status;
- LPCSTR AnsiName, OemName, LangName;
-
- /* Get ANSI codepage file */
- if (!InfFindFirstLine(InfHandle, "NLS", "AnsiCodepage",
&InfContext))
- {
- printf("Failed to find 'NLS/AnsiCodepage'\n");
- return;
- }
- if (!InfGetDataField(&InfContext, 1, &AnsiName))
- {
- printf("Failed to get load options\n");
- return;
- }
-
- /* Get OEM codepage file */
- if (!InfFindFirstLine(InfHandle, "NLS", "OemCodepage",
&InfContext))
- {
- printf("Failed to find 'NLS/AnsiCodepage'\n");
- return;
- }
- if (!InfGetDataField(&InfContext, 1, &OemName))
- {
- printf("Failed to get load options\n");
- return;
- }
-
- if (!InfFindFirstLine(InfHandle, "NLS", "UnicodeCasetable",
&InfContext))
- {
- printf("Failed to find 'NLS/AnsiCodepage'\n");
- return;
- }
- if (!InfGetDataField(&InfContext, 1, &LangName))
- {
- printf("Failed to get load options\n");
- return;
- }
-
- Status = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName);
- DPRINTM(DPRINT_WINDOWS, "NLS data loaded with status %d\n", Status);
-}
-
-VOID
-SetupLdrScanBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, HINF InfHandle, LPCSTR
SearchPath)
-{
- INFCONTEXT InfContext, dirContext;
- BOOLEAN Status;
- LPCSTR Media, DriverName, dirIndex, ImagePath;
- WCHAR ServiceName[256];
- WCHAR ImagePathW[256];
-
- /* Open inf section */
- if (!InfFindFirstLine(InfHandle, "SourceDisksFiles", NULL,
&InfContext))
- return;
-
- /* Load all listed boot drivers */
- do
- {
- if (InfGetDataField(&InfContext, 7, &Media) &&
- InfGetDataField(&InfContext, 0, &DriverName) &&
- InfGetDataField(&InfContext, 13, &dirIndex))
- {
- if ((strcmp(Media, "x") == 0) &&
- InfFindFirstLine(InfHandle, "Directories", dirIndex,
&dirContext) &&
- InfGetDataField(&dirContext, 1, &ImagePath))
- {
- /* Convert name to widechar */
- swprintf(ServiceName, L"%S", DriverName);
-
- /* Prepare image path */
- swprintf(ImagePathW, L"%S", ImagePath);
- wcscat(ImagePathW, L"\\");
- wcscat(ImagePathW, ServiceName);
-
- /* Remove .sys extension */
- ServiceName[wcslen(ServiceName) - 4] = 0;
-
- /* Add it to the list */
- Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead,
-
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
- ImagePathW,
- ServiceName);
-
- if (!Status)
- {
- DPRINTM(DPRINT_WINDOWS, "could not add boot driver %s,
%s\n", SearchPath, DriverName);
- return;
- }
- }
- }
- } while (InfFindNextLine(&InfContext, &InfContext));
-}
-
-VOID LoadReactOSSetup2(VOID)
-{
- CHAR SystemPath[512], SearchPath[512];
- CHAR FileName[512];
- CHAR BootPath[512];
- LPCSTR LoadOptions, BootOptions;
- BOOLEAN BootFromFloppy;
-#if DBG
- LPCSTR DbgOptions;
-#endif
- PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
- BOOLEAN Status;
- ULONG i, ErrorLine;
- HINF InfHandle;
- INFCONTEXT InfContext;
- PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA;
- PSETUP_LOADER_BLOCK SetupBlock;
- KERNEL_ENTRY_POINT KiSystemStartup;
- PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
- // Mm-related things
- PVOID GdtIdt;
- ULONG PcrBasePage=0;
- ULONG TssBasePage=0;
- LPCSTR SourcePath;
- LPCSTR SourcePaths[] =
- {
- "", /* Only for floppy boot */
-#if defined(_M_IX86)
- "\\I386",
-#elif defined(_M_MPPC)
- "\\PPC",
-#elif defined(_M_MRX000)
- "\\MIPS",
-#endif
- "\\reactos",
- NULL
- };
-
- /* Get boot path */
- MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
-
- /* And check if we booted from floppy */
- BootFromFloppy = strstr(SystemPath, "fdisk") != NULL;
-
- /* Open 'txtsetup.sif' from any of source paths */
- for (i = BootFromFloppy ? 0 : 1; ; i++)
- {
- SourcePath = SourcePaths[i];
- if (!SourcePath)
- {
- printf("Failed to open 'txtsetup.sif'\n");
- return;
- }
- sprintf(FileName, "%s\\txtsetup.sif", SourcePath);
- if (InfOpenFile (&InfHandle, FileName, &ErrorLine))
- {
- sprintf(BootPath, "%s%s\\", SystemPath, SourcePath);
- break;
- }
- }
-
- /* Get Load options - debug and non-debug */
- if (!InfFindFirstLine(InfHandle,
- "SetupData",
- "OsLoadOptions",
- &InfContext))
- {
- printf("Failed to find 'SetupData/OsLoadOptions'\n");
- return;
- }
-
- if (!InfGetDataField (&InfContext, 1, &LoadOptions))
- {
- printf("Failed to get load options\n");
- return;
- }
-
- BootOptions = LoadOptions;
-
-#if DBG
- /* Get debug load options and use them */
- if (InfFindFirstLine(InfHandle,
- "SetupData",
- "DbgOsLoadOptions",
- &InfContext))
- {
- if (!InfGetDataField(&InfContext, 1, &DbgOptions))
- DbgOptions = "";
- else
- BootOptions = DbgOptions;
- }
-#endif
-
- DPRINTM(DPRINT_WINDOWS,"BootOptions: '%s'\n", BootOptions);
-
- SetupUiInitialize();
- 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 */
- AllocateAndInitLPB(&LoaderBlock);
-
- /* Allocate and initialize setup loader block */
- SetupBlock = MmHeapAlloc(sizeof(SETUP_LOADER_BLOCK));
- RtlZeroMemory(SetupBlock, sizeof(SETUP_LOADER_BLOCK));
- LoaderBlock->SetupLdrBlock = SetupBlock;
-
- /* Set textmode setup flag */
- 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 */
- SetupLdrLoadNlsData(LoaderBlock, InfHandle, SearchPath);
-
- /* Get a list of boot drivers */
- 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 */
- WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
-
- /* Initialize Phase 1 - no drivers loading anymore */
- WinLdrInitializePhase1(LoaderBlock, (PCHAR)BootOptions, SystemPath, BootPath,
_WIN32_WINNT_WS03);
-
- /* 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;
-}