Challenge of handmade OS
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.
 
 
 
 

40 lines
994 B

#include "io.h"
UINT8 mapped_io_read(UINT16 addr) {
UINT8 data;
asm volatile("inb %1,%0" : "=a"(data) : "d"(addr));
return data;
}
void mapped_io_write(UINT16 addr, UINT8 data) {
asm volatile("outb %0,%1" ::"a"(data), "d"(addr));
}
UINT16 mapped_io_read_word(UINT16 addr) {
UINT16 data;
asm volatile("inw %1,%0" : "=a"(data) : "d"(addr));
return data;
}
void mapped_io_write_word(UINT16 addr, UINT16 data) {
asm volatile("outw %0,%1" ::"a"(data), "d"(addr));
}
UINT32 mapped_io_read_dword(UINT16 addr) {
UINT32 data;
asm volatile("inl %1,%0" : "=a"(data) : "d"(addr));
return data;
}
void mapped_io_write_dword(UINT16 addr, UINT32 data) {
asm volatile("outl %0,%1" ::"a"(data), "d"(addr));
}
UINT64 mapped_io_read_qword(UINT16 addr) {
UINT64 data;
asm volatile("inq %1,%0" : "=a"(data) : "d"(addr));
return data;
}
void mapped_io_write_qword(UINT16 addr, UINT64 data) {
asm volatile("outq %0,%1" ::"a"(data), "d"(addr));
}