[ create a new paste ] login | about

Link: http://codepad.org/5C1EZUbs    [ raw code | fork ]

C++, pasted on Jun 9:
#ifndef KERNELUTILS_H
#define KERNELUTILS_H

#include <cstddef>

namespace jlgos {

static __inline void halt() {
   asm volatile ("cli; hlt");
}

static __inline void outb ( unsigned short int port, unsigned char value ) {
   asm volatile ("outb %b0,%w1"
                 : 
                 :"a" (value), "Nd" (port));
}

static __inline void memcpy( void* source, void* destination, unsigned int num ) {
   asm volatile("cld ;"
                "rep movsb" 
                :
                : "S"(source), "D"(destination), "c"(num) 
                : "flags", "memory");
}

template <class T>
char * formathex( T value ) {
   const char hexdigits[] = "0123456789ABCDEF";
   static char localbuffer[ sizeof(T) * 2 + 1 ];

   size_t position = 0;
   for ( int i = sizeof(T) * 2 - 1; i >= 0; i--) {
      localbuffer[position++] = hexdigits[((value >> i * 4) & 0xF)];
   }
   localbuffer[position] = '\0';

   return localbuffer;

}

};

#endif


Create a new paste based on this one


Comments: