diff --git a/src/drivers/atapi/interrupt.rs b/src/drivers/atapi/interrupt.rs index 80ea515..8cbb063 100644 --- a/src/drivers/atapi/interrupt.rs +++ b/src/drivers/atapi/interrupt.rs @@ -3,26 +3,24 @@ use core::pin::Pin; use core::sync::atomic::{AtomicBool, Ordering}; use core::task::{Context, Poll}; -use lazy_static::lazy_static; use futures_util::task::AtomicWaker; +use lazy_static::lazy_static; lazy_static! { pub static ref INTERRUPT_FUTURE: InterruptFuture = InterruptFuture::new(); - static ref INTERRUPT: AtomicBool = AtomicBool::new(false); } static WAKER: AtomicWaker = AtomicWaker::new(); - pub(crate) fn mark_interrupt() { INTERRUPT.store(true, Ordering::Relaxed); WAKER.wake(); } -#[derive(Copy,Clone)] +#[derive(Copy, Clone)] pub struct InterruptFuture { - _private:(), + _private: (), } impl InterruptFuture { @@ -51,8 +49,8 @@ impl Future for InterruptFuture { true => { WAKER.take(); Poll::Ready(()) - }, + } false => Poll::Pending, } } -} \ No newline at end of file +} diff --git a/src/drivers/atapi/mod.rs b/src/drivers/atapi/mod.rs index 6614374..6a50729 100644 --- a/src/drivers/atapi/mod.rs +++ b/src/drivers/atapi/mod.rs @@ -1,20 +1,20 @@ -mod scsi; pub mod interrupt; +mod scsi; use crate::{println, serial_println}; -use scsi::{SCSIPacket}; -use interrupt::{INTERRUPT_FUTURE}; +use interrupt::INTERRUPT_FUTURE; +use scsi::SCSIPacket; use core::convert::TryInto; -use lazy_static::lazy_static; use crate::utils::AsyncMutex; +use lazy_static::lazy_static; use x86_64::instructions::port::Port; const CD_SECTOR_SIZE: usize = 2048; // Data buses -const ATA_BUS_PRIMARY: u16= 0x1f0; +const ATA_BUS_PRIMARY: u16 = 0x1f0; const ATA_BUS_SECONDARY: u16 = 0x170; // Drives @@ -54,16 +54,14 @@ static ATAPI_SIG: [u8; 4] = [ ATAPI_SIG_SC, ATAPI_SIG_LBA_LO, ATAPI_SIG_LBA_MI, - ATAPI_SIG_LBA_HI + ATAPI_SIG_LBA_HI, ]; lazy_static! { - pub static ref DRIVE: AsyncMutex> = { - AsyncMutex::new(ATABus::discover_atapi_drive()) - }; + pub static ref DRIVE: AsyncMutex> = + { AsyncMutex::new(ATABus::discover_atapi_drive()) }; } - pub async fn init() { println!("Detecting drives"); match DRIVE.lock().await.as_ref() { @@ -72,12 +70,12 @@ pub async fn init() { let drive_type = match drive.current_drive { ATA_DRIVE_MASTER => "master", ATA_DRIVE_SLAVE => "slave", - _ => "bad" + _ => "bad", }; let bus = match drive.base_port { ATA_BUS_PRIMARY => "primary", ATA_BUS_SECONDARY => "secondary", - _ => "bad" + _ => "bad", }; println!("Detected {} drive on {} bus", drive_type, bus); } @@ -100,7 +98,7 @@ pub struct ATABus { address3: Port, drive_select: Port, command: Port, // write - status: Port, // read + status: Port, // read dcr: Port, current_drive: u8, @@ -153,14 +151,14 @@ impl ATABus { data: Port::new(port), features: Port::new(port + 1), // write - error: Port::new(port + 1), // read + error: Port::new(port + 1), // read sector_count: Port::new(port + 2), address1: Port::new(port + 3), address2: Port::new(port + 4), address3: Port::new(port + 5), drive_select: Port::new(port + 6), command: Port::new(port + 7), // write - status: Port::new(port + 7), // read + status: Port::new(port + 7), // read dcr: Port::new(port + 0x206), current_drive: 0, @@ -204,7 +202,7 @@ impl ATABus { self.wait_packet_request(); for i in (0..raw_packet.len()).step_by(2) { - let word = u16::from_le_bytes(raw_packet[i..i+2].try_into().unwrap()); + let word = u16::from_le_bytes(raw_packet[i..i + 2].try_into().unwrap()); unsafe { self.data.write(word); } @@ -323,9 +321,8 @@ impl ATABus { } } - #[allow(dead_code)] pub async fn print_block(lba: u32) { let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await; serial_println!("{:x?}", block); -} \ No newline at end of file +} diff --git a/src/drivers/atapi/scsi.rs b/src/drivers/atapi/scsi.rs index 8a9b2c8..690eb1a 100644 --- a/src/drivers/atapi/scsi.rs +++ b/src/drivers/atapi/scsi.rs @@ -1,5 +1,5 @@ -use postcard::{to_vec}; -use serde::{Serialize, Deserialize}; +use postcard::to_vec; +use serde::{Deserialize, Serialize}; #[derive(Default, Serialize, Deserialize, Debug, Eq, PartialEq)] #[repr(C, packed)] @@ -15,7 +15,7 @@ pub struct SCSIPacket { transfer_length_milo: u8, transfer_length_lo: u8, flags_hi: u8, - control: u8 + control: u8, } impl SCSIPacket { @@ -40,4 +40,4 @@ impl SCSIPacket { self.transfer_length_mihi = ((l >> 0x10) & 0xff) as u8; self.transfer_length_hi = ((l >> 0x18) & 0xff) as u8; } -} \ No newline at end of file +} diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index 238be6f..f171f92 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -1,3 +1,3 @@ +pub mod atapi; pub mod serial; pub mod vga; -pub mod atapi; diff --git a/src/fd/mod.rs b/src/fd/mod.rs index f983188..4e91a0b 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -1,7 +1,7 @@ use crate::println; use crate::utils::AsyncMutex; -use alloc::{collections::BTreeMap, sync::Arc, boxed::Box}; +use alloc::{boxed::Box, collections::BTreeMap, sync::Arc}; use async_trait::async_trait; use core::cell::RefCell; use lazy_static::lazy_static; @@ -9,9 +9,7 @@ use lazy_static::lazy_static; pub type FDt = Arc>; lazy_static! { - pub static ref FD_TABLE: AsyncMutex = { - AsyncMutex::new(FDTable::new()) - }; + pub static ref FD_TABLE: AsyncMutex = { AsyncMutex::new(FDTable::new()) }; } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] @@ -30,13 +28,18 @@ pub struct FDTable { impl FDTable { pub fn new() -> Self { - FDTable { table: BTreeMap::new() } + FDTable { + table: BTreeMap::new(), + } } pub fn register_fd(&mut self, fd: FDt) { // TODO self.table.insert(fd.borrow().get_fd(), fd.clone()); - println!("Registered fd: {:?}", self.table.get(&FDId(1)).unwrap().borrow().get_fd()); + println!( + "Registered fd: {:?}", + self.table.get(&FDId(1)).unwrap().borrow().get_fd() + ); } } @@ -45,4 +48,4 @@ pub trait FileDescriptor { fn get_fd(&self) -> FDId; async fn write(&mut self, buf: &[u8], count: usize) -> isize; async fn read(&mut self, buf: &[u8], count: usize) -> isize; -} \ No newline at end of file +} diff --git a/src/fs/iso/fd.rs b/src/fs/iso/fd.rs index ee9954a..1134950 100644 --- a/src/fs/iso/fd.rs +++ b/src/fs/iso/fd.rs @@ -1,8 +1,8 @@ +use crate::fd::{FDId, FDt, FileDescriptor}; use crate::println; -use crate::fd::{FDId, FileDescriptor, FDt}; use crate::utils::mutex::AsyncMutex; -use alloc::{sync::Arc, boxed::Box}; +use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use core::cell::RefCell; @@ -12,9 +12,7 @@ pub struct IsoFD { impl IsoFD { pub fn new() -> FDt { - Arc::new(RefCell::new(IsoFD { - fd: FDId::new(), - })) + Arc::new(RefCell::new(IsoFD { fd: FDId::new() })) } } @@ -32,4 +30,4 @@ impl FileDescriptor for IsoFD { println!("Read from fd"); 0 } -} \ No newline at end of file +} diff --git a/src/fs/iso/iso9660.rs b/src/fs/iso/iso9660.rs index 1903983..d3b42b7 100644 --- a/src/fs/iso/iso9660.rs +++ b/src/fs/iso/iso9660.rs @@ -16,29 +16,25 @@ pub struct MultiEndian16 { be: u16, // Big endian value } - // Path table structure #[repr(C, packed)] #[derive(Copy, Clone)] struct IsoPathTable { - idf_len: u8, // Identifier name length - ext_size: u8, // Extended attribute record length - data_blk: u8, // File data block index + idf_len: u8, // Identifier name length + ext_size: u8, // Extended attribute record length + data_blk: u8, // File data block index parent_dir: u16, // Number of the parent dir - idf: [u8; 0] // Directory name, of size Self::idf_len + idf: [u8; 0], // Directory name, of size Self::idf_len } impl IsoPathTable { #[allow(unaligned_references)] pub fn get_idf(&self) -> &[u8] { - unsafe { - core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) - } + unsafe { core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) } } } - // Directory structure const ISO_DATE_LEN: usize = 7; @@ -46,20 +42,20 @@ const ISO_DATE_LEN: usize = 7; #[repr(u8)] #[derive(Copy, Clone)] enum IsoFileType { - HIDDEN = 0x1, // Hidden file - ISDIR = 0x2, // Directory - ASSOCIAT = 0x4, // Associated - USEEXT = 0x8, // - USEPERM = 0x10, // - MULTIDIR = 0x80 // + HIDDEN = 0x1, // Hidden file + ISDIR = 0x2, // Directory + ASSOCIAT = 0x4, // Associated + USEEXT = 0x8, // + USEPERM = 0x10, // + MULTIDIR = 0x80, // } #[repr(C, packed)] #[derive(Copy, Clone)] pub struct IsoDir { - dir_size: u8, // Length of directory record - ext_size: u8, // Length of extended attribute record - data_blk: MultiEndian32, // File data block index + dir_size: u8, // Length of directory record + ext_size: u8, // Length of extended attribute record + data_blk: MultiEndian32, // File data block index file_size: MultiEndian32, // File size date: [u8; ISO_DATE_LEN], file_type: IsoFileType, @@ -69,20 +65,17 @@ pub struct IsoDir { vol_seq: MultiEndian16, - idf_len: u8, // File name length + idf_len: u8, // File name length idf: [u8; 0], // File name } impl IsoDir { #[allow(unaligned_references)] pub fn get_idf(&self) -> &[u8] { - unsafe { - core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) - } + unsafe { core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) } } } - // Primary volume descriptor structure pub const ISO_PRIM_VOLDESC_BLOCK: u32 = 16; @@ -101,9 +94,9 @@ const ISO_LDATE_LEN: usize = 17; #[repr(C, packed)] #[derive(Copy, Clone)] pub struct IsoPrimVolDesc { - pub vol_desc_type: u8, // Volume descripto type (1) + pub vol_desc_type: u8, // Volume descripto type (1) pub std_identifier: [u8; 5], // standard identifier ("CD001") - pub vol_desc_version: u8, // Volume descriptor version (1) + pub vol_desc_version: u8, // Volume descriptor version (1) pub _unused1: u8, @@ -117,12 +110,12 @@ pub struct IsoPrimVolDesc { pub _unused3: [u8; 32], pub vol_set_size: MultiEndian16, // The Volume Set size of the volume - pub vol_seq_num: MultiEndian16, // The number of the volume in the set + pub vol_seq_num: MultiEndian16, // The number of the volume in the set pub vol_blk_size: MultiEndian16, // The size in bytes of a logical block pub path_table_size: MultiEndian32, // Length in bytes of the path table - pub le_path_table_blk: u32, // Path table block index little endian - pub le_opt_path_table_blk: u32, // Optionnal path table block index little endian + pub le_path_table_blk: u32, // Path table block index little endian + pub le_opt_path_table_blk: u32, // Optionnal path table block index little endian pub be_path_table_blk: u32, pub be_opt_path_table_blk: u32, @@ -131,17 +124,17 @@ pub struct IsoPrimVolDesc { pub _unused4: [u8; 34 - core::mem::size_of::()], // Padding pub volset_idf: [u8; ISO_VOLSET_LEN], // name of the multiple volume set - pub pub_idf: [u8; ISO_PUBIDF_LEN], // Publisher name - pub dprep_idf: [u8; ISO_DPREP_LEN], // Data preparer name - pub app_idf: [u8; ISO_APP_LEN], // Application name + pub pub_idf: [u8; ISO_PUBIDF_LEN], // Publisher name + pub dprep_idf: [u8; ISO_DPREP_LEN], // Data preparer name + pub app_idf: [u8; ISO_APP_LEN], // Application name pub copyright_file: [u8; ISO_CPRFIL_LEN], // Copyright file name in root dir - pub abstract_file: [u8; ISO_ABSFIL_LEN], // Abstract file name in root dir - pub bibli_file: [u8; ISO_BIBFIL_LEN], // Bibliograpgic file name in root dir - pub date_creat: [u8; ISO_LDATE_LEN], // Creation date - pub date_modif: [u8; ISO_LDATE_LEN], // Modification date - pub date_expir: [u8; ISO_LDATE_LEN], // Expiration date - pub date_effect: [u8; ISO_LDATE_LEN], // Effective date + pub abstract_file: [u8; ISO_ABSFIL_LEN], // Abstract file name in root dir + pub bibli_file: [u8; ISO_BIBFIL_LEN], // Bibliograpgic file name in root dir + pub date_creat: [u8; ISO_LDATE_LEN], // Creation date + pub date_modif: [u8; ISO_LDATE_LEN], // Modification date + pub date_expir: [u8; ISO_LDATE_LEN], // Expiration date + pub date_effect: [u8; ISO_LDATE_LEN], // Effective date pub file_struct_version: u8, // File structure version (1) -} \ No newline at end of file +} diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 52236c6..80a97ff 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -1,20 +1,19 @@ -pub mod iso9660; mod fd; +pub mod iso9660; +use crate::drivers::atapi::DRIVE; +use crate::fd::{FDt, FD_TABLE}; use crate::println; -use crate::drivers::atapi::{DRIVE}; -use crate::fd::{FD_TABLE, FDt}; use crate::utils::unserialize; use super::FileSystem; -use iso9660::{IsoPrimVolDesc, IsoDir}; use fd::IsoFD; +use iso9660::{IsoDir, IsoPrimVolDesc}; -use alloc::{sync::Arc, boxed::Box}; +use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; -pub struct IsoFS { -} +pub struct IsoFS {} #[async_trait(?Send)] impl FileSystem for IsoFS { @@ -44,4 +43,4 @@ pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { .read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK) .await; *unserialize::(desc_block.as_ptr()) -} \ No newline at end of file +} diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 6ea55db..8ab3b1f 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -3,7 +3,7 @@ pub mod iso; use crate::fd::FDt; use crate::utils::mutex::AsyncMutex; -use alloc::{sync::Arc, boxed::Box}; +use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use core::cell::RefCell; use lazy_static::lazy_static; @@ -11,9 +11,7 @@ use lazy_static::lazy_static; pub type FSt = Arc>; lazy_static! { - pub static ref VIRTUAL_FS: AsyncMutex = { - AsyncMutex::new(VirtualFS::new()) - }; + pub static ref VIRTUAL_FS: AsyncMutex = { AsyncMutex::new(VirtualFS::new()) }; } #[async_trait(?Send)] @@ -28,7 +26,7 @@ pub struct VirtualFS { impl VirtualFS { fn new() -> Self { VirtualFS { - fs: Arc::new(RefCell::new(iso::IsoFS {})) + fs: Arc::new(RefCell::new(iso::IsoFS {})), } } } @@ -38,4 +36,4 @@ impl FileSystem for VirtualFS { async fn open(&mut self, path: &str, flags: u32) -> Option { self.fs.borrow_mut().open(path, flags).await } -} \ No newline at end of file +} diff --git a/src/interrupts/mod.rs b/src/interrupts/mod.rs index 9a70f34..355c43b 100644 --- a/src/interrupts/mod.rs +++ b/src/interrupts/mod.rs @@ -4,12 +4,8 @@ use crate::memory::gdt; use crate::println; use lazy_static::lazy_static; use pic::{ - init_pic, - keyboard_interrupt_handler, - timer_interrupt_handler, - disk1_interrupt_handler, - disk2_interrupt_handler, - InterruptIndex + disk1_interrupt_handler, disk2_interrupt_handler, init_pic, keyboard_interrupt_handler, + timer_interrupt_handler, InterruptIndex, }; use x86_64::structures::idt::PageFaultErrorCode; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; diff --git a/src/interrupts/pic/mod.rs b/src/interrupts/pic/mod.rs index ca8d510..abec3f1 100644 --- a/src/interrupts/pic/mod.rs +++ b/src/interrupts/pic/mod.rs @@ -1,12 +1,12 @@ use crate::println; +pub use disk::{disk1_interrupt_handler, disk2_interrupt_handler}; pub use keyboard::keyboard_interrupt_handler; use pic8259::ChainedPics; pub use pit::timer_interrupt_handler; -pub use disk::{disk1_interrupt_handler, disk2_interrupt_handler}; +pub mod disk; pub mod keyboard; pub mod pit; -pub mod disk; pub const PIC_1_OFFSET: u8 = 32; pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; @@ -35,7 +35,7 @@ pub static PICS: spin::Mutex = pub fn init_pic() { println!("Initializing PIC"); - unsafe { + unsafe { PICS.lock().initialize(); PICS.lock().write_masks(0b10111000, 0b00001110); }; diff --git a/src/lib.rs b/src/lib.rs index 4b96f0d..70c4b6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,23 +4,23 @@ #![feature(alloc_error_handler)] mod drivers; +mod fd; +mod fs; mod interrupts; mod memory; -mod task; -mod fs; -mod utils; -mod fd; mod syscalls; +mod task; +mod utils; //#[macro_use] extern crate alloc; extern crate multiboot2; +use crate::fs::FileSystem; use core::panic::PanicInfo; use drivers::vga::{self, Color, ColorCode}; use multiboot2::BootInformation; use task::{executor::Executor, keyboard, Task}; -use crate::fs::FileSystem; #[alloc_error_handler] fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { @@ -64,8 +64,12 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! { executor.run(); } - async fn get_file() { - let fd = fs::VIRTUAL_FS.lock().await.open("test", syscalls::io::O_RDONLY).await.unwrap(); + let fd = fs::VIRTUAL_FS + .lock() + .await + .open("test", syscalls::io::O_RDONLY) + .await + .unwrap(); fd.borrow_mut().read(&[], 0).await; -} \ No newline at end of file +} diff --git a/src/syscalls/io.rs b/src/syscalls/io.rs index a43aa0c..1b45ac5 100644 --- a/src/syscalls/io.rs +++ b/src/syscalls/io.rs @@ -7,4 +7,4 @@ pub const SEEK_SET: u32 = 0; #[allow(dead_code)] pub const SEEK_CUR: u32 = 1; #[allow(dead_code)] -pub const SEEK_END: u32 = 2; \ No newline at end of file +pub const SEEK_END: u32 = 2; diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 678b90e..af514a1 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -1 +1 @@ -pub mod io; \ No newline at end of file +pub mod io; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index bfc745d..feab11c 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,5 +1,5 @@ -pub mod serialize; pub mod mutex; +pub mod serialize; +pub use mutex::AsyncMutex; pub use serialize::unserialize; -pub use mutex::AsyncMutex; \ No newline at end of file diff --git a/src/utils/mutex.rs b/src/utils/mutex.rs index 48f0c38..27760af 100644 --- a/src/utils/mutex.rs +++ b/src/utils/mutex.rs @@ -1,10 +1,10 @@ -use core::future::Future; -use core::pin::Pin; +use alloc::sync::Arc; use core::cell::UnsafeCell; +use core::future::Future; use core::ops::{Deref, DerefMut, Drop}; +use core::pin::Pin; use core::sync::atomic::{AtomicBool, Ordering}; use core::task::{Context, Poll}; -use alloc::sync::Arc; use futures_util::task::AtomicWaker; @@ -23,7 +23,7 @@ pub struct AsyncMutexGuard<'a, T> where T: 'a, { - mutex: &'a AsyncMutex + mutex: &'a AsyncMutex, } impl Lock { @@ -58,7 +58,7 @@ impl Future for Lock { false => { self.waker.take(); Poll::Ready(()) - }, + } true => Poll::Pending, } } @@ -98,16 +98,12 @@ impl Drop for AsyncMutexGuard<'_, T> { impl Deref for AsyncMutexGuard<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { - unsafe { - &*self.mutex.inner.get() - } + unsafe { &*self.mutex.inner.get() } } } impl DerefMut for AsyncMutexGuard<'_, T> { fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { - &mut *self.mutex.inner.get() - } + unsafe { &mut *self.mutex.inner.get() } } -} \ No newline at end of file +} diff --git a/src/utils/serialize.rs b/src/utils/serialize.rs index 6ddac65..d8aa98b 100644 --- a/src/utils/serialize.rs +++ b/src/utils/serialize.rs @@ -1,6 +1,4 @@ pub fn unserialize(ptr: *const u8) -> &'static T { let path_table_ptr: *const T = ptr as *const T; - unsafe { - &*path_table_ptr - } -} \ No newline at end of file + unsafe { &*path_table_ptr } +}