Files
my-kern/kernel/drivers/ports.c
2021-02-10 18:56:47 +01:00

64 lines
1.5 KiB
C

/*
* ports.c
*
* Created on: Aug 18, 2019
* Author: rick
*/
#include "ports.h"
/**
* Read a byte from the specified port
*/
unsigned char port_byte_in(unsigned short port) {
unsigned char result;
__asm__("in %%dx, %%al" : "=a" (result) : "d" (port));
return result;
}
void port_byte_out(unsigned short port, unsigned char data) {
__asm__("out %%al, %%dx" : : "a" (data), "d" (port));
}
unsigned short port_word_in(unsigned short port) {
unsigned short result;
__asm__("in %%dx, %%ax" : "=a" (result) : "d" (port));
return result;
}
void port_word_out(unsigned short port, unsigned short data) {
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
}
unsigned int port_double_word_in(unsigned int port) {
unsigned int result;
__asm__("in %%dx, %%eax" : "=a" (result) : "d" (port));
return result;
}
void port_double_word_out(unsigned short port, unsigned int data) {
__asm__("out %%eax, %%dx" : : "a" (data), "d" (port));
}
void port_word_out_repeat(unsigned short port, unsigned short *data, int buffer_size) {
asm("rep outsw"
: "+S"(data), "+c"(buffer_size)
: "d"(port)
: "memory");
}
void port_word_in_repeat(unsigned short port, unsigned short *data, int buffer_size) {
asm("rep insw"
: "+D"(data), "+c"(buffer_size)
: "d"(port)
: "memory");
}
void port_double_word_in_repeat(unsigned short port, unsigned int *data, int buffer_size) {
asm("rep insl"
: "+D"(data), "+c"(buffer_size)
: "d"(port)
: "memory");
}