1 /* Main simulator entry points specific to the SH5.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
5 This file is part of the GNU simulators.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "libiberty.h"
27 #include "sim-options.h"
30 static void free_state (SIM_DESC
);
32 /* Since we don't build the cgen-opcode table, we use a wrapper around
33 the existing disassembler from libopcodes. */
34 static CGEN_DISASSEMBLER sh64_disassemble_insn
;
36 /* Records simulator descriptor so utilities like sh5_dump_regs can be
38 SIM_DESC current_state
;
40 /* Cover function of sim_state_free to free the cpu buffers as well. */
43 free_state (SIM_DESC sd
)
45 if (STATE_MODULES (sd
) != NULL
)
46 sim_module_uninstall (sd
);
47 sim_cpu_free_all (sd
);
51 /* Create an instance of the simulator. */
54 sim_open (kind
, callback
, abfd
, argv
)
56 host_callback
*callback
;
62 SIM_DESC sd
= sim_state_alloc (kind
, callback
);
64 /* The cpu data is kept in a separately allocated chunk of memory. */
65 if (sim_cpu_alloc_all (sd
, 1, cgen_cpu_max_extra_bytes ()) != SIM_RC_OK
)
71 #if 0 /* FIXME: pc is in mach-specific struct */
72 /* FIXME: watchpoints code shouldn't need this */
74 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
75 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
76 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
80 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
86 #if 0 /* FIXME: 'twould be nice if we could do this */
87 /* These options override any module options.
88 Obviously ambiguity should be avoided, however the caller may wish to
89 augment the meaning of an option. */
90 if (extra_options
!= NULL
)
91 sim_add_option_table (sd
, extra_options
);
94 /* getopt will print the error message so we just have to exit if this fails.
95 FIXME: Hmmm... in the case of gdb we need getopt to call
97 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
103 /* Allocate core managed memory if none specified by user.
104 Use address 4 here in case the user wanted address 0 unmapped. */
105 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, 4, 1) == 0)
106 sim_do_commandf (sd
, "memory region 0,0x%x", SH64_DEFAULT_MEM_SIZE
);
108 /* Add a small memory region way up in the address space to handle
109 writes to invalidate an instruction cache line. This is used for
110 trampolines. Since we don't simulate the cache, this memory just
111 avoids bus errors. 64K ought to do. */
112 sim_do_command (sd
," memory region 0xf0000000,0x10000");
114 /* check for/establish the reference program image */
115 if (sim_analyze_program (sd
,
116 (STATE_PROG_ARGV (sd
) != NULL
117 ? *STATE_PROG_ARGV (sd
)
125 /* Establish any remaining configuration options. */
126 if (sim_config (sd
) != SIM_RC_OK
)
132 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
138 /* Open a copy of the cpu descriptor table. */
140 CGEN_CPU_DESC cd
= sh_cgen_cpu_open_1 (STATE_ARCHITECTURE (sd
)->printable_name
,
143 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
145 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
146 CPU_CPU_DESC (cpu
) = cd
;
147 CPU_DISASSEMBLER (cpu
) = sh64_disassemble_insn
;
151 /* Clear idesc table pointers for good measure. */
152 sh64_idesc_media
= sh64_idesc_compact
= NULL
;
154 /* Initialize various cgen things not done by common framework.
155 Must be done after sh_cgen_cpu_open. */
158 /* Store in a global so things like sparc32_dump_regs can be invoked
159 from the gdb command line. */
166 sim_close (sd
, quitting
)
170 sh_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd
, 0)));
171 sim_module_uninstall (sd
);
175 sim_create_inferior (sd
, abfd
, argv
, envp
)
181 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
185 addr
= bfd_get_start_address (abfd
);
188 sim_pc_set (current_cpu
, addr
);
191 STATE_ARGV (sd
) = sim_copy_argv (argv
);
192 STATE_ENVP (sd
) = sim_copy_argv (envp
);
199 sim_do_command (sd
, cmd
)
203 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
204 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);
208 /* Disassemble an instruction. */
211 sh64_disassemble_insn (SIM_CPU
*cpu
, const CGEN_INSN
*insn
,
212 const ARGBUF
*abuf
, IADDR pc
, char *buf
)
214 struct disassemble_info disasm_info
;
216 SIM_DESC sd
= CPU_STATE (cpu
);
218 sfile
.buffer
= sfile
.current
= buf
;
219 INIT_DISASSEMBLE_INFO (disasm_info
, (FILE *) &sfile
,
220 (fprintf_ftype
) sim_disasm_sprintf
);
222 disasm_info
.arch
= bfd_get_arch (STATE_PROG_BFD (sd
));
223 disasm_info
.mach
= bfd_get_mach (STATE_PROG_BFD (sd
));
225 (bfd_big_endian (STATE_PROG_BFD (sd
)) ? BFD_ENDIAN_BIG
226 : bfd_little_endian (STATE_PROG_BFD (sd
)) ? BFD_ENDIAN_LITTLE
227 : BFD_ENDIAN_UNKNOWN
);
228 disasm_info
.read_memory_func
= sim_disasm_read_memory
;
229 disasm_info
.memory_error_func
= sim_disasm_perror_memory
;
230 disasm_info
.application_data
= (PTR
) cpu
;
232 if (sh64_h_ism_get (cpu
) == ISM_MEDIA
)
233 print_insn_sh64x_media (pc
, &disasm_info
);
235 print_insn_sh (pc
, &disasm_info
);