* Makefile.in (SIM_OBJS): Add sim-load.o.

* compile.c (sim_kind, myname): New static locals.
	(sim_open): Set sim_kind, myname.
	(sim_load): Return SIM_RC.  New arg abfd.  Update test for h8300h.
	Call sim_load_file to load file into simulator.  Set start address
	from bfd.
	(sim_create_inferior): Return SIM_RC.  Delete arg start_address.
This commit is contained in:
David Edelsohn 1997-04-17 10:14:28 +00:00
parent 26277668db
commit 463372706f
2 changed files with 181 additions and 55 deletions

View file

@ -1,3 +1,18 @@
Thu Apr 17 03:06:39 1997 Doug Evans <dje@canuck.cygnus.com>
* Makefile.in (SIM_OBJS): Add sim-load.o.
* compile.c (sim_kind, myname): New static locals.
(sim_open): Set sim_kind, myname.
(sim_load): Return SIM_RC. New arg abfd. Update test for h8300h.
Call sim_load_file to load file into simulator. Set start address
from bfd.
(sim_create_inferior): Return SIM_RC. Delete arg start_address.
Mon Apr 7 15:45:02 1997 Andrew Cagney <cagney@kremvax.cygnus.com>
* configure: Regenerated to track ../common/aclocal.m4 changes.
* config.in: Ditto.
Wed Apr 2 15:06:28 1997 Doug Evans <dje@canuck.cygnus.com> Wed Apr 2 15:06:28 1997 Doug Evans <dje@canuck.cygnus.com>
* compile.c (sim_open): New arg `kind'. * compile.c (sim_open): New arg `kind'.

View file

@ -29,12 +29,22 @@
#include <sys/param.h> #include <sys/param.h>
#include "wait.h" #include "wait.h"
#include "ansidecl.h" #include "ansidecl.h"
#include "bfd.h"
#include "callback.h" #include "callback.h"
#include "remote-sim.h" #include "remote-sim.h"
#include "bfd.h"
int debug; int debug;
host_callback *sim_callback;
static SIM_OPEN_KIND sim_kind;
static char *myname;
/* FIXME: Needs to live in header file.
This header should also include the things in remote-sim.h.
One could move this to remote-sim.h but this function isn't needed
by gdb. */
void sim_set_simcache_size PARAMS ((int));
#define X(op, size) op*4+size #define X(op, size) op*4+size
@ -754,7 +764,7 @@ init_pointers ()
/* initialize the seg registers */ /* initialize the seg registers */
if (!cpu.cache) if (!cpu.cache)
sim_csize (CSIZE); sim_set_simcache_size (CSIZE);
} }
} }
@ -765,6 +775,7 @@ control_c (sig, code, scp, addr)
char *scp; char *scp;
char *addr; char *addr;
{ {
cpu.state = SIM_STATE_STOPPED;
cpu.exception = SIGINT; cpu.exception = SIGINT;
} }
@ -906,7 +917,8 @@ case O(name, SB): \
} }
void void
sim_resume (step, siggnal) sim_resume (sd, step, siggnal)
SIM_DESC sd;
{ {
static int init1; static int init1;
int cycles = 0; int cycles = 0;
@ -928,10 +940,12 @@ sim_resume (step, siggnal)
if (step) if (step)
{ {
cpu.state = SIM_STATE_STOPPED;
cpu.exception = SIGTRAP; cpu.exception = SIGTRAP;
} }
else else
{ {
cpu.state = SIM_STATE_RUNNING;
cpu.exception = 0; cpu.exception = 0;
} }
@ -1307,7 +1321,7 @@ sim_resume (step, siggnal)
pc = code->src.literal; pc = code->src.literal;
goto call; goto call;
case O (O_RTS, SB): case O (O_RTS, SN):
{ {
int tmp; int tmp;
@ -1329,18 +1343,39 @@ sim_resume (step, siggnal)
} }
case O (O_ILL, SB): case O (O_ILL, SB):
cpu.state = SIM_STATE_STOPPED;
cpu.exception = SIGILL; cpu.exception = SIGILL;
goto end; goto end;
case O (O_SLEEP, SB): case O (O_SLEEP, SN):
/* The format of r0 is defined by devo/include/wait.h. /* The format of r0 is defined by devo/include/wait.h. */
cpu.exception handling needs some cleanup: we need to make the #if 0 /* FIXME: Ugh. A breakpoint is the sleep insn. */
the handling of normal exits vs signals, etc. more sensible. */ if (WIFEXITED (cpu.regs[0]))
{
cpu.state = SIM_STATE_EXITED;
cpu.exception = WEXITSTATUS (cpu.regs[0]);
}
else if (WIFSTOPPED (cpu.regs[0]))
{
cpu.state = SIM_STATE_STOPPED;
cpu.exception = WSTOPSIG (cpu.regs[0]);
}
else
{
cpu.state = SIM_STATE_SIGNALLED;
cpu.exception = WTERMSIG (cpu.regs[0]);
}
#else
/* FIXME: Doesn't this break for breakpoints when r0
contains just the right (er, wrong) value? */
cpu.state = SIM_STATE_STOPPED;
if (! WIFEXITED (cpu.regs[0]) && WIFSIGNALED (cpu.regs[0])) if (! WIFEXITED (cpu.regs[0]) && WIFSIGNALED (cpu.regs[0]))
cpu.exception = SIGILL; cpu.exception = SIGILL;
else else
cpu.exception = SIGTRAP; cpu.exception = SIGTRAP;
#endif
goto end; goto end;
case O (O_BPT, SB): case O (O_BPT, SN):
cpu.state = SIM_STATE_STOPPED;
cpu.exception = SIGTRAP; cpu.exception = SIGTRAP;
goto end; goto end;
@ -1462,7 +1497,7 @@ sim_resume (step, siggnal)
res = rd + ea; res = rd + ea;
goto log32; goto log32;
case O (O_NOP, SB): case O (O_NOP, SN):
goto next; goto next;
case O (O_STM, SL): case O (O_STM, SL):
@ -1500,6 +1535,7 @@ sim_resume (step, siggnal)
goto next; goto next;
default: default:
cpu.state = SIM_STATE_STOPPED;
cpu.exception = SIGILL; cpu.exception = SIGILL;
goto end; goto end;
@ -1694,7 +1730,7 @@ sim_resume (step, siggnal)
#endif #endif
} }
while (!cpu.exception); while (cpu.state == SIM_STATE_RUNNING);
cpu.ticks += get_now () - tick_start; cpu.ticks += get_now () - tick_start;
cpu.cycles += cycles; cpu.cycles += cycles;
cpu.insts += insts; cpu.insts += insts;
@ -1705,9 +1741,17 @@ sim_resume (step, siggnal)
signal (SIGINT, prev); signal (SIGINT, prev);
} }
int
sim_trace (sd)
SIM_DESC sd;
{
/* FIXME: unfinished */
abort ();
}
int int
sim_write (addr, buffer, size) sim_write (sd, addr, buffer, size)
SIM_DESC sd;
SIM_ADDR addr; SIM_ADDR addr;
unsigned char *buffer; unsigned char *buffer;
int size; int size;
@ -1731,7 +1775,8 @@ sim_write (addr, buffer, size)
} }
int int
sim_read (addr, buffer, size) sim_read (sd, addr, buffer, size)
SIM_DESC sd;
SIM_ADDR addr; SIM_ADDR addr;
unsigned char *buffer; unsigned char *buffer;
int size; int size;
@ -1769,7 +1814,8 @@ sim_read (addr, buffer, size)
void void
sim_store_register (rn, value) sim_store_register (sd, rn, value)
SIM_DESC sd;
int rn; int rn;
unsigned char *value; unsigned char *value;
{ {
@ -1816,7 +1862,8 @@ sim_store_register (rn, value)
} }
void void
sim_fetch_register (rn, buf) sim_fetch_register (sd, rn, buf)
SIM_DESC sd;
int rn; int rn;
unsigned char *buf; unsigned char *buf;
{ {
@ -1873,15 +1920,37 @@ sim_fetch_register (rn, buf)
} }
void void
sim_stop_reason (reason, sigrc) sim_stop_reason (sd, reason, sigrc)
SIM_DESC sd;
enum sim_stop *reason; enum sim_stop *reason;
int *sigrc; int *sigrc;
{ {
#if 0 /* FIXME: This should work but we can't use it.
grep for SLEEP above. */
switch (cpu.state)
{
case SIM_STATE_EXITED : *reason = sim_exited; break;
case SIM_STATE_SIGNALLED : *reason = sim_signalled; break;
case SIM_STATE_STOPPED : *reason = sim_stopped; break;
default : abort ();
}
#else
*reason = sim_stopped; *reason = sim_stopped;
#endif
*sigrc = cpu.exception; *sigrc = cpu.exception;
} }
sim_csize (n) /* FIXME: Rename to sim_set_mem_size. */
void
sim_size (n)
int n;
{
/* Memory size is fixed. */
}
void
sim_set_simcache_size (n)
{ {
if (cpu.cache) if (cpu.cache)
free (cpu.cache); free (cpu.cache);
@ -1894,29 +1963,47 @@ sim_csize (n)
void void
sim_info (verbose) sim_info (sd, verbose)
SIM_DESC sd;
int verbose; int verbose;
{ {
double timetaken = (double) cpu.ticks / (double) now_persec (); double timetaken = (double) cpu.ticks / (double) now_persec ();
double virttime = cpu.cycles / 10.0e6; double virttime = cpu.cycles / 10.0e6;
printf_filtered ("\n\n#instructions executed %10d\n", cpu.insts); (*sim_callback->printf_filtered) (sim_callback,
printf_filtered ("#cycles (v approximate) %10d\n", cpu.cycles); "\n\n#instructions executed %10d\n",
printf_filtered ("#real time taken %10.4f\n", timetaken); cpu.insts);
printf_filtered ("#virtual time taked %10.4f\n", virttime); (*sim_callback->printf_filtered) (sim_callback,
"#cycles (v approximate) %10d\n",
cpu.cycles);
(*sim_callback->printf_filtered) (sim_callback,
"#real time taken %10.4f\n",
timetaken);
(*sim_callback->printf_filtered) (sim_callback,
"#virtual time taked %10.4f\n",
virttime);
if (timetaken != 0.0) if (timetaken != 0.0)
printf_filtered ("#simulation ratio %10.4f\n", virttime / timetaken); (*sim_callback->printf_filtered) (sim_callback,
printf_filtered ("#compiles %10d\n", cpu.compiles); "#simulation ratio %10.4f\n",
printf_filtered ("#cache size %10d\n", cpu.csize); virttime / timetaken);
(*sim_callback->printf_filtered) (sim_callback,
"#compiles %10d\n",
cpu.compiles);
(*sim_callback->printf_filtered) (sim_callback,
"#cache size %10d\n",
cpu.csize);
#ifdef ADEBUG #ifdef ADEBUG
if (verbose) /* This to be conditional on `what' (aka `verbose'),
however it was never passed as non-zero. */
if (1)
{ {
int i; int i;
for (i = 0; i < O_LAST; i++) for (i = 0; i < O_LAST; i++)
{ {
if (cpu.stats[i]) if (cpu.stats[i])
printf_filtered ("%d: %d\n", i, cpu.stats[i]); (*sim_callback->printf_filtered) (sim_callback,
"%d: %d\n", i, cpu.stats[i]);
} }
} }
#endif #endif
@ -1933,20 +2020,26 @@ set_h8300h (flag)
} }
void void
sim_kill () sim_kill (sd)
SIM_DESC sd;
{ {
/* nothing to do */ /* nothing to do */
} }
void SIM_DESC
sim_open (args) sim_open (kind,argv)
char *args; SIM_OPEN_KIND kind;
char **argv;
{ {
/* nothing to do */ sim_kind = kind;
myname = argv[0];
/* fudge our descriptor */
return (SIM_DESC) 1;
} }
void void
sim_close (quitting) sim_close (sd, quitting)
SIM_DESC sd;
int quitting; int quitting;
{ {
/* nothing to do */ /* nothing to do */
@ -1954,24 +2047,29 @@ sim_close (quitting)
/* Called by gdb to load a program into memory. */ /* Called by gdb to load a program into memory. */
int SIM_RC
sim_load (prog, from_tty) sim_load (sd, prog, abfd, from_tty)
SIM_DESC sd;
char *prog; char *prog;
bfd *abfd;
int from_tty; int from_tty;
{ {
bfd *abfd; bfd *prog_bfd;
/* See if the file is for the h8/300 or h8/300h. */ /* See if the file is for the h8/300 or h8/300h. */
/* ??? This may not be the most efficient way. The z8k simulator /* ??? This may not be the most efficient way. The z8k simulator
does this via a different mechanism (INIT_EXTRA_SYMTAB_INFO). */ does this via a different mechanism (INIT_EXTRA_SYMTAB_INFO). */
if ((abfd = bfd_openr (prog, "coff-h8300")) != 0) if (abfd != NULL)
prog_bfd = abfd;
else
prog_bfd = bfd_openr (prog, "coff-h8300");
if (prog_bfd != NULL)
{ {
if (bfd_check_format (abfd, bfd_object)) if (bfd_check_format (prog_bfd, bfd_object))
{ {
set_h8300h (abfd->arch_info->mach == bfd_mach_h8300h set_h8300h (prog_bfd->arch_info->mach == bfd_mach_h8300h
|| abfd->arch_info->mach == bfd_mach_h8300s); || prog_bfd->arch_info->mach == bfd_mach_h8300s);
} }
bfd_close (abfd);
} }
/* If we're using gdb attached to the simulator, then we have to /* If we're using gdb attached to the simulator, then we have to
@ -2009,32 +2107,45 @@ sim_load (prog, from_tty)
abort (); abort ();
cpu.mask = memory_size - 1; cpu.mask = memory_size - 1;
/* Return non-zero so gdb will handle it. */ if (sim_load_file (sd, myname, sim_callback, prog, prog_bfd,
return 1; sim_kind == SIM_OPEN_DEBUG)
== NULL)
{
/* Close the bfd if we opened it. */
if (abfd == NULL && prog_bfd != NULL)
bfd_close (prog_bfd);
return SIM_RC_FAIL;
} }
void cpu.pc = bfd_get_start_address (prog_bfd);
sim_create_inferior (start_address, argv, env) /* Close the bfd if we opened it. */
SIM_ADDR start_address; if (abfd == NULL && prog_bfd != NULL)
bfd_close (prog_bfd);
return SIM_RC_OK;
}
SIM_RC
sim_create_inferior (sd, argv, env)
SIM_DESC sd;
char **argv; char **argv;
char **env; char **env;
{ {
cpu.pc = start_address; return SIM_RC_OK;
} }
void void
sim_do_command (cmd) sim_do_command (sd, cmd)
SIM_DESC sd;
char *cmd; char *cmd;
{ {
printf_filtered ("This simulator does not accept any commands.\n"); (*sim_callback->printf_filtered) (sim_callback,
"This simulator does not accept any commands.\n");
} }
void void
sim_set_callbacks (ptr) sim_set_callbacks (sd, ptr)
SIM_DESC sd;
struct host_callback_struct *ptr; struct host_callback_struct *ptr;
{ {
sim_callback = ptr;
} }