Skip to content

Commit bf310b5

Browse files
author
Sir Richard
committed
[NTOS]: Implement new and correct MiAddressToPte, ToPde, ToPdeOffset, and MiPdeToAddres and MiAddressToPte on ARM. Remove deprecated ARM page definitions.
[NTOS]: Move HYPER_SPACE to 0xC0500000 since it must be on its own PDE. We need to revisit some FreeLDR Mm decisions later. [NTOS]: Move certain arch-specific definitions from mm.h to the arch-specific mm.h [NTOS]: Fix certain parts of ARM3 which made the assumption that a PDE shares the same structure as a PTE. This is true on all architectures except ARM. We now define a new MMPDE type specifically for PDEs. On x86 it is defined to MMPTE with no changes. svn path=/trunk/; revision=45542
1 parent 5095fd3 commit bf310b5

File tree

5 files changed

+69
-196
lines changed

5 files changed

+69
-196
lines changed

reactos/ntoskrnl/include/internal/arm/mm.h

Lines changed: 35 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define PTE_BASE 0xC0000000
2626
#define PTE_TOP 0xC03FFFFF
2727
#define PDE_BASE 0xC0400000
28-
#define HYPER_SPACE 0xC0404000
28+
#define HYPER_SPACE 0xC0500000
2929

3030
#if 0
3131
typedef struct _HARDWARE_PDE_ARMV6
@@ -123,167 +123,39 @@ PULONG MmGetPageDirectory(VOID);
123123
/* Easy accessing PFN in PTE */
124124
#define PFN_FROM_PTE(v) ((v)->u.Hard.PageFrameNumber)
125125

126-
127-
#if 1
128-
129-
//
130-
// FIXFIX: This is all wrong now!!!
131-
//
132-
133-
//
134-
// Take 0x80812345 and extract:
135-
// PTE_BASE[0x808][0x12]
136-
//
137-
#define MiGetPteAddress(x) \
138-
(PMMPTE)(PTE_BASE + \
139-
(((ULONG)(x) >> 20) << 12) + \
140-
((((ULONG)(x) >> 12) & 0xFF) << 2))
141-
142-
#define MiGetPdeAddress(x) \
143-
(PMMPDE_HARDWARE)(PDE_BASE + \
144-
(((ULONG)(x) >> 20) << 2))
145-
146-
#define MiGetPdeOffset(x) (((ULONG)(x)) >> 22)
147-
148-
//
149-
// FIXME: THESE ARE WRONG ATM.
150-
//
151-
#define MiAddressToPde(x) \
152-
((PMMPTE)(((((ULONG)(x)) >> 22) << 2) + PDE_BASE))
153-
#define MiAddressToPte(x) \
154-
((PMMPTE)(((((ULONG)(x)) >> 12) << 2) + PTE_BASE))
155-
#define MiAddressToPteOffset(x) \
156-
((((ULONG)(x)) << 10) >> 22)
157-
158-
159-
//
160-
// Convert a PTE into a corresponding address
161-
//
162-
#define MiPteToAddress(PTE) ((PVOID)((ULONG)(PTE) << 10))
163-
164-
#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
165-
#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE)))
166-
#define ADDR_TO_PTE_OFFSET(v) ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE_SIZE)
167-
168-
//
169-
// FIXFIX: This is all wrong now!!!
170-
//
171-
typedef union _ARM_PTE
172-
{
173-
union
174-
{
175-
struct
176-
{
177-
ULONG Type:2;
178-
ULONG Unused:30;
179-
} Fault;
180-
struct
181-
{
182-
ULONG Type:2;
183-
ULONG Ignored:2;
184-
ULONG Reserved:1;
185-
ULONG Domain:4;
186-
ULONG Ignored1:1;
187-
ULONG BaseAddress:22;
188-
} Coarse;
189-
struct
190-
{
191-
ULONG Type:2;
192-
ULONG Buffered:1;
193-
ULONG Cached:1;
194-
ULONG Reserved:1;
195-
ULONG Domain:4;
196-
ULONG Ignored:1;
197-
ULONG Access:2;
198-
ULONG Ignored1:8;
199-
ULONG BaseAddress:12;
200-
} Section;
201-
struct
202-
{
203-
ULONG Type:2;
204-
ULONG Reserved:3;
205-
ULONG Domain:4;
206-
ULONG Ignored:3;
207-
ULONG BaseAddress:20;
208-
} Fine;
209-
} L1;
210-
union
211-
{
212-
struct
213-
{
214-
ULONG Type:2;
215-
ULONG Unused:30;
216-
} Fault;
217-
struct
218-
{
219-
ULONG Type:2;
220-
ULONG Buffered:1;
221-
ULONG Cached:1;
222-
ULONG Access0:2;
223-
ULONG Access1:2;
224-
ULONG Access2:2;
225-
ULONG Access3:2;
226-
ULONG Ignored:4;
227-
ULONG BaseAddress:16;
228-
} Large;
229-
struct
230-
{
231-
ULONG Type:2;
232-
ULONG Buffered:1;
233-
ULONG Cached:1;
234-
ULONG Access0:2;
235-
ULONG Access1:2;
236-
ULONG Access2:2;
237-
ULONG Access3:2;
238-
ULONG BaseAddress:20;
239-
} Small;
240-
struct
241-
{
242-
ULONG Type:2;
243-
ULONG Buffered:1;
244-
ULONG Cached:1;
245-
ULONG Access0:2;
246-
ULONG Ignored:4;
247-
ULONG BaseAddress:22;
248-
} Tiny;
249-
} L2;
250-
ULONG AsUlong;
251-
} ARM_PTE, *PARM_PTE;
252-
253-
typedef struct _ARM_TRANSLATION_TABLE
254-
{
255-
ARM_PTE Pte[4096];
256-
} ARM_TRANSLATION_TABLE, *PARM_TRANSLATION_TABLE;
257-
258-
typedef struct _ARM_COARSE_PAGE_TABLE
259-
{
260-
ARM_PTE Pte[256];
261-
ULONG Padding[768];
262-
} ARM_COARSE_PAGE_TABLE, *PARM_COARSE_PAGE_TABLE;
263-
264-
typedef enum _ARM_L1_PTE_TYPE
265-
{
266-
FaultPte,
267-
CoarsePte,
268-
SectionPte,
269-
FinePte
270-
} ARM_L1_PTE_TYPE;
271-
272-
typedef enum _ARM_L2_PTE_TYPE
273-
{
274-
LargePte = 1,
275-
SmallPte,
276-
TinyPte
277-
} ARM_L2_PTE_TYPE;
278-
279-
typedef enum _ARM_PTE_ACCESS
280-
{
281-
FaultAccess,
282-
SupervisorAccess,
283-
SharedAccess,
284-
UserAccess
285-
} ARM_PTE_ACCESS;
286-
287-
#endif
126+
#define NR_SECTION_PAGE_TABLES 1024
127+
#define NR_SECTION_PAGE_ENTRIES 256
128+
129+
/* See PDR definition */
130+
#define MI_HYPERSPACE_PTES (256 - 1)
131+
#define MI_ZERO_PTES (32)
132+
#define MI_MAPPING_RANGE_START ((ULONG)HYPER_SPACE)
133+
#define MI_MAPPING_RANGE_END (MI_MAPPING_RANGE_START + \
134+
MI_HYPERSPACE_PTES * PAGE_SIZE)
135+
#define MI_ZERO_PTE (PMMPTE)(MI_MAPPING_RANGE_END + \
136+
PAGE_SIZE)
137+
138+
/* Retrives the PDE entry for the given VA */
139+
#define MiGetPdeAddress(x) ((PMMPDE)(PDE_BASE + (((ULONG)(x) >> 20) << 2)))
140+
#define MiAddressToPde(x) MiGetPdeAddress(x)
141+
142+
/* Retrieves the PTE entry for the given VA */
143+
#define MiGetPteAddress(x) ((PMMPTE)(PTE_BASE + (((ULONG)(x) >> 12) << 2)))
144+
#define MiAddressToPte(x) MiGetPteAddress(x)
145+
146+
/* Retrives the PDE offset for the given VA */
147+
#define MiGetPdeOffset(x) (((ULONG)(x)) >> 20)
148+
149+
/* Convert a PTE into a corresponding address */
150+
#define MiPteToAddress(x) ((PVOID)((ULONG)(x) << 10))
151+
#define MiPdeToAddress(x) ((PVOID)((ULONG)(x) << 18))
152+
153+
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
154+
((x) / (4*1024*1024))
155+
156+
#define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) \
157+
((((x)) % (4*1024*1024)) / (4*1024))
158+
159+
#define MM_CACHE_LINE_SIZE 64
288160

289161
#endif

reactos/ntoskrnl/include/internal/i386/mm.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,32 @@ PULONG MmGetPageDirectory(VOID);
5959
#define MI_MAKE_WRITE_PAGE(x) ((x)->u.Hard.Writable = 1)
6060
#endif
6161

62+
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
63+
((x) / (4*1024*1024))
64+
65+
#define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) \
66+
((((x)) % (4*1024*1024)) / (4*1024))
67+
68+
#define NR_SECTION_PAGE_TABLES 1024
69+
#define NR_SECTION_PAGE_ENTRIES 1024
70+
71+
#define TEB_BASE 0x7FFDE000
72+
73+
#define MI_HYPERSPACE_PTES (256 - 1)
74+
#define MI_ZERO_PTES (32)
75+
#define MI_MAPPING_RANGE_START (ULONG)HYPER_SPACE
76+
#define MI_MAPPING_RANGE_END (MI_MAPPING_RANGE_START + \
77+
MI_HYPERSPACE_PTES * PAGE_SIZE)
78+
#define MI_ZERO_PTE (PMMPTE)(MI_MAPPING_RANGE_END + \
79+
PAGE_SIZE)
80+
81+
/* On x86, these two are the same */
82+
#define MMPDE MMPTE
83+
#define PMMPDE PMMPTE
84+
85+
/*
86+
* FIXME - different architectures have different cache line sizes...
87+
*/
88+
#define MM_CACHE_LINE_SIZE 32
89+
6290
#endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_MM_H */

reactos/ntoskrnl/include/internal/mm.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,10 @@ typedef ULONG PFN_TYPE, *PPFN_TYPE;
108108
/* Number of list heads to use */
109109
#define MI_FREE_POOL_LISTS 4
110110

111-
#define MI_HYPERSPACE_PTES (256 - 1)
112-
#define MI_ZERO_PTES (32)
113-
#define MI_MAPPING_RANGE_START (ULONG)HYPER_SPACE
114-
#define MI_MAPPING_RANGE_END (MI_MAPPING_RANGE_START + \
115-
MI_HYPERSPACE_PTES * PAGE_SIZE)
116-
#define MI_ZERO_PTE (PMMPTE)(MI_MAPPING_RANGE_END + \
117-
PAGE_SIZE)
118111

119112
/* Signature of free pool blocks */
120113
#define MM_FREE_POOL_TAG 'lprF'
121114

122-
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
123-
((x) / (4*1024*1024))
124-
125-
#define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) \
126-
((((x)) % (4*1024*1024)) / (4*1024))
127-
128-
#define NR_SECTION_PAGE_TABLES 1024
129-
#define NR_SECTION_PAGE_ENTRIES 1024
130-
131-
#define TEB_BASE 0x7FFDE000
132-
133115
/* Although Microsoft says this isn't hardcoded anymore,
134116
they won't be able to change it. Stuff depends on it */
135117
#define MM_VIRTMEM_GRANULARITY (64 * 1024)
@@ -169,17 +151,6 @@ typedef ULONG PFN_TYPE, *PPFN_TYPE;
169151
*/
170152
#define MM_POOL_ALIGNMENT 8
171153

172-
/*
173-
* Maximum size of the kmalloc area (this is totally arbitary)
174-
*/
175-
#define MM_KERNEL_MAP_SIZE (16*1024*1024)
176-
#define MM_KERNEL_MAP_BASE (0xf0c00000)
177-
178-
/*
179-
* FIXME - different architectures have different cache line sizes...
180-
*/
181-
#define MM_CACHE_LINE_SIZE 32
182-
183154
#define MM_ROUND_UP(x,s) \
184155
((PVOID)(((ULONG_PTR)(x)+(s)-1) & ~((ULONG_PTR)(s)-1)))
185156

reactos/ntoskrnl/mm/ARM3/mdlsup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ MmProbeAndLockPages(IN PMDL Mdl,
579579
PETHREAD Thread;
580580
PMMSUPPORT AddressSpace;
581581
NTSTATUS ProbeStatus;
582-
PMMPTE PointerPte, PointerPde, LastPte;
582+
PMMPTE PointerPte, LastPte;
583+
PMMPDE PointerPde;
583584
PFN_NUMBER PageFrameIndex;
584585
PMMPFN Pfn1;
585586
BOOLEAN UsePfnLock;

reactos/ntoskrnl/mm/ARM3/pagfault.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ NTSTATUS
2424
FASTCALL
2525
MiCheckPdeForPagedPool(IN PVOID Address)
2626
{
27-
PMMPTE PointerPde;
27+
PMMPDE PointerPde;
2828
NTSTATUS Status = STATUS_SUCCESS;
2929

3030
//
@@ -37,7 +37,7 @@ MiCheckPdeForPagedPool(IN PVOID Address)
3737
// Send a hint to the page fault handler that this is only a valid fault
3838
// if we already detected this was access within the page table range
3939
//
40-
PointerPde = MiAddressToPte(Address);
40+
PointerPde = (PMMPDE)MiAddressToPte(Address);
4141
Status = STATUS_WAIT_1;
4242
}
4343
else if (Address < MmSystemRangeStart)
@@ -200,7 +200,8 @@ MmArmAccessFault(IN BOOLEAN StoreInstruction,
200200
IN PVOID TrapInformation)
201201
{
202202
KIRQL OldIrql = KeGetCurrentIrql(), LockIrql;
203-
PMMPTE PointerPde, PointerPte;
203+
PMMPTE PointerPte;
204+
PMMPDE PointerPde;
204205
MMPTE TempPte;
205206
PETHREAD CurrentThread;
206207
NTSTATUS Status;

0 commit comments

Comments
 (0)