diff --git a/Cargo.lock b/Cargo.lock index eb4d3dd..4bb8681 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,10 +35,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6419a5c75e40011b9fe0174db3fe24006ab122fbe1b7e9cc5974b338a755c76" -[[package]] -name = "error" -version = "0.1.0" - [[package]] name = "fallible-iterator" version = "0.2.0" @@ -49,8 +45,6 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" name = "fat32" version = "0.1.0" dependencies = [ - "error", - "libcommon", "vfs", ] @@ -77,22 +71,13 @@ dependencies = [ "bitflags", "cfg-if", "cortex-a", - "error", "fdt-rs", - "libcommon", "memfs", "syscall", "tock-registers", "vfs", ] -[[package]] -name = "libcommon" -version = "0.1.0" -dependencies = [ - "error", -] - [[package]] name = "libusr" version = "0.1.0" @@ -104,8 +89,7 @@ dependencies = [ name = "memfs" version = "0.1.0" dependencies = [ - "error", - "libcommon", + "syscall", "vfs", ] @@ -206,7 +190,6 @@ name = "syscall" version = "0.1.0" dependencies = [ "bitflags", - "error", ] [[package]] @@ -238,7 +221,5 @@ dependencies = [ name = "vfs" version = "0.1.0" dependencies = [ - "error", - "libcommon", "syscall", ] diff --git a/Cargo.toml b/Cargo.toml index 183dc28..e3c8c4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,7 @@ members = [ "fs/memfs", "fs/fat32", "syscall", - "libcommon", "kernel", "libusr", "user", - "error" ] diff --git a/error/Cargo.toml b/error/Cargo.toml deleted file mode 100644 index 31b8188..0000000 --- a/error/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "error" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/fs/fat32/Cargo.toml b/fs/fat32/Cargo.toml index cee876c..595cb0a 100644 --- a/fs/fat32/Cargo.toml +++ b/fs/fat32/Cargo.toml @@ -7,5 +7,3 @@ edition = "2021" [dependencies] vfs = { path = "../vfs" } -libcommon = { path = "../../libcommon" } -error = { path = "../../error" } diff --git a/fs/memfs/Cargo.toml b/fs/memfs/Cargo.toml index 2c7d297..a2d5267 100644 --- a/fs/memfs/Cargo.toml +++ b/fs/memfs/Cargo.toml @@ -7,8 +7,7 @@ edition = "2021" [dependencies] vfs = { path = "../vfs" } -error = { path = "../../error" } -libcommon = { path = "../../libcommon" } +syscall = { path = "../../syscall" } [features] cow = [] diff --git a/fs/memfs/src/block.rs b/fs/memfs/src/block.rs index e3c9289..5e46ef4 100644 --- a/fs/memfs/src/block.rs +++ b/fs/memfs/src/block.rs @@ -1,6 +1,6 @@ use core::mem::{size_of, MaybeUninit}; use core::ops::{Deref, DerefMut}; -use error::Errno; +use syscall::error::Errno; pub const SIZE: usize = 4096; pub const ENTRY_COUNT: usize = SIZE / size_of::(); diff --git a/fs/memfs/src/bvec.rs b/fs/memfs/src/bvec.rs index f75039f..366c370 100644 --- a/fs/memfs/src/bvec.rs +++ b/fs/memfs/src/bvec.rs @@ -2,7 +2,7 @@ use crate::{block, BlockAllocator, BlockRef}; use core::cmp::min; use core::mem::MaybeUninit; use core::ops::{Index, IndexMut}; -use error::Errno; +use syscall::error::Errno; const L0_BLOCKS: usize = 32; // 128K const L1_BLOCKS: usize = 8; // 16M diff --git a/fs/memfs/src/dir.rs b/fs/memfs/src/dir.rs index 552a6b6..0567757 100644 --- a/fs/memfs/src/dir.rs +++ b/fs/memfs/src/dir.rs @@ -1,7 +1,7 @@ use crate::{BlockAllocator, Bvec, FileInode}; use alloc::boxed::Box; -use error::Errno; -use vfs::{OpenFlags, Stat, Vnode, VnodeImpl, VnodeKind, VnodeRef, IoctlCmd}; +use syscall::error::Errno; +use vfs::{IoctlCmd, OpenFlags, Stat, Vnode, VnodeImpl, VnodeKind, VnodeRef}; pub struct DirInode { alloc: A, diff --git a/fs/memfs/src/file.rs b/fs/memfs/src/file.rs index 9c3a2b1..1bfb297 100644 --- a/fs/memfs/src/file.rs +++ b/fs/memfs/src/file.rs @@ -1,5 +1,5 @@ use crate::{BlockAllocator, Bvec}; -use error::Errno; +use syscall::error::Errno; use vfs::{OpenFlags, Stat, VnodeImpl, VnodeKind, VnodeRef, IoctlCmd}; pub struct FileInode<'a, A: BlockAllocator + Copy + 'static> { diff --git a/fs/memfs/src/lib.rs b/fs/memfs/src/lib.rs index 22ad694..42e02d2 100644 --- a/fs/memfs/src/lib.rs +++ b/fs/memfs/src/lib.rs @@ -14,8 +14,10 @@ extern crate std; use alloc::{boxed::Box, rc::Rc}; use core::any::Any; use core::cell::{Ref, RefCell}; -use error::Errno; -use libcommon::*; +use syscall::{ + error::Errno, + path::{path_component_right, path_component_left} +}; use vfs::{BlockDevice, FileMode, Filesystem, Vnode, VnodeKind, VnodeRef}; mod block; diff --git a/fs/memfs/src/tar.rs b/fs/memfs/src/tar.rs index 0cd4450..3fe7fb3 100644 --- a/fs/memfs/src/tar.rs +++ b/fs/memfs/src/tar.rs @@ -1,4 +1,4 @@ -use error::Errno; +use syscall::error::Errno; use vfs::VnodeKind; #[repr(packed)] diff --git a/fs/vfs/Cargo.toml b/fs/vfs/Cargo.toml index dd4bb6a..e754bc3 100644 --- a/fs/vfs/Cargo.toml +++ b/fs/vfs/Cargo.toml @@ -6,6 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -error = { path = "../../error" } -libcommon = { path = "../../libcommon" } syscall = { path = "../../syscall" } diff --git a/fs/vfs/src/block.rs b/fs/vfs/src/block.rs index 01368c6..8092a62 100644 --- a/fs/vfs/src/block.rs +++ b/fs/vfs/src/block.rs @@ -1,4 +1,4 @@ -use error::Errno; +use syscall::error::Errno; /// Block device interface pub trait BlockDevice { diff --git a/fs/vfs/src/char.rs b/fs/vfs/src/char.rs index 7022076..aeebdd8 100644 --- a/fs/vfs/src/char.rs +++ b/fs/vfs/src/char.rs @@ -1,5 +1,5 @@ use crate::{OpenFlags, Stat, VnodeImpl, VnodeKind, VnodeRef, IoctlCmd}; -use error::Errno; +use syscall::error::Errno; /// Generic character device trait pub trait CharDevice { diff --git a/fs/vfs/src/file.rs b/fs/vfs/src/file.rs index 8eea546..cf30f76 100644 --- a/fs/vfs/src/file.rs +++ b/fs/vfs/src/file.rs @@ -2,8 +2,10 @@ use crate::{VnodeKind, VnodeRef}; use alloc::rc::Rc; use core::cell::RefCell; use core::cmp::min; -use error::Errno; -use libcommon::{Read, Seek, SeekDir, Write}; +use syscall::{ + traits::{Read, Seek, SeekDir, Write}, + error::Errno +}; struct NormalFile { vnode: VnodeRef, diff --git a/fs/vfs/src/fs.rs b/fs/vfs/src/fs.rs index 4b60358..dcb96b5 100644 --- a/fs/vfs/src/fs.rs +++ b/fs/vfs/src/fs.rs @@ -2,7 +2,7 @@ use crate::{BlockDevice, VnodeRef}; use alloc::rc::Rc; use core::any::Any; use core::cell::Ref; -use error::Errno; +use syscall::error::Errno; /// General filesystem interface pub trait Filesystem { diff --git a/fs/vfs/src/ioctx.rs b/fs/vfs/src/ioctx.rs index a736c06..5095186 100644 --- a/fs/vfs/src/ioctx.rs +++ b/fs/vfs/src/ioctx.rs @@ -1,6 +1,8 @@ use crate::{FileMode, FileRef, OpenFlags, VnodeKind, VnodeRef}; -use error::Errno; -use libcommon::{path_component_left, path_component_right}; +use syscall::{ + error::Errno, + path::{path_component_left, path_component_right} +}; /// I/O context structure #[derive(Clone)] diff --git a/fs/vfs/src/node.rs b/fs/vfs/src/node.rs index fb37013..e3c4608 100644 --- a/fs/vfs/src/node.rs +++ b/fs/vfs/src/node.rs @@ -2,7 +2,7 @@ use crate::{File, FileMode, FileRef, Filesystem, IoctlCmd, OpenFlags, Stat}; use alloc::{borrow::ToOwned, boxed::Box, rc::Rc, string::String, vec::Vec}; use core::cell::{RefCell, RefMut}; use core::fmt; -use error::Errno; +use syscall::error::Errno; /// Convenience type alias for [Rc] pub type VnodeRef = Rc; diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 0675dec..8f4b9a8 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -10,10 +10,8 @@ name = "kernel" test = false [dependencies] -error = { path = "../error" } vfs = { path = "../fs/vfs" } memfs = { path = "../fs/memfs" } -libcommon = { path = "../libcommon" } syscall = { path = "../syscall" } cfg-if = "1.x.x" tock-registers = "0.7.x" diff --git a/kernel/src/arch/aarch64/boot/mod.rs b/kernel/src/arch/aarch64/boot/mod.rs index 580132e..898d481 100644 --- a/kernel/src/arch/aarch64/boot/mod.rs +++ b/kernel/src/arch/aarch64/boot/mod.rs @@ -11,7 +11,7 @@ use crate::dev::{ Device, }; use crate::fs::devfs; -use error::Errno; +use syscall::error::Errno; //use crate::debug::Level; use crate::mem::{ self, heap, diff --git a/kernel/src/arch/aarch64/irq/gic/mod.rs b/kernel/src/arch/aarch64/irq/gic/mod.rs index 4346f8a..b4b40a9 100644 --- a/kernel/src/arch/aarch64/irq/gic/mod.rs +++ b/kernel/src/arch/aarch64/irq/gic/mod.rs @@ -7,7 +7,7 @@ use crate::dev::{ use crate::mem::virt::{DeviceMemory, DeviceMemoryIo}; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; mod gicc; use gicc::Gicc; diff --git a/kernel/src/arch/aarch64/mach_orangepi3/gpio.rs b/kernel/src/arch/aarch64/mach_orangepi3/gpio.rs index 06db644..6ff7577 100644 --- a/kernel/src/arch/aarch64/mach_orangepi3/gpio.rs +++ b/kernel/src/arch/aarch64/mach_orangepi3/gpio.rs @@ -12,7 +12,7 @@ use crate::dev::{ use crate::mem::virt::DeviceMemoryIo; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; use tock_registers::interfaces::{Readable, Writeable}; use tock_registers::register_structs; use tock_registers::registers::ReadWrite; diff --git a/kernel/src/arch/aarch64/mach_orangepi3/mod.rs b/kernel/src/arch/aarch64/mach_orangepi3/mod.rs index 2e707b0..66113c7 100644 --- a/kernel/src/arch/aarch64/mach_orangepi3/mod.rs +++ b/kernel/src/arch/aarch64/mach_orangepi3/mod.rs @@ -13,7 +13,7 @@ use crate::dev::{ }; use crate::fs::devfs::{self, CharDeviceType}; use crate::mem::phys; -use error::Errno; +use syscall::error::Errno; mod gpio; mod rtc; diff --git a/kernel/src/arch/aarch64/mach_orangepi3/rtc.rs b/kernel/src/arch/aarch64/mach_orangepi3/rtc.rs index 01eaf1b..5a13f5f 100644 --- a/kernel/src/arch/aarch64/mach_orangepi3/rtc.rs +++ b/kernel/src/arch/aarch64/mach_orangepi3/rtc.rs @@ -7,7 +7,7 @@ use crate::dev::{ use crate::mem::virt::DeviceMemoryIo; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; use tock_registers::{ interfaces::{Readable, Writeable}, register_bitfields, register_structs, diff --git a/kernel/src/arch/aarch64/mach_orangepi3/uart.rs b/kernel/src/arch/aarch64/mach_orangepi3/uart.rs index 8fbc719..3c0bce2 100644 --- a/kernel/src/arch/aarch64/mach_orangepi3/uart.rs +++ b/kernel/src/arch/aarch64/mach_orangepi3/uart.rs @@ -8,7 +8,7 @@ use crate::dev::{ use crate::mem::virt::DeviceMemoryIo; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; use tock_registers::interfaces::{ReadWriteable, Readable, Writeable}; use tock_registers::registers::{Aliased, ReadOnly, ReadWrite}; use tock_registers::{register_bitfields, register_structs}; diff --git a/kernel/src/arch/aarch64/mach_orangepi3/wdog.rs b/kernel/src/arch/aarch64/mach_orangepi3/wdog.rs index 3bca2dd..5ae7ecd 100644 --- a/kernel/src/arch/aarch64/mach_orangepi3/wdog.rs +++ b/kernel/src/arch/aarch64/mach_orangepi3/wdog.rs @@ -2,7 +2,7 @@ use crate::dev::Device; use crate::mem::virt::DeviceMemoryIo; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; use tock_registers::{ interfaces::Writeable, register_bitfields, register_structs, registers::ReadWrite, }; diff --git a/kernel/src/arch/aarch64/mach_qemu/mod.rs b/kernel/src/arch/aarch64/mach_qemu/mod.rs index 344888f..c8a2389 100644 --- a/kernel/src/arch/aarch64/mach_qemu/mod.rs +++ b/kernel/src/arch/aarch64/mach_qemu/mod.rs @@ -13,7 +13,7 @@ use crate::dev::{ }; use crate::fs::devfs::{self, CharDeviceType}; use crate::mem::phys; -use error::Errno; +use syscall::error::Errno; pub use gic::IrqNumber; diff --git a/kernel/src/arch/aarch64/mach_rpi3/emmc.rs b/kernel/src/arch/aarch64/mach_rpi3/emmc.rs index b96835a..75bc25d 100644 --- a/kernel/src/arch/aarch64/mach_rpi3/emmc.rs +++ b/kernel/src/arch/aarch64/mach_rpi3/emmc.rs @@ -7,7 +7,7 @@ use crate::dev::Device; use crate::mem::virt::DeviceMemoryIo; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; use tock_registers::interfaces::{ReadWriteable, Readable, Writeable}; use tock_registers::registers::{ReadOnly, ReadWrite}; use tock_registers::{register_bitfields, register_structs}; diff --git a/kernel/src/arch/aarch64/mach_rpi3/irqchip.rs b/kernel/src/arch/aarch64/mach_rpi3/irqchip.rs index 0e77072..deab40a 100644 --- a/kernel/src/arch/aarch64/mach_rpi3/irqchip.rs +++ b/kernel/src/arch/aarch64/mach_rpi3/irqchip.rs @@ -7,7 +7,7 @@ use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; use core::fmt; use cortex_a::registers::MPIDR_EL1; -use error::Errno; +use syscall::error::Errno; use tock_registers::interfaces::{Readable, Writeable}; use tock_registers::register_structs; diff --git a/kernel/src/arch/aarch64/mach_rpi3/mailbox.rs b/kernel/src/arch/aarch64/mach_rpi3/mailbox.rs index bdfa1e1..94b9f5b 100644 --- a/kernel/src/arch/aarch64/mach_rpi3/mailbox.rs +++ b/kernel/src/arch/aarch64/mach_rpi3/mailbox.rs @@ -2,7 +2,7 @@ use crate::dev::Device; use crate::mem::{self, virt::DeviceMemoryIo}; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; use tock_registers::interfaces::{Readable, Writeable}; use tock_registers::registers::{ReadOnly, WriteOnly}; diff --git a/kernel/src/arch/aarch64/mach_rpi3/mod.rs b/kernel/src/arch/aarch64/mach_rpi3/mod.rs index 91cbf7c..fabb2e4 100644 --- a/kernel/src/arch/aarch64/mach_rpi3/mod.rs +++ b/kernel/src/arch/aarch64/mach_rpi3/mod.rs @@ -5,7 +5,7 @@ use crate::dev::{ Device, }; use crate::mem::phys; -use error::Errno; +use syscall::error::Errno; pub mod irqchip; pub use irqchip::{Bcm283xIrqchip, IrqNumber}; diff --git a/kernel/src/arch/aarch64/timer.rs b/kernel/src/arch/aarch64/timer.rs index 262184f..583a93a 100644 --- a/kernel/src/arch/aarch64/timer.rs +++ b/kernel/src/arch/aarch64/timer.rs @@ -8,7 +8,7 @@ use crate::dev::{ }; use core::time::Duration; use cortex_a::registers::{CNTFRQ_EL0, CNTPCT_EL0, CNTP_CTL_EL0, CNTP_TVAL_EL0}; -use error::Errno; +use syscall::error::Errno; use tock_registers::interfaces::{Readable, Writeable}; /// Generic timer struct diff --git a/kernel/src/dev/fdt.rs b/kernel/src/dev/fdt.rs index f170982..d515323 100644 --- a/kernel/src/dev/fdt.rs +++ b/kernel/src/dev/fdt.rs @@ -1,12 +1,11 @@ //! Device tree facilities use crate::debug::Level; -use error::Errno; use fdt_rs::prelude::*; use fdt_rs::{ base::DevTree, index::{DevTreeIndex, DevTreeIndexNode, DevTreeIndexProp}, }; -use libcommon::path_component_left; +use syscall::{error::Errno, path::path_component_left}; #[repr(align(16))] struct Wrap { diff --git a/kernel/src/dev/gpio.rs b/kernel/src/dev/gpio.rs index 7cf11fe..e21670f 100644 --- a/kernel/src/dev/gpio.rs +++ b/kernel/src/dev/gpio.rs @@ -1,7 +1,7 @@ //! GPIO and pin control interfaces use crate::dev::Device; -use error::Errno; +use syscall::error::Errno; /// Pin function mode pub enum PinMode { diff --git a/kernel/src/dev/irq.rs b/kernel/src/dev/irq.rs index c05e3ab..234c143 100644 --- a/kernel/src/dev/irq.rs +++ b/kernel/src/dev/irq.rs @@ -1,7 +1,7 @@ //! Interrupt controller and handler interfaces use crate::dev::Device; use core::marker::PhantomData; -use error::Errno; +use syscall::error::Errno; /// Token to indicate the local core is running in IRQ context pub struct IrqContext<'irq_context> { diff --git a/kernel/src/dev/mod.rs b/kernel/src/dev/mod.rs index b0e9dae..82c173e 100644 --- a/kernel/src/dev/mod.rs +++ b/kernel/src/dev/mod.rs @@ -1,6 +1,6 @@ //! Module for device interfaces and drivers -use error::Errno; +use syscall::error::Errno; // Device classes pub mod fdt; diff --git a/kernel/src/dev/pci/mod.rs b/kernel/src/dev/pci/mod.rs index 142c75f..cddfa7e 100644 --- a/kernel/src/dev/pci/mod.rs +++ b/kernel/src/dev/pci/mod.rs @@ -2,7 +2,7 @@ use crate::dev::Device; use core::fmt; -use error::Errno; +use syscall::error::Errno; pub mod pcie; diff --git a/kernel/src/dev/pci/pcie/gpex.rs b/kernel/src/dev/pci/pcie/gpex.rs index ee215d2..9ea5169 100644 --- a/kernel/src/dev/pci/pcie/gpex.rs +++ b/kernel/src/dev/pci/pcie/gpex.rs @@ -6,7 +6,7 @@ use crate::dev::{ }; use crate::mem::virt::DeviceMemory; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; /// GPEX host controller struct pub struct GenericPcieHost { diff --git a/kernel/src/dev/rtc/pl031.rs b/kernel/src/dev/rtc/pl031.rs index cf6e6b6..b4eddef 100644 --- a/kernel/src/dev/rtc/pl031.rs +++ b/kernel/src/dev/rtc/pl031.rs @@ -8,7 +8,7 @@ use crate::dev::{ use crate::mem::virt::DeviceMemoryIo; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; -use error::Errno; +use syscall::error::Errno; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, diff --git a/kernel/src/dev/sd.rs b/kernel/src/dev/sd.rs index fe60b98..5946843 100644 --- a/kernel/src/dev/sd.rs +++ b/kernel/src/dev/sd.rs @@ -1,6 +1,6 @@ //! SD host controller interface and card operation facilities use crate::dev::Device; -use error::Errno; +use syscall::error::Errno; use vfs::BlockDevice; /// Generic SD/MMC host controller interface diff --git a/kernel/src/dev/serial/mod.rs b/kernel/src/dev/serial/mod.rs index 2f84e84..a11495e 100644 --- a/kernel/src/dev/serial/mod.rs +++ b/kernel/src/dev/serial/mod.rs @@ -1,7 +1,7 @@ //! Module for serial device drivers use crate::dev::Device; -use error::Errno; +use syscall::error::Errno; #[cfg(feature = "pl011")] pub mod pl011; diff --git a/kernel/src/dev/serial/pl011.rs b/kernel/src/dev/serial/pl011.rs index 634e078..791aa6c 100644 --- a/kernel/src/dev/serial/pl011.rs +++ b/kernel/src/dev/serial/pl011.rs @@ -11,7 +11,7 @@ use crate::mem::virt::DeviceMemoryIo; use crate::sync::IrqSafeSpinLock; use crate::util::InitOnce; use core::fmt; -use error::Errno; +use syscall::error::Errno; use tock_registers::{ interfaces::{ReadWriteable, Readable, Writeable}, register_bitfields, register_structs, diff --git a/kernel/src/dev/timer.rs b/kernel/src/dev/timer.rs index 4494fda..14efc6b 100644 --- a/kernel/src/dev/timer.rs +++ b/kernel/src/dev/timer.rs @@ -2,7 +2,7 @@ use crate::dev::Device; use core::time::Duration; -use error::Errno; +use syscall::error::Errno; /// Interface for generic timestamp source pub trait TimestampSource: Device { diff --git a/kernel/src/dev/tty.rs b/kernel/src/dev/tty.rs index 6a87eba..ba1e8d6 100644 --- a/kernel/src/dev/tty.rs +++ b/kernel/src/dev/tty.rs @@ -2,7 +2,7 @@ use crate::dev::serial::SerialDevice; use crate::proc::wait::Wait; use crate::sync::IrqSafeSpinLock; -use error::Errno; +use syscall::error::Errno; use syscall::{ termios::{Termios, TermiosIflag, TermiosLflag, TermiosOflag}, ioctl::IoctlCmd diff --git a/kernel/src/fs/devfs.rs b/kernel/src/fs/devfs.rs index 3de2ad1..5394e9e 100644 --- a/kernel/src/fs/devfs.rs +++ b/kernel/src/fs/devfs.rs @@ -2,7 +2,7 @@ use crate::util::InitOnce; use alloc::boxed::Box; use core::sync::atomic::{AtomicUsize, Ordering}; -use error::Errno; +use syscall::error::Errno; use vfs::{CharDevice, CharDeviceWrapper, Vnode, VnodeKind, VnodeRef}; /// Possible character device kinds diff --git a/kernel/src/mem/mod.rs b/kernel/src/mem/mod.rs index 878494c..3f2433e 100644 --- a/kernel/src/mem/mod.rs +++ b/kernel/src/mem/mod.rs @@ -26,73 +26,3 @@ pub fn kernel_end_phys() -> usize { } unsafe { &__kernel_end as *const _ as usize - KERNEL_OFFSET } } - -/// See memcpy(3p). -/// -/// # Safety -/// -/// Unsafe: writes to arbitrary memory locations, performs no pointer -/// validation. -#[no_mangle] -pub unsafe extern "C" fn memcpy(dst: *mut u8, src: *mut u8, mut len: usize) -> *mut u8 { - while len != 0 { - len -= 1; - *dst.add(len) = *src.add(len); - } - dst -} - -/// See memcmp(3p). -/// -/// # Safety -/// -/// Unsafe: performs reads from arbitrary memory locations, performs no -/// pointer validation. -#[no_mangle] -pub unsafe extern "C" fn memcmp(a: *mut u8, b: *mut u8, mut len: usize) -> isize { - while len != 0 { - len -= 1; - if *a.add(len) < *b.add(len) { - return -1; - } - if *a.add(len) > *b.add(len) { - return 1; - } - } - 0 -} - -/// See memmove(3p) -/// -/// # Safety -/// -/// Unsafe: writes to arbitrary memory locations, performs no pointer -/// validation. -#[no_mangle] -pub unsafe extern "C" fn memmove(dst: *mut u8, src: *mut u8, len: usize) -> *mut u8 { - if dst < src { - for i in 0..len { - *dst.add(i) = *src.add(i); - } - } else { - for i in 0..len { - *dst.add(len - (i + 1)) = *src.add(len - (i + 1)); - } - } - dst -} - -/// See memset(3p) -/// -/// # Safety -/// -/// Unsafe: writes to arbitrary memory locations, performs no pointer -/// validation. -#[no_mangle] -pub unsafe extern "C" fn memset(buf: *mut u8, val: u8, mut len: usize) -> *mut u8 { - while len != 0 { - len -= 1; - *buf.add(len) = val; - } - buf -} diff --git a/kernel/src/mem/phys/manager.rs b/kernel/src/mem/phys/manager.rs index 0b3fdc4..1afe715 100644 --- a/kernel/src/mem/phys/manager.rs +++ b/kernel/src/mem/phys/manager.rs @@ -1,8 +1,10 @@ use super::{PageInfo, PageUsage}; -use crate::mem::{memcpy, memset, virtualize, PAGE_SIZE}; +use crate::mem::{virtualize, PAGE_SIZE}; use crate::sync::IrqSafeSpinLock; use core::mem; -use error::Errno; +use syscall::{ + error::Errno, mem::{memset, memcpy} +}; pub unsafe trait Manager { fn alloc_page(&mut self, pu: PageUsage) -> Result; diff --git a/kernel/src/mem/phys/mod.rs b/kernel/src/mem/phys/mod.rs index 4a395ac..4d95b57 100644 --- a/kernel/src/mem/phys/mod.rs +++ b/kernel/src/mem/phys/mod.rs @@ -3,7 +3,7 @@ use crate::config::{ConfigKey, CONFIG}; use crate::mem::PAGE_SIZE; use core::mem::size_of; -use error::Errno; +use syscall::error::Errno; mod manager; mod reserved; diff --git a/kernel/src/mem/virt/fixed.rs b/kernel/src/mem/virt/fixed.rs index 1327828..01cc7c6 100644 --- a/kernel/src/mem/virt/fixed.rs +++ b/kernel/src/mem/virt/fixed.rs @@ -5,7 +5,7 @@ use crate::mem::{ virt::{Entry, MapAttributes, Table}, }; use cortex_a::asm::barrier::{self, dsb, isb}; -use error::Errno; +use syscall::error::Errno; const DEVICE_MAP_OFFSET: usize = mem::KERNEL_OFFSET + (256usize << 30); diff --git a/kernel/src/mem/virt/mod.rs b/kernel/src/mem/virt/mod.rs index 97b8639..0dade9a 100644 --- a/kernel/src/mem/virt/mod.rs +++ b/kernel/src/mem/virt/mod.rs @@ -4,7 +4,7 @@ use core::marker::PhantomData; use core::ops::Deref; use cortex_a::asm::barrier::{self, dsb, isb}; use cortex_a::registers::TTBR0_EL1; -use error::Errno; +use syscall::error::Errno; use tock_registers::interfaces::Writeable; pub mod table; diff --git a/kernel/src/mem/virt/table.rs b/kernel/src/mem/virt/table.rs index 3f099b8..4c4ba20 100644 --- a/kernel/src/mem/virt/table.rs +++ b/kernel/src/mem/virt/table.rs @@ -5,7 +5,7 @@ use crate::mem::{ phys::{self, PageUsage}, }; use core::ops::{Index, IndexMut}; -use error::Errno; +use syscall::{error::Errno, mem::memset}; /// Transparent wrapper structure representing a single /// translation table entry @@ -320,7 +320,7 @@ impl Space { } } unsafe { - mem::memset(space as *mut Space as *mut u8, 0, 4096); + memset(space as *mut Space as *mut u8, 0, 4096); } } } diff --git a/kernel/src/proc/elf.rs b/kernel/src/proc/elf.rs index 2f6c3d9..4075ac9 100644 --- a/kernel/src/proc/elf.rs +++ b/kernel/src/proc/elf.rs @@ -5,8 +5,10 @@ use crate::mem::{ virt::{MapAttributes, Space}, }; use core::mem::{size_of, MaybeUninit}; -use error::Errno; -use libcommon::{Read, Seek, SeekDir}; +use syscall::{ + error::Errno, + traits::{Read, Seek, SeekDir} +}; use vfs::FileRef; trait Elf { diff --git a/kernel/src/proc/io.rs b/kernel/src/proc/io.rs index 2267a10..2b97960 100644 --- a/kernel/src/proc/io.rs +++ b/kernel/src/proc/io.rs @@ -1,6 +1,6 @@ //! Process file descriptors and I/O context use alloc::collections::BTreeMap; -use error::Errno; +use syscall::error::Errno; use vfs::{FileRef, Ioctx}; /// Process I/O context. Contains file tables, root/cwd info etc. diff --git a/kernel/src/proc/process.rs b/kernel/src/proc/process.rs index 9d2c2c1..02acc22 100644 --- a/kernel/src/proc/process.rs +++ b/kernel/src/proc/process.rs @@ -11,7 +11,7 @@ use alloc::rc::Rc; use core::cell::UnsafeCell; use core::fmt; use core::sync::atomic::{AtomicU32, Ordering}; -use error::Errno; +use syscall::error::Errno; pub use crate::arch::platform::context::{self, Context}; diff --git a/kernel/src/proc/wait.rs b/kernel/src/proc/wait.rs index c3f49a0..c40783c 100644 --- a/kernel/src/proc/wait.rs +++ b/kernel/src/proc/wait.rs @@ -6,7 +6,7 @@ use crate::proc::{self, sched::SCHED, Pid, Process}; use crate::sync::IrqSafeSpinLock; use alloc::collections::LinkedList; use core::time::Duration; -use error::Errno; +use syscall::error::Errno; /// Wait channel structure. Contains a queue of processes /// waiting for some event to happen. diff --git a/kernel/src/syscall/arg.rs b/kernel/src/syscall/arg.rs index 51c46b0..9b0715c 100644 --- a/kernel/src/syscall/arg.rs +++ b/kernel/src/syscall/arg.rs @@ -2,7 +2,7 @@ use crate::mem; use core::mem::size_of; -use error::Errno; +use syscall::error::Errno; fn translate(virt: usize) -> Option { let mut res: usize; diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index aa3d68a..234c6a5 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -6,13 +6,13 @@ use crate::proc::{elf, wait, Pid, Process, ProcessIo}; use core::mem::size_of; use core::ops::DerefMut; use core::time::Duration; -use error::Errno; -use libcommon::{Read, Write}; use syscall::{ abi, + error::Errno, stat::{AT_EMPTY_PATH, AT_FDCWD}, + traits::{Read, Write}, }; -use vfs::{FileMode, OpenFlags, Stat, VnodeRef, IoctlCmd}; +use vfs::{FileMode, IoctlCmd, OpenFlags, Stat, VnodeRef}; pub mod arg; pub use arg::*; @@ -131,8 +131,8 @@ pub fn syscall(num: usize, args: &[usize]) -> Result { Ok(exit) => { *status = i32::from(exit); Ok(0) - }, - _ => todo!() + } + _ => todo!(), } } abi::SYS_IOCTL => { @@ -144,7 +144,7 @@ pub fn syscall(num: usize, args: &[usize]) -> Result { let node = io.file(fd)?.borrow().node().ok_or(Errno::InvalidFile)?; node.ioctl(cmd, args[2], args[3]) - }, + } // Extra system calls abi::SYS_EX_DEBUG_TRACE => { diff --git a/libcommon/Cargo.toml b/libcommon/Cargo.toml deleted file mode 100644 index a49a495..0000000 --- a/libcommon/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "libcommon" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -error = { path = "../error" } diff --git a/libcommon/src/lib.rs b/libcommon/src/lib.rs deleted file mode 100644 index 961a822..0000000 --- a/libcommon/src/lib.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![no_std] - -use error::Errno; - -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum SeekDir { - Set, - End, - Current, -} - -pub trait Read { - fn read(&mut self, data: &mut [u8]) -> Result; -} - -pub trait Seek { - fn seek(&mut self, off: isize, whence: SeekDir) -> Result; -} - -pub trait Write { - fn write(&mut self, data: &[u8]) -> Result; -} - -pub fn path_component_left(path: &str) -> (&str, &str) { - if let Some((left, right)) = path.split_once('/') { - (left, right.trim_start_matches('/')) - } else { - (path, "") - } -} - -pub fn path_component_right(path: &str) -> (&str, &str) { - if let Some((left, right)) = path.trim_end_matches('/').rsplit_once('/') { - (left.trim_end_matches('/'), right) - } else { - ("", path) - } -} - -pub fn read_le32(src: &[u8]) -> u32 { - (src[0] as u32) | ((src[1] as u32) << 8) | ((src[2] as u32) << 16) | ((src[3] as u32) << 24) -} - -pub fn read_le16(src: &[u8]) -> u16 { - (src[0] as u16) | ((src[1] as u16) << 8) -} - -#[cfg(test)] -mod tests {} diff --git a/libcommon/src/sync.rs b/libcommon/src/sync.rs deleted file mode 100644 index e69de29..0000000 diff --git a/libusr/src/io.rs b/libusr/src/io.rs index e7b9ae7..5968513 100644 --- a/libusr/src/io.rs +++ b/libusr/src/io.rs @@ -1,13 +1,15 @@ -use crate::sys::{self, Stat}; use core::fmt; -use syscall::stat::AT_FDCWD; +use syscall::{ + calls::{sys_fstatat, sys_write}, + stat::{Stat, AT_FDCWD}, +}; // TODO populate this type pub struct Error; pub fn stat(pathname: &str) -> Result { let mut buf = Stat::default(); - let res = unsafe { sys::sys_fstatat(AT_FDCWD, pathname, &mut buf, 0) }; + let res = unsafe { sys_fstatat(AT_FDCWD, pathname, &mut buf, 0) }; if res != 0 { todo!(); } @@ -60,6 +62,6 @@ pub fn _print(fd: i32, args: fmt::Arguments) { }; writer.write_fmt(args).ok(); unsafe { - sys::sys_write(fd, &BUFFER[..writer.pos]); + sys_write(fd, &BUFFER[..writer.pos]); } } diff --git a/libusr/src/lib.rs b/libusr/src/lib.rs index ee8532b..f5e6993 100644 --- a/libusr/src/lib.rs +++ b/libusr/src/lib.rs @@ -4,12 +4,11 @@ use core::panic::PanicInfo; pub mod io; -pub mod mem; pub mod os; pub mod sys { pub use syscall::calls::*; - pub use syscall::stat::*; + pub use syscall::stat::{self, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO}; pub use syscall::termios; } diff --git a/syscall/Cargo.toml b/syscall/Cargo.toml index adfa386..878f881 100644 --- a/syscall/Cargo.toml +++ b/syscall/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] bitflags = "^1.3.0" -error = { path = "../error" } [features] user = [] diff --git a/error/src/lib.rs b/syscall/src/error.rs similarity index 96% rename from error/src/lib.rs rename to syscall/src/error.rs index 69a0188..3657ddb 100644 --- a/error/src/lib.rs +++ b/syscall/src/error.rs @@ -1,5 +1,3 @@ -#![no_std] - #[derive(PartialEq, Debug, Clone, Copy)] pub enum Errno { AlreadyExists, diff --git a/syscall/src/ioctl.rs b/syscall/src/ioctl.rs index 3f308d6..dd0196d 100644 --- a/syscall/src/ioctl.rs +++ b/syscall/src/ioctl.rs @@ -1,6 +1,5 @@ use core::convert::TryFrom; -use error::Errno; - +use crate::error::Errno; #[derive(Clone, Copy, Debug)] #[repr(u32)] diff --git a/syscall/src/lib.rs b/syscall/src/lib.rs index 1b8eb00..8b9d9b2 100644 --- a/syscall/src/lib.rs +++ b/syscall/src/lib.rs @@ -8,6 +8,10 @@ pub mod abi; pub mod stat; pub mod ioctl; pub mod termios; +pub mod error; +pub mod path; +pub mod mem; +pub mod traits; #[cfg(feature = "user")] pub mod calls; diff --git a/libusr/src/mem.rs b/syscall/src/mem.rs similarity index 87% rename from libusr/src/mem.rs rename to syscall/src/mem.rs index 1b9f19a..021c7cc 100644 --- a/libusr/src/mem.rs +++ b/syscall/src/mem.rs @@ -1,3 +1,11 @@ +pub fn read_le32(src: &[u8]) -> u32 { + (src[0] as u32) | ((src[1] as u32) << 8) | ((src[2] as u32) << 16) | ((src[3] as u32) << 24) +} + +pub fn read_le16(src: &[u8]) -> u16 { + (src[0] as u16) | ((src[1] as u16) << 8) +} + /// See memcpy(3p). /// /// # Safety diff --git a/syscall/src/path.rs b/syscall/src/path.rs new file mode 100644 index 0000000..b64ecef --- /dev/null +++ b/syscall/src/path.rs @@ -0,0 +1,15 @@ +pub fn path_component_left(path: &str) -> (&str, &str) { + if let Some((left, right)) = path.split_once('/') { + (left, right.trim_start_matches('/')) + } else { + (path, "") + } +} + +pub fn path_component_right(path: &str) -> (&str, &str) { + if let Some((left, right)) = path.trim_end_matches('/').rsplit_once('/') { + (left.trim_end_matches('/'), right) + } else { + ("", path) + } +} diff --git a/syscall/src/traits.rs b/syscall/src/traits.rs new file mode 100644 index 0000000..c586b0d --- /dev/null +++ b/syscall/src/traits.rs @@ -0,0 +1,28 @@ +use crate::error::Errno; + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum SeekDir { + Set, + End, + Current, +} + +pub trait Read { + fn read(&mut self, data: &mut [u8]) -> Result; +} + +pub trait Seek { + fn seek(&mut self, off: isize, whence: SeekDir) -> Result; +} + +pub trait Write { + fn write(&mut self, data: &[u8]) -> Result; +} + +pub trait RandomRead { + fn pread(&mut self, pos: usize, data: &mut [u8]) -> Result; +} + +pub trait RandomWrite { + fn pwrite(&mut self, pos: usize, data: &[u8]) -> Result; +}