Merge pull request #4 from Hoblovski/master

Add docs & small fix to makefile
master
Wang Runji 6 years ago committed by GitHub
commit 32b335adc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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<usize>;
@ -23,6 +35,7 @@ pub type BitAlloc1M = BitAllocCascade16<BitAlloc64K>;
pub type BitAlloc16M = BitAllocCascade16<BitAlloc1M>;
pub type BitAlloc256M = BitAllocCascade16<BitAlloc16M>;
/// Implement the bit allocator by segment tree algorithm.
#[derive(Default)]
pub struct BitAllocCascade16<T: BitAlloc> {
bitset: u16,
@ -77,6 +90,8 @@ impl<T: BitAlloc> BitAllocCascade16<T> {
#[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;

@ -212,3 +212,4 @@ fn expand<T: Default + Clone>(vec: &mut Vec<T>, id: usize) {
let len = vec.len();
vec.resize(len.max(id + 1), T::default());
}

@ -1 +1 @@
Subproject commit ed6e4c5b935d9d027303da829a7508c105df3139
Subproject commit 48dffe3f9aa6404a1bfe53de6645b53401d7499e

@ -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

@ -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); }

Loading…
Cancel
Save