1 /* Main simulator entry points for the SPARC.
2 Copyright (C) 1999 Cygnus Solutions. */
14 /* FIXME: Do we *need* to pass state to the semantic routines? */
15 SIM_DESC current_state
;
17 static MODULE_SUSPEND_FN regwin_suspend
;
19 /* Cover function of sim_state_free to free the cpu buffers as well. */
22 free_state (SIM_DESC sd
)
24 if (STATE_MODULES (sd
) != NULL
)
25 sim_module_uninstall (sd
);
26 sim_cpu_free_all (sd
);
30 /* Create an instance of the simulator. */
33 sim_open (kind
, callback
, abfd
, argv
)
35 host_callback
*callback
;
41 SIM_DESC sd
= sim_state_alloc (kind
, callback
);
43 /* The cpu data is kept in a separately allocated chunk of memory. */
44 if (sim_cpu_alloc_all (sd
, 1, cgen_cpu_max_extra_bytes ()) != SIM_RC_OK
)
50 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
56 #if 0 /* FIXME: 'twould be nice if we could do this */
57 /* These options override any module options.
58 Obviously ambiguity should be avoided, however the caller may wish to
59 augment the meaning of an option. */
60 if (extra_options
!= NULL
)
61 sim_add_option_table (sd
, extra_options
);
64 /* Make the default --environment=operating to be compatible with erc32. */
65 STATE_ENVIRONMENT (sd
) = OPERATING_ENVIRONMENT
;
67 /* getopt will print the error message so we just have to exit if this fails.
68 FIXME: Hmmm... in the case of gdb we need getopt to call
70 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
76 /* check for/establish the a reference program image */
77 if (sim_analyze_program (sd
,
78 (STATE_PROG_ARGV (sd
) != NULL
79 ? *STATE_PROG_ARGV (sd
)
87 /* Establish any remaining configuration options. */
88 if (sim_config (sd
) != SIM_RC_OK
)
94 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
100 /* Initialize various cgen things not done by common framework. */
103 /* Open a copy of the opcode table. */
104 STATE_OPCODE_TABLE (sd
) = sparc_cgen_opcode_open (STATE_ARCHITECTURE (sd
)->mach
,
106 sparc_cgen_init_dis (STATE_OPCODE_TABLE (sd
));
108 /* Allocate a handler for the control registers and other devices
109 if no memory for that range has been allocated by the user.
110 All are allocated in one chunk to keep things from being
111 unnecessarily complicated. */
112 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, ERC32_DEVICE_ADDR
, 1) == 0)
113 sim_core_attach (sd
, NULL
,
117 ERC32_DEVICE_ADDR
, ERC32_DEVICE_LEN
/*nr_bytes*/,
122 /* Allocate core managed memory if none specified by user. */
123 /* Use address 4 here in case the user wanted address 0 unmapped. */
124 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, 4, 1) == 0)
125 sim_do_commandf (sd
, "memory region 0,0x%x", SPARC_DEFAULT_MEM_SIZE
);
126 /* FIXME: magic number */
127 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, 0x2000000, 1) == 0)
128 sim_do_commandf (sd
, "memory region 0x%x,0x%x", 0x2000000, 0x200000);
133 sparc32_alloc_regwins (STATE_CPU (sd
, 0), NWINDOWS
);
139 sparc64_alloc_regwins (STATE_CPU (sd
, 0), NWINDOWS
);
143 sim_module_add_suspend_fn (sd
, regwin_suspend
);
145 /* Perform a cold-reset of the cpu(s). */
147 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
148 sparc32_cold_reset (STATE_CPU (sd
, i
), 0);
150 /* Store in a global so things like sparc32_dump_regs can be invoked
151 from the gdb command line. */
158 sim_close (sd
, quitting
)
164 sparc32_free_regwins (STATE_CPU (sd
, 0));
168 sparc64_free_regwins (STATE_CPU (sd
, 0));
170 sim_module_uninstall (sd
);
174 sim_create_inferior (sd
, abfd
, argv
, envp
)
183 addr
= bfd_get_start_address (abfd
);
188 STATE_ARGV (sd
) = sim_copy_argv (argv
);
189 STATE_ENVP (sd
) = sim_copy_argv (envp
);
195 sparc32_cold_reset (STATE_CPU (sd
, 0), 1);
196 sparc32_init_pc (STATE_CPU (sd
, 0), addr
, addr
+ 4);
202 sparc64_cold_reset (STATE_CPU (sd
, 0), 1);
203 sparc64_init_pc (STATE_CPU (sd
, 0), addr
, addr
+ 4);
210 /* Flush the register windows when we suspend so we can walk the stack
212 ??? Extremely inefficient in case where gdb is running a program
214 ??? Also interferes with debugging of --environment=operating. */
217 regwin_suspend (SIM_DESC sd
)
221 for (c
= 0; c
< MAX_NR_PROCESSORS
; ++c
)
223 SIM_CPU
*cpu
= STATE_CPU (sd
, c
);
227 sparc32_flush_regwins (cpu
, sim_pc_get (cpu
), 1 /* no errors */);
231 sparc64_flush_regwins (cpu
, sim_pc_get (cpu
), 1 /* no errors */);
239 sim_do_command (sd
, cmd
)
243 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
244 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);