1 /* Main simulator entry points specific to the M32R.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include "sim-options.h"
21 #include "libiberty.h"
35 static void free_state (SIM_DESC
);
36 static void print_m32r_misc_cpu (SIM_CPU
*cpu
, int verbose
);
38 /* Records simulator descriptor so utilities like m32r_dump_regs can be
40 SIM_DESC current_state
;
42 /* Cover function of sim_state_free to free the cpu buffers as well. */
45 free_state (SIM_DESC sd
)
47 if (STATE_MODULES (sd
) != NULL
)
48 sim_module_uninstall (sd
);
49 sim_cpu_free_all (sd
);
53 /* Create an instance of the simulator. */
56 sim_open (kind
, callback
, abfd
, argv
)
58 host_callback
*callback
;
62 SIM_DESC sd
= sim_state_alloc (kind
, callback
);
65 /* The cpu data is kept in a separately allocated chunk of memory. */
66 if (sim_cpu_alloc_all (sd
, 1, cgen_cpu_max_extra_bytes ()) != SIM_RC_OK
)
72 #if 0 /* FIXME: pc is in mach-specific struct */
73 /* FIXME: watchpoints code shouldn't need this */
75 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
76 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
77 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
81 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
87 #ifdef HAVE_DV_SOCKSER /* FIXME: was done differently before */
88 if (dv_sockser_install (sd
) != SIM_RC_OK
)
95 #if 0 /* FIXME: 'twould be nice if we could do this */
96 /* These options override any module options.
97 Obviously ambiguity should be avoided, however the caller may wish to
98 augment the meaning of an option. */
99 if (extra_options
!= NULL
)
100 sim_add_option_table (sd
, extra_options
);
103 /* getopt will print the error message so we just have to exit if this fails.
104 FIXME: Hmmm... in the case of gdb we need getopt to call
106 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
112 /* Allocate a handler for the control registers and other devices
113 if no memory for that range has been allocated by the user.
114 All are allocated in one chunk to keep things from being
115 unnecessarily complicated. */
116 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, M32R_DEVICE_ADDR
, 1) == 0)
117 sim_core_attach (sd
, NULL
,
121 M32R_DEVICE_ADDR
, M32R_DEVICE_LEN
/*nr_bytes*/,
126 /* Allocate core managed memory if none specified by user.
127 Use address 4 here in case the user wanted address 0 unmapped. */
128 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, 4, 1) == 0)
129 sim_do_commandf (sd
, "memory region 0,0x%x", M32R_DEFAULT_MEM_SIZE
);
131 /* check for/establish the reference program image */
132 if (sim_analyze_program (sd
,
133 (STATE_PROG_ARGV (sd
) != NULL
134 ? *STATE_PROG_ARGV (sd
)
142 /* Establish any remaining configuration options. */
143 if (sim_config (sd
) != SIM_RC_OK
)
149 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
155 /* Initialize various cgen things not done by common framework. */
158 /* Open a copy of the opcode table. */
159 STATE_OPCODE_TABLE (sd
) = m32r_cgen_opcode_open (STATE_ARCHITECTURE (sd
)->mach
,
161 m32r_cgen_init_dis (STATE_OPCODE_TABLE (sd
));
166 for (c
= 0; c
< MAX_NR_PROCESSORS
; ++c
)
168 /* Only needed for profiling, but the structure member is small. */
169 memset (CPU_M32R_MISC_PROFILE (STATE_CPU (sd
, c
)), 0,
170 sizeof (* CPU_M32R_MISC_PROFILE (STATE_CPU (sd
, c
))));
171 /* Hook in callback for reporting these stats */
172 PROFILE_INFO_CPU_CALLBACK (CPU_PROFILE_DATA (STATE_CPU (sd
, c
)))
173 = print_m32r_misc_cpu
;
177 /* Store in a global so things like sparc32_dump_regs can be invoked
178 from the gdb command line. */
185 sim_close (sd
, quitting
)
189 m32r_cgen_opcode_close (STATE_OPCODE_TABLE (sd
));
190 sim_module_uninstall (sd
);
194 sim_create_inferior (sd
, abfd
, argv
, envp
)
200 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
204 addr
= bfd_get_start_address (abfd
);
207 sim_pc_set (current_cpu
, addr
);
210 STATE_ARGV (sd
) = sim_copy_argv (argv
);
211 STATE_ENVP (sd
) = sim_copy_argv (envp
);
217 /* PROFILE_CPU_CALLBACK */
220 print_m32r_misc_cpu (SIM_CPU
*cpu
, int verbose
)
222 SIM_DESC sd
= CPU_STATE (cpu
);
225 if (CPU_PROFILE_FLAGS (cpu
) [PROFILE_INSN_IDX
])
227 sim_io_printf (sd
, "Miscellaneous Statistics\n\n");
228 sim_io_printf (sd
, " %-*s %s\n\n",
229 PROFILE_LABEL_WIDTH
, "Fill nops:",
230 sim_add_commas (buf
, sizeof (buf
),
231 CPU_M32R_MISC_PROFILE (cpu
)->fillnop_count
));
232 if (STATE_ARCHITECTURE (sd
)->mach
== bfd_mach_m32rx
)
233 sim_io_printf (sd
, " %-*s %s\n\n",
234 PROFILE_LABEL_WIDTH
, "Parallel insns:",
235 sim_add_commas (buf
, sizeof (buf
),
236 CPU_M32R_MISC_PROFILE (cpu
)->parallel_count
));
241 sim_do_command (sd
, cmd
)
250 argv
= buildargv (cmd
);
253 && strcasecmp (argv
[0], "info") == 0
255 && strncasecmp (argv
[1], "reg", 3) == 0)
259 /* We only support printing bbpsw,bbpc here as there is no equivalent
260 functionality in gdb. */
262 sim_io_eprintf (sd
, "Missing register in `%s'\n", cmd
);
263 else if (argv
[3] != NULL
)
264 sim_io_eprintf (sd
, "Too many arguments in `%s'\n", cmd
);
265 else if (strcasecmp (argv
[2], "bbpsw") == 0)
267 val
= a_m32r_h_cr_get (STATE_CPU (sd
, 0), H_CR_BBPSW
);
268 sim_io_printf (sd
, "bbpsw 0x%x %d\n", val
, val
);
270 else if (strcasecmp (argv
[2], "bbpc") == 0)
272 val
= a_m32r_h_cr_get (STATE_CPU (sd
, 0), H_CR_BBPC
);
273 sim_io_printf (sd
, "bbpc 0x%x %d\n", val
, val
);
276 sim_io_eprintf (sd
, "Printing of register `%s' not supported with `sim info'\n",
281 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
282 sim_io_eprintf (sd
, "Unknown sim command `%s'\n", cmd
);
This page took 0.047861 seconds and 5 git commands to generate.