xref: /netbsd-src/external/gpl3/gdb/dist/sim/common/sim-base.h (revision 0d3e0572e40d81edb4fdbff937458d47b685c34c)
14e98e3e1Schristos /* Simulator pseudo baseclass.
24e98e3e1Schristos 
3*0d3e0572Schristos    Copyright 1997-2024 Free Software Foundation, Inc.
44e98e3e1Schristos 
54e98e3e1Schristos    Contributed by Cygnus Support.
64e98e3e1Schristos 
74e98e3e1Schristos This file is part of GDB, the GNU debugger.
84e98e3e1Schristos 
94e98e3e1Schristos This program is free software; you can redistribute it and/or modify
104e98e3e1Schristos it under the terms of the GNU General Public License as published by
114e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or
124e98e3e1Schristos (at your option) any later version.
134e98e3e1Schristos 
144e98e3e1Schristos This program is distributed in the hope that it will be useful,
154e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
164e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
174e98e3e1Schristos GNU General Public License for more details.
184e98e3e1Schristos 
194e98e3e1Schristos You should have received a copy of the GNU General Public License
204e98e3e1Schristos along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
214e98e3e1Schristos 
224e98e3e1Schristos 
234e98e3e1Schristos /* Simulator state pseudo baseclass.
244e98e3e1Schristos 
254e98e3e1Schristos    Each simulator is required to have the file ``sim-main.h''.  That
264e98e3e1Schristos    file includes ``sim-basics.h'', defines the base type ``sim_cia''
274e98e3e1Schristos    (the data type that contains complete current instruction address
284e98e3e1Schristos    information), include ``sim-base.h'':
294e98e3e1Schristos 
304e98e3e1Schristos      #include "sim-basics.h"
314e98e3e1Schristos      /-* If `sim_cia' is not an integral value (e.g. a struct), define
324e98e3e1Schristos          CIA_ADDR to return the integral value.  *-/
33212397c6Schristos      /-* typedef struct {...} sim_cia; *-/
344e98e3e1Schristos      /-* #define CIA_ADDR(cia) (...) *-/
354e98e3e1Schristos      #include "sim-base.h"
364e98e3e1Schristos 
374e98e3e1Schristos    finally, two data types `struct _sim_cpu' and `struct sim_state'
384e98e3e1Schristos    are defined:
394e98e3e1Schristos 
404e98e3e1Schristos      struct _sim_cpu {
414e98e3e1Schristos         ... simulator specific members ...
424e98e3e1Schristos         sim_cpu_base base;
434e98e3e1Schristos      };
444e98e3e1Schristos 
454b169a6bSchristos    If your sim needs to allocate sim-wide state, use STATE_ARCH_DATA.  */
464e98e3e1Schristos 
474e98e3e1Schristos 
484e98e3e1Schristos #ifndef SIM_BASE_H
494e98e3e1Schristos #define SIM_BASE_H
504e98e3e1Schristos 
514559860eSchristos #ifdef __cplusplus
524559860eSchristos extern "C" {
534559860eSchristos #endif
544559860eSchristos 
554e98e3e1Schristos /* Pre-declare certain types. */
564e98e3e1Schristos 
574e98e3e1Schristos /* typedef <target-dependant> sim_cia; */
584e98e3e1Schristos #ifndef NULL_CIA
594e98e3e1Schristos #define NULL_CIA ((sim_cia) 0)
604e98e3e1Schristos #endif
614e98e3e1Schristos /* Return the current instruction address as a number.
624e98e3e1Schristos    Some targets treat the current instruction address as a struct
634e98e3e1Schristos    (e.g. for delay slot handling).  */
644e98e3e1Schristos #ifndef CIA_ADDR
654e98e3e1Schristos #define CIA_ADDR(cia) (cia)
66212397c6Schristos typedef address_word sim_cia;
674e98e3e1Schristos #endif
684e98e3e1Schristos #ifndef INVALID_INSTRUCTION_ADDRESS
694e98e3e1Schristos #define INVALID_INSTRUCTION_ADDRESS ((address_word)0 - 1)
704e98e3e1Schristos #endif
714e98e3e1Schristos 
72212397c6Schristos /* TODO: Probably should just delete SIM_CPU.  */
73212397c6Schristos typedef struct _sim_cpu SIM_CPU;
744e98e3e1Schristos typedef struct _sim_cpu sim_cpu;
754e98e3e1Schristos 
76*0d3e0572Schristos #include "bfd.h"
77*0d3e0572Schristos 
784e98e3e1Schristos #include "sim-module.h"
794e98e3e1Schristos 
808dffb485Schristos #include "sim-arange.h"
814e98e3e1Schristos #include "sim-trace.h"
824e98e3e1Schristos #include "sim-core.h"
834e98e3e1Schristos #include "sim-events.h"
844e98e3e1Schristos #include "sim-profile.h"
854e98e3e1Schristos #include "sim-model.h"
864e98e3e1Schristos #include "sim-io.h"
874e98e3e1Schristos #include "sim-engine.h"
884e98e3e1Schristos #include "sim-watch.h"
894e98e3e1Schristos #include "sim-memopt.h"
904e98e3e1Schristos #include "sim-cpu.h"
918dffb485Schristos #include "sim-assert.h"
924e98e3e1Schristos 
934b169a6bSchristos struct sim_state {
944b169a6bSchristos   /* All the cpus for this instance.  */
954b169a6bSchristos   sim_cpu *cpu[MAX_NR_PROCESSORS];
96212397c6Schristos #if (WITH_SMP)
97212397c6Schristos # define STATE_CPU(sd, n) ((sd)->cpu[n])
98212397c6Schristos #else
99212397c6Schristos # define STATE_CPU(sd, n) ((sd)->cpu[0])
100212397c6Schristos #endif
101212397c6Schristos 
1024e98e3e1Schristos   /* Simulator's argv[0].  */
1034e98e3e1Schristos   const char *my_name;
1044b169a6bSchristos #define STATE_MY_NAME(sd) ((sd)->my_name)
1054e98e3e1Schristos 
1064e98e3e1Schristos   /* Who opened the simulator.  */
1074e98e3e1Schristos   SIM_OPEN_KIND open_kind;
1084b169a6bSchristos #define STATE_OPEN_KIND(sd) ((sd)->open_kind)
1094e98e3e1Schristos 
1104e98e3e1Schristos   /* The host callbacks.  */
1114e98e3e1Schristos   struct host_callback_struct *callback;
1124b169a6bSchristos #define STATE_CALLBACK(sd) ((sd)->callback)
1134e98e3e1Schristos 
1144e98e3e1Schristos   /* The type of simulation environment (user/operating).  */
1154e98e3e1Schristos   enum sim_environment environment;
1164b169a6bSchristos #define STATE_ENVIRONMENT(sd) ((sd)->environment)
1174e98e3e1Schristos 
1184e98e3e1Schristos #if 0 /* FIXME: Not ready yet.  */
1194e98e3e1Schristos   /* Stuff defined in sim-config.h.  */
1204e98e3e1Schristos   struct sim_config config;
1214b169a6bSchristos #define STATE_CONFIG(sd) ((sd)->config)
1224e98e3e1Schristos #endif
1234e98e3e1Schristos 
1244e98e3e1Schristos   /* List of installed module `init' handlers.  */
1254e98e3e1Schristos   struct module_list *modules;
1264b169a6bSchristos #define STATE_MODULES(sd) ((sd)->modules)
1274e98e3e1Schristos 
1284e98e3e1Schristos   /* Supported options.  */
1294e98e3e1Schristos   struct option_list *options;
1304b169a6bSchristos #define STATE_OPTIONS(sd) ((sd)->options)
1314e98e3e1Schristos 
1324e98e3e1Schristos   /* Non-zero if -v specified.  */
1334e98e3e1Schristos   int verbose_p;
1344b169a6bSchristos #define STATE_VERBOSE_P(sd) ((sd)->verbose_p)
1354e98e3e1Schristos 
1364e98e3e1Schristos   /* Non cpu-specific trace data.  See sim-trace.h.  */
1374e98e3e1Schristos   TRACE_DATA trace_data;
1384b169a6bSchristos #define STATE_TRACE_DATA(sd) (& (sd)->trace_data)
1394e98e3e1Schristos 
1404e98e3e1Schristos   /* If non NULL, the BFD architecture specified on the command line */
1414e98e3e1Schristos   const struct bfd_arch_info *architecture;
1424b169a6bSchristos #define STATE_ARCHITECTURE(sd) ((sd)->architecture)
1434e98e3e1Schristos 
1444e98e3e1Schristos   /* If non NULL, the bfd target specified on the command line */
1454e98e3e1Schristos   const char *target;
1464b169a6bSchristos #define STATE_TARGET(sd) ((sd)->target)
1474b169a6bSchristos 
1484b169a6bSchristos   /* List of machs available.  */
1494b169a6bSchristos   const SIM_MACH * const *machs;
1504b169a6bSchristos #define STATE_MACHS(sd) ((sd)->machs)
1514b169a6bSchristos 
1524b169a6bSchristos   /* If non-NULL, the model to select for CPUs.  */
1534b169a6bSchristos   const char *model_name;
1544b169a6bSchristos #define STATE_MODEL_NAME(sd) ((sd)->model_name)
1554b169a6bSchristos 
1564b169a6bSchristos   /* In standalone simulator, this is the program to run.  Not to be confused
1574b169a6bSchristos      with argv which are the strings passed to the program itself.  */
1584b169a6bSchristos   char *prog_file;
1594b169a6bSchristos #define STATE_PROG_FILE(sd) ((sd)->prog_file)
1604e98e3e1Schristos 
1614e98e3e1Schristos   /* In standalone simulator, this is the program's arguments passed
1624e98e3e1Schristos      on the command line.  */
1634e98e3e1Schristos   char **prog_argv;
1644b169a6bSchristos #define STATE_PROG_ARGV(sd) ((sd)->prog_argv)
1654b169a6bSchristos 
1664b169a6bSchristos   /* Thie is the program's argv[0] override.  */
1674b169a6bSchristos   char *prog_argv0;
1684b169a6bSchristos #define STATE_PROG_ARGV0(sd) ((sd)->prog_argv0)
1694b169a6bSchristos 
1704b169a6bSchristos   /* The program's environment.  */
1714b169a6bSchristos   char **prog_envp;
1724b169a6bSchristos #define STATE_PROG_ENVP(sd) ((sd)->prog_envp)
1734e98e3e1Schristos 
1744e98e3e1Schristos   /* The program's bfd.  */
1754e98e3e1Schristos   struct bfd *prog_bfd;
1764b169a6bSchristos #define STATE_PROG_BFD(sd) ((sd)->prog_bfd)
1774e98e3e1Schristos 
1784e98e3e1Schristos   /* Symbol table for prog_bfd */
1794e98e3e1Schristos   struct bfd_symbol **prog_syms;
1804b169a6bSchristos #define STATE_PROG_SYMS(sd) ((sd)->prog_syms)
1814e98e3e1Schristos 
182796c32c9Schristos   /* Number of prog_syms symbols.  */
183796c32c9Schristos   long prog_syms_count;
1844b169a6bSchristos #define STATE_PROG_SYMS_COUNT(sd) ((sd)->prog_syms_count)
185796c32c9Schristos 
1864e98e3e1Schristos   /* The program's text section.  */
1874e98e3e1Schristos   struct bfd_section *text_section;
1884e98e3e1Schristos   /* Starting and ending text section addresses from the bfd.  */
1894e98e3e1Schristos   bfd_vma text_start, text_end;
1904b169a6bSchristos #define STATE_TEXT_SECTION(sd) ((sd)->text_section)
1914b169a6bSchristos #define STATE_TEXT_START(sd) ((sd)->text_start)
1924b169a6bSchristos #define STATE_TEXT_END(sd) ((sd)->text_end)
1934e98e3e1Schristos 
1944e98e3e1Schristos   /* Start address, set when the program is loaded from the bfd.  */
1954e98e3e1Schristos   bfd_vma start_addr;
1964b169a6bSchristos #define STATE_START_ADDR(sd) ((sd)->start_addr)
1974e98e3e1Schristos 
1984e98e3e1Schristos   /* Size of the simulator's cache, if any.
1994e98e3e1Schristos      This is not the target's cache.  It is the cache the simulator uses
2004e98e3e1Schristos      to process instructions.  */
2014e98e3e1Schristos   unsigned int scache_size;
2024b169a6bSchristos #define STATE_SCACHE_SIZE(sd) ((sd)->scache_size)
2034e98e3e1Schristos 
2044e98e3e1Schristos   /* core memory bus */
2054b169a6bSchristos #define STATE_CORE(sd) (&(sd)->core)
2064e98e3e1Schristos   sim_core core;
2074e98e3e1Schristos 
2084e98e3e1Schristos   /* Record of memory sections added via the memory-options interface.  */
2094b169a6bSchristos #define STATE_MEMOPT(sd) ((sd)->memopt)
2104e98e3e1Schristos   sim_memopt *memopt;
2114e98e3e1Schristos 
2124e98e3e1Schristos   /* event handler */
2134b169a6bSchristos #define STATE_EVENTS(sd) (&(sd)->events)
2144e98e3e1Schristos   sim_events events;
2154e98e3e1Schristos 
2164e98e3e1Schristos   /* generic halt/resume engine */
2174e98e3e1Schristos   sim_engine engine;
2184b169a6bSchristos #define STATE_ENGINE(sd) (&(sd)->engine)
2194e98e3e1Schristos 
2204e98e3e1Schristos   /* generic watchpoint support */
2214e98e3e1Schristos   sim_watchpoints watchpoints;
2224b169a6bSchristos #define STATE_WATCHPOINTS(sd) (&(sd)->watchpoints)
2234e98e3e1Schristos 
2244e98e3e1Schristos #if WITH_HW
2254e98e3e1Schristos   struct sim_hw *hw;
2264b169a6bSchristos #define STATE_HW(sd) ((sd)->hw)
2274e98e3e1Schristos #endif
2284e98e3e1Schristos 
2294e98e3e1Schristos   /* Should image loads be performed using the LMA or VMA?  Older
2304e98e3e1Schristos      simulators use the VMA while newer simulators prefer the LMA. */
2314e98e3e1Schristos   int load_at_lma_p;
2324b169a6bSchristos #define STATE_LOAD_AT_LMA_P(SD) ((SD)->load_at_lma_p)
2334b169a6bSchristos 
2344b169a6bSchristos   /* Pointer for sim target to store arbitrary state data.  Normally the
2354b169a6bSchristos      target should define a struct and use it here.  */
2364b169a6bSchristos   void *arch_data;
2374b169a6bSchristos #define STATE_ARCH_DATA(sd) ((sd)->arch_data)
2384e98e3e1Schristos 
2394e98e3e1Schristos   /* Marker for those wanting to do sanity checks.
2404e98e3e1Schristos      This should remain the last member of this struct to help catch
2414e98e3e1Schristos      miscompilation errors.  */
2424e98e3e1Schristos   int magic;
2434e98e3e1Schristos #define SIM_MAGIC_NUMBER 0x4242
2444b169a6bSchristos #define STATE_MAGIC(sd) ((sd)->magic)
2454b169a6bSchristos };
2464e98e3e1Schristos 
2474e98e3e1Schristos /* Functions for allocating/freeing a sim_state.  */
2484b169a6bSchristos SIM_DESC sim_state_alloc_extra (SIM_OPEN_KIND kind, host_callback *callback,
2494b169a6bSchristos 				size_t extra_bytes);
2504b169a6bSchristos #define sim_state_alloc(kind, callback) sim_state_alloc_extra(kind, callback, 0)
2514b169a6bSchristos 
25203467a24Schristos void sim_state_free (SIM_DESC);
2534e98e3e1Schristos 
2544559860eSchristos #ifdef __cplusplus
2554559860eSchristos }
2564559860eSchristos #endif
2574559860eSchristos 
2584e98e3e1Schristos #endif /* SIM_BASE_H */
259