Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / sim / common / sim-endian.c
CommitLineData
b85e4829
AC
1/* The common simulator framework for GDB, the GNU Debugger.
2
88b9d363 3 Copyright 2002-2022 Free Software Foundation, Inc.
b85e4829
AC
4
5 Contributed by Andrew Cagney and Red Hat.
6
7 This file is part of GDB.
8
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
4744ac1b 11 the Free Software Foundation; either version 3 of the License, or
b85e4829
AC
12 (at your option) any later version.
13
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.
18
19 You should have received a copy of the GNU General Public License
4744ac1b 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22
23#ifndef _SIM_ENDIAN_C_
24#define _SIM_ENDIAN_C_
25
6df01ab8
MF
26/* This must come before any other includes. */
27#include "defs.h"
28
c906108c
SS
29#include "sim-basics.h"
30#include "sim-assert.h"
c906108c
SS
31
32
33#if !defined(_SWAP_1)
34#define _SWAP_1(SET,RAW) SET (RAW)
35#endif
36
0cb8d851 37#if !defined(_SWAP_2) && (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE) && defined(htons)
c906108c
SS
38#define _SWAP_2(SET,RAW) SET htons (RAW)
39#endif
40
41#ifndef _SWAP_2
42#define _SWAP_2(SET,RAW) SET (((RAW) >> 8) | ((RAW) << 8))
43#endif
44
0cb8d851 45#if !defined(_SWAP_4) && (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE) && defined(htonl)
c906108c
SS
46#define _SWAP_4(SET,RAW) SET htonl (RAW)
47#endif
48
49#ifndef _SWAP_4
50#define _SWAP_4(SET,RAW) SET (((RAW) << 24) | (((RAW) & 0xff00) << 8) | (((RAW) & 0xff0000) >> 8) | ((RAW) >> 24))
51#endif
52
53#ifndef _SWAP_8
54#define _SWAP_8(SET,RAW) \
55 union { unsigned_8 dword; unsigned_4 words[2]; } in, out; \
56 in.dword = RAW; \
57 _SWAP_4 (out.words[0] =, in.words[1]); \
58 _SWAP_4 (out.words[1] =, in.words[0]); \
59 SET out.dword;
60#endif
61
62#ifndef _SWAP_16
63#define _SWAP_16(SET,RAW) \
64 union { unsigned_16 word; unsigned_4 words[4]; } in, out; \
65 in.word = (RAW); \
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]); \
70 SET out.word;
71#endif
72
73
74#define N 1
75#include "sim-n-endian.h"
76#undef N
77
78#define N 2
79#include "sim-n-endian.h"
80#undef N
81
82#define N 4
83#include "sim-n-endian.h"
84#undef N
85
86#define N 8
87#include "sim-n-endian.h"
88#undef N
89
90#define N 16
91#include "sim-n-endian.h"
92#undef N
93
94
95INLINE_SIM_ENDIAN\
96(unsigned_8)
97sim_endian_split_16 (unsigned_16 word, int w)
98{
0cb8d851 99 if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
c906108c
SS
100 {
101 return word.a[1 - w];
102 }
103 else
104 {
105 return word.a[w];
106 }
107}
108
109
110INLINE_SIM_ENDIAN\
111(unsigned_16)
112sim_endian_join_16 (unsigned_8 h, unsigned_8 l)
113
114{
115 unsigned_16 word;
0cb8d851 116 if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
c906108c
SS
117 {
118 word.a[0] = l;
119 word.a[1] = h;
120 }
121 else
122 {
123 word.a[0] = h;
124 word.a[1] = l;
125 }
126 return word;
127}
128
129
130
131#endif /* _SIM_ENDIAN_C_ */
This page took 1.015432 seconds and 4 git commands to generate.