Auto link multiple applications in kernel.
This commit is contained in:
parent
f613fa122c
commit
0d0c7255b6
5 changed files with 64 additions and 9 deletions
19
os/build.rs
19
os/build.rs
|
@ -20,13 +20,30 @@ fn insert_app_data() -> Result<()> {
|
|||
})
|
||||
.collect();
|
||||
|
||||
writeln!(f, r#"
|
||||
.align 4
|
||||
.section .data
|
||||
.global _num_app
|
||||
_num_app:
|
||||
.quad {}
|
||||
"#, apps.len())?;
|
||||
|
||||
for i in 0..apps.len() {
|
||||
writeln!(f, r#"
|
||||
.quad app_{}_start
|
||||
"#, i)?;
|
||||
}
|
||||
writeln!(f, r#"
|
||||
.quad app_{}_end
|
||||
"#, apps.len() - 1)?;
|
||||
|
||||
for (idx, app_with_extension) in apps.iter().enumerate() {
|
||||
writeln!(f, r#"
|
||||
.section .data
|
||||
.global app_{0}_start
|
||||
.global app_{0}_end
|
||||
app_{0}_start:
|
||||
.incbin "{2}{1}"
|
||||
.incbin "{2}{1}.bin"
|
||||
app_{0}_end:
|
||||
"#, idx, app_with_extension, TARGET_PATH)?;
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
nightly-2020-11-01
|
|
@ -26,12 +26,19 @@ fn clear_bss() {
|
|||
|
||||
#[no_mangle]
|
||||
pub fn rust_main() -> ! {
|
||||
extern "C" {
|
||||
fn app_0_start();
|
||||
fn app_0_end();
|
||||
};
|
||||
clear_bss();
|
||||
println!("Hello, world!");
|
||||
println!("app_0 [{:#x}, {:#x})", app_0_start as usize, app_0_end as usize);
|
||||
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!");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue