From 463372706f4bf9fe4693d455217496a1f1b8aeb6 Mon Sep 17 00:00:00 2001 From: David Edelsohn Date: Thu, 17 Apr 1997 10:14:28 +0000 Subject: [PATCH] * 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. --- sim/h8300/ChangeLog | 15 +++ sim/h8300/compile.c | 221 +++++++++++++++++++++++++++++++++----------- 2 files changed, 181 insertions(+), 55 deletions(-) diff --git a/sim/h8300/ChangeLog b/sim/h8300/ChangeLog index 47980b40795..1c0f27d1fec 100644 --- a/sim/h8300/ChangeLog +++ b/sim/h8300/ChangeLog @@ -1,3 +1,18 @@ +Thu Apr 17 03:06:39 1997 Doug Evans + + * 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 + + * configure: Regenerated to track ../common/aclocal.m4 changes. + * config.in: Ditto. + Wed Apr 2 15:06:28 1997 Doug Evans * compile.c (sim_open): New arg `kind'. diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c index 247a53a15ee..4973ed71c2a 100644 --- a/sim/h8300/compile.c +++ b/sim/h8300/compile.c @@ -29,12 +29,22 @@ #include #include "wait.h" #include "ansidecl.h" +#include "bfd.h" #include "callback.h" #include "remote-sim.h" -#include "bfd.h" 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 @@ -754,7 +764,7 @@ init_pointers () /* initialize the seg registers */ if (!cpu.cache) - sim_csize (CSIZE); + sim_set_simcache_size (CSIZE); } } @@ -765,6 +775,7 @@ control_c (sig, code, scp, addr) char *scp; char *addr; { + cpu.state = SIM_STATE_STOPPED; cpu.exception = SIGINT; } @@ -906,7 +917,8 @@ case O(name, SB): \ } void -sim_resume (step, siggnal) +sim_resume (sd, step, siggnal) + SIM_DESC sd; { static int init1; int cycles = 0; @@ -928,10 +940,12 @@ sim_resume (step, siggnal) if (step) { + cpu.state = SIM_STATE_STOPPED; cpu.exception = SIGTRAP; } else { + cpu.state = SIM_STATE_RUNNING; cpu.exception = 0; } @@ -1307,7 +1321,7 @@ sim_resume (step, siggnal) pc = code->src.literal; goto call; - case O (O_RTS, SB): + case O (O_RTS, SN): { int tmp; @@ -1329,18 +1343,39 @@ sim_resume (step, siggnal) } case O (O_ILL, SB): + cpu.state = SIM_STATE_STOPPED; cpu.exception = SIGILL; goto end; - case O (O_SLEEP, SB): - /* The format of r0 is defined by devo/include/wait.h. - cpu.exception handling needs some cleanup: we need to make the - the handling of normal exits vs signals, etc. more sensible. */ + case O (O_SLEEP, SN): + /* The format of r0 is defined by devo/include/wait.h. */ +#if 0 /* FIXME: Ugh. A breakpoint is the sleep insn. */ + 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])) cpu.exception = SIGILL; else cpu.exception = SIGTRAP; +#endif goto end; - case O (O_BPT, SB): + case O (O_BPT, SN): + cpu.state = SIM_STATE_STOPPED; cpu.exception = SIGTRAP; goto end; @@ -1462,7 +1497,7 @@ sim_resume (step, siggnal) res = rd + ea; goto log32; - case O (O_NOP, SB): + case O (O_NOP, SN): goto next; case O (O_STM, SL): @@ -1500,6 +1535,7 @@ sim_resume (step, siggnal) goto next; default: + cpu.state = SIM_STATE_STOPPED; cpu.exception = SIGILL; goto end; @@ -1694,7 +1730,7 @@ sim_resume (step, siggnal) #endif } - while (!cpu.exception); + while (cpu.state == SIM_STATE_RUNNING); cpu.ticks += get_now () - tick_start; cpu.cycles += cycles; cpu.insts += insts; @@ -1705,9 +1741,17 @@ sim_resume (step, siggnal) signal (SIGINT, prev); } +int +sim_trace (sd) + SIM_DESC sd; +{ + /* FIXME: unfinished */ + abort (); +} int -sim_write (addr, buffer, size) +sim_write (sd, addr, buffer, size) + SIM_DESC sd; SIM_ADDR addr; unsigned char *buffer; int size; @@ -1731,7 +1775,8 @@ sim_write (addr, buffer, size) } int -sim_read (addr, buffer, size) +sim_read (sd, addr, buffer, size) + SIM_DESC sd; SIM_ADDR addr; unsigned char *buffer; int size; @@ -1769,7 +1814,8 @@ sim_read (addr, buffer, size) void -sim_store_register (rn, value) +sim_store_register (sd, rn, value) + SIM_DESC sd; int rn; unsigned char *value; { @@ -1816,7 +1862,8 @@ sim_store_register (rn, value) } void -sim_fetch_register (rn, buf) +sim_fetch_register (sd, rn, buf) + SIM_DESC sd; int rn; unsigned char *buf; { @@ -1873,15 +1920,37 @@ sim_fetch_register (rn, buf) } void -sim_stop_reason (reason, sigrc) +sim_stop_reason (sd, reason, sigrc) + SIM_DESC sd; enum sim_stop *reason; 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; +#endif *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) free (cpu.cache); @@ -1894,29 +1963,47 @@ sim_csize (n) void -sim_info (verbose) +sim_info (sd, verbose) + SIM_DESC sd; int verbose; { double timetaken = (double) cpu.ticks / (double) now_persec (); double virttime = cpu.cycles / 10.0e6; - printf_filtered ("\n\n#instructions executed %10d\n", cpu.insts); - printf_filtered ("#cycles (v approximate) %10d\n", cpu.cycles); - printf_filtered ("#real time taken %10.4f\n", timetaken); - printf_filtered ("#virtual time taked %10.4f\n", virttime); + (*sim_callback->printf_filtered) (sim_callback, + "\n\n#instructions executed %10d\n", + cpu.insts); + (*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) - printf_filtered ("#simulation ratio %10.4f\n", virttime / timetaken); - printf_filtered ("#compiles %10d\n", cpu.compiles); - printf_filtered ("#cache size %10d\n", cpu.csize); + (*sim_callback->printf_filtered) (sim_callback, + "#simulation ratio %10.4f\n", + 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 - if (verbose) + /* This to be conditional on `what' (aka `verbose'), + however it was never passed as non-zero. */ + if (1) { int i; for (i = 0; i < O_LAST; 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 @@ -1933,20 +2020,26 @@ set_h8300h (flag) } void -sim_kill () +sim_kill (sd) + SIM_DESC sd; { /* nothing to do */ } -void -sim_open (args) - char *args; +SIM_DESC +sim_open (kind,argv) + SIM_OPEN_KIND kind; + char **argv; { - /* nothing to do */ + sim_kind = kind; + myname = argv[0]; + /* fudge our descriptor */ + return (SIM_DESC) 1; } void -sim_close (quitting) +sim_close (sd, quitting) + SIM_DESC sd; int quitting; { /* nothing to do */ @@ -1954,24 +2047,29 @@ sim_close (quitting) /* Called by gdb to load a program into memory. */ -int -sim_load (prog, from_tty) +SIM_RC +sim_load (sd, prog, abfd, from_tty) + SIM_DESC sd; char *prog; + bfd *abfd; int from_tty; { - bfd *abfd; + bfd *prog_bfd; /* See if the file is for the h8/300 or h8/300h. */ /* ??? This may not be the most efficient way. The z8k simulator 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 - || abfd->arch_info->mach == bfd_mach_h8300s); + set_h8300h (prog_bfd->arch_info->mach == bfd_mach_h8300h + || prog_bfd->arch_info->mach == bfd_mach_h8300s); } - bfd_close (abfd); } /* If we're using gdb attached to the simulator, then we have to @@ -2009,32 +2107,45 @@ sim_load (prog, from_tty) abort (); cpu.mask = memory_size - 1; - /* Return non-zero so gdb will handle it. */ - return 1; + if (sim_load_file (sd, myname, sim_callback, prog, prog_bfd, + 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; + } + + cpu.pc = bfd_get_start_address (prog_bfd); + /* Close the bfd if we opened it. */ + if (abfd == NULL && prog_bfd != NULL) + bfd_close (prog_bfd); + return SIM_RC_OK; } -void -sim_create_inferior (start_address, argv, env) - SIM_ADDR start_address; +SIM_RC +sim_create_inferior (sd, argv, env) + SIM_DESC sd; char **argv; char **env; { - cpu.pc = start_address; + return SIM_RC_OK; } void -sim_do_command (cmd) +sim_do_command (sd, cmd) + SIM_DESC sd; 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 -sim_set_callbacks (ptr) -struct host_callback_struct *ptr; +sim_set_callbacks (sd, ptr) + SIM_DESC sd; + struct host_callback_struct *ptr; { - + sim_callback = ptr; } - -- 2.30.2