Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / sim / common / cgen-utils.c
CommitLineData
c906108c 1/* Support code for various pieces of CGEN simulators.
88b9d363 2 Copyright (C) 1996-2022 Free Software Foundation, Inc.
c906108c
SS
3 Contributed by Cygnus Support.
4
5This file is part of GDB, the GNU debugger.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
4744ac1b
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
c906108c
SS
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
4744ac1b
JB
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
6df01ab8
MF
20/* This must come before any other includes. */
21#include "defs.h"
22
c906108c
SS
23#include "bfd.h"
24#include "sim-main.h"
1fef66b0 25#include "sim-signal.h"
c906108c
SS
26#include "dis-asm.h"
27
28#define MEMOPS_DEFINE_INLINE
29#include "cgen-mem.h"
30
31#define SEMOPS_DEFINE_INLINE
32#include "cgen-ops.h"
33
12279229 34const char * const cgen_mode_names[] = {
104c1213 35 "VOID",
c906108c
SS
36 "BI",
37 "QI",
38 "HI",
39 "SI",
40 "DI",
41 "UQI",
42 "UHI",
43 "USI",
44 "UDI",
45 "SF",
46 "DF",
47 "XF",
48 "TF",
49 0, /* MODE_TARGET_MAX */
50 "INT",
51 "UINT",
52 "PTR"
53};
54
55/* Opcode table for virtual insns used by the simulator. */
56
57#define V CGEN_ATTR_MASK (CGEN_INSN_VIRTUAL)
58
59static const CGEN_IBASE virtual_insn_entries[] =
60{
61 {
aac7ce3c 62 VIRTUAL_INSN_X_INVALID, "--invalid--", NULL, 0, { V, {} }
c906108c
SS
63 },
64 {
aac7ce3c 65 VIRTUAL_INSN_X_BEFORE, "--before--", NULL, 0, { V, {} }
c906108c
SS
66 },
67 {
aac7ce3c 68 VIRTUAL_INSN_X_AFTER, "--after--", NULL, 0, { V, {} }
c906108c
SS
69 },
70 {
aac7ce3c 71 VIRTUAL_INSN_X_BEGIN, "--begin--", NULL, 0, { V, {} }
c906108c
SS
72 },
73 {
aac7ce3c 74 VIRTUAL_INSN_X_CHAIN, "--chain--", NULL, 0, { V, {} }
c906108c
SS
75 },
76 {
aac7ce3c 77 VIRTUAL_INSN_X_CTI_CHAIN, "--cti-chain--", NULL, 0, { V, {} }
c906108c
SS
78 }
79};
80
81#undef V
82
83const CGEN_INSN cgen_virtual_insn_table[] =
84{
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] }
91};
92
c906108c
SS
93/* Return the name of insn number I. */
94
95const char *
96cgen_insn_name (SIM_CPU *cpu, int i)
97{
98 return CGEN_INSN_NAME ((* CPU_GET_IDATA (cpu)) ((cpu), (i)));
99}
100
101/* Return the maximum number of extra bytes required for a SIM_CPU struct. */
102
103int
1c636da0 104cgen_cpu_max_extra_bytes (SIM_DESC sd)
c906108c 105{
1c636da0 106 const SIM_MACH * const *machp;
c906108c
SS
107 int extra = 0;
108
1c636da0
MF
109 SIM_ASSERT (STATE_MACHS (sd) != NULL);
110
111 for (machp = STATE_MACHS (sd); *machp != NULL; ++machp)
c906108c 112 {
1c636da0 113 int size = IMP_PROPS_SIM_CPU_SIZE (MACH_IMP_PROPS (*machp));
c906108c
SS
114 if (size > extra)
115 extra = size;
116 }
117 return extra;
118}
119\f
120#ifdef DI_FN_SUPPORT
121
c906108c
SS
122DI
123ANDDI (a, b)
124 DI a, b;
125{
126 SI ahi = GETHIDI (a);
127 SI alo = GETLODI (a);
128 SI bhi = GETHIDI (b);
129 SI blo = GETLODI (b);
130 return MAKEDI (ahi & bhi, alo & blo);
131}
132
133DI
134ORDI (a, b)
135 DI a, b;
136{
137 SI ahi = GETHIDI (a);
138 SI alo = GETLODI (a);
139 SI bhi = GETHIDI (b);
140 SI blo = GETLODI (b);
141 return MAKEDI (ahi | bhi, alo | blo);
142}
143
144DI
145ADDDI (a, b)
146 DI a, b;
147{
148 USI ahi = GETHIDI (a);
149 USI alo = GETLODI (a);
150 USI bhi = GETHIDI (b);
151 USI blo = GETLODI (b);
152 USI x = alo + blo;
153 return MAKEDI (ahi + bhi + (x < alo), x);
154}
155
156DI
157MULDI (a, b)
158 DI a, b;
159{
160 USI ahi = GETHIDI (a);
161 USI alo = GETLODI (a);
162 USI bhi = GETHIDI (b);
163 USI blo = GETLODI (b);
164 USI rhi,rlo;
165 USI x0, x1, x2, x3;
166
167 x0 = alo * blo;
168 x1 = alo * bhi;
169 x2 = ahi * blo;
170 x3 = ahi * bhi;
171
172#define SI_TYPE_SIZE 32
173#define BITS4 (SI_TYPE_SIZE / 4)
174#define ll_B (1L << (SI_TYPE_SIZE / 2))
175#define ll_lowpart(t) ((USI) (t) % ll_B)
176#define ll_highpart(t) ((USI) (t) / ll_B)
177 x1 += ll_highpart (x0); /* this can't give carry */
178 x1 += x2; /* but this indeed can */
179 if (x1 < x2) /* did we get it? */
180 x3 += ll_B; /* yes, add it in the proper pos. */
181
182 rhi = x3 + ll_highpart (x1);
183 rlo = ll_lowpart (x1) * ll_B + ll_lowpart (x0);
184 return MAKEDI (rhi + (alo * bhi) + (ahi * blo), rlo);
185}
186
187DI
188SHLDI (val, shift)
189 DI val;
190 SI shift;
191{
192 USI hi = GETHIDI (val);
193 USI lo = GETLODI (val);
194 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
195 return MAKEDI ((hi << shift) | (lo >> (32 - shift)), lo << shift);
196}
197
198DI
199SLADI (val, shift)
200 DI val;
201 SI shift;
202{
203 SI hi = GETHIDI (val);
204 USI lo = GETLODI (val);
205 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
206 return MAKEDI ((hi << shift) | (lo >> (32 - shift)), lo << shift);
207}
208
209DI
210SRADI (val, shift)
211 DI val;
212 SI shift;
213{
214 SI hi = GETHIDI (val);
215 USI lo = GETLODI (val);
216 /* We use SRASI because the result is implementation defined if hi < 0. */
217 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
218 return MAKEDI (SRASI (hi, shift), (hi << (32 - shift)) | (lo >> shift));
219}
220
221int
222GEDI (a, b)
223 DI a, b;
224{
225 SI ahi = GETHIDI (a);
226 USI alo = GETLODI (a);
227 SI bhi = GETHIDI (b);
228 USI blo = GETLODI (b);
229 if (ahi > bhi)
230 return 1;
231 if (ahi == bhi)
232 return alo >= blo;
233 return 0;
234}
235
236int
237LEDI (a, b)
238 DI a, b;
239{
240 SI ahi = GETHIDI (a);
241 USI alo = GETLODI (a);
242 SI bhi = GETHIDI (b);
243 USI blo = GETLODI (b);
244 if (ahi < bhi)
245 return 1;
246 if (ahi == bhi)
247 return alo <= blo;
248 return 0;
249}
250
251DI
252CONVHIDI (val)
253 HI val;
254{
255 if (val < 0)
256 return MAKEDI (-1, val);
257 else
258 return MAKEDI (0, val);
259}
260
261DI
262CONVSIDI (val)
263 SI val;
264{
265 if (val < 0)
266 return MAKEDI (-1, val);
267 else
268 return MAKEDI (0, val);
269}
270
271SI
272CONVDISI (val)
273 DI val;
274{
275 return GETLODI (val);
276}
277
278#endif /* DI_FN_SUPPORT */
adf40b2e 279\f
6d4c43bf 280QI
81e6e8ae 281RORQI (QI val, int shift)
6d4c43bf
DB
282{
283 if (shift != 0)
284 {
285 int remain = 8 - shift;
286 int mask = (1 << shift) - 1;
287 QI result = (val & mask) << remain;
288 mask = (1 << remain) - 1;
289 result |= (val >> shift) & mask;
290 return result;
291 }
292 return val;
293}
294
295QI
81e6e8ae 296ROLQI (QI val, int shift)
6d4c43bf
DB
297{
298 if (shift != 0)
299 {
300 int remain = 8 - shift;
301 int mask = (1 << remain) - 1;
302 QI result = (val & mask) << shift;
303 mask = (1 << shift) - 1;
304 result |= (val >> remain) & mask;
305 return result;
306 }
307 return val;
308}
309
310HI
81e6e8ae 311RORHI (HI val, int shift)
6d4c43bf
DB
312{
313 if (shift != 0)
314 {
315 int remain = 16 - shift;
316 int mask = (1 << shift) - 1;
317 HI result = (val & mask) << remain;
318 mask = (1 << remain) - 1;
319 result |= (val >> shift) & mask;
320 return result;
321 }
322 return val;
323}
324
325HI
81e6e8ae 326ROLHI (HI val, int shift)
6d4c43bf
DB
327{
328 if (shift != 0)
329 {
330 int remain = 16 - shift;
331 int mask = (1 << remain) - 1;
332 HI result = (val & mask) << shift;
333 mask = (1 << shift) - 1;
334 result |= (val >> remain) & mask;
335 return result;
336 }
337 return val;
338}
339
adf40b2e 340SI
81e6e8ae 341RORSI (SI val, int shift)
adf40b2e
JM
342{
343 if (shift != 0)
344 {
345 int remain = 32 - shift;
346 int mask = (1 << shift) - 1;
347 SI result = (val & mask) << remain;
348 mask = (1 << remain) - 1;
349 result |= (val >> shift) & mask;
350 return result;
351 }
352 return val;
353}
354
355SI
81e6e8ae 356ROLSI (SI val, int shift)
adf40b2e
JM
357{
358 if (shift != 0)
359 {
360 int remain = 32 - shift;
361 int mask = (1 << remain) - 1;
362 SI result = (val & mask) << shift;
363 mask = (1 << shift) - 1;
364 result |= (val >> remain) & mask;
365 return result;
366 }
367
368 return val;
369}
a8d894af
BE
370
371/* Emit an error message from CGEN RTL. */
372
373void
374cgen_rtx_error (SIM_CPU *cpu, const char * msg)
375{
376 SIM_DESC sd = CPU_STATE (cpu);
377
6ae9091a 378 sim_io_printf (sd, "%s", msg);
a8d894af
BE
379 sim_io_printf (sd, "\n");
380
034685f9 381 sim_engine_halt (sd, cpu, NULL, CPU_PC_GET (cpu), sim_stopped, SIM_SIGTRAP);
a8d894af 382}
This page took 1.084562 seconds and 4 git commands to generate.