70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
static inline void outportb(const uint16_t port, const uint8_t val) {
|
|
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
|
|
}
|
|
|
|
static inline void outportw(const uint16_t port, const uint16_t val) {
|
|
asm volatile ( "outw %0, %1" : : "a"(val), "Nd"(port) );
|
|
}
|
|
|
|
static inline void outportl(const uint16_t port, const uint32_t val) {
|
|
asm volatile ( "outl %0, %1" : : "a"(val), "Nd"(port) );
|
|
}
|
|
|
|
static inline void outportsm(unsigned short port, unsigned char* data, unsigned long size) {
|
|
asm volatile ("rep outsw" : "+S" (data), "+c" (size) : "d" (port));
|
|
}
|
|
|
|
static inline uint8_t inportb(const uint16_t port) {
|
|
uint8_t ret;
|
|
asm volatile ( "inb %1, %0" : "=a"(ret) : "Nd"(port) );
|
|
return ret;
|
|
}
|
|
|
|
static inline uint16_t inportw(const uint16_t port) {
|
|
uint16_t ret;
|
|
asm volatile ( "inw %1, %0" : "=a"(ret) : "Nd"(port) );
|
|
return ret;
|
|
}
|
|
|
|
static inline uint32_t inportl(const uint16_t port) {
|
|
uint32_t ret;
|
|
asm volatile ( "inl %1, %0" : "=a"(ret) : "Nd"(port) );
|
|
return ret;
|
|
}
|
|
|
|
static inline void inportsm(unsigned short port, unsigned char* data, unsigned long size) {
|
|
asm volatile ("rep insw" : "+D" (data), "+c" (size) : "d" (port) : "memory");
|
|
}
|
|
|
|
static inline void io_wait() {
|
|
asm volatile("outb %%al, $0x80" : : "a"(0));
|
|
}
|
|
|
|
static inline bool are_interrupts_enabled() {
|
|
unsigned long flags;
|
|
asm volatile ( "pushf\n\t"
|
|
"pop %0"
|
|
: "=g"(flags) );
|
|
return flags & (1 << 9);
|
|
}
|
|
|
|
static inline void insl(unsigned reg, unsigned int *buffer, int quads) {
|
|
int index;
|
|
for (index = 0; index < quads; index++) {
|
|
buffer[index] = inportl(reg);
|
|
}
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|