|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(global_asm)]
|
|
|
|
#![feature(llvm_asm)]
|
|
|
|
#![feature(panic_info_message)]
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod console;
|
|
|
|
mod lang_items;
|
|
|
|
mod sbi;
|
|
|
|
mod syscall;
|
|
|
|
mod trap;
|
|
|
|
|
|
|
|
global_asm!(include_str!("entry.asm"));
|
|
|
|
global_asm!(include_str!("link_app.S"));
|
|
|
|
|
|
|
|
fn clear_bss() {
|
|
|
|
extern "C" {
|
|
|
|
fn sbss();
|
|
|
|
fn ebss();
|
|
|
|
}
|
|
|
|
(sbss as usize..ebss as usize).for_each(|a| {
|
|
|
|
unsafe { (a as *mut u8).write_volatile(0) }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn rust_main() -> ! {
|
|
|
|
clear_bss();
|
|
|
|
println!("Hello, world!");
|
|
|
|
extern "C" {
|
|
|
|
fn _num_app();
|
|
|
|
}
|
|
|
|
let num_app_ptr = _num_app as usize as *const usize;
|
|
|
|
let num_app = unsafe { num_app_ptr.read_volatile() };
|
|
|
|
println!("num_app = {}", num_app);
|
|
|
|
let app_start: &[usize] = unsafe {
|
|
|
|
core::slice::from_raw_parts(num_app_ptr.add(1), num_app + 1)
|
|
|
|
};
|
|
|
|
for i in 0..num_app {
|
|
|
|
println!("app_{} [{:#x}, {:#x})", i, app_start[i], app_start[i + 1]);
|
|
|
|
}
|
|
|
|
panic!("Shutdown machine!");
|
|
|
|
}
|