Sync with trunk r58113.
[reactos.git] / ntoskrnl / mm / arm / page.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/mm/arm/page.c
5 * PURPOSE: Old-school Page Management
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 #define MODULE_INVOLVED_IN_ARM3
16 #include "../ARM3/miarm.h"
17
18 /* GLOBALS ********************************************************************/
19
20 const
21 ULONG
22 MmProtectToPteMask[32] =
23 {
24 //
25 // These are the base MM_ protection flags
26 //
27 0,
28 PTE_READONLY | PTE_ENABLE_CACHE,
29 PTE_EXECUTE | PTE_ENABLE_CACHE,
30 PTE_EXECUTE_READ | PTE_ENABLE_CACHE,
31 PTE_READWRITE | PTE_ENABLE_CACHE,
32 PTE_WRITECOPY | PTE_ENABLE_CACHE,
33 PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE,
34 PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE,
35 //
36 // These OR in the MM_NOCACHE flag
37 //
38 0,
39 PTE_READONLY | PTE_DISABLE_CACHE,
40 PTE_EXECUTE | PTE_DISABLE_CACHE,
41 PTE_EXECUTE_READ | PTE_DISABLE_CACHE,
42 PTE_READWRITE | PTE_DISABLE_CACHE,
43 PTE_WRITECOPY | PTE_DISABLE_CACHE,
44 PTE_EXECUTE_READWRITE | PTE_DISABLE_CACHE,
45 PTE_EXECUTE_WRITECOPY | PTE_DISABLE_CACHE,
46 //
47 // These OR in the MM_DECOMMIT flag, which doesn't seem supported on x86/64/ARM
48 //
49 0,
50 PTE_READONLY | PTE_ENABLE_CACHE,
51 PTE_EXECUTE | PTE_ENABLE_CACHE,
52 PTE_EXECUTE_READ | PTE_ENABLE_CACHE,
53 PTE_READWRITE | PTE_ENABLE_CACHE,
54 PTE_WRITECOPY | PTE_ENABLE_CACHE,
55 PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE,
56 PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE,
57 //
58 // These OR in the MM_NOACCESS flag, which seems to enable WriteCombining?
59 //
60 0,
61 PTE_READONLY | PTE_WRITECOMBINED_CACHE,
62 PTE_EXECUTE | PTE_WRITECOMBINED_CACHE,
63 PTE_EXECUTE_READ | PTE_WRITECOMBINED_CACHE,
64 PTE_READWRITE | PTE_WRITECOMBINED_CACHE,
65 PTE_WRITECOPY | PTE_WRITECOMBINED_CACHE,
66 PTE_EXECUTE_READWRITE | PTE_WRITECOMBINED_CACHE,
67 PTE_EXECUTE_WRITECOPY | PTE_WRITECOMBINED_CACHE,
68 };
69
70 const
71 ULONG MmProtectToValue[32] =
72 {
73 PAGE_NOACCESS,
74 PAGE_READONLY,
75 PAGE_EXECUTE,
76 PAGE_EXECUTE_READ,
77 PAGE_READWRITE,
78 PAGE_WRITECOPY,
79 PAGE_EXECUTE_READWRITE,
80 PAGE_EXECUTE_WRITECOPY,
81 PAGE_NOACCESS,
82 PAGE_NOCACHE | PAGE_READONLY,
83 PAGE_NOCACHE | PAGE_EXECUTE,
84 PAGE_NOCACHE | PAGE_EXECUTE_READ,
85 PAGE_NOCACHE | PAGE_READWRITE,
86 PAGE_NOCACHE | PAGE_WRITECOPY,
87 PAGE_NOCACHE | PAGE_EXECUTE_READWRITE,
88 PAGE_NOCACHE | PAGE_EXECUTE_WRITECOPY,
89 PAGE_NOACCESS,
90 PAGE_GUARD | PAGE_READONLY,
91 PAGE_GUARD | PAGE_EXECUTE,
92 PAGE_GUARD | PAGE_EXECUTE_READ,
93 PAGE_GUARD | PAGE_READWRITE,
94 PAGE_GUARD | PAGE_WRITECOPY,
95 PAGE_GUARD | PAGE_EXECUTE_READWRITE,
96 PAGE_GUARD | PAGE_EXECUTE_WRITECOPY,
97 PAGE_NOACCESS,
98 PAGE_WRITECOMBINE | PAGE_READONLY,
99 PAGE_WRITECOMBINE | PAGE_EXECUTE,
100 PAGE_WRITECOMBINE | PAGE_EXECUTE_READ,
101 PAGE_WRITECOMBINE | PAGE_READWRITE,
102 PAGE_WRITECOMBINE | PAGE_WRITECOPY,
103 PAGE_WRITECOMBINE | PAGE_EXECUTE_READWRITE,
104 PAGE_WRITECOMBINE | PAGE_EXECUTE_WRITECOPY
105 };
106
107 ULONG MmGlobalKernelPageDirectory[4096];
108
109 /* Template PTE and PDE for a kernel page */
110 MMPDE ValidKernelPde = {.u.Hard.Valid = 1};
111 MMPTE ValidKernelPte = {.u.Hard.Valid = 1, .u.Hard.Sbo = 1};
112
113 /* Template PDE for a demand-zero page */
114 MMPDE DemandZeroPde = {.u.Long = (MM_READWRITE << MM_PTE_SOFTWARE_PROTECTION_BITS)};
115 MMPTE DemandZeroPte = {.u.Long = (MM_READWRITE << MM_PTE_SOFTWARE_PROTECTION_BITS)};
116
117 /* Template PTE for prototype page */
118 MMPTE PrototypePte = {.u.Long = (MM_READWRITE << MM_PTE_SOFTWARE_PROTECTION_BITS) | PTE_PROTOTYPE | (MI_PTE_LOOKUP_NEEDED << PAGE_SHIFT)};
119
120 /* PRIVATE FUNCTIONS **********************************************************/
121
122 VOID
123 NTAPI
124 MiFlushTlb(IN PMMPTE PointerPte,
125 IN PVOID Address)
126 {
127 UNIMPLEMENTED;
128 ASSERT(FALSE); // while (TRUE);
129 }
130
131 BOOLEAN
132 NTAPI
133 MmCreateProcessAddressSpace(IN ULONG MinWs,
134 IN PEPROCESS Process,
135 IN PULONG DirectoryTableBase)
136 {
137 UNIMPLEMENTED;
138 ASSERT(FALSE); // while (TRUE);
139 return FALSE;
140 }
141
142 VOID
143 NTAPI
144 MmUpdatePageDir(IN PEPROCESS Process,
145 IN PVOID Address,
146 IN ULONG Size)
147 {
148 /* Nothing to do */
149 return;
150 }
151
152 PULONG
153 NTAPI
154 MmGetPageDirectory(VOID)
155 {
156 /* Return the TTB */
157 return (PULONG)KeArmTranslationTableRegisterGet().AsUlong;
158 }
159
160 VOID
161 NTAPI
162 MmDisableVirtualMapping(IN PEPROCESS Process,
163 IN PVOID Address,
164 OUT PBOOLEAN WasDirty,
165 OUT PPFN_NUMBER Page)
166 {
167 UNIMPLEMENTED;
168 ASSERT(FALSE); // while (TRUE);
169 }
170
171 VOID
172 NTAPI
173 MmEnableVirtualMapping(IN PEPROCESS Process,
174 IN PVOID Address)
175 {
176 UNIMPLEMENTED;
177 ASSERT(FALSE); // while (TRUE);
178 }
179
180 NTSTATUS
181 NTAPI
182 MmCreateVirtualMappingUnsafe(IN PEPROCESS Process,
183 IN PVOID Address,
184 IN ULONG Protection,
185 IN PPFN_NUMBER Pages,
186 IN ULONG PageCount)
187 {
188 UNIMPLEMENTED;
189 ASSERT(FALSE); // while (TRUE);
190 return STATUS_SUCCESS;
191 }
192
193 NTSTATUS
194 NTAPI
195 MmCreateVirtualMapping(IN PEPROCESS Process,
196 IN PVOID Address,
197 IN ULONG Protection,
198 IN PPFN_NUMBER Pages,
199 IN ULONG PageCount)
200 {
201 UNIMPLEMENTED;
202 ASSERT(FALSE); // while (TRUE);
203 return STATUS_SUCCESS;
204 }
205
206 VOID
207 NTAPI
208 MmRawDeleteVirtualMapping(IN PVOID Address)
209 {
210 UNIMPLEMENTED;
211 ASSERT(FALSE); // while (TRUE);
212 }
213
214 VOID
215 NTAPI
216 MmDeleteVirtualMapping(IN PEPROCESS Process,
217 IN PVOID Address,
218 IN BOOLEAN FreePage,
219 OUT PBOOLEAN WasDirty,
220 OUT PPFN_NUMBER Page)
221 {
222 UNIMPLEMENTED;
223 ASSERT(FALSE); // while (TRUE);
224 }
225
226 VOID
227 NTAPI
228 MmDeletePageFileMapping(IN PEPROCESS Process,
229 IN PVOID Address,
230 IN SWAPENTRY *SwapEntry)
231 {
232 UNIMPLEMENTED;
233 ASSERT(FALSE); // while (TRUE);
234 }
235
236 NTSTATUS
237 NTAPI
238 MmCreatePageFileMapping(IN PEPROCESS Process,
239 IN PVOID Address,
240 IN SWAPENTRY SwapEntry)
241 {
242 UNIMPLEMENTED;
243 ASSERT(FALSE); // while (TRUE);
244 return STATUS_NOT_IMPLEMENTED;
245 }
246
247 PFN_NUMBER
248 NTAPI
249 MmGetPfnForProcess(IN PEPROCESS Process,
250 IN PVOID Address)
251 {
252 UNIMPLEMENTED;
253 ASSERT(FALSE); // while (TRUE);
254 return 0;
255 }
256
257 BOOLEAN
258 NTAPI
259 MmIsDirtyPage(IN PEPROCESS Process,
260 IN PVOID Address)
261 {
262 UNIMPLEMENTED;
263 ASSERT(FALSE); // while (TRUE);
264 return FALSE;
265 }
266
267 VOID
268 NTAPI
269 MmSetCleanPage(IN PEPROCESS Process,
270 IN PVOID Address)
271 {
272 UNIMPLEMENTED;
273 ASSERT(FALSE); // while (TRUE);
274 }
275
276 VOID
277 NTAPI
278 MmSetDirtyPage(IN PEPROCESS Process,
279 IN PVOID Address)
280 {
281 UNIMPLEMENTED;
282 ASSERT(FALSE); // while (TRUE);
283 }
284
285 BOOLEAN
286 NTAPI
287 MmIsPagePresent(IN PEPROCESS Process,
288 IN PVOID Address)
289 {
290 UNIMPLEMENTED;
291 ASSERT(FALSE); // while (TRUE);
292 return FALSE;
293 }
294
295 BOOLEAN
296 NTAPI
297 MmIsPageSwapEntry(IN PEPROCESS Process,
298 IN PVOID Address)
299 {
300 UNIMPLEMENTED;
301 ASSERT(FALSE); // while (TRUE);
302 return FALSE;
303 }
304
305 ULONG
306 NTAPI
307 MmGetPageProtect(IN PEPROCESS Process,
308 IN PVOID Address)
309 {
310 /* We don't enforce any protection on the pages -- they are all RWX */
311 return PAGE_READWRITE;
312 }
313
314 VOID
315 NTAPI
316 MmSetPageProtect(IN PEPROCESS Process,
317 IN PVOID Address,
318 IN ULONG Protection)
319 {
320 /* We don't enforce any protection on the pages -- they are all RWX */
321 return;
322 }
323
324 VOID
325 NTAPI
326 MmInitGlobalKernelPageDirectory(VOID)
327 {
328 ULONG i;
329 PULONG CurrentPageDirectory = (PULONG)PDE_BASE;
330
331
332 /* Loop the 2GB of address space which belong to the kernel */
333 for (i = MiGetPdeOffset(MmSystemRangeStart); i < 2048; i++)
334 {
335 /* Check if we have an entry for this already */
336 if ((i != MiGetPdeOffset(PTE_BASE)) &&
337 (i != MiGetPdeOffset(HYPER_SPACE)) &&
338 (!MmGlobalKernelPageDirectory[i]) &&
339 (CurrentPageDirectory[i]))
340 {
341 /* We don't, link it in our global page directory */
342 MmGlobalKernelPageDirectory[i] = CurrentPageDirectory[i];
343 }
344 }
345 }
346
347 /* PUBLIC FUNCTIONS ***********************************************************/
348
349 /*
350 * @implemented
351 */
352 PHYSICAL_ADDRESS
353 NTAPI
354 MmGetPhysicalAddress(IN PVOID Address)
355 {
356 PHYSICAL_ADDRESS PhysicalAddress;
357 PhysicalAddress.QuadPart = 0;
358
359 UNIMPLEMENTED;
360 ASSERT(FALSE); // while (TRUE);
361
362 return PhysicalAddress;
363 }