TSOS/src/kernel/drivers/ports/ports.c

31 lines
735 B
C

// Utilities for writing to and reading from I/O ports
#include "ports.h"
byte vga_readb(u16 port) {
// Reads a byte from the specified I/O port
byte result;
__asm__("in %%dx, %%al" : "=a" (result) : "d" (port));
return result;
}
void vga_writeb(u16 port, byte data) {
// Writes a byte to the specified I/O port
__asm__("out %%al, %%dx" : : "a" (data), "d" (port));
}
u16 vga_readw(u16 port) {
// Reads a word (16 bits) from the specified I/O port
u16 result;
__asm__("in %%dx, %%ax" : "=a" (result) : "d" (port));
return result;
}
void vga_writew(u16 port, u16 data) {
// Writes a word (16 bits) to the specified I/O port
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
}