From 638eb8666a95cfe6610b9d99d230c3de62b1ab77 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Thu, 26 Aug 2021 21:03:50 +0800 Subject: [PATCH] Update rustc && rustsbi-k210 --- bootloader/rustsbi-k210.bin | Bin 94904 -> 94904 bytes os/src/loader.rs | 62 ++++++++++++++++++++++++++++++++++++ rust-toolchain | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 os/src/loader.rs diff --git a/bootloader/rustsbi-k210.bin b/bootloader/rustsbi-k210.bin index 27987d6839be28f8acd13e816e4de1c4548debbe..c53ed1fc198816f8d4a0cfec958eaae3f2976cd0 100755 GIT binary patch delta 148 zcmV;F0Bira#KR3Y A!vFvP diff --git a/os/src/loader.rs b/os/src/loader.rs new file mode 100644 index 00000000..bfdc3970 --- /dev/null +++ b/os/src/loader.rs @@ -0,0 +1,62 @@ +use alloc::vec::Vec; +use lazy_static::*; + +pub fn get_num_app() -> usize { + extern "C" { fn _num_app(); } + unsafe { (_num_app as usize as *const usize).read_volatile() } +} + +pub fn get_app_data(app_id: usize) -> &'static [u8] { + extern "C" { fn _num_app(); } + let num_app_ptr = _num_app as usize as *const usize; + let num_app = get_num_app(); + let app_start = unsafe { + core::slice::from_raw_parts(num_app_ptr.add(1), num_app + 1) + }; + assert!(app_id < num_app); + unsafe { + core::slice::from_raw_parts( + app_start[app_id] as *const u8, + app_start[app_id + 1] - app_start[app_id] + ) + } +} + +lazy_static! { + static ref APP_NAMES: Vec<&'static str> = { + let num_app = get_num_app(); + extern "C" { fn _app_names(); } + let mut start = _app_names as usize as *const u8; + let mut v = Vec::new(); + unsafe { + for _ in 0..num_app { + let mut end = start; + while end.read_volatile() != '\0' as u8 { + end = end.add(1); + } + let slice = core::slice::from_raw_parts(start, end as usize - start as usize); + let str = core::str::from_utf8(slice).unwrap(); + v.push(str); + start = end.add(1); + } + } + v + }; +} + + +#[allow(unused)] +pub fn get_app_data_by_name(name: &str) -> Option<&'static [u8]> { + let num_app = get_num_app(); + (0..num_app) + .find(|&i| APP_NAMES[i] == name) + .map(|i| get_app_data(i)) +} + +pub fn list_apps() { + println!("/**** APPS ****"); + for app in APP_NAMES.iter() { + println!("{}", app); + } + println!("**************/"); +} \ No newline at end of file diff --git a/rust-toolchain b/rust-toolchain index bf867e0a..1c5af266 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly +nightly-2021-08-25