1 /* Support code for various pieces of CGEN simulators.
2 Copyright (C) 1996, 1997, 1998, 1999 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 2, or (at your option)
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 along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #define MEMOPS_DEFINE_INLINE
28 #define SEMOPS_DEFINE_INLINE
32 #define min(a,b) ((a) < (b) ? (a) : (b))
34 const char *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,
63 { CGEN_INSN_NBOOL_ATTRS
, V
, { 0 } }
66 VIRTUAL_INSN_X_BEFORE
, "--before--", NULL
, 0,
67 { CGEN_INSN_NBOOL_ATTRS
, V
, { 0 } }
70 VIRTUAL_INSN_X_AFTER
, "--after--", NULL
, 0,
71 { CGEN_INSN_NBOOL_ATTRS
, V
, { 0 } }
74 VIRTUAL_INSN_X_BEGIN
, "--begin--", NULL
, 0,
75 { CGEN_INSN_NBOOL_ATTRS
, V
, { 0 } }
78 VIRTUAL_INSN_X_CHAIN
, "--chain--", NULL
, 0,
79 { CGEN_INSN_NBOOL_ATTRS
, V
, { 0 } }
82 VIRTUAL_INSN_X_CTI_CHAIN
, "--cti-chain--", NULL
, 0,
83 { CGEN_INSN_NBOOL_ATTRS
, V
, { 0 } }
89 const CGEN_INSN cgen_virtual_insn_table
[] =
91 { & virtual_insn_entries
[0] },
92 { & virtual_insn_entries
[1] },
93 { & virtual_insn_entries
[2] },
94 { & virtual_insn_entries
[3] },
95 { & virtual_insn_entries
[4] },
96 { & virtual_insn_entries
[5] }
99 /* Initialize cgen things.
100 This is called after sim_post_argv_init. */
103 cgen_init (SIM_DESC sd
)
107 /* If no profiling or tracing has been enabled, run in fast mode. */
111 for (c
= 0; c
< MAX_NR_PROCESSORS
; ++c
)
113 SIM_CPU
*cpu
= STATE_CPU (sd
, c
);
115 for (i
= 0; i
< MAX_PROFILE_VALUES
; ++i
)
116 if (CPU_PROFILE_FLAGS (cpu
) [i
])
121 for (i
= 0; i
< MAX_TRACE_VALUES
; ++i
)
122 if (CPU_TRACE_FLAGS (cpu
) [i
])
130 STATE_RUN_FAST_P (sd
) = run_fast_p
;
134 /* Return the name of insn number I. */
137 cgen_insn_name (SIM_CPU
*cpu
, int i
)
139 return CGEN_INSN_NAME ((* CPU_GET_IDATA (cpu
)) ((cpu
), (i
)));
142 /* Return the maximum number of extra bytes required for a SIM_CPU struct. */
145 cgen_cpu_max_extra_bytes (void)
150 for (i
= 0; sim_machs
[i
] != 0; ++i
)
152 int size
= IMP_PROPS_SIM_CPU_SIZE (MACH_IMP_PROPS (sim_machs
[i
]));
162 make_struct_di (hi
, lo
)
176 SI ahi
= GETHIDI (a
);
177 SI alo
= GETLODI (a
);
178 SI bhi
= GETHIDI (b
);
179 SI blo
= GETLODI (b
);
180 return MAKEDI (ahi
& bhi
, alo
& blo
);
187 SI ahi
= GETHIDI (a
);
188 SI alo
= GETLODI (a
);
189 SI bhi
= GETHIDI (b
);
190 SI blo
= GETLODI (b
);
191 return MAKEDI (ahi
| bhi
, alo
| blo
);
198 USI ahi
= GETHIDI (a
);
199 USI alo
= GETLODI (a
);
200 USI bhi
= GETHIDI (b
);
201 USI blo
= GETLODI (b
);
203 return MAKEDI (ahi
+ bhi
+ (x
< alo
), x
);
210 USI ahi
= GETHIDI (a
);
211 USI alo
= GETLODI (a
);
212 USI bhi
= GETHIDI (b
);
213 USI blo
= GETLODI (b
);
222 #define SI_TYPE_SIZE 32
223 #define BITS4 (SI_TYPE_SIZE / 4)
224 #define ll_B (1L << (SI_TYPE_SIZE / 2))
225 #define ll_lowpart(t) ((USI) (t) % ll_B)
226 #define ll_highpart(t) ((USI) (t) / ll_B)
227 x1
+= ll_highpart (x0
); /* this can't give carry */
228 x1
+= x2
; /* but this indeed can */
229 if (x1
< x2
) /* did we get it? */
230 x3
+= ll_B
; /* yes, add it in the proper pos. */
232 rhi
= x3
+ ll_highpart (x1
);
233 rlo
= ll_lowpart (x1
) * ll_B
+ ll_lowpart (x0
);
234 return MAKEDI (rhi
+ (alo
* bhi
) + (ahi
* blo
), rlo
);
242 USI hi
= GETHIDI (val
);
243 USI lo
= GETLODI (val
);
244 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
245 return MAKEDI ((hi
<< shift
) | (lo
>> (32 - shift
)), lo
<< shift
);
253 SI hi
= GETHIDI (val
);
254 USI lo
= GETLODI (val
);
255 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
256 return MAKEDI ((hi
<< shift
) | (lo
>> (32 - shift
)), lo
<< shift
);
264 SI hi
= GETHIDI (val
);
265 USI lo
= GETLODI (val
);
266 /* We use SRASI because the result is implementation defined if hi < 0. */
267 /* FIXME: Need to worry about shift < 0 || shift >= 32. */
268 return MAKEDI (SRASI (hi
, shift
), (hi
<< (32 - shift
)) | (lo
>> shift
));
275 SI ahi
= GETHIDI (a
);
276 USI alo
= GETLODI (a
);
277 SI bhi
= GETHIDI (b
);
278 USI blo
= GETLODI (b
);
290 SI ahi
= GETHIDI (a
);
291 USI alo
= GETLODI (a
);
292 SI bhi
= GETHIDI (b
);
293 USI blo
= GETLODI (b
);
306 return MAKEDI (-1, val
);
308 return MAKEDI (0, val
);
316 return MAKEDI (-1, val
);
318 return MAKEDI (0, val
);
325 return GETLODI (val
);
328 #endif /* DI_FN_SUPPORT */