34725, 34726, 34727, 34728, 34733, 34735, 34747, 34748, 34888, 34937, 34968, 35021, 35351, 35360, 35445, 35493, 35495, 35505, 35547, 35696, 35704, 36343, 36355, 36865, 37306, 37896, 38332, 38942, 38950, 38951, 38959, 39073, 39278
svn path=/trunk/; revision=39638
<define name="_M_IX86" />
<define name="_X86_" />
<define name="__i386__" />
++++ <define name="TARGET_i386" host="true" />
++++
++++ <define name="USE_COMPILER_EXCEPTIONS" />
<property name="NTOSKRNL_SHARED" value="-file-alignment=0x1000 -section-alignment=0x1000 -shared"/>
+++++ <property name="PLATFORM" value="PC"/>
<if property="OPTIMIZE" value="1">
<compilerflag>-Os</compilerflag>
--- /dev/null
--- /dev/null
--- /dev/null
- -//.org 0x8000
++ + .intel_syntax noprefix
++ + .text
++ + .code16
++ +
- -#define STACK16ADDR 0x7000 /* The 16-bit stack top will be at 0000:7000 */
- -#define STACK64ADDR 0x74000 /* The 64-bit stack top will be at 0x74000 */
+++++#define ASM
+++++#include <arch.h>
++ +
- - * We defines one 2MB page at the start of memory, so we can access the first
- - * 2MBs as if paging was disabled
+++++//.org 0x8000
++ +
++ + .global RealEntryPoint
++ + RealEntryPoint:
++ +
++ + cli
++ +
++ + /* Setup real mode segment registers */
++ + xor ax, ax
++ + mov ds, ax
++ + mov es, ax
++ + mov fs, ax
++ + mov gs, ax
++ + mov ss, ax
++ +
++ + /* Setup a real mode stack */
++ + mov sp, stack16
++ +
++ + /* Zero BootDrive and BootPartition */
++ + xor eax, eax
++ + mov _BootDrive, eax
++ + mov _BootPartition, eax
++ +
++ + /* Store the boot drive */
++ + mov _BootDrive, dl
++ +
++ + /* Store the boot partition */
++ + mov _BootPartition, dh
++ +
++ + /* Load the GDT */
++ + lgdt gdtptr
++ + /* Load the IDT */
++ + // lidt idtptr
++ +
++ + call x86_16_EnableA20
++ +
++ + call x86_16_BuildPageTables
++ +
++ + /* Switch to long mode */
++ + call x86_16_SwitchToLong
++ +
++ + .code64
++ +
++ + /* GO! */
++ + xor rcx, rcx
++ + call _BootMain
++ +
++ + /* Return into real mode */
++ + call x86_64_SwitchToReal
++ + .code16
++ +
++ + // int 0x19
++ +
++ + /* We should never get here */
++ + stop:
++ + jmp stop
++ + nop
++ + nop
++ +
++ +
++ + /** 16 Bit helper functions ***************************************************/
++ + .code16
++ +
++ + x86_16_Empty8042:
++ + .word 0x00eb,0x00eb // jmp $+2, jmp $+2
++ + in al, 0x64
++ + cmp al, 0xff // legacy-free machine without keyboard
++ + jz empty_8042_ret // controllers on Intel Macs read back 0xFF
++ + test al, 0x02
++ + jnz x86_16_Empty8042
++ + empty_8042_ret:
++ + ret
++ +
++ + x86_16_EnableA20:
++ + pusha
++ + call x86_16_Empty8042
++ + mov al, 0xD1 // command write
++ + out 0x64, al
++ + call x86_16_Empty8042
++ + mov al, 0xDF // A20 on
++ + out 0x60, al
++ + call x86_16_Empty8042
++ + popa
++ + ret
++ +
++ +
++ + /*
- -
- -#define PML4_PAGENUM 60 // Put it high enough so it doesn't interfere with freeldr
- -
- -#define PAGESIZE 4096
- -#define PDP_PAGENUM (PML4_PAGENUM + 1)
- -#define PD_PAGENUM (PDP_PAGENUM + 1)
- -#define PML4_ADDRESS (PML4_PAGENUM * PAGESIZE)
- -#define PDP_ADDRESS (PDP_PAGENUM * PAGESIZE)
- -#define PML4_SEG (PML4_ADDRESS / 16)
- -
+++++ * We define 512 2MB pages at the start of memory, so we can access the first
+++++ * 1 GB as if paging was disabled
++ + */
- - mov ax, PML4_SEG
++ + x86_16_BuildPageTables:
++ + pusha
++ + push es
++ +
- - mov ax, ((PDP_PAGENUM << 12) & 0xffff) | 0x00f
- - stosw
- - mov ax, (PDP_PAGENUM >> 4)
- - stosw
- - xor ax,ax
- - mov cx, 0x07fe
- - rep stosw
+++++ /* Get segment of pml4 */
+++++ mov eax, offset _pml4_startup
+++++ shr eax, 4
++ + mov es, ax
++ + cld
++ + xor di, di
++ +
++ + /* One entry in the PML4 pointing to PDP */
- - mov ax, ((PD_PAGENUM << 12) & 0xffff) | 0x00f
- - stosw
- - mov ax, (PD_PAGENUM >> 4)
- - stosw
- - xor ax,ax
- - mov cx, 0x07fe
- - rep stosw
- -
- - /* One entry in the PD defining a 2MB page */
- - mov ax, 0x018f
- - stosw
- - xor ax,ax
- - mov cx,0x07ff
- - rep stosw
+++++ mov eax, offset _pdp_startup
+++++ or eax, 0x00f
+++++ stosd
+++++ /* clear rest */
+++++ xor eax, eax
+++++ mov cx, 0x03ff
+++++ rep stosd
++ +
++ + /* One entry in the PDP pointing to PD */
- -#define LMODE_CS 0x08
- -#define LMODE_DS 0x10
- -#define RMODE_CS 0x18 /* RMode code selector, base 0 limit 64k */
- -#define RMODE_DS 0x20 /* RMode data selector, base 0 limit 64k */
- -
+++++ mov eax, offset _pd_startup
+++++ or eax, 0x00f
+++++ stosd
+++++ /* clear rest */
+++++ xor eax, eax
+++++ mov ecx, 0x03ff
+++++ rep stosd
+++++
+++++ /* 512 entries in the PD defining a 2MB page each */
+++++ mov ecx, 512
+++++ mov eax, 0x008f
+++++
+++++Bpt2:
+++++ mov es: [di], eax
+++++ mov dword ptr es: [di + 4], 0
+++++ add eax, 512 << 12 // add 512 4k pages
+++++ add di, 8
+++++
+++++ /* Loop it */
+++++ dec cx
+++++ jnz Bpt2
++ +
++ + /* Return */
++ + pop es
++ + popa
++ + ret
++ +
++ +
- - mov edx, PML4_ADDRESS // Point cr3 at PML4
++ + //.global x86_16_SwitchToLong
++ + x86_16_SwitchToLong:
++ + cli
++ +
++ + xor ax,ax
++ + mov ds,ax
++ + mov es,ax
++ + mov fs,ax
++ + mov gs,ax
++ + mov ss,ax
++ +
++ + /* Get the return address off the stack */
++ + pop word ptr code64ret
++ +
++ + /* Save 16-bit stack pointer */
++ + mov stack16, sp
++ +
++ + mov eax, 0x00a0 // Set PAE and PGE: 10100000b
++ + mov cr4, eax
++ +
- - .quad 0x0000000000000000
- - .quad 0x0020980000000000
- - .quad 0x0000900000000000
+++++ mov edx, offset _pml4_startup // Point cr3 at PML4
++ + mov cr3, edx
++ +
++ + mov ecx, 0xC0000080 // Specify EFER MSR
++ +
++ + rdmsr // Enable long mode
++ + or eax, 0x00000100
++ + wrmsr
++ +
++ + mov ebx, cr0 // Activate long mode
++ + or ebx, 0x80000001 // by enabling paging and protection simultaneously
++ + mov cr0, ebx // skipping protected mode entirely
++ +
++ + jmp LMODE_CS:offset LongCat //Load CS with 64 bit segment and flush the instruction cache
++ +
++ + .code64
++ + LongCat:
++ + /* Set up 64 bit stack */
++ + mov rsp, stack64
++ +
++ + /* Put the return address back onto the stack */
++ + push qword ptr code64ret
++ +
++ + /* Now return in long mode! */
++ + ret
++ +
++ +
++ + /** 64 But functions **********************************************************/
++ + .code64
++ +
++ + .global x86_64_SwitchToReal
++ + x86_64_SwitchToReal:
++ +
++ + /* Get the return address off the stack */
++ + pop qword ptr code64ret
++ +
++ + /* Save 64-bit stack pointer */
++ + mov stack64, rsp
++ +
++ + /* Step 1 - deactivate long mode, by disabling paging */
++ + mov rax, cr0
++ + and rax, 0x000000007fffffff //~0x80000000
++ + mov cr0, rax
++ +
++ + /* Step 2 - disable long mode in EFER MSR */
++ + mov rcx, 0xC0000080 // Specify EFER MSR
++ + rdmsr
++ + and eax, ~0x00000100 // Disable EFER.LME
++ + wrmsr
++ +
++ + .code32
++ + /* jmp to 16-bit segment to set the limit correctly */
++ + jmp RMODE_CS: offset SwitchToReal2
++ +
++ + SwitchToReal2:
++ + .code16
++ +
++ + /* Step 3 - Disable Protected Mode */
++ + mov eax, cr0
++ + and eax, ~0x00000001
++ + mov cr0, eax
++ +
++ + /* Clear prefetch queue & correct CS */
++ + jmp 0:offset BeReal
++ +
++ + BeReal:
++ + /* Restore segment registers */
++ + mov ax, 0
++ + mov ds, ax
++ + mov es, ax
++ + mov fs, ax
++ + mov gs, ax
++ + mov ss, ax
++ +
++ + /* Rstore 16 bit stack */
++ + mov sp, stack16
++ +
++ + // lidt rmode_idtptr /* Load IDTR with real mode value */
++ +
++ + // sti /* These are ok now */
++ +
++ + /* Put the return address back onto the stack */
++ + push word ptr code64ret
++ +
++ + /* Now return in real mode! */
++ + ret
++ +
++ +
+++++
++ + /** Some data *****************************************************************/
++ +
++ + .code64
++ +
++ + stack16:
++ + .quad STACK16ADDR
++ +
++ + stack64:
++ + .quad STACK64ADDR
++ +
++ + code64ret:
++ + .quad 0
++ +
++ + gdt:
- - .word 0x27 /* Limit */
+++++ .quad 0x0000000000000000 /* 00: NULL descriptor */
+++++ .quad 0x0000000000000000 /* 08: */
+++++ .quad 0x0020980000000000 /* 10: long mode cs */
+++++ .quad 0x0000900000000000 /* 18: long mode ds */
++ + .word 0xFFFF, 0x0000, 0x9E00, 0x0000 /* 16-bit real mode CS */
++ + .word 0xFFFF, 0x0000, 0x9200, 0x0000 /* 16-bit real mode DS */
++ +
++ + /* GDT table pointer */
++ + gdtptr:
+++++ .word 0x2f /* Limit */
++ + .long gdt /* Base Address */
++ +
++ +
++ + .global _BootDrive
++ + _BootDrive:
++ + .long 0
++ +
++ + .global _BootPartition
++ + _BootPartition:
++ + .long 0
++ +
++ +
++ + ///////////////////////////////////////////////////////////////////////////////
++ +
++ + /* Need to include them here, because of linking issues between 64 / 16 bit */
++ + //#include "debug16.S"
++ + #include "int386.S"
++ + #include "boot.S"
++ + #include "i386pnp.S"
++ +
--- /dev/null
--- /dev/null
--- /dev/null
--- /dev/null
- * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
- * Copyright (C) 2005 Alex Ionescu <alex@relsoft.net>
++++ /*
++++ * FreeLoader
-#undef DbgPrint
+++++ * Copyright (C) 2008 - 2009 Timo Kreuzer (timo.kreuzer@reactor.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., 675 Mass Ave, Cambridge, MA 02139, USA.
++++ */
++++ #define _NTSYSTEM_
++++ #include <freeldr.h>
++++
++++ #define NDEBUG
++++ #include <debug.h>
-extern PAGE_DIRECTORY_X86 startup_pagedirectory;
-extern PAGE_DIRECTORY_X86 lowmem_pagetable;
-extern PAGE_DIRECTORY_X86 kernel_pagetable;
-extern PAGE_DIRECTORY_X86 hyperspace_pagetable;
-extern PAGE_DIRECTORY_X86 apic_pagetable;
-extern PAGE_DIRECTORY_X86 kpcr_pagetable;
-extern PAGE_DIRECTORY_X86 kuser_pagetable;
++++
++++ /* Page Directory and Tables for non-PAE Systems */
- ASSERT(FALSE);
-#if 0
- /* Disable Interrupts */
- _disable();
+++++extern ULONG_PTR NextModuleBase;
++++ extern ULONG_PTR KernelBase;
+++++ULONG_PTR GdtBase, IdtBase, TssBase;
++++ extern ROS_KERNEL_ENTRY_POINT KernelEntryPoint;
+++++
+++++PPAGE_DIRECTORY_AMD64 pPML4;
+++++PVOID pIdt, pGdt;
+++++
++++ /* FUNCTIONS *****************************************************************/
++++
+++++void
+++++EnableA20()
+++++{
+++++ /* Already done */
+++++}
+++++
+++++void
+++++DumpLoaderBlock()
+++++{
+++++ DbgPrint("LoaderBlock @ %p.\n", &LoaderBlock);
+++++ DbgPrint("Flags = 0x%x.\n", LoaderBlock.Flags);
+++++ DbgPrint("MemLower = 0x%p.\n", (PVOID)LoaderBlock.MemLower);
+++++ DbgPrint("MemHigher = 0x%p.\n", (PVOID)LoaderBlock.MemHigher);
+++++ DbgPrint("BootDevice = 0x%x.\n", LoaderBlock.BootDevice);
+++++ DbgPrint("CommandLine = %s.\n", LoaderBlock.CommandLine);
+++++ DbgPrint("ModsCount = 0x%x.\n", LoaderBlock.ModsCount);
+++++ DbgPrint("ModsAddr = 0x%p.\n", LoaderBlock.ModsAddr);
+++++ DbgPrint("Syms = 0x%s.\n", LoaderBlock.Syms);
+++++ DbgPrint("MmapLength = 0x%x.\n", LoaderBlock.MmapLength);
+++++ DbgPrint("MmapAddr = 0x%p.\n", (PVOID)LoaderBlock.MmapAddr);
+++++ DbgPrint("RdLength = 0x%x.\n", LoaderBlock.RdLength);
+++++ DbgPrint("RdAddr = 0x%p.\n", (PVOID)LoaderBlock.RdAddr);
+++++ DbgPrint("DrivesCount = 0x%x.\n", LoaderBlock.DrivesCount);
+++++ DbgPrint("DrivesAddr = 0x%p.\n", (PVOID)LoaderBlock.DrivesAddr);
+++++ DbgPrint("ConfigTable = 0x%x.\n", LoaderBlock.ConfigTable);
+++++ DbgPrint("BootLoaderName = 0x%x.\n", LoaderBlock.BootLoaderName);
+++++ DbgPrint("PageDirectoryStart = 0x%p.\n", (PVOID)LoaderBlock.PageDirectoryStart);
+++++ DbgPrint("PageDirectoryEnd = 0x%p.\n", (PVOID)LoaderBlock.PageDirectoryEnd);
+++++ DbgPrint("KernelBase = 0x%p.\n", (PVOID)LoaderBlock.KernelBase);
+++++ DbgPrint("ArchExtra = 0x%p.\n", (PVOID)LoaderBlock.ArchExtra);
+++++
+++++}
+++++
++++ /*++
++++ * FrLdrStartup
++++ * INTERNAL
++++ *
++++ * Prepares the system for loading the Kernel.
++++ *
++++ * Params:
++++ * Magic - Multiboot Magic
++++ *
++++ * Returns:
++++ * None.
++++ *
++++ * Remarks:
++++ * None.
++++ *
++++ *--*/
++++ VOID
++++ NTAPI
++++ FrLdrStartup(ULONG Magic)
++++ {
- /* Re-initalize EFLAGS */
- Ke386EraseFlags();
+++++ /* Disable Interrupts */
+++++ _disable();
++++
- /* Initialize the page directory */
- FrLdrSetupPageDirectory();
+++++ /* Re-initalize EFLAGS */
+++++ KeAmd64EraseFlags();
++++
- /* Initialize Paging, Write-Protection and Load NTOSKRNL */
- FrLdrSetupPae(Magic);
-#endif
+++++ /* Initialize the page directory */
+++++ FrLdrSetupPageDirectory();
+++++
+++++ /* Set the new PML4 */
+++++ __writecr3((ULONGLONG)pPML4);
+++++
+++++ FrLdrSetupGdtIdt();
+++++
+++++ LoaderBlock.FrLdrDbgPrint = DbgPrint;
+++++
+++++// DumpLoaderBlock();
+++++
+++++ DbgPrint("Jumping to kernel @ %p.\n", KernelEntryPoint);
+++++
+++++ /* Jump to Kernel */
+++++ (*KernelEntryPoint)(Magic, &LoaderBlock);
++++
-/*++
- * FrLdrSetupPae
- * INTERNAL
- *
- * Configures PAE on a MP System, and sets the PDBR if it's supported, or if
- * the system is UP.
- *
- * Params:
- * Magic - Multiboot Magic
- *
- * Returns:
- * None.
- *
- * Remarks:
- * None.
- *
- *--*/
-VOID
-FASTCALL
-FrLdrSetupPae(ULONG Magic)
++++ }
++++
-#if 0
- ULONG_PTR PageDirectoryBaseAddress = (ULONG_PTR)&startup_pagedirectory;
+++++PPAGE_DIRECTORY_AMD64
+++++FrLdrGetOrCreatePageDir(PPAGE_DIRECTORY_AMD64 pDir, ULONG Index)
+++++{
+++++ PPAGE_DIRECTORY_AMD64 pSubDir;
+++++
+++++ if (!pDir)
+++++ return NULL;
+++++
+++++ if (!pDir->Pde[Index].Valid)
+++++ {
+++++ pSubDir = MmAllocateMemoryWithType(PAGE_SIZE, LoaderSpecialMemory);
+++++ if (!pSubDir)
+++++ return NULL;
+++++ RtlZeroMemory(pSubDir, PAGE_SIZE);
+++++ pDir->Pde[Index].PageFrameNumber = PtrToPfn(pSubDir);
+++++ pDir->Pde[Index].Valid = 1;
+++++ pDir->Pde[Index].Write = 1;
+++++ }
+++++ else
+++++ {
+++++ pSubDir = (PPAGE_DIRECTORY_AMD64)((ULONGLONG)(pDir->Pde[Index].PageFrameNumber) * PAGE_SIZE);
+++++ }
+++++ return pSubDir;
+++++}
+++++
+++++BOOLEAN
+++++FrLdrMapSinglePage(ULONGLONG VirtualAddress, ULONGLONG PhysicalAddress)
++++ {
- /* Set the PDBR */
- __writecr3(PageDirectoryBaseAddress);
+++++ PPAGE_DIRECTORY_AMD64 pDir3, pDir2, pDir1;
+++++ ULONG Index;
++++
- /* Enable Paging and Write Protect*/
- __writecr0(__readcr0() | X86_CR0_PG | X86_CR0_WP);
+++++ pDir3 = FrLdrGetOrCreatePageDir(pPML4, VAtoPXI(VirtualAddress));
+++++ pDir2 = FrLdrGetOrCreatePageDir(pDir3, VAtoPPI(VirtualAddress));
+++++ pDir1 = FrLdrGetOrCreatePageDir(pDir2, VAtoPDI(VirtualAddress));
++++
- /* Jump to Kernel */
- (*KernelEntryPoint)(Magic, &LoaderBlock);
-#endif
+++++ if (!pDir1)
+++++ return FALSE;
++++
- *
- * Remarks:
- * We are setting PDEs, but using the equvivalent (for our purpose) PTE structure.
- * As such, please note that PageFrameNumber == PageEntryNumber.
- *
+++++ Index = VAtoPTI(VirtualAddress);
+++++ if (pDir1->Pde[Index].Valid)
+++++ {
+++++ return FALSE;
+++++ }
+++++
+++++ pDir1->Pde[Index].Valid = 1;
+++++ pDir1->Pde[Index].Write = 1;
+++++ pDir1->Pde[Index].PageFrameNumber = PhysicalAddress / PAGE_SIZE;
+++++
+++++ return TRUE;
++++ }
++++
+++++ULONG
+++++FrLdrMapRangeOfPages(ULONGLONG VirtualAddress, ULONGLONG PhysicalAddress, ULONG cPages)
+++++{
+++++ ULONG i;
+++++
+++++ for (i = 0; i < cPages; i++)
+++++ {
+++++ if (!FrLdrMapSinglePage(VirtualAddress, PhysicalAddress))
+++++ {
+++++ return i;
+++++ }
+++++ VirtualAddress += PAGE_SIZE;
+++++ PhysicalAddress += PAGE_SIZE;
+++++ }
+++++ return i;
+++++}
+++++
+++++
++++ /*++
++++ * FrLdrSetupPageDirectory
++++ * INTERNAL
++++ *
++++ * Sets up the ReactOS Startup Page Directory.
++++ *
++++ * Params:
++++ * None.
++++ *
++++ * Returns:
++++ * None.
-#if 0
- PPAGE_DIRECTORY_X86 PageDir;
- ULONG KernelPageTableIndex;
- ULONG i;
-
- /* Get the Kernel Table Index */
- KernelPageTableIndex = KernelBase >> PDE_SHIFT;
-
- /* Get the Startup Page Directory */
- PageDir = (PPAGE_DIRECTORY_X86)&startup_pagedirectory;
-
- /* Set up the Low Memory PDE */
- PageDir->Pde[LowMemPageTableIndex].Valid = 1;
- PageDir->Pde[LowMemPageTableIndex].Write = 1;
- PageDir->Pde[LowMemPageTableIndex].PageFrameNumber = PaPtrToPfn(lowmem_pagetable);
-
- /* Set up the Kernel PDEs */
- PageDir->Pde[KernelPageTableIndex].Valid = 1;
- PageDir->Pde[KernelPageTableIndex].Write = 1;
- PageDir->Pde[KernelPageTableIndex].PageFrameNumber = PaPtrToPfn(kernel_pagetable);
- PageDir->Pde[KernelPageTableIndex + 1].Valid = 1;
- PageDir->Pde[KernelPageTableIndex + 1].Write = 1;
- PageDir->Pde[KernelPageTableIndex + 1].PageFrameNumber = PaPtrToPfn(kernel_pagetable + 4096);
-
- /* Set up the Startup PDE */
- PageDir->Pde[StartupPageTableIndex].Valid = 1;
- PageDir->Pde[StartupPageTableIndex].Write = 1;
- PageDir->Pde[StartupPageTableIndex].PageFrameNumber = PaPtrToPfn(startup_pagedirectory);
-
- /* Set up the Hyperspace PDE */
- PageDir->Pde[HyperspacePageTableIndex].Valid = 1;
- PageDir->Pde[HyperspacePageTableIndex].Write = 1;
- PageDir->Pde[HyperspacePageTableIndex].PageFrameNumber = PaPtrToPfn(hyperspace_pagetable);
-
- /* Set up the HAL PDE */
- PageDir->Pde[HalPageTableIndex].Valid = 1;
- PageDir->Pde[HalPageTableIndex].Write = 1;
- PageDir->Pde[HalPageTableIndex].PageFrameNumber = PaPtrToPfn(apic_pagetable);
-
- /* Set up Low Memory PTEs */
- PageDir = (PPAGE_DIRECTORY_X86)&lowmem_pagetable;
- for (i=0; i<1024; i++)
- {
- PageDir->Pde[i].Valid = 1;
- PageDir->Pde[i].Write = 1;
- PageDir->Pde[i].Owner = 1;
- PageDir->Pde[i].PageFrameNumber = PaToPfn(i * PAGE_SIZE);
- }
-
- /* Set up Kernel PTEs */
- PageDir = (PPAGE_DIRECTORY_X86)&kernel_pagetable;
- for (i=0; i<1536; i++)
- {
- PageDir->Pde[i].Valid = 1;
- PageDir->Pde[i].Write = 1;
- PageDir->Pde[i].PageFrameNumber = PaToPfn(KERNEL_BASE_PHYS + i * PAGE_SIZE);
- }
-
- /* Setup APIC Base */
- PageDir = (PPAGE_DIRECTORY_X86)&apic_pagetable;
- PageDir->Pde[0].Valid = 1;
- PageDir->Pde[0].Write = 1;
- PageDir->Pde[0].CacheDisable = 1;
- PageDir->Pde[0].WriteThrough = 1;
- PageDir->Pde[0].PageFrameNumber = PaToPfn(HAL_BASE);
- PageDir->Pde[0x200].Valid = 1;
- PageDir->Pde[0x200].Write = 1;
- PageDir->Pde[0x200].CacheDisable = 1;
- PageDir->Pde[0x200].WriteThrough = 1;
- PageDir->Pde[0x200].PageFrameNumber = PaToPfn(HAL_BASE + KERNEL_BASE_PHYS);
-
- /* Setup KUSER_SHARED_DATA Base */
- PageDir->Pde[0x1F0].Valid = 1;
- PageDir->Pde[0x1F0].Write = 1;
- PageDir->Pde[0x1F0].PageFrameNumber = 2;
-
- /* Setup KPCR Base*/
- PageDir->Pde[0x1FF].Valid = 1;
- PageDir->Pde[0x1FF].Write = 1;
- PageDir->Pde[0x1FF].PageFrameNumber = 1;
-
- /* Zero shared data */
- RtlZeroMemory((PVOID)(2 << MM_PAGE_SHIFT), PAGE_SIZE);
-#endif
++++ *--*/
++++ VOID
++++ FASTCALL
++++ FrLdrSetupPageDirectory(VOID)
++++ {
+++++ ULONG KernelPages;
+++++ PVOID UserSharedData;
+++++
+++++ /* Allocate a Page for the PML4 */
+++++ pPML4 = MmAllocateMemoryWithType(PAGE_SIZE, LoaderSpecialMemory);
+++++
+++++ ASSERT(pPML4);
+++++
+++++ /* The page tables are located at 0xfffff68000000000
+++++ * We create a recursive self mapping through all 4 levels at
+++++ * virtual address 0xfffff6fb7dbedf68 */
+++++ pPML4->Pde[VAtoPXI(PXE_BASE)].Valid = 1;
+++++ pPML4->Pde[VAtoPXI(PXE_BASE)].Write = 1;
+++++ pPML4->Pde[VAtoPXI(PXE_BASE)].PageFrameNumber = PtrToPfn(pPML4);
+++++
+++++ /* Setup low memory pages */
+++++ if (FrLdrMapRangeOfPages(0, 0, 1024) < 1024)
+++++ {
+++++ DbgPrint("Could not map low memory pages.\n");
+++++ }
+++++
+++++ /* Setup kernel pages */
+++++ KernelPages = (ROUND_TO_PAGES(NextModuleBase - KERNEL_BASE_PHYS) / PAGE_SIZE);
+++++ if (FrLdrMapRangeOfPages(KernelBase, KERNEL_BASE_PHYS, KernelPages) != KernelPages)
+++++ {
+++++ DbgPrint("Could not map %d kernel pages.\n", KernelPages);
+++++ }
+++++
+++++ /* Setup a page for the idt */
+++++ pIdt = MmAllocateMemoryWithType(PAGE_SIZE, LoaderSpecialMemory);
+++++ IdtBase = KernelBase + KernelPages * PAGE_SIZE;
+++++ if (!FrLdrMapSinglePage(IdtBase, (ULONGLONG)pIdt))
+++++ {
+++++ DbgPrint("Could not map idt page.\n", KernelPages);
+++++ }
+++++
+++++ /* Setup a page for the gdt & tss */
+++++ pGdt = MmAllocateMemoryWithType(PAGE_SIZE, LoaderSpecialMemory);
+++++ GdtBase = IdtBase + PAGE_SIZE;
+++++ TssBase = GdtBase + 20 * sizeof(ULONG64); // FIXME: don't hardcode
+++++ if (!FrLdrMapSinglePage(GdtBase, (ULONGLONG)pGdt))
+++++ {
+++++ DbgPrint("Could not map gdt page.\n", KernelPages);
+++++ }
+++++
+++++ /* Setup KUSER_SHARED_DATA page */
+++++ UserSharedData = MmAllocateMemoryWithType(PAGE_SIZE, LoaderSpecialMemory);
+++++ if (!FrLdrMapSinglePage(KI_USER_SHARED_DATA, (ULONG64)UserSharedData))
+++++ {
+++++ DbgPrint("Could not map KUSER_SHARED_DATA page.\n", KernelPages);
+++++ }
+++++
+++++ /* Map APIC page */
+++++ if (!FrLdrMapSinglePage(APIC_BASE, APIC_PHYS_BASE))
+++++ {
+++++ DbgPrint("Could not map APIC page.\n");
+++++ }
+++++
++++ }
++++
+++++VOID
+++++FrLdrSetupGdtIdt()
+++++{
+++++ PKGDTENTRY64 Entry;
+++++ KDESCRIPTOR Desc;
+++++
+++++ RtlZeroMemory(pGdt, PAGE_SIZE);
+++++
+++++ /* Setup KGDT_64_R0_CODE */
+++++ Entry = KiGetGdtEntry(pGdt, KGDT_64_R0_CODE);
+++++ *(PULONG64)Entry = 0x00209b0000000000ULL;
+++++
+++++ /* Setup KGDT_64_R0_SS */
+++++ Entry = KiGetGdtEntry(pGdt, KGDT_64_R0_SS);
+++++ *(PULONG64)Entry = 0x00cf93000000ffffULL;
+++++
+++++ /* Setup KGDT_64_DATA */
+++++ Entry = KiGetGdtEntry(pGdt, KGDT_64_DATA);
+++++ *(PULONG64)Entry = 0x00cff3000000ffffULL;
+++++
+++++ /* Setup KGDT_64_R3_CODE */
+++++ Entry = KiGetGdtEntry(pGdt, KGDT_64_R3_CODE);
+++++ *(PULONG64)Entry = 0x0020fb0000000000ULL;
+++++
+++++ /* Setup KGDT_32_R3_TEB */
+++++ Entry = KiGetGdtEntry(pGdt, KGDT_32_R3_TEB);
+++++ *(PULONG64)Entry = 0xff40f3fd50003c00ULL;
+++++
+++++ /* Setup TSS entry */
+++++ Entry = KiGetGdtEntry(pGdt, KGDT_TSS);
+++++ KiInitGdtEntry(Entry, TssBase, sizeof(KTSS), I386_TSS, 0);
+++++
+++++ /* Setup the gdt descriptor */
+++++ Desc.Limit = 12 * sizeof(ULONG64) - 1;
+++++ Desc.Base = (PVOID)GdtBase;
+++++
+++++ /* Set the new Gdt */
+++++ __lgdt(&Desc.Limit);
+++++ DbgPrint("Gdtr.Base = %p\n", Desc.Base);
+++++
+++++ /* Setup the idt descriptor */
+++++ Desc.Limit = 12 * sizeof(ULONG64) - 1;
+++++ Desc.Base = (PVOID)IdtBase;
+++++
+++++ /* Set the new Idt */
+++++ __lidt(&Desc.Limit);
+++++ DbgPrint("Idtr.Base = %p\n", Desc.Base);
+++++
+++++}
--- /dev/null
--- /dev/null
--- .code32
++ /*
++ * FreeLoader
++ * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
++ *
++ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
++ */
++
++ .text
++ .code16
++
++ #define ASM
++ #include <arch.h>
++ #include <multiboot.h>
++
++ /*
++ * Here we assume the kernel is loaded at 1mb
++ * This boots the kernel
++ */
--- .globl _startup_pagedirectory
--- .globl _lowmem_pagetable
--- .globl _kernel_pagetable
--- .globl _hyperspace_pagetable
--- .globl _apic_pagetable
--- .globl _kpcr_pagetable
--- .globl _kuser_pagetable
+++++ .code64
++ .globl _PageDirectoryStart
++
---_startup_pagedirectory:
+++++ .globl _pml4_startup
+++++ .globl _pdp_startup
+++++ .globl _pd_startup
++
++ .globl _PageDirectoryEnd
++
++ //
++ // Boot information structure
++ //
++
++ EXTERN(_reactos_memory_map_descriptor_size)
++ .long 0
++
++ EXTERN(_reactos_memory_map)
++ .rept (32 * /*sizeof(memory_map_t)*/24)
++ .byte 0
++ .endr
++
++ .bss
++ _PageDirectoryStart:
---_lowmem_pagetable:
+++++_pml4_startup:
++ .fill 4096, 1, 0
++
---_kernel_pagetable:
--- .fill 2*4096, 1, 0
---
---_hyperspace_pagetable:
--- .fill 4096, 1, 0
---
---_apic_pagetable:
+++++_pdp_startup:
++ .fill 4096, 1, 0
++
---_kpcr_pagetable:
--- .fill 4096, 1, 0
---
---_kuser_pagetable:
--- .fill 4096, 1, 0
---
+++++_pd_startup:
++ .fill 4096, 1, 0
++
++ _PageDirectoryEnd:
InstData = (PCM_PNP_BIOS_INSTALLATION_CHECK)PnpBiosSupported();
if (InstData == NULL || strncmp((CHAR*)InstData->Signature, "$PnP", 4))
{
----- DbgPrint((DPRINT_HWDETECT, "PnP-BIOS not supported\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "PnP-BIOS not supported\n");
return;
}
----- DbgPrint((DPRINT_HWDETECT, "Signature '%c%c%c%c'\n",
+++++ DPRINTM(DPRINT_HWDETECT, "Signature '%c%c%c%c'\n",
InstData->Signature[0], InstData->Signature[1],
----- InstData->Signature[2], InstData->Signature[3]));
+++++ InstData->Signature[2], InstData->Signature[3]);
x = PnpBiosGetDeviceNodeCount(&NodeSize, &NodeCount);
// e.g. look: http://my.execpc.com/~geezer/osd/pnp/pnp16.c
if (x != 0 || NodeSize == 0 || NodeCount == 0)
{
----- DbgPrint((DPRINT_HWDETECT, "PnP-BIOS failed to enumerate device nodes\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "PnP-BIOS failed to enumerate device nodes\n");
return;
}
----- DbgPrint((DPRINT_HWDETECT, "PnP-BIOS supported\n"));
----- DbgPrint((DPRINT_HWDETECT, "MaxNodeSize %u NodeCount %u\n", NodeSize, NodeCount));
----- DbgPrint((DPRINT_HWDETECT, "Estimated buffer size %u\n", NodeSize * NodeCount));
+++++ DPRINTM(DPRINT_HWDETECT, "PnP-BIOS supported\n");
+++++ DPRINTM(DPRINT_HWDETECT, "MaxNodeSize %u NodeCount %u\n", NodeSize, NodeCount);
+++++ DPRINTM(DPRINT_HWDETECT, "Estimated buffer size %u\n", NodeSize * NodeCount);
/* Create component key */
FldrCreateComponentKey(SystemKey,
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
memset(PartialResourceList, 0, Size);
{
DeviceNode = (PCM_PNP_BIOS_DEVICE_NODE)DISKREADBUFFER;
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Node: %u Size %u (0x%x)\n",
DeviceNode->Node,
DeviceNode->Size,
----- DeviceNode->Size));
+++++ DeviceNode->Size);
memcpy (Ptr,
DeviceNode,
PnpBufferSize;
Size = sizeof(CM_PARTIAL_RESOURCE_LIST) + PnpBufferSize;
----- DbgPrint((DPRINT_HWDETECT, "Real buffer size: %u\n", PnpBufferSize));
----- DbgPrint((DPRINT_HWDETECT, "Resource size: %u\n", Size));
+++++ DPRINTM(DPRINT_HWDETECT, "Real buffer size: %u\n", PnpBufferSize);
+++++ DPRINTM(DPRINT_HWDETECT, "Resource size: %u\n", Size);
FldrSetConfigurationData(BusKey, PartialResourceList, Size);
MmHeapFree(PartialResourceList);
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate a full resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate a full resource descriptor\n");
return;
}
}
else
{
----- DbgPrint((DPRINT_HWDETECT, "Reading disk geometry failed\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Reading disk geometry failed\n");
MmHeapFree(PartialResourceList);
return;
}
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
DriveNumber,
DiskGeometry->NumberOfCylinders,
DiskGeometry->NumberOfHeads,
DiskGeometry->SectorsPerTrack,
----- DiskGeometry->BytesPerSector));
+++++ DiskGeometry->BytesPerSector);
FldrSetConfigurationData(DiskKey, PartialResourceList, Size);
MmHeapFree(PartialResourceList);
/* Read the MBR */
if (!MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, (PVOID)DISKREADBUFFER))
{
----- DbgPrint((DPRINT_HWDETECT, "Reading MBR failed\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Reading MBR failed\n");
return;
}
Mbr = (PMASTER_BOOT_RECORD)DISKREADBUFFER;
Signature = Mbr->Signature;
----- DbgPrint((DPRINT_HWDETECT, "Signature: %x\n", Signature));
+++++ DPRINTM(DPRINT_HWDETECT, "Signature: %x\n", Signature);
/* Calculate the MBR checksum */
Checksum = 0;
Checksum += Buffer[i];
}
Checksum = ~Checksum + 1;
----- DbgPrint((DPRINT_HWDETECT, "Checksum: %x\n", Checksum));
+++++ DPRINTM(DPRINT_HWDETECT, "Checksum: %x\n", Checksum);
/* Fill out the ARC disk block */
reactos_arc_disk_info[reactos_disk_count].Signature = Signature;
Identifier[17] = '-';
Identifier[18] = 'A';
Identifier[19] = 0;
----- DbgPrint((DPRINT_HWDETECT, "Identifier: %s\n", Identifier));
+++++ DPRINTM(DPRINT_HWDETECT, "Identifier: %s\n", Identifier);
/* Set identifier */
FldrSetIdentifier(DiskKey, Identifier);
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
ULONG FloppyCount;
FloppyCount = GetFloppyCount();
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Floppy count: %u\n",
----- FloppyCount));
+++++ FloppyCount);
Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
memset(PartialResourceList, 0, Size);
}
if (! Changed)
{
----- DbgPrint((DPRINT_HWDETECT, "BIOS reports success for disk %d but data didn't change\n",
----- (int)DiskCount));
+++++ DPRINTM(DPRINT_HWDETECT, "BIOS reports success for disk %d but data didn't change\n",
+++++ (int)DiskCount);
break;
}
DiskCount++;
memset((PVOID) DISKREADBUFFER, 0xcd, 512);
}
DiskReportError(TRUE);
----- DbgPrint((DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n",
----- (int)DiskCount, (DiskCount == 1) ? "": "s"));
+++++ DPRINTM(DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n",
+++++ (int)DiskCount, (DiskCount == 1) ? "": "s");
FldrCreateComponentKey(BusKey,
L"DiskController",
ControllerClass,
DiskController,
&ControllerKey);
----- DbgPrint((DPRINT_HWDETECT, "Created key: DiskController\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Created key: DiskController\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(ControllerKey,
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
Int13Drives[i].MaxHeads = Geometry.Heads - 1;
Int13Drives[i].NumberDrives = DiskCount;
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
0x80 + i,
Geometry.Cylinders - 1,
Geometry.Heads -1,
Geometry.Sectors,
----- Geometry.BytesPerSector));
+++++ Geometry.BytesPerSector);
}
}
if (TimeOut == 0)
return MOUSE_TYPE_NONE;
}
---- Buffer[i] = READ_PORT_UCHAR((PUCHAR)Port);
++++ Buffer[i] = READ_PORT_UCHAR(Port);
}
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Mouse data: %x %x %x %x\n",
----- Buffer[0],Buffer[1],Buffer[2],Buffer[3]));
+++++ Buffer[0],Buffer[1],Buffer[2],Buffer[3]);
/* Check that four bytes for signs */
for (i = 0; i < 4; ++i)
switch (Buffer[i + 1])
{
case '3':
----- DbgPrint((DPRINT_HWDETECT,
----- "Microsoft Mouse with 3-buttons detected\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Microsoft Mouse with 3-buttons detected\n");
return MOUSE_TYPE_LOGITECH;
case 'Z':
----- DbgPrint((DPRINT_HWDETECT,
----- "Microsoft Wheel Mouse detected\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Microsoft Wheel Mouse detected\n");
return MOUSE_TYPE_WHEELZ;
/* case '2': */
default:
----- DbgPrint((DPRINT_HWDETECT,
----- "Microsoft Mouse with 2-buttons detected\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Microsoft Mouse with 2-buttons detected\n");
return MOUSE_TYPE_MICROSOFT;
}
}
ULONG j;
ULONG k;
----- DbgPrint((DPRINT_HWDETECT,
----- "DetectSerialPointerPeripheral()\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "DetectSerialPointerPeripheral()\n");
Identifier[0] = 0;
if (MouseType != MOUSE_TYPE_NONE)
{
Length = GetSerialMousePnpId(Base, Buffer);
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"PnP ID length: %u\n",
----- Length));
+++++ Length);
if (Length != 0)
{
}
Buffer[Length] = 0;
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"PnP ID string: %s\n",
----- Buffer));
+++++ Buffer);
/* Copy PnpId string */
for (i = 0; i < 7; i++)
}
}
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Identifier string: %s\n",
----- Identifier));
+++++ Identifier);
}
if (Length == 0 || strlen(Identifier) < 11)
PeripheralClass,
PointerPeripheral,
&PeripheralKey);
----- DbgPrint((DPRINT_HWDETECT,
----- "Created key: PointerPeripheral\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Created key: PointerPeripheral\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(PeripheralKey,
ULONG i;
ULONG Size;
----- DbgPrint((DPRINT_HWDETECT, "DetectSerialPorts()\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "DetectSerialPorts()\n");
ControllerNumber = 0;
BasePtr = (PUSHORT)0x400;
if (Base == 0)
continue;
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Found COM%u port at 0x%x\n",
i + 1,
----- Base));
+++++ Base);
/* Create controller key */
FldrCreateComponentKey(BusKey,
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
continue;
}
memset(PartialResourceList, 0, Size);
/* Set 'Identifier' value */
sprintf(Buffer, "COM%ld", i + 1);
FldrSetIdentifier(ControllerKey, Buffer);
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Created value: Identifier %s\n",
----- Buffer));
+++++ Buffer);
if (!Rs232PortInUse(Base))
{
ULONG i;
ULONG Size;
----- DbgPrint((DPRINT_HWDETECT, "DetectParallelPorts() called\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "DetectParallelPorts() called\n");
ControllerNumber = 0;
BasePtr = (PUSHORT)0x408;
if (Base == 0)
continue;
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Parallel port %u: %x\n",
ControllerNumber,
----- Base));
+++++ Base);
/* Create controller key */
FldrCreateComponentKey(BusKey,
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
continue;
}
memset(PartialResourceList, 0, Size);
/* Set 'Identifier' value */
sprintf(Buffer, "PARALLEL%ld", i + 1);
FldrSetIdentifier(ControllerKey, Buffer);
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Created value: Identifier %s\n",
----- Buffer));
+++++ Buffer);
ControllerNumber++;
}
----- DbgPrint((DPRINT_HWDETECT, "DetectParallelPorts() done\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "DetectParallelPorts() done\n");
}
PeripheralClass,
KeyboardPeripheral,
&PeripheralKey);
----- DbgPrint((DPRINT_HWDETECT, "Created key: KeyboardPeripheral\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Created key: KeyboardPeripheral\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(PeripheralKey,
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
ControllerClass,
KeyboardController,
&ControllerKey);
----- DbgPrint((DPRINT_HWDETECT, "Created key: KeyboardController\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Created key: KeyboardController\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(ControllerKey,
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
if (DetectPS2AuxPort())
{
----- DbgPrint((DPRINT_HWDETECT, "Detected PS2 port\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Detected PS2 port\n");
/* Create controller key */
FldrCreateComponentKey(BusKey,
ControllerClass,
PointerController,
&ControllerKey);
----- DbgPrint((DPRINT_HWDETECT, "Created key: PointerController\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Created key: PointerController\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(ControllerKey,
if (DetectPS2AuxDevice())
{
----- DbgPrint((DPRINT_HWDETECT, "Detected PS2 mouse\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Detected PS2 mouse\n");
/* Create peripheral key */
FldrCreateComponentKey(ControllerKey,
ControllerClass,
PointerPeripheral,
&PeripheralKey);
----- DbgPrint((DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Created key: PointerPeripheral\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(PeripheralKey,
ControllerClass,
DisplayController,
&ControllerKey);
----- DbgPrint((DPRINT_HWDETECT, "Created key: DisplayController\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Created key: DisplayController\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(ControllerKey,
VesaVersion = BiosIsVesaSupported();
if (VesaVersion != 0)
{
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"VESA version %c.%c\n",
(VesaVersion >> 8) + '0',
----- (VesaVersion & 0xFF) + '0'));
+++++ (VesaVersion & 0xFF) + '0');
}
else
{
----- DbgPrint((DPRINT_HWDETECT,
----- "VESA not supported\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "VESA not supported\n");
}
if (VesaVersion >= 0x0200)
PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
PCONFIGURATION_COMPONENT_DATA SystemKey;
ULONG BusNumber = 0;
----- DbgPrint((DPRINT_HWDETECT, "DetectHardware()\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "DetectHardware()\n");
/* Create the 'System' key */
FldrCreateSystemKey(&SystemKey);
DetectIsaBios(SystemKey, &BusNumber);
DetectAcpiBios(SystemKey, &BusNumber);
----- DbgPrint((DPRINT_HWDETECT, "DetectHardware() Done\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "DetectHardware() Done\n");
return SystemKey;
}
{
if (!memcmp(Ptr, "RSD PTR ", 8))
{
----- DbgPrint((DPRINT_HWDETECT, "ACPI supported\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "ACPI supported\n");
return (PRSDP_DESCRIPTOR)Ptr;
}
---- Ptr = (PUCHAR)((ULONG)Ptr + 0x10);
++++ Ptr = (PUCHAR)((ULONG_PTR)Ptr + 0x10);
}
----- DbgPrint((DPRINT_HWDETECT, "ACPI not supported\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "ACPI not supported\n");
return NULL;
}
memcpy(AcpiBiosData->MemoryMap, BiosMemoryMap,
BiosMemoryMapEntryCount * sizeof(BIOS_MEMORY_MAP));
----- DbgPrint((DPRINT_HWDETECT, "RSDT %p, data size %x\n", Rsdp->rsdt_physical_address,
----- TableSize));
+++++ DPRINTM(DPRINT_HWDETECT, "RSDT %p, data size %x\n", Rsdp->rsdt_physical_address,
+++++ TableSize);
FldrSetConfigurationData(BiosKey,
PartialResourceList,
if (INT386_SUCCESS(RegsOut))
{
----- DbgPrint((DPRINT_HWDETECT, "Found APM BIOS\n"));
----- DbgPrint((DPRINT_HWDETECT, "AH: %x\n", RegsOut.b.ah));
----- DbgPrint((DPRINT_HWDETECT, "AL: %x\n", RegsOut.b.al));
----- DbgPrint((DPRINT_HWDETECT, "BH: %x\n", RegsOut.b.bh));
----- DbgPrint((DPRINT_HWDETECT, "BL: %x\n", RegsOut.b.bl));
----- DbgPrint((DPRINT_HWDETECT, "CX: %x\n", RegsOut.w.cx));
+++++ DPRINTM(DPRINT_HWDETECT, "Found APM BIOS\n");
+++++ DPRINTM(DPRINT_HWDETECT, "AH: %x\n", RegsOut.b.ah);
+++++ DPRINTM(DPRINT_HWDETECT, "AL: %x\n", RegsOut.b.al);
+++++ DPRINTM(DPRINT_HWDETECT, "BH: %x\n", RegsOut.b.bh);
+++++ DPRINTM(DPRINT_HWDETECT, "BL: %x\n", RegsOut.b.bl);
+++++ DPRINTM(DPRINT_HWDETECT, "CX: %x\n", RegsOut.w.cx);
return TRUE;
}
----- DbgPrint((DPRINT_HWDETECT, "No APM BIOS found\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "No APM BIOS found\n");
return FALSE;
}
{
if (Table->Signature == 0x52495024)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Found signature\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Found signature\n");
Ptr = (PUCHAR)Table;
Sum = 0;
if ((Sum & 0xFF) != 0)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Invalid routing table\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Invalid routing table\n");
return NULL;
}
----- DbgPrint((DPRINT_HWDETECT,
----- "Valid checksum\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Valid checksum\n");
return Table;
}
if (INT386_SUCCESS(RegsOut) && RegsOut.d.edx == 0x20494350 && RegsOut.b.ah == 0)
{
----- DbgPrint((DPRINT_HWDETECT, "Found PCI bios\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Found PCI bios\n");
----- DbgPrint((DPRINT_HWDETECT, "AL: %x\n", RegsOut.b.al));
----- DbgPrint((DPRINT_HWDETECT, "BH: %x\n", RegsOut.b.bh));
----- DbgPrint((DPRINT_HWDETECT, "BL: %x\n", RegsOut.b.bl));
----- DbgPrint((DPRINT_HWDETECT, "CL: %x\n", RegsOut.b.cl));
+++++ DPRINTM(DPRINT_HWDETECT, "AL: %x\n", RegsOut.b.al);
+++++ DPRINTM(DPRINT_HWDETECT, "BH: %x\n", RegsOut.b.bh);
+++++ DPRINTM(DPRINT_HWDETECT, "BL: %x\n", RegsOut.b.bl);
+++++ DPRINTM(DPRINT_HWDETECT, "CL: %x\n", RegsOut.b.cl);
BusData->NoBuses = RegsOut.b.cl + 1;
BusData->MajorRevision = RegsOut.b.bh;
}
----- DbgPrint((DPRINT_HWDETECT, "No PCI bios found\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "No PCI bios found\n");
return FALSE;
}
Table = GetPciIrqRoutingTable();
if (Table != NULL)
{
----- DbgPrint((DPRINT_HWDETECT, "Table size: %u\n", Table->Size));
+++++ DPRINTM(DPRINT_HWDETECT, "Table size: %u\n", Table->Size);
FldrCreateComponentKey(BusKey,
L"RealModeIrqRoutingTable",
/* Set 'Configuration Data' value */
Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + Table->Size;
---- PartialResourceList = MmAllocateMemory(Size);
++++ PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
/* Set 'Configuration Data' value */
Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST,
PartialDescriptors);
---- PartialResourceList = MmAllocateMemory(Size);
++++ PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
PartialDescriptors) +
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) +
sizeof(PCI_REGISTRY_INFO);
---- PartialResourceList = MmAllocateMemory(Size);
++++ PartialResourceList = MmHeapAlloc(Size);
if (!PartialResourceList)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
/* Set 'Configuration Data' value */
Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST,
PartialDescriptors);
---- PartialResourceList = MmAllocateMemory(Size);
++++ PartialResourceList = MmHeapAlloc(Size);
if (!PartialResourceList)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
REGS RegsIn;
REGS RegsOut;
----- DbgPrint((DPRINT_DISK, "DiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber));
+++++ DPRINTM(DPRINT_DISK, "DiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber);
// BIOS Int 13h, function 0 - Reset disk system
// AH = 00h
REGS RegsIn;
REGS RegsOut;
----- DbgPrint((DPRINT_DISK, "DiskInt13ExtensionsSupported()\n"));
+++++ DPRINTM(DPRINT_DISK, "DiskInt13ExtensionsSupported()\n");
// IBM/MS INT 13 Extensions - INSTALLATION CHECK
// AH = 41h
REGS RegsOut;
PUSHORT Ptr = (PUSHORT)(BIOSCALLBUFFER);
----- DbgPrint((DPRINT_DISK, "DiskGetExtendedDriveParameters()\n"));
+++++ DPRINTM(DPRINT_DISK, "DiskGetExtendedDriveParameters()\n");
// Initialize transfer buffer
*Ptr = BufferSize;
memcpy(Buffer, Ptr, BufferSize);
----- DbgPrint((DPRINT_DISK, "size of buffer: %x\n", Ptr[0]));
----- DbgPrint((DPRINT_DISK, "information flags: %x\n", Ptr[1]));
----- DbgPrint((DPRINT_DISK, "number of physical cylinders on drive: %u\n", *(PULONG)&Ptr[2]));
----- DbgPrint((DPRINT_DISK, "number of physical heads on drive: %u\n", *(PULONG)&Ptr[4]));
----- DbgPrint((DPRINT_DISK, "number of physical sectors per track: %u\n", *(PULONG)&Ptr[6]));
----- DbgPrint((DPRINT_DISK, "total number of sectors on drive: %I64u\n", *(unsigned long long*)&Ptr[8]));
----- DbgPrint((DPRINT_DISK, "bytes per sector: %u\n", Ptr[12]));
+++++ DPRINTM(DPRINT_DISK, "size of buffer: %x\n", Ptr[0]);
+++++ DPRINTM(DPRINT_DISK, "information flags: %x\n", Ptr[1]);
+++++ DPRINTM(DPRINT_DISK, "number of physical cylinders on drive: %u\n", *(PULONG)&Ptr[2]);
+++++ DPRINTM(DPRINT_DISK, "number of physical heads on drive: %u\n", *(PULONG)&Ptr[4]);
+++++ DPRINTM(DPRINT_DISK, "number of physical sectors per track: %u\n", *(PULONG)&Ptr[6]);
+++++ DPRINTM(DPRINT_DISK, "total number of sectors on drive: %I64u\n", *(unsigned long long*)&Ptr[8]);
+++++ DPRINTM(DPRINT_DISK, "bytes per sector: %u\n", Ptr[12]);
if (Ptr[0] >= 0x1e)
{
----- DbgPrint((DPRINT_DISK, "EED configuration parameters: %x:%x\n", Ptr[13], Ptr[14]));
+++++ DPRINTM(DPRINT_DISK, "EED configuration parameters: %x:%x\n", Ptr[13], Ptr[14]);
if (Ptr[13] != 0xffff && Ptr[14] != 0xffff)
{
---- PUCHAR SpecPtr = (PUCHAR)((Ptr[13] << 4) + Ptr[14]);
---- DbgPrint((DPRINT_DISK, "SpecPtr: %x\n", SpecPtr));
---- DbgPrint((DPRINT_DISK, "physical I/O port base address: %x\n", *(PUSHORT)&SpecPtr[0]));
---- DbgPrint((DPRINT_DISK, "disk-drive control port address: %x\n", *(PUSHORT)&SpecPtr[2]));
---- DbgPrint((DPRINT_DISK, "drive flags: %x\n", SpecPtr[4]));
---- DbgPrint((DPRINT_DISK, "proprietary information: %x\n", SpecPtr[5]));
---- DbgPrint((DPRINT_DISK, "IRQ for drive: %u\n", SpecPtr[6]));
---- DbgPrint((DPRINT_DISK, "sector count for multi-sector transfers: %u\n", SpecPtr[7]));
---- DbgPrint((DPRINT_DISK, "DMA control: %x\n", SpecPtr[8]));
---- DbgPrint((DPRINT_DISK, "programmed I/O control: %x\n", SpecPtr[9]));
---- DbgPrint((DPRINT_DISK, "drive options: %x\n", *(PUSHORT)&SpecPtr[10]));
++++ PUCHAR SpecPtr = (PUCHAR)(ULONG_PTR)((Ptr[13] << 4) + Ptr[14]);
- DbgPrint((DPRINT_DISK, "SpecPtr: %x\n", SpecPtr));
- DbgPrint((DPRINT_DISK, "physical I/O port base address: %x\n", *(PUSHORT)&SpecPtr[0]));
- DbgPrint((DPRINT_DISK, "disk-drive control port address: %x\n", *(PUSHORT)&SpecPtr[2]));
- DbgPrint((DPRINT_DISK, "drive flags: %x\n", SpecPtr[4]));
- DbgPrint((DPRINT_DISK, "proprietary information: %x\n", SpecPtr[5]));
- DbgPrint((DPRINT_DISK, "IRQ for drive: %u\n", SpecPtr[6]));
- DbgPrint((DPRINT_DISK, "sector count for multi-sector transfers: %u\n", SpecPtr[7]));
- DbgPrint((DPRINT_DISK, "DMA control: %x\n", SpecPtr[8]));
- DbgPrint((DPRINT_DISK, "programmed I/O control: %x\n", SpecPtr[9]));
- DbgPrint((DPRINT_DISK, "drive options: %x\n", *(PUSHORT)&SpecPtr[10]));
+++++ DPRINTM(DPRINT_DISK, "SpecPtr: %x\n", SpecPtr);
+++++ DPRINTM(DPRINT_DISK, "physical I/O port base address: %x\n", *(PUSHORT)&SpecPtr[0]);
+++++ DPRINTM(DPRINT_DISK, "disk-drive control port address: %x\n", *(PUSHORT)&SpecPtr[2]);
+++++ DPRINTM(DPRINT_DISK, "drive flags: %x\n", SpecPtr[4]);
+++++ DPRINTM(DPRINT_DISK, "proprietary information: %x\n", SpecPtr[5]);
+++++ DPRINTM(DPRINT_DISK, "IRQ for drive: %u\n", SpecPtr[6]);
+++++ DPRINTM(DPRINT_DISK, "sector count for multi-sector transfers: %u\n", SpecPtr[7]);
+++++ DPRINTM(DPRINT_DISK, "DMA control: %x\n", SpecPtr[8]);
+++++ DPRINTM(DPRINT_DISK, "programmed I/O control: %x\n", SpecPtr[9]);
+++++ DPRINTM(DPRINT_DISK, "drive options: %x\n", *(PUSHORT)&SpecPtr[10]);
}
}
if (Ptr[0] >= 0x42)
{
----- DbgPrint((DPRINT_DISK, "signature: %x\n", Ptr[15]));
+++++ DPRINTM(DPRINT_DISK, "signature: %x\n", Ptr[15]);
}
return TRUE;
//USHORT* VideoModes;
//USHORT Index;
----- DbgPrint((DPRINT_UI, "BiosIsVesaSupported()\n"));
+++++ DPRINTM(DPRINT_UI, "BiosIsVesaSupported()\n");
RtlZeroMemory(SvgaInfo, sizeof(VESA_SVGA_INFO));
Regs.w.di = BIOSCALLBUFOFFSET;
Int386(0x10, &Regs, &Regs);
----- DbgPrint((DPRINT_UI, "AL = 0x%x\n", Regs.b.al));
----- DbgPrint((DPRINT_UI, "AH = 0x%x\n", Regs.b.ah));
+++++ DPRINTM(DPRINT_UI, "AL = 0x%x\n", Regs.b.al);
+++++ DPRINTM(DPRINT_UI, "AH = 0x%x\n", Regs.b.ah);
if (Regs.w.ax != 0x004F)
{
----- DbgPrint((DPRINT_UI, "Failed.\n"));
+++++ DPRINTM(DPRINT_UI, "Failed.\n");
return 0x0000;
}
----- DbgPrint((DPRINT_UI, "Supported.\n"));
----- DbgPrint((DPRINT_UI, "SvgaInfo->Signature[4] = %c%c%c%c\n", SvgaInfo->Signature[0], SvgaInfo->Signature[1], SvgaInfo->Signature[2], SvgaInfo->Signature[3]));
----- DbgPrint((DPRINT_UI, "SvgaInfo->VesaVersion = v%d.%d\n", ((SvgaInfo->VesaVersion >> 8) & 0xFF), (SvgaInfo->VesaVersion & 0xFF)));
----- DbgPrint((DPRINT_UI, "SvgaInfo->OemNamePtr = 0x%x\n", SvgaInfo->OemNamePtr));
----- DbgPrint((DPRINT_UI, "SvgaInfo->Capabilities = 0x%x\n", SvgaInfo->Capabilities));
----- DbgPrint((DPRINT_UI, "SvgaInfo->VideoMemory = %dK\n", SvgaInfo->TotalVideoMemory * 64));
----- DbgPrint((DPRINT_UI, "---VBE v2.0 ---\n"));
----- DbgPrint((DPRINT_UI, "SvgaInfo->OemSoftwareVersion = v%d.%d\n", ((SvgaInfo->OemSoftwareVersion >> 8) & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 12) & 0x0F) * 10), (SvgaInfo->OemSoftwareVersion & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 4) & 0x0F) * 10)));
----- DbgPrint((DPRINT_UI, "SvgaInfo->VendorNamePtr = 0x%x\n", SvgaInfo->VendorNamePtr));
----- DbgPrint((DPRINT_UI, "SvgaInfo->ProductNamePtr = 0x%x\n", SvgaInfo->ProductNamePtr));
----- DbgPrint((DPRINT_UI, "SvgaInfo->ProductRevisionStringPtr = 0x%x\n", SvgaInfo->ProductRevisionStringPtr));
----- DbgPrint((DPRINT_UI, "SvgaInfo->VBE/AF Version = 0x%x (BCD WORD)\n", SvgaInfo->VBE_AF_Version));
-----
----- //DbgPrint((DPRINT_UI, "\nSupported VESA and OEM video modes:\n"));
+++++ DPRINTM(DPRINT_UI, "Supported.\n");
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->Signature[4] = %c%c%c%c\n", SvgaInfo->Signature[0], SvgaInfo->Signature[1], SvgaInfo->Signature[2], SvgaInfo->Signature[3]);
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->VesaVersion = v%d.%d\n", ((SvgaInfo->VesaVersion >> 8) & 0xFF), (SvgaInfo->VesaVersion & 0xFF));
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->OemNamePtr = 0x%x\n", SvgaInfo->OemNamePtr);
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->Capabilities = 0x%x\n", SvgaInfo->Capabilities);
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->VideoMemory = %dK\n", SvgaInfo->TotalVideoMemory * 64);
+++++ DPRINTM(DPRINT_UI, "---VBE v2.0 ---\n");
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->OemSoftwareVersion = v%d.%d\n", ((SvgaInfo->OemSoftwareVersion >> 8) & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 12) & 0x0F) * 10), (SvgaInfo->OemSoftwareVersion & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 4) & 0x0F) * 10));
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->VendorNamePtr = 0x%x\n", SvgaInfo->VendorNamePtr);
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->ProductNamePtr = 0x%x\n", SvgaInfo->ProductNamePtr);
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->ProductRevisionStringPtr = 0x%x\n", SvgaInfo->ProductRevisionStringPtr);
+++++ DPRINTM(DPRINT_UI, "SvgaInfo->VBE/AF Version = 0x%x (BCD WORD)\n", SvgaInfo->VBE_AF_Version);
+++++
+++++ //DPRINTM(DPRINT_UI, "\nSupported VESA and OEM video modes:\n");
//VideoModes = (USHORT*)SvgaInfo->SupportedModeListPtr;
//for (Index=0; VideoModes[Index]!=0xFFFF; Index++)
//{
----- // DbgPrint((DPRINT_UI, "Mode %d: 0x%x\n", Index, VideoModes[Index]));
+++++ // DPRINTM(DPRINT_UI, "Mode %d: 0x%x\n", Index, VideoModes[Index]);
//}
//if (SvgaInfo->VesaVersion >= 0x0200)
//{
----- // DbgPrint((DPRINT_UI, "\nSupported accelerated video modes (VESA v2.0):\n"));
+++++ // DPRINTM(DPRINT_UI, "\nSupported accelerated video modes (VESA v2.0):\n");
// VideoModes = (USHORT*)SvgaInfo->AcceleratedModeListPtr;
// for (Index=0; VideoModes[Index]!=0xFFFF; Index++)
// {
----- // DbgPrint((DPRINT_UI, "Mode %d: 0x%x\n", Index, VideoModes[Index]));
+++++ // DPRINTM(DPRINT_UI, "Mode %d: 0x%x\n", Index, VideoModes[Index]);
// }
//}
----- DbgPrint((DPRINT_UI, "\n"));
+++++ DPRINTM(DPRINT_UI, "\n");
return SvgaInfo->VesaVersion;
}
#define NDEBUG
#include <debug.h>
-----#undef DbgPrint
/* Page Directory and Tables for non-PAE Systems */
extern PAGE_DIRECTORY_X86 startup_pagedirectory;
REGS RegsIn;
REGS RegsOut;
----- DbgPrint((DPRINT_DISK, "PcDiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber));
+++++ DPRINTM(DPRINT_DISK, "PcDiskResetController(0x%x) DISK OPERATION FAILED -- RESETTING CONTROLLER\n", DriveNumber);
// BIOS Int 13h, function 0 - Reset disk system
// AH = 00h
ULONG RetryCount;
PI386_DISK_ADDRESS_PACKET Packet = (PI386_DISK_ADDRESS_PACKET)(BIOSCALLBUFFER);
----- DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectorsLBA() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer));
+++++ DPRINTM(DPRINT_DISK, "PcDiskReadLogicalSectorsLBA() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer);
// BIOS int 0x13, function 42h - IBM/MS INT 13 Extensions - EXTENDED READ
RegsIn.b.ah = 0x42; // Subfunction 42h
REGS RegsOut;
ULONG RetryCount;
----- DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectorsCHS()\n"));
+++++ DPRINTM(DPRINT_DISK, "PcDiskReadLogicalSectorsCHS()\n");
//
// Get the drive geometry
REGS RegsIn;
REGS RegsOut;
----- DbgPrint((DPRINT_DISK, "PcDiskInt13ExtensionsSupported()\n"));
+++++ DPRINTM(DPRINT_DISK, "PcDiskInt13ExtensionsSupported()\n");
if (DriveNumber == LastDriveNumber)
{
----- DbgPrint((DPRINT_DISK, "Using cached value %s for drive 0x%x\n", LastSupported ? "TRUE" : "FALSE", DriveNumber));
+++++ DPRINTM(DPRINT_DISK, "Using cached value %s for drive 0x%x\n", LastSupported ? "TRUE" : "FALSE", DriveNumber);
return LastSupported;
}
BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer)
{
----- DbgPrint((DPRINT_DISK, "PcDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer));
+++++ DPRINTM(DPRINT_DISK, "PcDiskReadLogicalSectors() DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d Buffer: 0x%x\n", DriveNumber, SectorNumber, SectorCount, Buffer);
//
// Check to see if it is a fixed disk drive
//
if ((DriveNumber >= 0x80) && PcDiskInt13ExtensionsSupported(DriveNumber))
{
----- DbgPrint((DPRINT_DISK, "Using Int 13 Extensions for read. PcDiskInt13ExtensionsSupported(%d) = %s\n", DriveNumber, PcDiskInt13ExtensionsSupported(DriveNumber) ? "TRUE" : "FALSE"));
+++++ DPRINTM(DPRINT_DISK, "Using Int 13 Extensions for read. PcDiskInt13ExtensionsSupported(%d) = %s\n", DriveNumber, PcDiskInt13ExtensionsSupported(DriveNumber) ? "TRUE" : "FALSE");
//
// LBA is easy, nothing to calculate
REGS RegsOut;
ULONG Cylinders;
----- DbgPrint((DPRINT_DISK, "DiskGetDriveGeometry()\n"));
+++++ DPRINTM(DPRINT_DISK, "DiskGetDriveGeometry()\n");
/* BIOS Int 13h, function 08h - Get drive parameters
* AH = 08h
REGS RegsOut;
ULONG MemorySize;
----- DbgPrint((DPRINT_MEMORY, "GetExtendedMemorySize()\n"));
+++++ DPRINTM(DPRINT_MEMORY, "GetExtendedMemorySize()\n");
/* Int 15h AX=E801h
* Phoenix BIOS v4.0 - GET MEMORY SIZE FOR >64M CONFIGURATIONS
RegsIn.w.ax = 0xE801;
Int386(0x15, &RegsIn, &RegsOut);
----- DbgPrint((DPRINT_MEMORY, "Int15h AX=E801h\n"));
----- DbgPrint((DPRINT_MEMORY, "AX = 0x%x\n", RegsOut.w.ax));
----- DbgPrint((DPRINT_MEMORY, "BX = 0x%x\n", RegsOut.w.bx));
----- DbgPrint((DPRINT_MEMORY, "CX = 0x%x\n", RegsOut.w.cx));
----- DbgPrint((DPRINT_MEMORY, "DX = 0x%x\n", RegsOut.w.dx));
----- DbgPrint((DPRINT_MEMORY, "CF set = %s\n\n", (RegsOut.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE"));
+++++ DPRINTM(DPRINT_MEMORY, "Int15h AX=E801h\n");
+++++ DPRINTM(DPRINT_MEMORY, "AX = 0x%x\n", RegsOut.w.ax);
+++++ DPRINTM(DPRINT_MEMORY, "BX = 0x%x\n", RegsOut.w.bx);
+++++ DPRINTM(DPRINT_MEMORY, "CX = 0x%x\n", RegsOut.w.cx);
+++++ DPRINTM(DPRINT_MEMORY, "DX = 0x%x\n", RegsOut.w.dx);
+++++ DPRINTM(DPRINT_MEMORY, "CF set = %s\n\n", (RegsOut.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE");
if (INT386_SUCCESS(RegsOut))
{
RegsIn.b.ah = 0x88;
Int386(0x15, &RegsIn, &RegsOut);
----- DbgPrint((DPRINT_MEMORY, "Int15h AH=88h\n"));
----- DbgPrint((DPRINT_MEMORY, "AX = 0x%x\n", RegsOut.w.ax));
----- DbgPrint((DPRINT_MEMORY, "CF set = %s\n\n", (RegsOut.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE"));
+++++ DPRINTM(DPRINT_MEMORY, "Int15h AH=88h\n");
+++++ DPRINTM(DPRINT_MEMORY, "AX = 0x%x\n", RegsOut.w.ax);
+++++ DPRINTM(DPRINT_MEMORY, "CF set = %s\n\n", (RegsOut.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE");
if (INT386_SUCCESS(RegsOut) && RegsOut.w.ax != 0)
{
MemorySize = (MemorySize & 0xFFFF);
MemorySize = (MemorySize << 8);
----- DbgPrint((DPRINT_MEMORY, "Int15h Failed\n"));
----- DbgPrint((DPRINT_MEMORY, "CMOS reports: 0x%x\n", MemorySize));
+++++ DPRINTM(DPRINT_MEMORY, "Int15h Failed\n");
+++++ DPRINTM(DPRINT_MEMORY, "CMOS reports: 0x%x\n", MemorySize);
return MemorySize;
}
{
REGS Regs;
----- DbgPrint((DPRINT_MEMORY, "GetConventionalMemorySize()\n"));
+++++ DPRINTM(DPRINT_MEMORY, "GetConventionalMemorySize()\n");
/* Int 12h
* BIOS - GET MEMORY SIZE
Regs.w.ax = 0;
Int386(0x12, &Regs, &Regs);
----- DbgPrint((DPRINT_MEMORY, "Int12h\n"));
----- DbgPrint((DPRINT_MEMORY, "AX = 0x%x\n\n", Regs.w.ax));
+++++ DPRINTM(DPRINT_MEMORY, "Int12h\n");
+++++ DPRINTM(DPRINT_MEMORY, "AX = 0x%x\n\n", Regs.w.ax);
return (ULONG)Regs.w.ax;
}
REGS Regs;
ULONG MapCount;
----- DbgPrint((DPRINT_MEMORY, "GetBiosMemoryMap()\n"));
+++++ DPRINTM(DPRINT_MEMORY, "GetBiosMemoryMap()\n");
/* Int 15h AX=E820h
* Newer BIOSes - GET SYSTEM MEMORY MAP
{
Int386(0x15, &Regs, &Regs);
----- DbgPrint((DPRINT_MEMORY, "Memory Map Entry %d\n", MapCount));
----- DbgPrint((DPRINT_MEMORY, "Int15h AX=E820h\n"));
----- DbgPrint((DPRINT_MEMORY, "EAX = 0x%x\n", Regs.x.eax));
----- DbgPrint((DPRINT_MEMORY, "EBX = 0x%x\n", Regs.x.ebx));
----- DbgPrint((DPRINT_MEMORY, "ECX = 0x%x\n", Regs.x.ecx));
----- DbgPrint((DPRINT_MEMORY, "CF set = %s\n", (Regs.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE"));
+++++ DPRINTM(DPRINT_MEMORY, "Memory Map Entry %d\n", MapCount);
+++++ DPRINTM(DPRINT_MEMORY, "Int15h AX=E820h\n");
+++++ DPRINTM(DPRINT_MEMORY, "EAX = 0x%x\n", Regs.x.eax);
+++++ DPRINTM(DPRINT_MEMORY, "EBX = 0x%x\n", Regs.x.ebx);
+++++ DPRINTM(DPRINT_MEMORY, "ECX = 0x%x\n", Regs.x.ecx);
+++++ DPRINTM(DPRINT_MEMORY, "CF set = %s\n", (Regs.x.eflags & I386FLAG_CF) ? "TRUE" : "FALSE");
/* If the BIOS didn't return 'SMAP' in EAX then
* it doesn't support this call */
/* Copy data to caller's buffer */
RtlCopyMemory(&BiosMemoryMap[MapCount], (PVOID)BIOSCALLBUFFER, Regs.x.ecx);
- DbgPrint((DPRINT_MEMORY, "BaseAddress: 0x%p\n", (PVOID)(ULONG_PTR)BiosMemoryMap[MapCount].BaseAddress));
- DbgPrint((DPRINT_MEMORY, "Length: 0x%p\n", (PVOID)(ULONG_PTR)BiosMemoryMap[MapCount].Length));
---- DbgPrint((DPRINT_MEMORY, "BaseAddress: 0x%x%x\n", BiosMemoryMap[MapCount].BaseAddress));
---- DbgPrint((DPRINT_MEMORY, "Length: 0x%x%x\n", BiosMemoryMap[MapCount].Length));
----- DbgPrint((DPRINT_MEMORY, "Type: 0x%x\n", BiosMemoryMap[MapCount].Type));
----- DbgPrint((DPRINT_MEMORY, "Reserved: 0x%x\n", BiosMemoryMap[MapCount].Reserved));
----- DbgPrint((DPRINT_MEMORY, "\n"));
+++++ DPRINTM(DPRINT_MEMORY, "BaseAddress: 0x%p\n", (PVOID)(ULONG_PTR)BiosMemoryMap[MapCount].BaseAddress);
+++++ DPRINTM(DPRINT_MEMORY, "Length: 0x%p\n", (PVOID)(ULONG_PTR)BiosMemoryMap[MapCount].Length);
+++++ DPRINTM(DPRINT_MEMORY, "Type: 0x%x\n", BiosMemoryMap[MapCount].Type);
+++++ DPRINTM(DPRINT_MEMORY, "Reserved: 0x%x\n", BiosMemoryMap[MapCount].Reserved);
+++++ DPRINTM(DPRINT_MEMORY, "\n");
/* If the continuation value is zero or the
* carry flag is set then this was
if (Regs.x.ebx == 0x00000000 || !INT386_SUCCESS(Regs))
{
MapCount++;
----- DbgPrint((DPRINT_MEMORY, "End Of System Memory Map!\n\n"));
+++++ DPRINTM(DPRINT_MEMORY, "End Of System Memory Map!\n\n");
break;
}
RtlCopyMemory(ModeInformation, (PVOID)BIOSCALLBUFFER, sizeof(SVGA_MODE_INFORMATION));
----- DbgPrint((DPRINT_UI, "\n"));
----- DbgPrint((DPRINT_UI, "BiosVesaGetSVGAModeInformation() mode 0x%x\n", Mode));
----- DbgPrint((DPRINT_UI, "ModeAttributes = 0x%x\n", ModeInformation->ModeAttributes));
----- DbgPrint((DPRINT_UI, "WindowAttributesA = 0x%x\n", ModeInformation->WindowAttributesA));
----- DbgPrint((DPRINT_UI, "WindowAttributesB = 0x%x\n", ModeInformation->WindowsAttributesB));
----- DbgPrint((DPRINT_UI, "WindowGranularity = %dKB\n", ModeInformation->WindowGranularity));
----- DbgPrint((DPRINT_UI, "WindowSize = %dKB\n", ModeInformation->WindowSize));
----- DbgPrint((DPRINT_UI, "WindowAStartSegment = 0x%x\n", ModeInformation->WindowAStartSegment));
----- DbgPrint((DPRINT_UI, "WindowBStartSegment = 0x%x\n", ModeInformation->WindowBStartSegment));
----- DbgPrint((DPRINT_UI, "WindowPositioningFunction = 0x%x\n", ModeInformation->WindowPositioningFunction));
----- DbgPrint((DPRINT_UI, "BytesPerScanLine = %d\n", ModeInformation->BytesPerScanLine));
----- DbgPrint((DPRINT_UI, "WidthInPixels = %d\n", ModeInformation->WidthInPixels));
----- DbgPrint((DPRINT_UI, "HeightInPixels = %d\n", ModeInformation->HeightInPixels));
----- DbgPrint((DPRINT_UI, "CharacterWidthInPixels = %d\n", ModeInformation->CharacterWidthInPixels));
----- DbgPrint((DPRINT_UI, "CharacterHeightInPixels = %d\n", ModeInformation->CharacterHeightInPixels));
----- DbgPrint((DPRINT_UI, "NumberOfMemoryPlanes = %d\n", ModeInformation->NumberOfMemoryPlanes));
----- DbgPrint((DPRINT_UI, "BitsPerPixel = %d\n", ModeInformation->BitsPerPixel));
----- DbgPrint((DPRINT_UI, "NumberOfBanks = %d\n", ModeInformation->NumberOfBanks));
----- DbgPrint((DPRINT_UI, "MemoryModel = %d\n", ModeInformation->MemoryModel));
----- DbgPrint((DPRINT_UI, "BankSize = %d\n", ModeInformation->BankSize));
----- DbgPrint((DPRINT_UI, "NumberOfImagePlanes = %d\n", ModeInformation->NumberOfImagePanes));
----- DbgPrint((DPRINT_UI, "---VBE v1.2+ ---\n"));
----- DbgPrint((DPRINT_UI, "RedMaskSize = %d\n", ModeInformation->RedMaskSize));
----- DbgPrint((DPRINT_UI, "RedMaskPosition = %d\n", ModeInformation->RedMaskPosition));
----- DbgPrint((DPRINT_UI, "GreenMaskSize = %d\n", ModeInformation->GreenMaskSize));
----- DbgPrint((DPRINT_UI, "GreenMaskPosition = %d\n", ModeInformation->GreenMaskPosition));
----- DbgPrint((DPRINT_UI, "BlueMaskSize = %d\n", ModeInformation->BlueMaskSize));
----- DbgPrint((DPRINT_UI, "BlueMaskPosition = %d\n", ModeInformation->BlueMaskPosition));
----- DbgPrint((DPRINT_UI, "ReservedMaskSize = %d\n", ModeInformation->ReservedMaskSize));
----- DbgPrint((DPRINT_UI, "ReservedMaskPosition = %d\n", ModeInformation->ReservedMaskPosition));
----- DbgPrint((DPRINT_UI, "\n"));
+++++ DPRINTM(DPRINT_UI, "\n");
+++++ DPRINTM(DPRINT_UI, "BiosVesaGetSVGAModeInformation() mode 0x%x\n", Mode);
+++++ DPRINTM(DPRINT_UI, "ModeAttributes = 0x%x\n", ModeInformation->ModeAttributes);
+++++ DPRINTM(DPRINT_UI, "WindowAttributesA = 0x%x\n", ModeInformation->WindowAttributesA);
+++++ DPRINTM(DPRINT_UI, "WindowAttributesB = 0x%x\n", ModeInformation->WindowsAttributesB);
+++++ DPRINTM(DPRINT_UI, "WindowGranularity = %dKB\n", ModeInformation->WindowGranularity);
+++++ DPRINTM(DPRINT_UI, "WindowSize = %dKB\n", ModeInformation->WindowSize);
+++++ DPRINTM(DPRINT_UI, "WindowAStartSegment = 0x%x\n", ModeInformation->WindowAStartSegment);
+++++ DPRINTM(DPRINT_UI, "WindowBStartSegment = 0x%x\n", ModeInformation->WindowBStartSegment);
+++++ DPRINTM(DPRINT_UI, "WindowPositioningFunction = 0x%x\n", ModeInformation->WindowPositioningFunction);
+++++ DPRINTM(DPRINT_UI, "BytesPerScanLine = %d\n", ModeInformation->BytesPerScanLine);
+++++ DPRINTM(DPRINT_UI, "WidthInPixels = %d\n", ModeInformation->WidthInPixels);
+++++ DPRINTM(DPRINT_UI, "HeightInPixels = %d\n", ModeInformation->HeightInPixels);
+++++ DPRINTM(DPRINT_UI, "CharacterWidthInPixels = %d\n", ModeInformation->CharacterWidthInPixels);
+++++ DPRINTM(DPRINT_UI, "CharacterHeightInPixels = %d\n", ModeInformation->CharacterHeightInPixels);
+++++ DPRINTM(DPRINT_UI, "NumberOfMemoryPlanes = %d\n", ModeInformation->NumberOfMemoryPlanes);
+++++ DPRINTM(DPRINT_UI, "BitsPerPixel = %d\n", ModeInformation->BitsPerPixel);
+++++ DPRINTM(DPRINT_UI, "NumberOfBanks = %d\n", ModeInformation->NumberOfBanks);
+++++ DPRINTM(DPRINT_UI, "MemoryModel = %d\n", ModeInformation->MemoryModel);
+++++ DPRINTM(DPRINT_UI, "BankSize = %d\n", ModeInformation->BankSize);
+++++ DPRINTM(DPRINT_UI, "NumberOfImagePlanes = %d\n", ModeInformation->NumberOfImagePanes);
+++++ DPRINTM(DPRINT_UI, "---VBE v1.2+ ---\n");
+++++ DPRINTM(DPRINT_UI, "RedMaskSize = %d\n", ModeInformation->RedMaskSize);
+++++ DPRINTM(DPRINT_UI, "RedMaskPosition = %d\n", ModeInformation->RedMaskPosition);
+++++ DPRINTM(DPRINT_UI, "GreenMaskSize = %d\n", ModeInformation->GreenMaskSize);
+++++ DPRINTM(DPRINT_UI, "GreenMaskPosition = %d\n", ModeInformation->GreenMaskPosition);
+++++ DPRINTM(DPRINT_UI, "BlueMaskSize = %d\n", ModeInformation->BlueMaskSize);
+++++ DPRINTM(DPRINT_UI, "BlueMaskPosition = %d\n", ModeInformation->BlueMaskPosition);
+++++ DPRINTM(DPRINT_UI, "ReservedMaskSize = %d\n", ModeInformation->ReservedMaskSize);
+++++ DPRINTM(DPRINT_UI, "ReservedMaskPosition = %d\n", ModeInformation->ReservedMaskPosition);
+++++ DPRINTM(DPRINT_UI, "\n");
return TRUE;
}
if (VIDEOCARD_CGA_OR_OTHER == PcVideoDetectVideoCard())
{
----- DbgPrint((DPRINT_UI, "CGA or other display adapter detected.\n"));
+++++ DPRINTM(DPRINT_UI, "CGA or other display adapter detected.\n");
printf("CGA or other display adapter detected.\n");
printf("Using 80x25 text mode.\n");
VideoMode = VIDEOMODE_NORMAL_TEXT;
}
else if (VIDEOCARD_EGA == PcVideoDetectVideoCard())
{
----- DbgPrint((DPRINT_UI, "EGA display adapter detected.\n"));
+++++ DPRINTM(DPRINT_UI, "EGA display adapter detected.\n");
printf("EGA display adapter detected.\n");
printf("Using 80x25 text mode.\n");
VideoMode = VIDEOMODE_NORMAL_TEXT;
}
else /* if (VIDEOCARD_VGA == PcVideoDetectVideoCard()) */
{
----- DbgPrint((DPRINT_UI, "VGA display adapter detected.\n"));
+++++ DPRINTM(DPRINT_UI, "VGA display adapter detected.\n");
if (0 == _stricmp(DisplayModeName, "NORMAL_VGA"))
{
}
StallExecutionProcessor(10);
}
----- DbgPrint((DPRINT_DISK, "status=0x%x\n", Status));
----- DbgPrint((DPRINT_DISK, "waited %d usecs for busy to clear\n", RetryCount * 10));
+++++ DPRINTM(DPRINT_DISK, "status=0x%x\n", Status);
+++++ DPRINTM(DPRINT_DISK, "waited %d usecs for busy to clear\n", RetryCount * 10);
if (RetryCount >= IDE_MAX_BUSY_RETRIES)
{
----- DbgPrint((DPRINT_DISK, "Drive is BUSY for too long\n"));
+++++ DPRINTM(DPRINT_DISK, "Drive is BUSY for too long\n");
return FALSE;
}
/* Issue command to drive */
if (DrvHead & IDE_DH_LBA)
{
----- DbgPrint((DPRINT_DISK, "READ:DRV=%d:LBA=1:BLK=%d:SC=0x%x:CM=0x%x\n",
+++++ DPRINTM(DPRINT_DISK, "READ:DRV=%d:LBA=1:BLK=%d:SC=0x%x:CM=0x%x\n",
DrvHead & IDE_DH_DRV1 ? 1 : 0,
((DrvHead & 0x0f) << 24) + (CylinderHigh << 16) + (CylinderLow << 8) + SectorNum,
SectorCnt,
----- Command));
+++++ Command);
}
else
{
----- DbgPrint((DPRINT_DISK, "READ:DRV=%d:LBA=0:CH=0x%x:CL=0x%x:HD=0x%x:SN=0x%x:SC=0x%x:CM=0x%x\n",
+++++ DPRINTM(DPRINT_DISK, "READ:DRV=%d:LBA=0:CH=0x%x:CL=0x%x:HD=0x%x:SN=0x%x:SC=0x%x:CM=0x%x\n",
DrvHead & IDE_DH_DRV1 ? 1 : 0,
CylinderHigh,
CylinderLow,
DrvHead & 0x0f,
SectorNum,
SectorCnt,
----- Command));
+++++ Command);
}
/* Setup command parameters */
{
if (SectorCount >= SectorCnt)
{
----- DbgPrint((DPRINT_DISK, "Buffer size exceeded!\n"));
+++++ DPRINTM(DPRINT_DISK, "Buffer size exceeded!\n");
Junk = TRUE;
}
break;
{
if (SectorCount > SectorCnt)
{
----- DbgPrint((DPRINT_DISK, "Read %lu sectors of junk!\n",
----- SectorCount - SectorCnt));
+++++ DPRINTM(DPRINT_DISK, "Read %lu sectors of junk!\n",
+++++ SectorCount - SectorCnt);
}
IDEWriteDriveControl(ControlPort, 0);
StallExecutionProcessor(50);
if (DriveNumber < 0x80 || 2 <= (DriveNumber & 0x0f))
{
/* Xbox has only 1 IDE controller and no floppy */
----- DbgPrint((DPRINT_DISK, "Invalid drive number\n"));
+++++ DPRINTM(DPRINT_DISK, "Invalid drive number\n");
return FALSE;
}
if (UINT64_C(0) != ((SectorNumber + SectorCount) & UINT64_C(0xfffffffff0000000)))
{
----- DbgPrint((DPRINT_DISK, "48bit LBA required but not implemented\n"));
+++++ DPRINTM(DPRINT_DISK, "48bit LBA required but not implemented\n");
return FALSE;
}
(Atapi ? IDE_CMD_IDENT_ATAPI_DRV : IDE_CMD_IDENT_ATA_DRV),
(PUCHAR) &DrvParms))
{
----- DbgPrint((DPRINT_DISK, "XboxDiskPolledRead() failed\n"));
+++++ DPRINTM(DPRINT_DISK, "XboxDiskPolledRead() failed\n");
return FALSE;
}
}
else
{
----- DbgPrint((DPRINT_DISK, "BytesPerSector %d\n", DrvParms.BytesPerSector));
+++++ DPRINTM(DPRINT_DISK, "BytesPerSector %d\n", DrvParms.BytesPerSector);
if (DrvParms.BytesPerSector == 0)
{
Geometry->BytesPerSector = 512;
}
}
}
----- DbgPrint((DPRINT_DISK, "Cylinders %d\n", Geometry->Cylinders));
----- DbgPrint((DPRINT_DISK, "Heads %d\n", Geometry->Heads));
----- DbgPrint((DPRINT_DISK, "Sectors %d\n", Geometry->Sectors));
----- DbgPrint((DPRINT_DISK, "BytesPerSector %d\n", Geometry->BytesPerSector));
+++++ DPRINTM(DPRINT_DISK, "Cylinders %d\n", Geometry->Cylinders);
+++++ DPRINTM(DPRINT_DISK, "Heads %d\n", Geometry->Heads);
+++++ DPRINTM(DPRINT_DISK, "Sectors %d\n", Geometry->Sectors);
+++++ DPRINTM(DPRINT_DISK, "BytesPerSector %d\n", Geometry->BytesPerSector);
return TRUE;
}
/* Set 'Configuration Data' value */
Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
---- PartialResourceList = MmAllocateMemory(Size);
++++ PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate a full resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate a full resource descriptor\n");
return;
}
}
else
{
----- DbgPrint((DPRINT_HWDETECT, "Reading disk geometry failed\n"));
---- MmFreeMemory(PartialResourceList);
+++++ DPRINTM(DPRINT_HWDETECT, "Reading disk geometry failed\n");
++++ MmHeapFree(PartialResourceList);
return;
}
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
DriveNumber,
DiskGeometry->NumberOfCylinders,
DiskGeometry->NumberOfHeads,
DiskGeometry->SectorsPerTrack,
----- DiskGeometry->BytesPerSector));
+++++ DiskGeometry->BytesPerSector);
FldrSetConfigurationData(DiskKey, PartialResourceList, Size);
---- MmFreeMemory(PartialResourceList);
++++ MmHeapFree(PartialResourceList);
}
/* Read the MBR */
if (!MachDiskReadLogicalSectors(DriveNumber, 0ULL, 1, (PVOID)DISKREADBUFFER))
{
----- DbgPrint((DPRINT_HWDETECT, "Reading MBR failed\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Reading MBR failed\n");
return;
}
Mbr = (PMASTER_BOOT_RECORD)DISKREADBUFFER;
Signature = Mbr->Signature;
----- DbgPrint((DPRINT_HWDETECT, "Signature: %x\n", Signature));
+++++ DPRINTM(DPRINT_HWDETECT, "Signature: %x\n", Signature);
/* Calculate the MBR checksum */
Checksum = 0;
Checksum += Buffer[i];
}
Checksum = ~Checksum + 1;
----- DbgPrint((DPRINT_HWDETECT, "Checksum: %x\n", Checksum));
+++++ DPRINTM(DPRINT_HWDETECT, "Checksum: %x\n", Checksum);
/* Fill out the ARC disk block */
reactos_arc_disk_info[reactos_disk_count].Signature = Signature;
Identifier[17] = '-';
Identifier[18] = 'A';
Identifier[19] = 0;
----- DbgPrint((DPRINT_HWDETECT, "Identifier: %s\n", Identifier));
+++++ DPRINTM(DPRINT_HWDETECT, "Identifier: %s\n", Identifier);
/* Set identifier */
FldrSetIdentifier(DiskKey, Identifier);
}
if (! Changed)
{
----- DbgPrint((DPRINT_HWDETECT, "BIOS reports success for disk %d but data didn't change\n",
----- (int)DiskCount));
+++++ DPRINTM(DPRINT_HWDETECT, "BIOS reports success for disk %d but data didn't change\n",
+++++ (int)DiskCount);
break;
}
DiskCount++;
memset((PVOID) DISKREADBUFFER, 0xcd, 512);
}
DiskReportError(TRUE);
----- DbgPrint((DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n",
----- (int)DiskCount, (DiskCount == 1) ? "": "s"));
+++++ DPRINTM(DPRINT_HWDETECT, "BIOS reports %d harddisk%s\n",
+++++ (int)DiskCount, (DiskCount == 1) ? "": "s");
FldrCreateComponentKey(BusKey,
L"DiskController",
ControllerClass,
DiskController,
&ControllerKey);
----- DbgPrint((DPRINT_HWDETECT, "Created key: DiskController\\0\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "Created key: DiskController\\0\n");
/* Set 'ComponentInformation' value */
FldrSetComponentInformation(ControllerKey,
/* Allocate resource descriptor */
Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
sizeof(CM_INT13_DRIVE_PARAMETER) * DiskCount;
---- PartialResourceList = MmAllocateMemory(Size);
++++ PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
Int13Drives[i].MaxHeads = Geometry.Heads - 1;
Int13Drives[i].NumberDrives = DiskCount;
----- DbgPrint((DPRINT_HWDETECT,
+++++ DPRINTM(DPRINT_HWDETECT,
"Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
0x80 + i,
Geometry.Cylinders - 1,
Geometry.Heads -1,
Geometry.Sectors,
----- Geometry.BytesPerSector));
+++++ Geometry.BytesPerSector);
}
}
/* Set 'Configuration Data' value */
Size = sizeof(CM_PARTIAL_RESOURCE_LIST) -
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
---- PartialResourceList = MmAllocateMemory(Size);
++++ PartialResourceList = MmHeapAlloc(Size);
if (PartialResourceList == NULL)
{
----- DbgPrint((DPRINT_HWDETECT,
----- "Failed to allocate resource descriptor\n"));
+++++ DPRINTM(DPRINT_HWDETECT,
+++++ "Failed to allocate resource descriptor\n");
return;
}
PCONFIGURATION_COMPONENT_DATA SystemKey;
ULONG BusNumber = 0;
----- DbgPrint((DPRINT_HWDETECT, "DetectHardware()\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "DetectHardware()\n");
/* Create the 'System' key */
FldrCreateSystemKey(&SystemKey);
/* TODO: Build actual xbox's hardware configuration tree */
DetectIsaBios(SystemKey, &BusNumber);
----- DbgPrint((DPRINT_HWDETECT, "DetectHardware() Done\n"));
+++++ DPRINTM(DPRINT_HWDETECT, "DetectHardware() Done\n");
return SystemKey;
}
#define NDEBUG
#include <debug.h>
-----#undef DbgPrint
#define DbgPrint printf
extern PVOID KernelBase;
{
PCACHE_BLOCK CacheBlock = NULL;
----- DbgPrint((DPRINT_CACHE, "CacheInternalGetBlockPointer() BlockNumber = %d\n", BlockNumber));
+++++ DPRINTM(DPRINT_CACHE, "CacheInternalGetBlockPointer() BlockNumber = %d\n", BlockNumber);
CacheBlock = CacheInternalFindBlock(CacheDrive, BlockNumber);
if (CacheBlock != NULL)
{
----- DbgPrint((DPRINT_CACHE, "Cache hit! BlockNumber: %d CacheBlock->BlockNumber: %d\n", BlockNumber, CacheBlock->BlockNumber));
+++++ DPRINTM(DPRINT_CACHE, "Cache hit! BlockNumber: %d CacheBlock->BlockNumber: %d\n", BlockNumber, CacheBlock->BlockNumber);
return CacheBlock;
}
----- DbgPrint((DPRINT_CACHE, "Cache miss! BlockNumber: %d\n", BlockNumber));
+++++ DPRINTM(DPRINT_CACHE, "Cache miss! BlockNumber: %d\n", BlockNumber);
CacheBlock = CacheInternalAddBlockToCache(CacheDrive, BlockNumber);
{
PCACHE_BLOCK CacheBlock = NULL;
----- DbgPrint((DPRINT_CACHE, "CacheInternalFindBlock() BlockNumber = %d\n", BlockNumber));
+++++ DPRINTM(DPRINT_CACHE, "CacheInternalFindBlock() BlockNumber = %d\n", BlockNumber);
//
// Make sure the block list has entries before I start searching it.
{
PCACHE_BLOCK CacheBlock = NULL;
----- DbgPrint((DPRINT_CACHE, "CacheInternalAddBlockToCache() BlockNumber = %d\n", BlockNumber));
+++++ DPRINTM(DPRINT_CACHE, "CacheInternalAddBlockToCache() BlockNumber = %d\n", BlockNumber);
// Check the size of the cache so we don't exceed our limits
CacheInternalCheckCacheSizeLimits(CacheDrive);
{
PCACHE_BLOCK CacheBlockToFree;
----- DbgPrint((DPRINT_CACHE, "CacheInternalFreeBlock()\n"));
+++++ DPRINTM(DPRINT_CACHE, "CacheInternalFreeBlock()\n");
// Get a pointer to the last item in the block list
// that isn't forced to be in the cache and remove
{
ULONG NewCacheSize;
----- DbgPrint((DPRINT_CACHE, "CacheInternalCheckCacheSizeLimits()\n"));
+++++ DPRINTM(DPRINT_CACHE, "CacheInternalCheckCacheSizeLimits()\n");
// Calculate the size of the cache if we added a block
NewCacheSize = (CacheBlockCount + 1) * (CacheDrive->BlockSize * CacheDrive->BytesPerSector);
{
PCACHE_BLOCK CacheBlock;
----- DbgPrint((DPRINT_CACHE, "Dumping block list for BIOS drive 0x%x.\n", CacheDrive->DriveNumber));
----- DbgPrint((DPRINT_CACHE, "BytesPerSector: %d.\n", CacheDrive->BytesPerSector));
----- DbgPrint((DPRINT_CACHE, "BlockSize: %d.\n", CacheDrive->BlockSize));
----- DbgPrint((DPRINT_CACHE, "CacheSizeLimit: %d.\n", CacheSizeLimit));
----- DbgPrint((DPRINT_CACHE, "CacheSizeCurrent: %d.\n", CacheSizeCurrent));
----- DbgPrint((DPRINT_CACHE, "CacheBlockCount: %d.\n", CacheBlockCount));
+++++ DPRINTM(DPRINT_CACHE, "Dumping block list for BIOS drive 0x%x.\n", CacheDrive->DriveNumber);
+++++ DPRINTM(DPRINT_CACHE, "BytesPerSector: %d.\n", CacheDrive->BytesPerSector);
+++++ DPRINTM(DPRINT_CACHE, "BlockSize: %d.\n", CacheDrive->BlockSize);
+++++ DPRINTM(DPRINT_CACHE, "CacheSizeLimit: %d.\n", CacheSizeLimit);
+++++ DPRINTM(DPRINT_CACHE, "CacheSizeCurrent: %d.\n", CacheSizeCurrent);
+++++ DPRINTM(DPRINT_CACHE, "CacheBlockCount: %d.\n", CacheBlockCount);
CacheBlock = CONTAINING_RECORD(CacheDrive->CacheBlockHead.Flink, CACHE_BLOCK, ListEntry);
while (&CacheBlock->ListEntry != &CacheDrive->CacheBlockHead)
{
----- DbgPrint((DPRINT_CACHE, "Cache Block: CacheBlock: 0x%x\n", CacheBlock));
----- DbgPrint((DPRINT_CACHE, "Cache Block: Block Number: %d\n", CacheBlock->BlockNumber));
----- DbgPrint((DPRINT_CACHE, "Cache Block: Access Count: %d\n", CacheBlock->AccessCount));
----- DbgPrint((DPRINT_CACHE, "Cache Block: Block Data: 0x%x\n", CacheBlock->BlockData));
----- DbgPrint((DPRINT_CACHE, "Cache Block: Locked In Cache: %d\n", CacheBlock->LockedInCache));
+++++ DPRINTM(DPRINT_CACHE, "Cache Block: CacheBlock: 0x%x\n", CacheBlock);
+++++ DPRINTM(DPRINT_CACHE, "Cache Block: Block Number: %d\n", CacheBlock->BlockNumber);
+++++ DPRINTM(DPRINT_CACHE, "Cache Block: Access Count: %d\n", CacheBlock->AccessCount);
+++++ DPRINTM(DPRINT_CACHE, "Cache Block: Block Data: 0x%x\n", CacheBlock->BlockData);
+++++ DPRINTM(DPRINT_CACHE, "Cache Block: Locked In Cache: %d\n", CacheBlock->LockedInCache);
if (CacheBlock->BlockData == NULL)
{
VOID CacheInternalOptimizeBlockList(PCACHE_DRIVE CacheDrive, PCACHE_BLOCK CacheBlock)
{
----- DbgPrint((DPRINT_CACHE, "CacheInternalOptimizeBlockList()\n"));
+++++ DPRINTM(DPRINT_CACHE, "CacheInternalOptimizeBlockList()\n");
// Don't do this if this block is already at the head of the list
if (&CacheBlock->ListEntry != CacheDrive->CacheBlockHead.Flink)
{
CacheManagerInitialized = FALSE;
----- DbgPrint((DPRINT_CACHE, "CacheBlockCount: %d\n", CacheBlockCount));
----- DbgPrint((DPRINT_CACHE, "CacheSizeLimit: %d\n", CacheSizeLimit));
----- DbgPrint((DPRINT_CACHE, "CacheSizeCurrent: %d\n", CacheSizeCurrent));
+++++ DPRINTM(DPRINT_CACHE, "CacheBlockCount: %d\n", CacheBlockCount);
+++++ DPRINTM(DPRINT_CACHE, "CacheSizeLimit: %d\n", CacheSizeLimit);
+++++ DPRINTM(DPRINT_CACHE, "CacheSizeCurrent: %d\n", CacheSizeCurrent);
//
// Loop through and free the cache blocks
//
CacheManagerInitialized = TRUE;
----- DbgPrint((DPRINT_CACHE, "Initializing BIOS drive 0x%x.\n", DriveNumber));
----- DbgPrint((DPRINT_CACHE, "BytesPerSector: %d.\n", CacheManagerDrive.BytesPerSector));
----- DbgPrint((DPRINT_CACHE, "BlockSize: %d.\n", CacheManagerDrive.BlockSize));
----- DbgPrint((DPRINT_CACHE, "CacheSizeLimit: %d.\n", CacheSizeLimit));
+++++ DPRINTM(DPRINT_CACHE, "Initializing BIOS drive 0x%x.\n", DriveNumber);
+++++ DPRINTM(DPRINT_CACHE, "BytesPerSector: %d.\n", CacheManagerDrive.BytesPerSector);
+++++ DPRINTM(DPRINT_CACHE, "BlockSize: %d.\n", CacheManagerDrive.BlockSize);
+++++ DPRINTM(DPRINT_CACHE, "CacheSizeLimit: %d.\n", CacheSizeLimit);
return TRUE;
}
ULONG BlockCount;
ULONG Idx;
----- DbgPrint((DPRINT_CACHE, "CacheReadDiskSectors() DiskNumber: 0x%x StartSector: %d SectorCount: %d Buffer: 0x%x\n", DiskNumber, StartSector, SectorCount, Buffer));
+++++ DPRINTM(DPRINT_CACHE, "CacheReadDiskSectors() DiskNumber: 0x%x StartSector: %d SectorCount: %d Buffer: 0x%x\n", DiskNumber, StartSector, SectorCount, Buffer);
// If we aren't initialized yet then they can't do this
if (CacheManagerInitialized == FALSE)
EndBlock = (StartSector + (SectorCount - 1)) / CacheManagerDrive.BlockSize;
SectorOffsetInEndBlock = 1 + (StartSector + (SectorCount - 1)) % CacheManagerDrive.BlockSize;
BlockCount = (EndBlock - StartBlock) + 1;
----- DbgPrint((DPRINT_CACHE, "StartBlock: %d SectorOffsetInStartBlock: %d CopyLengthInStartBlock: %d EndBlock: %d SectorOffsetInEndBlock: %d BlockCount: %d\n", StartBlock, SectorOffsetInStartBlock, CopyLengthInStartBlock, EndBlock, SectorOffsetInEndBlock, BlockCount));
+++++ DPRINTM(DPRINT_CACHE, "StartBlock: %d SectorOffsetInStartBlock: %d CopyLengthInStartBlock: %d EndBlock: %d SectorOffsetInEndBlock: %d BlockCount: %d\n", StartBlock, SectorOffsetInStartBlock, CopyLengthInStartBlock, EndBlock, SectorOffsetInEndBlock, BlockCount);
//
// Read the first block into the buffer
RtlCopyMemory(Buffer,
(PVOID)((ULONG_PTR)CacheBlock->BlockData + (SectorOffsetInStartBlock * CacheManagerDrive.BytesPerSector)),
(CopyLengthInStartBlock * CacheManagerDrive.BytesPerSector));
----- DbgPrint((DPRINT_CACHE, "1 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, ((ULONG_PTR)CacheBlock->BlockData + (SectorOffsetInStartBlock * CacheManagerDrive.BytesPerSector)), (CopyLengthInStartBlock * CacheManagerDrive.BytesPerSector)));
+++++ DPRINTM(DPRINT_CACHE, "1 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, ((ULONG_PTR)CacheBlock->BlockData + (SectorOffsetInStartBlock * CacheManagerDrive.BytesPerSector)), (CopyLengthInStartBlock * CacheManagerDrive.BytesPerSector));
//
// Update the buffer address
RtlCopyMemory(Buffer,
CacheBlock->BlockData,
CacheManagerDrive.BlockSize * CacheManagerDrive.BytesPerSector);
----- DbgPrint((DPRINT_CACHE, "2 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, CacheBlock->BlockData, CacheManagerDrive.BlockSize * CacheManagerDrive.BytesPerSector));
+++++ DPRINTM(DPRINT_CACHE, "2 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, CacheBlock->BlockData, CacheManagerDrive.BlockSize * CacheManagerDrive.BytesPerSector);
//
// Update the buffer address
RtlCopyMemory(Buffer,
CacheBlock->BlockData,
SectorOffsetInEndBlock * CacheManagerDrive.BytesPerSector);
----- DbgPrint((DPRINT_CACHE, "3 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, CacheBlock->BlockData, SectorOffsetInEndBlock * CacheManagerDrive.BytesPerSector));
+++++ DPRINTM(DPRINT_CACHE, "3 - RtlCopyMemory(0x%x, 0x%x, %d)\n", Buffer, CacheBlock->BlockData, SectorOffsetInEndBlock * CacheManagerDrive.BytesPerSector);
//
// Update the buffer address
ULONG BlockCount;
ULONG Idx;
----- DbgPrint((DPRINT_CACHE, "CacheForceDiskSectorsIntoCache() DiskNumber: 0x%x StartSector: %d SectorCount: %d\n", DiskNumber, StartSector, SectorCount));
+++++ DPRINTM(DPRINT_CACHE, "CacheForceDiskSectorsIntoCache() DiskNumber: 0x%x StartSector: %d SectorCount: %d\n", DiskNumber, StartSector, SectorCount);
// If we aren't initialized yet then they can't do this
if (CacheManagerInitialized == FALSE)
{
ULONG AmountReleased;
----- DbgPrint((DPRINT_CACHE, "CacheReleaseMemory() MinimumAmountToRelease = %d\n", MinimumAmountToRelease));
+++++ DPRINTM(DPRINT_CACHE, "CacheReleaseMemory() MinimumAmountToRelease = %d\n", MinimumAmountToRelease);
// If we aren't initialized yet then they can't do this
if (CacheManagerInitialized == FALSE)
#elif defined (DEBUG_REACTOS)
ULONG DebugPrintMask = DPRINT_REACTOS | DPRINT_REGISTRY;
#elif defined (DEBUG_CUSTOM)
-----ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY |
----- DPRINT_REACTOS | DPRINT_WINDOWS | DPRINT_HWDETECT;
+++++ULONG DebugPrintMask = DPRINT_WARNING |
+++++ DPRINT_UI | DPRINT_CACHE | DPRINT_REACTOS |
+++++ DPRINT_LINUX;
#else //#elif defined (DEBUG_NONE)
ULONG DebugPrintMask = 0;
#endif
}
}
+++++ULONG
+++++DbgPrint(const char *Format, ...)
+++++{
+++++ va_list ap;
+++++ CHAR Buffer[512];
+++++ ULONG Length;
+++++ char *ptr = Buffer;
+++++
+++++ va_start(ap, Format);
+++++
+++++ /* Construct a string */
+++++ Length = _vsnprintf(Buffer, 512, Format, ap);
+++++
+++++ /* Check if we went past the buffer */
+++++ if (Length == -1)
+++++ {
+++++ /* Terminate it if we went over-board */
+++++ Buffer[sizeof(Buffer) - 1] = '\n';
+++++
+++++ /* Put maximum */
+++++ Length = sizeof(Buffer);
+++++ }
+++++
+++++ while (*ptr)
+++++ {
+++++ DebugPrintChar(*ptr++);
+++++ }
+++++
+++++ va_end(ap);
+++++ return 0;
+++++}
+++++
VOID DebugPrintHeader(ULONG Mask)
{
/* No header */
switch (Mask)
{
case DPRINT_WARNING:
----- DebugPrintChar('W');
----- DebugPrintChar('A');
----- DebugPrintChar('R');
----- DebugPrintChar('N');
----- DebugPrintChar('I');
----- DebugPrintChar('N');
----- DebugPrintChar('G');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("WARNING: ");
break;
case DPRINT_MEMORY:
----- DebugPrintChar('M');
----- DebugPrintChar('E');
----- DebugPrintChar('M');
----- DebugPrintChar('O');
----- DebugPrintChar('R');
----- DebugPrintChar('Y');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("MEMORY: ");
break;
case DPRINT_FILESYSTEM:
----- DebugPrintChar('F');
----- DebugPrintChar('I');
----- DebugPrintChar('L');
----- DebugPrintChar('E');
----- DebugPrintChar('S');
----- DebugPrintChar('Y');
----- DebugPrintChar('S');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("FILESYS: ");
break;
case DPRINT_INIFILE:
----- DebugPrintChar('I');
----- DebugPrintChar('N');
----- DebugPrintChar('I');
----- DebugPrintChar('F');
----- DebugPrintChar('I');
----- DebugPrintChar('L');
----- DebugPrintChar('E');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("INIFILE: ");
break;
case DPRINT_UI:
----- DebugPrintChar('U');
----- DebugPrintChar('I');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("UI: ");
break;
case DPRINT_DISK:
----- DebugPrintChar('D');
----- DebugPrintChar('I');
----- DebugPrintChar('S');
----- DebugPrintChar('K');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("DISK: ");
break;
case DPRINT_CACHE:
----- DebugPrintChar('C');
----- DebugPrintChar('A');
----- DebugPrintChar('C');
----- DebugPrintChar('H');
----- DebugPrintChar('E');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("CACHE: ");
break;
case DPRINT_REGISTRY:
----- DebugPrintChar('R');
----- DebugPrintChar('E');
----- DebugPrintChar('G');
----- DebugPrintChar('I');
----- DebugPrintChar('S');
----- DebugPrintChar('T');
----- DebugPrintChar('R');
----- DebugPrintChar('Y');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("REGISTER: ");
break;
case DPRINT_REACTOS:
----- DebugPrintChar('R');
----- DebugPrintChar('E');
----- DebugPrintChar('A');
----- DebugPrintChar('C');
----- DebugPrintChar('T');
----- DebugPrintChar('O');
----- DebugPrintChar('S');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("REACTOS: ");
break;
case DPRINT_LINUX:
----- DebugPrintChar('L');
----- DebugPrintChar('I');
----- DebugPrintChar('N');
----- DebugPrintChar('U');
----- DebugPrintChar('X');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("LINUX: ");
break;
case DPRINT_WINDOWS:
----- DebugPrintChar('W');
----- DebugPrintChar('I');
----- DebugPrintChar('N');
----- DebugPrintChar('L');
----- DebugPrintChar('D');
----- DebugPrintChar('R');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("WINLDR: ");
break;
case DPRINT_HWDETECT:
----- DebugPrintChar('H');
----- DebugPrintChar('W');
----- DebugPrintChar('D');
----- DebugPrintChar('E');
----- DebugPrintChar('T');
----- DebugPrintChar('E');
----- DebugPrintChar('C');
----- DebugPrintChar('T');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("HWDETECT: ");
break;
default:
----- DebugPrintChar('U');
----- DebugPrintChar('N');
----- DebugPrintChar('K');
----- DebugPrintChar('N');
----- DebugPrintChar('O');
----- DebugPrintChar('W');
----- DebugPrintChar('N');
----- DebugPrintChar(':');
----- DebugPrintChar(' ');
+++++ DbgPrint("UNKNOWN: ");
break;
}
}
-----VOID DebugPrint(ULONG Mask, char *format, ...)
+++++char* g_file;
+++++int g_line;
+++++
+++++VOID DbgPrintMask(ULONG Mask, char *format, ...)
{
va_list ap;
-- - char Buffer[4096];
++ + char Buffer[2096];
char *ptr = Buffer;
// Mask out unwanted debug messages
// Print the header if we have started a new line
if (DebugStartOfLine)
{
+++++ DbgPrint("(%s:%d) ", g_file, g_line);
DebugPrintHeader(Mask);
DebugStartOfLine = FALSE;
}
}
}
-----VOID DebugPrint1(char *format, ...)
-----{
----- va_list ap;
-- - char Buffer[4096];
- - char Buffer[2096];
----- char *ptr = Buffer;
-----
----- va_start(ap, format);
----- vsprintf(Buffer, format, ap);
----- va_end(ap);
----- while (*ptr)
----- {
----- DebugPrintChar(*ptr++);
----- }
-----}
-----
VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length)
{
PUCHAR BufPtr = (PUCHAR)Buffer;
}
DebugStartOfLine = FALSE; // We don't want line headers
----- DebugPrint(Mask, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer, Length);
+++++ DbgPrintMask(Mask, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer, Length);
for (Idx=0; Idx<Length; )
{
if (Idx < 0x0010)
{
----- DebugPrint(Mask, "000%x:\t", Idx);
+++++ DbgPrintMask(Mask, "000%x:\t", Idx);
}
else if (Idx < 0x0100)
{
----- DebugPrint(Mask, "00%x:\t", Idx);
+++++ DbgPrintMask(Mask, "00%x:\t", Idx);
}
else if (Idx < 0x1000)
{
----- DebugPrint(Mask, "0%x:\t", Idx);
+++++ DbgPrintMask(Mask, "0%x:\t", Idx);
}
else
{
----- DebugPrint(Mask, "%x:\t", Idx);
+++++ DbgPrintMask(Mask, "%x:\t", Idx);
}
for (Idx2=0; Idx2<16; Idx2++,Idx++)
{
if (BufPtr[Idx] < 0x10)
{
----- DebugPrint(Mask, "0");
+++++ DbgPrintMask(Mask, "0");
}
----- DebugPrint(Mask, "%x", BufPtr[Idx]);
+++++ DbgPrintMask(Mask, "%x", BufPtr[Idx]);
if (Idx2 == 7)
{
----- DebugPrint(Mask, "-");
+++++ DbgPrintMask(Mask, "-");
}
else
{
----- DebugPrint(Mask, " ");
+++++ DbgPrintMask(Mask, " ");
}
}
Idx -= 16;
----- DebugPrint(Mask, " ");
+++++ DbgPrintMask(Mask, " ");
for (Idx2=0; Idx2<16; Idx2++,Idx++)
{
if ((BufPtr[Idx] > 20) && (BufPtr[Idx] < 0x80))
{
----- DebugPrint(Mask, "%c", BufPtr[Idx]);
+++++ DbgPrintMask(Mask, "%c", BufPtr[Idx]);
}
else
{
----- DebugPrint(Mask, ".");
+++++ DbgPrintMask(Mask, ".");
}
}
----- DebugPrint(Mask, "\n");
+++++ DbgPrintMask(Mask, "\n");
}
}
#else
-----VOID DebugPrint(ULONG Mask, char *format, ...)
+++++VOID DbgPrintMask(ULONG Mask, char *format, ...)
{
}
#endif // defined DBG
+++++
+++++ULONG
+++++MsgBoxPrint(const char *Format, ...)
+++++{
+++++ va_list ap;
+++++ CHAR Buffer[512];
+++++ ULONG Length;
+++++
+++++ va_start(ap, Format);
+++++
+++++ /* Construct a string */
+++++ Length = _vsnprintf(Buffer, 512, Format, ap);
+++++
+++++ /* Check if we went past the buffer */
+++++ if (Length == -1U)
+++++ {
+++++ /* Terminate it if we went over-board */
+++++ Buffer[sizeof(Buffer) - 1] = '\n';
+++++
+++++ /* Put maximum */
+++++ Length = sizeof(Buffer);
+++++ }
+++++
+++++ /* Show it as a message box */
+++++ UiMessageBox(Buffer);
+++++
+++++ /* Cleanup and exit */
+++++ va_end(ap);
+++++ return 0;
+++++}
+++++
sprintf(ErrorCodeString, "%s\n\nError Code: 0x%lx\nError: %s", ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode));
----- DbgPrint((DPRINT_DISK, "%s\n", ErrorCodeString));
+++++ DPRINTM(DPRINT_DISK, "%s\n", ErrorCodeString);
UiMessageBox(ErrorCodeString);
}
UCHAR VolumeType;
ULONG ActivePartition;
----- DbgPrint((DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", BootDrive, BootPartition));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FsOpenVolume() DriveNumber: 0x%x PartitionNumber: 0x%x\n", BootDrive, BootPartition);
// Check and see if it is a floppy drive
// If so then just assume FAT12 file system type
if (DiskIsDriveRemovable(BootDrive))
{
----- DbgPrint((DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Drive is a floppy diskette drive. Assuming FAT12 file system.\n");
*DriveNumber = BootDrive;
*StartSector = 0;
// Check for ISO9660 file system type
if (BootDrive >= 0x80 && FsRecIsIso9660(BootDrive))
{
----- DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n");
*DriveNumber = BootDrive;
*StartSector = 0;
/* Check for ISO9660 file system type */
if (*DriveNumber >= 0x80 && FsRecIsIso9660(*DriveNumber))
{
----- DbgPrint((DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Drive is a cdrom drive. Assuming ISO-9660 file system.\n");
if (NULL != Device)
{
// Make sure there was only one bootable partition
if (BootablePartitionCount == 0)
{
----- DbgPrint((DPRINT_DISK, "No bootable (active) partitions found.\n"));
+++++ DPRINTM(DPRINT_DISK, "No bootable (active) partitions found.\n");
return FALSE;
}
else if (BootablePartitionCount != 1)
{
----- DbgPrint((DPRINT_DISK, "Too many bootable (active) partitions found.\n"));
+++++ DPRINTM(DPRINT_DISK, "Too many bootable (active) partitions found.\n");
return FALSE;
}
RtlCopyMemory(BootRecord, (PVOID)DISKREADBUFFER, sizeof(MASTER_BOOT_RECORD));
----- DbgPrint((DPRINT_DISK, "Dumping partition table for drive 0x%x:\n", DriveNumber));
----- DbgPrint((DPRINT_DISK, "Boot record logical start sector = %d\n", LogicalSectorNumber));
----- DbgPrint((DPRINT_DISK, "sizeof(MASTER_BOOT_RECORD) = 0x%x.\n", sizeof(MASTER_BOOT_RECORD)));
+++++ DPRINTM(DPRINT_DISK, "Dumping partition table for drive 0x%x:\n", DriveNumber);
+++++ DPRINTM(DPRINT_DISK, "Boot record logical start sector = %d\n", LogicalSectorNumber);
+++++ DPRINTM(DPRINT_DISK, "sizeof(MASTER_BOOT_RECORD) = 0x%x.\n", sizeof(MASTER_BOOT_RECORD));
for (Index=0; Index<4; Index++)
{
----- DbgPrint((DPRINT_DISK, "-------------------------------------------\n"));
----- DbgPrint((DPRINT_DISK, "Partition %d\n", (Index + 1)));
----- DbgPrint((DPRINT_DISK, "BootIndicator: 0x%x\n", BootRecord->PartitionTable[Index].BootIndicator));
----- DbgPrint((DPRINT_DISK, "StartHead: 0x%x\n", BootRecord->PartitionTable[Index].StartHead));
----- DbgPrint((DPRINT_DISK, "StartSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].StartSector));
----- DbgPrint((DPRINT_DISK, "StartCylinder: 0x%x\n", BootRecord->PartitionTable[Index].StartCylinder));
----- DbgPrint((DPRINT_DISK, "SystemIndicator: 0x%x\n", BootRecord->PartitionTable[Index].SystemIndicator));
----- DbgPrint((DPRINT_DISK, "EndHead: 0x%x\n", BootRecord->PartitionTable[Index].EndHead));
----- DbgPrint((DPRINT_DISK, "EndSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].EndSector));
----- DbgPrint((DPRINT_DISK, "EndCylinder: 0x%x\n", BootRecord->PartitionTable[Index].EndCylinder));
----- DbgPrint((DPRINT_DISK, "SectorCountBeforePartition: 0x%x\n", BootRecord->PartitionTable[Index].SectorCountBeforePartition));
----- DbgPrint((DPRINT_DISK, "PartitionSectorCount: 0x%x\n", BootRecord->PartitionTable[Index].PartitionSectorCount));
+++++ DPRINTM(DPRINT_DISK, "-------------------------------------------\n");
+++++ DPRINTM(DPRINT_DISK, "Partition %d\n", (Index + 1));
+++++ DPRINTM(DPRINT_DISK, "BootIndicator: 0x%x\n", BootRecord->PartitionTable[Index].BootIndicator);
+++++ DPRINTM(DPRINT_DISK, "StartHead: 0x%x\n", BootRecord->PartitionTable[Index].StartHead);
+++++ DPRINTM(DPRINT_DISK, "StartSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].StartSector);
+++++ DPRINTM(DPRINT_DISK, "StartCylinder: 0x%x\n", BootRecord->PartitionTable[Index].StartCylinder);
+++++ DPRINTM(DPRINT_DISK, "SystemIndicator: 0x%x\n", BootRecord->PartitionTable[Index].SystemIndicator);
+++++ DPRINTM(DPRINT_DISK, "EndHead: 0x%x\n", BootRecord->PartitionTable[Index].EndHead);
+++++ DPRINTM(DPRINT_DISK, "EndSector (Plus 2 cylinder bits): 0x%x\n", BootRecord->PartitionTable[Index].EndSector);
+++++ DPRINTM(DPRINT_DISK, "EndCylinder: 0x%x\n", BootRecord->PartitionTable[Index].EndCylinder);
+++++ DPRINTM(DPRINT_DISK, "SectorCountBeforePartition: 0x%x\n", BootRecord->PartitionTable[Index].SectorCountBeforePartition);
+++++ DPRINTM(DPRINT_DISK, "PartitionSectorCount: 0x%x\n", BootRecord->PartitionTable[Index].PartitionSectorCount);
}
// Check the partition table magic value
DriveMapList.DriveMap[(DriveMapList.DriveMapCount * 2)+1] = DriveMapGetBiosDriveNumber(Drive2);
DriveMapList.DriveMapCount++;
----- DbgPrint((DPRINT_WARNING, "Mapping BIOS drive 0x%x to drive 0x%x\n", DriveMapGetBiosDriveNumber(Drive1), DriveMapGetBiosDriveNumber(Drive2)));
+++++ DPRINTM(DPRINT_WARNING, "Mapping BIOS drive 0x%x to drive 0x%x\n", DriveMapGetBiosDriveNumber(Drive1), DriveMapGetBiosDriveNumber(Drive2));
}
}
}
if (DriveMapList.DriveMapCount)
{
----- DbgPrint((DPRINT_WARNING, "Installing Int13 drive map for %d drives.\n", DriveMapList.DriveMapCount));
+++++ DPRINTM(DPRINT_WARNING, "Installing Int13 drive map for %d drives.\n", DriveMapList.DriveMapCount);
DriveMapInstallInt13Handler(&DriveMapList);
}
else
{
----- DbgPrint((DPRINT_WARNING, "Removing any previously installed Int13 drive map.\n"));
+++++ DPRINTM(DPRINT_WARNING, "Removing any previously installed Int13 drive map.\n");
DriveMapRemoveInt13Handler();
}
}
DebugInit();
----- DbgPrint((DPRINT_WARNING, "BootMain() called.\n"));
+++++ DPRINTM(DPRINT_WARNING, "BootMain() called.\n");
if (!UiInitialize(FALSE))
{
<file>versuart.c</file>
</if>
</directory>
---- <file>_alloca.S</file>
---- <file>mach.c</file>
+
+ <if property="ARCH" value="amd64">
+ <directory name="amd64">
---- <file>i386disk.c</file>
+++++ <file>loader.c</file>
+++++ </directory>
+++++ <directory name="i386">
+ <file>hardware.c</file>
+ <file>hwacpi.c</file>
+ <file>hwapm.c</file>
+ <file>hwpci.c</file>
- - <file>loader.c</file>
+ <file>i386rtl.c</file>
+++++ <file>i386disk.c</file>
+ <file>i386vid.c</file>
+++++ <file>machpc.c</file>
+ <file>pccons.c</file>
+ <file>pcdisk.c</file>
+ <file>pcmem.c</file>
+ <file>pcrtc.c</file>
+ <file>pcvideo.c</file>
+ </directory>
+ </if>
+
</directory>
</module>
BOOLEAN Ext2OpenVolume(UCHAR DriveNumber, ULONGLONG VolumeStartSector, ULONGLONG PartitionSectorCount)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2OpenVolume() DriveNumber = 0x%x VolumeStartSector = %d\n", DriveNumber, VolumeStartSector));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2OpenVolume() DriveNumber = 0x%x VolumeStartSector = %d\n", DriveNumber, VolumeStartSector);
// Store the drive number and start sector
Ext2DriveNumber = DriveNumber;
CHAR FullPath[EXT3_NAME_LEN * 2];
ULONG Index;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2OpenFile() FileName = %s\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2OpenFile() FileName = %s\n", FileName);
RtlZeroMemory(SymLinkPath, EXT3_NAME_LEN);
// and re-call this function
if ((TempExt2FileInfo.Inode.i_mode & EXT2_S_IFMT) == EXT2_S_IFLNK)
{
----- DbgPrint((DPRINT_FILESYSTEM, "File is a symbolic link\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "File is a symbolic link\n");
// Now read in the symbolic link path
if (!Ext2ReadFileBig(&TempExt2FileInfo, TempExt2FileInfo.FileSize, NULL, SymLinkPath))
return NULL;
}
----- DbgPrint((DPRINT_FILESYSTEM, "Symbolic link path = %s\n", SymLinkPath));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Symbolic link path = %s\n", SymLinkPath);
// Get the full path
if (SymLinkPath[0] == '/' || SymLinkPath[0] == '\\')
strcat(FullPath, SymLinkPath);
}
----- DbgPrint((DPRINT_FILESYSTEM, "Full file path = %s\n", FullPath));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Full file path = %s\n", FullPath);
if (TempExt2FileInfo.FileBlockList != NULL)
{
EXT2_INODE InodeData;
EXT2_DIR_ENTRY DirectoryEntry;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2LookupFile() FileName = %s\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2LookupFile() FileName = %s\n", FileName);
RtlZeroMemory(Ext2FileInfoPointer, sizeof(EXT2_FILE_INFO));
ULONG CurrentOffset;
PEXT2_DIR_ENTRY CurrentDirectoryEntry;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2SearchDirectoryBufferForFile() DirectoryBuffer = 0x%x DirectorySize = %d FileName = %s\n", DirectoryBuffer, DirectorySize, FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2SearchDirectoryBufferForFile() DirectoryBuffer = 0x%x DirectorySize = %d FileName = %s\n", DirectoryBuffer, DirectorySize, FileName);
for (CurrentOffset=0; CurrentOffset<DirectorySize; )
{
return FALSE;
}
----- DbgPrint((DPRINT_FILESYSTEM, "Dumping directory entry at offset %d:\n", CurrentOffset));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Dumping directory entry at offset %d:\n", CurrentOffset);
DbgDumpBuffer(DPRINT_FILESYSTEM, CurrentDirectoryEntry, CurrentDirectoryEntry->rec_len);
if ((_strnicmp(FileName, CurrentDirectoryEntry->name, CurrentDirectoryEntry->name_len) == 0) &&
{
RtlCopyMemory(DirectoryEntry, CurrentDirectoryEntry, sizeof(EXT2_DIR_ENTRY));
----- DbgPrint((DPRINT_FILESYSTEM, "EXT2 Directory Entry:\n"));
----- DbgPrint((DPRINT_FILESYSTEM, "inode = %d\n", DirectoryEntry->inode));
----- DbgPrint((DPRINT_FILESYSTEM, "rec_len = %d\n", DirectoryEntry->rec_len));
----- DbgPrint((DPRINT_FILESYSTEM, "name_len = %d\n", DirectoryEntry->name_len));
----- DbgPrint((DPRINT_FILESYSTEM, "file_type = %d\n", DirectoryEntry->file_type));
----- DbgPrint((DPRINT_FILESYSTEM, "name = "));
+++++ DPRINTM(DPRINT_FILESYSTEM, "EXT2 Directory Entry:\n");
+++++ DPRINTM(DPRINT_FILESYSTEM, "inode = %d\n", DirectoryEntry->inode);
+++++ DPRINTM(DPRINT_FILESYSTEM, "rec_len = %d\n", DirectoryEntry->rec_len);
+++++ DPRINTM(DPRINT_FILESYSTEM, "name_len = %d\n", DirectoryEntry->name_len);
+++++ DPRINTM(DPRINT_FILESYSTEM, "file_type = %d\n", DirectoryEntry->file_type);
+++++ DPRINTM(DPRINT_FILESYSTEM, "name = ");
for (CurrentOffset=0; CurrentOffset<DirectoryEntry->name_len; CurrentOffset++)
{
----- DbgPrint((DPRINT_FILESYSTEM, "%c", DirectoryEntry->name[CurrentOffset]));
+++++ DPRINTM(DPRINT_FILESYSTEM, "%c", DirectoryEntry->name[CurrentOffset]);
}
----- DbgPrint((DPRINT_FILESYSTEM, "\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "\n");
return TRUE;
}
ULONG LengthInBlock;
ULONG NumberOfBlocks;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadFileBig() BytesToRead = %d Buffer = 0x%x\n", (ULONG)BytesToRead, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadFileBig() BytesToRead = %d Buffer = 0x%x\n", (ULONG)BytesToRead, Buffer);
if (BytesRead != NULL)
{
if (((Ext2FileInfo->Inode.i_mode & EXT2_S_IFMT) == EXT2_S_IFLNK) &&
(Ext2FileInfo->FileSize <= FAST_SYMLINK_MAX_NAME_SIZE))
{
----- DbgPrint((DPRINT_FILESYSTEM, "Reading fast symbolic link data\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Reading fast symbolic link data\n");
// Copy the data from the link
RtlCopyMemory(Buffer, (PVOID)((ULONG_PTR)Ext2FileInfo->FilePointer + Ext2FileInfo->Inode.i_block), BytesToRead);
{
PEXT2_FILE_INFO Ext2FileHandle = (PEXT2_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2GetFileSize() FileSize = %d\n", Ext2FileHandle->FileSize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2GetFileSize() FileSize = %d\n", Ext2FileHandle->FileSize);
return Ext2FileHandle->FileSize;
}
{
PEXT2_FILE_INFO Ext2FileHandle = (PEXT2_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2SetFilePointer() NewFilePointer = %d\n", NewFilePointer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2SetFilePointer() NewFilePointer = %d\n", NewFilePointer);
Ext2FileHandle->FilePointer = NewFilePointer;
}
{
PEXT2_FILE_INFO Ext2FileHandle = (PEXT2_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2GetFilePointer() FilePointer = %d\n", Ext2FileHandle->FilePointer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2GetFilePointer() FilePointer = %d\n", Ext2FileHandle->FilePointer);
return Ext2FileHandle->FilePointer;
}
BOOLEAN Ext2ReadSuperBlock(VOID)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadSuperBlock()\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadSuperBlock()\n");
//
// Free any memory previously allocated
}
RtlCopyMemory(Ext2SuperBlock, (PVOID)(DISKREADBUFFER + 1024), 1024);
----- DbgPrint((DPRINT_FILESYSTEM, "Dumping super block:\n"));
-----
----- DbgPrint((DPRINT_FILESYSTEM, "s_inodes_count: %d\n", Ext2SuperBlock->s_inodes_count));
----- DbgPrint((DPRINT_FILESYSTEM, "s_blocks_count: %d\n", Ext2SuperBlock->s_blocks_count));
----- DbgPrint((DPRINT_FILESYSTEM, "s_r_blocks_count: %d\n", Ext2SuperBlock->s_r_blocks_count));
----- DbgPrint((DPRINT_FILESYSTEM, "s_free_blocks_count: %d\n", Ext2SuperBlock->s_free_blocks_count));
----- DbgPrint((DPRINT_FILESYSTEM, "s_free_inodes_count: %d\n", Ext2SuperBlock->s_free_inodes_count));
----- DbgPrint((DPRINT_FILESYSTEM, "s_first_data_block: %d\n", Ext2SuperBlock->s_first_data_block));
----- DbgPrint((DPRINT_FILESYSTEM, "s_log_block_size: %d\n", Ext2SuperBlock->s_log_block_size));
----- DbgPrint((DPRINT_FILESYSTEM, "s_log_frag_size: %d\n", Ext2SuperBlock->s_log_frag_size));
----- DbgPrint((DPRINT_FILESYSTEM, "s_blocks_per_group: %d\n", Ext2SuperBlock->s_blocks_per_group));
----- DbgPrint((DPRINT_FILESYSTEM, "s_frags_per_group: %d\n", Ext2SuperBlock->s_frags_per_group));
----- DbgPrint((DPRINT_FILESYSTEM, "s_inodes_per_group: %d\n", Ext2SuperBlock->s_inodes_per_group));
----- DbgPrint((DPRINT_FILESYSTEM, "s_mtime: %d\n", Ext2SuperBlock->s_mtime));
----- DbgPrint((DPRINT_FILESYSTEM, "s_wtime: %d\n", Ext2SuperBlock->s_wtime));
----- DbgPrint((DPRINT_FILESYSTEM, "s_mnt_count: %d\n", Ext2SuperBlock->s_mnt_count));
----- DbgPrint((DPRINT_FILESYSTEM, "s_max_mnt_count: %d\n", Ext2SuperBlock->s_max_mnt_count));
----- DbgPrint((DPRINT_FILESYSTEM, "s_magic: 0x%x\n", Ext2SuperBlock->s_magic));
----- DbgPrint((DPRINT_FILESYSTEM, "s_state: %d\n", Ext2SuperBlock->s_state));
----- DbgPrint((DPRINT_FILESYSTEM, "s_errors: %d\n", Ext2SuperBlock->s_errors));
----- DbgPrint((DPRINT_FILESYSTEM, "s_minor_rev_level: %d\n", Ext2SuperBlock->s_minor_rev_level));
----- DbgPrint((DPRINT_FILESYSTEM, "s_lastcheck: %d\n", Ext2SuperBlock->s_lastcheck));
----- DbgPrint((DPRINT_FILESYSTEM, "s_checkinterval: %d\n", Ext2SuperBlock->s_checkinterval));
----- DbgPrint((DPRINT_FILESYSTEM, "s_creator_os: %d\n", Ext2SuperBlock->s_creator_os));
----- DbgPrint((DPRINT_FILESYSTEM, "s_rev_level: %d\n", Ext2SuperBlock->s_rev_level));
----- DbgPrint((DPRINT_FILESYSTEM, "s_def_resuid: %d\n", Ext2SuperBlock->s_def_resuid));
----- DbgPrint((DPRINT_FILESYSTEM, "s_def_resgid: %d\n", Ext2SuperBlock->s_def_resgid));
----- DbgPrint((DPRINT_FILESYSTEM, "s_first_ino: %d\n", Ext2SuperBlock->s_first_ino));
----- DbgPrint((DPRINT_FILESYSTEM, "s_inode_size: %d\n", Ext2SuperBlock->s_inode_size));
----- DbgPrint((DPRINT_FILESYSTEM, "s_block_group_nr: %d\n", Ext2SuperBlock->s_block_group_nr));
----- DbgPrint((DPRINT_FILESYSTEM, "s_feature_compat: 0x%x\n", Ext2SuperBlock->s_feature_compat));
----- DbgPrint((DPRINT_FILESYSTEM, "s_feature_incompat: 0x%x\n", Ext2SuperBlock->s_feature_incompat));
----- DbgPrint((DPRINT_FILESYSTEM, "s_feature_ro_compat: 0x%x\n", Ext2SuperBlock->s_feature_ro_compat));
----- DbgPrint((DPRINT_FILESYSTEM, "s_uuid[16] = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", Ext2SuperBlock->s_uuid[0], Ext2SuperBlock->s_uuid[1], Ext2SuperBlock->s_uuid[2], Ext2SuperBlock->s_uuid[3], Ext2SuperBlock->s_uuid[4], Ext2SuperBlock->s_uuid[5], Ext2SuperBlock->s_uuid[6], Ext2SuperBlock->s_uuid[7], Ext2SuperBlock->s_uuid[8], Ext2SuperBlock->s_uuid[9], Ext2SuperBlock->s_uuid[10], Ext2SuperBlock->s_uuid[11], Ext2SuperBlock->s_uuid[12], Ext2SuperBlock->s_uuid[13], Ext2SuperBlock->s_uuid[14], Ext2SuperBlock->s_uuid[15]));
----- DbgPrint((DPRINT_FILESYSTEM, "s_volume_name[16] = '%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c'\n", Ext2SuperBlock->s_volume_name[0], Ext2SuperBlock->s_volume_name[1], Ext2SuperBlock->s_volume_name[2], Ext2SuperBlock->s_volume_name[3], Ext2SuperBlock->s_volume_name[4], Ext2SuperBlock->s_volume_name[5], Ext2SuperBlock->s_volume_name[6], Ext2SuperBlock->s_volume_name[7], Ext2SuperBlock->s_volume_name[8], Ext2SuperBlock->s_volume_name[9], Ext2SuperBlock->s_volume_name[10], Ext2SuperBlock->s_volume_name[11], Ext2SuperBlock->s_volume_name[12], Ext2SuperBlock->s_volume_name[13], Ext2SuperBlock->s_volume_name[14], Ext2SuperBlock->s_volume_name[15]));
----- DbgPrint((DPRINT_FILESYSTEM, "s_last_mounted[64]='%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c'\n", Ext2SuperBlock->s_last_mounted[0], Ext2SuperBlock->s_last_mounted[1], Ext2SuperBlock->s_last_mounted[2], Ext2SuperBlock->s_last_mounted[3], Ext2SuperBlock->s_last_mounted[4], Ext2SuperBlock->s_last_mounted[5], Ext2SuperBlock->s_last_mounted[6], Ext2SuperBlock->s_last_mounted[7], Ext2SuperBlock->s_last_mounted[8], Ext2SuperBlock->s_last_mounted[9],
+++++ DPRINTM(DPRINT_FILESYSTEM, "Dumping super block:\n");
+++++
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_inodes_count: %d\n", Ext2SuperBlock->s_inodes_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_blocks_count: %d\n", Ext2SuperBlock->s_blocks_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_r_blocks_count: %d\n", Ext2SuperBlock->s_r_blocks_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_free_blocks_count: %d\n", Ext2SuperBlock->s_free_blocks_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_free_inodes_count: %d\n", Ext2SuperBlock->s_free_inodes_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_first_data_block: %d\n", Ext2SuperBlock->s_first_data_block);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_log_block_size: %d\n", Ext2SuperBlock->s_log_block_size);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_log_frag_size: %d\n", Ext2SuperBlock->s_log_frag_size);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_blocks_per_group: %d\n", Ext2SuperBlock->s_blocks_per_group);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_frags_per_group: %d\n", Ext2SuperBlock->s_frags_per_group);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_inodes_per_group: %d\n", Ext2SuperBlock->s_inodes_per_group);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_mtime: %d\n", Ext2SuperBlock->s_mtime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_wtime: %d\n", Ext2SuperBlock->s_wtime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_mnt_count: %d\n", Ext2SuperBlock->s_mnt_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_max_mnt_count: %d\n", Ext2SuperBlock->s_max_mnt_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_magic: 0x%x\n", Ext2SuperBlock->s_magic);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_state: %d\n", Ext2SuperBlock->s_state);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_errors: %d\n", Ext2SuperBlock->s_errors);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_minor_rev_level: %d\n", Ext2SuperBlock->s_minor_rev_level);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_lastcheck: %d\n", Ext2SuperBlock->s_lastcheck);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_checkinterval: %d\n", Ext2SuperBlock->s_checkinterval);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_creator_os: %d\n", Ext2SuperBlock->s_creator_os);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_rev_level: %d\n", Ext2SuperBlock->s_rev_level);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_def_resuid: %d\n", Ext2SuperBlock->s_def_resuid);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_def_resgid: %d\n", Ext2SuperBlock->s_def_resgid);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_first_ino: %d\n", Ext2SuperBlock->s_first_ino);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_inode_size: %d\n", Ext2SuperBlock->s_inode_size);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_block_group_nr: %d\n", Ext2SuperBlock->s_block_group_nr);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_feature_compat: 0x%x\n", Ext2SuperBlock->s_feature_compat);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_feature_incompat: 0x%x\n", Ext2SuperBlock->s_feature_incompat);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_feature_ro_compat: 0x%x\n", Ext2SuperBlock->s_feature_ro_compat);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_uuid[16] = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", Ext2SuperBlock->s_uuid[0], Ext2SuperBlock->s_uuid[1], Ext2SuperBlock->s_uuid[2], Ext2SuperBlock->s_uuid[3], Ext2SuperBlock->s_uuid[4], Ext2SuperBlock->s_uuid[5], Ext2SuperBlock->s_uuid[6], Ext2SuperBlock->s_uuid[7], Ext2SuperBlock->s_uuid[8], Ext2SuperBlock->s_uuid[9], Ext2SuperBlock->s_uuid[10], Ext2SuperBlock->s_uuid[11], Ext2SuperBlock->s_uuid[12], Ext2SuperBlock->s_uuid[13], Ext2SuperBlock->s_uuid[14], Ext2SuperBlock->s_uuid[15]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_volume_name[16] = '%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c'\n", Ext2SuperBlock->s_volume_name[0], Ext2SuperBlock->s_volume_name[1], Ext2SuperBlock->s_volume_name[2], Ext2SuperBlock->s_volume_name[3], Ext2SuperBlock->s_volume_name[4], Ext2SuperBlock->s_volume_name[5], Ext2SuperBlock->s_volume_name[6], Ext2SuperBlock->s_volume_name[7], Ext2SuperBlock->s_volume_name[8], Ext2SuperBlock->s_volume_name[9], Ext2SuperBlock->s_volume_name[10], Ext2SuperBlock->s_volume_name[11], Ext2SuperBlock->s_volume_name[12], Ext2SuperBlock->s_volume_name[13], Ext2SuperBlock->s_volume_name[14], Ext2SuperBlock->s_volume_name[15]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_last_mounted[64]='%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c'\n", Ext2SuperBlock->s_last_mounted[0], Ext2SuperBlock->s_last_mounted[1], Ext2SuperBlock->s_last_mounted[2], Ext2SuperBlock->s_last_mounted[3], Ext2SuperBlock->s_last_mounted[4], Ext2SuperBlock->s_last_mounted[5], Ext2SuperBlock->s_last_mounted[6], Ext2SuperBlock->s_last_mounted[7], Ext2SuperBlock->s_last_mounted[8], Ext2SuperBlock->s_last_mounted[9],
Ext2SuperBlock->s_last_mounted[10], Ext2SuperBlock->s_last_mounted[11], Ext2SuperBlock->s_last_mounted[12], Ext2SuperBlock->s_last_mounted[13], Ext2SuperBlock->s_last_mounted[14], Ext2SuperBlock->s_last_mounted[15], Ext2SuperBlock->s_last_mounted[16], Ext2SuperBlock->s_last_mounted[17], Ext2SuperBlock->s_last_mounted[18], Ext2SuperBlock->s_last_mounted[19],
Ext2SuperBlock->s_last_mounted[20], Ext2SuperBlock->s_last_mounted[21], Ext2SuperBlock->s_last_mounted[22], Ext2SuperBlock->s_last_mounted[23], Ext2SuperBlock->s_last_mounted[24], Ext2SuperBlock->s_last_mounted[25], Ext2SuperBlock->s_last_mounted[26], Ext2SuperBlock->s_last_mounted[27], Ext2SuperBlock->s_last_mounted[28], Ext2SuperBlock->s_last_mounted[29],
Ext2SuperBlock->s_last_mounted[30], Ext2SuperBlock->s_last_mounted[31], Ext2SuperBlock->s_last_mounted[32], Ext2SuperBlock->s_last_mounted[33], Ext2SuperBlock->s_last_mounted[34], Ext2SuperBlock->s_last_mounted[35], Ext2SuperBlock->s_last_mounted[36], Ext2SuperBlock->s_last_mounted[37], Ext2SuperBlock->s_last_mounted[38], Ext2SuperBlock->s_last_mounted[39],
Ext2SuperBlock->s_last_mounted[40], Ext2SuperBlock->s_last_mounted[41], Ext2SuperBlock->s_last_mounted[42], Ext2SuperBlock->s_last_mounted[43], Ext2SuperBlock->s_last_mounted[44], Ext2SuperBlock->s_last_mounted[45], Ext2SuperBlock->s_last_mounted[46], Ext2SuperBlock->s_last_mounted[47], Ext2SuperBlock->s_last_mounted[48], Ext2SuperBlock->s_last_mounted[49],
Ext2SuperBlock->s_last_mounted[50], Ext2SuperBlock->s_last_mounted[51], Ext2SuperBlock->s_last_mounted[52], Ext2SuperBlock->s_last_mounted[53], Ext2SuperBlock->s_last_mounted[54], Ext2SuperBlock->s_last_mounted[55], Ext2SuperBlock->s_last_mounted[56], Ext2SuperBlock->s_last_mounted[57], Ext2SuperBlock->s_last_mounted[58], Ext2SuperBlock->s_last_mounted[59],
----- Ext2SuperBlock->s_last_mounted[60], Ext2SuperBlock->s_last_mounted[61], Ext2SuperBlock->s_last_mounted[62], Ext2SuperBlock->s_last_mounted[63]));
----- DbgPrint((DPRINT_FILESYSTEM, "s_algorithm_usage_bitmap = 0x%x\n", Ext2SuperBlock->s_algorithm_usage_bitmap));
----- DbgPrint((DPRINT_FILESYSTEM, "s_prealloc_blocks = %d\n", Ext2SuperBlock->s_prealloc_blocks));
----- DbgPrint((DPRINT_FILESYSTEM, "s_prealloc_dir_blocks = %d\n", Ext2SuperBlock->s_prealloc_dir_blocks));
----- DbgPrint((DPRINT_FILESYSTEM, "s_padding1 = %d\n", Ext2SuperBlock->s_padding1));
----- DbgPrint((DPRINT_FILESYSTEM, "s_journal_uuid[16] = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", Ext2SuperBlock->s_journal_uuid[0], Ext2SuperBlock->s_journal_uuid[1], Ext2SuperBlock->s_journal_uuid[2], Ext2SuperBlock->s_journal_uuid[3], Ext2SuperBlock->s_journal_uuid[4], Ext2SuperBlock->s_journal_uuid[5], Ext2SuperBlock->s_journal_uuid[6], Ext2SuperBlock->s_journal_uuid[7], Ext2SuperBlock->s_journal_uuid[8], Ext2SuperBlock->s_journal_uuid[9], Ext2SuperBlock->s_journal_uuid[10], Ext2SuperBlock->s_journal_uuid[11], Ext2SuperBlock->s_journal_uuid[12], Ext2SuperBlock->s_journal_uuid[13], Ext2SuperBlock->s_journal_uuid[14], Ext2SuperBlock->s_journal_uuid[15]));
----- DbgPrint((DPRINT_FILESYSTEM, "s_journal_inum = %d\n", Ext2SuperBlock->s_journal_inum));
----- DbgPrint((DPRINT_FILESYSTEM, "s_journal_dev = %d\n", Ext2SuperBlock->s_journal_dev));
----- DbgPrint((DPRINT_FILESYSTEM, "s_last_orphan = %d\n", Ext2SuperBlock->s_last_orphan));
+++++ Ext2SuperBlock->s_last_mounted[60], Ext2SuperBlock->s_last_mounted[61], Ext2SuperBlock->s_last_mounted[62], Ext2SuperBlock->s_last_mounted[63]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_algorithm_usage_bitmap = 0x%x\n", Ext2SuperBlock->s_algorithm_usage_bitmap);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_prealloc_blocks = %d\n", Ext2SuperBlock->s_prealloc_blocks);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_prealloc_dir_blocks = %d\n", Ext2SuperBlock->s_prealloc_dir_blocks);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_padding1 = %d\n", Ext2SuperBlock->s_padding1);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_journal_uuid[16] = 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", Ext2SuperBlock->s_journal_uuid[0], Ext2SuperBlock->s_journal_uuid[1], Ext2SuperBlock->s_journal_uuid[2], Ext2SuperBlock->s_journal_uuid[3], Ext2SuperBlock->s_journal_uuid[4], Ext2SuperBlock->s_journal_uuid[5], Ext2SuperBlock->s_journal_uuid[6], Ext2SuperBlock->s_journal_uuid[7], Ext2SuperBlock->s_journal_uuid[8], Ext2SuperBlock->s_journal_uuid[9], Ext2SuperBlock->s_journal_uuid[10], Ext2SuperBlock->s_journal_uuid[11], Ext2SuperBlock->s_journal_uuid[12], Ext2SuperBlock->s_journal_uuid[13], Ext2SuperBlock->s_journal_uuid[14], Ext2SuperBlock->s_journal_uuid[15]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_journal_inum = %d\n", Ext2SuperBlock->s_journal_inum);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_journal_dev = %d\n", Ext2SuperBlock->s_journal_dev);
+++++ DPRINTM(DPRINT_FILESYSTEM, "s_last_orphan = %d\n", Ext2SuperBlock->s_last_orphan);
//
// Check the super block magic
// Calculate the group count
Ext2GroupCount = (Ext2SuperBlock->s_blocks_count - Ext2SuperBlock->s_first_data_block + Ext2SuperBlock->s_blocks_per_group - 1) / Ext2SuperBlock->s_blocks_per_group;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2GroupCount: %d\n", Ext2GroupCount));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2GroupCount: %d\n", Ext2GroupCount);
// Calculate the block size
Ext2BlockSizeInBytes = 1024 << Ext2SuperBlock->s_log_block_size;
Ext2BlockSizeInSectors = Ext2BlockSizeInBytes / Ext2DiskGeometry.BytesPerSector;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2BlockSizeInBytes: %d\n", Ext2BlockSizeInBytes));
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2BlockSizeInSectors: %d\n", Ext2BlockSizeInSectors));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2BlockSizeInBytes: %d\n", Ext2BlockSizeInBytes);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2BlockSizeInSectors: %d\n", Ext2BlockSizeInSectors);
// Calculate the fragment size
if (Ext2SuperBlock->s_log_frag_size >= 0)
Ext2FragmentSizeInBytes = 1024 >> -(Ext2SuperBlock->s_log_frag_size);
}
Ext2FragmentSizeInSectors = Ext2FragmentSizeInBytes / Ext2DiskGeometry.BytesPerSector;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2FragmentSizeInBytes: %d\n", Ext2FragmentSizeInBytes));
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2FragmentSizeInSectors: %d\n", Ext2FragmentSizeInSectors));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2FragmentSizeInBytes: %d\n", Ext2FragmentSizeInBytes);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2FragmentSizeInSectors: %d\n", Ext2FragmentSizeInSectors);
// Verify that the fragment size and the block size are equal
if (Ext2BlockSizeInBytes != Ext2FragmentSizeInBytes)
// Calculate the number of inodes in one block
Ext2InodesPerBlock = Ext2BlockSizeInBytes / EXT3_INODE_SIZE(Ext2SuperBlock);
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2InodesPerBlock: %d\n", Ext2InodesPerBlock));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2InodesPerBlock: %d\n", Ext2InodesPerBlock);
// Calculate the number of group descriptors in one block
Ext2GroupDescPerBlock = EXT3_DESC_PER_BLOCK(Ext2SuperBlock);
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2GroupDescPerBlock: %d\n", Ext2GroupDescPerBlock));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2GroupDescPerBlock: %d\n", Ext2GroupDescPerBlock);
return TRUE;
}
ULONG GroupDescBlockCount;
ULONG CurrentGroupDescBlock;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadGroupDescriptors()\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadGroupDescriptors()\n");
//
// Free any memory previously allocated
{
EXT2_FILE_INFO DirectoryFileInfo;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadDirectory() Inode = %d\n", Inode));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadDirectory() Inode = %d\n", Inode);
// Read the directory inode
if (!Ext2ReadInode(Inode, InodePointer))
{
CHAR ErrorString[80];
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadBlock() BlockNumber = %d Buffer = 0x%x\n", BlockNumber, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadBlock() BlockNumber = %d Buffer = 0x%x\n", BlockNumber, Buffer);
// Make sure its a valid block
if (BlockNumber > Ext2SuperBlock->s_blocks_count)
// Check to see if this is a sparse block
if (BlockNumber == 0)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Block is part of a sparse file. Zeroing input buffer.\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Block is part of a sparse file. Zeroing input buffer.\n");
RtlZeroMemory(Buffer, Ext2BlockSizeInBytes);
BOOLEAN Ext2ReadPartialBlock(ULONG BlockNumber, ULONG StartingOffset, ULONG Length, PVOID Buffer)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadPartialBlock() BlockNumber = %d StartingOffset = %d Length = %d Buffer = 0x%x\n", BlockNumber, StartingOffset, Length, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadPartialBlock() BlockNumber = %d StartingOffset = %d Length = %d Buffer = 0x%x\n", BlockNumber, StartingOffset, Length, Buffer);
if (!Ext2ReadBlock(BlockNumber, (PVOID)FILESYSBUFFER))
{
CHAR ErrorString[80];
EXT2_GROUP_DESC GroupDescriptor;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadInode() Inode = %d\n", Inode));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadInode() Inode = %d\n", Inode);
// Make sure its a valid inode
if ((Inode < 1) || (Inode > Ext2SuperBlock->s_inodes_count))
InodeGroupNumber = Ext2GetInodeGroupNumber(Inode);
InodeBlockNumber = Ext2GetInodeBlockNumber(Inode);
InodeOffsetInBlock = Ext2GetInodeOffsetInBlock(Inode);
----- DbgPrint((DPRINT_FILESYSTEM, "InodeGroupNumber = %d\n", InodeGroupNumber));
----- DbgPrint((DPRINT_FILESYSTEM, "InodeBlockNumber = %d\n", InodeBlockNumber));
----- DbgPrint((DPRINT_FILESYSTEM, "InodeOffsetInBlock = %d\n", InodeOffsetInBlock));
+++++ DPRINTM(DPRINT_FILESYSTEM, "InodeGroupNumber = %d\n", InodeGroupNumber);
+++++ DPRINTM(DPRINT_FILESYSTEM, "InodeBlockNumber = %d\n", InodeBlockNumber);
+++++ DPRINTM(DPRINT_FILESYSTEM, "InodeOffsetInBlock = %d\n", InodeOffsetInBlock);
// Read the group descriptor
if (!Ext2ReadGroupDescriptor(InodeGroupNumber, &GroupDescriptor))
// Add the start block of the inode table to the inode block number
InodeBlockNumber += GroupDescriptor.bg_inode_table;
----- DbgPrint((DPRINT_FILESYSTEM, "InodeBlockNumber (after group desc correction) = %d\n", InodeBlockNumber));
+++++ DPRINTM(DPRINT_FILESYSTEM, "InodeBlockNumber (after group desc correction) = %d\n", InodeBlockNumber);
// Read the block
if (!Ext2ReadBlock(InodeBlockNumber, (PVOID)FILESYSBUFFER))
// Copy the data to their buffer
RtlCopyMemory(InodeBuffer, (PVOID)(ULONG_PTR)(FILESYSBUFFER + (InodeOffsetInBlock * EXT3_INODE_SIZE(Ext2SuperBlock))), sizeof(EXT2_INODE));
----- DbgPrint((DPRINT_FILESYSTEM, "Dumping inode information:\n"));
----- DbgPrint((DPRINT_FILESYSTEM, "i_mode = 0x%x\n", InodeBuffer->i_mode));
----- DbgPrint((DPRINT_FILESYSTEM, "i_uid = %d\n", InodeBuffer->i_uid));
----- DbgPrint((DPRINT_FILESYSTEM, "i_size = %d\n", InodeBuffer->i_size));
----- DbgPrint((DPRINT_FILESYSTEM, "i_atime = %d\n", InodeBuffer->i_atime));
----- DbgPrint((DPRINT_FILESYSTEM, "i_ctime = %d\n", InodeBuffer->i_ctime));
----- DbgPrint((DPRINT_FILESYSTEM, "i_mtime = %d\n", InodeBuffer->i_mtime));
----- DbgPrint((DPRINT_FILESYSTEM, "i_dtime = %d\n", InodeBuffer->i_dtime));
----- DbgPrint((DPRINT_FILESYSTEM, "i_gid = %d\n", InodeBuffer->i_gid));
----- DbgPrint((DPRINT_FILESYSTEM, "i_links_count = %d\n", InodeBuffer->i_links_count));
----- DbgPrint((DPRINT_FILESYSTEM, "i_blocks = %d\n", InodeBuffer->i_blocks));
----- DbgPrint((DPRINT_FILESYSTEM, "i_flags = 0x%x\n", InodeBuffer->i_flags));
----- DbgPrint((DPRINT_FILESYSTEM, "i_block[EXT3_N_BLOCKS (%d)] =\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d\n", EXT3_N_BLOCKS, InodeBuffer->i_block[0], InodeBuffer->i_block[1], InodeBuffer->i_block[2], InodeBuffer->i_block[3], InodeBuffer->i_block[4], InodeBuffer->i_block[5], InodeBuffer->i_block[6], InodeBuffer->i_block[7], InodeBuffer->i_block[8], InodeBuffer->i_block[9], InodeBuffer->i_block[10], InodeBuffer->i_block[11], InodeBuffer->i_block[12], InodeBuffer->i_block[13], InodeBuffer->i_block[14]));
----- DbgPrint((DPRINT_FILESYSTEM, "i_generation = %d\n", InodeBuffer->i_generation));
----- DbgPrint((DPRINT_FILESYSTEM, "i_file_acl = %d\n", InodeBuffer->i_file_acl));
----- DbgPrint((DPRINT_FILESYSTEM, "i_dir_acl = %d\n", InodeBuffer->i_dir_acl));
----- DbgPrint((DPRINT_FILESYSTEM, "i_faddr = %d\n", InodeBuffer->i_faddr));
----- DbgPrint((DPRINT_FILESYSTEM, "l_i_frag = %d\n", InodeBuffer->osd2.linux2.l_i_frag));
----- DbgPrint((DPRINT_FILESYSTEM, "l_i_fsize = %d\n", InodeBuffer->osd2.linux2.l_i_fsize));
----- DbgPrint((DPRINT_FILESYSTEM, "l_i_uid_high = %d\n", InodeBuffer->osd2.linux2.l_i_uid_high));
----- DbgPrint((DPRINT_FILESYSTEM, "l_i_gid_high = %d\n", InodeBuffer->osd2.linux2.l_i_gid_high));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Dumping inode information:\n");
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_mode = 0x%x\n", InodeBuffer->i_mode);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_uid = %d\n", InodeBuffer->i_uid);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_size = %d\n", InodeBuffer->i_size);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_atime = %d\n", InodeBuffer->i_atime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_ctime = %d\n", InodeBuffer->i_ctime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_mtime = %d\n", InodeBuffer->i_mtime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_dtime = %d\n", InodeBuffer->i_dtime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_gid = %d\n", InodeBuffer->i_gid);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_links_count = %d\n", InodeBuffer->i_links_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_blocks = %d\n", InodeBuffer->i_blocks);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_flags = 0x%x\n", InodeBuffer->i_flags);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_block[EXT3_N_BLOCKS (%d)] =\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d,\n%d\n", EXT3_N_BLOCKS, InodeBuffer->i_block[0], InodeBuffer->i_block[1], InodeBuffer->i_block[2], InodeBuffer->i_block[3], InodeBuffer->i_block[4], InodeBuffer->i_block[5], InodeBuffer->i_block[6], InodeBuffer->i_block[7], InodeBuffer->i_block[8], InodeBuffer->i_block[9], InodeBuffer->i_block[10], InodeBuffer->i_block[11], InodeBuffer->i_block[12], InodeBuffer->i_block[13], InodeBuffer->i_block[14]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_generation = %d\n", InodeBuffer->i_generation);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_file_acl = %d\n", InodeBuffer->i_file_acl);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_dir_acl = %d\n", InodeBuffer->i_dir_acl);
+++++ DPRINTM(DPRINT_FILESYSTEM, "i_faddr = %d\n", InodeBuffer->i_faddr);
+++++ DPRINTM(DPRINT_FILESYSTEM, "l_i_frag = %d\n", InodeBuffer->osd2.linux2.l_i_frag);
+++++ DPRINTM(DPRINT_FILESYSTEM, "l_i_fsize = %d\n", InodeBuffer->osd2.linux2.l_i_fsize);
+++++ DPRINTM(DPRINT_FILESYSTEM, "l_i_uid_high = %d\n", InodeBuffer->osd2.linux2.l_i_uid_high);
+++++ DPRINTM(DPRINT_FILESYSTEM, "l_i_gid_high = %d\n", InodeBuffer->osd2.linux2.l_i_gid_high);
return TRUE;
}
BOOLEAN Ext2ReadGroupDescriptor(ULONG Group, PEXT2_GROUP_DESC GroupBuffer)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadGroupDescriptor()\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadGroupDescriptor()\n");
/*if (!Ext2ReadBlock(Ext2GetGroupDescBlockNumber(Group), (PVOID)FILESYSBUFFER))
{
RtlCopyMemory(GroupBuffer, &Ext2GroupDescriptors[Group], sizeof(EXT2_GROUP_DESC));
----- DbgPrint((DPRINT_FILESYSTEM, "Dumping group descriptor:\n"));
----- DbgPrint((DPRINT_FILESYSTEM, "bg_block_bitmap = %d\n", GroupBuffer->bg_block_bitmap));
----- DbgPrint((DPRINT_FILESYSTEM, "bg_inode_bitmap = %d\n", GroupBuffer->bg_inode_bitmap));
----- DbgPrint((DPRINT_FILESYSTEM, "bg_inode_table = %d\n", GroupBuffer->bg_inode_table));
----- DbgPrint((DPRINT_FILESYSTEM, "bg_free_blocks_count = %d\n", GroupBuffer->bg_free_blocks_count));
----- DbgPrint((DPRINT_FILESYSTEM, "bg_free_inodes_count = %d\n", GroupBuffer->bg_free_inodes_count));
----- DbgPrint((DPRINT_FILESYSTEM, "bg_used_dirs_count = %d\n", GroupBuffer->bg_used_dirs_count));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Dumping group descriptor:\n");
+++++ DPRINTM(DPRINT_FILESYSTEM, "bg_block_bitmap = %d\n", GroupBuffer->bg_block_bitmap);
+++++ DPRINTM(DPRINT_FILESYSTEM, "bg_inode_bitmap = %d\n", GroupBuffer->bg_inode_bitmap);
+++++ DPRINTM(DPRINT_FILESYSTEM, "bg_inode_table = %d\n", GroupBuffer->bg_inode_table);
+++++ DPRINTM(DPRINT_FILESYSTEM, "bg_free_blocks_count = %d\n", GroupBuffer->bg_free_blocks_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "bg_free_inodes_count = %d\n", GroupBuffer->bg_free_inodes_count);
+++++ DPRINTM(DPRINT_FILESYSTEM, "bg_used_dirs_count = %d\n", GroupBuffer->bg_used_dirs_count);
return TRUE;
}
ULONG CurrentBlockInList;
ULONG CurrentBlock;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2ReadBlockPointerList()\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2ReadBlockPointerList()\n");
// Get the number of blocks this file occupies
// I would just use Inode->i_blocks but it
ULONG CurrentBlock;
ULONG BlockPointersPerBlock;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2CopyIndirectBlockPointers() BlockCount = %d\n", BlockCount));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2CopyIndirectBlockPointers() BlockCount = %d\n", BlockCount);
BlockPointersPerBlock = Ext2BlockSizeInBytes / sizeof(ULONG);
ULONG CurrentBlock;
ULONG BlockPointersPerBlock;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2CopyDoubleIndirectBlockPointers() BlockCount = %d\n", BlockCount));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2CopyDoubleIndirectBlockPointers() BlockCount = %d\n", BlockCount);
BlockPointersPerBlock = Ext2BlockSizeInBytes / sizeof(ULONG);
ULONG CurrentBlock;
ULONG BlockPointersPerBlock;
----- DbgPrint((DPRINT_FILESYSTEM, "Ext2CopyTripleIndirectBlockPointers() BlockCount = %d\n", BlockCount));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Ext2CopyTripleIndirectBlockPointers() BlockCount = %d\n", BlockCount);
BlockPointersPerBlock = Ext2BlockSizeInBytes / sizeof(ULONG);
PFAT32_BOOTSECTOR Fat32VolumeBootSector;
PFATX_BOOTSECTOR FatXVolumeBootSector;
----- DbgPrint((DPRINT_FILESYSTEM, "FatOpenVolume() DriveNumber = 0x%x VolumeStartSector = %d\n", DriveNumber, VolumeStartSector));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatOpenVolume() DriveNumber = 0x%x VolumeStartSector = %d\n", DriveNumber, VolumeStartSector);
// Store the drive number
FatDriveNumber = DriveNumber;
FatType = FatDetermineFatType(FatVolumeBootSector, PartitionSectorCount);
// Dump boot sector (and swap it for big endian systems)
----- DbgPrint((DPRINT_FILESYSTEM, "Dumping boot sector:\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Dumping boot sector:\n");
if (ISFATX(FatType))
{
FatSwapFatXBootSector(FatXVolumeBootSector);
----- DbgPrint((DPRINT_FILESYSTEM, "sizeof(FATX_BOOTSECTOR) = 0x%x.\n", sizeof(FATX_BOOTSECTOR)));
+++++ DPRINTM(DPRINT_FILESYSTEM, "sizeof(FATX_BOOTSECTOR) = 0x%x.\n", sizeof(FATX_BOOTSECTOR));
----- DbgPrint((DPRINT_FILESYSTEM, "FileSystemType: %c%c%c%c.\n", FatXVolumeBootSector->FileSystemType[0], FatXVolumeBootSector->FileSystemType[1], FatXVolumeBootSector->FileSystemType[2], FatXVolumeBootSector->FileSystemType[3]));
----- DbgPrint((DPRINT_FILESYSTEM, "VolumeSerialNumber: 0x%x\n", FatXVolumeBootSector->VolumeSerialNumber));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerCluster: %d\n", FatXVolumeBootSector->SectorsPerCluster));
----- DbgPrint((DPRINT_FILESYSTEM, "NumberOfFats: %d\n", FatXVolumeBootSector->NumberOfFats));
----- DbgPrint((DPRINT_FILESYSTEM, "Unknown: 0x%x\n", FatXVolumeBootSector->Unknown));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FileSystemType: %c%c%c%c.\n", FatXVolumeBootSector->FileSystemType[0], FatXVolumeBootSector->FileSystemType[1], FatXVolumeBootSector->FileSystemType[2], FatXVolumeBootSector->FileSystemType[3]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "VolumeSerialNumber: 0x%x\n", FatXVolumeBootSector->VolumeSerialNumber);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerCluster: %d\n", FatXVolumeBootSector->SectorsPerCluster);
+++++ DPRINTM(DPRINT_FILESYSTEM, "NumberOfFats: %d\n", FatXVolumeBootSector->NumberOfFats);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Unknown: 0x%x\n", FatXVolumeBootSector->Unknown);
----- DbgPrint((DPRINT_FILESYSTEM, "FatType %s\n", FatType == FATX16 ? "FATX16" : "FATX32"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatType %s\n", FatType == FATX16 ? "FATX16" : "FATX32");
}
else if (FatType == FAT32)
{
FatSwapFat32BootSector(Fat32VolumeBootSector);
----- DbgPrint((DPRINT_FILESYSTEM, "sizeof(FAT32_BOOTSECTOR) = 0x%x.\n", sizeof(FAT32_BOOTSECTOR)));
-----
----- DbgPrint((DPRINT_FILESYSTEM, "JumpBoot: 0x%x 0x%x 0x%x\n", Fat32VolumeBootSector->JumpBoot[0], Fat32VolumeBootSector->JumpBoot[1], Fat32VolumeBootSector->JumpBoot[2]));
----- DbgPrint((DPRINT_FILESYSTEM, "OemName: %c%c%c%c%c%c%c%c\n", Fat32VolumeBootSector->OemName[0], Fat32VolumeBootSector->OemName[1], Fat32VolumeBootSector->OemName[2], Fat32VolumeBootSector->OemName[3], Fat32VolumeBootSector->OemName[4], Fat32VolumeBootSector->OemName[5], Fat32VolumeBootSector->OemName[6], Fat32VolumeBootSector->OemName[7]));
----- DbgPrint((DPRINT_FILESYSTEM, "BytesPerSector: %d\n", Fat32VolumeBootSector->BytesPerSector));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerCluster: %d\n", Fat32VolumeBootSector->SectorsPerCluster));
----- DbgPrint((DPRINT_FILESYSTEM, "ReservedSectors: %d\n", Fat32VolumeBootSector->ReservedSectors));
----- DbgPrint((DPRINT_FILESYSTEM, "NumberOfFats: %d\n", Fat32VolumeBootSector->NumberOfFats));
----- DbgPrint((DPRINT_FILESYSTEM, "RootDirEntries: %d\n", Fat32VolumeBootSector->RootDirEntries));
----- DbgPrint((DPRINT_FILESYSTEM, "TotalSectors: %d\n", Fat32VolumeBootSector->TotalSectors));
----- DbgPrint((DPRINT_FILESYSTEM, "MediaDescriptor: 0x%x\n", Fat32VolumeBootSector->MediaDescriptor));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerFat: %d\n", Fat32VolumeBootSector->SectorsPerFat));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerTrack: %d\n", Fat32VolumeBootSector->SectorsPerTrack));
----- DbgPrint((DPRINT_FILESYSTEM, "NumberOfHeads: %d\n", Fat32VolumeBootSector->NumberOfHeads));
----- DbgPrint((DPRINT_FILESYSTEM, "HiddenSectors: %d\n", Fat32VolumeBootSector->HiddenSectors));
----- DbgPrint((DPRINT_FILESYSTEM, "TotalSectorsBig: %d\n", Fat32VolumeBootSector->TotalSectorsBig));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerFatBig: %d\n", Fat32VolumeBootSector->SectorsPerFatBig));
----- DbgPrint((DPRINT_FILESYSTEM, "ExtendedFlags: 0x%x\n", Fat32VolumeBootSector->ExtendedFlags));
----- DbgPrint((DPRINT_FILESYSTEM, "FileSystemVersion: 0x%x\n", Fat32VolumeBootSector->FileSystemVersion));
----- DbgPrint((DPRINT_FILESYSTEM, "RootDirStartCluster: %d\n", Fat32VolumeBootSector->RootDirStartCluster));
----- DbgPrint((DPRINT_FILESYSTEM, "FsInfo: %d\n", Fat32VolumeBootSector->FsInfo));
----- DbgPrint((DPRINT_FILESYSTEM, "BackupBootSector: %d\n", Fat32VolumeBootSector->BackupBootSector));
----- DbgPrint((DPRINT_FILESYSTEM, "Reserved: 0x%x\n", Fat32VolumeBootSector->Reserved));
----- DbgPrint((DPRINT_FILESYSTEM, "DriveNumber: 0x%x\n", Fat32VolumeBootSector->DriveNumber));
----- DbgPrint((DPRINT_FILESYSTEM, "Reserved1: 0x%x\n", Fat32VolumeBootSector->Reserved1));
----- DbgPrint((DPRINT_FILESYSTEM, "BootSignature: 0x%x\n", Fat32VolumeBootSector->BootSignature));
----- DbgPrint((DPRINT_FILESYSTEM, "VolumeSerialNumber: 0x%x\n", Fat32VolumeBootSector->VolumeSerialNumber));
----- DbgPrint((DPRINT_FILESYSTEM, "VolumeLabel: %c%c%c%c%c%c%c%c%c%c%c\n", Fat32VolumeBootSector->VolumeLabel[0], Fat32VolumeBootSector->VolumeLabel[1], Fat32VolumeBootSector->VolumeLabel[2], Fat32VolumeBootSector->VolumeLabel[3], Fat32VolumeBootSector->VolumeLabel[4], Fat32VolumeBootSector->VolumeLabel[5], Fat32VolumeBootSector->VolumeLabel[6], Fat32VolumeBootSector->VolumeLabel[7], Fat32VolumeBootSector->VolumeLabel[8], Fat32VolumeBootSector->VolumeLabel[9], Fat32VolumeBootSector->VolumeLabel[10]));
----- DbgPrint((DPRINT_FILESYSTEM, "FileSystemType: %c%c%c%c%c%c%c%c\n", Fat32VolumeBootSector->FileSystemType[0], Fat32VolumeBootSector->FileSystemType[1], Fat32VolumeBootSector->FileSystemType[2], Fat32VolumeBootSector->FileSystemType[3], Fat32VolumeBootSector->FileSystemType[4], Fat32VolumeBootSector->FileSystemType[5], Fat32VolumeBootSector->FileSystemType[6], Fat32VolumeBootSector->FileSystemType[7]));
----- DbgPrint((DPRINT_FILESYSTEM, "BootSectorMagic: 0x%x\n", Fat32VolumeBootSector->BootSectorMagic));
+++++ DPRINTM(DPRINT_FILESYSTEM, "sizeof(FAT32_BOOTSECTOR) = 0x%x.\n", sizeof(FAT32_BOOTSECTOR));
+++++
+++++ DPRINTM(DPRINT_FILESYSTEM, "JumpBoot: 0x%x 0x%x 0x%x\n", Fat32VolumeBootSector->JumpBoot[0], Fat32VolumeBootSector->JumpBoot[1], Fat32VolumeBootSector->JumpBoot[2]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "OemName: %c%c%c%c%c%c%c%c\n", Fat32VolumeBootSector->OemName[0], Fat32VolumeBootSector->OemName[1], Fat32VolumeBootSector->OemName[2], Fat32VolumeBootSector->OemName[3], Fat32VolumeBootSector->OemName[4], Fat32VolumeBootSector->OemName[5], Fat32VolumeBootSector->OemName[6], Fat32VolumeBootSector->OemName[7]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "BytesPerSector: %d\n", Fat32VolumeBootSector->BytesPerSector);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerCluster: %d\n", Fat32VolumeBootSector->SectorsPerCluster);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ReservedSectors: %d\n", Fat32VolumeBootSector->ReservedSectors);
+++++ DPRINTM(DPRINT_FILESYSTEM, "NumberOfFats: %d\n", Fat32VolumeBootSector->NumberOfFats);
+++++ DPRINTM(DPRINT_FILESYSTEM, "RootDirEntries: %d\n", Fat32VolumeBootSector->RootDirEntries);
+++++ DPRINTM(DPRINT_FILESYSTEM, "TotalSectors: %d\n", Fat32VolumeBootSector->TotalSectors);
+++++ DPRINTM(DPRINT_FILESYSTEM, "MediaDescriptor: 0x%x\n", Fat32VolumeBootSector->MediaDescriptor);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerFat: %d\n", Fat32VolumeBootSector->SectorsPerFat);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerTrack: %d\n", Fat32VolumeBootSector->SectorsPerTrack);
+++++ DPRINTM(DPRINT_FILESYSTEM, "NumberOfHeads: %d\n", Fat32VolumeBootSector->NumberOfHeads);
+++++ DPRINTM(DPRINT_FILESYSTEM, "HiddenSectors: %d\n", Fat32VolumeBootSector->HiddenSectors);
+++++ DPRINTM(DPRINT_FILESYSTEM, "TotalSectorsBig: %d\n", Fat32VolumeBootSector->TotalSectorsBig);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerFatBig: %d\n", Fat32VolumeBootSector->SectorsPerFatBig);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ExtendedFlags: 0x%x\n", Fat32VolumeBootSector->ExtendedFlags);
+++++ DPRINTM(DPRINT_FILESYSTEM, "FileSystemVersion: 0x%x\n", Fat32VolumeBootSector->FileSystemVersion);
+++++ DPRINTM(DPRINT_FILESYSTEM, "RootDirStartCluster: %d\n", Fat32VolumeBootSector->RootDirStartCluster);
+++++ DPRINTM(DPRINT_FILESYSTEM, "FsInfo: %d\n", Fat32VolumeBootSector->FsInfo);
+++++ DPRINTM(DPRINT_FILESYSTEM, "BackupBootSector: %d\n", Fat32VolumeBootSector->BackupBootSector);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Reserved: 0x%x\n", Fat32VolumeBootSector->Reserved);
+++++ DPRINTM(DPRINT_FILESYSTEM, "DriveNumber: 0x%x\n", Fat32VolumeBootSector->DriveNumber);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Reserved1: 0x%x\n", Fat32VolumeBootSector->Reserved1);
+++++ DPRINTM(DPRINT_FILESYSTEM, "BootSignature: 0x%x\n", Fat32VolumeBootSector->BootSignature);
+++++ DPRINTM(DPRINT_FILESYSTEM, "VolumeSerialNumber: 0x%x\n", Fat32VolumeBootSector->VolumeSerialNumber);
+++++ DPRINTM(DPRINT_FILESYSTEM, "VolumeLabel: %c%c%c%c%c%c%c%c%c%c%c\n", Fat32VolumeBootSector->VolumeLabel[0], Fat32VolumeBootSector->VolumeLabel[1], Fat32VolumeBootSector->VolumeLabel[2], Fat32VolumeBootSector->VolumeLabel[3], Fat32VolumeBootSector->VolumeLabel[4], Fat32VolumeBootSector->VolumeLabel[5], Fat32VolumeBootSector->VolumeLabel[6], Fat32VolumeBootSector->VolumeLabel[7], Fat32VolumeBootSector->VolumeLabel[8], Fat32VolumeBootSector->VolumeLabel[9], Fat32VolumeBootSector->VolumeLabel[10]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "FileSystemType: %c%c%c%c%c%c%c%c\n", Fat32VolumeBootSector->FileSystemType[0], Fat32VolumeBootSector->FileSystemType[1], Fat32VolumeBootSector->FileSystemType[2], Fat32VolumeBootSector->FileSystemType[3], Fat32VolumeBootSector->FileSystemType[4], Fat32VolumeBootSector->FileSystemType[5], Fat32VolumeBootSector->FileSystemType[6], Fat32VolumeBootSector->FileSystemType[7]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "BootSectorMagic: 0x%x\n", Fat32VolumeBootSector->BootSectorMagic);
}
else
{
FatSwapFatBootSector(FatVolumeBootSector);
----- DbgPrint((DPRINT_FILESYSTEM, "sizeof(FAT_BOOTSECTOR) = 0x%x.\n", sizeof(FAT_BOOTSECTOR)));
-----
----- DbgPrint((DPRINT_FILESYSTEM, "JumpBoot: 0x%x 0x%x 0x%x\n", FatVolumeBootSector->JumpBoot[0], FatVolumeBootSector->JumpBoot[1], FatVolumeBootSector->JumpBoot[2]));
----- DbgPrint((DPRINT_FILESYSTEM, "OemName: %c%c%c%c%c%c%c%c\n", FatVolumeBootSector->OemName[0], FatVolumeBootSector->OemName[1], FatVolumeBootSector->OemName[2], FatVolumeBootSector->OemName[3], FatVolumeBootSector->OemName[4], FatVolumeBootSector->OemName[5], FatVolumeBootSector->OemName[6], FatVolumeBootSector->OemName[7]));
----- DbgPrint((DPRINT_FILESYSTEM, "BytesPerSector: %d\n", FatVolumeBootSector->BytesPerSector));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerCluster: %d\n", FatVolumeBootSector->SectorsPerCluster));
----- DbgPrint((DPRINT_FILESYSTEM, "ReservedSectors: %d\n", FatVolumeBootSector->ReservedSectors));
----- DbgPrint((DPRINT_FILESYSTEM, "NumberOfFats: %d\n", FatVolumeBootSector->NumberOfFats));
----- DbgPrint((DPRINT_FILESYSTEM, "RootDirEntries: %d\n", FatVolumeBootSector->RootDirEntries));
----- DbgPrint((DPRINT_FILESYSTEM, "TotalSectors: %d\n", FatVolumeBootSector->TotalSectors));
----- DbgPrint((DPRINT_FILESYSTEM, "MediaDescriptor: 0x%x\n", FatVolumeBootSector->MediaDescriptor));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerFat: %d\n", FatVolumeBootSector->SectorsPerFat));
----- DbgPrint((DPRINT_FILESYSTEM, "SectorsPerTrack: %d\n", FatVolumeBootSector->SectorsPerTrack));
----- DbgPrint((DPRINT_FILESYSTEM, "NumberOfHeads: %d\n", FatVolumeBootSector->NumberOfHeads));
----- DbgPrint((DPRINT_FILESYSTEM, "HiddenSectors: %d\n", FatVolumeBootSector->HiddenSectors));
----- DbgPrint((DPRINT_FILESYSTEM, "TotalSectorsBig: %d\n", FatVolumeBootSector->TotalSectorsBig));
----- DbgPrint((DPRINT_FILESYSTEM, "DriveNumber: 0x%x\n", FatVolumeBootSector->DriveNumber));
----- DbgPrint((DPRINT_FILESYSTEM, "Reserved1: 0x%x\n", FatVolumeBootSector->Reserved1));
----- DbgPrint((DPRINT_FILESYSTEM, "BootSignature: 0x%x\n", FatVolumeBootSector->BootSignature));
----- DbgPrint((DPRINT_FILESYSTEM, "VolumeSerialNumber: 0x%x\n", FatVolumeBootSector->VolumeSerialNumber));
----- DbgPrint((DPRINT_FILESYSTEM, "VolumeLabel: %c%c%c%c%c%c%c%c%c%c%c\n", FatVolumeBootSector->VolumeLabel[0], FatVolumeBootSector->VolumeLabel[1], FatVolumeBootSector->VolumeLabel[2], FatVolumeBootSector->VolumeLabel[3], FatVolumeBootSector->VolumeLabel[4], FatVolumeBootSector->VolumeLabel[5], FatVolumeBootSector->VolumeLabel[6], FatVolumeBootSector->VolumeLabel[7], FatVolumeBootSector->VolumeLabel[8], FatVolumeBootSector->VolumeLabel[9], FatVolumeBootSector->VolumeLabel[10]));
----- DbgPrint((DPRINT_FILESYSTEM, "FileSystemType: %c%c%c%c%c%c%c%c\n", FatVolumeBootSector->FileSystemType[0], FatVolumeBootSector->FileSystemType[1], FatVolumeBootSector->FileSystemType[2], FatVolumeBootSector->FileSystemType[3], FatVolumeBootSector->FileSystemType[4], FatVolumeBootSector->FileSystemType[5], FatVolumeBootSector->FileSystemType[6], FatVolumeBootSector->FileSystemType[7]));
----- DbgPrint((DPRINT_FILESYSTEM, "BootSectorMagic: 0x%x\n", FatVolumeBootSector->BootSectorMagic));
+++++ DPRINTM(DPRINT_FILESYSTEM, "sizeof(FAT_BOOTSECTOR) = 0x%x.\n", sizeof(FAT_BOOTSECTOR));
+++++
+++++ DPRINTM(DPRINT_FILESYSTEM, "JumpBoot: 0x%x 0x%x 0x%x\n", FatVolumeBootSector->JumpBoot[0], FatVolumeBootSector->JumpBoot[1], FatVolumeBootSector->JumpBoot[2]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "OemName: %c%c%c%c%c%c%c%c\n", FatVolumeBootSector->OemName[0], FatVolumeBootSector->OemName[1], FatVolumeBootSector->OemName[2], FatVolumeBootSector->OemName[3], FatVolumeBootSector->OemName[4], FatVolumeBootSector->OemName[5], FatVolumeBootSector->OemName[6], FatVolumeBootSector->OemName[7]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "BytesPerSector: %d\n", FatVolumeBootSector->BytesPerSector);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerCluster: %d\n", FatVolumeBootSector->SectorsPerCluster);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ReservedSectors: %d\n", FatVolumeBootSector->ReservedSectors);
+++++ DPRINTM(DPRINT_FILESYSTEM, "NumberOfFats: %d\n", FatVolumeBootSector->NumberOfFats);
+++++ DPRINTM(DPRINT_FILESYSTEM, "RootDirEntries: %d\n", FatVolumeBootSector->RootDirEntries);
+++++ DPRINTM(DPRINT_FILESYSTEM, "TotalSectors: %d\n", FatVolumeBootSector->TotalSectors);
+++++ DPRINTM(DPRINT_FILESYSTEM, "MediaDescriptor: 0x%x\n", FatVolumeBootSector->MediaDescriptor);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerFat: %d\n", FatVolumeBootSector->SectorsPerFat);
+++++ DPRINTM(DPRINT_FILESYSTEM, "SectorsPerTrack: %d\n", FatVolumeBootSector->SectorsPerTrack);
+++++ DPRINTM(DPRINT_FILESYSTEM, "NumberOfHeads: %d\n", FatVolumeBootSector->NumberOfHeads);
+++++ DPRINTM(DPRINT_FILESYSTEM, "HiddenSectors: %d\n", FatVolumeBootSector->HiddenSectors);
+++++ DPRINTM(DPRINT_FILESYSTEM, "TotalSectorsBig: %d\n", FatVolumeBootSector->TotalSectorsBig);
+++++ DPRINTM(DPRINT_FILESYSTEM, "DriveNumber: 0x%x\n", FatVolumeBootSector->DriveNumber);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Reserved1: 0x%x\n", FatVolumeBootSector->Reserved1);
+++++ DPRINTM(DPRINT_FILESYSTEM, "BootSignature: 0x%x\n", FatVolumeBootSector->BootSignature);
+++++ DPRINTM(DPRINT_FILESYSTEM, "VolumeSerialNumber: 0x%x\n", FatVolumeBootSector->VolumeSerialNumber);
+++++ DPRINTM(DPRINT_FILESYSTEM, "VolumeLabel: %c%c%c%c%c%c%c%c%c%c%c\n", FatVolumeBootSector->VolumeLabel[0], FatVolumeBootSector->VolumeLabel[1], FatVolumeBootSector->VolumeLabel[2], FatVolumeBootSector->VolumeLabel[3], FatVolumeBootSector->VolumeLabel[4], FatVolumeBootSector->VolumeLabel[5], FatVolumeBootSector->VolumeLabel[6], FatVolumeBootSector->VolumeLabel[7], FatVolumeBootSector->VolumeLabel[8], FatVolumeBootSector->VolumeLabel[9], FatVolumeBootSector->VolumeLabel[10]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "FileSystemType: %c%c%c%c%c%c%c%c\n", FatVolumeBootSector->FileSystemType[0], FatVolumeBootSector->FileSystemType[1], FatVolumeBootSector->FileSystemType[2], FatVolumeBootSector->FileSystemType[3], FatVolumeBootSector->FileSystemType[4], FatVolumeBootSector->FileSystemType[5], FatVolumeBootSector->FileSystemType[6], FatVolumeBootSector->FileSystemType[7]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "BootSectorMagic: 0x%x\n", FatVolumeBootSector->BootSectorMagic);
}
//
{
PVOID DirectoryBuffer;
----- DbgPrint((DPRINT_FILESYSTEM, "FatBufferDirectory() DirectoryStartCluster = %d RootDirectory = %s\n", DirectoryStartCluster, (RootDirectory ? "TRUE" : "FALSE")));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatBufferDirectory() DirectoryStartCluster = %d RootDirectory = %s\n", DirectoryStartCluster, (RootDirectory ? "TRUE" : "FALSE"));
/*
* For FAT32, the root directory is nothing special. We can treat it the same
//
// Attempt to allocate memory for directory buffer
//
----- DbgPrint((DPRINT_FILESYSTEM, "Trying to allocate (DirectorySize) %d bytes.\n", *DirectorySize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Trying to allocate (DirectorySize) %d bytes.\n", *DirectorySize);
DirectoryBuffer = MmHeapAlloc(*DirectorySize);
if (DirectoryBuffer == NULL)
EntryCount = DirectorySize / sizeof(DIRENTRY);
----- DbgPrint((DPRINT_FILESYSTEM, "FatSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x EntryCount = %d FileName = %s\n", DirectoryBuffer, EntryCount, FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x EntryCount = %d FileName = %s\n", DirectoryBuffer, EntryCount, FileName);
memset(ShortNameBuffer, 0, 13 * sizeof(CHAR));
memset(LfnNameBuffer, 0, 261 * sizeof(CHAR));
OurDirEntry = *((PDIRENTRY) DirectoryBuffer);
FatSwapDirEntry(DirEntry);
----- //DbgPrint((DPRINT_FILESYSTEM, "Dumping directory entry %d:\n", CurrentEntry));
+++++ //DPRINTM(DPRINT_FILESYSTEM, "Dumping directory entry %d:\n", CurrentEntry);
//DbgDumpBuffer(DPRINT_FILESYSTEM, DirEntry, sizeof(DIRENTRY));
//
LfnNameBuffer[12 + (LfnDirEntry->SequenceNumber * 13)] = (UCHAR)LfnDirEntry->Name11_12[1];
}
----- //DbgPrint((DPRINT_FILESYSTEM, "Dumping long name buffer:\n"));
+++++ //DPRINTM(DPRINT_FILESYSTEM, "Dumping long name buffer:\n");
//DbgDumpBuffer(DPRINT_FILESYSTEM, LfnNameBuffer, 260);
continue;
//
FatParseShortFileName(ShortNameBuffer, DirEntry);
----- DbgPrint((DPRINT_FILESYSTEM, "Entry: %d LFN = %s\n", CurrentEntry, LfnNameBuffer));
----- DbgPrint((DPRINT_FILESYSTEM, "Entry: %d DOS name = %s\n", CurrentEntry, ShortNameBuffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Entry: %d LFN = %s\n", CurrentEntry, LfnNameBuffer);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Entry: %d DOS name = %s\n", CurrentEntry, ShortNameBuffer);
//
// See if the file name matches either the short or long name
FatFileInfoPointer->FileSize = DirEntry->Size;
FatFileInfoPointer->FilePointer = 0;
----- DbgPrint((DPRINT_FILESYSTEM, "MSDOS Directory Entry:\n"));
----- DbgPrint((DPRINT_FILESYSTEM, "FileName[11] = %c%c%c%c%c%c%c%c%c%c%c\n", DirEntry->FileName[0], DirEntry->FileName[1], DirEntry->FileName[2], DirEntry->FileName[3], DirEntry->FileName[4], DirEntry->FileName[5], DirEntry->FileName[6], DirEntry->FileName[7], DirEntry->FileName[8], DirEntry->FileName[9], DirEntry->FileName[10]));
----- DbgPrint((DPRINT_FILESYSTEM, "Attr = 0x%x\n", DirEntry->Attr));
----- DbgPrint((DPRINT_FILESYSTEM, "ReservedNT = 0x%x\n", DirEntry->ReservedNT));
----- DbgPrint((DPRINT_FILESYSTEM, "TimeInTenths = %d\n", DirEntry->TimeInTenths));
----- DbgPrint((DPRINT_FILESYSTEM, "CreateTime = %d\n", DirEntry->CreateTime));
----- DbgPrint((DPRINT_FILESYSTEM, "CreateDate = %d\n", DirEntry->CreateDate));
----- DbgPrint((DPRINT_FILESYSTEM, "LastAccessDate = %d\n", DirEntry->LastAccessDate));
----- DbgPrint((DPRINT_FILESYSTEM, "ClusterHigh = 0x%x\n", DirEntry->ClusterHigh));
----- DbgPrint((DPRINT_FILESYSTEM, "Time = %d\n", DirEntry->Time));
----- DbgPrint((DPRINT_FILESYSTEM, "Date = %d\n", DirEntry->Date));
----- DbgPrint((DPRINT_FILESYSTEM, "ClusterLow = 0x%x\n", DirEntry->ClusterLow));
----- DbgPrint((DPRINT_FILESYSTEM, "Size = %d\n", DirEntry->Size));
+++++ DPRINTM(DPRINT_FILESYSTEM, "MSDOS Directory Entry:\n");
+++++ DPRINTM(DPRINT_FILESYSTEM, "FileName[11] = %c%c%c%c%c%c%c%c%c%c%c\n", DirEntry->FileName[0], DirEntry->FileName[1], DirEntry->FileName[2], DirEntry->FileName[3], DirEntry->FileName[4], DirEntry->FileName[5], DirEntry->FileName[6], DirEntry->FileName[7], DirEntry->FileName[8], DirEntry->FileName[9], DirEntry->FileName[10]);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Attr = 0x%x\n", DirEntry->Attr);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ReservedNT = 0x%x\n", DirEntry->ReservedNT);
+++++ DPRINTM(DPRINT_FILESYSTEM, "TimeInTenths = %d\n", DirEntry->TimeInTenths);
+++++ DPRINTM(DPRINT_FILESYSTEM, "CreateTime = %d\n", DirEntry->CreateTime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "CreateDate = %d\n", DirEntry->CreateDate);
+++++ DPRINTM(DPRINT_FILESYSTEM, "LastAccessDate = %d\n", DirEntry->LastAccessDate);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ClusterHigh = 0x%x\n", DirEntry->ClusterHigh);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Time = %d\n", DirEntry->Time);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Date = %d\n", DirEntry->Date);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ClusterLow = 0x%x\n", DirEntry->ClusterLow);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Size = %d\n", DirEntry->Size);
//
// Get the cluster chain
//
StartCluster = ((ULONG)DirEntry->ClusterHigh << 16) + DirEntry->ClusterLow;
----- DbgPrint((DPRINT_FILESYSTEM, "StartCluster = 0x%x\n", StartCluster));
+++++ DPRINTM(DPRINT_FILESYSTEM, "StartCluster = 0x%x\n", StartCluster);
FatFileInfoPointer->FileFatChain = FatGetClusterChainArray(StartCluster);
//
EntryCount = DirectorySize / sizeof(FATX_DIRENTRY);
----- DbgPrint((DPRINT_FILESYSTEM, "FatXSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x EntryCount = %d FileName = %s\n", DirectoryBuffer, EntryCount, FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatXSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x EntryCount = %d FileName = %s\n", DirectoryBuffer, EntryCount, FileName);
FileNameLen = strlen(FileName);
FatFileInfoPointer->FileSize = DirEntry->Size;
FatFileInfoPointer->FilePointer = 0;
----- DbgPrint((DPRINT_FILESYSTEM, "FATX Directory Entry:\n"));
----- DbgPrint((DPRINT_FILESYSTEM, "FileNameSize = %d\n", DirEntry->FileNameSize));
----- DbgPrint((DPRINT_FILESYSTEM, "Attr = 0x%x\n", DirEntry->Attr));
----- DbgPrint((DPRINT_FILESYSTEM, "StartCluster = 0x%x\n", DirEntry->StartCluster));
----- DbgPrint((DPRINT_FILESYSTEM, "Size = %d\n", DirEntry->Size));
----- DbgPrint((DPRINT_FILESYSTEM, "Time = %d\n", DirEntry->Time));
----- DbgPrint((DPRINT_FILESYSTEM, "Date = %d\n", DirEntry->Date));
----- DbgPrint((DPRINT_FILESYSTEM, "CreateTime = %d\n", DirEntry->CreateTime));
----- DbgPrint((DPRINT_FILESYSTEM, "CreateDate = %d\n", DirEntry->CreateDate));
----- DbgPrint((DPRINT_FILESYSTEM, "LastAccessTime = %d\n", DirEntry->LastAccessTime));
----- DbgPrint((DPRINT_FILESYSTEM, "LastAccessDate = %d\n", DirEntry->LastAccessDate));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FATX Directory Entry:\n");
+++++ DPRINTM(DPRINT_FILESYSTEM, "FileNameSize = %d\n", DirEntry->FileNameSize);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Attr = 0x%x\n", DirEntry->Attr);
+++++ DPRINTM(DPRINT_FILESYSTEM, "StartCluster = 0x%x\n", DirEntry->StartCluster);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Size = %d\n", DirEntry->Size);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Time = %d\n", DirEntry->Time);
+++++ DPRINTM(DPRINT_FILESYSTEM, "Date = %d\n", DirEntry->Date);
+++++ DPRINTM(DPRINT_FILESYSTEM, "CreateTime = %d\n", DirEntry->CreateTime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "CreateDate = %d\n", DirEntry->CreateDate);
+++++ DPRINTM(DPRINT_FILESYSTEM, "LastAccessTime = %d\n", DirEntry->LastAccessTime);
+++++ DPRINTM(DPRINT_FILESYSTEM, "LastAccessDate = %d\n", DirEntry->LastAccessDate);
/*
* Get the cluster chain
ULONG DirectorySize;
FAT_FILE_INFO FatFileInfo;
----- DbgPrint((DPRINT_FILESYSTEM, "FatLookupFile() FileName = %s\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatLookupFile() FileName = %s\n", FileName);
memset(FatFileInfoPointer, 0, sizeof(FAT_FILE_INFO));
Buffer[Idx++] = (DirEntry->FileName[10] == ' ') ? '\0' : DirEntry->FileName[10];
}
----- DbgPrint((DPRINT_FILESYSTEM, "FatParseShortFileName() ShortName = %s\n", Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatParseShortFileName() ShortName = %s\n", Buffer);
}
/*
BOOLEAN FatGetFatEntry(ULONG Cluster, ULONG* ClusterPointer)
{
ULONG fat = 0;
---- UINT FatOffset;
---- UINT ThisFatSecNum;
---- UINT ThisFatEntOffset;
++++ UINT32 FatOffset;
++++ UINT32 ThisFatSecNum;
++++ UINT32 ThisFatEntOffset;
----- DbgPrint((DPRINT_FILESYSTEM, "FatGetFatEntry() Retrieving FAT entry for cluster %d.\n", Cluster));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatGetFatEntry() Retrieving FAT entry for cluster %d.\n", Cluster);
switch(FatType)
{
ThisFatSecNum = ActiveFatSectorStart + (FatOffset / BytesPerSector);
ThisFatEntOffset = (FatOffset % BytesPerSector);
----- DbgPrint((DPRINT_FILESYSTEM, "FatOffset: %d\n", FatOffset));
----- DbgPrint((DPRINT_FILESYSTEM, "ThisFatSecNum: %d\n", ThisFatSecNum));
----- DbgPrint((DPRINT_FILESYSTEM, "ThisFatEntOffset: %d\n", ThisFatEntOffset));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatOffset: %d\n", FatOffset);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ThisFatSecNum: %d\n", ThisFatSecNum);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ThisFatEntOffset: %d\n", ThisFatEntOffset);
if (ThisFatEntOffset == (BytesPerSector - 1))
{
}
----- DbgPrint((DPRINT_FILESYSTEM, "FAT entry is 0x%x.\n", fat));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FAT entry is 0x%x.\n", fat);
*ClusterPointer = fat;
FAT_FILE_INFO TempFatFileInfo;
PFAT_FILE_INFO FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "FatOpenFile() FileName = %s\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatOpenFile() FileName = %s\n", FileName);
if (!FatLookupFile(FileName, &TempFatFileInfo))
{
{
ULONG ClusterCount = 0;
----- DbgPrint((DPRINT_FILESYSTEM, "FatCountClustersInChain() StartCluster = %d\n", StartCluster));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatCountClustersInChain() StartCluster = %d\n", StartCluster);
while (1)
{
}
}
----- DbgPrint((DPRINT_FILESYSTEM, "FatCountClustersInChain() ClusterCount = %d\n", ClusterCount));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatCountClustersInChain() ClusterCount = %d\n", ClusterCount);
return ClusterCount;
}
ULONG* ArrayPointer;
ULONG Idx;
----- DbgPrint((DPRINT_FILESYSTEM, "FatGetClusterChainArray() StartCluster = %d\n", StartCluster));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatGetClusterChainArray() StartCluster = %d\n", StartCluster);
ClusterCount = FatCountClustersInChain(StartCluster) + 1; // Lets get the 0x0ffffff8 on the end of the array
ArraySize = ClusterCount * sizeof(ULONG);
ClusterStartSector = ((ClusterNumber - 2) * SectorsPerCluster) + DataSectorStart;
----- DbgPrint((DPRINT_FILESYSTEM, "FatReadCluster() ClusterNumber = %d Buffer = 0x%x ClusterStartSector = %d\n", ClusterNumber, Buffer, ClusterStartSector));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatReadCluster() ClusterNumber = %d Buffer = 0x%x ClusterStartSector = %d\n", ClusterNumber, Buffer, ClusterStartSector);
if (!FatReadVolumeSectors(FatDriveNumber, ClusterStartSector, SectorsPerCluster, (PVOID)FILESYSBUFFER))
{
{
ULONG ClusterStartSector;
----- DbgPrint((DPRINT_FILESYSTEM, "FatReadClusterChain() StartClusterNumber = %d NumberOfClusters = %d Buffer = 0x%x\n", StartClusterNumber, NumberOfClusters, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatReadClusterChain() StartClusterNumber = %d NumberOfClusters = %d Buffer = 0x%x\n", StartClusterNumber, NumberOfClusters, Buffer);
while (NumberOfClusters > 0)
{
----- DbgPrint((DPRINT_FILESYSTEM, "FatReadClusterChain() StartClusterNumber = %d NumberOfClusters = %d Buffer = 0x%x\n", StartClusterNumber, NumberOfClusters, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatReadClusterChain() StartClusterNumber = %d NumberOfClusters = %d Buffer = 0x%x\n", StartClusterNumber, NumberOfClusters, Buffer);
//
// Calculate starting sector for cluster
//
{
ULONG ClusterStartSector;
----- DbgPrint((DPRINT_FILESYSTEM, "FatReadPartialCluster() ClusterNumber = %d StartingOffset = %d Length = %d Buffer = 0x%x\n", ClusterNumber, StartingOffset, Length, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatReadPartialCluster() ClusterNumber = %d StartingOffset = %d Length = %d Buffer = 0x%x\n", ClusterNumber, StartingOffset, Length, Buffer);
ClusterStartSector = ((ClusterNumber - 2) * SectorsPerCluster) + DataSectorStart;
ULONG NumberOfClusters;
ULONG BytesPerCluster;
----- DbgPrint((DPRINT_FILESYSTEM, "FatReadFile() BytesToRead = %d Buffer = 0x%x\n", BytesToRead, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatReadFile() BytesToRead = %d Buffer = 0x%x\n", BytesToRead, Buffer);
if (BytesRead != NULL)
{
{
PFAT_FILE_INFO FatFileHandle = (PFAT_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "FatGetFileSize() FileSize = %d\n", FatFileHandle->FileSize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatGetFileSize() FileSize = %d\n", FatFileHandle->FileSize);
return FatFileHandle->FileSize;
}
{
PFAT_FILE_INFO FatFileHandle = (PFAT_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "FatSetFilePointer() NewFilePointer = %d\n", NewFilePointer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatSetFilePointer() NewFilePointer = %d\n", NewFilePointer);
FatFileHandle->FilePointer = NewFilePointer;
}
{
PFAT_FILE_INFO FatFileHandle = (PFAT_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "FatGetFilePointer() FilePointer = %d\n", FatFileHandle->FilePointer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatGetFilePointer() FilePointer = %d\n", FatFileHandle->FilePointer);
return FatFileHandle->FilePointer;
}
VOID FileSystemError(PCSTR ErrorString)
{
----- DbgPrint((DPRINT_FILESYSTEM, "%s\n", ErrorString));
+++++ DPRINTM(DPRINT_FILESYSTEM, "%s\n", ErrorString);
UiMessageBox(ErrorString);
}
//
// Print status message
//
----- DbgPrint((DPRINT_FILESYSTEM, "Opening file '%s'...\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Opening file '%s'...\n", FileName);
//
// Check and see if the first character is '\' or '/' and remove it if so
//
if (FileHandle != NULL)
{
----- DbgPrint((DPRINT_FILESYSTEM, "FsOpenFile() succeeded. FileHandle: 0x%x\n", FileHandle));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FsOpenFile() succeeded. FileHandle: 0x%x\n", FileHandle);
}
else
{
----- DbgPrint((DPRINT_FILESYSTEM, "FsOpenFile() failed.\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FsOpenFile() failed.\n");
}
return FileHandle;
}
num++;
----- DbgPrint((DPRINT_FILESYSTEM, "FatGetNumPathParts() Path = %s NumPathParts = %d\n", Path, num));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatGetNumPathParts() Path = %s NumPathParts = %d\n", Path, num);
return num;
}
Buffer[i] = 0;
----- DbgPrint((DPRINT_FILESYSTEM, "FatGetFirstNameFromPath() Path = %s FirstName = %s\n", Path, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FatGetFirstNameFromPath() Path = %s FirstName = %s\n", Path, Buffer);
}
BOOLEAN FsRecognizeVolume(ULONG DriveNumber, ULONG VolumeStartSector, UCHAR* VolumeType)
{
----- DbgPrint((DPRINT_FILESYSTEM, "FsRecognizeVolume() DriveNumber: 0x%x VolumeStartSector: %d\n", DriveNumber, VolumeStartSector));
+++++ DPRINTM(DPRINT_FILESYSTEM, "FsRecognizeVolume() DriveNumber: 0x%x VolumeStartSector: %d\n", DriveNumber, VolumeStartSector);
if (FsRecIsExt2(DriveNumber, VolumeStartSector))
{
{
PPVD Pvd = (PPVD)DISKREADBUFFER;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoOpenVolume() DriveNumber = 0x%x VolumeStartSector = 16\n", DriveNumber));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoOpenVolume() DriveNumber = 0x%x VolumeStartSector = 16\n", DriveNumber);
// Store the drive number
IsoDriveNumber = DriveNumber;
IsoRootSector = Pvd->RootDirRecord.ExtentLocationL;
IsoRootLength = Pvd->RootDirRecord.DataLengthL;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoRootSector = %u IsoRootLegth = %u\n", IsoRootSector, IsoRootLength));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoRootSector = %u IsoRootLegth = %u\n", IsoRootSector, IsoRootLength);
return TRUE;
}
ULONG i;
CHAR Name[32];
----- DbgPrint((DPRINT_FILESYSTEM, "IsoSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x DirectoryLength = %d FileName = %s\n", DirectoryBuffer, DirectoryLength, FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoSearchDirectoryBufferForFile() DirectoryBuffer = 0x%x DirectoryLength = %d FileName = %s\n", DirectoryBuffer, DirectoryLength, FileName);
RtlZeroMemory(Name, 32 * sizeof(UCHAR));
if (Record->FileIdLength == 1 && Record->FileId[0] == 0)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Name '.'\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Name '.'\n");
}
else if (Record->FileIdLength == 1 && Record->FileId[0] == 1)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Name '..'\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Name '..'\n");
}
else
{
for (i = 0; i < Record->FileIdLength && Record->FileId[i] != ';'; i++)
Name[i] = Record->FileId[i];
Name[i] = 0;
----- DbgPrint((DPRINT_FILESYSTEM, "Name '%s'\n", Name));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Name '%s'\n", Name);
if (strlen(FileName) == strlen(Name) && _stricmp(FileName, Name) == 0)
{
ULONG SectorCount;
ULONG i;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoBufferDirectory() DirectoryStartSector = %d DirectoryLength = %d\n", DirectoryStartSector, DirectoryLength));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoBufferDirectory() DirectoryStartSector = %d DirectoryLength = %d\n", DirectoryStartSector, DirectoryLength);
SectorCount = ROUND_UP(DirectoryLength, SECTORSIZE) / SECTORSIZE;
----- DbgPrint((DPRINT_FILESYSTEM, "Trying to read (DirectoryCount) %d sectors.\n", SectorCount));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Trying to read (DirectoryCount) %d sectors.\n", SectorCount);
//
// Attempt to allocate memory for directory buffer
//
----- DbgPrint((DPRINT_FILESYSTEM, "Trying to allocate (DirectoryLength) %d bytes.\n", DirectoryLength));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Trying to allocate (DirectoryLength) %d bytes.\n", DirectoryLength);
DirectoryBuffer = MmHeapAlloc(DirectoryLength);
if (DirectoryBuffer == NULL)
ULONG DirectoryLength;
ISO_FILE_INFO IsoFileInfo;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoLookupFile() FileName = %s\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoLookupFile() FileName = %s\n", FileName);
RtlZeroMemory(IsoFileInfoPointer, sizeof(ISO_FILE_INFO));
ISO_FILE_INFO TempFileInfo;
PISO_FILE_INFO FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoOpenFile() FileName = %s\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoOpenFile() FileName = %s\n", FileName);
if (!IsoLookupFile(FileName, &TempFileInfo))
{
ULONG NumberOfSectors;
ULONG i;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoReadFile() BytesToRead = %d Buffer = 0x%x\n", BytesToRead, Buffer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoReadFile() BytesToRead = %d Buffer = 0x%x\n", BytesToRead, Buffer);
if (BytesRead != NULL)
{
Buffer = (PVOID)((ULONG_PTR)Buffer + BytesToRead);
}
----- DbgPrint((DPRINT_FILESYSTEM, "IsoReadFile() done\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoReadFile() done\n");
return TRUE;
}
{
PISO_FILE_INFO IsoFileHandle = (PISO_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoGetFileSize() FileSize = %d\n", IsoFileHandle->FileSize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoGetFileSize() FileSize = %d\n", IsoFileHandle->FileSize);
return IsoFileHandle->FileSize;
}
{
PISO_FILE_INFO IsoFileHandle = (PISO_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoSetFilePointer() NewFilePointer = %d\n", NewFilePointer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoSetFilePointer() NewFilePointer = %d\n", NewFilePointer);
IsoFileHandle->FilePointer = NewFilePointer;
}
{
PISO_FILE_INFO IsoFileHandle = (PISO_FILE_INFO)FileHandle;
----- DbgPrint((DPRINT_FILESYSTEM, "IsoGetFilePointer() FilePointer = %d\n", IsoFileHandle->FilePointer));
+++++ DPRINTM(DPRINT_FILESYSTEM, "IsoGetFilePointer() FilePointer = %d\n", IsoFileHandle->FilePointer);
return IsoFileHandle->FilePointer;
}
*DataRunOffset = ((CHAR)(*(DataRun++)) << (i << 3)) + *DataRunOffset;
}
----- DbgPrint((DPRINT_FILESYSTEM, "DataRunOffsetSize: %x\n", DataRunOffsetSize));
----- DbgPrint((DPRINT_FILESYSTEM, "DataRunLengthSize: %x\n", DataRunLengthSize));
----- DbgPrint((DPRINT_FILESYSTEM, "DataRunOffset: %x\n", *DataRunOffset));
----- DbgPrint((DPRINT_FILESYSTEM, "DataRunLength: %x\n", *DataRunLength));
+++++ DPRINTM(DPRINT_FILESYSTEM, "DataRunOffsetSize: %x\n", DataRunOffsetSize);
+++++ DPRINTM(DPRINT_FILESYSTEM, "DataRunLengthSize: %x\n", DataRunLengthSize);
+++++ DPRINTM(DPRINT_FILESYSTEM, "DataRunOffset: %x\n", *DataRunOffset);
+++++ DPRINTM(DPRINT_FILESYSTEM, "DataRunLength: %x\n", *DataRunLength);
return DataRun;
}
{
USHORT ReadLength;
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsDiskRead - Offset: %I64d Length: %I64d\n", Offset, Length));
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsDiskRead - Offset: %I64d Length: %I64d\n", Offset, Length);
RtlZeroMemory((PCHAR)DISKREADBUFFER, 0x1000);
/* I. Read partial first sector if needed */
AnsiFileName[i] = FileName[i];
AnsiFileName[i] = 0;
----- DbgPrint((DPRINT_FILESYSTEM, "- %s (%x)\n", AnsiFileName, IndexEntry->Data.Directory.IndexedFile));
+++++ DPRINTM(DPRINT_FILESYSTEM, "- %s (%x)\n", AnsiFileName, IndexEntry->Data.Directory.IndexedFile);
}
#endif
IndexEntryEnd = (PNTFS_INDEX_ENTRY)(IndexRecord + IndexRootCtx->Record.Resident.ValueLength);
NtfsReleaseAttributeContext(IndexRootCtx);
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsIndexRecordSize: %x IndexBlockSize: %x\n", NtfsIndexRecordSize, IndexRoot->IndexBlockSize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsIndexRecordSize: %x IndexBlockSize: %x\n", NtfsIndexRecordSize, IndexRoot->IndexBlockSize);
while (IndexEntry < IndexEntryEnd &&
!(IndexEntry->Flags & NTFS_INDEX_ENTRY_END))
if (IndexRoot->IndexHeader.Flags & NTFS_LARGE_INDEX)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Large Index!\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Large Index!\n");
IndexBlockSize = IndexRoot->IndexBlockSize;
IndexBitmapCtx = NtfsFindAttribute(MftRecord, NTFS_ATTR_TYPE_BITMAP, L"$I30");
if (IndexBitmapCtx == NULL)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Corrupted filesystem!\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Corrupted filesystem!\n");
MmHeapFree(MftRecord);
return FALSE;
}
BitmapDataSize = NtfsGetAttributeSize(&IndexBitmapCtx->Record);
----- DbgPrint((DPRINT_FILESYSTEM, "BitmapDataSize: %x\n", BitmapDataSize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "BitmapDataSize: %x\n", BitmapDataSize);
BitmapData = MmHeapAlloc(BitmapDataSize);
if (BitmapData == NULL)
{
IndexAllocationCtx = NtfsFindAttribute(MftRecord, NTFS_ATTR_TYPE_INDEX_ALLOCATION, L"$I30");
if (IndexAllocationCtx == NULL)
{
----- DbgPrint((DPRINT_FILESYSTEM, "Corrupted filesystem!\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Corrupted filesystem!\n");
MmHeapFree(BitmapData);
MmHeapFree(IndexRecord);
MmHeapFree(MftRecord);
for (;;)
{
----- DbgPrint((DPRINT_FILESYSTEM, "RecordOffset: %x IndexAllocationSize: %x\n", RecordOffset, IndexAllocationSize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "RecordOffset: %x IndexAllocationSize: %x\n", RecordOffset, IndexAllocationSize);
for (; RecordOffset < IndexAllocationSize;)
{
UCHAR Bit = 1 << ((RecordOffset / IndexBlockSize) & 7);
{
if (NtfsCompareFileName(FileName, IndexEntry))
{
----- DbgPrint((DPRINT_FILESYSTEM, "File found\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "File found\n");
*OutMFTIndex = IndexEntry->Data.Directory.IndexedFile;
MmHeapFree(BitmapData);
MmHeapFree(IndexRecord);
}
else
{
----- DbgPrint((DPRINT_FILESYSTEM, "Can't read MFT record\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Can't read MFT record\n");
}
MmHeapFree(MftRecord);
ULONG CurrentMFTIndex;
UCHAR i;
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsLookupFile() FileName = %s\n", FileName));
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsLookupFile() FileName = %s\n", FileName);
CurrentMFTIndex = NTFS_FILE_ROOT;
NumberOfPathParts = FsGetNumPathParts(FileName);
;
FileName++;
----- DbgPrint((DPRINT_FILESYSTEM, "- Lookup: %s\n", PathPart));
+++++ DPRINTM(DPRINT_FILESYSTEM, "- Lookup: %s\n", PathPart);
if (!NtfsFindMftRecord(CurrentMFTIndex, PathPart, &CurrentMFTIndex))
{
----- DbgPrint((DPRINT_FILESYSTEM, "- Failed\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "- Failed\n");
return FALSE;
}
----- DbgPrint((DPRINT_FILESYSTEM, "- Lookup: %x\n", CurrentMFTIndex));
+++++ DPRINTM(DPRINT_FILESYSTEM, "- Lookup: %x\n", CurrentMFTIndex);
}
if (!NtfsReadMftRecord(CurrentMFTIndex, MftRecord))
{
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsLookupFile: Can't read MFT record\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsLookupFile: Can't read MFT record\n");
return FALSE;
}
*DataContext = NtfsFindAttribute(MftRecord, NTFS_ATTR_TYPE_DATA, L"");
if (*DataContext == NULL)
{
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsLookupFile: Can't find data attribute\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsLookupFile: Can't find data attribute\n");
return FALSE;
}
{
NtfsBootSector = (PNTFS_BOOTSECTOR)DISKREADBUFFER;
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsOpenVolume() DriveNumber = 0x%x VolumeStartSector = 0x%x\n", DriveNumber, VolumeStartSector));
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsOpenVolume() DriveNumber = 0x%x VolumeStartSector = 0x%x\n", DriveNumber, VolumeStartSector);
if (!MachDiskReadLogicalSectors(DriveNumber, VolumeStartSector, 1, (PCHAR)DISKREADBUFFER))
{
else
NtfsIndexRecordSize = 1 << (-NtfsBootSector->ClustersPerIndexRecord);
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsClusterSize: 0x%x\n", NtfsClusterSize));
----- DbgPrint((DPRINT_FILESYSTEM, "ClustersPerMftRecord: %d\n", NtfsBootSector->ClustersPerMftRecord));
----- DbgPrint((DPRINT_FILESYSTEM, "ClustersPerIndexRecord: %d\n", NtfsBootSector->ClustersPerIndexRecord));
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsMftRecordSize: 0x%x\n", NtfsMftRecordSize));
----- DbgPrint((DPRINT_FILESYSTEM, "NtfsIndexRecordSize: 0x%x\n", NtfsIndexRecordSize));
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsClusterSize: 0x%x\n", NtfsClusterSize);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ClustersPerMftRecord: %d\n", NtfsBootSector->ClustersPerMftRecord);
+++++ DPRINTM(DPRINT_FILESYSTEM, "ClustersPerIndexRecord: %d\n", NtfsBootSector->ClustersPerIndexRecord);
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsMftRecordSize: 0x%x\n", NtfsMftRecordSize);
+++++ DPRINTM(DPRINT_FILESYSTEM, "NtfsIndexRecordSize: 0x%x\n", NtfsIndexRecordSize);
NtfsDriveNumber = DriveNumber;
NtfsSectorOfClusterZero = VolumeStartSector;
----- DbgPrint((DPRINT_FILESYSTEM, "Reading MFT index...\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Reading MFT index...\n");
if (!MachDiskReadLogicalSectors(DriveNumber,
NtfsSectorOfClusterZero +
(NtfsBootSector->MftLocation * NtfsBootSector->SectorsPerCluster),
RtlCopyMemory(NtfsMasterFileTable, (PCHAR)DISKREADBUFFER, NtfsMftRecordSize);
----- DbgPrint((DPRINT_FILESYSTEM, "Searching for DATA attribute...\n"));
+++++ DPRINTM(DPRINT_FILESYSTEM, "Searching for DATA attribute...\n");
NtfsMFTContext = NtfsFindAttribute(NtfsMasterFileTable, NTFS_ATTR_TYPE_DATA, L"");
if (NtfsMFTContext == NULL)
{
#ifndef __ARCH_H
#define __ARCH_H
+++++#ifdef _M_AMD64
+++++#include <arch/amd64/amd64.h>
+++++#endif
+++++
+++++#if defined (_M_IX86)
/* Defines needed for switching between real and protected mode */
#define NULL_DESC 0x00 /* NULL descriptor */
#define PMODE_CS 0x08 /* PMode code selector, base 0 limit 4g */
#define PMODE_DS 0x10 /* PMode data selector, base 0 limit 4g */
#define RMODE_CS 0x18 /* RMode code selector, base 0 limit 64k */
#define RMODE_DS 0x20 /* RMode data selector, base 0 limit 64k */
+++++#endif
#define CR0_PE_SET 0x00000001 /* OR this value with CR0 to enable pmode */
#define CR0_PE_CLR 0xFFFFFFFE /* AND this value with CR0 to disable pmode */
--- /dev/null
+ /*
+ * FreeLoader
+ *
+ * Copyright (C) 2003 Eric Kohl
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+ #ifndef __AMD64_AMD64_H_
+ #define __AMD64_AMD64_H_
+
+++++#define STACK64ADDR 0x74000 /* The 64-bit stack top will be at 0x74000 */
+
+++++/* Long mode selectors */
+++++#define LMODE_CS 0x10
+++++#define LMODE_DS 0x18
+++++#define RMODE_CS 0x20 /* RMode code selector, base 0 limit 64k */
+++++#define RMODE_DS 0x28 /* RMode data selector, base 0 limit 64k */
+++++
+++++#define VA_MASK 0x0000FFFFFFFFFFFFUL
+++++
+++++#define PtrToPfn(p) \
+++++ ((((ULONGLONG)p) >> PAGE_SHIFT) & 0xfffffffULL)
+++++
+++++#define VAtoPXI(va) ((((ULONG64)va) >> PXI_SHIFT) & 0x1FF)
+++++#define VAtoPPI(va) ((((ULONG64)va) >> PPI_SHIFT) & 0x1FF)
+++++#define VAtoPDI(va) ((((ULONG64)va) >> PDI_SHIFT) & 0x1FF)
+++++#define VAtoPTI(va) ((((ULONG64)va) >> PTI_SHIFT) & 0x1FF)
+++++
+++++#define HYPERSPACE_BASE 0xfffff70000000000ULL
+++++#define HAL_BASE 0xffffffff80000000ULL
+++++#define APIC_BASE 0xfffffffffee00000ULL // FIXME
+++++
+++++#define APIC_PHYS_BASE 0xfee00000
+++++
+++++#define NUM_PAGES_KERNEL
+++++
+++++#ifndef ASM
+++++typedef struct _PAGE_DIRECTORY_AMD64
+++++{
+++++ HARDWARE_PTE Pde[512];
+++++} PAGE_DIRECTORY_AMD64, *PPAGE_DIRECTORY_AMD64;
+++++
+++++VOID
+++++FORCEINLINE
+++++__lgdt(void *gdt)
+++++{
+++++ asm volatile ("lgdt %0\n" : : "m"(*(short*)gdt));
+++++}
+++++
+++++PKGDTENTRY64
+++++FORCEINLINE
+++++KiGetGdtEntry(PVOID pGdt, USHORT Index)
+++++{
+++++ return (PKGDTENTRY64)((ULONG64)pGdt + (Index & ~RPL_MASK));
+++++}
+++++
+++++VOID
+++++FORCEINLINE
+++++KiInitGdtEntry(PKGDTENTRY64 Entry, ULONG64 Base, ULONG Limit, UCHAR Type, UCHAR Dpl)
+++++{
+++++ Entry->Bits.Type = Type;
+++++ Entry->Bits.Present = 1;
+++++ Entry->Bits.Dpl = Dpl;
+++++ Entry->BaseLow = (USHORT)(Base & 0xFFFF);
+++++ Entry->Bytes.BaseMiddle = (UCHAR)(Base >> 16);
+++++ Entry->Bytes.BaseHigh = (UCHAR)(Base >> 24);
+++++ Entry->BaseUpper = (ULONG)(Base >> 32);
+++++ Entry->LimitLow = (USHORT)(Limit & 0xFFFF);
+++++ Entry->Bits.LimitHigh = (ULONG)((Limit >> 16) & 0xf);
+++++ Entry->MustBeZero = 0;
+++++}
+++++
+++++VOID FrLdrSetupGdtIdt();
+++++
+++++#endif
+
+ #endif /* __AMD64_AMD64_H_ */
+
+ /* EOF */
--- /dev/null
+ /* $Id: machpc.h 32135 2008-02-05 11:13:17Z ros-arm-bringup $
+ *
+ * FreeLoader
+ *
+ * Copyright (C) 2003 Eric Kohl
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+ #ifndef __I386_MACHPC_H_
+ #define __I386_MACHPC_H_
+
+ #ifndef __MEMORY_H
+ #include "mm.h"
+ #endif
+
+++++#define MachInit PcMachInit
+ VOID PcMachInit(const char *CmdLine);
+
+ VOID PcConsPutChar(int Ch);
+ BOOLEAN PcConsKbHit();
+ int PcConsGetCh();
+
+ VOID PcVideoClearScreen(UCHAR Attr);
+ VIDEODISPLAYMODE PcVideoSetDisplayMode(char *DisplayMode, BOOLEAN Init);
+ VOID PcVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth);
+ ULONG PcVideoGetBufferSize(VOID);
+ VOID PcVideoSetTextCursorPosition(ULONG X, ULONG Y);
+ VOID PcVideoHideShowTextCursor(BOOLEAN Show);
+ VOID PcVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y);
+ VOID PcVideoCopyOffScreenBufferToVRAM(PVOID Buffer);
+ BOOLEAN PcVideoIsPaletteFixed(VOID);
+ VOID PcVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue);
+ VOID PcVideoGetPaletteColor(UCHAR Color, UCHAR* Red, UCHAR* Green, UCHAR* Blue);
+ VOID PcVideoSync(VOID);
+ VOID PcVideoPrepareForReactOS(IN BOOLEAN Setup);
+ VOID PcPrepareForReactOS(IN BOOLEAN Setup);
+
+ ULONG PcMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize);
+
+ BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
+ BOOLEAN PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
+ BOOLEAN PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry);
+ ULONG PcDiskGetCacheableBlockCount(ULONG DriveNumber);
+
+ VOID PcRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second);
+
+ PCONFIGURATION_COMPONENT_DATA PcHwDetect(VOID);
+
+ #endif /* __I386_MACHPC_H_ */
+
+ /* EOF */
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-----
+++++#include <reactos/debug.h>
#ifndef __DEBUG_H
#define __DEBUG_H
-----#define DPRINT_NONE 0x00000000 // No debug print
-----#define DPRINT_WARNING 0x00000001 // OR this with DebugPrintMask to enable debugger messages and other misc stuff
-----#define DPRINT_MEMORY 0x00000002 // OR this with DebugPrintMask to enable memory management messages
-----#define DPRINT_FILESYSTEM 0x00000004 // OR this with DebugPrintMask to enable file system messages
-----#define DPRINT_INIFILE 0x00000008 // OR this with DebugPrintMask to enable .ini file messages
-----#define DPRINT_UI 0x00000010 // OR this with DebugPrintMask to enable user interface messages
-----#define DPRINT_DISK 0x00000020 // OR this with DebugPrintMask to enable disk messages
-----#define DPRINT_CACHE 0x00000040 // OR this with DebugPrintMask to enable cache messages
-----#define DPRINT_REGISTRY 0x00000080 // OR this with DebugPrintMask to enable registry messages
-----#define DPRINT_REACTOS 0x00000100 // OR this with DebugPrintMask to enable ReactOS messages
-----#define DPRINT_LINUX 0x00000200 // OR this with DebugPrintMask to enable Linux messages
-----#define DPRINT_HWDETECT 0x00000400 // OR this with DebugPrintMask to enable hardware detection messages
-----#define DPRINT_WINDOWS 0x00000800 // OR this with DebugPrintMask to enable messages from Windows loader
+++++#define DPRINT_NONE 0x00000000 // No debug print
+++++#define DPRINT_WARNING 0x00000001 // OR this with DebugPrintMask to enable debugger messages and other misc stuff
+++++#define DPRINT_MEMORY 0x00000002 // OR this with DebugPrintMask to enable memory management messages
+++++#define DPRINT_FILESYSTEM 0x00000004 // OR this with DebugPrintMask to enable file system messages
+++++#define DPRINT_INIFILE 0x00000008 // OR this with DebugPrintMask to enable .ini file messages
+++++#define DPRINT_UI 0x00000010 // OR this with DebugPrintMask to enable user interface messages
+++++#define DPRINT_DISK 0x00000020 // OR this with DebugPrintMask to enable disk messages
+++++#define DPRINT_CACHE 0x00000040 // OR this with DebugPrintMask to enable cache messages
+++++#define DPRINT_REGISTRY 0x00000080 // OR this with DebugPrintMask to enable registry messages
+++++#define DPRINT_REACTOS 0x00000100 // OR this with DebugPrintMask to enable ReactOS messages
+++++#define DPRINT_LINUX 0x00000200 // OR this with DebugPrintMask to enable Linux messages
+++++#define DPRINT_HWDETECT 0x00000400 // OR this with DebugPrintMask to enable hardware detection messages
+++++#define DPRINT_WINDOWS 0x00000800 // OR this with DebugPrintMask to enable messages from Windows loader
-----VOID DebugPrint(ULONG Mask, char *format, ...);
+++++extern char* g_file;
+++++extern int g_line;
#ifdef DBG
+++++ VOID DbgPrintMask(ULONG Mask, char *format, ...);
VOID DebugInit(VOID);
----- VOID DebugPrint1(char *format, ...);
+++++ ULONG DbgPrint(const char *Format, ...);
+++++
VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length);
----- #define DbgPrint(_x_) DebugPrint _x_ ;
----- #define DPRINT1 DebugPrint1
----- #define BugCheck(_x_) { DebugPrint(DPRINT_WARNING, "Fatal Error: %s:%d(%s)\n", __FILE__, __LINE__, __FUNCTION__); DebugPrint _x_ ; for (;;); }
+++++ #define DPRINTM g_file=__FILE__;g_line=__LINE__;DbgPrintMask
+++++ #define BugCheck(_x_) { DbgPrintMask(DPRINT_WARNING, "Fatal Error: %s:%d(%s)\n", __FILE__, __LINE__, __FUNCTION__); DbgPrintMask _x_ ; for (;;); }
#define DbgDumpBuffer(_x_, _y_, _z_) DebugDumpBuffer(_x_, _y_, _z_)
#ifdef __i386__
#else
#define DebugInit()
----- #define DbgPrint(_x_) { if (0) DebugPrint _x_; }
----- #define DPRINT1(_x_) { if (0) printf _x_; }
+++++ #define DPRINTM(_x_)
#define BugCheck(_x_)
#define DbgDumpBuffer(_x_, _y_, _z_)
#endif // defined DBG
-----#define UNIMPLEMENTED BugCheck((DPRINT_WARNING, "This function is unimplemented!\n"))
-----
#endif // defined __DEBUG_H
#define Ke386EraseFlags(x) __asm__ __volatile__("pushl $0 ; popfl\n")
#endif
+++++#ifdef _M_AMD64
+++++#define KeAmd64EraseFlags(x) __asm__ __volatile__("pushq $0 ; popfq\n")
+++++#endif
+++++
VOID BootMain(LPSTR CmdLine);
VOID RunLoader(VOID);
/* Base Addres of Kernel in Physical Memory */
#define KERNEL_BASE_PHYS 0x800000
+++++#if !defined(_M_AMD64)
+++++
/* Bits to shift to convert a Virtual Address into an Offset in the Page Table */
#define PFN_SHIFT 12
HARDWARE_PTE Pde[1024];
} PAGE_DIRECTORY_X86, *PPAGE_DIRECTORY_X86;
+++++#endif
+++++
///////////////////////////////////////////////////////////////////////////////////////
//
// ReactOS Loading Functions
{
PINI_SECTION Section;
----- DbgPrint((DPRINT_INIFILE, "IniOpenSection() SectionName = %s\n", SectionName));
+++++ DPRINTM(DPRINT_INIFILE, "IniOpenSection() SectionName = %s\n", SectionName);
// Loop through each section and find the one they want
Section = CONTAINING_RECORD(IniFileSectionListHead.Flink, INI_SECTION, ListEntry);
// We found it
if (SectionId)
*SectionId = (ULONG_PTR)Section;
----- DbgPrint((DPRINT_INIFILE, "IniOpenSection() Found it! SectionId = 0x%x\n", SectionId));
+++++ DPRINTM(DPRINT_INIFILE, "IniOpenSection() Found it! SectionId = 0x%x\n", SectionId);
return TRUE;
}
Section = CONTAINING_RECORD(Section->ListEntry.Flink, INI_SECTION, ListEntry);
}
----- DbgPrint((DPRINT_INIFILE, "IniOpenSection() Section not found.\n"));
+++++ DPRINTM(DPRINT_INIFILE, "IniOpenSection() Section not found.\n");
return FALSE;
}
{
PINI_SECTION Section = (PINI_SECTION)SectionId;
----- DbgPrint((DPRINT_INIFILE, "IniGetNumSectionItems() SectionId = 0x%x\n", SectionId));
----- DbgPrint((DPRINT_INIFILE, "IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount));
+++++ DPRINTM(DPRINT_INIFILE, "IniGetNumSectionItems() SectionId = 0x%x\n", SectionId);
+++++ DPRINTM(DPRINT_INIFILE, "IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount);
return Section->SectionItemCount;
}
BOOLEAN IniReadSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize)
{
PINI_SECTION_ITEM SectionItem;
----- DbgPrint((DPRINT_INIFILE, ".001 NameSize = %d ValueSize = %d\n", NameSize, ValueSize));
+++++ DPRINTM(DPRINT_INIFILE, ".001 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() SectionId = 0x%x\n", SectionId));
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByNumber() SectionId = 0x%x\n", SectionId);
// Retrieve requested setting
SectionItem = IniGetSettingByNumber(SectionId, SettingNumber);
if (!SectionItem)
{
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d not found.\n", SettingNumber));
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d not found.\n", SettingNumber);
return FALSE;
}
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d found.\n", SettingNumber));
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName));
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue));
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d found.\n", SettingNumber);
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName);
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue);
----- DbgPrint((DPRINT_INIFILE, "1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize));
----- DbgPrint((DPRINT_INIFILE, "2 NameSize = %d ValueSize = %d\n", NameSize, ValueSize));
+++++ DPRINTM(DPRINT_INIFILE, "1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
+++++ DPRINTM(DPRINT_INIFILE, "2 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
strncpy(SettingName, SectionItem->ItemName, NameSize - 1);
SettingName[NameSize - 1] = '\0';
----- DbgPrint((DPRINT_INIFILE, "3 NameSize = %d ValueSize = %d\n", NameSize, ValueSize));
+++++ DPRINTM(DPRINT_INIFILE, "3 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
strncpy(SettingValue, SectionItem->ItemValue, ValueSize - 1);
SettingValue[ValueSize - 1] = '\0';
----- DbgPrint((DPRINT_INIFILE, "4 NameSize = %d ValueSize = %d\n", NameSize, ValueSize));
+++++ DPRINTM(DPRINT_INIFILE, "4 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
DbgDumpBuffer(DPRINT_INIFILE, SettingName, NameSize);
DbgDumpBuffer(DPRINT_INIFILE, SettingValue, ValueSize);
PINI_SECTION Section = (PINI_SECTION)SectionId;
PINI_SECTION_ITEM SectionItem;
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() SectionId = 0x%x\n", SectionId));
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByName() SectionId = 0x%x\n", SectionId);
// Loop through each section item and find the one they want
SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry);
// Check to see if this is the setting they want
if (_stricmp(SettingName, SectionItem->ItemName) == 0)
{
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' found.\n", SettingName));
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue));
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' found.\n", SettingName);
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue);
strncpy(Buffer, SectionItem->ItemValue, BufferSize - 1);
Buffer[BufferSize - 1] = '\0';
SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry);
}
----- DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' not found.\n", SettingName));
+++++ DPRINTM(DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' not found.\n", SettingName);
return FALSE;
}
PINI_SECTION CurrentSection = NULL;
PINI_SECTION_ITEM CurrentItem = NULL;
----- DbgPrint((DPRINT_INIFILE, "IniParseFile() IniFileSize: %d\n", IniFileSize));
+++++ DPRINTM(DPRINT_INIFILE, "IniParseFile() IniFileSize: %d\n", IniFileSize);
if (!IniFileSectionInitialized)
{
CurrentLineNumber++;
}
----- DbgPrint((DPRINT_INIFILE, "Parsed %d sections and %d settings.\n", IniFileSectionCount, IniFileSettingCount));
----- DbgPrint((DPRINT_INIFILE, "IniParseFile() done.\n"));
+++++ DPRINTM(DPRINT_INIFILE, "Parsed %d sections and %d settings.\n", IniFileSectionCount, IniFileSettingCount);
+++++ DPRINTM(DPRINT_INIFILE, "IniParseFile() done.\n");
return TRUE;
}
DbgDumpBuffer(DPRINT_LINUX, LinuxBootSector, 512);
----- DbgPrint((DPRINT_LINUX, "SetupSectors: %d\n", LinuxBootSector->SetupSectors));
----- DbgPrint((DPRINT_LINUX, "RootFlags: 0x%x\n", LinuxBootSector->RootFlags));
----- DbgPrint((DPRINT_LINUX, "SystemSize: 0x%x\n", LinuxBootSector->SystemSize));
----- DbgPrint((DPRINT_LINUX, "SwapDevice: 0x%x\n", LinuxBootSector->SwapDevice));
----- DbgPrint((DPRINT_LINUX, "RamSize: 0x%x\n", LinuxBootSector->RamSize));
----- DbgPrint((DPRINT_LINUX, "VideoMode: 0x%x\n", LinuxBootSector->VideoMode));
----- DbgPrint((DPRINT_LINUX, "RootDevice: 0x%x\n", LinuxBootSector->RootDevice));
----- DbgPrint((DPRINT_LINUX, "BootFlag: 0x%x\n", LinuxBootSector->BootFlag));
+++++ DPRINTM(DPRINT_LINUX, "SetupSectors: %d\n", LinuxBootSector->SetupSectors);
+++++ DPRINTM(DPRINT_LINUX, "RootFlags: 0x%x\n", LinuxBootSector->RootFlags);
+++++ DPRINTM(DPRINT_LINUX, "SystemSize: 0x%x\n", LinuxBootSector->SystemSize);
+++++ DPRINTM(DPRINT_LINUX, "SwapDevice: 0x%x\n", LinuxBootSector->SwapDevice);
+++++ DPRINTM(DPRINT_LINUX, "RamSize: 0x%x\n", LinuxBootSector->RamSize);
+++++ DPRINTM(DPRINT_LINUX, "VideoMode: 0x%x\n", LinuxBootSector->VideoMode);
+++++ DPRINTM(DPRINT_LINUX, "RootDevice: 0x%x\n", LinuxBootSector->RootDevice);
+++++ DPRINTM(DPRINT_LINUX, "BootFlag: 0x%x\n", LinuxBootSector->BootFlag);
return TRUE;
}
DbgDumpBuffer(DPRINT_LINUX, LinuxSetupSector, SetupSectorSize);
----- DbgPrint((DPRINT_LINUX, "SetupHeaderSignature: 0x%x (HdrS)\n", LinuxSetupSector->SetupHeaderSignature));
----- DbgPrint((DPRINT_LINUX, "Version: 0x%x\n", LinuxSetupSector->Version));
----- DbgPrint((DPRINT_LINUX, "RealModeSwitch: 0x%x\n", LinuxSetupSector->RealModeSwitch));
----- DbgPrint((DPRINT_LINUX, "SetupSeg: 0x%x\n", LinuxSetupSector->SetupSeg));
----- DbgPrint((DPRINT_LINUX, "StartSystemSeg: 0x%x\n", LinuxSetupSector->StartSystemSeg));
----- DbgPrint((DPRINT_LINUX, "KernelVersion: 0x%x\n", LinuxSetupSector->KernelVersion));
----- DbgPrint((DPRINT_LINUX, "TypeOfLoader: 0x%x\n", LinuxSetupSector->TypeOfLoader));
----- DbgPrint((DPRINT_LINUX, "LoadFlags: 0x%x\n", LinuxSetupSector->LoadFlags));
----- DbgPrint((DPRINT_LINUX, "SetupMoveSize: 0x%x\n", LinuxSetupSector->SetupMoveSize));
----- DbgPrint((DPRINT_LINUX, "Code32Start: 0x%x\n", LinuxSetupSector->Code32Start));
----- DbgPrint((DPRINT_LINUX, "RamdiskAddress: 0x%x\n", LinuxSetupSector->RamdiskAddress));
----- DbgPrint((DPRINT_LINUX, "RamdiskSize: 0x%x\n", LinuxSetupSector->RamdiskSize));
----- DbgPrint((DPRINT_LINUX, "BootSectKludgeOffset: 0x%x\n", LinuxSetupSector->BootSectKludgeOffset));
----- DbgPrint((DPRINT_LINUX, "BootSectKludgeSegment: 0x%x\n", LinuxSetupSector->BootSectKludgeSegment));
----- DbgPrint((DPRINT_LINUX, "HeapEnd: 0x%x\n", LinuxSetupSector->HeapEnd));
+++++ DPRINTM(DPRINT_LINUX, "SetupHeaderSignature: 0x%x (HdrS)\n", LinuxSetupSector->SetupHeaderSignature);
+++++ DPRINTM(DPRINT_LINUX, "Version: 0x%x\n", LinuxSetupSector->Version);
+++++ DPRINTM(DPRINT_LINUX, "RealModeSwitch: 0x%x\n", LinuxSetupSector->RealModeSwitch);
+++++ DPRINTM(DPRINT_LINUX, "SetupSeg: 0x%x\n", LinuxSetupSector->SetupSeg);
+++++ DPRINTM(DPRINT_LINUX, "StartSystemSeg: 0x%x\n", LinuxSetupSector->StartSystemSeg);
+++++ DPRINTM(DPRINT_LINUX, "KernelVersion: 0x%x\n", LinuxSetupSector->KernelVersion);
+++++ DPRINTM(DPRINT_LINUX, "TypeOfLoader: 0x%x\n", LinuxSetupSector->TypeOfLoader);
+++++ DPRINTM(DPRINT_LINUX, "LoadFlags: 0x%x\n", LinuxSetupSector->LoadFlags);
+++++ DPRINTM(DPRINT_LINUX, "SetupMoveSize: 0x%x\n", LinuxSetupSector->SetupMoveSize);
+++++ DPRINTM(DPRINT_LINUX, "Code32Start: 0x%x\n", LinuxSetupSector->Code32Start);
+++++ DPRINTM(DPRINT_LINUX, "RamdiskAddress: 0x%x\n", LinuxSetupSector->RamdiskAddress);
+++++ DPRINTM(DPRINT_LINUX, "RamdiskSize: 0x%x\n", LinuxSetupSector->RamdiskSize);
+++++ DPRINTM(DPRINT_LINUX, "BootSectKludgeOffset: 0x%x\n", LinuxSetupSector->BootSectKludgeOffset);
+++++ DPRINTM(DPRINT_LINUX, "BootSectKludgeSegment: 0x%x\n", LinuxSetupSector->BootSectKludgeSegment);
+++++ DPRINTM(DPRINT_LINUX, "HeapEnd: 0x%x\n", LinuxSetupSector->HeapEnd);
return TRUE;
}
LinuxSetupSector->RamdiskAddress = (ULONG)LinuxInitrdLoadAddress;
LinuxSetupSector->RamdiskSize = LinuxInitrdSize;
----- DbgPrint((DPRINT_LINUX, "RamdiskAddress: 0x%x\n", LinuxSetupSector->RamdiskAddress));
----- DbgPrint((DPRINT_LINUX, "RamdiskSize: 0x%x\n", LinuxSetupSector->RamdiskSize));
+++++ DPRINTM(DPRINT_LINUX, "RamdiskAddress: 0x%x\n", LinuxSetupSector->RamdiskAddress);
+++++ DPRINTM(DPRINT_LINUX, "RamdiskSize: 0x%x\n", LinuxSetupSector->RamdiskSize);
if (LinuxSetupSector->Version >= 0x0203)
{
----- DbgPrint((DPRINT_LINUX, "InitrdAddressMax: 0x%x\n", LinuxSetupSector->InitrdAddressMax));
+++++ DPRINTM(DPRINT_LINUX, "InitrdAddressMax: 0x%x\n", LinuxSetupSector->InitrdAddressMax);
}
// Read in the ramdisk
ULONG Index;
#endif
----- DbgPrint((DPRINT_MEMORY, "Initializing Memory Manager.\n"));
+++++ DPRINTM(DPRINT_MEMORY, "Initializing Memory Manager.\n");
RtlZeroMemory(BiosMemoryMap, sizeof(BIOS_MEMORY_MAP) * 32);
// Dump the system memory map
if (BiosMemoryMapEntryCount != 0)
{
----- DbgPrint((DPRINT_MEMORY, "System Memory Map (Base Address, Length, Type):\n"));
+++++ DPRINTM(DPRINT_MEMORY, "System Memory Map (Base Address, Length, Type):\n");
for (Index=0; Index<BiosMemoryMapEntryCount; Index++)
{
----- DbgPrint((DPRINT_MEMORY, "%x%x\t %x%x\t %s\n", BiosMemoryMap[Index].BaseAddress, BiosMemoryMap[Index].Length, MmGetSystemMemoryMapTypeString(BiosMemoryMap[Index].Type)));
+++++ DPRINTM(DPRINT_MEMORY, "%x%x\t %x%x\t %s\n", BiosMemoryMap[Index].BaseAddress, BiosMemoryMap[Index].Length, MmGetSystemMemoryMapTypeString(BiosMemoryMap[Index].Type));
}
}
#endif
MmUpdateLastFreePageHint(PageLookupTableAddress, TotalPagesInLookupTable);
// Add machine-dependent stuff
-----#ifdef __i386__
+++++#if defined (__i386__) || defined (_M_AMD64)
MmMarkPagesInLookupTable(PageLookupTableAddress, 0x00, 1, LoaderFirmwarePermanent); // realmode int vectors
MmMarkPagesInLookupTable(PageLookupTableAddress, 0x01, 7, LoaderFirmwareTemporary); // freeldr stack + cmdline
MmMarkPagesInLookupTable(PageLookupTableAddress, 0x08, 0x70, LoaderLoadedProgram); // freeldr image (roughly max. 0x64 pages)
MmInitializeHeap(PageLookupTableAddress);
----- DbgPrint((DPRINT_MEMORY, "Memory Manager initialized. %d pages available.\n", FreePagesInLookupTable));
+++++ DPRINTM(DPRINT_MEMORY, "Memory Manager initialized. %d pages available.\n", FreePagesInLookupTable);
return TRUE;
}
// Mark those pages as used
MmMarkPagesInLookupTable(PageLookupTableAddress, HeapStart, PagesNeeded, LoaderOsloaderHeap);
----- DbgPrint((DPRINT_MEMORY, "Heap initialized, base 0x%08x, pages %d\n", (HeapStart << MM_PAGE_SHIFT), PagesNeeded));
+++++ DPRINTM(DPRINT_MEMORY, "Heap initialized, base 0x%08x, pages %d\n", (HeapStart << MM_PAGE_SHIFT), PagesNeeded);
}
#ifdef DBG
}
}
----- DbgPrint((DPRINT_MEMORY, "MmGetEndAddressOfAnyMemory() returning 0x%x\n", (ULONG)EndAddressOfMemory));
+++++ DPRINTM(DPRINT_MEMORY, "MmGetEndAddressOfAnyMemory() returning 0x%x\n", (ULONG)EndAddressOfMemory);
return (PVOID)(ULONG_PTR)EndAddressOfMemory;
}
{
EndAddress = 0x100000000LL;
----- DbgPrint((DPRINT_MEMORY, "MmGetEndAddressOfAnyMemory() returned 0xFFFFFFFF, correcting to be 0x100000000.\n"));
+++++ DPRINTM(DPRINT_MEMORY, "MmGetEndAddressOfAnyMemory() returned 0xFFFFFFFF, correcting to be 0x100000000.\n");
}
PageCount = (EndAddress / MM_PAGE_SIZE);
----- DbgPrint((DPRINT_MEMORY, "MmGetAddressablePageCountIncludingHoles() returning %d\n", PageCount));
+++++ DPRINTM(DPRINT_MEMORY, "MmGetAddressablePageCountIncludingHoles() returning %d\n", PageCount);
return PageCount;
}
}
}
----- DbgPrint((DPRINT_MEMORY, "MmFindLocationForPageLookupTable() returning 0x%x\n", PageLookupTableMemAddress));
+++++ DPRINTM(DPRINT_MEMORY, "MmFindLocationForPageLookupTable() returning 0x%x\n", PageLookupTableMemAddress);
return PageLookupTableMemAddress;
}
ULONG PageLookupTablePageCount;
ULONG Index;
----- DbgPrint((DPRINT_MEMORY, "MmInitPageLookupTable()\n"));
+++++ DPRINTM(DPRINT_MEMORY, "MmInitPageLookupTable()\n");
// Mark every page as allocated initially
// We will go through and mark pages again according to the memory map
default:
MemoryMapPageAllocated = LoaderSpecialMemory;
}
----- DbgPrint((DPRINT_MEMORY, "Marking pages as type %d: StartPage: %d PageCount: %d\n", MemoryMapPageAllocated, MemoryMapStartPage, MemoryMapPageCount));
+++++ DPRINTM(DPRINT_MEMORY, "Marking pages as type %d: StartPage: %d PageCount: %d\n", MemoryMapPageAllocated, MemoryMapStartPage, MemoryMapPageCount);
MmMarkPagesInLookupTable(PageLookupTable, MemoryMapStartPage, MemoryMapPageCount, MemoryMapPageAllocated);
}
// Mark the pages that the lookup table occupies as reserved
PageLookupTableStartPage = MmGetPageNumberFromAddress(PageLookupTable);
PageLookupTablePageCount = MmGetPageNumberFromAddress((PVOID)((ULONG_PTR)PageLookupTable + ROUND_UP(TotalPageCount * sizeof(PAGE_LOOKUP_TABLE_ITEM), MM_PAGE_SIZE))) - PageLookupTableStartPage;
----- DbgPrint((DPRINT_MEMORY, "Marking the page lookup table pages as reserved StartPage: %d PageCount: %d\n", PageLookupTableStartPage, PageLookupTablePageCount));
+++++ DPRINTM(DPRINT_MEMORY, "Marking the page lookup table pages as reserved StartPage: %d PageCount: %d\n", PageLookupTableStartPage, PageLookupTablePageCount);
MmMarkPagesInLookupTable(PageLookupTable, PageLookupTableStartPage, PageLookupTablePageCount, LoaderFirmwareTemporary);
}
#if 0
if ((Index <= (StartPage + 16)) || (Index >= (StartPage+PageCount-16)))
{
----- DbgPrint((DPRINT_MEMORY, "Index = %d StartPage = %d PageCount = %d\n", Index, StartPage, PageCount));
+++++ DPRINTM(DPRINT_MEMORY, "Index = %d StartPage = %d PageCount = %d\n", Index, StartPage, PageCount);
}
#endif
RealPageLookupTable[Index].PageAllocated = PageAllocated;
RealPageLookupTable[Index].PageAllocationLength = (PageAllocated != LoaderFree) ? 1 : 0;
}
----- DbgPrint((DPRINT_MEMORY, "MmMarkPagesInLookupTable() Done\n"));
+++++ DPRINTM(DPRINT_MEMORY, "MmMarkPagesInLookupTable() Done\n");
}
VOID MmAllocatePagesInLookupTable(PVOID PageLookupTable, ULONG StartPage, ULONG PageCount, TYPE_OF_MEMORY MemoryType)
}
else
{
----- DbgPrint((DPRINT_MEMORY, "Alloc low memory, LastFreePageHint %d, TPC %d\n", LastFreePageHint, TotalPageCount));
+++++ DPRINTM(DPRINT_MEMORY, "Alloc low memory, LastFreePageHint %d, TPC %d\n", LastFreePageHint, TotalPageCount);
/* Allocate "low" pages */
for (Index=1; Index < LastFreePageHint; Index++)
{
if (MemorySize == 0)
{
----- DbgPrint((DPRINT_MEMORY, "MmAllocateMemory() called for 0 bytes. Returning NULL.\n"));
+++++ DPRINTM(DPRINT_MEMORY, "MmAllocateMemory() called for 0 bytes. Returning NULL.\n");
UiMessageBoxCritical("Memory allocation failed: MmAllocateMemory() called for 0 bytes.");
return NULL;
}
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
----- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
if (FirstFreePageFromEnd == 0)
{
----- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemory(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
MemPointer = (PVOID)((ULONG_PTR)FirstFreePageFromEnd * MM_PAGE_SIZE);
#ifdef DBG
----- DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd));
----- DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
+++++ DPRINTM(DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd);
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer);
#endif // DBG
// Update LoaderPagesSpanned count
if (MemorySize > MM_PAGE_SIZE)
{
----- DbgPrint((DPRINT_MEMORY, "Consider using other functions to allocate %d bytes of memory!\n", MemorySize));
+++++ DPRINTM(DPRINT_MEMORY, "Consider using other functions to allocate %d bytes of memory!\n", MemorySize);
}
// Get the buffer from BGET pool
if (Result == NULL)
{
----- DbgPrint((DPRINT_MEMORY, "Heap allocation for %d bytes failed\n", MemorySize));
+++++ DPRINTM(DPRINT_MEMORY, "Heap allocation for %d bytes failed\n", MemorySize);
}
// Gather some stats
bstats(&CurAlloc, &TotalFree, &MaxFree, &NumberOfGets, &NumberOfRels);
----- DbgPrint((DPRINT_MEMORY, "Current alloced %d bytes, free %d bytes, allocs %d, frees %d\n",
----- CurAlloc, TotalFree, NumberOfGets, NumberOfRels));
+++++ DPRINTM(DPRINT_MEMORY, "Current alloced %d bytes, free %d bytes, allocs %d, frees %d\n",
+++++ CurAlloc, TotalFree, NumberOfGets, NumberOfRels);
return Result;
}
if (MemorySize == 0)
{
----- DbgPrint((DPRINT_MEMORY, "MmAllocateMemoryAtAddress() called for 0 bytes. Returning NULL.\n"));
+++++ DPRINTM(DPRINT_MEMORY, "MmAllocateMemoryAtAddress() called for 0 bytes. Returning NULL.\n");
UiMessageBoxCritical("Memory allocation failed: MmAllocateMemoryAtAddress() called for 0 bytes.");
return NULL;
}
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
----- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
"Not enough free memory to allocate %d bytes (requesting %d pages but have only %d). "
----- "\n", MemorySize, PagesNeeded, FreePagesInLookupTable));
+++++ "\n", MemorySize, PagesNeeded, FreePagesInLookupTable);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
if (MmAreMemoryPagesAvailable(PageLookupTableAddress, TotalPagesInLookupTable, DesiredAddress, PagesNeeded) == FALSE)
{
----- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateMemoryAtAddress(). "
"Not enough free memory to allocate %d bytes at address %p.\n",
----- MemorySize, DesiredAddress));
+++++ MemorySize, DesiredAddress);
// Don't tell this to user since caller should try to alloc this memory
// at a different address
MemPointer = (PVOID)((ULONG_PTR)StartPageNumber * MM_PAGE_SIZE);
#ifdef DBG
----- DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, StartPageNumber));
----- DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
+++++ DPRINTM(DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, StartPageNumber);
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer);
#endif // DBG
// Update LoaderPagesSpanned count
if (MemorySize == 0)
{
----- DbgPrint((DPRINT_MEMORY, "MmAllocateHighestMemoryBelowAddress() called for 0 bytes. Returning NULL.\n"));
+++++ DPRINTM(DPRINT_MEMORY, "MmAllocateHighestMemoryBelowAddress() called for 0 bytes. Returning NULL.\n");
UiMessageBoxCritical("Memory allocation failed: MmAllocateHighestMemoryBelowAddress() called for 0 bytes.");
return NULL;
}
// then return NULL
if (FreePagesInLookupTable < PagesNeeded)
{
----- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
if (FirstFreePageFromEnd == 0)
{
----- DbgPrint((DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize));
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n", MemorySize);
UiMessageBoxCritical("Memory allocation failed: out of memory.");
return NULL;
}
MemPointer = (PVOID)((ULONG_PTR)FirstFreePageFromEnd * MM_PAGE_SIZE);
#ifdef DBG
----- DbgPrint((DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd));
----- DbgPrint((DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer));
+++++ DPRINTM(DPRINT_MEMORY, "Allocated %d bytes (%d pages) of memory starting at page %d.\n", MemorySize, PagesNeeded, FirstFreePageFromEnd);
+++++ DPRINTM(DPRINT_MEMORY, "Memory allocation pointer: 0x%x\n", MemPointer);
#endif // DBG
// Update LoaderPagesSpanned count
ULONG Idx;
PPAGE_LOOKUP_TABLE_ITEM RealPageLookupTable = (PPAGE_LOOKUP_TABLE_ITEM)PageLookupTableAddress;
----- DbgPrint((DPRINT_MEMORY, "----------- Memory Allocation Bitmap -----------\n"));
+++++ DPRINTM(DPRINT_MEMORY, "----------- Memory Allocation Bitmap -----------\n");
for (Idx=0; Idx<TotalPagesInLookupTable; Idx++)
{
if ((Idx % 32) == 0)
{
----- DbgPrint((DPRINT_MEMORY, "\n"));
----- DbgPrint((DPRINT_MEMORY, "%08x:\t", (Idx * MM_PAGE_SIZE)));
+++++ DPRINTM(DPRINT_MEMORY, "\n");
+++++ DPRINTM(DPRINT_MEMORY, "%08x:\t", (Idx * MM_PAGE_SIZE));
}
else if ((Idx % 4) == 0)
{
----- DbgPrint((DPRINT_MEMORY, " "));
+++++ DPRINTM(DPRINT_MEMORY, " ");
}
switch (RealPageLookupTable[Idx].PageAllocated)
{
case LoaderFree:
----- DbgPrint((DPRINT_MEMORY, "*"));
+++++ DPRINTM(DPRINT_MEMORY, "*");
break;
case LoaderBad:
----- DbgPrint((DPRINT_MEMORY, "-"));
+++++ DPRINTM(DPRINT_MEMORY, "-");
break;
case LoaderLoadedProgram:
----- DbgPrint((DPRINT_MEMORY, "O"));
+++++ DPRINTM(DPRINT_MEMORY, "O");
break;
case LoaderFirmwareTemporary:
----- DbgPrint((DPRINT_MEMORY, "T"));
+++++ DPRINTM(DPRINT_MEMORY, "T");
break;
case LoaderFirmwarePermanent:
----- DbgPrint((DPRINT_MEMORY, "P"));
+++++ DPRINTM(DPRINT_MEMORY, "P");
break;
case LoaderOsloaderHeap:
----- DbgPrint((DPRINT_MEMORY, "H"));
+++++ DPRINTM(DPRINT_MEMORY, "H");
break;
case LoaderOsloaderStack:
----- DbgPrint((DPRINT_MEMORY, "S"));
+++++ DPRINTM(DPRINT_MEMORY, "S");
break;
case LoaderSystemCode:
----- DbgPrint((DPRINT_MEMORY, "K"));
+++++ DPRINTM(DPRINT_MEMORY, "K");
break;
case LoaderHalCode:
----- DbgPrint((DPRINT_MEMORY, "L"));
+++++ DPRINTM(DPRINT_MEMORY, "L");
break;
case LoaderBootDriver:
----- DbgPrint((DPRINT_MEMORY, "B"));
+++++ DPRINTM(DPRINT_MEMORY, "B");
break;
case LoaderStartupPcrPage:
----- DbgPrint((DPRINT_MEMORY, "G"));
+++++ DPRINTM(DPRINT_MEMORY, "G");
break;
case LoaderRegistryData:
----- DbgPrint((DPRINT_MEMORY, "R"));
+++++ DPRINTM(DPRINT_MEMORY, "R");
break;
case LoaderMemoryData:
----- DbgPrint((DPRINT_MEMORY, "M"));
+++++ DPRINTM(DPRINT_MEMORY, "M");
break;
case LoaderNlsData:
----- DbgPrint((DPRINT_MEMORY, "N"));
+++++ DPRINTM(DPRINT_MEMORY, "N");
break;
case LoaderSpecialMemory:
----- DbgPrint((DPRINT_MEMORY, "C"));
+++++ DPRINTM(DPRINT_MEMORY, "C");
break;
default:
----- DbgPrint((DPRINT_MEMORY, "?"));
+++++ DPRINTM(DPRINT_MEMORY, "?");
break;
}
}
----- DbgPrint((DPRINT_MEMORY, "\n"));
+++++ DPRINTM(DPRINT_MEMORY, "\n");
}
#endif // DBG
if (ValueCell->Signature != CM_KEY_VALUE_SIGNATURE)
{
----- DbgPrint((DPRINT_REGISTRY, "Invalid key cell!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "Invalid key cell!\n");
return FALSE;
}
DataLength = ValueCell->DataLength & REG_DATA_SIZE_MASK;
----- DbgPrint((DPRINT_REGISTRY, "ValueName: '%S'\n", wName));
----- DbgPrint((DPRINT_REGISTRY, "DataLength: %u\n", DataLength));
+++++ DPRINTM(DPRINT_REGISTRY, "ValueName: '%S'\n", wName);
+++++ DPRINTM(DPRINT_REGISTRY, "DataLength: %u\n", DataLength);
if (DataLength <= sizeof(HCELL_INDEX) && (ValueCell->DataLength & REG_DATA_IN_OFFSET))
{
DataLength);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegSetValue() failed!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "RegSetValue() failed!\n");
MmHeapFree (wName);
return FALSE;
}
else
{
DataCell = (PVOID)HvGetCell (Hive, ValueCell->Data);
----- DbgPrint((DPRINT_REGISTRY, "DataCell: %x\n", DataCell));
+++++ DPRINTM(DPRINT_REGISTRY, "DataCell: %x\n", DataCell);
Error = RegSetValue (Key,
wName,
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegSetValue() failed!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "RegSetValue() failed!\n");
MmHeapFree (wName);
return FALSE;
}
{
ULONG i;
----- DbgPrint((DPRINT_REGISTRY, "IndexCell: %x\n", IndexCell));
+++++ DPRINTM(DPRINT_REGISTRY, "IndexCell: %x\n", IndexCell);
/* Enumerate and add subkeys */
if (IndexCell->Signature == CM_KEY_INDEX_ROOT ||
ULONG i;
----- DbgPrint((DPRINT_REGISTRY, "KeyCell: %x\n", KeyCell));
----- DbgPrint((DPRINT_REGISTRY, "KeyCell->Signature: %x\n", KeyCell->Signature));
+++++ DPRINTM(DPRINT_REGISTRY, "KeyCell: %x\n", KeyCell);
+++++ DPRINTM(DPRINT_REGISTRY, "KeyCell->Signature: %x\n", KeyCell->Signature);
if (KeyCell->Signature != CM_KEY_NODE_SIGNATURE)
{
----- DbgPrint((DPRINT_REGISTRY, "Invalid key cell Signature!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "Invalid key cell Signature!\n");
return FALSE;
}
wName[KeyCell->NameLength/sizeof(WCHAR)] = 0;
}
----- DbgPrint((DPRINT_REGISTRY, "KeyName: '%S'\n", wName));
+++++ DPRINTM(DPRINT_REGISTRY, "KeyName: '%S'\n", wName);
/* Create new sub key */
Error = RegCreateKey (ParentKey,
MmHeapFree (wName);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegCreateKey() failed!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "RegCreateKey() failed!\n");
return FALSE;
}
----- DbgPrint((DPRINT_REGISTRY, "Subkeys: %u\n", KeyCell->SubKeyCounts));
----- DbgPrint((DPRINT_REGISTRY, "Values: %u\n", KeyCell->ValueList.Count));
+++++ DPRINTM(DPRINT_REGISTRY, "Subkeys: %u\n", KeyCell->SubKeyCounts);
+++++ DPRINTM(DPRINT_REGISTRY, "Values: %u\n", KeyCell->ValueList.Count);
/* Enumerate and add values */
if (KeyCell->ValueList.Count > 0)
{
ValueListCell = (PVALUE_LIST_CELL) HvGetCell (Hive, KeyCell->ValueList.List);
----- DbgPrint((DPRINT_REGISTRY, "ValueListCell: %x\n", ValueListCell));
+++++ DPRINTM(DPRINT_REGISTRY, "ValueListCell: %x\n", ValueListCell);
for (i = 0; i < KeyCell->ValueList.Count; i++)
{
----- DbgPrint((DPRINT_REGISTRY, "ValueOffset[%d]: %x\n", i, ValueListCell->ValueOffset[i]));
+++++ DPRINTM(DPRINT_REGISTRY, "ValueOffset[%d]: %x\n", i, ValueListCell->ValueOffset[i]);
ValueCell = (PCM_KEY_VALUE) HvGetCell (Hive, ValueListCell->ValueOffset[i]);
----- DbgPrint((DPRINT_REGISTRY, "ValueCell[%d]: %x\n", i, ValueCell));
+++++ DPRINTM(DPRINT_REGISTRY, "ValueCell[%d]: %x\n", i, ValueCell);
if (!RegImportValue(Hive, ValueCell, SubKey))
return FALSE;
PHHIVE Hive;
NTSTATUS Status;
----- DbgPrint((DPRINT_REGISTRY, "RegImportBinaryHive(%x, %u) called\n",ChunkBase,ChunkSize));
+++++ DPRINTM(DPRINT_REGISTRY, "RegImportBinaryHive(%x, %u) called\n",ChunkBase,ChunkSize);
CmHive = CmpAllocate(sizeof(CMHIVE), TRUE, 0);
Status = HvInitialize (&CmHive->Hive,
NULL);
if (!NT_SUCCESS(Status))
{
---- DbgPrint((DPRINT_REGISTRY, "Invalid hive Signature!\n"));
++++ CmpFree(CmHive, 0);
- DbgPrint((DPRINT_REGISTRY, "Invalid hive Signature!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "Invalid hive Signature!\n");
return FALSE;
}
Hive = &CmHive->Hive;
KeyCell = (PCM_KEY_NODE)HvGetCell (Hive, Hive->BaseBlock->RootCell);
----- DbgPrint((DPRINT_REGISTRY, "KeyCell: %x\n", KeyCell));
----- DbgPrint((DPRINT_REGISTRY, "KeyCell->Signature: %x\n", KeyCell->Signature));
+++++ DPRINTM(DPRINT_REGISTRY, "KeyCell: %x\n", KeyCell);
+++++ DPRINTM(DPRINT_REGISTRY, "KeyCell->Signature: %x\n", KeyCell->Signature);
if (KeyCell->Signature != CM_KEY_NODE_SIGNATURE)
{
----- DbgPrint((DPRINT_REGISTRY, "Invalid key cell Signature!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "Invalid key cell Signature!\n");
return FALSE;
}
----- DbgPrint((DPRINT_REGISTRY, "Subkeys: %u\n", KeyCell->SubKeyCounts));
----- DbgPrint((DPRINT_REGISTRY, "Values: %u\n", KeyCell->ValueList.Count));
+++++ DPRINTM(DPRINT_REGISTRY, "Subkeys: %u\n", KeyCell->SubKeyCounts);
+++++ DPRINTM(DPRINT_REGISTRY, "Values: %u\n", KeyCell->ValueList.Count);
/* Open 'System' key */
Error = RegOpenKey(NULL,
&SystemKey);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "Failed to open 'system' key!\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "Failed to open 'system' key!\n");
return FALSE;
}
if (KeyCell->SubKeyCounts[Stable] > 0)
{
HashCell = (PCM_KEY_FAST_INDEX)HvGetCell (Hive, KeyCell->SubKeyLists[Stable]);
----- DbgPrint((DPRINT_REGISTRY, "HashCell: %x\n", HashCell));
----- DbgPrint((DPRINT_REGISTRY, "SubKeyCounts: %x\n", KeyCell->SubKeyCounts[Stable]));
+++++ DPRINTM(DPRINT_REGISTRY, "HashCell: %x\n", HashCell);
+++++ DPRINTM(DPRINT_REGISTRY, "SubKeyCounts: %x\n", KeyCell->SubKeyCounts[Stable]);
for (i = 0; i < KeyCell->SubKeyCounts[Stable]; i++)
{
----- DbgPrint((DPRINT_REGISTRY, "Cell[%d]: %x\n", i, HashCell->List[i].Cell));
+++++ DPRINTM(DPRINT_REGISTRY, "Cell[%d]: %x\n", i, HashCell->List[i].Cell);
SubKeyCell = (PCM_KEY_NODE)HvGetCell (Hive, HashCell->List[i].Cell);
----- DbgPrint((DPRINT_REGISTRY, "SubKeyCell[%d]: %x\n", i, SubKeyCell));
+++++ DPRINTM(DPRINT_REGISTRY, "SubKeyCell[%d]: %x\n", i, SubKeyCell);
if (!RegImportSubKey(Hive, SubKeyCell, SystemKey))
return FALSE;
#include <freeldr.h>
#include <debug.h>
-----#undef DbgPrint
extern BOOLEAN FrLdrBootType;
PIMAGE_NT_HEADERS NtHeader;
PIMAGE_SECTION_HEADER Section;
NTSTATUS Status = STATUS_SUCCESS;
+++++ PLOADER_MODULE pModule;
/* Try to see, maybe it's loaded already */
----- if (LdrGetModuleObject(Name) != NULL)
+++++ if ((pModule = LdrGetModuleObject(Name)) != NULL)
{
----- /* It's loaded, return NULL. It would be wise to return
----- correct LoadBase, but it seems to be ignored almost everywhere */
----- return NULL;
+++++ /* It's loaded, return LoadBase */
+++++ ImageBase = (PVOID)pModule->ModStart;
+++++ LoadBase = RVA(ImageBase, -KSEG0_BASE);
+++++ return LoadBase;
}
/* Set the virtual (image) and physical (load) addresses */
Section[i].Misc.VirtualSize);
}
}
+++++ else
+++++ {
+++++ DbgPrint("Section %s in %s doesn't fit: VA: %lx, Size: %lx\n",
+++++ Section[i].Name, Name, Section[i].VirtualAddress,
+++++ Section[i].Misc.VirtualSize);
+++++ }
}
/* Calculate Difference between Real Base and Compiled Base*/
(ULONG_PTR)LoadBase,
"FreeLdr",
STATUS_SUCCESS,
+++++#ifdef _M_AMD64
+++++ STATUS_SUCCESS, // allow stripped files
+++++#else
STATUS_UNSUCCESSFUL,
+++++#endif
STATUS_UNSUCCESSFUL);
if (!NT_SUCCESS(Status))
{
/* load ANSI codepage table */
sprintf(szFileName,"%ssystem32\\%S", szSystemRoot, szNameBuffer);
----- DbgPrint((DPRINT_REACTOS, "ANSI file: %s\n", szFileName));
+++++ DPRINTM(DPRINT_REACTOS, "ANSI file: %s\n", szFileName);
if (!FrLdrLoadNlsFile(szFileName, "ansi.nls")) {
strcpy(szErrorOut, "Couldn't load ansi.nls");
/* load OEM codepage table */
sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
----- DbgPrint((DPRINT_REACTOS, "Oem file: %s\n", szFileName));
+++++ DPRINTM(DPRINT_REACTOS, "Oem file: %s\n", szFileName);
if (!FrLdrLoadNlsFile(szFileName, "oem.nls")) {
strcpy(szErrorOut, "Couldn't load oem.nls");
/* load Unicode case table */
sprintf(szFileName, "%ssystem32\\%S", szSystemRoot, szNameBuffer);
----- DbgPrint((DPRINT_REACTOS, "Casemap file: %s\n", szFileName));
+++++ DPRINTM(DPRINT_REACTOS, "Casemap file: %s\n", szFileName);
if (!FrLdrLoadNlsFile(szFileName, "casemap.nls")) {
strcpy(szErrorOut, "casemap.nls");
&hGroupKey);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc);
return;
}
&hOrderKey);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc);
return;
}
&hServiceKey);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc);
return;
}
/* Get the Name Group */
BufferSize = sizeof(GroupNameBuffer);
rc = RegQueryValue(hGroupKey, L"List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize);
----- DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc);
if (rc != ERROR_SUCCESS) return;
----- DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
----- DbgPrint((DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer));
+++++ DPRINTM(DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize);
+++++ DPRINTM(DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer);
/* Loop through each group */
GroupName = GroupNameBuffer;
while (*GroupName) {
----- DbgPrint((DPRINT_REACTOS, "Driver group: '%S'\n", GroupName));
+++++ DPRINTM(DPRINT_REACTOS, "Driver group: '%S'\n", GroupName);
/* Query the Order */
BufferSize = sizeof(OrderList);
/* Get the Driver's Name */
ValueSize = sizeof(ServiceName);
rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
----- DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc);
/* Makre sure it's valid, and check if we're done */
if (rc == ERROR_NO_MORE_ITEMS) break;
if (rc != ERROR_SUCCESS) return;
----- DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+++++ DPRINTM(DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
/* open driver Key */
rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
----- DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
+++++ DPRINTM(DPRINT_REACTOS, " Start: %x \n", (int)StartValue);
/* Read the Tag */
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
----- DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
+++++ DPRINTM(DPRINT_REACTOS, " Tag: %x \n", (int)TagValue);
/* Read the driver's group */
DriverGroupSize = sizeof(DriverGroup);
rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
----- DbgPrint((DPRINT_REACTOS, " Group: '%S' \n", DriverGroup));
+++++ DPRINTM(DPRINT_REACTOS, " Group: '%S' \n", DriverGroup);
/* Make sure it should be started */
if ((StartValue == 0) &&
/* Write the whole path if it suceeded, else prepare to fail */
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: not found\n");
sprintf(ImagePath, "%s\\system32\\drivers\\%S.sys", szSystemRoot, ServiceName);
} else if (TempImagePath[0] != L'\\') {
sprintf(ImagePath, "%s%S", szSystemRoot, TempImagePath);
} else {
sprintf(ImagePath, "%S", TempImagePath);
----- DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath);
}
----- DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath);
/* Update the position if needed */
if (nPos < 100) nPos += 5;
} else {
----- DbgPrint((DPRINT_REACTOS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
----- ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName));
+++++ DPRINTM(DPRINT_REACTOS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
+++++ ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName);
}
}
ValueSize = sizeof(ServiceName);
rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
----- DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc);
if (rc == ERROR_NO_MORE_ITEMS) break;
if (rc != ERROR_SUCCESS) return;
----- DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+++++ DPRINTM(DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
/* open driver Key */
rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
----- DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
+++++ DPRINTM(DPRINT_REACTOS, " Start: %x \n", (int)StartValue);
/* Read the Tag */
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
----- DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
+++++ DPRINTM(DPRINT_REACTOS, " Tag: %x \n", (int)TagValue);
/* Read the driver's group */
DriverGroupSize = sizeof(DriverGroup);
rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
----- DbgPrint((DPRINT_REACTOS, " Group: '%S' \n", DriverGroup));
+++++ DPRINTM(DPRINT_REACTOS, " Group: '%S' \n", DriverGroup);
for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
if (TagValue == OrderList[TagIndex]) break;
ValueSize = sizeof(TempImagePath);
rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: not found\n");
sprintf(ImagePath, "%ssystem32\\drivers\\%S.sys", szSystemRoot, ServiceName);
} else if (TempImagePath[0] != L'\\') {
sprintf(ImagePath, "%s%S", szSystemRoot, TempImagePath);
} else {
sprintf(ImagePath, "%S", TempImagePath);
----- DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath);
}
----- DbgPrint((DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_REACTOS, " Loading driver: '%s'\n", ImagePath);
if (nPos < 100) nPos += 5;
} else {
----- DbgPrint((DPRINT_REACTOS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
----- ServiceName, StartValue, TagValue, DriverGroup, GroupName));
+++++ DPRINTM(DPRINT_REACTOS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
+++++ ServiceName, StartValue, TagValue, DriverGroup, GroupName);
}
}
LoaderBlock.DrivesCount = reactos_disk_count;
---- UiDrawStatusText("Loading...");
++++ UiDrawStatusText("Loading...");
---- //
---- // If we have a ramdisk, this will switch to the ramdisk disk routines
---- // which read from memory instead of using the firmware. This has to be done
---- // after hardware detection, since hardware detection will require using the
---- // real routines in order to perform disk-detection (just because we're on a
---- // ram-boot doesn't mean the user doesn't have actual disks installed too!)
---- //
---- RamDiskSwitchFromBios();
++++ //
++++ // If we have a ramdisk, this will switch to the ramdisk disk routines
++++ // which read from memory instead of using the firmware. This has to be done
++++ // after hardware detection, since hardware detection will require using the
++++ // real routines in order to perform disk-detection (just because we're on a
++++ // ram-boot doesn't mean the user doesn't have actual disks installed too!)
++++ //
++++ RamDiskSwitchFromBios();
---- /*
---- * Try to open system drive
---- */
---- if (!FsOpenSystemVolume(SystemPath, szBootPath, &LoaderBlock.BootDevice))
---- {
---- UiMessageBox("Failed to open system drive.");
---- return;
---- }
++++ /*
++++ * Try to open system drive
++++ */
++++ if (!FsOpenSystemVolume(SystemPath, szBootPath, &LoaderBlock.BootDevice))
++++ {
++++ UiMessageBox("Failed to open system drive.");
++++ return;
++++ }
---- /* append a backslash */
---- if ((strlen(szBootPath)==0) ||
---- szBootPath[strlen(szBootPath)] != '\\')
---- strcat(szBootPath, "\\");
++++ /* append a backslash */
++++ if ((strlen(szBootPath)==0) ||
++++ szBootPath[strlen(szBootPath)] != '\\')
++++ strcat(szBootPath, "\\");
- DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
- strcpy(SystemRoot, szBootPath);
---- DbgPrint((DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath));
+++++ DPRINTM(DPRINT_REACTOS,"SystemRoot: '%s'\n", szBootPath);
+ strcpy(SystemRoot, szBootPath);
---- /*
---- * Find the kernel image name
---- * and try to load the kernel off the disk
---- */
---- if(IniReadSettingByName(SectionId, "Kernel", value, sizeof(value)))
---- {
---- /*
---- * Set the name and
---- */
---- if (value[0] == '\\')
---- {
---- strcpy(szKernelName, value);
---- }
---- else
---- {
---- strcpy(szKernelName, szBootPath);
---- strcat(szKernelName, "SYSTEM32\\");
---- strcat(szKernelName, value);
---- }
---- }
---- else
---- {
---- strcpy(value, "NTOSKRNL.EXE");
---- strcpy(szKernelName, szBootPath);
---- strcat(szKernelName, "SYSTEM32\\");
---- strcat(szKernelName, value);
---- }
++++ /*
++++ * Find the kernel image name
++++ * and try to load the kernel off the disk
++++ */
++++ if(IniReadSettingByName(SectionId, "Kernel", value, sizeof(value)))
++++ {
++++ /*
++++ * Set the name and
++++ */
++++ if (value[0] == '\\')
++++ {
++++ strcpy(szKernelName, value);
++++ }
++++ else
++++ {
++++ strcpy(szKernelName, szBootPath);
++++ strcat(szKernelName, "SYSTEM32\\");
++++ strcat(szKernelName, value);
++++ }
++++ }
++++ else
++++ {
++++ strcpy(value, "NTOSKRNL.EXE");
++++ strcpy(szKernelName, szBootPath);
++++ strcat(szKernelName, "SYSTEM32\\");
++++ strcat(szKernelName, value);
++++ }
---- /*
---- * Find the HAL image name
---- * and try to load the kernel off the disk
---- */
---- if(IniReadSettingByName(SectionId, "Hal", value, sizeof(value)))
---- {
---- /*
---- * Set the name and
---- */
---- if (value[0] == '\\')
---- {
---- strcpy(szHalName, value);
---- }
---- else
---- {
---- strcpy(szHalName, szBootPath);
---- strcat(szHalName, "SYSTEM32\\");
---- strcat(szHalName, value);
---- }
---- }
---- else
---- {
---- strcpy(value, "HAL.DLL");
---- strcpy(szHalName, szBootPath);
---- strcat(szHalName, "SYSTEM32\\");
---- strcat(szHalName, value);
---- }
++++ /*
++++ * Find the HAL image name
++++ * and try to load the kernel off the disk
++++ */
++++ if(IniReadSettingByName(SectionId, "Hal", value, sizeof(value)))
++++ {
++++ /*
++++ * Set the name and
++++ */
++++ if (value[0] == '\\')
++++ {
++++ strcpy(szHalName, value);
++++ }
++++ else
++++ {
++++ strcpy(szHalName, szBootPath);
++++ strcat(szHalName, "SYSTEM32\\");
++++ strcat(szHalName, value);
++++ }
++++ }
++++ else
++++ {
++++ strcpy(value, "HAL.DLL");
++++ strcpy(szHalName, szBootPath);
++++ strcat(szHalName, "SYSTEM32\\");
++++ strcat(szHalName, value);
++++ }
---- /* Load the kernel */
---- LoadBase = FrLdrLoadImage(szKernelName, 5, 1);
---- if (!LoadBase) return;
++++ /* Load the kernel */
++++ LoadBase = FrLdrLoadImage(szKernelName, 5, 1);
++++ if (!LoadBase) return;
---- /* Get the NT header, kernel base and kernel entry */
---- NtHeader = RtlImageNtHeader(LoadBase);
---- KernelBase = SWAPD(NtHeader->OptionalHeader.ImageBase);
---- KernelEntryPoint = (ROS_KERNEL_ENTRY_POINT)(KernelBase + SWAPD(NtHeader->OptionalHeader.AddressOfEntryPoint));
---- LoaderBlock.KernelBase = KernelBase;
++++ /* Get the NT header, kernel base and kernel entry */
++++ NtHeader = RtlImageNtHeader(LoadBase);
++++ KernelBase = SWAPD(NtHeader->OptionalHeader.ImageBase);
++++ KernelEntryPoint = (ROS_KERNEL_ENTRY_POINT)(KernelBase + SWAPD(NtHeader->OptionalHeader.AddressOfEntryPoint));
++++ LoaderBlock.KernelBase = KernelBase;
---- /*
---- * Load the System hive from disk
---- */
---- strcpy(szFileName, szBootPath);
---- strcat(szFileName, "SYSTEM32\\CONFIG\\SYSTEM");
++++ /*
++++ * Load the System hive from disk
++++ */
++++ strcpy(szFileName, szBootPath);
++++ strcat(szFileName, "SYSTEM32\\CONFIG\\SYSTEM");
- DbgPrint((DPRINT_REACTOS, "SystemHive: '%s'", szFileName));
---- DbgPrint((DPRINT_REACTOS, "SystemHive: '%s'", szFileName));
+++++ DPRINTM(DPRINT_REACTOS, "SystemHive: '%s'", szFileName);
---- FilePointer = FsOpenFile(szFileName);
---- if (FilePointer == NULL)
---- {
---- UiMessageBox("Could not find the System hive!");
---- return;
---- }
++++ FilePointer = FsOpenFile(szFileName);
++++ if (FilePointer == NULL)
++++ {
++++ UiMessageBox("Could not find the System hive!");
++++ return;
++++ }
---- /*
---- * Update the status bar with the current file
---- */
---- strcpy(name, "Reading ");
---- strcat(name, value);
---- while (strlen(name) < 80)
---- strcat(name, " ");
---- UiDrawStatusText(name);
++++ /*
++++ * Update the status bar with the current file
++++ */
++++ strcpy(name, "Reading ");
++++ strcat(name, value);
++++ while (strlen(name) < 80)
++++ strcat(name, " ");
++++ UiDrawStatusText(name);
- /*
- * Load the System hive
- */
- Base = FrLdrLoadModule(FilePointer, szFileName, &Size);
- if (Base == 0 || Size == 0)
- {
- UiMessageBox("Could not load the System hive!\n");
- return;
- }
- DbgPrint((DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size));
+ /*
+ * Load the System hive
+ */
+ Base = FrLdrLoadModule(FilePointer, szFileName, &Size);
+ if (Base == 0 || Size == 0)
+ {
+ UiMessageBox("Could not load the System hive!\n");
+ return;
+ }
---- DbgPrint((DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size));
+++++ DPRINTM(DPRINT_REACTOS, "SystemHive loaded at 0x%x size %u", (unsigned)Base, (unsigned)Size);
---- /*
---- * Import the loaded system hive
---- */
---- RegImportBinaryHive((PCHAR)Base, Size);
++++ /*
++++ * Import the loaded system hive
++++ */
++++ RegImportBinaryHive((PCHAR)Base, Size);
---- /*
---- * Initialize the 'CurrentControlSet' link
---- */
---- RegInitCurrentControlSet(FALSE);
++++ /*
++++ * Initialize the 'CurrentControlSet' link
++++ */
++++ RegInitCurrentControlSet(FALSE);
---- UiDrawProgressBarCenter(15, 100, szLoadingMsg);
++++ UiDrawProgressBarCenter(15, 100, szLoadingMsg);
---- UiDrawProgressBarCenter(20, 100, szLoadingMsg);
++++ UiDrawProgressBarCenter(20, 100, szLoadingMsg);
---- /*
---- * Load NLS files
---- */
---- if (!FrLdrLoadNlsFiles(szBootPath, MsgBuffer))
---- {
---- UiMessageBox(MsgBuffer);
---- return;
---- }
---- UiDrawProgressBarCenter(30, 100, szLoadingMsg);
++++ /*
++++ * Load NLS files
++++ */
++++ if (!FrLdrLoadNlsFiles(szBootPath, MsgBuffer))
++++ {
++++ UiMessageBox(MsgBuffer);
++++ return;
++++ }
++++ UiDrawProgressBarCenter(30, 100, szLoadingMsg);
---- /*
---- * Load boot drivers
---- */
---- FrLdrLoadBootDrivers(szBootPath, 40);
---- //UiUnInitialize("Booting ReactOS...");
++++ /*
++++ * Load boot drivers
++++ */
++++ FrLdrLoadBootDrivers(szBootPath, 40);
++++ //UiUnInitialize("Booting ReactOS...");
//
// Perform architecture-specific pre-boot configuration
//
// Setup paging and jump to kernel
//
---- FrLdrStartup(0x2badb002);
----}
----
----#undef DbgPrint
----ULONG
----DbgPrint(const char *Format, ...)
----{
---- va_list ap;
---- CHAR Buffer[512];
---- ULONG Length;
----
---- va_start(ap, Format);
----
---- /* Construct a string */
---- Length = _vsnprintf(Buffer, 512, Format, ap);
----
---- /* Check if we went past the buffer */
---- if (Length == -1)
---- {
---- /* Terminate it if we went over-board */
---- Buffer[sizeof(Buffer) - 1] = '\n';
----
---- /* Put maximum */
---- Length = sizeof(Buffer);
---- }
----
---- /* Show it as a message box */
---- UiMessageBox(Buffer);
----
---- /* Cleanup and exit */
---- va_end(ap);
---- return 0;
++++ FrLdrStartup(0x2badb002);
}
- #undef DbgPrint
- ULONG
- DbgPrint(const char *Format, ...)
- {
- va_list ap;
- CHAR Buffer[512];
- ULONG Length;
-
- va_start(ap, Format);
-
- /* Construct a string */
- Length = _vsnprintf(Buffer, 512, Format, ap);
-
- /* Check if we went past the buffer */
- if (Length == -1U)
- {
- /* Terminate it if we went over-board */
- Buffer[sizeof(Buffer) - 1] = '\n';
-
- /* Put maximum */
- Length = sizeof(Buffer);
- }
-
- /* Show it as a message box */
- UiMessageBox(Buffer);
-
- /* Cleanup and exit */
- va_end(ap);
- return 0;
- }
-
/* EOF */
&SelectKey);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegOpenKey() failed (Error %u)\n", (int)Error));
+++++ DPRINTM(DPRINT_REGISTRY, "RegOpenKey() failed (Error %u)\n", (int)Error);
return(Error);
}
&DataSize);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error));
+++++ DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error);
return(Error);
}
&DataSize);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error));
+++++ DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error);
return(Error);
}
&SystemKey);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegOpenKey(SystemKey) failed (Error %u)\n", (int)Error));
+++++ DPRINTM(DPRINT_REGISTRY, "RegOpenKey(SystemKey) failed (Error %u)\n", (int)Error);
return(Error);
}
&ControlSetKey);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegOpenKey(ControlSetKey) failed (Error %u)\n", (int)Error));
+++++ DPRINTM(DPRINT_REGISTRY, "RegOpenKey(ControlSetKey) failed (Error %u)\n", (int)Error);
return(Error);
}
&LinkKey);
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegCreateKey(LinkKey) failed (Error %u)\n", (int)Error));
+++++ DPRINTM(DPRINT_REGISTRY, "RegCreateKey(LinkKey) failed (Error %u)\n", (int)Error);
return(Error);
}
sizeof(PVOID));
if (Error != ERROR_SUCCESS)
{
----- DbgPrint((DPRINT_REGISTRY, "RegSetValue(LinkKey) failed (Error %u)\n", (int)Error));
+++++ DPRINTM(DPRINT_REGISTRY, "RegSetValue(LinkKey) failed (Error %u)\n", (int)Error);
return(Error);
}
ULONG NameSize;
int CmpResult;
----- DbgPrint((DPRINT_REGISTRY, "KeyName '%S'\n", KeyName));
+++++ DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName);
if (*KeyName == L'\\')
{
while (*KeyName != 0)
{
----- DbgPrint((DPRINT_REGISTRY, "KeyName '%S'\n", KeyName));
+++++ DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName);
if (*KeyName == L'\\')
KeyName++;
CmpResult = 1;
while (Ptr != &CurrentKey->SubKeyList)
{
----- DbgPrint((DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr));
+++++ DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr);
SearchKey = CONTAINING_RECORD(Ptr,
KEY,
KeyList);
----- DbgPrint((DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey));
----- DbgPrint((DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name));
+++++ 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;
memcpy(NewKey->Name, name, NewKey->NameSize - sizeof(WCHAR));
NewKey->Name[subkeyLength] = 0;
----- DbgPrint((DPRINT_REGISTRY, "NewKey 0x%x\n", NewKey));
----- DbgPrint((DPRINT_REGISTRY, "NewKey '%S' Length %d\n", NewKey->Name, NewKey->NameSize));
+++++ DPRINTM(DPRINT_REGISTRY, "NewKey 0x%x\n", NewKey);
+++++ DPRINTM(DPRINT_REGISTRY, "NewKey '%S' Length %d\n", NewKey->Name, NewKey->NameSize);
CurrentKey = NewKey;
}
KEY,
KeyList);
----- DbgPrint((DPRINT_REGISTRY, "Name '%S' Length %d\n", SearchKey->Name, SearchKey->NameSize));
+++++ DPRINTM(DPRINT_REGISTRY, "Name '%S' Length %d\n", SearchKey->Name, SearchKey->NameSize);
Size = min(SearchKey->NameSize, *NameSize);
*NameSize = Size;
int stringLength;
ULONG NameSize;
----- DbgPrint((DPRINT_REGISTRY, "KeyName '%S'\n", KeyName));
+++++ DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName);
*Key = NULL;
while (*KeyName != 0)
{
----- DbgPrint((DPRINT_REGISTRY, "KeyName '%S'\n", KeyName));
+++++ DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName);
if (*KeyName == L'\\')
KeyName++;
Ptr = CurrentKey->SubKeyList.Flink;
while (Ptr != &CurrentKey->SubKeyList)
{
----- DbgPrint((DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr));
+++++ DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr);
SearchKey = CONTAINING_RECORD(Ptr,
KEY,
KeyList);
----- DbgPrint((DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey));
----- DbgPrint((DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name));
+++++ 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)
PLIST_ENTRY Ptr;
PVALUE Value = NULL;
----- DbgPrint((DPRINT_REGISTRY, "Key 0x%p, ValueName '%S', Type %ld, Data 0x%p, DataSize %ld\n",
----- Key, ValueName, Type, Data, DataSize));
+++++ 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))
{
VALUE,
ValueList);
----- DbgPrint((DPRINT_REGISTRY, "Value->Name '%S'\n", Value->Name));
+++++ DPRINTM(DPRINT_REGISTRY, "Value->Name '%S'\n", Value->Name);
if (_wcsicmp(Value->Name, ValueName) == 0)
break;
if (Ptr == &Key->ValueList)
{
/* add new value */
----- DbgPrint((DPRINT_REGISTRY, "No value found - adding new value\n"));
+++++ DPRINTM(DPRINT_REGISTRY, "No value found - adding new value\n");
Value = (PVALUE)MmHeapAlloc(sizeof(VALUE));
if (Value == NULL)
VALUE,
ValueList);
----- DbgPrint((DPRINT_REGISTRY, "Searching for '%S'. Value name '%S'\n", ValueName, Value->Name));
+++++ DPRINTM(DPRINT_REGISTRY, "Searching for '%S'. Value name '%S'\n", ValueName, Value->Name);
if (_wcsicmp(Value->Name, ValueName) == 0)
break;
strcat(strcat(strcat(strcat(reactos_kernel_cmdline, SourcePath), " "),
LoadOptions), DbgLoadOptions);
---- strcpy(SystemRoot, SourcePath);
---- strcat(SystemRoot, "\\");
----
/* Setup the boot path and kernel path */
strcpy(szBootPath, SourcePath);
---- strcpy(szKernelName, szBootPath);
---- strcat(szKernelName, "\\ntoskrnl.exe");
---- /* Setup the HAL path */
---- strcpy(szHalName, szBootPath);
---- strcat(szHalName, "\\hal.dll");
++++ sprintf(SystemRoot,"%s\\", SourcePath);
++++ sprintf(FileName,"%s\\ntoskrnl.exe", SourcePath);
++++ sprintf(szHalName,"%s\\hal.dll", SourcePath);
/* Load the kernel */
---- if (!FrLdrLoadKernel(szKernelName, 5)) return;
++++ LoadBase = FrLdrLoadImage(FileName, 5, 1);
- if (!LoadBase) return;
+++++ if (!LoadBase)
+++++ {
+++++ DPRINT1("Loading the kernel failed!\n");
+++++ return;
+++++ }
++++
++++ /* Get the NT header, kernel base and kernel entry */
++++ NtHeader = RtlImageNtHeader(LoadBase);
++++ KernelBase = SWAPD(NtHeader->OptionalHeader.ImageBase);
++++ KernelEntryPoint = (ROS_KERNEL_ENTRY_POINT)(KernelBase + SWAPD(NtHeader->OptionalHeader.AddressOfEntryPoint));
++++ LoaderBlock.KernelBase = KernelBase;
/* Insert boot disk 2 */
if (MachDiskBootingFromFloppy())
{
if (strcmp(Media, "x") == 0)
{
---- if (!LoadDriver(SourcePath, DriverName))
++++ if (!FrLdrLoadDriver((PCHAR)DriverName,0))
+++++ {
+++++ DPRINTM(DPRINT_WARNING, "could not load %s, %s\n", SourcePath, DriverName);
return;
+++++ }
}
}
} while (InfFindNextLine(&InfContext, &InfContext));
return TRUE;
}
----- DbgPrint((DPRINT_UI, "Initializing User Interface.\n"));
----- DbgPrint((DPRINT_UI, "Reading in UI settings from [Display] section.\n"));
+++++ DPRINTM(DPRINT_UI, "Initializing User Interface.\n");
+++++ DPRINTM(DPRINT_UI, "Reading in UI settings from [Display] section.\n");
DisplayModeText[0] = '\0';
if (IniOpenSection("Display", &SectionId))
// Draw the backdrop and fade it in if special effects are enabled
UiFadeInBackdrop();
----- DbgPrint((DPRINT_UI, "UiInitialize() returning TRUE.\n"));
+++++ DPRINTM(DPRINT_UI, "UiInitialize() returning TRUE.\n");
return TRUE;
}
UiVtbl.DrawText(4, 1, "ReactOS " KERNEL_VERSION_STR " Setup", ATTR(COLOR_GRAY, UiBackdropBgColor));
UiVtbl.DrawText(3, 2, DisplayModeText, ATTR(COLOR_GRAY, UiBackdropBgColor));
----- DbgPrint((DPRINT_UI, "UiInitialize() returning TRUE.\n"));
+++++ DPRINTM(DPRINT_UI, "UiInitialize() returning TRUE.\n");
return TRUE;
}
----/*\r
---- * PROJECT: EFI Windows Loader\r
---- * LICENSE: GPL - See COPYING in the top level directory\r
---- * FILE: freeldr/winldr/conversion.c\r
---- * PURPOSE: Physical <-> Virtual addressing mode conversions\r
---- * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)\r
---- */\r
----\r
----/* INCLUDES ***************************************************************/\r
----\r
----#include <freeldr.h>\r
----\r
----//#include <ndk/ldrtypes.h>\r
----#include <debug.h>\r
----\r
----/* FUNCTIONS **************************************************************/\r
----\r
----/* Arch-specific addresses translation implementation */\r
----PVOID\r
----VaToPa(PVOID Va)\r
----{\r
---- return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE);\r
----}\r
----\r
----PVOID\r
----PaToVa(PVOID Pa)\r
----{\r
---- return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE);\r
----}\r
----\r
----VOID\r
----List_PaToVa(LIST_ENTRY *ListEntry)\r
----{\r
---- LIST_ENTRY *ListHead = ListEntry;\r
---- LIST_ENTRY *Next = ListEntry->Flink;\r
---- LIST_ENTRY *NextPA;\r
----\r
---- //Print(L"\n\nList_Entry: %X, First Next: %X\n", ListEntry, Next);\r
---- //\r
---- // Walk through the whole list\r
---- //\r
---- if (Next != NULL)\r
---- {\r
---- while (Next != PaToVa(ListHead))\r
---- {\r
---- NextPA = VaToPa(Next);\r
---- //Print(L"Current: %X, Flink: %X, Blink: %X\n", Next, NextPA->Flink, NextPA->Blink);\r
----\r
---- NextPA->Flink = PaToVa((PVOID)NextPA->Flink);\r
---- NextPA->Blink = PaToVa((PVOID)NextPA->Blink);\r
----\r
---- //Print(L"After converting Flink: %X, Blink: %X\n", NextPA->Flink, NextPA->Blink);\r
----\r
---- Next = NextPA->Flink;\r
---- }\r
----\r
---- //\r
---- // Finally convert first Flink/Blink\r
---- //\r
---- ListEntry->Flink = PaToVa((PVOID)ListEntry->Flink);\r
---- if (ListEntry->Blink)\r
---- ListEntry->Blink = PaToVa((PVOID)ListEntry->Blink);\r
---- }\r
----}\r
----\r
----// This function converts only Child->Child, and calls itself for each Sibling\r
----VOID\r
----ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)\r
----{\r
---- PCONFIGURATION_COMPONENT_DATA Child;\r
---- PCONFIGURATION_COMPONENT_DATA Sibling;\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "ConvertConfigToVA(Start 0x%X)\n", Start));\r
---- Child = Start;\r
----\r
---- while (Child != NULL)\r
---- {\r
---- if (Child->ConfigurationData)\r
---- Child->ConfigurationData = PaToVa(Child->ConfigurationData);\r
----\r
---- if (Child->Child)\r
---- Child->Child = PaToVa(Child->Child);\r
----\r
---- if (Child->Parent)\r
---- Child->Parent = PaToVa(Child->Parent);\r
----\r
---- if (Child->Sibling)\r
---- Child->Sibling = PaToVa(Child->Sibling);\r
----\r
---- if (Child->ComponentEntry.Identifier)\r
---- Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Child,\r
---- Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent));\r
----\r
---- // Go through siblings list\r
---- Sibling = VaToPa(Child->Sibling);\r
---- while (Sibling != NULL)\r
---- {\r
---- if (Sibling->ConfigurationData)\r
---- Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData);\r
----\r
---- if (Sibling->Child)\r
---- Sibling->Child = PaToVa(Sibling->Child);\r
----\r
---- if (Sibling->Parent)\r
---- Sibling->Parent = PaToVa(Sibling->Parent);\r
----\r
---- if (Sibling->Sibling)\r
---- Sibling->Sibling = PaToVa(Sibling->Sibling);\r
----\r
---- if (Sibling->ComponentEntry.Identifier)\r
---- Sibling->ComponentEntry.Identifier = PaToVa(Sibling->ComponentEntry.Identifier);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Sibling,\r
---- Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent));\r
----\r
---- // Recurse into the Child tree\r
---- if (VaToPa(Sibling->Child) != NULL)\r
---- ConvertConfigToVA(VaToPa(Sibling->Child));\r
----\r
---- Sibling = VaToPa(Sibling->Sibling);\r
---- }\r
----\r
---- // Go to the next child\r
---- Child = VaToPa(Child->Child);\r
---- }\r
----}\r
++++/*
++++ * PROJECT: EFI Windows Loader
++++ * LICENSE: GPL - See COPYING in the top level directory
++++ * FILE: freeldr/winldr/conversion.c
++++ * PURPOSE: Physical <-> Virtual addressing mode conversions
++++ * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
++++ */
++++
++++/* INCLUDES ***************************************************************/
++++
++++#include <freeldr.h>
++++
++++//#include <ndk/ldrtypes.h>
++++#include <debug.h>
++++
++++/* FUNCTIONS **************************************************************/
++++
++++/* Arch-specific addresses translation implementation */
++++PVOID
++++VaToPa(PVOID Va)
++++{
++++ return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE);
++++}
++++
++++PVOID
++++PaToVa(PVOID Pa)
++++{
++++ return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE);
++++}
++++
++++VOID
++++List_PaToVa(LIST_ENTRY *ListEntry)
++++{
++++ LIST_ENTRY *ListHead = ListEntry;
++++ LIST_ENTRY *Next = ListEntry->Flink;
++++ LIST_ENTRY *NextPA;
++++
++++ //Print(L"\n\nList_Entry: %X, First Next: %X\n", ListEntry, Next);
++++ //
++++ // Walk through the whole list
++++ //
++++ if (Next != NULL)
++++ {
++++ while (Next != PaToVa(ListHead))
++++ {
++++ NextPA = VaToPa(Next);
++++ //Print(L"Current: %X, Flink: %X, Blink: %X\n", Next, NextPA->Flink, NextPA->Blink);
++++
++++ NextPA->Flink = PaToVa((PVOID)NextPA->Flink);
++++ NextPA->Blink = PaToVa((PVOID)NextPA->Blink);
++++
++++ //Print(L"After converting Flink: %X, Blink: %X\n", NextPA->Flink, NextPA->Blink);
++++
++++ Next = NextPA->Flink;
++++ }
++++
++++ //
++++ // Finally convert first Flink/Blink
++++ //
++++ ListEntry->Flink = PaToVa((PVOID)ListEntry->Flink);
++++ if (ListEntry->Blink)
++++ ListEntry->Blink = PaToVa((PVOID)ListEntry->Blink);
++++ }
++++}
++++
++++// This function converts only Child->Child, and calls itself for each Sibling
++++VOID
++++ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
++++{
++++ PCONFIGURATION_COMPONENT_DATA Child;
++++ PCONFIGURATION_COMPONENT_DATA Sibling;
++++
- DbgPrint((DPRINT_WINDOWS, "ConvertConfigToVA(Start 0x%X)\n", Start));
+++++ DPRINTM(DPRINT_WINDOWS, "ConvertConfigToVA(Start 0x%X)\n", Start);
++++ Child = Start;
++++
++++ while (Child != NULL)
++++ {
++++ if (Child->ConfigurationData)
++++ Child->ConfigurationData = PaToVa(Child->ConfigurationData);
++++
++++ if (Child->Child)
++++ Child->Child = PaToVa(Child->Child);
++++
++++ if (Child->Parent)
++++ Child->Parent = PaToVa(Child->Parent);
++++
++++ if (Child->Sibling)
++++ Child->Sibling = PaToVa(Child->Sibling);
++++
++++ if (Child->ComponentEntry.Identifier)
++++ Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier);
++++
- DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Child,
- Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent));
+++++ DPRINTM(DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Child,
+++++ Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent);
++++
++++ // Go through siblings list
++++ Sibling = VaToPa(Child->Sibling);
++++ while (Sibling != NULL)
++++ {
++++ if (Sibling->ConfigurationData)
++++ Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData);
++++
++++ if (Sibling->Child)
++++ Sibling->Child = PaToVa(Sibling->Child);
++++
++++ if (Sibling->Parent)
++++ Sibling->Parent = PaToVa(Sibling->Parent);
++++
++++ if (Sibling->Sibling)
++++ Sibling->Sibling = PaToVa(Sibling->Sibling);
++++
++++ if (Sibling->ComponentEntry.Identifier)
++++ Sibling->ComponentEntry.Identifier = PaToVa(Sibling->ComponentEntry.Identifier);
++++
- DbgPrint((DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Sibling,
- Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent));
+++++ DPRINTM(DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Sibling,
+++++ Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent);
++++
++++ // Recurse into the Child tree
++++ if (VaToPa(Sibling->Child) != NULL)
++++ ConvertConfigToVA(VaToPa(Sibling->Child));
++++
++++ Sibling = VaToPa(Sibling->Sibling);
++++ }
++++
++++ // Go to the next child
++++ Child = VaToPa(Child->Child);
++++ }
++++}
----/*\r
---- * PROJECT: FreeLoader\r
---- * LICENSE: GPL - See COPYING in the top level directory\r
---- * FILE: freeldr/winldr/peloader.c\r
---- * PURPOSE: Provides routines for loading PE files. To be merged with\r
---- * arch/i386/loader.c in future\r
---- * This article was very handy during development:\r
---- * http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/\r
---- * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)\r
---- * The source code in this file is based on the work of respective\r
---- * authors of PE loading code in ReactOS and Brian Palmer and\r
---- * Alex Ionescu's arch/i386/loader.c, and my research project\r
---- * (creating a native EFI loader for Windows)\r
---- */\r
----\r
----/* INCLUDES ***************************************************************/\r
----#include <freeldr.h>\r
----#include <debug.h>\r
----\r
----\r
----BOOLEAN\r
----WinLdrpCompareDllName(IN PCH DllName,\r
---- IN PUNICODE_STRING UnicodeName);\r
----\r
----BOOLEAN\r
----WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- IN PVOID DllBase,\r
---- IN PVOID ImageBase,\r
---- IN PIMAGE_THUNK_DATA ThunkData,\r
---- IN PIMAGE_EXPORT_DIRECTORY ExportDirectory,\r
---- IN ULONG ExportSize,\r
---- IN BOOLEAN ProcessForwards);\r
----\r
----BOOLEAN\r
----WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- PCCH DirectoryPath,\r
---- PCH ImportName,\r
---- PLDR_DATA_TABLE_ENTRY *DataTableEntry);\r
----\r
----BOOLEAN\r
----WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- IN PVOID DllBase,\r
---- IN PVOID ImageBase,\r
---- IN PIMAGE_THUNK_DATA ThunkData);\r
----\r
----\r
----\r
----/* FUNCTIONS **************************************************************/\r
----\r
----/* Returns TRUE if DLL has already been loaded - looks in LoadOrderList in LPB */\r
----BOOLEAN\r
----WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- IN PCH DllName,\r
---- OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)\r
----{\r
---- PLDR_DATA_TABLE_ENTRY DataTableEntry;\r
---- LIST_ENTRY *ModuleEntry;\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DllName %X, LoadedEntry: %X\n",\r
---- DllName, LoadedEntry));\r
----\r
---- /* Just go through each entry in the LoadOrderList and compare loaded module's\r
---- name with a given name */\r
---- ModuleEntry = WinLdrBlock->LoadOrderListHead.Flink;\r
---- while (ModuleEntry != &WinLdrBlock->LoadOrderListHead)\r
---- {\r
---- /* Get pointer to the current DTE */\r
---- DataTableEntry = CONTAINING_RECORD(ModuleEntry,\r
---- LDR_DATA_TABLE_ENTRY,\r
---- InLoadOrderLinks);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DTE %p, EP %p\n",\r
---- DataTableEntry, DataTableEntry->EntryPoint));\r
----\r
---- /* Compare names */\r
---- if (WinLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName))\r
---- {\r
---- /* Yes, found it, report pointer to the loaded module's DTE \r
---- to the caller and increase load count for it */\r
---- *LoadedEntry = DataTableEntry;\r
---- DataTableEntry->LoadCount++;\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: LoadedEntry %X\n", DataTableEntry));\r
---- return TRUE;\r
---- }\r
----\r
---- /* Go to the next entry */\r
---- ModuleEntry = ModuleEntry->Flink;\r
---- }\r
----\r
---- /* Nothing found */\r
---- return FALSE;\r
----}\r
----\r
----BOOLEAN\r
----WinLdrScanImportDescriptorTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- IN PCCH DirectoryPath,\r
---- IN PLDR_DATA_TABLE_ENTRY ScanDTE)\r
----{\r
---- PLDR_DATA_TABLE_ENTRY DataTableEntry;\r
---- PIMAGE_IMPORT_DESCRIPTOR ImportTable;\r
---- ULONG ImportTableSize;\r
---- PCH ImportName;\r
---- BOOLEAN Status;\r
----\r
---- /* Get a pointer to the import table of this image */\r
---- ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase),\r
---- TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);\r
----\r
---- {\r
---- UNICODE_STRING BaseName;\r
---- BaseName.Buffer = VaToPa(ScanDTE->BaseDllName.Buffer);\r
---- BaseName.MaximumLength = ScanDTE->BaseDllName.MaximumLength;\r
---- BaseName.Length = ScanDTE->BaseDllName.Length;\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%X\n",\r
---- &BaseName, ImportTable));\r
---- }\r
----\r
---- /* If image doesn't have any import directory - just return success */\r
---- if (ImportTable == NULL)\r
---- return TRUE;\r
----\r
---- /* Loop through all entries */\r
---- for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)\r
---- {\r
---- /* Get pointer to the name */\r
---- ImportName = (PCH)VaToPa(RVA(ScanDTE->DllBase, ImportTable->Name));\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): Looking at %s\n", ImportName));\r
----\r
---- /* In case we get a reference to ourselves - just skip it */\r
---- if (WinLdrpCompareDllName(ImportName, &ScanDTE->BaseDllName))\r
---- continue;\r
----\r
---- /* Load the DLL if it is not already loaded */\r
---- if (!WinLdrCheckForLoadedDll(WinLdrBlock, ImportName, &DataTableEntry))\r
---- {\r
---- Status = WinLdrpLoadAndScanReferencedDll(WinLdrBlock,\r
---- DirectoryPath,\r
---- ImportName,\r
---- &DataTableEntry);\r
----\r
---- if (!Status)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrpLoadAndScanReferencedDll() failed\n"));\r
---- return Status;\r
---- }\r
---- }\r
----\r
---- /* Scan its import address table */\r
---- Status = WinLdrpScanImportAddressTable(\r
---- WinLdrBlock,\r
---- DataTableEntry->DllBase,\r
---- ScanDTE->DllBase,\r
---- (PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk));\r
----\r
---- if (!Status)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable() failed\n"));\r
---- return Status;\r
---- }\r
---- }\r
----\r
---- return TRUE;\r
----}\r
----\r
----BOOLEAN\r
----WinLdrAllocateDataTableEntry(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- IN PCCH BaseDllName,\r
---- IN PCCH FullDllName,\r
---- IN PVOID BasePA,\r
---- OUT PLDR_DATA_TABLE_ENTRY *NewEntry)\r
----{\r
---- PVOID BaseVA = PaToVa(BasePA);\r
---- PWSTR Buffer;\r
---- PLDR_DATA_TABLE_ENTRY DataTableEntry;\r
---- PIMAGE_NT_HEADERS NtHeaders;\r
---- USHORT Length;\r
----\r
---- /* Allocate memory for a data table entry, zero-initialize it */\r
---- DataTableEntry = (PLDR_DATA_TABLE_ENTRY)MmHeapAlloc(sizeof(LDR_DATA_TABLE_ENTRY));\r
---- if (DataTableEntry == NULL)\r
---- return FALSE;\r
---- RtlZeroMemory(DataTableEntry, sizeof(LDR_DATA_TABLE_ENTRY));\r
----\r
---- /* Get NT headers from the image */\r
---- NtHeaders = RtlImageNtHeader(BasePA);\r
----\r
---- /* Initialize corresponding fields of DTE based on NT headers value */\r
---- DataTableEntry->DllBase = BaseVA;\r
---- DataTableEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage;\r
---- DataTableEntry->EntryPoint = RVA(BaseVA, NtHeaders->OptionalHeader.AddressOfEntryPoint);\r
---- DataTableEntry->SectionPointer = 0;\r
---- DataTableEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum;\r
----\r
---- /* Initialize BaseDllName field (UNICODE_STRING) from the Ansi BaseDllName\r
---- by simple conversion - copying each character */\r
---- Length = (USHORT)(strlen(BaseDllName) * sizeof(WCHAR));\r
---- Buffer = (PWSTR)MmHeapAlloc(Length);\r
---- if (Buffer == NULL)\r
---- {\r
---- MmHeapFree(DataTableEntry);\r
---- return FALSE;\r
---- }\r
---- RtlZeroMemory(Buffer, Length);\r
----\r
---- DataTableEntry->BaseDllName.Length = Length;\r
---- DataTableEntry->BaseDllName.MaximumLength = Length;\r
---- DataTableEntry->BaseDllName.Buffer = PaToVa(Buffer);\r
---- while (*BaseDllName != 0)\r
---- {\r
---- *Buffer++ = *BaseDllName++;\r
---- }\r
----\r
---- /* Initialize FullDllName field (UNICODE_STRING) from the Ansi FullDllName\r
---- using the same method */\r
---- Length = (USHORT)(strlen(FullDllName) * sizeof(WCHAR));\r
---- Buffer = (PWSTR)MmHeapAlloc(Length);\r
---- if (Buffer == NULL)\r
---- {\r
---- MmHeapFree(DataTableEntry);\r
---- return FALSE;\r
---- }\r
---- RtlZeroMemory(Buffer, Length);\r
----\r
---- DataTableEntry->FullDllName.Length = Length;\r
---- DataTableEntry->FullDllName.MaximumLength = Length;\r
---- DataTableEntry->FullDllName.Buffer = PaToVa(Buffer);\r
---- while (*FullDllName != 0)\r
---- {\r
---- *Buffer++ = *FullDllName++;\r
---- }\r
----\r
---- /* Initialize what's left - LoadCount which is 1, and set Flags so that\r
---- we know this entry is processed */\r
---- DataTableEntry->Flags = LDRP_ENTRY_PROCESSED;\r
---- DataTableEntry->LoadCount = 1;\r
----\r
---- /* Insert this DTE to a list in the LPB */\r
---- InsertTailList(&WinLdrBlock->LoadOrderListHead, &DataTableEntry->InLoadOrderLinks);\r
----\r
---- /* Save pointer to a newly allocated and initialized entry */\r
---- *NewEntry = DataTableEntry;\r
----\r
---- /* Return success */\r
---- return TRUE;\r
----}\r
----\r
----/* WinLdrLoadImage loads the specified image from the file (it doesn't\r
---- perform any additional operations on the filename, just directly\r
---- calls the file I/O routines), and relocates it so that it's ready\r
---- to be used when paging is enabled.\r
---- Addressing mode: physical\r
---- */\r
----BOOLEAN\r
----WinLdrLoadImage(IN PCHAR FileName,\r
---- TYPE_OF_MEMORY MemoryType,\r
---- OUT PVOID *ImageBasePA)\r
----{\r
---- PFILE FileHandle;\r
---- PVOID PhysicalBase;\r
---- PVOID VirtualBase = NULL;\r
---- UCHAR HeadersBuffer[SECTOR_SIZE * 2];\r
---- PIMAGE_NT_HEADERS NtHeaders;\r
---- PIMAGE_SECTION_HEADER SectionHeader;\r
---- ULONG VirtualSize, SizeOfRawData, NumberOfSections;\r
---- BOOLEAN Status;\r
---- ULONG i, BytesRead;\r
----\r
---- CHAR ProgressString[256];\r
----\r
---- /* Inform user we are loading files */\r
---- sprintf(ProgressString, "Loading %s...", FileName);\r
---- UiDrawProgressBarCenter(1, 100, ProgressString);\r
----\r
---- /* Open the image file */\r
---- FileHandle = FsOpenFile(FileName);\r
----\r
---- if (FileHandle == NULL)\r
---- {\r
---- //Print(L"Can not open the file %s\n",FileName);\r
---- UiMessageBox("Can not open the file");\r
---- return FALSE;\r
---- }\r
----\r
---- /* Load the first 2 sectors of the image so we can read the PE header */\r
---- Status = FsReadFile(FileHandle, SECTOR_SIZE * 2, NULL, HeadersBuffer);\r
---- if (!Status)\r
---- {\r
---- //Print(L"Error reading from file %s\n", FileName);\r
---- UiMessageBox("Error reading from file");\r
---- FsCloseFile(FileHandle);\r
---- return FALSE;\r
---- }\r
----\r
---- /* Now read the MZ header to get the offset to the PE Header */\r
---- NtHeaders = RtlImageNtHeader(HeadersBuffer);\r
----\r
---- if (!NtHeaders)\r
---- {\r
---- //Print(L"Error - no NT header found in %s\n", FileName);\r
---- UiMessageBox("Error - no NT header found");\r
---- FsCloseFile(FileHandle);\r
---- return FALSE;\r
---- }\r
----\r
---- /* Ensure this is executable image */\r
---- if (((NtHeaders->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE) == 0))\r
---- {\r
---- //Print(L"Not an executable image %s\n", FileName);\r
---- UiMessageBox("Not an executable image");\r
---- FsCloseFile(FileHandle);\r
---- return FALSE;\r
---- }\r
----\r
---- /* Store number of sections to read and a pointer to the first section */\r
---- NumberOfSections = NtHeaders->FileHeader.NumberOfSections;\r
---- SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);\r
----\r
---- /* Try to allocate this memory, if fails - allocate somewhere else */\r
---- PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage,\r
---- (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)),\r
---- MemoryType);\r
----\r
---- if (PhysicalBase == NULL)\r
---- {\r
---- /* It's ok, we don't panic - let's allocate again at any other "low" place */\r
---- PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType);\r
----\r
---- if (PhysicalBase == NULL)\r
---- {\r
---- //Print(L"Failed to alloc pages for image %s\n", FileName);\r
---- UiMessageBox("Failed to alloc pages for image");\r
---- FsCloseFile(FileHandle);\r
---- return FALSE;\r
---- }\r
---- }\r
----\r
---- /* This is the real image base - in form of a virtual address */\r
---- VirtualBase = PaToVa(PhysicalBase);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Base PA: 0x%X, VA: 0x%X\n", PhysicalBase, VirtualBase));\r
----\r
---- /* Set to 0 position and fully load the file image */\r
---- FsSetFilePointer(FileHandle, 0);\r
----\r
---- Status = FsReadFile(FileHandle, NtHeaders->OptionalHeader.SizeOfHeaders, NULL, PhysicalBase);\r
----\r
---- if (!Status)\r
---- {\r
---- //Print(L"Error reading headers %s\n", FileName);\r
---- UiMessageBox("Error reading headers");\r
---- FsCloseFile(FileHandle);\r
---- return FALSE;\r
---- }\r
----\r
---- /* Reload the NT Header */\r
---- NtHeaders = RtlImageNtHeader(PhysicalBase);\r
----\r
---- /* Load the first section */\r
---- SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);\r
----\r
---- /* Fill output parameters */\r
---- *ImageBasePA = PhysicalBase;\r
----\r
---- /* Walk through each section and read it (check/fix any possible\r
---- bad situations, if they arise) */\r
---- for (i = 0; i < NumberOfSections; i++)\r
---- {\r
---- VirtualSize = SectionHeader->Misc.VirtualSize;\r
---- SizeOfRawData = SectionHeader->SizeOfRawData;\r
----\r
---- /* Handle a case when VirtualSize equals 0 */\r
---- if (VirtualSize == 0)\r
---- VirtualSize = SizeOfRawData;\r
----\r
---- /* If PointerToRawData is 0, then force its size to be also 0 */\r
---- if (SectionHeader->PointerToRawData == 0)\r
---- {\r
---- SizeOfRawData = 0;\r
---- }\r
---- else\r
---- {\r
---- /* Cut the loaded size to the VirtualSize extents */\r
---- if (SizeOfRawData > VirtualSize)\r
---- SizeOfRawData = VirtualSize;\r
---- }\r
----\r
---- /* Actually read the section (if its size is not 0) */\r
---- if (SizeOfRawData != 0)\r
---- {\r
---- /* Seek to the correct position */\r
---- FsSetFilePointer(FileHandle, SectionHeader->PointerToRawData);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "SH->VA: 0x%X\n", SectionHeader->VirtualAddress));\r
----\r
---- /* Read this section from the file, size = SizeOfRawData */\r
---- Status = FsReadFile(FileHandle, SizeOfRawData, &BytesRead, (PUCHAR)PhysicalBase + SectionHeader->VirtualAddress);\r
----\r
---- if (!Status && (BytesRead == 0))\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): Error reading section from file!\n"));\r
---- break;\r
---- }\r
---- }\r
----\r
---- /* Size of data is less than the virtual size - fill up the remainder with zeroes */\r
---- if (SizeOfRawData < VirtualSize)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): SORD %d < VS %d", SizeOfRawData, VirtualSize));\r
---- RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData);\r
---- }\r
----\r
---- SectionHeader++;\r
---- }\r
----\r
---- /* We are done with the file - close it */\r
---- FsCloseFile(FileHandle);\r
----\r
---- /* If loading failed - return right now */\r
---- if (!Status)\r
---- return FALSE;\r
----\r
----\r
---- /* Relocate the image, if it needs it */\r
---- if (NtHeaders->OptionalHeader.ImageBase != (ULONG)VirtualBase)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "Relocating %p -> %p\n",\r
---- NtHeaders->OptionalHeader.ImageBase, VirtualBase));\r
---- Status = (BOOLEAN)LdrRelocateImageWithBias(PhysicalBase,\r
---- (ULONG_PTR)VirtualBase - (ULONG_PTR)PhysicalBase,\r
---- "FreeLdr",\r
---- TRUE,\r
---- TRUE, /* in case of conflict still return success */\r
---- FALSE);\r
---- }\r
----\r
---- return Status;\r
----}\r
----\r
----/* PRIVATE FUNCTIONS *******************************************************/\r
----\r
----/* DllName - physical, UnicodeString->Buffer - virtual */\r
----BOOLEAN\r
----WinLdrpCompareDllName(IN PCH DllName,\r
---- IN PUNICODE_STRING UnicodeName)\r
----{\r
---- PWSTR Buffer;\r
---- UNICODE_STRING UnicodeNamePA;\r
---- ULONG i, Length;\r
---- \r
---- /* First obvious check: for length of two names */\r
---- Length = strlen(DllName);\r
----\r
---- UnicodeNamePA.Length = UnicodeName->Length;\r
---- UnicodeNamePA.MaximumLength = UnicodeName->MaximumLength;\r
---- UnicodeNamePA.Buffer = VaToPa(UnicodeName->Buffer);\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrpCompareDllName: %s and %wZ, Length = %d "\r
---- "UN->Length %d\n", DllName, &UnicodeNamePA, Length, UnicodeName->Length));\r
----\r
---- if ((Length * sizeof(WCHAR)) > UnicodeName->Length)\r
---- return FALSE;\r
----\r
---- /* Store pointer to unicode string's buffer */\r
---- Buffer = VaToPa(UnicodeName->Buffer);\r
----\r
---- /* Loop character by character */\r
---- for (i = 0; i < Length; i++)\r
---- {\r
---- /* Compare two characters, uppercasing them */\r
---- if (toupper(*DllName) != toupper((CHAR)*Buffer))\r
---- return FALSE;\r
----\r
---- /* Move to the next character */\r
---- DllName++;\r
---- Buffer++;\r
---- }\r
----\r
---- /* Check, if strings either fully match, or match till the "." (w/o extension) */\r
---- if ((UnicodeName->Length == Length * sizeof(WCHAR)) || (*Buffer == L'.'))\r
---- {\r
---- /* Yes they do */\r
---- return TRUE;\r
---- }\r
----\r
---- /* Strings don't match, return FALSE */\r
---- return FALSE;\r
----}\r
----\r
----BOOLEAN\r
----WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- IN PVOID DllBase,\r
---- IN PVOID ImageBase,\r
---- IN PIMAGE_THUNK_DATA ThunkData,\r
---- IN PIMAGE_EXPORT_DIRECTORY ExportDirectory,\r
---- IN ULONG ExportSize,\r
---- IN BOOLEAN ProcessForwards)\r
----{\r
---- ULONG Ordinal;\r
---- PULONG NameTable, FunctionTable;\r
---- PUSHORT OrdinalTable;\r
---- LONG High, Low, Middle, Result;\r
---- ULONG Hint;\r
----\r
---- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): DllBase 0x%X, ImageBase 0x%X, ThunkData 0x%X, ExportDirectory 0x%X, ExportSize %d, ProcessForwards 0x%X\n",\r
---- // DllBase, ImageBase, ThunkData, ExportDirectory, ExportSize, ProcessForwards));\r
----\r
---- /* Check passed DllBase param */\r
---- if(DllBase == NULL)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "WARNING: DllBase == NULL!\n"));\r
---- return FALSE;\r
---- }\r
----\r
---- /* Convert all non-critical pointers to PA from VA */\r
---- ThunkData = VaToPa(ThunkData);\r
----\r
---- /* Is the reference by ordinal? */\r
---- if (IMAGE_SNAP_BY_ORDINAL(ThunkData->u1.Ordinal) && !ProcessForwards)\r
---- {\r
---- /* Yes, calculate the ordinal */\r
---- Ordinal = (ULONG)(IMAGE_ORDINAL(ThunkData->u1.Ordinal) - (UINT32)ExportDirectory->Base);\r
---- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal));\r
---- }\r
---- else\r
---- {\r
---- /* It's reference by name, we have to look it up in the export directory */\r
---- if (!ProcessForwards)\r
---- {\r
---- /* AddressOfData in thunk entry will become a virtual address (from relative) */\r
---- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD was %p\n", ThunkData->u1.AddressOfData));\r
---- ThunkData->u1.AddressOfData =\r
---- (ULONG)RVA(ImageBase, ThunkData->u1.AddressOfData);\r
---- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD became %p\n", ThunkData->u1.AddressOfData));\r
---- }\r
----\r
---- /* Get pointers to Name and Ordinal tables (RVA -> VA) */\r
---- NameTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNames));\r
---- OrdinalTable = (PUSHORT)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNameOrdinals));\r
----\r
---- //DbgPrint((DPRINT_WINDOWS, "NameTable 0x%X, OrdinalTable 0x%X, ED->AddressOfNames 0x%X, ED->AOFO 0x%X\n",\r
---- // NameTable, OrdinalTable, ExportDirectory->AddressOfNames, ExportDirectory->AddressOfNameOrdinals));\r
----\r
---- /* Get the hint, convert it to a physical pointer */\r
---- Hint = ((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Hint;\r
---- //DbgPrint((DPRINT_WINDOWS, "HintIndex %d\n", Hint));\r
----\r
---- /* If Hint is less than total number of entries in the export directory,\r
---- and import name == export name, then we can just get it from the OrdinalTable */\r
---- if (\r
---- (Hint < ExportDirectory->NumberOfNames) &&\r
---- (\r
---- strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]),\r
---- (PCHAR)VaToPa( RVA(DllBase, NameTable[Hint])) ) == 0\r
---- )\r
---- )\r
---- {\r
---- Ordinal = OrdinalTable[Hint];\r
---- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal));\r
---- }\r
---- else\r
---- {\r
---- /* It's not the easy way, we have to lookup import name in the name table.\r
---- Let's use a binary search for this task. */\r
----\r
---- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() looking up the import name using binary search...\n"));\r
----\r
---- /* Low boundary is set to 0, and high boundary to the maximum index */\r
---- Low = 0;\r
---- High = ExportDirectory->NumberOfNames - 1;\r
----\r
---- /* Perform a binary-search loop */\r
---- while (High >= Low)\r
---- {\r
---- /* Divide by 2 by shifting to the right once */\r
---- Middle = (Low + High) >> 1;\r
----\r
---- /* Compare the names */\r
---- Result = strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]),\r
---- (PCHAR)VaToPa(RVA(DllBase, NameTable[Middle])));\r
----\r
---- /*DbgPrint((DPRINT_WINDOWS, "Binary search: comparing Import '__', Export '%s'\n",*/\r
---- /*VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name[0]),*/\r
---- /*(PCHAR)VaToPa(RVA(DllBase, NameTable[Middle]))));*/\r
----\r
---- /*DbgPrint((DPRINT_WINDOWS, "TE->u1.AOD %p, fulladdr %p\n",\r
---- ThunkData->u1.AddressOfData,\r
---- ((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name ));*/\r
----\r
----\r
---- /* Depending on result of strcmp, perform different actions */\r
---- if (Result < 0)\r
---- {\r
---- /* Adjust top boundary */\r
---- High = Middle - 1;\r
---- }\r
---- else if (Result > 0)\r
---- {\r
---- /* Adjust bottom boundary */\r
---- Low = Middle + 1;\r
---- }\r
---- else\r
---- {\r
---- /* Yay, found it! */\r
---- break;\r
---- }\r
---- }\r
----\r
---- /* If high boundary is less than low boundary, then no result found */\r
---- if (High < Low)\r
---- {\r
---- //Print(L"Error in binary search\n");\r
---- DbgPrint((DPRINT_WINDOWS, "Error in binary search!\n"));\r
---- return FALSE;\r
---- }\r
----\r
---- /* Everything allright, get the ordinal */\r
---- Ordinal = OrdinalTable[Middle];\r
---- \r
---- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() found Ordinal %d\n", Ordinal));\r
---- }\r
---- }\r
----\r
---- /* Check ordinal number for validity! */\r
---- if (Ordinal >= ExportDirectory->NumberOfFunctions)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "Ordinal number is invalid!\n"));\r
---- return FALSE;\r
---- }\r
----\r
---- /* Get a pointer to the function table */\r
---- FunctionTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfFunctions));\r
----\r
---- /* Save a pointer to the function */\r
---- ThunkData->u1.Function = (ULONG)RVA(DllBase, FunctionTable[Ordinal]);\r
----\r
---- /* Is it a forwarder? (function pointer isn't within the export directory) */\r
---- if (((ULONG)VaToPa((PVOID)ThunkData->u1.Function) > (ULONG)ExportDirectory) &&\r
---- ((ULONG)VaToPa((PVOID)ThunkData->u1.Function) < ((ULONG)ExportDirectory + ExportSize)))\r
---- {\r
---- PLDR_DATA_TABLE_ENTRY DataTableEntry;\r
---- CHAR ForwardDllName[255];\r
---- PIMAGE_EXPORT_DIRECTORY RefExportDirectory;\r
---- ULONG RefExportSize;\r
----\r
---- /* Save the name of the forward dll */\r
---- RtlCopyMemory(ForwardDllName, (PCHAR)VaToPa((PVOID)ThunkData->u1.Function), sizeof(ForwardDllName));\r
----\r
---- /* Strip out its extension */\r
---- *strchr(ForwardDllName,'.') = '\0';\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ForwardDllName %s\n", ForwardDllName));\r
---- if (!WinLdrCheckForLoadedDll(WinLdrBlock, ForwardDllName, &DataTableEntry))\r
---- {\r
---- /* We can't continue if DLL couldn't be loaded, so bomb out with an error */\r
---- //Print(L"Error loading DLL!\n");\r
---- DbgPrint((DPRINT_WINDOWS, "Error loading DLL!\n"));\r
---- return FALSE;\r
---- }\r
----\r
---- /* Get pointer to the export directory of loaded DLL */\r
---- RefExportDirectory = (PIMAGE_EXPORT_DIRECTORY)\r
---- RtlImageDirectoryEntryToData(VaToPa(DataTableEntry->DllBase),\r
---- TRUE,\r
---- IMAGE_DIRECTORY_ENTRY_EXPORT,\r
---- &RefExportSize);\r
----\r
---- /* Fail if it's NULL */\r
---- if (RefExportDirectory)\r
---- {\r
---- UCHAR Buffer[128];\r
---- IMAGE_THUNK_DATA RefThunkData;\r
---- PIMAGE_IMPORT_BY_NAME ImportByName;\r
---- PCHAR ImportName;\r
---- BOOLEAN Status;\r
----\r
---- /* Get pointer to the import name */\r
---- ImportName = strchr((PCHAR)VaToPa((PVOID)ThunkData->u1.Function), '.') + 1;\r
----\r
---- /* Create a IMAGE_IMPORT_BY_NAME structure, pointing to the local Buffer */\r
---- ImportByName = (PIMAGE_IMPORT_BY_NAME)Buffer;\r
----\r
---- /* Fill the name with the import name */\r
---- RtlCopyMemory(ImportByName->Name, ImportName, strlen(ImportName)+1);\r
----\r
---- /* Set Hint to 0 */\r
---- ImportByName->Hint = 0;\r
----\r
---- /* And finally point ThunkData's AddressOfData to that structure */\r
---- RefThunkData.u1.AddressOfData = (ULONG)ImportByName;\r
----\r
---- /* And recursively call ourselves */\r
---- Status = WinLdrpBindImportName(\r
---- WinLdrBlock,\r
---- DataTableEntry->DllBase,\r
---- ImageBase,\r
---- &RefThunkData,\r
---- RefExportDirectory,\r
---- RefExportSize,\r
---- TRUE);\r
----\r
---- /* Fill out the ThunkData with data from RefThunkData */\r
---- ThunkData->u1 = RefThunkData.u1;\r
----\r
---- /* Return what we got from the recursive call */\r
---- return Status;\r
---- }\r
---- else\r
---- {\r
---- /* Fail if ExportDirectory is NULL */\r
---- return FALSE;\r
---- }\r
---- }\r
----\r
---- /* Success! */\r
---- return TRUE;\r
----}\r
----\r
----BOOLEAN\r
----WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- PCCH DirectoryPath,\r
---- PCH ImportName,\r
---- PLDR_DATA_TABLE_ENTRY *DataTableEntry)\r
----{\r
---- CHAR FullDllName[256];\r
---- BOOLEAN Status;\r
---- PVOID BasePA;\r
----\r
---- /* Prepare the full path to the file to be loaded */\r
---- strcpy(FullDllName, DirectoryPath);\r
---- strcat(FullDllName, ImportName);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Loading referenced DLL: %s\n", FullDllName));\r
---- //Print(L"Loading referenced DLL: %s\n", FullDllName);\r
----\r
---- /* Load the image */\r
---- Status = WinLdrLoadImage(FullDllName, LoaderHalCode, &BasePA);\r
----\r
---- if (!Status)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage() failed\n"));\r
---- return Status;\r
---- }\r
----\r
---- /* Allocate DTE for newly loaded DLL */\r
---- Status = WinLdrAllocateDataTableEntry(WinLdrBlock,\r
---- ImportName,\r
---- FullDllName,\r
---- BasePA,\r
---- DataTableEntry);\r
----\r
---- if (!Status)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS,\r
---- "WinLdrAllocateDataTableEntry() failed with Status=0x%X\n", Status));\r
---- return Status;\r
---- }\r
----\r
---- /* Scan its dependencies too */\r
---- DbgPrint((DPRINT_WINDOWS,\r
---- "WinLdrScanImportDescriptorTable() calling ourselves for %S\n",\r
---- VaToPa((*DataTableEntry)->BaseDllName.Buffer)));\r
---- Status = WinLdrScanImportDescriptorTable(WinLdrBlock, DirectoryPath, *DataTableEntry);\r
----\r
---- if (!Status)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS,\r
---- "WinLdrScanImportDescriptorTable() failed with Status=0x%X\n", Status));\r
---- return Status;\r
---- }\r
----\r
---- return TRUE;\r
----}\r
----\r
----BOOLEAN\r
----WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
---- IN PVOID DllBase,\r
---- IN PVOID ImageBase,\r
---- IN PIMAGE_THUNK_DATA ThunkData)\r
----{\r
---- PIMAGE_EXPORT_DIRECTORY ExportDirectory = NULL;\r
---- BOOLEAN Status;\r
---- ULONG ExportSize;\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): DllBase 0x%X, "\r
---- "ImageBase 0x%X, ThunkData 0x%X\n", DllBase, ImageBase, ThunkData));\r
----\r
---- /* Obtain the export table from the DLL's base */\r
---- if (DllBase == NULL)\r
---- {\r
---- //Print(L"Error, DllBase == NULL!\n");\r
---- return FALSE;\r
---- }\r
---- else\r
---- {\r
---- ExportDirectory =\r
---- (PIMAGE_EXPORT_DIRECTORY)RtlImageDirectoryEntryToData(VaToPa(DllBase),\r
---- TRUE,\r
---- IMAGE_DIRECTORY_ENTRY_EXPORT,\r
---- &ExportSize);\r
---- }\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): ExportDirectory 0x%X\n", ExportDirectory));\r
----\r
---- /* If pointer to Export Directory is */\r
---- if (ExportDirectory == NULL)\r
---- return FALSE;\r
----\r
---- /* Go through each entry in the thunk table and bind it */\r
---- while (((PIMAGE_THUNK_DATA)VaToPa(ThunkData))->u1.AddressOfData != 0)\r
---- {\r
---- /* Bind it */\r
---- Status = WinLdrpBindImportName(\r
---- WinLdrBlock,\r
---- DllBase,\r
---- ImageBase,\r
---- ThunkData,\r
---- ExportDirectory,\r
---- ExportSize,\r
---- FALSE);\r
----\r
---- /* Move to the next entry */\r
---- ThunkData++;\r
----\r
---- /* Return error if binding was unsuccessful */\r
---- if (!Status)\r
---- return Status;\r
---- }\r
----\r
---- /* Return success */\r
---- return TRUE;\r
----}\r
++++/*
++++ * PROJECT: FreeLoader
++++ * LICENSE: GPL - See COPYING in the top level directory
++++ * FILE: freeldr/winldr/peloader.c
++++ * PURPOSE: Provides routines for loading PE files. To be merged with
++++ * arch/i386/loader.c in future
++++ * This article was very handy during development:
++++ * http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/
++++ * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
++++ * The source code in this file is based on the work of respective
++++ * authors of PE loading code in ReactOS and Brian Palmer and
++++ * Alex Ionescu's arch/i386/loader.c, and my research project
++++ * (creating a native EFI loader for Windows)
++++ */
++++
++++/* INCLUDES ***************************************************************/
++++#include <freeldr.h>
++++#include <debug.h>
++++
++++
++++BOOLEAN
++++WinLdrpCompareDllName(IN PCH DllName,
++++ IN PUNICODE_STRING UnicodeName);
++++
++++BOOLEAN
++++WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ IN PVOID DllBase,
++++ IN PVOID ImageBase,
++++ IN PIMAGE_THUNK_DATA ThunkData,
++++ IN PIMAGE_EXPORT_DIRECTORY ExportDirectory,
++++ IN ULONG ExportSize,
++++ IN BOOLEAN ProcessForwards);
++++
++++BOOLEAN
++++WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ PCCH DirectoryPath,
++++ PCH ImportName,
++++ PLDR_DATA_TABLE_ENTRY *DataTableEntry);
++++
++++BOOLEAN
++++WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ IN PVOID DllBase,
++++ IN PVOID ImageBase,
++++ IN PIMAGE_THUNK_DATA ThunkData);
++++
++++
++++
++++/* FUNCTIONS **************************************************************/
++++
++++/* Returns TRUE if DLL has already been loaded - looks in LoadOrderList in LPB */
++++BOOLEAN
++++WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ IN PCH DllName,
++++ OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)
++++{
++++ PLDR_DATA_TABLE_ENTRY DataTableEntry;
++++ LIST_ENTRY *ModuleEntry;
++++
- DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DllName %X, LoadedEntry: %X\n",
- DllName, LoadedEntry));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DllName %X, LoadedEntry: %X\n",
+++++ DllName, LoadedEntry);
++++
++++ /* Just go through each entry in the LoadOrderList and compare loaded module's
++++ name with a given name */
++++ ModuleEntry = WinLdrBlock->LoadOrderListHead.Flink;
++++ while (ModuleEntry != &WinLdrBlock->LoadOrderListHead)
++++ {
++++ /* Get pointer to the current DTE */
++++ DataTableEntry = CONTAINING_RECORD(ModuleEntry,
++++ LDR_DATA_TABLE_ENTRY,
++++ InLoadOrderLinks);
++++
- DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DTE %p, EP %p\n",
- DataTableEntry, DataTableEntry->EntryPoint));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: DTE %p, EP %p\n",
+++++ DataTableEntry, DataTableEntry->EntryPoint);
++++
++++ /* Compare names */
++++ if (WinLdrpCompareDllName(DllName, &DataTableEntry->BaseDllName))
++++ {
++++ /* Yes, found it, report pointer to the loaded module's DTE
++++ to the caller and increase load count for it */
++++ *LoadedEntry = DataTableEntry;
++++ DataTableEntry->LoadCount++;
- DbgPrint((DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: LoadedEntry %X\n", DataTableEntry));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrCheckForLoadedDll: LoadedEntry %X\n", DataTableEntry);
++++ return TRUE;
++++ }
++++
++++ /* Go to the next entry */
++++ ModuleEntry = ModuleEntry->Flink;
++++ }
++++
++++ /* Nothing found */
++++ return FALSE;
++++}
++++
++++BOOLEAN
++++WinLdrScanImportDescriptorTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ IN PCCH DirectoryPath,
++++ IN PLDR_DATA_TABLE_ENTRY ScanDTE)
++++{
++++ PLDR_DATA_TABLE_ENTRY DataTableEntry;
++++ PIMAGE_IMPORT_DESCRIPTOR ImportTable;
++++ ULONG ImportTableSize;
++++ PCH ImportName;
++++ BOOLEAN Status;
++++
++++ /* Get a pointer to the import table of this image */
++++ ImportTable = (PIMAGE_IMPORT_DESCRIPTOR)RtlImageDirectoryEntryToData(VaToPa(ScanDTE->DllBase),
++++ TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
++++
++++ {
++++ UNICODE_STRING BaseName;
++++ BaseName.Buffer = VaToPa(ScanDTE->BaseDllName.Buffer);
++++ BaseName.MaximumLength = ScanDTE->BaseDllName.MaximumLength;
++++ BaseName.Length = ScanDTE->BaseDllName.Length;
- DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%X\n",
- &BaseName, ImportTable));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): %wZ ImportTable = 0x%X\n",
+++++ &BaseName, ImportTable);
++++ }
++++
++++ /* If image doesn't have any import directory - just return success */
++++ if (ImportTable == NULL)
++++ return TRUE;
++++
++++ /* Loop through all entries */
++++ for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
++++ {
++++ /* Get pointer to the name */
++++ ImportName = (PCH)VaToPa(RVA(ScanDTE->DllBase, ImportTable->Name));
- DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): Looking at %s\n", ImportName));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable(): Looking at %s\n", ImportName);
++++
++++ /* In case we get a reference to ourselves - just skip it */
++++ if (WinLdrpCompareDllName(ImportName, &ScanDTE->BaseDllName))
++++ continue;
++++
++++ /* Load the DLL if it is not already loaded */
++++ if (!WinLdrCheckForLoadedDll(WinLdrBlock, ImportName, &DataTableEntry))
++++ {
++++ Status = WinLdrpLoadAndScanReferencedDll(WinLdrBlock,
++++ DirectoryPath,
++++ ImportName,
++++ &DataTableEntry);
++++
++++ if (!Status)
++++ {
- DbgPrint((DPRINT_WINDOWS, "WinLdrpLoadAndScanReferencedDll() failed\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrpLoadAndScanReferencedDll() failed\n");
++++ return Status;
++++ }
++++ }
++++
++++ /* Scan its import address table */
++++ Status = WinLdrpScanImportAddressTable(
++++ WinLdrBlock,
++++ DataTableEntry->DllBase,
++++ ScanDTE->DllBase,
++++ (PIMAGE_THUNK_DATA)RVA(ScanDTE->DllBase, ImportTable->FirstThunk));
++++
++++ if (!Status)
++++ {
- DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable() failed\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrpScanImportAddressTable() failed\n");
++++ return Status;
++++ }
++++ }
++++
++++ return TRUE;
++++}
++++
++++BOOLEAN
++++WinLdrAllocateDataTableEntry(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ IN PCCH BaseDllName,
++++ IN PCCH FullDllName,
++++ IN PVOID BasePA,
++++ OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
++++{
++++ PVOID BaseVA = PaToVa(BasePA);
++++ PWSTR Buffer;
++++ PLDR_DATA_TABLE_ENTRY DataTableEntry;
++++ PIMAGE_NT_HEADERS NtHeaders;
++++ USHORT Length;
++++
++++ /* Allocate memory for a data table entry, zero-initialize it */
++++ DataTableEntry = (PLDR_DATA_TABLE_ENTRY)MmHeapAlloc(sizeof(LDR_DATA_TABLE_ENTRY));
++++ if (DataTableEntry == NULL)
++++ return FALSE;
++++ RtlZeroMemory(DataTableEntry, sizeof(LDR_DATA_TABLE_ENTRY));
++++
++++ /* Get NT headers from the image */
++++ NtHeaders = RtlImageNtHeader(BasePA);
++++
++++ /* Initialize corresponding fields of DTE based on NT headers value */
++++ DataTableEntry->DllBase = BaseVA;
++++ DataTableEntry->SizeOfImage = NtHeaders->OptionalHeader.SizeOfImage;
++++ DataTableEntry->EntryPoint = RVA(BaseVA, NtHeaders->OptionalHeader.AddressOfEntryPoint);
++++ DataTableEntry->SectionPointer = 0;
++++ DataTableEntry->CheckSum = NtHeaders->OptionalHeader.CheckSum;
++++
++++ /* Initialize BaseDllName field (UNICODE_STRING) from the Ansi BaseDllName
++++ by simple conversion - copying each character */
++++ Length = (USHORT)(strlen(BaseDllName) * sizeof(WCHAR));
++++ Buffer = (PWSTR)MmHeapAlloc(Length);
++++ if (Buffer == NULL)
++++ {
++++ MmHeapFree(DataTableEntry);
++++ return FALSE;
++++ }
++++ RtlZeroMemory(Buffer, Length);
++++
++++ DataTableEntry->BaseDllName.Length = Length;
++++ DataTableEntry->BaseDllName.MaximumLength = Length;
++++ DataTableEntry->BaseDllName.Buffer = PaToVa(Buffer);
++++ while (*BaseDllName != 0)
++++ {
++++ *Buffer++ = *BaseDllName++;
++++ }
++++
++++ /* Initialize FullDllName field (UNICODE_STRING) from the Ansi FullDllName
++++ using the same method */
++++ Length = (USHORT)(strlen(FullDllName) * sizeof(WCHAR));
++++ Buffer = (PWSTR)MmHeapAlloc(Length);
++++ if (Buffer == NULL)
++++ {
++++ MmHeapFree(DataTableEntry);
++++ return FALSE;
++++ }
++++ RtlZeroMemory(Buffer, Length);
++++
++++ DataTableEntry->FullDllName.Length = Length;
++++ DataTableEntry->FullDllName.MaximumLength = Length;
++++ DataTableEntry->FullDllName.Buffer = PaToVa(Buffer);
++++ while (*FullDllName != 0)
++++ {
++++ *Buffer++ = *FullDllName++;
++++ }
++++
++++ /* Initialize what's left - LoadCount which is 1, and set Flags so that
++++ we know this entry is processed */
++++ DataTableEntry->Flags = LDRP_ENTRY_PROCESSED;
++++ DataTableEntry->LoadCount = 1;
++++
++++ /* Insert this DTE to a list in the LPB */
++++ InsertTailList(&WinLdrBlock->LoadOrderListHead, &DataTableEntry->InLoadOrderLinks);
++++
++++ /* Save pointer to a newly allocated and initialized entry */
++++ *NewEntry = DataTableEntry;
++++
++++ /* Return success */
++++ return TRUE;
++++}
++++
++++/* WinLdrLoadImage loads the specified image from the file (it doesn't
++++ perform any additional operations on the filename, just directly
++++ calls the file I/O routines), and relocates it so that it's ready
++++ to be used when paging is enabled.
++++ Addressing mode: physical
++++ */
++++BOOLEAN
++++WinLdrLoadImage(IN PCHAR FileName,
++++ TYPE_OF_MEMORY MemoryType,
++++ OUT PVOID *ImageBasePA)
++++{
++++ PFILE FileHandle;
++++ PVOID PhysicalBase;
++++ PVOID VirtualBase = NULL;
++++ UCHAR HeadersBuffer[SECTOR_SIZE * 2];
++++ PIMAGE_NT_HEADERS NtHeaders;
++++ PIMAGE_SECTION_HEADER SectionHeader;
++++ ULONG VirtualSize, SizeOfRawData, NumberOfSections;
++++ BOOLEAN Status;
++++ ULONG i, BytesRead;
++++
++++ CHAR ProgressString[256];
++++
++++ /* Inform user we are loading files */
++++ sprintf(ProgressString, "Loading %s...", FileName);
++++ UiDrawProgressBarCenter(1, 100, ProgressString);
++++
++++ /* Open the image file */
++++ FileHandle = FsOpenFile(FileName);
++++
++++ if (FileHandle == NULL)
++++ {
++++ //Print(L"Can not open the file %s\n",FileName);
++++ UiMessageBox("Can not open the file");
++++ return FALSE;
++++ }
++++
++++ /* Load the first 2 sectors of the image so we can read the PE header */
++++ Status = FsReadFile(FileHandle, SECTOR_SIZE * 2, NULL, HeadersBuffer);
++++ if (!Status)
++++ {
++++ //Print(L"Error reading from file %s\n", FileName);
++++ UiMessageBox("Error reading from file");
++++ FsCloseFile(FileHandle);
++++ return FALSE;
++++ }
++++
++++ /* Now read the MZ header to get the offset to the PE Header */
++++ NtHeaders = RtlImageNtHeader(HeadersBuffer);
++++
++++ if (!NtHeaders)
++++ {
++++ //Print(L"Error - no NT header found in %s\n", FileName);
++++ UiMessageBox("Error - no NT header found");
++++ FsCloseFile(FileHandle);
++++ return FALSE;
++++ }
++++
++++ /* Ensure this is executable image */
++++ if (((NtHeaders->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE) == 0))
++++ {
++++ //Print(L"Not an executable image %s\n", FileName);
++++ UiMessageBox("Not an executable image");
++++ FsCloseFile(FileHandle);
++++ return FALSE;
++++ }
++++
++++ /* Store number of sections to read and a pointer to the first section */
++++ NumberOfSections = NtHeaders->FileHeader.NumberOfSections;
++++ SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
++++
++++ /* Try to allocate this memory, if fails - allocate somewhere else */
++++ PhysicalBase = MmAllocateMemoryAtAddress(NtHeaders->OptionalHeader.SizeOfImage,
++++ (PVOID)((ULONG)NtHeaders->OptionalHeader.ImageBase & (KSEG0_BASE - 1)),
++++ MemoryType);
++++
++++ if (PhysicalBase == NULL)
++++ {
++++ /* It's ok, we don't panic - let's allocate again at any other "low" place */
++++ PhysicalBase = MmAllocateMemoryWithType(NtHeaders->OptionalHeader.SizeOfImage, MemoryType);
++++
++++ if (PhysicalBase == NULL)
++++ {
++++ //Print(L"Failed to alloc pages for image %s\n", FileName);
++++ UiMessageBox("Failed to alloc pages for image");
++++ FsCloseFile(FileHandle);
++++ return FALSE;
++++ }
++++ }
++++
++++ /* This is the real image base - in form of a virtual address */
++++ VirtualBase = PaToVa(PhysicalBase);
++++
- DbgPrint((DPRINT_WINDOWS, "Base PA: 0x%X, VA: 0x%X\n", PhysicalBase, VirtualBase));
+++++ DPRINTM(DPRINT_WINDOWS, "Base PA: 0x%X, VA: 0x%X\n", PhysicalBase, VirtualBase);
++++
++++ /* Set to 0 position and fully load the file image */
++++ FsSetFilePointer(FileHandle, 0);
++++
++++ Status = FsReadFile(FileHandle, NtHeaders->OptionalHeader.SizeOfHeaders, NULL, PhysicalBase);
++++
++++ if (!Status)
++++ {
++++ //Print(L"Error reading headers %s\n", FileName);
++++ UiMessageBox("Error reading headers");
++++ FsCloseFile(FileHandle);
++++ return FALSE;
++++ }
++++
++++ /* Reload the NT Header */
++++ NtHeaders = RtlImageNtHeader(PhysicalBase);
++++
++++ /* Load the first section */
++++ SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
++++
++++ /* Fill output parameters */
++++ *ImageBasePA = PhysicalBase;
++++
++++ /* Walk through each section and read it (check/fix any possible
++++ bad situations, if they arise) */
++++ for (i = 0; i < NumberOfSections; i++)
++++ {
++++ VirtualSize = SectionHeader->Misc.VirtualSize;
++++ SizeOfRawData = SectionHeader->SizeOfRawData;
++++
++++ /* Handle a case when VirtualSize equals 0 */
++++ if (VirtualSize == 0)
++++ VirtualSize = SizeOfRawData;
++++
++++ /* If PointerToRawData is 0, then force its size to be also 0 */
++++ if (SectionHeader->PointerToRawData == 0)
++++ {
++++ SizeOfRawData = 0;
++++ }
++++ else
++++ {
++++ /* Cut the loaded size to the VirtualSize extents */
++++ if (SizeOfRawData > VirtualSize)
++++ SizeOfRawData = VirtualSize;
++++ }
++++
++++ /* Actually read the section (if its size is not 0) */
++++ if (SizeOfRawData != 0)
++++ {
++++ /* Seek to the correct position */
++++ FsSetFilePointer(FileHandle, SectionHeader->PointerToRawData);
++++
- DbgPrint((DPRINT_WINDOWS, "SH->VA: 0x%X\n", SectionHeader->VirtualAddress));
+++++ DPRINTM(DPRINT_WINDOWS, "SH->VA: 0x%X\n", SectionHeader->VirtualAddress);
++++
++++ /* Read this section from the file, size = SizeOfRawData */
++++ Status = FsReadFile(FileHandle, SizeOfRawData, &BytesRead, (PUCHAR)PhysicalBase + SectionHeader->VirtualAddress);
++++
++++ if (!Status && (BytesRead == 0))
++++ {
- DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): Error reading section from file!\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrLoadImage(): Error reading section from file!\n");
++++ break;
++++ }
++++ }
++++
++++ /* Size of data is less than the virtual size - fill up the remainder with zeroes */
++++ if (SizeOfRawData < VirtualSize)
++++ {
- DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage(): SORD %d < VS %d\n", SizeOfRawData, VirtualSize));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrLoadImage(): SORD %d < VS %d\n", SizeOfRawData, VirtualSize);
++++ RtlZeroMemory((PVOID)(SectionHeader->VirtualAddress + (ULONG)PhysicalBase + SizeOfRawData), VirtualSize - SizeOfRawData);
++++ }
++++
++++ SectionHeader++;
++++ }
++++
++++ /* We are done with the file - close it */
++++ FsCloseFile(FileHandle);
++++
++++ /* If loading failed - return right now */
++++ if (!Status)
++++ return FALSE;
++++
++++
++++ /* Relocate the image, if it needs it */
++++ if (NtHeaders->OptionalHeader.ImageBase != (ULONG)VirtualBase)
++++ {
- DbgPrint((DPRINT_WINDOWS, "Relocating %p -> %p\n",
- NtHeaders->OptionalHeader.ImageBase, VirtualBase));
+++++ DPRINTM(DPRINT_WINDOWS, "Relocating %p -> %p\n",
+++++ NtHeaders->OptionalHeader.ImageBase, VirtualBase);
++++ Status = (BOOLEAN)LdrRelocateImageWithBias(PhysicalBase,
++++ (ULONG_PTR)VirtualBase - (ULONG_PTR)PhysicalBase,
++++ "FreeLdr",
++++ TRUE,
++++ TRUE, /* in case of conflict still return success */
++++ FALSE);
++++ }
++++
++++ return Status;
++++}
++++
++++/* PRIVATE FUNCTIONS *******************************************************/
++++
++++/* DllName - physical, UnicodeString->Buffer - virtual */
++++BOOLEAN
++++WinLdrpCompareDllName(IN PCH DllName,
++++ IN PUNICODE_STRING UnicodeName)
++++{
++++ PWSTR Buffer;
++++ UNICODE_STRING UnicodeNamePA;
++++ ULONG i, Length;
++++
++++ /* First obvious check: for length of two names */
++++ Length = strlen(DllName);
++++
++++ UnicodeNamePA.Length = UnicodeName->Length;
++++ UnicodeNamePA.MaximumLength = UnicodeName->MaximumLength;
++++ UnicodeNamePA.Buffer = VaToPa(UnicodeName->Buffer);
- DbgPrint((DPRINT_WINDOWS, "WinLdrpCompareDllName: %s and %wZ, Length = %d "
- "UN->Length %d\n", DllName, &UnicodeNamePA, Length, UnicodeName->Length));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrpCompareDllName: %s and %wZ, Length = %d "
+++++ "UN->Length %d\n", DllName, &UnicodeNamePA, Length, UnicodeName->Length);
++++
++++ if ((Length * sizeof(WCHAR)) > UnicodeName->Length)
++++ return FALSE;
++++
++++ /* Store pointer to unicode string's buffer */
++++ Buffer = VaToPa(UnicodeName->Buffer);
++++
++++ /* Loop character by character */
++++ for (i = 0; i < Length; i++)
++++ {
++++ /* Compare two characters, uppercasing them */
++++ if (toupper(*DllName) != toupper((CHAR)*Buffer))
++++ return FALSE;
++++
++++ /* Move to the next character */
++++ DllName++;
++++ Buffer++;
++++ }
++++
++++ /* Check, if strings either fully match, or match till the "." (w/o extension) */
++++ if ((UnicodeName->Length == Length * sizeof(WCHAR)) || (*Buffer == L'.'))
++++ {
++++ /* Yes they do */
++++ return TRUE;
++++ }
++++
++++ /* Strings don't match, return FALSE */
++++ return FALSE;
++++}
++++
++++BOOLEAN
++++WinLdrpBindImportName(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ IN PVOID DllBase,
++++ IN PVOID ImageBase,
++++ IN PIMAGE_THUNK_DATA ThunkData,
++++ IN PIMAGE_EXPORT_DIRECTORY ExportDirectory,
++++ IN ULONG ExportSize,
++++ IN BOOLEAN ProcessForwards)
++++{
++++ ULONG Ordinal;
++++ PULONG NameTable, FunctionTable;
++++ PUSHORT OrdinalTable;
++++ LONG High, Low, Middle, Result;
++++ ULONG Hint;
++++
- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): DllBase 0x%X, ImageBase 0x%X, ThunkData 0x%X, ExportDirectory 0x%X, ExportSize %d, ProcessForwards 0x%X\n",
- // DllBase, ImageBase, ThunkData, ExportDirectory, ExportSize, ProcessForwards));
+++++ //DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName(): DllBase 0x%X, ImageBase 0x%X, ThunkData 0x%X, ExportDirectory 0x%X, ExportSize %d, ProcessForwards 0x%X\n",
+++++ // DllBase, ImageBase, ThunkData, ExportDirectory, ExportSize, ProcessForwards);
++++
++++ /* Check passed DllBase param */
++++ if(DllBase == NULL)
++++ {
- DbgPrint((DPRINT_WINDOWS, "WARNING: DllBase == NULL!\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "WARNING: DllBase == NULL!\n");
++++ return FALSE;
++++ }
++++
++++ /* Convert all non-critical pointers to PA from VA */
++++ ThunkData = VaToPa(ThunkData);
++++
++++ /* Is the reference by ordinal? */
++++ if (IMAGE_SNAP_BY_ORDINAL(ThunkData->u1.Ordinal) && !ProcessForwards)
++++ {
++++ /* Yes, calculate the ordinal */
++++ Ordinal = (ULONG)(IMAGE_ORDINAL(ThunkData->u1.Ordinal) - (UINT32)ExportDirectory->Base);
- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal));
+++++ //DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal);
++++ }
++++ else
++++ {
++++ /* It's reference by name, we have to look it up in the export directory */
++++ if (!ProcessForwards)
++++ {
++++ /* AddressOfData in thunk entry will become a virtual address (from relative) */
- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD was %p\n", ThunkData->u1.AddressOfData));
+++++ //DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD was %p\n", ThunkData->u1.AddressOfData);
++++ ThunkData->u1.AddressOfData =
++++ (ULONG)RVA(ImageBase, ThunkData->u1.AddressOfData);
- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD became %p\n", ThunkData->u1.AddressOfData));
+++++ //DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName(): ThunkData->u1.AOD became %p\n", ThunkData->u1.AddressOfData);
++++ }
++++
++++ /* Get pointers to Name and Ordinal tables (RVA -> VA) */
++++ NameTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNames));
++++ OrdinalTable = (PUSHORT)VaToPa(RVA(DllBase, ExportDirectory->AddressOfNameOrdinals));
++++
- //DbgPrint((DPRINT_WINDOWS, "NameTable 0x%X, OrdinalTable 0x%X, ED->AddressOfNames 0x%X, ED->AOFO 0x%X\n",
- // NameTable, OrdinalTable, ExportDirectory->AddressOfNames, ExportDirectory->AddressOfNameOrdinals));
+++++ //DPRINTM(DPRINT_WINDOWS, "NameTable 0x%X, OrdinalTable 0x%X, ED->AddressOfNames 0x%X, ED->AOFO 0x%X\n",
+++++ // NameTable, OrdinalTable, ExportDirectory->AddressOfNames, ExportDirectory->AddressOfNameOrdinals);
++++
++++ /* Get the hint, convert it to a physical pointer */
++++ Hint = ((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Hint;
- //DbgPrint((DPRINT_WINDOWS, "HintIndex %d\n", Hint));
+++++ //DPRINTM(DPRINT_WINDOWS, "HintIndex %d\n", Hint);
++++
++++ /* If Hint is less than total number of entries in the export directory,
++++ and import name == export name, then we can just get it from the OrdinalTable */
++++ if (
++++ (Hint < ExportDirectory->NumberOfNames) &&
++++ (
++++ strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]),
++++ (PCHAR)VaToPa( RVA(DllBase, NameTable[Hint])) ) == 0
++++ )
++++ )
++++ {
++++ Ordinal = OrdinalTable[Hint];
- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal));
+++++ //DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName(): Ordinal %d\n", Ordinal);
++++ }
++++ else
++++ {
++++ /* It's not the easy way, we have to lookup import name in the name table.
++++ Let's use a binary search for this task. */
++++
- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() looking up the import name using binary search...\n"));
+++++ //DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName() looking up the import name using binary search...\n");
++++
++++ /* Low boundary is set to 0, and high boundary to the maximum index */
++++ Low = 0;
++++ High = ExportDirectory->NumberOfNames - 1;
++++
++++ /* Perform a binary-search loop */
++++ while (High >= Low)
++++ {
++++ /* Divide by 2 by shifting to the right once */
++++ Middle = (Low + High) >> 1;
++++
++++ /* Compare the names */
++++ Result = strcmp(VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa((PVOID)ThunkData->u1.AddressOfData))->Name[0]),
++++ (PCHAR)VaToPa(RVA(DllBase, NameTable[Middle])));
++++
- /*DbgPrint((DPRINT_WINDOWS, "Binary search: comparing Import '__', Export '%s'\n",*/
+++++ /*DPRINTM(DPRINT_WINDOWS, "Binary search: comparing Import '__', Export '%s'\n",*/
++++ /*VaToPa(&((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name[0]),*/
- /*(PCHAR)VaToPa(RVA(DllBase, NameTable[Middle]))));*/
+++++ /*(PCHAR)VaToPa(RVA(DllBase, NameTable[Middle])));*/
++++
- /*DbgPrint((DPRINT_WINDOWS, "TE->u1.AOD %p, fulladdr %p\n",
+++++ /*DPRINTM(DPRINT_WINDOWS, "TE->u1.AOD %p, fulladdr %p\n",
++++ ThunkData->u1.AddressOfData,
- ((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name ));*/
+++++ ((PIMAGE_IMPORT_BY_NAME)VaToPa(ThunkData->u1.AddressOfData))->Name );*/
++++
++++
++++ /* Depending on result of strcmp, perform different actions */
++++ if (Result < 0)
++++ {
++++ /* Adjust top boundary */
++++ High = Middle - 1;
++++ }
++++ else if (Result > 0)
++++ {
++++ /* Adjust bottom boundary */
++++ Low = Middle + 1;
++++ }
++++ else
++++ {
++++ /* Yay, found it! */
++++ break;
++++ }
++++ }
++++
++++ /* If high boundary is less than low boundary, then no result found */
++++ if (High < Low)
++++ {
++++ //Print(L"Error in binary search\n");
- DbgPrint((DPRINT_WINDOWS, "Error in binary search!\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "Error in binary search!\n");
++++ return FALSE;
++++ }
++++
++++ /* Everything allright, get the ordinal */
++++ Ordinal = OrdinalTable[Middle];
++++
- //DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName() found Ordinal %d\n", Ordinal));
+++++ //DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName() found Ordinal %d\n", Ordinal);
++++ }
++++ }
++++
++++ /* Check ordinal number for validity! */
++++ if (Ordinal >= ExportDirectory->NumberOfFunctions)
++++ {
- DbgPrint((DPRINT_WINDOWS, "Ordinal number is invalid!\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "Ordinal number is invalid!\n");
++++ return FALSE;
++++ }
++++
++++ /* Get a pointer to the function table */
++++ FunctionTable = (PULONG)VaToPa(RVA(DllBase, ExportDirectory->AddressOfFunctions));
++++
++++ /* Save a pointer to the function */
++++ ThunkData->u1.Function = (ULONG)RVA(DllBase, FunctionTable[Ordinal]);
++++
++++ /* Is it a forwarder? (function pointer isn't within the export directory) */
++++ if (((ULONG)VaToPa((PVOID)ThunkData->u1.Function) > (ULONG)ExportDirectory) &&
++++ ((ULONG)VaToPa((PVOID)ThunkData->u1.Function) < ((ULONG)ExportDirectory + ExportSize)))
++++ {
++++ PLDR_DATA_TABLE_ENTRY DataTableEntry;
++++ CHAR ForwardDllName[255];
++++ PIMAGE_EXPORT_DIRECTORY RefExportDirectory;
++++ ULONG RefExportSize;
++++
++++ /* Save the name of the forward dll */
++++ RtlCopyMemory(ForwardDllName, (PCHAR)VaToPa((PVOID)ThunkData->u1.Function), sizeof(ForwardDllName));
++++
++++ /* Strip out its extension */
++++ *strchr(ForwardDllName,'.') = '\0';
++++
- DbgPrint((DPRINT_WINDOWS, "WinLdrpBindImportName(): ForwardDllName %s\n", ForwardDllName));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrpBindImportName(): ForwardDllName %s\n", ForwardDllName);
++++ if (!WinLdrCheckForLoadedDll(WinLdrBlock, ForwardDllName, &DataTableEntry))
++++ {
++++ /* We can't continue if DLL couldn't be loaded, so bomb out with an error */
++++ //Print(L"Error loading DLL!\n");
- DbgPrint((DPRINT_WINDOWS, "Error loading DLL!\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "Error loading DLL!\n");
++++ return FALSE;
++++ }
++++
++++ /* Get pointer to the export directory of loaded DLL */
++++ RefExportDirectory = (PIMAGE_EXPORT_DIRECTORY)
++++ RtlImageDirectoryEntryToData(VaToPa(DataTableEntry->DllBase),
++++ TRUE,
++++ IMAGE_DIRECTORY_ENTRY_EXPORT,
++++ &RefExportSize);
++++
++++ /* Fail if it's NULL */
++++ if (RefExportDirectory)
++++ {
++++ UCHAR Buffer[128];
++++ IMAGE_THUNK_DATA RefThunkData;
++++ PIMAGE_IMPORT_BY_NAME ImportByName;
++++ PCHAR ImportName;
++++ BOOLEAN Status;
++++
++++ /* Get pointer to the import name */
++++ ImportName = strchr((PCHAR)VaToPa((PVOID)ThunkData->u1.Function), '.') + 1;
++++
++++ /* Create a IMAGE_IMPORT_BY_NAME structure, pointing to the local Buffer */
++++ ImportByName = (PIMAGE_IMPORT_BY_NAME)Buffer;
++++
++++ /* Fill the name with the import name */
++++ RtlCopyMemory(ImportByName->Name, ImportName, strlen(ImportName)+1);
++++
++++ /* Set Hint to 0 */
++++ ImportByName->Hint = 0;
++++
++++ /* And finally point ThunkData's AddressOfData to that structure */
++++ RefThunkData.u1.AddressOfData = (ULONG)ImportByName;
++++
++++ /* And recursively call ourselves */
++++ Status = WinLdrpBindImportName(
++++ WinLdrBlock,
++++ DataTableEntry->DllBase,
++++ ImageBase,
++++ &RefThunkData,
++++ RefExportDirectory,
++++ RefExportSize,
++++ TRUE);
++++
++++ /* Fill out the ThunkData with data from RefThunkData */
++++ ThunkData->u1 = RefThunkData.u1;
++++
++++ /* Return what we got from the recursive call */
++++ return Status;
++++ }
++++ else
++++ {
++++ /* Fail if ExportDirectory is NULL */
++++ return FALSE;
++++ }
++++ }
++++
++++ /* Success! */
++++ return TRUE;
++++}
++++
++++BOOLEAN
++++WinLdrpLoadAndScanReferencedDll(PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ PCCH DirectoryPath,
++++ PCH ImportName,
++++ PLDR_DATA_TABLE_ENTRY *DataTableEntry)
++++{
++++ CHAR FullDllName[256];
++++ BOOLEAN Status;
++++ PVOID BasePA;
++++
++++ /* Prepare the full path to the file to be loaded */
++++ strcpy(FullDllName, DirectoryPath);
++++ strcat(FullDllName, ImportName);
++++
- DbgPrint((DPRINT_WINDOWS, "Loading referenced DLL: %s\n", FullDllName));
+++++ DPRINTM(DPRINT_WINDOWS, "Loading referenced DLL: %s\n", FullDllName);
++++ //Print(L"Loading referenced DLL: %s\n", FullDllName);
++++
++++ /* Load the image */
++++ Status = WinLdrLoadImage(FullDllName, LoaderHalCode, &BasePA);
++++
++++ if (!Status)
++++ {
- DbgPrint((DPRINT_WINDOWS, "WinLdrLoadImage() failed\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrLoadImage() failed\n");
++++ return Status;
++++ }
++++
++++ /* Allocate DTE for newly loaded DLL */
++++ Status = WinLdrAllocateDataTableEntry(WinLdrBlock,
++++ ImportName,
++++ FullDllName,
++++ BasePA,
++++ DataTableEntry);
++++
++++ if (!Status)
++++ {
- DbgPrint((DPRINT_WINDOWS,
- "WinLdrAllocateDataTableEntry() failed with Status=0x%X\n", Status));
+++++ DPRINTM(DPRINT_WINDOWS,
+++++ "WinLdrAllocateDataTableEntry() failed with Status=0x%X\n", Status);
++++ return Status;
++++ }
++++
++++ /* Scan its dependencies too */
- DbgPrint((DPRINT_WINDOWS,
+++++ DPRINTM(DPRINT_WINDOWS,
++++ "WinLdrScanImportDescriptorTable() calling ourselves for %S\n",
- VaToPa((*DataTableEntry)->BaseDllName.Buffer)));
+++++ VaToPa((*DataTableEntry)->BaseDllName.Buffer));
++++ Status = WinLdrScanImportDescriptorTable(WinLdrBlock, DirectoryPath, *DataTableEntry);
++++
++++ if (!Status)
++++ {
- DbgPrint((DPRINT_WINDOWS,
- "WinLdrScanImportDescriptorTable() failed with Status=0x%X\n", Status));
+++++ DPRINTM(DPRINT_WINDOWS,
+++++ "WinLdrScanImportDescriptorTable() failed with Status=0x%X\n", Status);
++++ return Status;
++++ }
++++
++++ return TRUE;
++++}
++++
++++BOOLEAN
++++WinLdrpScanImportAddressTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
++++ IN PVOID DllBase,
++++ IN PVOID ImageBase,
++++ IN PIMAGE_THUNK_DATA ThunkData)
++++{
++++ PIMAGE_EXPORT_DIRECTORY ExportDirectory = NULL;
++++ BOOLEAN Status;
++++ ULONG ExportSize;
++++
- DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): DllBase 0x%X, "
- "ImageBase 0x%X, ThunkData 0x%X\n", DllBase, ImageBase, ThunkData));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): DllBase 0x%X, "
+++++ "ImageBase 0x%X, ThunkData 0x%X\n", DllBase, ImageBase, ThunkData);
++++
++++ /* Obtain the export table from the DLL's base */
++++ if (DllBase == NULL)
++++ {
++++ //Print(L"Error, DllBase == NULL!\n");
++++ return FALSE;
++++ }
++++ else
++++ {
++++ ExportDirectory =
++++ (PIMAGE_EXPORT_DIRECTORY)RtlImageDirectoryEntryToData(VaToPa(DllBase),
++++ TRUE,
++++ IMAGE_DIRECTORY_ENTRY_EXPORT,
++++ &ExportSize);
++++ }
++++
- DbgPrint((DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): ExportDirectory 0x%X\n", ExportDirectory));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrpScanImportAddressTable(): ExportDirectory 0x%X\n", ExportDirectory);
++++
++++ /* If pointer to Export Directory is */
++++ if (ExportDirectory == NULL)
++++ return FALSE;
++++
++++ /* Go through each entry in the thunk table and bind it */
++++ while (((PIMAGE_THUNK_DATA)VaToPa(ThunkData))->u1.AddressOfData != 0)
++++ {
++++ /* Bind it */
++++ Status = WinLdrpBindImportName(
++++ WinLdrBlock,
++++ DllBase,
++++ ImageBase,
++++ ThunkData,
++++ ExportDirectory,
++++ ExportSize,
++++ FALSE);
++++
++++ /* Move to the next entry */
++++ ThunkData++;
++++
++++ /* Return error if binding was unsuccessful */
++++ if (!Status)
++++ return Status;
++++ }
++++
++++ /* Return success */
++++ return TRUE;
++++}
strcpy(SystemRoot, &SystemPath[PathSeparator]);
strcat(SystemRoot, "\\");
----- DbgPrint((DPRINT_WINDOWS, "ArcBoot: %s\n", ArcBoot));
----- DbgPrint((DPRINT_WINDOWS, "SystemRoot: %s\n", SystemRoot));
----- DbgPrint((DPRINT_WINDOWS, "Options: %s\n", Options));
+++++ DPRINTM(DPRINT_WINDOWS, "ArcBoot: %s\n", ArcBoot);
+++++ DPRINTM(DPRINT_WINDOWS, "SystemRoot: %s\n", SystemRoot);
+++++ DPRINTM(DPRINT_WINDOWS, "Options: %s\n", Options);
/* Fill Arc BootDevice */
LoaderBlock->ArcBootDeviceName = MmHeapAlloc(strlen(ArcBoot)+1);
*(DriverNamePos+1) = 0;
}
----- DbgPrint((DPRINT_WINDOWS, "DriverPath: %s, DllName: %s, LPB %p\n", DriverPath, DllName, LoaderBlock));
+++++ DPRINTM(DPRINT_WINDOWS, "DriverPath: %s, DllName: %s, LPB %p\n", DriverPath, DllName, LoaderBlock);
// Check if driver is already loaded
Status = WinLdrAllocateDataTableEntry(LoaderBlock, DllName, DllName, DriverBase, DriverDTE);
if (!Status)
{
----- DbgPrint((DPRINT_WINDOWS, "WinLdrAllocateDataTableEntry() failed\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrAllocateDataTableEntry() failed\n");
return FALSE;
}
Status = WinLdrScanImportDescriptorTable(LoaderBlock, FullPath, *DriverDTE);
if (!Status)
{
----- DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable() failed for %s\n",
----- FullPath));
+++++ DPRINTM(DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable() failed for %s\n",
+++++ FullPath);
return FALSE;
}
while (NextBd != &LoaderBlock->BootDriverListHead)
{
---- BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry);
++++ BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
----- DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
- BootDriver->LdrEntry, &BootDriver->RegistryPath));
---- BootDriver->DataTableEntry, &BootDriver->RegistryPath));
+++++ DPRINTM(DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
+++++ BootDriver->LdrEntry, &BootDriver->RegistryPath);
// Paths are relative (FIXME: Are they always relative?)
PVOID WinLdrLoadModule(PCSTR ModuleName, ULONG *Size,
TYPE_OF_MEMORY MemoryType)
{
---- PFILE FileHandle;\r
---- PVOID PhysicalBase;\r
---- ULONG FileSize;\r
---- BOOLEAN Status;\r
----\r
---- //CHAR ProgressString[256];\r
----\r
---- /* Inform user we are loading files */\r
---- //sprintf(ProgressString, "Loading %s...", FileName);\r
---- //UiDrawProgressBarCenter(1, 100, ProgressString);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Loading module %s\n", ModuleName));\r
---- *Size = 0;\r
----\r
---- /* Open the image file */\r
---- FileHandle = FsOpenFile(ModuleName);\r
----\r
---- if (FileHandle == NULL)\r
---- {\r
---- /* In case of errors, we just return, without complaining to the user */\r
---- return NULL;\r
---- }\r
----\r
---- /* Get this file's size */\r
---- FileSize = FsGetFileSize(FileHandle);\r
---- *Size = FileSize;\r
----\r
---- /* Allocate memory */\r
---- PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);\r
---- if (PhysicalBase == NULL)\r
---- {\r
---- FsCloseFile(FileHandle);\r
---- return NULL;\r
---- }\r
----\r
---- /* Load whole file */\r
---- Status = FsReadFile(FileHandle, FileSize, NULL, PhysicalBase);\r
---- if (!Status)\r
---- {\r
---- FsCloseFile(FileHandle);\r
---- return NULL;\r
---- }\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize));\r
----\r
---- /* We are done with the file - close it */\r
---- FsCloseFile(FileHandle);\r
----\r
---- return PhysicalBase;\r
++++ PFILE FileHandle;
++++ PVOID PhysicalBase;
++++ ULONG FileSize;
++++ BOOLEAN Status;
++++
++++ //CHAR ProgressString[256];
++++
++++ /* Inform user we are loading files */
++++ //sprintf(ProgressString, "Loading %s...", FileName);
++++ //UiDrawProgressBarCenter(1, 100, ProgressString);
++++
- DbgPrint((DPRINT_WINDOWS, "Loading module %s\n", ModuleName));
+++++ DPRINTM(DPRINT_WINDOWS, "Loading module %s\n", ModuleName);
++++ *Size = 0;
++++
++++ /* Open the image file */
++++ FileHandle = FsOpenFile(ModuleName);
++++
++++ if (FileHandle == NULL)
++++ {
++++ /* In case of errors, we just return, without complaining to the user */
++++ return NULL;
++++ }
++++
++++ /* Get this file's size */
++++ FileSize = FsGetFileSize(FileHandle);
++++ *Size = FileSize;
++++
++++ /* Allocate memory */
++++ PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
++++ if (PhysicalBase == NULL)
++++ {
++++ FsCloseFile(FileHandle);
++++ return NULL;
++++ }
++++
++++ /* Load whole file */
++++ Status = FsReadFile(FileHandle, FileSize, NULL, PhysicalBase);
++++ if (!Status)
++++ {
++++ FsCloseFile(FileHandle);
++++ return NULL;
++++ }
++++
- DbgPrint((DPRINT_WINDOWS, "Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize));
+++++ DPRINTM(DPRINT_WINDOWS, "Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
++++
++++ /* We are done with the file - close it */
++++ FsCloseFile(FileHandle);
++++
++++ return PhysicalBase;
}
BootPath[strlen(BootPath)] != '\\')
strcat(BootPath, "\\");
----- DbgPrint((DPRINT_WINDOWS,"SystemRoot: '%s'\n", BootPath));
+++++ DPRINTM(DPRINT_WINDOWS,"SystemRoot: '%s'\n", BootPath);
/* Allocate and minimalistic-initialize LPB */
AllocateAndInitLPB(&LoaderBlock);
strcpy(FileName, BootPath);
strcat(FileName, "SYSTEM32\\NTOSKRNL.EXE");
Status = WinLdrLoadImage(FileName, LoaderSystemCode, &NtosBase);
----- DbgPrint((DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase));
+++++ DPRINTM(DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase);
/* Load HAL */
strcpy(FileName, BootPath);
strcat(FileName, "SYSTEM32\\HAL.DLL");
Status = WinLdrLoadImage(FileName, LoaderHalCode, &HalBase);
----- DbgPrint((DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase));
+++++ DPRINTM(DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase);
/* Load kernel-debugger support dll */
if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
strcpy(FileName, BootPath);
strcat(FileName, "SYSTEM32\\KDCOM.DLL");
Status = WinLdrLoadImage(FileName, LoaderBootDriver, &KdComBase);
----- DbgPrint((DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase));
+++++ DPRINTM(DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase);
}
/* Allocate data table entries for above-loaded modules */
/* Load Hive, and then NLS data, OEM font, and prepare boot drivers list */
Status = WinLdrLoadAndScanSystemHive(LoaderBlock, BootPath);
----- DbgPrint((DPRINT_WINDOWS, "SYSTEM hive loaded and scanned with status %d\n", Status));
+++++ DPRINTM(DPRINT_WINDOWS, "SYSTEM hive loaded and scanned with status %d\n", Status);
/* Load boot drivers */
Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
----- DbgPrint((DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status));
+++++ DPRINTM(DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status);
/* Alloc PCR, TSS, do magic things with the GDT/IDT */
WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
/* Save final value of LoaderPagesSpanned */
LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
----- DbgPrint((DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
----- KiSystemStartup, LoaderBlockVA));
+++++ DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
+++++ KiSystemStartup, LoaderBlockVA);
WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
WinLdrpDumpBootDriver(LoaderBlockVA);
{
MemoryDescriptor = CONTAINING_RECORD(NextMd, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
----- DbgPrint((DPRINT_WINDOWS, "BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
----- MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType));
+++++ DPRINTM(DPRINT_WINDOWS, "BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
+++++ MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
NextMd = MemoryDescriptor->ListEntry.Flink;
}
while (NextBd != &LoaderBlock->BootDriverListHead)
{
---- BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry);
++++ BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
----- DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
- BootDriver->LdrEntry, &BootDriver->RegistryPath));
---- BootDriver->DataTableEntry, &BootDriver->RegistryPath));
+++++ DPRINTM(DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
+++++ BootDriver->LdrEntry, &BootDriver->RegistryPath);
---- NextBd = BootDriver->ListEntry.Flink;
++++ NextBd = BootDriver->Link.Flink;
}
}
{
ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
----- DbgPrint((DPRINT_WINDOWS, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
----- ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature));
+++++ DPRINTM(DPRINT_WINDOWS, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
+++++ ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
NextBd = ArcDisk->ListEntry.Flink;
}
----/*\r
---- * PROJECT: EFI Windows Loader\r
---- * LICENSE: GPL - See COPYING in the top level directory\r
---- * FILE: freeldr/winldr/wlmemory.c\r
---- * PURPOSE: Memory related routines\r
---- * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)\r
---- */\r
----\r
----/* INCLUDES ***************************************************************/\r
----\r
----#include <freeldr.h>\r
----\r
----#include <ndk/asm.h>\r
----#include <debug.h>\r
----\r
----extern ULONG TotalNLSSize;\r
----extern ULONG LoaderPagesSpanned;\r
----\r
----// This is needed because headers define wrong one for ReactOS\r
----#undef KIP0PCRADDRESS\r
----#define KIP0PCRADDRESS 0xffdff000\r
----\r
----#define HYPER_SPACE_ENTRY 0x300\r
----\r
----PCHAR MemTypeDesc[] = {\r
---- "ExceptionBlock ", // ?\r
---- "SystemBlock ", // ?\r
---- "Free ",\r
---- "Bad ", // used\r
---- "LoadedProgram ", // == Free\r
---- "FirmwareTemporary ", // == Free\r
---- "FirmwarePermanent ", // == Bad\r
---- "OsloaderHeap ", // used\r
---- "OsloaderStack ", // == Free\r
---- "SystemCode ",\r
---- "HalCode ",\r
---- "BootDriver ", // not used\r
---- "ConsoleInDriver ", // ?\r
---- "ConsoleOutDriver ", // ?\r
---- "StartupDpcStack ", // ?\r
---- "StartupKernelStack", // ?\r
---- "StartupPanicStack ", // ?\r
---- "StartupPcrPage ", // ?\r
---- "StartupPdrPage ", // ?\r
---- "RegistryData ", // used\r
---- "MemoryData ", // not used\r
---- "NlsData ", // used\r
---- "SpecialMemory ", // == Bad\r
---- "BBTMemory " // == Bad\r
---- };\r
----\r
----VOID\r
----WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);\r
----\r
----\r
----VOID\r
----MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,\r
---- ULONG BasePage,\r
---- ULONG PageCount,\r
---- ULONG Type);\r
----VOID\r
----WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,\r
---- IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor);\r
----\r
----VOID\r
----WinLdrRemoveDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR Descriptor);\r
----\r
----VOID\r
----WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss);\r
----\r
----// This is needed only for SetProcessorContext routine\r
----#pragma pack(2)\r
---- typedef struct\r
---- {\r
---- USHORT Limit;\r
---- ULONG Base;\r
---- } GDTIDT;\r
----#pragma pack(4)\r
----\r
----// this is needed for new IDT filling\r
----#if 0\r
----extern ULONG_PTR i386DivideByZero;\r
----extern ULONG_PTR i386DebugException;\r
----extern ULONG_PTR i386NMIException;\r
----extern ULONG_PTR i386Breakpoint;\r
----extern ULONG_PTR i386Overflow;\r
----extern ULONG_PTR i386BoundException;\r
----extern ULONG_PTR i386InvalidOpcode;\r
----extern ULONG_PTR i386FPUNotAvailable;\r
----extern ULONG_PTR i386DoubleFault;\r
----extern ULONG_PTR i386CoprocessorSegment;\r
----extern ULONG_PTR i386InvalidTSS;\r
----extern ULONG_PTR i386SegmentNotPresent;\r
----extern ULONG_PTR i386StackException;\r
----extern ULONG_PTR i386GeneralProtectionFault;\r
----extern ULONG_PTR i386PageFault; // exc 14\r
----extern ULONG_PTR i386CoprocessorError; // exc 16\r
----extern ULONG_PTR i386AlignmentCheck; // exc 17\r
----#endif\r
----\r
----/* GLOBALS ***************************************************************/\r
----\r
----PHARDWARE_PTE PDE;\r
----PHARDWARE_PTE HalPageTable;\r
----\r
----PUCHAR PhysicalPageTablesBuffer;\r
----PUCHAR KernelPageTablesBuffer;\r
----ULONG PhysicalPageTables;\r
----ULONG KernelPageTables;\r
----\r
----MEMORY_ALLOCATION_DESCRIPTOR *Mad;\r
----ULONG MadCount = 0;\r
----\r
----\r
----/* FUNCTIONS **************************************************************/\r
----\r
----BOOLEAN\r
----MempAllocatePageTables()\r
----{\r
---- ULONG NumPageTables, TotalSize;\r
---- PUCHAR Buffer;\r
---- // It's better to allocate PDE + PTEs contigiuos\r
----\r
---- // Max number of entries = MaxPageNum >> 10\r
---- // FIXME: This is a number to describe ALL physical memory\r
---- // and windows doesn't expect ALL memory mapped...\r
---- NumPageTables = (GetSystemMemorySize() >> MM_PAGE_SHIFT) >> 10;\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "NumPageTables = %d\n", NumPageTables));\r
----\r
---- // Allocate memory block for all these things:\r
---- // PDE, HAL mapping page table, physical mapping, kernel mapping\r
---- TotalSize = (1+1+NumPageTables*2)*MM_PAGE_SIZE;\r
----\r
---- // PDE+HAL+KernelPTEs == MemoryData\r
---- Buffer = MmAllocateMemoryWithType(\r
---- TotalSize - NumPageTables*MM_PAGE_SIZE, LoaderMemoryData);\r
----\r
---- // Physical PTEs = FirmwareTemporary\r
---- PhysicalPageTablesBuffer = MmAllocateMemoryWithType(\r
---- NumPageTables*MM_PAGE_SIZE, LoaderFirmwareTemporary);\r
----\r
---- if (Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) !=\r
---- PhysicalPageTablesBuffer)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "There was a problem allocating two adjacent blocks of memory!"));\r
---- }\r
----\r
---- if (Buffer == NULL || PhysicalPageTablesBuffer == NULL)\r
---- {\r
---- UiMessageBox("Impossible to allocate memory block for page tables!");\r
---- return FALSE;\r
---- }\r
----\r
---- // Zero all this memory block\r
---- RtlZeroMemory(Buffer, TotalSize);\r
----\r
---- // Set up pointers correctly now\r
---- PDE = (PHARDWARE_PTE)Buffer;\r
----\r
---- // Map the page directory at 0xC0000000 (maps itself)\r
---- PDE[HYPER_SPACE_ENTRY].PageFrameNumber = (ULONG)PDE >> MM_PAGE_SHIFT;\r
---- PDE[HYPER_SPACE_ENTRY].Valid = 1;\r
---- PDE[HYPER_SPACE_ENTRY].Write = 1;\r
----\r
---- // The last PDE slot is allocated for HAL's memory mapping (Virtual Addresses 0xFFC00000 - 0xFFFFFFFF)\r
---- HalPageTable = (PHARDWARE_PTE)&Buffer[MM_PAGE_SIZE*1];\r
----\r
---- // Map it\r
---- PDE[1023].PageFrameNumber = (ULONG)HalPageTable >> MM_PAGE_SHIFT;\r
---- PDE[1023].Valid = 1;\r
---- PDE[1023].Write = 1;\r
----\r
---- // Store pointer to the table for easier access\r
---- KernelPageTablesBuffer = &Buffer[MM_PAGE_SIZE*2];\r
----\r
---- // Zero counters of page tables used\r
---- PhysicalPageTables = 0;\r
---- KernelPageTables = 0;\r
----\r
---- return TRUE;\r
----}\r
----\r
----VOID\r
----MempAllocatePTE(ULONG Entry, PHARDWARE_PTE *PhysicalPT, PHARDWARE_PTE *KernelPT)\r
----{\r
---- //Print(L"Creating PDE Entry %X\n", Entry);\r
----\r
---- // Identity mapping\r
---- *PhysicalPT = (PHARDWARE_PTE)&PhysicalPageTablesBuffer[PhysicalPageTables*MM_PAGE_SIZE];\r
---- PhysicalPageTables++;\r
----\r
---- PDE[Entry].PageFrameNumber = (ULONG)*PhysicalPT >> MM_PAGE_SHIFT;\r
---- PDE[Entry].Valid = 1;\r
---- PDE[Entry].Write = 1;\r
----\r
---- if (Entry+(KSEG0_BASE >> 22) > 1023)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "WARNING! Entry: %X > 1023\n", Entry+(KSEG0_BASE >> 22)));\r
---- }\r
----\r
---- // Kernel-mode mapping\r
---- *KernelPT = (PHARDWARE_PTE)&KernelPageTablesBuffer[KernelPageTables*MM_PAGE_SIZE];\r
---- KernelPageTables++;\r
----\r
---- PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber = ((ULONG)*KernelPT >> MM_PAGE_SHIFT);\r
---- PDE[Entry+(KSEG0_BASE >> 22)].Valid = 1;\r
---- PDE[Entry+(KSEG0_BASE >> 22)].Write = 1;\r
----}\r
----\r
----BOOLEAN\r
----MempSetupPaging(IN ULONG StartPage,\r
---- IN ULONG NumberOfPages)\r
----{\r
---- PHARDWARE_PTE PhysicalPT;\r
---- PHARDWARE_PTE KernelPT;\r
---- ULONG Entry, Page;\r
----\r
---- //Print(L"MempSetupPaging: SP 0x%X, Number: 0x%X\n", StartPage, NumberOfPages);\r
---- \r
---- // HACK\r
---- if (StartPage+NumberOfPages >= 0x80000)\r
---- {\r
---- //\r
---- // We can't map this as it requires more than 1 PDE\r
---- // and in fact it's not possible at all ;)\r
---- //\r
---- //Print(L"skipping...\n");\r
---- return TRUE;\r
---- }\r
----\r
---- //\r
---- // Now actually set up the page tables for identity mapping\r
---- //\r
---- for (Page=StartPage; Page < StartPage+NumberOfPages; Page++)\r
---- {\r
---- Entry = Page >> 10;\r
----\r
---- if (((PULONG)PDE)[Entry] == 0)\r
---- {\r
---- MempAllocatePTE(Entry, &PhysicalPT, &KernelPT);\r
---- }\r
---- else\r
---- {\r
---- PhysicalPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT);\r
---- KernelPT = (PHARDWARE_PTE)(PDE[Entry+(KSEG0_BASE >> 22)].PageFrameNumber << MM_PAGE_SHIFT);\r
---- }\r
----\r
---- if (Page == 0)\r
---- {\r
---- PhysicalPT[Page & 0x3ff].PageFrameNumber = Page;\r
---- PhysicalPT[Page & 0x3ff].Valid = 0;\r
---- PhysicalPT[Page & 0x3ff].Write = 0;\r
----\r
---- KernelPT[Page & 0x3ff].PageFrameNumber = Page;\r
---- KernelPT[Page & 0x3ff].Valid = 0;\r
---- KernelPT[Page & 0x3ff].Write = 0;\r
---- }\r
---- else\r
---- {\r
---- PhysicalPT[Page & 0x3ff].PageFrameNumber = Page;\r
---- PhysicalPT[Page & 0x3ff].Valid = 1;\r
---- PhysicalPT[Page & 0x3ff].Write = 1;\r
----\r
---- KernelPT[Page & 0x3ff].PageFrameNumber = Page;\r
---- KernelPT[Page & 0x3ff].Valid = 1;\r
---- KernelPT[Page & 0x3ff].Write = 1;\r
---- }\r
---- }\r
----\r
---- return TRUE;\r
----}\r
----\r
----VOID\r
----MempDisablePages()\r
----{\r
---- int i;\r
----\r
---- //\r
---- // We need to delete kernel mapping from memory areas which are\r
---- // marked as Special or Permanent memory (thus non-accessible)\r
---- //\r
----\r
---- for (i=0; i<MadCount; i++)\r
---- {\r
---- ULONG StartPage, EndPage, Page;\r
----\r
---- StartPage = Mad[i].BasePage;\r
---- EndPage = Mad[i].BasePage + Mad[i].PageCount;\r
----\r
---- if (Mad[i].MemoryType == LoaderFirmwarePermanent ||\r
---- Mad[i].MemoryType == LoaderSpecialMemory ||\r
---- Mad[i].MemoryType == LoaderFree ||\r
---- (Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LoaderPagesSpanned) ||\r
---- Mad[i].MemoryType == LoaderOsloaderStack ||\r
---- Mad[i].MemoryType == LoaderLoadedProgram)\r
---- {\r
---- //\r
---- // But, the first megabyte of memory always stays!\r
---- // And, to tell the truth, we don't care about what's higher\r
---- // than LoaderPagesSpanned\r
---- if (Mad[i].MemoryType == LoaderFirmwarePermanent ||\r
---- Mad[i].MemoryType == LoaderSpecialMemory)\r
---- {\r
---- if (StartPage < 0x100)\r
---- StartPage = 0x100;\r
----\r
---- if (EndPage > LoaderPagesSpanned)\r
---- EndPage = LoaderPagesSpanned;\r
---- }\r
----\r
---- for (Page = StartPage; Page < EndPage; Page++)\r
---- {\r
---- PHARDWARE_PTE KernelPT;\r
---- ULONG Entry = (Page >> 10) + (KSEG0_BASE >> 22);\r
----\r
---- if (PDE[Entry].Valid)\r
---- {\r
---- KernelPT = (PHARDWARE_PTE)(PDE[Entry].PageFrameNumber << MM_PAGE_SHIFT);\r
----\r
---- if (KernelPT)\r
---- {\r
---- KernelPT[Page & 0x3ff].PageFrameNumber = 0;\r
---- KernelPT[Page & 0x3ff].Valid = 0;\r
---- KernelPT[Page & 0x3ff].Write = 0;\r
---- }\r
---- }\r
---- }\r
---- }\r
---- }\r
----}\r
----\r
----VOID\r
----MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,\r
---- ULONG BasePage,\r
---- ULONG PageCount,\r
---- ULONG Type)\r
----{\r
---- BOOLEAN Status;\r
----\r
---- //\r
---- // Check for some weird stuff at the top\r
---- //\r
---- if (BasePage + PageCount > 0xF0000)\r
---- {\r
---- //\r
---- // Just skip this, without even adding to MAD list\r
---- //\r
---- return;\r
---- }\r
----\r
---- //\r
---- // Set Base page, page count and type\r
---- //\r
---- Mad[MadCount].BasePage = BasePage;\r
---- Mad[MadCount].PageCount = PageCount;\r
---- Mad[MadCount].MemoryType = Type;\r
----\r
---- //\r
---- // Check if it's more than the allowed for OS loader\r
---- // if yes - don't map the pages, just add as FirmwareTemporary\r
---- //\r
---- if (BasePage + PageCount > LoaderPagesSpanned)\r
---- {\r
---- if (Mad[MadCount].MemoryType != LoaderSpecialMemory &&\r
---- Mad[MadCount].MemoryType != LoaderFirmwarePermanent &&\r
---- Mad[MadCount].MemoryType != LoaderFree)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "Setting page %x %x to Temporary from %d\n",\r
---- BasePage, PageCount, Mad[MadCount].MemoryType));\r
---- Mad[MadCount].MemoryType = LoaderFirmwareTemporary;\r
---- }\r
----\r
---- WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);\r
---- MadCount++;\r
----\r
---- return;\r
---- }\r
---- \r
---- //\r
---- // Add descriptor\r
---- //\r
---- WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);\r
---- MadCount++;\r
----\r
---- //\r
---- // Map it (don't map low 1Mb because it was already contigiously\r
---- // mapped in WinLdrTurnOnPaging)\r
---- //\r
---- if (BasePage >= 0x100)\r
---- {\r
---- Status = MempSetupPaging(BasePage, PageCount);\r
---- if (!Status)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging\n"));\r
---- return;\r
---- }\r
---- }\r
----}\r
----\r
----#ifdef _M_IX86\r
----\r
----BOOLEAN LocalAPIC = FALSE;\r
----ULONG_PTR APICAddress = 0;\r
----\r
----VOID\r
----WinLdrpMapApic()\r
----{\r
---- /* Check if we have a local APIC */\r
---- asm(".intel_syntax noprefix\n");\r
---- asm("mov eax, 1\n");\r
---- asm("cpuid\n");\r
---- asm("shr edx, 9\n");\r
---- asm("and edx, 0x1\n");\r
---- asm("mov _LocalAPIC, edx\n");\r
---- asm(".att_syntax\n");\r
----\r
---- /* If there is no APIC, just return */\r
---- if (!LocalAPIC)\r
---- return;\r
----\r
---- asm(".intel_syntax noprefix\n");\r
---- asm("mov ecx, 0x1B\n");\r
---- asm("rdmsr\n");\r
---- asm("mov edx, eax\n");\r
---- asm("and edx, 0xFFFFF000\n");\r
---- asm("mov _APICAddress, edx");\r
---- asm(".att_syntax\n");\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Local APIC detected at address 0x%x\n",\r
---- APICAddress));\r
----\r
---- /* Map it */\r
---- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber\r
---- = APICAddress >> MM_PAGE_SHIFT;\r
---- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1;\r
---- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1;\r
---- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].WriteThrough = 1;\r
---- HalPageTable[(APIC_BASE - 0xFFC00000) >> MM_PAGE_SHIFT].CacheDisable = 1;\r
----}\r
----#else\r
----VOID\r
----WinLdrpMapApic()\r
----{\r
---- /* Implement it for another arch */\r
----}\r
----#endif\r
----\r
----BOOLEAN\r
----WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,\r
---- ULONG PcrBasePage,\r
---- ULONG TssBasePage,\r
---- PVOID GdtIdt)\r
----{\r
---- ULONG i, PagesCount, MemoryMapSizeInPages;\r
---- ULONG LastPageIndex, LastPageType, MemoryMapStartPage;\r
---- PPAGE_LOOKUP_TABLE_ITEM MemoryMap;\r
---- ULONG NoEntries;\r
---- PKTSS Tss;\r
---- BOOLEAN Status;\r
----\r
---- //\r
---- // Creating a suitable memory map for the Windows can be tricky, so let's\r
---- // give a few advices:\r
---- // 1) One must not map the whole available memory pages to PDE!\r
---- // Map only what's needed - 16Mb, 24Mb, 32Mb max I think,\r
---- // thus occupying 4, 6 or 8 PDE entries for identical mapping,\r
---- // the same quantity for KSEG0_BASE mapping, one more entry for\r
---- // hyperspace and one more entry for HAL physical pages mapping.\r
---- // 2) Memory descriptors must map *the whole* physical memory\r
---- // showing any memory above 16/24/32 as FirmwareTemporary\r
---- //\r
---- // 3) Overall memory blocks count must not exceed 30 (?? why?)\r
---- //\r
----\r
---- //\r
---- // During MmInitMachineDependent, the kernel zeroes PDE at the following address\r
---- // 0xC0300000 - 0xC03007FC\r
---- //\r
---- // Then it finds the best place for non-paged pool:\r
---- // StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD\r
---- //\r
----\r
---- // Before we start mapping pages, create a block of memory, which will contain\r
---- // PDE and PTEs\r
---- if (MempAllocatePageTables() == FALSE)\r
---- return FALSE;\r
----\r
---- // Allocate memory for memory allocation descriptors\r
---- Mad = MmHeapAlloc(sizeof(MEMORY_ALLOCATION_DESCRIPTOR) * 1024);\r
----\r
---- // Setup an entry for each descriptor\r
---- MemoryMap = MmGetMemoryMap(&NoEntries);\r
---- if (MemoryMap == NULL)\r
---- {\r
---- UiMessageBox("Can not retrieve the current memory map");\r
---- return FALSE;\r
---- }\r
----\r
---- // Calculate parameters of the memory map\r
---- MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT;\r
---- MemoryMapSizeInPages = NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM);\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries));\r
----\r
---- // Always contigiously map low 1Mb of memory\r
---- Status = MempSetupPaging(0, 0x100);\r
---- if (!Status)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging of low 1Mb\n"));\r
---- return FALSE;\r
---- }\r
----\r
---- // Construct a good memory map from what we've got,\r
---- // but mark entries which the memory allocation bitmap takes\r
---- // as free entries (this is done in order to have the ability\r
---- // to place mem alloc bitmap outside lower 16Mb zone)\r
---- PagesCount = 1;\r
---- LastPageIndex = 0;\r
---- LastPageType = MemoryMap[0].PageAllocated;\r
---- for(i=1;i<NoEntries;i++)\r
---- {\r
---- // Check if its memory map itself\r
---- if (i >= MemoryMapStartPage &&\r
---- i < (MemoryMapStartPage+MemoryMapSizeInPages))\r
---- {\r
---- // Exclude it if current page belongs to the memory map\r
---- MemoryMap[i].PageAllocated = LoaderFree;\r
---- }\r
----\r
---- // Process entry\r
---- if (MemoryMap[i].PageAllocated == LastPageType &&\r
---- (i != NoEntries-1) )\r
---- {\r
---- PagesCount++;\r
---- }\r
---- else\r
---- {\r
---- // Add the resulting region\r
---- MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType);\r
----\r
---- // Reset our counter vars\r
---- LastPageIndex = i;\r
---- LastPageType = MemoryMap[i].PageAllocated;\r
---- PagesCount = 1;\r
---- }\r
---- }\r
----\r
---- // TEMP, DEBUG!\r
---- // adding special reserved memory zones for vmware workstation\r
----#if 0\r
---- {\r
---- Mad[MadCount].BasePage = 0xfec00;\r
---- Mad[MadCount].PageCount = 0x10;\r
---- Mad[MadCount].MemoryType = LoaderSpecialMemory;\r
---- WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);\r
---- MadCount++;\r
----\r
---- Mad[MadCount].BasePage = 0xfee00;\r
---- Mad[MadCount].PageCount = 0x1;\r
---- Mad[MadCount].MemoryType = LoaderSpecialMemory;\r
---- WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);\r
---- MadCount++;\r
----\r
---- Mad[MadCount].BasePage = 0xfffe0;\r
---- Mad[MadCount].PageCount = 0x20;\r
---- Mad[MadCount].MemoryType = LoaderSpecialMemory;\r
---- WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);\r
---- MadCount++;\r
---- }\r
----#endif\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "MadCount: %d\n", MadCount));\r
----\r
---- WinLdrpDumpMemoryDescriptors(LoaderBlock); //FIXME: Delete!\r
----\r
---- // Map our loader image, so we can continue running\r
---- /*Status = MempSetupPaging(OsLoaderBase >> MM_PAGE_SHIFT, OsLoaderSize >> MM_PAGE_SHIFT);\r
---- if (!Status)\r
---- {\r
---- UiMessageBox("Error during MempSetupPaging");\r
---- return;\r
---- }*/\r
----\r
---- //VideoDisplayString(L"Hello from VGA, going into the kernel\n");\r
---- DbgPrint((DPRINT_WINDOWS, "HalPageTable: 0x%X\n", HalPageTable));\r
----\r
---- // Page Tables have been setup, make special handling for PCR and TSS\r
---- // (which is done in BlSetupFotNt in usual ntldr)\r
---- HalPageTable[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber = PcrBasePage+1;\r
---- HalPageTable[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1;\r
---- HalPageTable[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1;\r
----\r
---- HalPageTable[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber = PcrBasePage;\r
---- HalPageTable[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1;\r
---- HalPageTable[(KIP0PCRADDRESS - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1;\r
----\r
---- // Map APIC\r
---- WinLdrpMapApic();\r
----\r
---- // Map VGA memory\r
---- //VideoMemoryBase = MmMapIoSpace(0xb8000, 4000, MmNonCached);\r
---- //DbgPrint((DPRINT_WINDOWS, "VideoMemoryBase: 0x%X\n", VideoMemoryBase));\r
----\r
---- Tss = (PKTSS)(KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));\r
----\r
---- // Unmap what is not needed from kernel page table\r
---- MempDisablePages();\r
----\r
---- // Fill the memory descriptor list and \r
---- //PrepareMemoryDescriptorList();\r
---- DbgPrint((DPRINT_WINDOWS, "Memory Descriptor List prepared, printing PDE\n"));\r
---- List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);\r
----\r
----#ifdef DBG\r
---- {\r
---- ULONG *PDE_Addr=(ULONG *)PDE;//0xC0300000;\r
---- int j;\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "\nPDE\n"));\r
----\r
---- for (i=0; i<128; i++)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "0x%04X | ", i*8));\r
----\r
---- for (j=0; j<8; j++)\r
---- {\r
---- DbgPrint((DPRINT_WINDOWS, "0x%08X ", PDE_Addr[i*8+j]));\r
---- }\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "\n"));\r
---- }\r
---- }\r
----#endif\r
----\r
----\r
---- // Enable paging\r
---- //BS->ExitBootServices(ImageHandle,MapKey);\r
----\r
---- // Disable Interrupts\r
---- _disable();\r
----\r
---- // Re-initalize EFLAGS\r
---- Ke386EraseFlags();\r
----\r
---- // Set the PDBR\r
---- __writecr3((ULONG_PTR)PDE);\r
----\r
---- // Enable paging by modifying CR0\r
---- __writecr0(__readcr0() | CR0_PG);\r
----\r
---- // Set processor context\r
---- WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));\r
----\r
---- // Zero KI_USER_SHARED_DATA page\r
---- memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE);\r
----\r
---- return TRUE;\r
----}\r
----\r
----// Two special things this func does: it sorts descriptors,\r
----// and it merges free ones\r
----VOID\r
----WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,\r
---- IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor)\r
----{\r
---- PLIST_ENTRY ListHead = &LoaderBlock->MemoryDescriptorListHead;\r
---- PLIST_ENTRY PreviousEntry, NextEntry;\r
---- PMEMORY_ALLOCATION_DESCRIPTOR PreviousDescriptor = NULL, NextDescriptor = NULL;\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "BP=0x%X PC=0x%X %s\n", NewDescriptor->BasePage,\r
---- NewDescriptor->PageCount, MemTypeDesc[NewDescriptor->MemoryType]));\r
----\r
---- /* Find a place where to insert the new descriptor to */\r
---- PreviousEntry = ListHead;\r
---- NextEntry = ListHead->Flink;\r
---- while (NextEntry != ListHead)\r
---- {\r
---- NextDescriptor = CONTAINING_RECORD(NextEntry,\r
---- MEMORY_ALLOCATION_DESCRIPTOR,\r
---- ListEntry);\r
---- if (NewDescriptor->BasePage < NextDescriptor->BasePage)\r
---- break;\r
----\r
---- PreviousEntry = NextEntry;\r
---- PreviousDescriptor = NextDescriptor;\r
---- NextEntry = NextEntry->Flink;\r
---- }\r
----\r
---- /* Don't forget about merging free areas */\r
---- if (NewDescriptor->MemoryType != LoaderFree)\r
---- {\r
---- /* Just insert, nothing to merge */\r
---- InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry);\r
---- }\r
---- else\r
---- {\r
---- /* Previous block also free? */\r
---- if ((PreviousEntry != ListHead) && (PreviousDescriptor->MemoryType == LoaderFree) &&\r
---- ((PreviousDescriptor->BasePage + PreviousDescriptor->PageCount) ==\r
---- NewDescriptor->BasePage))\r
---- {\r
---- /* Just enlarge previous descriptor's PageCount */\r
---- PreviousDescriptor->PageCount += NewDescriptor->PageCount;\r
---- NewDescriptor = PreviousDescriptor;\r
---- }\r
---- else\r
---- {\r
---- /* Nope, just insert */\r
---- InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry);\r
---- }\r
----\r
---- /* Next block is free ?*/\r
---- if ((NextEntry != ListHead) &&\r
---- (NextDescriptor->MemoryType == LoaderFree) &&\r
---- ((NewDescriptor->BasePage + NewDescriptor->PageCount) == NextDescriptor->BasePage))\r
---- {\r
---- /* Enlarge next descriptor's PageCount */\r
---- NewDescriptor->PageCount += NextDescriptor->PageCount;\r
---- RemoveEntryList(&NextDescriptor->ListEntry);\r
---- }\r
---- }\r
----\r
---- return;\r
----}\r
----\r
----VOID\r
----WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss)\r
----{\r
---- GDTIDT GdtDesc, IdtDesc, OldIdt;\r
---- PKGDTENTRY pGdt;\r
---- PKIDTENTRY pIdt;\r
---- ULONG Ldt = 0;\r
---- //ULONG i;\r
----\r
---- DbgPrint((DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n",\r
---- GdtIdt, Pcr, Tss));\r
----\r
---- // Kernel expects the PCR to be zero-filled on startup\r
---- // FIXME: Why zero it here when we can zero it right after allocation?\r
---- RtlZeroMemory((PVOID)Pcr, MM_PAGE_SIZE); //FIXME: Why zero only 1 page when we allocate 2?\r
----\r
---- // Get old values of GDT and IDT\r
---- Ke386GetGlobalDescriptorTable(GdtDesc);\r
---- Ke386GetInterruptDescriptorTable(IdtDesc);\r
----\r
---- // Save old IDT\r
---- OldIdt.Base = IdtDesc.Base;\r
---- OldIdt.Limit = IdtDesc.Limit;\r
----\r
---- // Prepare new IDT+GDT\r
---- GdtDesc.Base = KSEG0_BASE | (ULONG_PTR)GdtIdt;\r
---- GdtDesc.Limit = NUM_GDT * sizeof(KGDTENTRY) - 1;\r
---- IdtDesc.Base = (ULONG)((PUCHAR)GdtDesc.Base + GdtDesc.Limit + 1);\r
---- IdtDesc.Limit = NUM_IDT * sizeof(KIDTENTRY) - 1;\r
----\r
---- // ========================\r
---- // Fill all descriptors now\r
---- // ========================\r
----\r
---- pGdt = (PKGDTENTRY)GdtDesc.Base;\r
---- pIdt = (PKIDTENTRY)IdtDesc.Base;\r
----\r
---- //\r
---- // Code selector (0x8)\r
---- // Flat 4Gb\r
---- //\r
---- pGdt[1].LimitLow = 0xFFFF;\r
---- pGdt[1].BaseLow = 0;\r
---- pGdt[1].HighWord.Bytes.BaseMid = 0;\r
---- pGdt[1].HighWord.Bytes.Flags1 = 0x9A;\r
---- pGdt[1].HighWord.Bytes.Flags2 = 0xCF;\r
---- pGdt[1].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Data selector (0x10)\r
---- // Flat 4Gb\r
---- //\r
---- pGdt[2].LimitLow = 0xFFFF;\r
---- pGdt[2].BaseLow = 0;\r
---- pGdt[2].HighWord.Bytes.BaseMid = 0;\r
---- pGdt[2].HighWord.Bytes.Flags1 = 0x92;\r
---- pGdt[2].HighWord.Bytes.Flags2 = 0xCF;\r
---- pGdt[2].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Selector (0x18)\r
---- // Flat 2Gb\r
---- //\r
---- pGdt[3].LimitLow = 0xFFFF;\r
---- pGdt[3].BaseLow = 0;\r
---- pGdt[3].HighWord.Bytes.BaseMid = 0;\r
---- pGdt[3].HighWord.Bytes.Flags1 = 0xFA;\r
---- pGdt[3].HighWord.Bytes.Flags2 = 0xCF;\r
---- pGdt[3].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Selector (0x20)\r
---- // Flat 2Gb\r
---- //\r
---- pGdt[4].LimitLow = 0xFFFF;\r
---- pGdt[4].BaseLow = 0;\r
---- pGdt[4].HighWord.Bytes.BaseMid = 0;\r
---- pGdt[4].HighWord.Bytes.Flags1 = 0xF2;\r
---- pGdt[4].HighWord.Bytes.Flags2 = 0xCF;\r
---- pGdt[4].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // TSS Selector (0x28)\r
---- //\r
---- pGdt[5].LimitLow = 0x78-1; //FIXME: Check this\r
---- pGdt[5].BaseLow = (USHORT)(Tss & 0xffff);\r
---- pGdt[5].HighWord.Bytes.BaseMid = (UCHAR)((Tss >> 16) & 0xff);\r
---- pGdt[5].HighWord.Bytes.Flags1 = 0x89;\r
---- pGdt[5].HighWord.Bytes.Flags2 = 0x00;\r
---- pGdt[5].HighWord.Bytes.BaseHi = (UCHAR)((Tss >> 24) & 0xff);\r
----\r
---- //\r
---- // PCR Selector (0x30)\r
---- //\r
---- pGdt[6].LimitLow = 0x01;\r
---- pGdt[6].BaseLow = (USHORT)(Pcr & 0xffff);\r
---- pGdt[6].HighWord.Bytes.BaseMid = (UCHAR)((Pcr >> 16) & 0xff);\r
---- pGdt[6].HighWord.Bytes.Flags1 = 0x92;\r
---- pGdt[6].HighWord.Bytes.Flags2 = 0xC0;\r
---- pGdt[6].HighWord.Bytes.BaseHi = (UCHAR)((Pcr >> 24) & 0xff);\r
----\r
---- //\r
---- // Selector (0x38)\r
---- //\r
---- pGdt[7].LimitLow = 0xFFFF;\r
---- pGdt[7].BaseLow = 0;\r
---- pGdt[7].HighWord.Bytes.BaseMid = 0;\r
---- pGdt[7].HighWord.Bytes.Flags1 = 0xF3;\r
---- pGdt[7].HighWord.Bytes.Flags2 = 0x40;\r
---- pGdt[7].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Some BIOS stuff (0x40)\r
---- //\r
---- pGdt[8].LimitLow = 0xFFFF;\r
---- pGdt[8].BaseLow = 0x400;\r
---- pGdt[8].HighWord.Bytes.BaseMid = 0;\r
---- pGdt[8].HighWord.Bytes.Flags1 = 0xF2;\r
---- pGdt[8].HighWord.Bytes.Flags2 = 0x0;\r
---- pGdt[8].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Selector (0x48)\r
---- //\r
---- pGdt[9].LimitLow = 0;\r
---- pGdt[9].BaseLow = 0;\r
---- pGdt[9].HighWord.Bytes.BaseMid = 0;\r
---- pGdt[9].HighWord.Bytes.Flags1 = 0;\r
---- pGdt[9].HighWord.Bytes.Flags2 = 0;\r
---- pGdt[9].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Selector (0x50)\r
---- //\r
---- pGdt[10].LimitLow = 0xFFFF; //FIXME: Not correct!\r
---- pGdt[10].BaseLow = 0;\r
---- pGdt[10].HighWord.Bytes.BaseMid = 0x2;\r
---- pGdt[10].HighWord.Bytes.Flags1 = 0x89;\r
---- pGdt[10].HighWord.Bytes.Flags2 = 0;\r
---- pGdt[10].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Selector (0x58)\r
---- //\r
---- pGdt[11].LimitLow = 0xFFFF;\r
---- pGdt[11].BaseLow = 0;\r
---- pGdt[11].HighWord.Bytes.BaseMid = 0x2;\r
---- pGdt[11].HighWord.Bytes.Flags1 = 0x9A;\r
---- pGdt[11].HighWord.Bytes.Flags2 = 0;\r
---- pGdt[11].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Selector (0x60)\r
---- //\r
---- pGdt[12].LimitLow = 0xFFFF;\r
---- pGdt[12].BaseLow = 0; //FIXME: Maybe not correct, but noone cares\r
---- pGdt[12].HighWord.Bytes.BaseMid = 0x2;\r
---- pGdt[12].HighWord.Bytes.Flags1 = 0x92;\r
---- pGdt[12].HighWord.Bytes.Flags2 = 0;\r
---- pGdt[12].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Video buffer Selector (0x68)\r
---- //\r
---- pGdt[13].LimitLow = 0x3FFF;\r
---- pGdt[13].BaseLow = 0x8000;\r
---- pGdt[13].HighWord.Bytes.BaseMid = 0x0B;\r
---- pGdt[13].HighWord.Bytes.Flags1 = 0x92;\r
---- pGdt[13].HighWord.Bytes.Flags2 = 0;\r
---- pGdt[13].HighWord.Bytes.BaseHi = 0;\r
----\r
---- //\r
---- // Points to GDT (0x70)\r
---- //\r
---- pGdt[14].LimitLow = NUM_GDT*sizeof(KGDTENTRY) - 1;\r
---- pGdt[14].BaseLow = 0x7000;\r
---- pGdt[14].HighWord.Bytes.BaseMid = 0xFF;\r
---- pGdt[14].HighWord.Bytes.Flags1 = 0x92;\r
---- pGdt[14].HighWord.Bytes.Flags2 = 0;\r
---- pGdt[14].HighWord.Bytes.BaseHi = 0xFF;\r
----\r
---- //\r
---- // Some unused descriptors should go here\r
---- //\r
----\r
---- // Copy the old IDT\r
---- RtlCopyMemory(pIdt, (PVOID)OldIdt.Base, OldIdt.Limit);\r
----\r
---- // Mask interrupts\r
---- //asm("cli\n"); // they are already masked before enabling paged mode\r
----\r
---- // Load GDT+IDT\r
---- Ke386SetGlobalDescriptorTable(GdtDesc);\r
---- Ke386SetInterruptDescriptorTable(IdtDesc);\r
----\r
---- // Jump to proper CS and clear prefetch queue\r
---- asm("ljmp $0x08, $mb1\n"\r
---- "mb1:\n");\r
----\r
---- // Set SS selector\r
---- asm(".intel_syntax noprefix\n");\r
---- asm("mov ax, 0x10\n"); // DataSelector=0x10\r
---- asm("mov ss, ax\n");\r
---- asm(".att_syntax\n");\r
----\r
---- // Set DS and ES selectors\r
---- Ke386SetDs(0x10);\r
---- Ke386SetEs(0x10); // this is vital for rep stosd\r
----\r
---- // LDT = not used ever, thus set to 0\r
---- Ke386SetLocalDescriptorTable(Ldt);\r
----\r
---- // Load TSR\r
---- Ke386SetTr(0x28);\r
----\r
---- // Clear GS\r
---- asm(".intel_syntax noprefix\n");\r
---- asm("push 0\n");\r
---- asm("pop gs\n");\r
---- asm(".att_syntax\n");\r
----\r
---- // Set FS to PCR\r
---- Ke386SetFs(0x30);\r
----\r
---- // Real end of the function, just for information\r
---- /* do not uncomment!\r
---- pop edi;\r
---- pop esi;\r
---- pop ebx;\r
---- mov esp, ebp;\r
---- pop ebp;\r
---- ret\r
---- */\r
----}\r
++++/*
++++ * PROJECT: EFI Windows Loader
++++ * LICENSE: GPL - See COPYING in the top level directory
++++ * FILE: freeldr/winldr/wlmemory.c
++++ * PURPOSE: Memory related routines
++++ * PROGRAMMERS: Aleksey Bragin (aleksey@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
++++
++++PCHAR MemTypeDesc[] = {
++++ "ExceptionBlock ", // ?
++++ "SystemBlock ", // ?
++++ "Free ",
++++ "Bad ", // used
++++ "LoadedProgram ", // == Free
++++ "FirmwareTemporary ", // == Free
++++ "FirmwarePermanent ", // == Bad
++++ "OsloaderHeap ", // used
++++ "OsloaderStack ", // == Free
++++ "SystemCode ",
++++ "HalCode ",
++++ "BootDriver ", // not used
++++ "ConsoleInDriver ", // ?
++++ "ConsoleOutDriver ", // ?
++++ "StartupDpcStack ", // ?
++++ "StartupKernelStack", // ?
++++ "StartupPanicStack ", // ?
++++ "StartupPcrPage ", // ?
++++ "StartupPdrPage ", // ?
++++ "RegistryData ", // used
++++ "MemoryData ", // not used
++++ "NlsData ", // used
++++ "SpecialMemory ", // == Bad
++++ "BBTMemory " // == Bad
++++ };
++++
++++VOID
++++WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);
++++
++++
++++VOID
++++MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
++++ ULONG BasePage,
++++ ULONG PageCount,
++++ ULONG Type);
++++VOID
++++WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
++++ IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor);
++++
++++VOID
++++WinLdrRemoveDescriptor(IN PMEMORY_ALLOCATION_DESCRIPTOR Descriptor);
++++
++++VOID
++++WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss);
++++
++++// This is needed only for SetProcessorContext routine
++++#pragma pack(2)
++++ typedef struct
++++ {
++++ USHORT Limit;
++++ ULONG Base;
++++ } GDTIDT;
++++#pragma pack(4)
++++
++++// 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
++++
++++/* GLOBALS ***************************************************************/
++++
++++PHARDWARE_PTE PDE;
++++PHARDWARE_PTE HalPageTable;
++++
++++PUCHAR PhysicalPageTablesBuffer;
++++PUCHAR KernelPageTablesBuffer;
++++ULONG PhysicalPageTables;
++++ULONG KernelPageTables;
++++
++++MEMORY_ALLOCATION_DESCRIPTOR *Mad;
++++ULONG MadCount = 0;
++++
++++
++++/* 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 = (GetSystemMemorySize() >> MM_PAGE_SHIFT) >> 10;
++++
- DbgPrint((DPRINT_WINDOWS, "NumPageTables = %d\n", NumPageTables));
+++++ 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)
++++ {
- DbgPrint((DPRINT_WINDOWS, "There was a problem allocating two adjacent blocks of memory!"));
+++++ 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)
++++ {
- DbgPrint((DPRINT_WINDOWS, "WARNING! Entry: %X > 1023\n", Entry+(KSEG0_BASE >> 22)));
+++++ 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);
++++ }
++++
++++ if (Page == 0)
++++ {
++++ PhysicalPT[Page & 0x3ff].PageFrameNumber = Page;
++++ PhysicalPT[Page & 0x3ff].Valid = 0;
++++ PhysicalPT[Page & 0x3ff].Write = 0;
++++
++++ KernelPT[Page & 0x3ff].PageFrameNumber = Page;
++++ KernelPT[Page & 0x3ff].Valid = 0;
++++ KernelPT[Page & 0x3ff].Write = 0;
++++ }
++++ else
++++ {
++++ PhysicalPT[Page & 0x3ff].PageFrameNumber = Page;
++++ PhysicalPT[Page & 0x3ff].Valid = 1;
++++ PhysicalPT[Page & 0x3ff].Write = 1;
++++
++++ KernelPT[Page & 0x3ff].PageFrameNumber = Page;
++++ KernelPT[Page & 0x3ff].Valid = 1;
++++ KernelPT[Page & 0x3ff].Write = 1;
++++ }
++++ }
++++
++++ return TRUE;
++++}
++++
++++VOID
++++MempDisablePages()
++++{
++++ ULONG i;
++++
++++ //
++++ // We need to delete kernel mapping from memory areas which are
++++ // marked as Special or Permanent memory (thus non-accessible)
++++ //
++++
++++ for (i=0; i<MadCount; i++)
++++ {
++++ ULONG StartPage, EndPage, Page;
++++
++++ StartPage = Mad[i].BasePage;
++++ EndPage = Mad[i].BasePage + Mad[i].PageCount;
++++
++++ if (Mad[i].MemoryType == LoaderFirmwarePermanent ||
++++ Mad[i].MemoryType == LoaderSpecialMemory ||
++++ Mad[i].MemoryType == LoaderFree ||
++++ (Mad[i].MemoryType == LoaderFirmwareTemporary && EndPage <= LoaderPagesSpanned) ||
++++ Mad[i].MemoryType == LoaderOsloaderStack ||
++++ Mad[i].MemoryType == LoaderLoadedProgram)
++++ {
++++ //
++++ // But, the first megabyte of memory always stays!
++++ // And, to tell the truth, we don't care about what's higher
++++ // than LoaderPagesSpanned
++++ if (Mad[i].MemoryType == LoaderFirmwarePermanent ||
++++ Mad[i].MemoryType == LoaderSpecialMemory)
++++ {
++++ if (StartPage < 0x100)
++++ StartPage = 0x100;
++++
++++ if (EndPage > LoaderPagesSpanned)
++++ EndPage = LoaderPagesSpanned;
++++ }
++++
++++ for (Page = StartPage; Page < EndPage; Page++)
++++ {
++++ PHARDWARE_PTE KernelPT;
++++ ULONG Entry = (Page >> 10) + (KSEG0_BASE >> 22);
++++
++++ 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
++++MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
++++ ULONG BasePage,
++++ ULONG PageCount,
++++ ULONG Type)
++++{
++++ BOOLEAN Status;
++++
++++ //
++++ // Check for some weird stuff at the top
++++ //
++++ if (BasePage + PageCount > 0xF0000)
++++ {
++++ //
++++ // Just skip this, without even adding to MAD list
++++ //
++++ return;
++++ }
++++
++++ //
++++ // Set Base page, page count and type
++++ //
++++ Mad[MadCount].BasePage = BasePage;
++++ Mad[MadCount].PageCount = PageCount;
++++ Mad[MadCount].MemoryType = Type;
++++
++++ //
++++ // Check if it's more than the allowed for OS loader
++++ // if yes - don't map the pages, just add as FirmwareTemporary
++++ //
++++ if (BasePage + PageCount > LoaderPagesSpanned)
++++ {
++++ if (Mad[MadCount].MemoryType != LoaderSpecialMemory &&
++++ Mad[MadCount].MemoryType != LoaderFirmwarePermanent &&
++++ Mad[MadCount].MemoryType != LoaderFree)
++++ {
- DbgPrint((DPRINT_WINDOWS, "Setting page %x %x to Temporary from %d\n",
- BasePage, PageCount, Mad[MadCount].MemoryType));
+++++ DPRINTM(DPRINT_WINDOWS, "Setting page %x %x to Temporary from %d\n",
+++++ BasePage, PageCount, Mad[MadCount].MemoryType);
++++ Mad[MadCount].MemoryType = LoaderFirmwareTemporary;
++++ }
++++
++++ WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
++++ MadCount++;
++++
++++ return;
++++ }
++++
++++ //
++++ // Add descriptor
++++ //
++++ WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
++++ MadCount++;
++++
++++ //
++++ // Map it (don't map low 1Mb because it was already contigiously
++++ // mapped in WinLdrTurnOnPaging)
++++ //
++++ if (BasePage >= 0x100)
++++ {
++++ Status = MempSetupPaging(BasePage, PageCount);
++++ if (!Status)
++++ {
- DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "Error during MempSetupPaging\n");
++++ return;
++++ }
++++ }
++++}
++++
++++#ifdef _M_IX86
++++
++++BOOLEAN LocalAPIC = FALSE;
++++ULONG_PTR APICAddress = 0;
++++
++++VOID
++++WinLdrpMapApic()
++++{
++++ /* Check if we have a local APIC */
++++ asm(".intel_syntax noprefix\n");
++++ asm("mov eax, 1\n");
++++ asm("cpuid\n");
++++ asm("shr edx, 9\n");
++++ asm("and edx, 0x1\n");
++++ asm("mov _LocalAPIC, edx\n");
++++ asm(".att_syntax\n");
++++
++++ /* If there is no APIC, just return */
++++ if (!LocalAPIC)
++++ return;
++++
++++ asm(".intel_syntax noprefix\n");
++++ asm("mov ecx, 0x1B\n");
++++ asm("rdmsr\n");
++++ asm("mov edx, eax\n");
++++ asm("and edx, 0xFFFFF000\n");
++++ asm("mov _APICAddress, edx");
++++ asm(".att_syntax\n");
++++
- DbgPrint((DPRINT_WINDOWS, "Local APIC detected at address 0x%x\n",
- APICAddress));
+++++ 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;
++++}
++++#else
++++VOID
++++WinLdrpMapApic()
++++{
++++ /* Implement it for another arch */
++++}
++++#endif
++++
++++BOOLEAN
++++WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
++++ ULONG PcrBasePage,
++++ ULONG TssBasePage,
++++ PVOID GdtIdt)
++++{
++++ ULONG i, PagesCount, MemoryMapSizeInPages;
++++ ULONG LastPageIndex, LastPageType, MemoryMapStartPage;
++++ PPAGE_LOOKUP_TABLE_ITEM MemoryMap;
++++ ULONG NoEntries;
++++ PKTSS Tss;
++++ BOOLEAN Status;
++++
++++ //
++++ // Creating a suitable memory map for the Windows can be tricky, so let's
++++ // give a few advices:
++++ // 1) One must not map the whole available memory pages to PDE!
++++ // Map only what's needed - 16Mb, 24Mb, 32Mb max I think,
++++ // thus occupying 4, 6 or 8 PDE entries for identical mapping,
++++ // the same quantity for KSEG0_BASE mapping, one more entry for
++++ // hyperspace and one more entry for HAL physical pages mapping.
++++ // 2) Memory descriptors must map *the whole* physical memory
++++ // showing any memory above 16/24/32 as FirmwareTemporary
++++ //
++++ // 3) Overall memory blocks count must not exceed 30 (?? why?)
++++ //
++++
++++ //
++++ // During MmInitMachineDependent, the kernel zeroes PDE at the following address
++++ // 0xC0300000 - 0xC03007FC
++++ //
++++ // Then it finds the best place for non-paged pool:
++++ // StartPde C0300F70, EndPde C0300FF8, NumberOfPages C13, NextPhysPage 3AD
++++ //
++++
++++ // Before we start mapping pages, create a block of memory, which will contain
++++ // PDE and PTEs
++++ if (MempAllocatePageTables() == FALSE)
++++ return FALSE;
++++
++++ // Allocate memory for memory allocation descriptors
++++ Mad = MmHeapAlloc(sizeof(MEMORY_ALLOCATION_DESCRIPTOR) * 1024);
++++
++++ // Setup an entry for each descriptor
++++ MemoryMap = MmGetMemoryMap(&NoEntries);
++++ if (MemoryMap == NULL)
++++ {
++++ UiMessageBox("Can not retrieve the current memory map");
++++ return FALSE;
++++ }
++++
++++ // Calculate parameters of the memory map
++++ MemoryMapStartPage = (ULONG_PTR)MemoryMap >> MM_PAGE_SHIFT;
++++ MemoryMapSizeInPages = NoEntries * sizeof(PAGE_LOOKUP_TABLE_ITEM);
++++
- DbgPrint((DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries));
+++++ DPRINTM(DPRINT_WINDOWS, "Got memory map with %d entries\n", NoEntries);
++++
++++ // Always contigiously map low 1Mb of memory
++++ Status = MempSetupPaging(0, 0x100);
++++ if (!Status)
++++ {
- DbgPrint((DPRINT_WINDOWS, "Error during MempSetupPaging of low 1Mb\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "Error during MempSetupPaging of low 1Mb\n");
++++ return FALSE;
++++ }
++++
++++ // Construct a good memory map from what we've got,
++++ // but mark entries which the memory allocation bitmap takes
++++ // as free entries (this is done in order to have the ability
++++ // to place mem alloc bitmap outside lower 16Mb zone)
++++ PagesCount = 1;
++++ LastPageIndex = 0;
++++ LastPageType = MemoryMap[0].PageAllocated;
++++ for(i=1;i<NoEntries;i++)
++++ {
++++ // Check if its memory map itself
++++ if (i >= MemoryMapStartPage &&
++++ i < (MemoryMapStartPage+MemoryMapSizeInPages))
++++ {
++++ // Exclude it if current page belongs to the memory map
++++ MemoryMap[i].PageAllocated = LoaderFree;
++++ }
++++
++++ // Process entry
++++ if (MemoryMap[i].PageAllocated == LastPageType &&
++++ (i != NoEntries-1) )
++++ {
++++ PagesCount++;
++++ }
++++ else
++++ {
++++ // Add the resulting region
++++ MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType);
++++
++++ // Reset our counter vars
++++ LastPageIndex = i;
++++ LastPageType = MemoryMap[i].PageAllocated;
++++ PagesCount = 1;
++++ }
++++ }
++++
++++ // TEMP, DEBUG!
++++ // adding special reserved memory zones for vmware workstation
++++#if 0
++++ {
++++ Mad[MadCount].BasePage = 0xfec00;
++++ Mad[MadCount].PageCount = 0x10;
++++ Mad[MadCount].MemoryType = LoaderSpecialMemory;
++++ WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
++++ MadCount++;
++++
++++ Mad[MadCount].BasePage = 0xfee00;
++++ Mad[MadCount].PageCount = 0x1;
++++ Mad[MadCount].MemoryType = LoaderSpecialMemory;
++++ WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
++++ MadCount++;
++++
++++ Mad[MadCount].BasePage = 0xfffe0;
++++ Mad[MadCount].PageCount = 0x20;
++++ Mad[MadCount].MemoryType = LoaderSpecialMemory;
++++ WinLdrInsertDescriptor(LoaderBlock, &Mad[MadCount]);
++++ MadCount++;
++++ }
++++#endif
++++
- DbgPrint((DPRINT_WINDOWS, "MadCount: %d\n", MadCount));
+++++ DPRINTM(DPRINT_WINDOWS, "MadCount: %d\n", MadCount);
++++
++++ WinLdrpDumpMemoryDescriptors(LoaderBlock); //FIXME: Delete!
++++
++++ // Map our loader image, so we can continue running
++++ /*Status = MempSetupPaging(OsLoaderBase >> MM_PAGE_SHIFT, OsLoaderSize >> MM_PAGE_SHIFT);
++++ if (!Status)
++++ {
++++ UiMessageBox("Error during MempSetupPaging");
++++ return;
++++ }*/
++++
++++ //VideoDisplayString(L"Hello from VGA, going into the kernel\n");
- DbgPrint((DPRINT_WINDOWS, "HalPageTable: 0x%X\n", HalPageTable));
+++++ 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);
- //DbgPrint((DPRINT_WINDOWS, "VideoMemoryBase: 0x%X\n", VideoMemoryBase));
+++++ //DPRINTM(DPRINT_WINDOWS, "VideoMemoryBase: 0x%X\n", VideoMemoryBase);
++++
++++ Tss = (PKTSS)(KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
++++
++++ // Unmap what is not needed from kernel page table
++++ MempDisablePages();
++++
++++ // Fill the memory descriptor list and
++++ //PrepareMemoryDescriptorList();
- DbgPrint((DPRINT_WINDOWS, "Memory Descriptor List prepared, printing PDE\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "Memory Descriptor List prepared, printing PDE\n");
++++ List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
++++
++++#ifdef DBG
++++ {
++++ ULONG *PDE_Addr=(ULONG *)PDE;//0xC0300000;
++++ int j;
++++
- DbgPrint((DPRINT_WINDOWS, "\nPDE\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "\nPDE\n");
++++
++++ for (i=0; i<128; i++)
++++ {
- DbgPrint((DPRINT_WINDOWS, "0x%04X | ", i*8));
+++++ DPRINTM(DPRINT_WINDOWS, "0x%04X | ", i*8);
++++
++++ for (j=0; j<8; j++)
++++ {
- DbgPrint((DPRINT_WINDOWS, "0x%08X ", PDE_Addr[i*8+j]));
+++++ DPRINTM(DPRINT_WINDOWS, "0x%08X ", PDE_Addr[i*8+j]);
++++ }
++++
- DbgPrint((DPRINT_WINDOWS, "\n"));
+++++ DPRINTM(DPRINT_WINDOWS, "\n");
++++ }
++++ }
++++#endif
++++
++++
++++ // Enable paging
++++ //BS->ExitBootServices(ImageHandle,MapKey);
++++
++++ // Disable Interrupts
++++ _disable();
++++
++++ // Re-initalize EFLAGS
++++ Ke386EraseFlags();
++++
++++ // Set the PDBR
++++ __writecr3((ULONG_PTR)PDE);
++++
++++ // Enable paging by modifying CR0
++++ __writecr0(__readcr0() | CR0_PG);
++++
++++ // Set processor context
++++ WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
++++
++++ // Zero KI_USER_SHARED_DATA page
++++ memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE);
++++
++++ return TRUE;
++++}
++++
++++// Two special things this func does: it sorts descriptors,
++++// and it merges free ones
++++VOID
++++WinLdrInsertDescriptor(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
++++ IN PMEMORY_ALLOCATION_DESCRIPTOR NewDescriptor)
++++{
++++ PLIST_ENTRY ListHead = &LoaderBlock->MemoryDescriptorListHead;
++++ PLIST_ENTRY PreviousEntry, NextEntry;
++++ PMEMORY_ALLOCATION_DESCRIPTOR PreviousDescriptor = NULL, NextDescriptor = NULL;
++++
- DbgPrint((DPRINT_WINDOWS, "BP=0x%X PC=0x%X %s\n", NewDescriptor->BasePage,
- NewDescriptor->PageCount, MemTypeDesc[NewDescriptor->MemoryType]));
+++++ DPRINTM(DPRINT_WINDOWS, "BP=0x%X PC=0x%X %s\n", NewDescriptor->BasePage,
+++++ NewDescriptor->PageCount, MemTypeDesc[NewDescriptor->MemoryType]);
++++
++++ /* Find a place where to insert the new descriptor to */
++++ PreviousEntry = ListHead;
++++ NextEntry = ListHead->Flink;
++++ while (NextEntry != ListHead)
++++ {
++++ NextDescriptor = CONTAINING_RECORD(NextEntry,
++++ MEMORY_ALLOCATION_DESCRIPTOR,
++++ ListEntry);
++++ if (NewDescriptor->BasePage < NextDescriptor->BasePage)
++++ break;
++++
++++ PreviousEntry = NextEntry;
++++ PreviousDescriptor = NextDescriptor;
++++ NextEntry = NextEntry->Flink;
++++ }
++++
++++ /* Don't forget about merging free areas */
++++ if (NewDescriptor->MemoryType != LoaderFree)
++++ {
++++ /* Just insert, nothing to merge */
++++ InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry);
++++ }
++++ else
++++ {
++++ /* Previous block also free? */
++++ if ((PreviousEntry != ListHead) && (PreviousDescriptor->MemoryType == LoaderFree) &&
++++ ((PreviousDescriptor->BasePage + PreviousDescriptor->PageCount) ==
++++ NewDescriptor->BasePage))
++++ {
++++ /* Just enlarge previous descriptor's PageCount */
++++ PreviousDescriptor->PageCount += NewDescriptor->PageCount;
++++ NewDescriptor = PreviousDescriptor;
++++ }
++++ else
++++ {
++++ /* Nope, just insert */
++++ InsertHeadList(PreviousEntry, &NewDescriptor->ListEntry);
++++ }
++++
++++ /* Next block is free ?*/
++++ if ((NextEntry != ListHead) &&
++++ (NextDescriptor->MemoryType == LoaderFree) &&
++++ ((NewDescriptor->BasePage + NewDescriptor->PageCount) == NextDescriptor->BasePage))
++++ {
++++ /* Enlarge next descriptor's PageCount */
++++ NewDescriptor->PageCount += NextDescriptor->PageCount;
++++ RemoveEntryList(&NextDescriptor->ListEntry);
++++ }
++++ }
++++
++++ return;
++++}
++++
++++VOID
++++WinLdrSetProcessorContext(PVOID GdtIdt, IN ULONG Pcr, IN ULONG Tss)
++++{
++++ GDTIDT GdtDesc, IdtDesc, OldIdt;
++++ PKGDTENTRY pGdt;
++++ PKIDTENTRY pIdt;
++++ ULONG Ldt = 0;
++++ //ULONG i;
++++
- DbgPrint((DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n",
- GdtIdt, Pcr, Tss));
+++++ DPRINTM(DPRINT_WINDOWS, "GDtIdt %p, Pcr %p, Tss 0x%08X\n",
+++++ GdtIdt, Pcr, Tss);
++++
++++ // 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);
++++ Ke386GetInterruptDescriptorTable(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);
++++
++++ // Mask interrupts
++++ //asm("cli\n"); // they are already masked before enabling paged mode
++++
++++ // Load GDT+IDT
++++ Ke386SetGlobalDescriptorTable(GdtDesc);
++++ Ke386SetInterruptDescriptorTable(IdtDesc);
++++
++++ // Jump to proper CS and clear prefetch queue
++++ asm("ljmp $0x08, $mb1\n"
++++ "mb1:\n");
++++
++++ // Set SS selector
++++ asm(".intel_syntax noprefix\n");
++++ asm("mov ax, 0x10\n"); // DataSelector=0x10
++++ asm("mov ss, ax\n");
++++ asm(".att_syntax\n");
++++
++++ // 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(0x28);
++++
++++ // Clear GS
++++ asm(".intel_syntax noprefix\n");
++++ asm("push 0\n");
++++ asm("pop gs\n");
++++ asm(".att_syntax\n");
++++
++++ // 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
++++ */
++++}
return FALSE;
}
----- DbgPrint((DPRINT_WINDOWS, "NLS data %s %s %s\n", AnsiName, OemName, LangName));
+++++ DPRINTM(DPRINT_WINDOWS, "NLS data %s %s %s\n", AnsiName, OemName, LangName);
// Load NLS data
strcpy(SearchPath, DirectoryPath);
strcat(SearchPath, "SYSTEM32\\");
Status = WinLdrLoadNLSData(LoaderBlock, SearchPath, AnsiName, OemName, LangName);
----- DbgPrint((DPRINT_WINDOWS, "NLS data loaded with status %d\n", Status));
+++++ DPRINTM(DPRINT_WINDOWS, "NLS data loaded with status %d\n", Status);
/* TODO: Load OEM HAL font */
goto Failure;
AnsiFileSize = FsGetFileSize(AnsiFileHandle);
----- DbgPrint((DPRINT_WINDOWS, "AnsiFileSize: %d\n", AnsiFileSize));
+++++ DPRINTM(DPRINT_WINDOWS, "AnsiFileSize: %d\n", AnsiFileSize);
FsCloseFile(AnsiFileHandle);
/* Open OEM file and store its length */
OemFileSize = FsGetFileSize(OemFileHandle);
FsCloseFile(OemFileHandle);
}
----- DbgPrint((DPRINT_WINDOWS, "OemFileSize: %d\n", OemFileSize));
+++++ DPRINTM(DPRINT_WINDOWS, "OemFileSize: %d\n", OemFileSize);
/* And finally open the language codepage file and store its length */
//Print(L"Loading %s...\n", Filename);
LanguageFileSize = FsGetFileSize(LanguageFileHandle);
FsCloseFile(LanguageFileHandle);
----- DbgPrint((DPRINT_WINDOWS, "LanguageFileSize: %d\n", LanguageFileSize));
+++++ DPRINTM(DPRINT_WINDOWS, "LanguageFileSize: %d\n", LanguageFileSize);
/* Sum up all three length, having in mind that every one of them
must start at a page boundary => thus round up each file to a page */
&hGroupKey);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc);
return;
}
&hOrderKey);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc);
return;
}
&hServiceKey);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc);
return;
}
BufferSize = 4096;
GroupNameBuffer = MmHeapAlloc(BufferSize);
rc = RegQueryValue(hGroupKey, L"List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize);
----- DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
+++++ DPRINTM(DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc);
if (rc != ERROR_SUCCESS)
return;
----- DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
----- DbgPrint((DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer));
+++++ DPRINTM(DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize);
+++++ DPRINTM(DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer);
/* Loop through each group */
GroupName = GroupNameBuffer;
while (*GroupName)
{
----- DbgPrint((DPRINT_WINDOWS, "Driver group: '%S'\n", GroupName));
+++++ DPRINTM(DPRINT_WINDOWS, "Driver group: '%S'\n", GroupName);
/* Query the Order */
BufferSize = sizeof(OrderList);
/* Get the Driver's Name */
ValueSize = sizeof(ServiceName);
rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
----- //DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+++++ //DPRINTM(DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc);
/* Makre sure it's valid, and check if we're done */
if (rc == ERROR_NO_MORE_ITEMS)
MmHeapFree(GroupNameBuffer);
return;
}
----- //DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+++++ //DPRINTM(DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
/* open driver Key */
rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
----- //DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
+++++ //DPRINTM(DPRINT_REACTOS, " Start: %x \n", (int)StartValue);
/* Read the Tag */
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
----- //DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
+++++ //DPRINTM(DPRINT_REACTOS, " Tag: %x \n", (int)TagValue);
/* Read the driver's group */
DriverGroupSize = sizeof(DriverGroup);
rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
----- //DbgPrint((DPRINT_REACTOS, " Group: '%S' \n", DriverGroup));
+++++ //DPRINTM(DPRINT_REACTOS, " Group: '%S' \n", DriverGroup);
/* Make sure it should be started */
if ((StartValue == 0) &&
/* Write the whole path if it suceeded, else prepare to fail */
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: not found\n");
TempImagePath[0] = 0;
sprintf(ImagePath, "%s\\system32\\drivers\\%S.sys", DirectoryPath, ServiceName);
} else if (TempImagePath[0] != L'\\') {
sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath);
} else {
sprintf(ImagePath, "%S", TempImagePath);
----- DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath);
}
----- DbgPrint((DPRINT_WINDOWS, " Adding boot driver: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_WINDOWS, " Adding boot driver: '%s'\n", ImagePath);
Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
ServiceName);
if (!Status)
----- DbgPrint((DPRINT_WINDOWS, " Failed to add boot driver\n"));
+++++ DPRINTM(DPRINT_WINDOWS, " Failed to add boot driver\n");
} else
{
----- //DbgPrint((DPRINT_WINDOWS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
----- // ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName));
+++++ //DPRINTM(DPRINT_WINDOWS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
+++++ // ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName);
}
}
ValueSize = sizeof(ServiceName);
rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
----- //DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+++++ //DPRINTM(DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc);
if (rc == ERROR_NO_MORE_ITEMS)
break;
if (rc != ERROR_SUCCESS)
MmHeapFree(GroupNameBuffer);
return;
}
----- //DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+++++ //DPRINTM(DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
/* open driver Key */
rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
----- //DbgPrint((DPRINT_REACTOS, " Start: %x \n", (int)StartValue));
+++++ //DPRINTM(DPRINT_REACTOS, " Start: %x \n", (int)StartValue);
/* Read the Tag */
ValueSize = sizeof(ULONG);
rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
----- //DbgPrint((DPRINT_REACTOS, " Tag: %x \n", (int)TagValue));
+++++ //DPRINTM(DPRINT_REACTOS, " Tag: %x \n", (int)TagValue);
/* Read the driver's group */
DriverGroupSize = sizeof(DriverGroup);
rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
----- //DbgPrint((DPRINT_REACTOS, " Group: '%S' \n", DriverGroup));
+++++ //DPRINTM(DPRINT_REACTOS, " Group: '%S' \n", DriverGroup);
for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
if (TagValue == OrderList[TagIndex]) break;
ValueSize = sizeof(TempImagePath);
rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
if (rc != ERROR_SUCCESS) {
----- DbgPrint((DPRINT_REACTOS, " ImagePath: not found\n"));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: not found\n");
TempImagePath[0] = 0;
sprintf(ImagePath, "%ssystem32\\drivers\\%S.sys", DirectoryPath, ServiceName);
} else if (TempImagePath[0] != L'\\') {
sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath);
} else {
sprintf(ImagePath, "%S", TempImagePath);
----- DbgPrint((DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_REACTOS, " ImagePath: '%s'\n", ImagePath);
}
----- DbgPrint((DPRINT_WINDOWS, " Adding boot driver: '%s'\n", ImagePath));
+++++ DPRINTM(DPRINT_WINDOWS, " Adding boot driver: '%s'\n", ImagePath);
Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
ServiceName);
if (!Status)
----- DbgPrint((DPRINT_WINDOWS, " Failed to add boot driver\n"));
+++++ DPRINTM(DPRINT_WINDOWS, " Failed to add boot driver\n");
} else
{
----- //DbgPrint((DPRINT_WINDOWS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
----- // ServiceName, StartValue, TagValue, DriverGroup, GroupName));
+++++ //DPRINTM(DPRINT_WINDOWS, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
+++++ // ServiceName, StartValue, TagValue, DriverGroup, GroupName);
}
}
#define IMAGE_REL_BASED_HIGHLOW 3
#define IMAGE_REL_BASED_HIGHADJ 4
#define IMAGE_REL_BASED_MIPS_JMPADDR 5
+++++#define IMAGE_REL_BASED_MIPS_JMPADDR16 9
+++++#define IMAGE_REL_BASED_IA64_IMM64 9
+++++#define IMAGE_REL_BASED_DIR64 10
#define IMAGE_ARCHIVE_START_SIZE 8
#define IMAGE_ARCHIVE_START "!<arch>\n"
#define IMAGE_ARCHIVE_END "`\n"
USHORT i;
PUSHORT ShortPtr;
PULONG LongPtr;
+++++ PULONGLONG LongLongPtr;
for (i = 0; i < Count; i++)
{
*LongPtr = SWAPD(*LongPtr) + (ULONG)Delta;
break;
+++++ case IMAGE_REL_BASED_DIR64:
+++++ LongLongPtr = (PUINT64)RVA(Address, Offset);
+++++ *LongLongPtr = SWAPQ(*LongLongPtr) + Delta;
+++++ break;
+++++
case IMAGE_REL_BASED_HIGHADJ:
case IMAGE_REL_BASED_MIPS_JMPADDR:
default:
#ifdef _PPC_
#define SWAPD(x) ((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)>>8)&0xff00)|(((x)>>24)&0xff))
#define SWAPW(x) ((((x)&0xff)<<8)|(((x)>>8)&0xff))
+++++#define SWAPQ(x) ((SWAPD((x)&0xffffffff) << 32) | (SWAPD((x)>>32)))
#else
-----#define SWAPD(x) x
-----#define SWAPW(x) x
+++++#define SWAPD(x) (x)
+++++#define SWAPW(x) (x)
+++++#define SWAPQ(x) (x)
#endif
++++#define ROUND_DOWN(n, align) \
++++ (((ULONG)n) & ~((align) - 1l))
++++
++++#define ROUND_UP(n, align) \
++++ ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
++++
VOID
NTAPI
RtlpGetStackLimits(PULONG_PTR StackBase,