1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-25 17:33:28 +04:00

Recover fs for RV32. Add user-riscv.img

Now load user programs from SFS data linked at kernel.
This commit is contained in:
WangRunji 2018-07-14 17:41:45 +08:00
parent 019770c92d
commit c768ec3e1e
6 changed files with 36 additions and 54 deletions

View File

@ -36,7 +36,7 @@ volatile = "0.1.0"
lazy_static = { version = "1.0.0", features = ["spin_no_std"] }
bit-allocator = { path = "../crate/bit-allocator" }
ucore-memory = { path = "../crate/memory" }
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" }
[target.x86_64-blog_os.dependencies]
multiboot2 = "0.6"
@ -44,7 +44,6 @@ x86_64 = "0.2.6"
linked_list_allocator = "0.6"
redox_syscall = "0.1"
uart_16550 = "0.1"
simple-filesystem = { git = "https://github.com/wangrunji0408/SimpleFileSystem-Rust" }
[target.riscv32-blog_os.dependencies]
linked_list_allocator = "0.5" # due to rust version

View File

@ -23,10 +23,12 @@ assembly_source_files := $(wildcard $(boot_src)/*.asm)
assembly_object_files := $(patsubst $(boot_src)/%.asm, \
build/$(arch)/boot/%.o, $(assembly_source_files))
user_bin_path := ../user/target/$(arch)-ucore/debug
user_obj_path := build/$(arch)/user
user_object_files := $(patsubst $(user_bin_path)/%.d, $(user_obj_path)/%.o, $(wildcard $(user_bin_path)/*.d))
user_bins := $(patsubst $(user_bin_path)/%.d, $(user_bin_path)/%, $(wildcard $(user_bin_path)/*.d))
user_obj := build/$(arch)/user.o
SFSIMG := ../user/ucore32.img
ifeq ($(arch), x86_64)
qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio -drive file=$(SFSIMG),media=disk,cache=writeback
endif
ifeq ($(arch), riscv32)
qemu_opts := -machine virt -kernel $(iso) -nographic
endif
@ -34,9 +36,16 @@ features := use_apic
LOG ?= debug
# Link user binaries at ../user
ifdef link_user
features := $(features) link_user_program
assembly_object_files := $(assembly_object_files) $(user_object_files)
assembly_object_files := $(assembly_object_files) $(user_obj)
endif
# Link user-riscv.img for RV32
ifeq ($(arch), riscv32)
riscv_user_img_obj := build/riscv32/user-riscv.o
assembly_object_files := $(assembly_object_files) $(riscv_user_img_obj)
endif
ifdef travis
@ -143,11 +152,13 @@ build/riscv32/boot/%.o: $(boot_src)/%.asm
@mkdir -p $(shell dirname $@)
@$(as) -march=rv32i $< -o $@
# make .o from binary files
$(user_obj_path)/%.o: $(user_bin_path)/%
@mkdir -p $(user_obj_path)
# make user.o from binary files
$(user_obj): $(user_bins)
@cd $(user_bin_path) && \
$(ld) -b binary $(notdir $<) -o $(abspath $@)
$(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins)))
$(riscv_user_img_obj): ../user/user-riscv.img
@cd ../user && $(ld) -o $(abspath $@) -b binary $(notdir $<)
# patch Rust core for RISCV32I atomic
patch-core:

View File

@ -17,7 +17,7 @@ mod riscv {
pub const RECURSIVE_PAGE_PML4: usize = 0x3fe;
pub const KERNEL_OFFSET: usize = 0;
pub const KERNEL_PML4: usize = 0x8000_0000 >> 22;
pub const KERNEL_HEAP_OFFSET: usize = 0x8010_0000;
pub const KERNEL_HEAP_OFFSET: usize = 0x8020_0000;
pub const KERNEL_HEAP_SIZE: usize = 0x0010_0000;
pub const MEMORY_OFFSET: usize = 0x8000_0000;
pub const MEMORY_END: usize = 0x8080_0000;

View File

@ -1,19 +1,28 @@
use simple_filesystem::*;
use alloc::boxed::Box;
#[cfg(target_arch = "x86_64")]
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();
#[cfg(target_arch = "riscv")]
let device = {
extern {
fn _binary_user_riscv_img_start();
fn _binary_user_riscv_img_end();
}
Box::new(unsafe { MemBuf::new(_binary_user_riscv_img_start, _binary_user_riscv_img_end) })
};
#[cfg(target_arch = "x86_64")]
let device = Box::new(&ide::DISK0);
let sfs = SimpleFileSystem::open(device).unwrap();
let root = sfs.root_inode();
let files = root.borrow().list().unwrap();
trace!("Loading programs: {:?}", files);
// for name in files.iter().filter(|&f| f != "." && f != "..") {
for name in files.iter().filter(|&f| f == "sleep") {
for name in files.iter().filter(|&f| f == "hello") {
static mut BUF: [u8; 64 << 12] = [0; 64 << 12];
let file = root.borrow().lookup(name.as_str()).unwrap();
let len = file.borrow().read_at(0, unsafe { &mut BUF }).unwrap();
@ -23,24 +32,6 @@ 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_hello_start();
fn _binary_hello_size();
}
struct MemBuf(&'static [u8]);
impl MemBuf {
@ -64,6 +55,7 @@ impl Device for MemBuf {
use core::slice;
#[cfg(target_arch = "x86_64")]
impl BlockedDevice for &'static ide::DISK0 {
fn block_size_log2(&self) -> u8 {
debug_assert_eq!(ide::BLOCK_SIZE, 512);

View File

@ -37,7 +37,6 @@ extern crate once;
extern crate rlibc;
#[cfg(target_arch = "riscv")]
extern crate compiler_builtins;
#[cfg(target_arch = "x86_64")]
extern crate simple_filesystem;
extern crate spin;
extern crate ucore_memory;
@ -63,7 +62,6 @@ mod util;
mod consts;
mod process;
mod syscall;
#[cfg(target_arch = "x86_64")]
mod fs;
mod thread;
mod sync;
@ -83,27 +81,9 @@ mod arch;
pub extern fn rust_main() -> ! {
logging::init();
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();
}
}
process::init();
fs::load_sfs();
unsafe { arch::interrupt::enable(); }
loop {}
}

BIN
user/user-riscv.img Normal file

Binary file not shown.