A poorly written OS for the x86 arch. (WIP)
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.
eOS/kernel/io.c

53 lines
969 B

3 years ago
// Function to read a byte from port
3 years ago
unsigned char inb(unsigned short port) {
3 years ago
unsigned char res;
__asm__("in %%dx, %%al" : "=a" (res) : "d" (port));
return res;
}
3 years ago
// to write a byte to port
3 years ago
void outb(unsigned short port, unsigned char data) {
3 years ago
__asm__("out %%al, %%dx" : :"a" (data), "d" (port));
}
// Read word from port
3 years ago
unsigned short inw(unsigned short port) {
3 years ago
unsigned short res;
__asm__("in %%dx, %%ax" : "=a" (res) : "d" (port));
return res;
}
// write word to port
3 years ago
void outw(unsigned short port, unsigned short data) {
3 years ago
__asm__("out %%ax, %%dx" : :"a" (data), "d" (port));
3 years ago
}
3 years ago
3 years ago
static inline void io_wait() {
outb(0x80, 0);
}
unsigned char inb_w(unsigned short port) {
inb(port);
io_wait();
}
void outb_w(unsigned short port, unsigned char data) {
outb(port, data);
io_wait();
}
unsigned short inw_w(unsigned short port) {
inw(port);
io_wait();
}
void outw_w(unsigned short port, unsigned short data) {
outw(port, data);
io_wait();
}