1 /* Main simulator entry points for 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. */
23 #include "sim-options.h"
24 #include "libiberty.h"
26 #include "sim-assert.h"
29 static void free_state (SIM_DESC
);
31 /* Records simulator descriptor so utilities like m32r_dump_regs can be
33 SIM_DESC current_state
;
35 /* Cover function of sim_state_free to free the cpu buffers as well. */
38 free_state (SIM_DESC sd
)
40 if (STATE_MODULES (sd
) != NULL
)
41 sim_module_uninstall (sd
);
42 sim_cpu_free_all (sd
);
46 /* Create an instance of the simulator. */
49 sim_open (kind
, callback
, abfd
, argv
)
51 host_callback
*callback
;
55 SIM_DESC sd
= sim_state_alloc (kind
, callback
);
57 sim_cpu_alloc_all (sd
, 1, 0);
59 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
65 /* Allocate core managed memory */
66 sim_do_commandf (sd
, "memory region 0,0x%lx", M32R_DEFAULT_MEM_SIZE
);
68 /* getopt will print the error message so we just have to exit if this fails.
69 FIXME: Hmmm... in the case of gdb we need getopt to call
71 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
77 /* check for/establish the reference program image */
78 if (sim_analyze_program (sd
,
79 (STATE_PROG_ARGV (sd
) != NULL
80 ? *STATE_PROG_ARGV (sd
)
88 /* Establish any remaining configuration options. */
89 if (sim_config (sd
) != SIM_RC_OK
)
95 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
101 /* Store in a global so things like sparc32_dump_regs can be invoked
102 from the gdb command line. */
104 sim_gx_read_block_list();
109 sim_close (sd
, quitting
)
113 sim_gx_write_block_list();
114 sim_module_uninstall (sd
);
119 m32r_h_pc_get (SIM_CPU
*current_cpu
)
121 return current_cpu
->regs
.h_pc
;
124 /* Set a value for h-pc. */
127 m32r_h_pc_set (SIM_CPU
*current_cpu
, USI newval
)
129 current_cpu
->regs
.h_pc
= newval
;
134 sim_create_inferior (sd
, abfd
, argv
, envp
)
140 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
143 CPU_PC_STORE (current_cpu
) = m32r_h_pc_set
;
144 CPU_PC_FETCH (current_cpu
) = m32r_h_pc_get
;
145 CPU_REG_STORE (current_cpu
) = NULL
;
146 CPU_REG_FETCH (current_cpu
) = NULL
;
149 addr
= bfd_get_start_address (abfd
);
153 sim_pc_set (current_cpu
, addr
);
156 STATE_ARGV (sd
) = sim_copy_argv (argv
);
157 STATE_ENVP (sd
) = sim_copy_argv (envp
);
164 sim_stop (SIM_DESC sd
)
166 sim_io_error(sd
, "cannot sim_stop\n");
169 /* This isn't part of the official interface.
170 This is just a good place to put this for now. */
173 sim_sync_stop (SIM_DESC sd
, SIM_CPU
*cpu
, PCADDR pc
, enum sim_stop reason
, int sigrc
)
175 sim_io_error(sd
, "cannot sim_stop\n");
179 sim_resume (sd
, step
, siggnal
)
183 sim_engine
*engine
= STATE_ENGINE (sd
);
187 sim_module_resume (sd
);
188 ASSERT(step
== 0); /* XXX */
190 engine
->jmpbuf
= &buf
;
191 jmpval
= setjmp (buf
);
193 sim_engine_run(sd
, 0, 1, siggnal
);
194 engine
->jmpbuf
= NULL
;
196 sim_module_suspend (sd
);
199 /* The contents of BUF are in target byte order. */
202 sim_fetch_register (sd
, rn
, buf
, length
)
208 SIM_CPU
*cpu
= STATE_CPU (sd
, 0);
210 return (* CPU_REG_FETCH (cpu
)) (cpu
, rn
, buf
, length
);
213 /* The contents of BUF are in target byte order. */
216 sim_store_register (sd
, rn
, buf
, length
)
222 SIM_CPU
*cpu
= STATE_CPU (sd
, 0);
224 return (* CPU_REG_STORE (cpu
)) (cpu
, rn
, buf
, length
);
228 sim_do_command (sd
, cmd
)
232 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
233 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);
236 /* Utility fns to access registers, without knowing the current mach. */
239 h_gr_get (SIM_CPU
*current_cpu
, UINT regno
)
241 SIM_DESC sd
= CURRENT_STATE
;
242 sim_io_error(sd
, "cannot h_gr_get\n");
246 h_gr_set (SIM_CPU
*current_cpu
, UINT regno
, SI newval
)
248 SIM_DESC sd
= CURRENT_STATE
;
249 sim_io_error(sd
, "cannot h_gr_set\n");