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
]));
124 SI ahi
= GETHIDI (a
);
125 SI alo
= GETLODI (a
);
126 SI bhi
= GETHIDI (b
);
127 SI blo
= GETLODI (b
);
128 return MAKEDI (ahi
& bhi
, alo
& blo
);
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 USI ahi
= GETHIDI (a
);
147 USI alo
= GETLODI (a
);
148 USI bhi
= GETHIDI (b
);
149 USI blo
= GETLODI (b
);
151 return MAKEDI (ahi
+ bhi
+ (x
< alo
), x
);
158 USI ahi
= GETHIDI (a
);
159 USI alo
= GETLODI (a
);
160 USI bhi
= GETHIDI (b
);
161 USI blo
= GETLODI (b
);
170 #define SI_TYPE_SIZE 32
171 #define BITS4 (SI_TYPE_SIZE / 4)
172 #define ll_B (1L << (SI_TYPE_SIZE / 2))
173 #define ll_lowpart(t) ((USI) (t) % ll_B)
174 #define ll_highpart(t) ((USI) (t) / ll_B)
175 x1
+= ll_highpart (x0
); /* this can't give carry */
176 x1
+= x2
; /* but this indeed can */
177 if (x1
< x2
) /* did we get it? */
178 x3
+= ll_B
; /* yes, add it in the proper pos. */
180 rhi
= x3
+ ll_highpart (x1
);
181 rlo
= ll_lowpart (x1
) * ll_B
+ ll_lowpart (x0
);
182 return MAKEDI (rhi
+ (alo
* bhi
) + (ahi
* blo
), rlo
);
190 USI hi
= GETHIDI (val
);
191 USI lo
= GETLODI (val
);
192 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
193 return MAKEDI ((hi
<< shift
) | (lo
>> (32 - shift
)), lo
<< shift
);
201 SI 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 /* We use SRASI because the result is implementation defined if hi < 0. */
215 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
216 return MAKEDI (SRASI (hi
, shift
), (hi
<< (32 - shift
)) | (lo
>> shift
));
223 SI ahi
= GETHIDI (a
);
224 USI alo
= GETLODI (a
);
225 SI bhi
= GETHIDI (b
);
226 USI blo
= GETLODI (b
);
238 SI ahi
= GETHIDI (a
);
239 USI alo
= GETLODI (a
);
240 SI bhi
= GETHIDI (b
);
241 USI blo
= GETLODI (b
);
254 return MAKEDI (-1, val
);
256 return MAKEDI (0, val
);
264 return MAKEDI (-1, val
);
266 return MAKEDI (0, val
);
273 return GETLODI (val
);
276 #endif /* DI_FN_SUPPORT */
279 RORQI (QI val
, int shift
)
283 int remain
= 8 - shift
;
284 int mask
= (1 << shift
) - 1;
285 QI result
= (val
& mask
) << remain
;
286 mask
= (1 << remain
) - 1;
287 result
|= (val
>> shift
) & mask
;
294 ROLQI (QI val
, int shift
)
298 int remain
= 8 - shift
;
299 int mask
= (1 << remain
) - 1;
300 QI result
= (val
& mask
) << shift
;
301 mask
= (1 << shift
) - 1;
302 result
|= (val
>> remain
) & mask
;
309 RORHI (HI val
, int shift
)
313 int remain
= 16 - shift
;
314 int mask
= (1 << shift
) - 1;
315 HI result
= (val
& mask
) << remain
;
316 mask
= (1 << remain
) - 1;
317 result
|= (val
>> shift
) & mask
;
324 ROLHI (HI val
, int shift
)
328 int remain
= 16 - shift
;
329 int mask
= (1 << remain
) - 1;
330 HI result
= (val
& mask
) << shift
;
331 mask
= (1 << shift
) - 1;
332 result
|= (val
>> remain
) & mask
;
339 RORSI (SI val
, int shift
)
343 int remain
= 32 - shift
;
344 int mask
= (1 << shift
) - 1;
345 SI result
= (val
& mask
) << remain
;
346 mask
= (1 << remain
) - 1;
347 result
|= (val
>> shift
) & mask
;
354 ROLSI (SI val
, int shift
)
358 int remain
= 32 - shift
;
359 int mask
= (1 << remain
) - 1;
360 SI result
= (val
& mask
) << shift
;
361 mask
= (1 << shift
) - 1;
362 result
|= (val
>> remain
) & mask
;
369 /* Emit an error message from CGEN RTL. */
372 cgen_rtx_error (SIM_CPU
*cpu
, const char * msg
)
374 SIM_DESC sd
= CPU_STATE (cpu
);
376 sim_io_printf (sd
, "%s", msg
);
377 sim_io_printf (sd
, "\n");
379 sim_engine_halt (sd
, cpu
, NULL
, CPU_PC_GET (cpu
), sim_stopped
, SIM_SIGTRAP
);