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