Add --target=BFDTARGET and --architecture=MACHINE options.
[binutils-gdb.git] / sim / common / sim-base.h
index 8b1ac932acc9c3d077bc8586a53965445b5afd2f..b21c3970e93c13d9e5083f0378b9d44d0a1d75da 100644 (file)
@@ -18,11 +18,66 @@ You should have received a copy of the GNU General Public License 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 is meant to be included by sim-basics.h.  */
+
+/* Simulator state pseudo baseclass.
+
+   Each simulator is required to have a sim-main.h file that includes
+   sim-basics.h, defines the base type sim_cia (the data type that
+   contains the complete current instruction address information), and
+   then sim-base.h:
+
+     #include "sim-basics.h"
+     typedef address_word sim_cia;
+     #include "sim-base.h"
+   
+   and defines two key simulator structures.  Firstly, struct
+   _sim_cpu:
+
+     struct _sim_cpu {
+        ... simulator specific members ...
+        sim_cpu_base base;
+     };
+
+   and secondly, struct sim_state (which uses the sim_cpu structure):
+
+     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
+       ... simulator specific members ...
+       sim_state_base base;
+     };
+
+   Note that `base' appears last.  This makes `base.magic' appear last
+   in the entire struct and helps catch miscompilation errors. */
+
 
 #ifndef SIM_BASE_H
 #define SIM_BASE_H
 
+/* Pre-declare certain types. */
+
+/* typedef <target-dependant> sim_cia; */
+#ifndef NULL_CIA
+#define NULL_CIA ((sim_cia) 0)
+#endif
+typedef struct _sim_cpu sim_cpu;
+
+#include "sim-module.h"
+
+#include "sim-trace.h"
+#include "sim-profile.h"
+#include "sim-model.h"
+#include "sim-core.h"
+#include "sim-events.h"
+#include "sim-io.h"
+#include "sim-engine.h"
+#include "sim-watch.h"
+
+
 /* Global pointer to current state while sim_resume is running.
    On a machine with lots of registers, it might be possible to reserve
    one of them for current_state.  However on a machine with few registers
@@ -32,50 +87,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
    If CURRENT_STATE_REG is defined, it means current_state is living in
    a global register.  */
 
+
 #ifdef CURRENT_STATE_REG
 /* FIXME: wip */
 #else
 extern struct sim_state *current_state;
 #endif
 
+
 /* The simulator may provide different (and faster) definition.  */
 #ifndef CURRENT_STATE
 #define CURRENT_STATE current_state
 #endif
 
-/* Simulator state pseudo baseclass.
-   Each simulator is required to have a sim-main.h file that includes
-   sim-basics.h and defines struct sim_state to be:
-
-   struct sim_state {
-     sim_cpu cpu;
-   #define STATE_CPU(sd,n) (&(sd)->cpu)
-     ... simulator specific members ...
-     sim_state_base base;
-   };
-
-   for a single processor or
-
-   struct sim_state {
-     sim_cpu cpu[MAX_CPUS]; -- could be also be array of pointers
-   #define STATE_CPU(sd,n) (&(sd)->cpu[n])
-     ... simulator specific members ...
-     sim_state_base base;
-   };
-
-   for multiprocessors.
-   Note that `base' appears last.  This makes `base.magic' appear last
-   in the entire struct and helps catch miscompilation errors.
-
-   sim_cpu is defined to be:
-
-   typedef struct _sim_cpu {
-      ... simulator specific members ...
-      sim_cpu_base base;
-   } sim_cpu;
-   */
 
 typedef struct {
+
   /* Simulator's argv[0].  */
   const char *my_name;
 #define STATE_MY_NAME(sd) ((sd)->base.my_name)
@@ -94,6 +121,18 @@ typedef struct {
 #define STATE_CONFIG(sd) ((sd)->base.config)
 #endif
 
+  /* List of installed module `init' handlers.  */
+  MODULE_INIT_LIST *init_list;
+#define STATE_INIT_LIST(sd) ((sd)->base.init_list)
+  /* List of installed module `uninstall' handlers.  */
+  MODULE_UNINSTALL_LIST *uninstall_list;
+#define STATE_UNINSTALL_LIST(sd) ((sd)->base.uninstall_list)
+
+  /* ??? This might be more appropriate in sim_cpu.  */
+  /* Machine tables for this cpu.  See sim-model.h.  */
+  const MODEL *model;
+#define STATE_MODEL(sd) ((sd)->base.model)
+
   /* Supported options.  */
   struct option_list *options;
 #define STATE_OPTIONS(sd) ((sd)->base.options)
@@ -102,6 +141,14 @@ typedef struct {
   int verbose_p;
 #define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
 
+  /* If non NULL, the BFD architecture specified on the command line */
+  const struct bfd_arch_info *architecture;
+#define STATE_ARCHITECTURE(sd) ((sd)->base.architecture)
+
+  /* If non NULL, the bfd target specified on the command line */
+  const char *target;
+#define STATE_TARGET(sd) ((sd)->base.target)
+
   /* In standalone simulator, this is the program's arguments passed
      on the command line.  */
   char **prog_argv;
@@ -123,60 +170,65 @@ typedef struct {
   SIM_ADDR start_addr;
 #define STATE_START_ADDR(sd) ((sd)->base.start_addr)
 
+#if WITH_SCACHE
   /* Size of the simulator's cache, if any.
      This is not the target's cache.  It is the cache the simulator uses
      to process instructions.  */
-  unsigned int simcache_size;
-#define STATE_SIMCACHE_SIZE(sd) ((sd)->base.simcache_size)
+  unsigned int scache_size;
+#define STATE_SCACHE_SIZE(sd) ((sd)->base.scache_size)
+#endif
 
   /* FIXME: Move to top level sim_state struct (as some struct)?  */
 #ifdef SIM_HAVE_FLATMEM
   unsigned int mem_size;
 #define STATE_MEM_SIZE(sd) ((sd)->base.mem_size)
+  unsigned int mem_base;
+#define STATE_MEM_BASE(sd) ((sd)->base.mem_base)
   unsigned char *memory;
 #define STATE_MEMORY(sd) ((sd)->base.memory)
 #endif
 
+  /* core memory bus */
+#define STATE_CORE(sd) (&(sd)->base.core)
+  sim_core core;
+
+  /* event handler */
+#define STATE_EVENTS(sd) (&(sd)->base.events)
+  sim_events events;
+
+  /* generic halt/resume engine */
+  sim_engine engine;
+#define STATE_ENGINE(sd) (&(sd)->base.engine)
+
+  /* generic watchpoint support */
+  sim_watchpoints watchpoints;
+#define STATE_WATCHPOINTS(sd) (&(sd)->base.watchpoints)
+
   /* Marker for those wanting to do sanity checks.
      This should remain the last member of this struct to help catch
      miscompilation errors.  */
   int magic;
 #define SIM_MAGIC_NUMBER 0x4242
 #define STATE_MAGIC(sd) ((sd)->base.magic)
+
 } sim_state_base;
 
+
 /* Pseudo baseclass for each cpu.  */
 
 typedef struct {
+
   /* Backlink to main state struct.  */
-  SIM_DESC sd;
-#define CPU_STATE(cpu) ((cpu)->base.sd)
+  SIM_DESC state;
+#define CPU_STATE(cpu) ((cpu)->base.state)
 
-  /* Maximum number of traceable entities.  */
-#ifndef MAX_TRACE_VALUES
-#define MAX_TRACE_VALUES 12
-#endif
+  /* Processor specific core data */
+  sim_cpu_core core;
+#define CPU_CORE(cpu) (& (cpu)->base.core)
 
-  /* Boolean array of specified tracing flags.  */
-  /* ??? It's not clear that using an array vs a bit mask is faster.
-     Consider the case where one wants to test whether any of several bits
-     are set.  */
-  char trace_flags[MAX_TRACE_VALUES];
-#define CPU_TRACE_FLAGS(cpu) ((cpu)->base.trace_flags)
-  /* Standard values.  */
-#define TRACE_INSN_IDX 0
-#define TRACE_DECODE_IDX 1
-#define TRACE_EXTRACT_IDX 2
-#define TRACE_LINENUM_IDX 3
-#define TRACE_MEMORY_IDX 4
-#define TRACE_MODEL_IDX 5
-#define TRACE_ALU_IDX 6
-#define TRACE_NEXT_IDX 8 /* simulator specific trace bits begin here */
-
-  /* Tracing output goes to this or stdout if NULL.
-     We can't store `stdout' here as stdout goes through a callback.  */
-  FILE *trace_file;
-#define CPU_TRACE_FILE(cpu) ((cpu)->base.trace_file)
+  /* Trace data.  See sim-trace.h.  */
+  TRACE_DATA trace_data;
+#define CPU_TRACE_DATA(cpu) (& (cpu)->base.trace_data)
 
   /* Maximum number of debuggable entities.
      This debugging is not intended for normal use.
@@ -198,40 +250,16 @@ typedef struct {
   FILE *debug_file;
 #define CPU_DEBUG_FILE(cpu) ((cpu)->base.debug_file)
 
-#ifdef SIM_HAVE_PROFILE
-  /* Maximum number of profilable entities.  */
-#ifndef MAX_PROFILE_VALUES
-#define MAX_PROFILE_VALUES 8
-#endif
-
-  /* Boolean array of specified profiling flags.  */
-  char profile_flags[MAX_PROFILE_VALUES];
-#define CPU_PROFILE_FLAGS(cpu) ((cpu)->base.profile_flags)
-  /* Standard masks.  */
-#define PROFILE_INSN_MASK 0
-#define PROFILE_MEMORY_MASK 1
-#define PROFILE_MODEL_MASK 2
-#define PROFILE_SIMCACHE_MASK 3
-#define PROFILE_NEXT_MASK 6 /* simulator specific profile bits begin here */
-
-  /* PC profiling attempts to determine function usage by sampling the PC
-     every so many instructions.  */
-#ifdef SIM_HAVE_PROFILE_PC
-  unsigned int profile_pc_freq;
-#define STATE_PROFILE_PC_FREQ(sd) ((sd)->base.profile_pc_freq)
-  unsigned int profile_pc_size;
-#define STATE_PROFILE_PC_SIZE(sd) ((sd)->base.profile_pc_size)
-#endif
+  /* Profile data.  See sim-profile.h.  */
+  PROFILE_DATA profile_data;
+#define CPU_PROFILE_DATA(cpu) (& (cpu)->base.profile_data)
 
-  /* Profile output goes to this or stdout if NULL.
-     We can't store `stderr' here as stdout goes through a callback.  */
-  FILE *profile_file;
-#define CPU_PROFILE_FILE(cpu) ((cpu)->base.profile_file)
-#endif /* SIM_HAVE_PROFILE */
 } sim_cpu_base;
 
+
 /* Functions for allocating/freeing a sim_state.  */
 SIM_DESC sim_state_alloc PARAMS ((void));
 void sim_state_free PARAMS ((SIM_DESC));
 
+
 #endif /* SIM_BASE_H */