mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2025-01-18 21:17:14 +04:00
Working on app data auto linking.
This commit is contained in:
parent
d1fcf2fc9f
commit
f613fa122c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
.idea/*
|
||||
os/target/*
|
||||
os/.idea/*
|
||||
os/src/link_app.S
|
||||
user/target/*
|
||||
user/.idea/*
|
34
os/build.rs
Normal file
34
os/build.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use std::io::{Result, Write};
|
||||
use std::fs::{File, read_dir};
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=../user");
|
||||
insert_app_data().unwrap();
|
||||
}
|
||||
|
||||
static TARGET_PATH: &'static str = "../user/target/riscv64gc-unknown-none-elf/release/";
|
||||
|
||||
fn insert_app_data() -> Result<()> {
|
||||
let mut f = File::create("src/link_app.S").unwrap();
|
||||
let apps: Vec<_> = read_dir("../user/src/bin")
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|dir_entry| {
|
||||
let mut name_with_ext = dir_entry.unwrap().file_name().into_string().unwrap();
|
||||
name_with_ext.drain(name_with_ext.find('.').unwrap()..name_with_ext.len());
|
||||
name_with_ext
|
||||
})
|
||||
.collect();
|
||||
|
||||
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}"
|
||||
app_{0}_end:
|
||||
"#, idx, app_with_extension, TARGET_PATH)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
@ -8,9 +8,11 @@
|
||||
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" {
|
||||
@ -25,23 +27,11 @@ fn clear_bss() {
|
||||
#[no_mangle]
|
||||
pub fn rust_main() -> ! {
|
||||
extern "C" {
|
||||
fn stext();
|
||||
fn etext();
|
||||
fn srodata();
|
||||
fn erodata();
|
||||
fn sdata();
|
||||
fn edata();
|
||||
fn sbss();
|
||||
fn ebss();
|
||||
fn boot_stack();
|
||||
fn boot_stack_top();
|
||||
fn app_0_start();
|
||||
fn app_0_end();
|
||||
};
|
||||
clear_bss();
|
||||
println!("Hello, world!");
|
||||
println!(".text [{:#x}, {:#x})", stext as usize, etext as usize);
|
||||
println!(".rodata [{:#x}, {:#x})", srodata as usize, erodata as usize);
|
||||
println!(".data [{:#x}, {:#x})", sdata as usize, edata as usize);
|
||||
println!("boot_stack [{:#x}, {:#x})", boot_stack as usize, boot_stack_top as usize);
|
||||
println!(".bss [{:#x}, {:#x})", sbss as usize, ebss as usize);
|
||||
println!("app_0 [{:#x}, {:#x})", app_0_start as usize, app_0_end as usize);
|
||||
panic!("Shutdown machine!");
|
||||
}
|
2
os/src/syscall/mod.rs
Normal file
2
os/src/syscall/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
const SYSCALL_WRITE: usize = 64;
|
||||
|
0
os/src/trap.rs
Normal file
0
os/src/trap.rs
Normal file
17
user/Makefile
Normal file
17
user/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
TARGET := riscv64gc-unknown-none-elf
|
||||
MODE := release
|
||||
APP_DIR := src/bin
|
||||
TARGET_DIR := target/$(TARGET)/$(MODE)
|
||||
ELFS := $(patsubst $(APP_DIR)/*.rs, $(TARGET_DIR)/*, $(wildcard $(APP_DIR)/*.rs))
|
||||
BINS := $(patsubst $(APP_DIR)/*.rs, $(TARGET_DIR)/*.bin, $(wildcard $(APP_DIR)/*.rs))
|
||||
|
||||
OBJDUMP := rust-objdump --arch-name=riscv64
|
||||
OBJCOPY := rust-objcopy --binary-architecture=riscv64
|
||||
|
||||
elf:
|
||||
@cargo build --release
|
||||
|
||||
binary: elf
|
||||
$(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/*, $(TARGET_DIR)/*.bin, $(elf)))
|
||||
|
||||
build: binary
|
Loading…
Reference in New Issue
Block a user