morpheus_network/asm/core/
pio.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Port I/O bindings.
//!
//! # Safety
//! Port must be valid I/O port for the operation.
//!
//! # Reference
//! ARCHITECTURE_V3.md - PIO layer

#[cfg(target_arch = "x86_64")]
extern "win64" {
    fn asm_pio_read8(port: u16) -> u8;
    fn asm_pio_write8(port: u16, value: u8);
    fn asm_pio_read16(port: u16) -> u16;
    fn asm_pio_write16(port: u16, value: u16);
    fn asm_pio_read32(port: u16) -> u32;
    fn asm_pio_write32(port: u16, value: u32);
}

/// Read 8-bit value from I/O port.
///
/// # Safety
/// Port must be valid and accessible.
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn inb(port: u16) -> u8 {
    asm_pio_read8(port)
}

/// Write 8-bit value to I/O port.
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn outb(port: u16, value: u8) {
    asm_pio_write8(port, value)
}

/// Read 16-bit value from I/O port.
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn inw(port: u16) -> u16 {
    asm_pio_read16(port)
}

/// Write 16-bit value to I/O port.
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn outw(port: u16, value: u16) {
    asm_pio_write16(port, value)
}

/// Read 32-bit value from I/O port.
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn inl(port: u16) -> u32 {
    asm_pio_read32(port)
}

/// Write 32-bit value to I/O port.
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn outl(port: u16, value: u32) {
    asm_pio_write32(port, value)
}

// Stubs for non-x86_64
#[cfg(not(target_arch = "x86_64"))]
#[inline]
pub unsafe fn inb(_port: u16) -> u8 {
    0
}
#[cfg(not(target_arch = "x86_64"))]
#[inline]
pub unsafe fn outb(_port: u16, _value: u8) {}
#[cfg(not(target_arch = "x86_64"))]
#[inline]
pub unsafe fn inw(_port: u16) -> u16 {
    0
}
#[cfg(not(target_arch = "x86_64"))]
#[inline]
pub unsafe fn outw(_port: u16, _value: u16) {}
#[cfg(not(target_arch = "x86_64"))]
#[inline]
pub unsafe fn inl(_port: u16) -> u32 {
    0
}
#[cfg(not(target_arch = "x86_64"))]
#[inline]
pub unsafe fn outl(_port: u16, _value: u32) {}