diff options
author | Mike Frysinger <vapier@gentoo.org> | 2015-03-30 00:13:38 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-03-30 00:13:38 -0400 |
commit | 247ac9ee6e1ecea67d29a5712e77e8c64834b06e (patch) | |
tree | f19828be7f4c661ffc0fc2f1c70e47e165782fcf /sim/cr16 | |
parent | 4b0cc5edf489335509e155b5af0a0e754f4e3df9 (diff) | |
download | gdb-247ac9ee6e1ecea67d29a5712e77e8c64834b06e.zip gdb-247ac9ee6e1ecea67d29a5712e77e8c64834b06e.tar.gz gdb-247ac9ee6e1ecea67d29a5712e77e8c64834b06e.tar.bz2 |
sim: cr16: convert to nrun
A lot of cpu state is stored in global variables, as is memory handling.
The sim_size support needs unwinding at some point. But at least this
is an improvement on the status quo.
Diffstat (limited to 'sim/cr16')
-rw-r--r-- | sim/cr16/ChangeLog | 27 | ||||
-rw-r--r-- | sim/cr16/Makefile.in | 20 | ||||
-rw-r--r-- | sim/cr16/cr16_sim.h | 9 | ||||
-rw-r--r-- | sim/cr16/interp.c | 209 | ||||
-rw-r--r-- | sim/cr16/sim-main.h | 55 | ||||
-rw-r--r-- | sim/cr16/simops.c | 15 |
6 files changed, 188 insertions, 147 deletions
diff --git a/sim/cr16/ChangeLog b/sim/cr16/ChangeLog index 4564557..42e1abe 100644 --- a/sim/cr16/ChangeLog +++ b/sim/cr16/ChangeLog @@ -1,5 +1,32 @@ 2015-03-29 Mike Frysinger <vapier@gentoo.org> + * cr16_sim.h (text, text_start, text_end, prog_bfd): Delete. + (SEXT8, SEXT16, SEXT32): Undefine. + * interp.c: Delete run-sim.h and cr16_sim.h includes. Include + sim-main.h and sim-options.h. + (myname, sim_kind, init_text_p, prog_bfd_was_opened_p, prog_bfd, + text, text_start, text_end, decode_pc, sim_set_profile, + sim_set_profile_size, sim_set_trace, sim_info, sim_set_callbacks, + sim_trace, sim_complete_command, sim_do_command, sim_load): Delete. + (do_run): Delete prototype. + (INLINE): Delete define. + (do_run, xfer_mem): Pass in SIM_DESC. Set cr16_callback locally from + it. + (sim_size): Mark static. + (sim_write, sim_read): Pass sd to xfer_mem. + (free_state): New function. + (trace_sd): Declare global variable. + (sim_open): Rewrite to use new common logic. + (sim_close): Delete body. + (sim_resume): Pass sd to do_run. + * Makefile.in (SIM_RUN_OBJS, SIM_EXTRA_CFLAGS): Delete. + (SIM_OBJS): Change to $(SIM_NEW_COMMON_OBJS). + * sim-main.h: New file. + * simops.c: Change cr16_sim.h include to sim-main.h. + (trace_input_func): Rewrite pc checks to use trace_sd. + +2015-03-29 Mike Frysinger <vapier@gentoo.org> + * Makefile.in (SIM_EXTRA_CFLAGS): Delete -DNEED_UI_LOOP_HOOK. * interp.c [NEED_UI_LOOP_HOOK] (UI_LOOP_POLL_INTERVAL, ui_loop_hook_counter, deprecated_ui_loop_hook): Delete. diff --git a/sim/cr16/Makefile.in b/sim/cr16/Makefile.in index b5908e7..3798fc7 100644 --- a/sim/cr16/Makefile.in +++ b/sim/cr16/Makefile.in @@ -1,28 +1,32 @@ # Makefile template for Configure for the CR16 sim library. # Copyright (C) 2008-2015 Free Software Foundation, Inc. # Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com> -# +# # This program 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 3 of the License, or # (at your option) any later version. -# +# # This program 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 # along with this program. If not, see <http://www.gnu.org/licenses/>. ## COMMON_PRE_CONFIG_FRAG -# Use the deprecated run frontend until we migrate to nrun.o -SIM_RUN_OBJS = run.o - -SIM_OBJS = interp.o table.o simops.o endian.o sim-load.o +SIM_OBJS = \ + $(SIM_NEW_COMMON_OBJS) \ + sim-cpu.o \ + sim-engine.o \ + sim-hload.o \ + interp.o \ + table.o \ + simops.o \ + endian.o SIM_EXTRA_CLEAN = clean-extra -SIM_EXTRA_CFLAGS = -DSIM_USE_DEPRECATED_RUN_FRONTEND INCLUDE = cr16_sim.h $(srcroot)/include/gdb/callback.h targ-vals.h endian.c \ $(srcroot)/include/gdb/sim-cr16.h diff --git a/sim/cr16/cr16_sim.h b/sim/cr16/cr16_sim.h index 8598193..5e0eabe 100644 --- a/sim/cr16/cr16_sim.h +++ b/sim/cr16/cr16_sim.h @@ -285,10 +285,6 @@ extern host_callback *cr16_callback; extern uint32 OP[4]; extern uint32 sign_flag; extern struct simops Simops[]; -extern asection *text; -extern bfd_vma text_start; -extern bfd_vma text_end; -extern bfd *prog_bfd; enum { @@ -403,6 +399,11 @@ enum #define SIG_CR16_BUS -3 #define SIG_CR16_IAD -4 +/* TODO: Resolve conflicts with common headers. */ +#undef SEXT8 +#undef SEXT16 +#undef SEXT32 + #define SEXT3(x) ((((x)&0x7)^(~3))+4) /* sign-extend a 4-bit number */ diff --git a/sim/cr16/interp.c b/sim/cr16/interp.c index 88c4a80..fc8afd0 100644 --- a/sim/cr16/interp.c +++ b/sim/cr16/interp.c @@ -25,15 +25,14 @@ #include "bfd.h" #include "gdb/callback.h" #include "gdb/remote-sim.h" -#include "run-sim.h" -#include "cr16_sim.h" +#include "sim-main.h" +#include "sim-options.h" + #include "gdb/sim-cr16.h" #include "gdb/signals.h" #include "opcode/cr16.h" -static char *myname; -static SIM_OPEN_KIND sim_kind; int cr16_debug; host_callback *cr16_callback; @@ -41,28 +40,12 @@ host_callback *cr16_callback; uint32 OP[4]; uint32 sign_flag; -static int init_text_p = 0; -/* non-zero if we opened prog_bfd */ -static int prog_bfd_was_opened_p; -bfd *prog_bfd; -asection *text; -bfd_vma text_start; -bfd_vma text_end; - static struct hash_entry *lookup_hash (uint64 ins, int size); static void get_operands (operand_desc *s, uint64 mcode, int isize, int nops); -static int do_run (uint64 mc); extern void sim_set_profile (int n); extern void sim_set_profile_size (int n); static INLINE uint8 *map_memory (unsigned phys_addr); -#ifndef INLINE -#if defined(__GNUC__) && defined(__OPTIMIZE__) -#define INLINE __inline__ -#else -#define INLINE -#endif -#endif #define MAX_HASH 16 struct hash_entry @@ -347,31 +330,10 @@ get_operands (operand_desc *s, uint64 ins, int isize, int nops) State.trace.psw = PSR; } -bfd_vma -decode_pc (void) -{ - asection *s; - if (!init_text_p && prog_bfd != NULL) - { - init_text_p = 1; - for (s = prog_bfd->sections; s; s = s->next) - if (strcmp (bfd_get_section_name (prog_bfd, s), ".text") == 0) - { - text = s; - text_start = bfd_get_section_vma (prog_bfd, s); - text_end = text_start + bfd_section_size (prog_bfd, s); - break; - } - } - - return (PC) + text_start; -} - - - static int -do_run(uint64 mcode) +do_run (SIM_DESC sd, uint64 mcode) { + host_callback *cr16_callback = STATE_CALLBACK (sd); struct simops *s= Simops; struct hash_entry *h; char func[12]="\0"; @@ -410,7 +372,7 @@ do_run(uint64 mcode) return h->size; } -void +static void sim_size (int power) { int i; @@ -721,11 +683,12 @@ map_memory (unsigned phys_addr) than aborting the entire run. */ static int -xfer_mem (SIM_ADDR virt, +xfer_mem (SIM_DESC sd, SIM_ADDR virt, unsigned char *buffer, int size, int write_p) { + host_callback *cr16_callback = STATE_CALLBACK (sd); uint8 *memory; unsigned long phys; int phys_size; @@ -766,27 +729,88 @@ int sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size) { /* FIXME: this should be performing a virtual transfer */ - return xfer_mem( addr, buffer, size, 1); + return xfer_mem (sd, addr, buffer, size, 1); } int sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size) { /* FIXME: this should be performing a virtual transfer */ - return xfer_mem( addr, buffer, size, 0); + return xfer_mem (sd, addr, buffer, size, 0); } +static void +free_state (SIM_DESC sd) +{ + if (STATE_MODULES (sd) != NULL) + sim_module_uninstall (sd); + sim_cpu_free_all (sd); + sim_state_free (sd); +} + +SIM_DESC trace_sd = NULL; + SIM_DESC -sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *callback, struct bfd *abfd, char **argv) +sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *cb, struct bfd *abfd, char **argv) { struct simops *s; struct hash_entry *h; static int init_p = 0; char **p; + int i; + 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; + } + + if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) + { + 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; + } + + /* 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) + { + sim_module_uninstall (sd); + return 0; + } + + if (sim_post_argv_init (sd) != SIM_RC_OK) + { + /* Uninstall the modules to avoid memory leaks, + file descriptor leaks, etc. */ + sim_module_uninstall (sd); + return 0; + } - sim_kind = kind; - cr16_callback = callback; - myname = argv[0]; + trace_sd = sd; + cr16_callback = cb; /* put all the opcodes in the hash table. */ if (!init_p++) @@ -899,32 +923,14 @@ sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *callback, struct bfd sim_size (1); sim_create_inferior ((SIM_DESC) 1, NULL, NULL, NULL); - /* Fudge our descriptor. */ - return (SIM_DESC) 1; + return sd; } void sim_close (SIM_DESC sd, int quitting) { - if (prog_bfd != NULL && prog_bfd_was_opened_p) - { - bfd_close (prog_bfd); - prog_bfd = NULL; - prog_bfd_was_opened_p = 0; - } -} - -void -sim_set_profile (int n) -{ - (*cr16_callback->printf_filtered) (cr16_callback, "sim_set_profile %d\n",n); -} - -void -sim_set_profile_size (int n) -{ - (*cr16_callback->printf_filtered) (cr16_callback, "sim_set_profile_size %d\n",n); + /* Nothing to do. */ } uint8 * @@ -1054,7 +1060,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) State.pc_changed = 0; - curr_ins_size = do_run(mcode); + curr_ins_size = do_run(sd, mcode); #if CR16_DEBUG (*cr16_callback->printf_filtered) (cr16_callback, "INS: PC=0x%X, mcode=0x%X\n",PC,mcode); @@ -1091,19 +1097,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal) State.exception = SIGTRAP; } -void -sim_set_trace (void) -{ -#ifdef DEBUG - cr16_debug = DEBUG; -#endif -} - -void -sim_info (SIM_DESC sd, int verbose) -{ -} - SIM_RC sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env) { @@ -1135,21 +1128,6 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env) return SIM_RC_OK; } - -void -sim_set_callbacks (host_callback *p) -{ - cr16_callback = p; -} - -int -sim_trace (SIM_DESC sd) -{ - sim_resume (sd, 0, 0); - - return 1; -} - void sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc) { @@ -1289,34 +1267,3 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *memory, int length) SLOT_FLUSH (); return size; } - -char ** -sim_complete_command (SIM_DESC sd, const char *text, const char *word) -{ - return NULL; -} - -void -sim_do_command (SIM_DESC sd, const char *cmd) -{ - (*cr16_callback->printf_filtered) (cr16_callback, "sim_do_command: %s\n",cmd); -} - -SIM_RC -sim_load (SIM_DESC sd, const char *prog, struct bfd *abfd, int from_tty) -{ - extern bfd *sim_load_file (); /* ??? Don't know where this should live. */ - - if (prog_bfd != NULL && prog_bfd_was_opened_p) - { - bfd_close (prog_bfd); - prog_bfd_was_opened_p = 0; - } - prog_bfd = sim_load_file (sd, myname, cr16_callback, prog, abfd, - sim_kind == SIM_OPEN_DEBUG, - 1/*LMA*/, sim_write); - if (prog_bfd == NULL) - return SIM_RC_FAIL; - prog_bfd_was_opened_p = abfd == NULL; - return SIM_RC_OK; -} diff --git a/sim/cr16/sim-main.h b/sim/cr16/sim-main.h new file mode 100644 index 0000000..2be0e23 --- /dev/null +++ b/sim/cr16/sim-main.h @@ -0,0 +1,55 @@ +/* Simulation code for the CR16 processor. + Copyright (C) 2009-2015 Free Software Foundation, Inc. + + This file is part of simulators. + + This program 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 3 of the License, or + (at your option) any later version. + + This program 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 + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SIM_MAIN_H +#define SIM_MAIN_H + +#include "sim-basics.h" + +typedef address_word sim_cia; +typedef long int word; +typedef unsigned long int uword; + +typedef struct _sim_cpu SIM_CPU; + +#include "sim-base.h" +#include "bfd.h" + +#include "cr16_sim.h" + +#define CIA_GET(cpu) PC +#define CIA_SET(cpu,val) SET_PC (val) + +struct _sim_cpu { + + sim_cpu_base base; +}; + +struct sim_state { + + sim_cpu *cpu[MAX_NR_PROCESSORS]; +#if (WITH_SMP) +#define STATE_CPU(sd,n) ((sd)->cpu[n]) +#else +#define STATE_CPU(sd,n) ((sd)->cpu[0]) +#endif + + sim_state_base base; +}; + +#endif diff --git a/sim/cr16/simops.c b/sim/cr16/simops.c index 3773bf7..a923192 100644 --- a/sim/cr16/simops.c +++ b/sim/cr16/simops.c @@ -37,7 +37,7 @@ #include <sys/time.h> #endif -#include "cr16_sim.h" +#include "sim-main.h" #include "simops.h" #include "targ-vals.h" @@ -264,14 +264,21 @@ trace_input_func (const char *name, enum op_types in1, enum op_types in2, enum o else { + extern SIM_DESC trace_sd; + buf[0] = '\0'; - byte_pc = decode_pc (); - if (text && byte_pc >= text_start && byte_pc < text_end) + byte_pc = PC; + if (STATE_TEXT_SECTION (trace_sd) + && byte_pc >= STATE_TEXT_START (trace_sd) + && byte_pc < STATE_TEXT_END (trace_sd)) { filename = (const char *)0; functionname = (const char *)0; linenumber = 0; - if (bfd_find_nearest_line (prog_bfd, text, (struct bfd_symbol **)0, byte_pc - text_start, + if (bfd_find_nearest_line (STATE_PROG_BFD (trace_sd), + STATE_TEXT_SECTION (trace_sd), + (struct bfd_symbol **)0, + byte_pc - STATE_TEXT_START (trace_sd), &filename, &functionname, &linenumber)) { p = buf; |