SIM_DESC sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd, char **argv) { callbacks = callback; /* Note: The simulation is not created by sim_open() because complete information is not yet available */ /* trace the call */ TRACE(trace_gdb, ("sim_open called\n")); if (root_device != NULL) sim_io_printf_filtered("Warning - re-open of simulator leaks memory\n"); root_device = psim_tree(); simulator = NULL; psim_options(root_device, argv + 1); if (ppc_trace[trace_opts]) print_options (); /* fudge our descriptor for now */ return (SIM_DESC) 1; }
int main(int argc, char **argv) { const char *name_of_file; char *arg_; psim_status status; device *root = psim_tree(); /* parse the arguments */ argv = psim_options(root, argv + 1); if (argv[0] == NULL) { if (ppc_trace[trace_opts]) { print_options (); return 0; } else { psim_usage(0, 0); } } name_of_file = argv[0]; if (ppc_trace[trace_opts]) print_options (); /* create the simulator */ simulation = psim_create(name_of_file, root); /* fudge the environment so that _=prog-name */ arg_ = (char*)zalloc(strlen(argv[0]) + strlen("_=") + 1); strcpy(arg_, "_="); strcat(arg_, argv[0]); putenv(arg_); /* initialize it */ psim_init(simulation); psim_stack(simulation, argv, environ); { RETSIGTYPE (*prev) (); prev = signal(SIGINT, cntrl_c); psim_run(simulation); signal(SIGINT, prev); } /* any final clean up */ if (ppc_trace[trace_print_info]) psim_print_info (simulation, ppc_trace[trace_print_info]); /* why did we stop */ status = psim_get_status(simulation); switch (status.reason) { case was_continuing: error("psim: continuing while stopped!\n"); return 0; case was_trap: error("psim: no trap insn\n"); return 0; case was_exited: return status.signal; case was_signalled: printf ("%s: Caught signal %d at address 0x%lx\n", name_of_file, (int)status.signal, (long)status.program_counter); return status.signal; default: error("unknown halt condition\n"); return 0; } }