Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
af9a7aa712
commit
3968c4c376
@ -9,6 +9,7 @@ use core::convert::TryInto;
|
|||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
|
use crate::utils::AsyncMutex;
|
||||||
use x86_64::instructions::port::Port;
|
use x86_64::instructions::port::Port;
|
||||||
|
|
||||||
const CD_SECTOR_SIZE: usize = 2048;
|
const CD_SECTOR_SIZE: usize = 2048;
|
||||||
@ -58,15 +59,16 @@ static ATAPI_SIG: [u8; 4] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref DRIVE: Mutex<Option<ATABus>> = {
|
pub static ref DRIVE: AsyncMutex<Option<ATABus>> = {
|
||||||
Mutex::new(ATABus::discover_atapi_drive())
|
AsyncMutex::new(ATABus::discover_atapi_drive())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn init() {
|
pub async fn init() {
|
||||||
println!("Detecting drives");
|
println!("Detecting drives");
|
||||||
match DRIVE.lock().as_ref() {
|
let guard = DRIVE.lock().await;
|
||||||
|
match guard.as_ref() {
|
||||||
None => println!("No drive detected :("),
|
None => println!("No drive detected :("),
|
||||||
Some(drive) => {
|
Some(drive) => {
|
||||||
let drive_type = match drive.current_drive {
|
let drive_type = match drive.current_drive {
|
||||||
@ -322,6 +324,7 @@ impl ATABus {
|
|||||||
|
|
||||||
|
|
||||||
pub async fn print_block() {
|
pub async fn print_block() {
|
||||||
DRIVE.lock().as_mut().unwrap().read_block(500).await;
|
let mut guard = DRIVE.lock().await;
|
||||||
serial_println!("{:x?}", DRIVE.lock().as_mut().unwrap().block);
|
guard.as_mut().unwrap().read_block(500).await;
|
||||||
|
serial_println!("{:x?}", guard.as_mut().unwrap().block);
|
||||||
}
|
}
|
@ -6,9 +6,10 @@ use crate::utils::unserialize;
|
|||||||
use iso9660::{IsoPrimVolDesc};
|
use iso9660::{IsoPrimVolDesc};
|
||||||
|
|
||||||
pub async fn init_prim_vol_desc() {
|
pub async fn init_prim_vol_desc() {
|
||||||
let desc_block = DRIVE
|
let mut guard = DRIVE
|
||||||
.lock()
|
.lock()
|
||||||
.as_mut()
|
.await;
|
||||||
|
let desc_block = guard.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK)
|
.read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK)
|
||||||
.await;
|
.await;
|
||||||
|
@ -4,14 +4,14 @@ use core::cell::UnsafeCell;
|
|||||||
use core::ops::{Deref, DerefMut, Drop};
|
use core::ops::{Deref, DerefMut, Drop};
|
||||||
use core::sync::atomic::{AtomicBool, Ordering};
|
use core::sync::atomic::{AtomicBool, Ordering};
|
||||||
use core::task::{Context, Poll};
|
use core::task::{Context, Poll};
|
||||||
use alloc::rc::Rc;
|
use alloc::sync::Arc;
|
||||||
|
|
||||||
use futures_util::task::AtomicWaker;
|
use futures_util::task::AtomicWaker;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Lock {
|
struct Lock {
|
||||||
lock: Rc<AtomicBool>,
|
lock: Arc<AtomicBool>,
|
||||||
waker: Rc<AtomicWaker>,
|
waker: Arc<AtomicWaker>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AsyncMutex<T> {
|
pub struct AsyncMutex<T> {
|
||||||
@ -29,8 +29,8 @@ where
|
|||||||
impl Lock {
|
impl Lock {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Lock {
|
Lock {
|
||||||
lock: Rc::new(AtomicBool::new(false)),
|
lock: Arc::new(AtomicBool::new(false)),
|
||||||
waker: Rc::new(AtomicWaker::new()),
|
waker: Arc::new(AtomicWaker::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +86,8 @@ impl<T> AsyncMutex<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl<T> Send for AsyncMutex<T> {}
|
||||||
|
unsafe impl<T> Sync for AsyncMutex<T> {}
|
||||||
|
|
||||||
impl<T> Drop for AsyncMutexGuard<'_, T> {
|
impl<T> Drop for AsyncMutexGuard<'_, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user