]> git.corax.cc Git - corax/commitdiff
kernel/arch: Add functions for enabling and disabling paging
authorMatthias Kruk <m@m10k.eu>
Wed, 30 Dec 2020 02:16:03 +0000 (11:16 +0900)
committerMatthias Kruk <m@m10k.eu>
Wed, 30 Dec 2020 02:16:03 +0000 (11:16 +0900)
The new paging implementation needs to access paging structures in
physical memory, making it necessary to temporarily disable paging.
This commit adds the necessary functions to explicitly disable and
enable paging on a processor.

kernel/arch/cpu32.S
kernel/include/arch.h

index 63eb5a35a66f8800e1070af3a94273340a56aab3..99a5fea2aac9bfa329419f81ad1831c6e0ce805d 100644 (file)
@@ -33,7 +33,6 @@ boot_id:
 */
 
 .global cpu_get_id
-
 cpu_get_id:
        movl    $APIC_ID_ADDR, %esi
        movl    (%esi), %eax
@@ -41,7 +40,6 @@ cpu_get_id:
        ret
 
 .global cpu_get_capabilities
-
 cpu_get_capabilities:
        pushl   %ebx
        movl    $1, %eax
@@ -58,7 +56,6 @@ cpu_timestamp:
        ret
 
 .global cpu_set_pstate
-
 cpu_set_pstate:
        pushl   %ebx
        movl    $0x199, %ecx
@@ -69,3 +66,23 @@ cpu_set_pstate:
        wrmsr
        popl    %ebx
        ret
+
+.global cpu_paging_disable
+cpu_paging_disable:
+        movl    %cr0, %eax
+        movl    %eax, %ecx
+        andl    $0x7fffffff, %eax
+        movl    %eax, %cr0
+        movl    %ecx, %eax
+        shr     $31, %eax
+        ret
+
+.global cpu_paging_enable
+cpu_paging_enable:
+        movl    %cr0, %eax
+        movl    %eax, %ecx
+        orl     $0x80000000, %eax
+        movl    %eax, %cr0
+        movl    %ecx, %eax
+        shr     $31, %eax
+        ret
index a13ffc1e7152443b09bfd6d78791601d1a7e74ec..4407f95770f59c35ae4348c5cd9b98b0eb857a23 100644 (file)
@@ -222,6 +222,9 @@ u64_t   cpu_timestamp(void);
 
 u32_t   cpu_set_pstate(int pstate);
 
+int     cpu_paging_enable(void);
+int     cpu_paging_disable(void);
+
 int     task_prepare(struct task*, u32_t cr3, u32_t eip, u32_t esp0, u32_t esp, u32_t priv);
 int     task_prepare_fork(struct task*);
 int     task_switch(struct task*);