add basic alloc

master
koumingyang 6 years ago
parent a13f39149b
commit a0b948fb53

2
kernel/Cargo.lock generated

@ -263,6 +263,8 @@ dependencies = [
"uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "uart_16550 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ucore-memory 0.1.0", "ucore-memory 0.1.0",
"ucore-process 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)", "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)", "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)", "xmas-elf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",

@ -33,6 +33,10 @@ ucore-memory = { path = "../crate/memory" }
ucore-process = { path = "../crate/process" } ucore-process = { path = "../crate/process" }
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" } 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] [target.'cfg(target_arch = "x86_64")'.dependencies]
bootloader = "0.3" bootloader = "0.3"
x86_64 = "0.2.11" x86_64 = "0.2.11"
@ -45,6 +49,7 @@ bbl = { path = "../crate/bbl" }
[target.'cfg(target_arch = "aarch64")'.dependencies] [target.'cfg(target_arch = "aarch64")'.dependencies]
cortex-a = "2.2.1" cortex-a = "2.2.1"
usize_conversions = "0.2.0"
atags = { path = "../crate/atags" } atags = { path = "../crate/atags" }
bcm2837 = { path = "../crate/bcm2837", features = ["use_generic_timer"] } bcm2837 = { path = "../crate/bcm2837", features = ["use_generic_timer"] }

@ -1,6 +1,9 @@
//! Entrance and initialization for aarch64. //! Entrance and initialization for aarch64.
extern crate atags; extern crate atags;
extern crate bitflags;
extern crate usize_conversions;
pub extern crate ux;
pub mod io; pub mod io;
pub mod paging; pub mod paging;
@ -26,19 +29,19 @@ pub extern "C" fn rust_main() -> ! {
memory::init(); memory::init();
println!("memory init over"); println!("memory init over");
let mut v = vec![]; //let mut v = vec![];
for i in 0..1000 { //for i in 0..1000 {
v.push(i); // v.push(i);
println!("{:?}", v); // println!("{:?}", v);
} //}
// First init log mod, so that we can print log info. // First init log mod, so that we can print log info.
// FIXME // FIXME
// ::logging::init(); ::logging::init();
interrupt::init(); interrupt::init();
timer::init(); timer::init();
// ::process::init(); ::process::init();
unsafe { interrupt::enable(); } unsafe { interrupt::enable(); }

@ -3,8 +3,11 @@
use ucore_memory::memory_set::*; use ucore_memory::memory_set::*;
use ucore_memory::paging::*; use ucore_memory::paging::*;
type VirtAddr = usize; type VirtAddr=usize;
type PhysAddr = usize; type PhysAddr=usize;
use alloc::alloc::{alloc, Layout};
use memory::alloc_stack;
/// TODO /// TODO
pub struct ActivePageTable { pub struct ActivePageTable {
@ -152,9 +155,30 @@ 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 /// TODO
pub struct InactivePageTable0 { pub struct InactivePageTable0 {
// TODO p4_frame: MockFrame,
} }
/// TODO /// TODO
@ -162,11 +186,14 @@ impl InactivePageTable for InactivePageTable0 {
type Active = ActivePageTable; type Active = ActivePageTable;
fn new() -> Self { fn new() -> Self {
unimplemented!() unsafe {let layout = Layout::new::<u64>();
let ptr = alloc(layout);
let frame = MockFrame::of_addr(*ptr as usize);
InactivePageTable0 { p4_frame: frame }}
} }
fn new_bare() -> Self { fn new_bare() -> Self {
unimplemented!() Self::new()
} }
fn edit(&mut self, f: impl FnOnce(&mut Self::Active)) { fn edit(&mut self, f: impl FnOnce(&mut Self::Active)) {
@ -174,15 +201,15 @@ impl InactivePageTable for InactivePageTable0 {
} }
unsafe fn activate(&self) { unsafe fn activate(&self) {
unimplemented!()
} }
unsafe fn with(&self, f: impl FnOnce()) { unsafe fn with(&self, f: impl FnOnce()) {
unimplemented!()
} }
fn token(&self) -> usize { fn token(&self) -> usize {
unimplemented!() 0
} }
fn alloc_frame() -> Option<PhysAddr> { fn alloc_frame() -> Option<PhysAddr> {
@ -190,10 +217,10 @@ impl InactivePageTable for InactivePageTable0 {
} }
fn dealloc_frame(target: PhysAddr) { fn dealloc_frame(target: PhysAddr) {
unimplemented!()
} }
fn alloc_stack() -> Stack { fn alloc_stack() -> Stack {
unimplemented!() alloc_stack()
} }
} }

@ -9,6 +9,7 @@
#![feature(panic_info_message)] #![feature(panic_info_message)]
#![feature(global_asm)] #![feature(global_asm)]
#![feature(compiler_builtins_lib)] #![feature(compiler_builtins_lib)]
#![feature(try_from)]
#![no_std] #![no_std]
@ -33,6 +34,7 @@ extern crate volatile;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
extern crate x86_64; extern crate x86_64;
extern crate xmas_elf; extern crate xmas_elf;
extern crate usize_conversions;
use linked_list_allocator::LockedHeap; use linked_list_allocator::LockedHeap;

Loading…
Cancel
Save