system.h主要定義一些常用的x86彙編宏和字節序的處理。大部分都是拷貝linux中源代碼.
system.h源代碼:
#ifndef __SYSTEM_H__
#define __SYSTEM_H__
#ifndef NULL
#define NULL 0
#endif
typedef unsigned short u16;
typedef unsigned char u8;
typedef unsigned int u32;
typedef short s16;
typedef char s8;
typedef int s32;
typedef u32 dma_addr_t;
static inline unsigned int ntohl(unsigned int v)
{
return ( (( ( v ) & 0xff) << 24) |(( ( v >> 8 ) & 0xff) << 16) | ( ( ( v >> 16) & 0xff) << 8) | ( ( v >> 24) & 0xff) );
}
static inline unsigned short ntohs(unsigned short v)
{
return ((((v) & 0xff)<<8) |(((v) >> 8) & 0xff));
}
#define htonl ntohl
#define htons ntohs
#define wmb() __asm__ __volatile__ ("": : :"memory")
#define X86_FEATURE_XMM2 (0*32+26)
#define alternative(oldinstr, newinstr, feature) \
asm volatile ("661:\n\t" oldinstr "\n662:\n" \
".section .altinstructions,\"a\"\n" \
" .align 4\n" \
" .long 661b\n" /* label */ \
" .long 663f\n" /* new instruction */ \
" .byte %c0\n" /* feature bit */ \
" .byte 662b-661b\n" /* sourcelen */ \
" .byte 664f-663f\n" /* replacementlen */ \
".previous\n" \
".section .altinstr_replacement,\"ax\"\n" \
"663:\n\t" newinstr "\n664:\n" /* replacement */\
".previous" :: "i" (feature) : "memory")
#define rmb() alternative("lock; addl $0,0(%%esp)", "lfence", X86_FEATURE_XMM2)