-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from Harthann/138-diskio-interface-creation
138 diskio interface creation
- Loading branch information
Showing
11 changed files
with
646 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use super::DiskIO; | ||
use crate::pci::ide::IDEDevice; | ||
|
||
pub struct IDEDisk { | ||
diskno: u8, | ||
device: IDEDevice | ||
} | ||
|
||
unsafe impl Send for IDEDisk {} | ||
|
||
impl IDEDisk { | ||
pub const fn new(diskno: u8, device: IDEDevice) -> Self { | ||
Self { diskno, device } | ||
} | ||
} | ||
|
||
impl DiskIO for IDEDisk { | ||
fn read_sectors(&self, numsects: u8, lba: u32, edi: u32) -> Result<(), u8> { | ||
self.device.read_sectors(numsects, lba, edi) | ||
} | ||
|
||
fn write_sectors( | ||
&mut self, | ||
numsects: u8, | ||
lba: u32, | ||
edi: u32 | ||
) -> Result<(), u8> { | ||
self.device.write_sectors(numsects, lba, edi) | ||
} | ||
|
||
fn sector_size(&self) -> usize { | ||
self.device.sector_size() as usize | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use crate::alloc::boxed::Box; | ||
use crate::alloc::vec::Vec; | ||
use crate::pci::ide::IDE; | ||
|
||
pub mod ide; | ||
use ide::IDEDisk; | ||
|
||
pub trait DiskIO { | ||
fn read_sectors(&self, numsects: u8, lba: u32, edi: u32) -> Result<(), u8>; | ||
|
||
fn write_sectors( | ||
&mut self, | ||
numsects: u8, | ||
lba: u32, | ||
edi: u32 | ||
) -> Result<(), u8>; | ||
|
||
fn sector_size(&self) -> usize; | ||
} | ||
|
||
pub fn discover() -> Vec<Box<dyn DiskIO + Send>> { | ||
let mut found_disks = Vec::<Box<dyn DiskIO + Send>>::new(); | ||
|
||
// Discover IDE disks | ||
let binding = IDE.lock(); | ||
for i in 0..4 { | ||
let disk = binding.get_device(i); | ||
match disk { | ||
Some(x) => { | ||
let idedisk = IDEDisk::new(i as u8, x.clone()); | ||
let diskio = Box::new(idedisk); | ||
found_disks.push(diskio); | ||
}, | ||
None => {} | ||
} | ||
} | ||
|
||
found_disks | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
|
||
use super::ide::IDEDisk; | ||
use super::DiskIO; | ||
use crate::alloc::vec; | ||
use crate::{sys_macros, IDE}; | ||
|
||
#[sys_macros::test_case] | ||
fn idedisk_read_write_sector() { | ||
let to_write = vec!['C' as u8; 512]; | ||
let read_from = vec![0x0 as u8; 512]; | ||
|
||
let device = IDE.lock().get_device(1).unwrap().clone(); | ||
let mut idedisk = IDEDisk::new(1, device); | ||
let _ = idedisk.write_sectors(1, 0x0, to_write.as_ptr() as u32); | ||
let _ = idedisk.read_sectors(1, 0x0, read_from.as_ptr() as u32); | ||
|
||
assert_eq!(to_write, read_from); | ||
} | ||
|
||
#[sys_macros::test_case] | ||
fn idedisk_read_write_multiple_sectors() { | ||
let to_write = vec!['D' as u8; 1024]; | ||
let read_from = vec![0x0 as u8; 1024]; | ||
|
||
let device = IDE.lock().get_device(1).unwrap().clone(); | ||
let mut idedisk = IDEDisk::new(1, device); | ||
let _ = idedisk.write_sectors(2, 0x0, to_write.as_ptr() as u32); | ||
let _ = idedisk.read_sectors(2, 0x0, read_from.as_ptr() as u32); | ||
|
||
assert_eq!(to_write, read_from); | ||
} | ||
} |
Oops, something went wrong.