1 /* load.c --- loading object files into the M32C simulator.
3 Copyright (C) 2005-2024 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* This must come before any other includes. */
34 int (*decode_opcode
) (void) = 0;
35 int default_machine
= 0;
38 m32c_set_mach (unsigned long mach
)
43 m32c_set_cpu (CPU_M16C
);
45 fprintf (stderr
, "[cpu: r8c/m16c]\n");
48 m32c_set_cpu (CPU_M32C
);
50 fprintf (stderr
, "[cpu: m32cm/m32c]\n");
53 fprintf (stderr
, "unknown m32c machine type 0x%lx\n", mach
);
60 m32c_load (bfd
* prog
)
63 unsigned long mach
= bfd_get_mach (prog
);
64 unsigned long highest_addr_loaded
= 0;
66 if (mach
== 0 && default_machine
!= 0)
67 mach
= default_machine
;
71 for (s
= prog
->sections
; s
; s
= s
->next
)
74 /* This was a good idea until we started storing the RAM data in
75 ROM, at which point everything was all messed up. The code
76 remains as a reminder. */
77 if ((s
->flags
& SEC_ALLOC
) && !(s
->flags
& SEC_READONLY
))
79 if (strcmp (bfd_section_name (s
), ".stack"))
82 bfd_section_size (s
) + bfd_section_lma (s
);
83 if (heaptop
< secend
&& bfd_section_lma (s
) < 0x10000)
85 heaptop
= heapbottom
= secend
;
90 if (s
->flags
& SEC_LOAD
)
96 size
= bfd_section_size (s
);
100 base
= bfd_section_lma (s
);
102 fprintf (stderr
, "[load a=%08" PRIx64
" s=%08x %s]\n",
103 (uint64_t) base
, (int) size
, bfd_section_name (s
));
104 buf
= (char *) malloc (size
);
105 bfd_get_section_contents (prog
, s
, buf
, 0, size
);
106 mem_put_blk (base
, buf
, size
);
108 if (highest_addr_loaded
< base
+ size
- 1 && size
>= 4)
109 highest_addr_loaded
= base
+ size
- 1;
113 if (strcmp (bfd_get_target (prog
), "srec") == 0)
115 heaptop
= heapbottom
= 0;
119 if (highest_addr_loaded
> 0x10000)
120 regs
.r_pc
= mem_get_si (0x000ffffc) & membus_mask
;
122 regs
.r_pc
= mem_get_si (0x000fffc) & membus_mask
;
125 regs
.r_pc
= mem_get_si (0x00fffffc) & membus_mask
;
130 regs
.r_pc
= prog
->start_address
;
132 fprintf (stderr
, "[start pc=%08x]\n", (unsigned int) regs
.r_pc
);