1 use crate::mm::{ 2 allocator::page_frame::{FrameAllocator, PageFrameCount, PageFrameUsage}, 3 page::PageFlags, 4 MemoryManagementArch, PhysAddr, VirtAddr, 5 }; 6 7 pub mod bump; 8 pub(super) mod init; 9 10 pub type PageMapper = crate::mm::page::PageMapper<RiscV64MMArch, LockedFrameAllocator>; 11 12 /// RiscV64的内存管理架构结构体 13 #[derive(Debug, Clone, Copy, Hash)] 14 pub struct RiscV64MMArch; 15 16 impl MemoryManagementArch for RiscV64MMArch { 17 const PAGE_SHIFT: usize = 12; 18 19 const PAGE_ENTRY_SHIFT: usize = 9; 20 21 /// sv39分页只有三级 22 const PAGE_LEVELS: usize = 3; 23 24 const ENTRY_ADDRESS_SHIFT: usize = 39; 25 26 const ENTRY_FLAG_DEFAULT_PAGE: usize = Self::ENTRY_FLAG_PRESENT; 27 28 const ENTRY_FLAG_DEFAULT_TABLE: usize = Self::ENTRY_FLAG_PRESENT; 29 30 const ENTRY_FLAG_PRESENT: usize = 1 << 0; 31 32 const ENTRY_FLAG_READONLY: usize = 1 << 1; 33 34 const ENTRY_FLAG_READWRITE: usize = (1 << 2) | (1 << 1); 35 36 const ENTRY_FLAG_USER: usize = (1 << 4); 37 38 const ENTRY_FLAG_WRITE_THROUGH: usize = (2 << 61); 39 40 const ENTRY_FLAG_CACHE_DISABLE: usize = (2 << 61); 41 42 const ENTRY_FLAG_NO_EXEC: usize = 0; 43 44 const ENTRY_FLAG_EXEC: usize = (1 << 3); 45 46 const PHYS_OFFSET: usize = 0xffff_ffc0_0000_0000; 47 48 const USER_END_VADDR: crate::mm::VirtAddr = VirtAddr::new(0x0000_003f_ffff_ffff); 49 50 const USER_BRK_START: crate::mm::VirtAddr = VirtAddr::new(0x0000_001f_ffff_ffff); 51 52 const USER_STACK_START: crate::mm::VirtAddr = VirtAddr::new(0x0000_001f_ffa0_0000); 53 54 unsafe fn init() -> &'static [crate::mm::PhysMemoryArea] { 55 todo!() 56 } 57 58 unsafe fn invalidate_page(address: crate::mm::VirtAddr) { 59 todo!() 60 } 61 62 unsafe fn invalidate_all() { 63 todo!() 64 } 65 66 unsafe fn table(table_kind: crate::mm::PageTableKind) -> crate::mm::PhysAddr { 67 todo!() 68 } 69 70 unsafe fn set_table(table_kind: crate::mm::PageTableKind, table: crate::mm::PhysAddr) { 71 todo!() 72 } 73 74 fn virt_is_valid(virt: crate::mm::VirtAddr) -> bool { 75 todo!() 76 } 77 78 fn initial_page_table() -> crate::mm::PhysAddr { 79 todo!() 80 } 81 82 fn setup_new_usermapper() -> Result<crate::mm::ucontext::UserMapper, crate::syscall::SystemError> 83 { 84 todo!() 85 } 86 } 87 88 /// 获取内核地址默认的页面标志 89 pub unsafe fn kernel_page_flags<A: MemoryManagementArch>(virt: VirtAddr) -> PageFlags<A> { 90 unimplemented!("riscv64::kernel_page_flags") 91 } 92 93 /// 全局的页帧分配器 94 #[derive(Debug, Clone, Copy, Hash)] 95 pub struct LockedFrameAllocator; 96 97 impl FrameAllocator for LockedFrameAllocator { 98 unsafe fn allocate(&mut self, count: PageFrameCount) -> Option<(PhysAddr, PageFrameCount)> { 99 unimplemented!("RiscV64 LockedFrameAllocator::allocate") 100 } 101 102 unsafe fn free(&mut self, address: crate::mm::PhysAddr, count: PageFrameCount) { 103 assert!(count.data().is_power_of_two()); 104 unimplemented!("RiscV64 LockedFrameAllocator::free") 105 } 106 107 unsafe fn usage(&self) -> PageFrameUsage { 108 unimplemented!("RiscV64 LockedFrameAllocator::usage") 109 } 110 } 111