diff --git a/kernel-rs/src/memory/mod.rs b/kernel-rs/src/memory/mod.rs index 0ee34685..314b2dbc 100644 --- a/kernel-rs/src/memory/mod.rs +++ b/kernel-rs/src/memory/mod.rs @@ -1,14 +1,15 @@ mod bump; mod recycle; -// mod stack_allocator; +mod stack_allocator; use multiboot2; use x86::structures::paging::*; +use x86::*; use spin::Mutex; use self::bump::BumpFrameAllocator; use self::recycle::RecycleAllocator; -// use self::stack_allocator::StackAllocator; +use self::stack_allocator::StackAllocator; pub trait FrameAllocator { fn allocate_frames(&mut self, size: usize) -> Option; @@ -17,7 +18,7 @@ pub trait FrameAllocator { pub struct MemoryControler { frame_allocator: RecycleAllocator, - // stack_allocator: StackAllocator, + stack_allocator: StackAllocator, } static MEMORY_CONTROLER: Mutex> = Mutex::new(None); @@ -50,16 +51,19 @@ pub fn init(boot_info: &multiboot2::BootInformation) { let frame_allocator = RecycleAllocator::new(bump_allocator); - // let stack_allocator = { - // let stack_alloc_start = heap_end_page + 1; - // let stack_alloc_end = stack_alloc_start + 100; - // let stack_alloc_range = stack_alloc_start..stack_alloc_end + 1; - // StackAllocator::new(stack_alloc_range) - // }; + let heap_end_page = + Page::containing_address(VirtAddr::new(::HEAP_START as u32 + ::HEAP_SIZE as u32 - 1)); + + let stack_allocator = { + let stack_alloc_start = heap_end_page + 1; + let stack_alloc_end = stack_alloc_start + 100; + let stack_alloc_range = stack_alloc_start..stack_alloc_end + 1; + StackAllocator::new(stack_alloc_range) + }; *MEMORY_CONTROLER.lock() = Some(MemoryControler { frame_allocator, - // stack_allocator, + stack_allocator, }); } @@ -79,6 +83,14 @@ pub fn deallocate_frames(frame: PhysFrame, count: usize) { } } +pub fn allocate_stack() { + if let Some(ref mut controler) = *MEMORY_CONTROLER.lock() { + controler.stack_allocator.allocate_stack() + } else { + panic!("frame allocator not initialized!"); + } +} + /// Init memory module after core /// Must be called once, and only once, pub fn init_noncore() { diff --git a/kernel-rs/src/memory/stack_allocator.rs b/kernel-rs/src/memory/stack_allocator.rs index fb756ce4..ddf17a06 100644 --- a/kernel-rs/src/memory/stack_allocator.rs +++ b/kernel-rs/src/memory/stack_allocator.rs @@ -34,7 +34,7 @@ impl StackAllocator { StackAllocator { range } } - pub fn alloc_stack( + pub fn allocate_stack( &mut self, active_table: &mut ActivePageTable, frame_allocator: &mut FA, diff --git a/kernel-rs/x86 b/kernel-rs/x86 index f5e4cb87..2a8416d0 160000 --- a/kernel-rs/x86 +++ b/kernel-rs/x86 @@ -1 +1 @@ -Subproject commit f5e4cb879953ebbeba28a1eaa28bf531424e6824 +Subproject commit 2a8416d0af403786d082695d13a0f74cd2b7f216