/* Main simulator entry points specific to Lattice Mico32.
Contributed by Jon Beniston <jon@beniston.com>
- Copyright (C) 2009-2016 Free Software Foundation, Inc.
+ Copyright (C) 2009-2021 Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+/* This must come before any other includes. */
+#include "defs.h"
+
#include "sim-main.h"
#include "sim-options.h"
#include "libiberty.h"
#include "bfd.h"
-#ifdef HAVE_STDLIB_H
#include <stdlib.h>
-#endif
\f
/* Cover function of sim_state_free to free the cpu buffers as well. */
found = 0;
for (s = prog_bfd->sections; s; s = s->next)
{
- if ((strcmp (bfd_get_section_name (prog_bfd, s), ".boot") == 0)
- || (strcmp (bfd_get_section_name (prog_bfd, s), ".text") == 0)
- || (strcmp (bfd_get_section_name (prog_bfd, s), ".data") == 0)
- || (strcmp (bfd_get_section_name (prog_bfd, s), ".bss") == 0))
+ if ((strcmp (bfd_section_name (s), ".boot") == 0)
+ || (strcmp (bfd_section_name (s), ".text") == 0)
+ || (strcmp (bfd_section_name (s), ".data") == 0)
+ || (strcmp (bfd_section_name (s), ".bss") == 0))
{
if (!found)
{
- base = bfd_get_section_vma (prog_bfd, s);
+ base = bfd_section_vma (s);
found = 1;
}
else
- base =
- bfd_get_section_vma (prog_bfd,
- s) < base ? bfd_get_section_vma (prog_bfd,
- s) : base;
+ base = bfd_section_vma (s) < base ? bfd_section_vma (s) : base;
}
}
return base & ~(0xffffUL);
}
static unsigned long
-find_limit (bfd *prog_bfd)
+find_limit (SIM_DESC sd)
{
- struct bfd_symbol **asymbols;
- long symsize;
- long symbol_count;
- long s;
+ bfd_vma addr;
- symsize = bfd_get_symtab_upper_bound (prog_bfd);
- if (symsize < 0)
- return 0;
- asymbols = (asymbol **) xmalloc (symsize);
- symbol_count = bfd_canonicalize_symtab (prog_bfd, asymbols);
- if (symbol_count < 0)
+ addr = trace_sym_value (sd, "_fstack");
+ if (addr == -1)
return 0;
- for (s = 0; s < symbol_count; s++)
- {
- if (!strcmp (asymbols[s]->name, "_fstack"))
- return (asymbols[s]->value + 65536) & ~(0xffffUL);
- }
- return 0;
+ return (addr + 65536) & ~(0xffffUL);
}
+extern const SIM_MACH * const lm32_sim_machs[];
+
/* Create an instance of the simulator. */
SIM_DESC
-sim_open (kind, callback, abfd, argv)
- SIM_OPEN_KIND kind;
- host_callback *callback;
- struct bfd *abfd;
- char * const *argv;
+sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
+ char * const *argv)
{
SIM_DESC sd = sim_state_alloc (kind, callback);
char c;
int i;
unsigned long base, limit;
+ /* Set default options before parsing user options. */
+ STATE_MACHS (sd) = lm32_sim_machs;
+ STATE_MODEL_NAME (sd) = "lm32";
+ current_alignment = STRICT_ALIGNMENT;
+ current_target_byte_order = BFD_ENDIAN_BIG;
+
/* The cpu data is kept in a separately allocated chunk of memory. */
- if (sim_cpu_alloc_all (sd, 1, cgen_cpu_max_extra_bytes ()) != SIM_RC_OK)
+ if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK)
{
free_state (sd);
return 0;
{
/* It doesn't, so we should try to allocate enough memory to hold program. */
base = find_base (STATE_PROG_BFD (sd));
- limit = find_limit (STATE_PROG_BFD (sd));
+ limit = find_limit (sd);
if (limit == 0)
{
sim_io_eprintf (sd,
free_state (sd);
return 0;
}
- /*sim_io_printf (sd, "Allocating memory at 0x%x size 0x%x\n", base, limit); */
- sim_do_commandf (sd, "memory region 0x%x,0x%x", base, limit);
+ /*sim_io_printf (sd, "Allocating memory at 0x%lx size 0x%lx\n", base, limit); */
+ sim_do_commandf (sd, "memory region 0x%lx,0x%lx", base, limit);
}
}
lm32_cgen_init_dis (cd);
}
- /* Initialize various cgen things not done by common framework.
- Must be done after lm32_cgen_cpu_open. */
- cgen_init (sd);
-
return sd;
}
\f
SIM_RC
-sim_create_inferior (sd, abfd, argv, envp)
- SIM_DESC sd;
- struct bfd *abfd;
- char * const *argv;
- char * const *envp;
+sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
+ char * const *envp)
{
SIM_CPU *current_cpu = STATE_CPU (sd, 0);
SIM_ADDR addr;