#ifndef __io_h__ #define __io_h__ #include "type.h" template class Io { private: type justForPointerArithmetic; public: inline const Io & operator=(type v) const; inline operator type() const; inline const Io & operator|=(type v) const { register type r; r=*this; r|=v; *this=r; } inline const Io & operator&=(type v) const { register type r; r=*this; r&=v; *this=r; } }; template<> inline const Io & Io::operator=(U8 v) const { register U16 address __asm("%dx")=(U16)(U32)(this); register U8 value __asm("%al")=v; asm volatile("outb %0,%1" : : "al" (value) , "dx" (address) ); return *this; } template<> inline Io::operator U8() const { register U16 address __asm("%dx")=(U16)(U32)(this); register U8 value __asm("%al"); __asm volatile("inb %1,%0" : "=al" (value) : "dx" (address) ); return value; } template<> inline const Io & Io::operator=(U16 v) const { register U16 address __asm("%dx")=(U16)(U32)this; register U16 value __asm("%ax")=v; __asm volatile("outw %0,%1" : : "ax" (value) , "dx" (address) ); return *this; } template<> inline Io::operator U16() const { register U16 address __asm("%dx")=(U16)(U32)this; register U16 value __asm("%ax"); __asm volatile("inw %1,%0" : "=ax" (value) : "dx" (address) ); return value; } template<> inline const Io & Io::operator=(U32 v) const { register U16 address __asm("%dx")=(U16)(U32)this; register U32 value __asm("%eax")=v; __asm volatile("outl %0,%1" : : "eax" (value) , "dx" (address) ); return *this; } template<> inline Io::operator U32() const { register U16 address __asm("%dx")=(U16)(U32)this; register U32 value __asm("%eax"); __asm volatile("inl %1,%0" : "=eax" (value) : "dx" (address) ); return value; } #endif /* __io_h__ */