Fix SWAP_8 and optimize it; print out the failing address if a signal is issued for...
[deliverable/binutils-gdb.git] / sim / ppc / ppc-endian.c
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 */
20
21
22 #ifndef _ENDIAN_C_
23 #define _ENDIAN_C_
24
25 #ifndef STATIC_INLINE_ENDIAN
26 #define STATIC_INLINE_ENDIAN STATIC_INLINE
27 #endif
28
29
30 #include "config.h"
31 #include "ppc-config.h"
32 #include "words.h"
33 #include "ppc-endian.h"
34 #include "sim_callbacks.h"
35
36 #if (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && WITH_NTOH
37 #define SWAP_2(SET,RAW) SET htons (RAW)
38 #endif
39
40 #ifndef SWAP_2
41 #define SWAP_2(SET,RAW) SET (((RAW) >> 8) | ((RAW) << 8))
42 #endif
43
44 #if !defined(SWAP_4) && (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && WITH_NTOH
45 #define SWAP_4(SET,RAW) SET htonl (RAW)
46 #endif
47
48 #ifndef SWAP_4
49 #define SWAP_4(SET,RAW) SET (((RAW) << 24) | (((RAW) & 0xff00) << 8) | (((RAW) & 0xff0000) >> 8) | ((RAW) >> 24))
50 #endif
51
52 #ifndef SWAP_8
53 #define SWAP_8(SET,RAW) \
54 union { unsigned_8 dword; unsigned_4 words[2]; } in, out; \
55 in.dword = RAW; \
56 SWAP_4 (out.words[0] =, in.words[1]); \
57 SWAP_4 (out.words[1] =, in.words[0]); \
58 SET out.dword;
59 #endif
60
61 #ifndef ENDIAN_N
62 #define ENDIAN_N(NAME,BYTE_SIZE) \
63 INLINE unsigned_##BYTE_SIZE \
64 endian_##NAME##_##BYTE_SIZE(unsigned_##BYTE_SIZE raw_in) \
65 { \
66 if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) { \
67 return raw_in; \
68 } \
69 else { \
70 SWAP_##BYTE_SIZE(return, raw_in); \
71 } \
72 }
73 #endif
74
75 ENDIAN_N(h2t, 2)
76 ENDIAN_N(h2t, 4)
77 ENDIAN_N(h2t, 8)
78 ENDIAN_N(t2h, 2)
79 ENDIAN_N(t2h, 4)
80 ENDIAN_N(t2h, 8)
81
82 #endif /* _ENDIAN_C_ */
This page took 0.030347 seconds and 4 git commands to generate.