1 /* Main simulator entry points specific to the FR30.
2 Copyright (C) 1998, 1999 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. */
25 #include "sim-options.h"
26 #include "libiberty.h"
29 static void free_state (SIM_DESC
);
30 static void print_fr30_misc_cpu (SIM_CPU
*cpu
, int verbose
);
32 /* Records simulator descriptor so utilities like fr30_dump_regs can be
34 SIM_DESC current_state
;
36 /* Cover function of sim_state_free to free the cpu buffers as well. */
39 free_state (SIM_DESC sd
)
41 if (STATE_MODULES (sd
) != NULL
)
42 sim_module_uninstall (sd
);
43 sim_cpu_free_all (sd
);
47 /* Create an instance of the simulator. */
50 sim_open (kind
, callback
, abfd
, argv
)
52 host_callback
*callback
;
58 SIM_DESC sd
= sim_state_alloc (kind
, callback
);
60 /* The cpu data is kept in a separately allocated chunk of memory. */
61 if (sim_cpu_alloc_all (sd
, 1, cgen_cpu_max_extra_bytes ()) != SIM_RC_OK
)
67 #if 0 /* FIXME: pc is in mach-specific struct */
68 /* FIXME: watchpoints code shouldn't need this */
70 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
71 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
72 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
76 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
82 #if 0 /* FIXME: 'twould be nice if we could do this */
83 /* These options override any module options.
84 Obviously ambiguity should be avoided, however the caller may wish to
85 augment the meaning of an option. */
86 if (extra_options
!= NULL
)
87 sim_add_option_table (sd
, extra_options
);
90 /* getopt will print the error message so we just have to exit if this fails.
91 FIXME: Hmmm... in the case of gdb we need getopt to call
93 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
100 /* Allocate a handler for the control registers and other devices
101 if no memory for that range has been allocated by the user.
102 All are allocated in one chunk to keep things from being
103 unnecessarily complicated. */
104 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, FR30_DEVICE_ADDR
, 1) == 0)
105 sim_core_attach (sd
, NULL
,
109 FR30_DEVICE_ADDR
, FR30_DEVICE_LEN
/*nr_bytes*/,
115 /* Allocate core managed memory if none specified by user.
116 Use address 4 here in case the user wanted address 0 unmapped. */
117 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, 4, 1) == 0)
118 sim_do_commandf (sd
, "memory region 0,0x%lx", FR30_DEFAULT_MEM_SIZE
);
120 /* check for/establish the reference program image */
121 if (sim_analyze_program (sd
,
122 (STATE_PROG_ARGV (sd
) != NULL
123 ? *STATE_PROG_ARGV (sd
)
131 /* Establish any remaining configuration options. */
132 if (sim_config (sd
) != SIM_RC_OK
)
138 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
144 /* Open a copy of the cpu descriptor table. */
146 CGEN_CPU_DESC cd
= fr30_cgen_cpu_open_1 (STATE_ARCHITECTURE (sd
)->printable_name
,
148 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
150 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
151 CPU_CPU_DESC (cpu
) = cd
;
152 CPU_DISASSEMBLER (cpu
) = sim_cgen_disassemble_insn
;
154 fr30_cgen_init_dis (cd
);
157 /* Initialize various cgen things not done by common framework.
158 Must be done after fr30_cgen_cpu_open. */
161 /* Store in a global so things like sparc32_dump_regs can be invoked
162 from the gdb command line. */
169 sim_close (sd
, quitting
)
173 fr30_cgen_cpu_close (CPU_CPU_DESC (STATE_CPU (sd
, 0)));
174 sim_module_uninstall (sd
);
178 sim_create_inferior (sd
, abfd
, argv
, envp
)
184 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
188 addr
= bfd_get_start_address (abfd
);
191 sim_pc_set (current_cpu
, addr
);
194 STATE_ARGV (sd
) = sim_copy_argv (argv
);
195 STATE_ENVP (sd
) = sim_copy_argv (envp
);
202 sim_do_command (sd
, cmd
)
206 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
207 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);