1999-04-16 09:35:26 +08:00
|
|
|
/* Simulator pseudo baseclass.
|
2003-02-20 22:37:59 +08:00
|
|
|
|
2023-01-01 20:49:04 +08:00
|
|
|
Copyright 1997-2023 Free Software Foundation, Inc.
|
2003-02-20 22:37:59 +08:00
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
Contributed by Cygnus Support.
|
|
|
|
|
|
|
|
This file is part of GDB, the GNU debugger.
|
|
|
|
|
|
|
|
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
|
2007-08-24 22:30:15 +08:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2007-08-24 22:30:15 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Simulator state pseudo baseclass.
|
|
|
|
|
|
|
|
Each simulator is required to have the file ``sim-main.h''. That
|
|
|
|
file includes ``sim-basics.h'', defines the base type ``sim_cia''
|
|
|
|
(the data type that contains complete current instruction address
|
|
|
|
information), include ``sim-base.h'':
|
|
|
|
|
|
|
|
#include "sim-basics.h"
|
|
|
|
/-* If `sim_cia' is not an integral value (e.g. a struct), define
|
|
|
|
CIA_ADDR to return the integral value. *-/
|
2015-04-18 16:08:56 +08:00
|
|
|
/-* typedef struct {...} sim_cia; *-/
|
1999-04-16 09:35:26 +08:00
|
|
|
/-* #define CIA_ADDR(cia) (...) *-/
|
|
|
|
#include "sim-base.h"
|
2011-03-15 11:16:17 +08:00
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
finally, two data types `struct _sim_cpu' and `struct sim_state'
|
|
|
|
are defined:
|
|
|
|
|
|
|
|
struct _sim_cpu {
|
|
|
|
... simulator specific members ...
|
|
|
|
sim_cpu_base base;
|
|
|
|
};
|
|
|
|
|
2016-01-22 10:00:25 +08:00
|
|
|
If your sim needs to allocate sim-wide state, use STATE_ARCH_DATA. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef SIM_BASE_H
|
|
|
|
#define SIM_BASE_H
|
|
|
|
|
2018-12-31 19:53:54 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
/* Pre-declare certain types. */
|
|
|
|
|
|
|
|
/* typedef <target-dependant> sim_cia; */
|
|
|
|
#ifndef NULL_CIA
|
|
|
|
#define NULL_CIA ((sim_cia) 0)
|
|
|
|
#endif
|
|
|
|
/* Return the current instruction address as a number.
|
|
|
|
Some targets treat the current instruction address as a struct
|
|
|
|
(e.g. for delay slot handling). */
|
|
|
|
#ifndef CIA_ADDR
|
|
|
|
#define CIA_ADDR(cia) (cia)
|
2015-04-18 16:08:56 +08:00
|
|
|
typedef address_word sim_cia;
|
1999-04-16 09:35:26 +08:00
|
|
|
#endif
|
|
|
|
#ifndef INVALID_INSTRUCTION_ADDRESS
|
|
|
|
#define INVALID_INSTRUCTION_ADDRESS ((address_word)0 - 1)
|
|
|
|
#endif
|
|
|
|
|
2015-04-18 16:19:56 +08:00
|
|
|
/* TODO: Probably should just delete SIM_CPU. */
|
|
|
|
typedef struct _sim_cpu SIM_CPU;
|
1999-04-16 09:35:26 +08:00
|
|
|
typedef struct _sim_cpu sim_cpu;
|
|
|
|
|
2022-12-23 11:01:19 +08:00
|
|
|
#include "bfd.h"
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
#include "sim-module.h"
|
|
|
|
|
2019-03-28 05:40:30 +08:00
|
|
|
#include "sim-arange.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
#include "sim-trace.h"
|
|
|
|
#include "sim-core.h"
|
|
|
|
#include "sim-events.h"
|
|
|
|
#include "sim-profile.h"
|
|
|
|
#include "sim-model.h"
|
|
|
|
#include "sim-io.h"
|
|
|
|
#include "sim-engine.h"
|
|
|
|
#include "sim-watch.h"
|
|
|
|
#include "sim-memopt.h"
|
|
|
|
#include "sim-cpu.h"
|
2019-03-29 06:33:29 +08:00
|
|
|
#include "sim-assert.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2016-01-22 11:51:00 +08:00
|
|
|
struct sim_state {
|
|
|
|
/* All the cpus for this instance. */
|
|
|
|
sim_cpu *cpu[MAX_NR_PROCESSORS];
|
2015-04-15 14:13:23 +08:00
|
|
|
#if (WITH_SMP)
|
|
|
|
# define STATE_CPU(sd, n) ((sd)->cpu[n])
|
|
|
|
#else
|
|
|
|
# define STATE_CPU(sd, n) ((sd)->cpu[0])
|
|
|
|
#endif
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
/* Simulator's argv[0]. */
|
|
|
|
const char *my_name;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_MY_NAME(sd) ((sd)->my_name)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* Who opened the simulator. */
|
|
|
|
SIM_OPEN_KIND open_kind;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_OPEN_KIND(sd) ((sd)->open_kind)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* The host callbacks. */
|
|
|
|
struct host_callback_struct *callback;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_CALLBACK(sd) ((sd)->callback)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* The type of simulation environment (user/operating). */
|
|
|
|
enum sim_environment environment;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_ENVIRONMENT(sd) ((sd)->environment)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
#if 0 /* FIXME: Not ready yet. */
|
|
|
|
/* Stuff defined in sim-config.h. */
|
|
|
|
struct sim_config config;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_CONFIG(sd) ((sd)->config)
|
1999-04-16 09:35:26 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* List of installed module `init' handlers. */
|
|
|
|
struct module_list *modules;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_MODULES(sd) ((sd)->modules)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* Supported options. */
|
|
|
|
struct option_list *options;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_OPTIONS(sd) ((sd)->options)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* Non-zero if -v specified. */
|
|
|
|
int verbose_p;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_VERBOSE_P(sd) ((sd)->verbose_p)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* Non cpu-specific trace data. See sim-trace.h. */
|
|
|
|
TRACE_DATA trace_data;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_TRACE_DATA(sd) (& (sd)->trace_data)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* If non NULL, the BFD architecture specified on the command line */
|
|
|
|
const struct bfd_arch_info *architecture;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_ARCHITECTURE(sd) ((sd)->architecture)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* If non NULL, the bfd target specified on the command line */
|
|
|
|
const char *target;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_TARGET(sd) ((sd)->target)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2021-06-29 09:42:56 +08:00
|
|
|
/* List of machs available. */
|
|
|
|
const SIM_MACH * const *machs;
|
|
|
|
#define STATE_MACHS(sd) ((sd)->machs)
|
|
|
|
|
2021-06-29 10:07:44 +08:00
|
|
|
/* If non-NULL, the model to select for CPUs. */
|
|
|
|
const char *model_name;
|
|
|
|
#define STATE_MODEL_NAME(sd) ((sd)->model_name)
|
|
|
|
|
2021-11-15 15:32:06 +08:00
|
|
|
/* In standalone simulator, this is the program to run. Not to be confused
|
|
|
|
with argv which are the strings passed to the program itself. */
|
|
|
|
char *prog_file;
|
|
|
|
#define STATE_PROG_FILE(sd) ((sd)->prog_file)
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
/* In standalone simulator, this is the program's arguments passed
|
|
|
|
on the command line. */
|
|
|
|
char **prog_argv;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_PROG_ARGV(sd) ((sd)->prog_argv)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2021-11-15 15:36:29 +08:00
|
|
|
/* Thie is the program's argv[0] override. */
|
|
|
|
char *prog_argv0;
|
|
|
|
#define STATE_PROG_ARGV0(sd) ((sd)->prog_argv0)
|
|
|
|
|
2021-11-16 12:00:04 +08:00
|
|
|
/* The program's environment. */
|
|
|
|
char **prog_envp;
|
|
|
|
#define STATE_PROG_ENVP(sd) ((sd)->prog_envp)
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
/* The program's bfd. */
|
Index: arm/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* wrapper.c (sim_create_inferior, sim_open): Rename _bfd to bfd.
Index: common/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* sim-utils.h (sim_analyze_program, sim_load_file): Rename _bfd to bfd.
* sim-hload.c (sim_load), sim-base.h (sim_state_base): Ditto.
* nrun.c (main): Ditto.
Index: d10v/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: erc32/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interf.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: h8300/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* compile.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: h8500/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* compile.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: i960/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* sim-if.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: m32r/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* sim-if.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: m68hc11/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (sim_prepare_for_program, sim_open)
(sim_create_inferior): Rename _bfd to bfd.
Index: mcore/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: mips/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (sim_open):
(sim_create_inferior):
Index: mn10200/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: mn10300/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (sim_open, sim_create_inferior, sim_open)
(sim_create_inferior): Rename _bfd to bfd.
Index: ppc/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* sim_calls.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: sh/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (init_dsp, sim_open, sim_create_inferior): Rename _bfd
to bfd.
Index: v850/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* interp.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
Index: z8k/ChangeLog
2003-02-27 Andrew Cagney <cagney@redhat.com>
* iface.c (sim_open, sim_create_inferior): Rename _bfd to bfd.
2003-02-28 07:26:34 +08:00
|
|
|
struct bfd *prog_bfd;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_PROG_BFD(sd) ((sd)->prog_bfd)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* Symbol table for prog_bfd */
|
Index: sim/frv/ChangeLog
2003-10-30 Andrew Cagney <cagney@redhat.com>
* traps.c: Replace "struct symbol_cache_entry" with "struct
bfd_symbol".
Index: sim/d10v/ChangeLog
2003-10-30 Andrew Cagney <cagney@redhat.com>
* simops.c: Replace "struct symbol_cache_entry" with "struct
bfd_symbol".
Index: sim/common/ChangeLog
2003-10-30 Andrew Cagney <cagney@redhat.com>
* sim-trace.c, sim-base.h: Replace "struct symbol_cache_entry"
with "struct bfd_symbol".
Index: ld/ChangeLog
2003-10-30 Andrew Cagney <cagney@redhat.com>
* emultempl/pe.em, pe-dll.c: Replace "struct symbol_cache_entry"
with "struct bfd_symbol".
Index: bfd/ChangeLog
2003-10-30 Andrew Cagney <cagney@redhat.com>
* syms.c: Replace "struct symbol_cache_entry" with "struct
bfd_symbol".
* vms.h, targets.c, section.c, reloc.c, peicode.h: Ditto.
* mipsbsd.c, elf.c, linker.c, elf-bfd.h, ecoff.c: Ditto.
* cpu-z8k.c, cpu-ns32k.c, cpu-h8500.c, bfd.c, bfd-in.h: Ditto.
* bfd-in2.h: Re-generate.
2003-10-31 13:32:46 +08:00
|
|
|
struct bfd_symbol **prog_syms;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_PROG_SYMS(sd) ((sd)->prog_syms)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2016-01-22 11:17:59 +08:00
|
|
|
/* Number of prog_syms symbols. */
|
|
|
|
long prog_syms_count;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_PROG_SYMS_COUNT(sd) ((sd)->prog_syms_count)
|
2016-01-22 11:17:59 +08:00
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
/* The program's text section. */
|
2003-10-19 Andrew Cagney <cagney@redhat.com>
* targets.c: Replace "struct sec" with "struct bfd_section"
* syms.c, sparclynx.c, section.c, opncls.c: Ditto.
* libcoff-in.h, libbfd-in.h, elfxx-target.h: Ditto.
* elf.c, coffgen.c, bfd.c, bfd-in.h, aoutf1.h: Ditto.
* aout-tic30.c, aout-target.h:
* bfd-in2.h, libcoff.h, libbfd.h: Regenerate.
Index: binutils/ChangeLog
2003-10-19 Andrew Cagney <cagney@redhat.com>
* coffgrok.h (coff_section): Replace 'struct sec" with "struct
bfd_section".
Index: gdb/ChangeLog
2003-10-19 Andrew Cagney <cagney@redhat.com>
* symtab.c: Replace "struct sec" with "struct bfd_section".
* objfiles.c, linespec.c, blockframe.c, block.c: Ditto.
Index: ld/ChangeLog
2003-10-19 Andrew Cagney <cagney@redhat.com>
* pe-dll.c: Replace "struct sec" with "struct bfd_section".
Index: sim/common/ChangeLog
2003-10-19 Andrew Cagney <cagney@redhat.com>
* sim-base.h: Replace "struct sec" with "struct bfd_section".
2003-10-20 22:38:46 +08:00
|
|
|
struct bfd_section *text_section;
|
1999-04-16 09:35:26 +08:00
|
|
|
/* Starting and ending text section addresses from the bfd. */
|
2006-11-08 03:07:41 +08:00
|
|
|
bfd_vma text_start, text_end;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_TEXT_SECTION(sd) ((sd)->text_section)
|
|
|
|
#define STATE_TEXT_START(sd) ((sd)->text_start)
|
|
|
|
#define STATE_TEXT_END(sd) ((sd)->text_end)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* Start address, set when the program is loaded from the bfd. */
|
2006-11-08 03:07:41 +08:00
|
|
|
bfd_vma start_addr;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_START_ADDR(sd) ((sd)->start_addr)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* 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 scache_size;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_SCACHE_SIZE(sd) ((sd)->scache_size)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* core memory bus */
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_CORE(sd) (&(sd)->core)
|
1999-04-16 09:35:26 +08:00
|
|
|
sim_core core;
|
|
|
|
|
|
|
|
/* Record of memory sections added via the memory-options interface. */
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_MEMOPT(sd) ((sd)->memopt)
|
1999-04-16 09:35:26 +08:00
|
|
|
sim_memopt *memopt;
|
|
|
|
|
|
|
|
/* event handler */
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_EVENTS(sd) (&(sd)->events)
|
1999-04-16 09:35:26 +08:00
|
|
|
sim_events events;
|
|
|
|
|
|
|
|
/* generic halt/resume engine */
|
|
|
|
sim_engine engine;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_ENGINE(sd) (&(sd)->engine)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
/* generic watchpoint support */
|
|
|
|
sim_watchpoints watchpoints;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_WATCHPOINTS(sd) (&(sd)->watchpoints)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
#if WITH_HW
|
|
|
|
struct sim_hw *hw;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_HW(sd) ((sd)->hw)
|
1999-04-16 09:35:26 +08:00
|
|
|
#endif
|
|
|
|
|
1999-07-12 19:15:22 +08:00
|
|
|
/* Should image loads be performed using the LMA or VMA? Older
|
|
|
|
simulators use the VMA while newer simulators prefer the LMA. */
|
|
|
|
int load_at_lma_p;
|
2016-01-22 11:51:00 +08:00
|
|
|
#define STATE_LOAD_AT_LMA_P(SD) ((SD)->load_at_lma_p)
|
2016-01-22 10:00:25 +08:00
|
|
|
|
|
|
|
/* Pointer for sim target to store arbitrary state data. Normally the
|
|
|
|
target should define a struct and use it here. */
|
|
|
|
void *arch_data;
|
|
|
|
#define STATE_ARCH_DATA(sd) ((sd)->arch_data)
|
2016-01-22 10:13:06 +08:00
|
|
|
|
2016-01-22 11:51:00 +08:00
|
|
|
/* 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)->magic)
|
2016-01-22 10:00:25 +08:00
|
|
|
};
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
/* Functions for allocating/freeing a sim_state. */
|
2016-01-22 10:00:25 +08:00
|
|
|
SIM_DESC sim_state_alloc_extra (SIM_OPEN_KIND kind, host_callback *callback,
|
|
|
|
size_t extra_bytes);
|
|
|
|
#define sim_state_alloc(kind, callback) sim_state_alloc_extra(kind, callback, 0)
|
|
|
|
|
2014-01-05 12:43:21 +08:00
|
|
|
void sim_state_free (SIM_DESC);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
2018-12-31 19:53:54 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
#endif /* SIM_BASE_H */
|