From 56b569deb24e5621e93cf89fce4f647646ca20ff Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 11 Apr 2022 22:51:54 +0200 Subject: [PATCH] Refactoring - Applied some clippy lints - Formatting - Replaced lazy_static with Lazy from spin --- Cargo.lock | 15 +----- ableos/Cargo.toml | 30 +++-------- ableos/src/alias_table/mod.rs | 5 +- ableos/src/arch/x86_64/drivers/serial.rs | 17 +++---- ableos/src/arch/x86_64/drivers/vga.rs | 14 +++--- ableos/src/arch/x86_64/gdt.rs | 52 ++++++++++---------- ableos/src/arch/x86_64/interrupts.rs | 51 ++++++++++--------- ableos/src/arch/x86_64/mod.rs | 3 +- ableos/src/devices/dev_vterm.rs | 20 ++++---- ableos/src/devices/mod.rs | 11 ++--- ableos/src/driver_traits/serial.rs | 2 +- ableos/src/experiments/absi.rs | 6 +-- ableos/src/experiments/clip.rs | 20 ++++---- ableos/src/experiments/info.rs | 17 +++---- ableos/src/experiments/kinfo.rs | 19 +++---- ableos/src/filesystem/mod.rs | 19 ++++--- ableos/src/graphics/mod.rs | 9 ++-- ableos/src/kernel_state.rs | 8 ++- ableos/src/kmain.rs | 24 ++++----- ableos/src/logger.rs | 20 +++----- ableos/src/relib/clparse/mod.rs | 14 ++---- ableos/src/relib/encoding/rle.rs | 8 ++- ableos/src/relib/network/socket.rs | 13 ++--- ableos/src/rhai_shell/mod.rs | 33 ++++++------- ableos/src/scheduler/mod.rs | 13 ++--- ableos/src/scratchpad.rs | 8 --- ableos/src/stdio.rs | 5 +- ableos/src/vga_e.rs | 16 +++--- ableos/src/wasm/mod.rs | 2 +- ableos/src/wasm_jumploader/host_functions.rs | 15 +++--- ableos/src/wasm_jumploader/mod.rs | 10 ++-- kernel/Cargo.toml | 5 -- kernel/src/lib.rs | 6 +-- repbuild/Cargo.toml | 6 +-- repbuild/src/main.rs | 16 +++--- 35 files changed, 218 insertions(+), 314 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4df9a169..b912d5913 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,6 @@ dependencies = [ "genfs", "hashbrown 0.7.2", "kernel", - "lazy_static", "libwasm", "linked_list_allocator", "lliw", @@ -53,7 +52,7 @@ dependencies = [ "rkyv", "serde", "shadeable", - "spin 0.5.2", + "spin", "toml", "uart_16550", "unicode-width", @@ -274,7 +273,7 @@ dependencies = [ "bitflags", "genfs", "rlibc", - "spin 0.9.2", + "spin", ] [[package]] @@ -384,7 +383,6 @@ dependencies = [ name = "kernel" version = "0.1.2" dependencies = [ - "lazy_static", "log", "versioning", ] @@ -394,9 +392,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] [[package]] name = "libc" @@ -842,12 +837,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.2" diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 9e7c935d6..6f5926d8d 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -34,6 +34,7 @@ run-args = [ "unix:../qmp-sock,server,nowait" ] + test-args = [ "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", @@ -41,12 +42,10 @@ test-args = [ "stdio", ] - - [dependencies] linked_list_allocator = "0.9.0" lliw = "0.2.0" -spin = "0.5.2" +spin = "0.9" log = "*" pretty-hex = "0.2.1" unicode-width = "0.1.7" @@ -56,39 +55,32 @@ genfs = "0.1.0" rhai = "1.6.0" libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"} acpi = "4.1.0" - axel = { git = "https://git.ablecorp.us/able/aos_userland" } - - - [dependencies.logos] -version = "0.12.0" +version = "0.12" default-features = false features = ["export_derive"] [dependencies.rdrand] -version = "0.8.1" +version = "0.8" default-features = false [dependencies.kernel] path = "../kernel" [dependencies.serde] -version = "1.0.136" +version = "1.0" default-features = false features = ["derive", "alloc"] [dependencies.hashbrown] -version = "0.7.2" +version = "0.7" default-features = false features = ["inline-more"] - - - [dependencies.rkyv] -version = "0.7.29" +version = "0.7" default-features = false features = ["size_64", "alloc"] @@ -103,15 +95,11 @@ git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git" [dependencies.ext2] git = "https://git.ablecorp.us:443/able/ext2-rs.git" - - - [dependencies.toml] git = "https://github.com/diondokter/toml-rs" # version = "0.5.8" default-features = false - [dependencies.shadeable] path = "../shadeable" @@ -128,10 +116,6 @@ default-features = false features = ["core"] version = "*" -[dependencies.lazy_static] -features = ["spin_no_std"] -version = "1.0" - [dependencies.externc-libm] git = "https://git.ablecorp.us:443/able/externc-libm.git" diff --git a/ableos/src/alias_table/mod.rs b/ableos/src/alias_table/mod.rs index 3457b66b7..24be09100 100644 --- a/ableos/src/alias_table/mod.rs +++ b/ableos/src/alias_table/mod.rs @@ -1,8 +1,7 @@ use hashbrown::HashMap; -lazy_static::lazy_static! { - pub static ref ALIAS_TABLE: spin::Mutex = spin::Mutex::new(AliasTable::new()); -} +pub static ALIAS_TABLE: spin::Mutex = spin::Mutex::new(AliasTable::new()); + /// A table of aliases /// /// This is used to allow users to specify aliases for files and commands diff --git a/ableos/src/arch/x86_64/drivers/serial.rs b/ableos/src/arch/x86_64/drivers/serial.rs index e34f4f4b0..dc47c9cf9 100644 --- a/ableos/src/arch/x86_64/drivers/serial.rs +++ b/ableos/src/arch/x86_64/drivers/serial.rs @@ -1,13 +1,12 @@ -use lazy_static::lazy_static; -use spin::Mutex; +use spin::{Lazy, Mutex}; use uart_16550::SerialPort; -lazy_static! { - pub static ref SERIAL1: Mutex = { - let mut serial_port = unsafe { SerialPort::new(0x3F8) }; - serial_port.init(); - Mutex::new(serial_port) - }; -} + +pub static SERIAL1: Lazy> = Lazy::new(|| { + let mut serial_port = unsafe { SerialPort::new(0x3F8) }; + serial_port.init(); + Mutex::new(serial_port) +}); + #[doc(hidden)] pub fn _print(args: ::core::fmt::Arguments) { use core::fmt::Write; diff --git a/ableos/src/arch/x86_64/drivers/vga.rs b/ableos/src/arch/x86_64/drivers/vga.rs index 669b8bada..a157353b1 100644 --- a/ableos/src/arch/x86_64/drivers/vga.rs +++ b/ableos/src/arch/x86_64/drivers/vga.rs @@ -23,7 +23,7 @@ pub enum Color { #[repr(transparent)] struct ColorCode(u8); impl ColorCode { - fn new(foreground: Color, background: Color) -> ColorCode { + const fn new(foreground: Color, background: Color) -> ColorCode { ColorCode((background as u8) << 4 | (foreground as u8)) } } @@ -114,17 +114,17 @@ impl fmt::Write for Writer { Ok(()) } } -lazy_static! { - pub static ref WRITER: Mutex = Mutex::new(Writer { + +pub static WRITER: Lazy> = Lazy::new(|| { + Mutex::new(Writer { column_position: 0, color_code: ColorCode::new(Color::White, Color::Black), buffer: unsafe { &mut *(0xb8000 as *mut Buffer) }, - }); -} + }) +}); use core::fmt; -use lazy_static::lazy_static; -use spin::Mutex; +use spin::{Lazy, Mutex}; use volatile::Volatile; diff --git a/ableos/src/arch/x86_64/gdt.rs b/ableos/src/arch/x86_64/gdt.rs index 3a0ff77ca..96b7c42f9 100644 --- a/ableos/src/arch/x86_64/gdt.rs +++ b/ableos/src/arch/x86_64/gdt.rs @@ -1,39 +1,39 @@ -use lazy_static::lazy_static; +use spin::Lazy; use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector}; use x86_64::structures::tss::TaskStateSegment; use x86_64::VirtAddr; pub const DOUBLE_FAULT_IST_INDEX: u16 = 0; -lazy_static! { - static ref TSS: TaskStateSegment = { - let mut tss = TaskStateSegment::new(); - tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = { - const STACK_SIZE: usize = 4096 * 5; - static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE]; - let stack_start = VirtAddr::from_ptr(unsafe { &STACK }); - stack_start + STACK_SIZE - }; - tss +static TSS: Lazy = Lazy::new(|| { + let mut tss = TaskStateSegment::new(); + tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = { + const STACK_SIZE: usize = 4096 * 5; + static mut STACK: [u8; STACK_SIZE] = [0; STACK_SIZE]; + + let stack_start = VirtAddr::from_ptr(unsafe { &STACK }); + stack_start + STACK_SIZE }; -} + tss +}); + +static GDT: Lazy<(GlobalDescriptorTable, Selectors)> = Lazy::new(|| { + let mut gdt = GlobalDescriptorTable::new(); + let code_selector = gdt.add_entry(Descriptor::kernel_code_segment()); + let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS)); + ( + gdt, + Selectors { + code_selector, + tss_selector, + }, + ) +}); + struct Selectors { code_selector: SegmentSelector, tss_selector: SegmentSelector, } -lazy_static! { - static ref GDT: (GlobalDescriptorTable, Selectors) = { - let mut gdt = GlobalDescriptorTable::new(); - let code_selector = gdt.add_entry(Descriptor::kernel_code_segment()); - let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS)); - ( - gdt, - Selectors { - code_selector, - tss_selector, - }, - ) - }; -} + pub fn init() { use x86_64::instructions::segmentation::{Segment, CS}; use x86_64::instructions::tables::load_tss; diff --git a/ableos/src/arch/x86_64/interrupts.rs b/ableos/src/arch/x86_64/interrupts.rs index b7f647ec3..28c482267 100644 --- a/ableos/src/arch/x86_64/interrupts.rs +++ b/ableos/src/arch/x86_64/interrupts.rs @@ -6,9 +6,8 @@ use crate::{ }; use cpuio::outb; -use lazy_static::lazy_static; use pic8259::ChainedPics; -use spin; +use spin::Lazy; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; pub const PIC_1_OFFSET: u8 = 32; pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; @@ -35,27 +34,26 @@ impl InterruptIndex { pub fn init_idt() { IDT.load(); } -lazy_static! { - static ref IDT: InterruptDescriptorTable = { - let mut idt = InterruptDescriptorTable::new(); - idt.breakpoint.set_handler_fn(breakpoint_handler); - unsafe { - idt.double_fault.set_handler_fn(double_fault_handler) - .set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); - } - // This gives fast interrupts - set_pit_frequency(1000); +static IDT: Lazy = Lazy::new(|| { + let mut idt = InterruptDescriptorTable::new(); + idt.breakpoint.set_handler_fn(breakpoint_handler); + unsafe { + idt.double_fault + .set_handler_fn(double_fault_handler) + .set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); + } - idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler); - idt[InterruptIndex::Keyboard.as_usize()] .set_handler_fn(keyboard_interrupt_handler); + // This gives fast interrupts + set_pit_frequency(1000); - idt[6].set_handler_fn(floppy_disk_interrupt_handler); + idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler); + idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler); + idt[6].set_handler_fn(floppy_disk_interrupt_handler); - idt - }; -} + idt +}); extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) { println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame); @@ -84,14 +82,15 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac }; use spin::Mutex; use x86_64::instructions::port::Port; - lazy_static! { - static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new( - CustomLayout::new_us104key(), - CustomScancodeSet::default(), - HandleControl::Ignore - )); - } + + static KEYBOARD: Lazy>> = Lazy::new(|| { + Mutex::new(Keyboard::new( + CustomLayout::new_us104key(), + CustomScancodeSet::default(), + HandleControl::Ignore, + )) + }); + let mut keyboard = KEYBOARD.lock(); let mut port = Port::new(0x60); let scancode: u8 = unsafe { port.read() }; diff --git a/ableos/src/arch/x86_64/mod.rs b/ableos/src/arch/x86_64/mod.rs index 56392d4f9..94dfd80f8 100644 --- a/ableos/src/arch/x86_64/mod.rs +++ b/ableos/src/arch/x86_64/mod.rs @@ -54,6 +54,5 @@ pub fn generate_process_pass() -> u128 { use rdrand::RdRand; let gen = RdRand::new().unwrap(); - let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128); - ret + (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128) } diff --git a/ableos/src/devices/dev_vterm.rs b/ableos/src/devices/dev_vterm.rs index 39909a1c7..123738f47 100644 --- a/ableos/src/devices/dev_vterm.rs +++ b/ableos/src/devices/dev_vterm.rs @@ -177,30 +177,30 @@ impl CharacterDevice for VTerm { '\n' => { self.cursor_position.1 += 1; self.cursor_position.0 = 0; - return true; + true } '\r' => { self.cursor_position.0 = 0; - return true; + true } '\t' => { self.cursor_position.0 += 4; - return true; + true } '\x08' => { self.cursor_position.0 -= 1; self.characters[self.cursor_position.1 as usize][self.cursor_position.0 as usize] .character = ' '; - return true; + true } - /// This is a form feed, which is used to clear the screen + // This is a form feed, which is used to clear the screen '\x0c' => { self.characters = [[VtermCharacter { character: ' ', char_color: (0xff_ff_ff_ff, 0x00_00_00_00), style: Style::default(), }; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize]; - return true; + true } _ => { @@ -213,11 +213,11 @@ impl CharacterDevice for VTerm { if self.cursor_position.0 < VTERM_WIDTH { self.cursor_position.0 += 1; - return true; + true } else { self.cursor_position.0 = 0; self.cursor_position.1 += 1; - return true; + true } } } @@ -239,8 +239,6 @@ impl CharacterDevice for VTerm { } } -lazy_static::lazy_static! { - pub static ref VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0); -} +pub static VIRTUAL_TERMINAL_COUNT: AtomicU32 = AtomicU32::new(0); use core::sync::atomic::AtomicU32; use core::sync::atomic::Ordering; diff --git a/ableos/src/devices/mod.rs b/ableos/src/devices/mod.rs index 10d61a484..01aca5961 100644 --- a/ableos/src/devices/mod.rs +++ b/ableos/src/devices/mod.rs @@ -3,6 +3,7 @@ pub mod id; pub mod pci_inner; use hashbrown::HashMap; +use spin::Lazy; mod dev_vterm; use crate::devices::dev_vterm::VTerm; use kernel::device_interface::character::CharacterDevice; @@ -10,7 +11,7 @@ use kernel::device_interface::character::CharacterDevice; // #[derive(Debug)] pub enum Device { Character(Box), - Vterm(VTerm), + Vterm(Box), } unsafe impl Sync for Device {} unsafe impl Send for Device {} @@ -32,12 +33,10 @@ impl DeviceTable { next_read_char: 0x00 as char, })), ); - table.insert("kvterm".to_string(), Vterm(VTerm::new())); + table.insert("kvterm".to_string(), Vterm(Box::new(VTerm::new()))); DeviceTable { devices: table } } } -lazy_static::lazy_static!( - pub static ref DEVICE_TABLE: spin::Mutex = - spin::Mutex::new(DeviceTable::new()); -); +pub static DEVICE_TABLE: Lazy> = + Lazy::new(|| spin::Mutex::new(DeviceTable::new())); diff --git a/ableos/src/driver_traits/serial.rs b/ableos/src/driver_traits/serial.rs index 075d68675..56f87ac88 100644 --- a/ableos/src/driver_traits/serial.rs +++ b/ableos/src/driver_traits/serial.rs @@ -16,7 +16,7 @@ impl CharacterDevice for Serial { todo!() } - fn write_char(&mut self, c: char) -> bool { + fn write_char(&mut self, _c: char) -> bool { todo!() } diff --git a/ableos/src/experiments/absi.rs b/ableos/src/experiments/absi.rs index 5c60c87a9..36cbfa1df 100644 --- a/ableos/src/experiments/absi.rs +++ b/ableos/src/experiments/absi.rs @@ -1,7 +1,7 @@ // TODO improve tokenizer/parser pub fn colorify(eval: &str) { - let y = eval.split("$"); + let y = eval.split('$'); for z in y { match z { "BLACK" => { @@ -55,7 +55,7 @@ pub fn colorify(eval: &str) { "RESET" => { // set_vga_color(Color::White, Color::Black); } - elk => { + _elk => { // kprint!("{}", elk); } } @@ -91,7 +91,7 @@ pub fn colorify_2(eval: &str) { Reset => { // set_vga_color(Color::White, Color::Black); } - Text(text) => { + Text(_text) => { // kprint!("{}", text); } err => { diff --git a/ableos/src/experiments/clip.rs b/ableos/src/experiments/clip.rs index f5f728466..6a72587b3 100644 --- a/ableos/src/experiments/clip.rs +++ b/ableos/src/experiments/clip.rs @@ -1,19 +1,14 @@ use alloc::{string::String, vec, vec::Vec}; // use crate::String; // use crate::Vec; -use lazy_static::lazy_static; + #[derive(Debug)] pub enum Mime { None, Text(String), } -lazy_static! { - pub static ref CLIPBOARD: spin::Mutex = { - let clipboard = Clipboard::new(); - spin::Mutex::new(clipboard) - }; -} +pub static CLIPBOARD: spin::Mutex = spin::Mutex::new(Clipboard::new()); // ctrl+v paste but not pop and pastes // ctrl+shift+v pops from the stack and pastes @@ -26,29 +21,34 @@ pub struct Clipboard { pub pages: Vec, } impl Clipboard { - pub fn new() -> Clipboard { + pub const fn new() -> Clipboard { Clipboard { index: 0, pages: vec![], } } + pub fn clear(&mut self) { self.pages = vec![]; } + pub fn set_index(&mut self, index_new: usize) { self.index = index_new; } + pub fn clip_end(&mut self) { self.index = 0; } + pub fn clip_home(&mut self) { self.index = self.pages.len(); } + pub fn copy(&mut self, copy_mime: Mime) { self.pages.push(copy_mime); } + pub fn paste(&mut self) -> &Mime { - let paste_pos = &self.pages[self.index]; - paste_pos + &self.pages[self.index] as _ } } diff --git a/ableos/src/experiments/info.rs b/ableos/src/experiments/info.rs index 3455af3d8..35b990869 100644 --- a/ableos/src/experiments/info.rs +++ b/ableos/src/experiments/info.rs @@ -445,7 +445,7 @@ impl Clone for BrandString { for (d, s) in bytes.iter_mut().zip(self.bytes.iter()) { *d = *s; } - BrandString { bytes: bytes } + BrandString { bytes } } } @@ -752,12 +752,12 @@ impl Master { let tpm = when_supported( max_value, RequestType::ThermalPowerManagementInformation, - || ThermalPowerManagementInformation::new(), + ThermalPowerManagementInformation::new, ); let sei = when_supported( max_value, RequestType::StructuredExtendedInformation, - || StructuredExtendedInformation::new(), + StructuredExtendedInformation::new, ); // Extended information @@ -767,9 +767,8 @@ impl Master { let eps = when_supported(max_value, RequestType::ExtendedProcessorSignature, || { ExtendedProcessorSignature::new() }); - let brand_string = - when_supported(max_value, RequestType::BrandString3, || BrandString::new()); - let cache_line = when_supported(max_value, RequestType::CacheLine, || CacheLine::new()); + let brand_string = when_supported(max_value, RequestType::BrandString3, BrandString::new); + let cache_line = when_supported(max_value, RequestType::CacheLine, CacheLine::new); let tsc = when_supported(max_value, RequestType::TimeStampCounter, || { TimeStampCounter::new() }); @@ -782,8 +781,8 @@ impl Master { thermal_power_management_information: tpm, structured_extended_information: sei, extended_processor_signature: eps, - brand_string: brand_string, - cache_line: cache_line, + brand_string, + cache_line, time_stamp_counter: tsc, physical_address_size: pas, } @@ -807,7 +806,7 @@ impl Master { self.brand_string .as_ref() .map(|bs| bs as &str) - .or(self.version_information.and_then(|vi| vi.brand_string())) + .or_else(|| self.version_information.and_then(|vi| vi.brand_string())) } delegate_flag!(version_information, { diff --git a/ableos/src/experiments/kinfo.rs b/ableos/src/experiments/kinfo.rs index c048f78fb..039201db9 100644 --- a/ableos/src/experiments/kinfo.rs +++ b/ableos/src/experiments/kinfo.rs @@ -11,16 +11,14 @@ impl core::fmt::Display for SemanticVersion { } } // NOTE: Move to somewhere else -lazy_static! { - pub static ref KINFO: KernelInfo = KernelInfo { - kernel_version: SemanticVersion { - major: 0, - minor: 0, - patch: 0, - }, - memory: SystemMemory { used: 0, total: 0 } - }; -} +pub static KINFO: KernelInfo = KernelInfo { + kernel_version: SemanticVersion { + major: 0, + minor: 0, + patch: 0, + }, + memory: SystemMemory { used: 0, total: 0 }, +}; /// simple info you would want to know in a neofetch like program pub struct KernelInfo { // os: String, @@ -31,4 +29,3 @@ pub struct KernelInfo { pub memory: SystemMemory, } use super::systeminfo::SystemMemory; -use lazy_static::lazy_static; diff --git a/ableos/src/filesystem/mod.rs b/ableos/src/filesystem/mod.rs index 00afa56a2..f564f185a 100644 --- a/ableos/src/filesystem/mod.rs +++ b/ableos/src/filesystem/mod.rs @@ -6,24 +6,23 @@ use ext2::{ sector::{SectorSize, Size1024}, volume::Volume, }; +use spin::Lazy; fn load_fs() -> Synced>> { let mut volume = Vec::new(); volume.extend_from_slice(include_bytes!("../../../userland/root_fs/ext2.img")); - let fs = Synced::>::new(volume).unwrap(); - - fs + Synced::>::new(volume).unwrap() } // use serde::__private::from_utf8_lossy; -pub fn walk<'vol, S: SectorSize, V: Volume>( - fs: &'vol Synced>, +pub fn walk>( + fs: &Synced>, inode: Inode, name: String, ) { - inode.directory().map(|dir| { + if let Some(dir) = inode.directory() { for entry in dir { assert!(entry.is_ok()); let entry = entry.unwrap(); @@ -38,8 +37,8 @@ pub fn walk<'vol, S: SectorSize, V: Volume>( ); } } - }); + } } -lazy_static::lazy_static!( - pub static ref FILE_SYSTEM:spin::Mutex>>>= spin::Mutex::new(load_fs()); -); + +pub static FILE_SYSTEM: Lazy>>>> = + Lazy::new(|| spin::Mutex::new(load_fs())); diff --git a/ableos/src/graphics/mod.rs b/ableos/src/graphics/mod.rs index e4f7b52f3..2275124ff 100644 --- a/ableos/src/graphics/mod.rs +++ b/ableos/src/graphics/mod.rs @@ -2,7 +2,7 @@ use ab_glyph::{Font, FontRef, Glyph}; use shadeable::{evaluate_shader, pixel_format::Rgba64}; -use spin; +use spin::Lazy; // use vga::{colors::Color16, writers::GraphicsWriter}; #[derive(Debug)] @@ -15,10 +15,8 @@ const FONT_SCALE: f32 = 1.6; const GLYPH_HEIGHT: f32 = 18.0; const GLYPH_WIDTH: f32 = 10.0; -lazy_static::lazy_static! { - pub static ref SCREEN_BUFFER: spin::Mutex = spin::Mutex::new(ScreenBuffer::new(640, 480)); - -} +pub static SCREEN_BUFFER: Lazy> = + Lazy::new(|| spin::Mutex::new(ScreenBuffer::new(640, 480))); impl ScreenSize { pub fn new(x: usize, y: usize) -> Self { @@ -46,6 +44,7 @@ impl ScreenBuffer { buff: vec![0u64; x * y].into_boxed_slice(), } } + pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: usize, color: Rgba64) { let r = radius as i32 * 2; for y in 0..640 { diff --git a/ableos/src/kernel_state.rs b/ableos/src/kernel_state.rs index 78f8d1483..be421b29d 100644 --- a/ableos/src/kernel_state.rs +++ b/ableos/src/kernel_state.rs @@ -1,9 +1,7 @@ -use lazy_static::lazy_static; +use spin::Lazy; -lazy_static! { - pub static ref KERNEL_STATE: spin::Mutex = - spin::Mutex::new(KernelInternalState::new()); -} +pub static KERNEL_STATE: Lazy> = + Lazy::new(|| spin::Mutex::new(KernelInternalState::new())); pub struct KernelInternalState { pub hostname: String, diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 785db52d9..567c039cb 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -5,19 +5,15 @@ // use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER}; -use { - crate::{ - arch::{init, sloop}, - relib::network::socket::{SimpleSock, Socket}, - scratchpad, - }, - lazy_static::lazy_static, +use crate::{ + arch::{init, sloop}, + relib::network::socket::{SimpleSock, Socket}, + scratchpad, }; +use spin::Lazy; -lazy_static! { - // TODO: Change this structure to allow for multiple cores loaded - pub static ref KERNEL_CONF: KernelConfig = KernelConfig::new(); -} +// TODO: Change this structure to allow for multiple cores loaded +pub static KERNEL_CONF: Lazy = Lazy::new(KernelConfig::new); /// The main entry point of the kernel #[no_mangle] @@ -29,7 +25,7 @@ pub fn kernel_main() -> ! { } else { log::set_max_level(log::LevelFilter::Off); } - let mut scheduler = SCHEDULER.lock(); + let scheduler = SCHEDULER.lock(); for proc in &scheduler.execution_queue { trace!("{:?}", proc); } @@ -63,6 +59,4 @@ use crate::info::master; use kernel::KERNEL_VERSION; use crate::scheduler::SCHEDULER; -use crate::{ - boot_conf::KernelConfig, scheduler::capabilities::FileAccess, systeminfo::RELEASE_TYPE, -}; +use crate::{boot_conf::KernelConfig, systeminfo::RELEASE_TYPE}; diff --git a/ableos/src/logger.rs b/ableos/src/logger.rs index d2b855e7f..da830e241 100644 --- a/ableos/src/logger.rs +++ b/ableos/src/logger.rs @@ -1,10 +1,7 @@ -use crate::boot_conf; use crate::kmain::KERNEL_CONF; use crate::network::socket::{SimpleSock, Socket}; use crate::time::fetch_time; -use core::sync::atomic::Ordering; -use kernel::TICK; use lliw::{Fg, Reset}; use log::{Level, Metadata, Record}; @@ -18,17 +15,16 @@ impl log::Log for SimpleLogger { } fn log(&self, record: &Record) { if self.enabled(record.metadata()) { - let color; - let time_float = fetch_time(); - match record.level() { - log::Level::Error => color = (Fg::Red, "$RED$"), - log::Level::Warn => color = (Fg::LightYellow, "$LIGHTYELLOW$"), - log::Level::Info => color = (Fg::LightWhite, "$LIGHTGRAY$"), - log::Level::Debug => color = (Fg::Blue, "$BLUE$"), - log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"), - } + let color = match record.level() { + log::Level::Error => (Fg::Red, "$RED$"), + log::Level::Warn => (Fg::LightYellow, "$LIGHTYELLOW$"), + log::Level::Info => (Fg::LightWhite, "$LIGHTGRAY$"), + log::Level::Debug => (Fg::Blue, "$BLUE$"), + log::Level::Trace => (Fg::Yellow, "$YELLOW$"), + }; + let msg = format!( "[{}{}$RESET$][$GREEN${}$RESET$]{}\n", color.1, diff --git a/ableos/src/relib/clparse/mod.rs b/ableos/src/relib/clparse/mod.rs index 818d27b83..ef4b37058 100644 --- a/ableos/src/relib/clparse/mod.rs +++ b/ableos/src/relib/clparse/mod.rs @@ -19,25 +19,22 @@ pub struct Command { impl Command { pub fn parse(command: String) -> Command { - let split_command = command.split("?"); + let split_command = command.split('?'); let mut root = "".to_string(); - let mut root_count = 0; let mut args: Vec = vec![]; - for subcommand in split_command { + for (root_count, subcommand) in split_command.enumerate() { match root_count { 0 => root = subcommand.to_string(), 1 => { - for subarg in subcommand.split("&") { + for subarg in subcommand.split('&') { let mut arg1 = ""; let mut arg2 = ""; - let mut arg_count = 0; - for arg in subarg.split("=") { - if arg_count == 0 { + for (n, arg) in subarg.split('=').enumerate() { + if n == 0 { arg1 = arg; } else { arg2 = arg; } - arg_count += 1; } let arg_struct = Argument { key: arg1.to_string(), @@ -48,7 +45,6 @@ impl Command { } _ => {} } - root_count += 1; } Command { diff --git a/ableos/src/relib/encoding/rle.rs b/ableos/src/relib/encoding/rle.rs index fcd4e8ce3..abcd2163e 100644 --- a/ableos/src/relib/encoding/rle.rs +++ b/ableos/src/relib/encoding/rle.rs @@ -1,11 +1,9 @@ pub fn encode(bytes: &[u8]) -> Vec { - let mut encoding; - - if bytes.first().is_none() { + let mut encoding = if bytes.first().is_none() { return vec![]; } else { - encoding = vec![*bytes.first().unwrap()]; - } + vec![*bytes.first().unwrap()] + }; let mut occurrences = 1; diff --git a/ableos/src/relib/network/socket.rs b/ableos/src/relib/network/socket.rs index 9e35600ea..0a546f04d 100644 --- a/ableos/src/relib/network/socket.rs +++ b/ableos/src/relib/network/socket.rs @@ -7,12 +7,7 @@ pub struct SocketID { impl SocketID { pub fn protocol(self) -> Option { - let x = SOCKETS.lock()[self.id].protocol.clone(); - - match x { - Some(protocol_name) => Some(protocol_name), - None => None, - } + SOCKETS.lock()[self.id].protocol.clone() } } @@ -38,10 +33,8 @@ impl Socket for SocketID { } pub type SocketState = Vec; +pub static SOCKETS: spin::Mutex = spin::Mutex::new(vec![]); -lazy_static::lazy_static! { - pub static ref SOCKETS: spin::Mutex = spin::Mutex::new(vec![]); -} pub trait Socket { fn peek(&mut self) -> SocketReturns; @@ -116,7 +109,7 @@ impl Socket for SimpleSock { let mut return_vec = vec![]; for x in &self.stream { - return_vec.push(x.clone()); + return_vec.push(*x); } SocketReturns::ReadOk(return_vec) } diff --git a/ableos/src/rhai_shell/mod.rs b/ableos/src/rhai_shell/mod.rs index b0352c718..74e157bf6 100644 --- a/ableos/src/rhai_shell/mod.rs +++ b/ableos/src/rhai_shell/mod.rs @@ -1,9 +1,11 @@ +use spin::Lazy; + #[cfg(target_arch = "riscv64")] pub fn shell() {} #[cfg(target_arch = "x86_64")] pub fn shell() { - let mut current_dir = "/".to_string(); + let _current_dir = "/".to_string(); let engine = engine_construction(); let mut scope = rhai::Scope::new(); @@ -38,10 +40,9 @@ pub fn shell() { } } } -lazy_static::lazy_static!( - pub static ref KEYBUFF: spin::Mutex> = spin::Mutex::new(Vec::new()); - pub static ref CURRENT_DIR: spin::Mutex = spin::Mutex::new("/".to_string()); -); + +pub static KEYBUFF: spin::Mutex> = spin::Mutex::new(Vec::new()); +pub static CURRENT_DIR: Lazy> = Lazy::new(|| spin::Mutex::new("/".to_string())); use rhai::Engine; use x86_64::instructions::interrupts::{disable, enable}; @@ -49,7 +50,7 @@ use x86_64::instructions::interrupts::{disable, enable}; use crate::info::master; use crate::time::fetch_time; use crate::wasm_jumploader::interp; -use crate::{allocator, ALLOCATOR}; +use crate::ALLOCATOR; use crate::{ arch::{shutdown, sloop}, systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, @@ -114,18 +115,18 @@ fn engine_construction() -> Engine { /// Examine a memory pointer pub fn peek_memory(ptr: i64) -> u8 { - let ptr: usize = ptr.abs() as usize; + let ptr: usize = ptr.unsigned_abs() as _; println!(">:("); unsafe { *(ptr as *const u8) } } pub fn poke_memory(ptr: i64, val: u8) { - let ptr: usize = ptr.abs() as usize; + let ptr: usize = ptr.unsigned_abs() as _; unsafe { *(ptr as *mut u8) = val } } pub fn ls() { - let mut current_dir = CURRENT_DIR.lock(); + let current_dir = CURRENT_DIR.lock(); let fs = &*FILE_SYSTEM.lock(); @@ -166,7 +167,7 @@ pub fn log_dump() { } use crate::filesystem::FILE_SYSTEM; -use genfs::{DirEntry, Fs, OpenOptions}; +use genfs::{Fs, OpenOptions}; pub fn echo_file(path: String) { let mut current_dir = CURRENT_DIR.lock(); @@ -181,12 +182,10 @@ pub fn echo_file(path: String) { if file.is_dir() { println!("{} is a directory", path); - - return; } else { let mut file_contents = Vec::new(); - let ret = file.read_to_end(&mut file_contents).unwrap(); + let _ret = file.read_to_end(&mut file_contents).unwrap(); let file_contents_str = String::from_utf8_lossy(&file_contents); @@ -197,13 +196,13 @@ pub fn echo_file(path: String) { pub fn change_directory(path: String) { let mut current_dir = CURRENT_DIR.lock(); - let fs = &*FILE_SYSTEM.lock(); + let _fs = &*FILE_SYSTEM.lock(); if path == "." || path == ".." { - let mut split_dir = current_dir.split("/").collect::>(); + let mut split_dir = current_dir.split('/').collect::>(); let mut new_dir = String::new(); split_dir.remove(split_dir.len() - 1); println!("{:?}", split_dir); - if split_dir.len() == 0 { + if split_dir.is_empty() { new_dir = "/".to_string(); } else { for x in split_dir { @@ -214,7 +213,7 @@ pub fn change_directory(path: String) { *current_dir = new_dir; } else { if !current_dir.ends_with('/') { - current_dir.push_str("/"); + current_dir.push('/'); } current_dir.push_str(&path); } diff --git a/ableos/src/scheduler/mod.rs b/ableos/src/scheduler/mod.rs index db65e03d1..97d6bc4dc 100644 --- a/ableos/src/scheduler/mod.rs +++ b/ableos/src/scheduler/mod.rs @@ -38,7 +38,7 @@ pub struct Scheduler { } impl Scheduler { /// Create a new scheduler - pub fn new() -> Self { + pub const fn new() -> Self { Self { free_pid: 0, process_exec_time: 0, @@ -69,15 +69,14 @@ impl Scheduler { working_dir: String, stdio: StdIO, ) -> Process { - let mut process = Process { + Process { pid: 0, priority, working_dir, stdio, password: generate_process_pass(), capabilities, - }; - process + } } pub fn sleep_process(&mut self, process: &mut Process) { @@ -86,11 +85,9 @@ impl Scheduler { wake_condition: WakeCondition::TimerInterrupt(0), }; - self.sleeping_queue.push(sleeping_process.clone()); + self.sleeping_queue.push(sleeping_process); self.execution_queue.remove(0); } } -lazy_static::lazy_static! { - pub static ref SCHEDULER: spin::Mutex = spin::Mutex::new(Scheduler::new()); -} +pub static SCHEDULER: spin::Mutex = spin::Mutex::new(Scheduler::new()); diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index 50c2701c0..835db955f 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -1,13 +1,7 @@ use acpi::AcpiTables; -use kernel::device_interface::character::CharacterDevice; -use crate::devices::DEVICE_TABLE; use crate::rhai_shell::shell; -use crate::stdio::StdIO; - -use crate::devices::Device::Vterm; - /// Experimental scratchpad for testing. pub fn scratchpad() { let axel_raw = "kernel{ @@ -25,8 +19,6 @@ pub fn scratchpad() { shell(); } -use core::fmt::Write; - pub fn pci_fun() {} pub fn acpi() { diff --git a/ableos/src/stdio.rs b/ableos/src/stdio.rs index c49776ecb..de819781c 100644 --- a/ableos/src/stdio.rs +++ b/ableos/src/stdio.rs @@ -1,8 +1,5 @@ use { - crate::{ - devices::Device::{Character, Vterm}, - kprintln, - }, + crate::devices::Device::{Character, Vterm}, core::fmt::{Arguments, Error, Write}, kernel::device_interface::character::CharacterDevice, }; diff --git a/ableos/src/vga_e.rs b/ableos/src/vga_e.rs index 440be286d..cf2b584ae 100644 --- a/ableos/src/vga_e.rs +++ b/ableos/src/vga_e.rs @@ -3,15 +3,13 @@ use vga::{ writers::{Graphics640x480x16, GraphicsWriter}, }; -lazy_static::lazy_static! { - pub static ref VGAE: spin::Mutex = { - let xyz = Graphics640x480x16::new(); - xyz.set_mode(); - spin::Mutex::new(xyz) - }; - pub static ref VGAE_BUFF_OFFSET_X: spin::Mutex = spin::Mutex::new(0); - pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex = spin::Mutex::new(0); -} +pub static VGAE: spin::Mutex = { + let xyz = Graphics640x480x16::new(); + xyz.set_mode(); + spin::Mutex::new(xyz) +}; +pub static VGAE_BUFF_OFFSET_X: spin::Mutex = spin::Mutex::new(0); +pub static VGAE_BUFF_OFFSET_Y: spin::Mutex = spin::Mutex::new(0); /// Converts a number to ... i forgor 💀 pub fn num_to_vga16(num: u8) -> Color16 { diff --git a/ableos/src/wasm/mod.rs b/ableos/src/wasm/mod.rs index 9d77b9f2c..4122f4f30 100644 --- a/ableos/src/wasm/mod.rs +++ b/ableos/src/wasm/mod.rs @@ -104,6 +104,6 @@ impl WasmProgram { if self.raw_bytes[4..8] == WASM_VERSION { byte_version_valid = true; } - return (byte_magic_valid, byte_version_valid); + (byte_magic_valid, byte_version_valid) } } diff --git a/ableos/src/wasm_jumploader/host_functions.rs b/ableos/src/wasm_jumploader/host_functions.rs index 9d7d427b2..6e3db9090 100644 --- a/ableos/src/wasm_jumploader/host_functions.rs +++ b/ableos/src/wasm_jumploader/host_functions.rs @@ -1,5 +1,3 @@ -use core::arch; - use wasmi::{ Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue, Signature, Trap, ValueType, @@ -113,7 +111,7 @@ impl HostExternals { return false; } } - return true; + true } SEND_SIGNAL_INDEX => { let (params, ret_ty): (&[ValueType], Option) = @@ -129,7 +127,7 @@ impl HostExternals { return false; } } - return true; + true } GET_TIME_INDEX => { let (params, ret_ty): (&[ValueType], Option) = @@ -145,7 +143,7 @@ impl HostExternals { return false; } } - return true; + true } GET_RANDOM_INDEX => { let (params, ret_ty): (&[ValueType], Option) = @@ -161,7 +159,7 @@ impl HostExternals { return false; } } - return true; + true } GET_INPUT_INDEX => { let (params, ret_ty): (&[ValueType], Option) = @@ -177,7 +175,7 @@ impl HostExternals { return false; } } - return true; + true } PRINT_CLEVER_HACK => { @@ -193,7 +191,7 @@ impl HostExternals { return false; } } - return true; + true } _ => false, } @@ -228,4 +226,3 @@ impl ModuleImportResolver for HostExternals { Ok(FuncInstance::alloc_host(signature.clone(), index)) } } -use crate::wasm_jumploader::host_functions::ValueType::I32; diff --git a/ableos/src/wasm_jumploader/mod.rs b/ableos/src/wasm_jumploader/mod.rs index 751fffeea..aca74b449 100644 --- a/ableos/src/wasm_jumploader/mod.rs +++ b/ableos/src/wasm_jumploader/mod.rs @@ -35,25 +35,25 @@ pub fn interp() { match instance { Ok(inst) => { - let mut instance = inst.assert_no_start(); + let instance = inst.assert_no_start(); let mut is_driver = false; - let mut is_program = false; + let _is_program = false; let mut has_driver_entry = false; let mut has_driver_exit = false; let mut has_start = false; - if let Some(val) = instance.export_by_name("driver_entry") { + if let Some(_val) = instance.export_by_name("driver_entry") { has_driver_entry = true; } - if let Some(val) = instance.export_by_name("driver_exit") { + if let Some(_val) = instance.export_by_name("driver_exit") { has_driver_exit = true; } match instance.export_by_name("start") { - Some(val) => { + Some(_val) => { trace!("Program start function found"); has_start = true; } diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index d659c110e..b6b5df25e 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -3,13 +3,8 @@ edition = "2021" name = "kernel" version = "0.1.2" - [dependencies] log = "0.4.14" -[dependencies.lazy_static] -version = "1.4.0" -default-features = false - [dependencies.versioning] git = "https://git.ablecorp.us/able/aos_userland" \ No newline at end of file diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 97cb8ef00..35cc2605d 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -23,10 +23,8 @@ pub fn tick() { TICK.store(data, Relaxed) } -lazy_static::lazy_static! { - /// The number of ticks since the first CPU was started - pub static ref TICK: AtomicU64 = AtomicU64::new(0); -} +/// The number of ticks since the first CPU was started +pub static TICK: AtomicU64 = AtomicU64::new(0); /// pub const KERNEL_VERSION: Version = Version { diff --git a/repbuild/Cargo.toml b/repbuild/Cargo.toml index 8e2e10cb4..409740161 100644 --- a/repbuild/Cargo.toml +++ b/repbuild/Cargo.toml @@ -5,13 +5,9 @@ edition = "2021" authors = ["Able", "NotAble"] [dependencies] -<<<<<<< HEAD -======= -clap = { version = "3.1", features = ["cargo", "derive"] } ->>>>>>> e6dbfb4a0a4e14c8bf2ead04bb2078627f5780eb xshell = "0.1.9" anyhow = "*" [dependencies.clap] version = "3.1.8" -features = ["derive"] \ No newline at end of file +features = ["derive"] diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 20cc69971..0033dce7e 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -32,8 +32,8 @@ enum Command { #[derive(clap::ArgEnum, Debug, Clone)] enum MachineType { X86, - RISCV, - ARM, + Riscv, + Arm, } fn main() -> anyhow::Result<()> { @@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> { MachineType::X86 => { xshell::cmd!("cargo run --release").run()?; } - MachineType::ARM => { + MachineType::Arm => { xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json") .run()?; #[rustfmt::skip] @@ -65,7 +65,7 @@ fn main() -> anyhow::Result<()> { " ).run()?; } - MachineType::RISCV => { + MachineType::Riscv => { xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf") .run()?; #[rustfmt::skip] @@ -91,23 +91,23 @@ fn main() -> anyhow::Result<()> { MachineType::X86 => { xshell::cmd!("cargo doc --open").run()?; } - MachineType::ARM => { + MachineType::Arm => { xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json") .run()?; } - MachineType::RISCV => { + MachineType::Riscv => { xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?; } } } Command::Mount { path } => { - let path = path.unwrap_or("./userland/root_fs/mnt".to_string()); + let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string()); xshell::cmd!("sudo mount userland/root_fs/ext2.img {path}").run()?; } Command::Unmount { path } => { - let path = path.unwrap_or("./userland/root_fs/mnt".to_string()); + let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string()); xshell::cmd!("sudo umount {path}").run()?; } }