|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
use alloc::vec::Vec;
|
|
|
|
|
use core::arch::asm;
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
|
|
use crate::config::*;
|
|
|
|
|
use crate::*;
|
|
|
|
|
use crate::trap::TrapContext;
|
|
|
|
|
|
|
|
|
|
static KERNEL_STACK: [[u8; KERNEL_STACK_SIZE]; MAX_APP_NUM] = [[0; KERNEL_STACK_SIZE]; MAX_APP_NUM]; // 这一章, 每个用户应用对应一个内核栈 [每个应用自己的内核栈; 总应用数]
|
|
|
|
@ -8,6 +11,7 @@ static USER_STACK: [[u8; USER_STACK_SIZE]; MAX_APP_NUM] = [[0; USER_STACK_SIZE];
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
fn _num_app();
|
|
|
|
|
fn _app_names();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 得到用户app的数量
|
|
|
|
@ -31,4 +35,51 @@ pub fn get_app_data(app_id: usize) -> &'static [u8] {
|
|
|
|
|
app_start[app_id + 1] - app_start[app_id],
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lazy_static!{
|
|
|
|
|
static ref APP_NAMES:Vec<&'static str> = {
|
|
|
|
|
// app总数
|
|
|
|
|
let num_app = get_num_app();
|
|
|
|
|
|
|
|
|
|
// 名字开始的位置
|
|
|
|
|
let mut start = _app_names as usize as *const u8;
|
|
|
|
|
|
|
|
|
|
// 找到每个用户名
|
|
|
|
|
let mut app_names = Vec::new();
|
|
|
|
|
unsafe {
|
|
|
|
|
for _ in 0..num_app {
|
|
|
|
|
let mut end = start;
|
|
|
|
|
while end.read_volatile() != b'\0'{
|
|
|
|
|
end = end.add(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从start 到 end长度的切片
|
|
|
|
|
let slice = core::slice::from_raw_parts(start, end as usize - start as usize);
|
|
|
|
|
|
|
|
|
|
let str = core::str::from_utf8(slice).unwrap();
|
|
|
|
|
app_names.push(str);
|
|
|
|
|
start = end.add(1)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
app_names
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 根据app的名字 找到app的下标, 然后找到app的二进制elf数据
|
|
|
|
|
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(get_app_data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 输出所有的app的名字
|
|
|
|
|
pub fn list_apps() {
|
|
|
|
|
println!("/**** APPS ****");
|
|
|
|
|
for app in APP_NAMES.iter() {
|
|
|
|
|
println!("{}", app);
|
|
|
|
|
}
|
|
|
|
|
println!("**************/");
|
|
|
|
|
}
|