app应用信息已经正常加载进内核
parent
a0fba7a3bd
commit
4916c8bde9
@ -0,0 +1,72 @@
|
||||
use lazy_static::*;
|
||||
use crate::println;
|
||||
use crate::sync::UPSafeCell;
|
||||
|
||||
const USER_STACK_SIZE: usize = 4096 * 2; // 栈大小为8kb
|
||||
const KERNEL_STACK_SIZE: usize = 4096 * 2;
|
||||
|
||||
const MAX_APP_NUM: usize = 16; // 系统最大支持的运行程序数量
|
||||
|
||||
const APP_BASE_ADDRESS: usize = 0x80400000; // 载入的app的起始的地址
|
||||
const APP_SIZE_LIMIT: usize = 0x20000; // app的最大的二进制文件能够使用的大小
|
||||
|
||||
// 在此之后应用使用UserStack, 而内核使用KernelStack, entry.asm设置的64k启动栈不再被使用
|
||||
static KERNEL_STACK: [u8; KERNEL_STACK_SIZE] = [0; KERNEL_STACK_SIZE];
|
||||
static USER_STACK: [u8; USER_STACK_SIZE] = [0; USER_STACK_SIZE];
|
||||
|
||||
lazy_static! {
|
||||
static ref APP_MANAGER: UPSafeCell<AppManager> = unsafe {
|
||||
UPSafeCell::new({
|
||||
extern "C" {
|
||||
fn _num_app();
|
||||
}
|
||||
let num_app_ptr = _num_app as usize as *const usize;
|
||||
let num_app = num_app_ptr.read_volatile(); // 用户app的总数量
|
||||
|
||||
let mut app_start_lis: [usize; MAX_APP_NUM + 1] = [0; MAX_APP_NUM + 1]; // 创建一个数组, 用来保存每个app的起始位置
|
||||
|
||||
// 得到每个app的起始地址
|
||||
let mut app_start_lis: [usize; MAX_APP_NUM + 1] = [0; MAX_APP_NUM + 1];
|
||||
let app_start_raw: &[usize] =
|
||||
core::slice::from_raw_parts(num_app_ptr.add(1), num_app + 1);
|
||||
app_start_lis[..=num_app].copy_from_slice(app_start_raw);
|
||||
|
||||
AppManager{
|
||||
num_app,
|
||||
current_app: 0,
|
||||
app_start_lis
|
||||
}
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
// 由build.rs 生成的link_app.S, 根据里面的信息生成的结构体
|
||||
struct AppManager {
|
||||
num_app: usize, // 用户app数量
|
||||
current_app: usize, // 当前需要执行的第几个app
|
||||
app_start_lis: [usize; MAX_APP_NUM + 1], // 保存了每个app的起始位置, 后面会跳到这里, +1 是因为end的位置也占了一个usize, 需要知道end的位置
|
||||
}
|
||||
|
||||
impl AppManager{
|
||||
fn show_app_info(&self){
|
||||
println!("[kernel] num_app = {}", self.num_app);
|
||||
for i in 0..self.num_app {
|
||||
println!(
|
||||
"[kernel] app_{} [{:#x}, {:#x})",
|
||||
i,
|
||||
self.app_start_lis[i],
|
||||
self.app_start_lis[i + 1]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn init() {
|
||||
APP_MANAGER.exclusive_access().show_app_info();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue