diff options
author | Andrew Cagney <cagney@redhat.com> | 1998-02-28 02:51:06 +0000 |
---|---|---|
committer | Andrew Cagney <cagney@redhat.com> | 1998-02-28 02:51:06 +0000 |
commit | 0e701ac37b0154048977636afe262f55a9150492 (patch) | |
tree | e84fefe5fad67b84aa35d7556388e8cc6161ed5f /sim/common/sim-module.c | |
parent | 7c5d88c1bb671d64d01766531d48a1dfca8c8ee1 (diff) | |
download | gdb-0e701ac37b0154048977636afe262f55a9150492.zip gdb-0e701ac37b0154048977636afe262f55a9150492.tar.gz gdb-0e701ac37b0154048977636afe262f55a9150492.tar.bz2 |
Add generic sim-info.c:sim_info() function using module mechanism.
Clean up compile probs in mips/vr5400.
Diffstat (limited to 'sim/common/sim-module.c')
-rw-r--r-- | sim/common/sim-module.c | 153 |
1 files changed, 138 insertions, 15 deletions
diff --git a/sim/common/sim-module.c b/sim/common/sim-module.c index c4dcd30..bb1dca4 100644 --- a/sim/common/sim-module.c +++ b/sim/common/sim-module.c @@ -70,6 +70,8 @@ SIM_RC sim_pre_argv_init (SIM_DESC sd, const char *myname) { SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); + STATE_MY_NAME (sd) = myname + strlen (myname); while (STATE_MY_NAME (sd) > myname && STATE_MY_NAME (sd)[-1] != '/') --STATE_MY_NAME (sd); @@ -99,6 +101,7 @@ sim_post_argv_init (SIM_DESC sd) { int i; SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) != NULL); if (sim_module_init (sd) != SIM_RC_OK) return SIM_RC_FAIL; @@ -117,13 +120,17 @@ SIM_RC sim_module_install (SIM_DESC sd) { MODULE_INSTALL_FN * const *modp; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); + STATE_MODULES (sd) = ZALLOC (struct module_list); for (modp = modules; *modp != NULL; ++modp) { if ((*modp) (sd) != SIM_RC_OK) { sim_module_uninstall (sd); + SIM_ASSERT (STATE_MODULES (sd) == NULL); return SIM_RC_FAIL; } } @@ -136,10 +143,13 @@ sim_module_install (SIM_DESC sd) SIM_RC sim_module_init (SIM_DESC sd) { + struct module_list *modules = STATE_MODULES (sd); MODULE_INIT_LIST *modp; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); - for (modp = STATE_INIT_LIST (sd); modp != NULL; modp = modp->next) + for (modp = modules->init_list; modp != NULL; modp = modp->next) { if ((*modp->fn) (sd) != SIM_RC_OK) return SIM_RC_FAIL; @@ -152,10 +162,13 @@ sim_module_init (SIM_DESC sd) SIM_RC sim_module_resume (SIM_DESC sd) { + struct module_list *modules = STATE_MODULES (sd); MODULE_RESUME_LIST *modp; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); - for (modp = STATE_RESUME_LIST (sd); modp != NULL; modp = modp->next) + for (modp = modules->resume_list; modp != NULL; modp = modp->next) { if ((*modp->fn) (sd) != SIM_RC_OK) return SIM_RC_FAIL; @@ -168,10 +181,13 @@ sim_module_resume (SIM_DESC sd) SIM_RC sim_module_suspend (SIM_DESC sd) { + struct module_list *modules = STATE_MODULES (sd); MODULE_SUSPEND_LIST *modp; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); - for (modp = STATE_SUSPEND_LIST (sd); modp != NULL; modp = modp->next) + for (modp = modules->suspend_list; modp != NULL; modp = modp->next) { if ((*modp->fn) (sd) != SIM_RC_OK) return SIM_RC_FAIL; @@ -184,12 +200,85 @@ sim_module_suspend (SIM_DESC sd) void sim_module_uninstall (SIM_DESC sd) { + struct module_list *modules = STATE_MODULES (sd); MODULE_UNINSTALL_LIST *modp; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); /* Uninstall the modules. */ - for (modp = STATE_UNINSTALL_LIST (sd); modp != NULL; modp = modp->next) + for (modp = modules->uninstall_list; modp != NULL; modp = modp->next) (*modp->fn) (sd); + + /* clean-up init list */ + { + MODULE_INIT_LIST *n, *d; + for (d = modules->init_list; d != NULL; d = n) + { + n = d->next; + zfree (d); + } + } + + /* clean-up resume list */ + { + MODULE_RESUME_LIST *n, *d; + for (d = modules->resume_list; d != NULL; d = n) + { + n = d->next; + zfree (d); + } + } + + /* clean-up suspend list */ + { + MODULE_SUSPEND_LIST *n, *d; + for (d = modules->suspend_list; d != NULL; d = n) + { + n = d->next; + zfree (d); + } + } + + /* clean-up uninstall list */ + { + MODULE_UNINSTALL_LIST *n, *d; + for (d = modules->uninstall_list; d != NULL; d = n) + { + n = d->next; + zfree (d); + } + } + + /* clean-up info list */ + { + MODULE_INFO_LIST *n, *d; + for (d = modules->info_list; d != NULL; d = n) + { + n = d->next; + zfree (d); + } + } + + zfree (modules); + STATE_MODULES (sd) = NULL; +} + +/* Called when ever simulator info is needed */ + +void +sim_module_info (SIM_DESC sd, int verbose) +{ + struct module_list *modules = STATE_MODULES (sd); + MODULE_INFO_LIST *modp; + + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); + + for (modp = modules->info_list; modp != NULL; modp = modp->next) + { + (*modp->fn) (sd, verbose); + } } /* Add FN to the init handler list. @@ -198,11 +287,14 @@ sim_module_uninstall (SIM_DESC sd) void sim_module_add_init_fn (SIM_DESC sd, MODULE_INIT_FN fn) { - MODULE_INIT_LIST *l = - (MODULE_INIT_LIST *) xmalloc (sizeof (MODULE_INIT_LIST)); - MODULE_INIT_LIST **last = &STATE_INIT_LIST (sd); + struct module_list *modules = STATE_MODULES (sd); + MODULE_INIT_LIST *l = ZALLOC (MODULE_INIT_LIST); + MODULE_INIT_LIST **last; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); + last = &modules->init_list; while (*last != NULL) last = &((*last)->next); @@ -217,11 +309,14 @@ sim_module_add_init_fn (SIM_DESC sd, MODULE_INIT_FN fn) void sim_module_add_resume_fn (SIM_DESC sd, MODULE_RESUME_FN fn) { + struct module_list *modules = STATE_MODULES (sd); MODULE_RESUME_LIST *l = ZALLOC (MODULE_RESUME_LIST); MODULE_RESUME_LIST **last; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); - last = &STATE_RESUME_LIST (sd); + last = &modules->resume_list; while (*last != NULL) last = &((*last)->next); @@ -236,17 +331,20 @@ sim_module_add_resume_fn (SIM_DESC sd, MODULE_RESUME_FN fn) void sim_module_add_suspend_fn (SIM_DESC sd, MODULE_SUSPEND_FN fn) { + struct module_list *modules = STATE_MODULES (sd); MODULE_SUSPEND_LIST *l = ZALLOC (MODULE_SUSPEND_LIST); MODULE_SUSPEND_LIST **last; + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); - last = &STATE_SUSPEND_LIST (sd); + last = &modules->suspend_list; while (*last != NULL) last = &((*last)->next); l->fn = fn; - l->next = STATE_SUSPEND_LIST (sd); - STATE_SUSPEND_LIST (sd) = l; + l->next = modules->suspend_list; + modules->suspend_list = l; } /* Add FN to the uninstall handler list. @@ -255,10 +353,35 @@ sim_module_add_suspend_fn (SIM_DESC sd, MODULE_SUSPEND_FN fn) void sim_module_add_uninstall_fn (SIM_DESC sd, MODULE_UNINSTALL_FN fn) { - MODULE_UNINSTALL_LIST *l = - (MODULE_UNINSTALL_LIST *) xmalloc (sizeof (MODULE_UNINSTALL_LIST)); + struct module_list *modules = STATE_MODULES (sd); + MODULE_UNINSTALL_LIST *l = ZALLOC (MODULE_UNINSTALL_LIST); + + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); + + l->fn = fn; + l->next = modules->uninstall_list; + modules->uninstall_list = l; +} + +/* Add FN to the info handler list. + Report info in the same order as the install. */ + +void +sim_module_add_info_fn (SIM_DESC sd, MODULE_INFO_FN fn) +{ + struct module_list *modules = STATE_MODULES (sd); + MODULE_INFO_LIST *l = ZALLOC (MODULE_INFO_LIST); + MODULE_INFO_LIST **last; + + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + SIM_ASSERT (STATE_MODULES (sd) == NULL); + + last = &modules->info_list; + while (*last != NULL) + last = &((*last)->next); l->fn = fn; - l->next = STATE_UNINSTALL_LIST (sd); - STATE_UNINSTALL_LIST (sd) = l; + l->next = NULL; + *last = l; } |