/* load.c --- loading object files into the RX simulator.
-Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+Copyright (C) 2005-2020 Free Software Foundation, Inc.
Contributed by Red Hat, Inc.
This file is part of the GNU simulators.
#include <string.h>
#include "bfd.h"
-#include "libbfd.h"
#include "cpu.h"
#include "mem.h"
+#include "load.h"
#include "elf/internal.h"
#include "elf/common.h"
+/* Helper function for invoking a GDB-specified printf. */
+static void
+xprintf (host_callback *callback, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+
+ (*callback->vprintf_filtered) (callback, fmt, ap);
+
+ va_end (ap);
+}
+
+/* Given a file offset, look up the section name. */
+static const char *
+find_section_name_by_offset (bfd *abfd, file_ptr filepos)
+{
+ asection *s;
+
+ for (s = abfd->sections; s; s = s->next)
+ if (s->filepos == filepos)
+ return bfd_section_name (s);
+
+ return "(unknown)";
+}
+
/* A note about endianness and swapping...
The RX chip is CISC-like in that the opcodes are variable length
encoded in little-endian format. */
void
-rx_load (bfd *prog)
+rx_load (bfd *prog, host_callback *callback)
{
unsigned long highest_addr_loaded = 0;
Elf_Internal_Phdr * phdrs;
if (verbose > 1)
fprintf (stderr, "[load segment: lma=%08x vma=%08x size=%08x]\n",
(int) base, (int) p->p_vaddr, (int) size);
+ if (callback)
+ xprintf (callback,
+ "Loading section %s, size %#lx lma %08lx vma %08lx\n",
+ find_section_name_by_offset (prog, p->p_offset),
+ size, base, p->p_vaddr);
buf = malloc (size);
if (buf == NULL)
}
offset = p->p_offset;
- if (prog->iovec->bseek (prog, offset, SEEK_SET) != 0)
+ if (bfd_seek (prog, offset, SEEK_SET) != 0)
{
fprintf (stderr, "Failed to seek to offset %lx\n", (long) offset);
continue;
}
- if (prog->iovec->bread (prog, buf, size) != size)
+ if (bfd_bread (buf, size, prog) != size)
{
fprintf (stderr, "Failed to read %lx bytes\n", size);
continue;
heaptop = heapbottom = 0;
}
+ reset_decoder ();
+
if (verbose > 1)
fprintf (stderr, "[start pc=%08x %s]\n",
(unsigned int) regs.r_pc,