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

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

@ -82,6 +82,25 @@ pub extern fn rust_main() -> ! {
arch::init(); arch::init();
process::init(); process::init();
info!("RISCV init end"); 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(); } unsafe { arch::interrupt::enable(); }
loop {} loop {}
} }

Loading…
Cancel
Save