X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86_64%2Flib.c;h=e3669c045978c77dbc637f62cb63d8d90206b31d;hb=a79ebcb3a2e206251f44e99376ec2ed6c2bacc63;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=3234a52a913609230ffc140c27542d421bb1b7d3;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86_64/lib.c b/Kernel/arch/x86_64/lib.c index e69de29b..e3669c04 100644 --- a/Kernel/arch/x86_64/lib.c +++ b/Kernel/arch/x86_64/lib.c @@ -0,0 +1,93 @@ +/* + */ +#include +#include + +// === CODE === + +void outb(Uint16 Port, Uint8 Data) +{ + __asm__ __volatile__ ("outb %%al, %%dx"::"d"(Port),"a"(Data)); +} +void outw(Uint16 Port, Uint16 Data) +{ + __asm__ __volatile__ ("outw %%ax, %%dx"::"d"(Port),"a"(Data)); +} +void outd(Uint16 Port, Uint32 Data) +{ + __asm__ __volatile__ ("outl %%eax, %%dx"::"d"(Port),"a"(Data)); +} +Uint8 inb(Uint16 Port) +{ + Uint8 ret; + __asm__ __volatile__ ("inb %%dx, %%al":"=a"(ret):"d"(Port)); + return ret; +} +Uint16 inw(Uint16 Port) +{ + Uint16 ret; + __asm__ __volatile__ ("inw %%dx, %%ax":"=a"(ret):"d"(Port)); + return ret; +} +Uint32 ind(Uint16 Port) +{ + Uint32 ret; + __asm__ __volatile__ ("inl %%dx, %%eax":"=a"(ret):"d"(Port)); + return ret; +} + +// === Endianness === +Uint32 BigEndian32(Uint32 Value) +{ + Uint32 ret; + ret = (Value >> 24); + ret |= ((Value >> 16) & 0xFF) << 8; + ret |= ((Value >> 8) & 0xFF) << 16; + ret |= ((Value >> 0) & 0xFF) << 24; + return ret; +} + +Uint16 BigEndian16(Uint16 Value) +{ + return (Value>>8)|(Value<<8); +} + +// === Memory Manipulation === +void *memcpy(void *__dest, const void *__src, size_t __count) +{ + if( ((tVAddr)__dest & 7) != ((tVAddr)__src & 7) ) + __asm__ __volatile__ ("rep movsb" : : "D"(__dest),"S"(__src),"c"(__count)); + else { + const Uint8 *src = __src; + Uint8 *dst = __dest; + while( (tVAddr)src & 7 && __count ) { + *dst++ = *src++; + __count --; + } + + __asm__ __volatile__ ("rep movsq" : : "D"(dst),"S"(src),"c"(__count/8)); + src += __count & ~7; + dst += __count & ~7; + __count = __count & 7; + while( __count-- ) + *dst++ = *src++; + } + return __dest; +} + +void *memset(void *__dest, int __val, size_t __count) +{ + if( __val != 0 || ((tVAddr)__dest & 7) != 0 ) + __asm__ __volatile__ ("rep stosb" : : "D"(__dest),"a"(__val),"c"(__count)); + else { + Uint8 *dst = __dest; + + __asm__ __volatile__ ("rep stosq" : : "D"(dst),"a"(0),"c"(__count/8)); + dst += __count & ~7; + __count = __count & 7; + while( __count-- ) + *dst++ = 0; + } + return __dest; +} +