1 # Simulator main loop for lm32. -*- C -*-
2 # Contributed by Jon Beniston <jon@beniston.com>
4 # This file is part of the GNU Simulators.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, see <http://www.gnu.org/licenses/>.
20 # /bin/sh mainloop.in command
26 # extract-{simple,scache,pbb}
27 # {full,fast}-exec-{simple,scache,pbb}
38 static INLINE const IDESC *
39 extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn,
40 ARGBUF *abuf, int fast_p)
42 const IDESC *id = @cpu@_decode (current_cpu, pc, insn, insn, abuf);
44 @cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
47 int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
48 int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
49 @cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
55 execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
61 #if ! WITH_SEM_SWITCH_FAST
63 vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
65 vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
69 #endif /* WITH_SEM_SWITCH_FAST */
73 #if ! WITH_SEM_SWITCH_FULL
74 ARGBUF *abuf = &sc->argbuf;
75 const IDESC *idesc = abuf->idesc;
76 const CGEN_INSN *idata = idesc->idata;
78 int virtual_p = CGEN_INSN_ATTR_VALUE (idata, CGEN_INSN_VIRTUAL);
84 /* FIXME: call x-before */
85 if (ARGBUF_PROFILE_P (abuf))
86 PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
87 /* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
88 if (PROFILE_MODEL_P (current_cpu)
89 && ARGBUF_PROFILE_P (abuf))
90 @cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
91 CGEN_TRACE_INSN_INIT (current_cpu, abuf, 1);
92 CGEN_TRACE_INSN (current_cpu, idata,
93 (const struct argbuf *) abuf, abuf->addr);
96 vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
98 vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
102 /* FIXME: call x-after */
103 if (PROFILE_MODEL_P (current_cpu)
104 && ARGBUF_PROFILE_P (abuf))
108 cycles = (*idesc->timing->model_fn) (current_cpu, sc);
109 @cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
111 CGEN_TRACE_INSN_FINI (current_cpu, abuf, 1);
115 #endif /* WITH_SEM_SWITCH_FULL */
131 xextract-simple | xextract-scache)
136 CGEN_INSN_INT insn = GETIMEMUSI (current_cpu, vpc);
137 extract (current_cpu, vpc, insn, SEM_ARGBUF (sc), FAST_P);
145 # Inputs: current_cpu, pc, sc, max_insns, FAST_P
147 # sc must be left pointing past the last created entry.
148 # pc must be left pointing past the last created entry.
149 # If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
150 # to record the vpc of the cti insn.
151 # SET_INSN_COUNT(n) must be called to record number of real insns.
159 while (max_insns > 0)
161 USI insn = GETIMEMUSI (current_cpu, pc);
163 idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
169 if (IDESC_CTI_P (idesc))
171 SET_CTI_VPC (sc - 1);
177 SET_INSN_COUNT (icount);
183 xfull-exec-* | xfast-exec-*)
185 # Inputs: current_cpu, vpc, FAST_P
190 /* Update cycle counter */
191 SET_H_CSR (LM32_CSR_CC, GET_H_CSR (LM32_CSR_CC) + 1);
192 #if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
193 #define DEFINE_SWITCH
194 #include "sem-switch.c"
196 vpc = execute (current_cpu, vpc, FAST_P);
203 echo "Invalid argument to mainloop.in: $1" >&2