1 # Simulator main loop for IQ2000. -*- C -*-
2 # Copyright (C) 1998-2024 Free Software Foundation, Inc.
3 # Contributed by Cygnus Solutions.
5 # This file is part of the GNU Simulators.
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/>.
21 # /bin/sh mainloop.in command
27 # extract-{simple,scache,pbb}
28 # {full,fast}-exec-{simple,scache,pbb}
30 # A target need only provide a "full" version of one of simple,scache,pbb.
31 # If the target wants it can also provide a fast version of same.
32 # It can't provide more than this, however for illustration's sake the IQ2000
33 # port provides examples of all.
35 # ??? After a few more ports are done, revisit.
36 # Will eventually need to machine generate a lot of this.
46 static INLINE const IDESC *
47 extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn, ARGBUF *abuf,
50 const IDESC *id = @cpu@_decode (current_cpu, pc, insn, insn, abuf);
51 @cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
54 int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
55 int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
56 @cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
62 execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
66 /* Force R0 to zero before every insn. */
67 @cpu@_h_gr_set (current_cpu, 0, 0);
71 #if ! WITH_SEM_SWITCH_FAST
73 vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
75 vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
79 #endif /* WITH_SEM_SWITCH_FAST */
83 #if ! WITH_SEM_SWITCH_FULL
84 ARGBUF *abuf = &sc->argbuf;
85 const IDESC *idesc = abuf->idesc;
87 int virtual_p = CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_VIRTUAL);
94 /* FIXME: call x-before */
95 if (ARGBUF_PROFILE_P (abuf))
96 PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
97 /* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
98 if (PROFILE_MODEL_P (current_cpu)
99 && ARGBUF_PROFILE_P (abuf))
100 @cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
101 CGEN_TRACE_INSN_INIT (current_cpu, abuf, 1);
102 CGEN_TRACE_INSN (current_cpu, idesc->idata,
103 (const struct argbuf *) abuf, abuf->addr);
106 vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
108 vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
112 /* FIXME: call x-after */
113 if (PROFILE_MODEL_P (current_cpu)
114 && ARGBUF_PROFILE_P (abuf))
118 cycles = (*idesc->timing->model_fn) (current_cpu, sc);
119 @cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
121 CGEN_TRACE_INSN_FINI (current_cpu, abuf, 1);
125 #endif /* WITH_SEM_SWITCH_FULL */
137 xextract-simple | xextract-scache)
139 # Inputs: current_cpu, vpc, sc, FAST_P
140 # Outputs: sc filled in
145 CGEN_INSN_INT insn = GETIMEMUSI (current_cpu, CPU2INSN(vpc));
146 extract (current_cpu, vpc, insn, SEM_ARGBUF (sc), FAST_P);
147 SEM_SKIP_COMPILE (current_cpu, sc, 1);
155 # Inputs: current_cpu, pc, sc, max_insns, FAST_P
157 # sc must be left pointing past the last created entry.
158 # pc must be left pointing past the last created entry.
159 # If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
160 # to record the vpc of the cti insn.
161 # SET_INSN_COUNT(n) must be called to record number of real insns.
169 /* Is the CTI instruction at the end of the PBB a likely branch? */
172 while (max_insns > 0)
174 USI insn = GETIMEMUSI (current_cpu, CPU2INSN(pc));
176 idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
177 SEM_SKIP_COMPILE (current_cpu, sc, 1);
183 if (IDESC_CTI_P (idesc))
185 /* Likely branches annul their delay slot if the branch is
186 not taken by using the (skip ..) rtx. We'll rely on
188 likely_cti = (IDESC_SKIP_P (idesc));
190 SET_CTI_VPC (sc - 1);
192 if (CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_DELAY_SLOT))
194 insn = GETIMEMUSI (current_cpu, CPU2INSN(pc));
195 idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
197 if (likely_cti && IDESC_CTI_P (idesc))
199 /* malformed program */
200 sim_io_eprintf (CPU_STATE (current_cpu),
201 "malformed program, \`%s' insn in branch likely delay slot\n",
202 CGEN_INSN_NAME (idesc->idata));
217 SET_INSN_COUNT (icount);
223 xfull-exec-* | xfast-exec-*)
225 # Inputs: current_cpu, sc, FAST_P
227 # vpc contains the address of the next insn to execute
232 #if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
233 #define DEFINE_SWITCH
234 #include "sem-switch.c"
236 vpc = execute (current_cpu, vpc, FAST_P);
244 echo "Invalid argument to mainloop.in: $1" >&2