]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/bpf/mloop.in
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / sim / bpf / mloop.in
1 # Simulator main loop for eBPF. -*- C -*-
2 #
3 # Copyright (C) 2020-2021 Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Simulators.
6 #
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.
11 #
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.
16 #
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/>.
19
20 # Syntax:
21 # /bin/sh mloop.in command
22 #
23 # Command is one of:
24 #
25 # init
26 # support
27 # extract-{simple,scache,pbb}
28 # {full,fast}-exec-{simple,scache,pbb}
29 #
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.
36
37 # ??? After a few more ports are done, revisit.
38 # Will eventually need to machine generate a lot of this.
39
40 case "x$1" in
41
42 xsupport)
43
44 cat <<EOF
45
46 static INLINE const IDESC *
47 extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_WORD insn,
48 ARGBUF *abuf, int fast_p)
49 {
50 const IDESC *id = @prefix@_decode (current_cpu, pc, insn, abuf);
51 @prefix@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
52 if (!fast_p)
53 {
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 @prefix@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
57 }
58 return id;
59 }
60
61 static INLINE SEM_PC
62 execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
63 {
64 SEM_PC vpc;
65
66 if (fast_p)
67 vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
68 else
69 {
70 ARGBUF *abuf = &sc->argbuf;
71 const IDESC *idesc = abuf->idesc;
72 const CGEN_INSN *idata = idesc->idata;
73 int virtual_p = 0;
74
75 if (! virtual_p)
76 {
77 /* FIXME: call x-before */
78 if (ARGBUF_PROFILE_P (abuf))
79 PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
80 /* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
81 if (PROFILE_MODEL_P (current_cpu)
82 && ARGBUF_PROFILE_P (abuf))
83 @cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
84 CGEN_TRACE_INSN_INIT (current_cpu, abuf, 1);
85 CGEN_TRACE_INSN (current_cpu, idata,
86 (const struct argbuf *) abuf, abuf->addr);
87 }
88 vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
89 if (! virtual_p)
90 {
91 /* FIXME: call x-after */
92 if (PROFILE_MODEL_P (current_cpu)
93 && ARGBUF_PROFILE_P (abuf))
94 {
95 int cycles;
96
97 cycles = (*idesc->timing->model_fn) (current_cpu, sc);
98 @cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
99 }
100 CGEN_TRACE_INSN_FINI (current_cpu, abuf, 1);
101 }
102 }
103
104 return vpc;
105 }
106
107 EOF
108
109 ;;
110
111 xinit)
112
113 # Nothing needed.
114
115 ;;
116
117 xextract-scache)
118
119 cat <<EOF
120 {
121
122 UDI insn = GETIMEMUDI (current_cpu, vpc);
123
124 if (current_target_byte_order == BFD_ENDIAN_BIG)
125 {
126 /* eBPF instructions are little-endian, but GETIMEMUDI reads according
127 to target byte order. Swap to little-endian. */
128 insn = SWAP_8 (insn);
129
130 /* But, the imm32 and offset16 fields within instructions follow target
131 byte order. Swap those fields back. */
132 UHI off16 = (UHI) ((insn & 0x00000000ffff0000) >> 16);
133 USI imm32 = (USI) ((insn & 0xffffffff00000000) >> 32);
134 off16 = SWAP_2 (off16);
135 imm32 = SWAP_4 (imm32);
136
137 insn = (((UDI) imm32) << 32) | (((UDI) off16) << 16) | (insn & 0xffff);
138 }
139
140 extract (current_cpu, vpc, insn, sc, FAST_P);
141
142 //XXX SEM_SKIP_COMPILE (current_cpu, sc, 1);
143 }
144 EOF
145
146 ;;
147
148 xfull-exec-* | xfast-exec-*)
149
150 # Inputs: current_cpu, vpc, sc, FAST_P
151 # Outputs: vpc
152 # vpc is the virtual program counter.
153
154 cat <<EOF
155 vpc = execute (current_cpu, sc, FAST_P);
156 EOF
157
158 ;;
159
160 *)
161 echo "Invalid argument to mainloop.in: $1" >&2
162 exit 1
163 ;;
164
165 esac