You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

#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
*/
uint8_t io_byte_in(uint16_t port) {
uint8_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(uint16_t port, uint8_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
*/
uint16_t io_word_in(uint16_t port) {
uint16_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(uint16_t port, uint16_t data) {
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
}