refactor: merge error and libcommon into syscall
This commit is contained in:
Generated
+1
-20
@@ -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",
|
||||
]
|
||||
|
||||
@@ -13,9 +13,7 @@ members = [
|
||||
"fs/memfs",
|
||||
"fs/fat32",
|
||||
"syscall",
|
||||
"libcommon",
|
||||
"kernel",
|
||||
"libusr",
|
||||
"user",
|
||||
"error"
|
||||
]
|
||||
|
||||
@@ -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]
|
||||
@@ -7,5 +7,3 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
vfs = { path = "../vfs" }
|
||||
libcommon = { path = "../../libcommon" }
|
||||
error = { path = "../../error" }
|
||||
|
||||
+1
-2
@@ -7,8 +7,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
vfs = { path = "../vfs" }
|
||||
error = { path = "../../error" }
|
||||
libcommon = { path = "../../libcommon" }
|
||||
syscall = { path = "../../syscall" }
|
||||
|
||||
[features]
|
||||
cow = []
|
||||
|
||||
@@ -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::<usize>();
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-2
@@ -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<A: BlockAllocator + Copy + 'static> {
|
||||
alloc: A,
|
||||
|
||||
@@ -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> {
|
||||
|
||||
+4
-2
@@ -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;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use error::Errno;
|
||||
use syscall::error::Errno;
|
||||
use vfs::VnodeKind;
|
||||
|
||||
#[repr(packed)]
|
||||
|
||||
@@ -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" }
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use error::Errno;
|
||||
use syscall::error::Errno;
|
||||
|
||||
/// Block device interface
|
||||
pub trait BlockDevice {
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
+4
-2
@@ -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,
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
+4
-2
@@ -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)]
|
||||
|
||||
+1
-1
@@ -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<Vnode>]
|
||||
pub type VnodeRef = Rc<Vnode>;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Module for device interfaces and drivers
|
||||
|
||||
use error::Errno;
|
||||
use syscall::error::Errno;
|
||||
|
||||
// Device classes
|
||||
pub mod fdt;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::dev::Device;
|
||||
use core::fmt;
|
||||
use error::Errno;
|
||||
use syscall::error::Errno;
|
||||
|
||||
pub mod pcie;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<usize, Errno>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::mem;
|
||||
use core::mem::size_of;
|
||||
use error::Errno;
|
||||
use syscall::error::Errno;
|
||||
|
||||
fn translate(virt: usize) -> Option<usize> {
|
||||
let mut res: usize;
|
||||
|
||||
@@ -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<usize, Errno> {
|
||||
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<usize, Errno> {
|
||||
|
||||
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 => {
|
||||
|
||||
@@ -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" }
|
||||
@@ -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<usize, Errno>;
|
||||
}
|
||||
|
||||
pub trait Seek {
|
||||
fn seek(&mut self, off: isize, whence: SeekDir) -> Result<usize, Errno>;
|
||||
}
|
||||
|
||||
pub trait Write {
|
||||
fn write(&mut self, data: &[u8]) -> Result<usize, Errno>;
|
||||
}
|
||||
|
||||
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 {}
|
||||
+6
-4
@@ -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<Stat, Error> {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "^1.3.0"
|
||||
error = { path = "../error" }
|
||||
|
||||
[features]
|
||||
user = []
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#![no_std]
|
||||
|
||||
#[derive(PartialEq, Debug, Clone, Copy)]
|
||||
pub enum Errno {
|
||||
AlreadyExists,
|
||||
@@ -1,6 +1,5 @@
|
||||
use core::convert::TryFrom;
|
||||
use error::Errno;
|
||||
|
||||
use crate::error::Errno;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[repr(u32)]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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<usize, Errno>;
|
||||
}
|
||||
|
||||
pub trait Seek {
|
||||
fn seek(&mut self, off: isize, whence: SeekDir) -> Result<usize, Errno>;
|
||||
}
|
||||
|
||||
pub trait Write {
|
||||
fn write(&mut self, data: &[u8]) -> Result<usize, Errno>;
|
||||
}
|
||||
|
||||
pub trait RandomRead {
|
||||
fn pread(&mut self, pos: usize, data: &mut [u8]) -> Result<usize, Errno>;
|
||||
}
|
||||
|
||||
pub trait RandomWrite {
|
||||
fn pwrite(&mut self, pos: usize, data: &[u8]) -> Result<usize, Errno>;
|
||||
}
|
||||
Reference in New Issue
Block a user