hos/kernel/sys/io.h

60 lines
1.5 KiB
C

// io.h
// Author: Josh Holtrop
// Created: 02/26/04
// Implements basic port input/output functions
#ifndef __HOS_IO__
#define __HOS_IO__ __HOS_IO__
#include "hos_defines.h"
//void outportb(unsigned int port, unsigned char value);
//inline void outportw(unsigned int port, unsigned int value);
//inline unsigned char inportb(unsigned short port);
//Writes a byte out to a port
static inline void outportb(unsigned int port, unsigned int value) // Output a byte to a port
{
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
}
//Writes a word out to a port
static inline void outportw(unsigned int port, unsigned int value) // Output a word to a port
{
asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
}
//Writes a dword out to a port
static inline void outportd(unsigned int port, unsigned int value) // Output a word to a port
{
asm volatile ("outl %%eax,%%dx"::"d" (port), "a" (value));
}
//Reads a byte from a port
static inline unsigned char inportb(unsigned int port)
{
unsigned char ret_val;
asm volatile("inb %w1,%b0" : "=a"(ret_val) : "d"(port));
return ret_val;
}
//Reads a word from a port
static inline unsigned short inportw(unsigned int port)
{
unsigned int ret_val;
asm volatile("inw %w1,%w0" : "=a"(ret_val) : "d"(port));
return ret_val;
}
//Reads a dword from a port
static inline unsigned int inportd(unsigned int port)
{
unsigned int ret_val;
asm volatile("inl %w1,%0" : "=a"(ret_val) : "d"(port));
return ret_val;
}
#endif