feat: root: create_objects done

This commit is contained in:
Paul Pan 2024-06-15 17:47:37 +08:00
parent fe30d8d28c
commit 705fb217fd

View File

@ -1,15 +1,14 @@
use crate::arch::layout::{mmap_phys_to_virt, mmap_virt_to_phys, PAGE_SIZE}; use crate::arch::layout::{mmap_phys_to_virt, mmap_virt_to_phys, PAGE_BITS, PAGE_SIZE};
use crate::arch::vspace::{copy_kernel_pagetable, RAM_ALLOCATOR}; use crate::arch::vspace::{copy_kernel_pagetable, map_range, RAM_ALLOCATOR};
use crate::objects::*; use crate::objects::*;
use crate::vspace::*; use crate::vspace::*;
use core::ops::Range; use core::{cmp::min, ops::Range};
use elf::{abi::PT_LOAD, endian::AnyEndian, ElfBytes}; use elf::{abi::*, endian::AnyEndian, ElfBytes};
use fdt::Fdt; use fdt::Fdt;
use log::{debug, trace}; use log::{debug, trace};
use spin::Lazy; use spin::Lazy;
use uapi::cspace::CNodeSlot; use uapi::{cspace::CNodeSlot, error::SysError};
use uapi::error::SysError; use utils::{addr::*, bin::prev_power_of_two};
use utils::addr::*;
const ROOT_CNODE_SIZE: usize = 128; const ROOT_CNODE_SIZE: usize = 128;
static mut ROOT_CNODE: Lazy<[CapEntry; ROOT_CNODE_SIZE]> = 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); let memory_idx = create_untyped_memory(cnode_obj);
// 3. insert device memory [memory_idx, device_idx) // 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 // 4. create objects
let free_idx = create_objects(cnode_obj, device_idx); create_objects(cnode_obj, device_idx);
// 5. load root server // 5. load root server
@ -104,7 +103,7 @@ fn create_untyped_memory(cnode_obj: &mut CNodeObject) -> usize {
memory_idx 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 mut device_idx = memory_idx;
let memory = fdt.memory(); let memory = fdt.memory();
@ -150,8 +149,7 @@ fn create_untyped_device(cnode_obj: &mut CNodeObject, fdt: &Fdt, memory_idx: usi
device_idx device_idx
} }
fn create_objects(cnode_obj: &mut CNodeObject, end_idx: usize) -> usize { fn alloc_objects<T: KernelObject + ?Sized>(
fn alloc<T: KernelObject + ?Sized>(
cnode_obj: &mut CNodeObject, cnode_obj: &mut CNodeObject,
end_idx: usize, end_idx: usize,
user_obj_bits: 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"); panic!("init: untyped memory is exhausted");
} }
let free_idx = end_idx; fn create_objects(cnode_obj: &mut CNodeObject, end_idx: usize) {
// tcb // tcb
{ {
let tcb_idx = CNodeSlot::TcbCap as usize; 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); copy_kernel_pagetable(root);
} }
// bootinfo? // bootinfo
{
free_idx let bootinfo_idx = CNodeSlot::BootInfoFrameCap as usize;
trace!("[root] allocating bootinfo object at slot #{}", bootinfo_idx);
alloc_objects::<FrameObject>(cnode_obj, end_idx, PAGE_BITS, bootinfo_idx..bootinfo_idx + 1);
}
}
} }