kernel/mm/vmm/
boot_mapping.rs1use crate::lib::addr::{PhysAddr, VirtAddr};
8use crate::lib::types::boot_info::KernelSectionInfo;
9use crate::mm::layout;
10use crate::mm::vmm::vma::VmaFlags;
11
12pub struct BootMapping {
15 pub virt: VirtAddr,
16 pub phys: PhysAddr,
17 pub size: u64,
18 pub flags: VmaFlags,
19 pub can_overmap: bool
20}
21
22pub type BootMappings = [BootMapping; 4];
24
25pub fn build_boot_mappings(sections: &KernelSectionInfo, total_mem: u64) -> BootMappings {
26 let image_offset = sections.kernel_phys_start.wrapping_sub(layout::KERNEL_IMAGE_BASE.as_u64());
27
28 [
29 BootMapping {
31 virt: layout::KERNEL_HHDM_BASE,
32 phys: PhysAddr::new(0),
33 size: total_mem,
34 flags: VmaFlags::READ | VmaFlags::WRITE,
35 can_overmap: true
36 },
37 BootMapping {
39 virt: VirtAddr::new(sections.kernel_start),
40 phys: PhysAddr::new(sections.kernel_start.wrapping_add(image_offset)),
41 size: sections.kernel_text_end - sections.kernel_start,
42 flags: VmaFlags::READ | VmaFlags::EXEC,
43 can_overmap: false
44 },
45 BootMapping {
47 virt: VirtAddr::new(sections.kernel_text_end),
48 phys: PhysAddr::new(sections.kernel_text_end.wrapping_add(image_offset)),
49 size: sections.kernel_rodata_end - sections.kernel_text_end,
50 flags: VmaFlags::READ,
51 can_overmap: false
52 },
53 BootMapping {
55 virt: VirtAddr::new(sections.kernel_rodata_end),
56 phys: PhysAddr::new(sections.kernel_rodata_end.wrapping_add(image_offset)),
57 size: sections.kernel_end - sections.kernel_rodata_end,
58 flags: VmaFlags::READ | VmaFlags::WRITE,
59 can_overmap: false
60 }
61 ]
62}