1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #ifndef _SIM_ENDIAN_C_
26 #define _SIM_ENDIAN_C_
28 #include "sim-basics.h"
29 #include "sim-assert.h"
34 #define _SWAP_1(SET,RAW) SET (RAW)
37 #if !defined(_SWAP_2) && (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && defined(htons)
38 #define _SWAP_2(SET,RAW) SET htons (RAW)
42 #define _SWAP_2(SET,RAW) SET (((RAW) >> 8) | ((RAW) << 8))
45 #if !defined(_SWAP_4) && (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && defined(htonl)
46 #define _SWAP_4(SET,RAW) SET htonl (RAW)
50 #define _SWAP_4(SET,RAW) SET (((RAW) << 24) | (((RAW) & 0xff00) << 8) | (((RAW) & 0xff0000) >> 8) | ((RAW) >> 24))
54 #define _SWAP_8(SET,RAW) \
55 union { unsigned_8 dword; unsigned_4 words[2]; } in, out; \
57 _SWAP_4 (out.words[0] =, in.words[1]); \
58 _SWAP_4 (out.words[1] =, in.words[0]); \
63 #define _SWAP_16(SET,RAW) \
64 union { unsigned_16 word; unsigned_4 words[4]; } in, out; \
66 _SWAP_4 (out.words[0] =, in.words[3]); \
67 _SWAP_4 (out.words[1] =, in.words[2]); \
68 _SWAP_4 (out.words[2] =, in.words[1]); \
69 _SWAP_4 (out.words[3] =, in.words[0]); \
75 #include "sim-n-endian.h"
79 #include "sim-n-endian.h"
83 #include "sim-n-endian.h"
87 #include "sim-n-endian.h"
91 #include "sim-n-endian.h"
97 sim_endian_split_16 (unsigned_16 word
, int w
)
99 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
101 return word
.a
[1 - w
];
112 sim_endian_join_16 (unsigned_8 h
, unsigned_8 l
)
116 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
131 #endif /* _SIM_ENDIAN_C_ */