]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/arm/wrapper.c
Fix typo in ALIGN_N usage.
[thirdparty/binutils-gdb.git] / sim / arm / wrapper.c
CommitLineData
c906108c
SS
1/* run front end support for arm
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3
4This file is part of ARM SIM.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, 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. */
23
24#include <stdio.h>
25#include <stdarg.h>
26#include <bfd.h>
27#include <signal.h>
28#include "callback.h"
29#include "remote-sim.h"
30#include "armdefs.h"
31#include "armemu.h"
32#include "dbg_rdi.h"
33
34host_callback *sim_callback;
35
36static struct ARMul_State *state;
37
38/* Who is using the simulator. */
39static SIM_OPEN_KIND sim_kind;
40
41/* argv[0] */
42static char *myname;
43
44/* Memory size in bytes. */
45static int mem_size = (1 << 21);
46
47/* Non-zero to display start up banner, and maybe other things. */
48static int verbosity;
49
50/* Non-zero to set big endian mode. */
51static int big_endian;
52
7a292a7a
SS
53int stop_simulator;
54
c906108c
SS
55static void
56init ()
57{
58 static int done;
59
60 if (!done)
61 {
62 ARMul_EmulateInit();
63 state = ARMul_NewState ();
64 state->bigendSig = (big_endian ? HIGH : LOW);
65 ARMul_MemoryInit(state, mem_size);
66 ARMul_OSInit(state);
67 ARMul_CoProInit(state);
68 state->verbose = verbosity;
69 done = 1;
70 }
71}
72
73/* Set verbosity level of simulator.
74 This is not intended to produce detailed tracing or debugging information.
75 Just summaries. */
76/* FIXME: common/run.c doesn't do this yet. */
77
78void
79sim_set_verbose (v)
80 int v;
81{
82 verbosity = v;
83}
84
85/* Set the memory size to SIZE bytes.
86 Must be called before initializing simulator. */
87/* FIXME: Rename to sim_set_mem_size. */
88
89void
90sim_size (size)
91 int size;
92{
93 mem_size = size;
94}
95
96void
97ARMul_ConsolePrint (ARMul_State * state, const char *format,...)
98{
99 va_list ap;
100
101 if (state->verbose)
102 {
103 va_start (ap, format);
104 vprintf (format, ap);
105 va_end (ap);
106 }
107}
108
109ARMword
110ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr)
111{
112
113}
114
115int
116sim_write (sd, addr, buffer, size)
117 SIM_DESC sd;
118 SIM_ADDR addr;
119 unsigned char *buffer;
120 int size;
121{
122 int i;
123 init ();
124 for (i = 0; i < size; i++)
125 {
126 ARMul_WriteByte (state, addr+i, buffer[i]);
127 }
128 return size;
129}
130
131int
132sim_read (sd, addr, buffer, size)
133 SIM_DESC sd;
134 SIM_ADDR addr;
135 unsigned char *buffer;
136 int size;
137{
138 int i;
139 init ();
140 for (i = 0; i < size; i++)
141 {
142 buffer[i] = ARMul_ReadByte (state, addr + i);
143 }
144 return size;
145}
146
147int
148sim_trace (sd)
149 SIM_DESC sd;
150{
151 (*sim_callback->printf_filtered) (sim_callback, "This simulator does not support tracing\n");
152 return 1;
153}
154
155int
156sim_stop (sd)
157 SIM_DESC sd;
158{
7a292a7a
SS
159 state->Emulate = STOP;
160 stop_simulator = 1;
161 return 1;
c906108c
SS
162}
163
164void
165sim_resume (sd, step, siggnal)
166 SIM_DESC sd;
167 int step, siggnal;
168{
169 state->EndCondition = 0;
7a292a7a 170 stop_simulator = 0;
c906108c
SS
171
172 if (step)
173 {
174 state->Reg[15] = ARMul_DoInstr (state);
175 if (state->EndCondition == 0)
176 state->EndCondition = RDIError_BreakpointReached;
177 }
178 else
179 {
180#if 1 /* JGS */
181 state->NextInstr = RESUME; /* treat as PC change */
182#endif
183 state->Reg[15] = ARMul_DoProg (state);
184 }
185
186 FLUSHPIPE;
187}
188
189SIM_RC
190sim_create_inferior (sd, abfd, argv, env)
191 SIM_DESC sd;
192 struct _bfd *abfd;
193 char **argv;
194 char **env;
195{
196 int argvlen=0;
197 char **arg;
198
199 if (abfd != NULL)
200 ARMul_SetPC (state, bfd_get_start_address (abfd));
201 else
202 ARMul_SetPC (state, 0); /* ??? */
203
204#if 1 /* JGS */
205 /* We explicitly select a processor capable of supporting the ARM
206 32bit mode, and then we force the simulated CPU into the 32bit
207 User mode: */
208 ARMul_SelectProcessor(state, ARM600);
209 ARMul_SetCPSR(state, USER32MODE);
210#endif
211
212 if (argv != NULL)
213 {
214 /*
215 ** Set up the command line (by laboriously stringing together the
216 ** environment carefully picked apart by our caller...)
217 */
218 /* Free any old stuff */
219 if (state->CommandLine != NULL)
220 {
221 free(state->CommandLine);
222 state->CommandLine = NULL;
223 }
224
225 /* See how much we need */
226 for (arg = argv; *arg != NULL; arg++)
227 argvlen += strlen(*arg)+1;
228
229 /* allocate it... */
230 state->CommandLine = malloc(argvlen+1);
231 if (state->CommandLine != NULL)
232 {
233 arg = argv;
234 state->CommandLine[0]='\0';
235 for (arg = argv; *arg != NULL; arg++)
236 {
237 strcat(state->CommandLine, *arg);
238 strcat(state->CommandLine, " ");
239 }
240 }
241 }
242
243 if (env != NULL)
244 {
245 /* Now see if there's a MEMSIZE spec in the environment */
246 while (*env)
247 {
248 if (strncmp(*env, "MEMSIZE=", sizeof("MEMSIZE=")-1)==0)
249 {
250 unsigned long top_of_memory;
251 char *end_of_num;
252
253 /* Set up memory limit */
254 state->MemSize = strtoul(*env + sizeof("MEMSIZE=")-1, &end_of_num, 0);
255 }
256 env++;
257 }
258 }
259
260 return SIM_RC_OK;
261}
262
263void
264sim_info (sd, verbose)
265 SIM_DESC sd;
266 int verbose;
267{
268}
269
270
271static int
272frommem (state, memory)
273 struct ARMul_State *state;
274 unsigned char *memory;
275{
276 if (state->bigendSig == HIGH)
277 {
278 return (memory[0] << 24)
279 | (memory[1] << 16)
280 | (memory[2] << 8)
281 | (memory[3] << 0);
282 }
283 else
284 {
285 return (memory[3] << 24)
286 | (memory[2] << 16)
287 | (memory[1] << 8)
288 | (memory[0] << 0);
289 }
290}
291
292
293static void
294tomem (state, memory, val)
295 struct ARMul_State *state;
296 unsigned char *memory;
297 int val;
298{
299 if (state->bigendSig == HIGH)
300 {
301 memory[0] = val >> 24;
302 memory[1] = val >> 16;
303 memory[2] = val >> 8;
304 memory[3] = val >> 0;
305 }
306 else
307 {
308 memory[3] = val >> 24;
309 memory[2] = val >> 16;
310 memory[1] = val >> 8;
311 memory[0] = val >> 0;
312 }
313}
314
315int
316sim_store_register (sd, rn, memory, length)
317 SIM_DESC sd;
318 int rn;
319 unsigned char *memory;
320 int length;
321{
322 init ();
323 ARMul_SetReg(state, state->Mode, rn, frommem (state, memory));
324 return -1;
325}
326
327int
328sim_fetch_register (sd, rn, memory, length)
329 SIM_DESC sd;
330 int rn;
331 unsigned char *memory;
332 int length;
333{
334 ARMword regval;
335
336 init ();
337 if (rn < 16)
338 regval = ARMul_GetReg(state, state->Mode, rn);
339 else if (rn == 25) /* FIXME: use PS_REGNUM from gdb/config/arm/tm-arm.h */
340 regval = ARMul_GetCPSR(state);
341 else
342 regval = 0; /* FIXME: should report an error */
343 tomem (state, memory, regval);
344 return -1;
345}
346
347SIM_DESC
348sim_open (kind, ptr, abfd, argv)
349 SIM_OPEN_KIND kind;
350 host_callback *ptr;
351 struct _bfd *abfd;
352 char **argv;
353{
354 sim_kind = kind;
355 myname = argv[0];
356 sim_callback = ptr;
357
358 /* Decide upon the endian-ness of the processor.
359 If we can, get the information from the bfd itself.
360 Otherwise look to see if we have been given a command
361 line switch that tells us. Otherwise default to little endian. */
362 if (abfd != NULL)
363 big_endian = bfd_big_endian (abfd);
364 else if (argv[1] != NULL)
365 {
366 int i;
367
368 /* Scan for endian-ness switch. */
369 for (i = 0; (argv[i] != NULL) && (argv[i][0] != 0); i++)
370 if (argv[i][0] == '-' && argv[i][1] == 'E')
371 {
372 char c;
373
374 if ((c = argv[i][2]) == 0)
375 {
376 ++i;
377 c = argv[i][0];
378 }
379
380 switch (c)
381 {
382 case 0:
383 sim_callback->printf_filtered
384 (sim_callback, "No argument to -E option provided\n");
385 break;
386
387 case 'b':
388 case 'B':
389 big_endian = 1;
390 break;
391
392 case 'l':
393 case 'L':
394 big_endian = 0;
395 break;
396
397 default:
398 sim_callback->printf_filtered
399 (sim_callback, "Unrecognised argument to -E option\n");
400 break;
401 }
402 }
403 }
404
405 return (SIM_DESC) 1;
406}
407
408void
409sim_close (sd, quitting)
410 SIM_DESC sd;
411 int quitting;
412{
413 /* nothing to do */
414}
415
416SIM_RC
417sim_load (sd, prog, abfd, from_tty)
418 SIM_DESC sd;
419 char *prog;
420 bfd *abfd;
421 int from_tty;
422{
423 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
424 bfd *prog_bfd;
425
426 prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
427 sim_kind == SIM_OPEN_DEBUG,
428 0, sim_write);
429 if (prog_bfd == NULL)
430 return SIM_RC_FAIL;
431 ARMul_SetPC (state, bfd_get_start_address (prog_bfd));
432 if (abfd == NULL)
433 bfd_close (prog_bfd);
434 return SIM_RC_OK;
435}
436
437void
438sim_stop_reason (sd, reason, sigrc)
439 SIM_DESC sd;
440 enum sim_stop *reason;
441 int *sigrc;
442{
7a292a7a
SS
443 if (stop_simulator)
444 {
445 *reason = sim_stopped;
446 *sigrc = SIGINT;
447 }
448 else if (state->EndCondition == 0)
c906108c
SS
449 {
450 *reason = sim_exited;
451 *sigrc = state->Reg[0] & 255;
452 }
453 else
454 {
455 *reason = sim_stopped;
456 if (state->EndCondition == RDIError_BreakpointReached)
457 *sigrc = SIGTRAP;
458 else
459 *sigrc = 0;
460 }
461}
462
463void
464sim_do_command (sd, cmd)
465 SIM_DESC sd;
466 char *cmd;
467{
468 (*sim_callback->printf_filtered) (sim_callback, "This simulator does not accept any commands.\n");
469}
470
471
472void
473sim_set_callbacks (ptr)
474 host_callback *ptr;
475{
476 sim_callback = ptr;
477}