Selaa lähdekoodia

Flush the TLB after modifying page tables.

This is a very inefficient naive implementation, but it gets us going.
Mapping tasks in and out of a shared address space now totally works.
Andreas Kling 6 vuotta sitten
vanhempi
commit
98f76f0153
3 muutettua tiedostoa jossa 11 lisäystä ja 2 poistoa
  1. 10 0
      Kernel/MemoryManager.cpp
  2. 1 0
      Kernel/MemoryManager.h
  3. 0 2
      Kernel/init.cpp

+ 10 - 0
Kernel/MemoryManager.cpp

@@ -156,6 +156,14 @@ byte* MemoryManager::quickMapOnePage(PhysicalAddress physicalAddress)
     return (byte*)(4 * MB);
 }
 
+void MemoryManager::flushTLB()
+{
+    asm volatile(
+        "mov %cr3, %eax\n"
+        "mov %eax, %cr3\n"
+    );
+}
+
 bool MemoryManager::unmapRegion(Task& task, Task::Region& region)
 {
     auto& zone = *region.zone;
@@ -169,6 +177,7 @@ bool MemoryManager::unmapRegion(Task& task, Task::Region& region)
 
 //        kprintf("MM: >> Unmapped L%x => P%x <<\n", laddr, zone.m_pages[i].get());
     }
+    flushTLB();
     return true;
 }
 
@@ -194,6 +203,7 @@ bool MemoryManager::mapRegion(Task& task, Task::Region& region)
 
         //kprintf("MM: >> Mapped L%x => P%x <<\n", laddr, zone.m_pages[i].get());
     }
+    flushTLB();
     return true;
 }
 

+ 1 - 0
Kernel/MemoryManager.h

@@ -60,6 +60,7 @@ private:
     ~MemoryManager();
 
     void initializePaging();
+    void flushTLB();
 
     void protectMap(LinearAddress, size_t length);
     void identityMap(LinearAddress, size_t length);

+ 0 - 2
Kernel/init.cpp

@@ -168,8 +168,6 @@ static void init_stage2()
     }
 #endif
 
-    //auto* idTask = Task::create("/bin/id", (uid_t)209, (gid_t)1985);
-
     auto* shTask = Task::create("/bin/sh", (uid_t)100, (gid_t)100);
 
     //new Task(motd_main, "motd", IPC::Handle::MotdTask, Task::Ring0);