aphrodite/arch/x86_asmp/
ports.rs

1
2
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
31
32
33
34
35
36
37
38
39
//! Provides utilities for interacting with assembly ports
#![cfg(any(target_arch = "x86"))]

use core::arch::asm;

/// Outputs a byte to an IO port
#[inline(always)]
pub fn outb(port: u16, val: u8) {
    unsafe {
        asm!(
            "out dx, al", in("dx") port, in("al") val
        )
    }
}

/// Outputs an arbitrary number of bytes to an IO port
pub fn outbs(port: u16, val: &[u8]) {
    for ele in val {
        outb(port, *ele);
    }
}

/// Reads a byte from an IO port
#[inline(always)]
pub fn inb(port: u16) -> u8 {
    let out;
    unsafe {
        asm!(
            "in al, dx", out("al") out, in("dx") port
        )
    }
    out
}

/// Wait a short, indeterminable time
#[inline(always)]
pub fn io_wait() {
    outb(0x80, 0);
}