Allocate pages
(address: u64, size: u64)
| 71 | |
| 72 | // Allocate pages |
| 73 | pub fn palloc(address: u64, size: u64) |
| 74 | { |
| 75 | let mut mapper = unsafe |
| 76 | { |
| 77 | crate::mem::mapper(VirtAddr::new(crate::mem::PMEM_OFFSET)) |
| 78 | }; |
| 79 | |
| 80 | let mut framealloc = unsafe |
| 81 | { |
| 82 | crate::mem::BootInfoFrameAllocator::init(crate::mem::MEMMAP.unwrap()) |
| 83 | }; |
| 84 | |
| 85 | let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE; |
| 86 | |
| 87 | let pages = |
| 88 | { |
| 89 | let spage = Page::containing_address(VirtAddr::new(address)); |
| 90 | let epage = Page::containing_address(VirtAddr::new(address + size)); |
| 91 | Page::range_inclusive(spage, epage) |
| 92 | }; |
| 93 | |
| 94 | for page in pages |
| 95 | { |
| 96 | let frame = framealloc.allocate_frame().unwrap(); |
| 97 | |
| 98 | unsafe |
| 99 | { |
| 100 | if let Ok(mapping) = mapper.map_to(page, frame, flags, &mut framealloc) |
| 101 | { |
| 102 | mapping.flush(); |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | print!("[ERR] UNABLE TO MAP {:?}", page); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | |
| 113 | // Deallocate pages |
no test coverage detected