Commit | Line | Data |
---|---|---|
b9c8cd10 DE |
1 | # This shell script emits a C file. -*- C -*- |
2 | # Generate the main loop of the simulator. | |
3 | # Syntax: genmloop.sh mono|multi cpu mainloop.in | |
4 | # FIXME: "multi" support is wip. | |
5 | ||
6 | type=$1 | |
7 | cpu=$2 | |
8 | file=$3 | |
9 | ||
10 | cat <<EOF | |
11 | /* This file is is generated by the genmloop script. DO NOT EDIT! */ | |
12 | ||
13 | /* Main loop for CGEN-based simulators. | |
14 | Copyright (C) 1996, 1997 Free Software Foundation, Inc. | |
15 | Contributed by Cygnus Support. | |
16 | ||
17 | This file is part of GDB, the GNU debugger. | |
18 | ||
19 | This program is free software; you can redistribute it and/or modify | |
20 | it under the terms of the GNU General Public License as published by | |
21 | the Free Software Foundation; either version 2, or (at your option) | |
22 | any later version. | |
23 | ||
24 | This program is distributed in the hope that it will be useful, | |
25 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27 | GNU General Public License for more details. | |
28 | ||
29 | You should have received a copy of the GNU General Public License along | |
30 | with this program; if not, write to the Free Software Foundation, Inc., | |
31 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
32 | ||
33 | /* We want the simcache version of SEM_ARG. */ | |
34 | #define SCACHE_P | |
35 | ||
36 | #include "sim-main.h" | |
37 | #include "bfd.h" | |
3e324f89 DE |
38 | #include "mem-ops.h" |
39 | #include "sem-ops.h" | |
b9c8cd10 DE |
40 | #include "cgen-scache.h" |
41 | #include "cpu-opc.h" | |
42 | #include "cpu-sim.h" | |
43 | ||
44 | /* Tell sim_main_loop to use the cache if it's active. | |
45 | Collecting profile data and tracing slow us down so we don't do them in | |
46 | "fast mode". | |
47 | There are 2 possibilities on 2 axes: | |
48 | - use or don't use the cache | |
49 | - run normally (full featured) or run fast | |
50 | Supporting all four possibilities in one executable is a bit much but | |
51 | supporting normal/fast seems reasonable. | |
52 | If the cache is configured in it is always used. | |
53 | ??? Need to see whether it speeds up profiling significantly or not. | |
54 | Speeding up tracing doesn't seem worth it. | |
55 | ??? Sometimes supporting more than one set of semantic functions will make | |
56 | the simulator too large - this should be configurable. | |
57 | */ | |
58 | ||
59 | #if WITH_SCACHE | |
60 | #define RUN_FAST_P(cpu) (STATE_RUN_FAST_P (CPU_STATE (cpu))) | |
61 | #else | |
62 | #define RUN_FAST_P(cpu) 0 | |
63 | #endif | |
64 | ||
65 | #ifndef SIM_PRE_EXEC_HOOK | |
66 | #define SIM_PRE_EXEC_HOOK(state) | |
67 | #endif | |
68 | ||
69 | #ifndef SIM_POST_EXEC_HOOK | |
70 | #define SIM_POST_EXEC_HOOK(state) | |
71 | #endif | |
72 | ||
73 | EOF | |
74 | ||
75 | ${SHELL} $file support | |
76 | ||
77 | cat <<EOF | |
78 | ||
79 | static volatile int keep_running; | |
80 | ||
81 | int | |
82 | engine_stop (SIM_DESC sd) | |
83 | { | |
84 | keep_running = 0; | |
85 | return 1; | |
86 | } | |
87 | ||
88 | void | |
89 | engine_run (SIM_DESC sd, int step, int siggnal) | |
90 | { | |
91 | current_state = sd; | |
92 | #if WITH_SCACHE | |
93 | if (USING_SCACHE_P (sd)) | |
94 | scache_flush (sd); | |
95 | #endif | |
96 | engine_resume (sd, step, siggnal); | |
97 | } | |
98 | ||
99 | void | |
100 | engine_resume (SIM_DESC sd, int step, int siggnal) | |
101 | { | |
102 | #ifdef __STDC__ | |
103 | /* These are volatile to survive setjmp/longjmp. | |
104 | This will slow down the simulation a teensy bit, but we want to | |
105 | measure simulator speed even in fast mode. */ | |
106 | volatile unsigned long insn_count; | |
107 | volatile SIM_ELAPSED_TIME start_time; | |
108 | #else | |
109 | /* ??? Not sure what to do for K&R C. */ | |
110 | static unsigned long insn_count; | |
111 | static SIM_ELAPSED_TIME start_time; | |
112 | #endif | |
113 | SIM_DESC current_state = sd; | |
114 | sim_cpu *current_cpu = STATE_CPU (sd, 0); | |
115 | ||
116 | keep_running = 1; | |
117 | start_time = sim_elapsed_time_get (); | |
118 | insn_count = 0; | |
119 | ||
120 | if (setjmp (STATE_HALT_JMP_BUF (sd))) | |
121 | { | |
122 | TRACE_INSN_FINI (current_cpu); | |
123 | PROFILE_EXEC_TIME (CPU_PROFILE_DATA (current_cpu)) | |
124 | += sim_elapsed_time_since (start_time); | |
125 | PROFILE_TOTAL_INSN_COUNT (CPU_PROFILE_DATA (current_cpu)) | |
126 | += insn_count; | |
127 | return; | |
128 | } | |
129 | ||
130 | EOF | |
131 | ||
132 | # Any initialization code before looping starts. | |
133 | ${SHELL} $file init | |
134 | ||
135 | cat <<EOF | |
136 | ||
137 | /* ??? Restart support to be added in time. */ | |
138 | ||
139 | if (step | |
140 | || !RUN_FAST_P (current_cpu)) | |
141 | { | |
142 | do | |
143 | { | |
144 | #define FAST 0 /* ??? Hopefully this name won't collide with anything. */ | |
145 | /* FIXME: Later check every insn for events and such. */ | |
146 | ||
147 | SIM_PRE_EXEC_HOOK (current_cpu); | |
148 | ||
149 | EOF | |
150 | ||
151 | # Copy of main loop that uses the various compiled in features. | |
152 | # FIXME: May want more than one copy of this. | |
153 | ${SHELL} $file normal | |
154 | ||
155 | cat <<EOF | |
156 | ||
157 | SIM_POST_EXEC_HOOK (current_cpu); | |
158 | ||
c967f187 | 159 | ++insn_count; |
b9c8cd10 DE |
160 | if (step) |
161 | engine_halt (current_cpu, EXEC_STATE_STOPPED, SIM_SIGTRAP); | |
162 | } | |
163 | while (keep_running); | |
260b2c47 DE |
164 | /* If the loop exists, engine_stop was called. */ |
165 | engine_halt (current_cpu, EXEC_STATE_STOPPED, SIM_SIGINT); | |
b9c8cd10 DE |
166 | #undef FAST |
167 | } | |
168 | else | |
169 | { | |
170 | do | |
171 | { | |
172 | #define FAST 1 | |
173 | ||
174 | EOF | |
175 | ||
176 | # Copy of main loop that is run purely for fast execution. | |
177 | ${SHELL} $file fast | |
178 | ||
179 | cat <<EOF | |
180 | ||
181 | #undef FAST | |
182 | ++insn_count; | |
183 | } | |
184 | while (keep_running); | |
260b2c47 DE |
185 | /* If the loop exists, engine_stop was called. */ |
186 | engine_halt (current_cpu, EXEC_STATE_STOPPED, SIM_SIGINT); | |
b9c8cd10 DE |
187 | } |
188 | } | |
189 | EOF |