mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-21 04:42:53 +08:00
6df01ab8ab
The defs.h header will take care of including the various config.h headers. For now, it's just config.h, but we'll add more when we integrate gnulib in. This header should be used instead of config.h, and should be the first include in every .c file. We won't rely on the old behavior where we expected files to include the port's sim-main.h which then includes the common sim-basics.h which then includes config.h. We have a ton of code that includes things before sim-main.h, and it sometimes needs to be that way. Creating a dedicated header avoids the ordering mess and implicit inclusion that shows up otherwise.
134 lines
3.3 KiB
C
134 lines
3.3 KiB
C
/* load.c --- loading object files into the M32C simulator.
|
|
|
|
Copyright (C) 2005-2021 Free Software Foundation, Inc.
|
|
Contributed by Red Hat, Inc.
|
|
|
|
This file is part of the GNU simulators.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
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 <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "bfd.h"
|
|
|
|
#include "cpu.h"
|
|
#include "mem.h"
|
|
#include "load.h"
|
|
|
|
int (*decode_opcode) (void) = 0;
|
|
int default_machine = 0;
|
|
|
|
void
|
|
m32c_set_mach (unsigned long mach)
|
|
{
|
|
switch (mach)
|
|
{
|
|
case bfd_mach_m16c:
|
|
m32c_set_cpu (CPU_M16C);
|
|
if (verbose)
|
|
fprintf (stderr, "[cpu: r8c/m16c]\n");
|
|
break;
|
|
case bfd_mach_m32c:
|
|
m32c_set_cpu (CPU_M32C);
|
|
if (verbose)
|
|
fprintf (stderr, "[cpu: m32cm/m32c]\n");
|
|
break;
|
|
default:
|
|
fprintf (stderr, "unknown m32c machine type 0x%lx\n", mach);
|
|
decode_opcode = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void
|
|
m32c_load (bfd * prog)
|
|
{
|
|
asection *s;
|
|
unsigned long mach = bfd_get_mach (prog);
|
|
unsigned long highest_addr_loaded = 0;
|
|
|
|
if (mach == 0 && default_machine != 0)
|
|
mach = default_machine;
|
|
|
|
m32c_set_mach (mach);
|
|
|
|
for (s = prog->sections; s; s = s->next)
|
|
{
|
|
#if 0
|
|
/* This was a good idea until we started storing the RAM data in
|
|
ROM, at which point everything was all messed up. The code
|
|
remains as a reminder. */
|
|
if ((s->flags & SEC_ALLOC) && !(s->flags & SEC_READONLY))
|
|
{
|
|
if (strcmp (bfd_section_name (s), ".stack"))
|
|
{
|
|
int secend =
|
|
bfd_section_size (s) + bfd_section_lma (s);
|
|
if (heaptop < secend && bfd_section_lma (s) < 0x10000)
|
|
{
|
|
heaptop = heapbottom = secend;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
if (s->flags & SEC_LOAD)
|
|
{
|
|
char *buf;
|
|
bfd_size_type size;
|
|
bfd_vma base;
|
|
|
|
size = bfd_section_size (s);
|
|
if (size <= 0)
|
|
continue;
|
|
|
|
base = bfd_section_lma (s);
|
|
if (verbose)
|
|
fprintf (stderr, "[load a=%08" BFD_VMA_FMT "x s=%08x %s]\n",
|
|
base, (int) size, bfd_section_name (s));
|
|
buf = (char *) malloc (size);
|
|
bfd_get_section_contents (prog, s, buf, 0, size);
|
|
mem_put_blk (base, buf, size);
|
|
free (buf);
|
|
if (highest_addr_loaded < base + size - 1 && size >= 4)
|
|
highest_addr_loaded = base + size - 1;
|
|
}
|
|
}
|
|
|
|
if (strcmp (bfd_get_target (prog), "srec") == 0)
|
|
{
|
|
heaptop = heapbottom = 0;
|
|
switch (mach)
|
|
{
|
|
case bfd_mach_m16c:
|
|
if (highest_addr_loaded > 0x10000)
|
|
regs.r_pc = mem_get_si (0x000ffffc) & membus_mask;
|
|
else
|
|
regs.r_pc = mem_get_si (0x000fffc) & membus_mask;
|
|
break;
|
|
case bfd_mach_m32c:
|
|
regs.r_pc = mem_get_si (0x00fffffc) & membus_mask;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
regs.r_pc = prog->start_address;
|
|
if (verbose)
|
|
fprintf (stderr, "[start pc=%08x]\n", (unsigned int) regs.r_pc);
|
|
}
|