Auto link multiple applications in kernel.

This commit is contained in:
Yifan Wu 2020-11-19 04:33:06 +08:00
parent 1943a50d0d
commit 220397e5a5
5 changed files with 64 additions and 9 deletions

View file

@ -2,16 +2,20 @@ 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))
APPS := $(wildcard $(APP_DIR)/*.rs)
ELFS := $(patsubst $(APP_DIR)/%.rs, $(TARGET_DIR)/%, $(APPS))
BINS := $(patsubst $(APP_DIR)/%.rs, $(TARGET_DIR)/%.bin, $(APPS))
OBJDUMP := rust-objdump --arch-name=riscv64
OBJCOPY := rust-objcopy --binary-architecture=riscv64
elf:
@cargo build --release
@echo $(APPS)
@echo $(ELFS)
@echo $(BINS)
binary: elf
$(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/*, $(TARGET_DIR)/*.bin, $(elf)))
$(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf));)
build: binary

27
user/src/bin/power.rs Normal file
View file

@ -0,0 +1,27 @@
#![no_std]
#![no_main]
#[macro_use]
extern crate user_lib;
const SIZE: usize = 10;
const P: u32 = 3;
const STEP: usize = 10000000;
const MOD: u32 = 10007;
#[no_mangle]
fn main() -> i32 {
let mut pow = [0u32; SIZE];
let mut index: usize = 0;
pow[index] = 1;
for i in 1..=STEP {
let last = pow[index];
index = (index + 1) % SIZE;
pow[index] = last * P % MOD;
if i % 10000 == 0 {
println!("{}^{}={}", P, i, pow[index]);
}
}
println!("Test power OK!");
0
}