]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/m32c/load.c
sim: switch config.h usage to defs.h
[thirdparty/binutils-gdb.git] / sim / m32c / load.c
CommitLineData
d45a4bef
JB
1/* load.c --- loading object files into the M32C simulator.
2
3666a048 3Copyright (C) 2005-2021 Free Software Foundation, Inc.
d45a4bef
JB
4Contributed by Red Hat, Inc.
5
6This file is part of the GNU simulators.
7
4744ac1b
JB
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3 of the License, or
11(at your option) any later version.
d45a4bef 12
4744ac1b
JB
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
d45a4bef
JB
17
18You should have received a copy of the GNU General Public License
4744ac1b 19along with this program. If not, see <http://www.gnu.org/licenses/>. */
d45a4bef 20
6df01ab8
MF
21/* This must come before any other includes. */
22#include "defs.h"
23
d45a4bef
JB
24#include <stdlib.h>
25#include <stdio.h>
26#include <string.h>
27
28#include "bfd.h"
29
30#include "cpu.h"
31#include "mem.h"
269e9c18 32#include "load.h"
d45a4bef 33
269e9c18 34int (*decode_opcode) (void) = 0;
d45a4bef
JB
35int default_machine = 0;
36
37void
38m32c_set_mach (unsigned long mach)
39{
40 switch (mach)
41 {
42 case bfd_mach_m16c:
43 m32c_set_cpu (CPU_M16C);
44 if (verbose)
45 fprintf (stderr, "[cpu: r8c/m16c]\n");
46 break;
47 case bfd_mach_m32c:
48 m32c_set_cpu (CPU_M32C);
49 if (verbose)
50 fprintf (stderr, "[cpu: m32cm/m32c]\n");
51 break;
52 default:
53 fprintf (stderr, "unknown m32c machine type 0x%lx\n", mach);
54 decode_opcode = 0;
55 break;
56 }
57}
58
59void
3877a145 60m32c_load (bfd * prog)
d45a4bef
JB
61{
62 asection *s;
63 unsigned long mach = bfd_get_mach (prog);
64 unsigned long highest_addr_loaded = 0;
65
66 if (mach == 0 && default_machine != 0)
67 mach = default_machine;
68
69 m32c_set_mach (mach);
70
71 for (s = prog->sections; s; s = s->next)
72 {
73#if 0
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))
78 {
fd361982 79 if (strcmp (bfd_section_name (s), ".stack"))
d45a4bef
JB
80 {
81 int secend =
fd361982
AM
82 bfd_section_size (s) + bfd_section_lma (s);
83 if (heaptop < secend && bfd_section_lma (s) < 0x10000)
d45a4bef
JB
84 {
85 heaptop = heapbottom = secend;
86 }
87 }
88 }
89#endif
90 if (s->flags & SEC_LOAD)
91 {
92 char *buf;
93 bfd_size_type size;
269e9c18 94 bfd_vma base;
d45a4bef 95
fd361982 96 size = bfd_section_size (s);
d45a4bef
JB
97 if (size <= 0)
98 continue;
99
fd361982 100 base = bfd_section_lma (s);
d45a4bef 101 if (verbose)
5ee0bc23
MF
102 fprintf (stderr, "[load a=%08" BFD_VMA_FMT "x s=%08x %s]\n",
103 base, (int) size, bfd_section_name (s));
d45a4bef
JB
104 buf = (char *) malloc (size);
105 bfd_get_section_contents (prog, s, buf, 0, size);
106 mem_put_blk (base, buf, size);
107 free (buf);
108 if (highest_addr_loaded < base + size - 1 && size >= 4)
109 highest_addr_loaded = base + size - 1;
110 }
111 }
112
113 if (strcmp (bfd_get_target (prog), "srec") == 0)
114 {
115 heaptop = heapbottom = 0;
116 switch (mach)
117 {
118 case bfd_mach_m16c:
119 if (highest_addr_loaded > 0x10000)
120 regs.r_pc = mem_get_si (0x000ffffc) & membus_mask;
121 else
122 regs.r_pc = mem_get_si (0x000fffc) & membus_mask;
123 break;
124 case bfd_mach_m32c:
125 regs.r_pc = mem_get_si (0x00fffffc) & membus_mask;
126 break;
127 }
128 }
129 else
130 regs.r_pc = prog->start_address;
131 if (verbose)
132 fprintf (stderr, "[start pc=%08x]\n", (unsigned int) regs.r_pc);
133}