Fix linking user program binaries

master
WangRunji 6 years ago
parent ee80a3eeb7
commit c0138c4c35

@ -22,8 +22,9 @@ grub_cfg := $(boot_src)/grub.cfg
assembly_source_files := $(wildcard $(boot_src)/*.asm)
assembly_object_files := $(patsubst $(boot_src)/%.asm, \
build/arch/$(arch)/boot/%.o, $(assembly_source_files))
user_image_files := $(wildcard ../user/*.img)
user_object_files := $(patsubst ../user/%.img, build/user/%.o, $(user_image_files))
user_bin_path := ../user/target/$(arch)-ucore/debug
user_obj_path := build/arch/$(arch)/user
user_object_files := $(patsubst $(user_bin_path)/%.d, $(user_obj_path)/%.o, $(wildcard $(user_bin_path)/*.d))
SFSIMG := ../user/ucore32.img
qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback
ifeq ($(arch), riscv32)
@ -103,6 +104,9 @@ build: iso
asm:
@$(objdump) -dS $(kernel) | less
elf-h:
@$(objdump) -h $(kernel)
build/os-x86_64.iso: $(kernel) $(grub_cfg)
@mkdir -p build/isofiles/boot/grub
@cp $(kernel) build/isofiles/boot/kernel.bin
@ -139,10 +143,11 @@ build/arch/riscv32/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@)
@$(as) -march=rv32i $< -o $@
# make .o from .img file
build/user/%.o: ../user/%.img
@mkdir -p $(shell dirname $@)
@$(ld) -r -b binary $< -o $@
# make .o from binary files
$(user_obj_path)/%.o: $(user_bin_path)/%
@mkdir -p $(user_obj_path)
@cd $(user_bin_path) && \
$(ld) -b binary $(notdir $<) -o $(abspath $@)
# patch Rust core for RISCV32I atomic
patch-core:

@ -4,6 +4,7 @@ use arch::driver::ide;
use spin::Mutex;
use process;
#[cfg(not(feature = "link_user_program"))]
pub fn load_sfs() {
// let slice = unsafe { MemBuf::new(_binary_user_ucore32_img_start, _binary_user_ucore32_img_end) };
let sfs = SimpleFileSystem::open(Box::new(&ide::DISK0)).unwrap();
@ -22,12 +23,22 @@ pub fn load_sfs() {
process::print();
}
#[cfg(feature = "link_user_program")]
pub fn load_sfs() {
let slice = unsafe {
slice::from_raw_parts(_binary_hello_start as *const u8,
_binary_hello_size as usize)
};
process::add_user_process("hello", slice);
process::print();
}
#[cfg(feature = "link_user_program")]
extern {
fn _binary_user_ucore32_img_start();
fn _binary_user_ucore32_img_end();
fn _binary_user_xv6_64_img_start();
fn _binary_user_xv6_64_img_end();
fn _binary_hello_start();
fn _binary_hello_size();
}
struct MemBuf(&'static [u8]);

@ -82,6 +82,25 @@ pub extern fn rust_main() -> ! {
arch::init();
process::init();
info!("RISCV init end");
#[cfg(feature = "link_user_program")]
{
use core::slice;
let slice = unsafe {
slice::from_raw_parts(_binary_hello_start as *const u8,
_binary_hello_size as usize)
};
process::add_user_process("hello", slice);
process::print();
extern {
fn _binary_hello_start();
fn _binary_hello_size();
}
}
unsafe { arch::interrupt::enable(); }
loop {}
}

Loading…
Cancel
Save