diff --git a/Cargo.lock b/Cargo.lock index ffd865b..badec2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -381,6 +381,7 @@ dependencies = [ [[package]] name = "kramdisk" version = "0.1.0" +source = "git+https://github.com/Byte-OS/kramdisk.git#cccb30ddf105f783a3fc330eede9263e3e8e87c6" dependencies = [ "devices", "log", diff --git a/crates/kramdisk/Cargo.toml b/crates/kramdisk/Cargo.toml deleted file mode 100644 index 74b10bc..0000000 --- a/crates/kramdisk/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "kramdisk" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4" -virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "61ece50"} -devices = { git = "https://github.com/Byte-OS/devices.git" } diff --git a/crates/kramdisk/build.rs b/crates/kramdisk/build.rs deleted file mode 100644 index 4e71c8f..0000000 --- a/crates/kramdisk/build.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![feature(lazy_cell)] - -use std::{env, fs, path::PathBuf}; - -#[allow(unused_macros)] -macro_rules! display { - ($fmt:expr) => (println!("cargo:warning={}", format!($fmt))); - ($fmt:expr, $($arg:tt)*) => (println!(concat!("cargo:warning=", $fmt), $($arg)*)); -} - -fn main() { - let out_dir = PathBuf::from(env::var("OUT_DIR").expect("can't find manifest dir")); - let img_path = env::var("MOUNT_IMG_PATH").unwrap_or("mount.img".into()); - - fs::write( - out_dir.join("inc.S"), - format!( - ".section .data - .global ramdisk_start - .global ramdisk_end - .align 16 - ramdisk_start: - .incbin \"{img_path}\" - ramdisk_end:" - ), - ) - .expect("can't write ram file to out_dir"); - - // fs::write(path, contents) - - // write module configuration to OUT_PATH, then it will be included in the main.rs - println!("cargo:rerun-if-env-changed=MOUNT_IMG_PATH"); - println!("cargo:rerun-if-changed=mount.img"); - println!("cargo:rerun-if-changed=build.rs"); -} diff --git a/crates/kramdisk/src/lib.rs b/crates/kramdisk/src/lib.rs deleted file mode 100644 index 3278181..0000000 --- a/crates/kramdisk/src/lib.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![no_std] -#![feature(used_with_arg)] - -use core::{ - arch::global_asm, - ptr::{slice_from_raw_parts, slice_from_raw_parts_mut}, -}; - -extern crate alloc; - -use alloc::sync::Arc; -use devices::{ - device::{BlkDriver, DeviceType, Driver}, - driver_define, -}; -use log::info; - -// 虚拟IO设备 -pub struct RamDiskBlock { - start: usize, - size: usize, -} - -impl Driver for RamDiskBlock { - fn get_id(&self) -> &str { - "nvme" - } - - fn get_device_wrapper(self: Arc) -> DeviceType { - DeviceType::BLOCK(self.clone()) - } -} - -impl BlkDriver for RamDiskBlock { - fn read_blocks(&self, sector_offset: usize, buf: &mut [u8]) { - let rlen = buf.len(); - if (sector_offset * 0x200 + rlen) >= self.size { - panic!("can't out of ramdisk range") - }; - unsafe { - buf.copy_from_slice( - slice_from_raw_parts((self.start + sector_offset * 0x200) as *const u8, buf.len()) - .as_ref() - .expect("can't deref ptr in the Ramdisk"), - ); - // let source = (self.start as *mut [u8; 512]).add(sector_offset); - // buf.copy_from_slice(source.as_mut().unwrap()); - } - } - - fn write_blocks(&self, sector_offset: usize, buf: &[u8]) { - let wlen = buf.len(); - if (sector_offset * 0x200 + wlen) >= self.size { - panic!("can't out of ramdisk range") - }; - unsafe { - slice_from_raw_parts_mut((self.start + sector_offset * 0x200) as *mut u8, buf.len()) - .as_mut() - .expect("can't deref ptr in the ramdisk") - .copy_from_slice(buf); - // let dest = (self.start as *mut [u8; 512]).add(sector_offset); - // dest.as_mut().unwrap().copy_from_slice(buf); - } - } -} - -global_asm!(include_str!(concat!(env!("OUT_DIR"), "/inc.S"))); - -driver_define!({ - extern "C" { - fn ramdisk_start(); - fn ramdisk_end(); - } - info!( - "ramdisk range: {:#x} - {:#x}", - ramdisk_start as usize, ramdisk_end as usize - ); - Some(Arc::new(RamDiskBlock { - start: ramdisk_start as _, - size: ramdisk_end as usize - ramdisk_start as usize, - })) -}); diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 0ea9f96..bd486df 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -43,6 +43,6 @@ num-derive = "0.4" kvirtio = { git = "https://github.com/Byte-OS/driver-kvirtio.git" } kgoldfish-rtc = { git = "https://github.com/Byte-OS/driver-kgoldfish-rtc.git" } -kramdisk = { version = "0.1.0", path = "../crates/kramdisk" } +kramdisk = { git = "https://github.com/Byte-OS/kramdisk.git" } general-plic = { git = "https://github.com/Byte-OS/driver-general-plic.git" } ns16550a = { git = "https://github.com/Byte-OS/driver-ns16550a.git" }