diff options
author | Mike Frysinger <vapier@gentoo.org> | 2016-01-21 21:00:25 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-05-17 00:42:55 -0400 |
commit | 383861bd08c47a160f54351e6b8519140b9aad8e (patch) | |
tree | dc43aadd66fbcc1f7cf18d8bebd7b14740086e48 /sim/common | |
parent | 92bc001e1f91390b8e009c29e75f4e8b9be02d76 (diff) | |
download | gdb-383861bd08c47a160f54351e6b8519140b9aad8e.zip gdb-383861bd08c47a160f54351e6b8519140b9aad8e.tar.gz gdb-383861bd08c47a160f54351e6b8519140b9aad8e.tar.bz2 |
sim: invert sim_state storage
Currently all ports have to declare sim_state themselves in their
sim-main.h and then embed the common sim_state_base & sim_cpu in it.
This dynamic makes it impossible to share common object code among
multiple ports because the core data structure is always different.
Let's invert this relationship: common code declares sim_state, and
if the port actually needs state on a per-instance basis, it can use
the new arch_data field for it. Most ports don't actually use it,
so they don't need to declare anything at all.
This is the first in a series of changes: it adds a define to select
between the old & new layouts, then converts all the ports that don't
need custom state over to the new layout.
Diffstat (limited to 'sim/common')
-rw-r--r-- | sim/common/ChangeLog | 10 | ||||
-rw-r--r-- | sim/common/sim-base.h | 30 | ||||
-rw-r--r-- | sim/common/sim-utils.c | 9 |
3 files changed, 38 insertions, 11 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 1d875bb..f3fcaee 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,13 @@ +2021-05-17 Mike Frysinger <vapier@gentoo.org> + + * sim-base.h (struct sim_state): Update comment. + (struct sim_state): Define. + (STATE_ARCH_DATA): Likewise. + (sim_state_alloc): New define. + (sim_state_alloc_extra): Renamed & add 3rd arg. + * sim-utils.c (sim_state_alloc): Likewise. + (sim_state_alloc_extra): Set arch data. + 2021-05-16 Mike Frysinger <vapier@gentoo.org> * callback.c: Replace config.h include with defs.h. diff --git a/sim/common/sim-base.h b/sim/common/sim-base.h index 731fc7f..f38e841 100644 --- a/sim/common/sim-base.h +++ b/sim/common/sim-base.h @@ -42,14 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ sim_cpu_base base; }; - struct sim_state { - sim_cpu *cpu[MAX_NR_PROCESSORS]; - ... 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. */ + If your sim needs to allocate sim-wide state, use STATE_ARCH_DATA. */ #ifndef SIM_BASE_H @@ -226,8 +219,27 @@ typedef struct { #define STATE_MAGIC(sd) ((sd)->base.magic) } sim_state_base; +#ifdef SIM_HAVE_COMMON_SIM_STATE +/* TODO: Merge sim_state & sim_state_base. */ +struct sim_state { + /* All the cpus for this instance. */ + sim_cpu *cpu[MAX_NR_PROCESSORS]; + + /* All the common state. */ + sim_state_base base; + + /* 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) +}; +#endif + /* Functions for allocating/freeing a sim_state. */ -SIM_DESC sim_state_alloc (SIM_OPEN_KIND kind, host_callback *callback); +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) + void sim_state_free (SIM_DESC); #ifdef __cplusplus diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c index abb87f8..7a94375 100644 --- a/sim/common/sim-utils.c +++ b/sim/common/sim-utils.c @@ -48,8 +48,8 @@ zalloc (unsigned long size) /* Allocate a sim_state struct. */ SIM_DESC -sim_state_alloc (SIM_OPEN_KIND kind, - host_callback *callback) +sim_state_alloc_extra (SIM_OPEN_KIND kind, host_callback *callback, + size_t extra_bytes) { SIM_DESC sd = ZALLOC (struct sim_state); @@ -57,6 +57,11 @@ sim_state_alloc (SIM_OPEN_KIND kind, STATE_CALLBACK (sd) = callback; STATE_OPEN_KIND (sd) = kind; +#ifdef SIM_HAVE_COMMON_SIM_STATE + if (extra_bytes) + STATE_ARCH_DATA (sd) = zalloc (extra_bytes); +#endif + #if 0 { int cpu_nr; |