diff options
Diffstat (limited to 'sim/moxie/interp.c')
-rw-r--r-- | sim/moxie/interp.c | 223 |
1 files changed, 49 insertions, 174 deletions
diff --git a/sim/moxie/interp.c b/sim/moxie/interp.c index 5286b66..128fb48 100644 --- a/sim/moxie/interp.c +++ b/sim/moxie/interp.c @@ -26,20 +26,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/param.h> #include <unistd.h> #include "bfd.h" -#include "gdb/callback.h" #include "libiberty.h" #include "gdb/remote-sim.h" #include "sim-main.h" #include "sim-base.h" +#include "sim-options.h" typedef int word; typedef unsigned int uword; -host_callback * callback; - -FILE *tracefile; - /* Extract the signed 10-bit offset from a 16-bit branch instruction. */ #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1) @@ -117,6 +113,7 @@ static const char *reg_names[16] = /* The ordering of the moxie_regset structure is matched in the gdb/config/moxie/tm-moxie.h file in the REGISTER_NAMES macro. */ +/* TODO: This should be moved to sim-main.h:_sim_cpu. */ struct moxie_regset { word regs[NUM_MOXIE_REGS + 1]; /* primary registers */ @@ -132,23 +129,15 @@ struct moxie_regset #define CC_GTU 1<<3 #define CC_LTU 1<<4 +/* TODO: This should be moved to sim-main.h:_sim_cpu. */ union { struct moxie_regset asregs; word asints [1]; /* but accessed larger... */ } cpu; -static char *myname; -static SIM_OPEN_KIND sim_kind; -static int issue_messages = 0; - -void -sim_size (int s) -{ -} - static void -set_initial_gprs () +set_initial_gprs (void) { int i; long space; @@ -246,10 +235,11 @@ convert_target_flags (unsigned int tflags) return hflags; } +/* TODO: Move to sim-trace.h. */ +static FILE *tracefile; +static const int tracing = 0; #define TRACE(str) if (tracing) fprintf(tracefile,"0x%08x, %s, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", opc, str, cpu.asregs.regs[0], cpu.asregs.regs[1], cpu.asregs.regs[2], cpu.asregs.regs[3], cpu.asregs.regs[4], cpu.asregs.regs[5], cpu.asregs.regs[6], cpu.asregs.regs[7], cpu.asregs.regs[8], cpu.asregs.regs[9], cpu.asregs.regs[10], cpu.asregs.regs[11], cpu.asregs.regs[12], cpu.asregs.regs[13], cpu.asregs.regs[14], cpu.asregs.regs[15]); -static int tracing = 0; - void sim_resume (sd, step, siggnal) SIM_DESC sd; @@ -1128,35 +1118,6 @@ sim_resume (sd, step, siggnal) } int -sim_write (sd, addr, buffer, size) - SIM_DESC sd; - SIM_ADDR addr; - const unsigned char * buffer; - int size; -{ - sim_cpu *scpu = STATE_CPU (sd, 0); /* FIXME */ - - sim_core_write_buffer (sd, scpu, write_map, buffer, addr, size); - - return size; -} - -int -sim_read (sd, addr, buffer, size) - SIM_DESC sd; - SIM_ADDR addr; - unsigned char * buffer; - int size; -{ - sim_cpu *scpu = STATE_CPU (sd, 0); /* FIXME */ - - sim_core_read_buffer (sd, scpu, read_map, buffer, addr, size); - - return size; -} - - -int sim_store_register (sd, rn, memory, length) SIM_DESC sd; int rn; @@ -1203,61 +1164,15 @@ sim_fetch_register (sd, rn, memory, length) return 0; } - -int -sim_trace (sd) - SIM_DESC sd; -{ - if (tracefile == 0) - tracefile = fopen("trace.csv", "wb"); - - tracing = 1; - - sim_resume (sd, 0, 0); - - tracing = 0; - - return 1; -} - -void -sim_stop_reason (sd, reason, sigrc) - SIM_DESC sd; - enum sim_stop * reason; - int * sigrc; -{ - if (cpu.asregs.exception == SIGQUIT) - { - * reason = sim_exited; - * sigrc = cpu.asregs.regs[2]; - } - else - { - * reason = sim_stopped; - * sigrc = cpu.asregs.exception; - } -} - - -int -sim_stop (sd) - SIM_DESC sd; -{ - cpu.asregs.exception = SIGINT; - return 1; -} - - -void -sim_info (sd, verbose) - SIM_DESC sd; - int verbose; +static void +free_state (SIM_DESC sd) { - callback->printf_filtered (callback, "\n\n# instructions executed %llu\n", - cpu.asregs.insts); + if (STATE_MODULES (sd) != NULL) + sim_module_uninstall (sd); + sim_cpu_free_all (sd); + sim_state_free (sd); } - SIM_DESC sim_open (kind, cb, abfd, argv) SIM_OPEN_KIND kind; @@ -1268,20 +1183,44 @@ sim_open (kind, cb, abfd, argv) SIM_DESC sd = sim_state_alloc (kind, cb); SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + /* The cpu data is kept in a separately allocated chunk of memory. */ + if (sim_cpu_alloc_all (sd, 1, /*cgen_cpu_max_extra_bytes ()*/0) != SIM_RC_OK) + { + free_state (sd); + return 0; + } + + STATE_WATCHPOINTS (sd)->pc = &cpu.asregs.regs[PC_REGNO]; + STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (word); + if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) - return 0; + { + free_state (sd); + return 0; + } + + /* getopt will print the error message so we just have to exit if this fails. + FIXME: Hmmm... in the case of gdb we need getopt to call + print_filtered. */ + if (sim_parse_args (sd, argv) != SIM_RC_OK) + { + free_state (sd); + return 0; + } sim_do_command(sd," memory region 0x00000000,0x4000000") ; sim_do_command(sd," memory region 0xE0000000,0x10000") ; - myname = argv[0]; - callback = cb; - - if (kind == SIM_OPEN_STANDALONE) - issue_messages = 1; - - set_initial_gprs (); /* Reset the GPR registers. */ - + /* Check for/establish the a reference program image. */ + if (sim_analyze_program (sd, + (STATE_PROG_ARGV (sd) != NULL + ? *STATE_PROG_ARGV (sd) + : NULL), abfd) != SIM_RC_OK) + { + free_state (sd); + return 0; + } + /* Configure/verify the target byte order and other runtime configuration options. */ if (sim_config (sd) != SIM_RC_OK) @@ -1298,6 +1237,9 @@ sim_open (kind, cb, abfd, argv) return 0; } + /* CPU specific initialization. */ + set_initial_gprs (); + return sd; } @@ -1339,60 +1281,6 @@ load_dtb (SIM_DESC sd, const char *filename) } SIM_RC -sim_load (sd, prog, abfd, from_tty) - SIM_DESC sd; - const char * prog; - bfd * abfd; - int from_tty; -{ - - /* Do the right thing for ELF executables; this turns out to be - just about the right thing for any object format that: - - we crack using BFD routines - - follows the traditional UNIX text/data/bss layout - - calls the bss section ".bss". */ - - extern bfd * sim_load_file (); /* ??? Don't know where this should live. */ - bfd * prog_bfd; - - { - bfd * handle; - handle = bfd_openr (prog, 0); /* could be "moxie" */ - - if (!handle) - { - printf("``%s'' could not be opened.\n", prog); - return SIM_RC_FAIL; - } - - /* Makes sure that we have an object file, also cleans gets the - section headers in place. */ - if (!bfd_check_format (handle, bfd_object)) - { - /* wasn't an object file */ - bfd_close (handle); - printf ("``%s'' is not appropriate object file.\n", prog); - return SIM_RC_FAIL; - } - - /* Clean up after ourselves. */ - bfd_close (handle); - } - - /* from sh -- dac */ - prog_bfd = sim_load_file (sd, myname, callback, prog, abfd, - sim_kind == SIM_OPEN_DEBUG, - 0, sim_write); - if (prog_bfd == NULL) - return SIM_RC_FAIL; - - if (abfd == NULL) - bfd_close (prog_bfd); - - return SIM_RC_OK; -} - -SIM_RC sim_create_inferior (sd, prog_bfd, argv, env) SIM_DESC sd; struct bfd * prog_bfd; @@ -1403,12 +1291,6 @@ sim_create_inferior (sd, prog_bfd, argv, env) int l, argc, i, tp; sim_cpu *scpu = STATE_CPU (sd, 0); /* FIXME */ - /* Set the initial register set. */ - l = issue_messages; - issue_messages = 0; - set_initial_gprs (); - issue_messages = l; - if (prog_bfd != NULL) cpu.asregs.regs[PC_REGNO] = bfd_get_start_address (prog_bfd); @@ -1449,10 +1331,3 @@ sim_create_inferior (sd, prog_bfd, argv, env) return SIM_RC_OK; } - -void -sim_set_callbacks (ptr) - host_callback * ptr; -{ - callback = ptr; -} |