From 4b01ff7cc448c1717593021ea80dfcf21aad81c4 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Wed, 2 Dec 2020 09:40:00 +0800 Subject: [PATCH] Build application at 0x0 in release mode. --- user/Makefile | 4 ++-- user/build.py | 25 ------------------------- user/src/lib.rs | 10 ---------- user/src/linker.ld | 4 +--- 4 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 user/build.py diff --git a/user/Makefile b/user/Makefile index eabb4b27..5e0f87c3 100644 --- a/user/Makefile +++ b/user/Makefile @@ -1,5 +1,5 @@ TARGET := riscv64gc-unknown-none-elf -MODE := debug +MODE := release APP_DIR := src/bin TARGET_DIR := target/$(TARGET)/$(MODE) APPS := $(wildcard $(APP_DIR)/*.rs) @@ -10,7 +10,7 @@ OBJDUMP := rust-objdump --arch-name=riscv64 OBJCOPY := rust-objcopy --binary-architecture=riscv64 elf: $(APPS) - @python3 build.py + @cargo build --release binary: elf $(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf));) diff --git a/user/build.py b/user/build.py deleted file mode 100644 index 1a220881..00000000 --- a/user/build.py +++ /dev/null @@ -1,25 +0,0 @@ -import os - -base_address = 0x80100000 -step = 0x20000 -linker = 'src/linker.ld' - -app_id = 0 -apps = os.listdir('src/bin') -apps.sort() -for app in apps: - app = app[:app.find('.')] - lines = [] - lines_before = [] - with open(linker, 'r') as f: - for line in f.readlines(): - lines_before.append(line) - line = line.replace(hex(base_address), hex(base_address+step*app_id)) - lines.append(line) - with open(linker, 'w+') as f: - f.writelines(lines) - os.system('cargo build --bin %s' % app) - print('[build.py] application %s start with address %s' %(app, hex(base_address+step*app_id))) - with open(linker, 'w+') as f: - f.writelines(lines_before) - app_id = app_id + 1 diff --git a/user/src/lib.rs b/user/src/lib.rs index fdcb6d56..c072ef49 100644 --- a/user/src/lib.rs +++ b/user/src/lib.rs @@ -11,7 +11,6 @@ mod lang_items; #[no_mangle] #[link_section = ".text.entry"] pub extern "C" fn _start() -> ! { - clear_bss(); syscall::sys_exit(main()); panic!("unreachable after sys_exit!"); } @@ -22,14 +21,5 @@ fn main() -> i32 { panic!("Cannot find main!"); } -fn clear_bss() { - extern "C" { - fn start_bss(); - fn end_bss(); - } - (start_bss as usize..end_bss as usize).for_each(|addr| { - unsafe { (addr as *mut u8).write_volatile(0); } - }); -} pub use syscall::*; \ No newline at end of file diff --git a/user/src/linker.ld b/user/src/linker.ld index 1c64a19b..db314ce3 100644 --- a/user/src/linker.ld +++ b/user/src/linker.ld @@ -2,7 +2,7 @@ OUTPUT_ARCH(riscv) ENTRY(_start) -BASE_ADDRESS = 0x80100000; +BASE_ADDRESS = 0x0; SECTIONS { @@ -18,9 +18,7 @@ SECTIONS *(.data .data.*) } .bss : { - start_bss = .; *(.bss .bss.*) - end_bss = .; } /DISCARD/ : { *(.eh_frame)