diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index e1b7d05..4e27780 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -263,6 +263,8 @@ dependencies = [ "uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ucore-memory 0.1.0", "ucore-process 0.1.0", + "usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "volatile 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "x86_64 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index e2bba97..21080d5 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -33,6 +33,10 @@ ucore-memory = { path = "../crate/memory" } ucore-process = { path = "../crate/process" } simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" } +[dependencies.ux] +default-features = false +version = "0.1.0" + [target.'cfg(target_arch = "x86_64")'.dependencies] bootloader = "0.3" x86_64 = "0.2.11" @@ -45,6 +49,7 @@ bbl = { path = "../crate/bbl" } [target.'cfg(target_arch = "aarch64")'.dependencies] cortex-a = "2.2.1" +usize_conversions = "0.2.0" atags = { path = "../crate/atags" } bcm2837 = { path = "../crate/bcm2837", features = ["use_generic_timer"] } diff --git a/kernel/src/arch/aarch64/mod.rs b/kernel/src/arch/aarch64/mod.rs index 826078d..d3d0e6d 100644 --- a/kernel/src/arch/aarch64/mod.rs +++ b/kernel/src/arch/aarch64/mod.rs @@ -1,6 +1,9 @@ //! Entrance and initialization for aarch64. extern crate atags; +extern crate bitflags; +extern crate usize_conversions; +pub extern crate ux; pub mod io; pub mod paging; @@ -26,19 +29,19 @@ pub extern "C" fn rust_main() -> ! { memory::init(); println!("memory init over"); - let mut v = vec![]; - for i in 0..1000 { - v.push(i); - println!("{:?}", v); - } + //let mut v = vec![]; + //for i in 0..1000 { + // v.push(i); + // println!("{:?}", v); + //} // First init log mod, so that we can print log info. // FIXME - // ::logging::init(); + ::logging::init(); interrupt::init(); timer::init(); - // ::process::init(); + ::process::init(); unsafe { interrupt::enable(); } diff --git a/kernel/src/arch/aarch64/paging.rs b/kernel/src/arch/aarch64/paging.rs index 6c21839..76c395c 100644 --- a/kernel/src/arch/aarch64/paging.rs +++ b/kernel/src/arch/aarch64/paging.rs @@ -3,8 +3,11 @@ use ucore_memory::memory_set::*; use ucore_memory::paging::*; -type VirtAddr = usize; -type PhysAddr = usize; +type VirtAddr=usize; +type PhysAddr=usize; + +use alloc::alloc::{alloc, Layout}; +use memory::alloc_stack; /// TODO pub struct ActivePageTable { @@ -152,21 +155,45 @@ impl Entry for PageEntry { } +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct MockFrame(PhysAddr); + +impl MockFrame { + pub fn of_addr(addr: PhysAddr) -> Self { + MockFrame(addr) + } + pub fn start_address(&self) -> PhysAddr { + unimplemented!() + } + pub fn p2_index(&self) -> usize { + unimplemented!() + } + pub fn p1_index(&self) -> usize { + unimplemented!() + } + pub fn number(&self) -> usize { + unimplemented!() + } +} + /// TODO pub struct InactivePageTable0 { - // TODO + p4_frame: MockFrame, } /// TODO impl InactivePageTable for InactivePageTable0 { type Active = ActivePageTable; - fn new() -> Self { - unimplemented!() + fn new() -> Self { + unsafe {let layout = Layout::new::(); + let ptr = alloc(layout); + let frame = MockFrame::of_addr(*ptr as usize); + InactivePageTable0 { p4_frame: frame }} } fn new_bare() -> Self { - unimplemented!() + Self::new() } fn edit(&mut self, f: impl FnOnce(&mut Self::Active)) { @@ -174,15 +201,15 @@ impl InactivePageTable for InactivePageTable0 { } unsafe fn activate(&self) { - unimplemented!() + } unsafe fn with(&self, f: impl FnOnce()) { - unimplemented!() + } fn token(&self) -> usize { - unimplemented!() + 0 } fn alloc_frame() -> Option { @@ -190,10 +217,10 @@ impl InactivePageTable for InactivePageTable0 { } fn dealloc_frame(target: PhysAddr) { - unimplemented!() + } fn alloc_stack() -> Stack { - unimplemented!() + alloc_stack() } } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 8305a77..9d87616 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -9,6 +9,7 @@ #![feature(panic_info_message)] #![feature(global_asm)] #![feature(compiler_builtins_lib)] +#![feature(try_from)] #![no_std] @@ -33,6 +34,7 @@ extern crate volatile; #[cfg(target_arch = "x86_64")] extern crate x86_64; extern crate xmas_elf; +extern crate usize_conversions; use linked_list_allocator::LockedHeap;