Use x86's TaskStateSegment and use usize for stack pointers

This commit is contained in:
Philipp Oppermann
2016-12-21 00:12:19 +01:00
parent d1fb1516fa
commit ceb44d9c2e
8 changed files with 31 additions and 178 deletions

View File

@@ -9,7 +9,7 @@
pub use self::area_frame_allocator::AreaFrameAllocator;
pub use self::paging::remap_the_kernel;
pub use self::stack_allocator::{Stack, StackPointer};
pub use self::stack_allocator::Stack;
use self::paging::PhysicalAddress;
use multiboot2::BootInformation;

View File

@@ -1,6 +1,5 @@
use memory::paging::{self, Page, PageIter, ActivePageTable};
use memory::{PAGE_SIZE, FrameAllocator};
use core::nonzero::NonZero;
pub fn new_stack_allocator(page_range: PageIter) -> StackAllocator {
StackAllocator { range: page_range }
@@ -52,36 +51,24 @@ impl StackAllocator {
#[derive(Debug)]
pub struct Stack {
top: StackPointer,
bottom: StackPointer,
top: usize,
bottom: usize,
}
impl Stack {
fn new(top: usize, bottom: usize) -> Stack {
assert!(top > bottom);
Stack {
top: StackPointer::new(top),
bottom: StackPointer::new(bottom),
top: top,
bottom: bottom,
}
}
pub fn top(&self) -> StackPointer {
pub fn top(&self) -> usize {
self.top
}
}
#[derive(Debug, Clone, Copy)]
pub struct StackPointer(NonZero<usize>);
impl StackPointer {
fn new(ptr: usize) -> StackPointer {
assert!(ptr != 0);
StackPointer(unsafe { NonZero::new(ptr) })
}
}
impl Into<usize> for StackPointer {
fn into(self) -> usize {
*self.0
pub fn bottom(&self) -> usize {
self.bottom
}
}