#include "util.h" /** * Wrapper function that reads a byte from the specified I/O port. * * "=a" (result) - put al register in the `result` var when finished * "d" (port) - load edx with the specified `port` * * @param port * @return the read byte */ u8_t io_byte_in(u16_t port) { u8_t result; __asm__("in %%dx, %%al" : "=a" (result) : "d" (port)); return result; } /** * Wrapper function that writes a byte to the specified I/O port. * * "a" (data) - load eal with `data` * "d" (port) - load edx with `port` * * @param port * @param data */ void io_byte_out(u16_t port, u8_t data) { __asm__("out %%al, %%dx" : : "a" (data), "d" (port)); } /** * Wrapper function that reads a word from the specified I/O port. * * "=a" (result) - put eax register in the `result` var when finished * "d" (port) - load edx with the specified `port` * * @param port * @return the read word */ u16_t io_word_in(u16_t port) { u16_t result; __asm__("in %%dx, %%ax" : "=a" (result) : "d" (port)); return result; } /** * Wrapper function that writes a word to the specified I/O port. * * "a" (data) - load eax with `data` * "d" (port) - load edx with `port` * * @param port * @param data */ void io_word_out(u16_t port, u16_t data) { __asm__("out %%ax, %%dx" : : "a" (data), "d" (port)); }