From bf84aedad9eb5211fd9f2b3b9d9cbcd369c2b738 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Wed, 30 Dec 2020 11:16:03 +0900 Subject: [PATCH] kernel/arch: Add functions for enabling and disabling paging 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 | 23 ++++++++++++++++++++--- kernel/include/arch.h | 3 +++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/arch/cpu32.S b/kernel/arch/cpu32.S index 63eb5a3..99a5fea 100644 --- a/kernel/arch/cpu32.S +++ b/kernel/arch/cpu32.S @@ -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 diff --git a/kernel/include/arch.h b/kernel/include/arch.h index a13ffc1..4407f95 100644 --- a/kernel/include/arch.h +++ b/kernel/include/arch.h @@ -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*); -- 2.47.3