Newer
Older
tree-os / src / kernel / util / ports.c
#include <ports.h>
#include <stdint.h>

void outb(uint16_t port, uint8_t val) {
    asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
}

uint8_t inb(uint16_t port) {
    uint8_t result;
    __asm__("in %%dx, %%al" : "=a"(result) : "d"(port));
    return result;
}

void outw(uint16_t port, uint16_t val) {
    asm volatile("outw %0, %1" : : "a"(val), "Nd"(port));
}

uint16_t inw(uint16_t port) {
    uint16_t result;
    __asm__("in %%dx, %%al" : "=a"(result) : "d"(port));
    return result;
}

void outi(uint16_t port, uint32_t val) {
    asm volatile("outl %0, %1" : : "a"(val), "Nd"(port));
}

uint32_t ini(uint16_t port) {
    uint32_t result;
    __asm__("in %%dx, %%eax" : "=a"(result) : "d"(port));
    return result;
}

void ioWait() { asm volatile("outb %%al, $0x80" : : "a"(0)); }