diff --git a/kernel-rs/Cargo.toml b/kernel-rs/Cargo.toml index efc5451c..b44f28a4 100644 --- a/kernel-rs/Cargo.toml +++ b/kernel-rs/Cargo.toml @@ -11,15 +11,17 @@ rlibc = "1.0" bitflags = "1.0.1" spin = "0.4" slab_allocator = "0.3.1" -multiboot2 = { path = "multiboot2-elf64" } # added rsdp tag -x86 = { path = "x86" } # forked for IA32 -# raw-cpuid = { path = "rust-cpuid" } +multiboot2 = { path = "multiboot2-elf64" } # added rsdp tag [dependencies.raw-cpuid] # need to use github/master because of features not yet on crates.io git = "https://github.com/gz/rust-cpuid" features = ["nightly"] +[dependencies.x86] +# forked for IA32 compat +path = "x86" + [dependencies.lazy_static] version = "1.0.0" features = ["spin_no_std"] diff --git a/kernel-rs/src/arch/x86/gdt.rs b/kernel-rs/src/arch/x86/gdt.rs index 974c8a9b..cea7e214 100644 --- a/kernel-rs/src/arch/x86/gdt.rs +++ b/kernel-rs/src/arch/x86/gdt.rs @@ -8,7 +8,6 @@ static GDT: Once = Once::new(); static TSS: Once = Once::new(); pub fn init() { - let tss = tss::TaskStateSegment::new(); let tss = TSS.call_once(|| { let tss = tss::TaskStateSegment::new(); tss @@ -39,6 +38,7 @@ pub fn init() { // reload code segment register set_cs(code_selector); // load TSS + println!("loading tss {:?}", tss_selector); load_tss(tss_selector); } } diff --git a/kernel-rs/src/arch/x86/interrupt/exception.rs b/kernel-rs/src/arch/x86/interrupt/exception.rs index fa1682dc..b8994281 100644 --- a/kernel-rs/src/arch/x86/interrupt/exception.rs +++ b/kernel-rs/src/arch/x86/interrupt/exception.rs @@ -54,7 +54,7 @@ exception!(overflow, {}); exception!(bound_range, {}); exception!(invalid_opcode, {}); exception!(device_not_available, {}); -exception_err!(double_fault, {}); +exception_err!(double_fault, { panic!("double fault non recoverable") }); exception!(coprocessor_segment_overrun, {}); exception_err!(invalid_tss, {}); exception_err!(segment_not_present, {}); diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 04c00217..a7467976 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -53,13 +53,17 @@ pub fn kmain() -> ! { // x86::instructions::interrupts::int3(); - // fn stack_overflow() { stack_overflow(); } + // fn stack_overflow() { + // stack_overflow(); + // } // stack_overflow(); // unsafe { // *(0xdead as *mut u32) = 42; // }; + println!("tss: {:?}"); + // vga is *not* cpu specific vga::init(); diff --git a/kernel-rs/src/memory/mod.rs b/kernel-rs/src/memory/mod.rs index 7d9de270..0ee34685 100644 --- a/kernel-rs/src/memory/mod.rs +++ b/kernel-rs/src/memory/mod.rs @@ -1,5 +1,6 @@ mod bump; mod recycle; +// mod stack_allocator; use multiboot2; use x86::structures::paging::*; @@ -7,6 +8,7 @@ use spin::Mutex; use self::bump::BumpFrameAllocator; use self::recycle::RecycleAllocator; +// use self::stack_allocator::StackAllocator; pub trait FrameAllocator { fn allocate_frames(&mut self, size: usize) -> Option; diff --git a/kernel-rs/src/memory/stack_allocator.rs b/kernel-rs/src/memory/stack_allocator.rs index 3bce908e..fb756ce4 100644 --- a/kernel-rs/src/memory/stack_allocator.rs +++ b/kernel-rs/src/memory/stack_allocator.rs @@ -1,5 +1,5 @@ use x86::structures::paging::*; -use memory::paging::{ActivePageTable}; +use memory::paging::ActivePageTable; use memory::*; use core::ops::Range; @@ -10,12 +10,9 @@ pub struct Stack { } impl Stack { - fn new (top: usize, bottom: usize) -> Stack { + fn new(top: usize, bottom: usize) -> Stack { assert!(top > bottom); - Stack { - top, - bottom, - } + Stack { top, bottom } } pub fn top(&self) -> usize { @@ -29,7 +26,7 @@ impl Stack { #[derive(Debug)] pub struct StackAllocator { - range: Range + range: Range, } impl StackAllocator { @@ -37,10 +34,12 @@ impl StackAllocator { StackAllocator { range } } - pub fn alloc_stack(&mut self, - active_table: &mut ActivePageTable, - frame_allocator: &mut FA, - size_in_pages: usize) -> Option { + pub fn alloc_stack( + &mut self, + active_table: &mut ActivePageTable, + frame_allocator: &mut FA, + size_in_pages: usize, + ) -> Option { if size_in_pages == 0 { return None; /* a zero sized stack makes no sense */ } @@ -71,8 +70,10 @@ impl StackAllocator { // create a new stack let top_of_stack = end.start_address().as_u32() + PAGE_SIZE as u32; - Some(Stack::new(top_of_stack as usize, - start.start_address().as_u32() as usize)) + Some(Stack::new( + top_of_stack as usize, + start.start_address().as_u32() as usize, + )) } _ => None, /* not enough pages */ }