Phoenix
Object-oriented orthogonally persistent operating system
|
00001 /* 00002 byteswap.h - functions and macros for byte swapping. 00003 Copyright (C) 1995 - 2001 Michael Riepe 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00018 */ 00019 00020 /* @(#) $Id: byteswap.h 153 2010-11-10 06:26:43Z vagran $ */ 00021 00022 #ifndef _BYTESWAP_H 00023 #define _BYTESWAP_H 00024 00025 #define lu(from,i,s) (((__libelf_u32_t)((unsigned char*)(from))[i])<<(s)) 00026 #define li(from,i,s) (((__libelf_i32_t)(( signed char*)(from))[i])<<(s)) 00027 00028 #define __load_u16L(from) ((__libelf_u32_t) \ 00029 (lu(from,1,8) | lu(from,0,0))) 00030 #define __load_u16M(from) ((__libelf_u32_t) \ 00031 (lu(from,0,8) | lu(from,1,0))) 00032 #define __load_i16L(from) ((__libelf_i32_t) \ 00033 (li(from,1,8) | lu(from,0,0))) 00034 #define __load_i16M(from) ((__libelf_i32_t) \ 00035 (li(from,0,8) | lu(from,1,0))) 00036 00037 #define __load_u32L(from) ((__libelf_u32_t) \ 00038 (lu(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0))) 00039 #define __load_u32M(from) ((__libelf_u32_t) \ 00040 (lu(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0))) 00041 #define __load_i32L(from) ((__libelf_i32_t) \ 00042 (li(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0))) 00043 #define __load_i32M(from) ((__libelf_i32_t) \ 00044 (li(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0))) 00045 00046 #define su(to,i,v,s) (((char*)(to))[i]=((__libelf_u32_t)(v)>>(s))) 00047 #define si(to,i,v,s) (((char*)(to))[i]=((__libelf_i32_t)(v)>>(s))) 00048 00049 #define __store_u16L(to,v) \ 00050 (su(to,1,v,8), su(to,0,v,0)) 00051 #define __store_u16M(to,v) \ 00052 (su(to,0,v,8), su(to,1,v,0)) 00053 #define __store_i16L(to,v) \ 00054 (si(to,1,v,8), si(to,0,v,0)) 00055 #define __store_i16M(to,v) \ 00056 (si(to,0,v,8), si(to,1,v,0)) 00057 00058 #define __store_u32L(to,v) \ 00059 (su(to,3,v,24), su(to,2,v,16), su(to,1,v,8), su(to,0,v,0)) 00060 #define __store_u32M(to,v) \ 00061 (su(to,0,v,24), su(to,1,v,16), su(to,2,v,8), su(to,3,v,0)) 00062 #define __store_i32L(to,v) \ 00063 (si(to,3,v,24), si(to,2,v,16), si(to,1,v,8), si(to,0,v,0)) 00064 #define __store_i32M(to,v) \ 00065 (si(to,0,v,24), si(to,1,v,16), si(to,2,v,8), si(to,3,v,0)) 00066 00067 #if __LIBELF64 00068 00069 /* 00070 * conversion functions from swap64.c 00071 */ 00072 extern __libelf_u64_t _elf_load_u64L(const unsigned char *from); 00073 extern __libelf_u64_t _elf_load_u64M(const unsigned char *from); 00074 extern __libelf_i64_t _elf_load_i64L(const unsigned char *from); 00075 extern __libelf_i64_t _elf_load_i64M(const unsigned char *from); 00076 extern void _elf_store_u64L(unsigned char *to, __libelf_u64_t v); 00077 extern void _elf_store_u64M(unsigned char *to, __libelf_u64_t v); 00078 extern void _elf_store_i64L(unsigned char *to, __libelf_u64_t v); 00079 extern void _elf_store_i64M(unsigned char *to, __libelf_u64_t v); 00080 00081 /* 00082 * aliases for existing conversion code 00083 */ 00084 #define __load_u64L _elf_load_u64L 00085 #define __load_u64M _elf_load_u64M 00086 #define __load_i64L _elf_load_i64L 00087 #define __load_i64M _elf_load_i64M 00088 #define __store_u64L _elf_store_u64L 00089 #define __store_u64M _elf_store_u64M 00090 #define __store_i64L _elf_store_i64L 00091 #define __store_i64M _elf_store_i64M 00092 00093 #endif /* __LIBELF64 */ 00094 00095 #endif /* _BYTESWAP_H */