1 /* Support code for various pieces of CGEN simulators.
2 Copyright (C) 1996-2021 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This must come before any other includes. */
25 #include "sim-signal.h"
28 #define MEMOPS_DEFINE_INLINE
31 #define SEMOPS_DEFINE_INLINE
34 const char * const cgen_mode_names
[] = {
49 0, /* MODE_TARGET_MAX */
55 /* Opcode table for virtual insns used by the simulator. */
57 #define V CGEN_ATTR_MASK (CGEN_INSN_VIRTUAL)
59 static const CGEN_IBASE virtual_insn_entries
[] =
62 VIRTUAL_INSN_X_INVALID
, "--invalid--", NULL
, 0, { V
, {} }
65 VIRTUAL_INSN_X_BEFORE
, "--before--", NULL
, 0, { V
, {} }
68 VIRTUAL_INSN_X_AFTER
, "--after--", NULL
, 0, { V
, {} }
71 VIRTUAL_INSN_X_BEGIN
, "--begin--", NULL
, 0, { V
, {} }
74 VIRTUAL_INSN_X_CHAIN
, "--chain--", NULL
, 0, { V
, {} }
77 VIRTUAL_INSN_X_CTI_CHAIN
, "--cti-chain--", NULL
, 0, { V
, {} }
83 const CGEN_INSN cgen_virtual_insn_table
[] =
85 { & virtual_insn_entries
[0] },
86 { & virtual_insn_entries
[1] },
87 { & virtual_insn_entries
[2] },
88 { & virtual_insn_entries
[3] },
89 { & virtual_insn_entries
[4] },
90 { & virtual_insn_entries
[5] }
93 /* Return the name of insn number I. */
96 cgen_insn_name (SIM_CPU
*cpu
, int i
)
98 return CGEN_INSN_NAME ((* CPU_GET_IDATA (cpu
)) ((cpu
), (i
)));
101 /* Return the maximum number of extra bytes required for a SIM_CPU struct. */
104 cgen_cpu_max_extra_bytes (void)
109 for (i
= 0; sim_machs
[i
] != 0; ++i
)
111 int size
= IMP_PROPS_SIM_CPU_SIZE (MACH_IMP_PROPS (sim_machs
[i
]));
121 make_struct_di (hi
, lo
)
135 SI ahi
= GETHIDI (a
);
136 SI alo
= GETLODI (a
);
137 SI bhi
= GETHIDI (b
);
138 SI blo
= GETLODI (b
);
139 return MAKEDI (ahi
& bhi
, alo
& blo
);
146 SI ahi
= GETHIDI (a
);
147 SI alo
= GETLODI (a
);
148 SI bhi
= GETHIDI (b
);
149 SI blo
= GETLODI (b
);
150 return MAKEDI (ahi
| bhi
, alo
| blo
);
157 USI ahi
= GETHIDI (a
);
158 USI alo
= GETLODI (a
);
159 USI bhi
= GETHIDI (b
);
160 USI blo
= GETLODI (b
);
162 return MAKEDI (ahi
+ bhi
+ (x
< alo
), x
);
169 USI ahi
= GETHIDI (a
);
170 USI alo
= GETLODI (a
);
171 USI bhi
= GETHIDI (b
);
172 USI blo
= GETLODI (b
);
181 #define SI_TYPE_SIZE 32
182 #define BITS4 (SI_TYPE_SIZE / 4)
183 #define ll_B (1L << (SI_TYPE_SIZE / 2))
184 #define ll_lowpart(t) ((USI) (t) % ll_B)
185 #define ll_highpart(t) ((USI) (t) / ll_B)
186 x1
+= ll_highpart (x0
); /* this can't give carry */
187 x1
+= x2
; /* but this indeed can */
188 if (x1
< x2
) /* did we get it? */
189 x3
+= ll_B
; /* yes, add it in the proper pos. */
191 rhi
= x3
+ ll_highpart (x1
);
192 rlo
= ll_lowpart (x1
) * ll_B
+ ll_lowpart (x0
);
193 return MAKEDI (rhi
+ (alo
* bhi
) + (ahi
* blo
), rlo
);
201 USI hi
= GETHIDI (val
);
202 USI lo
= GETLODI (val
);
203 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
204 return MAKEDI ((hi
<< shift
) | (lo
>> (32 - shift
)), lo
<< shift
);
212 SI hi
= GETHIDI (val
);
213 USI lo
= GETLODI (val
);
214 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
215 return MAKEDI ((hi
<< shift
) | (lo
>> (32 - shift
)), lo
<< shift
);
223 SI hi
= GETHIDI (val
);
224 USI lo
= GETLODI (val
);
225 /* We use SRASI because the result is implementation defined if hi < 0. */
226 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
227 return MAKEDI (SRASI (hi
, shift
), (hi
<< (32 - shift
)) | (lo
>> shift
));
234 SI ahi
= GETHIDI (a
);
235 USI alo
= GETLODI (a
);
236 SI bhi
= GETHIDI (b
);
237 USI blo
= GETLODI (b
);
249 SI ahi
= GETHIDI (a
);
250 USI alo
= GETLODI (a
);
251 SI bhi
= GETHIDI (b
);
252 USI blo
= GETLODI (b
);
265 return MAKEDI (-1, val
);
267 return MAKEDI (0, val
);
275 return MAKEDI (-1, val
);
277 return MAKEDI (0, val
);
284 return GETLODI (val
);
287 #endif /* DI_FN_SUPPORT */
290 RORQI (QI val
, int shift
)
294 int remain
= 8 - shift
;
295 int mask
= (1 << shift
) - 1;
296 QI result
= (val
& mask
) << remain
;
297 mask
= (1 << remain
) - 1;
298 result
|= (val
>> shift
) & mask
;
305 ROLQI (QI val
, int shift
)
309 int remain
= 8 - shift
;
310 int mask
= (1 << remain
) - 1;
311 QI result
= (val
& mask
) << shift
;
312 mask
= (1 << shift
) - 1;
313 result
|= (val
>> remain
) & mask
;
320 RORHI (HI val
, int shift
)
324 int remain
= 16 - shift
;
325 int mask
= (1 << shift
) - 1;
326 HI result
= (val
& mask
) << remain
;
327 mask
= (1 << remain
) - 1;
328 result
|= (val
>> shift
) & mask
;
335 ROLHI (HI val
, int shift
)
339 int remain
= 16 - shift
;
340 int mask
= (1 << remain
) - 1;
341 HI result
= (val
& mask
) << shift
;
342 mask
= (1 << shift
) - 1;
343 result
|= (val
>> remain
) & mask
;
350 RORSI (SI val
, int shift
)
354 int remain
= 32 - shift
;
355 int mask
= (1 << shift
) - 1;
356 SI result
= (val
& mask
) << remain
;
357 mask
= (1 << remain
) - 1;
358 result
|= (val
>> shift
) & mask
;
365 ROLSI (SI val
, int shift
)
369 int remain
= 32 - shift
;
370 int mask
= (1 << remain
) - 1;
371 SI result
= (val
& mask
) << shift
;
372 mask
= (1 << shift
) - 1;
373 result
|= (val
>> remain
) & mask
;
380 /* Emit an error message from CGEN RTL. */
383 cgen_rtx_error (SIM_CPU
*cpu
, const char * msg
)
385 SIM_DESC sd
= CPU_STATE (cpu
);
387 sim_io_printf (sd
, "%s", msg
);
388 sim_io_printf (sd
, "\n");
390 sim_engine_halt (sd
, cpu
, NULL
, CPU_PC_GET (cpu
), sim_stopped
, SIM_SIGTRAP
);