1995-10-13 23:06:30 +01:00
|
|
|
/* run front end support for arm
|
1997-04-17 11:41:11 +02:00
|
|
|
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
1995-10-13 23:06:30 +01:00
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
This file is part of ARM SIM.
|
1995-10-13 23:06:30 +01:00
|
|
|
|
|
|
|
GNU CC is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
GNU CC is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
1997-04-17 08:05:19 +02:00
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
/* This file provides the interface between the simulator and run.c and gdb
|
|
|
|
(when the simulator is linked with gdb).
|
|
|
|
All simulator interaction should go through this file. */
|
1995-10-13 23:06:30 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <bfd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include "callback.h"
|
|
|
|
#include "remote-sim.h"
|
1997-04-17 08:05:19 +02:00
|
|
|
#include "armdefs.h"
|
|
|
|
#include "armemu.h"
|
|
|
|
#include "dbg_rdi.h"
|
|
|
|
|
|
|
|
host_callback *sim_callback;
|
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
static struct ARMul_State *state;
|
|
|
|
|
1997-04-17 11:41:11 +02:00
|
|
|
/* Who is using the simulator. */
|
|
|
|
static SIM_OPEN_KIND sim_kind;
|
|
|
|
|
|
|
|
/* argv[0] */
|
|
|
|
static char *myname;
|
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
/* Memory size in bytes. */
|
|
|
|
static int mem_size = (1 << 21);
|
|
|
|
|
|
|
|
/* Non-zero to display start up banner, and maybe other things. */
|
|
|
|
static int verbosity;
|
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
static void
|
|
|
|
init ()
|
|
|
|
{
|
|
|
|
static int done;
|
1997-04-17 08:05:19 +02:00
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
if (!done)
|
|
|
|
{
|
|
|
|
ARMul_EmulateInit();
|
|
|
|
state = ARMul_NewState ();
|
1997-04-17 08:05:19 +02:00
|
|
|
ARMul_MemoryInit(state, mem_size);
|
1995-10-13 23:06:30 +01:00
|
|
|
ARMul_OSInit(state);
|
|
|
|
ARMul_CoProInit(state);
|
1997-04-17 08:05:19 +02:00
|
|
|
state->verbose = verbosity;
|
1995-10-13 23:06:30 +01:00
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
/* Set verbosity level of simulator.
|
|
|
|
This is not intended to produce detailed tracing or debugging information.
|
|
|
|
Just summaries. */
|
|
|
|
/* FIXME: common/run.c doesn't do this yet. */
|
1995-10-13 23:06:30 +01:00
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
void
|
|
|
|
sim_set_verbose (v)
|
|
|
|
int v;
|
|
|
|
{
|
|
|
|
verbosity = v;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
/* Set the memory size to SIZE bytes.
|
|
|
|
Must be called before initializing simulator. */
|
|
|
|
/* FIXME: Rename to sim_set_mem_size. */
|
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
void
|
|
|
|
sim_size (size)
|
|
|
|
int size;
|
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
mem_size = size;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
ARMul_ConsolePrint (ARMul_State * state, const char *format,...)
|
1995-10-13 23:06:30 +01:00
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (state->verbose)
|
|
|
|
{
|
|
|
|
va_start (ap, format);
|
|
|
|
vprintf (format, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
1997-04-17 08:05:19 +02:00
|
|
|
|
|
|
|
ARMword
|
|
|
|
ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr)
|
1995-10-13 23:06:30 +01:00
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_write (sd, addr, buffer, size)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
SIM_ADDR addr;
|
|
|
|
unsigned char *buffer;
|
|
|
|
int size;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
init ();
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
ARMul_WriteByte (state, addr+i, buffer[i]);
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_read (sd, addr, buffer, size)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
SIM_ADDR addr;
|
|
|
|
unsigned char *buffer;
|
|
|
|
int size;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
init ();
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
buffer[i] = ARMul_ReadByte (state, addr + i);
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
int
|
|
|
|
sim_trace (sd)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
(*sim_callback->printf_filtered) (sim_callback, "This simulator does not support tracing\n");
|
|
|
|
return 1;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
1997-08-26 01:14:25 +02:00
|
|
|
int
|
|
|
|
sim_stop (sd)
|
|
|
|
SIM_DESC sd;
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_resume (sd, step, siggnal)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
int step, siggnal;
|
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
state->EndCondition = 0;
|
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
if (step)
|
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
state->Reg[15] = ARMul_DoInstr (state);
|
|
|
|
if (state->EndCondition == 0)
|
|
|
|
state->EndCondition = RDIError_BreakpointReached;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
state->Reg[15] = ARMul_DoProg (state);
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
1997-04-17 08:05:19 +02:00
|
|
|
|
|
|
|
FLUSHPIPE;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
1997-04-17 11:41:11 +02:00
|
|
|
SIM_RC
|
1997-10-22 07:26:27 +02:00
|
|
|
sim_create_inferior (sd, abfd, argv, env)
|
1997-04-17 08:05:19 +02:00
|
|
|
SIM_DESC sd;
|
1997-10-22 07:26:27 +02:00
|
|
|
struct _bfd *abfd;
|
1995-10-13 23:06:30 +01:00
|
|
|
char **argv;
|
|
|
|
char **env;
|
|
|
|
{
|
1997-10-22 07:26:27 +02:00
|
|
|
if (abfd != NULL)
|
|
|
|
ARMul_SetPC (state, bfd_get_start_address (abfd));
|
|
|
|
else
|
|
|
|
ARMul_SetPC (state, 0); /* ??? */
|
1997-04-17 11:41:11 +02:00
|
|
|
return SIM_RC_OK;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_info (sd, verbose)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
int verbose;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
static int
|
1995-10-13 23:06:30 +01:00
|
|
|
frommem (state, memory)
|
|
|
|
struct ARMul_State *state;
|
|
|
|
unsigned char *memory;
|
|
|
|
{
|
|
|
|
if (state->bigendSig == HIGH)
|
|
|
|
{
|
|
|
|
return (memory[0] << 24)
|
|
|
|
| (memory[1] << 16)
|
|
|
|
| (memory[2] << 8)
|
|
|
|
| (memory[3] << 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (memory[3] << 24)
|
|
|
|
| (memory[2] << 16)
|
|
|
|
| (memory[1] << 8)
|
|
|
|
| (memory[0] << 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
static void
|
1995-10-13 23:06:30 +01:00
|
|
|
tomem (state, memory, val)
|
|
|
|
struct ARMul_State *state;
|
|
|
|
unsigned char *memory;
|
|
|
|
int val;
|
|
|
|
{
|
|
|
|
if (state->bigendSig == HIGH)
|
|
|
|
{
|
|
|
|
memory[0] = val >> 24;
|
|
|
|
memory[1] = val >> 16;
|
|
|
|
memory[2] = val >> 8;
|
|
|
|
memory[3] = val >> 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memory[3] = val >> 24;
|
|
|
|
memory[2] = val >> 16;
|
|
|
|
memory[1] = val >> 8;
|
|
|
|
memory[0] = val >> 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_store_register (sd, rn, memory)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
int rn;
|
|
|
|
unsigned char *memory;
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
ARMul_SetReg(state, state->Mode, rn, frommem (state, memory));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_fetch_register (sd, rn, memory)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
int rn;
|
|
|
|
unsigned char *memory;
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
tomem (state, memory, ARMul_GetReg(state, state->Mode, rn));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-04-17 08:05:19 +02:00
|
|
|
SIM_DESC
|
1997-08-26 01:14:25 +02:00
|
|
|
sim_open (kind, ptr, abfd, argv)
|
1997-04-17 08:05:19 +02:00
|
|
|
SIM_OPEN_KIND kind;
|
1997-08-26 01:14:25 +02:00
|
|
|
host_callback *ptr;
|
|
|
|
struct _bfd *abfd;
|
1997-04-17 08:05:19 +02:00
|
|
|
char **argv;
|
1995-10-13 23:06:30 +01:00
|
|
|
{
|
1997-04-17 11:41:11 +02:00
|
|
|
sim_kind = kind;
|
|
|
|
myname = argv[0];
|
1997-08-26 01:14:25 +02:00
|
|
|
sim_callback = ptr;
|
1997-04-17 08:05:19 +02:00
|
|
|
return (SIM_DESC) 1;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_close (sd, quitting)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
int quitting;
|
|
|
|
{
|
|
|
|
/* nothing to do */
|
|
|
|
}
|
|
|
|
|
1997-04-17 11:41:11 +02:00
|
|
|
SIM_RC
|
|
|
|
sim_load (sd, prog, abfd, from_tty)
|
1997-04-17 08:05:19 +02:00
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
char *prog;
|
1997-04-17 11:41:11 +02:00
|
|
|
bfd *abfd;
|
1995-10-13 23:06:30 +01:00
|
|
|
int from_tty;
|
|
|
|
{
|
1997-04-17 11:41:11 +02:00
|
|
|
extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
|
|
|
|
bfd *prog_bfd;
|
|
|
|
|
|
|
|
prog_bfd = sim_load_file (sd, myname, sim_callback, prog, abfd,
|
1997-10-22 07:26:27 +02:00
|
|
|
sim_kind == SIM_OPEN_DEBUG,
|
|
|
|
0, sim_write);
|
1997-04-17 11:41:11 +02:00
|
|
|
if (prog_bfd == NULL)
|
|
|
|
return SIM_RC_FAIL;
|
|
|
|
if (abfd == NULL)
|
|
|
|
bfd_close (prog_bfd);
|
|
|
|
return SIM_RC_OK;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_stop_reason (sd, reason, sigrc)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
enum sim_stop *reason;
|
|
|
|
int *sigrc;
|
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
if (state->EndCondition == 0)
|
|
|
|
{
|
|
|
|
*reason = sim_exited;
|
|
|
|
*sigrc = state->Reg[0] & 255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*reason = sim_stopped;
|
|
|
|
if (state->EndCondition == RDIError_BreakpointReached)
|
|
|
|
*sigrc = SIGTRAP;
|
|
|
|
else
|
|
|
|
*sigrc = 0;
|
|
|
|
}
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
1997-04-17 08:05:19 +02:00
|
|
|
|
1995-10-13 23:06:30 +01:00
|
|
|
void
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_do_command (sd, cmd)
|
|
|
|
SIM_DESC sd;
|
1995-10-13 23:06:30 +01:00
|
|
|
char *cmd;
|
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
(*sim_callback->printf_filtered) (sim_callback, "This simulator does not accept any commands.\n");
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1997-08-26 01:14:25 +02:00
|
|
|
sim_set_callbacks (ptr)
|
1997-04-17 08:05:19 +02:00
|
|
|
host_callback *ptr;
|
1995-10-13 23:06:30 +01:00
|
|
|
{
|
1997-04-17 08:05:19 +02:00
|
|
|
sim_callback = ptr;
|
1995-10-13 23:06:30 +01:00
|
|
|
}
|