diff --git a/arch/Cargo.toml b/arch/Cargo.toml index 3a00f60..a795469 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -39,3 +39,4 @@ arm_gic = { git = "https://github.com/Byte-OS/arm_gic" } [target.'cfg(target_arch = "loongarch64")'.dependencies] spin = { version = "0.9.8", features = ["mutex"] } loongarch64 = {git = "https://github.com/Godones/loongArch64",package = "loongArch64" } +volatile = "0.3" diff --git a/arch/src/loongarch64/console.rs b/arch/src/loongarch64/console.rs index 19a3daa..32fa47e 100644 --- a/arch/src/loongarch64/console.rs +++ b/arch/src/loongarch64/console.rs @@ -4,9 +4,74 @@ use spin::Mutex; use crate::VIRT_ADDR_START; -const UART_ADDR: usize = 0x01FE001E0 | VIRT_ADDR_START; +const UART_ADDR: usize = 0x1fe001e0 | VIRT_ADDR_START; static COM1: Mutex = Mutex::new(Uart::new(UART_ADDR)); +use bitflags::*; +use volatile::{ReadOnly, Volatile, WriteOnly}; + +bitflags! { + #[derive(Copy, Clone)] + /// InterruptEnableRegister + pub struct IER: u8 { + const RX_AVAILABLE = 1 << 0; + const TX_EMPTY = 1 << 1; + } + #[derive(Copy, Clone)] + /// LineStatusRegister + pub struct LSR: u8 { + const DATA_AVAILABLE = 1 << 0; + const THR_EMPTY = 1 << 5; + } + #[derive(Copy, Clone)] + /// Model Control Register + pub struct MCR: u8 { + const DATA_TERMINAL_READY = 1 << 0; + const REQUEST_TO_SEND = 1 << 1; + const AUX_OUTPUT1 = 1 << 2; + const AUX_OUTPUT2 = 1 << 3; + } +} + +#[repr(C)] +#[allow(dead_code)] +struct ReadWithoutDLAB { + /// receiver buffer register + pub rbr: ReadOnly, + /// interrupt enable register + pub ier: Volatile, + /// interrupt identification register + pub iir: ReadOnly, + /// line control register + pub lcr: Volatile, + /// model control register + pub mcr: Volatile, + /// line status register + pub lsr: ReadOnly, + /// ignore MSR + _padding1: ReadOnly, + /// ignore SCR + _padding2: ReadOnly, +} + +#[repr(C)] +#[allow(dead_code)] +struct WriteWithoutDLAB { + /// transmitter holding register + pub thr: WriteOnly, + /// interrupt enable register + pub ier: Volatile, + /// ignore FCR + _padding0: ReadOnly, + /// line control register + pub lcr: Volatile, + /// modem control register + pub mcr: Volatile, + /// line status register + pub lsr: ReadOnly, + /// ignore other registers + _padding1: ReadOnly, +} pub struct Uart { base_address: usize, @@ -16,31 +81,43 @@ impl Uart { pub const fn new(base_address: usize) -> Self { Uart { base_address } } + fn read_end(&mut self) -> &mut ReadWithoutDLAB { + unsafe { &mut *(self.base_address as *mut ReadWithoutDLAB) } + } + + fn write_end(&mut self) -> &mut WriteWithoutDLAB { + unsafe { &mut *(self.base_address as *mut WriteWithoutDLAB) } + } + + pub fn init(&mut self) { + let read_end = self.read_end(); + let mut mcr = MCR::empty(); + mcr |= MCR::DATA_TERMINAL_READY; + mcr |= MCR::REQUEST_TO_SEND; + mcr |= MCR::AUX_OUTPUT2; + read_end.mcr.write(mcr); + let ier = IER::RX_AVAILABLE; + read_end.ier.write(ier); + } pub fn putchar(&mut self, c: u8) { - let ptr = self.base_address as *mut u8; + let write_end = self.write_end(); loop { - unsafe { - let c = ptr.add(5).read_volatile(); - if c & (1 << 5) != 0 { - break; - } + if write_end.lsr.read().contains(LSR::THR_EMPTY) { + write_end.thr.write(c); + break; } } - unsafe { - ptr.add(0).write_volatile(c); - } } pub fn getchar(&mut self) -> Option { - let ptr = self.base_address as *mut u8; + let read_end = self.read_end(); + let lsr = read_end.lsr.read(); unsafe { - if ptr.add(5).read_volatile() & 1 == 0 { - // The DR bit is 0, meaning no data - None - } else { - // The DR bit is 1, meaning data! - Some(ptr.add(0).read_volatile()) + if lsr.contains(LSR::DATA_AVAILABLE) {// The DR bit is 1, meaning data! + Some(read_end.rbr.read()) + } else { // The DR bit is 0, meaning no data + None } } } @@ -63,3 +140,7 @@ pub fn console_putchar(c: u8) { pub fn console_getchar() -> Option { COM1.lock().getchar() } +/// +pub fn console_init(){ + COM1.lock().init(); +} diff --git a/arch/src/loongarch64/mod.rs b/arch/src/loongarch64/mod.rs index 602d1b3..07aaf5f 100644 --- a/arch/src/loongarch64/mod.rs +++ b/arch/src/loongarch64/mod.rs @@ -9,7 +9,7 @@ mod sigtrx; mod timer; mod trap; -pub use console::{console_getchar, console_putchar}; +pub use console::{console_getchar, console_putchar,console_init}; pub use consts::*; pub use context::TrapFrame; #[cfg(feature = "kcontext")] @@ -23,6 +23,7 @@ use crate::clear_bss; pub fn rust_tmp_main(hart_id: usize) { clear_bss(); + console_init(); ArchInterface::init_logging(); ArchInterface::init_allocator(); trap::set_trap_vector_base(); diff --git a/config/src/lib.rs b/config/src/lib.rs index 03f5eaf..5444b8f 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -7,8 +7,10 @@ pub const USER_STACK_SIZE: usize = 4096 * 20; pub const KERNEL_STACK_SIZE: usize = 4096 *10; pub const KERNEL_HEAP_SIZE: usize = 0x300_0000; -pub const USER_STACK_TOP: usize = 0x8000_0000; -pub const USER_MMAP_TOP: usize = 0x6000_0000; +pub const USER_STACK_TOP: usize = 0x13_0000_0000; +pub const USER_MMAP_TOP: usize = 0x11_0000_0000; + +pub const DL_INTERP_OFFSET: usize = 0x15_0000_0000; pub const MAX_FD:usize = 1024; //pub const PAGE_SIZE: usize = 0x1000; diff --git a/ext4-fs-fuse/src/main.rs b/ext4-fs-fuse/src/main.rs index c0f3bd7..612dee1 100644 --- a/ext4-fs-fuse/src/main.rs +++ b/ext4-fs-fuse/src/main.rs @@ -115,11 +115,8 @@ fn easy_fs_pack() -> std::io::Result<()> { // write data to ext4 sb.ext4fs.ext4_file_write(inode as u64, 0, all_data.as_slice()); } + println!("app:----"); - /* list apps - for app in root_dentry.clone().ls() { - println!("{}", app); - }*/ drop(root_dentry); block_cache_sync_all(); Ok(()) diff --git a/ext4-test-fuse/src/main.rs b/ext4-test-fuse/src/main.rs index efb6af5..7e22498 100644 --- a/ext4-test-fuse/src/main.rs +++ b/ext4-test-fuse/src/main.rs @@ -6,7 +6,7 @@ use std::mem; use std::io::{Read, Seek, SeekFrom, Write}; use std::sync::{Arc, Once}; use std::sync::Mutex; -use vfs_defs::{Dentry, DentryState, DiskInodeType, File as OtherFile, FileInner, FileSystemType, SuperBlock, SuperBlockInner,OpenFlags}; +use vfs_defs::{dcache_drop, dcache_lookup, Dentry, DentryState, DiskInodeType, File as OtherFile, FileInner, FileSystemType, OpenFlags, SuperBlock, SuperBlockInner,dcache_sync_call}; use system_result::{SysError,SysResult}; use device::BlockDevice; use buffer::block_cache_sync_all; @@ -51,10 +51,11 @@ impl BlockDevice for BlockFile { } fn main() { - easy_fs_pack().expect("Error when packing ext4!"); + easy_fs_pack().expect("Error when packing ext4!"); +//rv_pack().expect("Error when packing ext4!"); } - -fn easy_fs_pack() -> std::io::Result<()> { + +fn rv_pack() -> std::io::Result<()> { let matches = App::new("Ext4 packer") .arg( Arg::with_name("source") @@ -100,21 +101,137 @@ fn easy_fs_pack() -> std::io::Result<()> { name_with_ext }) .collect(); - - { let mnt = root_dentry.create("mnt",DiskInodeType::Directory).unwrap(); - let mut host_file = File::open(format!("{}{}", src_path, "mnt/test_mount")).unwrap(); + + + for app in apps { + // load app data from host file system + println!("{}",app); + if app != String::from("user_shell"){ + continue; + } + let mut host_file = File::open(format!("{}{}", src_path, app)).unwrap(); let mut all_data: Vec = Vec::new(); host_file.read_to_end(&mut all_data).unwrap(); // create a file in ext4 - let den =mnt.create("test_mount",DiskInodeType::File).unwrap(); + let den =root_dentry.create(app.as_str(),DiskInodeType::File).unwrap(); let inode = den.get_inode().unwrap().get_meta().ino; // write data to ext4 sb.ext4fs.ext4_file_write(inode as u64, 0, all_data.as_slice()); } + { + let mut host_file = File::open(format!("{}{}", target_path, "initproc")).unwrap(); + let mut all_data: Vec = Vec::new(); + host_file.read_to_end(&mut all_data).unwrap(); + // create a file in ext4 + let den =root_dentry.create("initproc",DiskInodeType::File).unwrap(); + let inode = den.get_inode().unwrap().get_meta().ino; + // write data to ext4 + sb.ext4fs.ext4_file_write(inode as u64, 0, all_data.as_slice()); + } + println!("app:----"); + drop(root_dentry); + dcache_sync_call(); + dcache_drop(); + block_cache_sync_all(); + Ok(()) +} + + +fn easy_fs_pack() -> std::io::Result<()> { + let matches = App::new("Ext4 packer") + .arg( + Arg::with_name("source") + .short("s") + .long("source") + .takes_value(true) + .help("Executable source dir(with backslash)"), + ) + .arg( + Arg::with_name("target") + .short("t") + .long("target") + .takes_value(true) + .help("Executable target dir(with backslash)"), + ) + .get_matches(); + let src_path = matches.value_of("source").unwrap(); + let target_path = matches.value_of("target").unwrap(); + println!("src_path = {}\ntarget_path = {}", src_path, target_path); + let block_file = Arc::new(BlockFile(Mutex::new({ + let f = OpenOptions::new() + .read(true) + .write(true) + .create(true) + // .open("ext4.img")?; + .open(format!("{}{}", target_path, "fs.img"))?; + f.set_len(8192 * 1024 * 1024).unwrap(); + f + }))); + + + device::BLOCK_DEVICE.call_once(||block_file); + logger::init_logger(); + vfs::init(); + let root_dentry = get_root_dentry(); + let sb = root_dentry.get_superblock().downcast_arc::().map_err(|_| SysError::ENOENT).unwrap(); + let apps: Vec<_> = read_dir(src_path) + .unwrap() + .into_iter() + .map(|dir_entry| { + let mut name_with_ext = dir_entry.unwrap().file_name().into_string().unwrap(); + // name_with_ext.drain(name_with_ext.find('.').unwrap()..name_with_ext.len()); + name_with_ext + }) + .collect(); + let mnt = root_dentry.create("mnt",DiskInodeType::Directory).unwrap(); + let lib = root_dentry.create("lib",DiskInodeType::Directory).unwrap(); + + let mntapps: Vec<_> = read_dir(format!("{}{}", src_path, "mnt/")) + .unwrap() + .into_iter() + .map(|dir_entry| { + let mut name_with_ext = dir_entry.unwrap().file_name().into_string().unwrap(); + // name_with_ext.drain(name_with_ext.find('.').unwrap()..name_with_ext.len()); + name_with_ext + }) + .collect(); + let libapps: Vec<_> = read_dir(format!("{}{}", src_path, "lib/")) + .unwrap() + .into_iter() + .map(|dir_entry| { + let mut name_with_ext = dir_entry.unwrap().file_name().into_string().unwrap(); + // name_with_ext.drain(name_with_ext.find('.').unwrap()..name_with_ext.len()); + name_with_ext + }) + .collect(); + for app in mntapps { + // load app data from host file system + println!("{}",app); + let mut host_file = File::open(format!("{}{}{}", src_path,"mnt/", app)).unwrap(); + let mut all_data: Vec = Vec::new(); + host_file.read_to_end(&mut all_data).unwrap(); + // create a file in ext4 + let den =mnt.create(app.as_str(),DiskInodeType::File).unwrap(); + let inode = den.get_inode().unwrap().get_meta().ino; + // write data to ext4 + sb.ext4fs.ext4_file_write(inode as u64, 0, all_data.as_slice()); + } + for app in libapps { + // load app data from host file system + println!("{}",app); + let mut host_file = File::open(format!("{}{}{}", src_path,"lib/", app)).unwrap(); + let mut all_data: Vec = Vec::new(); + host_file.read_to_end(&mut all_data).unwrap(); + // create a file in ext4 + let den =lib.create(app.as_str(),DiskInodeType::File).unwrap(); + let inode = den.get_inode().unwrap().get_meta().ino; + // write data to ext4 + sb.ext4fs.ext4_file_write(inode as u64, 0, all_data.as_slice()); + } for app in apps { // load app data from host file system println!("{}",app); - if app == String::from("mnt"){ + if app == String::from("mnt") || app == String::from("lib"){ continue; } let mut host_file = File::open(format!("{}{}", src_path, app)).unwrap(); @@ -127,7 +244,11 @@ fn easy_fs_pack() -> std::io::Result<()> { sb.ext4fs.ext4_file_write(inode as u64, 0, all_data.as_slice()); } println!("app:----"); + drop(mnt); + drop(lib); drop(root_dentry); - block_cache_sync_all(); + dcache_sync_call(); + dcache_drop(); + block_cache_sync_all(); Ok(()) } \ No newline at end of file diff --git a/ext4/src/dentry.rs b/ext4/src/dentry.rs index a831daa..46df64d 100644 --- a/ext4/src/dentry.rs +++ b/ext4/src/dentry.rs @@ -8,7 +8,7 @@ use crate::file::Ext4ImplFile; use ext4_rs::*; use super::Ext4Inode; -const MODULE_LEVEL:log::Level = log::Level::Trace; +const MODULE_LEVEL:log::Level = log::Level::Debug; pub const EXT_MAX_BLOCKS: u32 = u32::MAX; pub struct Ext4Dentry{ inner:DentryInner @@ -29,14 +29,13 @@ impl Dentry for Ext4Dentry{ } fn concrete_create(self: Arc, name: &str, _type:DiskInodeType) -> SysResult> { let sblock = self.get_superblock().downcast_arc::().map_err(|_| SysError::ENOENT)?; - let mut inode_num = self.get_inode()?.downcast_arc::().map_err(|_| SysError::ENOENT)?.get_meta().ino as u32; let child_dir = self.get_child(name).unwrap(); let path = child_dir.path(); let child_ino; match _type{ DiskInodeType::File=>{ //child_ino = sblock.ext4fs.ext4_file_open( path.as_str(), "w+"); - child_ino = sblock.ext4fs.generic_open( path.as_str(),&mut inode_num,true,InodeFileType::S_IFREG.bits(),&mut 0 ); + child_ino = sblock.ext4fs.generic_open( path.as_str(),&mut 2,true,InodeFileType::S_IFREG.bits(),&mut 0 ); } DiskInodeType::Directory=>{ child_ino = sblock.ext4fs.ext4_dir_mk(path.as_str()); @@ -94,15 +93,19 @@ impl Dentry for Ext4Dentry{ } fn concrete_lookup(self: Arc, name: &str) -> SysResult> { let sblock = self.get_superblock().downcast_arc::().map_err(|_| SysError::ENOENT)?; + let mut ino = self.get_inode().unwrap().get_meta().ino as u32; let child = self.get_child(name).unwrap(); let path = child.path(); - let r; + let mut r; r = sblock.ext4fs.ext4_dir_open(path.as_str()); - if let Err(e) = r { - return match e.error() { - Errno::ENOENT => Err(SysError::ENOENT), - Errno::EINVAL => Err(SysError::EINVAL), - _ => Err(SysError::EINVAL), + if let Err(_e) = r { + r = sblock.ext4fs.generic_open(path.as_str(), &mut ino, false, 0, &mut 0); + if let Err(e) = r { + return match e.error() { + Errno::ENOENT => Err(SysError::ENOENT), + Errno::EINVAL => Err(SysError::EINVAL), + _ => Err(SysError::EINVAL), + } } } let inode_ref = sblock.ext4fs.get_inode_ref(r.unwrap()); diff --git a/os/Cargo.toml b/os/Cargo.toml index 89ab9cb..54225b9 100644 --- a/os/Cargo.toml +++ b/os/Cargo.toml @@ -16,7 +16,7 @@ virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "61 easy-fs = { path = "../easy-fs" } ext4 = { path = "../ext4" } log = "0.4" -sbi-rt = { version = "0.0.2", features = ["legacy"] } +#sbi-rt = { version = "0.0.2", features = ["legacy"] } spin = "0.7.0" volatile = "0.3" vfs-defs = { path = "../vfs-defs" } @@ -31,6 +31,7 @@ fdt = "0.1.5" # user_lib = {path="../user"} logger = { path = "../logger" } +sync = { path = "../sync" } [profile.release] debug = true diff --git a/os/Makefile b/os/Makefile index 1fc5931..cfe7cee 100644 --- a/os/Makefile +++ b/os/Makefile @@ -32,7 +32,8 @@ MODE := release KERNEL_ELF := target/$(TARGET)/$(MODE)/os KERNEL_BIN := $(KERNEL_ELF).bin DISASM_TMP := target/$(TARGET)/$(MODE)/asm -FS_IMG := ../user/target/$(TARGET)/$(MODE)/fs.img +#FS_IMG := ../user/target/$(TARGET)/$(MODE)/fs.img +FS_IMG := ../user/target/riscv64gc-unknown-none-elf/$(MODE)/fs.img APPS := ../user/src/bin/* # BOARD @@ -62,6 +63,8 @@ build: env $(KERNEL_BIN) fs-img testbuild: env $(KERNEL_BIN) test-fs-img +rvtestbuild: env $(KERNEL_BIN) rvtest-fs-img + env: (rustup target list | grep "riscv64gc-unknown-none-elf (installed)") || rustup target add $(TARGET) cargo install cargo-binutils @@ -72,7 +75,7 @@ $(KERNEL_BIN): kernel @$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@ fs-img: $(APPS) - @cd ../user && make build TEST=$(TEST) + @cd ../user && make build TARGET=$(TARGET) TEST=$(TEST) @rm -f $(FS_IMG) @dd if=/dev/zero of=$(FS_IMG) bs=1M count=512 @mkfs.ext4 $(FS_IMG) @@ -81,10 +84,18 @@ fs-img: $(APPS) # @cd ../easy-fs-fuse && cargo run --release -- -s ../user/src/bin/ -t ../user/target/riscv64gc-unknown-none-elf/release/ test-fs-img: $(APPS) - @cd ../user && make build TEST=$(TEST) +# @cd ../user && make build TEST=$(TEST) @rm -f $(FS_IMG) @dd if=/dev/zero of=$(FS_IMG) bs=1M count=512 @mkfs.ext4 $(FS_IMG) +# @cd ../ext4-fs-fuse && cargo run -- -s ../user/src/bin/ -t ../user/target/riscv64gc-unknown-none-elf/release/ + @cd ../ext4-test-fuse && cargo run -- -s ../testcase/basic/$(TARGET)/ -t ../user/target/riscv64gc-unknown-none-elf/release/ +# @cd ../easy-fs-fuse && cargo run --release -- -s ../user/src/bin/ -t ../user/target/riscv64gc-unknown-none-elf/release/ + +rvtest-fs-img: $(APPS) +# @cd ../user && make build TEST=$(TEST) + @rm -f $(FS_IMG) + @cp ../sdcard-rv.img $(FS_IMG) # @cd ../ext4-fs-fuse && cargo run -- -s ../user/src/bin/ -t ../user/target/riscv64gc-unknown-none-elf/release/ @cd ../ext4-test-fuse && cargo run -- -s ../testcase/basic/riscv64/ -t ../user/target/riscv64gc-unknown-none-elf/release/ # @cd ../easy-fs-fuse && cargo run --release -- -s ../user/src/bin/ -t ../user/target/riscv64gc-unknown-none-elf/release/ @@ -115,6 +126,8 @@ run: run-inner test: test-run-inner +rvtest: rvtest-run-inner + #QEMU_ARGS := -machine virt \ # -nographic \ # -bios $(BOOTLOADER) \ @@ -139,6 +152,9 @@ run-inner: build test-run-inner: testbuild $(QEMU_EXEC) +rvtest-run-inner: rvtestbuild + $(QEMU_EXEC) + #debug: qemu-version-check build # @tmux new-session -d \ "qemu-system-riscv64 $(QEMU_ARGS) -s -S" && \ @@ -167,4 +183,8 @@ test-gdbserver: testbuild gdbclient: @riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234' +lagdbclient: + @loongarch64-linux-gnu-gdb -ex 'file $(KERNEL_ELF)' -ex 'target remote localhost:1234' + + .PHONY: build env kernel clean disasm disasm-vim run-inner fs-img gdbserver gdbclient qemu-version-check test-run-inner testbuild test-fs-img diff --git a/os/ls2k_debug.sh b/os/ls2k_debug.sh new file mode 100644 index 0000000..88a831d --- /dev/null +++ b/os/ls2k_debug.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# 通常情况下该文件应当放在项目的根目录下 + +RUNENV_PREFIX=~/qemu-bin-9.2.1/bin +KERNEL_PREFIX=`pwd` + +cd $RUNENV_PREFIX + +./qemu-system-loongarch64 \ + -M virt, \ + -kernel /home/pierrecashon/rustcomp/os/target/loongarch64-unknown-none/release/os -m 1G -nographic -smp 1 -drive file=~/rustcomp/user/target/riscv64gc-unknown-none-elf/release/fs.img,if=none,format=raw,id=x0 \ + -device virtio-blk-pci,drive=x0 \ + -rtc base=utc +# -S -s + + + #-S -s + #-hdb ~/rcore-tutorial-v3-with-hal-component/user/target/loongarch64-unknown-none/release/fs.img diff --git a/os/src/drivers/block/mod.rs b/os/src/drivers/block/mod.rs index bcf9d30..75be8d8 100644 --- a/os/src/drivers/block/mod.rs +++ b/os/src/drivers/block/mod.rs @@ -1,5 +1,5 @@ -#[cfg(any(target_arch = "x86_64", target_arch = "loongarch64"))] -mod ram_blk; +//#[cfg(any(target_arch = "x86_64", target_arch = "loongarch64"))] +mod pci_virtio_blk; #[cfg(any(target_arch = "riscv64", target_arch = "aarch64"))] mod virtio_blk; @@ -11,7 +11,7 @@ use device::BlockDevice; use lazy_static::*; #[cfg(any(target_arch = "x86_64", target_arch = "loongarch64"))] -use ram_blk::RamDiskBlock; +pub use pci_virtio_blk::VirtIOBlock; #[cfg(any(target_arch = "riscv64", target_arch = "aarch64"))] lazy_static! { @@ -20,7 +20,7 @@ lazy_static! { #[cfg(any(target_arch = "x86_64", target_arch = "loongarch64"))] lazy_static! { - pub static ref BLOCK_DEVICE: Arc = Arc::new(RamDiskBlock::new()); + pub static ref BLOCK_DEVICE: Arc = Arc::new(VirtIOBlock::new()); } #[allow(unused)] pub fn block_device_test() { diff --git a/os/src/drivers/block/pci_virtio_blk.rs b/os/src/drivers/block/pci_virtio_blk.rs new file mode 100644 index 0000000..98448c0 --- /dev/null +++ b/os/src/drivers/block/pci_virtio_blk.rs @@ -0,0 +1,220 @@ +use core::ptr::NonNull; + +use super::BlockDevice; +use crate::mm::{frame_alloc, frame_dealloc, FrameTracker}; +use spin::Mutex; +use alloc::vec::{self, Vec}; +use arch::addr::{PhysAddr, PhysPage}; +use arch::VIRT_ADDR_START; +use lazy_static::*; +use virtio_drivers::transport::pci::bus::{BarInfo, Cam, Command, DeviceFunction, MemoryBarType, PciRoot}; +//use log::debug; +use virtio_drivers::transport::pci::{PciTransport,virtio_device_type}; +use virtio_drivers::device::blk::VirtIOBlk; +use virtio_drivers::transport::DeviceType; +use virtio_drivers::{BufferDirection, Hal}; + + +//#[allow(unused)] +//#[cfg(target_arch = "loongarch64")] +const VIRTIO0: usize = 0x2000_0000 | VIRT_ADDR_START; +const VIRT_PCI_BASE: usize = 0x4000_0000; +const VIRT_PCI_SIZE: usize = 0x0002_0000; + + +pub struct VirtIOBlock(Mutex>); + +lazy_static! { + static ref QUEUE_FRAMES: Mutex> = Mutex::new(Vec::new()) ; +} + +unsafe impl Sync for VirtIOBlock {} +unsafe impl Send for VirtIOBlock {} + +impl BlockDevice for VirtIOBlock { + fn read_block(&self, block_id: usize, buf: &mut [u8]) { + self.0 + .lock() + .read_blocks(block_id, buf) + .expect("Error when reading VirtIOBlk"); + } + fn write_block(&self, block_id: usize, buf: &[u8]) { + self.0 + .lock() + .write_blocks(block_id, buf) + .expect("Error when writing VirtIOBlk"); + } +} + +pub struct PciRangeAllocator { + _start: usize, + end: usize, + current: usize, + +} + +impl PciRangeAllocator { + /// Creates a new allocator from a memory range. + pub const fn new(pci_base:usize,pci_size:usize) -> Self { + Self { + _start:pci_base, + end:pci_base+pci_size, + current:pci_base + } + } + pub fn alloc_pci_mem(&mut self,size: usize) -> Option { + if !size.is_power_of_two() { + return None; + } + let ret = align_up(self.current, size); + if ret + size > self.end { + return None; + } + self.current = ret + size; + Some(ret) + } +} + + +const fn align_up(addr: usize, align: usize) -> usize { + (addr + align - 1) & !(align - 1) +} + + + +fn enumerate_pci()->Option { + let mmconfig_base = VIRTIO0 as *mut u8; + + let mut pci_root = unsafe { PciRoot::new(mmconfig_base, Cam::Ecam) }; + + let mut transport = None; + + for (device_function, info) in pci_root.enumerate_bus(0) { + let (_status, _command) = pci_root.get_status_command(device_function); + + if let Some(_virtio_type) = virtio_device_type(&info) { + // println!("type:{:?}",_virtio_type); + if _virtio_type != DeviceType::Block {continue;} + let mut pci_range_allocator = PciRangeAllocator::new(VIRT_PCI_BASE, VIRT_PCI_SIZE); + let mut bar_index = 0; + while bar_index < 6{ + let bar_info = pci_root.bar_info(device_function, bar_index).unwrap(); + if let BarInfo::Memory {address_type,address,size,..} = bar_info{ + if address == 0 && size != 0{ + let alloc_addr = pci_range_allocator.alloc_pci_mem(size as usize).unwrap(); + match address_type { + MemoryBarType::Width64=>pci_root.set_bar_64(device_function, bar_index, alloc_addr as u64), + MemoryBarType::Width32=>pci_root.set_bar_32(device_function, bar_index, alloc_addr as u32), + _=>{} + } + } + } + bar_index += 1; + if bar_info.takes_two_entries(){ + bar_index+=1; + } + } + + // Enable the device to use its BARs. + pci_root.set_command( + device_function, + Command::IO_SPACE | Command::MEMORY_SPACE | Command::BUS_MASTER, + ); + // dump_bar_contents(&mut pci_root, device_function, 1); + + transport = + Some(PciTransport::new::(&mut pci_root, device_function).unwrap()); + break; + } + } + return transport; +} +#[allow(unused)] +fn dump_bar_contents( + root: &mut PciRoot, + device_function: DeviceFunction, + bar_index: u8, +) { + let bar_info = root.bar_info(device_function, bar_index).unwrap(); + if let BarInfo::Memory { address, size, .. } = bar_info { + let start = address as *const u8; + println!("start:{:?}",start); + unsafe { + let mut buf = [0u8; 32]; + for i in 0..size / 32 { + let ptr = start.add(i as usize * 32); + println!("ptr:{:?}",ptr); + core::ptr::copy(ptr, buf.as_mut_ptr(), 32); + if buf.iter().any(|b| *b != 0xff) { + } + } + } + } +} + +impl VirtIOBlock { + #[allow(unused)] + pub fn new() -> Self { + unsafe { + Self(Mutex::new( + VirtIOBlk::::new( + enumerate_pci().unwrap() + ) + .expect("this is not a valid virtio device"), + ) + ) + } + } +} + +pub struct VirtioHal; + +unsafe impl Hal for VirtioHal { + fn dma_alloc(pages: usize, _direction: BufferDirection) -> (usize, NonNull) { + let mut ppn_base = PhysPage::new(0); + for i in 0..pages { + let frame = frame_alloc().unwrap(); + // debug!("alloc paddr: {:?}", frame); + if i == 0 { + ppn_base = frame.ppn + }; + assert_eq!(frame.ppn.as_num(), ppn_base.as_num() + i); + QUEUE_FRAMES.lock().push(frame); + } + let pa: usize = ppn_base.to_addr(); + unsafe { + ( + pa, + NonNull::new_unchecked((pa | VIRT_ADDR_START) as *mut u8), + ) + } + } + + unsafe fn dma_dealloc(paddr: usize, _vaddr: NonNull, pages: usize) -> i32 { + // trace!("dealloc DMA: paddr={:#x}, pages={}", paddr, pages); + log::error!("dealloc paddr: {:?}", paddr); + let pa = PhysAddr::new(paddr); + let mut ppn_base: PhysPage = pa.into(); + for _ in 0..pages { + frame_dealloc(ppn_base); + ppn_base = ppn_base + 1; + } + 0 + } + + unsafe fn mmio_phys_to_virt(paddr: usize, _size: usize) -> NonNull { + NonNull::new((usize::from(paddr) | VIRT_ADDR_START) as *mut u8).unwrap() + } + + unsafe fn share(buffer: NonNull<[u8]>, _direction: BufferDirection) -> usize { + buffer.as_ptr() as *mut u8 as usize - VIRT_ADDR_START + // let pt = PageTable::current(); + // let paddr = pt.translate(VirtAddr::new(buffer.as_ptr() as *const u8 as usize)).expect("can't find vaddr").0; + // paddr.addr() + } + + unsafe fn unshare(_paddr: usize, _buffer: NonNull<[u8]>, _direction: BufferDirection) { + // Nothing to do, as the host already has access to all memory and we didn't copy the buffer + // anywhere else. + } +} diff --git a/os/src/drivers/block/virtio_blk.rs b/os/src/drivers/block/virtio_blk.rs index c361f28..96e69b9 100644 --- a/os/src/drivers/block/virtio_blk.rs +++ b/os/src/drivers/block/virtio_blk.rs @@ -16,6 +16,7 @@ use virtio_drivers::{BufferDirection, Hal}; #[cfg(target_arch = "riscv64")] const VIRTIO0: usize = 0x10001000; + pub struct VirtIOBlock(Mutex>); lazy_static! { diff --git a/os/src/fs/inode.rs b/os/src/fs/inode.rs index 4b8fbd0..d079346 100644 --- a/os/src/fs/inode.rs +++ b/os/src/fs/inode.rs @@ -62,6 +62,10 @@ impl OSInode { }*/ ///List all files in the filesystems pub fn list_apps() { + // let root_dentry = get_root_dentry(); + // let lib = root_dentry.lookup("lib").unwrap(); + // let _ = lib.clone().load_dir(); + // let _libc = lib.lookup("libc.so").unwrap(); /* println!("/**** APPS ****"); let root_dentry = get_root_dentry(); diff --git a/os/src/fs/mod.rs b/os/src/fs/mod.rs index 9e09240..4721684 100644 --- a/os/src/fs/mod.rs +++ b/os/src/fs/mod.rs @@ -19,4 +19,4 @@ pub use inode::{list_apps, open_file,path_to_dentry,path_to_father_dentry,create pub use stdio::{Stdin, Stdout,StdioDentry,StdioInode}; /// pipe mod pub mod pipe; -pub use pipe::make_pipe; // 导出 make_pipe 函数 +pub use pipe::{make_pipe,PipeDentry,PipeInode}; // 导出 make_pipe 函数 diff --git a/os/src/fs/pipe.rs b/os/src/fs/pipe.rs index bc2ddc2..867ad27 100644 --- a/os/src/fs/pipe.rs +++ b/os/src/fs/pipe.rs @@ -3,11 +3,14 @@ use core::task::Poll; use crate::suspend_current_and_run_next; use alloc::sync::{Arc,Weak}; -use spin::Mutex; +use sync::Mutex; +use vfs_defs::DentryState; use vfs_defs::File; use vfs_defs::UserBuffer; use vfs_defs::FileInner; -use vfs_defs::{Dentry,PollEvents}; +use vfs_defs::{Dentry,PollEvents,Inode,InodeMeta,DentryInner,OpenFlags,DiskInodeType,RenameFlags,Kstat,ino_alloc,InodeMode,SuperBlock}; +use alloc::string::String; +use system_result::{SysError,SysResult}; use crate::sync::UPSafeCell; const RING_BUFFER_SIZE: usize = 2048; @@ -74,13 +77,17 @@ impl PipeRingBuffer { } /// Return (read_end, write_end) -pub fn make_pipe(dentry: Arc) -> (Arc, Arc) { +pub fn make_pipe(superblock:Arc) -> (Arc, Arc) { + let pipe_dentry = PipeDentry::new(superblock.clone()); + let pipe_inode = PipeInode::new(superblock); + pipe_dentry.set_inode(pipe_inode); + *pipe_dentry.get_state() = DentryState::Valid; let buffer = Arc::new(Mutex::new(PipeRingBuffer::new())); let read_end = Arc::new( - Pipe::read_end_with_buffer(buffer.clone(), dentry.clone()) + Pipe::read_end_with_buffer(buffer.clone(), pipe_dentry.clone()) ); let write_end = Arc::new( - Pipe::write_end_with_buffer(buffer.clone(), dentry.clone()) + Pipe::write_end_with_buffer(buffer.clone(), pipe_dentry) ); buffer.lock().set_write_end(&write_end);// 调用 PipeRingBuffer::set_write_end 在管道中保留它的写端的弱引用计数 (read_end, write_end) @@ -123,8 +130,9 @@ impl File for Pipe { let mut buf_iter = buf.into_iter(); // iterator for reading bytes let mut already_read = 0usize; // change task when data inadequate - loop { + //let mut ring_buffer = self.buffer.exclusive_access(); + loop { let mut ring_buffer = self.buffer.lock(); let loop_read = ring_buffer.available_read(); if loop_read == 0 { @@ -134,12 +142,10 @@ impl File for Pipe { drop(ring_buffer); suspend_current_and_run_next(); //change task: empty pipe continue; - } + } + let want_to_read = want_to_read.min(loop_read); for _ in 0..loop_read { if let Some(byte_ref) = buf_iter.next() { - /*unsafe { - *byte_ref = ring_buffer.read_byte(); - }*/ *byte_ref = ring_buffer.read_byte(); already_read += 1; if already_read == want_to_read { @@ -149,6 +155,7 @@ impl File for Pipe { return already_read; } } + return already_read; } } //需要返回什么? @@ -183,7 +190,7 @@ impl File for Pipe { suspend_current_and_run_next(); // 切换任务:管道为空 continue; } - + let want_to_read = want_to_read.min(loop_read); for _ in 0..loop_read { if let Some(byte_ref) = buf_iter.next() { *byte_ref = ring_buffer.read_byte(); // 从缓冲区读取一个字节 @@ -242,4 +249,107 @@ impl File for Pipe { } return PollEvents::POLLOUT; } +} + +pub struct PipeDentry { + inner: DentryInner, +} + +impl PipeDentry { + pub fn new( + superblock:Arc + ) -> Arc { + Arc::new(Self { + inner:DentryInner::new(String::from("pipe"), superblock, None), + }) + } +} +impl Dentry for PipeDentry{ + fn get_inner(&self) -> &DentryInner { + &self.inner + } + fn open(self:Arc,_flags:OpenFlags)->Arc { + unreachable!() + } + fn concrete_create(self: Arc, _name: &str, _type:DiskInodeType) -> SysResult> { + Err(SysError::ENOTDIR) + } + fn concrete_lookup(self: Arc, _name: &str) -> SysResult> { + Err(SysError::ENOTDIR) + } + fn concrete_link(self: Arc, _new: &Arc) -> SysResult<()> { + Err(SysError::ENOTDIR) + } + fn concrete_unlink(self: Arc, _old: &Arc) -> SysResult<()> { + Err(SysError::ENOTDIR) + } + fn load_dir(self:Arc)->SysResult<()> { + Err(SysError::ENOTDIR) + } + /* + fn ls(self:Arc)->Vec { + Vec::new() + }*/ + fn concrete_new_child(self: Arc, _name: &str) -> Arc { + unimplemented!() + } + fn concrete_rename(self: Arc, _new: Arc, _flags: RenameFlags) -> SysResult<()> { + Err(SysError::ENOTDIR) + } + fn concrete_getchild(self:Arc, _name: &str) -> Option> { + unimplemented!() + } + fn self_arc(self:Arc) -> Arc { + unimplemented!() + } +} + +pub struct PipeInode{ + meta:InodeMeta +} +impl PipeInode{ + pub fn new(superblock:Arc)->Arc{ + Arc::new(Self{ + meta:InodeMeta::new(InodeMode::FIFO, ino_alloc(), superblock), + }) + } +} +impl Inode for PipeInode{ + fn get_meta(&self) -> &InodeMeta { + &self.meta + } + fn get_attr(&self)->system_result::SysResult { + Ok(Kstat{ + st_dev: 0, + st_ino: self.meta.ino as u64, + st_mode: self.meta.mode.bits(), + st_nlink: 0, + st_uid: 0, + st_gid: 0, + st_rdev: 0, + __pad: 0, + st_size: self.get_size() as u64, + st_blksize: 0, + __pad2: 0, + st_blocks:0, + st_atime_sec: 0, + st_atime_nsec: 0, + st_mtime_sec: 0, + st_mtime_nsec: 0, + st_ctime_sec: 0, + st_ctime_nsec: 0, + unused: 0, + }) + + } + fn load_from_disk(&self) { + + } + fn clear(&self) { + + } + fn get_size(&self) -> u32 { + let size = self.meta.inner.lock().size as u32; + return size; + } } \ No newline at end of file diff --git a/os/src/fs/stdio.rs b/os/src/fs/stdio.rs index 0470b45..7c2324e 100644 --- a/os/src/fs/stdio.rs +++ b/os/src/fs/stdio.rs @@ -18,6 +18,11 @@ pub struct Stdout{ inner:FileInner } +pub struct StdIO{ + buf:Mutex>, + inner:FileInner +} + impl Stdin{ pub fn new(inner:FileInner)->Self{ Self{ @@ -33,7 +38,14 @@ impl Stdout{ } } } - +impl StdIO{ + pub fn new(inner:FileInner)->Self{ + Self{ + buf:Mutex::new(None), + inner + } + } +} impl File for Stdin { fn readable(&self) -> bool { true @@ -112,9 +124,17 @@ impl File for Stdout { } fn write(&self, user_buf: &[u8]) -> usize { // for buffer in user_buf.iter() { - // print!("{}", core::str::from_utf8(user_buf).unwrap()); - unsafe {print!("{}", core::str::from_utf8_unchecked(user_buf));} - // } + print!("{}", core::str::from_utf8(user_buf).unwrap()); + // unsafe {print!("{}", core::str::from_utf8_unchecked(user_buf));} + /* match core::str::from_utf8(user_buf) { + Ok(s) => {print!("{}", s);}, + Err(e) => { + let valid = &user_buf[..e.valid_up_to().min(user_buf.len())]; + if let Ok(valid_str) = core::str::from_utf8(valid) { + print!("{}", valid_str); + } + } + } */ user_buf.len() } fn get_inner(&self)->&FileInner { @@ -124,6 +144,15 @@ impl File for Stdout { unimplemented!() } fn write_at(&self, _offset: usize, _buf: &[u8])->usize { + /* match core::str::from_utf8(_buf) { + Ok(s) => {print!("{}", s);}, + Err(e) => { + let valid = &_buf[..e.valid_up_to().min(_buf.len())]; + if let Ok(valid_str) = core::str::from_utf8(valid) { + print!("{}", valid_str); + } + } + } */ print!("{}", core::str::from_utf8(_buf).unwrap()); _buf.len() } @@ -135,19 +164,84 @@ impl File for Stdout { } } +impl File for StdIO { + fn readable(&self) -> bool { + true + } + fn writable(&self) -> bool { + true + } + fn read(&self, user_buf: &mut [u8]) -> usize { + assert_eq!(user_buf.len(), 1); + // busy loop + let c: u8; + let mut buf = self.buf.lock(); + if buf.is_some(){ + user_buf[0] = buf.unwrap(); + *buf = None; + return 1; + } + drop(buf); + loop { + if let Some(ch) = console_getchar() { + c = ch; + break; + } + suspend_current_and_run_next(); + } + user_buf[0] = c as u8; + /* + let ch = UART.read(); + unsafe { + user_buf.buffers[0].as_mut_ptr().write_volatile(ch); + }*/ + 1 + } + fn write(&self, user_buf: &[u8]) -> usize { + print!("{}", core::str::from_utf8(user_buf).unwrap()); + user_buf.len() + } + fn get_inner(&self)->&FileInner { + &self.inner + } + fn read_at(&self, _offset: usize, _buf: &mut [u8])->usize { + unimplemented!() + } + fn write_at(&self, _offset: usize, _buf: &[u8])->usize { + print!("{}", core::str::from_utf8(_buf).unwrap()); + _buf.len() + } + fn get_offset(&self)->MutexGuard { + self.get_inner().offset.lock() + } + fn poll(&self, events: PollEvents) -> PollEvents { + if ! events.contains(PollEvents::POLLIN) { + return PollEvents::empty(); + } + loop { + if let Some(ch) = console_getchar() { + let mut buf = self.buf.lock(); + *buf = Some(ch); + drop(buf); + break; + } + suspend_current_and_run_next(); + } + return PollEvents::POLLIN; + } +} + pub struct StdioDentry { inner: DentryInner, - is_stdin:bool, } impl StdioDentry { pub fn new( - inner:DentryInner, - is_stdin:bool, + mut inner:DentryInner, ) -> Arc { + inner.name = String::from("tty"); Arc::new(Self { inner, - is_stdin, }) } } @@ -157,12 +251,7 @@ impl Dentry for StdioDentry{ } fn open(self:Arc,flags:OpenFlags)->Arc { let file; - if self.is_stdin{ - file = Arc::new(Stdin::new(FileInner::new(self))); - } - else{ - file = Arc::new(Stdin::new(FileInner::new(self))); - } + file = Arc::new(StdIO::new(FileInner::new(self))); *file.get_inner().flags.lock() = flags; return file; } @@ -217,7 +306,7 @@ impl Inode for StdioInode{ Ok(Kstat{ st_dev: 0, st_ino: self.meta.ino as u64, - st_mode: 0, + st_mode: vfs_defs::InodeMode::CHAR.bits(), st_nlink: 0, st_uid: 0, st_gid: 0, diff --git a/os/src/linker-loongarch64.ld b/os/src/linker-loongarch64.ld new file mode 100644 index 0000000..a73a520 --- /dev/null +++ b/os/src/linker-loongarch64.ld @@ -0,0 +1,69 @@ +OUTPUT_ARCH(loongarch) +ENTRY(_start) + +BASE_ADDRESS = 0x9000000090000000; + +SECTIONS +{ + /* Load the kernel at this address: "." means the current address */ + . = BASE_ADDRESS; + start = .; + _skernel = .; + + .text ALIGN(4K): { + stext = .; + *(.text.entry) + *(.text .text.*) + etext = .; + } + + .rodata ALIGN(4K): { + srodata = .; + *(.rodata .rodata.*) + . = ALIGN(4K); + erodata = .; + } + + .data ALIGN(4K): { + . = ALIGN(4K); + *(.data.prepage .data.prepage.*) + . = ALIGN(4K); + _sdata = .; + *(.data .data.*) + *(.sdata .sdata.*) + _edata = .; + } + + .sigtrx ALIGN(4K): { + *(.sigtrx .sigtrx.*) + } + + _load_end = .; + + .bss ALIGN(4K): { + *(.bss.stack) + _sbss = .; + *(.bss .bss.*) + *(.sbss .sbss.*) + _ebss = .; + } + + . = ALIGN(4K); + _percpu_start = .; + .percpu 0x0 : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = ALIGN(64); + _percpu_size_aligned = .; + + . = _percpu_load_start + _percpu_size_aligned * 1; + } + . = _percpu_start + SIZEOF(.percpu); + _percpu_end = .; + + PROVIDE(end = .); + /DISCARD/ : { + *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) + } +} \ No newline at end of file diff --git a/os/src/main.rs b/os/src/main.rs index 0eb4984..5678e3b 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -125,20 +125,6 @@ impl ArchInterface for ArchInterfaceImpl { } } StorePageFault(_paddr) | LoadPageFault(_paddr) | InstructionPageFault(_paddr) => { - /* - println!( - "[kernel] {:?} in application, bad addr = {:#x}, bad instruction = {:#x}, kernel killed it.", - scause.cause(), - stval, - current_trap_cx().sepc, - ); - */ - - /*let task=current_task().unwrap(); - let inner=task.inner_exclusive_access(); - println!("\nheaptop={} data={}",inner.heap_top,inner.max_data_addr); - drop(inner); - */ let ctask = current_task().unwrap(); let inner = ctask.inner_exclusive_access(); if inner.memory_set.lock().handle_lazy_addr(_paddr, trap_type).is_err() { @@ -164,9 +150,6 @@ impl ArchInterface for ArchInterfaceImpl { } } - //println!("err {:x?},sepc:{:x}", trap_type,ctx.sepc); - // ctx.syscall_ok(); - //exit_current_and_run_next(-1); } IllegalInstruction(_) => { println!("IllegalInstruction!"); @@ -209,10 +192,20 @@ impl ArchInterface for ArchInterfaceImpl { arch::init_interrupt(); //timer::set_next_trigger(); // board::device_init(); + println!("intr init"); device::BLOCK_DEVICE.call_once(||drivers::BLOCK_DEVICE.clone()); + println!("device added"); vfs::init(); + let superblock = vfs::get_root_dentry().get_superblock(); + let dev = vfs::get_root_dentry().lookup("dev").unwrap(); + let ttyinner = vfs_defs::DentryInner::new(alloc::string::String::from("tty"), superblock.clone(),Some(dev)); + let ttydentry = fs::StdioDentry::new(ttyinner); + let ttyinode = fs::StdioInode::new(vfs_defs::InodeMeta::new(vfs_defs::InodeMode::CHAR, vfs_defs::ino_alloc() as usize, superblock)); + vfs::add_tty(ttydentry,alloc::sync::Arc::new( ttyinode)); + println!("vfs init"); fs::list_apps(); task::add_initproc(); + println!("initproc add"); // *DEV_NON_BLOCKING_ACCESS.lock() = true; task::run_tasks(); panic!("Unreachable in rust_main!"); diff --git a/os/src/mm/memory_set.rs b/os/src/mm/memory_set.rs index 5510a66..388cd2c 100644 --- a/os/src/mm/memory_set.rs +++ b/os/src/mm/memory_set.rs @@ -9,12 +9,15 @@ use alloc::alloc::dealloc; use alloc::string::String; use arch::pagetable::{MappingFlags, MappingSize, PageTable, PageTableWrapper}; use arch::addr::{PhysAddr, PhysPage, VirtAddr, VirtPage}; +use crate::fs::path_to_dentry; use arch::{TrapType, PAGE_SIZE, USER_VADDR_END}; -use config::{USER_HEAP_SIZE, USER_MMAP_TOP, USER_STACK_SIZE, USER_STACK_TOP}; +use config::{USER_HEAP_SIZE, USER_MMAP_TOP, USER_STACK_SIZE, USER_STACK_TOP,DL_INTERP_OFFSET}; use crate::sync::UPSafeCell; use alloc::collections::BTreeMap; use alloc::sync::Arc; use alloc::vec::Vec; +use alloc::vec; +use alloc::string::{String,ToString}; use spin::Mutex; use system_result::{SysError,SysResult}; @@ -165,13 +168,54 @@ impl MemorySet { } self.mmap_area.push(map_area); } - /// Include sections in elf and trampoline and TrapContext and user stack, - /// also returns user_sp and entry point. - pub fn from_elf(elf_data: &[u8]) -> (Self, usize, usize, usize,u16,u16,u64,usize) { - let mut memory_set = Self::new_bare(); - // map trampoline - // map program headers of elf, with U flag + pub fn load_interp(&mut self,elf_data: &[u8]) -> Option{ let elf = xmas_elf::ElfFile::new(elf_data).unwrap(); + let elf_header = elf.header; + let ph_count = elf_header.pt2.ph_count(); + let mut is_dl = false; + for i in 0..ph_count { + let ph = elf.program_header(i).unwrap(); + if ph.get_type().unwrap() == xmas_elf::program::Type::Interp{ + is_dl = true; + break; + } + } + if is_dl{ + let section = elf.find_section_by_name(".interp").unwrap(); + let mut interp = String::from_utf8(section.raw_data(&elf).to_vec()).unwrap(); + interp = interp.strip_suffix("\0").unwrap_or(&interp).to_string(); + + let interps: Vec = vec![interp.clone()]; + + let mut interp_dentry: system_result::SysResult> = Err(system_result::SysError::ENOENT); + for interp in interps.into_iter() { + println!("dyn:{}",interp); + // if interp == String::from("/lib/ld-linux-riscv64-lp64.so.1"){ + // interp = String::from("/lib/libc.so"); + // } + + if let Ok(dentry) = path_to_dentry(interp.as_str()) { + interp_dentry = Ok(dentry); + break; + } + } + if interp_dentry.is_err(){ + return None; + } + let interp_dentry: Arc = interp_dentry.unwrap(); + let interp_file = interp_dentry.open(vfs_defs::OpenFlags::RDONLY); + let interp_elf_data = interp_file.read_all(); + let interp_elf = xmas_elf::ElfFile::new(&interp_elf_data).unwrap(); + + self.map_elf( &interp_elf, DL_INTERP_OFFSET.into()); + + Some(interp_elf.header.pt2.entry_point() as usize + DL_INTERP_OFFSET) + } + else{ + None + } + } + fn map_elf(&mut self,elf:& xmas_elf::ElfFile,offset:usize)->(u64,usize,u64,u16,usize){//(max_virt_mem,header_va,tls_addr,ph_count) let elf_header = elf.header; let magic = elf_header.pt1.magic; assert_eq!(magic, [0x7f, 0x45, 0x4c, 0x46], "invalid elf!"); @@ -184,11 +228,11 @@ impl MemorySet { for i in 0..ph_count { let ph = elf.program_header(i).unwrap(); if ph.get_type().unwrap() == xmas_elf::program::Type::Tls{ - tls_addr = ph.virtual_addr(); + tls_addr = ph.virtual_addr() + offset as u64; } if ph.get_type().unwrap() == xmas_elf::program::Type::Load { - let start_va: VirtAddr = (ph.virtual_addr() as usize).into(); - let end_va: VirtAddr = ((ph.virtual_addr() + ph.mem_size()) as usize).into(); + let start_va: VirtAddr = (ph.virtual_addr() as usize + offset).into(); + let end_va: VirtAddr = ((ph.virtual_addr() + ph.mem_size()) as usize + offset).into(); if !found_header_va { header_va = start_va.addr(); found_header_va = true; @@ -206,13 +250,13 @@ impl MemorySet { } let map_area = MapArea::new(start_va, end_va, MapType::Framed, map_perm); // max_end_vpn = map_area.vpn_range.get_end(); - memory_set.push( + self.push( map_area, Some(&elf.input[ph.offset() as usize..(ph.offset() + ph.file_size()) as usize]), ); // 最大段地址 //let section_end = align_up(ph.virtual_addr() + ph.mem_size(), PAGE_SIZE); - let mut section_end = ph.virtual_addr() + ph.mem_size(); + let mut section_end = ph.virtual_addr() + ph.mem_size() + offset as u64; let pn: u64 = section_end / PAGE_SIZE as u64; if pn * PAGE_SIZE as u64 != section_end { section_end = (pn + 1) * PAGE_SIZE as u64; @@ -220,6 +264,16 @@ impl MemorySet { max_virt_mem = max_virt_mem.max(section_end); } } + (max_virt_mem,header_va,tls_addr,ph_count,header_va + elf_header.pt2.ph_offset() as usize) + } + /// Include sections in elf and trampoline and TrapContext and user stack, + /// also returns user_sp and entry point. + pub fn from_elf(elf_data: &[u8]) -> (Self, usize, usize, usize,u16,u16,u64,usize) { + let mut memory_set = Self::new_bare(); + // map trampoline + // map program headers of elf, with U flag + let elf = xmas_elf::ElfFile::new(elf_data).unwrap(); + let (max_virt_mem,_header_va,tls_addr,ph_count,phdr) = memory_set.map_elf(&elf, 0); // 为程序映像转储 elf 程序头 @@ -256,7 +310,7 @@ impl MemorySet { elf.header.pt2.ph_entry_size(), ph_count, tls_addr, - header_va + elf_header.pt2.ph_offset() as usize + phdr ) } /// 打印memset diff --git a/os/src/syscall/fs.rs b/os/src/syscall/fs.rs index 2d85213..76293ac 100644 --- a/os/src/syscall/fs.rs +++ b/os/src/syscall/fs.rs @@ -30,6 +30,8 @@ use core::slice; use alloc::{task, vec}; use system_result::{SysError,SysResult}; + +//const MODULE_LEVEL:log::Level = log::Level::Debug; //const HEAP_MAX: usize = 0; pub const AT_FDCWD: isize = -100; @@ -122,8 +124,8 @@ pub fn sys_pipe(pipe: *mut i32) -> SysResult { //let mut inner = task.acquire_inner_lock(); let mut inner = task.inner_exclusive_access(); //自身目录项 - let self_dentry = inner.cwd.clone(); - let (pipe_read, pipe_write) = make_pipe(self_dentry); //创建一个管道并获取其读端和写端 + let self_super = inner.cwd.get_superblock(); + let (pipe_read, pipe_write) = make_pipe(self_super); //创建一个管道并获取其读端和写端 let read_fd = inner.fd_table.insert(Some(Fd::new(pipe_read, FdFlags::empty())))?; let write_fd = inner.fd_table.insert(Some(Fd::new(pipe_write, FdFlags::empty()))); if let Err(e) = write_fd{ @@ -211,8 +213,9 @@ pub fn sys_umount(special:*const u8,_flags:u32)->SysResult{ let path = translated_str(token, special); let ext4fstype = FILE_SYSTEMS.lock().find_fs(&String::from("Ext4")).unwrap(); let dentry = path_to_dentry(&path)?; - if let Err(e) = ext4fstype.umount(dentry.path().as_str(), MountFlags::empty()){ - return Err(e); + if let Err(_e) = ext4fstype.umount(dentry.path().as_str(), MountFlags::empty()){ + return Ok(0); + // return Err(e); } return Ok(0); } @@ -489,8 +492,10 @@ pub fn sys_writev(fd:isize,iov:*const IoVec,iovcnt:usize)->SysResult{ let file = file.file(); let mut offset = file.get_offset(); let mut total_write_size = 0; - let iov_iter = iov; - for _i in 0..iovcnt{ + let mut iov_iter = iov; + + for _i in 0..iovcnt{ + // println!("iov:{:?}",iov_iter); let iovs = translated_ref(token, iov_iter); if iovs.len == 0{ unsafe { @@ -498,13 +503,14 @@ pub fn sys_writev(fd:isize,iov:*const IoVec,iovcnt:usize)->SysResult{ } continue; } + // println!("writev:write len:{}",iovs.len); let ptr = iovs.base; let buf = translated_byte_buffer(token, ptr as *mut u8, iovs.len); let write_size = file.write_at(*offset, buf); total_write_size += write_size; *offset += write_size; unsafe { - let _ = iov_iter.add(1); + iov_iter = iov_iter.add(1); } } drop(offset); @@ -770,4 +776,53 @@ pub fn sys_renameat2(olddirfd:isize,oldpath:*const u8,newdirfd:isize,newpath:*co } return Ok(0); +} + +#[repr(C)] +pub struct Statx { + stx_mask:u32, /* 统计信息位标识 */ + stx_blksize:u32, /* 推荐的 I/O 大小 */ + stx_attributes:u64, /* 文件属性标志 */ + stx_nlink:u32, /* 链接数 */ + stx_uid:u32, /* 所有者用户 ID */ + stx_gid:u32, /* 所有者组 ID */ + stx_mode:u16, /* 文件类型和访问模式 */ + __spare0:u16, + stx_ino:u64, /* inode 号 */ + stx_size:u64, /* 文件大小(字节) */ + stx_blocks:u64, /* 分配的块数 */ + stx_attributes_mask:u64, + stx_atime:TimeSpec, /* 最后访问时间 */ + stx_btime:TimeSpec, /* 文件创建时间 */ + stx_ctime:TimeSpec, /* 元数据改变时间 */ + stx_mtime:TimeSpec, /* 最后修改时间 */ + stx_rdev_major:u32, /* 设备号(主) */ + stx_rdev_minor:u32, /* 设备号(次) */ + stx_dev_major:u32, /* 文件所在设备号(主) */ + stx_dev_minor:u32, /* 文件所在设备号(次) */ + __spare2:[u64;14], +} +/// +pub fn sys_statx(dirfd:isize,path:*const u8,_flags:i32,_mask:u32,statx:*mut Statx)->SysResult{ + let token = current_user_token(); + let path = parse_fd_path(dirfd, path)?; + let dentry = path_to_dentry(path.as_str())?; + let attr = dentry.get_inode()?.get_attr()?; + let statx = translated_refmut(token, statx); + statx.stx_mask = 0; + statx.stx_blksize = attr.st_blksize; + statx.stx_attributes = 0; + statx.stx_nlink = attr.st_nlink; + statx.stx_uid = 1; + statx.stx_gid = 1; + statx.stx_mode = attr.st_mode as u16; + statx.__spare0 = 0; + statx.stx_ino = attr.st_ino; + statx.stx_atime.sec = attr.st_atime_sec as usize; + statx.stx_atime.usec = attr.st_atime_nsec as usize; + statx.stx_mtime.sec = attr.st_mtime_sec as usize; + statx.stx_mtime.usec = attr.st_mtime_nsec as usize; + statx.stx_ctime.sec = attr.st_ctime_sec as usize; + statx.stx_ctime.usec = attr.st_ctime_nsec as usize; + Ok(0) } \ No newline at end of file diff --git a/os/src/syscall/mod.rs b/os/src/syscall/mod.rs index 7ec0dbc..6bfc81d 100644 --- a/os/src/syscall/mod.rs +++ b/os/src/syscall/mod.rs @@ -53,6 +53,7 @@ const SYSCALL_KILL: usize = 129; const SYSCALL_TGKILL: usize = 131; const SYSCALL_SIGACTION: usize = 134; const SYSCALL_SIGPROCMASK: usize = 135; +const SYSCALL_RT_SIGTIMEDWAIT:usize = 137; const SYSCALL_SIGRETURN: usize = 139; const SYSCALL_TIMES: usize = 153; const SYSCALL_SETPGID:usize = 154; @@ -77,6 +78,7 @@ const SYSCALL_WAITPID: usize = 260; const SYSCALL_PRLIMIT64: usize = 261; const SYSCALL_RENAMEAT2: usize = 276; const SYSCALL_GET_RANDOM: usize = 278; +const SYSCALL_STATX: usize = 291; mod fs; mod process; @@ -89,7 +91,7 @@ use crate::task::{check_signals_error_of_current, current_task, exit_current_and use crate::task::{TimeSpec, Tms, Utsname, SysInfo}; use config::RLimit; use system_result::{SysResult,SysError}; -const MODULE_LEVEL:log::Level = log::Level::Trace; +const MODULE_LEVEL:log::Level = log::Level::Debug; use crate::task::check_pending_signals; pub use process::CloneFlags; /// handle syscall exception with `syscall_id` and other arguments @@ -309,6 +311,12 @@ pub fn syscall(syscall_id: usize, args: [usize; 6]) -> isize { }, SYSCALL_MPROTECT => { result = sys_mprotect(VirtAddr::new(args[0]), args[1], args[2] as i32); + }, + SYSCALL_RT_SIGTIMEDWAIT=>{//TODO + result = Ok(0); + } + SYSCALL_STATX=>{ + result = sys_statx(args[0] as isize,args[1] as *const u8,args[2] as i32,args[3] as u32,args[4] as *mut Statx); } _ => panic!("Unsupported syscall_id: {}", syscall_id), } @@ -542,6 +550,12 @@ fn sysid_to_string(syscall_id: usize)->String{ SYSCALL_CLOCK_NANOSLEEP => { ret.push_str("sys_clock_nanosleep"); } + SYSCALL_RT_SIGTIMEDWAIT=>{ + ret.push_str("sys_rt_sigtimedwait"); + } + SYSCALL_STATX=>{ + ret.push_str("sys_statx"); + } _ => panic!("Unsupported syscall_id: {}", syscall_id), } ret diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index ac737a1..eb04cc9 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -105,7 +105,19 @@ pub fn sys_getpid() -> SysResult { Ok(current_task().unwrap().pid.0 as isize) } -pub fn sys_clone(flags:usize,stack_ptr:*const u8,ptid:*mut i32,_tls:*mut i32,ctid:*mut i32) -> SysResult { +pub fn sys_clone(flags:usize,stack_ptr:*const u8,ptid:*mut i32,mut _tls:*mut i32,mut ctid:*mut i32) -> SysResult { + let tls = _tls; + let ctid_ = ctid; + #[cfg(target_arch = "riscv64")] + { + ctid = ctid_; + _tls = tls; + } + #[cfg(target_arch = "loongarch64")] + { + ctid = tls; + _tls = ctid_; + } let flags = CloneFlags::from_bits(flags as u64 & !0xff); let token = current_user_token(); if flags.is_none(){ @@ -237,17 +249,20 @@ pub fn sys_chdir(path: *const u8) -> SysResult { pub fn sys_brk(new_brk: usize) -> SysResult { + log_debug!("brkarg:{:x}",new_brk); let task = current_task().unwrap(); let mut task_inner = task.inner_exclusive_access(); let cur_brk = task_inner.heap_top; //println!("sys_brk: heap_top = {}, stack_bottom = {} new_brk:{}",task_inner.heap_top,task_inner.stack_bottom,new_brk); if new_brk == 0 { + log_debug!("brkret:{:x}",cur_brk); return Ok(cur_brk as isize); } if task_inner.max_data_addr >= new_brk && new_brk < task_inner.stack_bottom { // 利用上一次分配的多余内存 task_inner.heap_top = new_brk; // return 0; + log_debug!("brkret:{:x}",new_brk); return Ok(new_brk as isize); } @@ -255,6 +270,7 @@ pub fn sys_brk(new_brk: usize) -> SysResult { let user_stack_bottom = task_inner.stack_bottom; if new_brk >= user_stack_bottom -PAGE_SIZE { + log_debug!("brkret:{:x}",cur_brk); return Ok(cur_brk as isize); // return -1; } @@ -274,10 +290,12 @@ pub fn sys_brk(new_brk: usize) -> SysResult { task_inner.max_data_addr += PAGE_SIZE*page_count; //println!("max_data_addr = {}", task_inner.max_data_addr); task_inner.heap_top = new_brk; + log_debug!("brkret:{:x}",new_brk); return Ok(new_brk as isize); // 0 } else if new_brk == cur_brk { + log_debug!("brkret:{:x}",cur_brk); return Ok(cur_brk as isize); // -1 } @@ -302,6 +320,7 @@ pub fn sys_brk(new_brk: usize) -> SysResult { return Err(SysError::ENXIO); } task_inner.heap_top = new_brk; + log_debug!("brkret:{:x}",new_brk); return Ok(new_brk as isize); // 0 } @@ -769,7 +788,7 @@ pub fn sys_sigreturn() -> SysResult { // 恢复 trap 上下文 if let Some(backup) = task_inner.trap_ctx_backup.take() { - let sepc = backup.sepc; + let sepc = backup[TrapFrameArgs::SEPC]; *task_inner.get_trap_cx() = backup; println!("[kernel] sys_sigreturn: Restoring trap context, sepc={:#x}", sepc); } else { diff --git a/os/src/task/aux.rs b/os/src/task/aux.rs index 7b0125e..d48b5eb 100644 --- a/os/src/task/aux.rs +++ b/os/src/task/aux.rs @@ -9,6 +9,8 @@ pub const AT_PHNUM: usize = 5; /// pub const AT_PAGESZ: usize = 6; /// +pub const AT_BASE: usize = 7; +/// pub const AT_RANDOM: usize = 25; diff --git a/os/src/task/fdtable.rs b/os/src/task/fdtable.rs index b759d40..8a8499f 100644 --- a/os/src/task/fdtable.rs +++ b/os/src/task/fdtable.rs @@ -2,7 +2,7 @@ use alloc::{string::String, vec::Vec}; use alloc::vec; use alloc::sync::Arc; use crate::fs::{Stdin, Stdout,StdioDentry,StdioInode}; -use vfs_defs::{DentryInner, File, FileInner, OpenFlags}; +use vfs_defs::{Dentry, DentryInner, DentryState, File, FileInner, OpenFlags}; use vfs::devfs::{DevFsType,DevSuperBlock}; use config::{RLimit,MAX_FD}; use system_result::{SysError,SysResult}; @@ -60,9 +60,14 @@ impl FdTable{ pub fn new()->Self{ let superblock = new_devfssuper(); let stdininner = DentryInner::new(String::from("stdin"), superblock.clone(),None); - let stdoutinner = DentryInner::new(String::from("stdout"), superblock,None); - let stdindentry = StdioDentry::new(stdininner, true); - let stdoutdentry = StdioDentry::new(stdoutinner, false); + let stdoutinner = DentryInner::new(String::from("stdout"), superblock.clone(),None); + let stdioinode = Arc::new(StdioInode::new(vfs_defs::InodeMeta::new(vfs_defs::InodeMode::CHAR, vfs_defs::ino_alloc() as usize, superblock))); + let stdindentry = StdioDentry::new(stdininner); + let stdoutdentry = StdioDentry::new(stdoutinner); + stdindentry.set_inode(stdioinode.clone()); + stdoutdentry.set_inode(stdioinode); + *stdindentry.get_state() = DentryState::Valid; + *stdoutdentry.get_state() = DentryState::Valid; Self{ fd_table: vec![ // 0 -> stdin diff --git a/os/src/task/mod.rs b/os/src/task/mod.rs index 020e712..9677847 100644 --- a/os/src/task/mod.rs +++ b/os/src/task/mod.rs @@ -278,8 +278,8 @@ pub fn call_user_signal_handler(sig: usize, _signal: SignalFlags) { task_inner.handling_sig = sig as isize; let trap_ctx = task_inner.get_trap_cx(); - trap_ctx.sepc = handler; - trap_ctx.x[10] = (sig as i32) as usize; // 修正:将 sig 转换为 i32 后再转换为 usize + trap_ctx[TrapFrameArgs::SEPC] = handler; + trap_ctx[TrapFrameArgs::ARG0] = (sig as i32) as usize; // 修正:将 sig 转换为 i32 后再转换为 usize println!("[kernel] Calling user signal handler for signal {} at {:#x}", sig, handler); } diff --git a/os/src/task/task.rs b/os/src/task/task.rs index 0b12b89..bba6f43 100644 --- a/os/src/task/task.rs +++ b/os/src/task/task.rs @@ -254,7 +254,7 @@ impl TaskControlBlock { /// pub fn exec(&self, elf_data: &[u8], args: Vec) { // memory_set with elf program headers/trampoline/trap context/user stack - let (memory_set, mut user_sp, entry_point, heap_top,entry_size,ph_count,tls_addr,phdr) = MemorySet::from_elf(elf_data); + let (mut memory_set, mut user_sp, entry_point, heap_top,entry_size,ph_count,tls_addr,phdr) = MemorySet::from_elf(elf_data); self.inner_exclusive_access().heap_top = heap_top; self.inner_exclusive_access().stack_bottom =user_sp - USER_STACK_SIZE; self.inner_exclusive_access().max_data_addr = heap_top; @@ -325,6 +325,17 @@ impl TaskControlBlock { aux.a_val = rd_pos; self.push_into_user_stack(token,&mut user_sp,aux); + if let Some(dl_entry) = memory_set.load_interp(elf_data){ + aux.a_type = AT_BASE; + aux.a_val = dl_entry; + self.push_into_user_stack(token,&mut user_sp,aux); + } + else{ + aux.a_type = AT_BASE; + aux.a_val = 0; + self.push_into_user_stack(token,&mut user_sp,aux); + } + // 5. 压入 envp data = 0; self.push_into_user_stack(token,&mut user_sp,data); diff --git a/sync/Cargo.toml b/sync/Cargo.toml index ebb3aee..7cda70a 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -18,5 +18,5 @@ default = [] [dependencies] cfg-if = "1.0" -kernel_guard = "=0.1.1" +#kernel_guard = "=0.1.1" spin = "0.7.0" \ No newline at end of file diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 49e5b3c..224c4a5 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -1,7 +1,8 @@ #![no_std] #![no_main] -mod kspinbase; -mod kspinlib; +//mod kspinbase; +//mod kspinlib; pub use spin::{Mutex,MutexGuard,Once}; -pub use kspinlib::{SpinNoIrq as MutexNoIrq, SpinNoIrqGuard as MutexGuardNoIrq}; \ No newline at end of file +pub use spin::{Mutex as MutexNoIrq, MutexGuard as MutexGuardNoIrq}; +//pub use kspinlib::{SpinNoIrq as MutexNoIrq, SpinNoIrqGuard as MutexGuardNoIrq}; \ No newline at end of file diff --git a/testcase/basic/loongarch64-unknown-none/brk b/testcase/basic/loongarch64-unknown-none/brk new file mode 100644 index 0000000..b3a8e89 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/brk differ diff --git a/testcase/basic/loongarch64-unknown-none/busybox b/testcase/basic/loongarch64-unknown-none/busybox new file mode 100644 index 0000000..2d62f6c Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/busybox differ diff --git a/testcase/basic/riscv64/busybox_cmd.txt b/testcase/basic/loongarch64-unknown-none/busybox_cmd.txt similarity index 100% rename from testcase/basic/riscv64/busybox_cmd.txt rename to testcase/basic/loongarch64-unknown-none/busybox_cmd.txt diff --git a/testcase/basic/loongarch64-unknown-none/busybox_testcode.sh b/testcase/basic/loongarch64-unknown-none/busybox_testcode.sh new file mode 100644 index 0000000..8ab265a --- /dev/null +++ b/testcase/basic/loongarch64-unknown-none/busybox_testcode.sh @@ -0,0 +1,27 @@ +#!/busybox sh + +./busybox echo "#### OS COMP TEST GROUP START busybox-glibc ####" +# RST=result.txt +# if [ -f $RST ];then +# rm $RST +# fi +# touch $RST + +# echo "If the CMD runs incorrectly, return value will put in $RST" > $RST +# echo -e "Else nothing will put in $RST\n" >> $RST +# echo "TEST START" >> $RST + +./busybox cat ./busybox_cmd.txt | while read line +do + eval "./busybox $line" + RTN=$? + if [[ $RTN -ne 0 && $line != "false" ]] ;then + echo "testcase busybox $line fail" + # echo "return: $RTN, cmd: $line" >> $RST + else + echo "testcase busybox $line success" + fi +done + +# echo "TEST END" >> $RST +./busybox echo "#### OS COMP TEST GROUP END busybox-glibc ####" diff --git a/testcase/basic/loongarch64-unknown-none/chdir b/testcase/basic/loongarch64-unknown-none/chdir new file mode 100644 index 0000000..2b13597 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/chdir differ diff --git a/testcase/basic/loongarch64-unknown-none/clone b/testcase/basic/loongarch64-unknown-none/clone new file mode 100644 index 0000000..ff08b65 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/clone differ diff --git a/testcase/basic/loongarch64-unknown-none/close b/testcase/basic/loongarch64-unknown-none/close new file mode 100644 index 0000000..fa94d9c Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/close differ diff --git a/testcase/basic/loongarch64-unknown-none/dup b/testcase/basic/loongarch64-unknown-none/dup new file mode 100644 index 0000000..c6d8a65 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/dup differ diff --git a/testcase/basic/loongarch64-unknown-none/dup2 b/testcase/basic/loongarch64-unknown-none/dup2 new file mode 100644 index 0000000..654dafb Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/dup2 differ diff --git a/testcase/basic/loongarch64-unknown-none/execve b/testcase/basic/loongarch64-unknown-none/execve new file mode 100644 index 0000000..6502ded Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/execve differ diff --git a/testcase/basic/loongarch64-unknown-none/exit b/testcase/basic/loongarch64-unknown-none/exit new file mode 100644 index 0000000..ac4c29b Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/exit differ diff --git a/testcase/basic/loongarch64-unknown-none/fork b/testcase/basic/loongarch64-unknown-none/fork new file mode 100644 index 0000000..5bade29 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/fork differ diff --git a/testcase/basic/loongarch64-unknown-none/fstat b/testcase/basic/loongarch64-unknown-none/fstat new file mode 100644 index 0000000..96d73e6 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/fstat differ diff --git a/testcase/basic/loongarch64-unknown-none/getcwd b/testcase/basic/loongarch64-unknown-none/getcwd new file mode 100644 index 0000000..42e361d Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/getcwd differ diff --git a/testcase/basic/loongarch64-unknown-none/getdents b/testcase/basic/loongarch64-unknown-none/getdents new file mode 100644 index 0000000..7c66353 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/getdents differ diff --git a/testcase/basic/loongarch64-unknown-none/getpid b/testcase/basic/loongarch64-unknown-none/getpid new file mode 100644 index 0000000..34064f7 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/getpid differ diff --git a/testcase/basic/loongarch64-unknown-none/getppid b/testcase/basic/loongarch64-unknown-none/getppid new file mode 100644 index 0000000..5137ae7 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/getppid differ diff --git a/testcase/basic/loongarch64-unknown-none/gettimeofday b/testcase/basic/loongarch64-unknown-none/gettimeofday new file mode 100644 index 0000000..a904004 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/gettimeofday differ diff --git a/testcase/basic/loongarch64-unknown-none/initproc b/testcase/basic/loongarch64-unknown-none/initproc new file mode 100644 index 0000000..37931e1 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/initproc differ diff --git a/testcase/basic/loongarch64-unknown-none/mkdir_ b/testcase/basic/loongarch64-unknown-none/mkdir_ new file mode 100644 index 0000000..cd3f60a Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/mkdir_ differ diff --git a/testcase/basic/loongarch64-unknown-none/mmap b/testcase/basic/loongarch64-unknown-none/mmap new file mode 100644 index 0000000..d33d813 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/mmap differ diff --git a/testcase/basic/loongarch64-unknown-none/mount b/testcase/basic/loongarch64-unknown-none/mount new file mode 100644 index 0000000..b30e2d1 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/mount differ diff --git a/testcase/basic/loongarch64-unknown-none/munmap b/testcase/basic/loongarch64-unknown-none/munmap new file mode 100644 index 0000000..444a7ad Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/munmap differ diff --git a/testcase/basic/loongarch64-unknown-none/open b/testcase/basic/loongarch64-unknown-none/open new file mode 100644 index 0000000..f528682 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/open differ diff --git a/testcase/basic/loongarch64-unknown-none/openat b/testcase/basic/loongarch64-unknown-none/openat new file mode 100644 index 0000000..30b5b45 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/openat differ diff --git a/testcase/basic/loongarch64-unknown-none/pipe b/testcase/basic/loongarch64-unknown-none/pipe new file mode 100644 index 0000000..47adc45 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/pipe differ diff --git a/testcase/basic/loongarch64-unknown-none/read b/testcase/basic/loongarch64-unknown-none/read new file mode 100644 index 0000000..b577a58 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/read differ diff --git a/testcase/basic/riscv64/run-all.sh b/testcase/basic/loongarch64-unknown-none/run-all.sh similarity index 100% rename from testcase/basic/riscv64/run-all.sh rename to testcase/basic/loongarch64-unknown-none/run-all.sh diff --git a/testcase/basic/loongarch64-unknown-none/sleep b/testcase/basic/loongarch64-unknown-none/sleep new file mode 100644 index 0000000..993d546 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/sleep differ diff --git a/testcase/basic/loongarch64-unknown-none/test_echo b/testcase/basic/loongarch64-unknown-none/test_echo new file mode 100644 index 0000000..a3a4809 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/test_echo differ diff --git a/testcase/basic/riscv64/text.txt b/testcase/basic/loongarch64-unknown-none/text.txt similarity index 100% rename from testcase/basic/riscv64/text.txt rename to testcase/basic/loongarch64-unknown-none/text.txt diff --git a/testcase/basic/loongarch64-unknown-none/times b/testcase/basic/loongarch64-unknown-none/times new file mode 100644 index 0000000..1bc91d6 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/times differ diff --git a/testcase/basic/loongarch64-unknown-none/umount b/testcase/basic/loongarch64-unknown-none/umount new file mode 100644 index 0000000..8164f2b Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/umount differ diff --git a/testcase/basic/loongarch64-unknown-none/uname b/testcase/basic/loongarch64-unknown-none/uname new file mode 100644 index 0000000..482347b Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/uname differ diff --git a/testcase/basic/loongarch64-unknown-none/unlink b/testcase/basic/loongarch64-unknown-none/unlink new file mode 100644 index 0000000..fed2a63 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/unlink differ diff --git a/testcase/basic/loongarch64-unknown-none/user_shell b/testcase/basic/loongarch64-unknown-none/user_shell new file mode 100644 index 0000000..ea0485d Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/user_shell differ diff --git a/testcase/basic/loongarch64-unknown-none/wait b/testcase/basic/loongarch64-unknown-none/wait new file mode 100644 index 0000000..78a0bd5 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/wait differ diff --git a/testcase/basic/loongarch64-unknown-none/waitpid b/testcase/basic/loongarch64-unknown-none/waitpid new file mode 100644 index 0000000..539df71 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/waitpid differ diff --git a/testcase/basic/loongarch64-unknown-none/write b/testcase/basic/loongarch64-unknown-none/write new file mode 100644 index 0000000..8148c91 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/write differ diff --git a/testcase/basic/loongarch64-unknown-none/yield b/testcase/basic/loongarch64-unknown-none/yield new file mode 100644 index 0000000..3879b65 Binary files /dev/null and b/testcase/basic/loongarch64-unknown-none/yield differ diff --git a/testcase/basic/riscv64/brk b/testcase/basic/riscv64gc-unknown-none-elf/brk similarity index 100% rename from testcase/basic/riscv64/brk rename to testcase/basic/riscv64gc-unknown-none-elf/brk diff --git a/testcase/basic/riscv64/busybox b/testcase/basic/riscv64gc-unknown-none-elf/busybox similarity index 100% rename from testcase/basic/riscv64/busybox rename to testcase/basic/riscv64gc-unknown-none-elf/busybox diff --git a/testcase/basic/riscv64gc-unknown-none-elf/busybox_cmd.txt b/testcase/basic/riscv64gc-unknown-none-elf/busybox_cmd.txt new file mode 100644 index 0000000..32ebf47 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/busybox_cmd.txt @@ -0,0 +1,55 @@ +echo "#### independent command test" +ash -c exit +sh -c exit +basename /aaa/bbb +cal +clear +date +df +dirname /aaa/bbb +dmesg +du +expr 1 + 1 +false +true +which ls +uname +uptime +printf "abc\n" +ps +pwd +free +hwclock +kill 10 +ls +sleep 1 +echo "#### file opration test" +touch test.txt +echo "hello world" > test.txt +cat test.txt +cut -c 3 test.txt +od test.txt +head test.txt +tail test.txt +hexdump -C test.txt +md5sum test.txt +echo "ccccccc" >> test.txt +echo "bbbbbbb" >> test.txt +echo "aaaaaaa" >> test.txt +echo "2222222" >> test.txt +echo "1111111" >> test.txt +echo "bbbbbbb" >> test.txt +sort test.txt | ./busybox uniq +stat test.txt +strings test.txt +wc test.txt +[ -f test.txt ] +more test.txt +rm test.txt +mkdir test_dir +mv test_dir test +rmdir test +grep hello busybox_cmd.txt +cp busybox_cmd.txt busybox_cmd.bak +rm busybox_cmd.bak +find -name "busybox_cmd.txt" diff --git a/testcase/basic/riscv64/busybox_testcode.sh b/testcase/basic/riscv64gc-unknown-none-elf/busybox_testcode.sh similarity index 100% rename from testcase/basic/riscv64/busybox_testcode.sh rename to testcase/basic/riscv64gc-unknown-none-elf/busybox_testcode.sh diff --git a/testcase/basic/riscv64gc-unknown-none-elf/busyboxmusl b/testcase/basic/riscv64gc-unknown-none-elf/busyboxmusl new file mode 100755 index 0000000..157016f Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/busyboxmusl differ diff --git a/testcase/basic/riscv64/chdir b/testcase/basic/riscv64gc-unknown-none-elf/chdir similarity index 100% rename from testcase/basic/riscv64/chdir rename to testcase/basic/riscv64gc-unknown-none-elf/chdir diff --git a/testcase/basic/riscv64/clone b/testcase/basic/riscv64gc-unknown-none-elf/clone similarity index 100% rename from testcase/basic/riscv64/clone rename to testcase/basic/riscv64gc-unknown-none-elf/clone diff --git a/testcase/basic/riscv64/close b/testcase/basic/riscv64gc-unknown-none-elf/close similarity index 100% rename from testcase/basic/riscv64/close rename to testcase/basic/riscv64gc-unknown-none-elf/close diff --git a/testcase/basic/riscv64gc-unknown-none-elf/date.lua b/testcase/basic/riscv64gc-unknown-none-elf/date.lua new file mode 100644 index 0000000..820ddb9 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/date.lua @@ -0,0 +1,10 @@ + + +local tbCurrentTime = os.date("*t") + +if tbCurrentTime ~= nil then + return 0 +else + return -1 +end + diff --git a/testcase/basic/riscv64/dup b/testcase/basic/riscv64gc-unknown-none-elf/dup similarity index 100% rename from testcase/basic/riscv64/dup rename to testcase/basic/riscv64gc-unknown-none-elf/dup diff --git a/testcase/basic/riscv64/dup2 b/testcase/basic/riscv64gc-unknown-none-elf/dup2 similarity index 100% rename from testcase/basic/riscv64/dup2 rename to testcase/basic/riscv64gc-unknown-none-elf/dup2 diff --git a/testcase/basic/riscv64gc-unknown-none-elf/entry-dynamic.exe b/testcase/basic/riscv64gc-unknown-none-elf/entry-dynamic.exe new file mode 100644 index 0000000..7f6d71c Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/entry-dynamic.exe differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/entry-static.exe b/testcase/basic/riscv64gc-unknown-none-elf/entry-static.exe new file mode 100644 index 0000000..0fd7056 Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/entry-static.exe differ diff --git a/testcase/basic/riscv64/execve b/testcase/basic/riscv64gc-unknown-none-elf/execve similarity index 100% rename from testcase/basic/riscv64/execve rename to testcase/basic/riscv64gc-unknown-none-elf/execve diff --git a/testcase/basic/riscv64/exit b/testcase/basic/riscv64gc-unknown-none-elf/exit similarity index 100% rename from testcase/basic/riscv64/exit rename to testcase/basic/riscv64gc-unknown-none-elf/exit diff --git a/testcase/basic/riscv64gc-unknown-none-elf/file_io.lua b/testcase/basic/riscv64gc-unknown-none-elf/file_io.lua new file mode 100644 index 0000000..86d7815 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/file_io.lua @@ -0,0 +1,9 @@ +-- Opens a file in write mode +file = io.open("test.txt", "w") + +if file ~= nil then + file:close() + return 0 +else + return -1 +end diff --git a/testcase/basic/riscv64/fork b/testcase/basic/riscv64gc-unknown-none-elf/fork similarity index 100% rename from testcase/basic/riscv64/fork rename to testcase/basic/riscv64gc-unknown-none-elf/fork diff --git a/testcase/basic/riscv64/fstat b/testcase/basic/riscv64gc-unknown-none-elf/fstat similarity index 100% rename from testcase/basic/riscv64/fstat rename to testcase/basic/riscv64gc-unknown-none-elf/fstat diff --git a/testcase/basic/riscv64/getcwd b/testcase/basic/riscv64gc-unknown-none-elf/getcwd similarity index 100% rename from testcase/basic/riscv64/getcwd rename to testcase/basic/riscv64gc-unknown-none-elf/getcwd diff --git a/testcase/basic/riscv64/getdents b/testcase/basic/riscv64gc-unknown-none-elf/getdents similarity index 100% rename from testcase/basic/riscv64/getdents rename to testcase/basic/riscv64gc-unknown-none-elf/getdents diff --git a/testcase/basic/riscv64/getpid b/testcase/basic/riscv64gc-unknown-none-elf/getpid similarity index 100% rename from testcase/basic/riscv64/getpid rename to testcase/basic/riscv64gc-unknown-none-elf/getpid diff --git a/testcase/basic/riscv64/getppid b/testcase/basic/riscv64gc-unknown-none-elf/getppid similarity index 100% rename from testcase/basic/riscv64/getppid rename to testcase/basic/riscv64gc-unknown-none-elf/getppid diff --git a/testcase/basic/riscv64/gettimeofday b/testcase/basic/riscv64gc-unknown-none-elf/gettimeofday similarity index 100% rename from testcase/basic/riscv64/gettimeofday rename to testcase/basic/riscv64gc-unknown-none-elf/gettimeofday diff --git a/testcase/basic/riscv64/initproc b/testcase/basic/riscv64gc-unknown-none-elf/initproc similarity index 100% rename from testcase/basic/riscv64/initproc rename to testcase/basic/riscv64gc-unknown-none-elf/initproc diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lib/dlopen_dso.so b/testcase/basic/riscv64gc-unknown-none-elf/lib/dlopen_dso.so new file mode 100644 index 0000000..77a6540 Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/lib/dlopen_dso.so differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lib/libc.so b/testcase/basic/riscv64gc-unknown-none-elf/lib/libc.so new file mode 100644 index 0000000..814a24c --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/lib/libc.so @@ -0,0 +1,5 @@ +/* GNU ld script + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ +OUTPUT_FORMAT(elf64-littleriscv) +GROUP ( /usr/riscv64-linux-gnu/lib/libc.so.6 /usr/riscv64-linux-gnu/lib/libc_nonshared.a AS_NEEDED ( /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 ) ) diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_align_dso.so b/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_align_dso.so new file mode 100644 index 0000000..dd0d9cf Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_align_dso.so differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_get_new-dtv_dso.so b/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_get_new-dtv_dso.so new file mode 100644 index 0000000..2c6c01f Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_get_new-dtv_dso.so differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_init_dso.so b/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_init_dso.so new file mode 100644 index 0000000..4c3f59e Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/lib/tls_init_dso.so differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lmbench b/testcase/basic/riscv64gc-unknown-none-elf/lmbench new file mode 100644 index 0000000..cf23f18 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/lmbench @@ -0,0 +1,485 @@ +#!/bin/sh + +# lmbench - run the lmbench benchmark suite. +# +# Hacked by Larry McVoy (lm@sun.com, lm@sgi.com, lm@bitmover.com). +# Copyright (c) 1994 Larry McVoy. GPLed software. +# $Id$ + +# Make sure we can find: ./cmd, df, and netstat +PATH=.:../../scripts:$PATH:/etc:/usr/etc:/sbin:/usr/sbin +export PATH + +if [ -f $1 ] +then . $1 + echo Using config in $1 >> ${OUTPUT} +else echo Using defaults >> ${OUTPUT} + ENOUGH=1000000 + TIMING_O=0 + LOOP_O=0 + LINE_SIZE=512 +fi +export ENOUGH TIMING_O LOOP_O SYNC_MAX LINE_SIZE LMBENCH_SCHED + +if [ X$FILE = X ] +then FILE=/tmp/XXX + touch $FILE || echo Can not create $FILE >> ${OUTPUT} +fi +if [ X$MB = X ] +then MB=8 +fi +AVAILKB=`expr $MB \* 1024` + +# Figure out how big we can go for stuff that wants to use +# all and half of memory. +HALF="512 1k 2k 4k 8k 16k 32k 64k 128k 256k 512k 1m" +ALL="$HALF 2m" +i=4 +while [ $i -le $MB ] +do + ALL="$ALL ${i}m" + h=`expr $i / 2` + HALF="$HALF ${h}m" + i=`expr $i \* 2` +done + + +if [ X$FSDIR = X ] +then FSDIR=/usr/tmp/lat_fs +fi +MP=N +if [ $SYNC_MAX -gt 1 ] +then if [ "X$DISKS" != X ] + then echo "MP and disks are mutually exclusive (sorry)" + exit 1 + fi + if [ "X$REMOTE" != X ] + then echo "MP and remote networking are mutually exclusive (sorry)" + exit 1 + fi + MP=Y +fi + +# Figure out as much stuff as we can about this system. +# Sure would be nice if everyone had SGI's "hinv". +echo \[lmbench3.0 results for `uname -a`] 1>&2 +echo \[LMBENCH_VER: ] 1>&2 +echo \[BENCHMARK_HARDWARE: ${BENCHMARK_HARDWARE}] 1>&2 +echo \[BENCHMARK_OS: ${BENCHMARK_OS}] 1>&2 +echo \[ALL: ${ALL}] 1>&2 +echo \[DISKS: ${DISKS}] 1>&2 +echo \[DISK_DESC: ${DISK_DESC}] 1>&2 +echo \[ENOUGH: ${ENOUGH}] 1>&2 +echo \[FAST: ${FAST}] 1>&2 +echo \[FASTMEM: ${FASTMEM}] 1>&2 +echo \[FILE: ${FILE}] 1>&2 +echo \[FSDIR: ${FSDIR}] 1>&2 +echo \[HALF: ${HALF}] 1>&2 +echo \[INFO: ${INFO}] 1>&2 +echo \[LINE_SIZE: ${LINE_SIZE}] 1>&2 +echo \[LOOP_O: ${LOOP_O}] 1>&2 +echo \[MB: ${MB}] 1>&2 +echo \[MHZ: ${MHZ}] 1>&2 +echo \[MOTHERBOARD: ${MOTHERBOARD}] 1>&2 +echo \[NETWORKS: ${NETWORKS}] 1>&2 +echo \[PROCESSORS: ${PROCESSORS}] 1>&2 +echo \[REMOTE: ${REMOTE}] 1>&2 +echo \[SLOWFS: ${SLOWFS}] 1>&2 +echo \[OS: ${OS}] 1>&2 +echo \[SYNC_MAX: ${SYNC_MAX}] 1>&2 +echo \[LMBENCH_SCHED: $LMBENCH_SCHED] 1>&2 +echo \[TIMING_O: ${TIMING_O}] 1>&2 +echo \[LMBENCH VERSION: ${VERSION}] 1>&2 +echo \[USER: $USER] 1>&2 +echo \[HOSTNAME: `hostname`] 1>&2 +echo \[NODENAME: `uname -n`] 1>&2 +echo \[SYSNAME: `uname -s`] 1>&2 +echo \[PROCESSOR: `uname -p`] 1>&2 +echo \[MACHINE: `uname -m`] 1>&2 +echo \[RELEASE: `uname -r`] 1>&2 +echo \[VERSION: `uname -v`] 1>&2 + +echo \[`date`] 1>&2 +echo \[`uptime`] 1>&2 +netstat -i | while read i +do echo \[net: "$i"] 1>&2 + interface=`echo $i | awk '{print $1}'` + case $interface in + *ame) ;; + *ace) ;; + *ernel) ;; + *) ifconfig $interface | while read i + do echo \[if: "$i"] 1>&2 + done + ;; + esac +done + +mount | while read i +do echo \[mount: "$i"] 1>&2 +done + +STAT=$FSDIR/lmbench +mkdir $FSDIR 2>/dev/null +touch $STAT 2>/dev/null +if [ ! -f $STAT ] +then echo "Can't make a file - $STAT - in $FSDIR" >> ${OUTPUT} + touch $STAT + exit 1 +fi +if [ X$SYNC != X ] +then /bin/rm -rf $SYNC + mkdir -p $SYNC 2>/dev/null + if [ ! -d $SYNC ] + then echo "Can't make $SYNC" >> ${OUTPUT} + exit 1 + fi +fi + +date >> ${OUTPUT} +echo Latency measurements >> ${OUTPUT} +msleep 250 +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_SYSCALL = XYES ]; then + lat_syscall -P $SYNC_MAX null + lat_syscall -P $SYNC_MAX read + lat_syscall -P $SYNC_MAX write + lat_syscall -P $SYNC_MAX stat $STAT + lat_syscall -P $SYNC_MAX fstat $STAT + lat_syscall -P $SYNC_MAX open $STAT +fi +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_SELECT = XYES ]; then + for i in 10 100 250 500 + do lat_select -n $i -P $SYNC_MAX file + done + for i in 10 100 250 500 + do lat_select -n $i -P $SYNC_MAX tcp + done +fi +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_SIG = XYES ]; then + lat_sig -P $SYNC_MAX install + lat_sig -P $SYNC_MAX catch + lat_sig -P $SYNC_MAX prot lat_sig +fi +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_PIPE = XYES ]; then + lat_pipe -P $SYNC_MAX +fi +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_UNIX = XYES ]; then + lat_unix -P $SYNC_MAX +fi +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_PROC = XYES ]; then + cp hello /tmp/hello + for i in fork exec shell + do lat_proc -P $SYNC_MAX $i + done + rm -f /tmp/hello +fi +if [ X$BENCHMARK_HARDWARE = XYES -o X$BENCHMARK_OPS = XYES ]; then + lat_ops + par_ops +fi + +rm -f $FILE + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_FILE = XYES ]; then + # choose one sample bandwidth from the middle of the pack + sample=`expr $SYNC_MAX / 2` + i=0 + while [ $i -lt $SYNC_MAX ]; do + if [ $i -eq $sample ]; then + lmdd label="File $FILE write bandwidth: " \ + of=$FILE move=${MB}m fsync=1 print=3 & + else + lmdd label="File $FILE write bandwidth: " \ + of=$FILE.$i move=${MB}m fsync=1 print=3 \ + >/dev/null 2>&1 & + fi + i=`expr $i + 1` + done + wait + rm -f $FILE.* +fi + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_PAGEFAULT = XYES ]; then + lat_pagefault -P $SYNC_MAX $FILE +fi +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_MMAP = XYES ]; then + echo "" 1>&2 + echo \"mappings 1>&2 + for i in $ALL + do lat_mmap -P $SYNC_MAX $i $FILE + done + echo "" 1>&2 +fi +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_FILE = XYES ]; then + if [ X$SLOWFS != XYES ] + then date >> ${OUTPUT} + echo Calculating file system latency >> ${OUTPUT} + msleep 250 + echo '"File system latency' 1>&2 + lat_fs $FSDIR + echo "" 1>&2 + fi +fi + +if [ X$BENCHMARK_HARDWARE = XYES ]; then + if [ X"$DISKS" != X ] + then for i in $DISKS + do if [ -r $i ] + then echo "Calculating disk zone bw & seek times" \ + >> ${OUTPUT} + msleep 250 + disk $i + echo "" 1>&2 + fi + done + fi +fi + +date >> ${OUTPUT} +echo Local networking >> ${OUTPUT} +if [ ! -d ../../src/webpage-lm ] +then (cd ../../src && tar xf webpage-lm.tar) + sync + sleep 1 +fi +SERVERS="lat_udp lat_tcp lat_rpc lat_connect bw_tcp" +for server in $SERVERS; do $server -s; done +DOCROOT=../../src/webpage-lm lmhttp 8008 & +sleep 2; + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_UDP = XYES ]; then + lat_udp -P $SYNC_MAX localhost +fi +lat_udp -S localhost + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_TCP = XYES ]; then + lat_tcp -P $SYNC_MAX localhost +fi +lat_tcp -S localhost + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_RPC = XYES ]; then + lat_rpc -P $SYNC_MAX -p udp localhost + lat_rpc -P $SYNC_MAX -p tcp localhost +fi +lat_rpc -S localhost + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_CONNECT = XYES ]; then + if [ $SYNC_MAX = 1 ]; then lat_connect localhost; fi +fi +lat_connect -S localhost + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_TCP = XYES ]; then + echo "" 1>&2 + echo "Socket bandwidth using localhost" 1>&2 + for m in 1 64 128 256 512 1024 1437 10M; do + bw_tcp -P $SYNC_MAX -m $m localhost; + done + echo "" 1>&2 +fi +bw_tcp -S localhost + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_HTTP = XYES ]; then + # I want a hot cache number + lat_http localhost 8008 < ../../src/webpage-lm/URLS > /dev/null 2>&1 + lat_http localhost 8008 < ../../src/webpage-lm/URLS +fi +lat_http -S localhost 8008 + +for remote in $REMOTE +do + echo Networking to $remote >> ${OUTPUT} + $RCP $SERVERS lmhttp ../../src/webpage-lm.tar ${remote}:/tmp + for server in $SERVERS + do $RSH $remote -n /tmp/$server -s & + done + $RSH $remote -n 'cd /tmp; tar xf webpage-lm.tar; cd webpage-lm; ../lmhttp 8008' & + sleep 10 + echo "[ Networking remote to $remote: `$RSH $remote uname -a` ]" 1>&2 + if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_UDP = XYES ]; then + lat_udp -P $SYNC_MAX $remote; + fi + lat_udp -S $remote; + + if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_TCP = XYES ]; then + lat_tcp -P $SYNC_MAX $remote; + fi + lat_tcp -S $remote; + + if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_RPC = XYES ]; then + lat_rpc -P $SYNC_MAX -p udp $remote; + lat_rpc -P $SYNC_MAX -p tcp $remote; + fi + lat_rpc -S $remote; + + if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_CONNECT = XYES ]; then + if [ $SYNC_MAX = 1 ]; then lat_connect $remote; fi + fi + lat_connect -S $remote; + + if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_TCP = XYES ]; then + echo "Socket bandwidth using $remote" 1>&2 + for m in 1 64 128 256 512 1024 1437 10M; do + bw_tcp -P $SYNC_MAX -m $m $remote; + done + echo "" 1>&2 + fi + bw_tcp -S $remote + + if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_HTTP = XYES ]; then + # I want a hot cache number + lat_http $remote 8008 < ../../src/webpage-lm/URLS > /dev/null 2>&1 + lat_http $remote 8008 < ../../src/webpage-lm/URLS + fi + lat_http -S $remote 8008 + + RM= + for server in $SERVERS + do RM="/tmp/$server $RM" + done + $RSH $remote rm $RM +done + +date >> ${OUTPUT} +echo Bandwidth measurements >> ${OUTPUT} +msleep 250 + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_UNIX = XYES ]; then + bw_unix -P $SYNC_MAX +fi + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_PIPE = XYES ]; then + bw_pipe -P $SYNC_MAX +fi + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_FILE = XYES ]; then + echo "" 1>&2 + echo \"read bandwidth 1>&2 + for i in $ALL + do bw_file_rd -P $SYNC_MAX $i io_only $FILE + done + echo "" 1>&2 + + echo \"read open2close bandwidth 1>&2 + for i in $ALL + do bw_file_rd -P $SYNC_MAX $i open2close $FILE + done + echo "" 1>&2 +fi + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_MMAP = XYES ]; then + echo "" 1>&2 + echo \"Mmap read bandwidth 1>&2 + for i in $ALL + do bw_mmap_rd -P $SYNC_MAX $i mmap_only $FILE + done + echo "" 1>&2 + + echo \"Mmap read open2close bandwidth 1>&2 + for i in $ALL + do bw_mmap_rd -P $SYNC_MAX $i open2close $FILE + done + echo "" 1>&2 + rm -f $FILE +fi + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_HARDWARE = XYES \ + -o X$BENCHMARK_BCOPY = XYES ]; then + echo "" 1>&2 + echo \"libc bcopy unaligned 1>&2 + for i in $HALF; do bw_mem -P $SYNC_MAX $i bcopy; done; echo "" 1>&2 + + echo \"libc bcopy aligned 1>&2 + for i in $HALF; do bw_mem -P $SYNC_MAX $i bcopy conflict; done; echo "" 1>&2 + + echo "Memory bzero bandwidth" 1>&2 + for i in $ALL; do bw_mem -P $SYNC_MAX $i bzero; done; echo "" 1>&2 + + echo \"unrolled bcopy unaligned 1>&2 + for i in $HALF; do bw_mem -P $SYNC_MAX $i fcp; done; echo "" 1>&2 + + echo \"unrolled partial bcopy unaligned 1>&2 + for i in $HALF; do bw_mem -P $SYNC_MAX $i cp; done; echo "" 1>&2 + + echo "Memory read bandwidth" 1>&2 + for i in $ALL; do bw_mem -P $SYNC_MAX $i frd; done; echo "" 1>&2 + + echo "Memory partial read bandwidth" 1>&2 + for i in $ALL; do bw_mem -P $SYNC_MAX $i rd; done; echo "" 1>&2 + + echo "Memory write bandwidth" 1>&2 + for i in $ALL; do bw_mem -P $SYNC_MAX $i fwr; done; echo "" 1>&2 + + echo "Memory partial write bandwidth" 1>&2 + for i in $ALL; do bw_mem -P $SYNC_MAX $i wr; done; echo "" 1>&2 + + echo "Memory partial read/write bandwidth" 1>&2 + for i in $ALL; do bw_mem -P $SYNC_MAX $i rdwr; done; echo "" 1>&2 +fi + +if [ X$BENCHMARK_OS = XYES -o X$BENCHMARK_CTX = XYES ]; then + date >> ${OUTPUT} + echo Calculating context switch overhead >> ${OUTPUT} + msleep 250 + if [ $MB -ge 8 ] + then CTX="0 4 8 16 32 64" + N="2 4 8 16 24 32 64 96" + else + CTX="0 4 8 16 32" + N="2 4 8 16 24 32 64 96" + fi + + echo "" 1>&2 + for size in $CTX + do + lat_ctx -P $SYNC_MAX -s $size $N + done + echo "" 1>&2 +fi + +if [ X$BENCHMARK_HARDWARE = XYES -o X$BENCHMARK_MEM = XYES ]; then + if [ $SYNC_MAX = 1 ]; then + date >> ${OUTPUT} + echo Calculating effective TLB size >> ${OUTPUT} + msleep 250 + tlb -L $LINE_SIZE -M ${MB}M + echo "" 1>&2 + + date >> ${OUTPUT} + echo Calculating memory load parallelism >> ${OUTPUT} + msleep 250 + echo "Memory load parallelism" 1>&2 + par_mem -L $LINE_SIZE -M ${MB}M + echo "" 1>&2 + +# date >> ${OUTPUT} +# echo Calculating cache parameters >> ${OUTPUT} +# msleep 250 +# cache -L $LINE_SIZE -M ${MB}M + fi + + date >> ${OUTPUT} + echo McCalpin\'s STREAM benchmark >> ${OUTPUT} + msleep 250 + stream -P $SYNC_MAX -M ${MB}M + stream -P $SYNC_MAX -v 2 -M ${MB}M + + date >> ${OUTPUT} + echo Calculating memory load latency >> ${OUTPUT} + msleep 250 + echo "" 1>&2 + echo "Memory load latency" 1>&2 + if [ X$FASTMEM = XYES ] + then lat_mem_rd -P $SYNC_MAX $MB 128 + else lat_mem_rd -P $SYNC_MAX $MB 16 32 64 128 256 512 1024 + fi + echo "" 1>&2 + echo "Random load latency" 1>&2 + lat_mem_rd -t -P $SYNC_MAX $MB 16 + echo "" 1>&2 +fi + +date >> ${OUTPUT} +echo '' 1>&2 +echo \[`date`] 1>&2 + +exit 0 diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lmbench_all b/testcase/basic/riscv64gc-unknown-none-elf/lmbench_all new file mode 100644 index 0000000..941dfd6 Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/lmbench_all differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lua b/testcase/basic/riscv64gc-unknown-none-elf/lua new file mode 100644 index 0000000..9fd7be7 Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/lua differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/lua_testcode.sh b/testcase/basic/riscv64gc-unknown-none-elf/lua_testcode.sh new file mode 100644 index 0000000..0d78344 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/lua_testcode.sh @@ -0,0 +1,13 @@ +./busybox echo "#### OS COMP TEST GROUP START lua-glibc ####" + +./busybox sh ./test.sh date.lua +./busybox sh ./test.sh file_io.lua +./busybox sh ./test.sh max_min.lua +./busybox sh ./test.sh random.lua +./busybox sh ./test.sh remove.lua +./busybox sh ./test.sh round_num.lua +./busybox sh ./test.sh sin30.lua +./busybox sh ./test.sh sort.lua +./busybox sh ./test.sh strings.lua + +./busybox echo "#### OS COMP TEST GROUP END lua-glibc ####" diff --git a/testcase/basic/riscv64gc-unknown-none-elf/max_min.lua b/testcase/basic/riscv64gc-unknown-none-elf/max_min.lua new file mode 100644 index 0000000..7381d61 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/max_min.lua @@ -0,0 +1,9 @@ + + +if math.max(2, 3, 2, 14, 2, 30, -3) == 30 and math.min(2, 3, 2, 14, 2, 30, -3) == -3 then + return 0 +else + return -1 +end + + diff --git a/testcase/basic/riscv64/mkdir_ b/testcase/basic/riscv64gc-unknown-none-elf/mkdir_ similarity index 100% rename from testcase/basic/riscv64/mkdir_ rename to testcase/basic/riscv64gc-unknown-none-elf/mkdir_ diff --git a/testcase/basic/riscv64/mmap b/testcase/basic/riscv64gc-unknown-none-elf/mmap similarity index 100% rename from testcase/basic/riscv64/mmap rename to testcase/basic/riscv64gc-unknown-none-elf/mmap diff --git a/testcase/basic/riscv64/mnt/test_mount b/testcase/basic/riscv64gc-unknown-none-elf/mnt/test_mount similarity index 100% rename from testcase/basic/riscv64/mnt/test_mount rename to testcase/basic/riscv64gc-unknown-none-elf/mnt/test_mount diff --git a/testcase/basic/riscv64/mount b/testcase/basic/riscv64gc-unknown-none-elf/mount similarity index 100% rename from testcase/basic/riscv64/mount rename to testcase/basic/riscv64gc-unknown-none-elf/mount diff --git a/testcase/basic/riscv64/munmap b/testcase/basic/riscv64gc-unknown-none-elf/munmap similarity index 100% rename from testcase/basic/riscv64/munmap rename to testcase/basic/riscv64gc-unknown-none-elf/munmap diff --git a/testcase/basic/riscv64/open b/testcase/basic/riscv64gc-unknown-none-elf/open similarity index 100% rename from testcase/basic/riscv64/open rename to testcase/basic/riscv64gc-unknown-none-elf/open diff --git a/testcase/basic/riscv64/openat b/testcase/basic/riscv64gc-unknown-none-elf/openat similarity index 100% rename from testcase/basic/riscv64/openat rename to testcase/basic/riscv64gc-unknown-none-elf/openat diff --git a/testcase/basic/riscv64/pipe b/testcase/basic/riscv64gc-unknown-none-elf/pipe similarity index 100% rename from testcase/basic/riscv64/pipe rename to testcase/basic/riscv64gc-unknown-none-elf/pipe diff --git a/testcase/basic/riscv64gc-unknown-none-elf/random.lua b/testcase/basic/riscv64gc-unknown-none-elf/random.lua new file mode 100644 index 0000000..f3c2779 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/random.lua @@ -0,0 +1,13 @@ + + +math.randomseed(os.time()) + +-- num应该大于等于0,小于1 +num = math.random() +if num >= 0 and num < 1 then + return 0 +else + return -1 +end + + diff --git a/testcase/basic/riscv64/read b/testcase/basic/riscv64gc-unknown-none-elf/read similarity index 100% rename from testcase/basic/riscv64/read rename to testcase/basic/riscv64gc-unknown-none-elf/read diff --git a/testcase/basic/riscv64gc-unknown-none-elf/remove.lua b/testcase/basic/riscv64gc-unknown-none-elf/remove.lua new file mode 100644 index 0000000..37995ca --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/remove.lua @@ -0,0 +1,10 @@ +file = io.open("test.txt", "r") + +if file then + file:close() + if os.remove("test.txt") ~= nil then + return 0 + else + return -1 + end +end diff --git a/testcase/basic/riscv64gc-unknown-none-elf/round_num.lua b/testcase/basic/riscv64gc-unknown-none-elf/round_num.lua new file mode 100644 index 0000000..8f60467 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/round_num.lua @@ -0,0 +1,9 @@ + + +if math.floor(5.6) == 5 and math.ceil(5.6) == 6 then + return 0 +else + return -1 +end + + diff --git a/testcase/basic/riscv64gc-unknown-none-elf/run-all.sh b/testcase/basic/riscv64gc-unknown-none-elf/run-all.sh new file mode 100644 index 0000000..1055882 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/run-all.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +tests=" +brk +chdir +clone +close +dup2 +dup +execve +exit +fork +fstat +getcwd +getdents +getpid +getppid +gettimeofday +mkdir_ +mmap +mount +munmap +openat +open +pipe +read +times +umount +uname +unlink +wait +waitpid +write +yield.sh +" +for i in $tests +do + echo "Testing $i :" + ./$i +done diff --git a/testcase/basic/riscv64gc-unknown-none-elf/run-dynamic.sh b/testcase/basic/riscv64gc-unknown-none-elf/run-dynamic.sh new file mode 100644 index 0000000..cc894b5 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/run-dynamic.sh @@ -0,0 +1,110 @@ +./runtest.exe -w entry-dynamic.exe argv +./runtest.exe -w entry-dynamic.exe basename +./runtest.exe -w entry-dynamic.exe clocale_mbfuncs +./runtest.exe -w entry-dynamic.exe clock_gettime +./runtest.exe -w entry-dynamic.exe dirname +./runtest.exe -w entry-dynamic.exe dlopen +./runtest.exe -w entry-dynamic.exe env +./runtest.exe -w entry-dynamic.exe fdopen +./runtest.exe -w entry-dynamic.exe fnmatch +./runtest.exe -w entry-dynamic.exe fscanf +./runtest.exe -w entry-dynamic.exe fwscanf +./runtest.exe -w entry-dynamic.exe iconv_open +./runtest.exe -w entry-dynamic.exe inet_pton +./runtest.exe -w entry-dynamic.exe mbc +./runtest.exe -w entry-dynamic.exe memstream +./runtest.exe -w entry-dynamic.exe pthread_cancel_points +./runtest.exe -w entry-dynamic.exe pthread_cancel +./runtest.exe -w entry-dynamic.exe pthread_cond +./runtest.exe -w entry-dynamic.exe pthread_tsd +./runtest.exe -w entry-dynamic.exe qsort +./runtest.exe -w entry-dynamic.exe random +./runtest.exe -w entry-dynamic.exe search_hsearch +./runtest.exe -w entry-dynamic.exe search_insque +./runtest.exe -w entry-dynamic.exe search_lsearch +./runtest.exe -w entry-dynamic.exe search_tsearch +./runtest.exe -w entry-dynamic.exe sem_init +./runtest.exe -w entry-dynamic.exe setjmp +./runtest.exe -w entry-dynamic.exe snprintf +./runtest.exe -w entry-dynamic.exe socket +./runtest.exe -w entry-dynamic.exe sscanf +./runtest.exe -w entry-dynamic.exe sscanf_long +./runtest.exe -w entry-dynamic.exe stat +./runtest.exe -w entry-dynamic.exe strftime +./runtest.exe -w entry-dynamic.exe string +./runtest.exe -w entry-dynamic.exe string_memcpy +./runtest.exe -w entry-dynamic.exe string_memmem +./runtest.exe -w entry-dynamic.exe string_memset +./runtest.exe -w entry-dynamic.exe string_strchr +./runtest.exe -w entry-dynamic.exe string_strcspn +./runtest.exe -w entry-dynamic.exe string_strstr +./runtest.exe -w entry-dynamic.exe strptime +./runtest.exe -w entry-dynamic.exe strtod +./runtest.exe -w entry-dynamic.exe strtod_simple +./runtest.exe -w entry-dynamic.exe strtof +./runtest.exe -w entry-dynamic.exe strtol +./runtest.exe -w entry-dynamic.exe strtold +./runtest.exe -w entry-dynamic.exe swprintf +./runtest.exe -w entry-dynamic.exe tgmath +./runtest.exe -w entry-dynamic.exe time +./runtest.exe -w entry-dynamic.exe tls_init +./runtest.exe -w entry-dynamic.exe tls_local_exec +./runtest.exe -w entry-dynamic.exe udiv +./runtest.exe -w entry-dynamic.exe ungetc +./runtest.exe -w entry-dynamic.exe utime +./runtest.exe -w entry-dynamic.exe wcsstr +./runtest.exe -w entry-dynamic.exe wcstol +./runtest.exe -w entry-dynamic.exe daemon_failure +./runtest.exe -w entry-dynamic.exe dn_expand_empty +./runtest.exe -w entry-dynamic.exe dn_expand_ptr_0 +./runtest.exe -w entry-dynamic.exe fflush_exit +./runtest.exe -w entry-dynamic.exe fgets_eof +./runtest.exe -w entry-dynamic.exe fgetwc_buffering +./runtest.exe -w entry-dynamic.exe fpclassify_invalid_ld80 +./runtest.exe -w entry-dynamic.exe ftello_unflushed_append +./runtest.exe -w entry-dynamic.exe getpwnam_r_crash +./runtest.exe -w entry-dynamic.exe getpwnam_r_errno +./runtest.exe -w entry-dynamic.exe iconv_roundtrips +./runtest.exe -w entry-dynamic.exe inet_ntop_v4mapped +./runtest.exe -w entry-dynamic.exe inet_pton_empty_last_field +./runtest.exe -w entry-dynamic.exe iswspace_null +./runtest.exe -w entry-dynamic.exe lrand48_signextend +./runtest.exe -w entry-dynamic.exe lseek_large +./runtest.exe -w entry-dynamic.exe malloc_0 +./runtest.exe -w entry-dynamic.exe mbsrtowcs_overflow +./runtest.exe -w entry-dynamic.exe memmem_oob_read +./runtest.exe -w entry-dynamic.exe memmem_oob +./runtest.exe -w entry-dynamic.exe mkdtemp_failure +./runtest.exe -w entry-dynamic.exe mkstemp_failure +./runtest.exe -w entry-dynamic.exe printf_1e9_oob +./runtest.exe -w entry-dynamic.exe printf_fmt_g_round +./runtest.exe -w entry-dynamic.exe printf_fmt_g_zeros +./runtest.exe -w entry-dynamic.exe printf_fmt_n +./runtest.exe -w entry-dynamic.exe pthread_robust_detach +./runtest.exe -w entry-dynamic.exe pthread_cond_smasher +./runtest.exe -w entry-dynamic.exe pthread_condattr_setclock +./runtest.exe -w entry-dynamic.exe pthread_exit_cancel +./runtest.exe -w entry-dynamic.exe pthread_once_deadlock +./runtest.exe -w entry-dynamic.exe pthread_rwlock_ebusy +./runtest.exe -w entry-dynamic.exe putenv_doublefree +./runtest.exe -w entry-dynamic.exe regex_backref_0 +./runtest.exe -w entry-dynamic.exe regex_bracket_icase +./runtest.exe -w entry-dynamic.exe regex_ere_backref +./runtest.exe -w entry-dynamic.exe regex_escaped_high_byte +./runtest.exe -w entry-dynamic.exe regex_negated_range +./runtest.exe -w entry-dynamic.exe regexec_nosub +./runtest.exe -w entry-dynamic.exe rewind_clear_error +./runtest.exe -w entry-dynamic.exe rlimit_open_files +./runtest.exe -w entry-dynamic.exe scanf_bytes_consumed +./runtest.exe -w entry-dynamic.exe scanf_match_literal_eof +./runtest.exe -w entry-dynamic.exe scanf_nullbyte_char +./runtest.exe -w entry-dynamic.exe setvbuf_unget +./runtest.exe -w entry-dynamic.exe sigprocmask_internal +./runtest.exe -w entry-dynamic.exe sscanf_eof +./runtest.exe -w entry-dynamic.exe statvfs +./runtest.exe -w entry-dynamic.exe strverscmp +./runtest.exe -w entry-dynamic.exe syscall_sign_extend +./runtest.exe -w entry-dynamic.exe tls_get_new_dtv +./runtest.exe -w entry-dynamic.exe uselocale_0 +./runtest.exe -w entry-dynamic.exe wcsncpy_read_overflow +./runtest.exe -w entry-dynamic.exe wcsstr_false_negative diff --git a/testcase/basic/riscv64gc-unknown-none-elf/run-static.sh b/testcase/basic/riscv64gc-unknown-none-elf/run-static.sh new file mode 100644 index 0000000..616263f --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/run-static.sh @@ -0,0 +1,107 @@ +./runtest.exe -w entry-static.exe argv +./runtest.exe -w entry-static.exe basename +./runtest.exe -w entry-static.exe clocale_mbfuncs +./runtest.exe -w entry-static.exe clock_gettime +./runtest.exe -w entry-static.exe dirname +./runtest.exe -w entry-static.exe env +./runtest.exe -w entry-static.exe fdopen +./runtest.exe -w entry-static.exe fnmatch +./runtest.exe -w entry-static.exe fscanf +./runtest.exe -w entry-static.exe fwscanf +./runtest.exe -w entry-static.exe iconv_open +./runtest.exe -w entry-static.exe inet_pton +./runtest.exe -w entry-static.exe mbc +./runtest.exe -w entry-static.exe memstream +./runtest.exe -w entry-static.exe pthread_cancel_points +./runtest.exe -w entry-static.exe pthread_cancel +./runtest.exe -w entry-static.exe pthread_cond +./runtest.exe -w entry-static.exe pthread_tsd +./runtest.exe -w entry-static.exe qsort +./runtest.exe -w entry-static.exe random +./runtest.exe -w entry-static.exe search_hsearch +./runtest.exe -w entry-static.exe search_insque +./runtest.exe -w entry-static.exe search_lsearch +./runtest.exe -w entry-static.exe search_tsearch +./runtest.exe -w entry-static.exe setjmp +./runtest.exe -w entry-static.exe snprintf +./runtest.exe -w entry-static.exe socket +./runtest.exe -w entry-static.exe sscanf +./runtest.exe -w entry-static.exe sscanf_long +./runtest.exe -w entry-static.exe stat +./runtest.exe -w entry-static.exe strftime +./runtest.exe -w entry-static.exe string +./runtest.exe -w entry-static.exe string_memcpy +./runtest.exe -w entry-static.exe string_memmem +./runtest.exe -w entry-static.exe string_memset +./runtest.exe -w entry-static.exe string_strchr +./runtest.exe -w entry-static.exe string_strcspn +./runtest.exe -w entry-static.exe string_strstr +./runtest.exe -w entry-static.exe strptime +./runtest.exe -w entry-static.exe strtod +./runtest.exe -w entry-static.exe strtod_simple +./runtest.exe -w entry-static.exe strtof +./runtest.exe -w entry-static.exe strtol +./runtest.exe -w entry-static.exe strtold +./runtest.exe -w entry-static.exe swprintf +./runtest.exe -w entry-static.exe tgmath +./runtest.exe -w entry-static.exe time +./runtest.exe -w entry-static.exe tls_align +./runtest.exe -w entry-static.exe udiv +./runtest.exe -w entry-static.exe ungetc +./runtest.exe -w entry-static.exe utime +./runtest.exe -w entry-static.exe wcsstr +./runtest.exe -w entry-static.exe wcstol +./runtest.exe -w entry-static.exe daemon_failure +./runtest.exe -w entry-static.exe dn_expand_empty +./runtest.exe -w entry-static.exe dn_expand_ptr_0 +./runtest.exe -w entry-static.exe fflush_exit +./runtest.exe -w entry-static.exe fgets_eof +./runtest.exe -w entry-static.exe fgetwc_buffering +./runtest.exe -w entry-static.exe fpclassify_invalid_ld80 +./runtest.exe -w entry-static.exe ftello_unflushed_append +./runtest.exe -w entry-static.exe getpwnam_r_crash +./runtest.exe -w entry-static.exe getpwnam_r_errno +./runtest.exe -w entry-static.exe iconv_roundtrips +./runtest.exe -w entry-static.exe inet_ntop_v4mapped +./runtest.exe -w entry-static.exe inet_pton_empty_last_field +./runtest.exe -w entry-static.exe iswspace_null +./runtest.exe -w entry-static.exe lrand48_signextend +./runtest.exe -w entry-static.exe lseek_large +./runtest.exe -w entry-static.exe malloc_0 +./runtest.exe -w entry-static.exe mbsrtowcs_overflow +./runtest.exe -w entry-static.exe memmem_oob_read +./runtest.exe -w entry-static.exe memmem_oob +./runtest.exe -w entry-static.exe mkdtemp_failure +./runtest.exe -w entry-static.exe mkstemp_failure +./runtest.exe -w entry-static.exe printf_1e9_oob +./runtest.exe -w entry-static.exe printf_fmt_g_round +./runtest.exe -w entry-static.exe printf_fmt_g_zeros +./runtest.exe -w entry-static.exe printf_fmt_n +./runtest.exe -w entry-static.exe pthread_robust_detach +./runtest.exe -w entry-static.exe pthread_cancel_sem_wait +./runtest.exe -w entry-static.exe pthread_cond_smasher +./runtest.exe -w entry-static.exe pthread_condattr_setclock +./runtest.exe -w entry-static.exe pthread_exit_cancel +./runtest.exe -w entry-static.exe pthread_once_deadlock +./runtest.exe -w entry-static.exe pthread_rwlock_ebusy +./runtest.exe -w entry-static.exe putenv_doublefree +./runtest.exe -w entry-static.exe regex_backref_0 +./runtest.exe -w entry-static.exe regex_bracket_icase +./runtest.exe -w entry-static.exe regex_ere_backref +./runtest.exe -w entry-static.exe regex_escaped_high_byte +./runtest.exe -w entry-static.exe regex_negated_range +./runtest.exe -w entry-static.exe regexec_nosub +./runtest.exe -w entry-static.exe rewind_clear_error +./runtest.exe -w entry-static.exe rlimit_open_files +./runtest.exe -w entry-static.exe scanf_bytes_consumed +./runtest.exe -w entry-static.exe scanf_match_literal_eof +./runtest.exe -w entry-static.exe scanf_nullbyte_char +./runtest.exe -w entry-static.exe setvbuf_unget +./runtest.exe -w entry-static.exe sigprocmask_internal +./runtest.exe -w entry-static.exe sscanf_eof +./runtest.exe -w entry-static.exe statvfs +./runtest.exe -w entry-static.exe strverscmp +./runtest.exe -w entry-static.exe syscall_sign_extend +./runtest.exe -w entry-static.exe uselocale_0 +./runtest.exe -w entry-static.exe wcsncpy_read_overflow +./runtest.exe -w entry-static.exe wcsstr_false_negative diff --git a/testcase/basic/riscv64gc-unknown-none-elf/runtest.exe b/testcase/basic/riscv64gc-unknown-none-elf/runtest.exe new file mode 100644 index 0000000..413836f Binary files /dev/null and b/testcase/basic/riscv64gc-unknown-none-elf/runtest.exe differ diff --git a/testcase/basic/riscv64gc-unknown-none-elf/sin30.lua b/testcase/basic/riscv64gc-unknown-none-elf/sin30.lua new file mode 100644 index 0000000..bcc1e98 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/sin30.lua @@ -0,0 +1,9 @@ + + +if math.sin(math.rad(30)) == 0.5 then + return 0 +else + return -1 +end + + diff --git a/testcase/basic/riscv64/sleep b/testcase/basic/riscv64gc-unknown-none-elf/sleep similarity index 100% rename from testcase/basic/riscv64/sleep rename to testcase/basic/riscv64gc-unknown-none-elf/sleep diff --git a/testcase/basic/riscv64gc-unknown-none-elf/sort.lua b/testcase/basic/riscv64gc-unknown-none-elf/sort.lua new file mode 100644 index 0000000..942d039 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/sort.lua @@ -0,0 +1,13 @@ + + +local tb = {20, 10, 2, 3, 4, 89, 20, 33, 2, 3} + +local rst = {2, 2, 3, 3, 4, 10, 20, 20, 33, 89} + +table.sort(tb) + +if tb == rst then + return 0 +else + return -1 +end diff --git a/testcase/basic/riscv64gc-unknown-none-elf/strings.lua b/testcase/basic/riscv64gc-unknown-none-elf/strings.lua new file mode 100644 index 0000000..2a1b157 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/strings.lua @@ -0,0 +1,35 @@ + + +local str = "Jelly Think" + +result = 0 + +-- string.len可以获得字符串的长度 + +if string.len(str) ~= 11 then + result = -1 +end + +-- string.rep返回字符串重复n次的结果 + +str = "ab" + +if string.rep(str, 2) ~= "abab" then + result = -1 +end + +-- string.lower将字符串小写变成大写形式,并返回一个改变以后的副本 + +str = "Jelly Think" + +if string.lower(str) ~= "jelly think" then + result = -1 +end + +-- string.upper将字符串大写变成小写形式,并返回一个改变以后的副本 + +if string.upper(str) == "JELLY THINK" then + result = -1 +end + +return result diff --git a/testcase/basic/riscv64gc-unknown-none-elf/test.sh b/testcase/basic/riscv64gc-unknown-none-elf/test.sh new file mode 100644 index 0000000..7184e1a --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/test.sh @@ -0,0 +1,8 @@ +#!/bin/busybox sh + +./lua $1 +if [ $? == 0 ]; then + echo "testcase lua $1 success" +else + echo "testcase lua $1 fail" +fi diff --git a/testcase/basic/riscv64/test_echo b/testcase/basic/riscv64gc-unknown-none-elf/test_echo similarity index 100% rename from testcase/basic/riscv64/test_echo rename to testcase/basic/riscv64gc-unknown-none-elf/test_echo diff --git a/testcase/basic/riscv64gc-unknown-none-elf/text.txt b/testcase/basic/riscv64gc-unknown-none-elf/text.txt new file mode 100644 index 0000000..2dba0f9 --- /dev/null +++ b/testcase/basic/riscv64gc-unknown-none-elf/text.txt @@ -0,0 +1,3 @@ +Hi, this is a text file. +syscalls testing success! + diff --git a/testcase/basic/riscv64/times b/testcase/basic/riscv64gc-unknown-none-elf/times similarity index 100% rename from testcase/basic/riscv64/times rename to testcase/basic/riscv64gc-unknown-none-elf/times diff --git a/testcase/basic/riscv64/umount b/testcase/basic/riscv64gc-unknown-none-elf/umount similarity index 100% rename from testcase/basic/riscv64/umount rename to testcase/basic/riscv64gc-unknown-none-elf/umount diff --git a/testcase/basic/riscv64/uname b/testcase/basic/riscv64gc-unknown-none-elf/uname similarity index 100% rename from testcase/basic/riscv64/uname rename to testcase/basic/riscv64gc-unknown-none-elf/uname diff --git a/testcase/basic/riscv64/unlink b/testcase/basic/riscv64gc-unknown-none-elf/unlink similarity index 100% rename from testcase/basic/riscv64/unlink rename to testcase/basic/riscv64gc-unknown-none-elf/unlink diff --git a/testcase/basic/riscv64/user_shell b/testcase/basic/riscv64gc-unknown-none-elf/user_shell similarity index 100% rename from testcase/basic/riscv64/user_shell rename to testcase/basic/riscv64gc-unknown-none-elf/user_shell diff --git a/testcase/basic/riscv64/wait b/testcase/basic/riscv64gc-unknown-none-elf/wait similarity index 100% rename from testcase/basic/riscv64/wait rename to testcase/basic/riscv64gc-unknown-none-elf/wait diff --git a/testcase/basic/riscv64/waitpid b/testcase/basic/riscv64gc-unknown-none-elf/waitpid similarity index 100% rename from testcase/basic/riscv64/waitpid rename to testcase/basic/riscv64gc-unknown-none-elf/waitpid diff --git a/testcase/basic/riscv64/write b/testcase/basic/riscv64gc-unknown-none-elf/write similarity index 100% rename from testcase/basic/riscv64/write rename to testcase/basic/riscv64gc-unknown-none-elf/write diff --git a/testcase/basic/riscv64/yield b/testcase/basic/riscv64gc-unknown-none-elf/yield similarity index 100% rename from testcase/basic/riscv64/yield rename to testcase/basic/riscv64gc-unknown-none-elf/yield diff --git a/user/Makefile b/user/Makefile index 5170327..3405681 100644 --- a/user/Makefile +++ b/user/Makefile @@ -13,7 +13,7 @@ CP := cp TEST ?= elf: $(APPS) - @cargo build --release + @cargo build -Z build-std --target $(TARGET) --release ifeq ($(TEST), 1) @$(CP) $(TARGET_DIR)/usertests $(TARGET_DIR)/initproc endif diff --git a/user/src/bin/initproc.rs b/user/src/bin/initproc.rs index 0452403..e78b2be 100644 --- a/user/src/bin/initproc.rs +++ b/user/src/bin/initproc.rs @@ -3,14 +3,22 @@ #[macro_use] extern crate user_lib; - -use user_lib::{exec, fork, wait, yield_}; +extern crate alloc; +use alloc::string::String; +use alloc::vec::Vec; +use user_lib::{exec, fork, wait, yield_,chdir}; #[no_mangle] fn main() -> i32 { println!("initproc"); + // chdir("/glibc\0"); + // let mut args_copy: Vec =Vec::new(); + // args_copy.push(String::from("sh")); + // let mut args_addr: Vec<*const u8> = args_copy.iter().map(|arg| arg.as_ptr()).collect(); + // args_addr.push(core::ptr::null::()); if fork() == 0 { - exec("user_shell\0", &[core::ptr::null::()]); + // exec("/glibc/busybox\0", &args_addr); + exec("user_shell\0", &[core::ptr::null::()]); } else { loop { let mut exit_code: i32 = 0; diff --git a/user/src/syscall.rs b/user/src/syscall.rs index dfb9536..4ddddb5 100644 --- a/user/src/syscall.rs +++ b/user/src/syscall.rs @@ -50,6 +50,21 @@ fn syscall(id: usize, args: [usize; 3]) -> isize { ret } +#[cfg(target_arch = "loongarch64")] +fn syscall(id: usize, args: [usize; 3]) -> isize { + let mut ret: isize; + unsafe { + asm!( + "syscall 0", + inlateout("$r4") args[0] => ret, + in("$r5") args[1], + in("$r6") args[2], + in("$r11") id + ); + } + ret +} + pub fn sys_chdir(path: &str) -> isize { syscall(SYSCALL_CHDIR, [path.as_ptr() as usize, 0, 0]) } diff --git a/vfs-defs/src/dentry_cache.rs b/vfs-defs/src/dentry_cache.rs index 098b7b8..a351969 100644 --- a/vfs-defs/src/dentry_cache.rs +++ b/vfs-defs/src/dentry_cache.rs @@ -9,7 +9,7 @@ use alloc::{ }; use lru::LruCache; use super::Dentry; -const DENTRY_LRU_SIZE:usize = 50;//must be bigger than max dir size,or getdents will be wrong +const DENTRY_LRU_SIZE:usize = 400;//must be bigger than max dir size,or getdents will be wrong pub struct DentryCache{ intenal_list:BTreeMap<(usize,String),Arc>, leaf_list:LruCache<(usize,String),Arc>, @@ -124,4 +124,18 @@ pub fn dcache_drop(){ DROPLIST .lock() .empty_droplist(); +} +/// +pub fn dcache_sync_call(){ + let mut manager = DENTRY_CACHE_MANAGER.lock(); + while !manager.leaf_list.is_empty(){ + if let Some(((_f,_n),old)) = manager.leaf_list.pop_lru(){ + DROPLIST.lock().drop_list.push(old); + } + } + while !manager.intenal_list.is_empty(){ + if let Some(((_f,_n),old)) = manager.intenal_list.pop_first(){ + DROPLIST.lock().drop_list.push(old); + } + } } \ No newline at end of file diff --git a/vfs-defs/src/lib.rs b/vfs-defs/src/lib.rs index 623c42c..41a7fa2 100644 --- a/vfs-defs/src/lib.rs +++ b/vfs-defs/src/lib.rs @@ -15,7 +15,7 @@ pub use dentry::{Dentry,DentryInner,DentryState}; pub use superblock::{SuperBlock,SuperBlockInner}; pub use inode::{Inode,InodeMeta,InodeMetaInner,DiskInodeType,InodeState,InodeMode}; pub use file::{File,FileInner,OpenFlags,UserBuffer,UserBufferIterator,SeekFlags}; -pub use dentry_cache::{DENTRY_CACHE_MANAGER,alloc_dentry,intenal_to_leaf,dcache_lookup,dcache_drop}; +pub use dentry_cache::{DENTRY_CACHE_MANAGER,alloc_dentry,intenal_to_leaf,dcache_lookup,dcache_drop,dcache_sync_call}; #[derive(Debug, Clone, Copy, Default, Eq, PartialEq)] #[repr(C)] /// diff --git a/vfs/src/devfs/mod.rs b/vfs/src/devfs/mod.rs index a4e575a..1779ef5 100644 --- a/vfs/src/devfs/mod.rs +++ b/vfs/src/devfs/mod.rs @@ -1,6 +1,8 @@ use vfs_defs::{FileSystemType,FileSystemTypeInner,SuperBlock,SuperBlockInner,Dentry,MountFlags,InodeMode,DentryState}; use alloc::{string::String, sync::Arc}; use device::BlockDevice; +use crate::get_root_dentry; + use super::{MemDentry,MemInode,add_vfs_dentry}; use system_result::SysResult; mod tty; @@ -73,6 +75,16 @@ pub fn init_devfs(root_dentry: Arc) -> SysResult<()> { Ok(()) } +pub fn add_tty(ttydentry:Arc,ttyinode:Arc){ + let root_dentry = get_root_dentry(); + let dev = root_dentry.lookup("dev").unwrap(); + *ttyinode.get_meta()._type.lock() = vfs_defs::DiskInodeType::File; + ttydentry.set_inode(ttyinode); + *ttydentry.get_state() = DentryState::Valid; + dev.add_child(ttydentry.clone()); + add_vfs_dentry(ttydentry); +} + pub struct DevFsType { inner: FileSystemTypeInner, } diff --git a/vfs/src/lib.rs b/vfs/src/lib.rs index 8955663..6476c62 100644 --- a/vfs/src/lib.rs +++ b/vfs/src/lib.rs @@ -19,6 +19,7 @@ use vfs_defs::{FileSystemType, MountFlags,Dentry}; use device::BLOCK_DEVICE; pub use ext4::BLOCK_SIZE; use memfs::{MemFile,MemInode,MemDentry}; +pub use devfs::add_tty; lazy_static!{ pub static ref FILE_SYSTEMS:Mutex =