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