Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 93a0584605 | |||
| 9c32c11b0b | |||
| 3be32b7b8f |
Generated
+68
@@ -2638,6 +2638,70 @@ dependencies = [
|
||||
"yggdrasil-abi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ygg_driver_bsp_arm"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"device-api",
|
||||
"device-tree",
|
||||
"libk",
|
||||
"libk-mm",
|
||||
"libk-util",
|
||||
"log",
|
||||
"tock-registers",
|
||||
"yggdrasil-abi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ygg_driver_bsp_bcm283x"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"device-api",
|
||||
"device-tree",
|
||||
"futures-util",
|
||||
"kernel-arch-aarch64",
|
||||
"libk",
|
||||
"libk-mm",
|
||||
"libk-util",
|
||||
"log",
|
||||
"tock-registers",
|
||||
"yggdrasil-abi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ygg_driver_bsp_jh7110"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"device-api",
|
||||
"device-tree",
|
||||
"futures-util",
|
||||
"libk",
|
||||
"libk-mm",
|
||||
"libk-util",
|
||||
"log",
|
||||
"tock-registers",
|
||||
"yggdrasil-abi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ygg_driver_bsp_riscv"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"device-api",
|
||||
"device-tree",
|
||||
"kernel-arch-riscv64",
|
||||
"libk",
|
||||
"libk-mm",
|
||||
"libk-util",
|
||||
"log",
|
||||
"tock-registers",
|
||||
"yggdrasil-abi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ygg_driver_fat32"
|
||||
version = "0.1.0"
|
||||
@@ -2951,6 +3015,10 @@ dependencies = [
|
||||
"yboot-proto",
|
||||
"ygg_driver_acpi",
|
||||
"ygg_driver_ahci",
|
||||
"ygg_driver_bsp_arm",
|
||||
"ygg_driver_bsp_bcm283x",
|
||||
"ygg_driver_bsp_jh7110",
|
||||
"ygg_driver_bsp_riscv",
|
||||
"ygg_driver_fat32",
|
||||
"ygg_driver_input",
|
||||
"ygg_driver_net_core",
|
||||
|
||||
@@ -56,11 +56,16 @@ git-version = "0.3.9"
|
||||
aarch64-cpu.workspace = true
|
||||
device-tree.workspace = true
|
||||
kernel-arch-aarch64.workspace = true
|
||||
ygg_driver_bsp_arm.path = "driver/bsp/arm"
|
||||
ygg_driver_bsp_bcm283x.path = "driver/bsp/bcm283x"
|
||||
|
||||
[target.'cfg(target_arch = "riscv64")'.dependencies]
|
||||
device-tree.workspace = true
|
||||
kernel-arch-riscv64.workspace = true
|
||||
ygg_driver_bsp_arm.path = "driver/bsp/arm" # PrimeCell components
|
||||
ygg_driver_bsp_riscv.path = "driver/bsp/riscv"
|
||||
ygg_driver_net_stmmac.path = "driver/net/stmmac"
|
||||
ygg_driver_bsp_jh7110.path = "driver/bsp/jh7110"
|
||||
|
||||
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
||||
yboot-proto.workspace = true
|
||||
@@ -87,7 +92,11 @@ kernel-arch-aarch64.workspace = true
|
||||
kernel-arch-riscv64.workspace = true
|
||||
|
||||
ygg_driver_acpi.path = "driver/acpi"
|
||||
ygg_driver_bsp_arm.path = "driver/bsp/arm"
|
||||
ygg_driver_bsp_riscv.path = "driver/bsp/riscv"
|
||||
ygg_driver_net_stmmac.path = "driver/net/stmmac"
|
||||
ygg_driver_bsp_bcm283x.path = "driver/bsp/bcm283x"
|
||||
ygg_driver_bsp_jh7110.path = "driver/bsp/jh7110"
|
||||
|
||||
[features]
|
||||
default = ["fb_console"]
|
||||
|
||||
@@ -44,6 +44,7 @@ pub struct PerCpuData {
|
||||
}
|
||||
|
||||
pub static CPU_COUNT: AtomicUsize = AtomicUsize::new(1);
|
||||
pub static mut BOOT_HART_ID: u64 = 0;
|
||||
static IPI_QUEUES: OneTimeInit<Vec<IpiQueue<ArchitectureImpl>>> = OneTimeInit::new();
|
||||
static HART_TO_QUEUE: IrqSafeSpinlock<ArchitectureImpl, BTreeMap<u32, usize>> =
|
||||
IrqSafeSpinlock::new(BTreeMap::new());
|
||||
@@ -60,6 +61,11 @@ impl CpuData for PerCpuData {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the ID of the bootstrap HART
|
||||
pub fn boot_hart_id() -> u64 {
|
||||
unsafe { BOOT_HART_ID }
|
||||
}
|
||||
|
||||
#[unsafe(naked)]
|
||||
extern "C" fn idle_task(_: usize) -> ! {
|
||||
core::arch::naked_asm!("1: nop; j 1b");
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "ygg_driver_bsp_arm"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
device-tree.workspace = true
|
||||
device-api.workspace = true
|
||||
yggdrasil-abi.workspace = true
|
||||
libk-mm.workspace = true
|
||||
libk-util.workspace = true
|
||||
libk.workspace = true
|
||||
|
||||
tock-registers.workspace = true
|
||||
log.workspace = true
|
||||
bytemuck.workspace = true
|
||||
@@ -0,0 +1,7 @@
|
||||
#![allow(unsafe_op_in_unsafe_fn)]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
mod pl011;
|
||||
mod pl061;
|
||||
@@ -1,5 +1,3 @@
|
||||
//! ARM PL011 driver
|
||||
use abi::{error::Error, io::TerminalOptions};
|
||||
use alloc::sync::Arc;
|
||||
use device_api::{
|
||||
device::{Device, DeviceInitContext},
|
||||
@@ -18,6 +16,7 @@ use tock_registers::{
|
||||
register_bitfields, register_structs,
|
||||
registers::{ReadOnly, ReadWrite, WriteOnly},
|
||||
};
|
||||
use yggdrasil_abi::{error::Error, io::TerminalOptions};
|
||||
|
||||
register_bitfields! {
|
||||
u32,
|
||||
@@ -1,6 +1,5 @@
|
||||
use core::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use abi::error::Error;
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use device_api::{
|
||||
clock::{ClockHandle, ResetHandle},
|
||||
@@ -26,6 +25,7 @@ use tock_registers::{
|
||||
register_structs,
|
||||
registers::{ReadOnly, ReadWrite, WriteOnly},
|
||||
};
|
||||
use yggdrasil_abi::error::Error;
|
||||
|
||||
register_structs! {
|
||||
#[allow(non_snake_case)]
|
||||
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "ygg_driver_bsp_bcm283x"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
device-tree.workspace = true
|
||||
device-api.workspace = true
|
||||
yggdrasil-abi.workspace = true
|
||||
libk-mm.workspace = true
|
||||
libk-util.workspace = true
|
||||
libk.workspace = true
|
||||
kernel-arch-aarch64.workspace = true
|
||||
|
||||
tock-registers.workspace = true
|
||||
log.workspace = true
|
||||
bytemuck.workspace = true
|
||||
futures-util.workspace = true
|
||||
@@ -1,6 +1,3 @@
|
||||
//! BCM283x AUX peripheral
|
||||
use aarch64_cpu::registers::ReadWriteable;
|
||||
use abi::error::Error;
|
||||
use alloc::sync::Arc;
|
||||
use device_api::{
|
||||
clock::{ClockController, ClockHandle},
|
||||
@@ -13,9 +10,11 @@ use device_tree::{
|
||||
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo};
|
||||
use libk_util::{sync::IrqSafeSpinlock, OneTimeInit};
|
||||
use tock_registers::{
|
||||
interfaces::ReadWriteable,
|
||||
register_bitfields, register_structs,
|
||||
registers::{ReadOnly, ReadWrite},
|
||||
};
|
||||
use yggdrasil_abi::error::Error;
|
||||
|
||||
register_bitfields! {
|
||||
u32,
|
||||
+4
-6
@@ -1,9 +1,3 @@
|
||||
//! Broadcom BCM2835 mini-UART driver
|
||||
|
||||
use abi::{
|
||||
error::Error,
|
||||
io::{TerminalOptions, TerminalOutputOptions},
|
||||
};
|
||||
use alloc::sync::Arc;
|
||||
use device_api::{
|
||||
clock::ClockHandle,
|
||||
@@ -23,6 +17,10 @@ use tock_registers::{
|
||||
register_bitfields, register_structs,
|
||||
registers::{ReadOnly, ReadWrite},
|
||||
};
|
||||
use yggdrasil_abi::{
|
||||
error::Error,
|
||||
io::{TerminalOptions, TerminalOutputOptions},
|
||||
};
|
||||
|
||||
register_bitfields! {
|
||||
u32,
|
||||
@@ -1,4 +1,3 @@
|
||||
use abi::error::Error;
|
||||
use alloc::sync::Arc;
|
||||
use device_api::{
|
||||
device::{Device, DeviceInitContext},
|
||||
@@ -20,6 +19,7 @@ use tock_registers::{
|
||||
register_structs,
|
||||
registers::{ReadOnly, ReadWrite, WriteOnly},
|
||||
};
|
||||
use yggdrasil_abi::error::Error;
|
||||
|
||||
const PUPD_NONE: u32 = 0b00;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
mod aux;
|
||||
mod aux_uart;
|
||||
mod gpio;
|
||||
mod mbox;
|
||||
@@ -1,8 +1,5 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use core::{cell::UnsafeCell, mem::MaybeUninit};
|
||||
|
||||
use abi::error::Error;
|
||||
use alloc::sync::Arc;
|
||||
use device_api::device::{Device, DeviceInitContext};
|
||||
use device_tree::driver::{device_tree_driver, Node, ProbeContext};
|
||||
@@ -25,6 +22,7 @@ use tock_registers::{
|
||||
register_bitfields, register_structs,
|
||||
registers::{ReadOnly, ReadWrite, WriteOnly},
|
||||
};
|
||||
use yggdrasil_abi::error::Error;
|
||||
|
||||
register_bitfields! {
|
||||
u32,
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "ygg_driver_bsp_jh7110"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
device-tree.workspace = true
|
||||
device-api.workspace = true
|
||||
yggdrasil-abi.workspace = true
|
||||
libk-mm.workspace = true
|
||||
libk-util.workspace = true
|
||||
libk.workspace = true
|
||||
|
||||
tock-registers.workspace = true
|
||||
log.workspace = true
|
||||
bytemuck.workspace = true
|
||||
futures-util.workspace = true
|
||||
@@ -1,8 +1,5 @@
|
||||
//! StarFive JH7110 clock drivers
|
||||
|
||||
use core::{marker::PhantomData, ops::Index};
|
||||
|
||||
use abi::error::Error;
|
||||
use alloc::sync::Arc;
|
||||
use device_api::{
|
||||
clock::{ClockController, ClockHandle, Hertz, ResetController, ResetHandle},
|
||||
@@ -17,6 +14,7 @@ use device_tree::{
|
||||
};
|
||||
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIoMut};
|
||||
use libk_util::sync::IrqSafeSpinlock;
|
||||
use yggdrasil_abi::error::Error;
|
||||
|
||||
// SYSCRG clocks
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#![allow(unsafe_op_in_unsafe_fn)]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
mod clocks;
|
||||
mod pinctrl;
|
||||
+1
-1
@@ -1,4 +1,3 @@
|
||||
use abi::error::Error;
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use device_api::{
|
||||
clock::{ClockHandle, ResetHandle},
|
||||
@@ -18,6 +17,7 @@ use device_tree::{
|
||||
};
|
||||
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIoMut};
|
||||
use libk_util::{bit::BitField, sync::IrqSafeSpinlock, OneTimeInit};
|
||||
use yggdrasil_abi::error::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PinMuxConfig {
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "ygg_driver_bsp_riscv"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
device-tree.workspace = true
|
||||
device-api.workspace = true
|
||||
yggdrasil-abi.workspace = true
|
||||
libk-mm.workspace = true
|
||||
libk-util.workspace = true
|
||||
libk.workspace = true
|
||||
kernel-arch-riscv64.workspace = true
|
||||
|
||||
tock-registers.workspace = true
|
||||
log.workspace = true
|
||||
bytemuck.workspace = true
|
||||
@@ -0,0 +1,6 @@
|
||||
#![allow(unsafe_op_in_unsafe_fn)]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
mod plic;
|
||||
@@ -1,6 +1,3 @@
|
||||
//! RISC-V PLIC driver
|
||||
|
||||
use abi::{error::Error, primitive_enum};
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use device_api::{
|
||||
device::{Device, DeviceInitContext},
|
||||
@@ -15,6 +12,7 @@ use device_tree::{
|
||||
},
|
||||
DeviceTreePropertyRead, TProp,
|
||||
};
|
||||
use kernel_arch_riscv64::boot_hart_id;
|
||||
use libk::{arch::Cpu, device::register_external_interrupt_controller};
|
||||
use libk_mm::{address::PhysicalAddress, device::DeviceMemoryIo};
|
||||
use libk_util::{sync::spin_rwlock::IrqSafeRwLock, OneTimeInit};
|
||||
@@ -23,8 +21,7 @@ use tock_registers::{
|
||||
register_structs,
|
||||
registers::{ReadOnly, ReadWrite},
|
||||
};
|
||||
|
||||
use crate::arch::riscv64::boot::boot_hart_id;
|
||||
use yggdrasil_abi::{error::Error, primitive_enum};
|
||||
|
||||
const MAX_IRQS: usize = 1024;
|
||||
|
||||
@@ -243,7 +243,7 @@ fn validate_user_align_size(addr: usize, layout: &Layout) -> Result<(), Error> {
|
||||
return Err(Error::InvalidArgument);
|
||||
}
|
||||
if addr + layout.size() > KERNEL_VIRT_OFFSET {
|
||||
todo!();
|
||||
return Err(Error::InvalidArgument);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -7,7 +7,7 @@ use core::{
|
||||
|
||||
use elf::{abi, relocation::Elf64_Rela};
|
||||
use kernel_arch::{Architecture, ArchitectureImpl};
|
||||
use kernel_arch_riscv64::{mem, CPU_COUNT};
|
||||
use kernel_arch_riscv64::{mem, BOOT_HART_ID, CPU_COUNT};
|
||||
use libk::{
|
||||
debug,
|
||||
fs::{devfs, sysfs},
|
||||
@@ -28,7 +28,6 @@ const BOOT_STACK_SIZE: usize = 65536;
|
||||
|
||||
static mut KERNEL_LOAD_BASE: u64 = 0;
|
||||
static mut DTB_ADDRESS: PhysicalAddress = PhysicalAddress::ZERO;
|
||||
static mut BOOT_HART_ID: u64 = 0;
|
||||
static mut BOOT_STACK: BootStack<BOOT_STACK_SIZE> = BootStack::zeroed();
|
||||
|
||||
#[repr(C, align(0x10))]
|
||||
@@ -58,11 +57,6 @@ unsafe extern "C" fn relocate_kernel(image_base: i64, rela_start: usize, rela_en
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the ID of the bootstrap HART
|
||||
pub fn boot_hart_id() -> u64 {
|
||||
unsafe { BOOT_HART_ID }
|
||||
}
|
||||
|
||||
unsafe fn long_jump(pc: usize, sp: usize, a0: usize) -> ! {
|
||||
core::arch::asm!("mv sp, {sp}; jr {pc}", in("a0") a0, sp = in(reg) sp, pc = in(reg) pc, options(noreturn))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use abi::error::Error;
|
||||
use device_api::interrupt::{IpiDeliveryTarget, IpiMessage};
|
||||
use device_tree::{DeviceTree, DeviceTreeNodeExt};
|
||||
use kernel_arch_riscv64::{
|
||||
mem::auto_lower_address, registers::SIP, sbi, ArchitectureImpl, CPU_COUNT,
|
||||
boot_hart_id, mem::auto_lower_address, registers::SIP, sbi, ArchitectureImpl, CPU_COUNT,
|
||||
};
|
||||
use libk::arch::Cpu;
|
||||
use libk_mm::{
|
||||
@@ -15,7 +15,7 @@ use libk_mm::{
|
||||
};
|
||||
use tock_registers::interfaces::ReadWriteable;
|
||||
|
||||
use crate::{arch::riscv64::boot::boot_hart_id, panic};
|
||||
use crate::panic;
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub const SECONDARY_STACK_SIZE: usize = 32768;
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
//! Clock controller drivers
|
||||
|
||||
#[cfg(any(target_arch = "aarch64", rust_analyzer))]
|
||||
pub mod bcm2835_aux;
|
||||
|
||||
#[cfg(any(target_arch = "riscv64", rust_analyzer))]
|
||||
pub mod jh7110_clocks;
|
||||
|
||||
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64", rust_analyzer))]
|
||||
pub mod fixed;
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
//! Interrupt controller drivers
|
||||
|
||||
#[cfg(any(target_arch = "riscv64", rust_analyzer))]
|
||||
pub mod riscv_plic;
|
||||
@@ -1,4 +0,0 @@
|
||||
//! Mailbox interfaces
|
||||
|
||||
#[cfg(any(rust_analyzer, target_arch = "aarch64"))]
|
||||
mod bcm2835_mbox;
|
||||
@@ -6,13 +6,12 @@ use libk_util::OneTimeInit;
|
||||
pub mod bus;
|
||||
pub mod clock;
|
||||
pub mod display;
|
||||
pub mod gpio;
|
||||
pub mod interrupt;
|
||||
pub mod mbox;
|
||||
pub mod pinctrl;
|
||||
pub mod power;
|
||||
pub mod serial;
|
||||
// pub mod timer;
|
||||
|
||||
#[cfg(any(rust_analyzer, not(target_arch = "x86_64")))]
|
||||
pub mod gpio;
|
||||
|
||||
/// Generic machine description string
|
||||
pub static MACHINE_NAME: OneTimeInit<String> = OneTimeInit::new();
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
//! GPIO/Pin controller, multiplexer drivers
|
||||
|
||||
#[cfg(any(target_arch = "aarch64", rust_analyzer))]
|
||||
mod bcm2711_gpio;
|
||||
#[cfg(any(target_arch = "riscv64", rust_analyzer))]
|
||||
mod jh7110_pinctrl;
|
||||
#[cfg(any(target_arch = "aarch64", rust_analyzer))]
|
||||
mod pl061;
|
||||
@@ -1,11 +1,5 @@
|
||||
//! Serial device interfaces
|
||||
|
||||
#[cfg(any(target_arch = "aarch64", rust_analyzer))]
|
||||
pub mod bcm2835_aux_uart;
|
||||
|
||||
#[cfg(any(target_arch = "aarch64", rust_analyzer))]
|
||||
pub mod pl011;
|
||||
|
||||
#[cfg(any(target_arch = "riscv64", rust_analyzer))]
|
||||
pub mod ns16550a;
|
||||
#[cfg(any(target_arch = "riscv64", rust_analyzer))]
|
||||
|
||||
@@ -74,7 +74,13 @@ extern crate ygg_driver_virtio_net;
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_arch = "x86_64")] {
|
||||
extern crate ygg_driver_net_igbe;
|
||||
} else if #[cfg(target_arch = "aarch64")] {
|
||||
extern crate ygg_driver_bsp_arm;
|
||||
extern crate ygg_driver_bsp_bcm283x;
|
||||
} else if #[cfg(target_arch = "riscv64")] {
|
||||
extern crate ygg_driver_bsp_riscv;
|
||||
extern crate ygg_driver_bsp_jh7110;
|
||||
|
||||
extern crate ygg_driver_net_stmmac;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ struct SpawnOptions<'a> {
|
||||
pub environment: &'a [&'a str],
|
||||
/// Working directory
|
||||
pub directory: Option<&'a str>,
|
||||
/// Root path
|
||||
pub root: Option<&'a str>,
|
||||
/// Optional arguments to specify details of the creation
|
||||
pub optional: &'a [SpawnOption],
|
||||
/// Extra flags controlling the new process behavior
|
||||
|
||||
Generated
+24
@@ -901,6 +901,12 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "elf"
|
||||
version = "0.7.4"
|
||||
@@ -1089,6 +1095,15 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuzzy"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"rand",
|
||||
"runtime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
@@ -1410,6 +1425,15 @@ version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
|
||||
@@ -17,6 +17,7 @@ members = [
|
||||
"netutils",
|
||||
"sysutils",
|
||||
"tools/crypt",
|
||||
"tools/fuzzy",
|
||||
"tools/init",
|
||||
"tools/md2txt",
|
||||
"tools/ntpc",
|
||||
|
||||
@@ -41,6 +41,10 @@ path = "src/lib.rs"
|
||||
name = "mount"
|
||||
path = "src/mount.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "chroot"
|
||||
path = "src/chroot.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "login"
|
||||
path = "src/login.rs"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
use std::process::ExitCode;
|
||||
|
||||
fn usage(cmd: &str) {
|
||||
eprintln!("Usage: {cmd} PATH PROGRAM [ARGS...]");
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let mut args = std::env::args();
|
||||
let cmd = args.next().unwrap();
|
||||
let Some(path) = args.next() else {
|
||||
usage(&cmd);
|
||||
return ExitCode::FAILURE;
|
||||
};
|
||||
let Some(program) = args.next() else {
|
||||
usage(&cmd);
|
||||
return ExitCode::FAILURE;
|
||||
};
|
||||
let cmd_args = args.collect::<Vec<_>>();
|
||||
|
||||
println!("Run {program:?} at {path:?} with args {cmd_args:?}");
|
||||
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "fuzzy"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
itertools = "0.14.0"
|
||||
rand.workspace = true
|
||||
runtime.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,164 @@
|
||||
#![feature(rustc_private)]
|
||||
|
||||
use itertools::Itertools;
|
||||
use rand::Rng;
|
||||
use runtime::abi::SyscallFunction;
|
||||
|
||||
enum Argument {
|
||||
Fd,
|
||||
OptionFd,
|
||||
Path,
|
||||
AccessMode,
|
||||
BytesRef,
|
||||
BytesMut,
|
||||
FileSize,
|
||||
Enum(usize),
|
||||
Number(usize, usize),
|
||||
}
|
||||
|
||||
struct Definition {
|
||||
name: &'static str,
|
||||
number: usize,
|
||||
args: &'static [Argument],
|
||||
}
|
||||
|
||||
const fn syscall(
|
||||
func: SyscallFunction,
|
||||
name: &'static str,
|
||||
args: &'static [Argument],
|
||||
) -> Definition {
|
||||
Definition {
|
||||
name,
|
||||
number: func as _,
|
||||
args,
|
||||
}
|
||||
}
|
||||
|
||||
const DEFS: &[Definition] = const {
|
||||
use Argument::*;
|
||||
|
||||
&[
|
||||
// syscall get_random(buffer: &mut [u8]);
|
||||
syscall(SyscallFunction::GetRandom, "get_random", &[BytesMut]),
|
||||
// syscall get_clock(clock: ClockType, out: &mut MaybeUninit<SystemTime>) -> Result<()>;
|
||||
// syscall set_clock(clock: ClockType, value: &SystemTime) -> Result<()>;
|
||||
// syscall mount(opts: &MountOptions<'_>) -> Result<()>;
|
||||
// syscall unmount(opts: &UnmountOptions) -> Result<()>;
|
||||
// syscall load_module(path: &str) -> Result<()>;
|
||||
|
||||
// syscall filesystem_control(fd: Option<RawFd>, option: u32, value: &mut [u8], len: usize) -> Result<usize>;
|
||||
// syscall get_system_info(option: u32, value: &mut [u8]) -> Result<usize>;
|
||||
|
||||
// syscall open(at: Option<RawFd>, path: &str, opts: OpenOptions, mode: FileMode) -> Result<RawFd>;
|
||||
syscall(SyscallFunction::Open, "open", &[OptionFd, Path, AccessMode]),
|
||||
// syscall check_access(at: Option<RawFd>, path: &str, access: AccessMode) -> Result<()>;
|
||||
syscall(
|
||||
SyscallFunction::CheckAccess,
|
||||
"check_access",
|
||||
&[OptionFd, Path, AccessMode],
|
||||
),
|
||||
// syscall close(fd: RawFd) -> Result<()>;
|
||||
syscall(SyscallFunction::Close, "close", &[Fd]),
|
||||
// syscall write(fd: RawFd, data: &[u8]) -> Result<usize>;
|
||||
syscall(SyscallFunction::Write, "write", &[Fd, BytesRef]),
|
||||
// syscall read(fd: RawFd, data: &mut [u8]) -> Result<usize>;
|
||||
syscall(SyscallFunction::Read, "read", &[Fd, BytesMut]),
|
||||
// syscall seek(fd: RawFd, pos: SeekFrom, output: &mut u64) -> Result<()>; TODO
|
||||
// syscall truncate(fd: RawFd, size: u64) -> Result<()>;
|
||||
syscall(SyscallFunction::Truncate, "truncate", &[Fd, FileSize]),
|
||||
// syscall fsync(fd: RawFd, what: FileSync) -> Result<()>;
|
||||
// syscall(SyscallFunction::Fsync, "fsync", &[Fd, Enum(123)]), TODO not implemented
|
||||
// syscall read_at(fd: RawFd, pos: u64, data: &mut [u8]) -> Result<usize>;
|
||||
syscall(
|
||||
SyscallFunction::ReadAt,
|
||||
"read_at",
|
||||
&[Fd, FileSize, BytesMut],
|
||||
),
|
||||
// syscall write_at(fd: RawFd, pos: u64, data: &[u8]) -> Result<usize>;
|
||||
syscall(
|
||||
SyscallFunction::WriteAt,
|
||||
"write_at",
|
||||
&[Fd, FileSize, BytesRef],
|
||||
),
|
||||
// syscall get_file_option(fd: RawFd, option: u32, data: &mut [u8]) -> Result<usize>;
|
||||
syscall(
|
||||
SyscallFunction::GetFileOption,
|
||||
"get_file_option",
|
||||
&[Fd, Number(usize::MIN, usize::MAX), BytesMut],
|
||||
),
|
||||
// syscall set_file_option(fd: RawFd, option: u32, data: &[u8]) -> Result<()>;
|
||||
syscall(
|
||||
SyscallFunction::SetFileOption,
|
||||
"set_file_option",
|
||||
&[Fd, Number(usize::MIN, usize::MAX), BytesRef],
|
||||
),
|
||||
]
|
||||
};
|
||||
|
||||
fn generate_argument_variants(arg: &Argument) -> Vec<Vec<usize>> {
|
||||
match arg {
|
||||
Argument::Path | Argument::BytesRef => {
|
||||
vec![vec![0, 0], vec![0, 123], vec![0xFFFFFF8012345678, 123]]
|
||||
}
|
||||
Argument::BytesMut => {
|
||||
vec![
|
||||
vec![0, 0],
|
||||
vec![0, 123],
|
||||
vec![0xFFFFFF8012345678, 123],
|
||||
vec!["abcdef".as_ptr().addr(), 123],
|
||||
]
|
||||
}
|
||||
Argument::OptionFd | Argument::Fd => {
|
||||
vec![vec![1234], vec![usize::MAX]]
|
||||
}
|
||||
Argument::AccessMode => {
|
||||
vec![vec![0], vec![usize::MAX]]
|
||||
}
|
||||
Argument::FileSize => {
|
||||
vec![vec![usize::MAX]]
|
||||
}
|
||||
&Argument::Enum(lower_bound) => {
|
||||
vec![vec![lower_bound + 1], vec![usize::MAX]]
|
||||
}
|
||||
&Argument::Number(a, b) => (0..100)
|
||||
.map(|_| rand::thread_rng().gen_range(a..b))
|
||||
.map(|a| vec![a])
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fuzz(def: &Definition) {
|
||||
let argument_variants = def
|
||||
.args
|
||||
.iter()
|
||||
.map(generate_argument_variants)
|
||||
.multi_cartesian_product()
|
||||
.map(|combo| combo.into_iter().flatten());
|
||||
|
||||
for variant in argument_variants {
|
||||
let variant = variant.collect::<Vec<_>>();
|
||||
println!("{}: {:x?}", def.name, variant);
|
||||
let result = unsafe {
|
||||
match variant.len() {
|
||||
1 => runtime::rt::syscall!(def.number, variant[0]),
|
||||
2 => runtime::rt::syscall!(def.number, variant[0], variant[1]),
|
||||
3 => runtime::rt::syscall!(def.number, variant[0], variant[1], variant[2]),
|
||||
4 => runtime::rt::syscall!(
|
||||
def.number, variant[0], variant[1], variant[2], variant[3]
|
||||
),
|
||||
5 => runtime::rt::syscall!(
|
||||
def.number, variant[0], variant[1], variant[2], variant[3], variant[4]
|
||||
),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
};
|
||||
|
||||
println!(" -> {:#x} ({})", result, result as isize);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for def in DEFS {
|
||||
fuzz(def);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ const PROGRAMS: &[(&str, &str)] = &[
|
||||
// sysutils
|
||||
("echo", "bin/echo"),
|
||||
("mount", "sbin/mount"),
|
||||
("chroot", "sbin/chroot"),
|
||||
("login", "sbin/login"),
|
||||
("strace", "bin/strace"),
|
||||
("ls", "bin/ls"),
|
||||
@@ -80,6 +81,7 @@ const PROGRAMS: &[(&str, &str)] = &[
|
||||
// crypt
|
||||
("crypt", "bin/crypt"),
|
||||
("dyn-loader", "libexec/dyn-loader"),
|
||||
("fuzzy", "sbin/fuzzy"),
|
||||
// TODO: proper process for C program builds
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user