xref: /DragonOS/kernel/src/arch/x86_64/mm/mod.rs (revision 9358ff0f6f7daa18d6fab4497de025736b3d6725)
1 pub mod barrier;
2 use crate::include::bindings::bindings::process_control_block;
3 
4 use core::arch::asm;
5 use core::ptr::read_volatile;
6 
7 use self::barrier::mfence;
8 
9 /// @brief 切换进程的页表
10 ///
11 /// @param 下一个进程的pcb。将会把它的页表切换进来。
12 ///
13 /// @return 下一个进程的pcb(把它return的目的主要是为了归还所有权)
14 #[inline(always)]
15 #[allow(dead_code)]
16 pub fn switch_mm(
17     next_pcb: &'static mut process_control_block,
18 ) -> &'static mut process_control_block {
19     mfence();
20     // kdebug!("to get pml4t");
21     let pml4t = unsafe { read_volatile(&next_pcb.mm.as_ref().unwrap().pgd) };
22 
23     unsafe {
24         asm!("mov cr3, {}", in(reg) pml4t);
25     }
26     mfence();
27     return next_pcb;
28 }
29