[FAST486]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Fri, 7 Nov 2014 00:00:17 +0000 (00:00 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Fri, 7 Nov 2014 00:00:17 +0000 (00:00 +0000)
Store the faulting address in CR2 (PFLA) when a page fault occurs.

svn path=/trunk/; revision=65304

reactos/lib/fast486/common.inl

index 73bb537..084bf1e 100644 (file)
@@ -170,8 +170,18 @@ Fast486ReadLinearMemory(PFAST486_STATE State,
             /* Get the table entry */
             TableEntry.Value = Fast486GetPageTableEntry(State, Page, FALSE);
 
+            /* Check if this is the first page */
+            if (Page == PAGE_ALIGN(LinearAddress))
+            {
+                /* Start reading from the offset from the beginning of the page */
+                PageOffset = PAGE_OFFSET(LinearAddress);
+                PageLength -= PageOffset;
+            }
+
             if (!TableEntry.Present || (!TableEntry.Usermode && (Cpl > 0)))
             {
+                State->ControlRegisters[FAST486_REG_CR2] = Page + PageOffset;
+
                 /* Exception */
                 Fast486ExceptionWithErrorCode(State,
                                               FAST486_EXCEPTION_PF,
@@ -179,14 +189,6 @@ Fast486ReadLinearMemory(PFAST486_STATE State,
                 return FALSE;
             }
 
-            /* Check if this is the first page */
-            if (Page == PAGE_ALIGN(LinearAddress))
-            {
-                /* Start reading from the offset from the beginning of the page */
-                PageOffset = PAGE_OFFSET(LinearAddress);
-                PageLength -= PageOffset;
-            }
-
             /* Check if this is the last page */
             if (Page == PAGE_ALIGN(LinearAddress + Size - 1))
             {
@@ -237,10 +239,20 @@ Fast486WriteLinearMemory(PFAST486_STATE State,
             /* Get the table entry */
             TableEntry.Value = Fast486GetPageTableEntry(State, Page, TRUE);
 
+            /* Check if this is the first page */
+            if (Page == PAGE_ALIGN(LinearAddress))
+            {
+                /* Start writing from the offset from the beginning of the page */
+                PageOffset = PAGE_OFFSET(LinearAddress);
+                PageLength -= PageOffset;
+            }
+
             if ((!TableEntry.Present || (!TableEntry.Usermode && (Cpl > 0)))
                 || ((State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_WP)
                 && !TableEntry.Writeable))
             {
+                State->ControlRegisters[FAST486_REG_CR2] = Page + PageOffset;
+
                 /* Exception */
                 Fast486ExceptionWithErrorCode(State,
                                               FAST486_EXCEPTION_PF,
@@ -248,14 +260,6 @@ Fast486WriteLinearMemory(PFAST486_STATE State,
                 return FALSE;
             }
 
-            /* Check if this is the first page */
-            if (Page == PAGE_ALIGN(LinearAddress))
-            {
-                /* Start writing from the offset from the beginning of the page */
-                PageOffset = PAGE_OFFSET(LinearAddress);
-                PageLength -= PageOffset;
-            }
-
             /* Check if this is the last page */
             if (Page == PAGE_ALIGN(LinearAddress + Size - 1))
             {