42_KFS/libbozo/headers/sys/io.h

44 lines
838 B
C
Raw Normal View History

2024-09-07 08:40:46 -04:00
#pragma once
#include <stddef.h>
#include <stdint.h>
2024-09-07 08:40:46 -04:00
static inline void outb(uint16_t port, uint8_t val)
{
__asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
2024-09-07 08:40:46 -04:00
}
static inline uint8_t inb(uint16_t port)
{
uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret;
}
2024-09-10 10:37:01 -04:00
static inline void outw(uint16_t port, uint16_t val)
{
__asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
}
static inline uint16_t inw(uint16_t port)
{
uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret;
}
static inline void io_wait(void)
{
outb(0x80, 0);
}
static inline void write_reg(size_t addr, uint32_t val)
{
*(volatile uint32_t *)addr = val;
}
static inline uint32_t read_reg(size_t addr)
{
return *(volatile uint32_t *)addr;
}