1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-27 02:03:29 +04:00
rCore/src/lib.rs

161 lines
3.9 KiB
Rust
Raw Normal View History

2018-04-02 11:28:32 +04:00
#![feature(ptr_internals)]
2017-04-11 17:02:21 +04:00
#![feature(lang_items)]
2017-04-12 21:16:04 +04:00
#![feature(const_fn)]
2017-11-19 15:41:20 +04:00
#![feature(alloc)]
#![feature(const_unique_new, const_atomic_usize_new)]
#![feature(unique)]
#![feature(allocator_api)]
2017-11-19 16:13:18 +04:00
#![feature(global_allocator)]
#![feature(abi_x86_interrupt)]
2018-04-05 18:36:39 +04:00
#![feature(iterator_step_by)]
2018-04-17 11:32:53 +04:00
#![feature(unboxed_closures)]
#![feature(naked_functions)]
#![feature(asm)]
2018-06-04 21:32:21 +04:00
#![feature(optin_builtin_traits)]
#![feature(panic_implementation)]
#![feature(panic_info_message)]
#![feature(universal_impl_trait)]
2018-07-04 12:23:11 +04:00
#![feature(global_asm)]
2017-04-11 17:02:21 +04:00
#![no_std]
2017-11-19 15:41:20 +04:00
#[macro_use]
extern crate alloc;
extern crate bit_allocator;
extern crate bit_field;
2017-04-13 20:27:39 +04:00
#[macro_use]
extern crate bitflags;
#[macro_use]
2017-04-18 17:15:44 +04:00
extern crate lazy_static;
extern crate linked_list_allocator;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate log;
#[cfg(target_arch = "x86_64")]
extern crate multiboot2;
#[macro_use]
extern crate once;
extern crate rlibc;
#[cfg(target_arch = "x86_64")]
extern crate simple_filesystem;
extern crate spin;
#[cfg(target_arch = "x86_64")]
extern crate syscall as redox_syscall;
#[cfg(target_arch = "x86_64")]
2018-06-19 20:24:07 +04:00
extern crate uart_16550;
2018-06-23 15:11:41 +04:00
extern crate ucore_memory;
extern crate volatile;
#[macro_use]
#[cfg(target_arch = "x86_64")]
extern crate x86_64;
extern crate xmas_elf;
2018-07-07 12:34:11 +04:00
pub use arch::interrupt::rust_trap;
#[cfg(target_arch = "x86_64")]
2018-07-07 12:34:11 +04:00
pub use arch::interrupt::set_return_rsp;
use linked_list_allocator::LockedHeap;
#[macro_use] // print!
#[cfg(target_arch = "x86_64")]
mod io;
#[macro_use] // print!
#[cfg(target_arch = "riscv")]
#[path = "io/riscv_io.rs"]
mod io;
#[cfg(target_arch = "x86_64")]
mod memory;
mod lang;
2018-04-05 18:36:39 +04:00
mod util;
2018-04-12 16:57:56 +04:00
mod consts;
#[cfg(target_arch = "x86_64")]
mod process;
#[cfg(target_arch = "x86_64")]
2018-05-12 23:41:41 +04:00
mod syscall;
#[cfg(target_arch = "x86_64")]
mod fs;
#[cfg(target_arch = "x86_64")]
2018-05-31 16:26:25 +04:00
mod thread;
#[cfg(target_arch = "x86_64")]
mod sync;
2017-04-12 21:16:04 +04:00
#[allow(dead_code)]
#[cfg(target_arch = "x86_64")]
#[path = "arch/x86_64/mod.rs"]
mod arch;
2018-07-04 12:23:11 +04:00
#[cfg(target_arch = "riscv")]
#[path = "arch/riscv32/mod.rs"]
mod arch;
#[no_mangle]
#[cfg(target_arch = "riscv")]
pub extern fn rust_main() -> ! {
2018-07-07 12:34:11 +04:00
arch::init();
2018-07-04 12:23:11 +04:00
loop {}
}
2018-05-13 11:06:44 +04:00
/// The entry point of Rust kernel
2017-04-11 17:02:21 +04:00
#[no_mangle]
#[cfg(target_arch = "x86_64")]
pub extern "C" fn rust_main(multiboot_information_address: usize) -> ! {
2018-05-22 19:48:39 +04:00
arch::idt::init();
io::init();
// ATTENTION: we have a very small stack and no guard page
println!("Hello World{}", "!");
2017-04-11 21:30:19 +04:00
let boot_info = unsafe { multiboot2::load(multiboot_information_address) };
2018-06-20 07:08:47 +04:00
let rsdt_addr = boot_info.rsdp_v1_tag().unwrap().rsdt_address();
// set up guard page and map the heap pages
let mut kernel_memory = memory::init(boot_info);
arch::gdt::init();
2018-06-23 18:30:57 +04:00
memory::test::cow();
2018-06-20 07:08:47 +04:00
let acpi = arch::driver::init(rsdt_addr, |addr: usize, count: usize| {
2018-06-23 18:30:57 +04:00
use memory::*;
kernel_memory.push(MemoryArea::new_identity(addr, addr + count * 0x1000, MemoryAttr::default(), "acpi"))
});
2018-04-17 11:32:53 +04:00
2018-06-16 21:41:43 +04:00
arch::smp::start_other_cores(&acpi, &mut kernel_memory);
process::init(kernel_memory);
fs::load_sfs();
unsafe{ arch::interrupt::enable(); }
// thread::test::unpack();
2018-06-04 21:32:21 +04:00
// sync::test::philosopher_using_mutex();
// sync::test::philosopher_using_monitor();
sync::mpsc::test::test_all();
loop {}
2017-04-11 20:25:51 +04:00
}
2017-04-11 17:02:21 +04:00
2018-05-13 11:06:44 +04:00
/// The entry point for another processors
#[no_mangle]
#[cfg(target_arch = "x86_64")]
pub extern "C" fn other_main() -> ! {
arch::gdt::init();
arch::idt::init();
arch::driver::apic::other_init();
2018-04-18 11:22:06 +04:00
let cpu_id = arch::driver::apic::lapic_id();
let ms = unsafe { arch::smp::notify_started(cpu_id) };
2018-07-10 20:53:40 +04:00
unsafe { ms.activate(); }
2018-06-03 07:22:28 +04:00
println!("Hello world! from CPU {}!", arch::driver::apic::lapic_id());
// unsafe{ let a = *(0xdeadbeaf as *const u8); } // Page fault
loop {}
}
2018-05-13 11:06:44 +04:00
/// Global heap allocator
///
/// Available after `memory::init()`.
///
/// It should be defined in memory mod, but in Rust `global_allocator` must be in root mod.
2017-11-19 16:13:18 +04:00
#[global_allocator]
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();