27 lines
830 B
C
Raw Normal View History

2023-01-13 12:56:54 +04:00
#pragma once
static inline unsigned char port_byte_in(unsigned short port) {
unsigned char result;
2023-01-27 13:15:37 +04:00
asm volatile("in %%dx, %%al" : "=a" (result) : "d" (port));
2023-01-13 12:56:54 +04:00
return result;
}
static inline unsigned short port_word_in(unsigned short port) {
unsigned short result;
2023-01-27 13:15:37 +04:00
asm volatile("in %%dx, %%ax" : "=a" (result) : "d" (port));
2023-01-13 12:56:54 +04:00
return result;
}
static inline void port_byte_out(unsigned short port, unsigned char data) {
2023-01-27 13:15:37 +04:00
asm volatile("outb %%al, %%dx" : : "a" (data), "d" (port));
2023-01-13 12:56:54 +04:00
}
static inline void port_word_out(unsigned short port, unsigned short data) {
2023-01-27 13:15:37 +04:00
asm volatile("outw %%ax, %%dx" : : "a" (data), "d" (port));
2023-01-13 12:56:54 +04:00
}
/* assembler-long, not c-long */
2023-01-13 12:56:54 +04:00
static inline void port_long_out(unsigned short port, unsigned int data) {
2023-01-27 13:15:37 +04:00
asm volatile("outl %%eax, %%dx" : : "a" (data), "d" (port));
2023-01-13 12:56:54 +04:00
}