Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / fs / hfsplus / include / swab.h
1 /*
2  * libhfs - library for reading and writing Macintosh HFS volumes
3  *
4  * Copyright (C) 2000 Klaus Halfmann <klaus.halfmann@feri.de>
5  * Original work 1996-1998 Robert Leslie <rob@mars.org>
6  *
7  * This file defines some byte swapping function. I did not find this
8  * in any standard or linux way.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23  * MA 02110-1301, USA.
24  *
25  * $Id: swab.h,v 1.1.1.1 2002/03/05 19:50:29 klaus Exp $
26  */
27
28 #include "config.h"
29 #include "libc/byteorder.h"
30
31  /* basic fuction:
32     value = swab_inc(ptr);
33         ptr is afterwards incremented by sizeof(value)
34  */
35
36 #ifndef CONFIG_BIG_ENDIAN
37
38 #define bswabU16(val) __bswap16(val)
39
40 #define bswabU16_inc(ptr) (__extension__ ({ UInt16 v=__bswap16(*((UInt16*) (ptr))); ptr+=sizeof(UInt16);v;}))
41 #define bswabU32_inc(ptr) (__extension__ ({ UInt32 v=__bswap32(*((UInt32*) (ptr))); ptr+=sizeof(UInt32);v;}))
42 #define bswabU64_inc(ptr) (__extension__ ({ UInt64 v=__bswap64(*((UInt64*) (ptr))); ptr+=sizeof(UInt64);v;}))
43
44 #define bstoreU16_inc(ptr, val) do {(*((UInt16*) (ptr))) = __bswap16(val); ptr+=sizeof(UInt16);} while (0)
45 #define bstoreU32_inc(ptr, val) do {(*((UInt32*) (ptr))) = __bswap32(val); ptr+=sizeof(UInt32);} while (0)
46 #define bstoreU64_inc(ptr, val) do {(*((UInt64*) (ptr))) = __bswap64(val); ptr+=sizeof(UInt64);} while (0)
47
48 #else // BYTE_ORDER == BIG_ENDIAN
49
50 #define bswabU16(val) val
51
52 #define bswabU16_inc(ptr) (__extension__ ({ UInt16 v=(*((UInt16*) (ptr))); ptr+=sizeof(UInt16);v;}))
53 #define bswabU32_inc(ptr) (__extension__ ({ UInt32 v=(*((UInt32*) (ptr))); ptr+=sizeof(UInt32);v;}))
54 #define bswabU64_inc(ptr) (__extension__ ({ UInt64 v=(*((UInt64*) (ptr))); ptr+=sizeof(UInt64);v;}))
55
56 #define bstoreU16_inc(ptr, val) do {(*((UInt16*) (ptr))) = val; ptr+=sizeof(UInt16);} while (0)
57 #define bstoreU32_inc(ptr, val) do {(*((UInt32*) (ptr))) = val; ptr+=sizeof(UInt32);} while (0)
58 #define bstoreU64_inc(ptr, val) do {(*((UInt64*) (ptr))) = val; ptr+=sizeof(UInt64);} while (0)
59
60 #endif
61
62 /* for the sake of compleetness and readability */
63 #define bswabU8_inc(ptr)        (__extension__ ({ UInt8 v=(*((UInt8*) (ptr))); ptr+=sizeof(UInt8);v;}))
64 #define bstoreU8_inc(ptr,val)   do {(*((UInt8*) (ptr))) = val; ptr+=sizeof(UInt8);} while (0)