sim-main.h revision 1.1.1.11 1 1.1 christos /* MIPS Simulator definition.
2 1.1.1.11 christos Copyright (C) 1997-2024 Free Software Foundation, Inc.
3 1.1 christos Contributed by Cygnus Support.
4 1.1 christos
5 1.1.1.6 christos This file is part of the MIPS sim.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #ifndef SIM_MAIN_H
21 1.1 christos #define SIM_MAIN_H
22 1.1 christos
23 1.1 christos #define SIM_CORE_SIGNAL(SD,CPU,CIA,MAP,NR_BYTES,ADDR,TRANSFER,ERROR) \
24 1.1 christos mips_core_signal ((SD), (CPU), (CIA), (MAP), (NR_BYTES), (ADDR), (TRANSFER), (ERROR))
25 1.1 christos
26 1.1 christos #include "sim-basics.h"
27 1.1 christos #include "sim-base.h"
28 1.1.1.11 christos #include "bfd/elf-bfd.h"
29 1.1.1.10 christos #include "elf/mips.h"
30 1.1 christos
31 1.1 christos /* Deprecated macros and types for manipulating 64bit values. Use
32 1.1 christos ../common/sim-bits.h and ../common/sim-endian.h macros instead. */
33 1.1 christos
34 1.1.1.10 christos typedef int64_t word64;
35 1.1.1.10 christos typedef uint64_t uword64;
36 1.1 christos
37 1.1 christos #define WORD64LO(t) (unsigned int)((t)&0xFFFFFFFF)
38 1.1 christos #define WORD64HI(t) (unsigned int)(((uword64)(t))>>32)
39 1.1 christos #define SET64LO(t) (((uword64)(t))&0xFFFFFFFF)
40 1.1 christos #define SET64HI(t) (((uword64)(t))<<32)
41 1.1 christos #define WORD64(h,l) ((word64)((SET64HI(h)|SET64LO(l))))
42 1.1 christos #define UWORD64(h,l) (SET64HI(h)|SET64LO(l))
43 1.1 christos
44 1.1 christos /* Check if a value will fit within a halfword: */
45 1.1 christos #define NOTHALFWORDVALUE(v) ((((((uword64)(v)>>16) == 0) && !((v) & ((unsigned)1 << 15))) || (((((uword64)(v)>>32) == 0xFFFFFFFF) && ((((uword64)(v)>>16) & 0xFFFF) == 0xFFFF)) && ((v) & ((unsigned)1 << 15)))) ? (1 == 0) : (1 == 1))
46 1.1 christos
47 1.1 christos
48 1.1.1.6 christos typedef enum {
49 1.1.1.6 christos cp0_dmfc0,
50 1.1.1.6 christos cp0_dmtc0,
51 1.1.1.6 christos cp0_mfc0,
52 1.1.1.6 christos cp0_mtc0,
53 1.1.1.6 christos cp0_tlbr,
54 1.1.1.6 christos cp0_tlbwi,
55 1.1.1.6 christos cp0_tlbwr,
56 1.1.1.6 christos cp0_tlbp,
57 1.1.1.6 christos cp0_cache,
58 1.1.1.6 christos cp0_eret,
59 1.1.1.6 christos cp0_deret,
60 1.1.1.6 christos cp0_rfe
61 1.1.1.6 christos } CP0_operation;
62 1.1 christos
63 1.1 christos /* Floating-point operations: */
64 1.1 christos
65 1.1 christos #include "sim-fpu.h"
66 1.1 christos #include "cp1.h"
67 1.1 christos
68 1.1 christos /* FPU registers must be one of the following types. All other values
69 1.1 christos are reserved (and undefined). */
70 1.1 christos typedef enum {
71 1.1 christos fmt_single = 0,
72 1.1 christos fmt_double = 1,
73 1.1 christos fmt_word = 4,
74 1.1 christos fmt_long = 5,
75 1.1 christos fmt_ps = 6,
76 1.1.1.10 christos /* The following is a special case for FP conditions where only
77 1.1.1.10 christos the lower 32bits are considered. This is a HACK. */
78 1.1.1.10 christos fmt_dc32 = 7,
79 1.1 christos /* The following are well outside the normal acceptable format
80 1.1 christos range, and are used in the register status vector. */
81 1.1 christos fmt_unknown = 0x10000000,
82 1.1 christos fmt_uninterpreted = 0x20000000,
83 1.1 christos fmt_uninterpreted_32 = 0x40000000,
84 1.1 christos fmt_uninterpreted_64 = 0x80000000U,
85 1.1 christos } FP_formats;
86 1.1 christos
87 1.1 christos /* For paired word (pw) operations, the opcode representation is fmt_word,
88 1.1 christos but register transfers (StoreFPR, ValueFPR, etc.) are done as fmt_long. */
89 1.1 christos #define fmt_pw fmt_long
90 1.1 christos
91 1.1 christos /* This should be the COC1 value at the start of the preceding
92 1.1 christos instruction: */
93 1.1 christos #define PREVCOC1() ((STATE & simPCOC1) ? 1 : 0)
94 1.1 christos
95 1.1 christos #ifdef TARGET_ENABLE_FR
96 1.1 christos /* FIXME: this should be enabled for all targets, but needs testing first. */
97 1.1 christos #define SizeFGR() (((WITH_TARGET_FLOATING_POINT_BITSIZE) == 64) \
98 1.1 christos ? ((SR & status_FR) ? 64 : 32) \
99 1.1 christos : (WITH_TARGET_FLOATING_POINT_BITSIZE))
100 1.1 christos #else
101 1.1 christos #define SizeFGR() (WITH_TARGET_FLOATING_POINT_BITSIZE)
102 1.1 christos #endif
103 1.1 christos
104 1.1 christos
105 1.1 christos
106 1.1 christos
107 1.1 christos
108 1.1 christos /* HI/LO register accesses */
109 1.1 christos
110 1.1 christos /* For some MIPS targets, the HI/LO registers have certain timing
111 1.1 christos restrictions in that, for instance, a read of a HI register must be
112 1.1 christos separated by at least three instructions from a preceeding read.
113 1.1 christos
114 1.1 christos The struct below is used to record the last access by each of A MT,
115 1.1 christos MF or other OP instruction to a HI/LO register. See mips.igen for
116 1.1 christos more details. */
117 1.1 christos
118 1.1 christos typedef struct _hilo_access {
119 1.1.1.10 christos int64_t timestamp;
120 1.1 christos address_word cia;
121 1.1 christos } hilo_access;
122 1.1 christos
123 1.1 christos typedef struct _hilo_history {
124 1.1 christos hilo_access mt;
125 1.1 christos hilo_access mf;
126 1.1 christos hilo_access op;
127 1.1 christos } hilo_history;
128 1.1 christos
129 1.1 christos
130 1.1 christos
131 1.1 christos
132 1.1 christos /* Integer ALU operations: */
133 1.1 christos
134 1.1 christos #include "sim-alu.h"
135 1.1 christos
136 1.1 christos #define ALU32_END(ANS) \
137 1.1 christos if (ALU32_HAD_OVERFLOW) \
138 1.1 christos SignalExceptionIntegerOverflow (); \
139 1.1.1.10 christos (ANS) = (int32_t) ALU32_OVERFLOW_RESULT
140 1.1 christos
141 1.1 christos
142 1.1 christos #define ALU64_END(ANS) \
143 1.1 christos if (ALU64_HAD_OVERFLOW) \
144 1.1 christos SignalExceptionIntegerOverflow (); \
145 1.1 christos (ANS) = ALU64_OVERFLOW_RESULT;
146 1.1 christos
147 1.1 christos
148 1.1 christos
149 1.1 christos
150 1.1 christos
151 1.1 christos /* The following is probably not used for MIPS IV onwards: */
152 1.1 christos /* Slots for delayed register updates. For the moment we just have a
153 1.1 christos fixed number of slots (rather than a more generic, dynamic
154 1.1 christos system). This keeps the simulator fast. However, we only allow
155 1.1 christos for the register update to be delayed for a single instruction
156 1.1 christos cycle. */
157 1.1 christos #define PSLOTS (8) /* Maximum number of instruction cycles */
158 1.1 christos
159 1.1 christos typedef struct _pending_write_queue {
160 1.1 christos int in;
161 1.1 christos int out;
162 1.1 christos int total;
163 1.1 christos int slot_delay[PSLOTS];
164 1.1 christos int slot_size[PSLOTS];
165 1.1 christos int slot_bit[PSLOTS];
166 1.1 christos void *slot_dest[PSLOTS];
167 1.1.1.10 christos uint64_t slot_value[PSLOTS];
168 1.1 christos } pending_write_queue;
169 1.1 christos
170 1.1 christos #ifndef PENDING_TRACE
171 1.1 christos #define PENDING_TRACE 0
172 1.1 christos #endif
173 1.1.1.11 christos #define PENDING_IN (MIPS_SIM_CPU (CPU)->pending.in)
174 1.1.1.11 christos #define PENDING_OUT (MIPS_SIM_CPU (CPU)->pending.out)
175 1.1.1.11 christos #define PENDING_TOTAL (MIPS_SIM_CPU (CPU)->pending.total)
176 1.1.1.11 christos #define PENDING_SLOT_SIZE (MIPS_SIM_CPU (CPU)->pending.slot_size)
177 1.1.1.11 christos #define PENDING_SLOT_BIT (MIPS_SIM_CPU (CPU)->pending.slot_bit)
178 1.1.1.11 christos #define PENDING_SLOT_DELAY (MIPS_SIM_CPU (CPU)->pending.slot_delay)
179 1.1.1.11 christos #define PENDING_SLOT_DEST (MIPS_SIM_CPU (CPU)->pending.slot_dest)
180 1.1.1.11 christos #define PENDING_SLOT_VALUE (MIPS_SIM_CPU (CPU)->pending.slot_value)
181 1.1 christos
182 1.1 christos /* Invalidate the pending write queue, all pending writes are
183 1.1 christos discarded. */
184 1.1 christos
185 1.1 christos #define PENDING_INVALIDATE() \
186 1.1.1.11 christos memset (&MIPS_SIM_CPU (CPU)->pending, 0, sizeof (MIPS_SIM_CPU (CPU)->pending))
187 1.1 christos
188 1.1 christos /* Schedule a write to DEST for N cycles time. For 64 bit
189 1.1 christos destinations, schedule two writes. For floating point registers,
190 1.1 christos the caller should schedule a write to both the dest register and
191 1.1 christos the FPR_STATE register. When BIT is non-negative, only BIT of DEST
192 1.1 christos is updated. */
193 1.1 christos
194 1.1 christos #define PENDING_SCHED(DEST,VAL,DELAY,BIT) \
195 1.1 christos do { \
196 1.1 christos if (PENDING_SLOT_DEST[PENDING_IN] != NULL) \
197 1.1 christos sim_engine_abort (SD, CPU, cia, \
198 1.1 christos "PENDING_SCHED - buffer overflow\n"); \
199 1.1 christos if (PENDING_TRACE) \
200 1.1 christos sim_io_eprintf (SD, "PENDING_SCHED - 0x%lx - dest 0x%lx, val 0x%lx, bit %d, size %d, pending_in %d, pending_out %d, pending_total %d\n", \
201 1.1 christos (unsigned long) cia, (unsigned long) &(DEST), \
202 1.1 christos (unsigned long) (VAL), (BIT), (int) sizeof (DEST),\
203 1.1 christos PENDING_IN, PENDING_OUT, PENDING_TOTAL); \
204 1.1 christos PENDING_SLOT_DELAY[PENDING_IN] = (DELAY) + 1; \
205 1.1 christos PENDING_SLOT_DEST[PENDING_IN] = &(DEST); \
206 1.1 christos PENDING_SLOT_VALUE[PENDING_IN] = (VAL); \
207 1.1 christos PENDING_SLOT_SIZE[PENDING_IN] = sizeof (DEST); \
208 1.1 christos PENDING_SLOT_BIT[PENDING_IN] = (BIT); \
209 1.1 christos PENDING_IN = (PENDING_IN + 1) % PSLOTS; \
210 1.1 christos PENDING_TOTAL += 1; \
211 1.1 christos } while (0)
212 1.1 christos
213 1.1 christos #define PENDING_WRITE(DEST,VAL,DELAY) PENDING_SCHED(DEST,VAL,DELAY,-1)
214 1.1 christos #define PENDING_BIT(DEST,VAL,DELAY,BIT) PENDING_SCHED(DEST,VAL,DELAY,BIT)
215 1.1 christos
216 1.1 christos #define PENDING_TICK() pending_tick (SD, CPU, cia)
217 1.1 christos
218 1.1 christos #define PENDING_FLUSH() abort () /* think about this one */
219 1.1 christos #define PENDING_FP() abort () /* think about this one */
220 1.1 christos
221 1.1 christos /* For backward compatibility */
222 1.1 christos #define PENDING_FILL(R,VAL) \
223 1.1 christos do { \
224 1.1 christos if ((R) >= FGR_BASE && (R) < FGR_BASE + NR_FGR) \
225 1.1 christos { \
226 1.1 christos PENDING_SCHED(FGR[(R) - FGR_BASE], VAL, 1, -1); \
227 1.1 christos PENDING_SCHED(FPR_STATE[(R) - FGR_BASE], fmt_uninterpreted, 1, -1); \
228 1.1 christos } \
229 1.1 christos else \
230 1.1 christos PENDING_SCHED(GPR[(R)], VAL, 1, -1); \
231 1.1 christos } while (0)
232 1.1 christos
233 1.1 christos
234 1.1 christos enum float_operation
235 1.1 christos {
236 1.1 christos FLOP_ADD, FLOP_SUB, FLOP_MUL, FLOP_MADD,
237 1.1 christos FLOP_MSUB, FLOP_MAX=10, FLOP_MIN, FLOP_ABS,
238 1.1 christos FLOP_ITOF0=14, FLOP_FTOI0=18, FLOP_NEG=23
239 1.1 christos };
240 1.1 christos
241 1.1 christos
242 1.1.1.10 christos /* The internal representation of an MDMX accumulator.
243 1.1 christos Note that 24 and 48 bit accumulator elements are represented in
244 1.1 christos 32 or 64 bits. Since the accumulators are 2's complement with
245 1.1 christos overflow suppressed, high-order bits can be ignored in most contexts. */
246 1.1 christos
247 1.1.1.10 christos typedef int32_t signed24;
248 1.1.1.10 christos typedef int64_t signed48;
249 1.1 christos
250 1.1.1.10 christos typedef union {
251 1.1 christos signed24 ob[8];
252 1.1.1.10 christos signed48 qh[4];
253 1.1 christos } MDMX_accumulator;
254 1.1 christos
255 1.1 christos
256 1.1.1.10 christos /* Conventional system arguments. */
257 1.1 christos #define SIM_STATE sim_cpu *cpu, address_word cia
258 1.1 christos #define SIM_ARGS CPU, cia
259 1.1 christos
260 1.1.1.11 christos struct mips_sim_cpu {
261 1.1 christos
262 1.1 christos /* The following are internal simulator state variables: */
263 1.1 christos address_word dspc; /* delay-slot PC */
264 1.1.1.11 christos #define DSPC (MIPS_SIM_CPU (CPU)->dspc)
265 1.1 christos
266 1.1 christos #define DELAY_SLOT(TARGET) NIA = delayslot32 (SD_, (TARGET))
267 1.1.1.10 christos #define FORBIDDEN_SLOT() { NIA = forbiddenslot32 (SD_); }
268 1.1 christos #define NULLIFY_NEXT_INSTRUCTION() NIA = nullify_next_insn32 (SD_)
269 1.1 christos
270 1.1 christos
271 1.1 christos /* State of the simulator */
272 1.1 christos unsigned int state;
273 1.1 christos unsigned int dsstate;
274 1.1.1.11 christos #define STATE (MIPS_SIM_CPU (CPU)->state)
275 1.1.1.11 christos #define DSSTATE (MIPS_SIM_CPU (CPU)->dsstate)
276 1.1 christos
277 1.1 christos /* Flags in the "state" variable: */
278 1.1.1.10 christos #define simHALTEX (1 << 2) /* 0 = run; 1 = halt on exception */
279 1.1.1.10 christos #define simHALTIN (1 << 3) /* 0 = run; 1 = halt on interrupt */
280 1.1.1.10 christos #define simTRACE (1 << 8) /* 1 = trace address activity */
281 1.1.1.10 christos #define simPCOC0 (1 << 17) /* COC[1] from current */
282 1.1.1.10 christos #define simPCOC1 (1 << 18) /* COC[1] from previous */
283 1.1.1.10 christos #define simDELAYSLOT (1 << 24) /* 1 = delay slot entry exists */
284 1.1.1.10 christos #define simSKIPNEXT (1 << 25) /* 0 = do nothing; 1 = skip instruction */
285 1.1.1.10 christos #define simSIGINT (1 << 28) /* 0 = do nothing; 1 = SIGINT has occured */
286 1.1.1.10 christos #define simJALDELAYSLOT (1 << 29) /* 1 = in jal delay slot */
287 1.1.1.10 christos #define simFORBIDDENSLOT (1 << 30) /* 1 = n forbidden slot */
288 1.1 christos
289 1.1 christos #ifndef ENGINE_ISSUE_PREFIX_HOOK
290 1.1 christos #define ENGINE_ISSUE_PREFIX_HOOK() \
291 1.1 christos { \
292 1.1 christos /* Perform any pending writes */ \
293 1.1 christos PENDING_TICK(); \
294 1.1 christos /* Set previous flag, depending on current: */ \
295 1.1 christos if (STATE & simPCOC0) \
296 1.1 christos STATE |= simPCOC1; \
297 1.1 christos else \
298 1.1 christos STATE &= ~simPCOC1; \
299 1.1 christos /* and update the current value: */ \
300 1.1 christos if (GETFCC(0)) \
301 1.1 christos STATE |= simPCOC0; \
302 1.1 christos else \
303 1.1 christos STATE &= ~simPCOC0; \
304 1.1 christos }
305 1.1 christos #endif /* ENGINE_ISSUE_PREFIX_HOOK */
306 1.1 christos
307 1.1 christos
308 1.1 christos /* This is nasty, since we have to rely on matching the register
309 1.1 christos numbers used by GDB. Unfortunately, depending on the MIPS target
310 1.1 christos GDB uses different register numbers. We cannot just include the
311 1.1 christos relevant "gdb/tm.h" link, since GDB may not be configured before
312 1.1 christos the sim world, and also the GDB header file requires too much other
313 1.1 christos state. */
314 1.1 christos
315 1.1 christos #ifndef TM_MIPS_H
316 1.1 christos #define LAST_EMBED_REGNUM (96)
317 1.1 christos #define NUM_REGS (LAST_EMBED_REGNUM + 1)
318 1.1 christos
319 1.1 christos #define FP0_REGNUM 38 /* Floating point register 0 (single float) */
320 1.1 christos #define FCRCS_REGNUM 70 /* FP control/status */
321 1.1 christos #define FCRIR_REGNUM 71 /* FP implementation/revision */
322 1.1 christos #endif
323 1.1 christos
324 1.1 christos
325 1.1 christos /* To keep this default simulator simple, and fast, we use a direct
326 1.1 christos vector of registers. The internal simulator engine then uses
327 1.1 christos manifests to access the correct slot. */
328 1.1 christos
329 1.1 christos unsigned_word registers[LAST_EMBED_REGNUM + 1];
330 1.1 christos
331 1.1 christos int register_widths[NUM_REGS];
332 1.1.1.11 christos #define REGISTERS (MIPS_SIM_CPU (CPU)->registers)
333 1.1 christos
334 1.1 christos #define GPR (®ISTERS[0])
335 1.1 christos #define GPR_SET(N,VAL) (REGISTERS[(N)] = (VAL))
336 1.1 christos
337 1.1 christos #define LO (REGISTERS[33])
338 1.1 christos #define HI (REGISTERS[34])
339 1.1 christos #define PCIDX 37
340 1.1 christos #define PC (REGISTERS[PCIDX])
341 1.1 christos #define CAUSE (REGISTERS[36])
342 1.1 christos #define SRIDX (32)
343 1.1 christos #define SR (REGISTERS[SRIDX]) /* CPU status register */
344 1.1 christos #define FCR0IDX (71)
345 1.1 christos #define FCR0 (REGISTERS[FCR0IDX]) /* really a 32bit register */
346 1.1 christos #define FCR31IDX (70)
347 1.1 christos #define FCR31 (REGISTERS[FCR31IDX]) /* really a 32bit register */
348 1.1 christos #define FCSR (FCR31)
349 1.1 christos #define Debug (REGISTERS[86])
350 1.1 christos #define DEPC (REGISTERS[87])
351 1.1 christos #define EPC (REGISTERS[88])
352 1.1 christos #define ACX (REGISTERS[89])
353 1.1 christos
354 1.1 christos #define AC0LOIDX (33) /* Must be the same register as LO */
355 1.1 christos #define AC0HIIDX (34) /* Must be the same register as HI */
356 1.1 christos #define AC1LOIDX (90)
357 1.1 christos #define AC1HIIDX (91)
358 1.1 christos #define AC2LOIDX (92)
359 1.1 christos #define AC2HIIDX (93)
360 1.1 christos #define AC3LOIDX (94)
361 1.1 christos #define AC3HIIDX (95)
362 1.1 christos
363 1.1 christos #define DSPLO(N) (REGISTERS[DSPLO_REGNUM[N]])
364 1.1 christos #define DSPHI(N) (REGISTERS[DSPHI_REGNUM[N]])
365 1.1 christos
366 1.1 christos #define DSPCRIDX (96) /* DSP control register */
367 1.1 christos #define DSPCR (REGISTERS[DSPCRIDX])
368 1.1 christos
369 1.1 christos #define DSPCR_POS_SHIFT (0)
370 1.1 christos #define DSPCR_POS_MASK (0x3f)
371 1.1 christos #define DSPCR_POS_SMASK (DSPCR_POS_MASK << DSPCR_POS_SHIFT)
372 1.1 christos
373 1.1 christos #define DSPCR_SCOUNT_SHIFT (7)
374 1.1 christos #define DSPCR_SCOUNT_MASK (0x3f)
375 1.1 christos #define DSPCR_SCOUNT_SMASK (DSPCR_SCOUNT_MASK << DSPCR_SCOUNT_SHIFT)
376 1.1 christos
377 1.1 christos #define DSPCR_CARRY_SHIFT (13)
378 1.1 christos #define DSPCR_CARRY_MASK (1)
379 1.1 christos #define DSPCR_CARRY_SMASK (DSPCR_CARRY_MASK << DSPCR_CARRY_SHIFT)
380 1.1 christos #define DSPCR_CARRY (1 << DSPCR_CARRY_SHIFT)
381 1.1 christos
382 1.1 christos #define DSPCR_EFI_SHIFT (14)
383 1.1 christos #define DSPCR_EFI_MASK (1)
384 1.1 christos #define DSPCR_EFI_SMASK (DSPCR_EFI_MASK << DSPCR_EFI_SHIFT)
385 1.1 christos #define DSPCR_EFI (1 << DSPCR_EFI_MASK)
386 1.1 christos
387 1.1 christos #define DSPCR_OUFLAG_SHIFT (16)
388 1.1 christos #define DSPCR_OUFLAG_MASK (0xff)
389 1.1 christos #define DSPCR_OUFLAG_SMASK (DSPCR_OUFLAG_MASK << DSPCR_OUFLAG_SHIFT)
390 1.1 christos #define DSPCR_OUFLAG4 (1 << (DSPCR_OUFLAG_SHIFT + 4))
391 1.1 christos #define DSPCR_OUFLAG5 (1 << (DSPCR_OUFLAG_SHIFT + 5))
392 1.1 christos #define DSPCR_OUFLAG6 (1 << (DSPCR_OUFLAG_SHIFT + 6))
393 1.1 christos #define DSPCR_OUFLAG7 (1 << (DSPCR_OUFLAG_SHIFT + 7))
394 1.1 christos
395 1.1 christos #define DSPCR_CCOND_SHIFT (24)
396 1.1 christos #define DSPCR_CCOND_MASK (0xf)
397 1.1 christos #define DSPCR_CCOND_SMASK (DSPCR_CCOND_MASK << DSPCR_CCOND_SHIFT)
398 1.1 christos
399 1.1 christos /* All internal state modified by signal_exception() that may need to be
400 1.1 christos rolled back for passing moment-of-exception image back to gdb. */
401 1.1 christos unsigned_word exc_trigger_registers[LAST_EMBED_REGNUM + 1];
402 1.1 christos unsigned_word exc_suspend_registers[LAST_EMBED_REGNUM + 1];
403 1.1 christos int exc_suspended;
404 1.1 christos
405 1.1 christos #define SIM_CPU_EXCEPTION_TRIGGER(SD,CPU,CIA) mips_cpu_exception_trigger(SD,CPU,CIA)
406 1.1 christos #define SIM_CPU_EXCEPTION_SUSPEND(SD,CPU,EXC) mips_cpu_exception_suspend(SD,CPU,EXC)
407 1.1 christos #define SIM_CPU_EXCEPTION_RESUME(SD,CPU,EXC) mips_cpu_exception_resume(SD,CPU,EXC)
408 1.1 christos
409 1.1 christos unsigned_word c0_config_reg;
410 1.1.1.11 christos #define C0_CONFIG (MIPS_SIM_CPU (CPU)->c0_config_reg)
411 1.1 christos
412 1.1 christos /* The following are pseudonyms for standard registers */
413 1.1 christos #define ZERO (REGISTERS[0])
414 1.1 christos #define V0 (REGISTERS[2])
415 1.1 christos #define A0 (REGISTERS[4])
416 1.1 christos #define A1 (REGISTERS[5])
417 1.1 christos #define A2 (REGISTERS[6])
418 1.1 christos #define A3 (REGISTERS[7])
419 1.1 christos #define T8IDX 24
420 1.1 christos #define T8 (REGISTERS[T8IDX])
421 1.1 christos #define SPIDX 29
422 1.1 christos #define SP (REGISTERS[SPIDX])
423 1.1 christos #define RAIDX 31
424 1.1 christos #define RA (REGISTERS[RAIDX])
425 1.1 christos
426 1.1 christos /* While space is allocated in the main registers arrray for some of
427 1.1 christos the COP0 registers, that space isn't sufficient. Unknown COP0
428 1.1 christos registers overflow into the array below */
429 1.1 christos
430 1.1 christos #define NR_COP0_GPR 32
431 1.1 christos unsigned_word cop0_gpr[NR_COP0_GPR];
432 1.1.1.11 christos #define COP0_GPR (MIPS_SIM_CPU (CPU)->cop0_gpr)
433 1.1 christos #define COP0_BADVADDR (COP0_GPR[8])
434 1.1 christos
435 1.1 christos /* While space is allocated for the floating point registers in the
436 1.1 christos main registers array, they are stored separatly. This is because
437 1.1 christos their size may not necessarily match the size of either the
438 1.1 christos general-purpose or system specific registers. */
439 1.1 christos #define NR_FGR (32)
440 1.1 christos #define FGR_BASE FP0_REGNUM
441 1.1 christos fp_word fgr[NR_FGR];
442 1.1.1.11 christos #define FGR (MIPS_SIM_CPU (CPU)->fgr)
443 1.1 christos
444 1.1 christos /* Keep the current format state for each register: */
445 1.1 christos FP_formats fpr_state[32];
446 1.1.1.11 christos #define FPR_STATE (MIPS_SIM_CPU (CPU)->fpr_state)
447 1.1 christos
448 1.1 christos pending_write_queue pending;
449 1.1 christos
450 1.1 christos /* The MDMX accumulator (used only for MDMX ASE). */
451 1.1.1.10 christos MDMX_accumulator acc;
452 1.1.1.11 christos #define ACC (MIPS_SIM_CPU (CPU)->acc)
453 1.1 christos
454 1.1 christos /* LLBIT = Load-Linked bit. A bit of "virtual" state used by atomic
455 1.1 christos read-write instructions. It is set when a linked load occurs. It
456 1.1 christos is tested and cleared by the conditional store. It is cleared
457 1.1 christos (during other CPU operations) when a store to the location would
458 1.1 christos no longer be atomic. In particular, it is cleared by exception
459 1.1 christos return instructions. */
460 1.1 christos int llbit;
461 1.1.1.11 christos #define LLBIT (MIPS_SIM_CPU (CPU)->llbit)
462 1.1 christos
463 1.1 christos
464 1.1 christos /* The HIHISTORY and LOHISTORY timestamps are used to ensure that
465 1.1 christos corruptions caused by using the HI or LO register too close to a
466 1.1 christos following operation is spotted. See mips.igen for more details. */
467 1.1 christos
468 1.1 christos hilo_history hi_history;
469 1.1.1.11 christos #define HIHISTORY (&MIPS_SIM_CPU (CPU)->hi_history)
470 1.1 christos hilo_history lo_history;
471 1.1.1.11 christos #define LOHISTORY (&MIPS_SIM_CPU (CPU)->lo_history)
472 1.1 christos };
473 1.1.1.11 christos #define MIPS_SIM_CPU(cpu) ((struct mips_sim_cpu *) CPU_ARCH_DATA (cpu))
474 1.1 christos
475 1.1.1.6 christos extern void mips_sim_close (SIM_DESC sd, int quitting);
476 1.1.1.6 christos #define SIM_CLOSE_HOOK(...) mips_sim_close (__VA_ARGS__)
477 1.1 christos
478 1.1 christos /* FIXME: At present much of the simulator is still static */
479 1.1.1.10 christos struct mips_sim_state {
480 1.1.1.6 christos /* microMIPS ISA mode. */
481 1.1.1.6 christos int isa_mode;
482 1.1 christos };
483 1.1.1.10 christos #define MIPS_SIM_STATE(sd) ((struct mips_sim_state *) STATE_ARCH_DATA (sd))
484 1.1 christos
485 1.1 christos
486 1.1 christos /* Status information: */
487 1.1 christos
488 1.1 christos /* TODO : these should be the bitmasks for these bits within the
489 1.1 christos status register. At the moment the following are VR4300
490 1.1 christos bit-positions: */
491 1.1 christos #define status_KSU_mask (0x18) /* mask for KSU bits */
492 1.1 christos #define status_KSU_shift (3) /* shift for field */
493 1.1 christos #define ksu_kernel (0x0)
494 1.1 christos #define ksu_supervisor (0x1)
495 1.1 christos #define ksu_user (0x2)
496 1.1 christos #define ksu_unknown (0x3)
497 1.1 christos
498 1.1 christos #define SR_KSU ((SR & status_KSU_mask) >> status_KSU_shift)
499 1.1 christos
500 1.1 christos #define status_IE (1 << 0) /* Interrupt enable */
501 1.1 christos #define status_EIE (1 << 16) /* Enable Interrupt Enable */
502 1.1 christos #define status_EXL (1 << 1) /* Exception level */
503 1.1 christos #define status_RE (1 << 25) /* Reverse Endian in user mode */
504 1.1 christos #define status_FR (1 << 26) /* enables MIPS III additional FP registers */
505 1.1 christos #define status_SR (1 << 20) /* soft reset or NMI */
506 1.1 christos #define status_BEV (1 << 22) /* Location of general exception vectors */
507 1.1 christos #define status_TS (1 << 21) /* TLB shutdown has occurred */
508 1.1 christos #define status_ERL (1 << 2) /* Error level */
509 1.1 christos #define status_IM7 (1 << 15) /* Timer Interrupt Mask */
510 1.1 christos #define status_RP (1 << 27) /* Reduced Power mode */
511 1.1 christos
512 1.1 christos /* Specializations for TX39 family */
513 1.1 christos #define status_IEc (1 << 0) /* Interrupt enable (current) */
514 1.1 christos #define status_KUc (1 << 1) /* Kernel/User mode */
515 1.1 christos #define status_IEp (1 << 2) /* Interrupt enable (previous) */
516 1.1 christos #define status_KUp (1 << 3) /* Kernel/User mode */
517 1.1 christos #define status_IEo (1 << 4) /* Interrupt enable (old) */
518 1.1 christos #define status_KUo (1 << 5) /* Kernel/User mode */
519 1.1 christos #define status_IM_mask (0xff) /* Interrupt mask */
520 1.1 christos #define status_IM_shift (8)
521 1.1 christos #define status_NMI (1 << 20) /* NMI */
522 1.1 christos #define status_NMI (1 << 20) /* NMI */
523 1.1 christos
524 1.1 christos /* Status bits used by MIPS32/MIPS64. */
525 1.1 christos #define status_UX (1 << 5) /* 64-bit user addrs */
526 1.1 christos #define status_SX (1 << 6) /* 64-bit supervisor addrs */
527 1.1 christos #define status_KX (1 << 7) /* 64-bit kernel addrs */
528 1.1 christos #define status_TS (1 << 21) /* TLB shutdown has occurred */
529 1.1 christos #define status_PX (1 << 23) /* Enable 64 bit operations */
530 1.1 christos #define status_MX (1 << 24) /* Enable MDMX resources */
531 1.1 christos #define status_CU0 (1 << 28) /* Coprocessor 0 usable */
532 1.1 christos #define status_CU1 (1 << 29) /* Coprocessor 1 usable */
533 1.1 christos #define status_CU2 (1 << 30) /* Coprocessor 2 usable */
534 1.1 christos #define status_CU3 (1 << 31) /* Coprocessor 3 usable */
535 1.1 christos /* Bits reserved for implementations: */
536 1.1 christos #define status_SBX (1 << 16) /* Enable SiByte SB-1 extensions. */
537 1.1 christos
538 1.1.1.10 christos /* From R6 onwards, some instructions (e.g. ADDIUPC) change behaviour based
539 1.1.1.10 christos * on the Status.UX bits to either sign extend, or act as full 64 bit. */
540 1.1.1.10 christos #define status_optional_EXTEND32(x) ((SR & status_UX) ? x : EXTEND32(x))
541 1.1.1.10 christos
542 1.1 christos #define cause_BD ((unsigned)1 << 31) /* L1 Exception in branch delay slot */
543 1.1 christos #define cause_BD2 (1 << 30) /* L2 Exception in branch delay slot */
544 1.1 christos #define cause_CE_mask 0x30000000 /* Coprocessor exception */
545 1.1 christos #define cause_CE_shift 28
546 1.1 christos #define cause_EXC2_mask 0x00070000
547 1.1 christos #define cause_EXC2_shift 16
548 1.1 christos #define cause_IP7 (1 << 15) /* Interrupt pending */
549 1.1 christos #define cause_SIOP (1 << 12) /* SIO pending */
550 1.1 christos #define cause_IP3 (1 << 11) /* Int 0 pending */
551 1.1 christos #define cause_IP2 (1 << 10) /* Int 1 pending */
552 1.1 christos
553 1.1 christos #define cause_EXC_mask (0x1c) /* Exception code */
554 1.1 christos #define cause_EXC_shift (2)
555 1.1 christos
556 1.1 christos #define cause_SW0 (1 << 8) /* Software interrupt 0 */
557 1.1 christos #define cause_SW1 (1 << 9) /* Software interrupt 1 */
558 1.1 christos #define cause_IP_mask (0x3f) /* Interrupt pending field */
559 1.1 christos #define cause_IP_shift (10)
560 1.1 christos
561 1.1 christos #define cause_set_EXC(x) CAUSE = (CAUSE & ~cause_EXC_mask) | ((x << cause_EXC_shift) & cause_EXC_mask)
562 1.1 christos #define cause_set_EXC2(x) CAUSE = (CAUSE & ~cause_EXC2_mask) | ((x << cause_EXC2_shift) & cause_EXC2_mask)
563 1.1 christos
564 1.1 christos
565 1.1 christos /* NOTE: We keep the following status flags as bit values (1 for true,
566 1.1 christos 0 for false). This allows them to be used in binary boolean
567 1.1 christos operations without worrying about what exactly the non-zero true
568 1.1 christos value is. */
569 1.1 christos
570 1.1 christos /* UserMode */
571 1.1 christos #ifdef SUBTARGET_R3900
572 1.1 christos #define UserMode ((SR & status_KUc) ? 1 : 0)
573 1.1 christos #else
574 1.1 christos #define UserMode ((((SR & status_KSU_mask) >> status_KSU_shift) == ksu_user) ? 1 : 0)
575 1.1 christos #endif /* SUBTARGET_R3900 */
576 1.1 christos
577 1.1 christos /* BigEndianMem */
578 1.1 christos /* Hardware configuration. Affects endianness of LoadMemory and
579 1.1 christos StoreMemory and the endianness of Kernel and Supervisor mode
580 1.1 christos execution. The value is 0 for little-endian; 1 for big-endian. */
581 1.1.1.6 christos #define BigEndianMem (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
582 1.1 christos /*(state & simBE) ? 1 : 0)*/
583 1.1 christos
584 1.1 christos /* ReverseEndian */
585 1.1 christos /* This mode is selected if in User mode with the RE bit being set in
586 1.1 christos SR (Status Register). It reverses the endianness of load and store
587 1.1 christos instructions. */
588 1.1 christos #define ReverseEndian (((SR & status_RE) && UserMode) ? 1 : 0)
589 1.1 christos
590 1.1 christos /* BigEndianCPU */
591 1.1 christos /* The endianness for load and store instructions (0=little;1=big). In
592 1.1 christos User mode this endianness may be switched by setting the state_RE
593 1.1 christos bit in the SR register. Thus, BigEndianCPU may be computed as
594 1.1 christos (BigEndianMem EOR ReverseEndian). */
595 1.1 christos #define BigEndianCPU (BigEndianMem ^ ReverseEndian) /* Already bits */
596 1.1 christos
597 1.1 christos
598 1.1 christos
599 1.1 christos /* Exceptions: */
600 1.1 christos
601 1.1 christos /* NOTE: These numbers depend on the processor architecture being
602 1.1 christos simulated: */
603 1.1 christos enum ExceptionCause {
604 1.1 christos Interrupt = 0,
605 1.1 christos TLBModification = 1,
606 1.1 christos TLBLoad = 2,
607 1.1 christos TLBStore = 3,
608 1.1 christos AddressLoad = 4,
609 1.1 christos AddressStore = 5,
610 1.1 christos InstructionFetch = 6,
611 1.1 christos DataReference = 7,
612 1.1 christos SystemCall = 8,
613 1.1 christos BreakPoint = 9,
614 1.1 christos ReservedInstruction = 10,
615 1.1 christos CoProcessorUnusable = 11,
616 1.1 christos IntegerOverflow = 12, /* Arithmetic overflow (IDT monitor raises SIGFPE) */
617 1.1 christos Trap = 13,
618 1.1 christos FPE = 15,
619 1.1 christos DebugBreakPoint = 16, /* Impl. dep. in MIPS32/MIPS64. */
620 1.1 christos MDMX = 22,
621 1.1 christos Watch = 23,
622 1.1 christos MCheck = 24,
623 1.1 christos CacheErr = 30,
624 1.1 christos NMIReset = 31, /* Reserved in MIPS32/MIPS64. */
625 1.1 christos
626 1.1 christos
627 1.1 christos /* The following exception code is actually private to the simulator
628 1.1 christos world. It is *NOT* a processor feature, and is used to signal
629 1.1 christos run-time errors in the simulator. */
630 1.1 christos SimulatorFault = 0xFFFFFFFF
631 1.1 christos };
632 1.1 christos
633 1.1 christos #define TLB_REFILL (0)
634 1.1 christos #define TLB_INVALID (1)
635 1.1 christos
636 1.1 christos
637 1.1 christos /* The following break instructions are reserved for use by the
638 1.1 christos simulator. The first is used to halt the simulation. The second
639 1.1.1.10 christos is used by gdb for break-points. NOTE: Care must be taken, since
640 1.1 christos this value may be used in later revisions of the MIPS ISA. */
641 1.1 christos #define HALT_INSTRUCTION_MASK (0x03FFFFC0)
642 1.1 christos
643 1.1 christos #define HALT_INSTRUCTION (0x03ff000d)
644 1.1 christos #define HALT_INSTRUCTION2 (0x0000ffcd)
645 1.1 christos
646 1.1 christos
647 1.1 christos #define BREAKPOINT_INSTRUCTION (0x0005000d)
648 1.1 christos #define BREAKPOINT_INSTRUCTION2 (0x0000014d)
649 1.1 christos
650 1.1 christos
651 1.1 christos
652 1.1 christos void interrupt_event (SIM_DESC sd, void *data);
653 1.1 christos
654 1.1 christos void signal_exception (SIM_DESC sd, sim_cpu *cpu, address_word cia, int exception, ...);
655 1.1 christos #define SignalException(exc,instruction) signal_exception (SD, CPU, cia, (exc), (instruction))
656 1.1 christos #define SignalExceptionInterrupt(level) signal_exception (SD, CPU, cia, Interrupt, level)
657 1.1 christos #define SignalExceptionInstructionFetch() signal_exception (SD, CPU, cia, InstructionFetch)
658 1.1 christos #define SignalExceptionAddressStore() signal_exception (SD, CPU, cia, AddressStore)
659 1.1 christos #define SignalExceptionAddressLoad() signal_exception (SD, CPU, cia, AddressLoad)
660 1.1 christos #define SignalExceptionDataReference() signal_exception (SD, CPU, cia, DataReference)
661 1.1 christos #define SignalExceptionSimulatorFault(buf) signal_exception (SD, CPU, cia, SimulatorFault, buf)
662 1.1 christos #define SignalExceptionFPE() signal_exception (SD, CPU, cia, FPE)
663 1.1 christos #define SignalExceptionIntegerOverflow() signal_exception (SD, CPU, cia, IntegerOverflow)
664 1.1 christos #define SignalExceptionCoProcessorUnusable(cop) signal_exception (SD, CPU, cia, CoProcessorUnusable)
665 1.1 christos #define SignalExceptionNMIReset() signal_exception (SD, CPU, cia, NMIReset)
666 1.1 christos #define SignalExceptionTLBRefillStore() signal_exception (SD, CPU, cia, TLBStore, TLB_REFILL)
667 1.1 christos #define SignalExceptionTLBRefillLoad() signal_exception (SD, CPU, cia, TLBLoad, TLB_REFILL)
668 1.1 christos #define SignalExceptionTLBInvalidStore() signal_exception (SD, CPU, cia, TLBStore, TLB_INVALID)
669 1.1 christos #define SignalExceptionTLBInvalidLoad() signal_exception (SD, CPU, cia, TLBLoad, TLB_INVALID)
670 1.1 christos #define SignalExceptionTLBModification() signal_exception (SD, CPU, cia, TLBModification)
671 1.1 christos #define SignalExceptionMDMX() signal_exception (SD, CPU, cia, MDMX)
672 1.1 christos #define SignalExceptionWatch() signal_exception (SD, CPU, cia, Watch)
673 1.1 christos #define SignalExceptionMCheck() signal_exception (SD, CPU, cia, MCheck)
674 1.1 christos #define SignalExceptionCacheErr() signal_exception (SD, CPU, cia, CacheErr)
675 1.1 christos
676 1.1 christos /* Co-processor accesses */
677 1.1 christos
678 1.1 christos /* XXX FIXME: For now, assume that FPU (cp1) is always usable. */
679 1.1 christos #define COP_Usable(coproc_num) (coproc_num == 1)
680 1.1 christos
681 1.1.1.3 christos void cop_lw (SIM_DESC sd, sim_cpu *cpu, address_word cia, int coproc_num, int coproc_reg, unsigned int memword);
682 1.1.1.3 christos void cop_ld (SIM_DESC sd, sim_cpu *cpu, address_word cia, int coproc_num, int coproc_reg, uword64 memword);
683 1.1.1.3 christos unsigned int cop_sw (SIM_DESC sd, sim_cpu *cpu, address_word cia, int coproc_num, int coproc_reg);
684 1.1.1.3 christos uword64 cop_sd (SIM_DESC sd, sim_cpu *cpu, address_word cia, int coproc_num, int coproc_reg);
685 1.1 christos
686 1.1 christos #define COP_LW(coproc_num,coproc_reg,memword) \
687 1.1 christos cop_lw (SD, CPU, cia, coproc_num, coproc_reg, memword)
688 1.1 christos #define COP_LD(coproc_num,coproc_reg,memword) \
689 1.1 christos cop_ld (SD, CPU, cia, coproc_num, coproc_reg, memword)
690 1.1 christos #define COP_SW(coproc_num,coproc_reg) \
691 1.1 christos cop_sw (SD, CPU, cia, coproc_num, coproc_reg)
692 1.1 christos #define COP_SD(coproc_num,coproc_reg) \
693 1.1 christos cop_sd (SD, CPU, cia, coproc_num, coproc_reg)
694 1.1 christos
695 1.1 christos
696 1.1.1.6 christos void decode_coproc (SIM_DESC sd, sim_cpu *cpu, address_word cia,
697 1.1.1.6 christos unsigned int instruction, int coprocnum, CP0_operation op,
698 1.1.1.6 christos int rt, int rd, int sel);
699 1.1.1.6 christos #define DecodeCoproc(instruction,coprocnum,op,rt,rd,sel) \
700 1.1.1.6 christos decode_coproc (SD, CPU, cia, (instruction), (coprocnum), (op), \
701 1.1.1.6 christos (rt), (rd), (sel))
702 1.1 christos
703 1.1 christos int sim_monitor (SIM_DESC sd, sim_cpu *cpu, address_word cia, unsigned int arg);
704 1.1.1.10 christos
705 1.1 christos
706 1.1 christos /* FPR access. */
707 1.1.1.10 christos uint64_t value_fpr (SIM_STATE, int fpr, FP_formats);
708 1.1 christos #define ValueFPR(FPR,FMT) value_fpr (SIM_ARGS, (FPR), (FMT))
709 1.1.1.10 christos void store_fpr (SIM_STATE, int fpr, FP_formats fmt, uint64_t value);
710 1.1 christos #define StoreFPR(FPR,FMT,VALUE) store_fpr (SIM_ARGS, (FPR), (FMT), (VALUE))
711 1.1.1.10 christos uint64_t ps_lower (SIM_STATE, uint64_t op);
712 1.1 christos #define PSLower(op) ps_lower (SIM_ARGS, op)
713 1.1.1.10 christos uint64_t ps_upper (SIM_STATE, uint64_t op);
714 1.1 christos #define PSUpper(op) ps_upper (SIM_ARGS, op)
715 1.1.1.10 christos uint64_t pack_ps (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats from);
716 1.1 christos #define PackPS(op1,op2) pack_ps (SIM_ARGS, op1, op2, fmt_single)
717 1.1 christos
718 1.1 christos
719 1.1 christos /* FCR access. */
720 1.1 christos unsigned_word value_fcr (SIM_STATE, int fcr);
721 1.1 christos #define ValueFCR(FCR) value_fcr (SIM_ARGS, (FCR))
722 1.1 christos void store_fcr (SIM_STATE, int fcr, unsigned_word value);
723 1.1 christos #define StoreFCR(FCR,VALUE) store_fcr (SIM_ARGS, (FCR), (VALUE))
724 1.1 christos void test_fcsr (SIM_STATE);
725 1.1 christos #define TestFCSR() test_fcsr (SIM_ARGS)
726 1.1 christos
727 1.1 christos
728 1.1 christos /* FPU operations. */
729 1.1.1.10 christos /* Non-signalling */
730 1.1.1.10 christos #define FP_R6CMP_AF 0x0
731 1.1.1.10 christos #define FP_R6CMP_EQ 0x2
732 1.1.1.10 christos #define FP_R6CMP_LE 0x6
733 1.1.1.10 christos #define FP_R6CMP_LT 0x4
734 1.1.1.10 christos #define FP_R6CMP_NE 0x13
735 1.1.1.10 christos #define FP_R6CMP_OR 0x11
736 1.1.1.10 christos #define FP_R6CMP_UEQ 0x3
737 1.1.1.10 christos #define FP_R6CMP_ULE 0x7
738 1.1.1.10 christos #define FP_R6CMP_ULT 0x5
739 1.1.1.10 christos #define FP_R6CMP_UN 0x1
740 1.1.1.10 christos #define FP_R6CMP_UNE 0x12
741 1.1.1.10 christos
742 1.1.1.10 christos /* Signalling */
743 1.1.1.10 christos #define FP_R6CMP_SAF 0x8
744 1.1.1.10 christos #define FP_R6CMP_SEQ 0xa
745 1.1.1.10 christos #define FP_R6CMP_SLE 0xe
746 1.1.1.10 christos #define FP_R6CMP_SLT 0xc
747 1.1.1.10 christos #define FP_R6CMP_SNE 0x1b
748 1.1.1.10 christos #define FP_R6CMP_SOR 0x19
749 1.1.1.10 christos #define FP_R6CMP_SUEQ 0xb
750 1.1.1.10 christos #define FP_R6CMP_SULE 0xf
751 1.1.1.10 christos #define FP_R6CMP_SULT 0xd
752 1.1.1.10 christos #define FP_R6CMP_SUN 0x9
753 1.1.1.10 christos #define FP_R6CMP_SUNE 0x1a
754 1.1.1.10 christos
755 1.1.1.10 christos /* FPU Class */
756 1.1.1.10 christos #define FP_R6CLASS_SNAN (1<<0)
757 1.1.1.10 christos #define FP_R6CLASS_QNAN (1<<1)
758 1.1.1.10 christos #define FP_R6CLASS_NEGINF (1<<2)
759 1.1.1.10 christos #define FP_R6CLASS_NEGNORM (1<<3)
760 1.1.1.10 christos #define FP_R6CLASS_NEGSUB (1<<4)
761 1.1.1.10 christos #define FP_R6CLASS_NEGZERO (1<<5)
762 1.1.1.10 christos #define FP_R6CLASS_POSINF (1<<6)
763 1.1.1.10 christos #define FP_R6CLASS_POSNORM (1<<7)
764 1.1.1.10 christos #define FP_R6CLASS_POSSUB (1<<8)
765 1.1.1.10 christos #define FP_R6CLASS_POSZERO (1<<9)
766 1.1.1.10 christos
767 1.1.1.10 christos void fp_cmp (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt,
768 1.1.1.10 christos int abs, int cond, int cc);
769 1.1.1.10 christos #define Compare(op1,op2,fmt,cond,cc) \
770 1.1.1.10 christos fp_cmp(SIM_ARGS, op1, op2, fmt, 0, cond, cc)
771 1.1.1.10 christos uint64_t fp_r6_cmp (SIM_STATE, uint64_t op1, uint64_t op2,
772 1.1.1.10 christos FP_formats fmt, int cond);
773 1.1.1.10 christos #define R6Compare(op1,op2,fmt,cond) fp_r6_cmp(SIM_ARGS, op1, op2, fmt, cond)
774 1.1.1.10 christos uint64_t fp_classify(SIM_STATE, uint64_t op, FP_formats fmt);
775 1.1.1.10 christos #define Classify(op, fmt) fp_classify(SIM_ARGS, op, fmt)
776 1.1.1.10 christos int fp_rint(SIM_STATE, uint64_t op, uint64_t *ans, FP_formats fmt);
777 1.1.1.10 christos #define RoundToIntegralExact(op, ans, fmt) fp_rint(SIM_ARGS, op, ans, fmt)
778 1.1.1.10 christos uint64_t fp_abs (SIM_STATE, uint64_t op, FP_formats fmt);
779 1.1 christos #define AbsoluteValue(op,fmt) fp_abs(SIM_ARGS, op, fmt)
780 1.1.1.10 christos uint64_t fp_neg (SIM_STATE, uint64_t op, FP_formats fmt);
781 1.1 christos #define Negate(op,fmt) fp_neg(SIM_ARGS, op, fmt)
782 1.1.1.10 christos uint64_t fp_add (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
783 1.1 christos #define Add(op1,op2,fmt) fp_add(SIM_ARGS, op1, op2, fmt)
784 1.1.1.10 christos uint64_t fp_sub (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
785 1.1 christos #define Sub(op1,op2,fmt) fp_sub(SIM_ARGS, op1, op2, fmt)
786 1.1.1.10 christos uint64_t fp_mul (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
787 1.1 christos #define Multiply(op1,op2,fmt) fp_mul(SIM_ARGS, op1, op2, fmt)
788 1.1.1.10 christos uint64_t fp_div (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
789 1.1 christos #define Divide(op1,op2,fmt) fp_div(SIM_ARGS, op1, op2, fmt)
790 1.1.1.10 christos uint64_t fp_min (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
791 1.1.1.10 christos #define Min(op1,op2,fmt) fp_min(SIM_ARGS, op1, op2, fmt)
792 1.1.1.10 christos uint64_t fp_max (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
793 1.1.1.10 christos #define Max(op1,op2,fmt) fp_max(SIM_ARGS, op1, op2, fmt)
794 1.1.1.10 christos uint64_t fp_mina (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
795 1.1.1.10 christos #define MinA(op1,op2,fmt) fp_mina(SIM_ARGS, op1, op2, fmt)
796 1.1.1.10 christos uint64_t fp_maxa (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
797 1.1.1.10 christos #define MaxA(op1,op2,fmt) fp_maxa(SIM_ARGS, op1, op2, fmt)
798 1.1.1.10 christos uint64_t fp_recip (SIM_STATE, uint64_t op, FP_formats fmt);
799 1.1 christos #define Recip(op,fmt) fp_recip(SIM_ARGS, op, fmt)
800 1.1.1.10 christos uint64_t fp_sqrt (SIM_STATE, uint64_t op, FP_formats fmt);
801 1.1 christos #define SquareRoot(op,fmt) fp_sqrt(SIM_ARGS, op, fmt)
802 1.1.1.10 christos uint64_t fp_rsqrt (SIM_STATE, uint64_t op, FP_formats fmt);
803 1.1 christos #define RSquareRoot(op,fmt) fp_rsqrt(SIM_ARGS, op, fmt)
804 1.1.1.10 christos uint64_t fp_madd (SIM_STATE, uint64_t op1, uint64_t op2,
805 1.1.1.10 christos uint64_t op3, FP_formats fmt);
806 1.1.1.10 christos #define FusedMultiplyAdd(op1,op2,op3,fmt) fp_fmadd(SIM_ARGS, op1, op2, op3, fmt)
807 1.1.1.10 christos uint64_t fp_fmadd (SIM_STATE, uint64_t op1, uint64_t op2,
808 1.1.1.10 christos uint64_t op3, FP_formats fmt);
809 1.1.1.10 christos #define FusedMultiplySub(op1,op2,op3,fmt) fp_fmsub(SIM_ARGS, op1, op2, op3, fmt)
810 1.1.1.10 christos uint64_t fp_fmsub (SIM_STATE, uint64_t op1, uint64_t op2,
811 1.1.1.10 christos uint64_t op3, FP_formats fmt);
812 1.1 christos #define MultiplyAdd(op1,op2,op3,fmt) fp_madd(SIM_ARGS, op1, op2, op3, fmt)
813 1.1.1.10 christos uint64_t fp_msub (SIM_STATE, uint64_t op1, uint64_t op2,
814 1.1.1.10 christos uint64_t op3, FP_formats fmt);
815 1.1 christos #define MultiplySub(op1,op2,op3,fmt) fp_msub(SIM_ARGS, op1, op2, op3, fmt)
816 1.1.1.10 christos uint64_t fp_nmadd (SIM_STATE, uint64_t op1, uint64_t op2,
817 1.1.1.10 christos uint64_t op3, FP_formats fmt);
818 1.1 christos #define NegMultiplyAdd(op1,op2,op3,fmt) fp_nmadd(SIM_ARGS, op1, op2, op3, fmt)
819 1.1.1.10 christos uint64_t fp_nmsub (SIM_STATE, uint64_t op1, uint64_t op2,
820 1.1.1.10 christos uint64_t op3, FP_formats fmt);
821 1.1 christos #define NegMultiplySub(op1,op2,op3,fmt) fp_nmsub(SIM_ARGS, op1, op2, op3, fmt)
822 1.1.1.10 christos uint64_t convert (SIM_STATE, int rm, uint64_t op, FP_formats from, FP_formats to);
823 1.1 christos #define Convert(rm,op,from,to) convert (SIM_ARGS, rm, op, from, to)
824 1.1.1.10 christos uint64_t convert_ps (SIM_STATE, int rm, uint64_t op, FP_formats from,
825 1.1 christos FP_formats to);
826 1.1 christos #define ConvertPS(rm,op,from,to) convert_ps (SIM_ARGS, rm, op, from, to)
827 1.1 christos
828 1.1 christos
829 1.1 christos /* MIPS-3D ASE operations. */
830 1.1 christos #define CompareAbs(op1,op2,fmt,cond,cc) \
831 1.1 christos fp_cmp(SIM_ARGS, op1, op2, fmt, 1, cond, cc)
832 1.1.1.10 christos uint64_t fp_add_r (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
833 1.1 christos #define AddR(op1,op2,fmt) fp_add_r(SIM_ARGS, op1, op2, fmt)
834 1.1.1.10 christos uint64_t fp_mul_r (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
835 1.1 christos #define MultiplyR(op1,op2,fmt) fp_mul_r(SIM_ARGS, op1, op2, fmt)
836 1.1.1.10 christos uint64_t fp_recip1 (SIM_STATE, uint64_t op, FP_formats fmt);
837 1.1 christos #define Recip1(op,fmt) fp_recip1(SIM_ARGS, op, fmt)
838 1.1.1.10 christos uint64_t fp_recip2 (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
839 1.1 christos #define Recip2(op1,op2,fmt) fp_recip2(SIM_ARGS, op1, op2, fmt)
840 1.1.1.10 christos uint64_t fp_rsqrt1 (SIM_STATE, uint64_t op, FP_formats fmt);
841 1.1 christos #define RSquareRoot1(op,fmt) fp_rsqrt1(SIM_ARGS, op, fmt)
842 1.1.1.10 christos uint64_t fp_rsqrt2 (SIM_STATE, uint64_t op1, uint64_t op2, FP_formats fmt);
843 1.1 christos #define RSquareRoot2(op1,op2,fmt) fp_rsqrt2(SIM_ARGS, op1, op2, fmt)
844 1.1 christos
845 1.1 christos
846 1.1 christos /* MDMX access. */
847 1.1 christos
848 1.1 christos typedef unsigned int MX_fmtsel; /* MDMX format select field (5 bits). */
849 1.1 christos #define ob_fmtsel(sel) (((sel)<<1)|0x0)
850 1.1 christos #define qh_fmtsel(sel) (((sel)<<2)|0x1)
851 1.1 christos
852 1.1 christos #define fmt_mdmx fmt_uninterpreted
853 1.1 christos
854 1.1 christos #define MX_VECT_AND (0)
855 1.1 christos #define MX_VECT_NOR (1)
856 1.1 christos #define MX_VECT_OR (2)
857 1.1 christos #define MX_VECT_XOR (3)
858 1.1 christos #define MX_VECT_SLL (4)
859 1.1 christos #define MX_VECT_SRL (5)
860 1.1 christos #define MX_VECT_ADD (6)
861 1.1 christos #define MX_VECT_SUB (7)
862 1.1 christos #define MX_VECT_MIN (8)
863 1.1 christos #define MX_VECT_MAX (9)
864 1.1 christos #define MX_VECT_MUL (10)
865 1.1 christos #define MX_VECT_MSGN (11)
866 1.1 christos #define MX_VECT_SRA (12)
867 1.1 christos #define MX_VECT_ABSD (13) /* SB-1 only. */
868 1.1 christos #define MX_VECT_AVG (14) /* SB-1 only. */
869 1.1 christos
870 1.1.1.10 christos uint64_t mdmx_cpr_op (SIM_STATE, int op, uint64_t op1, int vt, MX_fmtsel fmtsel);
871 1.1 christos #define MX_Add(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_ADD, op1, vt, fmtsel)
872 1.1 christos #define MX_And(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_AND, op1, vt, fmtsel)
873 1.1 christos #define MX_Max(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_MAX, op1, vt, fmtsel)
874 1.1 christos #define MX_Min(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_MIN, op1, vt, fmtsel)
875 1.1 christos #define MX_Msgn(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_MSGN, op1, vt, fmtsel)
876 1.1 christos #define MX_Mul(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_MUL, op1, vt, fmtsel)
877 1.1 christos #define MX_Nor(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_NOR, op1, vt, fmtsel)
878 1.1 christos #define MX_Or(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_OR, op1, vt, fmtsel)
879 1.1 christos #define MX_ShiftLeftLogical(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_SLL, op1, vt, fmtsel)
880 1.1 christos #define MX_ShiftRightArith(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_SRA, op1, vt, fmtsel)
881 1.1 christos #define MX_ShiftRightLogical(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_SRL, op1, vt, fmtsel)
882 1.1 christos #define MX_Sub(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_SUB, op1, vt, fmtsel)
883 1.1 christos #define MX_Xor(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_XOR, op1, vt, fmtsel)
884 1.1 christos #define MX_AbsDiff(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_ABSD, op1, vt, fmtsel)
885 1.1 christos #define MX_Avg(op1,vt,fmtsel) mdmx_cpr_op(SIM_ARGS, MX_VECT_AVG, op1, vt, fmtsel)
886 1.1 christos
887 1.1 christos #define MX_C_EQ 0x1
888 1.1 christos #define MX_C_LT 0x4
889 1.1 christos
890 1.1.1.10 christos void mdmx_cc_op (SIM_STATE, int cond, uint64_t op1, int vt, MX_fmtsel fmtsel);
891 1.1 christos #define MX_Comp(op1,cond,vt,fmtsel) mdmx_cc_op(SIM_ARGS, cond, op1, vt, fmtsel)
892 1.1 christos
893 1.1.1.10 christos uint64_t mdmx_pick_op (SIM_STATE, int tf, uint64_t op1, int vt, MX_fmtsel fmtsel);
894 1.1 christos #define MX_Pick(tf,op1,vt,fmtsel) mdmx_pick_op(SIM_ARGS, tf, op1, vt, fmtsel)
895 1.1 christos
896 1.1 christos #define MX_VECT_ADDA (0)
897 1.1 christos #define MX_VECT_ADDL (1)
898 1.1 christos #define MX_VECT_MULA (2)
899 1.1 christos #define MX_VECT_MULL (3)
900 1.1 christos #define MX_VECT_MULS (4)
901 1.1 christos #define MX_VECT_MULSL (5)
902 1.1 christos #define MX_VECT_SUBA (6)
903 1.1 christos #define MX_VECT_SUBL (7)
904 1.1 christos #define MX_VECT_ABSDA (8) /* SB-1 only. */
905 1.1 christos
906 1.1.1.10 christos void mdmx_acc_op (SIM_STATE, int op, uint64_t op1, int vt, MX_fmtsel fmtsel);
907 1.1 christos #define MX_AddA(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_ADDA, op1, vt, fmtsel)
908 1.1 christos #define MX_AddL(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_ADDL, op1, vt, fmtsel)
909 1.1 christos #define MX_MulA(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_MULA, op1, vt, fmtsel)
910 1.1 christos #define MX_MulL(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_MULL, op1, vt, fmtsel)
911 1.1 christos #define MX_MulS(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_MULS, op1, vt, fmtsel)
912 1.1 christos #define MX_MulSL(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_MULSL, op1, vt, fmtsel)
913 1.1 christos #define MX_SubA(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_SUBA, op1, vt, fmtsel)
914 1.1 christos #define MX_SubL(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_SUBL, op1, vt, fmtsel)
915 1.1 christos #define MX_AbsDiffC(op1,vt,fmtsel) mdmx_acc_op(SIM_ARGS, MX_VECT_ABSDA, op1, vt, fmtsel)
916 1.1 christos
917 1.1 christos #define MX_FMT_OB (0)
918 1.1 christos #define MX_FMT_QH (1)
919 1.1 christos
920 1.1 christos /* The following codes chosen to indicate the units of shift. */
921 1.1 christos #define MX_RAC_L (0)
922 1.1 christos #define MX_RAC_M (1)
923 1.1 christos #define MX_RAC_H (2)
924 1.1 christos
925 1.1.1.10 christos uint64_t mdmx_rac_op (SIM_STATE, int, int);
926 1.1 christos #define MX_RAC(op,fmt) mdmx_rac_op(SIM_ARGS, op, fmt)
927 1.1 christos
928 1.1.1.10 christos void mdmx_wacl (SIM_STATE, int, uint64_t, uint64_t);
929 1.1 christos #define MX_WACL(fmt,vs,vt) mdmx_wacl(SIM_ARGS, fmt, vs, vt)
930 1.1.1.10 christos void mdmx_wach (SIM_STATE, int, uint64_t);
931 1.1 christos #define MX_WACH(fmt,vs) mdmx_wach(SIM_ARGS, fmt, vs)
932 1.1 christos
933 1.1 christos #define MX_RND_AS (0)
934 1.1 christos #define MX_RND_AU (1)
935 1.1 christos #define MX_RND_ES (2)
936 1.1 christos #define MX_RND_EU (3)
937 1.1 christos #define MX_RND_ZS (4)
938 1.1 christos #define MX_RND_ZU (5)
939 1.1 christos
940 1.1.1.10 christos uint64_t mdmx_round_op (SIM_STATE, int, int, MX_fmtsel);
941 1.1 christos #define MX_RNAS(vt,fmt) mdmx_round_op(SIM_ARGS, MX_RND_AS, vt, fmt)
942 1.1 christos #define MX_RNAU(vt,fmt) mdmx_round_op(SIM_ARGS, MX_RND_AU, vt, fmt)
943 1.1 christos #define MX_RNES(vt,fmt) mdmx_round_op(SIM_ARGS, MX_RND_ES, vt, fmt)
944 1.1 christos #define MX_RNEU(vt,fmt) mdmx_round_op(SIM_ARGS, MX_RND_EU, vt, fmt)
945 1.1 christos #define MX_RZS(vt,fmt) mdmx_round_op(SIM_ARGS, MX_RND_ZS, vt, fmt)
946 1.1 christos #define MX_RZU(vt,fmt) mdmx_round_op(SIM_ARGS, MX_RND_ZU, vt, fmt)
947 1.1 christos
948 1.1.1.10 christos uint64_t mdmx_shuffle (SIM_STATE, int, uint64_t, uint64_t);
949 1.1 christos #define MX_SHFL(shop,op1,op2) mdmx_shuffle(SIM_ARGS, shop, op1, op2)
950 1.1 christos
951 1.1 christos
952 1.1 christos
953 1.1 christos /* Memory accesses */
954 1.1 christos
955 1.1 christos /* The following are generic to all versions of the MIPS architecture
956 1.1 christos to date: */
957 1.1 christos
958 1.1 christos #define isINSTRUCTION (1 == 0) /* FALSE */
959 1.1 christos #define isDATA (1 == 1) /* TRUE */
960 1.1 christos #define isLOAD (1 == 0) /* FALSE */
961 1.1 christos #define isSTORE (1 == 1) /* TRUE */
962 1.1 christos #define isREAL (1 == 0) /* FALSE */
963 1.1 christos #define isRAW (1 == 1) /* TRUE */
964 1.1 christos /* The parameter HOST (isTARGET / isHOST) is ignored */
965 1.1 christos #define isTARGET (1 == 0) /* FALSE */
966 1.1 christos /* #define isHOST (1 == 1) TRUE */
967 1.1 christos
968 1.1 christos /* The "AccessLength" specifications for Loads and Stores. NOTE: This
969 1.1 christos is the number of bytes minus 1. */
970 1.1 christos #define AccessLength_BYTE (0)
971 1.1 christos #define AccessLength_HALFWORD (1)
972 1.1 christos #define AccessLength_TRIPLEBYTE (2)
973 1.1 christos #define AccessLength_WORD (3)
974 1.1 christos #define AccessLength_QUINTIBYTE (4)
975 1.1 christos #define AccessLength_SEXTIBYTE (5)
976 1.1 christos #define AccessLength_SEPTIBYTE (6)
977 1.1 christos #define AccessLength_DOUBLEWORD (7)
978 1.1 christos #define AccessLength_QUADWORD (15)
979 1.1 christos
980 1.1 christos #define LOADDRMASK (WITH_TARGET_WORD_BITSIZE == 64 \
981 1.1 christos ? AccessLength_DOUBLEWORD /*7*/ \
982 1.1 christos : AccessLength_WORD /*3*/)
983 1.1 christos
984 1.1.1.3 christos INLINE_SIM_MAIN (void) load_memory (SIM_DESC sd, sim_cpu *cpu, address_word cia, uword64* memvalp, uword64* memval1p, int CCA, unsigned int AccessLength, address_word pAddr, address_word vAddr, int IorD);
985 1.1.1.6 christos #define LoadMemory(memvalp,memval1p,AccessLength,pAddr,vAddr,IorD,raw) \
986 1.1.1.6 christos load_memory (SD, CPU, cia, memvalp, memval1p, 0, AccessLength, pAddr, vAddr, IorD)
987 1.1 christos
988 1.1.1.3 christos INLINE_SIM_MAIN (void) store_memory (SIM_DESC sd, sim_cpu *cpu, address_word cia, int CCA, unsigned int AccessLength, uword64 MemElem, uword64 MemElem1, address_word pAddr, address_word vAddr);
989 1.1.1.6 christos #define StoreMemory(AccessLength,MemElem,MemElem1,pAddr,vAddr,raw) \
990 1.1.1.6 christos store_memory (SD, CPU, cia, 0, AccessLength, MemElem, MemElem1, pAddr, vAddr)
991 1.1 christos
992 1.1.1.3 christos INLINE_SIM_MAIN (void) cache_op (SIM_DESC sd, sim_cpu *cpu, address_word cia, int op, address_word pAddr, address_word vAddr, unsigned int instruction);
993 1.1 christos #define CacheOp(op,pAddr,vAddr,instruction) \
994 1.1 christos cache_op (SD, CPU, cia, op, pAddr, vAddr, instruction)
995 1.1 christos
996 1.1.1.3 christos INLINE_SIM_MAIN (void) sync_operation (SIM_DESC sd, sim_cpu *cpu, address_word cia, int stype);
997 1.1 christos #define SyncOperation(stype) \
998 1.1 christos sync_operation (SD, CPU, cia, (stype))
999 1.1 christos
1000 1.1 christos void unpredictable_action (sim_cpu *cpu, address_word cia);
1001 1.1 christos #define NotWordValue(val) not_word_value (SD_, (val))
1002 1.1 christos #define Unpredictable() unpredictable (SD_)
1003 1.1 christos #define UnpredictableResult() /* For now, do nothing. */
1004 1.1 christos
1005 1.1.1.10 christos INLINE_SIM_MAIN (uint32_t) ifetch32 (SIM_DESC sd, sim_cpu *cpu, address_word cia, address_word vaddr);
1006 1.1 christos #define IMEM32(CIA) ifetch32 (SD, CPU, (CIA), (CIA))
1007 1.1.1.10 christos INLINE_SIM_MAIN (uint16_t) ifetch16 (SIM_DESC sd, sim_cpu *cpu, address_word cia, address_word vaddr);
1008 1.1 christos #define IMEM16(CIA) ifetch16 (SD, CPU, (CIA), ((CIA) & ~1))
1009 1.1 christos #define IMEM16_IMMED(CIA,NR) ifetch16 (SD, CPU, (CIA), ((CIA) & ~1) + 2 * (NR))
1010 1.1.1.6 christos #define IMEM32_MICROMIPS(CIA) \
1011 1.1.1.6 christos (ifetch16 (SD, CPU, (CIA), (CIA)) << 16 | ifetch16 (SD, CPU, (CIA + 2), \
1012 1.1.1.6 christos (CIA + 2)))
1013 1.1.1.6 christos #define IMEM16_MICROMIPS(CIA) ifetch16 (SD, CPU, (CIA), ((CIA)))
1014 1.1.1.6 christos
1015 1.1.1.6 christos #define MICROMIPS_MINOR_OPCODE(INSN) ((INSN & 0x1C00) >> 10)
1016 1.1.1.6 christos
1017 1.1.1.6 christos #define MICROMIPS_DELAYSLOT_SIZE_ANY 0
1018 1.1.1.6 christos #define MICROMIPS_DELAYSLOT_SIZE_16 2
1019 1.1.1.6 christos #define MICROMIPS_DELAYSLOT_SIZE_32 4
1020 1.1.1.6 christos
1021 1.1.1.6 christos extern int isa_mode;
1022 1.1.1.6 christos
1023 1.1.1.6 christos #define ISA_MODE_MIPS32 0
1024 1.1.1.6 christos #define ISA_MODE_MICROMIPS 1
1025 1.1.1.6 christos
1026 1.1.1.6 christos address_word micromips_instruction_decode (SIM_DESC sd, sim_cpu * cpu,
1027 1.1.1.6 christos address_word cia,
1028 1.1.1.6 christos int instruction_size);
1029 1.1 christos
1030 1.1.1.5 christos #if WITH_TRACE_ANY_P
1031 1.1.1.11 christos void dotrace (SIM_DESC sd, sim_cpu *cpu, FILE *tracefh, int type, address_word address, int width, const char *comment, ...) ATTRIBUTE_PRINTF (7, 8);
1032 1.1 christos extern FILE *tracefh;
1033 1.1.1.5 christos #else
1034 1.1.1.5 christos #define dotrace(sd, cpu, tracefh, type, address, width, comment, ...)
1035 1.1.1.5 christos #endif
1036 1.1 christos
1037 1.1 christos extern int DSPLO_REGNUM[4];
1038 1.1 christos extern int DSPHI_REGNUM[4];
1039 1.1 christos
1040 1.1.1.3 christos INLINE_SIM_MAIN (void) pending_tick (SIM_DESC sd, sim_cpu *cpu, address_word cia);
1041 1.1.1.11 christos extern SIM_CORE_SIGNAL_FN mips_core_signal ATTRIBUTE_NORETURN;
1042 1.1 christos
1043 1.1.1.11 christos char* pr_addr (address_word addr);
1044 1.1.1.3 christos char* pr_uword64 (uword64 addr);
1045 1.1 christos
1046 1.1 christos
1047 1.1 christos #define GPR_CLEAR(N) do { GPR_SET((N),0); } while (0)
1048 1.1 christos
1049 1.1 christos void mips_cpu_exception_trigger(SIM_DESC sd, sim_cpu* cpu, address_word pc);
1050 1.1 christos void mips_cpu_exception_suspend(SIM_DESC sd, sim_cpu* cpu, int exception);
1051 1.1 christos void mips_cpu_exception_resume(SIM_DESC sd, sim_cpu* cpu, int exception);
1052 1.1 christos
1053 1.1 christos /* Macros for determining whether a MIPS IV or MIPS V part is subject
1054 1.1 christos to the hi/lo restrictions described in mips.igen. */
1055 1.1 christos
1056 1.1 christos #define MIPS_MACH_HAS_MT_HILO_HAZARD(SD) \
1057 1.1.1.11 christos (STATE_ARCHITECTURE (SD)->mach != bfd_mach_mips5500)
1058 1.1 christos
1059 1.1 christos #define MIPS_MACH_HAS_MULT_HILO_HAZARD(SD) \
1060 1.1.1.11 christos (STATE_ARCHITECTURE (SD)->mach != bfd_mach_mips5500)
1061 1.1 christos
1062 1.1 christos #define MIPS_MACH_HAS_DIV_HILO_HAZARD(SD) \
1063 1.1.1.11 christos (STATE_ARCHITECTURE (SD)->mach != bfd_mach_mips5500)
1064 1.1 christos
1065 1.1 christos #if H_REVEALS_MODULE_P (SIM_MAIN_INLINE)
1066 1.1 christos #include "sim-main.c"
1067 1.1 christos #endif
1068 1.1 christos
1069 1.1 christos #endif
1070