Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / sim / or1k / mloop.in
bloba1cb117dc61de989f8959653c661e1fd0802b9bc
1 # Simulator main loop for or1k. -*- C -*-
3 # Copyright (C) 2017-2023 Free Software Foundation, Inc.
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/>.
20 # Syntax:
21 # /bin/sh mainloop.in command
23 # Command is one of:
25 # init
26 # support
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, or if
32 # the slow (full featured) version is `simple', then the fast version can be
33 # one of scache/pbb.
34 # A target can't provide more than this.
35 # However for illustration's sake this file provides examples of all.
37 # ??? After a few more ports are done, revisit.
38 # Will eventually need to machine generate a lot of this.
40 case "x$1" in
42 xsupport)
44 cat <<EOF
45 #include <stdlib.h>
47 static INLINE const IDESC *
48 extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn,
49          ARGBUF *abuf, int fast_p)
51   const IDESC *id = @cpu@_decode (current_cpu, pc, insn, insn, abuf);
52   @cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
53   if (!fast_p)
54     {
55       int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
56       int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
57       @cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
58     }
59   return id;
62 static INLINE SEM_PC
63 execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
65   SEM_PC vpc = sc;
67   @cpu@_insn_before (current_cpu, vpc, sc->argbuf.idesc);
69   if (fast_p)
70     {
71 #if ! WITH_SEM_SWITCH_FAST
72 #if WITH_SCACHE
73       vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
74 #else
75       vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
76 #endif
77 #else
78       abort ();
79 #endif /* WITH_SEM_SWITCH_FAST */
80     }
81   else
82     {
83 #if ! WITH_SEM_SWITCH_FULL
84       ARGBUF *abuf = &sc->argbuf;
85       const IDESC *idesc = abuf->idesc;
86       const CGEN_INSN *idata = idesc->idata;
87 #if WITH_SCACHE_PBB
88       int virtual_p = CGEN_INSN_ATTR_VALUE (idata, CGEN_INSN_VIRTUAL);
89 #else
90       int virtual_p = 0;
91 #endif
93       if (! virtual_p)
94         {
95           /* FIXME: call x-before */
96           if (ARGBUF_PROFILE_P (abuf))
97             PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
98           /* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}.  */
99           if (PROFILE_MODEL_P (current_cpu)
100               && ARGBUF_PROFILE_P (abuf))
101             @cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
102           CGEN_TRACE_INSN_INIT (current_cpu, abuf, 1);
103           CGEN_TRACE_INSN (current_cpu, idata,
104                       (const struct argbuf *) abuf, abuf->addr);
105         }
106 #if WITH_SCACHE
107       vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
108 #else
109       vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
110 #endif
111       if (! virtual_p)
112         {
113           /* FIXME: call x-after */
114           if (PROFILE_MODEL_P (current_cpu)
115               && ARGBUF_PROFILE_P (abuf))
116             {
117               int cycles;
119               cycles = (*idesc->timing->model_fn) (current_cpu, sc);
120               @cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
121             }
122           CGEN_TRACE_INSN_FINI (current_cpu, abuf, 1);
123         }
124 #else
125       abort ();
126 #endif /* WITH_SEM_SWITCH_FULL */
127     }
129   @cpu@_insn_after (current_cpu, vpc, sc->argbuf.idesc);
131   return vpc;
138 xinit)
140 # Nothing needed.
144 xextract-simple | xextract-scache)
146 cat <<EOF
148   USI insn = GETIMEMUSI (current_cpu, pc);
149   extract (current_cpu, pc, insn, sc, FAST_P);
150   SEM_SKIP_COMPILE (current_cpu, sc, 1);
156 xextract-pbb)
158 # Inputs:  current_cpu, pc, sc, max_insns, FAST_P
159 # Outputs: sc, pc
160 # sc must be left pointing past the last created entry.
161 # pc must be left pointing past the last created entry.
162 # If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
163 # to record the vpc of the cti insn.
164 # SET_INSN_COUNT(n) must be called to record number of real insns.
166 cat <<EOF
168   const IDESC *idesc;
169   int icount = 0;
171   while (max_insns > 0) {
173     USI insn = GETIMEMUSI (current_cpu, pc);
175     idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
177     SEM_SKIP_COMPILE (current_cpu, sc, 1);
179     ++sc;
180     --max_insns;
181     ++icount;
182     pc += 4;
184     if (CGEN_ATTR_BOOLS (CGEN_INSN_ATTRS ((idesc)->idata)) & CGEN_ATTR_MASK (CGEN_INSN_FORCED_CTI))
185       {
187         SET_CTI_VPC (sc - 1);
189         break;
191       }
192     else if (CGEN_ATTR_BOOLS (CGEN_INSN_ATTRS ((idesc)->idata)) & CGEN_ATTR_MASK (CGEN_INSN_DELAYED_CTI))
193       {
195         /* handle delay slot */
196         SET_CTI_VPC (sc - 1);
198         insn = GETIMEMUSI (current_cpu, pc);
200         idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
202         ++sc;
203         --max_insns;
204         ++icount;
205         pc += 4;
207         break;
208       }
209   }
211   SET_INSN_COUNT (icount);
218 xfull-exec-* | xfast-exec-*)
220 # Inputs: current_cpu, vpc, FAST_P
221 # Outputs: vpc
222 # vpc is the virtual program counter.
224 cat <<EOF
225 #if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
226 #define DEFINE_SWITCH
227 #ifdef WANT_CPU_OR1K32BF
228 #include "sem-switch.c"
229 #endif
230 #else
231   vpc = execute (current_cpu, vpc, FAST_P);
232 #endif
238   echo "Invalid argument to mainloop.in: $1" >&2
239   exit 1
240   ;;
242 esac