]> Zhao Yanbai Git Server - minix.git/commitdiff
set global flag for kernel pages, so tlb entries for kernel aren't thrown
authorBen Gras <ben@minix3.org>
Thu, 23 Apr 2009 15:11:16 +0000 (15:11 +0000)
committerBen Gras <ben@minix3.org>
Thu, 23 Apr 2009 15:11:16 +0000 (15:11 +0000)
away on cr3 reload. minor optimization.

kernel/arch/i386/klib386.s
kernel/arch/i386/memory.c
kernel/arch/i386/proto.h
servers/vm/i386/pagetable.c
servers/vm/i386/pagetable.h

index e91bba094108f5dddf4052ea7413d5dfa442ae49..0aff6c0bd8a353c2b447b8b435684a6b2e2f46a6 100755 (executable)
@@ -38,6 +38,8 @@
 .define        _write_cr3      ! write cr3
 .define _last_cr3
 .define        _write_cr0      ! write a value in cr0
+.define        _read_cr4
+.define        _write_cr4
 
 .define        _kernel_cr3     
 
@@ -606,6 +608,31 @@ _write_cr0:
        pop     ebp
        ret
 
+!*===========================================================================*
+!*                           read_cr4                                       *
+!*===========================================================================*
+! PUBLIC unsigned long read_cr4(void);
+_read_cr4:
+       push    ebp
+       mov     ebp, esp
+.data1 0x0f, 0x20, 0xe0 ! mov eax, cr4
+       pop     ebp
+       ret
+
+!*===========================================================================*
+!*                           write_cr4                                      *
+!*===========================================================================*
+! PUBLIC void write_cr4(unsigned long value);
+_write_cr4:
+       push    ebp
+       mov     ebp, esp
+       mov     eax, 8(ebp)
+.data1 0x0f, 0x22, 0xe0 ! mov cr4, eax
+       jmp     0f
+0:
+       pop     ebp
+       ret
+
 !*===========================================================================*
 !*                             write_cr3                               *
 !*===========================================================================*
index 16c6cb2943bc4607fd59c307bea2c689dc19bc07..7e8456b847ebe40830eb10ab0dd21aa6f8406666 100644 (file)
@@ -149,10 +149,28 @@ PRIVATE void set_cr3()
 
 PRIVATE void vm_enable_paging(void)
 {
-       u32_t cr0;
+       u32_t cr0, cr4;
+
+
+       cr0= read_cr0();
+       cr4= read_cr4();
+
+       /* First clear PG and PGE flag, as PGE must be enabled after PG. */
+       write_cr0(cr0 & ~I386_CR0_PG);
+       write_cr4(cr4 & ~I386_CR4_PGE);
 
        cr0= read_cr0();
+       cr4= read_cr4();
+
+       /* First enable paging, then enable global page flag. */
        write_cr0(cr0 | I386_CR0_PG);
+       write_cr4(cr4 | I386_CR4_PGE);
+
+{
+       u32_t cr4v;
+       cr4v = read_cr4();
+       kprintf("cr4 = 0x%lx\n", cr4v);
+}
 }
 
 PUBLIC vir_bytes alloc_remote_segment(u32_t *selector,
index de8de011ebb8f880bbca93fefef93d18067ff304..b6ae9b27ad525ef11e148bbdf8cd448abb0ae808 100644 (file)
@@ -62,6 +62,8 @@ _PROTOTYPE( void reset, (void)                                          );
 _PROTOTYPE( void int86, (void)                                         );
 _PROTOTYPE( unsigned long read_cr0, (void)                              );
 _PROTOTYPE( void write_cr0, (unsigned long value)                       );
+_PROTOTYPE( unsigned long read_cr4, (void)                              );
+_PROTOTYPE( void write_cr4, (unsigned long value)                       );
 _PROTOTYPE( void write_cr3, (unsigned long value)                       );
 _PROTOTYPE( unsigned long read_cpu_flags, (void)                        );
 _PROTOTYPE( void phys_insb, (U16_t port, phys_bytes buf, size_t count)  );
index 5c421f4719fca281b49014f90ecc3041156a135e..a9ad925be5eed3a9531c0ad592db6e9d1c2f35df 100644 (file)
@@ -785,12 +785,12 @@ PUBLIC int pt_mapkernel(pt_t *pt)
 
         /* Map in text. flags: don't write, supervisor only */
         if((r=pt_writemap(pt, KERNEL_TEXT, KERNEL_TEXT, KERNEL_TEXT_LEN,
-               I386_VM_PRESENT, 0)) != OK)
+               I386_VM_PRESENT|I386_VM_GLOBAL, 0)) != OK)
                return r;
  
         /* Map in data. flags: read-write, supervisor only */
         if((r=pt_writemap(pt, KERNEL_DATA, KERNEL_DATA, KERNEL_DATA_LEN,
-               I386_VM_PRESENT|I386_VM_WRITE, 0)) != OK)
+               I386_VM_PRESENT|I386_VM_WRITE|I386_VM_GLOBAL, 0)) != OK)
                return r;
 
        return OK;
index e4934c72e3a9a46ecaa3fc4a2d7e5f8d7945eb09..b26ac9cd360f7fc4045eafbf9210ac5986cf699d 100644 (file)
@@ -26,12 +26,13 @@ typedef struct {
 #define PTF_WRITE      I386_VM_WRITE
 #define PTF_PRESENT    I386_VM_PRESENT
 #define PTF_USER       I386_VM_USER
+#define PTF_GLOBAL     I386_VM_GLOBAL
 #define PTF_MAPALLOC   I386_VM_PTAVAIL1 /* Page allocated by pt code. */
 
 /* For arch-specific PT routines to check if no bits outside
  * the regular flags are set.
  */
-#define PTF_ALLFLAGS   (PTF_WRITE|PTF_PRESENT|PTF_USER)
+#define PTF_ALLFLAGS   (PTF_WRITE|PTF_PRESENT|PTF_USER|PTF_GLOBAL)
 
 #endif