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. */
27 #define MEMOPS_DEFINE_INLINE
30 #define SEMOPS_DEFINE_INLINE
33 const char * const cgen_mode_names
[] = {
48 0, /* MODE_TARGET_MAX */
54 /* Opcode table for virtual insns used by the simulator. */
56 #define V CGEN_ATTR_MASK (CGEN_INSN_VIRTUAL)
58 static const CGEN_IBASE virtual_insn_entries
[] =
61 VIRTUAL_INSN_X_INVALID
, "--invalid--", NULL
, 0, { V
, {} }
64 VIRTUAL_INSN_X_BEFORE
, "--before--", NULL
, 0, { V
, {} }
67 VIRTUAL_INSN_X_AFTER
, "--after--", NULL
, 0, { V
, {} }
70 VIRTUAL_INSN_X_BEGIN
, "--begin--", NULL
, 0, { V
, {} }
73 VIRTUAL_INSN_X_CHAIN
, "--chain--", NULL
, 0, { V
, {} }
76 VIRTUAL_INSN_X_CTI_CHAIN
, "--cti-chain--", NULL
, 0, { V
, {} }
82 const CGEN_INSN cgen_virtual_insn_table
[] =
84 { & virtual_insn_entries
[0] },
85 { & virtual_insn_entries
[1] },
86 { & virtual_insn_entries
[2] },
87 { & virtual_insn_entries
[3] },
88 { & virtual_insn_entries
[4] },
89 { & virtual_insn_entries
[5] }
92 /* Initialize cgen things.
93 This is called after sim_post_argv_init. */
96 cgen_init (SIM_DESC sd
)
100 /* If no profiling or tracing has been enabled, run in fast mode. */
104 for (c
= 0; c
< MAX_NR_PROCESSORS
; ++c
)
106 SIM_CPU
*cpu
= STATE_CPU (sd
, c
);
108 for (i
= 0; i
< MAX_PROFILE_VALUES
; ++i
)
109 if (CPU_PROFILE_FLAGS (cpu
) [i
])
114 for (i
= 0; i
< MAX_TRACE_VALUES
; ++i
)
115 if (CPU_TRACE_FLAGS (cpu
) [i
])
123 STATE_RUN_FAST_P (sd
) = run_fast_p
;
127 /* Return the name of insn number I. */
130 cgen_insn_name (SIM_CPU
*cpu
, int i
)
132 return CGEN_INSN_NAME ((* CPU_GET_IDATA (cpu
)) ((cpu
), (i
)));
135 /* Return the maximum number of extra bytes required for a SIM_CPU struct. */
138 cgen_cpu_max_extra_bytes (void)
143 for (i
= 0; sim_machs
[i
] != 0; ++i
)
145 int size
= IMP_PROPS_SIM_CPU_SIZE (MACH_IMP_PROPS (sim_machs
[i
]));
155 make_struct_di (hi
, lo
)
169 SI ahi
= GETHIDI (a
);
170 SI alo
= GETLODI (a
);
171 SI bhi
= GETHIDI (b
);
172 SI blo
= GETLODI (b
);
173 return MAKEDI (ahi
& bhi
, alo
& blo
);
180 SI ahi
= GETHIDI (a
);
181 SI alo
= GETLODI (a
);
182 SI bhi
= GETHIDI (b
);
183 SI blo
= GETLODI (b
);
184 return MAKEDI (ahi
| bhi
, alo
| blo
);
191 USI ahi
= GETHIDI (a
);
192 USI alo
= GETLODI (a
);
193 USI bhi
= GETHIDI (b
);
194 USI blo
= GETLODI (b
);
196 return MAKEDI (ahi
+ bhi
+ (x
< alo
), x
);
203 USI ahi
= GETHIDI (a
);
204 USI alo
= GETLODI (a
);
205 USI bhi
= GETHIDI (b
);
206 USI blo
= GETLODI (b
);
215 #define SI_TYPE_SIZE 32
216 #define BITS4 (SI_TYPE_SIZE / 4)
217 #define ll_B (1L << (SI_TYPE_SIZE / 2))
218 #define ll_lowpart(t) ((USI) (t) % ll_B)
219 #define ll_highpart(t) ((USI) (t) / ll_B)
220 x1
+= ll_highpart (x0
); /* this can't give carry */
221 x1
+= x2
; /* but this indeed can */
222 if (x1
< x2
) /* did we get it? */
223 x3
+= ll_B
; /* yes, add it in the proper pos. */
225 rhi
= x3
+ ll_highpart (x1
);
226 rlo
= ll_lowpart (x1
) * ll_B
+ ll_lowpart (x0
);
227 return MAKEDI (rhi
+ (alo
* bhi
) + (ahi
* blo
), rlo
);
235 USI hi
= GETHIDI (val
);
236 USI lo
= GETLODI (val
);
237 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
238 return MAKEDI ((hi
<< shift
) | (lo
>> (32 - shift
)), lo
<< shift
);
246 SI hi
= GETHIDI (val
);
247 USI lo
= GETLODI (val
);
248 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
249 return MAKEDI ((hi
<< shift
) | (lo
>> (32 - shift
)), lo
<< shift
);
257 SI hi
= GETHIDI (val
);
258 USI lo
= GETLODI (val
);
259 /* We use SRASI because the result is implementation defined if hi < 0. */
260 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
261 return MAKEDI (SRASI (hi
, shift
), (hi
<< (32 - shift
)) | (lo
>> shift
));
268 SI ahi
= GETHIDI (a
);
269 USI alo
= GETLODI (a
);
270 SI bhi
= GETHIDI (b
);
271 USI blo
= GETLODI (b
);
283 SI ahi
= GETHIDI (a
);
284 USI alo
= GETLODI (a
);
285 SI bhi
= GETHIDI (b
);
286 USI blo
= GETLODI (b
);
299 return MAKEDI (-1, val
);
301 return MAKEDI (0, val
);
309 return MAKEDI (-1, val
);
311 return MAKEDI (0, val
);
318 return GETLODI (val
);
321 #endif /* DI_FN_SUPPORT */
324 RORQI (QI val
, int shift
)
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
;
339 ROLQI (QI val
, int shift
)
343 int remain
= 8 - shift
;
344 int mask
= (1 << remain
) - 1;
345 QI result
= (val
& mask
) << shift
;
346 mask
= (1 << shift
) - 1;
347 result
|= (val
>> remain
) & mask
;
354 RORHI (HI val
, int shift
)
358 int remain
= 16 - shift
;
359 int mask
= (1 << shift
) - 1;
360 HI result
= (val
& mask
) << remain
;
361 mask
= (1 << remain
) - 1;
362 result
|= (val
>> shift
) & mask
;
369 ROLHI (HI val
, int shift
)
373 int remain
= 16 - shift
;
374 int mask
= (1 << remain
) - 1;
375 HI result
= (val
& mask
) << shift
;
376 mask
= (1 << shift
) - 1;
377 result
|= (val
>> remain
) & mask
;
384 RORSI (SI val
, int shift
)
388 int remain
= 32 - shift
;
389 int mask
= (1 << shift
) - 1;
390 SI result
= (val
& mask
) << remain
;
391 mask
= (1 << remain
) - 1;
392 result
|= (val
>> shift
) & mask
;
399 ROLSI (SI val
, int shift
)
403 int remain
= 32 - shift
;
404 int mask
= (1 << remain
) - 1;
405 SI result
= (val
& mask
) << shift
;
406 mask
= (1 << shift
) - 1;
407 result
|= (val
>> remain
) & mask
;
414 /* Emit an error message from CGEN RTL. */
417 cgen_rtx_error (SIM_CPU
*cpu
, const char * msg
)
419 SIM_DESC sd
= CPU_STATE (cpu
);
421 sim_io_printf (sd
, "%s", msg
);
422 sim_io_printf (sd
, "\n");
424 sim_engine_halt (sd
, cpu
, NULL
, CPU_PC_GET (cpu
), sim_stopped
, SIM_SIGTRAP
);