cargo-fmt
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2022-12-23 20:07:46 +01:00
parent b2ffbc34b5
commit 43eec9621c
17 changed files with 112 additions and 132 deletions

@ -3,18 +3,16 @@ use core::pin::Pin;
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use core::task::{Context, Poll}; use core::task::{Context, Poll};
use lazy_static::lazy_static;
use futures_util::task::AtomicWaker; use futures_util::task::AtomicWaker;
use lazy_static::lazy_static;
lazy_static! { lazy_static! {
pub static ref INTERRUPT_FUTURE: InterruptFuture = InterruptFuture::new(); pub static ref INTERRUPT_FUTURE: InterruptFuture = InterruptFuture::new();
static ref INTERRUPT: AtomicBool = AtomicBool::new(false); static ref INTERRUPT: AtomicBool = AtomicBool::new(false);
} }
static WAKER: AtomicWaker = AtomicWaker::new(); static WAKER: AtomicWaker = AtomicWaker::new();
pub(crate) fn mark_interrupt() { pub(crate) fn mark_interrupt() {
INTERRUPT.store(true, Ordering::Relaxed); INTERRUPT.store(true, Ordering::Relaxed);
WAKER.wake(); WAKER.wake();
@ -51,7 +49,7 @@ impl Future for InterruptFuture {
true => { true => {
WAKER.take(); WAKER.take();
Poll::Ready(()) Poll::Ready(())
}, }
false => Poll::Pending, false => Poll::Pending,
} }
} }

@ -1,14 +1,14 @@
mod scsi;
pub mod interrupt; pub mod interrupt;
mod scsi;
use crate::{println, serial_println}; use crate::{println, serial_println};
use scsi::{SCSIPacket}; use interrupt::INTERRUPT_FUTURE;
use interrupt::{INTERRUPT_FUTURE}; use scsi::SCSIPacket;
use core::convert::TryInto; use core::convert::TryInto;
use lazy_static::lazy_static;
use crate::utils::AsyncMutex; use crate::utils::AsyncMutex;
use lazy_static::lazy_static;
use x86_64::instructions::port::Port; use x86_64::instructions::port::Port;
const CD_SECTOR_SIZE: usize = 2048; const CD_SECTOR_SIZE: usize = 2048;
@ -54,16 +54,14 @@ static ATAPI_SIG: [u8; 4] = [
ATAPI_SIG_SC, ATAPI_SIG_SC,
ATAPI_SIG_LBA_LO, ATAPI_SIG_LBA_LO,
ATAPI_SIG_LBA_MI, ATAPI_SIG_LBA_MI,
ATAPI_SIG_LBA_HI ATAPI_SIG_LBA_HI,
]; ];
lazy_static! { lazy_static! {
pub static ref DRIVE: AsyncMutex<Option<ATABus>> = { pub static ref DRIVE: AsyncMutex<Option<ATABus>> =
AsyncMutex::new(ATABus::discover_atapi_drive()) { AsyncMutex::new(ATABus::discover_atapi_drive()) };
};
} }
pub async fn init() { pub async fn init() {
println!("Detecting drives"); println!("Detecting drives");
match DRIVE.lock().await.as_ref() { match DRIVE.lock().await.as_ref() {
@ -72,12 +70,12 @@ pub async fn init() {
let drive_type = match drive.current_drive { let drive_type = match drive.current_drive {
ATA_DRIVE_MASTER => "master", ATA_DRIVE_MASTER => "master",
ATA_DRIVE_SLAVE => "slave", ATA_DRIVE_SLAVE => "slave",
_ => "bad" _ => "bad",
}; };
let bus = match drive.base_port { let bus = match drive.base_port {
ATA_BUS_PRIMARY => "primary", ATA_BUS_PRIMARY => "primary",
ATA_BUS_SECONDARY => "secondary", ATA_BUS_SECONDARY => "secondary",
_ => "bad" _ => "bad",
}; };
println!("Detected {} drive on {} bus", drive_type, bus); println!("Detected {} drive on {} bus", drive_type, bus);
} }
@ -323,7 +321,6 @@ impl ATABus {
} }
} }
#[allow(dead_code)] #[allow(dead_code)]
pub async fn print_block(lba: u32) { pub async fn print_block(lba: u32) {
let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await; let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await;

@ -1,5 +1,5 @@
use postcard::{to_vec}; use postcard::to_vec;
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
#[derive(Default, Serialize, Deserialize, Debug, Eq, PartialEq)] #[derive(Default, Serialize, Deserialize, Debug, Eq, PartialEq)]
#[repr(C, packed)] #[repr(C, packed)]
@ -15,7 +15,7 @@ pub struct SCSIPacket {
transfer_length_milo: u8, transfer_length_milo: u8,
transfer_length_lo: u8, transfer_length_lo: u8,
flags_hi: u8, flags_hi: u8,
control: u8 control: u8,
} }
impl SCSIPacket { impl SCSIPacket {

@ -1,3 +1,3 @@
pub mod atapi;
pub mod serial; pub mod serial;
pub mod vga; pub mod vga;
pub mod atapi;

@ -1,7 +1,7 @@
use crate::println; use crate::println;
use crate::utils::AsyncMutex; 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 async_trait::async_trait;
use core::cell::RefCell; use core::cell::RefCell;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -9,9 +9,7 @@ use lazy_static::lazy_static;
pub type FDt = Arc<RefCell<dyn FileDescriptor>>; pub type FDt = Arc<RefCell<dyn FileDescriptor>>;
lazy_static! { lazy_static! {
pub static ref FD_TABLE: AsyncMutex<FDTable> = { pub static ref FD_TABLE: AsyncMutex<FDTable> = { AsyncMutex::new(FDTable::new()) };
AsyncMutex::new(FDTable::new())
};
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
@ -30,13 +28,18 @@ pub struct FDTable {
impl FDTable { impl FDTable {
pub fn new() -> Self { pub fn new() -> Self {
FDTable { table: BTreeMap::new() } FDTable {
table: BTreeMap::new(),
}
} }
pub fn register_fd(&mut self, fd: FDt) { pub fn register_fd(&mut self, fd: FDt) {
// TODO // TODO
self.table.insert(fd.borrow().get_fd(), fd.clone()); 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()
);
} }
} }

@ -1,8 +1,8 @@
use crate::fd::{FDId, FDt, FileDescriptor};
use crate::println; use crate::println;
use crate::fd::{FDId, FileDescriptor, FDt};
use crate::utils::mutex::AsyncMutex; use crate::utils::mutex::AsyncMutex;
use alloc::{sync::Arc, boxed::Box}; use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait; use async_trait::async_trait;
use core::cell::RefCell; use core::cell::RefCell;
@ -12,9 +12,7 @@ pub struct IsoFD {
impl IsoFD { impl IsoFD {
pub fn new() -> FDt { pub fn new() -> FDt {
Arc::new(RefCell::new(IsoFD { Arc::new(RefCell::new(IsoFD { fd: FDId::new() }))
fd: FDId::new(),
}))
} }
} }

@ -16,7 +16,6 @@ pub struct MultiEndian16 {
be: u16, // Big endian value be: u16, // Big endian value
} }
// Path table structure // Path table structure
#[repr(C, packed)] #[repr(C, packed)]
@ -26,18 +25,15 @@ struct IsoPathTable {
ext_size: u8, // Extended attribute record length ext_size: u8, // Extended attribute record length
data_blk: u8, // File data block index data_blk: u8, // File data block index
parent_dir: u16, // Number of the parent dir 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 { impl IsoPathTable {
#[allow(unaligned_references)] #[allow(unaligned_references)]
pub fn get_idf(&self) -> &[u8] { pub fn get_idf(&self) -> &[u8] {
unsafe { unsafe { core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) }
core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize)
} }
} }
}
// Directory structure // Directory structure
@ -51,7 +47,7 @@ enum IsoFileType {
ASSOCIAT = 0x4, // Associated ASSOCIAT = 0x4, // Associated
USEEXT = 0x8, // USEEXT = 0x8, //
USEPERM = 0x10, // USEPERM = 0x10, //
MULTIDIR = 0x80 // MULTIDIR = 0x80, //
} }
#[repr(C, packed)] #[repr(C, packed)]
@ -76,12 +72,9 @@ pub struct IsoDir {
impl IsoDir { impl IsoDir {
#[allow(unaligned_references)] #[allow(unaligned_references)]
pub fn get_idf(&self) -> &[u8] { pub fn get_idf(&self) -> &[u8] {
unsafe { unsafe { core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) }
core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize)
} }
} }
}
// Primary volume descriptor structure // Primary volume descriptor structure

@ -1,20 +1,19 @@
pub mod iso9660;
mod fd; mod fd;
pub mod iso9660;
use crate::drivers::atapi::DRIVE;
use crate::fd::{FDt, FD_TABLE};
use crate::println; use crate::println;
use crate::drivers::atapi::{DRIVE};
use crate::fd::{FD_TABLE, FDt};
use crate::utils::unserialize; use crate::utils::unserialize;
use super::FileSystem; use super::FileSystem;
use iso9660::{IsoPrimVolDesc, IsoDir};
use fd::IsoFD; use fd::IsoFD;
use iso9660::{IsoDir, IsoPrimVolDesc};
use alloc::{sync::Arc, boxed::Box}; use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait; use async_trait::async_trait;
pub struct IsoFS { pub struct IsoFS {}
}
#[async_trait(?Send)] #[async_trait(?Send)]
impl FileSystem for IsoFS { impl FileSystem for IsoFS {

@ -3,7 +3,7 @@ pub mod iso;
use crate::fd::FDt; use crate::fd::FDt;
use crate::utils::mutex::AsyncMutex; use crate::utils::mutex::AsyncMutex;
use alloc::{sync::Arc, boxed::Box}; use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait; use async_trait::async_trait;
use core::cell::RefCell; use core::cell::RefCell;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -11,9 +11,7 @@ use lazy_static::lazy_static;
pub type FSt = Arc<RefCell<dyn FileSystem>>; pub type FSt = Arc<RefCell<dyn FileSystem>>;
lazy_static! { lazy_static! {
pub static ref VIRTUAL_FS: AsyncMutex<VirtualFS> = { pub static ref VIRTUAL_FS: AsyncMutex<VirtualFS> = { AsyncMutex::new(VirtualFS::new()) };
AsyncMutex::new(VirtualFS::new())
};
} }
#[async_trait(?Send)] #[async_trait(?Send)]
@ -28,7 +26,7 @@ pub struct VirtualFS {
impl VirtualFS { impl VirtualFS {
fn new() -> Self { fn new() -> Self {
VirtualFS { VirtualFS {
fs: Arc::new(RefCell::new(iso::IsoFS {})) fs: Arc::new(RefCell::new(iso::IsoFS {})),
} }
} }
} }

@ -4,12 +4,8 @@ use crate::memory::gdt;
use crate::println; use crate::println;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use pic::{ use pic::{
init_pic, disk1_interrupt_handler, disk2_interrupt_handler, init_pic, keyboard_interrupt_handler,
keyboard_interrupt_handler, timer_interrupt_handler, InterruptIndex,
timer_interrupt_handler,
disk1_interrupt_handler,
disk2_interrupt_handler,
InterruptIndex
}; };
use x86_64::structures::idt::PageFaultErrorCode; use x86_64::structures::idt::PageFaultErrorCode;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};

@ -1,12 +1,12 @@
use crate::println; use crate::println;
pub use disk::{disk1_interrupt_handler, disk2_interrupt_handler};
pub use keyboard::keyboard_interrupt_handler; pub use keyboard::keyboard_interrupt_handler;
use pic8259::ChainedPics; use pic8259::ChainedPics;
pub use pit::timer_interrupt_handler; pub use pit::timer_interrupt_handler;
pub use disk::{disk1_interrupt_handler, disk2_interrupt_handler};
pub mod disk;
pub mod keyboard; pub mod keyboard;
pub mod pit; pub mod pit;
pub mod disk;
pub const PIC_1_OFFSET: u8 = 32; pub const PIC_1_OFFSET: u8 = 32;
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8; pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;

@ -4,23 +4,23 @@
#![feature(alloc_error_handler)] #![feature(alloc_error_handler)]
mod drivers; mod drivers;
mod fd;
mod fs;
mod interrupts; mod interrupts;
mod memory; mod memory;
mod task;
mod fs;
mod utils;
mod fd;
mod syscalls; mod syscalls;
mod task;
mod utils;
//#[macro_use] //#[macro_use]
extern crate alloc; extern crate alloc;
extern crate multiboot2; extern crate multiboot2;
use crate::fs::FileSystem;
use core::panic::PanicInfo; use core::panic::PanicInfo;
use drivers::vga::{self, Color, ColorCode}; use drivers::vga::{self, Color, ColorCode};
use multiboot2::BootInformation; use multiboot2::BootInformation;
use task::{executor::Executor, keyboard, Task}; use task::{executor::Executor, keyboard, Task};
use crate::fs::FileSystem;
#[alloc_error_handler] #[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
@ -64,8 +64,12 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! {
executor.run(); executor.run();
} }
async fn get_file() { 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; fd.borrow_mut().read(&[], 0).await;
} }

@ -1,5 +1,5 @@
pub mod serialize;
pub mod mutex; pub mod mutex;
pub mod serialize;
pub use serialize::unserialize;
pub use mutex::AsyncMutex; pub use mutex::AsyncMutex;
pub use serialize::unserialize;

@ -1,10 +1,10 @@
use core::future::Future; use alloc::sync::Arc;
use core::pin::Pin;
use core::cell::UnsafeCell; use core::cell::UnsafeCell;
use core::future::Future;
use core::ops::{Deref, DerefMut, Drop}; use core::ops::{Deref, DerefMut, Drop};
use core::pin::Pin;
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use core::task::{Context, Poll}; use core::task::{Context, Poll};
use alloc::sync::Arc;
use futures_util::task::AtomicWaker; use futures_util::task::AtomicWaker;
@ -23,7 +23,7 @@ pub struct AsyncMutexGuard<'a, T>
where where
T: 'a, T: 'a,
{ {
mutex: &'a AsyncMutex<T> mutex: &'a AsyncMutex<T>,
} }
impl Lock { impl Lock {
@ -58,7 +58,7 @@ impl Future for Lock {
false => { false => {
self.waker.take(); self.waker.take();
Poll::Ready(()) Poll::Ready(())
}, }
true => Poll::Pending, true => Poll::Pending,
} }
} }
@ -98,16 +98,12 @@ impl<T> Drop for AsyncMutexGuard<'_, T> {
impl<T> Deref for AsyncMutexGuard<'_, T> { impl<T> Deref for AsyncMutexGuard<'_, T> {
type Target = T; type Target = T;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
unsafe { unsafe { &*self.mutex.inner.get() }
&*self.mutex.inner.get()
}
} }
} }
impl<T> DerefMut for AsyncMutexGuard<'_, T> { impl<T> DerefMut for AsyncMutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { unsafe { &mut *self.mutex.inner.get() }
&mut *self.mutex.inner.get()
}
} }
} }

@ -1,6 +1,4 @@
pub fn unserialize<T>(ptr: *const u8) -> &'static T { pub fn unserialize<T>(ptr: *const u8) -> &'static T {
let path_table_ptr: *const T = ptr as *const T; let path_table_ptr: *const T = ptr as *const T;
unsafe { unsafe { &*path_table_ptr }
&*path_table_ptr
}
} }