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.
37 lines
1.0 KiB
37 lines
1.0 KiB
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#define NUL 0 // TODO Fix VSCode thinking `NULL` conflicts with some other definition.
|
|
|
|
static inline uint8_t inb(uint16_t port) {
|
|
uint8_t value;
|
|
__asm__ volatile("inb %1, %0" : "=a"(value) : "Nd"(port));
|
|
return value;
|
|
}
|
|
|
|
static inline void outb(uint16_t port, uint8_t value) {
|
|
__asm__ volatile("outb %0, %1" : : "a"(value), "Nd"(port));
|
|
}
|
|
|
|
static inline uint16_t inw(uint16_t port) {
|
|
uint16_t value;
|
|
__asm__ volatile("inw %1, %0" : "=a"(value) : "Nd"(port));
|
|
return value;
|
|
}
|
|
|
|
static inline void outw(uint16_t port, uint16_t value) {
|
|
__asm__ volatile("outw %0, %1" : : "a"(value), "Nd"(port));
|
|
}
|
|
|
|
static inline void insw(uint16_t port, void *to, uint32_t count) {
|
|
__asm__ volatile("rep insw" : "=D"(to), "=c"(count) : "d"(port), "D"(to), "c"(count) : "memory");
|
|
}
|
|
|
|
static inline void outsw(uint16_t port, const void *buffer, uint32_t count) {
|
|
__asm__ volatile("rep outsw" : "=S"(buffer), "=c"(count) : "d"(port), "S"(buffer), "c"(count) : "memory");
|
|
}
|
|
|
|
static inline void io_wait() {
|
|
outb(0x80, 0x00);
|
|
}
|
|
|