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. */
26 #error "N must be #defined"
31 #if defined(__STDC__) && defined(signed)
32 /* If signed were defined to be say __signed (ie, some versions of Linux),
33 then the signedN macro would not work correctly. If we have a standard
34 compiler, we have signed. */
38 /* NOTE: See end of file for #undef */
39 #define unsignedN XCONCAT2(unsigned,N)
40 #define signedN XCONCAT2(signed,N)
41 #define LSMASKn XCONCAT2(LSMASK,N)
42 #define MSMASKn XCONCAT2(MSMASK,N)
43 #define LSMASKEDn XCONCAT2(LSMASKED,N)
44 #define MSMASKEDn XCONCAT2(MSMASKED,N)
45 #define LSEXTRACTEDn XCONCAT2(LSEXTRACTED,N)
46 #define MSEXTRACTEDn XCONCAT2(MSEXTRACTED,N)
47 #define LSINSERTEDn XCONCAT2(LSINSERTED,N)
48 #define MSINSERTEDn XCONCAT2(MSINSERTED,N)
49 #define ROTn XCONCAT2(ROT,N)
50 #define ROTLn XCONCAT2(ROTL,N)
51 #define ROTRn XCONCAT2(ROTR,N)
52 #define MSSEXTn XCONCAT2(MSSEXT,N)
53 #define LSSEXTn XCONCAT2(LSSEXT,N)
55 /* TAGS: LSMASKED16 LSMASKED32 LSMASKED64 */
59 LSMASKEDn (unsignedN word
,
63 word
&= LSMASKn (start
, stop
);
67 /* TAGS: MSMASKED16 MSMASKED32 MSMASKED64 */
71 MSMASKEDn (unsignedN word
,
75 word
&= MSMASKn (start
, stop
);
79 /* TAGS: LSEXTRACTED16 LSEXTRACTED32 LSEXTRACTED64 */
83 LSEXTRACTEDn (unsignedN val
,
87 val
<<= (N
- 1 - start
); /* drop high bits */
88 val
>>= (N
- 1 - start
) + (stop
); /* drop low bits */
92 /* TAGS: MSEXTRACTED16 MSEXTRACTED32 MSEXTRACTED64 */
96 MSEXTRACTEDn (unsignedN val
,
100 val
<<= (start
); /* drop high bits */
101 val
>>= (start
) + (N
- 1 - stop
); /* drop low bits */
105 /* TAGS: LSINSERTED16 LSINSERTED32 LSINSERTED64 */
109 LSINSERTEDn (unsignedN val
,
114 val
&= LSMASKn (start
, stop
);
118 /* TAGS: MSINSERTED16 MSINSERTED32 MSINSERTED64 */
122 MSINSERTEDn (unsignedN val
,
126 val
<<= ((N
- 1) - stop
);
127 val
&= MSMASKn (start
, stop
);
131 /* TAGS: ROT16 ROT32 ROT64 */
139 return ROTRn (val
, shift
);
141 return ROTLn (val
, -shift
);
146 /* TAGS: ROTL16 ROTL32 ROTL64 */
150 ROTLn (unsignedN val
,
155 result
= (((val
) << (shift
)) | ((val
) >> ((N
)-(shift
))));
159 /* TAGS: ROTR16 ROTR32 ROTR64 */
163 ROTRn (unsignedN val
,
168 result
= (((val
) >> (shift
)) | ((val
) << ((N
)-(shift
))));
172 /* TAGS: LSSEXT16 LSSEXT32 LSSEXT64 */
176 LSSEXTn (signedN val
,
180 /* make the sign-bit most significant and then smear it back into
182 ASSERT (sign_bit
< N
);
183 shift
= ((N
- 1) - sign_bit
);
189 /* TAGS: MSSEXT16 MSSEXT32 MSSEXT64 */
193 MSSEXTn (signedN val
,
196 /* make the sign-bit most significant and then smear it back into
198 ASSERT (sign_bit
< N
);
205 /* NOTE: See start of file for #define */