1 /* Main simulator entry points for the M32R.
2 Copyright (C) 1996, 1997 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. */
24 #include "libiberty.h"
29 /* Global state until sim_open starts creating and returning it
30 [and the other simulator i/f fns take it as an argument]. */
31 struct sim_state sim_global_state
;
33 /* FIXME: Do we *need* to pass state to the semantic routines? */
36 /* Create an instance of the simulator. */
39 sim_open (kind
, callback
, abfd
, argv
)
41 host_callback
*callback
;
46 SIM_DESC sd
= &sim_global_state
;
48 /* FIXME: until we alloc one, use the global. */
49 memset (sd
, 0, sizeof (sim_global_state
));
50 STATE_OPEN_KIND (sd
) = kind
;
51 STATE_CALLBACK (sd
) = callback
;
53 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 /* getopt will print the error message so we just have to exit if this fails.
65 FIXME: Hmmm... in the case of gdb we need getopt to call
67 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
69 sim_module_uninstall (sd
);
73 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
75 sim_module_uninstall (sd
);
79 /* Initialize various cgen things not done by common framework. */
83 sim_core_attach (sd
, NULL
, attach_raw_memory
, access_read_write_exec
,
84 0, 0, M32R_DEFAULT_MEM_SIZE
, NULL
, NULL
);
86 /* Only needed for profiling, but the structure member is small. */
87 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
88 memset (& CPU_M32R_PROFILE (STATE_CPU (sd
, i
)), 0,
89 sizeof (CPU_M32R_PROFILE (STATE_CPU (sd
, i
))));
91 return &sim_global_state
;
95 sim_close (sd
, quitting
)
99 sim_module_uninstall (sd
);
103 sim_load (sd
, prog
, abfd
, from_tty
)
109 extern bfd
*sim_load_file (); /* ??? Don't know where this should live. */
112 prog_bfd
= sim_load_file (sd
, STATE_MY_NAME (sd
),
115 /* pass NULL for abfd, we always open our own */
117 STATE_OPEN_KIND (sd
) == SIM_OPEN_DEBUG
);
118 if (prog_bfd
== NULL
)
120 sim_analyze_program (sd
, prog_bfd
);
121 STATE_CPU_CPU (sd
, 0)->pc
= STATE_START_ADDR (sd
);
126 sim_create_inferior (sd
, argv
, envp
)
132 STATE_ARGV (sd
) = sim_copy_argv (argv
);
133 STATE_ENVP (sd
) = sim_copy_argv (envp
);
139 sim_stop (SIM_DESC sd
)
141 return engine_stop (sd
);
145 sim_resume (sd
, step
, siggnal
)
149 engine_run (sd
, step
, siggnal
);
153 sim_stop_reason (sd
, reason
, sigrc
)
155 enum sim_stop
*reason
;
158 sim_cpu
*cpu
= STATE_CPU (sd
, 0);
160 /* Map sim_state to sim_stop. */
161 switch (CPU_EXEC_STATE (cpu
))
163 case EXEC_STATE_EXITED
:
164 *reason
= sim_exited
;
165 *sigrc
= CPU_HALT_SIGRC (cpu
);
167 case EXEC_STATE_STOPPED
:
168 *reason
= sim_stopped
;
169 *sigrc
= sim_signal_to_host (CPU_HALT_SIGRC (cpu
));
171 case EXEC_STATE_SIGNALLED
:
172 *reason
= sim_signalled
;
173 *sigrc
= sim_signal_to_host (CPU_HALT_SIGRC (cpu
));
178 /* PROFILE_CPU_CALLBACK */
181 print_m32r_misc_cpu (SIM_CPU
*cpu
, int verbose
)
183 SIM_DESC sd
= CPU_STATE (cpu
);
186 if (CPU_PROFILE_FLAGS (cpu
) [PROFILE_INSN_IDX
])
188 sim_io_printf (sd
, "Miscellaneous Statistics\n\n");
189 sim_io_printf (sd
, " %-*s %s\n\n",
190 PROFILE_LABEL_WIDTH
, "Fill nops:",
191 sim_add_commas (buf
, sizeof (buf
),
192 CPU_M32R_PROFILE (cpu
).fillnop_count
));
197 sim_info (sd
, verbose
)
201 profile_print (sd
, STATE_VERBOSE_P (sd
), NULL
, print_m32r_misc_cpu
);
204 /* The contents of BUF are in target byte order. */
207 sim_fetch_register (sd
, rn
, buf
)
213 SETTWI (buf
, STATE_CPU_CPU (sd
, 0)->h_gr
[rn
]);
215 SETTWI (buf
, STATE_CPU_CPU (sd
, 0)->h_cr
[rn
- 16]);
218 SETTWI (buf
, STATE_CPU_CPU (sd
, 0)->pc
);
221 SETTWI (buf
, GETLODI (STATE_CPU_CPU (sd
, 0)->h_accum
));
224 SETTWI (buf
, GETHIDI (STATE_CPU_CPU (sd
, 0)->h_accum
));
227 case 23: *reg
= STATE_CPU_CPU (sd
, 0)->h_cond
; break;
228 case 24: *reg
= STATE_CPU_CPU (sd
, 0)->h_sm
; break;
229 case 25: *reg
= STATE_CPU_CPU (sd
, 0)->h_bsm
; break;
230 case 26: *reg
= STATE_CPU_CPU (sd
, 0)->h_ie
; break;
231 case 27: *reg
= STATE_CPU_CPU (sd
, 0)->h_bie
; break;
232 case 28: *reg
= STATE_CPU_CPU (sd
, 0)->h_bcarry
; break; /* rename: bc */
233 case 29: memcpy (buf
, &STATE_CPU_CPU (sd
, 0)->h_bpc
, sizeof(WI
)); break; /* duplicate */
239 /* The contents of BUF are in target byte order. */
242 sim_store_register (sd
, rn
, buf
)
248 STATE_CPU_CPU (sd
, 0)->h_gr
[rn
] = GETTWI (buf
);
250 STATE_CPU_CPU (sd
, 0)->h_cr
[rn
- 16] = GETTWI (buf
);
253 STATE_CPU_CPU (sd
, 0)->pc
= GETTWI (buf
);
256 SETLODI (STATE_CPU_CPU (sd
, 0)->h_accum
, GETTWI (buf
));
259 SETHIDI (STATE_CPU_CPU (sd
, 0)->h_accum
, GETTWI (buf
));
262 case 23: STATE_CPU_CPU (sd
, 0)->h_cond
= *reg
; break;
263 case 24: STATE_CPU_CPU (sd
, 0)->h_sm
= *reg
; break;
264 case 25: STATE_CPU_CPU (sd
, 0)->h_bsm
= *reg
; break;
265 case 26: STATE_CPU_CPU (sd
, 0)->h_ie
= *reg
; break;
266 case 27: STATE_CPU_CPU (sd
, 0)->h_bie
= *reg
; break;
267 case 28: STATE_CPU_CPU (sd
, 0)->h_bcarry
= *reg
; break; /* rename: bc */
268 case 29: memcpy (&STATE_CPU_CPU (sd
, 0)->h_bpc
, buf
, sizeof(DI
)); break; /* duplicate */
274 sim_read (sd
, addr
, buf
, len
)
281 return sim_core_read_buffer (sd
, NULL
, sim_core_read_map
,
284 return (*STATE_MEM_READ (sd
)) (sd
, addr
, buf
, len
);
289 sim_write (sd
, addr
, buf
, len
)
296 return sim_core_write_buffer (sd
, NULL
, sim_core_write_map
,
299 return (*STATE_MEM_WRITE (sd
)) (sd
, addr
, buf
, len
);
304 sim_do_command (sd
, cmd
)
308 sim_io_error (sd
, "sim_do_command - unimplemented");