ReactOS 0.4.16-dev-257-g6aa11ac
winldr.c File Reference
#include <freeldr.h>
#include <debug.h>
#include <internal/arm/mm.h>
#include <internal/arm/intrin_i.h>
#include "../../winldr.h"
Include dependency graph for winldr.c:

Go to the source code of this file.

Classes

struct  _KPDR_PAGE
 

Macros

#define PFN_SHIFT   12
 
#define LARGE_PFN_SHIFT   20
 
#define PTE_BASE   0xC0000000
 
#define PDE_BASE   0xC0400000
 
#define PDR_BASE   0xFFD00000
 
#define VECTOR_BASE   0xFFFF0000
 
#define IDMAP_BASE   0x00000000
 
#define MMIO_BASE   0x10000000
 
#define LowMemPageTableIndex   (IDMAP_BASE >> PDE_SHIFT)
 
#define MmioPageTableIndex   (MMIO_BASE >> PDE_SHIFT)
 
#define KernelPageTableIndex   (KSEG0_BASE >> PDE_SHIFT)
 
#define StartupPtePageTableIndex   (PTE_BASE >> PDE_SHIFT)
 
#define StartupPdePageTableIndex   (PDE_BASE >> PDE_SHIFT)
 
#define PdrPageTableIndex   (PDR_BASE >> PDE_SHIFT)
 
#define VectorPageTableIndex   (VECTOR_BASE >> PDE_SHIFT)
 
#define PaToPfn(p)   ((p) >> PFN_SHIFT)
 
#define PaToLargePfn(p)   ((p) >> LARGE_PFN_SHIFT)
 
#define PaPtrToPfn(p)   (((ULONG_PTR)(p)) >> PFN_SHIFT)
 
#define PaPtrToPdePfn(p)   (((ULONG_PTR)(p)) >> CPT_SHIFT)
 

Typedefs

typedef struct _KPDR_PAGE KPDR_PAGE
 
typedef struct _KPDR_PAGEPKPDR_PAGE
 

Functions

 C_ASSERT (sizeof(KPDR_PAGE)==(1 *1024 *1024))
 
BOOLEAN MempSetupPaging (IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
 
VOID MempUnmapPage (IN PFN_NUMBER Page)
 
VOID MempDump (VOID)
 
static BOOLEAN WinLdrMapSpecialPages (ULONG PcrBasePage)
 
VOID WinLdrSetupForNt (IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PVOID *GdtIdt, IN PULONG PcrBasePage, IN PULONG TssBasePage)
 
static BOOLEAN MempAllocatePageTables (VOID)
 
VOID WinLdrSetProcessorContext (_In_ USHORT OperatingSystemVersion)
 
VOID WinLdrSetupMachineDependent (PLOADER_PARAMETER_BLOCK LoaderBlock)
 

Variables

PVOID MempPdrBaseAddress = (PVOID)0x70000
 
PVOID MempKernelBaseAddress = (PVOID)0
 
HARDWARE_PTE_ARMV6 TempPte
 
HARDWARE_LARGE_PTE_ARMV6 TempLargePte
 
HARDWARE_PDE_ARMV6 TempPde
 
PKPDR_PAGE PdrPage
 

Macro Definition Documentation

◆ IDMAP_BASE

#define IDMAP_BASE   0x00000000

Definition at line 29 of file winldr.c.

◆ KernelPageTableIndex

#define KernelPageTableIndex   (KSEG0_BASE >> PDE_SHIFT)

Definition at line 35 of file winldr.c.

◆ LARGE_PFN_SHIFT

#define LARGE_PFN_SHIFT   20

Definition at line 18 of file winldr.c.

◆ LowMemPageTableIndex

#define LowMemPageTableIndex   (IDMAP_BASE >> PDE_SHIFT)

Definition at line 33 of file winldr.c.

◆ MMIO_BASE

#define MMIO_BASE   0x10000000

Definition at line 30 of file winldr.c.

◆ MmioPageTableIndex

#define MmioPageTableIndex   (MMIO_BASE >> PDE_SHIFT)

Definition at line 34 of file winldr.c.

◆ PaPtrToPdePfn

#define PaPtrToPdePfn (   p)    (((ULONG_PTR)(p)) >> CPT_SHIFT)

Definition at line 55 of file winldr.c.

◆ PaPtrToPfn

#define PaPtrToPfn (   p)    (((ULONG_PTR)(p)) >> PFN_SHIFT)

Definition at line 52 of file winldr.c.

◆ PaToLargePfn

#define PaToLargePfn (   p)    ((p) >> LARGE_PFN_SHIFT)

Definition at line 51 of file winldr.c.

◆ PaToPfn

#define PaToPfn (   p)    ((p) >> PFN_SHIFT)

Definition at line 50 of file winldr.c.

◆ PDE_BASE

#define PDE_BASE   0xC0400000

Definition at line 21 of file winldr.c.

◆ PDR_BASE

#define PDR_BASE   0xFFD00000

Definition at line 22 of file winldr.c.

◆ PdrPageTableIndex

#define PdrPageTableIndex   (PDR_BASE >> PDE_SHIFT)

Definition at line 38 of file winldr.c.

◆ PFN_SHIFT

#define PFN_SHIFT   12

Definition at line 17 of file winldr.c.

◆ PTE_BASE

#define PTE_BASE   0xC0000000

Definition at line 20 of file winldr.c.

◆ StartupPdePageTableIndex

#define StartupPdePageTableIndex   (PDE_BASE >> PDE_SHIFT)

Definition at line 37 of file winldr.c.

◆ StartupPtePageTableIndex

#define StartupPtePageTableIndex   (PTE_BASE >> PDE_SHIFT)

Definition at line 36 of file winldr.c.

◆ VECTOR_BASE

#define VECTOR_BASE   0xFFFF0000

Definition at line 23 of file winldr.c.

◆ VectorPageTableIndex

#define VectorPageTableIndex   (VECTOR_BASE >> PDE_SHIFT)

Definition at line 39 of file winldr.c.

Typedef Documentation

◆ KPDR_PAGE

◆ PKPDR_PAGE

Function Documentation

◆ C_ASSERT()

C_ASSERT ( sizeof(KPDR_PAGE = =(1 *1024 *1024))

◆ MempAllocatePageTables()

static BOOLEAN MempAllocatePageTables ( VOID  )
static

Definition at line 198 of file winldr.c.

199{
200 ULONG i;
201 PHARDWARE_PTE_ARMV6 PointerPte;
202 PHARDWARE_PDE_ARMV6 PointerPde;
204 PFN_NUMBER Pfn;
205
206 /* Setup templates */
208
209 /* Allocate the 1MB "PDR" (Processor Data Region). Must be 1MB aligned */
213
214 /* Setup the Low Memory PDE as an identity-mapped Large Page (1MB) */
217 *LargePte = TempLargePte;
218
219 /* Setup the MMIO PDE as two identity mapped large pages -- the kernel will blow these away later */
221 Pfn = PaToLargePfn(MMIO_BASE);
222 for (i = 0; i < 2; i++)
223 {
225 *LargePte++ = TempLargePte;
226 }
227
228 /* Setup the Kernel PDEs */
229 PointerPde = &PdrPage->PageDir.Pde[KernelPageTableIndex];
231 for (i = 0; i < 12; i++)
232 {
234 *PointerPde++ = TempPde;
235 Pfn++;
236 }
237
238 /* Setup the Kernel PTEs */
239 PointerPte = PdrPage->KernelPageTable[0].Pte;
241 for (i = 0; i < 3072; i++)
242 {
243 TempPte.PageFrameNumber = Pfn++;
244 *PointerPte++ = TempPte;
245 }
246
247 /* Done */
248 return TRUE;
249}
#define PaPtrToPdePfn(p)
Definition: winldr.c:55
PVOID MempPdrBaseAddress
Definition: winldr.c:42
#define KernelPageTableIndex
Definition: winldr.c:35
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
PKPDR_PAGE PdrPage
Definition: winldr.c:79
#define PaPtrToPfn(p)
Definition: winldr.c:52
#define IDMAP_BASE
Definition: winldr.c:29
HARDWARE_PDE_ARMV6 TempPde
Definition: winldr.c:78
HARDWARE_LARGE_PTE_ARMV6 TempLargePte
Definition: winldr.c:77
#define PaToLargePfn(p)
Definition: winldr.c:51
#define LowMemPageTableIndex
Definition: winldr.c:33
PVOID MempKernelBaseAddress
Definition: winldr.c:43
#define MmioPageTableIndex
Definition: winldr.c:34
#define MMIO_BASE
Definition: winldr.c:30
PVOID MmAllocateMemoryAtAddress(SIZE_T MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:85
#define TRUE
Definition: types.h:120
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
@ LoaderMemoryData
Definition: arc.h:194
ULONG PFN_NUMBER
Definition: ke.h:9
ULONG PageFrameNumber
Definition: mmtypes.h:74
ULONG PageFrameNumber
Definition: mmtypes.h:109
PAGE_TABLE_ARM KernelPageTable[3]
Definition: winldr.c:61
PAGE_DIRECTORY_ARM PageDir
Definition: winldr.c:59
HARDWARE_LARGE_PTE_ARMV6 Pte[4096]
Definition: hardware.h:53
HARDWARE_PDE_ARMV6 Pde[4096]
Definition: hardware.h:52
HARDWARE_PTE_ARMV6 Pte[1024]
Definition: hardware.h:44
uint32_t ULONG
Definition: typedefs.h:59

◆ MempDump()

VOID MempDump ( VOID  )

Definition at line 98 of file winldr.c.

99{
100 return;
101}

◆ MempSetupPaging()

BOOLEAN MempSetupPaging ( IN PFN_NUMBER  StartPage,
IN PFN_NUMBER  NumberOfPages,
IN BOOLEAN  KernelMapping 
)

Definition at line 84 of file winldr.c.

87{
88 return TRUE;
89}

◆ MempUnmapPage()

VOID MempUnmapPage ( IN PFN_NUMBER  Page)

Definition at line 92 of file winldr.c.

93{
94 return;
95}

◆ WinLdrMapSpecialPages()

static BOOLEAN WinLdrMapSpecialPages ( ULONG  PcrBasePage)
static

Definition at line 105 of file winldr.c.

106{
107 ULONG i;
108 PHARDWARE_PTE_ARMV6 PointerPte;
109 PHARDWARE_PDE_ARMV6 PointerPde;
111 PFN_NUMBER Pfn;
112
113 /* Setup the Startup PDE */
116 *LargePte = TempLargePte;
117
118 /* Map-in the PDR */
119 LargePte = &PdrPage->PageDir.Pte[PdrPageTableIndex];
120 *LargePte = TempLargePte;
121
122 /* After this point, any MiAddressToPde is guaranteed not to fault */
123
124 /*
125 * Link them in the Startup PDE.
126 * Note these are the entries in the PD at (MiAddressToPde(PTE_BASE)).
127 */
130 for (i = 0; i < 4; i++)
131 {
132 TempPde.PageFrameNumber = Pfn++;
133 *PointerPde++ = TempPde;
134 }
135
136 /*
137 * Now map these page tables in PTE space (MiAddressToPte(PTE_BASE)).
138 * Note that they all live on a single page, since each is 1KB.
139 */
140 PointerPte = &PdrPage->PageDirPageTable.Pte[0x300];
142 *PointerPte = TempPte;
143
144 /*
145 * After this point, MiAddressToPte((PDE_BASE) to MiAddressToPte(PDE_TOP))
146 * is guaranteed not to fault.
147 * Any subsequent page allocation will first need its page table created
148 * and mapped in the PTE_BASE first, then the page table itself will be
149 * editable through its flat PTE address.
150 */
151
152 /* Setup the Vector PDE */
153 PointerPde = &PdrPage->PageDir.Pde[VectorPageTableIndex];
155 *PointerPde = TempPde;
156
157 /* Setup the Vector PTEs */
158 PointerPte = &PdrPage->VectorPageTable.Pte[0xF0];
160 *PointerPte = TempPte;
161
162 /* TODO: Map in the kernel CPTs */
163 return TRUE;
164}
#define StartupPdePageTableIndex
Definition: winldr.c:37
#define StartupPtePageTableIndex
Definition: winldr.c:36
#define VectorPageTableIndex
Definition: winldr.c:39
#define PdrPageTableIndex
Definition: winldr.c:38
PAGE_TABLE_ARM PageDirPageTable
Definition: winldr.c:69
PAGE_TABLE_ARM VectorPageTable
Definition: winldr.c:70
uint32_t ULONG_PTR
Definition: typedefs.h:65

◆ WinLdrSetProcessorContext()

VOID WinLdrSetProcessorContext ( _In_ USHORT  OperatingSystemVersion)

Definition at line 252 of file winldr.c.

254{
255 ARM_CONTROL_REGISTER ControlRegister;
256 ARM_TTB_REGISTER TtbRegister;
257 ARM_DOMAIN_REGISTER DomainRegister;
258
259 /* Set the TTBR */
260 TtbRegister.AsUlong = (ULONG_PTR)&PdrPage->PageDir;
261 ASSERT(TtbRegister.Reserved == 0);
263
264 /* Disable domains and simply use access bits on PTEs */
265 DomainRegister.AsUlong = 0;
266 DomainRegister.Domain0 = ClientDomain;
267 KeArmDomainRegisterSet(DomainRegister);
268
269 /* Enable ARMv6+ paging (MMU), caches and the access bit */
270 ControlRegister = KeArmControlRegisterGet();
271 ControlRegister.MmuEnabled = TRUE;
272 ControlRegister.ICacheEnabled = TRUE;
273 ControlRegister.DCacheEnabled = TRUE;
274 ControlRegister.ForceAp = TRUE;
275 ControlRegister.ExtendedPageTables = TRUE;
276 KeArmControlRegisterSet(ControlRegister);
277}
FORCEINLINE VOID KeArmControlRegisterSet(IN ARM_CONTROL_REGISTER ControlRegister)
Definition: intrin_i.h:135
FORCEINLINE VOID KeArmDomainRegisterSet(IN ARM_DOMAIN_REGISTER DomainRegister)
Definition: intrin_i.h:155
FORCEINLINE ARM_CONTROL_REGISTER KeArmControlRegisterGet(VOID)
Definition: intrin_i.h:18
FORCEINLINE VOID KeArmTranslationTableRegisterSet(IN ARM_TTB_REGISTER Ttb)
Definition: intrin_i.h:145
@ ClientDomain
Definition: hardware.h:62
#define ULONG_PTR
Definition: config.h:101
#define ASSERT(a)
Definition: mode.c:44
ULONG ExtendedPageTables
Definition: ketypes.h:520

◆ WinLdrSetupForNt()

VOID WinLdrSetupForNt ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock,
IN PVOID GdtIdt,
IN PULONG  PcrBasePage,
IN PULONG  TssBasePage 
)

Definition at line 167 of file winldr.c.

171{
172 PKPDR_PAGE PdrPage = (PVOID)0xFFD00000;
173
174 /* Load cache information */
175 LoaderBlock->u.Arm.FirstLevelDcacheSize = FirstLevelDcacheSize;
176 LoaderBlock->u.Arm.FirstLevelDcacheFillSize = FirstLevelDcacheFillSize;
177 LoaderBlock->u.Arm.FirstLevelIcacheSize = FirstLevelIcacheSize;
178 LoaderBlock->u.Arm.FirstLevelIcacheFillSize = FirstLevelIcacheFillSize;
179 LoaderBlock->u.Arm.SecondLevelDcacheSize = SecondLevelDcacheSize;
180 LoaderBlock->u.Arm.SecondLevelDcacheFillSize = SecondLevelDcacheFillSize;
181 LoaderBlock->u.Arm.SecondLevelIcacheSize = SecondLevelIcacheSize;
182 LoaderBlock->u.Arm.SecondLevelIcacheFillSize = SecondLevelIcacheSize;
183
184 /* Write initial context information */
185 LoaderBlock->KernelStack = (ULONG_PTR)PdrPage->KernelStack;
186 LoaderBlock->KernelStack += KERNEL_STACK_SIZE;
187 LoaderBlock->u.Arm.PanicStack = (ULONG_PTR)PdrPage->PanicStack;
188 LoaderBlock->u.Arm.PanicStack += KERNEL_STACK_SIZE;
189 LoaderBlock->u.Arm.InterruptStack = (ULONG_PTR)PdrPage->InterruptStack;
190 LoaderBlock->u.Arm.InterruptStack += KERNEL_STACK_SIZE;
191 LoaderBlock->Prcb = (ULONG_PTR)PdrPage->Prcb;
192 LoaderBlock->Process = (ULONG_PTR)PdrPage->InitialProcess;
193 LoaderBlock->Thread = (ULONG_PTR)PdrPage->InitialThread;
194}
ULONG FirstLevelIcacheFillSize
Definition: macharm.c:28
ULONG SecondLevelDcacheSize
Definition: macharm.c:29
ULONG FirstLevelDcacheFillSize
Definition: macharm.c:26
ULONG FirstLevelIcacheSize
Definition: macharm.c:27
ULONG SecondLevelIcacheSize
Definition: macharm.c:31
ULONG FirstLevelDcacheSize
Definition: macharm.c:25
ULONG SecondLevelDcacheFillSize
Definition: macharm.c:30
#define KERNEL_STACK_SIZE
CHAR KernelStack[KERNEL_STACK_SIZE]
Definition: winldr.c:63
CHAR Prcb[PAGE_SIZE]
Definition: winldr.c:68
CHAR InitialThread[PAGE_SIZE]
Definition: winldr.c:67
CHAR InterruptStack[KERNEL_STACK_SIZE]
Definition: winldr.c:65
CHAR InitialProcess[PAGE_SIZE]
Definition: winldr.c:66
CHAR PanicStack[KERNEL_STACK_SIZE]
Definition: winldr.c:64
void * PVOID
Definition: typedefs.h:50

◆ WinLdrSetupMachineDependent()

VOID WinLdrSetupMachineDependent ( PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 280 of file winldr.c.

282{
283}

Variable Documentation

◆ MempKernelBaseAddress

PVOID MempKernelBaseAddress = (PVOID)0

Definition at line 43 of file winldr.c.

Referenced by MempAllocatePageTables().

◆ MempPdrBaseAddress

PVOID MempPdrBaseAddress = (PVOID)0x70000

Definition at line 42 of file winldr.c.

Referenced by MempAllocatePageTables().

◆ PdrPage

◆ TempLargePte

Definition at line 77 of file winldr.c.

Referenced by MempAllocatePageTables(), and WinLdrMapSpecialPages().

◆ TempPde

◆ TempPte

Definition at line 76 of file winldr.c.

Referenced by _IRQL_requires_max_(), GetFreeWsleIndex(), KdpPhysMap(), MempAllocatePageTables(), MI_UPDATE_VALID_PTE(), MI_WRITE_VALID_PTE(), MiAccessCheck(), MiAddMappedPtes(), MiAllocatePoolPages(), MiArchCreateProcessAddressSpace(), MiBuildPagedPool(), MiCompleteProtoPteFault(), MiCopyPfn(), MiCreatePagingFileMap(), MiDbgTranslatePhysicalAddress(), MiDecrementShareCount(), MiDeletePte(), MiDeleteVirtualAddresses(), MiDetermineUserGlobalPteMask(), MiDispatchFault(), MiFlushTbAndCapture(), MiGetPageProtection(), MiGetPageTableForProcess(), MiInitializeColorTables(), MiInitializePfnAndMakePteValid(), MiInitMachineDependent(), MiLoadImageSection(), MiMapLockedPagesInUserSpace(), MiMapPageInHyperSpace(), MiMapPagesInZeroSpace(), MiMapPfnDatabase(), MiMapViewOfDataSection(), MiProcessValidPteList(), MiProtectFreeNonPagedPool(), MiQueryAddressState(), MiReloadBootLoadedDrivers(), MiResolveDemandZeroFault(), MiResolvePageFileFault(), MiResolveProtoPteFault(), MiResolveTransitionFault(), MiSegmentDelete(), MiSessionCreateInternal(), MiSessionInitializeWorkingSetList(), MiSetSystemCodeProtection(), MiUnProtectFreeNonPagedPool(), MiZeroPfn(), MmAllocateNonCachedMemory(), MmAllocateSpecialPool(), MmArmAccessFault(), MmArmInitSystem(), MmChangeKernelResourceSectionProtection(), MmCommitSessionMappedView(), MmCreateKernelStack(), MmCreateVirtualMappingInternal(), MmCreateVirtualMappingUnsafeEx(), MmGetPhysicalAddress(), MmGrowKernelStackEx(), MmInitSystem(), MmMapIoSpace(), MmMapLockedPagesSpecifyCache(), MmSetPageProtect(), NtAllocateVirtualMemory(), and WinLdrMapSpecialPages().