SIM_RC sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **envp) { unsigned_word entry_point; TRACE(trace_gdb, ("sim_create_inferior(start_address=0x%x, ...)\n", entry_point)); if (simulator == NULL) error ("No program loaded"); if (abfd != NULL) entry_point = bfd_get_start_address (abfd); else entry_point = 0xfff00000; /* ??? */ psim_init(simulator); psim_stack(simulator, argv, envp); ASSERT (psim_write_register(simulator, -1 /* all start at same PC */, &entry_point, "pc", cooked_transfer) > 0); return SIM_RC_OK; }
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; } }