diff --git a/Cargo.toml b/Cargo.toml index 733a5aa..1104c73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ bit_field = "0.9.0" volatile = "0.1.0" lazy_static = { version = "1.0.0", features = ["spin_no_std"] } bit-allocator = { path = "crate/bit-allocator" } +ucore-memory = { path = "crate/memory" } [target.x86_64-blog_os.dependencies] @@ -39,10 +40,9 @@ redox_syscall = "0.1" log = "0.4" uart_16550 = "0.1" simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" } -ucore-memory = { path = "crate/memory" } [target.riscv32-blog_os.dependencies] -linked_list_allocator = { version = "0.5", default-features = false } # due to rust version +linked_list_allocator = "0.5" # due to rust version riscv = { path = "crate/riscv" } bbl = { path = "crate/bbl" } diff --git a/crate/memory/src/lib.rs b/crate/memory/src/lib.rs index 480d8e3..e48802d 100644 --- a/crate/memory/src/lib.rs +++ b/crate/memory/src/lib.rs @@ -11,6 +11,8 @@ extern crate alloc; extern crate std; pub mod paging; +// FIXME: LLVM error on riscv32 +#[cfg(target_arch = "x86_64")] pub mod cow; pub mod swap; diff --git a/crate/riscv b/crate/riscv index ef046c8..4bf5f1b 160000 --- a/crate/riscv +++ b/crate/riscv @@ -1 +1 @@ -Subproject commit ef046c88fdb7ed0f416f29e034d4679f0e7a2573 +Subproject commit 4bf5f1b732b8977d445f668df0b3f11c0d19d9a5 diff --git a/src/io/riscv_io.rs b/src/io/riscv_io.rs index 6619310..c324296 100644 --- a/src/io/riscv_io.rs +++ b/src/io/riscv_io.rs @@ -13,6 +13,31 @@ macro_rules! println { ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); } +macro_rules! trace { + ($fmt:expr) => (print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); +} + +macro_rules! debug { + ($fmt:expr) => (print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); +} + +macro_rules! info { + ($fmt:expr) => (print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); +} + +macro_rules! warn { + ($fmt:expr) => (print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); +} + +macro_rules! error { + ($fmt:expr) => (print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); +} + pub fn print(args: fmt::Arguments) { use arch::serial::SerialPort; use core::fmt::Write; diff --git a/src/lang.rs b/src/lang.rs index d2cef8a..95914f1 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -32,6 +32,6 @@ pub fn panic_fmt(fmt: ::core::fmt::Arguments, file: &'static str, line: u32, col #[cfg(target_arch = "x86_64")] #[lang = "oom"] #[no_mangle] -fn oom() -> ! { +pub fn oom() -> ! { panic!("out of memory"); } diff --git a/src/lib.rs b/src/lib.rs index 0d773e1..4b4ef86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,19 +20,13 @@ #[macro_use] -#[cfg(target_arch = "x86_64")] extern crate alloc; -#[cfg(target_arch = "x86_64")] extern crate bit_allocator; -#[cfg(target_arch = "x86_64")] extern crate bit_field; #[macro_use] -#[cfg(target_arch = "x86_64")] extern crate bitflags; #[macro_use] -#[cfg(target_arch = "x86_64")] extern crate lazy_static; -#[cfg(target_arch = "x86_64")] extern crate linked_list_allocator; #[macro_use] #[cfg(target_arch = "x86_64")] @@ -40,7 +34,6 @@ extern crate log; #[cfg(target_arch = "x86_64")] extern crate multiboot2; #[macro_use] -#[cfg(target_arch = "x86_64")] extern crate once; extern crate rlibc; #[cfg(target_arch = "x86_64")] @@ -50,20 +43,16 @@ extern crate spin; extern crate syscall as redox_syscall; #[cfg(target_arch = "x86_64")] extern crate uart_16550; -#[cfg(target_arch = "x86_64")] extern crate ucore_memory; -#[cfg(target_arch = "x86_64")] extern crate volatile; #[macro_use] #[cfg(target_arch = "x86_64")] extern crate x86_64; -#[cfg(target_arch = "x86_64")] extern crate xmas_elf; pub use arch::interrupt::rust_trap; #[cfg(target_arch = "x86_64")] pub use arch::interrupt::set_return_rsp; -#[cfg(target_arch = "x86_64")] use linked_list_allocator::LockedHeap; #[macro_use] // print! @@ -78,11 +67,7 @@ mod io; #[cfg(target_arch = "x86_64")] mod memory; mod lang; -#[cfg(target_arch = "x86_64")] mod util; -#[macro_use] -mod macros; -#[cfg(target_arch = "x86_64")] mod consts; #[cfg(target_arch = "x86_64")] mod process; @@ -130,9 +115,6 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) -> ! { arch::gdt::init(); memory::test::cow(); - test!(global_allocator); - test!(guard_page); - test!(find_mp); let acpi = arch::driver::init(rsdt_addr, |addr: usize, count: usize| { use memory::*; @@ -151,23 +133,7 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) -> ! { // sync::test::philosopher_using_monitor(); sync::mpsc::test::test_all(); - // 直接进入用户态暂不可用:内核代码用户不可访问 -// unsafe{ -// use arch::syscall; -// // 在用户模式下触发时钟中断,会导致GPF -// // (可能是由于没有合理分离栈) -// no_interrupt!({ -// syscall::switch_to_user(); -// println!("Now in user mode"); -// syscall::switch_to_kernel(); -// println!("Now in kernel mode"); -// }); -// } - loop {} - - test_end!(); - unreachable!(); } /// The entry point for another processors @@ -191,33 +157,4 @@ pub extern "C" fn other_main() -> ! { /// /// It should be defined in memory mod, but in Rust `global_allocator` must be in root mod. #[global_allocator] -#[cfg(target_arch = "x86_64")] static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty(); - -#[cfg(target_arch = "x86_64")] -mod test { - pub fn global_allocator() { - for i in 0..10000 { - format!("Some String"); - } - } - pub fn find_mp() { - use arch; - let mp = arch::driver::mp::find_mp(); - assert!(mp.is_some()); - } - pub fn guard_page() { - use x86_64; - // invoke a breakpoint exception - unsafe { asm!("int 3"::::"intel" "volatile"); } - - fn stack_overflow() { - stack_overflow(); // for each recursion, the return address is pushed - } - - // trigger a stack overflow - stack_overflow(); - - println!("It did not crash!"); - } -} \ No newline at end of file diff --git a/src/macros.rs b/src/macros.rs deleted file mode 100644 index d349beb..0000000 --- a/src/macros.rs +++ /dev/null @@ -1,24 +0,0 @@ -macro_rules! test_end { - () => ( - println!("Test end"); - // test success - unsafe{ arch::cpu::exit_in_qemu(11) } - ) -} - -macro_rules! test { - // ($name:expr, $body:expr) => ( - // if cfg!(feature = "test") { - // println!("Testing: {}", $name); - // $body; - // println!("Success: {}", $name); - // } - // ); - ($func:ident) => ( - if cfg!(feature = "test") { - println!("Testing: {}", stringify!($func)); - test::$func(); - println!("Success: {}", stringify!($func)); - } - ) -}