1 /* Support code for various pieces of CGEN simulators.
2 Copyright (C) 1996-2016 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/>. */
25 #define MEMOPS_DEFINE_INLINE
28 #define SEMOPS_DEFINE_INLINE
31 const char * const mode_names[] = {
46 0, /* MODE_TARGET_MAX */
52 /* Opcode table for virtual insns used by the simulator. */
54 #define V CGEN_ATTR_MASK (CGEN_INSN_VIRTUAL)
56 static const CGEN_IBASE virtual_insn_entries[] =
59 VIRTUAL_INSN_X_INVALID, "--invalid--", NULL, 0, { V, { 0 } }
62 VIRTUAL_INSN_X_BEFORE, "--before--", NULL, 0, { V, { 0 } }
65 VIRTUAL_INSN_X_AFTER, "--after--", NULL, 0, { V, { 0 } }
68 VIRTUAL_INSN_X_BEGIN, "--begin--", NULL, 0, { V, { 0 } }
71 VIRTUAL_INSN_X_CHAIN, "--chain--", NULL, 0, { V, { 0 } }
74 VIRTUAL_INSN_X_CTI_CHAIN, "--cti-chain--", NULL, 0, { V, { 0 } }
80 const CGEN_INSN cgen_virtual_insn_table[] =
82 { & virtual_insn_entries[0] },
83 { & virtual_insn_entries[1] },
84 { & virtual_insn_entries[2] },
85 { & virtual_insn_entries[3] },
86 { & virtual_insn_entries[4] },
87 { & virtual_insn_entries[5] }
90 /* Initialize cgen things.
91 This is called after sim_post_argv_init. */
94 cgen_init (SIM_DESC sd)
98 /* If no profiling or tracing has been enabled, run in fast mode. */
102 for (c = 0; c < MAX_NR_PROCESSORS; ++c)
104 SIM_CPU *cpu = STATE_CPU (sd, c);
106 for (i = 0; i < MAX_PROFILE_VALUES; ++i)
107 if (CPU_PROFILE_FLAGS (cpu) [i])
112 for (i = 0; i < MAX_TRACE_VALUES; ++i)
113 if (CPU_TRACE_FLAGS (cpu) [i])
121 STATE_RUN_FAST_P (sd) = run_fast_p;
125 /* Return the name of insn number I. */
128 cgen_insn_name (SIM_CPU *cpu, int i)
130 return CGEN_INSN_NAME ((* CPU_GET_IDATA (cpu)) ((cpu), (i)));
133 /* Return the maximum number of extra bytes required for a SIM_CPU struct. */
136 cgen_cpu_max_extra_bytes (void)
141 for (i = 0; sim_machs[i] != 0; ++i)
143 int size = IMP_PROPS_SIM_CPU_SIZE (MACH_IMP_PROPS (sim_machs[i]));
153 make_struct_di (hi, lo)
167 SI ahi = GETHIDI (a);
168 SI alo = GETLODI (a);
169 SI bhi = GETHIDI (b);
170 SI blo = GETLODI (b);
171 return MAKEDI (ahi & bhi, alo & blo);
178 SI ahi = GETHIDI (a);
179 SI alo = GETLODI (a);
180 SI bhi = GETHIDI (b);
181 SI blo = GETLODI (b);
182 return MAKEDI (ahi | bhi, alo | blo);
189 USI ahi = GETHIDI (a);
190 USI alo = GETLODI (a);
191 USI bhi = GETHIDI (b);
192 USI blo = GETLODI (b);
194 return MAKEDI (ahi + bhi + (x < alo), x);
201 USI ahi = GETHIDI (a);
202 USI alo = GETLODI (a);
203 USI bhi = GETHIDI (b);
204 USI blo = GETLODI (b);
213 #define SI_TYPE_SIZE 32
214 #define BITS4 (SI_TYPE_SIZE / 4)
215 #define ll_B (1L << (SI_TYPE_SIZE / 2))
216 #define ll_lowpart(t) ((USI) (t) % ll_B)
217 #define ll_highpart(t) ((USI) (t) / ll_B)
218 x1 += ll_highpart (x0); /* this can't give carry */
219 x1 += x2; /* but this indeed can */
220 if (x1 < x2) /* did we get it? */
221 x3 += ll_B; /* yes, add it in the proper pos. */
223 rhi = x3 + ll_highpart (x1);
224 rlo = ll_lowpart (x1) * ll_B + ll_lowpart (x0);
225 return MAKEDI (rhi + (alo * bhi) + (ahi * blo), rlo);
233 USI hi = GETHIDI (val);
234 USI lo = GETLODI (val);
235 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
236 return MAKEDI ((hi << shift) | (lo >> (32 - shift)), lo << shift);
244 SI hi = GETHIDI (val);
245 USI lo = GETLODI (val);
246 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
247 return MAKEDI ((hi << shift) | (lo >> (32 - shift)), lo << shift);
255 SI hi = GETHIDI (val);
256 USI lo = GETLODI (val);
257 /* We use SRASI because the result is implementation defined if hi < 0. */
258 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
259 return MAKEDI (SRASI (hi, shift), (hi << (32 - shift)) | (lo >> shift));
266 SI ahi = GETHIDI (a);
267 USI alo = GETLODI (a);
268 SI bhi = GETHIDI (b);
269 USI blo = GETLODI (b);
281 SI ahi = GETHIDI (a);
282 USI alo = GETLODI (a);
283 SI bhi = GETHIDI (b);
284 USI blo = GETLODI (b);
297 return MAKEDI (-1, val);
299 return MAKEDI (0, val);
307 return MAKEDI (-1, val);
309 return MAKEDI (0, val);
316 return GETLODI (val);
319 #endif /* DI_FN_SUPPORT */
328 int remain = 8 - shift;
329 int mask = (1 << shift) - 1;
330 QI result = (val & mask) << remain;
331 mask = (1 << remain) - 1;
332 result |= (val >> shift) & mask;
345 int remain = 8 - shift;
346 int mask = (1 << remain) - 1;
347 QI result = (val & mask) << shift;
348 mask = (1 << shift) - 1;
349 result |= (val >> remain) & mask;
362 int remain = 16 - shift;
363 int mask = (1 << shift) - 1;
364 HI result = (val & mask) << remain;
365 mask = (1 << remain) - 1;
366 result |= (val >> shift) & mask;
379 int remain = 16 - shift;
380 int mask = (1 << remain) - 1;
381 HI result = (val & mask) << shift;
382 mask = (1 << shift) - 1;
383 result |= (val >> remain) & mask;
396 int remain = 32 - shift;
397 int mask = (1 << shift) - 1;
398 SI result = (val & mask) << remain;
399 mask = (1 << remain) - 1;
400 result |= (val >> shift) & mask;
413 int remain = 32 - shift;
414 int mask = (1 << remain) - 1;
415 SI result = (val & mask) << shift;
416 mask = (1 << shift) - 1;
417 result |= (val >> remain) & mask;
424 /* Emit an error message from CGEN RTL. */
427 cgen_rtx_error (SIM_CPU *cpu, const char * msg)
429 SIM_DESC sd = CPU_STATE (cpu);
431 sim_io_printf (sd, msg);
432 sim_io_printf (sd, "\n");
434 sim_engine_halt (sd, cpu, NULL, CPU_PC_GET (cpu), sim_stopped, SIM_SIGTRAP);