Fully working x86 paging support!
[reactos.git] / reactos / boot / environ / lib / arch / i386 / arch.c
index 1a5778a..de5c0e2 100644 (file)
@@ -171,7 +171,10 @@ BlpArchSwitchContext (
 
     /* In real mode, use EFI, otherwise, use the application mode */
     Context = &FirmwareExecutionContext;
-    if (NewMode != BlProtectedMode) Context = &ApplicationExecutionContext;
+    if (NewMode != BlRealMode)
+    {
+        Context = &ApplicationExecutionContext;
+    }
 
     /* Are we in a different mode? */
     if (CurrentExecutionContext->Mode != NewMode)
@@ -182,6 +185,40 @@ BlpArchSwitchContext (
     }
 }
 
+VOID
+BlpArchEnableTranslation (
+    VOID
+    )
+{
+    PBL_ARCH_CONTEXT Context;
+
+    /* Does the current execution context already have paging enabled? */
+    Context = CurrentExecutionContext;
+    if (!(Context->ContextFlags & BL_CONTEXT_PAGING_ON))
+    {
+        /* No -- does it have interrupts enabled? */
+        if (Context->ContextFlags & BL_CONTEXT_INTERRUPTS_ON)
+        {
+            /* Disable them */
+            _disable();
+            Context->ContextFlags &= ~BL_CONTEXT_INTERRUPTS_ON;
+        }
+
+        /* Are we enabling PAE? */
+        if (Context->TranslationType == BlPae)
+        {
+            /* Make sure CR4 reflects this */
+            __writecr4(__readcr4() | CR4_PAE);
+        }
+
+        /* Enable paging in the CPU */
+        __writecr0(__readcr0() | CR0_PG);
+
+        /* Reflect that paging is enabled */
+        Context->ContextFlags |= BL_CONTEXT_PAGING_ON;
+    }
+}
+
 /*++
 * @name BlpArchInitialize
 *