From 705fb217fddf62ce7914ba26db08feb23fc19cd0 Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Sat, 15 Jun 2024 17:47:37 +0800 Subject: [PATCH] feat: root: create_objects done --- kernel/src/root.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/kernel/src/root.rs b/kernel/src/root.rs index abef2e7..9e36926 100644 --- a/kernel/src/root.rs +++ b/kernel/src/root.rs @@ -1,15 +1,14 @@ -use crate::arch::layout::{mmap_phys_to_virt, mmap_virt_to_phys, PAGE_SIZE}; -use crate::arch::vspace::{copy_kernel_pagetable, RAM_ALLOCATOR}; +use crate::arch::layout::{mmap_phys_to_virt, mmap_virt_to_phys, PAGE_BITS, PAGE_SIZE}; +use crate::arch::vspace::{copy_kernel_pagetable, map_range, RAM_ALLOCATOR}; use crate::objects::*; use crate::vspace::*; -use core::ops::Range; -use elf::{abi::PT_LOAD, endian::AnyEndian, ElfBytes}; +use core::{cmp::min, ops::Range}; +use elf::{abi::*, endian::AnyEndian, ElfBytes}; use fdt::Fdt; use log::{debug, trace}; use spin::Lazy; -use uapi::cspace::CNodeSlot; -use uapi::error::SysError; -use utils::addr::*; +use uapi::{cspace::CNodeSlot, error::SysError}; +use utils::{addr::*, bin::prev_power_of_two}; const ROOT_CNODE_SIZE: usize = 128; static mut ROOT_CNODE: Lazy<[CapEntry; ROOT_CNODE_SIZE]> = @@ -35,10 +34,10 @@ pub fn setup_root_server(fdt: &Fdt) { let memory_idx = create_untyped_memory(cnode_obj); // 3. insert device memory [memory_idx, device_idx) - let device_idx = create_untyped_device(cnode_obj, fdt, memory_idx); + let device_idx = create_untyped_device(cnode_obj, memory_idx, fdt); // 4. create objects - let free_idx = create_objects(cnode_obj, device_idx); + create_objects(cnode_obj, device_idx); // 5. load root server @@ -104,7 +103,7 @@ fn create_untyped_memory(cnode_obj: &mut CNodeObject) -> usize { memory_idx } -fn create_untyped_device(cnode_obj: &mut CNodeObject, fdt: &Fdt, memory_idx: usize) -> usize { +fn create_untyped_device(cnode_obj: &mut CNodeObject, memory_idx: usize, fdt: &Fdt) -> usize { let mut device_idx = memory_idx; let memory = fdt.memory(); @@ -150,8 +149,7 @@ fn create_untyped_device(cnode_obj: &mut CNodeObject, fdt: &Fdt, memory_idx: usi device_idx } -fn create_objects(cnode_obj: &mut CNodeObject, end_idx: usize) -> usize { - fn alloc( +fn alloc_objects( cnode_obj: &mut CNodeObject, end_idx: usize, user_obj_bits: usize, @@ -188,8 +186,7 @@ fn create_objects(cnode_obj: &mut CNodeObject, end_idx: usize) -> usize { panic!("init: untyped memory is exhausted"); } - let free_idx = end_idx; - +fn create_objects(cnode_obj: &mut CNodeObject, end_idx: usize) { // tcb { let tcb_idx = CNodeSlot::TcbCap as usize; @@ -209,7 +206,12 @@ fn create_objects(cnode_obj: &mut CNodeObject, end_idx: usize) -> usize { copy_kernel_pagetable(root); } - // bootinfo? - - free_idx + // bootinfo + { + let bootinfo_idx = CNodeSlot::BootInfoFrameCap as usize; + trace!("[root] allocating bootinfo object at slot #{}", bootinfo_idx); + alloc_objects::(cnode_obj, end_idx, PAGE_BITS, bootinfo_idx..bootinfo_idx + 1); + } +} + }