Author: tkreuzer Date: Thu Sep 1 19:01:19 2011 New Revision: 53526
URL: http://svn.reactos.org/svn/reactos?rev=53526&view=rev Log: [FREELDR] - Move cleaning the shared user data to after WinLdrSetProcessorContext, as we need the new page tables to be active - Fix indentation/coding style in registry.c - Fix a few 64 bit warnings - delete <arch>/ntsetup.c and rename <arch>/wlmemory.c to <arch>/winldr.c
Added: trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c - copied, changed from r53510, trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c trunk/reactos/boot/freeldr/freeldr/arch/arm/winldr.c - copied unchanged from r53454, trunk/reactos/boot/freeldr/freeldr/arch/arm/wlmemory.c trunk/reactos/boot/freeldr/freeldr/arch/i386/winldr.c - copied unchanged from r53510, trunk/reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c Removed: trunk/reactos/boot/freeldr/freeldr/arch/amd64/ntsetup.c trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c trunk/reactos/boot/freeldr/freeldr/arch/arm/wlmemory.c trunk/reactos/boot/freeldr/freeldr/arch/i386/ntsetup.c trunk/reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c Modified: trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt trunk/reactos/boot/freeldr/freeldr/cmdline.c trunk/reactos/boot/freeldr/freeldr/debug.c trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild trunk/reactos/boot/freeldr/freeldr/fs/ext2.c trunk/reactos/boot/freeldr/freeldr/fs/fat.c trunk/reactos/boot/freeldr/freeldr/include/fs/ext2.h trunk/reactos/boot/freeldr/freeldr/include/mm.h trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c trunk/reactos/boot/freeldr/freeldr/inifile/inifile.c trunk/reactos/boot/freeldr/freeldr/reactos/registry.c trunk/reactos/boot/freeldr/freeldr/windows/winldr.c trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c
Modified: trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/CMakeL... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/CMakeLists.txt [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -112,8 +112,7 @@ arch/i386/xboxmem.c arch/i386/xboxrtc.c arch/i386/xboxvideo.c - arch/i386/ntsetup.c - arch/i386/wlmemory.c + arch/i386/winldr.c windows/headless.c disk/scsiport.c) if(NOT MSVC) @@ -141,8 +140,7 @@ arch/i386/pcmem.c arch/i386/pcrtc.c arch/i386/pcvideo.c - arch/amd64/ntsetup.c - arch/amd64/wlmemory.c) + arch/amd64/winldr.c) else() #TBD endif()
Removed: trunk/reactos/boot/freeldr/freeldr/arch/amd64/ntsetup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/a... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/amd64/ntsetup.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/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@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); -}
Copied: trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c (from r53510, trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c) URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/a... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -23,8 +23,8 @@ //PHARDWARE_PTE HalPageTable;
PVOID GdtIdt; -ULONG PcrBasePage; -ULONG TssBasePage; +ULONG_PTR PcrBasePage; +ULONG_PTR TssBasePage;
/* FUNCTIONS **************************************************************/
@@ -152,6 +152,8 @@ { if (!MempMapSinglePage(VirtualAddress, PhysicalAddress)) { + DPRINTM(DPRINT_WINDOWS, "Failed to map page %ld from %p to %p\n", + i, (PVOID)VirtualAddress, (PVOID)PhysicalAddress); return i; } VirtualAddress += PAGE_SIZE; @@ -172,7 +174,8 @@ StartPage * PAGE_SIZE, NumberOfPages) != NumberOfPages) { - DPRINTM(DPRINT_WINDOWS,"Failed to map pages 1\n"); + DPRINTM(DPRINT_WINDOWS,"Failed to map pages %ld, %ld\n", + StartPage, NumberOfPages); return FALSE; }
@@ -181,7 +184,8 @@ StartPage * PAGE_SIZE, NumberOfPages) != NumberOfPages) { - DPRINTM(DPRINT_WINDOWS,"Failed to map pages 2\n"); + DPRINTM(DPRINT_WINDOWS,"Failed to map pages %ld, %ld\n", + StartPage, NumberOfPages); return FALSE; }
@@ -227,7 +231,7 @@ }
BOOLEAN -WinLdrMapSpecialPages(ULONG PcrBasePage) +WinLdrMapSpecialPages() { /* Map the PCR page */ if (!MempMapSinglePage(KIP0PCRADDRESS, PcrBasePage * PAGE_SIZE)) @@ -350,10 +354,8 @@ DPRINTM(DPRINT_WINDOWS, "leave WinLdrSetProcessorContext\n"); }
-WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock) -{ - ULONG TssSize; - ULONG_PTR KernelStack; +void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock) +{ ULONG_PTR Pcr = 0; ULONG_PTR Tss = 0; ULONG BlockSize, NumPages; @@ -382,24 +384,25 @@ /* 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) + 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; - + 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(); }
Removed: trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/a... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c (removed) @@ -1,410 +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@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; - -PVOID GdtIdt; -ULONG PcrBasePage; -ULONG TssBasePage; - -/* 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 -Amd64SetupGdt(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 -Amd64SetupIdt(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(void) -{ - DPRINTM(DPRINT_WINDOWS, "WinLdrSetProcessorContext\n"); - - /* 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 */ - Amd64SetupGdt(GdtIdt, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT)); - - /* Copy old Idt and set idtr */ - Amd64SetupIdt((PVOID)((ULONG64)GdtIdt + 2048)); // HACK! - - /* LDT is unused */ -// __lldt(0); - - /* Load TSR */ - __ltr(KGDT64_SYS_TSS); - - 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 -MempDump() -{ -} -
Removed: trunk/reactos/boot/freeldr/freeldr/arch/arm/wlmemory.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/a... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/arm/wlmemory.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/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/arch/i386/ntsetup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/ntsetup.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/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@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 **************************************************************/ -#if 0 -// 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); -} -#endif
Removed: trunk/reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c (removed) @@ -1,613 +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@reactos.org) - */ - -/* INCLUDES ***************************************************************/ - -#include <freeldr.h> - -#include <ndk/asm.h> -#include <debug.h> - -// 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; - -ULONG PcrBasePage; -ULONG TssBasePage; -PVOID GdtIdt; - -/* 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(void) -{ - - //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 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 -WinLdrSetProcessorContext(void) -{ - GDTIDT GdtDesc, IdtDesc, OldIdt; - PKGDTENTRY pGdt; - PKIDTENTRY pIdt; - USHORT Ldt = 0; - ULONG Pcr; - ULONG Tss; - //ULONG i; - - Pcr = KIP0PCRADDRESS; - Tss = KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT); - - 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 -
Modified: trunk/reactos/boot/freeldr/freeldr/cmdline.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/cmdlin... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/cmdline.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/cmdline.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -21,14 +21,14 @@ CmdLineParse(IN PCHAR CmdLine) { PCHAR End, Setting; - ULONG Length, Offset = 0; + ULONG_PTR Length, Offset = 0;
// // Set defaults // CmdLineInfo.DefaultOperatingSystem = NULL; CmdLineInfo.TimeOut = -1; - + // // Get timeout // @@ -49,14 +49,14 @@ Setting += sizeof("defaultos=") + sizeof(ANSI_NULL); End = strstr(Setting, " "); if (End) Length = End - Setting; else Length = sizeof(DefaultOs); - + // // Copy the default OS // strncpy(DefaultOs, Setting, Length); CmdLineInfo.DefaultOperatingSystem = DefaultOs; } - + // // Get ramdisk base address // @@ -66,7 +66,7 @@ sizeof(ANSI_NULL), NULL, 0); - + // // Get ramdisk size //
Modified: trunk/reactos/boot/freeldr/freeldr/debug.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/debug.... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -32,15 +32,13 @@ #if defined (DEBUG_ALL) ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM | DPRINT_UI | DPRINT_DISK | DPRINT_CACHE | DPRINT_REACTOS | - DPRINT_LINUX | DPRINT_HWDETECT | DPRINT_PELOADER; + DPRINT_LINUX | DPRINT_HWDETECT | DPRINT_PELOADER | DPRINT_WINDOWS; #elif defined (DEBUG_INIFILE) ULONG DebugPrintMask = DPRINT_INIFILE; #elif defined (DEBUG_REACTOS) ULONG DebugPrintMask = DPRINT_REACTOS | DPRINT_REGISTRY; #elif defined (DEBUG_CUSTOM) -ULONG DebugPrintMask = DPRINT_WARNING | - DPRINT_UI | DPRINT_CACHE | DPRINT_REACTOS | - DPRINT_LINUX; +ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_WINDOWS; #else //#elif defined (DEBUG_NONE) ULONG DebugPrintMask = 0; #endif
Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeld... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -41,8 +41,7 @@ <file>xboxmem.c</file> <file>xboxrtc.c</file> <file>xboxvideo.c</file> - <file>ntsetup.c</file> - <file>wlmemory.c</file> + <file>winldr.c</file> </if> </directory> <directory name="powerpc"> @@ -71,8 +70,7 @@ <if property="ARCH" value="amd64"> <directory name="amd64"> <file>loader.c</file> - <file>ntsetup.c</file> - <file>wlmemory.c</file> + <file>winldr.c</file> </directory> <directory name="i386"> <file>hardware.c</file> @@ -93,7 +91,7 @@
<if property="ARCH" value="arm"> <directory name="arm"> - <file>wlmemory.c</file> + <file>winldr.c</file> </directory> </if> </directory>
Modified: trunk/reactos/boot/freeldr/freeldr/fs/ext2.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/fs/ext... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/fs/ext2.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/fs/ext2.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -118,7 +118,7 @@ PEXT2_FILE_INFO FileHandle; CHAR SymLinkPath[EXT2_NAME_LEN]; CHAR FullPath[EXT2_NAME_LEN * 2]; - ULONG Index; + ULONG_PTR Index;
DPRINTM(DPRINT_FILESYSTEM, "Ext2OpenFile() FileName = %s\n", FileName);
Modified: trunk/reactos/boot/freeldr/freeldr/fs/fat.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/fs/fat... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/fs/fat.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/fs/fat.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -650,7 +650,7 @@ { ULONG EntryCount; ULONG CurrentEntry; - ULONG FileNameLen; + SIZE_T FileNameLen; FATX_DIRENTRY OurDirEntry; PFATX_DIRENTRY DirEntry = &OurDirEntry;
Modified: trunk/reactos/boot/freeldr/freeldr/include/fs/ext2.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/fs/ext2.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/fs/ext2.h [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -183,7 +183,7 @@ #define LOG2_BLOCK_SIZE(sb) (sb->log2_block_size + 10)
/* The size of an ext2 block in bytes. */ -#define EXT2_BLOCK_SIZE(sb) (1 << LOG2_BLOCK_SIZE(sb)) +#define EXT2_BLOCK_SIZE(sb) (((SIZE_T)1) << LOG2_BLOCK_SIZE(sb))
/* The revision level. */ #define EXT2_REVISION(sb) (sb->revision_level)
Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -117,7 +117,7 @@ PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType); PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType);
-PVOID MmHeapAlloc(ULONG MemorySize); +PVOID MmHeapAlloc(SIZE_T MemorySize); VOID MmHeapFree(PVOID MemoryPointer);
#define ExAllocatePool(pool, size) MmHeapAlloc(size)
Modified: trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inffil... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -320,7 +320,7 @@ if (Line->Key != NULL) return NULL;
- Line->Key = (PCHAR)MmHeapAlloc (strlen (Key) + 1); + Line->Key = MmHeapAlloc(strlen(Key) + 1); if (Line->Key == NULL) return NULL;
@@ -431,7 +431,7 @@ /* push data from current token start up to pos into the current token */ static int push_token( struct parser *parser, const CHAR *pos ) { - unsigned int len = pos - parser->start; + SIZE_T len = pos - parser->start; const CHAR *src = parser->start; CHAR *dst = parser->token + parser->token_len;
Modified: trunk/reactos/boot/freeldr/freeldr/inifile/inifile.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inifil... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/inifile/inifile.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/inifile/inifile.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -93,7 +93,7 @@ return 0;
// Return the size of the string plus 1 for the null-terminator - return (strlen(SectionItem->ItemName) + 1); + return (ULONG)(strlen(SectionItem->ItemName) + 1); }
ULONG IniGetSectionSettingValueSize(ULONG_PTR SectionId, ULONG SettingIndex) @@ -106,7 +106,7 @@ return 0;
// Return the size of the string plus 1 for the null-terminator - return (strlen(SectionItem->ItemValue) + 1); + return (ULONG)(strlen(SectionItem->ItemValue) + 1); }
BOOLEAN IniReadSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize)
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/registry.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/reacto... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/reactos/registry.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/reactos/registry.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -27,774 +27,731 @@ VOID RegInitializeRegistry (VOID) { - /* Create root key */ - RootKey = (FRLDRHKEY) MmHeapAlloc (sizeof(KEY)); - - InitializeListHead (&RootKey->SubKeyList); - InitializeListHead (&RootKey->ValueList); - InitializeListHead (&RootKey->KeyList); - - RootKey->SubKeyCount = 0; - RootKey->ValueCount = 0; - - RootKey->NameSize = 4; - RootKey->Name = MmHeapAlloc (4); - wcscpy (RootKey->Name, L"\"); - - RootKey->DataType = 0; - RootKey->DataSize = 0; - RootKey->Data = NULL; - - /* Create 'SYSTEM' key */ - RegCreateKey (RootKey, - L"Registry\Machine\SYSTEM", - NULL); + /* Create root key */ + RootKey = MmHeapAlloc(sizeof(KEY)); + + InitializeListHead(&RootKey->SubKeyList); + InitializeListHead(&RootKey->ValueList); + InitializeListHead(&RootKey->KeyList); + + RootKey->SubKeyCount = 0; + RootKey->ValueCount = 0; + + RootKey->NameSize = 4; + RootKey->Name = MmHeapAlloc(4); + wcscpy (RootKey->Name, L"\"); + + RootKey->DataType = 0; + RootKey->DataSize = 0; + RootKey->Data = NULL; + + /* Create 'SYSTEM' key */ + RegCreateKey (RootKey, + L"Registry\Machine\SYSTEM", + NULL); }
LONG RegInitCurrentControlSet(BOOLEAN LastKnownGood) { - WCHAR ControlSetKeyName[80]; - FRLDRHKEY SelectKey; - FRLDRHKEY SystemKey; - FRLDRHKEY ControlSetKey; - FRLDRHKEY LinkKey; - ULONG CurrentSet = 0; - ULONG DefaultSet = 0; - ULONG LastKnownGoodSet = 0; - ULONG DataSize; - LONG Error; - - Error = RegOpenKey(NULL, - L"\Registry\Machine\SYSTEM\Select", - &SelectKey); - if (Error != ERROR_SUCCESS) - { - DPRINTM(DPRINT_REGISTRY, "RegOpenKey() failed (Error %u)\n", (int)Error); - return(Error); - } - - DataSize = sizeof(ULONG); - Error = RegQueryValue(SelectKey, - L"Default", - NULL, - (PUCHAR)&DefaultSet, - &DataSize); - if (Error != ERROR_SUCCESS) - { - DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); - return(Error); - } - - DataSize = sizeof(ULONG); - Error = RegQueryValue(SelectKey, - L"LastKnownGood", - NULL, - (PUCHAR)&LastKnownGoodSet, - &DataSize); - if (Error != ERROR_SUCCESS) - { - DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); - return(Error); - } - - CurrentSet = (LastKnownGood == TRUE) ? LastKnownGoodSet : DefaultSet; - wcscpy(ControlSetKeyName, L"ControlSet"); - switch(CurrentSet) - { - case 1: - wcscat(ControlSetKeyName, L"001"); - break; - case 2: - wcscat(ControlSetKeyName, L"002"); - break; - case 3: - wcscat(ControlSetKeyName, L"003"); - break; - case 4: - wcscat(ControlSetKeyName, L"004"); - break; - case 5: - wcscat(ControlSetKeyName, L"005"); - break; - } - - Error = RegOpenKey(NULL, - L"\Registry\Machine\SYSTEM", - &SystemKey); - if (Error != ERROR_SUCCESS) - { - DPRINTM(DPRINT_REGISTRY, "RegOpenKey(SystemKey) failed (Error %u)\n", (int)Error); - return(Error); - } - - Error = RegOpenKey(SystemKey, - ControlSetKeyName, - &ControlSetKey); - if (Error != ERROR_SUCCESS) - { - DPRINTM(DPRINT_REGISTRY, "RegOpenKey(ControlSetKey) failed (Error %u)\n", (int)Error); - return(Error); - } - - Error = RegCreateKey(SystemKey, - L"CurrentControlSet", - &LinkKey); - if (Error != ERROR_SUCCESS) - { - DPRINTM(DPRINT_REGISTRY, "RegCreateKey(LinkKey) failed (Error %u)\n", (int)Error); - return(Error); - } - - Error = RegSetValue(LinkKey, - NULL, - REG_LINK, - (PCHAR)&ControlSetKey, - sizeof(PVOID)); - if (Error != ERROR_SUCCESS) - { - DPRINTM(DPRINT_REGISTRY, "RegSetValue(LinkKey) failed (Error %u)\n", (int)Error); - return(Error); - } - - return(ERROR_SUCCESS); + WCHAR ControlSetKeyName[80]; + FRLDRHKEY SelectKey; + FRLDRHKEY SystemKey; + FRLDRHKEY ControlSetKey; + FRLDRHKEY LinkKey; + ULONG CurrentSet = 0; + ULONG DefaultSet = 0; + ULONG LastKnownGoodSet = 0; + ULONG DataSize; + LONG Error; + + Error = RegOpenKey(NULL, + L"\Registry\Machine\SYSTEM\Select", + &SelectKey); + if (Error != ERROR_SUCCESS) + { + DPRINTM(DPRINT_REGISTRY, "RegOpenKey() failed (Error %u)\n", (int)Error); + return Error; + } + + DataSize = sizeof(ULONG); + Error = RegQueryValue(SelectKey, + L"Default", + NULL, + (PUCHAR)&DefaultSet, + &DataSize); + if (Error != ERROR_SUCCESS) + { + DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); + return Error; + } + + DataSize = sizeof(ULONG); + Error = RegQueryValue(SelectKey, + L"LastKnownGood", + NULL, + (PUCHAR)&LastKnownGoodSet, + &DataSize); + if (Error != ERROR_SUCCESS) + { + DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); + return Error; + } + + CurrentSet = (LastKnownGood == TRUE) ? LastKnownGoodSet : DefaultSet; + wcscpy(ControlSetKeyName, L"ControlSet"); + switch(CurrentSet) + { + case 1: + wcscat(ControlSetKeyName, L"001"); + break; + case 2: + wcscat(ControlSetKeyName, L"002"); + break; + case 3: + wcscat(ControlSetKeyName, L"003"); + break; + case 4: + wcscat(ControlSetKeyName, L"004"); + break; + case 5: + wcscat(ControlSetKeyName, L"005"); + break; + } + + Error = RegOpenKey(NULL, + L"\Registry\Machine\SYSTEM", + &SystemKey); + if (Error != ERROR_SUCCESS) + { + DPRINTM(DPRINT_REGISTRY, "RegOpenKey(SystemKey) failed (Error %lu)\n", Error); + return Error; + } + + Error = RegOpenKey(SystemKey, + ControlSetKeyName, + &ControlSetKey); + if (Error != ERROR_SUCCESS) + { + DPRINTM(DPRINT_REGISTRY, "RegOpenKey(ControlSetKey) failed (Error %lu)\n", Error); + return Error; + } + + Error = RegCreateKey(SystemKey, + L"CurrentControlSet", + &LinkKey); + if (Error != ERROR_SUCCESS) + { + DPRINTM(DPRINT_REGISTRY, "RegCreateKey(LinkKey) failed (Error %lu)\n", Error); + return Error; + } + + Error = RegSetValue(LinkKey, + NULL, + REG_LINK, + (PCHAR)&ControlSetKey, + sizeof(PVOID)); + if (Error != ERROR_SUCCESS) + { + DPRINTM(DPRINT_REGISTRY, "RegSetValue(LinkKey) failed (Error %lu)\n", Error); + return Error; + } + + return ERROR_SUCCESS; }
LONG RegCreateKey(FRLDRHKEY ParentKey, - PCWSTR KeyName, - PFRLDRHKEY Key) -{ - PLIST_ENTRY Ptr; - FRLDRHKEY SearchKey = NULL; - FRLDRHKEY CurrentKey; - FRLDRHKEY NewKey; - PWCHAR p; - PCWSTR name; - int subkeyLength; - int stringLength; - ULONG NameSize; - int CmpResult; - - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - - if (*KeyName == L'\') - { - KeyName++; - CurrentKey = RootKey; - } - else if (ParentKey == NULL) - { - CurrentKey = RootKey; - } - else - { - CurrentKey = ParentKey; - } - - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) - { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; - } - - while (*KeyName != 0) - { - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - - if (*KeyName == L'\') - KeyName++; - p = wcschr(KeyName, L'\'); - if ((p != NULL) && (p != KeyName)) - { - subkeyLength = p - KeyName; - stringLength = subkeyLength + 1; - name = KeyName; - } - else - { - subkeyLength = wcslen(KeyName); - stringLength = subkeyLength; - name = KeyName; - } - NameSize = (subkeyLength + 1) * sizeof(WCHAR); - - Ptr = CurrentKey->SubKeyList.Flink; - CmpResult = 1; - while (Ptr != &CurrentKey->SubKeyList) - { - DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); - - SearchKey = CONTAINING_RECORD(Ptr, - KEY, - KeyList); - DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); - DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); - CmpResult = _wcsnicmp(SearchKey->Name, name, subkeyLength); - if (CmpResult == 0 && SearchKey->NameSize == NameSize) - break; - else if (CmpResult == -1) - break; - - Ptr = Ptr->Flink; - } - - if (CmpResult != 0) - { - /* no key found -> create new subkey */ - NewKey = (FRLDRHKEY)MmHeapAlloc(sizeof(KEY)); - if (NewKey == NULL) - return(ERROR_OUTOFMEMORY); - - InitializeListHead(&NewKey->SubKeyList); - InitializeListHead(&NewKey->ValueList); - - NewKey->SubKeyCount = 0; - NewKey->ValueCount = 0; - - NewKey->DataType = 0; - NewKey->DataSize = 0; - NewKey->Data = NULL; - - InsertTailList(Ptr, &NewKey->KeyList); - CurrentKey->SubKeyCount++; - - NewKey->NameSize = NameSize; - NewKey->Name = (PWCHAR)MmHeapAlloc(NewKey->NameSize); - if (NewKey->Name == NULL) - return(ERROR_OUTOFMEMORY); - memcpy(NewKey->Name, name, NewKey->NameSize - sizeof(WCHAR)); - NewKey->Name[subkeyLength] = 0; - - DPRINTM(DPRINT_REGISTRY, "NewKey 0x%x\n", NewKey); - DPRINTM(DPRINT_REGISTRY, "NewKey '%S' Length %d\n", NewKey->Name, NewKey->NameSize); - - CurrentKey = NewKey; - } - else - { - CurrentKey = SearchKey; - - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) - { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; - } - } - - KeyName = KeyName + stringLength; - } - - if (Key != NULL) - *Key = CurrentKey; - - return(ERROR_SUCCESS); + PCWSTR KeyName, + PFRLDRHKEY Key) +{ + PLIST_ENTRY Ptr; + FRLDRHKEY SearchKey = NULL; + FRLDRHKEY CurrentKey; + FRLDRHKEY NewKey; + PWCHAR p; + PCWSTR name; + int subkeyLength; + int stringLength; + ULONG NameSize; + int CmpResult; + + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + + if (*KeyName == L'\') + { + KeyName++; + CurrentKey = RootKey; + } + else if (ParentKey == NULL) + { + CurrentKey = RootKey; + } + else + { + CurrentKey = ParentKey; + } + + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) + { + CurrentKey = (FRLDRHKEY)CurrentKey->Data; + } + + while (*KeyName != 0) + { + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + + if (*KeyName == L'\') + KeyName++; + p = wcschr(KeyName, L'\'); + if ((p != NULL) && (p != KeyName)) + { + subkeyLength = p - KeyName; + stringLength = subkeyLength + 1; + name = KeyName; + } + else + { + subkeyLength = wcslen(KeyName); + stringLength = subkeyLength; + name = KeyName; + } + NameSize = (subkeyLength + 1) * sizeof(WCHAR); + + Ptr = CurrentKey->SubKeyList.Flink; + CmpResult = 1; + while (Ptr != &CurrentKey->SubKeyList) + { + DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); + + SearchKey = CONTAINING_RECORD(Ptr, KEY, KeyList); + DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); + DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); + CmpResult = _wcsnicmp(SearchKey->Name, name, subkeyLength); + + if (CmpResult == 0 && SearchKey->NameSize == NameSize) break; + else if (CmpResult == -1) break; + + Ptr = Ptr->Flink; + } + + if (CmpResult != 0) + { + /* no key found -> create new subkey */ + NewKey = MmHeapAlloc(sizeof(KEY)); + if (NewKey == NULL) return ERROR_OUTOFMEMORY; + + InitializeListHead(&NewKey->SubKeyList); + InitializeListHead(&NewKey->ValueList); + + NewKey->SubKeyCount = 0; + NewKey->ValueCount = 0; + + NewKey->DataType = 0; + NewKey->DataSize = 0; + NewKey->Data = NULL; + + InsertTailList(Ptr, &NewKey->KeyList); + CurrentKey->SubKeyCount++; + + NewKey->NameSize = NameSize; + NewKey->Name = (PWCHAR)MmHeapAlloc(NewKey->NameSize); + if (NewKey->Name == NULL) return ERROR_OUTOFMEMORY; + + memcpy(NewKey->Name, name, NewKey->NameSize - sizeof(WCHAR)); + NewKey->Name[subkeyLength] = 0; + + DPRINTM(DPRINT_REGISTRY, "NewKey 0x%x\n", NewKey); + DPRINTM(DPRINT_REGISTRY, "NewKey '%S' Length %d\n", NewKey->Name, NewKey->NameSize); + + CurrentKey = NewKey; + } + else + { + CurrentKey = SearchKey; + + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) + { + CurrentKey = (FRLDRHKEY)CurrentKey->Data; + } + } + + KeyName = KeyName + stringLength; + } + + if (Key != NULL) *Key = CurrentKey; + + return ERROR_SUCCESS; }
LONG RegDeleteKey(FRLDRHKEY Key, - PCWSTR Name) -{ - - - if (wcschr(Name, L'\') != NULL) - return(ERROR_INVALID_PARAMETER); - - - - return(ERROR_SUCCESS); + PCWSTR Name) +{ + + if (wcschr(Name, L'\') != NULL) return ERROR_INVALID_PARAMETER; + + return ERROR_SUCCESS; }
LONG RegEnumKey(FRLDRHKEY Key, - ULONG Index, - PWCHAR Name, - ULONG* NameSize) -{ - PLIST_ENTRY Ptr; - FRLDRHKEY SearchKey; - ULONG Count = 0; - ULONG Size; - - Ptr = Key->SubKeyList.Flink; - while (Ptr != &Key->SubKeyList) - { - if (Index == Count) - break; - - Count++; - Ptr = Ptr->Flink; - } - - if (Ptr == &Key->SubKeyList) - return(ERROR_NO_MORE_ITEMS); - - SearchKey = CONTAINING_RECORD(Ptr, - KEY, - KeyList); - - DPRINTM(DPRINT_REGISTRY, "Name '%S' Length %d\n", SearchKey->Name, SearchKey->NameSize); - - Size = min(SearchKey->NameSize, *NameSize); - *NameSize = Size; - memcpy(Name, SearchKey->Name, Size); - - return(ERROR_SUCCESS); + ULONG Index, + PWCHAR Name, + ULONG* NameSize) +{ + PLIST_ENTRY Ptr; + FRLDRHKEY SearchKey; + ULONG Count = 0; + ULONG Size; + + Ptr = Key->SubKeyList.Flink; + while (Ptr != &Key->SubKeyList) + { + if (Index == Count) break; + + Count++; + Ptr = Ptr->Flink; + } + + if (Ptr == &Key->SubKeyList) return ERROR_NO_MORE_ITEMS; + + SearchKey = CONTAINING_RECORD(Ptr, KEY, KeyList); + + DPRINTM(DPRINT_REGISTRY, "Name '%S' Length %d\n", SearchKey->Name, SearchKey->NameSize); + + Size = min(SearchKey->NameSize, *NameSize); + *NameSize = Size; + memcpy(Name, SearchKey->Name, Size); + + return ERROR_SUCCESS; }
LONG RegOpenKey(FRLDRHKEY ParentKey, - PCWSTR KeyName, - PFRLDRHKEY Key) -{ - PLIST_ENTRY Ptr; - FRLDRHKEY SearchKey = NULL; - FRLDRHKEY CurrentKey; - PWCHAR p; - PCWSTR name; - int subkeyLength; - int stringLength; - ULONG NameSize; - - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - - *Key = NULL; - - if (*KeyName == L'\') - { - KeyName++; - CurrentKey = RootKey; - } - else if (ParentKey == NULL) - { - CurrentKey = RootKey; - } - else - { - CurrentKey = ParentKey; - } - - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) - { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; - } - - while (*KeyName != 0) - { - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - - if (*KeyName == L'\') - KeyName++; - p = wcschr(KeyName, L'\'); - if ((p != NULL) && (p != KeyName)) - { - subkeyLength = p - KeyName; - stringLength = subkeyLength + 1; - name = KeyName; - } - else - { - subkeyLength = wcslen(KeyName); - stringLength = subkeyLength; - name = KeyName; - } - NameSize = (subkeyLength + 1) * sizeof(WCHAR); - - Ptr = CurrentKey->SubKeyList.Flink; - while (Ptr != &CurrentKey->SubKeyList) - { - DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); - - SearchKey = CONTAINING_RECORD(Ptr, - KEY, - KeyList); - - DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); - DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); - - if (SearchKey->NameSize == NameSize && - _wcsnicmp(SearchKey->Name, name, subkeyLength) == 0) - break; - - Ptr = Ptr->Flink; - } - - if (Ptr == &CurrentKey->SubKeyList) - { - return(ERROR_PATH_NOT_FOUND); - } - else - { - CurrentKey = SearchKey; - - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) - { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; - } - } - - KeyName = KeyName + stringLength; - } - - if (Key != NULL) - *Key = CurrentKey; - - return(ERROR_SUCCESS); + PCWSTR KeyName, + PFRLDRHKEY Key) +{ + PLIST_ENTRY Ptr; + FRLDRHKEY SearchKey = NULL; + FRLDRHKEY CurrentKey; + PWCHAR p; + PCWSTR name; + int subkeyLength; + int stringLength; + ULONG NameSize; + + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + + *Key = NULL; + + if (*KeyName == L'\') + { + KeyName++; + CurrentKey = RootKey; + } + else if (ParentKey == NULL) + { + CurrentKey = RootKey; + } + else + { + CurrentKey = ParentKey; + } + + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) + { + CurrentKey = (FRLDRHKEY)CurrentKey->Data; + } + + while (*KeyName != 0) + { + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + + if (*KeyName == L'\') KeyName++; + p = wcschr(KeyName, L'\'); + if ((p != NULL) && (p != KeyName)) + { + subkeyLength = p - KeyName; + stringLength = subkeyLength + 1; + name = KeyName; + } + else + { + subkeyLength = wcslen(KeyName); + stringLength = subkeyLength; + name = KeyName; + } + NameSize = (subkeyLength + 1) * sizeof(WCHAR); + + Ptr = CurrentKey->SubKeyList.Flink; + while (Ptr != &CurrentKey->SubKeyList) + { + DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); + + SearchKey = CONTAINING_RECORD(Ptr, KEY, KeyList); + + DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); + DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); + + if (SearchKey->NameSize == NameSize && + _wcsnicmp(SearchKey->Name, name, subkeyLength) == 0) break; + + Ptr = Ptr->Flink; + } + + if (Ptr == &CurrentKey->SubKeyList) + { + return ERROR_PATH_NOT_FOUND; + } + else + { + CurrentKey = SearchKey; + + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) + { + CurrentKey = (FRLDRHKEY)CurrentKey->Data; + } + } + + KeyName = KeyName + stringLength; + } + + if (Key != NULL) + *Key = CurrentKey; + + return ERROR_SUCCESS; }
LONG RegSetValue(FRLDRHKEY Key, - PCWSTR ValueName, - ULONG Type, - PCSTR Data, - ULONG DataSize) -{ - PLIST_ENTRY Ptr; - PVALUE Value = NULL; - - DPRINTM(DPRINT_REGISTRY, "Key 0x%p, ValueName '%S', Type %ld, Data 0x%p, DataSize %ld\n", - Key, ValueName, Type, Data, DataSize); - - if ((ValueName == NULL) || (*ValueName == 0)) - { - /* set default value */ - if ((Key->Data != NULL) && (Key->DataSize > sizeof(PUCHAR))) - { - MmHeapFree(Key->Data); - } - - if (DataSize <= sizeof(PUCHAR)) - { - Key->DataSize = DataSize; - Key->DataType = Type; - memcpy(&Key->Data, Data, DataSize); - } - else - { - Key->Data = MmHeapAlloc(DataSize); - Key->DataSize = DataSize; - Key->DataType = Type; - memcpy(Key->Data, Data, DataSize); - } - } - else - { - /* set non-default value */ - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) - { - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); - - DPRINTM(DPRINT_REGISTRY, "Value->Name '%S'\n", Value->Name); - - if (_wcsicmp(Value->Name, ValueName) == 0) - break; - - Ptr = Ptr->Flink; - } - - if (Ptr == &Key->ValueList) - { - /* add new value */ - DPRINTM(DPRINT_REGISTRY, "No value found - adding new value\n"); - - Value = (PVALUE)MmHeapAlloc(sizeof(VALUE)); - if (Value == NULL) - return(ERROR_OUTOFMEMORY); - - InsertTailList(&Key->ValueList, &Value->ValueList); - Key->ValueCount++; - - Value->NameSize = (wcslen(ValueName)+1)*sizeof(WCHAR); - Value->Name = (PWCHAR)MmHeapAlloc(Value->NameSize); - if (Value->Name == NULL) - return(ERROR_OUTOFMEMORY); - wcscpy(Value->Name, ValueName); - Value->DataType = REG_NONE; - Value->DataSize = 0; - Value->Data = NULL; - } - - /* set new value */ - if ((Value->Data != NULL) && (Value->DataSize > sizeof(PUCHAR))) - { - MmHeapFree(Value->Data); - } - - if (DataSize <= sizeof(PUCHAR)) - { - Value->DataSize = DataSize; - Value->DataType = Type; - memcpy(&Value->Data, Data, DataSize); - } - else - { - Value->Data = MmHeapAlloc(DataSize); - if (Value->Data == NULL) - return(ERROR_OUTOFMEMORY); - Value->DataType = Type; - Value->DataSize = DataSize; - memcpy(Value->Data, Data, DataSize); - } - } - return(ERROR_SUCCESS); + PCWSTR ValueName, + ULONG Type, + PCSTR Data, + ULONG DataSize) +{ + PLIST_ENTRY Ptr; + PVALUE Value = NULL; + + DPRINTM(DPRINT_REGISTRY, "Key 0x%p, ValueName '%S', Type %ld, Data 0x%p, DataSize %ld\n", + Key, ValueName, Type, Data, DataSize); + + if ((ValueName == NULL) || (*ValueName == 0)) + { + /* set default value */ + if ((Key->Data != NULL) && (Key->DataSize > sizeof(PUCHAR))) + { + MmHeapFree(Key->Data); + } + + if (DataSize <= sizeof(PUCHAR)) + { + Key->DataSize = DataSize; + Key->DataType = Type; + memcpy(&Key->Data, Data, DataSize); + } + else + { + Key->Data = MmHeapAlloc(DataSize); + Key->DataSize = DataSize; + Key->DataType = Type; + memcpy(Key->Data, Data, DataSize); + } + } + else + { + /* set non-default value */ + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) + { + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); + + DPRINTM(DPRINT_REGISTRY, "Value->Name '%S'\n", Value->Name); + + if (_wcsicmp(Value->Name, ValueName) == 0) break; + + Ptr = Ptr->Flink; + } + + if (Ptr == &Key->ValueList) + { + /* add new value */ + DPRINTM(DPRINT_REGISTRY, "No value found - adding new value\n"); + + Value = (PVALUE)MmHeapAlloc(sizeof(VALUE)); + if (Value == NULL) return ERROR_OUTOFMEMORY; + + InsertTailList(&Key->ValueList, &Value->ValueList); + Key->ValueCount++; + + Value->NameSize = (wcslen(ValueName)+1) * sizeof(WCHAR); + Value->Name = MmHeapAlloc(Value->NameSize); + if (Value->Name == NULL) return ERROR_OUTOFMEMORY; + wcscpy(Value->Name, ValueName); + Value->DataType = REG_NONE; + Value->DataSize = 0; + Value->Data = NULL; + } + + /* set new value */ + if ((Value->Data != NULL) && (Value->DataSize > sizeof(PUCHAR))) + { + MmHeapFree(Value->Data); + } + + if (DataSize <= sizeof(PUCHAR)) + { + Value->DataSize = DataSize; + Value->DataType = Type; + memcpy(&Value->Data, Data, DataSize); + } + else + { + Value->Data = MmHeapAlloc(DataSize); + if (Value->Data == NULL) return ERROR_OUTOFMEMORY; + Value->DataType = Type; + Value->DataSize = DataSize; + memcpy(Value->Data, Data, DataSize); + } + } + return(ERROR_SUCCESS); }
LONG RegQueryValue(FRLDRHKEY Key, - PCWSTR ValueName, - ULONG* Type, - PUCHAR Data, - ULONG* DataSize) -{ - ULONG Size; - PLIST_ENTRY Ptr; - PVALUE Value = NULL; - - if ((ValueName == NULL) || (*ValueName == 0)) - { - /* query default value */ - if (Key->Data == NULL) - return(ERROR_INVALID_PARAMETER); - - if (Type != NULL) - *Type = Key->DataType; - if ((Data != NULL) && (DataSize != NULL)) - { - if (Key->DataSize <= sizeof(PUCHAR)) - { - Size = min(Key->DataSize, *DataSize); - memcpy(Data, &Key->Data, Size); - *DataSize = Size; - } - else - { - Size = min(Key->DataSize, *DataSize); - memcpy(Data, Key->Data, Size); - *DataSize = Size; - } - } - else if ((Data == NULL) && (DataSize != NULL)) - { - *DataSize = Key->DataSize; - } - } - else - { - /* query non-default value */ - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) - { - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); - - DPRINTM(DPRINT_REGISTRY, "Searching for '%S'. Value name '%S'\n", ValueName, Value->Name); - - if (_wcsicmp(Value->Name, ValueName) == 0) - break; - - Ptr = Ptr->Flink; - } - - if (Ptr == &Key->ValueList) - return(ERROR_INVALID_PARAMETER); - - if (Type != NULL) - *Type = Value->DataType; - if ((Data != NULL) && (DataSize != NULL)) - { - if (Value->DataSize <= sizeof(PUCHAR)) - { - Size = min(Value->DataSize, *DataSize); - memcpy(Data, &Value->Data, Size); - *DataSize = Size; - } - else - { - Size = min(Value->DataSize, *DataSize); - memcpy(Data, Value->Data, Size); - *DataSize = Size; - } - } - else if ((Data == NULL) && (DataSize != NULL)) - { - *DataSize = Value->DataSize; - } - } - - return(ERROR_SUCCESS); + PCWSTR ValueName, + ULONG* Type, + PUCHAR Data, + ULONG* DataSize) +{ + ULONG Size; + PLIST_ENTRY Ptr; + PVALUE Value = NULL; + + if ((ValueName == NULL) || (*ValueName == 0)) + { + /* query default value */ + if (Key->Data == NULL) return ERROR_INVALID_PARAMETER; + + if (Type != NULL) + *Type = Key->DataType; + if ((Data != NULL) && (DataSize != NULL)) + { + if (Key->DataSize <= sizeof(PUCHAR)) + { + Size = min(Key->DataSize, *DataSize); + memcpy(Data, &Key->Data, Size); + *DataSize = Size; + } + else + { + Size = min(Key->DataSize, *DataSize); + memcpy(Data, Key->Data, Size); + *DataSize = Size; + } + } + else if ((Data == NULL) && (DataSize != NULL)) + { + *DataSize = Key->DataSize; + } + } + else + { + /* query non-default value */ + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) + { + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); + + DPRINTM(DPRINT_REGISTRY, "Searching for '%S'. Value name '%S'\n", ValueName, Value->Name); + + if (_wcsicmp(Value->Name, ValueName) == 0) break; + + Ptr = Ptr->Flink; + } + + if (Ptr == &Key->ValueList) return ERROR_INVALID_PARAMETER; + + if (Type != NULL) *Type = Value->DataType; + if ((Data != NULL) && (DataSize != NULL)) + { + if (Value->DataSize <= sizeof(PUCHAR)) + { + Size = min(Value->DataSize, *DataSize); + memcpy(Data, &Value->Data, Size); + *DataSize = Size; + } + else + { + Size = min(Value->DataSize, *DataSize); + memcpy(Data, Value->Data, Size); + *DataSize = Size; + } + } + else if ((Data == NULL) && (DataSize != NULL)) + { + *DataSize = Value->DataSize; + } + } + + return ERROR_SUCCESS; }
LONG RegDeleteValue(FRLDRHKEY Key, - PCWSTR ValueName) -{ - PLIST_ENTRY Ptr; - PVALUE Value = NULL; - - if ((ValueName == NULL) || (*ValueName == 0)) - { - /* delete default value */ - if (Key->Data != NULL) - MmFreeMemory(Key->Data); - Key->Data = NULL; - Key->DataSize = 0; - Key->DataType = 0; - } - else - { - /* delete non-default value */ - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) - { - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); - if (_wcsicmp(Value->Name, ValueName) == 0) - break; - - Ptr = Ptr->Flink; - } - - if (Ptr == &Key->ValueList) - return(ERROR_INVALID_PARAMETER); - - /* delete value */ - Key->ValueCount--; - if (Value->Name != NULL) - MmFreeMemory(Value->Name); - Value->Name = NULL; - Value->NameSize = 0; - - if (Value->DataSize > sizeof(PUCHAR)) - { - if (Value->Data != NULL) - MmFreeMemory(Value->Data); - } - Value->Data = NULL; - Value->DataSize = 0; - Value->DataType = 0; - - RemoveEntryList(&Value->ValueList); - MmFreeMemory(Value); - } - return(ERROR_SUCCESS); + PCWSTR ValueName) +{ + PLIST_ENTRY Ptr; + PVALUE Value = NULL; + + if ((ValueName == NULL) || (*ValueName == 0)) + { + /* delete default value */ + if (Key->Data != NULL) MmFreeMemory(Key->Data); + Key->Data = NULL; + Key->DataSize = 0; + Key->DataType = 0; + } + else + { + /* delete non-default value */ + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) + { + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); + if (_wcsicmp(Value->Name, ValueName) == 0) break; + + Ptr = Ptr->Flink; + } + + if (Ptr == &Key->ValueList) return ERROR_INVALID_PARAMETER; + + /* delete value */ + Key->ValueCount--; + if (Value->Name != NULL) MmFreeMemory(Value->Name); + Value->Name = NULL; + Value->NameSize = 0; + + if (Value->DataSize > sizeof(PUCHAR)) + { + if (Value->Data != NULL) MmFreeMemory(Value->Data); + } + Value->Data = NULL; + Value->DataSize = 0; + Value->DataType = 0; + + RemoveEntryList(&Value->ValueList); + MmFreeMemory(Value); + } + return ERROR_SUCCESS; }
LONG RegEnumValue(FRLDRHKEY Key, - ULONG Index, - PWCHAR ValueName, - ULONG* NameSize, - ULONG* Type, - PUCHAR Data, - ULONG* DataSize) -{ - PLIST_ENTRY Ptr; - PVALUE Value; - ULONG Count = 0; - - if (Key->Data != NULL) - { - if (Index > 0) - { - Index--; - } - else - { - /* enumerate default value */ - if (ValueName != NULL) - *ValueName = 0; - if (Type != NULL) - *Type = Key->DataType; - if (Data != NULL) - { - if (Key->DataSize <= sizeof(PUCHAR)) + ULONG Index, + PWCHAR ValueName, + ULONG* NameSize, + ULONG* Type, + PUCHAR Data, + ULONG* DataSize) +{ + PLIST_ENTRY Ptr; + PVALUE Value; + ULONG Count = 0; + + if (Key->Data != NULL) + { + if (Index > 0) + { + Index--; + } + else + { + /* enumerate default value */ + if (ValueName != NULL) *ValueName = 0; + if (Type != NULL) *Type = Key->DataType; + if (Data != NULL) { - memcpy(Data, &Key->Data, min(Key->DataSize, *DataSize)); + if (Key->DataSize <= sizeof(PUCHAR)) + { + memcpy(Data, &Key->Data, min(Key->DataSize, *DataSize)); + } + else + { + memcpy(Data, Key->Data, min(Key->DataSize, *DataSize)); + } } - else - { - memcpy(Data, Key->Data, min(Key->DataSize, *DataSize)); - } - } - if (DataSize != NULL) - *DataSize = min(Key->DataSize, *DataSize); - - return(ERROR_SUCCESS); - } - } - - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) - { - if (Index == Count) - break; - - Count++; - Ptr = Ptr->Flink; - } - - if (Ptr == &Key->ValueList) - return(ERROR_NO_MORE_ITEMS); - - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); - - /* enumerate non-default value */ - if (ValueName != NULL) - memcpy(ValueName, Value->Name, min(Value->NameSize, *NameSize)); - if (Type != NULL) - *Type = Value->DataType; - - if (Data != NULL) - { - if (Value->DataSize <= sizeof(PUCHAR)) - { - memcpy(Data, &Value->Data, min(Value->DataSize, *DataSize)); - } - else - { - memcpy(Data, Value->Data, min(Value->DataSize, *DataSize)); - } - } - - if (DataSize != NULL) - *DataSize = min(Value->DataSize, *DataSize); - - return(ERROR_SUCCESS); + + if (DataSize != NULL) *DataSize = min(Key->DataSize, *DataSize); + + return ERROR_SUCCESS; + } + } + + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) + { + if (Index == Count) break; + + Count++; + Ptr = Ptr->Flink; + } + + if (Ptr == &Key->ValueList) return ERROR_NO_MORE_ITEMS; + + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); + + /* enumerate non-default value */ + if (ValueName != NULL) + { + memcpy(ValueName, Value->Name, min(Value->NameSize, *NameSize)); + } + if (Type != NULL) *Type = Value->DataType; + + if (Data != NULL) + { + if (Value->DataSize <= sizeof(PUCHAR)) + { + memcpy(Data, &Value->Data, min(Value->DataSize, *DataSize)); + } + else + { + memcpy(Data, Value->Data, min(Value->DataSize, *DataSize)); + } + } + + if (DataSize != NULL) *DataSize = min(Value->DataSize, *DataSize); + + return ERROR_SUCCESS; }
ULONG RegGetSubKeyCount (FRLDRHKEY Key) { - return Key->SubKeyCount; + return Key->SubKeyCount; }
ULONG RegGetValueCount (FRLDRHKEY Key) { - if (Key->DataSize != 0) - return Key->ValueCount + 1; - - return Key->ValueCount; + if (Key->DataSize != 0) return Key->ValueCount + 1; + + return Key->ValueCount; }
/* EOF */
Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/window... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -628,7 +628,7 @@ /* Do the machine specific initialization */ WinLdrSetupMachineDependent(LoaderBlock);
- /* Turn on paging mode of CPU */ + /* Map pages and create memory descriptors */ WinLdrSetupMemoryLayout(LoaderBlock);
/* Save final value of LoaderPagesSpanned */ @@ -639,6 +639,9 @@
DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n", KiSystemStartup, LoaderBlockVA); + + // Zero KI_USER_SHARED_DATA page + memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE);
WinLdrpDumpMemoryDescriptors(LoaderBlockVA); WinLdrpDumpBootDriver(LoaderBlockVA);
Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/window... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -324,9 +324,6 @@ MempDump(); #endif
- // Zero KI_USER_SHARED_DATA page - memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE); - return TRUE; }
Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/window... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] Thu Sep 1 19:01:19 2011 @@ -11,7 +11,7 @@ #include <freeldr.h> #include <debug.h>
-// The only global var here, used to mark mem pages as NLS in WinLdrTurnOnPaging() +// The only global var here, used to mark mem pages as NLS in WinLdrSetupMemoryLayout() ULONG TotalNLSSize = 0;
BOOLEAN WinLdrGetNLSNames(LPSTR AnsiName,