[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] kernel2: Code readonly mappen



* kernel2: Code readonly mappen

Signed-off-by: Antoine Kaufmann <toni@xxxxxxxxxx>
---
 src/kernel2/include/mm.h            |    3 +++
 src/kernel2/src/arch/i386/kernel.ld |    4 ++++
 src/kernel2/src/arch/i386/mm/virt.c |   15 ++++++++++-----
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/kernel2/include/mm.h b/src/kernel2/include/mm.h
index 9ab51f0..ffb68b1 100644
--- a/src/kernel2/include/mm.h
+++ b/src/kernel2/include/mm.h
@@ -51,6 +51,9 @@ extern void kernel_phys_end(void);
 extern void kernel_start(void);
 extern void kernel_end(void);
 
+/* Start des bereichs des Kernels der beschreibbar sein muss */
+extern void kernel_rw_start(void);
+
 
 void pmm_init(struct multiboot_info* multiboot_info);
 
diff --git a/src/kernel2/src/arch/i386/kernel.ld b/src/kernel2/src/arch/i386/kernel.ld
index 0cb7936..6921bcf 100644
--- a/src/kernel2/src/arch/i386/kernel.ld
+++ b/src/kernel2/src/arch/i386/kernel.ld
@@ -20,6 +20,10 @@ SECTIONS
 	}
 	.data ALIGN(4096) : AT(ADDR(.data) - VIRT_TO_PHYS)
 	{
+		/* Um klar zwischen Bereichen unterscheiden zu koennen, die
+		   schreibbar sein muessen, und nur lesbaren, wird davon
+		   ausgegangen, dass alle vor diesem Label nur lesbar sind. */
+		kernel_rw_start = .;
 		*(.data)
 	}
 	.bss ALIGN(4096) : AT(ADDR(.bss) - VIRT_TO_PHYS)
diff --git a/src/kernel2/src/arch/i386/mm/virt.c b/src/kernel2/src/arch/i386/mm/virt.c
index d057523..9b0b4ea 100644
--- a/src/kernel2/src/arch/i386/mm/virt.c
+++ b/src/kernel2/src/arch/i386/mm/virt.c
@@ -51,12 +51,17 @@ extern page_directory_t page_directory_current;
  * Die physische Speicherverwaltung muss dazu bereits initialisiert sein.
  */
 void vmm_init(mmc_context_t* kernel_context)
-{ 
+{
+    size_t rosize = kernel_rw_start - kernel_start;
+    size_t rwsize = kernel_end - kernel_rw_start;
+
     // TODO: 4M-Pages benutzen, wenn in config.h aktiviert
     // Den Kernel mappen
-    mmc_map(kernel_context, kernel_start, kernel_phys_start, PTE_W | PTE_P, 
-        NUM_PAGES((uintptr_t) kernel_end - (uintptr_t) kernel_start));
-    
+    mmc_map(kernel_context, kernel_start, kernel_phys_start, PTE_P,
+        NUM_PAGES(rosize));
+    mmc_map(kernel_context, kernel_start + rosize,
+        kernel_phys_start + rosize, PTE_P | PTE_W, NUM_PAGES(rwsize));
+
     // Videospeicher mappen
     // TODO Usermodus muss die momentan wegen VM86 sehen. Waere wohl besser,
     // wenn VM86 einen eigenen Adressraum haette.
@@ -110,7 +115,7 @@ void vmm_init_local(mmc_context_t* kernel_context)
         "mov %0, %%cr3\n\t"
         // Paging aktivieren
         "mov %%cr0, %%eax\n\t"
-        "or $0x80000000, %%eax\n\t"
+        "or $0x80010000, %%eax\n\t"
         "mov %%eax, %%cr0\n\t"
     : : "r" (kernel_context->page_directory) : "eax");
 }
-- 
1.6.4.4