main.rs 1.5 KB
Newer Older
1
#![feature(asm)]
2
#![feature(question_mark)]
3 4 5

#[macro_use]
extern crate bitflags;
Jeremy Soller's avatar
Jeremy Soller committed
6
extern crate dma;
7
extern crate io;
8
extern crate spin;
9 10
extern crate syscall;

11 12
use std::fs::File;
use std::io::{Read, Write};
13
use std::{env, thread, usize};
14
use syscall::{iopl, physmap, physunmap, MAP_WRITE, Packet, Scheme};
15

16
use scheme::DiskScheme;
17 18

pub mod ahci;
19
pub mod scheme;
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

fn main() {
    let mut args = env::args().skip(1);

    let bar_str = args.next().expect("ahcid: no address provided");
    let bar = usize::from_str_radix(&bar_str, 16).expect("ahcid: failed to parse address");

    let irq_str = args.next().expect("ahcid: no irq provided");
    let irq = irq_str.parse::<u8>().expect("ahcid: failed to parse irq");

    thread::spawn(move || {
        unsafe {
            iopl(3).expect("ahcid: failed to get I/O permission");
            asm!("cli" :::: "intel", "volatile");
        }

        let address = unsafe { physmap(bar, 4096, MAP_WRITE).expect("ahcid: failed to map address") };
Jeremy Soller's avatar
Jeremy Soller committed
37
        {
38 39
            let mut socket = File::create(":disk").expect("ahcid: failed to create disk scheme");
            let scheme = DiskScheme::new(ahci::disks(address, irq));
Jeremy Soller's avatar
Jeremy Soller committed
40
            loop {
41 42 43 44
                let mut packet = Packet::default();
                socket.read(&mut packet).expect("ahcid: failed to read disk scheme");
                scheme.handle(&mut packet);
                socket.write(&mut packet).expect("ahcid: failed to read disk scheme");
Jeremy Soller's avatar
Jeremy Soller committed
45
            }
46
        }
Jeremy Soller's avatar
Jeremy Soller committed
47
        unsafe { let _ = physunmap(address); }
48 49
    });
}