2019-05-22 21:12:46 +02:00
|
|
|
// Zig version: 0.4.0
|
|
|
|
|
|
|
|
const is_test = @import("builtin").is_test;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Initialise the architecture
|
|
|
|
///
|
2019-05-28 22:12:41 +02:00
|
|
|
pub fn init() void {}
|
2019-05-22 21:12:46 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Inline assembly to write to a given port with a byte of data.
|
|
|
|
///
|
|
|
|
/// Arguments:
|
|
|
|
/// IN port: u16 - The port to write to.
|
|
|
|
/// IN data: u8 - The byte of data that will be sent.
|
|
|
|
///
|
2019-05-28 22:12:41 +02:00
|
|
|
pub fn outb(port: u16, data: u8) void {
|
2019-05-22 21:12:46 +02:00
|
|
|
asm volatile ("outb %[data], %[port]"
|
|
|
|
:
|
2019-05-28 22:12:41 +02:00
|
|
|
: [port] "{dx}" (port),
|
|
|
|
[data] "{al}" (data)
|
|
|
|
);
|
2019-05-22 21:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Inline assembly that reads data from a given port and returns its value.
|
|
|
|
///
|
|
|
|
/// Arguments:
|
|
|
|
/// IN port: u16 - The port to read data from.
|
|
|
|
///
|
|
|
|
/// Return:
|
|
|
|
/// The data that the port returns.
|
|
|
|
///
|
2019-05-28 22:12:41 +02:00
|
|
|
pub fn inb(port: u16) u8 {
|
2019-05-22 21:12:46 +02:00
|
|
|
return asm volatile ("inb %[port], %[result]"
|
|
|
|
: [result] "={al}" (-> u8)
|
2019-05-28 22:12:41 +02:00
|
|
|
: [port] "N{dx}" (port)
|
|
|
|
);
|
2019-05-22 21:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// A simple way of waiting for I/O event to happen by doing an I/O event to flush the I/O
|
|
|
|
/// event being waited.
|
|
|
|
///
|
2019-05-28 22:12:41 +02:00
|
|
|
pub fn ioWait() void {
|
2019-05-22 21:12:46 +02:00
|
|
|
outb(0x80, 0);
|
|
|
|
}
|