From 989132fbedc48b661c5fa3adc08bf4c9ed5ca588 Mon Sep 17 00:00:00 2001 From: yufeng <321353225@qq.com> Date: Tue, 16 Apr 2024 23:23:53 +0800 Subject: [PATCH] fix: optimize project source tree --- .gitignore | 3 +- Cargo.lock | 46 ++--------------------------- Makefile | 7 +++-- drivers/general-plic/Cargo.toml | 7 +---- drivers/general-plic/src/lib.rs | 5 +--- drivers/k210-sdcard/Cargo.toml | 3 -- drivers/k210-sdcard/src/lib.rs | 4 +-- drivers/kcvitek-sd/Cargo.toml | 5 ---- drivers/kcvitek-sd/src/lib.rs | 3 +- drivers/kgoldfish-rtc/Cargo.toml | 3 -- drivers/kgoldfish-rtc/src/lib.rs | 5 +--- drivers/knvme/Cargo.toml | 5 ---- drivers/knvme/src/lib.rs | 6 +--- drivers/kramdisk/Cargo.toml | 3 -- drivers/kvirtio/Cargo.toml | 5 ---- drivers/kvirtio/src/lib.rs | 5 +--- drivers/kvirtio/src/virtio_blk.rs | 3 +- drivers/kvirtio/src/virtio_impl.rs | 4 +-- drivers/kvirtio/src/virtio_input.rs | 3 +- drivers/kvirtio/src/virtio_net.rs | 3 +- drivers/ns16550a/Cargo.toml | 5 ---- drivers/ns16550a/src/lib.rs | 5 +--- kernel/Cargo.toml | 1 - modules/devices/Cargo.toml | 1 + modules/devices/src/lib.rs | 18 ++++++----- modules/devices/src/memory.rs | 22 -------------- modules/frame_allocator/Cargo.toml | 2 -- modules/frame_allocator/src/lib.rs | 6 ---- modules/kheader/src/lib.rs | 1 - modules/kheader/src/mm.rs | 19 ------------ 30 files changed, 32 insertions(+), 176 deletions(-) delete mode 100644 modules/devices/src/memory.rs delete mode 100644 modules/kheader/src/mm.rs diff --git a/.gitignore b/.gitignore index 9f1e867c..d4ea57a2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ packets.pcap .gdb_history kernel/*.lds qemu.log -kernel/src/drivers.rs \ No newline at end of file +kernel/src/drivers.rs +graph.png \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index fd41e072..892c623a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,7 +56,7 @@ dependencies = [ "cfg-if", "crate_interface", "fdt", - "irq_safety 0.1.1 (git+https://github.com/theseus-os/irq_safety.git)", + "irq_safety", "log", "loongarch64", "multiboot", @@ -244,6 +244,7 @@ dependencies = [ "fdt", "frame_allocator", "kheader", + "linkme", "log", "sync", "timestamp", @@ -316,7 +317,6 @@ version = "0.1.0" dependencies = [ "arch", "bit_field", - "kheader", "log", "sync", ] @@ -413,13 +413,8 @@ dependencies = [ name = "general-plic" version = "0.1.0" dependencies = [ - "arch", "devices", - "fdt", - "frame_allocator", - "kheader", "log", - "sync", ] [[package]] @@ -443,13 +438,6 @@ dependencies = [ "allocator-api2", ] -[[package]] -name = "irq_safety" -version = "0.1.1" -dependencies = [ - "spin 0.9.8", -] - [[package]] name = "irq_safety" version = "0.1.1" @@ -487,10 +475,7 @@ dependencies = [ "k210-hal", "k210-pac", "k210-soc", - "kheader", "log", - "logging", - "sync", ] [[package]] @@ -509,14 +494,9 @@ dependencies = [ name = "kcvitek-sd" version = "0.1.0" dependencies = [ - "arch", "cv1811-sd", "devices", - "fdt", - "frame_allocator", - "kheader", "log", - "sync", ] [[package]] @@ -542,7 +522,6 @@ dependencies = [ "k210-sdcard", "kcvitek-sd", "kgoldfish-rtc", - "kheader", "knvme", "kramdisk", "kvirtio", @@ -565,10 +544,7 @@ dependencies = [ name = "kgoldfish-rtc" version = "0.1.0" dependencies = [ - "arch", "devices", - "fdt", - "kheader", "log", "timestamp", ] @@ -585,14 +561,9 @@ dependencies = [ name = "knvme" version = "0.1.0" dependencies = [ - "arch", "devices", - "fdt", - "frame_allocator", - "kheader", "log", "nvme_driver", - "sync", ] [[package]] @@ -600,10 +571,7 @@ name = "kramdisk" version = "0.1.0" dependencies = [ "devices", - "frame_allocator", - "kheader", "log", - "sync", "virtio-drivers 0.7.1", ] @@ -611,13 +579,8 @@ dependencies = [ name = "kvirtio" version = "0.1.0" dependencies = [ - "arch", "devices", - "fdt", - "frame_allocator", - "kheader", "log", - "sync", "virtio-drivers 0.7.1", ] @@ -768,14 +731,9 @@ checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" name = "ns16550a" version = "0.1.0" dependencies = [ - "arch", "devices", - "fdt", - "frame_allocator", - "kheader", "log", "ns16550a 0.2.0", - "sync", ] [[package]] diff --git a/Makefile b/Makefile index 6e43cb30..238668b9 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ LOG := error BOARD:= qemu RELEASE := release QEMU_EXEC ?= +BUILD_ARGS := GDB ?= gdb-multiarch BUS := device @@ -31,6 +32,7 @@ else ifeq ($(ARCH), aarch64) else ifeq ($(ARCH), loongarch64) TARGET := loongarch64-unknown-none QEMU_EXEC += qemu-system-$(ARCH) -kernel $(KERNEL_ELF) + BUILD_ARGS += -Z build-std BUS := pci else $(error "ARCH" must be one of "x86_64", "riscv64", "aarch64" or "loongarch64") @@ -50,7 +52,6 @@ QEMU_EXEC += -m 1G\ -smp 2 \ -D qemu.log -d in_asm,int,pcall,cpu_reset,guest_errors -BUILD_ARGS := ifeq ($(RELEASE), release) BUILD_ARGS += --release endif @@ -77,7 +78,7 @@ endif all: build offline: - RUST_BACKTRACE=1 LOG=$(LOG) cargo build -Z build-std $(BUILD_ARGS) --features "$(features)" --offline + RUST_BACKTRACE=1 LOG=$(LOG) cargo build $(BUILD_ARGS) --features "$(features)" --offline # cp $(SBI) sbi-qemu # cp $(KERNEL_ELF) kernel-qemu rust-objcopy --binary-architecture=riscv64 $(KERNEL_ELF) --strip-all -O binary os.bin @@ -94,7 +95,7 @@ fs-img: sudo umount $(FS_IMG) build: - RUST_BACKTRACE=1 LOG=$(LOG) cargo build -Z build-std --target $(TARGET) $(BUILD_ARGS) --features "$(features)" + RUST_BACKTRACE=1 LOG=$(LOG) cargo build --target $(TARGET) $(BUILD_ARGS) --features "$(features)" rust-objcopy --binary-architecture=$(ARCH) $(KERNEL_ELF) --strip-all -O binary $(KERNEL_BIN) justbuild: fs-img build diff --git a/drivers/general-plic/Cargo.toml b/drivers/general-plic/Cargo.toml index a2abf8cf..79633f9c 100644 --- a/drivers/general-plic/Cargo.toml +++ b/drivers/general-plic/Cargo.toml @@ -6,10 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -arch = { path = "../../arch" } -fdt = "0.1.5" -sync = { path = "../../modules/sync" } -kheader = { path = "../../modules/kheader" } devices = { path = "../../modules/devices" } -frame_allocator = { path = "../../modules/frame_allocator" } -log = "0.4" +log = "0.4.11" diff --git a/drivers/general-plic/src/lib.rs b/drivers/general-plic/src/lib.rs index d181ef56..156732b7 100644 --- a/drivers/general-plic/src/lib.rs +++ b/drivers/general-plic/src/lib.rs @@ -6,12 +6,9 @@ extern crate alloc; mod plic; use alloc::sync::Arc; -use arch::VIRT_ADDR_START; use devices::{ - device::{DeviceType, Driver, IntDriver}, - driver_define, + device::{DeviceType, Driver, IntDriver}, driver_define, fdt::node::FdtNode, VIRT_ADDR_START }; -use fdt::node::FdtNode; pub struct PLIC { base: usize, diff --git a/drivers/k210-sdcard/Cargo.toml b/drivers/k210-sdcard/Cargo.toml index 55102844..83722127 100644 --- a/drivers/k210-sdcard/Cargo.toml +++ b/drivers/k210-sdcard/Cargo.toml @@ -6,11 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sync = { path = "../../modules/sync" } devices = { path = "../../modules/devices" } k210-pac = { git = "https://github.com/byte-os/k210-pac" } k210-hal = { git = "https://github.com/byte-os/k210-hal" } k210-soc = { git = "https://github.com/byte-os/k210-soc" } log = "0.4" -logging = { path = "../../modules/logging" } -kheader = { path = "../../modules/kheader" } \ No newline at end of file diff --git a/drivers/k210-sdcard/src/lib.rs b/drivers/k210-sdcard/src/lib.rs index 8745e41b..1579b7d1 100644 --- a/drivers/k210-sdcard/src/lib.rs +++ b/drivers/k210-sdcard/src/lib.rs @@ -10,8 +10,7 @@ extern crate alloc; use alloc::sync::Arc; use core::{cell::RefCell, convert::TryInto}; use devices::{ - device::{BlkDriver, DeviceType, Driver}, - driver_define, DRIVERS_INIT, + device::{BlkDriver, DeviceType, Driver}, driver_define, Mutex, DRIVERS_INIT }; use k210_hal::prelude::*; use k210_pac::{Peripherals, SPI0}; @@ -25,7 +24,6 @@ use k210_soc::{ sysctl, }; use log::info; -use sync::{LazyInit, Mutex}; pub struct SDCard { spi: SPI, diff --git a/drivers/kcvitek-sd/Cargo.toml b/drivers/kcvitek-sd/Cargo.toml index ffc5f5de..0ab4cda7 100644 --- a/drivers/kcvitek-sd/Cargo.toml +++ b/drivers/kcvitek-sd/Cargo.toml @@ -6,11 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -arch = { path = "../../arch" } -fdt = "0.1.5" -sync = { path = "../../modules/sync" } -kheader = { path = "../../modules/kheader" } devices = { path = "../../modules/devices" } -frame_allocator = { path = "../../modules/frame_allocator" } log = "0.4" cv1811-sd = { git = "https://github.com/Byte-OS/cv1811-sd.git" } diff --git a/drivers/kcvitek-sd/src/lib.rs b/drivers/kcvitek-sd/src/lib.rs index 4e0e96c0..8b861f0d 100644 --- a/drivers/kcvitek-sd/src/lib.rs +++ b/drivers/kcvitek-sd/src/lib.rs @@ -10,9 +10,8 @@ use alloc::sync::Arc; use cv1811_sd::clk_en; use devices::{ device::{BlkDriver, DeviceType, Driver}, - driver_define, + driver_define, fdt::node::FdtNode, }; -use fdt::node::FdtNode; pub struct CvSd; diff --git a/drivers/kgoldfish-rtc/Cargo.toml b/drivers/kgoldfish-rtc/Cargo.toml index 8571c0e2..3e7285a0 100644 --- a/drivers/kgoldfish-rtc/Cargo.toml +++ b/drivers/kgoldfish-rtc/Cargo.toml @@ -6,9 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -arch = { path = "../../arch" } -fdt = "0.1.5" -kheader = { path = "../../modules/kheader" } devices = { path = "../../modules/devices" } log = "0.4" timestamp = { git = "https://github.com/Byte-OS/timestamp.git" } diff --git a/drivers/kgoldfish-rtc/src/lib.rs b/drivers/kgoldfish-rtc/src/lib.rs index 91bbc0df..c5b0fb77 100644 --- a/drivers/kgoldfish-rtc/src/lib.rs +++ b/drivers/kgoldfish-rtc/src/lib.rs @@ -7,13 +7,10 @@ extern crate alloc; extern crate log; use alloc::sync::Arc; -use arch::VIRT_ADDR_START; use core::ptr::read_volatile; use devices::{ - device::{DeviceType, Driver, RtcDriver}, - driver_define, + device::{DeviceType, Driver, RtcDriver}, driver_define, fdt::node::FdtNode, VIRT_ADDR_START }; -use fdt::node::FdtNode; use timestamp::DateTime; const TIMER_TIME_LOW: usize = 0x00; diff --git a/drivers/knvme/Cargo.toml b/drivers/knvme/Cargo.toml index 27e9a206..b1e6982e 100644 --- a/drivers/knvme/Cargo.toml +++ b/drivers/knvme/Cargo.toml @@ -6,11 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -arch = { path = "../../arch" } -fdt = "0.1.5" -sync = { path = "../../modules/sync" } -kheader = { path = "../../modules/kheader" } devices = { path = "../../modules/devices" } -frame_allocator = { path = "../../modules/frame_allocator" } log = "0.4" nvme_driver = { git = "https://github.com/rcore-os/nvme_driver", rev = "8ae0572" } diff --git a/drivers/knvme/src/lib.rs b/drivers/knvme/src/lib.rs index 1ff7e274..60d97439 100644 --- a/drivers/knvme/src/lib.rs +++ b/drivers/knvme/src/lib.rs @@ -8,14 +8,10 @@ extern crate alloc; extern crate log; use alloc::{sync::Arc, vec::Vec}; -use arch::{PAGE_SIZE, VIRT_ADDR_START}; use devices::{ - device::{BlkDriver, DeviceType, Driver}, - driver_define, + device::{BlkDriver, DeviceType, Driver}, driver_define, frame_alloc_much, FrameTracker, Mutex, PAGE_SIZE, VIRT_ADDR_START }; -use frame_allocator::{frame_alloc_much, FrameTracker}; use nvme_driver::{DmaAllocator, IrqController, NvmeInterface}; -use sync::Mutex; use core::ptr::write_volatile; diff --git a/drivers/kramdisk/Cargo.toml b/drivers/kramdisk/Cargo.toml index 1a712ac6..2ffbde09 100644 --- a/drivers/kramdisk/Cargo.toml +++ b/drivers/kramdisk/Cargo.toml @@ -7,8 +7,5 @@ edition = "2021" [dependencies] log = "0.4" -sync = { path = "../../modules/sync" } virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "61ece50"} -kheader = { path = "../../modules/kheader" } devices = { path = "../../modules/devices" } -frame_allocator = { path = "../../modules/frame_allocator" } diff --git a/drivers/kvirtio/Cargo.toml b/drivers/kvirtio/Cargo.toml index f73ad057..8cad4a44 100644 --- a/drivers/kvirtio/Cargo.toml +++ b/drivers/kvirtio/Cargo.toml @@ -6,11 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -arch = { path = "../../arch" } -fdt = "0.1.5" log = "0.4" -sync = { path = "../../modules/sync" } virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "61ece50"} -kheader = { path = "../../modules/kheader" } devices = { path = "../../modules/devices" } -frame_allocator = { path = "../../modules/frame_allocator" } diff --git a/drivers/kvirtio/src/lib.rs b/drivers/kvirtio/src/lib.rs index 98f90cc7..731ac2ec 100644 --- a/drivers/kvirtio/src/lib.rs +++ b/drivers/kvirtio/src/lib.rs @@ -13,12 +13,9 @@ pub mod virtio_net; use core::ptr::NonNull; use alloc::{sync::Arc, vec::Vec}; -use arch::VIRT_ADDR_START; use devices::{ - device::{Driver, UnsupportedDriver}, - driver_define, node_to_interrupts, + device::{Driver, UnsupportedDriver}, driver_define, fdt::node::FdtNode, node_to_interrupts, VIRT_ADDR_START }; -use fdt::node::FdtNode; use virtio_drivers::transport::{ mmio::{MmioTransport, VirtIOHeader}, DeviceType, Transport, diff --git a/drivers/kvirtio/src/virtio_blk.rs b/drivers/kvirtio/src/virtio_blk.rs index b1b8900f..597377b3 100644 --- a/drivers/kvirtio/src/virtio_blk.rs +++ b/drivers/kvirtio/src/virtio_blk.rs @@ -1,8 +1,7 @@ use alloc::sync::Arc; use alloc::vec::Vec; use devices::device::{BlkDriver, DeviceType, Driver}; -use devices::register_device_irqs; -use sync::Mutex; +use devices::{register_device_irqs, Mutex}; use virtio_drivers::device::blk::VirtIOBlk; use virtio_drivers::transport::Transport; diff --git a/drivers/kvirtio/src/virtio_impl.rs b/drivers/kvirtio/src/virtio_impl.rs index faf2a731..dbf45371 100644 --- a/drivers/kvirtio/src/virtio_impl.rs +++ b/drivers/kvirtio/src/virtio_impl.rs @@ -1,9 +1,7 @@ use alloc::vec::Vec; -use arch::VIRT_ADDR_START; +use devices::{frame_alloc_much, FrameTracker, Mutex, VIRT_ADDR_START}; use core::ptr::NonNull; -use frame_allocator::{frame_alloc_much, FrameTracker}; use log::trace; -use sync::Mutex; use virtio_drivers::{BufferDirection, Hal, PhysAddr}; static VIRTIO_CONTAINER: Mutex> = Mutex::new(Vec::new()); diff --git a/drivers/kvirtio/src/virtio_input.rs b/drivers/kvirtio/src/virtio_input.rs index 808b759f..480c7ea4 100644 --- a/drivers/kvirtio/src/virtio_input.rs +++ b/drivers/kvirtio/src/virtio_input.rs @@ -1,8 +1,7 @@ use alloc::sync::Arc; use alloc::vec::Vec; use devices::device::{DeviceType, Driver, InputDriver}; -use devices::register_device_irqs; -use sync::Mutex; +use devices::{register_device_irqs, Mutex}; use virtio_drivers::device::input::VirtIOInput as VirtIOInputWrapper; use virtio_drivers::transport::mmio::MmioTransport; diff --git a/drivers/kvirtio/src/virtio_net.rs b/drivers/kvirtio/src/virtio_net.rs index edf1de7c..ef223708 100644 --- a/drivers/kvirtio/src/virtio_net.rs +++ b/drivers/kvirtio/src/virtio_net.rs @@ -3,8 +3,7 @@ use core::cmp; use alloc::sync::Arc; use alloc::vec::Vec; use devices::device::{DeviceType, Driver, NetDriver, NetError}; -use devices::register_device_irqs; -use sync::Mutex; +use devices::{register_device_irqs, Mutex}; use virtio_drivers::device::net::{self, TxBuffer}; use virtio_drivers::transport::Transport; diff --git a/drivers/ns16550a/Cargo.toml b/drivers/ns16550a/Cargo.toml index b881b217..f2eef571 100644 --- a/drivers/ns16550a/Cargo.toml +++ b/drivers/ns16550a/Cargo.toml @@ -7,10 +7,5 @@ edition = "2021" [dependencies] ns16550a = "0.2" -arch = { path = "../../arch" } -fdt = "0.1.5" log = "0.4" -sync = { path = "../../modules/sync" } -kheader = { path = "../../modules/kheader" } devices = { path = "../../modules/devices" } -frame_allocator = { path = "../../modules/frame_allocator" } \ No newline at end of file diff --git a/drivers/ns16550a/src/lib.rs b/drivers/ns16550a/src/lib.rs index aa1b7fad..7f93c178 100644 --- a/drivers/ns16550a/src/lib.rs +++ b/drivers/ns16550a/src/lib.rs @@ -4,12 +4,9 @@ extern crate alloc; use alloc::{sync::Arc, vec::Vec}; -use arch::VIRT_ADDR_START; use devices::{ - device::{DeviceType, Driver, UartDriver}, - driver_define, node_to_interrupts, register_device_irqs, + device::{DeviceType, Driver, UartDriver}, driver_define, fdt::node::FdtNode, node_to_interrupts, register_device_irqs, VIRT_ADDR_START }; -use fdt::node::FdtNode; use log::info; use ns16550a::{ Break, DMAMode, Divisor, ParityBit, ParitySelect, StickParity, StopBits, Uart, WordLength, diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 369cc490..eae6ef90 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -34,7 +34,6 @@ lose-net-stack = { git = "https://github.com/byte-os/lose-net-stack", rev = "b06 vfscore = { git = "https://github.com/Byte-OS/vfscore.git" } async-recursion = "1.0.4" futures-lite = { version = "1.13.0", default-features = false, features=["alloc"] } -kheader = { path = "../modules/kheader" } # backtrace = { path = "../crates/backtrace" } hashbrown = "0.14" cfg-if = "1.0.0" diff --git a/modules/devices/Cargo.toml b/modules/devices/Cargo.toml index dd92e45a..fbd533d7 100644 --- a/modules/devices/Cargo.toml +++ b/modules/devices/Cargo.toml @@ -10,6 +10,7 @@ edition = "2021" [dependencies] arch = { path = "../../arch" } fdt = "0.1.5" +linkme = { version = "0.3.22", features = ["used_linker"] } log = "0.4" sync = { path = "../sync" } virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers", rev = "f1d1cbb"} diff --git a/modules/devices/src/lib.rs b/modules/devices/src/lib.rs index 63194e08..a41feace 100644 --- a/modules/devices/src/lib.rs +++ b/modules/devices/src/lib.rs @@ -10,14 +10,18 @@ extern crate log; extern crate alloc; pub mod device; -pub mod memory; + +pub use arch::{PAGE_SIZE, VIRT_ADDR_START}; +pub use fdt; +pub use frame_allocator::{frame_alloc, FrameTracker, frame_alloc_much}; +pub use linkme::{self, distributed_slice as linker_use}; +pub use sync::{LazyInit, Mutex, MutexGuard}; // pub mod virtio; use alloc::{collections::BTreeMap, string::String, sync::Arc, vec::Vec}; use device::{BlkDriver, DeviceSet, Driver, IntDriver, NetDriver, UartDriver}; -use fdt::{self, node::FdtNode, Fdt}; +use fdt::{node::FdtNode, Fdt}; use kheader::macros::link_define; -use sync::{LazyInit, Mutex}; // pub static DEVICE_TREE_ADDR: AtomicUsize = AtomicUsize::new(0); pub static DEVICE_TREE: LazyInit> = LazyInit::new(); @@ -135,15 +139,15 @@ pub fn node_to_interrupts(node: &FdtNode) -> Vec { #[macro_export] macro_rules! driver_define { ($body: block) => { - #[kheader::macros::linker_use($crate::DRIVERS_INIT)] - #[linkme(crate = kheader::macros::linkme)] + #[devices::linker_use($crate::DRIVERS_INIT)] + #[linkme(crate = devices::linkme)] fn __driver_init() -> Option> { $body } }; ($obj:expr, $func: expr) => { - #[kheader::macros::linker_use($crate::DRIVERS_INIT)] - #[linkme(crate = kheader::macros::linkme)] + #[devices::linker_use($crate::DRIVERS_INIT)] + #[linkme(crate = devices::linkme)] fn __driver_init() -> Option> { $crate::DRIVER_REGS.lock().insert($obj, $func); None diff --git a/modules/devices/src/memory.rs b/modules/devices/src/memory.rs deleted file mode 100644 index c0b41c89..00000000 --- a/modules/devices/src/memory.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fdt::Fdt; -use kheader::mm::{set_memory, MemoryRegion}; - -use crate::DEVICE_TREE; - -// use crate::DEVICE_TREE_ADDR; - -pub fn init() { - let mut mrs = vec![]; - // let fdt = - // unsafe { Fdt::from_ptr(DEVICE_TREE_ADDR.load(Ordering::Relaxed) as *const u8).unwrap() }; - let fdt = Fdt::new(DEVICE_TREE.as_ref()).unwrap(); - - fdt.memory().regions().for_each(|mr| { - mrs.push(MemoryRegion { - start: mr.starting_address as usize, - end: mr.starting_address as usize + mr.size.unwrap_or(0), - }) - }); - - set_memory(mrs); -} diff --git a/modules/frame_allocator/Cargo.toml b/modules/frame_allocator/Cargo.toml index 984a38b7..313f4c70 100644 --- a/modules/frame_allocator/Cargo.toml +++ b/modules/frame_allocator/Cargo.toml @@ -9,6 +9,4 @@ edition = "2021" bit_field = "0.10.1" log = "0.4" arch = { path = "../../arch" } -# devices = { path = "../devices" } -kheader = { path = "../kheader" } sync = { path = "../sync" } \ No newline at end of file diff --git a/modules/frame_allocator/src/lib.rs b/modules/frame_allocator/src/lib.rs index 72bb88d1..86c9e861 100644 --- a/modules/frame_allocator/src/lib.rs +++ b/modules/frame_allocator/src/lib.rs @@ -9,7 +9,6 @@ use alloc::vec::Vec; use arch::addr::PhysPage; use arch::{PAGE_SIZE, VIRT_ADDR_START}; use bit_field::{BitArray, BitField}; -use kheader::mm::get_memorys; use log::info; use sync::Mutex; @@ -249,11 +248,6 @@ pub fn add_frame_map(mm_start: usize, mm_end: usize) { pub fn init() { info!("initialize frame allocator"); - // 在帧分配器中添加内存 - get_memorys() - .iter() - .for_each(|mr| add_frame_map(mr.start | VIRT_ADDR_START, mr.end | VIRT_ADDR_START)); - // 确保帧分配器一定能工作 assert!( FRAME_ALLOCATOR.lock().0.len() > 0, diff --git a/modules/kheader/src/lib.rs b/modules/kheader/src/lib.rs index fa055120..6d0c0bf3 100644 --- a/modules/kheader/src/lib.rs +++ b/modules/kheader/src/lib.rs @@ -4,4 +4,3 @@ extern crate alloc; pub mod macros; -pub mod mm; diff --git a/modules/kheader/src/mm.rs b/modules/kheader/src/mm.rs deleted file mode 100644 index 3603f825..00000000 --- a/modules/kheader/src/mm.rs +++ /dev/null @@ -1,19 +0,0 @@ -use alloc::vec::Vec; -use sync::Mutex; - -static MEMORY_REGIONS: Mutex> = Mutex::new(Vec::new()); - -#[derive(Debug, Clone, Copy)] -pub struct MemoryRegion { - pub start: usize, - pub end: usize, -} - -#[inline] -pub fn get_memorys() -> Vec { - MEMORY_REGIONS.lock().clone() -} - -pub fn set_memory(mrs: Vec) { - *MEMORY_REGIONS.lock() = mrs; -}