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

extern crate syscall;

use std::fs::File;
use std::io::{Read, Write};
7
use std::mem;
8 9 10 11 12
use std::thread;

use syscall::iopl;

fn main() {
13 14 15
    println!("PS/2 driver launching");

    thread::spawn(|| {
16 17 18 19 20 21 22 23 24 25 26
        unsafe {
            iopl(3).expect("pskbd: failed to get I/O permission");
            asm!("cli" :::: "intel", "volatile");
        }

        let mut file = File::open("irq:1").expect("pskbd: failed to open irq:1");

        println!("pskbd: Reading keyboard IRQs");

        loop {
            let mut irqs = [0; 8];
27 28 29 30 31
            if file.read(&mut irqs).expect("pskbd: failed to read irq:1") >= mem::size_of::<usize>() {
                let data: u8;
                unsafe {
                    asm!("in al, dx" : "={al}"(data) : "{dx}"(0x60) : : "intel", "volatile");
                }
32

33
                println!("pskbd: IRQ {}: {:X}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
34

35 36 37 38
                file.write(&irqs).expect("pskbd: failed to write irq:1");
            } else {
                thread::yield_now();
            }
39
        }
40 41 42
    });

    thread::spawn(|| {
43 44 45 46 47 48 49 50 51 52
        unsafe {
            iopl(3).expect("psmsd: failed to get I/O permission");
            asm!("cli" :::: "intel", "volatile");
        }

        let mut file = File::open("irq:12").expect("psmsd: failed to open irq:12");

        println!("psmsd: Reading mouse IRQs");

        loop {
53 54 55 56 57 58
            let mut irqs = [0; 8];
            if file.read(&mut irqs).expect("psmsd: failed to read irq:12") >= mem::size_of::<usize>() {
                let data: u8;
                unsafe {
                    asm!("in al, dx" : "={al}"(data) : "{dx}"(0x60) : : "intel", "volatile");
                }
59

60
                println!("psmsd: IRQ {}: {:X}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
61

62 63 64 65
                file.write(&irqs).expect("psmsd: failed to write irq:12");
            } else {
                thread::yield_now();
            }
66
        }
67 68 69
    });

    println!("PS/2 driver running in background");
70
}