diff --git a/crate/bit-allocator/src/lib.rs b/crate/bit-allocator/src/lib.rs index bc49dcb..02c38c2 100644 --- a/crate/bit-allocator/src/lib.rs +++ b/crate/bit-allocator/src/lib.rs @@ -6,6 +6,18 @@ extern crate bit_field; use bit_field::BitField; use core::ops::Range; +/// Allocator of a bitmap, able to allocate / free bits. +/// +/// CAP: the bitmap has a total of CAP bits, numbered from 0 to CAP-1 inclusively. +/// +/// alloc: allocate a free bit. +/// dealloc: free an allocated bit. +/// +/// insert: mark bits in the range as allocated +/// remove: reverse of insert +/// +/// any: whether there are free bits remaining +/// test: whether a specific bit is free pub trait BitAlloc: Default { const CAP: usize; fn alloc(&mut self) -> Option; @@ -23,6 +35,7 @@ pub type BitAlloc1M = BitAllocCascade16; pub type BitAlloc16M = BitAllocCascade16; pub type BitAlloc256M = BitAllocCascade16; +/// Implement the bit allocator by segment tree algorithm. #[derive(Default)] pub struct BitAllocCascade16 { bitset: u16, @@ -77,6 +90,8 @@ impl BitAllocCascade16 { #[derive(Default)] pub struct BitAlloc16(u16); +/// BitAlloc16 acts as the leaf (except the leaf bits of course) nodes +/// in the segment trees. impl BitAlloc for BitAlloc16 { const CAP: usize = 16; diff --git a/crate/process/src/scheduler.rs b/crate/process/src/scheduler.rs index f29df1f..4d8e696 100644 --- a/crate/process/src/scheduler.rs +++ b/crate/process/src/scheduler.rs @@ -211,4 +211,5 @@ mod stride { fn expand(vec: &mut Vec, id: usize) { let len = vec.len(); vec.resize(len.max(id + 1), T::default()); -} \ No newline at end of file +} + diff --git a/crate/riscv b/crate/riscv index ed6e4c5..48dffe3 160000 --- a/crate/riscv +++ b/crate/riscv @@ -1 +1 @@ -Subproject commit ed6e4c5b935d9d027303da829a7508c105df3139 +Subproject commit 48dffe3f9aa6404a1bfe53de6645b53401d7499e diff --git a/kernel/Makefile b/kernel/Makefile index 1213feb..5e58276 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -143,6 +143,7 @@ $(kernel): kernel $(assembly_object_files) $(linker_script) $(assembly_object_files) target/x86_64-blog_os/$(mode)/libucore.a kernel: + @mkdir build/$(arch) -p @CC=$(cc) cargo xbuild $(build_args) # compile assembly files diff --git a/kernel/src/arch/riscv32/paging.rs b/kernel/src/arch/riscv32/paging.rs index 95ecefe..680448b 100644 --- a/kernel/src/arch/riscv32/paging.rs +++ b/kernel/src/arch/riscv32/paging.rs @@ -17,9 +17,11 @@ pub fn setup_page_table(frame: Frame) { p2.set_recursive(RECURSIVE_PAGE_PML4, frame.clone()); // Set kernel identity map - p2[0x40].set(Frame::of_addr(PhysAddr::new(0x10000000)), EF::VALID | EF::READABLE | EF::WRITABLE); - p2[KERNEL_PML4].set(Frame::of_addr(PhysAddr::new((KERNEL_PML4 as u32) << 22)), EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE); - p2[KERNEL_PML4 + 1].set(Frame::of_addr(PhysAddr::new((KERNEL_PML4 as u32 + 1) << 22)), EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE); + // 0x10000000 ~ 1K area + p2.map_identity(0x40, EF::VALID | EF::READABLE | EF::WRITABLE); + // 0x80000000 ~ 8K area + p2.map_identity(KERNEL_PML4, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE); + p2.map_identity(KERNEL_PML4 + 1, EF::VALID | EF::READABLE | EF::WRITABLE | EF::EXECUTABLE); use super::riscv::register::satp; unsafe { satp::set(satp::Mode::Sv32, 0, frame); } @@ -249,4 +251,4 @@ impl FrameDeallocator for FrameAllocatorForRiscv { fn dealloc(&mut self, frame: Frame) { dealloc_frame(frame.start_address().as_u32() as usize); } -} \ No newline at end of file +}