HhhOS/include/std/inline.h
2021-08-17 12:45:35 +03:00

62 lines
1.6 KiB
C

#pragma once
#include <stdbool.h>
#include <types.h>
static inline void outportb(const u16 port, const u8 val) {
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
}
static inline void outportw(const u16 port, const u16 val) {
asm volatile ( "outw %0, %1" : : "a"(val), "Nd"(port) );
}
static inline void outportl(const u16 port, const u32 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 u8 inportb(const u16 port) {
u8 ret;
asm volatile ( "inb %1, %0" : "=a"(ret) : "Nd"(port) );
return ret;
}
static inline u16 inportw(const u16 port) {
u16 ret;
asm volatile ( "inw %1, %0" : "=a"(ret) : "Nd"(port) );
return ret;
}
static inline u32 inportl(const u16 port) {
u32 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);
}
}