Commit | Line | Data |
---|---|---|
a325a02e | 1 | /* run front end support for arm |
0ab92fe7 | 2 | Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. |
a325a02e | 3 | |
87e43259 | 4 | This file is part of ARM SIM. |
a325a02e SC |
5 | |
6 | GNU CC 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 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC 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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
87e43259 AC |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | /* This file provides the interface between the simulator and run.c and gdb | |
21 | (when the simulator is linked with gdb). | |
22 | All simulator interaction should go through this file. */ | |
a325a02e SC |
23 | |
24 | #include <stdio.h> | |
25 | #include <stdarg.h> | |
a325a02e SC |
26 | #include <bfd.h> |
27 | #include <signal.h> | |
28 | #include "callback.h" | |
29 | #include "remote-sim.h" | |
87e43259 AC |
30 | #include "armdefs.h" |
31 | #include "armemu.h" | |
32 | #include "dbg_rdi.h" | |
33 | ||
34 | host_callback *sim_callback; | |
35 | ||
a325a02e SC |
36 | static struct ARMul_State *state; |
37 | ||
0ab92fe7 DE |
38 | /* Who is using the simulator. */ |
39 | static SIM_OPEN_KIND sim_kind; | |
40 | ||
41 | /* argv[0] */ | |
42 | static char *myname; | |
43 | ||
87e43259 AC |
44 | /* Memory size in bytes. */ |
45 | static int mem_size = (1 << 21); | |
46 | ||
47 | /* Non-zero to display start up banner, and maybe other things. */ | |
48 | static int verbosity; | |
49 | ||
a325a02e SC |
50 | static void |
51 | init () | |
52 | { | |
53 | static int done; | |
87e43259 | 54 | |
a325a02e SC |
55 | if (!done) |
56 | { | |
57 | ARMul_EmulateInit(); | |
58 | state = ARMul_NewState (); | |
87e43259 | 59 | ARMul_MemoryInit(state, mem_size); |
a325a02e SC |
60 | ARMul_OSInit(state); |
61 | ARMul_CoProInit(state); | |
87e43259 | 62 | state->verbose = verbosity; |
a325a02e SC |
63 | done = 1; |
64 | } | |
a325a02e SC |
65 | } |
66 | ||
87e43259 AC |
67 | /* Set verbosity level of simulator. |
68 | This is not intended to produce detailed tracing or debugging information. | |
69 | Just summaries. */ | |
70 | /* FIXME: common/run.c doesn't do this yet. */ | |
a325a02e | 71 | |
87e43259 AC |
72 | void |
73 | sim_set_verbose (v) | |
74 | int v; | |
75 | { | |
76 | verbosity = v; | |
a325a02e SC |
77 | } |
78 | ||
87e43259 AC |
79 | /* Set the memory size to SIZE bytes. |
80 | Must be called before initializing simulator. */ | |
81 | /* FIXME: Rename to sim_set_mem_size. */ | |
82 | ||
a325a02e SC |
83 | void |
84 | sim_size (size) | |
85 | int size; | |
86 | { | |
87e43259 | 87 | mem_size = size; |
a325a02e SC |
88 | } |
89 | ||
a325a02e | 90 | void |
87e43259 | 91 | ARMul_ConsolePrint (ARMul_State * state, const char *format,...) |
a325a02e | 92 | { |
87e43259 AC |
93 | va_list ap; |
94 | ||
95 | if (state->verbose) | |
96 | { | |
97 | va_start (ap, format); | |
98 | vprintf (format, ap); | |
99 | va_end (ap); | |
100 | } | |
a325a02e | 101 | } |
87e43259 AC |
102 | |
103 | ARMword | |
104 | ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr) | |
a325a02e | 105 | { |
87e43259 | 106 | |
a325a02e SC |
107 | } |
108 | ||
109 | int | |
87e43259 AC |
110 | sim_write (sd, addr, buffer, size) |
111 | SIM_DESC sd; | |
a325a02e SC |
112 | SIM_ADDR addr; |
113 | unsigned char *buffer; | |
114 | int size; | |
115 | { | |
116 | int i; | |
117 | init (); | |
118 | for (i = 0; i < size; i++) | |
119 | { | |
120 | ARMul_WriteByte (state, addr+i, buffer[i]); | |
121 | } | |
122 | return size; | |
123 | } | |
124 | ||
125 | int | |
87e43259 AC |
126 | sim_read (sd, addr, buffer, size) |
127 | SIM_DESC sd; | |
a325a02e SC |
128 | SIM_ADDR addr; |
129 | unsigned char *buffer; | |
130 | int size; | |
131 | { | |
132 | int i; | |
133 | init (); | |
134 | for (i = 0; i < size; i++) | |
135 | { | |
136 | buffer[i] = ARMul_ReadByte (state, addr + i); | |
137 | } | |
138 | return size; | |
139 | } | |
140 | ||
87e43259 AC |
141 | int |
142 | sim_trace (sd) | |
143 | SIM_DESC sd; | |
a325a02e | 144 | { |
87e43259 AC |
145 | (*sim_callback->printf_filtered) (sim_callback, "This simulator does not support tracing\n"); |
146 | return 1; | |
a325a02e SC |
147 | } |
148 | ||
247fccde AC |
149 | int |
150 | sim_stop (sd) | |
151 | SIM_DESC sd; | |
152 | { | |
153 | return 0; | |
154 | } | |
155 | ||
a325a02e | 156 | void |
87e43259 AC |
157 | sim_resume (sd, step, siggnal) |
158 | SIM_DESC sd; | |
a325a02e SC |
159 | int step, siggnal; |
160 | { | |
87e43259 AC |
161 | state->EndCondition = 0; |
162 | ||
a325a02e SC |
163 | if (step) |
164 | { | |
87e43259 AC |
165 | state->Reg[15] = ARMul_DoInstr (state); |
166 | if (state->EndCondition == 0) | |
167 | state->EndCondition = RDIError_BreakpointReached; | |
a325a02e SC |
168 | } |
169 | else | |
170 | { | |
87e43259 | 171 | state->Reg[15] = ARMul_DoProg (state); |
a325a02e | 172 | } |
87e43259 AC |
173 | |
174 | FLUSHPIPE; | |
a325a02e SC |
175 | } |
176 | ||
0ab92fe7 DE |
177 | SIM_RC |
178 | sim_create_inferior (sd, argv, env) | |
87e43259 | 179 | SIM_DESC sd; |
a325a02e SC |
180 | char **argv; |
181 | char **env; | |
182 | { | |
0ab92fe7 | 183 | return SIM_RC_OK; |
a325a02e SC |
184 | } |
185 | ||
186 | void | |
87e43259 AC |
187 | sim_info (sd, verbose) |
188 | SIM_DESC sd; | |
a325a02e SC |
189 | int verbose; |
190 | { | |
191 | } | |
192 | ||
193 | ||
87e43259 | 194 | static int |
a325a02e SC |
195 | frommem (state, memory) |
196 | struct ARMul_State *state; | |
197 | unsigned char *memory; | |
198 | { | |
199 | if (state->bigendSig == HIGH) | |
200 | { | |
201 | return (memory[0] << 24) | |
202 | | (memory[1] << 16) | |
203 | | (memory[2] << 8) | |
204 | | (memory[3] << 0); | |
205 | } | |
206 | else | |
207 | { | |
208 | return (memory[3] << 24) | |
209 | | (memory[2] << 16) | |
210 | | (memory[1] << 8) | |
211 | | (memory[0] << 0); | |
212 | } | |
213 | } | |
214 | ||
215 | ||
87e43259 | 216 | static void |
a325a02e SC |
217 | tomem (state, memory, val) |
218 | struct ARMul_State *state; | |
219 | unsigned char *memory; | |
220 | int val; | |
221 | { | |
222 | if (state->bigendSig == HIGH) | |
223 | { | |
224 | memory[0] = val >> 24; | |
225 | memory[1] = val >> 16; | |
226 | memory[2] = val >> 8; | |
227 | memory[3] = val >> 0; | |
228 | } | |
229 | else | |
230 | { | |
231 | memory[3] = val >> 24; | |
232 | memory[2] = val >> 16; | |
233 | memory[1] = val >> 8; | |
234 | memory[0] = val >> 0; | |
235 | } | |
236 | } | |
237 | ||
238 | void | |
87e43259 AC |
239 | sim_store_register (sd, rn, memory) |
240 | SIM_DESC sd; | |
a325a02e SC |
241 | int rn; |
242 | unsigned char *memory; | |
243 | { | |
244 | init (); | |
245 | ARMul_SetReg(state, state->Mode, rn, frommem (state, memory)); | |
246 | } | |
247 | ||
248 | void | |
87e43259 AC |
249 | sim_fetch_register (sd, rn, memory) |
250 | SIM_DESC sd; | |
a325a02e SC |
251 | int rn; |
252 | unsigned char *memory; | |
253 | { | |
254 | init (); | |
255 | tomem (state, memory, ARMul_GetReg(state, state->Mode, rn)); | |
256 | } | |
257 | ||
258 | ||
259 | ||
260 | ||
87e43259 | 261 | SIM_DESC |
247fccde | 262 | sim_open (kind, ptr, abfd, argv) |
87e43259 | 263 | SIM_OPEN_KIND kind; |
247fccde AC |
264 | host_callback *ptr; |
265 | struct _bfd *abfd; | |
87e43259 | 266 | char **argv; |
a325a02e | 267 | { |
0ab92fe7 DE |
268 | sim_kind = kind; |
269 | myname = argv[0]; | |
247fccde | 270 | sim_callback = ptr; |
87e43259 | 271 | return (SIM_DESC) 1; |
a325a02e SC |
272 | } |
273 | ||
274 | void | |
87e43259 AC |
275 | sim_close (sd, quitting) |
276 | SIM_DESC sd; | |
a325a02e SC |
277 | int quitting; |
278 | { | |
279 | /* nothing to do */ | |
280 | } | |
281 | ||
0ab92fe7 DE |
282 | SIM_RC |
283 | sim_load (sd, prog, abfd, from_tty) | |
87e43259 | 284 | SIM_DESC sd; |
a325a02e | 285 | char *prog; |
0ab92fe7 | 286 | bfd *abfd; |
a325a02e SC |
287 | int from_tty; |
288 | { | |
0ab92fe7 DE |
289 | extern bfd *sim_load_file (); /* ??? Don't know where this should live. */ |
290 | bfd *prog_bfd; | |
291 | ||
292 | prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd, | |
293 | sim_kind == SIM_OPEN_DEBUG); | |
294 | if (prog_bfd == NULL) | |
295 | return SIM_RC_FAIL; | |
296 | ARMul_SetPC (state, bfd_get_start_address (prog_bfd)); | |
297 | if (abfd == NULL) | |
298 | bfd_close (prog_bfd); | |
299 | return SIM_RC_OK; | |
a325a02e SC |
300 | } |
301 | ||
302 | void | |
87e43259 AC |
303 | sim_stop_reason (sd, reason, sigrc) |
304 | SIM_DESC sd; | |
a325a02e SC |
305 | enum sim_stop *reason; |
306 | int *sigrc; | |
307 | { | |
87e43259 AC |
308 | if (state->EndCondition == 0) |
309 | { | |
310 | *reason = sim_exited; | |
311 | *sigrc = state->Reg[0] & 255; | |
312 | } | |
313 | else | |
314 | { | |
315 | *reason = sim_stopped; | |
316 | if (state->EndCondition == RDIError_BreakpointReached) | |
317 | *sigrc = SIGTRAP; | |
318 | else | |
319 | *sigrc = 0; | |
320 | } | |
a325a02e | 321 | } |
87e43259 | 322 | |
a325a02e | 323 | void |
87e43259 AC |
324 | sim_do_command (sd, cmd) |
325 | SIM_DESC sd; | |
a325a02e SC |
326 | char *cmd; |
327 | { | |
87e43259 | 328 | (*sim_callback->printf_filtered) (sim_callback, "This simulator does not accept any commands.\n"); |
a325a02e SC |
329 | } |
330 | ||
331 | ||
332 | void | |
247fccde | 333 | sim_set_callbacks (ptr) |
87e43259 | 334 | host_callback *ptr; |
a325a02e | 335 | { |
87e43259 | 336 | sim_callback = ptr; |
a325a02e | 337 | } |