[ros-diffs] [fireball] 32629: - Move some PTE/PDE macros from i386/page.c into arch-specific mm.h. Also change some macros operation from integer division to bit shifting. - Remove unused/#if0-ed stuff from mm.h.

fireball at svn.reactos.org fireball at svn.reactos.org
Sun Mar 9 21:30:29 CET 2008


Author: fireball
Date: Sun Mar  9 15:30:28 2008
New Revision: 32629

URL: http://svn.reactos.org/svn/reactos?rev=3D32629&view=3Drev
Log:
- Move some PTE/PDE macros from i386/page.c into arch-specific mm.h. Also c=
hange some macros operation from integer division to bit shifting.
- Remove unused/#if0-ed stuff from mm.h.

Modified:
    trunk/reactos/ntoskrnl/include/internal/i386/mm.h
    trunk/reactos/ntoskrnl/mm/i386/page.c

Modified: trunk/reactos/ntoskrnl/include/internal/i386/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/inte=
rnal/i386/mm.h?rev=3D32629&r1=3D32628&r2=3D32629&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/include/internal/i386/mm.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/i386/mm.h Sun Mar  9 15:30:28 2=
008
@@ -5,29 +5,27 @@
 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_MM_H
 #define __NTOSKRNL_INCLUDE_INTERNAL_I386_MM_H
 =

-#if 0
-/*
- * Page access attributes (or these together)
- */
-#define PA_READ            (1<<0)
-#define PA_WRITE           ((1<<0)+(1<<1))
-#define PA_EXECUTE         PA_READ
-#define PA_PCD             (1<<4)
-#define PA_PWT             (1<<3)
-
-/*
- * Page attributes
- */
-#define PA_USER            (1<<2)
-#define PA_SYSTEM          (0)
-#endif
-
 struct _EPROCESS;
 PULONG MmGetPageDirectory(VOID);
-
-
 =

 #define PAGE_MASK(x)		((x)&(~0xfff))
 #define PAE_PAGE_MASK(x)	((x)&(~0xfffLL))
 =

+/* Base addresses of PTE and PDE */
+#define PAGETABLE_MAP       (0xc0000000)
+#define PAGEDIRECTORY_MAP   (0xc0000000 + (PAGETABLE_MAP / (1024)))
+
+/* Converting address to a corresponding PDE or PTE entry */
+#define MiAddressToPde(x) \
+    ((PMMPTE)(((((ULONG)(x)) >> 22) << 2) + PAGEDIRECTORY_MAP))
+#define MiAddressToPte(x) \
+    ((PMMPTE)(((((ULONG)(x)) >> 12) << 2) + PAGETABLE_MAP))
+
+#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
+#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE)))
+#define ADDR_TO_PTE_OFFSET(v)  ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE=
_SIZE)
+
+/* Easy accessing PFN in PTE */
+#define PFN_FROM_PTE(v) ((v)->u.Hard.PageFrameNumber)
+
 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_MM_H */

Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page=
.c?rev=3D32629&r1=3D32628&r2=3D32629&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/mm/i386/page.c (original)
+++ trunk/reactos/ntoskrnl/mm/i386/page.c Sun Mar  9 15:30:28 2008
@@ -39,9 +39,6 @@
 #define PA_ACCESSED  (1 << PA_BIT_ACCESSED)
 #define PA_GLOBAL    (1 << PA_BIT_GLOBAL)
 =

-#define PAGETABLE_MAP		(0xc0000000)
-#define PAGEDIRECTORY_MAP	(0xc0000000 + (PAGETABLE_MAP / (1024)))
-
 #define HYPERSPACE		(0xc0400000)
 #define IS_HYPERSPACE(v)	(((ULONG)(v) >=3D HYPERSPACE && (ULONG)(v) < HYPE=
RSPACE + 0x400000))
 =

@@ -141,17 +138,6 @@
    }
    return(Attributes);
 }
-
-#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
-
-#define ADDR_TO_PDE(v) (PULONG)(PAGEDIRECTORY_MAP + \
-                                ((((ULONG)(v)) / (1024 * 1024))&(~0x3)))
-#define ADDR_TO_PTE(v) (PULONG)(PAGETABLE_MAP + ((((ULONG)(v) / 1024))&(~0=
x3)))
-
-#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE)))
-
-#define ADDR_TO_PTE_OFFSET(v)  ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE=
_SIZE)
-
 =

 NTSTATUS
 NTAPI
@@ -294,8 +280,9 @@
       KeAttachProcess(&Process->Pcb);
    }
 =

-      *(ADDR_TO_PDE(Address)) =3D 0;
-      MiFlushTlb(ADDR_TO_PDE(Address), ADDR_TO_PTE(Address));
+      MiAddressToPde(Address)->u.Long =3D 0;
+      MiFlushTlb((PULONG)MiAddressToPde(Address),
+          MiAddressToPte(Address));
 =

    if (Address >=3D MmSystemRangeStart)
    {
@@ -323,7 +310,7 @@
       KeAttachProcess(&Process->Pcb);
    }
 =

-      PageTable =3D (PULONG)PAGE_ROUND_DOWN((PVOID)ADDR_TO_PTE(Address));
+      PageTable =3D (PULONG)PAGE_ROUND_DOWN((PVOID)MiAddressToPte(Address)=
);
       for (i =3D 0; i < 1024; i++)
       {
          if (PageTable[i] !=3D 0)
@@ -333,9 +320,9 @@
             KEBUGCHECK(0);
          }
       }
-      Pfn =3D PTE_TO_PFN(*(ADDR_TO_PDE(Address)));
-      *(ADDR_TO_PDE(Address)) =3D 0;
-      MiFlushTlb(ADDR_TO_PDE(Address), ADDR_TO_PTE(Address));
+      Pfn =3D MiAddressToPde(Address)->u.Hard.PageFrameNumber;
+      MiAddressToPde(Address)->u.Long =3D 0;
+      MiFlushTlb((PULONG)MiAddressToPde(Address), MiAddressToPte(Address));
 =

    if (Address >=3D MmSystemRangeStart)
    {
@@ -399,7 +386,7 @@
       }
       return Pt + ADDR_TO_PTE_OFFSET(Address);
    }
-   PageDir =3D ADDR_TO_PDE(Address);
+   PageDir =3D (PULONG)MiAddressToPde(Address);
    if (0 =3D=3D InterlockedCompareExchangeUL(PageDir, 0, 0))
    {
       if (Address >=3D MmSystemRangeStart)
@@ -445,7 +432,7 @@
 	 }
       }
    }
-   return (PULONG)ADDR_TO_PTE(Address);
+   return (PULONG)MiAddressToPte(Address);
 }
 =

 BOOLEAN MmUnmapPageTable(PULONG Pt)
@@ -693,7 +680,7 @@
 Mmi386MakeKernelPageTableGlobal(PVOID PAddress)
 {
       PULONG Pt, Pde;
-      Pde =3D ADDR_TO_PDE(PAddress);
+      Pde =3D (PULONG)MiAddressToPde(PAddress);
       if (*Pde =3D=3D 0)
       {
          Pt =3D MmGetPageTableForProcess(NULL, PAddress, FALSE);
@@ -1274,7 +1261,7 @@
       ULONG Entry;
       PULONG Pte;
       Entry =3D PFN_TO_PTE(Page) | PA_PRESENT | PA_READWRITE;
-      Pte =3D ADDR_TO_PTE(HYPERSPACE) + Page % 1024;
+      Pte =3D (PULONG)MiAddressToPte(HYPERSPACE) + Page % 1024;
       if (Page & 1024)
       {
          for (i =3D Page % 1024; i < 1024; i++, Pte++)
@@ -1286,7 +1273,7 @@
          }
          if (i >=3D 1024)
          {
-            Pte =3D ADDR_TO_PTE(HYPERSPACE);
+            Pte =3D (PULONG)MiAddressToPte(HYPERSPACE);
             for (i =3D 0; i < Page % 1024; i++, Pte++)
             {
                if (0 =3D=3D InterlockedCompareExchange((PLONG)Pte, (LONG)E=
ntry, 0))
@@ -1311,7 +1298,7 @@
          }
          if ((LONG)i < 0)
          {
-            Pte =3D ADDR_TO_PTE(HYPERSPACE) + 1023;
+            Pte =3D (PULONG)MiAddressToPte(HYPERSPACE) + 1023;
             for (i =3D 1023; i > Page % 1024; i--, Pte--)
             {
                if (0 =3D=3D InterlockedCompareExchange((PLONG)Pte, (LONG)E=
ntry, 0))
@@ -1339,7 +1326,7 @@
 =

    ASSERT (IS_HYPERSPACE(Address));
 =

-      Entry =3D InterlockedExchange((PLONG)ADDR_TO_PTE(Address), PFN_TO_PT=
E(NewPage) | PA_PRESENT | PA_READWRITE);
+      Entry =3D InterlockedExchange((PLONG)MiAddressToPte(Address), PFN_TO=
_PTE(NewPage) | PA_PRESENT | PA_READWRITE);
       Pfn =3D PTE_TO_PFN(Entry);
 =

    __invlpg(Address);
@@ -1355,7 +1342,7 @@
 =

    ASSERT (IS_HYPERSPACE(Address));
 =

-      Entry =3D InterlockedExchange((PLONG)ADDR_TO_PTE(Address), 0);
+      Entry =3D InterlockedExchange((PLONG)MiAddressToPte(Address), 0);
       Pfn =3D PTE_TO_PFN(Entry);
 =

    __invlpg(Address);




More information about the Ros-diffs mailing list