00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _BYTESWAP_H
00027 #define _BYTESWAP_H
00028
00029 #define lu(from,i,s) (((__libelf_u32_t)((unsigned char*)(from))[i])<<(s))
00030 #define li(from,i,s) (((__libelf_i32_t)(( signed char*)(from))[i])<<(s))
00031
00032 #define __load_u16L(from) ((__libelf_u32_t) \
00033 (lu(from,1,8) | lu(from,0,0)))
00034 #define __load_u16M(from) ((__libelf_u32_t) \
00035 (lu(from,0,8) | lu(from,1,0)))
00036 #define __load_i16L(from) ((__libelf_i32_t) \
00037 (li(from,1,8) | lu(from,0,0)))
00038 #define __load_i16M(from) ((__libelf_i32_t) \
00039 (li(from,0,8) | lu(from,1,0)))
00040
00041 #define __load_u32L(from) ((__libelf_u32_t) \
00042 (lu(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0)))
00043 #define __load_u32M(from) ((__libelf_u32_t) \
00044 (lu(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0)))
00045 #define __load_i32L(from) ((__libelf_i32_t) \
00046 (li(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0)))
00047 #define __load_i32M(from) ((__libelf_i32_t) \
00048 (li(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0)))
00049
00050 #define su(to,i,v,s) (((char*)(to))[i]=((__libelf_u32_t)(v)>>(s)))
00051 #define si(to,i,v,s) (((char*)(to))[i]=((__libelf_i32_t)(v)>>(s)))
00052
00053 #define __store_u16L(to,v) \
00054 (su(to,1,v,8), su(to,0,v,0))
00055 #define __store_u16M(to,v) \
00056 (su(to,0,v,8), su(to,1,v,0))
00057 #define __store_i16L(to,v) \
00058 (si(to,1,v,8), si(to,0,v,0))
00059 #define __store_i16M(to,v) \
00060 (si(to,0,v,8), si(to,1,v,0))
00061
00062 #define __store_u32L(to,v) \
00063 (su(to,3,v,24), su(to,2,v,16), su(to,1,v,8), su(to,0,v,0))
00064 #define __store_u32M(to,v) \
00065 (su(to,0,v,24), su(to,1,v,16), su(to,2,v,8), su(to,3,v,0))
00066 #define __store_i32L(to,v) \
00067 (si(to,3,v,24), si(to,2,v,16), si(to,1,v,8), si(to,0,v,0))
00068 #define __store_i32M(to,v) \
00069 (si(to,0,v,24), si(to,1,v,16), si(to,2,v,8), si(to,3,v,0))
00070
00071 #if __LIBELF64
00072
00073
00074
00075
00076 extern __libelf_u64_t _elf_load_u64L(const unsigned char *from);
00077 extern __libelf_u64_t _elf_load_u64M(const unsigned char *from);
00078 extern __libelf_i64_t _elf_load_i64L(const unsigned char *from);
00079 extern __libelf_i64_t _elf_load_i64M(const unsigned char *from);
00080 extern void _elf_store_u64L(unsigned char *to, __libelf_u64_t v);
00081 extern void _elf_store_u64M(unsigned char *to, __libelf_u64_t v);
00082 extern void _elf_store_i64L(unsigned char *to, __libelf_u64_t v);
00083 extern void _elf_store_i64M(unsigned char *to, __libelf_u64_t v);
00084
00085
00086
00087
00088 #define __load_u64L _elf_load_u64L
00089 #define __load_u64M _elf_load_u64M
00090 #define __load_i64L _elf_load_i64L
00091 #define __load_i64M _elf_load_i64M
00092 #define __store_u64L _elf_store_u64L
00093 #define __store_u64M _elf_store_u64M
00094 #define __store_i64L _elf_store_i64L
00095 #define __store_i64M _elf_store_i64M
00096
00097 #endif
00098
00099 #endif