-
Notifications
You must be signed in to change notification settings - Fork 1
/
port.c
31 lines (25 loc) · 880 Bytes
/
port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdint.h>
unsigned char port_byte_in (unsigned short port) {
unsigned char result;
__asm__ volatile("in %%dx, %%al" : "=a" (result) : "d" (port));
return result;
}
void port_byte_out (unsigned short port, unsigned char data) {
__asm__ volatile("out %%al, %%dx" : : "a" (data), "d" (port));
}
uint16_t port_word_in (uint16_t port) {
uint16_t result;
__asm__ volatile("in %%dx, %%ax" : "=a" (result) : "d" (port));
return result;
}
void port_word_out (unsigned short port, unsigned short data) {
__asm__ volatile("out %%ax, %%dx" : : "a" (data), "d" (port));
}
void port_long_out(uint32_t port, uint32_t value) {
__asm__ __volatile__("outl %%eax,%%dx"::"d" (port), "a" (value));
};
uint32_t port_long_in(uint32_t port) {
uint32_t result;
__asm__ __volatile__("inl %%dx,%%eax":"=a" (result):"d"(port));
return result;
}