Skip to content

Commit

Permalink
Run args and improvements for AHCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy-Python-Programmer committed Mar 29, 2021
1 parent 172cc6a commit fb6ba5b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/log.log
/qemu.log
*.img
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ lto = true

[profile.release]
lto = true

[package.metadata.bootimage]
run-args = [
"-d",
"int,guest_errors",
"-D",
"qemu.log",
"-drive",
"id=disk,file=hdd.img,format=raw,if=none",
"-device",
"ahci,id=ahci",
"-device",
"ide-hd,drive=disk,bus=ahci.0",
]
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ run:
cargo run

clean:
cargo clean
cargo clean

init:
touch hdd.img

Empty file removed hdd.img
Empty file.
52 changes: 38 additions & 14 deletions src/drivers/ahci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,41 @@ use x86_64::{
use super::pci::{Bar, PCIHeader};
use crate::log;

use bitflags::bitflags;

bitflags! {
#[repr(C)]
pub struct HBACapabilities: u32 {
const SXS_SUPPORT = 1 << 5;
const EMS_SUPPORT = 1 << 6;
const CCC_SUPPORT = 1 << 7;
const PS_CAPABLE = 1 << 13;
const SS_CAPABLE = 1 << 14;
const PIO_MULTI_DRQ_SUPPORT = 1 << 15;
const FBSS_SUPPORT = 1 << 16;
const PM_SUPPORT = 1 << 17;
const AHCI_ONLY = 1 << 18;
const CLO_SUPPORT = 1 << 24;
const AL_SUPPORT = 1 << 25;
const ALP_SUPPORT = 1 << 26;
const SS_SUPPORT = 1 << 27;
const MPS_SUPPORT = 1 << 28;
const SNTF_SUPPORT = 1 << 29;
const NCQ_SUPPORT = 1 << 30;
const SUPPORTS_64_ADDRESSES = 1 << 31;
}
}

bitflags! {
#[repr(C)]
pub struct GlobalHBAControl: u32 {
const HBA_RESET = 1;
const INT_ENABLE = 1 << 1;
const MRSM = 1 << 2;
const AHCI_ENABLE = 1 << 31;
}
}

const SATA_SIG_ATAPI: u32 = 0xEB140101;
const SATA_SIG_ATA: u32 = 0x00000101;
const SATA_SIG_SEMB: u32 = 0xC33C0101;
Expand All @@ -28,8 +63,8 @@ pub enum AHCIPortType {

#[repr(C, packed)]
struct HBAMemory {
host_capability: u32,
global_host_control: u32,
host_capability: HBACapabilities,
global_host_control: GlobalHBAControl,
interrupt_status: u32,
ports_implemented: u32,
version: u32,
Expand Down Expand Up @@ -59,17 +94,6 @@ impl HBAMemory {
panic!()
}
}

pub fn port_count(&self) -> u32 {
self.ports_implemented.count_ones()
}

pub fn port_slice(&self) -> &[HBAPort] {
let count = self.port_count() as usize;
let slice = &self.ports[..count];

unsafe { MaybeUninit::slice_assume_init_ref(slice) }
}
}

#[repr(C, packed)]
Expand Down Expand Up @@ -140,7 +164,7 @@ impl AHCI {
let port = self.memory.get_port(i);
let port_type = self.get_port_type(port);

crate::println!("Found! {:?}{}", port_type, port.signature);
crate::println!("Found! {:?}", port_type);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/drivers/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,15 @@ impl PCIHeader {
Self(result)
}

fn bus(&self) -> u8 {
pub fn bus(&self) -> u8 {
self.0.get_bits(8..16) as u8
}

fn device(&self) -> u8 {
pub fn device(&self) -> u8 {
self.0.get_bits(3..8) as u8
}

fn function(&self) -> u8 {
pub fn function(&self) -> u8 {
self.0.get_bits(0..3) as u8
}

Expand Down

0 comments on commit fb6ba5b

Please sign in to comment.