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

#[macro_use]
extern crate bitflags;
extern crate io;
7
extern crate spin;
8 9
extern crate syscall;

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

15
use scheme::DiskScheme;
16 17

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

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
36
        {
37 38
            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
39
            loop {
40 41 42 43
                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
44
            }
45
        }
Jeremy Soller's avatar
Jeremy Soller committed
46
        unsafe { let _ = physunmap(address); }
47 48
    });
}