main.rs 1.65 KB
Newer Older
1
#![feature(asm)]
2
#![feature(question_mark)]
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

#[macro_use]
extern crate bitflags;
extern crate io;
extern crate syscall;

use std::{env, thread, usize};

use syscall::{iopl, physmap, physunmap, MAP_WRITE};

pub mod ahci;

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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
        {
            let mut disks = ahci::disks(address, irq);
            for mut disk in disks.iter_mut() {
                let mut sector = [0; 512];
                println!("Read disk {} size {} MB", disk.id(), disk.size()/1024/1024);
                match disk.read(0, &mut sector) {
                    Ok(count) => {
                        println!("{}", count);
                        for i in 0..512 {
                            print!("{:X} ", sector[i]);
                        }
                        println!("");
                    },
                    Err(err) => {
                        println!("{}", err);
                    }
                }
            }
            loop {
                let _ = syscall::sched_yield();
            }
52
        }
Jeremy Soller's avatar
Jeremy Soller committed
53
        unsafe { let _ = physunmap(address); }
54 55
    });
}